@tidegap/core 0.19.0 → 0.21.0
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/README.md +1 -1
- package/dist/agent-snippet.d.ts +30 -0
- package/dist/agent-snippet.js +120 -0
- package/dist/channels/commands.d.ts +137 -0
- package/dist/channels/commands.js +377 -0
- package/dist/channels/delivery-codes.d.ts +9 -0
- package/dist/channels/delivery-codes.js +53 -0
- package/dist/channels/digest.d.ts +102 -0
- package/dist/channels/digest.js +146 -0
- package/dist/channels/format.d.ts +138 -0
- package/dist/channels/format.js +425 -0
- package/dist/channels/index.d.ts +15 -0
- package/dist/channels/index.js +15 -0
- package/dist/channels/kinds/command.d.ts +13 -0
- package/dist/channels/kinds/command.js +65 -0
- package/dist/channels/kinds/discord.d.ts +16 -0
- package/dist/channels/kinds/discord.js +67 -0
- package/dist/channels/kinds/email.d.ts +20 -0
- package/dist/channels/kinds/email.js +162 -0
- package/dist/channels/kinds/index.d.ts +8 -0
- package/dist/channels/kinds/index.js +17 -0
- package/dist/channels/kinds/ntfy.d.ts +25 -0
- package/dist/channels/kinds/ntfy.js +163 -0
- package/dist/channels/kinds/pushover.d.ts +11 -0
- package/dist/channels/kinds/pushover.js +77 -0
- package/dist/channels/kinds/shared.d.ts +25 -0
- package/dist/channels/kinds/shared.js +39 -0
- package/dist/channels/kinds/shortcuts.d.ts +9 -0
- package/dist/channels/kinds/shortcuts.js +45 -0
- package/dist/channels/kinds/slack.d.ts +8 -0
- package/dist/channels/kinds/slack.js +57 -0
- package/dist/channels/kinds/telegram.d.ts +4 -0
- package/dist/channels/kinds/telegram.js +26 -0
- package/dist/channels/kinds/webhook.d.ts +30 -0
- package/dist/channels/kinds/webhook.js +177 -0
- package/dist/channels/payload.d.ts +36 -0
- package/dist/channels/payload.js +61 -0
- package/dist/channels/plan.d.ts +24 -0
- package/dist/channels/plan.js +66 -0
- package/dist/channels/registry.d.ts +191 -0
- package/dist/channels/registry.js +125 -0
- package/dist/channels/telegram.d.ts +110 -0
- package/dist/channels/telegram.js +168 -0
- package/dist/channels/types.d.ts +107 -0
- package/dist/channels/types.js +26 -0
- package/dist/claude-tools.d.ts +29 -0
- package/dist/claude-tools.js +49 -0
- package/dist/data/tables.generated.d.ts +6 -0
- package/dist/data/tables.generated.js +37 -0
- package/dist/energy.d.ts +84 -0
- package/dist/energy.js +138 -0
- package/dist/grid.d.ts +17 -2
- package/dist/grid.js +43 -4
- package/dist/handoff.d.ts +171 -0
- package/dist/handoff.js +482 -0
- package/dist/history.d.ts +17 -0
- package/dist/history.js +14 -1
- package/dist/index.d.ts +49 -15
- package/dist/index.js +36 -8
- package/dist/job-cadence.d.ts +76 -0
- package/dist/job-cadence.js +240 -0
- package/dist/jobs.d.ts +183 -0
- package/dist/jobs.js +917 -0
- package/dist/notify.d.ts +11 -0
- package/dist/notify.js +19 -4
- package/dist/postpone.d.ts +113 -0
- package/dist/postpone.js +185 -0
- package/dist/providers/anthropic.js +14 -8
- package/dist/providers/base.d.ts +145 -2
- package/dist/providers/base.js +41 -1
- package/dist/providers/budget.d.ts +25 -0
- package/dist/providers/budget.js +57 -0
- package/dist/providers/defaults.js +4 -0
- package/dist/providers/defer.d.ts +16 -0
- package/dist/providers/defer.js +31 -0
- package/dist/providers/gemini.d.ts +4 -0
- package/dist/providers/gemini.js +34 -24
- package/dist/providers/http.d.ts +40 -0
- package/dist/providers/http.js +82 -0
- package/dist/providers/index.d.ts +2 -2
- package/dist/providers/index.js +1 -1
- package/dist/providers/ollama.d.ts +4 -0
- package/dist/providers/ollama.js +32 -25
- package/dist/providers/openai.js +11 -9
- package/dist/providers/timeout.d.ts +36 -0
- package/dist/providers/timeout.js +71 -0
- package/dist/quota.d.ts +7 -2
- package/dist/quota.js +12 -27
- package/dist/readiness.d.ts +205 -0
- package/dist/readiness.js +326 -0
- package/dist/redact.d.ts +42 -0
- package/dist/redact.js +110 -0
- package/dist/region-host.d.ts +30 -0
- package/dist/region-host.js +69 -0
- package/dist/region.d.ts +102 -20
- package/dist/region.js +175 -23
- package/dist/run-limits.d.ts +268 -0
- package/dist/run-limits.js +572 -0
- package/dist/run-session.d.ts +36 -0
- package/dist/run-session.js +72 -0
- package/dist/schedule-job.d.ts +118 -0
- package/dist/schedule-job.js +243 -0
- package/dist/scheduler.d.ts +391 -18
- package/dist/scheduler.js +1341 -177
- package/dist/sign.d.ts +8 -1
- package/dist/sign.js +49 -3
- package/dist/storage/sqlite.d.ts +183 -5
- package/dist/storage/sqlite.js +720 -19
- package/dist/task-events.d.ts +117 -0
- package/dist/task-events.js +345 -0
- package/dist/tool-surface.d.ts +31 -2
- package/dist/tool-surface.js +390 -65
- package/dist/types.d.ts +267 -3
- package/dist/types.js +6 -1
- package/dist/zone-time.d.ts +22 -0
- package/dist/zone-time.js +76 -0
- package/package.json +13 -5
- package/dist/aggregator.d.ts.map +0 -1
- package/dist/aggregator.js.map +0 -1
- package/dist/budget.d.ts.map +0 -1
- package/dist/budget.js.map +0 -1
- package/dist/data/tables.generated.d.ts.map +0 -1
- package/dist/data/tables.generated.js.map +0 -1
- package/dist/energy.d.ts.map +0 -1
- package/dist/energy.js.map +0 -1
- package/dist/grid.d.ts.map +0 -1
- package/dist/grid.js.map +0 -1
- package/dist/history.d.ts.map +0 -1
- package/dist/history.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/notify.d.ts.map +0 -1
- package/dist/notify.js.map +0 -1
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/providers/anthropic.d.ts.map +0 -1
- package/dist/providers/anthropic.js.map +0 -1
- package/dist/providers/base.d.ts.map +0 -1
- package/dist/providers/base.js.map +0 -1
- package/dist/providers/defaults.d.ts.map +0 -1
- package/dist/providers/defaults.js.map +0 -1
- package/dist/providers/gemini.d.ts.map +0 -1
- package/dist/providers/gemini.js.map +0 -1
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/index.js.map +0 -1
- package/dist/providers/ollama.d.ts.map +0 -1
- package/dist/providers/ollama.js.map +0 -1
- package/dist/providers/openai.d.ts.map +0 -1
- package/dist/providers/openai.js.map +0 -1
- package/dist/quota.d.ts.map +0 -1
- package/dist/quota.js.map +0 -1
- package/dist/recommend.d.ts.map +0 -1
- package/dist/recommend.js.map +0 -1
- package/dist/redact.d.ts.map +0 -1
- package/dist/redact.js.map +0 -1
- package/dist/region.d.ts.map +0 -1
- package/dist/region.js.map +0 -1
- package/dist/routing.d.ts.map +0 -1
- package/dist/routing.js.map +0 -1
- package/dist/scheduler.d.ts.map +0 -1
- package/dist/scheduler.js.map +0 -1
- package/dist/select-window.d.ts.map +0 -1
- package/dist/select-window.js.map +0 -1
- package/dist/sign.d.ts.map +0 -1
- package/dist/sign.js.map +0 -1
- package/dist/storage/sqlite.d.ts.map +0 -1
- package/dist/storage/sqlite.js.map +0 -1
- package/dist/tool-surface.d.ts.map +0 -1
- package/dist/tool-surface.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `schedule_task` sugar for floating recurring jobs (KTD16), shared by the
|
|
3
|
+
* MCP server and the OpenClaw plugin so both hosts read the same `repeat`
|
|
4
|
+
* vocabulary the same way.
|
|
5
|
+
*
|
|
6
|
+
* A job `repeat` (`daily`, `weekdays`, `weekly`, `every_n_hours`) creates a
|
|
7
|
+
* prompt job; `none` queues a one-off task and `quota_reset` keeps the older
|
|
8
|
+
* series path. Agents never create command jobs (KD10): a shell-like
|
|
9
|
+
* argument is refused with the CLI command the user runs instead.
|
|
10
|
+
*/
|
|
11
|
+
import { type JobInput } from "./jobs.js";
|
|
12
|
+
import { type DurationValue } from "./run-limits.js";
|
|
13
|
+
import type { Scheduler } from "./scheduler.js";
|
|
14
|
+
import type { JobRecord, JobTools, ProviderName } from "./types.js";
|
|
15
|
+
/** The `repeat` values that create a job. */
|
|
16
|
+
export declare const JOB_REPEATS: readonly ["daily", "weekdays", "weekly", "every_n_hours"];
|
|
17
|
+
export type JobRepeat = (typeof JOB_REPEATS)[number];
|
|
18
|
+
/** True when `repeat` creates a job rather than a one-off task or a series. */
|
|
19
|
+
export declare function isJobRepeat(repeat: unknown): repeat is JobRepeat;
|
|
20
|
+
/** Parameters that only mean something with a job repeat. */
|
|
21
|
+
export declare const JOB_ONLY_PARAMS: readonly ["every_hours", "days", "window", "time_zone"];
|
|
22
|
+
/** The CLI line that queues a one-off shell command task, which only the user runs. */
|
|
23
|
+
export declare const QUEUE_ADD_COMMAND_LINE = "tidegap queue add --runner command --cwd <dir> --by <when> '<cmd>'";
|
|
24
|
+
/**
|
|
25
|
+
* The refusal for a call that tries to create a command job (AE12) or a
|
|
26
|
+
* one-off shell command task (`runner` or `provider` "command"), or
|
|
27
|
+
* undefined. Checked on the raw arguments: the schemas drop unknown keys.
|
|
28
|
+
*/
|
|
29
|
+
export declare function commandJobRefusal(args: Record<string, unknown>): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* The refusal for job-only parameters passed without a job repeat, or
|
|
32
|
+
* undefined. `repeat` is the call's repeat when it creates a job (else
|
|
33
|
+
* undefined); `present` lists the parameter names the call set.
|
|
34
|
+
*/
|
|
35
|
+
export declare function jobParamsRefusal(repeat: JobRepeat | undefined, present: readonly string[]): string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The refusal for per-task options a job cannot keep, or undefined. `args`
|
|
38
|
+
* are the call's arguments; an option counts when set to anything but
|
|
39
|
+
* `false`, and `dispatch` counts only when `false` (its default is `true`).
|
|
40
|
+
*/
|
|
41
|
+
export declare function jobUnsupportedRefusal(args: Record<string, unknown>): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The job tool group for a `claude-code` tool list: any file tool keeps the
|
|
44
|
+
* read-only file group, any web tool the web group, `[]` none. The caller
|
|
45
|
+
* has already refused a list that mixes the two (claudeCodeToolsError).
|
|
46
|
+
*/
|
|
47
|
+
export declare function jobToolsFor(tools: readonly string[]): JobTools;
|
|
48
|
+
/** What both hosts pass to build a prompt job from a `schedule_task` call. */
|
|
49
|
+
export interface ScheduleJobArgs {
|
|
50
|
+
prompt: string;
|
|
51
|
+
title?: string;
|
|
52
|
+
repeat: JobRepeat;
|
|
53
|
+
everyHours?: number;
|
|
54
|
+
days?: readonly string[];
|
|
55
|
+
window?: string;
|
|
56
|
+
timeZone?: string;
|
|
57
|
+
/** Deadline of the first run only (AS9). */
|
|
58
|
+
deadline?: string;
|
|
59
|
+
provider: ProviderName;
|
|
60
|
+
model?: string;
|
|
61
|
+
tools: JobTools;
|
|
62
|
+
/** The project directory a run starts in; never a session to fork (KD8). */
|
|
63
|
+
cwd?: string;
|
|
64
|
+
/** The job's own LLM time limit (`llm_timeout`), in ms or `"none"`; unset follows the settings. */
|
|
65
|
+
llmTimeoutMs?: DurationValue;
|
|
66
|
+
/** The job's own retries per slot and retry delay in ms (`retries`, `retry_delay`); unset follows the settings. */
|
|
67
|
+
retries?: number;
|
|
68
|
+
retryDelayMs?: number;
|
|
69
|
+
host: "mcp" | "openclaw";
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The `llm_timeout` tool argument in ms or `"none"`, or undefined when it
|
|
73
|
+
* is absent. Throws an Error whose message names the grammar and `none`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function llmTimeoutArg(value: unknown): DurationValue | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* The `retries` and `retry_delay` tool arguments as caps (`retries`,
|
|
78
|
+
* `retryDelayMs`), each only when given. Throws an Error whose message names
|
|
79
|
+
* the parameter and its rule.
|
|
80
|
+
*/
|
|
81
|
+
export declare function retryCapsArgs(args: {
|
|
82
|
+
retries?: unknown;
|
|
83
|
+
retry_delay?: unknown;
|
|
84
|
+
}): {
|
|
85
|
+
retries?: number;
|
|
86
|
+
retryDelayMs?: number;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* The {@link JobInput} for a `schedule_task` job call. Throws an Error with
|
|
90
|
+
* a plain message on a bad cadence, window or zone.
|
|
91
|
+
*/
|
|
92
|
+
export declare function scheduleJobInput(args: ScheduleJobArgs, now?: Date): JobInput;
|
|
93
|
+
/** A job as the tool hosts list it. */
|
|
94
|
+
export interface JobToolView {
|
|
95
|
+
jobId: string;
|
|
96
|
+
title: string;
|
|
97
|
+
status: JobRecord["status"];
|
|
98
|
+
/** The guarantee in words, e.g. "runs every day between 00:00 and 08:00". */
|
|
99
|
+
guarantee: string;
|
|
100
|
+
/** Planned hour of the job's live run, if one is planned. */
|
|
101
|
+
nextRun?: string;
|
|
102
|
+
/** Id of that run. */
|
|
103
|
+
nextTaskId?: string;
|
|
104
|
+
lastOutcome?: JobRecord["lastOutcome"];
|
|
105
|
+
pauseReason?: string;
|
|
106
|
+
}
|
|
107
|
+
/** One job's list view: guarantee, next run, last result. */
|
|
108
|
+
export declare function jobToolView(scheduler: Scheduler, job: JobRecord): JobToolView;
|
|
109
|
+
/**
|
|
110
|
+
* `cancel_task series=true` on a job's run (series coexistence map): remove
|
|
111
|
+
* the job, so no further run is materialized. Returns the job when the task
|
|
112
|
+
* belongs to one (already removed included), else undefined. The caller
|
|
113
|
+
* cancels the task itself afterwards (stop flag first, KTD4).
|
|
114
|
+
*/
|
|
115
|
+
export declare function endJobOfTask(scheduler: Scheduler, taskId: string, opts?: {
|
|
116
|
+
actor?: string;
|
|
117
|
+
}): Promise<JobRecord | undefined>;
|
|
118
|
+
//# sourceMappingURL=schedule-job.d.ts.map
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `schedule_task` sugar for floating recurring jobs (KTD16), shared by the
|
|
3
|
+
* MCP server and the OpenClaw plugin so both hosts read the same `repeat`
|
|
4
|
+
* vocabulary the same way.
|
|
5
|
+
*
|
|
6
|
+
* A job `repeat` (`daily`, `weekdays`, `weekly`, `every_n_hours`) creates a
|
|
7
|
+
* prompt job; `none` queues a one-off task and `quota_reset` keeps the older
|
|
8
|
+
* series path. Agents never create command jobs (KD10): a shell-like
|
|
9
|
+
* argument is refused with the CLI command the user runs instead.
|
|
10
|
+
*/
|
|
11
|
+
import { includesFileTool, includesWebTool } from "./claude-tools.js";
|
|
12
|
+
import { guaranteeText, parseWindow, validateJobSchedule } from "./job-cadence.js";
|
|
13
|
+
import { getJob, removeJob } from "./jobs.js";
|
|
14
|
+
import { DURATION_FORM_ERROR, parseDuration, parseRetryDelay, RETRY_DELAY_ERROR, runLimitValueError, } from "./run-limits.js";
|
|
15
|
+
import { systemTimeZone } from "./zone-time.js";
|
|
16
|
+
/** The `repeat` values that create a job. */
|
|
17
|
+
export const JOB_REPEATS = ["daily", "weekdays", "weekly", "every_n_hours"];
|
|
18
|
+
/** True when `repeat` creates a job rather than a one-off task or a series. */
|
|
19
|
+
export function isJobRepeat(repeat) {
|
|
20
|
+
return typeof repeat === "string" && JOB_REPEATS.includes(repeat);
|
|
21
|
+
}
|
|
22
|
+
/** Parameters that only mean something with a job repeat. */
|
|
23
|
+
export const JOB_ONLY_PARAMS = ["every_hours", "days", "window", "time_zone"];
|
|
24
|
+
/** Argument names that would make the run execute a shell command. */
|
|
25
|
+
const SHELL_KEYS = ["command", "cmd", "shell", "script"];
|
|
26
|
+
/** The CLI line that queues a one-off shell command task, which only the user runs. */
|
|
27
|
+
export const QUEUE_ADD_COMMAND_LINE = "tidegap queue add --runner command --cwd <dir> --by <when> '<cmd>'";
|
|
28
|
+
/**
|
|
29
|
+
* The refusal for a call that tries to create a command job (AE12) or a
|
|
30
|
+
* one-off shell command task (`runner` or `provider` "command"), or
|
|
31
|
+
* undefined. Checked on the raw arguments: the schemas drop unknown keys.
|
|
32
|
+
*/
|
|
33
|
+
export function commandJobRefusal(args) {
|
|
34
|
+
const field = ["runner", "provider"].find((k) => args[k] === "command");
|
|
35
|
+
if (field) {
|
|
36
|
+
return (`schedule_task cannot queue a shell command (${field} "command"): a shell command task is the user's call. ` +
|
|
37
|
+
`Ask the user to run: ${QUEUE_ADD_COMMAND_LINE}`);
|
|
38
|
+
}
|
|
39
|
+
const key = SHELL_KEYS.find((k) => args[k] !== undefined);
|
|
40
|
+
if (!key)
|
|
41
|
+
return undefined;
|
|
42
|
+
return (`schedule_task cannot create command jobs (got "${key}"). ` +
|
|
43
|
+
`Ask the user to run: tidegap jobs add --command '<cmd>' --daily (see tidegap jobs add --help)`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The refusal for job-only parameters passed without a job repeat, or
|
|
47
|
+
* undefined. `repeat` is the call's repeat when it creates a job (else
|
|
48
|
+
* undefined); `present` lists the parameter names the call set.
|
|
49
|
+
*/
|
|
50
|
+
export function jobParamsRefusal(repeat, present) {
|
|
51
|
+
if (repeat !== undefined) {
|
|
52
|
+
if (repeat !== "every_n_hours" && present.includes("every_hours"))
|
|
53
|
+
return `every_hours needs repeat "every_n_hours"`;
|
|
54
|
+
if (repeat !== "weekly" && present.includes("days"))
|
|
55
|
+
return `days needs repeat "weekly"`;
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const stray = JOB_ONLY_PARAMS.filter((p) => present.includes(p));
|
|
59
|
+
if (stray.length === 0)
|
|
60
|
+
return undefined;
|
|
61
|
+
return `${stray.join(", ")} need a job repeat (${JOB_REPEATS.join(", ")})`;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Per-task options a job cannot keep, across both hosts: a job's runs plan
|
|
65
|
+
* against the default region and carry no routing, budget, timing or
|
|
66
|
+
* delivery options of their own.
|
|
67
|
+
*/
|
|
68
|
+
const JOB_UNSUPPORTED_PARAMS = [
|
|
69
|
+
"region",
|
|
70
|
+
"carbon_budget_g",
|
|
71
|
+
"candidates",
|
|
72
|
+
"route_weights",
|
|
73
|
+
"not_before",
|
|
74
|
+
"after_limit_reset",
|
|
75
|
+
"dry_run",
|
|
76
|
+
"output_path",
|
|
77
|
+
"cwd",
|
|
78
|
+
"permission_profile",
|
|
79
|
+
"result_path",
|
|
80
|
+
"wake_session",
|
|
81
|
+
"redact_in_receipt",
|
|
82
|
+
"quota_provider",
|
|
83
|
+
"deliver",
|
|
84
|
+
"webhook_url",
|
|
85
|
+
"file_path",
|
|
86
|
+
"file_format",
|
|
87
|
+
];
|
|
88
|
+
/**
|
|
89
|
+
* The refusal for per-task options a job cannot keep, or undefined. `args`
|
|
90
|
+
* are the call's arguments; an option counts when set to anything but
|
|
91
|
+
* `false`, and `dispatch` counts only when `false` (its default is `true`).
|
|
92
|
+
*/
|
|
93
|
+
export function jobUnsupportedRefusal(args) {
|
|
94
|
+
const present = JOB_UNSUPPORTED_PARAMS.filter((k) => args[k] !== undefined && args[k] !== false);
|
|
95
|
+
if (args.dispatch === false)
|
|
96
|
+
present.push("dispatch");
|
|
97
|
+
if (present.length === 0)
|
|
98
|
+
return undefined;
|
|
99
|
+
return `${present.join(", ")} cannot be used with a job repeat; omit ${present.length === 1 ? "it" : "them"}`;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The job tool group for a `claude-code` tool list: any file tool keeps the
|
|
103
|
+
* read-only file group, any web tool the web group, `[]` none. The caller
|
|
104
|
+
* has already refused a list that mixes the two (claudeCodeToolsError).
|
|
105
|
+
*/
|
|
106
|
+
export function jobToolsFor(tools) {
|
|
107
|
+
if (includesFileTool(tools))
|
|
108
|
+
return "files";
|
|
109
|
+
if (includesWebTool(tools))
|
|
110
|
+
return "web";
|
|
111
|
+
return "none";
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The `llm_timeout` tool argument in ms or `"none"`, or undefined when it
|
|
115
|
+
* is absent. Throws an Error whose message names the grammar and `none`.
|
|
116
|
+
*/
|
|
117
|
+
export function llmTimeoutArg(value) {
|
|
118
|
+
if (value === undefined)
|
|
119
|
+
return undefined;
|
|
120
|
+
if (typeof value !== "string")
|
|
121
|
+
throw new Error(`llm_timeout: ${DURATION_FORM_ERROR}`);
|
|
122
|
+
try {
|
|
123
|
+
return parseDuration(value);
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
throw new Error(`llm_timeout: ${err.message}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The `retries` and `retry_delay` tool arguments as caps (`retries`,
|
|
131
|
+
* `retryDelayMs`), each only when given. Throws an Error whose message names
|
|
132
|
+
* the parameter and its rule.
|
|
133
|
+
*/
|
|
134
|
+
export function retryCapsArgs(args) {
|
|
135
|
+
const out = {};
|
|
136
|
+
if (args.retries !== undefined) {
|
|
137
|
+
const error = runLimitValueError("retries", args.retries);
|
|
138
|
+
if (error)
|
|
139
|
+
throw new Error(`retries: ${error}`);
|
|
140
|
+
out.retries = args.retries;
|
|
141
|
+
}
|
|
142
|
+
if (args.retry_delay !== undefined) {
|
|
143
|
+
if (typeof args.retry_delay !== "string")
|
|
144
|
+
throw new Error(`retry_delay: ${RETRY_DELAY_ERROR}`);
|
|
145
|
+
try {
|
|
146
|
+
out.retryDelayMs = parseRetryDelay(args.retry_delay);
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
throw new Error(`retry_delay: ${err.message}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
/** Today's weekday in `timeZone` (a `weekly` job with no days, KTD16). */
|
|
155
|
+
function weekdayIn(timeZone, now) {
|
|
156
|
+
return new Intl.DateTimeFormat("en-US", { weekday: "short", timeZone }).format(now).toLowerCase().slice(0, 3);
|
|
157
|
+
}
|
|
158
|
+
function cadenceOf(args, timeZone, now) {
|
|
159
|
+
switch (args.repeat) {
|
|
160
|
+
case "daily":
|
|
161
|
+
return { kind: "daily" };
|
|
162
|
+
case "weekdays":
|
|
163
|
+
return { kind: "weekdays" };
|
|
164
|
+
case "weekly":
|
|
165
|
+
// validateJobSchedule checks the day names.
|
|
166
|
+
return {
|
|
167
|
+
kind: "weekly",
|
|
168
|
+
days: (args.days && args.days.length > 0 ? args.days : [weekdayIn(timeZone, now)]),
|
|
169
|
+
};
|
|
170
|
+
case "every_n_hours":
|
|
171
|
+
if (args.everyHours === undefined)
|
|
172
|
+
throw new Error(`repeat "every_n_hours" needs every_hours (2 to 168)`);
|
|
173
|
+
return { kind: "hours", every: args.everyHours };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* The {@link JobInput} for a `schedule_task` job call. Throws an Error with
|
|
178
|
+
* a plain message on a bad cadence, window or zone.
|
|
179
|
+
*/
|
|
180
|
+
export function scheduleJobInput(args, now = new Date()) {
|
|
181
|
+
const timeZone = args.timeZone ?? systemTimeZone();
|
|
182
|
+
// The zone is checked before the weekday lookup uses it.
|
|
183
|
+
validateJobSchedule({ cadence: { kind: "daily" }, timeZone });
|
|
184
|
+
const cadence = cadenceOf(args, timeZone, now);
|
|
185
|
+
const window = args.window !== undefined ? parseWindow(args.window) : undefined;
|
|
186
|
+
const schedule = validateJobSchedule({ cadence, window, timeZone });
|
|
187
|
+
const caps = {
|
|
188
|
+
...(args.llmTimeoutMs !== undefined ? { llmTimeoutMs: args.llmTimeoutMs } : {}),
|
|
189
|
+
...(args.retries !== undefined ? { retries: args.retries } : {}),
|
|
190
|
+
...(args.retryDelayMs !== undefined ? { retryDelayMs: args.retryDelayMs } : {}),
|
|
191
|
+
};
|
|
192
|
+
return {
|
|
193
|
+
title: args.title?.trim() ? args.title : args.prompt,
|
|
194
|
+
cadence: schedule.cadence,
|
|
195
|
+
window: schedule.window,
|
|
196
|
+
timeZone: schedule.timeZone,
|
|
197
|
+
template: {
|
|
198
|
+
runner: "prompt",
|
|
199
|
+
prompt: args.prompt,
|
|
200
|
+
provider: args.provider,
|
|
201
|
+
model: args.model,
|
|
202
|
+
cwd: args.cwd,
|
|
203
|
+
tools: args.tools,
|
|
204
|
+
},
|
|
205
|
+
originHost: args.host,
|
|
206
|
+
originCwd: args.cwd,
|
|
207
|
+
...(caps && Object.keys(caps).length > 0 ? { caps } : {}),
|
|
208
|
+
...(args.deadline !== undefined ? { deadline: args.deadline } : {}),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
const LIVE = new Set(["queued", "scheduled", "running", "submitted"]);
|
|
212
|
+
/** One job's list view: guarantee, next run, last result. */
|
|
213
|
+
export function jobToolView(scheduler, job) {
|
|
214
|
+
const row = job.pendingTaskId ? scheduler.ledger()?.get(job.pendingTaskId) : undefined;
|
|
215
|
+
const live = row && LIVE.has(row.status) ? row : undefined;
|
|
216
|
+
return {
|
|
217
|
+
jobId: job.jobId,
|
|
218
|
+
title: job.title,
|
|
219
|
+
status: job.status,
|
|
220
|
+
guarantee: guaranteeText({ cadence: job.cadence, window: job.window, timeZone: job.timeZone }),
|
|
221
|
+
...(live ? { nextTaskId: live.taskId, nextRun: live.scheduledFor ?? live.notBefore } : {}),
|
|
222
|
+
...(job.lastOutcome ? { lastOutcome: job.lastOutcome } : {}),
|
|
223
|
+
...(job.pauseReason ? { pauseReason: job.pauseReason } : {}),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* `cancel_task series=true` on a job's run (series coexistence map): remove
|
|
228
|
+
* the job, so no further run is materialized. Returns the job when the task
|
|
229
|
+
* belongs to one (already removed included), else undefined. The caller
|
|
230
|
+
* cancels the task itself afterwards (stop flag first, KTD4).
|
|
231
|
+
*/
|
|
232
|
+
export async function endJobOfTask(scheduler, taskId, opts = {}) {
|
|
233
|
+
const jobId = scheduler.ledger()?.get(taskId)?.jobId;
|
|
234
|
+
if (!jobId)
|
|
235
|
+
return undefined;
|
|
236
|
+
const job = getJob(scheduler, jobId);
|
|
237
|
+
if (!job)
|
|
238
|
+
return undefined;
|
|
239
|
+
if (job.status === "removed")
|
|
240
|
+
return job;
|
|
241
|
+
return removeJob(scheduler, jobId, opts);
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=schedule-job.js.map
|