openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
102 lines (101 loc) • 3.8 kB
JavaScript
import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs";
import { r as withPluginRuntimeGenerationRegistryScope } from "./generation-state-CbpjEoxA.mjs";
import { i as getPluginToolMeta } from "./tool-metadata-rqUpUHlb.mjs";
import { r as inspectRuntimeToolInputSchemas } from "./tool-schema-projection-D-AbMZEk.mjs";
import { n as normalizeAgentRuntimeTools } from "./tools-CX1i5Uw0.mjs";
import { t as buildReadableToolsByName } from "./tools-effective-inventory-build-8WnvX32A.mjs";
//#region src/flows/doctor-tool-schema-projection.ts
function collectNormalizedToolSchemaFindings(e) {
const t = [];
const n = buildReadableToolsByName(e.tools);
const projectDiagnostics = (t, n, r) => n.map((n) => {
const i = e.agentId;
let a;
try {
a = t[n.toolIndex];
} catch {
a = void 0;
}
const o = r?.get(n.toolName);
const s = (a ? getPluginToolMeta(a)?.pluginId : void 0) ?? (o ? getPluginToolMeta(o)?.pluginId : void 0);
const c = s ? ` from plugin ${s}` : "";
const l = `Agent ${i} `;
const u = s === "bundle-mcp" ? "mcp.servers" : s ? `plugins.entries.${s}` : `tools.${n.toolName}`;
const d = s === "bundle-mcp" ? "Disable or update the offending MCP server/tool so its parameters are a JSON object schema, then rerun doctor." : "Disable or update the offending plugin/tool so its parameters are a JSON object schema, then rerun doctor.";
return {
checkId: "core/doctor/runtime-tool-schemas",
severity: "error",
message: `${l}tool ${n.toolName}${c} has an unsupported input schema for runtime projection.`,
path: u,
target: n.toolName,
requirement: n.violations.join(", "),
fixHint: d
};
});
let r;
try {
r = normalizeAgentRuntimeTools({
tools: e.tools,
provider: e.modelRef.provider,
config: e.cfg,
workspaceDir: e.workspaceDir,
env: process.env,
modelId: e.modelRef.model,
modelApi: e.model.api,
model: e.model,
onPreNormalizationSchemaDiagnostics: (e, n) => {
t.push(...projectDiagnostics(n, e));
}
});
} catch (n) {
return [...t, e.normalizationFailureFinding(n)];
}
return [...t, ...projectDiagnostics(r, inspectRuntimeToolInputSchemas(r), n)];
}
function agentRuntimeToolFailureFinding(e) {
return {
checkId: "core/doctor/runtime-tool-schemas",
severity: "error",
message: `Agent ${e.agentId} runtime tool schema validation could not ${e.phase} the runtime tool set.`,
path: `agents.${e.agentId}.tools`,
requirement: formatErrorMessage(e.error),
fixHint: e.phase === "load" ? "Fix provider/plugin tool loading errors, then rerun doctor before relying on assistant tool startup." : "Fix provider/plugin schema normalization errors, then rerun doctor before relying on assistant tool startup."
};
}
async function collectAgentRuntimeToolSchemaFindings(e) {
let t;
try {
const { createOpenClawCodingTools: n } = await import("./agent-tools-CB4-xgf1.mjs");
t = withPluginRuntimeGenerationRegistryScope(e.toolRegistry, () => n({
agentId: e.agentId,
agentDir: e.agentDir,
conversationCapabilityProfile: e.capabilityProfile,
workspaceDir: e.workspaceDir,
config: e.cfg,
modelProvider: e.modelRef.provider,
modelId: e.modelRef.model,
modelApi: e.model.api,
modelCompat: e.model.compat,
modelContextWindowTokens: e.model.contextWindow,
allowGatewaySubagentBinding: true,
emitBeforeToolCallDiagnostics: false
}));
} catch (t) {
return [agentRuntimeToolFailureFinding({
agentId: e.agentId,
error: t,
phase: "load"
})];
}
return collectNormalizedToolSchemaFindings({
...e,
tools: t,
normalizationFailureFinding: (t) => agentRuntimeToolFailureFinding({
agentId: e.agentId,
error: t,
phase: "normalize"
})
});
}
//#endregion
export { collectAgentRuntimeToolSchemaFindings, collectNormalizedToolSchemaFindings };