@theokit/agents 0.47.0 → 1.0.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-entry-BQ6UUSLZ.d.ts → bridge-entry-F9kHGaIn.d.ts} +378 -106
- package/dist/bridge.d.ts +1 -2
- package/dist/bridge.js +3 -12
- package/dist/{chunk-FEH7JFH7.js → chunk-7KRJJX7W.js} +139 -358
- package/dist/chunk-7KRJJX7W.js.map +1 -0
- package/dist/index.d.ts +173 -15
- package/dist/index.js +225 -15
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
- package/dist/chunk-FEH7JFH7.js.map +0 -1
- package/dist/chunk-NERDIS45.js +0 -329
- package/dist/chunk-NERDIS45.js.map +0 -1
- package/dist/decorators.d.ts +0 -176
- package/dist/decorators.js +0 -308
- package/dist/decorators.js.map +0 -1
- package/dist/types-DVA4LQsA.d.ts +0 -313
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AGENT_CONFIG,
|
|
3
|
-
AGENT_MAIN_LOOP,
|
|
4
|
-
Audit,
|
|
5
|
-
Budget,
|
|
6
|
-
RequiresApproval,
|
|
7
|
-
TOOLBOX_CONFIG,
|
|
8
|
-
TOOL_CONFIG,
|
|
9
|
-
TOOL_METHODS,
|
|
10
|
-
Trace,
|
|
11
|
-
getAgentConfig,
|
|
12
|
-
getCheckpointConfig,
|
|
13
|
-
getCompactionConfig,
|
|
14
|
-
getContextWindowConfig,
|
|
15
|
-
getGatewayConfig,
|
|
16
|
-
getGuardrailsConfig,
|
|
17
|
-
getHumanInTheLoopConfig,
|
|
18
|
-
getMcpConfig,
|
|
19
|
-
getMemoryConfig,
|
|
20
|
-
getMeta,
|
|
21
|
-
getMixins,
|
|
22
|
-
getProjectContextConfig,
|
|
23
|
-
getSkillsConfig,
|
|
24
|
-
getSubAgents
|
|
25
|
-
} from "./chunk-NERDIS45.js";
|
|
26
1
|
import {
|
|
27
2
|
__name
|
|
28
3
|
} from "./chunk-7QVYU63E.js";
|
|
@@ -163,25 +138,6 @@ function compileApprovals(def) {
|
|
|
163
138
|
}
|
|
164
139
|
__name(compileApprovals, "compileApprovals");
|
|
165
140
|
|
|
166
|
-
// src/bridge/agent-execution-context.ts
|
|
167
|
-
function createAgentExecutionContext(base, agent2, run, toolCall) {
|
|
168
|
-
return {
|
|
169
|
-
getRequest: /* @__PURE__ */ __name(() => base.getRequest(), "getRequest"),
|
|
170
|
-
getUrl: /* @__PURE__ */ __name(() => base.getUrl(), "getUrl"),
|
|
171
|
-
getClass: /* @__PURE__ */ __name(() => base.getClass(), "getClass"),
|
|
172
|
-
getMethodName: /* @__PURE__ */ __name(() => base.getMethodName(), "getMethodName"),
|
|
173
|
-
getAgent: /* @__PURE__ */ __name(() => agent2, "getAgent"),
|
|
174
|
-
getRun: /* @__PURE__ */ __name(() => run, "getRun"),
|
|
175
|
-
getToolCall: /* @__PURE__ */ __name(() => toolCall ?? null, "getToolCall"),
|
|
176
|
-
isAgentContext: /* @__PURE__ */ __name(() => true, "isAgentContext")
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
__name(createAgentExecutionContext, "createAgentExecutionContext");
|
|
180
|
-
function isAgentContext(ctx) {
|
|
181
|
-
return "isAgentContext" in ctx && ctx.isAgentContext();
|
|
182
|
-
}
|
|
183
|
-
__name(isAgentContext, "isAgentContext");
|
|
184
|
-
|
|
185
141
|
// src/bridge/compile-context-window.ts
|
|
186
142
|
var STRATEGY_KNOBS = [
|
|
187
143
|
"compactionStrategy",
|
|
@@ -203,198 +159,6 @@ function compileContextWindow(options) {
|
|
|
203
159
|
}
|
|
204
160
|
__name(compileContextWindow, "compileContextWindow");
|
|
205
161
|
|
|
206
|
-
// src/bridge/compile-project-context.ts
|
|
207
|
-
var UNMAPPED_KNOBS = [
|
|
208
|
-
"indexStrategy",
|
|
209
|
-
"relevanceStrategy",
|
|
210
|
-
"maxFilesInContext",
|
|
211
|
-
"includeExtensions",
|
|
212
|
-
"rootMarkers"
|
|
213
|
-
];
|
|
214
|
-
function projectContextMetadataOnlyKnobs(options) {
|
|
215
|
-
const opts = options;
|
|
216
|
-
return UNMAPPED_KNOBS.filter((knob) => opts[knob] !== void 0);
|
|
217
|
-
}
|
|
218
|
-
__name(projectContextMetadataOnlyKnobs, "projectContextMetadataOnlyKnobs");
|
|
219
|
-
function compileProjectContext(options, base) {
|
|
220
|
-
return async (promptCtx) => {
|
|
221
|
-
const resolvedBase = typeof base === "function" ? await base(promptCtx) : base;
|
|
222
|
-
const cwd = promptCtx.cwd;
|
|
223
|
-
if (!cwd) {
|
|
224
|
-
return resolvedBase ?? "";
|
|
225
|
-
}
|
|
226
|
-
const { buildEnvContext, buildRepoMap } = await import("@theokit/sdk-tools");
|
|
227
|
-
const { readProjectInstructions } = await import("@theokit/sdk/project");
|
|
228
|
-
const env = buildEnvContext(cwd);
|
|
229
|
-
const repoMap = buildRepoMap(cwd, {
|
|
230
|
-
ignore: options.ignorePatterns
|
|
231
|
-
});
|
|
232
|
-
let instructions = "";
|
|
233
|
-
try {
|
|
234
|
-
instructions = (await readProjectInstructions(cwd)).content ?? "";
|
|
235
|
-
} catch {
|
|
236
|
-
instructions = "";
|
|
237
|
-
}
|
|
238
|
-
return [
|
|
239
|
-
env,
|
|
240
|
-
repoMap,
|
|
241
|
-
instructions,
|
|
242
|
-
resolvedBase
|
|
243
|
-
].filter(Boolean).join("\n\n");
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
__name(compileProjectContext, "compileProjectContext");
|
|
247
|
-
|
|
248
|
-
// src/bridge/walk-agent-metadata.ts
|
|
249
|
-
import "reflect-metadata";
|
|
250
|
-
import { Reflector } from "@theokit/http";
|
|
251
|
-
var USE_GUARDS = /* @__PURE__ */ Symbol.for("theokit:http-decorators:use-guards");
|
|
252
|
-
var USE_INTERCEPTORS = /* @__PURE__ */ Symbol.for("theokit:http-decorators:use-interceptors");
|
|
253
|
-
var USE_FILTERS = /* @__PURE__ */ Symbol.for("theokit:http-decorators:use-filters");
|
|
254
|
-
var AgentWarningCode = {
|
|
255
|
-
INTERCEPTOR_METADATA_ONLY: "THEO_AGENT_INTERCEPTOR_METADATA_ONLY",
|
|
256
|
-
FILTER_METADATA_ONLY: "THEO_AGENT_FILTER_METADATA_ONLY",
|
|
257
|
-
BUDGET_TOP_LEVEL_METADATA_ONLY: "THEO_AGENT_BUDGET_TOP_LEVEL_METADATA_ONLY",
|
|
258
|
-
CONTEXT_STRATEGY_METADATA_ONLY: "THEO_AGENT_CONTEXT_STRATEGY_METADATA_ONLY",
|
|
259
|
-
PROJECT_CONTEXT_KNOB_METADATA_ONLY: "THEO_AGENT_PROJECT_CONTEXT_KNOB_METADATA_ONLY",
|
|
260
|
-
CHECKPOINT_STORAGE_METADATA_ONLY: "THEO_AGENT_CHECKPOINT_STORAGE_METADATA_ONLY"
|
|
261
|
-
};
|
|
262
|
-
var reflectorInstance = new Reflector();
|
|
263
|
-
function walkToolbox(ToolboxClass) {
|
|
264
|
-
const config = getMeta(TOOLBOX_CONFIG, ToolboxClass) ?? {};
|
|
265
|
-
const methods = getMeta(TOOL_METHODS, ToolboxClass) ?? [];
|
|
266
|
-
const classGuards = getMeta(USE_GUARDS, ToolboxClass) ?? [];
|
|
267
|
-
const tools = methods.map((propertyKey) => {
|
|
268
|
-
const toolConfig = getMeta(TOOL_CONFIG, ToolboxClass, propertyKey);
|
|
269
|
-
if (!toolConfig) {
|
|
270
|
-
throw new Error(`[@theokit/agents] Toolbox ${ToolboxClass.name}: method '${String(propertyKey)}' is in TOOL_METHODS but has no @Tool() config.`);
|
|
271
|
-
}
|
|
272
|
-
const methodGuards = getMeta(USE_GUARDS, ToolboxClass, propertyKey) ?? [];
|
|
273
|
-
const ref = reflectorInstance;
|
|
274
|
-
const approvalVal = ref.get(RequiresApproval, ToolboxClass, propertyKey);
|
|
275
|
-
const traceVal = ref.get(Trace, ToolboxClass, propertyKey);
|
|
276
|
-
const auditVal = ref.get(Audit, ToolboxClass, propertyKey);
|
|
277
|
-
return {
|
|
278
|
-
propertyKey,
|
|
279
|
-
config: toolConfig,
|
|
280
|
-
guards: [
|
|
281
|
-
...classGuards,
|
|
282
|
-
...methodGuards
|
|
283
|
-
],
|
|
284
|
-
approval: approvalVal && typeof approvalVal === "object" && "reason" in approvalVal ? approvalVal : void 0,
|
|
285
|
-
capabilities: void 0,
|
|
286
|
-
budget: void 0,
|
|
287
|
-
trace: traceVal ?? false,
|
|
288
|
-
audit: auditVal ?? false,
|
|
289
|
-
hitl: getHumanInTheLoopConfig(ToolboxClass, propertyKey)
|
|
290
|
-
};
|
|
291
|
-
});
|
|
292
|
-
return {
|
|
293
|
-
class: ToolboxClass,
|
|
294
|
-
namespace: config.namespace ?? "",
|
|
295
|
-
tools,
|
|
296
|
-
guards: classGuards
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
__name(walkToolbox, "walkToolbox");
|
|
300
|
-
function warnUnmappedDecoratorKnobs(agentName, contextWindow, projectContext) {
|
|
301
|
-
if (contextWindow) {
|
|
302
|
-
const { metadataOnlyKnobs } = compileContextWindow(contextWindow);
|
|
303
|
-
if (metadataOnlyKnobs.length > 0) {
|
|
304
|
-
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 }).`);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
if (projectContext) {
|
|
308
|
-
const unmapped = projectContextMetadataOnlyKnobs(projectContext);
|
|
309
|
-
if (unmapped.length > 0) {
|
|
310
|
-
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.`);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
__name(warnUnmappedDecoratorKnobs, "warnUnmappedDecoratorKnobs");
|
|
315
|
-
function warnNonDurableCheckpoint(agentName, checkpoint) {
|
|
316
|
-
if (checkpoint && checkpoint.storage !== "filesystem") {
|
|
317
|
-
console.warn(`[${AgentWarningCode.CHECKPOINT_STORAGE_METADATA_ONLY}] Agent ${agentName}: @Checkpoint({ storage: '${checkpoint.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.`);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
__name(warnNonDurableCheckpoint, "warnNonDurableCheckpoint");
|
|
321
|
-
var agentWalkCache = /* @__PURE__ */ new WeakMap();
|
|
322
|
-
function walkAgentMetadata(AgentClass, toolboxClasses = []) {
|
|
323
|
-
if (toolboxClasses.length === 0) {
|
|
324
|
-
const cached = agentWalkCache.get(AgentClass);
|
|
325
|
-
if (cached) return cached;
|
|
326
|
-
}
|
|
327
|
-
const agentConfig = getMeta(AGENT_CONFIG, AgentClass);
|
|
328
|
-
if (!agentConfig) {
|
|
329
|
-
throw new Error(`[@theokit/agents] Class ${AgentClass.name} is missing @Agent() decorator.`);
|
|
330
|
-
}
|
|
331
|
-
const mainLoop = getMeta(AGENT_MAIN_LOOP, AgentClass);
|
|
332
|
-
if (!mainLoop) {
|
|
333
|
-
throw new Error(`[@theokit/agents] Agent ${AgentClass.name} is missing @MainLoop() decorator. Decorate exactly one method with @MainLoop().`);
|
|
334
|
-
}
|
|
335
|
-
const guards = getMeta(USE_GUARDS, AgentClass) ?? [];
|
|
336
|
-
const interceptors = getMeta(USE_INTERCEPTORS, AgentClass) ?? [];
|
|
337
|
-
if (interceptors.length > 0) {
|
|
338
|
-
console.warn(`[${AgentWarningCode.INTERCEPTOR_METADATA_ONLY}] Agent ${AgentClass.name}: @UseInterceptors is metadata-only on agents and will not execute. Agent pipeline shares guards with HTTP but uses a distinct execution model. Interceptors are reserved for future agent-specific lifecycle hooks.`);
|
|
339
|
-
}
|
|
340
|
-
const filters = getMeta(USE_FILTERS, AgentClass) ?? [];
|
|
341
|
-
if (filters.length > 0) {
|
|
342
|
-
console.warn(`[${AgentWarningCode.FILTER_METADATA_ONLY}] Agent ${AgentClass.name}: @UseFilters is metadata-only on agents and will not catch agent runtime errors. Agent errors flow through SSE error events, not HTTP exception filters. Filters are reserved for future agent-specific error handling.`);
|
|
343
|
-
}
|
|
344
|
-
const agentBudget = reflectorInstance.get(Budget, AgentClass);
|
|
345
|
-
if (agentBudget) {
|
|
346
|
-
console.warn(`[${AgentWarningCode.BUDGET_TOP_LEVEL_METADATA_ONLY}] Agent ${AgentClass.name}: @Budget on top-level agents is metadata-only in this version. Budget enforcement currently applies to delegate() calls only. Top-level run enforcement will be wired through SDK cost tracking in a future release.`);
|
|
347
|
-
}
|
|
348
|
-
const toolboxes = toolboxClasses.map(walkToolbox);
|
|
349
|
-
const gateway = getGatewayConfig(AgentClass);
|
|
350
|
-
const subAgentClasses = getSubAgents(AgentClass);
|
|
351
|
-
const memory = getMemoryConfig(AgentClass);
|
|
352
|
-
const skills = getSkillsConfig(AgentClass);
|
|
353
|
-
const mcpServers = getMcpConfig(AgentClass);
|
|
354
|
-
const guardrails = getGuardrailsConfig(AgentClass);
|
|
355
|
-
const contextWindow = getContextWindowConfig(AgentClass);
|
|
356
|
-
const projectContext = getProjectContextConfig(AgentClass);
|
|
357
|
-
warnUnmappedDecoratorKnobs(AgentClass.name, contextWindow, projectContext);
|
|
358
|
-
const compaction = getCompactionConfig(AgentClass);
|
|
359
|
-
const checkpoint = getCheckpointConfig(AgentClass);
|
|
360
|
-
warnNonDurableCheckpoint(AgentClass.name, checkpoint);
|
|
361
|
-
const result = {
|
|
362
|
-
agentConfig,
|
|
363
|
-
mainLoop,
|
|
364
|
-
toolboxes,
|
|
365
|
-
guards,
|
|
366
|
-
interceptors,
|
|
367
|
-
filters,
|
|
368
|
-
route: agentConfig.route,
|
|
369
|
-
gateway,
|
|
370
|
-
subAgentClasses,
|
|
371
|
-
memory,
|
|
372
|
-
skills,
|
|
373
|
-
contextWindow,
|
|
374
|
-
projectContext,
|
|
375
|
-
mcpServers,
|
|
376
|
-
guardrails,
|
|
377
|
-
compaction,
|
|
378
|
-
checkpoint
|
|
379
|
-
};
|
|
380
|
-
if (toolboxClasses.length === 0) {
|
|
381
|
-
agentWalkCache.set(AgentClass, result);
|
|
382
|
-
}
|
|
383
|
-
return result;
|
|
384
|
-
}
|
|
385
|
-
__name(walkAgentMetadata, "walkAgentMetadata");
|
|
386
|
-
function validateUniqueRoutes(results) {
|
|
387
|
-
const seen = /* @__PURE__ */ new Map();
|
|
388
|
-
for (const r of results) {
|
|
389
|
-
const existing = seen.get(r.route);
|
|
390
|
-
if (existing) {
|
|
391
|
-
throw new Error(`[@theokit/agents] Duplicate agent route '${r.route}': both '${existing}' and '${r.agentConfig.name}' declare it.`);
|
|
392
|
-
}
|
|
393
|
-
seen.set(r.route, r.agentConfig.name);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
__name(validateUniqueRoutes, "validateUniqueRoutes");
|
|
397
|
-
|
|
398
162
|
// src/bridge/compile-skills.ts
|
|
399
163
|
function compileSkills(options) {
|
|
400
164
|
if (options.autoDiscover) {
|
|
@@ -414,18 +178,6 @@ function toolRuntimeName(namespace, toolName) {
|
|
|
414
178
|
return namespace ? `${namespace}.${toolName}` : toolName;
|
|
415
179
|
}
|
|
416
180
|
__name(toolRuntimeName, "toolRuntimeName");
|
|
417
|
-
function compileHitlGates(toolboxes) {
|
|
418
|
-
const gates = /* @__PURE__ */ new Map();
|
|
419
|
-
for (const tb of toolboxes) {
|
|
420
|
-
for (const tool of tb.tools) {
|
|
421
|
-
if (tool.hitl) {
|
|
422
|
-
gates.set(toolRuntimeName(tb.namespace, tool.config.name), tool.hitl);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
return gates;
|
|
427
|
-
}
|
|
428
|
-
__name(compileHitlGates, "compileHitlGates");
|
|
429
181
|
function compileTools(toolboxes, toolboxInstances) {
|
|
430
182
|
const tools = [];
|
|
431
183
|
for (const tb of toolboxes) {
|
|
@@ -450,46 +202,67 @@ function compileTools(toolboxes, toolboxInstances) {
|
|
|
450
202
|
return tools;
|
|
451
203
|
}
|
|
452
204
|
__name(compileTools, "compileTools");
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const config = getAgentConfig(cls);
|
|
457
|
-
if (!config) continue;
|
|
458
|
-
agents[config.name] = {
|
|
459
|
-
model: config.model,
|
|
460
|
-
systemPrompt: config.systemPrompt
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
return agents;
|
|
464
|
-
}
|
|
465
|
-
__name(compileSubAgents, "compileSubAgents");
|
|
466
|
-
function compileAgent(walkResult, toolboxInstances = /* @__PURE__ */ new Map()) {
|
|
467
|
-
const tools = compileTools(walkResult.toolboxes, toolboxInstances);
|
|
468
|
-
const agents = compileSubAgents(walkResult.subAgentClasses);
|
|
469
|
-
const hitl = compileHitlGates(walkResult.toolboxes);
|
|
205
|
+
|
|
206
|
+
// src/bridge/agent-execution-context.ts
|
|
207
|
+
function createAgentExecutionContext(base, agent2, run, toolCall) {
|
|
470
208
|
return {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
209
|
+
getRequest: /* @__PURE__ */ __name(() => base.getRequest(), "getRequest"),
|
|
210
|
+
getUrl: /* @__PURE__ */ __name(() => base.getUrl(), "getUrl"),
|
|
211
|
+
getClass: /* @__PURE__ */ __name(() => base.getClass(), "getClass"),
|
|
212
|
+
getMethodName: /* @__PURE__ */ __name(() => base.getMethodName(), "getMethodName"),
|
|
213
|
+
getAgent: /* @__PURE__ */ __name(() => agent2, "getAgent"),
|
|
214
|
+
getRun: /* @__PURE__ */ __name(() => run, "getRun"),
|
|
215
|
+
getToolCall: /* @__PURE__ */ __name(() => toolCall ?? null, "getToolCall"),
|
|
216
|
+
isAgentContext: /* @__PURE__ */ __name(() => true, "isAgentContext")
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
__name(createAgentExecutionContext, "createAgentExecutionContext");
|
|
220
|
+
function isAgentContext(ctx) {
|
|
221
|
+
return "isAgentContext" in ctx && ctx.isAgentContext();
|
|
222
|
+
}
|
|
223
|
+
__name(isAgentContext, "isAgentContext");
|
|
224
|
+
|
|
225
|
+
// src/bridge/compile-project-context.ts
|
|
226
|
+
var UNMAPPED_KNOBS = [
|
|
227
|
+
"indexStrategy",
|
|
228
|
+
"relevanceStrategy",
|
|
229
|
+
"maxFilesInContext",
|
|
230
|
+
"includeExtensions",
|
|
231
|
+
"rootMarkers"
|
|
232
|
+
];
|
|
233
|
+
function projectContextMetadataOnlyKnobs(options) {
|
|
234
|
+
const opts = options;
|
|
235
|
+
return UNMAPPED_KNOBS.filter((knob) => opts[knob] !== void 0);
|
|
236
|
+
}
|
|
237
|
+
__name(projectContextMetadataOnlyKnobs, "projectContextMetadataOnlyKnobs");
|
|
238
|
+
function compileProjectContext(options, base) {
|
|
239
|
+
return async (promptCtx) => {
|
|
240
|
+
const resolvedBase = typeof base === "function" ? await base(promptCtx) : base;
|
|
241
|
+
const cwd = promptCtx.cwd;
|
|
242
|
+
if (!cwd) {
|
|
243
|
+
return resolvedBase ?? "";
|
|
244
|
+
}
|
|
245
|
+
const { buildEnvContext, buildRepoMap } = await import("@theokit/sdk-tools");
|
|
246
|
+
const { readProjectInstructions } = await import("@theokit/sdk/project");
|
|
247
|
+
const env = buildEnvContext(cwd);
|
|
248
|
+
const repoMap = buildRepoMap(cwd, {
|
|
249
|
+
ignore: options.ignorePatterns
|
|
250
|
+
});
|
|
251
|
+
let instructions = "";
|
|
252
|
+
try {
|
|
253
|
+
instructions = (await readProjectInstructions(cwd)).content ?? "";
|
|
254
|
+
} catch {
|
|
255
|
+
instructions = "";
|
|
256
|
+
}
|
|
257
|
+
return [
|
|
258
|
+
env,
|
|
259
|
+
repoMap,
|
|
260
|
+
instructions,
|
|
261
|
+
resolvedBase
|
|
262
|
+
].filter(Boolean).join("\n\n");
|
|
490
263
|
};
|
|
491
264
|
}
|
|
492
|
-
__name(
|
|
265
|
+
__name(compileProjectContext, "compileProjectContext");
|
|
493
266
|
|
|
494
267
|
// src/bridge/agent-sse-handler.ts
|
|
495
268
|
var encoder = new TextEncoder();
|
|
@@ -1152,9 +925,12 @@ function buildExtraCreateOptions(overrides, compiled) {
|
|
|
1152
925
|
const recoverLeakedToolCalls = overrides.recoverLeakedToolCalls ?? compiled.recoverLeakedToolCalls ?? false;
|
|
1153
926
|
const extra = {};
|
|
1154
927
|
if (overrides.plugins !== void 0) {
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
928
|
+
const asArray = /* @__PURE__ */ __name((v) => Array.isArray(v) ? v : void 0, "asArray");
|
|
929
|
+
const overrideList = asArray(overrides.plugins);
|
|
930
|
+
const compiledList = asArray(compiled.plugins);
|
|
931
|
+
extra.plugins = overrideList !== void 0 && compiledList !== void 0 ? [
|
|
932
|
+
...compiledList,
|
|
933
|
+
...overrideList
|
|
1158
934
|
] : overrides.plugins;
|
|
1159
935
|
}
|
|
1160
936
|
if (overrides.providers !== void 0) {
|
|
@@ -1353,7 +1129,7 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
|
|
|
1353
1129
|
const reasoningEffort = overrides.reasoningEffort ?? compiled.reasoningEffort;
|
|
1354
1130
|
const { parseThinkTags, stripToolDialect } = resolveTextTransformFlags(compiled, overrides);
|
|
1355
1131
|
const runContext = overrides.runContext ?? compiled.runContext;
|
|
1356
|
-
|
|
1132
|
+
const factory = /* @__PURE__ */ __name((message, sessionId, factoryOpts) => ({
|
|
1357
1133
|
async *[Symbol.asyncIterator]() {
|
|
1358
1134
|
const runId = `run-${Date.now()}`;
|
|
1359
1135
|
const t0 = Date.now();
|
|
@@ -1407,6 +1183,9 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
|
|
|
1407
1183
|
};
|
|
1408
1184
|
}
|
|
1409
1185
|
}
|
|
1186
|
+
}), "factory");
|
|
1187
|
+
return Object.assign(factory, {
|
|
1188
|
+
resolvedModel: model
|
|
1410
1189
|
});
|
|
1411
1190
|
}
|
|
1412
1191
|
__name(createSdkAgentStream, "createSdkAgentStream");
|
|
@@ -2291,19 +2070,18 @@ function extractDefaultExport(mod) {
|
|
|
2291
2070
|
return mod;
|
|
2292
2071
|
}
|
|
2293
2072
|
__name(extractDefaultExport, "extractDefaultExport");
|
|
2073
|
+
function isCompiledAgentOptions(value) {
|
|
2074
|
+
if (typeof value !== "object" || value === null) return false;
|
|
2075
|
+
const v = value;
|
|
2076
|
+
return Array.isArray(v.tools) && typeof v.agents === "object" && v.agents !== null;
|
|
2077
|
+
}
|
|
2078
|
+
__name(isCompiledAgentOptions, "isCompiledAgentOptions");
|
|
2294
2079
|
function compileAgentModule(mod, source = "agent module") {
|
|
2295
2080
|
const def = extractDefaultExport(mod);
|
|
2296
2081
|
if (isAgentDefinition(def)) {
|
|
2297
2082
|
return compileAgentDefinition(def);
|
|
2298
2083
|
}
|
|
2299
|
-
if (
|
|
2300
|
-
const walk = walkAgentMetadata(def, getMixins(def));
|
|
2301
|
-
const instances = /* @__PURE__ */ new Map();
|
|
2302
|
-
for (const tb of walk.toolboxes) {
|
|
2303
|
-
instances.set(tb.class, new tb.class());
|
|
2304
|
-
}
|
|
2305
|
-
return compileAgent(walk, instances);
|
|
2306
|
-
}
|
|
2084
|
+
if (isCompiledAgentOptions(def)) return def;
|
|
2307
2085
|
throw new AgentDefinitionError(source);
|
|
2308
2086
|
}
|
|
2309
2087
|
__name(compileAgentModule, "compileAgentModule");
|
|
@@ -2377,12 +2155,16 @@ function streamAgentUIMessages(compiled, apiKey, input) {
|
|
|
2377
2155
|
source = asAgentStream(events2);
|
|
2378
2156
|
} else {
|
|
2379
2157
|
const queue = new EventQueue();
|
|
2380
|
-
input.signal?.addEventListener("abort", () =>
|
|
2158
|
+
input.signal?.addEventListener("abort", () => {
|
|
2159
|
+
queue.close();
|
|
2160
|
+
}, {
|
|
2381
2161
|
once: true
|
|
2382
2162
|
});
|
|
2383
2163
|
const plugin = createHitlPlugin({
|
|
2384
2164
|
gated: input.hitl.gated,
|
|
2385
|
-
emit: /* @__PURE__ */ __name((e) =>
|
|
2165
|
+
emit: /* @__PURE__ */ __name((e) => {
|
|
2166
|
+
queue.push(e);
|
|
2167
|
+
}, "emit"),
|
|
2386
2168
|
awaitApproval: input.hitl.awaitApproval
|
|
2387
2169
|
});
|
|
2388
2170
|
const sdkStream = createSdkAgentStream(compiled, compiled.tools, apiKey, {
|
|
@@ -3020,9 +2802,9 @@ var AgentRunner = class {
|
|
|
3020
2802
|
this.streamEnabled = state.streamEnabled;
|
|
3021
2803
|
this.compaction = state.compaction;
|
|
3022
2804
|
}
|
|
3023
|
-
/** Start a fluent builder
|
|
3024
|
-
static
|
|
3025
|
-
return new AgentRunnerBuilder(
|
|
2805
|
+
/** Start a fluent builder from an already-compiled spec. */
|
|
2806
|
+
static fromSpec(spec) {
|
|
2807
|
+
return new AgentRunnerBuilder(spec);
|
|
3026
2808
|
}
|
|
3027
2809
|
/**
|
|
3028
2810
|
* V4-D-stream: stream the agent's events LIVE across the reflective loop, returning
|
|
@@ -3084,12 +2866,12 @@ var AgentRunnerBuilder = class {
|
|
|
3084
2866
|
static {
|
|
3085
2867
|
__name(this, "AgentRunnerBuilder");
|
|
3086
2868
|
}
|
|
3087
|
-
|
|
2869
|
+
spec;
|
|
3088
2870
|
reflectionOverride;
|
|
3089
2871
|
streamEnabled = true;
|
|
3090
2872
|
compactionOverride;
|
|
3091
|
-
constructor(
|
|
3092
|
-
this.
|
|
2873
|
+
constructor(spec) {
|
|
2874
|
+
this.spec = spec;
|
|
3093
2875
|
}
|
|
3094
2876
|
/** Override the default reflection strategy (OCP — plan Drawback #2). No arg ⇒ keep default. */
|
|
3095
2877
|
reflection(strategy) {
|
|
@@ -3113,23 +2895,19 @@ var AgentRunnerBuilder = class {
|
|
|
3113
2895
|
};
|
|
3114
2896
|
return this;
|
|
3115
2897
|
}
|
|
3116
|
-
/**
|
|
2898
|
+
/** Resolve strategies from the spec — the compile→execute boundary (no I/O). */
|
|
3117
2899
|
build() {
|
|
3118
|
-
const
|
|
3119
|
-
const
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
const compiled = compileAgent(walk, toolboxInstances);
|
|
3124
|
-
const loopStrategy = resolveLoopStrategy(walk.mainLoop.strategy, walk.mainLoop.maxIterations);
|
|
3125
|
-
const reflectionStrategy = this.reflectionOverride ?? (walk.mainLoop.strategy === "plan-act-reflect" ? ladderReflectionStrategy : noopReflectionStrategy);
|
|
3126
|
-
const compactionDecl = this.compactionOverride ?? walk.compaction;
|
|
2900
|
+
const { spec } = this;
|
|
2901
|
+
const strategy = spec.strategy ?? "simple-chat";
|
|
2902
|
+
const loopStrategy = resolveLoopStrategy(strategy, spec.maxIterations);
|
|
2903
|
+
const reflectionStrategy = this.reflectionOverride ?? (strategy === "plan-act-reflect" ? ladderReflectionStrategy : noopReflectionStrategy);
|
|
2904
|
+
const compactionDecl = this.compactionOverride ?? spec.compaction;
|
|
3127
2905
|
const compaction = compactionDecl ? resolveCompactionStrategy(compactionDecl.name, {
|
|
3128
2906
|
keepTokens: compactionDecl.keepTokens
|
|
3129
2907
|
}) : void 0;
|
|
3130
2908
|
return new AgentRunner({
|
|
3131
|
-
compiled,
|
|
3132
|
-
agentName:
|
|
2909
|
+
compiled: spec.compiled,
|
|
2910
|
+
agentName: spec.name,
|
|
3133
2911
|
loopStrategy,
|
|
3134
2912
|
reflectionStrategy,
|
|
3135
2913
|
streamEnabled: this.streamEnabled,
|
|
@@ -3156,22 +2934,17 @@ function mergeTools(parentTools, subTools) {
|
|
|
3156
2934
|
];
|
|
3157
2935
|
}
|
|
3158
2936
|
__name(mergeTools, "mergeTools");
|
|
3159
|
-
async function delegate(
|
|
3160
|
-
const apiKey = requireApiKey(opts,
|
|
2937
|
+
async function delegate(spec, message, opts = {}) {
|
|
2938
|
+
const apiKey = requireApiKey(opts, spec.name);
|
|
3161
2939
|
const effectiveMessage = opts.onDelegationStart ? await opts.onDelegationStart({
|
|
3162
|
-
subAgent:
|
|
2940
|
+
subAgent: spec.name,
|
|
3163
2941
|
input: message
|
|
3164
2942
|
}) : message;
|
|
3165
|
-
const
|
|
3166
|
-
const toolboxInstances = new Map(walk.toolboxes.map((tb) => [
|
|
3167
|
-
tb.class,
|
|
3168
|
-
new tb.class()
|
|
3169
|
-
]));
|
|
3170
|
-
const compiled = compileAgent(walk, toolboxInstances);
|
|
2943
|
+
const { compiled } = spec;
|
|
3171
2944
|
const allTools = mergeTools(opts.parentTools ?? [], compiled.tools);
|
|
3172
2945
|
const budget = Math.min(opts.budget ?? Infinity, opts.parentBudgetRemaining ?? Infinity);
|
|
3173
2946
|
const streamFactory = opts.streamFactory ?? createSdkAgentStream(compiled, allTools, apiKey, {
|
|
3174
|
-
model: opts.model ??
|
|
2947
|
+
model: opts.model ?? compiled.model,
|
|
3175
2948
|
cwd: opts.cwd,
|
|
3176
2949
|
plugins: opts.plugins,
|
|
3177
2950
|
providers: opts.providers,
|
|
@@ -3180,19 +2953,19 @@ async function delegate(SubAgentClass, message, opts = {}) {
|
|
|
3180
2953
|
sdkTools: opts.sdkTools
|
|
3181
2954
|
});
|
|
3182
2955
|
const sessionId = opts.sessionId ?? `sub-${crypto.randomUUID()}`;
|
|
3183
|
-
const loopStrategy = resolveLoopStrategy(
|
|
2956
|
+
const loopStrategy = resolveLoopStrategy(spec.strategy ?? "simple-chat", opts.maxIterations ?? spec.maxIterations);
|
|
3184
2957
|
const reflection = opts.reflection ?? (loopStrategy.name === "plan-act-reflect" ? ladderReflectionStrategy : noopReflectionStrategy);
|
|
3185
2958
|
const result = await runReflectiveLoop(streamFactory, effectiveMessage, sessionId, {
|
|
3186
2959
|
loop: loopStrategy,
|
|
3187
2960
|
reflection,
|
|
3188
2961
|
budget,
|
|
3189
|
-
agentName:
|
|
2962
|
+
agentName: spec.name,
|
|
3190
2963
|
signal: opts.signal,
|
|
3191
2964
|
retry: opts.retry
|
|
3192
2965
|
});
|
|
3193
2966
|
if (opts.onDelegationComplete) {
|
|
3194
2967
|
return await opts.onDelegationComplete({
|
|
3195
|
-
subAgent:
|
|
2968
|
+
subAgent: spec.name,
|
|
3196
2969
|
result
|
|
3197
2970
|
});
|
|
3198
2971
|
}
|
|
@@ -3323,6 +3096,9 @@ async function delegateWithScoring(subAgent, message, opts) {
|
|
|
3323
3096
|
}
|
|
3324
3097
|
if (verdict.feedback) currentMessage = feedbackTemplate(message, verdict.feedback);
|
|
3325
3098
|
}
|
|
3099
|
+
if (lastResult === void 0) {
|
|
3100
|
+
throw new Error("[@theokit/agents] delegateWithScoring: no round ran (maxRounds < 1)");
|
|
3101
|
+
}
|
|
3326
3102
|
return {
|
|
3327
3103
|
result: lastResult,
|
|
3328
3104
|
rounds: maxRounds,
|
|
@@ -3398,11 +3174,11 @@ function mcpToolApprovals(specs) {
|
|
|
3398
3174
|
__name(mcpToolApprovals, "mcpToolApprovals");
|
|
3399
3175
|
|
|
3400
3176
|
// src/manifest/agent-manifest.ts
|
|
3401
|
-
function generateAgentManifest(
|
|
3177
|
+
function generateAgentManifest(sources) {
|
|
3402
3178
|
return {
|
|
3403
3179
|
version: "1.0",
|
|
3404
3180
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3405
|
-
agents:
|
|
3181
|
+
agents: sources.map((r) => ({
|
|
3406
3182
|
name: r.agentConfig.name,
|
|
3407
3183
|
route: r.route,
|
|
3408
3184
|
model: r.agentConfig.model,
|
|
@@ -3441,7 +3217,17 @@ function generateAgentManifest(walkResults) {
|
|
|
3441
3217
|
__name(generateAgentManifest, "generateAgentManifest");
|
|
3442
3218
|
|
|
3443
3219
|
// src/theokit-plugin.ts
|
|
3444
|
-
|
|
3220
|
+
function validateUniqueRoutes(results) {
|
|
3221
|
+
const seen = /* @__PURE__ */ new Map();
|
|
3222
|
+
for (const r of results) {
|
|
3223
|
+
const existing = seen.get(r.route);
|
|
3224
|
+
if (existing !== void 0) {
|
|
3225
|
+
throw new Error(`[@theokit/agents] Duplicate agent route '${r.route}': both '${existing}' and '${r.agentConfig.name}' declare it.`);
|
|
3226
|
+
}
|
|
3227
|
+
seen.set(r.route, r.agentConfig.name);
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
__name(validateUniqueRoutes, "validateUniqueRoutes");
|
|
3445
3231
|
function agentsPlugin(opts) {
|
|
3446
3232
|
let routes = null;
|
|
3447
3233
|
return {
|
|
@@ -3462,25 +3248,24 @@ function agentsPlugin(opts) {
|
|
|
3462
3248
|
__name(agentsPlugin, "agentsPlugin");
|
|
3463
3249
|
function initRoutes(opts) {
|
|
3464
3250
|
const allRoutes = [];
|
|
3465
|
-
const
|
|
3466
|
-
for (const
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
const walkResult = walkAgentMetadata(AgentClass, toolboxes);
|
|
3473
|
-
walkResults.push(walkResult);
|
|
3474
|
-
const compiled = compileAgent(walkResult, /* @__PURE__ */ new Map());
|
|
3475
|
-
const createRun = opts.createRunFactory ? opts.createRunFactory(compiled, walkResult) : defaultCreateRun(compiled);
|
|
3476
|
-
const agentRoutes = generateAgentRoutes({
|
|
3477
|
-
walkResult,
|
|
3478
|
-
compiledOptions: compiled,
|
|
3479
|
-
createRun
|
|
3251
|
+
const routeIdentities = [];
|
|
3252
|
+
for (const entry of opts.agents) {
|
|
3253
|
+
routeIdentities.push({
|
|
3254
|
+
route: entry.route,
|
|
3255
|
+
agentConfig: {
|
|
3256
|
+
name: entry.name
|
|
3257
|
+
}
|
|
3480
3258
|
});
|
|
3481
|
-
|
|
3259
|
+
const createRun = opts.createRunFactory ? opts.createRunFactory(entry.compiled) : defaultCreateRun(entry.compiled);
|
|
3260
|
+
allRoutes.push(...generateAgentRoutes({
|
|
3261
|
+
walkResult: {
|
|
3262
|
+
route: entry.route
|
|
3263
|
+
},
|
|
3264
|
+
compiledOptions: entry.compiled,
|
|
3265
|
+
createRun
|
|
3266
|
+
}));
|
|
3482
3267
|
}
|
|
3483
|
-
validateUniqueRoutes(
|
|
3268
|
+
validateUniqueRoutes(routeIdentities);
|
|
3484
3269
|
return compileRoutePatterns(allRoutes);
|
|
3485
3270
|
}
|
|
3486
3271
|
__name(initRoutes, "initRoutes");
|
|
@@ -3526,17 +3311,13 @@ export {
|
|
|
3526
3311
|
isAgentDefinition,
|
|
3527
3312
|
compileAgentDefinition,
|
|
3528
3313
|
compileSkillsSelection,
|
|
3314
|
+
compileContextWindow,
|
|
3315
|
+
compileSkills,
|
|
3316
|
+
compileTools,
|
|
3529
3317
|
createAgentExecutionContext,
|
|
3530
3318
|
isAgentContext,
|
|
3531
|
-
compileContextWindow,
|
|
3532
3319
|
projectContextMetadataOnlyKnobs,
|
|
3533
3320
|
compileProjectContext,
|
|
3534
|
-
AgentWarningCode,
|
|
3535
|
-
walkAgentMetadata,
|
|
3536
|
-
validateUniqueRoutes,
|
|
3537
|
-
compileSkills,
|
|
3538
|
-
compileTools,
|
|
3539
|
-
compileAgent,
|
|
3540
3321
|
streamAgentResponse,
|
|
3541
3322
|
isTextDelta,
|
|
3542
3323
|
isToolCall,
|
|
@@ -3595,4 +3376,4 @@ export {
|
|
|
3595
3376
|
generateAgentManifest,
|
|
3596
3377
|
agentsPlugin
|
|
3597
3378
|
};
|
|
3598
|
-
//# sourceMappingURL=chunk-
|
|
3379
|
+
//# sourceMappingURL=chunk-7KRJJX7W.js.map
|