@theokit/agents 0.4.0 → 0.6.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.
@@ -1,5 +1,5 @@
1
- import { A as AgentOptions, d as MainLoopOptions, c as MainLoopMeta, T as ToolOptions, n as ToolboxOptions, B as BudgetOptions, k as PolicyHandler, a as ApprovalOptions } from './mcp-yyfC5u7t.js';
2
- export { G as Gateway, b as GatewayOptions, M as MCP, e as McpServerConfig, f as McpServersMap, g as Memory, h as MemoryOptions, i as MemoryProvider, j as MemoryScope, P as PlatformName, S as SessionStrategy, l as Skills, m as SkillsOptions, o as getGatewayConfig, p as getMcpConfig, q as getMemoryConfig, r as getSkillsConfig, s as resolveSessionId } from './mcp-yyfC5u7t.js';
1
+ import { A as AgentOptions, f as MainLoopOptions, M as MainLoopMeta, T as ToolOptions, r as ToolboxOptions, B as BudgetOptions, m as PolicyHandler, a as ApprovalOptions } from './skills-DmN1HGUb.js';
2
+ export { C as ContextCompactionStrategy, b as ContextWindow, c as ContextWindowOptions, G as Gateway, d as GatewayOptions, I as IndexStrategy, e as MCP, g as McpServerConfig, h as McpServersMap, i as Memory, j as MemoryOptions, k as MemoryProvider, l as MemoryScope, P as PlatformName, n as ProjectContext, o as ProjectContextOptions, R as RelevanceStrategy, S as SessionStrategy, p as Skills, q as SkillsOptions, s as getContextWindowConfig, t as getGatewayConfig, u as getMcpConfig, v as getMemoryConfig, w as getProjectContextConfig, x as getSkillsConfig, y as resolveSessionId } from './skills-DmN1HGUb.js';
3
3
  import 'zod';
4
4
 
5
5
  declare function Agent(options?: Partial<AgentOptions>): ClassDecorator;
