nsarrazin HF Staff commited on
Commit
dd4a8d9
·
1 Parent(s): d54ccf7

fix(tools): better parse MIME types in tool outputs

Browse files
package-lock.json CHANGED
@@ -24,7 +24,7 @@
24
  "date-fns": "^2.29.3",
25
  "dotenv": "^16.0.3",
26
  "express": "^4.19.2",
27
- "file-type": "^19.0.0",
28
  "google-auth-library": "^9.13.0",
29
  "handlebars": "^4.7.8",
30
  "highlight.js": "^11.7.0",
@@ -7438,13 +7438,13 @@
7438
  }
7439
  },
7440
  "node_modules/file-type": {
7441
- "version": "19.4.0",
7442
- "resolved": "https://registry.npmjs.org/file-type/-/file-type-19.4.0.tgz",
7443
- "integrity": "sha512-7N7Pu0UzVYV8YP6WXhN+kcvtp/P00eWKVo76nMAK+RasRO/ICzuJzjoG+aSLqbY6khDAFQuqsyImGaSdkm49Iw==",
7444
  "license": "MIT",
7445
  "dependencies": {
7446
  "get-stream": "^9.0.1",
7447
- "strtok3": "^8.0.0",
7448
  "token-types": "^6.0.0",
7449
  "uint8array-extras": "^1.3.0"
7450
  },
@@ -12267,9 +12267,9 @@
12267
  "license": "MIT"
12268
  },
12269
  "node_modules/strtok3": {
12270
- "version": "8.0.5",
12271
- "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-8.0.5.tgz",
12272
- "integrity": "sha512-yybH4XOcYsQLSiPCRSqCdC6Nz6mtceq84y1RtBPfPSM2yKjeQKQDZGvQ2JwcT9jlCX1Eb5Gu0OqRhCfhOFhRvQ==",
12273
  "license": "MIT",
12274
  "dependencies": {
12275
  "@tokenizer/token": "^0.3.0",
 
24
  "date-fns": "^2.29.3",
25
  "dotenv": "^16.0.3",
26
  "express": "^4.19.2",
27
+ "file-type": "^19.4.1",
28
  "google-auth-library": "^9.13.0",
29
  "handlebars": "^4.7.8",
30
  "highlight.js": "^11.7.0",
 
7438
  }
7439
  },
7440
  "node_modules/file-type": {
7441
+ "version": "19.4.1",
7442
+ "resolved": "https://registry.npmjs.org/file-type/-/file-type-19.4.1.tgz",
7443
+ "integrity": "sha512-RuWzwF2L9tCHS76KR/Mdh+DwJZcFCzrhrPXpOw6MlEfl/o31fjpTikzcKlYuyeV7e7ftdCGVJTNOCzkYD/aLbw==",
7444
  "license": "MIT",
7445
  "dependencies": {
7446
  "get-stream": "^9.0.1",
7447
+ "strtok3": "^8.1.0",
7448
  "token-types": "^6.0.0",
7449
  "uint8array-extras": "^1.3.0"
7450
  },
 
12267
  "license": "MIT"
12268
  },
12269
  "node_modules/strtok3": {
12270
+ "version": "8.1.0",
12271
+ "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-8.1.0.tgz",
12272
+ "integrity": "sha512-ExzDvHYPj6F6QkSNe/JxSlBxTh3OrI6wrAIz53ulxo1c4hBJ1bT9C/JrAthEKHWG9riVH3Xzg7B03Oxty6S2Lw==",
12273
  "license": "MIT",
12274
  "dependencies": {
12275
  "@tokenizer/token": "^0.3.0",
package.json CHANGED
@@ -68,13 +68,13 @@
68
  "@playwright/browser-chromium": "^1.43.1",
69
  "@resvg/resvg-js": "^2.6.2",
70
  "autoprefixer": "^10.4.14",
71
- "aws4": "^1.13.0",
72
  "aws-sigv4-fetch": "^4.0.1",
 
73
  "browser-image-resizer": "^2.4.1",
74
  "date-fns": "^2.29.3",
75
  "dotenv": "^16.0.3",
76
  "express": "^4.19.2",
77
- "file-type": "^19.0.0",
78
  "google-auth-library": "^9.13.0",
79
  "handlebars": "^4.7.8",
80
  "highlight.js": "^11.7.0",
 
68
  "@playwright/browser-chromium": "^1.43.1",
69
  "@resvg/resvg-js": "^2.6.2",
70
  "autoprefixer": "^10.4.14",
 
71
  "aws-sigv4-fetch": "^4.0.1",
72
+ "aws4": "^1.13.0",
73
  "browser-image-resizer": "^2.4.1",
74
  "date-fns": "^2.29.3",
75
  "dotenv": "^16.0.3",
76
  "express": "^4.19.2",
77
+ "file-type": "^19.4.1",
78
  "google-auth-library": "^9.13.0",
79
  "handlebars": "^4.7.8",
80
  "highlight.js": "^11.7.0",
src/lib/server/tools/index.ts CHANGED
@@ -26,6 +26,7 @@ import { sha256 } from "$lib/utils/sha256";
26
  import { ObjectId } from "mongodb";
27
  import { isValidOutputComponent, ToolOutputPaths } from "./outputs";
28
  import { downloadFile } from "../files/downloadFile";
 
29
 
30
  export type BackendToolContext = Pick<
31
  TextGenerationContext,
@@ -253,13 +254,13 @@ export function getCallMethod(tool: Omit<BaseTool, "call">): BackendCall {
253
  await fetch(output)
254
  .then((res) => res.blob())
255
  .then(async (blob) => {
256
- const mimeType = blob.type;
257
- const fileType = blob.type.split("/")[1] ?? mimeType?.split("/")[1];
258
  return new File(
259
  [blob],
260
- `${idx}-${await sha256(JSON.stringify(params))}.${fileType}`,
261
  {
262
- type: fileType,
263
  }
264
  );
265
  })
 
26
  import { ObjectId } from "mongodb";
27
  import { isValidOutputComponent, ToolOutputPaths } from "./outputs";
28
  import { downloadFile } from "../files/downloadFile";
29
+ import { fileTypeFromBlob } from "file-type";
30
 
31
  export type BackendToolContext = Pick<
32
  TextGenerationContext,
 
254
  await fetch(output)
255
  .then((res) => res.blob())
256
  .then(async (blob) => {
257
+ const { ext, mime } = (await fileTypeFromBlob(blob)) ?? { ext: "octet-stream" };
258
+
259
  return new File(
260
  [blob],
261
+ `${idx}-${await sha256(JSON.stringify(params))}.${ext}`,
262
  {
263
+ type: mime,
264
  }
265
  );
266
  })