@copilotkit/bot 0.0.1

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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +190 -0
  3. package/dist/action-registry.d.ts +20 -0
  4. package/dist/action-registry.d.ts.map +1 -0
  5. package/dist/action-registry.js +109 -0
  6. package/dist/action-registry.test.d.ts +2 -0
  7. package/dist/action-registry.test.d.ts.map +1 -0
  8. package/dist/action-registry.test.js +45 -0
  9. package/dist/action-store.d.ts +19 -0
  10. package/dist/action-store.d.ts.map +1 -0
  11. package/dist/action-store.js +22 -0
  12. package/dist/action-store.test.d.ts +2 -0
  13. package/dist/action-store.test.d.ts.map +1 -0
  14. package/dist/action-store.test.js +27 -0
  15. package/dist/commands.d.ts +68 -0
  16. package/dist/commands.d.ts.map +1 -0
  17. package/dist/commands.js +30 -0
  18. package/dist/create-bot.d.ts +44 -0
  19. package/dist/create-bot.d.ts.map +1 -0
  20. package/dist/create-bot.js +166 -0
  21. package/dist/create-bot.test.d.ts +2 -0
  22. package/dist/create-bot.test.d.ts.map +1 -0
  23. package/dist/create-bot.test.js +261 -0
  24. package/dist/index.d.ts +17 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +19 -0
  27. package/dist/mint-id.d.ts +3 -0
  28. package/dist/mint-id.d.ts.map +1 -0
  29. package/dist/mint-id.js +20 -0
  30. package/dist/mint-id.test.d.ts +2 -0
  31. package/dist/mint-id.test.d.ts.map +1 -0
  32. package/dist/mint-id.test.js +16 -0
  33. package/dist/platform-adapter.d.ts +125 -0
  34. package/dist/platform-adapter.d.ts.map +1 -0
  35. package/dist/platform-adapter.js +1 -0
  36. package/dist/platform-adapter.test.d.ts +2 -0
  37. package/dist/platform-adapter.test.d.ts.map +1 -0
  38. package/dist/platform-adapter.test.js +32 -0
  39. package/dist/run-loop.d.ts +38 -0
  40. package/dist/run-loop.d.ts.map +1 -0
  41. package/dist/run-loop.js +100 -0
  42. package/dist/run-loop.test.d.ts +2 -0
  43. package/dist/run-loop.test.d.ts.map +1 -0
  44. package/dist/run-loop.test.js +80 -0
  45. package/dist/standard-schema.d.ts +52 -0
  46. package/dist/standard-schema.d.ts.map +1 -0
  47. package/dist/standard-schema.js +66 -0
  48. package/dist/testing/fake-adapter.d.ts +44 -0
  49. package/dist/testing/fake-adapter.d.ts.map +1 -0
  50. package/dist/testing/fake-adapter.js +123 -0
  51. package/dist/testing/fake-agent.d.ts +28 -0
  52. package/dist/testing/fake-agent.d.ts.map +1 -0
  53. package/dist/testing/fake-agent.js +36 -0
  54. package/dist/thread.d.ts +60 -0
  55. package/dist/thread.d.ts.map +1 -0
  56. package/dist/thread.js +109 -0
  57. package/dist/tools.d.ts +67 -0
  58. package/dist/tools.d.ts.map +1 -0
  59. package/dist/tools.js +38 -0
  60. package/dist/tools.test.d.ts +2 -0
  61. package/dist/tools.test.d.ts.map +1 -0
  62. package/dist/tools.test.js +31 -0
  63. package/package.json +60 -0
