@theokit/agents 13.0.0-next.10 → 13.0.0-next.12

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,77 @@
1
1
  # @theokit/agents
2
2
 
3
+ ## 13.0.0-next.12
4
+
5
+ ### Minor Changes
6
+
7
+ - a7e35bb: A guardrail returning `action: 'redact'` with no replacement `text` now throws
8
+ `MalformedGuardrailResultError` instead of silently redacting nothing.
9
+
10
+ `GuardrailResult.text` is optional, so such a guard compiles and reads like a working one. The
11
+ pipeline tested `r.text !== undefined` and moved on, so the caller received the original text and
12
+ believed a guard had run on it — the operator believing a protection is in place when none is.
13
+
14
+ **This is a behaviour change.** A guard relying on the previous no-op will now throw. That is
15
+ deliberate: the alternative is unredacted output reaching a model because a guard was written wrong.
16
+ `text: ''` is unaffected and always was a real redaction — a guard choosing to erase everything.
17
+
18
+ `MalformedGuardrailResultError` is exported from `@theokit/agents`, carries the guard's name and the
19
+ phase, and is not retryable.
20
+
21
+ This also reaches the streaming path (`moderateOutputStream`), which shares the same pipeline: a
22
+ malformed guard there now throws where it previously continued.
23
+
24
+ ### Patch Changes
25
+
26
+ - 2bc27d3: `inheritHooks` no longer lets a member's `transform_tool_result` or `pre_user_send` handler replace
27
+ its parent's — both now chain parent-first, matching the six events that already composed.
28
+
29
+ `inheritHooks` documents its security property as "the parent's refusal is evaluated first, and a
30
+ member can only ever ADD a reason to refuse". For these two events the plain object spread did the
31
+ opposite: a member declaring either handler silently discarded the parent's. The reachable surface is the EXPORTED `inheritHooks`, called with two handler maps.
32
+ `delegate()` passes `undefined` for the member (`agent-orchestrator.ts:175`), so that path composed
33
+ nothing and was never affected — a distinction the first version of this note got wrong.
34
+
35
+ `pre_user_send` composes additively — both contributions reach the model, parent first — because
36
+ `PreUserSendResult` carries only `recalledContext` and the seam exposes no prompt mutation.
37
+
38
+ - eaac7b0: The "will NOT fire" warning for a declared-but-unwired hook event now names where the capability
39
+ already lives, instead of ending "the handler does not exist yet".
40
+
41
+ Two of the three unwired events are served today by purpose-built seams — `Guardrail.checkOutput`
42
+ for `transform_llm_output`, and `createToolHooksPlugin({ processInput })` for `pre_user_send` — so
43
+ the old message told consumers to wait for work that will not come. The third, `on_session_end`, is
44
+ named as genuinely uncovered, with the reason: its handler returns `void` and cannot refuse an
45
+ ending, so wiring it would produce a hook that runs and cannot decide.
46
+
47
+ Nothing is wired. `HOOK_EVENTS`, `WIRED_EVENTS` and `OBSERVATIONAL_EVENTS` keep the same members.
48
+
49
+ - ec899f4: An observational hook handler is now assigned to its own key rather than chosen by comparison.
50
+
51
+ The dispatch loop used a two-branch conditional over a list of two event names, so a third
52
+ observational event would have landed on `post_assistant_reply` — silently, with no test objecting.
53
+ No behaviour changes for the events wired today; the fix removes the trap for the next one added.
54
+
55
+ ## 13.0.0-next.11
56
+
57
+ ### Patch Changes
58
+
59
+ - 5451233: Say, where a consumer can read it, why `CompatSurface` has five names and the SDK's has four
60
+
61
+ `CompatSurface` gained `'commands'` in #704 because this package reads
62
+ `<projectDir>/.claude/commands/*.md` itself. The SDK's own union still has four. A caller who
63
+ builds SDK `local` options directly therefore cannot pass a value of this type, and `TS2345` names
64
+ the mismatch without naming the reason.
65
+
66
+ The explanation existed only in `//` comments, which do not survive into the emitted `.d.ts` — so
67
+ it was invisible to exactly the audience that hits the error. It now lives in the JSDoc block that
68
+ does ship, together with the guidance to derive the SDK's four from this five rather than writing a
69
+ second list by hand: a hand-copied list goes stale the day a surface is added, which is the
70
+ divergence #704 existed to remove.
71
+
72
+ Documentation only; no behaviour changes. Reported by a consumer who hit the compiler error while
73
+ converging four call sites onto one declaration, and who supplied the sentence that was missing.
74
+
3
75
  ## 13.0.0-next.10
4
76
 
5
77
  ### Minor Changes
@@ -1,7 +1,7 @@
1
1
  import { InlineSkill, SystemPromptResolver, SettingSource, MemorySettings, SkillsSettings, ContextSettings } from '@theokit/sdk';
2
2
  import { TheokitAgentError } from '@theokit/sdk/errors';
3
3
  import { R as ReasoningEffort, a as MemoryOptions, P as ProjectContextOptions, M as McpServersMap, H as HumanInTheLoopOptions, C as CheckpointOptions, T as ToolOptions, A as ApprovalOptions, B as BudgetOptions } from './types-C16Wuh9E.js';
