@kingsoftcloud/agentkit-harness-core 0.0.7 → 0.0.9
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.
|
@@ -19,17 +19,26 @@ export function redactDiagnosticText(input, maxChars = 2048) {
|
|
|
19
19
|
}
|
|
20
20
|
export function publicErrorMessage(error, fallback = 'Tool operation failed.') {
|
|
21
21
|
const message = error && typeof error === 'object' && 'message' in error ? error.message : error;
|
|
22
|
-
return redactDiagnosticText(message, 1024) || fallback;
|
|
22
|
+
return redactDiagnosticText(message, 1024) || redactDiagnosticText(fallback, 1024) || 'Tool operation failed.';
|
|
23
23
|
}
|
|
24
24
|
export function publicErrorCode(error, fallback) {
|
|
25
25
|
const code = error && typeof error === 'object' && 'code' in error ? error.code : undefined;
|
|
26
|
-
|
|
27
|
-
&& redactDiagnosticText(
|
|
26
|
+
const valid = (value) => typeof value === 'string' && /^[A-Za-z][A-Za-z0-9_.-]{0,79}$/.test(value)
|
|
27
|
+
&& redactDiagnosticText(value) === value;
|
|
28
|
+
return valid(code) ? code : fallback === '' || valid(fallback) ? fallback : 'TOOL_OPERATION_FAILED';
|
|
28
29
|
}
|
|
29
30
|
/** Project diagnostic fields without rewriting receipts, locators or inputs. */
|
|
30
31
|
export function publicFailureContent(content) {
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
// Field names supply the context absent from an otherwise innocuous bare
|
|
33
|
+
// value. Locator identifiers (sessionId, operationKey, etc.) are not secrets.
|
|
34
|
+
const credentialFields = new Set(['password', 'passwd', 'dbpassword', 'databasepassword', 'secret', 'secrets', 'secretkey',
|
|
35
|
+
'secretaccesskey', 'apikey', 'apitoken', 'accesskey', 'accesskeyid', 'accesskeysecret', 'authorization', 'proxyauthorization',
|
|
36
|
+
'cookie', 'setcookie', 'token', 'accesstoken', 'refreshtoken', 'sessiontoken', 'idtoken', 'bearertoken', 'authtoken', 'clientsecret',
|
|
37
|
+
'kssaccesskeyid', 'ksssecuritytoken', 'awsaccesskeyid', 'awssecretaccesskey', 'awssessiontoken', 'xapikey', 'xauthtoken',
|
|
38
|
+
'xamzsecuritytoken', 'csrftoken', 'xcsrftoken', 'credentials', 'privatekey', 'sshprivatekey', 'connectionstring']);
|
|
39
|
+
const isCredential = (key) => credentialFields.has(key.replace(/[-_.\s]/g, '').toLowerCase());
|
|
40
|
+
const diagnosticFields = new Set(['message', 'error_message', 'errorMessage', 'error_description', 'detail', 'details', 'error', 'cause', 'stack', 'reason', 'reason_message', 'reasonMessage', 'hint']);
|
|
41
|
+
const codeFields = new Set(['code', 'error_type', 'error_code', 'errorCode']);
|
|
33
42
|
const ancestors = new Set();
|
|
34
43
|
let remaining = 10000;
|
|
35
44
|
function project(value, diagnostic, depth) {
|
|
@@ -51,9 +60,15 @@ export function publicFailureContent(content) {
|
|
|
51
60
|
for (const key of ['message', 'stack', 'cause', 'code'])
|
|
52
61
|
if (Object.hasOwn(value, key))
|
|
53
62
|
keys.add(key);
|
|
63
|
+
const fields = value;
|
|
64
|
+
const namedCredential = ['name', 'key'].some(key => typeof fields[key] === 'string' && isCredential(fields[key]));
|
|
54
65
|
return Object.fromEntries([...keys].map(key => {
|
|
55
66
|
const item = value[key];
|
|
56
|
-
|
|
67
|
+
if (isCredential(key) || (namedCredential && key === 'value'))
|
|
68
|
+
return [key, '[redacted]'];
|
|
69
|
+
// Empty optional diagnostic codes mean "absent" in typed Skill events.
|
|
70
|
+
// They carry no secret and must remain stable execution evidence.
|
|
71
|
+
return [key, codeFields.has(key) && typeof item === 'string' && item !== ''
|
|
57
72
|
? publicErrorCode({ code: item }, 'TOOL_OPERATION_FAILED')
|
|
58
73
|
: project(item, diagnostic || diagnosticFields.has(key), depth + 1)];
|
|
59
74
|
}));
|
package/package.json
CHANGED
|
@@ -20,19 +20,28 @@ export function redactDiagnosticText(input: unknown, maxChars = 2048): string {
|
|
|
20
20
|
|
|
21
21
|
export function publicErrorMessage(error: unknown, fallback = 'Tool operation failed.'): string {
|
|
22
22
|
const message = error && typeof error === 'object' && 'message' in error ? (error as { message?: unknown }).message : error;
|
|
23
|
-
return redactDiagnosticText(message, 1024) || fallback;
|
|
23
|
+
return redactDiagnosticText(message, 1024) || redactDiagnosticText(fallback, 1024) || 'Tool operation failed.';
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export function publicErrorCode(error: unknown, fallback: string): string {
|
|
27
27
|
const code = error && typeof error === 'object' && 'code' in error ? (error as { code?: unknown }).code : undefined;
|
|
28
|
-
|
|
29
|
-
&& redactDiagnosticText(
|
|
28
|
+
const valid = (value: unknown): value is string => typeof value === 'string' && /^[A-Za-z][A-Za-z0-9_.-]{0,79}$/.test(value)
|
|
29
|
+
&& redactDiagnosticText(value) === value;
|
|
30
|
+
return valid(code) ? code : fallback === '' || valid(fallback) ? fallback : 'TOOL_OPERATION_FAILED';
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
/** Project diagnostic fields without rewriting receipts, locators or inputs. */
|
|
33
34
|
export function publicFailureContent<T extends Record<string, unknown>>(content: T): T {
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
// Field names supply the context absent from an otherwise innocuous bare
|
|
36
|
+
// value. Locator identifiers (sessionId, operationKey, etc.) are not secrets.
|
|
37
|
+
const credentialFields = new Set(['password', 'passwd', 'dbpassword', 'databasepassword', 'secret', 'secrets', 'secretkey',
|
|
38
|
+
'secretaccesskey', 'apikey', 'apitoken', 'accesskey', 'accesskeyid', 'accesskeysecret', 'authorization', 'proxyauthorization',
|
|
39
|
+
'cookie', 'setcookie', 'token', 'accesstoken', 'refreshtoken', 'sessiontoken', 'idtoken', 'bearertoken', 'authtoken', 'clientsecret',
|
|
40
|
+
'kssaccesskeyid', 'ksssecuritytoken', 'awsaccesskeyid', 'awssecretaccesskey', 'awssessiontoken', 'xapikey', 'xauthtoken',
|
|
41
|
+
'xamzsecuritytoken', 'csrftoken', 'xcsrftoken', 'credentials', 'privatekey', 'sshprivatekey', 'connectionstring']);
|
|
42
|
+
const isCredential = (key: string) => credentialFields.has(key.replace(/[-_.\s]/g, '').toLowerCase());
|
|
43
|
+
const diagnosticFields = new Set(['message', 'error_message', 'errorMessage', 'error_description', 'detail', 'details', 'error', 'cause', 'stack', 'reason', 'reason_message', 'reasonMessage', 'hint']);
|
|
44
|
+
const codeFields = new Set(['code', 'error_type', 'error_code', 'errorCode']);
|
|
36
45
|
const ancestors = new Set<object>();
|
|
37
46
|
let remaining = 10000;
|
|
38
47
|
function project(value: unknown, diagnostic: boolean, depth: number): unknown {
|
|
@@ -47,9 +56,14 @@ export function publicFailureContent<T extends Record<string, unknown>>(content:
|
|
|
47
56
|
const keys = new Set(Object.keys(value));
|
|
48
57
|
if (value instanceof Error) for (const key of ['message', 'stack', 'cause', 'code'])
|
|
49
58
|
if (Object.hasOwn(value, key)) keys.add(key);
|
|
59
|
+
const fields = value as Record<string, unknown>;
|
|
60
|
+
const namedCredential = ['name', 'key'].some(key => typeof fields[key] === 'string' && isCredential(fields[key] as string));
|
|
50
61
|
return Object.fromEntries([...keys].map(key => {
|
|
51
62
|
const item = (value as Record<string, unknown>)[key];
|
|
52
|
-
|
|
63
|
+
if (isCredential(key) || (namedCredential && key === 'value')) return [key, '[redacted]'];
|
|
64
|
+
// Empty optional diagnostic codes mean "absent" in typed Skill events.
|
|
65
|
+
// They carry no secret and must remain stable execution evidence.
|
|
66
|
+
return [key, codeFields.has(key) && typeof item === 'string' && item !== ''
|
|
53
67
|
? publicErrorCode({ code: item }, 'TOOL_OPERATION_FAILED')
|
|
54
68
|
: project(item, diagnostic || diagnosticFields.has(key), depth + 1)];
|
|
55
69
|
}));
|