import { z } from 'zod';

const TranscriptSegmentSchema = z.object({
  text: z.string(),
  role: z.string(),
  // 'Agent' or 'User'
  time: z.string(),
  // ISO timestamp
  duration: z.number()
});
const ConversationSchema = z.object({
  conversationId: z.string(),
  medium: z.string(),
  // 'phone' | 'whatsapp' | ...
  agentId: z.string().optional(),
  phoneNumber: z.string().optional(),
  duration: z.number().optional(),
  audioUrl: z.string().url().optional(),
  transcript: z.union([z.string(), z.array(TranscriptSegmentSchema)]).optional(),
  createdAt: z.number()
}).passthrough();
const PaginatedConversationsResponseSchema = z.object({
  limit: z.number(),
  items: z.array(ConversationSchema),
  lastConversationId: z.string().optional()
});
const LlmUsageSchema = z.object({
  promptTokens: z.number().optional(),
  completionTokens: z.number().optional(),
  totalTokens: z.number().optional(),
  cachedPromptTokens: z.number().optional()
}).passthrough();
const StepTraceSchema = z.object({
  traceType: z.literal("STEP"),
  traceId: z.string().optional(),
  conversationId: z.string().optional(),
  scopeId: z.string().optional(),
  workflowId: z.string().optional(),
  workflowRunId: z.string().optional(),
  name: z.string().optional(),
  renderedPrompt: z.string().optional(),
  receivedContext: z.any().optional(),
  receivedPrompt: z.any().optional(),
  stringifiedConversation: z.string().optional(),
  response: z.string().optional(),
  model: z.string().optional(),
  llmUsage: LlmUsageSchema.optional(),
  createdAt: z.number(),
  error: z.any().optional()
}).passthrough();
const ApiCallTraceSchema = z.object({
  traceType: z.literal("API_CALL"),
  traceId: z.string().optional(),
  conversationId: z.string().optional(),
  scopeId: z.string().optional(),
  operationName: z.string(),
  method: z.string(),
  path: z.string(),
  baseUrl: z.string().optional(),
  request: z.any().optional(),
  response: z.any().optional(),
  status: z.number().optional(),
  ok: z.boolean().optional(),
  durationMs: z.number().optional(),
  createdAt: z.number(),
  error: z.any().optional()
}).passthrough();
const ConversationalTraceSchema = z.object({
  traceType: z.literal("CONVERSATIONAL"),
  traceId: z.string().optional(),
  conversationId: z.string().optional(),
  scopeId: z.string().optional(),
  eventName: z.string(),
  role: z.string(),
  medium: z.string(),
  content: z.string(),
  createdAt: z.number(),
  error: z.any().optional()
}).passthrough();
const TraceSchema = z.discriminatedUnion("traceType", [
  StepTraceSchema,
  ApiCallTraceSchema,
  ConversationalTraceSchema
]);
const PaginatedTracesResponseSchema = z.object({
  items: z.array(TraceSchema),
  limit: z.number(),
  lastTraceId: z.string().optional()
});
const TELESCOPE_SOURCE_STORAGE_KEY = "bosun.traces.telescopeSourceId";
function getPersistedTelescopeSourceId() {
  if (typeof window === "undefined") return null;
  try {
    return window.localStorage.getItem(TELESCOPE_SOURCE_STORAGE_KEY);
  } catch {
    return null;
  }
}
function persistTelescopeSourceId(sourceId) {
  if (typeof window === "undefined") return;
  if (!sourceId || !sourceId.trim()) return;
  try {
    window.localStorage.setItem(TELESCOPE_SOURCE_STORAGE_KEY, sourceId);
  } catch {
  }
}

export { ConversationSchema as C, PaginatedConversationsResponseSchema as P, PaginatedTracesResponseSchema as a, getPersistedTelescopeSourceId as g, persistTelescopeSourceId as p };
//# sourceMappingURL=source-selection-hOQHZ-fn.js.map
