UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

146 lines (145 loc) 7.26 kB
import { w as parseStrictPositiveInteger, x as parseStrictFiniteNumber } from "./number-coercion-CLj0HTDM.js"; import { a as writeRuntimeJson, r as defaultRuntime } from "./runtime-CF2WjnNZ.js"; import { n as getRuntimeConfig } from "./io.runtime-B9iJRs3w.js"; import { _ as resolveConfiguredAgentId, f as resolveAgentOperationAgentId, u as resolveAgentDir } from "./agent-scope-config-DcbEhP0R.js"; import { E as setRuntimeConfigSnapshot, l as getRuntimeConfigSourceSnapshot } from "./runtime-snapshot-BaQikjTR.js"; import "./agent-scope-DbtJyKUL.js"; import { t as getProviderEnvVars } from "./provider-env-vars-B8XgJCSL.js"; import "./config-Cs0XXL3x.js"; import { n as inheritOptionFromParent } from "./command-options-BDuSHeWG.js"; import { n as parseTimeoutMsWithFallback } from "./parse-timeout-BhPKqfrV.js"; import { f as loadAuthProfileStoreForRuntime } from "./store-F1B2duCT.js"; import { n as listProfilesForProvider } from "./profile-list-DyfWX-d2.js"; import "./auth-profiles-BdUEhE7u.js"; import { t as resolveCommandConfigWithSecrets } from "./command-config-resolution-CMrTrLUm.js"; //#region src/cli/capability-cli/shared.ts function resolveTransport(opts) { if (opts.local && opts.gateway) throw new Error("Pass only one of --local or --gateway."); if (opts.local) { if (!opts.supported.includes("local")) throw new Error("This command does not support --local."); return "local"; } if (opts.gateway) { if (!opts.supported.includes("gateway")) throw new Error("This command does not support --gateway."); return "gateway"; } return opts.defaultTransport; } function emitJsonOrText(runtime, json, value, textFormatter) { if (json) { writeRuntimeJson(runtime, value); return; } runtime.log(textFormatter(value)); } function formatEnvelopeForText(value) { const envelope = value; if (!envelope.ok) return `${envelope.capability} failed: ${envelope.error ?? "unknown error"}`; const lines = [ `${envelope.capability} via ${envelope.transport}`, ...envelope.provider ? [`provider: ${envelope.provider}`] : [], ...envelope.model ? [`model: ${envelope.model}`] : [], ...envelope.ignoredOverrides && envelope.ignoredOverrides.length > 0 ? [`ignoredOverrides: ${JSON.stringify(envelope.ignoredOverrides)}`] : [], `outputs: ${String(envelope.outputs.length)}` ]; for (const output of envelope.outputs) { const pathValue = typeof output.path === "string" ? output.path : void 0; const textValue = typeof output.text === "string" ? output.text : void 0; if (pathValue || textValue) lines.push(...[pathValue, textValue].filter((entry) => Boolean(entry))); else lines.push(JSON.stringify(output)); } return lines.join("\n"); } function providerSummaryText(value) { return value.map((entry) => JSON.stringify(entry)).join("\n") || "No results found."; } function hasOwnKeys(value) { return Boolean(value && typeof value === "object" && Object.keys(value).length > 0); } function resolveSelectedProviderFromModelRef(modelRef) { return resolveModelRefOverride(modelRef).provider; } function resolveCapabilityProviderAgentId(cfg, rawAgentId, surface = "inference provider inspection") { const requestedAgentId = rawAgentId?.trim(); if (rawAgentId !== void 0 && !requestedAgentId) throw new Error("--agent must not be blank"); const agentId = resolveAgentOperationAgentId(cfg, requestedAgentId, { surface, hint: "Pass --agent <id> or set agents.defaults.systemAgent.agentId." }); return resolveConfiguredAgentId(cfg, agentId); } function resolveCapabilityAgentOption(command, rawAgentId) { return typeof rawAgentId === "string" ? rawAgentId : inheritOptionFromParent(command, "agent"); } function getAuthProfileIdsForProvider(cfg, providerId, agentId) { const agentDir = resolveAgentDir(cfg, agentId); const store = loadAuthProfileStoreForRuntime(agentDir); return listProfilesForProvider(store, providerId); } function providerHasGenericConfig(params) { const modelsProviders = params.cfg.models?.providers ?? {}; const pluginEntries = params.cfg.plugins?.entries ?? {}; const ttsProviders = params.cfg.tts?.providers ?? {}; const envConfigured = (params.envVars ?? getProviderEnvVars(params.providerId, { config: params.cfg, includeUntrustedWorkspacePlugins: false })).some((envVar) => Boolean(process.env[envVar]?.trim())); return (params.agentId ? getAuthProfileIdsForProvider(params.cfg, params.providerId, params.agentId).length > 0 : false) || hasOwnKeys(modelsProviders[params.providerId]) || hasOwnKeys(pluginEntries[params.providerId]?.config) || hasOwnKeys(ttsProviders[params.providerId]) || envConfigured; } function resolveModelRefOverride(raw) { const trimmed = raw?.trim(); if (!trimmed) return {}; const slash = trimmed.indexOf("/"); if (slash <= 0 || slash === trimmed.length - 1) return { model: trimmed }; return { provider: trimmed.slice(0, slash), model: trimmed.slice(slash + 1) }; } function requireProviderModelOverride(raw) { const resolved = resolveModelRefOverride(raw); if (!raw?.trim()) return; if (!resolved.provider || !resolved.model) throw new Error("Model overrides must use the form <provider/model>."); return { provider: resolved.provider, model: resolved.model }; } function parseOptionalFiniteNumber(raw, label) { if (raw === void 0 || typeof raw === "string" && raw.trim() === "") return; const value = parseStrictFiniteNumber(raw); if (value === void 0) throw new Error(`${label} must be a finite number`); return value; } function parseOptionalPositiveInteger(raw, label) { if (raw === void 0 || typeof raw === "string" && raw.trim() === "") return; const value = parseStrictPositiveInteger(raw); if (value === void 0) throw new Error(`${label} must be a positive integer`); return value; } function parseOptionalTimeoutMs(raw) { if (raw === void 0 || typeof raw === "string" && raw.trim() === "") return; return parseTimeoutMsWithFallback(raw, 0, { invalidType: "error" }); } async function resolveLocalCapabilityRuntimeConfig(params) { const cfg = params.config ?? getRuntimeConfig(); const { effectiveConfig } = await resolveCommandConfigWithSecrets({ config: cfg, commandName: params.commandName, targetIds: params.targetIds, ...params.allowedPaths ? { allowedPaths: params.allowedPaths } : {}, ...params.forcedActivePaths ? { forcedActivePaths: params.forcedActivePaths } : {}, ...params.optionalActivePaths ? { optionalActivePaths: params.optionalActivePaths } : {}, runtime: defaultRuntime, autoEnable: true }); pinRuntimeConfigSnapshot(effectiveConfig); return effectiveConfig; } function pinRuntimeConfigSnapshot(config) { const sourceConfig = getRuntimeConfigSourceSnapshot(); if (sourceConfig) setRuntimeConfigSnapshot(config, sourceConfig); else setRuntimeConfigSnapshot(config); } //#endregion export { parseOptionalTimeoutMs as a, providerSummaryText as c, resolveCapabilityProviderAgentId as d, resolveLocalCapabilityRuntimeConfig as f, resolveTransport as h, parseOptionalPositiveInteger as i, requireProviderModelOverride as l, resolveSelectedProviderFromModelRef as m, formatEnvelopeForText as n, pinRuntimeConfigSnapshot as o, resolveModelRefOverride as p, parseOptionalFiniteNumber as r, providerHasGenericConfig as s, emitJsonOrText as t, resolveCapabilityAgentOption as u };