@copilotkit/shared 2.0.0-rc.26 → 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/attachments/utils.cjs +16 -5
- package/dist/attachments/utils.cjs.map +1 -1
- package/dist/attachments/utils.d.cts +3 -1
- package/dist/attachments/utils.d.cts.map +1 -1
- package/dist/attachments/utils.d.mts +3 -1
- package/dist/attachments/utils.d.mts.map +1 -1
- package/dist/attachments/utils.mjs +16 -5
- package/dist/attachments/utils.mjs.map +1 -1
- package/dist/index.umd.js +17 -6
- package/dist/index.umd.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +1 -1
- package/src/attachments/__tests__/utils.test.ts +22 -0
- package/src/attachments/utils.ts +23 -5
package/dist/package.cjs
CHANGED
package/dist/package.mjs
CHANGED
package/package.json
CHANGED
|
@@ -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
|
+
});
|
package/src/attachments/utils.ts
CHANGED
|
@@ -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
|
|
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 (
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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;
|