larkup 0.1.14
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/.env +2 -0
- package/app/actions/vercel.ts +417 -0
- package/app/api/chat/route.ts +192 -0
- package/app/api/chat/status/route.ts +55 -0
- package/app/api/chat/suggestions/route.ts +115 -0
- package/app/api/config/route.ts +73 -0
- package/app/api/config/test/route.ts +67 -0
- package/app/api/config/test-embedding/route.ts +40 -0
- package/app/api/config/test-llm/route.ts +47 -0
- package/app/api/config/test-provider/route.ts +36 -0
- package/app/api/demo/route.ts +176 -0
- package/app/api/deploy/ssh/route.ts +340 -0
- package/app/api/documents/route.ts +90 -0
- package/app/api/firecrawl/local/route.ts +46 -0
- package/app/api/index/route.ts +113 -0
- package/app/api/jobs/[id]/route.ts +44 -0
- package/app/api/jobs/route.ts +116 -0
- package/app/api/parse-file/route.ts +39 -0
- package/app/api/search/google/route.ts +162 -0
- package/app/api/search/route.ts +29 -0
- package/app/api/server/download/route.ts +112 -0
- package/app/api/server/generate/route.ts +46 -0
- package/app/api/server/local/route.ts +42 -0
- package/app/api/servers/route.ts +137 -0
- package/app/api/vector-stores/install/route.ts +65 -0
- package/app/api/vector-stores/status/route.ts +26 -0
- package/app/chat/page.tsx +15 -0
- package/app/configure/page.tsx +53 -0
- package/app/data/page.tsx +15 -0
- package/app/demo/page.tsx +15 -0
- package/app/favicon.ico +0 -0
- package/app/globals.css +190 -0
- package/app/index-data/page.tsx +15 -0
- package/app/layout.tsx +51 -0
- package/app/page.tsx +34 -0
- package/app/server/page.tsx +22 -0
- package/app/simple/chat/page.tsx +17 -0
- package/app/simple/docs/page.tsx +21 -0
- package/app/simple/layout.tsx +9 -0
- package/app/simple/settings/page.tsx +627 -0
- package/app/template.tsx +16 -0
- package/app/themes.css +733 -0
- package/components/alerts/generic-alert.tsx +74 -0
- package/components/app-sidebar.tsx +187 -0
- package/components/app-topnav.tsx +195 -0
- package/components/chat/chat-settings-modal.tsx +209 -0
- package/components/chat/chat-workspace.tsx +348 -0
- package/components/chat/knowledge-base-result.tsx +97 -0
- package/components/chat/message-item.tsx +103 -0
- package/components/client-layout-wrapper.tsx +182 -0
- package/components/configure/configure-form.tsx +1683 -0
- package/components/configure/store-fields.tsx +152 -0
- package/components/data/corpus-panel.tsx +499 -0
- package/components/data/data-workspace.tsx +272 -0
- package/components/data/firecrawl-notice.tsx +236 -0
- package/components/data/jobs-panel.tsx +485 -0
- package/components/data/paste-panel.tsx +79 -0
- package/components/data/scrape-panel.tsx +964 -0
- package/components/data/upload-panel.tsx +714 -0
- package/components/demo/demo-workspace.tsx +419 -0
- package/components/global-settings.tsx +286 -0
- package/components/index/index-workspace.tsx +482 -0
- package/components/onboarding/simple-setup.tsx +702 -0
- package/components/onboarding/tech-setup.tsx +121 -0
- package/components/onboarding/welcome-screen.tsx +183 -0
- package/components/page-header.tsx +44 -0
- package/components/server/code-viewer.tsx +87 -0
- package/components/server/deploy-button.tsx +1390 -0
- package/components/server/server-workspace.tsx +392 -0
- package/components/simple/sdk-connect-dialog.tsx +201 -0
- package/components/simple/simple-index-button.tsx +83 -0
- package/components/simple/simple-sidebar.tsx +161 -0
- package/components/theme-customizer-provider.tsx +171 -0
- package/components/theme-switcher.tsx +445 -0
- package/components/ui/alert-dialog.tsx +187 -0
- package/components/ui/alert.tsx +76 -0
- package/components/ui/badge.tsx +52 -0
- package/components/ui/button.tsx +59 -0
- package/components/ui/card.tsx +103 -0
- package/components/ui/checkbox.tsx +28 -0
- package/components/ui/collapsible.tsx +21 -0
- package/components/ui/dialog.tsx +159 -0
- package/components/ui/dropdown-menu.tsx +281 -0
- package/components/ui/input.tsx +22 -0
- package/components/ui/label.tsx +20 -0
- package/components/ui/popover.tsx +90 -0
- package/components/ui/progress.tsx +83 -0
- package/components/ui/provider-icon.tsx +94 -0
- package/components/ui/scroll-area.tsx +55 -0
- package/components/ui/select.tsx +248 -0
- package/components/ui/separator.tsx +25 -0
- package/components/ui/sheet.tsx +138 -0
- package/components/ui/skeleton.tsx +13 -0
- package/components/ui/sonner.tsx +63 -0
- package/components/ui/switch.tsx +32 -0
- package/components/ui/table.tsx +116 -0
- package/components/ui/tabs.tsx +84 -0
- package/components/ui/textarea.tsx +18 -0
- package/components/ui/tooltip.tsx +66 -0
- package/components/workspace/delete-server-dialog.tsx +71 -0
- package/components/workspace/server-form-dialog.tsx +103 -0
- package/components/workspace/server-switcher.tsx +163 -0
- package/components/workspace/workspace-provider.tsx +177 -0
- package/components/workspace/workspace-top-bar.tsx +23 -0
- package/components.json +21 -0
- package/lib/error-formatter.ts +15 -0
- package/lib/utils.ts +6 -0
- package/next-env.d.ts +6 -0
- package/next.config.mjs +18 -0
- package/package.json +65 -0
- package/postcss.config.mjs +8 -0
- package/public/docker.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/github.svg +3 -0
- package/public/hetzner.svg +1 -0
- package/public/icons/aws.svg +38 -0
- package/public/icons/azure.svg +1 -0
- package/public/icons/chroma.png +0 -0
- package/public/icons/cohere.svg +30 -0
- package/public/icons/digital-ocean.webp +0 -0
- package/public/icons/firecrawl2.png +0 -0
- package/public/icons/gcp.svg +1 -0
- package/public/icons/gemini.svg +1 -0
- package/public/icons/jina.svg +1 -0
- package/public/icons/lancedb2.png +0 -0
- package/public/icons/mistral.svg +469 -0
- package/public/icons/nomic.png +0 -0
- package/public/icons/openai.svg +1 -0
- package/public/icons/pgvector2.png +0 -0
- package/public/icons/pinecone.png +0 -0
- package/public/icons/qdrant.svg +35 -0
- package/public/icons/supabase.png +0 -0
- package/public/icons/vercel copy.svg +1 -0
- package/public/icons/vercel.svg +1 -0
- package/public/icons/voyage-light.png +0 -0
- package/public/icons/weaviate.webp +0 -0
- package/public/logo-light.png +0 -0
- package/public/logo.png +0 -0
- package/public/logo9.png +0 -0
- package/public/vercel.svg +1 -0
- package/tsconfig.json +33 -0
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect, useRef } from "react";
|
|
4
|
+
import useSWR from "swr";
|
|
5
|
+
import {
|
|
6
|
+
AlertTriangle,
|
|
7
|
+
Boxes,
|
|
8
|
+
CheckCircle2,
|
|
9
|
+
Cpu,
|
|
10
|
+
Database,
|
|
11
|
+
FileText,
|
|
12
|
+
Hash,
|
|
13
|
+
Info,
|
|
14
|
+
Layers,
|
|
15
|
+
Loader2,
|
|
16
|
+
Play,
|
|
17
|
+
RotateCcw,
|
|
18
|
+
Scissors,
|
|
19
|
+
} from "lucide-react";
|
|
20
|
+
import type {
|
|
21
|
+
ChunkingParams,
|
|
22
|
+
IndexRun,
|
|
23
|
+
IndexType,
|
|
24
|
+
VectorStoreId,
|
|
25
|
+
} from "@larkup/core/types";
|
|
26
|
+
import { getEmbeddingModel } from "@larkup/core/embeddings/registry";
|
|
27
|
+
import { getVectorStore } from "@larkup/vector-stores/registry";
|
|
28
|
+
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
29
|
+
import { Button } from "@/components/ui/button";
|
|
30
|
+
import { Progress } from "@/components/ui/progress";
|
|
31
|
+
import { Badge } from "@/components/ui/badge";
|
|
32
|
+
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
|
33
|
+
import { Skeleton } from "@/components/ui/skeleton";
|
|
34
|
+
import { toast } from "sonner";
|
|
35
|
+
import {
|
|
36
|
+
AlertDialog,
|
|
37
|
+
AlertDialogAction,
|
|
38
|
+
AlertDialogCancel,
|
|
39
|
+
AlertDialogContent,
|
|
40
|
+
AlertDialogDescription,
|
|
41
|
+
AlertDialogFooter,
|
|
42
|
+
AlertDialogHeader,
|
|
43
|
+
AlertDialogTitle,
|
|
44
|
+
AlertDialogTrigger,
|
|
45
|
+
} from "@/components/ui/alert-dialog";
|
|
46
|
+
|
|
47
|
+
const fetcher = (url: string) => fetch(url).then((r) => r.json());
|
|
48
|
+
|
|
49
|
+
interface IndexStatus {
|
|
50
|
+
run: IndexRun | null;
|
|
51
|
+
running: boolean;
|
|
52
|
+
docCount: number;
|
|
53
|
+
charCount: number;
|
|
54
|
+
ready: boolean;
|
|
55
|
+
blockers: string[];
|
|
56
|
+
unindexedCount: number;
|
|
57
|
+
config: {
|
|
58
|
+
embeddingModelId: string;
|
|
59
|
+
vectorStore: VectorStoreId;
|
|
60
|
+
indexType: IndexType;
|
|
61
|
+
chunking: ChunkingParams;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const ACTIVE: IndexRun["status"][] = ["chunking", "embedding", "upserting"];
|
|
66
|
+
|
|
67
|
+
export function IndexWorkspace() {
|
|
68
|
+
const [starting, setStarting] = useState(false);
|
|
69
|
+
const { data, isLoading, mutate } = useSWR<IndexStatus>(
|
|
70
|
+
"/api/index",
|
|
71
|
+
fetcher,
|
|
72
|
+
{
|
|
73
|
+
refreshInterval: (d) =>
|
|
74
|
+
d?.run && ACTIVE.includes(d.run.status) ? 1000 : 0,
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// Show a warning toast whenever the run's warning message changes
|
|
79
|
+
const lastWarning = useRef<string | undefined>(undefined);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
const warning = data?.run?.warning;
|
|
82
|
+
if (warning && warning !== lastWarning.current) {
|
|
83
|
+
toast.warning(warning, { id: "rate-limit-warning", duration: 70_000 });
|
|
84
|
+
} else if (!warning && lastWarning.current) {
|
|
85
|
+
toast.dismiss("rate-limit-warning");
|
|
86
|
+
toast.success("Rate limit resolved — resuming indexing.", {
|
|
87
|
+
duration: 3000,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
lastWarning.current = warning;
|
|
91
|
+
}, [data?.run?.warning]);
|
|
92
|
+
|
|
93
|
+
if (isLoading || !data) {
|
|
94
|
+
return (
|
|
95
|
+
<div className="px-6 py-6 md:px-8">
|
|
96
|
+
<Skeleton className="h-40 w-full" />
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const { run, ready, blockers, docCount, charCount, unindexedCount, config } =
|
|
102
|
+
data;
|
|
103
|
+
const running = Boolean(run && ACTIVE.includes(run.status));
|
|
104
|
+
|
|
105
|
+
async function build(incremental = false) {
|
|
106
|
+
setStarting(true);
|
|
107
|
+
try {
|
|
108
|
+
const res = await fetch("/api/index", {
|
|
109
|
+
method: "POST",
|
|
110
|
+
body: JSON.stringify({ incremental }),
|
|
111
|
+
headers: { "Content-Type": "application/json" },
|
|
112
|
+
});
|
|
113
|
+
const body = await res.json();
|
|
114
|
+
if (!res.ok) {
|
|
115
|
+
toast.error(body.error ?? "Could not start indexing.");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
toast.success("Indexing started.");
|
|
119
|
+
mutate();
|
|
120
|
+
} catch {
|
|
121
|
+
toast.error("Could not start indexing.");
|
|
122
|
+
} finally {
|
|
123
|
+
setStarting(false);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function cancel() {
|
|
128
|
+
setStarting(true);
|
|
129
|
+
try {
|
|
130
|
+
const res = await fetch("/api/index", { method: "DELETE" });
|
|
131
|
+
if (!res.ok) {
|
|
132
|
+
toast.error("Could not cancel indexing.");
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
toast.success("Indexing cancelled.");
|
|
136
|
+
mutate();
|
|
137
|
+
} catch {
|
|
138
|
+
toast.error("Could not cancel indexing.");
|
|
139
|
+
} finally {
|
|
140
|
+
setStarting(false);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<div className="space-y-6 px-6 py-6 md:px-8">
|
|
146
|
+
<ConfigSummary
|
|
147
|
+
config={config}
|
|
148
|
+
docCount={docCount}
|
|
149
|
+
charCount={charCount}
|
|
150
|
+
/>
|
|
151
|
+
|
|
152
|
+
{!ready && (
|
|
153
|
+
<Alert variant="default">
|
|
154
|
+
<AlertTriangle className="size-4 text-orange-500!" />
|
|
155
|
+
<AlertTitle className="text-orange-500!">
|
|
156
|
+
Not ready to index
|
|
157
|
+
</AlertTitle>
|
|
158
|
+
<AlertDescription>
|
|
159
|
+
<ul className="list-disc pl-4">
|
|
160
|
+
{blockers.map((b) => (
|
|
161
|
+
<li key={b}>{b}</li>
|
|
162
|
+
))}
|
|
163
|
+
</ul>
|
|
164
|
+
</AlertDescription>
|
|
165
|
+
</Alert>
|
|
166
|
+
)}
|
|
167
|
+
|
|
168
|
+
<RunCard run={run} running={running} />
|
|
169
|
+
|
|
170
|
+
{/* Pre-indexing warning — only shown before the very first run */}
|
|
171
|
+
{ready && !run && (
|
|
172
|
+
<Alert>
|
|
173
|
+
<Info className="size-4 text-blue-500!" />
|
|
174
|
+
<AlertTitle className="text-blue-600 dark:text-blue-400">
|
|
175
|
+
Before you start indexing
|
|
176
|
+
</AlertTitle>
|
|
177
|
+
<AlertDescription className="text-muted-foreground space-y-1">
|
|
178
|
+
<p>
|
|
179
|
+
Once indexing begins, two settings become{" "}
|
|
180
|
+
<span className="font-medium text-foreground">locked</span> to the
|
|
181
|
+
existing index:
|
|
182
|
+
</p>
|
|
183
|
+
<ul className="list-disc pl-4 space-y-0.5">
|
|
184
|
+
<li>
|
|
185
|
+
<span className="font-medium text-foreground">
|
|
186
|
+
Embedding model
|
|
187
|
+
</span>{" "}
|
|
188
|
+
— you can swap to any model with the{" "}
|
|
189
|
+
<span className="font-medium text-foreground">
|
|
190
|
+
same vector dimensions
|
|
191
|
+
</span>
|
|
192
|
+
, but switching to a model with different dimensions will
|
|
193
|
+
require a full re-index.
|
|
194
|
+
</li>
|
|
195
|
+
<li>
|
|
196
|
+
<span className="font-medium text-foreground">
|
|
197
|
+
Vector store
|
|
198
|
+
</span>{" "}
|
|
199
|
+
— changing the store after indexing requires starting fresh.
|
|
200
|
+
</li>
|
|
201
|
+
</ul>
|
|
202
|
+
</AlertDescription>
|
|
203
|
+
</Alert>
|
|
204
|
+
)}
|
|
205
|
+
|
|
206
|
+
<div className="flex items-center gap-3">
|
|
207
|
+
<Button
|
|
208
|
+
onClick={() => build(run?.status === "completed")}
|
|
209
|
+
disabled={
|
|
210
|
+
!ready ||
|
|
211
|
+
running ||
|
|
212
|
+
starting ||
|
|
213
|
+
(run?.status === "completed" && unindexedCount === 0)
|
|
214
|
+
}
|
|
215
|
+
size="lg"
|
|
216
|
+
>
|
|
217
|
+
{running || starting ? (
|
|
218
|
+
<Loader2 className="size-4 animate-spin" />
|
|
219
|
+
) : (
|
|
220
|
+
<Play className="size-4" />
|
|
221
|
+
)}
|
|
222
|
+
{running
|
|
223
|
+
? "Indexing…"
|
|
224
|
+
: run?.status === "completed"
|
|
225
|
+
? `Index new documents (${unindexedCount})`
|
|
226
|
+
: `Start indexing (${unindexedCount})`}
|
|
227
|
+
</Button>
|
|
228
|
+
{running && (
|
|
229
|
+
<Button
|
|
230
|
+
onClick={cancel}
|
|
231
|
+
disabled={starting}
|
|
232
|
+
size="lg"
|
|
233
|
+
variant="destructive"
|
|
234
|
+
>
|
|
235
|
+
Cancel
|
|
236
|
+
</Button>
|
|
237
|
+
)}
|
|
238
|
+
{run?.status === "completed" && (
|
|
239
|
+
<AlertDialog>
|
|
240
|
+
<AlertDialogTrigger
|
|
241
|
+
render={
|
|
242
|
+
<Button
|
|
243
|
+
disabled={!ready || running || starting}
|
|
244
|
+
size="lg"
|
|
245
|
+
variant="outline"
|
|
246
|
+
>
|
|
247
|
+
<RotateCcw className="size-4 mr-2" />
|
|
248
|
+
Re-Index
|
|
249
|
+
</Button>
|
|
250
|
+
}
|
|
251
|
+
/>
|
|
252
|
+
<AlertDialogContent>
|
|
253
|
+
<AlertDialogHeader>
|
|
254
|
+
<AlertDialogTitle>
|
|
255
|
+
Are you sure you want to re-index?
|
|
256
|
+
</AlertDialogTitle>
|
|
257
|
+
<AlertDialogDescription>
|
|
258
|
+
This will rebuild the entire index from scratch. All documents
|
|
259
|
+
will be re-processed.
|
|
260
|
+
</AlertDialogDescription>
|
|
261
|
+
</AlertDialogHeader>
|
|
262
|
+
<AlertDialogFooter>
|
|
263
|
+
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
264
|
+
<AlertDialogAction onClick={() => build(false)}>
|
|
265
|
+
Continue
|
|
266
|
+
</AlertDialogAction>
|
|
267
|
+
</AlertDialogFooter>
|
|
268
|
+
</AlertDialogContent>
|
|
269
|
+
</AlertDialog>
|
|
270
|
+
)}
|
|
271
|
+
</div>
|
|
272
|
+
</div>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function ConfigSummary({
|
|
277
|
+
config,
|
|
278
|
+
docCount,
|
|
279
|
+
charCount,
|
|
280
|
+
}: {
|
|
281
|
+
config: IndexStatus["config"];
|
|
282
|
+
docCount: number;
|
|
283
|
+
charCount: number;
|
|
284
|
+
}) {
|
|
285
|
+
const model = getEmbeddingModel(config.embeddingModelId);
|
|
286
|
+
const store = getVectorStore(config.vectorStore);
|
|
287
|
+
|
|
288
|
+
const items = [
|
|
289
|
+
{
|
|
290
|
+
icon: Cpu,
|
|
291
|
+
label: "Embedding model",
|
|
292
|
+
value: model?.label ?? config.embeddingModelId,
|
|
293
|
+
hint: model ? `${model.dimensions} dims` : undefined,
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
icon: Database,
|
|
297
|
+
label: "Vector store",
|
|
298
|
+
value: store?.label ?? config.vectorStore,
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
icon: Boxes,
|
|
302
|
+
label: "Index type",
|
|
303
|
+
value: config.indexType.toUpperCase(),
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
icon: Scissors,
|
|
307
|
+
label: "Chunking",
|
|
308
|
+
value: `${config.chunking.chunkSize} / ${config.chunking.chunkOverlap}`,
|
|
309
|
+
hint: "size / overlap",
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
icon: FileText,
|
|
313
|
+
label: "Corpus",
|
|
314
|
+
value: `${docCount.toLocaleString()} docs`,
|
|
315
|
+
hint: `${charCount.toLocaleString()} chars`,
|
|
316
|
+
},
|
|
317
|
+
];
|
|
318
|
+
|
|
319
|
+
return (
|
|
320
|
+
<Card>
|
|
321
|
+
<CardHeader>
|
|
322
|
+
<CardTitle className="flex items-center gap-2 text-base">
|
|
323
|
+
<Layers className="size-4 text-primary" />
|
|
324
|
+
Index configuration
|
|
325
|
+
</CardTitle>
|
|
326
|
+
</CardHeader>
|
|
327
|
+
<CardContent>
|
|
328
|
+
<dl className="grid grid-cols-2 gap-x-6 gap-y-5 sm:grid-cols-3 lg:grid-cols-5">
|
|
329
|
+
{items.map((it) => (
|
|
330
|
+
<div key={it.label} className="flex flex-col gap-1.5">
|
|
331
|
+
<dt className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
|
332
|
+
<it.icon className="size-3.5" />
|
|
333
|
+
{it.label}
|
|
334
|
+
</dt>
|
|
335
|
+
<dd className="text-sm font-medium leading-tight">
|
|
336
|
+
{it.value}
|
|
337
|
+
{it.hint && (
|
|
338
|
+
<span className="ml-1.5 font-mono text-[11px] font-normal text-muted-foreground">
|
|
339
|
+
{it.hint}
|
|
340
|
+
</span>
|
|
341
|
+
)}
|
|
342
|
+
</dd>
|
|
343
|
+
</div>
|
|
344
|
+
))}
|
|
345
|
+
</dl>
|
|
346
|
+
</CardContent>
|
|
347
|
+
</Card>
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const STATUS_COPY: Record<
|
|
352
|
+
IndexRun["status"],
|
|
353
|
+
{ label: string; phase?: string }
|
|
354
|
+
> = {
|
|
355
|
+
idle: { label: "Idle" },
|
|
356
|
+
chunking: { label: "Chunking", phase: "Splitting documents into chunks" },
|
|
357
|
+
embedding: { label: "Embedding", phase: "Generating vector embeddings" },
|
|
358
|
+
upserting: { label: "Storing", phase: "Writing vectors to the store" },
|
|
359
|
+
completed: { label: "Completed" },
|
|
360
|
+
failed: { label: "Failed" },
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
function RunCard({ run, running }: { run: IndexRun | null; running: boolean }) {
|
|
364
|
+
if (!run) {
|
|
365
|
+
return (
|
|
366
|
+
<Card>
|
|
367
|
+
<CardContent className="flex flex-col items-center justify-center gap-1 py-12 text-center">
|
|
368
|
+
<Hash className="mb-1 size-6 text-muted-foreground/60" />
|
|
369
|
+
<p className="text-sm font-medium">No index built yet</p>
|
|
370
|
+
<p className="text-sm text-muted-foreground">
|
|
371
|
+
Build a Larkup index to embed your corpus and make it
|
|
372
|
+
searchable.
|
|
373
|
+
</p>
|
|
374
|
+
</CardContent>
|
|
375
|
+
</Card>
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const copy = STATUS_COPY[run.status];
|
|
380
|
+
const pct =
|
|
381
|
+
run.totalChunks > 0
|
|
382
|
+
? Math.round((run.processedChunks / run.totalChunks) * 100)
|
|
383
|
+
: running
|
|
384
|
+
? 5
|
|
385
|
+
: 0;
|
|
386
|
+
|
|
387
|
+
return (
|
|
388
|
+
<Card>
|
|
389
|
+
<CardHeader className="flex-row items-center justify-between">
|
|
390
|
+
<CardTitle className="flex items-center gap-2 text-base">
|
|
391
|
+
{run.status === "completed" ? (
|
|
392
|
+
<CheckCircle2 className="size-4 text-primary" />
|
|
393
|
+
) : run.status === "failed" ? (
|
|
394
|
+
<AlertTriangle className="size-4 text-destructive" />
|
|
395
|
+
) : (
|
|
396
|
+
<Loader2 className="size-4 animate-spin text-primary" />
|
|
397
|
+
)}
|
|
398
|
+
{copy.label}
|
|
399
|
+
</CardTitle>
|
|
400
|
+
<StatusBadge status={run.status} />
|
|
401
|
+
</CardHeader>
|
|
402
|
+
<CardContent className="space-y-4">
|
|
403
|
+
{run.status === "failed" ? (
|
|
404
|
+
<Alert variant="destructive">
|
|
405
|
+
<AlertTriangle className="size-4" />
|
|
406
|
+
<AlertTitle>Indexing failed</AlertTitle>
|
|
407
|
+
<AlertDescription>{run.error}</AlertDescription>
|
|
408
|
+
</Alert>
|
|
409
|
+
) : (
|
|
410
|
+
<>
|
|
411
|
+
<div className="space-y-2">
|
|
412
|
+
<div className="flex items-center justify-between text-sm">
|
|
413
|
+
<span className="text-muted-foreground">
|
|
414
|
+
{copy.phase ?? "Done"}
|
|
415
|
+
</span>
|
|
416
|
+
<span className="font-mono tabular-nums">
|
|
417
|
+
{run.processedChunks.toLocaleString()}
|
|
418
|
+
{run.totalChunks > 0 &&
|
|
419
|
+
` / ${run.totalChunks.toLocaleString()}`}{" "}
|
|
420
|
+
chunks
|
|
421
|
+
</span>
|
|
422
|
+
</div>
|
|
423
|
+
<Progress
|
|
424
|
+
value={pct}
|
|
425
|
+
className="**:data-[slot=progress-indicator]:bg-green-600"
|
|
426
|
+
/>
|
|
427
|
+
</div>
|
|
428
|
+
|
|
429
|
+
<dl className="grid grid-cols-2 gap-4 pt-1 sm:grid-cols-4">
|
|
430
|
+
<Stat label="Documents" value={run.docCount.toLocaleString()} />
|
|
431
|
+
<Stat label="Chunks" value={run.totalChunks.toLocaleString()} />
|
|
432
|
+
<Stat
|
|
433
|
+
label="Dimensions"
|
|
434
|
+
value={run.dimensions ? run.dimensions.toLocaleString() : "—"}
|
|
435
|
+
/>
|
|
436
|
+
<Stat
|
|
437
|
+
label="Duration"
|
|
438
|
+
value={
|
|
439
|
+
run.durationMs
|
|
440
|
+
? `${(run.durationMs / 1000).toFixed(1)}s`
|
|
441
|
+
: running
|
|
442
|
+
? "running…"
|
|
443
|
+
: "—"
|
|
444
|
+
}
|
|
445
|
+
/>
|
|
446
|
+
</dl>
|
|
447
|
+
</>
|
|
448
|
+
)}
|
|
449
|
+
</CardContent>
|
|
450
|
+
</Card>
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function Stat({ label, value }: { label: string; value: string }) {
|
|
455
|
+
return (
|
|
456
|
+
<div className="flex flex-col gap-1">
|
|
457
|
+
<dt className="text-xs text-muted-foreground">{label}</dt>
|
|
458
|
+
<dd className="font-mono text-sm tabular-nums">{value}</dd>
|
|
459
|
+
</div>
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function StatusBadge({ status }: { status: IndexRun["status"] }) {
|
|
464
|
+
if (status === "completed")
|
|
465
|
+
return (
|
|
466
|
+
<Badge className="bg-primary/12 text-primary hover:bg-primary/12">
|
|
467
|
+
Ready
|
|
468
|
+
</Badge>
|
|
469
|
+
);
|
|
470
|
+
if (status === "failed") return <Badge variant="destructive">Failed</Badge>;
|
|
471
|
+
if (ACTIVE.includes(status))
|
|
472
|
+
return (
|
|
473
|
+
<span className="flex items-center gap-1.5 text-xs font-medium text-green-600">
|
|
474
|
+
<span className="relative flex size-2">
|
|
475
|
+
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-green-600 opacity-75" />
|
|
476
|
+
<span className="relative inline-flex size-2 rounded-full bg-green-600" />
|
|
477
|
+
</span>
|
|
478
|
+
Live
|
|
479
|
+
</span>
|
|
480
|
+
);
|
|
481
|
+
return null;
|
|
482
|
+
}
|