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

34 lines (33 loc) • 1.74 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/. /** The inference keys model work's agent carries as options. */ export const MODEL_WORK_AGENT_INFERENCE = ["temperature", "reasoningEffort", "enableThinking"]; const isPositiveInteger = (value) => typeof value === "number" && Number.isInteger(value) && value > 0; /** * Split `inference` into opencode config: `entry` for a model (its options, and * its limit), and for model work `agentOptions` for the confined agent in place * of the entry's options. A value of the wrong type is left out. */ export function opencodeInferenceConfig(inference, modelWork) { const { temperature, reasoningEffort, enableThinking, maxTokens, contextLength } = inference ?? {}; const options = {}; if (typeof temperature === "number" && Number.isFinite(temperature)) options.temperature = temperature; if (typeof reasoningEffort === "string" && reasoningEffort.length > 0) options.reasoningEffort = reasoningEffort; if (typeof enableThinking === "boolean") { options.chat_template_kwargs = { enable_thinking: enableThinking }; options.enable_thinking = enableThinking; } const hasOptions = Object.keys(options).length > 0; return { entry: { ...(hasOptions && !modelWork ? { options } : {}), ...(isPositiveInteger(maxTokens) && isPositiveInteger(contextLength) ? { limit: { context: contextLength, output: maxTokens } } : {}), }, ...(hasOptions && modelWork ? { agentOptions: options } : {}), }; }