@theokit/agents 0.47.0 → 1.0.1

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/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { G as Guardrail, R as ReasoningEffort } from './types-DVA4LQsA.js';
2
- export { A as AgentOptions, a as ApprovalOptions, B as BudgetOptions, C as CostBudgetExceededError, b as GuardrailAction, c as GuardrailPhase, d as GuardrailResult, e as GuardrailViolationError, H as HumanInTheLoopOptions, M as MainLoopMeta, f as MainLoopOptions, P as PolicyHandler, T as TimeoutAction, g as ToolOptions, h as ToolboxOptions } from './types-DVA4LQsA.js';
3
- import { L as LoopStrategy, R as ReflectionStrategy, C as CompiledAgentOptions, a as CompiledTool, b as RoundStreamFactory, S as StreamEvent, D as DelegationResult, A as AgentManifestEntry } from './bridge-entry-BQ6UUSLZ.js';
4
- export { c as AGENT_BRAND, d as AfterToolCallContext, e as AgentBuilder, f as AgentDefinition, g as AgentDefinitionError, h as AgentExecutionContext, i as AgentManifest, j as AgentManifestTool, k as AgentRoute, l as AgentRouteContext, m as AgentRunInfo, n as AgentStreamEvent, o as AgentTurnMetadata, p as AgentWalkResult, q as AgentWarningCode, r as AgentsPluginOptions, s as ApiErrorContext, t as ApiErrorDecision, u as ApiErrorPolicy, v as ApprovalRequiredEvent, w as ArtifactChunkEvent, x as ArtifactStartEvent, B as BackgroundDelegation, y as BeforeToolCallContext, z as BudgetExceededError, E as CheckpointSavedEvent, F as CompiledContextWindow, G as ContextualTool, H as DEFAULT_MAX_ITERATIONS, I as DefineAgentConfig, J as DelegateFn, K as DelegateOptions, M as DelegationError, N as DoneEvent, O as ErrorEvent, P as FileEditEvent, Q as HitlDecision, T as InferAgentInput, U as InferAgentToolNames, V as IterationEvent, W as LLMCallContext, X as LoopFinishReason, Y as LoopOutcome, Z as LoopStrategyConfig, _ as McpApprovalSpec, $ as McpRegistryConfig, a0 as McpRequestContext, a1 as McpSelection, a2 as PartialToolCallEvent, a3 as ProcessInputContext, a4 as ReflectionContext, a5 as ReflectionResult, a6 as ReflectionStrategyConfig, a7 as RunStartedEvent, a8 as ScoreVerdict, a9 as ScoredDelegation, aa as Scorer, ab as SdkAgentHandle, ac as SdkMessage, ad as Segment, ae as SkillsRequestContext, af as SkillsSelection, ag as StateUpdateEvent, ah as TextDeltaEvent, ai as ThinkingEvent, aj as ToolCallEvent, ak as ToolCallVeto, al as ToolHooks, am as ToolHooksPlugin, an as ToolResultEvent, ao as ToolWalkResult, ap as ToolboxWalkResult, aq as agent, ar as agentsPlugin, as as buildModelSelection, at as compileAgent, au as compileAgentDefinition, av as compileAgentModule, aw as compileContextWindow, ax as compileProjectContext, ay as compileSkills, az as compileTools, aA as contextualTool, aB as createAgentExecutionContext, aC as createApiErrorHandler, aD as createSdkAgentStream, aE as createThinkTagExtractor, aF as createToolHooksPlugin, aG as delegate, aH as delegateBackground, aI as delegateWithScoring, aJ as extractThinkTagStream, aK as generateAgentManifest, aL as generateAgentRoutes, aM as isAgentContext, aN as isAgentDefinition, aO as isApprovalRequired, aP as isDone, aQ as isError, aR as isPartialToolCall, aS as isTextDelta, aT as isToolCall, aU as isToolResult, aV as ladderReflectionStrategy, aW as loopStrategyConfigSchema, aX as mcpRegistry, aY as mcpToolApprovals, aZ as noopReflectionStrategy, a_ as presentUIMessageStream, a$ as projectContextMetadataOnlyKnobs, b0 as reflectionStrategyConfigSchema, b1 as resolveEnabledSkills, b2 as resolveLoopStrategy, b3 as resolveMcpServers, b4 as runWithApiErrorHandling, b5 as streamAgentResponse, b6 as streamAgentUIMessages, b7 as toAgentFactory, b8 as translateSdkEvent, b9 as validateUniqueRoutes, ba as walkAgentMetadata } from './bridge-entry-BQ6UUSLZ.js';
1
+ import { G as Guardrail, L as LoopStrategy, R as ReflectionStrategy, C as CompiledAgentOptions, M as MainLoopMeta, a as CompiledTool, b as ReasoningEffort, c as RoundStreamFactory, S as StreamEvent, D as DelegationResult, d as ContextWindowOptions, H as HumanInTheLoopOptions, e as McpServersMap, f as MemoryOptions, P as ProjectContextOptions, g as SkillsOptions, h as SkillsSelection, T as ToolOptions, A as ApprovalOptions, i as AgentManifestEntry } from './bridge-entry-F9kHGaIn.js';
2
+ export { j as AGENT_BRAND, k as AfterToolCallContext, l as AgentBuilder, m as AgentDefinition, n as AgentDefinitionError, o as AgentExecutionContext, p as AgentManifest, q as AgentManifestSource, r as AgentManifestTool, s as AgentOptions, t as AgentRoute, u as AgentRouteContext, v as AgentRunInfo, w as AgentStreamEvent, x as AgentTurnMetadata, y as AgentsPluginOptions, z as ApiErrorContext, B as ApiErrorDecision, E as ApiErrorPolicy, F as ApprovalRequiredEvent, I as ArtifactChunkEvent, J as ArtifactStartEvent, K as BackgroundDelegation, N as BeforeToolCallContext, O as BudgetExceededError, Q as BudgetOptions, U as CheckpointSavedEvent, V as CompiledContextWindow, W as ContextualTool, X as CostBudgetExceededError, Y as DEFAULT_MAX_ITERATIONS, Z as DefineAgentConfig, _ as DelegateFn, $ as DelegateOptions, a0 as DelegationError, a1 as DoneEvent, a2 as ErrorEvent, a3 as FileEditEvent, a4 as GuardrailAction, a5 as GuardrailPhase, a6 as GuardrailResult, a7 as GuardrailViolationError, a8 as HitlDecision, a9 as InferAgentInput, aa as InferAgentToolNames, ab as IterationEvent, ac as LLMCallContext, ad as LoopFinishReason, ae as LoopOutcome, af as LoopStrategyConfig, ag as MainLoopOptions, ah as McpApprovalSpec, ai as McpRegistryConfig, aj as McpRequestContext, ak as McpSelection, al as PartialToolCallEvent, am as PolicyHandler, an as ProcessInputContext, ao as ReflectionContext, ap as ReflectionResult, aq as ReflectionStrategyConfig, ar as RunStartedEvent, as as ScoreVerdict, at as ScoredDelegation, au as Scorer, av as SdkAgentHandle, aw as SdkMessage, ax as Segment, ay as SkillsRequestContext, az as StateUpdateEvent, aA as TextDeltaEvent, aB as ThinkingEvent, aC as TimeoutAction, aD as ToolCallEvent, aE as ToolCallVeto, aF as ToolHooks, aG as ToolHooksPlugin, aH as ToolResultEvent, aI as ToolWalkResult, aJ as ToolboxOptions, aK as ToolboxWalkResult, aL as agent, aM as agentsPlugin, aN as buildModelSelection, aO as compileAgentDefinition, aP as compileAgentModule, aQ as compileContextWindow, aR as compileProjectContext, aS as compileSkills, aT as compileTools, aU as contextualTool, aV as createAgentExecutionContext, aW as createApiErrorHandler, aX as createSdkAgentStream, aY as createThinkTagExtractor, aZ as createToolHooksPlugin, a_ as delegate, a$ as delegateBackground, b0 as delegateWithScoring, b1 as extractThinkTagStream, b2 as generateAgentManifest, b3 as generateAgentRoutes, b4 as isAgentContext, b5 as isAgentDefinition, b6 as isApprovalRequired, b7 as isDone, b8 as isError, b9 as isPartialToolCall, ba as isTextDelta, bb as isToolCall, bc as isToolResult, bd as ladderReflectionStrategy, be as loopStrategyConfigSchema, bf as mcpRegistry, bg as mcpToolApprovals, bh as noopReflectionStrategy, bi as presentUIMessageStream, bj as projectContextMetadataOnlyKnobs, bk as reflectionStrategyConfigSchema, bl as resolveEnabledSkills, bm as resolveLoopStrategy, bn as resolveMcpServers, bo as runWithApiErrorHandling, bp as streamAgentResponse, bq as streamAgentUIMessages, br as toAgentFactory, bs as translateSdkEvent } from './bridge-entry-F9kHGaIn.js';
3
+ import * as _theokit_sdk from '@theokit/sdk';
5
4
  import { PluginsSettings, Plugin, ProviderRoutingSettings, AgentDefinition, BudgetTracker, CustomTool, InlineSkill } from '@theokit/sdk';
