@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.
- package/dist/bridge.d.ts +111 -30
- package/dist/bridge.js +10 -2
- package/dist/{chunk-NC5EE7HN.js → chunk-KTYBQ7HY.js} +429 -79
- package/dist/chunk-KTYBQ7HY.js.map +1 -0
- package/dist/{chunk-O4UG4RXE.js → chunk-MVEY7HEY.js} +58 -1
- package/dist/chunk-MVEY7HEY.js.map +1 -0
- package/dist/{chunk-VKHDADMG.js → chunk-XWVZS2PQ.js} +2 -59
- package/dist/chunk-XWVZS2PQ.js.map +1 -0
- package/dist/decorators.d.ts +3 -38
- package/dist/decorators.js +6 -6
- package/dist/index.d.ts +199 -4
- package/dist/index.js +31 -7
- package/dist/{mcp-yyfC5u7t.d.ts → skills-DmN1HGUb.d.ts} +50 -15
- package/package.json +18 -7
- package/dist/chunk-NC5EE7HN.js.map +0 -1
- package/dist/chunk-O4UG4RXE.js.map +0 -1
- package/dist/chunk-VKHDADMG.js.map +0 -1
package/dist/bridge.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ExecutionContext } from '@theokit/http';
|
|
2
|
-
import { A as AgentOptions, T as ToolOptions,
|
|
2
|
+
import { A as AgentOptions, T as ToolOptions, M as MainLoopMeta, a as ApprovalOptions, B as BudgetOptions, d as GatewayOptions, j as MemoryOptions, q as SkillsOptions, c as ContextWindowOptions, o as ProjectContextOptions, h as McpServersMap } from './skills-DmN1HGUb.js';
|
|
3
|
+
import { SkillsSettings, ContextSettings, SystemPromptResolver } from '@theokit/sdk';
|
|
3
4
|
import 'zod';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -44,6 +45,8 @@ declare const AgentWarningCode: {
|
|
|
44
45
|
readonly INTERCEPTOR_METADATA_ONLY: "THEO_AGENT_INTERCEPTOR_METADATA_ONLY";
|
|
45
46
|
readonly FILTER_METADATA_ONLY: "THEO_AGENT_FILTER_METADATA_ONLY";
|
|
46
47
|
readonly BUDGET_TOP_LEVEL_METADATA_ONLY: "THEO_AGENT_BUDGET_TOP_LEVEL_METADATA_ONLY";
|
|
48
|
+
readonly CONTEXT_STRATEGY_METADATA_ONLY: "THEO_AGENT_CONTEXT_STRATEGY_METADATA_ONLY";
|
|
49
|
+
readonly PROJECT_CONTEXT_KNOB_METADATA_ONLY: "THEO_AGENT_PROJECT_CONTEXT_KNOB_METADATA_ONLY";
|
|
47
50
|
};
|
|
48
51
|
interface AgentWalkResult {
|
|
49
52
|
agentConfig: AgentOptions;
|
|
@@ -57,6 +60,8 @@ interface AgentWalkResult {
|
|
|
57
60
|
subAgentClasses: Function[];
|
|
58
61
|
memory?: MemoryOptions;
|
|
59
62
|
skills?: SkillsOptions;
|
|
63
|
+
contextWindow?: ContextWindowOptions;
|
|
64
|
+
projectContext?: ProjectContextOptions;
|
|
60
65
|
mcpServers?: McpServersMap;
|
|
61
66
|
}
|
|
62
67
|
interface ToolboxWalkResult {
|
|
@@ -89,6 +94,15 @@ declare function walkAgentMetadata(AgentClass: Function, toolboxClasses?: Functi
|
|
|
89
94
|
*/
|
|
90
95
|
declare function validateUniqueRoutes(results: AgentWalkResult[]): void;
|
|
91
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Agent compiler — transforms decorator metadata into SDK calls.
|
|
99
|
+
*
|
|
100
|
+
* Per ADR D1: @Agent is a macro over Agent.create().
|
|
101
|
+
* Per ADR D3: @Tool compiles to defineTool().
|
|
102
|
+
*
|
|
103
|
+
* EC-3: throws if toolbox instance is missing from the instances map.
|
|
104
|
+
*/
|
|
105
|
+
|
|
92
106
|
/** Minimal interface matching defineTool() result shape. */
|
|
93
107
|
interface CompiledTool {
|
|
94
108
|
name: string;
|
|
@@ -115,7 +129,10 @@ interface CompiledAgentOptions {
|
|
|
115
129
|
tools: CompiledTool[];
|
|
116
130
|
agents: Record<string, CompiledSubAgent>;
|
|
117
131
|
memory?: MemoryOptions;
|
|
118
|
-
skills?:
|
|
132
|
+
skills?: SkillsSettings;
|
|
133
|
+
context?: ContextSettings;
|
|
134
|
+
/** Raw @ProjectContext config; the adapter builds the (async) systemPrompt resolver from it. */
|
|
135
|
+
projectContext?: ProjectContextOptions;
|
|
119
136
|
mcpServers?: McpServersMap;
|
|
120
137
|
maxIterations?: number;
|
|
121
138
|
timeoutMs?: number;
|
|
@@ -128,6 +145,69 @@ interface CompiledAgentOptions {
|
|
|
128
145
|
*/
|
|
129
146
|
declare function compileAgent(walkResult: AgentWalkResult, toolboxInstances?: Map<Function, object>): CompiledAgentOptions;
|
|
130
147
|
|
|
148
|
+
/**
|
|
149
|
+
* M8-3 — compile `@Skills` metadata into the SDK's `SkillsSettings`.
|
|
150
|
+
*
|
|
151
|
+
* Per sdk-runtime.md: the bridge COMPILES decorator metadata into a format the
|
|
152
|
+
* SDK accepts; the SDK is the runtime. `Agent.create({ skills })` natively
|
|
153
|
+
* discovers `.theokit/skills/<name>/SKILL.md` files and injects the `<skills>`
|
|
154
|
+
* block — so giving `@Skills` runtime is a pure shape translation, not a
|
|
155
|
+
* reimplementation of discovery.
|
|
156
|
+
*
|
|
157
|
+
* Mapping (ADR D4):
|
|
158
|
+
* - `{ include }` → `{ enabled: include, autoInject: true }`
|
|
159
|
+
* - `{ autoDiscover: true }` → `{ autoInject: true }` (enabled omitted ⇒ the SDK
|
|
160
|
+
* enables every discovered skill)
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
declare function compileSkills(options: SkillsOptions): SkillsSettings;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* M8-1 — compile `@ContextWindow` metadata into the SDK's `ContextSettings`.
|
|
167
|
+
*
|
|
168
|
+
* Per sdk-runtime.md, the SDK owns session/transcript storage + compaction.
|
|
169
|
+
* The bridge therefore maps the one knob the SDK natively exposes as a budget —
|
|
170
|
+
* `maxTokens` → `ContextSettings.maxTokens` — and reports the strategy knobs that
|
|
171
|
+
* have NO native `AgentOptions` equivalent (`compactionStrategy`, `preserveLastN`,
|
|
172
|
+
* `preserveToolResults`, `preserveSystemPrompt`). Those are surfaced as
|
|
173
|
+
* `metadataOnlyKnobs` so the walk can emit an honest `metadata-only` warning
|
|
174
|
+
* (ADR D2) instead of silently dropping them (G10 — honest enforcement).
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
interface CompiledContextWindow {
|
|
178
|
+
/** SDK-shaped context budget passed to `Agent.create({ context })`. */
|
|
179
|
+
context: ContextSettings;
|
|
180
|
+
/** Declared knobs the SDK does not expose — reported, never silently dropped. */
|
|
181
|
+
metadataOnlyKnobs: string[];
|
|
182
|
+
}
|
|
183
|
+
declare function compileContextWindow(options: ContextWindowOptions): CompiledContextWindow;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* M8-2 — compile `@ProjectContext` metadata into an SDK `SystemPromptResolver`.
|
|
187
|
+
*
|
|
188
|
+
* There is no native `AgentOptions` field that carries a repo map, so the bridge
|
|
189
|
+
* composes the documented `systemPrompt` seam (`string | SystemPromptResolver`):
|
|
190
|
+
* the resolver prepends `buildEnvContext` + `buildRepoMap` (`@theokit/sdk-tools`)
|
|
191
|
+
* and the nearest `THEO.md` (`@theokit/sdk/project#readProjectInstructions`) to
|
|
192
|
+
* the agent's base prompt (ADR D3). The SDK primitives are dynamically imported
|
|
193
|
+
* so `@theokit/sdk-tools` stays an OPTIONAL peer — only loaded when a `@ProjectContext`
|
|
194
|
+
* agent actually sends.
|
|
195
|
+
*
|
|
196
|
+
* Knobs with no primitive mapping (`indexStrategy`, `relevanceStrategy`,
|
|
197
|
+
* `maxFilesInContext`, `includeExtensions`, `rootMarkers`) are reported via
|
|
198
|
+
* {@link projectContextMetadataOnlyKnobs} so the walk warns honestly (G10).
|
|
199
|
+
* Only `ignorePatterns` is forwarded (to `buildRepoMap`).
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
declare function projectContextMetadataOnlyKnobs(options: ProjectContextOptions): string[];
|
|
203
|
+
/**
|
|
204
|
+
* Build a `SystemPromptResolver` that prepends env + repo map + project
|
|
205
|
+
* instructions to `base`. When the SDK provides no `cwd`, the resolver returns
|
|
206
|
+
* `base` unchanged (no filesystem guess — keeps `packages/agents/src` free of
|
|
207
|
+
* direct Node `process` access per G8; the repo map needs a real cwd).
|
|
208
|
+
*/
|
|
209
|
+
declare function compileProjectContext(options: ProjectContextOptions, base?: string): SystemPromptResolver;
|
|
210
|
+
|
|
131
211
|
/**
|
|
132
212
|
* SSE streaming handler — Web Standard Response with ReadableStream.
|
|
133
213
|
*
|
|
@@ -299,22 +379,13 @@ interface AgentRouteContext {
|
|
|
299
379
|
/** Generate HTTP routes for a single agent. Returns Web Standard handlers. */
|
|
300
380
|
declare function generateAgentRoutes(ctx: AgentRouteContext): AgentRoute[];
|
|
301
381
|
|
|
302
|
-
/**
|
|
303
|
-
* SDK Adapter — bridges @theokit/agents decorators → @theokit/sdk runtime.
|
|
304
|
-
*
|
|
305
|
-
* Per rule sdk-runtime.md (INQUEBRÁVEL): @theokit/sdk is the ONLY agent runtime.
|
|
306
|
-
* This adapter replaces llm-runner.ts (which called OpenRouter API directly).
|
|
307
|
-
*
|
|
308
|
-
* Flow: @Agent decorator → compileAgent() → createSdkAgentStream() → SDK Agent.create() → Run.stream()
|
|
309
|
-
*/
|
|
310
|
-
|
|
311
382
|
/**
|
|
312
383
|
* Creates an agent stream factory using @theokit/sdk as the runtime.
|
|
313
384
|
*
|
|
314
385
|
* Returns a function that, given a message + sessionId, yields TheoKit
|
|
315
386
|
* AgentStreamEvent via the SDK's Agent.create() + Run.stream() pipeline.
|
|
316
387
|
*/
|
|
317
|
-
declare function createSdkAgentStream(
|
|
388
|
+
declare function createSdkAgentStream(compiled: CompiledAgentOptions, compiledTools: CompiledTool[], apiKey: string, envModel?: string): (message: string, _sessionId: string) => AsyncIterable<StreamEvent>;
|
|
318
389
|
|
|
319
390
|
/**
|
|
320
391
|
* Translates @theokit/sdk SDKMessage events → TheoKit AgentStreamEvent.
|
|
@@ -336,25 +407,14 @@ interface SdkMessage {
|
|
|
336
407
|
declare function translateSdkEvent(msg: SdkMessage, runId: string): StreamEvent[];
|
|
337
408
|
|
|
338
409
|
/**
|
|
339
|
-
*
|
|
410
|
+
* Shared delegation value types + typed errors.
|
|
340
411
|
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
412
|
+
* Extracted from `agent-orchestrator.ts` so BOTH the orchestrator (`delegate`)
|
|
413
|
+
* and the loop driver (`loop/run-reflective-loop.ts`) can import them WITHOUT a
|
|
414
|
+
* cycle (orchestrator → loop → delegation-types; orchestrator → delegation-types;
|
|
415
|
+
* delegation-types depends on nothing — Acyclic Dependencies Principle, G1).
|
|
416
|
+
* `agent-orchestrator.ts` re-exports these for backward compatibility.
|
|
344
417
|
*/
|
|
345
|
-
|
|
346
|
-
interface DelegateOptions {
|
|
347
|
-
/** Max USD for this sub-agent call. */
|
|
348
|
-
budget?: number;
|
|
349
|
-
/** Parent's remaining budget (for clamping). */
|
|
350
|
-
parentBudgetRemaining?: number;
|
|
351
|
-
/** Parent's tools (for sharing — sub-agent inherits these). */
|
|
352
|
-
parentTools?: CompiledTool[];
|
|
353
|
-
/** LLM API key (inherited from parent). */
|
|
354
|
-
apiKey?: string;
|
|
355
|
-
/** Session ID override (default: crypto.randomUUID for isolation). */
|
|
356
|
-
sessionId?: string;
|
|
357
|
-
}
|
|
358
418
|
interface DelegationResult {
|
|
359
419
|
response: string;
|
|
360
420
|
toolCalls: {
|
|
@@ -364,6 +424,8 @@ interface DelegationResult {
|
|
|
364
424
|
}[];
|
|
365
425
|
cost: number;
|
|
366
426
|
tokens: number;
|
|
427
|
+
/** Rounds the reflective loop ran (set by `runReflectiveLoop`; absent for the single-shot path). */
|
|
428
|
+
rounds?: number;
|
|
367
429
|
}
|
|
368
430
|
declare class BudgetExceededError extends Error {
|
|
369
431
|
readonly agentName: string;
|
|
@@ -376,6 +438,21 @@ declare class DelegationError extends Error {
|
|
|
376
438
|
readonly cause: unknown;
|
|
377
439
|
constructor(agentName: string, cause: unknown);
|
|
378
440
|
}
|
|
441
|
+
|
|
442
|
+
interface DelegateOptions {
|
|
443
|
+
/** Max USD for this sub-agent call. */
|
|
444
|
+
budget?: number;
|
|
445
|
+
/** Parent's remaining budget (for clamping). */
|
|
446
|
+
parentBudgetRemaining?: number;
|
|
447
|
+
/** Parent's tools (for sharing — sub-agent inherits these). */
|
|
448
|
+
parentTools?: CompiledTool[];
|
|
449
|
+
/** LLM API key (inherited from parent). */
|
|
450
|
+
apiKey?: string;
|
|
451
|
+
/** Session ID override (default: crypto.randomUUID for isolation). */
|
|
452
|
+
sessionId?: string;
|
|
453
|
+
/** Cancellation — aborts stop the reflective loop from re-entering. */
|
|
454
|
+
signal?: AbortSignal;
|
|
455
|
+
}
|
|
379
456
|
/**
|
|
380
457
|
* Delegate a task to a sub-agent and collect its result.
|
|
381
458
|
*
|
|
@@ -383,6 +460,10 @@ declare class DelegationError extends Error {
|
|
|
383
460
|
* - Tool sharing: parent tools merged with sub-agent tools (sub wins on collision)
|
|
384
461
|
* - Toolbox auto-instantiation: sub-agent toolboxes instantiated without DI (EC-1)
|
|
385
462
|
* - Session isolation: each delegation gets a unique session ID (EC-4)
|
|
463
|
+
* - `@MainLoop` strategy runtime: routes through `runReflectiveLoop` (the same loop
|
|
464
|
+
* `AgentRunner.run` uses — one runtime for both on-ramps, ADR D4). The runtime
|
|
465
|
+
* metric (`THEO_AGENT_MAINLOOP_RUNTIME_APPLIED`) + typed-error + cumulative budget
|
|
466
|
+
* all live in the shared driver, so they fire identically on both paths.
|
|
386
467
|
*/
|
|
387
468
|
declare function delegate(SubAgentClass: Function, message: string, opts?: DelegateOptions): Promise<DelegationResult>;
|
|
388
469
|
|
|
@@ -469,4 +550,4 @@ declare function agentsPlugin(opts: AgentsPluginOptions): {
|
|
|
469
550
|
register(app: PluginApp): void;
|
|
470
551
|
};
|
|
471
552
|
|
|
472
|
-
export { type AgentExecutionContext, type AgentManifest, type AgentManifestEntry, type AgentManifestTool, type AgentRoute, type AgentRouteContext, type AgentRunInfo, type AgentStreamEvent, type AgentWalkResult, AgentWarningCode, type AgentsPluginOptions, type ApprovalRequiredEvent, type ArtifactChunkEvent, type ArtifactStartEvent, BudgetExceededError, type CheckpointSavedEvent, type CompiledAgentOptions, type CompiledTool, type DelegateOptions, DelegationError, type DelegationResult, type DoneEvent, type ErrorEvent, type FileEditEvent, type IterationEvent, type RunStartedEvent, type SdkMessage, type StateUpdateEvent, type StreamEvent, type TextDeltaEvent, type ThinkingEvent, type ToolCallEvent, type ToolResultEvent, type ToolWalkResult, type ToolboxWalkResult, agentsPlugin, compileAgent, compileTools, createAgentExecutionContext, createSdkAgentStream, delegate, generateAgentManifest, generateAgentRoutes, isAgentContext, isApprovalRequired, isDone, isError, isTextDelta, isToolCall, isToolResult, streamAgentResponse, translateSdkEvent, validateUniqueRoutes, walkAgentMetadata };
|
|
553
|
+
export { type AgentExecutionContext, type AgentManifest, type AgentManifestEntry, type AgentManifestTool, type AgentRoute, type AgentRouteContext, type AgentRunInfo, type AgentStreamEvent, type AgentWalkResult, AgentWarningCode, type AgentsPluginOptions, type ApprovalRequiredEvent, type ArtifactChunkEvent, type ArtifactStartEvent, BudgetExceededError, type CheckpointSavedEvent, type CompiledAgentOptions, type CompiledContextWindow, type CompiledTool, type DelegateOptions, DelegationError, type DelegationResult, type DoneEvent, type ErrorEvent, type FileEditEvent, type IterationEvent, type RunStartedEvent, type SdkMessage, type StateUpdateEvent, type StreamEvent, type TextDeltaEvent, type ThinkingEvent, type ToolCallEvent, type ToolResultEvent, type ToolWalkResult, type ToolboxWalkResult, agentsPlugin, compileAgent, compileContextWindow, compileProjectContext, compileSkills, compileTools, createAgentExecutionContext, createSdkAgentStream, delegate, generateAgentManifest, generateAgentRoutes, isAgentContext, isApprovalRequired, isDone, isError, isTextDelta, isToolCall, isToolResult, projectContextMetadataOnlyKnobs, streamAgentResponse, translateSdkEvent, validateUniqueRoutes, walkAgentMetadata };
|
package/dist/bridge.js
CHANGED
|
@@ -4,6 +4,9 @@ import {
|
|
|
4
4
|
DelegationError,
|
|
5
5
|
agentsPlugin,
|
|
6
6
|
compileAgent,
|
|
7
|
+
compileContextWindow,
|
|
8
|
+
compileProjectContext,
|
|
9
|
+
compileSkills,
|
|
7
10
|
compileTools,
|
|
8
11
|
createAgentExecutionContext,
|
|
9
12
|
createSdkAgentStream,
|
|
@@ -17,12 +20,13 @@ import {
|
|
|
17
20
|
isTextDelta,
|
|
18
21
|
isToolCall,
|
|
19
22
|
isToolResult,
|
|
23
|
+
projectContextMetadataOnlyKnobs,
|
|
20
24
|
streamAgentResponse,
|
|
21
25
|
translateSdkEvent,
|
|
22
26
|
validateUniqueRoutes,
|
|
23
27
|
walkAgentMetadata
|
|
24
|
-
} from "./chunk-
|
|
25
|
-
import "./chunk-
|
|
28
|
+
} from "./chunk-KTYBQ7HY.js";
|
|
29
|
+
import "./chunk-MVEY7HEY.js";
|
|
26
30
|
import "./chunk-7QVYU63E.js";
|
|
27
31
|
export {
|
|
28
32
|
AgentWarningCode,
|
|
@@ -30,6 +34,9 @@ export {
|
|
|
30
34
|
DelegationError,
|
|
31
35
|
agentsPlugin,
|
|
32
36
|
compileAgent,
|
|
37
|
+
compileContextWindow,
|
|
38
|
+
compileProjectContext,
|
|
39
|
+
compileSkills,
|
|
33
40
|
compileTools,
|
|
34
41
|
createAgentExecutionContext,
|
|
35
42
|
createSdkAgentStream,
|
|
@@ -43,6 +50,7 @@ export {
|
|
|
43
50
|
isTextDelta,
|
|
44
51
|
isToolCall,
|
|
45
52
|
isToolResult,
|
|
53
|
+
projectContextMetadataOnlyKnobs,
|
|
46
54
|
streamAgentResponse,
|
|
47
55
|
translateSdkEvent,
|
|
48
56
|
validateUniqueRoutes,
|