@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
@@ -60,5 +60,16 @@ export interface DefineToolSpec<T extends ZodType, O extends ZodType = never> {
60
60
  */
61
61
  sanitize?: boolean | SanitizeOptions;
62
62
  }
63
- export declare function defineTool<T extends ZodType, O extends ZodType = never>(spec: DefineToolSpec<T, O>): CustomTool;
63
+ /**
64
+ * SE36 — the uniform `X.create()` namespace API. `Tool.create(spec)` is the sole public
65
+ * constructor for a {@link CustomTool}; it wraps the internal builder so behavior is identical
66
+ * (ADR 0015). A `private constructor` makes `Tool` a namespace, not an instantiable value —
67
+ * `new Tool()` is a compile error. Mirrors `Agent.create` / `Cron.create`.
68
+ *
69
+ * @public
70
+ */
71
+ export declare class Tool {
72
+ private constructor();
73
+ static create<T extends ZodType, O extends ZodType = never>(spec: DefineToolSpec<T, O>): CustomTool;
74
+ }
64
75
  export {};
@@ -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
@@ -19436,6 +19436,13 @@ function deepMergeCloud(base, top) {
19436
19436
  if (base === void 0 && top === void 0) return void 0;
19437
19437
  return { ...base ?? {}, ...top ?? {} };
19438
19438
  }
19439
+ var AgentFactory = class {
19440
+ constructor() {
19441
+ }
19442
+ static create(common) {
19443
+ return createAgentFactory(common);
19444
+ }
19445
+ };
19439
19446
 
19440
19447
  // src/internal/budget/enforcement.ts
19441
19448
  init_errors();
@@ -19873,6 +19880,20 @@ function createTokenLimiter(opts) {
19873
19880
  processOutput: (ctx) => cap2(ctx.text, ctx)
19874
19881
  };
19875
19882
  }
19883
+ var TokenLimiter = class {
19884
+ constructor() {
19885
+ }
19886
+ static create(opts) {
19887
+ return createTokenLimiter(opts);
19888
+ }
19889
+ };
19890
+ var UnicodeNormalizer = class {
19891
+ constructor() {
19892
+ }
19893
+ static create(opts = {}) {
19894
+ return createUnicodeNormalizer(opts);
19895
+ }
19896
+ };
19876
19897
 
19877
19898
  // src/create-skill.ts
19878
19899
  function createSkill(spec) {
@@ -19888,19 +19909,42 @@ function createSkill(spec) {
19888
19909
  ...spec.references !== void 0 ? { references: spec.references } : {}
19889
19910
  };
19890
19911
  }
19912
+ var Skill = class {
19913
+ constructor() {
19914
+ }
19915
+ static create(spec) {
19916
+ return createSkill(spec);
19917
+ }
19918
+ };
19891
19919
 
19892
19920
  // src/cron.ts
19893
19921
  init_errors();
19894
19922
 
19923
+ // src/internal/cron/fire-handler.ts
19924
+ init_registry();
19925
+
19895
19926
  // src/internal/cron/run-job.ts
19896
19927
  init_errors();
19897
19928
  init_agent_factory_registry();
19898
19929
  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
- });
19930
+ if (job.workflow !== void 0) return job.workflow.run(job.inputData);
19931
+ if (job.agent !== void 0) return runWithEphemeralAgent(job.agent, requireMessage(job));
19932
+ if (job.agentId !== void 0) return runWithExistingAgent(job.agentId, requireMessage(job));
19933
+ throw new exports.ConfigurationError(
19934
+ `Cron job ${job.id} has no target (agent, agentId, or workflow) \u2014 cannot run.`,
19935
+ { code: "cron_no_target" }
19936
+ );
19937
+ }
19938
+ function isAgentRun(outcome) {
19939
+ return typeof outcome.wait === "function";
19940
+ }
19941
+ function requireMessage(job) {
19942
+ if (job.message === void 0) {
19943
+ throw new exports.ConfigurationError(`Cron job ${job.id} is an agent target but has no message.`, {
19944
+ code: "cron_missing_message"
19945
+ });
19946
+ }
19947
+ return job.message;
19904
19948
  }
