@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/dist/a2a/index.js CHANGED
@@ -10093,6 +10093,124 @@ var init_ollama_native = __esm({
10093
10093
  ollamaSystemText = collapseSystemText;
10094
10094
  }
10095
10095
  });
10096
+ function loadJsonrepair() {
10097
+ if (cachedJsonrepair === void 0) {
10098
+ const req = createRequire(import.meta.url);
10099
+ cachedJsonrepair = req("jsonrepair").jsonrepair;
10100
+ }
10101
+ return cachedJsonrepair;
10102
+ }
10103
+ function isPlainObject(v) {
10104
+ return v !== null && typeof v === "object" && !Array.isArray(v);
10105
+ }
10106
+ function toFiniteNumber(raw) {
10107
+ if (raw === "") return void 0;
10108
+ const n = Number(raw);
10109
+ return Number.isFinite(n) && String(n) === raw ? n : void 0;
10110
+ }
10111
+ function tryJson(raw, repair) {
10112
+ const t = raw.trimStart();
10113
+ if (!(t.startsWith("{") || t.startsWith("["))) return void 0;
10114
+ try {
10115
+ return JSON.parse(repair ? loadJsonrepair()(t) : t);
10116
+ } catch {
10117
+ return void 0;
10118
+ }
10119
+ }
10120
+ function heuristicCoerce(raw, repairJson) {
10121
+ if (raw === "true") return true;
10122
+ if (raw === "false") return false;
10123
+ if (raw === "null") return null;
10124
+ const n = toFiniteNumber(raw);
10125
+ if (n !== void 0) return n;
10126
+ const json = tryJson(raw, false) ?? (repairJson ? tryJson(raw, true) : void 0);
10127
+ return json === void 0 ? raw : json;
10128
+ }
10129
+ function coerceCandidates(raw, repairJson) {
10130
+ const out = [];
10131
+ if (raw === "true") out.push(true);
10132
+ else if (raw === "false") out.push(false);
10133
+ else if (raw === "null") out.push(null);
10134
+ const n = toFiniteNumber(raw);
10135
+ if (n !== void 0) out.push(n);
10136
+ const json = tryJson(raw, false) ?? (repairJson ? tryJson(raw, true) : void 0);
10137
+ if (json !== void 0) out.push(json);
10138
+ out.push(raw);
10139
+ return out;
10140
+ }
10141
+ function objectShape(schema) {
10142
+ const shape = schema?.shape;
10143
+ return shape !== null && typeof shape === "object" ? shape : void 0;
10144
+ }
10145
+ var cachedJsonrepair;
10146
+ var init_coerce = __esm({
10147
+ "src/sanitize/coerce.ts"() {
10148
+ }
10149
+ });
10150
+
10151
+ // src/sanitize/sanitize-tool-input.ts
10152
+ function applyTrim(key, value, ctx) {
10153
+ const trimmed = value.trim();
10154
+ if (trimmed !== value) ctx.notes.push(`trimmed "${key}"`);
10155
+ return trimmed;
10156
+ }
10157
+ function applyCoerce(key, raw, ctx) {
10158
+ const field = ctx.shape?.[key];
10159
+ let coerced = raw;
10160
+ if (field) {
10161
+ for (const candidate of coerceCandidates(raw, ctx.repairJson)) {
10162
+ if (field.safeParse(candidate).success) {
10163
+ coerced = candidate;
10164
+ break;
10165
+ }
10166
+ }
10167
+ } else {
10168
+ coerced = heuristicCoerce(raw, ctx.repairJson);
10169
+ }
10170
+ if (coerced !== raw) ctx.notes.push(`coerced "${key}"`);
10171
+ return coerced;
10172
+ }
10173
+ function applyRepair(key, value, ctx) {
10174
+ const repaired = tryJson(value, true);
10175
+ if (repaired === void 0) return value;
10176
+ ctx.notes.push(`repaired json "${key}"`);
10177
+ return repaired;
10178
+ }
10179
+ function sanitizeString(key, value, ctx) {
10180
+ let out = ctx.trim ? applyTrim(key, value, ctx) : value;
10181
+ if (ctx.coerce && typeof out === "string") out = applyCoerce(key, out, ctx);
10182
+ if (ctx.repairJson && !ctx.coerce && typeof out === "string") out = applyRepair(key, out, ctx);
10183
+ return out;
10184
+ }
10185
+ function walk(input, ctx, depth) {
10186
+ const out = {};
10187
+ for (const [key, value] of Object.entries(input)) {
10188
+ if (typeof value === "string") out[key] = sanitizeString(key, value, ctx);
10189
+ else if (ctx.deep && depth < ctx.maxDepth && isPlainObject(value))
10190
+ out[key] = walk(value, ctx, depth + 1);
10191
+ else out[key] = value;
10192
+ }
10193
+ return out;
10194
+ }
10195
+ function sanitizeToolInput(input, options) {
10196
+ if (!isPlainObject(input)) return { value: input, changed: false, notes: [] };
10197
+ const ctx = {
10198
+ trim: options?.trim,
10199
+ coerce: options?.coerce ?? false,
10200
+ repairJson: options?.repairJson ?? false,
10201
+ deep: options?.deep ?? false,
10202
+ maxDepth: options?.maxDepth ?? 8,
10203
+ shape: objectShape(options?.schema),
10204
+ notes: []
10205
+ };
10206
+ const value = walk(input, ctx, 0);
10207
+ return { value, changed: ctx.notes.length > 0, notes: ctx.notes };
10208
+ }
10209
+ var init_sanitize_tool_input = __esm({
10210
+ "src/sanitize/sanitize-tool-input.ts"() {
10211
+ init_coerce();
10212
+ }
10213
+ });
10096
10214
 
10097
10215
  // src/internal/llm/hermes-tool-extract.ts
10098
10216
  function extractHermesToolCalls(content, makeId) {
@@ -10116,13 +10234,14 @@ function parseHermesParams(inner) {
10116
10234
  const key = param[1];
10117
10235
  const value = param[2];
10118
10236
  if (key === void 0 || value === void 0) continue;
10119
- input[key.trim()] = value.trim();
10237
+ input[key.trim()] = value;
10120
10238
  }
10121
- return input;
10239
+ return sanitizeToolInput(input, { trim: true }).value;
10122
10240
  }
10123
10241
  var HERMES_BLOCK, HERMES_PARAM;
10124
10242
  var init_hermes_tool_extract = __esm({
10125
10243
  "src/internal/llm/hermes-tool-extract.ts"() {
10244
+ init_sanitize_tool_input();
10126
10245
  HERMES_BLOCK = /<function=\s*([^>\s]+)\s*>([\s\S]*?)<\/tool_call>/g;
10127
10246
  HERMES_PARAM = /<parameter=\s*([^>\s]+)\s*>([\s\S]*?)<\/parameter>/g;
10128
10247
  }