@copilotkit/core 1.68.3-canary.1787220377 → 1.68.3

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
@@ -618,6 +618,32 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
618
618
  }
619
619
  };
620
620
 
621
+ //#endregion
622
+ //#region src/utils/runtime-info-error.ts
623
+ /**
624
+ * Build the error for a failed runtime `/info` response, folding in whatever
625
+ * explanation the runtime sent back.
626
+ *
627
+ * The status alone cannot distinguish a wrong `runtimeUrl` from a transport
628
+ * mismatch, so the runtime answers the latter with a body naming the cause
629
+ * (see the handler's `single_route_envelope_against_multi_route_runtime`
630
+ * diagnostic). Discarding that body — as every `/info` caller used to — left
631
+ * the developer with a bare 404 and nothing to act on (OSS-882).
632
+ *
633
+ * A body that isn't JSON, or carries no string `message`, contributes nothing:
634
+ * the status is then the whole error.
635
+ */
636
+ async function runtimeInfoError(response) {
637
+ const base = `Runtime info request failed with status ${response.status}`;
638
+ let detail;
639
+ try {
640
+ const body = await response.clone().json();
641
+ const message = body === null || body === void 0 ? void 0 : body.message;
642
+ if (typeof message === "string" && message.trim().length > 0) detail = message.trim();
643
+ } catch (_unused) {}
644
+ return new Error(detail ? `${base}: ${detail}` : base);
645
+ }
646
+
621
647
  //#endregion
622
648
  //#region \0@oxc-project+runtime@0.112.0/helpers/checkPrivateRedeclaration.js
623
649
  function _checkPrivateRedeclaration(e, t) {
@@ -947,7 +973,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
947
973
  headers,
948
974
  ...this.credentials ? { credentials: this.credentials } : {}
949
975
  });
950
- if (!response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
976
+ if (!response.ok) throw await runtimeInfoError(response);
951
977
  return await response.json();
952
978
  }
953
979
  async fetchRuntimeInfoAutoDetect(headers) {
@@ -969,7 +995,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
969
995
  body: JSON.stringify({ method: "info" }),
970
996
  ...this.credentials ? { credentials: this.credentials } : {}
971
997
  });
972
- if (!response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
998
+ if (!response.ok) throw await runtimeInfoError(response);
973
999
  this.transport = "single";
974
1000
  this.singleEndpointUrl = this.runtimeUrl;
975
1001
  return await response.json();
@@ -1602,7 +1628,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1602
1628
  headers,
1603
1629
  ...credentials ? { credentials } : {}
1604
1630
  });
1605
- if (!response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
1631
+ if (!response.ok) throw await runtimeInfoError(response);
1606
1632
  return {
1607
1633
  runtimeInfo: await response.json(),
1608
1634
  resolvedTransport: "rest"
@@ -1615,7 +1641,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1615
1641
  body: JSON.stringify({ method: "info" }),
1616
1642
  ...credentials ? { credentials } : {}
1617
1643
  });
1618
- if (!response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
1644
+ if (!response.ok) throw await runtimeInfoError(response);
1619
1645
  return await response.json();
1620
1646
  }
