// @bun
import {
  telemetry_default
} from "./chunk-c18d2qwm.js";
import {
  getAdkVersion
} from "./chunk-p4n31dgt.js";
import {
  AgentProject,
  auth,
  workspaceCache
} from "./chunk-7krp2mgz.js";

// src/utils/telemetry-identify.ts
async function identifyUser(projectPath) {
  try {
    const profile = await auth.getCurrentProfileDetails();
    if (!profile)
      return;
    const credentials = await auth.getActiveCredentials();
    const properties = {
      email: profile.email,
      userId: profile.accountId,
      userCreatedAt: profile.createdAt
    };
    if (credentials.workspaceId) {
      properties.workspaceId = credentials.workspaceId;
      try {
        const workspaceName = await workspaceCache.getWorkspaceName(credentials.workspaceId);
        if (workspaceName) {
          properties.workspaceName = workspaceName;
        }
      } catch {}
    }
    if (projectPath) {
      try {
        const project = await AgentProject.load(projectPath);
        if (project.agentInfo) {
          if (project.agentInfo.botId) {
            properties.botId = project.agentInfo.botId;
          }
          if (project.agentInfo.workspaceId) {
            properties.workspaceId = project.agentInfo.workspaceId;
          }
        }
      } catch {}
    }
    if (properties.userId) {
      telemetry_default.identify(properties.userId, properties);
      telemetry_default.track("environment", {
        os: process.platform,
        node_version: process.version,
        bun_version: process.versions.bun,
        adk_version: getAdkVersion()
      });
    }
  } catch {}
}
async function updateBotContext(botId, botName) {
  try {
    const profile = await auth.getCurrentProfileDetails();
    if (!profile || !profile.accountId)
      return;
    telemetry_default.identify(profile.accountId, {
      botId,
      botName
    });
  } catch {}
}

export { identifyUser, updateBotContext };
