@theokit/sdk 2.29.0 → 2.30.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/CHANGELOG.md +10 -0
- package/dist/{cron-COSAehOL.d.ts → cron-BNHJywtl.d.ts} +374 -17
- package/dist/{cron-yJoNUZxe.d.cts → cron-t4oKI2Is.d.cts} +374 -17
- package/dist/cron.cjs +89 -44
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +2 -2
- package/dist/cron.d.ts +2 -2
- package/dist/cron.js +89 -44
- package/dist/cron.js.map +1 -1
- package/dist/{errors-tP-8O-hR.d.cts → errors-DZpCGlYv.d.cts} +1 -1
- package/dist/{errors-BxMIlgLP.d.ts → errors-D_Bfo30u.d.ts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/index.cjs +89 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -135
- package/dist/index.d.ts +7 -135
- package/dist/index.js +89 -44
- package/dist/index.js.map +1 -1
- package/dist/{run-q_P0vHlY.d.cts → run-CLXKMRgq.d.cts} +1 -1
- package/dist/{run-q_P0vHlY.d.ts → run-CLXKMRgq.d.ts} +1 -1
- package/dist/types/cron.d.ts +30 -13
- package/package.json +1 -1
package/dist/cron.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { V as Cron } from './cron-t4oKI2Is.cjs';
|
|
2
|
+
import './run-CLXKMRgq.cjs';
|
|
3
3
|
import 'zod';
|
package/dist/cron.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { V as Cron } from './cron-BNHJywtl.js';
|
|
2
|
+
import './run-CLXKMRgq.js';
|
|
3
3
|
import 'zod';
|
package/dist/cron.js
CHANGED
|
@@ -17766,15 +17766,31 @@ setAgentFacade({
|
|
|
17766
17766
|
// src/cron.ts
|
|
17767
17767
|
init_errors();
|
|
17768
17768
|
|
|
17769
|
+
// src/internal/cron/fire-handler.ts
|
|
17770
|
+
init_registry();
|
|
17771
|
+
|
|
17769
17772
|
// src/internal/cron/run-job.ts
|
|
17770
17773
|
init_errors();
|
|
17771
17774
|
init_agent_factory_registry();
|
|
17772
17775
|
async function runCronJob(job) {
|
|
17773
|
-
if (job.
|
|
17774
|
-
if (job.
|
|
17775
|
-
|
|
17776
|
-
|
|
17777
|
-
|
|
17776
|
+
if (job.workflow !== void 0) return job.workflow.run(job.inputData);
|
|
17777
|
+
if (job.agent !== void 0) return runWithEphemeralAgent(job.agent, requireMessage(job));
|
|
17778
|
+
if (job.agentId !== void 0) return runWithExistingAgent(job.agentId, requireMessage(job));
|
|
17779
|
+
throw new ConfigurationError(
|
|
17780
|
+
`Cron job ${job.id} has no target (agent, agentId, or workflow) \u2014 cannot run.`,
|
|
17781
|
+
{ code: "cron_no_target" }
|
|
17782
|
+
);
|
|
17783
|
+
}
|
|
17784
|
+
function isAgentRun(outcome) {
|
|
17785
|
+
return typeof outcome.wait === "function";
|
|
17786
|
+
}
|
|
17787
|
+
function requireMessage(job) {
|
|
17788
|
+
if (job.message === void 0) {
|
|
17789
|
+
throw new ConfigurationError(`Cron job ${job.id} is an agent target but has no message.`, {
|
|
17790
|
+
code: "cron_missing_message"
|
|
17791
|
+
});
|
|
17792
|
+
}
|
|
17793
|
+
return job.message;
|
|
17778
17794
|
}
|
|
17779
17795
|
async function runWithExistingAgent(agentId, message) {
|
|
17780
17796
|
const info = await getAgentFacade().get(agentId).catch(() => void 0);
|
|
@@ -17792,6 +17808,37 @@ async function runWithEphemeralAgent(baseOptions, message) {
|
|
|
17792
17808
|
return agent.send(message);
|
|
17793
17809
|
}
|
|
17794
17810
|
|
|
17811
|
+
// src/internal/cron/fire-handler.ts
|
|
17812
|
+
async function fireCronJobAsTask(job) {
|
|
17813
|
+
const fireTs = Date.now();
|
|
17814
|
+
const taskId = `cron-${job.id}-${fireTs}`;
|
|
17815
|
+
try {
|
|
17816
|
+
await submit({
|
|
17817
|
+
kind: "cron",
|
|
17818
|
+
id: taskId,
|
|
17819
|
+
allowReservedPrefix: true,
|
|
17820
|
+
meta: { jobId: job.id, jobName: job.name, schedule: job.cron, firedAt: fireTs },
|
|
17821
|
+
work: async (ctx) => {
|
|
17822
|
+
const outcome = await runCronJob(job);
|
|
17823
|
+
if (isAgentRun(outcome)) {
|
|
17824
|
+
ctx.signal.addEventListener("abort", () => void outcome.cancel().catch(() => {
|
|
17825
|
+
}), {
|
|
17826
|
+
once: true
|
|
17827
|
+
});
|
|
17828
|
+
const result = await outcome.wait();
|
|
17829
|
+
ctx.emit({ status: result.status, runId: outcome.id });
|
|
17830
|
+
return { status: result.status, runId: outcome.id };
|
|
17831
|
+
}
|
|
17832
|
+
ctx.emit({ status: outcome.status, runId: outcome.id });
|
|
17833
|
+
return { status: outcome.status, runId: outcome.id };
|
|
17834
|
+
}
|
|
17835
|
+
});
|
|
17836
|
+
} catch {
|
|
17837
|
+
const outcome = await runCronJob(job);
|
|
17838
|
+
if (isAgentRun(outcome)) await outcome.wait();
|
|
17839
|
+
}
|
|
17840
|
+
}
|
|
17841
|
+
|
|
17795
17842
|
// src/internal/cron/store.ts
|
|
17796
17843
|
var jobs = /* @__PURE__ */ new Map();
|
|
17797
17844
|
function listJobs() {
|
|
@@ -17982,7 +18029,6 @@ function estimateNextRunAt(_cron, _timezone) {
|
|
|
17982
18029
|
}
|
|
17983
18030
|
|
|
17984
18031
|
// src/cron.ts
|
|
17985
|
-
init_registry();
|
|
17986
18032
|
var Cron = class {
|
|
17987
18033
|
constructor() {
|
|
17988
18034
|
}
|
|
@@ -18049,7 +18095,8 @@ var Cron = class {
|
|
|
18049
18095
|
return updateJobStatus(jobId, false);
|
|
18050
18096
|
}
|
|
18051
18097
|
/**
|
|
18052
|
-
* Manually trigger a cron job off-schedule. Returns the resulting `Run
|
|
18098
|
+
* Manually trigger a cron job off-schedule. Returns the resulting `Run`
|
|
18099
|
+
* (agent target) or `WorkflowRun` (workflow target — SE35).
|
|
18053
18100
|
*
|
|
18054
18101
|
* @public
|
|
18055
18102
|
*/
|
|
@@ -18066,30 +18113,7 @@ var Cron = class {
|
|
|
18066
18113
|
* @public
|
|
18067
18114
|
*/
|
|
18068
18115
|
static start(options = {}) {
|
|
18069
|
-
setCronFireHandler(
|
|
18070
|
-
const fireTs = Date.now();
|
|
18071
|
-
const taskId = `cron-${job.id}-${fireTs}`;
|
|
18072
|
-
try {
|
|
18073
|
-
await submit({
|
|
18074
|
-
kind: "cron",
|
|
18075
|
-
id: taskId,
|
|
18076
|
-
allowReservedPrefix: true,
|
|
18077
|
-
meta: { jobId: job.id, jobName: job.name, schedule: job.cron, firedAt: fireTs },
|
|
18078
|
-
work: async (ctx) => {
|
|
18079
|
-
const run = await runCronJob(job);
|
|
18080
|
-
ctx.signal.addEventListener("abort", () => void run.cancel().catch(() => {
|
|
18081
|
-
}), {
|
|
18082
|
-
once: true
|
|
18083
|
-
});
|
|
18084
|
-
const result = await run.wait();
|
|
18085
|
-
ctx.emit({ status: result.status, runId: run.id });
|
|
18086
|
-
return { status: result.status, runId: run.id };
|
|
18087
|
-
}
|
|
18088
|
-
});
|
|
18089
|
-
} catch {
|
|
18090
|
-
await runCronJob(job).then((run) => run.wait());
|
|
18091
|
-
}
|
|
18092
|
-
});
|
|
18116
|
+
setCronFireHandler(fireCronJobAsTask);
|
|
18093
18117
|
startScheduler(options.cwd);
|
|
18094
18118
|
return Promise.resolve();
|
|
18095
18119
|
}
|
|
@@ -18113,17 +18137,7 @@ var Cron = class {
|
|
|
18113
18137
|
}
|
|
18114
18138
|
};
|
|
18115
18139
|
async function createCronJob(options) {
|
|
18116
|
-
|
|
18117
|
-
throw new ConfigurationError(
|
|
18118
|
-
"agent and agentId are mutually exclusive \u2014 pass either agent (ephemeral) or agentId (reuse).",
|
|
18119
|
-
{ code: "cron_agent_exclusive" }
|
|
18120
|
-
);
|
|
18121
|
-
}
|
|
18122
|
-
if (options.agent === void 0 && options.agentId === void 0) {
|
|
18123
|
-
throw new ConfigurationError("Cron job requires either agent or agentId", {
|
|
18124
|
-
code: "cron_missing_agent"
|
|
18125
|
-
});
|
|
18126
|
-
}
|
|
18140
|
+
validateCronTarget(options);
|
|
18127
18141
|
validateCronExpression(options.cron);
|
|
18128
18142
|
const timezone = options.timezone ?? "UTC";
|
|
18129
18143
|
validateTimezone(timezone);
|
|
@@ -18134,20 +18148,51 @@ async function createCronJob(options) {
|
|
|
18134
18148
|
id: generateCronId(),
|
|
18135
18149
|
cron: options.cron,
|
|
18136
18150
|
timezone,
|
|
18137
|
-
message: options.message,
|
|
18138
18151
|
enabled: options.enabled ?? true,
|
|
18139
18152
|
status: options.enabled === false ? "paused" : "scheduled",
|
|
18140
18153
|
runtime,
|
|
18141
18154
|
createdAt: now,
|
|
18142
18155
|
nextRunAt: estimateNextRunAt(options.cron),
|
|
18143
18156
|
...options.name !== void 0 ? { name: options.name } : {},
|
|
18157
|
+
...options.message !== void 0 ? { message: options.message } : {},
|
|
18144
18158
|
...options.agent !== void 0 ? { agent: options.agent } : {},
|
|
18145
|
-
...options.agentId !== void 0 ? { agentId: options.agentId } : {}
|
|
18159
|
+
...options.agentId !== void 0 ? { agentId: options.agentId } : {},
|
|
18160
|
+
...options.workflow !== void 0 ? { workflow: options.workflow } : {},
|
|
18161
|
+
...options.inputData !== void 0 ? { inputData: options.inputData } : {}
|
|
18146
18162
|
};
|
|
18147
18163
|
upsertJob(job);
|
|
18148
18164
|
return job;
|
|
18149
18165
|
}
|
|
18166
|
+
function validateCronTarget(options) {
|
|
18167
|
+
const targets = [options.agent, options.agentId, options.workflow].filter(
|
|
18168
|
+
(t) => t !== void 0
|
|
18169
|
+
).length;
|
|
18170
|
+
if (targets > 1) {
|
|
18171
|
+
throw new ConfigurationError(
|
|
18172
|
+
"agent, agentId, and workflow are mutually exclusive \u2014 pass exactly one target.",
|
|
18173
|
+
{ code: "cron_ambiguous_target" }
|
|
18174
|
+
);
|
|
18175
|
+
}
|
|
18176
|
+
if (targets === 0) {
|
|
18177
|
+
throw new ConfigurationError(
|
|
18178
|
+
"Cron job requires exactly one target: agent, agentId, or workflow.",
|
|
18179
|
+
{ code: "cron_no_target" }
|
|
18180
|
+
);
|
|
18181
|
+
}
|
|
18182
|
+
if (options.workflow !== void 0 && options.message !== void 0) {
|
|
18183
|
+
throw new ConfigurationError(
|
|
18184
|
+
"A workflow cron target takes inputData, not a message \u2014 remove `message`.",
|
|
18185
|
+
{ code: "cron_workflow_message" }
|
|
18186
|
+
);
|
|
18187
|
+
}
|
|
18188
|
+
if (options.workflow === void 0 && options.message === void 0) {
|
|
18189
|
+
throw new ConfigurationError("An agent cron target requires a message.", {
|
|
18190
|
+
code: "cron_missing_message"
|
|
18191
|
+
});
|
|
18192
|
+
}
|
|
18193
|
+
}
|
|
18150
18194
|
function detectRuntime(options) {
|
|
18195
|
+
if (options.workflow !== void 0) return "local";
|
|
18151
18196
|
if (options.agentId !== void 0) {
|
|
18152
18197
|
return options.agentId.startsWith("bc-") ? "cloud" : "local";
|
|
18153
18198
|
}
|