@copilotkit/shared 2.0.0-rc.25 → 2.0.0-rc.27

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/package.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  //#region package.json
3
- var version = "2.0.0-rc.25";
3
+ var version = "2.0.0-rc.27";
4
4
 
5
5
  //#endregion
6
6
  Object.defineProperty(exports, 'version', {
package/dist/package.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.0.0-rc.25";
2
+ var version = "2.0.0-rc.27";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotkit/shared",
3
- "version": "2.0.0-rc.25",
3
+ "version": "2.0.0-rc.27",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "ai",
@@ -4,6 +4,7 @@ import {
4
4
  exceedsMaxSize,
5
5
  matchesAcceptFilter,
6
6
  getSourceUrl,
7
+ generateVideoThumbnail,
7
8
  } from "../utils";
8
9
 
9
10
  // ---------------------------------------------------------------------------
@@ -212,3 +213,24 @@ describe("getSourceUrl", () => {
212
213
  expect(getSourceUrl({ type: "file", value: "file-abc123" })).toBe("");
213
214
  });
214
215
  });
216
+
217
+ // ---------------------------------------------------------------------------
218
+ // generateVideoThumbnail
219
+ // ---------------------------------------------------------------------------
220
+
221
+ describe("generateVideoThumbnail", () => {
222
+ afterEach(() => {
223
+ vi.unstubAllGlobals();
224
+ });
225
+
226
+ it("returns undefined for a file that is not a Blob, such as a React Native file", async () => {
227
+ vi.stubGlobal("document", { createElement: () => ({}) });
228
+ const nativeVideo = {
229
+ name: "clip.mp4",
230
+ size: 1,
231
+ type: "video/mp4",
232
+ } as unknown as File;
233
+
234
+ await expect(generateVideoThumbnail(nativeVideo)).resolves.toBeUndefined();
235
+ });
236
+ });
@@ -54,19 +54,37 @@ export function readFileAsBase64(file: File): Promise<string> {
54
54
 
55
55
  /**
56
56
  * Generate a thumbnail data URL from a video file by capturing a frame near the start (at 0.1s).
57
- * Returns undefined if thumbnail generation fails or if called outside a browser environment.
57
+ * Returns undefined if thumbnail generation fails, if called outside a browser environment,
58
+ * or if `file` is not a `Blob` the browser can read (React Native for web passes a
59
+ * native file's description). Never rejects.
58
60
  */
59
61
  export function generateVideoThumbnail(
60
62
  file: File,
61
63
  ): Promise<string | undefined> {
62
- if (typeof document === "undefined") {
64
+ if (
65
+ typeof document === "undefined" ||
66
+ typeof Blob === "undefined" ||
67
+ !(file instanceof Blob)
68
+ ) {
63
69
  return Promise.resolve(undefined);
64
70
  }
65
71
  return new Promise((resolve) => {
66
72
  let resolved = false;
67
- const video = document.createElement("video");
68
- const canvas = document.createElement("canvas");
69
- const url = URL.createObjectURL(file);
73
+ let url: string;
74
+ let video: HTMLVideoElement;
75
+ let canvas: HTMLCanvasElement;
76
+ try {
77
+ video = document.createElement("video");
78
+ canvas = document.createElement("canvas");
79
+ url = URL.createObjectURL(file);
80
+ } catch (error) {
81
+ console.warn(
82
+ `[CopilotKit] generateVideoThumbnail: could not read file "${file.name}"`,
83
+ error,
84
+ );
85
+ resolve(undefined);
86
+ return;
87
+ }
70
88
 
71
89
  const cleanup = (result: string | undefined) => {
72
90
  if (resolved) return;