@cntyclub/ui-react 0.14.0 → 0.15.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntyclub/ui-react",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "React component library for the Country Club UI Kit — Base UI primitives styled with the Country Club design system (Tailwind CSS v4)",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -0,0 +1,67 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ import { cn } from "../../lib/utils/css";
6
+
7
+ type ChatDividerVariant = "default" | "summary" | "unread";
8
+
9
+ interface ChatDividerProps extends React.HTMLAttributes<HTMLDivElement> {
10
+ /** Centered label, e.g. "New messages", "You're caught up", "Earlier messages summarized". */
11
+ label?: React.ReactNode;
12
+ /** Optional leading icon (e.g. a summary or sparkle glyph). */
13
+ icon?: React.ReactNode;
14
+ /**
15
+ * - `default` — neutral hairline with a muted label.
16
+ * - `summary` — marks where a rolling summary folds older history.
17
+ * - `unread` — the "new messages" baseline; accented so it stands out.
18
+ */
19
+ variant?: ChatDividerVariant;
20
+ }
21
+
22
+ const LABEL_TONE: Record<ChatDividerVariant, string> = {
23
+ default: "text-muted-foreground",
24
+ summary: "text-muted-foreground",
25
+ unread: "text-primary",
26
+ };
27
+
28
+ const LINE_TONE: Record<ChatDividerVariant, string> = {
29
+ default: "bg-border",
30
+ summary: "bg-border",
31
+ unread: "bg-primary/40",
32
+ };
33
+
34
+ /**
35
+ * A centered, labeled divider for the message stream: the point a rolling summary
36
+ * folds history (`summary`), the unread baseline (`unread`), or a plain date/section
37
+ * break (`default`). Pairs with the backend `AgentSummaryCheckpoint` and each
38
+ * participant's `joined_seq`/`last_read_seq`.
39
+ */
40
+ function ChatDivider({ label, icon, variant = "default", className, ...props }: ChatDividerProps) {
41
+ return (
42
+ <div
43
+ className={cn("flex w-full items-center gap-3 py-1 select-none", className)}
44
+ data-slot="chat-divider"
45
+ data-variant={variant}
46
+ role="separator"
47
+ {...props}
48
+ >
49
+ <span className={cn("h-px flex-1", LINE_TONE[variant])} />
50
+ {label != null ? (
51
+ <span
52
+ className={cn(
53
+ "inline-flex items-center gap-1.5 font-medium text-xs whitespace-nowrap",
54
+ LABEL_TONE[variant],
55
+ )}
56
+ >
57
+ {icon ? <span className="inline-flex shrink-0 items-center">{icon}</span> : null}
58
+ {label}
59
+ </span>
60
+ ) : null}
61
+ <span className={cn("h-px flex-1", LINE_TONE[variant])} />
62
+ </div>
63
+ );
64
+ }
65
+
66
+ export { ChatDivider };
67
+ export type { ChatDividerProps, ChatDividerVariant };
@@ -0,0 +1,134 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+
5
+ import { cn } from "../../lib/utils/css";
6
+
7
+ type ContextMeterState = "ok" | "warn" | "summarizing" | "full";
8
+
9
+ interface ContextMeterProps extends Omit<React.SVGProps<SVGSVGElement>, "children"> {
10
+ /** Tokens currently in context. Used with `budget` when `pct` is not given. */
11
+ used?: number;
12
+ /** The model's context budget in tokens. */
13
+ budget?: number;
14
+ /** Fill fraction 0..1. Takes precedence over `used`/`budget` when provided. */
15
+ pct?: number;
16
+ /** Visual state; derived from the thresholds below when omitted. */
17
+ state?: ContextMeterState;
18
+ /** Threshold fractions — mirror the backend `config.context` values. */
19
+ warnAt?: number;
20
+ summarizeAt?: number;
21
+ lockAt?: number;
22
+ /** Diameter in px. */
23
+ size?: number;
24
+ /** Ring thickness in px. */
25
+ strokeWidth?: number;
26
+ /** Render the rounded percentage in the ring's center. */
27
+ showLabel?: boolean;
28
+ className?: string;
29
+ }
30
+
31
+ const STATE_COLOR: Record<ContextMeterState, string> = {
32
+ ok: "text-muted-foreground",
33
+ warn: "text-amber-500",
34
+ summarizing: "text-sky-500",
35
+ full: "text-destructive",
36
+ };
37
+
38
+ function deriveState(
39
+ pct: number,
40
+ warnAt: number,
41
+ summarizeAt: number,
42
+ lockAt: number,
43
+ ): ContextMeterState {
44
+ if (pct >= lockAt) return "full";
45
+ if (pct >= summarizeAt) return "summarizing";
46
+ if (pct >= warnAt) return "warn";
47
+ return "ok";
48
+ }
49
+
50
+ /**
51
+ * A compact radial gauge for how full an agent conversation's context window is.
52
+ *
53
+ * Feed it the backend `context_meter` payload (`pct`/`state` + thresholds) or a
54
+ * raw `used`/`budget` pair. The ring colors shift as the conversation approaches
55
+ * the summarize (folds older messages) and lock (must start a new chat) points,
56
+ * mirroring Claude Code's context indicator. Theme-aware and accessible
57
+ * (`role="meter"`).
58
+ */
59
+ function ContextMeter({
60
+ used,
61
+ budget,
62
+ pct,
63
+ state,
64
+ warnAt = 0.75,
65
+ summarizeAt = 0.85,
66
+ lockAt = 0.98,
67
+ size = 24,
68
+ strokeWidth = 2.5,
69
+ showLabel = false,
70
+ className,
71
+ ...props
72
+ }: ContextMeterProps) {
73
+ const fraction = Math.max(
74
+ 0,
75
+ Math.min(1, pct ?? (budget ? (used ?? 0) / budget : 0)),
76
+ );
77
+ const resolvedState = state ?? deriveState(fraction, warnAt, summarizeAt, lockAt);
78
+ const percent = Math.round(fraction * 100);
79
+
80
+ const radius = (size - strokeWidth) / 2;
81
+ const circumference = 2 * Math.PI * radius;
82
+ const dash = circumference * fraction;
83
+ const center = size / 2;
84
+
85
+ return (
86
+ <span
87
+ className={cn("relative inline-flex items-center justify-center", STATE_COLOR[resolvedState])}
88
+ data-slot="context-meter"
89
+ data-state={resolvedState}
90
+ style={{ width: size, height: size }}
91
+ >
92
+ <svg
93
+ width={size}
94
+ height={size}
95
+ viewBox={`0 0 ${size} ${size}`}
96
+ role="meter"
97
+ aria-valuemin={0}
98
+ aria-valuemax={100}
99
+ aria-valuenow={percent}
100
+ aria-label={`Context ${percent}% used`}
101
+ className={cn("-rotate-90", className)}
102
+ {...props}
103
+ >
104
+ <circle
105
+ cx={center}
106
+ cy={center}
107
+ r={radius}
108
+ fill="none"
109
+ strokeWidth={strokeWidth}
110
+ className="stroke-muted"
111
+ />
112
+ <circle
113
+ cx={center}
114
+ cy={center}
115
+ r={radius}
116
+ fill="none"
117
+ strokeWidth={strokeWidth}
118
+ strokeLinecap="round"
119
+ stroke="currentColor"
120
+ strokeDasharray={`${dash} ${circumference}`}
121
+ className="transition-[stroke-dasharray] duration-500 ease-out"
122
+ />
123
+ </svg>
124
+ {showLabel ? (
125
+ <span className="absolute font-medium text-[0.5rem] text-foreground tabular-nums">
126
+ {percent}
127
+ </span>
128
+ ) : null}
129
+ </span>
130
+ );
131
+ }
132
+
133
+ export { ContextMeter };
134
+ export type { ContextMeterProps, ContextMeterState };
package/src/index.ts CHANGED
@@ -24,12 +24,14 @@ export * from "./components/ui/card";
24
24
  export * from "./components/ui/carousel";
25
25
  export * from "./components/ui/chart";
26
26
  export * from "./components/ui/chat";
27
+ export * from "./components/ui/chat-divider";
27
28
  export * from "./components/ui/checkbox";
28
29
  export * from "./components/ui/checkbox-group";
29
30
  export * from "./components/ui/collapsible";
30
31
  export * from "./components/ui/combobox";
31
32
  export * from "./components/ui/command";
32
33
  export * from "./components/ui/confetti";
34
+ export * from "./components/ui/context-meter";
33
35
  export * from "./components/ui/credit-card";
34
36
  export * from "./components/ui/data-table-paged";
35
37
  export * from "./components/ui/drawer";