// shared/workspaceAgentProviderLabel.ts
function workspaceAgentProviderLabel(provider) {
  const normalized = provider.trim().toLowerCase();
  switch (normalized) {
    case "codex":
      return "Codex";
    case "claude-code":
      return "Claude Code";
    case "gemini":
      return "Gemini";
    case "openclaw":
      return "OpenClaw";
    case "hermes":
      return "Hermes";
    case "nexight":
      return "Nexight";
    case "unknown":
      return "Unknown";
    default:
      return titleCase(provider);
  }
}
function titleCase(value) {
  return value.split(/[-_\s]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
}

// shared/workspaceAgentSessionSortTime.ts
function resolveWorkspaceAgentSessionSortTimeUnixMs(session, context = {}) {
  const hasSortContext = hasWorkspaceAgentSessionSortContext(context);
  const fallbackUpdatedAtUnixMs = hasSortContext ? null : positiveNumber(session.updatedAtUnixMs);
  return latestUserTurnStartTimeUnixMs(session, context) ?? positiveNumber(session.endedAtUnixMs) ?? fallbackUpdatedAtUnixMs ?? positiveNumber(session.startedAtUnixMs) ?? positiveNumber(session.createdAtUnixMs) ?? positiveNumber(session.id) ?? 0;
}
function hasWorkspaceAgentSessionSortContext(context) {
  return Boolean(context.messages?.length);
}
function latestUserTurnStartTimeUnixMs(session, context) {
  const sessionIds = new Set(
    [session.agentSessionId, session.providerSessionId].map((value) => value?.trim()).filter((value) => Boolean(value))
  );
  const startsByTurnId = /* @__PURE__ */ new Map();
  for (const message of context.messages ?? []) {
    if (!matchesSession(message.agentSessionId, sessionIds)) {
      continue;
    }
    const turnId = message.turnId?.trim();
    if (!turnId) {
      continue;
    }
    const role = normalizeToken(message.role);
    if (role === "user") {
      const startedAtUnixMs = positiveNumber(message.occurredAtUnixMs);
      if (startedAtUnixMs !== null) {
        startsByTurnId.set(
          turnId,
          minNullable(startsByTurnId.get(turnId) ?? null, startedAtUnixMs)
        );
      }
    }
  }
  let latest = null;
  for (const startedAtUnixMs of startsByTurnId.values()) {
    latest = latest === null ? startedAtUnixMs : Math.max(latest, startedAtUnixMs);
  }
  return latest;
}
function matchesSession(agentSessionId, sessionIds) {
  if (sessionIds.size === 0) {
    return true;
  }
  const normalized = agentSessionId?.trim();
  return Boolean(normalized && sessionIds.has(normalized));
}
function minNullable(left, right) {
  if (left === null) {
    return right;
  }
  if (right === null) {
    return left;
  }
  return Math.min(left, right);
}
function normalizeToken(value) {
  return value?.trim().toLowerCase() ?? "";
}
function positiveNumber(value) {
  return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : null;
}

export {
  workspaceAgentProviderLabel,
  resolveWorkspaceAgentSessionSortTimeUnixMs
};
//# sourceMappingURL=chunk-3D5VTIKP.js.map