@theokit/sdk 2.25.0 → 2.26.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 (37) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/a2a/index.cjs +208 -4
  3. package/dist/a2a/index.cjs.map +1 -1
  4. package/dist/a2a/index.js +208 -4
  5. package/dist/a2a/index.js.map +1 -1
  6. package/dist/{cron-B44D-678.d.ts → cron-BR1NCSk1.d.cts} +11 -1
  7. package/dist/{cron-qI-dbG7c.d.cts → cron-DgEQCJ2i.d.ts} +11 -1
  8. package/dist/cron.cjs +187 -4
  9. package/dist/cron.cjs.map +1 -1
  10. package/dist/cron.d.cts +2 -2
  11. package/dist/cron.d.ts +2 -2
  12. package/dist/cron.js +187 -4
  13. package/dist/cron.js.map +1 -1
  14. package/dist/{errors-DRS-kqOK.d.ts → errors-CbY3pxY7.d.ts} +1 -1
  15. package/dist/{errors-DIKBXffg.d.cts → errors-DLMNb4Ka.d.cts} +1 -1
  16. package/dist/errors.d.cts +2 -2
  17. package/dist/eval.cjs +187 -4
  18. package/dist/eval.cjs.map +1 -1
  19. package/dist/eval.js +187 -4
  20. package/dist/eval.js.map +1 -1
  21. package/dist/index.cjs +234 -6
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +56 -7
  24. package/dist/index.d.ts +56 -7
  25. package/dist/index.js +232 -7
  26. package/dist/index.js.map +1 -1
  27. package/dist/internal/runtime/processors/run-processors.d.ts +10 -0
  28. package/dist/internal/runtime/processors/tripwire-run.d.ts +16 -0
  29. package/dist/internal/runtime/processors/wrap-output-run.d.ts +18 -0
  30. package/dist/{run-Cr0C6cOM.d.cts → run-CdWiihyU.d.cts} +109 -2
  31. package/dist/{run-Cr0C6cOM.d.ts → run-CdWiihyU.d.ts} +109 -2
  32. package/dist/types/agent.d.ts +10 -0
  33. package/dist/types/index.d.ts +1 -0
  34. package/dist/types/processors.d.ts +84 -0
  35. package/dist/types/run-events.d.ts +11 -1
  36. package/dist/types/run.d.ts +12 -0
  37. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { C as CustomTool, M as ModelSelection, Z as SDKUserMessage, $ as SendOptions, b as Run, G as GenerateOptions, j as GenerateRunResult, F as RunToCompletionOptions, H as RunToCompletionResult, S as SDKMessage, a6 as StreamToCompletionResult, a as McpServerConfig } from './run-Cr0C6cOM.js';
1
+ import { C as CustomTool, M as ModelSelection, a4 as SDKUserMessage, a6 as SendOptions, b as Run, G as GenerateOptions, j as GenerateRunResult, N as RunToCompletionOptions, Q as RunToCompletionResult, S as SDKMessage, ad as StreamToCompletionResult, a as McpServerConfig, P as Processor } from './run-CdWiihyU.cjs';
2
2
  import * as zod from 'zod';
3
3
 
4
4
  /**
@@ -1490,6 +1490,16 @@ interface AgentOptions {
1490
1490
  * resolver drives the per-send `<skills>` block.
1491
1491
  */
1492
1492
  skills?: SkillsSettings | SkillsResolver;
1493
+ /**
1494
+ * SE24 — guardrail processors. `inputProcessors` run in order before the LLM
1495
+ * (normalize / validate / block / rewrite the user message); `outputProcessors`
1496
+ * run on the model's final text before it reaches the caller (redact / block).
1497
+ * A processor that `abort()`s stops the run with a {@link RunResult.tripwire}
1498
+ * (+ a `tripwire` run-event). Empty/absent ⇒ unchanged behavior. See
1499
+ * {@link Processor}.
1500
+ */
1501
+ inputProcessors?: readonly Processor[];
1502
+ outputProcessors?: readonly Processor[];
1493
1503
  /** Memory configuration. Persists durable facts; auto-recalled on send. */
1494
1504
  memory?: MemorySettings;
