@opencode/schema 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/automation.d.ts +383 -0
- package/dist/automation.js +150 -0
- package/dist/blob-store.d.ts +16 -0
- package/dist/blob-store.js +15 -0
- package/dist/config/compaction.d.ts +1 -0
- package/dist/config/compaction.js +3 -0
- package/dist/config/experimental.d.ts +4 -3
- package/dist/config/experimental.js +8 -3
- package/dist/config/flag.d.ts +11 -7
- package/dist/config/flag.js +11 -7
- package/dist/generate.d.ts +134 -0
- package/dist/generate.js +57 -1
- package/dist/job.d.ts +28 -1
- package/dist/job.js +5 -2
- package/dist/model.d.ts +1 -1
- package/dist/model.js +1 -1
- package/package.json +1 -1
- package/dist/schedule.d.ts +0 -462
- package/dist/schedule.js +0 -206
package/dist/schedule.js
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
export * as Schedule from "./schedule.js";
|
|
2
|
-
import { Duration, Option, Schema } from "effect";
|
|
3
|
-
import { ascending } from "./identifier.js";
|
|
4
|
-
import { DateTimeUtcFromMillis, NonNegativeInt, PositiveInt, optional, statics } from "./schema.js";
|
|
5
|
-
import { SessionID } from "./session-id.js";
|
|
6
|
-
export const ID = Schema.String.check(Schema.isStartingWith("sch_")).pipe(Schema.brand("Schedule.ID"), Schema.annotate({ identifier: "Schedule.ID" }), statics((schema) => ({
|
|
7
|
-
create: () => schema.make("sch_" + ascending()),
|
|
8
|
-
})));
|
|
9
|
-
const decodeDuration = Schema.decodeUnknownOption(Schema.DurationFromString);
|
|
10
|
-
/** Milliseconds in a duration string, or `None` when it is not one. */
|
|
11
|
-
export const durationMillis = (value) => decodeDuration(value).pipe(Option.map(Duration.toMillis));
|
|
12
|
-
/** A duration such as "90 seconds", "5 minutes" or "2 hours". The service validates it, since clients cannot run a custom check. */
|
|
13
|
-
export const DurationString = Schema.String.annotate({
|
|
14
|
-
identifier: "Schedule.Duration",
|
|
15
|
-
description: 'A duration such as "90 seconds", "5 minutes" or "2 hours".',
|
|
16
|
-
});
|
|
17
|
-
const zone = {
|
|
18
|
-
tz: Schema.String.pipe(optional).annotate({
|
|
19
|
-
description: "IANA time zone. Defaults to the configured timezone, then the server's local zone.",
|
|
20
|
-
}),
|
|
21
|
-
};
|
|
22
|
-
export const In = Schema.Struct({ type: Schema.tag("in"), in: DurationString, ...zone }).annotate({
|
|
23
|
-
identifier: "Schedule.When.In",
|
|
24
|
-
});
|
|
25
|
-
/** An instant with an offset, or a wall-clock time in `tz`, e.g. "2026-10-27T09:00". */
|
|
26
|
-
export const At = Schema.Struct({ type: Schema.tag("at"), at: Schema.String, ...zone }).annotate({
|
|
27
|
-
identifier: "Schedule.When.At",
|
|
28
|
-
});
|
|
29
|
-
export const Every = Schema.Struct({ type: Schema.tag("every"), every: DurationString, ...zone }).annotate({
|
|
30
|
-
identifier: "Schedule.When.Every",
|
|
31
|
-
});
|
|
32
|
-
export const Cron = Schema.Struct({ type: Schema.tag("cron"), cron: Schema.String, ...zone }).annotate({
|
|
33
|
-
identifier: "Schedule.When.Cron",
|
|
34
|
-
});
|
|
35
|
-
export const When = Schema.Union([In, At, Every, Cron]).pipe(Schema.toTaggedUnion("type"), Schema.annotate({ identifier: "Schedule.When" }));
|
|
36
|
-
/** Stops a repeating schedule at whichever limit comes first. */
|
|
37
|
-
export const Ends = Schema.Struct({
|
|
38
|
-
after: DurationString.pipe(optional),
|
|
39
|
-
at: Schema.String.pipe(optional),
|
|
40
|
-
times: PositiveInt.pipe(optional),
|
|
41
|
-
}).annotate({ identifier: "Schedule.Ends" });
|
|
42
|
-
export const PromptAction = Schema.Struct({ type: Schema.tag("prompt"), prompt: Schema.String }).annotate({
|
|
43
|
-
identifier: "Schedule.Action.Prompt",
|
|
44
|
-
});
|
|
45
|
-
export const Action = Schema.Union([PromptAction]).pipe(Schema.toTaggedUnion("type"), Schema.annotate({ identifier: "Schedule.Action" }));
|
|
46
|
-
/**
|
|
47
|
-
* Runs `run` in the Session's directory before firing, with no model call. With none of `is`, `matches` or `changes`
|
|
48
|
-
* set, exit 0 wakes and any non-zero exit is "not yet". With `is`, `matches` or `changes`, non-zero exit is a check
|
|
49
|
-
* error, and exit 0 wakes when trimmed stdout equals `is`, stdout matches `matches`, or stdout differs from the
|
|
50
|
-
* previous run (`changes`).
|
|
51
|
-
*/
|
|
52
|
-
export const ShellCondition = Schema.Struct({
|
|
53
|
-
type: Schema.tag("shell"),
|
|
54
|
-
run: Schema.String,
|
|
55
|
-
is: Schema.String.pipe(optional),
|
|
56
|
-
matches: Schema.String.pipe(optional),
|
|
57
|
-
changes: Schema.Boolean.pipe(optional),
|
|
58
|
-
}).annotate({ identifier: "Schedule.Condition.Shell" });
|
|
59
|
-
/**
|
|
60
|
-
* Runs `code` in a confined Code Mode runtime before firing, with no model call and no `fetch`. Tools called statically
|
|
61
|
-
* as `tools.<path>(...)` are extracted from the AST and authorized at creation; the program receives `state` (initially
|
|
62
|
-
* `null`), `now` (epoch ms) and `runs` (completed checks), and returns a boolean or `{ wake, state?, message? }`.
|
|
63
|
-
*/
|
|
64
|
-
export const CodeCondition = Schema.Struct({
|
|
65
|
-
type: Schema.tag("code"),
|
|
66
|
-
code: Schema.String,
|
|
67
|
-
}).annotate({ identifier: "Schedule.Condition.Code" });
|
|
68
|
-
/** Checked before firing; the schedule wakes the Session only when the condition passes. */
|
|
69
|
-
export const Condition = Schema.Union([ShellCondition, CodeCondition]).pipe(Schema.toTaggedUnion("type"), Schema.annotate({ identifier: "Schedule.Condition" }));
|
|
70
|
-
export const CheckMode = Schema.Literals(["if", "until"]).annotate({ identifier: "Schedule.CheckMode" });
|
|
71
|
-
export const StoredCheck = Schema.Struct({
|
|
72
|
-
mode: CheckMode,
|
|
73
|
-
condition: Condition,
|
|
74
|
-
}).annotate({ identifier: "Schedule.StoredCheck" });
|
|
75
|
-
export const Status = Schema.Literals(["active", "paused", "done"]).annotate({ identifier: "Schedule.Status" });
|
|
76
|
-
export const Outcome = Schema.Literals([
|
|
77
|
-
"fired",
|
|
78
|
-
"late",
|
|
79
|
-
"checked",
|
|
80
|
-
"expired",
|
|
81
|
-
"skipped",
|
|
82
|
-
"disabled",
|
|
83
|
-
"failed",
|
|
84
|
-
]).annotate({
|
|
85
|
-
identifier: "Schedule.Outcome",
|
|
86
|
-
});
|
|
87
|
-
export const Info = Schema.Struct({
|
|
88
|
-
id: ID,
|
|
89
|
-
sessionID: SessionID.pipe(optional),
|
|
90
|
-
name: Schema.String.pipe(optional),
|
|
91
|
-
when: When,
|
|
92
|
-
tz: Schema.String,
|
|
93
|
-
if: Condition.pipe(optional),
|
|
94
|
-
until: Condition.pipe(optional),
|
|
95
|
-
action: Action,
|
|
96
|
-
status: Status,
|
|
97
|
-
nextDueAt: DateTimeUtcFromMillis.pipe(optional),
|
|
98
|
-
endsAt: DateTimeUtcFromMillis.pipe(optional),
|
|
99
|
-
remainingRuns: NonNegativeInt.pipe(optional),
|
|
100
|
-
runCount: NonNegativeInt,
|
|
101
|
-
lastFiredAt: DateTimeUtcFromMillis.pipe(optional),
|
|
102
|
-
lastOutcome: Outcome.pipe(optional),
|
|
103
|
-
lastOutput: Schema.String.pipe(optional),
|
|
104
|
-
time: Schema.Struct({ created: DateTimeUtcFromMillis, updated: DateTimeUtcFromMillis }),
|
|
105
|
-
}).annotate({ identifier: "Schedule.Info" });
|
|
106
|
-
export const CreateInput = Schema.Struct({
|
|
107
|
-
sessionID: SessionID,
|
|
108
|
-
name: Schema.String.pipe(optional),
|
|
109
|
-
when: When.pipe(optional),
|
|
110
|
-
if: Condition.pipe(optional),
|
|
111
|
-
until: Condition.pipe(optional),
|
|
112
|
-
ends: Ends.pipe(optional),
|
|
113
|
-
action: Action,
|
|
114
|
-
}).annotate({ identifier: "Schedule.CreateInput" });
|
|
115
|
-
/** Declares a variant field absent, so `{ in, every }` or `{ run, code }` fails instead of silently dropping one. */
|
|
116
|
-
const absent = Schema.optionalKey(Schema.Never);
|
|
117
|
-
/** The `when` callers write: exactly one of `in`, `at`, `every` or `cron`, with an optional `tz`. */
|
|
118
|
-
export const WhenInput = Schema.Union([
|
|
119
|
-
Schema.Struct({ in: In.fields.in, at: absent, every: absent, cron: absent, ...zone }),
|
|
120
|
-
Schema.Struct({ at: At.fields.at, in: absent, every: absent, cron: absent, ...zone }),
|
|
121
|
-
Schema.Struct({ every: Every.fields.every, in: absent, at: absent, cron: absent, ...zone }),
|
|
122
|
-
Schema.Struct({ cron: Cron.fields.cron, in: absent, at: absent, every: absent, ...zone }),
|
|
123
|
-
]).annotate({ identifier: "Schedule.WhenInput" });
|
|
124
|
-
export const ShellConditionInput = Schema.Struct({
|
|
125
|
-
run: Schema.String.check(Schema.isMinLength(1)).annotate({
|
|
126
|
-
description: "Shell command to run in the Session's directory. Alone, exit 0 wakes and stdout is appended.",
|
|
127
|
-
}),
|
|
128
|
-
is: Schema.String.pipe(optional).annotate({
|
|
129
|
-
description: "Wake when exit is 0 and trimmed stdout equals this value.",
|
|
130
|
-
}),
|
|
131
|
-
matches: Schema.String.pipe(optional).annotate({
|
|
132
|
-
description: "Wake when exit is 0 and stdout matches this regular expression.",
|
|
133
|
-
}),
|
|
134
|
-
changes: Schema.Boolean.pipe(optional).annotate({
|
|
135
|
-
description: "Wake when exit is 0 and stdout differs from the previous check.",
|
|
136
|
-
}),
|
|
137
|
-
}).annotate({ identifier: "Schedule.ShellConditionInput" });
|
|
138
|
-
export const CodeConditionInput = Schema.Struct({
|
|
139
|
-
code: Schema.String.check(Schema.isMinLength(1)).annotate({
|
|
140
|
-
description: [
|
|
141
|
-
"Code Mode JavaScript check (no fetch; 30s, 20 tool calls, 32 KB output cap).",
|
|
142
|
-
'Call tools statically as tools.<ns>.<tool>(...) or tools["ns-name"].tool(...); each is authorized once at creation to run unattended.',
|
|
143
|
-
"Runs once at creation with state = null (if baselines state without waking; until matches immediately if true), with globals state, now (epoch ms) and runs.",
|
|
144
|
-
"Return a boolean or { wake, state?, message? } (message is appended to prompt on wake), e.g.:",
|
|
145
|
-
'const t = await tools.slack.read_thread({ id }); return { wake: state !== null && t.count > state.count, state: { count: t.count }, message: "New reply" }',
|
|
146
|
-
].join(" "),
|
|
147
|
-
}),
|
|
148
|
-
}).annotate({ identifier: "Schedule.CodeConditionInput" });
|
|
149
|
-
export const ConditionInput = Schema.Union([
|
|
150
|
-
Schema.Struct({ ...ShellConditionInput.fields, code: absent }),
|
|
151
|
-
Schema.Struct({
|
|
152
|
-
...CodeConditionInput.fields,
|
|
153
|
-
run: absent,
|
|
154
|
-
is: absent,
|
|
155
|
-
matches: absent,
|
|
156
|
-
changes: absent,
|
|
157
|
-
}),
|
|
158
|
-
]).annotate({ identifier: "Schedule.ConditionInput" });
|
|
159
|
-
/** A schedule as callers describe it: when it fires, optional condition, when it stops, and the prompt it sends. */
|
|
160
|
-
export const Request = Schema.Struct({
|
|
161
|
-
name: Schema.String.pipe(optional).annotate({ description: "A short label for the schedule." }),
|
|
162
|
-
when: WhenInput.pipe(optional).annotate({
|
|
163
|
-
description: 'When it fires: { in: "20 minutes" }, { at: "2026-10-27T09:00" }, { every: "1 hour" } or { cron: "0 9 * * 1-5" }. Optional with `until` (defaults to { every: "30 seconds" }).',
|
|
164
|
-
}),
|
|
165
|
-
if: ConditionInput.pipe(optional).annotate({
|
|
166
|
-
description: "Recurring gate ({ run } shell command or { code } Code Mode script): check on each slot with no model call, and wake on every slot where it passes.",
|
|
167
|
-
}),
|
|
168
|
-
until: ConditionInput.pipe(optional).annotate({
|
|
169
|
-
description: 'One-shot gate ({ run } shell command or { code } Code Mode script): poll with no model call, wake once when it passes, and stop. Defaults ends.after to "24 hours".',
|
|
170
|
-
}),
|
|
171
|
-
ends: Ends.pipe(optional).annotate({
|
|
172
|
-
description: 'Stops a repeating schedule at the first limit reached: { after: "8 hours" }, { at }, { times: 3 }.',
|
|
173
|
-
}),
|
|
174
|
-
prompt: Schema.String.check(Schema.isMinLength(1)).annotate({
|
|
175
|
-
description: "The message the Session receives when the schedule wakes.",
|
|
176
|
-
}),
|
|
177
|
-
}).annotate({ identifier: "Schedule.Request" });
|
|
178
|
-
export const toCreateInput = (sessionID, request) => ({
|
|
179
|
-
sessionID,
|
|
180
|
-
name: request.name,
|
|
181
|
-
when: request.when === undefined ? undefined : toWhen(request.when),
|
|
182
|
-
if: request.if === undefined ? undefined : toCondition(request.if),
|
|
183
|
-
until: request.until === undefined ? undefined : toCondition(request.until),
|
|
184
|
-
ends: request.ends,
|
|
185
|
-
action: { type: "prompt", prompt: request.prompt },
|
|
186
|
-
});
|
|
187
|
-
const toCondition = (condition) => {
|
|
188
|
-
if (condition.code !== undefined)
|
|
189
|
-
return { type: "code", code: condition.code };
|
|
190
|
-
return {
|
|
191
|
-
type: "shell",
|
|
192
|
-
run: condition.run,
|
|
193
|
-
is: condition.is,
|
|
194
|
-
matches: condition.matches,
|
|
195
|
-
changes: condition.changes,
|
|
196
|
-
};
|
|
197
|
-
};
|
|
198
|
-
const toWhen = (when) => {
|
|
199
|
-
if (when.in !== undefined)
|
|
200
|
-
return { type: "in", in: when.in, tz: when.tz };
|
|
201
|
-
if (when.at !== undefined)
|
|
202
|
-
return { type: "at", at: when.at, tz: when.tz };
|
|
203
|
-
if (when.every !== undefined)
|
|
204
|
-
return { type: "every", every: when.every, tz: when.tz };
|
|
205
|
-
return { type: "cron", cron: when.cron, tz: when.tz };
|
|
206
|
-
};
|