@tangle-network/agent-app 0.52.18 → 0.53.1

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.
@@ -1,6 +1,5 @@
1
1
  import {
2
- ChatEmptyState,
3
- ChatMessages
2
+ chatToolCallPart
4
3
  } from "../chunk-2LPNGZFG.js";
5
4
  import "../chunk-FRABQIQ4.js";
6
5
  import "../chunk-3HUFJ5LO.js";
@@ -1175,6 +1174,8 @@ function useAssistantChat(userId, options) {
1175
1174
  onWorkflowMutationRef.current = options?.onWorkflowMutation;
1176
1175
  const onConnectRequirementRef = useRef(options?.onConnectRequirement);
1177
1176
  onConnectRequirementRef.current = options?.onConnectRequirement;
1177
+ const contextRef = useRef(options?.context ?? null);
1178
+ contextRef.current = options?.context ?? null;
1178
1179
  const confirmingRef = useRef(/* @__PURE__ */ new Set());
1179
1180
  const [confirmingIds, setConfirmingIds] = useState(EMPTY_IDS);
1180
1181
  const sendingRef = useRef(false);
@@ -1215,7 +1216,8 @@ function useAssistantChat(userId, options) {
1215
1216
  // null → omit, so the server applies its default model.
1216
1217
  model,
1217
1218
  threadId,
1218
- turnKey: uuid()
1219
+ turnKey: uuid(),
1220
+ ...contextRef.current ? { context: contextRef.current } : {}
1219
1221
  },
1220
1222
  (event) => {
1221
1223
  if (streamSeqRef.current === seq) dispatch({ type: "stream", event });
@@ -1699,15 +1701,29 @@ function useAssistantThreads(userId) {
1699
1701
  }
1700
1702
 
1701
1703
  // src/assistant/AssistantDock.tsx
1702
- import { MessageSquare } from "lucide-react";
1703
1704
  import {
1704
- useEffect as useEffect7,
1705
- useRef as useRef8
1705
+ useEffect as useEffect8,
1706
+ useRef as useRef9
1706
1707
  } from "react";
1707
1708
 
1708
1709
  // src/assistant/AssistantPanel.tsx
1709
- import { History, MessageSquarePlus, Minus, Plus, X } from "lucide-react";
1710
- import { useEffect as useEffect6, useLayoutEffect as useLayoutEffect2, useMemo as useMemo3, useRef as useRef6, useState as useState6 } from "react";
1710
+ import { focusRing as focusRing2 } from "@tangle-network/ui/utils";
1711
+ import {
1712
+ AlertCircle,
1713
+ AlertTriangle,
1714
+ ArrowUpRight,
1715
+ History,
1716
+ Info,
1717
+ MessageSquarePlus,
1718
+ X
1719
+ } from "lucide-react";
1720
+ import {
1721
+ useEffect as useEffect7,
1722
+ useLayoutEffect as useLayoutEffect2,
1723
+ useMemo as useMemo4,
1724
+ useRef as useRef7,
1725
+ useState as useState7
1726
+ } from "react";
1711
1727
 
1712
1728
  // src/assistant/AssistantHistory.tsx
1713
1729
  import { Search, Trash2 } from "lucide-react";
@@ -1887,8 +1903,273 @@ function AssistantHistory({
1887
1903
  ] });
1888
1904
  }
1889
1905
 
1906
+ // src/assistant/panel-toggle.tsx
1907
+ import { focusRing } from "@tangle-network/ui/utils";
1908
+ import { PanelRight } from "lucide-react";
1909
+
1910
+ // src/assistant/launcher.tsx
1911
+ import {
1912
+ createContext as createContext2,
1913
+ useCallback as useCallback4,
1914
+ useContext as useContext2,
1915
+ useEffect as useEffect5,
1916
+ useMemo as useMemo2,
1917
+ useRef as useRef4,
1918
+ useState as useState5
1919
+ } from "react";
1920
+
1921
+ // src/assistant/usePanelPrefs.ts
1922
+ import { useCallback as useCallback3, useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
1923
+ var MIN_PANEL_WIDTH = 360;
1924
+ var DEFAULT_PANEL_WIDTH = 480;
1925
+ var MAX_PANEL_WIDTH = 800;
1926
+ var MAX_PANEL_WIDTH_FRACTION = 0.5;
1927
+ var DOCKED_MEDIA_QUERY = "(min-width: 80rem)";
1928
+ var LEGACY_WIDTH_KEY = "assistant.panel.width";
1929
+ function prefsKey(userId) {
1930
+ return userId ? `assistant:v1:${userId}:panel` : null;
1931
+ }
1932
+ function readPrefs(userId) {
1933
+ const key = prefsKey(userId);
1934
+ if (!key) return {};
1935
+ try {
1936
+ const raw = window.localStorage.getItem(key);
1937
+ const parsed = raw ? JSON.parse(raw) : {};
1938
+ const legacy = Number(window.localStorage.getItem(LEGACY_WIDTH_KEY) ?? "");
1939
+ const width = typeof parsed.width === "number" && Number.isFinite(parsed.width) ? parsed.width : Number.isFinite(legacy) && legacy > 0 ? legacy : void 0;
1940
+ return {
1941
+ ...typeof parsed.open === "boolean" ? { open: parsed.open } : {},
1942
+ ...width !== void 0 ? { width } : {}
1943
+ };
1944
+ } catch {
1945
+ return {};
1946
+ }
1947
+ }
1948
+ function writePrefs(userId, next) {
1949
+ const key = prefsKey(userId);
1950
+ if (!key) return;
1951
+ try {
1952
+ const current = readPrefs(userId);
1953
+ window.localStorage.setItem(key, JSON.stringify({ ...current, ...next }));
1954
+ } catch {
1955
+ }
1956
+ }
1957
+ function maxPanelWidth() {
1958
+ if (typeof window === "undefined") return MAX_PANEL_WIDTH;
1959
+ return Math.max(
1960
+ MIN_PANEL_WIDTH,
1961
+ Math.min(
1962
+ Math.round(window.innerWidth * MAX_PANEL_WIDTH_FRACTION),
1963
+ MAX_PANEL_WIDTH
1964
+ )
1965
+ );
1966
+ }
1967
+ function clampWidth(value) {
1968
+ return Math.min(
1969
+ Math.max(Math.round(value), MIN_PANEL_WIDTH),
1970
+ maxPanelWidth()
1971
+ );
1972
+ }
1973
+ function usePanelPrefs(userId) {
1974
+ const [storedOpen, setStoredOpen] = useState4(null);
1975
+ const [width, setWidthState] = useState4(DEFAULT_PANEL_WIDTH);
1976
+ const [maxWidth, setMaxWidth] = useState4(() => maxPanelWidth());
1977
+ const desiredRef = useRef3(DEFAULT_PANEL_WIDTH);
1978
+ const userRef = useRef3(userId);
1979
+ userRef.current = userId;
1980
+ useEffect4(() => {
1981
+ const prefs = readPrefs(userId);
1982
+ setStoredOpen(prefs.open ?? null);
1983
+ desiredRef.current = Math.max(
1984
+ Math.round(prefs.width ?? DEFAULT_PANEL_WIDTH),
1985
+ MIN_PANEL_WIDTH
1986
+ );
1987
+ setMaxWidth(maxPanelWidth());
1988
+ setWidthState(clampWidth(desiredRef.current));
1989
+ }, [userId]);
1990
+ useEffect4(() => {
1991
+ const onResize = () => {
1992
+ setMaxWidth(maxPanelWidth());
1993
+ setWidthState(clampWidth(desiredRef.current));
1994
+ };
1995
+ window.addEventListener("resize", onResize);
1996
+ return () => window.removeEventListener("resize", onResize);
1997
+ }, []);
1998
+ const persistOpen = useCallback3((open) => {
1999
+ setStoredOpen(open);
2000
+ writePrefs(userRef.current, { open });
2001
+ }, []);
2002
+ const setWidth = useCallback3((next) => {
2003
+ const clamped = clampWidth(next);
2004
+ desiredRef.current = clamped;
2005
+ writePrefs(userRef.current, { width: clamped });
2006
+ setWidthState(clamped);
2007
+ }, []);
2008
+ const previewWidth = useCallback3((next) => {
2009
+ setWidthState(clampWidth(next));
2010
+ }, []);
2011
+ const nudgeWidth = useCallback3((deltaPx) => {
2012
+ const clamped = clampWidth(desiredRef.current + deltaPx);
2013
+ desiredRef.current = clamped;
2014
+ writePrefs(userRef.current, { width: clamped });
2015
+ setWidthState(clamped);
2016
+ }, []);
2017
+ return {
2018
+ storedOpen,
2019
+ persistOpen,
2020
+ width,
2021
+ maxWidth,
2022
+ setWidth,
2023
+ previewWidth,
2024
+ nudgeWidth
2025
+ };
2026
+ }
2027
+ function useMediaQuery(query, fallback = true) {
2028
+ const [matches, setMatches] = useState4(
2029
+ () => typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia(query).matches : fallback
2030
+ );
2031
+ useEffect4(() => {
2032
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
2033
+ return;
2034
+ }
2035
+ const mq = window.matchMedia(query);
2036
+ const update = () => setMatches(mq.matches);
2037
+ update();
2038
+ mq.addEventListener("change", update);
2039
+ return () => mq.removeEventListener("change", update);
2040
+ }, [query]);
2041
+ return matches;
2042
+ }
2043
+
2044
+ // src/assistant/launcher.tsx
2045
+ import { jsx as jsx3 } from "react/jsx-runtime";
2046
+ var AssistantLauncherContext = createContext2(null);
2047
+ function AssistantLauncherProvider({
2048
+ userId = null,
2049
+ children
2050
+ }) {
2051
+ const [open, setOpen] = useState5(false);
2052
+ const [seed, setSeed] = useState5(null);
2053
+ const [openedOnLoad, setOpenedOnLoad] = useState5(false);
2054
+ const prefs = usePanelPrefs(userId);
2055
+ const docked = useMediaQuery(DOCKED_MEDIA_QUERY, true);
2056
+ const layout = docked ? "docked" : "sheet";
2057
+ const { persistOpen, storedOpen } = prefs;
2058
+ const restoredFor = useRef4(null);
2059
+ useEffect5(() => {
2060
+ if (!userId || restoredFor.current === userId || storedOpen === null) return;
2061
+ restoredFor.current = userId;
2062
+ if (storedOpen && docked) {
2063
+ setOpenedOnLoad(true);
2064
+ setOpen(true);
2065
+ }
2066
+ }, [userId, storedOpen, docked]);
2067
+ const openAssistant = useCallback4(
2068
+ (next) => {
2069
+ if (next != null) setSeed(next);
2070
+ setOpenedOnLoad(false);
2071
+ setOpen(true);
2072
+ persistOpen(true);
2073
+ },
2074
+ [persistOpen]
2075
+ );
2076
+ const closeAssistant = useCallback4(() => {
2077
+ setOpen(false);
2078
+ persistOpen(false);
2079
+ }, [persistOpen]);
2080
+ const toggleAssistant = useCallback4(() => {
2081
+ setOpenedOnLoad(false);
2082
+ setOpen(!open);
2083
+ persistOpen(!open);
2084
+ }, [open, persistOpen]);
2085
+ const clearSeed = useCallback4(() => setSeed(null), []);
2086
+ const { width, maxWidth, setWidth, previewWidth, nudgeWidth } = prefs;
2087
+ const panel = useMemo2(
2088
+ () => ({ width, maxWidth, setWidth, previewWidth, nudgeWidth }),
2089
+ [width, maxWidth, setWidth, previewWidth, nudgeWidth]
2090
+ );
2091
+ const inset = open && docked ? width : 0;
2092
+ const value = useMemo2(
2093
+ () => ({
2094
+ open,
2095
+ seed,
2096
+ openAssistant,
2097
+ closeAssistant,
2098
+ toggleAssistant,
2099
+ clearSeed,
2100
+ layout,
2101
+ openedOnLoad,
2102
+ inset,
2103
+ panel
2104
+ }),
2105
+ [
2106
+ open,
2107
+ seed,
2108
+ openAssistant,
2109
+ closeAssistant,
2110
+ toggleAssistant,
2111
+ clearSeed,
2112
+ layout,
2113
+ openedOnLoad,
2114
+ inset,
2115
+ panel
2116
+ ]
2117
+ );
2118
+ return /* @__PURE__ */ jsx3(AssistantLauncherContext.Provider, { value, children });
2119
+ }
2120
+ function useOptionalAssistantLauncher() {
2121
+ return useContext2(AssistantLauncherContext);
2122
+ }
2123
+ function useAssistantLauncher() {
2124
+ const ctx = useContext2(AssistantLauncherContext);
2125
+ if (!ctx) {
2126
+ throw new Error(
2127
+ "useAssistantLauncher must be used within an AssistantLauncherProvider"
2128
+ );
2129
+ }
2130
+ return ctx;
2131
+ }
2132
+
2133
+ // src/assistant/panel-toggle.tsx
2134
+ import { jsx as jsx4 } from "react/jsx-runtime";
2135
+ var ASSISTANT_PANEL_ID = "assistant-panel";
2136
+ function isApplePlatform() {
2137
+ return typeof navigator !== "undefined" && /Mac|iPhone|iPad|iPod/.test(navigator.platform ?? "");
2138
+ }
2139
+ function assistantShortcutLabel() {
2140
+ return isApplePlatform() ? "\u2318E" : "Ctrl+E";
2141
+ }
2142
+ function AssistantPanelToggle({
2143
+ open: openOverride,
2144
+ onToggle,
2145
+ className,
2146
+ style,
2147
+ buttonRef
2148
+ }) {
2149
+ const launcher = useOptionalAssistantLauncher();
2150
+ const open = openOverride ?? launcher?.open ?? false;
2151
+ const toggleAssistant = onToggle ?? launcher?.toggleAssistant;
2152
+ const label = open ? "Close assistant" : "Open assistant";
2153
+ return /* @__PURE__ */ jsx4(
2154
+ "button",
2155
+ {
2156
+ ref: buttonRef,
2157
+ type: "button",
2158
+ onClick: () => toggleAssistant?.(),
2159
+ "aria-label": label,
2160
+ "aria-expanded": open,
2161
+ "aria-controls": open && launcher ? ASSISTANT_PANEL_ID : void 0,
2162
+ "aria-keyshortcuts": "Meta+E Control+E",
2163
+ title: `${label} (${assistantShortcutLabel()})`,
2164
+ style,
2165
+ className: `flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-[var(--accent-surface-soft)] hover:text-foreground ${focusRing} ${className ?? ""}`,
2166
+ children: /* @__PURE__ */ jsx4(PanelRight, { "aria-hidden": "true", className: "h-[18px] w-[18px] shrink-0" })
2167
+ }
2168
+ );
2169
+ }
2170
+
1890
2171
  // src/assistant/ProposalCard.tsx
