Copilot Kit Core Subscriber
Set of optional callbacks notified of CopilotKitCore lifecycle events.
Overview
CopilotKitCoreSubscriber is the object passed to CopilotKitCore.subscribe. Every callback is optional, receives an event object that always includes the copilotkit instance, and may return void or a Promise<void>. Use it to react to connection status, tool execution, suggestions, configuration changes, and errors.
Import
import type { CopilotKitCoreSubscriber } from "@copilotkit/core";Definition
The shape below shows one callback, onRuntimeConnectionStatusChanged.
Properties lists the event shape of each callback.
interface CopilotKitCoreSubscriber {
onRuntimeConnectionStatusChanged?: (event: {
copilotkit: CopilotKitCore;
status: CopilotKitCoreRuntimeConnectionStatus;
}) => void | Promise<void>;
// ...one optional callback per lifecycle event (tool execution, agents,
// context, suggestions, properties, headers, Inspector metadata, errors,
// and thread stores).
// See the Properties section below for each callback's event shape.
}Properties
Prop
Type
Usage
const subscription = copilotkit.subscribe({
onRuntimeConnectionStatusChanged: ({ status }) => {
console.log("connection:", status);
},
onError: ({ code, error }) => {
console.error(code, error);
},
onInspectorMetadataChanged: ({ inspectorMetadata }) => {
console.log("project context:", inspectorMetadata);
},
});
// later
subscription.unsubscribe();How is this guide?