fix(cron): use jobId parameter instead of id for AI tool schema
Fixes parameter mismatch between AI tool schema and internal validation. The TypeBox schema now uses `jobId` for update/remove/run/runs actions, matching what users expect based on the returned job objects. Changes: - Changed parameter from `id` to `jobId` in TypeBox schema for update/remove/run/runs - Updated execute function to read `jobId` parameter - Updated tests to use `jobId` in input parameters The gateway protocol still uses `id` internally - the tool now maps `jobId` from the AI to `id` for the gateway call. Fixes #185 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
committed by
Peter Steinberger
parent
28a0864de8
commit
4dac298ae2
@@ -16,12 +16,12 @@ describe("cron tool", () => {
|
|||||||
it.each([
|
it.each([
|
||||||
[
|
[
|
||||||
"update",
|
"update",
|
||||||
{ action: "update", id: "job-1", patch: { foo: "bar" } },
|
{ action: "update", jobId: "job-1", patch: { foo: "bar" } },
|
||||||
{ id: "job-1", patch: { foo: "bar" } },
|
{ id: "job-1", patch: { foo: "bar" } },
|
||||||
],
|
],
|
||||||
["remove", { action: "remove", id: "job-1" }, { id: "job-1" }],
|
["remove", { action: "remove", jobId: "job-1" }, { id: "job-1" }],
|
||||||
["run", { action: "run", id: "job-1" }, { id: "job-1" }],
|
["run", { action: "run", jobId: "job-1" }, { id: "job-1" }],
|
||||||
["runs", { action: "runs", id: "job-1" }, { id: "job-1" }],
|
["runs", { action: "runs", jobId: "job-1" }, { id: "job-1" }],
|
||||||
])("%s sends id to gateway", async (action, args, expectedParams) => {
|
])("%s sends id to gateway", async (action, args, expectedParams) => {
|
||||||
const tool = createCronTool();
|
const tool = createCronTool();
|
||||||
await tool.execute("call1", args);
|
await tool.execute("call1", args);
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ const CronToolSchema = Type.Union([
|
|||||||
gatewayUrl: Type.Optional(Type.String()),
|
gatewayUrl: Type.Optional(Type.String()),
|
||||||
gatewayToken: Type.Optional(Type.String()),
|
gatewayToken: Type.Optional(Type.String()),
|
||||||
timeoutMs: Type.Optional(Type.Number()),
|
timeoutMs: Type.Optional(Type.Number()),
|
||||||
id: Type.String(),
|
jobId: Type.String(),
|
||||||
patch: Type.Object({}, { additionalProperties: true }),
|
patch: Type.Object({}, { additionalProperties: true }),
|
||||||
}),
|
}),
|
||||||
Type.Object({
|
Type.Object({
|
||||||
@@ -55,21 +55,21 @@ const CronToolSchema = Type.Union([
|
|||||||
gatewayUrl: Type.Optional(Type.String()),
|
gatewayUrl: Type.Optional(Type.String()),
|
||||||
gatewayToken: Type.Optional(Type.String()),
|
gatewayToken: Type.Optional(Type.String()),
|
||||||
timeoutMs: Type.Optional(Type.Number()),
|
timeoutMs: Type.Optional(Type.Number()),
|
||||||
id: Type.String(),
|
jobId: Type.String(),
|
||||||
}),
|
}),
|
||||||
Type.Object({
|
Type.Object({
|
||||||
action: Type.Literal("run"),
|
action: Type.Literal("run"),
|
||||||
gatewayUrl: Type.Optional(Type.String()),
|
gatewayUrl: Type.Optional(Type.String()),
|
||||||
gatewayToken: Type.Optional(Type.String()),
|
gatewayToken: Type.Optional(Type.String()),
|
||||||
timeoutMs: Type.Optional(Type.Number()),
|
timeoutMs: Type.Optional(Type.Number()),
|
||||||
id: Type.String(),
|
jobId: Type.String(),
|
||||||
}),
|
}),
|
||||||
Type.Object({
|
Type.Object({
|
||||||
action: Type.Literal("runs"),
|
action: Type.Literal("runs"),
|
||||||
gatewayUrl: Type.Optional(Type.String()),
|
gatewayUrl: Type.Optional(Type.String()),
|
||||||
gatewayToken: Type.Optional(Type.String()),
|
gatewayToken: Type.Optional(Type.String()),
|
||||||
timeoutMs: Type.Optional(Type.Number()),
|
timeoutMs: Type.Optional(Type.Number()),
|
||||||
id: Type.String(),
|
jobId: Type.String(),
|
||||||
}),
|
}),
|
||||||
Type.Object({
|
Type.Object({
|
||||||
action: Type.Literal("wake"),
|
action: Type.Literal("wake"),
|
||||||
@@ -121,7 +121,7 @@ export function createCronTool(): AnyAgentTool {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
case "update": {
|
case "update": {
|
||||||
const id = readStringParam(params, "id", { required: true });
|
const id = readStringParam(params, "jobId", { required: true });
|
||||||
if (!params.patch || typeof params.patch !== "object") {
|
if (!params.patch || typeof params.patch !== "object") {
|
||||||
throw new Error("patch required");
|
throw new Error("patch required");
|
||||||
}
|
}
|
||||||
@@ -134,19 +134,19 @@ export function createCronTool(): AnyAgentTool {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
case "remove": {
|
case "remove": {
|
||||||
const id = readStringParam(params, "id", { required: true });
|
const id = readStringParam(params, "jobId", { required: true });
|
||||||
return jsonResult(
|
return jsonResult(
|
||||||
await callGatewayTool("cron.remove", gatewayOpts, { id }),
|
await callGatewayTool("cron.remove", gatewayOpts, { id }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case "run": {
|
case "run": {
|
||||||
const id = readStringParam(params, "id", { required: true });
|
const id = readStringParam(params, "jobId", { required: true });
|
||||||
return jsonResult(
|
return jsonResult(
|
||||||
await callGatewayTool("cron.run", gatewayOpts, { id }),
|
await callGatewayTool("cron.run", gatewayOpts, { id }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case "runs": {
|
case "runs": {
|
||||||
const id = readStringParam(params, "id", { required: true });
|
const id = readStringParam(params, "jobId", { required: true });
|
||||||
return jsonResult(
|
return jsonResult(
|
||||||
await callGatewayTool("cron.runs", gatewayOpts, { id }),
|
await callGatewayTool("cron.runs", gatewayOpts, { id }),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user