rowboat/apps/rowboat/app/lib/client_utils.ts
tusharmagar 24f930fa86 feat: Add Copilot trigger creation support
- Add support for One-Time and Recurring triggers in Copilot
- Extend CopilotAssistantMessageActionPart schema with trigger config types
- Update Copilot instructions with trigger creation examples and guidelines
- Implement trigger action handling in messages.tsx component
- Add trigger icons ( for one-time, 🔄 for recurring) in action cards
- Update workflow reducer to handle trigger creation via existing APIs
- Fix action parser to recognize trigger config types in comment format
- Add async trigger processing using createScheduledJobRule and createRecurringJobRule APIs

Users can now ask Copilot to create triggers with natural language requests like:
'Create a daily report trigger at 9 AM' or 'Set up a one-time reminder for next Friday'
2025-09-24 11:25:40 +05:30

114 lines
3.5 KiB
TypeScript

import { WorkflowTool, WorkflowAgent, WorkflowPrompt, WorkflowPipeline } from "./types/workflow_types";
import { Message } from "./types/types";
import { z } from "zod";
const ZFallbackSchema = z.object({}).passthrough();
export function validateConfigChanges(configType: string, configChanges: Record<string, unknown>, name: string) {
let testObject: any;
let schema: z.ZodType<any> = ZFallbackSchema;
switch (configType) {
case 'tool': {
testObject = {
name: 'test',
description: 'test',
parameters: {
type: 'object',
properties: {},
required: [],
},
} as z.infer<typeof WorkflowTool>;
schema = WorkflowTool;
break;
}
case 'agent': {
testObject = {
name: 'test',
description: 'test',
type: 'conversation',
instructions: 'test',
prompts: [],
tools: [],
model: 'gpt-4.1',
ragReturnType: 'chunks',
ragK: 10,
connectedAgents: [],
controlType: 'retain',
outputVisibility: 'user_facing',
maxCallsPerParentAgent: 3,
} as z.infer<typeof WorkflowAgent>;
schema = WorkflowAgent;
break;
}
case 'prompt': {
testObject = {
name: 'test',
type: 'base_prompt',
prompt: "test",
} as z.infer<typeof WorkflowPrompt>;
schema = WorkflowPrompt;
break;
}
case 'pipeline': {
testObject = {
name: 'test',
description: 'test',
agents: [],
} as z.infer<typeof WorkflowPipeline>;
schema = WorkflowPipeline;
break;
}
case 'start_agent': {
testObject = {};
break;
}
case 'one_time_trigger': {
testObject = {
scheduledTime: new Date(0).toISOString(),
input: {
messages: [],
},
};
schema = z.object({
scheduledTime: z.string().min(1),
input: z.object({
messages: z.array(Message),
}),
}).passthrough();
break;
}
case 'recurring_trigger': {
testObject = {
cron: '* * * * *',
input: {
messages: [],
},
};
schema = z.object({
cron: z.string().min(1),
input: z.object({
messages: z.array(Message),
}),
}).passthrough();
break;
}
default:
return { error: `Unknown config type: ${configType}` };
}
// Validate each field and remove invalid ones
const validatedChanges = { ...configChanges };
for (const [key, value] of Object.entries(configChanges)) {
const result = schema.safeParse({
...testObject,
[key]: value,
});
if (!result.success) {
console.log(`discarding field ${key} from ${configType}: ${name}`, result.error.message);
delete validatedChanges[key];
}
}
return { changes: validatedChanges };
}