@theokit/sdk 2.13.1 → 2.14.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 +121 -2
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +121 -2
- package/dist/a2a/index.js.map +1 -1
- package/dist/cron.cjs +111 -2
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.js +111 -2
- package/dist/cron.js.map +1 -1
- package/dist/define-tool.d.ts +8 -0
- package/dist/eval.cjs +114 -5
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +114 -5
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +116 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +116 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/llm/hermes-tool-extract.d.ts +1 -0
- package/dist/sanitize/coerce.d.cts +1 -0
- package/dist/sanitize/coerce.d.ts +1 -0
- package/dist/sanitize/index.cjs +119 -0
- package/dist/sanitize/index.cjs.map +1 -0
- package/dist/sanitize/index.d.cts +9 -0
- package/dist/sanitize/index.d.ts +9 -0
- package/dist/sanitize/index.js +116 -0
- package/dist/sanitize/index.js.map +1 -0
- package/dist/sanitize/sanitize-tool-input.d.cts +11 -0
- package/dist/sanitize/sanitize-tool-input.d.ts +11 -0
- package/dist/sanitize/types.d.cts +39 -0
- package/dist/sanitize/types.d.ts +39 -0
- package/package.json +13 -2
package/dist/cron.cjs
CHANGED
|
@@ -10955,6 +10955,115 @@ function toOllamaTools(tools) {
|
|
|
10955
10955
|
}
|
|
10956
10956
|
}));
|
|
10957
10957
|
}
|
|
10958
|
+
var cachedJsonrepair;
|
|
10959
|
+
function loadJsonrepair() {
|
|
10960
|
+
if (cachedJsonrepair === void 0) {
|
|
10961
|
+
const req = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cron.cjs', document.baseURI).href)));
|
|
10962
|
+
cachedJsonrepair = req("jsonrepair").jsonrepair;
|
|
10963
|
+
}
|
|
10964
|
+
return cachedJsonrepair;
|
|
10965
|
+
}
|
|
10966
|
+
function isPlainObject(v) {
|
|
10967
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
10968
|
+
}
|
|
10969
|
+
function toFiniteNumber(raw) {
|
|
10970
|
+
if (raw === "") return void 0;
|
|
10971
|
+
const n = Number(raw);
|
|
10972
|
+
return Number.isFinite(n) && String(n) === raw ? n : void 0;
|
|
10973
|
+
}
|
|
10974
|
+
function tryJson(raw, repair) {
|
|
10975
|
+
const t = raw.trimStart();
|
|
10976
|
+
if (!(t.startsWith("{") || t.startsWith("["))) return void 0;
|
|
10977
|
+
try {
|
|
10978
|
+
return JSON.parse(repair ? loadJsonrepair()(t) : t);
|
|
10979
|
+
} catch {
|
|
10980
|
+
return void 0;
|
|
10981
|
+
}
|
|
10982
|
+
}
|
|
10983
|
+
function heuristicCoerce(raw, repairJson) {
|
|
10984
|
+
if (raw === "true") return true;
|
|
10985
|
+
if (raw === "false") return false;
|
|
10986
|
+
if (raw === "null") return null;
|
|
10987
|
+
const n = toFiniteNumber(raw);
|
|
10988
|
+
if (n !== void 0) return n;
|
|
10989
|
+
const json = tryJson(raw, false) ?? (repairJson ? tryJson(raw, true) : void 0);
|
|
10990
|
+
return json === void 0 ? raw : json;
|
|
10991
|
+
}
|
|
10992
|
+
function coerceCandidates(raw, repairJson) {
|
|
10993
|
+
const out = [];
|
|
10994
|
+
if (raw === "true") out.push(true);
|
|
10995
|
+
else if (raw === "false") out.push(false);
|
|
10996
|
+
else if (raw === "null") out.push(null);
|
|
10997
|
+
const n = toFiniteNumber(raw);
|
|
10998
|
+
if (n !== void 0) out.push(n);
|
|
10999
|
+
const json = tryJson(raw, false) ?? (repairJson ? tryJson(raw, true) : void 0);
|
|
11000
|
+
if (json !== void 0) out.push(json);
|
|
11001
|
+
out.push(raw);
|
|
11002
|
+
return out;
|
|
11003
|
+
}
|
|
11004
|
+
function objectShape(schema) {
|
|
11005
|
+
const shape = schema?.shape;
|
|
11006
|
+
return shape !== null && typeof shape === "object" ? shape : void 0;
|
|
11007
|
+
}
|
|
11008
|
+
|
|
11009
|
+
// src/sanitize/sanitize-tool-input.ts
|
|
11010
|
+
function applyTrim(key, value, ctx) {
|
|
11011
|
+
const trimmed = value.trim();
|
|
11012
|
+
if (trimmed !== value) ctx.notes.push(`trimmed "${key}"`);
|
|
11013
|
+
return trimmed;
|
|
11014
|
+
}
|
|
11015
|
+
function applyCoerce(key, raw, ctx) {
|
|
11016
|
+
const field = ctx.shape?.[key];
|
|
11017
|
+
let coerced = raw;
|
|
11018
|
+
if (field) {
|
|
11019
|
+
for (const candidate of coerceCandidates(raw, ctx.repairJson)) {
|
|
11020
|
+
if (field.safeParse(candidate).success) {
|
|
11021
|
+
coerced = candidate;
|
|
11022
|
+
break;
|
|
11023
|
+
}
|
|
11024
|
+
}
|
|
11025
|
+
} else {
|
|
11026
|
+
coerced = heuristicCoerce(raw, ctx.repairJson);
|
|
11027
|
+
}
|
|
11028
|
+
if (coerced !== raw) ctx.notes.push(`coerced "${key}"`);
|
|
11029
|
+
return coerced;
|
|
11030
|
+
}
|
|
11031
|
+
function applyRepair(key, value, ctx) {
|
|
11032
|
+
const repaired = tryJson(value, true);
|
|
11033
|
+
if (repaired === void 0) return value;
|
|
11034
|
+
ctx.notes.push(`repaired json "${key}"`);
|
|
11035
|
+
return repaired;
|
|
11036
|
+
}
|
|
11037
|
+
function sanitizeString(key, value, ctx) {
|
|
11038
|
+
let out = ctx.trim ? applyTrim(key, value, ctx) : value;
|
|
11039
|
+
if (ctx.coerce && typeof out === "string") out = applyCoerce(key, out, ctx);
|
|
11040
|
+
if (ctx.repairJson && !ctx.coerce && typeof out === "string") out = applyRepair(key, out, ctx);
|
|
11041
|
+
return out;
|
|
11042
|
+
}
|
|
11043
|
+
function walk(input, ctx, depth) {
|
|
11044
|
+
const out = {};
|
|
11045
|
+
for (const [key, value] of Object.entries(input)) {
|
|
11046
|
+
if (typeof value === "string") out[key] = sanitizeString(key, value, ctx);
|
|
11047
|
+
else if (ctx.deep && depth < ctx.maxDepth && isPlainObject(value))
|
|
11048
|
+
out[key] = walk(value, ctx, depth + 1);
|
|
11049
|
+
else out[key] = value;
|
|
11050
|
+
}
|
|
11051
|
+
return out;
|
|
11052
|
+
}
|
|
11053
|
+
function sanitizeToolInput(input, options) {
|
|
11054
|
+
if (!isPlainObject(input)) return { value: input, changed: false, notes: [] };
|
|
11055
|
+
const ctx = {
|
|
11056
|
+
trim: options?.trim,
|
|
11057
|
+
coerce: options?.coerce ?? false,
|
|
11058
|
+
repairJson: options?.repairJson ?? false,
|
|
11059
|
+
deep: options?.deep ?? false,
|
|
11060
|
+
maxDepth: options?.maxDepth ?? 8,
|
|
11061
|
+
shape: objectShape(options?.schema),
|
|
11062
|
+
notes: []
|
|
11063
|
+
};
|
|
11064
|
+
const value = walk(input, ctx, 0);
|
|
11065
|
+
return { value, changed: ctx.notes.length > 0, notes: ctx.notes };
|
|
11066
|
+
}
|
|
10958
11067
|
|
|
10959
11068
|
// src/internal/llm/hermes-tool-extract.ts
|
|
10960
11069
|
var HERMES_BLOCK = /<function=\s*([^>\s]+)\s*>([\s\S]*?)<\/tool_call>/g;
|
|
@@ -10980,9 +11089,9 @@ function parseHermesParams(inner) {
|
|
|
10980
11089
|
const key = param[1];
|
|
10981
11090
|
const value = param[2];
|
|
10982
11091
|
if (key === void 0 || value === void 0) continue;
|
|
10983
|
-
input[key.trim()] = value
|
|
11092
|
+
input[key.trim()] = value;
|
|
10984
11093
|
}
|
|
10985
|
-
return input;
|
|
11094
|
+
return sanitizeToolInput(input, { trim: true }).value;
|
|
10986
11095
|
}
|
|
10987
11096
|
|
|
10988
11097
|
// src/internal/llm/openai.ts
|