@theokit/sdk 2.29.0 → 3.0.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/a2a/index.cjs +8 -1
  3. package/dist/a2a/index.cjs.map +1 -1
  4. package/dist/a2a/index.d.cts +1 -1
  5. package/dist/a2a/index.d.ts +1 -1
  6. package/dist/a2a/index.js +8 -1
  7. package/dist/a2a/index.js.map +1 -1
  8. package/dist/a2a/subagent.d.cts +5 -1
  9. package/dist/a2a/subagent.d.ts +5 -1
  10. package/dist/agent-factory.d.ts +5 -20
  11. package/dist/concurrency.cjs +10 -1
  12. package/dist/concurrency.cjs.map +1 -1
  13. package/dist/concurrency.d.cts +7 -1
  14. package/dist/concurrency.d.ts +7 -1
  15. package/dist/concurrency.js +10 -1
  16. package/dist/concurrency.js.map +1 -1
  17. package/dist/create-skill.d.ts +7 -7
  18. package/dist/{cron-COSAehOL.d.ts → cron-BLRe166v.d.ts} +392 -31
  19. package/dist/{cron-yJoNUZxe.d.cts → cron-C2jWAvlQ.d.cts} +392 -31
  20. package/dist/cron.cjs +89 -44
  21. package/dist/cron.cjs.map +1 -1
  22. package/dist/cron.d.cts +2 -2
  23. package/dist/cron.d.ts +2 -2
  24. package/dist/cron.js +89 -44
  25. package/dist/cron.js.map +1 -1
  26. package/dist/define-tool.d.ts +12 -1
  27. package/dist/{errors-tP-8O-hR.d.cts → errors-DZpCGlYv.d.cts} +1 -1
  28. package/dist/{errors-BxMIlgLP.d.ts → errors-D_Bfo30u.d.ts} +1 -1
  29. package/dist/errors.d.cts +2 -2
  30. package/dist/index.cjs +179 -56
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +64 -246
  33. package/dist/index.d.ts +64 -246
  34. package/dist/index.js +168 -45
  35. package/dist/index.js.map +1 -1
  36. package/dist/internal/plugins/index.d.cts +1 -1
  37. package/dist/internal/plugins/index.d.ts +1 -1
  38. package/dist/internal/plugins/types.d.cts +4 -0
  39. package/dist/internal/plugins/types.d.ts +4 -0
  40. package/dist/retry.cjs +10 -1
  41. package/dist/retry.cjs.map +1 -1
  42. package/dist/retry.d.cts +12 -1
  43. package/dist/retry.d.ts +12 -1
  44. package/dist/retry.js +10 -1
  45. package/dist/retry.js.map +1 -1
  46. package/dist/{run-q_P0vHlY.d.cts → run-CLXKMRgq.d.cts} +1 -1
  47. package/dist/{run-q_P0vHlY.d.ts → run-CLXKMRgq.d.ts} +1 -1
  48. package/dist/server/auth/index.cjs +8 -1
  49. package/dist/server/auth/index.cjs.map +1 -1
  50. package/dist/server/auth/index.d.cts +1 -1
  51. package/dist/server/auth/index.d.ts +1 -1
  52. package/dist/server/auth/index.js +8 -1
  53. package/dist/server/auth/index.js.map +1 -1
  54. package/dist/server/auth/orchestrator.d.cts +5 -1
  55. package/dist/server/auth/orchestrator.d.ts +5 -1
  56. package/dist/subscription/define-subscription.d.cts +5 -0
  57. package/dist/subscription/define-subscription.d.ts +5 -0
  58. package/dist/subscription/index.cjs +8 -1
  59. package/dist/subscription/index.cjs.map +1 -1
  60. package/dist/subscription/index.d.cts +1 -1
  61. package/dist/subscription/index.d.ts +1 -1
  62. package/dist/subscription/index.js +8 -1
  63. package/dist/subscription/index.js.map +1 -1
  64. package/dist/types/cron.d.ts +30 -13
  65. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -19433,6 +19433,13 @@ function deepMergeCloud(base, top) {
19433
19433
  if (base === void 0 && top === void 0) return void 0;
19434
19434
  return { ...base ?? {}, ...top ?? {} };
19435
19435
  }
19436
+ var AgentFactory = class {
19437
+ constructor() {
19438
+ }
19439
+ static create(common) {
19440
+ return createAgentFactory(common);
19441
+ }
19442
+ };
19436
19443
 
