Merge pull request 'fix: render const values as literals in output format instruction (#129)' (#130) from fix/129-const-prompt into main
CI / check (push) Successful in 2m29s
CI / check (push) Successful in 2m29s
This commit was merged in pull request #130.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
---
|
||||
"@united-workforce/util-agent": patch
|
||||
---
|
||||
|
||||
fix: render const values as literals in output format instruction (#129)
|
||||
|
||||
Previously `buildOutputFormatInstruction` rendered `const: greeted` as
|
||||
`$status: <string>`, causing agents to output `$status: const` instead of
|
||||
the actual value. Now const fields render as `$status: greeted # required | fixed value`.
|
||||
@@ -225,4 +225,34 @@ describe("buildOutputFormatInstruction", () => {
|
||||
const result = buildOutputFormatInstruction({});
|
||||
expect(result).toContain("Focus exclusively on YOUR role");
|
||||
});
|
||||
|
||||
test("renders const value as literal in flat schema example", () => {
|
||||
const schema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
$status: { type: "string", const: "greeted" },
|
||||
message: { type: "string" },
|
||||
},
|
||||
required: ["$status", "message"],
|
||||
};
|
||||
const result = buildOutputFormatInstruction(schema);
|
||||
expect(result).toContain("$status: greeted");
|
||||
expect(result).toContain("fixed value");
|
||||
expect(result).not.toContain("$status: <string>");
|
||||
});
|
||||
|
||||
test("renders const value for non-string types", () => {
|
||||
const schema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
count: { type: "number", const: 42 },
|
||||
done: { type: "boolean", const: true },
|
||||
},
|
||||
required: ["count", "done"],
|
||||
};
|
||||
const result = buildOutputFormatInstruction(schema);
|
||||
expect(result).toContain("count: 42");
|
||||
expect(result).toContain("done: true");
|
||||
expect(result).toContain("fixed value");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -74,6 +74,10 @@ function collectObjectSchemas(schema: JSONSchema): JSONSchema[] {
|
||||
}
|
||||
|
||||
function resolvePropertySchema(prop: JSONSchema): JSONSchema {
|
||||
if (prop.const !== undefined) {
|
||||
return prop;
|
||||
}
|
||||
|
||||
if (Array.isArray(prop.enum) && prop.enum.length > 0) {
|
||||
return prop;
|
||||
}
|
||||
@@ -113,6 +117,11 @@ function buildPropertyExampleLine(prop: SchemaProperty): string {
|
||||
commentParts.push("required");
|
||||
}
|
||||
|
||||
if (resolved.const !== undefined) {
|
||||
commentParts.push("fixed value");
|
||||
return `${prop.name}: ${formatYamlScalar(resolved.const)}${buildPropertyComment(commentParts)}`;
|
||||
}
|
||||
|
||||
if (Array.isArray(resolved.enum) && resolved.enum.length > 0) {
|
||||
const enumValues = resolved.enum.map((v) => String(v));
|
||||
commentParts.push(...enumValues);
|
||||
|
||||
Reference in New Issue
Block a user