@kingsoftcloud/agentkit-harness-core 0.0.6 → 0.0.7
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.
|
@@ -28,14 +28,39 @@ export function publicErrorCode(error, fallback) {
|
|
|
28
28
|
}
|
|
29
29
|
/** Project diagnostic fields without rewriting receipts, locators or inputs. */
|
|
30
30
|
export function publicFailureContent(content) {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const diagnosticFields = new Set(['message', 'error_message', 'errorMessage', 'detail', 'details', 'error', 'cause', 'stack']);
|
|
32
|
+
const codeFields = new Set(['code', 'error_type', 'error_code']);
|
|
33
|
+
const ancestors = new Set();
|
|
34
|
+
let remaining = 10000;
|
|
35
|
+
function project(value, diagnostic, depth) {
|
|
36
|
+
if (--remaining < 0 || depth > 32)
|
|
37
|
+
return '[Diagnostic projection limit]';
|
|
38
|
+
if (typeof value === 'string')
|
|
39
|
+
return diagnostic ? redactDiagnosticText(value, 1024) : value;
|
|
40
|
+
if (value === null || typeof value !== 'object')
|
|
41
|
+
return value;
|
|
42
|
+
if (ancestors.has(value))
|
|
43
|
+
return '[Circular diagnostic]';
|
|
44
|
+
ancestors.add(value);
|
|
45
|
+
try {
|
|
46
|
+
if (Array.isArray(value))
|
|
47
|
+
return value.map(item => project(item, diagnostic, depth + 1));
|
|
48
|
+
// Error.message/stack/cause are non-enumerable, unlike ordinary payloads.
|
|
49
|
+
const keys = new Set(Object.keys(value));
|
|
50
|
+
if (value instanceof Error)
|
|
51
|
+
for (const key of ['message', 'stack', 'cause', 'code'])
|
|
52
|
+
if (Object.hasOwn(value, key))
|
|
53
|
+
keys.add(key);
|
|
54
|
+
return Object.fromEntries([...keys].map(key => {
|
|
55
|
+
const item = value[key];
|
|
56
|
+
return [key, codeFields.has(key) && typeof item === 'string'
|
|
57
|
+
? publicErrorCode({ code: item }, 'TOOL_OPERATION_FAILED')
|
|
58
|
+
: project(item, diagnostic || diagnosticFields.has(key), depth + 1)];
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
ancestors.delete(value);
|
|
63
|
+
}
|
|
35
64
|
}
|
|
36
|
-
|
|
37
|
-
if (typeof result[key] === 'string')
|
|
38
|
-
result[key] = publicErrorCode({ code: result[key] }, 'TOOL_OPERATION_FAILED');
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
65
|
+
return project(content, false, 0);
|
|
41
66
|
}
|
package/package.json
CHANGED
|
@@ -31,12 +31,29 @@ export function publicErrorCode(error: unknown, fallback: string): string {
|
|
|
31
31
|
|
|
32
32
|
/** Project diagnostic fields without rewriting receipts, locators or inputs. */
|
|
33
33
|
export function publicFailureContent<T extends Record<string, unknown>>(content: T): T {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const diagnosticFields = new Set(['message', 'error_message', 'errorMessage', 'detail', 'details', 'error', 'cause', 'stack']);
|
|
35
|
+
const codeFields = new Set(['code', 'error_type', 'error_code']);
|
|
36
|
+
const ancestors = new Set<object>();
|
|
37
|
+
let remaining = 10000;
|
|
38
|
+
function project(value: unknown, diagnostic: boolean, depth: number): unknown {
|
|
39
|
+
if (--remaining < 0 || depth > 32) return '[Diagnostic projection limit]';
|
|
40
|
+
if (typeof value === 'string') return diagnostic ? redactDiagnosticText(value, 1024) : value;
|
|
41
|
+
if (value === null || typeof value !== 'object') return value;
|
|
42
|
+
if (ancestors.has(value)) return '[Circular diagnostic]';
|
|
43
|
+
ancestors.add(value);
|
|
44
|
+
try {
|
|
45
|
+
if (Array.isArray(value)) return value.map(item => project(item, diagnostic, depth + 1));
|
|
46
|
+
// Error.message/stack/cause are non-enumerable, unlike ordinary payloads.
|
|
47
|
+
const keys = new Set(Object.keys(value));
|
|
48
|
+
if (value instanceof Error) for (const key of ['message', 'stack', 'cause', 'code'])
|
|
49
|
+
if (Object.hasOwn(value, key)) keys.add(key);
|
|
50
|
+
return Object.fromEntries([...keys].map(key => {
|
|
51
|
+
const item = (value as Record<string, unknown>)[key];
|
|
52
|
+
return [key, codeFields.has(key) && typeof item === 'string'
|
|
53
|
+
? publicErrorCode({ code: item }, 'TOOL_OPERATION_FAILED')
|
|
54
|
+
: project(item, diagnostic || diagnosticFields.has(key), depth + 1)];
|
|
55
|
+
}));
|
|
56
|
+
} finally { ancestors.delete(value); }
|
|
37
57
|
}
|
|
38
|
-
|
|
39
|
-
if (typeof result[key] === 'string') (result as Record<string, unknown>)[key] = publicErrorCode({ code: result[key] }, 'TOOL_OPERATION_FAILED');
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
58
|
+
return project(content, false, 0) as T;
|
|
42
59
|
}
|