19437
19444
  // src/internal/budget/enforcement.ts
19438
19445
  init_errors();
@@ -19870,6 +19877,20 @@ function createTokenLimiter(opts) {
19870
19877
  processOutput: (ctx) => cap2(ctx.text, ctx)
19871
19878
  };
19872
19879
  }
19880
+ var TokenLimiter = class {
19881
+ constructor() {
19882
+ }
19883
+ static create(opts) {
19884
+ return createTokenLimiter(opts);
19885
+ }
19886
+ };
19887
+ var UnicodeNormalizer = class {
19888
+ constructor() {
19889
+ }
19890
+ static create(opts = {}) {
19891
+ return createUnicodeNormalizer(opts);
19892
+ }
19893
+ };
19873
19894
 
19874
19895
  // src/create-skill.ts
19875
19896
  function createSkill(spec) {
@@ -19885,19 +19906,42 @@ function createSkill(spec) {
19885
19906
  ...spec.references !== void 0 ? { references: spec.references } : {}
19886
19907
  };
19887
19908
  }
19909
+ var Skill = class {
19910
+ constructor() {
19911
+ }
19912
+ static create(spec) {
19913
+ return createSkill(spec);
19914
+ }
19915
+ };
19888
19916
 
19889
19917
  // src/cron.ts
19890
19918
  init_errors();
19891
19919
 
19920
+ // src/internal/cron/fire-handler.ts
19921
+ init_registry();
19922
+
19892
19923
  // src/internal/cron/run-job.ts
19893
19924
  init_errors();
19894
19925
  init_agent_factory_registry();
19895
19926
  async function runCronJob(job) {
19896
- if (job.agent !== void 0) return runWithEphemeralAgent(job.agent, job.message);
19897
- if (job.agentId !== void 0) return runWithExistingAgent(job.agentId, job.message);
19898
- throw new ConfigurationError(`Cron job ${job.id} has neither agent nor agentId \u2014 cannot run.`, {
19899
- code: "cron_no_target"
19900
- });
19927
+ if (job.workflow !== void 0) return job.workflow.run(job.inputData);
19928
+ if (job.agent !== void 0) return runWithEphemeralAgent(job.agent, requireMessage(job));
19929
+ if (job.agentId !== void 0) return runWithExistingAgent(job.agentId, requireMessage(job));
19930
+ throw new ConfigurationError(
19931
+ `Cron job ${job.id} has no target (agent, agentId, or workflow) \u2014 cannot run.`,
19932
+ { code: "cron_no_target" }
19933
+ );
19934
+ }
19935
+ function isAgentRun(outcome) {
19936
+ return typeof outcome.wait === "function";
19937
+ }
19938
+ function requireMessage(job) {
19939
+ if (job.message === void 0) {
19940
+ throw new ConfigurationError(`Cron job ${job.id} is an agent target but has no message.`, {
19941
+ code: "cron_missing_message"
19942
+ });
19943
+ }
19944
+ return job.message;
19901
19945
  }
