@kingsoftcloud/agentkit-harness-core 0.0.2 → 0.0.4

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.
@@ -0,0 +1,9 @@
1
+ /** Public diagnostic projection shared by adapters and browser presentation.
2
+ * Apply before bounding so a truncated credential cannot escape recognition.
3
+ * This is for diagnostics only; successful file/terminal content is not input.
4
+ */
5
+ export declare function redactDiagnosticText(input: unknown, maxChars?: number): string;
6
+ export declare function publicErrorMessage(error: unknown, fallback?: string): string;
7
+ export declare function publicErrorCode(error: unknown, fallback: string): string;
8
+ /** Project diagnostic fields without rewriting receipts, locators or inputs. */
9
+ export declare function publicFailureContent<T extends Record<string, unknown>>(content: T): T;
@@ -0,0 +1,41 @@
1
+ /** Public diagnostic projection shared by adapters and browser presentation.
2
+ * Apply before bounding so a truncated credential cannot escape recognition.
3
+ * This is for diagnostics only; successful file/terminal content is not input.
4
+ */
5
+ export function redactDiagnosticText(input, maxChars = 2048) {
6
+ const text = typeof input === 'string' ? input : '';
7
+ const credential = '(?:authorization|proxy-authorization|api[_-]?key|access[_-]?key(?:[_-]?(?:id|secret))?|secret(?:[_-]?key)?|password|passwd|token|access[_-]?token|refresh[_-]?token|session[_-]?(?:id|token)|client[_-]?secret|cookie|set-cookie|signature|KSSAccessKeyId|KSSSecurityToken)';
8
+ const cleaned = text
9
+ .replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?(?:-----END [^-]*PRIVATE KEY-----|$)/g, '[redacted private key]')
10
+ .replace(/\b(?:Bearer|Basic)\s+[^\s,;"'<>]+/gi, '[redacted]')
11
+ .replace(/([a-z][a-z0-9+.-]*:\/\/)[^\s/<>"']*@/gi, '$1[redacted]@')
12
+ .replace(new RegExp(`(["']?${credential}["']?\\s*[=:]\\s*)(?:"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|[^\\s&,;<>]+)`, 'gi'), '$1[redacted]')
13
+ .replace(/\b(?:sk|ak|tok)-[A-Za-z0-9_-]{8,}/g, '[redacted]')
14
+ .replace(/\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g, '[redacted]')
15
+ .replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g, '[redacted]')
16
+ .replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, '');
17
+ const limit = Number.isSafeInteger(maxChars) && maxChars > 0 ? Math.min(maxChars, 8192) : 2048;
18
+ return cleaned.length <= limit ? cleaned : cleaned.slice(0, Math.max(0, limit - 1)) + '…';
19
+ }
20
+ export function publicErrorMessage(error, fallback = 'Tool operation failed.') {
21
+ const message = error && typeof error === 'object' && 'message' in error ? error.message : error;
22
+ return redactDiagnosticText(message, 1024) || fallback;
23
+ }
24
+ export function publicErrorCode(error, fallback) {
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;
28
+ }
29
+ /** Project diagnostic fields without rewriting receipts, locators or inputs. */
30
+ export function publicFailureContent(content) {
31
+ const result = { ...content };
32
+ for (const key of ['message', 'error_message', 'errorMessage', 'detail']) {
33
+ if (typeof result[key] === 'string')
34
+ result[key] = redactDiagnosticText(result[key], 1024);
35
+ }
36
+ for (const key of ['code', 'error_type']) {
37
+ if (typeof result[key] === 'string')
38
+ result[key] = publicErrorCode({ code: result[key] }, 'TOOL_OPERATION_FAILED');
39
+ }
40
+ return result;
41
+ }
package/dist/index.d.mts CHANGED
@@ -63,3 +63,4 @@ export * from './model-failure.mjs';
63
63
  export * from './summary-continuity.mjs';
64
64
  export { matchesToolExecutionContract } from './tool-execution-contract.mjs';
65
65
  export * from './workspace-change.mjs';
66
+ export * from './error-presentation.mjs';
package/dist/index.mjs CHANGED
@@ -63,3 +63,4 @@ export * from './model-failure.mjs';
63
63
  export * from './summary-continuity.mjs';
64
64
  export { matchesToolExecutionContract } from './tool-execution-contract.mjs';
65
65
  export * from './workspace-change.mjs';
66
+ export * from './error-presentation.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingsoftcloud/agentkit-harness-core",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Host-independent Native Harness contracts, transitions and durable execution.",
@@ -68,6 +68,10 @@
68
68
  "./capability-profile": {
69
69
  "types": "./dist/capability-profile.d.mts",
70
70
  "default": "./dist/capability-profile.mjs"
71
+ },
72
+ "./error-presentation": {
73
+ "types": "./dist/error-presentation.d.mts",
74
+ "default": "./dist/error-presentation.mjs"
71
75
  }
72
76
  },
