UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

187 lines (186 loc) • 8.72 kB
import { t as formatErrorMessage } from "../errors-BKzCeTYb.mjs"; import { r as resolveOpenClawPackageRootSync } from "../openclaw-root-C-ayo09z.mjs"; import { n as loadBundledPluginManifestRegistry } from "../manifest-registry-build-BbYTyBDW.mjs"; import { t as loadPluginManifestRegistryCore } from "../manifest-registry-CuWv8ibc.mjs"; import { a as tryLoadActivatedBundledPluginPublicSurfaceModuleSync, r as loadBundledPluginPublicSurfaceModuleSync } from "../facade-runtime-B7RI0rKM.mjs"; import fs from "node:fs"; import path from "node:path"; //#region src/plugin-sdk/private-qa-bundled-env.ts /** * Runtime helper for private QA CLI source-checkout bundled plugin resolution. */ /** Returns an env override that points bundled plugin loading at source extensions. */ function resolvePrivateQaBundledPluginsEnv(e = process.env) { if (e.OPENCLAW_ENABLE_PRIVATE_QA_CLI !== "1") return; const t = resolveOpenClawPackageRootSync({ argv1: process.argv[1], cwd: process.cwd(), moduleUrl: import.meta.url }); if (!t) return; const n = path.join(t, "extensions"); if (!fs.existsSync(path.join(t, ".git")) || !fs.existsSync(path.join(t, "src")) || !fs.existsSync(n)) return; return { ...e, OPENCLAW_BUNDLED_PLUGINS_DIR: n }; } //#endregion //#region src/plugin-sdk/qa-runner-runtime.ts /** Memoize a lazy CLI runtime import so repeated command paths share one loaded module. */ function createLazyCliRuntimeLoader(e) { let t = null; return async () => { t ??= e(); return await t; }; } function collectLiveTransportQaStringOption(e, t) { const n = e.trim(); return n ? [...t, n] : t; } function mapLiveTransportQaCommanderOptions(e, t) { return { ...e.channelDriver ? { channelDriver: e.channelDriver } : {}, ...!t || e.concurrency !== void 0 ? { concurrency: e.concurrency } : {}, repoRoot: e.repoRoot, outputDir: e.outputDir, providerMode: e.providerMode, primaryModel: e.model, alternateModel: e.altModel, fastMode: e.fast, allowFailures: e.allowFailures, failFast: e.failFast, profile: e.profile, scenarioIds: e.scenario, listScenarios: t ? e.listScenarios || void 0 : e.listScenarios, sutAccountId: e.sutAccount, ...!t || e.credentialFile ? { credentialFile: e.credentialFile } : {}, credentialSource: e.credentialSource, credentialRole: e.credentialRole }; } function registerLiveTransportQaCli(e) { const t = e.qa.command(e.commandName).description(e.description).option("--repo-root <path>", "Repository root to target when running from a neutral cwd").option("--output-dir <path>", e.outputDirHelp).option("--provider-mode <mode>", e.providerModeHelp, e.defaultProviderMode).option("--model <ref>", "Primary provider/model ref").option("--alt-model <ref>", "Alternate provider/model ref").option("--scenario <id>", e.scenarioHelp, collectLiveTransportQaStringOption, []).option("--fast", "Enable provider fast mode where supported"); if (e.concurrency) t.option("--concurrency <count>", e.concurrency.help, e.concurrency.parse); if (e.allowFailuresHelp) t.option("--allow-failures", e.allowFailuresHelp, false); t.option("--sut-account <id>", e.sutAccountHelp, "sut"); if (e.credentialFileHelp) t.option("--credential-file <path>", e.credentialFileHelp); if (e.listScenariosHelp) t.option("--list-scenarios", e.listScenariosHelp, false); if (e.profileHelp) t.option("--profile <profile>", e.profileHelp); if (e.failFastHelp) t.option("--fail-fast", e.failFastHelp, false); if (e.credentialOptions) { t.option("--credential-source <source>", e.credentialOptions.sourceDescription ?? "Credential source for live lanes: env or convex (default: env)"); if (e.credentialOptions.roleDescription) t.option("--credential-role <role>", e.credentialOptions.roleDescription); } t.action(async (n) => { try { if (t.getOptionValueSource("scenario") === "cli" && n.scenario?.length === 0) throw new Error("--scenario must name at least one non-empty scenario id."); await e.run(mapLiveTransportQaCommanderOptions(n, e.normalizeInactiveSelectionOptions === true)); } catch (e) { process.stderr.write(`${formatErrorMessage(e)}\n`); process.exitCode = 1; } }); } /** Build a Commander registration object for one live-transport QA command. */ function createLiveTransportQaCliRegistration(e) { return { commandName: e.commandName, adapterFactory: e.adapterFactory, register(t) { registerLiveTransportQaCli({ ...e, qa: t }); } }; } /** Load the private QA Lab runtime facade used by QA runner commands. */ function loadQaRuntimeModule() { const e = resolvePrivateQaBundledPluginsEnv(); return loadBundledPluginPublicSurfaceModuleSync({ dirName: ["qa", "lab"].join("-"), artifactBasename: ["runtime-api", "js"].join("."), ...e ? { env: e } : {} }); } /** Load a bundled QA runner plugin test API facade by plugin id. */ function loadQaRunnerBundledPluginTestApi(e) { const t = resolvePrivateQaBundledPluginsEnv(); return loadBundledPluginPublicSurfaceModuleSync({ dirName: e, artifactBasename: "test-api.js", ...t ? { env: t } : {} }); } /** Returns whether the private QA Lab runtime facade is available in this build. */ function isQaRuntimeAvailable() { try { loadQaRuntimeModule(); return true; } catch (e) { if (e instanceof Error && e.message.includes("qa-lab") && (e.message.includes("runtime-api.js") || e.message.startsWith("Unable to open bundled plugin public surface "))) return false; throw e; } } /** Run a plugin-owned transport adapter through QA Lab's shared suite host. */ async function runLiveTransportQaSuiteCommand(e) { return await loadQaRuntimeModule().runLiveTransportQaSuiteCommand(e); } function listDeclaredQaRunnerPlugins(e) { return (e ? loadBundledPluginManifestRegistry({ env: e }) : loadPluginManifestRegistryCore()).plugins.filter((e) => Array.isArray(e.qaRunners) && e.qaRunners.length > 0).toSorted((e, t) => e.id.localeCompare(t.id) || e.rootDir.localeCompare(t.rootDir)); } function indexRuntimeRegistrations(e, t) { const n = t.qaRunnerCliRegistrations ?? []; const r = /* @__PURE__ */ new Map(); for (const t of n) { if (!t?.commandName || typeof t.register !== "function") throw new Error(`QA runner plugin "${e}" exported an invalid CLI registration`); if (r.has(t.commandName)) throw new Error(`QA runner plugin "${e}" exported duplicate CLI registration "${t.commandName}"`); r.set(t.commandName, t); } return r; } /** List QA runner CLI contributions declared by manifests and backed by runtime registrations. */ function listQaRunnerCliContributions() { const e = resolvePrivateQaBundledPluginsEnv(); const t = /* @__PURE__ */ new Map(); for (const n of listDeclaredQaRunnerPlugins(e)) { const r = (n.origin === "bundled" ? loadBundledPluginPublicSurfaceModuleSync : tryLoadActivatedBundledPluginPublicSurfaceModuleSync)({ dirName: n.id, artifactBasename: "qa-runner-api.js", ...e ? { env: e } : {} }); const i = r ? indexRuntimeRegistrations(n.id, r) : null; const a = new Set(n.qaRunners.map((e) => e.commandName)); for (const e of n.qaRunners) { const a = t.get(e.commandName); if (a && a.pluginId !== n.id) throw new Error(`QA runner command "${e.commandName}" declared by both "${a.pluginId}" and "${n.id}"`); const o = i?.get(e.commandName); if (!r) { t.set(e.commandName, { pluginId: n.id, commandName: e.commandName, ...e.description ? { description: e.description } : {}, status: "blocked" }); continue; } if (!o) throw new Error(`QA runner plugin "${n.id}" declared "${e.commandName}" in openclaw.plugin.json but did not export a matching CLI registration from its QA runner surface`); const s = o.adapterFactory; const c = s ? Reflect.get(s, "supportsModuleFlows") : void 0; if (s && (s.id !== e.commandName || c !== void 0 && c !== true || s.isolatesInstances !== void 0 && typeof s.isolatesInstances !== "boolean" || typeof s.matches !== "function" || typeof s.create !== "function")) throw new Error(`QA runner plugin "${n.id}" exported an invalid transport factory for "${e.commandName}"`); t.set(e.commandName, { pluginId: n.id, commandName: e.commandName, ...e.description ? { description: e.description } : {}, status: "available", registration: o }); } for (const e of i?.keys() ?? []) if (!a.has(e)) throw new Error(`QA runner plugin "${n.id}" exported "${e}" from its QA runner surface but did not declare it in openclaw.plugin.json`); } return [...t.values()]; } //#endregion export { createLazyCliRuntimeLoader, createLiveTransportQaCliRegistration, isQaRuntimeAvailable, listQaRunnerCliContributions, loadQaRunnerBundledPluginTestApi, loadQaRuntimeModule, runLiveTransportQaSuiteCommand };