Open History to see the last commit
1import * as Schema from "effect/Schema";
2
3import {
4 CommandId,
5 IsoDateTime,
6 PositiveInt,
7 ProjectId,
8 ScheduledTaskId,
9 ThreadId,
10 TrimmedNonEmptyString,
11} from "./baseSchemas.ts";
12import { ModelSelection } from "./modelSelection.ts";
13import {
14 OrchestrationV2Actor,
15 OrchestrationV2CreationSource,
16 OrchestrationV2ThreadLaunchWorkspaceStrategy,
17} from "./orchestrationV2.ts";
18import { ProviderInteractionMode, RuntimeMode } from "./providerPolicy.ts";
19
20/** 24-hour "HH:MM" wall-clock time. Mirrors `parseTimeOfDay` on the server. */
21const TimeOfDay = TrimmedNonEmptyString.check(Schema.isPattern(/^([01]?\d|2[0-3]):([0-5]\d)$/));
22
23export const ScheduledTaskSchedule = Schema.Union([
24 Schema.Struct({
25 type: Schema.Literal("interval"),
26 everyMs: PositiveInt,
27 }),
28 Schema.Struct({
29 type: Schema.Literal("fixed_time"),
30 timeOfDay: TimeOfDay,
31 weekdays: Schema.optional(
32 Schema.Array(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 6 }))),
33 ),
34 }),
35]);
36export type ScheduledTaskSchedule = typeof ScheduledTaskSchedule.Type;
37
38export const ScheduledTaskRunStatus = Schema.Literals(["never", "running", "succeeded", "failed"]);
39export type ScheduledTaskRunStatus = typeof ScheduledTaskRunStatus.Type;
40
41export const ScheduledTask = Schema.Struct({
42 id: ScheduledTaskId,
43 title: TrimmedNonEmptyString,
44 prompt: TrimmedNonEmptyString,
45 enabled: Schema.Boolean,
46 schedule: ScheduledTaskSchedule,
47 projectId: ProjectId,
48 threadId: Schema.NullOr(ThreadId),
49 workspaceStrategy: OrchestrationV2ThreadLaunchWorkspaceStrategy,
50 modelSelection: ModelSelection,
51 runtimeMode: RuntimeMode,
52 interactionMode: ProviderInteractionMode,
53 createdBy: OrchestrationV2Actor,
54 creationSource: OrchestrationV2CreationSource,
55 createdAt: IsoDateTime,
56 updatedAt: IsoDateTime,
57 nextRunAt: Schema.NullOr(IsoDateTime),
58 lastRunAt: Schema.NullOr(IsoDateTime),
59 lastRunStatus: ScheduledTaskRunStatus,
60 lastRunError: Schema.NullOr(Schema.String),
61 runCount: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
62});
63export type ScheduledTask = typeof ScheduledTask.Type;
64
65export const ScheduledTaskListInput = Schema.Struct({});
66export type ScheduledTaskListInput = typeof ScheduledTaskListInput.Type;
67
68export const ScheduledTaskListResult = Schema.Struct({
69 tasks: Schema.Array(ScheduledTask),
70});
71export type ScheduledTaskListResult = typeof ScheduledTaskListResult.Type;
72
73export const ScheduledTaskUpsertInput = Schema.Struct({
74 id: Schema.optional(ScheduledTaskId),
75 commandId: Schema.optional(CommandId),
76 title: TrimmedNonEmptyString,
77 prompt: TrimmedNonEmptyString,
78 enabled: Schema.Boolean,
79 schedule: ScheduledTaskSchedule,
80 projectId: ProjectId,
81 threadId: Schema.optional(Schema.NullOr(ThreadId)),
82 workspaceStrategy: OrchestrationV2ThreadLaunchWorkspaceStrategy,
83 modelSelection: ModelSelection,
84 runtimeMode: RuntimeMode,
85 interactionMode: ProviderInteractionMode,
86 createdBy: Schema.optional(OrchestrationV2Actor),
87 creationSource: Schema.optional(OrchestrationV2CreationSource),
88});
89export type ScheduledTaskUpsertInput = typeof ScheduledTaskUpsertInput.Type;
90
91/** Partial update that flips only the enabled flag — never overwrites other fields. */
92export const ScheduledTaskSetEnabledInput = Schema.Struct({
93 id: ScheduledTaskId,
94 enabled: Schema.Boolean,
95});
96export type ScheduledTaskSetEnabledInput = typeof ScheduledTaskSetEnabledInput.Type;
97
98export const ScheduledTaskDeleteInput = Schema.Struct({
99 id: ScheduledTaskId,
100});
101export type ScheduledTaskDeleteInput = typeof ScheduledTaskDeleteInput.Type;
102
103export const ScheduledTaskRunNowInput = Schema.Struct({
104 id: ScheduledTaskId,
105});
106export type ScheduledTaskRunNowInput = typeof ScheduledTaskRunNowInput.Type;
107
108export const ScheduledTaskMutationResult = Schema.Struct({
109 task: ScheduledTask,
110});
111export type ScheduledTaskMutationResult = typeof ScheduledTaskMutationResult.Type;
112
113export const ScheduledTaskDeleteResult = Schema.Struct({
114 id: ScheduledTaskId,
115});
116export type ScheduledTaskDeleteResult = typeof ScheduledTaskDeleteResult.Type;
117
118export const ScheduledTaskRunNowResult = Schema.Struct({
119 task: ScheduledTask,
120});
121export type ScheduledTaskRunNowResult = typeof ScheduledTaskRunNowResult.Type;
122
123export class ScheduledTaskError extends Schema.TaggedErrorClass<ScheduledTaskError>()(
124 "ScheduledTaskError",
125 {
126 message: Schema.String,
127 taskId: Schema.optional(ScheduledTaskId),
128 cause: Schema.optional(Schema.Defect()),
129 },
130) {}