| 362 | } |
| 363 | |
| 364 | export class CopilotKitCore { |
| 365 | private _headers: Record<string, string>; |
| 366 | private _credentials?: RequestCredentials; |
| 367 | private _properties: Record<string, unknown>; |
| 368 | private _defaultThrottleMs?: number; |
| 369 | private _debug?: DebugConfig; |
| 370 | |
| 371 | private subscribers: Set<CopilotKitCoreSubscriber> = new Set(); |
| 372 | |
| 373 | // Delegate classes |
| 374 | private agentRegistry: AgentRegistry; |
| 375 | private contextStore: ContextStore; |
| 376 | private suggestionEngine: SuggestionEngine; |
| 377 | private runHandler: RunHandler; |
| 378 | private stateManager: StateManager; |
| 379 | private threadStoreRegistry: ThreadStoreRegistry; |
| 380 | /** |
| 381 | * Tracks the agent IDs from the most recent `onAgentsChanged` notification. |
| 382 | * Used to gate thread-store auto-unregister so the FIRST empty-agents |
| 383 | * notification (before published agents are merged in) does not rip out a |
| 384 | * store that was registered prior to that initial notification. |
| 385 | */ |
| 386 | private previousAgentIds: Set<string> = new Set(); |
| 387 | |
| 388 | constructor({ |
| 389 | runtimeUrl, |
| 390 | runtimeTransport = "auto", |
| 391 | headers = {}, |
| 392 | credentials, |
| 393 | properties = {}, |
| 394 | agents__unsafe_dev_only = {}, |
| 395 | tools = [], |
| 396 | suggestionsConfig = [], |
| 397 | debug, |
| 398 | }: CopilotKitCoreConfig) { |
| 399 | this._headers = normalizeHeaders(headers); |
| 400 | this._credentials = credentials; |
| 401 | this._properties = properties; |
| 402 | this._debug = debug; |
| 403 | |
| 404 | // Initialize delegate classes |
| 405 | this.agentRegistry = new AgentRegistry(this); |
| 406 | this.contextStore = new ContextStore(this); |
| 407 | this.suggestionEngine = new SuggestionEngine(this); |
| 408 | this.runHandler = new RunHandler(this); |
| 409 | this.stateManager = new StateManager(this); |
| 410 | this.threadStoreRegistry = new ThreadStoreRegistry(this); |
| 411 | |
| 412 | // Initialize each subsystem |
| 413 | this.agentRegistry.initialize(agents__unsafe_dev_only); |
| 414 | this.runHandler.initialize(tools); |
| 415 | this.suggestionEngine.initialize(suggestionsConfig); |
| 416 | this.stateManager.initialize(); |
| 417 | |
| 418 | this.agentRegistry.setRuntimeTransport(runtimeTransport); |
| 419 | this.agentRegistry.setRuntimeUrl(runtimeUrl); |
| 420 | |
| 421 | // Seed the previous-agents snapshot from the constructor-supplied agents. |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…