@copilotkit/core 1.62.1 → 1.62.2-canary.1784333495

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.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _ag_ui_client0 from "@ag-ui/client";
2
2
  import { AbstractAgent, AgentCapabilities, AgentSubscriber, BaseEvent, Context, HttpAgent, HttpAgentConfig, Message, ResumeEntry, RunAgentInput, RunAgentParameters, RunAgentResult, State, Tool, ToolCall } from "@ag-ui/client";
3
3
  import { DebugConfig, IntelligenceRuntimeInfo, IntelligenceRuntimeInfo as IntelligenceRuntimeInfo$1, ResolvedDebugConfig, RuntimeLicenseStatus, RuntimeLicenseStatus as RuntimeLicenseStatus$1, RuntimeMode, RuntimeMode as RuntimeMode$1, StandardSchemaV1, ThreadEndpointRuntimeInfo, ThreadEndpointRuntimeInfo as ThreadEndpointRuntimeInfo$1 } from "@copilotkit/shared";
4
- import { Observable, OperatorFunction } from "rxjs";
4
+ import { Observable, OperatorFunction, Subscription } from "rxjs";
5
5
 
6
6
  //#region src/types.d.ts
7
7
  /**
@@ -388,6 +388,11 @@ declare class ContextStore {
388
388
  interface CopilotKitCoreRunAgentParams {
389
389
  agent: AbstractAgent;
390
390
  forwardedProps?: Record<string, unknown>;
391
+ /**
392
+ * Optional caller-supplied run identifier forwarded to the underlying AG-UI
393
+ * agent. When omitted, the agent creates one.
394
+ */
395
+ runId?: string;
391
396
  /**
392
397
  * Per-interrupt responses addressing every open AG-UI interrupt from the
393
398
  * previous run. Forwarded to the agent as the standard `resume` array.
@@ -466,7 +471,9 @@ declare class RunHandler {
466
471
  * downstream churn into duplicate `cpki_event_id` rows in the
467
472
  * inspector and intermittent "Message not found" toasts.
468
473
  */
469
- private _lastConnectedThreadId;
474
+ private _lastConnectedThreadIdsByAgent;
475
+ private _anonymousAgentIds;
476
+ private _nextAnonymousAgentId;
470
477
  constructor(core: CopilotKitCore);
471
478
  /**
472
479
  * Abort the current run. Called by `CopilotKitCore.stopAgent()` to signal
@@ -479,6 +486,12 @@ declare class RunHandler {
479
486
  * Centralises the single unavoidable cast so call-sites stay clean.
480
487
  */
481
488
  private get _internal();
489
+ /**
490
+ * Return a stable restore-tracking key for the logical agent being
491
+ * connected. Named agents share their last-thread marker across proxy
492
+ * instances; anonymous agents fall back to object identity.
493
+ */
494
+ private getConnectRestoreKey;
482
495
  /**
483
496
  * Get all tools as a readonly array
484
497
  */
