@copilotkit/react-core 1.68.2 → 1.68.3-canary.1786716392

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.
@@ -4643,6 +4643,75 @@ function useAgent({ agentId, threadId, runtimeAgentId, updates, throttleMs } = {
4643
4643
  };
4644
4644
  }
4645
4645
 
4646
+ //#endregion
4647
+ //#region src/v2/hooks/use-subagent.tsx
4648
+ const warnedAmbiguousNames = /* @__PURE__ */ new Set();
4649
+ function resolveSubagent(subagents, subagentRunId, subagentName) {
4650
+ if (subagentRunId) {
4651
+ const match = subagents[subagentRunId];
4652
+ return match ? { ...match } : void 0;
4653
+ }
4654
+ if (subagentName) {
4655
+ const matches = Object.values(subagents).filter((s) => s.name === subagentName);
4656
+ if (matches.length === 0) return;
4657
+ const chosen = matches[matches.length - 1];
4658
+ return matches.length > 1 ? {
4659
+ ...chosen,
4660
+ isAmbiguous: true,
4661
+ matchCount: matches.length
4662
+ } : { ...chosen };
4663
+ }
4664
+ }
4665
+ /**
4666
+ * Read a subagent's live lifecycle state (name, description, running status)
4667
+ * from the CopilotKit core subagent registry, by id or by declared name.
4668
+ *
4669
+ * @example
4670
+ * const sub = useSubagent({ subagentRunId: message.subagentRunId });
4671
+ * // sub?.name, sub?.description, sub?.status
4672
+ */
4673
+ function useSubagent(params) {
4674
+ const { subagentRunId, subagentName, agentId } = params;
4675
+ const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
4676
+ const config = useCopilotChatConfiguration();
4677
+ const resolvedAgentId = (0, react.useMemo)(() => agentId ?? config?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID, [agentId, config?.agentId]);
4678
+ const [subagent, setSubagent] = (0, react.useState)(() => resolveSubagent(copilotkit.getSubagents(resolvedAgentId), subagentRunId, subagentName));
4679
+ (0, react.useEffect)(() => {
4680
+ setSubagent(resolveSubagent(copilotkit.getSubagents(resolvedAgentId), subagentRunId, subagentName));
4681
+ }, [
4682
+ copilotkit,
4683
+ resolvedAgentId,
4684
+ subagentRunId,
4685
+ subagentName
4686
+ ]);
4687
+ (0, react.useEffect)(() => {
4688
+ const subscription = copilotkit.subscribe({ onSubagentsChanged: ({ agentId: changedAgentId, subagents }) => {
4689
+ if (changedAgentId !== resolvedAgentId) return;
4690
+ setSubagent(resolveSubagent(subagents, subagentRunId, subagentName));
4691
+ } });
4692
+ return () => {
4693
+ subscription.unsubscribe();
4694
+ };
4695
+ }, [
4696
+ copilotkit,
4697
+ resolvedAgentId,
4698
+ subagentRunId,
4699
+ subagentName
4700
+ ]);
4701
+ (0, react.useEffect)(() => {
4702
+ if (process.env.NODE_ENV === "production" || !subagentName || !subagent?.isAmbiguous) return;
4703
+ const key = `${subagentName}:${subagent.matchCount}`;
4704
+ if (warnedAmbiguousNames.has(key)) return;
4705
+ warnedAmbiguousNames.add(key);
4706
+ console.warn(`[CopilotKit] useSubagent({ subagentName: ${JSON.stringify(subagentName)} }) matched ${subagent.matchCount} subagents. Returning the most recently started one; pass a subagentRunId for a stable reference.`);
4707
+ }, [
4708
+ subagentName,
4709
+ subagent?.isAmbiguous,
4710
+ subagent?.matchCount
4711
+ ]);
4712
+ return subagent;
4713
+ }
4714
+
4646
4715
  //#endregion
4647
4716
  //#region src/v2/hooks/use-capabilities.tsx
4648
4717
  /**
@@ -12440,6 +12509,12 @@ Object.defineProperty(exports, 'useSandboxFunctions', {
12440
12509
  return useSandboxFunctions;
12441
12510
  }
12442
12511
  });
12512
+ Object.defineProperty(exports, 'useSubagent', {
12513
+ enumerable: true,
12514
+ get: function () {
12515
+ return useSubagent;
12516
+ }
12517
+ });
12443
12518
  Object.defineProperty(exports, 'useSuggestions', {
12444
12519
  enumerable: true,
12445
12520
  get: function () {
@@ -12470,4 +12545,4 @@ Object.defineProperty(exports, 'ɵrunMcpFollowUp', {
12470
12545
  return ɵrunMcpFollowUp;
12471
12546
  }
12472
12547
  });
12473
- //# sourceMappingURL=copilotkit-Bocmlr37.cjs.map
12548
+ //# sourceMappingURL=copilotkit-EFunREg5.cjs.map