@copilotkit/core 1.64.2-canary.1785346263 → 1.64.2-canary.rc-1

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
@@ -1911,6 +1911,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1911
1911
  constructor(core) {
1912
1912
  this.core = core;
1913
1913
  _defineProperty(this, "_tools", []);
1914
+ _defineProperty(this, "_catalogComponents", []);
1915
+ _defineProperty(this, "_disabledCatalogComponents", /* @__PURE__ */ new Set());
1916
+ _defineProperty(this, "_disabledToolKeys", /* @__PURE__ */ new Set());
1914
1917
  _defineProperty(this, "_runAbortController", null);
1915
1918
  _defineProperty(this, "_runDepth", 0);
1916
1919
  _defineProperty(this, "_lastConnectedThreadIdsByAgent", /* @__PURE__ */ new Map());
@@ -1998,6 +2001,32 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1998
2001
  this._tools = [...tools];
1999
2002
  }
2000
2003
  /**
2004
+ * Return the registered A2UI catalog components (readonly).
2005
+ */
2006
+ get catalogComponents() {
2007
+ return this._catalogComponents;
2008
+ }
2009
+ /**
2010
+ * Replace the registered catalog component list. Preserves the disabled set
2011
+ * (by name) so re-registration does not re-enable disabled components.
2012
+ */
2013
+ setCatalogComponents(components) {
2014
+ this._catalogComponents = [...components];
2015
+ }
2016
+ /**
2017
+ * Enable or disable a catalog component by name.
2018
+ */
2019
+ setCatalogComponentEnabled(name, enabled) {
2020
+ if (enabled) this._disabledCatalogComponents.delete(name);
2021
+ else this._disabledCatalogComponents.add(name);
2022
+ }
2023
+ /**
2024
+ * Whether a catalog component is enabled. Unknown names default to enabled.
2025
+ */
2026
+ isCatalogComponentEnabled(name) {
2027
+ return !this._disabledCatalogComponents.has(name);
2028
+ }
2029
+ /**
2001
2030
  * Connect an agent (establish initial connection)
2002
2031
  */
2003
2032
  async connectAgent({ agent }) {
@@ -2485,11 +2514,30 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2485
2514
  error: handlerResult.error
2486
2515
  };
2487
2516
  }
2517
+ /** Stable identity for a tool override: agent-scope + name (NUL-separated). */
2518
+ capabilityKey(name, agentId) {
2519
+ return `${agentId !== null && agentId !== void 0 ? agentId : ""}\u0000${name}`;
2520
+ }
2521
+ /**
2522
+ * Enable/disable a registered frontend tool at runtime without unregistering
2523
+ * it. A disabled tool is omitted from {@link buildFrontendTools}, so the agent
2524
+ * never receives it. Unlike the per-tool `available` flag, this override
2525
+ * survives the tool being re-registered.
2526
+ */
2527
+ setToolEnabled(name, enabled, agentId) {
2528
+ const key = this.capabilityKey(name, agentId);
2529
+ if (enabled) this._disabledToolKeys.delete(key);
2530
+ else this._disabledToolKeys.add(key);
2531
+ }
2532
+ /** Whether a tool is currently enabled (not overridden off). Defaults true. */
2533
+ isToolEnabled(name, agentId) {
2534
+ return !this._disabledToolKeys.has(this.capabilityKey(name, agentId));
2535
+ }
2488
2536
  /**
2489
2537
  * Build frontend tools for an agent
2490
2538
  */
