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:
Vincent Koc
2026-04-04 10:55:36 +09:00
committed by GitHub
parent dd31ee1139
commit 858bf405f4
17 changed files with 359 additions and 319 deletions

View File

@@ -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 }];
});
}