@hanzo/browser-extension 1.9.36 → 1.9.46

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 (51) hide show
  1. package/dist/safari/Hanzo AI/Hanzo AI.xcodeproj/project.pbxproj +1059 -0
  2. package/dist/safari/Hanzo AI/Hanzo AI.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  3. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
  4. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
  5. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-128@1x.png +0 -0
  6. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-128@2x.png +0 -0
  7. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-16@1x.png +0 -0
  8. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-16@2x.png +0 -0
  9. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-256@1x.png +0 -0
  10. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-256@2x.png +0 -0
  11. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-32@1x.png +0 -0
  12. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-32@2x.png +0 -0
  13. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-512@1x.png +0 -0
  14. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/mac-icon-512@2x.png +0 -0
  15. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/AppIcon.appiconset/universal-icon-1024@1x.png +0 -0
  16. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/Contents.json +6 -0
  17. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/LargeIcon.imageset/Contents.json +21 -0
  18. package/dist/safari/Hanzo AI/Shared (App)/Assets.xcassets/LargeIcon.imageset/icon128.png +0 -0
  19. package/dist/safari/Hanzo AI/Shared (App)/Resources/Base.lproj/Main.html +20 -0
  20. package/dist/safari/Hanzo AI/Shared (App)/Resources/Icon.png +0 -0
  21. package/dist/safari/Hanzo AI/Shared (App)/Resources/Script.js +24 -0
  22. package/dist/safari/Hanzo AI/Shared (App)/Resources/Style.css +61 -0
  23. package/dist/safari/Hanzo AI/Shared (App)/ViewController.swift +81 -0
  24. package/dist/safari/Hanzo AI/Shared (Extension)/SafariWebExtensionHandler.swift +42 -0
  25. package/dist/safari/Hanzo AI/iOS (App)/AppDelegate.swift +24 -0
  26. package/dist/safari/Hanzo AI/iOS (App)/Base.lproj/LaunchScreen.storyboard +36 -0
  27. package/dist/safari/Hanzo AI/iOS (App)/Base.lproj/Main.storyboard +38 -0
  28. package/dist/safari/Hanzo AI/iOS (App)/Info.plist +27 -0
  29. package/dist/safari/Hanzo AI/iOS (App)/SceneDelegate.swift +18 -0
  30. package/dist/safari/Hanzo AI/iOS (Extension)/Info.plist +13 -0
  31. package/dist/safari/Hanzo AI/macOS (App)/AppDelegate.swift +21 -0
  32. package/dist/safari/Hanzo AI/macOS (App)/Base.lproj/Main.storyboard +124 -0
  33. package/dist/safari/Hanzo AI/macOS (App)/Info.plist +8 -0
  34. package/dist/safari/Hanzo AI/macOS (Extension)/Info.plist +13 -0
  35. package/package.json +20 -14
  36. package/src/answer/AnswerEngine.tsx +172 -348
  37. package/src/answer/Composer.tsx +147 -0
  38. package/src/answer/Mark.tsx +14 -0
  39. package/src/answer/Models.tsx +118 -0
  40. package/src/answer/Rail.tsx +69 -0
  41. package/src/answer/Source.tsx +26 -0
  42. package/src/answer/Stories.tsx +27 -0
  43. package/src/answer/WidgetView.tsx +136 -0
  44. package/src/manifest.json +4 -1
  45. package/src/newtab.css +187 -35
  46. package/src/popup.html +1 -1
  47. package/src/sidebar.css +0 -40
  48. package/src/sidebar.html +5 -11
  49. package/LICENSE +0 -12
  50. package/src/chat-widget.tsx +0 -96
  51. package/src/gui-primitives.tsx +0 -116
@@ -1,18 +1,56 @@
1
1
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
- import { createAiClient, type SearchEvent, type SearchMode, type SearchSource } from '@hanzo/ai';
2
+ import { createAiClient, type AiClient, type SearchEvent, type SearchSource } from '@hanzo/ai';
3
3
  import { fetchNews, type NewsItem } from './news.js';
4
4
  import { AUTO_MODEL, fetchModelCatalog, type ChatModel, type ModelGroup } from './model-catalog.js';
5
5
  import { renderMarkdown } from './markdown.js';
