langchain_agentx_stream_ui 0.7.2 → 0.7.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.
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { b as ToolDisplayProps, T as ToolBodyComponent } from './types-SVtInovH.js';
3
- import { T as ToolDisplayRegistry } from './sessionViewOptions-DeTrGjRM.js';
2
+ import { b as ToolDisplayProps, T as ToolBodyComponent } from './types-BzeE37Ze.js';
3
+ import { T as ToolDisplayRegistry } from './sessionViewOptions-DaxstMhx.js';
4
4
 
5
5
  declare function DefaultToolBody({ result, bodyMode, onBodyModeChange, }: ToolDisplayProps): react_jsx_runtime.JSX.Element;
6
6
 
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { a as ToolBodyMode } from './types-SVtInovH.js';
2
+ import { a as ToolBodyMode } from './types-BzeE37Ze.js';
3
3
 
4
4
  declare const MAX_PREVIEW_LINES = 3;
5
5
  interface TruncatedContentProps {
@@ -5,7 +5,7 @@ import {
5
5
  getNoopInteractionBus,
6
6
  resolveToolBody,
7
7
  useInteractionBus
8
- } from "./chunk-OV6UUIA3.js";
8
+ } from "./chunk-VYXHVGJU.js";
9
9
  import {
10
10
  DEFAULT_SESSION_VIEW_OPTIONS,
11
11
  MultiSessionStoreContext,
@@ -22,9 +22,10 @@ import {
22
22
  useNodeTyped,
23
23
  usePendingPermissionForTool,
24
24
  useSessionStatus,
25
+ useSessionStoreApi,
25
26
  useSessionViewOptions,
26
27
  useToolDisplayOptions
27
- } from "./chunk-N2OSBCFN.js";
28
+ } from "./chunk-RWKNI52H.js";
28
29
  import {
29
30
  classifyToolResultSoftKind,
30
31
  createDefaultToolRegistry,
@@ -1560,24 +1561,295 @@ function PermissionCard({ nodeId }) {
1560
1561
  );
1561
1562
  }
1562
1563
 
