@lobu/runtime-device 24.5.0 → 24.7.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.
Files changed (33) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +32 -17
  3. package/npm-shrinkwrap.json +140 -89
  4. package/package.json +2 -1
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +57 -9
  6. package/vendor/cli/dist/commands/_lib/view-bundler.js +9 -1
  7. package/vendor/cli/dist/connectors/linkedin-identity.ts +43 -0
  8. package/vendor/cli/dist/connectors/linkedin.ts +154 -3
  9. package/vendor/cli/dist/connectors/x-like-follow.ts +329 -0
  10. package/vendor/cli/dist/connectors/x.ts +709 -80
  11. package/vendor/cli/dist/internal/connector-compiler.js +3 -1
  12. package/vendor/cli/dist/runtime-components.json +4 -4
  13. package/vendor/cli/package.json +2 -1
  14. package/vendor/connector-sdk/package.json +1 -1
  15. package/vendor/connector-worker/dist/compile/index.d.ts +4 -3
  16. package/vendor/connector-worker/dist/compile/index.js +6 -3
  17. package/vendor/connector-worker/package.json +1 -1
  18. package/vendor/core/dist/contracts/tools/view-host.d.ts +7 -0
  19. package/vendor/core/dist/contracts/tools/view-host.js +28 -0
  20. package/vendor/core/dist/contracts/tools/view-runtime.d.ts +2 -4
  21. package/vendor/core/dist/contracts/tools/view-runtime.js +19 -7
  22. package/vendor/core/package.json +11 -1
  23. package/vendor/views/dist/api.d.ts +290 -0
  24. package/vendor/views/dist/api.js +714 -0
  25. package/vendor/views/dist/bridge.d.ts +157 -0
  26. package/vendor/views/dist/bridge.js +372 -0
  27. package/vendor/views/dist/components.d.ts +172 -0
  28. package/vendor/views/dist/components.js +376 -0
  29. package/vendor/views/dist/index.d.ts +13 -0
  30. package/vendor/views/dist/index.js +3 -0
  31. package/vendor/views/dist/native.d.ts +327 -0
  32. package/vendor/views/dist/native.js +57 -0
  33. package/vendor/views/package.json +53 -0
