@copilotkit/channels-core 0.1.1 → 0.2.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.
- package/dist/create-channel.d.ts.map +1 -1
- package/dist/create-channel.js +10 -3
- package/dist/platform-adapter.d.ts +9 -0
- package/dist/platform-adapter.d.ts.map +1 -1
- package/dist/reactions.test.js +20 -0
- package/package.json +4 -4
- package/dist/create-bot.d.ts +0 -171
- package/dist/create-bot.d.ts.map +0 -1
- package/dist/create-bot.foundations.test.d.ts +0 -2
- package/dist/create-bot.foundations.test.d.ts.map +0 -1
- package/dist/create-bot.foundations.test.js +0 -147
- package/dist/create-bot.js +0 -579
- package/dist/create-bot.test.d.ts +0 -2
- package/dist/create-bot.test.d.ts.map +0 -1
- package/dist/create-bot.test.js +0 -936
- package/dist/telemetry/bot-telemetry.d.ts +0 -31
- package/dist/telemetry/bot-telemetry.d.ts.map +0 -1
- package/dist/telemetry/bot-telemetry.js +0 -70
- package/dist/telemetry/bot-telemetry.test.d.ts +0 -2
- package/dist/telemetry/bot-telemetry.test.d.ts.map +0 -1
- package/dist/telemetry/bot-telemetry.test.js +0 -56
- package/dist/telemetry/create-bot-telemetry.test.d.ts +0 -2
- package/dist/telemetry/create-bot-telemetry.test.d.ts.map +0 -1
- package/dist/telemetry/create-bot-telemetry.test.js +0 -71
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { LambdaSendOptions } from "@copilotkit/shared";
|
|
2
|
-
import type { StateStore } from "../state/state-store.js";
|
|
3
|
-
export declare const BOT_TELEMETRY_EVENTS: readonly ["oss.bot.configured", "oss.bot.started", "oss.bot.start_failed", "oss.bot.agent_run", "oss.bot.agent_run_failed"];
|
|
4
|
-
export type BotTelemetryEvent = (typeof BOT_TELEMETRY_EVENTS)[number];
|
|
5
|
-
export declare function isTestEnv(): boolean;
|
|
6
|
-
export declare function resolveEnvironment(): string;
|
|
7
|
-
export interface BotTelemetryOptions {
|
|
8
|
-
backend: StateStore;
|
|
9
|
-
packageName: string;
|
|
10
|
-
packageVersion: string;
|
|
11
|
-
environment?: string;
|
|
12
|
-
disabled?: boolean;
|
|
13
|
-
sessionId?: string;
|
|
14
|
-
send?: (o: LambdaSendOptions) => Promise<void>;
|
|
15
|
-
resolveId?: () => Promise<string>;
|
|
16
|
-
}
|
|
17
|
-
export declare class BotTelemetry {
|
|
18
|
-
private readonly opts;
|
|
19
|
-
private readonly disabled;
|
|
20
|
-
private readonly sendFn;
|
|
21
|
-
private readonly sessionId;
|
|
22
|
-
private readonly environment;
|
|
23
|
-
private readonly resolveId;
|
|
24
|
-
private idPromise?;
|
|
25
|
-
private static disclosed;
|
|
26
|
-
constructor(opts: BotTelemetryOptions);
|
|
27
|
-
capture(event: BotTelemetryEvent, properties: Record<string, unknown>): void;
|
|
28
|
-
private disclose;
|
|
29
|
-
private dispatch;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=bot-telemetry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bot-telemetry.d.ts","sourceRoot":"","sources":["../../src/telemetry/bot-telemetry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG1D,eAAO,MAAM,oBAAoB,6HAMvB,CAAC;AACX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,wBAAgB,SAAS,IAAI,OAAO,CAGnC;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAI3C;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,UAAU,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CACnC;AAED,qBAAa,YAAY;IASX,OAAO,CAAC,QAAQ,CAAC,IAAI;IARjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0C;IACjE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwB;IAClD,OAAO,CAAC,SAAS,CAAC,CAAkB;IACpC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAS;gBAEJ,IAAI,EAAE,mBAAmB;IAStD,OAAO,CAAC,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAM5E,OAAO,CAAC,QAAQ;YAQF,QAAQ;CAsBvB"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { lambdaClient, isTelemetryDisabled } from "@copilotkit/shared";
|
|
2
|
-
import { resolveInstallId } from "./install-id.js";
|
|
3
|
-
export const BOT_TELEMETRY_EVENTS = [
|
|
4
|
-
"oss.bot.configured",
|
|
5
|
-
"oss.bot.started",
|
|
6
|
-
"oss.bot.start_failed",
|
|
7
|
-
"oss.bot.agent_run",
|
|
8
|
-
"oss.bot.agent_run_failed",
|
|
9
|
-
];
|
|
10
|
-
export function isTestEnv() {
|
|
11
|
-
const env = process.env;
|
|
12
|
-
return env.NODE_ENV === "test" || !!env.VITEST || !!env.JEST_WORKER_ID;
|
|
13
|
-
}
|
|
14
|
-
export function resolveEnvironment() {
|
|
15
|
-
const e = (process.env.NODE_ENV ?? "").toLowerCase();
|
|
16
|
-
if (e === "production" || e === "development" || e === "test")
|
|
17
|
-
return e;
|
|
18
|
-
return "unknown";
|
|
19
|
-
}
|
|
20
|
-
export class BotTelemetry {
|
|
21
|
-
opts;
|
|
22
|
-
disabled;
|
|
23
|
-
sendFn;
|
|
24
|
-
sessionId;
|
|
25
|
-
environment;
|
|
26
|
-
resolveId;
|
|
27
|
-
idPromise;
|
|
28
|
-
static disclosed = false;
|
|
29
|
-
constructor(opts) {
|
|
30
|
-
this.opts = opts;
|
|
31
|
-
this.disabled = opts.disabled ?? (isTelemetryDisabled() || isTestEnv());
|
|
32
|
-
this.sendFn = opts.send ?? lambdaClient.send;
|
|
33
|
-
this.sessionId = opts.sessionId ?? globalThis.crypto.randomUUID();
|
|
34
|
-
this.environment = opts.environment ?? resolveEnvironment();
|
|
35
|
-
this.resolveId =
|
|
36
|
-
opts.resolveId ?? (() => resolveInstallId({ backend: opts.backend }));
|
|
37
|
-
}
|
|
38
|
-
capture(event, properties) {
|
|
39
|
-
if (this.disabled)
|
|
40
|
-
return;
|
|
41
|
-
this.disclose();
|
|
42
|
-
void this.dispatch(event, properties);
|
|
43
|
-
}
|
|
44
|
-
disclose() {
|
|
45
|
-
if (BotTelemetry.disclosed)
|
|
46
|
-
return;
|
|
47
|
-
BotTelemetry.disclosed = true;
|
|
48
|
-
console.info("[CopilotKit Bot] anonymous telemetry enabled — see https://docs.copilotkit.ai/telemetry to opt out (set COPILOTKIT_TELEMETRY_DISABLED=true).");
|
|
49
|
-
}
|
|
50
|
-
async dispatch(event, properties) {
|
|
51
|
-
try {
|
|
52
|
-
this.idPromise ??= this.resolveId();
|
|
53
|
-
const anonymous_id = await this.idPromise;
|
|
54
|
-
await this.sendFn({
|
|
55
|
-
event,
|
|
56
|
-
properties,
|
|
57
|
-
globalProperties: {
|
|
58
|
-
anonymous_id,
|
|
59
|
-
bot_session_id: this.sessionId,
|
|
60
|
-
environment: this.environment,
|
|
61
|
-
},
|
|
62
|
-
packageName: this.opts.packageName,
|
|
63
|
-
packageVersion: this.opts.packageVersion,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
/* best-effort: telemetry must not break the host app */
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bot-telemetry.test.d.ts","sourceRoot":"","sources":["../../src/telemetry/bot-telemetry.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { BotTelemetry, BOT_TELEMETRY_EVENTS } from "./bot-telemetry.js";
|
|
3
|
-
import { MemoryStore } from "../state/memory-store.js";
|
|
4
|
-
const tick = () => new Promise((r) => setTimeout(r, 0));
|
|
5
|
-
const base = {
|
|
6
|
-
backend: new MemoryStore(),
|
|
7
|
-
packageName: "@copilotkit/channels",
|
|
8
|
-
packageVersion: "0.0.3",
|
|
9
|
-
};
|
|
10
|
-
describe("BotTelemetry", () => {
|
|
11
|
-
it("sends event with anonymous_id + bot_session_id in global_properties", async () => {
|
|
12
|
-
const send = vi.fn().mockResolvedValue(undefined);
|
|
13
|
-
const t = new BotTelemetry({
|
|
14
|
-
...base,
|
|
15
|
-
disabled: false,
|
|
16
|
-
send,
|
|
17
|
-
sessionId: "S1",
|
|
18
|
-
resolveId: async () => "ANON",
|
|
19
|
-
});
|
|
20
|
-
t.capture("oss.bot.configured", { platforms: ["slack"] });
|
|
21
|
-
await tick();
|
|
22
|
-
expect(send).toHaveBeenCalledTimes(1);
|
|
23
|
-
const arg = send.mock.calls[0][0];
|
|
24
|
-
expect(arg.event).toBe("oss.bot.configured");
|
|
25
|
-
expect(arg.properties).toEqual({ platforms: ["slack"] });
|
|
26
|
-
expect(arg.globalProperties.anonymous_id).toBe("ANON");
|
|
27
|
-
expect(arg.globalProperties.bot_session_id).toBe("S1");
|
|
28
|
-
});
|
|
29
|
-
it("is a no-op when disabled", async () => {
|
|
30
|
-
const send = vi.fn();
|
|
31
|
-
const t = new BotTelemetry({ ...base, disabled: true, send });
|
|
32
|
-
t.capture("oss.bot.started", {});
|
|
33
|
-
await tick();
|
|
34
|
-
expect(send).not.toHaveBeenCalled();
|
|
35
|
-
});
|
|
36
|
-
it("never throws when send rejects", async () => {
|
|
37
|
-
const send = vi.fn().mockRejectedValue(new Error("boom"));
|
|
38
|
-
const t = new BotTelemetry({
|
|
39
|
-
...base,
|
|
40
|
-
disabled: false,
|
|
41
|
-
send,
|
|
42
|
-
resolveId: async () => "X",
|
|
43
|
-
});
|
|
44
|
-
expect(() => t.capture("oss.bot.agent_run", {})).not.toThrow();
|
|
45
|
-
await tick();
|
|
46
|
-
});
|
|
47
|
-
it("exposes the five event names", () => {
|
|
48
|
-
expect([...BOT_TELEMETRY_EVENTS].sort()).toEqual([
|
|
49
|
-
"oss.bot.agent_run",
|
|
50
|
-
"oss.bot.agent_run_failed",
|
|
51
|
-
"oss.bot.configured",
|
|
52
|
-
"oss.bot.start_failed",
|
|
53
|
-
"oss.bot.started",
|
|
54
|
-
]);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-bot-telemetry.test.d.ts","sourceRoot":"","sources":["../../src/telemetry/create-bot-telemetry.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
const capture = vi.fn();
|
|
3
|
-
vi.mock("./bot-telemetry.js", () => ({
|
|
4
|
-
// A `function` (not an arrow) so `new BotTelemetry(...)` in create-bot.ts is
|
|
5
|
-
// constructible under vitest's mock — an arrow implementation throws
|
|
6
|
-
// "is not a constructor".
|
|
7
|
-
BotTelemetry: vi.fn().mockImplementation(function () {
|
|
8
|
-
return { capture };
|
|
9
|
-
}),
|
|
10
|
-
BOT_TELEMETRY_EVENTS: [],
|
|
11
|
-
}));
|
|
12
|
-
import { createBot } from "../create-bot.js";
|
|
13
|
-
import { FakeAdapter } from "../testing/fake-adapter.js";
|
|
14
|
-
import { FakeAgent } from "../testing/fake-agent.js";
|
|
15
|
-
import { Section } from "@copilotkit/channels-ui";
|
|
16
|
-
const tick = () => new Promise((r) => setTimeout(r, 0));
|
|
17
|
-
describe("createBot telemetry wiring", () => {
|
|
18
|
-
beforeEach(() => capture.mockClear());
|
|
19
|
-
it("emits oss.bot.configured with a config snapshot", async () => {
|
|
20
|
-
// The config snapshot is captured at start() — the backend (and therefore
|
|
21
|
-
// telemetry) is resolved there, not at construction, so an adapter attached
|
|
22
|
-
// via addAdapter can still provide the persistence backend.
|
|
23
|
-
const bot = createBot({
|
|
24
|
-
adapters: [new FakeAdapter()],
|
|
25
|
-
components: [
|
|
26
|
-
function Card() {
|
|
27
|
-
return Section({ children: "x" });
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
});
|
|
31
|
-
await bot.start();
|
|
32
|
-
const call = capture.mock.calls.find((c) => c[0] === "oss.bot.configured");
|
|
33
|
-
expect(call).toBeDefined();
|
|
34
|
-
expect(call[1].platforms).toEqual(["custom"]); // FakeAdapter.platform "fake" → normalized
|
|
35
|
-
expect(call[1].store).toBe("memory");
|
|
36
|
-
expect(call[1].hasComponents).toBe(true);
|
|
37
|
-
});
|
|
38
|
-
it("emits oss.bot.started on start, start_failed (category only) on a throwing adapter", async () => {
|
|
39
|
-
const ok = new FakeAdapter();
|
|
40
|
-
const bot = createBot({ adapters: [ok] });
|
|
41
|
-
await bot.start();
|
|
42
|
-
expect(capture.mock.calls.find((c) => c[0] === "oss.bot.started")?.[1]
|
|
43
|
-
.startedCount).toBe(1);
|
|
44
|
-
capture.mockClear();
|
|
45
|
-
const bad = new FakeAdapter();
|
|
46
|
-
bad.start = () => Promise.reject(Object.assign(new Error("xoxb-SECRET token bad"), { code: "EAUTH" }));
|
|
47
|
-
const bot2 = createBot({ adapters: [bad] });
|
|
48
|
-
await bot2.start();
|
|
49
|
-
const f = capture.mock.calls.find((c) => c[0] === "oss.bot.start_failed");
|
|
50
|
-
expect(f).toBeDefined();
|
|
51
|
-
expect(f[1].errorClass).toBe("auth");
|
|
52
|
-
expect(JSON.stringify(f[1])).not.toContain("SECRET");
|
|
53
|
-
});
|
|
54
|
-
it("emits oss.bot.agent_run on a successful run", async () => {
|
|
55
|
-
const fake = new FakeAdapter();
|
|
56
|
-
const bot = createBot({ adapters: [fake], agent: () => new FakeAgent() });
|
|
57
|
-
bot.onMention(async ({ thread }) => {
|
|
58
|
-
await thread.runAgent();
|
|
59
|
-
});
|
|
60
|
-
await bot.start();
|
|
61
|
-
capture.mockClear();
|
|
62
|
-
fake.emitTurn({ userText: "hi", conversationKey: "c1" });
|
|
63
|
-
await tick();
|
|
64
|
-
await tick();
|
|
65
|
-
const run = capture.mock.calls.find((c) => c[0] === "oss.bot.agent_run");
|
|
66
|
-
expect(run).toBeDefined();
|
|
67
|
-
expect(run[1].platform).toBe("custom"); // "fake" → normalized
|
|
68
|
-
expect(typeof run[1].durationMs).toBe("number");
|
|
69
|
-
expect(run[1].interrupted).toBe(false);
|
|
70
|
-
});
|
|
71
|
-
});
|