6
5
  import { RetryOptions } from '@theokit/sdk/retry';
7
6
  import { CompressibleMessage } from '@theokit/sdk/compaction';
@@ -170,9 +169,8 @@ declare const tokenBudgetCompactionStrategy: TranscriptCompactionStrategy;
170
169
  /**
171
170
  * AgentRunner — the imperative twin of `@MainLoop` (plan ADR D4, V4-B).
172
171
  *
173
- * `AgentRunner.builder(AgentClass).reflection().stream().build()` walks +
174
- * compiles the agent and resolves the SAME `{ compiled, loopStrategy }` that
175
- * `delegate()` resolves for the decorator path (two on-ramps, one runtime).
172
+ * `AgentRunner.fromSpec(spec).reflection().stream().build()` resolves the loop strategy from
173
+ * an already-compiled spec (the capability-authored agent). `delegate()` shares the same runtime.
176
174
  * `build()` is the compile boundary (no I/O, no IoC — standalone, mirrors
177
175
  * Spring's `ChatClient.builder(...).build()`); `stream()`/`run()` do the I/O via
178
176
  * `runReflectiveLoopStream` (the SAME loop `delegate()` drains — DRY, ADR 0031).
@@ -206,7 +204,7 @@ interface AgentRunnerRunOptions {
206
204
  * M1 (Axis-A SWAP): per-run extended-thinking effort. Merge-over-compiled —
207
205
  * `opts.reasoningEffort ?? compiled.reasoningEffort` (resolved in the adapter, single site).
208
206
  * Mapped to the SDK `ModelSelection.params` so the provider reasons (surfaced as `thinking`
209
- * StreamEvents). Absent ⇒ the compiled `@Agent({ reasoningEffort })` (or none).
207
+ * StreamEvents). Absent ⇒ the compiled reasoning effort (or none).
210
208
  */
