@kingsoftcloud/agentkit-harness-core 0.0.8 → 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
- return typeof code === 'string' && /^[A-Za-z][A-Za-z0-9_.-]{0,79}$/.test(code)
27
- && redactDiagnosticText(code) === code ? code : fallback;
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
- const diagnosticFields = new Set(['message', 'error_message', 'errorMessage', 'detail', 'details', 'error', 'cause', 'stack']);
32
- const codeFields = new Set(['code', 'error_type', 'error_code']);
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,8 +60,12 @@ 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];
67
+ if (isCredential(key) || (namedCredential && key === 'value'))
68
+ return [key, '[redacted]'];
56
69
  // Empty optional diagnostic codes mean "absent" in typed Skill events.
57
70
  // They carry no secret and must remain stable execution evidence.
58
71
  return [key, codeFields.has(key) && typeof item === 'string' && item !== ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingsoftcloud/agentkit-harness-core",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Host-independent Native Harness contracts, transitions and durable execution.",
@@ -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
- return typeof code === 'string' && /^[A-Za-z][A-Za-z0-9_.-]{0,79}$/.test(code)
29
- && redactDiagnosticText(code) === code ? code : fallback;
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
- const diagnosticFields = new Set(['message', 'error_message', 'errorMessage', 'detail', 'details', 'error', 'cause', 'stack']);
35
- const codeFields = new Set(['code', 'error_type', 'error_code']);
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,8 +56,11 @@ 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];
63
+ if (isCredential(key) || (namedCredential && key === 'value')) return [key, '[redacted]'];
52
64
  // Empty optional diagnostic codes mean "absent" in typed Skill events.
53
65
  // They carry no secret and must remain stable execution evidence.
54
66
  return [key, codeFields.has(key) && typeof item === 'string' && item !== ''