@brixel_ai/artifact-sdk 1.0.4 → 1.0.6
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 +48 -1
- package/dist/index.mjs +48 -1
- package/package.json +1 -1
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
|
|
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,52 @@ 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
|
+
const { encoding: _encoding, ...payloadWithoutEncoding } = value;
|
|
166
|
+
return {
|
|
167
|
+
...payloadWithoutEncoding,
|
|
168
|
+
content: decodeBase64ToUint8Array(value.content)
|
|
169
|
+
};
|
|
170
|
+
} catch {
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (Array.isArray(value)) {
|
|
175
|
+
return value.map((entry) => decodeBase64BytesPayloads(entry));
|
|
176
|
+
}
|
|
177
|
+
if (!isRecord(value)) {
|
|
178
|
+
return value;
|
|
179
|
+
}
|
|
180
|
+
const transformed = {};
|
|
181
|
+
for (const [key, nestedValue] of Object.entries(value)) {
|
|
182
|
+
transformed[key] = decodeBase64BytesPayloads(nestedValue);
|
|
183
|
+
}
|
|
184
|
+
return transformed;
|
|
185
|
+
}
|
|
186
|
+
function decodeBase64ToUint8Array(base64Value) {
|
|
187
|
+
const normalizedBase64 = base64Value.replace(/\s+/g, "");
|
|
188
|
+
if (typeof globalThis.atob === "function") {
|
|
189
|
+
const decoded = globalThis.atob(normalizedBase64);
|
|
190
|
+
const bytes = new Uint8Array(decoded.length);
|
|
191
|
+
for (let index = 0; index < decoded.length; index += 1) {
|
|
192
|
+
bytes[index] = decoded.charCodeAt(index);
|
|
193
|
+
}
|
|
194
|
+
return bytes;
|
|
195
|
+
}
|
|
196
|
+
const globalWithOptionalBuffer = globalThis;
|
|
197
|
+
if (globalWithOptionalBuffer.Buffer) {
|
|
198
|
+
return Uint8Array.from(globalWithOptionalBuffer.Buffer.from(normalizedBase64, "base64"));
|
|
199
|
+
}
|
|
200
|
+
throw new Error("No base64 decoder available in this environment");
|
|
201
|
+
}
|
|
155
202
|
function isActionExecutePayload(value) {
|
|
156
203
|
return isRecord(value) && ("result" in value || "success" in value || "error" in value);
|
|
157
204
|
}
|
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
|
|
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,52 @@ 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
|
+
const { encoding: _encoding, ...payloadWithoutEncoding } = value;
|
|
131
|
+
return {
|
|
132
|
+
...payloadWithoutEncoding,
|
|
133
|
+
content: decodeBase64ToUint8Array(value.content)
|
|
134
|
+
};
|
|
135
|
+
} catch {
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (Array.isArray(value)) {
|
|
140
|
+
return value.map((entry) => decodeBase64BytesPayloads(entry));
|
|
141
|
+
}
|
|
142
|
+
if (!isRecord(value)) {
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
const transformed = {};
|
|
146
|
+
for (const [key, nestedValue] of Object.entries(value)) {
|
|
147
|
+
transformed[key] = decodeBase64BytesPayloads(nestedValue);
|
|
148
|
+
}
|
|
149
|
+
return transformed;
|
|
150
|
+
}
|
|
151
|
+
function decodeBase64ToUint8Array(base64Value) {
|
|
152
|
+
const normalizedBase64 = base64Value.replace(/\s+/g, "");
|
|
153
|
+
if (typeof globalThis.atob === "function") {
|
|
154
|
+
const decoded = globalThis.atob(normalizedBase64);
|
|
155
|
+
const bytes = new Uint8Array(decoded.length);
|
|
156
|
+
for (let index = 0; index < decoded.length; index += 1) {
|
|
157
|
+
bytes[index] = decoded.charCodeAt(index);
|
|
158
|
+
}
|
|
159
|
+
return bytes;
|
|
160
|
+
}
|
|
161
|
+
const globalWithOptionalBuffer = globalThis;
|
|
162
|
+
if (globalWithOptionalBuffer.Buffer) {
|
|
163
|
+
return Uint8Array.from(globalWithOptionalBuffer.Buffer.from(normalizedBase64, "base64"));
|
|
164
|
+
}
|
|
165
|
+
throw new Error("No base64 decoder available in this environment");
|
|
166
|
+
}
|
|
120
167
|
function isActionExecutePayload(value) {
|
|
121
168
|
return isRecord(value) && ("result" in value || "success" in value || "error" in value);
|
|
122
169
|
}
|
package/package.json
CHANGED