mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 08:30:43 +00:00
fix(cli): fail empty local model probes
This commit is contained in:
@@ -419,6 +419,24 @@ describe("capability cli", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("fails local model probes when the provider returns no text output", async () => {
|
||||
mocks.completeWithPreparedSimpleCompletionModel.mockResolvedValueOnce({
|
||||
content: [],
|
||||
} as never);
|
||||
|
||||
await expect(
|
||||
runRegisteredCli({
|
||||
register: registerCapabilityCli as (program: Command) => void,
|
||||
argv: ["capability", "model", "run", "--prompt", "hello", "--json"],
|
||||
}),
|
||||
).rejects.toThrow("exit 1");
|
||||
|
||||
expect(mocks.runtime.error).toHaveBeenCalledWith(
|
||||
expect.stringContaining('No text output returned for provider "openai" model "gpt-5.4"'),
|
||||
);
|
||||
expect(mocks.runtime.writeJson).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("runs gateway model probes without chat-agent prompt policy or tools", async () => {
|
||||
await runRegisteredCli({
|
||||
register: registerCapabilityCli as (program: Command) => void,
|
||||
|
||||
@@ -112,7 +112,7 @@ type CapabilityEnvelope = {
|
||||
const CAPABILITY_METADATA: CapabilityMetadata[] = [
|
||||
{
|
||||
id: "model.run",
|
||||
description: "Run a one-shot text inference turn through the agent runtime.",
|
||||
description: "Run a one-shot text inference turn through the selected model provider.",
|
||||
transports: ["local", "gateway"],
|
||||
flags: ["--prompt", "--model", "--local", "--gateway", "--json"],
|
||||
resultShape: "normalized payloads plus provider/model attribution",
|
||||
@@ -570,6 +570,13 @@ function requireProviderModelOverride(
|
||||
};
|
||||
}
|
||||
|
||||
function collectModelRunText(content: Array<{ type: string; text?: string }>): string {
|
||||
return content
|
||||
.map((block) => (block.type === "text" && typeof block.text === "string" ? block.text : ""))
|
||||
.join("")
|
||||
.trim();
|
||||
}
|
||||
|
||||
async function runModelRun(params: {
|
||||
prompt: string;
|
||||
model?: string;
|
||||
@@ -607,10 +614,12 @@ async function runModelRun(params: {
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
const text = result.content
|
||||
.map((block) => (block.type === "text" ? block.text : ""))
|
||||
.join("")
|
||||
.trim();
|
||||
const text = collectModelRunText(result.content);
|
||||
if (!text) {
|
||||
throw new Error(
|
||||
`No text output returned for provider "${prepared.selection.provider}" model "${prepared.selection.modelId}".`,
|
||||
);
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
capability: "model.run",
|
||||
@@ -618,14 +627,12 @@ async function runModelRun(params: {
|
||||
provider: prepared.selection.provider,
|
||||
model: prepared.selection.modelId,
|
||||
attempts: [],
|
||||
outputs: text
|
||||
? [
|
||||
{
|
||||
text,
|
||||
mediaUrl: null,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
outputs: [
|
||||
{
|
||||
text,
|
||||
mediaUrl: null,
|
||||
},
|
||||
],
|
||||
} satisfies CapabilityEnvelope;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user