@brixel_ai/artifact-sdk 1.0.4 → 1.0.5

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.
package/dist/index.js CHANGED
@@ -120,7 +120,8 @@ async function executeTask(params) {
120
120
  body: JSON.stringify({ inputs })
121
121
  }
122
122
  );
123
- const data = await parseJsonOrText(response);
123
+ const rawData = await parseJsonOrText(response);
124
+ const data = decodeBase64BytesPayloads(rawData);
124
125
  if (!response.ok) {
125
126
  return toExecuteTaskFailure(toHttpError(response, data));
126
127
  }
@@ -152,6 +153,48 @@ function createExecuteTask(contextAuth) {
152
153
  function isRecord(value) {
153
154
  return typeof value === "object" && value !== null;
154
155
  }
156
+ function isBase64BytesPayload(value) {
157
+ if (!isRecord(value)) {
158
+ return false;
159
+ }
160
+ return value.type === "bytes" && value.encoding === "base64" && typeof value.content === "string";
161
+ }
162
+ function decodeBase64BytesPayloads(value) {
163
+ if (isBase64BytesPayload(value)) {
164
+ try {
165
+ return decodeBase64ToUint8Array(value.content);
166
+ } catch {
167
+ return value;
168
+ }
169
+ }
170
+ if (Array.isArray(value)) {
171
+ return value.map((entry) => decodeBase64BytesPayloads(entry));
172
+ }
173
+ if (!isRecord(value)) {
174
+ return value;
175
+ }
176
+ const transformed = {};
177
+ for (const [key, nestedValue] of Object.entries(value)) {
178
+ transformed[key] = decodeBase64BytesPayloads(nestedValue);
179
+ }
180
+ return transformed;
181
+ }
182
+ function decodeBase64ToUint8Array(base64Value) {
183
+ const normalizedBase64 = base64Value.replace(/\s+/g, "");
184
+ if (typeof globalThis.atob === "function") {
185
+ const decoded = globalThis.atob(normalizedBase64);
186
+ const bytes = new Uint8Array(decoded.length);
187
+ for (let index = 0; index < decoded.length; index += 1) {
188
+ bytes[index] = decoded.charCodeAt(index);
189
+ }
190
+ return bytes;
191
+ }
192
+ const globalWithOptionalBuffer = globalThis;
193
+ if (globalWithOptionalBuffer.Buffer) {
194
+ return Uint8Array.from(globalWithOptionalBuffer.Buffer.from(normalizedBase64, "base64"));
195
+ }
196
+ throw new Error("No base64 decoder available in this environment");
197
+ }
155
198
  function isActionExecutePayload(value) {
156
199
  return isRecord(value) && ("result" in value || "success" in value || "error" in value);
157
200
  }
package/dist/index.mjs CHANGED
@@ -85,7 +85,8 @@ async function executeTask(params) {
85
85
  body: JSON.stringify({ inputs })
86
86
  }
87
87
  );
88
- const data = await parseJsonOrText(response);
88
+ const rawData = await parseJsonOrText(response);
89
+ const data = decodeBase64BytesPayloads(rawData);
89
90
  if (!response.ok) {
90
91
  return toExecuteTaskFailure(toHttpError(response, data));
91
92
  }
@@ -117,6 +118,48 @@ function createExecuteTask(contextAuth) {
117
118
  function isRecord(value) {
118
119
  return typeof value === "object" && value !== null;
119
120
  }
121
+ function isBase64BytesPayload(value) {
122
+ if (!isRecord(value)) {
123
+ return false;
124
+ }
125
+ return value.type === "bytes" && value.encoding === "base64" && typeof value.content === "string";
126
+ }
127
+ function decodeBase64BytesPayloads(value) {
128
+ if (isBase64BytesPayload(value)) {
129
+ try {
130
+ return decodeBase64ToUint8Array(value.content);
131
+ } catch {
132
+ return value;
133
+ }
134
+ }
135
+ if (Array.isArray(value)) {
136
+ return value.map((entry) => decodeBase64BytesPayloads(entry));
137
+ }
138
+ if (!isRecord(value)) {
139
+ return value;
140
+ }
141
+ const transformed = {};
142
+ for (const [key, nestedValue] of Object.entries(value)) {
143
+ transformed[key] = decodeBase64BytesPayloads(nestedValue);
144
+ }
145
+ return transformed;
146
+ }
147
+ function decodeBase64ToUint8Array(base64Value) {
148
+ const normalizedBase64 = base64Value.replace(/\s+/g, "");
149
+ if (typeof globalThis.atob === "function") {
150
+ const decoded = globalThis.atob(normalizedBase64);
151
+ const bytes = new Uint8Array(decoded.length);
152
+ for (let index = 0; index < decoded.length; index += 1) {
153
+ bytes[index] = decoded.charCodeAt(index);
154
+ }
155
+ return bytes;
156
+ }
157
+ const globalWithOptionalBuffer = globalThis;
158
+ if (globalWithOptionalBuffer.Buffer) {
159
+ return Uint8Array.from(globalWithOptionalBuffer.Buffer.from(normalizedBase64, "base64"));
160
+ }
161
+ throw new Error("No base64 decoder available in this environment");
162
+ }
120
163
  function isActionExecutePayload(value) {
121
164
  return isRecord(value) && ("result" in value || "success" in value || "error" in value);
122
165
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brixel_ai/artifact-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "SDK for building Brixel Artifacts - interactive React components that integrate with Brixel workflows",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",