copilotkit 0.0.41 ā 0.0.42-alpha.0
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/commands/base-command.js +1 -1
- package/dist/commands/base-command.js.map +1 -1
- package/dist/commands/dev.js +51 -11
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/init.d.ts +14 -0
- package/dist/commands/init.js +356 -27
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.js +50 -10
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.js +50 -10
- package/dist/commands/logout.js.map +1 -1
- package/dist/lib/init/index.js +21 -1
- package/dist/lib/init/index.js.map +1 -1
- package/dist/lib/init/questions.js +21 -1
- package/dist/lib/init/questions.js.map +1 -1
- package/dist/lib/init/scaffold/index.js +6 -0
- package/dist/lib/init/scaffold/index.js.map +1 -1
- package/dist/lib/init/scaffold/shadcn.js +6 -0
- package/dist/lib/init/scaffold/shadcn.js.map +1 -1
- package/dist/lib/init/types/index.js +6 -0
- package/dist/lib/init/types/index.js.map +1 -1
- package/dist/lib/init/types/questions.d.ts +14 -6
- package/dist/lib/init/types/questions.js +6 -0
- package/dist/lib/init/types/questions.js.map +1 -1
- package/dist/services/analytics.service.d.ts +9 -0
- package/dist/services/analytics.service.js +33 -0
- package/dist/services/analytics.service.js.map +1 -1
- package/dist/services/auth.service.d.ts +1 -1
- package/dist/services/auth.service.js +49 -9
- package/dist/services/auth.service.js.map +1 -1
- package/dist/services/events.d.ts +43 -0
- package/dist/utils/version.d.ts +1 -1
- package/dist/utils/version.js +1 -1
- package/dist/utils/version.js.map +1 -1
- package/oclif.manifest.json +12 -1
- package/package.json +2 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/services/analytics.service.ts
|
|
2
2
|
import { Analytics } from "@segment/analytics-node";
|
|
3
|
+
import { PostHog } from "posthog-node";
|
|
3
4
|
import Conf from "conf";
|
|
4
5
|
var AnalyticsService = class {
|
|
5
6
|
constructor(authData) {
|
|
@@ -25,12 +26,20 @@ var AnalyticsService = class {
|
|
|
25
26
|
writeKey: segmentWriteKey,
|
|
26
27
|
disable: process.env.SEGMENT_DISABLE === "true"
|
|
27
28
|
});
|
|
29
|
+
if (process.env.POSTHOG_DISABLED !== "true") {
|
|
30
|
+
const posthogKey = process.env.POSTHOG_KEY || "phc_XZdymVYjrph9Mi0xZYGNyCKexxgblXRR1jMENCtdz5Q";
|
|
31
|
+
const posthogHost = process.env.POSTHOG_HOST || "https://eu.i.posthog.com";
|
|
32
|
+
this.posthog = new PostHog(posthogKey, {
|
|
33
|
+
host: posthogHost
|
|
34
|
+
});
|
|
35
|
+
}
|
|
28
36
|
const config = new Conf({ projectName: "CopilotKitCLI" });
|
|
29
37
|
if (!config.get("anonymousId")) {
|
|
30
38
|
config.set("anonymousId", crypto.randomUUID());
|
|
31
39
|
}
|
|
32
40
|
}
|
|
33
41
|
segment;
|
|
42
|
+
posthog;
|
|
34
43
|
globalProperties = {};
|
|
35
44
|
userId;
|
|
36
45
|
email;
|
|
@@ -75,6 +84,30 @@ var AnalyticsService = class {
|
|
|
75
84
|
});
|
|
76
85
|
});
|
|
77
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if a feature flag is enabled
|
|
89
|
+
*/
|
|
90
|
+
async isFeatureEnabled(flagKey) {
|
|
91
|
+
if (!this.posthog) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const distinctId = this.userId || this.getAnonymousId();
|
|
96
|
+
const flag = await this.posthog.isFeatureEnabled(flagKey, distinctId);
|
|
97
|
+
return Boolean(flag);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.warn(`Failed to check feature flag ${flagKey}:`, error);
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Shutdown analytics services
|
|
105
|
+
*/
|
|
106
|
+
async shutdown() {
|
|
107
|
+
if (this.posthog) {
|
|
108
|
+
await this.posthog.shutdown();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
78
111
|
};
|
|
79
112
|
export {
|
|
80
113
|
AnalyticsService
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/services/analytics.service.ts"],"sourcesContent":["import {Analytics} from '@segment/analytics-node'\nimport {AnalyticsEvents} from './events.js'\nimport Conf from 'conf'\n\nexport class AnalyticsService {\n private segment: Analytics | undefined\n private globalProperties: Record<string, any> = {}\n private userId: string | undefined\n private email: string | undefined\n private organizationId: string | undefined\n private config = new Conf({projectName: 'CopilotKitCLI'})\n\n constructor(\n private readonly authData?: {\n userId: string\n email: string\n organizationId: string\n },\n ) {\n if (process.env.SEGMENT_DISABLED === 'true') {\n return\n }\n\n const segmentWriteKey = process.env.SEGMENT_WRITE_KEY || '9Pv6QyExYef2P4hPz4gks6QAvNMi2AOf'\n\n this.globalProperties = {\n service: 'cli',\n }\n\n if (this.authData?.userId) {\n this.userId = this.authData.userId\n }\n\n if (this.authData?.email) {\n this.email = this.authData.email\n this.globalProperties.email = this.authData.email\n }\n\n if (this.authData?.organizationId) {\n this.organizationId = this.authData.organizationId\n }\n\n this.segment = new Analytics({\n writeKey: segmentWriteKey,\n disable: process.env.SEGMENT_DISABLE === 'true',\n })\n\n const config = new Conf({projectName: 'CopilotKitCLI'})\n if (!config.get('anonymousId')) {\n config.set('anonymousId', crypto.randomUUID())\n }\n }\n\n private getAnonymousId(): string {\n const anonymousId = this.config.get('anonymousId')\n if (!anonymousId) {\n const anonymousId = crypto.randomUUID()\n this.config.set('anonymousId', anonymousId)\n return anonymousId\n }\n\n return anonymousId as string\n }\n\n public track<K extends keyof AnalyticsEvents>(\n event: Omit<Parameters<Analytics['track']>[0], 'userId'> & {\n event: K\n properties: AnalyticsEvents[K]\n },\n ): Promise<void> {\n if (!this.segment) {\n return Promise.resolve()\n }\n\n const payload = {\n userId: this.userId ? this.userId : undefined,\n email: this.email ? this.email : undefined,\n anonymousId: this.getAnonymousId(),\n event: event.event,\n properties: {\n ...this.globalProperties,\n ...event.properties,\n $groups: this.organizationId\n ? {\n segment_group: this.organizationId,\n }\n : undefined,\n eventProperties: {\n ...event.properties,\n ...this.globalProperties,\n },\n },\n }\n\n return new Promise((resolve, reject) => {\n this.segment!.track(payload, (err) => {\n if (err) {\n // Resolve anyway\n resolve()\n }\n\n resolve()\n })\n })\n }\n}\n"],"mappings":";AAAA,SAAQ,iBAAgB;
|
|
1
|
+
{"version":3,"sources":["../../src/services/analytics.service.ts"],"sourcesContent":["import {Analytics} from '@segment/analytics-node'\nimport {PostHog} from 'posthog-node'\nimport {AnalyticsEvents} from './events.js'\nimport Conf from 'conf'\n\nexport class AnalyticsService {\n private segment: Analytics | undefined\n private posthog: PostHog | undefined\n private globalProperties: Record<string, any> = {}\n private userId: string | undefined\n private email: string | undefined\n private organizationId: string | undefined\n private config = new Conf({projectName: 'CopilotKitCLI'})\n\n constructor(\n private readonly authData?: {\n userId: string\n email: string\n organizationId: string\n },\n ) {\n if (process.env.SEGMENT_DISABLED === 'true') {\n return\n }\n\n const segmentWriteKey = process.env.SEGMENT_WRITE_KEY || '9Pv6QyExYef2P4hPz4gks6QAvNMi2AOf'\n\n this.globalProperties = {\n service: 'cli',\n }\n\n if (this.authData?.userId) {\n this.userId = this.authData.userId\n }\n\n if (this.authData?.email) {\n this.email = this.authData.email\n this.globalProperties.email = this.authData.email\n }\n\n if (this.authData?.organizationId) {\n this.organizationId = this.authData.organizationId\n }\n\n this.segment = new Analytics({\n writeKey: segmentWriteKey,\n disable: process.env.SEGMENT_DISABLE === 'true',\n })\n\n // Initialize PostHog for feature flags\n if (process.env.POSTHOG_DISABLED !== 'true') {\n const posthogKey = process.env.POSTHOG_KEY || 'phc_XZdymVYjrph9Mi0xZYGNyCKexxgblXRR1jMENCtdz5Q' // Default key\n const posthogHost = process.env.POSTHOG_HOST || 'https://eu.i.posthog.com'\n\n this.posthog = new PostHog(posthogKey, {\n host: posthogHost,\n })\n }\n\n const config = new Conf({projectName: 'CopilotKitCLI'})\n if (!config.get('anonymousId')) {\n config.set('anonymousId', crypto.randomUUID())\n }\n }\n\n private getAnonymousId(): string {\n const anonymousId = this.config.get('anonymousId')\n if (!anonymousId) {\n const anonymousId = crypto.randomUUID()\n this.config.set('anonymousId', anonymousId)\n return anonymousId\n }\n\n return anonymousId as string\n }\n\n public track<K extends keyof AnalyticsEvents>(\n event: Omit<Parameters<Analytics['track']>[0], 'userId'> & {\n event: K\n properties: AnalyticsEvents[K]\n },\n ): Promise<void> {\n if (!this.segment) {\n return Promise.resolve()\n }\n\n const payload = {\n userId: this.userId ? this.userId : undefined,\n email: this.email ? this.email : undefined,\n anonymousId: this.getAnonymousId(),\n event: event.event,\n properties: {\n ...this.globalProperties,\n ...event.properties,\n $groups: this.organizationId\n ? {\n segment_group: this.organizationId,\n }\n : undefined,\n eventProperties: {\n ...event.properties,\n ...this.globalProperties,\n },\n },\n }\n\n return new Promise((resolve, reject) => {\n this.segment!.track(payload, (err) => {\n if (err) {\n // Resolve anyway\n resolve()\n }\n\n resolve()\n })\n })\n }\n\n /**\n * Check if a feature flag is enabled\n */\n public async isFeatureEnabled(flagKey: string): Promise<boolean> {\n if (!this.posthog) {\n return false\n }\n\n try {\n // Use authenticated user ID if available, otherwise use anonymous ID\n const distinctId = this.userId || this.getAnonymousId()\n const flag = await this.posthog.isFeatureEnabled(flagKey, distinctId)\n return Boolean(flag)\n } catch (error) {\n // If there's an error checking the flag, return false (flag disabled)\n console.warn(`Failed to check feature flag ${flagKey}:`, error)\n return false\n }\n }\n\n /**\n * Shutdown analytics services\n */\n public async shutdown(): Promise<void> {\n if (this.posthog) {\n await this.posthog.shutdown()\n }\n }\n}\n"],"mappings":";AAAA,SAAQ,iBAAgB;AACxB,SAAQ,eAAc;AAEtB,OAAO,UAAU;AAEV,IAAM,mBAAN,MAAuB;AAAA,EAS5B,YACmB,UAKjB;AALiB;AAMjB,QAAI,QAAQ,IAAI,qBAAqB,QAAQ;AA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AAC,KAAK,SAAS;AACjB,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAEA,UAAM,UAAU;AAAA,MACd,QAAQ,KAAK,SAAS,KAAK,SAAS;AAAA,MACpC,OAAO,KAAK,QAAQ,KAAK,QAAQ;AAAA,MACjC,aAAa,KAAK,eAAe;AAAA,MACjC,OAAO,MAAM;AAAA,MACb,YAAY;AAAA,QACV,GAAG,KAAK;AAAA,QACR,GAAG,MAAM;AAAA,QACT,SAAS,KAAK,iBACV;AAAA,UACE,eAAe,KAAK;AAAA,QACtB,IACA;AAAA,QACJ,iBAAiB;AAAA,UACf,GAAG,MAAM;AAAA,UACT,GAAG,KAAK;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAEA,WAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,WAAK,QAAS,MAAM,SAAS,CAAC,QAAQ;AACpC,YAAI,KAAK;AAEP,kBAAQ;AAAA,QACV;AAEA,gBAAQ;AAAA,MACV,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,iBAAiB,SAAmC;AAC/D,QAAI,CAAC,KAAK,SAAS;AACjB,aAAO;AAAA,IACT;AAEA,QAAI;AAEF,YAAM,aAAa,KAAK,UAAU,KAAK,eAAe;AACtD,YAAM,OAAO,MAAM,KAAK,QAAQ,iBAAiB,SAAS,UAAU;AACpE,aAAO,QAAQ,IAAI;AAAA,IACrB,SAAS,OAAO;AAEd,cAAQ,KAAK,gCAAgC,OAAO,KAAK,KAAK;AAC9D,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,WAA0B;AACrC,QAAI,KAAK,SAAS;AAChB,YAAM,KAAK,QAAQ,SAAS;AAAA,IAC9B;AAAA,EACF;AACF;","names":["anonymousId"]}
|
|
@@ -17,7 +17,7 @@ declare class AuthService {
|
|
|
17
17
|
getToken(): string | undefined;
|
|
18
18
|
getCLIToken(): string | undefined;
|
|
19
19
|
logout(cmd: BaseCommand): Promise<void>;
|
|
20
|
-
requireLogin(cmd: Command): Promise<LoginResponse>;
|
|
20
|
+
requireLogin(cmd: Command, context?: 'cloud-features' | 'general'): Promise<LoginResponse>;
|
|
21
21
|
login({ exitAfterLogin }?: {
|
|
22
22
|
exitAfterLogin?: boolean;
|
|
23
23
|
}): Promise<LoginResponse>;
|
|
@@ -32,6 +32,7 @@ function createTRPCClient(cliToken) {
|
|
|
32
32
|
|
|
33
33
|
// src/services/analytics.service.ts
|
|
34
34
|
import { Analytics } from "@segment/analytics-node";
|
|
35
|
+
import { PostHog } from "posthog-node";
|
|
35
36
|
import Conf from "conf";
|
|
36
37
|
var AnalyticsService = class {
|
|
37
38
|
constructor(authData) {
|
|
@@ -57,12 +58,20 @@ var AnalyticsService = class {
|
|
|
57
58
|
writeKey: segmentWriteKey,
|
|
58
59
|
disable: process.env.SEGMENT_DISABLE === "true"
|
|
59
60
|
});
|
|
61
|
+
if (process.env.POSTHOG_DISABLED !== "true") {
|
|
62
|
+
const posthogKey = process.env.POSTHOG_KEY || "phc_XZdymVYjrph9Mi0xZYGNyCKexxgblXRR1jMENCtdz5Q";
|
|
63
|
+
const posthogHost = process.env.POSTHOG_HOST || "https://eu.i.posthog.com";
|
|
64
|
+
this.posthog = new PostHog(posthogKey, {
|
|
65
|
+
host: posthogHost
|
|
66
|
+
});
|
|
67
|
+
}
|
|
60
68
|
const config = new Conf({ projectName: "CopilotKitCLI" });
|
|
61
69
|
if (!config.get("anonymousId")) {
|
|
62
70
|
config.set("anonymousId", crypto.randomUUID());
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
73
|
segment;
|
|
74
|
+
posthog;
|
|
66
75
|
globalProperties = {};
|
|
67
76
|
userId;
|
|
68
77
|
email;
|
|
@@ -107,6 +116,30 @@ var AnalyticsService = class {
|
|
|
107
116
|
});
|
|
108
117
|
});
|
|
109
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Check if a feature flag is enabled
|
|
121
|
+
*/
|
|
122
|
+
async isFeatureEnabled(flagKey) {
|
|
123
|
+
if (!this.posthog) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const distinctId = this.userId || this.getAnonymousId();
|
|
128
|
+
const flag = await this.posthog.isFeatureEnabled(flagKey, distinctId);
|
|
129
|
+
return Boolean(flag);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.warn(`Failed to check feature flag ${flagKey}:`, error);
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Shutdown analytics services
|
|
137
|
+
*/
|
|
138
|
+
async shutdown() {
|
|
139
|
+
if (this.posthog) {
|
|
140
|
+
await this.posthog.shutdown();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
110
143
|
};
|
|
111
144
|
|
|
112
145
|
// src/services/auth.service.ts
|
|
@@ -123,19 +156,26 @@ var AuthService = class {
|
|
|
123
156
|
async logout(cmd) {
|
|
124
157
|
this.config.delete("cliToken");
|
|
125
158
|
}
|
|
126
|
-
async requireLogin(cmd) {
|
|
159
|
+
async requireLogin(cmd, context) {
|
|
127
160
|
let cliToken = this.getCLIToken();
|
|
128
161
|
if (!cliToken) {
|
|
129
162
|
try {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
163
|
+
let shouldLogin = true;
|
|
164
|
+
if (context !== "cloud-features") {
|
|
165
|
+
const response = await inquirer.prompt([
|
|
166
|
+
{
|
|
167
|
+
name: "shouldLogin",
|
|
168
|
+
type: "confirm",
|
|
169
|
+
message: "\u{1FA81} You are not yet authenticated. Authenticate with Copilot Cloud? (press Enter to confirm)",
|
|
170
|
+
default: true
|
|
171
|
+
}
|
|
172
|
+
]);
|
|
173
|
+
shouldLogin = response.shouldLogin;
|
|
174
|
+
}
|
|
138
175
|
if (shouldLogin) {
|
|
176
|
+
if (context === "cloud-features") {
|
|
177
|
+
cmd.log(chalk.cyan("\n\u{1F680} Setting up Copilot Cloud authentication for your selected features...\n"));
|
|
178
|
+
}
|
|
139
179
|
const loginResult = await this.login({ exitAfterLogin: false });
|
|
140
180
|
cliToken = loginResult.cliToken;
|
|
141
181
|
return loginResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/services/auth.service.ts","../../src/utils/trpc.ts","../../src/services/analytics.service.ts"],"sourcesContent":["// @ts-ignore\nimport Conf from 'conf'\nimport cors from 'cors'\nimport express from 'express'\nimport crypto from 'node:crypto'\nimport open from 'open'\nimport getPort from 'get-port'\nimport ora from 'ora'\nimport chalk from 'chalk'\nimport inquirer from 'inquirer'\nimport {Command} from '@oclif/core'\nimport {createTRPCClient} from '../utils/trpc.js'\nimport {AnalyticsService} from '../services/analytics.service.js'\nimport {BaseCommand} from '../commands/base-command.js'\n\ninterface LoginResponse {\n cliToken: string\n user: {\n email: string\n id: string\n }\n organization: {\n id: string\n }\n}\n\nexport class AuthService {\n private readonly config = new Conf({projectName: 'CopilotKitCLI'})\n private readonly COPILOT_CLOUD_BASE_URL = process.env.COPILOT_CLOUD_BASE_URL || 'https://cloud.copilotkit.ai'\n\n getToken(): string | undefined {\n return this.config.get('cliToken') as string | undefined\n }\n\n getCLIToken(): string | undefined {\n const cliToken = this.config.get('cliToken') as string | undefined\n return cliToken\n }\n\n async logout(cmd: BaseCommand): Promise<void> {\n this.config.delete('cliToken')\n }\n\n async requireLogin(cmd: Command): Promise<LoginResponse> {\n let cliToken = this.getCLIToken()\n // Check authentication\n if (!cliToken) {\n try {\n const {shouldLogin} = await inquirer.prompt([\n {\n name: 'shouldLogin',\n type: 'confirm',\n message: 'šŖ You are not yet authenticated. Authenticate with Copilot Cloud? (press Enter to confirm)',\n default: true,\n },\n ])\n if (shouldLogin) {\n const loginResult = await this.login({exitAfterLogin: false})\n cliToken = loginResult.cliToken\n return loginResult\n } else {\n cmd.error('Authentication required to proceed.')\n }\n } catch (error) {\n if (error instanceof Error && error.name === 'ExitPromptError') {\n cmd.error(chalk.yellow('\\nAuthentication cancelled'))\n }\n\n throw error\n }\n }\n\n let me\n\n const trpcClient = createTRPCClient(cliToken)\n try {\n me = await trpcClient.me.query()\n } catch (error) {\n cmd.log(chalk.red('Could not authenticate with Copilot Cloud. Please run: npx copilotkit@latest login'))\n process.exit(1)\n }\n\n if (!me.organization || !me.user) {\n cmd.error('Authentication required to proceed.')\n }\n\n return {cliToken, user: me.user, organization: me.organization}\n }\n\n async login({exitAfterLogin}: {exitAfterLogin?: boolean} = {exitAfterLogin: true}): Promise<LoginResponse> {\n const spinner = ora('šŖ Opening browser for authentication...').start()\n let analytics: AnalyticsService\n analytics = new AnalyticsService()\n\n const app = express()\n app.use(cors())\n app.use(express.urlencoded({extended: true}))\n app.use(express.json())\n\n const port = await getPort()\n const state = crypto.randomBytes(16).toString('hex')\n\n return new Promise(async (resolve) => {\n const server = app.listen(port, () => {})\n\n await analytics.track({\n event: 'cli.login.initiated',\n properties: {},\n })\n\n spinner.text = 'šŖ Waiting for browser authentication to complete...'\n\n app.post('/callback', async (req, res) => {\n const {cliToken, user, organization} = req.body\n\n analytics = new AnalyticsService({userId: user.id, organizationId: organization.id, email: user.email})\n await analytics.track({\n event: 'cli.login.success',\n properties: {\n organizationId: organization.id,\n userId: user.id,\n email: user.email,\n },\n })\n\n if (state !== req.query.state) {\n res.status(401).json({message: 'Invalid state'})\n spinner.fail('Invalid state')\n return\n }\n\n this.config.set('cliToken', cliToken)\n res.status(200).json({message: 'Callback called'})\n spinner.succeed(`šŖ Successfully logged in as ${chalk.hex('#7553fc')(user.email)}`)\n if (exitAfterLogin) {\n process.exit(0)\n } else {\n server.close()\n resolve({cliToken, user, organization})\n }\n })\n\n open(`${this.COPILOT_CLOUD_BASE_URL}/cli-auth?callbackUrl=http://localhost:${port}/callback&state=${state}`)\n })\n }\n}\n","import {createTRPCClient as trpcClient, httpBatchLink} from '@trpc/client'\nimport superjson from 'superjson'\n\nexport const COPILOT_CLOUD_BASE_URL = process.env.COPILOT_CLOUD_BASE_URL || 'https://cloud.copilotkit.ai'\n\nexport function createTRPCClient(cliToken: string): any {\n return trpcClient({\n links: [\n httpBatchLink({\n url: `${COPILOT_CLOUD_BASE_URL}/api/trpc-cli`,\n transformer: superjson,\n headers: () => {\n return {\n 'x-trpc-source': 'cli',\n 'x-cli-token': cliToken,\n }\n },\n }),\n ],\n })\n}\n","import {Analytics} from '@segment/analytics-node'\nimport {AnalyticsEvents} from './events.js'\nimport Conf from 'conf'\n\nexport class AnalyticsService {\n private segment: Analytics | undefined\n private globalProperties: Record<string, any> = {}\n private userId: string | undefined\n private email: string | undefined\n private organizationId: string | undefined\n private config = new Conf({projectName: 'CopilotKitCLI'})\n\n constructor(\n private readonly authData?: {\n userId: string\n email: string\n organizationId: string\n },\n ) {\n if (process.env.SEGMENT_DISABLED === 'true') {\n return\n }\n\n const segmentWriteKey = process.env.SEGMENT_WRITE_KEY || '9Pv6QyExYef2P4hPz4gks6QAvNMi2AOf'\n\n this.globalProperties = {\n service: 'cli',\n }\n\n if (this.authData?.userId) {\n this.userId = this.authData.userId\n }\n\n if (this.authData?.email) {\n this.email = this.authData.email\n this.globalProperties.email = this.authData.email\n }\n\n if (this.authData?.organizationId) {\n this.organizationId = this.authData.organizationId\n }\n\n this.segment = new Analytics({\n writeKey: segmentWriteKey,\n disable: process.env.SEGMENT_DISABLE === 'true',\n })\n\n const config = new Conf({projectName: 'CopilotKitCLI'})\n if (!config.get('anonymousId')) {\n config.set('anonymousId', crypto.randomUUID())\n }\n }\n\n private getAnonymousId(): string {\n const anonymousId = this.config.get('anonymousId')\n if (!anonymousId) {\n const anonymousId = crypto.randomUUID()\n this.config.set('anonymousId', anonymousId)\n return anonymousId\n }\n\n return anonymousId as string\n }\n\n public track<K extends keyof AnalyticsEvents>(\n event: Omit<Parameters<Analytics['track']>[0], 'userId'> & {\n event: K\n properties: AnalyticsEvents[K]\n },\n ): Promise<void> {\n if (!this.segment) {\n return Promise.resolve()\n }\n\n const payload = {\n userId: this.userId ? this.userId : undefined,\n email: this.email ? this.email : undefined,\n anonymousId: this.getAnonymousId(),\n event: event.event,\n properties: {\n ...this.globalProperties,\n ...event.properties,\n $groups: this.organizationId\n ? {\n segment_group: this.organizationId,\n }\n : undefined,\n eventProperties: {\n ...event.properties,\n ...this.globalProperties,\n },\n },\n }\n\n return new Promise((resolve, reject) => {\n this.segment!.track(payload, (err) => {\n if (err) {\n // Resolve anyway\n resolve()\n }\n\n resolve()\n })\n })\n }\n}\n"],"mappings":";AACA,OAAOA,WAAU;AACjB,OAAO,UAAU;AACjB,OAAO,aAAa;AACpB,OAAOC,aAAY;AACnB,OAAO,UAAU;AACjB,OAAO,aAAa;AACpB,OAAO,SAAS;AAChB,OAAO,WAAW;AAClB,OAAO,cAAc;;;ACTrB,SAAQ,oBAAoB,YAAY,qBAAoB;AAC5D,OAAO,eAAe;AAEf,IAAM,yBAAyB,QAAQ,IAAI,0BAA0B;AAErE,SAAS,iBAAiB,UAAuB;AACtD,SAAO,WAAW;AAAA,IAChB,OAAO;AAAA,MACL,cAAc;AAAA,QACZ,KAAK,GAAG,sBAAsB;AAAA,QAC9B,aAAa;AAAA,QACb,SAAS,MAAM;AACb,iBAAO;AAAA,YACL,iBAAiB;AAAA,YACjB,eAAe;AAAA,UACjB;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;;;ACpBA,SAAQ,iBAAgB;AAExB,OAAO,UAAU;AAEV,IAAM,mBAAN,MAAuB;AAAA,EAQ5B,YACmB,UAKjB;AALiB;AAMjB,QAAI,QAAQ,IAAI,qBAAqB,QAAQ;AAC3C;AAAA,IACF;AAEA,UAAM,kBAAkB,QAAQ,IAAI,qBAAqB;AAEzD,SAAK,mBAAmB;AAAA,MACtB,SAAS;AAAA,IACX;AAEA,QAAI,KAAK,UAAU,QAAQ;AACzB,WAAK,SAAS,KAAK,SAAS;AAAA,IAC9B;AAEA,Q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AAAA,QACF,CAAC;AAED,YAAI,UAAU,IAAI,MAAM,OAAO;AAC7B,cAAI,OAAO,GAAG,EAAE,KAAK,EAAC,SAAS,gBAAe,CAAC;AAC/C,kBAAQ,KAAK,eAAe;AAC5B;AAAA,QACF;AAEA,aAAK,OAAO,IAAI,YAAY,QAAQ;AACpC,YAAI,OAAO,GAAG,EAAE,KAAK,EAAC,SAAS,kBAAiB,CAAC;AACjD,gBAAQ,QAAQ,uCAAgC,MAAM,IAAI,SAAS,EAAE,KAAK,KAAK,CAAC,EAAE;AAClF,YAAI,gBAAgB;AAClB,kBAAQ,KAAK,CAAC;AAAA,QAChB,OAAO;AACL,iBAAO,MAAM;AACb,kBAAQ,EAAC,UAAU,MAAM,aAAY,CAAC;AAAA,QACxC;AAAA,MACF,CAAC;AAED,WAAK,GAAG,KAAK,sBAAsB,0CAA0C,IAAI,mBAAmB,KAAK,EAAE;AAAA,IAC7G,CAAC;AAAA,EACH;AACF;","names":["Conf","crypto","anonymousId","Conf","trpcClient","crypto"]}
|
|
1
|
+
{"version":3,"sources":["../../src/services/auth.service.ts","../../src/utils/trpc.ts","../../src/services/analytics.service.ts"],"sourcesContent":["// @ts-ignore\nimport Conf from 'conf'\nimport cors from 'cors'\nimport express from 'express'\nimport crypto from 'node:crypto'\nimport open from 'open'\nimport getPort from 'get-port'\nimport ora from 'ora'\nimport chalk from 'chalk'\nimport inquirer from 'inquirer'\nimport {Command} from '@oclif/core'\nimport {createTRPCClient} from '../utils/trpc.js'\nimport {AnalyticsService} from '../services/analytics.service.js'\nimport {BaseCommand} from '../commands/base-command.js'\n\ninterface LoginResponse {\n cliToken: string\n user: {\n email: string\n id: string\n }\n organization: {\n id: string\n }\n}\n\nexport class AuthService {\n private readonly config = new Conf({projectName: 'CopilotKitCLI'})\n private readonly COPILOT_CLOUD_BASE_URL = process.env.COPILOT_CLOUD_BASE_URL || 'https://cloud.copilotkit.ai'\n\n getToken(): string | undefined {\n return this.config.get('cliToken') as string | undefined\n }\n\n getCLIToken(): string | undefined {\n const cliToken = this.config.get('cliToken') as string | undefined\n return cliToken\n }\n\n async logout(cmd: BaseCommand): Promise<void> {\n this.config.delete('cliToken')\n }\n\n async requireLogin(cmd: Command, context?: 'cloud-features' | 'general'): Promise<LoginResponse> {\n let cliToken = this.getCLIToken()\n // Check authentication\n if (!cliToken) {\n try {\n let shouldLogin = true\n\n // For cloud features, automatically proceed with login\n // For general usage, ask for confirmation\n if (context !== 'cloud-features') {\n const response = await inquirer.prompt([\n {\n name: 'shouldLogin',\n type: 'confirm',\n message: 'šŖ You are not yet authenticated. Authenticate with Copilot Cloud? (press Enter to confirm)',\n default: true,\n },\n ])\n shouldLogin = response.shouldLogin\n }\n\n if (shouldLogin) {\n // Show different message for cloud features vs general usage\n if (context === 'cloud-features') {\n cmd.log(chalk.cyan('\\nš Setting up Copilot Cloud authentication for your selected features...\\n'))\n }\n const loginResult = await this.login({exitAfterLogin: false})\n cliToken = loginResult.cliToken\n return loginResult\n } else {\n cmd.error('Authentication required to proceed.')\n }\n } catch (error) {\n if (error instanceof Error && error.name === 'ExitPromptError') {\n cmd.error(chalk.yellow('\\nAuthentication cancelled'))\n }\n\n throw error\n }\n }\n\n let me\n\n const trpcClient = createTRPCClient(cliToken)\n try {\n me = await trpcClient.me.query()\n } catch (error) {\n cmd.log(chalk.red('Could not authenticate with Copilot Cloud. Please run: npx copilotkit@latest login'))\n process.exit(1)\n }\n\n if (!me.organization || !me.user) {\n cmd.error('Authentication required to proceed.')\n }\n\n return {cliToken, user: me.user, organization: me.organization}\n }\n\n async login({exitAfterLogin}: {exitAfterLogin?: boolean} = {exitAfterLogin: true}): Promise<LoginResponse> {\n const spinner = ora('šŖ Opening browser for authentication...').start()\n let analytics: AnalyticsService\n analytics = new AnalyticsService()\n\n const app = express()\n app.use(cors())\n app.use(express.urlencoded({extended: true}))\n app.use(express.json())\n\n const port = await getPort()\n const state = crypto.randomBytes(16).toString('hex')\n\n return new Promise(async (resolve) => {\n const server = app.listen(port, () => {})\n\n await analytics.track({\n event: 'cli.login.initiated',\n properties: {},\n })\n\n spinner.text = 'šŖ Waiting for browser authentication to complete...'\n\n app.post('/callback', async (req, res) => {\n const {cliToken, user, organization} = req.body\n\n analytics = new AnalyticsService({userId: user.id, organizationId: organization.id, email: user.email})\n await analytics.track({\n event: 'cli.login.success',\n properties: {\n organizationId: organization.id,\n userId: user.id,\n email: user.email,\n },\n })\n\n if (state !== req.query.state) {\n res.status(401).json({message: 'Invalid state'})\n spinner.fail('Invalid state')\n return\n }\n\n this.config.set('cliToken', cliToken)\n res.status(200).json({message: 'Callback called'})\n spinner.succeed(`šŖ Successfully logged in as ${chalk.hex('#7553fc')(user.email)}`)\n if (exitAfterLogin) {\n process.exit(0)\n } else {\n server.close()\n resolve({cliToken, user, organization})\n }\n })\n\n open(`${this.COPILOT_CLOUD_BASE_URL}/cli-auth?callbackUrl=http://localhost:${port}/callback&state=${state}`)\n })\n }\n}\n","import {createTRPCClient as trpcClient, httpBatchLink} from '@trpc/client'\nimport superjson from 'superjson'\n\nexport const COPILOT_CLOUD_BASE_URL = process.env.COPILOT_CLOUD_BASE_URL || 'https://cloud.copilotkit.ai'\n\nexport function createTRPCClient(cliToken: string): any {\n return trpcClient({\n links: [\n httpBatchLink({\n url: `${COPILOT_CLOUD_BASE_URL}/api/trpc-cli`,\n transformer: superjson,\n headers: () => {\n return {\n 'x-trpc-source': 'cli',\n 'x-cli-token': cliToken,\n }\n },\n }),\n ],\n })\n}\n","import {Analytics} from '@segment/analytics-node'\nimport {PostHog} from 'posthog-node'\nimport {AnalyticsEvents} from './events.js'\nimport Conf from 'conf'\n\nexport class AnalyticsService {\n private segment: Analytics | undefined\n private posthog: PostHog | undefined\n private globalProperties: Record<string, any> = {}\n private userId: string | undefined\n private email: string | undefined\n private organizationId: string | undefined\n private config = new Conf({projectName: 'CopilotKitCLI'})\n\n constructor(\n private readonly authData?: {\n userId: string\n email: string\n organizationId: string\n },\n ) {\n if (process.env.SEGMENT_DISABLED === 'true') {\n return\n }\n\n const segmentWriteKey = process.env.SEGMENT_WRITE_KEY || '9Pv6QyExYef2P4hPz4gks6QAvNMi2AOf'\n\n this.globalProperties = {\n service: 'cli',\n }\n\n if (this.authData?.userId) {\n this.userId = this.authData.userId\n }\n\n if (this.authData?.email) {\n this.email = this.authData.email\n this.globalProperties.email = this.authData.email\n }\n\n if (this.authData?.organizationId) {\n this.organizationId = this.authData.organizationId\n }\n\n this.segment = new Analytics({\n writeKey: segmentWriteKey,\n disable: process.env.SEGMENT_DISABLE === 'true',\n })\n\n // Initialize PostHog for feature flags\n if (process.env.POSTHOG_DISABLED !== 'true') {\n const posthogKey = process.env.POSTHOG_KEY || 'phc_XZdymVYjrph9Mi0xZYGNyCKexxgblXRR1jMENCtdz5Q' // Default key\n const posthogHost = process.env.POSTHOG_HOST || 'https://eu.i.posthog.com'\n\n this.posthog = new PostHog(posthogKey, {\n host: posthogHost,\n })\n }\n\n const config = new Conf({projectName: 'CopilotKitCLI'})\n if (!config.get('anonymousId')) {\n config.set('anonymousId', crypto.randomUUID())\n }\n }\n\n private getAnonymousId(): string {\n const anonymousId = this.config.get('anonymousId')\n if (!anonymousId) {\n const anonymousId = crypto.randomUUID()\n this.config.set('anonymousId', anonymousId)\n return anonymousId\n }\n\n return anonymousId as string\n }\n\n public track<K extends keyof AnalyticsEvents>(\n event: Omit<Parameters<Analytics['track']>[0], 'userId'> & {\n event: K\n properties: AnalyticsEvents[K]\n },\n ): Promise<void> {\n if (!this.segment) {\n return Promise.resolve()\n }\n\n const payload = {\n userId: this.userId ? this.userId : undefined,\n email: this.email ? this.email : undefined,\n anonymousId: this.getAnonymousId(),\n event: event.event,\n properties: {\n ...this.globalProperties,\n ...event.properties,\n $groups: this.organizationId\n ? {\n segment_group: this.organizationId,\n }\n : undefined,\n eventProperties: {\n ...event.properties,\n ...this.globalProperties,\n },\n },\n }\n\n return new Promise((resolve, reject) => {\n this.segment!.track(payload, (err) => {\n if (err) {\n // Resolve anyway\n resolve()\n }\n\n resolve()\n })\n })\n }\n\n /**\n * Check if a feature flag is enabled\n */\n public async isFeatureEnabled(flagKey: string): Promise<boolean> {\n if (!this.posthog) {\n return false\n }\n\n try {\n // Use authenticated user ID if available, otherwise use anonymous ID\n const distinctId = this.userId || this.getAnonymousId()\n const flag = await this.posthog.isFeatureEnabled(flagKey, distinctId)\n return Boolean(flag)\n } catch (error) {\n // If there's an error checking the flag, return false (flag disabled)\n console.warn(`Failed to check feature flag ${flagKey}:`, error)\n return false\n }\n }\n\n /**\n * Shutdown analytics services\n */\n public async shutdown(): Promise<void> {\n if (this.posthog) {\n await this.posthog.shutdown()\n }\n }\n}\n"],"mappings":";AACA,OAAOA,WAAU;AACjB,OAAO,UAAU;AACjB,OAAO,aAAa;AACpB,OAAOC,aAAY;AACnB,OAAO,UAAU;AACjB,OAAO,aAAa;AACpB,OAAO,SAAS;AAChB,OAAO,WAAW;AAClB,OAAO,cAAc;;;ACTrB,SAAQ,oBAAoB,YAAY,qBAAoB;AAC5D,OAAO,eAAe;AAEf,IAAM,yBAAyB,QAAQ,IAAI,0BAA0B;AAErE,SAAS,iBAAiB,UAAuB;AACtD,SAAO,WAAW;AAAA,IAChB,OAAO;AAAA,MACL,cAAc;AAAA,QACZ,KAAK,GAAG,sBAAsB;AAAA,QAC9B,aAAa;AAAA,QACb,SAAS,MAAM;AACb,iBAAO;AAAA,YACL,iBAAiB;AAAA,YACjB,eAAe;AAAA,UACjB;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AACH;;;ACpBA,SAAQ,iBAAgB;AACxB,SAAQ,eAAc;AAEtB,OAAO,UAAU;AAEV,IAAM,mBAAN,MAAuB;AAAA,EAS5B,YACmB,UAKjB;AALiB;AAMjB,QAAI,QAAQ,IAAI,qBAAqB,QAAQ;AAC3C;AAAA,IACF;AAEA,UAAM,kBAAkB,QAAQ,IAAI,qBAAqB;AAEzD,SAAK,mBAAmB;AAAA,MACtB,SAAS;AAAA,I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AAS,EAAE,KAAK,KAAK,CAAC,EAAE;AAClF,YAAI,gBAAgB;AAClB,kBAAQ,KAAK,CAAC;AAAA,QAChB,OAAO;AACL,iBAAO,MAAM;AACb,kBAAQ,EAAC,UAAU,MAAM,aAAY,CAAC;AAAA,QACxC;AAAA,MACF,CAAC;AAED,WAAK,GAAG,KAAK,sBAAsB,0CAA0C,IAAI,mBAAmB,KAAK,EAAE;AAAA,IAC7G,CAAC;AAAA,EACH;AACF;","names":["Conf","crypto","anonymousId","Conf","trpcClient","crypto"]}
|
|
@@ -26,6 +26,49 @@ type AnalyticsEvents = {
|
|
|
26
26
|
'cli.dev.tunnel.closed': {
|
|
27
27
|
tunnelId: string;
|
|
28
28
|
};
|
|
29
|
+
'cli.init.started': {
|
|
30
|
+
nextjs_detected: boolean;
|
|
31
|
+
flags_used?: string[];
|
|
32
|
+
};
|
|
33
|
+
'cli.init.early_signup_prompt_shown': {};
|
|
34
|
+
'cli.init.early_signup_selected': {
|
|
35
|
+
choice: 'Yes' | 'No';
|
|
36
|
+
cloud_by_default_enabled?: boolean;
|
|
37
|
+
};
|
|
38
|
+
'cli.init.early_signup_completed': {
|
|
39
|
+
userId: string;
|
|
40
|
+
organizationId: string;
|
|
41
|
+
email: string;
|
|
42
|
+
projectId: string;
|
|
43
|
+
api_key_retrieved: boolean;
|
|
44
|
+
};
|
|
45
|
+
'cli.init.early_signup_failed': {
|
|
46
|
+
error: string;
|
|
47
|
+
step: 'auth' | 'project_selection' | 'api_key_retrieval';
|
|
48
|
+
};
|
|
49
|
+
'cli.init.mode_selected': {
|
|
50
|
+
mode: 'LangGraph' | 'CrewAI' | 'Standard' | 'MCP' | 'Mastra' | 'LlamaIndex' | 'Agno' | 'AG2';
|
|
51
|
+
early_signup_completed?: boolean;
|
|
52
|
+
};
|
|
53
|
+
'cli.init.cloud_deployment_selected': {
|
|
54
|
+
choice: 'Yes' | 'No';
|
|
55
|
+
mode: string;
|
|
56
|
+
early_signup_completed?: boolean;
|
|
57
|
+
};
|
|
58
|
+
'cli.init.completed': {
|
|
59
|
+
mode: string;
|
|
60
|
+
early_signup_completed: boolean;
|
|
61
|
+
cloud_deployment: boolean;
|
|
62
|
+
agent_scaffolded: boolean;
|
|
63
|
+
api_key_in_env: boolean;
|
|
64
|
+
duration_ms: number;
|
|
65
|
+
};
|
|
66
|
+
'cli.init.failed': {
|
|
67
|
+
error: string;
|
|
68
|
+
step: string;
|
|
69
|
+
mode?: string;
|
|
70
|
+
early_signup_completed?: boolean;
|
|
71
|
+
};
|
|
29
72
|
'cli.init.cloud_used': {
|
|
30
73
|
userId: string;
|
|
31
74
|
};
|
package/dist/utils/version.d.ts
CHANGED
package/dist/utils/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/version.ts"],"sourcesContent":["// This is auto generated!\nexport const LIB_VERSION = \"0.0.
|
|
1
|
+
{"version":3,"sources":["../../src/utils/version.ts"],"sourcesContent":["// This is auto generated!\nexport const LIB_VERSION = \"0.0.42-alpha.0\";\n"],"mappings":";AACO,IAAM,cAAc;","names":[]}
|
package/oclif.manifest.json
CHANGED
|
@@ -128,6 +128,17 @@
|
|
|
128
128
|
"allowNo": false,
|
|
129
129
|
"type": "boolean"
|
|
130
130
|
},
|
|
131
|
+
"signup-for-copilot-cloud": {
|
|
132
|
+
"description": "Sign up for Copilot Cloud for error tracking and debugging insights",
|
|
133
|
+
"name": "signup-for-copilot-cloud",
|
|
134
|
+
"hasDynamicHelp": false,
|
|
135
|
+
"multiple": false,
|
|
136
|
+
"options": [
|
|
137
|
+
"Yes",
|
|
138
|
+
"No"
|
|
139
|
+
],
|
|
140
|
+
"type": "option"
|
|
141
|
+
},
|
|
131
142
|
"mode": {
|
|
132
143
|
"char": "m",
|
|
133
144
|
"description": "How you will be interacting with AI",
|
|
@@ -326,5 +337,5 @@
|
|
|
326
337
|
]
|
|
327
338
|
}
|
|
328
339
|
},
|
|
329
|
-
"version": "0.0.
|
|
340
|
+
"version": "0.0.42-alpha.0"
|
|
330
341
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "copilotkit",
|
|
3
3
|
"description": "CopilotKit CLI",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.42-alpha.0",
|
|
5
5
|
"author": "CopilotKit",
|
|
6
6
|
"bin": {
|
|
7
7
|
"copilotkit": "./bin/run.js",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"localtunnel": "^2.0.2",
|
|
41
41
|
"open": "^10.1.0",
|
|
42
42
|
"ora": "^8.1.1",
|
|
43
|
+
"posthog-node": "^4.0.1",
|
|
43
44
|
"superjson": "^2.2.1",
|
|
44
45
|
"zod": "^3.22.4",
|
|
45
46
|
"execa": "^8.0.1",
|