73
77
  "files": [
@@ -0,0 +1,42 @@
1
+ /** Public diagnostic projection shared by adapters and browser presentation.
2
+ * Apply before bounding so a truncated credential cannot escape recognition.
3
+ * This is for diagnostics only; successful file/terminal content is not input.
4
+ */
5
+ export function redactDiagnosticText(input: unknown, maxChars = 2048): string {
6
+ const text = typeof input === 'string' ? input : '';
7
+ const credential = '(?:authorization|proxy-authorization|api[_-]?key|access[_-]?key(?:[_-]?(?:id|secret))?|secret(?:[_-]?key)?|password|passwd|token|access[_-]?token|refresh[_-]?token|session[_-]?(?:id|token)|client[_-]?secret|cookie|set-cookie|signature|KSSAccessKeyId|KSSSecurityToken)';
8
+ const cleaned = text
9
+ .replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?(?:-----END [^-]*PRIVATE KEY-----|$)/g, '[redacted private key]')
10
+ .replace(/\b(?:Bearer|Basic)\s+[^\s,;"'<>]+/gi, '[redacted]')
11
+ .replace(/([a-z][a-z0-9+.-]*:\/\/)[^\s/<>"']*@/gi, '$1[redacted]@')
12
+ .replace(new RegExp(`(["']?${credential}["']?\\s*[=:]\\s*)(?:"(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|[^\\s&,;<>]+)`, 'gi'), '$1[redacted]')
13
+ .replace(/\b(?:sk|ak|tok)-[A-Za-z0-9_-]{8,}/g, '[redacted]')
14
+ .replace(/\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g, '[redacted]')
15
+ .replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g, '[redacted]')
16
+ .replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, '');
17
+ const limit = Number.isSafeInteger(maxChars) && maxChars > 0 ? Math.min(maxChars, 8192) : 2048;
18
+ return cleaned.length <= limit ? cleaned : cleaned.slice(0, Math.max(0, limit - 1)) + '…';
19
+ }
20
+
21
+ export function publicErrorMessage(error: unknown, fallback = 'Tool operation failed.'): string {
22
+ const message = error && typeof error === 'object' && 'message' in error ? (error as { message?: unknown }).message : error;
23
+ return redactDiagnosticText(message, 1024) || fallback;
24
+ }
25
+
26
+ export function publicErrorCode(error: unknown, fallback: string): string {
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;
30
+ }
31
+
32
+ /** Project diagnostic fields without rewriting receipts, locators or inputs. */
33
+ export function publicFailureContent<T extends Record<string, unknown>>(content: T): T {
34
+ const result = { ...content };
35
+ for (const key of ['message', 'error_message', 'errorMessage', 'detail'] as const) {
36
+ if (typeof result[key] === 'string') (result as Record<string, unknown>)[key] = redactDiagnosticText(result[key], 1024);
37
+ }
38
+ for (const key of ['code', 'error_type'] as const) {
39
+ if (typeof result[key] === 'string') (result as Record<string, unknown>)[key] = publicErrorCode({ code: result[key] }, 'TOOL_OPERATION_FAILED');
40
+ }
41
+ return result;
42
+ }
package/src/index.mts CHANGED
@@ -63,3 +63,4 @@ export * from './model-failure.mjs';
63
63
  export * from './summary-continuity.mjs';
64
64
  export { matchesToolExecutionContract } from './tool-execution-contract.mjs';
65
65
  export * from './workspace-change.mjs';
66
+ export * from './error-presentation.mjs';