@hanzo/browser-extension 1.9.54 → 1.9.55
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.
- package/package.json +3 -2
- package/src/Chat.tsx +164 -0
- package/src/answer/AnswerEngine.tsx +140 -115
- package/src/answer/Toolbar.tsx +93 -0
- package/src/newtab.css +10 -464
- package/src/shared/Prose.tsx +29 -0
- package/src/sidebar.css +16 -418
- package/src/sidebar.html +10 -71
- package/src/answer/Composer.tsx +0 -147
- package/src/answer/Models.tsx +0 -118
- package/src/answer/Source.tsx +0 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/browser-extension",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.55",
|
|
4
4
|
"description": "Hanzo AI Browser Extension",
|
|
5
5
|
"main": "dist/background.js",
|
|
6
6
|
"dependencies": {
|
|
@@ -8,9 +8,10 @@
|
|
|
8
8
|
"@hanzo/data": "^1.2.3",
|
|
9
9
|
"@hanzo/event": "^0.3.18",
|
|
10
10
|
"@hanzo/gui": "^8.1.1",
|
|
11
|
-
"@hanzo/ui": "^8.
|
|
11
|
+
"@hanzo/ui": "^8.1.2",
|
|
12
12
|
"@hanzo/usage": "^0.1.6",
|
|
13
13
|
"@hanzogui/config": "^8.1.1",
|
|
14
|
+
"@hanzogui/lucide-icons-2": "^8.1.1",
|
|
14
15
|
"@supabase/supabase-js": "^2.50.3",
|
|
15
16
|
"axios": "^1.10.0",
|
|
16
17
|
"chalk": "^4.1.2",
|
package/src/Chat.tsx
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Button, Checkbox, SizableText, XStack, YStack } from '@hanzo/ui';
|
|
3
|
+
import { Composer, Failure, Message, Thread } from '@hanzo/ui/chat';
|
|
4
|
+
import { ModelSelector, type ModelCatalogEntry } from '@hanzo/ui/models';
|
|
5
|
+
import { Prose } from './shared/Prose.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The sidebar's chat surface — `@hanzo/ui/chat`, the same shell the new-tab
|
|
9
|
+
* answer engine and every other Hanzo surface draw with.
|
|
10
|
+
*
|
|
11
|
+
* The sidebar is the narrow client: ~360px, an MV3 extension page, and a
|
|
12
|
+
* transport that is the service worker rather than a fetch loop. None of that
|
|
13
|
+
* reaches the presentation. Every turn, the draft, the model and the busy flag
|
|
14
|
+
* arrive as props and every action leaves as a callback, so `sidebar.ts` keeps
|
|
15
|
+
* the whole wire — token brokering, retrieval, budgets, dedupe, the stream —
|
|
16
|
+
* and this file keeps none of it.
|
|
17
|
+
*
|
|
18
|
+
* Width is the one thing the shell is asked to bend on. `Thread` caps prose at a
|
|
19
|
+
* reading measure and centres it, which in a ~360px column would inset the text
|
|
20
|
+
* from both edges, so it is told to fill — and its gutters come from the wrapper
|
|
21
|
+
* here, because the shell drops its own padding along with the cap. The model
|
|
22
|
+
* picker's trigger is `width: "100%"`, so it is boxed: left free it takes the
|
|
23
|
+
* whole toolbar row and pushes the send control off the edge.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** How wide the model picker is allowed to be in a sidebar toolbar row. */
|
|
27
|
+
const PICKER = 132;
|
|
28
|
+
|
|
29
|
+
export interface Turn {
|
|
30
|
+
role: 'user' | 'assistant' | 'system';
|
|
31
|
+
content: string;
|
|
32
|
+
/** The turn failed. Rendered as the shell's Failure, with a retry. */
|
|
33
|
+
error?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ChatProps {
|
|
37
|
+
turns: Turn[];
|
|
38
|
+
draft: string;
|
|
39
|
+
onDraft: (value: string) => void;
|
|
40
|
+
onSend: () => void;
|
|
41
|
+
onStop: () => void;
|
|
42
|
+
/** Run the last question again. */
|
|
43
|
+
onRetry: () => void;
|
|
44
|
+
busy: boolean;
|
|
45
|
+
models: ModelCatalogEntry[];
|
|
46
|
+
model: string;
|
|
47
|
+
onModel: (id: string) => void;
|
|
48
|
+
/** Whether retrieval runs before the turn, and whether it sees the open tab. */
|
|
49
|
+
rag: boolean;
|
|
50
|
+
onRag: (on: boolean) => void;
|
|
51
|
+
tab: boolean;
|
|
52
|
+
onTab: (on: boolean) => void;
|
|
53
|
+
/** What retrieval last did. Shown at the end of the composer's toolbar row. */
|
|
54
|
+
status: string;
|
|
55
|
+
signedIn: boolean;
|
|
56
|
+
onSignIn: () => void;
|
|
57
|
+
onSignUp: () => void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A named toggle, sized for the composer's toolbar row. */
|
|
61
|
+
function Toggle({
|
|
62
|
+
label,
|
|
63
|
+
hint,
|
|
64
|
+
on,
|
|
65
|
+
onChange,
|
|
66
|
+
}: {
|
|
67
|
+
label: string;
|
|
68
|
+
hint: string;
|
|
69
|
+
on: boolean;
|
|
70
|
+
onChange: (on: boolean) => void;
|
|
71
|
+
}) {
|
|
72
|
+
return (
|
|
73
|
+
<XStack items="center" gap="$1" title={hint}>
|
|
74
|
+
<Checkbox
|
|
75
|
+
size="$2"
|
|
76
|
+
checked={on}
|
|
77
|
+
onCheckedChange={(v) => onChange(v === true)}
|
|
78
|
+
aria-label={hint}
|
|
79
|
+
/>
|
|
80
|
+
<SizableText size="$1" color="$color10">
|
|
81
|
+
{label}
|
|
82
|
+
</SizableText>
|
|
83
|
+
</XStack>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function Chat(props: ChatProps) {
|
|
88
|
+
const { turns, busy, signedIn } = props;
|
|
89
|
+
|
|
90
|
+
if (!signedIn) {
|
|
91
|
+
return (
|
|
92
|
+
<YStack flex={1} justify="center" items="center" gap="$3" p="$5">
|
|
93
|
+
<SizableText size="$5" fontWeight="600">
|
|
94
|
+
Sign in to Hanzo AI
|
|
95
|
+
</SizableText>
|
|
96
|
+
<SizableText size="$2" color="$color10" text="center">
|
|
97
|
+
Chat with Zen AI models, use browser tools, and build with AI agents.
|
|
98
|
+
</SizableText>
|
|
99
|
+
<Button width="100%" onPress={props.onSignIn}>
|
|
100
|
+
Sign in
|
|
101
|
+
</Button>
|
|
102
|
+
<Button width="100%" variant="outline" onPress={props.onSignUp}>
|
|
103
|
+
Create account
|
|
104
|
+
</Button>
|
|
105
|
+
<SizableText size="$1" color="$color10" text="center">
|
|
106
|
+
Browser tools work without sign-in.{' '}
|
|
107
|
+
<a href="https://docs.hanzo.ai" target="_blank" rel="noreferrer">
|
|
108
|
+
Learn more
|
|
109
|
+
</a>
|
|
110
|
+
</SizableText>
|
|
111
|
+
</YStack>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<YStack flex={1} minH={0}>
|
|
117
|
+
<YStack flex={1} minH={0} px="$3">
|
|
118
|
+
<Thread maxWidth={0} gap={16}>
|
|
119
|
+
{turns.length === 0 ? (
|
|
120
|
+
<Message role="system">Ask anything. Powered by Hanzo Cloud.</Message>
|
|
121
|
+
) : (
|
|
122
|
+
turns.map((t, i) => (
|
|
123
|
+
<Message
|
|
124
|
+
key={i}
|
|
125
|
+
role={t.role}
|
|
126
|
+
busy={busy && i === turns.length - 1 && t.role === 'assistant' && !t.content}
|
|
127
|
+
>
|
|
128
|
+
{t.error ? (
|
|
129
|
+
<Failure onRetry={props.onRetry}>{t.error}</Failure>
|
|
130
|
+
) : t.role === 'assistant' ? (
|
|
131
|
+
<Prose text={t.content} />
|
|
132
|
+
) : (
|
|
133
|
+
t.content
|
|
134
|
+
)}
|
|
135
|
+
</Message>
|
|
136
|
+
))
|
|
137
|
+
)}
|
|
138
|
+
</Thread>
|
|
139
|
+
</YStack>
|
|
140
|
+
|
|
141
|
+
<YStack p="$2">
|
|
142
|
+
<Composer
|
|
143
|
+
value={props.draft}
|
|
144
|
+
onChange={props.onDraft}
|
|
145
|
+
onSend={props.onSend}
|
|
146
|
+
onStop={props.onStop}
|
|
147
|
+
busy={busy}
|
|
148
|
+
hint={props.status}
|
|
149
|
+
>
|
|
150
|
+
<XStack width={PICKER} shrink={0}>
|
|
151
|
+
<ModelSelector
|
|
152
|
+
models={props.models}
|
|
153
|
+
value={props.model}
|
|
154
|
+
onChange={props.onModel}
|
|
155
|
+
size="sm"
|
|
156
|
+
/>
|
|
157
|
+
</XStack>
|
|
158
|
+
<Toggle label="RAG" hint="Retrieval context" on={props.rag} onChange={props.onRag} />
|
|
159
|
+
<Toggle label="Tab" hint="Include active tab" on={props.tab} onChange={props.onTab} />
|
|
160
|
+
</Composer>
|
|
161
|
+
</YStack>
|
|
162
|
+
</YStack>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { createAiClient, type AiClient, type SearchEvent, type SearchSource } from '@hanzo/ai';
|
|
3
|
+
import { Button, SizableText, XStack, YStack } from '@hanzo/ui';
|
|
4
|
+
import { Composer, Failure, Message, Sources, Step, Thread, type Source } from '@hanzo/ui/chat';
|
|
5
|
+
import { ModelSelector, type ModelCatalogEntry } from '@hanzo/ui/models';
|
|
3
6
|
import { fetchNews, type NewsItem } from './news.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
7
|
+
import { AUTO, fetchCatalog } from './model-catalog.js';
|
|
8
|
+
import { Prose } from '../shared/Prose.js';
|
|
6
9
|
import { capture, contributeTrainingSample } from '../shared/consent.js';
|
|
7
|
-
import {
|
|
10
|
+
import { Toolbar, type Mode } from './Toolbar.js';
|
|
8
11
|
import { Rail } from './Rail.js';
|
|
9
|
-
import { Source } from './Source.js';
|
|
10
12
|
import { Stories } from './Stories.js';
|
|
11
13
|
import { Widgets } from './WidgetView.js';
|
|
12
14
|
import { extractWidgets } from './widget.js';
|
|
@@ -16,14 +18,13 @@ import { DEFAULT_PROVIDER_ID, fallbackUrl, loadProviderId, providerById } from '
|
|
|
16
18
|
* Hanzo Answer Engine — the shared AI-answer surface (query → streamed answer +
|
|
17
19
|
* inline citations + sources + live news). Backend = api.hanzo.ai ONLY, reached
|
|
18
20
|
* through @hanzo/ai: `search` for the grounded modes, `chat.completions` for
|
|
19
|
-
* Chat (each capability defined in exactly one place).
|
|
20
|
-
* the Hanzo brand.
|
|
21
|
+
* Chat (each capability defined in exactly one place).
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
23
|
+
* It draws with `@hanzo/ui/chat` — Thread, Message, Sources, Composer — and
|
|
24
|
+
* `@hanzo/ui/models` for the picker. This file is the state and the wire; the
|
|
25
|
+
* presentation is the shell every Hanzo chat surface shares. What is left local
|
|
26
|
+
* is only what is true HERE: the modes and sources in the composer's toolbar
|
|
27
|
+
* slot, the widgets the answer can emit, and the news rail.
|
|
27
28
|
*/
|
|
28
29
|
|
|
29
30
|
/**
|
|
@@ -51,6 +52,28 @@ async function* converse(
|
|
|
51
52
|
yield { type: 'done', answer, sources: [] };
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
/** What each wire stage is called on the surface. */
|
|
56
|
+
const STAGE: Record<string, string> = {
|
|
57
|
+
planning: 'Planning research',
|
|
58
|
+
searching: 'Searching the web',
|
|
59
|
+
reading: 'Reading sources',
|
|
60
|
+
writing: 'Writing the answer',
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** How wide the model picker is allowed to be in the composer's toolbar row. */
|
|
64
|
+
const PICKER = 176;
|
|
65
|
+
|
|
66
|
+
/** A cited source in the shell's vocabulary. The favicon is the mark; the host
|
|
67
|
+
* initial stands in when a site serves none, so a citation always renders. */
|
|
68
|
+
function cite(s: SearchSource): Source {
|
|
69
|
+
return {
|
|
70
|
+
id: s.url,
|
|
71
|
+
title: s.title || s.url,
|
|
72
|
+
href: s.url,
|
|
73
|
+
...(s.favicon ? { icon: <img src={s.favicon} alt="" width={16} height={16} /> } : null),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
54
77
|
export interface AnswerEngineProps {
|
|
55
78
|
apiBase: string;
|
|
56
79
|
/** Resolves the current IAM bearer, or null when signed out. */
|
|
@@ -62,26 +85,27 @@ export interface AnswerEngineProps {
|
|
|
62
85
|
}
|
|
63
86
|
|
|
64
87
|
export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: AnswerEngineProps) {
|
|
65
|
-
//
|
|
66
|
-
// a single centered column.
|
|
88
|
+
// Rail hidden by default — the answer surface should read like hanzo.chat:
|
|
89
|
+
// a single centered column. Its own header control brings it back.
|
|
67
90
|
const [collapsed, setCollapsed] = useState(true);
|
|
68
91
|
const [query, setQuery] = useState('');
|
|
69
92
|
const [submitted, setSubmitted] = useState('');
|
|
70
93
|
const [mode, setMode] = useState<Mode>('search');
|
|
71
94
|
const [sources, setSources] = useState<Set<string>>(new Set());
|
|
72
|
-
const [
|
|
73
|
-
const [model, setModel] = useState<
|
|
95
|
+
const [models, setModels] = useState<ModelCatalogEntry[]>([]);
|
|
96
|
+
const [model, setModel] = useState<string>(AUTO);
|
|
74
97
|
const [news, setNews] = useState<NewsItem[]>([]);
|
|
75
98
|
// True once the user picks a model themselves, so the catalog's default-to-Enso
|
|
76
99
|
// never overwrites a deliberate choice made while the fetch was still in flight.
|
|
77
100
|
const picked = useRef(false);
|
|
78
|
-
const chooseModel = useCallback((
|
|
101
|
+
const chooseModel = useCallback((id: string) => {
|
|
79
102
|
picked.current = true;
|
|
80
|
-
setModel(
|
|
103
|
+
setModel(id);
|
|
81
104
|
}, []);
|
|
82
105
|
|
|
83
106
|
const [phase, setPhase] = useState<'idle' | 'running' | 'done'>('idle');
|
|
84
|
-
|
|
107
|
+
/** What the answer is doing right now, as the shell's Step reads it. */
|
|
108
|
+
const [step, setStep] = useState<{ name: string; detail?: string }>({ name: '' });
|
|
85
109
|
const [answer, setAnswer] = useState('');
|
|
86
110
|
const [answerSources, setAnswerSources] = useState<SearchSource[]>([]);
|
|
87
111
|
const [followUps, setFollowUps] = useState<string[]>([]);
|
|
@@ -98,17 +122,17 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
|
|
|
98
122
|
// Enso is the default, selected once the catalog lands. It cannot be the
|
|
99
123
|
// useState seed: the catalog is fetched at runtime, so naming a model before
|
|
100
124
|
// 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.
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
//
|
|
125
|
+
// of model-catalog.ts is that the list is never fabricated. Auto is the seed
|
|
126
|
+
// and the fallback, so a failed/slow fetch degrades to "routes to the best
|
|
127
|
+
// model" instead of a dead selection. Only the initial pick is overridden:
|
|
128
|
+
// `picked` guards a user's choice against a late catalog resolve.
|
|
105
129
|
useEffect(() => {
|
|
106
|
-
|
|
107
|
-
.then((
|
|
108
|
-
|
|
130
|
+
fetchCatalog()
|
|
131
|
+
.then((entries) => {
|
|
132
|
+
setModels(entries);
|
|
109
133
|
if (picked.current) return;
|
|
110
|
-
const enso =
|
|
111
|
-
if (enso) setModel(enso);
|
|
134
|
+
const enso = entries.find((m) => /enso/i.test(m.family ?? ''));
|
|
135
|
+
if (enso) setModel(enso.id);
|
|
112
136
|
})
|
|
113
137
|
.catch(() => {});
|
|
114
138
|
fetchNews().then(setNews).catch(() => {});
|
|
@@ -162,21 +186,21 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
|
|
|
162
186
|
|
|
163
187
|
setSubmitted(question);
|
|
164
188
|
setPhase('running');
|
|
165
|
-
|
|
189
|
+
setStep({ name: mode === 'chat' ? 'Thinking' : 'Searching the web' });
|
|
166
190
|
setAnswer('');
|
|
167
191
|
setAnswerSources([]);
|
|
168
192
|
setFollowUps([]);
|
|
169
193
|
setError('');
|
|
170
194
|
setNeedAuth(false);
|
|
171
|
-
void capture('answer_search', { mode, model
|
|
195
|
+
void capture('answer_search', { mode, model });
|
|
172
196
|
let fullAnswer = '';
|
|
173
197
|
|
|
174
198
|
const stream =
|
|
175
199
|
mode === 'chat'
|
|
176
|
-
? converse(client, question, model
|
|
200
|
+
? converse(client, question, model, ctrl.signal)
|
|
177
201
|
: (client.search(question, {
|
|
178
202
|
mode,
|
|
179
|
-
model
|
|
203
|
+
model,
|
|
180
204
|
sources: [...sources],
|
|
181
205
|
signal: ctrl.signal,
|
|
182
206
|
}) as AsyncGenerator<SearchEvent>);
|
|
@@ -184,15 +208,10 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
|
|
|
184
208
|
for await (const ev of stream) {
|
|
185
209
|
switch (ev.type) {
|
|
186
210
|
case 'status':
|
|
187
|
-
|
|
188
|
-
ev.stage
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
? 'Searching the web' + (ev.detail ? `: ${ev.detail}` : '')
|
|
192
|
-
: ev.stage === 'reading'
|
|
193
|
-
? 'Reading sources' + (ev.detail ? `: ${ev.detail}` : '')
|
|
194
|
-
: 'Writing the answer',
|
|
195
|
-
);
|
|
211
|
+
setStep({
|
|
212
|
+
name: STAGE[ev.stage] ?? 'Writing the answer',
|
|
213
|
+
...(ev.detail ? { detail: ev.detail } : null),
|
|
214
|
+
});
|
|
196
215
|
break;
|
|
197
216
|
case 'sources':
|
|
198
217
|
setAnswerSources(ev.sources);
|
|
@@ -206,10 +225,10 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
|
|
|
206
225
|
break;
|
|
207
226
|
case 'done':
|
|
208
227
|
setPhase('done');
|
|
209
|
-
void capture('answer_shown', { mode, model
|
|
228
|
+
void capture('answer_shown', { mode, model });
|
|
210
229
|
// Opt-in only: no-ops unless the user turned on training
|
|
211
230
|
// contribution (the consent module gates the send).
|
|
212
|
-
void contributeTrainingSample({ query: question, answer: fullAnswer, model
|
|
231
|
+
void contributeTrainingSample({ query: question, answer: fullAnswer, model });
|
|
213
232
|
break;
|
|
214
233
|
case 'error':
|
|
215
234
|
if (ev.error.includes('__NO_TOKEN__') || /401|invalid api key/i.test(ev.error)) {
|
|
@@ -241,6 +260,10 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
|
|
|
241
260
|
}, [initialQuery, run]);
|
|
242
261
|
|
|
243
262
|
const submit = useCallback(() => void run(query), [query, run]);
|
|
263
|
+
const stop = useCallback(() => {
|
|
264
|
+
abortRef.current?.abort();
|
|
265
|
+
setPhase('done');
|
|
266
|
+
}, []);
|
|
244
267
|
const toggleSource = useCallback((s: string) => {
|
|
245
268
|
setSources((prev) => {
|
|
246
269
|
const next = new Set(prev);
|
|
@@ -261,27 +284,22 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
|
|
|
261
284
|
setNeedAuth(false);
|
|
262
285
|
}, []);
|
|
263
286
|
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
model={model}
|
|
275
|
-
setModel={chooseModel}
|
|
276
|
-
busy={busy}
|
|
277
|
-
/>
|
|
287
|
+
const busy = phase === 'running';
|
|
288
|
+
const composer = (
|
|
289
|
+
<Composer value={query} onChange={setQuery} onSend={submit} onStop={stop} busy={busy}>
|
|
290
|
+
<Toolbar mode={mode} setMode={setMode} sources={sources} toggleSource={toggleSource} />
|
|
291
|
+
{/* Boxed: the picker's trigger is `width: "100%"`, so left free in the
|
|
292
|
+
toolbar row it takes everything and pushes the send control out. */}
|
|
293
|
+
<XStack width={PICKER} shrink={0}>
|
|
294
|
+
<ModelSelector models={models} value={model} onChange={chooseModel} size="sm" />
|
|
295
|
+
</XStack>
|
|
296
|
+
</Composer>
|
|
278
297
|
);
|
|
279
298
|
|
|
299
|
+
const { prose, widgets } = extractWidgets(answer);
|
|
300
|
+
|
|
280
301
|
return (
|
|
281
302
|
<div className={'ae-root' + (collapsed ? ' collapsed' : '')}>
|
|
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
303
|
<Rail
|
|
286
304
|
collapsed={collapsed}
|
|
287
305
|
toggle={() => setCollapsed((v) => !v)}
|
|
@@ -291,28 +309,18 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
|
|
|
291
309
|
|
|
292
310
|
<main className="ae-main">
|
|
293
311
|
{phase === 'idle' ? (
|
|
294
|
-
<
|
|
295
|
-
<
|
|
312
|
+
<YStack flex={1} justify="center" items="center" gap="$6" px="$4" py="$6">
|
|
313
|
+
<YStack width="100%" maxW={768}>
|
|
314
|
+
{composer}
|
|
315
|
+
</YStack>
|
|
296
316
|
<Stories items={news} />
|
|
297
|
-
</
|
|
317
|
+
</YStack>
|
|
298
318
|
) : (
|
|
299
|
-
|
|
300
|
-
<
|
|
301
|
-
<
|
|
302
|
-
|
|
303
|
-
{answerSources.length > 0 && (
|
|
304
|
-
<div className="ae-sources">
|
|
305
|
-
{answerSources.map((s, i) => (
|
|
306
|
-
<Source key={s.url} source={s} index={i} />
|
|
307
|
-
))}
|
|
308
|
-
</div>
|
|
309
|
-
)}
|
|
319
|
+
<>
|
|
320
|
+
<Thread>
|
|
321
|
+
<Message role="user">{submitted}</Message>
|
|
310
322
|
|
|
311
|
-
{
|
|
312
|
-
<div className="ae-status">
|
|
313
|
-
<span className="ae-spinner" /> {status}…
|
|
314
|
-
</div>
|
|
315
|
-
)}
|
|
323
|
+
{answerSources.length > 0 && <Sources sources={answerSources.map(cite)} />}
|
|
316
324
|
|
|
317
325
|
{needAuth ? (
|
|
318
326
|
/* Reached only when a token EXISTED and the call still came back
|
|
@@ -321,20 +329,24 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
|
|
|
321
329
|
Both doors are offered: renew the session for an AI answer, or
|
|
322
330
|
take the same query to the configured engine. A dead end here
|
|
323
331
|
would strand someone who simply needs to sign in again. */
|
|
324
|
-
<
|
|
325
|
-
<
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
332
|
+
<YStack gap="$3" items="flex-start">
|
|
333
|
+
<SizableText size="$3">
|
|
334
|
+
Your Hanzo session expired. Sign in again for AI answers.
|
|
335
|
+
</SizableText>
|
|
336
|
+
<XStack gap="$3" items="center">
|
|
337
|
+
<Button onPress={signIn}>Sign in</Button>
|
|
338
|
+
<a
|
|
339
|
+
href={fallbackUrl(providerId, submitted) || undefined}
|
|
340
|
+
style={{ color: 'inherit', opacity: 0.7, fontSize: 13 }}
|
|
341
|
+
>
|
|
342
|
+
Search {providerById(providerId).label} instead
|
|
343
|
+
</a>
|
|
344
|
+
</XStack>
|
|
345
|
+
</YStack>
|
|
336
346
|
) : error ? (
|
|
337
|
-
<
|
|
347
|
+
<Message role="assistant">
|
|
348
|
+
<Failure onRetry={() => void run(submitted)}>{error}</Failure>
|
|
349
|
+
</Message>
|
|
338
350
|
) : (
|
|
339
351
|
/* The answer picks its own presentation: any widget blocks it
|
|
340
352
|
emitted render as real components, and the prose is what is
|
|
@@ -342,42 +354,55 @@ export function AnswerEngine({ apiBase, getToken, signIn, initialQuery }: Answer
|
|
|
342
354
|
as raw JSON. Extraction runs per frame against a STREAMING,
|
|
343
355
|
half-written document, which is why an unterminated fence is
|
|
344
356
|
left alone until it closes. */
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
dangerouslySetInnerHTML={{ __html: renderMarkdown(prose) }}
|
|
353
|
-
/>
|
|
354
|
-
</>
|
|
355
|
-
);
|
|
356
|
-
})()
|
|
357
|
+
<Message role="assistant" busy={busy && !answer}>
|
|
358
|
+
{busy && !answer ? (
|
|
359
|
+
<Step name={step.name} status="running" {...(step.detail ? { detail: step.detail } : null)} />
|
|
360
|
+
) : null}
|
|
361
|
+
<Widgets widgets={widgets} />
|
|
362
|
+
<Prose text={prose} />
|
|
363
|
+
</Message>
|
|
357
364
|
)}
|
|
358
365
|
|
|
359
366
|
{followUps.length > 0 && (
|
|
360
|
-
<
|
|
361
|
-
<
|
|
367
|
+
<YStack gap="$1.5">
|
|
368
|
+
<SizableText size="$1" color="$color10" fontWeight="500">
|
|
369
|
+
Follow-up
|
|
370
|
+
</SizableText>
|
|
362
371
|
{followUps.map((f) => (
|
|
363
|
-
<
|
|
372
|
+
<XStack
|
|
364
373
|
key={f}
|
|
365
|
-
|
|
366
|
-
|
|
374
|
+
items="center"
|
|
375
|
+
gap="$2"
|
|
376
|
+
px="$3"
|
|
377
|
+
py="$2"
|
|
378
|
+
rounded="$3"
|
|
379
|
+
borderWidth={1}
|
|
380
|
+
borderColor="$borderColor"
|
|
381
|
+
cursor="pointer"
|
|
382
|
+
role="button"
|
|
383
|
+
tabIndex={0}
|
|
384
|
+
hoverStyle={{ backgroundColor: '$color3' }}
|
|
385
|
+
onPress={() => {
|
|
367
386
|
setQuery(f);
|
|
368
387
|
void run(f);
|
|
369
388
|
}}
|
|
370
389
|
>
|
|
371
|
-
{
|
|
372
|
-
|
|
373
|
-
|
|
390
|
+
<SizableText size="$2" flex={1}>
|
|
391
|
+
{f}
|
|
392
|
+
</SizableText>
|
|
393
|
+
<SizableText size="$2" color="$color10">
|
|
394
|
+
→
|
|
395
|
+
</SizableText>
|
|
396
|
+
</XStack>
|
|
374
397
|
))}
|
|
375
|
-
</
|
|
398
|
+
</YStack>
|
|
376
399
|
)}
|
|
377
|
-
</
|
|
400
|
+
</Thread>
|
|
378
401
|
|
|
379
|
-
<
|
|
380
|
-
|
|
402
|
+
<YStack width="100%" maxW={768} self="center" px="$3" pb="$4">
|
|
403
|
+
{composer}
|
|
404
|
+
</YStack>
|
|
405
|
+
</>
|
|
381
406
|
)}
|
|
382
407
|
</main>
|
|
383
408
|
</div>
|