1495
1505
  /**
@@ -1,4 +1,4 @@
1
- import { C as CustomTool, M as ModelSelection, Z as SDKUserMessage, $ as SendOptions, b as Run, G as GenerateOptions, j as GenerateRunResult, F as RunToCompletionOptions, H as RunToCompletionResult, S as SDKMessage, a6 as StreamToCompletionResult, a as McpServerConfig } from './run-Cr0C6cOM.cjs';
1
+ import { C as CustomTool, M as ModelSelection, a4 as SDKUserMessage, a6 as SendOptions, b as Run, G as GenerateOptions, j as GenerateRunResult, N as RunToCompletionOptions, Q as RunToCompletionResult, S as SDKMessage, ad as StreamToCompletionResult, a as McpServerConfig, P as Processor } from './run-CdWiihyU.js';
2
2
  import * as zod from 'zod';
3
3
 
4
4
  /**
@@ -1490,6 +1490,16 @@ interface AgentOptions {
1490
1490
  * resolver drives the per-send `<skills>` block.
1491
1491
  */
1492
1492
  skills?: SkillsSettings | SkillsResolver;
1493
+ /**
1494
+ * SE24 — guardrail processors. `inputProcessors` run in order before the LLM
1495
+ * (normalize / validate / block / rewrite the user message); `outputProcessors`
1496
+ * run on the model's final text before it reaches the caller (redact / block).
1497
+ * A processor that `abort()`s stops the run with a {@link RunResult.tripwire}
1498
+ * (+ a `tripwire` run-event). Empty/absent ⇒ unchanged behavior. See
1499
+ * {@link Processor}.
1500
+ */
1501
+ inputProcessors?: readonly Processor[];
1502
+ outputProcessors?: readonly Processor[];
1493
1503
  /** Memory configuration. Persists durable facts; auto-recalled on send. */
1494
1504
  memory?: MemorySettings;
