MCPcopy Index your code
hub / github.com/CopilotKit/CopilotKit / constructor

Method constructor

packages/core/src/core/core.ts:388–491  ·  view source on GitHub ↗
({
    runtimeUrl,
    runtimeTransport = "auto",
    headers = {},
    credentials,
    properties = {},
    agents__unsafe_dev_only = {},
    tools = [],
    suggestionsConfig = [],
    debug,
  }: CopilotKitCoreConfig)

Source from the content-addressed store, hash-verified

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.
422 // `agentRegistry.initialize` does not emit `onAgentsChanged`, so the
423 // subscriber below would otherwise see its first non-empty notification
424 // as an "addition" relative to an empty baseline — and a later removal
425 // of those same agents would NOT trigger the auto-unregister branch
426 // because the guard would think the agentId was never previously
427 // present. Seeding the set here keeps the guard honest.
428 this.previousAgentIds = new Set(Object.keys(agents__unsafe_dev_only));
429
430 // Subscribe to agent changes to track state for new agents
431 this.subscribe({
432 onAgentsChanged: ({ agents }) => {
433 Object.values(agents).forEach((agent) => {
434 if (agent.agentId) {
435 this.stateManager.subscribeToAgent(agent);
436 }
437 });
438
439 // Unregister thread stores for agents that have been removed.
440 //
441 // Critically, only unregister an agentId that was present in the
442 // PREVIOUS agents snapshot AND is missing from the new one. Without
443 // the "previously had" guard, the FIRST `onAgentsChanged({ agents: {} })`
444 // delivered to a freshly-published core would tear out a thread store
445 // that a consumer (e.g. useThreads) just registered — `core.agents`

Callers

nothing calls this directly

Calls 14

subscribeMethod · 0.95
normalizeHeadersFunction · 0.85
keysMethod · 0.80
forEachMethod · 0.80
valuesMethod · 0.80
getAllMethod · 0.80
unregisterMethod · 0.65
errorMethod · 0.65
initializeMethod · 0.45
setRuntimeTransportMethod · 0.45
setRuntimeUrlMethod · 0.45
subscribeToAgentMethod · 0.45

Tested by

no test coverage detected