@theokit/agents 0.21.1 → 0.22.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.
@@ -1,6 +1,6 @@
1
1
  import { ExecutionContext } from '@theokit/http';
2
- import { A as AgentOptions, T as ToolOptions, g as MainLoopMeta, a as ApprovalOptions, B as BudgetOptions, f as GatewayOptions, l as MemoryOptions, s as SkillsOptions, e as ContextWindowOptions, q as ProjectContextOptions, j as McpServersMap, b as CompactionDecoratorConfig } from './skills-CO7vBqHz.js';
3
- import { SystemPromptResolver, SkillsSettings, ContextSettings, PluginsSettings, Plugin, ProviderRoutingSettings, AgentDefinition, BudgetTracker, ConversationStorageAdapter, CustomTool } from '@theokit/sdk';
2
+ import { A as AgentOptions, T as ToolOptions, g as MainLoopMeta, a as ApprovalOptions, B as BudgetOptions, f as GatewayOptions, l as MemoryOptions, t as SkillsOptions, e as ContextWindowOptions, q as ProjectContextOptions, j as McpServersMap, b as CompactionDecoratorConfig, R as ReasoningEffort } from './skills-BzEzl0YN.js';
3
+ import { SystemPromptResolver, SkillsSettings, ContextSettings, PluginsSettings, Plugin, ProviderRoutingSettings, AgentDefinition, BudgetTracker, ConversationStorageAdapter, CustomTool, ModelSelection } from '@theokit/sdk';
4
4
  import { RetryOptions } from '@theokit/sdk/retry';
5
5
  import { z } from 'zod';
6
6
 