19902
19946
  async function runWithExistingAgent(agentId, message) {
19903
19947
  const info = await getAgentFacade().get(agentId).catch(() => void 0);
@@ -19915,6 +19959,37 @@ async function runWithEphemeralAgent(baseOptions, message) {
19915
19959
  return agent.send(message);
19916
19960
  }
19917
19961
 
19962
+ // src/internal/cron/fire-handler.ts
19963
+ async function fireCronJobAsTask(job) {
19964
+ const fireTs = Date.now();
19965
+ const taskId = `cron-${job.id}-${fireTs}`;
19966
+ try {
19967
+ await submit({
19968
+ kind: "cron",
19969
+ id: taskId,
19970
+ allowReservedPrefix: true,
19971
+ meta: { jobId: job.id, jobName: job.name, schedule: job.cron, firedAt: fireTs },
19972
+ work: async (ctx) => {
19973
+ const outcome = await runCronJob(job);
19974
+ if (isAgentRun(outcome)) {
19975
+ ctx.signal.addEventListener("abort", () => void outcome.cancel().catch(() => {
19976
+ }), {
19977
+ once: true
19978
+ });
19979
+ const result = await outcome.wait();
19980
+ ctx.emit({ status: result.status, runId: outcome.id });
19981
+ return { status: result.status, runId: outcome.id };
19982
+ }
19983
+ ctx.emit({ status: outcome.status, runId: outcome.id });
19984
+ return { status: outcome.status, runId: outcome.id };
19985
+ }
19986
+ });
19987
+ } catch {
19988
+ const outcome = await runCronJob(job);
19989
+ if (isAgentRun(outcome)) await outcome.wait();
19990
+ }
19991
+ }
19992
+
19918
19993
  // src/internal/cron/store.ts
19919
19994
  var jobs = /* @__PURE__ */ new Map();
19920
19995
  function listJobs() {
@@ -20105,7 +20180,6 @@ function estimateNextRunAt(_cron, _timezone) {
20105
20180
  }
20106
20181
 
20107
20182
  // src/cron.ts
20108
- init_registry();
20109
20183
  var Cron = class {
20110
20184
  constructor() {
20111
20185
  }
@@ -20172,7 +20246,8 @@ var Cron = class {
20172
20246
  return updateJobStatus(jobId, false);
20173
20247
  }
20174
20248
  /**
20175
- * Manually trigger a cron job off-schedule. Returns the resulting `Run`.
20249
+ * Manually trigger a cron job off-schedule. Returns the resulting `Run`
20250
+ * (agent target) or `WorkflowRun` (workflow target — SE35).
20176
20251
  *
20177
20252
  * @public
20178
20253
  */
@@ -20189,30 +20264,7 @@ var Cron = class {
20189
20264
  * @public
20190
20265
  */
20191
20266
  static start(options = {}) {
20192
- setCronFireHandler(async (job) => {
20193
- const fireTs = Date.now();
20194
- const taskId = `cron-${job.id}-${fireTs}`;
20195
- try {
20196
- await submit({
20197
- kind: "cron",
20198
- id: taskId,
20199
- allowReservedPrefix: true,
20200
- meta: { jobId: job.id, jobName: job.name, schedule: job.cron, firedAt: fireTs },
20201
- work: async (ctx) => {
20202
- const run = await runCronJob(job);
20203
- ctx.signal.addEventListener("abort", () => void run.cancel().catch(() => {
20204
- }), {
20205
- once: true
20206
- });
20207
- const result = await run.wait();
20208
- ctx.emit({ status: result.status, runId: run.id });
20209
- return { status: result.status, runId: run.id };
20210
- }
20211
- });
20212
- } catch {
20213
- await runCronJob(job).then((run) => run.wait());
20214
- }
20215
- });
20267
+ setCronFireHandler(fireCronJobAsTask);
20216
20268
  startScheduler(options.cwd);
20217
20269
  return Promise.resolve();
20218
20270
  }
@@ -20236,17 +20288,7 @@ var Cron = class {
20236
20288
  }
20237
20289
  };
20238
20290
  async function createCronJob(options) {
20239
- if (options.agent !== void 0 && options.agentId !== void 0) {
20240
- throw new ConfigurationError(
20241
- "agent and agentId are mutually exclusive \u2014 pass either agent (ephemeral) or agentId (reuse).",
20242
- { code: "cron_agent_exclusive" }
20243
- );
20244
- }
20245
- if (options.agent === void 0 && options.agentId === void 0) {
20246
- throw new ConfigurationError("Cron job requires either agent or agentId", {
20247
- code: "cron_missing_agent"
20248
- });
20249
- }
20291
+ validateCronTarget(options);
20250
20292
  validateCronExpression(options.cron);
20251
20293
  const timezone = options.timezone ?? "UTC";
20252
20294
  validateTimezone(timezone);
@@ -20257,20 +20299,51 @@ async function createCronJob(options) {
20257
20299
  id: generateCronId(),
20258
20300
  cron: options.cron,
20259
20301
  timezone,
20260
- message: options.message,
20261
20302
  enabled: options.enabled ?? true,
20262
20303
  status: options.enabled === false ? "paused" : "scheduled",
20263
20304
  runtime,
20264
20305
  createdAt: now,
20265
20306
  nextRunAt: estimateNextRunAt(options.cron),
20266
20307
  ...options.name !== void 0 ? { name: options.name } : {},
20308
+ ...options.message !== void 0 ? { message: options.message } : {},
20267
20309
  ...options.agent !== void 0 ? { agent: options.agent } : {},
20268
- ...options.agentId !== void 0 ? { agentId: options.agentId } : {}
20310
+ ...options.agentId !== void 0 ? { agentId: options.agentId } : {},
20311
+ ...options.workflow !== void 0 ? { workflow: options.workflow } : {},
20312
+ ...options.inputData !== void 0 ? { inputData: options.inputData } : {}
20269
20313
  };
20270
20314
  upsertJob(job);
20271
20315
  return job;
20272
20316
  }
20317
+ function validateCronTarget(options) {
20318
+ const targets = [options.agent, options.agentId, options.workflow].filter(
20319
+ (t) => t !== void 0
20320
+ ).length;
20321
+ if (targets > 1) {
20322
+ throw new ConfigurationError(
20323
+ "agent, agentId, and workflow are mutually exclusive \u2014 pass exactly one target.",
20324
+ { code: "cron_ambiguous_target" }
20325
+ );
20326
+ }
20327
+ if (targets === 0) {
20328
+ throw new ConfigurationError(
20329
+ "Cron job requires exactly one target: agent, agentId, or workflow.",
20330
+ { code: "cron_no_target" }
20331
+ );
20332
+ }
20333
+ if (options.workflow !== void 0 && options.message !== void 0) {
20334
+ throw new ConfigurationError(
20335
+ "A workflow cron target takes inputData, not a message \u2014 remove `message`.",
20336
+ { code: "cron_workflow_message" }
20337
+ );
20338
+ }
20339
+ if (options.workflow === void 0 && options.message === void 0) {
20340
+ throw new ConfigurationError("An agent cron target requires a message.", {
20341
+ code: "cron_missing_message"
20342
+ });
20343
+ }
20344
+ }
20273
20345
  function detectRuntime(options) {
20346
+ if (options.workflow !== void 0) return "local";
20274
20347
  if (options.agentId !== void 0) {
20275
20348
  return options.agentId.startsWith("bc-") ? "cloud" : "local";
20276
20349
  }
@@ -20308,6 +20381,13 @@ function defineProvider(profile, opts) {
20308
20381
  profile
20309
20382
  };
20310
20383
  }
20384
+ var Provider = class {
20385
+ constructor() {
20386
+ }
20387
+ static create(profile, opts) {
20388
+ return defineProvider(profile, opts);
20389
+ }
20390
+ };
20311
20391
 
20312
20392
  // src/define-skill-read-tool.ts
20313
20393
  init_to_json_schema();
@@ -20348,6 +20428,13 @@ function defineSkillReadTool(skills) {
20348
20428
  }
20349
20429
  };
20350
20430
  }
20431
+ var SkillReadTool = class {
20432
+ constructor() {
20433
+ }
20434
+ static create(skills) {
20435
+ return defineSkillReadTool(skills);
20436
+ }
20437
+ };
20351
20438
 
20352
20439
  // src/define-tool.ts
20353
20440
  init_to_json_schema();
@@ -20356,6 +20443,13 @@ function shapeToolResult(spec, out) {
20356
20443
  if (spec.toModelOutput !== void 0) return spec.toModelOutput(validated);
20357
20444
  return typeof validated === "string" ? validated : JSON.stringify(validated);
20358
20445
  }
20446
+ var Tool = class {
20447
+ constructor() {
20448
+ }
20449
+ static create(spec) {
20450
+ return defineTool(spec);
20451
+ }
20452
+ };
20359
20453
  function defineTool(spec) {
20360
20454
  const inputSchema = toJsonSchema(spec.inputSchema, {
20361
20455
  unrepresentable: "any"
@@ -20539,6 +20633,7 @@ init_cwd_mutex();
20539
20633
  function definePlugin(p) {
20540
20634
  return p;
20541
20635
  }
20636
+ var Plugin = { create: definePlugin };
20542
20637
 
20543
20638
  // src/internal/runtime/budget/budget-tracker-counter.ts
20544
20639
  function createCounterBudgetTracker(options = {}) {
@@ -20697,6 +20792,13 @@ function createNoopMemoryProvider() {
20697
20792
  }
20698
20793
  };
20699
20794
  }
20795
+ var NoopMemoryProvider = class {
20796
+ constructor() {
20797
+ }
20798
+ static create() {
20799
+ return createNoopMemoryProvider();
20800
+ }
20801
+ };
20700
20802
  var JobQueue = class {
20701
20803
  jobs = /* @__PURE__ */ new Map();
20702
20804
  controllers = /* @__PURE__ */ new Map();
@@ -21353,6 +21455,13 @@ function createPermissionPlugin(engine, opts = {}) {
21353
21455
  }
21354
21456
  });
21355
21457
  }
21458
+ var PermissionPlugin = class {
21459
+ constructor() {
21460
+ }
21461
+ static create(engine, opts = {}) {
21462
+ return createPermissionPlugin(engine, opts);
21463
+ }
21464
+ };
21356
21465
 
21357
21466
  // src/schema-normalizer.ts
21358
21467
  init_to_json_schema();
@@ -21542,6 +21651,13 @@ function previewOf(text) {
21542
21651
  if (oneLine.length === 0) return void 0;
21543
21652
  return oneLine.length > SUMMARY_PREVIEW_MAX ? `${oneLine.slice(0, SUMMARY_PREVIEW_MAX - 1)}\u2026` : oneLine;
21544
21653
  }
21654
+ var Session = class {
21655
+ constructor() {
21656
+ }
21657
+ static create(storage2) {
21658
+ return createSessionManager(storage2);
21659
+ }
21660
+ };
21545
21661
 
21546
21662
  // src/session-scope.ts
21547
21663
  function scopedConversationId(scope, id) {
@@ -21899,6 +22015,13 @@ function createSquad(options) {
21899
22015
  }
21900
22016
  };
21901
22017
  }
