Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

1.9 KB
Raw Blame
// Whether a migration scan may run at all. Gated on the Model Hub capability so a
// disabled instance issues no scan request; separated from its callers so the gate
// is testable without rendering a surface.
//
// This module also owns the one predicate the API-key import entry is defined
// by. Setup's notice is about keys the gateway can actually take over, so the
// count, the rows offered, the batch submitted and the remainder after an import
// all read `isImportableKey` — a number that came from a different rule than the
// rows behind it is the bug this exists to prevent.
//
// It is intentionally narrower than the server's complete migration matrix:
// only API-key-like rows can be handled by the setup notice. OAuth takeover and
// re-authentication stay in the settings migration flow.
import { modelsApi } from './modelsApi';
import type { MigrationItem, MigrationKind } from './types';

export const scanMigrationWhenEnabled = async (
  enabled: boolean,
  scan: typeof modelsApi.scanMigration = modelsApi.scanMigration,
) => (enabled ? scan() : null);

/** The kinds whose credential is a key the gateway can hold. `oauth_native` is
 *  a native subscription token and is excluded by kind, not by action — an
 *  OpenCode key arrives as `opencode_provider`, not `api_key`, so filtering on
 *  `api_key` alone would silently drop every OpenCode import. */
export const IMPORTABLE_KEY_KINDS: readonly MigrationKind[] = ['api_key', 'opencode_provider'];

/** One candidate the API-key import entry may count, offer, submit and re-count. */
export const isImportableKey = (item: Pick<MigrationItem, 'proposed_action' | 'kind'>): boolean =>
  item.proposed_action === 'import' && IMPORTABLE_KEY_KINDS.includes(item.kind);

/** The candidates of a scan, in scan order. */
export const importableKeys = (items: readonly MigrationItem[]): MigrationItem[] =>
  items.filter(isImportableKey);