@theokit/agents 0.4.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 +84 -13
- package/dist/bridge.js +10 -2
- package/dist/{chunk-NC5EE7HN.js → chunk-2MI27XCA.js} +151 -8
- package/dist/chunk-2MI27XCA.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 +4 -3
- package/dist/index.js +15 -7
- package/dist/{mcp-yyfC5u7t.d.ts → skills-DnfvEUSg.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, 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
|
/**
|
|
@@ -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.
|
|
@@ -469,4 +540,4 @@ declare function agentsPlugin(opts: AgentsPluginOptions): {
|
|
|
469
540
|
register(app: PluginApp): void;
|
|
470
541
|
};
|
|
471
542
|
|
|
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 };
|
|
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
|
@@ -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-2MI27XCA.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,
|
|
@@ -9,14 +9,16 @@ import {
|
|
|
9
9
|
TOOL_METHODS,
|
|
10
10
|
Trace,
|
|
11
11
|
getAgentConfig,
|
|
12
|
+
getContextWindowConfig,
|
|
12
13
|
getGatewayConfig,
|
|
13
14
|
getMcpConfig,
|
|
14
15
|
getMemoryConfig,
|
|
15
16
|
getMeta,
|
|
16
17
|
getMixins,
|
|
18
|
+
getProjectContextConfig,
|
|
17
19
|
getSkillsConfig,
|
|
18
20
|
getSubAgents
|
|
19
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-MVEY7HEY.js";
|
|
20
22
|
import {
|
|
21
23
|
__name
|
|
22
24
|
} from "./chunk-7QVYU63E.js";
|
|
@@ -40,6 +42,68 @@ function isAgentContext(ctx) {
|
|
|
40
42
|
}
|
|
41
43
|
__name(isAgentContext, "isAgentContext");
|
|
42
44
|
|
|
45
|
+
// src/bridge/compile-context-window.ts
|
|
46
|
+
var STRATEGY_KNOBS = [
|
|
47
|
+
"compactionStrategy",
|
|
48
|
+
"preserveLastN",
|
|
49
|
+
"preserveToolResults",
|
|
50
|
+
"preserveSystemPrompt"
|
|
51
|
+
];
|
|
52
|
+
function compileContextWindow(options) {
|
|
53
|
+
const context = {};
|
|
54
|
+
if (typeof options.maxTokens === "number") {
|
|
55
|
+
context.maxTokens = options.maxTokens;
|
|
56
|
+
}
|
|
57
|
+
const opts = options;
|
|
58
|
+
const metadataOnlyKnobs = STRATEGY_KNOBS.filter((knob) => opts[knob] !== void 0);
|
|
59
|
+
return {
|
|
60
|
+
context,
|
|
61
|
+
metadataOnlyKnobs
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
__name(compileContextWindow, "compileContextWindow");
|
|
65
|
+
|
|
66
|
+
// src/bridge/compile-project-context.ts
|
|
67
|
+
var UNMAPPED_KNOBS = [
|
|
68
|
+
"indexStrategy",
|
|
69
|
+
"relevanceStrategy",
|
|
70
|
+
"maxFilesInContext",
|
|
71
|
+
"includeExtensions",
|
|
72
|
+
"rootMarkers"
|
|
73
|
+
];
|
|
74
|
+
function projectContextMetadataOnlyKnobs(options) {
|
|
75
|
+
const opts = options;
|
|
76
|
+
return UNMAPPED_KNOBS.filter((knob) => opts[knob] !== void 0);
|
|
77
|
+
}
|
|
78
|
+
__name(projectContextMetadataOnlyKnobs, "projectContextMetadataOnlyKnobs");
|
|
79
|
+
function compileProjectContext(options, base) {
|
|
80
|
+
return async (promptCtx) => {
|
|
81
|
+
const cwd = promptCtx.cwd;
|
|
82
|
+
if (!cwd) {
|
|
83
|
+
return base ?? "";
|
|
84
|
+
}
|
|
85
|
+
const { buildEnvContext, buildRepoMap } = await import("@theokit/sdk-tools");
|
|
86
|
+
const { readProjectInstructions } = await import("@theokit/sdk/project");
|
|
87
|
+
const env = buildEnvContext(cwd);
|
|
88
|
+
const repoMap = buildRepoMap(cwd, {
|
|
89
|
+
ignore: options.ignorePatterns
|
|
90
|
+
});
|
|
91
|
+
let instructions = "";
|
|
92
|
+
try {
|
|
93
|
+
instructions = (await readProjectInstructions(cwd)).content ?? "";
|
|
94
|
+
} catch {
|
|
95
|
+
instructions = "";
|
|
96
|
+
}
|
|
97
|
+
return [
|
|
98
|
+
env,
|
|
99
|
+
repoMap,
|
|
100
|
+
instructions,
|
|
101
|
+
base
|
|
102
|
+
].filter(Boolean).join("\n\n");
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
__name(compileProjectContext, "compileProjectContext");
|
|
106
|
+
|
|
43
107
|
// src/bridge/walk-agent-metadata.ts
|
|
44
108
|
import "reflect-metadata";
|
|
45
109
|
import { Reflector } from "@theokit/http";
|
|
@@ -49,7 +113,9 @@ var USE_FILTERS = /* @__PURE__ */ Symbol.for("theokit:http-decorators:use-filter
|
|
|
49
113
|
var AgentWarningCode = {
|
|
50
114
|
INTERCEPTOR_METADATA_ONLY: "THEO_AGENT_INTERCEPTOR_METADATA_ONLY",
|
|
51
115
|
FILTER_METADATA_ONLY: "THEO_AGENT_FILTER_METADATA_ONLY",
|
|
52
|
-
BUDGET_TOP_LEVEL_METADATA_ONLY: "THEO_AGENT_BUDGET_TOP_LEVEL_METADATA_ONLY"
|
|
116
|
+
BUDGET_TOP_LEVEL_METADATA_ONLY: "THEO_AGENT_BUDGET_TOP_LEVEL_METADATA_ONLY",
|
|
117
|
+
CONTEXT_STRATEGY_METADATA_ONLY: "THEO_AGENT_CONTEXT_STRATEGY_METADATA_ONLY",
|
|
118
|
+
PROJECT_CONTEXT_KNOB_METADATA_ONLY: "THEO_AGENT_PROJECT_CONTEXT_KNOB_METADATA_ONLY"
|
|
53
119
|
};
|
|
54
120
|
var reflectorInstance = new Reflector();
|
|
55
121
|
function walkToolbox(ToolboxClass) {
|
|
@@ -88,6 +154,21 @@ function walkToolbox(ToolboxClass) {
|
|
|
88
154
|
};
|
|
89
155
|
}
|
|
90
156
|
__name(walkToolbox, "walkToolbox");
|
|
157
|
+
function warnUnmappedDecoratorKnobs(agentName, contextWindow, projectContext) {
|
|
158
|
+
if (contextWindow) {
|
|
159
|
+
const { metadataOnlyKnobs } = compileContextWindow(contextWindow);
|
|
160
|
+
if (metadataOnlyKnobs.length > 0) {
|
|
161
|
+
console.warn(`[${AgentWarningCode.CONTEXT_STRATEGY_METADATA_ONLY}] Agent ${agentName}: @ContextWindow knob(s) ${metadataOnlyKnobs.join(", ")} are metadata-only \u2014 the SDK manages transcript compaction internally. Only maxTokens is forwarded to Agent.create({ context }).`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (projectContext) {
|
|
165
|
+
const unmapped = projectContextMetadataOnlyKnobs(projectContext);
|
|
166
|
+
if (unmapped.length > 0) {
|
|
167
|
+
console.warn(`[${AgentWarningCode.PROJECT_CONTEXT_KNOB_METADATA_ONLY}] Agent ${agentName}: @ProjectContext knob(s) ${unmapped.join(", ")} are metadata-only \u2014 the repo map is composed via buildRepoMap/buildEnvContext/readProjectInstructions; only ignorePatterns is forwarded.`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
__name(warnUnmappedDecoratorKnobs, "warnUnmappedDecoratorKnobs");
|
|
91
172
|
var agentWalkCache = /* @__PURE__ */ new WeakMap();
|
|
92
173
|
function walkAgentMetadata(AgentClass, toolboxClasses = []) {
|
|
93
174
|
if (toolboxClasses.length === 0) {
|
|
@@ -121,6 +202,9 @@ function walkAgentMetadata(AgentClass, toolboxClasses = []) {
|
|
|
121
202
|
const memory = getMemoryConfig(AgentClass);
|
|
122
203
|
const skills = getSkillsConfig(AgentClass);
|
|
123
204
|
const mcpServers = getMcpConfig(AgentClass);
|
|
205
|
+
const contextWindow = getContextWindowConfig(AgentClass);
|
|
206
|
+
const projectContext = getProjectContextConfig(AgentClass);
|
|
207
|
+
warnUnmappedDecoratorKnobs(AgentClass.name, contextWindow, projectContext);
|
|
124
208
|
const result = {
|
|
125
209
|
agentConfig,
|
|
126
210
|
mainLoop,
|
|
@@ -133,6 +217,8 @@ function walkAgentMetadata(AgentClass, toolboxClasses = []) {
|
|
|
133
217
|
subAgentClasses,
|
|
134
218
|
memory,
|
|
135
219
|
skills,
|
|
220
|
+
contextWindow,
|
|
221
|
+
projectContext,
|
|
136
222
|
mcpServers
|
|
137
223
|
};
|
|
138
224
|
if (toolboxClasses.length === 0) {
|
|
@@ -153,6 +239,20 @@ function validateUniqueRoutes(results) {
|
|
|
153
239
|
}
|
|
154
240
|
__name(validateUniqueRoutes, "validateUniqueRoutes");
|
|
155
241
|
|
|
242
|
+
// src/bridge/compile-skills.ts
|
|
243
|
+
function compileSkills(options) {
|
|
244
|
+
if (options.autoDiscover) {
|
|
245
|
+
return {
|
|
246
|
+
autoInject: true
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
enabled: options.include,
|
|
251
|
+
autoInject: true
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
__name(compileSkills, "compileSkills");
|
|
255
|
+
|
|
156
256
|
// src/bridge/agent-compiler.ts
|
|
157
257
|
function compileTools(toolboxes, toolboxInstances) {
|
|
158
258
|
const tools = [];
|
|
@@ -200,7 +300,9 @@ function compileAgent(walkResult, toolboxInstances = /* @__PURE__ */ new Map())
|
|
|
200
300
|
tools,
|
|
201
301
|
agents,
|
|
202
302
|
memory: walkResult.memory,
|
|
203
|
-
skills: walkResult.skills,
|
|
303
|
+
skills: walkResult.skills ? compileSkills(walkResult.skills) : void 0,
|
|
304
|
+
context: walkResult.contextWindow ? compileContextWindow(walkResult.contextWindow).context : void 0,
|
|
305
|
+
projectContext: walkResult.projectContext,
|
|
204
306
|
mcpServers: walkResult.mcpServers,
|
|
205
307
|
maxIterations: walkResult.mainLoop.maxIterations ?? walkResult.agentConfig.maxIterations,
|
|
206
308
|
timeoutMs: walkResult.mainLoop.timeoutMs ?? walkResult.agentConfig.timeoutMs,
|
|
@@ -480,8 +582,37 @@ function translateSdkEvent(msg, runId) {
|
|
|
480
582
|
__name(translateSdkEvent, "translateSdkEvent");
|
|
481
583
|
|
|
482
584
|
// src/bridge/sdk-adapter.ts
|
|
483
|
-
function
|
|
484
|
-
const
|
|
585
|
+
function assembleM8CreateOptions(compiled) {
|
|
586
|
+
const options = {};
|
|
587
|
+
const applied = [];
|
|
588
|
+
const base = compiled.systemPrompt;
|
|
589
|
+
if (compiled.skills) {
|
|
590
|
+
options.skills = compiled.skills;
|
|
591
|
+
options.local = {
|
|
592
|
+
settingSources: [
|
|
593
|
+
"project"
|
|
594
|
+
]
|
|
595
|
+
};
|
|
596
|
+
applied.push("skills");
|
|
597
|
+
}
|
|
598
|
+
if (compiled.context) {
|
|
599
|
+
options.context = compiled.context;
|
|
600
|
+
applied.push("context");
|
|
601
|
+
}
|
|
602
|
+
if (compiled.projectContext) {
|
|
603
|
+
options.systemPrompt = compileProjectContext(compiled.projectContext, base);
|
|
604
|
+
applied.push("projectContext");
|
|
605
|
+
} else if (base !== void 0) {
|
|
606
|
+
options.systemPrompt = base;
|
|
607
|
+
}
|
|
608
|
+
return {
|
|
609
|
+
options,
|
|
610
|
+
applied
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
__name(assembleM8CreateOptions, "assembleM8CreateOptions");
|
|
614
|
+
function createSdkAgentStream(compiled, compiledTools, apiKey, envModel) {
|
|
615
|
+
const model = envModel ?? compiled.model ?? "openai/gpt-4o-mini";
|
|
485
616
|
return (message, _sessionId) => ({
|
|
486
617
|
async *[Symbol.asyncIterator]() {
|
|
487
618
|
const runId = `run-${Date.now()}`;
|
|
@@ -508,13 +639,21 @@ function createSdkAgentStream(agentWalk, compiledTools, apiKey, envModel) {
|
|
|
508
639
|
handler: t.handler
|
|
509
640
|
}));
|
|
510
641
|
try {
|
|
642
|
+
const { options: m8, applied } = assembleM8CreateOptions(compiled);
|
|
643
|
+
if (applied.length > 0) {
|
|
644
|
+
console.debug("[THEO_AGENT_M8_RUNTIME_APPLIED]", {
|
|
645
|
+
skills: applied.includes("skills"),
|
|
646
|
+
context: applied.includes("context"),
|
|
647
|
+
projectContext: applied.includes("projectContext")
|
|
648
|
+
});
|
|
649
|
+
}
|
|
511
650
|
const agent = await Agent.create({
|
|
512
651
|
apiKey,
|
|
513
652
|
model: {
|
|
514
653
|
id: model
|
|
515
654
|
},
|
|
516
655
|
tools: sdkTools,
|
|
517
|
-
|
|
656
|
+
...m8
|
|
518
657
|
});
|
|
519
658
|
const run = await agent.send(message);
|
|
520
659
|
for await (const sdkEvent of run.stream()) {
|
|
@@ -636,7 +775,7 @@ async function delegate(SubAgentClass, message, opts = {}) {
|
|
|
636
775
|
const compiled = compileAgent(walk, toolboxInstances);
|
|
637
776
|
const allTools = mergeTools(opts.parentTools ?? [], compiled.tools);
|
|
638
777
|
const budget = Math.min(opts.budget ?? Infinity, opts.parentBudgetRemaining ?? Infinity);
|
|
639
|
-
const streamFactory = createSdkAgentStream(
|
|
778
|
+
const streamFactory = createSdkAgentStream(compiled, allTools, apiKey, walk.agentConfig.model);
|
|
640
779
|
const sessionId = opts.sessionId ?? `sub-${crypto.randomUUID()}`;
|
|
641
780
|
const acc = {
|
|
642
781
|
response: "",
|
|
@@ -786,9 +925,13 @@ __name(matchRoute, "matchRoute");
|
|
|
786
925
|
export {
|
|
787
926
|
createAgentExecutionContext,
|
|
788
927
|
isAgentContext,
|
|
928
|
+
compileContextWindow,
|
|
929
|
+
projectContextMetadataOnlyKnobs,
|
|
930
|
+
compileProjectContext,
|
|
789
931
|
AgentWarningCode,
|
|
790
932
|
walkAgentMetadata,
|
|
791
933
|
validateUniqueRoutes,
|
|
934
|
+
compileSkills,
|
|
792
935
|
compileTools,
|
|
793
936
|
compileAgent,
|
|
794
937
|
streamAgentResponse,
|
|
@@ -807,4 +950,4 @@ export {
|
|
|
807
950
|
generateAgentManifest,
|
|
808
951
|
agentsPlugin
|
|
809
952
|
};
|
|
810
|
-
//# sourceMappingURL=chunk-
|
|
953
|
+
//# sourceMappingURL=chunk-2MI27XCA.js.map
|