@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.mjs CHANGED
@@ -4641,6 +4641,16 @@ const MAX_BATCH_BYTES = 64 * 1024;
4641
4641
  const MAX_EVENT_BYTES = 16 * 1024;
4642
4642
  const byteLength = (value) => new TextEncoder().encode(JSON.stringify(value)).byteLength;
4643
4643
  const reconnectDelay = phoenixExponentialBackoff(1e3, 1e4);
4644
+ const SETUP_HINTS = {
4645
+ RUNTIME_REQUIRED: "Set runtimeUrl: capture connects through the CopilotKit runtime.",
4646
+ INTELLIGENCE_RUNTIME_REQUIRED: "Configure the CopilotRuntime with `intelligence` to accept capture.",
4647
+ CONNECTION_FAILED: "Check that the CopilotRuntime is configured with `intelligence` and valid Intelligence credentials, and check the runtime logs.",
4648
+ IDENTITY_REQUIRED: "The runtime could not identify the user. Configure `identifyUser` on the CopilotRuntime and send the app's session with runtime requests.",
4649
+ TRAJECTORIES_NOT_ENABLED: "Trajectories are not enabled for this Intelligence project.",
4650
+ TRAJECTORIES_UNAVAILABLE: "This Intelligence deployment does not serve Trajectory capture.",
4651
+ TRAJECTORIES_ENTITLEMENT_UNAVAILABLE: "Intelligence could not confirm that Trajectories are enabled for this project; try again later.",
4652
+ MARKETPLACE_LICENSE_REQUIRED: "Trajectory capture requires a CopilotKit license for this project."
4653
+ };
4644
4654
  function isObject(value) {
4645
4655
  return typeof value === "object" && value !== null;
4646
4656
  }
@@ -4653,12 +4663,23 @@ function isBatchAcknowledgement(value, eventCount) {
4653
4663
  function isGrant(value) {
4654
4664
  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;
4655
4665
  }
4666
+ const JOIN_REFUSAL_CODES = {
4667
+ trajectories_unavailable: "TRAJECTORIES_UNAVAILABLE",
4668
+ trajectories_not_enabled: "TRAJECTORIES_NOT_ENABLED",
4669
+ entitlement_unavailable: "TRAJECTORIES_ENTITLEMENT_UNAVAILABLE",
4670
+ marketplace_license_required: "MARKETPLACE_LICENSE_REQUIRED"
4671
+ };
4672
+ function joinErrorCode(value) {
4673
+ const reason = isObject(value) ? value.reason : void 0;
4674
+ return (typeof reason === "string" && Object.hasOwn(JOIN_REFUSAL_CODES, reason) ? JOIN_REFUSAL_CODES[reason] : void 0) ?? errorCode(value, "JOIN_FAILED");
4675
+ }
4656
4676
  function errorCode(value, fallback) {
4657
4677
  return isObject(value) && typeof value.code === "string" && /^[A-Z][A-Z0-9_]{0,63}$/.test(value.code) ? value.code : fallback;
4658
4678
  }
4659
4679
  /** Owns bounded, connected-only capture batches. Failed batches are never resent. */
4660
4680
  var TrajectoryConnection = class {
4661
4681
  session;
4682
+ warned = /* @__PURE__ */ new Set();
4662
4683
  nextSeq = Math.floor(Date.now()) * 1e3;
4663
4684
  constructor(core, onChange) {
4664
4685
  this.core = core;
@@ -4790,9 +4811,23 @@ var TrajectoryConnection = class {
4790
4811
  window.removeEventListener("offline", session.onOffline);
4791
4812
  window.removeEventListener("online", session.onOnline);
4792
4813
  }
4814
+ if (result.status === "error" && result.code !== "CANCELLED") this.warnEnded(session, result.code);
4793
4815
  session.resolve(result);
4794
4816
  this.onChange();
4795
4817
  }
4818
+ /**
4819
+ * Without an app handler, a capture that ends on its own would otherwise fail
4820
+ * silently. Each outcome warns once per Core, so StrictMode replays and
4821
+ * repeated starts against the same misconfigured Runtime stay quiet.
4822
+ */
4823
+ warnEnded(session, code) {
4824
+ if (session.config.onError !== void 0) return;
4825
+ const summary = session.started ? `Trajectory capture stopped (${code}).` : `Trajectory capture did not start (${code}).`;
4826
+ if (this.warned.has(summary)) return;
4827
+ this.warned.add(summary);
4828
+ const hint = SETUP_HINTS[code];
4829
+ console.warn(`[CopilotKit] ${summary}${hint === void 0 ? "" : ` ${hint}`} Set learning.onError to handle capture errors in the app.`);
4830
+ }
4796
4831
  cleanup(session, connection) {
4797
4832
  session.connection = void 0;
4798
4833
  clearTimeout(connection.timer);
@@ -4937,7 +4972,7 @@ var TrajectoryConnection = class {
4937
4972
  } catch {
4938
4973
  this.fail(session, connection, "CAPTURE_FAILED", false);
4939
4974
  }
4940
- }).receive("error", (joinError) => this.fail(session, connection, errorCode(joinError, "JOIN_FAILED"))).receive("timeout", () => this.fail(session, connection, "CONNECTION_TIMEOUT"));
4975
+ }).receive("error", (joinError) => this.fail(session, connection, joinErrorCode(joinError))).receive("timeout", () => this.fail(session, connection, "CONNECTION_TIMEOUT"));
4941
4976
  } catch {
4942
4977
  this.fail(session, connection, "CONNECTION_FAILED");
4943
4978
  }