1621
1647
  /**
@@ -3148,129 +3174,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3148
3174
  }
3149
3175
  };
3150
3176
 
3151
- //#endregion
3152
- //#region src/core/subagent-registry.ts
3153
- /**
3154
- * Tracks subagent lifecycle events (SUBAGENT_STARTED / FINISHED / ERROR) per
3155
- * owning agent so consumers can resolve a message's `subagentRunId` to a name,
3156
- * description, and running status.
3157
- *
3158
- * Modeled on {@link SuggestionEngine}: an in-memory `Record` keyed by (owning)
3159
- * agentId, mutated from streamed AG-UI events, made reactive by calling
3160
- * `notifySubscribers(onSubagentsChanged)` after every change. It owns its own
3161
- * per-agent `agent.subscribe` (like {@link StateManager}) so it is fully
3162
- * self-contained and adds no coupling to the state/message tracking path.
3163
- *
3164
- * No-op for runs without subagents (a normal LangGraph run never emits
3165
- * SUBAGENT_* events), so the registry simply stays empty.
3166
- */
3167
- var SubagentRegistry = class {
3168
- constructor(core) {
3169
- this.core = core;
3170
- _defineProperty(this, "_subagents", {});
3171
- _defineProperty(this, "agentSubscriptions", /* @__PURE__ */ new Map());
3172
- }
3173
- /**
3174
- * Subscribe to an agent's subagent lifecycle events. Idempotent per agentId:
3175
- * an existing subscription for the same agent is revoked and replaced.
3176
- */
3177
- subscribeToAgent(agent) {
3178
- if (!agent.agentId) return;
3179
- const agentId = agent.agentId;
3180
- const existingUnsubscribe = this.agentSubscriptions.get(agentId);
3181
- if (existingUnsubscribe) {
3182
- existingUnsubscribe();
3183
- this.agentSubscriptions.delete(agentId);
3184
- }
3185
- let revoked = false;
3186
- const { unsubscribe } = agent.subscribe({
3187
- onSubagentStartedEvent: ({ event }) => {
3188
- if (revoked) return;
3189
- this.handleStarted(agentId, event);
3190
- },
3191
- onSubagentFinishedEvent: ({ event }) => {
3192
- if (revoked) return;
3193
- this.handleFinished(agentId, event);
3194
- },
3195
- onSubagentErrorEvent: ({ event }) => {
3196
- if (revoked) return;
3197
- this.handleError(agentId, event);
3198
- }
3199
- });
3200
- this.agentSubscriptions.set(agentId, () => {
3201
- revoked = true;
3202
- unsubscribe();
3203
- });
3204
- }
3205
- /**
3206
- * Unsubscribe an agent's subscription (symmetric with StateManager cleanup).
3207
- */
3208
- unsubscribeFromAgent(agentId) {
3209
- const unsubscribe = this.agentSubscriptions.get(agentId);
3210
- if (unsubscribe) {
3211
- unsubscribe();
3212
- this.agentSubscriptions.delete(agentId);
3213
- }
3214
- }
3215
- /**
3216
- * Get the subagents observed for an owning agent, keyed by subagentRunId.
3217
- * Returns a fresh shallow copy each call so consumers (and React state) see
3218
- * a new reference when anything changed.
3219
- */
3220
- getSubagents(agentId) {
3221
- return { ...this._subagents[agentId] };
3222
- }
3223
- handleStarted(agentId, event) {
3224
- var _this$_subagents, _this$_subagents$agen;
3225
- const bucket = (_this$_subagents$agen = (_this$_subagents = this._subagents)[agentId]) !== null && _this$_subagents$agen !== void 0 ? _this$_subagents$agen : _this$_subagents[agentId] = {};
3226
- bucket[event.subagentRunId] = {
3227
- subagentRunId: event.subagentRunId,
3228
- name: event.name,
3229
- description: event.description,
3230
- parentSubagentRunId: event.parentSubagentRunId,
3231
- status: "running"
3232
- };
3233
- this.notifySubagentsChanged(agentId);
3234
- }
3235
- handleFinished(agentId, event) {
3236
- const bucket = this._subagents[agentId];
3237
- const existing = bucket === null || bucket === void 0 ? void 0 : bucket[event.subagentRunId];
3238
- if (!bucket || !existing) return;
3239
- bucket[event.subagentRunId] = {
3240
- ...existing,
3241
- status: "finished"
3242
- };
3243
- this.notifySubagentsChanged(agentId);
3244
- }
3245
- handleError(agentId, event) {
3246
- var _this$_subagents2, _this$_subagents2$age;
3247
- const bucket = (_this$_subagents2$age = (_this$_subagents2 = this._subagents)[agentId]) !== null && _this$_subagents2$age !== void 0 ? _this$_subagents2$age : _this$_subagents2[agentId] = {};
3248
- const existing = bucket[event.subagentRunId];
3249
- bucket[event.subagentRunId] = existing ? {
3250
- ...existing,
3251
- status: "error",
3252
- error: event.message
3253
- } : {
3254
- subagentRunId: event.subagentRunId,
3255
- name: event.subagentRunId,
3256
- status: "error",
3257
- error: event.message
3258
- };
3259
- this.notifySubagentsChanged(agentId);
3260
- }
3261
- async notifySubagentsChanged(agentId) {
3262
- const subagents = this.getSubagents(agentId);
3263
- await this.core.notifySubscribers((subscriber) => {
3264
- var _subscriber$onSubagen;
3265
- return (_subscriber$onSubagen = subscriber.onSubagentsChanged) === null || _subscriber$onSubagen === void 0 ? void 0 : _subscriber$onSubagen.call(subscriber, {
3266
- copilotkit: this.core,
3267
- agentId,
3268
- subagents
3269
- });
3270
- }, "Subscriber onSubagentsChanged error:");
3271
- }
3272
- };
3273
-
3274
3177
  //#endregion
3275
3178
  //#region src/core/thread-store-registry.ts
