@copilotkitnext/core 1.53.0 → 1.53.1-next.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.
package/dist/index.umd.js CHANGED
@@ -1831,26 +1831,18 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1831
1831
  return new IntelligenceAgent(this.config);
1832
1832
  }
1833
1833
  abortRun() {
1834
- if (!this.threadId) return;
1835
- if (typeof fetch === "undefined") {
1836
- this.cleanup();
1837
- return;
1838
- }
1839
- const { runtimeUrl, agentId, headers, credentials } = this.config;
1840
- const stopPath = `${runtimeUrl}/agent/${encodeURIComponent(agentId)}/stop/${encodeURIComponent(this.threadId)}`;
1841
- const origin = typeof window !== "undefined" && window.location ? window.location.origin : "http://localhost";
1842
- const stopUrl = new URL(stopPath, new URL(runtimeUrl, origin));
1843
- fetch(stopUrl.toString(), {
1844
- method: "POST",
1845
- headers: {
1846
- "Content-Type": "application/json",
1847
- ...headers
1848
- },
1849
- ...credentials ? { credentials } : {}
1850
- }).catch((error) => {
1851
- console.error("IntelligenceAgent: stop request failed", error);
1852
- });
1853
- this.cleanup();
1834
+ if (this.activeChannel && this.threadId) {
1835
+ const fallback = setTimeout(() => this.cleanup(), 5e3);
1836
+ const clear = () => {
1837
+ clearTimeout(fallback);
1838
+ this.cleanup();
1839
+ };
1840
+ this.activeChannel.push(_copilotkitnext_shared.AG_UI_CHANNEL_EVENT, {
1841
+ type: _ag_ui_client.EventType.CUSTOM,
1842
+ name: "stop",
1843
+ value: { threadId: this.threadId }
1844
+ }).receive("ok", clear).receive("error", clear).receive("timeout", clear);
1845
+ } else this.cleanup();
1854
1846
  }
1855
1847
  /**
1856
1848
  * Connect to a Phoenix channel scoped to the thread, trigger the run via
@@ -1865,7 +1857,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1865
1857
  return new rxjs.Observable((observer) => {
1866
1858
  var _this$config$socketPa;
1867
1859
  this.threadId = input.threadId;
1868
- const socket = new phoenix.Socket(this.config.url, { params: (_this$config$socketPa = this.config.socketParams) !== null && _this$config$socketPa !== void 0 ? _this$config$socketPa : {} });
1860
+ const socket = new phoenix.Socket(this.config.url, {
1861
+ params: (_this$config$socketPa = this.config.socketParams) !== null && _this$config$socketPa !== void 0 ? _this$config$socketPa : {},
1862
+ reconnectAfterMs: (0, _copilotkitnext_shared.phoenixExponentialBackoff)(100, 1e4),
1863
+ rejoinAfterMs: (0, _copilotkitnext_shared.phoenixExponentialBackoff)(1e3, 3e4)
1864
+ });
1869
1865
  this.socket = socket;
1870
1866
  socket.connect();
1871
1867
  const channel = socket.channel(`agent:${input.threadId}`, { runId: input.runId });
@@ -1881,6 +1877,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1881
1877
  this.cleanup();
1882
1878
  }
1883
1879
  });
1880
+ const MAX_CONSECUTIVE_ERRORS = 5;
1881
+ let consecutiveErrors = 0;
1882
+ socket.onError(() => {
1883
+ consecutiveErrors++;
1884
+ if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) {
1885
+ observer.error(/* @__PURE__ */ new Error(`WebSocket connection failed after ${MAX_CONSECUTIVE_ERRORS} consecutive errors`));
1886
+ this.cleanup();
1887
+ }
1888
+ });
1889
+ socket.onOpen(() => {
1890
+ consecutiveErrors = 0;
1891
+ });
1892
+ channel.onError(() => {});
1884
1893
  channel.join().receive("ok", () => {
1885
1894
  const { runtimeUrl, agentId, headers, credentials } = this.config;
1886
1895
  const runPath = `${runtimeUrl}/agent/${encodeURIComponent(agentId)}/run`;
@@ -1927,7 +1936,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1927
1936
  return new rxjs.Observable((observer) => {
1928
1937
  var _this$config$socketPa2;
1929
1938
  this.threadId = input.threadId;
1930
- const socket = new phoenix.Socket(this.config.url, { params: (_this$config$socketPa2 = this.config.socketParams) !== null && _this$config$socketPa2 !== void 0 ? _this$config$socketPa2 : {} });
1939
+ const socket = new phoenix.Socket(this.config.url, {
1940
+ params: (_this$config$socketPa2 = this.config.socketParams) !== null && _this$config$socketPa2 !== void 0 ? _this$config$socketPa2 : {},
1941
+ reconnectAfterMs: (0, _copilotkitnext_shared.phoenixExponentialBackoff)(100, 1e4),
1942
+ rejoinAfterMs: (0, _copilotkitnext_shared.phoenixExponentialBackoff)(1e3, 3e4)
1943
+ });
1931
1944
  this.socket = socket;
1932
1945
  socket.connect();
1933
1946
  const channel = socket.channel(`agent:${input.threadId}`, { mode: "connect" });
@@ -1939,6 +1952,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1939
1952
  this.cleanup();
1940
1953
  }
1941
1954
  });
1955
+ const MAX_CONSECUTIVE_ERRORS = 5;
1956
+ let consecutiveErrors = 0;
1957
+ socket.onError(() => {
1958
+ consecutiveErrors++;
1959
+ if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) {
1960
+ observer.error(/* @__PURE__ */ new Error(`WebSocket connection failed after ${MAX_CONSECUTIVE_ERRORS} consecutive errors`));
1961
+ this.cleanup();
1962
+ }
1963
+ });
1964
+ socket.onOpen(() => {
1965
+ consecutiveErrors = 0;
1966
+ });
1967
+ channel.onError(() => {});
1942
1968
  channel.join().receive("ok", () => {
1943
1969
  channel.push(_ag_ui_client.EventType.CUSTOM, {
1944
1970
  type: _ag_ui_client.EventType.CUSTOM,