


















@@ -109,38 +109,42 @@ function cronPayloadObjectSchema(params: { toolsAllow: TSchema }) {
109109);
110110}
111111112-const CronScheduleSchema = Type.Optional(
113-Type.Object(
114-{
115-kind: optionalStringEnum(CRON_SCHEDULE_KINDS, { description: "Schedule kind" }),
116-at: Type.Optional(Type.String({ description: "ISO-8601 time (kind=at)" })),
117-everyMs: optionalPositiveIntegerSchema({ description: "Interval ms (kind=every)" }),
118-anchorMs: optionalNonNegativeIntegerSchema({
119-description: "Start anchor ms (kind=every)",
120-}),
121-expr: Type.Optional(
122-Type.String({
123-description:
124-'Cron expr in tz wall-clock time; do not convert to UTC. Omitted tz => Gateway host local timezone. Example 6pm Shanghai daily: expr "0 18 * * *", tz "Asia/Shanghai".',
125-}),
126-),
127-tz: Type.Optional(
128-Type.String({
129-description:
130-'IANA timezone for cron wall-clock fields, e.g. "Asia/Shanghai"; omitted => Gateway host local timezone.',
112+function createCronScheduleSchema(): TSchema {
113+return Type.Optional(
114+Type.Object(
115+{
116+kind: optionalStringEnum(CRON_SCHEDULE_KINDS, { description: "Schedule kind" }),
117+at: Type.Optional(Type.String({ description: "ISO-8601 time (kind=at)" })),
118+everyMs: optionalPositiveIntegerSchema({ description: "Interval ms (kind=every)" }),
119+anchorMs: optionalNonNegativeIntegerSchema({
120+description: "Start anchor ms (kind=every)",
131121}),
132-),
133-staggerMs: optionalNonNegativeIntegerSchema({ description: "Jitter ms (kind=cron)" }),
134-},
135-{ additionalProperties: true },
136-),
137-);
122+expr: Type.Optional(
123+Type.String({
124+description:
125+'Cron expr in tz wall-clock time; do not convert to UTC. Omitted tz => Gateway host local timezone. Example 6pm Shanghai daily: expr "0 18 * * *", tz "Asia/Shanghai".',
126+}),
127+),
128+tz: Type.Optional(
129+Type.String({
130+description:
131+'IANA timezone for cron wall-clock fields, e.g. "Asia/Shanghai"; omitted => Gateway host local timezone.',
132+}),
133+),
134+staggerMs: optionalNonNegativeIntegerSchema({ description: "Jitter ms (kind=cron)" }),
135+},
136+{ additionalProperties: true },
137+),
138+);
139+}
138140139-const CronPayloadSchema = Type.Optional(
140-cronPayloadObjectSchema({
141-toolsAllow: Type.Optional(Type.Array(Type.String(), { description: "Allowed tools" })),
142-}),
143-);
141+function createCronPayloadSchema(): TSchema {
142+return Type.Optional(
143+cronPayloadObjectSchema({
144+toolsAllow: Type.Optional(Type.Array(Type.String(), { description: "Allowed tools" })),
145+}),
146+);
147+}
144148145149function cronDeliverySchema(params: { nullableClears: boolean }) {
146150const failureDestinationObject = Type.Object(
@@ -193,101 +197,116 @@ function cronDeliverySchema(params: { nullableClears: boolean }) {
193197);
194198}
195199196-const CronDeliverySchema = cronDeliverySchema({ nullableClears: false });
197-const CronDeliveryPatchSchema = cronDeliverySchema({ nullableClears: true });
200+function createCronDeliverySchema(): TSchema {
201+return cronDeliverySchema({ nullableClears: false });
202+}
203+204+function createCronDeliveryPatchSchema(): TSchema {
205+return cronDeliverySchema({ nullableClears: true });
206+}
198207199208// Omitting `failureAlert` means "leave defaults/unchanged"; `false` explicitly disables alerts.
200209// Runtime handles `failureAlert === false` in cron/service/timer.ts.
201210// The schema declares `type: "object"` to stay compatible with providers that
202211// enforce an OpenAPI 3.0 subset (e.g. Gemini via GitHub Copilot). The
203212// description tells the LLM that `false` is also accepted.
204-const CronFailureAlertSchema = Type.Optional(
205-Type.Unsafe<Record<string, unknown> | false>({
206-type: "object",
207-properties: {
208-after: optionalPositiveIntegerSchema({ description: "Failures before alert" }),
209-channel: Type.Optional(Type.String({ description: "Alert channel" })),
210-to: Type.Optional(Type.String({ description: "Alert target" })),
211-cooldownMs: optionalNonNegativeIntegerSchema({ description: "Alert cooldown ms" }),
212-includeSkipped: Type.Optional(
213-Type.Boolean({ description: "Skipped runs count toward alert" }),
214-),
215-mode: optionalStringEnum(["announce", "webhook"] as const),
216-accountId: Type.Optional(Type.String()),
217-},
218-additionalProperties: true,
219-description: "Failure alert object; false disables alerts",
220-}),
221-);
213+function createCronFailureAlertSchema(): TSchema {
214+return Type.Optional(
215+Type.Unsafe<Record<string, unknown> | false>({
216+type: "object",
217+properties: {
218+after: optionalPositiveIntegerSchema({ description: "Failures before alert" }),
219+channel: Type.Optional(Type.String({ description: "Alert channel" })),
220+to: Type.Optional(Type.String({ description: "Alert target" })),
221+cooldownMs: optionalNonNegativeIntegerSchema({ description: "Alert cooldown ms" }),
222+includeSkipped: Type.Optional(
223+Type.Boolean({ description: "Skipped runs count toward alert" }),
224+),
225+mode: optionalStringEnum(["announce", "webhook"] as const),
226+accountId: Type.Optional(Type.String()),
227+},
228+additionalProperties: true,
229+description: "Failure alert object; false disables alerts",
230+}),
231+);
232+}
222233223-const CronJobObjectSchema = Type.Optional(
224-Type.Object(
225-{
226-name: Type.Optional(Type.String({ description: "Job name" })),
227-schedule: CronScheduleSchema,
228-sessionTarget: Type.Optional(
229-Type.String({
230-description: "main | isolated | current | session:<id>",
231-}),
232-),
233-wakeMode: optionalStringEnum(CRON_WAKE_MODES, { description: "Wake timing" }),
234-payload: CronPayloadSchema,
235-delivery: CronDeliverySchema,
236-agentId: nullableStringSchema("Agent id, or null to keep it unset"),
237-description: Type.Optional(Type.String({ description: "Human description" })),
238-enabled: Type.Optional(Type.Boolean()),
239-deleteAfterRun: Type.Optional(Type.Boolean({ description: "Delete after first run" })),
240-sessionKey: nullableStringSchema("Explicit session key, or null to clear it"),
241-failureAlert: CronFailureAlertSchema,
242-},
243-{ additionalProperties: true },
244-),
245-);
234+function createCronJobObjectSchema(): TSchema {
235+return Type.Optional(
236+Type.Object(
237+{
238+name: Type.Optional(Type.String({ description: "Job name" })),
239+schedule: createCronScheduleSchema(),
240+sessionTarget: Type.Optional(
241+Type.String({
242+description: "main | isolated | current | session:<id>",
243+}),
244+),
245+wakeMode: optionalStringEnum(CRON_WAKE_MODES, { description: "Wake timing" }),
246+payload: createCronPayloadSchema(),
247+delivery: createCronDeliverySchema(),
248+agentId: nullableStringSchema("Agent id, or null to keep it unset"),
249+description: Type.Optional(Type.String({ description: "Human description" })),
250+enabled: Type.Optional(Type.Boolean()),
251+deleteAfterRun: Type.Optional(Type.Boolean({ description: "Delete after first run" })),
252+sessionKey: nullableStringSchema("Explicit session key, or null to clear it"),
253+failureAlert: createCronFailureAlertSchema(),
254+},
255+{ additionalProperties: true },
256+),
257+);
258+}
259+260+function createCronPatchObjectSchema(): TSchema {
261+return Type.Optional(
262+Type.Object(
263+{
264+name: Type.Optional(Type.String({ description: "Job name" })),
265+schedule: createCronScheduleSchema(),
266+sessionTarget: Type.Optional(Type.String({ description: "Session target" })),
267+wakeMode: optionalStringEnum(CRON_WAKE_MODES),
268+payload: Type.Optional(
269+cronPayloadObjectSchema({
270+toolsAllow: nullableStringArraySchema("Allowed tool ids, or null to clear"),
271+}),
272+),
273+delivery: createCronDeliveryPatchSchema(),
274+description: Type.Optional(Type.String()),
275+enabled: Type.Optional(Type.Boolean()),
276+deleteAfterRun: Type.Optional(Type.Boolean()),
277+agentId: nullableStringSchema("Agent id, or null to clear it"),
278+sessionKey: nullableStringSchema("Explicit session key, or null to clear it"),
279+failureAlert: createCronFailureAlertSchema(),
280+},
281+{ additionalProperties: true },
282+),
283+);
284+}
246285247-const CronPatchObjectSchema = Type.Optional(
248-Type.Object(
286+// Flattened schema: runtime validates per-action requirements.
287+export function createCronToolSchema(): TSchema {
288+return Type.Object(
249289{
250-name: Type.Optional(Type.String({ description: "Job name" })),
251-schedule: CronScheduleSchema,
252-sessionTarget: Type.Optional(Type.String({ description: "Session target" })),
253-wakeMode: optionalStringEnum(CRON_WAKE_MODES),
254-payload: Type.Optional(
255-cronPayloadObjectSchema({
256-toolsAllow: nullableStringArraySchema("Allowed tool ids, or null to clear"),
257-}),
290+action: stringEnum(CRON_ACTIONS),
291+ ...gatewayCallOptionSchemaProperties(),
292+includeDisabled: Type.Optional(Type.Boolean()),
293+job: createCronJobObjectSchema(),
294+jobId: Type.Optional(Type.String()),
295+id: Type.Optional(Type.String()),
296+patch: createCronPatchObjectSchema(),
297+text: Type.Optional(Type.String()),
298+mode: optionalStringEnum(CRON_WAKE_MODES),
299+runMode: optionalStringEnum(CRON_RUN_MODES),
300+contextMessages: Type.Optional(
301+Type.Integer({ minimum: 0, maximum: REMINDER_CONTEXT_MESSAGES_MAX }),
258302),
259-delivery: CronDeliveryPatchSchema,
260-description: Type.Optional(Type.String()),
261-enabled: Type.Optional(Type.Boolean()),
262-deleteAfterRun: Type.Optional(Type.Boolean()),
263-agentId: nullableStringSchema("Agent id, or null to clear it"),
264-sessionKey: nullableStringSchema("Explicit session key, or null to clear it"),
265-failureAlert: CronFailureAlertSchema,
303+agentId: Type.Optional(Type.String({ description: "List filter: agent id" })),
266304},
267305{ additionalProperties: true },
268-),
269-);
306+);
307+}
270308271-// Flattened schema: runtime validates per-action requirements.
272-export const CronToolSchema = Type.Object(
273-{
274-action: stringEnum(CRON_ACTIONS),
275- ...gatewayCallOptionSchemaProperties(),
276-includeDisabled: Type.Optional(Type.Boolean()),
277-job: CronJobObjectSchema,
278-jobId: Type.Optional(Type.String()),
279-id: Type.Optional(Type.String()),
280-patch: CronPatchObjectSchema,
281-text: Type.Optional(Type.String()),
282-mode: optionalStringEnum(CRON_WAKE_MODES),
283-runMode: optionalStringEnum(CRON_RUN_MODES),
284-contextMessages: Type.Optional(
285-Type.Integer({ minimum: 0, maximum: REMINDER_CONTEXT_MESSAGES_MAX }),
286-),
287-agentId: Type.Optional(Type.String({ description: "List filter: agent id" })),
288-},
289-{ additionalProperties: true },
290-);
309+export const CronToolSchema = createCronToolSchema();
291310292311type CronToolOptions = {
293312agentSessionKey?: string;
@@ -550,7 +569,7 @@ WAKE MODES (for wake action):
550569- "now": wake immediately
551570552571Use jobId canonical; id accepted compat. contextMessages (0-10) adds previous messages as job context.`,
553-parameters: CronToolSchema,
572+parameters: createCronToolSchema(),
554573execute: async (_toolCallId, args) => {
555574const params = args as Record<string, unknown>;
556575const action = readStringParam(params, "action", { required: true });
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。