forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration-explorer.tsx
More file actions
666 lines (612 loc) · 20.4 KB
/
Copy pathintegration-explorer.tsx
File metadata and controls
666 lines (612 loc) · 20.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
"use client";
import { useMemo, useState } from "react";
import Link from "next/link";
import { type Integration, getCategoryLabel } from "@/lib/registry";
import constraintsData from "@/data/constraints.json";
// Module-scope: stable reference, no useMemo needed
const constraints = constraintsData as {
generative_ui: Record<string, { allowed?: string[]; excluded?: string[] }>;
interaction_modalities: Record<
string,
{ allowed?: string[]; excluded?: string[] }
>;
};
const GEN_UI_LABELS: Record<string, string> = {
"constrained-declarative": "Declarative",
"constrained-explicit": "Explicitly Specified",
open: "Open",
};
const MODALITY_LABELS: Record<string, string> = {
sidebar: "Sidebar",
embedded: "Embedded",
popup: "Popup",
chat: "Chat",
headless: "Headless",
};
const GEN_UI_VALUES = Object.keys(GEN_UI_LABELS);
const MODALITY_VALUES = Object.keys(MODALITY_LABELS);
const CATEGORY_ORDER = [
"popular",
"agent-framework",
"enterprise-platform",
"provider-sdk",
"protocol",
"emerging",
"starter",
];
interface IntegrationExplorerProps {
integrations: Integration[];
initialFeatureFilter?: string;
}
interface FilteredDemo {
integration: Integration;
demo: Integration["demos"][number];
}
export function IntegrationExplorer({
integrations,
initialFeatureFilter,
}: IntegrationExplorerProps) {
const [framework, setFramework] = useState("all");
const [genUi, setGenUi] = useState("all");
const [modality, setModality] = useState("all");
const [featureFilter, setFeatureFilter] = useState(
initialFeatureFilter ?? "",
);
// Only deployed integrations participate in filtering
const deployed = useMemo(
() => integrations.filter((i) => i.deployed),
[integrations],
);
// Unique framework names from deployed integrations
const frameworkOptions = useMemo(() => {
// Preserve registry sort_order (not alphabetical)
const seen = new Set<string>();
return deployed
.filter((i) => {
if (seen.has(i.name)) return false;
seen.add(i.name);
return true;
})
.map((i) => i.name);
}, [deployed]);
// Coming-soon frameworks: present in integrations but not deployed
const comingSoonFrameworks = useMemo(() => {
const deployedNames = new Set(deployed.map((i) => i.name));
const allNames = new Set(integrations.map((i) => i.name));
return new Set([...allNames].filter((n) => !deployedNames.has(n)));
}, [integrations, deployed]);
// Determine "coming soon" enum values: those with no deployed packages
const comingSoonGenUi = useMemo(() => {
const available = new Set(deployed.flatMap((i) => i.generative_ui ?? []));
return new Set(GEN_UI_VALUES.filter((v) => !available.has(v)));
}, [deployed]);
const comingSoonModality = useMemo(() => {
const available = new Set(
deployed.flatMap((i) => i.interaction_modalities ?? []),
);
return new Set(MODALITY_VALUES.filter((v) => !available.has(v)));
}, [deployed]);
// Count demos per framework (deployed only)
const frameworkCounts = useMemo(() => {
const counts: Record<string, number> = {};
for (const i of deployed) {
counts[i.name] = (counts[i.name] ?? 0) + i.demos.length;
}
return counts;
}, [deployed]);
const totalDemoCount = useMemo(
() => deployed.reduce((sum, i) => sum + i.demos.length, 0),
[deployed],
);
const filteredDemos = useMemo(() => {
let packages = deployed;
// Feature filter: keep only packages that support the selected feature
if (featureFilter) {
packages = packages.filter((i) => i.features.includes(featureFilter));
}
// Framework filter: keep only packages matching selected framework
if (framework !== "all") {
packages = packages.filter((i) => i.name === framework);
}
// Generative UI filter: package-level then demo-level
if (genUi !== "all") {
packages = packages.filter(
(i) => i.generative_ui && i.generative_ui.includes(genUi),
);
}
// Interaction modality filter: package-level
if (modality !== "all") {
packages = packages.filter(
(i) =>
i.interaction_modalities &&
i.interaction_modalities.includes(modality),
);
}
// Collect demos with demo-level filtering
const results: FilteredDemo[] = [];
for (const integration of packages) {
for (const demo of integration.demos) {
// Generative UI demo-level: keep only demos in allowed list
if (genUi !== "all") {
const genUiConstraint = constraints.generative_ui[genUi];
if (
genUiConstraint?.allowed &&
!genUiConstraint.allowed.includes(demo.id)
) {
continue;
}
}
// Interaction modality demo-level: exclude demos in excluded list
if (modality !== "all") {
const modalityConstraint =
constraints.interaction_modalities[modality];
if (
modalityConstraint?.excluded &&
modalityConstraint.excluded.includes(demo.id)
) {
continue;
}
}
results.push({ integration, demo });
}
}
return results;
}, [deployed, framework, genUi, modality, featureFilter]);
const groupedDemos = useMemo(() => {
const groups: Record<string, FilteredDemo[]> = {};
for (const entry of filteredDemos) {
const cat = entry.integration.category;
if (!groups[cat]) groups[cat] = [];
groups[cat].push(entry);
}
// Return ordered array of [category, demos] pairs
const result = CATEGORY_ORDER.filter(
(cat) => groups[cat] && groups[cat].length > 0,
).map((cat) => [cat, groups[cat]] as [string, FilteredDemo[]]);
// Append any categories not in CATEGORY_ORDER so they aren't silently dropped
const orderedCats = new Set(CATEGORY_ORDER);
for (const cat of Object.keys(groups)) {
if (!orderedCats.has(cat) && groups[cat].length > 0) {
console.warn(
`[integration-explorer] Unknown category "${cat}" — appending to end`,
);
result.push([cat, groups[cat]]);
}
}
return result;
}, [filteredDemos]);
const [mobileFilterOpen, setMobileFilterOpen] = useState(false);
const hasActiveFilters =
framework !== "all" ||
genUi !== "all" ||
modality !== "all" ||
!!featureFilter;
const clearFilter = (
which: "framework" | "genUi" | "modality" | "feature",
) => {
if (which === "framework") setFramework("all");
else if (which === "genUi") setGenUi("all");
else if (which === "feature") setFeatureFilter("");
else setModality("all");
};
const activeFilterLabel =
framework !== "all"
? framework
: genUi !== "all"
? GEN_UI_LABELS[genUi]
: modality !== "all"
? MODALITY_LABELS[modality]
: "All Frameworks";
return (
<div className="flex flex-col sm:flex-row gap-4 sm:gap-6">
{/* ---- Mobile filter dropdown ---- */}
<div className="block sm:hidden relative">
<button
type="button"
onClick={() => setMobileFilterOpen(!mobileFilterOpen)}
className="w-full flex items-center justify-between rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] px-4 py-2.5 text-[13px] font-medium text-[var(--text-secondary)] hover:border-[var(--text-faint)] transition-colors"
>
<span>Filter: {activeFilterLabel}</span>
<svg
className={`w-4 h-4 text-[var(--text-muted)] transition-transform ${mobileFilterOpen ? "rotate-180" : ""}`}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M19 9l-7 7-7-7"
/>
</svg>
</button>
{mobileFilterOpen && (
<div className="absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-[var(--border)] bg-[var(--bg-surface)] shadow-lg p-4 max-h-[60vh] overflow-y-auto">
<FilterGroup title="Framework">
<RadioOption
label="All"
count={totalDemoCount}
selected={framework === "all"}
onClick={() => {
setFramework("all");
setMobileFilterOpen(false);
}}
/>
{frameworkOptions.map((name) => (
<RadioOption
key={name}
label={name}
count={frameworkCounts[name] ?? 0}
selected={framework === name}
onClick={() => {
setFramework(name);
setMobileFilterOpen(false);
}}
/>
))}
{[...comingSoonFrameworks].map((name) => (
<RadioOption key={name} label={name} comingSoon />
))}
</FilterGroup>
<FilterGroup title="Generative UI">
<RadioOption
label="All"
selected={genUi === "all"}
onClick={() => {
setGenUi("all");
setMobileFilterOpen(false);
}}
/>
{GEN_UI_VALUES.map((v) => (
<RadioOption
key={v}
label={GEN_UI_LABELS[v]}
selected={genUi === v}
comingSoon={comingSoonGenUi.has(v)}
onClick={
comingSoonGenUi.has(v)
? undefined
: () => {
setGenUi(v);
setMobileFilterOpen(false);
}
}
/>
))}
</FilterGroup>
<FilterGroup title="Interaction">
<RadioOption
label="All"
selected={modality === "all"}
onClick={() => {
setModality("all");
setMobileFilterOpen(false);
}}
/>
{MODALITY_VALUES.map((v) => (
<RadioOption
key={v}
label={MODALITY_LABELS[v]}
selected={modality === v}
comingSoon={comingSoonModality.has(v)}
onClick={
comingSoonModality.has(v)
? undefined
: () => {
setModality(v);
setMobileFilterOpen(false);
}
}
/>
))}
</FilterGroup>
</div>
)}
</div>
{/* ---- Desktop sidebar ---- */}
<aside
className="hidden sm:block shrink-0 sticky top-4 self-start"
style={{ width: 220 }}
>
{/* Framework group */}
<FilterGroup title="Framework">
<RadioOption
label="All"
count={totalDemoCount}
selected={framework === "all"}
onClick={() => setFramework("all")}
/>
{frameworkOptions.map((name) => (
<RadioOption
key={name}
label={name}
count={frameworkCounts[name] ?? 0}
selected={framework === name}
onClick={() => setFramework(name)}
/>
))}
{[...comingSoonFrameworks].map((name) => (
<RadioOption key={name} label={name} comingSoon />
))}
</FilterGroup>
{/* Generative UI group */}
<FilterGroup title="Generative UI">
<RadioOption
label="All"
selected={genUi === "all"}
onClick={() => setGenUi("all")}
/>
{GEN_UI_VALUES.map((v) => (
<RadioOption
key={v}
label={GEN_UI_LABELS[v]}
selected={genUi === v}
comingSoon={comingSoonGenUi.has(v)}
onClick={comingSoonGenUi.has(v) ? undefined : () => setGenUi(v)}
/>
))}
</FilterGroup>
{/* Interaction group */}
<FilterGroup title="Interaction">
<RadioOption
label="All"
selected={modality === "all"}
onClick={() => setModality("all")}
/>
{MODALITY_VALUES.map((v) => (
<RadioOption
key={v}
label={MODALITY_LABELS[v]}
selected={modality === v}
comingSoon={comingSoonModality.has(v)}
onClick={
comingSoonModality.has(v) ? undefined : () => setModality(v)
}
/>
))}
</FilterGroup>
</aside>
{/* ---- Main area ---- */}
<div className="flex-1 min-w-0">
{/* Header */}
<div className="flex items-baseline gap-3 mb-4">
<h2 className="text-[18px] font-semibold text-[var(--text)]">
Demos
</h2>
<span className="text-[13px] text-[var(--text-muted)]">
{filteredDemos.length}{" "}
{filteredDemos.length === 1 ? "result" : "results"}
</span>
</div>
{/* Active filter chips */}
{hasActiveFilters && (
<div className="flex flex-wrap gap-2 mb-4">
{featureFilter && (
<FilterChip
label={`Feature: ${featureFilter}`}
onDismiss={() => clearFilter("feature")}
/>
)}
{framework !== "all" && (
<FilterChip
label={framework}
onDismiss={() => clearFilter("framework")}
/>
)}
{genUi !== "all" && (
<FilterChip
label={GEN_UI_LABELS[genUi]}
onDismiss={() => clearFilter("genUi")}
/>
)}
{modality !== "all" && (
<FilterChip
label={MODALITY_LABELS[modality]}
onDismiss={() => clearFilter("modality")}
/>
)}
</div>
)}
{/* Demo cards grouped by category */}
{filteredDemos.length === 0 ? (
<div className="text-center py-16 text-[var(--text-muted)] text-sm">
No demos match the current filters.
</div>
) : (
<div className="flex flex-col gap-8">
{groupedDemos.map(([category, demos]) => (
<section key={category}>
<h3 className="text-[13px] font-semibold uppercase tracking-wider text-[var(--text-muted)] mb-3">
{getCategoryLabel(category)}
</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{demos.map(({ integration, demo }) => (
<DemoCard
key={`${integration.slug}::${demo.id}`}
integration={integration}
demo={demo}
/>
))}
</div>
</section>
))}
</div>
)}
</div>
</div>
);
}
// ---------------------------------------------------------------------------
// FilterGroup
// ---------------------------------------------------------------------------
function FilterGroup({
title,
children,
}: {
title: string;
children: React.ReactNode;
}) {
return (
<div className="mb-5">
<h3 className="text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)] mb-2 px-1">
{title}
</h3>
<div className="flex flex-col gap-0.5">{children}</div>
</div>
);
}
// ---------------------------------------------------------------------------
// RadioOption
// ---------------------------------------------------------------------------
function RadioOption({
label,
count,
selected,
comingSoon,
onClick,
}: {
label: string;
count?: number;
selected?: boolean;
comingSoon?: boolean;
onClick?: () => void;
}) {
if (comingSoon) {
return (
<div className="flex items-center justify-between rounded-md px-2 py-1.5 cursor-default">
<span className="text-[13px] text-[var(--text-faint)]">{label}</span>
<span className="text-[10px] text-[var(--text-faint)] italic">
soon
</span>
</div>
);
}
return (
<button
type="button"
onClick={onClick}
className={`flex items-center justify-between rounded-md px-2 py-1.5 text-left transition-colors ${
selected
? "bg-[var(--accent-light)] text-[var(--accent)]"
: "text-[var(--text-secondary)] hover:bg-[var(--bg-elevated)]"
}`}
>
<span className={`text-[13px] ${selected ? "font-medium" : ""}`}>
{label}
</span>
{count !== undefined && (
<span
className={`text-[11px] ${selected ? "text-[var(--accent)]" : "text-[var(--text-muted)]"}`}
>
{count}
</span>
)}
</button>
);
}
// ---------------------------------------------------------------------------
// FilterChip
// ---------------------------------------------------------------------------
function FilterChip({
label,
onDismiss,
}: {
label: string;
onDismiss: () => void;
}) {
return (
<button
type="button"
onClick={onDismiss}
className="inline-flex items-center gap-1.5 rounded-full border border-[var(--border)] bg-[var(--bg-elevated)] px-2.5 py-1 text-[12px] text-[var(--text-secondary)] hover:border-[var(--accent)] hover:text-[var(--accent)] transition-colors"
>
{label}
<svg
width="10"
height="10"
viewBox="0 0 10 10"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
>
<path d="M2.5 2.5L7.5 7.5M7.5 2.5L2.5 7.5" />
</svg>
</button>
);
}
// ---------------------------------------------------------------------------
// DemoCard
// ---------------------------------------------------------------------------
function DemoCard({
integration,
demo,
}: {
integration: Integration;
demo: Integration["demos"][number];
}) {
const [hovered, setHovered] = useState(false);
const previewUrl =
demo.animated_preview_url || integration.animated_preview_url;
return (
<Link
href={`/integrations/${integration.slug}?demo=${demo.id}`}
className="group relative block rounded-xl border border-[var(--border)] bg-[var(--bg-surface)] p-4 transition-all hover:border-[var(--accent)] hover:shadow-md"
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
>
{/* Animated preview — floating overlay on hover, no layout shift */}
{hovered && previewUrl && (
<div className="absolute bottom-full left-0 right-0 z-50 mb-2 pointer-events-none">
<video
src={previewUrl}
autoPlay
muted
loop
playsInline
className="w-full h-auto rounded-lg shadow-xl border border-[var(--border)]"
/>
</div>
)}
{/* Badges */}
<div className="flex flex-wrap items-center gap-2 mb-3">
{integration.logo && (
<img
src={integration.logo}
alt=""
className="w-5 h-5 rounded"
onError={(e) => {
(e.target as HTMLImageElement).style.display = "none";
}}
/>
)}
<span className="inline-flex items-center rounded-full bg-[var(--accent-light)] px-2.5 py-0.5 text-[11px] font-medium text-[var(--accent)]">
{integration.name}
</span>
{integration.managed_platform && (
<span
className="inline-flex items-center rounded-full px-2.5 py-0.5 text-[11px] font-medium text-[var(--blue)] cursor-pointer"
style={{
backgroundColor:
"color-mix(in srgb, var(--blue) 10%, transparent)",
}}
onClick={(e) => {
e.preventDefault();
window.open(integration.managed_platform!.url, "_blank");
}}
>
{integration.managed_platform.name}
</span>
)}
</div>
{/* Name + description */}
<h3 className="text-[14px] font-semibold text-[var(--text)] mb-1 group-hover:text-[var(--accent)] transition-colors">
{demo.name}
</h3>
<p className="text-[12px] text-[var(--text-secondary)] leading-relaxed line-clamp-2">
{demo.description}
</p>
</Link>
);
}