@openagentpack/sdk 0.0.2-beta.0

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,13 @@
1
+ import { P as ProviderSessionEvent, al as SessionEvent } from './session-event-CmiO8Gqv.js';
2
+ import 'zod';
3
+
4
+ declare function sanitizeSessionEvents(events: ProviderSessionEvent[], options?: {
5
+ includeRaw?: boolean;
6
+ }): SessionEvent[];
7
+ declare function sanitizeSessionEvent(event: ProviderSessionEvent, options?: {
8
+ includeRaw?: boolean;
9
+ }): SessionEvent;
10
+
11
+ declare function toSessionEvent(raw: Record<string, unknown>): ProviderSessionEvent;
12
+
13
+ export { sanitizeSessionEvent, sanitizeSessionEvents, toSessionEvent as toBailianSessionEvent };
@@ -0,0 +1,202 @@
1
+ import {
2
+ toSessionEvent
3
+ } from "./chunk-GAAU67HX.js";
4
+
5
+ // src/redaction.ts
6
+ var REDACTED = "[redacted]";
7
+ var SENSITIVE_QUERY_KEYS = /* @__PURE__ */ new Set([
8
+ "access_key",
9
+ "access_key_id",
10
+ "accesskeyid",
11
+ "api_key",
12
+ "apikey",
13
+ "authorization",
14
+ "credential",
15
+ "expires",
16
+ "ossaccesskeyid",
17
+ "policy",
18
+ "security-token",
19
+ "signature",
20
+ "token",
21
+ "x-oss-access-key-id",
22
+ "x-oss-credential",
23
+ "x-oss-date",
24
+ "x-oss-expires",
25
+ "x-oss-security-token",
26
+ "x-oss-signature",
27
+ "x-amz-credential",
28
+ "x-amz-date",
29
+ "x-amz-expires",
30
+ "x-amz-security-token",
31
+ "x-amz-signature"
32
+ ]);
33
+ var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "gif", "webp", "svg", "bmp", "avif", "ico"]);
34
+ var VIDEO_EXTENSIONS = /* @__PURE__ */ new Set(["mp4", "webm", "mov", "m4v", "avi", "mkv"]);
35
+ var AUDIO_EXTENSIONS = /* @__PURE__ */ new Set(["mp3", "wav", "m4a", "ogg", "aac", "flac", "opus"]);
36
+ var DOWNLOAD_EXTENSIONS = /* @__PURE__ */ new Set([
37
+ "pdf",
38
+ "zip",
39
+ "rar",
40
+ "7z",
41
+ "tar",
42
+ "gz",
43
+ "doc",
44
+ "docx",
45
+ "xls",
46
+ "xlsx",
47
+ "ppt",
48
+ "pptx",
49
+ "csv",
50
+ "txt",
51
+ "md",
52
+ "json",
53
+ "epub",
54
+ "html"
55
+ ]);
56
+ var MARKDOWN_LINK_RE = /!?\[[^\]]*\]\((https?:\/\/[^)\s]+)\)/g;
57
+ function redactSensitiveText(value) {
58
+ const preservedUrls = [];
59
+ const withPlaceholders = value.replace(MARKDOWN_LINK_RE, (match, url) => {
60
+ if (!shouldPreserveMarkdownMediaUrl(url, match.startsWith("!"))) {
61
+ return match;
62
+ }
63
+ const index = preservedUrls.length;
64
+ preservedUrls.push(url);
65
+ return match.replace(url, mediaUrlPlaceholder(index));
66
+ });
67
+ let result = redactKeyValuePairs(redactUrls(withPlaceholders));
68
+ for (let i = 0; i < preservedUrls.length; i++) {
69
+ result = result.replaceAll(mediaUrlPlaceholder(i), preservedUrls[i]);
70
+ }
71
+ return result;
72
+ }
73
+ function mediaUrlPlaceholder(index) {
74
+ return `__AGENTS_PRESERVED_MEDIA_URL_${index}__`;
75
+ }
76
+ function shouldPreserveMarkdownMediaUrl(url, isImageSyntax) {
77
+ if (isImageSyntax) return true;
78
+ const ext = mediaExtensionFromUrl(url);
79
+ if (!ext) return false;
80
+ return IMAGE_EXTENSIONS.has(ext) || VIDEO_EXTENSIONS.has(ext) || AUDIO_EXTENSIONS.has(ext) || DOWNLOAD_EXTENSIONS.has(ext);
81
+ }
82
+ function mediaExtensionFromUrl(url) {
83
+ try {
84
+ const match = new URL(url).pathname.match(/\.([a-z0-9]+)$/i);
85
+ return match ? match[1].toLowerCase() : null;
86
+ } catch {
87
+ return null;
88
+ }
89
+ }
90
+ function redactUrls(value) {
91
+ return value.replace(/https?:\/\/[^\s)\]'"<>]+/g, (candidate) => {
92
+ try {
93
+ const url = new URL(candidate);
94
+ let redacted = false;
95
+ for (const key of Array.from(url.searchParams.keys())) {
96
+ if (isSensitiveQueryKey(key)) {
97
+ url.searchParams.set(key, REDACTED);
98
+ redacted = true;
99
+ }
100
+ }
101
+ return redacted ? url.toString() : candidate;
102
+ } catch {
103
+ return candidate;
104
+ }
105
+ });
106
+ }
107
+ function redactKeyValuePairs(value) {
108
+ return value.replace(
109
+ /\b(api[_-]?key|access[_-]?key(?:_id)?|authorization|credential|ossaccesskeyid|secret|signature|token)\b\s*[:=]\s*["']?[^"',\s)}\]]+/gi,
110
+ (_match, key) => `${key}: ${REDACTED}`
111
+ );
112
+ }
113
+ function isSensitiveQueryKey(key) {
114
+ const normalized = key.toLowerCase();
115
+ return SENSITIVE_QUERY_KEYS.has(normalized) || normalized.startsWith("x-oss-") || normalized.startsWith("x-amz-");
116
+ }
117
+
118
+ // src/internal/core/session-event-sanitizer.ts
119
+ var DEFAULT_TEXT_LIMIT = 4e3;
120
+ var TOOL_TEXT_LIMIT = 8e3;
121
+ function sanitizeSessionEvents(events, options = {}) {
122
+ return events.map((event) => sanitizeSessionEvent(event, options));
123
+ }
124
+ function sanitizeSessionEvent(event, options = {}) {
125
+ const isToolEvent = event.type === "tool_result" || event.type === "tool_use";
126
+ const textLimit = isToolEvent ? TOOL_TEXT_LIMIT : DEFAULT_TEXT_LIMIT;
127
+ const primarySource = event.content ?? (event.type === "tool_use" ? event.tool_input : void 0);
128
+ const primary = sanitizeOptionalText(primarySource, textLimit);
129
+ const raw = options.includeRaw ? sanitizeUnknown(event.raw, TOOL_TEXT_LIMIT * 2) : void 0;
130
+ const redacted = Boolean(primary?.redacted || raw?.redacted);
131
+ const truncated = Boolean(primary?.truncated || raw?.truncated);
132
+ const content = [];
133
+ if (primary?.value !== void 0) content.push({ type: "text", text: primary.value });
134
+ const metadata = {};
135
+ if (event.tool_name !== void 0) metadata.tool_name = event.tool_name;
136
+ if (event.tool_input !== void 0) metadata.tool_input = event.tool_input;
137
+ if (event.status !== void 0) metadata.status = event.status;
138
+ if (event.stop_reason !== void 0) metadata.stop_reason = event.stop_reason;
139
+ if (event.type !== "unknown") metadata.display_bucket = event.type;
140
+ if (event.artifact) metadata.artifact = event.artifact;
141
+ if (redacted) metadata.redacted = true;
142
+ if (truncated) metadata.truncated = true;
143
+ if (raw !== void 0) metadata.raw = raw.value;
144
+ const result = { type: event.raw_type };
145
+ if (event.role !== void 0) result.role = event.role;
146
+ if (content.length > 0) result.content = content;
147
+ if (Object.keys(metadata).length > 0) result.metadata = metadata;
148
+ if (event.type === "error") {
149
+ result.is_error = true;
150
+ if (primary?.value) result.message = primary.value;
151
+ }
152
+ return result;
153
+ }
154
+ function sanitizeOptionalText(value, limit) {
155
+ if (value === void 0) return void 0;
156
+ return sanitizeText(value, limit);
157
+ }
158
+ function sanitizeUnknown(value, limit) {
159
+ if (typeof value === "string") return sanitizeText(value, limit);
160
+ if (value === null || typeof value !== "object") {
161
+ return {
162
+ value,
163
+ redacted: false,
164
+ truncated: false
165
+ };
166
+ }
167
+ const serialized = safeStringify(value);
168
+ const sanitized = sanitizeText(serialized, limit);
169
+ return {
170
+ ...sanitized,
171
+ value: parseJsonOrText(sanitized.value)
172
+ };
173
+ }
174
+ function sanitizeText(value, limit) {
175
+ const redacted = redactSensitiveText(value);
176
+ const truncated = redacted.length > limit;
177
+ return {
178
+ value: truncated ? `${redacted.slice(0, limit)}
179
+ ...[truncated ${redacted.length - limit} chars]` : redacted,
180
+ redacted: redacted !== value,
181
+ truncated
182
+ };
183
+ }
184
+ function safeStringify(value) {
185
+ try {
186
+ return JSON.stringify(value, null, 2);
187
+ } catch {
188
+ return String(value);
189
+ }
190
+ }
191
+ function parseJsonOrText(value) {
192
+ try {
193
+ return JSON.parse(value);
194
+ } catch {
195
+ return value;
196
+ }
197
+ }
198
+ export {
199
+ sanitizeSessionEvent,
200
+ sanitizeSessionEvents,
201
+ toSessionEvent as toBailianSessionEvent
202
+ };
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@openagentpack/sdk",
3
+ "version": "0.0.2-beta.0",
4
+ "description": "OpenAgentPack SDK (Node-compatible runtime)",
5
+ "license": "Apache-2.0",
6
+ "keywords": [
7
+ "ai-agents",
8
+ "infrastructure-as-code",
9
+ "sdk",
10
+ "mcp",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://github.com/modelstudioai/OpenAgentPack/tree/main/packages/sdk#readme",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/modelstudioai/OpenAgentPack.git",
17
+ "directory": "packages/sdk"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/modelstudioai/OpenAgentPack/issues"
21
+ },
22
+ "engines": {
23
+ "node": ">=20"
24
+ },
25
+ "type": "module",
26
+ "main": "./dist/index.js",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "bun": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "./session-events": {
37
+ "bun": "./dist/session-events.js",
38
+ "types": "./dist/session-events.d.ts",
39
+ "import": "./dist/session-events.js"
40
+ },
41
+ "./scan-lifecycle": {
42
+ "bun": "./dist/scan-lifecycle.js",
43
+ "types": "./dist/scan-lifecycle.d.ts",
44
+ "import": "./dist/scan-lifecycle.js"
45
+ },
46
+ "./file-lifecycle": {
47
+ "bun": "./dist/file-lifecycle.js",
48
+ "types": "./dist/file-lifecycle.d.ts",
49
+ "import": "./dist/file-lifecycle.js"
50
+ }
51
+ },
52
+ "files": [
53
+ "dist",
54
+ "LICENSE"
55
+ ],
56
+ "publishConfig": {
57
+ "access": "public",
58
+ "registry": "https://registry.npmjs.org/"
59
+ },
60
+ "scripts": {
61
+ "build": "tsup",
62
+ "test": "bun test",
63
+ "typecheck": "tsc --noEmit"
64
+ },
65
+ "dependencies": {
66
+ "jszip": "^3.10.1",
67
+ "yaml": "^2.9.0",
68
+ "zod": "^4.4.3"
69
+ },
70
+ "devDependencies": {
71
+ "@types/bun": "^1.3.14",
72
+ "typescript": "^6.0.3"
73
+ }
74
+ }