211
209
  readonly reasoningEffort?: ReasoningEffort;
212
210
  /**
@@ -287,7 +285,7 @@ interface AgentRunnerRunOptions {
287
285
  readonly retry?: RetryOptions;
288
286
  }
289
287
  /**
290
- * A built, runnable agent. Construct via {@link AgentRunner.builder} — the
288
+ * A built, runnable agent. Construct via {@link AgentRunner.fromSpec} — the
291
289
  * constructor takes already-resolved state and is an internal detail.
292
290
  */
293
291
  /** Already-resolved state handed to the {@link AgentRunner} constructor (internal). */
@@ -325,8 +323,8 @@ declare class AgentRunner {
325
323
  */
326
324
  readonly compaction?: TranscriptCompactionStrategy;
327
325
  constructor(state: AgentRunnerState);
328
- /** Start a fluent builder for `AgentClass`. */
329
- static builder(AgentClass: Function): AgentRunnerBuilder;
326
+ /** Start a fluent builder from an already-compiled spec. */
327
+ static fromSpec(spec: AgentRunnerSpec): AgentRunnerBuilder;
330
328
  /**
331
329
  * V4-D-stream: stream the agent's events LIVE across the reflective loop, returning
332
330
  * the aggregated {@link DelegationResult} as the generator's return value. This is the
@@ -340,13 +338,33 @@ declare class AgentRunner {
340
338
  /** Run the agent to a terminal result via the shared reflective loop (collect mode). */
341
339
  run(message: string, opts: AgentRunnerRunOptions): Promise<DelegationResult>;
342
340
  }
341
+ /**
342
+ * M53 — what the runner actually needs in order to run: an already-compiled agent plus the two
343
+ * loop knobs. It used to derive all of this from `walkAgentMetadata`, which chained the runner to
344
+ * the decorator surface. `strategy` and `compaction` are the two non-waist channels ADR 0002 keeps
345
+ * (the builder's `.compaction()` already outranked the decorator; this just names the input).
346
+ */
347
+ /**
348
+ * The already-compiled agent the runner executes. Field-compatible with `SubAgentSpec` on purpose —
349
+ * one spec drives both `AgentRunner.fromSpec` and `delegate`.
350
+ */
351
+ interface AgentRunnerSpec {
352
+ readonly name: string;
353
+ readonly compiled: CompiledAgentOptions;
354
+ readonly strategy?: MainLoopMeta['strategy'];
355
+ readonly maxIterations?: number;
356
+ readonly compaction?: {
357
+ name: string;
358
+ keepTokens?: number;
359
+ };
360
+ }
343
361
  /** Fluent builder — accumulates config; `build()` is the compile boundary. */
