{"version":3,"file":"index.mjs","names":[],"sources":["../src/client.ts","../src/config.ts"],"sourcesContent":["import { createORPCClient, createSafeClient } from \"@orpc/client\";\nimport { RPCLink } from \"@orpc/client/fetch\";\n\nexport type RpcProcedure<Input = unknown, Output = unknown> = (\n  input?: Input\n) => Promise<readonly [unknown, Output, ...unknown[]]>;\n\nexport type ThrowingRpcProcedure<Input = unknown, Output = unknown> = (\n  input?: Input\n) => Promise<Output>;\n\nexport type EntityType =\n  | \"person\"\n  | \"event\"\n  | \"action\"\n  | \"knowledge\"\n  | \"document\";\n\nexport type JsonValue =\n  | boolean\n  | number\n  | string\n  | null\n  | JsonValue[]\n  | { [key: string]: JsonValue };\n\nexport interface AddMemoryInput {\n  memory: string;\n  observationDate?: string;\n  source?: string;\n  lobeKey?: string;\n}\n\nexport interface AddMemoryOutput {\n  queued: boolean;\n  workflowId: string;\n}\n\nexport interface AddMemoryRecallInput {\n  memory: string;\n  observationDate?: string;\n}\n\nexport interface AddMemoryRecallOutput {\n  processing: true;\n  status: \"enqueued\";\n}\n\nexport interface AddMemoriesInput {\n  memories: {\n    memory: string;\n    observationDate?: string;\n    source?: string;\n    lobeKey?: string;\n  }[];\n}\n\nexport interface AddMemoriesOutput {\n  failures: { error: string; groupKey: string | null }[];\n  queued: number;\n  workflowId: string;\n}\n\nexport interface FindMemoryEntitiesInput {\n  name: string;\n  type?: EntityType;\n  limit?: number;\n}\n\nexport interface MemoriesByEntityInput {\n  entityId: string;\n  limit?: number;\n}\n\nexport interface MemoriesByDateInput {\n  start?: string;\n  end?: string;\n  limit?: number;\n}\n\nexport interface MemoryRecallResult {\n  category: string | null;\n  content: string;\n  id: string;\n  lobeKey: string;\n  recordedAt: string;\n}\n\nexport interface FindMemoryEntitiesOutput {\n  entities: {\n    displayName: string;\n    id: string;\n    memoryCount: number;\n    name: string;\n    type: EntityType;\n  }[];\n  suggestedNextAction: {\n    entityIds: string[];\n    tool: \"search_memories_by_entity\";\n    when: string;\n  } | null;\n}\n\nexport interface SearchMemoryRecallInput {\n  limit?: number;\n  query: string;\n}\n\nexport interface SearchMemoryRecallOutput {\n  memories: MemoryRecallResult[];\n  suggestedNextAction: {\n    consentRequired: true;\n    tool: \"add_memory\";\n    when: string;\n  } | null;\n}\n\nexport interface MemoriesByEntityOutput {\n  entity: {\n    displayName: string;\n    id: string;\n    type: EntityType;\n  };\n  memories: MemoryRecallResult[];\n}\n\nexport interface MemoriesByDateOutput {\n  memories: MemoryRecallResult[];\n  range: {\n    end: string | null;\n    start: string | null;\n  };\n}\n\nexport interface MemoryOverviewOutput {\n  account: {\n    name: string;\n    numberOfAiTools: number | null;\n    preferredMessagingChannel: string | null;\n    primaryRole: string | null;\n    workplace: string | null;\n  };\n  profile: {\n    facts: Omit<MemoryRecallResult, \"id\">[];\n    ongoingContext: Omit<MemoryRecallResult, \"id\">[];\n    scope: string;\n    suggestions: {\n      expiresAt: string | null;\n      text: string;\n    }[];\n    updatedAt: string;\n  } | null;\n  suggestedNextAction: {\n    tool: \"search_memory\";\n    when: string;\n  };\n}\n\nexport interface ListLivingDocumentsInput {\n  status?: (\"enabled\" | \"disabled\" | \"archived\")[];\n}\n\nexport type LivingDocumentStatus = \"enabled\" | \"disabled\" | \"archived\";\n\nexport interface LivingDocument {\n  autoPublish: boolean;\n  createdAt: string;\n  currentApprovedVersionId: string | null;\n  currentVersionId: string | null;\n  description: string | null;\n  entities: string[];\n  extractionPrompt: string;\n  id: string;\n  patchFailureCount: number;\n  routingSummary: string | null;\n  routingSummaryDirty: boolean;\n  status: LivingDocumentStatus;\n  title: string;\n  triggerKeywords: string[];\n  updatedAt: string;\n}\n\nexport interface LivingDocumentVersion {\n  causedByMemoryIds: string[];\n  causedByRunId: string | null;\n  contentMd: string;\n  contentMdSummary: string | null;\n  createdAt: string;\n  documentId: string;\n  extractorModel: string | null;\n  id: string;\n  parentVersionId: string | null;\n  patch: JsonValue;\n  updatedAt: string;\n  versionNumber: number;\n}\n\nexport interface LivingDocumentShare {\n  createdAt: string;\n  documentId: string;\n  expiresAt: string | null;\n  id: string;\n  mode: \"pinned\" | \"live\";\n  permissions: \"view\" | \"view+comment\";\n  revokedAt: string | null;\n  shareToken: string;\n  updatedAt: string;\n  versionId: string | null;\n}\n\nexport interface ListLivingDocumentsOutput {\n  documents: LivingDocument[];\n  slots: {\n    limit: number;\n    plan: string;\n    remaining: number;\n    used: number;\n  };\n}\n\nexport interface ListLivingDocumentsRecallOutput {\n  documents: {\n    autoPublish: boolean;\n    currentVersion: { createdAt: string; number: number } | null;\n    id: string;\n    status: string;\n    summary: string;\n    title: string;\n  }[];\n}\n\nexport interface ReadLivingDocumentRecallInput {\n  documentId: string;\n}\n\nexport interface ReadLivingDocumentRecallOutput {\n  document: {\n    activeShares: {\n      expiresAt: string | null;\n      mode: string;\n      permissions: string;\n      url: string;\n      versionId: string | null;\n    }[];\n    autoPublish: boolean;\n    currentVersion: {\n      contentMarkdown: string;\n      createdAt: string;\n      id: string;\n      number: number;\n    } | null;\n    description: string | null;\n    entities: string[];\n    headings: string[];\n    id: string;\n    status: string;\n    summary: string;\n    title: string;\n    triggerKeywords: string[];\n  };\n}\n\nexport interface GetLivingDocumentOutput {\n  currentVersion: LivingDocumentVersion | null;\n  document: LivingDocument;\n}\n\nexport interface ListLivingDocumentSharesOutput {\n  shares: LivingDocumentShare[];\n}\n\nexport interface GetLivingDocumentInput {\n  id: string;\n}\n\nexport interface ListLivingDocumentSharesInput {\n  documentId: string;\n}\n\nexport interface AddChatSessionInput {\n  memories: {\n    memory: string;\n    source?: string;\n  }[];\n  lobeKey?: string;\n  source?: string;\n  sessionMetadata?: Record<string, unknown>;\n}\n\nexport interface AddChatSessionOutput {\n  queued: number;\n  workflowId: string;\n}\n\nexport interface AddChatSessionsInput {\n  lobeKey?: string;\n  source?: string;\n  questionMetadata?: Record<string, unknown>;\n  /**\n   * Override the V3 extractor's prompt profile.\n   *   - `general`        — default chat-ingest extraction.\n   *   - `agent`          — agent-scoped ingests (no user, only agent_id).\n   *   - `code-personal`  — coding-session bias (developer intent over\n   *                        assistant scaffolding, code-specific entities).\n   * When omitted, the server resolves a profile from `source`\n   * (e.g. `claude-code` → `code-personal`); use this only to override\n   * that mapping or for sources the server hasn't pre-mapped.\n   */\n  extractionProfile?: \"general\" | \"agent\" | \"code-personal\";\n  /**\n   * Optional idempotency key (1-64 chars, [A-Za-z0-9_-]). When supplied,\n   * retries with the same key short-circuit on the server instead of\n   * re-running the ingest pipeline. Derive deterministically from\n   * (sessionId, turnRange) so retries collide but distinct flushes do not.\n   */\n  idempotencyKey?: string;\n  sessions: {\n    sessionId: string;\n    metadata?: Record<string, unknown>;\n    turns: {\n      content: string;\n      role: \"user\" | \"assistant\";\n      speaker?: string;\n      turnIndex: number;\n    }[];\n  }[];\n}\n\nexport interface AddChatSessionsOutput {\n  queuedSessions: number;\n  workflowId: string;\n}\n\nexport interface SearchMemoriesInput {\n  query: string;\n  lobeKey?: string;\n  limit?: number;\n  threshold?: number;\n  mode?: \"fast\" | \"adaptive\" | \"reflective\";\n  graph?: {\n    enabled?: boolean;\n    maxNeighborsPerSeed?: number;\n    maxTotalNeighbors?: number;\n  };\n}\n\nexport interface SearchMemoryHit {\n  category: string | null;\n  content: string;\n  id: string;\n  memoryDate: string;\n  score: number;\n  summary: string | null;\n}\n\nexport interface MemoryStatusInput {\n  lobeKey?: string;\n}\n\nexport interface MemoryStatusOutput {\n  count: number;\n}\n\nexport interface ClearLobeInput {\n  lobeKey: string;\n}\n\nexport interface ClearLobeOutput {\n  deleted: number;\n}\n\nexport interface MemoryListItem {\n  category: string | null;\n  content: string;\n  createdAt: string;\n  expiresAt: string | null;\n  id: string;\n  isCurrent: string;\n  lobeKey: string;\n  memoryAt: string | null;\n  memoryKind: string;\n  metadata: JsonValue | null;\n  summary: string | null;\n  supersededByMemoryId: string | null;\n  updatedAt: string;\n}\n\nexport interface AuthSessionOutput {\n  session: {\n    createdAt: string | null;\n    expiresAt: string | null;\n    id: string;\n    ipAddress: string | null;\n    token: string;\n    updatedAt: string | null;\n    userAgent: string | null;\n    userId: string;\n  };\n  user: {\n    createdAt: string | null;\n    email: string;\n    emailVerified: boolean;\n    id: string;\n    image: string | null;\n    name: string;\n    onboardingComplete: boolean;\n    updatedAt: string | null;\n  };\n}\n\nexport type UsagePlan = \"free\" | \"beta\";\nexport type UsageMeter =\n  | \"assistant_messages\"\n  | \"automation_executions\"\n  | \"llm_tokens\"\n  | \"memory_processed\";\n\nexport interface UsageMeterSummary {\n  allowed: boolean;\n  current: number;\n  limit: number | null;\n  meter: UsageMeter;\n  periodKey: string;\n  plan: UsagePlan;\n  remaining: number | null;\n  userId: string;\n}\n\nexport interface UsageSummaryOutput {\n  billing: {\n    hasPaidPlan: boolean;\n    plan: UsagePlan;\n    scheduledDowngradeAt: string | null;\n  };\n  llm: {\n    byModel: {\n      inputTokens: number;\n      model: string;\n      outputTokens: number;\n      provider: string;\n      requests: number;\n      totalTokens: number;\n    }[];\n    bySurface: {\n      inputTokens: number;\n      outputTokens: number;\n      requests: number;\n      surface: string;\n      totalTokens: number;\n    }[];\n    recentRequests: {\n      cachedInputTokens: number;\n      createdAt: string;\n      id: string;\n      inputTokens: number;\n      model: string;\n      outputTokens: number;\n      provider: string;\n      reasoningTokens: number;\n      requestId: string | null;\n      surface: string;\n      totalTokens: number;\n    }[];\n    totals: {\n      cachedInputTokens: number;\n      inputTokens: number;\n      outputTokens: number;\n      reasoningTokens: number;\n      requests: number;\n      totalTokens: number;\n    };\n  };\n  meters: {\n    automationExecutions: UsageMeterSummary;\n    llmTokens: UsageMeterSummary;\n    memoryProcessed: UsageMeterSummary;\n  };\n  periodStart: string;\n  plan: UsagePlan;\n  plans: {\n    automations: number | null;\n    id: UsagePlan;\n    memories: number | null;\n    tokens: number | null;\n  }[];\n}\n\nexport interface GetSessionStartContextInput {\n  /**\n   * Restrict to a single lobe. Plugin callers pass `cc:<repo-slug>` so memory\n   * is scoped to the active project. Omit to read across every lobe.\n   */\n  lobeKey?: string;\n  /**\n   * Short retrieval hints biased toward what the caller is about to do\n   * (e.g. current git branch name, last commit subject, cwd basename).\n   * Cap: 5 hints × 200 chars.\n   */\n  recentHints?: string[];\n  /**\n   * Caller-side budget. Server hard caps both numbers regardless.\n   */\n  budget?: {\n    /** Default 15, hard cap 30. */\n    maxMemories?: number;\n    /** Default 2000, hard cap 4000. Char-based estimate (chars / 4). */\n    maxTokens?: number;\n  };\n}\n\nexport interface GetSessionStartContextOutput {\n  /** Markdown block ready to drop into a hook's `additionalContext`. */\n  markdown: string;\n  /** IDs of every memory referenced in the markdown. */\n  memoryIds: string[];\n  /** True when the response was truncated by the budget. */\n  hasMore: boolean;\n  /** Server-side ISO 8601 timestamp the context was generated. */\n  generatedAt: string;\n}\n\ninterface MerraiProcedureContract {\n  addChatSession: {\n    input: AddChatSessionInput;\n    output: AddChatSessionOutput;\n  };\n  addChatSessions: {\n    input: AddChatSessionsInput;\n    output: AddChatSessionsOutput;\n  };\n  addMemories: { input: AddMemoriesInput; output: AddMemoriesOutput };\n  addMemory: { input: AddMemoryInput; output: AddMemoryOutput };\n  clearLobe: { input: ClearLobeInput; output: ClearLobeOutput };\n  findMemoryEntities: {\n    input: FindMemoryEntitiesInput;\n    output: FindMemoryEntitiesOutput;\n  };\n  getLivingDocument: {\n    input: GetLivingDocumentInput;\n    output: GetLivingDocumentOutput;\n  };\n  getSessionStartContext: {\n    input: GetSessionStartContextInput;\n    output: GetSessionStartContextOutput;\n  };\n  healthCheck: { input: undefined; output: \"OK\" };\n  listLivingDocuments: {\n    input: ListLivingDocumentsInput;\n    output: ListLivingDocumentsOutput;\n  };\n  listLivingDocumentShares: {\n    input: ListLivingDocumentSharesInput;\n    output: ListLivingDocumentSharesOutput;\n  };\n  memories: { input: undefined; output: MemoryListItem[] };\n  memoriesByDate: {\n    input: MemoriesByDateInput;\n    output: MemoriesByDateOutput;\n  };\n  memoriesByEntity: {\n    input: MemoriesByEntityInput;\n    output: MemoriesByEntityOutput;\n  };\n  memoryOverview: { input: undefined; output: MemoryOverviewOutput };\n  memoryStatus: { input: MemoryStatusInput; output: MemoryStatusOutput };\n  searchMemories: { input: SearchMemoriesInput; output: SearchMemoryHit[] };\n  session: { input: undefined; output: AuthSessionOutput | null };\n  usageSummary: { input: undefined; output: UsageSummaryOutput };\n}\n\ninterface MerraiRecallProcedureContract {\n  addMemory: {\n    input: AddMemoryRecallInput;\n    output: AddMemoryRecallOutput;\n  };\n  listLivingDocuments: {\n    input: undefined;\n    output: ListLivingDocumentsRecallOutput;\n  };\n  readLivingDocument: {\n    input: ReadLivingDocumentRecallInput;\n    output: ReadLivingDocumentRecallOutput;\n  };\n  searchMemory: {\n    input: SearchMemoryRecallInput;\n    output: SearchMemoryRecallOutput;\n  };\n}\n\ntype SafeProcedureClient<Contract> = {\n  [ProcedureName in keyof Contract]: Contract[ProcedureName] extends {\n    input: infer Input;\n    output: infer Output;\n  }\n    ? RpcProcedure<Input, Output>\n    : never;\n};\n\ntype ThrowingProcedureClient<Contract> = {\n  [ProcedureName in keyof Contract]: Contract[ProcedureName] extends {\n    input: infer Input;\n    output: infer Output;\n  }\n    ? ThrowingRpcProcedure<Input, Output>\n    : never;\n};\n\nexport type MerraiClient = SafeProcedureClient<MerraiProcedureContract> & {\n  recall: SafeProcedureClient<MerraiRecallProcedureContract>;\n};\n\nexport type MerraiThrowingClient =\n  ThrowingProcedureClient<MerraiProcedureContract> & {\n    recall: ThrowingProcedureClient<MerraiRecallProcedureContract>;\n  };\n\nexport interface MerraiClientOptions {\n  baseURL?: string;\n  apiKey?: string;\n  cookie?: string;\n  fetch?: typeof fetch;\n  headers?: HeadersInit;\n}\n\nexport const resolveBaseURL = (baseURL?: string) => {\n  const resolved = baseURL?.trim();\n\n  if (!resolved) {\n    throw new Error(\n      \"baseURL is required. Set --base-url, MERRAI_BASE_URL, or saved credentials\"\n    );\n  }\n\n  return resolved.endsWith(\"/\") ? resolved.slice(0, -1) : resolved;\n};\n\nconst resolveHeaders = (\n  headers?: HeadersInit,\n  apiKey?: string,\n  cookie?: string\n): Record<string, string> => {\n  const resolvedHeaders = new Headers(headers);\n\n  if (apiKey) {\n    resolvedHeaders.set(\"x-api-key\", apiKey);\n  }\n\n  if (cookie) {\n    resolvedHeaders.set(\"Cookie\", cookie);\n  }\n\n  return Object.fromEntries(resolvedHeaders.entries());\n};\n\nexport const createRawMerraiClient = (options: MerraiClientOptions = {}) => {\n  const link = new RPCLink({\n    fetch: options.fetch,\n    headers: () =>\n      resolveHeaders(options.headers, options.apiKey, options.cookie),\n    url: `${resolveBaseURL(options.baseURL)}/rpc`,\n  });\n\n  return createORPCClient(link);\n};\n\nexport const createMerraiClient = (options: MerraiClientOptions = {}) =>\n  // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Legacy cast requires typed boundary validation.\n  createSafeClient(createRawMerraiClient(options)) as unknown as MerraiClient;\n\nexport const createMerraiThrowingClient = (\n  options: MerraiClientOptions = {}\n): MerraiThrowingClient =>\n  // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- oRPC is dynamic without the server contract package; keep the cast at this construction seam.\n  createRawMerraiClient(options) as unknown as MerraiThrowingClient;\n","import fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nimport type { MerraiClientOptions } from \"./client\";\n\nexport const DEFAULT_MERRAI_BASE_URL = \"https://api.merrai.app\";\nconst CREDENTIALS_VERSION = 1;\n\nexport type MerraiCliEnvironment = Readonly<Record<string, string | undefined>>;\n\nexport interface MerraiCliConnectionOverrides {\n  apiKey?: string;\n  baseURL?: string;\n  cookie?: string;\n}\n\nexport interface MerraiCredentials {\n  apiKey: string;\n  baseURL?: string;\n  savedAt: string;\n  version: typeof CREDENTIALS_VERSION;\n}\n\nexport interface MerraiConfigPaths {\n  credentials: string;\n  directory: string;\n  legacyClaudeCredentials: string;\n}\n\nconst trimmed = (value: string | undefined): string | undefined => {\n  const result = value?.trim();\n  return result === undefined || result.length === 0 ? undefined : result;\n};\n\nconst isUnknownRecord = (value: unknown): value is Record<string, unknown> =>\n  typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst resolveHomeDirectory = (env: MerraiCliEnvironment): string =>\n  trimmed(env.HOME) ?? trimmed(env.USERPROFILE) ?? os.homedir();\n\nexport const resolveMerraiConfigPaths = (\n  env: MerraiCliEnvironment\n): MerraiConfigPaths => {\n  const home = resolveHomeDirectory(env);\n  const xdgConfigHome = trimmed(env.XDG_CONFIG_HOME);\n  const windowsAppData = trimmed(env.APPDATA);\n  const directory = xdgConfigHome\n    ? path.join(xdgConfigHome, \"merrai\")\n    : process.platform === \"win32\" && windowsAppData\n      ? path.join(windowsAppData, \"Merrai\")\n      : path.join(home, \".config\", \"merrai\");\n\n  return {\n    credentials: path.join(directory, \"credentials.json\"),\n    directory,\n    legacyClaudeCredentials: path.join(\n      home,\n      \".merrai-claude-code\",\n      \"credentials.json\"\n    ),\n  };\n};\n\nconst parseCredentials = (\n  raw: string,\n  options: { requireVersion: boolean }\n): MerraiCredentials | null => {\n  try {\n    const value: unknown = JSON.parse(raw);\n    if (!isUnknownRecord(value)) {\n      return null;\n    }\n\n    if (options.requireVersion && value.version !== CREDENTIALS_VERSION) {\n      return null;\n    }\n    const apiKey =\n      typeof value.apiKey === \"string\" ? trimmed(value.apiKey) : undefined;\n    const baseURL =\n      typeof value.baseURL === \"string\" ? trimmed(value.baseURL) : undefined;\n    if (apiKey === undefined) {\n      return null;\n    }\n\n    return {\n      apiKey,\n      ...(baseURL === undefined ? {} : { baseURL }),\n      savedAt:\n        typeof value.savedAt === \"string\"\n          ? value.savedAt\n          : new Date(0).toISOString(),\n      version: CREDENTIALS_VERSION,\n    };\n  } catch {\n    return null;\n  }\n};\n\nconst readCredentialsFile = (\n  file: string,\n  options: { requireVersion: boolean; strict: boolean }\n): MerraiCredentials | null => {\n  if (!fs.existsSync(file)) {\n    return null;\n  }\n  try {\n    const credentials = parseCredentials(fs.readFileSync(file, \"utf8\"), {\n      requireVersion: options.requireVersion,\n    });\n    if (credentials === null && options.strict) {\n      throw new Error(\n        `Invalid Merrai credentials file at ${file}. Run 'merrai auth set-key' to replace it.`\n      );\n    }\n    return credentials;\n  } catch (error) {\n    if (options.strict) {\n      throw error;\n    }\n    return null;\n  }\n};\n\nexport const loadMerraiCredentials = (\n  env: MerraiCliEnvironment,\n  options: { strict?: boolean } = {}\n): MerraiCredentials | null => {\n  const paths = resolveMerraiConfigPaths(env);\n  return (\n    readCredentialsFile(paths.credentials, {\n      requireVersion: true,\n      strict: options.strict === true,\n    }) ??\n    readCredentialsFile(paths.legacyClaudeCredentials, {\n      requireVersion: false,\n      strict: options.strict === true,\n    })\n  );\n};\n\nexport const saveMerraiCredentials = (\n  env: MerraiCliEnvironment,\n  input: { apiKey: string; baseURL?: string }\n): MerraiCredentials => {\n  const apiKey = trimmed(input.apiKey);\n  if (apiKey === undefined) {\n    throw new Error(\"API key cannot be empty\");\n  }\n\n  const paths = resolveMerraiConfigPaths(env);\n  fs.mkdirSync(paths.directory, { mode: 0o700, recursive: true });\n  fs.chmodSync(paths.directory, 0o700);\n  const credentials: MerraiCredentials = {\n    apiKey,\n    baseURL: trimmed(input.baseURL) ?? DEFAULT_MERRAI_BASE_URL,\n    savedAt: new Date().toISOString(),\n    version: CREDENTIALS_VERSION,\n  };\n  fs.writeFileSync(paths.credentials, JSON.stringify(credentials, null, 2), {\n    mode: 0o600,\n  });\n  fs.chmodSync(paths.credentials, 0o600);\n  return credentials;\n};\n\nconst removeFileIfPresent = (file: string): boolean => {\n  try {\n    fs.unlinkSync(file);\n    return true;\n  } catch (error) {\n    if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n      return false;\n    }\n    throw error;\n  }\n};\n\nexport const clearMerraiCredentials = (\n  env: MerraiCliEnvironment,\n  options: { includeLegacy?: boolean } = {}\n): boolean => {\n  const paths = resolveMerraiConfigPaths(env);\n  const removedShared = removeFileIfPresent(paths.credentials);\n  const removedLegacy =\n    options.includeLegacy === true\n      ? removeFileIfPresent(paths.legacyClaudeCredentials)\n      : false;\n  return removedShared || removedLegacy;\n};\n\nexport const resolveMerraiClientOptions = (\n  env: MerraiCliEnvironment,\n  overrides: MerraiCliConnectionOverrides,\n  options: { strictCredentials?: boolean } = {}\n): MerraiClientOptions => {\n  const apiKeyOverride =\n    trimmed(overrides.apiKey) ?? trimmed(env.MERRAI_API_KEY);\n  const baseURLOverride =\n    trimmed(overrides.baseURL) ?? trimmed(env.MERRAI_BASE_URL);\n  const credentials =\n    apiKeyOverride !== undefined && baseURLOverride !== undefined\n      ? null\n      : loadMerraiCredentials(env, {\n          strict: options.strictCredentials !== false,\n        });\n  return {\n    apiKey: apiKeyOverride ?? credentials?.apiKey,\n    baseURL: baseURLOverride ?? credentials?.baseURL ?? DEFAULT_MERRAI_BASE_URL,\n    cookie: trimmed(overrides.cookie) ?? trimmed(env.MERRAI_COOKIE),\n  };\n};\n"],"mappings":";;;;;;;AAgnBA,MAAa,kBAAkB,YAAqB;CAClD,MAAM,WAAW,SAAS,MAAM;AAEhC,KAAI,CAAC,SACH,OAAM,IAAI,MACR,6EACD;AAGH,QAAO,SAAS,SAAS,IAAI,GAAG,SAAS,MAAM,GAAG,GAAG,GAAG;;AAG1D,MAAM,kBACJ,SACA,QACA,WAC2B;CAC3B,MAAM,kBAAkB,IAAI,QAAQ,QAAQ;AAE5C,KAAI,OACF,iBAAgB,IAAI,aAAa,OAAO;AAG1C,KAAI,OACF,iBAAgB,IAAI,UAAU,OAAO;AAGvC,QAAO,OAAO,YAAY,gBAAgB,SAAS,CAAC;;AAGtD,MAAa,yBAAyB,UAA+B,EAAE,KAAK;AAQ1E,QAAO,iBAPM,IAAI,QAAQ;EACvB,OAAO,QAAQ;EACf,eACE,eAAe,QAAQ,SAAS,QAAQ,QAAQ,QAAQ,OAAO;EACjE,KAAK,GAAG,eAAe,QAAQ,QAAQ,CAAC;EACzC,CAAC,CAE2B;;AAG/B,MAAa,sBAAsB,UAA+B,EAAE,KAElE,iBAAiB,sBAAsB,QAAQ,CAAC;AAElD,MAAa,8B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