Skip to content

Commit 8ba2de8

Browse files
committed
agents: use flat heartbeat tool enums
1 parent e693753 commit 8ba2de8

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/agents/tools/heartbeat-response-tool.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,32 @@ import { describe, expect, it } from "vitest";
22
import { HEARTBEAT_RESPONSE_TOOL_NAME } from "../../auto-reply/heartbeat-tool-response.js";
33
import { createHeartbeatResponseTool } from "./heartbeat-response-tool.js";
44

5+
function readSchemaProperty(schema: unknown, key: string): Record<string, unknown> {
6+
const root = schema as { properties?: Record<string, unknown> };
7+
const property = root.properties?.[key];
8+
expect(property).toBeTruthy();
9+
return property as Record<string, unknown>;
10+
}
11+
512
describe("createHeartbeatResponseTool", () => {
13+
it("uses flat enum schemas for provider portability", () => {
14+
const tool = createHeartbeatResponseTool();
15+
16+
const outcome = readSchemaProperty(tool.parameters, "outcome");
17+
const priority = readSchemaProperty(tool.parameters, "priority");
18+
19+
expect(outcome).toMatchObject({
20+
type: "string",
21+
enum: ["no_change", "progress", "done", "blocked", "needs_attention"],
22+
});
23+
expect(priority).toMatchObject({
24+
type: "string",
25+
enum: ["low", "normal", "high"],
26+
});
27+
expect(outcome).not.toHaveProperty("anyOf");
28+
expect(priority).not.toHaveProperty("anyOf");
29+
});
30+
631
it("records a quiet heartbeat outcome", async () => {
732
const tool = createHeartbeatResponseTool();
833

src/agents/tools/heartbeat-response-tool.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ import {
66
normalizeHeartbeatToolResponse,
77
} from "../../auto-reply/heartbeat-tool-response.js";
88
import { readSnakeCaseParamRaw } from "../../param-key.js";
9+
import { optionalStringEnum, stringEnum } from "../schema/string-enum.js";
910
import type { AnyAgentTool } from "./common.js";
1011
import { jsonResult, ToolInputError } from "./common.js";
1112

1213
const HeartbeatResponseToolSchema = Type.Object(
1314
{
14-
outcome: Type.Union(HEARTBEAT_TOOL_OUTCOMES.map((value) => Type.Literal(value))),
15+
outcome: stringEnum(HEARTBEAT_TOOL_OUTCOMES),
1516
notify: Type.Boolean(),
1617
summary: Type.String(),
1718
notificationText: Type.Optional(Type.String()),
1819
reason: Type.Optional(Type.String()),
19-
priority: Type.Optional(
20-
Type.Union(HEARTBEAT_TOOL_PRIORITIES.map((value) => Type.Literal(value))),
21-
),
20+
priority: optionalStringEnum(HEARTBEAT_TOOL_PRIORITIES),
2221
nextCheck: Type.Optional(Type.String()),
2322
},
2423
{ additionalProperties: false },

0 commit comments

Comments
 (0)