@copilotkit/core 1.56.5 → 1.57.0-canary.1778082736

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.cts CHANGED
@@ -93,11 +93,91 @@ type StaticSuggestionsConfig = {
93
93
  };
94
94
  type SuggestionsConfig = DynamicSuggestionsConfig | StaticSuggestionsConfig;
95
95
  //#endregion
96
+ //#region src/agent.d.ts
97
+ type ResolvedRuntimeMode = RuntimeMode$1 | "pending";
98
+ interface ProxiedCopilotRuntimeAgentConfig extends Omit<HttpAgentConfig, "url"> {
99
+ runtimeUrl?: string;
100
+ transport?: CopilotRuntimeTransport;
101
+ credentials?: RequestCredentials;
102
+ runtimeMode?: ResolvedRuntimeMode;
103
+ intelligence?: IntelligenceRuntimeInfo$1;
104
+ capabilities?: AgentCapabilities;
105
+ debug?: ResolvedDebugConfig;
106
+ /**
107
+ * When set, runtime requests (HTTP path, single-route envelope, intelligence
108
+ * delegate) are routed to this agent on the runtime instead of `agentId`.
109
+ * The local `agentId` remains the registry key used for subscriber
110
+ * bookkeeping; only outbound routing is overridden.
111
+ */
112
+ runtimeAgentId?: string;
113
+ }
114
+ declare class ProxiedCopilotRuntimeAgent extends HttpAgent {
115
+ #private;
116
+ runtimeUrl?: string;
117
+ credentials?: RequestCredentials;
118
+ readonly runtimeAgentId?: string;
119
+ private transport;
120
+ private singleEndpointUrl?;
121
+ private runtimeMode;
122
+ private intelligence?;
123
+ private _capabilities?;
124
+ private delegate?;
125
+ private runtimeInfoPromise?;
126
+ constructor(config: ProxiedCopilotRuntimeAgentConfig);
127
+ /**
128
+ * The agent id used for outbound runtime requests — `runtimeAgentId` when
129
+ * set (manually-registered proxy), otherwise `agentId` (registry id
130
+ * matches runtime id). Subscriber bookkeeping keeps using `agentId`
131
+ * directly.
132
+ *
133
+ * Throws when both are unset: a proxy reaching an HTTP path with no
134
+ * routable id is a bug, and a missing id would otherwise produce a
135
+ * malformed `/agent//run` or `/agent/undefined/connect` URL silently.
136
+ */
137
+ private routedAgentId;
138
+ get capabilities(): AgentCapabilities | undefined;
139
+ getCapabilities(): Promise<AgentCapabilities>;
140
+ detachActiveRun(): Promise<void>;
141
+ abortRun(): void;
142
+ connectAgent(parameters?: RunAgentParameters, subscriber?: AgentSubscriber): Promise<RunAgentResult>;
143
+ connect(input: RunAgentInput): Observable<BaseEvent>;
144
+ run(input: RunAgentInput): Observable<BaseEvent>;
145
+ clone(): ProxiedCopilotRuntimeAgent;
146
+ private resolveDelegate;
147
+ private ensureRuntimeMode;
148
+ private fetchRuntimeInfo;
149
+ private fetchRuntimeInfoAutoDetect;
150
+ private createSingleRouteRequestInit;
151
+ private createIntelligenceDelegate;
152
+ private syncDelegate;
153
+ }
154
+ //#endregion
96
155
  //#region src/core/agent-registry.d.ts
97
156
  interface CopilotKitCoreAddAgentParams {
98
157
  id: string;
99
158
  agent: AbstractAgent;
100
159
  }
160
+ /**
161
+ * Parameters for registering a proxied agent against an existing runtime agent.
162
+ */
163
+ interface CopilotKitCoreRegisterProxiedAgentParams {
164
+ /**
165
+ * The local registry id under which the proxy is registered. Used by
166
+ * `useAgent`, state-manager subscriptions, and all subscriber bookkeeping.
167
+ * Must not collide with any existing local or runtime-discovered agent id.
168
+ */
169
+ agentId: string;
170
+ /**
171
+ * The id of the runtime agent that this proxy routes outbound HTTP requests
172
+ * to. Invisible to subscribers — only affects URL paths and single-route
173
+ * envelopes.
174
+ */
175
+ runtimeAgentId: string;
176
+ }
177
+ interface CopilotKitCoreRegisterProxiedAgentResult {
178
+ agent: ProxiedCopilotRuntimeAgent;
179
+ unregister: () => void;
180
+ }
101
181
  /**
102
182
  * Manages agent registration, lifecycle, and runtime connectivity for CopilotKitCore.
103
183
  * Handles both local development agents and remote runtime agents.
@@ -156,6 +236,21 @@ declare class AgentRegistry {
156
236
  * Remove an agent by ID (for development use)
157
237
  */
158
238
  removeAgent__unsafe_dev_only(id: string): void;
239
+ /**
240
+ * Register a proxied agent that routes outbound runtime requests to an
241
+ * existing runtime agent (`runtimeAgentId`) while exposing a distinct local
242
+ * registry id (`agentId`). Throws if `agentId` is already taken by either a
243
+ * local or runtime-discovered agent.
244
+ *
245
+ * Use this to mount multiple frontend agents against a single runtime
246
+ * agent (e.g. a chat-1 / chat-2 pair both proxying to "default") without
247
+ * implicit per-thread cloning. The returned `unregister` removes the proxy
248
+ * from the registry and emits `onAgentsChanged`.
249
+ */
250
+ registerProxiedAgent({
251
+ agentId,
252
+ runtimeAgentId
253
+ }: CopilotKitCoreRegisterProxiedAgentParams): CopilotKitCoreRegisterProxiedAgentResult;
159
254
  /**
160
255
  * Get an agent by ID
161
256
  */
@@ -375,148 +470,451 @@ declare function ensureObjectArgs(parsed: unknown, toolName: string): Record<str
375
470
  */
376
471
  declare function parseToolArguments(rawArgs: unknown, toolName: string): Record<string, unknown>;
377
472
  //#endregion