@@ -0,0 +1,172 @@
1
+ /**
2
+ * `@lobu/views/components` — first-party presentational kit for Lobu views.
3
+ *
4
+ * React-only by design: inline styles, no fetch, no
5
+ * document access. Everything here runs inside the sandboxed MCP Apps frame,
6
+ * where the host (not the view) owns data access. Reads still go through
7
+ * `useQuery`/`tool`/`sql` from `@lobu/views`; these components only render
8
+ * what the host returns, plus the honest states (`QueryState.loading`,
9
+ * `.error`, `.errorCode`, `.truncated`) that `useQuery` reports.
10
+ *
11
+ * Styling follows the shell's theme tokens (`--fg`, `--muted`, `--border`,
12
+ * `--accent`, `--font`, `--radius`, `--radius-lg`), which derive from the
13
+ * host's MCP Apps style variables and flip with its `.dark` class, so kit
14
+ * output takes the host's look without configuration. Theme tokens carry
15
+ * light-mode fallbacks; pie series and error accents use fixed colors.
16
+ *
17
+ * Server-side compile allowlist: this module is pinned beside `react` and
18
+ * `@lobu/views` in the view compiler funds, so MCP/tool-path views may
19
+ * `import { DataTable } from "@lobu/views/components"`. Anything fancier
20
+ * (third-party chart/table libraries, user components in other files) ships
21
+ * through `lobu apply`, which bundles the project's own `node_modules`.
22
+ */
23
+ import type { ReactNode } from "react";
24
+ export interface CardProps {
25
+ title?: string;
26
+ description?: string;
27
+ actions?: ReactNode;
28
+ children: ReactNode;
29
+ }
30
+ /** Section container: title row, optional description and action slot. */
31
+ export declare function Card({ title, description, actions, children }: CardProps): import("react/jsx-runtime").JSX.Element;
32
+ export interface TableColumn<T> {
33
+ /** Stable key; doubles as the server sort key when `sortable`. */
34
+ key: string;
35
+ header: string;
36
+ align?: "left" | "center" | "right";
37
+ sortable?: boolean;
38
+ /** Custom cell. Defaults to `String(row[key] ?? "")`. */
39
+ render?: (row: T) => ReactNode;
40
+ }
41
+ export interface TablePagination {
42
+ /** 1-based current page. */
43
+ page: number;
44
+ pageSize: number;
45
+ /** Total rows when known; otherwise a short page disables Next. */
46
+ total?: number;
47
+ onPage: (page: number) => void;
48
+ }
49
+ export interface TableSort {
50
+ key: string;
51
+ dir: "asc" | "desc";
52
+ }
53
+ export interface DataTableProps<T> {
54
+ columns: TableColumn<T>[];
55
+ rows: T[];
56
+ keyOf: (row: T, index: number) => string | number;
57
+ loading?: boolean;
58
+ error?: string | null;
59
+ onRetry?: () => void;
60
+ emptyText?: string;
61
+ /** Controlled server-side sort; omit for unsorted data. */
62
+ sort?: TableSort;
63
+ onSort?: (key: string) => void;
64
+ pagination?: TablePagination;
65
+ caption?: string;
66
+ }
67
+ /**
68
+ * Server-driven table. The view owns state (page/sort live in `useParams`,
69
+ * rows come from `useQuery`); the table only renders and reports intent.
70
+ * Pass query loading/error state explicitly; render TruncatedNotice beside
71
+ * the table when the query reports partial results.
72
+ */
73
+ export declare function DataTable<T>({ columns, rows, keyOf, loading, error, onRetry, emptyText, sort, onSort, pagination, caption, }: DataTableProps<T>): import("react/jsx-runtime").JSX.Element;
74
+ /** Layout row for filter controls; wrap `SearchField`/`SelectField`. */
75
+ export declare function FilterBar({ children }: {
76
+ children: ReactNode;
77
+ }): import("react/jsx-runtime").JSX.Element;
78
+ /**
79
+ * Controlled search box. The view owns the value (usually a `useParams`
80
+ * entry); pushing every keystroke into params re-renders the whole view, so
81
+ * debounce at the call site when the backing query is expensive.
82
+ */
83
+ export declare function SearchField({ label, value, onChange, placeholder, }: {
84
+ label?: string;
85
+ value: string;
86
+ onChange: (value: string) => void;
87
+ placeholder?: string;
88
+ }): import("react/jsx-runtime").JSX.Element;
89
+ export interface SelectOption {
90
+ value: string;
91
+ label: string;
92
+ }
93
+ /** Controlled select. `value === ""` means "no filter". */
94
+ export declare function SelectField({ label, value, options, onChange, }: {
95
+ label: string;
96
+ value: string;
97
+ options: SelectOption[];
98
+ onChange: (value: string) => void;
99
+ }): import("react/jsx-runtime").JSX.Element;
100
+ export interface ChartDatum {
101
+ label: string;
102
+ value: number;
103
+ color?: string;
104
+ }
105
+ /** Vertical bars. Values must already be aggregated — views cannot aggregate history. */
106
+ export declare function BarChart({ data, title, height, formatValue, }: {
107
+ data: ChartDatum[];
108
+ title?: string;
109
+ height?: number;
110
+ formatValue?: (v: number) => string;
111
+ }): import("react/jsx-runtime").JSX.Element;
112
+ /** Single-series line over ordered labels. */
113
+ export declare function LineChart({ data, title, height, baseline, formatValue, }: {
114
+ data: ChartDatum[];
115
+ title?: string;
116
+ height?: number;
117
+ /** `zero` (default) includes 0; `auto` fits the data's range. */
118
+ baseline?: "zero" | "auto";
119
+ formatValue?: (v: number) => string;
120
+ }): import("react/jsx-runtime").JSX.Element;
121
+ /** Pie with legend. Cap slices upstream (query limit); the chart renders what it gets. */
122
+ export declare function PieChart({ data, title, size, formatValue, }: {
123
+ data: ChartDatum[];
124
+ title?: string;
125
+ size?: number;
126
+ formatValue?: (v: number) => string;
127
+ }): import("react/jsx-runtime").JSX.Element;
128
+ /** Single-series inline trend. Purely presentational — no axes. */
129
+ export declare function Sparkline({ values, width, height, label, }: {
130
+ values: number[];
131
+ width?: number;
132
+ height?: number;
133
+ label?: string;
134
+ }): import("react/jsx-runtime").JSX.Element;
135
+ /**
136
+ * A link the host opens: `href="deal/acme-renewal"` opens that record
137
+ * (relative links resolve against the workspace root, see
138
+ * `useHost().openLink`). On Lobu hosts, supported same-workspace links open
139
+ * the peek pane; other app links navigate normally and external URLs open a new
140
+ * tab. The sandboxed frame cannot navigate itself, so every click goes through the host, modifier
141
+ * clicks included; the anchor still shows the resolved address on hover.
142
+ */
143
+ export declare function Link({ href, children, }: {
144
+ href: string;
145
+ children: ReactNode;
146
+ }): import("react/jsx-runtime").JSX.Element;
147
+ export declare function LoadingState({ text }: {
148
+ text?: string;
149
+ }): import("react/jsx-runtime").JSX.Element;
150
+ export declare function EmptyState({ title, hint }: {
151
+ title: string;
152
+ hint?: string;
153
+ }): import("react/jsx-runtime").JSX.Element;
154
+ export declare function ErrorState({ message, errorCode, onRetry, }: {
155
+ message: string;
156
+ /** The server's typed code (e.g. UPSTREAM_TIMEOUT). Shown, never branched on for copy. */
157
+ errorCode?: string | null;
158
+ onRetry?: () => void;
159
+ }): import("react/jsx-runtime").JSX.Element;
160
+ /**
161
+ * Honest cap notice: the server answered, but not wholly (`query_sql` 500-row
162
+ * ceiling, `query_sdk` oversized return). Rendered data is partial by
163
+ * construction — narrow the query instead of treating it as complete.
164
+ */
165
+ export declare function TruncatedNotice({ shown, total, }: {
166
+ shown: number;
167
+ total?: number;
168
+ }): import("react/jsx-runtime").JSX.Element;
169
+ /** Format large counts compactly (1.2K, 3.4M). Plain numbers pass through. */
170
+ export declare function formatCompact(value: number): string;
171
+ export * from "./native.js";
172
+ //# sourceMappingURL=components.d.ts.map
@@ -0,0 +1,376 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useRef, useState } from "react";
3
+ import { resolveViewHref, useHost } from "./api.js";
4
+ const FONT_STACK = 'var(--font, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif)';
5
+ const INK = {
6
+ color: "var(--fg, #0a0a0a)",
7
+ fontFamily: FONT_STACK,
8
+ fontSize: 13,
9
+ lineHeight: 1.45,
10
+ };
11
+ /** Section container: title row, optional description and action slot. */
12
+ export function Card({ title, description, actions, children }) {
13
+ return (_jsxs("section", { style: {
14
+ ...INK,
15
+ border: "1px solid var(--border, #e5e7eb)",
16
+ borderRadius: "var(--radius-lg, 8px)",
17
+ padding: "12px 14px",
18
+ background: "transparent",
19
+ }, children: [(title || actions) && (_jsxs("header", { style: {
20
+ display: "flex",
21
+ alignItems: "baseline",
22
+ justifyContent: "space-between",
23
+ gap: 12,
24
+ marginBottom: description || children ? 4 : 0,
25
+ }, children: [title && (_jsx("h3", { style: { margin: 0, fontSize: 14, fontWeight: 600 }, children: title })), actions] })), description && (_jsx("p", { style: {
26
+ margin: "0 0 8px",
27
+ color: "var(--color-text-secondary, #6b7280)",
28
+ }, children: description })), children] }));
29
+ }
30
+ const CELL = {
31
+ padding: "6px 8px",
32
+ borderBottom: "1px solid var(--border, #e5e7eb)",
33
+ textAlign: "left",
34
+ verticalAlign: "top",
35
+ overflowWrap: "anywhere",
36
+ };
37
+ /**
38
+ * Server-driven table. The view owns state (page/sort live in `useParams`,
39
+ * rows come from `useQuery`); the table only renders and reports intent.
40
+ * Pass query loading/error state explicitly; render TruncatedNotice beside
41
+ * the table when the query reports partial results.
42
+ */
43
+ export function DataTable({ columns, rows, keyOf, loading = false, error = null, onRetry, emptyText = "No rows.", sort, onSort, pagination, caption, }) {
44
+ const labelId = useId();
45
+ const pageCount = pagination && pagination.total != null
46
+ ? Math.max(1, Math.ceil(pagination.total / pagination.pageSize))
47
+ : null;
48
+ return (_jsxs("div", { style: INK, children: [caption && (_jsx("p", { id: labelId, style: {
49
+ margin: "0 0 6px",
50
+ color: "var(--color-text-secondary, #6b7280)",
51
+ }, children: caption })), _jsx("div", { style: { overflowX: "auto" }, children: _jsxs("table", { "aria-labelledby": caption ? labelId : undefined, style: { borderCollapse: "collapse", width: "100%" }, children: [_jsx("thead", { children: _jsx("tr", { children: columns.map((col) => (_jsx("th", { "aria-sort": sort?.key === col.key
52
+ ? sort.dir === "asc"
53
+ ? "ascending"
54
+ : "descending"
55
+ : undefined, style: {
56
+ ...CELL,
57
+ fontWeight: 600,
58
+ whiteSpace: "nowrap",
59
+ textAlign: col.align ?? "left",
60
+ }, children: col.sortable && onSort ? (_jsxs("button", { type: "button", onClick: () => onSort(col.key), title: `Sort by ${col.header}`, style: {
61
+ border: 0,
62
+ padding: 0,
63
+ background: "transparent",
64
+ font: "inherit",
65
+ cursor: "pointer",
66
+ color: "var(--color-text-info, #2563eb)",
67
+ }, children: [col.header, sort?.key === col.key
68
+ ? sort.dir === "asc"
69
+ ? " ▲"
70
+ : " ▼"
71
+ : ""] })) : (col.header) }, col.key))) }) }), _jsx("tbody", { children: rows.map((row, i) => (_jsx("tr", { children: columns.map((col) => (_jsx("td", { style: { ...CELL, textAlign: col.align ?? "left" }, children: col.render
72
+ ? col.render(row)
73
+ : String(row[col.key] ?? "") }, col.key))) }, keyOf(row, i)))) })] }) }), loading && _jsx(LoadingState, { text: "Loading rows\u2026" }), error && !loading && _jsx(ErrorState, { message: error, onRetry: onRetry }), !loading && !error && rows.length === 0 && (_jsx(EmptyState, { title: emptyText })), pagination &&
74
+ (pageCount == null || pageCount > 1 || pagination.page > 1) && (_jsxs("nav", { "aria-label": "Table pages", style: {
75
+ display: "flex",
76
+ alignItems: "center",
77
+ gap: 8,
78
+ marginTop: 8,
79
+ }, children: [_jsx(PageButton, { disabled: pagination.page <= 1, onClick: () => pagination.onPage(pagination.page - 1), label: "Previous page" }), _jsxs("span", { style: { color: "var(--color-text-secondary, #6b7280)" }, children: ["Page ", pagination.page, pageCount != null ? ` of ${pageCount}` : ""] }), _jsx(PageButton, { disabled: pageCount == null
80
+ ? rows.length < pagination.pageSize
81
+ : pagination.page >= pageCount, onClick: () => pagination.onPage(pagination.page + 1), label: "Next page" })] }))] }));
82
+ }
83
+ function PageButton({ disabled, onClick, label, }) {
84
+ return (_jsx("button", { type: "button", disabled: disabled, onClick: onClick, "aria-label": label, style: {
85
+ cursor: disabled ? "default" : "pointer",
86
+ opacity: disabled ? 0.45 : 1,
87
+ border: "1px solid var(--border, #e5e7eb)",
88
+ borderRadius: "var(--radius, 6px)",
89
+ background: "transparent",
90
+ color: "var(--fg, #0a0a0a)",
91
+ padding: "2px 10px",
92
+ font: "inherit",
93
+ }, children: label === "Previous page" ? "‹ Prev" : "Next ›" }));
94
+ }
95
+ /* ------------------------------------------------------------------ */
96
+ /* Filters */
97
+ /* ------------------------------------------------------------------ */
98
+ /** Layout row for filter controls; wrap `SearchField`/`SelectField`. */
99
+ export function FilterBar({ children }) {
100
+ return (_jsx("search", { style: {
101
+ display: "flex",
102
+ flexWrap: "wrap",
103
+ alignItems: "end",
104
+ gap: 8,
105
+ marginBottom: 8,
106
+ }, children: children }));
107
+ }
108
+ const FIELD_LABEL = {
109
+ display: "block",
110
+ fontSize: 12,
111
+ color: "var(--color-text-secondary, #6b7280)",
112
+ marginBottom: 2,
113
+ };
114
+ const FIELD_BOX = {
115
+ border: "1px solid var(--border, #e5e7eb)",
116
+ borderRadius: "var(--radius, 6px)",
117
+ background: "transparent",
118
+ color: "var(--fg, #0a0a0a)",
119
+ padding: "4px 8px",
120
+ font: "inherit",
121
+ maxWidth: "100%",
122
+ };
123
+ /**
124
+ * Controlled search box. The view owns the value (usually a `useParams`
125
+ * entry); pushing every keystroke into params re-renders the whole view, so
126
+ * debounce at the call site when the backing query is expensive.
127
+ */
128
+ export function SearchField({ label = "Search", value, onChange, placeholder = "", }) {
129
+ const id = useId();
130
+ return (_jsxs("label", { style: { ...INK, display: "block" }, children: [_jsx("span", { style: FIELD_LABEL, children: label }), _jsx("input", { id: id, type: "search", value: value, placeholder: placeholder, onChange: (e) => onChange(e.target.value), style: { ...FIELD_BOX, minWidth: 180 } })] }));
131
+ }
132
+ /** Controlled select. `value === ""` means "no filter". */
133
+ export function SelectField({ label, value, options, onChange, }) {
134
+ const id = useId();
135
+ return (_jsxs("label", { style: { ...INK, display: "block" }, children: [_jsx("span", { style: FIELD_LABEL, children: label }), _jsxs("select", { id: id, value: value, onChange: (e) => onChange(e.target.value), style: FIELD_BOX, children: [_jsx("option", { value: "", children: "All" }), options.map((o) => (_jsx("option", { value: o.value, children: o.label }, o.value)))] })] }));
136
+ }
137
+ const CHART_BAR = "var(--color-text-info, #2563eb)";
138
+ const CHART_GRID = "var(--border, #e5e7eb)";
139
+ const CHART_TEXT = "var(--color-text-secondary, #6b7280)";
140
+ function niceMax(value) {
141
+ if (!Number.isFinite(value) || value <= 0)
142
+ return 1;
143
+ const power = 10 ** Math.floor(Math.log10(value));
144
+ const scaled = value / power;
145
+ const nice = scaled <= 1 ? 1 : scaled <= 2 ? 2 : scaled <= 5 ? 5 : 10;
146
+ return nice * power;
147
+ }
148
+ const CHART_FALLBACK_WIDTH = 320;
149
+ /** Width of the chart's own box, so the SVG draws at its real size instead of
150
+ * letterboxing a fixed viewBox inside a wider card. */
151
+ function useChartWidth() {
152
+ const ref = useRef(null);
153
+ const [width, setWidth] = useState(CHART_FALLBACK_WIDTH);
154
+ useEffect(() => {
155
+ const el = ref.current;
156
+ if (!el || typeof ResizeObserver === "undefined")
157
+ return;
158
+ const observer = new ResizeObserver(([entry]) => {
159
+ const next = Math.round(entry.contentRect.width);
160
+ if (next > 0)
161
+ setWidth(next);
162
+ });
163
+ observer.observe(el);
164
+ return () => observer.disconnect();
165
+ }, []);
166
+ return [ref, width];
167
+ }
168
+ function ChartFrame({ title, width, height, frameRef, children, labelledBy, }) {
169
+ return (_jsxs("figure", { ref: frameRef, style: { ...INK, margin: 0 }, children: [title && (_jsx("figcaption", { id: labelledBy, style: { fontWeight: 600, marginBottom: 4 }, children: title })), _jsx("svg", { role: "img", "aria-labelledby": title ? labelledBy : undefined, "aria-label": title ? undefined : "Chart", viewBox: `0 0 ${width} ${height}`, width: "100%", height: height, style: { display: "block" }, children: children })] }));
170
+ }
171
+ /** Vertical bars. Values must already be aggregated — views cannot aggregate history. */
172
+ export function BarChart({ data, title, height = 180, formatValue = (v) => String(v), }) {
173
+ const id = useId();
174
+ const [frameRef, width] = useChartWidth();
175
+ const max = niceMax(Math.max(0, ...data.map((d) => d.value)));
176
+ const min = Math.min(0, ...data.map((d) => d.value));
177
+ const padL = 44;
178
+ const padB = 22;
179
+ const padT = 6;
180
+ const w = width - padL - 8;
181
+ const h = height - padT - padB;
182
+ const y = (value) => padT + h - ((value - min) / (max - min)) * h;
183
+ const zero = y(0);
184
+ const slot = data.length > 0 ? w / data.length : w;
185
+ const bw = Math.max(2, Math.min(28, slot * 0.6));
186
+ return (_jsxs(ChartFrame, { title: title, width: width, height: height, frameRef: frameRef, labelledBy: id, children: [_jsx("line", { x1: padL, y1: padT, x2: padL, y2: padT + h, stroke: CHART_GRID }), _jsx("line", { x1: padL, y1: zero, x2: padL + w, y2: zero, stroke: CHART_GRID }), _jsx("text", { x: padL - 4, y: padT + 8, textAnchor: "end", fontSize: 9, fill: CHART_TEXT, children: formatValue(max) }), _jsx("text", { x: padL - 4, y: padT + h, textAnchor: "end", fontSize: 9, fill: CHART_TEXT, children: formatValue(min) }), data.map((d, i) => {
187
+ const bh = Math.abs(y(d.value) - zero);
188
+ const x = padL + i * slot + (slot - bw) / 2;
189
+ const top = Math.min(y(d.value), zero);
190
+ return (
191
+ // biome-ignore lint/suspicious/noArrayIndexKey: Stateless marks allow repeated labels at different positions.
192
+ _jsxs("g", { children: [_jsx("title", { children: `${d.label}: ${formatValue(d.value)}` }), _jsx("rect", { x: x, y: top, width: bw, height: bh, fill: d.color ?? CHART_BAR, rx: 2 }), _jsx("text", { x: x + bw / 2, y: padT + h + 12, textAnchor: "middle", fontSize: 9, fill: CHART_TEXT, children: d.label.length > 10 ? `${d.label.slice(0, 9)}…` : d.label })] }, `${d.label}-${i}`));
193
+ })] }));
194
+ }
195
+ /** Y-axis bounds for a line: include zero by default; `auto` fits the data's
196
+ * own range, for a series whose movement is small next to its level. */
197
+ function lineBounds(values, baseline) {
198
+ if (baseline === "zero" || values.length === 0) {
199
+ return {
200
+ min: Math.min(0, ...values),
201
+ max: niceMax(Math.max(0, ...values)),
202
+ };
203
+ }
204
+ const lo = Math.min(...values);
205
+ const hi = Math.max(...values);
206
+ const pad = (hi - lo) * 0.1 || Math.abs(hi) * 0.05 || 1;
207
+ return { min: lo - pad, max: hi + pad };
208
+ }
209
+ /** The end points sit on the plot's edges, so a centred label there spills
210
+ * past the frame; anchor the first and last labels inward instead. */
211
+ function edgeAnchor(i, count) {
212
+ if (count < 2)
213
+ return "middle";
214
+ if (i === 0)
215
+ return "start";
216
+ return i === count - 1 ? "end" : "middle";
217
+ }
218
+ /** Single-series line over ordered labels. */
219
+ export function LineChart({ data, title, height = 180, baseline = "zero", formatValue = (v) => String(v), }) {
220
+ const id = useId();
221
+ const [frameRef, width] = useChartWidth();
222
+ const values = data.map((d) => d.value);
223
+ const { min, max } = lineBounds(values, baseline);
224
+ const padL = 44;
225
+ const padB = 22;
226
+ const padT = 6;
227
+ const w = width - padL - 8;
228
+ const h = height - padT - padB;
229
+ const span = max - min || 1;
230
+ const x = (i) => data.length < 2 ? padL + w / 2 : padL + (i / (data.length - 1)) * w;
231
+ const y = (v) => padT + h - ((v - min) / span) * h;
232
+ const points = data.map((d, i) => `${x(i)},${y(d.value)}`).join(" ");
233
+ return (_jsxs(ChartFrame, { title: title, width: width, height: height, frameRef: frameRef, labelledBy: id, children: [_jsx("line", { x1: padL, y1: padT, x2: padL, y2: padT + h, stroke: CHART_GRID }), _jsx("line", { x1: padL, y1: padT + h, x2: padL + w, y2: padT + h, stroke: CHART_GRID }), _jsx("text", { x: padL - 4, y: padT + 8, textAnchor: "end", fontSize: 9, fill: CHART_TEXT, children: formatValue(max) }), min !== 0 && (_jsx("text", { x: padL - 4, y: padT + h, textAnchor: "end", fontSize: 9, fill: CHART_TEXT, children: formatValue(min) })), data.length > 0 && (_jsx("polyline", { points: points, fill: "none", stroke: CHART_BAR, strokeWidth: 2, strokeLinejoin: "round" })), data.map((d, i) => (
234
+ // biome-ignore lint/suspicious/noArrayIndexKey: Stateless marks allow repeated labels at different positions.
235
+ _jsxs("g", { children: [_jsx("title", { children: `${d.label}: ${formatValue(d.value)}` }), _jsx("circle", { cx: x(i), cy: y(d.value), r: 2.5, fill: CHART_BAR }), data.length <= 8 && (_jsx("text", { x: x(i), y: padT + h + 12, textAnchor: edgeAnchor(i, data.length), fontSize: 9, fill: CHART_TEXT, children: d.label.length > 10 ? `${d.label.slice(0, 9)}…` : d.label }))] }, `${d.label}-${i}`)))] }));
236
+ }
237
+ /** Pie with legend. Cap slices upstream (query limit); the chart renders what it gets. */
238
+ export function PieChart({ data, title, size = 180, formatValue = (v) => String(v), }) {
239
+ const id = useId();
240
+ const total = data.reduce((s, d) => s + (d.value > 0 ? d.value : 0), 0);
241
+ const palette = [
242
+ "#2563eb",
243
+ "#16a34a",
244
+ "#d97706",
245
+ "#dc2626",
246
+ "#7c3aed",
247
+ "#0891b2",
248
+ "#db2777",
249
+ "#65a30d",
250
+ ];
251
+ const r = Math.max(0, Math.min(70, size / 2 - 2));
252
+ const cx = 80;
253
+ const cy = size / 2;
254
+ let angle = -Math.PI / 2;
255
+ const slices = data.map((d, i) => {
256
+ const frac = total > 0 ? Math.max(0, d.value) / total : 0;
257
+ const a0 = angle;
258
+ angle += frac * Math.PI * 2;
259
+ const large = frac > 0.5 ? 1 : 0;
260
+ const x0 = cx + r * Math.cos(a0);
261
+ const y0 = cy + r * Math.sin(a0);
262
+ const x1 = cx + r * Math.cos(angle);
263
+ const y1 = cy + r * Math.sin(angle);
264
+ return {
265
+ d,
266
+ i,
267
+ frac,
268
+ path: `M ${cx} ${cy} L ${x0} ${y0} A ${r} ${r} 0 ${large} 1 ${x1} ${y1} Z`,
269
+ };
270
+ });
271
+ return (_jsxs("figure", { style: { ...INK, margin: 0 }, children: [title && (_jsx("figcaption", { id: id, style: { fontWeight: 600, marginBottom: 4 }, children: title })), _jsxs("div", { style: {
272
+ display: "flex",
273
+ flexWrap: "wrap",
274
+ alignItems: "center",
275
+ gap: 12,
276
+ }, children: [_jsx("svg", { role: "img", "aria-labelledby": title ? id : undefined, "aria-label": title ? undefined : "Pie chart", viewBox: `0 0 160 ${size}`, width: 160, height: size, style: { flexShrink: 0 }, children: total === 0 ? (_jsx("circle", { cx: cx, cy: cy, r: r, fill: "none", stroke: CHART_GRID })) : (slices.map((s) => s.frac === 1 ? (_jsx("circle", { cx: cx, cy: cy, r: r, fill: s.d.color ?? palette[s.i % palette.length], children: _jsx("title", { children: `${s.d.label}: ${formatValue(s.d.value)}` }) }, s.i)) : (_jsx("path", { d: s.path, fill: s.d.color ?? palette[s.i % palette.length], children: _jsx("title", { children: `${s.d.label}: ${formatValue(s.d.value)}` }) }, s.i)))) }), _jsx("ul", { style: { margin: 0, padding: 0, listStyle: "none" }, children: data.map((d, i) => (_jsxs("li", { style: {
277
+ display: "flex",
278
+ alignItems: "center",
279
+ gap: 6,
280
+ marginBottom: 2,
281
+ }, children: [_jsx("span", { "aria-hidden": "true", style: {
282
+ width: 10,
283
+ height: 10,
284
+ borderRadius: 2,
285
+ background: d.color ?? palette[i % palette.length],
286
+ flexShrink: 0,
287
+ } }), _jsxs("span", { children: [d.label, ": ", formatValue(d.value)] })] }, `${d.label}-${i}`))) })] })] }));
288
+ }
289
+ /** Single-series inline trend. Purely presentational — no axes. */
290
+ export function Sparkline({ values, width = 120, height = 32, label, }) {
291
+ const max = Math.max(0, ...values);
292
+ const min = Math.min(0, ...values);
293
+ const span = max - min || 1;
294
+ const x = (i) => values.length < 2 ? width / 2 : (i / (values.length - 1)) * width;
295
+ const y = (v) => height - 2 - ((v - min) / span) * (height - 4);
296
+ return (_jsxs("svg", { role: "img", "aria-label": label ?? "Trend", viewBox: `0 0 ${width} ${height}`, width: width, height: height, style: { display: "block" }, children: [values.length === 1 && (_jsx("circle", { cx: x(0), cy: y(values[0]), r: 1.5, fill: CHART_BAR })), values.length > 1 && (_jsx("polyline", { points: values.map((v, i) => `${x(i)},${y(v)}`).join(" "), fill: "none", stroke: CHART_BAR, strokeWidth: 1.5, strokeLinejoin: "round" }))] }));
297
+ }
298
+ /* ------------------------------------------------------------------ */
299
+ /* Link */
300
+ /* ------------------------------------------------------------------ */
301
+ /**
302
+ * A link the host opens: `href="deal/acme-renewal"` opens that record
303
+ * (relative links resolve against the workspace root, see
304
+ * `useHost().openLink`). On Lobu hosts, supported same-workspace links open
305
+ * the peek pane; other app links navigate normally and external URLs open a new
306
+ * tab. The sandboxed frame cannot navigate itself, so every click goes through the host, modifier
307
+ * clicks included; the anchor still shows the resolved address on hover.
308
+ */
309
+ export function Link({ href, children, }) {
310
+ const { openLink } = useHost();
311
+ const open = (event) => {
312
+ event.preventDefault();
313
+ openLink(href).catch((error) => console.error("[lobu-views] link not opened", error));
314
+ };
315
+ return (_jsx("a", { href: resolveViewHref(href), onClick: open, onAuxClick: (event) => {
316
+ if (event.button === 1)
317
+ open(event);
318
+ }, style: {
319
+ color: "var(--color-text-info, #2563eb)",
320
+ textDecoration: "none",
321
+ }, children: children }));
322
+ }
323
+ /* ------------------------------------------------------------------ */
324
+ /* Query states — render `useQuery` honestly */
325
+ /* ------------------------------------------------------------------ */
326
+ export function LoadingState({ text = "Loading…" }) {
327
+ return (_jsx("p", { role: "status", style: { ...INK, color: "var(--color-text-secondary, #6b7280)" }, children: text }));
328
+ }
329
+ export function EmptyState({ title, hint }) {
330
+ return (_jsxs("div", { style: { ...INK, color: "var(--color-text-secondary, #6b7280)" }, children: [_jsx("p", { style: { margin: "4px 0" }, children: title }), hint && _jsx("p", { style: { margin: "0 0 4px", fontSize: 12 }, children: hint })] }));
331
+ }
332
+ export function ErrorState({ message, errorCode, onRetry, }) {
333
+ return (_jsxs("div", { role: "alert", style: {
334
+ ...INK,
335
+ border: "1px solid var(--border, #e5e7eb)",
336
+ borderRadius: "var(--radius, 6px)",
337
+ padding: "8px 10px",
338
+ }, children: [_jsx("p", { style: { margin: "0 0 4px" }, children: message }), errorCode && (_jsxs("p", { style: {
339
+ margin: "0 0 4px",
340
+ fontSize: 12,
341
+ color: "var(--color-text-secondary, #6b7280)",
342
+ }, children: ["Code: ", errorCode] })), onRetry && (_jsx("button", { type: "button", onClick: onRetry, style: {
343
+ cursor: "pointer",
344
+ border: "1px solid var(--border, #e5e7eb)",
345
+ borderRadius: "var(--radius, 6px)",
346
+ background: "transparent",
347
+ color: "var(--fg, #0a0a0a)",
348
+ padding: "2px 10px",
349
+ font: "inherit",
350
+ }, children: "Retry" }))] }));
351
+ }
352
+ /**
353
+ * Honest cap notice: the server answered, but not wholly (`query_sql` 500-row
354
+ * ceiling, `query_sdk` oversized return). Rendered data is partial by
355
+ * construction — narrow the query instead of treating it as complete.
356
+ */
357
+ export function TruncatedNotice({ shown, total, }) {
358
+ return (_jsxs("p", { style: {
359
+ ...INK,
360
+ color: "var(--color-text-secondary, #6b7280)",
361
+ fontSize: 12,
362
+ }, children: ["Showing ", shown, total != null ? ` of ${total}` : "", " rows \u2014 refine filters to see the rest."] }));
363
+ }
364
+ /** Format large counts compactly (1.2K, 3.4M). Plain numbers pass through. */
365
+ export function formatCompact(value) {
366
+ if (!Number.isFinite(value))
367
+ return String(value);
368
+ const abs = Math.abs(value);
369
+ if (abs >= 1_000_000)
370
+ return `${(value / 1_000_000).toFixed(1)}M`;
371
+ if (abs >= 1_000)
372
+ return `${(value / 1_000).toFixed(1)}K`;
373
+ return String(value);
374
+ }
375
+ export * from "./native.js";
376
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `@lobu/views` — authoring runtime for Lobu views.
3
+ *
4
+ * A view is an ordinary React module rendered in the sandboxed MCP Apps
5
+ * frame. The module declares itself with `defineView` and mounts once with
6
+ * `mountView`; hooks bridge params, scope, reads and actions to the host.
7
+ */
8
+ export type { AttributeFilter, CollectionSelection, } from "@lobu/core/contracts/tools/collection-selection";
9
+ export { ViewBridge } from "./bridge.js";
10
+ export type { BridgeOptions, HostContext, ToolResult, ViewHandoff, } from "./bridge.js";
11
+ export { coerceParams, defaultsFor, defineView, escapeLiteral, mintInteractionId, mountView, resolveViewHref, Provider, sql, tool, useAction, useHost, useParams, useQuery, useScope, } from "./api.js";
12
+ export type { ActionResult, Attachment, Container, DisplayMode, MountOptions, ParamDef, Params, ParamValue, QueryOptions, QueryState, Scope, SqlQuery, ToolQuery, ViewDefinition, } from "./api.js";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { ViewBridge } from "./bridge.js";
2
+ export { coerceParams, defaultsFor, defineView, escapeLiteral, mintInteractionId, mountView, resolveViewHref, Provider, sql, tool, useAction, useHost, useParams, useQuery, useScope, } from "./api.js";
3
+ //# sourceMappingURL=index.js.map