asta-ui 0.9.5 → 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,226 @@
1
+ "use client";
2
+
3
+ // components/kit/agent-plan.tsx
4
+ import { useEffect, useRef, useState } from "react";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ var cx = (...c) => c.filter(Boolean).join(" ");
7
+ var CURVE = "cubic-bezier(.16,1,.3,1)";
8
+ var KEYFRAMES = `@keyframes asta-plan-spin { to { transform: rotate(360deg) } }
9
+ @keyframes asta-plan-pop { from { opacity: 0; transform: scale(.6) } }
10
+ @keyframes asta-plan-draw { from { stroke-dashoffset: 1 } }
11
+ @keyframes asta-plan-in { from { opacity: 0; transform: translateY(4px) } }
12
+ @media (prefers-reduced-motion: reduce) { .asta-plan-a, .asta-plan-a * { animation: none !important; transition-duration: 0s !important } }`;
13
+ var formatStepTime = (ms) => {
14
+ const s = Math.max(0, ms) / 1e3;
15
+ if (s < 10) return `${s.toFixed(1)}s`;
16
+ if (s < 60) return `${Math.floor(s)}s`;
17
+ return `${Math.floor(s / 60)}m ${String(Math.floor(s % 60)).padStart(2, "0")}s`;
18
+ };
19
+ var settled = (s) => s === "done" || s === "skipped" || s === "failed";
20
+ function useNow(on, el) {
21
+ const [now, setNow] = useState(0);
22
+ useEffect(() => {
23
+ if (!on) return;
24
+ const node = el.current;
25
+ let seen = true;
26
+ let timer;
27
+ const tick = () => setNow(Date.now());
28
+ const sync = () => {
29
+ clearInterval(timer);
30
+ timer = void 0;
31
+ if (seen && !document.hidden) {
32
+ tick();
33
+ timer = setInterval(tick, 250);
34
+ }
35
+ };
36
+ const io = node ? new IntersectionObserver(([e]) => {
37
+ seen = e.isIntersecting;
38
+ sync();
39
+ }) : null;
40
+ if (node) io?.observe(node);
41
+ document.addEventListener("visibilitychange", sync);
42
+ sync();
43
+ return () => {
44
+ clearInterval(timer);
45
+ io?.disconnect();
46
+ document.removeEventListener("visibilitychange", sync);
47
+ };
48
+ }, [on, el]);
49
+ return now;
50
+ }
51
+ function StatusIcon({ status, small }) {
52
+ const box = small ? "h-3.5 w-3.5" : "h-[18px] w-[18px]";
53
+ if (status === "running")
54
+ return /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 18 18", className: cx(box, "asta-plan-a shrink-0 animate-[asta-plan-spin_.8s_linear_infinite] text-brand"), fill: "none", "aria-hidden": true, children: [
55
+ /* @__PURE__ */ jsx("circle", { cx: "9", cy: "9", r: "7", stroke: "currentColor", strokeOpacity: ".2", strokeWidth: "2" }),
56
+ /* @__PURE__ */ jsx("path", { d: "M16 9a7 7 0 0 0-7-7", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" })
57
+ ] });
58
+ if (status === "done")
59
+ return /* @__PURE__ */ jsx("span", { className: cx(box, "asta-plan-a grid shrink-0 place-items-center rounded-full bg-brand text-white animate-[asta-plan-pop_.35s_cubic-bezier(.16,1,.3,1)_both]"), "aria-hidden": true, children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", className: "h-[70%] w-[70%]", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx("path", { d: "m3.5 8.5 3 3 6-7", pathLength: 1, strokeDasharray: 1, className: "asta-plan-a animate-[asta-plan-draw_.45s_cubic-bezier(.16,1,.3,1)_.1s_both]" }) }) });
60
+ if (status === "failed")
61
+ return /* @__PURE__ */ jsx("span", { className: cx(box, "asta-plan-a grid shrink-0 place-items-center rounded-full bg-ink text-paper animate-[asta-plan-pop_.35s_cubic-bezier(.16,1,.3,1)_both]"), "aria-hidden": true, children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", className: "h-[70%] w-[70%]", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", children: /* @__PURE__ */ jsx("path", { d: "M8 4v5M8 12h.01" }) }) });
62
+ if (status === "skipped")
63
+ return /* @__PURE__ */ jsx("span", { className: cx(box, "grid shrink-0 place-items-center rounded-full text-mute shadow-[inset_0_0_0_1.5px_color-mix(in_srgb,var(--ink)_20%,transparent)]"), "aria-hidden": true, children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 16 16", className: "h-[70%] w-[70%]", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", children: /* @__PURE__ */ jsx("path", { d: "M5 8h6" }) }) });
64
+ return /* @__PURE__ */ jsx("span", { className: cx(box, "shrink-0 rounded-full shadow-[inset_0_0_0_1.5px_color-mix(in_srgb,var(--ink)_20%,transparent)]"), "aria-hidden": true });
65
+ }
66
+ var WORD = { pending: "Pending", running: "Running", done: "Done", skipped: "Skipped", failed: "Failed" };
67
+ function elapsed(s, now) {
68
+ if (s.status === "running" && s.startedAt) return Math.max(0, (now || s.startedAt) - s.startedAt);
69
+ return s.duration;
70
+ }
71
+ function AgentPlan({ title, steps, action, footer, className }) {
72
+ const root = useRef(null);
73
+ const [pinned, setPinned] = useState({});
74
+ const running = steps.some((s) => s.status === "running" || s.substeps?.some((x) => x.status === "running"));
75
+ const now = useNow(running, root);
76
+ const total = steps.length;
77
+ const doneCount = steps.filter((s) => settled(s.status)).length;
78
+ const failedAt = steps.findIndex((s) => s.status === "failed");
79
+ const current = steps.findIndex((s) => s.status === "running");
80
+ const allDone = total > 0 && doneCount === total && failedAt < 0;
81
+ const spent = steps.reduce((a, s) => a + (elapsed(s, now) ?? 0), 0);
82
+ const state = failedAt >= 0 ? `Stopped at step ${failedAt + 1}` : allDone ? "Done" : running ? "Running" : doneCount === 0 ? "Not started" : "Paused";
83
+ const live = failedAt >= 0 ? `Step ${failedAt + 1} failed: ${steps[failedAt].title}.` : current >= 0 ? `Step ${current + 1} of ${total}: ${steps[current].title}.` : allDone ? `All ${total} steps done.` : "";
84
+ return /* @__PURE__ */ jsxs(
85
+ "section",
86
+ {
87
+ ref: root,
88
+ "aria-label": title,
89
+ className: cx(
90
+ "asta-plan-a flex w-full flex-col rounded-[14px] bg-paper text-ink shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--ink)_9%,transparent),0_1px_2px_rgb(0_0_0/0.04)]",
91
+ className
92
+ ),
93
+ children: [
94
+ /* @__PURE__ */ jsx("style", { href: "asta-agent-plan", precedence: "asta", children: KEYFRAMES }),
95
+ /* @__PURE__ */ jsx("p", { className: "sr-only", "aria-live": "polite", children: live }),
96
+ /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 px-4 pb-3 pt-4", children: [
97
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-3", children: [
98
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
99
+ /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-1.5 text-[12px] text-mute", children: [
100
+ running && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "h-1.5 w-1.5 rounded-full bg-brand animate-[asta-plan-pop_1.2s_ease-in-out_infinite_alternate]" }),
101
+ /* @__PURE__ */ jsx("span", { className: cx(failedAt >= 0 && "font-medium text-ink"), children: state }),
102
+ spent > 0 && /* @__PURE__ */ jsxs("span", { className: "tabular-nums", children: [
103
+ "\xB7 ",
104
+ formatStepTime(spent)
105
+ ] })
106
+ ] }),
107
+ /* @__PURE__ */ jsx("h3", { className: "mt-0.5 text-[14.5px] font-medium leading-snug tracking-[-0.01em]", children: title })
108
+ ] }),
109
+ action
110
+ ] }),
111
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
112
+ /* @__PURE__ */ jsx("div", { className: "relative h-1 flex-1 overflow-hidden rounded-full bg-paper-2", children: /* @__PURE__ */ jsx(
113
+ "span",
114
+ {
115
+ className: cx("absolute inset-0 origin-left transition-[transform,background-color] duration-700 motion-reduce:transition-none", failedAt >= 0 ? "bg-ink" : "bg-brand"),
116
+ style: { transform: `scaleX(${total ? doneCount / total : 0})`, transitionTimingFunction: CURVE }
117
+ }
118
+ ) }),
119
+ /* @__PURE__ */ jsxs("p", { className: "shrink-0 text-[12px] tabular-nums text-mute", children: [
120
+ /* @__PURE__ */ jsx("span", { className: "font-medium text-ink", children: doneCount }),
121
+ " of ",
122
+ total
123
+ ] })
124
+ ] })
125
+ ] }),
126
+ total === 0 ? /* @__PURE__ */ jsx("p", { className: "px-4 pb-5 text-[13px] text-mute", children: "The plan shows up here once the agent has one." }) : /* @__PURE__ */ jsx("ol", { className: "flex flex-col px-2 pb-2", children: steps.map((s, i) => {
127
+ const subs = s.substeps ?? [];
128
+ const canOpen = !!s.detail || subs.length > 0;
129
+ const open = canOpen && (pinned[s.id] ?? (s.status === "running" || s.status === "failed"));
130
+ const t = elapsed(s, now);
131
+ const bodyId = `plan-${s.id}`;
132
+ const row = /* @__PURE__ */ jsxs(Fragment, { children: [
133
+ /* @__PURE__ */ jsx(StatusIcon, { status: s.status }, s.status),
134
+ /* @__PURE__ */ jsx(
135
+ "span",
136
+ {
137
+ className: cx(
138
+ "min-w-0 flex-1 text-left text-[13.5px] leading-snug [overflow-wrap:anywhere]",
139
+ s.status === "pending" && "text-mute",
140
+ s.status === "running" && "font-medium text-ink",
141
+ s.status === "done" && "text-ink-2",
142
+ s.status === "skipped" && "text-mute line-through decoration-[color-mix(in_srgb,var(--ink)_30%,transparent)]",
143
+ s.status === "failed" && "font-medium text-ink"
144
+ ),
145
+ children: s.title
146
+ }
147
+ ),
148
+ (s.status === "skipped" || s.status === "failed") && /* @__PURE__ */ jsx("span", { className: cx("shrink-0 rounded px-1.5 py-px text-[11px]", s.status === "failed" ? "bg-ink font-medium text-paper" : "bg-paper-2 text-mute"), children: WORD[s.status] }),
149
+ t !== void 0 && s.status !== "skipped" && /* @__PURE__ */ jsx("span", { className: "w-12 shrink-0 text-right text-[12px] tabular-nums text-mute", children: formatStepTime(t) }),
150
+ canOpen && /* @__PURE__ */ jsx(
151
+ "svg",
152
+ {
153
+ viewBox: "0 0 16 16",
154
+ "aria-hidden": true,
155
+ className: cx("h-3.5 w-3.5 shrink-0 text-mute transition-transform duration-300", open && "rotate-90"),
156
+ style: { transitionTimingFunction: CURVE },
157
+ fill: "none",
158
+ stroke: "currentColor",
159
+ strokeWidth: "1.7",
160
+ strokeLinecap: "round",
161
+ strokeLinejoin: "round",
162
+ children: /* @__PURE__ */ jsx("path", { d: "m6 4 4 4-4 4" })
163
+ }
164
+ )
165
+ ] });
166
+ return /* @__PURE__ */ jsxs("li", { className: "relative", children: [
167
+ i < total - 1 && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute bottom-[-6px] left-[17px] top-[30px] w-px bg-[color-mix(in_srgb,var(--ink)_10%,transparent)]" }),
168
+ canOpen ? /* @__PURE__ */ jsxs(
169
+ "button",
170
+ {
171
+ type: "button",
172
+ "aria-expanded": open,
173
+ "aria-controls": bodyId,
174
+ onClick: () => setPinned((p) => ({ ...p, [s.id]: !open })),
175
+ className: "flex min-h-10 w-full items-center gap-2.5 rounded-lg px-2 py-2 outline-none transition-colors duration-200 hover:bg-paper-2 focus-visible:ring-2 focus-visible:ring-brand/50",
176
+ children: [
177
+ row,
178
+ /* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
179
+ ", ",
180
+ WORD[s.status]
181
+ ] })
182
+ ]
183
+ }
184
+ ) : /* @__PURE__ */ jsxs("div", { className: "flex min-h-10 w-full items-center gap-2.5 px-2 py-2", children: [
185
+ row,
186
+ /* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
187
+ ", ",
188
+ WORD[s.status]
189
+ ] })
190
+ ] }),
191
+ open && /* @__PURE__ */ jsxs("div", { id: bodyId, className: "asta-plan-a flex flex-col gap-1.5 pb-2 pl-[38px] pr-2 animate-[asta-plan-in_.3s_cubic-bezier(.16,1,.3,1)_both]", children: [
192
+ s.detail && /* @__PURE__ */ jsx(
193
+ "p",
194
+ {
195
+ className: cx(
196
+ "asta-plan-a truncate text-[12px] leading-relaxed animate-[asta-plan-in_.3s_cubic-bezier(.16,1,.3,1)_both]",
197
+ s.status === "running" ? "font-mono text-mute" : s.status === "failed" ? "whitespace-normal text-ink" : "text-mute"
198
+ ),
199
+ title: s.detail,
200
+ children: s.detail
201
+ },
202
+ s.detail
203
+ ),
204
+ subs.length > 0 && /* @__PURE__ */ jsx("ul", { className: "flex flex-col gap-1", children: subs.map((x) => /* @__PURE__ */ jsxs("li", { className: "flex items-center gap-2 text-[12.5px]", children: [
205
+ /* @__PURE__ */ jsx(StatusIcon, { status: x.status, small: true }, x.status),
206
+ /* @__PURE__ */ jsx("span", { className: cx("min-w-0 flex-1 truncate", x.status === "pending" ? "text-mute" : x.status === "running" ? "text-ink" : "text-ink-2"), children: x.title }),
207
+ /* @__PURE__ */ jsxs("span", { className: "sr-only", children: [
208
+ ", ",
209
+ WORD[x.status]
210
+ ] })
211
+ ] }, x.id)) })
212
+ ] })
213
+ ] }, s.id);
214
+ }) }),
215
+ footer && /* @__PURE__ */ jsx("div", { className: "px-4 pb-4", children: footer })
216
+ ]
217
+ }
218
+ );
219
+ }
220
+ var agent_plan_default = AgentPlan;
221
+
222
+ export {
223
+ formatStepTime,
224
+ AgentPlan,
225
+ agent_plan_default
226
+ };
@@ -0,0 +1,163 @@
1
+ "use client";
2
+
3
+ // components/kit/thinking.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 CURVE = "cubic-bezier(.16,1,.3,1)";
8
+ var MASK = "linear-gradient(90deg, transparent 32%, #000 50%, transparent 68%)";
9
+ var KEYFRAMES = `@keyframes asta-thinking-sweep { from { transform: translateX(-100%) } 70%, to { transform: translateX(100%) } }
10
+ @keyframes asta-thinking-counter { from { transform: translateX(100%) } 70%, to { transform: translateX(-100%) } }
11
+ @keyframes asta-thinking-in { from { opacity: 0; transform: translateY(4px) } }
12
+ @keyframes asta-thinking-pulse { 0%, 100% { opacity: .4 } 50% { opacity: 1 } }
13
+ @media (prefers-reduced-motion: reduce) { .asta-thinking-a, .asta-thinking-a * { animation: none !important; transition-duration: 0s !important } .asta-thinking-shine { display: none } }`;
14
+ var formatThinkingTime = (s) => s < 60 ? `${s}s` : `${Math.floor(s / 60)}m ${String(s % 60).padStart(2, "0")}s`;
15
+ function useElapsed(running, el) {
16
+ const [secs, setSecs] = useState(0);
17
+ const start = useRef(null);
18
+ useEffect(() => {
19
+ if (!running) return;
20
+ if (start.current === null) start.current = Date.now();
21
+ const node = el.current;
22
+ let seen = true;
23
+ let timer;
24
+ const tick = () => setSecs(Math.floor((Date.now() - (start.current ?? Date.now())) / 1e3));
25
+ const sync = () => {
26
+ clearInterval(timer);
27
+ timer = void 0;
28
+ tick();
29
+ if (seen && !document.hidden) timer = setInterval(tick, 1e3);
30
+ };
31
+ const io = node ? new IntersectionObserver(([e]) => {
32
+ seen = e.isIntersecting;
33
+ sync();
34
+ }) : null;
35
+ if (node) io?.observe(node);
36
+ document.addEventListener("visibilitychange", sync);
37
+ sync();
38
+ return () => {
39
+ clearInterval(timer);
40
+ io?.disconnect();
41
+ document.removeEventListener("visibilitychange", sync);
42
+ tick();
43
+ };
44
+ }, [running, el]);
45
+ useEffect(() => {
46
+ if (running) return;
47
+ return () => {
48
+ start.current = null;
49
+ };
50
+ }, [running]);
51
+ return secs;
52
+ }
53
+ function Shimmer({ text, on }) {
54
+ return /* @__PURE__ */ jsxs("span", { className: cx("relative inline-block truncate", on ? "text-mute" : "text-ink"), children: [
55
+ text,
56
+ on && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "asta-thinking-shine pointer-events-none absolute inset-0 overflow-hidden", children: /* @__PURE__ */ jsx("span", { className: "absolute inset-0 animate-[asta-thinking-sweep_2.2s_linear_infinite]", style: { maskImage: MASK, WebkitMaskImage: MASK }, children: /* @__PURE__ */ jsx("span", { className: "absolute inset-0 animate-[asta-thinking-counter_2.2s_linear_infinite] whitespace-nowrap text-ink", children: text }) }) })
57
+ ] });
58
+ }
59
+ function Spark({ live, className }) {
60
+ return /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 16 16", className: cx(className, "shrink-0", live ? "animate-[asta-thinking-pulse_1.6s_ease-in-out_infinite] text-brand" : "text-mute"), fill: "currentColor", "aria-hidden": true, children: [
61
+ /* @__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" }),
62
+ /* @__PURE__ */ jsx("path", { d: "M12.5 10c.2 1.4.8 2 2.2 2.2-1.4.2-2 .8-2.2 2.2-.2-1.4-.8-2-2.2-2.2 1.4-.2 2-.8 2.2-2.2Z", opacity: ".55" })
63
+ ] });
64
+ }
65
+ function Thinking({
66
+ status = "thinking",
67
+ steps = [],
68
+ summary,
69
+ seconds,
70
+ label = "Thinking",
71
+ open,
72
+ defaultOpen = false,
73
+ onOpenChange,
74
+ variant = "block",
75
+ size = "md",
76
+ className
77
+ }) {
78
+ const id = useId();
79
+ const root = useRef(null);
80
+ const live = status === "thinking";
81
+ const own = useElapsed(live && seconds === void 0, root);
82
+ const secs = seconds ?? own;
83
+ const [inner, setInner] = useState(defaultOpen);
84
+ const isOpen = open ?? inner;
85
+ const setOpen = (next) => {
86
+ if (open === void 0) setInner(next);
87
+ onOpenChange?.(next);
88
+ };
89
+ const [prev, setPrev] = useState(status);
90
+ if (prev !== status) {
91
+ setPrev(status);
92
+ if (!live && open === void 0) setInner(false);
93
+ }
94
+ const time = formatThinkingTime(secs);
95
+ const heading = live ? label : status === "stopped" ? `Stopped after ${time}` : `Thought for ${time}`;
96
+ const sm = size === "sm";
97
+ const inline = variant === "inline";
98
+ const canOpen = !inline && steps.length > 0;
99
+ const preview = live ? steps[steps.length - 1] : summary ?? steps[steps.length - 1];
100
+ const head = /* @__PURE__ */ jsxs(Fragment, { children: [
101
+ /* @__PURE__ */ jsx(Spark, { live, className: sm ? "h-3.5 w-3.5" : "h-4 w-4" }),
102
+ /* @__PURE__ */ jsx(Shimmer, { text: heading, on: live }),
103
+ live && /* @__PURE__ */ jsx("span", { className: "shrink-0 tabular-nums text-mute", children: time }),
104
+ canOpen && /* @__PURE__ */ jsx(
105
+ "svg",
106
+ {
107
+ viewBox: "0 0 16 16",
108
+ "aria-hidden": true,
109
+ className: cx("h-3.5 w-3.5 shrink-0 text-mute transition-transform duration-300", isOpen && "rotate-90"),
110
+ style: { transitionTimingFunction: CURVE },
111
+ fill: "none",
112
+ stroke: "currentColor",
113
+ strokeWidth: "1.7",
114
+ strokeLinecap: "round",
115
+ strokeLinejoin: "round",
116
+ children: /* @__PURE__ */ jsx("path", { d: "m6 4 4 4-4 4" })
117
+ }
118
+ )
119
+ ] });
120
+ return /* @__PURE__ */ jsxs(
121
+ "div",
122
+ {
123
+ ref: root,
124
+ className: cx("asta-thinking-a min-w-0 text-ink", inline ? "inline-flex max-w-full align-middle" : "flex w-full flex-col", sm ? "text-[12.5px]" : "text-[13.5px]", className),
125
+ children: [
126
+ /* @__PURE__ */ jsx("style", { href: "asta-thinking", precedence: "asta", children: KEYFRAMES }),
127
+ /* @__PURE__ */ jsx("span", { className: "sr-only", "aria-live": "polite", children: live ? `${label}\u2026` : heading.replace(/(\d+)s$/, "$1 seconds") }),
128
+ canOpen ? /* @__PURE__ */ jsx(
129
+ "button",
130
+ {
131
+ type: "button",
132
+ "aria-expanded": isOpen,
133
+ "aria-controls": `${id}-panel`,
134
+ onClick: () => setOpen(!isOpen),
135
+ className: "-mx-1.5 flex min-w-0 max-w-full items-center gap-1.5 self-start rounded-md px-1.5 py-1 font-medium outline-none transition-colors duration-200 hover:bg-paper-2 focus-visible:ring-2 focus-visible:ring-brand/50",
136
+ children: head
137
+ }
138
+ ) : /* @__PURE__ */ jsx("span", { className: "flex min-w-0 items-center gap-1.5 py-1 font-medium", children: head }),
139
+ !inline && preview && !isOpen && /* @__PURE__ */ jsx("p", { title: preview, className: cx("asta-thinking-a truncate text-mute animate-[asta-thinking-in_.4s_cubic-bezier(.16,1,.3,1)_both]", sm ? "pl-5" : "pl-[22px]"), children: preview }, preview),
140
+ canOpen && /* @__PURE__ */ jsx(
141
+ "div",
142
+ {
143
+ id: `${id}-panel`,
144
+ inert: !isOpen,
145
+ className: cx("grid transition-[grid-template-rows,opacity] duration-300", isOpen ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0"),
146
+ style: { transitionTimingFunction: CURVE },
147
+ children: /* @__PURE__ */ jsx("div", { className: "min-h-0 overflow-hidden", children: /* @__PURE__ */ jsx("ol", { "aria-label": "Reasoning", className: "ml-[7px] mt-1 flex flex-col gap-2 pb-1 pl-[14px] shadow-[inset_1px_0_0_color-mix(in_srgb,var(--ink)_12%,transparent)]", children: steps.map((s, i) => /* @__PURE__ */ jsxs("li", { className: "asta-thinking-a leading-relaxed text-ink-2 animate-[asta-thinking-in_.45s_cubic-bezier(.16,1,.3,1)_both]", children: [
148
+ s,
149
+ live && i === steps.length - 1 && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "ml-1.5 inline-block h-1.5 w-1.5 rounded-full bg-brand align-middle animate-[asta-thinking-pulse_1.2s_ease-in-out_infinite]" })
150
+ ] }, `${i}-${s}`)) }) })
151
+ }
152
+ )
153
+ ]
154
+ }
155
+ );
156
+ }
157
+ var thinking_default = Thinking;
158
+
159
+ export {
160
+ formatThinkingTime,
161
+ Thinking,
162
+ thinking_default
163
+ };