copilotkit 0.0.4 → 0.0.5
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/README.md +40 -2
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +8 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +5 -0
- package/dist/commands/base-command.d.ts +11 -0
- package/dist/commands/base-command.js +70 -0
- package/dist/commands/base-command.js.map +1 -0
- package/dist/commands/dev.d.ts +25 -0
- package/dist/commands/dev.js +591 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/login.d.ts +13 -0
- package/dist/commands/login.js +306 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +13 -0
- package/dist/commands/logout.js +309 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/services/analytics.service.d.ts +25 -0
- package/dist/services/analytics.service.js +75 -0
- package/dist/services/analytics.service.js.map +1 -0
- package/dist/services/auth.service.d.ts +23 -0
- package/dist/services/auth.service.js +226 -0
- package/dist/services/auth.service.js.map +1 -0
- package/dist/services/events.d.ts +31 -0
- package/dist/services/events.js +1 -0
- package/dist/services/events.js.map +1 -0
- package/dist/services/tunnel.service.d.ts +15 -0
- package/dist/services/tunnel.service.js +17 -0
- package/dist/services/tunnel.service.js.map +1 -0
- package/dist/utils/detect-endpoint-type.utils.d.ts +13 -0
- package/dist/utils/detect-endpoint-type.utils.js +117 -0
- package/dist/utils/detect-endpoint-type.utils.js.map +1 -0
- package/dist/utils/trpc.d.ts +4 -0
- package/dist/utils/trpc.js +25 -0
- package/dist/utils/trpc.js.map +1 -0
- package/dist/utils/version.d.ts +3 -0
- package/dist/utils/version.js +6 -0
- package/dist/utils/version.js.map +1 -0
- package/oclif.manifest.json +106 -0
- package/package.json +90 -84
- package/LICENSE +0 -13
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
// src/services/auth.service.ts
|
|
2
|
+
import Conf2 from "conf";
|
|
3
|
+
import cors from "cors";
|
|
4
|
+
import express from "express";
|
|
5
|
+
import crypto2 from "node:crypto";
|
|
6
|
+
import open from "open";
|
|
7
|
+
import getPort from "get-port";
|
|
8
|
+
import ora from "ora";
|
|
9
|
+
import chalk from "chalk";
|
|
10
|
+
import inquirer from "inquirer";
|
|
11
|
+
|
|
12
|
+
// src/utils/trpc.ts
|
|
13
|
+
import { createTRPCClient as createTRPClient_, unstable_httpBatchStreamLink } from "@trpc/client";
|
|
14
|
+
import superjson from "superjson";
|
|
15
|
+
var COPILOT_CLOUD_BASE_URL = process.env.COPILOT_CLOUD_BASE_URL || "https://cloud.copilotkit.ai";
|
|
16
|
+
function createTRPCClient(cliToken) {
|
|
17
|
+
return createTRPClient_({
|
|
18
|
+
links: [
|
|
19
|
+
unstable_httpBatchStreamLink({
|
|
20
|
+
transformer: superjson,
|
|
21
|
+
url: `${COPILOT_CLOUD_BASE_URL}/api/trpc-cli`,
|
|
22
|
+
headers: () => {
|
|
23
|
+
const headers = new Headers();
|
|
24
|
+
headers.set("x-trpc-source", "cli");
|
|
25
|
+
headers.set("x-cli-token", cliToken);
|
|
26
|
+
return headers;
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
]
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/services/analytics.service.ts
|
|
34
|
+
import { Analytics } from "@segment/analytics-node";
|
|
35
|
+
import Conf from "conf";
|
|
36
|
+
var AnalyticsService = class {
|
|
37
|
+
constructor(authData) {
|
|
38
|
+
this.authData = authData;
|
|
39
|
+
if (process.env.SEGMENT_DISABLED === "true") {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const segmentWriteKey = process.env.SEGMENT_WRITE_KEY || "9Pv6QyExYef2P4hPz4gks6QAvNMi2AOf";
|
|
43
|
+
this.globalProperties = {
|
|
44
|
+
service: "cli"
|
|
45
|
+
};
|
|
46
|
+
if (this.authData?.userId) {
|
|
47
|
+
this.userId = this.authData.userId;
|
|
48
|
+
}
|
|
49
|
+
if (this.authData?.email) {
|
|
50
|
+
this.email = this.authData.email;
|
|
51
|
+
this.globalProperties.email = this.authData.email;
|
|
52
|
+
}
|
|
53
|
+
if (this.authData?.organizationId) {
|
|
54
|
+
this.organizationId = this.authData.organizationId;
|
|
55
|
+
}
|
|
56
|
+
this.segment = new Analytics({
|
|
57
|
+
writeKey: segmentWriteKey,
|
|
58
|
+
disable: process.env.SEGMENT_DISABLE === "true"
|
|
59
|
+
});
|
|
60
|
+
const config = new Conf({ projectName: "CopilotKitCLI" });
|
|
61
|
+
if (!config.get("anonymousId")) {
|
|
62
|
+
config.set("anonymousId", crypto.randomUUID());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
segment;
|
|
66
|
+
globalProperties = {};
|
|
67
|
+
userId;
|
|
68
|
+
email;
|
|
69
|
+
organizationId;
|
|
70
|
+
config = new Conf({ projectName: "CopilotKitCLI" });
|
|
71
|
+
getAnonymousId() {
|
|
72
|
+
const anonymousId = this.config.get("anonymousId");
|
|
73
|
+
if (!anonymousId) {
|
|
74
|
+
const anonymousId2 = crypto.randomUUID();
|
|
75
|
+
this.config.set("anonymousId", anonymousId2);
|
|
76
|
+
return anonymousId2;
|
|
77
|
+
}
|
|
78
|
+
return anonymousId;
|
|
79
|
+
}
|
|
80
|
+
track(event) {
|
|
81
|
+
if (!this.segment) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const payload = {
|
|
85
|
+
userId: this.userId ? this.userId : void 0,
|
|
86
|
+
email: this.email ? this.email : void 0,
|
|
87
|
+
anonymousId: this.getAnonymousId(),
|
|
88
|
+
event: event.event,
|
|
89
|
+
properties: {
|
|
90
|
+
...this.globalProperties,
|
|
91
|
+
...event.properties,
|
|
92
|
+
$groups: this.organizationId ? {
|
|
93
|
+
segment_group: this.organizationId
|
|
94
|
+
} : void 0,
|
|
95
|
+
eventProperties: {
|
|
96
|
+
...event.properties,
|
|
97
|
+
...this.globalProperties
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
this.segment.track(payload);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/services/auth.service.ts
|
|
106
|
+
var AuthService = class {
|
|
107
|
+
config = new Conf2({ projectName: "CopilotKitCLI" });
|
|
108
|
+
COPILOT_CLOUD_BASE_URL = process.env.COPILOT_CLOUD_BASE_URL || "https://cloud.copilotkit.ai";
|
|
109
|
+
getToken() {
|
|
110
|
+
return this.config.get("cliToken");
|
|
111
|
+
}
|
|
112
|
+
getCLIToken() {
|
|
113
|
+
const cliToken = this.config.get("cliToken");
|
|
114
|
+
return cliToken;
|
|
115
|
+
}
|
|
116
|
+
async logout() {
|
|
117
|
+
const cliToken = this.getCLIToken();
|
|
118
|
+
if (!cliToken) {
|
|
119
|
+
throw new Error("You are not logged in");
|
|
120
|
+
}
|
|
121
|
+
const trpcClient = createTRPCClient(cliToken);
|
|
122
|
+
const me = await trpcClient.me.query();
|
|
123
|
+
const analytics = new AnalyticsService({ userId: me.user.id, organizationId: me.organization.id, email: me.user.email });
|
|
124
|
+
this.config.delete("cliToken");
|
|
125
|
+
analytics.track({
|
|
126
|
+
event: "cli.logout",
|
|
127
|
+
properties: {
|
|
128
|
+
organizationId: me.organization.id,
|
|
129
|
+
userId: me.user.id,
|
|
130
|
+
email: me.user.email
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async requireLogin(cmd) {
|
|
135
|
+
let cliToken = this.getCLIToken();
|
|
136
|
+
if (!cliToken) {
|
|
137
|
+
try {
|
|
138
|
+
const { shouldLogin } = await inquirer.prompt([
|
|
139
|
+
{
|
|
140
|
+
name: "shouldLogin",
|
|
141
|
+
type: "confirm",
|
|
142
|
+
message: "You are not yet authenticated. Authenticate with Copilot Cloud? (press Enter to confirm)",
|
|
143
|
+
default: true
|
|
144
|
+
}
|
|
145
|
+
]);
|
|
146
|
+
if (shouldLogin) {
|
|
147
|
+
const loginResult = await this.login();
|
|
148
|
+
cliToken = loginResult.cliToken;
|
|
149
|
+
cmd.log(`\u{1FA81} Logged in as ${chalk.hex("#7553fc")(loginResult.user.email)}
|
|
150
|
+
`);
|
|
151
|
+
return loginResult;
|
|
152
|
+
} else {
|
|
153
|
+
cmd.error("Authentication required to proceed.");
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (error instanceof Error && error.name === "ExitPromptError") {
|
|
157
|
+
cmd.error(chalk.yellow("\nAuthentication cancelled"));
|
|
158
|
+
}
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
let me;
|
|
163
|
+
const trpcClient = createTRPCClient(cliToken);
|
|
164
|
+
try {
|
|
165
|
+
me = await trpcClient.me.query();
|
|
166
|
+
} catch (error) {
|
|
167
|
+
cmd.log(chalk.red("Could not authenticate with Copilot Cloud. Please try again."));
|
|
168
|
+
process.exit(1);
|
|
169
|
+
}
|
|
170
|
+
if (!me.organization || !me.user) {
|
|
171
|
+
cmd.error("Authentication required to proceed.");
|
|
172
|
+
}
|
|
173
|
+
return { cliToken, user: me.user, organization: me.organization };
|
|
174
|
+
}
|
|
175
|
+
async login() {
|
|
176
|
+
let analytics;
|
|
177
|
+
analytics = new AnalyticsService();
|
|
178
|
+
const app = express();
|
|
179
|
+
app.use(cors());
|
|
180
|
+
app.use(express.urlencoded({ extended: true }));
|
|
181
|
+
app.use(express.json());
|
|
182
|
+
const port = await getPort();
|
|
183
|
+
const state = crypto2.randomBytes(16).toString("hex");
|
|
184
|
+
return new Promise((resolve) => {
|
|
185
|
+
const server = app.listen(port, () => {
|
|
186
|
+
});
|
|
187
|
+
analytics.track({
|
|
188
|
+
event: "cli.login.initiated",
|
|
189
|
+
properties: {}
|
|
190
|
+
});
|
|
191
|
+
const spinner = ora("Waiting for browser authentication to complete...\n").start();
|
|
192
|
+
app.post("/callback", async (req, res) => {
|
|
193
|
+
const { cliToken, user, organization } = req.body;
|
|
194
|
+
analytics = new AnalyticsService({ userId: user.id, organizationId: organization.id, email: user.email });
|
|
195
|
+
analytics.track({
|
|
196
|
+
event: "cli.login.success",
|
|
197
|
+
properties: {
|
|
198
|
+
organizationId: organization.id,
|
|
199
|
+
userId: user.id,
|
|
200
|
+
email: user.email
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
if (state !== req.query.state) {
|
|
204
|
+
res.status(401).json({ message: "Invalid state" });
|
|
205
|
+
spinner.fail("Invalid state");
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
this.config.set("cliToken", cliToken);
|
|
209
|
+
res.status(200).json({ message: "Callback called" });
|
|
210
|
+
spinner.succeed(`\u{1FA81} Successfully logged in as ${chalk.hex("#7553fc")(user.email)}
|
|
211
|
+
`);
|
|
212
|
+
server.close();
|
|
213
|
+
resolve({
|
|
214
|
+
cliToken,
|
|
215
|
+
organization,
|
|
216
|
+
user
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
open(`${this.COPILOT_CLOUD_BASE_URL}/cli-auth?callbackUrl=http://localhost:${port}/callback&state=${state}`);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// src/commands/base-command.ts
|
|
225
|
+
import { Command } from "@oclif/core";
|
|
226
|
+
import Sentry, { consoleIntegration } from "@sentry/node";
|
|
227
|
+
|
|
228
|
+
// src/utils/version.ts
|
|
229
|
+
var LIB_VERSION = "0.0.5";
|
|
230
|
+
|
|
231
|
+
// src/commands/base-command.ts
|
|
232
|
+
import chalk2 from "chalk";
|
|
233
|
+
var BaseCommand = class extends Command {
|
|
234
|
+
async init() {
|
|
235
|
+
await this.checkCLIVersion();
|
|
236
|
+
if (process.env.SENTRY_DISABLED === "true") {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
Sentry.init({
|
|
240
|
+
dsn: process.env.SENTRY_DSN || "https://1eea15d32e2eacb0456a77db5e39aeeb@o4507288195170304.ingest.us.sentry.io/4508581448581120",
|
|
241
|
+
integrations: [
|
|
242
|
+
consoleIntegration()
|
|
243
|
+
],
|
|
244
|
+
// Tracing
|
|
245
|
+
tracesSampleRate: 1
|
|
246
|
+
// Capture 100% of the transactions
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
async catch(err) {
|
|
250
|
+
if (process.env.SENTRY_DISABLED === "true") {
|
|
251
|
+
super.catch(err);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
Sentry.captureException(err);
|
|
255
|
+
super.catch(err);
|
|
256
|
+
}
|
|
257
|
+
async finally() {
|
|
258
|
+
if (process.env.SENTRY_DISABLED === "true") {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
Sentry.close();
|
|
262
|
+
}
|
|
263
|
+
async run() {
|
|
264
|
+
}
|
|
265
|
+
async checkCLIVersion() {
|
|
266
|
+
const response = await fetch(`${COPILOT_CLOUD_BASE_URL}/api/healthz`);
|
|
267
|
+
const data = await response.json();
|
|
268
|
+
const cloudVersion = data.cliVersion;
|
|
269
|
+
if (cloudVersion === LIB_VERSION) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
this.log(chalk2.yellow("================ New version available! =================\n"));
|
|
273
|
+
this.log(`A new CopilotKit CLI version is available (${LIB_VERSION}).
|
|
274
|
+
`);
|
|
275
|
+
this.log("Please update your CLI to the latest version:\n\n");
|
|
276
|
+
this.log(`${chalk2.cyan(chalk2.underline(chalk2.bold("npm:")))} npm install -g copilotkit@${LIB_VERSION}
|
|
277
|
+
`);
|
|
278
|
+
this.log(`${chalk2.cyan(chalk2.underline(chalk2.bold("pnpm:")))} pnpm install -g copilotkit@${LIB_VERSION}
|
|
279
|
+
`);
|
|
280
|
+
this.log(`${chalk2.cyan(chalk2.underline(chalk2.bold("yarn:")))} yarn global add copilotkit@${LIB_VERSION}
|
|
281
|
+
`);
|
|
282
|
+
process.exit(0);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// src/commands/login.ts
|
|
287
|
+
var CloudLogin = class _CloudLogin extends BaseCommand {
|
|
288
|
+
constructor(argv, config, authService = new AuthService()) {
|
|
289
|
+
super(argv, config);
|
|
290
|
+
this.authService = authService;
|
|
291
|
+
}
|
|
292
|
+
static description = "Authenticate with Copilot Cloud";
|
|
293
|
+
static examples = ["<%= config.bin %> login"];
|
|
294
|
+
async run() {
|
|
295
|
+
await this.parse(_CloudLogin);
|
|
296
|
+
try {
|
|
297
|
+
await this.authService.login();
|
|
298
|
+
} catch (error) {
|
|
299
|
+
this.error(error.message);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
export {
|
|
304
|
+
CloudLogin as default
|
|
305
|
+
};
|
|
306
|
+
//# sourceMappingURL=login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/auth.service.ts","../../src/utils/trpc.ts","../../src/services/analytics.service.ts","../../src/commands/base-command.ts","../../src/utils/version.ts","../../src/commands/login.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'\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(): Promise<void> {\n const cliToken = this.getCLIToken();\n \n if (!cliToken) {\n throw new Error('You are not logged in');\n }\n\n const trpcClient = createTRPCClient(cliToken)\n const me = await trpcClient.me.query()\n\n const analytics = new AnalyticsService({ userId: me.user!.id, organizationId: me.organization!.id, email: me.user!.email });\n \n this.config.delete('cliToken')\n \n analytics.track({\n event: \"cli.logout\",\n properties: {\n organizationId: me.organization!.id,\n userId: me.user!.id,\n email: me.user!.email,\n }\n });\n }\n\n async requireLogin(cmd: Command): Promise<LoginResponse> {\n let cliToken = this.getCLIToken()\n\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\n if (shouldLogin) {\n const loginResult = await this.login()\n cliToken = loginResult.cliToken\n cmd.log(`🪁 Logged in as ${chalk.hex('#7553fc')(loginResult.user.email)}\\n`)\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 try again.\"))\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(): Promise<LoginResponse> {\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((resolve) => {\n const server = app.listen(port, () => {})\n\n analytics.track({\n event: \"cli.login.initiated\",\n properties: {}\n });\n\n const spinner = ora('Waiting for browser authentication to complete...\\n').start()\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 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`)\n server.close()\n resolve({\n cliToken,\n organization,\n user,\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 createTRPClient_, unstable_httpBatchStreamLink} from '@trpc/client'\nimport type {CLIRouter} from '@repo/trpc-cli'\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) {\n return createTRPClient_<CLIRouter>({\n links: [\n unstable_httpBatchStreamLink({\n transformer: superjson,\n url: `${COPILOT_CLOUD_BASE_URL}/api/trpc-cli`,\n headers: () => {\n const headers = new Headers()\n headers.set('x-trpc-source', 'cli')\n headers.set('x-cli-token', cliToken)\n return headers\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(private readonly authData?: {\n userId: string,\n email: string,\n organizationId: string,\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\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 ): void {\n if (!this.segment) {\n return;\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 segment_group: this.organizationId,\n } : undefined,\n eventProperties: {\n ...event.properties,\n ...this.globalProperties,\n },\n },\n }\n\n this.segment.track(payload)\n }\n}\n","import { Command } from \"@oclif/core\";\nimport Sentry, { consoleIntegration } from \"@sentry/node\";\nimport { LIB_VERSION } from \"../utils/version.js\";\nimport { COPILOT_CLOUD_BASE_URL } from \"../utils/trpc.js\";\nimport chalk from \"chalk\";\n\nexport class BaseCommand extends Command {\n async init() {\n await this.checkCLIVersion();\n\n if (process.env.SENTRY_DISABLED === 'true') {\n return;\n }\n\n Sentry.init({\n dsn: process.env.SENTRY_DSN || \"https://1eea15d32e2eacb0456a77db5e39aeeb@o4507288195170304.ingest.us.sentry.io/4508581448581120\",\n integrations: [\n consoleIntegration(),\n ],\n // Tracing\n tracesSampleRate: 1.0, // Capture 100% of the transactions\n });\n }\n\n async catch(err: any) {\n if (process.env.SENTRY_DISABLED === 'true') {\n super.catch(err)\n return;\n }\n\n Sentry.captureException(err)\n super.catch(err)\n }\n\n async finally() {\n if (process.env.SENTRY_DISABLED === 'true') {\n return;\n }\n\n Sentry.close()\n }\n \n async run() {}\n\n async checkCLIVersion() {\n const response = await fetch(`${COPILOT_CLOUD_BASE_URL}/api/healthz`)\n const data = await response.json()\n const cloudVersion = data.cliVersion\n\n if (cloudVersion === LIB_VERSION) {\n return;\n }\n\n this.log(chalk.yellow('================ New version available! =================\\n'))\n this.log(`A new CopilotKit CLI version is available (${LIB_VERSION}).\\n`)\n this.log('Please update your CLI to the latest version:\\n\\n')\n this.log(`${chalk.cyan(chalk.underline(chalk.bold('npm:')))}\\t npm install -g copilotkit@${LIB_VERSION}\\n`)\n this.log(`${chalk.cyan(chalk.underline(chalk.bold('pnpm:')))}\\t pnpm install -g copilotkit@${LIB_VERSION}\\n`)\n this.log(`${chalk.cyan(chalk.underline(chalk.bold('yarn:')))}\\t yarn global add copilotkit@${LIB_VERSION}\\n`)\n\n process.exit(0)\n }\n}\n","// This is auto generated!\nexport const LIB_VERSION = \"0.0.5\";\n","import {Config} from '@oclif/core'\n\nimport {AuthService} from '../services/auth.service.js'\nimport { BaseCommand } from './base-command.js'\n\nexport default class CloudLogin extends BaseCommand {\n static override description = 'Authenticate with Copilot Cloud'\n\n static override examples = ['<%= config.bin %> login']\n\n constructor(argv: string[], config: Config, private authService = new AuthService()) {\n super(argv, config)\n }\n\n public async run(): Promise<void> {\n await this.parse(CloudLogin)\n\n try {\n await this.authService.login()\n } catch (error: unknown) {\n this.error((error as Error).message)\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,S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AO,MAAM,SAAS,KAAK;AACjC,UAAM,eAAe,KAAK;AAE1B,QAAI,iBAAiB,aAAa;AAChC;AAAA,IACF;AAEA,SAAK,IAAIA,OAAM,OAAO,6DAA6D,CAAC;AACpF,SAAK,IAAI,8CAA8C,WAAW;AAAA,CAAM;AACxE,SAAK,IAAI,mDAAmD;AAC5D,SAAK,IAAI,GAAGA,OAAM,KAAKA,OAAM,UAAUA,OAAM,KAAK,MAAM,CAAC,CAAC,CAAC,+BAAgC,WAAW;AAAA,CAAI;AAC1G,SAAK,IAAI,GAAGA,OAAM,KAAKA,OAAM,UAAUA,OAAM,KAAK,OAAO,CAAC,CAAC,CAAC,gCAAiC,WAAW;AAAA,CAAI;AAC5G,SAAK,IAAI,GAAGA,OAAM,KAAKA,OAAM,UAAUA,OAAM,KAAK,OAAO,CAAC,CAAC,CAAC,gCAAiC,WAAW;AAAA,CAAI;AAE5G,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;;;AEzDA,IAAqB,aAArB,MAAqB,oBAAmB,YAAY;AAAA,EAKlD,YAAY,MAAgB,QAAwB,cAAc,IAAI,YAAY,GAAG;AACnF,UAAM,MAAM,MAAM;AADgC;AAAA,EAEpD;AAAA,EANA,OAAgB,cAAc;AAAA,EAE9B,OAAgB,WAAW,CAAC,yBAAyB;AAAA,EAMrD,MAAa,MAAqB;AAChC,UAAM,KAAK,MAAM,WAAU;AAE3B,QAAI;AACF,YAAM,KAAK,YAAY,MAAM;AAAA,IAC/B,SAAS,OAAgB;AACvB,WAAK,MAAO,MAAgB,OAAO;AAAA,IACrC;AAAA,EACF;AACF;","names":["Conf","crypto","anonymousId","Conf","crypto","chalk"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Config } from '@oclif/core';
|
|
2
|
+
import { AuthService } from '../services/auth.service.js';
|
|
3
|
+
import { BaseCommand } from './base-command.js';
|
|
4
|
+
|
|
5
|
+
declare class CloudLogout extends BaseCommand {
|
|
6
|
+
private authService;
|
|
7
|
+
static description: string;
|
|
8
|
+
static examples: string[];
|
|
9
|
+
constructor(argv: string[], config: Config, authService?: AuthService);
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { CloudLogout as default };
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// src/commands/logout.ts
|
|
2
|
+
import chalk3 from "chalk";
|
|
3
|
+
import ora2 from "ora";
|
|
4
|
+
|
|
5
|
+
// src/services/auth.service.ts
|
|
6
|
+
import Conf2 from "conf";
|
|
7
|
+
import cors from "cors";
|
|
8
|
+
import express from "express";
|
|
9
|
+
import crypto2 from "node:crypto";
|
|
10
|
+
import open from "open";
|
|
11
|
+
import getPort from "get-port";
|
|
12
|
+
import ora from "ora";
|
|
13
|
+
import chalk from "chalk";
|
|
14
|
+
import inquirer from "inquirer";
|
|
15
|
+
|
|
16
|
+
// src/utils/trpc.ts
|
|
17
|
+
import { createTRPCClient as createTRPClient_, unstable_httpBatchStreamLink } from "@trpc/client";
|
|
18
|
+
import superjson from "superjson";
|
|
19
|
+
var COPILOT_CLOUD_BASE_URL = process.env.COPILOT_CLOUD_BASE_URL || "https://cloud.copilotkit.ai";
|
|
20
|
+
function createTRPCClient(cliToken) {
|
|
21
|
+
return createTRPClient_({
|
|
22
|
+
links: [
|
|
23
|
+
unstable_httpBatchStreamLink({
|
|
24
|
+
transformer: superjson,
|
|
25
|
+
url: `${COPILOT_CLOUD_BASE_URL}/api/trpc-cli`,
|
|
26
|
+
headers: () => {
|
|
27
|
+
const headers = new Headers();
|
|
28
|
+
headers.set("x-trpc-source", "cli");
|
|
29
|
+
headers.set("x-cli-token", cliToken);
|
|
30
|
+
return headers;
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/services/analytics.service.ts
|
|
38
|
+
import { Analytics } from "@segment/analytics-node";
|
|
39
|
+
import Conf from "conf";
|
|
40
|
+
var AnalyticsService = class {
|
|
41
|
+
constructor(authData) {
|
|
42
|
+
this.authData = authData;
|
|
43
|
+
if (process.env.SEGMENT_DISABLED === "true") {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const segmentWriteKey = process.env.SEGMENT_WRITE_KEY || "9Pv6QyExYef2P4hPz4gks6QAvNMi2AOf";
|
|
47
|
+
this.globalProperties = {
|
|
48
|
+
service: "cli"
|
|
49
|
+
};
|
|
50
|
+
if (this.authData?.userId) {
|
|
51
|
+
this.userId = this.authData.userId;
|
|
52
|
+
}
|
|
53
|
+
if (this.authData?.email) {
|
|
54
|
+
this.email = this.authData.email;
|
|
55
|
+
this.globalProperties.email = this.authData.email;
|
|
56
|
+
}
|
|
57
|
+
if (this.authData?.organizationId) {
|
|
58
|
+
this.organizationId = this.authData.organizationId;
|
|
59
|
+
}
|
|
60
|
+
this.segment = new Analytics({
|
|
61
|
+
writeKey: segmentWriteKey,
|
|
62
|
+
disable: process.env.SEGMENT_DISABLE === "true"
|
|
63
|
+
});
|
|
64
|
+
const config = new Conf({ projectName: "CopilotKitCLI" });
|
|
65
|
+
if (!config.get("anonymousId")) {
|
|
66
|
+
config.set("anonymousId", crypto.randomUUID());
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
segment;
|
|
70
|
+
globalProperties = {};
|
|
71
|
+
userId;
|
|
72
|
+
email;
|
|
73
|
+
organizationId;
|
|
74
|
+
config = new Conf({ projectName: "CopilotKitCLI" });
|
|
75
|
+
getAnonymousId() {
|
|
76
|
+
const anonymousId = this.config.get("anonymousId");
|
|
77
|
+
if (!anonymousId) {
|
|
78
|
+
const anonymousId2 = crypto.randomUUID();
|
|
79
|
+
this.config.set("anonymousId", anonymousId2);
|
|
80
|
+
return anonymousId2;
|
|
81
|
+
}
|
|
82
|
+
return anonymousId;
|
|
83
|
+
}
|
|
84
|
+
track(event) {
|
|
85
|
+
if (!this.segment) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const payload = {
|
|
89
|
+
userId: this.userId ? this.userId : void 0,
|
|
90
|
+
email: this.email ? this.email : void 0,
|
|
91
|
+
anonymousId: this.getAnonymousId(),
|
|
92
|
+
event: event.event,
|
|
93
|
+
properties: {
|
|
94
|
+
...this.globalProperties,
|
|
95
|
+
...event.properties,
|
|
96
|
+
$groups: this.organizationId ? {
|
|
97
|
+
segment_group: this.organizationId
|
|
98
|
+
} : void 0,
|
|
99
|
+
eventProperties: {
|
|
100
|
+
...event.properties,
|
|
101
|
+
...this.globalProperties
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
this.segment.track(payload);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/services/auth.service.ts
|
|
110
|
+
var AuthService = class {
|
|
111
|
+
config = new Conf2({ projectName: "CopilotKitCLI" });
|
|
112
|
+
COPILOT_CLOUD_BASE_URL = process.env.COPILOT_CLOUD_BASE_URL || "https://cloud.copilotkit.ai";
|
|
113
|
+
getToken() {
|
|
114
|
+
return this.config.get("cliToken");
|
|
115
|
+
}
|
|
116
|
+
getCLIToken() {
|
|
117
|
+
const cliToken = this.config.get("cliToken");
|
|
118
|
+
return cliToken;
|
|
119
|
+
}
|
|
120
|
+
async logout() {
|
|
121
|
+
const cliToken = this.getCLIToken();
|
|
122
|
+
if (!cliToken) {
|
|
123
|
+
throw new Error("You are not logged in");
|
|
124
|
+
}
|
|
125
|
+
const trpcClient = createTRPCClient(cliToken);
|
|
126
|
+
const me = await trpcClient.me.query();
|
|
127
|
+
const analytics = new AnalyticsService({ userId: me.user.id, organizationId: me.organization.id, email: me.user.email });
|
|
128
|
+
this.config.delete("cliToken");
|
|
129
|
+
analytics.track({
|
|
130
|
+
event: "cli.logout",
|
|
131
|
+
properties: {
|
|
132
|
+
organizationId: me.organization.id,
|
|
133
|
+
userId: me.user.id,
|
|
134
|
+
email: me.user.email
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async requireLogin(cmd) {
|
|
139
|
+
let cliToken = this.getCLIToken();
|
|
140
|
+
if (!cliToken) {
|
|
141
|
+
try {
|
|
142
|
+
const { shouldLogin } = await inquirer.prompt([
|
|
143
|
+
{
|
|
144
|
+
name: "shouldLogin",
|
|
145
|
+
type: "confirm",
|
|
146
|
+
message: "You are not yet authenticated. Authenticate with Copilot Cloud? (press Enter to confirm)",
|
|
147
|
+
default: true
|
|
148
|
+
}
|
|
149
|
+
]);
|
|
150
|
+
if (shouldLogin) {
|
|
151
|
+
const loginResult = await this.login();
|
|
152
|
+
cliToken = loginResult.cliToken;
|
|
153
|
+
cmd.log(`\u{1FA81} Logged in as ${chalk.hex("#7553fc")(loginResult.user.email)}
|
|
154
|
+
`);
|
|
155
|
+
return loginResult;
|
|
156
|
+
} else {
|
|
157
|
+
cmd.error("Authentication required to proceed.");
|
|
158
|
+
}
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (error instanceof Error && error.name === "ExitPromptError") {
|
|
161
|
+
cmd.error(chalk.yellow("\nAuthentication cancelled"));
|
|
162
|
+
}
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
let me;
|
|
167
|
+
const trpcClient = createTRPCClient(cliToken);
|
|
168
|
+
try {
|
|
169
|
+
me = await trpcClient.me.query();
|
|
170
|
+
} catch (error) {
|
|
171
|
+
cmd.log(chalk.red("Could not authenticate with Copilot Cloud. Please try again."));
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
if (!me.organization || !me.user) {
|
|
175
|
+
cmd.error("Authentication required to proceed.");
|
|
176
|
+
}
|
|
177
|
+
return { cliToken, user: me.user, organization: me.organization };
|
|
178
|
+
}
|
|
179
|
+
async login() {
|
|
180
|
+
let analytics;
|
|
181
|
+
analytics = new AnalyticsService();
|
|
182
|
+
const app = express();
|
|
183
|
+
app.use(cors());
|
|
184
|
+
app.use(express.urlencoded({ extended: true }));
|
|
185
|
+
app.use(express.json());
|
|
186
|
+
const port = await getPort();
|
|
187
|
+
const state = crypto2.randomBytes(16).toString("hex");
|
|
188
|
+
return new Promise((resolve) => {
|
|
189
|
+
const server = app.listen(port, () => {
|
|
190
|
+
});
|
|
191
|
+
analytics.track({
|
|
192
|
+
event: "cli.login.initiated",
|
|
193
|
+
properties: {}
|
|
194
|
+
});
|
|
195
|
+
const spinner = ora("Waiting for browser authentication to complete...\n").start();
|
|
196
|
+
app.post("/callback", async (req, res) => {
|
|
197
|
+
const { cliToken, user, organization } = req.body;
|
|
198
|
+
analytics = new AnalyticsService({ userId: user.id, organizationId: organization.id, email: user.email });
|
|
199
|
+
analytics.track({
|
|
200
|
+
event: "cli.login.success",
|
|
201
|
+
properties: {
|
|
202
|
+
organizationId: organization.id,
|
|
203
|
+
userId: user.id,
|
|
204
|
+
email: user.email
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
if (state !== req.query.state) {
|
|
208
|
+
res.status(401).json({ message: "Invalid state" });
|
|
209
|
+
spinner.fail("Invalid state");
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
this.config.set("cliToken", cliToken);
|
|
213
|
+
res.status(200).json({ message: "Callback called" });
|
|
214
|
+
spinner.succeed(`\u{1FA81} Successfully logged in as ${chalk.hex("#7553fc")(user.email)}
|
|
215
|
+
`);
|
|
216
|
+
server.close();
|
|
217
|
+
resolve({
|
|
218
|
+
cliToken,
|
|
219
|
+
organization,
|
|
220
|
+
user
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
open(`${this.COPILOT_CLOUD_BASE_URL}/cli-auth?callbackUrl=http://localhost:${port}/callback&state=${state}`);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/commands/base-command.ts
|
|
229
|
+
import { Command } from "@oclif/core";
|
|
230
|
+
import Sentry, { consoleIntegration } from "@sentry/node";
|
|
231
|
+
|
|
232
|
+
// src/utils/version.ts
|
|
233
|
+
var LIB_VERSION = "0.0.5";
|
|
234
|
+
|
|
235
|
+
// src/commands/base-command.ts
|
|
236
|
+
import chalk2 from "chalk";
|
|
237
|
+
var BaseCommand = class extends Command {
|
|
238
|
+
async init() {
|
|
239
|
+
await this.checkCLIVersion();
|
|
240
|
+
if (process.env.SENTRY_DISABLED === "true") {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
Sentry.init({
|
|
244
|
+
dsn: process.env.SENTRY_DSN || "https://1eea15d32e2eacb0456a77db5e39aeeb@o4507288195170304.ingest.us.sentry.io/4508581448581120",
|
|
245
|
+
integrations: [
|
|
246
|
+
consoleIntegration()
|
|
247
|
+
],
|
|
248
|
+
// Tracing
|
|
249
|
+
tracesSampleRate: 1
|
|
250
|
+
// Capture 100% of the transactions
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
async catch(err) {
|
|
254
|
+
if (process.env.SENTRY_DISABLED === "true") {
|
|
255
|
+
super.catch(err);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
Sentry.captureException(err);
|
|
259
|
+
super.catch(err);
|
|
260
|
+
}
|
|
261
|
+
async finally() {
|
|
262
|
+
if (process.env.SENTRY_DISABLED === "true") {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
Sentry.close();
|
|
266
|
+
}
|
|
267
|
+
async run() {
|
|
268
|
+
}
|
|
269
|
+
async checkCLIVersion() {
|
|
270
|
+
const response = await fetch(`${COPILOT_CLOUD_BASE_URL}/api/healthz`);
|
|
271
|
+
const data = await response.json();
|
|
272
|
+
const cloudVersion = data.cliVersion;
|
|
273
|
+
if (cloudVersion === LIB_VERSION) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
this.log(chalk2.yellow("================ New version available! =================\n"));
|
|
277
|
+
this.log(`A new CopilotKit CLI version is available (${LIB_VERSION}).
|
|
278
|
+
`);
|
|
279
|
+
this.log("Please update your CLI to the latest version:\n\n");
|
|
280
|
+
this.log(`${chalk2.cyan(chalk2.underline(chalk2.bold("npm:")))} npm install -g copilotkit@${LIB_VERSION}
|
|
281
|
+
`);
|
|
282
|
+
this.log(`${chalk2.cyan(chalk2.underline(chalk2.bold("pnpm:")))} pnpm install -g copilotkit@${LIB_VERSION}
|
|
283
|
+
`);
|
|
284
|
+
this.log(`${chalk2.cyan(chalk2.underline(chalk2.bold("yarn:")))} yarn global add copilotkit@${LIB_VERSION}
|
|
285
|
+
`);
|
|
286
|
+
process.exit(0);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// src/commands/logout.ts
|
|
291
|
+
var CloudLogout = class _CloudLogout extends BaseCommand {
|
|
292
|
+
constructor(argv, config, authService = new AuthService()) {
|
|
293
|
+
super(argv, config);
|
|
294
|
+
this.authService = authService;
|
|
295
|
+
}
|
|
296
|
+
static description = "Authenticate with Copilot Cloud";
|
|
297
|
+
static examples = ["<%= config.bin %> logout"];
|
|
298
|
+
async run() {
|
|
299
|
+
await this.parse(_CloudLogout);
|
|
300
|
+
const spinner = ora2("Logging out...\n").start();
|
|
301
|
+
await this.authService.logout();
|
|
302
|
+
spinner.succeed(chalk3.green("Successfully logged out!"));
|
|
303
|
+
spinner.stop();
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
export {
|
|
307
|
+
CloudLogout as default
|
|
308
|
+
};
|
|
309
|
+
//# sourceMappingURL=logout.js.map
|