@copilotkit/core 1.56.5 → 1.57.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 +96 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +605 -557
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +417 -369
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +96 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +96 -0
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2265,6 +2265,61 @@ var StateManager = class {
|
|
|
2265
2265
|
}
|
|
2266
2266
|
};
|
|
2267
2267
|
|
|
2268
|
+
//#endregion
|
|
2269
|
+
//#region src/core/thread-store-registry.ts
|
|
2270
|
+
var ThreadStoreRegistry = class {
|
|
2271
|
+
_stores = {};
|
|
2272
|
+
_snapshot = null;
|
|
2273
|
+
constructor(core) {
|
|
2274
|
+
this.core = core;
|
|
2275
|
+
}
|
|
2276
|
+
register(agentId, store) {
|
|
2277
|
+
if (agentId in this._stores) {
|
|
2278
|
+
const prevStore = this._stores[agentId];
|
|
2279
|
+
delete this._stores[agentId];
|
|
2280
|
+
this._snapshot = null;
|
|
2281
|
+
this.notifyUnregistered(agentId, prevStore).catch((err) => {
|
|
2282
|
+
console.error("ThreadStoreRegistry notifyUnregistered failed:", err);
|
|
2283
|
+
});
|
|
2284
|
+
}
|
|
2285
|
+
this._stores[agentId] = store;
|
|
2286
|
+
this._snapshot = null;
|
|
2287
|
+
this.notifyRegistered(agentId, store).catch((err) => {
|
|
2288
|
+
console.error("ThreadStoreRegistry notifyRegistered failed:", err);
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
unregister(agentId) {
|
|
2292
|
+
if (!(agentId in this._stores)) return;
|
|
2293
|
+
const prevStore = this._stores[agentId];
|
|
2294
|
+
delete this._stores[agentId];
|
|
2295
|
+
this._snapshot = null;
|
|
2296
|
+
this.notifyUnregistered(agentId, prevStore).catch((err) => {
|
|
2297
|
+
console.error("ThreadStoreRegistry notifyUnregistered failed:", err);
|
|
2298
|
+
});
|
|
2299
|
+
}
|
|
2300
|
+
get(agentId) {
|
|
2301
|
+
return this._stores[agentId];
|
|
2302
|
+
}
|
|
2303
|
+
getAll() {
|
|
2304
|
+
if (this._snapshot === null) this._snapshot = Object.freeze({ ...this._stores });
|
|
2305
|
+
return this._snapshot;
|
|
2306
|
+
}
|
|
2307
|
+
async notifyRegistered(agentId, store) {
|
|
2308
|
+
await this.core.notifySubscribers((subscriber) => subscriber.onThreadStoreRegistered?.({
|
|
2309
|
+
copilotkit: this.core,
|
|
2310
|
+
agentId,
|
|
2311
|
+
store
|
|
2312
|
+
}), "Subscriber onThreadStoreRegistered error:");
|
|
2313
|
+
}
|
|
2314
|
+
async notifyUnregistered(agentId, prevStore) {
|
|
2315
|
+
await this.core.notifySubscribers((subscriber) => subscriber.onThreadStoreUnregistered?.({
|
|
2316
|
+
copilotkit: this.core,
|
|
2317
|
+
agentId,
|
|
2318
|
+
prevStore
|
|
2319
|
+
}), "Subscriber onThreadStoreUnregistered error:");
|
|
2320
|
+
}
|
|
2321
|
+
};
|
|
2322
|
+
|
|
2268
2323
|
//#endregion
|
|
2269
2324
|
//#region src/core/core.ts
|
|
2270
2325
|
let CopilotKitCoreErrorCode = /* @__PURE__ */ function(CopilotKitCoreErrorCode) {
|
|
@@ -2333,6 +2388,14 @@ var CopilotKitCore = class {
|
|
|
2333
2388
|
suggestionEngine;
|
|
2334
2389
|
runHandler;
|
|
2335
2390
|
stateManager;
|
|
2391
|
+
threadStoreRegistry;
|
|
2392
|
+
/**
|
|
2393
|
+
* Tracks the agent IDs from the most recent `onAgentsChanged` notification.
|
|
2394
|
+
* Used to gate thread-store auto-unregister so the FIRST empty-agents
|
|
2395
|
+
* notification (before published agents are merged in) does not rip out a
|
|
2396
|
+
* store that was registered prior to that initial notification.
|
|
2397
|
+
*/
|
|
2398
|
+
previousAgentIds = /* @__PURE__ */ new Set();
|
|
2336
2399
|
constructor({ runtimeUrl, runtimeTransport = "auto", headers = {}, credentials, properties = {}, agents__unsafe_dev_only = {}, tools = [], suggestionsConfig = [], debug }) {
|
|
2337
2400
|
this._headers = headers;
|
|
2338
2401
|
this._credentials = credentials;
|
|
@@ -2343,16 +2406,21 @@ var CopilotKitCore = class {
|
|
|
2343
2406
|
this.suggestionEngine = new SuggestionEngine(this);
|
|
2344
2407
|
this.runHandler = new RunHandler(this);
|
|
2345
2408
|
this.stateManager = new StateManager(this);
|
|
2409
|
+
this.threadStoreRegistry = new ThreadStoreRegistry(this);
|
|
2346
2410
|
this.agentRegistry.initialize(agents__unsafe_dev_only);
|
|
2347
2411
|
this.runHandler.initialize(tools);
|
|
2348
2412
|
this.suggestionEngine.initialize(suggestionsConfig);
|
|
2349
2413
|
this.stateManager.initialize();
|
|
2350
2414
|
this.agentRegistry.setRuntimeTransport(runtimeTransport);
|
|
2351
2415
|
this.agentRegistry.setRuntimeUrl(runtimeUrl);
|
|
2416
|
+
this.previousAgentIds = new Set(Object.keys(agents__unsafe_dev_only));
|
|
2352
2417
|
this.subscribe({ onAgentsChanged: ({ agents }) => {
|
|
2353
2418
|
Object.values(agents).forEach((agent) => {
|
|
2354
2419
|
if (agent.agentId) this.stateManager.subscribeToAgent(agent);
|
|
2355
2420
|
});
|
|
2421
|
+
const currentAgentIds = new Set(Object.keys(agents));
|
|
2422
|
+
for (const agentId of Object.keys(this.threadStoreRegistry.getAll())) if (this.previousAgentIds.has(agentId) && !currentAgentIds.has(agentId)) this.threadStoreRegistry.unregister(agentId);
|
|
2423
|
+
this.previousAgentIds = currentAgentIds;
|
|
2356
2424
|
} });
|
|
2357
2425
|
}
|
|
2358
2426
|
/**
|
|
@@ -2527,6 +2595,21 @@ var CopilotKitCore = class {
|
|
|
2527
2595
|
this.contextStore.removeContext(id);
|
|
2528
2596
|
}
|
|
2529
2597
|
/**
|
|
2598
|
+
* Thread store registry (delegated to ThreadStoreRegistry)
|
|
2599
|
+
*/
|
|
2600
|
+
registerThreadStore(agentId, store) {
|
|
2601
|
+
this.threadStoreRegistry.register(agentId, store);
|
|
2602
|
+
}
|
|
2603
|
+
unregisterThreadStore(agentId) {
|
|
2604
|
+
this.threadStoreRegistry.unregister(agentId);
|
|
2605
|
+
}
|
|
2606
|
+
getThreadStore(agentId) {
|
|
2607
|
+
return this.threadStoreRegistry.get(agentId);
|
|
2608
|
+
}
|
|
2609
|
+
getThreadStores() {
|
|
2610
|
+
return this.threadStoreRegistry.getAll();
|
|
2611
|
+
}
|
|
2612
|
+
/**
|
|
2530
2613
|
* Suggestions management (delegated to SuggestionEngine)
|
|
2531
2614
|
*/
|
|
2532
2615
|
addSuggestionsConfig(config) {
|
|
@@ -3611,6 +3694,11 @@ function createThreadStore(environment) {
|
|
|
3611
3694
|
setContext(context) {
|
|
3612
3695
|
store.dispatch(threadAdapterEvents.contextChanged({ context }));
|
|
3613
3696
|
},
|
|
3697
|
+
refresh() {
|
|
3698
|
+
const { sessionId, context } = store.getState();
|
|
3699
|
+
if (!context) return;
|
|
3700
|
+
store.dispatch(threadRestEvents.listRequested({ sessionId }));
|
|
3701
|
+
},
|
|
3614
3702
|
fetchNextPage() {
|
|
3615
3703
|
store.dispatch(threadAdapterEvents.fetchNextPageRequested());
|
|
3616
3704
|
},
|
|
@@ -3645,6 +3733,13 @@ const ɵselectThreadsIsLoading = selectThreadsIsLoading;
|
|
|
3645
3733
|
const ɵselectThreadsError = selectThreadsError;
|
|
3646
3734
|
const ɵselectHasNextPage = selectHasNextPage;
|
|
3647
3735
|
const ɵselectIsFetchingNextPage = selectIsFetchingNextPage;
|
|
3736
|
+
/**
|
|
3737
|
+
* Number of consecutive WebSocket connection failures after which the
|
|
3738
|
+
* threads channel tears itself down rather than retrying indefinitely.
|
|
3739
|
+
* Exposed for tests so they can assert teardown semantics without
|
|
3740
|
+
* hardcoding the threshold separately from production.
|
|
3741
|
+
*/
|
|
3742
|
+
const ɵMAX_SOCKET_RETRIES = MAX_SOCKET_RETRIES;
|
|
3648
3743
|
|
|
3649
3744
|
//#endregion
|
|
3650
3745
|
exports.AgentRegistry = AgentRegistry;
|
|
@@ -3672,6 +3767,7 @@ exports.on = on;
|
|
|
3672
3767
|
exports.parseToolArguments = parseToolArguments;
|
|
3673
3768
|
exports.props = props;
|
|
3674
3769
|
exports.select = select;
|
|
3770
|
+
exports.ɵMAX_SOCKET_RETRIES = ɵMAX_SOCKET_RETRIES;
|
|
3675
3771
|
exports.ɵcreateThreadStore = createThreadStore;
|
|
3676
3772
|
exports.ɵjoinPhoenixChannel$ = ɵjoinPhoenixChannel$;
|
|
3677
3773
|
exports.ɵobservePhoenixEvent$ = ɵobservePhoenixEvent$;
|