mac: fix web chat boot in WKWebView
parent
e528b439bc
commit
6182b205c8
|
|
@ -80,11 +80,16 @@ final class WebChatWindowController: NSWindowController, WKScriptMessageHandler
|
|||
let importMap = [
|
||||
"imports": [
|
||||
"@mariozechner/pi-web-ui": "file://\(distPath)/index.js",
|
||||
"@mariozechner/pi-web-ui/": "file://\(distPath)/",
|
||||
"@mariozechner/pi-ai": "file://\(piAi)",
|
||||
"@mariozechner/pi-ai/": "file://\(vendor.appendingPathComponent("pi-ai/").path(percentEncoded: false))",
|
||||
"@mariozechner/mini-lit": "file://\(miniLit)",
|
||||
"@mariozechner/mini-lit/": "file://\(vendor.appendingPathComponent("mini-lit/").path(percentEncoded: false))",
|
||||
"lit": "file://\(lit)",
|
||||
"lit/": "file://\(vendor.appendingPathComponent("lit/").path(percentEncoded: false))",
|
||||
"lucide": "file://\(lucide)",
|
||||
"pdfjs-dist": "file://\(pdfjs)",
|
||||
"pdfjs-dist/": "file://\(vendor.appendingPathComponent("pdfjs-dist/").path(percentEncoded: false))",
|
||||
"pdfjs-dist/build/pdf.worker.min.mjs": "file://\(pdfWorker)",
|
||||
],
|
||||
]
|
||||
|
|
@ -114,9 +119,23 @@ final class WebChatWindowController: NSWindowController, WKScriptMessageHandler
|
|||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module">
|
||||
const status = (msg) => {
|
||||
console.log(msg);
|
||||
window.__clawdisLog(msg);
|
||||
const el = document.getElementById('app');
|
||||
if (el && !el.dataset.booted) {
|
||||
el.textContent = msg;
|
||||
}
|
||||
};
|
||||
|
||||
status('boot: starting imports');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const { Agent, ChatPanel, AppStorage, setAppStorage } = await import('@mariozechner/pi-web-ui');
|
||||
status('boot: pi-web-ui imported');
|
||||
const { getModel } = await import('@mariozechner/pi-ai');
|
||||
status('boot: pi-ai imported');
|
||||
|
||||
class NativeTransport {
|
||||
async *run(messages, userMessage, cfg, signal) {
|
||||
|
|
@ -172,7 +191,11 @@ final class WebChatWindowController: NSWindowController, WKScriptMessageHandler
|
|||
panel.style.height = '100%';
|
||||
panel.style.display = 'block';
|
||||
await panel.setAgent(agent);
|
||||
document.getElementById('app').appendChild(panel);
|
||||
const mount = document.getElementById('app');
|
||||
mount.dataset.booted = '1';
|
||||
mount.textContent = '';
|
||||
mount.appendChild(panel);
|
||||
status('boot: ready');
|
||||
} catch (err) {
|
||||
const msg = err?.stack || err?.message || String(err);
|
||||
window.__clawdisLog(msg);
|
||||
|
|
@ -181,6 +204,7 @@ final class WebChatWindowController: NSWindowController, WKScriptMessageHandler
|
|||
document.body.style.padding = '16px';
|
||||
document.body.innerText = 'Web chat failed to load:\\n' + msg;
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -191,8 +215,15 @@ final class WebChatWindowController: NSWindowController, WKScriptMessageHandler
|
|||
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
||||
guard let body = message.body as? [String: Any],
|
||||
let id = body["id"] as? String,
|
||||
let type = body["type"] as? String,
|
||||
type == "chat",
|
||||
let type = body["type"] as? String
|
||||
else { return }
|
||||
|
||||
if id == "log", let log = body["log"] as? String {
|
||||
NSLog("WebChat JS: %@", log)
|
||||
return
|
||||
}
|
||||
|
||||
guard type == "chat",
|
||||
let payload = body["payload"] as? [String: Any],
|
||||
let text = payload["text"] as? String
|
||||
else { return }
|
||||
|
|
|
|||
|
|
@ -23,5 +23,5 @@ The macOS Clawdis app ships a built-in web chat window that reuses your primary
|
|||
|
||||
## Usage
|
||||
|
||||
- Launch the macOS Clawdis menu bar app, click the lobster icon → “Open Web Chat”.
|
||||
- Launch the macOS Clawdis menu bar app, click the lobster icon → “Open Chat”.
|
||||
- Type and send; replies continue the primary Clawd session.
|
||||
|
|
|
|||
Loading…
Reference in New Issue