UNPKG

akm-cli

Version:

akm (Agent Knowledge Manager) — a portable, local-first capability library for AI agents. Discover, load, share, and improve reusable skills, scripts, workflows, and knowledge across any shell-capable coding agent, including Claude Code, OpenCode, and Cur

59 lines (58 loc) • 3.21 kB
// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. /** * Semantic-search asset preparation for setup. For the built-in local embedder * that is its runtime (onnxruntime-node's binding and library) and its model, * both fetched into akm's cache; for an embedding endpoint, a check that it * answers. */ import * as p from "../cli/clack.js"; import { isHttpUrl } from "../core/common.js"; import { checkEmbeddingAvailability, DEFAULT_LOCAL_MODEL } from "../llm/embedder.js"; import { effectiveEmbedding } from "../llm/embedders/connection.js"; import { ONNXRUNTIME_VERSION } from "../llm/embedders/onnx-runtime.js"; // Approximate first-download size of the default local model (DEFAULT_LOCAL_MODEL), used in the setup note. const LOCAL_MODEL_APPROX_SIZE_MB = 127; export function isRemoteEmbeddingConfig(embedding) { return isHttpUrl(embedding?.endpoint); } /** * @internal Exported for testing only. */ export function describeSemanticSearchAssets(embedding) { if (isRemoteEmbeddingConfig(embedding)) { return [`• Embedding endpoint: ${embedding?.provider ?? "custom"} / ${embedding?.model} (no local model download)`]; } return [ `• ONNX Runtime ${ONNXRUNTIME_VERSION}, the local embedder's runtime (~86 MB download, once)`, `• Local embedding model: ${embedding?.localModel ?? DEFAULT_LOCAL_MODEL} (~${LOCAL_MODEL_APPROX_SIZE_MB} MB download, once)`, ]; } export async function prepareSemanticSearchAssets(config) { const embedding = effectiveEmbedding(config); const remote = isRemoteEmbeddingConfig(embedding); const spin = p.spinner(); spin.start(remote ? "Checking remote embedding endpoint..." : `Downloading the local embedder's runtime and model (${embedding?.localModel ?? DEFAULT_LOCAL_MODEL})...`); const result = await checkEmbeddingAvailability(embedding); if (!result.available) { spin.stop("Semantic-search assets could not be prepared."); if (result.reason === "remote-unreachable") { p.log.warn("The remote embedding endpoint is not reachable. Check your endpoint and credentials, then retry `akm index --full --verbose`."); return { ok: false, reason: "remote-network", message: "The remote embedding endpoint is not reachable." }; } else if (result.reason === "runtime-unavailable") { p.log.warn(`${result.message}\nSet \`embedding.endpoint\` to use a remote embedding service instead.`); return { ok: false, reason: "runtime-unavailable", message: result.message }; } else { p.log.warn(`The local embedding model could not be downloaded: ${result.message}\n` + "Retry `akm index --full --verbose` after confirming local model downloads are permitted."); return { ok: false, reason: "local-model-download", message: result.message }; } } spin.stop(remote ? "Remote embedding endpoint is ready." : "Local embedder's runtime and model downloaded and ready."); return { ok: true }; }