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
32 lines (31 loc) • 1.66 kB
JavaScript
// 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/.
import { defaultConnection } from "../../core/config/config.js";
import { apiKeyReference } from "../../core/config/credentials.js";
import { openAiBaseUrl } from "../../core/endpoint-url.js";
import { warnOnce } from "../../core/warn.js";
/**
* The embedding block as the embedder uses it. `embedding.model` without an
* `embedding.endpoint` means the model is served by the default connection: its
* endpoint, and its key (its `$VAR`, else `credentials.json` under its name).
* With no default connection there is nothing to serve it, so the built-in local
* embedder runs, with one warning. Computed where the embedder is used and never
* stored, so a config write cannot persist it.
*/
export function effectiveEmbedding(config) {
const embedding = config.embedding;
if (!embedding || embedding.endpoint !== undefined || !embedding.model)
return embedding;
const found = defaultConnection(config);
if (!found) {
warnOnce("embedding:no-default-connection", "embedding.model is set, but there is no embedding.endpoint and no default connection to serve it; using the built-in local embedder. Add a connection with `akm setup`.");
return embedding;
}
return {
...embedding,
endpoint: openAiBaseUrl(found.connection.endpoint),
...(apiKeyReference(found.connection.apiKey) !== undefined ? { apiKey: found.connection.apiKey } : {}),
credentialName: found.name,
};
}