asta-ui 0.9.4 → 0.9.6

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 (130) hide show
  1. package/css/asta.css +2 -2
  2. package/css/asta.js +1461 -1
  3. package/css/components.css +1900 -138
  4. package/css/runtime/agent.css +136 -0
  5. package/css/runtime/agent.js +173 -0
  6. package/css/runtime/assist.css +79 -0
  7. package/css/runtime/assist.js +799 -0
  8. package/css/runtime/controls.css +48 -0
  9. package/css/runtime/controls.js +482 -0
  10. package/css/src/agent.css +484 -0
  11. package/css/src/assist.css +598 -0
  12. package/css/src/controls.css +424 -0
  13. package/css/tokens.css +16 -0
  14. package/dist/agent-plan.d.ts +2 -0
  15. package/dist/agent-plan.js +11 -0
  16. package/dist/agent-team.d.ts +2 -0
  17. package/dist/agent-team.js +7 -0
  18. package/dist/api-keys.d.ts +2 -0
  19. package/dist/api-keys.js +10 -0
  20. package/dist/autonomy-dial.d.ts +2 -0
  21. package/dist/autonomy-dial.js +7 -0
  22. package/dist/base/agent-plan.d.ts +2 -0
  23. package/dist/base/agent-plan.js +11 -0
  24. package/dist/base/agent-team.d.ts +2 -0
  25. package/dist/base/agent-team.js +7 -0
  26. package/dist/base/api-keys.d.ts +2 -0
  27. package/dist/base/api-keys.js +10 -0
  28. package/dist/base/autonomy-dial.d.ts +2 -0
  29. package/dist/base/autonomy-dial.js +7 -0
  30. package/dist/base/change-ledger.d.ts +2 -0
  31. package/dist/base/change-ledger.js +7 -0
  32. package/dist/base/citations.d.ts +2 -0
  33. package/dist/base/citations.js +9 -0
  34. package/dist/base/context-meter.d.ts +2 -0
  35. package/dist/base/context-meter.js +14 -0
  36. package/dist/base/fallback-chain.d.ts +2 -0
  37. package/dist/base/fallback-chain.js +7 -0
  38. package/dist/base/model-picker.d.ts +2 -0
  39. package/dist/base/model-picker.js +9 -0
  40. package/dist/base/prompt-composer.d.ts +2 -0
  41. package/dist/base/prompt-composer.js +9 -0
  42. package/dist/base/scrub-input.d.ts +2 -0
  43. package/dist/base/scrub-input.js +13 -0
  44. package/dist/base/thinking.d.ts +2 -0
  45. package/dist/base/thinking.js +11 -0
  46. package/dist/base/tool-approval.d.ts +2 -0
  47. package/dist/base/tool-approval.js +9 -0
  48. package/dist/base/trace-waterfall.d.ts +2 -0
  49. package/dist/base/trace-waterfall.js +9 -0
  50. package/dist/base.js +202 -134
  51. package/dist/change-ledger.d.ts +2 -0
  52. package/dist/change-ledger.js +7 -0
  53. package/dist/chunk-24O5V2PQ.js +253 -0
  54. package/dist/chunk-44DNL43W.js +490 -0
  55. package/dist/chunk-45IXJ7W7.js +245 -0
  56. package/dist/chunk-ANL6VX4X.js +326 -0
  57. package/dist/chunk-DNROUJ62.js +432 -0
  58. package/dist/chunk-F4CWSZXK.js +226 -0
  59. package/dist/chunk-GBOJUMMY.js +163 -0
  60. package/dist/chunk-H4NFBYKY.js +275 -0
  61. package/dist/chunk-KFPGQ5RT.js +321 -0
  62. package/dist/chunk-OIIMYSVT.js +342 -0
  63. package/dist/chunk-TL32C2SQ.js +221 -0
  64. package/dist/chunk-UBTYMAKF.js +240 -0
  65. package/dist/chunk-W6YVDJHX.js +235 -0
  66. package/dist/chunk-XYQI4ZYV.js +314 -0
  67. package/dist/citations.d.ts +2 -0
  68. package/dist/citations.js +9 -0
  69. package/dist/context-meter.d.ts +2 -0
  70. package/dist/context-meter.js +14 -0
  71. package/dist/fallback-chain.d.ts +2 -0
  72. package/dist/fallback-chain.js +7 -0
  73. package/dist/index.js +202 -134
  74. package/dist/model-picker.d.ts +2 -0
  75. package/dist/model-picker.js +9 -0
  76. package/dist/prompt-composer.d.ts +2 -0
  77. package/dist/prompt-composer.js +9 -0
  78. package/dist/scrub-input.d.ts +2 -0
  79. package/dist/scrub-input.js +13 -0
  80. package/dist/thinking.d.ts +2 -0
  81. package/dist/thinking.js +11 -0
  82. package/dist/tool-approval.d.ts +2 -0
  83. package/dist/tool-approval.js +9 -0
  84. package/dist/trace-waterfall.d.ts +2 -0
  85. package/dist/trace-waterfall.js +9 -0
  86. package/dist/types/components/kit/agent-plan.d.ts +34 -0
  87. package/dist/types/components/kit/api-keys.d.ts +62 -0
  88. package/dist/types/components/kit/citations.d.ts +34 -0
  89. package/dist/types/components/kit/context-meter.d.ts +38 -0
  90. package/dist/types/components/kit/model-picker.d.ts +46 -0
  91. package/dist/types/components/kit/prompt-composer.d.ts +61 -0
  92. package/dist/types/components/kit/scrub-input.d.ts +44 -0
  93. package/dist/types/components/kit/thinking.d.ts +28 -0
  94. package/dist/types/components/kit/tool-approval.d.ts +43 -0
  95. package/dist/types/components/kit/trace-waterfall.d.ts +44 -0
  96. package/dist/types/components/lab/blocks/AgentTeam.d.ts +2 -0
  97. package/dist/types/components/lab/blocks/AutonomyDial.d.ts +2 -0
  98. package/dist/types/components/lab/blocks/ChangeLedger.d.ts +2 -0
  99. package/dist/types/components/lab/blocks/FallbackChain.d.ts +2 -0
  100. package/dist/types/packages/asta-ui/src/agent-plan.d.ts +2 -0
  101. package/dist/types/packages/asta-ui/src/agent-team.d.ts +2 -0
  102. package/dist/types/packages/asta-ui/src/api-keys.d.ts +2 -0
  103. package/dist/types/packages/asta-ui/src/autonomy-dial.d.ts +2 -0
  104. package/dist/types/packages/asta-ui/src/base/agent-plan.d.ts +2 -0
  105. package/dist/types/packages/asta-ui/src/base/agent-team.d.ts +2 -0
  106. package/dist/types/packages/asta-ui/src/base/api-keys.d.ts +2 -0
  107. package/dist/types/packages/asta-ui/src/base/autonomy-dial.d.ts +2 -0
  108. package/dist/types/packages/asta-ui/src/base/change-ledger.d.ts +2 -0
  109. package/dist/types/packages/asta-ui/src/base/citations.d.ts +2 -0
  110. package/dist/types/packages/asta-ui/src/base/context-meter.d.ts +2 -0
  111. package/dist/types/packages/asta-ui/src/base/fallback-chain.d.ts +2 -0
  112. package/dist/types/packages/asta-ui/src/base/model-picker.d.ts +2 -0
  113. package/dist/types/packages/asta-ui/src/base/prompt-composer.d.ts +2 -0
  114. package/dist/types/packages/asta-ui/src/base/scrub-input.d.ts +2 -0
  115. package/dist/types/packages/asta-ui/src/base/thinking.d.ts +2 -0
  116. package/dist/types/packages/asta-ui/src/base/tool-approval.d.ts +2 -0
  117. package/dist/types/packages/asta-ui/src/base/trace-waterfall.d.ts +2 -0
  118. package/dist/types/packages/asta-ui/src/base.d.ts +25 -1
  119. package/dist/types/packages/asta-ui/src/change-ledger.d.ts +2 -0
  120. package/dist/types/packages/asta-ui/src/citations.d.ts +2 -0
  121. package/dist/types/packages/asta-ui/src/context-meter.d.ts +2 -0
  122. package/dist/types/packages/asta-ui/src/fallback-chain.d.ts +2 -0
  123. package/dist/types/packages/asta-ui/src/index.d.ts +25 -1
  124. package/dist/types/packages/asta-ui/src/model-picker.d.ts +2 -0
  125. package/dist/types/packages/asta-ui/src/prompt-composer.d.ts +2 -0
  126. package/dist/types/packages/asta-ui/src/scrub-input.d.ts +2 -0
  127. package/dist/types/packages/asta-ui/src/thinking.d.ts +2 -0
  128. package/dist/types/packages/asta-ui/src/tool-approval.d.ts +2 -0
  129. package/dist/types/packages/asta-ui/src/trace-waterfall.d.ts +2 -0
  130. package/package.json +1 -1
