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,253 @@
1
+ "use client";
2
+ import {
3
+ Popover
4
+ } from "./chunk-IATF2OTU.js";
5
+
6
+ // components/kit/context-meter.tsx
7
+ import { useEffect, useRef, useState } from "react";
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+ var cx = (...c) => c.filter(Boolean).join(" ");
10
+ var CURVE = "cubic-bezier(.16,1,.3,1)";
11
+ var KEYFRAMES = `@keyframes asta-ctx-in { from { opacity: 0; transform: translateY(3px) } }
12
+ @keyframes asta-ctx-spin { to { transform: rotate(360deg) } }
13
+ @media (prefers-reduced-motion: reduce) { .asta-ctx-a, .asta-ctx-a * { animation: none !important; transition-duration: 0s !important } }`;
14
+ var FILLS = [
15
+ "var(--brand)",
16
+ "color-mix(in srgb, var(--brand) 55%, var(--paper))",
17
+ "color-mix(in srgb, var(--ink) 62%, var(--paper))",
18
+ "color-mix(in srgb, var(--ink) 28%, var(--paper))",
19
+ "color-mix(in srgb, var(--ink) 14%, var(--paper))"
20
+ ];
21
+ var formatTokens = (n) => {
22
+ if (n < 1e3) return String(Math.round(n));
23
+ const k = n / 1e3;
24
+ return `${k >= 100 || Number.isInteger(k) ? Math.round(k) : k.toFixed(1)}k`;
25
+ };
26
+ function useTween(value) {
27
+ const [shown, setShown] = useState(value);
28
+ const from = useRef(value);
29
+ useEffect(() => {
30
+ const start = from.current;
31
+ if (start === value) return;
32
+ if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
33
+ from.current = value;
34
+ const id2 = requestAnimationFrame(() => setShown(value));
35
+ return () => cancelAnimationFrame(id2);
36
+ }
37
+ const t0 = performance.now();
38
+ let id = 0;
39
+ const step = (t) => {
40
+ const p = Math.min(1, (t - t0) / 700);
41
+ const e = 1 - Math.pow(1 - p, 4);
42
+ const v = start + (value - start) * e;
43
+ from.current = v;
44
+ setShown(v);
45
+ if (p < 1) id = requestAnimationFrame(step);
46
+ };
47
+ id = requestAnimationFrame(step);
48
+ return () => cancelAnimationFrame(id);
49
+ }, [value]);
50
+ return shown;
51
+ }
52
+ function Ring({ share, warn, className }) {
53
+ return /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 16 16", className: cx("-rotate-90 shrink-0", className), "aria-hidden": true, children: [
54
+ /* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "6.25", fill: "none", strokeWidth: "2.5", style: { stroke: "color-mix(in srgb, var(--ink) 11%, transparent)" } }),
55
+ /* @__PURE__ */ jsx(
56
+ "circle",
57
+ {
58
+ cx: "8",
59
+ cy: "8",
60
+ r: "6.25",
61
+ fill: "none",
62
+ strokeWidth: "2.5",
63
+ strokeLinecap: "round",
64
+ pathLength: 100,
65
+ strokeDasharray: "100 100",
66
+ strokeDashoffset: 100 - Math.max(share * 100, share > 0 ? 3 : 0),
67
+ className: cx("transition-[stroke-dashoffset,stroke] duration-700 motion-reduce:transition-none", warn ? "stroke-ink" : "stroke-brand"),
68
+ style: { transitionTimingFunction: CURVE }
69
+ }
70
+ )
71
+ ] });
72
+ }
73
+ function WarnIcon() {
74
+ return /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", className: "mt-px h-3.5 w-3.5 shrink-0", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M8 2.5 14 13H2zM8 6.5v3M8 11.2h.01" }) });
75
+ }
76
+ var sum = (s) => s.reduce((a, p) => a + Math.max(0, p.tokens), 0);
77
+ function ContextBreakdown({ segments, max, model, warnAt = 0.8, onCompact, className }) {
78
+ const used = sum(segments);
79
+ const share = max > 0 ? Math.min(1, used / max) : 0;
80
+ const warn = share >= warnAt;
81
+ const shown = useTween(used);
82
+ const [busy, setBusy] = useState(false);
83
+ const [freed, setFreed] = useState(0);
84
+ const [last, setLast] = useState(used);
85
+ const alive = useRef(true);
86
+ useEffect(() => {
87
+ alive.current = true;
88
+ return () => {
89
+ alive.current = false;
90
+ };
91
+ }, []);
92
+ if (last !== used) {
93
+ setLast(used);
94
+ setFreed(used < last ? last - used : 0);
95
+ }
96
+ const compact = async () => {
97
+ if (!onCompact || busy) return;
98
+ setBusy(true);
99
+ try {
100
+ await onCompact();
101
+ } finally {
102
+ if (alive.current) setBusy(false);
103
+ }
104
+ };
105
+ const starts = segments.map((_, i) => sum(segments.slice(0, i)));
106
+ return /* @__PURE__ */ jsxs("div", { className: cx("asta-ctx-a flex w-full flex-col gap-3 text-ink", className), children: [
107
+ /* @__PURE__ */ jsx("style", { href: "asta-context-meter", precedence: "asta", children: KEYFRAMES }),
108
+ /* @__PURE__ */ jsxs("div", { className: "flex items-baseline justify-between gap-3", children: [
109
+ /* @__PURE__ */ jsx("p", { className: "text-[13.5px] font-medium", children: "Context window" }),
110
+ model && /* @__PURE__ */ jsx("p", { className: "truncate text-[12px] text-mute", children: model })
111
+ ] }),
112
+ /* @__PURE__ */ jsxs("div", { className: "flex items-baseline justify-between gap-3", children: [
113
+ /* @__PURE__ */ jsxs("p", { className: "tabular-nums", children: [
114
+ /* @__PURE__ */ jsx("span", { className: "text-[22px] font-medium tracking-[-0.03em]", children: formatTokens(shown) }),
115
+ /* @__PURE__ */ jsxs("span", { className: "text-[12.5px] text-mute", children: [
116
+ " of ",
117
+ formatTokens(max),
118
+ " tokens"
119
+ ] })
120
+ ] }),
121
+ /* @__PURE__ */ jsxs("p", { className: cx("text-[12.5px] tabular-nums", warn ? "font-medium text-ink" : "text-mute"), children: [
122
+ Math.round(shown / (max || 1) * 100),
123
+ "% used"
124
+ ] })
125
+ ] }),
126
+ /* @__PURE__ */ jsx(
127
+ "div",
128
+ {
129
+ role: "meter",
130
+ "aria-label": "Context used",
131
+ "aria-valuemin": 0,
132
+ "aria-valuemax": max,
133
+ "aria-valuenow": Math.min(used, max),
134
+ "aria-valuetext": `${formatTokens(used)} of ${formatTokens(max)} tokens${warn ? ", near the limit" : ""}`,
135
+ className: "relative h-2 w-full overflow-hidden rounded-full bg-paper-2 shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--ink)_6%,transparent)]",
136
+ children: segments.map((p, i) => {
137
+ const x = starts[i] / (max || 1);
138
+ const w = Math.max(0, p.tokens) / (max || 1);
139
+ return /* @__PURE__ */ jsx(
140
+ "span",
141
+ {
142
+ className: "absolute inset-y-0 left-0 w-full origin-left transition-transform duration-700 motion-reduce:transition-none",
143
+ style: {
144
+ transform: `translateX(${Math.min(1, x) * 100}%) scaleX(${Math.min(w, Math.max(0, 1 - x))})`,
145
+ background: FILLS[i % FILLS.length],
146
+ transitionTimingFunction: CURVE,
147
+ boxShadow: "inset -1px 0 0 var(--paper)"
148
+ }
149
+ },
150
+ p.label
151
+ );
152
+ })
153
+ }
154
+ ),
155
+ /* @__PURE__ */ jsxs("ul", { className: "flex flex-col gap-1.5 text-[12.5px]", children: [
156
+ segments.map((p, i) => /* @__PURE__ */ jsxs("li", { className: "flex items-center gap-2", children: [
157
+ /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "h-2 w-2 shrink-0 rounded-full", style: { background: FILLS[i % FILLS.length] } }),
158
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate text-ink-2", children: p.label }),
159
+ /* @__PURE__ */ jsx("span", { className: "tabular-nums text-ink", children: formatTokens(p.tokens) }),
160
+ /* @__PURE__ */ jsxs("span", { className: "w-9 text-right tabular-nums text-mute", children: [
161
+ Math.round(p.tokens / (max || 1) * 100),
162
+ "%"
163
+ ] })
164
+ ] }, p.label)),
165
+ /* @__PURE__ */ jsxs("li", { className: "flex items-center gap-2", children: [
166
+ /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "h-2 w-2 shrink-0 rounded-full shadow-[inset_0_0_0_1.5px_color-mix(in_srgb,var(--ink)_22%,transparent)]" }),
167
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate text-mute", children: "Free" }),
168
+ /* @__PURE__ */ jsx("span", { className: "tabular-nums text-ink", children: formatTokens(Math.max(0, max - used)) }),
169
+ /* @__PURE__ */ jsxs("span", { className: "w-9 text-right tabular-nums text-mute", children: [
170
+ Math.max(0, 100 - Math.round(share * 100)),
171
+ "%"
172
+ ] })
173
+ ] })
174
+ ] }),
175
+ /* @__PURE__ */ jsx("p", { className: "sr-only", "aria-live": "polite", children: freed > 0 ? `Compacted. Freed ${formatTokens(freed)} tokens.` : busy ? "Compacting conversation." : "" }),
176
+ warn ? /* @__PURE__ */ jsxs("p", { className: "asta-ctx-a flex gap-1.5 rounded-lg bg-paper-2 px-2.5 py-2 text-[12.5px] leading-snug text-ink animate-[asta-ctx-in_.35s_cubic-bezier(.16,1,.3,1)_both]", children: [
177
+ /* @__PURE__ */ jsx(WarnIcon, {}),
178
+ /* @__PURE__ */ jsxs("span", { children: [
179
+ /* @__PURE__ */ jsx("span", { className: "font-medium", children: "Near the limit." }),
180
+ " Older messages get summarised soon. Compact now to choose when."
181
+ ] })
182
+ ] }, "warn") : freed > 0 ? /* @__PURE__ */ jsxs("p", { className: "asta-ctx-a text-[12.5px] text-mute animate-[asta-ctx-in_.35s_cubic-bezier(.16,1,.3,1)_both]", children: [
183
+ "Freed ",
184
+ /* @__PURE__ */ jsx("span", { className: "font-medium tabular-nums text-ink", children: formatTokens(freed) }),
185
+ " tokens. The summary keeps decisions and open tasks."
186
+ ] }, `freed-${freed}`) : null,
187
+ onCompact && /* @__PURE__ */ jsxs(
188
+ "button",
189
+ {
190
+ type: "button",
191
+ onClick: compact,
192
+ "aria-busy": busy || void 0,
193
+ disabled: busy || used === 0,
194
+ className: "flex h-8 w-full items-center justify-center gap-2 rounded-md bg-paper-2 text-[13px] font-medium text-ink outline-none transition-[background-color,opacity,transform] duration-200 hover:bg-[color-mix(in_srgb,var(--ink)_8%,var(--paper-2))] active:scale-[0.98] focus-visible:ring-2 focus-visible:ring-brand/50 disabled:pointer-events-none disabled:opacity-60",
195
+ children: [
196
+ busy ? /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 16 16", className: "h-3.5 w-3.5 animate-[asta-ctx-spin_.8s_linear_infinite]", fill: "none", "aria-hidden": true, children: [
197
+ /* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "6", stroke: "currentColor", strokeOpacity: ".2", strokeWidth: "2" }),
198
+ /* @__PURE__ */ jsx("path", { d: "M14 8a6 6 0 0 0-6-6", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })
199
+ ] }) : /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", className: "h-3.5 w-3.5", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M3 6h10M3 10h10M8 1.5V4.5L6.5 3M8 4.5 9.5 3M8 14.5v-3L6.5 13M8 11.5l1.5 1.5" }) }),
200
+ busy ? "Compacting\u2026" : "Compact conversation"
201
+ ]
202
+ }
203
+ )
204
+ ] });
205
+ }
206
+ function ContextMeter({ size = "md", side = "top", align = "end", ...props }) {
207
+ const { segments, max, warnAt = 0.8 } = props;
208
+ const used = sum(segments);
209
+ const share = max > 0 ? Math.min(1, used / max) : 0;
210
+ const warn = share >= warnAt;
211
+ const pct = Math.round(share * 100);
212
+ return /* @__PURE__ */ jsx(
213
+ Popover,
214
+ {
215
+ side,
216
+ align,
217
+ label: "Context window",
218
+ className: "w-[300px] p-4",
219
+ trigger: /* @__PURE__ */ jsxs(
220
+ "button",
221
+ {
222
+ type: "button",
223
+ "aria-label": `Context window: ${pct}% used, ${formatTokens(used)} of ${formatTokens(max)} tokens${warn ? ", near the limit" : ""}`,
224
+ className: cx(
225
+ "asta-ctx-a inline-flex shrink-0 items-center gap-1.5 rounded-md text-[12.5px] tabular-nums outline-none transition-colors duration-200 hover:bg-paper-2 focus-visible:ring-2 focus-visible:ring-brand/50 data-[state=open]:bg-paper-2",
226
+ size === "sm" ? "h-7 px-1.5" : "h-8 px-2",
227
+ warn ? "text-ink" : "text-mute hover:text-ink"
228
+ ),
229
+ children: [
230
+ /* @__PURE__ */ jsx(Ring, { share, warn, className: "h-4 w-4" }),
231
+ /* @__PURE__ */ jsxs("span", { className: cx(warn && "font-medium"), children: [
232
+ pct,
233
+ "%"
234
+ ] }),
235
+ size === "md" && (warn ? /* @__PURE__ */ jsx("span", { className: "font-medium", children: "\xB7 Near limit" }) : /* @__PURE__ */ jsxs("span", { children: [
236
+ "of ",
237
+ formatTokens(max)
238
+ ] }))
239
+ ]
240
+ }
241
+ ),
242
+ children: /* @__PURE__ */ jsx(ContextBreakdown, { ...props })
243
+ }
244
+ );
245
+ }
246
+ var context_meter_default = ContextMeter;
247
+
248
+ export {
249
+ formatTokens,
250
+ ContextBreakdown,
251
+ ContextMeter,
252
+ context_meter_default
253
+ };