@hanzo/browser-extension 1.9.56 → 1.9.65

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.
Files changed (60) hide show
  1. package/README.md +11 -0
  2. package/chrome/background.js +527 -0
  3. package/chrome/content-script.js +550 -0
  4. package/{src → chrome}/manifest.json +2 -12
  5. package/chrome/newtab.js +230 -0
  6. package/chrome/onboarding.js +31 -0
  7. package/chrome/page.js +35 -0
  8. package/{src → chrome}/popup.html +8 -0
  9. package/chrome/popup.js +48 -0
  10. package/chrome/sidebar.js +291 -0
  11. package/firefox/ai-worker.js +571 -0
  12. package/firefox/background.js +235 -0
  13. package/firefox/callback.html +17 -0
  14. package/firefox/content-script.js +550 -0
  15. package/firefox/icon128.png +0 -0
  16. package/firefox/icon16.png +0 -0
  17. package/firefox/icon48.png +0 -0
  18. package/{src/manifest-firefox.json → firefox/manifest.json} +2 -3
  19. package/firefox/newtab.css +543 -0
  20. package/firefox/newtab.html +13 -0
  21. package/firefox/newtab.js +230 -0
  22. package/firefox/onboarding.css +78 -0
  23. package/firefox/onboarding.html +45 -0
  24. package/firefox/onboarding.js +31 -0
  25. package/firefox/page.js +35 -0
  26. package/firefox/popup.css +761 -0
  27. package/firefox/popup.html +413 -0
  28. package/firefox/popup.js +48 -0
  29. package/firefox/sidebar.css +1350 -0
  30. package/firefox/sidebar.html +388 -0
  31. package/firefox/sidebar.js +291 -0
  32. package/package.json +4 -53
  33. package/manifest.json +0 -34
  34. package/src/Chat.tsx +0 -164
  35. package/src/answer/AnswerEngine.tsx +0 -410
  36. package/src/answer/Mark.tsx +0 -14
  37. package/src/answer/Rail.tsx +0 -95
  38. package/src/answer/Stories.tsx +0 -27
  39. package/src/answer/Toolbar.tsx +0 -93
  40. package/src/answer/WidgetView.tsx +0 -136
  41. package/src/icon128.png +0 -0
  42. package/src/icon16.png +0 -0
  43. package/src/icon32.png +0 -0
  44. package/src/icon48.png +0 -0
  45. package/src/package.json +0 -41
  46. package/src/safari/SafariWebExtensionHandler.swift +0 -153
  47. package/src/shared/Prose.tsx +0 -29
  48. package/src/webgpu.d.ts +0 -131
  49. /package/{src → chrome}/ai-worker.js +0 -0
  50. /package/{src → chrome}/callback.html +0 -0
  51. /package/{images → chrome}/icon128.png +0 -0
  52. /package/{images → chrome}/icon16.png +0 -0
  53. /package/{images → chrome}/icon48.png +0 -0
  54. /package/{src → chrome}/newtab.css +0 -0
  55. /package/{src → chrome}/newtab.html +0 -0
  56. /package/{src → chrome}/onboarding.css +0 -0
  57. /package/{src → chrome}/onboarding.html +0 -0
  58. /package/{src → chrome}/popup.css +0 -0
  59. /package/{src → chrome}/sidebar.css +0 -0
  60. /package/{src → chrome}/sidebar.html +0 -0
