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