@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.cjs CHANGED
@@ -572,6 +572,31 @@ var IntelligenceAgent = class IntelligenceAgent extends _ag_ui_client.AbstractAg
572
572
  }
573
573
  };
574
574
 
575
+ //#endregion
576
+ //#region src/utils/runtime-info-error.ts
577
+ /**
578
+ * Build the error for a failed runtime `/info` response, folding in whatever
579
+ * explanation the runtime sent back.
580
+ *
581
+ * The status alone cannot distinguish a wrong `runtimeUrl` from a transport
582
+ * mismatch, so the runtime answers the latter with a body naming the cause
583
+ * (see the handler's `single_route_envelope_against_multi_route_runtime`
584
+ * diagnostic). Discarding that body — as every `/info` caller used to — left
585
+ * the developer with a bare 404 and nothing to act on (OSS-882).
586
+ *
587
+ * A body that isn't JSON, or carries no string `message`, contributes nothing:
588
+ * the status is then the whole error.
589
+ */
590
+ async function runtimeInfoError(response) {
591
+ const base = `Runtime info request failed with status ${response.status}`;
592
+ let detail;
593
+ try {
594
+ const message = (await response.clone().json())?.message;
595
+ if (typeof message === "string" && message.trim().length > 0) detail = message.trim();
596
+ } catch {}
597
+ return new Error(detail ? `${base}: ${detail}` : base);
598
+ }
599
+
575
600
  //#endregion
576
601
  //#region src/agent.ts
577
602
  function hasHeaders(agent) {
@@ -861,7 +886,7 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
861
886
  headers,
862
887
  ...this.credentials ? { credentials: this.credentials } : {}
863
888
  });
864
- if (!response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
889
+ if (!response.ok) throw await runtimeInfoError(response);
865
890
  return await response.json();
866
891
  }
867
892
  async fetchRuntimeInfoAutoDetect(headers) {
@@ -883,7 +908,7 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
883
908
  body: JSON.stringify({ method: "info" }),
884
909
  ...this.credentials ? { credentials: this.credentials } : {}
885
910
  });
886
- if (!response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
911
+ if (!response.ok) throw await runtimeInfoError(response);
887
912
  this.transport = "single";
888
913
  this.singleEndpointUrl = this.runtimeUrl;
889
914
  return await response.json();
@@ -1492,7 +1517,7 @@ var AgentRegistry = class {
1492
1517
  headers,
1493
1518
  ...credentials ? { credentials } : {}
1494
1519
  });
1495
- if (!response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
1520
+ if (!response.ok) throw await runtimeInfoError(response);
1496
1521
  return {
1497
1522
  runtimeInfo: await response.json(),
1498
1523
  resolvedTransport: "rest"
@@ -1505,7 +1530,7 @@ var AgentRegistry = class {
1505
1530
  body: JSON.stringify({ method: "info" }),
1506
1531
  ...credentials ? { credentials } : {}
1507
1532
  });
1508
- if (!response.ok) throw new Error(`Runtime info request failed with status ${response.status}`);
1533
+ if (!response.ok) throw await runtimeInfoError(response);
1509
1534
  return await response.json();
1510
1535
  }