@@ -1,95 +0,0 @@
1
- import React from "react";
2
- import { Mark } from "./Mark.js";
3
-
4
- /**
5
- * The left rail: mark, new thread, links, sign-in.
6
- *
7
- * COLLAPSED IS AN ICON RAIL, NOT AN ABSENCE — the `collapsible="icon"` behaviour of
8
- * @hanzo/ui primitives/sidebar. A collapsed rail still shows the brand and the way
9
- * back; hiding it outright left the surface with no affordance at all.
10
- *
11
- * The labels are ALWAYS RENDERED and hidden in CSS, never branched on in JS, so the
12
- * rail can widen without React re-rendering its contents.
13
- *
14
- * Collapse is an EXPLICIT, remembered choice — the rail never springs open under the
15
- * pointer. That is the model console and hanzo.app both settled on, and while the
16
- * rail opened on hover the mark had no job of its own and the collapse toggle was
17
- * hidden, so hover was the ONLY way back: an affordance you cannot see. Collapsed,
18
- * the mark IS the expand control. Presentational: every action is injected.
19
- */
20
- export interface RailProps {
21
- collapsed: boolean;
22
- toggle: () => void;
23
- newThread: () => void;
24
- signIn: () => void;
25
- }
26
-
27
- export function Rail({ collapsed, toggle, newThread, signIn }: RailProps) {
28
- return (
29
- <aside className="ae-sidebar">
30
- <div className="ae-side-top">
31
- <button
32
- className="ae-brand"
33
- onClick={collapsed ? toggle : newThread}
34
- title={collapsed ? "Expand sidebar" : "Hanzo"}
35
- aria-label={collapsed ? "Expand sidebar" : "Hanzo"}
36
- {...(collapsed ? { "aria-expanded": false } : {})}
37
- >
38
- <Mark size={22} />
39
- <span>Hanzo</span>
40
- </button>
41
- <button
42
- className="ae-collapse"
43
- onClick={toggle}
44
- title={collapsed ? "Expand sidebar" : "Collapse sidebar"}
45
- aria-label={collapsed ? "Expand sidebar" : "Collapse sidebar"}
46
- aria-expanded={!collapsed}
47
- >
48
- <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true">
49
- <path
50
- d="M6 3v10M3 3h10v10H3z"
51
- fill="none"
52
- stroke="currentColor"
53
- strokeWidth="1.3"
54
- />
55
- </svg>
56
- </button>
57
- </div>
58
- <button className="ae-new" onClick={newThread} title="New thread">
59
- <svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true">
60
- <path
61
- d="M8 3v10M3 8h10"
62
- fill="none"
63
- stroke="currentColor"
64
- strokeWidth="1.5"
65
- />
66
- </svg>
67
- <span>New thread</span>
68
- </button>
69
- <nav className="ae-nav">
70
- <a href="https://hanzo.chat" target="_blank" rel="noreferrer">
71
- Threads
72
- </a>
73
- <a href="https://docs.hanzo.ai" target="_blank" rel="noreferrer">
74
- Docs
75
- </a>
76
- <a href="https://hanzo.ai" target="_blank" rel="noreferrer">
77
- About
78
- </a>
79
- </nav>
80
- <div className="ae-side-bottom">
81
- <button className="ae-signin" onClick={signIn} title="Sign in">
82
- <svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true">
83
- <path
84
- d="M6 3H3v10h3M10 5l3 3-3 3M13 8H6"
85
- fill="none"
86
- stroke="currentColor"
87
- strokeWidth="1.4"
88
- />
89
- </svg>
90
- <span className="ae-signin-label">Sign in — free to start</span>
91
- </button>
92
- </div>
93
- </aside>
94
- );
95
- }
@@ -1,27 +0,0 @@
1
- import React from 'react';
2
- import type { NewsItem } from './news.js';
3
-
4
- /**
5
- * Top stories — the idle state of the answer surface. Renders nothing at all
6
- * when the feed is empty, so a failed fetch leaves a clean page rather than an
7
- * empty frame.
8
- */
9
- export function Stories({ items, limit = 6 }: { items: NewsItem[]; limit?: number }) {
10
- if (!items.length) return null;
11
- return (
12
- <div className="ae-news">
13
- <div className="ae-news-head">Top stories</div>
14
- <div className="ae-news-grid">
15
- {items.slice(0, limit).map((n) => (
16
- <a key={n.url} className="ae-news-item" href={n.url} target="_blank" rel="noreferrer">
17
- <span className="ae-news-title">{n.title}</span>
18
- <span className="ae-news-meta">
19
- {n.source}
20
- {typeof n.points === 'number' ? ` · ${n.points} pts` : ''}
21
- </span>
22
- </a>
23
- ))}
24
- </div>
25
- </div>
26
- );
27
- }
@@ -1,93 +0,0 @@
1
- import React from 'react';
2
- import type { SearchMode } from '@hanzo/ai';
3
- import { Button, XStack } from '@hanzo/ui';
4
-
5
- /**
6
- * What the composer's toolbar slot holds on this surface: how to ask (mode) and
7
- * where to look (sources).
8
- *
9
- * The composer itself is `@hanzo/ui/chat`. It owns the field, the Enter rule and
10
- * the send/stop control — the parts every Hanzo surface shares — and hands back
11
- * one slot for the affordances that are only true here. Modes and sources are
12
- * exactly that, so this is what is left after the shell took the rest.
13
- *
14
- * Presentational: the selection and both effects arrive as props.
15
- */
16
-
17
- /** What the composer sends. `chat` goes straight to the model; the rest ground
18
- * the question on the live web (`SearchMode` is the wire's own vocabulary).
19
- *
20
- * `deep` is EXCLUDED rather than absent. The wire still names it — dropping it
21
- * from `MODES` only stopped it being offered, it stayed a legal `Mode`, so any
22
- * call site could still hold one and put the retired name back on the surface.
23
- * Excluding it makes the collapse structural. Derived from `SearchMode` and not
24
- * restated, so a mode this surface invents is still a type error, and the day
25
- * the wire drops `deep` this narrows to nothing on its own. */
26
- export type Mode = Exclude<SearchMode, 'deep'> | 'chat';
27
-
28
- /** The modes, in the order they read as escalating effort. */
29
- export const MODES: { id: Mode; label: string; hint: string }[] = [
30
- { id: 'chat', label: 'Chat', hint: 'Straight to the model' },
31
- { id: 'search', label: 'Search', hint: 'Fast grounded answer' },
32
- { id: 'news', label: 'News', hint: 'Recency-biased' },
33
- // No 'deep'. It was research with the dials up — same system prompt, same
34
- // models, same gate — so two names offered a choice that was really an
35
- // intensity, and hid a 2x price behind an adjective. Cloud folded them into
36
- // one research mode (apps/answer/mode.go) that always does the deeper pass;
37
- // 'deep' still RESOLVES there, so a client that has not shipped this does not
38
- // 400 — which is why dropping the tab is safe on its own.
39
- { id: 'research', label: 'Research', hint: 'Plans, reads sources, synthesizes' },
40
- ];
41
-
42
- export const SOURCES = ['web', 'news', 'academic', 'github', 'reddit', 'x'];
43
-
44
- export interface ToolbarProps {
45
- mode: Mode;
46
- setMode: (mode: Mode) => void;
47
- sources: Set<string>;
48
- toggleSource: (source: string) => void;
49
- }
50
-
51
- export function Toolbar({ mode, setMode, sources, toggleSource }: ToolbarProps) {
52
- return (
53
- // Wraps rather than overflows: ten controls do not fit one row beside the
54
- // picker and the send control at a reading measure, and the composer's
55
- // toolbar row does not wrap for its children.
56
- <XStack shrink={1} minW={0} items="center" gap="$2" flexWrap="wrap">
57
- <XStack data-slot="modes" items="center" gap="$1">
58
- {MODES.map((m) => (
59
- <Button
60
- key={m.id}
61
- data-mode={m.id}
62
- data-on={mode === m.id ? 'true' : undefined}
63
- size="sm"
64
- variant={mode === m.id ? 'secondary' : 'ghost'}
65
- title={m.hint}
66
- onPress={() => setMode(m.id)}
67
- >
68
- {m.label}
69
- </Button>
70
- ))}
71
- </XStack>
72
- {/* The container stays in the row whatever the mode: dropping it would
73
- slide the rest of the toolbar left as soon as Chat is picked. Chat is
74
- ungrounded, so it offers no sources to pick. */}
75
- <XStack data-slot="sources" items="center" gap="$1">
76
- {mode !== 'chat' &&
77
- SOURCES.map((s) => (
78
- <Button
79
- key={s}
80
- data-source={s}
81
- data-on={sources.has(s) ? 'true' : undefined}
82
- size="sm"
83
- variant={sources.has(s) ? 'secondary' : 'ghost'}
84
- title={`@${s}`}
85
- onPress={() => toggleSource(s)}
86
- >
87
- @{s}
88
- </Button>
89
- ))}
90
- </XStack>
91
- </XStack>
92
- );
93
- }
@@ -1,136 +0,0 @@
1
- import React from 'react';
2
- import type { Widget } from './widget.js';
3
-
4
- /**
5
- * Renders a generative result widget.
6
- *
7
- * NAMED WidgetView, not Widget, because widget.ts sits beside it and macOS is
8
- * case-insensitive: `./Widget.js` resolves to `widget.ts` there, so the schema
9
- * module shadowed this one and the build failed on a missing export. Two modules
10
- * in one directory differing only by case cannot both be imported.
11
- *
12
- * Presentational and total: every kind in the union has a branch, and every value
13
- * arrives as a React child, so it is ESCAPED by construction. There is no
14
- * dangerouslySetInnerHTML here and there must never be one — the content is written
15
- * by a model that reads the open web, so treating any of it as markup hands whoever
16
- * wrote that web page a path into this extension's origin.
17
- */
18
- export function WidgetView({ widget }: { widget: Widget }) {
19
- switch (widget.kind) {
20
- case 'comparison':
21
- return (
22
- <section className="ae-widget ae-widget-comparison">
23
- {widget.title && <h3 className="ae-widget-title">{widget.title}</h3>}
24
- {/* Its own scroll container: a wide table must never make the PAGE
25
- scroll sideways. */}
26
- <div className="ae-widget-scroll">
27
- <table className="ae-widget-table">
28
- <thead>
29
- <tr>
30
- {widget.columns.map((c, i) => (
31
- <th key={i} scope={i === 0 ? 'row' : 'col'}>
32
- {c}
33
- </th>
34
- ))}
35
- </tr>
36
- </thead>
37
- <tbody>
38
- {widget.rows.map((row, i) => (
39
- <tr key={i}>
40
- {row.map((cell, j) =>
41
- j === 0 ? (
42
- <th key={j} scope="row">
43
- {cell}
44
- </th>
45
- ) : (
46
- <td key={j}>{cell}</td>
47
- ),
48
- )}
49
- </tr>
50
- ))}
51
- </tbody>
52
- </table>
53
- </div>
54
- </section>
55
- );
56
-
57
- case 'steps':
58
- return (
59
- <section className="ae-widget ae-widget-steps">
60
- {widget.title && <h3 className="ae-widget-title">{widget.title}</h3>}
61
- <ol className="ae-widget-steplist">
62
- {widget.steps.map((s, i) => (
63
- <li key={i}>{s}</li>
64
- ))}
65
- </ol>
66
- </section>
67
- );
68
-
69
- case 'stats':
70
- return (
71
- <section className="ae-widget ae-widget-stats">
72
- {widget.title && <h3 className="ae-widget-title">{widget.title}</h3>}
73
- <div className="ae-widget-statgrid">
74
- {widget.stats.map((s, i) => (
75
- <div className="ae-widget-stat" key={i}>
76
- <span className="ae-widget-statvalue">{s.value}</span>
77
- <span className="ae-widget-statlabel">{s.label}</span>
78
- </div>
79
- ))}
80
- </div>
81
- </section>
82
- );
83
-
84
- case 'timeline':
85
- return (
86
- <section className="ae-widget ae-widget-timeline">
87
- {widget.title && <h3 className="ae-widget-title">{widget.title}</h3>}
88
- <ol className="ae-widget-events">
89
- {widget.events.map((e, i) => (
90
- <li key={i}>
91
- <span className="ae-widget-when">{e.when}</span>
92
- <span className="ae-widget-what">{e.what}</span>
93
- </li>
94
- ))}
95
- </ol>
96
- </section>
97
- );
98
-
99
- case 'entity':
100
- return (
101
- <section className="ae-widget ae-widget-entity">
102
- <h3 className="ae-widget-title">{widget.title}</h3>
103
- {widget.subtitle && <p className="ae-widget-subtitle">{widget.subtitle}</p>}
104
- <dl className="ae-widget-facts">
105
- {widget.facts.map((f, i) => (
106
- <React.Fragment key={i}>
107
- <dt>{f.label}</dt>
108
- <dd>{f.value}</dd>
109
- </React.Fragment>
110
- ))}
111
- </dl>
112
- </section>
113
- );
114
-
115
- case 'definition':
116
- return (
117
- <section className="ae-widget ae-widget-definition">
118
- <h3 className="ae-widget-title">{widget.term}</h3>
119
- <p className="ae-widget-meaning">{widget.meaning}</p>
120
- {widget.example && <pre className="ae-widget-example">{widget.example}</pre>}
121
- </section>
122
- );
123
- }
124
- }
125
-
126
- /** Renders every widget an answer produced, or nothing. */
127
- export function Widgets({ widgets }: { widgets: Widget[] }) {
128
- if (!widgets.length) return null;
129
- return (
130
- <div className="ae-widgets">
131
- {widgets.map((w, i) => (
132
- <WidgetView key={i} widget={w} />
133
- ))}
134
- </div>
135
- );
136
- }
package/src/icon128.png DELETED
Binary file
package/src/icon16.png DELETED
Binary file
package/src/icon32.png DELETED
Binary file
package/src/icon48.png DELETED
Binary file
package/src/package.json DELETED
@@ -1,41 +0,0 @@
1
- {
2
- "name": "@hanzo/browser-extension",
3
- "version": "1.0.0",
4
- "description": "Browser extension for click-to-code navigation with MCP integration",
5
- "main": "cli.js",
6
- "bin": {
7
- "hanzo-browser-server": "./cli.js"
8
- },
9
- "scripts": {
10
- "start": "node cli.js"
11
- },
12
- "files": [
13
- "cli.js",
14
- "browser-extension-server.js",
15
- "content-script.js",
16
- "manifest.json",
17
- "README.md"
18
- ],
19
- "keywords": [
20
- "mcp",
21
- "browser",
22
- "devtools",
23
- "source-maps",
24
- "react",
25
- "vue",
26
- "developer-tools"
27
- ],
28
- "dependencies": {
29
- "ws": "^8.18.0",
30
- "commander": "^11.0.0",
31
- "chalk": "^5.3.0"
32
- },
33
- "devDependencies": {
34
- "@types/ws": "^8.5.0",
35
- "typescript": "^5.0.0",
36
- "esbuild": "^0.25.0"
37
- },
38
- "peerDependencies": {
39
- "@modelcontextprotocol/sdk": "^1.0.0"
40
- }
41
- }
@@ -1,153 +0,0 @@
1
- //
2
- // SafariWebExtensionHandler.swift
3
- // Shared (Extension)
4
- //
5
- // Relays the extension to zapd, which is the same fabric Chrome and Firefox
6
- // join. They reach it by spawning `zapd` over stdio as a native messaging
7
- // host; Safari cannot spawn a binary, so it carries the last hop itself and
8
- // writes to the router's socket directly.
9
- //
10
- // The message is the router envelope the shared transport already sends —
11
- // { t, flags, from, to, payload } with a base64 payload — so the browser side
12
- // is byte-identical across all three engines and only the hop changes.
13
- //
14
-
15
- import SafariServices
16
- import Foundation
17
- import os.log
18
-
19
- /// One connection to the router, kept open across messages.
20
- ///
21
- /// A native port is a channel, not a request: the router pushes ROUTE commands
22
- /// on it long after the extension last spoke, and a socket opened per message
23
- /// would miss every one of them.
24
- final class ZapSocket {
25
- static let shared = ZapSocket()
26
-
27
- private let path = NSHomeDirectory() + "/.zap/run/zapd.sock"
28
- private var fd: Int32 = -1
29
- private let lock = NSLock()
30
-
31
- /// Connect if we are not already. Returns false when the router is absent —
32
- /// which is a normal state (zapd not running), not an error to throw at the
33
- /// browser.
34
- @discardableResult
35
- private func connect() -> Bool {
36
- if fd >= 0 { return true }
37
- let s = socket(AF_UNIX, SOCK_STREAM, 0)
38
- if s < 0 { return false }
39
-
40
- var addr = sockaddr_un()
41
- addr.sun_family = sa_family_t(AF_UNIX)
42
- let bytes = Array(path.utf8)
43
- // sun_path is a fixed C array; a path that does not fit is not a path
44
- // this socket can name, and truncating it would name a different one.
45
- guard bytes.count < MemoryLayout.size(ofValue: addr.sun_path) else { close(s); return false }
46
- withUnsafeMutablePointer(to: &addr.sun_path) { p in
47
- p.withMemoryRebound(to: CChar.self, capacity: bytes.count + 1) { dst in
48
- for (i, b) in bytes.enumerated() { dst[i] = CChar(bitPattern: b) }
49
- dst[bytes.count] = 0
50
- }
51
- }
52
- let size = socklen_t(MemoryLayout<sockaddr_un>.size)
53
- let ok = withUnsafePointer(to: &addr) { p in
54
- p.withMemoryRebound(to: sockaddr.self, capacity: 1) { sa in
55
- Darwin.connect(s, sa, size) == 0
56
- }
57
- }
58
- if !ok { close(s); return false }
59
- fd = s
60
- return true
61
- }
62
-
63
- private func drop() {
64
- if fd >= 0 { close(fd) }
65
- fd = -1
66
- }
67
-
68
- /// Send one envelope and read one back.
69
- ///
70
- /// Length-prefixed both ways, matching the native messaging framing the
71
- /// other two engines get from the host: u32 little-endian, then the JSON.
72
- func exchange(_ message: Any) -> Any? {
73
- lock.lock()
74
- defer { lock.unlock() }
75
- guard connect() else { return nil }
76
- guard let body = try? JSONSerialization.data(withJSONObject: message) else { return nil }
77
-
78
- var length = UInt32(body.count).littleEndian
79
- var frame = Data(bytes: &length, count: 4)
80
- frame.append(body)
81
-
82
- guard write(frame) else { drop(); return nil }
83
- guard let header = read(exactly: 4) else { drop(); return nil }
84
- let expected = header.withUnsafeBytes { $0.load(as: UInt32.self).littleEndian }
85
- // A reply that claims more than the router will ever send is a desynced
86
- // stream, not a big message. Start over rather than block on it.
87
- guard expected > 0, expected <= 16 * 1024 * 1024, let payload = read(exactly: Int(expected)) else {
88
- drop(); return nil
89
- }
90
- return try? JSONSerialization.jsonObject(with: payload)
91
- }
92
-
93
- private func write(_ data: Data) -> Bool {
94
- var sent = 0
95
- return data.withUnsafeBytes { raw -> Bool in
96
- guard let base = raw.baseAddress else { return false }
97
- while sent < data.count {
98
- let n = Darwin.write(fd, base.advanced(by: sent), data.count - sent)
99
- if n <= 0 { return false }
100
- sent += n
101
- }
102
- return true
103
- }
104
- }
105
-
106
- private func read(exactly count: Int) -> Data? {
107
- var out = Data()
108
- var buf = [UInt8](repeating: 0, count: count)
109
- while out.count < count {
110
- let n = buf.withUnsafeMutableBytes { p -> Int in
111
- guard let base = p.baseAddress else { return -1 }
112
- return Darwin.read(fd, base, count - out.count)
113
- }
114
- if n <= 0 { return nil }
115
- out.append(contentsOf: buf[0..<n])
116
- }
117
- return out
118
- }
119
- }
120
-
121
- class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
122
-
123
- func beginRequest(with context: NSExtensionContext) {
124
- let request = context.inputItems.first as? NSExtensionItem
125
-
126
- let message: Any?
127
- if #available(iOS 15.0, macOS 11.0, *) {
128
- message = request?.userInfo?[SFExtensionMessageKey]
129
- } else {
130
- message = request?.userInfo?["message"]
131
- }
132
-
133
- // iOS has no router to reach: zapd is a desktop daemon and an iOS app
134
- // has no filesystem path to another process's socket. The extension
135
- // treats a null reply as "not connected", which is what this is.
136
- var reply: Any? = nil
137
- #if os(macOS)
138
- if let message { reply = ZapSocket.shared.exchange(message) }
139
- #endif
140
-
141
- if reply == nil {
142
- os_log(.default, "zapd unreachable at ~/.zap/run/zapd.sock")
143
- }
144
-
145
- let response = NSExtensionItem()
146
- if #available(iOS 15.0, macOS 11.0, *) {
147
- response.userInfo = [SFExtensionMessageKey: reply ?? [:]]
148
- } else {
149
- response.userInfo = ["message": reply ?? [:]]
150
- }
151
- context.completeRequest(returningItems: [response], completionHandler: nil)
152
- }
153
- }
@@ -1,29 +0,0 @@
1
- import React from 'react';
2
- import { YStack } from '@hanzo/ui';
3
- import { Code } from '@hanzo/ui/chat';
4
- import { blocks } from './markdown.js';
5
-
6
- /**
7
- * An answer's text, as both surfaces render it: prose as HTML, fenced code as
8
- * the shared `@hanzo/ui/chat` Code block — which is what carries the language
9
- * label and the copy control.
10
- *
11
- * The `markdown` class is the prose stylesheet's hook and the only thing left
12
- * here that is CSS rather than a token; the pipeline itself is `blocks()`.
13
- */
14
- export function Prose({ text }: { text: string }) {
15
- if (!text) return null;
16
- return (
17
- <YStack gap="$3" width="100%">
18
- {blocks(text).map((b, i) =>
19
- 'code' in b ? (
20
- <Code key={i} language={b.lang} value={b.code}>
21
- {b.code}
22
- </Code>
23
- ) : (
24
- <div key={i} className="markdown" dangerouslySetInnerHTML={{ __html: b.html }} />
25
- ),
26
- )}
27
- </YStack>
28
- );
29
- }