Make browser context network-aware and render Mermaid diagrams - #117
Make browser context network-aware and render Mermaid diagrams#117anglinb wants to merge 2 commits into
Conversation
Detect whether the web app is reached through loopback or a network hostname, pass that context to agent turns, rewrite local server URLs, and preview project file links in the browser for network sessions. 🌸 Shipped with Kanna — https://kanna.sh Co-Authored-By: Kanna <noreply@kanna.sh> Kanna-Agent: codex/gpt-5.6-sol
|
| const openServer = useCallback(async (server: LocalHttpServerInfo) => { | ||
| if (!isCloud) { | ||
| navigateBrowser(projectId, server.address) | ||
| navigateBrowser(projectId, resolveUrlForBrowserHost(server.address, browserOriginFromWindow())) |
There was a problem hiding this comment.
Loopback links become unreachable
When Kanna is opened through the machine's LAN hostname or IP, this rewrites every discovered loopback URL to that hostname. Discovery does not retain whether the server listens only on loopback, so a server bound to 127.0.0.1 is presented and opened as http://<lan-host>:<port>, where it is unreachable. This also breaks same-machine sessions in which the original localhost URL was usable. Preserve the listener's bind interface and rewrite only servers known to accept network traffic, or retain a usable fallback.
| const root = projectPath.replace(/[\\/]+$/, "") | ||
| if (filePath === root) return null | ||
| const prefix = `${root}/` | ||
| return filePath.startsWith(prefix) ? filePath.slice(prefix.length) : null |
There was a problem hiding this comment.
This check strips either trailing separator but always appends / and then performs a raw prefix comparison. On Windows, runtime.localPath comes from the platform-native path.resolve and uses backslashes, so valid files inside the active project are reported as outside it and cannot be previewed during network sessions. Normalize both paths consistently and add Windows path cases.
| relativePath, | ||
| contentUrl, | ||
| mimeType, | ||
| size: 0, |
There was a problem hiding this comment.
Workspace attachments always use size: 0, which bypasses the classifier's existing large-JSON guard. JSON files above the preview threshold therefore open in the modal, are truncated by the text preview reader, and can no longer be parsed or formatted as JSON instead of following the large-file new-tab path. Obtain the actual file size before classification or classify workspace files without relying on a fabricated zero size.
Render fenced Mermaid blocks as theme-aware SVGs, lazy-load the renderer, and preserve a copyable source fallback for invalid diagrams. 🌸 Shipped with Kanna — https://kanna.sh Co-Authored-By: Kanna <noreply@kanna.sh> Kanna-Agent: codex/gpt-5.6-sol
Summary
mermaidMarkdown blocks as responsive, theme-aware SVG diagramsVerification
bun test src/client/components/messages/shared.test.tsx src/shared/browser-context.test.ts src/server/browser-context.test.ts src/client/lib/pathUtils.test.ts src/client/components/messages/attachmentPreview.test.tsbunx tsc --noEmitbun run build🌸 Shipped with Kanna — an open-source workspace for all your coding agents. Written by
codex/gpt-5.6-sol.