1495
1505
  /**
package/dist/cron.cjs CHANGED
@@ -5244,8 +5244,18 @@ function validateCloudToolParity(options) {
5244
5244
  if (options.cloud === void 0) return;
5245
5245
  rejectFunctionSystemPrompt(options);
5246
5246
  rejectFunctionSkills(options);
5247
+ rejectProcessors(options);
5247
5248
  rejectStdioMcpLocalPaths(options);
5248
5249
  }
5250
+ function rejectProcessors(options) {
5251
+ const hasProcessors = (options.inputProcessors?.length ?? 0) > 0 || (options.outputProcessors?.length ?? 0) > 0;
5252
+ if (hasProcessors) {
5253
+ throw new ConfigurationError(
5254
+ "Cloud agents can't run guardrail processors \u2014 a Processor carries function handlers that don't survive serialization to PaaS. Run processors on a local agent, or move the guardrail into a server-side gateway in front of TheoCloud.",
5255
+ { code: "cloud_incompatible_function_resolver" }
5256
+ );
5257
+ }
5258
+ }
5249
5259
  function rejectFunctionSystemPrompt(options) {
5250
5260
  if (typeof options.systemPrompt === "function") {
5251
5261
  throw new ConfigurationError(
@@ -16144,6 +16154,145 @@ function ponyfillAny(signals) {
16144
16154
  return ctrl.signal;
16145
16155
  }
16146
16156
 
16157
+ // src/internal/runtime/processors/run-processors.ts
16158
+ var ProcessorAbort = class {
16159
+ constructor(processorId, reason) {
16160
+ this.processorId = processorId;
16161
+ this.reason = reason;
16162
+ }
16163
+ processorId;
16164
+ reason;
16165
+ };
16166
+ function fireViolation(processor, violation) {
16167
+ try {
16168
+ processor.onViolation?.(violation);
16169
+ } catch {
16170
+ }
16171
+ }
16172
+ function controlsFor(processor) {
16173
+ return {
16174
+ abort(reason) {
16175
+ throw new ProcessorAbort(processor.id, reason);
16176
+ },
16177
+ warn(message, detail) {
16178
+ fireViolation(processor, {
16179
+ processorId: processor.id,
16180
+ message,
16181
+ ...detail !== void 0 ? { detail } : {}
16182
+ });
16183
+ }
16184
+ };
16185
+ }
16186
+ function selectHandler(processor, phase) {
16187
+ if (phase === "input") {
16188
+ return processor.processInput ? { kind: "input", fn: processor.processInput } : void 0;
16189
+ }
16190
+ return processor.processOutput ? { kind: "output", fn: processor.processOutput } : void 0;
16191
+ }
16192
+ function invokeHandler(handler, value, agentId, controls) {
16193
+ return handler.kind === "input" ? handler.fn({ message: value, agentId, ...controls }) : handler.fn({ text: value, agentId, ...controls });
16194
+ }
16195
+ async function runOneProcessor(processor, value, agentId, phase) {
16196
+ const handler = selectHandler(processor, phase);
16197
+ if (handler === void 0) return { value };
16198
+ try {
16199
+ const out = await invokeHandler(handler, value, agentId, controlsFor(processor));
16200
+ return { value: typeof out === "string" ? out : value };
16201
+ } catch (err) {
16202
+ if (!(err instanceof ProcessorAbort)) throw err;
16203
+ fireViolation(processor, { processorId: err.processorId, message: err.reason });
16204
+ return { tripwire: { reason: err.reason, processorId: err.processorId } };
16205
+ }
16206
+ }
16207
+ async function runPipeline(processors, initial, agentId, phase) {
16208
+ let value = initial;
16209
+ for (const processor of processors) {
16210
+ const step = await runOneProcessor(processor, value, agentId, phase);
16211
+ if ("tripwire" in step) return { kind: "tripwire", tripwire: step.tripwire };
16212
+ value = step.value;
16213
+ }
16214
+ return { kind: "ok", value };
16215
+ }
16216
+ function runInputProcessors(processors, message, agentId) {
16217
+ return runPipeline(processors, message, agentId, "input");
16218
+ }
16219
+ function runOutputProcessors(processors, text, agentId) {
16220
+ return runPipeline(processors, text, agentId, "output");
16221
+ }
16222
+
16223
+ // src/internal/runtime/processors/tripwire-run.ts
16224
+ var SUPPORTED = /* @__PURE__ */ new Set([
16225
+ "stream",
16226
+ "wait",
16227
+ "cancel",
16228
+ "conversation"
16229
+ ]);
16230
+ function emptyStream() {
16231
+ return {
16232
+ next: () => Promise.resolve({ done: true, value: void 0 }),
16233
+ return: () => Promise.resolve({ done: true, value: void 0 }),
16234
+ throw: (err) => Promise.reject(err),
16235
+ [Symbol.asyncIterator]() {
16236
+ return this;
16237
+ }
16238
+ };
16239
+ }
16240
+ function createTripwireRun(args) {
16241
+ const id = globalThis.crypto.randomUUID();
16242
+ const result = {
16243
+ id,
16244
+ status: "cancelled",
16245
+ tripwire: args.tripwire,
16246
+ ...args.model !== void 0 ? { model: args.model } : {}
16247
+ };
16248
+ const run = {
16249
+ id,
16250
+ agentId: args.agentId,
16251
+ status: "cancelled",
16252
+ ...args.model !== void 0 ? { model: args.model } : {},
16253
+ stream: () => emptyStream(),
16254
+ wait: () => Promise.resolve(result),
16255
+ cancel: () => Promise.resolve(),
16256
+ conversation: () => Promise.resolve([]),
16257
+ supports: (op) => SUPPORTED.has(op),
16258
+ unsupportedReason: (op) => SUPPORTED.has(op) ? void 0 : `operation "${op}" is not available on a tripwire run`,
16259
+ onDidChangeStatus: () => () => {
16260
+ }
16261
+ // already terminal — status never changes
16262
+ };
16263
+ registerRun(run);
16264
+ return run;
16265
+ }
16266
+
16267
+ // src/internal/runtime/processors/wrap-output-run.ts
16268
+ function wrapRunWithOutputProcessors(args) {
16269
+ if (args.processors.length === 0) return args.run;
16270
+ const compute = async () => {
16271
+ const result = await args.run.wait();
16272
+ if (result.status !== "finished" || result.result === void 0) return result;
16273
+ const res = await runOutputProcessors(args.processors, result.result, args.agentId);
16274
+ if (res.kind === "ok") return { ...result, result: res.value };
16275
+ emitRunEvent(args.onRunEvent, {
16276
+ type: "tripwire",
16277
+ reason: res.tripwire.reason,
16278
+ processorId: res.tripwire.processorId
16279
+ });
16280
+ const { result: _suppressed, ...metadata } = result;
16281
+ return { ...metadata, status: "cancelled", tripwire: res.tripwire };
16282
+ };
16283
+ let processed;
16284
+ const wrappedWait = () => {
16285
+ processed ??= compute();
16286
+ return processed;
16287
+ };
16288
+ return new Proxy(args.run, {
16289
+ get(target, prop, receiver) {
16290
+ if (prop === "wait") return wrappedWait;
16291
+ return Reflect.get(target, prop, receiver);
16292
+ }
16293
+ });
16294
+ }
16295
+
16147
16296
  // src/internal/runtime/local-agent/local-agent-memory-hooks.ts
