Files
copilotkit__copilotkit/packages/runtime/src/lib/telemetry-client.ts
Tyler Slaton 96885b5959 refactor: consolidate V1/V2 packages into flat @copilotkit/* structure
Flatten all packages from packages/v1/* and packages/v2/* into packages/* —
every package now lives directly under the @copilotkit/ scope with no v1/v2
subdirectories.

- Move all v1 packages (react-core, react-ui, runtime, shared, etc.) from
  packages/v1/* to packages/*
- Absorb v2 react code into packages/react-core/src/v2/ (exported via /v2 subpath)
- Absorb v2 agent code into packages/runtime/src/agent/ (exported via /v2 subpath)
- Move v2 packages (core, angular, demo-agents, etc.) to packages/*
- Replace all @copilotkitnext/* imports with @copilotkit/* equivalents
- Keep @copilotkitnext/angular as the sole exception (angular remains on next)
- Update CI workflows, renovate config, release scripts for flat structure
- No public API surface changes — all exports fields are preserved

Co-authored-by: Alem Tuzlak <t.zlak@hotmail.com>
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
2026-03-28 16:45:10 -07:00

67 lines
2.4 KiB
TypeScript

import { TelemetryClient } from "@copilotkit/shared";
import { createHash } from "node:crypto";
import { CopilotRuntime, resolveEndpointType } from "./runtime/copilot-runtime";
import { RuntimeInstanceCreatedInfo } from "@copilotkit/shared/src/telemetry/events";
import { CreateCopilotRuntimeServerOptions } from "./integrations/shared";
import { EndpointType, LangGraphPlatformEndpoint } from "./runtime/types";
const packageJson = require("../../package.json");
const telemetryClient = new TelemetryClient({
packageName: packageJson.name,
packageVersion: packageJson.version,
});
export function getRuntimeInstanceTelemetryInfo(
options: CreateCopilotRuntimeServerOptions,
): RuntimeInstanceCreatedInfo {
const runtime = options.runtime;
const remoteEndpoints = runtime.params?.remoteEndpoints ?? [];
const endpointsInfo = remoteEndpoints.reduce(
(acc, endpoint) => {
let info = { ...acc };
const endpointType = resolveEndpointType(endpoint);
if (!info.endpointTypes.includes(endpointType)) {
info = {
...info,
endpointTypes: [...info.endpointTypes, endpointType],
};
}
if (endpointType === EndpointType.LangGraphPlatform) {
// When type is resolved, recreating a const with casting of type
const ep = endpoint as LangGraphPlatformEndpoint;
info = {
...info,
agentsAmount: ep.agents.length,
hashedKey: ep.langsmithApiKey
? createHash("sha256").update(ep.langsmithApiKey).digest("hex")
: null,
};
}
return info;
},
{ endpointTypes: [], agentsAmount: null, hashedKey: null },
);
// Get public API key from options.cloud.publicApiKey
const publicApiKey = options.cloud?.publicApiKey;
const apiKeyProvided = !!publicApiKey && publicApiKey.trim().length > 0;
return {
actionsAmount: runtime.params?.actions?.length ?? 0,
endpointsAmount: remoteEndpoints.length,
endpointTypes: endpointsInfo.endpointTypes,
agentsAmount: Object.keys(runtime.instance.agents).length,
hashedLgcKey: endpointsInfo.hashedKey,
"cloud.api_key_provided": apiKeyProvided,
...(apiKeyProvided ? { "cloud.public_api_key": publicApiKey } : {}),
...(options.cloud?.baseUrl
? { "cloud.base_url": options.cloud.baseUrl }
: {}),
} as RuntimeInstanceCreatedInfo;
}
export default telemetryClient;