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
41 lines (40 loc) • 1.91 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/.
/**
* What the pieces of the engines conversion share: the shapes they pass around and the
* few helpers more than one of them needs. See `convert-engines.ts`.
*/
import { isRecord } from "../common.js";
import { normalizeExtraParamKey } from "../extra-params.js";
import { inferenceWireFields } from "../llm-inference.js";
export const str = (value) => (typeof value === "string" && value ? value : undefined);
export const asDict = (value) => (isRecord(value) ? value : {});
/**
* The request fields an old engine's (or a `models.json` entry's) inference
* becomes. The first-class settings win over `extraParams`: an `extraParams` key
* that names the same field as one of them (`temperature`, `maxTokens`/`max_tokens`,
* `enableThinking`, `reasoningEffort`, `chat_template_kwargs`) is dropped, with a
* note that names the key and not its value.
*/
export function wireFieldsOf(inference, where, notes) {
const { extraParams, ...settings } = inference;
const firstClass = inferenceWireFields(settings);
const taken = new Set(Object.keys(firstClass).map(normalizeExtraParamKey));
const extras = {};
for (const [key, value] of Object.entries(isRecord(extraParams) ? extraParams : {})) {
if (taken.has(normalizeExtraParamKey(key))) {
notes.push(`${where}: extraParams.${key} is dropped, because the setting it shadows takes precedence.`);
}
else {
extras[key] = value;
}
}
return { ...extras, ...firstClass };
}
/** `holder[key]` as an object, made on `holder` when it is not one yet. */
export function objectAt(holder, key) {
if (!isRecord(holder[key]))
holder[key] = {};
return holder[key];
}