@@ -517,7 +530,8 @@ declare class RunHandler {
517
530
  runAgent({
518
531
  agent,
519
532
  forwardedProps,
520
- resume
533
+ resume,
534
+ runId
521
535
  }: CopilotKitCoreRunAgentParams): Promise<RunAgentResult>;
522
536
  /**
523
537
  * Process agent result and execute tools
@@ -577,6 +591,62 @@ declare function ensureObjectArgs(parsed: unknown, toolName: string): Record<str
577
591
  */
578
592
  declare function parseToolArguments(rawArgs: unknown, toolName: string): Record<string, unknown>;
579
593
  //#endregion
594
+ //#region src/core/subagent-registry.d.ts
595
+ type SubagentStatus = "running" | "finished" | "error";
596
+ /**
597
+ * The observed lifecycle state of a single subagent invocation, keyed in the
598
+ * registry by its `subagentId`. `name`/`description` come from SUBAGENT_STARTED
599
+ * so the UI can show a friendly label instead of the opaque id.
600
+ */
601
+ interface SubagentState {
602
+ subagentId: string;
603
+ name: string;
604
+ description?: string;
605
+ parentSubagentId?: string;
606
+ status: SubagentStatus;
607
+ /** Set only when `status === "error"` (from SUBAGENT_ERROR.message). */
608
+ error?: string;
609
+ }
610
+ /**
611
+ * Tracks subagent lifecycle events (SUBAGENT_STARTED / FINISHED / ERROR) per
612
+ * owning agent so consumers can resolve a message's `subagentId` to a name,
613
+ * description, and running status.
614
+ *
615
+ * Modeled on {@link SuggestionEngine}: an in-memory `Record` keyed by (owning)
616
+ * agentId, mutated from streamed AG-UI events, made reactive by calling
617
+ * `notifySubscribers(onSubagentsChanged)` after every change. It owns its own
618
+ * per-agent `agent.subscribe` (like {@link StateManager}) so it is fully
619
+ * self-contained and adds no coupling to the state/message tracking path.
620
+ *
621
+ * No-op for runs without subagents (a normal LangGraph run never emits
622
+ * SUBAGENT_* events), so the registry simply stays empty.
623
+ */
624
+ declare class SubagentRegistry {
625
+ private core;
626
+ private _subagents;
627
+ private agentSubscriptions;
628
+ constructor(core: CopilotKitCore);
629
+ /**
630
+ * Subscribe to an agent's subagent lifecycle events. Idempotent per agentId:
631
+ * an existing subscription for the same agent is revoked and replaced.
632
+ */
633
+ subscribeToAgent(agent: AbstractAgent): void;
634
+ /**
635
+ * Unsubscribe an agent's subscription (symmetric with StateManager cleanup).
636
+ */
637
+ unsubscribeFromAgent(agentId: string): void;
638
+ /**
639
+ * Get the subagents observed for an owning agent, keyed by subagentId.
640
+ * Returns a fresh shallow copy each call so consumers (and React state) see
641
+ * a new reference when anything changed.
642
+ */
643
+ getSubagents(agentId: string): Record<string, SubagentState>;
644
+ private handleStarted;
645
+ private handleFinished;
646
+ private handleError;
647
+ private notifySubagentsChanged;
648
+ }
649
+ //#endregion
580
650
  //#region src/utils/micro-redux.d.ts
581
651
  /**
582
652
  * The minimal action shape used by this micro-redux implementation.
@@ -819,6 +889,18 @@ type ThreadMetadataEvent = {
819
889
  id: string;
820
890
  };
821
891
  };
892
+ /**
893
+ * Internal notification emitted when Intelligence observes new run activity
894
+ * for a thread without changing that thread's metadata row.
895
+ */
896
+ type ThreadRunActivityNotification = {
897
+ type: "thread_run_activity";
898
+ threadId: string;
899
+ agentId?: string;
900
+ runId?: string;
901
+ eventType: string;
902
+ latestEventId?: string;
903
+ };
822
904
  interface ThreadEnvironment {
823
905
  fetch: typeof fetch;
824
906
  /**
@@ -836,6 +918,14 @@ interface ThreadState {
836
918
  isLoading: boolean;
837
919
  isFetchingNextPage: boolean;
838
920
  error: Error | null;
921
+ /**
922
+ * Error from the most recent failed next-page (`fetchMore`) load, or `null`.
923
+ * Tracked SEPARATELY from `error` so a paginated-load failure surfaces an
924
+ * inline "couldn't load more" affordance without replacing the already-loaded
925
+ * list with a full-panel error. Cleared when a fetch-more is retried or when
926
+ * one succeeds; reset on context change / stop.
927
+ */
928
+ fetchMoreError: Error | null;
839
929
  context: ThreadRuntimeContext | null;
840
930
  sessionId: number;
841
931
  metadataCredentialsRequested: boolean;
@@ -861,6 +951,7 @@ interface ThreadSelectors {
861
951
  threads: (state: ThreadState) => ThreadRecord[];
862
952
  isLoading: (state: ThreadState) => boolean;
863
953
  error: (state: ThreadState) => Error | null;
954
+ fetchMoreError: (state: ThreadState) => Error | null;
864
955
  hasNextPage: (state: ThreadState) => boolean;
865
956
  isFetchingNextPage: (state: ThreadState) => boolean;
866
957
  isMutating: (state: ThreadState) => boolean;
@@ -904,6 +995,11 @@ interface ThreadStore {
904
995
  archiveThread(threadId: string): Promise<void>;
905
996
  unarchiveThread(threadId: string): Promise<void>;
906
997
  deleteThread(threadId: string): Promise<void>;
998
+ /**
999
+ * Subscribes to synthetic run-activity notifications without changing the
1000
+ * thread metadata list.
1001
+ */
1002
+ subscribeToRunActivity?(callback: (notification: ThreadRunActivityNotification) => void): Subscription;
907
1003
  getState(): ThreadState;
908
1004
  /**
909
1005
  * Returns a stable initial snapshot for server-side rendering.
@@ -963,6 +1059,7 @@ declare const ɵcreateThreadSelectors: typeof createThreadSelectors;
963
1059
  declare const ɵselectThreads: (state: ThreadState) => ThreadRecord[];
964
1060
  declare const ɵselectThreadsIsLoading: (state: ThreadState) => boolean;
965
1061
  declare const ɵselectThreadsError: (state: ThreadState) => Error | null;
1062
+ declare const ɵselectFetchMoreError: (state: ThreadState) => Error | null;
966
1063
  declare const ɵselectHasNextPage: (state: ThreadState) => boolean;
967
1064
  declare const ɵselectIsFetchingNextPage: (state: ThreadState) => boolean;
968
1065
  declare const ɵselectIsMutating: (state: ThreadState) => boolean;
@@ -974,6 +1071,383 @@ declare const ɵselectIsMutating: (state: ThreadState) => boolean;
974
1071
  */
975
1072
  declare const ɵMAX_SOCKET_RETRIES = 5;
976
1073
  //#endregion
1074
+ //#region src/memory-errors.d.ts
1075
+ /**
1076
+ * Memory error registry — stable codes for the errors the memory store throws.
1077
+ *
1078
+ * The memory store (`memory.ts`) used to throw bare `new Error("Failed to fetch
1079
+ * memories: 500")` / `"Request timed out"` / `"Request failed: <status>"`. Those
1080
+ * reach the `error` selector (and the consumer UI via `useMemories` /
1081
+ * `injectMemories`) verbatim, with no machine-readable `code`/`category`/
1082
+ * `retryable`, so they cannot be grouped in observability or branched on by
1083
+ * consumers.
1084
+ *
1085
+ * Per the repo's error-handling architecture standard (AGENTS.md: "Each project
1086
+ * must maintain an explicit error registry"), this file is the explicit registry
1087
+ * for the memory feature. It is deliberately scoped to memory — not a repo-wide
1088
+ * registry refactor — because `packages/core` has no pre-existing
1089
+ * code/category/retryable registry convention to plug into (the runtime's
1090
+ * `lib/error-messages.ts` is a message-templating table, not a typed
1091
+ * code/category/retryable registry). It mirrors the existing
1092
+ * `AgentThreadLockedError extends Error` precedent in
1093
+ * `intelligence-agent.ts`: a real `Error` subclass so `instanceof Error` holds
1094
+ * and the public `MemoryState.error: Error | null` contract is preserved.
1095
+ *
1096
+ * `docsPath` is recorded per entry per the standard; there is no
1097
+ * `docs/errors/<project>.md` in this repo, so this docblock plus the registry
1098
+ * are the source of truth.
1099
+ *
1100
+ * Each registry entry carries:
1101
+ * - `code`: stable identifier (e.g. `MEMORY_LIST_FAILED`).
1102
+ * - `category`: one of the standard categories
1103
+ * (`validation`|`auth`|`permission`|`not_found`|`conflict`|`rate_limit`|`internal`|`dependency`).
1104
+ * - `retryable`: whether a retry could plausibly succeed (timeouts + transient
1105
+ * dependency failures are retryable; client-caused 4xx are not).
1106
+ * - `message`: the default human-readable message (callers may override with a
1107
+ * status-bearing string to preserve the prior wording).
1108
+ * - `docsPath`: documentation pointer for the code.
1109
+ */
1110
+ /** Standard error categories from the repo error-handling architecture. */
1111
+ type MemoryErrorCategory = "validation" | "auth" | "permission" | "not_found" | "conflict" | "rate_limit" | "internal" | "dependency";
1112
+ /** Stable codes for the memory store's surfaced errors. */
1113
+ type MemoryErrorCode = "MEMORY_LIST_FAILED" | "MEMORY_CREDENTIALS_FAILED" | "MEMORY_MUTATION_FAILED" | "MEMORY_REQUEST_TIMEOUT";
1114
+ /** A single registry entry describing one memory error code. */
1115
+ interface MemoryErrorRegistryEntry {
1116
+ readonly code: MemoryErrorCode;
1117
+ readonly category: MemoryErrorCategory;
1118
+ readonly retryable: boolean;
1119
+ readonly message: string;
1120
+ readonly docsPath: string;
1121
+ }
1122
+ /**
1123
+ * The memory error registry: the single source of truth for memory error
1124
+ * metadata. Keyed by `code` so a code maps to exactly one category/retryable
1125
+ * default.
1126
+ *
1127
+ * Categories/retryable rationale:
1128
+ * - List/credentials/mutation failures are `dependency` (the runtime/platform
1129
+ * the store calls failed). A 5xx is transient (`retryable: true`); a 4xx is
1130
+ * caller-caused, so the helpers below downgrade those to non-retryable.
1131
+ * - Timeouts are `dependency` and `retryable: true` (the request may simply be
1132
+ * slow).
1133
+ */
1134
+ declare const MEMORY_ERROR_REGISTRY: Readonly<Record<MemoryErrorCode, MemoryErrorRegistryEntry>>;
1135
+ /**
1136
+ * An `Error` carrying a stable memory error `code`, `category`, and `retryable`
1137
+ * flag so consumers and observability can branch on it without string-matching
1138
+ * the message.
1139
+ *
1140
+ * It is a real `Error` subclass: `instanceof Error` is true, so the public
1141
+ * `MemoryState.error: Error | null` contract (and the `error: Error | null`
1142
+ * surfaced by `useMemories` / `injectMemories`) holds unchanged. Existing
1143
+ * consumers that only read `.message` keep working; the richer fields are
1144
+ * additive.
1145
+ */
1146
+ declare class MemoryError extends Error {
1147
+ /** Stable, machine-readable error identifier. */
1148
+ readonly code: MemoryErrorCode;
1149
+ /** Coarse error category for grouping/observability. */
1150
+ readonly category: MemoryErrorCategory;
1151
+ /** Whether retrying the operation could plausibly succeed. */
1152
+ readonly retryable: boolean;
1153
+ /**
1154
+ * @param code - Registry code identifying this error.
1155
+ * @param options - Optional overrides:
1156
+ * - `message`: human-readable message (defaults to the registry message;
1157
+ * callers pass a status-bearing string to preserve prior wording).
1158
+ * - `retryable`: overrides the registry default (e.g. a 4xx list failure is
1159
+ * not retryable even though the code's default is).
1160
+ * - `cause`: the underlying error, preserved for debugging.
1161
+ */
1162
+ constructor(code: MemoryErrorCode, options?: {
1163
+ message?: string;
1164
+ retryable?: boolean;
1165
+ cause?: unknown;
1166
+ });
1167
+ }
1168
+ /**
1169
+ * Narrows an HTTP status to whether the failure is worth retrying: a 5xx (or a
1170
+ * missing/0 status) is a transient dependency failure and retryable; a 4xx is
1171
+ * caller-caused and not. Used so a `MEMORY_LIST_FAILED`/`MEMORY_MUTATION_FAILED`
1172
+ * carries an accurate `retryable` flag derived from the response status.
1173
+ */
1174
+ declare function isRetryableStatus(status: number): boolean;
1175
+ //#endregion
1176
+ //#region src/memory.d.ts
1177
+ /** Public, customer-facing memory kind vocabulary (single taxonomy, no mapping). */
1178
+ type MemoryKind = "topical" | "episodic" | "operational";
1179
+ /** Visibility scope of a memory. */
1180
+ type MemoryScope = "user" | "project";
1181
+ /**
1182
+ * Health of the realtime (`user_meta:memories:<code>`) connection that streams
1183
+ * live `memory_metadata` deltas. Distinct from `available`/`error`, which
1184
+ * describe the REST list route: `realtimeStatus` reports ONLY whether the
1185
+ * realtime socket/channel is live so the UI can stop showing a "live" indicator
1186
+ * over a frozen snapshot once the socket permanently gives up.
1187
+ *
1188
+ * - `"connecting"` — fetching join credentials / opening the socket / joining
1189
+ * the channel (the default, and the state every `contextChanged`/`stopped`
1190
+ * resets to).
1191
+ * - `"connected"` — the channel join succeeded; live deltas are flowing.
1192
+ * - `"unavailable"` — the socket exhausted its retries or the join failed
1193
+ * permanently; the snapshot is frozen and no deltas will arrive. This is a
1194
+ * silent degrade for `available`/`error` (those stay untouched) — only this
1195
+ * signal flips.
1196
+ */
1197
+ type MemoryRealtimeStatus = "connecting" | "connected" | "unavailable";
1198
+ /**
1199
+ * A memory as projected across the public REST/realtime boundary — the minimal
1200
+ * shape the SDK surfaces. Mirrors the server's `PublicMemory` projection.
1201
+ */
1202
+ interface Memory {
1203
+ id: string;
1204
+ kind: MemoryKind;
1205
+ scope: MemoryScope;
1206
+ content: string;
1207
+ sourceThreadIds: readonly string[];
1208
+ invalidatedAt: string | null;
1209
+ }
1210
+ /** Input for creating a memory; `scope` defaults to `"user"` (v1 is user-scoped). */
1211
+ interface NewMemory {
1212
+ content: string;
1213
+ kind: MemoryKind;
1214
+ scope?: MemoryScope;
1215
+ sourceThreadIds?: readonly string[];
1216
+ }
1217
+ /**
1218
+ * New values for superseding (updating) a memory — same shape as create.
1219
+ *
1220
+ * Supersede is a FULL replacement, not a partial patch: this is the complete
1221
+ * definition of the new memory that replaces the old one. `content` and `kind`
1222
+ * are required and must be re-supplied, and an omitted `sourceThreadIds` resets
1223
+ * the new memory's source threads to `[]` — it does NOT preserve the prior
1224
+ * memory's value.
1225
+ */
1226
+ type MemoryChanges = NewMemory;
1227
+ /** Outcome of a mutation, tracked so the caller's promise resolves/rejects. */
1228
+ type MemoryMutationOutcome = {
1229
+ requestId: string;
1230
+ sessionId: number;
1231
+ ok: true;
1232
+ memory: Memory | null;
1233
+ } | {
1234
+ requestId: string;
1235
+ sessionId: number;
1236
+ ok: false;
1237
+ error: Error;
1238
+ };
1239
+ /**
1240
+ * Runtime wiring for the memory store: where to reach the REST surface and the
1241
+ * headers (auth + `X-Cpki-User-Id`) to send. Scoped to the current user; v1
1242
+ * surfaces user-scoped memories only.
1243
+ */
1244
+ interface MemoryRuntimeContext {
1245
+ runtimeUrl: string;
1246
+ /** WebSocket URL for the realtime gateway (e.g. `wss://gw.example.com/client`). */
1247
+ wsUrl: string;
1248
+ headers: Record<string, string>;
1249
+ includeInvalidated?: boolean;
1250
+ }
1251
+ /**
1252
+ * In-memory state for the memory store. Session-guarded like the thread store:
1253
+ * `sessionId` is bumped whenever the runtime context changes so that responses
1254
+ * and realtime deltas from a previous context are ignored.
1255
+ */
1256
+ interface MemoryState {
1257
+ memories: Memory[];
1258
+ isLoading: boolean;
1259
+ inFlightMutationCount: number;
1260
+ error: Error | null;
1261
+ context: MemoryRuntimeContext | null;
1262
+ sessionId: number;
1263
+ available: boolean;
1264
+ realtimeStatus: MemoryRealtimeStatus;
1265
+ }
1266
+ declare const memoryDomainEvents: ActionGroupResult<"Memory Domain", {
1267
+ readonly memoryUpserted: PropsActionConfig<{
1268
+ sessionId: number;
1269
+ memory: Memory;
1270
+ }>;
1271
+ readonly memoryInvalidated: PropsActionConfig<{
1272
+ sessionId: number;
1273
+ memoryId: string;
1274
+ }>;
1275
+ readonly realtimeConnecting: PropsActionConfig<{
1276
+ sessionId: number;
1277
+ }>;
1278
+ readonly realtimeConnected: PropsActionConfig<{
1279
+ sessionId: number;
1280
+ }>;
1281
+ readonly realtimeUnavailable: PropsActionConfig<{
1282
+ sessionId: number;
1283
+ }>;
1284
+ }>;
1285
+ /** Wire shape of a memory inside a `memory_metadata` payload (carries tenant ids). */
1286
+ interface MemoryMetadataPayloadMemory extends Memory {
1287
+ organizationId: string;
1288
+ projectId: string;
1289
+ }
1290
+ /**
1291
+ * The realtime `memory_metadata` event broadcast on the `user_meta` channel:
1292
+ * `created`/`updated` carry the full memory, `invalidated` carries only its id.
1293
+ * The gateway strips `userId` before broadcasting and only delivers
1294
+ * user-scoped memories, so this is always the current user's stream.
1295
+ */
1296
+ type MemoryMetadataEvent = {
1297
+ operation: "created" | "updated";
1298
+ memoryId: string;
1299
+ organizationId: string;
1300
+ projectId: string;
1301
+ occurredAt: string;
1302
+ memory: MemoryMetadataPayloadMemory;
1303
+ } | {
1304
+ operation: "invalidated";
1305
+ memoryId: string;
1306
+ organizationId: string;
1307
+ projectId: string;
1308
+ occurredAt: string;
1309
+ invalidated: {
1310
+ id: string;
1311
+ };
1312
+ };
1313
+ /**
1314
+ * Maps a realtime `memory_metadata` event to the domain action that applies it:
1315
+ * `created`/`updated` upsert the projected memory, `invalidated` removes it by
1316
+ * id. Carries the current `sessionId` so the reducer's session guard can drop
1317
+ * deltas left over from a previous context.
1318
+ */
1319
+ declare function mapMemoryMetadataEvent(event: MemoryMetadataEvent, sessionId: number): ReturnType<typeof memoryDomainEvents.memoryUpserted> | ReturnType<typeof memoryDomainEvents.memoryInvalidated>;
1320
+ /**
1321
+ * Dependencies injected into the memory store. The store opens its own
1322
+ * `user_meta:memories:<joinCode>` socket/channel and does not share the
1323
+ * thread store's socket, so only a `fetch` implementation is required.
1324
+ */
1325
+ interface MemoryEnvironment {
1326
+ fetch: typeof fetch;
1327
+ }
1328
+ interface MemoryStore {
1329
+ start(): void;
1330
+ stop(): void;
1331
+ setContext(context: MemoryRuntimeContext | null): void;
1332
+ /**
1333
+ * Re-fetches the REST snapshot without clearing the current list. Resolves
1334
+ * once the re-pull settles (success or failure) for the current context, so
1335
+ * callers (e.g. a `useMemories` `refresh()`) can await it. Resolves
1336
+ * immediately when no context is set.
1337
+ */
1338
+ refresh(): Promise<void>;
1339
+ /** Creates a memory; resolves to the stored memory (server-authoritative). */
1340
+ addMemory(input: NewMemory): Promise<Memory>;
1341
+ /** Supersedes a memory; resolves to the new memory (its id changes). */
1342
+ updateMemory(id: string, changes: MemoryChanges): Promise<Memory>;
1343
+ /** Retires a memory (non-lossy delete). */
1344
+ removeMemory(id: string): Promise<void>;
1345
+ getState(): MemoryState;
1346
+ /**
1347
+ * Stable, render-safe state for SSR/prerender. React's
1348
+ * `useSyncExternalStore` requires a `getServerSnapshot` during SSR/prerender
1349
+ * (e.g. Next.js); without one React throws "Missing getServerSnapshot". The
1350
+ * returned reference is stable across calls so React does not loop. There is
1351
+ * no client-side memory data during prerender, so this is the empty initial
1352
+ * state (no memories, not loading, no error).
1353
+ */
1354
+ getServerState(): MemoryState;
1355
+ select: Store<MemoryState>["select"];
1356
+ }
1357
+ /**
1358
+ * Creates the framework-agnostic memory store: a REST snapshot on `setContext`,
1359
+ * server-authoritative add/update/remove mutations, and realtime
1360
+ * `memory_metadata` deltas off the injected `user_meta` event source — all
1361
+ * reduced into observable state.
1362
+ */
1363
+ declare function createMemoryStore(environment: MemoryEnvironment): MemoryStore;
1364
+ type ɵMemoryState = MemoryState;
1365
+ type ɵMemoryRuntimeContext = MemoryRuntimeContext;
1366
+ type ɵMemoryMetadataEvent = MemoryMetadataEvent;
1367
+ type ɵMemoryEnvironment = MemoryEnvironment;
1368
+ type ɵMemoryStore = MemoryStore;
1369
+ declare const ɵmemoryAdapterEvents: ActionGroupResult<"Memory Adapter", {
1370
+ readonly started: EmptyActionConfig;
1371
+ readonly stopped: EmptyActionConfig;
1372
+ readonly contextChanged: PropsActionConfig<{
1373
+ context: MemoryRuntimeContext | null;
1374
+ }>;
1375
+ readonly addRequested: PropsActionConfig<{
1376
+ requestId: string;
1377
+ input: NewMemory;
1378
+ }>;
1379
+ readonly updateRequested: PropsActionConfig<{
1380
+ requestId: string;
1381
+ id: string;
1382
+ changes: MemoryChanges;
1383
+ }>;
1384
+ readonly removeRequested: PropsActionConfig<{
1385
+ requestId: string;
1386
+ id: string;
1387
+ }>;
1388
+ }>;
1389
+ declare const ɵmemoryRestEvents: ActionGroupResult<"Memory REST", {
1390
+ readonly listRequested: PropsActionConfig<{
1391
+ sessionId: number;
1392
+ }>;
1393
+ readonly listSucceeded: PropsActionConfig<{
1394
+ sessionId: number;
1395
+ memories: Memory[];
1396
+ }>;
1397
+ readonly listFailed: PropsActionConfig<{
1398
+ sessionId: number;
1399
+ error: Error;
1400
+ }>;
1401
+ readonly listUnavailable: PropsActionConfig<{
1402
+ sessionId: number;
1403
+ }>;
1404
+ readonly mutationFinished: PropsActionConfig<{
1405
+ outcome: MemoryMutationOutcome;
1406
+ }>;
1407
+ readonly credentialsRequested: PropsActionConfig<{
1408
+ sessionId: number;
1409
+ }>;
1410
+ readonly credentialsSucceeded: PropsActionConfig<{
1411
+ sessionId: number;
1412
+ joinToken: string;
1413
+ joinCode: string;
1414
+ }>;
1415
+ readonly credentialsFailed: PropsActionConfig<{
1416
+ sessionId: number;
1417
+ error: Error;
1418
+ }>;
1419
+ readonly credentialsUnavailable: PropsActionConfig<{
1420
+ sessionId: number;
1421
+ }>;
1422
+ }>;
1423
+ declare const ɵmemoryDomainEvents: ActionGroupResult<"Memory Domain", {
1424
+ readonly memoryUpserted: PropsActionConfig<{
1425
+ sessionId: number;
1426
+ memory: Memory;
1427
+ }>;
1428
+ readonly memoryInvalidated: PropsActionConfig<{
1429
+ sessionId: number;
1430
+ memoryId: string;
1431
+ }>;
1432
+ readonly realtimeConnecting: PropsActionConfig<{
1433
+ sessionId: number;
1434
+ }>;
1435
+ readonly realtimeConnected: PropsActionConfig<{
1436
+ sessionId: number;
1437
+ }>;
1438
+ readonly realtimeUnavailable: PropsActionConfig<{
1439
+ sessionId: number;
1440
+ }>;
1441
+ }>;
1442
+ declare const ɵmemoryReducer: Reducer<MemoryState>;
1443
+ declare const ɵmapMemoryMetadataEvent: typeof mapMemoryMetadataEvent;
1444
+ declare const ɵselectMemories: Selector<MemoryState, Memory[]>;
1445
+ declare const ɵselectMemoriesIsLoading: Selector<MemoryState, boolean>;
1446
+ declare const ɵselectMemoriesError: Selector<MemoryState, Error | null>;
1447
+ declare const ɵselectMemoriesIsMutating: Selector<MemoryState, boolean>;
1448
+ declare const ɵselectMemoriesAvailable: Selector<MemoryState, boolean>;
1449
+ declare const ɵselectMemoriesRealtimeStatus: Selector<MemoryState, MemoryRealtimeStatus>;
1450
+ //#endregion
977
1451
  //#region src/core/core.d.ts
978
1452
  /** Configuration options for `CopilotKitCore`. */
979
1453
  interface CopilotKitCoreConfig {
@@ -1096,6 +1570,11 @@ interface CopilotKitCoreSubscriber {
1096
1570
  copilotkit: CopilotKitCore;
1097
1571
  agentId: string;
1098
1572
  }) => void | Promise<void>;
1573
+ onSubagentsChanged?: (event: {
1574
+ copilotkit: CopilotKitCore;
1575
+ agentId: string;
1576
+ subagents: Readonly<Record<string, SubagentState>>;
1577
+ }) => void | Promise<void>;
1099
1578
  onPropertiesChanged?: (event: {
1100
1579
  copilotkit: CopilotKitCore;
1101
1580
  properties: Readonly<Record<string, unknown>>;
@@ -1244,7 +1723,15 @@ declare class CopilotKitCore {
1244
1723
  private suggestionEngine;
1245
1724
  private runHandler;
1246
1725
  private stateManager;
1726
+ private subagentRegistry;
1247
1727
  private threadStoreRegistry;
1728
+ /**
1729
+ * The single core-owned memory store, created lazily on first
1730
+ * `getMemoryStore()` and kept user-scoped for the lifetime of the core.
1731
+ * Its runtime context is wired by the core itself (see `syncMemoryContext`),
1732
+ * so callers never register or look it up by `agentId`.
1733
+ */
1734
+ private _memoryStore?;
1248
1735
  /**
1249
1736
  * Tracks the agent IDs from the most recent `onAgentsChanged` notification.
1250
1737
  * Used to gate thread-store auto-unregister so the FIRST empty-agents
@@ -1416,6 +1903,29 @@ declare class CopilotKitCore {
1416
1903
  unregisterThreadStore(agentId: string): void;
1417
1904
  getThreadStore(agentId: string): ɵThreadStore | undefined;
1418
1905
  getThreadStores(): Readonly<Record<string, ɵThreadStore>>;
1906
+ /**
1907
+ * Returns the single core-owned, user-scoped memory store, creating and
1908
+ * starting it on first access. Unlike thread stores, memory is not scoped per
1909
+ * agent: there is exactly one store whose runtime context the core wires
1910
+ * itself (see `syncMemoryContext`), so consumers (e.g. a `useMemories`
1911
+ * binding) just read this store rather than registering one.
1912
+ */
1913
+ getMemoryStore(): ɵMemoryStore;
1914
+ /**
1915
+ * Lazily creates, starts, and context-syncs the core-owned memory store on
1916
+ * first access, then returns it. Subsequent calls return the existing store.
1917
+ * The store is constructed with a bound `globalThis.fetch` and immediately
1918
+ * has its runtime context synced from the current connection state.
1919
+ */
1920
+ private ensureMemoryStore;
1921
+ /**
1922
+ * Pushes the current runtime wiring into the memory store. When the runtime
1923
+ * is connected and both the intelligence WebSocket URL and runtime URL are
1924
+ * available, the store receives a context (runtime URL, WebSocket URL, and a
1925
+ * copy of the current headers); otherwise its context is cleared. No-op when
1926
+ * the store has not been created yet.
1927
+ */
1928
+ private syncMemoryContext;
1419
1929
  /**
1420
1930
  * Suggestions management (delegated to SuggestionEngine)
1421
1931
  */
@@ -1424,6 +1934,14 @@ declare class CopilotKitCore {
1424
1934
  reloadSuggestions(agentId: string): void;
1425
1935
  clearSuggestions(agentId: string): void;
1426
1936
  getSuggestions(agentId: string): CopilotKitCoreGetSuggestionsResult;
1937
+ /**
1938
+ * Subagent registry (delegated to SubagentRegistry).
1939
+ *
1940
+ * Returns the subagents observed for an owning agent during its run(s),
1941
+ * keyed by `subagentId`, each carrying `name` / `description` / `status`.
1942
+ * Empty for runs that never emit SUBAGENT_* events.
1943
+ */
1944
+ getSubagents(agentId: string): Readonly<Record<string, SubagentState>>;
1427
1945
  /**
1428
1946
  * Tool management (delegated to RunHandler)
1429
1947
  */
@@ -1787,8 +2305,11 @@ declare class IntelligenceAgent extends AbstractAgent {
1787
2305
  clearReconnectCursor(threadId: string): void;
1788
2306
  private updateLastSeenEventId;
1789
2307
  private updateLastSeenEventIdFromControl;
2308
+ private advanceLastSeenEventId;
1790
2309
  private readEventId;
1791
2310
  private readControlEventId;
2311
+ private readDurableEventId;
2312
+ private canFallbackCompleteConnect;
1792
2313
  private applyCanonicalRunIdentity;
1793
2314
  private isSocketReconnectExhaustedError;
1794
2315
  }
@@ -1948,5 +2469,5 @@ type ɵCopilotKitFeature = (typeof ɵCOPILOTKIT_FEATURES)[number];
1948
2469
  */
1949
2470
  declare function ɵisCopilotKitFeature(name: string): name is ɵCopilotKitFeature;
1950
2471
  //#endregion
1951
- export { ActionConfig, ActionCreator, ActionFromCreator, ActionFromCreators, ActionGroupConfig, ActionGroupResult, AgentRegistry, AgentThreadLockedError, AnyAction, ContextStore, CopilotKitCore, type CopilotKitCoreAddAgentParams, CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams, CopilotKitCoreErrorCode, CopilotKitCoreFriendsAccess, CopilotKitCoreGetSuggestionsResult, type CopilotKitCoreGetToolParams, type CopilotKitCoreRegisterProxiedAgentParams, type CopilotKitCoreRegisterProxiedAgentResult, type CopilotKitCoreRunAgentParams, type CopilotKitCoreRunToolParams, type CopilotKitCoreRunToolResult, CopilotKitCoreRuntimeConnectionStatus, CopilotKitCoreStopAgentParams, CopilotKitCoreSubscriber, CopilotKitCoreSubscription, CopilotRuntimeTransport, DispatchingEffect, DispatchingEffectOptions, DynamicSuggestionsConfig, Effect, EmptyActionConfig, FrontendTool, FrontendToolHandlerContext, IntelligenceAgent, IntelligenceAgentConfig, type IntelligenceRuntimeInfo, NonDispatchingEffect, NonDispatchingEffectOptions, PropsActionConfig, ProxiedCopilotRuntimeAgent, ProxiedCopilotRuntimeAgentConfig, Reducer, RunCompletionAware, RunHandler, type RuntimeLicenseStatus, type RuntimeMode, ScopedContext, Selector, StateManager, StaticSuggestionsConfig, Store, StoreLifecycleAction, SubscribeToAgentOptions, SubscribeToAgentSubscriber, Suggestion, SuggestionAvailability, SuggestionEngine, SuggestionsConfig, type ThreadEndpointRuntimeInfo, ToolCallStatus, completePartialMarkdown, createActionGroup, createEffect, createReducer, createSelector, createStore, empty, ensureObjectArgs, isRunCompletionAware, ofType, on, parseToolArguments, props, select, ɵCOPILOTKIT_FEATURES, ɵCopilotKitFeature, ɵMAX_SOCKET_RETRIES, ɵPhoenixChannelLike, ɵPhoenixChannelOptions, ɵPhoenixChannelSession, ɵPhoenixJoinOutcome, ɵPhoenixPushLike, ɵPhoenixSocketLike, ɵPhoenixSocketOptions, ɵPhoenixSocketSession, ɵPhoenixSocketSignal, ɵThread, ɵThreadEnvironment, ɵThreadMetadataEvent, ɵThreadRuntimeContext, ɵThreadSelectors, ɵThreadStore, ɵcreateThreadSelectors, createThreadStore as ɵcreateThreadStore, ɵisCopilotKitFeature, ɵjoinPhoenixChannel$, ɵobservePhoenixEvent$, ɵobservePhoenixJoinOutcome$, ɵobservePhoenixSocketHealth$, ɵobservePhoenixSocketSignals$, ɵphoenixChannel$, ɵphoenixSocket$, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectIsMutating, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading, ɵthreadAdapterEvents };
2472
+ export { ActionConfig, ActionCreator, ActionFromCreator, ActionFromCreators, ActionGroupConfig, ActionGroupResult, AgentRegistry, AgentThreadLockedError, AnyAction, ContextStore, CopilotKitCore, type CopilotKitCoreAddAgentParams, CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams, CopilotKitCoreErrorCode, CopilotKitCoreFriendsAccess, CopilotKitCoreGetSuggestionsResult, type CopilotKitCoreGetToolParams, type CopilotKitCoreRegisterProxiedAgentParams, type CopilotKitCoreRegisterProxiedAgentResult, type CopilotKitCoreRunAgentParams, type CopilotKitCoreRunToolParams, type CopilotKitCoreRunToolResult, CopilotKitCoreRuntimeConnectionStatus, CopilotKitCoreStopAgentParams, CopilotKitCoreSubscriber, CopilotKitCoreSubscription, CopilotRuntimeTransport, DispatchingEffect, DispatchingEffectOptions, DynamicSuggestionsConfig, Effect, EmptyActionConfig, FrontendTool, FrontendToolHandlerContext, IntelligenceAgent, IntelligenceAgentConfig, type IntelligenceRuntimeInfo, MEMORY_ERROR_REGISTRY, Memory, MemoryChanges, MemoryError, type MemoryErrorCategory, type MemoryErrorCode, type MemoryErrorRegistryEntry, MemoryKind, MemoryRealtimeStatus, MemoryScope, NewMemory, NonDispatchingEffect, NonDispatchingEffectOptions, PropsActionConfig, ProxiedCopilotRuntimeAgent, ProxiedCopilotRuntimeAgentConfig, Reducer, RunCompletionAware, RunHandler, type RuntimeLicenseStatus, type RuntimeMode, ScopedContext, Selector, StateManager, StaticSuggestionsConfig, Store, StoreLifecycleAction, SubagentRegistry, SubagentState, SubagentStatus, SubscribeToAgentOptions, SubscribeToAgentSubscriber, Suggestion, SuggestionAvailability, SuggestionEngine, SuggestionsConfig, type ThreadEndpointRuntimeInfo, ThreadRunActivityNotification, ToolCallStatus, completePartialMarkdown, createActionGroup, createEffect, createReducer, createSelector, createStore, empty, ensureObjectArgs, isRunCompletionAware, ofType, on, parseToolArguments, props, select, ɵCOPILOTKIT_FEATURES, ɵCopilotKitFeature, ɵMAX_SOCKET_RETRIES, ɵMemoryEnvironment, ɵMemoryMetadataEvent, ɵMemoryRuntimeContext, ɵMemoryState, ɵMemoryStore, ɵPhoenixChannelLike, ɵPhoenixChannelOptions, ɵPhoenixChannelSession, ɵPhoenixJoinOutcome, ɵPhoenixPushLike, ɵPhoenixSocketLike, ɵPhoenixSocketOptions, ɵPhoenixSocketSession, ɵPhoenixSocketSignal, ɵThread, ɵThreadEnvironment, ɵThreadMetadataEvent, ɵThreadRuntimeContext, ɵThreadSelectors, ɵThreadStore, 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 };
1952
2473
  //# sourceMappingURL=index.d.mts.map