@dual-os/sdk 0.9.2 → 0.10.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.
- package/dist/AgentChannel.d.ts +12 -12
- package/dist/AgentChannel.d.ts.map +1 -1
- package/dist/AgentChannel.js +2 -2
- package/dist/AgentChannel.js.map +1 -1
- package/dist/Files.d.ts +1 -1
- package/dist/Files.js +2 -2
- package/dist/Files.js.map +1 -1
- package/dist/Http.d.ts +38 -36
- package/dist/Http.d.ts.map +1 -1
- package/dist/Http.js +28 -25
- package/dist/Http.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/remote-runtime.d.ts.map +1 -1
- package/dist/remote-runtime.js +15 -11
- package/dist/remote-runtime.js.map +1 -1
- package/package.json +1 -1
- package/src/AgentChannel.ts +3 -6
- package/src/Files.ts +2 -2
- package/src/Http.ts +33 -31
- package/src/remote-runtime.ts +10 -5
package/src/Http.ts
CHANGED
|
@@ -150,14 +150,17 @@ function sniff(bytes: Uint8Array) {
|
|
|
150
150
|
);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
function fileContentType(bytes: Uint8Array, declared: string | null) {
|
|
154
|
+
return declared === null || pipe(declared, String.startsWith("application/octet-stream"))
|
|
155
|
+
? (sniff(bytes) ?? declared)
|
|
156
|
+
: declared;
|
|
157
|
+
}
|
|
158
|
+
|
|
153
159
|
function toolFile(bytes: Uint8Array, declared: string | null, filename: string | null) {
|
|
154
160
|
return {
|
|
155
161
|
_tag: "ToolFile",
|
|
156
162
|
contentBase64: Base64.encode(bytes),
|
|
157
|
-
contentType:
|
|
158
|
-
declared === null || pipe(declared, String.startsWith("application/octet-stream"))
|
|
159
|
-
? (sniff(bytes) ?? declared)
|
|
160
|
-
: declared,
|
|
163
|
+
contentType: fileContentType(bytes, declared),
|
|
161
164
|
filename,
|
|
162
165
|
sizeBytes: bytes.byteLength,
|
|
163
166
|
} satisfies ToolFile.File;
|
|
@@ -213,14 +216,30 @@ function textOf(carrier: Carrier, content: Content) {
|
|
|
213
216
|
|
|
214
217
|
function fileFrom(carrier: Carrier) {
|
|
215
218
|
return Schema.String.pipe(
|
|
216
|
-
Schema.decodeTo(
|
|
219
|
+
Schema.decodeTo(Files.File, {
|
|
217
220
|
decode: SchemaGetter.compose(
|
|
218
221
|
contentOf(carrier),
|
|
219
|
-
SchemaGetter.
|
|
222
|
+
SchemaGetter.transformEffect((content, options) =>
|
|
223
|
+
pipe(
|
|
224
|
+
Files.write({
|
|
225
|
+
bytes: content.bytes,
|
|
226
|
+
contentType: fileContentType(content.bytes, content.contentType),
|
|
227
|
+
name: "file",
|
|
228
|
+
}),
|
|
229
|
+
Effect.mapError(
|
|
230
|
+
error => new SchemaIssue.InvalidValue({ expected: error.message }, content, options),
|
|
231
|
+
),
|
|
232
|
+
),
|
|
233
|
+
),
|
|
220
234
|
),
|
|
221
|
-
encode: SchemaGetter.transformEffect((file:
|
|
222
|
-
|
|
223
|
-
|
|
235
|
+
encode: SchemaGetter.transformEffect((file: Files.File, options) =>
|
|
236
|
+
pipe(
|
|
237
|
+
Files.read(file),
|
|
238
|
+
Effect.mapBoth({
|
|
239
|
+
onSuccess: bytes => textOf(carrier, { bytes, contentType: file.contentType }),
|
|
240
|
+
onFailure: error =>
|
|
241
|
+
new SchemaIssue.InvalidValue({ expected: error.message }, file, options),
|
|
242
|
+
}),
|
|
224
243
|
),
|
|
225
244
|
),
|
|
226
245
|
}),
|
|
@@ -228,25 +247,11 @@ function fileFrom(carrier: Carrier) {
|
|
|
228
247
|
}
|
|
229
248
|
|
|
230
249
|
function encodedFrom(carrier: Carrier) {
|
|
231
|
-
return
|
|
232
|
-
Schema.decodeTo(Schema.String, {
|
|
233
|
-
decode: SchemaGetter.transform(file =>
|
|
234
|
-
textOf(carrier, { bytes: file.contentBase64, contentType: file.contentType ?? null }),
|
|
235
|
-
),
|
|
236
|
-
encode: SchemaGetter.compose(
|
|
237
|
-
contentOf(carrier),
|
|
238
|
-
SchemaGetter.transform(content => ({
|
|
239
|
-
contentBase64: content.bytes,
|
|
240
|
-
contentType: content.contentType,
|
|
241
|
-
})),
|
|
242
|
-
),
|
|
243
|
-
}),
|
|
244
|
-
);
|
|
250
|
+
return Schema.flip(fileFrom(carrier));
|
|
245
251
|
}
|
|
246
252
|
|
|
247
253
|
/**
|
|
248
|
-
* A file the API returns as a Base64 string inside JSON,
|
|
249
|
-
* type recognized from the bytes.
|
|
254
|
+
* A file the API returns as a Base64 string inside JSON, stored by the host and returned by reference.
|
|
250
255
|
*
|
|
251
256
|
* @since 0.0.0
|
|
252
257
|
* @category schemas
|
|
@@ -262,7 +267,7 @@ export const FileFromBase64 = fileFrom("base64");
|
|
|
262
267
|
export const FileFromBase64Url = fileFrom("base64url");
|
|
263
268
|
|
|
264
269
|
/**
|
|
265
|
-
* A {@link File} input the API reads as a Base64 string inside JSON.
|
|
270
|
+
* A {@link Files.File} input the API reads as a Base64 string inside JSON.
|
|
266
271
|
*
|
|
267
272
|
* @since 0.0.0
|
|
268
273
|
* @category schemas
|
|
@@ -783,12 +788,9 @@ const read = Effect.fnUntraced(function* (
|
|
|
783
788
|
const bytes = new Uint8Array(yield* response.arrayBuffer);
|
|
784
789
|
const name = dispositionName(response.headers["content-disposition"]);
|
|
785
790
|
if (body === "file") {
|
|
791
|
+
const declared = response.headers["content-type"] ?? null;
|
|
786
792
|
return yield* pipe(
|
|
787
|
-
Files.write({
|
|
788
|
-
bytes,
|
|
789
|
-
contentType: Option.getOrNull(Option.fromUndefinedOr(response.headers["content-type"])),
|
|
790
|
-
name: name ?? "file",
|
|
791
|
-
}),
|
|
793
|
+
Files.write({ bytes, contentType: fileContentType(bytes, declared), name: name ?? "file" }),
|
|
792
794
|
Effect.mapError(fileFailed),
|
|
793
795
|
);
|
|
794
796
|
}
|
package/src/remote-runtime.ts
CHANGED
|
@@ -244,6 +244,7 @@ const FileFailure = Schema.Struct({ message: Schema.String });
|
|
|
244
244
|
|
|
245
245
|
// The host's file routes do the reading and storing, as the caller the token names.
|
|
246
246
|
function filesService(access: FileAccess, http: HttpClient.HttpClient) {
|
|
247
|
+
let writes = 0;
|
|
247
248
|
const client = HttpClient.mapRequest(
|
|
248
249
|
http,
|
|
249
250
|
flow(
|
|
@@ -281,12 +282,16 @@ function filesService(access: FileAccess, http: HttpClient.HttpClient) {
|
|
|
281
282
|
Effect.map(response.arrayBuffer, buffer => new Uint8Array(buffer)),
|
|
282
283
|
),
|
|
283
284
|
write: file =>
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
285
|
+
Effect.suspend(() =>
|
|
286
|
+
call(
|
|
287
|
+
pipe(
|
|
288
|
+
HttpClientRequest.post("", {
|
|
289
|
+
urlParams: { name: file.name, writeIndex: `${writes++}` },
|
|
290
|
+
}),
|
|
291
|
+
HttpClientRequest.bodyUint8Array(file.bytes, file.contentType ?? undefined),
|
|
292
|
+
),
|
|
293
|
+
response => Effect.flatMap(response.json, Schema.decodeUnknownEffect(Files.File)),
|
|
288
294
|
),
|
|
289
|
-
response => Effect.flatMap(response.json, Schema.decodeUnknownEffect(Files.File)),
|
|
290
295
|
),
|
|
291
296
|
});
|
|
292
297
|
}
|