@livekit/agents-plugin-livekit 0.1.2 → 1.0.0-next.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.
Files changed (91) hide show
  1. package/dist/hf_utils.cjs +272 -0
  2. package/dist/hf_utils.cjs.map +1 -0
  3. package/dist/hf_utils.d.cts +40 -0
  4. package/dist/hf_utils.d.ts +40 -0
  5. package/dist/hf_utils.d.ts.map +1 -0
  6. package/dist/hf_utils.js +237 -0
  7. package/dist/hf_utils.js.map +1 -0
  8. package/dist/hf_utils.test.cjs +330 -0
  9. package/dist/hf_utils.test.cjs.map +1 -0
  10. package/dist/hf_utils.test.d.cts +2 -0
  11. package/dist/hf_utils.test.d.ts +2 -0
  12. package/dist/hf_utils.test.d.ts.map +1 -0
  13. package/dist/hf_utils.test.js +307 -0
  14. package/dist/hf_utils.test.js.map +1 -0
  15. package/dist/index.cjs +27 -10
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +2 -2
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +24 -6
  21. package/dist/index.js.map +1 -1
  22. package/dist/turn_detector/base.cjs +202 -0
  23. package/dist/turn_detector/base.cjs.map +1 -0
  24. package/dist/turn_detector/base.d.cts +52 -0
  25. package/dist/turn_detector/base.d.ts +52 -0
  26. package/dist/turn_detector/base.d.ts.map +1 -0
  27. package/dist/turn_detector/base.js +172 -0
  28. package/dist/turn_detector/base.js.map +1 -0
  29. package/dist/turn_detector/constants.cjs +44 -0
  30. package/dist/turn_detector/constants.cjs.map +1 -0
  31. package/dist/turn_detector/constants.d.cts +7 -0
  32. package/dist/turn_detector/constants.d.ts +7 -0
  33. package/dist/turn_detector/constants.d.ts.map +1 -0
  34. package/dist/turn_detector/constants.js +16 -0
  35. package/dist/turn_detector/constants.js.map +1 -0
  36. package/dist/turn_detector/english.cjs +52 -0
  37. package/dist/turn_detector/english.cjs.map +1 -0
  38. package/dist/turn_detector/english.d.cts +11 -0
  39. package/dist/turn_detector/english.d.ts +11 -0
  40. package/dist/turn_detector/english.d.ts.map +1 -0
  41. package/dist/turn_detector/english.js +26 -0
  42. package/dist/turn_detector/english.js.map +1 -0
  43. package/dist/turn_detector/index.cjs +53 -0
  44. package/dist/turn_detector/index.cjs.map +1 -0
  45. package/dist/turn_detector/index.d.cts +5 -0
  46. package/dist/turn_detector/index.d.ts +5 -0
  47. package/dist/turn_detector/index.d.ts.map +1 -0
  48. package/dist/turn_detector/index.js +23 -0
  49. package/dist/turn_detector/index.js.map +1 -0
  50. package/dist/turn_detector/multilingual.cjs +144 -0
  51. package/dist/turn_detector/multilingual.cjs.map +1 -0
  52. package/dist/turn_detector/multilingual.d.cts +15 -0
  53. package/dist/turn_detector/multilingual.d.ts +15 -0
  54. package/dist/turn_detector/multilingual.d.ts.map +1 -0
  55. package/dist/turn_detector/multilingual.js +118 -0
  56. package/dist/turn_detector/multilingual.js.map +1 -0
  57. package/dist/turn_detector/utils.cjs +54 -0
  58. package/dist/turn_detector/utils.cjs.map +1 -0
  59. package/dist/turn_detector/utils.d.cts +35 -0
  60. package/dist/turn_detector/utils.d.ts +35 -0
  61. package/dist/turn_detector/utils.d.ts.map +1 -0
  62. package/dist/turn_detector/utils.js +29 -0
  63. package/dist/turn_detector/utils.js.map +1 -0
  64. package/dist/turn_detector/utils.test.cjs +196 -0
  65. package/dist/turn_detector/utils.test.cjs.map +1 -0
  66. package/dist/turn_detector/utils.test.d.cts +2 -0
  67. package/dist/turn_detector/utils.test.d.ts +2 -0
  68. package/dist/turn_detector/utils.test.d.ts.map +1 -0
  69. package/dist/turn_detector/utils.test.js +195 -0
  70. package/dist/turn_detector/utils.test.js.map +1 -0
  71. package/package.json +7 -6
  72. package/src/hf_utils.test.ts +392 -0
  73. package/src/hf_utils.ts +365 -0
  74. package/src/index.ts +32 -9
  75. package/src/turn_detector/base.ts +238 -0
  76. package/src/turn_detector/constants.ts +16 -0
  77. package/src/turn_detector/english.ts +27 -0
  78. package/src/turn_detector/index.ts +21 -0
  79. package/src/turn_detector/multilingual.ts +145 -0
  80. package/src/turn_detector/utils.test.ts +231 -0
  81. package/src/turn_detector/utils.ts +76 -0
  82. package/dist/turn_detector.cjs +0 -129
  83. package/dist/turn_detector.cjs.map +0 -1
  84. package/dist/turn_detector.d.cts +0 -22
  85. package/dist/turn_detector.d.ts +0 -22
  86. package/dist/turn_detector.d.ts.map +0 -1
  87. package/dist/turn_detector.js +0 -102
  88. package/dist/turn_detector.js.map +0 -1
  89. package/dist/turn_detector.onnx +0 -0
  90. package/src/turn_detector.onnx +0 -0
  91. package/src/turn_detector.ts +0 -121
