@causyne/agent 1.20.117 → 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 +7 -2
- 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 +20 -4
- package/src/commands.js +12 -14
- 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/plugins/pluginManager.js +74 -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/reporting.js +12 -4
- package/src/skillsManager.js +3 -2
- package/src/skillsManager.ts +3 -2
- 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/pluginManager.js +17 -2
- 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/composerControls.js +16 -3
- package/src/tui/composerControls.ts +14 -3
- package/src/tui/prompt.js +122 -16
- 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/usageCard.js +119 -47
- package/src/tui/usageCard.ts +133 -49
- package/src/tui/workspaceIdentity.js +133 -0
- package/src/tui/workspaceIdentity.ts +146 -0
- package/src/tui/workspaceSwitch.js +2 -0
- package/src/tui/workspaceSwitch.ts +1 -0
- package/src/verification/boundedExplorer.js +119 -0
- package/src/verification/cliProbe.js +116 -0
- package/src/verification/featureMap.js +78 -0
- package/src/verification/interactivePty.js +188 -0
- package/src/verification/propertyProbe.js +121 -0
- package/src/verification/ptyProbe.js +125 -0
- package/src/verification/skillCatalog.d.ts +1 -0
- package/src/verification/skillCatalog.js +60 -0
- package/src/verification/statechart.js +143 -0
- package/src/verification/uiRuntime.js +57 -0
- package/src/verificationPlan.js +1 -1
- package/src/verificationPlan.ts +1 -1
|
@@ -11,6 +11,7 @@ import os from 'node:os';
|
|
|
11
11
|
import fs from 'node:fs';
|
|
12
12
|
import { fileURLToPath } from 'node:url';
|
|
13
13
|
import { randomUUID } from 'node:crypto';
|
|
14
|
+
import { decodeFreeFormArguments } from './toolScanner.js';
|
|
14
15
|
/**
|
|
15
16
|
* Universal tool name alias dictionary. Maps hallucinations from OpenAI,
|
|
16
17
|
* Anthropic, DeepSeek, Qwen, Ollama, etc. to Causyne Agent canonical tool names.
|
|
@@ -833,142 +834,245 @@ export function resolveParameterAliases(toolName, args, schema) {
|
|
|
833
834
|
repairs
|
|
834
835
|
};
|
|
835
836
|
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
const repairs = [];
|
|
841
|
-
const modified = { ...args };
|
|
842
|
-
if (!schema || !schema.properties) {
|
|
843
|
-
return { args: modified, repaired: false, repairs: [] };
|
|
837
|
+
function collectSchemaTypes(propSchema) {
|
|
838
|
+
const found = new Set();
|
|
839
|
+
if (typeof propSchema.type === 'string') {
|
|
840
|
+
found.add(propSchema.type);
|
|
844
841
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
const rawVal = parseFloat(timeMatch[1]);
|
|
859
|
-
const unit = (timeMatch[2] || '').toLowerCase();
|
|
860
|
-
let ms = rawVal;
|
|
861
|
-
if (unit === 'ms')
|
|
862
|
-
ms = rawVal;
|
|
863
|
-
else if (unit === 'm')
|
|
864
|
-
ms = rawVal * 60 * 1000;
|
|
865
|
-
else if (unit === 's')
|
|
866
|
-
ms = rawVal * 1000;
|
|
867
|
-
else
|
|
868
|
-
ms = rawVal <= 600 ? rawVal * 1000 : rawVal;
|
|
869
|
-
modified[key] = expectedType === 'integer' ? Math.round(ms) : ms;
|
|
870
|
-
repairs.push(`Normalized time string "${val}" -> ${modified[key]}ms for parameter '${key}'`);
|
|
871
|
-
}
|
|
872
|
-
else if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
|
|
873
|
-
const num = expectedType === 'integer' ? parseInt(trimmed, 10) : parseFloat(trimmed);
|
|
874
|
-
if (!isNaN(num)) {
|
|
875
|
-
modified[key] = num;
|
|
876
|
-
repairs.push(`Coerced string "${val}" -> number ${num} for parameter '${key}'`);
|
|
877
|
-
}
|
|
842
|
+
else if (Array.isArray(propSchema.type)) {
|
|
843
|
+
for (const entry of propSchema.type) {
|
|
844
|
+
if (typeof entry === 'string' && entry !== 'null')
|
|
845
|
+
found.add(entry);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
for (const branchKey of ['oneOf', 'anyOf', 'allOf']) {
|
|
849
|
+
const branches = propSchema[branchKey];
|
|
850
|
+
if (Array.isArray(branches)) {
|
|
851
|
+
for (const branch of branches) {
|
|
852
|
+
if (branch && typeof branch === 'object') {
|
|
853
|
+
for (const t of collectSchemaTypes(branch))
|
|
854
|
+
found.add(t);
|
|
878
855
|
}
|
|
879
856
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
return Array.from(found);
|
|
860
|
+
}
|
|
861
|
+
function coerceValueBySchema(key, val, propSchema, pathLabel, repairs, depth) {
|
|
862
|
+
if (depth > 8 || val === undefined || val === null)
|
|
863
|
+
return val;
|
|
864
|
+
const allowedTypes = collectSchemaTypes(propSchema);
|
|
865
|
+
const singleType = typeof propSchema.type === 'string'
|
|
866
|
+
? propSchema.type
|
|
867
|
+
: (allowedTypes.length === 1 ? allowedTypes[0] : undefined);
|
|
868
|
+
// Handle polymorphic / multi-type schemas (e.g. oneOf [string, string[]], union type arrays)
|
|
869
|
+
if (!singleType && allowedTypes.length > 1 && typeof val === 'string') {
|
|
870
|
+
const trimmed = val.trim();
|
|
871
|
+
if (allowedTypes.includes('string') && trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
|
|
872
|
+
try {
|
|
873
|
+
const unquoted = JSON.parse(trimmed);
|
|
874
|
+
if (typeof unquoted === 'string') {
|
|
875
|
+
repairs.push(`Unwrapped JSON-quoted string literal for polymorphic parameter '${pathLabel}'`);
|
|
876
|
+
return unquoted;
|
|
884
877
|
}
|
|
885
878
|
}
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
}
|
|
879
|
+
catch {
|
|
880
|
+
// Keep original string if not valid JSON string literal
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
if (allowedTypes.includes('object') && trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
|
884
|
+
const recovered = repairJsonArguments(trimmed);
|
|
885
|
+
if (!recovered.error) {
|
|
886
|
+
repairs.push(`Decoded JSON object string for polymorphic parameter '${pathLabel}'`);
|
|
887
|
+
return recovered.args;
|
|
896
888
|
}
|
|
897
889
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
repairs.push(`Coerced string "${val}" -> boolean true for parameter '${key}'`);
|
|
890
|
+
if (allowedTypes.includes('array') && trimmed.startsWith('[') && trimmed.endsWith(']')) {
|
|
891
|
+
try {
|
|
892
|
+
const parsed = JSON.parse(trimmed);
|
|
893
|
+
if (Array.isArray(parsed)) {
|
|
894
|
+
repairs.push(`Decoded JSON array string for polymorphic parameter '${pathLabel}'`);
|
|
895
|
+
return parsed;
|
|
905
896
|
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
897
|
+
}
|
|
898
|
+
catch {
|
|
899
|
+
// Keep string intact
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
if (allowedTypes.includes('boolean') && (trimmed === 'true' || trimmed === 'false')) {
|
|
903
|
+
repairs.push(`Coerced string "${val}" -> boolean ${trimmed} for parameter '${pathLabel}'`);
|
|
904
|
+
return trimmed === 'true';
|
|
905
|
+
}
|
|
906
|
+
if ((allowedTypes.includes('number') || allowedTypes.includes('integer')) && /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/.test(trimmed)) {
|
|
907
|
+
const num = allowedTypes.includes('integer') && !allowedTypes.includes('number') && !trimmed.includes('.')
|
|
908
|
+
? parseInt(trimmed, 10)
|
|
909
|
+
: parseFloat(trimmed);
|
|
910
|
+
if (Number.isFinite(num)) {
|
|
911
|
+
repairs.push(`Coerced string "${val}" -> number ${num} for parameter '${pathLabel}'`);
|
|
912
|
+
return num;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return val;
|
|
916
|
+
}
|
|
917
|
+
const expectedType = singleType;
|
|
918
|
+
// 1. Number / Integer coercion
|
|
919
|
+
if (expectedType === 'number' || expectedType === 'integer') {
|
|
920
|
+
if (typeof val === 'string') {
|
|
921
|
+
const trimmed = val.trim();
|
|
922
|
+
const timeMatch = (key === 'timeout' || key === 'timeoutMs' || key === 'timeout_ms' || key === 'duration')
|
|
923
|
+
? trimmed.match(/^(\d+(?:\.\d+)?)\s*(ms|s|m)?$/i)
|
|
924
|
+
: null;
|
|
925
|
+
if (timeMatch && timeMatch[1]) {
|
|
926
|
+
const rawVal = parseFloat(timeMatch[1]);
|
|
927
|
+
const unit = (timeMatch[2] || '').toLowerCase();
|
|
928
|
+
let ms = rawVal;
|
|
929
|
+
if (unit === 'ms')
|
|
930
|
+
ms = rawVal;
|
|
931
|
+
else if (unit === 'm')
|
|
932
|
+
ms = rawVal * 60 * 1000;
|
|
933
|
+
else if (unit === 's')
|
|
934
|
+
ms = rawVal * 1000;
|
|
935
|
+
else
|
|
936
|
+
ms = rawVal <= 600 ? rawVal * 1000 : rawVal;
|
|
937
|
+
const normalized = expectedType === 'integer' ? Math.round(ms) : ms;
|
|
938
|
+
repairs.push(`Normalized time string "${val}" -> ${normalized}ms for parameter '${pathLabel}'`);
|
|
939
|
+
return normalized;
|
|
940
|
+
}
|
|
941
|
+
else if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
|
|
942
|
+
const num = expectedType === 'integer' ? parseInt(trimmed, 10) : parseFloat(trimmed);
|
|
943
|
+
if (!isNaN(num)) {
|
|
944
|
+
repairs.push(`Coerced string "${val}" -> number ${num} for parameter '${pathLabel}'`);
|
|
945
|
+
return num;
|
|
909
946
|
}
|
|
910
947
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
948
|
+
}
|
|
949
|
+
else if (typeof val === 'number' && (key === 'timeout' || key === 'timeoutMs')) {
|
|
950
|
+
if (val > 0 && val <= 600) {
|
|
951
|
+
const ms = Math.round(val * 1000);
|
|
952
|
+
repairs.push(`Scaled timeout from seconds (${val}s) -> ${ms}ms for parameter '${pathLabel}'`);
|
|
953
|
+
return ms;
|
|
914
954
|
}
|
|
915
955
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
if (typeof
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
956
|
+
else if (Array.isArray(val) && val.length === 1) {
|
|
957
|
+
const item = val[0];
|
|
958
|
+
if (typeof item === 'number') {
|
|
959
|
+
repairs.push(`Unwrapped single-element array to number for parameter '${pathLabel}'`);
|
|
960
|
+
return item;
|
|
961
|
+
}
|
|
962
|
+
else if (typeof item === 'string' && /^-?\d+(\.\d+)?$/.test(item.trim())) {
|
|
963
|
+
const num = expectedType === 'integer' ? parseInt(item.trim(), 10) : parseFloat(item.trim());
|
|
964
|
+
repairs.push(`Unwrapped single-element array to number for parameter '${pathLabel}'`);
|
|
965
|
+
return num;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
return val;
|
|
969
|
+
}
|
|
970
|
+
// 2. Boolean coercion
|
|
971
|
+
if (expectedType === 'boolean') {
|
|
972
|
+
if (typeof val === 'string') {
|
|
973
|
+
const lower = val.trim().toLowerCase();
|
|
974
|
+
if (lower === 'true' || lower === '1') {
|
|
975
|
+
repairs.push(`Coerced string "${val}" -> boolean true for parameter '${pathLabel}'`);
|
|
976
|
+
return true;
|
|
977
|
+
}
|
|
978
|
+
else if (lower === 'false' || lower === '0') {
|
|
979
|
+
repairs.push(`Coerced string "${val}" -> boolean false for parameter '${pathLabel}'`);
|
|
980
|
+
return false;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
else if (typeof val === 'number') {
|
|
984
|
+
const coerced = val !== 0;
|
|
985
|
+
repairs.push(`Coerced number ${val} -> boolean ${coerced} for parameter '${pathLabel}'`);
|
|
986
|
+
return coerced;
|
|
987
|
+
}
|
|
988
|
+
return val;
|
|
989
|
+
}
|
|
990
|
+
// 3. Array coercion (auto-wraps single objects, parses strings, and coerces items recursively)
|
|
991
|
+
if (expectedType === 'array' || (allowedTypes.length === 1 && allowedTypes[0] === 'array')) {
|
|
992
|
+
let arrVal = Array.isArray(val) ? val : null;
|
|
993
|
+
if (!arrVal && typeof val === 'string') {
|
|
994
|
+
const trimmed = val.trim();
|
|
995
|
+
if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
|
|
996
|
+
try {
|
|
997
|
+
const parsed = JSON.parse(trimmed);
|
|
998
|
+
if (Array.isArray(parsed)) {
|
|
999
|
+
arrVal = parsed;
|
|
1000
|
+
repairs.push(`Parsed stringified array for parameter '${pathLabel}'`);
|
|
930
1001
|
}
|
|
931
1002
|
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
repairs.push(`Split comma-separated string into array for parameter '${key}'`);
|
|
935
|
-
}
|
|
936
|
-
else if (trimmed.length > 0) {
|
|
937
|
-
modified[key] = [trimmed];
|
|
938
|
-
repairs.push(`Wrapped single string into array for parameter '${key}'`);
|
|
1003
|
+
catch {
|
|
1004
|
+
// Passthrough
|
|
939
1005
|
}
|
|
940
1006
|
}
|
|
941
|
-
else if (
|
|
942
|
-
|
|
943
|
-
repairs.push(`
|
|
1007
|
+
else if (trimmed.includes(',')) {
|
|
1008
|
+
arrVal = trimmed.split(',').map((s) => s.trim());
|
|
1009
|
+
repairs.push(`Split comma-separated string into array for parameter '${pathLabel}'`);
|
|
1010
|
+
}
|
|
1011
|
+
else if (trimmed.length > 0) {
|
|
1012
|
+
arrVal = [trimmed];
|
|
1013
|
+
repairs.push(`Wrapped single string into array for parameter '${pathLabel}'`);
|
|
944
1014
|
}
|
|
945
1015
|
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
1016
|
+
else if (!arrVal && val && typeof val === 'object' && !Array.isArray(val)) {
|
|
1017
|
+
arrVal = [val];
|
|
1018
|
+
repairs.push(`Wrapped single object into array for parameter '${pathLabel}'`);
|
|
1019
|
+
}
|
|
1020
|
+
if (arrVal && propSchema.items) {
|
|
1021
|
+
const itemSchema = propSchema.items;
|
|
1022
|
+
return arrVal.map((entry, idx) => coerceValueBySchema(`${key}[]`, entry, itemSchema, `${pathLabel}[${idx}]`, repairs, depth + 1));
|
|
1023
|
+
}
|
|
1024
|
+
return arrVal ?? val;
|
|
1025
|
+
}
|
|
1026
|
+
// 4. Object coercion (parses JSON object strings and recurses into nested properties)
|
|
1027
|
+
if (expectedType === 'object' || (propSchema.properties && typeof propSchema.properties === 'object')) {
|
|
1028
|
+
let objVal = (val && typeof val === 'object' && !Array.isArray(val))
|
|
1029
|
+
? { ...val }
|
|
1030
|
+
: null;
|
|
1031
|
+
if (!objVal && typeof val === 'string') {
|
|
1032
|
+
const trimmed = val.trim();
|
|
1033
|
+
if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
|
1034
|
+
const recovered = repairJsonArguments(trimmed);
|
|
1035
|
+
if (!recovered.error) {
|
|
1036
|
+
objVal = recovered.args;
|
|
1037
|
+
repairs.push(`Parsed stringified JSON object for parameter '${pathLabel}'`);
|
|
961
1038
|
}
|
|
962
1039
|
}
|
|
963
1040
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
if (Array.isArray(val) && val.length === 1 && typeof val[0] === 'string') {
|
|
967
|
-
modified[key] = val[0];
|
|
968
|
-
repairs.push(`Unwrapped single-element array to string for parameter '${key}'`);
|
|
969
|
-
}
|
|
1041
|
+
if (objVal && propSchema.properties) {
|
|
1042
|
+
return coerceObjectBySchema(objVal, propSchema, pathLabel, repairs, depth + 1);
|
|
970
1043
|
}
|
|
1044
|
+
return objVal ?? val;
|
|
971
1045
|
}
|
|
1046
|
+
// 5. String coercion (unwrapping single-element arrays)
|
|
1047
|
+
if (expectedType === 'string') {
|
|
1048
|
+
if (Array.isArray(val) && val.length === 1 && typeof val[0] === 'string') {
|
|
1049
|
+
repairs.push(`Unwrapped single-element array to string for parameter '${pathLabel}'`);
|
|
1050
|
+
return val[0];
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
return val;
|
|
1054
|
+
}
|
|
1055
|
+
function coerceObjectBySchema(obj, schema, pathPrefix, repairs, depth) {
|
|
1056
|
+
if (depth > 8 || !schema.properties)
|
|
1057
|
+
return obj;
|
|
1058
|
+
const modified = { ...obj };
|
|
1059
|
+
for (const [key, propSchema] of Object.entries(schema.properties)) {
|
|
1060
|
+
if (!(key in modified))
|
|
1061
|
+
continue;
|
|
1062
|
+
const label = pathPrefix ? `${pathPrefix}.${key}` : key;
|
|
1063
|
+
modified[key] = coerceValueBySchema(key, modified[key], propSchema, label, repairs, depth);
|
|
1064
|
+
}
|
|
1065
|
+
return modified;
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Automatically coerce argument types recursively according to the tool's parameter schema.
|
|
1069
|
+
*/
|
|
1070
|
+
export function coerceArgumentTypes(_toolName, args, schema) {
|
|
1071
|
+
const repairs = [];
|
|
1072
|
+
if (!schema || !schema.properties) {
|
|
1073
|
+
return { args: { ...args }, repaired: false, repairs: [] };
|
|
1074
|
+
}
|
|
1075
|
+
const modified = coerceObjectBySchema(args, schema, '', repairs, 0);
|
|
972
1076
|
return {
|
|
973
1077
|
args: modified,
|
|
974
1078
|
repaired: repairs.length > 0,
|
|
@@ -1096,8 +1200,33 @@ export function selfRepairToolCall(toolCall, toolSchema, options = {}) {
|
|
|
1096
1200
|
};
|
|
1097
1201
|
}
|
|
1098
1202
|
allRepairs.push(...jsonResult.repairs);
|
|
1203
|
+
// 1b. Decode any dialect-adapted free-form / polymorphic JSON string paths
|
|
1204
|
+
let decodedInput = jsonResult.args;
|
|
1205
|
+
if (options.freeFormPaths && options.freeFormPaths.length > 0) {
|
|
1206
|
+
try {
|
|
1207
|
+
const beforeSnapshot = JSON.stringify(decodedInput);
|
|
1208
|
+
const cloned = structuredClone(decodedInput);
|
|
1209
|
+
decodedInput = decodeFreeFormArguments(cloned, options.freeFormPaths);
|
|
1210
|
+
if (JSON.stringify(decodedInput) !== beforeSnapshot) {
|
|
1211
|
+
allRepairs.push('Decoded adapted free-form/polymorphic schema arguments');
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
catch {
|
|
1215
|
+
decodedInput = decodeFreeFormArguments({ ...decodedInput }, options.freeFormPaths);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
// Unwrap accidental single-key argument envelope { arguments: { ... } }
|
|
1219
|
+
if (decodedInput &&
|
|
1220
|
+
Object.keys(decodedInput).length === 1 &&
|
|
1221
|
+
decodedInput.arguments &&
|
|
1222
|
+
typeof decodedInput.arguments === 'object' &&
|
|
1223
|
+
!Array.isArray(decodedInput.arguments) &&
|
|
1224
|
+
!(toolSchema?.properties && 'arguments' in toolSchema.properties)) {
|
|
1225
|
+
decodedInput = decodedInput.arguments;
|
|
1226
|
+
allRepairs.push("Unwrapped single-key 'arguments' object envelope");
|
|
1227
|
+
}
|
|
1099
1228
|
// 2. Resolve parameter aliases & structural transforms
|
|
1100
|
-
const aliasResult = resolveParameterAliases(canonicalName,
|
|
1229
|
+
const aliasResult = resolveParameterAliases(canonicalName, decodedInput, toolSchema);
|
|
1101
1230
|
allRepairs.push(...aliasResult.repairs);
|
|
1102
1231
|
// 3. Coerce argument types
|
|
1103
1232
|
const typeResult = coerceArgumentTypes(canonicalName, aliasResult.args, toolSchema);
|