@@ -0,0 +1,60 @@
1
+ import type { PlatformAdapter, ReplyTarget } from "./platform-adapter.js";
2
+ import type { ActionRegistry } from "./action-registry.js";
3
+ import type { Renderable, MessageRef, PlatformUser, ThreadMessage, Thread as ThreadInterface } from "@copilotkit/bot-ui";
4
+ import type { BotTool, ContextEntry, AgentToolDescriptor } from "./tools.js";
5
+ import type { AbstractAgent } from "@ag-ui/client";
6
+ export interface ThreadDeps {
7
+ adapter: PlatformAdapter;
8
+ replyTarget: ReplyTarget;
9
+ conversationKey: string;
10
+ registry: ActionRegistry;
11
+ agentFactory: (threadId: string) => AbstractAgent;
12
+ tools: Map<string, BotTool>;
13
+ toolDescriptors: AgentToolDescriptor[];
14
+ context: ContextEntry[];
15
+ registerWaiter: (conversationKey: string, resolve: (value: unknown) => void) => void;
16
+ interruptHandlers: Map<string, (args: {
17
+ payload: unknown;
18
+ thread: Thread;
19
+ }) => void | Promise<void>>;
20
+ }
21
+ /** A concrete conversation thread: posts UI, runs the agent loop, and resolves HITL waiters. */
22
+ export declare class Thread implements ThreadInterface {
23
+ private deps;
24
+ readonly platform: string;
25
+ constructor(deps: ThreadDeps);
26
+ private bindForPost;
27
+ post(ui: Renderable): Promise<MessageRef>;
28
+ update(ref: MessageRef, ui: Renderable): Promise<MessageRef>;
29
+ delete(ref: MessageRef): Promise<void>;
30
+ stream(src: string | AsyncIterable<string>): Promise<MessageRef>;
31
+ postFile(args: {
32
+ bytes: Uint8Array;
33
+ filename: string;
34
+ title?: string;
35
+ altText?: string;
36
+ }): Promise<{
37
+ ok: boolean;
38
+ fileId?: string;
39
+ error?: string;
40
+ }>;
41
+ /** Read the conversation's messages (returns `[]` when the adapter can't read history). */
42
+ getMessages(): Promise<ThreadMessage[]>;
43
+ /** Resolve a platform user by free-form query (returns `undefined` when unsupported). */
44
+ lookupUser(query: string): Promise<PlatformUser | undefined>;
45
+ /** Post a picker and wait until an interaction in this conversation resolves it. */
46
+ awaitChoice<T = unknown>(ui: Renderable): Promise<T>;
47
+ runAgent(input?: {
48
+ context?: ContextEntry[];
49
+ tools?: BotTool[];
50
+ /**
51
+ * A user message to inject before running. Needed when the input isn't
52
+ * already in the conversation history the adapter reconstructs — e.g. a
53
+ * slash command, whose args are never posted to the channel.
54
+ */
55
+ prompt?: string;
56
+ }): Promise<MessageRef | undefined>;
57
+ resume(value: unknown): Promise<MessageRef | undefined>;
58
+ private run;
59
+ }
60
+ //# sourceMappingURL=thread.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../src/thread.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,YAAY,EACZ,aAAa,EACb,MAAM,IAAI,eAAe,EAC1B,MAAM,oBAAoB,CAAC;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O,CAAC,UAAU,CAAC;IAUhE,QAAQ,CAAC,IAAI,EAAE;QACnB,KAAK,EAAE,UAAU,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAW7D,2FAA2F;IACrF,WAAW,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAI7C,yFAAyF;IACnF,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAIlE,oFAAoF;IAC9E,WAAW,CAAC,CAAC,GAAG,OAAO,EAAE,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC;IAWpD,QAAQ,CAAC,KAAK,CAAC,EAAE;QACrB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;QACzB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;QAClB;;;;WAIG;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAI7B,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;YAI/C,GAAG;CAsDlB"}
package/dist/thread.js ADDED
@@ -0,0 +1,109 @@
1
+ import { runAgentLoop } from "./run-loop.js";
2
+ import { toAgentToolDescriptors } from "./tools.js";
3
+ /** A concrete conversation thread: posts UI, runs the agent loop, and resolves HITL waiters. */
4
+ export class Thread {
5
+ deps;
6
+ platform;
7
+ constructor(deps) {
8
+ this.deps = deps;
9
+ this.platform = deps.adapter.platform;
10
+ }
11
+ async bindForPost(ui) {
12
+ return this.deps.registry.bindRenderable(ui, this.deps.conversationKey);
13
+ }
14
+ async post(ui) {
15
+ return this.deps.adapter.post(this.deps.replyTarget, await this.bindForPost(ui));
16
+ }
17
+ async update(ref, ui) {
18
+ await this.deps.adapter.update(ref, await this.bindForPost(ui));
19
+ return ref;
20
+ }
21
+ async delete(ref) {
22
+ await this.deps.adapter.delete(ref);
23
+ }
24
+ async stream(src) {
25
+ const iter = typeof src === "string"
26
+ ? (async function* () {
27
+ yield src;
28
+ })()
29
+ : src;
30
+ return this.deps.adapter.stream(this.deps.replyTarget, iter);
31
+ }
32
+ async postFile(args) {
33
+ const adapter = this.deps.adapter;
34
+ if (!adapter.postFile) {
35
+ return {
36
+ ok: false,
37
+ error: `${this.platform} does not support file upload`,
38
+ };
39
+ }
40
+ return adapter.postFile(this.deps.replyTarget, args);
41
+ }
42
+ /** Read the conversation's messages (returns `[]` when the adapter can't read history). */
43
+ async getMessages() {
44
+ return (await this.deps.adapter.getMessages?.(this.deps.replyTarget)) ?? [];
45
+ }
46
+ /** Resolve a platform user by free-form query (returns `undefined` when unsupported). */
47
+ async lookupUser(query) {
48
+ return this.deps.adapter.lookupUser?.({ query });
49
+ }
50
+ /** Post a picker and wait until an interaction in this conversation resolves it. */
51
+ async awaitChoice(ui) {
52
+ const p = new Promise((resolve) => this.deps.registerWaiter(this.deps.conversationKey, resolve));
53
+ await this.post(ui);
54
+ return p;
55
+ }
56
+ async runAgent(input) {
57
+ return this.run(undefined, input);
58
+ }
59
+ async resume(value) {
60
+ return this.run({ resume: value });
61
+ }
62
+ async run(initialResume, extra) {
63
+ const session = await this.deps.adapter.conversationStore.getOrCreate(this.deps.conversationKey, this.deps.replyTarget, this.deps.agentFactory);
64
+ // Inject an explicit user message when the input isn't in the adapter's
65
+ // reconstructed history (e.g. a slash command's args).
66
+ if (extra?.prompt) {
67
+ session.agent.addMessage({
68
+ id: globalThis.crypto.randomUUID(),
69
+ role: "user",
70
+ content: extra.prompt,
71
+ });
72
+ }
73
+ const renderer = this.deps.adapter.createRunRenderer(this.deps.replyTarget);
74
+ // Merge per-run context/tools (this run only) on top of the bot-level deps.
75
+ const extraTools = extra?.tools ?? [];
76
+ let tools = this.deps.tools;
77
+ let toolDescriptors = this.deps.toolDescriptors;
78
+ if (extraTools.length > 0) {
79
+ tools = new Map(this.deps.tools);
80
+ for (const t of extraTools)
81
+ tools.set(t.name, t);
82
+ toolDescriptors = [
83
+ ...this.deps.toolDescriptors,
84
+ ...toAgentToolDescriptors(extraTools),
85
+ ];
86
+ }
87
+ const context = extra?.context?.length
88
+ ? [...this.deps.context, ...extra.context]
89
+ : this.deps.context;
90
+ await runAgentLoop({
91
+ agent: session.agent,
92
+ renderer,
93
+ tools,
94
+ toolDescriptors,
95
+ context,
96
+ makeToolCtx: () => ({
97
+ thread: this,
98
+ platform: this.platform,
99
+ }),
100
+ handleInterrupt: async (interrupt) => {
101
+ const h = this.deps.interruptHandlers.get(interrupt.eventName);
102
+ if (h)
103
+ await h({ payload: interrupt.value, thread: this });
104
+ },
105
+ initialResume,
106
+ });
107
+ return undefined;
108
+ }
109
+ }
@@ -0,0 +1,67 @@
1
+ import type { InferSchemaOutput, ObjectSchema } from "./standard-schema.js";
2
+ import { validateSchema } from "./standard-schema.js";
3
+ import type { Thread, IncomingMessage, PlatformUser } from "@copilotkit/bot-ui";
4
+ export type { ObjectSchema } from "./standard-schema.js";
5
+ export interface BotToolContext {
6
+ thread: Thread;
7
+ message?: IncomingMessage;
8
+ user?: PlatformUser;
9
+ signal?: AbortSignal;
10
+ platform: string;
11
+ }
12
+ export type BotTool<Schema extends ObjectSchema = ObjectSchema> = {
13
+ name: string;
14
+ description: string;
15
+ parameters: Schema;
16
+ /**
17
+ * Run the tool. The returned value is what the **agent (LLM)** reads back as
18
+ * the tool result — not the end user.
19
+ *
20
+ * Return any value: a `string` is sent to the agent as-is; `null`/`undefined`
21
+ * becomes an empty string; any other value is JSON-stringified automatically
22
+ * (see {@link stringifyHandlerResult}). Do NOT hand-stringify and do NOT
23
+ * return boilerplate like `{ ok: true }`.
24
+ *
25
+ * Return something MEANINGFUL to the model:
26
+ * - a render tool (one that posts a card via `thread.post`) → a short
27
+ * natural-language confirmation (e.g. `"Displayed the issue card to the
28
+ * user."`) so the model gives a brief ack and doesn't restate the card;
29
+ * - a failure → the actual error text so the model can repair and retry;
30
+ * - a data tool → the data itself (return the raw object/array — the SDK
31
+ * serializes it for you).
32
+ */
33
+ handler(args: InferSchemaOutput<Schema>, ctx: BotToolContext): Promise<unknown> | unknown;
34
+ };
35
+ /**
36
+ * Define a {@link BotTool} with full type inference. The handler's `args` are
37
+ * inferred from `parameters`, and `ctx` is the generic {@link BotToolContext}
38
+ * ({@link Thread} + optional message/user/signal + platform). Reach for
39
+ * platform power via capability-gated `thread` methods (e.g.
40
+ * `thread.getMessages()`, `thread.lookupUser(query)`).
41
+ *
42
+ * ```ts
43
+ * const tool = defineBotTool({
44
+ * name: "show_thing",
45
+ * description: "...",
46
+ * parameters: z.object({ id: z.string() }),
47
+ * async handler({ id }, { thread }) { // `id` and `ctx` fully typed
48
+ * await thread.post(<Thing id={id} />);
49
+ * return "Displayed the thing.";
50
+ * },
51
+ * });
52
+ * ```
53
+ */
54
+ export declare function defineBotTool<Schema extends ObjectSchema>(tool: BotTool<Schema>): BotTool<Schema>;
55
+ export interface ContextEntry {
56
+ description: string;
57
+ value: string;
58
+ }
59
+ export interface AgentToolDescriptor {
60
+ name: string;
61
+ description: string;
62
+ parameters: Record<string, unknown>;
63
+ }
64
+ export declare function toAgentToolDescriptors(tools: ReadonlyArray<BotTool>): AgentToolDescriptor[];
65
+ export declare const parseToolArgs: typeof validateSchema;
66
+ export declare function stringifyHandlerResult(value: unknown): string;
67
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAgB,cAAc,EAAE,MAAM,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AAK,EAAE,OAAO,GAAG,MAAM,CAI7D"}
package/dist/tools.js ADDED
@@ -0,0 +1,38 @@
1
+ import { toJsonSchema, validateSchema } from "./standard-schema.js";
2
+ /**
3
+ * Define a {@link BotTool} with full type inference. The handler's `args` are
4
+ * inferred from `parameters`, and `ctx` is the generic {@link BotToolContext}
5
+ * ({@link Thread} + optional message/user/signal + platform). Reach for
6
+ * platform power via capability-gated `thread` methods (e.g.
7
+ * `thread.getMessages()`, `thread.lookupUser(query)`).
8
+ *
9
+ * ```ts
10
+ * const tool = defineBotTool({
11
+ * name: "show_thing",
12
+ * description: "...",
13
+ * parameters: z.object({ id: z.string() }),
14
+ * async handler({ id }, { thread }) { // `id` and `ctx` fully typed
15
+ * await thread.post(<Thing id={id} />);
16
+ * return "Displayed the thing.";
17
+ * },
18
+ * });
19
+ * ```
20
+ */
21
+ export function defineBotTool(tool) {
22
+ return tool;
23
+ }
24
+ export function toAgentToolDescriptors(tools) {
25
+ return tools.map((t) => ({
26
+ name: t.name,
27
+ description: t.description,
28
+ parameters: toJsonSchema(t.parameters),
29
+ }));
30
+ }
31
+ export const parseToolArgs = validateSchema;
32
+ export function stringifyHandlerResult(value) {
33
+ if (value == null)
34
+ return "";
35
+ if (typeof value === "string")
36
+ return value;
37
+ return JSON.stringify(value);
38
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tools.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.test.d.ts","sourceRoot":"","sources":["../src/tools.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { z } from "zod";
3
+ import { toAgentToolDescriptors, parseToolArgs, stringifyHandlerResult, } from "./tools.js";
4
+ describe("tools", () => {
5
+ const tool = {
6
+ name: "t",
7
+ description: "d",
8
+ parameters: z.object({ q: z.string() }),
9
+ handler: () => "ok",
10
+ };
11
+ it("emits JSON-schema descriptor", () => {
12
+ const descriptors = toAgentToolDescriptors([tool]);
13
+ const d = descriptors[0];
14
+ if (!d)
15
+ throw new Error("expected a descriptor");
16
+ expect(d.name).toBe("t");
17
+ expect(d.parameters.type).toBe("object");
18
+ });
19
+ it("parses valid and rejects invalid args", async () => {
20
+ expect(await parseToolArgs(tool.parameters, { q: "x" })).toEqual({
21
+ ok: true,
22
+ value: { q: "x" },
23
+ });
24
+ expect((await parseToolArgs(tool.parameters, {})).ok).toBe(false);
25
+ });
26
+ it("stringifies handler results", () => {
27
+ expect(stringifyHandlerResult("s")).toBe("s");
28
+ expect(stringifyHandlerResult({ a: 1 })).toBe('{"a":1}');
29
+ expect(stringifyHandlerResult(undefined)).toBe("");
30
+ });
31
+ });
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@copilotkit/bot",
3
+ "version": "0.0.1",
4
+ "description": "Platform-agnostic JSX bot engine for CopilotKit (createBot, Thread, PlatformAdapter, ActionStore).",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/CopilotKit/CopilotKit.git"
9
+ },
10
+ "homepage": "https://github.com/CopilotKit/CopilotKit",
11
+ "keywords": [
12
+ "ai",
13
+ "agent",
14
+ "bot",
15
+ "chatbot",
16
+ "copilotkit",
17
+ "slack",
18
+ "teams",
19
+ "discord",
20
+ "ag-ui"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "type": "module",
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "dependencies": {
38
+ "@ag-ui/client": "0.0.53",
39
+ "@ag-ui/core": "0.0.53",
40
+ "zod-to-json-schema": "^3.24.1",
41
+ "@copilotkit/bot-ui": "~0.0.1",
42
+ "@copilotkit/shared": "^1.59.5",
43
+ "@copilotkit/core": "^1.59.5"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^22.10.0",
47
+ "typescript": "^5.6.3",
48
+ "vitest": "^4.1.3",
49
+ "zod": "^3.25.76",
50
+ "@copilotkit/typescript-config": "^1.55.0-next.8"
51
+ },
52
+ "scripts": {
53
+ "build": "tsc -p tsconfig.json",
54
+ "check-types": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.check.json",
55
+ "test": "vitest run",
56
+ "test:watch": "vitest",
57
+ "publint": "publint .",
58
+ "attw": "attw --pack . --profile esm-only"
59
+ }
60
+ }