@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.
@@ -1,4 +1,4 @@
1
- import { H as RunOperation } from './run-q_P0vHlY.cjs';
1
+ import { H as RunOperation } from './run-CLXKMRgq.cjs';
2
2
 
3
3
  /**
4
4
  * Public type contract for the Budget enforcement primitive
@@ -1,4 +1,4 @@
1
- import { H as RunOperation } from './run-q_P0vHlY.js';
1
+ import { H as RunOperation } from './run-CLXKMRgq.js';
2
2
 
3
3
  /**
4
4
  * Public type contract for the Budget enforcement primitive
package/dist/errors.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, m as ErrorCode, E as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, K as KnownAgentRunErrorCode, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, T as TheokitAgentError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-tP-8O-hR.cjs';
2
- import './run-q_P0vHlY.cjs';
1
+ export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, g as BudgetExceededError, C as ConfigurationError, u as CredentialPoolExhaustedError, m as ErrorCode, E as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, K as KnownAgentRunErrorCode, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, T as TheokitAgentError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-DZpCGlYv.cjs';
2
+ import './run-CLXKMRgq.cjs';
3
3
  import 'zod';
package/dist/index.cjs CHANGED
@@ -19892,15 +19892,31 @@ function createSkill(spec) {
19892
19892
  // src/cron.ts
19893
19893
  init_errors();
19894
19894
 
19895
+ // src/internal/cron/fire-handler.ts
19896
+ init_registry();
19897
+
19895
19898
  // src/internal/cron/run-job.ts
19896
19899
  init_errors();
19897
19900
  init_agent_factory_registry();
19898
19901
  async function runCronJob(job) {
19899
- if (job.agent !== void 0) return runWithEphemeralAgent(job.agent, job.message);
19900
- if (job.agentId !== void 0) return runWithExistingAgent(job.agentId, job.message);
19901
- throw new exports.ConfigurationError(`Cron job ${job.id} has neither agent nor agentId \u2014 cannot run.`, {
19902
- code: "cron_no_target"
19903
- });
19902
+ if (job.workflow !== void 0) return job.workflow.run(job.inputData);
19903
+ if (job.agent !== void 0) return runWithEphemeralAgent(job.agent, requireMessage(job));
19904
+ if (job.agentId !== void 0) return runWithExistingAgent(job.agentId, requireMessage(job));
19905
+ throw new exports.ConfigurationError(
19906
+ `Cron job ${job.id} has no target (agent, agentId, or workflow) \u2014 cannot run.`,
19907
+ { code: "cron_no_target" }
19908
+ );
19909
+ }
19910
+ function isAgentRun(outcome) {
19911
+ return typeof outcome.wait === "function";
19912
+ }
19913
+ function requireMessage(job) {
19914
+ if (job.message === void 0) {
19915
+ throw new exports.ConfigurationError(`Cron job ${job.id} is an agent target but has no message.`, {
19916
+ code: "cron_missing_message"
19917
+ });
19918
+ }
19919
+ return job.message;
19904
19920
  }
19905
19921
  async function runWithExistingAgent(agentId, message) {
19906
19922
  const info = await getAgentFacade().get(agentId).catch(() => void 0);
@@ -19918,6 +19934,37 @@ async function runWithEphemeralAgent(baseOptions, message) {
19918
19934
  return agent.send(message);
19919
19935
  }
19920
19936
 
19937
+ // src/internal/cron/fire-handler.ts
19938
+ async function fireCronJobAsTask(job) {
19939
+ const fireTs = Date.now();
19940
+ const taskId = `cron-${job.id}-${fireTs}`;
19941
+ try {
19942
+ await submit({
19943
+ kind: "cron",
19944
+ id: taskId,
19945
+ allowReservedPrefix: true,
19946
+ meta: { jobId: job.id, jobName: job.name, schedule: job.cron, firedAt: fireTs },
19947
+ work: async (ctx) => {
19948
+ const outcome = await runCronJob(job);
19949
+ if (isAgentRun(outcome)) {
19950
+ ctx.signal.addEventListener("abort", () => void outcome.cancel().catch(() => {
19951
+ }), {
19952
+ once: true
19953
+ });
19954
+ const result = await outcome.wait();
19955
+ ctx.emit({ status: result.status, runId: outcome.id });
19956
+ return { status: result.status, runId: outcome.id };
19957
+ }
19958
+ ctx.emit({ status: outcome.status, runId: outcome.id });
19959
+ return { status: outcome.status, runId: outcome.id };
19960
+ }
19961
+ });
19962
+ } catch {
19963
+ const outcome = await runCronJob(job);
19964
+ if (isAgentRun(outcome)) await outcome.wait();
19965
+ }
19966
+ }
19967
+
19921
19968
  // src/internal/cron/store.ts
19922
19969
  var jobs = /* @__PURE__ */ new Map();