6
6
  import { capture, contributeTrainingSample } from '../shared/consent.js';
7
+ import { Composer, type Mode } from './Composer.js';
8
+ import { Rail } from './Rail.js';
9
+ import { Source } from './Source.js';
10
+ import { Stories } from './Stories.js';
11
+ import { Widgets } from './WidgetView.js';
12
+ import { extractWidgets } from './widget.js';
13
+ import { DEFAULT_PROVIDER_ID, fallbackUrl, loadProviderId, providerById } from './websearch.js';
7
14
 
8
15
  /**
9
16
  * Hanzo Answer Engine — the shared AI-answer surface (query → streamed answer +
10
17
  * inline citations + sources + live news). Backend = api.hanzo.ai ONLY, reached
11
- * through the @hanzo/ai `search`/`deepResearch` primitive (the one place the
12
- * capability is defined). Rendered on the @hanzo/gui primitive surface; strict
13
- * monochrome per the Hanzo brand.
18
+ * through @hanzo/ai: `search` for the grounded modes, `chat.completions` for
19
+ * Chat (each capability defined in exactly one place). Strict monochrome per
20
+ * the Hanzo brand.
21
+ *
22
+ * This file holds the state and the wire. Everything it draws with is a
23
+ * presentational sibling — Rail, Composer (Models), Source, Stories — each one
24
+ * a component whose data and effects arrive as props, so the same parts can be
25
+ * lifted into @hanzo/ui and mounted by chat and app without dragging the
26
+ * extension's transport along.
14
27
  */
15
28
 
