@livekit/agents-plugin-livekit 0.0.0-next-20260624041820
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/LICENSE +201 -0
- package/README.md +17 -0
- package/dist/hf_utils.cjs +272 -0
- package/dist/hf_utils.cjs.map +1 -0
- package/dist/hf_utils.d.cts +40 -0
- package/dist/hf_utils.d.ts +40 -0
- package/dist/hf_utils.d.ts.map +1 -0
- package/dist/hf_utils.js +237 -0
- package/dist/hf_utils.js.map +1 -0
- package/dist/hf_utils.test.cjs +330 -0
- package/dist/hf_utils.test.cjs.map +1 -0
- package/dist/hf_utils.test.d.cts +2 -0
- package/dist/hf_utils.test.d.ts +2 -0
- package/dist/hf_utils.test.d.ts.map +1 -0
- package/dist/hf_utils.test.js +307 -0
- package/dist/hf_utils.test.js.map +1 -0
- package/dist/index.cjs +63 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/onnxruntime.d.cjs +2 -0
- package/dist/onnxruntime.d.cjs.map +1 -0
- package/dist/onnxruntime.d.js +1 -0
- package/dist/onnxruntime.d.js.map +1 -0
- package/dist/turn_detector/base.cjs +228 -0
- package/dist/turn_detector/base.cjs.map +1 -0
- package/dist/turn_detector/base.d.cts +54 -0
- package/dist/turn_detector/base.d.ts +54 -0
- package/dist/turn_detector/base.d.ts.map +1 -0
- package/dist/turn_detector/base.js +198 -0
- package/dist/turn_detector/base.js.map +1 -0
- package/dist/turn_detector/constants.cjs +44 -0
- package/dist/turn_detector/constants.cjs.map +1 -0
- package/dist/turn_detector/constants.d.cts +7 -0
- package/dist/turn_detector/constants.d.ts +7 -0
- package/dist/turn_detector/constants.d.ts.map +1 -0
- package/dist/turn_detector/constants.js +16 -0
- package/dist/turn_detector/constants.js.map +1 -0
- package/dist/turn_detector/english.cjs +52 -0
- package/dist/turn_detector/english.cjs.map +1 -0
- package/dist/turn_detector/english.d.cts +11 -0
- package/dist/turn_detector/english.d.ts +11 -0
- package/dist/turn_detector/english.d.ts.map +1 -0
- package/dist/turn_detector/english.js +26 -0
- package/dist/turn_detector/english.js.map +1 -0
- package/dist/turn_detector/index.cjs +58 -0
- package/dist/turn_detector/index.cjs.map +1 -0
- package/dist/turn_detector/index.d.cts +5 -0
- package/dist/turn_detector/index.d.ts +5 -0
- package/dist/turn_detector/index.d.ts.map +1 -0
- package/dist/turn_detector/index.js +28 -0
- package/dist/turn_detector/index.js.map +1 -0
- package/dist/turn_detector/multilingual.cjs +145 -0
- package/dist/turn_detector/multilingual.cjs.map +1 -0
- package/dist/turn_detector/multilingual.d.cts +15 -0
- package/dist/turn_detector/multilingual.d.ts +15 -0
- package/dist/turn_detector/multilingual.d.ts.map +1 -0
- package/dist/turn_detector/multilingual.js +119 -0
- package/dist/turn_detector/multilingual.js.map +1 -0
- package/dist/turn_detector/utils.cjs +54 -0
- package/dist/turn_detector/utils.cjs.map +1 -0
- package/dist/turn_detector/utils.d.cts +35 -0
- package/dist/turn_detector/utils.d.ts +35 -0
- package/dist/turn_detector/utils.d.ts.map +1 -0
- package/dist/turn_detector/utils.js +29 -0
- package/dist/turn_detector/utils.js.map +1 -0
- package/dist/turn_detector/utils.test.cjs +196 -0
- package/dist/turn_detector/utils.test.cjs.map +1 -0
- package/dist/turn_detector/utils.test.d.cts +2 -0
- package/dist/turn_detector/utils.test.d.ts +2 -0
- package/dist/turn_detector/utils.test.d.ts.map +1 -0
- package/dist/turn_detector/utils.test.js +195 -0
- package/dist/turn_detector/utils.test.js.map +1 -0
- package/package.json +51 -0
- package/src/hf_utils.test.ts +392 -0
- package/src/hf_utils.ts +365 -0
- package/src/index.ts +34 -0
- package/src/onnxruntime.d.ts +8 -0
- package/src/turn_detector/base.ts +268 -0
- package/src/turn_detector/constants.ts +16 -0
- package/src/turn_detector/english.ts +27 -0
- package/src/turn_detector/index.ts +31 -0
- package/src/turn_detector/multilingual.ts +147 -0
- package/src/turn_detector/utils.test.ts +231 -0
- package/src/turn_detector/utils.ts +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
3
|
+
|
|
4
|
+
SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
-->
|
|
6
|
+
# Additional utilities for LiveKit Agents
|
|
7
|
+
|
|
8
|
+
The Agents Framework is designed for building realtime, programmable
|
|
9
|
+
participants that run on servers. Use it to create conversational, multi-modal
|
|
10
|
+
voice agents that can see, hear, and understand.
|
|
11
|
+
|
|
12
|
+
This package contains additional utilities provided by LiveKit.
|
|
13
|
+
Refer to the [documentation](https://docs.livekit.io/agents/overview/) for
|
|
14
|
+
information on how to use it, or browse the [API
|
|
15
|
+
reference](https://docs.livekit.io/agents-js/modules/plugins_agents_plugin_livekit.html).
|
|
16
|
+
See the [repository](https://github.com/livekit/agents-js) for more information
|
|
17
|
+
about the framework as a whole.
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var hf_utils_exports = {};
|
|
30
|
+
__export(hf_utils_exports, {
|
|
31
|
+
REGEX_COMMIT_HASH: () => REGEX_COMMIT_HASH,
|
|
32
|
+
downloadFileToCacheDir: () => downloadFileToCacheDir
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(hf_utils_exports);
|
|
35
|
+
var import_hub = require("@huggingface/hub");
|
|
36
|
+
var import_agents = require("@livekit/agents");
|
|
37
|
+
var import_node_fs = require("node:fs");
|
|
38
|
+
var import_promises = require("node:fs/promises");
|
|
39
|
+
var import_node_os = require("node:os");
|
|
40
|
+
var import_node_path = require("node:path");
|
|
41
|
+
var import_node_stream = require("node:stream");
|
|
42
|
+
var import_promises2 = require("node:stream/promises");
|
|
43
|
+
const REGEX_COMMIT_HASH = new RegExp("^[0-9a-f]{40}$");
|
|
44
|
+
function getHFHubCachePath(customCacheDir) {
|
|
45
|
+
return customCacheDir || (0, import_node_path.join)((0, import_node_os.homedir)(), ".cache", "huggingface", "hub");
|
|
46
|
+
}
|
|
47
|
+
function getRepoFolderName(repoId) {
|
|
48
|
+
return `models--${repoId.replace(/\//g, "--")}`;
|
|
49
|
+
}
|
|
50
|
+
function toRepoId(repo) {
|
|
51
|
+
if (typeof repo === "string") {
|
|
52
|
+
return repo;
|
|
53
|
+
}
|
|
54
|
+
return `${repo.name}`;
|
|
55
|
+
}
|
|
56
|
+
async function getBranchHeadCommit(repo, revision, params) {
|
|
57
|
+
const logger = (0, import_agents.log)();
|
|
58
|
+
try {
|
|
59
|
+
if (REGEX_COMMIT_HASH.test(revision)) {
|
|
60
|
+
return revision;
|
|
61
|
+
}
|
|
62
|
+
for await (const commit of (0, import_hub.listCommits)({
|
|
63
|
+
repo,
|
|
64
|
+
revision,
|
|
65
|
+
...params
|
|
66
|
+
})) {
|
|
67
|
+
const commitHash = commit.oid || commit.id || commit.commitId;
|
|
68
|
+
if (commitHash) {
|
|
69
|
+
return commitHash;
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
logger.error({ repo: toRepoId(repo), revision }, "No commits found for revision");
|
|
74
|
+
return null;
|
|
75
|
+
} catch (error) {
|
|
76
|
+
logger.error(
|
|
77
|
+
{ error: error.message, repo: toRepoId(repo), revision },
|
|
78
|
+
"Error getting HEAD commit"
|
|
79
|
+
);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function createSymlink(sourcePath, targetPath) {
|
|
84
|
+
const logger = (0, import_agents.log)();
|
|
85
|
+
const { symlink, rm, copyFile } = await import("node:fs/promises");
|
|
86
|
+
function expandUser(path) {
|
|
87
|
+
if (path.startsWith("~")) {
|
|
88
|
+
return path.replace("~", (0, import_node_os.homedir)());
|
|
89
|
+
}
|
|
90
|
+
return path;
|
|
91
|
+
}
|
|
92
|
+
const absSrc = (0, import_node_path.resolve)(expandUser(sourcePath));
|
|
93
|
+
const absDst = (0, import_node_path.resolve)(expandUser(targetPath));
|
|
94
|
+
try {
|
|
95
|
+
await rm(absDst);
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const relativePath = (0, import_node_path.relative)((0, import_node_path.dirname)(absDst), absSrc);
|
|
100
|
+
await symlink(relativePath, absDst);
|
|
101
|
+
logger.debug({ source: absSrc, target: absDst, relative: relativePath }, "Created symlink");
|
|
102
|
+
} catch (symlinkError) {
|
|
103
|
+
logger.warn({ source: absSrc, target: absDst }, "Symlink not supported, falling back to copy");
|
|
104
|
+
try {
|
|
105
|
+
await copyFile(absSrc, absDst);
|
|
106
|
+
logger.debug({ source: absSrc, target: absDst }, "File copied successfully");
|
|
107
|
+
} catch (copyError) {
|
|
108
|
+
logger.error(
|
|
109
|
+
{ error: copyError.message, source: absSrc, target: absDst },
|
|
110
|
+
"Failed to copy file"
|
|
111
|
+
);
|
|
112
|
+
throw symlinkError;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function getFilePointer(storageFolder, revision, relativeFilename) {
|
|
117
|
+
const snapshotPath = (0, import_node_path.join)(storageFolder, "snapshots");
|
|
118
|
+
return (0, import_node_path.join)(snapshotPath, revision, relativeFilename);
|
|
119
|
+
}
|
|
120
|
+
async function exists(path, followSymlinks) {
|
|
121
|
+
try {
|
|
122
|
+
if (followSymlinks) {
|
|
123
|
+
await (0, import_promises.stat)(path);
|
|
124
|
+
} else {
|
|
125
|
+
await (0, import_promises.lstat)(path);
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
} catch (err) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function saveRevisionMapping({
|
|
133
|
+
storageFolder,
|
|
134
|
+
revision,
|
|
135
|
+
commitHash
|
|
136
|
+
}) {
|
|
137
|
+
if (!REGEX_COMMIT_HASH.test(revision) && revision !== commitHash) {
|
|
138
|
+
const refsPath = (0, import_node_path.join)(storageFolder, "refs");
|
|
139
|
+
await (0, import_promises.mkdir)(refsPath, { recursive: true });
|
|
140
|
+
(0, import_node_fs.writeFileSync)((0, import_node_path.join)(refsPath, revision), commitHash);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async function downloadFileToCacheDir(params) {
|
|
144
|
+
const logger = (0, import_agents.log)();
|
|
145
|
+
const revision = params.revision ?? "main";
|
|
146
|
+
const cacheDir = params.cacheDir ?? getHFHubCachePath();
|
|
147
|
+
const repoId = toRepoId(params.repo);
|
|
148
|
+
const storageFolder = (0, import_node_path.join)(cacheDir, getRepoFolderName(repoId));
|
|
149
|
+
let branchHeadCommit;
|
|
150
|
+
if (REGEX_COMMIT_HASH.test(revision)) {
|
|
151
|
+
branchHeadCommit = revision;
|
|
152
|
+
const pointerPath2 = getFilePointer(storageFolder, revision, params.path);
|
|
153
|
+
if (await exists(pointerPath2, true)) {
|
|
154
|
+
logger.debug(
|
|
155
|
+
{ pointerPath: pointerPath2, commitHash: branchHeadCommit },
|
|
156
|
+
"File found in cache (commit hash)"
|
|
157
|
+
);
|
|
158
|
+
return pointerPath2;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (params.localFileOnly) {
|
|
162
|
+
logger.debug({ repoId, path: params.path, revision }, "Local file only mode - checking cache");
|
|
163
|
+
const directPath = getFilePointer(storageFolder, revision, params.path);
|
|
164
|
+
if (await exists(directPath, true)) {
|
|
165
|
+
logger.debug({ directPath }, "File found in cache (direct path)");
|
|
166
|
+
return directPath;
|
|
167
|
+
}
|
|
168
|
+
if (!REGEX_COMMIT_HASH.test(revision)) {
|
|
169
|
+
const refsPath = (0, import_node_path.join)(storageFolder, "refs", revision);
|
|
170
|
+
try {
|
|
171
|
+
const { readFileSync } = await import("fs");
|
|
172
|
+
const resolvedHash = readFileSync(refsPath, "utf-8").trim();
|
|
173
|
+
const resolvedPath = getFilePointer(storageFolder, resolvedHash, params.path);
|
|
174
|
+
if (await exists(resolvedPath, true)) {
|
|
175
|
+
logger.debug({ resolvedPath, resolvedHash }, "File found in cache (via refs)");
|
|
176
|
+
return resolvedPath;
|
|
177
|
+
}
|
|
178
|
+
} catch {
|
|
179
|
+
logger.debug({ revision }, "No ref mapping found for revision");
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const error = `File not found in cache: ${repoId}/${params.path} (revision: ${revision}). Make sure to run the download-files command before running the agent worker.`;
|
|
183
|
+
logger.error({ repoId, path: params.path, revision }, error);
|
|
184
|
+
throw new Error(error);
|
|
185
|
+
}
|
|
186
|
+
if (!branchHeadCommit) {
|
|
187
|
+
const headCommit = await getBranchHeadCommit(params.repo, revision, params);
|
|
188
|
+
if (!headCommit) {
|
|
189
|
+
throw new Error(`Failed to resolve revision ${revision} to commit hash`);
|
|
190
|
+
}
|
|
191
|
+
branchHeadCommit = headCommit;
|
|
192
|
+
}
|
|
193
|
+
const pointerPath = getFilePointer(storageFolder, branchHeadCommit, params.path);
|
|
194
|
+
if (await exists(pointerPath, true)) {
|
|
195
|
+
logger.debug({ pointerPath, branchHeadCommit }, "File found in cache (branch HEAD)");
|
|
196
|
+
await saveRevisionMapping({
|
|
197
|
+
storageFolder,
|
|
198
|
+
revision,
|
|
199
|
+
commitHash: branchHeadCommit
|
|
200
|
+
});
|
|
201
|
+
return pointerPath;
|
|
202
|
+
}
|
|
203
|
+
logger.debug(
|
|
204
|
+
{ repoId, path: params.path, revision: branchHeadCommit },
|
|
205
|
+
"Fetching path info from HF API"
|
|
206
|
+
);
|
|
207
|
+
const pathsInformation = await (0, import_hub.pathsInfo)({
|
|
208
|
+
...params,
|
|
209
|
+
paths: [params.path],
|
|
210
|
+
revision: branchHeadCommit,
|
|
211
|
+
// Use HEAD commit for consistency
|
|
212
|
+
expand: true
|
|
213
|
+
});
|
|
214
|
+
if (!pathsInformation || pathsInformation.length !== 1) {
|
|
215
|
+
const error = `cannot get path info for ${params.path}`;
|
|
216
|
+
logger.error({ repoId, path: params.path, pathsInfoLength: pathsInformation == null ? void 0 : pathsInformation.length }, error);
|
|
217
|
+
throw new Error(error);
|
|
218
|
+
}
|
|
219
|
+
const pathInfo = pathsInformation[0];
|
|
220
|
+
if (!pathInfo) {
|
|
221
|
+
const error = `No path info returned for ${params.path}`;
|
|
222
|
+
logger.error({ repoId, path: params.path }, error);
|
|
223
|
+
throw new Error(error);
|
|
224
|
+
}
|
|
225
|
+
let etag;
|
|
226
|
+
if (pathInfo.lfs) {
|
|
227
|
+
etag = pathInfo.lfs.oid;
|
|
228
|
+
logger.debug({ etag, path: params.path }, "File is LFS pointer");
|
|
229
|
+
} else {
|
|
230
|
+
etag = pathInfo.oid;
|
|
231
|
+
logger.debug({ etag, path: params.path }, "File is regular git object");
|
|
232
|
+
}
|
|
233
|
+
const blobPath = (0, import_node_path.join)(storageFolder, "blobs", etag);
|
|
234
|
+
logger.debug({ branchHeadCommit, pointerPath, blobPath }, "Computed cache paths");
|
|
235
|
+
await (0, import_promises.mkdir)((0, import_node_path.dirname)(blobPath), { recursive: true });
|
|
236
|
+
await (0, import_promises.mkdir)((0, import_node_path.dirname)(pointerPath), { recursive: true });
|
|
237
|
+
if (await exists(blobPath)) {
|
|
238
|
+
logger.debug({ blobPath, etag }, "Blob already exists in cache, creating symlink only");
|
|
239
|
+
await createSymlink(blobPath, pointerPath);
|
|
240
|
+
return pointerPath;
|
|
241
|
+
}
|
|
242
|
+
const incomplete = `${blobPath}.incomplete`;
|
|
243
|
+
logger.debug({ path: params.path, incomplete }, "Starting file download");
|
|
244
|
+
const blob = await (0, import_hub.downloadFile)({
|
|
245
|
+
...params,
|
|
246
|
+
revision: branchHeadCommit
|
|
247
|
+
});
|
|
248
|
+
if (!blob) {
|
|
249
|
+
const error = `invalid response for file ${params.path}`;
|
|
250
|
+
logger.error({ path: params.path }, error);
|
|
251
|
+
throw new Error(error);
|
|
252
|
+
}
|
|
253
|
+
logger.debug({ size: blob.size }, "Writing blob to disk");
|
|
254
|
+
await (0, import_promises2.pipeline)(import_node_stream.Readable.fromWeb(blob.stream()), (0, import_node_fs.createWriteStream)(incomplete));
|
|
255
|
+
await (0, import_promises.rename)(incomplete, blobPath);
|
|
256
|
+
logger.debug({ blobPath }, "Renamed incomplete file to final blob");
|
|
257
|
+
await createSymlink(blobPath, pointerPath);
|
|
258
|
+
logger.debug({ blobPath, pointerPath }, "Created symlink from snapshot to blob");
|
|
259
|
+
await saveRevisionMapping({
|
|
260
|
+
storageFolder,
|
|
261
|
+
revision,
|
|
262
|
+
commitHash: branchHeadCommit
|
|
263
|
+
});
|
|
264
|
+
logger.debug({ pointerPath, size: blob.size }, "File download completed successfully");
|
|
265
|
+
return pointerPath;
|
|
266
|
+
}
|
|
267
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
268
|
+
0 && (module.exports = {
|
|
269
|
+
REGEX_COMMIT_HASH,
|
|
270
|
+
downloadFileToCacheDir
|
|
271
|
+
});
|
|
272
|
+
//# sourceMappingURL=hf_utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hf_utils.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Fixed version of HuggingFace's downloadFileToCacheDir that matches Python's behavior\n *\n * Key fix: Uses branch/tag HEAD commit for snapshot paths, not file's last commit\n * This ensures all files from the same revision end up in the same snapshot folder\n */\nimport type { CommitInfo, PathInfo, RepoDesignation } from '@huggingface/hub';\nimport { downloadFile, listCommits, pathsInfo } from '@huggingface/hub';\nimport { log } from '@livekit/agents';\nimport { createWriteStream, writeFileSync } from 'node:fs';\nimport { lstat, mkdir, rename, stat } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { dirname, join, relative, resolve } from 'node:path';\nimport { Readable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\nimport type { ReadableStream } from 'node:stream/web';\n\n// Define CredentialsParams if not exported\ninterface CredentialsParams {\n accessToken?: string;\n}\n\nexport const REGEX_COMMIT_HASH: RegExp = new RegExp('^[0-9a-f]{40}$');\n\n// Helper functions from HuggingFace's cache-management\nfunction getHFHubCachePath(customCacheDir?: string): string {\n return customCacheDir || join(homedir(), '.cache', 'huggingface', 'hub');\n}\n\nfunction getRepoFolderName(repoId: string): string {\n return `models--${repoId.replace(/\\//g, '--')}`;\n}\n\nfunction toRepoId(repo: RepoDesignation | string): string {\n if (typeof repo === 'string') {\n return repo;\n }\n return `${repo.name}`;\n}\n\n/**\n * Get the HEAD commit hash for a branch/tag (matching Python's behavior)\n */\nasync function getBranchHeadCommit(\n repo: RepoDesignation,\n revision: string,\n params: { accessToken?: string; hubUrl?: string; fetch?: typeof fetch },\n): Promise<string | null> {\n const logger = log();\n\n try {\n // If already a commit hash, return it\n if (REGEX_COMMIT_HASH.test(revision)) {\n return revision;\n }\n\n // Get the first commit from listCommits - this is the HEAD\n for await (const commit of listCommits({\n repo,\n revision,\n ...params,\n })) {\n // The commit object structure varies, so we check multiple possible properties\n const commitHash = (commit as any).oid || (commit as any).id || (commit as any).commitId;\n if (commitHash) {\n return commitHash;\n }\n break; // Only need the first one\n }\n\n logger.error({ repo: toRepoId(repo), revision }, 'No commits found for revision');\n return null;\n } catch (error) {\n logger.error(\n { error: (error as Error).message, repo: toRepoId(repo), revision },\n 'Error getting HEAD commit',\n );\n throw error;\n }\n}\n\n/**\n * Create a symbolic link following HuggingFace's implementation\n */\nasync function createSymlink(sourcePath: string, targetPath: string): Promise<void> {\n const logger = log();\n const { symlink, rm, copyFile } = await import('node:fs/promises');\n\n // Expand ~ to home directory\n function expandUser(path: string): string {\n if (path.startsWith('~')) {\n return path.replace('~', homedir());\n }\n return path;\n }\n\n const absSrc = resolve(expandUser(sourcePath));\n const absDst = resolve(expandUser(targetPath));\n\n // Remove existing file/symlink if it exists\n try {\n await rm(absDst);\n } catch {\n // Ignore - file might not exist\n }\n\n try {\n // Create relative symlink (better for portability)\n const relativePath = relative(dirname(absDst), absSrc);\n await symlink(relativePath, absDst);\n logger.debug({ source: absSrc, target: absDst, relative: relativePath }, 'Created symlink');\n } catch (symlinkError) {\n // Symlink failed (common on Windows without admin rights)\n // Fall back to copying the file\n logger.warn({ source: absSrc, target: absDst }, 'Symlink not supported, falling back to copy');\n try {\n await copyFile(absSrc, absDst);\n logger.debug({ source: absSrc, target: absDst }, 'File copied successfully');\n } catch (copyError) {\n logger.error(\n { error: (copyError as Error).message, source: absSrc, target: absDst },\n 'Failed to copy file',\n );\n // If copy also fails, throw the original symlink error\n throw symlinkError;\n }\n }\n}\n\nfunction getFilePointer(storageFolder: string, revision: string, relativeFilename: string): string {\n const snapshotPath = join(storageFolder, 'snapshots');\n return join(snapshotPath, revision, relativeFilename);\n}\n\n/**\n * handy method to check if a file exists, or the pointer of a symlinks exists\n */\nasync function exists(path: string, followSymlinks?: boolean): Promise<boolean> {\n try {\n if (followSymlinks) {\n await stat(path);\n } else {\n await lstat(path);\n }\n return true;\n } catch (err: unknown) {\n return false;\n }\n}\n\nasync function saveRevisionMapping({\n storageFolder,\n revision,\n commitHash,\n}: {\n storageFolder: string;\n revision: string;\n commitHash: string;\n}): Promise<void> {\n if (!REGEX_COMMIT_HASH.test(revision) && revision !== commitHash) {\n const refsPath = join(storageFolder, 'refs');\n await mkdir(refsPath, { recursive: true });\n writeFileSync(join(refsPath, revision), commitHash);\n }\n}\n\n/**\n * Download a given file if it's not already present in the local cache.\n * Matches Python's hf_hub_download behavior by using branch HEAD commits.\n */\nexport async function downloadFileToCacheDir(\n params: {\n repo: RepoDesignation;\n path: string;\n /**\n * If true, will download the raw git file.\n */\n raw?: boolean;\n /**\n * An optional Git revision id which can be a branch name, a tag, or a commit hash.\n * @default \"main\"\n */\n revision?: string;\n hubUrl?: string;\n cacheDir?: string;\n /**\n * Custom fetch function to use instead of the default one\n */\n fetch?: typeof fetch;\n /**\n * If true, only return cached files, don't download\n */\n localFileOnly?: boolean;\n } & Partial<CredentialsParams>,\n): Promise<string> {\n const logger = log();\n\n // get revision provided or default to main\n const revision = params.revision ?? 'main';\n const cacheDir = params.cacheDir ?? getHFHubCachePath();\n // get repo id\n const repoId = toRepoId(params.repo);\n // get storage folder\n const storageFolder = join(cacheDir, getRepoFolderName(repoId));\n\n let branchHeadCommit: string | undefined;\n\n // if user provides a commitHash as revision, use it directly\n if (REGEX_COMMIT_HASH.test(revision)) {\n branchHeadCommit = revision;\n const pointerPath = getFilePointer(storageFolder, revision, params.path);\n if (await exists(pointerPath, true)) {\n logger.debug(\n { pointerPath, commitHash: branchHeadCommit },\n 'File found in cache (commit hash)',\n );\n return pointerPath;\n }\n }\n\n // If localFileOnly, check cache without making API calls\n if (params.localFileOnly) {\n logger.debug({ repoId, path: params.path, revision }, 'Local file only mode - checking cache');\n\n // Check with revision as-is (in case it's a commit hash)\n const directPath = getFilePointer(storageFolder, revision, params.path);\n if (await exists(directPath, true)) {\n logger.debug({ directPath }, 'File found in cache (direct path)');\n return directPath;\n }\n\n // If revision is not a commit hash, try to resolve from refs\n if (!REGEX_COMMIT_HASH.test(revision)) {\n const refsPath = join(storageFolder, 'refs', revision);\n try {\n const { readFileSync } = await import('fs');\n const resolvedHash = readFileSync(refsPath, 'utf-8').trim();\n const resolvedPath = getFilePointer(storageFolder, resolvedHash, params.path);\n if (await exists(resolvedPath, true)) {\n logger.debug({ resolvedPath, resolvedHash }, 'File found in cache (via refs)');\n return resolvedPath;\n }\n } catch {\n logger.debug({ revision }, 'No ref mapping found for revision');\n }\n }\n\n const error = `File not found in cache: ${repoId}/${params.path} (revision: ${revision}). Make sure to run the download-files command before running the agent worker.`;\n logger.error({ repoId, path: params.path, revision }, error);\n throw new Error(error);\n }\n\n // Get the branch HEAD commit if not already a commit hash\n if (!branchHeadCommit) {\n const headCommit = await getBranchHeadCommit(params.repo, revision, params);\n if (!headCommit) {\n throw new Error(`Failed to resolve revision ${revision} to commit hash`);\n }\n branchHeadCommit = headCommit;\n }\n\n // Check if file exists with the branch HEAD commit\n const pointerPath = getFilePointer(storageFolder, branchHeadCommit, params.path);\n if (await exists(pointerPath, true)) {\n logger.debug({ pointerPath, branchHeadCommit }, 'File found in cache (branch HEAD)');\n\n await saveRevisionMapping({\n storageFolder,\n revision,\n commitHash: branchHeadCommit,\n });\n\n return pointerPath;\n }\n\n // Now get file metadata to download it\n logger.debug(\n { repoId, path: params.path, revision: branchHeadCommit },\n 'Fetching path info from HF API',\n );\n const pathsInformation: (PathInfo & { lastCommit: CommitInfo })[] = await pathsInfo({\n ...params,\n paths: [params.path],\n revision: branchHeadCommit, // Use HEAD commit for consistency\n expand: true,\n });\n\n if (!pathsInformation || pathsInformation.length !== 1) {\n const error = `cannot get path info for ${params.path}`;\n logger.error({ repoId, path: params.path, pathsInfoLength: pathsInformation?.length }, error);\n throw new Error(error);\n }\n\n const pathInfo = pathsInformation[0];\n if (!pathInfo) {\n const error = `No path info returned for ${params.path}`;\n logger.error({ repoId, path: params.path }, error);\n throw new Error(error);\n }\n\n let etag: string;\n if (pathInfo.lfs) {\n etag = pathInfo.lfs.oid; // get the LFS pointed file oid\n logger.debug({ etag, path: params.path }, 'File is LFS pointer');\n } else {\n etag = pathInfo.oid; // get the repo file if not a LFS pointer\n logger.debug({ etag, path: params.path }, 'File is regular git object');\n }\n\n const blobPath = join(storageFolder, 'blobs', etag);\n\n logger.debug({ branchHeadCommit, pointerPath, blobPath }, 'Computed cache paths');\n\n // mkdir blob and pointer path parent directory\n await mkdir(dirname(blobPath), { recursive: true });\n await mkdir(dirname(pointerPath), { recursive: true });\n\n // We might already have the blob but not the pointer\n // shortcut the download if needed\n if (await exists(blobPath)) {\n logger.debug({ blobPath, etag }, 'Blob already exists in cache, creating symlink only');\n // create symlinks in snapshot folder to blob object\n await createSymlink(blobPath, pointerPath);\n return pointerPath;\n }\n\n const incomplete = `${blobPath}.incomplete`;\n logger.debug({ path: params.path, incomplete }, 'Starting file download');\n\n // Use enhanced download with retry - use branch HEAD commit for download\n const blob: Blob | null = await downloadFile({\n ...params,\n revision: branchHeadCommit,\n });\n\n if (!blob) {\n const error = `invalid response for file ${params.path}`;\n logger.error({ path: params.path }, error);\n throw new Error(error);\n }\n\n logger.debug({ size: blob.size }, 'Writing blob to disk');\n await pipeline(Readable.fromWeb(blob.stream() as ReadableStream), createWriteStream(incomplete));\n\n // rename .incomplete file to expected blob\n await rename(incomplete, blobPath);\n logger.debug({ blobPath }, 'Renamed incomplete file to final blob');\n\n // create symlinks in snapshot folder to blob object\n await createSymlink(blobPath, pointerPath);\n logger.debug({ blobPath, pointerPath }, 'Created symlink from snapshot to blob');\n\n await saveRevisionMapping({\n storageFolder,\n revision,\n commitHash: branchHeadCommit,\n });\n\n logger.debug({ pointerPath, size: blob.size }, 'File download completed successfully');\n return pointerPath;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,iBAAqD;AACrD,oBAAoB;AACpB,qBAAiD;AACjD,sBAA2C;AAC3C,qBAAwB;AACxB,uBAAiD;AACjD,yBAAyB;AACzB,IAAAA,mBAAyB;AAQlB,MAAM,oBAA4B,IAAI,OAAO,gBAAgB;AAGpE,SAAS,kBAAkB,gBAAiC;AAC1D,SAAO,sBAAkB,2BAAK,wBAAQ,GAAG,UAAU,eAAe,KAAK;AACzE;AAEA,SAAS,kBAAkB,QAAwB;AACjD,SAAO,WAAW,OAAO,QAAQ,OAAO,IAAI,CAAC;AAC/C;AAEA,SAAS,SAAS,MAAwC;AACxD,MAAI,OAAO,SAAS,UAAU;AAC5B,WAAO;AAAA,EACT;AACA,SAAO,GAAG,KAAK,IAAI;AACrB;AAKA,eAAe,oBACb,MACA,UACA,QACwB;AACxB,QAAM,aAAS,mBAAI;AAEnB,MAAI;AAEF,QAAI,kBAAkB,KAAK,QAAQ,GAAG;AACpC,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K,CAAC;AAIrD,MAAI,MAAM,OAAO,QAAQ,GAAG;AAC1B,WAAO,MAAM,EAAE,UAAU,KAAK,GAAG,qDAAqD;AAEtF,UAAM,cAAc,UAAU,WAAW;AACzC,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,GAAG,QAAQ;AAC9B,SAAO,MAAM,EAAE,MAAM,OAAO,MAAM,WAAW,GAAG,wBAAwB;AAGxE,QAAM,OAAoB,UAAM,yBAAa;AAAA,IAC3C,GAAG;AAAA,IACH,UAAU;AAAA,EACZ,CAAC;AAED,MAAI,CAAC,MAAM;AACT,UAAM,QAAQ,6BAA6B,OAAO,IAAI;AACtD,WAAO,MAAM,EAAE,MAAM,OAAO,KAAK,GAAG,KAAK;AACzC,UAAM,IAAI,MAAM,KAAK;AAAA,EACvB;AAEA,SAAO,MAAM,EAAE,MAAM,KAAK,KAAK,GAAG,sBAAsB;AACxD,YAAM,2BAAS,4BAAS,QAAQ,KAAK,OAAO,CAAmB,OAAG,kCAAkB,UAAU,CAAC;AAG/F,YAAM,wBAAO,YAAY,QAAQ;AACjC,SAAO,MAAM,EAAE,SAAS,GAAG,uCAAuC;AAGlE,QAAM,cAAc,UAAU,WAAW;AACzC,SAAO,MAAM,EAAE,UAAU,YAAY,GAAG,uCAAuC;AAE/E,QAAM,oBAAoB;AAAA,IACxB;AAAA,IACA;AAAA,IACA,YAAY;AAAA,EACd,CAAC;AAED,SAAO,MAAM,EAAE,aAAa,MAAM,KAAK,KAAK,GAAG,sCAAsC;AACrF,SAAO;AACT;","names":["import_promises","pointerPath"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed version of HuggingFace's downloadFileToCacheDir that matches Python's behavior
|
|
3
|
+
*
|
|
4
|
+
* Key fix: Uses branch/tag HEAD commit for snapshot paths, not file's last commit
|
|
5
|
+
* This ensures all files from the same revision end up in the same snapshot folder
|
|
6
|
+
*/
|
|
7
|
+
import type { RepoDesignation } from '@huggingface/hub';
|
|
8
|
+
interface CredentialsParams {
|
|
9
|
+
accessToken?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const REGEX_COMMIT_HASH: RegExp;
|
|
12
|
+
/**
|
|
13
|
+
* Download a given file if it's not already present in the local cache.
|
|
14
|
+
* Matches Python's hf_hub_download behavior by using branch HEAD commits.
|
|
15
|
+
*/
|
|
16
|
+
export declare function downloadFileToCacheDir(params: {
|
|
17
|
+
repo: RepoDesignation;
|
|
18
|
+
path: string;
|
|
19
|
+
/**
|
|
20
|
+
* If true, will download the raw git file.
|
|
21
|
+
*/
|
|
22
|
+
raw?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* An optional Git revision id which can be a branch name, a tag, or a commit hash.
|
|
25
|
+
* @default "main"
|
|
26
|
+
*/
|
|
27
|
+
revision?: string;
|
|
28
|
+
hubUrl?: string;
|
|
29
|
+
cacheDir?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Custom fetch function to use instead of the default one
|
|
32
|
+
*/
|
|
33
|
+
fetch?: typeof fetch;
|
|
34
|
+
/**
|
|
35
|
+
* If true, only return cached files, don't download
|
|
36
|
+
*/
|
|
37
|
+
localFileOnly?: boolean;
|
|
38
|
+
} & Partial<CredentialsParams>): Promise<string>;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=hf_utils.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed version of HuggingFace's downloadFileToCacheDir that matches Python's behavior
|
|
3
|
+
*
|
|
4
|
+
* Key fix: Uses branch/tag HEAD commit for snapshot paths, not file's last commit
|
|
5
|
+
* This ensures all files from the same revision end up in the same snapshot folder
|
|
6
|
+
*/
|
|
7
|
+
import type { RepoDesignation } from '@huggingface/hub';
|
|
8
|
+
interface CredentialsParams {
|
|
9
|
+
accessToken?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const REGEX_COMMIT_HASH: RegExp;
|
|
12
|
+
/**
|
|
13
|
+
* Download a given file if it's not already present in the local cache.
|
|
14
|
+
* Matches Python's hf_hub_download behavior by using branch HEAD commits.
|
|
15
|
+
*/
|
|
16
|
+
export declare function downloadFileToCacheDir(params: {
|
|
17
|
+
repo: RepoDesignation;
|
|
18
|
+
path: string;
|
|
19
|
+
/**
|
|
20
|
+
* If true, will download the raw git file.
|
|
21
|
+
*/
|
|
22
|
+
raw?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* An optional Git revision id which can be a branch name, a tag, or a commit hash.
|
|
25
|
+
* @default "main"
|
|
26
|
+
*/
|
|
27
|
+
revision?: string;
|
|
28
|
+
hubUrl?: string;
|
|
29
|
+
cacheDir?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Custom fetch function to use instead of the default one
|
|
32
|
+
*/
|
|
33
|
+
fetch?: typeof fetch;
|
|
34
|
+
/**
|
|
35
|
+
* If true, only return cached files, don't download
|
|
36
|
+
*/
|
|
37
|
+
localFileOnly?: boolean;
|
|
38
|
+
} & Partial<CredentialsParams>): Promise<string>;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=hf_utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hf_utils.d.ts","sourceRoot":"","sources":["../src/hf_utils.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,OAAO,KAAK,EAAwB,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAY9E,UAAU,iBAAiB;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,iBAAiB,EAAE,MAAqC,CAAC;AAgJtE;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE;IACN,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GAAG,OAAO,CAAC,iBAAiB,CAAC,GAC7B,OAAO,CAAC,MAAM,CAAC,CAsKjB"}
|