19923
19970
  function listJobs() {
@@ -20108,7 +20155,6 @@ function estimateNextRunAt(_cron, _timezone) {
20108
20155
  }
20109
20156
 
20110
20157
  // src/cron.ts
20111
- init_registry();
20112
20158
  var Cron = class {
20113
20159
  constructor() {
20114
20160
  }
@@ -20175,7 +20221,8 @@ var Cron = class {
20175
20221
  return updateJobStatus(jobId, false);
20176
20222
  }
20177
20223
  /**
20178
- * Manually trigger a cron job off-schedule. Returns the resulting `Run`.
20224
+ * Manually trigger a cron job off-schedule. Returns the resulting `Run`
20225
+ * (agent target) or `WorkflowRun` (workflow target — SE35).
20179
20226
  *
20180
20227
  * @public
20181
20228
  */
@@ -20192,30 +20239,7 @@ var Cron = class {
20192
20239
  * @public
20193
20240
  */
20194
20241
  static start(options = {}) {
20195
- setCronFireHandler(async (job) => {
20196
- const fireTs = Date.now();
20197
- const taskId = `cron-${job.id}-${fireTs}`;
20198
- try {
20199
- await submit({
20200
- kind: "cron",
20201
- id: taskId,
20202
- allowReservedPrefix: true,
20203
- meta: { jobId: job.id, jobName: job.name, schedule: job.cron, firedAt: fireTs },
20204
- work: async (ctx) => {
20205
- const run = await runCronJob(job);
20206
- ctx.signal.addEventListener("abort", () => void run.cancel().catch(() => {
20207
- }), {
20208
- once: true
20209
- });
20210
- const result = await run.wait();
20211
- ctx.emit({ status: result.status, runId: run.id });
20212
- return { status: result.status, runId: run.id };
20213
- }
20214
- });
20215
- } catch {
20216
- await runCronJob(job).then((run) => run.wait());
20217
- }
20218
- });
20242
+ setCronFireHandler(fireCronJobAsTask);
20219
20243
  startScheduler(options.cwd);
20220
20244
  return Promise.resolve();
20221
20245
  }
@@ -20239,17 +20263,7 @@ var Cron = class {
20239
20263
  }
20240
20264
  };
20241
20265
  async function createCronJob(options) {
20242
- if (options.agent !== void 0 && options.agentId !== void 0) {
20243
- throw new exports.ConfigurationError(
20244
- "agent and agentId are mutually exclusive \u2014 pass either agent (ephemeral) or agentId (reuse).",
20245
- { code: "cron_agent_exclusive" }
20246
- );
20247
- }
20248
- if (options.agent === void 0 && options.agentId === void 0) {
20249
- throw new exports.ConfigurationError("Cron job requires either agent or agentId", {
20250
- code: "cron_missing_agent"
20251
- });
20252
- }
20266
+ validateCronTarget(options);
20253
20267
  validateCronExpression(options.cron);
20254
20268
  const timezone = options.timezone ?? "UTC";
20255
20269
  validateTimezone(timezone);
@@ -20260,20 +20274,51 @@ async function createCronJob(options) {
20260
20274
  id: generateCronId(),
20261
20275
  cron: options.cron,
20262
20276
  timezone,
20263
- message: options.message,
20264
20277
  enabled: options.enabled ?? true,
20265
20278
  status: options.enabled === false ? "paused" : "scheduled",
20266
20279
  runtime,
20267
20280
  createdAt: now,
20268
20281
  nextRunAt: estimateNextRunAt(options.cron),
20269
20282
  ...options.name !== void 0 ? { name: options.name } : {},
20283
+ ...options.message !== void 0 ? { message: options.message } : {},
20270
20284
  ...options.agent !== void 0 ? { agent: options.agent } : {},
20271
- ...options.agentId !== void 0 ? { agentId: options.agentId } : {}
20285
+ ...options.agentId !== void 0 ? { agentId: options.agentId } : {},
20286
+ ...options.workflow !== void 0 ? { workflow: options.workflow } : {},
20287
+ ...options.inputData !== void 0 ? { inputData: options.inputData } : {}
20272
20288
  };
20273
20289
  upsertJob(job);
20274
20290
  return job;
20275
20291
  }
20292
+ function validateCronTarget(options) {
20293
+ const targets = [options.agent, options.agentId, options.workflow].filter(
20294
+ (t) => t !== void 0
20295
+ ).length;
20296
+ if (targets > 1) {
20297
+ throw new exports.ConfigurationError(
20298
+ "agent, agentId, and workflow are mutually exclusive \u2014 pass exactly one target.",
20299
+ { code: "cron_ambiguous_target" }
20300
+ );
20301
+ }
20302
+ if (targets === 0) {
20303
+ throw new exports.ConfigurationError(
20304
+ "Cron job requires exactly one target: agent, agentId, or workflow.",
20305
+ { code: "cron_no_target" }
20306
+ );
20307
+ }
20308
+ if (options.workflow !== void 0 && options.message !== void 0) {
20309
+ throw new exports.ConfigurationError(
20310
+ "A workflow cron target takes inputData, not a message \u2014 remove `message`.",
20311
+ { code: "cron_workflow_message" }
20312
+ );
20313
+ }
20314
+ if (options.workflow === void 0 && options.message === void 0) {
20315
+ throw new exports.ConfigurationError("An agent cron target requires a message.", {
20316
+ code: "cron_missing_message"
20317
+ });
20318
+ }
20319
+ }
20276
20320
  function detectRuntime(options) {
20321
+ if (options.workflow !== void 0) return "local";
20277
20322
  if (options.agentId !== void 0) {
20278
20323
  return options.agentId.startsWith("bc-") ? "cloud" : "local";
20279
20324
  }