{"version":3,"file":"telemetry-client.mjs","names":[],"sources":["../../../src/v1-deprecated/lib/telemetry-client.ts"],"sourcesContent":["import { TelemetryClient } from \"@copilotkit/shared/telemetry\";\nimport { createHash } from \"node:crypto\";\nimport { CopilotRuntime, resolveEndpointType } from \"./runtime/copilot-runtime\";\nimport type { RuntimeInstanceCreatedInfo } from \"@copilotkit/shared/src/telemetry/events\";\nimport type { CreateCopilotRuntimeServerOptions } from \"./integrations/shared\";\nimport type { LangGraphPlatformEndpoint } from \"./runtime/types\";\nimport { EndpointType } from \"./runtime/types\";\nconst packageJson = require(\"../../../package.json\");\n\nconst telemetryClient = new TelemetryClient({\n  packageName: packageJson.name,\n  packageVersion: packageJson.version,\n});\n\n/**\n * The configured agents, counted without touching `runtime.instance`. Every\n * v1 endpoint captures telemetry before it calls `handleServiceAdapter`, and\n * reading the instance there builds the v2 runtime with these agents, so the\n * per-request factory `handleServiceAdapter` installs afterwards was never\n * used and no v1 `actions` or `mcpServers` tool reached an agent.\n */\nfunction countConfiguredAgents(agents: unknown): number {\n  if (!agents || typeof agents !== \"object\" || \"then\" in agents) {\n    return 0;\n  }\n  return Object.keys(agents).length;\n}\n\nexport function getRuntimeInstanceTelemetryInfo(\n  options: CreateCopilotRuntimeServerOptions,\n): RuntimeInstanceCreatedInfo {\n  const runtime = options.runtime;\n  const remoteEndpoints = runtime.params?.remoteEndpoints ?? [];\n  const endpointsInfo = remoteEndpoints.reduce(\n    (acc, endpoint) => {\n      let info = { ...acc };\n\n      const endpointType = resolveEndpointType(endpoint);\n      if (!info.endpointTypes.includes(endpointType)) {\n        info = {\n          ...info,\n          endpointTypes: [...info.endpointTypes, endpointType],\n        };\n      }\n\n      if (endpointType === EndpointType.LangGraphPlatform) {\n        // When type is resolved, recreating a const with casting of type\n        const ep = endpoint as LangGraphPlatformEndpoint;\n        info = {\n          ...info,\n          agentsAmount: ep.agents.length,\n          hashedKey: ep.langsmithApiKey\n            ? createHash(\"sha256\").update(ep.langsmithApiKey).digest(\"hex\")\n            : null,\n        };\n      }\n\n      return info;\n    },\n    { endpointTypes: [], agentsAmount: null, hashedKey: null },\n  );\n\n  // Get public API key from options.cloud.publicApiKey\n  const publicApiKey = options.cloud?.publicApiKey;\n  const apiKeyProvided = !!publicApiKey && publicApiKey.trim().length > 0;\n\n  return {\n    actionsAmount: runtime.params?.actions?.length ?? 0,\n    endpointsAmount: remoteEndpoints.length,\n    endpointTypes: endpointsInfo.endpointTypes,\n    agentsAmount: countConfiguredAgents(runtime.params?.agents),\n    hashedLgcKey: endpointsInfo.hashedKey,\n    \"cloud.api_key_provided\": apiKeyProvided,\n    ...(apiKeyProvided ? { \"cloud.public_api_key\": publicApiKey } : {}),\n    ...(options.cloud?.baseUrl\n      ? { \"cloud.base_url\": options.cloud.baseUrl }\n      : {}),\n  } as RuntimeInstanceCreatedInfo;\n}\n\nexport default telemetryClient;\n"],"mappings":";;;;;;;;AAOA,MAAM;AAEN,MAAM,kBAAkB,IAAI,gBAAgB;CAC1C,aAAa,YAAY;CACzB,gBAAgB,YAAY;CAC7B,CAAC;;;;;;;;AASF,SAAS,sBAAsB,QAAyB;AACtD,KAAI,CAAC,UAAU,OAAO,WAAW,YAAY,UAAU,OACrD,QAAO;AAET,QAAO,OAAO,KAAK,OAAO,CAAC;;AAG7B,SAAgB,gCACd,SAC4B;CAC5B,MAAM,UAAU,QAAQ;CACxB,MAAM,kBAAkB,QAAQ,QAAQ,mBAAmB,EAAE;CAC7D,MAAM,gBAAgB,gBAAgB,QACnC,KAAK,aAAa;EACjB,IAAI,OAAO,EAAE,GAAG,KAAK;EAErB,MAAM,eAAe,oBAAoB,SAAS;AAClD,MAAI,CAAC,KAAK,cAAc,SAAS,aAAa,CAC5C,QAAO;GACL,GAAG;GACH,eAAe,CAAC,GAAG,KAAK,eAAe,aAAa;GACrD;AAGH,MAAI,iBAAiB,aAAa,mBAAmB;GAEnD,MAAM,KAAK;AACX,UAAO;IACL,GAAG;IACH,cAAc,GAAG,OAAO;IACxB,W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