1891
- import { useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
2172
+ import { useEffect as useEffect6, useRef as useRef5, useState as useState6 } from "react";
1892
2173
  import { ProviderIcon } from "@tangle-network/sandbox-ui/integrations";
1893
2174
 
1894
2175
  // src/assistant/provider-label.ts
@@ -1907,7 +2188,7 @@ function providerLabel(provider) {
1907
2188
  }
1908
2189
 
1909
2190
  // src/assistant/ProposalCard.tsx
1910
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
2191
+ import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
1911
2192
  var EYEBROW_CLASS = "text-xs font-semibold uppercase tracking-[0.05em] text-muted-foreground";
1912
2193
  function ProposalCard({
1913
2194
  proposal,
@@ -1920,20 +2201,20 @@ function ProposalCard({
1920
2201
  renderProviderIcon
1921
2202
  }) {
1922
2203
  const view = describeProposal(proposal);
1923
- const [tab, setTab] = useState4("graph");
2204
+ const [tab, setTab] = useState6("graph");
1924
2205
  const isWorkflow = view.preview?.kind === "workflow";
1925
2206
  const showGraph = isWorkflow && !!renderGraph;
1926
2207
  const requirements = proposal.requirements ?? [];
1927
2208
  return /* @__PURE__ */ jsxs2("div", { className: "rounded-lg border border-primary/40 bg-card p-3 text-sm", children: [
1928
- /* @__PURE__ */ jsx3("p", { className: "font-semibold text-[15px] text-foreground", children: view.title }),
1929
- view.fields.length > 0 && /* @__PURE__ */ jsx3("dl", { className: "mt-2 space-y-1", children: view.fields.map((f) => /* @__PURE__ */ jsxs2("div", { className: "grid grid-cols-[auto_1fr] gap-x-3 text-xs", children: [
1930
- /* @__PURE__ */ jsx3("dt", { className: "text-muted-foreground", children: f.label }),
1931
- /* @__PURE__ */ jsx3("dd", { className: "truncate text-foreground", title: f.value, children: f.value })
2209
+ /* @__PURE__ */ jsx5("p", { className: "font-semibold text-[15px] text-foreground", children: view.title }),
2210
+ view.fields.length > 0 && /* @__PURE__ */ jsx5("dl", { className: "mt-2 space-y-1", children: view.fields.map((f) => /* @__PURE__ */ jsxs2("div", { className: "grid grid-cols-[auto_1fr] gap-x-3 text-xs", children: [
2211
+ /* @__PURE__ */ jsx5("dt", { className: "text-muted-foreground", children: f.label }),
2212
+ /* @__PURE__ */ jsx5("dd", { className: "truncate text-foreground", title: f.value, children: f.value })
1932
2213
  ] }, f.label)) }),
1933
2214
  view.skills && view.skills.length > 0 && /* @__PURE__ */ jsxs2("div", { className: "mt-2", children: [
1934
- /* @__PURE__ */ jsx3("p", { className: EYEBROW_CLASS, children: "New skills" }),
1935
- /* @__PURE__ */ jsx3("ul", { className: "mt-1 space-y-0.5", children: view.skills.map((s) => /* @__PURE__ */ jsxs2("li", { className: "text-foreground text-xs", children: [
1936
- /* @__PURE__ */ jsx3("span", { className: "font-medium", children: s.name }),
2215
+ /* @__PURE__ */ jsx5("p", { className: EYEBROW_CLASS, children: "New skills" }),
2216
+ /* @__PURE__ */ jsx5("ul", { className: "mt-1 space-y-0.5", children: view.skills.map((s) => /* @__PURE__ */ jsxs2("li", { className: "text-foreground text-xs", children: [
2217
+ /* @__PURE__ */ jsx5("span", { className: "font-medium", children: s.name }),
1937
2218
  s.description ? /* @__PURE__ */ jsxs2("span", { className: "text-muted-foreground", children: [
1938
2219
  " \u2014 ",
1939
2220
  s.description
@@ -1942,9 +2223,9 @@ function ProposalCard({
1942
2223
  ] }),
1943
2224
  view.preview && /* @__PURE__ */ jsxs2("div", { className: "mt-2", children: [
1944
2225
  /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between", children: [
1945
- /* @__PURE__ */ jsx3("p", { className: EYEBROW_CLASS, children: view.preview.label }),
2226
+ /* @__PURE__ */ jsx5("p", { className: EYEBROW_CLASS, children: view.preview.label }),
1946
2227
  showGraph && /* @__PURE__ */ jsxs2("div", { className: "flex gap-2 text-xs", children: [
1947
- /* @__PURE__ */ jsx3(
2228
+ /* @__PURE__ */ jsx5(
1948
2229
  "button",
1949
2230
  {
1950
2231
  type: "button",
@@ -1954,7 +2235,7 @@ function ProposalCard({
1954
2235
  children: "Graph"
1955
2236
  }
1956
2237
  ),
1957
- /* @__PURE__ */ jsx3(
2238
+ /* @__PURE__ */ jsx5(
1958
2239
  "button",
1959
2240
  {
1960
2241
  type: "button",
@@ -1966,16 +2247,16 @@ function ProposalCard({
1966
2247
  )
1967
2248
  ] })
1968
2249
  ] }),
1969
- showGraph && tab === "graph" ? /* @__PURE__ */ jsx3("div", { className: "mt-1 h-64 overflow-hidden rounded border border-border", children: renderGraph?.(view.preview.content) }) : (
2250
+ showGraph && tab === "graph" ? /* @__PURE__ */ jsx5("div", { className: "mt-1 h-64 overflow-hidden rounded border border-border", children: renderGraph?.(view.preview.content) }) : (
1970
2251
  // max-h fits a whole number of lines at text-xs' 16px leading —
1971
2252
  // 1px border + 8px top padding, 12 lines = 202px — so the scroll
1972
2253
  // cut lands on a line boundary, never mid-glyph.
1973
- /* @__PURE__ */ jsx3("pre", { className: "mt-1 max-h-[202px] overflow-auto rounded border border-border bg-secondary p-2 font-mono text-xs tabular-nums", children: /* @__PURE__ */ jsx3("code", { children: view.preview.content }) })
2254
+ /* @__PURE__ */ jsx5("pre", { className: "mt-1 max-h-[202px] overflow-auto rounded border border-border bg-secondary p-2 font-mono text-xs tabular-nums", children: /* @__PURE__ */ jsx5("code", { children: view.preview.content }) })
1974
2255
  )
1975
2256
  ] }),
1976
2257
  requirements.length > 0 && /* @__PURE__ */ jsxs2("div", { className: "mt-3 rounded border border-border p-2", children: [
1977
- /* @__PURE__ */ jsx3("p", { className: EYEBROW_CLASS, children: "Integrations" }),
1978
- /* @__PURE__ */ jsx3("ul", { className: "mt-1 space-y-1", children: requirements.map((r) => /* @__PURE__ */ jsx3(
2258
+ /* @__PURE__ */ jsx5("p", { className: EYEBROW_CLASS, children: "Integrations" }),
2259
+ /* @__PURE__ */ jsx5("ul", { className: "mt-1 space-y-1", children: requirements.map((r) => /* @__PURE__ */ jsx5(
1979
2260
  RequirementRow,
1980
2261
  {
1981
2262
  req: r,
@@ -1986,11 +2267,11 @@ function ProposalCard({
1986
2267
  },
1987
2268
  `${r.provider}-${requirementKind(r)}`
1988
2269
  )) }),
1989
- /* @__PURE__ */ jsx3("p", { className: "mt-1 text-muted-foreground text-xs", children: "Connect the items above, then confirm." })
2270
+ /* @__PURE__ */ jsx5("p", { className: "mt-1 text-muted-foreground text-xs", children: "Connect the items above, then confirm." })
1990
2271
  ] }),
1991
- proposal.retryError && /* @__PURE__ */ jsx3("p", { role: "alert", className: "mt-2 text-destructive text-xs", children: proposal.retryError }),
2272
+ proposal.retryError && /* @__PURE__ */ jsx5("p", { role: "alert", className: "mt-2 text-destructive text-xs", children: proposal.retryError }),
1992
2273
  /* @__PURE__ */ jsxs2("div", { className: "mt-3 flex gap-2", children: [
1993
- /* @__PURE__ */ jsx3(
2274
+ /* @__PURE__ */ jsx5(
1994
2275
  "button",
1995
2276
  {
1996
2277
  type: "button",
@@ -2000,7 +2281,7 @@ function ProposalCard({
2000
2281
  children: confirming ? "Confirming\u2026" : "Confirm"
2001
2282
  }
2002
2283
  ),
2003
- /* @__PURE__ */ jsx3(
2284
+ /* @__PURE__ */ jsx5(
2004
2285
  "button",
2005
2286
  {
2006
2287
  type: "button",
@@ -2052,9 +2333,9 @@ function RequirementRow({
2052
2333
  onConnect,
2053
2334
  renderProviderIcon
2054
2335
  }) {
2055
- const [connecting, setConnecting] = useState4(false);
2056
- const mountedRef = useRef3(true);
2057
- useEffect4(() => {
2336
+ const [connecting, setConnecting] = useState6(false);
2337
+ const mountedRef = useRef5(true);
2338
+ useEffect6(() => {
2058
2339
  mountedRef.current = true;
2059
2340
  return () => {
2060
2341
  mountedRef.current = false;
@@ -2092,7 +2373,7 @@ function RequirementRow({
2092
2373
  }
2093
2374
  return /* @__PURE__ */ jsxs2("li", { className: "flex items-center justify-between gap-2 text-sm", children: [
2094
2375
  /* @__PURE__ */ jsxs2("span", { className: "flex min-w-0 items-center gap-2", children: [
2095
- providerIcon ?? /* @__PURE__ */ jsx3(
2376
+ providerIcon ?? /* @__PURE__ */ jsx5(
2096
2377
  ProviderIcon,
2097
2378
  {
2098
2379
  id: req.provider,
@@ -2100,16 +2381,16 @@ function RequirementRow({
2100
2381
  className: "rounded-[4px]"
2101
2382
  }
2102
2383
  ),
2103
- /* @__PURE__ */ jsx3("span", { className: "truncate font-medium text-foreground", children: kindLabel }),
2384
+ /* @__PURE__ */ jsx5("span", { className: "truncate font-medium text-foreground", children: kindLabel }),
2104
2385
  /* @__PURE__ */ jsxs2("span", { className: "flex shrink-0 items-center gap-1", children: [
2105
- /* @__PURE__ */ jsx3(
2386
+ /* @__PURE__ */ jsx5(
2106
2387
  "span",
2107
2388
  {
2108
2389
  "aria-hidden": "true",
2109
2390
  className: `h-1.5 w-1.5 rounded-full ${req.connected ? "bg-primary" : "border border-muted-foreground"}`
2110
2391
  }
2111
2392
  ),
2112
- /* @__PURE__ */ jsx3(
2393
+ /* @__PURE__ */ jsx5(
2113
2394
  "span",
2114
2395
  {
2115
2396
  className: req.connected ? "text-primary" : "text-muted-foreground",
@@ -2121,8 +2402,8 @@ function RequirementRow({
2121
2402
  blockedBy && !req.connected && // Named rather than silent: a row with no affordance and no reason reads
2122
2403
  // as broken. The step it waits on is the row above (the server lists a
2123
2404
  // prerequisite first), so this points at something already on screen.
2124
- /* @__PURE__ */ jsx3("span", { className: "shrink-0 text-muted-foreground text-xs", children: blockedNote(blockedBy) }),
2125
- canConnect && /* @__PURE__ */ jsx3(
2405
+ /* @__PURE__ */ jsx5("span", { className: "shrink-0 text-muted-foreground text-xs", children: blockedNote(blockedBy) }),
2406
+ canConnect && /* @__PURE__ */ jsx5(
2126
2407
  "button",
2127
2408
  {
2128
2409
  type: "button",
@@ -2136,9 +2417,12 @@ function RequirementRow({
2136
2417
  }
2137
2418
 
2138
2419
  // src/assistant/transcript.tsx
2139
- import { Check } from "lucide-react";
2140
- import { useCallback as useCallback3, useMemo as useMemo2 } from "react";
2141
- import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
2420
+ import {
2421
+ AgentTimeline
2422
+ } from "@tangle-network/ui/chat";
2423
+ import { InlineThinkingItem, InlineToolItem } from "@tangle-network/ui/run";
2424
+ import { useMemo as useMemo3 } from "react";
2425
+ import { Fragment, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
2142
2426
  function assistantIsThinking(state) {
2143
2427
  if (state.status !== "streaming") return false;
2144
2428
  const streaming = state.streamingId ? state.messages.find((m) => m.id === state.streamingId) : void 0;
@@ -2153,314 +2437,132 @@ function adaptToolResult(outcome) {
2153
2437
  if (outcome.ok) return { ok: true, result: outcome.result };
2154
2438
  return { ok: false, message: outcome.error?.message, code: outcome.error?.code };
2155
2439
  }
2156
- function adaptTranscript(view) {
2157
- const blocks = [];
2158
- const confirmedResults = /* @__PURE__ */ new Map();
2159
- let run = [];
2160
- const flushRun = () => {
2161
- if (run.length > 0) blocks.push({ kind: "run", messages: run });
2162
- run = [];
2163
- };
2164
- let turn = null;
2165
- let currentTurnAssistant = null;
2166
- const openTurn = (id) => {
2167
- const message = { id, role: "assistant", content: "", segments: [] };
2168
- run.push(message);
2169
- turn = message;
2170
- currentTurnAssistant = message;
2171
- return message;
2172
- };
2173
- const appendText = (message, text) => {
2174
- if (!text.trim()) return;
2175
- message.segments.push({ kind: "text", content: text });
2176
- message.content = message.content ? `${message.content}
2177
-
2178
- ${text}` : text;
2179
- };
2180
- for (const msg of view.messages) {
2181
- if (msg.role === "user") {
2182
- run.push({ id: msg.id, role: "user", content: msg.text });
2183
- turn = null;
2184
- currentTurnAssistant = null;
2185
- } else if (msg.role === "assistant") {
2186
- const active = turn ?? openTurn(msg.id);
2187
- appendText(active, msg.text);
2188
- currentTurnAssistant = active;
2189
- } else if (msg.role === "tool") {
2190
- if (!msg.tool) continue;
2191
- const active = turn ?? openTurn(`turn-${msg.id}`);
2192
- currentTurnAssistant = active;
2193
- active.segments.push({
2194
- kind: "tool",
2195
- call: {
2196
- id: msg.id,
2197
- name: msg.tool.name,
2198
- // An unmapped status resolves to "error", not "running": a stuck
2199
- // spinner would hide a finished or failed tool.
2200
- status: TOOL_STATUS[msg.tool.status] ?? "error",
2201
- ...msg.tool.args ? { args: msg.tool.args } : {},
2202
- ...msg.tool.outcome ? { result: adaptToolResult(msg.tool.outcome) } : {}
2203
- }
2204
- });
2205
- } else {
2206
- flushRun();
2207
- blocks.push({ kind: "status", id: msg.id, text: msg.text });
2208
- if (msg.result) confirmedResults.set(msg.id, msg.result);
2209
- turn = null;
2210
- }
2211
- }
2212
- let proposalHostId = null;
2213
- if (view.pendingProposals.length > 0) {
2214
- if (!currentTurnAssistant) {
2215
- currentTurnAssistant = openTurn(
2216
- `proposal-host-${view.pendingProposals[0].callId}`
2217
- );
2218
- }
2219
- proposalHostId = currentTurnAssistant.id;
2220
- }
2221
- if (currentTurnAssistant) {
2222
- if (view.reasoning) currentTurnAssistant.reasoning = view.reasoning;
2223
- if (view.model) currentTurnAssistant.modelUsed = view.model;
2224
- if (view.usage) {
2225
- if (view.usage.completionTokens != null)
2226
- currentTurnAssistant.completionTokens = view.usage.completionTokens;
2227
- if (view.usage.promptTokens != null)
2228
- currentTurnAssistant.promptTokens = view.usage.promptTokens;
2229
- if (view.usage.durationMs != null)
2230
- currentTurnAssistant.durationMs = view.usage.durationMs;
2231
- }
2232
- }
2233
- flushRun();
2234
- const isEmptyShell = (m) => m.role === "assistant" && m.content === "" && (m.segments?.length ?? 0) === 0 && m.reasoning == null && m.modelUsed == null && m.completionTokens == null && m.promptTokens == null && m.durationMs == null && m.id !== proposalHostId;
2235
- const kept = [];
2236
- const messages = [];
2237
- for (const block of blocks) {
2238
- if (block.kind === "status") {
2239
- kept.push(block);
2240
- continue;
2241
- }
2242
- const visible = block.messages.filter((m) => !isEmptyShell(m));
2243
- if (visible.length > 0) {
2244
- kept.push({ kind: "run", messages: visible });
2245
- messages.push(...visible);
2246
- }
2247
- }
2440
+ function toolCallOf(message) {
2441
+ if (!message.tool) return null;
2248
2442
  return {
2249
- blocks: kept,
2250
- messages,
2251
- proposalHostId,
2252
- metricsHostId: currentTurnAssistant && !isEmptyShell(currentTurnAssistant) ? currentTurnAssistant.id : null,
2253
- confirmedResults
2443
+ id: message.id,
2444
+ name: message.tool.name,
2445
+ // An unmapped status resolves to "error", never "running": a stuck
2446
+ // spinner would hide a finished or failed tool.
2447
+ status: TOOL_STATUS[message.tool.status] ?? "error",
2448
+ ...message.tool.args ? { args: message.tool.args } : {},
2449
+ ...message.tool.outcome ? { result: adaptToolResult(message.tool.outcome) } : {}
2254
2450
  };
2255
2451
  }
2452
+ function toolTitle(name) {
2453
+ const words = name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").trim();
2454
+ return words ? words.charAt(0).toUpperCase() + words.slice(1) : name;
2455
+ }
2256
2456
  function formatTurnCost(costUsd) {
2257
2457
  return costUsd < 0.01 ? `$${costUsd.toFixed(4)}` : `$${costUsd.toFixed(2)}`;
2258
2458
  }
2259
- function ProposalSlot({
2260
- proposal,
2261
- render
2262
- }) {
2263
- return /* @__PURE__ */ jsx4(Fragment, { children: render(proposal) });
2459
+ function ProseAligned({ children }) {
2460
+ return /* @__PURE__ */ jsx6("div", { className: "mx-3", children });
2264
2461
  }
2265
- function StatusRow({
2266
- text,
2267
- result,
2268
- renderConfirmedResult
2269
- }) {
2270
- const confirmed = result && renderConfirmedResult ? renderConfirmedResult(result) : null;
2271
- return /* @__PURE__ */ jsxs3("div", { className: "mx-auto w-full max-w-3xl px-6 py-1", children: [
2272
- /* @__PURE__ */ jsxs3("p", { className: "flex items-center justify-center gap-1.5 text-center text-muted-foreground text-xs", children: [
2273
- /* @__PURE__ */ jsx4(Check, { "aria-hidden": "true", className: "h-3.5 w-3.5 shrink-0" }),
2274
- text
2275
- ] }),
2276
- confirmed ? /* @__PURE__ */ jsx4("div", { className: "mt-3", children: confirmed }) : null
2277
- ] });
2462
+ function buildAssistantTimeline(view, options = {}) {
2463
+ const items = [];
2464
+ let lastUser = -1;
2465
+ view.messages.forEach((m, i) => {
2466
+ if (m.role === "user") lastUser = i;
2467
+ });
2468
+ view.messages.forEach((message, index) => {
2469
+ if (message.role === "user") {
2470
+ items.push({ id: message.id, kind: "message", role: "user", content: message.text });
2471
+ if (index === lastUser && view.reasoning) {
2472
+ items.push({
2473
+ id: `${message.id}-reasoning`,
2474
+ kind: "custom",
2475
+ content: /* @__PURE__ */ jsx6(
2476
+ InlineThinkingItem,
2477
+ {
2478
+ part: { type: "reasoning", text: view.reasoning },
2479
+ defaultOpen: view.isStreaming
2480
+ }
2481
+ )
2482
+ });
2483
+ }
2484
+ return;
2485
+ }
2486
+ if (message.role === "assistant") {
2487
+ if (!message.text.trim()) return;
2488
+ items.push({
2489
+ id: message.id,
2490
+ kind: "message",
2491
+ role: "assistant",
2492
+ content: message.text,
2493
+ isStreaming: view.isStreaming && message.id === view.streamingId
2494
+ });
2495
+ return;
2496
+ }
2497
+ if (message.role === "tool") {
2498
+ const call = toolCallOf(message);
2499
+ if (!call) return;
2500
+ const renderer = options.toolRenderers?.[call.name];
2501
+ const host = { id: message.id, role: "assistant", content: "" };
2502
+ items.push({
2503
+ id: message.id,
2504
+ kind: "custom",
2505
+ content: /* @__PURE__ */ jsx6(
2506
+ InlineToolItem,
2507
+ {
2508
+ part: chatToolCallPart(call),
2509
+ title: toolTitle(call.name),
2510
+ renderToolDetail: renderer ? () => renderer(call, host) : void 0
2511
+ }
2512
+ )
2513
+ });
2514
+ return;
2515
+ }
2516
+ items.push({ id: message.id, kind: "status", label: message.text, tone: "success" });
2517
+ const card = message.result && options.renderConfirmedResult ? options.renderConfirmedResult(message.result) : null;
2518
+ if (card) {
2519
+ items.push({
2520
+ id: `${message.id}-result`,
2521
+ kind: "custom",
2522
+ content: /* @__PURE__ */ jsx6(ProseAligned, { children: card })
2523
+ });
2524
+ }
2525
+ });
2526
+ for (const proposal of view.pendingProposals) {
2527
+ items.push({
2528
+ id: `proposal-${proposal.callId}`,
2529
+ kind: "custom",
2530
+ content: /* @__PURE__ */ jsx6(ProseAligned, { children: view.renderProposal(proposal) })
2531
+ });
2532
+ }
2533
+ if (lastUser >= 0 && !view.isStreaming && view.usage?.costUsd != null && !view.usage.replayed) {
2534
+ items.push({
2535
+ id: "turn-cost",
2536
+ kind: "custom",
2537
+ content: /* @__PURE__ */ jsx6(ProseAligned, { children: /* @__PURE__ */ jsxs3("p", { className: "text-muted-foreground text-xs tabular-nums", children: [
2538
+ formatTurnCost(view.usage.costUsd),
2539
+ " this turn"
2540
+ ] }) })
2541
+ });
2542
+ }
2543
+ return items;
2278
2544
  }
2279
2545
  function AssistantTranscript({
2280
2546
  view,
2281
- renderMarkdown,
2282
2547
  toolRenderers,
2283
2548
  renderConfirmedResult,
2284
2549
  emptyState
2285
2550
  }) {
2286
- const { blocks, proposalHostId, metricsHostId, confirmedResults } = useMemo2(
2287
- () => adaptTranscript(view),
2288
- [view]
2289
- );
2290
- const markdown = useCallback3(
2291
- (content) => renderMarkdown ? renderMarkdown(content) : content,
2292
- [renderMarkdown]
2293
- );
2294
- if (blocks.length === 0 && !view.isStreaming) {
2295
- return /* @__PURE__ */ jsx4(Fragment, { children: emptyState });
2296
- }
2297
- const extras = (message) => {
2298
- const proposals = message.id === proposalHostId && view.pendingProposals.length > 0 ? /* @__PURE__ */ jsx4("div", { className: "mt-3 flex flex-col gap-3", children: view.pendingProposals.map((proposal) => /* @__PURE__ */ jsx4(
2299
- ProposalSlot,
2300
- {
2301
- proposal,
2302
- render: view.renderProposal
2303
- },
2304
- proposal.callId
2305
- )) }) : null;
2306
- const cost = message.id === metricsHostId && !view.isStreaming && view.usage?.costUsd != null && !view.usage.replayed ? /* @__PURE__ */ jsxs3("p", { className: "mt-1 text-xs text-muted-foreground", children: [
2307
- formatTurnCost(view.usage.costUsd),
2308
- " this turn"
2309
- ] }) : null;
2310
- if (!proposals && !cost) return null;
2311
- return /* @__PURE__ */ jsxs3(Fragment, { children: [
2312
- proposals,
2313
- cost
2314
- ] });
2315
- };
2316
- return /* @__PURE__ */ jsx4(Fragment, { children: blocks.map(
2317
- (block, i) => block.kind === "status" ? /* @__PURE__ */ jsx4(
2318
- StatusRow,
2319
- {
2320
- text: block.text,
2321
- result: confirmedResults.get(block.id),
2322
- renderConfirmedResult
2323
- },
2324
- block.id
2325
- ) : /* @__PURE__ */ jsx4(
2326
- ChatMessages,
2327
- {
2328
- messages: block.messages,
2329
- loading: view.isStreaming && i === blocks.length - 1,
2330
- agentLabel: "Assistant",
2331
- chrome: "quiet",
2332
- renderMarkdown: markdown,
2333
- toolRenderers,
2334
- renderExtras: extras
2335
- },
2336
- i
2337
- )
2338
- ) });
2339
- }
2340
-
2341
- // src/assistant/usePanelPrefs.ts
2342
- import { useCallback as useCallback4, useEffect as useEffect5, useRef as useRef4, useState as useState5 } from "react";
2343
- var MIN_PANEL_WIDTH = 360;
2344
- var DEFAULT_PANEL_WIDTH = 448;
2345
- var MAX_PANEL_WIDTH_FRACTION = 0.95;
2346
- var MIN_FONT_SCALE = 0.875;
2347
- var MAX_FONT_SCALE = 1.5;
2348
- var DEFAULT_FONT_SCALE = 1;
2349
- var FONT_SCALE_STEP = 0.125;
2350
- var WIDTH_KEY = "assistant.panel.width";
2351
- var FONT_SCALE_KEY = "assistant.panel.fontScale";
2352
- function readNumber(key) {
2353
- try {
2354
- const raw = window.localStorage.getItem(key);
2355
- if (raw == null || raw.trim() === "") return null;
2356
- const n = Number(raw);
2357
- return Number.isFinite(n) ? n : null;
2358
- } catch {
2359
- return null;
2360
- }
2361
- }
2362
- function writeNumber(key, value) {
2363
- try {
2364
- window.localStorage.setItem(key, String(value));
2365
- } catch {
2366
- }
2367
- }
2368
- function maxPanelWidth() {
2369
- if (typeof window === "undefined") return 9999;
2370
- return Math.round(window.innerWidth * MAX_PANEL_WIDTH_FRACTION);
2371
- }
2372
- function clampWidth(value) {
2373
- return Math.min(
2374
- Math.max(Math.round(value), MIN_PANEL_WIDTH),
2375
- maxPanelWidth()
2376
- );
2377
- }
2378
- function clampScale(value) {
2379
- const stepped = Math.round(value / FONT_SCALE_STEP) * FONT_SCALE_STEP;
2380
- return Math.min(Math.max(stepped, MIN_FONT_SCALE), MAX_FONT_SCALE);
2381
- }
2382
- function usePanelWidth() {
2383
- const [width, setWidthState] = useState5(DEFAULT_PANEL_WIDTH);
2384
- const [maxWidth, setMaxWidth] = useState5(() => maxPanelWidth());
2385
- const desiredRef = useRef4(DEFAULT_PANEL_WIDTH);
2386
- useEffect5(() => {
2387
- setMaxWidth(maxPanelWidth());
2388
- const stored = readNumber(WIDTH_KEY);
2389
- if (stored != null) {
2390
- desiredRef.current = Math.max(Math.round(stored), MIN_PANEL_WIDTH);
2391
- setWidthState(clampWidth(stored));
2392
- }
2393
- }, []);
2394
- useEffect5(() => {
2395
- const onResize = () => {
2396
- setMaxWidth(maxPanelWidth());
2397
- setWidthState(clampWidth(desiredRef.current));
2398
- };
2399
- window.addEventListener("resize", onResize);
2400
- return () => window.removeEventListener("resize", onResize);
2401
- }, []);
2402
- const setWidth = useCallback4((next) => {
2403
- const clamped = clampWidth(next);
2404
- desiredRef.current = clamped;
2405
- writeNumber(WIDTH_KEY, clamped);
2406
- setWidthState(clamped);
2407
- }, []);
2408
- const previewWidth = useCallback4((next) => {
2409
- setWidthState(clampWidth(next));
2410
- }, []);
2411
- const nudgeWidth = useCallback4((deltaPx) => {
2412
- const clamped = clampWidth(desiredRef.current + deltaPx);
2413
- desiredRef.current = clamped;
2414
- writeNumber(WIDTH_KEY, clamped);
2415
- setWidthState(clamped);
2416
- }, []);
2417
- return { width, maxWidth, setWidth, previewWidth, nudgeWidth };
2418
- }
2419
- function useFontScale() {
2420
- const [scale, setScaleState] = useState5(DEFAULT_FONT_SCALE);
2421
- useEffect5(() => {
2422
- const stored = readNumber(FONT_SCALE_KEY);
2423
- if (stored != null) setScaleState(clampScale(stored));
2424
- }, []);
2425
- const step = useCallback4((delta) => {
2426
- setScaleState((prev) => {
2427
- const clamped = clampScale(prev + delta);
2428
- writeNumber(FONT_SCALE_KEY, clamped);
2429
- return clamped;
2430
- });
2431
- }, []);
2432
- return {
2433
- scale,
2434
- increase: () => step(FONT_SCALE_STEP),
2435
- decrease: () => step(-FONT_SCALE_STEP),
2436
- canIncrease: scale < MAX_FONT_SCALE - 1e-9,
2437
- canDecrease: scale > MIN_FONT_SCALE + 1e-9
2438
- };
2439
- }
2440
- function useIsDesktop() {
2441
- const [isDesktop, setIsDesktop] = useState5(
2442
- () => typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia("(min-width: 768px)").matches : true
2551
+ const items = useMemo3(
2552
+ () => buildAssistantTimeline(view, { toolRenderers, renderConfirmedResult }),
2553
+ [view, toolRenderers, renderConfirmedResult]
2443
2554
  );
2444
- useEffect5(() => {
2445
- if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
2446
- return;
2447
- }
2448
- const mq = window.matchMedia("(min-width: 768px)");
2449
- const update = () => setIsDesktop(mq.matches);
2450
- update();
2451
- mq.addEventListener("change", update);
2452
- return () => mq.removeEventListener("change", update);
2453
- }, []);
2454
- return isDesktop;
2555
+ if (items.length === 0 && !view.isStreaming) return /* @__PURE__ */ jsx6(Fragment, { children: emptyState });
2556
+ return /* @__PURE__ */ jsx6(AgentTimeline, { items, isThinking: view.isThinking });
2455
2557
  }
2456
2558
 
2457
2559
  // src/assistant/use-stick-to-bottom.ts
2458
- import { useCallback as useCallback5, useLayoutEffect, useRef as useRef5 } from "react";
2560
+ import { useCallback as useCallback5, useLayoutEffect, useRef as useRef6 } from "react";
2459
2561
  var STICK_SLACK_PX = 48;
2460
2562
  function useStickToBottom(ref, { enabled, contentSignature, streamingId, threadId }) {
2461
- const stuckRef = useRef5(true);
2462
- const prevStreamingRef = useRef5(streamingId);
2463
- const prevThreadRef = useRef5(threadId);
2563
+ const stuckRef = useRef6(true);
2564
+ const prevStreamingRef = useRef6(streamingId);
2565
+ const prevThreadRef = useRef6(threadId);
2464
2566
  const onScroll = useCallback5(() => {
2465
2567
  if (!enabled) return;
2466
2568
  const el = ref.current;
@@ -2481,12 +2583,16 @@ function useStickToBottom(ref, { enabled, contentSignature, streamingId, threadI
2481
2583
  }
2482
2584
 
2483
2585
  // src/assistant/AssistantPanel.tsx
2484
- import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
2485
- var EMPTY_DOORS = [
2586
+ import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
2587
+ var STARTERS = [
2486
2588
  { label: "Create a workflow", seed: "Create a workflow that " },
2487
2589
  { label: "Check usage", seed: "What did my workflows cost this week?" },
2488
2590
  { label: "Manage API keys", seed: "Create an API key named " }
2489
2591
  ];
2592
+ var PAGE_STARTER = {
2593
+ label: "Explain this page",
2594
+ seed: "Explain what this page shows and what I can do next."
2595
+ };
2490
2596
  function defaultFormatMoney(usd) {
2491
2597
  if (usd == null) return "\u2014";
2492
2598
  return new Intl.NumberFormat("en-US", {
@@ -2494,6 +2600,93 @@ function defaultFormatMoney(usd) {
2494
2600
  currency: "USD"
2495
2601
  }).format(usd);
2496
2602
  }
2603
+ var HEADER_BUTTON = `flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-[var(--accent-surface-soft)] hover:text-foreground ${focusRing2}`;
2604
+ var NOTICE_TONE = {
2605
+ error: {
2606
+ surface: "border-[var(--surface-danger-border)] bg-[var(--surface-danger-bg)]",
2607
+ icon: "text-[var(--surface-danger-text)]",
2608
+ Glyph: AlertCircle
2609
+ },
2610
+ warning: {
2611
+ surface: "border-[var(--surface-warning-border)] bg-[var(--surface-warning-bg)]",
2612
+ icon: "text-[var(--surface-warning-text)]",
2613
+ Glyph: AlertTriangle
2614
+ },
2615
+ info: {
2616
+ surface: "border-border bg-background",
2617
+ icon: "text-muted-foreground",
2618
+ Glyph: Info
2619
+ }
2620
+ };
2621
+ function Notice({
2622
+ tone,
2623
+ children,
2624
+ action
2625
+ }) {
2626
+ const style = NOTICE_TONE[tone];
2627
+ return /* @__PURE__ */ jsxs4(
2628
+ "div",
2629
+ {
2630
+ className: `flex items-start gap-3 rounded-lg border px-3 py-2.5 text-sm ${style.surface}`,
2631
+ children: [
2632
+ /* @__PURE__ */ jsxs4(
2633
+ "div",
2634
+ {
2635
+ role: tone === "error" ? "alert" : "status",
2636
+ className: "flex min-w-0 flex-1 items-start gap-2.5",
2637
+ children: [
2638
+ /* @__PURE__ */ jsx7(
2639
+ style.Glyph,
2640
+ {
2641
+ "aria-hidden": "true",
2642
+ className: `mt-0.5 h-4 w-4 shrink-0 ${style.icon}`
2643
+ }
2644
+ ),
2645
+ /* @__PURE__ */ jsx7("p", { className: "min-w-0 flex-1 break-words font-medium text-foreground", children })
2646
+ ]
2647
+ }
2648
+ ),
2649
+ action && /* @__PURE__ */ jsx7(
2650
+ "button",
2651
+ {
2652
+ type: "button",
2653
+ onClick: action.onClick,
2654
+ className: `shrink-0 rounded-md border border-border bg-card px-2.5 py-1 font-medium text-foreground text-xs transition-colors hover:bg-[var(--accent-surface-soft)] ${focusRing2}`,
2655
+ children: action.label
2656
+ }
2657
+ )
2658
+ ]
2659
+ }
2660
+ );
2661
+ }
2662
+ function FirstRun({
2663
+ hasPage,
2664
+ onPick
2665
+ }) {
2666
+ const starters = hasPage ? [PAGE_STARTER, ...STARTERS] : STARTERS;
2667
+ return /* @__PURE__ */ jsxs4("div", { className: "px-4 pt-6 pb-4", children: [
2668
+ /* @__PURE__ */ jsx7("h3", { className: "font-semibold text-[var(--font-size-lg)] text-foreground leading-snug", children: "What should the assistant do?" }),
2669
+ /* @__PURE__ */ jsx7("p", { className: "mt-1.5 text-[var(--font-size-base)] text-muted-foreground leading-[1.5]", children: "It creates workflows, checks usage, and manages API keys. Changes wait for your approval." }),
2670
+ /* @__PURE__ */ jsx7("ul", { className: "mt-5 flex flex-col gap-2", children: starters.map((starter) => /* @__PURE__ */ jsx7("li", { children: /* @__PURE__ */ jsxs4(
2671
+ "button",
2672
+ {
2673
+ type: "button",
2674
+ onClick: () => onPick(starter.seed),
2675
+ className: `group flex min-h-11 w-full items-center justify-between gap-3 rounded-lg border border-border bg-background px-3.5 py-2.5 text-left text-foreground text-sm transition-colors hover:bg-[var(--accent-surface-soft)] ${focusRing2}`,
2676
+ children: [
2677
+ starter.label,
2678
+ /* @__PURE__ */ jsx7(
2679
+ ArrowUpRight,
2680
+ {
2681
+ "aria-hidden": "true",
2682
+ className: "h-4 w-4 shrink-0 text-muted-foreground transition-colors group-hover:text-foreground"
2683
+ }
2684
+ )
2685
+ ]
2686
+ }
2687
+ ) }, starter.label)) })
2688
+ ] });
2689
+ }
2497
2690
  function providerOf(slug) {
2498
2691
  const i = slug.indexOf("/");
2499
2692
  return i > 0 ? slug.slice(0, i) : "other";
@@ -2517,12 +2710,6 @@ function toPickerModels(models, selected) {
2517
2710
  }
2518
2711
  return mapped;
2519
2712
  }
2520
- function WorkingIndicator() {
2521
- return /* @__PURE__ */ jsxs4("span", { className: "inline-flex items-center gap-1.5 text-muted-foreground text-xs", children: [
2522
- /* @__PURE__ */ jsx5("span", { className: "h-1.5 w-1.5 animate-pulse rounded-full bg-primary" }),
2523
- "Working\u2026"
2524
- ] });
2525
- }
2526
2713
  function nextModelSelection(id, defaultSlug) {
2527
2714
  if (defaultSlug != null && id === defaultSlug) return null;
2528
2715
  return id || null;
@@ -2531,15 +2718,16 @@ function AssistantPanel({
2531
2718
  chat,
2532
2719
  userId,
2533
2720
  onClose,
2721
+ layout = "docked",
2722
+ context = null,
2723
+ toggleRef,
2534
2724
  navigate,
2535
2725
  balanceUsd = null,
2536
2726
  formatMoney = defaultFormatMoney,
2537
2727
  renderGraph,
2538
2728
  renderProviderIcon,
2539
- renderMarkdown,
2540
2729
  toolRenderers,
2541
2730
  renderConfirmedResult,
2542
- renderTranscript,
2543
2731
  composerSeed = null,
2544
2732
  onComposerSeedApplied,
2545
2733
  composerAttachments,
@@ -2547,27 +2735,26 @@ function AssistantPanel({
2547
2735
  }) {
2548
2736
  const models = useAssistantModels();
2549
2737
  const threads = useAssistantThreads(userId);
2550
- const font = useFontScale();
2551
- const [doorSeed, setDoorSeed] = useState6(null);
2552
- const [view, setView] = useState6("chat");
2553
- const historyButtonRef = useRef6(null);
2554
- const logRef = useRef6(null);
2555
- const pickerModels = useMemo3(
2738
+ const [starterSeed, setStarterSeed] = useState7(null);
2739
+ const [view, setView] = useState7("chat");
2740
+ const historyButtonRef = useRef7(null);
2741
+ const logRef = useRef7(null);
2742
+ const pickerModels = useMemo4(
2556
2743
  () => toPickerModels(models, chat.selectedModel),
2557
2744
  [models, chat.selectedModel]
2558
2745
  );
2559
2746
  const pickerValue = chat.selectedModel ?? models.default ?? "";
2560
2747
  const { state } = chat;
2561
- const chatRef = useRef6(chat);
2748
+ const chatRef = useRef7(chat);
2562
2749
  chatRef.current = chat;
2563
- useEffect6(() => {
2750
+ useEffect7(() => {
2564
2751
  if (view !== "history") return;
2565
2752
  const search = logRef.current?.querySelector(
2566
2753
  'input[type="search"]'
2567
2754
  );
2568
2755
  (search ?? logRef.current)?.focus();
2569
2756
  }, [view]);
2570
- useEffect6(() => {
2757
+ useEffect7(() => {
2571
2758
  if (view !== "history") return;
2572
2759
  const onKeyDownCapture = (e) => {
2573
2760
  if (e.key !== "Escape") return;
@@ -2582,7 +2769,7 @@ function AssistantPanel({
2582
2769
  document.addEventListener("keydown", onKeyDownCapture, true);
2583
2770
  return () => document.removeEventListener("keydown", onKeyDownCapture, true);
2584
2771
  }, [view]);
2585
- const contentSignature = useMemo3(() => {
2772
+ const contentSignature = useMemo4(() => {
2586
2773
  let sig = `${state.reasoning?.length ?? 0}|${state.status}`;
2587
2774
  for (const m of state.messages) {
2588
2775
  sig += `|${m.text?.length ?? 0}`;
@@ -2610,10 +2797,8 @@ function AssistantPanel({
2610
2797
  const errorView = state.error ? presentError(state.error.code, state.error.message) : null;
2611
2798
  const low = isLowBalance(effectiveBalance) && !errorView;
2612
2799
  const streaming = state.status === "streaming";
2613
- const firstUserText = state.messages.find((m) => m.role === "user")?.text.trim();
2614
- const titleChars = firstUserText ? Array.from(firstUserText) : [];
2615
- const conversationTitle = firstUserText ? titleChars.length > 60 ? `${titleChars.slice(0, 60).join("")}\u2026` : firstUserText : null;
2616
- const renderProposal = (proposal) => /* @__PURE__ */ jsx5(
2800
+ const showContinue = state.capped && state.status === "idle" && !chat.restoring && view === "chat";
2801
+ const renderProposal = (proposal) => /* @__PURE__ */ jsx7(
2617
2802
  ProposalCard,
2618
2803
  {
2619
2804
  proposal,
@@ -2626,26 +2811,25 @@ function AssistantPanel({
2626
2811
  renderProviderIcon
2627
2812
  }
2628
2813
  );
2629
- const isThinking = assistantIsThinking(state);
2630
2814
  const transcriptView = {
2631
2815
  messages: state.messages,
2632
2816
  reasoning: state.reasoning,
2633
2817
  streamingId: state.streamingId,
2634
2818
  model: state.model,
2635
2819
  isStreaming: streaming,
2636
- isThinking,
2820
+ isThinking: assistantIsThinking(state),
2637
2821
  pendingProposals: state.pendingProposals,
2638
2822
  usage: state.usage,
2639
2823
  renderProposal
2640
2824
  };
2641
- const showHistory = () => {
2825
+ const toggleHistory = () => {
2826
+ if (view === "history") {
2827
+ setView("chat");
2828
+ return;
2829
+ }
2642
2830
  threads.refresh();
2643
2831
  setView("history");
2644
2832
  };
2645
- const toggleHistory = () => {
2646
- if (view === "history") setView("chat");
2647
- else showHistory();
2648
- };
2649
2833
  const deleteThread = async (threadId) => {
2650
2834
  const pre = chatRef.current.state;
2651
2835
  if (pre.threadId === threadId && pre.status !== "idle") return;
@@ -2658,101 +2842,73 @@ function AssistantPanel({
2658
2842
  chatRef.current.reset();
2659
2843
  }
2660
2844
  };
2661
- return /* @__PURE__ */ jsxs4("div", { className: "relative flex h-full flex-col bg-card", children: [
2662
- /* @__PURE__ */ jsx5("div", { className: "border-border border-b", children: /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between gap-2 px-4 pt-3 pb-2.5", children: [
2663
- /* @__PURE__ */ jsxs4("div", { className: "flex min-w-0 flex-col", children: [
2664
- /* @__PURE__ */ jsxs4("div", { className: "flex items-baseline gap-2", children: [
2665
- /* @__PURE__ */ jsx5("span", { className: "font-semibold text-[15px] text-foreground", children: "Assistant" }),
2666
- effectiveBalance != null && /* @__PURE__ */ jsx5(
2845
+ return /* @__PURE__ */ jsxs4("div", { className: "relative flex h-full min-h-0 flex-col bg-card", children: [
2846
+ /* @__PURE__ */ jsxs4("header", { className: "flex h-[var(--assistant-header-height,3.5rem)] shrink-0 items-center gap-2 border-border border-b px-3", children: [
2847
+ layout === "docked" && /* @__PURE__ */ jsx7(AssistantPanelToggle, { open: true, onToggle: onClose, buttonRef: toggleRef }),
2848
+ /* @__PURE__ */ jsxs4("div", { className: "flex min-w-0 flex-1 flex-col justify-center", children: [
2849
+ /* @__PURE__ */ jsxs4("div", { className: "flex min-w-0 items-baseline gap-2", children: [
2850
+ /* @__PURE__ */ jsx7("h2", { className: "truncate font-semibold text-[var(--font-size-base)] text-foreground leading-tight", children: "Assistant" }),
2851
+ effectiveBalance != null && /* @__PURE__ */ jsx7(
2667
2852
  "span",
2668
2853
  {
2669
2854
  "aria-label": "Your credit balance",
2670
- className: "text-muted-foreground text-xs",
2855
+ className: "shrink-0 text-muted-foreground text-xs tabular-nums",
2671
2856
  children: formatMoney(effectiveBalance)
2672
2857
  }
2673
2858
  )
2674
2859
  ] }),
2675
- conversationTitle && /* @__PURE__ */ jsx5(
2676
- "span",
2860
+ context && /* @__PURE__ */ jsxs4(
2861
+ "p",
2677
2862
  {
2678
- className: "truncate text-muted-foreground text-xs",
2679
- title: conversationTitle,
2680
- children: conversationTitle
2681
- }
2682
- )
2683
- ] }),
2684
- /* @__PURE__ */ jsxs4("div", { className: "flex shrink-0 items-center gap-1", children: [
2685
- /* @__PURE__ */ jsxs4(
2686
- "div",
2687
- {
2688
- className: "flex items-center overflow-hidden rounded-md border border-border",
2689
- role: "group",
2690
- "aria-label": "Text size",
2863
+ className: "truncate text-muted-foreground text-xs leading-snug",
2864
+ title: `The assistant sees ${context.path}`,
2691
2865
  children: [
2692
- /* @__PURE__ */ jsx5(
2693
- "button",
2694
- {
2695
- type: "button",
2696
- onClick: font.decrease,
2697
- disabled: !font.canDecrease,
2698
- "aria-label": "Decrease text size",
2699
- className: "px-1.5 py-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-40 disabled:hover:bg-transparent",
2700
- children: /* @__PURE__ */ jsx5(Minus, { className: "h-3.5 w-3.5" })
2701
- }
2702
- ),
2703
- /* @__PURE__ */ jsx5(
2704
- "button",
2705
- {
2706
- type: "button",
2707
- onClick: font.increase,
2708
- disabled: !font.canIncrease,
2709
- "aria-label": "Increase text size",
2710
- className: "border-border border-l px-1.5 py-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-40 disabled:hover:bg-transparent",
2711
- children: /* @__PURE__ */ jsx5(Plus, { className: "h-3.5 w-3.5" })
2712
- }
2713
- )
2866
+ /* @__PURE__ */ jsx7("span", { className: "sr-only", children: "Looking at " }),
2867
+ context.label
2714
2868
  ]
2715
2869
  }
2716
- ),
2717
- /* @__PURE__ */ jsx5(
2718
- "button",
2719
- {
2720
- ref: historyButtonRef,
2721
- type: "button",
2722
- onClick: toggleHistory,
2723
- "aria-label": "Chat history",
2724
- "aria-pressed": view === "history",
2725
- className: `rounded-md p-1.5 transition-colors hover:bg-muted hover:text-foreground ${view === "history" ? "bg-muted text-foreground" : "text-muted-foreground"}`,
2726
- children: /* @__PURE__ */ jsx5(History, { className: "h-4 w-4" })
2727
- }
2728
- ),
2729
- /* @__PURE__ */ jsx5(
2730
- "button",
2731
- {
2732
- type: "button",
2733
- onClick: () => {
2734
- chat.reset();
2735
- setView("chat");
2736
- },
2737
- "aria-label": "New chat",
2738
- title: "New chat",
2739
- className: "rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
2740
- children: /* @__PURE__ */ jsx5(MessageSquarePlus, { className: "h-4 w-4" })
2741
- }
2742
- ),
2743
- /* @__PURE__ */ jsx5(
2744
- "button",
2745
- {
2746
- type: "button",
2747
- onClick: onClose,
2748
- "aria-label": "Close assistant",
2749
- className: "rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",
2750
- children: /* @__PURE__ */ jsx5(X, { className: "h-4 w-4" })
2751
- }
2752
2870
  )
2753
- ] })
2754
- ] }) }),
2755
- /* @__PURE__ */ jsx5(
2871
+ ] }),
2872
+ /* @__PURE__ */ jsx7(
2873
+ "button",
2874
+ {
2875
+ type: "button",
2876
+ onClick: () => {
2877
+ chat.reset();
2878
+ setView("chat");
2879
+ },
2880
+ "aria-label": "New chat",
2881
+ title: "New chat",
2882
+ className: HEADER_BUTTON,
2883
+ children: /* @__PURE__ */ jsx7(MessageSquarePlus, { "aria-hidden": "true", className: "h-[18px] w-[18px]" })
2884
+ }
2885
+ ),
2886
+ /* @__PURE__ */ jsx7(
2887
+ "button",
2888
+ {
2889
+ ref: historyButtonRef,
2890
+ type: "button",
2891
+ onClick: toggleHistory,
2892
+ "aria-label": "Chat history",
2893
+ "aria-pressed": view === "history",
2894
+ title: "Chat history",
2895
+ className: `${HEADER_BUTTON} ${view === "history" ? "bg-[var(--accent-surface-soft)] text-foreground" : ""}`,
2896
+ children: /* @__PURE__ */ jsx7(History, { "aria-hidden": "true", className: "h-[18px] w-[18px]" })
2897
+ }
2898
+ ),
2899
+ layout === "sheet" && /* @__PURE__ */ jsx7(
2900
+ "button",
2901
+ {
2902
+ type: "button",
2903
+ onClick: onClose,
2904
+ "aria-label": "Close assistant",
2905
+ title: "Close assistant",
2906
+ className: HEADER_BUTTON,
2907
+ children: /* @__PURE__ */ jsx7(X, { "aria-hidden": "true", className: "h-[18px] w-[18px]" })
2908
+ }
2909
+ )
2910
+ ] }),
2911
+ /* @__PURE__ */ jsx7(
2756
2912
  "div",
2757
2913
  {
2758
2914
  ref: logRef,
@@ -2762,7 +2918,7 @@ function AssistantPanel({
2762
2918
  role: view === "chat" ? "log" : void 0,
2763
2919
  "aria-live": view === "chat" ? "polite" : void 0,
2764
2920
  className: "min-h-0 flex-1 overflow-y-auto focus:outline-none",
2765
- children: view === "history" ? /* @__PURE__ */ jsx5(
2921
+ children: view === "history" ? /* @__PURE__ */ jsx7(
2766
2922
  AssistantHistory,
2767
2923
  {
2768
2924
  threads: threads.threads,
@@ -2778,119 +2934,52 @@ function AssistantPanel({
2778
2934
  },
2779
2935
  onDelete: (id) => void deleteThread(id)
2780
2936
  }
2781
- ) : (
2782
- // The text-size control zooms the transcript only — not the history
2783
- // view's search box and buttons. `zoom` scales every descendant
2784
- // uniformly regardless of which renderer draws the conversation; an
2785
- // inline `font-size` would not (the transcript's text utilities set
2786
- // absolute rem sizes), and `transform: scale` would break the scroll
2787
- // container by keeping the original layout box.
2788
- /* @__PURE__ */ jsx5("div", { className: "px-2 py-3", style: { zoom: font.scale }, children: renderTranscript ? renderTranscript(transcriptView) : /* @__PURE__ */ jsx5(
2789
- AssistantTranscript,
2790
- {
2791
- view: transcriptView,
2792
- renderMarkdown,
2793
- toolRenderers,
2794
- renderConfirmedResult,
2795
- emptyState: /* @__PURE__ */ jsx5(
2796
- ChatEmptyState,
2797
- {
2798
- productName: "Assistant",
2799
- headline: "Ask the assistant to do something",
2800
- subline: "Create workflows, check usage, or manage API keys \u2014 I'll pause for approval before anything changes.",
2801
- doors: EMPTY_DOORS.map((door) => ({
2802
- label: door.label,
2803
- onSelect: () => setDoorSeed(door.seed)
2804
- }))
2805
- }
2806
- )
2807
- }
2808
- ) })
2809
- )
2810
- }
2811
- ),
2812
- errorView && /* @__PURE__ */ jsxs4(
2813
- "div",
2814
- {
2815
- role: "alert",
2816
- className: "mx-4 mb-2 flex items-start gap-2.5 rounded-lg border border-destructive/40 bg-destructive/5 px-3 py-2.5 text-destructive text-sm",
2817
- children: [
2818
- /* @__PURE__ */ jsxs4(
2819
- "svg",
2820
- {
2821
- className: "mt-0.5 h-4 w-4 shrink-0",
2822
- viewBox: "0 0 24 24",
2823
- fill: "none",
2824
- stroke: "currentColor",
2825
- strokeWidth: "2",
2826
- strokeLinecap: "round",
2827
- strokeLinejoin: "round",
2828
- "aria-hidden": "true",
2829
- children: [
2830
- /* @__PURE__ */ jsx5("circle", { cx: "12", cy: "12", r: "9" }),
2831
- /* @__PURE__ */ jsx5("path", { d: "M12 8v4m0 4h.01" })
2832
- ]
2833
- }
2834
- ),
2835
- /* @__PURE__ */ jsxs4("div", { className: "min-w-0 flex-1", children: [
2836
- /* @__PURE__ */ jsx5("p", { children: errorView.message }),
2837
- errorView.cta && /* @__PURE__ */ jsx5(
2838
- "button",
2839
- {
2840
- type: "button",
2841
- onClick: () => navigate?.(errorView.cta?.to ?? ""),
2842
- className: "mt-1.5 rounded border border-destructive/40 bg-card px-2 py-0.5 font-medium text-xs text-destructive transition hover:bg-destructive/10",
2843
- children: errorView.cta.label
2844
- }
2845
- )
2846
- ] })
2847
- ]
2848
- }
2849
- ),
2850
- low && /* @__PURE__ */ jsxs4(
2851
- "div",
2852
- {
2853
- role: "status",
2854
- className: "mx-4 mb-2 rounded-lg border border-border bg-secondary px-3 py-2 text-sm",
2855
- children: [
2856
- /* @__PURE__ */ jsx5("p", { className: "text-foreground", children: "Your credit balance is running low." }),
2857
- /* @__PURE__ */ jsx5(
2858
- "button",
2859
- {
2860
- type: "button",
2861
- onClick: () => navigate?.("/app/billing"),
2862
- className: "mt-1 text-primary text-xs",
2863
- children: "Add credits \u2192"
2864
- }
2865
- )
2866
- ]
2867
- }
2868
- ),
2869
- state.capped && state.status === "idle" && !chat.restoring && view === "chat" && /* @__PURE__ */ jsxs4(
2870
- "div",
2871
- {
2872
- role: "status",
2873
- className: "mx-4 mb-2 flex items-center gap-3 rounded-lg border border-border bg-secondary px-3 py-2 text-sm",
2874
- children: [
2875
- /* @__PURE__ */ jsx5("p", { className: "min-w-0 flex-1 text-foreground", children: "Paused at the step limit." }),
2876
- /* @__PURE__ */ jsx5(
2877
- "button",
2878
- {
2879
- type: "button",
2880
- onClick: () => {
2881
- setView("chat");
2882
- chat.send("continue");
2883
- },
2884
- className: "shrink-0 rounded-lg bg-primary px-3 py-1.5 font-semibold text-primary-foreground text-xs transition hover:bg-primary/90",
2885
- children: "Continue"
2886
- }
2887
- )
2888
- ]
2937
+ ) : /* @__PURE__ */ jsx7("div", { className: "mx-auto w-full max-w-3xl", children: /* @__PURE__ */ jsx7(
2938
+ AssistantTranscript,
2939
+ {
2940
+ view: transcriptView,
2941
+ toolRenderers,
2942
+ renderConfirmedResult,
2943
+ emptyState: /* @__PURE__ */ jsx7(FirstRun, { hasPage: context != null, onPick: setStarterSeed })
2944
+ }
2945
+ ) })
2889
2946
  }
2890
2947
  ),
2891
- /* @__PURE__ */ jsxs4("div", { className: "border-border border-t p-3", children: [
2892
- streaming && /* @__PURE__ */ jsx5("div", { className: "px-2 pb-1.5", "aria-label": "Assistant is working", children: /* @__PURE__ */ jsx5(WorkingIndicator, {}) }),
2893
- /* @__PURE__ */ jsx5(
2948
+ /* @__PURE__ */ jsxs4("div", { className: "mx-auto flex w-full max-w-3xl shrink-0 flex-col gap-2 p-3", children: [
2949
+ errorView && /* @__PURE__ */ jsx7(
2950
+ Notice,
2951
+ {
2952
+ tone: "error",
2953
+ action: errorView.cta ? {
2954
+ label: errorView.cta.label,
2955
+ onClick: () => navigate?.(errorView.cta?.to ?? "")
2956
+ } : void 0,
2957
+ children: errorView.message
2958
+ }
2959
+ ),
2960
+ low && /* @__PURE__ */ jsx7(
2961
+ Notice,
2962
+ {
2963
+ tone: "warning",
2964
+ action: {
2965
+ label: "Add credits",
2966
+ onClick: () => navigate?.("/app/billing")
2967
+ },
2968
+ children: "Your credit balance is running low."
2969
+ }
2970
+ ),
2971
+ showContinue && // A capped turn stopped mid-plan. "continue" is an ordinary user
2972
+ // message: the server replays the thread's full history every turn,
2973
+ // so the model resumes the interrupted work from context.
2974
+ /* @__PURE__ */ jsx7(
2975
+ Notice,
2976
+ {
2977
+ tone: "info",
2978
+ action: { label: "Continue", onClick: () => chat.send("continue") },
2979
+ children: "Paused at the step limit."
2980
+ }
2981
+ ),
2982
+ /* @__PURE__ */ jsx7(
2894
2983
  ChatComposer,
2895
2984
  {
2896
2985
  onSend: (message) => {
@@ -2902,9 +2991,10 @@ function AssistantPanel({
2902
2991
  isStreaming: streaming,
2903
2992
  disabled: chat.restoring || state.status === "awaiting_confirm",
2904
2993
  placeholder: state.status === "awaiting_confirm" ? "Confirm or cancel the proposal above to continue" : "Message the assistant\u2026",
2905
- seed: doorSeed ?? composerSeed,
2994
+ sendVariant: "icon",
2995
+ seed: starterSeed ?? composerSeed,
2906
2996
  onSeedApplied: () => {
2907
- setDoorSeed(null);
2997
+ setStarterSeed(null);
2908
2998
  onComposerSeedApplied?.();
2909
2999
  },
2910
3000
  onAttach: composerAttachments?.onAttach,
@@ -2912,60 +3002,24 @@ function AssistantPanel({
2912
3002
  pendingFiles: composerAttachments?.pendingFiles,
2913
3003
  onRemoveFile: composerAttachments?.onRemoveFile,
2914
3004
  accept: composerAttachments?.accept,
2915
- controls: pickerModels.length > 0 ? /* @__PURE__ */ jsx5(
3005
+ controls: pickerModels.length > 0 ? /* @__PURE__ */ jsx7(
2916
3006
  ModelPicker,
2917
3007
  {
3008
+ variant: "quiet",
2918
3009
  value: pickerValue,
2919
3010
  onChange: (id) => chat.setModel(nextModelSelection(id, models.default)),
2920
3011
  models: pickerModels
2921
3012
  }
2922
- ) : /* @__PURE__ */ jsx5("span", { className: "px-1 text-muted-foreground text-xs", children: "Default model" })
3013
+ ) : /* @__PURE__ */ jsx7("span", { className: "px-1 text-muted-foreground text-xs", children: "Default model" })
2923
3014
  }
2924
3015
  )
2925
3016
  ] })
2926
3017
  ] });
2927
3018
  }
2928
3019
 
2929
- // src/assistant/launcher.tsx
2930
- import {
2931
- createContext as createContext2,
2932
- useCallback as useCallback6,
2933
- useContext as useContext2,
2934
- useMemo as useMemo4,
2935
- useState as useState7
2936
- } from "react";
2937
- import { jsx as jsx6 } from "react/jsx-runtime";
2938
- var AssistantLauncherContext = createContext2(null);
2939
- function AssistantLauncherProvider({
2940
- children
2941
- }) {
2942
- const [open, setOpen] = useState7(false);
2943
- const [seed, setSeed] = useState7(null);
2944
- const openAssistant = useCallback6((next) => {
2945
- if (next != null) setSeed(next);
2946
- setOpen(true);
2947
- }, []);
2948
- const closeAssistant = useCallback6(() => setOpen(false), []);
2949
- const clearSeed = useCallback6(() => setSeed(null), []);
2950
- const value = useMemo4(
2951
- () => ({ open, seed, openAssistant, closeAssistant, clearSeed }),
2952
- [open, seed, openAssistant, closeAssistant, clearSeed]
2953
- );
2954
- return /* @__PURE__ */ jsx6(AssistantLauncherContext.Provider, { value, children });
2955
- }
2956
- function useAssistantLauncher() {
2957
- const ctx = useContext2(AssistantLauncherContext);
2958
- if (!ctx) {
2959
- throw new Error(
2960
- "useAssistantLauncher must be used within an AssistantLauncherProvider"
2961
- );
2962
- }
2963
- return ctx;
2964
- }
2965
-
2966
3020
  // src/assistant/ResizeHandle.tsx
2967
- import { useRef as useRef7 } from "react";
2968
- import { jsx as jsx7 } from "react/jsx-runtime";
3021
+ import { useRef as useRef8 } from "react";
3022
+ import { jsx as jsx8 } from "react/jsx-runtime";
2969
3023
  function ResizeHandle({
2970
3024
  width,
2971
3025
  maxWidth,
@@ -2973,7 +3027,7 @@ function ResizeHandle({
2973
3027
  onCommit,
2974
3028
  onNudge
2975
3029
  }) {
2976
- const dragRef = useRef7(null);
3030
+ const dragRef = useRef8(null);
2977
3031
  const onPointerDown = (e) => {
2978
3032
  if (e.button !== 0) return;
2979
3033
  e.preventDefault();
@@ -3013,7 +3067,7 @@ function ResizeHandle({
3013
3067
  };
3014
3068
  return (
3015
3069
  // biome-ignore lint/a11y/useSemanticElements: a focusable drag handle is an ARIA window-splitter (role=separator); no native HTML element provides this.
3016
- /* @__PURE__ */ jsx7(
3070
+ /* @__PURE__ */ jsx8(
3017
3071
  "div",
3018
3072
  {
3019
3073
  role: "separator",
@@ -3029,7 +3083,7 @@ function ResizeHandle({
3029
3083
  onPointerCancel: endDrag,
3030
3084
  onKeyDown,
3031
3085
  className: "group absolute inset-y-0 left-0 z-10 flex w-2 -translate-x-1/2 cursor-ew-resize touch-none items-center justify-center",
3032
- children: /* @__PURE__ */ jsx7(
3086
+ children: /* @__PURE__ */ jsx8(
3033
3087
  "span",
3034
3088
  {
3035
3089
  "aria-hidden": "true",
@@ -3042,15 +3096,24 @@ function ResizeHandle({
3042
3096
  }
3043
3097
 
3044
3098
  // src/assistant/AssistantDock.tsx
3045
- import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
3099
+ import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
3046
3100
  function focusableWithin(container) {
3047
- const selector = 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';
3101
+ const selector = 'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [contenteditable="true"], [tabindex]:not([tabindex="-1"])';
3048
3102
  return Array.from(container.querySelectorAll(selector)).filter(
3049
3103
  (el) => el.getClientRects().length > 0
3050
3104
  );
3051
3105
  }
3106
+ function isEditableTarget(target) {
3107
+ if (!(target instanceof HTMLElement)) return false;
3108
+ return target.isContentEditable || target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.tagName === "SELECT";
3109
+ }
3110
+ function initialFocus(panel) {
3111
+ return panel.querySelector("textarea:not([disabled])") ?? focusableWithin(panel)[0] ?? panel;
3112
+ }
3052
3113
  function AssistantDock({
3053
3114
  userId,
3115
+ context = null,
3116
+ floatingToggle = true,
3054
3117
  navigate,
3055
3118
  balanceUsd = null,
3056
3119
  formatMoney,
@@ -3058,86 +3121,104 @@ function AssistantDock({
3058
3121
  renderProviderIcon,
3059
3122
  onWorkflowMutation,
3060
3123
  onConnectRequirement,
3061
- renderMarkdown,
3062
3124
  toolRenderers,
3063
3125
  renderConfirmedResult,
3064
- renderTranscript,
3065
3126
  composerAttachments,
3066
3127
  onComposerSend
3067
3128
  }) {
3068
- const { open, openAssistant, closeAssistant, seed, clearSeed } = useAssistantLauncher();
3129
+ const {
3130
+ open,
3131
+ closeAssistant,
3132
+ toggleAssistant,
3133
+ seed,
3134
+ clearSeed,
3135
+ layout,
3136
+ openedOnLoad,
3137
+ panel: { width, maxWidth, setWidth, previewWidth, nudgeWidth }
3138
+ } = useAssistantLauncher();
3139
+ const wideSheet = useMediaQuery("(min-width: 40rem)", true);
3069
3140
  const chat = useAssistantChat(userId, {
3070
3141
  onWorkflowMutation,
3071
- onConnectRequirement
3142
+ onConnectRequirement,
3143
+ context
3072
3144
  });
3073
- const isDesktop = useIsDesktop();
3074
- const { width, maxWidth, setWidth, previewWidth, nudgeWidth } = usePanelWidth();
3075
- const launcherRef = useRef8(null);
3076
- const dialogRef = useRef8(null);
3077
- const returnFocusRef = useRef8(null);
3078
- const wasOpenRef = useRef8(false);
3079
- useEffect7(() => {
3145
+ const panelRef = useRef9(null);
3146
+ const toggleRef = useRef9(null);
3147
+ const returnFocusRef = useRef9(null);
3148
+ const wasOpenRef = useRef9(false);
3149
+ const sheet = layout === "sheet";
3150
+ useEffect8(() => {
3151
+ const onKeyDown = (e) => {
3152
+ if (!(e.metaKey || e.ctrlKey) || e.altKey || e.shiftKey) return;
3153
+ if (e.key.toLowerCase() !== "e" || isEditableTarget(e.target)) return;
3154
+ e.preventDefault();
3155
+ toggleAssistant();
3156
+ };
3157
+ window.addEventListener("keydown", onKeyDown);
3158
+ return () => window.removeEventListener("keydown", onKeyDown);
3159
+ }, [toggleAssistant]);
3160
+ useEffect8(() => {
3080
3161
  if (!open) return;
3081
3162
  const onKeyDown = (e) => {
3082
3163
  if (e.key !== "Escape") return;
3083
- if (dialogRef.current?.querySelector(
3084
- '[aria-haspopup="true"][aria-expanded="true"]'
3085
- )) {
3164
+ const panel2 = panelRef.current;
3165
+ if (panel2?.querySelector('[aria-haspopup="true"][aria-expanded="true"]')) {
3166
+ return;
3167
+ }
3168
+ if (!sheet && !(e.target instanceof Node && panel2?.contains(e.target))) {
3086
3169
  return;
3087
3170
  }
3088
3171
  closeAssistant();
3089
3172
  };
3090
3173
  document.addEventListener("keydown", onKeyDown);
3091
3174
  return () => document.removeEventListener("keydown", onKeyDown);
3092
- }, [open, closeAssistant]);
3093
- useEffect7(() => {
3094
- if (open) {
3095
- if (!wasOpenRef.current && !returnFocusRef.current) {
3096
- returnFocusRef.current = document.activeElement;
3097
- }
3175
+ }, [open, sheet, closeAssistant]);
3176
+ useEffect8(() => {
3177
+ if (open && !wasOpenRef.current) {
3098
3178
  wasOpenRef.current = true;
3099
- const el = dialogRef.current;
3100
- if (el) (focusableWithin(el)[0] ?? el).focus();
3101
- } else if (wasOpenRef.current) {
3179
+ if (openedOnLoad) return;
3180
+ returnFocusRef.current = document.activeElement;
3181
+ const panel2 = panelRef.current;
3182
+ if (panel2) initialFocus(panel2).focus();
3183
+ } else if (!open && wasOpenRef.current) {
3102
3184
  wasOpenRef.current = false;
3103
- const target = returnFocusRef.current?.isConnected ? returnFocusRef.current : launcherRef.current;
3104
- target?.focus();
3185
+ const back = returnFocusRef.current;
3105
3186
  returnFocusRef.current = null;
3187
+ const focusLost = document.activeElement === null || document.activeElement === document.body;
3188
+ if (!focusLost) return;
3189
+ (back?.isConnected ? back : toggleRef.current)?.focus();
3106
3190
  }
3107
- }, [open]);
3108
- const openDialog = () => {
3109
- returnFocusRef.current = document.activeElement;
3110
- openAssistant();
3111
- };
3191
+ }, [open, openedOnLoad]);
3112
3192
  if (!open) {
3113
- return /* @__PURE__ */ jsx8(
3114
- "button",
3193
+ return floatingToggle ? /* @__PURE__ */ jsx9(
3194
+ AssistantPanelToggle,
3115
3195
  {
3116
- ref: launcherRef,
3117
- type: "button",
3118
- onClick: openDialog,
3119
- "aria-label": "Open assistant",
3120
- className: "fixed right-4 bottom-4 z-40 flex h-12 w-12 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-[var(--shadow-overlay)] transition-colors hover:bg-primary/90 focus:outline-none focus:ring-2 focus:ring-ring",
3121
- children: /* @__PURE__ */ jsx8(MessageSquare, { className: "h-6 w-6" })
3196
+ buttonRef: toggleRef,
3197
+ className: "fixed",
3198
+ style: {
3199
+ top: "var(--assistant-toggle-top, 0.75rem)",
3200
+ right: "var(--assistant-toggle-right, 0.75rem)",
3201
+ zIndex: "var(--assistant-toggle-z, 30)"
3202
+ }
3122
3203
  }
3123
- );
3204
+ ) : null;
3124
3205
  }
3125
3206
  const trapTab = (e) => {
3126
- if (e.key !== "Tab") return;
3127
- const dialog = dialogRef.current;
3128
- if (!dialog) return;
3129
- const focusables = focusableWithin(dialog);
3207
+ if (!sheet || e.key !== "Tab") return;
3208
+ const container = panelRef.current;
3209
+ if (!container) return;
3210
+ const focusables = focusableWithin(container);
3130
3211
  if (focusables.length === 0) {
3131
3212
  e.preventDefault();
3132
- dialog.focus();
3213
+ container.focus();
3133
3214
  return;
3134
3215
  }
3135
3216
  const first = focusables[0];
3136
3217
  const last = focusables[focusables.length - 1];
3137
3218
  const active = document.activeElement;
3138
- const inside = active instanceof Node && dialog.contains(active);
3219
+ const inside = active instanceof Node && container.contains(active);
3139
3220
  if (e.shiftKey) {
3140
- if (!inside || active === first || active === dialog) {
3221
+ if (!inside || active === first || active === container) {
3141
3222
  e.preventDefault();
3142
3223
  last.focus();
3143
3224
  }
@@ -3146,79 +3227,141 @@ function AssistantDock({
3146
3227
  first.focus();
3147
3228
  }
3148
3229
  };
3149
- return /* @__PURE__ */ jsxs5(Fragment2, { children: [
3150
- /* @__PURE__ */ jsx8(
3151
- "div",
3152
- {
3153
- "aria-hidden": "true",
3154
- className: "fixed inset-0 z-40 bg-black/50",
3155
- onClick: () => closeAssistant()
3156
- }
3157
- ),
3158
- /* @__PURE__ */ jsxs5(
3159
- "div",
3160
- {
3161
- ref: dialogRef,
3162
- role: "dialog",
3163
- "aria-label": "Assistant",
3164
- "aria-modal": "true",
3165
- tabIndex: -1,
3166
- onKeyDown: trapTab,
3167
- style: isDesktop ? { width: `${width}px` } : void 0,
3168
- className: "fixed inset-y-0 right-0 z-50 flex w-full flex-col border-card-edge border-l shadow-[var(--shadow-overlay)] focus:outline-none",
3169
- children: [
3170
- /* @__PURE__ */ jsx8(
3171
- AssistantPanel,
3172
- {
3173
- chat,
3174
- userId,
3175
- onClose: () => closeAssistant(),
3176
- navigate,
3177
- balanceUsd,
3178
- formatMoney,
3179
- renderGraph,
3180
- renderProviderIcon,
3181
- renderMarkdown,
3182
- toolRenderers,
3183
- renderConfirmedResult,
3184
- renderTranscript,
3185
- composerSeed: seed,
3186
- onComposerSeedApplied: clearSeed,
3187
- composerAttachments,
3188
- onComposerSend
3189
- },
3190
- userId ?? "anon"
3191
- ),
3192
- isDesktop && /* @__PURE__ */ jsx8(
3193
- ResizeHandle,
3194
- {
3195
- width,
3196
- maxWidth,
3197
- onPreview: previewWidth,
3198
- onCommit: setWidth,
3199
- onNudge: nudgeWidth
3200
- }
3201
- )
3202
- ]
3203
- }
3204
- )
3205
- ] });
3230
+ const panel = /* @__PURE__ */ jsx9(
3231
+ AssistantPanel,
3232
+ {
3233
+ chat,
3234
+ userId,
3235
+ onClose: closeAssistant,
3236
+ layout,
3237
+ context,
3238
+ toggleRef,
3239
+ navigate,
3240
+ balanceUsd,
3241
+ formatMoney,
3242
+ renderGraph,
3243
+ renderProviderIcon,
3244
+ toolRenderers,
3245
+ renderConfirmedResult,
3246
+ composerSeed: seed,
3247
+ onComposerSeedApplied: clearSeed,
3248
+ composerAttachments,
3249
+ onComposerSend
3250
+ },
3251
+ userId ?? "anon"
3252
+ );
3253
+ if (sheet) {
3254
+ return /* @__PURE__ */ jsxs5(Fragment2, { children: [
3255
+ /* @__PURE__ */ jsx9(
3256
+ "div",
3257
+ {
3258
+ "aria-hidden": "true",
3259
+ className: "fixed inset-0 z-40 bg-black/50",
3260
+ onClick: closeAssistant
3261
+ }
3262
+ ),
3263
+ /* @__PURE__ */ jsx9(
3264
+ "div",
3265
+ {
3266
+ ref: panelRef,
3267
+ id: ASSISTANT_PANEL_ID,
3268
+ role: "dialog",
3269
+ "aria-label": "Assistant",
3270
+ "aria-modal": "true",
3271
+ tabIndex: -1,
3272
+ onKeyDown: trapTab,
3273
+ style: { width: wideSheet ? `min(${width}px, 100vw)` : "100%" },
3274
+ className: "fixed inset-y-0 right-0 z-50 flex flex-col border-border border-l shadow-[var(--shadow-overlay)] focus:outline-none",
3275
+ children: panel
3276
+ }
3277
+ )
3278
+ ] });
3279
+ }
3280
+ return /* @__PURE__ */ jsxs5(
3281
+ "aside",
3282
+ {
3283
+ ref: panelRef,
3284
+ id: ASSISTANT_PANEL_ID,
3285
+ "aria-label": "Assistant",
3286
+ tabIndex: -1,
3287
+ style: { width: `${width}px` },
3288
+ className: "fixed inset-y-0 right-0 z-30 flex flex-col border-border border-l focus:outline-none",
3289
+ children: [
3290
+ panel,
3291
+ /* @__PURE__ */ jsx9(
3292
+ ResizeHandle,
3293
+ {
3294
+ width,
3295
+ maxWidth,
3296
+ onPreview: previewWidth,
3297
+ onCommit: setWidth,
3298
+ onNudge: nudgeWidth
3299
+ }
3300
+ )
3301
+ ]
3302
+ }
3303
+ );
3304
+ }
3305
+
3306
+ // src/assistant/page-context.ts
3307
+ import { useEffect as useEffect9, useMemo as useMemo5, useState as useState8 } from "react";
3308
+ var MAX_LABEL = 200;
3309
+ function pageLabelFromTitle(title, titleSuffix, ignoreTitles = []) {
3310
+ const label = (titleSuffix ? title.replace(titleSuffix, "") : title).trim();
3311
+ if (!label || ignoreTitles.includes(label)) return null;
3312
+ return label.length > MAX_LABEL ? `${label.slice(0, MAX_LABEL - 1)}\u2026` : label;
3313
+ }
3314
+ function useDocumentTitle() {
3315
+ const [title, setTitle] = useState8(
3316
+ () => typeof document === "undefined" ? "" : document.title
3317
+ );
3318
+ useEffect9(() => {
3319
+ const update = () => setTitle(document.title);
3320
+ const observer = new MutationObserver(update);
3321
+ observer.observe(document.head, {
3322
+ subtree: true,
3323
+ childList: true,
3324
+ characterData: true
3325
+ });
3326
+ update();
3327
+ return () => observer.disconnect();
3328
+ }, []);
3329
+ return title;
3330
+ }
3331
+ function useDocumentPageContext({
3332
+ path,
3333
+ titleSuffix,
3334
+ ignoreTitles,
3335
+ ids
3336
+ }) {
3337
+ const title = useDocumentTitle();
3338
+ return useMemo5(() => {
3339
+ const label = pageLabelFromTitle(title, titleSuffix, ignoreTitles);
3340
+ if (!label) return null;
3341
+ const pageIds = ids?.(path);
3342
+ return { label, path, ...pageIds ? { ids: pageIds } : {} };
3343
+ }, [title, path, titleSuffix, ignoreTitles, ids]);
3206
3344
  }
3207
3345
  export {
3346
+ ASSISTANT_PANEL_ID,
3208
3347
  AssistantClientInputError,
3209
3348
  AssistantClientProvider,
3210
3349
  AssistantDock,
3211
3350
  AssistantLauncherProvider,
3212
3351
  AssistantPanel,
3352
+ AssistantPanelToggle,
3213
3353
  AssistantTranscript,
3214
3354
  ProposalCard,
3215
- adaptTranscript,
3216
3355
  assistantIsThinking,
3356
+ assistantShortcutLabel,
3357
+ buildAssistantTimeline,
3217
3358
  createAssistantClient,
3359
+ pageLabelFromTitle,
3218
3360
  useAssistantChat,
3219
3361
  useAssistantClient,
3220
3362
  useAssistantLauncher,
3221
3363
  useAssistantModels,
3222
- useAssistantThreads
3364
+ useAssistantThreads,
3365
+ useDocumentPageContext
3223
3366
  };
3224
3367
  //# sourceMappingURL=index.js.map