4
- import { R as ResolvedCompatSource } from './setting-sources-gate-tadmHT0c.js';
4
+ import { R as ResolvedCompatSource } from './setting-sources-gate-D2NS1GsB.js';
5
5
 
6
6
  /**
7
7
  * M9 (theokit-ai-first) — guardrail contract + typed errors.
@@ -36,15 +36,36 @@ interface Guardrail {
36
36
  }
37
37
  /** Which boundary phase a violation happened in. */
38
38
  type GuardrailPhase = 'input' | 'output';
39
- /** Thrown (fail-fast) when a guard returns `action: 'block'`. Typed per error-handling.md. */
40
39
  /**
41
- * M80 — extends {@link TheokitAgentError}, not plain `Error`.
40
+ * A guard declared `redact` and supplied no replacement text.
42
41
  *
43
- * `isTransientError` is defined over `TheokitAgentError`, so a class outside that hierarchy is
44
- * INVISIBLE to it and the only recourse left to a consumer is matching on message text — a regex
45
- * over an eight-level `cause` chain, which is what one actually wrote. `code` is stable across a
46
- * rename of the class; `isRetryable` is DECLARED rather than defaulted, because a default would be a
47
- * retry policy nobody chose.
42
+ * Distinct from {@link GuardrailViolationError} on purpose: that one says the guard REFUSED
43
+ * something, which is a decision working as designed. This says the guard is MALFORMED — it asked
44
+ * for a redaction and gave nothing to redact with, so nothing was redacted.
45
+ *
46
+ * Until B-008 this condition was silent: `pipeline.ts` tested `r.text !== undefined` and moved on, so
47
+ * the caller received the original text and believed a guard had run on it. That is the shape this
48
+ * package's hook engine calls "worse than no hook at all" — a belief in a protection that is not
49
+ * there. Throwing is fail-fast per `rules/error-handling.md § 2`, and the alternative was leaving
50
+ * unredacted output to reach a model because a guard was written wrong.
51
+ *
52
+ * `''` is NOT this case. An empty replacement is a guard choosing to erase everything, which is the
53
+ * strongest redaction available, and treating it as absent would invert the defect.
54
+ */
55
+ declare class MalformedGuardrailResultError extends TheokitAgentError {
56
+ readonly guardName: string;
57
+ readonly phase: GuardrailPhase;
58
+ readonly name = "MalformedGuardrailResultError";
59
+ constructor(guardName: string, phase: GuardrailPhase);
60
+ }
61
+ /**
62
+ * Thrown (fail-fast) when a guard returns `action: 'block'`. Typed per error-handling.md.
63
+ *
64
+ * M80 — extends {@link TheokitAgentError}, not plain `Error`. `isTransientError` is defined over
65
+ * `TheokitAgentError`, so a class outside that hierarchy is INVISIBLE to it and the only recourse
66
+ * left to a consumer is matching on message text — a regex over an eight-level `cause` chain, which
67
+ * is what one actually wrote. `code` is stable across a rename of the class; `isRetryable` is
68
+ * DECLARED rather than defaulted, because a default would be a retry policy nobody chose.
48
69
  */