1564
+ // src/view/nodes/AskUserQuestionCard.tsx
1565
+ import { useId as useId2, useMemo as useMemo2, useState as useState10 } from "react";
1566
+ import { Fragment as Fragment2, jsx as jsx18, jsxs as jsxs14 } from "react/jsx-runtime";
1567
+ function setUserQuestionStatus(store, nodeId, status, errorMessage = null) {
1568
+ const tree = store.getState().tree;
1569
+ const node = tree.byId[nodeId];
1570
+ if (!node || node.kind !== "user_question") return;
1571
+ store.setState({
1572
+ tree: {
1573
+ ...tree,
1574
+ byId: {
1575
+ ...tree.byId,
1576
+ [nodeId]: { ...node, status, errorMessage }
1577
+ }
1578
+ }
1579
+ });
1580
+ }
1581
+ function AskUserQuestionCard({ nodeId }) {
1582
+ const node = useNodeTyped(nodeId, "user_question");
1583
+ const bus = useInteractionBus();
1584
+ const store = useSessionStoreApi();
1585
+ const questionHeadingId = useId2();
1586
+ const [index, setIndex] = useState10(0);
1587
+ const [answers, setAnswers] = useState10({});
1588
+ const [otherText, setOtherText] = useState10({});
1589
+ const [multiSelected, setMultiSelected] = useState10({});
1590
+ const [submitting, setSubmitting] = useState10(false);
1591
+ const [localError, setLocalError] = useState10(null);
1592
+ const questions = node?.questions ?? [];
1593
+ const current = questions[index];
1594
+ const isLast = index >= questions.length - 1;
1595
+ const header = useMemo2(() => {
1596
+ if (!current) return "Ask user";
1597
+ return current.header ? `Ask user \xB7 ${current.header}` : "Ask user";
1598
+ }, [current]);
1599
+ if (!node) return null;
1600
+ const terminal = node.status === "resolved" || node.status === "rejected";
1601
+ const inactive = terminal || submitting || node.status === "submitting";
1602
+ const setSingle = (label) => {
1603
+ if (!current || inactive) return;
1604
+ setAnswers((prev) => ({ ...prev, [current.question]: label }));
1605
+ };
1606
+ const toggleMulti = (label) => {
1607
+ if (!current || inactive) return;
1608
+ setMultiSelected((prev) => {
1609
+ const cur = prev[current.question] ?? [];
1610
+ const next = cur.includes(label) ? cur.filter((x) => x !== label) : [...cur, label];
1611
+ return { ...prev, [current.question]: next };
1612
+ });
1613
+ };
1614
+ const commitCurrentAnswer = () => {
1615
+ if (!current) return "No question";
1616
+ if (current.multiSelect) {
1617
+ const labels = multiSelected[current.question] ?? [];
1618
+ const other = (otherText[current.question] ?? "").trim();
1619
+ const parts = [...labels];
1620
+ if (answers[current.question] === "__other__" || other) {
1621
+ if (!other) return "Other text required";
1622
+ parts.push(other);
1623
+ }
1624
+ if (parts.length === 0) return "Select at least one option";
1625
+ setAnswers((prev) => ({ ...prev, [current.question]: parts.join(", ") }));
1626
+ return null;
1627
+ }
1628
+ const chosen = answers[current.question];
1629
+ if (!chosen) return "Select an option";
1630
+ if (chosen === "__other__") {
1631
+ const other = (otherText[current.question] ?? "").trim();
1632
+ if (!other) return "Other text required";
1633
+ setAnswers((prev) => ({ ...prev, [current.question]: other }));
1634
+ }
1635
+ return null;
1636
+ };
1637
+ const buildAnswersSnapshot = () => {
1638
+ const err = commitCurrentAnswer();
1639
+ if (err) {
1640
+ setLocalError(err);
1641
+ return null;
1642
+ }
1643
+ const next = { ...answers };
1644
+ if (current) {
1645
+ if (current.multiSelect) {
1646
+ const labels = multiSelected[current.question] ?? [];
1647
+ const other = (otherText[current.question] ?? "").trim();
1648
+ const parts = [...labels];
1649
+ if (answers[current.question] === "__other__" || other) {
1650
+ if (other) parts.push(other);
1651
+ }
1652
+ next[current.question] = parts.join(", ");
1653
+ } else if (answers[current.question] === "__other__") {
1654
+ next[current.question] = (otherText[current.question] ?? "").trim();
1655
+ }
1656
+ }
1657
+ for (const q of questions) {
1658
+ if (!next[q.question]?.trim()) {
1659
+ setLocalError("Please answer all questions");
1660
+ return null;
1661
+ }
1662
+ }
1663
+ setLocalError(null);
1664
+ return next;
1665
+ };
1666
+ const onNext = () => {
1667
+ const err = commitCurrentAnswer();
1668
+ if (err) {
1669
+ setLocalError(err);
1670
+ return;
1671
+ }
1672
+ setLocalError(null);
1673
+ setIndex((i) => Math.min(i + 1, questions.length - 1));
1674
+ };
1675
+ const onSubmit = async () => {
1676
+ const snapshot = buildAnswersSnapshot();
1677
+ if (!snapshot) return;
1678
+ setSubmitting(true);
1679
+ setLocalError(null);
1680
+ setUserQuestionStatus(store, nodeId, "submitting");
1681
+ try {
1682
+ await bus.resolveUserQuestions({
1683
+ sessionId: node.sessionId,
1684
+ toolCallId: node.toolCallId,
1685
+ answers: snapshot
1686
+ });
1687
+ setUserQuestionStatus(store, nodeId, "resolved");
1688
+ } catch (e) {
1689
+ const message = e instanceof Error ? e.message : String(e);
1690
+ setLocalError(message);
1691
+ setUserQuestionStatus(store, nodeId, "pending", message);
1692
+ } finally {
1693
+ setSubmitting(false);
1694
+ }
1695
+ };
1696
+ const onReject = async () => {
1697
+ setSubmitting(true);
1698
+ setLocalError(null);
1699
+ setUserQuestionStatus(store, nodeId, "submitting");
1700
+ try {
1701
+ await bus.resolveUserQuestions({
1702
+ sessionId: node.sessionId,
1703
+ toolCallId: node.toolCallId,
1704
+ reject: true
1705
+ });
1706
+ setUserQuestionStatus(store, nodeId, "rejected");
1707
+ } catch (e) {
1708
+ const message = e instanceof Error ? e.message : String(e);
1709
+ setLocalError(message);
1710
+ setUserQuestionStatus(store, nodeId, "pending", message);
1711
+ } finally {
1712
+ setSubmitting(false);
1713
+ }
1714
+ };
1715
+ const singleValue = current ? answers[current.question] : void 0;
1716
+ const multiValues = current ? multiSelected[current.question] ?? [] : [];
1717
+ return /* @__PURE__ */ jsxs14(
1718
+ "div",
1719
+ {
1720
+ className: "lax-user-question-card",
1721
+ "data-status": terminal ? node.status : submitting ? "submitting" : "pending",
1722
+ "data-tool-call-id": node.toolCallId,
1723
+ children: [
1724
+ /* @__PURE__ */ jsxs14("div", { className: "lax-user-question-card__header", children: [
1725
+ /* @__PURE__ */ jsx18("span", { className: "lax-user-question-card__label", children: header }),
1726
+ questions.length > 1 ? /* @__PURE__ */ jsxs14("span", { className: "lax-user-question-card__progress", children: [
1727
+ index + 1,
1728
+ "/",
1729
+ questions.length
1730
+ ] }) : null
1731
+ ] }),
1732
+ current ? /* @__PURE__ */ jsxs14(Fragment2, { children: [
1733
+ /* @__PURE__ */ jsx18("div", { className: "lax-user-question-card__question", id: questionHeadingId, children: current.question }),
1734
+ /* @__PURE__ */ jsxs14(
1735
+ "div",
1736
+ {
1737
+ className: "lax-user-question-card__options",
1738
+ role: "group",
1739
+ "aria-labelledby": questionHeadingId,
1740
+ children: [
1741
+ current.options.map((opt) => {
1742
+ const selected = current.multiSelect ? multiValues.includes(opt.label) : singleValue === opt.label;
1743
+ return /* @__PURE__ */ jsxs14("label", { className: "lax-user-question-card__option", children: [
1744
+ /* @__PURE__ */ jsx18(
1745
+ "input",
1746
+ {
1747
+ type: current.multiSelect ? "checkbox" : "radio",
1748
+ name: `${node.id}-${index}`,
1749
+ checked: selected,
1750
+ disabled: inactive,
1751
+ onChange: () => current.multiSelect ? toggleMulti(opt.label) : setSingle(opt.label)
1752
+ }
1753
+ ),
1754
+ /* @__PURE__ */ jsxs14("span", { children: [
1755
+ /* @__PURE__ */ jsx18("strong", { children: opt.label }),
1756
+ opt.description ? /* @__PURE__ */ jsxs14("span", { className: "lax-user-question-card__desc", children: [
1757
+ " \u2014 ",
1758
+ opt.description
1759
+ ] }) : null
1760
+ ] })
1761
+ ] }, opt.label);
1762
+ }),
1763
+ /* @__PURE__ */ jsxs14("label", { className: "lax-user-question-card__option", children: [
1764
+ /* @__PURE__ */ jsx18(
1765
+ "input",
1766
+ {
1767
+ type: current.multiSelect ? "checkbox" : "radio",
1768
+ name: `${node.id}-${index}`,
1769
+ checked: current.multiSelect ? Boolean((otherText[current.question] ?? "").trim()) || singleValue === "__other__" : singleValue === "__other__",
1770
+ disabled: inactive,
1771
+ onChange: () => {
1772
+ if (current.multiSelect) {
1773
+ setAnswers((prev) => ({ ...prev, [current.question]: "__other__" }));
1774
+ } else {
1775
+ setSingle("__other__");
1776
+ }
1777
+ }
1778
+ }
1779
+ ),
1780
+ /* @__PURE__ */ jsx18("span", { children: "Other\u2026" })
1781
+ ] }),
1782
+ (singleValue === "__other__" || current.multiSelect) && /* @__PURE__ */ jsx18(
1783
+ "input",
1784
+ {
1785
+ className: "lax-user-question-card__other",
1786
+ type: "text",
1787
+ placeholder: "Custom answer",
1788
+ disabled: inactive,
1789
+ "aria-label": "Custom answer",
1790
+ value: otherText[current.question] ?? "",
1791
+ onChange: (e) => setOtherText((prev) => ({ ...prev, [current.question]: e.target.value }))
1792
+ }
1793
+ )
1794
+ ]
1795
+ }
1796
+ )
1797
+ ] }) : /* @__PURE__ */ jsx18("div", { className: "lax-user-question-card__question", children: "No questions" }),
1798
+ (localError || node.errorMessage) && /* @__PURE__ */ jsx18("div", { className: "lax-user-question-card__error", role: "alert", children: localError || node.errorMessage }),
1799
+ terminal ? /* @__PURE__ */ jsx18("div", { className: "lax-user-question-card__resolved", children: node.status === "rejected" ? "Rejected" : "Submitted" }) : /* @__PURE__ */ jsxs14("div", { className: "lax-user-question-card__actions", children: [
1800
+ /* @__PURE__ */ jsx18(
1801
+ "button",
1802
+ {
1803
+ type: "button",
1804
+ className: "lax-user-question-card__reject",
1805
+ disabled: submitting,
1806
+ onClick: () => void onReject(),
1807
+ children: "Reject"
1808
+ }
1809
+ ),
1810
+ !isLast ? /* @__PURE__ */ jsx18(
1811
+ "button",
1812
+ {
1813
+ type: "button",
1814
+ className: "lax-user-question-card__next",
1815
+ disabled: submitting,
1816
+ onClick: onNext,
1817
+ children: "Next"
1818
+ }
1819
+ ) : /* @__PURE__ */ jsx18(
1820
+ "button",
1821
+ {
1822
+ type: "button",
1823
+ className: "lax-user-question-card__submit",
1824
+ disabled: submitting,
1825
+ onClick: () => void onSubmit(),
1826
+ children: submitting ? "Submitting\u2026" : "Submit"
1827
+ }
1828
+ )
1829
+ ] })
1830
+ ]
1831
+ }
1832
+ );
1833
+ }
1834
+
1563
1835
  // src/view/nodes/MemorySavedNode.tsx
