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,240 @@
1
+ "use client";
2
+
3
+ // components/lab/blocks/AutonomyDial.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 STOPS = ["Ask me first", "Edits only", "Edits and email", "Everything but deploys", "Runs on its own"];
9
+ var MAX = STOPS.length - 1;
10
+ var SWEEP = [1, 2, 3, 4, 3, 2, 1, 0];
11
+ var ICONS = {
12
+ edit: "M4 1.8h5.2L12.5 5v9.2H4zM9 1.8V5.2h3.4M6.2 8.5h4M6.2 11h2.6",
13
+ email: "M2 4h12v8.5H2zM2.4 4.4 8 9l5.6-4.6",
14
+ sql: "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",
15
+ deploy: "M8 10.5V2.2M4.8 5.2 8 2l3.2 3.2M2.5 9.5v4h11v-4"
16
+ };
17
+ var ACTIONS = [
18
+ { id: "edit", name: "Edit files", sub: "Write to the repo", risk: 1 },
19
+ { id: "email", name: "Send email", sub: "Reply to customers", risk: 2 },
20
+ { id: "sql", name: "Run SQL", sub: "Read and write prod", risk: 3 },
21
+ { id: "deploy", name: "Deploy", sub: "Ship to production", risk: 4 }
22
+ ];
23
+ var still = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches;
24
+ function AutonomyDial() {
25
+ const [level, setLevel] = useState(1);
26
+ const [moved, setMoved] = useState(null);
27
+ const [demo, setDemo] = useState(true);
28
+ const [visible, setVisible] = useState(true);
29
+ const root = useRef(null);
30
+ const track = useRef(null);
31
+ const rect = useRef(null);
32
+ const idle = useRef(null);
33
+ const lv = useRef(1);
34
+ const go = (n) => {
35
+ const next = Math.max(0, Math.min(MAX, n));
36
+ const prev = lv.current;
37
+ if (next === prev) return;
38
+ lv.current = next;
39
+ setLevel(next);
40
+ const crossed = ACTIONS.find((a) => a.risk === Math.max(next, prev));
41
+ if (crossed && Math.abs(next - prev) === 1) setMoved((m) => ({ id: crossed.id, n: (m?.n ?? 0) + 1 }));
42
+ };
43
+ const takeOver = () => {
44
+ setDemo(false);
45
+ if (idle.current) clearTimeout(idle.current);
46
+ idle.current = setTimeout(() => setDemo(true), 8e3);
47
+ };
48
+ useEffect(() => () => void (idle.current && clearTimeout(idle.current)), []);
49
+ useEffect(() => {
50
+ const el = root.current;
51
+ if (!el) return;
52
+ let seen = true;
53
+ const sync = () => setVisible(seen && !document.hidden);
54
+ const io = new IntersectionObserver(([e]) => {
55
+ seen = e.isIntersecting;
56
+ sync();
57
+ });
58
+ io.observe(el);
59
+ document.addEventListener("visibilitychange", sync);
60
+ return () => {
61
+ io.disconnect();
62
+ document.removeEventListener("visibilitychange", sync);
63
+ };
64
+ }, []);
65
+ useEffect(() => {
66
+ if (!demo || !visible || still()) return;
67
+ let i = Math.max(0, SWEEP.indexOf(lv.current));
68
+ let id;
69
+ const tick = () => {
70
+ i = (i + 1) % SWEEP.length;
71
+ go(SWEEP[i]);
72
+ id = setTimeout(tick, 1700);
73
+ };
74
+ id = setTimeout(tick, 1400);
75
+ return () => clearTimeout(id);
76
+ }, [demo, visible]);
77
+ const fromX = (x) => {
78
+ const r = rect.current;
79
+ if (!r) return;
80
+ go(Math.round((x - r.left) / r.width * MAX));
81
+ };
82
+ const onDown = (e) => {
83
+ takeOver();
84
+ rect.current = track.current?.getBoundingClientRect() ?? null;
85
+ e.currentTarget.setPointerCapture(e.pointerId);
86
+ fromX(e.clientX);
87
+ };
88
+ const onMove = (e) => {
89
+ if (e.currentTarget.hasPointerCapture(e.pointerId)) fromX(e.clientX);
90
+ };
91
+ const onKey = (e) => {
92
+ const d = { ArrowRight: 1, ArrowUp: 1, ArrowLeft: -1, ArrowDown: -1 }[e.key];
93
+ const to = e.key === "Home" ? 0 : e.key === "End" ? MAX : d !== void 0 ? lv.current + d : null;
94
+ if (to === null) return;
95
+ e.preventDefault();
96
+ takeOver();
97
+ go(to);
98
+ };
99
+ const asks = ACTIONS.filter((a) => a.risk > level);
100
+ const alone = ACTIONS.filter((a) => a.risk <= level);
101
+ return /* @__PURE__ */ jsxs("div", { ref: root, className: "flex h-full w-full items-center justify-center px-5 pb-5 pt-11", style: { containerType: "size" }, children: [
102
+ /* @__PURE__ */ jsx("style", { href: "asta-autonomydial", precedence: "asta", children: `
103
+ @keyframes lab-ad-flash { from { opacity: 1 } to { opacity: 0 } }
104
+ @keyframes lab-ad-pop { from { transform: scale(.9); opacity: 0 } to { transform: none; opacity: 1 } }
105
+ .lab-ad-flash { animation: lab-ad-flash 1.2s ${EASE} .25s both }
106
+ .lab-ad-pop { animation: lab-ad-pop .4s ${EASE} both }
107
+ .lab-ad-sub, .lab-ad-tag { display: none }
108
+ @container (min-height: 320px) { .lab-ad-sub { display: block } }
109
+ @container (min-width: 520px) { .lab-ad-tag { display: inline } }
110
+ @container (max-height: 300px) { .lab-ad-head { display: none } }
111
+ @media (prefers-reduced-motion: reduce) { .lab-ad-flash, .lab-ad-pop { animation: none; opacity: 0 } .lab-ad-glide { transition: none !important } }
112
+ ` }),
113
+ /* @__PURE__ */ jsxs(
114
+ "div",
115
+ {
116
+ className: `flex w-full max-w-[500px] flex-col gap-[max(8px,2.6cqh)] rounded-[14px] bg-paper p-[clamp(10px,3.4cqmin,16px)] ${RING} shadow-[0_18px_40px_-28px_rgb(0_0_0/0.35)]`,
117
+ style: { "--row": "clamp(26px, 10.5cqh, 44px)" },
118
+ children: [
119
+ /* @__PURE__ */ jsxs("div", { className: "lab-ad-head flex items-center justify-between gap-3 px-1", children: [
120
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
121
+ /* @__PURE__ */ jsx("p", { className: "text-[13.5px] font-medium tracking-[-0.01em] text-ink", children: "Agent permissions" }),
122
+ /* @__PURE__ */ jsx("p", { className: "truncate text-[11.5px] text-mute", children: "Astabyte Ops \xB7 production workspace" })
123
+ ] }),
124
+ /* @__PURE__ */ jsxs("span", { className: "shrink-0 rounded-md bg-paper-2 px-2 py-1 text-[11px] tabular-nums text-ink-2", children: [
125
+ alone.length,
126
+ " of ",
127
+ ACTIONS.length,
128
+ " run alone"
129
+ ] })
130
+ ] }),
131
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 px-1", children: [
132
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between text-[11.5px]", children: [
133
+ /* @__PURE__ */ jsx("span", { className: level === 0 ? "font-medium text-ink" : "text-mute", style: { transition: `color .3s ${EASE}` }, children: "Ask me first" }),
134
+ /* @__PURE__ */ jsx("span", { className: "lab-ad-pop hidden truncate px-2 text-[11px] text-ink-2 @[380px]:block", children: level > 0 && level < MAX ? STOPS[level] : "" }, level),
135
+ /* @__PURE__ */ jsx("span", { className: level === MAX ? "font-medium text-ink" : "text-mute", style: { transition: `color .3s ${EASE}` }, children: "Runs on its own" })
136
+ ] }),
137
+ /* @__PURE__ */ jsx(
138
+ "div",
139
+ {
140
+ role: "slider",
141
+ tabIndex: 0,
142
+ "aria-label": "Agent autonomy",
143
+ "aria-valuemin": 0,
144
+ "aria-valuemax": MAX,
145
+ "aria-valuenow": level,
146
+ "aria-valuetext": `${STOPS[level]}. ${alone.length} of ${ACTIONS.length} actions run without asking`,
147
+ onPointerDown: onDown,
148
+ onPointerMove: onMove,
149
+ onKeyDown: onKey,
150
+ className: "group relative h-6 cursor-grab touch-none rounded-md px-[9px] outline-none active:cursor-grabbing focus-visible:ring-2 focus-visible:ring-brand/60",
151
+ children: /* @__PURE__ */ jsxs("div", { ref: track, className: "relative h-full", children: [
152
+ /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "absolute inset-x-0 top-1/2 h-1 -translate-y-1/2 rounded-full bg-paper-2" }),
153
+ /* @__PURE__ */ jsx(
154
+ "span",
155
+ {
156
+ "aria-hidden": true,
157
+ className: "lab-ad-glide absolute inset-x-0 top-1/2 h-1 origin-left -translate-y-1/2 rounded-full bg-brand",
158
+ style: { transform: `scaleX(${level / MAX})`, transition: `transform .55s ${EASE}` }
159
+ }
160
+ ),
161
+ STOPS.map((s, i) => /* @__PURE__ */ jsx(
162
+ "span",
163
+ {
164
+ "aria-hidden": true,
165
+ className: `absolute top-1/2 h-1.5 w-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full ${i <= level ? "bg-paper" : "bg-mute"}`,
166
+ style: { left: `${i / MAX * 100}%`, transition: `background-color .3s ${EASE}` }
167
+ },
168
+ s
169
+ )),
170
+ /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "lab-ad-glide absolute inset-0", style: { transform: `translateX(${level / MAX * 100}%)`, transition: `transform .55s ${EASE}` }, children: /* @__PURE__ */ jsx("span", { className: "absolute left-0 top-1/2 h-[18px] w-[18px] -translate-x-1/2 -translate-y-1/2 rounded-full bg-paper shadow-[inset_0_0_0_1.5px_var(--brand),0_2px_6px_-1px_rgb(0_0_0/0.35)] transition-transform duration-150 group-active:scale-110" }) })
171
+ ] })
172
+ }
173
+ )
174
+ ] }),
175
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
176
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-[10px] px-1 text-[11px]", children: [
177
+ /* @__PURE__ */ jsxs("span", { className: "text-mute", children: [
178
+ "Asks first ",
179
+ /* @__PURE__ */ jsxs("span", { className: "tabular-nums text-ink-2", children: [
180
+ "\xB7 ",
181
+ asks.length
182
+ ] })
183
+ ] }),
184
+ /* @__PURE__ */ jsxs("span", { className: "text-mute", children: [
185
+ "Runs alone ",
186
+ /* @__PURE__ */ jsxs("span", { className: "tabular-nums text-ink-2", children: [
187
+ "\xB7 ",
188
+ alone.length
189
+ ] })
190
+ ] })
191
+ ] }),
192
+ /* @__PURE__ */ jsxs("div", { className: "relative", style: { height: `calc(${ACTIONS.length} * var(--row) + ${ACTIONS.length - 1} * 5px + 10px)` }, children: [
193
+ /* @__PURE__ */ jsxs("div", { "aria-hidden": true, className: "absolute inset-0 grid grid-cols-2 gap-[10px]", children: [
194
+ /* @__PURE__ */ jsx("div", { className: "grid place-items-center rounded-[11px] bg-paper-2", children: /* @__PURE__ */ jsx("span", { className: "text-[11.5px] text-mute", style: { opacity: asks.length ? 0 : 1, transition: `opacity .4s ${EASE}` }, children: "Nothing needs your OK" }) }),
195
+ /* @__PURE__ */ jsx("div", { className: "grid place-items-center rounded-[11px] bg-paper-2", children: /* @__PURE__ */ jsx("span", { className: "text-[11.5px] text-mute", style: { opacity: alone.length ? 0 : 1, transition: `opacity .4s ${EASE}` }, children: "Nothing runs alone" }) })
196
+ ] }),
197
+ /* @__PURE__ */ jsx("ul", { "aria-label": "Actions", className: "absolute inset-[5px]", children: ACTIONS.map((a) => {
198
+ const on = a.risk <= level;
199
+ const idx = on ? alone.indexOf(a) : asks.indexOf(a);
200
+ return /* @__PURE__ */ jsxs(
201
+ "li",
202
+ {
203
+ className: `lab-ad-glide absolute left-0 top-0 flex h-[var(--row)] w-[calc(50%-10px)] items-center gap-2 rounded-[8px] bg-paper px-2 ${RING} shadow-[0_1px_2px_rgb(0_0_0/0.12)]`,
204
+ style: {
205
+ transform: `translate(${on ? "calc(100% + 20px)" : "0px"}, calc(${idx} * (100% + 5px)))`,
206
+ transition: `transform .6s ${EASE}`,
207
+ zIndex: moved?.id === a.id ? 2 : 1
208
+ },
209
+ children: [
210
+ moved?.id === a.id && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "lab-ad-flash pointer-events-none absolute inset-0 rounded-[8px] shadow-[inset_0_0_0_1.5px_var(--brand)]" }, moved.n),
211
+ /* @__PURE__ */ jsx(
212
+ "span",
213
+ {
214
+ className: `grid h-[clamp(18px,6cqh,24px)] w-[clamp(18px,6cqh,24px)] shrink-0 place-items-center rounded-[6px] ${on ? "bg-brand text-paper" : "bg-paper-2 text-ink-2"}`,
215
+ style: { transition: `background-color .4s ${EASE}, color .4s ${EASE}` },
216
+ children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", className: "h-[62%] w-[62%]", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: ICONS[a.id] }) })
217
+ }
218
+ ),
219
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1 leading-tight", children: [
220
+ /* @__PURE__ */ jsx("span", { className: "block truncate text-[12.5px] font-medium text-ink", children: a.name }),
221
+ /* @__PURE__ */ jsx("span", { className: "lab-ad-sub truncate text-[10.5px] text-mute", children: a.sub })
222
+ ] }),
223
+ /* @__PURE__ */ jsx("span", { className: `lab-ad-tag shrink-0 text-[10.5px] ${on ? "text-brand" : "text-mute"}`, children: on ? "Auto" : "Needs OK" }),
224
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: on ? ", runs without asking" : ", asks first" })
225
+ ]
226
+ },
227
+ a.id
228
+ );
229
+ }) })
230
+ ] })
231
+ ] })
232
+ ]
233
+ }
234
+ )
235
+ ] });
236
+ }
237
+
238
+ export {
239
+ AutonomyDial
240
+ };
@@ -0,0 +1,235 @@
1
+ "use client";
2
+
3
+ // components/kit/citations.tsx
4
+ import { useEffect, useId, useRef, useState } from "react";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ var cx = (...c) => c.filter(Boolean).join(" ");
7
+ var KEYFRAMES = `@keyframes asta-cite-in { from { opacity: 0; transform: translateY(4px) scale(.98) } }
8
+ @keyframes asta-cite-rise { from { opacity: 0; transform: translateY(6px) } }
9
+ @keyframes asta-cite-pulse { 50% { opacity: .45 } }
10
+ @media (prefers-reduced-motion: reduce) { .asta-cite, .asta-cite * { animation: none !important; transition-duration: 0s !important } }`;
11
+ var TILES = ["bg-ink text-paper", "bg-brand text-white", "bg-paper-2 text-ink shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--ink)_10%,transparent)]"];
12
+ function Tile({ domain, i, size = "sm" }) {
13
+ return /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: cx("grid shrink-0 place-items-center font-semibold uppercase", size === "md" ? "h-7 w-7 rounded-md text-[12px]" : "h-[18px] w-[18px] rounded-[5px] text-[10px]", TILES[i % TILES.length]), children: domain.replace(/^www\./, "").charAt(0) });
14
+ }
15
+ function Quote({ s }) {
16
+ const at = s.quote ? s.snippet.indexOf(s.quote) : -1;
17
+ if (at < 0) return /* @__PURE__ */ jsx(Fragment, { children: s.snippet });
18
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
19
+ s.snippet.slice(0, at),
20
+ /* @__PURE__ */ jsx("mark", { className: "rounded-[3px] bg-[color-mix(in_srgb,var(--brand)_14%,transparent)] px-0.5 text-ink [box-decoration-break:clone]", children: s.quote }),
21
+ s.snippet.slice(at + s.quote.length)
22
+ ] });
23
+ }
24
+ var parse = (p) => {
25
+ const out = [];
26
+ const re = /(?:\s*\[(\d+(?:\s*,\s*\d+)*)\])+/g;
27
+ let last = 0;
28
+ for (let m; m = re.exec(p); ) {
29
+ out.push(p.slice(last, m.index));
30
+ out.push([...m[0].matchAll(/\d+/g)].map((d) => Number(d[0])));
31
+ last = re.lastIndex;
32
+ }
33
+ out.push(p.slice(last));
34
+ return out;
35
+ };
36
+ var arrow = /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", className: "h-3 w-3", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M5.5 10.5 10.5 5.5M6 5.5h4.5V10" }) });
37
+ function Citations({ text, sources, loading, visible = 3, className }) {
38
+ const [card, setCard] = useState(null);
39
+ const [lit, setLit] = useState(null);
40
+ const [all, setAll] = useState(false);
41
+ const timer = useRef(void 0);
42
+ const root = useRef(null);
43
+ const uid = useId();
44
+ useEffect(() => () => clearTimeout(timer.current), []);
45
+ useEffect(() => {
46
+ if (!card) return;
47
+ const onKey = (e) => e.key === "Escape" && setCard(null);
48
+ const onDown = (e) => !e.target.closest?.("[data-asta-cite-pill]") && setCard(null);
49
+ document.addEventListener("keydown", onKey);
50
+ document.addEventListener("pointerdown", onDown);
51
+ return () => {
52
+ document.removeEventListener("keydown", onKey);
53
+ document.removeEventListener("pointerdown", onDown);
54
+ };
55
+ }, [card]);
56
+ const openCard = (el, key, src, pinned = false) => {
57
+ clearTimeout(timer.current);
58
+ const r = el.getBoundingClientRect();
59
+ const w = Math.min(304, window.innerWidth - 32);
60
+ const left = Math.max(16, Math.min(r.left + r.width / 2 - w / 2, window.innerWidth - 16 - w));
61
+ setCard({ key, src, x: left - r.left, below: r.top < 220, pinned });
62
+ };
63
+ const later = (fn, ms) => {
64
+ clearTimeout(timer.current);
65
+ timer.current = setTimeout(fn, ms);
66
+ };
67
+ const closeSoon = () => later(() => setCard((c) => c?.pinned ? c : null), 140);
68
+ const paragraphs = text.split(/\n\s*\n/);
69
+ const shown = all ? sources : sources.slice(0, visible);
70
+ const more = sources.length - visible;
71
+ const pill = (n, key) => {
72
+ const i = n - 1;
73
+ const s = sources[i];
74
+ if (!s) return /* @__PURE__ */ jsxs("span", { className: "text-mute", children: [
75
+ "[",
76
+ n,
77
+ "]"
78
+ ] }, key);
79
+ const open = card?.key === key;
80
+ const on = lit === i || card?.src === i && !open;
81
+ return /* @__PURE__ */ jsxs("span", { className: "relative inline-block", children: [
82
+ /* @__PURE__ */ jsx(
83
+ "button",
84
+ {
85
+ type: "button",
86
+ "data-asta-cite-pill": true,
87
+ "aria-label": `Source ${n}: ${s.title}`,
88
+ "aria-describedby": open ? `${uid}-card` : void 0,
89
+ "aria-expanded": open,
90
+ onPointerEnter: (e) => {
91
+ const el = e.currentTarget;
92
+ if (e.pointerType === "mouse") later(() => openCard(el, key, i), 90);
93
+ },
94
+ onPointerLeave: (e) => e.pointerType === "mouse" && closeSoon(),
95
+ onFocus: (e) => e.currentTarget.matches(":focus-visible") && openCard(e.currentTarget, key, i),
96
+ onBlur: () => setCard((c) => c?.key === key ? null : c),
97
+ onClick: (e) => open && card?.pinned ? setCard(null) : openCard(e.currentTarget, key, i, true),
98
+ className: cx(
99
+ "mx-px inline-grid h-[18px] min-w-[18px] -translate-y-px place-items-center rounded-[5px] px-1 align-middle text-[11px] font-semibold leading-none tabular-nums outline-none",
100
+ "transition-[background-color,color,transform] duration-200 focus-visible:ring-2 focus-visible:ring-brand/50 active:scale-95",
101
+ open || on ? "bg-brand text-white" : "bg-[color-mix(in_srgb,var(--ink)_8%,transparent)] text-ink-2 hover:bg-[color-mix(in_srgb,var(--ink)_14%,transparent)] hover:text-ink"
102
+ ),
103
+ children: n
104
+ }
105
+ ),
106
+ open && /* @__PURE__ */ jsxs(
107
+ "span",
108
+ {
109
+ id: `${uid}-card`,
110
+ role: "tooltip",
111
+ onPointerEnter: () => clearTimeout(timer.current),
112
+ onPointerLeave: closeSoon,
113
+ style: { left: card.x },
114
+ className: cx(
115
+ "absolute z-50 block w-[304px] max-w-[calc(100vw-32px)] whitespace-normal rounded-xl bg-paper p-3.5 text-left leading-normal",
116
+ "shadow-[0_0_0_1px_color-mix(in_srgb,var(--ink)_10%,transparent),0_16px_36px_-12px_rgb(0_0_0/0.28),0_4px_10px_-6px_rgb(0_0_0/0.1)]",
117
+ "animate-[asta-cite-in_.18s_cubic-bezier(.16,1,.3,1)_both]",
118
+ card.below ? "top-full mt-2 origin-top" : "bottom-full mb-2 origin-bottom"
119
+ ),
120
+ children: [
121
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-2", children: [
122
+ /* @__PURE__ */ jsx(Tile, { domain: s.domain, i }),
123
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1 truncate text-[12px] text-mute", children: [
124
+ s.domain,
125
+ s.date && ` \xB7 ${s.date}`
126
+ ] }),
127
+ /* @__PURE__ */ jsxs("span", { className: "font-mono text-[11px] text-mute", children: [
128
+ "[",
129
+ n,
130
+ "]"
131
+ ] })
132
+ ] }),
133
+ /* @__PURE__ */ jsx("span", { className: "mt-2 line-clamp-2 text-[13.5px] font-medium leading-snug text-ink", children: s.title }),
134
+ /* @__PURE__ */ jsx("span", { className: "mt-1.5 line-clamp-4 text-[12.5px] leading-relaxed text-ink-2", children: /* @__PURE__ */ jsx(Quote, { s }) })
135
+ ]
136
+ }
137
+ )
138
+ ] }, key);
139
+ };
140
+ if (loading)
141
+ return /* @__PURE__ */ jsxs("div", { className: cx("asta-cite flex w-full flex-col gap-5", className), "aria-busy": "true", "aria-label": "Loading answer", children: [
142
+ /* @__PURE__ */ jsx("style", { href: "asta-citations", precedence: "asta", children: KEYFRAMES }),
143
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2.5 pt-1", children: ["w-full", "w-[94%]", "w-[86%]", "w-[60%]"].map((w, i) => /* @__PURE__ */ jsx("span", { className: cx("h-3 rounded-full bg-paper-2", w), style: { animation: `asta-cite-pulse 1.4s cubic-bezier(.16,1,.3,1) ${i * 120}ms infinite` } }, w)) }),
144
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-2 sm:grid-cols-4", children: [0, 1, 2, 3].map((i) => /* @__PURE__ */ jsx("span", { className: cx("h-[58px] rounded-[10px] bg-paper-2", i > 1 && "hidden sm:block"), style: { animation: `asta-cite-pulse 1.4s cubic-bezier(.16,1,.3,1) ${i * 120}ms infinite` } }, i)) })
145
+ ] });
146
+ return /* @__PURE__ */ jsxs("div", { ref: root, className: cx("asta-cite flex w-full flex-col gap-5", className), children: [
147
+ /* @__PURE__ */ jsx("style", { href: "asta-citations", precedence: "asta", children: KEYFRAMES }),
148
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-3 text-[15px] leading-[1.7] text-ink", children: paragraphs.map((p, pi) => /* @__PURE__ */ jsx("p", { children: parse(p).map((part, k) => typeof part === "string" ? part : /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap", children: part.map((n, j) => pill(n, `${pi}-${k}-${j}`)) }, k)) }, pi)) }),
149
+ sources.length === 0 ? /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-2 text-[12.5px] text-mute", children: [
150
+ /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 16 16", className: "h-3.5 w-3.5", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", "aria-hidden": true, children: [
151
+ /* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "6" }),
152
+ /* @__PURE__ */ jsx("path", { d: "M8 5v3.5M8 11h.01" })
153
+ ] }),
154
+ "No sources were used for this answer. Check it before you rely on it."
155
+ ] }) : /* @__PURE__ */ jsxs("section", { "aria-labelledby": `${uid}-h`, className: "flex flex-col gap-2.5", children: [
156
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3", children: [
157
+ /* @__PURE__ */ jsxs("h4", { id: `${uid}-h`, className: "flex items-center gap-2 text-[12.5px] font-medium text-ink-2", children: [
158
+ "Sources",
159
+ /* @__PURE__ */ jsx("span", { className: "rounded-[5px] bg-paper-2 px-1.5 text-[11px] tabular-nums text-mute", children: sources.length })
160
+ ] }),
161
+ more > 0 && /* @__PURE__ */ jsxs(
162
+ "button",
163
+ {
164
+ type: "button",
165
+ "aria-expanded": all,
166
+ "aria-controls": `${uid}-list`,
167
+ onClick: () => setAll((a) => !a),
168
+ className: "flex h-7 items-center gap-1 rounded-md px-2 text-[12.5px] font-medium text-ink-2 outline-none transition-colors duration-150 hover:bg-paper-2 hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50",
169
+ children: [
170
+ all ? "Show less" : `Show all ${sources.length}`,
171
+ /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", className: cx("h-3.5 w-3.5 transition-transform duration-300 ease-[cubic-bezier(.16,1,.3,1)]", all && "rotate-180"), fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "m4 6 4 4 4-4" }) })
172
+ ]
173
+ }
174
+ )
175
+ ] }),
176
+ /* @__PURE__ */ jsxs("ol", { id: `${uid}-list`, className: cx(all ? "flex flex-col gap-1" : "grid grid-cols-1 gap-2 min-[480px]:grid-cols-2 sm:grid-cols-4"), children: [
177
+ shown.map((s, i) => {
178
+ const lightUp = { onPointerEnter: () => setLit(i), onPointerLeave: () => setLit(null), onFocus: () => setLit(i), onBlur: () => setLit(null) };
179
+ const hot = lit === i || card?.src === i;
180
+ const body = all ? /* @__PURE__ */ jsxs(Fragment, { children: [
181
+ /* @__PURE__ */ jsx("span", { className: "w-5 shrink-0 pt-1 text-right font-mono text-[11px] tabular-nums text-mute", children: i + 1 }),
182
+ /* @__PURE__ */ jsx(Tile, { domain: s.domain, i, size: "md" }),
183
+ /* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
184
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
185
+ /* @__PURE__ */ jsx("span", { className: "truncate text-[13.5px] font-medium text-ink", children: s.title }),
186
+ s.url && /* @__PURE__ */ jsx("span", { className: "shrink-0 text-mute", children: arrow })
187
+ ] }),
188
+ /* @__PURE__ */ jsxs("span", { className: "block text-[12px] text-mute", children: [
189
+ s.domain,
190
+ s.date && ` \xB7 ${s.date}`
191
+ ] }),
192
+ /* @__PURE__ */ jsx("span", { className: "mt-1 line-clamp-2 text-[12.5px] leading-relaxed text-ink-2", children: /* @__PURE__ */ jsx(Quote, { s }) })
193
+ ] })
194
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
195
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
196
+ /* @__PURE__ */ jsx(Tile, { domain: s.domain, i }),
197
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate text-[11.5px] text-mute", children: s.domain }),
198
+ /* @__PURE__ */ jsx("span", { className: "font-mono text-[11px] tabular-nums text-mute", children: i + 1 })
199
+ ] }),
200
+ /* @__PURE__ */ jsx("span", { className: "mt-1.5 line-clamp-2 text-[12.5px] font-medium leading-snug text-ink", children: s.title })
201
+ ] });
202
+ const cls = cx(
203
+ "block w-full rounded-[10px] text-left outline-none transition-[background-color,box-shadow] duration-200 focus-visible:ring-2 focus-visible:ring-brand/50",
204
+ all ? "flex gap-3 p-2.5" : "p-2.5",
205
+ hot ? "bg-[color-mix(in_srgb,var(--brand)_7%,var(--paper))] shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--brand)_35%,transparent)]" : "bg-paper-2 hover:bg-[color-mix(in_srgb,var(--ink)_7%,var(--paper-2))]",
206
+ all && !hot && "bg-transparent"
207
+ );
208
+ return /* @__PURE__ */ jsx("li", { style: { animation: `asta-cite-rise .35s cubic-bezier(.16,1,.3,1) ${all ? i * 35 : 0}ms both` }, children: s.url ? /* @__PURE__ */ jsx("a", { href: s.url, target: "_blank", rel: "noopener noreferrer", ...lightUp, className: cx(cls, all && "flex"), "aria-label": `${i + 1}. ${s.title}, ${s.domain}. Opens in a new tab`, children: body }) : /* @__PURE__ */ jsx("div", { tabIndex: 0, ...lightUp, className: cls, "aria-label": `${i + 1}. ${s.title}, ${s.domain}`, children: body }) }, i);
209
+ }),
210
+ !all && more > 0 && /* @__PURE__ */ jsx("li", { className: "hidden sm:block", children: /* @__PURE__ */ jsxs(
211
+ "button",
212
+ {
213
+ type: "button",
214
+ onClick: () => setAll(true),
215
+ className: "flex h-full w-full flex-col justify-between rounded-[10px] bg-paper-2 p-2.5 text-left outline-none transition-colors duration-200 hover:bg-[color-mix(in_srgb,var(--ink)_7%,var(--paper-2))] focus-visible:ring-2 focus-visible:ring-brand/50",
216
+ children: [
217
+ /* @__PURE__ */ jsx("span", { className: "line-clamp-1 text-[11.5px] text-mute", children: sources.slice(visible).map((s) => s.domain).join(", ") }),
218
+ /* @__PURE__ */ jsxs("span", { className: "mt-1.5 text-[12.5px] font-medium text-ink", children: [
219
+ "+",
220
+ more,
221
+ " more"
222
+ ] })
223
+ ]
224
+ }
225
+ ) })
226
+ ] })
227
+ ] })
228
+ ] });
229
+ }
230
+ var citations_default = Citations;
231
+
232
+ export {
233
+ Citations,
234
+ citations_default
235
+ };