@causyne/agent 1.20.118 → 1.20.120
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/package.json +1 -1
- package/src/agentLoop.js +29 -12
- package/src/agentLoop.ts +29 -16
- package/src/browser/causyneBrowser.js +231 -136
- package/src/browser/causyneBrowser.ts +229 -140
- package/src/browser/searchProviders.js +41 -30
- package/src/browser/searchProviders.ts +24 -14
- package/src/browser/workspacePathSafety.js +50 -0
- package/src/browser/workspacePathSafety.ts +50 -0
- package/src/browser/workspacePreview.js +27 -4
- package/src/browser/workspacePreview.ts +28 -4
- package/src/cliMode.js +1 -1
- package/src/commands.js +5 -13
- package/src/creative/liveBridge.js +34 -1
- package/src/creative/liveBridge.ts +28 -1
- package/src/observer/evidence.js +23 -0
- package/src/observer/evidence.ts +21 -0
- package/src/providers/anthropic.js +33 -17
- package/src/providers/base.js +14 -0
- package/src/providers/dashscope-byok.js +13 -7
- package/src/providers/deepseek.js +13 -18
- package/src/providers/gemini.js +33 -25
- package/src/providers/moonshot.js +13 -12
- package/src/providers/ollama.js +21 -21
- package/src/providers/openai-compatible.js +12 -19
- package/src/providers/openrouter.js +20 -90
- package/src/providers/openrouter.ts +31 -94
- package/src/providers/qwen-byok.js +13 -7
- package/src/providers/toolContracts.js +9 -3
- package/src/providers/toolContracts.ts +9 -3
- package/src/providers/wireNormalizer.js +238 -0
- package/src/providers/wireNormalizer.ts +279 -0
- package/src/providers/xai.js +13 -12
- package/src/tools/browserAutomator.js +13 -1
- package/src/tools/browserAutomator.ts +13 -0
- package/src/tools/creativeApps.js +2 -1
- package/src/tools/creativeApps.ts +2 -1
- package/src/tools/gameAssetFetcher.js +130 -26
- package/src/tools/gameAssetHarvester.js +80 -58
- package/src/tools/nativeEngine.js +1 -1
- package/src/tools/nativeEngine.ts +1 -1
- package/src/tools/registry.js +13 -0
- package/src/tools/toolScanner.js +596 -140
- package/src/tools/toolScanner.ts +665 -147
- package/src/tools/toolSelfRepair.js +243 -114
- package/src/tools/toolSelfRepair.ts +262 -111
- package/src/tools/webFetch.js +161 -24
- package/src/tools/webFetch.ts +157 -22
- package/src/tools/webSearch.js +33 -4
- package/src/tools/webSearch.ts +27 -4
- package/src/tui/sessionPicker.js +132 -35
- package/src/tui/sessionPicker.ts +153 -32
- package/src/tui/sessionPickerView.js +277 -34
- package/src/tui/sessionPickerView.ts +328 -34
- package/src/tui/statusLine.js +3 -0
- package/src/tui/statusLine.ts +5 -0
- package/src/tui/workspaceIdentity.js +133 -0
- package/src/tui/workspaceIdentity.ts +146 -0
|
@@ -12,6 +12,7 @@ import os from 'node:os';
|
|
|
12
12
|
import fs from 'node:fs';
|
|
13
13
|
import { fileURLToPath } from 'node:url';
|
|
14
14
|
import { randomUUID } from 'node:crypto';
|
|
15
|
+
import { decodeFreeFormArguments } from './toolScanner.js';
|
|
15
16
|
|
|
16
17
|
export interface RepairResult {
|
|
17
18
|
args: Record<string, unknown>;
|
|
@@ -34,6 +35,10 @@ export interface ParameterSchema {
|
|
|
34
35
|
properties?: Record<string, ParameterSchema>;
|
|
35
36
|
required?: string[];
|
|
36
37
|
items?: ParameterSchema;
|
|
38
|
+
oneOf?: ParameterSchema[];
|
|
39
|
+
anyOf?: ParameterSchema[];
|
|
40
|
+
allOf?: ParameterSchema[];
|
|
41
|
+
enum?: unknown[];
|
|
37
42
|
[key: string]: unknown;
|
|
38
43
|
}
|
|
39
44
|
|
|
@@ -866,138 +871,256 @@ export function resolveParameterAliases(
|
|
|
866
871
|
};
|
|
867
872
|
}
|
|
868
873
|
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
const repairs: string[] = [];
|
|
878
|
-
const modified = { ...args };
|
|
879
|
-
|
|
880
|
-
if (!schema || !schema.properties) {
|
|
881
|
-
return { args: modified, repaired: false, repairs: [] };
|
|
874
|
+
function collectSchemaTypes(propSchema: ParameterSchema): string[] {
|
|
875
|
+
const found = new Set<string>();
|
|
876
|
+
if (typeof propSchema.type === 'string') {
|
|
877
|
+
found.add(propSchema.type);
|
|
878
|
+
} else if (Array.isArray(propSchema.type)) {
|
|
879
|
+
for (const entry of propSchema.type) {
|
|
880
|
+
if (typeof entry === 'string' && entry !== 'null') found.add(entry);
|
|
881
|
+
}
|
|
882
882
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
if (
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
// 1. Number / Integer coercion
|
|
890
|
-
if (expectedType === 'number' || expectedType === 'integer') {
|
|
891
|
-
if (typeof val === 'string') {
|
|
892
|
-
const trimmed = val.trim();
|
|
893
|
-
const timeMatch = (key === 'timeout' || key === 'timeoutMs' || key === 'timeout_ms' || key === 'duration')
|
|
894
|
-
? trimmed.match(/^(\d+(?:\.\d+)?)\s*(ms|s|m)?$/i)
|
|
895
|
-
: null;
|
|
896
|
-
if (timeMatch && timeMatch[1]) {
|
|
897
|
-
const rawVal = parseFloat(timeMatch[1]);
|
|
898
|
-
const unit = (timeMatch[2] || '').toLowerCase();
|
|
899
|
-
let ms = rawVal;
|
|
900
|
-
if (unit === 'ms') ms = rawVal;
|
|
901
|
-
else if (unit === 'm') ms = rawVal * 60 * 1000;
|
|
902
|
-
else if (unit === 's') ms = rawVal * 1000;
|
|
903
|
-
else ms = rawVal <= 600 ? rawVal * 1000 : rawVal;
|
|
904
|
-
modified[key] = expectedType === 'integer' ? Math.round(ms) : ms;
|
|
905
|
-
repairs.push(`Normalized time string "${val}" -> ${modified[key]}ms for parameter '${key}'`);
|
|
906
|
-
} else if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
|
|
907
|
-
const num = expectedType === 'integer' ? parseInt(trimmed, 10) : parseFloat(trimmed);
|
|
908
|
-
if (!isNaN(num)) {
|
|
909
|
-
modified[key] = num;
|
|
910
|
-
repairs.push(`Coerced string "${val}" -> number ${num} for parameter '${key}'`);
|
|
911
|
-
}
|
|
883
|
+
for (const branchKey of ['oneOf', 'anyOf', 'allOf'] as const) {
|
|
884
|
+
const branches = propSchema[branchKey];
|
|
885
|
+
if (Array.isArray(branches)) {
|
|
886
|
+
for (const branch of branches) {
|
|
887
|
+
if (branch && typeof branch === 'object') {
|
|
888
|
+
for (const t of collectSchemaTypes(branch)) found.add(t);
|
|
912
889
|
}
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
return Array.from(found);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
function coerceValueBySchema(
|
|
897
|
+
key: string,
|
|
898
|
+
val: unknown,
|
|
899
|
+
propSchema: ParameterSchema,
|
|
900
|
+
pathLabel: string,
|
|
901
|
+
repairs: string[],
|
|
902
|
+
depth: number
|
|
903
|
+
): unknown {
|
|
904
|
+
if (depth > 8 || val === undefined || val === null) return val;
|
|
905
|
+
|
|
906
|
+
const allowedTypes = collectSchemaTypes(propSchema);
|
|
907
|
+
const singleType = typeof propSchema.type === 'string'
|
|
908
|
+
? propSchema.type
|
|
909
|
+
: (allowedTypes.length === 1 ? allowedTypes[0] : undefined);
|
|
910
|
+
|
|
911
|
+
// Handle polymorphic / multi-type schemas (e.g. oneOf [string, string[]], union type arrays)
|
|
912
|
+
if (!singleType && allowedTypes.length > 1 && typeof val === 'string') {
|
|
913
|
+
const trimmed = val.trim();
|
|
914
|
+
if (allowedTypes.includes('string') && trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
|
|
915
|
+
try {
|
|
916
|
+
const unquoted = JSON.parse(trimmed);
|
|
917
|
+
if (typeof unquoted === 'string') {
|
|
918
|
+
repairs.push(`Unwrapped JSON-quoted string literal for polymorphic parameter '${pathLabel}'`);
|
|
919
|
+
return unquoted;
|
|
917
920
|
}
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
921
|
+
} catch {
|
|
922
|
+
// Keep original string if not valid JSON string literal
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
if (allowedTypes.includes('object') && trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
|
926
|
+
const recovered = repairJsonArguments(trimmed);
|
|
927
|
+
if (!recovered.error) {
|
|
928
|
+
repairs.push(`Decoded JSON object string for polymorphic parameter '${pathLabel}'`);
|
|
929
|
+
return recovered.args;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
if (allowedTypes.includes('array') && trimmed.startsWith('[') && trimmed.endsWith(']')) {
|
|
933
|
+
try {
|
|
934
|
+
const parsed = JSON.parse(trimmed);
|
|
935
|
+
if (Array.isArray(parsed)) {
|
|
936
|
+
repairs.push(`Decoded JSON array string for polymorphic parameter '${pathLabel}'`);
|
|
937
|
+
return parsed;
|
|
926
938
|
}
|
|
939
|
+
} catch {
|
|
940
|
+
// Keep string intact
|
|
927
941
|
}
|
|
928
942
|
}
|
|
943
|
+
if (allowedTypes.includes('boolean') && (trimmed === 'true' || trimmed === 'false')) {
|
|
944
|
+
repairs.push(`Coerced string "${val}" -> boolean ${trimmed} for parameter '${pathLabel}'`);
|
|
945
|
+
return trimmed === 'true';
|
|
946
|
+
}
|
|
947
|
+
if ((allowedTypes.includes('number') || allowedTypes.includes('integer')) && /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(trimmed)) {
|
|
948
|
+
const num = allowedTypes.includes('integer') && !allowedTypes.includes('number') && !trimmed.includes('.')
|
|
949
|
+
? parseInt(trimmed, 10)
|
|
950
|
+
: parseFloat(trimmed);
|
|
951
|
+
if (Number.isFinite(num)) {
|
|
952
|
+
repairs.push(`Coerced string "${val}" -> number ${num} for parameter '${pathLabel}'`);
|
|
953
|
+
return num;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
return val;
|
|
957
|
+
}
|
|
929
958
|
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
959
|
+
const expectedType = singleType;
|
|
960
|
+
|
|
961
|
+
// 1. Number / Integer coercion
|
|
962
|
+
if (expectedType === 'number' || expectedType === 'integer') {
|
|
963
|
+
if (typeof val === 'string') {
|
|
964
|
+
const trimmed = val.trim();
|
|
965
|
+
const timeMatch = (key === 'timeout' || key === 'timeoutMs' || key === 'timeout_ms' || key === 'duration')
|
|
966
|
+
? trimmed.match(/^(\d+(?:\.\d+)?)\s*(ms|s|m)?$/i)
|
|
967
|
+
: null;
|
|
968
|
+
if (timeMatch && timeMatch[1]) {
|
|
969
|
+
const rawVal = parseFloat(timeMatch[1]);
|
|
970
|
+
const unit = (timeMatch[2] || '').toLowerCase();
|
|
971
|
+
let ms = rawVal;
|
|
972
|
+
if (unit === 'ms') ms = rawVal;
|
|
973
|
+
else if (unit === 'm') ms = rawVal * 60 * 1000;
|
|
974
|
+
else if (unit === 's') ms = rawVal * 1000;
|
|
975
|
+
else ms = rawVal <= 600 ? rawVal * 1000 : rawVal;
|
|
976
|
+
const normalized = expectedType === 'integer' ? Math.round(ms) : ms;
|
|
977
|
+
repairs.push(`Normalized time string "${val}" -> ${normalized}ms for parameter '${pathLabel}'`);
|
|
978
|
+
return normalized;
|
|
979
|
+
} else if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
|
|
980
|
+
const num = expectedType === 'integer' ? parseInt(trimmed, 10) : parseFloat(trimmed);
|
|
981
|
+
if (!isNaN(num)) {
|
|
982
|
+
repairs.push(`Coerced string "${val}" -> number ${num} for parameter '${pathLabel}'`);
|
|
983
|
+
return num;
|
|
940
984
|
}
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
|
|
985
|
+
}
|
|
986
|
+
} else if (typeof val === 'number' && (key === 'timeout' || key === 'timeoutMs')) {
|
|
987
|
+
if (val > 0 && val <= 600) {
|
|
988
|
+
const ms = Math.round(val * 1000);
|
|
989
|
+
repairs.push(`Scaled timeout from seconds (${val}s) -> ${ms}ms for parameter '${pathLabel}'`);
|
|
990
|
+
return ms;
|
|
991
|
+
}
|
|
992
|
+
} else if (Array.isArray(val) && val.length === 1) {
|
|
993
|
+
const item = val[0];
|
|
994
|
+
if (typeof item === 'number') {
|
|
995
|
+
repairs.push(`Unwrapped single-element array to number for parameter '${pathLabel}'`);
|
|
996
|
+
return item;
|
|
997
|
+
} else if (typeof item === 'string' && /^-?\d+(\.\d+)?$/.test(item.trim())) {
|
|
998
|
+
const num = expectedType === 'integer' ? parseInt(item.trim(), 10) : parseFloat(item.trim());
|
|
999
|
+
repairs.push(`Unwrapped single-element array to number for parameter '${pathLabel}'`);
|
|
1000
|
+
return num;
|
|
944
1001
|
}
|
|
945
1002
|
}
|
|
1003
|
+
return val;
|
|
1004
|
+
}
|
|
946
1005
|
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
}
|
|
958
|
-
} catch {
|
|
959
|
-
// Passthrough
|
|
960
|
-
}
|
|
961
|
-
} else if (trimmed.includes(',')) {
|
|
962
|
-
modified[key] = trimmed.split(',').map((s) => s.trim());
|
|
963
|
-
repairs.push(`Split comma-separated string into array for parameter '${key}'`);
|
|
964
|
-
} else if (trimmed.length > 0) {
|
|
965
|
-
modified[key] = [trimmed];
|
|
966
|
-
repairs.push(`Wrapped single string into array for parameter '${key}'`);
|
|
967
|
-
}
|
|
968
|
-
} else if (val && typeof val === 'object' && !Array.isArray(val)) {
|
|
969
|
-
modified[key] = [val];
|
|
970
|
-
repairs.push(`Wrapped single object into array for parameter '${key}'`);
|
|
1006
|
+
// 2. Boolean coercion
|
|
1007
|
+
if (expectedType === 'boolean') {
|
|
1008
|
+
if (typeof val === 'string') {
|
|
1009
|
+
const lower = val.trim().toLowerCase();
|
|
1010
|
+
if (lower === 'true' || lower === '1') {
|
|
1011
|
+
repairs.push(`Coerced string "${val}" -> boolean true for parameter '${pathLabel}'`);
|
|
1012
|
+
return true;
|
|
1013
|
+
} else if (lower === 'false' || lower === '0') {
|
|
1014
|
+
repairs.push(`Coerced string "${val}" -> boolean false for parameter '${pathLabel}'`);
|
|
1015
|
+
return false;
|
|
971
1016
|
}
|
|
1017
|
+
} else if (typeof val === 'number') {
|
|
1018
|
+
const coerced = val !== 0;
|
|
1019
|
+
repairs.push(`Coerced number ${val} -> boolean ${coerced} for parameter '${pathLabel}'`);
|
|
1020
|
+
return coerced;
|
|
972
1021
|
}
|
|
1022
|
+
return val;
|
|
1023
|
+
}
|
|
973
1024
|
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
}
|
|
985
|
-
} catch {
|
|
986
|
-
// Passthrough
|
|
1025
|
+
// 3. Array coercion (auto-wraps single objects, parses strings, and coerces items recursively)
|
|
1026
|
+
if (expectedType === 'array' || (allowedTypes.length === 1 && allowedTypes[0] === 'array')) {
|
|
1027
|
+
let arrVal: unknown[] | null = Array.isArray(val) ? val : null;
|
|
1028
|
+
if (!arrVal && typeof val === 'string') {
|
|
1029
|
+
const trimmed = val.trim();
|
|
1030
|
+
if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
|
|
1031
|
+
try {
|
|
1032
|
+
const parsed = JSON.parse(trimmed);
|
|
1033
|
+
if (Array.isArray(parsed)) {
|
|
1034
|
+
arrVal = parsed;
|
|
1035
|
+
repairs.push(`Parsed stringified array for parameter '${pathLabel}'`);
|
|
987
1036
|
}
|
|
1037
|
+
} catch {
|
|
1038
|
+
// Passthrough
|
|
988
1039
|
}
|
|
1040
|
+
} else if (trimmed.includes(',')) {
|
|
1041
|
+
arrVal = trimmed.split(',').map((s) => s.trim());
|
|
1042
|
+
repairs.push(`Split comma-separated string into array for parameter '${pathLabel}'`);
|
|
1043
|
+
} else if (trimmed.length > 0) {
|
|
1044
|
+
arrVal = [trimmed];
|
|
1045
|
+
repairs.push(`Wrapped single string into array for parameter '${pathLabel}'`);
|
|
989
1046
|
}
|
|
1047
|
+
} else if (!arrVal && val && typeof val === 'object' && !Array.isArray(val)) {
|
|
1048
|
+
arrVal = [val];
|
|
1049
|
+
repairs.push(`Wrapped single object into array for parameter '${pathLabel}'`);
|
|
990
1050
|
}
|
|
991
1051
|
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1052
|
+
if (arrVal && propSchema.items) {
|
|
1053
|
+
const itemSchema = propSchema.items;
|
|
1054
|
+
return arrVal.map((entry, idx) =>
|
|
1055
|
+
coerceValueBySchema(`${key}[]`, entry, itemSchema, `${pathLabel}[${idx}]`, repairs, depth + 1)
|
|
1056
|
+
);
|
|
1057
|
+
}
|
|
1058
|
+
return arrVal ?? val;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// 4. Object coercion (parses JSON object strings and recurses into nested properties)
|
|
1062
|
+
if (expectedType === 'object' || (propSchema.properties && typeof propSchema.properties === 'object')) {
|
|
1063
|
+
let objVal: Record<string, unknown> | null = (val && typeof val === 'object' && !Array.isArray(val))
|
|
1064
|
+
? { ...(val as Record<string, unknown>) }
|
|
1065
|
+
: null;
|
|
1066
|
+
if (!objVal && typeof val === 'string') {
|
|
1067
|
+
const trimmed = val.trim();
|
|
1068
|
+
if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
|
1069
|
+
const recovered = repairJsonArguments(trimmed);
|
|
1070
|
+
if (!recovered.error) {
|
|
1071
|
+
objVal = recovered.args;
|
|
1072
|
+
repairs.push(`Parsed stringified JSON object for parameter '${pathLabel}'`);
|
|
1073
|
+
}
|
|
997
1074
|
}
|
|
998
1075
|
}
|
|
1076
|
+
if (objVal && propSchema.properties) {
|
|
1077
|
+
return coerceObjectBySchema(objVal, propSchema, pathLabel, repairs, depth + 1);
|
|
1078
|
+
}
|
|
1079
|
+
return objVal ?? val;
|
|
999
1080
|
}
|
|
1000
1081
|
|
|
1082
|
+
// 5. String coercion (unwrapping single-element arrays)
|
|
1083
|
+
if (expectedType === 'string') {
|
|
1084
|
+
if (Array.isArray(val) && val.length === 1 && typeof val[0] === 'string') {
|
|
1085
|
+
repairs.push(`Unwrapped single-element array to string for parameter '${pathLabel}'`);
|
|
1086
|
+
return val[0];
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
return val;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
function coerceObjectBySchema(
|
|
1094
|
+
obj: Record<string, unknown>,
|
|
1095
|
+
schema: ParameterSchema,
|
|
1096
|
+
pathPrefix: string,
|
|
1097
|
+
repairs: string[],
|
|
1098
|
+
depth: number
|
|
1099
|
+
): Record<string, unknown> {
|
|
1100
|
+
if (depth > 8 || !schema.properties) return obj;
|
|
1101
|
+
const modified: Record<string, unknown> = { ...obj };
|
|
1102
|
+
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
1103
|
+
if (!(key in modified)) continue;
|
|
1104
|
+
const label = pathPrefix ? `${pathPrefix}.${key}` : key;
|
|
1105
|
+
modified[key] = coerceValueBySchema(key, modified[key], propSchema, label, repairs, depth);
|
|
1106
|
+
}
|
|
1107
|
+
return modified;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* Automatically coerce argument types recursively according to the tool's parameter schema.
|
|
1112
|
+
*/
|
|
1113
|
+
export function coerceArgumentTypes(
|
|
1114
|
+
_toolName: string,
|
|
1115
|
+
args: Record<string, unknown>,
|
|
1116
|
+
schema?: ParameterSchema
|
|
1117
|
+
): RepairResult {
|
|
1118
|
+
const repairs: string[] = [];
|
|
1119
|
+
if (!schema || !schema.properties) {
|
|
1120
|
+
return { args: { ...args }, repaired: false, repairs: [] };
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
const modified = coerceObjectBySchema(args, schema, '', repairs, 0);
|
|
1001
1124
|
return {
|
|
1002
1125
|
args: modified,
|
|
1003
1126
|
repaired: repairs.length > 0,
|
|
@@ -1117,7 +1240,7 @@ export function selfRepairToolCall(
|
|
|
1117
1240
|
arguments?: unknown;
|
|
1118
1241
|
},
|
|
1119
1242
|
toolSchema?: ParameterSchema,
|
|
1120
|
-
options: { cwd?: string } = {}
|
|
1243
|
+
options: { cwd?: string; freeFormPaths?: string[][] } = {}
|
|
1121
1244
|
): SelfRepairToolCallResult {
|
|
1122
1245
|
const rawName = toolCall.function?.name || toolCall.name || '';
|
|
1123
1246
|
const canonicalName = canonicalizeToolName(rawName);
|
|
@@ -1143,8 +1266,36 @@ export function selfRepairToolCall(
|
|
|
1143
1266
|
}
|
|
1144
1267
|
allRepairs.push(...jsonResult.repairs);
|
|
1145
1268
|
|
|
1269
|
+
// 1b. Decode any dialect-adapted free-form / polymorphic JSON string paths
|
|
1270
|
+
let decodedInput = jsonResult.args;
|
|
1271
|
+
if (options.freeFormPaths && options.freeFormPaths.length > 0) {
|
|
1272
|
+
try {
|
|
1273
|
+
const beforeSnapshot = JSON.stringify(decodedInput);
|
|
1274
|
+
const cloned = structuredClone(decodedInput) as Record<string, unknown>;
|
|
1275
|
+
decodedInput = decodeFreeFormArguments(cloned, options.freeFormPaths);
|
|
1276
|
+
if (JSON.stringify(decodedInput) !== beforeSnapshot) {
|
|
1277
|
+
allRepairs.push('Decoded adapted free-form/polymorphic schema arguments');
|
|
1278
|
+
}
|
|
1279
|
+
} catch {
|
|
1280
|
+
decodedInput = decodeFreeFormArguments({ ...decodedInput }, options.freeFormPaths);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
// Unwrap accidental single-key argument envelope { arguments: { ... } }
|
|
1285
|
+
if (
|
|
1286
|
+
decodedInput &&
|
|
1287
|
+
Object.keys(decodedInput).length === 1 &&
|
|
1288
|
+
decodedInput.arguments &&
|
|
1289
|
+
typeof decodedInput.arguments === 'object' &&
|
|
1290
|
+
!Array.isArray(decodedInput.arguments) &&
|
|
1291
|
+
!(toolSchema?.properties && 'arguments' in toolSchema.properties)
|
|
1292
|
+
) {
|
|
1293
|
+
decodedInput = decodedInput.arguments as Record<string, unknown>;
|
|
1294
|
+
allRepairs.push("Unwrapped single-key 'arguments' object envelope");
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1146
1297
|
// 2. Resolve parameter aliases & structural transforms
|
|
1147
|
-
const aliasResult = resolveParameterAliases(canonicalName,
|
|
1298
|
+
const aliasResult = resolveParameterAliases(canonicalName, decodedInput, toolSchema);
|
|
1148
1299
|
allRepairs.push(...aliasResult.repairs);
|
|
1149
1300
|
|
|
1150
1301
|
// 3. Coerce argument types
|