@@ -134,6 +134,8 @@ interface CompiledSubAgent {
134
134
  /** Compiled agent options ready for SDK Agent.create(). */
135
135
  interface CompiledAgentOptions {
136
136
  model?: string;
137
+ /** Extended-thinking effort declared via `@Agent({ reasoningEffort })`; mapped to SDK ModelSelection.params. */
138
+ reasoningEffort?: ReasoningEffort;
137
139
  /** Static prompt OR a per-request {@link SystemPromptResolver} (V4-L.1, Axis-B). */
138
140
  systemPrompt?: string | SystemPromptResolver;
139
141
  tools: CompiledTool[];
@@ -413,6 +415,11 @@ declare function generateAgentRoutes(ctx: AgentRouteContext): AgentRoute[];
413
415
  interface RuntimeOverrides {
414
416
  /** Overrides the model for this call (`?? compiled.model ?? default`). */
415
417
  model?: string;
418
+ /**
419
+ * Per-run extended-thinking effort (`?? compiled.reasoningEffort`). Mapped to the SDK
420
+ * `ModelSelection.params` so the provider produces reasoning (surfaced as `thinking` StreamEvents).
421
+ */
422
+ reasoningEffort?: ReasoningEffort;
416
423
  /** Per-run cwd → `Agent.create({ local: { cwd } })` → `SystemPromptContext.cwd`. */
417
424
  cwd?: string;
418
425
  /**
@@ -449,6 +456,20 @@ interface RuntimeOverrides {
449
456
  */
450
457
  declare function createSdkAgentStream(compiled: CompiledAgentOptions, compiledTools: CompiledTool[], apiKey: string, overrides?: RuntimeOverrides): (message: string, sessionId: string) => AsyncIterable<StreamEvent>;
451
458
 
459
+ /**
460
+ * Model-selection mapping (M1 reasoning-visibility) — the single site that turns a
461
+ * provider-agnostic `ReasoningEffort` into the SDK `ModelSelection`. Kept in its own small module
462
+ * (not inside `sdk-adapter.ts`) so the adapter stays under the G6 500-LoC budget and the helper has
463
+ * a focused home (per the plan's T1.1 "or a small sibling").
464
+ */
465
+
466
+ /**
467
+ * Build the SDK `ModelSelection` for a model id + optional reasoning effort. With no (or empty)
468
+ * effort it returns the bare `{ id }` — byte-identical to the prior behavior (backward-compat). With
469
+ * an effort it adds the canonical reasoning param `{ id: 'thinking', value: effort }`. Pure.
470
+ */
471
+ declare function buildModelSelection(modelId: string, effort?: ReasoningEffort): ModelSelection;
472
+
452
473
  /**
453
474
  * Translates @theokit/sdk SDKMessage events → TheoKit AgentStreamEvent.
454
475
  *
@@ -798,4 +819,4 @@ declare function agentsPlugin(opts: AgentsPluginOptions): {
798
819
  register(app: PluginApp): void;
799
820
  };
800
821
 
801
- export { delegate as $, type AgentExecutionContext as A, BudgetExceededError as B, type CompiledAgentOptions as C, type DelegationResult as D, type ErrorEvent as E, type FileEditEvent as F, type RunStartedEvent as G, type SdkMessage as H, type IterationEvent as I, type StateUpdateEvent as J, type ThinkingEvent as K, type LoopStrategy as L, type ToolCallEvent as M, type ToolResultEvent as N, type ToolWalkResult as O, type ToolboxWalkResult as P, agentsPlugin as Q, type ReflectionStrategy as R, type StreamEvent as S, type TextDeltaEvent as T, compileAgent as U, compileContextWindow as V, compileProjectContext as W, compileSkills as X, compileTools as Y, createAgentExecutionContext as Z, createSdkAgentStream as _, type CompiledTool as a, generateAgentManifest as a0, generateAgentRoutes as a1, isAgentContext as a2, isApprovalRequired as a3, isDone as a4, isError as a5, isTextDelta as a6, isToolCall as a7, isToolResult as a8, ladderReflectionStrategy as a9, loopStrategyConfigSchema as aa, noopReflectionStrategy as ab, projectContextMetadataOnlyKnobs as ac, reflectionStrategyConfigSchema as ad, resolveLoopStrategy as ae, streamAgentResponse as af, translateSdkEvent as ag, validateUniqueRoutes as ah, walkAgentMetadata as ai, type AgentManifest as b, type AgentManifestEntry as c, type AgentManifestTool as d, type AgentRoute as e, type AgentRouteContext as f, type AgentRunInfo as g, type AgentStreamEvent as h, type AgentWalkResult as i, AgentWarningCode as j, type AgentsPluginOptions as k, type ApprovalRequiredEvent as l, type ArtifactChunkEvent as m, type ArtifactStartEvent as n, type CheckpointSavedEvent as o, type CompiledContextWindow as p, DEFAULT_MAX_ITERATIONS as q, type DelegateOptions as r, DelegationError as s, type DoneEvent as t, type LoopFinishReason as u, type LoopOutcome as v, type LoopStrategyConfig as w, type ReflectionContext as x, type ReflectionResult as y, type ReflectionStrategyConfig as z };
822
+ export { createSdkAgentStream as $, type AgentExecutionContext as A, BudgetExceededError as B, type CompiledAgentOptions as C, type DelegationResult as D, type ErrorEvent as E, type FileEditEvent as F, type RunStartedEvent as G, type SdkMessage as H, type IterationEvent as I, type StateUpdateEvent as J, type ThinkingEvent as K, type LoopStrategy as L, type ToolCallEvent as M, type ToolResultEvent as N, type ToolWalkResult as O, type ToolboxWalkResult as P, agentsPlugin as Q, type ReflectionStrategy as R, type StreamEvent as S, type TextDeltaEvent as T, buildModelSelection as U, compileAgent as V, compileContextWindow as W, compileProjectContext as X, compileSkills as Y, compileTools as Z, createAgentExecutionContext as _, type CompiledTool as a, delegate as a0, generateAgentManifest as a1, generateAgentRoutes as a2, isAgentContext as a3, isApprovalRequired as a4, isDone as a5, isError as a6, isTextDelta as a7, isToolCall as a8, isToolResult as a9, ladderReflectionStrategy as aa, loopStrategyConfigSchema as ab, noopReflectionStrategy as ac, projectContextMetadataOnlyKnobs as ad, reflectionStrategyConfigSchema as ae, resolveLoopStrategy as af, streamAgentResponse as ag, translateSdkEvent as ah, validateUniqueRoutes as ai, walkAgentMetadata as aj, type AgentManifest as b, type AgentManifestEntry as c, type AgentManifestTool as d, type AgentRoute as e, type AgentRouteContext as f, type AgentRunInfo as g, type AgentStreamEvent as h, type AgentWalkResult as i, AgentWarningCode as j, type AgentsPluginOptions as k, type ApprovalRequiredEvent as l, type ArtifactChunkEvent as m, type ArtifactStartEvent as n, type CheckpointSavedEvent as o, type CompiledContextWindow as p, DEFAULT_MAX_ITERATIONS as q, type DelegateOptions as r, DelegationError as s, type DoneEvent as t, type LoopFinishReason as u, type LoopOutcome as v, type LoopStrategyConfig as w, type ReflectionContext as x, type ReflectionResult as y, type ReflectionStrategyConfig as z };
package/dist/bridge.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { A as AgentExecutionContext, b as AgentManifest, c as AgentManifestEntry, d as AgentManifestTool, e as AgentRoute, f as AgentRouteContext, g as AgentRunInfo, h as AgentStreamEvent, i as AgentWalkResult, j as AgentWarningCode, k as AgentsPluginOptions, l as ApprovalRequiredEvent, m as ArtifactChunkEvent, n as ArtifactStartEvent, B as BudgetExceededError, o as CheckpointSavedEvent, C as CompiledAgentOptions, p as CompiledContextWindow, a as CompiledTool, r as DelegateOptions, s as DelegationError, D as DelegationResult, t as DoneEvent, E as ErrorEvent, F as FileEditEvent, I as IterationEvent, G as RunStartedEvent, H as SdkMessage, J as StateUpdateEvent, S as StreamEvent, T as TextDeltaEvent, K as ThinkingEvent, M as ToolCallEvent, N as ToolResultEvent, O as ToolWalkResult, P as ToolboxWalkResult, Q as agentsPlugin, U as compileAgent, V as compileContextWindow, W as compileProjectContext, X as compileSkills, Y as compileTools, Z as createAgentExecutionContext, _ as createSdkAgentStream, $ as delegate, a0 as generateAgentManifest, a1 as generateAgentRoutes, a2 as isAgentContext, a3 as isApprovalRequired, a4 as isDone, a5 as isError, a6 as isTextDelta, a7 as isToolCall, a8 as isToolResult, ac as projectContextMetadataOnlyKnobs, af as streamAgentResponse, ag as translateSdkEvent, ah as validateUniqueRoutes, ai as walkAgentMetadata } from './bridge-entry-CEnpN6oR.js';
1
+ export { A as AgentExecutionContext, b as AgentManifest, c as AgentManifestEntry, d as AgentManifestTool, e as AgentRoute, f as AgentRouteContext, g as AgentRunInfo, h as AgentStreamEvent, i as AgentWalkResult, j as AgentWarningCode, k as AgentsPluginOptions, l as ApprovalRequiredEvent, m as ArtifactChunkEvent, n as ArtifactStartEvent, B as BudgetExceededError, o as CheckpointSavedEvent, C as CompiledAgentOptions, p as CompiledContextWindow, a as CompiledTool, r as DelegateOptions, s as DelegationError, D as DelegationResult, t as DoneEvent, E as ErrorEvent, F as FileEditEvent, I as IterationEvent, G as RunStartedEvent, H as SdkMessage, J as StateUpdateEvent, S as StreamEvent, T as TextDeltaEvent, K as ThinkingEvent, M as ToolCallEvent, N as ToolResultEvent, O as ToolWalkResult, P as ToolboxWalkResult, Q as agentsPlugin, U as buildModelSelection, V as compileAgent, W as compileContextWindow, X as compileProjectContext, Y as compileSkills, Z as compileTools, _ as createAgentExecutionContext, $ as createSdkAgentStream, a0 as delegate, a1 as generateAgentManifest, a2 as generateAgentRoutes, a3 as isAgentContext, a4 as isApprovalRequired, a5 as isDone, a6 as isError, a7 as isTextDelta, a8 as isToolCall, a9 as isToolResult, ad as projectContextMetadataOnlyKnobs, ag as streamAgentResponse, ah as translateSdkEvent, ai as validateUniqueRoutes, aj as walkAgentMetadata } from './bridge-entry-CHodDWs0.js';
2
2
  import '@theokit/http';
3
- import './skills-CO7vBqHz.js';
3
+ import './skills-BzEzl0YN.js';
4
4
  import '@theokit/sdk';
5
5
  import 'zod';
6
6
  import '@theokit/sdk/retry';
package/dist/bridge.js CHANGED
@@ -3,6 +3,7 @@ import {
3
3
  BudgetExceededError,
4
4
  DelegationError,
5
5
  agentsPlugin,
6
+ buildModelSelection,
6
7
  compileAgent,
7
8
  compileContextWindow,
8
9
  compileProjectContext,
@@ -25,7 +26,7 @@ import {
25
26
  translateSdkEvent,
26
27
  validateUniqueRoutes,
27
28
  walkAgentMetadata
28
- } from "./chunk-FN5HVN6P.js";
29
+ } from "./chunk-ITKVE65Q.js";
29
30
  import "./chunk-GVPUUKKE.js";
30
31
  import "./chunk-7QVYU63E.js";
31
32
  export {
@@ -33,6 +34,7 @@ export {
33
34
  BudgetExceededError,
34
35
  DelegationError,
35
36
  agentsPlugin,
37
+ buildModelSelection,
36
38
  compileAgent,
37
39
  compileContextWindow,
38
40
  compileProjectContext,
@@ -300,6 +300,7 @@ function compileAgent(walkResult, toolboxInstances = /* @__PURE__ */ new Map())
300
300
  const agents = compileSubAgents(walkResult.subAgentClasses);
301
301
  return {
302
302
  model: walkResult.agentConfig.model,
303
+ reasoningEffort: walkResult.agentConfig.reasoningEffort,
303
304
  systemPrompt: walkResult.agentConfig.systemPrompt,
304
305
  tools,
305
306
  agents,
@@ -607,6 +608,64 @@ function translateSdkEvent(msg, runId) {
607
608
  }
608
609
  }
609
610
  __name(translateSdkEvent, "translateSdkEvent");
611
+ function translateInteractionUpdate(update) {
612
+ switch (update.type) {
613
+ case "text-delta":
614
+ return update.text ? [
615
+ {
616
+ type: "text_delta",
617
+ content: update.text
618
+ }
619
+ ] : [];
620
+ case "thinking-delta":
621
+ return update.text ? [
622
+ {
623
+ type: "thinking",
624
+ content: update.text
625
+ }
626
+ ] : [];
627
+ case "tool-call-started":
628
+ return [
629
+ {
630
+ type: "tool_call",
631
+ callId: update.callId,
632
+ toolName: update.toolCall.name,
633
+ input: update.toolCall.args ?? {}
634
+ }
635
+ ];
636
+ case "tool-call-completed":
637
+ return [
638
+ {
639
+ type: "tool_result",
640
+ callId: update.callId,
641
+ toolName: update.toolCall.name,
642
+ output: serializeToolOutput(update.toolCall.result, ""),
643
+ durationMs: 0,
644
+ isError: false
645
+ }
646
+ ];
647
+ default:
648
+ return [];
649
+ }
650
+ }
651
+ __name(translateInteractionUpdate, "translateInteractionUpdate");
652
+
653
+ // src/bridge/model-selection.ts
654
+ function buildModelSelection(modelId, effort) {
655
+ if (!effort) return {
656
+ id: modelId
657
+ };
658
+ return {
659
+ id: modelId,
660
+ params: [
661
+ {
662
+ id: "thinking",
663
+ value: effort
664
+ }
665
+ ]
666
+ };
667
+ }
668
+ __name(buildModelSelection, "buildModelSelection");
610
669
 
611
670
  // src/bridge/sdk-adapter.ts
612
671
  function assembleM8CreateOptions(compiled) {
@@ -703,9 +762,29 @@ function createAsyncQueue() {
703
762
  };
704
763
  }
705
764
  __name(createAsyncQueue, "createAsyncQueue");
706
- async function* mergeDeltaStream(stream, queue, runId, state) {
765
+ function streamCallId(ev) {
766
+ return typeof ev.callId === "string" ? ev.callId : "";
767
+ }
768
+ __name(streamCallId, "streamCallId");
769
+ function isDuplicatedByDelta(ev, state) {
770
+ if (ev.type === "text_delta") return state.sawTextDelta;
771
+ if (ev.type === "thinking") return state.sawThinkingDelta;
772
+ if (ev.type === "tool_call") {
773
+ const id = streamCallId(ev);
774
+ return id !== "" && state.emittedToolCallIds.has(id);
775
+ }
776
+ if (ev.type === "tool_result") {
777
+ const id = streamCallId(ev);
778
+ return id !== "" && state.emittedToolResultIds.has(id);
779
+ }
780
+ return false;
781
+ }
782
+ __name(isDuplicatedByDelta, "isDuplicatedByDelta");
783
+ async function* mergeDeltaStream(queue, openStream, runId, state) {
784
+ let pumpError;
707
785
  const pump = (async () => {
708
786
  try {
787
+ const stream = await openStream();
709
788
  for await (const msg of stream) queue.push({
710
789
  kind: "sdk",
711
790
  msg
@@ -713,7 +792,11 @@ async function* mergeDeltaStream(stream, queue, runId, state) {
713
792
  } finally {
714
793
  queue.close();
715
794
  }
716
- })();
795
+ })().catch((thrown) => {
796
+ pumpError = {
797
+ thrown
798
+ };
799
+ });
717
800
  for await (const item of queue) {
718
801
  if (item.kind === "delta") {
719
802
  yield item.event;
@@ -721,16 +804,49 @@ async function* mergeDeltaStream(stream, queue, runId, state) {
721
804
  }
722
805
  for (const out of translateSdkEvent(item.msg, runId)) {
723
806
  if (out.type === "done") continue;
724
- if (out.type === "text_delta" && state.sawDelta) continue;
807
+ if (isDuplicatedByDelta(out, state)) continue;
725
808
  if (out.type === "error") state.sawError = true;
726
809
  yield out;
727
810
  }
728
811
  }
729
812
  await pump;
813
+ if (pumpError) throw pumpError.thrown;
730
814
  }
731
815
  __name(mergeDeltaStream, "mergeDeltaStream");
816
+ function createDeltaSink(queue) {
817
+ const state = {
818
+ sawTextDelta: false,
819
+ sawThinkingDelta: false,
820
+ emittedToolCallIds: /* @__PURE__ */ new Set(),
821
+ emittedToolResultIds: /* @__PURE__ */ new Set(),
822
+ sawError: false
823
+ };
824
+ const onDelta = /* @__PURE__ */ __name((d) => {
825
+ for (const event of translateInteractionUpdate(d.update)) {
826
+ if (event.type === "text_delta") state.sawTextDelta = true;
827
+ else if (event.type === "thinking") state.sawThinkingDelta = true;
828
+ else if (event.type === "tool_call") {
829
+ const id = streamCallId(event);
830
+ if (id !== "") state.emittedToolCallIds.add(id);
831
+ } else if (event.type === "tool_result") {
832
+ const id = streamCallId(event);
833
+ if (id !== "") state.emittedToolResultIds.add(id);
834
+ }
835
+ queue.push({
836
+ kind: "delta",
837
+ event
838
+ });
839
+ }
840
+ }, "onDelta");
841
+ return {
842
+ state,
843
+ onDelta
844
+ };
845
+ }
846
+ __name(createDeltaSink, "createDeltaSink");
732
847
  function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
733
848
  const model = overrides.model ?? compiled.model ?? "openai/gpt-4o-mini";
849
+ const reasoningEffort = overrides.reasoningEffort ?? compiled.reasoningEffort;
734
850
  let storage = overrides.conversationStorage;
735
851
  return (message, sessionId) => ({
736
852
  async *[Symbol.asyncIterator]() {
@@ -780,39 +896,23 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
780
896
  }
781
897
  agent = await Agent.getOrCreate(sessionId, {
782
898
  apiKey,
783
- model: {
784
- id: model
785
- },
899
+ model: buildModelSelection(model, reasoningEffort),
786
900
  tools: sdkTools,
787
901
  ...m8,
788
902
  ...extra,
789
903
  conversationStorage: storage
790
904
  });
791
905
  const queue = createAsyncQueue();
792
- const state = {
793
- sawDelta: false,
794
- sawError: false
795
- };
796
- const onDelta = /* @__PURE__ */ __name((d) => {
797
- if (d.update.type === "text-delta" && d.update.text) {
798
- state.sawDelta = true;
799
- queue.push({
800
- kind: "delta",
801
- event: {
802
- type: "text_delta",
803
- content: d.update.text
804
- }
805
- });
806
- }
807
- }, "onDelta");
808
- const run = await agent.send(message, {
906
+ const { state, onDelta } = createDeltaSink(queue);
907
+ const sendPromise = agent.send(message, {
809
908
  onDelta
810
909
  });
811
- for await (const event of mergeDeltaStream(run.stream(), queue, runId, state)) {
910
+ const openStream = /* @__PURE__ */ __name(async () => (await sendPromise).stream(), "openStream");
911
+ for await (const event of mergeDeltaStream(queue, openStream, runId, state)) {
812
912
  yield event;
813
913
  }
814
914
  if (!state.sawError) {
815
- yield realUsageDone(await run.wait(), t0);
915
+ yield realUsageDone(await (await sendPromise).wait(), t0);
816
916
  }
817
917
  } catch (err) {
818
918
  yield {
@@ -1251,6 +1351,7 @@ var AgentRunner = class {
1251
1351
  const loop = opts.maxIterations != null ? resolveLoopStrategy(this.loopStrategy.name, opts.maxIterations) : this.loopStrategy;
1252
1352
  const streamFactory = opts.streamFactory ?? createSdkAgentStream(this.compiled, tools, opts.apiKey, {
1253
1353
  model: opts.model,
1354
+ reasoningEffort: opts.reasoningEffort,
1254
1355
  cwd: opts.cwd,
1255
1356
  plugins: opts.plugins,
1256
1357
  providers: opts.providers,
@@ -1532,6 +1633,7 @@ export {
1532
1633
  isApprovalRequired,
1533
1634
  generateAgentRoutes,
1534
1635
  translateSdkEvent,
1636
+ buildModelSelection,
1535
1637
  createSdkAgentStream,
1536
1638
  DEFAULT_KEEP_TOKENS,
1537
1639
  compactionStrategyConfigSchema,
@@ -1551,4 +1653,4 @@ export {
1551
1653
  generateAgentManifest,
1552
1654
  agentsPlugin
1553
1655
  };
1554
- //# sourceMappingURL=chunk-FN5HVN6P.js.map
1656
+ //# sourceMappingURL=chunk-ITKVE65Q.js.map