@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/CHANGELOG.md +6 -0
- package/dist/a2a/index.cjs +306 -192
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +306 -192
- package/dist/a2a/index.js.map +1 -1
- package/dist/{cron-D_BnMYIf.d.cts → cron-CZmTuHol.d.cts} +10 -0
- package/dist/{cron-I-6f-0As.d.ts → cron-DdETATFN.d.ts} +10 -0
- package/dist/cron.cjs +471 -357
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +1 -1
- package/dist/cron.d.ts +1 -1
- package/dist/cron.js +471 -357
- package/dist/cron.js.map +1 -1
- package/dist/eval.cjs +471 -357
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +471 -357
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +536 -465
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +536 -465
- package/dist/index.js.map +1 -1
- package/dist/internal/runtime/local-agent/real-local-run-tools.d.ts +19 -0
- package/dist/internal/runtime/reasoning/native-reasoning.d.ts +25 -0
- package/dist/internal/runtime/system-prompt/sources/reasoning-provider.d.ts +1 -0
- package/dist/types/agent.d.ts +10 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2606c98: SE37 — Reasoning ergonomics. Ships `ReasoningTools.create()` (`think`/`analyze` scratchpad tools, from `@theokit/sdk` core, re-exported by `@theokit/sdk-tools`) and a lightweight `AgentOptions.reasoning?: boolean` flag. When `reasoning: true`, the agent gets a chain-of-thought preamble prepended to its system prompt AND the reasoning tools auto-attached, turning a non-reasoning model into a reason→act→observe loop using the SAME model (reuses the existing tool loop; no new runtime). Inert (with a one-time warn) when a native reasoning model is configured (`model.params: [{ id: "thinking" }]`) — native reasoning wins, no double-reasoning. Default off; byte-identical behaviour when unset. Validated REAL on OpenRouter: `reasoning: true` drove the `think` tool and answered the "9.11 vs 9.9" trap correctly (9.9).
|
|
8
|
+
|
|
3
9
|
## 3.5.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/a2a/index.cjs
CHANGED
|
@@ -962,10 +962,10 @@ function buildToolPrompt(prompt) {
|
|
|
962
962
|
Respond by calling the \`output\` tool with the structured answer that matches the schema.`;
|
|
963
963
|
}
|
|
964
964
|
function setupStructuredOutput(schema, maxRetries) {
|
|
965
|
-
const
|
|
965
|
+
const z8 = requireZod();
|
|
966
966
|
const jsonSchema = toJsonSchema(schema, { unrepresentable: "any" });
|
|
967
967
|
return {
|
|
968
|
-
z:
|
|
968
|
+
z: z8,
|
|
969
969
|
jsonSchema,
|
|
970
970
|
maxRetries: maxRetries ?? 1,
|
|
971
971
|
initialUsage: { inputTokens: 0, outputTokens: 0 }
|
|
@@ -5755,6 +5755,213 @@ var init_subagents_loader = __esm({
|
|
|
5755
5755
|
init_yaml_frontmatter();
|
|
5756
5756
|
}
|
|
5757
5757
|
});
|
|
5758
|
+
function loadJsonrepair() {
|
|
5759
|
+
if (cachedJsonrepair === void 0) {
|
|
5760
|
+
const req = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
5761
|
+
cachedJsonrepair = req("jsonrepair").jsonrepair;
|
|
5762
|
+
}
|
|
5763
|
+
return cachedJsonrepair;
|
|
5764
|
+
}
|
|
5765
|
+
function isPlainObject(v) {
|
|
5766
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
5767
|
+
}
|
|
5768
|
+
function toFiniteNumber(raw) {
|
|
5769
|
+
if (raw === "") return void 0;
|
|
5770
|
+
const n = Number(raw);
|
|
5771
|
+
return Number.isFinite(n) && String(n) === raw ? n : void 0;
|
|
5772
|
+
}
|
|
5773
|
+
function tryJson(raw, repair) {
|
|
5774
|
+
const t = raw.trimStart();
|
|
5775
|
+
if (!(t.startsWith("{") || t.startsWith("["))) return void 0;
|
|
5776
|
+
try {
|
|
5777
|
+
return JSON.parse(repair ? loadJsonrepair()(t) : t);
|
|
5778
|
+
} catch {
|
|
5779
|
+
return void 0;
|
|
5780
|
+
}
|
|
5781
|
+
}
|
|
5782
|
+
function heuristicCoerce(raw, repairJson) {
|
|
5783
|
+
if (raw === "true") return true;
|
|
5784
|
+
if (raw === "false") return false;
|
|
5785
|
+
if (raw === "null") return null;
|
|
5786
|
+
const n = toFiniteNumber(raw);
|
|
5787
|
+
if (n !== void 0) return n;
|
|
5788
|
+
const json = tryJson(raw, false) ?? (repairJson ? tryJson(raw, true) : void 0);
|
|
5789
|
+
return json === void 0 ? raw : json;
|
|
5790
|
+
}
|
|
5791
|
+
function coerceCandidates(raw, repairJson) {
|
|
5792
|
+
const out = [];
|
|
5793
|
+
if (raw === "true") out.push(true);
|
|
5794
|
+
else if (raw === "false") out.push(false);
|
|
5795
|
+
else if (raw === "null") out.push(null);
|
|
5796
|
+
const n = toFiniteNumber(raw);
|
|
5797
|
+
if (n !== void 0) out.push(n);
|
|
5798
|
+
const json = tryJson(raw, false) ?? (repairJson ? tryJson(raw, true) : void 0);
|
|
5799
|
+
if (json !== void 0) out.push(json);
|
|
5800
|
+
out.push(raw);
|
|
5801
|
+
return out;
|
|
5802
|
+
}
|
|
5803
|
+
function objectShape(schema) {
|
|
5804
|
+
const shape = schema?.shape;
|
|
5805
|
+
return shape !== null && typeof shape === "object" ? shape : void 0;
|
|
5806
|
+
}
|
|
5807
|
+
var cachedJsonrepair;
|
|
5808
|
+
var init_coerce = __esm({
|
|
5809
|
+
"src/sanitize/coerce.ts"() {
|
|
5810
|
+
}
|
|
5811
|
+
});
|
|
5812
|
+
|
|
5813
|
+
// src/sanitize/sanitize-tool-input.ts
|
|
5814
|
+
function applyTrim(key, value, ctx) {
|
|
5815
|
+
const trimmed = value.trim();
|
|
5816
|
+
if (trimmed !== value) ctx.notes.push(`trimmed "${key}"`);
|
|
5817
|
+
return trimmed;
|
|
5818
|
+
}
|
|
5819
|
+
function applyCoerce(key, raw, ctx) {
|
|
5820
|
+
const field = ctx.shape?.[key];
|
|
5821
|
+
let coerced = raw;
|
|
5822
|
+
if (field) {
|
|
5823
|
+
for (const candidate of coerceCandidates(raw, ctx.repairJson)) {
|
|
5824
|
+
if (field.safeParse(candidate).success) {
|
|
5825
|
+
coerced = candidate;
|
|
5826
|
+
break;
|
|
5827
|
+
}
|
|
5828
|
+
}
|
|
5829
|
+
} else {
|
|
5830
|
+
coerced = heuristicCoerce(raw, ctx.repairJson);
|
|
5831
|
+
}
|
|
5832
|
+
if (coerced !== raw) ctx.notes.push(`coerced "${key}"`);
|
|
5833
|
+
return coerced;
|
|
5834
|
+
}
|
|
5835
|
+
function applyRepair(key, value, ctx) {
|
|
5836
|
+
const repaired = tryJson(value, true);
|
|
5837
|
+
if (repaired === void 0) return value;
|
|
5838
|
+
ctx.notes.push(`repaired json "${key}"`);
|
|
5839
|
+
return repaired;
|
|
5840
|
+
}
|
|
5841
|
+
function sanitizeString(key, value, ctx) {
|
|
5842
|
+
let out = ctx.trim ? applyTrim(key, value, ctx) : value;
|
|
5843
|
+
if (ctx.coerce && typeof out === "string") out = applyCoerce(key, out, ctx);
|
|
5844
|
+
if (ctx.repairJson && !ctx.coerce && typeof out === "string") out = applyRepair(key, out, ctx);
|
|
5845
|
+
return out;
|
|
5846
|
+
}
|
|
5847
|
+
function walk(input, ctx, depth) {
|
|
5848
|
+
const out = {};
|
|
5849
|
+
for (const [key, value] of Object.entries(input)) {
|
|
5850
|
+
if (typeof value === "string") out[key] = sanitizeString(key, value, ctx);
|
|
5851
|
+
else if (ctx.deep && depth < ctx.maxDepth && isPlainObject(value))
|
|
5852
|
+
out[key] = walk(value, ctx, depth + 1);
|
|
5853
|
+
else out[key] = value;
|
|
5854
|
+
}
|
|
5855
|
+
return out;
|
|
5856
|
+
}
|
|
5857
|
+
function sanitizeToolInput(input, options) {
|
|
5858
|
+
if (!isPlainObject(input)) return { value: input, changed: false, notes: [] };
|
|
5859
|
+
const ctx = {
|
|
5860
|
+
trim: options?.trim ?? true,
|
|
5861
|
+
coerce: options?.coerce ?? false,
|
|
5862
|
+
repairJson: options?.repairJson ?? false,
|
|
5863
|
+
deep: options?.deep ?? false,
|
|
5864
|
+
maxDepth: options?.maxDepth ?? 8,
|
|
5865
|
+
shape: objectShape(options?.schema),
|
|
5866
|
+
notes: []
|
|
5867
|
+
};
|
|
5868
|
+
const value = walk(input, ctx, 0);
|
|
5869
|
+
return { value, changed: ctx.notes.length > 0, notes: ctx.notes };
|
|
5870
|
+
}
|
|
5871
|
+
var init_sanitize_tool_input = __esm({
|
|
5872
|
+
"src/sanitize/sanitize-tool-input.ts"() {
|
|
5873
|
+
init_coerce();
|
|
5874
|
+
}
|
|
5875
|
+
});
|
|
5876
|
+
|
|
5877
|
+
// src/define-tool.ts
|
|
5878
|
+
async function runValidated(spec, input, ctx) {
|
|
5879
|
+
const raw = spec.sanitize ? sanitizeToolInput(input, {
|
|
5880
|
+
...spec.sanitize === true ? {} : spec.sanitize,
|
|
5881
|
+
schema: spec.inputSchema
|
|
5882
|
+
}).value : input;
|
|
5883
|
+
const parsed = spec.inputSchema.parse(raw);
|
|
5884
|
+
const out = await spec.handler(parsed, ctx);
|
|
5885
|
+
return spec.outputSchema === void 0 ? out : spec.outputSchema.parse(out);
|
|
5886
|
+
}
|
|
5887
|
+
function serializeOutput(validated) {
|
|
5888
|
+
return typeof validated === "string" ? validated : JSON.stringify(validated);
|
|
5889
|
+
}
|
|
5890
|
+
function shapeModelOutput(spec, validated) {
|
|
5891
|
+
if (spec.toModelOutput !== void 0) return spec.toModelOutput(validated);
|
|
5892
|
+
return serializeOutput(validated);
|
|
5893
|
+
}
|
|
5894
|
+
function defineTool(spec) {
|
|
5895
|
+
const inputSchema = toJsonSchema(spec.inputSchema, {
|
|
5896
|
+
unrepresentable: "any"
|
|
5897
|
+
});
|
|
5898
|
+
const handler = async (input, ctx) => {
|
|
5899
|
+
const validated = await runValidated(spec, input, ctx);
|
|
5900
|
+
return shapeModelOutput(spec, validated);
|
|
5901
|
+
};
|
|
5902
|
+
const tool = { name: spec.name, description: spec.description, inputSchema, handler };
|
|
5903
|
+
if (spec.toModelOutput !== void 0) {
|
|
5904
|
+
const resolver = async (input, ctx) => {
|
|
5905
|
+
const validated = await runValidated(spec, input, ctx);
|
|
5906
|
+
return { model: shapeModelOutput(spec, validated), app: serializeOutput(validated) };
|
|
5907
|
+
};
|
|
5908
|
+
handler[TOOL_SPLIT_RESOLVER] = resolver;
|
|
5909
|
+
}
|
|
5910
|
+
return tool;
|
|
5911
|
+
}
|
|
5912
|
+
var TOOL_SPLIT_RESOLVER, Tool;
|
|
5913
|
+
var init_define_tool = __esm({
|
|
5914
|
+
"src/define-tool.ts"() {
|
|
5915
|
+
init_to_json_schema();
|
|
5916
|
+
init_sanitize_tool_input();
|
|
5917
|
+
TOOL_SPLIT_RESOLVER = /* @__PURE__ */ Symbol("theokit.toolSplitResolver");
|
|
5918
|
+
Tool = class {
|
|
5919
|
+
constructor() {
|
|
5920
|
+
}
|
|
5921
|
+
static create(spec) {
|
|
5922
|
+
return defineTool(spec);
|
|
5923
|
+
}
|
|
5924
|
+
};
|
|
5925
|
+
}
|
|
5926
|
+
});
|
|
5927
|
+
function createThinkTool() {
|
|
5928
|
+
return Tool.create({
|
|
5929
|
+
name: "think",
|
|
5930
|
+
description: "Scratchpad: reason through ONE step before answering. No side effects \u2014 your private reasoning space. Call it repeatedly before the final answer.",
|
|
5931
|
+
inputSchema: zod.z.object({ thought: zod.z.string().min(1, "think: `thought` must be non-empty.") }),
|
|
5932
|
+
handler: ({ thought }) => thought
|
|
5933
|
+
});
|
|
5934
|
+
}
|
|
5935
|
+
function isNativeReasoning(model) {
|
|
5936
|
+
if (model === void 0 || typeof model === "string") return false;
|
|
5937
|
+
const params = model.params;
|
|
5938
|
+
if (params === void 0) return false;
|
|
5939
|
+
return params.some((p) => NATIVE_REASONING_PARAM_IDS.has(p.id));
|
|
5940
|
+
}
|
|
5941
|
+
function warnDoubleReasoningOnce() {
|
|
5942
|
+
if (warned2.has("double-reasoning")) return;
|
|
5943
|
+
warned2.add("double-reasoning");
|
|
5944
|
+
process.stderr.write(
|
|
5945
|
+
"[theokit-sdk] `reasoning: true` skipped \u2014 a native reasoning model is configured (model.params thinking/reasoning); native reasoning wins. Remove one to silence.\n"
|
|
5946
|
+
);
|
|
5947
|
+
}
|
|
5948
|
+
function reasoningActive(reasoning, model) {
|
|
5949
|
+
if (reasoning !== true) return false;
|
|
5950
|
+
if (isNativeReasoning(model)) {
|
|
5951
|
+
warnDoubleReasoningOnce();
|
|
5952
|
+
return false;
|
|
5953
|
+
}
|
|
5954
|
+
return true;
|
|
5955
|
+
}
|
|
5956
|
+
var NATIVE_REASONING_PARAM_IDS, REASONING_PREAMBLE, warned2;
|
|
5957
|
+
var init_native_reasoning = __esm({
|
|
5958
|
+
"src/internal/runtime/reasoning/native-reasoning.ts"() {
|
|
5959
|
+
init_define_tool();
|
|
5960
|
+
NATIVE_REASONING_PARAM_IDS = /* @__PURE__ */ new Set(["thinking", "reasoning", "reasoning_effort"]);
|
|
5961
|
+
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.";
|
|
5962
|
+
warned2 = /* @__PURE__ */ new Set();
|
|
5963
|
+
}
|
|
5964
|
+
});
|
|
5758
5965
|
|
|
5759
5966
|
// src/internal/runtime/skills/skill-frontmatter.ts
|
|
5760
5967
|
function asString(v) {
|
|
@@ -6006,6 +6213,9 @@ async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFa
|
|
|
6006
6213
|
if (activeMemorySummary !== void 0 && activeMemorySummary.length > 0) {
|
|
6007
6214
|
assemblyCtx.activeMemorySummary = activeMemorySummary;
|
|
6008
6215
|
}
|
|
6216
|
+
if (reasoningActive(inputs.options.reasoning, inputs.model)) {
|
|
6217
|
+
assemblyCtx.reasoning = true;
|
|
6218
|
+
}
|
|
6009
6219
|
if (inputs.context !== void 0) {
|
|
6010
6220
|
await inputs.context.applyScope(contextPaths);
|
|
6011
6221
|
const internal = inputs.context.internalAssemblySnapshot();
|
|
@@ -6027,6 +6237,7 @@ async function assembleSystemPromptForSend(inputs, userText, baseSystemPrompt, m
|
|
|
6027
6237
|
}
|
|
6028
6238
|
var init_local_assembly = __esm({
|
|
6029
6239
|
"src/internal/runtime/system-prompt/local-assembly.ts"() {
|
|
6240
|
+
init_native_reasoning();
|
|
6030
6241
|
init_skills_manager();
|
|
6031
6242
|
}
|
|
6032
6243
|
});
|
|
@@ -6162,6 +6373,21 @@ ${lines.join("\n")}
|
|
|
6162
6373
|
}
|
|
6163
6374
|
});
|
|
6164
6375
|
|
|
6376
|
+
// src/internal/runtime/system-prompt/sources/reasoning-provider.ts
|
|
6377
|
+
var ReasoningPromptProvider;
|
|
6378
|
+
var init_reasoning_provider = __esm({
|
|
6379
|
+
"src/internal/runtime/system-prompt/sources/reasoning-provider.ts"() {
|
|
6380
|
+
init_native_reasoning();
|
|
6381
|
+
ReasoningPromptProvider = class {
|
|
6382
|
+
id = "reasoning";
|
|
6383
|
+
priority = 1;
|
|
6384
|
+
contribute(ctx) {
|
|
6385
|
+
return Promise.resolve(ctx.reasoning === true ? REASONING_PREAMBLE : void 0);
|
|
6386
|
+
}
|
|
6387
|
+
};
|
|
6388
|
+
}
|
|
6389
|
+
});
|
|
6390
|
+
|
|
6165
6391
|
// src/internal/runtime/skills/skills-block.ts
|
|
6166
6392
|
function buildSkillsBlock(skills) {
|
|
6167
6393
|
if (skills.length === 0) return void 0;
|
|
@@ -6204,6 +6430,7 @@ var init_pipeline = __esm({
|
|
|
6204
6430
|
init_base_provider();
|
|
6205
6431
|
init_context_provider();
|
|
6206
6432
|
init_memory_provider();
|
|
6433
|
+
init_reasoning_provider();
|
|
6207
6434
|
init_skills_provider();
|
|
6208
6435
|
SystemPromptPipeline = class _SystemPromptPipeline {
|
|
6209
6436
|
providers;
|
|
@@ -6243,6 +6470,7 @@ var init_pipeline = __esm({
|
|
|
6243
6470
|
*/
|
|
6244
6471
|
static default() {
|
|
6245
6472
|
return new _SystemPromptPipeline([
|
|
6473
|
+
new ReasoningPromptProvider(),
|
|
6246
6474
|
new ActiveMemoryPromptProvider(),
|
|
6247
6475
|
new ContextPromptProvider(),
|
|
6248
6476
|
new SkillsPromptProvider(),
|
|
@@ -8569,132 +8797,6 @@ var init_repair_middleware = __esm({
|
|
|
8569
8797
|
DECIMAL_RE = /^-?\d+(\.\d+)?$/;
|
|
8570
8798
|
}
|
|
8571
8799
|
});
|
|
8572
|
-
function loadJsonrepair() {
|
|
8573
|
-
if (cachedJsonrepair === void 0) {
|
|
8574
|
-
const req = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
8575
|
-
cachedJsonrepair = req("jsonrepair").jsonrepair;
|
|
8576
|
-
}
|
|
8577
|
-
return cachedJsonrepair;
|
|
8578
|
-
}
|
|
8579
|
-
function isPlainObject(v) {
|
|
8580
|
-
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
8581
|
-
}
|
|
8582
|
-
function toFiniteNumber(raw) {
|
|
8583
|
-
if (raw === "") return void 0;
|
|
8584
|
-
const n = Number(raw);
|
|
8585
|
-
return Number.isFinite(n) && String(n) === raw ? n : void 0;
|
|
8586
|
-
}
|
|
8587
|
-
function tryJson(raw, repair) {
|
|
8588
|
-
const t = raw.trimStart();
|
|
8589
|
-
if (!(t.startsWith("{") || t.startsWith("["))) return void 0;
|
|
8590
|
-
try {
|
|
8591
|
-
return JSON.parse(repair ? loadJsonrepair()(t) : t);
|
|
8592
|
-
} catch {
|
|
8593
|
-
return void 0;
|
|
8594
|
-
}
|
|
8595
|
-
}
|
|
8596
|
-
function heuristicCoerce(raw, repairJson) {
|
|
8597
|
-
if (raw === "true") return true;
|
|
8598
|
-
if (raw === "false") return false;
|
|
8599
|
-
if (raw === "null") return null;
|
|
8600
|
-
const n = toFiniteNumber(raw);
|
|
8601
|
-
if (n !== void 0) return n;
|
|
8602
|
-
const json = tryJson(raw, false) ?? (repairJson ? tryJson(raw, true) : void 0);
|
|
8603
|
-
return json === void 0 ? raw : json;
|
|
8604
|
-
}
|
|
8605
|
-
function coerceCandidates(raw, repairJson) {
|
|
8606
|
-
const out = [];
|
|
8607
|
-
if (raw === "true") out.push(true);
|
|
8608
|
-
else if (raw === "false") out.push(false);
|
|
8609
|
-
else if (raw === "null") out.push(null);
|
|
8610
|
-
const n = toFiniteNumber(raw);
|
|
8611
|
-
if (n !== void 0) out.push(n);
|
|
8612
|
-
const json = tryJson(raw, false) ?? (repairJson ? tryJson(raw, true) : void 0);
|
|
8613
|
-
if (json !== void 0) out.push(json);
|
|
8614
|
-
out.push(raw);
|
|
8615
|
-
return out;
|
|
8616
|
-
}
|
|
8617
|
-
function objectShape(schema) {
|
|
8618
|
-
const shape = schema?.shape;
|
|
8619
|
-
return shape !== null && typeof shape === "object" ? shape : void 0;
|
|
8620
|
-
}
|
|
8621
|
-
var cachedJsonrepair;
|
|
8622
|
-
var init_coerce = __esm({
|
|
8623
|
-
"src/sanitize/coerce.ts"() {
|
|
8624
|
-
}
|
|
8625
|
-
});
|
|
8626
|
-
|
|
8627
|
-
// src/sanitize/sanitize-tool-input.ts
|
|
8628
|
-
function applyTrim(key, value, ctx) {
|
|
8629
|
-
const trimmed = value.trim();
|
|
8630
|
-
if (trimmed !== value) ctx.notes.push(`trimmed "${key}"`);
|
|
8631
|
-
return trimmed;
|
|
8632
|
-
}
|
|
8633
|
-
function applyCoerce(key, raw, ctx) {
|
|
8634
|
-
const field = ctx.shape?.[key];
|
|
8635
|
-
let coerced = raw;
|
|
8636
|
-
if (field) {
|
|
8637
|
-
for (const candidate of coerceCandidates(raw, ctx.repairJson)) {
|
|
8638
|
-
if (field.safeParse(candidate).success) {
|
|
8639
|
-
coerced = candidate;
|
|
8640
|
-
break;
|
|
8641
|
-
}
|
|
8642
|
-
}
|
|
8643
|
-
} else {
|
|
8644
|
-
coerced = heuristicCoerce(raw, ctx.repairJson);
|
|
8645
|
-
}
|
|
8646
|
-
if (coerced !== raw) ctx.notes.push(`coerced "${key}"`);
|
|
8647
|
-
return coerced;
|
|
8648
|
-
}
|
|
8649
|
-
function applyRepair(key, value, ctx) {
|
|
8650
|
-
const repaired = tryJson(value, true);
|
|
8651
|
-
if (repaired === void 0) return value;
|
|
8652
|
-
ctx.notes.push(`repaired json "${key}"`);
|
|
8653
|
-
return repaired;
|
|
8654
|
-
}
|
|
8655
|
-
function sanitizeString(key, value, ctx) {
|
|
8656
|
-
let out = ctx.trim ? applyTrim(key, value, ctx) : value;
|
|
8657
|
-
if (ctx.coerce && typeof out === "string") out = applyCoerce(key, out, ctx);
|
|
8658
|
-
if (ctx.repairJson && !ctx.coerce && typeof out === "string") out = applyRepair(key, out, ctx);
|
|
8659
|
-
return out;
|
|
8660
|
-
}
|
|
8661
|
-
function walk(input, ctx, depth) {
|
|
8662
|
-
const out = {};
|
|
8663
|
-
for (const [key, value] of Object.entries(input)) {
|
|
8664
|
-
if (typeof value === "string") out[key] = sanitizeString(key, value, ctx);
|
|
8665
|
-
else if (ctx.deep && depth < ctx.maxDepth && isPlainObject(value))
|
|
8666
|
-
out[key] = walk(value, ctx, depth + 1);
|
|
8667
|
-
else out[key] = value;
|
|
8668
|
-
}
|
|
8669
|
-
return out;
|
|
8670
|
-
}
|
|
8671
|
-
function sanitizeToolInput(input, options) {
|
|
8672
|
-
if (!isPlainObject(input)) return { value: input, changed: false, notes: [] };
|
|
8673
|
-
const ctx = {
|
|
8674
|
-
trim: options?.trim,
|
|
8675
|
-
coerce: options?.coerce ?? false,
|
|
8676
|
-
repairJson: options?.repairJson ?? false,
|
|
8677
|
-
deep: options?.deep ?? false,
|
|
8678
|
-
maxDepth: options?.maxDepth ?? 8,
|
|
8679
|
-
shape: objectShape(options?.schema),
|
|
8680
|
-
notes: []
|
|
8681
|
-
};
|
|
8682
|
-
const value = walk(input, ctx, 0);
|
|
8683
|
-
return { value, changed: ctx.notes.length > 0, notes: ctx.notes };
|
|
8684
|
-
}
|
|
8685
|
-
var init_sanitize_tool_input = __esm({
|
|
8686
|
-
"src/sanitize/sanitize-tool-input.ts"() {
|
|
8687
|
-
init_coerce();
|
|
8688
|
-
}
|
|
8689
|
-
});
|
|
8690
|
-
|
|
8691
|
-
// src/define-tool.ts
|
|
8692
|
-
var TOOL_SPLIT_RESOLVER;
|
|
8693
|
-
var init_define_tool = __esm({
|
|
8694
|
-
"src/define-tool.ts"() {
|
|
8695
|
-
TOOL_SPLIT_RESOLVER = /* @__PURE__ */ Symbol("theokit.toolSplitResolver");
|
|
8696
|
-
}
|
|
8697
|
-
});
|
|
8698
8800
|
|
|
8699
8801
|
// src/tool-error.ts
|
|
8700
8802
|
function renderToolErrorMessage(content) {
|
|
@@ -13132,6 +13234,39 @@ var init_register_plugin_providers = __esm({
|
|
|
13132
13234
|
}
|
|
13133
13235
|
});
|
|
13134
13236
|
|
|
13237
|
+
// src/internal/runtime/local-agent/real-local-run-provider.ts
|
|
13238
|
+
function inferProviderFromApiKey(apiKey) {
|
|
13239
|
+
if (apiKey === void 0 || apiKey.length === 0) return void 0;
|
|
13240
|
+
const byPrefix = [
|
|
13241
|
+
{ provider: "openrouter", prefix: "sk-or-" },
|
|
13242
|
+
{ provider: "anthropic", prefix: "sk-ant-" },
|
|
13243
|
+
{ provider: "openai", prefix: "sk-" }
|
|
13244
|
+
];
|
|
13245
|
+
for (const { provider, prefix } of byPrefix) {
|
|
13246
|
+
if (apiKey.startsWith(prefix) && getProviderProfile(provider) !== void 0) {
|
|
13247
|
+
return provider;
|
|
13248
|
+
}
|
|
13249
|
+
}
|
|
13250
|
+
return void 0;
|
|
13251
|
+
}
|
|
13252
|
+
function detectPrimaryProvider() {
|
|
13253
|
+
if (process.env.ANTHROPIC_API_KEY !== void 0 && process.env.ANTHROPIC_API_KEY.length > 0) {
|
|
13254
|
+
return "anthropic";
|
|
13255
|
+
}
|
|
13256
|
+
if (process.env.OPENAI_API_KEY !== void 0 && process.env.OPENAI_API_KEY.length > 0) {
|
|
13257
|
+
return "openai";
|
|
13258
|
+
}
|
|
13259
|
+
if (process.env.OPENROUTER_API_KEY !== void 0 && process.env.OPENROUTER_API_KEY.length > 0) {
|
|
13260
|
+
return "openrouter";
|
|
13261
|
+
}
|
|
13262
|
+
return "openai";
|
|
13263
|
+
}
|
|
13264
|
+
var init_real_local_run_provider = __esm({
|
|
13265
|
+
"src/internal/runtime/local-agent/real-local-run-provider.ts"() {
|
|
13266
|
+
init_providers();
|
|
13267
|
+
}
|
|
13268
|
+
});
|
|
13269
|
+
|
|
13135
13270
|
// src/internal/tool-registry/personality-filter.ts
|
|
13136
13271
|
function applyPersonalityFilter(exposedTools, whitelist, opts) {
|
|
13137
13272
|
if (whitelist === void 0) return exposedTools;
|
|
@@ -13187,36 +13322,49 @@ var init_personality_filter = __esm({
|
|
|
13187
13322
|
}
|
|
13188
13323
|
});
|
|
13189
13324
|
|
|
13190
|
-
// src/internal/runtime/local-agent/real-local-run-
|
|
13191
|
-
function
|
|
13192
|
-
if (
|
|
13193
|
-
|
|
13194
|
-
{ provider: "openrouter", prefix: "sk-or-" },
|
|
13195
|
-
{ provider: "anthropic", prefix: "sk-ant-" },
|
|
13196
|
-
{ provider: "openai", prefix: "sk-" }
|
|
13197
|
-
];
|
|
13198
|
-
for (const { provider, prefix } of byPrefix) {
|
|
13199
|
-
if (apiKey.startsWith(prefix) && getProviderProfile(provider) !== void 0) {
|
|
13200
|
-
return provider;
|
|
13201
|
-
}
|
|
13202
|
-
}
|
|
13203
|
-
return void 0;
|
|
13325
|
+
// src/internal/runtime/local-agent/real-local-run-tools.ts
|
|
13326
|
+
function declarativeSubagentTools(agents2, parentTools) {
|
|
13327
|
+
if (agents2 === void 0 || Object.keys(agents2).length === 0) return [];
|
|
13328
|
+
return subAgentToolsFromDefinitions(agents2, parentTools);
|
|
13204
13329
|
}
|
|
13205
|
-
function
|
|
13206
|
-
|
|
13207
|
-
|
|
13208
|
-
|
|
13209
|
-
|
|
13210
|
-
|
|
13211
|
-
}
|
|
13212
|
-
|
|
13213
|
-
|
|
13330
|
+
function bindParentCredentials(tools, agentOptions) {
|
|
13331
|
+
const parentPlugins = Array.isArray(agentOptions.plugins) ? agentOptions.plugins : void 0;
|
|
13332
|
+
const credentials = {
|
|
13333
|
+
...agentOptions.apiKey !== void 0 ? { apiKey: agentOptions.apiKey } : {},
|
|
13334
|
+
...typeof agentOptions.model === "object" ? { model: agentOptions.model } : {},
|
|
13335
|
+
...parentPlugins !== void 0 ? { plugins: parentPlugins } : {}
|
|
13336
|
+
};
|
|
13337
|
+
for (const tool of tools) inheritSubAgentCredentials(tool, credentials);
|
|
13338
|
+
}
|
|
13339
|
+
function buildCustomToolsInput(agentOptions, sendOptions, pluginManager, personalityToolWhitelist, agentId, personalityName, subagents, effectiveModel) {
|
|
13340
|
+
const baseTools = sendOptions?.tools ?? agentOptions.tools ?? [];
|
|
13341
|
+
const agentsForTools = subagents !== void 0 && Object.keys(subagents).length > 0 ? subagents : agentOptions.agents;
|
|
13342
|
+
const subagentTools = declarativeSubagentTools(agentsForTools, baseTools);
|
|
13343
|
+
const pluginTools = pluginManager?.aggregated.tools ?? [];
|
|
13344
|
+
const reasoningTools = reasoningActive(agentOptions.reasoning, effectiveModel) ? [createThinkTool()] : [];
|
|
13345
|
+
if (baseTools.length === 0 && subagentTools.length === 0 && pluginTools.length === 0 && reasoningTools.length === 0) {
|
|
13346
|
+
return {};
|
|
13214
13347
|
}
|
|
13215
|
-
|
|
13348
|
+
const allTools = [...baseTools, ...subagentTools, ...pluginTools, ...reasoningTools];
|
|
13349
|
+
bindParentCredentials(allTools, agentOptions);
|
|
13350
|
+
const merged = allTools.map((tool) => ({
|
|
13351
|
+
name: tool.name,
|
|
13352
|
+
description: tool.description,
|
|
13353
|
+
inputSchema: tool.inputSchema,
|
|
13354
|
+
handler: tool.handler
|
|
13355
|
+
}));
|
|
13356
|
+
const customTools = applyPersonalityFilter(merged, personalityToolWhitelist, {
|
|
13357
|
+
agentId,
|
|
13358
|
+
personalityName
|
|
13359
|
+
});
|
|
13360
|
+
if (customTools.length === 0 && personalityToolWhitelist === void 0) return {};
|
|
13361
|
+
return { customTools };
|
|
13216
13362
|
}
|
|
13217
|
-
var
|
|
13218
|
-
"src/internal/runtime/local-agent/real-local-run-
|
|
13219
|
-
|
|
13363
|
+
var init_real_local_run_tools = __esm({
|
|
13364
|
+
"src/internal/runtime/local-agent/real-local-run-tools.ts"() {
|
|
13365
|
+
init_subagent();
|
|
13366
|
+
init_personality_filter();
|
|
13367
|
+
init_native_reasoning();
|
|
13220
13368
|
}
|
|
13221
13369
|
});
|
|
13222
13370
|
|
|
@@ -13335,7 +13483,8 @@ function buildLoopInputs(options, runId, userText) {
|
|
|
13335
13483
|
options.personalityToolWhitelist,
|
|
13336
13484
|
options.agentId,
|
|
13337
13485
|
options.personalityName,
|
|
13338
|
-
options.subagents
|
|
13486
|
+
options.subagents,
|
|
13487
|
+
options.model
|
|
13339
13488
|
),
|
|
13340
13489
|
...options.pluginManager !== void 0 ? { pluginManager: options.pluginManager } : {},
|
|
13341
13490
|
// D318 — forward SendOptions.signal to the agent loop so streamLlmTurn
|
|
@@ -13373,40 +13522,6 @@ function buildLoopInputs(options, runId, userText) {
|
|
|
13373
13522
|
...options.agentOptions.memoryProvider !== void 0 ? { memoryProvider: options.agentOptions.memoryProvider } : {}
|
|
13374
13523
|
};
|
|
13375
13524
|
}
|
|
13376
|
-
function declarativeSubagentTools(agents2, parentTools) {
|
|
13377
|
-
if (agents2 === void 0 || Object.keys(agents2).length === 0) return [];
|
|
13378
|
-
return subAgentToolsFromDefinitions(agents2, parentTools);
|
|
13379
|
-
}
|
|
13380
|
-
function bindParentCredentials(tools, agentOptions) {
|
|
13381
|
-
const parentPlugins = Array.isArray(agentOptions.plugins) ? agentOptions.plugins : void 0;
|
|
13382
|
-
const credentials = {
|
|
13383
|
-
...agentOptions.apiKey !== void 0 ? { apiKey: agentOptions.apiKey } : {},
|
|
13384
|
-
...typeof agentOptions.model === "object" ? { model: agentOptions.model } : {},
|
|
13385
|
-
...parentPlugins !== void 0 ? { plugins: parentPlugins } : {}
|
|
13386
|
-
};
|
|
13387
|
-
for (const tool of tools) inheritSubAgentCredentials(tool, credentials);
|
|
13388
|
-
}
|
|
13389
|
-
function buildCustomToolsInput(agentOptions, sendOptions, pluginManager, personalityToolWhitelist, agentId, personalityName, subagents) {
|
|
13390
|
-
const baseTools = sendOptions?.tools ?? agentOptions.tools ?? [];
|
|
13391
|
-
const agentsForTools = subagents !== void 0 && Object.keys(subagents).length > 0 ? subagents : agentOptions.agents;
|
|
13392
|
-
const subagentTools = declarativeSubagentTools(agentsForTools, baseTools);
|
|
13393
|
-
const pluginTools = pluginManager?.aggregated.tools ?? [];
|
|
13394
|
-
if (baseTools.length === 0 && subagentTools.length === 0 && pluginTools.length === 0) return {};
|
|
13395
|
-
const allTools = [...baseTools, ...subagentTools, ...pluginTools];
|
|
13396
|
-
bindParentCredentials(allTools, agentOptions);
|
|
13397
|
-
const merged = allTools.map((tool) => ({
|
|
13398
|
-
name: tool.name,
|
|
13399
|
-
description: tool.description,
|
|
13400
|
-
inputSchema: tool.inputSchema,
|
|
13401
|
-
handler: tool.handler
|
|
13402
|
-
}));
|
|
13403
|
-
const customTools = applyPersonalityFilter(merged, personalityToolWhitelist, {
|
|
13404
|
-
agentId,
|
|
13405
|
-
personalityName
|
|
13406
|
-
});
|
|
13407
|
-
if (customTools.length === 0 && personalityToolWhitelist === void 0) return {};
|
|
13408
|
-
return { customTools };
|
|
13409
|
-
}
|
|
13410
13525
|
function buildMcpMap(options) {
|
|
13411
13526
|
const map = /* @__PURE__ */ new Map();
|
|
13412
13527
|
const inline = options.sendOptions.mcpServers ?? options.agentOptions.mcpServers;
|
|
@@ -13419,7 +13534,6 @@ function buildMcpMap(options) {
|
|
|
13419
13534
|
var pluginProvidersAnnounced, RealLocalRun;
|
|
13420
13535
|
var init_real_local_run = __esm({
|
|
13421
13536
|
"src/internal/runtime/local-agent/real-local-run.ts"() {
|
|
13422
|
-
init_subagent();
|
|
13423
13537
|
init_errors();
|
|
13424
13538
|
init_run_events();
|
|
13425
13539
|
init_loop();
|
|
@@ -13432,11 +13546,11 @@ var init_real_local_run = __esm({
|
|
|
13432
13546
|
init_providers();
|
|
13433
13547
|
init_register_plugin_providers();
|
|
13434
13548
|
init_tracer();
|
|
13435
|
-
init_personality_filter();
|
|
13436
13549
|
init_async_local_storage();
|
|
13437
13550
|
init_fixture_run_base();
|
|
13438
13551
|
init_run_registry();
|
|
13439
13552
|
init_real_local_run_provider();
|
|
13553
|
+
init_real_local_run_tools();
|
|
13440
13554
|
pluginProvidersAnnounced = false;
|
|
13441
13555
|
RealLocalRun = class extends FixtureRunBase {
|
|
13442
13556
|
buildInputs;
|