mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 21:20:23 +00:00
refactor(providers): share replay and tool compat helpers (#60637)
* refactor(providers): share replay and tool compat helpers * chore(plugin-sdk): refresh api baseline
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
// Shared provider-tool helpers for plugin-owned schema compatibility rewrites.
|
||||
export {
|
||||
import {
|
||||
cleanSchemaForGemini,
|
||||
GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS,
|
||||
} from "../agents/schema/clean-for-gemini.js";
|
||||
import type { ModelCompatConfig } from "../config/types.models.js";
|
||||
import type {
|
||||
AnyAgentTool,
|
||||
ProviderNormalizeToolSchemasContext,
|
||||
ProviderToolSchemaDiagnostic,
|
||||
} from "./plugin-entry.js";
|
||||
|
||||
// Shared provider-tool helpers for plugin-owned schema compatibility rewrites.
|
||||
export { cleanSchemaForGemini, GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS };
|
||||
|
||||
export const XAI_TOOL_SCHEMA_PROFILE = "xai";
|
||||
export const HTML_ENTITY_TOOL_CALL_ARGUMENTS_ENCODING = "html-entities";
|
||||
|
||||
export const XAI_UNSUPPORTED_SCHEMA_KEYWORDS = new Set([
|
||||
"minLength",
|
||||
@@ -59,6 +70,15 @@ export function stripXaiUnsupportedKeywords(schema: unknown): unknown {
|
||||
return stripUnsupportedSchemaKeywords(schema, XAI_UNSUPPORTED_SCHEMA_KEYWORDS);
|
||||
}
|
||||
|
||||
export function resolveXaiModelCompatPatch(): ModelCompatConfig {
|
||||
return {
|
||||
toolSchemaProfile: XAI_TOOL_SCHEMA_PROFILE,
|
||||
unsupportedToolSchemaKeywords: Array.from(XAI_UNSUPPORTED_SCHEMA_KEYWORDS),
|
||||
nativeWebSearchTool: true,
|
||||
toolCallArgumentsEncoding: HTML_ENTITY_TOOL_CALL_ARGUMENTS_ENCODING,
|
||||
};
|
||||
}
|
||||
|
||||
export function findUnsupportedSchemaKeywords(
|
||||
schema: unknown,
|
||||
path: string,
|
||||
@@ -100,3 +120,33 @@ export function findUnsupportedSchemaKeywords(
|
||||
}
|
||||
return violations;
|
||||
}
|
||||
|
||||
export function normalizeGeminiToolSchemas(
|
||||
ctx: ProviderNormalizeToolSchemasContext,
|
||||
): AnyAgentTool[] {
|
||||
return ctx.tools.map((tool) => {
|
||||
if (!tool.parameters || typeof tool.parameters !== "object") {
|
||||
return tool;
|
||||
}
|
||||
return {
|
||||
...tool,
|
||||
parameters: cleanSchemaForGemini(tool.parameters as Record<string, unknown>),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function inspectGeminiToolSchemas(
|
||||
ctx: ProviderNormalizeToolSchemasContext,
|
||||
): ProviderToolSchemaDiagnostic[] {
|
||||
return ctx.tools.flatMap((tool, toolIndex) => {
|
||||
const violations = findUnsupportedSchemaKeywords(
|
||||
tool.parameters,
|
||||
`${tool.name}.parameters`,
|
||||
GEMINI_UNSUPPORTED_SCHEMA_KEYWORDS,
|
||||
);
|
||||
if (violations.length === 0) {
|
||||
return [];
|
||||
}
|
||||
return [{ toolName: tool.name, toolIndex, violations }];
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user