1511
1536
  /**
@@ -3003,124 +3028,6 @@ var StateManager = class {
3003
3028
  }
3004
3029
  };
3005
3030
 
3006
- //#endregion
3007
- //#region src/core/subagent-registry.ts
3008
- /**
3009
- * Tracks subagent lifecycle events (SUBAGENT_STARTED / FINISHED / ERROR) per
3010
- * owning agent so consumers can resolve a message's `subagentRunId` to a name,
3011
- * description, and running status.
3012
- *
3013
- * Modeled on {@link SuggestionEngine}: an in-memory `Record` keyed by (owning)
3014
- * agentId, mutated from streamed AG-UI events, made reactive by calling
3015
- * `notifySubscribers(onSubagentsChanged)` after every change. It owns its own
3016
- * per-agent `agent.subscribe` (like {@link StateManager}) so it is fully
3017
- * self-contained and adds no coupling to the state/message tracking path.
3018
- *
3019
- * No-op for runs without subagents (a normal LangGraph run never emits
3020
- * SUBAGENT_* events), so the registry simply stays empty.
3021
- */
3022
- var SubagentRegistry = class {
3023
- _subagents = {};
3024
- agentSubscriptions = /* @__PURE__ */ new Map();
3025
- constructor(core) {
3026
- this.core = core;
3027
- }
3028
- /**
3029
- * Subscribe to an agent's subagent lifecycle events. Idempotent per agentId:
3030
- * an existing subscription for the same agent is revoked and replaced.
3031
- */
3032
- subscribeToAgent(agent) {
3033
- if (!agent.agentId) return;
3034
- const agentId = agent.agentId;
3035
- const existingUnsubscribe = this.agentSubscriptions.get(agentId);
3036
- if (existingUnsubscribe) {
3037
- existingUnsubscribe();
3038
- this.agentSubscriptions.delete(agentId);
3039
- }
3040
- let revoked = false;
3041
- const { unsubscribe } = agent.subscribe({
3042
- onSubagentStartedEvent: ({ event }) => {
3043
- if (revoked) return;
3044
- this.handleStarted(agentId, event);
3045
- },
3046
- onSubagentFinishedEvent: ({ event }) => {
3047
- if (revoked) return;
3048
- this.handleFinished(agentId, event);
3049
- },
3050
- onSubagentErrorEvent: ({ event }) => {
3051
- if (revoked) return;
3052
- this.handleError(agentId, event);
3053
- }
3054
- });
3055
- this.agentSubscriptions.set(agentId, () => {
3056
- revoked = true;
3057
- unsubscribe();
3058
- });
3059
- }
3060
- /**
3061
- * Unsubscribe an agent's subscription (symmetric with StateManager cleanup).
3062
- */
3063
- unsubscribeFromAgent(agentId) {
3064
- const unsubscribe = this.agentSubscriptions.get(agentId);
3065
- if (unsubscribe) {
3066
- unsubscribe();
3067
- this.agentSubscriptions.delete(agentId);
3068
- }
3069
- }
3070
- /**
3071
- * Get the subagents observed for an owning agent, keyed by subagentRunId.
3072
- * Returns a fresh shallow copy each call so consumers (and React state) see
3073
- * a new reference when anything changed.
3074
- */
3075
- getSubagents(agentId) {
3076
- return { ...this._subagents[agentId] };
3077
- }
3078
- handleStarted(agentId, event) {
3079
- const bucket = this._subagents[agentId] ??= {};
3080
- bucket[event.subagentRunId] = {
3081
- subagentRunId: event.subagentRunId,
3082
- name: event.name,
3083
- description: event.description,
3084
- parentSubagentRunId: event.parentSubagentRunId,
3085
- status: "running"
3086
- };
3087
- this.notifySubagentsChanged(agentId);
3088
- }
3089
- handleFinished(agentId, event) {
3090
- const bucket = this._subagents[agentId];
3091
- const existing = bucket?.[event.subagentRunId];
3092
- if (!bucket || !existing) return;
3093
- bucket[event.subagentRunId] = {
3094
- ...existing,
3095
- status: "finished"
3096
- };
3097
- this.notifySubagentsChanged(agentId);
3098
- }
3099
- handleError(agentId, event) {
3100
- const bucket = this._subagents[agentId] ??= {};
3101
- const existing = bucket[event.subagentRunId];
3102
- bucket[event.subagentRunId] = existing ? {
3103
- ...existing,
3104
- status: "error",
3105
- error: event.message
3106
- } : {
3107
- subagentRunId: event.subagentRunId,
3108
- name: event.subagentRunId,
3109
- status: "error",
3110
- error: event.message
3111
- };
3112
- this.notifySubagentsChanged(agentId);
3113
- }
3114
- async notifySubagentsChanged(agentId) {
3115
- const subagents = this.getSubagents(agentId);
3116
- await this.core.notifySubscribers((subscriber) => subscriber.onSubagentsChanged?.({
3117
- copilotkit: this.core,
3118
- agentId,
3119
- subagents
3120
- }), "Subscriber onSubagentsChanged error:");
3121
- }
3122
- };
3123
-
3124
3031
  //#endregion
3125
3032
  //#region src/core/thread-store-registry.ts