@@ -0,0 +1,245 @@
1
+ "use client";
2
+
3
+ // components/lab/blocks/ChangeLedger.tsx
4
+ import { useEffect, useRef, useState } from "react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ var EASE = "cubic-bezier(.16,1,.3,1)";
7
+ var RING = "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--ink)_10%,transparent)]";
8
+ var ENTRIES = [
9
+ { id: 1, kind: "file", verb: "Edited", target: "billing/plan.ts", meta: "+14 \u22123", time: "14:02", deps: [] },
10
+ { id: 2, kind: "file", verb: "Edited", target: "billing/seats.ts", meta: "+41", time: "14:03", deps: [] },
11
+ { id: 3, kind: "db", verb: "Added column", target: "accounts.seats", meta: "Migration 0042", time: "14:05", deps: [] },
12
+ { id: 4, kind: "db", verb: "Updated 38 rows in", target: "accounts", meta: "seats = 5", time: "14:06", deps: [3] },
13
+ { id: 5, kind: "mail", verb: "Drafted email", target: "Your plan now has 5 seats", meta: "To 38 admins", time: "14:07", deps: [4] }
14
+ ];
15
+ var ICONS = {
16
+ file: "M4 1.8h5.2L12.5 5v9.2H4zM9 1.8V5.2h3.4M6.2 8.5h4M6.2 11h2.6",
17
+ db: "M3 3.8c0-1 2.2-1.8 5-1.8s5 .8 5 1.8v8.4c0 1-2.2 1.8-5 1.8s-5-.8-5-1.8zM3 3.8c0 1 2.2 1.8 5 1.8s5-.8 5-1.8M3 8c0 1 2.2 1.8 5 1.8s5-.8 5-1.8",
18
+ mail: "M2 4h12v8.5H2zM2.4 4.4 8 9l5.6-4.6"
19
+ };
20
+ var INIT = { landed: 0, undone: [], hot: null };
21
+ var STEPS = [
22
+ ...ENTRIES.map((_, i) => [i ? 950 : 700, (s) => ({ ...s, landed: i + 1 })]),
23
+ [1300, (s) => ({ ...s, hot: 3 })],
24
+ [900, (s) => ({ ...s, undone: s.undone.includes(3) ? s.undone : [...s.undone, 3] })],
25
+ [3600, (s) => ({ ...s, hot: null })]
26
+ ];
27
+ function blockedBy(e, undone) {
28
+ for (const d of e.deps) {
29
+ if (undone.includes(d)) return d;
30
+ const up = blockedBy(ENTRIES[d - 1], undone);
31
+ if (up) return up;
32
+ }
33
+ return null;
34
+ }
35
+ function ChangeLedger() {
36
+ const [s, setS] = useState(INIT);
37
+ const [fade, setFade] = useState(false);
38
+ const [hover, setHover] = useState(false);
39
+ const [held, setHeld] = useState(false);
40
+ const [focusIn, setFocusIn] = useState(false);
41
+ const [visible, setVisible] = useState(true);
42
+ const root = useRef(null);
43
+ const btns = useRef([]);
44
+ const idle = useRef(null);
45
+ const k = useRef(0);
46
+ const paused = hover || held || focusIn || !visible;
47
+ useEffect(() => {
48
+ const el = root.current;
49
+ if (!el) return;
50
+ let seen = true;
51
+ const sync = () => setVisible(seen && !document.hidden);
52
+ const io = new IntersectionObserver(([e]) => {
53
+ seen = e.isIntersecting;
54
+ sync();
55
+ });
56
+ io.observe(el);
57
+ document.addEventListener("visibilitychange", sync);
58
+ return () => {
59
+ io.disconnect();
60
+ document.removeEventListener("visibilitychange", sync);
61
+ };
62
+ }, []);
63
+ useEffect(() => () => void (idle.current && clearTimeout(idle.current)), []);
64
+ useEffect(() => {
65
+ if (paused) return;
66
+ const t = [];
67
+ let alive = true;
68
+ const later = (ms, f) => t.push(setTimeout(() => alive && f(), ms));
69
+ const step = () => {
70
+ if (k.current >= STEPS.length) {
71
+ setFade(true);
72
+ later(480, () => {
73
+ k.current = 0;
74
+ setS(INIT);
75
+ });
76
+ later(600, () => setFade(false));
77
+ later(700, step);
78
+ return;
79
+ }
80
+ const [wait, f] = STEPS[k.current];
81
+ later(wait, () => {
82
+ k.current++;
83
+ setS(f);
84
+ step();
85
+ });
86
+ };
87
+ step();
88
+ return () => {
89
+ alive = false;
90
+ t.forEach(clearTimeout);
91
+ };
92
+ }, [paused]);
93
+ const hold = () => {
94
+ setHeld(true);
95
+ if (idle.current) clearTimeout(idle.current);
96
+ idle.current = setTimeout(() => setHeld(false), 9e3);
97
+ };
98
+ const setHot = (id) => setS((v) => v.hot === id ? v : { ...v, hot: id });
99
+ const toggle = (id) => {
100
+ hold();
101
+ setS((v) => ({ ...v, hot: id, undone: v.undone.includes(id) ? v.undone.filter((u) => u !== id) : [...v.undone, id] }));
102
+ };
103
+ const shown = ENTRIES.slice(0, s.landed).reverse();
104
+ const onKey = (e) => {
105
+ const i = btns.current.findIndex((b) => b === document.activeElement);
106
+ const d = e.key === "ArrowDown" ? 1 : e.key === "ArrowUp" ? -1 : 0;
107
+ if (!d || i < 0) return;
108
+ e.preventDefault();
109
+ hold();
110
+ btns.current[(i + d + shown.length) % shown.length]?.focus();
111
+ };
112
+ const undoneCount = s.undone.filter((u) => u <= s.landed).length;
113
+ const blockedCount = shown.filter((e) => !s.undone.includes(e.id) && blockedBy(e, s.undone)).length;
114
+ return /* @__PURE__ */ jsxs(
115
+ "div",
116
+ {
117
+ ref: root,
118
+ onPointerEnter: (e) => e.pointerType === "mouse" && setHover(true),
119
+ onPointerLeave: (e) => {
120
+ if (e.pointerType !== "mouse") return;
121
+ setHover(false);
122
+ setHot(null);
123
+ },
124
+ onKeyDown: onKey,
125
+ onFocus: () => setFocusIn(true),
126
+ onBlur: (e) => !e.currentTarget.contains(e.relatedTarget) && setFocusIn(false),
127
+ className: "flex h-full w-full items-center justify-center px-5 pb-5 pt-11",
128
+ style: { containerType: "size" },
129
+ children: [
130
+ /* @__PURE__ */ jsx("style", { href: "asta-changeledger", precedence: "asta", children: `
131
+ @keyframes lab-cl-land { from { transform: translateY(-14px) scale(.97); opacity: 0 } to { transform: none; opacity: 1 } }
132
+ @keyframes lab-cl-pop { from { transform: scale(.9); opacity: 0 } to { transform: none; opacity: 1 } }
133
+ .lab-cl-land { animation: lab-cl-land .55s ${EASE} both }
134
+ .lab-cl-pop { animation: lab-cl-pop .35s ${EASE} both }
135
+ .lab-cl-meta { display: none }
136
+ @container (min-height: 300px) { .lab-cl-meta { display: block } }
137
+ @container (max-height: 270px) { .lab-cl-sub { display: none } }
138
+ @media (prefers-reduced-motion: reduce) { .lab-cl-land, .lab-cl-pop { animation: none } .lab-cl-move { transition: none !important } }
139
+ ` }),
140
+ /* @__PURE__ */ jsxs(
141
+ "div",
142
+ {
143
+ className: `flex w-full max-w-[480px] flex-col gap-[max(6px,2.2cqh)] rounded-[14px] bg-paper p-[clamp(10px,3.4cqmin,16px)] ${RING} shadow-[0_18px_40px_-28px_rgb(0_0_0/0.35)]`,
144
+ style: { opacity: fade ? 0 : 1, transition: `opacity .45s ${EASE}`, "--row": "clamp(30px, 11.5cqh, 48px)" },
145
+ children: [
146
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 px-1", children: [
147
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
148
+ /* @__PURE__ */ jsx("p", { className: "text-[13.5px] font-medium tracking-[-0.01em] text-ink", children: "Agent changes" }),
149
+ /* @__PURE__ */ jsx("p", { className: "lab-cl-sub truncate text-[11.5px] text-mute", children: "Astabyte Ops \xB7 seats rollout \xB7 today" })
150
+ ] }),
151
+ /* @__PURE__ */ jsx("span", { className: "shrink-0 rounded-md bg-paper-2 px-2 py-1 text-[11px] tabular-nums text-ink-2", "aria-live": "polite", children: undoneCount ? `${undoneCount} undone \xB7 ${blockedCount} blocked` : `${s.landed} ${s.landed === 1 ? "change" : "changes"}` })
152
+ ] }),
153
+ /* @__PURE__ */ jsxs("ol", { className: "relative", style: { height: `calc(${ENTRIES.length} * var(--row))` }, "aria-label": "Changes, newest first", children: [
154
+ !s.landed && /* @__PURE__ */ jsx("li", { className: "absolute inset-0 grid place-items-center rounded-[11px] bg-paper-2 text-[12px] text-mute", children: "Changes the agent makes land here" }),
155
+ shown.map((e, i) => {
156
+ const undone = s.undone.includes(e.id);
157
+ const by = undone ? null : blockedBy(e, s.undone);
158
+ const hot = s.hot === e.id;
159
+ return /* @__PURE__ */ jsx(
160
+ "li",
161
+ {
162
+ className: "lab-cl-move absolute inset-x-0 top-0 h-[var(--row)]",
163
+ style: { transform: `translateY(calc(${i} * var(--row)))`, transition: `transform .6s ${EASE}` },
164
+ onPointerEnter: (ev) => ev.pointerType === "mouse" && setHot(e.id),
165
+ onPointerDown: (ev) => {
166
+ if (ev.pointerType === "mouse") return;
167
+ hold();
168
+ setHot(e.id);
169
+ },
170
+ children: /* @__PURE__ */ jsxs("div", { className: `lab-cl-land relative flex h-full items-center gap-2.5 rounded-[9px] px-2 ${hot ? "bg-paper-2" : ""}`, style: { transition: `background-color .25s ${EASE}` }, children: [
171
+ /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-1 items-center gap-2.5", style: { opacity: by ? 0.42 : 1, transition: `opacity .45s ${EASE}` }, children: [
172
+ /* @__PURE__ */ jsx("span", { className: `grid h-[clamp(20px,7cqh,26px)] w-[clamp(20px,7cqh,26px)] shrink-0 place-items-center rounded-[7px] ${undone ? `bg-paper text-mute ${RING}` : "bg-paper-2 text-ink-2"}`, children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", className: "h-[60%] w-[60%]", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: ICONS[e.kind] }) }) }),
173
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1 leading-tight", children: [
174
+ /* @__PURE__ */ jsxs("span", { className: "relative block w-fit max-w-full truncate text-[12.5px]", children: [
175
+ /* @__PURE__ */ jsxs("span", { className: undone ? "text-mute" : "text-ink", children: [
176
+ e.verb,
177
+ " "
178
+ ] }),
179
+ /* @__PURE__ */ jsx("span", { className: `${e.kind === "mail" ? "" : "font-mono text-[11.5px]"} ${undone ? "text-mute" : "text-ink-2"}`, children: e.kind === "mail" ? `\u201C${e.target}\u201D` : e.target }),
180
+ /* @__PURE__ */ jsx(
181
+ "span",
182
+ {
183
+ "aria-hidden": true,
184
+ className: "lab-cl-move absolute inset-x-0 top-1/2 h-px origin-left bg-ink",
185
+ style: { transform: `scaleX(${undone ? 1 : 0})`, transition: `transform .45s ${EASE}` }
186
+ }
187
+ )
188
+ ] }),
189
+ /* @__PURE__ */ jsxs("span", { className: "lab-cl-meta truncate text-[10.5px] tabular-nums text-mute", children: [
190
+ e.meta,
191
+ " \xB7 ",
192
+ e.time
193
+ ] })
194
+ ] })
195
+ ] }),
196
+ by && /* @__PURE__ */ jsxs("span", { className: "lab-cl-pop flex shrink-0 items-center gap-1 rounded-md bg-paper-2 px-1.5 py-0.5 text-[10.5px] text-ink-2", children: [
197
+ /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", className: "h-2.5 w-2.5", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M6.5 9.5 9.5 6.5M7 4.5l1.2-1.2a2.6 2.6 0 0 1 3.7 3.7L10.7 8.2M9 11.5l-1.2 1.2a2.6 2.6 0 0 1-3.7-3.7l1.2-1.2" }) }),
198
+ "Depends on #",
199
+ by
200
+ ] }),
201
+ /* @__PURE__ */ jsxs("span", { className: "relative grid shrink-0 place-items-end", children: [
202
+ /* @__PURE__ */ jsxs(
203
+ "span",
204
+ {
205
+ className: `col-start-1 row-start-1 flex items-center gap-1.5 font-mono text-[10.5px] tabular-nums ${undone ? "text-ink" : i === 0 && !by ? "text-brand" : "text-mute"}`,
206
+ style: { opacity: hot ? 0 : 1, transition: `opacity .2s ${EASE}` },
207
+ children: [
208
+ i === 0 && !undone && !by && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "h-1.5 w-1.5 rounded-full bg-brand" }),
209
+ undone ? "Undone" : `#${e.id}`
210
+ ]
211
+ }
212
+ ),
213
+ /* @__PURE__ */ jsx(
214
+ "button",
215
+ {
216
+ ref: (el) => {
217
+ btns.current[i] = el;
218
+ },
219
+ type: "button",
220
+ onClick: () => toggle(e.id),
221
+ onFocus: () => setHot(e.id),
222
+ "aria-label": `${undone ? "Restore" : "Undo"} change #${e.id}: ${e.verb} ${e.target}${by ? `. Depends on #${by}, which is undone` : ""}`,
223
+ className: `col-start-1 row-start-1 rounded-[7px] px-2 py-1 text-[11px] font-medium outline-none focus-visible:ring-2 focus-visible:ring-brand/60 active:scale-[.96] ${undone ? `bg-paper text-ink ${RING}` : "bg-ink text-paper"} ${hot ? "" : "pointer-events-none"}`,
224
+ style: { opacity: hot ? 1 : 0, transform: hot ? "none" : "scale(.94)", transition: `opacity .2s ${EASE}, transform .2s ${EASE}` },
225
+ children: undone ? "Restore" : "Undo"
226
+ }
227
+ )
228
+ ] })
229
+ ] })
230
+ },
231
+ e.id
232
+ );
233
+ })
234
+ ] })
235
+ ]
236
+ }
237
+ )
238
+ ]
239
+ }
240
+ );
241
+ }
242
+
243
+ export {
244
+ ChangeLedger
245
+ };
@@ -0,0 +1,326 @@
1
+ "use client";
2
+
3
+ // components/kit/model-picker.tsx
4
+ import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ var cx = (...c) => c.filter(Boolean).join(" ");
7
+ var KEYFRAMES = `@keyframes asta-mp-in { from { opacity: 0; transform: translateY(var(--asta-mp-y, -4px)) scale(.97) } }
8
+ @media (prefers-reduced-motion: reduce) { .asta-mp, .asta-mp * { animation: none !important; transition-duration: 0s !important } }`;
9
+ var ROW = 56;
10
+ var BAR = 22;
11
+ var EASE = "cubic-bezier(.16,1,.3,1)";
12
+ var icon = { viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true };
13
+ var SPEED = "M9 1.5 3.5 9H8l-1 5.5L12.5 7H8z";
14
+ var SMART = "M8 2.5c.3 2.2 1.3 3.2 3.5 3.5-2.2.3-3.2 1.3-3.5 3.5-.3-2.2-1.3-3.2-3.5-3.5 2.2-.3 3.2-1.3 3.5-3.5ZM12.5 10.5v3M11 12h3";
15
+ function Dots({ n, label }) {
16
+ const v = Math.max(0, Math.min(5, Math.round(n)));
17
+ return /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-[3px]", children: [
18
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `${label} ${v} of 5.` }),
19
+ [0, 1, 2, 3, 4].map((i) => /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: cx("h-[5px] w-[5px] rounded-full", i < v ? "bg-ink" : "bg-[color-mix(in_srgb,var(--ink)_14%,transparent)]") }, i))
20
+ ] });
21
+ }
22
+ function ModelPicker({
23
+ models,
24
+ value,
25
+ defaultValue,
26
+ onChange,
27
+ label = "Model",
28
+ searchable = true,
29
+ variant = "field",
30
+ side = "bottom",
31
+ align = "start",
32
+ name,
33
+ disabled,
34
+ className
35
+ }) {
36
+ const [inner, setInner] = useState(defaultValue ?? models.find((m) => !m.disabled)?.value ?? "");
37
+ const current = value ?? inner;
38
+ const [open, setOpen] = useState(false);
39
+ const [query, setQuery] = useState("");
40
+ const [active, setActive] = useState(-1);
41
+ const root = useRef(null);
42
+ const trigger = useRef(null);
43
+ const search = useRef(null);
44
+ const list = useRef(null);
45
+ const hl = useRef(null);
46
+ const bar = useRef(null);
47
+ const pop = useRef(null);
48
+ const placed = useRef(false);
49
+ const typed = useRef({ text: "", at: 0 });
50
+ const uid = useId();
51
+ const selected = models.find((m) => m.value === current);
52
+ const q = query.trim().toLowerCase();
53
+ const shown = useMemo(
54
+ () => q ? models.filter((m) => `${m.label} ${m.group ?? ""} ${m.hint ?? ""} ${m.tag ?? ""}`.toLowerCase().includes(q)) : models,
55
+ [models, q]
56
+ );
57
+ const groups = useMemo(() => {
58
+ const out = [];
59
+ shown.forEach((m, i) => {
60
+ const g = m.group ?? "";
61
+ let bucket = out.find((x) => x.name === g);
62
+ if (!bucket) out.push(bucket = { name: g, items: [] });
63
+ bucket.items.push({ m, i });
64
+ });
65
+ return out;
66
+ }, [shown]);
67
+ const order = useMemo(() => groups.flatMap((g) => g.items.map((x) => x.i)), [groups]);
68
+ const usable = order.filter((i) => !shown[i].disabled);
69
+ const act = usable.includes(active) ? active : usable[0] ?? -1;
70
+ const step = (dir) => {
71
+ if (!usable.length) return;
72
+ const k = usable.indexOf(act);
73
+ setActive(usable[(k + dir + usable.length) % usable.length]);
74
+ };
75
+ const show = (seed = "") => {
76
+ if (disabled) return;
77
+ placed.current = false;
78
+ setQuery(seed);
79
+ setActive(seed ? -1 : models.findIndex((m) => m.value === current));
80
+ setOpen(true);
81
+ };
82
+ const hide = (refocus = true) => {
83
+ setOpen(false);
84
+ setQuery("");
85
+ if (refocus) trigger.current?.focus();
86
+ };
87
+ const pick = (m) => {
88
+ if (!m || m.disabled) return;
89
+ if (value === void 0) setInner(m.value);
90
+ onChange?.(m.value);
91
+ hide();
92
+ };
93
+ useEffect(() => {
94
+ if (open) (searchable ? search.current : list.current)?.focus({ preventScroll: true });
95
+ }, [open, searchable]);
96
+ useLayoutEffect(() => {
97
+ const el = pop.current;
98
+ if (!open || !el) return;
99
+ el.style.translate = "";
100
+ const r = el.getBoundingClientRect();
101
+ const dx = r.left < 16 ? 16 - r.left : r.right > window.innerWidth - 16 ? window.innerWidth - 16 - r.right : 0;
102
+ if (dx) el.style.translate = `${Math.round(dx)}px 0`;
103
+ }, [open]);
104
+ useLayoutEffect(() => {
105
+ const box = list.current;
106
+ if (!open || !box || !hl.current || !bar.current) return;
107
+ const row = (i) => i < 0 ? null : box.querySelector(`[data-i="${i}"]`);
108
+ const a = row(act);
109
+ const s = row(shown.findIndex((m) => m.value === current));
110
+ const first = !placed.current;
111
+ for (const el of [hl.current, bar.current]) el.style.transition = first ? "none" : `transform ${el === bar.current ? 300 : 200}ms ${EASE}, opacity 200ms ${EASE}`;
112
+ hl.current.style.opacity = a ? "1" : "0";
113
+ if (a) hl.current.style.transform = `translateY(${a.offsetTop}px)`;
114
+ bar.current.style.opacity = s ? "1" : "0";
115
+ if (s) bar.current.style.transform = `translateY(${s.offsetTop + (ROW - BAR) / 2}px)`;
116
+ placed.current = true;
117
+ a?.scrollIntoView({ block: "nearest" });
118
+ }, [open, act, shown, current]);
119
+ useEffect(() => {
120
+ if (!open) return;
121
+ const onDown = (e) => {
122
+ if (!root.current?.contains(e.target)) {
123
+ setOpen(false);
124
+ setQuery("");
125
+ }
126
+ };
127
+ document.addEventListener("pointerdown", onDown);
128
+ return () => document.removeEventListener("pointerdown", onDown);
129
+ }, [open]);
130
+ const onListKey = (e) => {
131
+ if (e.key === "ArrowDown") step(1);
132
+ else if (e.key === "ArrowUp") step(-1);
133
+ else if (e.key === "Home" && !searchable) setActive(usable[0] ?? -1);
134
+ else if (e.key === "End" && !searchable) setActive(usable[usable.length - 1] ?? -1);
135
+ else if (e.key === "Enter") pick(shown[act]);
136
+ else if (e.key === "Escape") hide();
137
+ else if (e.key === "Tab") return hide(false);
138
+ else if (!searchable && e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey) {
139
+ const now = Date.now();
140
+ typed.current = { text: (now - typed.current.at < 700 ? typed.current.text : "") + e.key.toLowerCase(), at: now };
141
+ const t = typed.current.text;
142
+ const hit = usable.find((i) => shown[i].label.toLowerCase().startsWith(t)) ?? usable.find((i) => shown[i].label.toLowerCase().includes(t));
143
+ if (hit !== void 0) setActive(hit);
144
+ } else return;
145
+ e.preventDefault();
146
+ };
147
+ const listId = `${uid}-list`;
148
+ const activeId = open && act >= 0 ? `${uid}-o-${act}` : void 0;
149
+ const chip = variant === "chip";
150
+ return /* @__PURE__ */ jsxs("div", { ref: root, className: cx("asta-mp relative", chip ? "inline-flex" : "w-full", className), children: [
151
+ /* @__PURE__ */ jsx("style", { href: "asta-model-picker", precedence: "asta", children: KEYFRAMES }),
152
+ /* @__PURE__ */ jsxs(
153
+ "button",
154
+ {
155
+ ref: trigger,
156
+ type: "button",
157
+ disabled,
158
+ "aria-haspopup": "listbox",
159
+ "aria-expanded": open,
160
+ "aria-controls": open ? listId : void 0,
161
+ "aria-label": `${label}: ${selected?.label ?? "none"}`,
162
+ onClick: () => open ? hide() : show(),
163
+ onKeyDown: (e) => {
164
+ if (open) return;
165
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
166
+ e.preventDefault();
167
+ show();
168
+ } else if (searchable && e.key.length === 1 && e.key !== " " && !e.metaKey && !e.ctrlKey && !e.altKey) {
169
+ e.preventDefault();
170
+ show(e.key);
171
+ }
172
+ },
173
+ className: cx(
174
+ "flex items-center gap-2 text-left outline-none transition-[background-color,box-shadow,color] duration-200",
175
+ "focus-visible:ring-2 focus-visible:ring-brand/50 disabled:cursor-not-allowed disabled:opacity-45",
176
+ chip ? "h-8 max-w-[220px] rounded-md px-2 text-[13px] text-ink-2 hover:bg-paper-2 hover:text-ink aria-expanded:bg-paper-2 aria-expanded:text-ink" : "h-10 w-full rounded-lg bg-paper px-3 text-[14px] text-ink shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--ink)_14%,transparent)] hover:shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--ink)_24%,transparent)] aria-expanded:shadow-[inset_0_0_0_1px_var(--brand),0_0_0_3px_color-mix(in_srgb,var(--brand)_18%,transparent)]"
177
+ ),
178
+ children: [
179
+ /* @__PURE__ */ jsx("svg", { ...icon, className: "h-3.5 w-3.5 shrink-0 text-brand", fill: "currentColor", stroke: "none", children: /* @__PURE__ */ jsx("path", { d: "M8 1.5c.4 2.9 1.6 4.1 4.5 4.5-2.9.4-4.1 1.6-4.5 4.5-.4-2.9-1.6-4.1-4.5-4.5C6.4 5.6 7.6 4.4 8 1.5Z" }) }),
180
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 truncate font-medium", children: selected?.label ?? "Choose a model" }),
181
+ selected?.tag && /* @__PURE__ */ jsx("span", { className: "shrink-0 rounded-[5px] bg-[color-mix(in_srgb,var(--ink)_7%,transparent)] px-1.5 py-px text-[11px] font-medium text-ink-2", children: selected.tag }),
182
+ /* @__PURE__ */ jsx("svg", { ...icon, className: cx("ml-auto h-3.5 w-3.5 shrink-0 text-mute transition-transform duration-300 ease-[cubic-bezier(.16,1,.3,1)]", open && "rotate-180"), children: /* @__PURE__ */ jsx("path", { d: side === "top" ? "m4 10 4-4 4 4" : "m4 6 4 4 4-4" }) })
183
+ ]
184
+ }
185
+ ),
186
+ name && /* @__PURE__ */ jsx("input", { type: "hidden", name, value: current }),
187
+ open && /* @__PURE__ */ jsxs(
188
+ "div",
189
+ {
190
+ ref: pop,
191
+ className: cx(
192
+ "absolute z-50 flex w-[372px] max-w-[calc(100vw-32px)] flex-col overflow-hidden rounded-xl bg-paper",
193
+ "shadow-[0_0_0_1px_color-mix(in_srgb,var(--ink)_10%,transparent),0_16px_40px_-12px_rgb(0_0_0/0.25),0_4px_10px_-6px_rgb(0_0_0/0.1)]",
194
+ "animate-[asta-mp-in_.18s_cubic-bezier(.16,1,.3,1)_both]",
195
+ side === "top" ? "bottom-full mb-1.5 origin-bottom [--asta-mp-y:4px]" : "top-full mt-1.5 origin-top",
196
+ align === "end" ? "right-0" : "left-0"
197
+ ),
198
+ children: [
199
+ searchable && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-3 pt-2.5 pb-1.5", children: [
200
+ /* @__PURE__ */ jsxs("svg", { ...icon, className: "h-4 w-4 shrink-0 text-mute", children: [
201
+ /* @__PURE__ */ jsx("circle", { cx: "7", cy: "7", r: "4.5" }),
202
+ /* @__PURE__ */ jsx("path", { d: "m10.5 10.5 3 3" })
203
+ ] }),
204
+ /* @__PURE__ */ jsx(
205
+ "input",
206
+ {
207
+ ref: search,
208
+ type: "search",
209
+ role: "combobox",
210
+ "aria-label": `Search ${label.toLowerCase()}s`,
211
+ "aria-expanded": true,
212
+ "aria-controls": listId,
213
+ "aria-autocomplete": "list",
214
+ "aria-activedescendant": activeId,
215
+ autoComplete: "off",
216
+ spellCheck: false,
217
+ enterKeyHint: "go",
218
+ placeholder: "Search models\u2026",
219
+ value: query,
220
+ onChange: (e) => setQuery(e.target.value),
221
+ onKeyDown: onListKey,
222
+ className: "h-8 min-w-0 flex-1 bg-transparent text-[16px] text-ink outline-none placeholder:text-mute sm:text-[13.5px] [&::-webkit-search-cancel-button]:hidden"
223
+ }
224
+ )
225
+ ] }),
226
+ /* @__PURE__ */ jsxs(
227
+ "div",
228
+ {
229
+ ref: list,
230
+ id: listId,
231
+ role: "listbox",
232
+ "aria-label": label,
233
+ tabIndex: searchable ? void 0 : -1,
234
+ "aria-activedescendant": searchable ? void 0 : activeId,
235
+ onKeyDown: searchable ? void 0 : onListKey,
236
+ onPointerDown: (e) => searchable && e.preventDefault(),
237
+ className: "relative max-h-[min(360px,60vh)] overflow-y-auto overscroll-contain p-1.5 outline-none [scrollbar-width:thin]",
238
+ children: [
239
+ /* @__PURE__ */ jsx("span", { ref: hl, "aria-hidden": true, className: "pointer-events-none absolute inset-x-1.5 top-0 rounded-lg bg-paper-2 opacity-0", style: { height: ROW } }),
240
+ /* @__PURE__ */ jsx("span", { ref: bar, "aria-hidden": true, className: "pointer-events-none absolute left-1.5 top-0 z-[1] w-[3px] rounded-full bg-brand opacity-0", style: { height: BAR } }),
241
+ groups.map((g) => /* @__PURE__ */ jsxs("div", { role: "group", "aria-labelledby": g.name ? `${uid}-g-${g.name}` : void 0, "aria-label": g.name ? void 0 : label, children: [
242
+ g.name && /* @__PURE__ */ jsx("p", { id: `${uid}-g-${g.name}`, className: "relative px-3.5 pt-2.5 pb-1 font-mono text-[10.5px] uppercase tracking-wider text-mute", children: g.name }),
243
+ g.items.map(({ m, i }) => {
244
+ const on = m.value === current;
245
+ return /* @__PURE__ */ jsxs(
246
+ "div",
247
+ {
248
+ id: `${uid}-o-${i}`,
249
+ "data-i": i,
250
+ role: "option",
251
+ "aria-selected": on,
252
+ "aria-disabled": m.disabled || void 0,
253
+ onPointerMove: () => !m.disabled && act !== i && setActive(i),
254
+ onClick: () => pick(m),
255
+ className: cx("relative flex select-none items-center gap-3 rounded-lg pl-3.5 pr-2.5", m.disabled ? "cursor-not-allowed" : "cursor-pointer"),
256
+ style: { height: ROW },
257
+ children: [
258
+ /* @__PURE__ */ jsxs("span", { className: cx("min-w-0 flex-1", m.disabled && "opacity-55"), children: [
259
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
260
+ /* @__PURE__ */ jsx("span", { className: cx("truncate text-[13.5px] font-medium", on ? "text-ink" : "text-ink-2"), children: m.label }),
261
+ m.isNew && /* @__PURE__ */ jsx("span", { className: "shrink-0 rounded-[5px] bg-brand px-1.5 text-[10px] font-semibold leading-[16px] text-white", children: "New" })
262
+ ] }),
263
+ /* @__PURE__ */ jsx("span", { className: "mt-0.5 block truncate text-[12px] text-mute", children: m.disabled ? m.disabledReason ?? "Not available" : m.hint })
264
+ ] }),
265
+ /* @__PURE__ */ jsxs("span", { className: cx("flex shrink-0 flex-col items-end gap-1.5", m.disabled && "opacity-55"), children: [
266
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", title: "Speed", children: [
267
+ /* @__PURE__ */ jsx("svg", { ...icon, className: "h-3 w-3 text-mute", children: /* @__PURE__ */ jsx("path", { d: SPEED }) }),
268
+ /* @__PURE__ */ jsx(Dots, { n: m.speed, label: "Speed" })
269
+ ] }),
270
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", title: "Intelligence", children: [
271
+ /* @__PURE__ */ jsx("svg", { ...icon, className: "h-3 w-3 text-mute", children: /* @__PURE__ */ jsx("path", { d: SMART }) }),
272
+ /* @__PURE__ */ jsx(Dots, { n: m.intelligence, label: "Intelligence" })
273
+ ] })
274
+ ] }),
275
+ /* @__PURE__ */ jsxs("span", { className: cx("w-9 shrink-0 text-right font-mono text-[11px] tabular-nums text-mute", m.disabled && "opacity-55"), title: "Context window", children: [
276
+ m.context && /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Context window " }),
277
+ m.context
278
+ ] }),
279
+ /* @__PURE__ */ jsx(
280
+ "svg",
281
+ {
282
+ ...icon,
283
+ strokeWidth: 2,
284
+ className: cx("h-3.5 w-3.5 shrink-0 text-brand transition-[opacity,transform] duration-200 ease-[cubic-bezier(.16,1,.3,1)]", on ? "scale-100 opacity-100" : "scale-75 opacity-0"),
285
+ children: /* @__PURE__ */ jsx("path", { d: "m3.5 8.5 3 3 6-7" })
286
+ }
287
+ )
288
+ ]
289
+ },
290
+ m.value
291
+ );
292
+ })
293
+ ] }, g.name || "_")),
294
+ shown.length === 0 && /* @__PURE__ */ jsxs("div", { role: "presentation", className: "flex flex-col items-center gap-1 px-3 py-8 text-center", children: [
295
+ /* @__PURE__ */ jsx("span", { className: "text-[13px] font-medium text-ink-2", children: "No models found" }),
296
+ /* @__PURE__ */ jsxs("span", { className: "text-[12px] text-mute", children: [
297
+ "Nothing matches \u201C",
298
+ query.trim(),
299
+ "\u201D. Try a family name."
300
+ ] })
301
+ ] })
302
+ ]
303
+ }
304
+ ),
305
+ /* @__PURE__ */ jsxs("div", { className: "hidden items-center gap-3 bg-paper-2 px-3.5 py-2 text-[11.5px] text-mute sm:flex", children: [
306
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
307
+ /* @__PURE__ */ jsx("svg", { ...icon, className: "h-3 w-3", children: /* @__PURE__ */ jsx("path", { d: SPEED }) }),
308
+ "Speed"
309
+ ] }),
310
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
311
+ /* @__PURE__ */ jsx("svg", { ...icon, className: "h-3 w-3", children: /* @__PURE__ */ jsx("path", { d: SMART }) }),
312
+ "Intelligence"
313
+ ] }),
314
+ /* @__PURE__ */ jsx("span", { className: "ml-auto", children: "\u2191\u2193 to move \xB7 Enter to pick" })
315
+ ] })
316
+ ]
317
+ }
318
+ )
319
+ ] });
320
+ }
321
+ var model_picker_default = ModelPicker;
322
+
323
+ export {
324
+ ModelPicker,
325
+ model_picker_default
326
+ };