Files
copilotkit__copilotkit/docs/lib/track-command-copy.ts
Benjamin Taylor 61f0b629ea feat(docs): extend cli_command_copied install_type with infra CLIs
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>
2026-05-05 05:28:17 -07:00

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 } : {}),
});
}