forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackages-section.tsx
More file actions
145 lines (136 loc) · 5.03 KB
/
Copy pathpackages-section.tsx
File metadata and controls
145 lines (136 loc) · 5.03 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
"use client";
/**
* Packages section: one row per package, each showing an L1-L4 strip and
* an achieved-depth column (D0-D4).
*/
import { useMemo } from "react";
import { getPackages, type Package } from "@/lib/registry";
import {
keyFor,
type ConnectionStatus,
type LiveStatusMap,
} from "@/lib/live-status";
import { LevelStrip } from "@/components/level-strip";
import { DepthChip } from "@/components/depth-chip";
/**
* Adapter: LevelStrip expects an Integration-shaped object but packages
* only have slug + name. Build a minimal compatible shape.
*/
function packageAsIntegration(pkg: Package) {
return {
slug: pkg.slug,
name: pkg.name,
category: "",
language: "",
description: "",
repo: "",
backend_url: "",
deployed: true,
features: [],
demos: [], // no demos -> Tools badge shows n/a
};
}
/**
* Derive a simple integration-scoped depth for a package row.
* Packages don't have per-feature e2e data, so D3 is skipped.
* D0 = exists, D1 = health green, D2 = agent green, D4 = chat|tools green.
*/
function derivePackageDepth(
slug: string,
liveStatus: LiveStatusMap,
): 0 | 1 | 2 | 4 {
const health = liveStatus.get(keyFor("health", slug));
if (!health || health.state !== "green") return 0;
const agent = liveStatus.get(keyFor("agent", slug));
if (!agent || agent.state !== "green") return 1;
const chat = liveStatus.get(keyFor("chat", slug));
const tools = liveStatus.get(keyFor("tools", slug));
if ((chat && chat.state === "green") || (tools && tools.state === "green")) {
return 4;
}
return 2;
}
export interface PackagesSectionProps {
/** Merged live-status map from all subscribed dimensions (lifted to page). */
liveStatus: LiveStatusMap;
/** Aggregated SSE connection status (lifted to page). */
connection: ConnectionStatus;
}
export function PackagesSection({
liveStatus,
connection,
}: PackagesSectionProps) {
const packages = useMemo(() => getPackages(), []);
if (packages.length === 0) return null;
return (
<div className="px-8 pb-8" data-testid="packages-section">
<h2 className="text-lg font-semibold tracking-tight mb-3">Packages</h2>
{connection === "error" && (
<div
role="alert"
className="mb-3 rounded-md border border-[var(--danger)] bg-[var(--bg-danger)] px-4 py-2 text-xs text-[var(--danger)]"
>
dashboard unavailable — check #oss-alerts
</div>
)}
<div className="overflow-auto rounded-lg border border-[var(--border)] bg-[var(--bg-surface)]">
<table className="border-collapse text-sm w-full">
<thead>
<tr>
<th className="sticky left-0 top-0 z-30 bg-[var(--bg-muted)] px-4 py-2 text-left border-b border-[var(--border)]">
<span className="text-[10px] font-medium uppercase tracking-wider text-[var(--text-muted)]">
Package
</span>
</th>
<th className="bg-[var(--bg-muted)] px-4 py-2 text-left border-b border-l border-[var(--border)]">
<span className="text-[10px] font-medium uppercase tracking-wider text-[var(--text-muted)]">
L1-L4 Status
</span>
<span
className="ml-2 text-[10px] font-normal normal-case text-[var(--text-muted)]"
data-testid="packages-uwct-legend"
>
(U=Up, W=Wired, C=Chats, T=Tools)
</span>
</th>
<th className="bg-[var(--bg-muted)] px-4 py-2 text-center border-b border-l border-[var(--border)]">
<span className="text-[10px] font-medium uppercase tracking-wider text-[var(--text-muted)]">
Depth
</span>
</th>
</tr>
</thead>
<tbody>
{packages.map((pkg) => {
const depth = derivePackageDepth(pkg.slug, liveStatus);
return (
<tr
key={pkg.slug}
className="border-t border-[var(--border)] hover:bg-[var(--bg-hover)]"
>
<td className="sticky left-0 z-10 bg-[var(--bg-surface)] px-4 py-2 border-r border-[var(--border)]">
<span className="font-medium text-[var(--text)]">
{pkg.name}
</span>
<span className="ml-2 text-[10px] text-[var(--text-muted)]">
{pkg.slug}
</span>
</td>
<td className="px-4 py-2 border-l border-[var(--border)]">
<LevelStrip
integration={packageAsIntegration(pkg)}
liveStatus={liveStatus}
/>
</td>
<td className="px-4 py-2 border-l border-[var(--border)] text-center">
<DepthChip depth={depth} status="wired" />
</td>
</tr>
);
})}
</tbody>
</table>
</div>
</div>
);
}