@theokit/sdk 3.5.0 → 3.6.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/a2a/index.js CHANGED
@@ -959,10 +959,10 @@ function buildToolPrompt(prompt) {
959
959
  Respond by calling the \`output\` tool with the structured answer that matches the schema.`;
960
960
  }
961
961
  function setupStructuredOutput(schema, maxRetries) {
962
- const z7 = requireZod();
962
+ const z8 = requireZod();
963
963
  const jsonSchema = toJsonSchema(schema, { unrepresentable: "any" });
964
964
  return {
965
- z: z7,
965
+ z: z8,
966
966
  jsonSchema,
967
967
  maxRetries: maxRetries ?? 1,
968
968
  initialUsage: { inputTokens: 0, outputTokens: 0 }
@@ -5752,6 +5752,213 @@ var init_subagents_loader = __esm({
5752
5752
  init_yaml_frontmatter();
5753
5753
  }
5754
5754
  });
5755
+ function loadJsonrepair() {
5756
+ if (cachedJsonrepair === void 0) {
5757
+ const req = createRequire(import.meta.url);
5758
+ cachedJsonrepair = req("jsonrepair").jsonrepair;
5759
+ }
5760
+ return cachedJsonrepair;
5761
+ }
5762
+ function isPlainObject(v) {
5763
+ return v !== null && typeof v === "object" && !Array.isArray(v);
5764
+ }
5765
+ function toFiniteNumber(raw) {
5766
+ if (raw === "") return void 0;
5767
+ const n = Number(raw);
5768
+ return Number.isFinite(n) && String(n) === raw ? n : void 0;
5769
+ }
5770
+ function tryJson(raw, repair) {
5771
+ const t = raw.trimStart();
5772
+ if (!(t.startsWith("{") || t.startsWith("["))) return void 0;
5773
+ try {
5774
+ return JSON.parse(repair ? loadJsonrepair()(t) : t);
5775
+ } catch {
5776
+ return void 0;
5777
+ }
5778
+ }
5779
+ function heuristicCoerce(raw, repairJson) {
5780
+ if (raw === "true") return true;
5781
+ if (raw === "false") return false;
5782
+ if (raw === "null") return null;
5783
+ const n = toFiniteNumber(raw);
5784
+ if (n !== void 0) return n;
5785
+ const json = tryJson(raw, false) ?? (repairJson ? tryJson(raw, true) : void 0);
5786
+ return json === void 0 ? raw : json;
5787
+ }
5788
+ function coerceCandidates(raw, repairJson) {
5789
+ const out = [];
5790
+ if (raw === "true") out.push(true);
5791
+ else if (raw === "false") out.push(false);
5792
+ else if (raw === "null") out.push(null);
5793
+ const n = toFiniteNumber(raw);
5794
+ if (n !== void 0) out.push(n);
5795
+ const json = tryJson(raw, false) ?? (repairJson ? tryJson(raw, true) : void 0);
5796
+ if (json !== void 0) out.push(json);
5797
+ out.push(raw);
5798
+ return out;
5799
+ }
5800
+ function objectShape(schema) {
5801
+ const shape = schema?.shape;
5802
+ return shape !== null && typeof shape === "object" ? shape : void 0;
5803
+ }
5804
+ var cachedJsonrepair;
5805
+ var init_coerce = __esm({
5806
+ "src/sanitize/coerce.ts"() {
5807
+ }
5808
+ });
5809
+
5810
+ // src/sanitize/sanitize-tool-input.ts
5811
+ function applyTrim(key, value, ctx) {
5812
+ const trimmed = value.trim();
5813
+ if (trimmed !== value) ctx.notes.push(`trimmed "${key}"`);
5814
+ return trimmed;
5815
+ }
5816
+ function applyCoerce(key, raw, ctx) {
5817
+ const field = ctx.shape?.[key];
5818
+ let coerced = raw;
5819
+ if (field) {
5820
+ for (const candidate of coerceCandidates(raw, ctx.repairJson)) {
5821
+ if (field.safeParse(candidate).success) {
5822
+ coerced = candidate;
5823
+ break;
5824
+ }
5825
+ }
5826
+ } else {
5827
+ coerced = heuristicCoerce(raw, ctx.repairJson);
5828
+ }
5829
+ if (coerced !== raw) ctx.notes.push(`coerced "${key}"`);
5830
+ return coerced;
5831
+ }
5832
+ function applyRepair(key, value, ctx) {
5833
+ const repaired = tryJson(value, true);
5834
+ if (repaired === void 0) return value;
5835
+ ctx.notes.push(`repaired json "${key}"`);
5836
+ return repaired;
5837
+ }
5838
+ function sanitizeString(key, value, ctx) {
5839
+ let out = ctx.trim ? applyTrim(key, value, ctx) : value;
5840
+ if (ctx.coerce && typeof out === "string") out = applyCoerce(key, out, ctx);
5841
+ if (ctx.repairJson && !ctx.coerce && typeof out === "string") out = applyRepair(key, out, ctx);
5842
+ return out;
5843
+ }
5844
+ function walk(input, ctx, depth) {
5845
+ const out = {};
5846
+ for (const [key, value] of Object.entries(input)) {
5847
+ if (typeof value === "string") out[key] = sanitizeString(key, value, ctx);
5848
+ else if (ctx.deep && depth < ctx.maxDepth && isPlainObject(value))
5849
+ out[key] = walk(value, ctx, depth + 1);
5850
+ else out[key] = value;
5851
+ }
5852
+ return out;
5853
+ }
5854
+ function sanitizeToolInput(input, options) {
5855
+ if (!isPlainObject(input)) return { value: input, changed: false, notes: [] };
5856
+ const ctx = {
5857
+ trim: options?.trim ?? true,
5858
+ coerce: options?.coerce ?? false,
5859
+ repairJson: options?.repairJson ?? false,
5860
+ deep: options?.deep ?? false,
5861
+ maxDepth: options?.maxDepth ?? 8,
5862
+ shape: objectShape(options?.schema),
5863
+ notes: []
5864
+ };
5865
+ const value = walk(input, ctx, 0);
5866
+ return { value, changed: ctx.notes.length > 0, notes: ctx.notes };
5867
+ }
5868
+ var init_sanitize_tool_input = __esm({
5869
+ "src/sanitize/sanitize-tool-input.ts"() {
5870
+ init_coerce();
5871
+ }
5872
+ });
5873
+
5874
+ // src/define-tool.ts
5875
+ async function runValidated(spec, input, ctx) {
5876
+ const raw = spec.sanitize ? sanitizeToolInput(input, {
5877
+ ...spec.sanitize === true ? {} : spec.sanitize,
5878
+ schema: spec.inputSchema
5879
+ }).value : input;
5880
+ const parsed = spec.inputSchema.parse(raw);
5881
+ const out = await spec.handler(parsed, ctx);
5882
+ return spec.outputSchema === void 0 ? out : spec.outputSchema.parse(out);
5883
+ }
5884
+ function serializeOutput(validated) {
5885
+ return typeof validated === "string" ? validated : JSON.stringify(validated);
5886
+ }
5887
+ function shapeModelOutput(spec, validated) {
5888
+ if (spec.toModelOutput !== void 0) return spec.toModelOutput(validated);
5889
+ return serializeOutput(validated);
5890
+ }
5891
+ function defineTool(spec) {
5892
+ const inputSchema = toJsonSchema(spec.inputSchema, {
5893
+ unrepresentable: "any"
5894
+ });
5895
+ const handler = async (input, ctx) => {
5896
+ const validated = await runValidated(spec, input, ctx);
5897
+ return shapeModelOutput(spec, validated);
5898
+ };
5899
+ const tool = { name: spec.name, description: spec.description, inputSchema, handler };
5900
+ if (spec.toModelOutput !== void 0) {
5901
+ const resolver = async (input, ctx) => {
5902
+ const validated = await runValidated(spec, input, ctx);
5903
+ return { model: shapeModelOutput(spec, validated), app: serializeOutput(validated) };
5904
+ };
5905
+ handler[TOOL_SPLIT_RESOLVER] = resolver;
5906
+ }
5907
+ return tool;
5908
+ }
5909
+ var TOOL_SPLIT_RESOLVER, Tool;
5910
+ var init_define_tool = __esm({
5911
+ "src/define-tool.ts"() {
5912
+ init_to_json_schema();
5913
+ init_sanitize_tool_input();
5914
+ TOOL_SPLIT_RESOLVER = /* @__PURE__ */ Symbol("theokit.toolSplitResolver");
5915
+ Tool = class {
5916
+ constructor() {
5917
+ }
5918
+ static create(spec) {
5919
+ return defineTool(spec);
5920
+ }
5921
+ };
5922
+ }
5923
+ });
5924
+ function createThinkTool() {
5925
+ return Tool.create({
5926
+ name: "think",
5927
+ description: "Scratchpad: reason through ONE step before answering. No side effects \u2014 your private reasoning space. Call it repeatedly before the final answer.",
5928
+ inputSchema: z.object({ thought: z.string().min(1, "think: `thought` must be non-empty.") }),
5929
+ handler: ({ thought }) => thought
5930
+ });
5931
+ }
5932
+ function isNativeReasoning(model) {
5933
+ if (model === void 0 || typeof model === "string") return false;
5934
+ const params = model.params;
5935
+ if (params === void 0) return false;
5936
+ return params.some((p) => NATIVE_REASONING_PARAM_IDS.has(p.id));
5937
+ }
5938
+ function warnDoubleReasoningOnce() {
5939
+ if (warned2.has("double-reasoning")) return;
5940
+ warned2.add("double-reasoning");
5941
+ process.stderr.write(
5942
+ "[theokit-sdk] `reasoning: true` skipped \u2014 a native reasoning model is configured (model.params thinking/reasoning); native reasoning wins. Remove one to silence.\n"
5943
+ );
5944
+ }
5945
+ function reasoningActive(reasoning, model) {
5946
+ if (reasoning !== true) return false;
5947
+ if (isNativeReasoning(model)) {
5948
+ warnDoubleReasoningOnce();
5949
+ return false;
5950
+ }
5951
+ return true;
5952
+ }
5953
+ var NATIVE_REASONING_PARAM_IDS, REASONING_PREAMBLE, warned2;
5954
+ var init_native_reasoning = __esm({
5955
+ "src/internal/runtime/reasoning/native-reasoning.ts"() {
5956
+ init_define_tool();
5957
+ NATIVE_REASONING_PARAM_IDS = /* @__PURE__ */ new Set(["thinking", "reasoning", "reasoning_effort"]);
5958
+ REASONING_PREAMBLE = "Think step by step before answering: use the `think` tool to reason through each step, validate your work, then answer. Reason about magnitude before comparing numbers.";
5959
+ warned2 = /* @__PURE__ */ new Set();
5960
+ }
5961
+ });
5755
5962
 
5756
5963
  // src/internal/runtime/skills/skill-frontmatter.ts
5757
5964
  function asString(v) {
@@ -6003,6 +6210,9 @@ async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFa
6003
6210
  if (activeMemorySummary !== void 0 && activeMemorySummary.length > 0) {
6004
6211
  assemblyCtx.activeMemorySummary = activeMemorySummary;
6005
6212
  }
6213
+ if (reasoningActive(inputs.options.reasoning, inputs.model)) {
6214
+ assemblyCtx.reasoning = true;
6215
+ }
6006
6216
  if (inputs.context !== void 0) {
6007
6217
  await inputs.context.applyScope(contextPaths);
6008
6218
  const internal = inputs.context.internalAssemblySnapshot();
@@ -6024,6 +6234,7 @@ async function assembleSystemPromptForSend(inputs, userText, baseSystemPrompt, m
6024
6234
  }
6025
6235
  var init_local_assembly = __esm({
6026
6236
  "src/internal/runtime/system-prompt/local-assembly.ts"() {
6237
+ init_native_reasoning();
6027
6238
  init_skills_manager();
6028
6239
  }
6029
6240
  });
@@ -6159,6 +6370,21 @@ ${lines.join("\n")}
6159
6370
  }
6160
6371
  });
