@theokit/agents 0.39.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.
@@ -1,6 +1,6 @@
1
1
  import { ExecutionContext } from '@theokit/http';
2
2
  import { A as AgentOptions, g as ToolOptions, M as MainLoopMeta, a as ApprovalOptions, B as BudgetOptions, H as HumanInTheLoopOptions, t as GatewayOptions, z as MemoryOptions, O as SkillsOptions, r as ContextWindowOptions, K as ProjectContextOptions, x as McpServersMap, G as Guardrail, o as CompactionDecoratorConfig, j as CheckpointOptions, R as ReasoningEffort } from './types-DVA4LQsA.js';
3
- import { InlineSkill, SystemPromptResolver, ConversationStorageAdapter, SkillsSettings, ContextSettings, PluginsSettings, Plugin, ProviderRoutingSettings, AgentDefinition as AgentDefinition$1, BudgetTracker, CustomTool, ModelSelection } from '@theokit/sdk';
3
+ import { InlineSkill, SystemPromptResolver, SettingSource, SkillsSettings, ContextSettings, PluginsSettings, Plugin, ProviderRoutingSettings, AgentDefinition as AgentDefinition$1, BudgetTracker, CustomTool, ModelSelection } from '@theokit/sdk';
4
4
  import { UIMessageChunk } from 'ai';
5
5
  import { z } from 'zod';
6
6
  import { RetryOptions } from '@theokit/sdk/retry';
