@opencode/schema 0.0.0-dev-210 → 0.0.0-dev-216
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/schedule.d.ts +70 -1
- package/dist/schedule.js +43 -5
- package/package.json +1 -1
package/dist/schedule.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export * as Schedule from "./schedule.js";
|
|
2
2
|
import { Option, Schema } from "effect";
|
|
3
|
+
import { SessionID } from "./session-id.js";
|
|
3
4
|
export declare const ID: Schema.brand<Schema.String, "Schedule.ID"> & {
|
|
4
5
|
create: () => string & import("effect/Brand").Brand<"Schedule.ID">;
|
|
5
6
|
};
|
|
6
7
|
export type ID = typeof ID.Type;
|
|
7
8
|
/** Milliseconds in a duration string, or `None` when it is not one. */
|
|
8
9
|
export declare const durationMillis: (value: string) => Option.Option<number>;
|
|
9
|
-
/** A duration such as "90 seconds", "5 minutes" or "2 hours". */
|
|
10
|
+
/** A duration such as "90 seconds", "5 minutes" or "2 hours". The service validates it, since clients cannot run a custom check. */
|
|
10
11
|
export declare const DurationString: Schema.String;
|
|
11
12
|
export declare const In: Schema.Struct<{
|
|
12
13
|
readonly tz: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
@@ -149,3 +150,71 @@ export declare const CreateInput: Schema.Struct<{
|
|
|
149
150
|
}>]>;
|
|
150
151
|
}>;
|
|
151
152
|
export type CreateInput = typeof CreateInput.Type;
|
|
153
|
+
/** The `when` callers write: exactly one of `in`, `at`, `every` or `cron`, with an optional `tz`. */
|
|
154
|
+
export declare const WhenInput: Schema.Union<readonly [Schema.Struct<{
|
|
155
|
+
readonly tz: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
156
|
+
readonly in: Schema.String;
|
|
157
|
+
readonly at: Schema.optionalKey<Schema.Never>;
|
|
158
|
+
readonly every: Schema.optionalKey<Schema.Never>;
|
|
159
|
+
readonly cron: Schema.optionalKey<Schema.Never>;
|
|
160
|
+
}>, Schema.Struct<{
|
|
161
|
+
readonly tz: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
162
|
+
readonly at: Schema.String;
|
|
163
|
+
readonly in: Schema.optionalKey<Schema.Never>;
|
|
164
|
+
readonly every: Schema.optionalKey<Schema.Never>;
|
|
165
|
+
readonly cron: Schema.optionalKey<Schema.Never>;
|
|
166
|
+
}>, Schema.Struct<{
|
|
167
|
+
readonly tz: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
168
|
+
readonly every: Schema.String;
|
|
169
|
+
readonly in: Schema.optionalKey<Schema.Never>;
|
|
170
|
+
readonly at: Schema.optionalKey<Schema.Never>;
|
|
171
|
+
readonly cron: Schema.optionalKey<Schema.Never>;
|
|
172
|
+
}>, Schema.Struct<{
|
|
173
|
+
readonly tz: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
174
|
+
readonly cron: Schema.String;
|
|
175
|
+
readonly in: Schema.optionalKey<Schema.Never>;
|
|
176
|
+
readonly at: Schema.optionalKey<Schema.Never>;
|
|
177
|
+
readonly every: Schema.optionalKey<Schema.Never>;
|
|
178
|
+
}>]>;
|
|
179
|
+
export type WhenInput = typeof WhenInput.Type;
|
|
180
|
+
/** A schedule as callers describe it: when it fires, when it stops, and the prompt it wakes the Session with. */
|
|
181
|
+
export declare const Request: Schema.Struct<{
|
|
182
|
+
readonly name: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
183
|
+
readonly when: Schema.Union<readonly [Schema.Struct<{
|
|
184
|
+
readonly tz: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
185
|
+
readonly in: Schema.String;
|
|
186
|
+
readonly at: Schema.optionalKey<Schema.Never>;
|
|
187
|
+
readonly every: Schema.optionalKey<Schema.Never>;
|
|
188
|
+
readonly cron: Schema.optionalKey<Schema.Never>;
|
|
189
|
+
}>, Schema.Struct<{
|
|
190
|
+
readonly tz: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
191
|
+
readonly at: Schema.String;
|
|
192
|
+
readonly in: Schema.optionalKey<Schema.Never>;
|
|
193
|
+
readonly every: Schema.optionalKey<Schema.Never>;
|
|
194
|
+
readonly cron: Schema.optionalKey<Schema.Never>;
|
|
195
|
+
}>, Schema.Struct<{
|
|
196
|
+
readonly tz: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
197
|
+
readonly every: Schema.String;
|
|
198
|
+
readonly in: Schema.optionalKey<Schema.Never>;
|
|
199
|
+
readonly at: Schema.optionalKey<Schema.Never>;
|
|
200
|
+
readonly cron: Schema.optionalKey<Schema.Never>;
|
|
201
|
+
}>, Schema.Struct<{
|
|
202
|
+
readonly tz: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
203
|
+
readonly cron: Schema.String;
|
|
204
|
+
readonly in: Schema.optionalKey<Schema.Never>;
|
|
205
|
+
readonly at: Schema.optionalKey<Schema.Never>;
|
|
206
|
+
readonly every: Schema.optionalKey<Schema.Never>;
|
|
207
|
+
}>]>;
|
|
208
|
+
readonly ends: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Struct<{
|
|
209
|
+
readonly after: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
210
|
+
readonly at: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
211
|
+
readonly times: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Int>>, Schema.optionalKey<Schema.Int>, never, never>;
|
|
212
|
+
}>>>, Schema.optionalKey<Schema.Struct<{
|
|
213
|
+
readonly after: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
214
|
+
readonly at: Schema.decodeTo<Schema.optional<Schema.toType<Schema.String>>, Schema.optionalKey<Schema.String>, never, never>;
|
|
215
|
+
readonly times: Schema.decodeTo<Schema.optional<Schema.toType<Schema.Int>>, Schema.optionalKey<Schema.Int>, never, never>;
|
|
216
|
+
}>>, never, never>;
|
|
217
|
+
readonly prompt: Schema.String;
|
|
218
|
+
}>;
|
|
219
|
+
export type Request = typeof Request.Type;
|
|
220
|
+
export declare const toCreateInput: (sessionID: SessionID, request: Request) => CreateInput;
|
package/dist/schedule.js
CHANGED
|
@@ -9,11 +9,11 @@ export const ID = Schema.String.check(Schema.isStartingWith("sch_")).pipe(Schema
|
|
|
9
9
|
const decodeDuration = Schema.decodeUnknownOption(Schema.DurationFromString);
|
|
10
10
|
/** Milliseconds in a duration string, or `None` when it is not one. */
|
|
11
11
|
export const durationMillis = (value) => decodeDuration(value).pipe(Option.map(Duration.toMillis));
|
|
12
|
-
/** A duration such as "90 seconds", "5 minutes" or "2 hours". */
|
|
13
|
-
export const DurationString = Schema.String.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})
|
|
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
17
|
const zone = {
|
|
18
18
|
tz: Schema.String.pipe(optional).annotate({
|
|
19
19
|
description: "IANA time zone. Defaults to the configured timezone, then the server's local zone.",
|
|
@@ -70,3 +70,41 @@ export const CreateInput = Schema.Struct({
|
|
|
70
70
|
ends: Ends.pipe(optional),
|
|
71
71
|
action: Action,
|
|
72
72
|
}).annotate({ identifier: "Schedule.CreateInput" });
|
|
73
|
+
/** Declares a trigger absent, so `{ in, every }` fails instead of decoding as a one-shot. */
|
|
74
|
+
const absent = Schema.optionalKey(Schema.Never);
|
|
75
|
+
/** The `when` callers write: exactly one of `in`, `at`, `every` or `cron`, with an optional `tz`. */
|
|
76
|
+
export const WhenInput = Schema.Union([
|
|
77
|
+
Schema.Struct({ in: In.fields.in, at: absent, every: absent, cron: absent, ...zone }),
|
|
78
|
+
Schema.Struct({ at: At.fields.at, in: absent, every: absent, cron: absent, ...zone }),
|
|
79
|
+
Schema.Struct({ every: Every.fields.every, in: absent, at: absent, cron: absent, ...zone }),
|
|
80
|
+
Schema.Struct({ cron: Cron.fields.cron, in: absent, at: absent, every: absent, ...zone }),
|
|
81
|
+
]).annotate({ identifier: "Schedule.WhenInput" });
|
|
82
|
+
/** A schedule as callers describe it: when it fires, when it stops, and the prompt it wakes the Session with. */
|
|
83
|
+
export const Request = Schema.Struct({
|
|
84
|
+
name: Schema.String.pipe(optional).annotate({ description: "A short label for the schedule." }),
|
|
85
|
+
when: WhenInput.annotate({
|
|
86
|
+
description: 'When it fires: { in: "20 minutes" }, { at: "2026-10-27T09:00" }, { every: "1 hour" } or { cron: "0 9 * * 1-5" }. Wall-clock times use tz.',
|
|
87
|
+
}),
|
|
88
|
+
ends: Ends.pipe(optional).annotate({
|
|
89
|
+
description: 'Stops a repeating schedule at the first limit reached: { after: "8 hours" }, { at }, { times: 3 }.',
|
|
90
|
+
}),
|
|
91
|
+
prompt: Schema.String.check(Schema.isMinLength(1)).annotate({
|
|
92
|
+
description: "The message the Session receives each time the schedule fires.",
|
|
93
|
+
}),
|
|
94
|
+
}).annotate({ identifier: "Schedule.Request" });
|
|
95
|
+
export const toCreateInput = (sessionID, request) => ({
|
|
96
|
+
sessionID,
|
|
97
|
+
name: request.name,
|
|
98
|
+
when: toWhen(request.when),
|
|
99
|
+
ends: request.ends,
|
|
100
|
+
action: { type: "prompt", prompt: request.prompt },
|
|
101
|
+
});
|
|
102
|
+
const toWhen = (when) => {
|
|
103
|
+
if (when.in !== undefined)
|
|
104
|
+
return { type: "in", in: when.in, tz: when.tz };
|
|
105
|
+
if (when.at !== undefined)
|
|
106
|
+
return { type: "at", at: when.at, tz: when.tz };
|
|
107
|
+
if (when.every !== undefined)
|
|
108
|
+
return { type: "every", every: when.every, tz: when.tz };
|
|
109
|
+
return { type: "cron", cron: when.cron, tz: when.tz };
|
|
110
|
+
};
|