mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
61f0b629ea
The self-hosting pages are heavy on helm install, kubectl apply, and shell-script invocations — without these in KNOWN_INSTALL_TYPES they all bucket as "code" and the self-hosting funnel goes blind to install method. Skips sudo deliberately: it's a wrapper that would swallow the real installer in the funnel. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
51 lines
1.0 KiB
TypeScript
51 lines
1.0 KiB
TypeScript
import type { PostHog } from "posthog-js";
|
|
|
|
const KNOWN_INSTALL_TYPES = [
|
|
"npx",
|
|
"npm",
|
|
"pnpm",
|
|
"yarn",
|
|
"bun",
|
|
"pip",
|
|
"uv",
|
|
"poetry",
|
|
"cargo",
|
|
"go",
|
|
"docker",
|
|
"curl",
|
|
"brew",
|
|
"helm",
|
|
"kubectl",
|
|
"make",
|
|
"bash",
|
|
"sh",
|
|
] as const;
|
|
|
|
export type InstallType = (typeof KNOWN_INSTALL_TYPES)[number] | "code";
|
|
|
|
function inferInstallType(command: string): InstallType {
|
|
const firstToken = command.trim().split(/\s+/)[0]?.toLowerCase();
|
|
if (!firstToken) return "code";
|
|
return (KNOWN_INSTALL_TYPES as readonly string[]).includes(firstToken)
|
|
? (firstToken as InstallType)
|
|
: "code";
|
|
}
|
|
|
|
export type TrackCommandCopyArgs = {
|
|
command: string;
|
|
location?: string;
|
|
};
|
|
|
|
export function trackCommandCopy(
|
|
posthog: PostHog | undefined,
|
|
{ command, location }: TrackCommandCopyArgs,
|
|
) {
|
|
if (!posthog) return;
|
|
const trimmed = command.trim();
|
|
if (!trimmed) return;
|
|
posthog.capture("cli_command_copied", {
|
|
install_type: inferInstallType(trimmed),
|
|
...(location ? { location } : {}),
|
|
});
|
|
}
|