1564
- import { jsx as jsx18, jsxs as jsxs14 } from "react/jsx-runtime";
1836
+ import { jsx as jsx19, jsxs as jsxs15 } from "react/jsx-runtime";
1565
1837
  function MemorySavedRow({ nodeId }) {
1566
1838
  const node = useNodeTyped(nodeId, "memory_saved");
1567
1839
  if (!node) return null;
1568
1840
  const hasPaths = node.writtenPaths.length > 0;
1569
- return /* @__PURE__ */ jsxs14(
1841
+ return /* @__PURE__ */ jsxs15(
1570
1842
  "details",
1571
1843
  {
1572
1844
  className: "lax-memory-saved",
1573
1845
  "data-testid": "lax-memory-saved",
1574
1846
  "data-node-id": nodeId,
1575
1847
  children: [
1576
- /* @__PURE__ */ jsxs14("summary", { className: "lax-memory-saved__summary", children: [
1577
- /* @__PURE__ */ jsx18("span", { className: "lax-memory-saved__icon", "aria-hidden": "true", children: "\u{1F4BE}" }),
1578
- /* @__PURE__ */ jsx18("span", { className: "lax-memory-saved__hint", children: node.displayHint })
1848
+ /* @__PURE__ */ jsxs15("summary", { className: "lax-memory-saved__summary", children: [
1849
+ /* @__PURE__ */ jsx19("span", { className: "lax-memory-saved__icon", "aria-hidden": "true", children: "\u{1F4BE}" }),
1850
+ /* @__PURE__ */ jsx19("span", { className: "lax-memory-saved__hint", children: node.displayHint })
1579
1851
  ] }),
1580
- hasPaths ? /* @__PURE__ */ jsx18("ul", { className: "lax-memory-saved__paths", children: node.writtenPaths.map((p) => /* @__PURE__ */ jsx18("li", { className: "lax-memory-saved__path", children: /* @__PURE__ */ jsx18("code", { children: p }) }, p)) }) : null
1852
+ hasPaths ? /* @__PURE__ */ jsx19("ul", { className: "lax-memory-saved__paths", children: node.writtenPaths.map((p) => /* @__PURE__ */ jsx19("li", { className: "lax-memory-saved__path", children: /* @__PURE__ */ jsx19("code", { children: p }) }, p)) }) : null
1581
1853
  ]
1582
1854
  }
1583
1855
  );
@@ -1592,6 +1864,7 @@ var DEFAULT_WIDGETS = /* @__PURE__ */ new Map([
1592
1864
  ["error", ErrorCard],
1593
1865
  ["unknown", UnknownCard],
1594
1866
  ["permission", PermissionCard],
1867
+ ["user_question", AskUserQuestionCard],
1595
1868
  ["memory_saved", MemorySavedRow]
1596
1869
  ]);
1597
1870
  var NodeRegistry = class _NodeRegistry {
@@ -1797,18 +2070,18 @@ function createActiveSessionBridge(multiStore) {
1797
2070
  }
1798
2071
 
1799
2072
  // src/view/MultiAgentSession.tsx
1800
- import { useEffect as useEffect8, useMemo as useMemo2, useRef as useRef7 } from "react";
1801
- import { jsx as jsx19, jsxs as jsxs15 } from "react/jsx-runtime";
2073
+ import { useEffect as useEffect8, useMemo as useMemo3, useRef as useRef7 } from "react";
2074
+ import { jsx as jsx20, jsxs as jsxs16 } from "react/jsx-runtime";
1802
2075
  function DebugPanel() {
1803
2076
  const status = useSessionStatus();
1804
2077
  const errors = useInternalErrors();
1805
2078
  if (errors.length === 0) return null;
1806
- return /* @__PURE__ */ jsxs15("div", { className: "lax-debug-panel", "data-testid": "lax-debug-panel", children: [
1807
- /* @__PURE__ */ jsxs15("div", { children: [
2079
+ return /* @__PURE__ */ jsxs16("div", { className: "lax-debug-panel", "data-testid": "lax-debug-panel", children: [
2080
+ /* @__PURE__ */ jsxs16("div", { children: [
1808
2081
  "status: ",
1809
2082
  status
1810
2083
  ] }),
1811
- /* @__PURE__ */ jsx19("ul", { children: errors.map((err, i) => /* @__PURE__ */ jsxs15("li", { children: [
2084
+ /* @__PURE__ */ jsx20("ul", { children: errors.map((err, i) => /* @__PURE__ */ jsxs16("li", { children: [
1812
2085
  "[",
1813
2086
  err.eventType,
1814
2087
  "] ",
@@ -1851,19 +2124,19 @@ function MultiAgentSession({
1851
2124
  multiStoreRef.current.getState().ensureSession(cfg.sessionId, cfg.initialEvents);
1852
2125
  }
1853
2126
  }
1854
- const registryRef = useMemo2(() => registry ?? createDefaultRegistry(), [registry]);
1855
- const busRef = useMemo2(
2127
+ const registryRef = useMemo3(() => registry ?? createDefaultRegistry(), [registry]);
2128
+ const busRef = useMemo3(
1856
2129
  () => interactionBus ?? getNoopInteractionBus(),
1857
2130
  [interactionBus]
1858
2131
  );
1859
- const toolDisplayRef = useMemo2(
2132
+ const toolDisplayRef = useMemo3(
1860
2133
  () => ({
1861
2134
  registry: toolDisplayRegistry ?? createDefaultToolRegistry(),
1862
2135
  defaultBodyMode
1863
2136
  }),
1864
2137
  [toolDisplayRegistry, defaultBodyMode]
1865
2138
  );
1866
- const sessionViewRef = useMemo2(
2139
+ const sessionViewRef = useMemo3(
1867
2140
  () => ({
1868
2141
  ...DEFAULT_SESSION_VIEW_OPTIONS,
1869
2142
  groupParallelTools,
@@ -1899,8 +2172,8 @@ function MultiAgentSession({
1899
2172
  for (const c of controllers) c.abort();
1900
2173
  };
1901
2174
  }, [sessions, onError]);
1902
- return /* @__PURE__ */ jsx19(MultiSessionStoreContext.Provider, { value: multiStoreRef.current, children: /* @__PURE__ */ jsx19(SessionStoreContext.Provider, { value: bridgeRef.current, children: /* @__PURE__ */ jsx19(InteractionBusContext.Provider, { value: busRef, children: /* @__PURE__ */ jsx19(NodeRegistryContext.Provider, { value: registryRef, children: /* @__PURE__ */ jsx19(MarkdownRendererContext.Provider, { value: markdownRenderer, children: /* @__PURE__ */ jsx19(ToolDisplayOptionsContext.Provider, { value: toolDisplayRef, children: /* @__PURE__ */ jsx19(SessionViewOptionsContext.Provider, { value: sessionViewRef, children: /* @__PURE__ */ jsxs15("div", { className: "lax-agent-session lax-multi-agent-session", "data-testid": "lax-multi-agent-session", children: [
1903
- children ?? /* @__PURE__ */ jsx19(
2175
+ return /* @__PURE__ */ jsx20(MultiSessionStoreContext.Provider, { value: multiStoreRef.current, children: /* @__PURE__ */ jsx20(SessionStoreContext.Provider, { value: bridgeRef.current, children: /* @__PURE__ */ jsx20(InteractionBusContext.Provider, { value: busRef, children: /* @__PURE__ */ jsx20(NodeRegistryContext.Provider, { value: registryRef, children: /* @__PURE__ */ jsx20(MarkdownRendererContext.Provider, { value: markdownRenderer, children: /* @__PURE__ */ jsx20(ToolDisplayOptionsContext.Provider, { value: toolDisplayRef, children: /* @__PURE__ */ jsx20(SessionViewOptionsContext.Provider, { value: sessionViewRef, children: /* @__PURE__ */ jsxs16("div", { className: "lax-agent-session lax-multi-agent-session", "data-testid": "lax-multi-agent-session", children: [
2176
+ children ?? /* @__PURE__ */ jsx20(
1904
2177
  SessionTimeline,
1905
2178
  {
1906
2179
  virtualized,
@@ -1908,7 +2181,7 @@ function MultiAgentSession({
1908
2181
  groupParallelTools
1909
2182
  }
1910
2183
  ),
1911
- debug ? /* @__PURE__ */ jsx19(DebugPanel, {}) : null
2184
+ debug ? /* @__PURE__ */ jsx20(DebugPanel, {}) : null
1912
2185
  ] }) }) }) }) }) }) }) });
1913
2186
  }
1914
2187
 
@@ -1932,10 +2205,11 @@ export {
1932
2205
  ErrorCard,
1933
2206
  UnknownCard,
1934
2207
  PermissionCard,
2208
+ AskUserQuestionCard,
1935
2209
  NodeRegistry,
1936
2210
  createDefaultRegistry,
1937
2211
  createMultiSessionStore,
1938
2212
  createActiveSessionBridge,
1939
2213
  MultiAgentSession
1940
2214
  };
1941
- //# sourceMappingURL=chunk-TSZ6GVSA.js.map
2215
+ //# sourceMappingURL=chunk-AMUGAG7U.js.map