mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 09:40:22 +00:00
refactor: move provider replay runtime ownership into plugins (#60126)
* refactor: move provider replay runtime ownership into plugins * fix(provider-runtime): address review followups --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
@@ -55,10 +55,10 @@ let resolveProviderSyntheticAuthWithPlugin: typeof import("./provider-runtime.js
|
||||
let shouldDeferProviderSyntheticProfileAuthWithPlugin: typeof import("./provider-runtime.js").shouldDeferProviderSyntheticProfileAuthWithPlugin;
|
||||
let sanitizeProviderReplayHistoryWithPlugin: typeof import("./provider-runtime.js").sanitizeProviderReplayHistoryWithPlugin;
|
||||
let resolveProviderUsageSnapshotWithPlugin: typeof import("./provider-runtime.js").resolveProviderUsageSnapshotWithPlugin;
|
||||
let resolveProviderCapabilitiesWithPlugin: typeof import("./provider-runtime.js").resolveProviderCapabilitiesWithPlugin;
|
||||
let resolveProviderUsageAuthWithPlugin: typeof import("./provider-runtime.js").resolveProviderUsageAuthWithPlugin;
|
||||
let resolveProviderXHighThinking: typeof import("./provider-runtime.js").resolveProviderXHighThinking;
|
||||
let normalizeProviderToolSchemasWithPlugin: typeof import("./provider-runtime.js").normalizeProviderToolSchemasWithPlugin;
|
||||
let inspectProviderToolSchemasWithPlugin: typeof import("./provider-runtime.js").inspectProviderToolSchemasWithPlugin;
|
||||
let normalizeProviderResolvedModelWithPlugin: typeof import("./provider-runtime.js").normalizeProviderResolvedModelWithPlugin;
|
||||
let prepareProviderDynamicModel: typeof import("./provider-runtime.js").prepareProviderDynamicModel;
|
||||
let prepareProviderRuntimeAuth: typeof import("./provider-runtime.js").prepareProviderRuntimeAuth;
|
||||
@@ -273,10 +273,10 @@ describe("provider-runtime", () => {
|
||||
shouldDeferProviderSyntheticProfileAuthWithPlugin,
|
||||
sanitizeProviderReplayHistoryWithPlugin,
|
||||
resolveProviderUsageSnapshotWithPlugin,
|
||||
resolveProviderCapabilitiesWithPlugin,
|
||||
resolveProviderUsageAuthWithPlugin,
|
||||
resolveProviderXHighThinking,
|
||||
normalizeProviderToolSchemasWithPlugin,
|
||||
inspectProviderToolSchemasWithPlugin,
|
||||
normalizeProviderResolvedModelWithPlugin,
|
||||
prepareProviderDynamicModel,
|
||||
prepareProviderRuntimeAuth,
|
||||
@@ -382,6 +382,29 @@ describe("provider-runtime", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves stream wrapper hooks through hook-only aliases without provider ownership", () => {
|
||||
const wrappedStreamFn = vi.fn();
|
||||
resolvePluginProvidersMock.mockReturnValue([
|
||||
{
|
||||
id: "openai",
|
||||
label: "OpenAI",
|
||||
hookAliases: ["azure-openai-responses"],
|
||||
auth: [],
|
||||
wrapStreamFn: ({ streamFn }) => streamFn ?? wrappedStreamFn,
|
||||
},
|
||||
]);
|
||||
|
||||
expect(
|
||||
wrapProviderStreamFn({
|
||||
provider: "azure-openai-responses",
|
||||
context: createDemoResolvedModelContext({
|
||||
provider: "azure-openai-responses",
|
||||
streamFn: wrappedStreamFn,
|
||||
}),
|
||||
}),
|
||||
).toBe(wrappedStreamFn);
|
||||
});
|
||||
|
||||
it("normalizes transport hooks without needing provider ownership", () => {
|
||||
resolvePluginProvidersMock.mockReturnValue([
|
||||
{
|
||||
@@ -497,6 +520,7 @@ describe("provider-runtime", () => {
|
||||
const normalizeToolSchemas = vi.fn(
|
||||
({ tools }: Pick<ProviderNormalizeToolSchemasContext, "tools">): AnyAgentTool[] => tools,
|
||||
);
|
||||
const inspectToolSchemas = vi.fn(() => [] as { toolName: string; violations: string[] }[]);
|
||||
const resolveReasoningOutputMode = vi.fn(() => "tagged" as const);
|
||||
const resolveSyntheticAuth = vi.fn(() => ({
|
||||
apiKey: "demo-local",
|
||||
@@ -548,13 +572,11 @@ describe("provider-runtime", () => {
|
||||
...providerConfig,
|
||||
compat: { supportsUsageInStreaming: true },
|
||||
}),
|
||||
capabilities: {
|
||||
providerFamily: "openai",
|
||||
},
|
||||
buildReplayPolicy,
|
||||
sanitizeReplayHistory,
|
||||
validateReplayTurns,
|
||||
normalizeToolSchemas,
|
||||
inspectToolSchemas,
|
||||
resolveReasoningOutputMode,
|
||||
prepareExtraParams: ({ extraParams }) => ({
|
||||
...extraParams,
|
||||
@@ -679,14 +701,6 @@ describe("provider-runtime", () => {
|
||||
}),
|
||||
});
|
||||
|
||||
expect(
|
||||
resolveProviderCapabilitiesWithPlugin({
|
||||
provider: DEMO_PROVIDER_ID,
|
||||
}),
|
||||
).toMatchObject({
|
||||
providerFamily: "openai",
|
||||
});
|
||||
|
||||
expect(
|
||||
resolveProviderReplayPolicyWithPlugin({
|
||||
provider: DEMO_PROVIDER_ID,
|
||||
@@ -860,6 +874,16 @@ describe("provider-runtime", () => {
|
||||
}),
|
||||
).toEqual([DEMO_TOOL]);
|
||||
|
||||
expect(
|
||||
inspectProviderToolSchemasWithPlugin({
|
||||
provider: DEMO_PROVIDER_ID,
|
||||
context: createDemoResolvedModelContext({
|
||||
modelApi: MODEL.api,
|
||||
tools: [DEMO_TOOL],
|
||||
}),
|
||||
}),
|
||||
).toEqual([]);
|
||||
|
||||
expect(
|
||||
normalizeProviderResolvedModelWithPlugin({
|
||||
provider: DEMO_PROVIDER_ID,
|
||||
@@ -1010,6 +1034,7 @@ describe("provider-runtime", () => {
|
||||
sanitizeReplayHistory,
|
||||
validateReplayTurns,
|
||||
normalizeToolSchemas,
|
||||
inspectToolSchemas,
|
||||
resolveReasoningOutputMode,
|
||||
refreshOAuth,
|
||||
resolveSyntheticAuth,
|
||||
|
||||
Reference in New Issue
Block a user