344
362
  declare class AgentRunnerBuilder {
345
- private readonly AgentClass;
363
+ private readonly spec;
346
364
  private reflectionOverride?;
347
365
  private streamEnabled;
348
366
  private compactionOverride?;
349
- constructor(AgentClass: Function);
367
+ constructor(spec: AgentRunnerSpec);
350
368
  /** Override the default reflection strategy (OCP — plan Drawback #2). No arg ⇒ keep default. */
351
369
  reflection(strategy?: ReflectionStrategy): this;
352
370
  /** Record the streaming preference (see {@link AgentRunner.streamEnabled}). */
@@ -359,7 +377,7 @@ declare class AgentRunnerBuilder {
359
377
  compaction(name: string, options?: {
360
378
  keepTokens?: number;
361
379
  }): this;
362
- /** Walk + compile + resolve strategies — the compile→execute boundary (no I/O). */
380
+ /** Resolve strategies from the spec — the compile→execute boundary (no I/O). */
363
381
  build(): AgentRunner;
364
382
  }
365
383
 
@@ -467,6 +485,146 @@ declare class CapabilityPreset implements Capability {
467
485
  apply(draft: CompiledAgentOptionsDraft): void;
468
486
  }
469
487
 
488
+ /** `@Memory` → `memory`. */
489
+ declare const memory: (value: NonNullable<MemoryOptions | _theokit_sdk.MemorySettings | undefined>) => Capability;
490
+ /**
491
+ * `@ContextWindow` → `context`. DELEGATES to `compileContextWindow`, which is the canonical
492
+ * `ContextWindowOptions → ContextSettings` conversion (it also reports the metadata-only knobs).
493
+ * Taking a pre-converted value here would duplicate that knowledge — the exact divergence the M52
494
+ * zero-behavior proof caught in `skills`.
495
+ */
496
+ declare const contextWindow: (options: ContextWindowOptions) => Capability;
497
+ /** `@ProjectContext` → `projectContext`. */
498
+ declare const projectContext: (value: ProjectContextOptions) => Capability;
499
+ /** `@MCP` → `mcpServers`. */
500
+ declare const mcpServers: (value: McpServersMap) => Capability;
501
+ /** `@Guardrails` → `guardrails`. */
502
+ declare const guardrails: (value: readonly Guardrail[]) => Capability;
503
+ /**
504
+ * `@Checkpoint` → `checkpoint`. Carries the non-durable WARNING the metadata walk used to emit: only
505
+ * `'filesystem'` selects the SDK's durable store, so any other storage cannot resume across
506
+ * requests. The warning moves WITH the feature — a declared checkpoint that silently cannot resume
507
+ * is exactly the kind of no-op this project refuses to ship.
508
+ */
509
+ declare const checkpoint: (options: CompiledAgentOptions["checkpoint"]) => Capability;
510
+ /** `@HumanInTheLoop` → `hitl` (keyed `"<toolbox>.<tool>"`, as `compileHitlGates` keys it today). */
511
+ declare const humanInTheLoop: (value: Map<string, HumanInTheLoopOptions>) => Capability;
512
+ /**
513
+ * `@SubAgents` → `agents`. MERGES instead of `setOnce`: `agents` is a pre-seeded collection on the
514
+ * draft (`createDraft` gives it `{}`), so a `setOnce` would conflict against the seed itself — the
515
+ * same trap the pre-seeded `stream` sprang in M52. Merging also lets a preset declare a baseline
516
+ * child set that a call site extends.
517
+ */
518
+ declare const subAgents: (children: CompiledAgentOptions["agents"]) => Capability;
519
+ /**
520
+ * `@Skills({ include, autoDiscover })` → `skills`. Delegates to `compileSkills` (same reason as
521
+ * `contextWindow`). Distinct from the M52 `skills([...])`, which takes the plain name/inline list.
522
+ */
523
+ declare const skillsOptions: (options: SkillsOptions) => Capability;
524
+ /** Functional-path fields that had no decorator source — closing the gap list, not adding surface. */
525
+ declare const settingSources: (value: readonly _theokit_sdk.SettingSource[]) => Capability;
526
+ declare const plugins: (value: readonly unknown[]) => Capability;
527
+ declare const runContext: (value: Record<string, unknown>) => Capability;
528
+ declare const skillsResolver: (value: NonNullable<SkillsSelection | undefined>) => Capability;
529
+ /** The scalar agent config (name/route are HTTP concerns, never agent config). */
530
+ interface AgentConfig {
531
+ readonly systemPrompt?: CompiledAgentOptions['systemPrompt'];
532
+ readonly parseThinkTags?: boolean;
533
+ readonly stripToolDialect?: boolean;
534
+ readonly recoverLeakedToolCalls?: boolean;
535
+ readonly stream?: boolean;
536
+ readonly maxIterations?: number;
537
+ readonly timeoutMs?: number;
538
+ }
539
+ /**
540
+ * Scalar waist fields (formerly the `@Agent` options). CLASS, not a factory: it validates, and it is the one
541
+ * capability that writes fields another capability may legitimately override (see
542
+ * {@link MainLoopCapability}).
543
+ */
544
+ declare class AgentConfigCapability implements Capability {
545
+ private readonly config;
546
+ readonly name = "agent-config";
547
+ constructor(config: AgentConfig);
548
+ apply(draft: CompiledAgentOptionsDraft): void;
549
+ }
550
+ /**
551
+ * `@MainLoop({ maxIterations, timeoutMs })` → the same two fields `@Agent` can write.
552
+ *
553
+ * PRECEDENCE, preserved deliberately: `compileAgent` resolves these as
554
+ * `mainLoop.x ?? agentConfig.x` — the main-loop declaration WINS when both are present. A plain
555
+ * `setOnce` would raise a conflict where the pipeline has a defined winner, so this capability
556
+ * OVERRIDES instead. That is the one place in the layer where a later write beats an earlier one,
557
+ * and it exists to keep behavior identical, not for convenience.
558
+ */
559
+ declare class MainLoopCapability implements Capability {
560
+ private readonly config;
561
+ readonly name = "main-loop";
562
+ constructor(config: {
563
+ maxIterations?: number;
564
+ timeoutMs?: number;
565
+ });
566
+ apply(draft: CompiledAgentOptionsDraft): void;
567
+ }
568
+
569
+ /**
570
+ * M53 — tools without `@Toolbox`/`@Tool`.
571
+ *
572
+ * A toolbox class declares its tools as DATA (`static tools`) and keeps its handlers as ordinary
573
+ * methods; the capability takes an INSTANCE. That preserves what the decorators actually bought —
574
+ * grouping under a namespace and handlers bound to the instance (so a toolbox can hold state and
575
+ * injected dependencies) — with no metadata reflection at all.
576
+ *
577
+ * The compilation itself is NOT reimplemented: it delegates to `compileTools`, the same function the
578
+ * decorator path calls, so namespacing (`toolRuntimeName`), handler binding and the fail-fast checks
579
+ * stay in one place.
580
+ *
581
+ * @example
582
+ * ```ts
583
+ * class SupportTools {
584
+ * static tools: ToolDeclaration[] = [
585
+ * { name: 'search', description: 'Search tickets', input: z.object({ q: z.string() }), method: 'search' },
586
+ * ]
587
+ * async search({ q }: { q: string }): Promise<string> { return `found ${q}` }
588
+ * }
589
+ *
590
+ * const agent = applyCapabilities([
591
+ * new ModelCapability('openai/gpt-5.4'),
592
+ * new ToolboxCapability(new SupportTools(), { namespace: 'support' }),
593
+ * ])
594
+ * ```
595
+ */
596
+ interface ToolDeclaration extends ToolOptions {
597
+ /** Method on the toolbox instance that implements this tool. */
598
+ readonly method: string;
599
+ /** Require human approval before the tool runs (surfaced in the manifest). */
600
+ readonly approval?: ApprovalOptions;
601
+ /** Gate the tool behind human-in-the-loop (M4). */
602
+ readonly hitl?: HumanInTheLoopOptions;
603
+ /** Manifest-only observability flags. */
604
+ readonly trace?: boolean;
605
+ readonly audit?: boolean;
606
+ }
607
+ /** A toolbox instance whose class declares its tools. */
608
+ interface ToolboxSource {
609
+ readonly constructor: {
610
+ tools?: readonly ToolDeclaration[];
611
+ };
612
+ }
613
+ interface ToolboxOptions {
614
+ /** Prefix for every tool name (`"<namespace>.<tool>"`), as `@Toolbox({ namespace })` did. */
615
+ readonly namespace?: string;
616
+ /** Declarations, when they are not on the class as `static tools`. */
617
+ readonly tools?: readonly ToolDeclaration[];
618
+ }
619
+ declare class ToolboxCapability implements Capability {
620
+ #private;
621
+ readonly name = "toolbox";
622
+ constructor(instance: object, options?: ToolboxOptions);
623
+ /** The compiled tools this toolbox contributes — the same shape the decorator path produces. */
624
+ compile(): CompiledTool[];
625
+ apply(draft: CompiledAgentOptionsDraft): void;
626
+ }
627
+
470
628
  /**
471
629
  * M15 (theokit-ai-first) — A2A agent card generation (ADR-0040 § D2, home/discovery concern).
472
630
  *
@@ -658,4 +816,4 @@ declare class AcpClient {
658
816
  private handleServerRequest;
659
817
  }
660
818
 
661
- export { type A2AAuth, type A2ACapabilities, type A2ASkill, type A2AToolConfig, AcpClient, AcpMessageDecoder, type AcpTransport, type AgentCard, AgentManifestEntry, AgentRunner, AgentRunnerBuilder, type AgentRunnerRunOptions, type BuildAgentCardOptions, type Capability, CapabilityConflictError, CapabilityPreset, CapabilityRegistry, type CompactionCallOptions, type CompactionStrategyConfig, CompiledAgentOptions, type CompiledAgentOptionsDraft, CompiledTool, ConfigurationError, type CostGuardOptions, DEFAULT_KEEP_TOKENS, DelegationResult, type FinalizedDraft, Guardrail, LoopStrategy, MCP_PROTOCOL_VERSION, type McpJsonSchema, type McpServerInfo, type McpToolDescriptor, ModelCapability, type OutputModerationOptions, type PiiOptions, type PromptInjectionOptions, type ProvenanceEntry, ReasoningEffort, ReflectionStrategy, RoundStreamFactory, StreamEvent, type Summarize, ToolsCapability, type TranscriptCompactionStrategy, UnknownCapabilityError, applyCapabilities, buildAgentCard, buildMcpToolDescriptors, compactionStrategyConfigSchema, costGuard, createA2ATool, createDraft, deriveConversationId, encodeAcpMessage, estimateTokens, mcpServerInfo, moderateOutputStream, outputModeration, parseConversationId, piiDetector, promptInjectionDetector, resolveCompactionStrategy, runInputGuards, runOutputGuards, setOnce, skills, tokenBudgetCompactionStrategy, unicodeNormalizer, wellKnownCardPath };
819
+ export { type A2AAuth, type A2ACapabilities, type A2ASkill, type A2AToolConfig, AcpClient, AcpMessageDecoder, type AcpTransport, type AgentCard, type AgentConfig, AgentConfigCapability, AgentManifestEntry, AgentRunner, AgentRunnerBuilder, type AgentRunnerRunOptions, ApprovalOptions, type BuildAgentCardOptions, type Capability, CapabilityConflictError, CapabilityPreset, CapabilityRegistry, type CompactionCallOptions, type CompactionStrategyConfig, CompiledAgentOptions, type CompiledAgentOptionsDraft, CompiledTool, ConfigurationError, type CostGuardOptions, DEFAULT_KEEP_TOKENS, DelegationResult, type FinalizedDraft, Guardrail, HumanInTheLoopOptions, LoopStrategy, MCP_PROTOCOL_VERSION, MainLoopCapability, MainLoopMeta, type McpJsonSchema, type McpServerInfo, type McpToolDescriptor, ModelCapability, type OutputModerationOptions, type PiiOptions, type PromptInjectionOptions, type ProvenanceEntry, ReasoningEffort, ReflectionStrategy, RoundStreamFactory, SkillsSelection, StreamEvent, type Summarize, type ToolDeclaration, ToolOptions, ToolboxCapability, type ToolboxSource, ToolsCapability, type TranscriptCompactionStrategy, UnknownCapabilityError, applyCapabilities, buildAgentCard, buildMcpToolDescriptors, checkpoint, compactionStrategyConfigSchema, contextWindow, costGuard, createA2ATool, createDraft, deriveConversationId, encodeAcpMessage, estimateTokens, guardrails, humanInTheLoop, mcpServerInfo, mcpServers, memory, moderateOutputStream, outputModeration, parseConversationId, piiDetector, plugins, projectContext, promptInjectionDetector, resolveCompactionStrategy, runContext, runInputGuards, runOutputGuards, setOnce, settingSources, skills, skillsOptions, skillsResolver, subAgents, tokenBudgetCompactionStrategy, unicodeNormalizer, wellKnownCardPath };
package/dist/index.js CHANGED
@@ -3,18 +3,17 @@ import {
3
3
  AgentDefinitionError,
4
4
  AgentRunner,
5
5
  AgentRunnerBuilder,
6
- AgentWarningCode,
7
6
  BudgetExceededError,
8
7
  CostBudgetExceededError,
9
8
  DEFAULT_KEEP_TOKENS,
10
9
  DEFAULT_MAX_ITERATIONS,
11
10
  DelegationError,
12
11
  GuardrailViolationError,
12
+ SDK_TOOL_NAME,
13
13
  agent,
14
14
  agentsPlugin,
15
15
  buildModelSelection,
16
16
  compactionStrategyConfigSchema,
17
- compileAgent,
18
17
  compileAgentDefinition,
19
18
  compileAgentModule,
20
19
  compileContextWindow,
@@ -67,12 +66,10 @@ import {
67
66
  streamAgentUIMessages,
68
67
  toAgentFactory,
69
68
  tokenBudgetCompactionStrategy,
69
+ toolRuntimeName,
70
70
  translateSdkEvent,
71
- unicodeNormalizer,
72
- validateUniqueRoutes,
73
- walkAgentMetadata
74
- } from "./chunk-FEH7JFH7.js";
75
- import "./chunk-NERDIS45.js";
71
+ unicodeNormalizer
72
+ } from "./chunk-PTHRG25K.js";
76
73
  import {
77
74
  __name
78
75
  } from "./chunk-7QVYU63E.js";
@@ -213,9 +210,7 @@ var skills = /* @__PURE__ */ __name((entries) => {
213
210
  return {
214
211
  name: "skills",
215
212
  apply: /* @__PURE__ */ __name((draft) => {
216
- const compiled = compileSkillsSelection([
217
- ...entries
218
- ]);
213
+ const compiled = compileSkillsSelection(entries.slice());
219
214
  if (compiled.skills === void 0) return;
220
215
  const previous = draft.skills;
221
216
  draft.skills = previous === void 0 ? compiled.skills : {
@@ -296,6 +291,213 @@ var CapabilityPreset = class {
296
291
  }
297
292
  };
298
293
 
294
+ // src/capability/agent-capabilities.ts
295
+ function fieldCapability(name, field) {
296
+ return (value) => ({
297
+ name,
298
+ apply: /* @__PURE__ */ __name((draft) => {
299
+ setOnce(draft, field, value, name);
300
+ }, "apply")
301
+ });
302
+ }
303
+ __name(fieldCapability, "fieldCapability");
304
+ var memory = fieldCapability("memory", "memory");
305
+ var contextWindow = /* @__PURE__ */ __name((options) => ({
306
+ name: "context-window",
307
+ apply: /* @__PURE__ */ __name((draft) => {
308
+ setOnce(draft, "context", compileContextWindow(options).context, "context-window");
309
+ }, "apply")
310
+ }), "contextWindow");
311
+ var projectContext = fieldCapability("project-context", "projectContext");
312
+ var mcpServers = fieldCapability("mcp", "mcpServers");
313
+ var guardrails = fieldCapability("guardrails", "guardrails");
314
+ var checkpoint = /* @__PURE__ */ __name((options) => ({
315
+ name: "checkpoint",
316
+ apply: /* @__PURE__ */ __name((draft) => {
317
+ if (options !== void 0 && options.storage !== "filesystem") {
318
+ console.warn(`[THEO_AGENT_CHECKPOINT_STORAGE_METADATA_ONLY] checkpoint({ storage: '${options.storage ?? "memory"}' }) does NOT resume across requests \u2014 only 'filesystem' selects the SDK's durable conversation store. Use checkpoint({ storage: 'filesystem' }) for cross-request resume.`);
319
+ }
320
+ setOnce(draft, "checkpoint", options, "checkpoint");
321
+ }, "apply")
322
+ }), "checkpoint");
323
+ var humanInTheLoop = fieldCapability("human-in-the-loop", "hitl");
324
+ var subAgents = /* @__PURE__ */ __name((children) => ({
325
+ name: "sub-agents",
326
+ apply: /* @__PURE__ */ __name((draft) => {
327
+ for (const [name, child] of Object.entries(children)) {
328
+ if (name in draft.agents && draft.agents[name] !== child) {
329
+ throw new ConfigurationError(`sub-agents: filho "${name}" declarado duas vezes com defini\xE7\xF5es diferentes`);
330
+ }
331
+ draft.agents[name] = child;
332
+ }
333
+ draft.provenance.push({
334
+ capability: "sub-agents",
335
+ contributed: [
336
+ "agents"
337
+ ]
338
+ });
339
+ }, "apply")
340
+ }), "subAgents");
341
+ var skillsOptions = /* @__PURE__ */ __name((options) => ({
342
+ name: "skills",
343
+ apply: /* @__PURE__ */ __name((draft) => {
344
+ setOnce(draft, "skills", compileSkills(options), "skills");
345
+ }, "apply")
346
+ }), "skillsOptions");
347
+ var settingSources = fieldCapability("setting-sources", "settingSources");
348
+ var plugins = fieldCapability("plugins", "plugins");
349
+ var runContext = fieldCapability("run-context", "runContext");
350
+ var skillsResolver = fieldCapability("skills-resolver", "skillsResolver");
351
+ var AgentConfigCapability = class {
352
+ static {
353
+ __name(this, "AgentConfigCapability");
354
+ }
355
+ config;
356
+ name = "agent-config";
357
+ constructor(config) {
358
+ this.config = config;
359
+ if (typeof config !== "object" || config === null) {
360
+ throw new ConfigurationError("agent-config: esperava um objeto de configura\xE7\xE3o");
361
+ }
362
+ for (const field of [
363
+ "maxIterations",
364
+ "timeoutMs"
365
+ ]) {
366
+ const value = config[field];
367
+ if (value !== void 0 && (!Number.isFinite(value) || value <= 0)) {
368
+ throw new ConfigurationError(`agent-config: \`${field}\` deve ser um n\xFAmero positivo`);
369
+ }
370
+ }
371
+ }
372
+ apply(draft) {
373
+ const claimedByMainLoop = /* @__PURE__ */ __name((field) => draft.provenance.some((p) => p.capability === "main-loop" && p.contributed.includes(field)), "claimedByMainLoop");
374
+ if (!claimedByMainLoop("maxIterations")) {
375
+ setOnce(draft, "maxIterations", this.config.maxIterations, this.name);
376
+ }
377
+ if (!claimedByMainLoop("timeoutMs")) {
378
+ setOnce(draft, "timeoutMs", this.config.timeoutMs, this.name);
379
+ }
380
+ setOnce(draft, "systemPrompt", this.config.systemPrompt, this.name);
381
+ setOnce(draft, "parseThinkTags", this.config.parseThinkTags, this.name);
382
+ setOnce(draft, "stripToolDialect", this.config.stripToolDialect, this.name);
383
+ setOnce(draft, "recoverLeakedToolCalls", this.config.recoverLeakedToolCalls, this.name);
384
+ setOnce(draft, "stream", this.config.stream, this.name);
385
+ }
386
+ };
387
+ var MainLoopCapability = class {
388
+ static {
389
+ __name(this, "MainLoopCapability");
390
+ }
391
+ config;
392
+ name = "main-loop";
393
+ constructor(config) {
394
+ this.config = config;
395
+ }
396
+ apply(draft) {
397
+ const contributed = [];
398
+ if (this.config.maxIterations !== void 0) {
399
+ draft.maxIterations = this.config.maxIterations;
400
+ contributed.push("maxIterations");
401
+ }
402
+ if (this.config.timeoutMs !== void 0) {
403
+ draft.timeoutMs = this.config.timeoutMs;
404
+ contributed.push("timeoutMs");
405
+ }
406
+ if (contributed.length > 0) draft.provenance.push({
407
+ capability: this.name,
408
+ contributed
409
+ });
410
+ }
411
+ };
412
+
413
+ // src/capability/toolbox.ts
414
+ var ToolboxCapability = class {
415
+ static {
416
+ __name(this, "ToolboxCapability");
417
+ }
418
+ name = "toolbox";
419
+ #instance;
420
+ #declarations;
421
+ #namespace;
422
+ constructor(instance, options = {}) {
423
+ if (typeof instance !== "object" || instance === null) {
424
+ throw new ConfigurationError("toolbox: esperava uma inst\xE2ncia de toolbox");
425
+ }
426
+ const declared = options.tools ?? instance.constructor.tools;
427
+ if (declared === void 0 || declared.length === 0) {
428
+ throw new ConfigurationError(`toolbox: ${instance.constructor.name} n\xE3o declara tools \u2014 use \`static tools = [...]\` ou a op\xE7\xE3o \`tools\``);
429
+ }
430
+ for (const tool of declared) {
431
+ if (typeof instance[tool.method] !== "function") {
432
+ throw new ConfigurationError(`toolbox: ${instance.constructor.name}.${tool.method} n\xE3o \xE9 um m\xE9todo (tool "${tool.name}")`);
433
+ }
434
+ }
435
+ this.#instance = instance;
436
+ this.#declarations = declared;
437
+ this.#namespace = options.namespace ?? "";
438
+ for (const tool of declared) {
439
+ const runtime = toolRuntimeName(this.#namespace, tool.name);
440
+ if (!SDK_TOOL_NAME.test(runtime)) {
441
+ throw new ConfigurationError(`toolbox: nome de tool inv\xE1lido "${runtime}" \u2014 deve casar ${String(SDK_TOOL_NAME)} (o SDK rejeita o resto; verifique o namespace e o nome da tool)`);
442
+ }
443
+ }
444
+ }
445
+ /** The compiled tools this toolbox contributes — the same shape the decorator path produces. */
446
+ compile() {
447
+ const token = this.#instance.constructor;
448
+ const walk = {
449
+ class: token,
450
+ namespace: this.#namespace,
451
+ guards: [],
452
+ tools: this.#declarations.map((tool) => ({
453
+ propertyKey: tool.method,
454
+ config: tool,
455
+ guards: [],
456
+ approval: tool.approval,
457
+ trace: tool.trace ?? false,
458
+ audit: tool.audit ?? false,
459
+ ...tool.hitl !== void 0 ? {
460
+ hitl: tool.hitl
461
+ } : {}
462
+ }))
463
+ };
464
+ return compileTools([
465
+ walk
466
+ ], /* @__PURE__ */ new Map([
467
+ [
468
+ token,
469
+ this.#instance
470
+ ]
471
+ ]));
472
+ }
473
+ apply(draft) {
474
+ draft.tools.push(...this.compile());
475
+ draft.provenance.push({
476
+ capability: this.name,
477
+ contributed: [
478
+ "tools"
479
+ ]
480
+ });
481
+ const gates = [];
482
+ for (const tool of this.#declarations) {
483
+ if (tool.hitl === void 0) continue;
484
+ gates.push([
485
+ toolRuntimeName(this.#namespace, tool.name),
486
+ tool.hitl
487
+ ]);
488
+ }
489
+ if (gates.length === 0) return;
490
+ draft.hitl ??= /* @__PURE__ */ new Map();
491
+ for (const [key, options] of gates) draft.hitl.set(key, options);
492
+ draft.provenance.push({
493
+ capability: this.name,
494
+ contributed: [
495
+ "hitl"
496
+ ]
497
+ });
498
+ }
499
+ };
500
+
299
501
  // src/a2a/agent-card.ts
300
502
  function trimTrailingSlash(url) {
301
503
  return url.endsWith("/") ? url.slice(0, -1) : url;
@@ -432,8 +634,12 @@ async function resolveEnabledSkills(selection, ctx) {
432
634
  if (!Array.isArray(resolved)) {
433
635
  throw new Error("[@theokit/agents] skills resolver must return an array of skill names");
434
636
  }
637
+ const names = resolved;
638
+ if (!names.every((n) => typeof n === "string" && n.trim().length > 0)) {
639
+ throw new Error("[@theokit/agents] skills resolver must return non-empty skill NAME strings");
640
+ }
435
641
  return [
436
- ...resolved
642
+ ...names
437
643
  ];
438
644
  }
439
645
  __name(resolveEnabledSkills, "resolveEnabledSkills");
@@ -567,10 +773,10 @@ export {
567
773
  AGENT_BRAND,
568
774
  AcpClient,
569
775
  AcpMessageDecoder,
776
+ AgentConfigCapability,
570
777
  AgentDefinitionError,
571
778
  AgentRunner,
572
779
  AgentRunnerBuilder,
573
- AgentWarningCode,
574
780
  BudgetExceededError,
575
781
  CapabilityConflictError,
576
782
  CapabilityPreset,
@@ -582,7 +788,9 @@ export {
582
788
  DelegationError,
583
789
  GuardrailViolationError,
584
790
  MCP_PROTOCOL_VERSION,
791
+ MainLoopCapability,
585
792
  ModelCapability,
793
+ ToolboxCapability,
586
794
  ToolsCapability,
587
795
  UnknownCapabilityError,
588
796
  agent,
@@ -591,14 +799,15 @@ export {
591
799
  buildAgentCard,
592
800
  buildMcpToolDescriptors,
593
801
  buildModelSelection,
802
+ checkpoint,
594
803
  compactionStrategyConfigSchema,
595
- compileAgent,
596
804
  compileAgentDefinition,
597
805
  compileAgentModule,
598
806
  compileContextWindow,
599
807
  compileProjectContext,
600
808
  compileSkills,
601
809
  compileTools,
810
+ contextWindow,
602
811
  contextualTool,
603
812
  costGuard,
604
813
  createA2ATool,
@@ -617,6 +826,8 @@ export {
617
826
  extractThinkTagStream,
618
827
  generateAgentManifest,
619
828
  generateAgentRoutes,
829
+ guardrails,
830
+ humanInTheLoop,
620
831
  isAgentContext,
621
832
  isAgentDefinition,
622
833
  isApprovalRequired,
@@ -630,13 +841,17 @@ export {
630
841
  loopStrategyConfigSchema,
631
842
  mcpRegistry,
632
843
  mcpServerInfo,
844
+ mcpServers,
633
845
  mcpToolApprovals,
846
+ memory,
634
847
  moderateOutputStream,
635
848
  noopReflectionStrategy,
636
849
  outputModeration,
637
850
  parseConversationId,
638
851
  piiDetector,
852
+ plugins,
639
853
  presentUIMessageStream,
854
+ projectContext,
640
855
  projectContextMetadataOnlyKnobs,
641
856
  promptInjectionDetector,
642
857
  reflectionStrategyConfigSchema,
@@ -644,19 +859,22 @@ export {
644
859
  resolveEnabledSkills,
645
860
  resolveLoopStrategy,
646
861
  resolveMcpServers,
862
+ runContext,
647
863
  runInputGuards,
648
864
  runOutputGuards,
649
865
  runWithApiErrorHandling,
650
866
  setOnce,
867
+ settingSources,
651
868
  skills,
869
+ skillsOptions,
870
+ skillsResolver,
652
871
  streamAgentResponse,
653
872
  streamAgentUIMessages,
873
+ subAgents,
654
874
  toAgentFactory,
655
875
  tokenBudgetCompactionStrategy,
656
876
  translateSdkEvent,
657
877
  unicodeNormalizer,
658
- validateUniqueRoutes,
659
- walkAgentMetadata,
660
878
  wellKnownCardPath
661
879
  };
662
880
  //# sourceMappingURL=index.js.map