@theokit/agents 0.2.0 → 0.4.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 +97 -13
- package/dist/bridge.js +15 -4
- package/dist/chunk-7QVYU63E.js +7 -0
- package/dist/chunk-7QVYU63E.js.map +1 -0
- package/dist/{chunk-YSQAZWGW.js → chunk-NC5EE7HN.js} +325 -237
- package/dist/chunk-NC5EE7HN.js.map +1 -0
- package/dist/{chunk-3LCIXX3T.js → chunk-O4UG4RXE.js} +19 -7
- package/dist/chunk-O4UG4RXE.js.map +1 -0
- package/dist/{chunk-XUACDN32.js → chunk-VKHDADMG.js} +35 -13
- package/dist/chunk-VKHDADMG.js.map +1 -0
- package/dist/decorators.d.ts +8 -4
- package/dist/decorators.js +3 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +16 -5
- package/dist/{mcp-DmtwLSF-.d.ts → mcp-yyfC5u7t.d.ts} +2 -2
- package/dist/testing.d.ts +47 -0
- package/dist/testing.js +73 -0
- package/dist/testing.js.map +1 -0
- package/package.json +9 -3
- package/dist/chunk-3LCIXX3T.js.map +0 -1
- package/dist/chunk-XUACDN32.js.map +0 -1
- package/dist/chunk-YSQAZWGW.js.map +0 -1
package/dist/bridge.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ExecutionContext } from '@theokit/http
|
|
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-
|
|
1
|
+
import { ExecutionContext } from '@theokit/http';
|
|
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-yyfC5u7t.js';
|
|
3
3
|
import 'zod';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -36,6 +36,15 @@ declare function isAgentContext(ctx: ExecutionContext): ctx is AgentExecutionCon
|
|
|
36
36
|
* EC-4: throws on duplicate routes across agents.
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Stable warning codes for agent pipeline metadata-only decorators.
|
|
41
|
+
* Test by code, not by message string. Document in agent support matrix.
|
|
42
|
+
*/
|
|
43
|
+
declare const AgentWarningCode: {
|
|
44
|
+
readonly INTERCEPTOR_METADATA_ONLY: "THEO_AGENT_INTERCEPTOR_METADATA_ONLY";
|
|
45
|
+
readonly FILTER_METADATA_ONLY: "THEO_AGENT_FILTER_METADATA_ONLY";
|
|
46
|
+
readonly BUDGET_TOP_LEVEL_METADATA_ONLY: "THEO_AGENT_BUDGET_TOP_LEVEL_METADATA_ONLY";
|
|
47
|
+
};
|
|
39
48
|
interface AgentWalkResult {
|
|
40
49
|
agentConfig: AgentOptions;
|
|
41
50
|
mainLoop: MainLoopMeta;
|
|
@@ -202,6 +211,8 @@ interface DoneEvent {
|
|
|
202
211
|
totalTokens: number;
|
|
203
212
|
};
|
|
204
213
|
durationMs: number;
|
|
214
|
+
/** Total cost in USD for this agent run (EC-2: added for budget tracking). */
|
|
215
|
+
cost?: number;
|
|
205
216
|
}
|
|
206
217
|
/** Agent run started. */
|
|
207
218
|
interface RunStartedEvent {
|
|
@@ -289,18 +300,91 @@ interface AgentRouteContext {
|
|
|
289
300
|
declare function generateAgentRoutes(ctx: AgentRouteContext): AgentRoute[];
|
|
290
301
|
|
|
291
302
|
/**
|
|
292
|
-
*
|
|
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
|
+
/**
|
|
312
|
+
* Creates an agent stream factory using @theokit/sdk as the runtime.
|
|
293
313
|
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
* 3. Model from decorator metadata (EC-5 provider prefix auto-detect)
|
|
297
|
-
* 4. Consistent tool names (dot ↔ underscore bidirectional mapping)
|
|
298
|
-
* 5. Robust Zod→JSON Schema via Zod v4 native z.toJSONSchema()
|
|
299
|
-
* 6. Budget enforcement (per-session cost tracking from EC-3 last-chunk usage)
|
|
300
|
-
* 7. AbortController cancel (EC-4 race-safe signal.aborted check)
|
|
314
|
+
* Returns a function that, given a message + sessionId, yields TheoKit
|
|
315
|
+
* AgentStreamEvent via the SDK's Agent.create() + Run.stream() pipeline.
|
|
301
316
|
*/
|
|
317
|
+
declare function createSdkAgentStream(agentWalk: AgentWalkResult, compiledTools: CompiledTool[], apiKey: string, envModel?: string): (message: string, _sessionId: string) => AsyncIterable<StreamEvent>;
|
|
302
318
|
|
|
303
|
-
|
|
319
|
+
/**
|
|
320
|
+
* Translates @theokit/sdk SDKMessage events → TheoKit AgentStreamEvent.
|
|
321
|
+
*
|
|
322
|
+
* The SDK yields SDKMessage (system/assistant/tool_call/thinking/status).
|
|
323
|
+
* TheoKit devtools + SSE handler expect AgentStreamEvent (run_started/text_delta/tool_call/done).
|
|
324
|
+
* This module bridges the two — Adapter pattern (per sdk-integration-blueprint ADR-D2).
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
/** Minimal SDK message shape — duck-typed to avoid hard import of @theokit/sdk types. */
|
|
328
|
+
interface SdkMessage {
|
|
329
|
+
type: string;
|
|
330
|
+
[key: string]: unknown;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Translate a single SDK message to zero or more TheoKit stream events.
|
|
334
|
+
* Returns an array because one SDK message may map to multiple TheoKit events.
|
|
335
|
+
*/
|
|
336
|
+
declare function translateSdkEvent(msg: SdkMessage, runId: string): StreamEvent[];
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Multi-agent orchestration runtime.
|
|
340
|
+
*
|
|
341
|
+
* Provides `delegate()` — a function that lets a parent agent invoke a
|
|
342
|
+
* sub-agent and receive its result. Handles budget clamping (D4),
|
|
343
|
+
* tool sharing, and toolbox auto-instantiation (EC-1).
|
|
344
|
+
*/
|
|
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
|
+
interface DelegationResult {
|
|
359
|
+
response: string;
|
|
360
|
+
toolCalls: {
|
|
361
|
+
name: string;
|
|
362
|
+
input: unknown;
|
|
363
|
+
output: string;
|
|
364
|
+
}[];
|
|
365
|
+
cost: number;
|
|
366
|
+
tokens: number;
|
|
367
|
+
}
|
|
368
|
+
declare class BudgetExceededError extends Error {
|
|
369
|
+
readonly agentName: string;
|
|
370
|
+
readonly actualCost: number;
|
|
371
|
+
readonly budgetLimit: number;
|
|
372
|
+
constructor(agentName: string, actualCost: number, budgetLimit: number);
|
|
373
|
+
}
|
|
374
|
+
declare class DelegationError extends Error {
|
|
375
|
+
readonly agentName: string;
|
|
376
|
+
readonly cause: unknown;
|
|
377
|
+
constructor(agentName: string, cause: unknown);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Delegate a task to a sub-agent and collect its result.
|
|
381
|
+
*
|
|
382
|
+
* - Budget clamping: `min(parentBudgetRemaining, budget)` (D4)
|
|
383
|
+
* - Tool sharing: parent tools merged with sub-agent tools (sub wins on collision)
|
|
384
|
+
* - Toolbox auto-instantiation: sub-agent toolboxes instantiated without DI (EC-1)
|
|
385
|
+
* - Session isolation: each delegation gets a unique session ID (EC-4)
|
|
386
|
+
*/
|
|
387
|
+
declare function delegate(SubAgentClass: Function, message: string, opts?: DelegateOptions): Promise<DelegationResult>;
|
|
304
388
|
|
|
305
389
|
/**
|
|
306
390
|
* Agent manifest generator — build-time JSON describing all agents, tools, guards, policies.
|
|
@@ -374,7 +458,7 @@ interface AgentsPluginOptions {
|
|
|
374
458
|
interface PluginApp {
|
|
375
459
|
addHook(name: string, fn: (ctx: {
|
|
376
460
|
request: Request;
|
|
377
|
-
}) => Promise<Response |
|
|
461
|
+
}) => Promise<Response | undefined>): void;
|
|
378
462
|
}
|
|
379
463
|
/**
|
|
380
464
|
* Create a TheoKit plugin that mounts agent routes.
|
|
@@ -385,4 +469,4 @@ declare function agentsPlugin(opts: AgentsPluginOptions): {
|
|
|
385
469
|
register(app: PluginApp): void;
|
|
386
470
|
};
|
|
387
471
|
|
|
388
|
-
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, type CheckpointSavedEvent, type CompiledAgentOptions, type CompiledTool, 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,
|
|
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 };
|
package/dist/bridge.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AgentWarningCode,
|
|
3
|
+
BudgetExceededError,
|
|
4
|
+
DelegationError,
|
|
2
5
|
agentsPlugin,
|
|
3
6
|
compileAgent,
|
|
4
7
|
compileTools,
|
|
5
8
|
createAgentExecutionContext,
|
|
6
|
-
|
|
9
|
+
createSdkAgentStream,
|
|
10
|
+
delegate,
|
|
7
11
|
generateAgentManifest,
|
|
8
12
|
generateAgentRoutes,
|
|
9
13
|
isAgentContext,
|
|
@@ -14,16 +18,22 @@ import {
|
|
|
14
18
|
isToolCall,
|
|
15
19
|
isToolResult,
|
|
16
20
|
streamAgentResponse,
|
|
21
|
+
translateSdkEvent,
|
|
17
22
|
validateUniqueRoutes,
|
|
18
23
|
walkAgentMetadata
|
|
19
|
-
} from "./chunk-
|
|
20
|
-
import "./chunk-
|
|
24
|
+
} from "./chunk-NC5EE7HN.js";
|
|
25
|
+
import "./chunk-O4UG4RXE.js";
|
|
26
|
+
import "./chunk-7QVYU63E.js";
|
|
21
27
|
export {
|
|
28
|
+
AgentWarningCode,
|
|
29
|
+
BudgetExceededError,
|
|
30
|
+
DelegationError,
|
|
22
31
|
agentsPlugin,
|
|
23
32
|
compileAgent,
|
|
24
33
|
compileTools,
|
|
25
34
|
createAgentExecutionContext,
|
|
26
|
-
|
|
35
|
+
createSdkAgentStream,
|
|
36
|
+
delegate,
|
|
27
37
|
generateAgentManifest,
|
|
28
38
|
generateAgentRoutes,
|
|
29
39
|
isAgentContext,
|
|
@@ -34,6 +44,7 @@ export {
|
|
|
34
44
|
isToolCall,
|
|
35
45
|
isToolResult,
|
|
36
46
|
streamAgentResponse,
|
|
47
|
+
translateSdkEvent,
|
|
37
48
|
validateUniqueRoutes,
|
|
38
49
|
walkAgentMetadata
|
|
39
50
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|