@tangle-network/agent-app 0.63.5 → 0.63.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,7 +1,7 @@
1
1
  import {
2
2
  ReasoningRow,
3
3
  chatToolCallPart
4
- } from "../chunk-4CALWPN5.js";
4
+ } from "../chunk-L6BS2XTE.js";
5
5
  import "../chunk-3HUFJ5LO.js";
6
6
  import "../chunk-UHSUY6H6.js";
7
7
  import "../chunk-7PULOECS.js";
@@ -1723,14 +1723,11 @@ function parseDecisionResult(value) {
1723
1723
  ...body.effectPending === true ? { effectPending: true } : {}
1724
1724
  };
1725
1725
  }
1726
- async function responseBody(response) {
1727
- return recordOf(await response.json().catch(() => null)) ?? {};
1728
- }
1729
1726
  function createDurablePlanDecisionClient(options) {
1730
1727
  const fetchImpl = options.fetchImpl ?? fetch;
1731
1728
  const urlFor = (input) => typeof options.url === "function" ? options.url(input) : options.url;
1732
1729
  const read = async (response) => {
1733
- const body = await responseBody(response);
1730
+ const body = recordOf(await response.json().catch(() => null)) ?? {};
1734
1731
  const result = parseDecisionResult(body);
1735
1732
  if (response.ok && result) return result;
1736
1733
  const currentPlan = readPlan(body.plan) ?? void 0;
@@ -1743,6 +1740,7 @@ function createDurablePlanDecisionClient(options) {
1743
1740
  );
1744
1741
  };
1745
1742
  return {
1743
+ scopeKey: options.scopeKey ?? (typeof options.url === "string" ? options.url : void 0),
1746
1744
  async current(input) {
1747
1745
  const rawUrl = urlFor(input);
1748
1746
  const url = new URL(rawUrl, globalThis.location?.origin ?? "http://localhost");
@@ -1802,6 +1800,11 @@ function useDurablePlanFlow(options) {
1802
1800
  const [restoreRetry, setRestoreRetry] = useState8(0);
1803
1801
  const advanceRestore = useCallback2(() => setRestoreRetry((value) => value + 1), []);
1804
1802
  const lifetime = useRef5(null);
1803
+ const scopeKey = options.scopeKey ?? options.client.scopeKey;
1804
+ const latest = useRef5(options);
1805
+ useLayoutEffect2(() => {
1806
+ latest.current = options;
1807
+ });
1805
1808
  useLayoutEffect2(() => {
1806
1809
  lifetime.current = {};
1807
1810
  restoration.current = { restored: null, inFlight: null, attempts: /* @__PURE__ */ new Map() };
@@ -1817,13 +1820,14 @@ function useDurablePlanFlow(options) {
1817
1820
  lifetime.current = null;
1818
1821
  restoration.current = { restored: null, inFlight: null, attempts: /* @__PURE__ */ new Map() };
1819
1822
  };
1820
- }, [options.plan.planId, options.plan.revision, options.client]);
1823
+ }, [options.plan.planId, options.plan.revision, scopeKey]);
1821
1824
  useEffect4(() => setPlan(options.plan), [options.plan]);
1822
1825
  const apply = useCallback2(async (result, context, decision) => {
1823
1826
  const active = () => lifetime.current === context;
1824
1827
  if (!active()) return;
1828
+ const options2 = latest.current;
1825
1829
  setPlan(result.plan);
1826
- options.onUpdated?.(result.plan);
1830
+ options2.onUpdated?.(result.plan);
1827
1831
  if (!active()) return;
1828
1832
  setEffectPending(result.effectPending === true);
1829
1833
  const receipt = result.followUp;
@@ -1831,12 +1835,12 @@ function useDurablePlanFlow(options) {
1831
1835
  restoration.current.restored = planDecisionKey(result.plan);
1832
1836
  return;
1833
1837
  }
1834
- if (!options.attachFollowUp) return;
1838
+ if (!options2.attachFollowUp) return;
1835
1839
  const currentAttachments = attachments.current;
1836
1840
  let pending = currentAttachments.get(receipt.receiptId);
1837
1841
  if (!pending) {
1838
1842
  pending = Promise.resolve().then(() => {
1839
- if (active()) return options.attachFollowUp(
1843
+ if (active()) return options2.attachFollowUp(
1840
1844
  receipt,
1841
1845
  result.plan,
1842
1846
  decision ?? (result.plan.status === "rejected" ? "rejected" : "approved")
@@ -1855,7 +1859,7 @@ function useDurablePlanFlow(options) {
1855
1859
  setAttachError(null);
1856
1860
  } catch (cause) {
1857
1861
  if (!active()) return;
1858
- if (!options.autoRestore) throw cause;
1862
+ if (!options2.autoRestore) throw cause;
1859
1863
  const key = planDecisionKey(result.plan);
1860
1864
  if (restoration.current.restored === key) restoration.current.restored = null;
1861
1865
  if (decision !== void 0) {
@@ -1864,7 +1868,7 @@ function useDurablePlanFlow(options) {
1864
1868
  advanceRestore();
1865
1869
  }
1866
1870
  }
1867
- }, [options.attachFollowUp, options.onUpdated, options.autoRestore, advanceRestore]);
1871
+ }, [advanceRestore]);
1868
1872
  const decide = useCallback2(async (decision, feedback) => {
1869
1873
  const context = lifetime.current;
1870
1874
  if (!context || decisionInFlight.current) return null;
@@ -1872,7 +1876,7 @@ function useDurablePlanFlow(options) {
1872
1876
  setDeciding(decision);
1873
1877
  setError(null);
1874
1878
  try {
1875
- const result = await options.client.decide({
1879
+ const result = await latest.current.client.decide({
1876
1880
  planId: plan.planId,
1877
1881
  revision: plan.revision,
1878
1882
  decision,
@@ -1885,7 +1889,7 @@ function useDurablePlanFlow(options) {
1885
1889
  if (lifetime.current !== context) return null;
1886
1890
  if (cause instanceof DurablePlanClientError && cause.currentPlan) {
1887
1891
  setPlan(cause.currentPlan);
1888
- options.onUpdated?.(cause.currentPlan);
1892
+ latest.current.onUpdated?.(cause.currentPlan);
1889
1893
  }
1890
1894
  setError(cause instanceof Error ? cause.message : "Could not decide the plan.");
1891
1895
  return null;
@@ -1895,14 +1899,14 @@ function useDurablePlanFlow(options) {
1895
1899
  setDeciding(null);
1896
1900
  }
1897
1901
  }
1898
- }, [apply, options.client, options.onUpdated, plan.planId, plan.revision]);
1902
+ }, [apply, plan.planId, plan.revision, scopeKey]);
1899
1903
  const restore = useCallback2(async () => {
1900
1904
  const context = lifetime.current;
1901
1905
  if (!context) return null;
1902
1906
  setRestoring(true);
1903
1907
  setError(null);
1904
1908
  try {
1905
- const result = await options.client.current({ planId: plan.planId, revision: plan.revision });
1909
+ const result = await latest.current.client.current({ planId: plan.planId, revision: plan.revision });
1906
1910
  if (lifetime.current !== context) return null;
1907
1911
  await apply(result, context);
1908
1912
  return lifetime.current === context ? result : null;
@@ -1913,7 +1917,7 @@ function useDurablePlanFlow(options) {
1913
1917
  } finally {
1914
1918
  if (lifetime.current === context) setRestoring(false);
1915
1919
  }
1916
- }, [apply, options.client, plan.planId, plan.revision]);
1920
+ }, [apply, plan.planId, plan.revision, scopeKey]);
1917
1921
  const retryAttach = useCallback2(() => {
1918
1922
  restoration.current.attempts.set(planDecisionKey(plan), 0);
1919
1923
  setAttachError(null);
@@ -8410,4 +8414,4 @@ export {
8410
8414
  AgentProfileChoices,
8411
8415
  ComposerProfilePill
8412
8416
  };
8413
- //# sourceMappingURL=chunk-4CALWPN5.js.map
8417
+ //# sourceMappingURL=chunk-L6BS2XTE.js.map