3276
3179
  var ThreadStoreRegistry = class {
@@ -4471,7 +4374,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4471
4374
  _defineProperty(this, "suggestionEngine", void 0);
4472
4375
  _defineProperty(this, "runHandler", void 0);
4473
4376
  _defineProperty(this, "stateManager", void 0);
4474
- _defineProperty(this, "subagentRegistry", void 0);
4475
4377
  _defineProperty(this, "threadStoreRegistry", void 0);
4476
4378
  _defineProperty(this, "_memoryStore", void 0);
4477
4379
  _defineProperty(this, "previousAgentIds", /* @__PURE__ */ new Set());
@@ -4484,7 +4386,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4484
4386
  this.suggestionEngine = new SuggestionEngine(this);
4485
4387
  this.runHandler = new RunHandler(this);
4486
4388
  this.stateManager = new StateManager(this);
4487
- this.subagentRegistry = new SubagentRegistry(this);
4488
4389
  this.threadStoreRegistry = new ThreadStoreRegistry(this);
4489
4390
  this.agentRegistry.initialize(agents__unsafe_dev_only);
4490
4391
  this.runHandler.initialize(tools);
@@ -4499,10 +4400,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4499
4400
  },
4500
4401
  onAgentsChanged: ({ agents }) => {
4501
4402
  Object.values(agents).forEach((agent) => {
4502
- if (agent.agentId) {
4503
- this.stateManager.subscribeToAgent(agent);
4504
- this.subagentRegistry.subscribeToAgent(agent);
4505
- }
4403
+ if (agent.agentId) this.stateManager.subscribeToAgent(agent);
4506
4404
  });
4507
4405
  const currentAgentIds = new Set(Object.keys(agents));
4508
4406
  for (const agentId of Object.keys(this.threadStoreRegistry.getAll())) if (this.previousAgentIds.has(agentId) && !currentAgentIds.has(agentId)) try {
@@ -4510,17 +4408,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4510
4408
  } catch (err) {
4511
4409
  console.error(`CopilotKitCore.onAgentsChanged: threadStoreRegistry.unregister failed for "${agentId}":`, err);
4512
4410
  }
4513
- for (const agentId of this.previousAgentIds) if (!currentAgentIds.has(agentId)) {
4514
- try {
4515
- this.stateManager.unsubscribeFromAgent(agentId);
4516
- } catch (err) {
4517
- console.error(`CopilotKitCore.onAgentsChanged: stateManager.unsubscribeFromAgent failed for "${agentId}":`, err);
4518
- }
4519
- try {
4520
- this.subagentRegistry.unsubscribeFromAgent(agentId);
4521
- } catch (err) {
4522
- console.error(`CopilotKitCore.onAgentsChanged: subagentRegistry.unsubscribeFromAgent failed for "${agentId}":`, err);
4523
- }
4411
+ for (const agentId of this.previousAgentIds) if (!currentAgentIds.has(agentId)) try {
4412
+ this.stateManager.unsubscribeFromAgent(agentId);
4413
+ } catch (err) {
4414
+ console.error(`CopilotKitCore.onAgentsChanged: stateManager.unsubscribeFromAgent failed for "${agentId}":`, err);
4524
4415
  }
4525
4416
  this.previousAgentIds = currentAgentIds;
4526
4417
  }
@@ -4900,16 +4791,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4900
4791
  return this.suggestionEngine.getSuggestions(agentId);
4901
4792
  }
4902
4793
  /**
4903
- * Subagent registry (delegated to SubagentRegistry).
4904
- *
4905
- * Returns the subagents observed for an owning agent during its run(s),
4906
- * keyed by `subagentRunId`, each carrying `name` / `description` / `status`.
4907
- * Empty for runs that never emit SUBAGENT_* events.
4908
- */
4909
- getSubagents(agentId) {
4910
- return this.subagentRegistry.getSubagents(agentId);
4911
- }
4912
- /**
4913
4794
  * Tool management (delegated to RunHandler)
4914
4795
  */
4915
4796
  addTool(tool) {
@@ -6253,7 +6134,6 @@ exports.MemoryError = MemoryError;
6253
6134
  exports.ProxiedCopilotRuntimeAgent = ProxiedCopilotRuntimeAgent;
6254
6135
  exports.RunHandler = RunHandler;
6255
6136
  exports.StateManager = StateManager;
6256
- exports.SubagentRegistry = SubagentRegistry;
6257
6137
  exports.SuggestionEngine = SuggestionEngine;
6258
6138
  exports.ToolCallStatus = ToolCallStatus;
6259
6139
  exports.completePartialMarkdown = completePartialMarkdown;