49
70
  declare class GuardrailViolationError extends TheokitAgentError {
50
71
  readonly guardName: string;
@@ -299,4 +320,4 @@ interface CompiledAgentOptions {
299
320
  skillsResolver?: SkillsSelection;
300
321
  }
301
322
 
302
- export { type CompiledAgentOptions as C, type Guardrail as G, type HookApprovalGate as H, type SkillsSelection as S, type ToolWalkResult as T, type CompiledTool as a, CostBudgetExceededError as b, type GuardrailAction as c, type GuardrailPhase as d, type GuardrailResult as e, GuardrailViolationError as f, type HookApprovalRequest as g, HookGateUnsupportedError as h, type SkillsRequestContext as i, type ToolboxWalkResult as j, compileTools as k, resolveEnabledSkills as r };
323
+ export { type CompiledAgentOptions as C, type Guardrail as G, type HookApprovalGate as H, MalformedGuardrailResultError as M, type SkillsSelection as S, type ToolWalkResult as T, type CompiledTool as a, CostBudgetExceededError as b, type GuardrailAction as c, type GuardrailPhase as d, type GuardrailResult as e, GuardrailViolationError as f, type HookApprovalRequest as g, HookGateUnsupportedError as h, type SkillsRequestContext as i, type ToolboxWalkResult as j, compileTools as k, resolveEnabledSkills as r };
@@ -1,14 +1,14 @@
1
1
  import { ExecutionContext } from '@theokit/http';
2
2
  import { c as AgentOptions, T as ToolOptions, P as ProjectContextOptions, H as HumanInTheLoopOptions, R as ReasoningEffort, M as McpServersMap } from './types-C16Wuh9E.js';
3
- import { C as CompiledAgentOptions, a as CompiledTool, G as Guardrail, S as SkillsSelection, H as HookApprovalGate } from './agent-compiler-CvYfM-0t.js';
3
+ import { C as CompiledAgentOptions, a as CompiledTool, G as Guardrail, S as SkillsSelection, H as HookApprovalGate } from './agent-compiler-aim29SS_.js';
4
4
  import { SkillsSettings, ContextSettings, SystemPromptResolver, ModelSelection, PluginsSettings, Plugin, ProviderRoutingSettings, AgentDefinition as AgentDefinition$1, BudgetTracker, CustomTool, RunEventSink, MemorySettings } from '@theokit/sdk';
5
- import { S as StreamEvent, f as ApprovalRequiredEvent, a4 as MaskError } from './delegation-scoring-BZdtCdMN.js';
5
+ import { S as StreamEvent, f as ApprovalRequiredEvent, a4 as MaskError } from './delegation-scoring-CNX1SQzT.js';
6
6
  import { RetryOptions } from '@theokit/sdk/retry';
7
7
  import { SandboxPosture } from '@theokit/sdk/sandbox';
8
- import { A as AgentDefinition } from './define-agent-Dp6e7chT.js';
8
+ import { A as AgentDefinition } from './define-agent-Bh3TjozZ.js';
9
9
  import { z } from 'zod';
10
10
  import { H as HookHandlers } from './hook-handlers-Cw2FsnE5.js';
11
- import { S as SettingSourcesSelection } from './setting-sources-gate-tadmHT0c.js';
11
+ import { S as SettingSourcesSelection } from './setting-sources-gate-D2NS1GsB.js';
12
12
  import { WireChunk } from '@theokit/presenter/wire';
13
13
  import { TheokitAgentError } from '@theokit/sdk/errors';
14
14
 
package/dist/bridge.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export { c as APPROVAL_MODES, d as AfterToolCallContext, e as AgentBuilder, f as AgentDefinitionError, g as AgentExecutionContext, h as AgentManifest, A as AgentManifestEntry, i as AgentManifestSource, j as AgentManifestTool, b as AgentModule, k as AgentRoute, l as AgentRouteContext, m as AgentRunInfo, n as AgentsPluginOptions, o as ApiErrorContext, p as ApiErrorDecision, q as ApiErrorPolicy, r as ApprovalMode, a as ApprovalPosture, B as BeforeToolCallContext, u as CompiledContextWindow, v as ContextualTool, D as DefinitionOrThunk, w as DelegationTimeoutError, E as EphemeralAgent, L as LLMCallContext, M as McpApprovalSpec, x as McpFileError, y as McpRegistryConfig, z as McpRequestContext, F as McpSelection, P as ProcessInputContext, G as SdkAgentHandle, I as SdkMessage, J as SdkSendOptions, K as SdkTurnHandle, N as Segment, O as ShouldAutoApproveOptions, T as ToolCallVeto, Q as ToolHooks, R as ToolHooksPlugin, W as WRITE_SCOPED_TOOLS, U as agentsPlugin, V as applyPosture, X as buildModelSelection, Y as compileAgentModule, Z as compileContextWindow, _ as compileLoadedAgentModule, $ as compileProjectContext, a0 as compileSkills, a1 as createAgentExecutionContext, a2 as createApiErrorHandler, a3 as createSdkAgentStream, a4 as createThinkTagExtractor, a5 as createToolHooksPlugin, a6 as extractThinkTagStream, a7 as generateAgentManifest, a8 as generateAgentRoutes, a9 as isAgentContext, aa as loadMcpJson, ab as mcpRegistry, ac as mcpToolApprovals, ad as projectContextMetadataOnlyKnobs, ae as reasoningEffortOf, af as resolveMcpServers, ag as runWithApiErrorHandling, ah as shouldAutoApprove, s as streamAgentUIMessages, ai as toAgentFactory, aj as translateSdkEvent, ak as withClockCap, al as withEphemeralAgent } from './bridge-entry-B3BRB3e_.js';
2
- export { C as CompiledAgentOptions, a as CompiledTool, H as HookApprovalGate, g as HookApprovalRequest, h as HookGateUnsupportedError, T as ToolWalkResult, j as ToolboxWalkResult, k as compileTools } from './agent-compiler-CvYfM-0t.js';
3
- export { A as AgentStopReason, d as AgentStreamEvent, e as AgentTurnMetadata, f as ApprovalRequiredEvent, g as ArtifactChunkEvent, h as ArtifactStartEvent, B as BackgroundDelegation, i as BudgetExceededError, C as CheckpointSavedEvent, k as DelegateFn, a as DelegateOptions, l as DelegationBudgetExceededError, m as DelegationError, n as DelegationPort, c as DelegationResult, D as DelegationTarget, o as DoneEvent, E as ErrorEvent, F as FileEditEvent, I as IterationEvent, P as PartialToolCallEvent, v as RunStartedEvent, w as ScoreVerdict, x as ScoredDelegation, y as Scorer, z as StateUpdateEvent, S as StreamEvent, T as TextDeltaEvent, G as ThinkingEvent, H as ToolCallEvent, J as ToolResultEvent, K as delegate, M as delegateBackground, N as delegateWithScoring, O as isApprovalRequired, Q as isDone, U as isError, V as isPartialToolCall, W as isTextDelta, X as isToolCall, Y as isToolResult, a0 as presentUIMessageStream, a3 as streamAgentResponse } from './delegation-scoring-BZdtCdMN.js';
4
- export { a as AGENT_BRAND, A as AgentDefinition, D as DefineAgentConfig, I as InferAgentInput, b as InferAgentToolNames, c as compileAgentDefinition, i as isAgentDefinition } from './define-agent-Dp6e7chT.js';
5
- export { C as CompatSurface, P as ProjectSettingsGrant, R as ResolvedCompatSource, a as SettingSourceCapability, S as SettingSourcesSelection, U as UntrustedSettingSourceError, r as resolveCompatSources, b as resolveSettingSources } from './setting-sources-gate-tadmHT0c.js';
1
+ export { c as APPROVAL_MODES, d as AfterToolCallContext, e as AgentBuilder, f as AgentDefinitionError, g as AgentExecutionContext, h as AgentManifest, A as AgentManifestEntry, i as AgentManifestSource, j as AgentManifestTool, b as AgentModule, k as AgentRoute, l as AgentRouteContext, m as AgentRunInfo, n as AgentsPluginOptions, o as ApiErrorContext, p as ApiErrorDecision, q as ApiErrorPolicy, r as ApprovalMode, a as ApprovalPosture, B as BeforeToolCallContext, u as CompiledContextWindow, v as ContextualTool, D as DefinitionOrThunk, w as DelegationTimeoutError, E as EphemeralAgent, L as LLMCallContext, M as McpApprovalSpec, x as McpFileError, y as McpRegistryConfig, z as McpRequestContext, F as McpSelection, P as ProcessInputContext, G as SdkAgentHandle, I as SdkMessage, J as SdkSendOptions, K as SdkTurnHandle, N as Segment, O as ShouldAutoApproveOptions, T as ToolCallVeto, Q as ToolHooks, R as ToolHooksPlugin, W as WRITE_SCOPED_TOOLS, U as agentsPlugin, V as applyPosture, X as buildModelSelection, Y as compileAgentModule, Z as compileContextWindow, _ as compileLoadedAgentModule, $ as compileProjectContext, a0 as compileSkills, a1 as createAgentExecutionContext, a2 as createApiErrorHandler, a3 as createSdkAgentStream, a4 as createThinkTagExtractor, a5 as createToolHooksPlugin, a6 as extractThinkTagStream, a7 as generateAgentManifest, a8 as generateAgentRoutes, a9 as isAgentContext, aa as loadMcpJson, ab as mcpRegistry, ac as mcpToolApprovals, ad as projectContextMetadataOnlyKnobs, ae as reasoningEffortOf, af as resolveMcpServers, ag as runWithApiErrorHandling, ah as shouldAutoApprove, s as streamAgentUIMessages, ai as toAgentFactory, aj as translateSdkEvent, ak as withClockCap, al as withEphemeralAgent } from './bridge-entry-D_85aOn3.js';
2
+ export { C as CompiledAgentOptions, a as CompiledTool, H as HookApprovalGate, g as HookApprovalRequest, h as HookGateUnsupportedError, T as ToolWalkResult, j as ToolboxWalkResult, k as compileTools } from './agent-compiler-aim29SS_.js';
3
+ export { A as AgentStopReason, d as AgentStreamEvent, e as AgentTurnMetadata, f as ApprovalRequiredEvent, g as ArtifactChunkEvent, h as ArtifactStartEvent, B as BackgroundDelegation, i as BudgetExceededError, C as CheckpointSavedEvent, k as DelegateFn, a as DelegateOptions, l as DelegationBudgetExceededError, m as DelegationError, n as DelegationPort, c as DelegationResult, D as DelegationTarget, o as DoneEvent, E as ErrorEvent, F as FileEditEvent, I as IterationEvent, P as PartialToolCallEvent, v as RunStartedEvent, w as ScoreVerdict, x as ScoredDelegation, y as Scorer, z as StateUpdateEvent, S as StreamEvent, T as TextDeltaEvent, G as ThinkingEvent, H as ToolCallEvent, J as ToolResultEvent, K as delegate, M as delegateBackground, N as delegateWithScoring, O as isApprovalRequired, Q as isDone, U as isError, V as isPartialToolCall, W as isTextDelta, X as isToolCall, Y as isToolResult, a0 as presentUIMessageStream, a3 as streamAgentResponse } from './delegation-scoring-CNX1SQzT.js';
4
+ export { a as AGENT_BRAND, A as AgentDefinition, D as DefineAgentConfig, I as InferAgentInput, b as InferAgentToolNames, c as compileAgentDefinition, i as isAgentDefinition } from './define-agent-Bh3TjozZ.js';
5
+ export { C as CompatSurface, P as ProjectSettingsGrant, R as ResolvedCompatSource, a as SettingSourceCapability, S as SettingSourcesSelection, U as UntrustedSettingSourceError, r as resolveCompatSources, b as resolveSettingSources } from './setting-sources-gate-D2NS1GsB.js';
6
6
  import '@theokit/http';
7
7
  import './types-C16Wuh9E.js';
8
8
  import '@theokit/sdk';
package/dist/bridge.js CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  runWithApiErrorHandling,
30
30
  streamAgentResponse,
31
31
  streamAgentUIMessages
32
- } from "./chunk-6YJIXBMA.js";
32
+ } from "./chunk-THGIRKEE.js";
33
33
  import {
34
34
  APPROVAL_MODES,
35
35
  BudgetExceededError,
@@ -55,8 +55,8 @@ import {
55
55
  translateSdkEvent,
56
56
  withClockCap,
57
57
  withEphemeralAgent
58
- } from "./chunk-FXQF7LS3.js";
59
- import "./chunk-RKWCXVYG.js";
58
+ } from "./chunk-O3VYC2KJ.js";
59
+ import "./chunk-MJ6FRILJ.js";
60
60
  import {
61
61
  AGENT_BRAND,
62
62
  UntrustedSettingSourceError,
@@ -64,7 +64,7 @@ import {
64
64
  isAgentDefinition,
65
65
  resolveCompatSources,
66
66
  resolveSettingSources
67
- } from "./chunk-43O2CCZR.js";
67
+ } from "./chunk-KTOWSF2S.js";
68
68
  import "./chunk-OXNDJSAJ.js";