@@ -191,13 +191,11 @@ interface CompiledAgentOptions {
191
191
  /** Static prompt OR a per-request {@link SystemPromptResolver} (V4-L.1, Axis-B). */
192
192
  systemPrompt?: string | SystemPromptResolver;
193
193
  /**
194
- * Agent-level conversation memory: the `ConversationStorageAdapter` the SDK persists turns to
195
- * (`Agent.getOrCreate({ conversationStorage })`). Populated by `defineAgent({ conversationStorage })`
196
- * / `.conversationStorage(adapter)`. A per-run override (`RuntimeOverrides.conversationStorage`)
197
- * wins over this; absent ⇒ the SDK default store is chosen lazily. Distinct from `@Checkpoint`,
198
- * which only toggles filesystem-vs-memory for the built-in default.
194
+ * theokit-file-based-config opt-in `.theokit/` file-based config roots (`"project"`/`"user"`/…).
195
+ * Projected into `Agent.create({ local: { settingSources } })` by `assembleM8CreateOptions`
196
+ * (merged with `cwd`, decoupled from inline skills). Absent inline (code) config only.
199
197
  */
200
- conversationStorage?: ConversationStorageAdapter;
198
+ settingSources?: readonly SettingSource[];
201
199
  tools: CompiledTool[];
202
200
  agents: Record<string, CompiledSubAgent>;
203
201
  memory?: MemoryOptions;
@@ -416,6 +414,19 @@ interface DoneEvent {
416
414
  /** Total cost in USD for this agent run (EC-2: added for budget tracking). */
417
415
  cost?: number;
418
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
+ }
419
430
  /** Agent run started. */
420
431
  interface RunStartedEvent {
421
432
  type: 'run_started';
@@ -563,11 +574,13 @@ interface RuntimeOverrides {
563
574
  /** Per-run SDK budget tracker (inner tool-loop cap; distinct from the loop's USD `budget`). */
564
575
  budgetTracker?: BudgetTracker;
565
576
  /**
566
- * V4-M: conversation store shared across the loop's rounds so history persists
567
- * (round N+1 sees rounds 1..N). Default `InMemoryConversationStorage` (per-run,
568
- * no disk). Pass a `FileSystemConversationStorage`/custom adapter for durable history.
577
+ * SDK 4.0 (SE40) root of the native Claude-shaped `.jsonl` session transcript the SDK writes
578
+ * automatically (`<baseDir>/projects/<encoded-cwd>/<agentId>.jsonl`). The framework threads the
579
+ * app's project root here (see `mount-agent`) so sessions persist per-app; unset ⇒ SDK default
580
+ * (`~/.theokit`). Replaces the removed pluggable `conversationStorage` — persistence is now the
581
+ * SDK's native transcript, not a swappable adapter.
569
582
  */
570
- conversationStorage?: ConversationStorageAdapter;
583
+ baseDir?: string;
571
584
  /**
572
585
  * V4-Q: pre-built SDK `CustomTool[]` forwarded RAW to `Agent.create.tools` (appended after the
573
586
  * compiled tools), bypassing `defineTool` (which requires a Zod schema). Lets an app whose tools
@@ -736,12 +749,14 @@ interface DefineAgentConfig<TInput extends z.ZodType = z.ZodType> {
736
749
  */
737
750
  skills?: SkillsSelection;
738
751
  /**
739
- * Conversation memory: the `ConversationStorageAdapter` the agent persists its turns to. Swap it to
740
- * control WHERE memory lives `InMemoryConversationStorage` (ephemeral, great for tests) vs
741
- * `FileSystemConversationStorage` (durable) vs a custom adapter. Absent ⇒ the SDK picks its default
742
- * store. A per-run override still wins over this agent-level default.
752
+ * theokit-file-based-config opt into `.theokit/` file-based config (skills, subagents, hooks,
753
+ * MCP, context, cron). The SDK discovers config from these roots under the app's `cwd`:
754
+ * `"project"` = `<cwd>/.theokit/`, `"user"` = `~/.theokit/`. Absent ⇒ inline (code) config only.
755
+ * SECURITY: enabling `"project"` enables shell-executing hooks from `.theokit/hooks.json` this
756
+ * is opt-in because `.theokit/` is the app's own repo (informed consent). The SDK owns discovery
757
+ * + execution (G2 / ADR-0040); theokit only wires this into `Agent.create({ local.settingSources })`.
743
758
  */
744
- conversationStorage?: ConversationStorageAdapter;
759
+ settingSources?: readonly SettingSource[];
745
760
  }
746
761
  /**
747
762
  * A branded agent definition — the value {@link defineAgent} returns.
@@ -873,10 +888,12 @@ interface AgentBuilder<TInput extends z.ZodType | UnsetMarker = UnsetMarker, TMo
873
888
  */
874
889
  skills(selection: SkillsSelection): AgentBuilder<TInput, TModel, TContext, TTools>;
875
890
  /**
876
- * Set the agent's conversation memory the `ConversationStorageAdapter` the SDK persists turns to.
877
- * Swap in-memory filesystem custom without touching the runtime. A per-run override still wins.
891
+ * theokit-file-based-config opt into `.theokit/` file-based config (skills, subagents, hooks,
892
+ * MCP, context, cron), discovered by the SDK from the app root (`"project"` = `<cwd>/.theokit/`,
893
+ * `"user"` = `~/.theokit/`). Unset ⇒ inline (code) config only. SECURITY: `"project"` enables
894
+ * shell-executing hooks from `.theokit/hooks.json` — opt-in because `.theokit/` is your own repo.
878
895
  */
879
- conversationStorage(adapter: ConversationStorageAdapter): AgentBuilder<TInput, TModel, TContext, TTools>;
896
+ settingSources(sources: readonly SettingSource[]): AgentBuilder<TInput, TModel, TContext, TTools>;
880
897
  /**
881
898
  * Apply a reusable partial chain (Spring-Boot-style composition). `preset` receives the current
882
899
  * builder and returns an advanced one; its accumulated type-state flows through.
@@ -974,8 +991,18 @@ interface StreamAgentOptions {
974
991
  sessionId: string;
975
992
  /** Enable human-in-the-loop tool approval (M4). Absent ⇒ the M2 non-HITL path, byte-unchanged. */
976
993
  hitl?: StreamHitlOptions;
977
- /** Durable conversation storage for resume (M4); defaults to the SDK per-run in-memory store. */
978
- conversationStorage?: RuntimeOverrides['conversationStorage'];
994
+ /**
995
+ * theokit-file-based-config (EC-1) — the app root `cwd` the SDK resolves `.theokit/` against when
996
+ * `settingSources` is active. The framework boundary (`mountAgent`) threads its resolved
997
+ * `projectRoot` here so discovery points at the app root, NOT `process.cwd()`. Absent ⇒ no `local.cwd`.
998
+ */
999
+ cwd?: RuntimeOverrides['cwd'];
1000
+ /**
1001
+ * SDK 4.0 (SE40) — root of the native `.jsonl` session transcript. The framework boundary
1002
+ * (`mountAgent`) threads the resolved app root here so sessions persist per-app; absent ⇒ the SDK
1003
+ * default (`~/.theokit`).
1004
+ */
1005
+ baseDir?: RuntimeOverrides['baseDir'];
979
1006
  /**
980
1007
  * The request's abort signal (M4). On client disconnect, the HITL merge queue is closed so the
981
1008
  * detached SDK pump stops buffering (bounded memory) and the client stream terminates at once.
@@ -1242,8 +1269,6 @@ interface DelegateOptions {
1242
1269
  agents?: Record<string, AgentDefinition$1>;
1243
1270
  /** Per-run SDK budget tracker (inner tool-loop cap). */
1244
1271
  budgetTracker?: BudgetTracker;
1245
- /** Per-run conversation store (cross-round history). */
1246
- conversationStorage?: ConversationStorageAdapter;
1247
1272
  /** Per-run pre-built SDK tools forwarded raw (V4-Q). */
1248
1273
  sdkTools?: readonly CustomTool[];
1249
1274
  /** Per-round transient retry (V4-P). */
@@ -1631,4 +1656,4 @@ declare function agentsPlugin(opts: AgentsPluginOptions): {
1631
1656
  register(app: PluginApp): void;
1632
1657
  };
1633
1658
 
1634
- export { type McpRequestContext as $, type AgentManifestEntry as A, type BackgroundDelegation as B, type CompiledAgentOptions as C, type DelegationResult as D, type CompiledContextWindow as E, type ContextualTool as F, DEFAULT_MAX_ITERATIONS as G, type DefineAgentConfig as H, type DelegateFn as I, type DelegateOptions as J, DelegationError as K, type LoopStrategy as L, type DoneEvent as M, type ErrorEvent as N, type FileEditEvent as O, type HitlDecision as P, type InferAgentInput as Q, type ReflectionStrategy as R, type StreamEvent as S, type InferAgentToolNames as T, type IterationEvent as U, type LLMCallContext as V, type LoopFinishReason as W, type LoopOutcome as X, type LoopStrategyConfig as Y, type McpApprovalSpec as Z, type McpRegistryConfig as _, type CompiledTool as a, resolveLoopStrategy as a$, type McpSelection as a0, type PartialToolCallEvent as a1, type ProcessInputContext as a2, type ReflectionContext as a3, type ReflectionResult as a4, type ReflectionStrategyConfig as a5, type RunStartedEvent as a6, type ScoreVerdict as a7, type ScoredDelegation as a8, type Scorer as a9, createApiErrorHandler as aA, createSdkAgentStream as aB, createThinkTagExtractor as aC, createToolHooksPlugin as aD, delegate as aE, delegateBackground as aF, delegateWithScoring as aG, extractThinkTagStream as aH, generateAgentManifest as aI, generateAgentRoutes as aJ, isAgentContext as aK, isAgentDefinition as aL, isApprovalRequired as aM, isDone as aN, isError as aO, isPartialToolCall as aP, isTextDelta as aQ, isToolCall as aR, isToolResult as aS, ladderReflectionStrategy as aT, loopStrategyConfigSchema as aU, mcpRegistry as aV, mcpToolApprovals as aW, noopReflectionStrategy as aX, projectContextMetadataOnlyKnobs as aY, reflectionStrategyConfigSchema as aZ, resolveEnabledSkills as a_, type SdkMessage as aa, type Segment as ab, type SkillsRequestContext as ac, type SkillsSelection as ad, type StateUpdateEvent as ae, type TextDeltaEvent as af, type ThinkingEvent as ag, type ToolCallEvent as ah, type ToolCallVeto as ai, type ToolHooks as aj, type ToolHooksPlugin as ak, type ToolResultEvent as al, type ToolWalkResult as am, type ToolboxWalkResult as an, agent as ao, agentsPlugin as ap, buildModelSelection as aq, compileAgent as ar, compileAgentDefinition as as, compileAgentModule as at, compileContextWindow as au, compileProjectContext as av, compileSkills as aw, compileTools as ax, contextualTool as ay, createAgentExecutionContext as az, type RoundStreamFactory as b, resolveMcpServers as b0, runWithApiErrorHandling as b1, streamAgentResponse as b2, streamAgentUIMessages as b3, translateSdkEvent as b4, translateToUIMessageStream as b5, validateUniqueRoutes as b6, walkAgentMetadata as b7, 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 AgentWalkResult as o, AgentWarningCode as p, type AgentsPluginOptions as q, type ApiErrorContext as r, type ApiErrorDecision as s, type ApiErrorPolicy as t, type ApprovalRequiredEvent as u, type ArtifactChunkEvent as v, type ArtifactStartEvent as w, type BeforeToolCallContext as x, BudgetExceededError as y, type CheckpointSavedEvent as z };
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 AgentWalkResult, p as AgentWarningCode, q as AgentsPluginOptions, r as ApiErrorContext, s as ApiErrorDecision, t as ApiErrorPolicy, u as ApprovalRequiredEvent, v as ArtifactChunkEvent, w as ArtifactStartEvent, B as BackgroundDelegation, x as BeforeToolCallContext, y as BudgetExceededError, z as CheckpointSavedEvent, C as CompiledAgentOptions, E as CompiledContextWindow, a as CompiledTool, F as ContextualTool, H as DefineAgentConfig, I as DelegateFn, J as DelegateOptions, K as DelegationError, D as DelegationResult, M as DoneEvent, N as ErrorEvent, O as FileEditEvent, Q as InferAgentInput, T as InferAgentToolNames, U as IterationEvent, V as LLMCallContext, Z as McpApprovalSpec, _ as McpRegistryConfig, $ as McpRequestContext, a0 as McpSelection, a1 as PartialToolCallEvent, a2 as ProcessInputContext, a6 as RunStartedEvent, a7 as ScoreVerdict, a8 as ScoredDelegation, a9 as Scorer, aa as SdkMessage, ab as Segment, ae as StateUpdateEvent, S as StreamEvent, af as TextDeltaEvent, ag as ThinkingEvent, ah as ToolCallEvent, ai as ToolCallVeto, aj as ToolHooks, ak as ToolHooksPlugin, al as ToolResultEvent, am as ToolWalkResult, an as ToolboxWalkResult, ao as agent, ap as agentsPlugin, aq as buildModelSelection, ar as compileAgent, as as compileAgentDefinition, at as compileAgentModule, au as compileContextWindow, av as compileProjectContext, aw as compileSkills, ax as compileTools, ay as contextualTool, az as createAgentExecutionContext, aA as createApiErrorHandler, aB as createSdkAgentStream, aC as createThinkTagExtractor, aD as createToolHooksPlugin, aE as delegate, aF as delegateBackground, aG as delegateWithScoring, aH as extractThinkTagStream, aI as generateAgentManifest, aJ as generateAgentRoutes, aK as isAgentContext, aL as isAgentDefinition, aM as isApprovalRequired, aN as isDone, aO as isError, aP as isPartialToolCall, aQ as isTextDelta, aR as isToolCall, aS as isToolResult, aV as mcpRegistry, aW as mcpToolApprovals, aY as projectContextMetadataOnlyKnobs, b0 as resolveMcpServers, b1 as runWithApiErrorHandling, b2 as streamAgentResponse, b3 as streamAgentUIMessages, b4 as translateSdkEvent, b5 as translateToUIMessageStream, b6 as validateUniqueRoutes, b7 as walkAgentMetadata } from './bridge-entry-CAY5JP9z.js';
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
@@ -46,7 +46,7 @@ import {
46
46
  translateToUIMessageStream,
47
47
  validateUniqueRoutes,
48
48
  walkAgentMetadata
49
- } from "./chunk-JID4DOB3.js";
49
+ } from "./chunk-5VK63XGX.js";
50
50
  import "./chunk-NERDIS45.js";