378
- //#region src/core/core.d.ts
379
- /** Configuration options for `CopilotKitCore`. */
380
- interface CopilotKitCoreConfig {
381
- /** The endpoint of the CopilotRuntime. */
382
- runtimeUrl?: string;
383
- /** Transport style for CopilotRuntime endpoints. Defaults to REST. */
384
- runtimeTransport?: CopilotRuntimeTransport;
385
- /** Mapping from agent name to its `AbstractAgent` instance. For development only - production requires CopilotRuntime. */
386
- agents__unsafe_dev_only?: Record<string, AbstractAgent>;
387
- /** Headers appended to every HTTP request made by `CopilotKitCore`. */
388
- headers?: Record<string, string>;
389
- /** Credentials mode for fetch requests (e.g., "include" for HTTP-only cookies). */
390
- credentials?: RequestCredentials;
391
- /** Properties sent as `forwardedProps` to the AG-UI agent. */
392
- properties?: Record<string, unknown>;
393
- /** Ordered collection of frontend tools available to the core. */
394
- tools?: FrontendTool<any>[];
395
- /** Suggestions config for the core. */
396
- suggestionsConfig?: SuggestionsConfig[];
397
- /** Enable debug logging for the client-side event pipeline. */
398
- debug?: DebugConfig;
399
- }
400
- interface CopilotKitCoreStopAgentParams {
401
- agent: AbstractAgent;
473
+ //#region src/utils/micro-redux.d.ts
474
+ /**
475
+ * The minimal action shape used by this micro-redux implementation.
476
+ */
477
+ interface AnyAction {
478
+ type: string;
402
479
  }
403
- type CopilotKitCoreGetSuggestionsResult = {
404
- suggestions: Suggestion[];
405
- isLoading: boolean;
480
+ /**
481
+ * A typed action creator function with a `type` literal and runtime matcher.
482
+ */
483
+ type ActionCreator<Type extends string, Args extends unknown[] = unknown[], Action extends AnyAction & {
484
+ type: Type;
485
+ } = {
486
+ type: Type;
487
+ }> = ((...args: Args) => Action) & {
488
+ type: Type;
489
+ match(action: AnyAction): action is Action;
406
490
  };
407
- declare enum CopilotKitCoreErrorCode {
408
- RUNTIME_INFO_FETCH_FAILED = "runtime_info_fetch_failed",
409
- AGENT_CONNECT_FAILED = "agent_connect_failed",
410
- AGENT_RUN_FAILED = "agent_run_failed",
411
- AGENT_RUN_FAILED_EVENT = "agent_run_failed_event",
412
- AGENT_RUN_ERROR_EVENT = "agent_run_error_event",
413
- TOOL_ARGUMENT_PARSE_FAILED = "tool_argument_parse_failed",
414
- TOOL_HANDLER_FAILED = "tool_handler_failed",
415
- TOOL_NOT_FOUND = "tool_not_found",
416
- AGENT_NOT_FOUND = "agent_not_found",
417
- /**
418
- * Emitted when an agent run fails because the thread is already locked
419
- * by another active run.
420
- *
421
- * @example
422
- * ```tsx
423
- * <CopilotKitProvider
424
- * onError={({ code, error, context }) => {
425
- * if (code === "agent_thread_locked") {
426
- * // Show "Agent is busy, retry?" UI
427
- * }
428
- * }}
429
- * />
430
- * ```
431
- */
432
- AGENT_THREAD_LOCKED = "agent_thread_locked",
433
- TRANSCRIPTION_FAILED = "transcription_failed",
434
- TRANSCRIPTION_SERVICE_NOT_CONFIGURED = "transcription_service_not_configured",
435
- TRANSCRIPTION_INVALID_AUDIO = "transcription_invalid_audio",
436
- TRANSCRIPTION_RATE_LIMITED = "transcription_rate_limited",
437
- TRANSCRIPTION_AUTH_FAILED = "transcription_auth_failed",
438
- TRANSCRIPTION_NETWORK_ERROR = "transcription_network_error",
439
- SUBSCRIBER_CALLBACK_FAILED = "subscriber_callback_failed"
491
+ /**
492
+ * Extracts the action type produced by an action creator.
493
+ */
494
+ type ActionFromCreator<T> = T extends ((...args: any[]) => infer A) ? A : never;
495
+ /**
496
+ * Extracts a union of actions produced by a tuple/array of action creators.
497
+ */
498
+ type ActionFromCreators<Creators extends readonly ActionCreator<string, any[], any>[]> = ActionFromCreator<Creators[number]>;
499
+ /**
500
+ * A reducer transforms state in response to actions.
501
+ */
502
+ type Reducer<State, Action extends AnyAction = AnyAction> = (state: State | undefined, action: Action) => State;
503
+ /**
504
+ * A selector derives a value from state.
505
+ */
506
+ type Selector<State, Result> = (state: State) => Result;
507
+ /**
508
+ * Marker config for action creators that accept no payload.
509
+ */
510
+ interface EmptyActionConfig {
511
+ readonly kind: "empty";
440
512
  }
441
- interface CopilotKitCoreSubscriber {
442
- onRuntimeConnectionStatusChanged?: (event: {
443
- copilotkit: CopilotKitCore;
444
- status: CopilotKitCoreRuntimeConnectionStatus;
445
- }) => void | Promise<void>;
446
- onToolExecutionStart?: (event: {
447
- copilotkit: CopilotKitCore;
448
- toolCallId: string;
449
- agentId: string;
450
- toolName: string;
451
- args: unknown;
452
- }) => void | Promise<void>;
453
- onToolExecutionEnd?: (event: {
454
- copilotkit: CopilotKitCore;
455
- toolCallId: string;
456
- agentId: string;
457
- toolName: string;
458
- result: string;
459
- error?: string;
460
- }) => void | Promise<void>;
461
- onAgentsChanged?: (event: {
462
- copilotkit: CopilotKitCore;
463
- agents: Readonly<Record<string, AbstractAgent>>;
464
- }) => void | Promise<void>;
465
- onContextChanged?: (event: {
466
- copilotkit: CopilotKitCore;
467
- context: Readonly<Record<string, Context>>;
468
- }) => void | Promise<void>;
469
- onSuggestionsConfigChanged?: (event: {
470
- copilotkit: CopilotKitCore;
471
- suggestionsConfig: Readonly<Record<string, SuggestionsConfig>>;
472
- }) => void | Promise<void>;
473
- onSuggestionsChanged?: (event: {
474
- copilotkit: CopilotKitCore;
475
- agentId: string;
476
- suggestions: Suggestion[];
477
- }) => void | Promise<void>;
478
- onSuggestionsStartedLoading?: (event: {
479
- copilotkit: CopilotKitCore;
480
- agentId: string;
481
- }) => void | Promise<void>;
482
- onSuggestionsFinishedLoading?: (event: {
483
- copilotkit: CopilotKitCore;
484
- agentId: string;
485
- }) => void | Promise<void>;
486
- onPropertiesChanged?: (event: {
487
- copilotkit: CopilotKitCore;
488
- properties: Readonly<Record<string, unknown>>;
489
- }) => void | Promise<void>;
490
- onHeadersChanged?: (event: {
491
- copilotkit: CopilotKitCore;
492
- headers: Readonly<Record<string, string>>;
493
- }) => void | Promise<void>;
494
- onError?: (event: {
495
- copilotkit: CopilotKitCore;
496
- error: Error;
497
- code: CopilotKitCoreErrorCode;
498
- context: Record<string, any>;
499
- }) => void | Promise<void>;
500
- /**
501
- * Fired when an agent run or connect begins. The `agent` may be a per-thread
502
- * clone that is not present in `core.agents`. Subscribers (e.g. the inspector)
503
- * can use this to subscribe to the clone's AG-UI events.
504
- */
505
- onAgentRunStarted?: (event: {
506
- copilotkit: CopilotKitCore;
507
- agent: AbstractAgent;
508
- }) => void | Promise<void>;
513
+ declare const PROPS_MARKER: unique symbol;
514
+ /**
515
+ * Marker config for action creators that require payload props.
516
+ */
517
+ interface PropsActionConfig<Props extends Record<string, unknown>> {
518
+ readonly kind: "props";
519
+ readonly [PROPS_MARKER]?: Props;
509
520
  }
510
- interface CopilotKitCoreSubscription {
511
- unsubscribe: () => void;
521
+ /**
522
+ * Supported action creator config node in an action group.
523
+ */
524
+ type ActionConfig = EmptyActionConfig | PropsActionConfig<Record<string, unknown>>;
525
+ /**
526
+ * Shape of an action group declaration object.
527
+ */
528
+ type ActionGroupConfig = Record<string, ActionConfig>;
529
+ /**
530
+ * Maps an action group declaration to a strongly typed action-creator object.
531
+ */
532
+ type ActionGroupResult<Source extends string, Config extends ActionGroupConfig> = { [K in keyof Config & string]: Config[K] extends PropsActionConfig<infer P> ? ActionCreator<`[${Source}] ${K}`, [P], {
533
+ type: `[${Source}] ${K}`;
534
+ } & P> : ActionCreator<`[${Source}] ${K}`, [], {
535
+ type: `[${Source}] ${K}`;
536
+ }> };
537
+ interface OnReducerEntry<State, Action extends AnyAction = AnyAction, Creators extends readonly ActionCreator<string, any[], any>[] = readonly ActionCreator<string, any[], any>[]> {
538
+ creators: Creators;
539
+ reducer: (state: State, action: Action) => State;
512
540
  }
541
+ type ActionFromOnReducerEntry<TEntry> = TEntry extends OnReducerEntry<any, infer TAction, any> ? TAction : never;
513
542
  /**
514
- * The callback keys accepted by {@link CopilotKitCore.subscribeToAgentWithOptions}.
515
- * This tuple is the single source of truth — both the
516
- * `SubscribeToAgentSubscriber` type and the runtime `ALLOWED_KEYS` set
517
- * are derived from it, so they cannot desynchronise.
543
+ * Effect contract for streams that emit actions to dispatch.
518
544
  */
519
- declare const SUBSCRIBE_TO_AGENT_KEYS: readonly ["onMessagesChanged", "onStateChanged", "onRunInitialized", "onRunFinalized", "onRunFailed", "onRunErrorEvent"];
545
+ interface DispatchingEffect<State, InputAction extends AnyAction = AnyAction, OutputAction extends AnyAction = AnyAction> {
546
+ run: (actions$: Observable<InputAction>, state$: Observable<State>) => Observable<OutputAction>;
547
+ dispatch: true;
548
+ }
549
+ /**
550
+ * Effect contract for side-effect-only streams whose emissions are ignored.
551
+ */
552
+ interface NonDispatchingEffect<State, InputAction extends AnyAction = AnyAction> {
553
+ run: (actions$: Observable<InputAction>, state$: Observable<State>) => Observable<unknown>;
554
+ dispatch: false;
555
+ }
556
+ /**
557
+ * Union of supported effect shapes.
558
+ */
559
+ type Effect<State, InputAction extends AnyAction = AnyAction, OutputAction extends AnyAction = AnyAction> = DispatchingEffect<State, InputAction, OutputAction> | NonDispatchingEffect<State, InputAction>;
560
+ /**
561
+ * Lifecycle actions dispatched by the store.
562
+ */
563
+ type StoreLifecycleAction = {
564
+ type: "@@micro-redux/init";
565
+ } | {
566
+ type: "@@micro-redux/stop";
567
+ };
568
+ /**
569
+ * Options for a dispatching effect.
570
+ */
571
+ interface DispatchingEffectOptions {
572
+ dispatch?: true;
573
+ }
574
+ /**
575
+ * Options for a non-dispatching effect.
576
+ */
577
+ interface NonDispatchingEffectOptions {
578
+ dispatch: false;
579
+ }
580
+ /**
581
+ * Declares a payload-based action config for `createActionGroup`.
582
+ *
583
+ * @example
584
+ * ```ts
585
+ * const actions = createActionGroup("User", {
586
+ * loaded: props<{ id: string }>(),
587
+ * });
588
+ * ```
589
+ */
590
+ declare function props<Props extends Record<string, unknown>>(): PropsActionConfig<Props>;
591
+ /**
592
+ * Declares a no-payload action config for `createActionGroup`.
593
+ *
594
+ * @example
595
+ * ```ts
596
+ * const actions = createActionGroup("User", {
597
+ * reset: empty(),
598
+ * });
599
+ * ```
600
+ */
601
+ declare function empty(): EmptyActionConfig;
602
+ /**
603
+ * Creates a namespaced group of typed action creators.
604
+ *
605
+ * Action types are formatted as: `[Source] actionName`.
606
+ */
607
+ declare function createActionGroup<const Source extends string, const Config extends ActionGroupConfig>(source: Source, config: Config): ActionGroupResult<Source, Config>;
608
+ /**
609
+ * Registers one reducer handler for one or more action creators.
610
+ *
611
+ * @throws Error when called without at least one action creator and reducer.
612
+ */
613
+ declare function on<State, const Creators extends readonly ActionCreator<string, any[], any>[], Action extends ActionFromCreators<Creators>>(...args: [...creators: Creators, reducer: (state: State, action: Action) => State]): OnReducerEntry<State, Action, Creators>;
614
+ /**
615
+ * Creates a reducer from an initial state and `on(...)` handler entries.
616
+ *
617
+ * Unknown action types return the current state unchanged.
618
+ */
619
+ declare function createReducer<State, const Entries extends readonly OnReducerEntry<any, any, any>[]>(initialState: State, ...entries: Entries): Reducer<State, ActionFromOnReducerEntry<Entries[number]>>;
620
+ /**
621
+ * Creates a memoized selector from a single projector.
622
+ */
623
+ declare function createSelector<State, Result>(projector: (state: State) => Result): Selector<State, Result>;
624
+ /**
625
+ * Creates a memoized selector from input selectors and a projector.
626
+ *
627
+ * Memoization uses one-entry caching over the latest input selector values.
628
+ */
629
+ declare function createSelector<State, const Selectors extends readonly Selector<State, unknown>[], Result>(...args: [...selectors: Selectors, projector: (...inputs: { [K in keyof Selectors]: ReturnType<Selectors[K]> }) => Result]): Selector<State, Result>;
630
+ /**
631
+ * RxJS operator that maps state emissions through a selector and suppresses
632
+ * unchanged projected values via reference equality.
633
+ */
634
+ declare function select<State, Result>(selector: Selector<State, Result>): OperatorFunction<State, Result>;
635
+ /**
636
+ * RxJS operator that filters an action stream by action creators and narrows
637
+ * the output action type to the matched creator union.
638
+ *
639
+ * @throws Error when called without at least one action creator.
640
+ */
641
+ declare function ofType<const Creators extends readonly ActionCreator<string, any[], AnyAction>[]>(...creators: Creators): OperatorFunction<AnyAction, ActionFromCreators<Creators>>;
642
+ /**
643
+ * Creates a dispatching effect. Emitted actions are automatically dispatched.
644
+ */
645
+ declare function createEffect<State, InputAction extends AnyAction, OutputAction extends AnyAction>(factory: (actions$: Observable<InputAction>, state$: Observable<State>) => Observable<OutputAction>, options?: DispatchingEffectOptions): DispatchingEffect<State, InputAction, OutputAction>;
646
+ /**
647
+ * Creates a non-dispatching effect. Emitted values are ignored.
648
+ */
649
+ declare function createEffect<State, InputAction extends AnyAction>(factory: (actions$: Observable<InputAction>, state$: Observable<State>) => Observable<unknown>, options: NonDispatchingEffectOptions): NonDispatchingEffect<State, InputAction>;
650
+ /**
651
+ * Store interface returned by `createStore`.
652
+ */
653
+ interface Store<State, Action extends AnyAction = AnyAction> {
654
+ dispatch(action: Action): void;
655
+ getState(): State;
656
+ readonly state$: Observable<State>;
657
+ readonly actions$: Observable<Action | StoreLifecycleAction>;
658
+ select<Result>(selector: Selector<State, Result>): Observable<Result>;
659
+ init(): void;
660
+ stop(): void;
661
+ }
662
+ /**
663
+ * Creates a small observable store with reducer + effects.
664
+ *
665
+ * Behavior:
666
+ * - `init()` starts effects and dispatches `@@micro-redux/init`.
667
+ * - `stop()` dispatches `@@micro-redux/stop` and unsubscribes all effects.
668
+ * - Effect action observation is scheduled on `asapScheduler` to avoid
669
+ * synchronous re-entrancy in the effect loop.
670
+ * - Any effect error triggers fail-fast teardown and errors both `actions$`
671
+ * and `state$`.
672
+ */
673
+ declare function createStore<State, Action extends AnyAction = AnyAction>(options: {
674
+ reducer: Reducer<State, Action | StoreLifecycleAction>;
675
+ effects?: Array<Effect<State, Action | StoreLifecycleAction, Action>>;
676
+ }): Store<State, Action>;
677
+ //#endregion
678
+ //#region src/threads.d.ts
679
+ interface ThreadRecord {
680
+ id: string;
681
+ organizationId: string;
682
+ agentId: string;
683
+ createdById: string;
684
+ name: string | null;
685
+ archived: boolean;
686
+ createdAt: string;
687
+ updatedAt: string;
688
+ lastRunAt?: string;
689
+ }
690
+ interface ThreadRuntimeContext {
691
+ runtimeUrl: string;
692
+ headers: Record<string, string>;
693
+ wsUrl?: string;
694
+ agentId: string;
695
+ includeArchived?: boolean;
696
+ limit?: number;
697
+ }
698
+ type ThreadMetadataEvent = {
699
+ operation: "created" | "renamed" | "archived" | "unarchived" | "updated";
700
+ threadId: string;
701
+ userId: string;
702
+ organizationId: string;
703
+ occurredAt: string;
704
+ thread: ThreadRecord;
705
+ } | {
706
+ operation: "deleted";
707
+ threadId: string;
708
+ userId: string;
709
+ organizationId: string;
710
+ occurredAt: string;
711
+ deleted: {
712
+ id: string;
713
+ };
714
+ };
715
+ interface ThreadEnvironment {
716
+ fetch: typeof fetch;
717
+ }
718
+ interface ThreadState {
719
+ threads: ThreadRecord[];
720
+ isLoading: boolean;
721
+ isFetchingNextPage: boolean;
722
+ error: Error | null;
723
+ context: ThreadRuntimeContext | null;
724
+ sessionId: number;
725
+ metadataCredentialsRequested: boolean;
726
+ metadataJoinCode: string | null;
727
+ nextCursor: string | null;
728
+ }
729
+ interface ThreadStore {
730
+ start(): void;
731
+ stop(): void;
732
+ setContext(context: ThreadRuntimeContext | null): void;
733
+ /** Re-fetches the thread list without resetting the current list to empty. */
734
+ refresh(): void;
735
+ fetchNextPage(): void;
736
+ renameThread(threadId: string, name: string): Promise<void>;
737
+ archiveThread(threadId: string): Promise<void>;
738
+ deleteThread(threadId: string): Promise<void>;
739
+ getState(): ThreadState;
740
+ select: Store<ThreadState>["select"];
741
+ }
742
+ declare function createThreadStore(environment: ThreadEnvironment): ThreadStore;
743
+ type ɵThread = ThreadRecord;
744
+ type ɵThreadRuntimeContext = ThreadRuntimeContext;
745
+ type ɵThreadMetadataEvent = ThreadMetadataEvent;
746
+ type ɵThreadEnvironment = ThreadEnvironment;
747
+ type ɵThreadStore = ThreadStore;
748
+ declare const ɵthreadAdapterEvents: any;
749
+ declare const ɵselectThreads: any;
750
+ declare const ɵselectThreadsIsLoading: any;
751
+ declare const ɵselectThreadsError: any;
752
+ declare const ɵselectHasNextPage: any;
753
+ declare const ɵselectIsFetchingNextPage: any;
754
+ /**
755
+ * Number of consecutive WebSocket connection failures after which the
756
+ * threads channel tears itself down rather than retrying indefinitely.
757
+ * Exposed for tests so they can assert teardown semantics without
758
+ * hardcoding the threshold separately from production.
759
+ */
760
+ declare const ɵMAX_SOCKET_RETRIES = 5;
761
+ //#endregion
762
+ //#region src/core/core.d.ts
763
+ /** Configuration options for `CopilotKitCore`. */
764
+ interface CopilotKitCoreConfig {
765
+ /** The endpoint of the CopilotRuntime. */
766
+ runtimeUrl?: string;
767
+ /** Transport style for CopilotRuntime endpoints. Defaults to REST. */
768
+ runtimeTransport?: CopilotRuntimeTransport;
769
+ /** Mapping from agent name to its `AbstractAgent` instance. For development only - production requires CopilotRuntime. */
770
+ agents__unsafe_dev_only?: Record<string, AbstractAgent>;
771
+ /** Headers appended to every HTTP request made by `CopilotKitCore`. */
772
+ headers?: Record<string, string>;
773
+ /** Credentials mode for fetch requests (e.g., "include" for HTTP-only cookies). */
774
+ credentials?: RequestCredentials;
775
+ /** Properties sent as `forwardedProps` to the AG-UI agent. */
776
+ properties?: Record<string, unknown>;
777
+ /** Ordered collection of frontend tools available to the core. */
778
+ tools?: FrontendTool<any>[];
779
+ /** Suggestions config for the core. */
780
+ suggestionsConfig?: SuggestionsConfig[];
781
+ /** Enable debug logging for the client-side event pipeline. */
782
+ debug?: DebugConfig;
783
+ }
784
+ interface CopilotKitCoreStopAgentParams {
785
+ agent: AbstractAgent;
786
+ }
787
+ type CopilotKitCoreGetSuggestionsResult = {
788
+ suggestions: Suggestion[];
789
+ isLoading: boolean;
790
+ };
791
+ declare enum CopilotKitCoreErrorCode {
792
+ RUNTIME_INFO_FETCH_FAILED = "runtime_info_fetch_failed",
793
+ AGENT_CONNECT_FAILED = "agent_connect_failed",
794
+ AGENT_RUN_FAILED = "agent_run_failed",
795
+ AGENT_RUN_FAILED_EVENT = "agent_run_failed_event",
796
+ AGENT_RUN_ERROR_EVENT = "agent_run_error_event",
797
+ TOOL_ARGUMENT_PARSE_FAILED = "tool_argument_parse_failed",
798
+ TOOL_HANDLER_FAILED = "tool_handler_failed",
799
+ TOOL_NOT_FOUND = "tool_not_found",
800
+ AGENT_NOT_FOUND = "agent_not_found",
801
+ /**
802
+ * Emitted when an agent run fails because the thread is already locked
803
+ * by another active run.
804
+ *
805
+ * @example
806
+ * ```tsx
807
+ * <CopilotKitProvider
808
+ * onError={({ code, error, context }) => {
809
+ * if (code === "agent_thread_locked") {
810
+ * // Show "Agent is busy, retry?" UI
811
+ * }
812
+ * }}
813
+ * />
814
+ * ```
815
+ */
816
+ AGENT_THREAD_LOCKED = "agent_thread_locked",
817
+ TRANSCRIPTION_FAILED = "transcription_failed",
818
+ TRANSCRIPTION_SERVICE_NOT_CONFIGURED = "transcription_service_not_configured",
819
+ TRANSCRIPTION_INVALID_AUDIO = "transcription_invalid_audio",
820
+ TRANSCRIPTION_RATE_LIMITED = "transcription_rate_limited",
821
+ TRANSCRIPTION_AUTH_FAILED = "transcription_auth_failed",
822
+ TRANSCRIPTION_NETWORK_ERROR = "transcription_network_error",
823
+ SUBSCRIBER_CALLBACK_FAILED = "subscriber_callback_failed"
824
+ }
825
+ interface CopilotKitCoreSubscriber {
826
+ onRuntimeConnectionStatusChanged?: (event: {
827
+ copilotkit: CopilotKitCore;
828
+ status: CopilotKitCoreRuntimeConnectionStatus;
829
+ }) => void | Promise<void>;
830
+ onToolExecutionStart?: (event: {
831
+ copilotkit: CopilotKitCore;
832
+ toolCallId: string;
833
+ agentId: string;
834
+ toolName: string;
835
+ args: unknown;
836
+ }) => void | Promise<void>;
837
+ onToolExecutionEnd?: (event: {
838
+ copilotkit: CopilotKitCore;
839
+ toolCallId: string;
840
+ agentId: string;
841
+ toolName: string;
842
+ result: string;
843
+ error?: string;
844
+ }) => void | Promise<void>;
845
+ onAgentsChanged?: (event: {
846
+ copilotkit: CopilotKitCore;
847
+ agents: Readonly<Record<string, AbstractAgent>>;
848
+ }) => void | Promise<void>;
849
+ onContextChanged?: (event: {
850
+ copilotkit: CopilotKitCore;
851
+ context: Readonly<Record<string, Context>>;
852
+ }) => void | Promise<void>;
853
+ onSuggestionsConfigChanged?: (event: {
854
+ copilotkit: CopilotKitCore;
855
+ suggestionsConfig: Readonly<Record<string, SuggestionsConfig>>;
856
+ }) => void | Promise<void>;
857
+ onSuggestionsChanged?: (event: {
858
+ copilotkit: CopilotKitCore;
859
+ agentId: string;
860
+ suggestions: Suggestion[];
861
+ }) => void | Promise<void>;
862
+ onSuggestionsStartedLoading?: (event: {
863
+ copilotkit: CopilotKitCore;
864
+ agentId: string;
865
+ }) => void | Promise<void>;
866
+ onSuggestionsFinishedLoading?: (event: {
867
+ copilotkit: CopilotKitCore;
868
+ agentId: string;
869
+ }) => void | Promise<void>;
870
+ onPropertiesChanged?: (event: {
871
+ copilotkit: CopilotKitCore;
872
+ properties: Readonly<Record<string, unknown>>;
873
+ }) => void | Promise<void>;
874
+ onHeadersChanged?: (event: {
875
+ copilotkit: CopilotKitCore;
876
+ headers: Readonly<Record<string, string>>;
877
+ }) => void | Promise<void>;
878
+ onError?: (event: {
879
+ copilotkit: CopilotKitCore;
880
+ error: Error;
881
+ code: CopilotKitCoreErrorCode;
882
+ context: Record<string, any>;
883
+ }) => void | Promise<void>;
884
+ onThreadStoreRegistered?: (event: {
885
+ copilotkit: CopilotKitCore;
886
+ agentId: string;
887
+ store: ɵThreadStore;
888
+ }) => void | Promise<void>;
889
+ /**
890
+ * Fired when a thread store is removed from the registry, either by an
891
+ * explicit `unregister()` call or by a `register()` call that replaces an
892
+ * existing store for the same `agentId`.
893
+ *
894
+ * The previous store is delivered via `prevStore` so subscribers can tear
895
+ * down state that depends on the concrete instance (e.g. cancel an active
896
+ * subscription) without consulting the registry. By the time async
897
+ * subscribers resume after an `await`, a replacement `register()` may have
898
+ * already installed the new store under the same key, so calling
899
+ * `registry.get(agentId)` inside this callback is unsafe and may return
900
+ * the new store instead of the unregistered one.
901
+ */
902
+ onThreadStoreUnregistered?: (event: {
903
+ copilotkit: CopilotKitCore;
904
+ agentId: string;
905
+ prevStore: ɵThreadStore;
906
+ }) => void | Promise<void>;
907
+ }
908
+ interface CopilotKitCoreSubscription {
909
+ unsubscribe: () => void;
910
+ }
911
+ /**
912
+ * The callback keys accepted by {@link CopilotKitCore.subscribeToAgentWithOptions}.
913
+ * This tuple is the single source of truth — both the
914
+ * `SubscribeToAgentSubscriber` type and the runtime `ALLOWED_KEYS` set
915
+ * are derived from it, so they cannot desynchronise.
916
+ */
917
+ declare const SUBSCRIBE_TO_AGENT_KEYS: readonly ["onMessagesChanged", "onStateChanged", "onRunInitialized", "onRunFinalized", "onRunFailed", "onRunErrorEvent"];
520
918
  /**
521
919
  * The subset of `AgentSubscriber` callbacks accepted by
522
920
  * {@link CopilotKitCore.subscribeToAgentWithOptions}. Only the callbacks
@@ -596,12 +994,6 @@ interface CopilotKitCoreFriendsAccess {
596
994
  * See CopilotKitCore.waitForPendingFrameworkUpdates for details.
597
995
  */
598
996
  waitForPendingFrameworkUpdates(): Promise<void>;
599
- /**
600
- * Subscribe the state manager to an agent (including per-thread clones).
601
- * Called by RunHandler before executing an agent so that events from
602
- * clones are tracked in stateByRun/messageToRun.
603
- */
604
- subscribeAgentToStateManager(agent: AbstractAgent): void;
605
997
  }
606
998
  declare class CopilotKitCore {
607
999
  private _headers;
@@ -615,6 +1007,14 @@ declare class CopilotKitCore {
615
1007
  private suggestionEngine;
616
1008
  private runHandler;
617
1009
  private stateManager;
1010
+ private threadStoreRegistry;
1011
+ /**
1012
+ * Tracks the agent IDs from the most recent `onAgentsChanged` notification.
1013
+ * Used to gate thread-store auto-unregister so the FIRST empty-agents
1014
+ * notification (before published agents are merged in) does not rip out a
1015
+ * store that was registered prior to that initial notification.
1016
+ */
1017
+ private previousAgentIds;
618
1018
  constructor({
619
1019
  runtimeUrl,
620
1020
  runtimeTransport,
@@ -688,12 +1088,39 @@ declare class CopilotKitCore {
688
1088
  setAgents__unsafe_dev_only(agents: Record<string, AbstractAgent>): void;
689
1089
  addAgent__unsafe_dev_only(params: CopilotKitCoreAddAgentParams): void;
690
1090
  removeAgent__unsafe_dev_only(id: string): void;
1091
+ /**
1092
+ * Register a proxied agent against an existing runtime agent. The proxy is
1093
+ * exposed under `agentId` (local registry id) and routes outbound runtime
1094
+ * requests to `runtimeAgentId`. Throws if `agentId` is already taken.
1095
+ *
1096
+ * Returns the minted proxy and an `unregister` handle for cleanup.
1097
+ *
1098
+ * Use this to mount multiple frontend agents against a single runtime
1099
+ * agent (e.g. one per chat window) without implicit per-thread cloning.
1100
+ *
1101
+ * @example
1102
+ * const { agent, unregister } = copilotkit.registerProxiedAgent({
1103
+ * agentId: "chat-1",
1104
+ * runtimeAgentId: "default",
1105
+ * });
1106
+ * // ... <CopilotChat agentId="chat-1" />
1107
+ * // on cleanup:
1108
+ * unregister();
1109
+ */
1110
+ registerProxiedAgent(params: CopilotKitCoreRegisterProxiedAgentParams): CopilotKitCoreRegisterProxiedAgentResult;
691
1111
  getAgent(id: string): AbstractAgent | undefined;
692
1112
  /**
693
1113
  * Context management (delegated to ContextStore)
694
1114
  */
695
1115
  addContext(context: Context): string;
696
1116
  removeContext(id: string): void;
1117
+ /**
1118
+ * Thread store registry (delegated to ThreadStoreRegistry)
1119
+ */
1120
+ registerThreadStore(agentId: string, store: ɵThreadStore): void;
1121
+ unregisterThreadStore(agentId: string): void;
1122
+ getThreadStore(agentId: string): ɵThreadStore | undefined;
1123
+ getThreadStores(): Readonly<Record<string, ɵThreadStore>>;
697
1124
  /**
698
1125
  * Suggestions management (delegated to SuggestionEngine)
699
1126
  */
@@ -742,7 +1169,6 @@ declare class CopilotKitCore {
742
1169
  getStateByRun(agentId: string, threadId: string, runId: string): State | undefined;
743
1170
  getRunIdForMessage(agentId: string, threadId: string, messageId: string): string | undefined;
744
1171
  getRunIdsForThread(agentId: string, threadId: string): string[];
745
- subscribeAgentToStateManager(agent: AbstractAgent): void;
746
1172
  /**
747
1173
  * Internal method used by RunHandler to build frontend tools
748
1174
  */
@@ -825,14 +1251,8 @@ declare class SuggestionEngine {
825
1251
  /**
826
1252
  * Reload suggestions for a specific agent
827
1253
  * This triggers generation of new suggestions based on current configs
828
- *
829
- * @param agentId - The consumer agent ID
830
- * @param consumerAgent - Optional: the specific agent instance whose messages should be used
831
- * for availability filtering and context. When running with per-thread clones, the thread
832
- * clone holds the conversation messages; passing it here ensures dynamic suggestions fire
833
- * after the first message even though the registry agent has an empty message list.
834
1254
  */
835
- reloadSuggestions(agentId: string, consumerAgent?: AbstractAgent): void;
1255
+ reloadSuggestions(agentId: string): void;
836
1256
  /**
837
1257
  * Clear all suggestions for a specific agent
838
1258
  */
@@ -897,23 +1317,10 @@ declare class StateManager {
897
1317
  initialize(): void;
898
1318
  /**
899
1319
  * Subscribe to an agent's events to track state and messages.
900
- *
901
- * Registry agents (subscribed via `onAgentsChanged`) use the bare `agentId`
902
- * key so that `unsubscribeFromAgent(agentId)` can remove them when they
903
- * are replaced. Per-thread clones (subscribed via `subscribeAgentToStateManager`)
904
- * pass `{ isClone: true }` to use a composite `agentId:threadId` key, keeping
905
- * their subscription independent of the registry agent's.
906
- */
907
- subscribeToAgent(agent: AbstractAgent, /** @param isClone When true, uses a composite `agentId:threadId` key for per-thread isolation. */{
908
- isClone
909
- }?: {
910
- isClone?: boolean;
911
- }): void;
912
- /**
913
- * Unsubscribe a registry agent's subscription (bare `agentId` key).
914
- * Per-thread clone subscriptions use composite `agentId:threadId` keys and
915
- * are replaced (not removed) by subsequent subscribeToAgent(agent, { isClone: true })
916
- * calls for the same (agentId, threadId) pair.
1320
+ */
1321
+ subscribeToAgent(agent: AbstractAgent): void;
1322
+ /**
1323
+ * Unsubscribe an agent's subscription.
917
1324
  */
918
1325
  unsubscribeFromAgent(agentId: string): void;
919
1326
  /**
@@ -975,46 +1382,6 @@ declare class StateManager {
975
1382
  clearThreadState(agentId: string, threadId: string): void;
976
1383
  }
977
1384
  //#endregion
978
- //#region src/agent.d.ts
979
- type ResolvedRuntimeMode = RuntimeMode$1 | "pending";
980
- interface ProxiedCopilotRuntimeAgentConfig extends Omit<HttpAgentConfig, "url"> {
981
- runtimeUrl?: string;
982
- transport?: CopilotRuntimeTransport;
983
- credentials?: RequestCredentials;
984
- runtimeMode?: ResolvedRuntimeMode;
985
- intelligence?: IntelligenceRuntimeInfo$1;
986
- capabilities?: AgentCapabilities;
987
- debug?: ResolvedDebugConfig;
988
- }
989
- declare class ProxiedCopilotRuntimeAgent extends HttpAgent {
990
- #private;
991
- runtimeUrl?: string;
992
- credentials?: RequestCredentials;
993
- private transport;
994
- private singleEndpointUrl?;
995
- private runtimeMode;
996
- private intelligence?;
997
- private _capabilities?;
998
- private delegate?;
999
- private runtimeInfoPromise?;
1000
- constructor(config: ProxiedCopilotRuntimeAgentConfig);
1001
- get capabilities(): AgentCapabilities | undefined;
1002
- getCapabilities(): Promise<AgentCapabilities>;
1003
- detachActiveRun(): Promise<void>;
1004
- abortRun(): void;
1005
- connectAgent(parameters?: RunAgentParameters, subscriber?: AgentSubscriber): Promise<RunAgentResult>;
1006
- connect(input: RunAgentInput): Observable<BaseEvent>;
1007
- run(input: RunAgentInput): Observable<BaseEvent>;
1008
- clone(): ProxiedCopilotRuntimeAgent;
1009
- private resolveDelegate;
1010
- private ensureRuntimeMode;
1011
- private fetchRuntimeInfo;
1012
- private fetchRuntimeInfoAutoDetect;
1013
- private createSingleRouteRequestInit;
1014
- private createIntelligenceDelegate;
1015
- private syncDelegate;
1016
- }
1017
- //#endregion
1018
1385
  //#region src/utils/markdown.d.ts
1019
1386
  declare function completePartialMarkdown(input: string): string;
1020
1387
  //#endregion
@@ -1025,297 +1392,92 @@ interface IntelligenceAgentSharedState {
1025
1392
  declare class AgentThreadLockedError extends Error {
1026
1393
  constructor(threadId?: string);
1027
1394
  }
1028
- interface IntelligenceAgentConfig {
1029
- /** Phoenix websocket URL, e.g. "ws://localhost:4000/socket" */
1030
- url: string;
1031
- /** Runtime REST URL, e.g. "http://localhost:4000" */
1032
- runtimeUrl: string;
1033
- /** Agent identifier for REST endpoints */
1034
- agentId: string;
1035
- /** Optional params sent on socket connect (e.g. auth token) */
1036
- socketParams?: Record<string, string>;
1037
- /** Optional headers sent with REST requests */
1038
- headers?: Record<string, string>;
1039
- /** Optional credentials mode for fetch requests */
1040
- credentials?: RequestCredentials;
1041
- }
1042
- declare class IntelligenceAgent extends AbstractAgent {
1043
- private config;
1044
- private socket;
1045
- private activeChannel;
1046
- private canonicalRunId;
1047
- private sharedState;
1048
- constructor(config: IntelligenceAgentConfig, sharedState?: IntelligenceAgentSharedState);
1049
- clone(): IntelligenceAgent;
1050
- /**
1051
- * Override of AbstractAgent.connectAgent that removes the `verifyEvents` step.
1052
- *
1053
- * Background: AbstractAgent's connectAgent pipeline runs events through
1054
- * `verifyEvents`, which validates that the stream follows the AG-UI protocol
1055
- * lifecycle — specifically, it expects a RUN_STARTED event before any content
1056
- * events and a RUN_FINISHED/RUN_ERROR event to complete the stream.
1057
- *
1058
- * IntelligenceAgent uses long-lived WebSocket connections rather than
1059
- * request-scoped SSE streams. When connecting to replay historical messages
1060
- * for an existing thread, the connection semantics don't map to a single
1061
- * agent run start/stop cycle. The replayed events may not include
1062
- * RUN_STARTED/RUN_FINISHED bookends (or may contain events from multiple
1063
- * past runs), which causes verifyEvents to either never complete or to
1064
- * error out.
1065
- *
1066
- * This override replicates the base connectAgent implementation exactly,
1067
- * substituting only `transformChunks` (which is still needed for message
1068
- * reassembly) and omitting `verifyEvents`.
1069
- *
1070
- * TODO: Remove this override once AG-UI's AbstractAgent supports opting out
1071
- * of verifyEvents for transports with different connection life-cycles.
1072
- */
1073
- connectAgent(parameters?: RunAgentParameters, subscriber?: AgentSubscriber): Promise<RunAgentResult>;
1074
- abortRun(): void;
1075
- /**
1076
- * Trigger the run via REST, then join the realtime thread channel and relay
1077
- * server-pushed AG-UI events to the Observable subscriber.
1078
- */
1079
- run(input: RunAgentInput): Observable<BaseEvent>;
1080
- /**
1081
- * Reconnect to an existing thread by fetching websocket credentials and
1082
- * joining the realtime thread channel.
1083
- */
1084
- protected connect(input: RunAgentInput): Observable<BaseEvent>;
1085
- /**
1086
- * Tear down a specific channel + socket pair that belongs to one pipeline.
1087
- * Only nulls instance references when they still point to the owned resource,
1088
- * so a concurrent pipeline's resources are never clobbered.
1089
- */
1090
- private cleanupOwned;
1091
- private cleanup;
1092
- private requestJoinCredentials$;
1093
- private normalizeJoinCredentials;
1094
- private observeThread$;
1095
- private observeThreadSession$;
1096
- private joinThreadChannel$;
1097
- private observeSocketHealth$;
1098
- private observeThreadEvents$;
1099
- private observeControlEvent$;
1100
- private observeChannelEvent$;
1101
- private createThreadNotifications;
1102
- private buildRuntimeUrl;
1103
- private createThreadChannelParams;
1104
- private getLastSeenEventId;
1105
- private getReconnectCursor;
1106
- private clearReconnectCursor;
1107
- private updateLastSeenEventId;
1108
- private updateLastSeenEventIdFromControl;
1109
- private readEventId;
1110
- private readControlEventId;
1111
- private applyCanonicalRunIdentity;
1112
- private isSocketReconnectExhaustedError;
1113
- }
1114
- //#endregion
1115
- //#region src/utils/micro-redux.d.ts
1116
- /**
1117
- * The minimal action shape used by this micro-redux implementation.
1118
- */
1119
- interface AnyAction {
1120
- type: string;
1121
- }
1122
- /**
1123
- * A typed action creator function with a `type` literal and runtime matcher.
1124
- */
1125
- type ActionCreator<Type extends string, Args extends unknown[] = unknown[], Action extends AnyAction & {
1126
- type: Type;
1127
- } = {
1128
- type: Type;
1129
- }> = ((...args: Args) => Action) & {
1130
- type: Type;
1131
- match(action: AnyAction): action is Action;
1132
- };
1133
- /**
1134
- * Extracts the action type produced by an action creator.
1135
- */
1136
- type ActionFromCreator<T> = T extends ((...args: any[]) => infer A) ? A : never;
1137
- /**
1138
- * Extracts a union of actions produced by a tuple/array of action creators.
1139
- */
1140
- type ActionFromCreators<Creators extends readonly ActionCreator<string, any[], any>[]> = ActionFromCreator<Creators[number]>;
1141
- /**
1142
- * A reducer transforms state in response to actions.
1143
- */
1144
- type Reducer<State, Action extends AnyAction = AnyAction> = (state: State | undefined, action: Action) => State;
1145
- /**
1146
- * A selector derives a value from state.
1147
- */
1148
- type Selector<State, Result> = (state: State) => Result;
1149
- /**
1150
- * Marker config for action creators that accept no payload.
1151
- */
1152
- interface EmptyActionConfig {
1153
- readonly kind: "empty";
1154
- }
1155
- declare const PROPS_MARKER: unique symbol;
1156
- /**
1157
- * Marker config for action creators that require payload props.
1158
- */
1159
- interface PropsActionConfig<Props extends Record<string, unknown>> {
1160
- readonly kind: "props";
1161
- readonly [PROPS_MARKER]?: Props;
1162
- }
1163
- /**
1164
- * Supported action creator config node in an action group.
1165
- */
1166
- type ActionConfig = EmptyActionConfig | PropsActionConfig<Record<string, unknown>>;
1167
- /**
1168
- * Shape of an action group declaration object.
1169
- */
1170
- type ActionGroupConfig = Record<string, ActionConfig>;
1171
- /**
1172
- * Maps an action group declaration to a strongly typed action-creator object.
1173
- */
1174
- type ActionGroupResult<Source extends string, Config extends ActionGroupConfig> = { [K in keyof Config & string]: Config[K] extends PropsActionConfig<infer P> ? ActionCreator<`[${Source}] ${K}`, [P], {
1175
- type: `[${Source}] ${K}`;
1176
- } & P> : ActionCreator<`[${Source}] ${K}`, [], {
1177
- type: `[${Source}] ${K}`;
1178
- }> };
1179
- interface OnReducerEntry<State, Action extends AnyAction = AnyAction, Creators extends readonly ActionCreator<string, any[], any>[] = readonly ActionCreator<string, any[], any>[]> {
1180
- creators: Creators;
1181
- reducer: (state: State, action: Action) => State;
1182
- }
1183
- type ActionFromOnReducerEntry<TEntry> = TEntry extends OnReducerEntry<any, infer TAction, any> ? TAction : never;
1184
- /**
1185
- * Effect contract for streams that emit actions to dispatch.
1186
- */
1187
- interface DispatchingEffect<State, InputAction extends AnyAction = AnyAction, OutputAction extends AnyAction = AnyAction> {
1188
- run: (actions$: Observable<InputAction>, state$: Observable<State>) => Observable<OutputAction>;
1189
- dispatch: true;
1190
- }
1191
- /**
1192
- * Effect contract for side-effect-only streams whose emissions are ignored.
1193
- */
1194
- interface NonDispatchingEffect<State, InputAction extends AnyAction = AnyAction> {
1195
- run: (actions$: Observable<InputAction>, state$: Observable<State>) => Observable<unknown>;
1196
- dispatch: false;
1197
- }
1198
- /**
1199
- * Union of supported effect shapes.
1200
- */
1201
- type Effect<State, InputAction extends AnyAction = AnyAction, OutputAction extends AnyAction = AnyAction> = DispatchingEffect<State, InputAction, OutputAction> | NonDispatchingEffect<State, InputAction>;
1202
- /**
1203
- * Lifecycle actions dispatched by the store.
1204
- */
1205
- type StoreLifecycleAction = {
1206
- type: "@@micro-redux/init";
1207
- } | {
1208
- type: "@@micro-redux/stop";
1209
- };
1210
- /**
1211
- * Options for a dispatching effect.
1212
- */
1213
- interface DispatchingEffectOptions {
1214
- dispatch?: true;
1215
- }
1216
- /**
1217
- * Options for a non-dispatching effect.
1218
- */
1219
- interface NonDispatchingEffectOptions {
1220
- dispatch: false;
1221
- }
1222
- /**
1223
- * Declares a payload-based action config for `createActionGroup`.
1224
- *
1225
- * @example
1226
- * ```ts
1227
- * const actions = createActionGroup("User", {
1228
- * loaded: props<{ id: string }>(),
1229
- * });
1230
- * ```
1231
- */
1232
- declare function props<Props extends Record<string, unknown>>(): PropsActionConfig<Props>;
1233
- /**
1234
- * Declares a no-payload action config for `createActionGroup`.
1235
- *
1236
- * @example
1237
- * ```ts
1238
- * const actions = createActionGroup("User", {
1239
- * reset: empty(),
1240
- * });
1241
- * ```
1242
- */
1243
- declare function empty(): EmptyActionConfig;
1244
- /**
1245
- * Creates a namespaced group of typed action creators.
1246
- *
1247
- * Action types are formatted as: `[Source] actionName`.
1248
- */
1249
- declare function createActionGroup<const Source extends string, const Config extends ActionGroupConfig>(source: Source, config: Config): ActionGroupResult<Source, Config>;
1250
- /**
1251
- * Registers one reducer handler for one or more action creators.
1252
- *
1253
- * @throws Error when called without at least one action creator and reducer.
1254
- */
1255
- declare function on<State, const Creators extends readonly ActionCreator<string, any[], any>[], Action extends ActionFromCreators<Creators>>(...args: [...creators: Creators, reducer: (state: State, action: Action) => State]): OnReducerEntry<State, Action, Creators>;
1256
- /**
1257
- * Creates a reducer from an initial state and `on(...)` handler entries.
1258
- *
1259
- * Unknown action types return the current state unchanged.
1260
- */
1261
- declare function createReducer<State, const Entries extends readonly OnReducerEntry<any, any, any>[]>(initialState: State, ...entries: Entries): Reducer<State, ActionFromOnReducerEntry<Entries[number]>>;
1262
- /**
1263
- * Creates a memoized selector from a single projector.
1264
- */
1265
- declare function createSelector<State, Result>(projector: (state: State) => Result): Selector<State, Result>;
1266
- /**
1267
- * Creates a memoized selector from input selectors and a projector.
1268
- *
1269
- * Memoization uses one-entry caching over the latest input selector values.
1270
- */
1271
- declare function createSelector<State, const Selectors extends readonly Selector<State, unknown>[], Result>(...args: [...selectors: Selectors, projector: (...inputs: { [K in keyof Selectors]: ReturnType<Selectors[K]> }) => Result]): Selector<State, Result>;
1272
- /**
1273
- * RxJS operator that maps state emissions through a selector and suppresses
1274
- * unchanged projected values via reference equality.
1275
- */
1276
- declare function select<State, Result>(selector: Selector<State, Result>): OperatorFunction<State, Result>;
1277
- /**
1278
- * RxJS operator that filters an action stream by action creators and narrows
1279
- * the output action type to the matched creator union.
1280
- *
1281
- * @throws Error when called without at least one action creator.
1282
- */
1283
- declare function ofType<const Creators extends readonly ActionCreator<string, any[], AnyAction>[]>(...creators: Creators): OperatorFunction<AnyAction, ActionFromCreators<Creators>>;
1284
- /**
1285
- * Creates a dispatching effect. Emitted actions are automatically dispatched.
1286
- */
1287
- declare function createEffect<State, InputAction extends AnyAction, OutputAction extends AnyAction>(factory: (actions$: Observable<InputAction>, state$: Observable<State>) => Observable<OutputAction>, options?: DispatchingEffectOptions): DispatchingEffect<State, InputAction, OutputAction>;
1288
- /**
1289
- * Creates a non-dispatching effect. Emitted values are ignored.
1290
- */
1291
- declare function createEffect<State, InputAction extends AnyAction>(factory: (actions$: Observable<InputAction>, state$: Observable<State>) => Observable<unknown>, options: NonDispatchingEffectOptions): NonDispatchingEffect<State, InputAction>;
1292
- /**
1293
- * Store interface returned by `createStore`.
1294
- */
1295
- interface Store<State, Action extends AnyAction = AnyAction> {
1296
- dispatch(action: Action): void;
1297
- getState(): State;
1298
- readonly state$: Observable<State>;
1299
- readonly actions$: Observable<Action | StoreLifecycleAction>;
1300
- select<Result>(selector: Selector<State, Result>): Observable<Result>;
1301
- init(): void;
1302
- stop(): void;
1395
+ interface IntelligenceAgentConfig {
1396
+ /** Phoenix websocket URL, e.g. "ws://localhost:4000/socket" */
1397
+ url: string;
1398
+ /** Runtime REST URL, e.g. "http://localhost:4000" */
1399
+ runtimeUrl: string;
1400
+ /** Agent identifier for REST endpoints */
1401
+ agentId: string;
1402
+ /** Optional params sent on socket connect (e.g. auth token) */
1403
+ socketParams?: Record<string, string>;
1404
+ /** Optional headers sent with REST requests */
1405
+ headers?: Record<string, string>;
1406
+ /** Optional credentials mode for fetch requests */
1407
+ credentials?: RequestCredentials;
1408
+ }
1409
+ declare class IntelligenceAgent extends AbstractAgent {
1410
+ private config;
1411
+ private socket;
1412
+ private activeChannel;
1413
+ private canonicalRunId;
1414
+ private sharedState;
1415
+ constructor(config: IntelligenceAgentConfig, sharedState?: IntelligenceAgentSharedState);
1416
+ clone(): IntelligenceAgent;
1417
+ /**
1418
+ * Override of AbstractAgent.connectAgent that removes the `verifyEvents` step.
1419
+ *
1420
+ * Background: AbstractAgent's connectAgent pipeline runs events through
1421
+ * `verifyEvents`, which validates that the stream follows the AG-UI protocol
1422
+ * lifecycle — specifically, it expects a RUN_STARTED event before any content
1423
+ * events and a RUN_FINISHED/RUN_ERROR event to complete the stream.
1424
+ *
1425
+ * IntelligenceAgent uses long-lived WebSocket connections rather than
1426
+ * request-scoped SSE streams. When connecting to replay historical messages
1427
+ * for an existing thread, the connection semantics don't map to a single
1428
+ * agent run start/stop cycle. The replayed events may not include
1429
+ * RUN_STARTED/RUN_FINISHED bookends (or may contain events from multiple
1430
+ * past runs), which causes verifyEvents to either never complete or to
1431
+ * error out.
1432
+ *
1433
+ * This override replicates the base connectAgent implementation exactly,
1434
+ * substituting only `transformChunks` (which is still needed for message
1435
+ * reassembly) and omitting `verifyEvents`.
1436
+ *
1437
+ * TODO: Remove this override once AG-UI's AbstractAgent supports opting out
1438
+ * of verifyEvents for transports with different connection life-cycles.
1439
+ */
1440
+ connectAgent(parameters?: RunAgentParameters, subscriber?: AgentSubscriber): Promise<RunAgentResult>;
1441
+ abortRun(): void;
1442
+ /**
1443
+ * Trigger the run via REST, then join the realtime thread channel and relay
1444
+ * server-pushed AG-UI events to the Observable subscriber.
1445
+ */
1446
+ run(input: RunAgentInput): Observable<BaseEvent>;
1447
+ /**
1448
+ * Reconnect to an existing thread by fetching websocket credentials and
1449
+ * joining the realtime thread channel.
1450
+ */
1451
+ protected connect(input: RunAgentInput): Observable<BaseEvent>;
1452
+ /**
1453
+ * Tear down a specific channel + socket pair that belongs to one pipeline.
1454
+ * Only nulls instance references when they still point to the owned resource,
1455
+ * so a concurrent pipeline's resources are never clobbered.
1456
+ */
1457
+ private cleanupOwned;
1458
+ private cleanup;
1459
+ private requestJoinCredentials$;
1460
+ private normalizeJoinCredentials;
1461
+ private observeThread$;
1462
+ private observeThreadSession$;
1463
+ private joinThreadChannel$;
1464
+ private observeSocketHealth$;
1465
+ private observeThreadEvents$;
1466
+ private observeControlEvent$;
1467
+ private observeChannelEvent$;
1468
+ private createThreadNotifications;
1469
+ private buildRuntimeUrl;
1470
+ private createThreadChannelParams;
1471
+ private getLastSeenEventId;
1472
+ private getReconnectCursor;
1473
+ private clearReconnectCursor;
1474
+ private updateLastSeenEventId;
1475
+ private updateLastSeenEventIdFromControl;
1476
+ private readEventId;
1477
+ private readControlEventId;
1478
+ private applyCanonicalRunIdentity;
1479
+ private isSocketReconnectExhaustedError;
1303
1480
  }
1304
- /**
1305
- * Creates a small observable store with reducer + effects.
1306
- *
1307
- * Behavior:
1308
- * - `init()` starts effects and dispatches `@@micro-redux/init`.
1309
- * - `stop()` dispatches `@@micro-redux/stop` and unsubscribes all effects.
1310
- * - Effect action observation is scheduled on `asapScheduler` to avoid
1311
- * synchronous re-entrancy in the effect loop.
1312
- * - Any effect error triggers fail-fast teardown and errors both `actions$`
1313
- * and `state$`.
1314
- */
1315
- declare function createStore<State, Action extends AnyAction = AnyAction>(options: {
1316
- reducer: Reducer<State, Action | StoreLifecycleAction>;
1317
- effects?: Array<Effect<State, Action | StoreLifecycleAction, Action>>;
1318
- }): Store<State, Action>;
1319
1481
  //#endregion
1320
1482
  //#region src/utils/phoenix-observable.d.ts
1321
1483
  /**
@@ -1432,80 +1594,5 @@ declare function ɵobservePhoenixSocketSignals$(socket$: Observable<ɵPhoenixSoc
1432
1594
  */
1433
1595
  declare function ɵobservePhoenixSocketHealth$(socketSignals$: Observable<ɵPhoenixSocketSignal>, maxConsecutiveErrors: number): Observable<never>;
1434
1596
  //#endregion
1435
- //#region src/threads.d.ts
1436
- interface ThreadRecord {
1437
- id: string;
1438
- organizationId: string;
1439
- agentId: string;
1440
- createdById: string;
1441
- name: string | null;
1442
- archived: boolean;
1443
- createdAt: string;
1444
- updatedAt: string;
1445
- lastRunAt?: string;
1446
- }
1447
- interface ThreadRuntimeContext {
1448
- runtimeUrl: string;
1449
- headers: Record<string, string>;
1450
- wsUrl?: string;
1451
- agentId: string;
1452
- includeArchived?: boolean;
1453
- limit?: number;
1454
- }
1455
- type ThreadMetadataEvent = {
1456
- operation: "created" | "renamed" | "archived" | "unarchived" | "updated";
1457
- threadId: string;
1458
- userId: string;
1459
- organizationId: string;
1460
- occurredAt: string;
1461
- thread: ThreadRecord;
1462
- } | {
1463
- operation: "deleted";
1464
- threadId: string;
1465
- userId: string;
1466
- organizationId: string;
1467
- occurredAt: string;
1468
- deleted: {
1469
- id: string;
1470
- };
1471
- };
1472
- interface ThreadEnvironment {
1473
- fetch: typeof fetch;
1474
- }
1475
- interface ThreadState {
1476
- threads: ThreadRecord[];
1477
- isLoading: boolean;
1478
- isFetchingNextPage: boolean;
1479
- error: Error | null;
1480
- context: ThreadRuntimeContext | null;
1481
- sessionId: number;
1482
- metadataCredentialsRequested: boolean;
1483
- metadataJoinCode: string | null;
1484
- nextCursor: string | null;
1485
- }
1486
- interface ThreadStore {
1487
- start(): void;
1488
- stop(): void;
1489
- setContext(context: ThreadRuntimeContext | null): void;
1490
- fetchNextPage(): void;
1491
- renameThread(threadId: string, name: string): Promise<void>;
1492
- archiveThread(threadId: string): Promise<void>;
1493
- deleteThread(threadId: string): Promise<void>;
1494
- getState(): ThreadState;
1495
- select: Store<ThreadState>["select"];
1496
- }
1497
- declare function createThreadStore(environment: ThreadEnvironment): ThreadStore;
1498
- type ɵThread = ThreadRecord;
1499
- type ɵThreadRuntimeContext = ThreadRuntimeContext;
1500
- type ɵThreadMetadataEvent = ThreadMetadataEvent;
1501
- type ɵThreadEnvironment = ThreadEnvironment;
1502
- type ɵThreadStore = ThreadStore;
1503
- declare const ɵthreadAdapterEvents: any;
1504
- declare const ɵselectThreads: any;
1505
- declare const ɵselectThreadsIsLoading: any;
1506
- declare const ɵselectThreadsError: any;
1507
- declare const ɵselectHasNextPage: any;
1508
- declare const ɵselectIsFetchingNextPage: any;
1509
- //#endregion
1510
- export { ActionConfig, ActionCreator, ActionFromCreator, ActionFromCreators, ActionGroupConfig, ActionGroupResult, AgentRegistry, AgentThreadLockedError, AnyAction, ContextStore, CopilotKitCore, type CopilotKitCoreAddAgentParams, CopilotKitCoreConfig, type CopilotKitCoreConnectAgentParams, CopilotKitCoreErrorCode, CopilotKitCoreFriendsAccess, CopilotKitCoreGetSuggestionsResult, type CopilotKitCoreGetToolParams, 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, RunHandler, type RuntimeLicenseStatus, type RuntimeMode, Selector, StateManager, StaticSuggestionsConfig, Store, StoreLifecycleAction, SubscribeToAgentOptions, SubscribeToAgentSubscriber, Suggestion, SuggestionAvailability, SuggestionEngine, SuggestionsConfig, ToolCallStatus, completePartialMarkdown, createActionGroup, createEffect, createReducer, createSelector, createStore, empty, ensureObjectArgs, ofType, on, parseToolArguments, props, select, ɵPhoenixChannelLike, ɵPhoenixChannelOptions, ɵPhoenixChannelSession, ɵPhoenixJoinOutcome, ɵPhoenixPushLike, ɵPhoenixSocketLike, ɵPhoenixSocketOptions, ɵPhoenixSocketSession, ɵPhoenixSocketSignal, ɵThread, ɵThreadEnvironment, ɵThreadMetadataEvent, ɵThreadRuntimeContext, ɵThreadStore, createThreadStore as ɵcreateThreadStore, ɵjoinPhoenixChannel$, ɵobservePhoenixEvent$, ɵobservePhoenixJoinOutcome$, ɵobservePhoenixSocketHealth$, ɵobservePhoenixSocketSignals$, ɵphoenixChannel$, ɵphoenixSocket$, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading, ɵthreadAdapterEvents };
1597
+ 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, RunHandler, type RuntimeLicenseStatus, type RuntimeMode, Selector, StateManager, StaticSuggestionsConfig, Store, StoreLifecycleAction, SubscribeToAgentOptions, SubscribeToAgentSubscriber, Suggestion, SuggestionAvailability, SuggestionEngine, SuggestionsConfig, ToolCallStatus, completePartialMarkdown, createActionGroup, createEffect, createReducer, createSelector, createStore, empty, ensureObjectArgs, ofType, on, parseToolArguments, props, select, ɵMAX_SOCKET_RETRIES, ɵPhoenixChannelLike, ɵPhoenixChannelOptions, ɵPhoenixChannelSession, ɵPhoenixJoinOutcome, ɵPhoenixPushLike, ɵPhoenixSocketLike, ɵPhoenixSocketOptions, ɵPhoenixSocketSession, ɵPhoenixSocketSignal, ɵThread, ɵThreadEnvironment, ɵThreadMetadataEvent, ɵThreadRuntimeContext, ɵThreadStore, createThreadStore as ɵcreateThreadStore, ɵjoinPhoenixChannel$, ɵobservePhoenixEvent$, ɵobservePhoenixJoinOutcome$, ɵobservePhoenixSocketHealth$, ɵobservePhoenixSocketSignals$, ɵphoenixChannel$, ɵphoenixSocket$, ɵselectHasNextPage, ɵselectIsFetchingNextPage, ɵselectThreads, ɵselectThreadsError, ɵselectThreadsIsLoading, ɵthreadAdapterEvents };
1511
1598
  //# sourceMappingURL=index.d.cts.map