Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/core/src/tools/cron-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ describe('CronCreateTool', () => {
expect(tasks).toHaveLength(0);
});

it.each(['', ' '])('rejects blank prompt %j', (prompt) => {
expect(() =>
tool.build({
cron: '*/5 * * * *',
prompt,
}),
).toThrow('Parameter "prompt" must be a non-empty string.');
expect(config._scheduler.list()).toHaveLength(0);
});

it('trims the prompt before scheduling the job', async () => {
const invocation = tool.build({
cron: '*/5 * * * *',
prompt: ' check status ',
});

const result = await invocation.execute(new AbortController().signal);

expect(result.error).toBeUndefined();
const jobs = config._scheduler.list();
expect(jobs).toHaveLength(1);
expect(jobs[0]!.prompt).toBe('check status');
});

it('returns error for invalid cron expression', async () => {
const invocation = tool.build({
cron: 'bad cron',
Expand Down
18 changes: 12 additions & 6 deletions packages/core/src/tools/cron-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CronCreateInvocation extends BaseToolInvocation<
const scheduler = this.config.getCronScheduler();
const recurring = this.params.recurring !== false;
const durable = this.params.durable === true;
const prompt = this.params.prompt.trim();

try {
// Validate cron expression before creating the job
Expand All @@ -59,12 +60,8 @@ class CronCreateInvocation extends BaseToolInvocation<
nextFireTime(this.params.cron, new Date());

const job = durable
? await scheduler.createDurable(
this.params.cron,
this.params.prompt,
recurring,
)
: scheduler.create(this.params.cron, this.params.prompt, recurring);
? await scheduler.createDurable(this.params.cron, prompt, recurring)
: scheduler.create(this.params.cron, prompt, recurring);

const display = humanReadableCron(job.cronExpr);
const returnDisplay = `Scheduled ${job.id} (${display})${durable ? ' [durable]' : ''}`;
Expand Down Expand Up @@ -165,6 +162,15 @@ export class CronCreateTool extends BaseDeclarativeTool<
return new CronCreateInvocation(this.config, params);
}

protected override validateToolParamValues(
params: CronCreateParams,
): string | null {
if (!params.prompt || params.prompt.trim() === '') {
return 'Parameter "prompt" must be a non-empty string.';
}
return null;
}

/**
* Forward the prompt and cadence to the classifier. The scheduled
* prompt will be enqueued and executed against the agent at fire-time,
Expand Down
Loading