fix(cli): fail empty local model probes

This commit is contained in:
Peter Steinberger
2026-04-27 23:16:29 +01:00
parent 81390c643b
commit 48e91f09d5
4 changed files with 40 additions and 13 deletions

View File

@@ -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,

View File

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