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
17 changes: 17 additions & 0 deletions apps/api/src/handlers/custom-automations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ type CustomAutomationVariables = Variables & {
customAutomationAdminId: string;
};

const modelSchema = z
.string()
.trim()
.min(1)
.max(200)
.regex(/^[^/\s]+\/.+$/u, 'Model must use provider/model format.');

const writeSchema = z.object({
name: z.string().trim().min(1).max(100),
prompt: z.string().trim().min(1).max(8_000),
enabled: z.boolean().default(true),
schedule: z.string().trim().min(1).max(500),
model: modelSchema.optional(),
environmentId: z.string().uuid(),
targetProvider: z.enum(['slack', 'discord', 'teams', 'telegram']).optional(),
targetChannelId: z.string().trim().min(1).max(160).optional(),
Expand All @@ -51,6 +59,7 @@ const updateSchema = z.object({
prompt: z.string().trim().min(1).max(8_000).optional(),
enabled: z.boolean().optional(),
schedule: z.string().trim().min(1).max(500).optional(),
model: modelSchema.nullable().optional(),
environmentId: z.string().uuid().optional(),
targetProvider: z
.enum(['slack', 'discord', 'teams', 'telegram'])
Expand Down Expand Up @@ -132,6 +141,8 @@ const VALIDATION_ERROR_PATTERNS: RegExp[] = [
/^Cron expression must be at most \d+ characters\.$/,
/^Cron expression must be between 1 and \d+ characters\.$/,
/^Use a standard five-field cron expression\.$/,
/^Model must be at most \d+ characters\.$/,
/^Model must use provider\/model format\.$/,
/^Environment is required\.$/,
/^Selected environment was not found\.$/,
/^Custom automation was not found\.$/,
Expand Down Expand Up @@ -313,6 +324,7 @@ customAutomationsRouter.post('/', async (c) => {
enabled: parsed.data.enabled,
scheduleMode: schedule.scheduleMode,
cronExpression: schedule.cronExpression,
model: parsed.data.model ?? null,
environmentId: parsed.data.environmentId,
target: buildTarget(parsed.data),
createdByUserId: adminId(c),
Expand Down Expand Up @@ -373,6 +385,11 @@ customAutomationsRouter.patch('/:id', async (c) => {
enabled: parsed.data.enabled ?? existing.enabled,
scheduleMode: schedule.scheduleMode,
cronExpression: schedule.cronExpression,
// Explicit null clears the override; omitted keeps the existing value.
model:
parsed.data.model === null
? null
: (parsed.data.model ?? existing.model),
environmentId: parsed.data.environmentId ?? existing.environmentId ?? '',
target: clearTarget
? {}
Expand Down
2 changes: 2 additions & 0 deletions apps/docs/automations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Create arbitrary scheduled agent runs with:
- the **prompt** Roomote should run
- a **cadence** (`every hour`, `every 6 hours`, `daily`, or `weekly`)
- one required **environment**
- an optional **model** override for the runs; the default follows the
deployment task model
- an optional **report destination** channel (Slack, Discord, Teams, or
Telegram)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
Trash2,
} from '@/components/system';

import { ModelSelect } from '@/components/tasks/ModelSelect';

import { SlackChannelSelect } from './SlackChannelSelect';

type CustomAutomationFormState = {
Expand All @@ -42,6 +44,8 @@ type CustomAutomationFormState = {
scheduleMode: CustomAutomationScheduleMode;
environmentId: string;
cronExpression: string;
/** Provider/model launch override; empty string means deployment default. */
model: string;
targetProvider: 'none' | 'slack' | 'discord' | 'teams' | 'telegram';
targetChannelId: string;
targetServiceUrl: string;
Expand All @@ -54,6 +58,7 @@ const EMPTY_FORM: CustomAutomationFormState = {
scheduleMode: 'daily',
environmentId: '',
cronExpression: '',
model: '',
targetProvider: 'slack',
targetChannelId: '',
targetServiceUrl: '',
Expand Down Expand Up @@ -112,6 +117,7 @@ function formFromRow(row: CustomAutomationListItem): CustomAutomationFormState {
scheduleMode: row.scheduleMode,
environmentId: row.environmentId ?? '',
cronExpression: row.cronExpression ?? '',
model: row.model ?? '',
targetProvider: target.provider,
targetChannelId: target.channelId,
targetServiceUrl: target.serviceUrl,
Expand Down Expand Up @@ -349,6 +355,7 @@ export function CustomAutomationsSection() {
scheduleMode: form.scheduleMode,
cronExpression:
form.scheduleMode === 'cron' ? effectiveResolvedCron : null,
model: form.model || null,
environmentId: form.environmentId,
...(form.targetProvider !== 'none'
? {
Expand Down Expand Up @@ -437,6 +444,53 @@ export function CustomAutomationsSection() {
</Select>
</div>

{form.scheduleMode === 'cron' ? (
<div className="space-y-2">
<Label htmlFor="custom-automation-cron">Custom schedule</Label>
<Input
id="custom-automation-cron"
value={form.cronExpression}
disabled={busy}
placeholder="Weekdays at 9am or 0 9 * * 1-5"
onChange={(event) => {
setResolvedCron(null);
setScheduleSummary(null);
setForm((current) => ({
...current,
cronExpression: event.target.value,
}));
}}
onBlur={() => {
const alreadyResolvingThisInput =
resolveScheduleMutation.isPending &&
resolveScheduleMutation.variables?.schedule ===
form.cronExpression;
if (
!clientParsedCron &&
!resolvedCron &&
form.cronExpression.trim() &&
!alreadyResolvingThisInput
) {
resolveScheduleMutation.mutate({
schedule: form.cronExpression,
});
}
}}
/>
{resolveScheduleMutation.isPending ? (
<p className="text-sm text-muted-foreground">
Interpreting schedule...
</p>
) : effectiveScheduleSummary ? (
<p className="text-sm text-muted-foreground">
{effectiveScheduleSummary}
</p>
) : null}
</div>
) : null}
</div>

<div className="grid gap-4 sm:grid-cols-2">
<div className="space-y-2">
<Label>Environment</Label>
<Select
Expand All @@ -461,53 +515,22 @@ export function CustomAutomationsSection() {
</SelectContent>
</Select>
</div>
</div>

{form.scheduleMode === 'cron' ? (
<div className="space-y-2">
<Label htmlFor="custom-automation-cron">Custom schedule</Label>
<Input
id="custom-automation-cron"
className="sm:max-w-md"
value={form.cronExpression}
<Label>Model</Label>
<ModelSelect
className="w-full"
size="default"
ariaLabel="Automation model"
value={form.model}
emptyOptionLabel="Default coding model"
disabled={busy}
placeholder="Weekdays at 9am or 0 9 * * 1-5"
onChange={(event) => {
setResolvedCron(null);
setScheduleSummary(null);
setForm((current) => ({
...current,
cronExpression: event.target.value,
}));
}}
onBlur={() => {
const alreadyResolvingThisInput =
resolveScheduleMutation.isPending &&
resolveScheduleMutation.variables?.schedule ===
form.cronExpression;
if (
!clientParsedCron &&
!resolvedCron &&
form.cronExpression.trim() &&
!alreadyResolvingThisInput
) {
resolveScheduleMutation.mutate({
schedule: form.cronExpression,
});
}
}}
onValueChange={(value) =>
setForm((current) => ({ ...current, model: value }))
}
/>
{resolveScheduleMutation.isPending ? (
<p className="text-sm text-muted-foreground">
Interpreting schedule...
</p>
) : effectiveScheduleSummary ? (
<p className="text-sm text-muted-foreground">
{effectiveScheduleSummary}
</p>
) : null}
</div>
) : null}
</div>

<div className="grid gap-4 sm:grid-cols-2">
<div className="space-y-2">
Expand Down Expand Up @@ -746,6 +769,7 @@ export function CustomAutomationsSection() {
? destinationLabel
: `${target.provider}:${destinationLabel}`}{' '}
· {statusLine(row)}
{row.model ? ` · ${row.model}` : null}
{row.createdByName ? ` · by ${row.createdByName}` : null}
</p>
</div>
Expand Down
24 changes: 21 additions & 3 deletions apps/web/src/components/tasks/ModelSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ type ModelSelectProps = {
disabled?: boolean;
className?: string;
ariaLabel?: string;
/**
* When set, renders this label as a leading option that maps to the empty
* string value, for pickers where "no override" is a valid choice.
*/
emptyOptionLabel?: string;
/** Trigger size; use 'default' to line up with default-size form controls. */
size?: 'sm' | 'default';
};

// Radix Select items cannot use an empty-string value, so the empty option
// round-trips through this sentinel.
const EMPTY_OPTION_VALUE = '__model-select-empty__';

function modelOptionLabel(model: {
displayName: string;
isDefault?: boolean;
Expand All @@ -35,6 +46,8 @@ export function ModelSelect({
disabled = false,
className,
ariaLabel = 'Model',
emptyOptionLabel,
size = 'sm',
}: ModelSelectProps) {
const { data, isPending } = useLaunchTaskModels();
const modelGroups = useMemo(() => {
Expand All @@ -59,14 +72,19 @@ export function ModelSelect({

return (
<Select
value={value}
onValueChange={onValueChange}
value={emptyOptionLabel && !value ? EMPTY_OPTION_VALUE : value}
onValueChange={(next) =>
onValueChange(next === EMPTY_OPTION_VALUE ? '' : next)
}
disabled={disabled || isPending || !data}
>
<SelectTrigger size="sm" className={className} aria-label={ariaLabel}>
<SelectTrigger size={size} className={className} aria-label={ariaLabel}>
<SelectValue placeholder="Model" />
</SelectTrigger>
<SelectContent>
{emptyOptionLabel ? (
<SelectItem value={EMPTY_OPTION_VALUE}>{emptyOptionLabel}</SelectItem>
) : null}
{showProviderHeaders
? modelGroups.map((group) => (
<SelectGroup key={group.providerId}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type CustomAutomationListItem = {
enabled: boolean;
scheduleMode: CustomAutomationScheduleMode;
cronExpression: string | null;
model: string | null;
environmentId: string | null;
target: OptionalAutomationTarget;
lastRunAt: Date | null;
Expand All @@ -52,6 +53,8 @@ export type CustomAutomationWriteInput = {
enabled: boolean;
scheduleMode: string;
cronExpression?: string | null;
/** Provider/model launch override, or null for the deployment default. */
model?: string | null;
environmentId: string;
/** Omitted when the automation has no report destination channel. */
targetProvider?: 'slack' | 'discord' | 'teams' | 'telegram';
Expand All @@ -78,6 +81,7 @@ function toListItem(
enabled: row.enabled,
scheduleMode,
cronExpression: row.cronExpression,
model: row.model,
environmentId: row.environmentId,
target: row.target,
lastRunAt: row.lastRunAt,
Expand Down Expand Up @@ -181,6 +185,7 @@ export async function createCustomAutomationCommand(
enabled: input.enabled,
scheduleMode: input.scheduleMode,
cronExpression,
model: input.model ?? null,
environmentId: input.environmentId,
target: buildTarget(input),
createdByUserId: auth.userId,
Expand Down Expand Up @@ -212,6 +217,7 @@ export async function updateCustomAutomationCommand(
enabled: input.enabled,
scheduleMode: input.scheduleMode,
cronExpression,
model: input.model ?? null,
environmentId: input.environmentId,
target: buildTarget(input),
});
Expand Down
16 changes: 16 additions & 0 deletions apps/web/src/trpc/routers/_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,14 @@ const automationsRouter = createRouter({
'cron',
]),
cronExpression: z.string().trim().max(200).nullable().optional(),
model: z
.string()
.trim()
.min(1)
.max(200)
.regex(/^[^/\s]+\/.+$/u, 'Model must use provider/model format.')
.nullable()
.optional(),
environmentId: z.string().uuid(),
targetProvider: z
.enum(['slack', 'discord', 'teams', 'telegram'])
Expand Down Expand Up @@ -699,6 +707,14 @@ const automationsRouter = createRouter({
'cron',
]),
cronExpression: z.string().trim().max(200).nullable().optional(),
model: z
.string()
.trim()
.min(1)
.max(200)
.regex(/^[^/\s]+\/.+$/u, 'Model must use provider/model format.')
.nullable()
.optional(),
environmentId: z.string().uuid(),
targetProvider: z
.enum(['slack', 'discord', 'teams', 'telegram'])
Expand Down
Loading
Loading