69
69
  import "./chunk-Z4QWC7IK.js";
70
70
  export {
@@ -232,4 +232,4 @@ export {
232
232
  compileAgentDefinition,
233
233
  compileSkillsSelection
234
234
  };
235
- //# sourceMappingURL=chunk-43O2CCZR.js.map
235
+ //# sourceMappingURL=chunk-KTOWSF2S.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/bridge/setting-sources-gate.ts","../src/bridge/define-agent.ts"],"mappings":";;;;;AACA,SAASA,yBAAyB;AAgJ3B,IAAMC,8BAAN,cAA0CC,kBAAAA;EAhJjD,OAgJiDA;;;;;EAC7BC,OAAO;EAEzB,YACEC,SAESC,aAEAC,YACT;AACA,UAAMF,OAAAA,GAAAA,KAJGC,cAAAA,aAAAA,KAEAC,aAAAA;EAGX;AACF;AAaO,SAASC,sBACdC,WAA8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AUF,SAAQG,KAAKD,KAAAA;QACvCD,QAAOE,KAAKD,KAAAA;EACnB;AACA,SAAO;IACL1B,QAAQ;MAAEwB;MAASI,YAAY;MAAM,GAAIH,OAAOT,SAAS,IAAI;QAAES;MAAO,IAAI,CAAC;IAAG;EAChF;AACF;AAdgB1B;AAqBhB,SAASD,iBAAiBd,KAAoB;AAC5C,QAAM6C,YAAY,IAAIC,KAAK9C,IAAIK,SAAS,CAAA,GAAIC,IAAI,CAACyC,MAAMA,EAAExD,IAAI,CAAA;AAC7D,QAAMyD,QAAQ,oBAAIC,IAAAA;AAClB,aAAW,CAACC,UAAUC,OAAAA,KAAYtD,OAAO8B,QAAQ3B,IAAIY,aAAa,CAAC,CAAA,GAAI;AACrE,QAAI,CAACiC,UAAUO,IAAIF,QAAAA,GAAW;AAC5B,YAAM,IAAIlE,MACR,mEAAmEkE,QAAAA,sBAC9C;WAAIL;QAAWQ,KAAK,IAAA,KAAS,QAAA,GAAW;IAEjE;AACAL,UAAMM,IAAIJ,UAAUC,OAAAA;EACtB;AACA,SAAOH;AACT;AAbSlC;","names":["TheokitAgentError","UntrustedSettingSourceError","TheokitAgentError","name","message","trustSource","capability","resolveSettingSources","selection","undefined","sources","user","push","grant","project","posture","trustedBy","allows","projectSettings","level","source","resolveCompatSources","claudeCode","surfaces","import","length","kind","AGENT_BRAND","Symbol","for","defineAgent","config","assertValidMaxIterations","maxIterations","value","undefined","Number","isInteger","Error","String","isAgentDefinition","toCompiledTool","tool","handler","compiled","name","description","inputSchema","input","ctx","sym","Object","getOwnPropertySymbols","compileAgentDefinition","def","model","reasoningEffort","systemPrompt","system","tools","map","agents","stream","context","runContext","guardrails","approvals","hitl","compileApprovals","compileSkillsSelection","skills","settingSources","resolveSettingSources","claudeCode","compatSources","resolveCompatSources","hookApproval","memory","compileHooksAndPlugins","mcpServers","hooks","entries","filter","h","explicit","plugins","length","plugin","version","kind","register","hookName","on","skillsResolver","enabled","inline","entry","push","autoInject","toolNames","Set","t","gates","Map","toolName","options","has","join","set"]}
1
+ {"version":3,"sources":["../src/bridge/setting-sources-gate.ts","../src/bridge/define-agent.ts"],"mappings":";;;;;AACA,SAASA,yBAAyB;AAuJ3B,IAAMC,8BAAN,cAA0CC,kBAAAA;EAvJjD,OAuJiDA;;;;;EAC7BC,OAAO;EAEzB,YACEC,SAESC,aAEAC,YACT;AACA,UAAMF,OAAAA,GAAAA,KAJGC,cAAAA,aAAAA,KAEAC,aAAAA;EAGX;AACF;AAaO,SAASC,sBACdC,WAA8C;AAE9C,MAAIA,cAAcC,OAAW,QAAO,CAAA;AAEpC,QAAMC,UAA2B,CAAA;AACjC,MAAIF,UAAUG,SAAS,KAAMD,SAAQE,KAAK,MAAA;AAE1C,QAAMC,QAAQL,UAAUM;AACxB,MAAID,UAAUJ,QAAW;AACvB,UAAMM,UAAUF,MAAMG;AACtB,QAAI,CAACD,QAAQE,OAAOC,iBAAiB;AACnC,YAAM,IAAIjB,4BACR,iKACgEc,QAAQI,KAAK,iBACpEJ,QAAQK,MAAM,wGAEvBL,QAAQK,QACR,iBAAA;IAEJ;AACAV,YAAQE,KAAK,SAAA;EACf;AAEA,SAAOF;AACT;AAzBgBH;AA4CT,SAASc,qBACdb,WAA8C;AAE9C,MAAIA,WAAWc,eAAeb,OAAW,QAAO,CAAA;AAEhD,QAAMM,UAAUP,UAAUc,WAAWN;AACrC,MAAI,CAACD,QAAQE,OAAOC,iBAAiB;AACnC,UAAM,IAAIjB,4BACR,6KAEKc,QAAQI,KAAK,iBAAiBJ,QAAQK,MAAM,oNAGjDL,QAAQK,QACR,iBAAA;EAEJ;AAiBA,QAAMG,WAAWf,UAAUc,WAAWE;AACtC,MAAID,UAAUE,WAAW,GAAG;AAC1B,UAAM,IAAIxB,4BACR,6QAGAO,UAAUc,WAAWN,UAAUI,QAC/B,iBAAA;EAEJ;AACA,MAAIG,aAAad,OAAW,QAAO;IAAC;MAAEiB,MAAM;MAAeF,QAAQ;WAAID;;IAAU;;AACjF,SAAO;IA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;IACF;EACF;AACA,SAAO;IAAE0C,SAAS;SAAID;MAAUG;;EAAQ;AAC1C;AAtBST;AAwBF,SAAST,uBACdC,QAAmC;AAEnC,MAAIA,WAAWnC,OAAW,QAAO,CAAC;AAClC,MAAI,OAAOmC,WAAW,WAAY,QAAO;IAAEuB,gBAAgBvB;EAAO;AAClE,QAAMwB,UAAoB,CAAA;AAC1B,QAAMC,SAAwB,CAAA;AAC9B,aAAWC,SAAS1B,QAAQ;AAC1B,QAAI,OAAO0B,UAAU,SAAUF,SAAQG,KAAKD,KAAAA;QACvCD,QAAOE,KAAKD,KAAAA;EACnB;AACA,SAAO;IACL1B,QAAQ;MAAEwB;MAASI,YAAY;MAAM,GAAIH,OAAOT,SAAS,IAAI;QAAES;MAAO,IAAI,CAAC;IAAG;EAChF;AACF;AAdgB1B;AAqBhB,SAASD,iBAAiBd,KAAoB;AAC5C,QAAM6C,YAAY,IAAIC,KAAK9C,IAAIK,SAAS,CAAA,GAAIC,IAAI,CAACyC,MAAMA,EAAExD,IAAI,CAAA;AAC7D,QAAMyD,QAAQ,oBAAIC,IAAAA;AAClB,aAAW,CAACC,UAAUC,OAAAA,KAAYtD,OAAO8B,QAAQ3B,IAAIY,aAAa,CAAC,CAAA,GAAI;AACrE,QAAI,CAACiC,UAAUO,IAAIF,QAAAA,GAAW;AAC5B,YAAM,IAAIlE,MACR,mEAAmEkE,QAAAA,sBAC9C;WAAIL;QAAWQ,KAAK,IAAA,KAAS,QAAA,GAAW;IAEjE;AACAL,UAAMM,IAAIJ,UAAUC,OAAAA;EACtB;AACA,SAAOH;AACT;AAbSlC;","names":["TheokitAgentError","UntrustedSettingSourceError","TheokitAgentError","name","message","trustSource","capability","resolveSettingSources","selection","undefined","sources","user","push","grant","project","posture","trustedBy","allows","projectSettings","level","source","resolveCompatSources","claudeCode","surfaces","import","length","kind","AGENT_BRAND","Symbol","for","defineAgent","config","assertValidMaxIterations","maxIterations","value","undefined","Number","isInteger","Error","String","isAgentDefinition","toCompiledTool","tool","handler","compiled","name","description","inputSchema","input","ctx","sym","Object","getOwnPropertySymbols","compileAgentDefinition","def","model","reasoningEffort","systemPrompt","system","tools","map","agents","stream","context","runContext","guardrails","approvals","hitl","compileApprovals","compileSkillsSelection","skills","settingSources","resolveSettingSources","claudeCode","compatSources","resolveCompatSources","hookApproval","memory","compileHooksAndPlugins","mcpServers","hooks","entries","filter","h","explicit","plugins","length","plugin","version","kind","register","hookName","on","skillsResolver","enabled","inline","entry","push","autoInject","toolNames","Set","t","gates","Map","toolName","options","has","join","set"]}
@@ -4,7 +4,7 @@ import {
4
4
 
5
5
  // src/bridge/delegation-hooks.ts
6
6
  function bothOf(parent, own) {
7
- return parent !== void 0 && own !== void 0 ? [
7
+ return typeof parent === "function" && typeof own === "function" ? [
8
8
  parent,
9
9
  own
10
10
  ] : void 0;
@@ -60,6 +60,70 @@ function composeObservers(merged, parent, own) {
60
60
  if (reply) merged.post_assistant_reply = chainObserver(reply[0], reply[1]);
61
61
  }
62
62
  __name(composeObservers, "composeObservers");
63
+ function chainRecall(parent, own) {
64
+ return async (ctx) => {
65
+ const parts = [];
66
+ for (const [side, handler] of [
67
+ [
68
+ "parent",
69
+ parent
70
+ ],
71
+ [
72
+ "member",
73
+ own
74
+ ]
75
+ ]) {
76
+ try {
77
+ const text = (await handler(ctx))?.recalledContext;
78
+ if (text !== void 0 && text.length > 0) parts.push(text);
79
+ } catch (cause) {
80
+ console.warn(`[delegation] a ${side} pre_user_send threw; its contribution is lost`, cause);
81
+ }
82
+ }
83
+ return parts.length > 0 ? {
84
+ recalledContext: parts.join("\n\n")
85
+ } : void 0;
86
+ };
87
+ }
88
+ __name(chainRecall, "chainRecall");
89
+ var COMPOSITION = {
90
+ pre_tool_call: "chained",
91
+ post_tool_call: "chained",
92
+ on_session_start: "chained",
93
+ on_session_end: "chained",
94
+ post_assistant_reply: "chained",
95
+ transform_llm_output: "chained",
96
+ transform_tool_result: "chained",
97
+ pre_user_send: "chained"
98
+ };
99
+ var CHAINED_HOOKS = Object.entries(COMPOSITION).filter(([, mode]) => mode === "chained").map(([key]) => key);
100
+ var EXEMPT_HOOKS = Object.entries(COMPOSITION).filter(([, mode]) => mode === "exempt").map(([key]) => key);
101
+ function chainToolResult(parent, own) {
102
+ return async (results, ctx) => {
103
+ let current = results;
104
+ try {
105
+ current = await parent(current, ctx);
106
+ } catch (cause) {
107
+ console.warn(`[delegation] a parent transform_tool_result threw; its change is lost`, cause);
108
+ }
109
+ try {
110
+ return await own(current, ctx);
111
+ } catch (cause) {
112
+ console.warn(`[delegation] a member transform_tool_result threw; the parent's result stands`, cause);
113
+ return current;
114
+ }
115
+ };
116
+ }
117
+ __name(chainToolResult, "chainToolResult");
118
+ function composeTransforms(merged, parent, own) {
119
+ const llm = bothOf(parent?.transform_llm_output, own?.transform_llm_output);
120
+ if (llm) merged.transform_llm_output = chainTransform(llm[0], llm[1]);
121
+ const toolResult = bothOf(parent?.transform_tool_result, own?.transform_tool_result);
122
+ if (toolResult) merged.transform_tool_result = chainToolResult(toolResult[0], toolResult[1]);
123
+ const recall = bothOf(parent?.pre_user_send, own?.pre_user_send);
124
+ if (recall) merged.pre_user_send = chainRecall(recall[0], recall[1]);
125
+ }
126
+ __name(composeTransforms, "composeTransforms");
63
127
  function inheritHooks(parent, own) {
64
128
  const merged = {
65
129
  ...parent ?? {},
@@ -71,9 +135,7 @@ function inheritHooks(parent, own) {
71
135
  ].filter((gate) => gate !== void 0);
72
136
  if (gates.length > 0) merged.pre_tool_call = chainVeto(...gates);
73
137
  composeObservers(merged, parent, own);
74
- if (parent?.transform_llm_output && own?.transform_llm_output) {
75
- merged.transform_llm_output = chainTransform(parent.transform_llm_output, own.transform_llm_output);
76
- }
138
+ composeTransforms(merged, parent, own);
77
139
  return merged;
78
140
  }
79
141
  __name(inheritHooks, "inheritHooks");
@@ -97,4 +159,4 @@ export {
97
159
  inheritHooks,
98
160
  hooksPlugin
99
161
  };
100
- //# sourceMappingURL=chunk-RKWCXVYG.js.map
162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E1C,MAAIE,MAAMgC,SAAS,EAAGf,QAAOmB,gBAAgBrC,UAAAA,GAAaC,KAAAA;AAE1DgB,mBAAiBC,QAAQrB,QAAQC,GAAAA;AAEjCsD,oBAAkBlC,QAAQrB,QAAQC,GAAAA;AAElC,SAAOoB;AACT;AAlBgBsC;AA8BT,SAASC,YAAYC,UAAsB;AAChD,QAAMf,UAAUD,OAAOC,QAAQe,QAAAA,EAAUd,OAAO,CAAC,CAAA,EAAGe,CAAAA,MAAO,OAAOA,MAAM,UAAA;AACxE,MAAIhB,QAAQV,WAAW,EAAG,QAAOlC;AACjC,SAAO;IACL6D,MAAM;IACNC,SAAS;IACTC,MAAM;IACNC,SAAS7D,KAAG;AACV,iBAAW,CAAC8D,UAAUlC,OAAAA,KAAYa,SAAS;AAQzCzC,YAAI+D,GAAGD,UAAUlC,OAAAA;MACnB;IACF;EACF;AACF;AApBgB2B;","names":["bothOf","parent","own","undefined","chainVeto","gates","ctx","gate","decision","cause","reason","Error","message","String","block","chainObserver","observe","console","warn","chainTransform","value","composeObservers","merged","post","post_tool_call","start","on_session_start","end","on_session_end","reply","post_assistant_reply","chainRecall","parts","side","handler","text","recalledContext","length","push","join","COMPOSITION","pre_tool_call","transform_llm_output","transform_tool_result","pre_user_send","CHAINED_HOOKS","Object","entries","filter","mode","map","key","EXEMPT_HOOKS","chainToolResult","results","current","composeTransforms","llm","toolResult","recall","inheritHooks","hooksPlugin","handlers","h","name","version","kind","register","hookName","on"]}
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  hooksPlugin,
3
3
  inheritHooks
4
- } from "./chunk-RKWCXVYG.js";
4
+ } from "./chunk-MJ6FRILJ.js";
5
5
  import {
6
6
  compileAgentDefinition
7
- } from "./chunk-43O2CCZR.js";
7
+ } from "./chunk-KTOWSF2S.js";
8
8
  import {
9
9
  createRunUsageMeter
10
10
  } from "./chunk-OXNDJSAJ.js";
@@ -56,6 +56,21 @@ __name(compileProjectContext, "compileProjectContext");
56
56
 
57
57
  // src/guardrails/types.ts
58
58
  import { TheokitAgentError } from "@theokit/sdk/errors";
59
+ var MalformedGuardrailResultError = class extends TheokitAgentError {
60
+ static {
61
+ __name(this, "MalformedGuardrailResultError");
62
+ }
63
+ guardName;
64
+ phase;
65
+ name = "MalformedGuardrailResultError";
66
+ constructor(guardName, phase) {
67
+ super(`Guardrail "${guardName}" returned action 'redact' for ${phase} with no replacement text. Nothing was redacted. Supply \`text\` (\`''\` erases), or return 'allow' or 'block'.`, {
68
+ code: "GUARDRAIL_RESULT_MALFORMED",
69
+ // A guard written wrong is not written right on the next attempt.
70
+ isRetryable: false
71
+ }), this.guardName = guardName, this.phase = phase;
72
+ }
73
+ };
59
74
  var GuardrailViolationError = class extends TheokitAgentError {
60
75
  static {
61
76
  __name(this, "GuardrailViolationError");
@@ -210,30 +225,30 @@ function outputModeration(options) {
210
225
  __name(outputModeration, "outputModeration");
211
226
 
212
227
  // src/guardrails/pipeline.ts
213
- async function runInputGuards(text, guards) {
228
+ async function runGuards(text, guards, phase) {
229
+ const check = phase === "input" ? "checkInput" : "checkOutput";
214
230
  let current = text;
215
231
  for (const g of guards) {
216
- if (!g.checkInput) continue;
217
- const r = await g.checkInput(current);
232
+ const fn = g[check];
233
+ if (!fn) continue;
234
+ const r = await fn.call(g, current);
218
235
  if (r.action === "block") {
219
- throw new GuardrailViolationError(g.name, "input", r.reason ?? "blocked");
236
+ throw new GuardrailViolationError(g.name, phase, r.reason ?? "blocked");
237
+ }
238
+ if (r.action === "redact") {
239
+ if (r.text === void 0) throw new MalformedGuardrailResultError(g.name, phase);
240
+ current = r.text;
220
241
  }
221
- if (r.action === "redact" && r.text !== void 0) current = r.text;
222
242
  }
223
243
  return current;
224
244
  }
245
+ __name(runGuards, "runGuards");
246
+ async function runInputGuards(text, guards) {
247
+ return runGuards(text, guards, "input");
248
+ }
225
249
  __name(runInputGuards, "runInputGuards");
226
250
  async function runOutputGuards(text, guards) {
227
- let current = text;
228
- for (const g of guards) {
229
- if (!g.checkOutput) continue;
230
- const r = await g.checkOutput(current);
231
- if (r.action === "block") {
232
- throw new GuardrailViolationError(g.name, "output", r.reason ?? "blocked");
233
- }
234
- if (r.action === "redact" && r.text !== void 0) current = r.text;
235
- }
236
- return current;
251
+ return runGuards(text, guards, "output");
237
252
  }
238
253
  __name(runOutputGuards, "runOutputGuards");
239
254
 
@@ -2502,6 +2517,7 @@ __name(delegateWithScoring, "delegateWithScoring");
2502
2517
  export {
2503
2518
  projectContextMetadataOnlyKnobs,
2504
2519
  compileProjectContext,
2520
+ MalformedGuardrailResultError,
2505
2521
  GuardrailViolationError,
2506
2522
  CostBudgetExceededError,
2507
2523
  estimateTokens,
@@ -2553,4 +2569,4 @@ export {
2553
2569
  delegateBackground,
2554
2570
  delegateWithScoring
2555
2571
  };
2556
- //# sourceMappingURL=chunk-FXQF7LS3.js.map
2572
+ //# sourceMappingURL=chunk-O3VYC2KJ.js.map