mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
Refactor schedules hooks to accept repoId as parameter
Remove repoId from hook closure and pass it explicitly. Improves reusability and makes hooks more flexible.
This commit is contained in:
1 parent
9975be955e
commit
fbf259f22c
8 files changed
+665
-446
No files matched your search
@@ -0,0 +1,137 @@
|
||||
import { Combobox, type ComboboxOption } from '@/components/ui/combobox'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { TabsContent } from '@/components/ui/tabs'
|
||||
import { Info } from 'lucide-react'
|
||||
|
||||
type GeneralTabProps = {
|
||||
name: string
|
||||
onNameChange: (value: string) => void
|
||||
description: string
|
||||
onDescriptionChange: (value: string) => void
|
||||
agentSlug: string
|
||||
onAgentSlugChange: (value: string) => void
|
||||
agentOptions: ComboboxOption[]
|
||||
model: string
|
||||
onModelChange: (value: string) => void
|
||||
modelOptions: ComboboxOption[]
|
||||
enabled: boolean
|
||||
onEnabledChange: (value: boolean) => void
|
||||
showRepoSelector?: boolean
|
||||
isEditing: boolean
|
||||
repoId?: number
|
||||
onRepoChange?: (repoId: number | undefined) => void
|
||||
repoOptions: ComboboxOption[]
|
||||
}
|
||||
|
||||
function InfoHint({ text }: { text: string }) {
|
||||
return (
|
||||
<span
|
||||
title={text}
|
||||
aria-label={text}
|
||||
className="inline-flex h-4 w-4 items-center justify-center text-muted-foreground"
|
||||
>
|
||||
<Info className="h-3.5 w-3.5" />
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
export function GeneralTab({
|
||||
name,
|
||||
onNameChange,
|
||||
description,
|
||||
onDescriptionChange,
|
||||
agentSlug,
|
||||
onAgentSlugChange,
|
||||
agentOptions,
|
||||
model,
|
||||
onModelChange,
|
||||
modelOptions,
|
||||
enabled,
|
||||
onEnabledChange,
|
||||
showRepoSelector,
|
||||
isEditing,
|
||||
repoId,
|
||||
onRepoChange,
|
||||
repoOptions,
|
||||
}: GeneralTabProps) {
|
||||
return (
|
||||
<TabsContent value="basics" className="mt-0 min-h-0 flex-1 overflow-y-auto pt-4 pb-5">
|
||||
<div className="space-y-4">
|
||||
{showRepoSelector && !isEditing && (
|
||||
<div className="space-y-2">
|
||||
<Label>Repository</Label>
|
||||
<Combobox
|
||||
value={repoId?.toString() ?? ''}
|
||||
onChange={(value) => onRepoChange?.(value ? Number(value) : undefined)}
|
||||
options={repoOptions}
|
||||
placeholder="Select a repository"
|
||||
allowCustomValue={false}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-name">Name</Label>
|
||||
<Input
|
||||
id="schedule-name"
|
||||
value={name}
|
||||
onChange={(event) => onNameChange(event.target.value)}
|
||||
placeholder="Nightly repo health check"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-description">Description</Label>
|
||||
<Input
|
||||
id="schedule-description"
|
||||
value={description}
|
||||
onChange={(event) => onDescriptionChange(event.target.value)}
|
||||
placeholder="What this job checks or produces"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-[minmax(0,1fr)_220px] sm:items-end">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-agent">Agent slug</Label>
|
||||
<Combobox
|
||||
value={agentSlug}
|
||||
onChange={onAgentSlugChange}
|
||||
options={agentOptions}
|
||||
placeholder="Select an agent"
|
||||
allowCustomValue
|
||||
showClear
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label htmlFor="schedule-model">Model override</Label>
|
||||
<InfoHint text="Pick from detected OpenCode models or type a custom provider/model value." />
|
||||
</div>
|
||||
<Combobox
|
||||
value={model}
|
||||
onChange={onModelChange}
|
||||
options={modelOptions}
|
||||
placeholder="Workspace default"
|
||||
allowCustomValue
|
||||
showClear
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rounded-lg border border-border bg-card p-4">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<p className="text-sm font-medium">Enabled</p>
|
||||
<InfoHint text="Auto-run this job on its schedule while still allowing manual runs from the dashboard." />
|
||||
</div>
|
||||
<Switch checked={enabled} onCheckedChange={onEnabledChange} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { TabsContent } from '@/components/ui/tabs'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Check, Pencil, Plus, Trash2 } from 'lucide-react'
|
||||
import type { PromptTemplate } from '@opencode-manager/shared/types'
|
||||
|
||||
type PromptTabProps = {
|
||||
prompt: string
|
||||
onPromptChange: (value: string) => void
|
||||
selectedPromptTemplateId: number | null
|
||||
onApplyTemplate: (template: PromptTemplate) => void
|
||||
templates: PromptTemplate[]
|
||||
onEditTemplate: (template: PromptTemplate) => void
|
||||
onDeleteTemplate: (templateId: number) => void
|
||||
onNewTemplate: () => void
|
||||
}
|
||||
|
||||
export function PromptTab({
|
||||
prompt,
|
||||
onPromptChange,
|
||||
selectedPromptTemplateId,
|
||||
onApplyTemplate,
|
||||
templates,
|
||||
onEditTemplate,
|
||||
onDeleteTemplate,
|
||||
onNewTemplate,
|
||||
}: PromptTabProps) {
|
||||
return (
|
||||
<TabsContent value="prompt" className="mt-0 min-h-0 flex-1 overflow-y-auto px-3 pt-4 pb-5 sm:px-4">
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
<Label>Prompt templates</Label>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-7 gap-1 text-xs"
|
||||
onClick={onNewTemplate}
|
||||
>
|
||||
<Plus className="h-3 w-3" />
|
||||
New
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-3 lg:grid-cols-2">
|
||||
{templates.map((template) => {
|
||||
const isSelected = selectedPromptTemplateId === template.id
|
||||
|
||||
return (
|
||||
<div key={template.id} className="relative group">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onApplyTemplate(template)}
|
||||
className={`w-full rounded-xl border-2 p-4 text-left transition-all ${
|
||||
isSelected
|
||||
? 'border-primary bg-primary/10 ring-2 ring-primary/30'
|
||||
: 'border-border bg-card hover:bg-accent/40'
|
||||
}`}
|
||||
>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Badge className="text-[10px] uppercase tracking-wide border-transparent bg-orange-500 text-white">
|
||||
{template.category}
|
||||
</Badge>
|
||||
<Badge className="text-[10px] uppercase tracking-wide border-transparent bg-slate-600 text-white">
|
||||
{template.cadenceHint}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="mt-3">
|
||||
<p className="text-sm font-semibold">{template.title}</p>
|
||||
<p className="mt-1 text-xs text-muted-foreground">{template.description}</p>
|
||||
</div>
|
||||
<p className="mt-3 text-xs text-muted-foreground line-clamp-3">{template.suggestedDescription}</p>
|
||||
{isSelected && (
|
||||
<div className="absolute top-2 right-2 h-5 w-5 rounded-full bg-primary flex items-center justify-center">
|
||||
<Check className="h-3 w-3 text-primary-foreground" />
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
<div className={`absolute top-2 right-10 flex gap-1 transition-opacity ${isSelected ? 'opacity-100' : 'opacity-0 group-hover:opacity-100'}`}>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6"
|
||||
onClick={(e) => { e.stopPropagation(); onEditTemplate(template) }}
|
||||
>
|
||||
<Pencil className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 text-destructive hover:text-destructive"
|
||||
onClick={(e) => { e.stopPropagation(); onDeleteTemplate(template.id) }}
|
||||
>
|
||||
<Trash2 className="h-3 w-3" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-prompt">Prompt</Label>
|
||||
<Textarea
|
||||
id="schedule-prompt"
|
||||
value={prompt}
|
||||
onChange={(event) => {
|
||||
onPromptChange(event.target.value)
|
||||
}}
|
||||
className="min-h-[320px]"
|
||||
placeholder="Review the repo, summarize notable risks, and open a session I can inspect later."
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
This prompt becomes the first message sent to the agent when the schedule runs.
|
||||
</p>
|
||||
</div>
|
||||
</TabsContent>
|
||||
)
|
||||
}
|
||||
@@ -7,32 +7,25 @@ import { settingsApi } from '@/api/settings'
|
||||
import { listRepos } from '@/api/repos'
|
||||
import type { Repo } from '@/api/types'
|
||||
import { OPENCODE_API_ENDPOINT } from '@/config'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Combobox, type ComboboxOption } from '@/components/ui/combobox'
|
||||
import type { ComboboxOption } from '@/components/ui/combobox'
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { MultiSelect } from '@/components/ui/multi-select'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import {
|
||||
buildCronExpressionFromPreset,
|
||||
cronPresetOptions,
|
||||
detectSchedulePreset,
|
||||
formatDraftScheduleSummary,
|
||||
getLocalTimeZone,
|
||||
intervalOptions,
|
||||
schedulePresetOptions,
|
||||
type SchedulePreset,
|
||||
weekdayOptions,
|
||||
} from '@/components/schedules/schedule-utils'
|
||||
import { getRepoDisplayName } from '@/lib/utils'
|
||||
import { Check, Info, Loader2, Pencil, Plus, Sparkles, Trash2 } from 'lucide-react'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { usePromptTemplates, useDeletePromptTemplate } from '@/hooks/usePromptTemplates'
|
||||
import { PromptTemplateDialog } from './PromptTemplateDialog'
|
||||
import { DeleteDialog } from '@/components/ui/delete-dialog'
|
||||
import { GeneralTab } from './GeneralTab'
|
||||
import { TimingTab } from './TimingTab'
|
||||
import { PromptTab } from './PromptTab'
|
||||
import { SkillsTab } from './SkillsTab'
|
||||
|
||||
type ScheduleJobDialogProps = {
|
||||
open: boolean
|
||||
@@ -43,18 +36,7 @@ type ScheduleJobDialogProps = {
|
||||
showRepoSelector?: boolean
|
||||
repoId?: number
|
||||
onRepoChange?: (repoId: number | undefined) => void
|
||||
}
|
||||
|
||||
function InfoHint({ text }: { text: string }) {
|
||||
return (
|
||||
<span
|
||||
title={text}
|
||||
aria-label={text}
|
||||
className="inline-flex h-4 w-4 items-center justify-center text-muted-foreground"
|
||||
>
|
||||
<Info className="h-3.5 w-3.5" />
|
||||
</span>
|
||||
)
|
||||
isEditing?: boolean
|
||||
}
|
||||
|
||||
export function ScheduleJobDialog({ open, onOpenChange, job, isSaving, onSubmit, showRepoSelector, repoId: selectedRepoId, onRepoChange }: ScheduleJobDialogProps) {
|
||||
@@ -291,384 +273,64 @@ export function ScheduleJobDialog({ open, onOpenChange, job, isSaving, onSubmit,
|
||||
</TabsList>
|
||||
</div>
|
||||
|
||||
<TabsContent value="basics" className="mt-0 min-h-0 flex-1 overflow-y-auto pt-4 pb-5">
|
||||
<div className="space-y-4">
|
||||
{showRepoSelector && !job && (
|
||||
<div className="space-y-2">
|
||||
<Label>Repository</Label>
|
||||
<Combobox
|
||||
value={selectedRepoId?.toString() ?? ''}
|
||||
onChange={(value) => onRepoChange?.(value ? Number(value) : undefined)}
|
||||
options={repoOptions}
|
||||
placeholder="Select a repository"
|
||||
allowCustomValue={false}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-name">Name</Label>
|
||||
<Input id="schedule-name" value={name} onChange={(event) => setName(event.target.value)} placeholder="Nightly repo health check" />
|
||||
</div>
|
||||
<GeneralTab
|
||||
name={name}
|
||||
onNameChange={setName}
|
||||
description={description}
|
||||
onDescriptionChange={setDescription}
|
||||
agentSlug={agentSlug}
|
||||
onAgentSlugChange={setAgentSlug}
|
||||
agentOptions={agentOptions}
|
||||
model={model}
|
||||
onModelChange={setModel}
|
||||
modelOptions={modelOptions}
|
||||
enabled={enabled}
|
||||
onEnabledChange={setEnabled}
|
||||
showRepoSelector={showRepoSelector}
|
||||
isEditing={!!job}
|
||||
repoId={selectedRepoId}
|
||||
onRepoChange={onRepoChange}
|
||||
repoOptions={repoOptions}
|
||||
/>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-description">Description</Label>
|
||||
<Input id="schedule-description" value={description} onChange={(event) => setDescription(event.target.value)} placeholder="What this job checks or produces" />
|
||||
</div>
|
||||
</div>
|
||||
<TimingTab
|
||||
schedulePreset={schedulePreset}
|
||||
onSchedulePresetChange={setSchedulePreset}
|
||||
intervalMinutes={intervalMinutes}
|
||||
onIntervalMinutesChange={setIntervalMinutes}
|
||||
timeOfDay={timeOfDay}
|
||||
onTimeOfDayChange={setTimeOfDay}
|
||||
hourlyMinute={hourlyMinute}
|
||||
onHourlyMinuteChange={setHourlyMinute}
|
||||
weeklyDays={weeklyDays}
|
||||
onWeeklyDaysChange={setWeeklyDays}
|
||||
monthlyDay={monthlyDay}
|
||||
onMonthlyDayChange={setMonthlyDay}
|
||||
cronExpression={cronExpression}
|
||||
onCronExpressionChange={setCronExpression}
|
||||
timezone={timezone}
|
||||
onTimezoneChange={setTimezone}
|
||||
/>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-[minmax(0,1fr)_220px] sm:items-end">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-agent">Agent slug</Label>
|
||||
<Combobox
|
||||
value={agentSlug}
|
||||
onChange={setAgentSlug}
|
||||
options={agentOptions}
|
||||
placeholder="Select an agent"
|
||||
allowCustomValue
|
||||
showClear
|
||||
/>
|
||||
</div>
|
||||
<PromptTab
|
||||
prompt={prompt}
|
||||
onPromptChange={setPrompt}
|
||||
selectedPromptTemplateId={selectedPromptTemplateId}
|
||||
onApplyTemplate={applyPromptTemplate}
|
||||
templates={templates}
|
||||
onEditTemplate={(template) => { setEditingTemplate(template); setTemplateDialogOpen(true) }}
|
||||
onDeleteTemplate={setDeletingTemplateId}
|
||||
onNewTemplate={() => { setEditingTemplate(undefined); setTemplateDialogOpen(true) }}
|
||||
/>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label htmlFor="schedule-model">Model override</Label>
|
||||
<InfoHint text="Pick from detected OpenCode models or type a custom provider/model value." />
|
||||
</div>
|
||||
<Combobox
|
||||
value={model}
|
||||
onChange={setModel}
|
||||
options={modelOptions}
|
||||
placeholder="Workspace default"
|
||||
allowCustomValue
|
||||
showClear
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rounded-lg border border-border bg-card p-4">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<p className="text-sm font-medium">Enabled</p>
|
||||
<InfoHint text="Auto-run this job on its schedule while still allowing manual runs from the dashboard." />
|
||||
</div>
|
||||
<Switch checked={enabled} onCheckedChange={setEnabled} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="timing" className="px-3 mt-0 min-h-0 flex-1 overflow-y-auto sm:px-6 pt-4 pb-5">
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-3 rounded-lg border border-border bg-card p-4">
|
||||
<div>
|
||||
<Label>Repeat</Label>
|
||||
<p className="mt-1 text-xs text-muted-foreground">Use a simple scheduler builder by default. Advanced cron is still available if you need it.</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{schedulePresetOptions.map((option) => (
|
||||
<Button
|
||||
key={option.value}
|
||||
type="button"
|
||||
variant={schedulePreset === option.value ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
onClick={() => setSchedulePreset(option.value)}
|
||||
>
|
||||
{option.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{schedulePreset === 'interval' ? (
|
||||
<div className="space-y-3 rounded-lg border border-border bg-card p-4">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<Label htmlFor="schedule-interval">Run every</Label>
|
||||
<Input
|
||||
id="schedule-interval"
|
||||
type="number"
|
||||
min={5}
|
||||
max={10080}
|
||||
value={intervalMinutes}
|
||||
onChange={(event) => setIntervalMinutes(event.target.value)}
|
||||
className="w-28"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{intervalOptions.map((option) => (
|
||||
<Button key={option.value} type="button" variant={intervalMinutes === String(option.value) ? 'default' : 'outline'} size="sm" onClick={() => setIntervalMinutes(String(option.value))}>
|
||||
{option.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : schedulePreset === 'hourly' ? (
|
||||
<div className="grid gap-4 rounded-lg border border-border bg-card p-4 sm:grid-cols-[120px_minmax(0,1fr)] sm:items-end">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-hourly-minute">Minute</Label>
|
||||
<Input
|
||||
id="schedule-hourly-minute"
|
||||
type="number"
|
||||
min={0}
|
||||
max={59}
|
||||
value={hourlyMinute}
|
||||
onChange={(event) => setHourlyMinute(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">Run every hour at the selected minute mark.</p>
|
||||
</div>
|
||||
) : schedulePreset === 'daily' || schedulePreset === 'weekdays' ? (
|
||||
<div className="grid gap-4 rounded-lg border border-border bg-card p-4 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-time">Time</Label>
|
||||
<Input id="schedule-time" type="time" value={timeOfDay} onChange={(event) => setTimeOfDay(event.target.value)} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-timezone">Timezone</Label>
|
||||
<Input id="schedule-timezone" value={timezone} onChange={(event) => setTimezone(event.target.value)} placeholder="Detected from browser" />
|
||||
</div>
|
||||
</div>
|
||||
) : schedulePreset === 'weekly' ? (
|
||||
<div className="space-y-4 rounded-lg border border-border bg-card p-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Days</Label>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{weekdayOptions.map((option) => {
|
||||
const selected = weeklyDays.includes(option.value)
|
||||
|
||||
return (
|
||||
<Button
|
||||
key={option.value}
|
||||
type="button"
|
||||
variant={selected ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
onClick={() => setWeeklyDays((current) => selected ? current.filter((value) => value !== option.value) : [...current, option.value])}
|
||||
>
|
||||
{option.label}
|
||||
</Button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-weekly-time">Time</Label>
|
||||
<Input id="schedule-weekly-time" type="time" value={timeOfDay} onChange={(event) => setTimeOfDay(event.target.value)} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-weekly-timezone">Timezone</Label>
|
||||
<Input id="schedule-weekly-timezone" value={timezone} onChange={(event) => setTimezone(event.target.value)} placeholder="Detected from browser" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : schedulePreset === 'monthly' ? (
|
||||
<div className="space-y-4 rounded-lg border border-border bg-card p-4">
|
||||
<div className="grid gap-4 sm:grid-cols-3">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-monthly-day">Day</Label>
|
||||
<Input
|
||||
id="schedule-monthly-day"
|
||||
type="number"
|
||||
min={1}
|
||||
max={31}
|
||||
value={monthlyDay}
|
||||
onChange={(event) => setMonthlyDay(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-monthly-time">Time</Label>
|
||||
<Input id="schedule-monthly-time" type="time" value={timeOfDay} onChange={(event) => setTimeOfDay(event.target.value)} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-monthly-timezone">Timezone</Label>
|
||||
<Input id="schedule-monthly-timezone" value={timezone} onChange={(event) => setTimezone(event.target.value)} placeholder="Detected from browser" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4 rounded-lg border border-border bg-card p-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-cron">Cron expression</Label>
|
||||
<Input
|
||||
id="schedule-cron"
|
||||
value={cronExpression}
|
||||
onChange={(event) => setCronExpression(event.target.value)}
|
||||
placeholder="0 9 * * 1-5"
|
||||
className="font-mono"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">Examples: `0 9 * * 1-5` weekdays at 9 AM, `30 6 1 * *` monthly on the 1st at 6:30 AM.</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-timezone">Timezone</Label>
|
||||
<Input
|
||||
id="schedule-timezone"
|
||||
value={timezone}
|
||||
onChange={(event) => setTimezone(event.target.value)}
|
||||
placeholder="Detected from browser"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{cronPresetOptions.map((option) => (
|
||||
<Button key={option.value} type="button" variant="outline" size="sm" onClick={() => setCronExpression(option.value)}>
|
||||
{option.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="rounded-lg border border-border bg-muted/40 p-4">
|
||||
<p className="text-xs font-medium uppercase tracking-wide text-muted-foreground">Schedule Preview</p>
|
||||
<p className="mt-2 text-sm font-medium break-words">{formatDraftScheduleSummary({ preset: schedulePreset, intervalMinutes, timeOfDay, hourlyMinute, weeklyDays, monthlyDay, cronExpression, timezone })}</p>
|
||||
{schedulePreset !== 'interval' && (
|
||||
<p className="mt-2 text-xs text-muted-foreground font-mono break-all">
|
||||
{buildCronExpressionFromPreset({ preset: schedulePreset, intervalMinutes, timeOfDay, hourlyMinute, weeklyDays, monthlyDay, cronExpression })}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="prompt" className="mt-0 min-h-0 flex-1 overflow-y-auto px-3 pt-4 pb-5 sm:px-4">
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
<Label>Prompt templates</Label>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-7 gap-1 text-xs"
|
||||
onClick={() => { setEditingTemplate(undefined); setTemplateDialogOpen(true) }}
|
||||
>
|
||||
<Plus className="h-3 w-3" />
|
||||
New
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-3 lg:grid-cols-2">
|
||||
{templates.map((template) => {
|
||||
const isSelected = selectedPromptTemplateId === template.id
|
||||
|
||||
return (
|
||||
<div key={template.id} className="relative group">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => applyPromptTemplate(template)}
|
||||
className={`w-full rounded-xl border-2 p-4 text-left transition-all ${
|
||||
isSelected
|
||||
? 'border-primary bg-primary/10 ring-2 ring-primary/30'
|
||||
: 'border-border bg-card hover:bg-accent/40'
|
||||
}`}
|
||||
>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Badge className="text-[10px] uppercase tracking-wide border-transparent bg-orange-500 text-white">
|
||||
{template.category}
|
||||
</Badge>
|
||||
<Badge className="text-[10px] uppercase tracking-wide border-transparent bg-slate-600 text-white">
|
||||
{template.cadenceHint}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="mt-3">
|
||||
<p className="text-sm font-semibold">{template.title}</p>
|
||||
<p className="mt-1 text-xs text-muted-foreground">{template.description}</p>
|
||||
</div>
|
||||
<p className="mt-3 text-xs text-muted-foreground line-clamp-3">{template.suggestedDescription}</p>
|
||||
{isSelected && (
|
||||
<div className="absolute top-2 right-2 h-5 w-5 rounded-full bg-primary flex items-center justify-center">
|
||||
<Check className="h-3 w-3 text-primary-foreground" />
|
||||
</div>
|
||||
)}
|
||||
</button>
|
||||
<div className={`absolute top-2 right-10 flex gap-1 transition-opacity ${isSelected ? 'opacity-100' : 'opacity-0 group-hover:opacity-100'}`}>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6"
|
||||
onClick={(e) => { e.stopPropagation(); setEditingTemplate(template); setTemplateDialogOpen(true) }}
|
||||
>
|
||||
<Pencil className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 text-destructive hover:text-destructive"
|
||||
onClick={(e) => { e.stopPropagation(); setDeletingTemplateId(template.id) }}
|
||||
>
|
||||
<Trash2 className="h-3 w-3" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-prompt">Prompt</Label>
|
||||
<Textarea
|
||||
id="schedule-prompt"
|
||||
value={prompt}
|
||||
onChange={(event) => {
|
||||
setPrompt(event.target.value)
|
||||
setSelectedPromptTemplateId(null)
|
||||
}}
|
||||
className="min-h-[320px]"
|
||||
placeholder="Review the repo, summarize notable risks, and open a session I can inspect later."
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
This prompt becomes the first message sent to the agent when the schedule runs.
|
||||
</p>
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="skills" className="mt-0 min-h-0 flex-1 overflow-y-auto px-6 pt-4 pb-5">
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Select skills for this schedule</Label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Skills provide domain-specific instructions to the agent. Select which skills should be available when this schedule runs.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{skillsLoading ? (
|
||||
<div className="flex items-center justify-center py-8">
|
||||
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
) : skills.length === 0 ? (
|
||||
<div className="rounded-lg border border-dashed border-border bg-card/50 p-6 text-center">
|
||||
<Sparkles className="h-6 w-6 mx-auto mb-2 text-muted-foreground" />
|
||||
<p className="text-sm text-muted-foreground">No skills discovered. Configure skill paths in Settings to make skills available here.</p>
|
||||
</div>
|
||||
) : (
|
||||
<MultiSelect
|
||||
value={skillSlugs}
|
||||
onChange={setSkillSlugs}
|
||||
options={skills.map(s => ({ value: s.name, label: s.name, description: s.description }))}
|
||||
placeholder="Search and select skills..."
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-skill-notes">Notes</Label>
|
||||
<Textarea
|
||||
id="schedule-skill-notes"
|
||||
value={skillNotes}
|
||||
onChange={(event) => setSkillNotes(event.target.value)}
|
||||
placeholder="Optional notes about skill usage for this schedule."
|
||||
className="min-h-[80px]"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
<SkillsTab
|
||||
skillSlugs={skillSlugs}
|
||||
onSkillSlugsChange={setSkillSlugs}
|
||||
skillNotes={skillNotes}
|
||||
onSkillNotesChange={setSkillNotes}
|
||||
skills={skills}
|
||||
skillsLoading={skillsLoading}
|
||||
/>
|
||||
</Tabs>
|
||||
|
||||
<div className="mt-0 shrink-0 border-t border-border px-3 sm:px-6 py-4 flex flex-row gap-2 sm:justify-end">
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { TabsContent } from '@/components/ui/tabs'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { MultiSelect } from '@/components/ui/multi-select'
|
||||
import { Loader2, Sparkles } from 'lucide-react'
|
||||
|
||||
type SkillsTabProps = {
|
||||
skillSlugs: string[]
|
||||
onSkillSlugsChange: (value: string[]) => void
|
||||
skillNotes: string
|
||||
onSkillNotesChange: (value: string) => void
|
||||
skills: Array<{ name: string; description: string }>
|
||||
skillsLoading: boolean
|
||||
}
|
||||
|
||||
export function SkillsTab({
|
||||
skillSlugs,
|
||||
onSkillSlugsChange,
|
||||
skillNotes,
|
||||
onSkillNotesChange,
|
||||
skills,
|
||||
skillsLoading,
|
||||
}: SkillsTabProps) {
|
||||
return (
|
||||
<TabsContent value="skills" className="mt-0 min-h-0 flex-1 overflow-y-auto px-6 pt-4 pb-5">
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Select skills for this schedule</Label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Skills provide domain-specific instructions to the agent. Select which skills should be available when this schedule runs.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{skillsLoading ? (
|
||||
<div className="flex items-center justify-center py-8">
|
||||
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
) : skills.length === 0 ? (
|
||||
<div className="rounded-lg border border-dashed border-border bg-card/50 p-6 text-center">
|
||||
<Sparkles className="h-6 w-6 mx-auto mb-2 text-muted-foreground" />
|
||||
<p className="text-sm text-muted-foreground">No skills discovered. Configure skill paths in Settings to make skills available here.</p>
|
||||
</div>
|
||||
) : (
|
||||
<MultiSelect
|
||||
value={skillSlugs}
|
||||
onChange={onSkillSlugsChange}
|
||||
options={skills.map(s => ({ value: s.name, label: s.name, description: s.description }))}
|
||||
placeholder="Search and select skills..."
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-skill-notes">Notes</Label>
|
||||
<Textarea
|
||||
id="schedule-skill-notes"
|
||||
value={skillNotes}
|
||||
onChange={(event) => onSkillNotesChange(event.target.value)}
|
||||
placeholder="Optional notes about skill usage for this schedule."
|
||||
className="min-h-[80px]"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { TabsContent } from '@/components/ui/tabs'
|
||||
import {
|
||||
buildCronExpressionFromPreset,
|
||||
cronPresetOptions,
|
||||
intervalOptions,
|
||||
schedulePresetOptions,
|
||||
weekdayOptions,
|
||||
type SchedulePreset,
|
||||
} from '@/components/schedules/schedule-utils'
|
||||
import { formatDraftScheduleSummary, getLocalTimeZone } from '@/components/schedules/schedule-utils'
|
||||
|
||||
type TimingTabProps = {
|
||||
schedulePreset: SchedulePreset
|
||||
onSchedulePresetChange: (value: SchedulePreset) => void
|
||||
intervalMinutes: string
|
||||
onIntervalMinutesChange: (value: string) => void
|
||||
timeOfDay: string
|
||||
onTimeOfDayChange: (value: string) => void
|
||||
hourlyMinute: string
|
||||
onHourlyMinuteChange: (value: string) => void
|
||||
weeklyDays: string[]
|
||||
onWeeklyDaysChange: (value: string[]) => void
|
||||
monthlyDay: string
|
||||
onMonthlyDayChange: (value: string) => void
|
||||
cronExpression: string
|
||||
onCronExpressionChange: (value: string) => void
|
||||
timezone: string
|
||||
onTimezoneChange: (value: string) => void
|
||||
}
|
||||
|
||||
export function TimingTab({
|
||||
schedulePreset,
|
||||
onSchedulePresetChange,
|
||||
intervalMinutes,
|
||||
onIntervalMinutesChange,
|
||||
timeOfDay,
|
||||
onTimeOfDayChange,
|
||||
hourlyMinute,
|
||||
onHourlyMinuteChange,
|
||||
weeklyDays,
|
||||
onWeeklyDaysChange,
|
||||
monthlyDay,
|
||||
onMonthlyDayChange,
|
||||
cronExpression,
|
||||
onCronExpressionChange,
|
||||
timezone,
|
||||
onTimezoneChange,
|
||||
}: TimingTabProps) {
|
||||
return (
|
||||
<TabsContent value="timing" className="px-3 mt-0 min-h-0 flex-1 overflow-y-auto sm:px-6 pt-4 pb-5">
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-3 rounded-lg border border-border bg-card p-4">
|
||||
<div>
|
||||
<Label>Repeat</Label>
|
||||
<p className="mt-1 text-xs text-muted-foreground">Use a simple scheduler builder by default. Advanced cron is still available if you need it.</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{schedulePresetOptions.map((option) => (
|
||||
<Button
|
||||
key={option.value}
|
||||
type="button"
|
||||
variant={schedulePreset === option.value ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
onClick={() => onSchedulePresetChange(option.value)}
|
||||
>
|
||||
{option.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{schedulePreset === 'interval' ? (
|
||||
<div className="space-y-3 rounded-lg border border-border bg-card p-4">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<Label htmlFor="schedule-interval">Run every</Label>
|
||||
<Input
|
||||
id="schedule-interval"
|
||||
type="number"
|
||||
min={5}
|
||||
max={10080}
|
||||
value={intervalMinutes}
|
||||
onChange={(event) => onIntervalMinutesChange(event.target.value)}
|
||||
className="w-28"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{intervalOptions.map((option) => (
|
||||
<Button key={option.value} type="button" variant={intervalMinutes === String(option.value) ? 'default' : 'outline'} size="sm" onClick={() => onIntervalMinutesChange(String(option.value))}>
|
||||
{option.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : schedulePreset === 'hourly' ? (
|
||||
<div className="grid gap-4 rounded-lg border border-border bg-card p-4 sm:grid-cols-[120px_minmax(0,1fr)] sm:items-end">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-hourly-minute">Minute</Label>
|
||||
<Input
|
||||
id="schedule-hourly-minute"
|
||||
type="number"
|
||||
min={0}
|
||||
max={59}
|
||||
value={hourlyMinute}
|
||||
onChange={(event) => onHourlyMinuteChange(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">Run every hour at the selected minute mark.</p>
|
||||
</div>
|
||||
) : schedulePreset === 'daily' || schedulePreset === 'weekdays' ? (
|
||||
<div className="grid gap-4 rounded-lg border border-border bg-card p-4 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-time">Time</Label>
|
||||
<Input id="schedule-time" type="time" value={timeOfDay} onChange={(event) => onTimeOfDayChange(event.target.value)} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-timezone">Timezone</Label>
|
||||
<Input id="schedule-timezone" value={timezone} onChange={(event) => onTimezoneChange(event.target.value)} placeholder={getLocalTimeZone()} />
|
||||
</div>
|
||||
</div>
|
||||
) : schedulePreset === 'weekly' ? (
|
||||
<div className="space-y-4 rounded-lg border border-border bg-card p-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Days</Label>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{weekdayOptions.map((option) => {
|
||||
const selected = weeklyDays.includes(option.value)
|
||||
|
||||
return (
|
||||
<Button
|
||||
key={option.value}
|
||||
type="button"
|
||||
variant={selected ? 'default' : 'outline'}
|
||||
size="sm"
|
||||
onClick={() => onWeeklyDaysChange(selected ? weeklyDays.filter((value) => value !== option.value) : [...weeklyDays, option.value])}
|
||||
>
|
||||
{option.label}
|
||||
</Button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-weekly-time">Time</Label>
|
||||
<Input id="schedule-weekly-time" type="time" value={timeOfDay} onChange={(event) => onTimeOfDayChange(event.target.value)} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-weekly-timezone">Timezone</Label>
|
||||
<Input id="schedule-weekly-timezone" value={timezone} onChange={(event) => onTimezoneChange(event.target.value)} placeholder={getLocalTimeZone()} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : schedulePreset === 'monthly' ? (
|
||||
<div className="space-y-4 rounded-lg border border-border bg-card p-4">
|
||||
<div className="grid gap-4 sm:grid-cols-3">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-monthly-day">Day</Label>
|
||||
<Input
|
||||
id="schedule-monthly-day"
|
||||
type="number"
|
||||
min={1}
|
||||
max={31}
|
||||
value={monthlyDay}
|
||||
onChange={(event) => onMonthlyDayChange(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-monthly-time">Time</Label>
|
||||
<Input id="schedule-monthly-time" type="time" value={timeOfDay} onChange={(event) => onTimeOfDayChange(event.target.value)} />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-monthly-timezone">Timezone</Label>
|
||||
<Input id="schedule-monthly-timezone" value={timezone} onChange={(event) => onTimezoneChange(event.target.value)} placeholder={getLocalTimeZone()} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4 rounded-lg border border-border bg-card p-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-cron">Cron expression</Label>
|
||||
<Input
|
||||
id="schedule-cron"
|
||||
value={cronExpression}
|
||||
onChange={(event) => onCronExpressionChange(event.target.value)}
|
||||
placeholder="0 9 * * 1-5"
|
||||
className="font-mono"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">Examples: `0 9 * * 1-5` weekdays at 9 AM, `30 6 1 * *` monthly on the 1st at 6:30 AM.</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="schedule-timezone">Timezone</Label>
|
||||
<Input
|
||||
id="schedule-timezone"
|
||||
value={timezone}
|
||||
onChange={(event) => onTimezoneChange(event.target.value)}
|
||||
placeholder={getLocalTimeZone()}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{cronPresetOptions.map((option) => (
|
||||
<Button key={option.value} type="button" variant="outline" size="sm" onClick={() => onCronExpressionChange(option.value)}>
|
||||
{option.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="rounded-lg border border-border bg-muted/40 p-4">
|
||||
<p className="text-xs font-medium uppercase tracking-wide text-muted-foreground">Schedule Preview</p>
|
||||
<p className="mt-2 text-sm font-medium break-words">{formatDraftScheduleSummary({ preset: schedulePreset, intervalMinutes, timeOfDay, hourlyMinute, weeklyDays, monthlyDay, cronExpression, timezone })}</p>
|
||||
{schedulePreset !== 'interval' && (
|
||||
<p className="mt-2 text-xs text-muted-foreground font-mono break-all">
|
||||
{buildCronExpressionFromPreset({ preset: schedulePreset, intervalMinutes, timeOfDay, hourlyMinute, weeklyDays, monthlyDay, cronExpression })}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user