19905
19949
  async function runWithExistingAgent(agentId, message) {
19906
19950
  const info = await getAgentFacade().get(agentId).catch(() => void 0);
@@ -19918,6 +19962,37 @@ async function runWithEphemeralAgent(baseOptions, message) {
19918
19962
  return agent.send(message);
19919
19963
  }
19920
19964
 
19965
+ // src/internal/cron/fire-handler.ts
19966
+ async function fireCronJobAsTask(job) {
19967
+ const fireTs = Date.now();
19968
+ const taskId = `cron-${job.id}-${fireTs}`;
19969
+ try {
19970
+ await submit({
19971
+ kind: "cron",
19972
+ id: taskId,
19973
+ allowReservedPrefix: true,
19974
+ meta: { jobId: job.id, jobName: job.name, schedule: job.cron, firedAt: fireTs },
19975
+ work: async (ctx) => {
19976
+ const outcome = await runCronJob(job);
19977
+ if (isAgentRun(outcome)) {
19978
+ ctx.signal.addEventListener("abort", () => void outcome.cancel().catch(() => {
19979
+ }), {
19980
+ once: true
19981
+ });
19982
+ const result = await outcome.wait();
19983
+ ctx.emit({ status: result.status, runId: outcome.id });
19984
+ return { status: result.status, runId: outcome.id };
19985
+ }
19986
+ ctx.emit({ status: outcome.status, runId: outcome.id });
19987
+ return { status: outcome.status, runId: outcome.id };
19988
+ }
19989
+ });
19990
+ } catch {
19991
+ const outcome = await runCronJob(job);
19992
+ if (isAgentRun(outcome)) await outcome.wait();
19993
+ }
19994
+ }
19995
+
19921
19996
  // src/internal/cron/store.ts
19922
19997
  var jobs = /* @__PURE__ */ new Map();
19923
19998
  function listJobs() {
@@ -20108,7 +20183,6 @@ function estimateNextRunAt(_cron, _timezone) {
20108
20183
  }
20109
20184
 
20110
20185
  // src/cron.ts
20111
- init_registry();
20112
20186
  var Cron = class {
20113
20187
  constructor() {
20114
20188
  }
@@ -20175,7 +20249,8 @@ var Cron = class {
20175
20249
  return updateJobStatus(jobId, false);
20176
20250
  }
20177
20251
  /**
20178
- * Manually trigger a cron job off-schedule. Returns the resulting `Run`.
20252
+ * Manually trigger a cron job off-schedule. Returns the resulting `Run`
20253
+ * (agent target) or `WorkflowRun` (workflow target — SE35).
20179
20254
  *
20180
20255
  * @public
20181
20256
  */
@@ -20192,30 +20267,7 @@ var Cron = class {
20192
20267
  * @public
20193
20268
  */
20194
20269
  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
- });
20270
+ setCronFireHandler(fireCronJobAsTask);
20219
20271
  startScheduler(options.cwd);
20220
20272
  return Promise.resolve();
20221
20273
  }
@@ -20239,17 +20291,7 @@ var Cron = class {
20239
20291
  }
20240
20292
  };
20241
20293
  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
- }
20294
+ validateCronTarget(options);
20253
20295
  validateCronExpression(options.cron);
20254
20296
  const timezone = options.timezone ?? "UTC";
20255
20297
  validateTimezone(timezone);
@@ -20260,20 +20302,51 @@ async function createCronJob(options) {
20260
20302
  id: generateCronId(),
20261
20303
  cron: options.cron,
20262
20304
  timezone,
20263
- message: options.message,
20264
20305
  enabled: options.enabled ?? true,
20265
20306
  status: options.enabled === false ? "paused" : "scheduled",
20266
20307
  runtime,
20267
20308
  createdAt: now,
20268
20309
  nextRunAt: estimateNextRunAt(options.cron),
20269
20310
  ...options.name !== void 0 ? { name: options.name } : {},
20311
+ ...options.message !== void 0 ? { message: options.message } : {},
20270
20312
  ...options.agent !== void 0 ? { agent: options.agent } : {},
20271
- ...options.agentId !== void 0 ? { agentId: options.agentId } : {}
20313
+ ...options.agentId !== void 0 ? { agentId: options.agentId } : {},
20314
+ ...options.workflow !== void 0 ? { workflow: options.workflow } : {},
20315
+ ...options.inputData !== void 0 ? { inputData: options.inputData } : {}
20272
20316
  };
