@theokit/agents 0.3.0 → 0.5.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 CHANGED
@@ -1,5 +1,6 @@
1
- import { ExecutionContext } from '@theokit/http-decorators';
2
- import { A as AgentOptions, T as ToolOptions, c as MainLoopMeta, a as ApprovalOptions, B as BudgetOptions, b as GatewayOptions, h as MemoryOptions, m as SkillsOptions, f as McpServersMap } from './mcp-DmtwLSF-.js';
1
+ import { ExecutionContext } from '@theokit/http';
2
+ import { A as AgentOptions, T as ToolOptions, e 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-DnfvEUSg.js';
3
+ import { SkillsSettings, ContextSettings, SystemPromptResolver } from '@theokit/sdk';
3
4
  import 'zod';
4
5
 
5
6
  /**
@@ -36,6 +37,17 @@ declare function isAgentContext(ctx: ExecutionContext): ctx is AgentExecutionCon
36
37
  * EC-4: throws on duplicate routes across agents.
37
38
  */
38
39
 
40
+ /**
41
+ * Stable warning codes for agent pipeline metadata-only decorators.
42
+ * Test by code, not by message string. Document in agent support matrix.
43
+ */
44
+ declare const AgentWarningCode: {
45
+ readonly INTERCEPTOR_METADATA_ONLY: "THEO_AGENT_INTERCEPTOR_METADATA_ONLY";
46
+ readonly FILTER_METADATA_ONLY: "THEO_AGENT_FILTER_METADATA_ONLY";
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";
50
+ };
39
51
  interface AgentWalkResult {
40
52
  agentConfig: AgentOptions;
41
53
  mainLoop: MainLoopMeta;
@@ -48,6 +60,8 @@ interface AgentWalkResult {
48
60
  subAgentClasses: Function[];
49
61
  memory?: MemoryOptions;
50
62
  skills?: SkillsOptions;
63
+ contextWindow?: ContextWindowOptions;
64
+ projectContext?: ProjectContextOptions;
51
65
  mcpServers?: McpServersMap;
52
66
  }
53
67
  interface ToolboxWalkResult {
@@ -80,6 +94,15 @@ declare function walkAgentMetadata(AgentClass: Function, toolboxClasses?: Functi
80
94
  */
81
95
  declare function validateUniqueRoutes(results: AgentWalkResult[]): void;
82
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
+
83
106
  /** Minimal interface matching defineTool() result shape. */
84
107
  interface CompiledTool {
85
108
  name: string;
@@ -106,7 +129,10 @@ interface CompiledAgentOptions {
106
129
  tools: CompiledTool[];
107
130
  agents: Record<string, CompiledSubAgent>;
108
131
  memory?: MemoryOptions;
109
- skills?: SkillsOptions;
132
+ skills?: SkillsSettings;
133
+ context?: ContextSettings;
134
+ /** Raw @ProjectContext config; the adapter builds the (async) systemPrompt resolver from it. */
135
+ projectContext?: ProjectContextOptions;
110
136
  mcpServers?: McpServersMap;
111
137
  maxIterations?: number;
112
138
  timeoutMs?: number;
@@ -119,6 +145,69 @@ interface CompiledAgentOptions {
119
145
  */
120
146
  declare function compileAgent(walkResult: AgentWalkResult, toolboxInstances?: Map<Function, object>): CompiledAgentOptions;
121
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
+
122
211
  /**
123
212
  * SSE streaming handler — Web Standard Response with ReadableStream.
124
213
  *
@@ -291,18 +380,39 @@ interface AgentRouteContext {
291
380
  declare function generateAgentRoutes(ctx: AgentRouteContext): AgentRoute[];
292
381
 
293
382
  /**
294
- * Real LLM Agent Runner v1.1 all 7 dogfood gaps fixed.
383
+ * Creates an agent stream factory using @theokit/sdk as the runtime.
295
384
  *
296
- * 1. Token-by-token streaming (stream: true + SSE delta parsing + EC-1 buffer safety)
297
- * 2. Multi-turn conversation (session Map + EC-2 TTL eviction)
298
- * 3. Model from decorator metadata (EC-5 provider prefix auto-detect)
299
- * 4. Consistent tool names (dot ↔ underscore bidirectional mapping)
300
- * 5. Robust Zod→JSON Schema via Zod v4 native z.toJSONSchema()
301
- * 6. Budget enforcement (per-session cost tracking from EC-3 last-chunk usage)
302
- * 7. AbortController cancel (EC-4 race-safe signal.aborted check)
385
+ * Returns a function that, given a message + sessionId, yields TheoKit
386
+ * AgentStreamEvent via the SDK's Agent.create() + Run.stream() pipeline.
303
387
  */
388
+ declare function createSdkAgentStream(compiled: CompiledAgentOptions, compiledTools: CompiledTool[], apiKey: string, envModel?: string): (message: string, _sessionId: string) => AsyncIterable<StreamEvent>;
304
389
 
305
- declare function createRealAgentStream(agentWalk: AgentWalkResult, compiledTools: CompiledTool[], apiKey: string, envModel?: string): (message: string, sessionId: string) => AsyncIterable<StreamEvent>;
390
+ /**
391
+ * Translates @theokit/sdk SDKMessage events → TheoKit AgentStreamEvent.
392
+ *
393
+ * The SDK yields SDKMessage (system/assistant/tool_call/thinking/status).
394
+ * TheoKit devtools + SSE handler expect AgentStreamEvent (run_started/text_delta/tool_call/done).
395
+ * This module bridges the two — Adapter pattern (per sdk-integration-blueprint ADR-D2).
396
+ */
397
+
398
+ /** Minimal SDK message shape — duck-typed to avoid hard import of @theokit/sdk types. */
399
+ interface SdkMessage {
400
+ type: string;
401
+ [key: string]: unknown;
402
+ }
403
+ /**
404
+ * Translate a single SDK message to zero or more TheoKit stream events.
405
+ * Returns an array because one SDK message may map to multiple TheoKit events.
406
+ */
407
+ declare function translateSdkEvent(msg: SdkMessage, runId: string): StreamEvent[];
408
+
409
+ /**
410
+ * Multi-agent orchestration runtime.
411
+ *
412
+ * Provides `delegate()` — a function that lets a parent agent invoke a
413
+ * sub-agent and receive its result. Handles budget clamping (D4),
414
+ * tool sharing, and toolbox auto-instantiation (EC-1).
415
+ */
306
416
 
307
417
  interface DelegateOptions {
308
418
  /** Max USD for this sub-agent call. */
@@ -419,7 +529,7 @@ interface AgentsPluginOptions {
419
529
  interface PluginApp {
420
530
  addHook(name: string, fn: (ctx: {
421
531
  request: Request;
422
- }) => Promise<Response | void>): void;
532
+ }) => Promise<Response | undefined>): void;
423
533
  }
424
534
  /**
425
535
  * Create a TheoKit plugin that mounts agent routes.
@@ -430,4 +540,4 @@ declare function agentsPlugin(opts: AgentsPluginOptions): {
430
540
  register(app: PluginApp): void;
431
541
  };
432
542
 
433
- export { type AgentExecutionContext, type AgentManifest, type AgentManifestEntry, type AgentManifestTool, type AgentRoute, type AgentRouteContext, type AgentRunInfo, type AgentStreamEvent, type AgentWalkResult, 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 StateUpdateEvent, type StreamEvent, type TextDeltaEvent, type ThinkingEvent, type ToolCallEvent, type ToolResultEvent, type ToolWalkResult, type ToolboxWalkResult, agentsPlugin, compileAgent, compileTools, createAgentExecutionContext, createRealAgentStream, delegate, generateAgentManifest, generateAgentRoutes, isAgentContext, isApprovalRequired, isDone, isError, isTextDelta, isToolCall, isToolResult, streamAgentResponse, validateUniqueRoutes, walkAgentMetadata };
543
+ 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
@@ -1,11 +1,15 @@
1
1
  import {
2
+ AgentWarningCode,
2
3
  BudgetExceededError,
3
4
  DelegationError,
4
5
  agentsPlugin,
5
6
  compileAgent,
7
+ compileContextWindow,
8
+ compileProjectContext,
9
+ compileSkills,
6
10
  compileTools,
7
11
  createAgentExecutionContext,
8
- createRealAgentStream,
12
+ createSdkAgentStream,
9
13
  delegate,
10
14
  generateAgentManifest,
11
15
  generateAgentRoutes,
@@ -16,19 +20,26 @@ import {
16
20
  isTextDelta,
17
21
  isToolCall,
18
22
  isToolResult,
23
+ projectContextMetadataOnlyKnobs,
19
24
  streamAgentResponse,
25
+ translateSdkEvent,
20
26
  validateUniqueRoutes,
21
27
  walkAgentMetadata
22
- } from "./chunk-SWPOX3LR.js";
23
- import "./chunk-3LCIXX3T.js";
28
+ } from "./chunk-2MI27XCA.js";
29
+ import "./chunk-MVEY7HEY.js";
30
+ import "./chunk-7QVYU63E.js";
24
31
  export {
32
+ AgentWarningCode,
25
33
  BudgetExceededError,
26
34
  DelegationError,
27
35
  agentsPlugin,
28
36
  compileAgent,
37
+ compileContextWindow,
38
+ compileProjectContext,
39
+ compileSkills,
29
40
  compileTools,
30
41
  createAgentExecutionContext,
31
- createRealAgentStream,
42
+ createSdkAgentStream,
32
43
  delegate,
33
44
  generateAgentManifest,
34
45
  generateAgentRoutes,
@@ -39,7 +50,9 @@ export {
39
50
  isTextDelta,
40
51
  isToolCall,
41
52
  isToolResult,
53
+ projectContextMetadataOnlyKnobs,
42
54
  streamAgentResponse,
55
+ translateSdkEvent,
43
56
  validateUniqueRoutes,
44
57
  walkAgentMetadata
45
58
  };