@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
@@ -0,0 +1,10 @@
1
+ /**
2
+ * SE24 — the guardrail processor runner. Runs an ordered processor pipeline over
3
+ * a string payload (the user message for input, the model's text for output).
4
+ * Each processor may rewrite the payload (return a string), `abort()` (→ a
5
+ * tripwire that short-circuits the rest), or `warn()` (fire `onViolation`,
6
+ * continue). A processor's own bug (a non-abort throw) propagates (fail-fast).
7
+ *
8
+ * @internal
9
+ */
10
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * SE24 — a terminal {@link Run} born from an input-processor `abort()`. It never
3
+ * reached the model: `wait()` resolves to a `cancelled` {@link RunResult}
4
+ * carrying the tripwire; `stream()` yields no content messages. The `tripwire`
5
+ * run-event is emitted by the caller via `SendOptions.onRunEvent` before this
6
+ * run is returned.
7
+ *
8
+ * @internal
9
+ */
10
+ import type { ProcessorTripwire } from "../../../types/processors.js";
11
+ import type { Run } from "../../../types/run.js";
12
+ export declare function createTripwireRun(args: {
13
+ agentId: string;
14
+ tripwire: ProcessorTripwire;
15
+ model: ModelSelection | undefined;
16
+ }): Run;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * SE24 — wrap a {@link Run} so its `wait()` result passes through the output
3
+ * processors before reaching the caller. A processor may redact/rewrite the
4
+ * final text or `abort()` → the result becomes `cancelled` with a tripwire (and
5
+ * a `tripwire` run-event is emitted). Streaming output redaction is deferred
6
+ * (v1 processes the buffered `wait()` path only); a Proxy preserves every other
7
+ * Run member (`stream`, `cancel`, `conversation`, …).
8
+ *
9
+ * @internal
10
+ */
11
+ import type { Run } from "../../../types/run.js";
12
+ import { type RunEventSink } from "../../../types/run-events.js";
13
+ export declare function wrapRunWithOutputProcessors(args: {
14
+ run: Run;
15
+ processors: readonly Processor[];
16
+ agentId: string;
17
+ onRunEvent: RunEventSink | undefined;
18
+ }): Run;
@@ -87,7 +87,17 @@ interface ToolResultGuardOptions {
87
87
  *
88
88
  * @public
89
89
  */
90
- type RunEvent = RunToolProgressEvent | RunRateLimitEvent | RunPermissionDeniedEvent | RunTaskStartedEvent | RunTaskUpdatedEvent | RunTaskCompletedEvent | RunCompactBoundaryEvent;
90
+ type RunEvent = RunToolProgressEvent | RunRateLimitEvent | RunPermissionDeniedEvent | RunTaskStartedEvent | RunTaskUpdatedEvent | RunTaskCompletedEvent | RunCompactBoundaryEvent | RunTripwireEvent;
91
+ /**
92
+ * SE24 — a guardrail processor called `abort()`; the run stops with a tripwire.
93
+ * Delivered via {@link SendOptions.onRunEvent} (mirrors the `RunResult.tripwire`
94
+ * surfaced on `wait()`).
95
+ */
96
+ interface RunTripwireEvent {
97
+ readonly type: "tripwire";
98
+ readonly reason: string;
99
+ readonly processorId: string;
100
+ }
91
101
  /** A tool call is being dispatched (before its result). */
92
102
  interface RunToolProgressEvent {
93
103
  readonly type: "tool_progress";
@@ -154,6 +164,91 @@ type RunEventSink = (event: RunEvent) => void;
154
164
  */
155
165
  declare function emitRunEvent(sink: RunEventSink | undefined, event: RunEvent): void;
156
166
 
167
+ /**
168
+ * SE24 — guardrail processor pipeline. A `Processor` inspects/transforms/blocks
169
+ * the user message (input) or the model's final text (output). Processors run in
170
+ * order; each may rewrite its payload, `abort(reason)` to stop the run (surfaced
171
+ * as {@link RunResult.tripwire} + a `tripwire` run-event), or `warn()` to report
172
+ * a non-blocking violation. The pipeline is provider-agnostic and carries NO LLM
173
+ * — an LLM-classifier processor is the consumer's (delegated, see the guardrails
174
+ * ADR). Mirrors Mastra's `inputProcessors` / `outputProcessors`.
175
+ *
176
+ * @public
177
+ */
178
+ /**
179
+ * A policy violation surfaced to a processor's {@link Processor.onViolation}
180
+ * callback — on `abort()` (blocking) AND on `warn()` (non-blocking).
181
+ *
182
+ * @public
183
+ */
184
+ interface ProcessorViolation {
185
+ processorId: string;
186
+ message: string;
187
+ detail?: unknown;
188
+ }
189
+ /**
190
+ * Controls available to a processor while it runs: `abort()` stops the run with
191
+ * a tripwire; `warn()` reports a non-blocking violation and continues.
192
+ *
193
+ * @public
194
+ */
195
+ interface ProcessorControls {
196
+ /** Stop the run immediately with a tripwire. Throws — code after it never runs. */
197
+ abort(reason: string): never;
198
+ /** Report a non-blocking violation (fires `onViolation`); the run continues. */
199
+ warn(message: string, detail?: unknown): void;
200
+ }
201
+ /** Context passed to {@link Processor.processInput}. @public */
202
+ interface InputProcessorContext extends ProcessorControls {
203
+ /** The user message text for this send. */
204
+ message: string;
205
+ agentId: string;
206
+ }
207
+ /** Context passed to {@link Processor.processOutput}. @public */
208
+ interface OutputProcessorContext extends ProcessorControls {
209
+ /** The model's final assistant text for this run. */
210
+ text: string;
211
+ agentId: string;
212
+ }
213
+ /**
214
+ * A guardrail processor. Provide `processInput` (runs before the LLM) and/or
215
+ * `processOutput` (runs on the final text). A processor's `strategy` (block /
216
+ * rewrite / redact / warn) is expressed via the {@link ProcessorControls}:
217
+ * return the transformed payload to rewrite/redact, `abort()` to block, `warn()`
218
+ * to report without blocking. The core ships no strategy enum — strategies are a
219
+ * processor-level convention over these primitives.
220
+ *
221
+ * @public
222
+ */
223
+ interface Processor {
224
+ /** Stable id — surfaced on {@link ProcessorViolation} and {@link RunResult.tripwire}. */
225
+ id: string;
226
+ /**
227
+ * Transform or block the user message before it reaches the model. Return the
228
+ * (possibly rewritten) text; returning nothing (void) preserves the message
229
+ * unchanged. May be `async`.
230
+ */
231
+ processInput?(ctx: InputProcessorContext): string | Promise<string> | void;
232
+ /**
233
+ * Transform or block the model's final text before it reaches the caller.
234
+ * Return the (possibly redacted) text; returning nothing (void) preserves the
235
+ * text unchanged. May be `async`.
236
+ */
237
+ processOutput?(ctx: OutputProcessorContext): string | Promise<string> | void;
238
+ /** Fires on `abort()` and `warn()`. Errors thrown here are swallowed (never break the pipeline). */
239
+ onViolation?(violation: ProcessorViolation): void;
240
+ }
241
+ /**
242
+ * The tripwire detail attached to {@link RunResult.tripwire} when a processor
243
+ * aborts, and carried by the `tripwire` run-event.
244
+ *
245
+ * @public
246
+ */
247
+ interface ProcessorTripwire {
248
+ reason: string;
249
+ processorId: string;
250
+ }
251
+
157
252
  /**
158
253
  * Type-leaf — primitives shared between `agent.ts`, `run.ts`, and
159
254
  * `messages.ts`. Extracted to break LOW type-only cycles #5 and #7
@@ -886,6 +981,18 @@ interface RunResult {
886
981
  id: string;
887
982
  status: "finished" | "error" | "cancelled";
888
983
  result?: string;
984
+ /**
985
+ * SE24 — set when a guardrail processor called `abort()`. The run stops
986
+ * (`status: "cancelled"`) and `tripwire` carries the blocking reason +
987
+ * processor id. `undefined` on every non-guardrail outcome. A
988
+ * `throwOnError: true` agent resolves normally on a tripwire (status is
989
+ * `"cancelled"`, not `"error"`). On an OUTPUT block the model already ran, so
990
+ * `usage`/`cost` survive (billing) while `result` is suppressed; an INPUT
991
+ * block never reaches the model, so `usage` is absent.
992
+ *
993
+ * @public
994
+ */
995
+ tripwire?: ProcessorTripwire;
889
996
  model?: ModelSelection;
890
997
  durationMs?: number;
891
998
  git?: RunGitInfo;
@@ -1290,4 +1397,4 @@ interface GenerateRunResult<O> {
1290
1397
  };
1291
1398
  }
1292
1399
 
1293
- export { type SendOptions as $, type AgentConversationTurn as A, type RunTaskStartedEvent as B, type CustomTool as C, type DoomLoopThresholds as D, type RunTaskUpdatedEvent as E, type RunToCompletionOptions as F, type GenerateOptions as G, type RunToCompletionResult as H, type ImageBlock as I, type RunToolProgressEvent as J, type SDKAssistantMessage as K, type SDKImage as L, type ModelSelection as M, type SDKImageDimension as N, type SDKObjectDelta as O, type PartialToolCallUpdate as P, type SDKRequestMessage as Q, type RunResult as R, type SDKMessage as S, type ToolResultContentBlock as T, type SDKStatusMessage as U, type SDKSystemMessage as V, type SDKTaskMessage as W, type SDKThinkingMessage as X, type SDKToolUseMessage as Y, type SDKUserMessage as Z, type SDKUserMessageEvent as _, type McpServerConfig as a, type ShellCommand as a0, type ShellConversationTurn as a1, type ShellOutput as a2, type ShellOutputDeltaUpdate as a3, type StepCompletedUpdate as a4, type StepStartedUpdate as a5, type StreamToCompletionResult as a6, type SummaryCompletedUpdate as a7, type SummaryStartedUpdate as a8, type SummaryUpdate as a9, type TextBlock as aa, type TextDeltaUpdate as ab, type ThinkingCompletedUpdate as ac, type ThinkingDeltaUpdate as ad, type ThinkingMessage as ae, type TokenDeltaUpdate as af, type TokenUsage as ag, type ToolCall as ah, type ToolCallCompletedUpdate as ai, type ToolCallStartedUpdate as aj, type ToolContextMessage as ak, type ToolResult as al, type ToolResultGuardOptions as am, type ToolUseBlock as an, type TurnEndedUpdate as ao, type UserMessage as ap, type UserMessageAppendedUpdate as aq, emitRunEvent as ar, type Run as b, type MessageOrigin as c, type AssistantMessage as d, type ConversationStep as e, type ConversationTurn as f, type CostBreakdown as g, type CostSource as h, type CostStatus as i, type GenerateRunResult as j, type InteractionUpdate as k, type McpAuthConfig as l, type McpHttpServerConfig as m, type McpOAuthConfig as n, type McpStdioServerConfig as o, type ModelParameterValue as p, type RunCompactBoundaryEvent as q, type RunErrorDetail as r, type RunEvent as s, type RunEventSink as t, type RunGitInfo as u, type RunOperation as v, type RunPermissionDeniedEvent as w, type RunRateLimitEvent as x, type RunStatus as y, type RunTaskCompletedEvent as z };
1400
+ export { type SDKStatusMessage as $, type AgentConversationTurn as A, type RunOperation as B, type CustomTool as C, type DoomLoopThresholds as D, type RunPermissionDeniedEvent as E, type RunRateLimitEvent as F, type GenerateOptions as G, type RunStatus as H, type ImageBlock as I, type RunTaskCompletedEvent as J, type RunTaskStartedEvent as K, type RunTaskUpdatedEvent as L, type ModelSelection as M, type RunToCompletionOptions as N, type OutputProcessorContext as O, type Processor as P, type RunToCompletionResult as Q, type RunResult as R, type SDKMessage as S, type ToolResultContentBlock as T, type RunToolProgressEvent as U, type RunTripwireEvent as V, type SDKAssistantMessage as W, type SDKImage as X, type SDKImageDimension as Y, type SDKObjectDelta as Z, type SDKRequestMessage as _, type McpServerConfig as a, type SDKSystemMessage as a0, type SDKTaskMessage as a1, type SDKThinkingMessage as a2, type SDKToolUseMessage as a3, type SDKUserMessage as a4, type SDKUserMessageEvent as a5, type SendOptions as a6, type ShellCommand as a7, type ShellConversationTurn as a8, type ShellOutput as a9, type ShellOutputDeltaUpdate as aa, type StepCompletedUpdate as ab, type StepStartedUpdate as ac, type StreamToCompletionResult as ad, type SummaryCompletedUpdate as ae, type SummaryStartedUpdate as af, type SummaryUpdate as ag, type TextBlock as ah, type TextDeltaUpdate as ai, type ThinkingCompletedUpdate as aj, type ThinkingDeltaUpdate as ak, type ThinkingMessage as al, type TokenDeltaUpdate as am, type TokenUsage as an, type ToolCall as ao, type ToolCallCompletedUpdate as ap, type ToolCallStartedUpdate as aq, type ToolContextMessage as ar, type ToolResult as as, type ToolResultGuardOptions as at, type ToolUseBlock as au, type TurnEndedUpdate as av, type UserMessage as aw, type UserMessageAppendedUpdate as ax, emitRunEvent as ay, type Run as b, type MessageOrigin as c, type AssistantMessage as d, type ConversationStep as e, type ConversationTurn as f, type CostBreakdown as g, type CostSource as h, type CostStatus as i, type GenerateRunResult as j, type InputProcessorContext as k, type InteractionUpdate as l, type McpAuthConfig as m, type McpHttpServerConfig as n, type McpOAuthConfig as o, type McpStdioServerConfig as p, type ModelParameterValue as q, type PartialToolCallUpdate as r, type ProcessorControls as s, type ProcessorTripwire as t, type ProcessorViolation as u, type RunCompactBoundaryEvent as v, type RunErrorDetail as w, type RunEvent as x, type RunEventSink as y, type RunGitInfo as z };
@@ -87,7 +87,17 @@ interface ToolResultGuardOptions {
87
87
  *
88
88
  * @public
89
89
  */
90
- type RunEvent = RunToolProgressEvent | RunRateLimitEvent | RunPermissionDeniedEvent | RunTaskStartedEvent | RunTaskUpdatedEvent | RunTaskCompletedEvent | RunCompactBoundaryEvent;
90
+ type RunEvent = RunToolProgressEvent | RunRateLimitEvent | RunPermissionDeniedEvent | RunTaskStartedEvent | RunTaskUpdatedEvent | RunTaskCompletedEvent | RunCompactBoundaryEvent | RunTripwireEvent;
91
+ /**
92
+ * SE24 — a guardrail processor called `abort()`; the run stops with a tripwire.
93
+ * Delivered via {@link SendOptions.onRunEvent} (mirrors the `RunResult.tripwire`
94
+ * surfaced on `wait()`).
95
+ */
96
+ interface RunTripwireEvent {
97
+ readonly type: "tripwire";
98
+ readonly reason: string;
99
+ readonly processorId: string;
100
+ }
91
101
  /** A tool call is being dispatched (before its result). */
92
102
  interface RunToolProgressEvent {
93
103
  readonly type: "tool_progress";
@@ -154,6 +164,91 @@ type RunEventSink = (event: RunEvent) => void;
154
164
  */
155
165
  declare function emitRunEvent(sink: RunEventSink | undefined, event: RunEvent): void;
156
166
 
167
+ /**
168
+ * SE24 — guardrail processor pipeline. A `Processor` inspects/transforms/blocks
169
+ * the user message (input) or the model's final text (output). Processors run in
170
+ * order; each may rewrite its payload, `abort(reason)` to stop the run (surfaced
171
+ * as {@link RunResult.tripwire} + a `tripwire` run-event), or `warn()` to report
172
+ * a non-blocking violation. The pipeline is provider-agnostic and carries NO LLM
173
+ * — an LLM-classifier processor is the consumer's (delegated, see the guardrails
174
+ * ADR). Mirrors Mastra's `inputProcessors` / `outputProcessors`.
175
+ *
176
+ * @public
177
+ */
178
+ /**
179
+ * A policy violation surfaced to a processor's {@link Processor.onViolation}
180
+ * callback — on `abort()` (blocking) AND on `warn()` (non-blocking).
181
+ *
182
+ * @public
183
+ */
184
+ interface ProcessorViolation {
185
+ processorId: string;
186
+ message: string;
187
+ detail?: unknown;
188
+ }
189
+ /**
190
+ * Controls available to a processor while it runs: `abort()` stops the run with
191
+ * a tripwire; `warn()` reports a non-blocking violation and continues.
192
+ *
193
+ * @public
194
+ */
195
+ interface ProcessorControls {
196
+ /** Stop the run immediately with a tripwire. Throws — code after it never runs. */
197
+ abort(reason: string): never;
198
+ /** Report a non-blocking violation (fires `onViolation`); the run continues. */
199
+ warn(message: string, detail?: unknown): void;
200
+ }
201
+ /** Context passed to {@link Processor.processInput}. @public */
202
+ interface InputProcessorContext extends ProcessorControls {
203
+ /** The user message text for this send. */
204
+ message: string;
205
+ agentId: string;
206
+ }
207
+ /** Context passed to {@link Processor.processOutput}. @public */
208
+ interface OutputProcessorContext extends ProcessorControls {
209
+ /** The model's final assistant text for this run. */
210
+ text: string;
211
+ agentId: string;
212
+ }
213
+ /**
214
+ * A guardrail processor. Provide `processInput` (runs before the LLM) and/or
215
+ * `processOutput` (runs on the final text). A processor's `strategy` (block /
216
+ * rewrite / redact / warn) is expressed via the {@link ProcessorControls}:
217
+ * return the transformed payload to rewrite/redact, `abort()` to block, `warn()`
218
+ * to report without blocking. The core ships no strategy enum — strategies are a
219
+ * processor-level convention over these primitives.
220
+ *
221
+ * @public
222
+ */
223
+ interface Processor {
224
+ /** Stable id — surfaced on {@link ProcessorViolation} and {@link RunResult.tripwire}. */
225
+ id: string;
226
+ /**
227
+ * Transform or block the user message before it reaches the model. Return the
228
+ * (possibly rewritten) text; returning nothing (void) preserves the message
229
+ * unchanged. May be `async`.
230
+ */
231
+ processInput?(ctx: InputProcessorContext): string | Promise<string> | void;
232
+ /**
233
+ * Transform or block the model's final text before it reaches the caller.
234
+ * Return the (possibly redacted) text; returning nothing (void) preserves the
235
+ * text unchanged. May be `async`.
236
+ */
237
+ processOutput?(ctx: OutputProcessorContext): string | Promise<string> | void;
238
+ /** Fires on `abort()` and `warn()`. Errors thrown here are swallowed (never break the pipeline). */
239
+ onViolation?(violation: ProcessorViolation): void;
240
+ }
241
+ /**
242
+ * The tripwire detail attached to {@link RunResult.tripwire} when a processor
243
+ * aborts, and carried by the `tripwire` run-event.
244
+ *
245
+ * @public
246
+ */
247
+ interface ProcessorTripwire {
248
+ reason: string;
249
+ processorId: string;
250
+ }
251
+
157
252
  /**
158
253
  * Type-leaf — primitives shared between `agent.ts`, `run.ts`, and
159
254
  * `messages.ts`. Extracted to break LOW type-only cycles #5 and #7
@@ -886,6 +981,18 @@ interface RunResult {
886
981
  id: string;
887
982
  status: "finished" | "error" | "cancelled";
888
983
  result?: string;
984
+ /**
985
+ * SE24 — set when a guardrail processor called `abort()`. The run stops
986
+ * (`status: "cancelled"`) and `tripwire` carries the blocking reason +
987
+ * processor id. `undefined` on every non-guardrail outcome. A
988
+ * `throwOnError: true` agent resolves normally on a tripwire (status is
989
+ * `"cancelled"`, not `"error"`). On an OUTPUT block the model already ran, so
990
+ * `usage`/`cost` survive (billing) while `result` is suppressed; an INPUT
991
+ * block never reaches the model, so `usage` is absent.
992
+ *
993
+ * @public
994
+ */
995
+ tripwire?: ProcessorTripwire;
889
996
  model?: ModelSelection;
890
997
  durationMs?: number;
891
998
  git?: RunGitInfo;
@@ -1290,4 +1397,4 @@ interface GenerateRunResult<O> {
1290
1397
  };
1291
1398
  }
1292
1399
 
1293
- export { type SendOptions as $, type AgentConversationTurn as A, type RunTaskStartedEvent as B, type CustomTool as C, type DoomLoopThresholds as D, type RunTaskUpdatedEvent as E, type RunToCompletionOptions as F, type GenerateOptions as G, type RunToCompletionResult as H, type ImageBlock as I, type RunToolProgressEvent as J, type SDKAssistantMessage as K, type SDKImage as L, type ModelSelection as M, type SDKImageDimension as N, type SDKObjectDelta as O, type PartialToolCallUpdate as P, type SDKRequestMessage as Q, type RunResult as R, type SDKMessage as S, type ToolResultContentBlock as T, type SDKStatusMessage as U, type SDKSystemMessage as V, type SDKTaskMessage as W, type SDKThinkingMessage as X, type SDKToolUseMessage as Y, type SDKUserMessage as Z, type SDKUserMessageEvent as _, type McpServerConfig as a, type ShellCommand as a0, type ShellConversationTurn as a1, type ShellOutput as a2, type ShellOutputDeltaUpdate as a3, type StepCompletedUpdate as a4, type StepStartedUpdate as a5, type StreamToCompletionResult as a6, type SummaryCompletedUpdate as a7, type SummaryStartedUpdate as a8, type SummaryUpdate as a9, type TextBlock as aa, type TextDeltaUpdate as ab, type ThinkingCompletedUpdate as ac, type ThinkingDeltaUpdate as ad, type ThinkingMessage as ae, type TokenDeltaUpdate as af, type TokenUsage as ag, type ToolCall as ah, type ToolCallCompletedUpdate as ai, type ToolCallStartedUpdate as aj, type ToolContextMessage as ak, type ToolResult as al, type ToolResultGuardOptions as am, type ToolUseBlock as an, type TurnEndedUpdate as ao, type UserMessage as ap, type UserMessageAppendedUpdate as aq, emitRunEvent as ar, type Run as b, type MessageOrigin as c, type AssistantMessage as d, type ConversationStep as e, type ConversationTurn as f, type CostBreakdown as g, type CostSource as h, type CostStatus as i, type GenerateRunResult as j, type InteractionUpdate as k, type McpAuthConfig as l, type McpHttpServerConfig as m, type McpOAuthConfig as n, type McpStdioServerConfig as o, type ModelParameterValue as p, type RunCompactBoundaryEvent as q, type RunErrorDetail as r, type RunEvent as s, type RunEventSink as t, type RunGitInfo as u, type RunOperation as v, type RunPermissionDeniedEvent as w, type RunRateLimitEvent as x, type RunStatus as y, type RunTaskCompletedEvent as z };
1400
+ export { type SDKStatusMessage as $, type AgentConversationTurn as A, type RunOperation as B, type CustomTool as C, type DoomLoopThresholds as D, type RunPermissionDeniedEvent as E, type RunRateLimitEvent as F, type GenerateOptions as G, type RunStatus as H, type ImageBlock as I, type RunTaskCompletedEvent as J, type RunTaskStartedEvent as K, type RunTaskUpdatedEvent as L, type ModelSelection as M, type RunToCompletionOptions as N, type OutputProcessorContext as O, type Processor as P, type RunToCompletionResult as Q, type RunResult as R, type SDKMessage as S, type ToolResultContentBlock as T, type RunToolProgressEvent as U, type RunTripwireEvent as V, type SDKAssistantMessage as W, type SDKImage as X, type SDKImageDimension as Y, type SDKObjectDelta as Z, type SDKRequestMessage as _, type McpServerConfig as a, type SDKSystemMessage as a0, type SDKTaskMessage as a1, type SDKThinkingMessage as a2, type SDKToolUseMessage as a3, type SDKUserMessage as a4, type SDKUserMessageEvent as a5, type SendOptions as a6, type ShellCommand as a7, type ShellConversationTurn as a8, type ShellOutput as a9, type ShellOutputDeltaUpdate as aa, type StepCompletedUpdate as ab, type StepStartedUpdate as ac, type StreamToCompletionResult as ad, type SummaryCompletedUpdate as ae, type SummaryStartedUpdate as af, type SummaryUpdate as ag, type TextBlock as ah, type TextDeltaUpdate as ai, type ThinkingCompletedUpdate as aj, type ThinkingDeltaUpdate as ak, type ThinkingMessage as al, type TokenDeltaUpdate as am, type TokenUsage as an, type ToolCall as ao, type ToolCallCompletedUpdate as ap, type ToolCallStartedUpdate as aq, type ToolContextMessage as ar, type ToolResult as as, type ToolResultGuardOptions as at, type ToolUseBlock as au, type TurnEndedUpdate as av, type UserMessage as aw, type UserMessageAppendedUpdate as ax, emitRunEvent as ay, type Run as b, type MessageOrigin as c, type AssistantMessage as d, type ConversationStep as e, type ConversationTurn as f, type CostBreakdown as g, type CostSource as h, type CostStatus as i, type GenerateRunResult as j, type InputProcessorContext as k, type InteractionUpdate as l, type McpAuthConfig as m, type McpHttpServerConfig as n, type McpOAuthConfig as o, type McpStdioServerConfig as p, type ModelParameterValue as q, type PartialToolCallUpdate as r, type ProcessorControls as s, type ProcessorTripwire as t, type ProcessorViolation as u, type RunCompactBoundaryEvent as v, type RunErrorDetail as w, type RunEvent as x, type RunEventSink as y, type RunGitInfo as z };
@@ -392,6 +392,16 @@ export interface AgentOptions {
392
392
  * resolver drives the per-send `<skills>` block.
393
393
  */
394
394
  skills?: SkillsSettings | SkillsResolver;
395
+ /**
396
+ * SE24 — guardrail processors. `inputProcessors` run in order before the LLM
397
+ * (normalize / validate / block / rewrite the user message); `outputProcessors`
398
+ * run on the model's final text before it reaches the caller (redact / block).
399
+ * A processor that `abort()`s stops the run with a {@link RunResult.tripwire}
400
+ * (+ a `tripwire` run-event). Empty/absent ⇒ unchanged behavior. See
401
+ * {@link Processor}.
402
+ */
403
+ inputProcessors?: readonly import("./processors.js").Processor[];
404
+ outputProcessors?: readonly import("./processors.js").Processor[];
395
405
  /** Memory configuration. Persists durable facts; auto-recalled on send. */
396
406
  memory?: MemorySettings;
397
407
  /**
@@ -9,6 +9,7 @@ export type * from "./goal-events.js";
9
9
  export type * from "./mcp.js";
10
10
  export type * from "./memory-adapter.js";
11
11
  export type * from "./messages.js";
12
+ export type * from "./processors.js";
12
13
  export type * from "./providers.js";
13
14
  export type * from "./run.js";
14
15
  export type * from "./session.js";
@@ -0,0 +1,84 @@
1
+ /**
2
+ * SE24 — guardrail processor pipeline. A `Processor` inspects/transforms/blocks
3
+ * the user message (input) or the model's final text (output). Processors run in
4
+ * order; each may rewrite its payload, `abort(reason)` to stop the run (surfaced
5
+ * as {@link RunResult.tripwire} + a `tripwire` run-event), or `warn()` to report
6
+ * a non-blocking violation. The pipeline is provider-agnostic and carries NO LLM
7
+ * — an LLM-classifier processor is the consumer's (delegated, see the guardrails
8
+ * ADR). Mirrors Mastra's `inputProcessors` / `outputProcessors`.
9
+ *
10
+ * @public
11
+ */
12
+ /**
13
+ * A policy violation surfaced to a processor's {@link Processor.onViolation}
14
+ * callback — on `abort()` (blocking) AND on `warn()` (non-blocking).
15
+ *
16
+ * @public
17
+ */
18
+ export interface ProcessorViolation {
19
+ processorId: string;
20
+ message: string;
21
+ detail?: unknown;
22
+ }
23
+ /**
24
+ * Controls available to a processor while it runs: `abort()` stops the run with
25
+ * a tripwire; `warn()` reports a non-blocking violation and continues.
26
+ *
27
+ * @public
28
+ */
29
+ export interface ProcessorControls {
30
+ /** Stop the run immediately with a tripwire. Throws — code after it never runs. */
31
+ abort(reason: string): never;
32
+ /** Report a non-blocking violation (fires `onViolation`); the run continues. */
33
+ warn(message: string, detail?: unknown): void;
34
+ }
35
+ /** Context passed to {@link Processor.processInput}. @public */
36
+ export interface InputProcessorContext extends ProcessorControls {
37
+ /** The user message text for this send. */
38
+ message: string;
39
+ agentId: string;
40
+ }
41
+ /** Context passed to {@link Processor.processOutput}. @public */
42
+ export interface OutputProcessorContext extends ProcessorControls {
43
+ /** The model's final assistant text for this run. */
44
+ text: string;
45
+ agentId: string;
46
+ }
47
+ /**
48
+ * A guardrail processor. Provide `processInput` (runs before the LLM) and/or
49
+ * `processOutput` (runs on the final text). A processor's `strategy` (block /
50
+ * rewrite / redact / warn) is expressed via the {@link ProcessorControls}:
51
+ * return the transformed payload to rewrite/redact, `abort()` to block, `warn()`
52
+ * to report without blocking. The core ships no strategy enum — strategies are a
53
+ * processor-level convention over these primitives.
54
+ *
55
+ * @public
56
+ */
57
+ export interface Processor {
58
+ /** Stable id — surfaced on {@link ProcessorViolation} and {@link RunResult.tripwire}. */
59
+ id: string;
60
+ /**
61
+ * Transform or block the user message before it reaches the model. Return the
62
+ * (possibly rewritten) text; returning nothing (void) preserves the message
63
+ * unchanged. May be `async`.
64
+ */
65
+ processInput?(ctx: InputProcessorContext): string | Promise<string> | void;
66
+ /**
67
+ * Transform or block the model's final text before it reaches the caller.
68
+ * Return the (possibly redacted) text; returning nothing (void) preserves the
69
+ * text unchanged. May be `async`.
70
+ */
71
+ processOutput?(ctx: OutputProcessorContext): string | Promise<string> | void;
72
+ /** Fires on `abort()` and `warn()`. Errors thrown here are swallowed (never break the pipeline). */
73
+ onViolation?(violation: ProcessorViolation): void;
74
+ }
75
+ /**
76
+ * The tripwire detail attached to {@link RunResult.tripwire} when a processor
77
+ * aborts, and carried by the `tripwire` run-event.
78
+ *
79
+ * @public
80
+ */
81
+ export interface ProcessorTripwire {
82
+ reason: string;
83
+ processorId: string;
84
+ }
@@ -16,7 +16,17 @@
16
16
  *
17
17
  * @public
18
18
  */
19
- export type RunEvent = RunToolProgressEvent | RunRateLimitEvent | RunPermissionDeniedEvent | RunTaskStartedEvent | RunTaskUpdatedEvent | RunTaskCompletedEvent | RunCompactBoundaryEvent;
19
+ export type RunEvent = RunToolProgressEvent | RunRateLimitEvent | RunPermissionDeniedEvent | RunTaskStartedEvent | RunTaskUpdatedEvent | RunTaskCompletedEvent | RunCompactBoundaryEvent | RunTripwireEvent;
20
+ /**
21
+ * SE24 — a guardrail processor called `abort()`; the run stops with a tripwire.
22
+ * Delivered via {@link SendOptions.onRunEvent} (mirrors the `RunResult.tripwire`
23
+ * surfaced on `wait()`).
24
+ */
25
+ export interface RunTripwireEvent {
26
+ readonly type: "tripwire";
27
+ readonly reason: string;
28
+ readonly processorId: string;
29
+ }
20
30
  /** A tool call is being dispatched (before its result). */
21
31
  export interface RunToolProgressEvent {
22
32
  readonly type: "tool_progress";
@@ -84,6 +84,18 @@ export interface RunResult {
84
84
  id: string;
85
85
  status: "finished" | "error" | "cancelled";
86
86
  result?: string;
87
+ /**
88
+ * SE24 — set when a guardrail processor called `abort()`. The run stops
89
+ * (`status: "cancelled"`) and `tripwire` carries the blocking reason +
90
+ * processor id. `undefined` on every non-guardrail outcome. A
91
+ * `throwOnError: true` agent resolves normally on a tripwire (status is
92
+ * `"cancelled"`, not `"error"`). On an OUTPUT block the model already ran, so
93
+ * `usage`/`cost` survive (billing) while `result` is suppressed; an INPUT
94
+ * block never reaches the model, so `usage` is absent.
95
+ *
96
+ * @public
97
+ */
98
+ tripwire?: import("./processors.js").ProcessorTripwire;
87
99
  model?: ModelSelection;
88
100
  durationMs?: number;
89
101
  git?: RunGitInfo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theokit/sdk",
3
- "version": "2.25.0",
3
+ "version": "2.26.0",
4
4
  "description": "TypeScript SDK for the Theo agent harness — same surface, local or cloud.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/usetheo/theokit-sdk#readme",