2491
2539
  buildFrontendTools(agentId) {
2492
- return this._tools.filter((tool) => tool.available !== false && tool.available !== "disabled" && (!tool.agentId || tool.agentId === agentId)).map((tool) => {
2540
+ return this._tools.filter((tool) => tool.available !== false && tool.available !== "disabled" && (!tool.agentId || tool.agentId === agentId) && this.isToolEnabled(tool.name, tool.agentId)).map((tool) => {
2493
2541
  var _tool$description;
2494
2542
  return {
2495
2543
  name: tool.name,
@@ -3151,6 +3199,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3151
3199
  message: "Failed to fetch memories",
3152
3200
  docsPath: "docs/errors/memory.md#memory_list_failed"
3153
3201
  },
3202
+ MEMORY_RECALL_FAILED: {
3203
+ code: "MEMORY_RECALL_FAILED",
3204
+ category: "dependency",
3205
+ retryable: true,
3206
+ message: "Failed to recall memories",
3207
+ docsPath: "docs/errors/memory.md#memory_recall_failed"
3208
+ },
3154
3209
  MEMORY_CREDENTIALS_FAILED: {
3155
3210
  code: "MEMORY_CREDENTIALS_FAILED",
3156
3211
  category: "dependency",
@@ -3222,6 +3277,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3222
3277
  //#region src/memory.ts
3223
3278
  const MEMORIES_PATH = "/memories";
3224
3279
  const MEMORIES_SUBSCRIBE_PATH = "/memories/subscribe";
3280
+ const MEMORIES_RECALL_PATH = "/memories/recall";
3225
3281
  const REQUEST_TIMEOUT_MS$1 = 15e3;
3226
3282
  /** Consecutive socket errors tolerated before the realtime stream gives up. */
3227
3283
  const MAX_SOCKET_RETRIES$1 = 5;
@@ -3436,10 +3492,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3436
3492
  return (0, rxjs_fetch.fromFetch)(input, init);
3437
3493
  }
3438
3494
  /**
3439
- * Fetches the memory snapshot and maps it to a success/failure action. Keeps
3440
- * only user-scoped memories (v1 surfaces user scope only; the realtime stream
3441
- * is user-scoped too), so project-scoped rows visible to the caller are
3442
- * dropped from the store.
3495
+ * Fetches the memory snapshot and maps it to a success/failure action. Both
3496
+ * user- and project-scoped rows are kept: the store now opens a second
3497
+ * `project_meta:memories:<code>` realtime channel (when project credentials are
3498
+ * available) that keeps project rows in sync, so surfacing them in the snapshot
3499
+ * no longer risks a stale list. Rows are keyed by id across both channels, so
3500
+ * realtime deltas reconcile either scope idempotently.
3443
3501
  */
3444
3502
  function createMemoryFetchObservable(environment, context, sessionId) {
3445
3503
  return (0, rxjs.defer)(() => {
@@ -3465,7 +3523,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3465
3523
  }
3466
3524
  }), (0, rxjs_operators.map)((data) => memoryRestEvents.listSucceeded({
3467
3525
  sessionId,
3468
- memories: data.memories.filter((memory) => memory.scope === "user")
3526
+ memories: data.memories
3469
3527
  })), (0, rxjs_operators.catchError)((error) => {
3470
3528
  if (error instanceof MemoryRouteUnavailableError) return (0, rxjs.of)(memoryRestEvents.listUnavailable({ sessionId }));
3471
3529
  return (0, rxjs.of)(memoryRestEvents.listFailed({
@@ -3508,10 +3566,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3508
3566
  }), (0, rxjs_operators.map)((data) => {
3509
3567
  if (typeof data.joinToken !== "string" || data.joinToken.length === 0) throw new Error("missing joinToken");
3510
3568
  if (typeof data.joinCode !== "string" || data.joinCode.length === 0) throw new Error("missing joinCode");
3569
+ const hasProjectCreds = typeof data.projectJoinToken === "string" && data.projectJoinToken.length > 0 && typeof data.projectJoinCode === "string" && data.projectJoinCode.length > 0;
3511
3570
  return memoryRestEvents.credentialsSucceeded({
3512
3571
  sessionId,
3513
3572
  joinToken: data.joinToken,
3514
- joinCode: data.joinCode
3573
+ joinCode: data.joinCode,
3574
+ ...hasProjectCreds ? {
3575
+ projectJoinToken: data.projectJoinToken,
3576
+ projectJoinCode: data.projectJoinCode
3577
+ } : {}
3515
3578
  });
3516
3579
  }), (0, rxjs_operators.catchError)((error) => {
3517
3580
  if (error instanceof MemoryRouteUnavailableError) return (0, rxjs.of)(memoryRestEvents.credentialsUnavailable({ sessionId }));
@@ -3532,6 +3595,21 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3532
3595
  invalidatedAt: data.invalidatedAt
3533
3596
  };
3534
3597
  }
3598
+ /**
3599
+ * Projects a recall REST response memory (which carries a relevance `score`)
3600
+ * to the public {@link Memory} shape. `score` is copied through when supplied.
3601
+ */
3602
+ function recallResponseToMemory(data) {
3603
+ return {
3604
+ id: data.id,
3605
+ kind: data.kind,
3606
+ scope: data.scope,
3607
+ content: data.content,
3608
+ sourceThreadIds: data.sourceThreadIds,
3609
+ invalidatedAt: data.invalidatedAt,
3610
+ ...typeof data.score === "number" ? { score: data.score } : {}
3611
+ };
3612
+ }
3535
3613
  const MEMORY_KINDS = new Set([
3536
3614
  "topical",
3537
3615
  "episodic",
@@ -3722,9 +3800,32 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3722
3800
  return action.sessionId === state.sessionId && Boolean((_state$context = state.context) === null || _state$context === void 0 ? void 0 : _state$context.wsUrl);
3723
3801
  }), (0, rxjs_operators.switchMap)(([action, state]) => {
3724
3802
  const context = state.context;
3725
- const { joinToken, joinCode } = action;
3803
+ const { joinToken, joinCode, projectJoinToken, projectJoinCode } = action;
3726
3804
  const sessionId = action.sessionId;
3727
3805
  const shutdown$ = actions$.pipe(ofType(memoryAdapterEvents.contextChanged, memoryAdapterEvents.stopped));
3806
+ const channelMetadata$ = (channelJoinToken, topic) => {
3807
+ const channel$ = ɵphoenixChannel$({
3808
+ socket$: ɵphoenixSocket$({
3809
+ url: context.wsUrl,
3810
+ options: {
3811
+ params: { join_token: channelJoinToken },
3812
+ reconnectAfterMs: (0, _copilotkit_shared.phoenixExponentialBackoff)(100, 1e4),
3813
+ rejoinAfterMs: (0, _copilotkit_shared.phoenixExponentialBackoff)(1e3, 3e4)
3814
+ }
3815
+ }).pipe((0, rxjs_operators.shareReplay)({
3816
+ bufferSize: 1,
3817
+ refCount: true
3818
+ })),
3819
+ topic
3820
+ }).pipe((0, rxjs_operators.shareReplay)({
3821
+ bufferSize: 1,
3822
+ refCount: true
3823
+ }));
3824
+ return (0, rxjs.merge)(channel$.pipe((0, rxjs_operators.switchMap)(({ channel }) => ɵobservePhoenixEvent$(channel, MEMORY_METADATA_EVENT)), (0, rxjs_operators.map)((event) => mapMemoryMetadataEvent(event, sessionId))), ɵjoinPhoenixChannel$(channel$).pipe((0, rxjs_operators.catchError)((error) => {
3825
+ console.warn(`[memory] failed to join ${topic}`, error);
3826
+ return rxjs.EMPTY;
3827
+ })));
3828
+ };
3728
3829
  return (0, rxjs.defer)(() => {
3729
3830
  const socket$ = ɵphoenixSocket$({
3730
3831
  url: context.wsUrl,
@@ -3754,7 +3855,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3754
3855
  console.warn(`[memory] failed to join user_meta:memories:${joinCode}`, error);
3755
3856
  return (0, rxjs.of)(memoryDomainEvents.realtimeUnavailable({ sessionId }));
3756
3857
  }));
3757
- return (0, rxjs.merge)((0, rxjs.of)(memoryDomainEvents.realtimeConnecting({ sessionId })), metadata$, join$, fatalStatus$).pipe((0, rxjs_operators.takeUntil)((0, rxjs.merge)(shutdown$, fatalSocketShutdown$.pipe((0, rxjs.observeOn)(rxjs.asapScheduler)))), (0, rxjs_operators.finalize)(() => {}));
3858
+ const projectMetadata$ = projectJoinToken && projectJoinCode ? channelMetadata$(projectJoinToken, `project_meta:memories:${projectJoinCode}`) : rxjs.EMPTY;
3859
+ return (0, rxjs.merge)((0, rxjs.of)(memoryDomainEvents.realtimeConnecting({ sessionId })), metadata$, join$, projectMetadata$, fatalStatus$).pipe((0, rxjs_operators.takeUntil)((0, rxjs.merge)(shutdown$, fatalSocketShutdown$.pipe((0, rxjs.observeOn)(rxjs.asapScheduler)))), (0, rxjs_operators.finalize)(() => {}));
3758
3860
  });
3759
3861
  })))
3760
3862
  ]
@@ -3796,6 +3898,37 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3796
3898
  store.dispatch(memoryRestEvents.listRequested({ sessionId }));
3797
3899
  return done;
3798
3900
  },
3901
+ recall(query, opts) {
3902
+ const { context } = store.getState();
3903
+ if (!(context === null || context === void 0 ? void 0 : context.runtimeUrl)) return Promise.reject(/* @__PURE__ */ new Error("Runtime URL is not configured"));
3904
+ const body = { query };
3905
+ if ((opts === null || opts === void 0 ? void 0 : opts.limit) !== void 0) body.limit = opts.limit;
3906
+ if ((opts === null || opts === void 0 ? void 0 : opts.scope) !== void 0) body.scope = opts.scope;
3907
+ return (0, rxjs.firstValueFrom)(memoryFromFetch(`${context.runtimeUrl}${MEMORIES_RECALL_PATH}`, {
3908
+ selector: async (response) => {
3909
+ if (!response.ok) throw new MemoryError("MEMORY_RECALL_FAILED", {
3910
+ message: `Failed to recall memories: ${response.status}`,
3911
+ retryable: isRetryableStatus(response.status)
3912
+ });
3913
+ return await response.json();
3914
+ },
3915
+ fetch: environment.fetch,
3916
+ method: "POST",
3917
+ headers: {
3918
+ ...context.headers,
3919
+ "Content-Type": "application/json"
3920
+ },
3921
+ body: JSON.stringify(body)
3922
+ }).pipe((0, rxjs_operators.timeout)({
3923
+ first: REQUEST_TIMEOUT_MS$1,
3924
+ with: () => {
3925
+ throw new MemoryError("MEMORY_REQUEST_TIMEOUT");
3926
+ }
3927
+ }), (0, rxjs_operators.map)((data) => {
3928
+ var _data$memories;
3929
+ return ((_data$memories = data.memories) !== null && _data$memories !== void 0 ? _data$memories : []).map((m) => recallResponseToMemory(m));
3930
+ })));
3931
+ },
3799
3932
  addMemory(input) {
3800
3933
  return trackMutation(memoryAdapterEvents.addRequested({
3801
3934
  requestId: createMemoryRequestId(),
@@ -4011,6 +4144,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4011
4144
  get tools() {
4012
4145
  return this.runHandler.tools;
4013
4146
  }
4147
+ get catalogComponents() {
4148
+ return this.runHandler.catalogComponents;
4149
+ }
4014
4150
  get runtimeUrl() {
4015
4151
  return this.agentRegistry.runtimeUrl;
4016
4152
  }
@@ -4339,6 +4475,46 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4339
4475
  this.runHandler.setTools(tools);
4340
4476
  }
4341
4477
  /**
4478
+ * Enable/disable a registered frontend tool at runtime without unregistering
4479
+ * it (Inspector "Capabilities" tool). A disabled tool is omitted from the
4480
+ * tool list sent to the agent on the next run. The override is keyed by name
4481
+ * (+ optional agentId) and survives the tool being re-registered.
4482
+ */
4483
+ setToolEnabled(name, enabled, agentId) {
4484
+ this.runHandler.setToolEnabled(name, enabled, agentId);
4485
+ }
4486
+ /** Whether a registered tool is currently enabled (defaults true). */
4487
+ isToolEnabled(name, agentId) {
4488
+ return this.runHandler.isToolEnabled(name, agentId);
4489
+ }
4490
+ /**
4491
+ * A2UI catalog component management (delegated to RunHandler).
4492
+ * Registers the full component list and controls per-component enablement.
4493
+ */
4494
+ setCatalogComponents(components) {
4495
+ this.runHandler.setCatalogComponents(components);
4496
+ this.notifySubscribers((subscriber) => {
4497
+ var _subscriber$onCatalog;
4498
+ return (_subscriber$onCatalog = subscriber.onCatalogComponentsChanged) === null || _subscriber$onCatalog === void 0 ? void 0 : _subscriber$onCatalog.call(subscriber, {
4499
+ copilotkit: this,
4500
+ catalogComponents: this.runHandler.catalogComponents
4501
+ });
4502
+ }, "Subscriber onCatalogComponentsChanged error:");
4503
+ }
4504
+ setCatalogComponentEnabled(name, enabled) {
4505
+ this.runHandler.setCatalogComponentEnabled(name, enabled);
4506
+ this.notifySubscribers((subscriber) => {
4507
+ var _subscriber$onCatalog2;
4508
+ return (_subscriber$onCatalog2 = subscriber.onCatalogComponentsChanged) === null || _subscriber$onCatalog2 === void 0 ? void 0 : _subscriber$onCatalog2.call(subscriber, {
4509
+ copilotkit: this,
4510
+ catalogComponents: this.runHandler.catalogComponents
4511
+ });
4512
+ }, "Subscriber onCatalogComponentsChanged error:");
4513
+ }
4514
+ isCatalogComponentEnabled(name) {
4515
+ return this.runHandler.isCatalogComponentEnabled(name);
4516
+ }
4517
+ /**
4342
4518
  * Subscription lifecycle
4343
4519
  */
4344
4520
  subscribe(subscriber) {