MCPcopy
hub / github.com/CopilotKit/CopilotKit / createBot

Function createBot

packages/bot/src/create-bot.ts:254–814  ·  view source on GitHub ↗
(opts: CreateBotOptions<TStateSchema>)

Source from the content-addressed store, hash-verified

252}
253
254export function createBot<
255 TStateSchema extends StandardSchemaV1 | undefined = undefined,
256>(opts: CreateBotOptions<TStateSchema>): Bot<ThreadStateOf<TStateSchema>> {
257 const cfg = opts.store ?? {};
258 if (
259 (cfg.identity && !cfg.transcripts) ||
260 (!cfg.identity && cfg.transcripts)
261 ) {
262 throw new Error(
263 "createBot: `identity` and `transcripts` must be configured together.",
264 );
265 }
266
267 const backend: StateStore = cfg.adapter ?? new MemoryStore();
268 const telemetry = new BotTelemetry({
269 backend,
270 packageName: pkg.name,
271 packageVersion: pkg.version,
272 });
273 const transcripts = new Transcripts(backend, cfg.transcripts ?? {});
274 const registry = new ActionRegistry({
275 store: opts.actionStore ?? kvActionStore(backend),
276 });
277
278 for (const c of opts.components ?? []) {
279 if (!c.name) {
280 console.warn(
281 "[bot] createBot: skipping anonymous component — give it a name to enable durable actions after restart.",
282 );
283 continue;
284 }
285 registry.registerComponent(c.name, c as unknown as ComponentFn);
286 }
287
288 const agentFactory: (threadId: string) => AbstractAgent = (() => {
289 const a = opts.agent;
290 if (typeof a === "function")
291 return a as (threadId: string) => AbstractAgent;
292 if (a) return () => a;
293 return () => {
294 throw new Error(
295 "createBot: no agent configured (pass `agent` to use runAgent)",
296 );
297 };
298 })();
299
300 const toolMap = new Map<string, BotTool>();
301 for (const t of opts.tools ?? []) toolMap.set(t.name, t);
302 const context = opts.context ?? [];
303
304 const mentionHandlers: BotHandler[] = [];
305 const messageHandlers: BotHandler[] = [];
306 const threadStartedHandlers: ThreadStartHandler[] = [];
307 const interactionHandlers = new Map<
308 string,
309 (ctx: InteractionContext) => void | Promise<void>
310 >();
311 const interruptHandlers = new Map<

Callers 12

mainFunction · 0.90
index.tsxFile · 0.90
reactions.test.tsFile · 0.85
__handlerTypeGuardsFunction · 0.85
create-bot.test.tsFile · 0.85
runOnMessageFunction · 0.85

Calls 10

registerComponentMethod · 0.95
captureMethod · 0.95
kvActionStoreFunction · 0.85
normalizeCommandNameFunction · 0.85
toAgentToolDescriptorsFunction · 0.85
normalizePlatformFunction · 0.85
storeKindFunction · 0.85
valuesMethod · 0.80
warnMethod · 0.65
setMethod · 0.45

Tested by 2

__handlerTypeGuardsFunction · 0.68
runOnMessageFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…