16148
16297
  var DEFAULT_MAX_RECALL_BYTES = 16e3;
16149
16298
  async function applyPreUserSendHook(args) {
@@ -16191,11 +16340,38 @@ function wrapRunWithPostReplyHook(args) {
16191
16340
  }
16192
16341
 
16193
16342
  // src/internal/runtime/local-agent/local-agent-send.ts
16343
+ async function applyInputProcessors(inputs, message, rawUserText, options, sendModel) {
16344
+ const processors = inputs.options.inputProcessors;
16345
+ if (processors === void 0 || processors.length === 0) {
16346
+ return { userText: rawUserText, effectiveMessage: message };
16347
+ }
16348
+ const res = await runInputProcessors(processors, rawUserText, inputs.agentId);
16349
+ if (res.kind === "tripwire") {
16350
+ emitRunEvent(options.onRunEvent, {
16351
+ type: "tripwire",
16352
+ reason: res.tripwire.reason,
16353
+ processorId: res.tripwire.processorId
16354
+ });
16355
+ return {
16356
+ tripwireRun: createTripwireRun({
16357
+ agentId: inputs.agentId,
16358
+ tripwire: res.tripwire,
16359
+ model: sendModel
16360
+ })
16361
+ };
16362
+ }
16363
+ const effectiveMessage = typeof message === "string" ? res.value : { ...message, text: res.value };
16364
+ return { userText: res.value, effectiveMessage };
16365
+ }
16194
16366
  async function executeSendLocked(inputs, message, options) {
16195
16367
  if (inputs.disposed) throw new AgentDisposedError(inputs.agentId);
16196
16368
  await consumePending(inputs.agentId, inputs.invalidationPending, inputs.clearInvalidation, inputs.reload);
16197
- inputs.applyModelOverride(normalizeModel(options.model));
16198
- const userText = typeof message === "string" ? message : message.text;
16369
+ const sendModel = normalizeModel(options.model);
16370
+ inputs.applyModelOverride(sendModel);
16371
+ const rawUserText = typeof message === "string" ? message : message.text;
16372
+ const gated = await applyInputProcessors(inputs, message, rawUserText, options, sendModel);
16373
+ if ("tripwireRun" in gated) return gated.tripwireRun;
16374
+ const { userText, effectiveMessage } = gated;
16199
16375
  if (inputs.options.onBeforeSend !== void 0) {
16200
16376
  await inputs.options.onBeforeSend({
16201
16377
  conversationId: inputs.agentId,
@@ -16207,7 +16383,7 @@ async function executeSendLocked(inputs, message, options) {
16207
16383
  pluginManager: inputs.pluginManagerCode,
16208
16384
  agentId: inputs.agentId,
16209
16385
  options: inputs.options,
16210
- original: message,
16386
+ original: effectiveMessage,
16211
16387
  userText,
16212
16388
  sendOptions: options
16213
16389
  });
@@ -16245,11 +16421,18 @@ async function executeSendLocked(inputs, message, options) {
16245
16421
  memoryTools,
16246
16422
  effectiveMemoryProvider
16247
16423
  );
16424
+ const outputProcessors = inputs.options.outputProcessors;
16425
+ const processedRun = outputProcessors !== void 0 && outputProcessors.length > 0 ? wrapRunWithOutputProcessors({
16426
+ run,
16427
+ processors: outputProcessors,
16428
+ agentId: inputs.agentId,
16429
+ onRunEvent: options.onRunEvent
16430
+ }) : run;
16248
16431
  return wrapRunWithPostReplyHook({
16249
16432
  pluginManager: inputs.pluginManagerCode,
16250
16433
  agentId: inputs.agentId,
16251
16434
  options: inputs.options,
16252
- run,
16435
+ run: processedRun,
16253
16436
  userText
16254
16437
  });
16255
16438
  }