@theokit/agents 0.42.0 → 0.43.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-CE3ie8rG.d.ts → bridge-entry-Bo3LsMQF.d.ts} +14 -1
- package/dist/bridge.d.ts +1 -1
- package/dist/bridge.js +1 -1
- package/dist/{chunk-OFPS2N3U.js → chunk-5VK63XGX.js} +55 -31
- package/dist/chunk-5VK63XGX.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-OFPS2N3U.js.map +0 -1
|
@@ -414,6 +414,19 @@ interface DoneEvent {
|
|
|
414
414
|
/** Total cost in USD for this agent run (EC-2: added for budget tracking). */
|
|
415
415
|
cost?: number;
|
|
416
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Per-turn usage the translator attaches to the ai-sdk `finish` chunk's `messageMetadata`, so it
|
|
419
|
+
* lands on the reconstructed assistant `UIMessage.metadata` on the client (via `readUIMessageStream`)
|
|
420
|
+
* with NO extra header/store wiring. It is the seam that lets a surface (a TUI status bar, a web
|
|
421
|
+
* cost meter) show real tokens/cost for the turn it just streamed. Mirrors `DoneEvent`'s usage/cost
|
|
422
|
+
* (the authoritative totals the SDK reports at turn end) plus the wall-clock `durationMs`.
|
|
423
|
+
*/
|
|
424
|
+
interface AgentTurnMetadata {
|
|
425
|
+
usage: DoneEvent['usage'];
|
|
426
|
+
/** Total cost in USD for the turn (present iff the SDK reported it). */
|
|
427
|
+
cost?: number;
|
|
428
|
+
durationMs: number;
|
|
429
|
+
}
|
|
417
430
|
/** Agent run started. */
|
|
418
431
|
interface RunStartedEvent {
|
|
419
432
|
type: 'run_started';
|
|
@@ -1643,4 +1656,4 @@ declare function agentsPlugin(opts: AgentsPluginOptions): {
|
|
|
1643
1656
|
register(app: PluginApp): void;
|
|
1644
1657
|
};
|
|
1645
1658
|
|
|
1646
|
-
export { type
|
|
1659
|
+
export { type McpRegistryConfig as $, type AgentManifestEntry as A, type BackgroundDelegation as B, type CompiledAgentOptions as C, type DelegationResult as D, type CheckpointSavedEvent as E, type CompiledContextWindow as F, type ContextualTool as G, DEFAULT_MAX_ITERATIONS as H, type DefineAgentConfig as I, type DelegateFn as J, type DelegateOptions as K, type LoopStrategy as L, DelegationError as M, type DoneEvent as N, type ErrorEvent as O, type FileEditEvent as P, type HitlDecision as Q, type ReflectionStrategy as R, type StreamEvent as S, type InferAgentInput as T, type InferAgentToolNames as U, type IterationEvent as V, type LLMCallContext as W, type LoopFinishReason as X, type LoopOutcome as Y, type LoopStrategyConfig as Z, type McpApprovalSpec as _, type CompiledTool as a, resolveEnabledSkills as a$, type McpRequestContext as a0, type McpSelection as a1, type PartialToolCallEvent as a2, type ProcessInputContext as a3, type ReflectionContext as a4, type ReflectionResult as a5, type ReflectionStrategyConfig as a6, type RunStartedEvent as a7, type ScoreVerdict as a8, type ScoredDelegation as a9, createAgentExecutionContext as aA, createApiErrorHandler as aB, createSdkAgentStream as aC, createThinkTagExtractor as aD, createToolHooksPlugin as aE, delegate as aF, delegateBackground as aG, delegateWithScoring as aH, extractThinkTagStream as aI, generateAgentManifest as aJ, generateAgentRoutes as aK, isAgentContext as aL, isAgentDefinition as aM, isApprovalRequired as aN, isDone as aO, isError as aP, isPartialToolCall as aQ, isTextDelta as aR, isToolCall as aS, isToolResult as aT, ladderReflectionStrategy as aU, loopStrategyConfigSchema as aV, mcpRegistry as aW, mcpToolApprovals as aX, noopReflectionStrategy as aY, projectContextMetadataOnlyKnobs as aZ, reflectionStrategyConfigSchema as a_, type Scorer as aa, type SdkMessage as ab, type Segment as ac, type SkillsRequestContext as ad, type SkillsSelection as ae, type StateUpdateEvent as af, type TextDeltaEvent as ag, type ThinkingEvent as ah, type ToolCallEvent as ai, type ToolCallVeto as aj, type ToolHooks as ak, type ToolHooksPlugin as al, type ToolResultEvent as am, type ToolWalkResult as an, type ToolboxWalkResult as ao, agent as ap, agentsPlugin as aq, buildModelSelection as ar, compileAgent as as, compileAgentDefinition as at, compileAgentModule as au, compileContextWindow as av, compileProjectContext as aw, compileSkills as ax, compileTools as ay, contextualTool as az, type RoundStreamFactory as b, resolveLoopStrategy as b0, resolveMcpServers as b1, runWithApiErrorHandling as b2, streamAgentResponse as b3, streamAgentUIMessages as b4, translateSdkEvent as b5, translateToUIMessageStream as b6, validateUniqueRoutes as b7, walkAgentMetadata as b8, AGENT_BRAND as c, type AfterToolCallContext as d, type AgentBuilder as e, type AgentDefinition as f, AgentDefinitionError as g, type AgentExecutionContext as h, type AgentManifest as i, type AgentManifestTool as j, type AgentRoute as k, type AgentRouteContext as l, type AgentRunInfo as m, type AgentStreamEvent as n, type AgentTurnMetadata as o, type AgentWalkResult as p, AgentWarningCode as q, type AgentsPluginOptions as r, type ApiErrorContext as s, type ApiErrorDecision as t, type ApiErrorPolicy as u, type ApprovalRequiredEvent as v, type ArtifactChunkEvent as w, type ArtifactStartEvent as x, type BeforeToolCallContext as y, BudgetExceededError as z };
|
package/dist/bridge.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { c as AGENT_BRAND, d as AfterToolCallContext, e as AgentBuilder, f as AgentDefinition, g as AgentDefinitionError, h as AgentExecutionContext, i as AgentManifest, A as AgentManifestEntry, j as AgentManifestTool, k as AgentRoute, l as AgentRouteContext, m as AgentRunInfo, n as AgentStreamEvent, o as
|
|
1
|
+
export { c as AGENT_BRAND, d as AfterToolCallContext, e as AgentBuilder, f as AgentDefinition, g as AgentDefinitionError, h as AgentExecutionContext, i as AgentManifest, A as AgentManifestEntry, j as AgentManifestTool, k as AgentRoute, l as AgentRouteContext, m as AgentRunInfo, n as AgentStreamEvent, o as AgentTurnMetadata, p as AgentWalkResult, q as AgentWarningCode, r as AgentsPluginOptions, s as ApiErrorContext, t as ApiErrorDecision, u as ApiErrorPolicy, v as ApprovalRequiredEvent, w as ArtifactChunkEvent, x as ArtifactStartEvent, B as BackgroundDelegation, y as BeforeToolCallContext, z as BudgetExceededError, E as CheckpointSavedEvent, C as CompiledAgentOptions, F as CompiledContextWindow, a as CompiledTool, G as ContextualTool, I as DefineAgentConfig, J as DelegateFn, K as DelegateOptions, M as DelegationError, D as DelegationResult, N as DoneEvent, O as ErrorEvent, P as FileEditEvent, T as InferAgentInput, U as InferAgentToolNames, V as IterationEvent, W as LLMCallContext, _ as McpApprovalSpec, $ as McpRegistryConfig, a0 as McpRequestContext, a1 as McpSelection, a2 as PartialToolCallEvent, a3 as ProcessInputContext, a7 as RunStartedEvent, a8 as ScoreVerdict, a9 as ScoredDelegation, aa as Scorer, ab as SdkMessage, ac as Segment, af as StateUpdateEvent, S as StreamEvent, ag as TextDeltaEvent, ah as ThinkingEvent, ai as ToolCallEvent, aj as ToolCallVeto, ak as ToolHooks, al as ToolHooksPlugin, am as ToolResultEvent, an as ToolWalkResult, ao as ToolboxWalkResult, ap as agent, aq as agentsPlugin, ar as buildModelSelection, as as compileAgent, at as compileAgentDefinition, au as compileAgentModule, av as compileContextWindow, aw as compileProjectContext, ax as compileSkills, ay as compileTools, az as contextualTool, aA as createAgentExecutionContext, aB as createApiErrorHandler, aC as createSdkAgentStream, aD as createThinkTagExtractor, aE as createToolHooksPlugin, aF as delegate, aG as delegateBackground, aH as delegateWithScoring, aI as extractThinkTagStream, aJ as generateAgentManifest, aK as generateAgentRoutes, aL as isAgentContext, aM as isAgentDefinition, aN as isApprovalRequired, aO as isDone, aP as isError, aQ as isPartialToolCall, aR as isTextDelta, aS as isToolCall, aT as isToolResult, aW as mcpRegistry, aX as mcpToolApprovals, aZ as projectContextMetadataOnlyKnobs, b1 as resolveMcpServers, b2 as runWithApiErrorHandling, b3 as streamAgentResponse, b4 as streamAgentUIMessages, b5 as translateSdkEvent, b6 as translateToUIMessageStream, b7 as validateUniqueRoutes, b8 as walkAgentMetadata } from './bridge-entry-Bo3LsMQF.js';
|
|
2
2
|
import '@theokit/http';
|
|
3
3
|
import './types-DVA4LQsA.js';
|
|
4
4
|
import '@theokit/sdk';
|
package/dist/bridge.js
CHANGED
|
@@ -1319,6 +1319,41 @@ function* closeOpenBlock(state, textId) {
|
|
|
1319
1319
|
state.reasoningId = null;
|
|
1320
1320
|
}
|
|
1321
1321
|
__name(closeOpenBlock, "closeOpenBlock");
|
|
1322
|
+
function* emitTextDelta(state, textId, content) {
|
|
1323
|
+
if (state.openBlock !== "text") {
|
|
1324
|
+
yield* closeOpenBlock(state, textId);
|
|
1325
|
+
yield {
|
|
1326
|
+
type: "text-start",
|
|
1327
|
+
id: textId
|
|
1328
|
+
};
|
|
1329
|
+
state.openBlock = "text";
|
|
1330
|
+
}
|
|
1331
|
+
yield {
|
|
1332
|
+
type: "text-delta",
|
|
1333
|
+
id: textId,
|
|
1334
|
+
delta: content
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
__name(emitTextDelta, "emitTextDelta");
|
|
1338
|
+
function* emitReasoningDelta(state, textId, content) {
|
|
1339
|
+
let reasoningId = state.openBlock === "reasoning" ? state.reasoningId : null;
|
|
1340
|
+
if (reasoningId === null) {
|
|
1341
|
+
yield* closeOpenBlock(state, textId);
|
|
1342
|
+
reasoningId = crypto.randomUUID();
|
|
1343
|
+
state.reasoningId = reasoningId;
|
|
1344
|
+
yield {
|
|
1345
|
+
type: "reasoning-start",
|
|
1346
|
+
id: reasoningId
|
|
1347
|
+
};
|
|
1348
|
+
state.openBlock = "reasoning";
|
|
1349
|
+
}
|
|
1350
|
+
yield {
|
|
1351
|
+
type: "reasoning-delta",
|
|
1352
|
+
id: reasoningId,
|
|
1353
|
+
delta: content
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
__name(emitReasoningDelta, "emitReasoningDelta");
|
|
1322
1357
|
function* emitToolCall(event, seen) {
|
|
1323
1358
|
seen.add(event.callId);
|
|
1324
1359
|
yield {
|
|
@@ -1395,39 +1430,13 @@ async function* translateToUIMessageStream(events, opts) {
|
|
|
1395
1430
|
reasoningId: null
|
|
1396
1431
|
};
|
|
1397
1432
|
const seenToolCallIds = /* @__PURE__ */ new Set();
|
|
1433
|
+
let turnMetadata;
|
|
1398
1434
|
try {
|
|
1399
1435
|
for await (const event of events) {
|
|
1400
1436
|
if (event.type === "text_delta") {
|
|
1401
|
-
|
|
1402
|
-
yield* closeOpenBlock(state, opts.textId);
|
|
1403
|
-
yield {
|
|
1404
|
-
type: "text-start",
|
|
1405
|
-
id: opts.textId
|
|
1406
|
-
};
|
|
1407
|
-
state.openBlock = "text";
|
|
1408
|
-
}
|
|
1409
|
-
yield {
|
|
1410
|
-
type: "text-delta",
|
|
1411
|
-
id: opts.textId,
|
|
1412
|
-
delta: event.content
|
|
1413
|
-
};
|
|
1437
|
+
yield* emitTextDelta(state, opts.textId, event.content);
|
|
1414
1438
|
} else if (event.type === "thinking") {
|
|
1415
|
-
|
|
1416
|
-
if (reasoningId === null) {
|
|
1417
|
-
yield* closeOpenBlock(state, opts.textId);
|
|
1418
|
-
reasoningId = crypto.randomUUID();
|
|
1419
|
-
state.reasoningId = reasoningId;
|
|
1420
|
-
yield {
|
|
1421
|
-
type: "reasoning-start",
|
|
1422
|
-
id: reasoningId
|
|
1423
|
-
};
|
|
1424
|
-
state.openBlock = "reasoning";
|
|
1425
|
-
}
|
|
1426
|
-
yield {
|
|
1427
|
-
type: "reasoning-delta",
|
|
1428
|
-
id: reasoningId,
|
|
1429
|
-
delta: event.content
|
|
1430
|
-
};
|
|
1439
|
+
yield* emitReasoningDelta(state, opts.textId, event.content);
|
|
1431
1440
|
} else if (event.type === "tool_call") {
|
|
1432
1441
|
yield* closeOpenBlock(state, opts.textId);
|
|
1433
1442
|
yield* emitToolCall(event, seenToolCallIds);
|
|
@@ -1447,6 +1456,7 @@ async function* translateToUIMessageStream(events, opts) {
|
|
|
1447
1456
|
};
|
|
1448
1457
|
break;
|
|
1449
1458
|
} else if (event.type === "done") {
|
|
1459
|
+
turnMetadata = doneToMetadata(event);
|
|
1450
1460
|
break;
|
|
1451
1461
|
}
|
|
1452
1462
|
}
|
|
@@ -1457,11 +1467,25 @@ async function* translateToUIMessageStream(events, opts) {
|
|
|
1457
1467
|
};
|
|
1458
1468
|
}
|
|
1459
1469
|
yield* closeOpenBlock(state, opts.textId);
|
|
1460
|
-
yield {
|
|
1470
|
+
yield turnMetadata ? {
|
|
1471
|
+
type: "finish",
|
|
1472
|
+
messageMetadata: turnMetadata
|
|
1473
|
+
} : {
|
|
1461
1474
|
type: "finish"
|
|
1462
1475
|
};
|
|
1463
1476
|
}
|
|
1464
1477
|
__name(translateToUIMessageStream, "translateToUIMessageStream");
|
|
1478
|
+
function doneToMetadata(event) {
|
|
1479
|
+
return event.cost === void 0 ? {
|
|
1480
|
+
usage: event.usage,
|
|
1481
|
+
durationMs: event.durationMs
|
|
1482
|
+
} : {
|
|
1483
|
+
usage: event.usage,
|
|
1484
|
+
durationMs: event.durationMs,
|
|
1485
|
+
cost: event.cost
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
__name(doneToMetadata, "doneToMetadata");
|
|
1465
1489
|
|
|
1466
1490
|
// src/bridge/define-agent.ts
|
|
1467
1491
|
var AGENT_BRAND = /* @__PURE__ */ Symbol.for("theokit.agent.definition");
|
|
@@ -2993,4 +3017,4 @@ export {
|
|
|
2993
3017
|
generateAgentManifest,
|
|
2994
3018
|
agentsPlugin
|
|
2995
3019
|
};
|
|
2996
|
-
//# sourceMappingURL=chunk-
|
|
3020
|
+
//# sourceMappingURL=chunk-5VK63XGX.js.map
|