@@ -71,22 +71,6 @@ interface HumanInTheLoopOptions {
71
71
  declare function HumanInTheLoop(options: HumanInTheLoopOptions): MethodDecorator;
72
72
  declare function getHumanInTheLoopConfig(target: Function, propertyKey: string | symbol): HumanInTheLoopOptions | undefined;
73
73
 
74
- type ContextCompactionStrategy = 'truncate-oldest' | 'summarize-oldest' | 'sliding-window' | 'priority-based';
75
- interface ContextWindowOptions {
76
- /** Maximum tokens before compaction triggers. */
77
- maxTokens?: number;
78
- /** How to compact when maxTokens is exceeded. */
79
- compactionStrategy?: ContextCompactionStrategy;
80
- /** Always preserve the system prompt during compaction (default: true). */
81
- preserveSystemPrompt?: boolean;
82
- /** Number of recent messages to always keep intact (default: 10). */
83
- preserveLastN?: number;
84
- /** Keep all tool results even during compaction (default: true). */
85
- preserveToolResults?: boolean;
86
- }
87
- declare function ContextWindow(options?: ContextWindowOptions): ClassDecorator;
88
- declare function getContextWindowConfig(target: Function): ContextWindowOptions | undefined;
89
-
90
74
  /** Override the LLM model for an agent class or a specific tool method. */
91
75
  declare const Model: (value: string) => MethodDecorator & ClassDecorator;
92
76
 
@@ -191,25 +175,6 @@ type EditFormatType = 'search-replace' | 'unified-diff' | 'full-file' | 'line-ra
191
175
  /** Declare the edit format a tool produces. */
192
176
  declare const EditFormat: (value: EditFormatType) => MethodDecorator & ClassDecorator;
193
177
 
194
- type IndexStrategy = 'tree-sitter' | 'regex' | 'none';
195
- type RelevanceStrategy = 'git-history' | 'import-graph' | 'semantic' | 'manual';
196
- interface ProjectContextOptions {
197
- /** Files that mark the project root (searched upward from cwd). */
198
- rootMarkers?: string[];
199
- /** How to index the codebase for structural understanding. */
200
- indexStrategy?: IndexStrategy;
201
- /** Maximum files to include in context per request. */
202
- maxFilesInContext?: number;
203
- /** How to rank file relevance when selecting context. */
204
- relevanceStrategy?: RelevanceStrategy;
205
- /** Glob patterns to exclude from indexing and context. */
206
- ignorePatterns?: string[];
207
- /** File extensions to include in indexing (default: all text files). */
208
- includeExtensions?: string[];
209
- }
210
- declare function ProjectContext(options?: ProjectContextOptions): ClassDecorator;
211
- declare function getProjectContextConfig(target: Function): ProjectContextOptions | undefined;
212
-
213
178
  /**
214
179
  * applyDecorators() — compose multiple decorators into a single reusable decorator.
215
180
  *
@@ -245,4 +210,4 @@ declare function applyDecorators(...decorators: AnyDecorator[]): ClassDecorator
245
210
  declare function Mixin(...mixinClasses: Function[]): ClassDecorator;
246
211
  declare function getMixins(target: Function): Function[];
247
212
 
248
- export { Agent, AgentOptions, ApprovalOptions, Artifact, type ArtifactOptions, type ArtifactResult, Audit, Budget, BudgetOptions, Checkpoint, type CheckpointOptions, type CheckpointState, type CheckpointStorage, type CheckpointStrategy, type CommandPermissions, type CompactionStrategy, type ContextCompactionStrategy, ContextWindow, type ContextWindowOptions, Conversation, type ConversationOptions, type ConversationStorage, EditFormat, type EditFormatType, type FilesystemPermissions, Hook, type HookEntry, type HookPoint, HumanInTheLoop, type HumanInTheLoopOptions, type IndexStrategy, MainLoop, MainLoopMeta, MainLoopOptions, Mixin, Model, Observable, type ObservableEntry, Policy, PolicyHandler, ProjectContext, type ProjectContextOptions, type RelevanceStrategy, RequiresApproval, RequiresCapability, Sandbox, type SandboxOptions, SubAgents, type TimeoutAction, Tool, ToolOptions, Toolbox, ToolboxOptions, Trace, applyDecorators, getAgentConfig, getArtifactConfig, getCheckpointConfig, getContextWindowConfig, getConversationConfig, getHooks, getHooksByPoint, getHumanInTheLoopConfig, getMainLoop, getMixins, getObservableByChannel, getObservables, getProjectContextConfig, getSandboxConfig, getSubAgents, getToolConfig, getToolMethods, getToolboxConfig, isCommandAllowed, isPathAllowed };
213
+ export { Agent, AgentOptions, ApprovalOptions, Artifact, type ArtifactOptions, type ArtifactResult, Audit, Budget, BudgetOptions, Checkpoint, type CheckpointOptions, type CheckpointState, type CheckpointStorage, type CheckpointStrategy, type CommandPermissions, type CompactionStrategy, Conversation, type ConversationOptions, type ConversationStorage, EditFormat, type EditFormatType, type FilesystemPermissions, Hook, type HookEntry, type HookPoint, HumanInTheLoop, type HumanInTheLoopOptions, MainLoop, MainLoopMeta, MainLoopOptions, Mixin, Model, Observable, type ObservableEntry, Policy, PolicyHandler, RequiresApproval, RequiresCapability, Sandbox, type SandboxOptions, SubAgents, type TimeoutAction, Tool, ToolOptions, Toolbox, ToolboxOptions, Trace, applyDecorators, getAgentConfig, getArtifactConfig, getCheckpointConfig, getConversationConfig, getHooks, getHooksByPoint, getHumanInTheLoopConfig, getMainLoop, getMixins, getObservableByChannel, getObservables, getSandboxConfig, getSubAgents, getToolConfig, getToolMethods, getToolboxConfig, isCommandAllowed, isPathAllowed };
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  Artifact,
3
3
  Checkpoint,
4
- ContextWindow,
5
4
  Conversation,
6
5
  EditFormat,
7
6
  Hook,
@@ -9,14 +8,12 @@ import {
9
8
  MainLoop,
10
9
  Model,
11
10
  Observable,
12
- ProjectContext,
13
11
  Sandbox,
14
12
  Tool,
15
13
  Toolbox,
16
14
  applyDecorators,
17
15
  getArtifactConfig,
18
16
  getCheckpointConfig,
19
- getContextWindowConfig,
20
17
  getConversationConfig,
21
18
  getHooks,
22
19
  getHooksByPoint,
@@ -24,37 +21,40 @@ import {
24
21
  getMainLoop,
25
22
  getObservableByChannel,
26
23
  getObservables,
27
- getProjectContextConfig,
28
24
  getSandboxConfig,
29
25
  getToolConfig,
30
26
  getToolMethods,
31
27
  getToolboxConfig,
32
28
  isCommandAllowed,
33
29
  isPathAllowed
34
- } from "./chunk-VKHDADMG.js";
30
+ } from "./chunk-XWVZS2PQ.js";
35
31
  import {
36
32
  Agent,
37
33
  Audit,
38
34
  Budget,
35
+ ContextWindow,
39
36
  Gateway,
40
37
  MCP,
41
38
  Memory,
42
39
  Mixin,
43
40
  Policy,
41
+ ProjectContext,
44
42
  RequiresApproval,
45
43
  RequiresCapability,
46
44
  Skills,
47
45
  SubAgents,
48
46
  Trace,
49
47
  getAgentConfig,
48
+ getContextWindowConfig,
50
49
  getGatewayConfig,
51
50
  getMcpConfig,
52
51
  getMemoryConfig,
53
52
  getMixins,
53
+ getProjectContextConfig,
54
54
  getSkillsConfig,
55
55
  getSubAgents,
56
56
  resolveSessionId
57
- } from "./chunk-O4UG4RXE.js";
57
+ } from "./chunk-MVEY7HEY.js";
58
58
  import "./chunk-7QVYU63E.js";
59
59
  export {
60
60
  Agent,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,200 @@
1
- export { Agent, Artifact, ArtifactOptions, ArtifactResult, Audit, Budget, Checkpoint, CheckpointOptions, CheckpointState, CheckpointStorage, CheckpointStrategy, CommandPermissions, CompactionStrategy, ContextCompactionStrategy, ContextWindow, ContextWindowOptions, Conversation, ConversationOptions, ConversationStorage, EditFormat, EditFormatType, FilesystemPermissions, Hook, HookEntry, HookPoint, HumanInTheLoop, HumanInTheLoopOptions, IndexStrategy, MainLoop, Mixin, Model, Observable, ObservableEntry, Policy, ProjectContext, ProjectContextOptions, RelevanceStrategy, RequiresApproval, RequiresCapability, Sandbox, SandboxOptions, SubAgents, TimeoutAction, Tool, Toolbox, Trace, applyDecorators, getAgentConfig, getArtifactConfig, getCheckpointConfig, getContextWindowConfig, getConversationConfig, getHooks, getHooksByPoint, getHumanInTheLoopConfig, getMainLoop, getMixins, getObservableByChannel, getObservables, getProjectContextConfig, getSandboxConfig, getSubAgents, getToolConfig, getToolMethods, getToolboxConfig, isCommandAllowed, isPathAllowed } from './decorators.js';
2
- export { A as AgentOptions, a as ApprovalOptions, B as BudgetOptions, G as Gateway, b as GatewayOptions, M as MCP, c as MainLoopMeta, d as MainLoopOptions, e as McpServerConfig, f as McpServersMap, g as Memory, h as MemoryOptions, i as MemoryProvider, j as MemoryScope, P as PlatformName, k as PolicyHandler, S as SessionStrategy, l as Skills, m as SkillsOptions, T as ToolOptions, n as ToolboxOptions, o as getGatewayConfig, p as getMcpConfig, q as getMemoryConfig, r as getSkillsConfig, s as resolveSessionId } from './mcp-yyfC5u7t.js';
3
- export { AgentExecutionContext, AgentManifest, AgentManifestEntry, AgentManifestTool, AgentRoute, AgentRouteContext, AgentRunInfo, AgentStreamEvent, AgentWalkResult, AgentWarningCode, AgentsPluginOptions, ApprovalRequiredEvent, ArtifactChunkEvent, ArtifactStartEvent, BudgetExceededError, CheckpointSavedEvent, CompiledAgentOptions, CompiledTool, DelegateOptions, DelegationError, DelegationResult, DoneEvent, ErrorEvent, FileEditEvent, IterationEvent, RunStartedEvent, SdkMessage, StateUpdateEvent, StreamEvent, TextDeltaEvent, ThinkingEvent, ToolCallEvent, ToolResultEvent, ToolWalkResult, ToolboxWalkResult, agentsPlugin, compileAgent, compileTools, createAgentExecutionContext, createSdkAgentStream, delegate, generateAgentManifest, generateAgentRoutes, isAgentContext, isApprovalRequired, isDone, isError, isTextDelta, isToolCall, isToolResult, streamAgentResponse, translateSdkEvent, validateUniqueRoutes, walkAgentMetadata } from './bridge.js';
4
- import 'zod';
1
+ export { Agent, Artifact, ArtifactOptions, ArtifactResult, Audit, Budget, Checkpoint, CheckpointOptions, CheckpointState, CheckpointStorage, CheckpointStrategy, CommandPermissions, CompactionStrategy, Conversation, ConversationOptions, ConversationStorage, EditFormat, EditFormatType, FilesystemPermissions, Hook, HookEntry, HookPoint, HumanInTheLoop, HumanInTheLoopOptions, MainLoop, Mixin, Model, Observable, ObservableEntry, Policy, RequiresApproval, RequiresCapability, Sandbox, SandboxOptions, SubAgents, TimeoutAction, Tool, Toolbox, Trace, applyDecorators, getAgentConfig, getArtifactConfig, getCheckpointConfig, getConversationConfig, getHooks, getHooksByPoint, getHumanInTheLoopConfig, getMainLoop, getMixins, getObservableByChannel, getObservables, getSandboxConfig, getSubAgents, getToolConfig, getToolMethods, getToolboxConfig, isCommandAllowed, isPathAllowed } from './decorators.js';
2
+ import { M as MainLoopMeta } from './skills-DmN1HGUb.js';
3
+ export { A as AgentOptions, a as ApprovalOptions, B as BudgetOptions, C as ContextCompactionStrategy, b as ContextWindow, c as ContextWindowOptions, G as Gateway, d as GatewayOptions, I as IndexStrategy, e as MCP, f as MainLoopOptions, g as McpServerConfig, h as McpServersMap, i as Memory, j as MemoryOptions, k as MemoryProvider, l as MemoryScope, P as PlatformName, m as PolicyHandler, n as ProjectContext, o as ProjectContextOptions, R as RelevanceStrategy, S as SessionStrategy, p as Skills, q as SkillsOptions, T as ToolOptions, r as ToolboxOptions, s as getContextWindowConfig, t as getGatewayConfig, u as getMcpConfig, v as getMemoryConfig, w as getProjectContextConfig, x as getSkillsConfig, y as resolveSessionId } from './skills-DmN1HGUb.js';
4
+ import { CompiledAgentOptions, DelegationResult } from './bridge.js';
5
+ export { AgentExecutionContext, AgentManifest, AgentManifestEntry, AgentManifestTool, AgentRoute, AgentRouteContext, AgentRunInfo, AgentStreamEvent, AgentWalkResult, AgentWarningCode, AgentsPluginOptions, ApprovalRequiredEvent, ArtifactChunkEvent, ArtifactStartEvent, BudgetExceededError, CheckpointSavedEvent, CompiledContextWindow, CompiledTool, DelegateOptions, DelegationError, DoneEvent, ErrorEvent, FileEditEvent, IterationEvent, RunStartedEvent, SdkMessage, StateUpdateEvent, StreamEvent, TextDeltaEvent, ThinkingEvent, ToolCallEvent, ToolResultEvent, ToolWalkResult, ToolboxWalkResult, agentsPlugin, compileAgent, compileContextWindow, compileProjectContext, compileSkills, compileTools, createAgentExecutionContext, createSdkAgentStream, delegate, generateAgentManifest, generateAgentRoutes, isAgentContext, isApprovalRequired, isDone, isError, isTextDelta, isToolCall, isToolResult, projectContextMetadataOnlyKnobs, streamAgentResponse, translateSdkEvent, validateUniqueRoutes, walkAgentMetadata } from './bridge.js';
6
+ import { z } from 'zod';
5
7
  import '@theokit/http';
8
+ import '@theokit/sdk';
9
+
10
+ /**
11
+ * LoopStrategy — the per-round terminal-decision contract that gives runtime to
12
+ * `@MainLoop({ strategy })`.
13
+ *
14
+ * V4-A proved `@MainLoop`'s `strategy` field was metadata-only (declared +
15
+ * compiled, never executed). This module is the foundation Phase 2's
16
+ * `runReflectiveLoop` branches on. Modeled on Mastra's `agentic-loop`/`stopWhen`
17
+ * (inverted) + `maxSteps` ceiling — NOT Spring's per-call Advisor (plan ADR D1).
18
+ * Config is Zod-validated so an invalid `maxIterations` fails fast at resolve
19
+ * time, never as a silent infinite loop at runtime (plan ADR D3).
20
+ *
21
+ * referencia: knowledge-base/references/mastra agentic-loop/index.ts (stopWhen + maxSteps).
22
+ */
23
+
24
+ /** Why a single round ended. Derived in the bridge from the SDK stream events. */
25
+ type LoopFinishReason = 'tool-calls' | 'stop' | 'length' | 'error';
26
+ /** Value object describing one round's result. */
27
+ interface LoopOutcome {
28
+ /** Why the round ended (the continuation signal). */
29
+ readonly finishReason: LoopFinishReason;
30
+ /** 1-indexed round number that just completed. */
31
+ readonly round: number;
32
+ /** Tool calls executed during the round. */
33
+ readonly toolCalls: readonly {
34
+ name: string;
35
+ input: unknown;
36
+ output: string;
37
+ }[];
38
+ /** Accumulated assistant text for the round. */
39
+ readonly responseText: string;
40
+ }
41
+ /** The terminal-decision contract. `shouldContinue` is the inverted `stopWhen`. */
42
+ interface LoopStrategy {
43
+ /** The originating `@MainLoop` strategy name. */
44
+ readonly name: MainLoopMeta['strategy'];
45
+ /** Hard ceiling on rounds — guarantees termination. */
46
+ readonly maxIterations: number;
47
+ /** True ⇒ re-enter for another round; false ⇒ terminate. Never true forever. */
48
+ shouldContinue(outcome: LoopOutcome): boolean;
49
+ }
50
+ /** Default round ceiling when `@MainLoop` declares no `maxIterations` (EC-3: finite, never Infinity). */
51
+ declare const DEFAULT_MAX_ITERATIONS = 8;
52
+ /** Serializable config for a LoopStrategy. SSoT per type-safety.md (ADR D3). */
53
+ declare const loopStrategyConfigSchema: z.ZodObject<{
54
+ name: z.ZodEnum<{
55
+ react: "react";
56
+ "simple-chat": "simple-chat";
57
+ "plan-act-reflect": "plan-act-reflect";
58
+ }>;
59
+ maxIterations: z.ZodNumber;
60
+ }, z.core.$strip>;
61
+ type LoopStrategyConfig = z.infer<typeof loopStrategyConfigSchema>;
62
+ /**
63
+ * Map a `@MainLoop` strategy + ceiling to a concrete {@link LoopStrategy}.
64
+ *
65
+ * - `simple-chat` ⇒ exactly one round (`shouldContinue` always false).
66
+ * - `plan-act-reflect` / `react` ⇒ continue while the round ended on `tool-calls`
67
+ * AND the ceiling has not been reached (`round < maxIterations`).
68
+ *
69
+ * Throws (Zod) when `maxIterations < 1` — fail fast, never a silent infinite loop.
70
+ */
71
+ declare function resolveLoopStrategy(strategy: MainLoopMeta['strategy'], maxIterations?: number): LoopStrategy;
72
+
73
+ /**
74
+ * ReflectionStrategy — composes INTO the loop between rounds (the loop calls
75
+ * `reflect()` then `LoopStrategy.shouldContinue()`).
76
+ *
77
+ * `'plan-act-reflect'` resolves to the `'ladder'` default shipped here; a custom
78
+ * strategy may be supplied (OCP — plan Drawback #2). `reflect()` is pure (no
79
+ * I/O, no LLM) — it inspects the round's outcome and returns feedback to inject
80
+ * into the next round's prompt plus a `continue` hint. The hard round ceiling
81
+ * lives in `LoopStrategy.shouldContinue` (maxIterations), NOT here.
82
+ *
83
+ * referencia: knowledge-base/references/mastra agentic-loop/index.ts (onIterationComplete → { feedback, continue }).
84
+ */
85
+
86
+ /** Result of reflecting on a completed round. */
87
+ interface ReflectionResult {
88
+ /** Optional text prepended to the next round's prompt. */
89
+ readonly feedback?: string;
90
+ /** Hint: should the loop reflect-and-continue? (the ceiling still bounds it) */
91
+ readonly continue: boolean;
92
+ }
93
+ /** Pluggable between-round reflection. Pure — never performs I/O. */
94
+ interface ReflectionStrategy {
95
+ /** Strategy identifier (e.g. `'ladder'`). */
96
+ readonly name: string;
97
+ /** Inspect the round outcome; return feedback + continue hint. */
98
+ reflect(outcome: LoopOutcome): ReflectionResult;
99
+ }
100
+ /** Serializable config for a ReflectionStrategy. SSoT per type-safety.md (ADR D3). */
101
+ declare const reflectionStrategyConfigSchema: z.ZodObject<{
102
+ name: z.ZodString;
103
+ }, z.core.$strip>;
104
+ type ReflectionStrategyConfig = z.infer<typeof reflectionStrategyConfigSchema>;
105
+ /**
106
+ * The default `'ladder'` reflection (what `'plan-act-reflect'` resolves to).
107
+ *
108
+ * Continues with bounded templated feedback while the round ended on
109
+ * `tool-calls`; terminates on any terminal `finishReason` (`stop`/`error`/
110
+ * `length`). The feedback is a short fixed template (bounded — EC-5; context
111
+ * growth is the SDK's responsibility, not the loop's).
112
+ */
113
+ declare const ladderReflectionStrategy: ReflectionStrategy;
114
+ /**
115
+ * No-op reflection for `'react'` (multi-round WITHOUT reflection feedback).
116
+ *
117
+ * Returns `{ continue: true }` (no feedback) so the round-continuation decision
118
+ * is delegated entirely to `LoopStrategy.shouldContinue` (i.e. `react` loops
119
+ * while `finishReason === 'tool-calls'` under the ceiling). NOTE: the plan's
120
+ * pseudo-code (Files-to-edit) sketched `{ continue: false }`, which would make
121
+ * `react` single-shot — that contradicts the plan's own Deep Dives ("`react`
122
+ * still multi-rounds while finishReason==='tool-calls'"); `continue: true` is
123
+ * the behavior the resolved react LoopStrategy requires.
124
+ */
125
+ declare const noopReflectionStrategy: ReflectionStrategy;
126
+
127
+ /**
128
+ * AgentRunner — the imperative twin of `@MainLoop` (plan ADR D4, V4-B).
129
+ *
130
+ * `AgentRunner.builder(AgentClass).reflection().stream().build()` walks +
131
+ * compiles the agent and resolves the SAME `{ compiled, loopStrategy }` that
132
+ * `delegate()` resolves for the decorator path (two on-ramps, one runtime).
133
+ * `build()` is the compile boundary (no I/O, no IoC — standalone, mirrors
134
+ * Spring's `ChatClient.builder(...).build()`); `run()` does the I/O via
135
+ * `runReflectiveLoop` (the SAME loop `delegate()` uses — DRY, ADR 0031).
136
+ *
137
+ * referencia: knowledge-base/references/spring-ai DefaultChatClientBuilder.java (build() returns standalone).
138
+ */
139
+
140
+ /** Options for {@link AgentRunner.run}. */
141
+ interface AgentRunnerRunOptions {
142
+ /** LLM API key. */
143
+ readonly apiKey: string;
144
+ /** Session id override (default: a fresh isolated id). */
145
+ readonly sessionId?: string;
146
+ /** Cumulative USD budget across rounds. */
147
+ readonly budget?: number;
148
+ /** Cancellation — aborts stop the reflective loop from re-entering. */
149
+ readonly signal?: AbortSignal;
150
+ }
151
+ /**
152
+ * A built, runnable agent. Construct via {@link AgentRunner.builder} — the
153
+ * constructor takes already-resolved state and is an internal detail.
154
+ */
155
+ declare class AgentRunner {
156
+ private readonly compiled;
157
+ private readonly agentName;
158
+ /** The resolved terminal-decision strategy (parity with `delegate()`). */
159
+ readonly loopStrategy: LoopStrategy;
160
+ /** The resolved between-round reflection (default or `.reflection(custom)` override). */
161
+ readonly reflectionStrategy: ReflectionStrategy;
162
+ /**
163
+ * Recorded streaming preference. The reflective loop currently always
164
+ * streams via the SDK `Run.stream()`; a non-streaming collect mode is future
165
+ * work — the flag is captured + exposed here, not yet branched on (honest
166
+ * per G10: documented, not a silent no-op).
167
+ */
168
+ readonly streamEnabled: boolean;
169
+ constructor(compiled: CompiledAgentOptions, agentName: string,
170
+ /** The resolved terminal-decision strategy (parity with `delegate()`). */
171
+ loopStrategy: LoopStrategy,
172
+ /** The resolved between-round reflection (default or `.reflection(custom)` override). */
173
+ reflectionStrategy: ReflectionStrategy,
174
+ /**
175
+ * Recorded streaming preference. The reflective loop currently always
176
+ * streams via the SDK `Run.stream()`; a non-streaming collect mode is future
177
+ * work — the flag is captured + exposed here, not yet branched on (honest
178
+ * per G10: documented, not a silent no-op).
179
+ */
180
+ streamEnabled: boolean);
181
+ /** Start a fluent builder for `AgentClass`. */
182
+ static builder(AgentClass: Function): AgentRunnerBuilder;
183
+ /** Run the agent to a terminal result via the shared reflective loop. */
184
+ run(message: string, opts: AgentRunnerRunOptions): Promise<DelegationResult>;
185
+ }
186
+ /** Fluent builder — accumulates config; `build()` is the compile boundary. */
187
+ declare class AgentRunnerBuilder {
188
+ private readonly AgentClass;
189
+ private reflectionOverride?;
190
+ private streamEnabled;
191
+ constructor(AgentClass: Function);
192
+ /** Override the default reflection strategy (OCP — plan Drawback #2). No arg ⇒ keep default. */
193
+ reflection(strategy?: ReflectionStrategy): this;
194
+ /** Record the streaming preference (see {@link AgentRunner.streamEnabled}). */
195
+ stream(enabled?: boolean): this;
196
+ /** Walk + compile + resolve strategies — the compile→execute boundary (no I/O). */
197
+ build(): AgentRunner;
198
+ }
199
+
200
+ export { AgentRunner, AgentRunnerBuilder, type AgentRunnerRunOptions, CompiledAgentOptions, DEFAULT_MAX_ITERATIONS, DelegationResult, type LoopFinishReason, type LoopOutcome, type LoopStrategy, type LoopStrategyConfig, MainLoopMeta, type ReflectionResult, type ReflectionStrategy, type ReflectionStrategyConfig, ladderReflectionStrategy, loopStrategyConfigSchema, noopReflectionStrategy, reflectionStrategyConfigSchema, resolveLoopStrategy };
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  Artifact,
3
3
  Checkpoint,
4
- ContextWindow,
5
4
  Conversation,
6
5
  EditFormat,
7
6
  Hook,
@@ -9,14 +8,12 @@ import {
9
8
  MainLoop,
10
9
  Model,
11
10
  Observable,
12
- ProjectContext,
13
11
  Sandbox,
14
12
  Tool,
15
13
  Toolbox,
16
14
  applyDecorators,
17
15
  getArtifactConfig,
18
16
  getCheckpointConfig,
19
- getContextWindowConfig,
20
17
  getConversationConfig,
21
18
  getHooks,
22
19
  getHooksByPoint,
@@ -24,20 +21,25 @@ import {
24
21
  getMainLoop,
25
22
  getObservableByChannel,
26
23
  getObservables,
27
- getProjectContextConfig,
28
24
  getSandboxConfig,
29
25
  getToolConfig,
30
26
  getToolMethods,
31
27
  getToolboxConfig,
32
28
  isCommandAllowed,
33
29
  isPathAllowed
34
- } from "./chunk-VKHDADMG.js";
30
+ } from "./chunk-XWVZS2PQ.js";
35
31
  import {
32
+ AgentRunner,
33
+ AgentRunnerBuilder,
36
34
  AgentWarningCode,
37
35
  BudgetExceededError,
36
+ DEFAULT_MAX_ITERATIONS,
38
37
  DelegationError,
39
38
  agentsPlugin,
40
39
  compileAgent,
40
+ compileContextWindow,
41
+ compileProjectContext,
42
+ compileSkills,
41
43
  compileTools,
42
44
  createAgentExecutionContext,
43
45
  createSdkAgentStream,
@@ -51,37 +53,49 @@ import {
51
53
  isTextDelta,
52
54
  isToolCall,
53
55
  isToolResult,
56
+ ladderReflectionStrategy,
57
+ loopStrategyConfigSchema,
58
+ noopReflectionStrategy,
59
+ projectContextMetadataOnlyKnobs,
60
+ reflectionStrategyConfigSchema,
61
+ resolveLoopStrategy,
54
62
  streamAgentResponse,
55
63
  translateSdkEvent,
56
64
  validateUniqueRoutes,
57
65
  walkAgentMetadata
58
- } from "./chunk-NC5EE7HN.js";
66
+ } from "./chunk-KTYBQ7HY.js";
59
67
  import {
60
68
  Agent,
61
69
  Audit,
62
70
  Budget,
71
+ ContextWindow,
63
72
  Gateway,
64
73
  MCP,
65
74
  Memory,
66
75
  Mixin,
67
76
  Policy,
77
+ ProjectContext,
68
78
  RequiresApproval,
69
79
  RequiresCapability,
70
80
  Skills,
71
81
  SubAgents,
72
82
  Trace,
73
83
  getAgentConfig,
84
+ getContextWindowConfig,
74
85
  getGatewayConfig,
75
86
  getMcpConfig,
76
87
  getMemoryConfig,
77
88
  getMixins,
89
+ getProjectContextConfig,
78
90
  getSkillsConfig,
79
91
  getSubAgents,
80
92
  resolveSessionId
81
- } from "./chunk-O4UG4RXE.js";
93
+ } from "./chunk-MVEY7HEY.js";
82
94
  import "./chunk-7QVYU63E.js";