3126
3033
  var ThreadStoreRegistry = class {
@@ -4309,7 +4216,6 @@ var CopilotKitCore = class {
4309
4216
  suggestionEngine;
4310
4217
  runHandler;
4311
4218
  stateManager;
4312
- subagentRegistry;
4313
4219
  threadStoreRegistry;
4314
4220
  /**
4315
4221
  * The single core-owned memory store, created lazily on first
@@ -4335,7 +4241,6 @@ var CopilotKitCore = class {
4335
4241
  this.suggestionEngine = new SuggestionEngine(this);
4336
4242
  this.runHandler = new RunHandler(this);
4337
4243
  this.stateManager = new StateManager(this);
4338
- this.subagentRegistry = new SubagentRegistry(this);
4339
4244
  this.threadStoreRegistry = new ThreadStoreRegistry(this);
4340
4245
  this.agentRegistry.initialize(agents__unsafe_dev_only);
4341
4246
  this.runHandler.initialize(tools);
@@ -4350,10 +4255,7 @@ var CopilotKitCore = class {
4350
4255
  },
4351
4256
  onAgentsChanged: ({ agents }) => {
4352
4257
  Object.values(agents).forEach((agent) => {
4353
- if (agent.agentId) {
4354
- this.stateManager.subscribeToAgent(agent);
4355
- this.subagentRegistry.subscribeToAgent(agent);
4356
- }
4258
+ if (agent.agentId) this.stateManager.subscribeToAgent(agent);
4357
4259
  });
4358
4260
  const currentAgentIds = new Set(Object.keys(agents));
4359
4261
  for (const agentId of Object.keys(this.threadStoreRegistry.getAll())) if (this.previousAgentIds.has(agentId) && !currentAgentIds.has(agentId)) try {
@@ -4361,17 +4263,10 @@ var CopilotKitCore = class {
4361
4263
  } catch (err) {
4362
4264
  console.error(`CopilotKitCore.onAgentsChanged: threadStoreRegistry.unregister failed for "${agentId}":`, err);
4363
4265
  }
4364
- for (const agentId of this.previousAgentIds) if (!currentAgentIds.has(agentId)) {
4365
- try {
4366
- this.stateManager.unsubscribeFromAgent(agentId);
4367
- } catch (err) {
4368
- console.error(`CopilotKitCore.onAgentsChanged: stateManager.unsubscribeFromAgent failed for "${agentId}":`, err);
4369
- }
4370
- try {
4371
- this.subagentRegistry.unsubscribeFromAgent(agentId);
4372
- } catch (err) {
4373
- console.error(`CopilotKitCore.onAgentsChanged: subagentRegistry.unsubscribeFromAgent failed for "${agentId}":`, err);
4374
- }
4266
+ for (const agentId of this.previousAgentIds) if (!currentAgentIds.has(agentId)) try {
4267
+ this.stateManager.unsubscribeFromAgent(agentId);
4268
+ } catch (err) {
4269
+ console.error(`CopilotKitCore.onAgentsChanged: stateManager.unsubscribeFromAgent failed for "${agentId}":`, err);
4375
4270
  }
4376
4271
  this.previousAgentIds = currentAgentIds;
4377
4272
  }
@@ -4741,16 +4636,6 @@ var CopilotKitCore = class {
4741
4636
  return this.suggestionEngine.getSuggestions(agentId);
4742
4637
  }
4743
4638
  /**
4744
- * Subagent registry (delegated to SubagentRegistry).
4745
- *
4746
- * Returns the subagents observed for an owning agent during its run(s),
4747
- * keyed by `subagentRunId`, each carrying `name` / `description` / `status`.
4748
- * Empty for runs that never emit SUBAGENT_* events.
4749
- */
4750
- getSubagents(agentId) {
4751
- return this.subagentRegistry.getSubagents(agentId);
4752
- }
4753
- /**
4754
4639
  * Tool management (delegated to RunHandler)
4755
4640
  */
4756
4641
  addTool(tool) {
@@ -6045,7 +5930,6 @@ exports.MemoryError = MemoryError;
6045
5930
  exports.ProxiedCopilotRuntimeAgent = ProxiedCopilotRuntimeAgent;
6046
5931
  exports.RunHandler = RunHandler;
6047
5932
  exports.StateManager = StateManager;
6048
- exports.SubagentRegistry = SubagentRegistry;
6049
5933
  exports.SuggestionEngine = SuggestionEngine;
6050
5934
  exports.ToolCallStatus = ToolCallStatus;
6051
5935
  exports.completePartialMarkdown = completePartialMarkdown;