Skip to content

Commit 466db07

Browse files
fix(acp): a multi-select with a minimum selection stays required
An ACP form field with minItems > 0 now marks its question required, so the client no longer submits an empty selection that the form rejects and the agent receives as a cancel. AI-assisted; verified with the tests and tools listed above.
1 parent 029fc5d commit 466db07

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

‎packages/provider-acp/src/server/elicitationForm.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,30 @@ describe("parseElicitationForm", () => {
4444
},
4545
);
4646
}
47+
it("requires a multi-select with a minimum and accepts none for an optional one", () => {
48+
const items = { type: "string", enum: ["web", "mobile"] };
49+
const form = parseElicitationForm(
50+
{
51+
type: "object",
52+
properties: {
53+
targets: { type: "array", minItems: 1, items },
54+
extras: { type: "array", items },
55+
},
56+
required: ["targets"],
57+
},
58+
"Choose",
59+
);
60+
assert(form !== undefined);
61+
assert.deepStrictEqual(
62+
form.questions.map((question) => [question.id, question.required]),
63+
[
64+
["targets", true],
65+
["extras", undefined],
66+
],
67+
);
68+
assert.deepStrictEqual(form.content({ targets: ["web"], extras: [] }), {
69+
targets: ["web"],
70+
extras: [],
71+
});
72+
});
4773
});

‎packages/provider-acp/src/server/elicitationForm.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function parseField(
111111
const values = new Set(options.map(optionValue));
112112
const minItems = typeof property.minItems === "number" ? property.minItems : 0;
113113
const maxItems = typeof property.maxItems === "number" ? property.maxItems : Infinity;
114-
// Clients require a selection, so empty-only questions cannot be answered.
114+
// Empty-only questions carry no choice worth asking.
115115
if (maxItems === 0 || minItems > maxItems || minItems > values.size) return undefined;
116116
return { field: { kind: "multiChoice", values, minItems, maxItems }, options };
117117
}
@@ -203,7 +203,9 @@ export function parseElicitationForm(
203203
...(parsed.field.kind === "text" || parsed.field.kind === "number"
204204
? {}
205205
: { allowCustomAnswer: false }),
206-
...(parsed.field.kind === "multiChoice" ? { multiSelect: true } : {}),
206+
...(parsed.field.kind === "multiChoice"
207+
? { multiSelect: true, ...(parsed.field.minItems > 0 ? { required: true } : {}) }
208+
: {}),
207209
});
208210
}
209211
return {

0 commit comments

Comments
 (0)