@@ -0,0 +1,307 @@
1
+ import { initializeLogger } from "@livekit/agents";
2
+ import { existsSync, rmSync, statSync } from "fs";
3
+ import { homedir } from "os";
4
+ import { join } from "path";
5
+ import { afterAll, beforeAll, describe, expect, it } from "vitest";
6
+ import { downloadFileToCacheDir } from "./hf_utils.js";
7
+ function getCachePath(repo, cacheDir) {
8
+ const baseCacheDir = cacheDir || join(homedir(), ".cache", "huggingface", "hub");
9
+ return join(baseCacheDir, `models--${repo.replace(/\//g, "--")}`);
10
+ }
11
+ function clearCache(repo, cacheDir) {
12
+ const repoPath = getCachePath(repo, cacheDir);
13
+ if (existsSync(repoPath)) {
14
+ rmSync(repoPath, { recursive: true, force: true });
15
+ }
16
+ }
17
+ describe("HuggingFace Download Fixed Implementation", () => {
18
+ initializeLogger({ pretty: true, level: "debug" });
19
+ const TEST_REPO = "livekit/turn-detector";
20
+ const TEST_CACHE_DIR = join(process.cwd(), ".test-cache");
21
+ beforeAll(() => {
22
+ clearCache(TEST_REPO, TEST_CACHE_DIR);
23
+ });
24
+ afterAll(() => {
25
+ if (existsSync(TEST_CACHE_DIR)) {
26
+ rmSync(TEST_CACHE_DIR, { recursive: true, force: true });
27
+ }
28
+ });
29
+ describe("Basic Downloads", () => {
30
+ it("should download a standard file in subdirectory", async () => {
31
+ const result = await downloadFileToCacheDir({
32
+ repo: TEST_REPO,
33
+ path: "onnx/model_q8.onnx",
34
+ revision: "v1.2.2-en",
35
+ cacheDir: TEST_CACHE_DIR
36
+ });
37
+ expect(result).toBeTruthy();
38
+ expect(existsSync(result)).toBe(true);
39
+ const stats = statSync(result);
40
+ const sizeMB = stats.size / 1024 / 1024;
41
+ expect(sizeMB).toBeCloseTo(62.67, 1);
42
+ });
43
+ it("should download a large file with retry logic", async () => {
44
+ const result = await downloadFileToCacheDir({
45
+ repo: TEST_REPO,
46
+ path: "onnx/model.onnx",
47
+ revision: "v1.2.2-en",
48
+ cacheDir: TEST_CACHE_DIR
49
+ });
50
+ expect(result).toBeTruthy();
51
+ expect(existsSync(result)).toBe(true);
52
+ const stats = statSync(result);
53
+ const sizeMB = stats.size / 1024 / 1024;
54
+ expect(sizeMB).toBeCloseTo(249.96, 1);
55
+ });
56
+ it("should download a very small file", async () => {
57
+ const result = await downloadFileToCacheDir({
58
+ repo: TEST_REPO,
59
+ path: "languages.json",
60
+ revision: "v1.2.2-en",
61
+ cacheDir: TEST_CACHE_DIR
62
+ });
63
+ expect(result).toBeTruthy();
64
+ expect(existsSync(result)).toBe(true);
65
+ const stats = statSync(result);
66
+ expect(stats.size).toBeLessThan(200);
67
+ });
68
+ it("should download from different revision", async () => {
69
+ const result = await downloadFileToCacheDir({
70
+ repo: TEST_REPO,
71
+ path: "tokenizer.json",
72
+ revision: "v0.2.0-intl",
73
+ cacheDir: TEST_CACHE_DIR
74
+ });
75
+ expect(result).toBeTruthy();
76
+ expect(existsSync(result)).toBe(true);
77
+ const stats = statSync(result);
78
+ const sizeMB = stats.size / 1024 / 1024;
79
+ expect(sizeMB).toBeGreaterThan(3);
80
+ });
81
+ });
82
+ describe("Cache Behavior", () => {
83
+ it("should use cache on second download", async () => {
84
+ const firstPath = await downloadFileToCacheDir({
85
+ repo: TEST_REPO,
86
+ path: "onnx/model_q8.onnx",
87
+ revision: "v1.2.2-en",
88
+ cacheDir: TEST_CACHE_DIR
89
+ });
90
+ const startTime = Date.now();
91
+ const secondPath = await downloadFileToCacheDir({
92
+ repo: TEST_REPO,
93
+ path: "onnx/model_q8.onnx",
94
+ revision: "v1.2.2-en",
95
+ cacheDir: TEST_CACHE_DIR
96
+ });
97
+ const cacheTime = Date.now() - startTime;
98
+ expect(secondPath).toBe(firstPath);
99
+ expect(cacheTime).toBeLessThan(500);
100
+ });
101
+ it("should respect localFileOnly flag when file is cached", async () => {
102
+ await downloadFileToCacheDir({
103
+ repo: TEST_REPO,
104
+ path: "tokenizer.json",
105
+ revision: "v0.2.0-intl",
106
+ cacheDir: TEST_CACHE_DIR
107
+ });
108
+ const cachedPath = await downloadFileToCacheDir({
109
+ repo: TEST_REPO,
110
+ path: "tokenizer.json",
111
+ revision: "v0.2.0-intl",
112
+ cacheDir: TEST_CACHE_DIR,
113
+ localFileOnly: true
114
+ });
115
+ expect(cachedPath).toBeTruthy();
116
+ expect(existsSync(cachedPath)).toBe(true);
117
+ });
118
+ it("should throw error with localFileOnly when file is not cached", async () => {
119
+ await expect(
120
+ downloadFileToCacheDir({
121
+ repo: TEST_REPO,
122
+ path: "non-existent-file.txt",
123
+ revision: "main",
124
+ cacheDir: TEST_CACHE_DIR,
125
+ localFileOnly: true
126
+ })
127
+ ).rejects.toThrow(/File not found in cache/);
128
+ });
129
+ it("should save revision-to-commit mappings", async () => {
130
+ await downloadFileToCacheDir({
131
+ repo: TEST_REPO,
132
+ path: "languages.json",
133
+ revision: "v1.2.2-en",
134
+ cacheDir: TEST_CACHE_DIR
135
+ });
136
+ const refsPath = join(getCachePath(TEST_REPO, TEST_CACHE_DIR), "refs", "v1.2.2-en");
137
+ expect(existsSync(refsPath)).toBe(true);
138
+ });
139
+ it("should handle multiple files from same revision without overwriting refs", async () => {
140
+ const file1Path = await downloadFileToCacheDir({
141
+ repo: TEST_REPO,
142
+ path: "onnx/model_q8.onnx",
143
+ revision: "v1.2.2-en",
144
+ cacheDir: TEST_CACHE_DIR
145
+ });
146
+ const file2Path = await downloadFileToCacheDir({
147
+ repo: TEST_REPO,
148
+ path: "languages.json",
149
+ revision: "v1.2.2-en",
150
+ cacheDir: TEST_CACHE_DIR
151
+ });
152
+ expect(existsSync(file1Path)).toBe(true);
153
+ expect(existsSync(file2Path)).toBe(true);
154
+ const cachedFile1 = await downloadFileToCacheDir({
155
+ repo: TEST_REPO,
156
+ path: "onnx/model_q8.onnx",
157
+ revision: "v1.2.2-en",
158
+ cacheDir: TEST_CACHE_DIR,
159
+ localFileOnly: true
160
+ });
161
+ const cachedFile2 = await downloadFileToCacheDir({
162
+ repo: TEST_REPO,
163
+ path: "languages.json",
164
+ revision: "v1.2.2-en",
165
+ cacheDir: TEST_CACHE_DIR,
166
+ localFileOnly: true
167
+ });
168
+ expect(cachedFile1).toBe(file1Path);
169
+ expect(cachedFile2).toBe(file2Path);
170
+ const match1 = file1Path.match(/snapshots\/([a-f0-9]{40})\//);
171
+ const match2 = file2Path.match(/snapshots\/([a-f0-9]{40})\//);
172
+ expect(match1).toBeTruthy();
173
+ expect(match2).toBeTruthy();
174
+ const commitHash1 = match1[1];
175
+ const commitHash2 = match2[1];
176
+ expect(commitHash1).toBe(commitHash2);
177
+ const { readFileSync } = await import("fs");
178
+ const refsPath = join(getCachePath(TEST_REPO, TEST_CACHE_DIR), "refs", "v1.2.2-en");
179
+ const refsContent = readFileSync(refsPath, "utf-8").trim();
180
+ expect(refsContent).toMatch(/^[a-f0-9]{40}$/);
181
+ expect(refsContent).toBe(commitHash1);
182
+ });
183
+ });
184
+ describe("Error Handling", () => {
185
+ it("should handle invalid repository gracefully", async () => {
186
+ await expect(
187
+ downloadFileToCacheDir({
188
+ repo: "non-existent-org/non-existent-repo",
189
+ path: "file.txt",
190
+ revision: "main",
191
+ cacheDir: TEST_CACHE_DIR
192
+ })
193
+ ).rejects.toThrow();
194
+ });
195
+ it("should handle invalid file path gracefully", async () => {
196
+ await expect(
197
+ downloadFileToCacheDir({
198
+ repo: TEST_REPO,
199
+ path: "non-existent-file-path.xyz",
200
+ revision: "v1.2.2-en",
201
+ cacheDir: TEST_CACHE_DIR
202
+ })
203
+ ).rejects.toThrow();
204
+ });
205
+ it("should handle invalid revision gracefully", async () => {
206
+ await expect(
207
+ downloadFileToCacheDir({
208
+ repo: TEST_REPO,
209
+ path: "tokenizer.json",
210
+ revision: "non-existent-revision",
211
+ cacheDir: TEST_CACHE_DIR
212
+ })
213
+ ).rejects.toThrow();
214
+ });
215
+ });
216
+ describe("Cache Structure", () => {
217
+ it("should create proper cache directory structure", async () => {
218
+ await downloadFileToCacheDir({
219
+ repo: TEST_REPO,
220
+ path: "onnx/model_q8.onnx",
221
+ revision: "v1.2.2-en",
222
+ cacheDir: TEST_CACHE_DIR
223
+ });
224
+ const cachePath = getCachePath(TEST_REPO, TEST_CACHE_DIR);
225
+ expect(existsSync(join(cachePath, "blobs"))).toBe(true);
226
+ expect(existsSync(join(cachePath, "snapshots"))).toBe(true);
227
+ expect(existsSync(join(cachePath, "refs"))).toBe(true);
228
+ });
229
+ it("should handle commit hash revisions", async () => {
230
+ const tagResult = await downloadFileToCacheDir({
231
+ repo: TEST_REPO,
232
+ path: "onnx/model_q8.onnx",
233
+ revision: "v1.2.2-en",
234
+ cacheDir: TEST_CACHE_DIR
235
+ });
236
+ const match = tagResult.match(/snapshots\/([a-f0-9]{40})\//);
237
+ expect(match).toBeTruthy();
238
+ const commitHash = match[1];
239
+ const result = await downloadFileToCacheDir({
240
+ repo: TEST_REPO,
241
+ path: "onnx/model_q8.onnx",
242
+ revision: commitHash,
243
+ cacheDir: TEST_CACHE_DIR
244
+ });
245
+ expect(result).toBeTruthy();
246
+ expect(result).toContain(commitHash);
247
+ });
248
+ it("should store files as content-addressed blobs", async () => {
249
+ await downloadFileToCacheDir({
250
+ repo: TEST_REPO,
251
+ path: "languages.json",
252
+ revision: "v1.2.2-en",
253
+ cacheDir: TEST_CACHE_DIR
254
+ });
255
+ const blobsPath = join(getCachePath(TEST_REPO, TEST_CACHE_DIR), "blobs");
256
+ const { readdirSync } = await import("fs");
257
+ const blobs = readdirSync(blobsPath);
258
+ expect(blobs.length).toBeGreaterThan(0);
259
+ expect(blobs[0]).toMatch(/^[a-f0-9]{64}$/);
260
+ });
261
+ });
262
+ describe("Performance", () => {
263
+ it("should download files in parallel efficiently", async () => {
264
+ const startTime = Date.now();
265
+ const promises = [
266
+ downloadFileToCacheDir({
267
+ repo: TEST_REPO,
268
+ path: "onnx/model_q8.onnx",
269
+ revision: "v1.2.2-en",
270
+ cacheDir: TEST_CACHE_DIR
271
+ }),
272
+ downloadFileToCacheDir({
273
+ repo: TEST_REPO,
274
+ path: "languages.json",
275
+ revision: "v1.2.2-en",
276
+ cacheDir: TEST_CACHE_DIR
277
+ }),
278
+ downloadFileToCacheDir({
279
+ repo: TEST_REPO,
280
+ path: "tokenizer.json",
281
+ revision: "v0.2.0-intl",
282
+ cacheDir: TEST_CACHE_DIR
283
+ })
284
+ ];
285
+ const results = await Promise.all(promises);
286
+ const totalTime = Date.now() - startTime;
287
+ results.forEach((result) => {
288
+ expect(result).toBeTruthy();
289
+ expect(existsSync(result)).toBe(true);
290
+ });
291
+ console.log(`Parallel download took ${totalTime}ms`);
292
+ });
293
+ });
294
+ describe("Failures", () => {
295
+ it("should handle non-existent file", async () => {
296
+ await expect(
297
+ downloadFileToCacheDir({
298
+ repo: TEST_REPO,
299
+ path: "onnx/model_non_existent.onnx",
300
+ revision: "v1.2.2-en",
301
+ cacheDir: TEST_CACHE_DIR
302
+ })
303
+ ).rejects.toThrow("cannot get path info for onnx/model_non_existent.onnx");
304
+ });
305
+ });
306
+ });
307
+ //# sourceMappingURL=hf_utils.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hf_utils.test.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { initializeLogger } from '@livekit/agents';\nimport { existsSync, rmSync, statSync } from 'fs';\nimport { homedir } from 'os';\nimport { join } from 'path';\nimport { afterAll, beforeAll, describe, expect, it } from 'vitest';\nimport { downloadFileToCacheDir } from './hf_utils.js';\n\nfunction getCachePath(repo: string, cacheDir?: string): string {\n const baseCacheDir = cacheDir || join(homedir(), '.cache', 'huggingface', 'hub');\n return join(baseCacheDir, `models--${repo.replace(/\\//g, '--')}`);\n}\n\nfunction clearCache(repo: string, cacheDir?: string): void {\n const repoPath = getCachePath(repo, cacheDir);\n if (existsSync(repoPath)) {\n rmSync(repoPath, { recursive: true, force: true });\n }\n}\n\ndescribe('HuggingFace Download Fixed Implementation', () => {\n initializeLogger({ pretty: true, level: 'debug' });\n\n const TEST_REPO = 'livekit/turn-detector';\n const TEST_CACHE_DIR = join(process.cwd(), '.test-cache');\n\n beforeAll(() => {\n // Clear test cache before all tests\n clearCache(TEST_REPO, TEST_CACHE_DIR);\n });\n\n afterAll(() => {\n // Clean up test cache after all tests\n if (existsSync(TEST_CACHE_DIR)) {\n rmSync(TEST_CACHE_DIR, { recursive: true, force: true });\n }\n });\n\n describe('Basic Downloads', () => {\n it('should download a standard file in subdirectory', async () => {\n const result = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'onnx/model_q8.onnx',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n });\n\n expect(result).toBeTruthy();\n expect(existsSync(result)).toBe(true);\n\n const stats = statSync(result);\n const sizeMB = stats.size / 1024 / 1024;\n expect(sizeMB).toBeCloseTo(62.67, 1); // ~62.67 MB\n });\n\n it('should download a large file with retry logic', async () => {\n const result = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'onnx/model.onnx',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n });\n\n expect(result).toBeTruthy();\n expect(existsSync(result)).toBe(true);\n\n const stats = statSync(result);\n const sizeMB = stats.size / 1024 / 1024;\n expect(sizeMB).toBeCloseTo(249.96, 1); // ~250 MB\n });\n\n it('should download a very small file', async () => {\n const result = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'languages.json',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n });\n\n expect(result).toBeTruthy();\n expect(existsSync(result)).toBe(true);\n\n const stats = statSync(result);\n expect(stats.size).toBeLessThan(200); // Very small file (102 bytes)\n });\n\n it('should download from different revision', async () => {\n const result = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'tokenizer.json',\n revision: 'v0.2.0-intl',\n cacheDir: TEST_CACHE_DIR,\n });\n\n expect(result).toBeTruthy();\n expect(existsSync(result)).toBe(true);\n\n const stats = statSync(result);\n const sizeMB = stats.size / 1024 / 1024;\n expect(sizeMB).toBeGreaterThan(3); // Should be around 3.36 MB or more\n });\n });\n\n describe('Cache Behavior', () => {\n it('should use cache on second download', async () => {\n // First download\n const firstPath = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'onnx/model_q8.onnx',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n });\n\n // Second download (should be from cache)\n const startTime = Date.now();\n const secondPath = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'onnx/model_q8.onnx',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n });\n const cacheTime = Date.now() - startTime;\n\n expect(secondPath).toBe(firstPath);\n expect(cacheTime).toBeLessThan(500); // Should be very fast if from cache\n });\n\n it('should respect localFileOnly flag when file is cached', async () => {\n // Ensure file is cached first\n await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'tokenizer.json',\n revision: 'v0.2.0-intl',\n cacheDir: TEST_CACHE_DIR,\n });\n\n // Now try with localFileOnly\n const cachedPath = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'tokenizer.json',\n revision: 'v0.2.0-intl',\n cacheDir: TEST_CACHE_DIR,\n localFileOnly: true,\n });\n\n expect(cachedPath).toBeTruthy();\n expect(existsSync(cachedPath)).toBe(true);\n });\n\n it('should throw error with localFileOnly when file is not cached', async () => {\n await expect(\n downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'non-existent-file.txt',\n revision: 'main',\n cacheDir: TEST_CACHE_DIR,\n localFileOnly: true,\n }),\n ).rejects.toThrow(/File not found in cache/);\n });\n\n it('should save revision-to-commit mappings', async () => {\n await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'languages.json',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n });\n\n // Check if refs file was created\n const refsPath = join(getCachePath(TEST_REPO, TEST_CACHE_DIR), 'refs', 'v1.2.2-en');\n expect(existsSync(refsPath)).toBe(true);\n });\n\n it('should handle multiple files from same revision without overwriting refs', async () => {\n // Download two different files from the same revision\n const file1Path = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'onnx/model_q8.onnx',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n });\n\n const file2Path = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'languages.json',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n });\n\n // Both files should exist\n expect(existsSync(file1Path)).toBe(true);\n expect(existsSync(file2Path)).toBe(true);\n\n // Now test that both files can be retrieved with localFileOnly\n const cachedFile1 = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'onnx/model_q8.onnx',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n localFileOnly: true,\n });\n\n const cachedFile2 = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'languages.json',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n localFileOnly: true,\n });\n\n // Both should be found in cache\n expect(cachedFile1).toBe(file1Path);\n expect(cachedFile2).toBe(file2Path);\n\n // Check that both files are in the same snapshot folder (same commit hash)\n // Extract commit hash from paths\n const match1 = file1Path.match(/snapshots\\/([a-f0-9]{40})\\//);\n const match2 = file2Path.match(/snapshots\\/([a-f0-9]{40})\\//);\n\n expect(match1).toBeTruthy();\n expect(match2).toBeTruthy();\n\n const commitHash1 = match1![1];\n const commitHash2 = match2![1];\n\n // FIXED: All files from the same revision should use the same HEAD commit\n expect(commitHash1).toBe(commitHash2);\n\n // Check that the refs file contains the single HEAD commit\n const { readFileSync } = await import('fs');\n const refsPath = join(getCachePath(TEST_REPO, TEST_CACHE_DIR), 'refs', 'v1.2.2-en');\n const refsContent = readFileSync(refsPath, 'utf-8').trim();\n\n // The refs file should contain just the commit hash, not a JSON mapping\n expect(refsContent).toMatch(/^[a-f0-9]{40}$/);\n expect(refsContent).toBe(commitHash1);\n });\n });\n\n describe('Error Handling', () => {\n it('should handle invalid repository gracefully', async () => {\n await expect(\n downloadFileToCacheDir({\n repo: 'non-existent-org/non-existent-repo',\n path: 'file.txt',\n revision: 'main',\n cacheDir: TEST_CACHE_DIR,\n }),\n ).rejects.toThrow();\n });\n\n it('should handle invalid file path gracefully', async () => {\n await expect(\n downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'non-existent-file-path.xyz',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n }),\n ).rejects.toThrow();\n });\n\n it('should handle invalid revision gracefully', async () => {\n await expect(\n downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'tokenizer.json',\n revision: 'non-existent-revision',\n cacheDir: TEST_CACHE_DIR,\n }),\n ).rejects.toThrow();\n });\n });\n\n describe('Cache Structure', () => {\n it('should create proper cache directory structure', async () => {\n await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'onnx/model_q8.onnx',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n });\n\n const cachePath = getCachePath(TEST_REPO, TEST_CACHE_DIR);\n\n // Check expected directories exist\n expect(existsSync(join(cachePath, 'blobs'))).toBe(true);\n expect(existsSync(join(cachePath, 'snapshots'))).toBe(true);\n expect(existsSync(join(cachePath, 'refs'))).toBe(true);\n });\n\n it('should handle commit hash revisions', async () => {\n // We'll use the actual commit hash from the v1.2.2-en tag\n // First, download to ensure we have the commit hash mapping\n const tagResult = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'onnx/model_q8.onnx',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n });\n\n // Extract the commit hash from the path\n const match = tagResult.match(/snapshots\\/([a-f0-9]{40})\\//);\n expect(match).toBeTruthy();\n const commitHash = match![1];\n\n // Now download with commit hash directly\n const result = await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'onnx/model_q8.onnx',\n revision: commitHash,\n cacheDir: TEST_CACHE_DIR,\n });\n\n expect(result).toBeTruthy();\n expect(result).toContain(commitHash);\n });\n\n it('should store files as content-addressed blobs', async () => {\n await downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'languages.json',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n });\n\n const blobsPath = join(getCachePath(TEST_REPO, TEST_CACHE_DIR), 'blobs');\n const { readdirSync } = await import('fs');\n const blobs = readdirSync(blobsPath);\n\n // Should have at least one blob with SHA256 hash name\n expect(blobs.length).toBeGreaterThan(0);\n expect(blobs[0]).toMatch(/^[a-f0-9]{64}$/);\n });\n });\n\n describe('Performance', () => {\n it('should download files in parallel efficiently', async () => {\n const startTime = Date.now();\n\n // Download multiple files in parallel\n const promises = [\n downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'onnx/model_q8.onnx',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n }),\n downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'languages.json',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n }),\n downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'tokenizer.json',\n revision: 'v0.2.0-intl',\n cacheDir: TEST_CACHE_DIR,\n }),\n ];\n\n const results = await Promise.all(promises);\n const totalTime = Date.now() - startTime;\n\n // All should succeed\n results.forEach((result) => {\n expect(result).toBeTruthy();\n expect(existsSync(result)).toBe(true);\n });\n\n // Should be faster than downloading sequentially\n console.log(`Parallel download took ${totalTime}ms`);\n });\n });\n\n describe('Failures', () => {\n it('should handle non-existent file', async () => {\n await expect(\n downloadFileToCacheDir({\n repo: TEST_REPO,\n path: 'onnx/model_non_existent.onnx',\n revision: 'v1.2.2-en',\n cacheDir: TEST_CACHE_DIR,\n }),\n ).rejects.toThrow('cannot get path info for onnx/model_non_existent.onnx');\n });\n });\n});\n"],"mappings":"AAGA,SAAS,wBAAwB;AACjC,SAAS,YAAY,QAAQ,gBAAgB;AAC7C,SAAS,eAAe;AACxB,SAAS,YAAY;AACrB,SAAS,UAAU,WAAW,UAAU,QAAQ,UAAU;AAC1D,SAAS,8BAA8B;AAEvC,SAAS,aAAa,MAAc,UAA2B;AAC7D,QAAM,eAAe,YAAY,KAAK,QAAQ,GAAG,UAAU,eAAe,KAAK;AAC/E,SAAO,KAAK,cAAc,WAAW,KAAK,QAAQ,OAAO,IAAI,CAAC,EAAE;AAClE;AAEA,SAAS,WAAW,MAAc,UAAyB;AACzD,QAAM,WAAW,aAAa,MAAM,QAAQ;AAC5C,MAAI,WAAW,QAAQ,GAAG;AACxB,WAAO,UAAU,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,EACnD;AACF;AAEA,SAAS,6CAA6C,MAAM;AAC1D,mBAAiB,EAAE,QAAQ,MAAM,OAAO,QAAQ,CAAC;AAEjD,QAAM,YAAY;AAClB,QAAM,iBAAiB,KAAK,QAAQ,IAAI,GAAG,aAAa;AAExD,YAAU,MAAM;AAEd,eAAW,WAAW,cAAc;AAAA,EACtC,CAAC;AAED,WAAS,MAAM;AAEb,QAAI,WAAW,cAAc,GAAG;AAC9B,aAAO,gBAAgB,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,IACzD;AAAA,EACF,CAAC;AAED,WAAS,mBAAmB,MAAM;AAChC,OAAG,mDAAmD,YAAY;AAChE,YAAM,SAAS,MAAM,uBAAuB;AAAA,QAC1C,MAAM;AAAA,QACN,MAAM;AAAA,QACN,UAAU;AAAA,QACV,UAAU;AAAA,MACZ,CAAC;AAED,aAAO,MAAM,EAAE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I,IAAI;AAG/B,cAAQ,QAAQ,CAAC,WAAW;AAC1B,eAAO,MAAM,EAAE,WAAW;AAC1B,eAAO,WAAW,MAAM,CAAC,EAAE,KAAK,IAAI;AAAA,MACtC,CAAC;AAGD,cAAQ,IAAI,0BAA0B,SAAS,IAAI;AAAA,IACrD,CAAC;AAAA,EACH,CAAC;AAED,WAAS,YAAY,MAAM;AACzB,OAAG,mCAAmC,YAAY;AAChD,YAAM;AAAA,QACJ,uBAAuB;AAAA,UACrB,MAAM;AAAA,UACN,MAAM;AAAA,UACN,UAAU;AAAA,UACV,UAAU;AAAA,QACZ,CAAC;AAAA,MACH,EAAE,QAAQ,QAAQ,uDAAuD;AAAA,IAC3E,CAAC;AAAA,EACH,CAAC;AACH,CAAC;","names":[]}
package/dist/index.cjs CHANGED
@@ -26,21 +26,38 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var src_exports = {};
30
- __export(src_exports, {
29
+ var index_exports = {};
30
+ __export(index_exports, {
31
+ downloadFileToCacheDir: () => import_hf_utils2.downloadFileToCacheDir,
31
32
  turnDetector: () => turnDetector
32
33
  });
33
- module.exports = __toCommonJS(src_exports);
34
- var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
35
- var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
34
+ module.exports = __toCommonJS(index_exports);
36
35
  var import_agents = require("@livekit/agents");
37
- var turnDetector = __toESM(require("./turn_detector.cjs"), 1);
38
- import_agents.InferenceRunner.registerRunner(
39
- turnDetector.EOURunner.INFERENCE_METHOD,
40
- new URL("./turn_detector.js", importMetaUrl).toString()
41
- );
36
+ var import_hf_utils = require("./hf_utils.cjs");
37
+ var import_constants = require("./turn_detector/constants.cjs");
38
+ var import_hf_utils2 = require("./hf_utils.cjs");
39
+ var turnDetector = __toESM(require("./turn_detector/index.cjs"), 1);
40
+ class EOUPlugin extends import_agents.Plugin {
41
+ constructor() {
42
+ super({
43
+ title: "turn-detector",
44
+ version: "0.1.1",
45
+ package: "@livekit/agents-plugin-livekit"
46
+ });
47
+ }
48
+ async downloadFiles() {
49
+ const { AutoTokenizer } = await import("@huggingface/transformers");
50
+ for (const revision of Object.values(import_constants.MODEL_REVISIONS)) {
51
+ await AutoTokenizer.from_pretrained(import_constants.HG_MODEL_REPO, { revision });
52
+ await (0, import_hf_utils.downloadFileToCacheDir)({ repo: import_constants.HG_MODEL_REPO, path: import_constants.ONNX_FILEPATH, revision });
53
+ await (0, import_hf_utils.downloadFileToCacheDir)({ repo: import_constants.HG_MODEL_REPO, path: "languages.json", revision });
54
+ }
55
+ }
56
+ }
57
+ import_agents.Plugin.registerPlugin(new EOUPlugin());
42
58
  // Annotate the CommonJS export names for ESM import in node:
43
59
  0 && (module.exports = {
60
+ downloadFileToCacheDir,
44
61
  turnDetector
45
62
  });
46
63
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../../../node_modules/.pnpm/tsup@8.3.5_@microsoft+api-extractor@7.43.7_@types+node@22.5.5__postcss@8.4.38_tsx@4.19.2_typescript@5.4.5/node_modules/tsup/assets/cjs_shims.js"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { InferenceRunner } from '@livekit/agents';\nimport * as turnDetector from './turn_detector.js';\n\nInferenceRunner.registerRunner(\n turnDetector.EOURunner.INFERENCE_METHOD,\n new URL('./turn_detector.js', import.meta.url).toString(),\n);\nexport { turnDetector };\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,OAClD,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEpC,IAAM,gBAAgC,iCAAiB;ADR9D,oBAAgC;AAChC,mBAA8B;AAE9B,8BAAgB;AAAA,EACd,aAAa,UAAU;AAAA,EACvB,IAAI,IAAI,sBAAsB,aAAe,EAAE,SAAS;AAC1D;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Plugin } from '@livekit/agents';\nimport { downloadFileToCacheDir as hfDownload } from './hf_utils.js';\nimport { HG_MODEL_REPO, MODEL_REVISIONS, ONNX_FILEPATH } from './turn_detector/constants.js';\n\nexport { downloadFileToCacheDir } from './hf_utils.js';\nexport * as turnDetector from './turn_detector/index.js';\n\nclass EOUPlugin extends Plugin {\n constructor() {\n super({\n title: 'turn-detector',\n version: '0.1.1',\n package: '@livekit/agents-plugin-livekit',\n });\n }\n\n async downloadFiles(): Promise<void> {\n const { AutoTokenizer } = await import('@huggingface/transformers');\n\n for (const revision of Object.values(MODEL_REVISIONS)) {\n // Ensure tokenizer is cached\n await AutoTokenizer.from_pretrained(HG_MODEL_REPO, { revision });\n\n // Ensure ONNX model and language data are cached\n await hfDownload({ repo: HG_MODEL_REPO, path: ONNX_FILEPATH, revision });\n await hfDownload({ repo: HG_MODEL_REPO, path: 'languages.json', revision });\n }\n }\n}\n\nPlugin.registerPlugin(new EOUPlugin());\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAuB;AACvB,sBAAqD;AACrD,uBAA8D;AAE9D,IAAAA,mBAAuC;AACvC,mBAA8B;AAE9B,MAAM,kBAAkB,qBAAO;AAAA,EAC7B,cAAc;AACZ,UAAM;AAAA,MACJ,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,gBAA+B;AACnC,UAAM,EAAE,cAAc,IAAI,MAAM,OAAO,2BAA2B;AAElE,eAAW,YAAY,OAAO,OAAO,gCAAe,GAAG;AAErD,YAAM,cAAc,gBAAgB,gCAAe,EAAE,SAAS,CAAC;AAG/D,gBAAM,gBAAAC,wBAAW,EAAE,MAAM,gCAAe,MAAM,gCAAe,SAAS,CAAC;AACvE,gBAAM,gBAAAA,wBAAW,EAAE,MAAM,gCAAe,MAAM,kBAAkB,SAAS,CAAC;AAAA,IAC5E;AAAA,EACF;AACF;AAEA,qBAAO,eAAe,IAAI,UAAU,CAAC;","names":["import_hf_utils","hfDownload"]}
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import * as turnDetector from './turn_detector.js';
2
- export { turnDetector };
1
+ export { downloadFileToCacheDir } from './hf_utils.js';
2
+ export * as turnDetector from './turn_detector/index.js';
3
3
  //# sourceMappingURL=index.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import * as turnDetector from './turn_detector.js';
2
- export { turnDetector };
1
+ export { downloadFileToCacheDir } from './hf_utils.js';
2
+ export * as turnDetector from './turn_detector/index.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AAMnD,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,YAAY,MAAM,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -1,10 +1,28 @@
1
- import { InferenceRunner } from "@livekit/agents";
2
- import * as turnDetector from "./turn_detector.js";
3
- InferenceRunner.registerRunner(
4
- turnDetector.EOURunner.INFERENCE_METHOD,
5
- new URL("./turn_detector.js", import.meta.url).toString()
6
- );
1
+ import { Plugin } from "@livekit/agents";
2
+ import { downloadFileToCacheDir as hfDownload } from "./hf_utils.js";
3
+ import { HG_MODEL_REPO, MODEL_REVISIONS, ONNX_FILEPATH } from "./turn_detector/constants.js";
4
+ import { downloadFileToCacheDir } from "./hf_utils.js";
5
+ import * as turnDetector from "./turn_detector/index.js";
6
+ class EOUPlugin extends Plugin {
7
+ constructor() {
8
+ super({
9
+ title: "turn-detector",
10
+ version: "0.1.1",
11
+ package: "@livekit/agents-plugin-livekit"
12
+ });
13
+ }
14
+ async downloadFiles() {
15
+ const { AutoTokenizer } = await import("@huggingface/transformers");
16
+ for (const revision of Object.values(MODEL_REVISIONS)) {
17
+ await AutoTokenizer.from_pretrained(HG_MODEL_REPO, { revision });
18
+ await hfDownload({ repo: HG_MODEL_REPO, path: ONNX_FILEPATH, revision });
19
+ await hfDownload({ repo: HG_MODEL_REPO, path: "languages.json", revision });
20
+ }
21
+ }
22
+ }
23
+ Plugin.registerPlugin(new EOUPlugin());
7
24
  export {
25
+ downloadFileToCacheDir,
8
26
  turnDetector
9
27
  };
10
28
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { InferenceRunner } from '@livekit/agents';\nimport * as turnDetector from './turn_detector.js';\n\nInferenceRunner.registerRunner(\n turnDetector.EOURunner.INFERENCE_METHOD,\n new URL('./turn_detector.js', import.meta.url).toString(),\n);\nexport { turnDetector };\n"],"mappings":"AAGA,SAAS,uBAAuB;AAChC,YAAY,kBAAkB;AAE9B,gBAAgB;AAAA,EACd,aAAa,UAAU;AAAA,EACvB,IAAI,IAAI,sBAAsB,YAAY,GAAG,EAAE,SAAS;AAC1D;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Plugin } from '@livekit/agents';\nimport { downloadFileToCacheDir as hfDownload } from './hf_utils.js';\nimport { HG_MODEL_REPO, MODEL_REVISIONS, ONNX_FILEPATH } from './turn_detector/constants.js';\n\nexport { downloadFileToCacheDir } from './hf_utils.js';\nexport * as turnDetector from './turn_detector/index.js';\n\nclass EOUPlugin extends Plugin {\n constructor() {\n super({\n title: 'turn-detector',\n version: '0.1.1',\n package: '@livekit/agents-plugin-livekit',\n });\n }\n\n async downloadFiles(): Promise<void> {\n const { AutoTokenizer } = await import('@huggingface/transformers');\n\n for (const revision of Object.values(MODEL_REVISIONS)) {\n // Ensure tokenizer is cached\n await AutoTokenizer.from_pretrained(HG_MODEL_REPO, { revision });\n\n // Ensure ONNX model and language data are cached\n await hfDownload({ repo: HG_MODEL_REPO, path: ONNX_FILEPATH, revision });\n await hfDownload({ repo: HG_MODEL_REPO, path: 'languages.json', revision });\n }\n }\n}\n\nPlugin.registerPlugin(new EOUPlugin());\n"],"mappings":"AAGA,SAAS,cAAc;AACvB,SAAS,0BAA0B,kBAAkB;AACrD,SAAS,eAAe,iBAAiB,qBAAqB;AAE9D,SAAS,8BAA8B;AACvC,YAAY,kBAAkB;AAE9B,MAAM,kBAAkB,OAAO;AAAA,EAC7B,cAAc;AACZ,UAAM;AAAA,MACJ,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,gBAA+B;AACnC,UAAM,EAAE,cAAc,IAAI,MAAM,OAAO,2BAA2B;AAElE,eAAW,YAAY,OAAO,OAAO,eAAe,GAAG;AAErD,YAAM,cAAc,gBAAgB,eAAe,EAAE,SAAS,CAAC;AAG/D,YAAM,WAAW,EAAE,MAAM,eAAe,MAAM,eAAe,SAAS,CAAC;AACvE,YAAM,WAAW,EAAE,MAAM,eAAe,MAAM,kBAAkB,SAAS,CAAC;AAAA,IAC5E;AAAA,EACF;AACF;AAEA,OAAO,eAAe,IAAI,UAAU,CAAC;","names":[]}