51
51
  import "./chunk-7QVYU63E.js";
52
52
  export {
@@ -820,12 +820,15 @@ function assembleM8CreateOptions(compiled) {
820
820
  const base = compiled.systemPrompt;
821
821
  if (compiled.skills) {
822
822
  options.skills = compiled.skills;
823
+ applied.push("skills");
824
+ }
825
+ const settingSources = resolveSettingSources(compiled);
826
+ if (settingSources) {
823
827
  options.local = {
824
- settingSources: [
825
- "project"
826
- ]
828
+ ...options.local,
829
+ settingSources
827
830
  };
828
- applied.push("skills");
831
+ applied.push("settingSources");
829
832
  }
830
833
  if (compiled.context) {
831
834
  options.context = compiled.context;
@@ -847,6 +850,17 @@ function assembleM8CreateOptions(compiled) {
847
850
  };
848
851
  }
849
852
  __name(assembleM8CreateOptions, "assembleM8CreateOptions");
853
+ function resolveSettingSources(compiled) {
854
+ const explicit = compiled.settingSources;
855
+ if (explicit && explicit.length > 0) return [
856
+ ...explicit
857
+ ];
858
+ if (compiled.skills) return [
859
+ "project"
860
+ ];
861
+ return void 0;
862
+ }
863
+ __name(resolveSettingSources, "resolveSettingSources");
850
864
  function realUsageDone(result, t0) {
851
865
  const u = result.usage;
852
866
  const inputTokens = u?.inputTokens ?? 0;
@@ -994,15 +1008,12 @@ __name(buildExtraCreateOptions, "buildExtraCreateOptions");
994
1008
  async function loadSdkRuntime() {
995
1009
  try {
996
1010
  const sdk = await import("@theokit/sdk");
997
- const InMemory = sdk.InMemoryConversationStorage;
998
1011
  const skillReadTool = "SkillReadTool" in sdk ? sdk.SkillReadTool : void 0;
999
1012
  return {
1000
1013
  Agent: sdk.Agent,
1001
1014
  // `.bind` keeps the static factory callable when detached from `sdk.Tool` (it takes no `this`,
1002
1015
  // but binding is explicit + satisfies unbound-method rather than relying on that).
1003
1016
  defineTool: sdk.Tool.create.bind(sdk.Tool),
1004
- InMemoryConversationStorage: InMemory,
1005
- FileSystemConversationStorage: "FileSystemConversationStorage" in sdk ? sdk.FileSystemConversationStorage : InMemory,
1006
1017
  ...skillReadTool ? {
1007
1018
  defineSkillReadTool: /* @__PURE__ */ __name((skills) => skillReadTool.create(skills), "defineSkillReadTool")
1008
1019
  } : {}
@@ -1013,10 +1024,6 @@ async function loadSdkRuntime() {
1013
1024
  }
1014
1025
  }
1015
1026
  __name(loadSdkRuntime, "loadSdkRuntime");
1016
- function newConversationStorage(compiled, InMemory, FileSystem) {
1017
- return compiled.checkpoint?.storage === "filesystem" ? new FileSystem() : new InMemory();
1018
- }
1019
- __name(newConversationStorage, "newConversationStorage");
1020
1027
  function createAsyncQueue() {
1021
1028
  const items = [];
1022
1029
  let wake = null;
@@ -1186,7 +1193,6 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
1186
1193
  const reasoningEffort = overrides.reasoningEffort ?? compiled.reasoningEffort;
1187
1194
  const { parseThinkTags, stripToolDialect } = resolveTextTransformFlags(compiled, overrides);
1188
1195
  const runContext = overrides.runContext ?? compiled.runContext;
1189
- let storage = overrides.conversationStorage ?? compiled.conversationStorage;
1190
1196
  return (message, sessionId, factoryOpts) => ({
1191
1197
  async *[Symbol.asyncIterator]() {
1192
1198
  const runId = `run-${Date.now()}`;
@@ -1201,7 +1207,6 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
1201
1207
  };
1202
1208
  return;
1203
1209
  }
1204
- const { InMemoryConversationStorage, FileSystemConversationStorage } = rt;
1205
1210
  const sdkTools = buildSdkTools(compiledTools, rt.defineTool, overrides.sdkTools, runContext);
1206
1211
  const inlineSkills = compiled.skills?.inline;
1207
1212
  if (inlineSkills !== void 0 && inlineSkills.length > 0 && rt.defineSkillReadTool !== void 0 && !compiledTools.some((t) => t.name === "skill_read")) {
@@ -1219,9 +1224,8 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
1219
1224
  source: runContextSource,
1220
1225
  keys: runContext !== void 0 ? Object.keys(runContext) : []
1221
1226
  });
1222
- storage ??= newConversationStorage(compiled, InMemoryConversationStorage, FileSystemConversationStorage);
1223
1227
  try {
1224
- yield* streamSdkAgent(rt, compiled, sdkTools, storage, {
1228
+ yield* streamSdkAgent(rt, compiled, sdkTools, {
1225
1229
  apiKey,
1226
1230
  model,
1227
1231
  reasoningEffort,
@@ -1246,7 +1250,7 @@ function createSdkAgentStream(compiled, compiledTools, apiKey, overrides = {}) {
1246
1250
  });
1247
1251
  }
1248
1252
  __name(createSdkAgentStream, "createSdkAgentStream");
1249
- async function* streamSdkAgent(rt, compiled, sdkTools, storage, opts) {
1253
+ async function* streamSdkAgent(rt, compiled, sdkTools, opts) {
1250
1254
  const { Agent } = rt;
1251
1255
  const { apiKey, model, reasoningEffort, overrides, parseThinkTags, stripToolDialect, sessionId, message, factoryOpts, runId, t0 } = opts;
1252
1256
  const { options: m8, applied } = assembleM8CreateOptions(compiled);
@@ -1254,6 +1258,10 @@ async function* streamSdkAgent(rt, compiled, sdkTools, storage, opts) {
1254
1258
  ...m8.local,
1255
1259
  cwd: overrides.cwd
1256
1260
  };
1261
+ if (overrides.baseDir !== void 0) m8.local = {
1262
+ ...m8.local,
1263
+ baseDir: overrides.baseDir
1264
+ };
1257
1265
  const extra = buildExtraCreateOptions(overrides, compiled);
1258
1266
  if (applied.length > 0) {
1259
1267
  debugLog("[THEO_AGENT_M8_RUNTIME_APPLIED]", {
@@ -1267,8 +1275,7 @@ async function* streamSdkAgent(rt, compiled, sdkTools, storage, opts) {
1267
1275
  model: buildModelSelection(model, reasoningEffort),
1268
1276
  tools: sdkTools,
1269
1277
  ...m8,
1270
- ...extra,
1271
- conversationStorage: storage
1278
+ ...extra
1272
1279
  });
1273
1280
  try {
1274
1281
  const queue = createAsyncQueue();
@@ -1312,6 +1319,41 @@ function* closeOpenBlock(state, textId) {
1312
1319
  state.reasoningId = null;
1313
1320
  }
1314
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");
1315
1357
  function* emitToolCall(event, seen) {
1316
1358
  seen.add(event.callId);
1317
1359
  yield {
@@ -1388,39 +1430,13 @@ async function* translateToUIMessageStream(events, opts) {
1388
1430
  reasoningId: null
1389
1431
  };
1390
1432
  const seenToolCallIds = /* @__PURE__ */ new Set();
1433
+ let turnMetadata;
1391
1434
  try {
1392
1435
  for await (const event of events) {
1393
1436
  if (event.type === "text_delta") {
1394
- if (state.openBlock !== "text") {
1395
- yield* closeOpenBlock(state, opts.textId);
1396
- yield {
1397
- type: "text-start",
1398
- id: opts.textId
1399
- };
1400
- state.openBlock = "text";
1401
- }
1402
- yield {
1403
- type: "text-delta",
1404
- id: opts.textId,
1405
- delta: event.content
1406
- };
1437
+ yield* emitTextDelta(state, opts.textId, event.content);
1407
1438
  } else if (event.type === "thinking") {
1408
- let reasoningId = state.openBlock === "reasoning" ? state.reasoningId : null;
1409
- if (reasoningId === null) {
1410
- yield* closeOpenBlock(state, opts.textId);
1411
- reasoningId = crypto.randomUUID();
1412
- state.reasoningId = reasoningId;
1413
- yield {
1414
- type: "reasoning-start",
1415
- id: reasoningId
1416
- };
1417
- state.openBlock = "reasoning";
1418
- }
1419
- yield {
1420
- type: "reasoning-delta",
1421
- id: reasoningId,
1422
- delta: event.content
1423
- };
1439
+ yield* emitReasoningDelta(state, opts.textId, event.content);
1424
1440
  } else if (event.type === "tool_call") {
1425
1441
  yield* closeOpenBlock(state, opts.textId);
1426
1442
  yield* emitToolCall(event, seenToolCallIds);
@@ -1440,6 +1456,7 @@ async function* translateToUIMessageStream(events, opts) {
1440
1456
  };
1441
1457
  break;
1442
1458
  } else if (event.type === "done") {
1459
+ turnMetadata = doneToMetadata(event);
1443
1460
  break;
1444
1461
  }
1445
1462
  }
@@ -1450,11 +1467,25 @@ async function* translateToUIMessageStream(events, opts) {
1450
1467
  };
1451
1468
  }
1452
1469
  yield* closeOpenBlock(state, opts.textId);
1453
- yield {
1470
+ yield turnMetadata ? {
1471
+ type: "finish",
1472
+ messageMetadata: turnMetadata
1473
+ } : {
1454
1474
  type: "finish"
1455
1475
  };
1456
1476
  }
1457
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");
1458
1489
 
1459
1490
  // src/bridge/define-agent.ts
1460
1491
  var AGENT_BRAND = /* @__PURE__ */ Symbol.for("theokit.agent.definition");
@@ -1502,10 +1533,10 @@ function compileAgentDefinition(def) {
1502
1533
  } : {},
1503
1534
  // M13 — skills: a static list → SDK skills.enabled; a resolver → carried for the request path.
1504
1535
  ...compileSkillsSelection(def.skills),
1505
- // Conversation memory: the declared adapter flows to the run path, which hands it to
1506
- // `Agent.getOrCreate({ conversationStorage })`; absent ⇒ the SDK default is chosen lazily.
1507
- ...def.conversationStorage !== void 0 ? {
1508
- conversationStorage: def.conversationStorage
1536
+ // theokit-file-based-config the declared `.theokit/` sources flow to the run path, which
1537
+ // projects them into `Agent.create({ local.settingSources })`; absent ⇒ inline config only.
1538
+ ...def.settingSources !== void 0 ? {
1539
+ settingSources: def.settingSources
1509
1540
  } : {}
1510
1541
  };
1511
1542
  }
@@ -1607,10 +1638,10 @@ function makeBuilder(config) {
1607
1638
  ...config,
1608
1639
  skills: selection
1609
1640
  }), "skills"),
1610
- conversationStorage: /* @__PURE__ */ __name((adapter) => makeBuilder({
1641
+ settingSources: /* @__PURE__ */ __name((sources) => makeBuilder({
1611
1642
  ...config,
1612
- conversationStorage: adapter
1613
- }), "conversationStorage"),
1643
+ settingSources: sources
1644
+ }), "settingSources"),
1614
1645
  use: /* @__PURE__ */ __name((preset) => preset(runtime), "use"),
1615
1646
  build: /* @__PURE__ */ __name(() => defineAgent(config), "build")
1616
1647
  };
@@ -1762,7 +1793,8 @@ __name(appendCheckpointSaved, "appendCheckpointSaved");
1762
1793
  function streamAgentUIMessages(compiled, apiKey, input) {
1763
1794
  const textId = crypto.randomUUID();
1764
1795
  const overrides = {};
1765
- if (input.conversationStorage) overrides.conversationStorage = input.conversationStorage;
1796
+ if (input.cwd !== void 0) overrides.cwd = input.cwd;
1797
+ if (input.baseDir !== void 0) overrides.baseDir = input.baseDir;
1766
1798
  let source;
1767
1799
  if (!input.hitl || input.hitl.gated.size === 0) {
1768
1800
  const events2 = createSdkAgentStream(compiled, compiled.tools, apiKey, overrides)(input.message, input.sessionId);
@@ -2447,11 +2479,11 @@ var AgentRunner = class {
2447
2479
  stripToolDialect: opts.stripToolDialect,
2448
2480
  recoverLeakedToolCalls: opts.recoverLeakedToolCalls,
2449
2481
  cwd: opts.cwd,
2482
+ baseDir: opts.baseDir,
2450
2483
  plugins: opts.plugins,
2451
2484
  providers: opts.providers,
2452
2485
  agents: opts.agents,
2453
2486
  budgetTracker: opts.budgetTracker,
2454
- conversationStorage: opts.conversationStorage,
2455
2487
  sdkTools: opts.sdkTools
2456
2488
  });
2457
2489
  const sessionId = opts.sessionId ?? `runner-${crypto.randomUUID()}`;
@@ -2569,7 +2601,6 @@ async function delegate(SubAgentClass, message, opts = {}) {
2569
2601
  providers: opts.providers,
2570
2602
  agents: opts.agents,
2571
2603
  budgetTracker: opts.budgetTracker,
2572
- conversationStorage: opts.conversationStorage,
2573
2604
  sdkTools: opts.sdkTools
2574
2605
  });
2575
2606
  const sessionId = opts.sessionId ?? `sub-${crypto.randomUUID()}`;
@@ -2986,4 +3017,4 @@ export {
2986
3017
  generateAgentManifest,
2987
3018
  agentsPlugin
2988
3019
  };
2989
- //# sourceMappingURL=chunk-JID4DOB3.js.map
3020
+ //# sourceMappingURL=chunk-5VK63XGX.js.map