22018
+ var Squad = class {
22019
+ constructor() {
22020
+ }
22021
+ static create(options) {
22022
+ return createSquad(options);
22023
+ }
22024
+ };
21902
22025
 
21903
22026
  // src/index.ts
21904
22027
  init_stream_object();
@@ -22346,6 +22469,6 @@ function safeStringify2(v) {
22346
22469
  }
22347
22470
  }
22348
22471
 
22349
- export { Agent, AgentBuilder, AgentDisposedError, AgentRunError, AuthenticationError, Budget, BudgetExceededError, ConfigurationError, Cron, EventBus, FileSystemConversationStorage, GenerateObjectError, InMemoryConversationStorage, IntegrationNotConnectedError, InvalidTaskIdError, JobQueue, Memory, MemoryAdapterError, NetworkError, PermissionEngine, RateLimitError, Security, StreamObjectError, Task, TaskNotFoundError, Theokit, TheokitAgentError, ToolError, UnknownAgentError, UnsupportedBudgetOperationError, UnsupportedRunOperationError, UnsupportedTaskOperationError, UsageAccumulator, applyMode, buildReplayHistory, chargeAndCheckThresholds, computeCost, createAgentFactory, createCounterBudgetTracker, createNoopMemoryProvider, createPermissionPlugin, createSessionManager, createSkill, createSquad, createTokenLimiter, createUnicodeNormalizer, definePlugin, defineProvider, defineSkillReadTool, defineTool, emitRunEvent, estimateTokens, extractRawId, getPricingEntry, inferApiMode, isTransientError, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, preflightCheck, scopedConversationId, sessionScopePrefix, toShareGptTrajectory, withCwdMutex };
22472
+ export { Agent, AgentBuilder, AgentDisposedError, AgentFactory, AgentRunError, AuthenticationError, Budget, BudgetExceededError, ConfigurationError, Cron, EventBus, FileSystemConversationStorage, GenerateObjectError, InMemoryConversationStorage, IntegrationNotConnectedError, InvalidTaskIdError, JobQueue, Memory, MemoryAdapterError, NetworkError, NoopMemoryProvider, PermissionEngine, PermissionPlugin, Plugin, Provider, RateLimitError, Security, Session, Skill, SkillReadTool, Squad, StreamObjectError, Task, TaskNotFoundError, Theokit, TheokitAgentError, TokenLimiter, Tool, ToolError, UnicodeNormalizer, UnknownAgentError, UnsupportedBudgetOperationError, UnsupportedRunOperationError, UnsupportedTaskOperationError, UsageAccumulator, applyMode, buildReplayHistory, chargeAndCheckThresholds, computeCost, createCounterBudgetTracker, emitRunEvent, estimateTokens, extractRawId, getPricingEntry, inferApiMode, isTransientError, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, preflightCheck, scopedConversationId, sessionScopePrefix, toShareGptTrajectory, withCwdMutex };
22350
22473
  //# sourceMappingURL=index.js.map
22351
22474
  //# sourceMappingURL=index.js.map