20273
20317
  upsertJob(job);
20274
20318
  return job;
20275
20319
  }
20320
+ function validateCronTarget(options) {
20321
+ const targets = [options.agent, options.agentId, options.workflow].filter(
20322
+ (t) => t !== void 0
20323
+ ).length;
20324
+ if (targets > 1) {
20325
+ throw new exports.ConfigurationError(
20326
+ "agent, agentId, and workflow are mutually exclusive \u2014 pass exactly one target.",
20327
+ { code: "cron_ambiguous_target" }
20328
+ );
20329
+ }
20330
+ if (targets === 0) {
20331
+ throw new exports.ConfigurationError(
20332
+ "Cron job requires exactly one target: agent, agentId, or workflow.",
20333
+ { code: "cron_no_target" }
20334
+ );
20335
+ }
20336
+ if (options.workflow !== void 0 && options.message !== void 0) {
20337
+ throw new exports.ConfigurationError(
20338
+ "A workflow cron target takes inputData, not a message \u2014 remove `message`.",
20339
+ { code: "cron_workflow_message" }
20340
+ );
20341
+ }
20342
+ if (options.workflow === void 0 && options.message === void 0) {
20343
+ throw new exports.ConfigurationError("An agent cron target requires a message.", {
20344
+ code: "cron_missing_message"
20345
+ });
20346
+ }
20347
+ }
20276
20348
  function detectRuntime(options) {
20349
+ if (options.workflow !== void 0) return "local";
20277
20350
  if (options.agentId !== void 0) {
20278
20351
  return options.agentId.startsWith("bc-") ? "cloud" : "local";
20279
20352
  }
@@ -20311,6 +20384,13 @@ function defineProvider(profile, opts) {
20311
20384
  profile
20312
20385
  };
20313
20386
  }
20387
+ var Provider = class {
20388
+ constructor() {
20389
+ }
20390
+ static create(profile, opts) {
20391
+ return defineProvider(profile, opts);
20392
+ }
20393
+ };
20314
20394
 
20315
20395
  // src/define-skill-read-tool.ts
20316
20396
  init_to_json_schema();
@@ -20351,6 +20431,13 @@ function defineSkillReadTool(skills) {
20351
20431
  }
20352
20432
  };
20353
20433
  }
20434
+ var SkillReadTool = class {
20435
+ constructor() {
20436
+ }
20437
+ static create(skills) {
20438
+ return defineSkillReadTool(skills);
20439
+ }
20440
+ };
20354
20441
 
20355
20442
  // src/define-tool.ts
20356
20443
  init_to_json_schema();
@@ -20359,6 +20446,13 @@ function shapeToolResult(spec, out) {
20359
20446
  if (spec.toModelOutput !== void 0) return spec.toModelOutput(validated);
20360
20447
  return typeof validated === "string" ? validated : JSON.stringify(validated);
20361
20448
  }
20449
+ var Tool = class {
20450
+ constructor() {
20451
+ }
20452
+ static create(spec) {
20453
+ return defineTool(spec);
20454
+ }
20455
+ };
20362
20456
  function defineTool(spec) {
20363
20457
  const inputSchema = toJsonSchema(spec.inputSchema, {
20364
20458
  unrepresentable: "any"
@@ -20542,6 +20636,7 @@ init_cwd_mutex();
20542
20636
  function definePlugin(p) {
20543
20637
  return p;
20544
20638
  }
20639
+ var Plugin = { create: definePlugin };
20545
20640
 
20546
20641
  // src/internal/runtime/budget/budget-tracker-counter.ts
20547
20642
  function createCounterBudgetTracker(options = {}) {
@@ -20700,6 +20795,13 @@ function createNoopMemoryProvider() {
20700
20795
  }
20701
20796
  };
20702
20797
  }
20798
+ var NoopMemoryProvider = class {
20799
+ constructor() {
20800
+ }
20801
+ static create() {
20802
+ return createNoopMemoryProvider();
20803
+ }
20804
+ };
20703
20805
  var JobQueue = class {
20704
20806
  jobs = /* @__PURE__ */ new Map();
20705
20807
  controllers = /* @__PURE__ */ new Map();
@@ -21356,6 +21458,13 @@ function createPermissionPlugin(engine, opts = {}) {
21356
21458
  }
21357
21459
  });
21358
21460
  }
