mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 20:21:23 +00:00
fix(ci): restore main lint/typecheck after direct merges
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { StreamFn } from "@mariozechner/pi-agent-core";
|
||||
import type { Context, Model } from "@mariozechner/pi-ai";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { applyExtraParamsToAgent } from "./extra-params.js";
|
||||
|
||||
// Mock streamSimple for testing
|
||||
@@ -13,7 +12,6 @@ vi.mock("@mariozechner/pi-ai", () => ({
|
||||
|
||||
describe("extra-params: Z.AI tool_stream support", () => {
|
||||
it("should inject tool_stream=true for zai provider by default", () => {
|
||||
const capturedPayloads: unknown[] = [];
|
||||
const mockStreamFn: StreamFn = vi.fn((model, context, options) => {
|
||||
// Capture the payload that would be sent
|
||||
options?.onPayload?.({ model: model.id, messages: [] });
|
||||
@@ -24,7 +22,7 @@ describe("extra-params: Z.AI tool_stream support", () => {
|
||||
content: [{ type: "text", text: "ok" }],
|
||||
stopReason: "stop",
|
||||
}),
|
||||
} as any;
|
||||
} as unknown as ReturnType<StreamFn>;
|
||||
});
|
||||
|
||||
const agent = { streamFn: mockStreamFn };
|
||||
@@ -34,7 +32,12 @@ describe("extra-params: Z.AI tool_stream support", () => {
|
||||
},
|
||||
};
|
||||
|
||||
applyExtraParamsToAgent(agent, cfg as any, "zai", "glm-5");
|
||||
applyExtraParamsToAgent(
|
||||
agent,
|
||||
cfg as unknown as Parameters<typeof applyExtraParamsToAgent>[1],
|
||||
"zai",
|
||||
"glm-5",
|
||||
);
|
||||
|
||||
// The streamFn should be wrapped
|
||||
expect(agent.streamFn).toBeDefined();
|
||||
@@ -42,33 +45,44 @@ describe("extra-params: Z.AI tool_stream support", () => {
|
||||
});
|
||||
|
||||
it("should not inject tool_stream for non-zai providers", () => {
|
||||
const mockStreamFn: StreamFn = vi.fn(() => ({
|
||||
push: vi.fn(),
|
||||
result: vi.fn().mockResolvedValue({
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "ok" }],
|
||||
stopReason: "stop",
|
||||
}),
|
||||
} as any));
|
||||
const mockStreamFn: StreamFn = vi.fn(
|
||||
() =>
|
||||
({
|
||||
push: vi.fn(),
|
||||
result: vi.fn().mockResolvedValue({
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "ok" }],
|
||||
stopReason: "stop",
|
||||
}),
|
||||
}) as unknown as ReturnType<StreamFn>,
|
||||
);
|
||||
|
||||
const agent = { streamFn: mockStreamFn };
|
||||
const cfg = {};
|
||||
|
||||
applyExtraParamsToAgent(agent, cfg as any, "anthropic", "claude-opus-4-6");
|
||||
applyExtraParamsToAgent(
|
||||
agent,
|
||||
cfg as unknown as Parameters<typeof applyExtraParamsToAgent>[1],
|
||||
"anthropic",
|
||||
"claude-opus-4-6",
|
||||
);
|
||||
|
||||
// Should remain unchanged (except for OpenAI wrapper)
|
||||
expect(agent.streamFn).toBeDefined();
|
||||
});
|
||||
|
||||
it("should allow disabling tool_stream via params", () => {
|
||||
const mockStreamFn: StreamFn = vi.fn(() => ({
|
||||
push: vi.fn(),
|
||||
result: vi.fn().mockResolvedValue({
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "ok" }],
|
||||
stopReason: "stop",
|
||||
}),
|
||||
} as any));
|
||||
const mockStreamFn: StreamFn = vi.fn(
|
||||
() =>
|
||||
({
|
||||
push: vi.fn(),
|
||||
result: vi.fn().mockResolvedValue({
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: "ok" }],
|
||||
stopReason: "stop",
|
||||
}),
|
||||
}) as unknown as ReturnType<StreamFn>,
|
||||
);
|
||||
|
||||
const agent = { streamFn: mockStreamFn };
|
||||
const cfg = {
|
||||
@@ -85,7 +99,12 @@ describe("extra-params: Z.AI tool_stream support", () => {
|
||||
},
|
||||
};
|
||||
|
||||
applyExtraParamsToAgent(agent, cfg as any, "zai", "glm-5");
|
||||
applyExtraParamsToAgent(
|
||||
agent,
|
||||
cfg as unknown as Parameters<typeof applyExtraParamsToAgent>[1],
|
||||
"zai",
|
||||
"glm-5",
|
||||
);
|
||||
|
||||
// The tool_stream wrapper should be applied but with enabled=false
|
||||
// In this case, it should just return the underlying streamFn
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { AgentMessage } from "@mariozechner/pi-agent-core";
|
||||
import type { TextContent } from "@mariozechner/pi-ai";
|
||||
import type { SessionManager } from "@mariozechner/pi-coding-agent";
|
||||
import type {
|
||||
PluginHookBeforeMessageWriteEvent,
|
||||
PluginHookBeforeMessageWriteResult,
|
||||
} from "../plugins/types.js";
|
||||
import type { TextContent } from "@mariozechner/pi-ai";
|
||||
import type { SessionManager } from "@mariozechner/pi-coding-agent";
|
||||
import { emitSessionTranscriptUpdate } from "../sessions/transcript-events.js";
|
||||
import { HARD_MAX_TOOL_RESULT_CHARS } from "./pi-embedded-runner/tool-result-truncation.js";
|
||||
import { makeMissingToolResult, sanitizeToolCallInputs } from "./session-transcript-repair.js";
|
||||
@@ -132,10 +132,16 @@ export function installSessionToolResultGuard(
|
||||
* or null if the message should be blocked.
|
||||
*/
|
||||
const applyBeforeWriteHook = (msg: AgentMessage): AgentMessage | null => {
|
||||
if (!beforeWrite) return msg;
|
||||
if (!beforeWrite) {
|
||||
return msg;
|
||||
}
|
||||
const result = beforeWrite({ message: msg });
|
||||
if (result?.block) return null;
|
||||
if (result?.message) return result.message;
|
||||
if (result?.block) {
|
||||
return null;
|
||||
}
|
||||
if (result?.message) {
|
||||
return result.message;
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
@@ -192,7 +198,9 @@ export function installSessionToolResultGuard(
|
||||
isSynthetic: false,
|
||||
}),
|
||||
);
|
||||
if (!persisted) return undefined;
|
||||
if (!persisted) {
|
||||
return undefined;
|
||||
}
|
||||
return originalAppend(persisted as never);
|
||||
}
|
||||
|
||||
@@ -213,7 +221,9 @@ export function installSessionToolResultGuard(
|
||||
}
|
||||
|
||||
const finalMessage = applyBeforeWriteHook(persistMessage(nextMessage));
|
||||
if (!finalMessage) return undefined;
|
||||
if (!finalMessage) {
|
||||
return undefined;
|
||||
}
|
||||
const result = originalAppend(finalMessage as never);
|
||||
|
||||
const sessionFile = (
|
||||
|
||||
Reference in New Issue
Block a user