@copilotkit/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.
- package/dist/index.cjs +146 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +71 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +71 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +146 -6
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +151 -5
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -3002,6 +3002,124 @@ var StateManager = class {
|
|
|
3002
3002
|
}
|
|
3003
3003
|
};
|
|
3004
3004
|
|
|
3005
|
+
//#endregion
|
|
3006
|
+
//#region src/core/subagent-registry.ts
|
|
3007
|
+
/**
|
|
3008
|
+
* Tracks subagent lifecycle events (SUBAGENT_STARTED / FINISHED / ERROR) per
|
|
3009
|
+
* owning agent so consumers can resolve a message's `subagentRunId` to a name,
|
|
3010
|
+
* description, and running status.
|
|
3011
|
+
*
|
|
3012
|
+
* Modeled on {@link SuggestionEngine}: an in-memory `Record` keyed by (owning)
|
|
3013
|
+
* agentId, mutated from streamed AG-UI events, made reactive by calling
|
|
3014
|
+
* `notifySubscribers(onSubagentsChanged)` after every change. It owns its own
|
|
3015
|
+
* per-agent `agent.subscribe` (like {@link StateManager}) so it is fully
|
|
3016
|
+
* self-contained and adds no coupling to the state/message tracking path.
|
|
3017
|
+
*
|
|
3018
|
+
* No-op for runs without subagents (a normal LangGraph run never emits
|
|
3019
|
+
* SUBAGENT_* events), so the registry simply stays empty.
|
|
3020
|
+
*/
|
|
3021
|
+
var SubagentRegistry = class {
|
|
3022
|
+
_subagents = {};
|
|
3023
|
+
agentSubscriptions = /* @__PURE__ */ new Map();
|
|
3024
|
+
constructor(core) {
|
|
3025
|
+
this.core = core;
|
|
3026
|
+
}
|
|
3027
|
+
/**
|
|
3028
|
+
* Subscribe to an agent's subagent lifecycle events. Idempotent per agentId:
|
|
3029
|
+
* an existing subscription for the same agent is revoked and replaced.
|
|
3030
|
+
*/
|
|
3031
|
+
subscribeToAgent(agent) {
|
|
3032
|
+
if (!agent.agentId) return;
|
|
3033
|
+
const agentId = agent.agentId;
|
|
3034
|
+
const existingUnsubscribe = this.agentSubscriptions.get(agentId);
|
|
3035
|
+
if (existingUnsubscribe) {
|
|
3036
|
+
existingUnsubscribe();
|
|
3037
|
+
this.agentSubscriptions.delete(agentId);
|
|
3038
|
+
}
|
|
3039
|
+
let revoked = false;
|
|
3040
|
+
const { unsubscribe } = agent.subscribe({
|
|
3041
|
+
onSubagentStartedEvent: ({ event }) => {
|
|
3042
|
+
if (revoked) return;
|
|
3043
|
+
this.handleStarted(agentId, event);
|
|
3044
|
+
},
|
|
3045
|
+
onSubagentFinishedEvent: ({ event }) => {
|
|
3046
|
+
if (revoked) return;
|
|
3047
|
+
this.handleFinished(agentId, event);
|
|
3048
|
+
},
|
|
3049
|
+
onSubagentErrorEvent: ({ event }) => {
|
|
3050
|
+
if (revoked) return;
|
|
3051
|
+
this.handleError(agentId, event);
|
|
3052
|
+
}
|
|
3053
|
+
});
|
|
3054
|
+
this.agentSubscriptions.set(agentId, () => {
|
|
3055
|
+
revoked = true;
|
|
3056
|
+
unsubscribe();
|
|
3057
|
+
});
|
|
3058
|
+
}
|
|
3059
|
+
/**
|
|
3060
|
+
* Unsubscribe an agent's subscription (symmetric with StateManager cleanup).
|
|
3061
|
+
*/
|
|
3062
|
+
unsubscribeFromAgent(agentId) {
|
|
3063
|
+
const unsubscribe = this.agentSubscriptions.get(agentId);
|
|
3064
|
+
if (unsubscribe) {
|
|
3065
|
+
unsubscribe();
|
|
3066
|
+
this.agentSubscriptions.delete(agentId);
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
/**
|
|
3070
|
+
* Get the subagents observed for an owning agent, keyed by subagentRunId.
|
|
3071
|
+
* Returns a fresh shallow copy each call so consumers (and React state) see
|
|
3072
|
+
* a new reference when anything changed.
|
|
3073
|
+
*/
|
|
3074
|
+
getSubagents(agentId) {
|
|
3075
|
+
return { ...this._subagents[agentId] };
|
|
3076
|
+
}
|
|
3077
|
+
handleStarted(agentId, event) {
|
|
3078
|
+
const bucket = this._subagents[agentId] ??= {};
|
|
3079
|
+
bucket[event.subagentRunId] = {
|
|
3080
|
+
subagentRunId: event.subagentRunId,
|
|
3081
|
+
name: event.name,
|
|
3082
|
+
description: event.description,
|
|
3083
|
+
parentSubagentRunId: event.parentSubagentRunId,
|
|
3084
|
+
status: "running"
|
|
3085
|
+
};
|
|
3086
|
+
this.notifySubagentsChanged(agentId);
|
|
3087
|
+
}
|
|
3088
|
+
handleFinished(agentId, event) {
|
|
3089
|
+
const bucket = this._subagents[agentId];
|
|
3090
|
+
const existing = bucket?.[event.subagentRunId];
|
|
3091
|
+
if (!bucket || !existing) return;
|
|
3092
|
+
bucket[event.subagentRunId] = {
|
|
3093
|
+
...existing,
|
|
3094
|
+
status: "finished"
|
|
3095
|
+
};
|
|
3096
|
+
this.notifySubagentsChanged(agentId);
|
|
3097
|
+
}
|
|
3098
|
+
handleError(agentId, event) {
|
|
3099
|
+
const bucket = this._subagents[agentId] ??= {};
|
|
3100
|
+
const existing = bucket[event.subagentRunId];
|
|
3101
|
+
bucket[event.subagentRunId] = existing ? {
|
|
3102
|
+
...existing,
|
|
3103
|
+
status: "error",
|
|
3104
|
+
error: event.message
|
|
3105
|
+
} : {
|
|
3106
|
+
subagentRunId: event.subagentRunId,
|
|
3107
|
+
name: event.subagentRunId,
|
|
3108
|
+
status: "error",
|
|
3109
|
+
error: event.message
|
|
3110
|
+
};
|
|
3111
|
+
this.notifySubagentsChanged(agentId);
|
|
3112
|
+
}
|
|
3113
|
+
async notifySubagentsChanged(agentId) {
|
|
3114
|
+
const subagents = this.getSubagents(agentId);
|
|
3115
|
+
await this.core.notifySubscribers((subscriber) => subscriber.onSubagentsChanged?.({
|
|
3116
|
+
copilotkit: this.core,
|
|
3117
|
+
agentId,
|
|
3118
|
+
subagents
|
|
3119
|
+
}), "Subscriber onSubagentsChanged error:");
|
|
3120
|
+
}
|
|
3121
|
+
};
|
|
3122
|
+
|
|
3005
3123
|
//#endregion
|
|
3006
3124
|
//#region src/core/thread-store-registry.ts
|
|
3007
3125
|
var ThreadStoreRegistry = class {
|
|
@@ -4190,6 +4308,7 @@ var CopilotKitCore = class {
|
|
|
4190
4308
|
suggestionEngine;
|
|
4191
4309
|
runHandler;
|
|
4192
4310
|
stateManager;
|
|
4311
|
+
subagentRegistry;
|
|
4193
4312
|
threadStoreRegistry;
|
|
4194
4313
|
/**
|
|
4195
4314
|
* The single core-owned memory store, created lazily on first
|
|
@@ -4215,6 +4334,7 @@ var CopilotKitCore = class {
|
|
|
4215
4334
|
this.suggestionEngine = new SuggestionEngine(this);
|
|
4216
4335
|
this.runHandler = new RunHandler(this);
|
|
4217
4336
|
this.stateManager = new StateManager(this);
|
|
4337
|
+
this.subagentRegistry = new SubagentRegistry(this);
|
|
4218
4338
|
this.threadStoreRegistry = new ThreadStoreRegistry(this);
|
|
4219
4339
|
this.agentRegistry.initialize(agents__unsafe_dev_only);
|
|
4220
4340
|
this.runHandler.initialize(tools);
|
|
@@ -4229,7 +4349,10 @@ var CopilotKitCore = class {
|
|
|
4229
4349
|
},
|
|
4230
4350
|
onAgentsChanged: ({ agents }) => {
|
|
4231
4351
|
Object.values(agents).forEach((agent) => {
|
|
4232
|
-
if (agent.agentId)
|
|
4352
|
+
if (agent.agentId) {
|
|
4353
|
+
this.stateManager.subscribeToAgent(agent);
|
|
4354
|
+
this.subagentRegistry.subscribeToAgent(agent);
|
|
4355
|
+
}
|
|
4233
4356
|
});
|
|
4234
4357
|
const currentAgentIds = new Set(Object.keys(agents));
|
|
4235
4358
|
for (const agentId of Object.keys(this.threadStoreRegistry.getAll())) if (this.previousAgentIds.has(agentId) && !currentAgentIds.has(agentId)) try {
|
|
@@ -4237,10 +4360,17 @@ var CopilotKitCore = class {
|
|
|
4237
4360
|
} catch (err) {
|
|
4238
4361
|
console.error(`CopilotKitCore.onAgentsChanged: threadStoreRegistry.unregister failed for "${agentId}":`, err);
|
|
4239
4362
|
}
|
|
4240
|
-
for (const agentId of this.previousAgentIds) if (!currentAgentIds.has(agentId))
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4363
|
+
for (const agentId of this.previousAgentIds) if (!currentAgentIds.has(agentId)) {
|
|
4364
|
+
try {
|
|
4365
|
+
this.stateManager.unsubscribeFromAgent(agentId);
|
|
4366
|
+
} catch (err) {
|
|
4367
|
+
console.error(`CopilotKitCore.onAgentsChanged: stateManager.unsubscribeFromAgent failed for "${agentId}":`, err);
|
|
4368
|
+
}
|
|
4369
|
+
try {
|
|
4370
|
+
this.subagentRegistry.unsubscribeFromAgent(agentId);
|
|
4371
|
+
} catch (err) {
|
|
4372
|
+
console.error(`CopilotKitCore.onAgentsChanged: subagentRegistry.unsubscribeFromAgent failed for "${agentId}":`, err);
|
|
4373
|
+
}
|
|
4244
4374
|
}
|
|
4245
4375
|
this.previousAgentIds = currentAgentIds;
|
|
4246
4376
|
}
|
|
@@ -4610,6 +4740,16 @@ var CopilotKitCore = class {
|
|
|
4610
4740
|
return this.suggestionEngine.getSuggestions(agentId);
|
|
4611
4741
|
}
|
|
4612
4742
|
/**
|
|
4743
|
+
* Subagent registry (delegated to SubagentRegistry).
|
|
4744
|
+
*
|
|
4745
|
+
* Returns the subagents observed for an owning agent during its run(s),
|
|
4746
|
+
* keyed by `subagentRunId`, each carrying `name` / `description` / `status`.
|
|
4747
|
+
* Empty for runs that never emit SUBAGENT_* events.
|
|
4748
|
+
*/
|
|
4749
|
+
getSubagents(agentId) {
|
|
4750
|
+
return this.subagentRegistry.getSubagents(agentId);
|
|
4751
|
+
}
|
|
4752
|
+
/**
|
|
4613
4753
|
* Tool management (delegated to RunHandler)
|
|
4614
4754
|
*/
|
|
4615
4755
|
addTool(tool) {
|
|
@@ -5892,5 +6032,5 @@ var ɵInterruptState = class {
|
|
|
5892
6032
|
};
|
|
5893
6033
|
|
|
5894
6034
|
//#endregion
|
|
5895
|
-
export { AgentRegistry, AgentThreadLockedError, ContextStore, CopilotKitCore, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, IntelligenceAgent, MEMORY_ERROR_REGISTRY, MemoryError, ProxiedCopilotRuntimeAgent, RunHandler, StateManager, SuggestionEngine, ToolCallStatus, completePartialMarkdown, createActionGroup, createEffect, createReducer, createSelector, createStore, empty, ensureObjectArgs, isAbortError, isRunCompletionAware, ofType, on, parseToolArguments, props, select, ɵCOPILOTKIT_FEATURES, ɵInterruptState, ɵMAX_SOCKET_RETRIES, createMemoryStore as ɵcreateMemoryStore, ɵcreateThreadSelectors, createThreadStore as ɵcreateThreadStore, ɵisCopilotKitFeature, isRetryableStatus as ɵisRetryableMemoryStatus, ɵjoinPhoenixChannel$, ɵmapMemoryMetadataEvent, ɵmemoryAdapterEvents, ɵmemoryDomainEvents, ɵmemoryReducer, ɵmemoryRestEvents, ɵobservePhoenixEvent$, ɵobservePhoenixJoinOutcome$, ɵobservePhoenixSocketHealth$, ɵobservePhoenixSocketSignals$, ɵphoenixChannel$, ɵphoenixSocket$, ɵselectFetchMoreError, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectMemories, ɵselectMemoriesAvailable, ɵselectMemoriesError, ɵselectMemoriesIsLoading, ɵselectMemoriesIsMutating, ɵselectMemoriesRealtimeStatus, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading, ɵthreadAdapterEvents };
|
|
6035
|
+
export { AgentRegistry, AgentThreadLockedError, ContextStore, CopilotKitCore, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, IntelligenceAgent, MEMORY_ERROR_REGISTRY, MemoryError, ProxiedCopilotRuntimeAgent, RunHandler, StateManager, SubagentRegistry, SuggestionEngine, ToolCallStatus, completePartialMarkdown, createActionGroup, createEffect, createReducer, createSelector, createStore, empty, ensureObjectArgs, isAbortError, isRunCompletionAware, ofType, on, parseToolArguments, props, select, ɵCOPILOTKIT_FEATURES, ɵInterruptState, ɵMAX_SOCKET_RETRIES, createMemoryStore as ɵcreateMemoryStore, ɵcreateThreadSelectors, createThreadStore as ɵcreateThreadStore, ɵisCopilotKitFeature, isRetryableStatus as ɵisRetryableMemoryStatus, ɵjoinPhoenixChannel$, ɵmapMemoryMetadataEvent, ɵmemoryAdapterEvents, ɵmemoryDomainEvents, ɵmemoryReducer, ɵmemoryRestEvents, ɵobservePhoenixEvent$, ɵobservePhoenixJoinOutcome$, ɵobservePhoenixSocketHealth$, ɵobservePhoenixSocketSignals$, ɵphoenixChannel$, ɵphoenixSocket$, ɵselectFetchMoreError, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectMemories, ɵselectMemoriesAvailable, ɵselectMemoriesError, ɵselectMemoriesIsLoading, ɵselectMemoriesIsMutating, ɵselectMemoriesRealtimeStatus, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading, ɵthreadAdapterEvents };
|
|
5896
6036
|
//# sourceMappingURL=index.mjs.map
|