21461
+ var PermissionPlugin = class {
21462
+ constructor() {
21463
+ }
21464
+ static create(engine, opts = {}) {
21465
+ return createPermissionPlugin(engine, opts);
21466
+ }
21467
+ };
21359
21468
 
21360
21469
  // src/schema-normalizer.ts
21361
21470
  init_to_json_schema();
@@ -21545,6 +21654,13 @@ function previewOf(text) {
21545
21654
  if (oneLine.length === 0) return void 0;
21546
21655
  return oneLine.length > SUMMARY_PREVIEW_MAX ? `${oneLine.slice(0, SUMMARY_PREVIEW_MAX - 1)}\u2026` : oneLine;
21547
21656
  }
21657
+ var Session = class {
21658
+ constructor() {
21659
+ }
21660
+ static create(storage2) {
21661
+ return createSessionManager(storage2);
21662
+ }
21663
+ };
21548
21664
 
21549
21665
  // src/session-scope.ts
21550
21666
  function scopedConversationId(scope, id) {
@@ -21902,6 +22018,13 @@ function createSquad(options) {
21902
22018
  }
21903
22019
  };
21904
22020
  }
22021
+ var Squad = class {
22022
+ constructor() {
22023
+ }
22024
+ static create(options) {
22025
+ return createSquad(options);
22026
+ }
22027
+ };
21905
22028
 
21906
22029
  // src/index.ts
21907
22030
  init_stream_object();
@@ -22351,35 +22474,35 @@ function safeStringify2(v) {
22351
22474
 
22352
22475
  exports.Agent = Agent;
22353
22476
  exports.AgentBuilder = AgentBuilder;
22477
+ exports.AgentFactory = AgentFactory;
22354
22478
  exports.Budget = Budget;
22355
22479
  exports.Cron = Cron;
22356
22480
  exports.EventBus = EventBus;
22357
22481
  exports.InMemoryConversationStorage = InMemoryConversationStorage;
22358
22482
  exports.JobQueue = JobQueue;
22359
22483
  exports.Memory = Memory;
22484
+ exports.NoopMemoryProvider = NoopMemoryProvider;
22360
22485
  exports.PermissionEngine = PermissionEngine;
22486
+ exports.PermissionPlugin = PermissionPlugin;
22487
+ exports.Plugin = Plugin;
22488
+ exports.Provider = Provider;
22361
22489
  exports.Security = Security;
22490
+ exports.Session = Session;
22491
+ exports.Skill = Skill;
22492
+ exports.SkillReadTool = SkillReadTool;
22493
+ exports.Squad = Squad;
22362
22494
  exports.Task = Task;
22363
22495
  exports.Theokit = Theokit;
22496
+ exports.TokenLimiter = TokenLimiter;
22497
+ exports.Tool = Tool;
22364
22498
  exports.ToolError = ToolError;
22499
+ exports.UnicodeNormalizer = UnicodeNormalizer;
22365
22500
  exports.UsageAccumulator = UsageAccumulator;
22366
22501
  exports.applyMode = applyMode;
22367
22502
  exports.buildReplayHistory = buildReplayHistory;
22368
22503
  exports.chargeAndCheckThresholds = chargeAndCheckThresholds;
22369
22504
  exports.computeCost = computeCost;
22370
- exports.createAgentFactory = createAgentFactory;
22371
22505
  exports.createCounterBudgetTracker = createCounterBudgetTracker;
22372
- exports.createNoopMemoryProvider = createNoopMemoryProvider;
22373
- exports.createPermissionPlugin = createPermissionPlugin;
22374
- exports.createSessionManager = createSessionManager;
22375
- exports.createSkill = createSkill;
22376
- exports.createSquad = createSquad;
22377
- exports.createTokenLimiter = createTokenLimiter;
22378
- exports.createUnicodeNormalizer = createUnicodeNormalizer;
22379
- exports.definePlugin = definePlugin;
22380
- exports.defineProvider = defineProvider;
22381
- exports.defineSkillReadTool = defineSkillReadTool;
22382
- exports.defineTool = defineTool;
22383
22506
  exports.emitRunEvent = emitRunEvent;
22384
22507
  exports.estimateTokens = estimateTokens;
22385
22508
  exports.extractRawId = extractRawId;