@copilotkit/core 1.77.1 → 1.78.0

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
@@ -4806,6 +4806,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4806
4806
  const MAX_EVENT_BYTES = 16 * 1024;
4807
4807
  const byteLength = (value) => new TextEncoder().encode(JSON.stringify(value)).byteLength;
4808
4808
  const reconnectDelay = (0, _copilotkit_shared.phoenixExponentialBackoff)(1e3, 1e4);
4809
+ const SETUP_HINTS = {
4810
+ RUNTIME_REQUIRED: "Set runtimeUrl: capture connects through the CopilotKit runtime.",
4811
+ INTELLIGENCE_RUNTIME_REQUIRED: "Configure the CopilotRuntime with `intelligence` to accept capture.",
4812
+ CONNECTION_FAILED: "Check that the CopilotRuntime is configured with `intelligence` and valid Intelligence credentials, and check the runtime logs.",
4813
+ IDENTITY_REQUIRED: "The runtime could not identify the user. Configure `identifyUser` on the CopilotRuntime and send the app's session with runtime requests.",
4814
+ TRAJECTORIES_NOT_ENABLED: "Trajectories are not enabled for this Intelligence project.",
4815
+ TRAJECTORIES_UNAVAILABLE: "This Intelligence deployment does not serve Trajectory capture.",
4816
+ TRAJECTORIES_ENTITLEMENT_UNAVAILABLE: "Intelligence could not confirm that Trajectories are enabled for this project; try again later.",
4817
+ MARKETPLACE_LICENSE_REQUIRED: "Trajectory capture requires a CopilotKit license for this project."
4818
+ };
4809
4819
  function isObject(value) {
4810
4820
  return typeof value === "object" && value !== null;
4811
4821
  }
@@ -4818,6 +4828,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4818
4828
  function isGrant(value) {
4819
4829
  return isObject(value) && typeof value.joinToken === "string" && value.joinToken.length > 0 && isObject(value.realtime) && typeof value.realtime.clientUrl === "string" && value.realtime.clientUrl.length > 0 && typeof value.realtime.topic === "string" && value.realtime.topic.length > 0;
4820
4830
  }
4831
+ const JOIN_REFUSAL_CODES = {
4832
+ trajectories_unavailable: "TRAJECTORIES_UNAVAILABLE",
4833
+ trajectories_not_enabled: "TRAJECTORIES_NOT_ENABLED",
4834
+ entitlement_unavailable: "TRAJECTORIES_ENTITLEMENT_UNAVAILABLE",
4835
+ marketplace_license_required: "MARKETPLACE_LICENSE_REQUIRED"
4836
+ };
4837
+ function joinErrorCode(value) {
4838
+ const reason = isObject(value) ? value.reason : void 0;
4839
+ const code = typeof reason === "string" && Object.hasOwn(JOIN_REFUSAL_CODES, reason) ? JOIN_REFUSAL_CODES[reason] : void 0;
4840
+ return code !== null && code !== void 0 ? code : errorCode(value, "JOIN_FAILED");
4841
+ }
4821
4842
  function errorCode(value, fallback) {
4822
4843
  return isObject(value) && typeof value.code === "string" && /^[A-Z][A-Z0-9_]{0,63}$/.test(value.code) ? value.code : fallback;
4823
4844
  }
@@ -4827,6 +4848,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4827
4848
  this.core = core;
4828
4849
  this.onChange = onChange;
4829
4850
  _defineProperty(this, "session", void 0);
4851
+ _defineProperty(this, "warned", /* @__PURE__ */ new Set());
4830
4852
  _defineProperty(this, "nextSeq", Math.floor(Date.now()) * 1e3);
4831
4853
  }
4832
4854
  get trajectoryId() {
@@ -4959,9 +4981,23 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4959
4981
  window.removeEventListener("offline", session.onOffline);
4960
4982
  window.removeEventListener("online", session.onOnline);
4961
4983
  }
4984
+ if (result.status === "error" && result.code !== "CANCELLED") this.warnEnded(session, result.code);
4962
4985
  session.resolve(result);
4963
4986
  this.onChange();
4964
4987
  }
4988
+ /**
4989
+ * Without an app handler, a capture that ends on its own would otherwise fail
4990
+ * silently. Each outcome warns once per Core, so StrictMode replays and
4991
+ * repeated starts against the same misconfigured Runtime stay quiet.
4992
+ */
4993
+ warnEnded(session, code) {
4994
+ if (session.config.onError !== void 0) return;
4995
+ const summary = session.started ? `Trajectory capture stopped (${code}).` : `Trajectory capture did not start (${code}).`;
4996
+ if (this.warned.has(summary)) return;
4997
+ this.warned.add(summary);
4998
+ const hint = SETUP_HINTS[code];
4999
+ console.warn(`[CopilotKit] ${summary}${hint === void 0 ? "" : ` ${hint}`} Set learning.onError to handle capture errors in the app.`);
5000
+ }
4965
5001
  cleanup(session, connection) {
4966
5002
  session.connection = void 0;
4967
5003
  clearTimeout(connection.timer);
@@ -5110,7 +5146,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5110
5146
  } catch (_unused3) {
5111
5147
  this.fail(session, connection, "CAPTURE_FAILED", false);
5112
5148
  }
5113
- }).receive("error", (joinError) => this.fail(session, connection, errorCode(joinError, "JOIN_FAILED"))).receive("timeout", () => this.fail(session, connection, "CONNECTION_TIMEOUT"));
5149
+ }).receive("error", (joinError) => this.fail(session, connection, joinErrorCode(joinError))).receive("timeout", () => this.fail(session, connection, "CONNECTION_TIMEOUT"));
5114
5150
  } catch (_unused4) {
5115
5151
  this.fail(session, connection, "CONNECTION_FAILED");
5116
5152
  }