29
+ /**
30
+ * Chat mode — the same question, ungrounded, straight to the model. It yields
31
+ * `SearchEvent`s so the surface keeps ONE stream to consume and ONE way to
32
+ * render an answer; a mode is a value the wire takes, never a second UI.
33
+ */
34
+ async function* converse(
35
+ client: AiClient,
36
+ question: string,
37
+ model: string,
38
+ signal: AbortSignal,
39
+ ): AsyncGenerator<SearchEvent> {
40
+ const stream = await client.chat.completions.create(
41
+ { model, messages: [{ role: 'user', content: question }], stream: true },
42
+ { signal },
43
+ );
44
+ let answer = '';
45
+ for await (const chunk of stream) {
46
+ const delta = chunk.choices?.[0]?.delta?.content;
47
+ if (!delta) continue;
48
+ answer += delta;
49
+ yield { type: 'text', delta };
50
+ }
51
+ yield { type: 'done', answer, sources: [] };
52
+ }
53
+
16
54
  export interface AnswerEngineProps {
17
55
  apiBase: string;
18
56
  /** Resolves the current IAM bearer, or null when signed out. */
@@ -23,257 +61,24 @@ export interface AnswerEngineProps {
23
61
  initialQuery?: string;
24
62
  }
25
63
 
26
- const MODES: { id: SearchMode; label: string; hint: string }[] = [
27
- { id: 'search', label: 'Search', hint: 'Fast grounded answer' },
28
- { id: 'news', label: 'News', hint: 'Recency-biased' },
29
- { id: 'research', label: 'Research', hint: 'Multi-source synthesis' },
30
- { id: 'deep', label: 'Deep', hint: 'Plan + wide research' },
31
- ];
32
-
33
- const SOURCE_CHIPS = ['web', 'news', 'academic', 'github', 'reddit', 'x'];
34
-
35
- // Hanzo tiers mirror @hanzo/plans (the SoT for pricing); shown in the picker's
36
- // upgrade banner. Full plan detail lives at console.hanzo.ai/pricing.
37
- const PLAN_TIERS = [
38
- { name: 'Pro', price: '$20' },
39
- { name: 'Max', price: '$100' },
40
- { name: 'Ultra', price: '$200' },
41
- ];
42
-
43
- function HanzoMark({ size = 28 }: { size?: number }) {
44
- return (
45
- <svg viewBox="0 0 67 67" width={size} height={size} xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
46
- <path d="M22.21 67V44.6369H0V67H22.21Z" fill="currentColor" />
47
- <path d="M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z" fill="currentColor" />
48
- <path d="M22.21 0H0V22.3184H22.21V0Z" fill="currentColor" />
49
- <path d="M66.7198 0H44.5098V22.3184H66.7198V0Z" fill="currentColor" />
50
- <path d="M66.7198 67V44.6369H44.5098V67H66.7198Z" fill="currentColor" />
51
- </svg>
52
- );
53
- }
54
-
55
- function ModelPicker({
56
- groups,
57
- current,
58
- onPick,
59
- }: {
60
- groups: ModelGroup[];
61
- current: ChatModel;
62
- onPick: (m: ChatModel) => void;
63
- }) {
64
- const [open, setOpen] = useState(false);
65
- const [filter, setFilter] = useState('');
66
- const ref = useRef<HTMLDivElement>(null);
67
-
68
- useEffect(() => {
69
- if (!open) return;
70
- const onDoc = (e: MouseEvent) => {
71
- if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
72
- };
73
- document.addEventListener('mousedown', onDoc);
74
- return () => document.removeEventListener('mousedown', onDoc);
75
- }, [open]);
76
-
77
- const q = filter.trim().toLowerCase();
78
- const shown = useMemo(
79
- () =>
80
- groups
81
- .map((g) => ({
82
- ...g,
83
- models: g.models.filter(
84
- (m) => !q || m.name.toLowerCase().includes(q) || m.id.toLowerCase().includes(q),
85
- ),
86
- }))
87
- .filter((g) => g.models.length),
88
- [groups, q],
89
- );
90
-
91
- return (
92
- <div className="ae-picker" ref={ref}>
93
- <button className="ae-picker-btn" onClick={() => setOpen((v) => !v)} title="Choose model">
94
- <span className="ae-dot" />
95
- {current.name}
96
- <svg viewBox="0 0 16 16" width="12" height="12" aria-hidden="true">
97
- <path d="M4 6l4 4 4-4" fill="none" stroke="currentColor" strokeWidth="1.5" />
98
- </svg>
99
- </button>
100
- {open && (
101
- <div className="ae-picker-menu">
102
- <input
103
- className="ae-picker-filter"
104
- placeholder="Search models…"
105
- value={filter}
106
- autoFocus
107
- onChange={(e) => setFilter(e.target.value)}
108
- />
109
- <div className="ae-picker-list">
110
- <button
111
- className={'ae-model-row' + (current.id === AUTO_MODEL.id ? ' active' : '')}
112
- onClick={() => {
113
- onPick(AUTO_MODEL);
114
- setOpen(false);
115
- }}
116
- >
117
- <span className="ae-model-name">Auto</span>
118
- <span className="ae-model-desc">Routes to the best model</span>
119
- </button>
120
- {shown.map((g) => (
121
- <div key={g.family} className="ae-model-group">
122
- <div className="ae-model-group-label">{g.label}</div>
123
- {g.models.map((m) => (
124
- <button
125
- key={m.id}
126
- className={'ae-model-row' + (current.id === m.id ? ' active' : '')}
127
- onClick={() => {
128
- onPick(m);
129
- setOpen(false);
130
- }}
131
- >
132
- <span className="ae-model-name">
133
- {m.name}
134
- {m.tier && <span className="ae-badge">{m.tier}</span>}
135
- </span>
136
- {m.description && <span className="ae-model-desc">{m.description}</span>}
137
- </button>
138
- ))}
139
- </div>
140
- ))}
141
- </div>
142
- <a className="ae-plan-banner" href="https://console.hanzo.ai/pricing" target="_blank" rel="noreferrer">
143
- <span>Unlock every model</span>
144
- <span className="ae-plan-tiers">
145
- {PLAN_TIERS.map((t) => (
146
- <span key={t.name} className="ae-plan-tier">
147
- {t.name} <b>{t.price}</b>
148
- </span>
149
- ))}
150
- </span>
151
- </a>
152
- </div>
153
- )}
154
- </div>
155
- );
156
- }
157
-
158
- function SourceCard({ s, index }: { s: SearchSource; index: number }) {
159
- let host = '';
160
- try {
161
- host = new URL(s.url).hostname.replace(/^www\./, '');
162
- } catch {
163
- host = s.url;
164
- }
165
- return (
166
- <a className="ae-source" href={s.url} target="_blank" rel="noreferrer" title={s.title}>
167
- <span className="ae-source-head">
168
- {s.favicon ? <img src={s.favicon} alt="" width="14" height="14" /> : <span className="ae-dot" />}
169
- <span className="ae-source-host">{host}</span>
170
- <span className="ae-source-idx">{index + 1}</span>
171
- </span>
172
- <span className="ae-source-title">{s.title}</span>
173
- </a>
174
- );
175
- }
176
-
177
- function InputCard({
178
- value,
179
- onChange,
180
- onSubmit,
181
- mode,
182
- setMode,
183
- sources,
184
- toggleSource,
185
- models,
186
- model,
187
- setModel,
188
- busy,
189
- }: {
190
- value: string;
191
- onChange: (v: string) => void;
192
- onSubmit: () => void;
193
- mode: SearchMode;
194
- setMode: (m: SearchMode) => void;
195
- sources: Set<string>;
196
- toggleSource: (s: string) => void;
197
- models: ModelGroup[];
198
- model: ChatModel;
199
- setModel: (m: ChatModel) => void;
200
- busy: boolean;
201
- }) {
202
- const taRef = useRef<HTMLTextAreaElement>(null);
203
- useEffect(() => {
204
- const ta = taRef.current;
205
- if (!ta) return;
206
- ta.style.height = 'auto';
207
- ta.style.height = Math.min(ta.scrollHeight, 200) + 'px';
208
- }, [value]);
209
-
210
- return (
211
- <div className="ae-card">
212
- <textarea
213
- ref={taRef}
214
- className="ae-input"
215
- placeholder="Type @ for sources or / for modes"
216
- value={value}
217
- rows={1}
218
- onChange={(e) => onChange(e.target.value)}
219
- onKeyDown={(e) => {
220
- if (e.key === 'Enter' && !e.shiftKey) {
221
- e.preventDefault();
222
- onSubmit();
223
- }
224
- }}
225
- />
226
- <div className="ae-card-row">
227
- <div className="ae-chips">
228
- {SOURCE_CHIPS.map((s) => (
229
- <button
230
- key={s}
231
- className={'ae-chip' + (sources.has(s) ? ' on' : '')}
232
- onClick={() => toggleSource(s)}
233
- title={`@${s}`}
234
- >
235
- @{s}
236
- </button>
237
- ))}
238
- </div>
239
- <div className="ae-card-right">
240
- <div className="ae-modes">
241
- {MODES.map((m) => (
242
- <button
243
- key={m.id}
244
- className={'ae-mode' + (mode === m.id ? ' on' : '')}
245
- onClick={() => setMode(m.id)}
246
- title={m.hint}
247
- >
248
- {m.label}
249
- </button>
250
- ))}
251
- </div>
252
- <ModelPicker groups={models} current={model} onPick={setModel} />
253
- <button className="ae-send" onClick={onSubmit} disabled={busy || !value.trim()} title="Search (Enter)">
254
- {busy ? (
255
- <span className="ae-spinner" />
256
- ) : (
257
- <svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true">
258
- <path d="M3 13V3l10 5-10 5z" fill="currentColor" />
259
- </svg>
260
- )}
261
- </button>
262
- </div>
263
- </div>
264
- </div>
265
- );
266
- }
267
-
268
64
  export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: AnswerEngineProps) {
269
- const [collapsed, setCollapsed] = useState(false);
65
+ // Sidebar hidden by default — the answer surface should read like hanzo.chat:
66
+ // a single centered column. A fixed toggle (below) brings the rail back.
67
+ const [collapsed, setCollapsed] = useState(true);
270
68
  const [query, setQuery] = useState('');
271
69
  const [submitted, setSubmitted] = useState('');
272
- const [mode, setMode] = useState<SearchMode>('search');
70
+ const [mode, setMode] = useState<Mode>('search');
273
71
  const [sources, setSources] = useState<Set<string>>(new Set());
274
72
  const [modelGroups, setModelGroups] = useState<ModelGroup[]>([]);
275
73
  const [model, setModel] = useState<ChatModel>(AUTO_MODEL);
276
74
  const [news, setNews] = useState<NewsItem[]>([]);
75
+ // True once the user picks a model themselves, so the catalog's default-to-Enso
76
+ // never overwrites a deliberate choice made while the fetch was still in flight.
77
+ const picked = useRef(false);
78
+ const chooseModel = useCallback((m: ChatModel) => {
79
+ picked.current = true;
80
+ setModel(m);
81
+ }, []);
277
82
 
278
83
  const [phase, setPhase] = useState<'idle' | 'running' | 'done'>('idle');
279
84
  const [status, setStatus] = useState('');
@@ -282,15 +87,32 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
282
87
  const [followUps, setFollowUps] = useState<string[]>([]);
283
88
  const [error, setError] = useState('');
284
89
  const [needAuth, setNeedAuth] = useState(false);
90
+ // The engine an unauthenticated query falls back to. Read once; the default
91
+ // stands until storage answers, so a query typed in the first moments after a
92
+ // new tab opens still has somewhere to go.
93
+ const [providerId, setProviderId] = useState<string>(DEFAULT_PROVIDER_ID);
285
94
  const abortRef = useRef<AbortController | null>(null);
286
95
 
287
96
  // Load real model catalog + live news (both public — work signed out).
288
- // Default stays on Auto ("routes to the best model"); the picker changes it.
97
+ //
98
+ // Enso is the default, selected once the catalog lands. It cannot be the
99
+ // useState seed: the catalog is fetched at runtime, so naming a model before
100
+ // it arrives would hardcode an id the server may not serve — the whole point
101
+ // of model-catalog.ts is that the list is never fabricated. AUTO_MODEL is the
102
+ // seed and the fallback, so a failed/slow fetch degrades to "routes to the
103
+ // best model" instead of a dead selection. Only the initial pick is
104
+ // overridden: `picked` guards a user's choice against a late catalog resolve.
289
105
  useEffect(() => {
290
- fetchModelCatalog(apiBase)
291
- .then(({ groups }) => setModelGroups(groups))
106
+ fetchModelCatalog()
107
+ .then(({ groups }) => {
108
+ setModelGroups(groups);
109
+ if (picked.current) return;
110
+ const enso = groups.find((g) => g.family === 'enso')?.models[0];
111
+ if (enso) setModel(enso);
112
+ })
292
113
  .catch(() => {});
293
114
  fetchNews().then(setNews).catch(() => {});
115
+ loadProviderId().then(setProviderId).catch(() => {});
294
116
  }, [apiBase]);
295
117
 
296
118
  const client = useMemo(
@@ -314,9 +136,33 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
314
136
  const ctrl = new AbortController();
315
137
  abortRef.current = ctrl;
316
138
 
139
+ // NO IDENTITY, NO DEAD END. /v1/ask is metered and answers 401 to a
140
+ // signed-out caller, but this surface IS the browser's search box: a query
141
+ // that returns a sign-in card has broken the address bar rather than shown a
142
+ // paywall. Hand it to the configured engine instead, before any spinner —
143
+ // checking first is what makes the handoff instant rather than a flash of
144
+ // "Searching the web" followed by a navigation.
145
+ //
146
+ // The fallback is not a Hanzo call: no token, no proxy, no telemetry. The
147
+ // query goes from this browser straight to the engine the user chose.
148
+ let identified = false;
149
+ try {
150
+ identified = Boolean(await getToken());
151
+ } catch {
152
+ identified = false;
153
+ }
154
+ if (!identified) {
155
+ const url = fallbackUrl(providerId, question);
156
+ if (url) {
157
+ void capture('answer_search_fallback', { provider: providerId, mode });
158
+ window.location.assign(url);
159
+ return;
160
+ }
161
+ }
162
+
317
163
  setSubmitted(question);
318
164
  setPhase('running');
319
- setStatus('Searching the web');
165
+ setStatus(mode === 'chat' ? 'Thinking' : 'Searching the web');
320
166
  setAnswer('');
321
167
  setAnswerSources([]);
322
168
  setFollowUps([]);
@@ -325,23 +171,26 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
325
171
  void capture('answer_search', { mode, model: model.id });
326
172
  let fullAnswer = '';
327
173
 
328
- const opts = {
329
- mode,
330
- model: model.id,
331
- sources: [...sources],
332
- signal: ctrl.signal,
333
- };
174
+ const stream =
175
+ mode === 'chat'
176
+ ? converse(client, question, model.id, ctrl.signal)
177
+ : (client.search(question, {
178
+ mode,
179
+ model: model.id,
180
+ sources: [...sources],
181
+ signal: ctrl.signal,
182
+ }) as AsyncGenerator<SearchEvent>);
334
183
  try {
335
- for await (const ev of client.search(question, opts) as AsyncGenerator<SearchEvent>) {
184
+ for await (const ev of stream) {
336
185
  switch (ev.type) {
337
186
  case 'status':
338
187
  setStatus(
339
188
  ev.stage === 'planning'
340
- ? 'Planning research'
189
+ ? 'Planning research' + (ev.detail ? `: ${ev.detail}` : '')
341
190
  : ev.stage === 'searching'
342
191
  ? 'Searching the web' + (ev.detail ? `: ${ev.detail}` : '')
343
192
  : ev.stage === 'reading'
344
- ? 'Reading sources'
193
+ ? 'Reading sources' + (ev.detail ? `: ${ev.detail}` : '')
345
194
  : 'Writing the answer',
346
195
  );
347
196
  break;
@@ -379,7 +228,7 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
379
228
  setPhase('done');
380
229
  }
381
230
  },
382
- [client, mode, model, sources],
231
+ [client, mode, model, sources, getToken, providerId],
383
232
  );
384
233
 
385
234
  // Fire the initial (address-bar) query once models are ready enough.
@@ -412,76 +261,39 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
412
261
  setNeedAuth(false);
413
262
  }, []);
414
263
 
264
+ const composer = (busy: boolean) => (
265
+ <Composer
266
+ value={query}
267
+ onChange={setQuery}
268
+ onSubmit={submit}
269
+ mode={mode}
270
+ setMode={setMode}
271
+ sources={sources}
272
+ toggleSource={toggleSource}
273
+ models={modelGroups}
274
+ model={model}
275
+ setModel={chooseModel}
276
+ busy={busy}
277
+ />
278
+ );
279
+
415
280
  return (
416
281
  <div className={'ae-root' + (collapsed ? ' collapsed' : '')}>
417
- <aside className="ae-sidebar">
418
- <div className="ae-side-top">
419
- <button className="ae-brand" onClick={newThread} title="Hanzo">
420
- <HanzoMark size={22} />
421
- {!collapsed && <span>Hanzo</span>}
422
- </button>
423
- <button className="ae-collapse" onClick={() => setCollapsed((v) => !v)} title="Toggle sidebar">
424
- <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true">
425
- <path d="M6 3v10M3 3h10v10H3z" fill="none" stroke="currentColor" strokeWidth="1.3" />
426
- </svg>
427
- </button>
428
- </div>
429
- <button className="ae-new" onClick={newThread}>
430
- <svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true">
431
- <path d="M8 3v10M3 8h10" fill="none" stroke="currentColor" strokeWidth="1.5" />
432
- </svg>
433
- {!collapsed && <span>New thread</span>}
434
- </button>
435
- <nav className="ae-nav">
436
- <a href="https://hanzo.chat" target="_blank" rel="noreferrer">Threads</a>
437
- <a href="https://docs.hanzo.ai" target="_blank" rel="noreferrer">Docs</a>
438
- <a href="https://hanzo.ai" target="_blank" rel="noreferrer">About</a>
439
- </nav>
440
- <div className="ae-side-bottom">
441
- <button className="ae-signin" onClick={signIn}>
442
- {collapsed ? '↪' : 'Sign in — free to start'}
443
- </button>
444
- </div>
445
- </aside>
282
+ {/* No fixed reveal button: the rail itself is always present now, and it
283
+ carries its own expand control. A floating toggle only existed because
284
+ the collapsed rail rendered nothing to click. */}
285
+ <Rail
286
+ collapsed={collapsed}
287
+ toggle={() => setCollapsed((v) => !v)}
288
+ newThread={newThread}
289
+ signIn={signIn}
290
+ />
446
291
 
447
292
  <main className="ae-main">
448
293
  {phase === 'idle' ? (
449
294
  <div className="ae-hero">
450
- <div className="ae-wordmark">
451
- <HanzoMark size={44} />
452
- <span>Hanzo</span>
453
- </div>
454
- <div className="ae-hero-card">
455
- <InputCard
456
- value={query}
457
- onChange={setQuery}
458
- onSubmit={submit}
459
- mode={mode}
460
- setMode={setMode}
461
- sources={sources}
462
- toggleSource={toggleSource}
463
- models={modelGroups}
464
- model={model}
465
- setModel={setModel}
466
- busy={false}
467
- />
468
- </div>
469
- {news.length > 0 && (
470
- <div className="ae-news">
471
- <div className="ae-news-head">Top stories</div>
472
- <div className="ae-news-grid">
473
- {news.slice(0, 6).map((n) => (
474
- <a key={n.url} className="ae-news-item" href={n.url} target="_blank" rel="noreferrer">
475
- <span className="ae-news-title">{n.title}</span>
476
- <span className="ae-news-meta">
477
- {n.source}
478
- {typeof n.points === 'number' ? ` · ${n.points} pts` : ''}
479
- </span>
480
- </a>
481
- ))}
482
- </div>
483
- </div>
484
- )}
295
+ <div className="ae-hero-card">{composer(false)}</div>
296
+ <Stories items={news} />
485
297
  </div>
486
298
  ) : (
487
299
  <div className="ae-answer-wrap">
@@ -491,7 +303,7 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
491
303
  {answerSources.length > 0 && (
492
304
  <div className="ae-sources">
493
305
  {answerSources.map((s, i) => (
494
- <SourceCard key={s.url} s={s} index={i} />
306
+ <Source key={s.url} source={s} index={i} />
495
307
  ))}
496
308
  </div>
497
309
  )}
@@ -503,19 +315,45 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
503
315
  )}
504
316
 
505
317
  {needAuth ? (
318
+ /* Reached only when a token EXISTED and the call still came back
319
+ 401 — an expired or revoked session, since a signed-out query
320
+ never gets here (run() hands it to the fallback engine first).
321
+ Both doors are offered: renew the session for an AI answer, or
322
+ take the same query to the configured engine. A dead end here
323
+ would strand someone who simply needs to sign in again. */
506
324
  <div className="ae-auth">
507
- <p>Sign in with Hanzo to get AI answers.</p>
325
+ <p>Your Hanzo session expired. Sign in again for AI answers.</p>
508
326
  <button className="ae-signin big" onClick={signIn}>
509
- Sign in — free to start
327
+ Sign in
510
328
  </button>
329
+ <a
330
+ className="ae-fallback-link"
331
+ href={fallbackUrl(providerId, submitted) || undefined}
332
+ >
333
+ Search {providerById(providerId).label} instead
334
+ </a>
511
335
  </div>
512
336
  ) : error ? (
513
337
  <div className="ae-error">{error}</div>
514
338
  ) : (
515
- <div
516
- className="ae-answer markdown"
517
- dangerouslySetInnerHTML={{ __html: renderMarkdown(answer) }}
518
- />
339
+ /* The answer picks its own presentation: any widget blocks it
340
+ emitted render as real components, and the prose is what is
341
+ left after they are removed — so a widget is never also shown
342
+ as raw JSON. Extraction runs per frame against a STREAMING,
343
+ half-written document, which is why an unterminated fence is
344
+ left alone until it closes. */
345
+ (() => {
346
+ const { prose, widgets } = extractWidgets(answer);
347
+ return (
348
+ <>
349
+ <Widgets widgets={widgets} />
350
+ <div
351
+ className="ae-answer markdown"
352
+ dangerouslySetInnerHTML={{ __html: renderMarkdown(prose) }}
353
+ />
354
+ </>
355
+ );
356
+ })()
519
357
  )}
520
358
 
521
359
  {followUps.length > 0 && (
@@ -538,21 +376,7 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
538
376
  )}
539
377
  </div>
540
378
 
541
- <div className="ae-answer-composer">
542
- <InputCard
543
- value={query}
544
- onChange={setQuery}
545
- onSubmit={submit}
546
- mode={mode}
547
- setMode={setMode}
548
- sources={sources}
549
- toggleSource={toggleSource}
550
- models={modelGroups}
551
- model={model}
552
- setModel={setModel}
553
- busy={phase === 'running'}
554
- />
555
- </div>
379
+ <div className="ae-answer-composer">{composer(phase === 'running')}</div>
556
380
  </div>
557
381
  )}
558
382
  </main>