83
95
  export {
84
96
  Agent,
97
+ AgentRunner,
98
+ AgentRunnerBuilder,
85
99
  AgentWarningCode,
86
100
  Artifact,
87
101
  Audit,
@@ -90,6 +104,7 @@ export {
90
104
  Checkpoint,
91
105
  ContextWindow,
92
106
  Conversation,
107
+ DEFAULT_MAX_ITERATIONS,
93
108
  DelegationError,
94
109
  EditFormat,
95
110
  Gateway,
@@ -114,6 +129,9 @@ export {
114
129
  agentsPlugin,
115
130
  applyDecorators,
116
131
  compileAgent,
132
+ compileContextWindow,
133
+ compileProjectContext,
134
+ compileSkills,
117
135
  compileTools,
118
136
  createAgentExecutionContext,
119
137
  createSdkAgentStream,
@@ -151,6 +169,12 @@ export {
151
169
  isTextDelta,
152
170
  isToolCall,
153
171
  isToolResult,
172
+ ladderReflectionStrategy,
173
+ loopStrategyConfigSchema,
174
+ noopReflectionStrategy,
175
+ projectContextMetadataOnlyKnobs,
176
+ reflectionStrategyConfigSchema,
177
+ resolveLoopStrategy,
154
178
  resolveSessionId,
155
179
  streamAgentResponse,
156
180
  translateSdkEvent,
@@ -66,6 +66,22 @@ type PolicyHandler = (user: {
66
66
  roles: string[];
67
67
  }) => boolean;
68
68
 
69
+ type ContextCompactionStrategy = 'truncate-oldest' | 'summarize-oldest' | 'sliding-window' | 'priority-based';
70
+ interface ContextWindowOptions {
71
+ /** Maximum tokens before compaction triggers. */
72
+ maxTokens?: number;
73
+ /** How to compact when maxTokens is exceeded. */
74
+ compactionStrategy?: ContextCompactionStrategy;
75
+ /** Always preserve the system prompt during compaction (default: true). */
76
+ preserveSystemPrompt?: boolean;
77
+ /** Number of recent messages to always keep intact (default: 10). */
78
+ preserveLastN?: number;
79
+ /** Keep all tool results even during compaction (default: true). */
80
+ preserveToolResults?: boolean;
81
+ }
82
+ declare function ContextWindow(options?: ContextWindowOptions): ClassDecorator;
83
+ declare function getContextWindowConfig(target: Function): ContextWindowOptions | undefined;
84
+
69
85
  type PlatformName = 'telegram' | 'discord' | 'slack' | 'whatsapp' | 'teams' | 'email' | 'sms' | 'mattermost' | 'line' | 'matrix';
70
86
  type SessionStrategy = 'per-user' | 'per-channel' | 'per-thread';
71
87
  interface GatewayOptions {
@@ -92,6 +108,20 @@ declare function resolveSessionId(strategy: SessionStrategy, platform: string, s
92
108
  topicId?: string;
93
109
  }): string;
94
110
 
111
+ interface McpServerConfig {
112
+ /** Command to start the MCP server. */
113
+ command: string;
114
+ /** Arguments passed to the command. */
115
+ args?: string[];
116
+ /** Environment variables for the server process. */
117
+ env?: Record<string, string>;
118
+ /** Working directory for the server process. */
119
+ cwd?: string;
120
+ }
121
+ type McpServersMap = Record<string, McpServerConfig>;
122
+ declare function MCP(servers: McpServersMap): ClassDecorator;
123
+ declare function getMcpConfig(target: Function): McpServersMap | undefined;
124
+
95
125
  type MemoryProvider = 'built-in' | 'honcho' | 'supermemory' | 'mem0';
96
126
  type MemoryScope = 'per-user' | 'per-agent' | 'per-tenant' | 'global';
97
127
  interface MemoryOptions {
@@ -109,6 +139,25 @@ interface MemoryOptions {
109
139
  declare function Memory(options?: MemoryOptions): ClassDecorator;
110
140
  declare function getMemoryConfig(target: Function): MemoryOptions | undefined;
111
141
 
142
+ type IndexStrategy = 'tree-sitter' | 'regex' | 'none';
143
+ type RelevanceStrategy = 'git-history' | 'import-graph' | 'semantic' | 'manual';
144
+ interface ProjectContextOptions {
145
+ /** Files that mark the project root (searched upward from cwd). */
146
+ rootMarkers?: string[];
147
+ /** How to index the codebase for structural understanding. */
148
+ indexStrategy?: IndexStrategy;
149
+ /** Maximum files to include in context per request. */
150
+ maxFilesInContext?: number;
151
+ /** How to rank file relevance when selecting context. */
152
+ relevanceStrategy?: RelevanceStrategy;
153
+ /** Glob patterns to exclude from indexing and context. */
154
+ ignorePatterns?: string[];
155
+ /** File extensions to include in indexing (default: all text files). */
156
+ includeExtensions?: string[];
157
+ }
158
+ declare function ProjectContext(options?: ProjectContextOptions): ClassDecorator;
159
+ declare function getProjectContextConfig(target: Function): ProjectContextOptions | undefined;
160
+
112
161
  interface SkillsOptions {
113
162
  /** Skill names to include (resolved from .theokit/skills/<name>/SKILL.md). */
114
163
  include: string[];
@@ -118,18 +167,4 @@ interface SkillsOptions {
118
167
  declare function Skills(namesOrOptions: string[] | SkillsOptions): ClassDecorator;
119
168
  declare function getSkillsConfig(target: Function): SkillsOptions | undefined;
120
169
 
121
- interface McpServerConfig {
122
- /** Command to start the MCP server. */
123
- command: string;
124
- /** Arguments passed to the command. */
125
- args?: string[];
126
- /** Environment variables for the server process. */
127
- env?: Record<string, string>;
128
- /** Working directory for the server process. */
129
- cwd?: string;
130
- }
131
- type McpServersMap = Record<string, McpServerConfig>;
132
- declare function MCP(servers: McpServersMap): ClassDecorator;
133
- declare function getMcpConfig(target: Function): McpServersMap | undefined;
134
-
135
- export { type AgentOptions as A, type BudgetOptions as B, Gateway as G, MCP as M, type PlatformName as P, type SessionStrategy as S, type ToolOptions as T, type ApprovalOptions as a, type GatewayOptions as b, type MainLoopMeta as c, type MainLoopOptions as d, type McpServerConfig as e, type McpServersMap as f, Memory as g, type MemoryOptions as h, type MemoryProvider as i, type MemoryScope as j, type PolicyHandler as k, Skills as l, type SkillsOptions as m, type ToolboxOptions as n, getGatewayConfig as o, getMcpConfig as p, getMemoryConfig as q, getSkillsConfig as r, resolveSessionId as s };
170
+ export { type AgentOptions as A, type BudgetOptions as B, type ContextCompactionStrategy as C, Gateway as G, type IndexStrategy as I, type MainLoopMeta as M, type PlatformName as P, type RelevanceStrategy as R, type SessionStrategy as S, type ToolOptions as T, type ApprovalOptions as a, ContextWindow as b, type ContextWindowOptions as c, type GatewayOptions as d, MCP as e, type MainLoopOptions as f, type McpServerConfig as g, type McpServersMap as h, Memory as i, type MemoryOptions as j, type MemoryProvider as k, type MemoryScope as l, type PolicyHandler as m, ProjectContext as n, type ProjectContextOptions as o, Skills as p, type SkillsOptions as q, type ToolboxOptions as r, getContextWindowConfig as s, getGatewayConfig as t, getMcpConfig as u, getMemoryConfig as v, getProjectContextConfig as w, getSkillsConfig as x, resolveSessionId as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theokit/agents",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Unified decorator runtime — AI agents as first-class citizens of the TheoKit pipeline. @Agent() compiles to SDK Agent.create(), @Tool() compiles to defineTool().",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -36,16 +36,27 @@
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@theokit/http": ">=0.1.0-alpha.0",
39
- "@theokit/sdk": ">=1.5.0",
39
+ "@theokit/sdk": ">=2.5.0",
40
+ "@theokit/sdk-tools": ">=0.2.0",
40
41
  "reflect-metadata": ">=0.2.0",
41
42
  "zod": "^4.0.0"
42
43
  },
44
+ "peerDependenciesMeta": {
45
+ "@theokit/sdk-tools": {
46
+ "optional": true
47
+ }
48
+ },
43
49
  "devDependencies": {
44
50
  "@theokit/http": "workspace:*",
45
- "reflect-metadata": "^0.2.0",
46
- "zod": "^4.0.0",
47
- "tsup": "^8.0.0",
48
- "typescript": "^5.5.0",
49
- "vitest": "^3.0.0"
51
+ "@theokit/sdk": "^2.5.0",
52
+ "@theokit/sdk-tools": "^0.2.0",
53
+ "reflect-metadata": "^0.2.2",
54
+ "tsup": "^8.5.1",
55
+ "typescript": "^5.9.3",
56
+ "vitest": "^3.2.6",
57
+ "zod": "^4.4.3"
58
+ },
59
+ "engines": {
60
+ "node": ">=22.12.0"
50
61
  }
51
62
  }