@hanzo/browser-extension 1.9.36 → 1.9.49

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.
@@ -1,561 +0,0 @@
1
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
- import { createAiClient, type SearchEvent, type SearchMode, type SearchSource } from '@hanzo/ai';
3
- import { fetchNews, type NewsItem } from './news.js';
4
- import { AUTO_MODEL, fetchModelCatalog, type ChatModel, type ModelGroup } from './model-catalog.js';
5
- import { renderMarkdown } from './markdown.js';
6
- import { capture, contributeTrainingSample } from '../shared/consent.js';
7
-
8
- /**
9
- * Hanzo Answer Engine — the shared AI-answer surface (query → streamed answer +
10
- * 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.
14
- */
15
-
16
- export interface AnswerEngineProps {
17
- apiBase: string;
18
- /** Resolves the current IAM bearer, or null when signed out. */
19
- getToken: () => Promise<string | null>;
20
- /** Kicks off IAM sign-in (opens the OAuth tab). */
21
- signIn: () => void;
22
- /** Optional initial query (from the omnibox / address bar `?q=`). */
23
- initialQuery?: string;
24
- }
25
-
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
- export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: AnswerEngineProps) {
269
- const [collapsed, setCollapsed] = useState(false);
270
- const [query, setQuery] = useState('');
271
- const [submitted, setSubmitted] = useState('');
272
- const [mode, setMode] = useState<SearchMode>('search');
273
- const [sources, setSources] = useState<Set<string>>(new Set());
274
- const [modelGroups, setModelGroups] = useState<ModelGroup[]>([]);
275
- const [model, setModel] = useState<ChatModel>(AUTO_MODEL);
276
- const [news, setNews] = useState<NewsItem[]>([]);
277
-
278
- const [phase, setPhase] = useState<'idle' | 'running' | 'done'>('idle');
279
- const [status, setStatus] = useState('');
280
- const [answer, setAnswer] = useState('');
281
- const [answerSources, setAnswerSources] = useState<SearchSource[]>([]);
282
- const [followUps, setFollowUps] = useState<string[]>([]);
283
- const [error, setError] = useState('');
284
- const [needAuth, setNeedAuth] = useState(false);
285
- const abortRef = useRef<AbortController | null>(null);
286
-
287
- // 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.
289
- useEffect(() => {
290
- fetchModelCatalog(apiBase)
291
- .then(({ groups }) => setModelGroups(groups))
292
- .catch(() => {});
293
- fetchNews().then(setNews).catch(() => {});
294
- }, [apiBase]);
295
-
296
- const client = useMemo(
297
- () =>
298
- createAiClient({
299
- baseUrl: apiBase,
300
- getToken: async () => {
301
- const t = await getToken();
302
- if (!t) throw new Error('__NO_TOKEN__');
303
- return t;
304
- },
305
- }),
306
- [apiBase, getToken],
307
- );
308
-
309
- const run = useCallback(
310
- async (q: string) => {
311
- const question = q.trim();
312
- if (!question) return;
313
- abortRef.current?.abort();
314
- const ctrl = new AbortController();
315
- abortRef.current = ctrl;
316
-
317
- setSubmitted(question);
318
- setPhase('running');
319
- setStatus('Searching the web');
320
- setAnswer('');
321
- setAnswerSources([]);
322
- setFollowUps([]);
323
- setError('');
324
- setNeedAuth(false);
325
- void capture('answer_search', { mode, model: model.id });
326
- let fullAnswer = '';
327
-
328
- const opts = {
329
- mode,
330
- model: model.id,
331
- sources: [...sources],
332
- signal: ctrl.signal,
333
- };
334
- try {
335
- for await (const ev of client.search(question, opts) as AsyncGenerator<SearchEvent>) {
336
- switch (ev.type) {
337
- case 'status':
338
- setStatus(
339
- ev.stage === 'planning'
340
- ? 'Planning research'
341
- : ev.stage === 'searching'
342
- ? 'Searching the web' + (ev.detail ? `: ${ev.detail}` : '')
343
- : ev.stage === 'reading'
344
- ? 'Reading sources'
345
- : 'Writing the answer',
346
- );
347
- break;
348
- case 'sources':
349
- setAnswerSources(ev.sources);
350
- break;
351
- case 'text':
352
- fullAnswer += ev.delta;
353
- setAnswer((a) => a + ev.delta);
354
- break;
355
- case 'follow_ups':
356
- setFollowUps(ev.questions);
357
- break;
358
- case 'done':
359
- setPhase('done');
360
- void capture('answer_shown', { mode, model: model.id });
361
- // Opt-in only: no-ops unless the user turned on training
362
- // contribution (the consent module gates the send).
363
- void contributeTrainingSample({ query: question, answer: fullAnswer, model: model.id });
364
- break;
365
- case 'error':
366
- if (ev.error.includes('__NO_TOKEN__') || /401|invalid api key/i.test(ev.error)) {
367
- setNeedAuth(true);
368
- } else {
369
- setError(ev.error);
370
- }
371
- setPhase('done');
372
- break;
373
- }
374
- }
375
- } catch (e) {
376
- const msg = e instanceof Error ? e.message : String(e);
377
- if (msg.includes('__NO_TOKEN__') || /401|invalid api key/i.test(msg)) setNeedAuth(true);
378
- else setError(msg);
379
- setPhase('done');
380
- }
381
- },
382
- [client, mode, model, sources],
383
- );
384
-
385
- // Fire the initial (address-bar) query once models are ready enough.
386
- const didInit = useRef(false);
387
- useEffect(() => {
388
- if (didInit.current || !initialQuery) return;
389
- didInit.current = true;
390
- setQuery(initialQuery);
391
- void run(initialQuery);
392
- }, [initialQuery, run]);
393
-
394
- const submit = useCallback(() => void run(query), [query, run]);
395
- const toggleSource = useCallback((s: string) => {
396
- setSources((prev) => {
397
- const next = new Set(prev);
398
- next.has(s) ? next.delete(s) : next.add(s);
399
- return next;
400
- });
401
- }, []);
402
-
403
- const newThread = useCallback(() => {
404
- abortRef.current?.abort();
405
- setPhase('idle');
406
- setQuery('');
407
- setSubmitted('');
408
- setAnswer('');
409
- setAnswerSources([]);
410
- setFollowUps([]);
411
- setError('');
412
- setNeedAuth(false);
413
- }, []);
414
-
415
- return (
416
- <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>
446
-
447
- <main className="ae-main">
448
- {phase === 'idle' ? (
449
- <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
- )}
485
- </div>
486
- ) : (
487
- <div className="ae-answer-wrap">
488
- <div className="ae-answer-scroll">
489
- <h1 className="ae-question">{submitted}</h1>
490
-
491
- {answerSources.length > 0 && (
492
- <div className="ae-sources">
493
- {answerSources.map((s, i) => (
494
- <SourceCard key={s.url} s={s} index={i} />
495
- ))}
496
- </div>
497
- )}
498
-
499
- {phase === 'running' && !answer && (
500
- <div className="ae-status">
501
- <span className="ae-spinner" /> {status}…
502
- </div>
503
- )}
504
-
505
- {needAuth ? (
506
- <div className="ae-auth">
507
- <p>Sign in with Hanzo to get AI answers.</p>
508
- <button className="ae-signin big" onClick={signIn}>
509
- Sign in — free to start
510
- </button>
511
- </div>
512
- ) : error ? (
513
- <div className="ae-error">{error}</div>
514
- ) : (
515
- <div
516
- className="ae-answer markdown"
517
- dangerouslySetInnerHTML={{ __html: renderMarkdown(answer) }}
518
- />
519
- )}
520
-
521
- {followUps.length > 0 && (
522
- <div className="ae-followups">
523
- <div className="ae-followups-head">Follow-up</div>
524
- {followUps.map((f) => (
525
- <button
526
- key={f}
527
- className="ae-followup"
528
- onClick={() => {
529
- setQuery(f);
530
- void run(f);
531
- }}
532
- >
533
- {f}
534
- <span className="ae-followup-arrow">→</span>
535
- </button>
536
- ))}
537
- </div>
538
- )}
539
- </div>
540
-
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>
556
- </div>
557
- )}
558
- </main>
559
- </div>
560
- );
561
- }
package/src/callback.html DELETED
@@ -1,17 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Hanzo AI — Signing in...</title>
6
- <style>
7
- body { background: #000; color: #fff; font-family: system-ui, sans-serif; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; }
8
- .msg { text-align: center; opacity: 0.7; }
9
- </style>
10
- </head>
11
- <body>
12
- <div class="msg">
13
- <p>Signing in to Hanzo AI...</p>
14
- <p><small>This tab will close automatically.</small></p>
15
- </div>
16
- </body>
17
- </html>
@@ -1,96 +0,0 @@
1
- import React from 'react';
2
- import { createRoot } from 'react-dom/client';
3
- import { flushSync } from 'react-dom';
4
- import {
5
- Button,
6
- Card,
7
- CardContent,
8
- CardDescription,
9
- CardHeader,
10
- CardTitle,
11
- Textarea,
12
- } from '@hanzo/gui';
13
-
14
- function LoginPrompt() {
15
- return (
16
- <Card className="chat-modern-login-card">
17
- <CardHeader>
18
- <CardTitle>Chat with Zen AI models</CardTitle>
19
- <CardDescription>Models enabled in Hanzo Cloud are loaded automatically.</CardDescription>
20
- </CardHeader>
21
- <CardContent>
22
- <Button id="auth-btn" className="chat-modern-auth-btn" type="button">
23
- Sign in
24
- </Button>
25
- <Button id="signup-btn" className="secondary-btn" type="button">
26
- Create account
27
- </Button>
28
- <p className="auth-note">
29
- Browser tools work without sign-in.{' '}
30
- <a href="https://docs.hanzo.ai" target="_blank" rel="noreferrer">
31
- Learn more
32
- </a>
33
- </p>
34
- </CardContent>
35
- </Card>
36
- );
37
- }
38
-
39
- function ChatComposer() {
40
- return (
41
- <div className="chat-modern-composer">
42
- <div className="model-selector">
43
- <select id="model-select">
44
- <option value="claude-sonnet-4-20250514">Claude Sonnet 4</option>
45
- <option value="claude-opus-4-20250514">Claude Opus 4</option>
46
- <option value="gpt-4o">GPT-4o</option>
47
- <option value="zen-coder-flash">Zen Coder Flash</option>
48
- <option value="zen-max">Zen Max</option>
49
- </select>
50
- </div>
51
-
52
- <div className="chat-flags">
53
- <label className="flag-toggle">
54
- <input type="checkbox" id="rag-enabled" defaultChecked />
55
- <span>RAG</span>
56
- </label>
57
- <label className="flag-toggle">
58
- <input type="checkbox" id="tab-context-enabled" defaultChecked />
59
- <span>Tab Context</span>
60
- </label>
61
- <span id="rag-status" className="rag-status">
62
- Ready
63
- </span>
64
- </div>
65
-
66
- <div className="input-row">
67
- <Textarea id="chat-input" className="chat-modern-input" placeholder="Ask anything..." rows={1} />
68
- <Button id="send-btn" className="send-btn chat-modern-send" title="Send" type="button">
69
- <svg viewBox="0 0 20 20" fill="none" stroke="currentColor" aria-hidden="true">
70
- <path d="M4 10l12-6-6 12-2-6-4-2z" strokeWidth="1.5" fill="currentColor" />
71
- </svg>
72
- </Button>
73
- </div>
74
- </div>
75
- );
76
- }
77
-
78
- export function mountModernChatWidget() {
79
- const loginTarget = document.getElementById('chat-login-prompt');
80
- if (loginTarget) {
81
- loginTarget.innerHTML = '';
82
- const loginRoot = createRoot(loginTarget);
83
- flushSync(() => {
84
- loginRoot.render(<LoginPrompt />);
85
- });
86
- }
87
-
88
- const composerTarget = document.getElementById('chat-composer');
89
- if (composerTarget) {
90
- composerTarget.innerHTML = '';
91
- const composerRoot = createRoot(composerTarget);
92
- flushSync(() => {
93
- composerRoot.render(<ChatComposer />);
94
- });
95
- }
96
- }