6161
6372
 
6373
+ // src/internal/runtime/system-prompt/sources/reasoning-provider.ts
6374
+ var ReasoningPromptProvider;
6375
+ var init_reasoning_provider = __esm({
6376
+ "src/internal/runtime/system-prompt/sources/reasoning-provider.ts"() {
6377
+ init_native_reasoning();
6378
+ ReasoningPromptProvider = class {
6379
+ id = "reasoning";
6380
+ priority = 1;
6381
+ contribute(ctx) {
6382
+ return Promise.resolve(ctx.reasoning === true ? REASONING_PREAMBLE : void 0);
6383
+ }
6384
+ };
6385
+ }
6386
+ });
6387
+
6162
6388
  // src/internal/runtime/skills/skills-block.ts
6163
6389
  function buildSkillsBlock(skills) {
6164
6390
  if (skills.length === 0) return void 0;
@@ -6201,6 +6427,7 @@ var init_pipeline = __esm({
6201
6427
  init_base_provider();
6202
6428
  init_context_provider();
6203
6429
  init_memory_provider();
6430
+ init_reasoning_provider();
6204
6431
  init_skills_provider();
6205
6432
  SystemPromptPipeline = class _SystemPromptPipeline {
6206
6433
  providers;
@@ -6240,6 +6467,7 @@ var init_pipeline = __esm({
6240
6467
  */
6241
6468
  static default() {
6242
6469
  return new _SystemPromptPipeline([
6470
+ new ReasoningPromptProvider(),
6243
6471
  new ActiveMemoryPromptProvider(),
6244
6472
  new ContextPromptProvider(),
6245
6473
  new SkillsPromptProvider(),
@@ -8566,132 +8794,6 @@ var init_repair_middleware = __esm({
8566
8794
  DECIMAL_RE = /^-?\d+(\.\d+)?$/;
8567
8795
  }
8568
8796
  });
8569
- function loadJsonrepair() {
8570
- if (cachedJsonrepair === void 0) {
8571
- const req = createRequire(import.meta.url);
8572
- cachedJsonrepair = req("jsonrepair").jsonrepair;
8573
- }
8574
- return cachedJsonrepair;
8575
- }
8576
- function isPlainObject(v) {
8577
- return v !== null && typeof v === "object" && !Array.isArray(v);
8578
- }
8579
- function toFiniteNumber(raw) {
8580
- if (raw === "") return void 0;
8581
- const n = Number(raw);
8582
- return Number.isFinite(n) && String(n) === raw ? n : void 0;
8583
- }
8584
- function tryJson(raw, repair) {
8585
- const t = raw.trimStart();
8586
- if (!(t.startsWith("{") || t.startsWith("["))) return void 0;
8587
- try {
8588
- return JSON.parse(repair ? loadJsonrepair()(t) : t);
8589
- } catch {
8590
- return void 0;
8591
- }
8592
- }
8593
- function heuristicCoerce(raw, repairJson) {
8594
- if (raw === "true") return true;
8595
- if (raw === "false") return false;
8596
- if (raw === "null") return null;
8597
- const n = toFiniteNumber(raw);
8598
- if (n !== void 0) return n;
8599
- const json = tryJson(raw, false) ?? (repairJson ? tryJson(raw, true) : void 0);
8600
- return json === void 0 ? raw : json;
8601
- }
8602
- function coerceCandidates(raw, repairJson) {
8603
- const out = [];
8604
- if (raw === "true") out.push(true);
8605
- else if (raw === "false") out.push(false);
8606
- else if (raw === "null") out.push(null);
8607
- const n = toFiniteNumber(raw);
8608
- if (n !== void 0) out.push(n);
8609
- const json = tryJson(raw, false) ?? (repairJson ? tryJson(raw, true) : void 0);
8610
- if (json !== void 0) out.push(json);
8611
- out.push(raw);
8612
- return out;
8613
- }
8614
- function objectShape(schema) {
8615
- const shape = schema?.shape;
8616
- return shape !== null && typeof shape === "object" ? shape : void 0;
8617
- }
8618
- var cachedJsonrepair;
8619
- var init_coerce = __esm({
8620
- "src/sanitize/coerce.ts"() {
8621
- }
8622
- });
8623
-
8624
- // src/sanitize/sanitize-tool-input.ts
8625
- function applyTrim(key, value, ctx) {
8626
- const trimmed = value.trim();
8627
- if (trimmed !== value) ctx.notes.push(`trimmed "${key}"`);
8628
- return trimmed;
8629
- }
8630
- function applyCoerce(key, raw, ctx) {
8631
- const field = ctx.shape?.[key];
8632
- let coerced = raw;
8633
- if (field) {
8634
- for (const candidate of coerceCandidates(raw, ctx.repairJson)) {
8635
- if (field.safeParse(candidate).success) {
8636
- coerced = candidate;
8637
- break;
8638
- }
8639
- }
8640
- } else {
8641
- coerced = heuristicCoerce(raw, ctx.repairJson);
8642
- }
8643
- if (coerced !== raw) ctx.notes.push(`coerced "${key}"`);
8644
- return coerced;
8645
- }
8646
- function applyRepair(key, value, ctx) {
8647
- const repaired = tryJson(value, true);
8648
- if (repaired === void 0) return value;
8649
- ctx.notes.push(`repaired json "${key}"`);
8650
- return repaired;
8651
- }
8652
- function sanitizeString(key, value, ctx) {
8653
- let out = ctx.trim ? applyTrim(key, value, ctx) : value;
8654
- if (ctx.coerce && typeof out === "string") out = applyCoerce(key, out, ctx);
8655
- if (ctx.repairJson && !ctx.coerce && typeof out === "string") out = applyRepair(key, out, ctx);
8656
- return out;
8657
- }
8658
- function walk(input, ctx, depth) {
8659
- const out = {};
8660
- for (const [key, value] of Object.entries(input)) {
8661
- if (typeof value === "string") out[key] = sanitizeString(key, value, ctx);
8662
- else if (ctx.deep && depth < ctx.maxDepth && isPlainObject(value))
8663
- out[key] = walk(value, ctx, depth + 1);
8664
- else out[key] = value;
8665
- }
8666
- return out;
8667
- }
8668
- function sanitizeToolInput(input, options) {
8669
- if (!isPlainObject(input)) return { value: input, changed: false, notes: [] };
8670
- const ctx = {
8671
- trim: options?.trim,
8672
- coerce: options?.coerce ?? false,
8673
- repairJson: options?.repairJson ?? false,
8674
- deep: options?.deep ?? false,
8675
- maxDepth: options?.maxDepth ?? 8,
8676
- shape: objectShape(options?.schema),
8677
- notes: []
8678
- };
8679
- const value = walk(input, ctx, 0);
8680
- return { value, changed: ctx.notes.length > 0, notes: ctx.notes };
8681
- }
8682
- var init_sanitize_tool_input = __esm({
8683
- "src/sanitize/sanitize-tool-input.ts"() {
8684
- init_coerce();
8685
- }
8686
- });
8687
-
8688
- // src/define-tool.ts
8689
- var TOOL_SPLIT_RESOLVER;
8690
- var init_define_tool = __esm({
8691
- "src/define-tool.ts"() {
8692
- TOOL_SPLIT_RESOLVER = /* @__PURE__ */ Symbol("theokit.toolSplitResolver");
8693
- }
8694
- });
8695
8797
 
8696
8798
  // src/tool-error.ts
8697
8799
  function renderToolErrorMessage(content) {
@@ -13129,6 +13231,39 @@ var init_register_plugin_providers = __esm({
13129
13231
  }
13130
13232
  });
13131
13233
 
13234
+ // src/internal/runtime/local-agent/real-local-run-provider.ts
13235
+ function inferProviderFromApiKey(apiKey) {
13236
+ if (apiKey === void 0 || apiKey.length === 0) return void 0;
13237
+ const byPrefix = [
13238
+ { provider: "openrouter", prefix: "sk-or-" },
13239
+ { provider: "anthropic", prefix: "sk-ant-" },
13240
+ { provider: "openai", prefix: "sk-" }
13241
+ ];
13242
+ for (const { provider, prefix } of byPrefix) {
13243
+ if (apiKey.startsWith(prefix) && getProviderProfile(provider) !== void 0) {
13244
+ return provider;
13245
+ }
13246
+ }
13247
+ return void 0;
13248
+ }
13249
+ function detectPrimaryProvider() {
13250
+ if (process.env.ANTHROPIC_API_KEY !== void 0 && process.env.ANTHROPIC_API_KEY.length > 0) {
13251
+ return "anthropic";
13252
+ }
13253
+ if (process.env.OPENAI_API_KEY !== void 0 && process.env.OPENAI_API_KEY.length > 0) {
13254
+ return "openai";
13255
+ }
13256
+ if (process.env.OPENROUTER_API_KEY !== void 0 && process.env.OPENROUTER_API_KEY.length > 0) {
13257
+ return "openrouter";
13258
+ }
13259
+ return "openai";
13260
+ }
13261
+ var init_real_local_run_provider = __esm({
13262
+ "src/internal/runtime/local-agent/real-local-run-provider.ts"() {
13263
+ init_providers();
13264
+ }
13265
+ });
13266
+
13132
13267
  // src/internal/tool-registry/personality-filter.ts
13133
13268
  function applyPersonalityFilter(exposedTools, whitelist, opts) {
13134
13269
  if (whitelist === void 0) return exposedTools;
@@ -13184,36 +13319,49 @@ var init_personality_filter = __esm({
13184
13319
  }
13185
13320
  });
13186
13321
 
13187
- // src/internal/runtime/local-agent/real-local-run-provider.ts
13188
- function inferProviderFromApiKey(apiKey) {
13189
- if (apiKey === void 0 || apiKey.length === 0) return void 0;
13190
- const byPrefix = [
13191
- { provider: "openrouter", prefix: "sk-or-" },
13192
- { provider: "anthropic", prefix: "sk-ant-" },
13193
- { provider: "openai", prefix: "sk-" }
13194
- ];
13195
- for (const { provider, prefix } of byPrefix) {
13196
- if (apiKey.startsWith(prefix) && getProviderProfile(provider) !== void 0) {
13197
- return provider;
13198
- }
13199
- }
13200
- return void 0;
13322
+ // src/internal/runtime/local-agent/real-local-run-tools.ts
13323
+ function declarativeSubagentTools(agents2, parentTools) {
13324
+ if (agents2 === void 0 || Object.keys(agents2).length === 0) return [];
13325
+ return subAgentToolsFromDefinitions(agents2, parentTools);
13201
13326
  }
13202
- function detectPrimaryProvider() {
13203
- if (process.env.ANTHROPIC_API_KEY !== void 0 && process.env.ANTHROPIC_API_KEY.length > 0) {
13204
- return "anthropic";
13205
- }
13206
- if (process.env.OPENAI_API_KEY !== void 0 && process.env.OPENAI_API_KEY.length > 0) {
13207
- return "openai";
13208
- }
13209
- if (process.env.OPENROUTER_API_KEY !== void 0 && process.env.OPENROUTER_API_KEY.length > 0) {
13210
- return "openrouter";
13327
+ function bindParentCredentials(tools, agentOptions) {
13328
+ const parentPlugins = Array.isArray(agentOptions.plugins) ? agentOptions.plugins : void 0;
13329
+ const credentials = {
13330
+ ...agentOptions.apiKey !== void 0 ? { apiKey: agentOptions.apiKey } : {},
13331
+ ...typeof agentOptions.model === "object" ? { model: agentOptions.model } : {},
13332
+ ...parentPlugins !== void 0 ? { plugins: parentPlugins } : {}
13333
+ };
13334
+ for (const tool of tools) inheritSubAgentCredentials(tool, credentials);
13335
+ }
13336
+ function buildCustomToolsInput(agentOptions, sendOptions, pluginManager, personalityToolWhitelist, agentId, personalityName, subagents, effectiveModel) {
13337
+ const baseTools = sendOptions?.tools ?? agentOptions.tools ?? [];
13338
+ const agentsForTools = subagents !== void 0 && Object.keys(subagents).length > 0 ? subagents : agentOptions.agents;
13339
+ const subagentTools = declarativeSubagentTools(agentsForTools, baseTools);
13340
+ const pluginTools = pluginManager?.aggregated.tools ?? [];
13341
+ const reasoningTools = reasoningActive(agentOptions.reasoning, effectiveModel) ? [createThinkTool()] : [];
13342
+ if (baseTools.length === 0 && subagentTools.length === 0 && pluginTools.length === 0 && reasoningTools.length === 0) {
13343
+ return {};
13211
13344
  }
13212
- return "openai";
13345
+ const allTools = [...baseTools, ...subagentTools, ...pluginTools, ...reasoningTools];
13346
+ bindParentCredentials(allTools, agentOptions);
13347
+ const merged = allTools.map((tool) => ({
13348
+ name: tool.name,
13349
+ description: tool.description,
13350
+ inputSchema: tool.inputSchema,
13351
+ handler: tool.handler
13352
+ }));
13353
+ const customTools = applyPersonalityFilter(merged, personalityToolWhitelist, {
13354
+ agentId,
13355
+ personalityName
13356
+ });
13357
+ if (customTools.length === 0 && personalityToolWhitelist === void 0) return {};
13358
+ return { customTools };
13213
13359
  }
13214
- var init_real_local_run_provider = __esm({
13215
- "src/internal/runtime/local-agent/real-local-run-provider.ts"() {
13216
- init_providers();
13360
+ var init_real_local_run_tools = __esm({
13361
+ "src/internal/runtime/local-agent/real-local-run-tools.ts"() {
13362
+ init_subagent();
13363
+ init_personality_filter();
13364
+ init_native_reasoning();
13217
13365
  }
13218
13366
  });
13219
13367
 
@@ -13332,7 +13480,8 @@ function buildLoopInputs(options, runId, userText) {
13332
13480
  options.personalityToolWhitelist,
13333
13481
  options.agentId,
13334
13482
  options.personalityName,
13335
- options.subagents
13483
+ options.subagents,
13484
+ options.model
13336
13485
  ),
13337
13486
  ...options.pluginManager !== void 0 ? { pluginManager: options.pluginManager } : {},
13338
13487
  // D318 — forward SendOptions.signal to the agent loop so streamLlmTurn
@@ -13370,40 +13519,6 @@ function buildLoopInputs(options, runId, userText) {
13370
13519
  ...options.agentOptions.memoryProvider !== void 0 ? { memoryProvider: options.agentOptions.memoryProvider } : {}
13371
13520
  };
13372
13521
  }
13373
- function declarativeSubagentTools(agents2, parentTools) {
13374
- if (agents2 === void 0 || Object.keys(agents2).length === 0) return [];
13375
- return subAgentToolsFromDefinitions(agents2, parentTools);
13376
- }
13377
- function bindParentCredentials(tools, agentOptions) {
13378
- const parentPlugins = Array.isArray(agentOptions.plugins) ? agentOptions.plugins : void 0;
13379
- const credentials = {
13380
- ...agentOptions.apiKey !== void 0 ? { apiKey: agentOptions.apiKey } : {},
13381
- ...typeof agentOptions.model === "object" ? { model: agentOptions.model } : {},
13382
- ...parentPlugins !== void 0 ? { plugins: parentPlugins } : {}
13383
- };
13384
- for (const tool of tools) inheritSubAgentCredentials(tool, credentials);
13385
- }
13386
- function buildCustomToolsInput(agentOptions, sendOptions, pluginManager, personalityToolWhitelist, agentId, personalityName, subagents) {
13387
- const baseTools = sendOptions?.tools ?? agentOptions.tools ?? [];
13388
- const agentsForTools = subagents !== void 0 && Object.keys(subagents).length > 0 ? subagents : agentOptions.agents;
13389
- const subagentTools = declarativeSubagentTools(agentsForTools, baseTools);
13390
- const pluginTools = pluginManager?.aggregated.tools ?? [];
13391
- if (baseTools.length === 0 && subagentTools.length === 0 && pluginTools.length === 0) return {};
13392
- const allTools = [...baseTools, ...subagentTools, ...pluginTools];
13393
- bindParentCredentials(allTools, agentOptions);
13394
- const merged = allTools.map((tool) => ({
13395
- name: tool.name,
13396
- description: tool.description,
13397
- inputSchema: tool.inputSchema,
13398
- handler: tool.handler
13399
- }));
13400
- const customTools = applyPersonalityFilter(merged, personalityToolWhitelist, {
13401
- agentId,
13402
- personalityName
13403
- });
13404
- if (customTools.length === 0 && personalityToolWhitelist === void 0) return {};
13405
- return { customTools };
13406
- }
13407
13522
  function buildMcpMap(options) {
13408
13523
  const map = /* @__PURE__ */ new Map();
13409
13524
  const inline = options.sendOptions.mcpServers ?? options.agentOptions.mcpServers;
@@ -13416,7 +13531,6 @@ function buildMcpMap(options) {
13416
13531
  var pluginProvidersAnnounced, RealLocalRun;
13417
13532
  var init_real_local_run = __esm({
13418
13533
  "src/internal/runtime/local-agent/real-local-run.ts"() {
13419
- init_subagent();
13420
13534
  init_errors();
13421
13535
  init_run_events();
13422
13536
  init_loop();
@@ -13429,11 +13543,11 @@ var init_real_local_run = __esm({
13429
13543
  init_providers();
13430
13544
  init_register_plugin_providers();
13431
13545
  init_tracer();
13432
- init_personality_filter();
13433
13546
  init_async_local_storage();
13434
13547
  init_fixture_run_base();
13435
13548
  init_run_registry();
13436
13549
  init_real_local_run_provider();
13550
+ init_real_local_run_tools();
13437
13551
  pluginProvidersAnnounced = false;
13438
13552
  RealLocalRun = class extends FixtureRunBase {
13439
13553
  buildInputs;