forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase-command.ts
More file actions
77 lines (62 loc) · 2.46 KB
/
Copy pathbase-command.ts
File metadata and controls
77 lines (62 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Command } from "@oclif/core";
import Sentry, { consoleIntegration } from "@sentry/node";
import { LIB_VERSION } from "../utils/version.js";
import { COPILOT_CLOUD_BASE_URL } from "../utils/trpc.js";
import chalk from "chalk";
export class BaseCommand extends Command {
async init() {
await this.checkCLIVersion();
if (process.env.SENTRY_DISABLED === "true") {
return;
}
Sentry.init({
dsn:
process.env.SENTRY_DSN ||
"https://1eea15d32e2eacb0456a77db5e39aeeb@o4507288195170304.ingest.us.sentry.io/4508581448581120",
integrations: [consoleIntegration()],
// Tracing
tracesSampleRate: 1.0, // Capture 100% of the transactions
});
}
async catch(err: any) {
if (process.env.SENTRY_DISABLED !== "true") {
Sentry.captureException(err);
}
const message = err?.message ?? "Unknown error";
this.log("\n" + chalk.red(message) + "\n");
const exitCode = err?.oclif?.exit ?? 1;
this.exit(exitCode);
}
async finally() {
if (process.env.SENTRY_DISABLED === "true") {
return;
}
Sentry.close();
}
async run() {}
async checkCLIVersion() {
try {
const response = await fetch(`${COPILOT_CLOUD_BASE_URL}/api/healthz`);
const data = await response.json();
const cloudVersion = data.cliVersion;
if (!cloudVersion || cloudVersion === LIB_VERSION) {
return;
}
// TODO: add this back in, removed for crew ai launch since we don't want to keep releasing cloud
// this.log(chalk.yellow('================ New version available! =================\n'))
// this.log(`You are using CopilotKit CLI v${LIB_VERSION}.`)
// this.log(`A new CopilotKit CLI version is available (v${cloudVersion}).\n`)
// this.log('Please update your CLI to the latest version:\n\n')
// this.log(`${chalk.cyan(chalk.underline(chalk.bold('npm:')))}\t npm install -g copilotkit@${cloudVersion}\n`)
// this.log(`${chalk.cyan(chalk.underline(chalk.bold('pnpm:')))}\t pnpm install -g copilotkit@${cloudVersion}\n`)
// this.log(`${chalk.cyan(chalk.underline(chalk.bold('yarn:')))}\t yarn global add copilotkit@${cloudVersion}\n`)
// this.log(chalk.yellow('============================================================\n\n'))
} catch {
// Version check is non-critical — don't crash the CLI when offline
}
}
async gracefulError(message: string) {
this.log("\n" + chalk.red(message));
process.exit(1);
}
}