Charlie commited on
Commit
2c217a5
·
1 Parent(s): bc6eb2f

update files

Browse files
dist/app.js DELETED
@@ -1,71 +0,0 @@
1
- // DOM Elements
2
- const loginSection = document.getElementById("login-section");
3
- const profileSection = document.getElementById("profile-section");
4
- const loginButton = document.getElementById("login-button");
5
- const logoutButton = document.getElementById("logout-button");
6
- const usernameElement = document.getElementById("username");
7
- const avatarElement = document.getElementById("avatar");
8
- // Check for OAuth redirect and handle the token
9
- async function checkAndHandleOAuth() {
10
- try {
11
- const oauthResult = await window.HuggingFaceHub.oauthHandleRedirectIfPresent();
12
- if (oauthResult) {
13
- // Store the tokens
14
- localStorage.setItem("hf_token", oauthResult.accessToken);
15
- localStorage.setItem("hf_user", JSON.stringify(oauthResult.userInfo));
16
- // Update UI
17
- updateUIWithUserInfo(oauthResult.userInfo);
18
- }
19
- else {
20
- // Check if we have stored tokens
21
- const storedUser = localStorage.getItem("hf_user");
22
- if (storedUser) {
23
- updateUIWithUserInfo(JSON.parse(storedUser));
24
- }
25
- }
26
- }
27
- catch (error) {
28
- console.error("OAuth error:", error);
29
- localStorage.removeItem("hf_token");
30
- localStorage.removeItem("hf_user");
31
- showLoginSection();
32
- }
33
- }
34
- // Update UI with user information
35
- function updateUIWithUserInfo(userInfo) {
36
- usernameElement.textContent =
37
- userInfo.name || userInfo.preferred_username || "User";
38
- if (userInfo.picture) {
39
- avatarElement.src = userInfo.picture;
40
- }
41
- showProfileSection();
42
- }
43
- // Show login section
44
- function showLoginSection() {
45
- loginSection.style.display = "block";
46
- profileSection.style.display = "none";
47
- }
48
- // Show profile section
49
- function showProfileSection() {
50
- loginSection.style.display = "none";
51
- profileSection.style.display = "block";
52
- }
53
- // Handle login button click
54
- loginButton.addEventListener("click", async () => {
55
- try {
56
- const loginUrl = await window.HuggingFaceHub.oauthLoginUrl();
57
- window.location.href = loginUrl;
58
- }
59
- catch (error) {
60
- console.error("Login error:", error);
61
- }
62
- });
63
- // Handle logout button click
64
- logoutButton.addEventListener("click", () => {
65
- localStorage.removeItem("hf_token");
66
- localStorage.removeItem("hf_user");
67
- showLoginSection();
68
- });
69
- // Initialize the app
70
- checkAndHandleOAuth();
71
- export {};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dist/assets/index-DH6LWxsk.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ (function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))a(e);new MutationObserver(e=>{for(const n of e)if(n.type==="childList")for(const i of n.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&a(i)}).observe(document,{childList:!0,subtree:!0});function o(e){const n={};return e.integrity&&(n.integrity=e.integrity),e.referrerPolicy&&(n.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?n.credentials="include":e.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function a(e){if(e.ep)return;e.ep=!0;const n=o(e);fetch(e.href,n)}})();var T=Object.defineProperty,A=(t,r,o)=>r in t?T(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o,g=(t,r,o)=>(A(t,typeof r!="symbol"?r+"":r,o),o),E="https://huggingface.co";async function w(t,r){var o,a;const e=new q(t.url,t.status,(o=t.headers.get("X-Request-Id"))!=null?o:void 0);e.message=`Api error with status ${e.statusCode}`;const n=[`URL: ${e.url}`,e.requestId?`Request ID: ${e.requestId}`:void 0].filter(Boolean).join(". ");if((a=t.headers.get("Content-Type"))!=null&&a.startsWith("application/json")){const i=await t.json();e.message=i.error||i.message||e.message,i.error_description&&(e.message=e.message?e.message+`: ${i.error_description}`:i.error_description),e.data=i}else e.data={message:await t.text()};throw e.message+=`. ${n}`,e}var q=class extends Error{constructor(t,r,o,a){super(a),g(this,"statusCode"),g(this,"url"),g(this,"requestId"),g(this,"data"),this.statusCode=r,this.requestId=o,this.url=t}};new Promise(t=>{});function $(t){if(globalThis.Buffer)return globalThis.Buffer.from(t).toString("base64");{const r=[];return t.forEach(o=>{r.push(String.fromCharCode(o))}),globalThis.btoa(r.join(""))}}async function S(t){var r,o,a;if(typeof window>"u")throw new Error("oauthHandleRedirect is only available in the browser, unless you provide redirectedUrl");if(typeof localStorage>"u")throw new Error("oauthHandleRedirect requires localStorage to be available, unless you provide nonce and codeVerifier");const e=(r=void 0)!=null?r:window.location.href,n=(()=>{try{return new URL(e).searchParams}catch{throw new Error("Failed to parse redirected URL: "+e)}})(),[i,u]=[n.get("error"),n.get("error_description")];if(i)throw new Error(`${i}: ${u}`);const d=n.get("code"),l=(o=void 0)!=null?o:localStorage.getItem("huggingface.co:oauth:nonce");if(!d)throw new Error("Missing oauth code from query parameters in redirected URL: "+e);if(!l)throw new Error("Missing oauth nonce from localStorage");const f=(a=void 0)!=null?a:localStorage.getItem("huggingface.co:oauth:code_verifier");if(!f)throw new Error("Missing oauth code_verifier from localStorage");const s=n.get("state");if(!s)throw new Error("Missing oauth state from query parameters in redirected URL");let c;try{c=JSON.parse(s)}catch{throw new Error("Invalid oauth state in redirected URL, unable to parse JSON: "+s)}if(c.nonce!==l)throw new Error("Invalid oauth state in redirected URL");const m=E,L=`${new URL(m).origin}/.well-known/openid-configuration`,y=await fetch(L,{headers:{Accept:"application/json"}});if(!y.ok)throw await w(y);const U=await y.json(),v=await fetch(U.token_endpoint,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",code:d,redirect_uri:c.redirectUri,code_verifier:f}).toString()});if(localStorage.removeItem("huggingface.co:oauth:code_verifier"),localStorage.removeItem("huggingface.co:oauth:nonce"),!v.ok)throw await w(v);const h=await v.json(),C=new Date(Date.now()+h.expires_in*1e3),b=await fetch(U.userinfo_endpoint,{headers:{Authorization:`Bearer ${h.access_token}`}});if(!b.ok)throw await w(b);const O=await b.json();return{accessToken:h.access_token,accessTokenExpiresAt:C,userInfo:O,state:c.state,scope:h.scope}}async function j(t){var r;if(typeof window>"u")throw new Error("oauthHandleRedirect is only available in the browser, unless you provide redirectedUrl");if(typeof localStorage>"u")throw new Error("oauthHandleRedirect requires localStorage to be available, unless you provide nonce and codeVerifier");const o=new URLSearchParams((r=void 0)!=null?r:window.location.search);return o.has("error")?S():o.has("code")?localStorage.getItem("huggingface.co:oauth:nonce")?S():(console.warn("Missing oauth nonce from localStorage. This can happen when the user refreshes the page after logging in, without changing the URL."),!1):!1}async function H(t){var r,o;if(typeof window>"u")throw new Error("oauthLogin is only available in the browser, unless you provide clientId and redirectUrl");if(typeof localStorage>"u")throw new Error("oauthLogin requires localStorage to be available in the context, unless you provide a localStorage empty object as argument");const a=E,e=`${new URL(a).origin}/.well-known/openid-configuration`,n=await fetch(e,{headers:{Accept:"application/json"}});if(!n.ok)throw await w(n);const i=await n.json(),u=globalThis.crypto.randomUUID(),d=globalThis.crypto.randomUUID()+globalThis.crypto.randomUUID();localStorage.setItem("huggingface.co:oauth:nonce",u),localStorage.setItem("huggingface.co:oauth:code_verifier",d);const l=typeof window<"u"?window.location.href:void 0;if(!l)throw new Error("Missing redirectUrl");const f=JSON.stringify({nonce:u,redirectUri:l,state:void 0}),s=typeof window<"u"&&(o=(r=window.huggingface)==null?void 0:r.variables)!=null?o:null,c=s==null?void 0:s.OAUTH_CLIENT_ID;if(!c)throw s?new Error("Missing clientId, please add hf_oauth: true to the README.md's metadata in your static Space"):new Error("Missing clientId");const m=$(new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256",new TextEncoder().encode(d)))).replace(/[+]/g,"-").replace(/[/]/g,"_").replace(/=/g,"");return`${i.authorization_endpoint}?${new URLSearchParams({client_id:c,scope:(s==null?void 0:s.OAUTH_SCOPES)||"openid profile",response_type:"code",redirect_uri:l,state:f,code_challenge:m,code_challenge_method:"S256"}).toString()}`}const I=document.getElementById("signin"),R=document.getElementById("signout"),_=document.querySelector("pre");function p(t){I.style.display=t?"none":"block",R.style.display=t?"block":"none"}async function x(){try{const t=await j();return t?(_.textContent=JSON.stringify(t,null,2),p(!0)):p(!1),t}catch(t){throw console.error("OAuth error:",t),_.textContent="Error: "+t.message,p(!1),t}}I.addEventListener("click",async()=>{const t=await H();window.location.href=t});R.addEventListener("click",()=>{_.textContent="",p(!1)});x().catch(console.error);
2
+ //# sourceMappingURL=index-DH6LWxsk.js.map
dist/assets/index-DH6LWxsk.js.map ADDED
@@ -0,0 +1 @@
 
 
1
+ {"version":3,"file":"index-DH6LWxsk.js","sources":["../../node_modules/@huggingface/hub/dist/browser/chunk-NHABU752.mjs","../../node_modules/@huggingface/hub/dist/browser/index.mjs","../../src/index.ts"],"sourcesContent":["var __defProp = Object.defineProperty;\nvar __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;\nvar __publicField = (obj, key, value) => {\n __defNormalProp(obj, typeof key !== \"symbol\" ? key + \"\" : key, value);\n return value;\n};\n\nexport {\n __publicField\n};\n","import {\n __publicField\n} from \"./chunk-NHABU752.mjs\";\n\n// src/consts.ts\nvar HUB_URL = \"https://huggingface.co\";\n\n// src/error.ts\nasync function createApiError(response, opts) {\n var _a, _b;\n const error = new HubApiError(response.url, response.status, (_a = response.headers.get(\"X-Request-Id\")) != null ? _a : opts == null ? void 0 : opts.requestId);\n error.message = `Api error with status ${error.statusCode}${(opts == null ? void 0 : opts.message) ? `. ${opts.message}` : \"\"}`;\n const trailer = [`URL: ${error.url}`, error.requestId ? `Request ID: ${error.requestId}` : void 0].filter(Boolean).join(\". \");\n if ((_b = response.headers.get(\"Content-Type\")) == null ? void 0 : _b.startsWith(\"application/json\")) {\n const json = await response.json();\n error.message = json.error || json.message || error.message;\n if (json.error_description) {\n error.message = error.message ? error.message + `: ${json.error_description}` : json.error_description;\n }\n error.data = json;\n } else {\n error.data = { message: await response.text() };\n }\n error.message += `. ${trailer}`;\n throw error;\n}\nvar HubApiError = class extends Error {\n constructor(url, statusCode, requestId, message) {\n super(message);\n __publicField(this, \"statusCode\");\n __publicField(this, \"url\");\n __publicField(this, \"requestId\");\n __publicField(this, \"data\");\n this.statusCode = statusCode;\n this.requestId = requestId;\n this.url = url;\n }\n};\nvar InvalidApiResponseFormatError = class extends Error {\n};\n\n// src/utils/checkCredentials.ts\nfunction checkAccessToken(accessToken) {\n if (!accessToken.startsWith(\"hf_\")) {\n throw new TypeError(\"Your access token must start with 'hf_'\");\n }\n}\nfunction checkCredentials(params) {\n var _a;\n if (params.accessToken) {\n checkAccessToken(params.accessToken);\n return params.accessToken;\n }\n if ((_a = params.credentials) == null ? void 0 : _a.accessToken) {\n checkAccessToken(params.credentials.accessToken);\n return params.credentials.accessToken;\n }\n}\n\n// src/utils/toRepoId.ts\nfunction toRepoId(repo) {\n if (typeof repo !== \"string\") {\n return repo;\n }\n if (repo.startsWith(\"model/\") || repo.startsWith(\"models/\")) {\n throw new TypeError(\n \"A repo designation for a model should not start with 'models/', directly specify the model namespace / name\"\n );\n }\n if (repo.startsWith(\"space/\")) {\n throw new TypeError(\"Spaces should start with 'spaces/', plural, not 'space/'\");\n }\n if (repo.startsWith(\"dataset/\")) {\n throw new TypeError(\"Datasets should start with 'dataset/', plural, not 'dataset/'\");\n }\n const slashes = repo.split(\"/\").length - 1;\n if (repo.startsWith(\"spaces/\")) {\n if (slashes !== 2) {\n throw new TypeError(\"Space Id must include namespace and name of the space\");\n }\n return {\n type: \"space\",\n name: repo.slice(\"spaces/\".length)\n };\n }\n if (repo.startsWith(\"datasets/\")) {\n if (slashes > 2) {\n throw new TypeError(\"Too many slashes in repo designation: \" + repo);\n }\n return {\n type: \"dataset\",\n name: repo.slice(\"datasets/\".length)\n };\n }\n if (slashes > 1) {\n throw new TypeError(\"Too many slashes in repo designation: \" + repo);\n }\n return {\n type: \"model\",\n name: repo\n };\n}\n\n// src/lib/check-repo-access.ts\nasync function checkRepoAccess(params) {\n const accessToken = params && checkCredentials(params);\n const repoId = toRepoId(params.repo);\n const response = await (params.fetch || fetch)(`${(params == null ? void 0 : params.hubUrl) || HUB_URL}/api/${repoId.type}s/${repoId.name}`, {\n headers: {\n ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {}\n }\n });\n if (!response.ok) {\n throw await createApiError(response);\n }\n}\n\n// src/utils/range.ts\nfunction range(n, b) {\n return b ? Array(b - n).fill(0).map((_, i) => n + i) : Array(n).fill(0).map((_, i) => i);\n}\n\n// src/utils/chunk.ts\nfunction chunk(arr, chunkSize) {\n if (isNaN(chunkSize) || chunkSize < 1) {\n throw new RangeError(\"Invalid chunk size: \" + chunkSize);\n }\n if (!arr.length) {\n return [];\n }\n if (arr.length <= chunkSize) {\n return [arr];\n }\n return range(Math.ceil(arr.length / chunkSize)).map((i) => {\n return arr.slice(i * chunkSize, (i + 1) * chunkSize);\n });\n}\n\n// src/utils/promisesQueue.ts\nasync function promisesQueue(factories, concurrency) {\n const results = [];\n const executing = /* @__PURE__ */ new Set();\n let index = 0;\n for (const factory of factories) {\n const closureIndex = index++;\n const e = factory().then((r) => {\n results[closureIndex] = r;\n executing.delete(e);\n });\n executing.add(e);\n if (executing.size >= concurrency) {\n await Promise.race(executing);\n }\n }\n await Promise.all(executing);\n return results;\n}\n\n// src/utils/promisesQueueStreaming.ts\nasync function promisesQueueStreaming(factories, concurrency) {\n const executing = [];\n for await (const factory of factories) {\n const e = factory().then(() => {\n executing.splice(executing.indexOf(e), 1);\n });\n executing.push(e);\n if (executing.length >= concurrency) {\n await Promise.race(executing);\n }\n }\n await Promise.all(executing);\n}\n\n// src/utils/eventToGenerator.ts\nasync function* eventToGenerator(cb) {\n const promises = [];\n function addPromise() {\n let resolve2;\n let reject;\n const p = new Promise((res, rej) => {\n resolve2 = res;\n reject = rej;\n });\n promises.push({ p, resolve: resolve2, reject });\n }\n addPromise();\n const callbackRes = Promise.resolve().then(\n () => cb(\n (y) => {\n var _a;\n addPromise();\n (_a = promises.at(-2)) == null ? void 0 : _a.resolve({ done: false, value: y });\n },\n (r) => {\n var _a;\n addPromise();\n (_a = promises.at(-2)) == null ? void 0 : _a.resolve({ done: true, value: r });\n },\n (err) => {\n var _a;\n return (_a = promises.shift()) == null ? void 0 : _a.reject(err);\n }\n )\n ).catch((err) => {\n var _a;\n return (_a = promises.shift()) == null ? void 0 : _a.reject(err);\n });\n while (1) {\n const p = promises[0];\n if (!p) {\n throw new Error(\"Logic error in eventGenerator, promises should never be empty\");\n }\n const result = await p.p;\n promises.shift();\n if (result.done) {\n await callbackRes;\n return result.value;\n }\n yield result.value;\n }\n throw new Error(\"Unreachable\");\n}\n\n// src/utils/hexFromBytes.ts\nfunction hexFromBytes(arr) {\n if (globalThis.Buffer) {\n return globalThis.Buffer.from(arr).toString(\"hex\");\n } else {\n const bin = [];\n arr.forEach((byte) => {\n bin.push(byte.toString(16).padStart(2, \"0\"));\n });\n return bin.join(\"\");\n }\n}\n\n// src/utils/isBackend.ts\nvar isBrowser = typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\nvar isWebWorker = typeof self === \"object\" && self.constructor && self.constructor.name === \"DedicatedWorkerGlobalScope\";\nvar isBackend = !isBrowser && !isWebWorker;\n\n// src/utils/isFrontend.ts\nvar isFrontend = !isBackend;\n\n// src/utils/sha256.ts\nasync function getWebWorkerCode() {\n const sha256Module = await import(\"./sha256-wrapper-2GO3XT7J.mjs\");\n return URL.createObjectURL(new Blob([sha256Module.createSHA256WorkerCode()]));\n}\nvar pendingWorkers = [];\nvar runningWorkers = /* @__PURE__ */ new Set();\nvar resolve;\nvar waitPromise = new Promise((r) => {\n resolve = r;\n});\nasync function getWorker(poolSize) {\n {\n const worker2 = pendingWorkers.pop();\n if (worker2) {\n runningWorkers.add(worker2);\n return worker2;\n }\n }\n if (!poolSize) {\n const worker2 = new Worker(await getWebWorkerCode());\n runningWorkers.add(worker2);\n return worker2;\n }\n if (poolSize <= 0) {\n throw new TypeError(\"Invalid webworker pool size: \" + poolSize);\n }\n while (runningWorkers.size >= poolSize) {\n await waitPromise;\n }\n const worker = new Worker(await getWebWorkerCode());\n runningWorkers.add(worker);\n return worker;\n}\nasync function freeWorker(worker, poolSize) {\n if (!poolSize) {\n return destroyWorker(worker);\n }\n runningWorkers.delete(worker);\n pendingWorkers.push(worker);\n const r = resolve;\n waitPromise = new Promise((r2) => {\n resolve = r2;\n });\n r();\n}\nfunction destroyWorker(worker) {\n runningWorkers.delete(worker);\n worker.terminate();\n const r = resolve;\n waitPromise = new Promise((r2) => {\n resolve = r2;\n });\n r();\n}\nasync function* sha256(buffer, opts) {\n var _a, _b;\n yield 0;\n const maxCryptoSize = typeof (opts == null ? void 0 : opts.useWebWorker) === \"object\" && (opts == null ? void 0 : opts.useWebWorker.minSize) !== void 0 ? opts.useWebWorker.minSize : 1e7;\n if (buffer.size < maxCryptoSize && ((_a = globalThis.crypto) == null ? void 0 : _a.subtle)) {\n const res = hexFromBytes(\n new Uint8Array(\n await globalThis.crypto.subtle.digest(\"SHA-256\", buffer instanceof Blob ? await buffer.arrayBuffer() : buffer)\n )\n );\n yield 1;\n return res;\n }\n if (isFrontend) {\n if (opts == null ? void 0 : opts.useWebWorker) {\n try {\n const poolSize = typeof (opts == null ? void 0 : opts.useWebWorker) === \"object\" ? opts.useWebWorker.poolSize : void 0;\n const worker = await getWorker(poolSize);\n return yield* eventToGenerator((yieldCallback, returnCallback, rejectCallack) => {\n worker.addEventListener(\"message\", (event) => {\n var _a2;\n if (event.data.sha256) {\n freeWorker(worker, poolSize);\n returnCallback(event.data.sha256);\n } else if (event.data.progress) {\n yieldCallback(event.data.progress);\n try {\n (_a2 = opts.abortSignal) == null ? void 0 : _a2.throwIfAborted();\n } catch (err) {\n destroyWorker(worker);\n rejectCallack(err);\n }\n } else {\n destroyWorker(worker);\n rejectCallack(event);\n }\n });\n worker.addEventListener(\"error\", (event) => {\n destroyWorker(worker);\n rejectCallack(event.error);\n });\n worker.postMessage({ file: buffer });\n });\n } catch (err) {\n console.warn(\"Failed to use web worker for sha256\", err);\n }\n }\n if (!wasmModule) {\n wasmModule = await import(\"./sha256-wrapper-2GO3XT7J.mjs\");\n }\n const sha2562 = await wasmModule.createSHA256();\n sha2562.init();\n const reader = buffer.stream().getReader();\n const total = buffer.size;\n let bytesDone = 0;\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n sha2562.update(value);\n bytesDone += value.length;\n yield bytesDone / total;\n (_b = opts == null ? void 0 : opts.abortSignal) == null ? void 0 : _b.throwIfAborted();\n }\n return sha2562.digest(\"hex\");\n }\n if (!cryptoModule) {\n cryptoModule = await import(\"./sha256-node-TNZ2WHTI.mjs\");\n }\n return yield* cryptoModule.sha256Node(buffer, { abortSignal: opts == null ? void 0 : opts.abortSignal });\n}\nvar cryptoModule;\nvar wasmModule;\n\n// src/utils/WebBlob.ts\nvar WebBlob = class extends Blob {\n constructor(url, start, end, contentType, full, customFetch) {\n super([]);\n __publicField(this, \"url\");\n __publicField(this, \"start\");\n __publicField(this, \"end\");\n __publicField(this, \"contentType\");\n __publicField(this, \"full\");\n __publicField(this, \"fetch\");\n this.url = url;\n this.start = start;\n this.end = end;\n this.contentType = contentType;\n this.full = full;\n this.fetch = customFetch;\n }\n static async create(url, opts) {\n var _a, _b;\n const customFetch = (_a = opts == null ? void 0 : opts.fetch) != null ? _a : fetch;\n const response = await customFetch(url, { method: \"HEAD\" });\n const size = Number(response.headers.get(\"content-length\"));\n const contentType = response.headers.get(\"content-type\") || \"\";\n const supportRange = response.headers.get(\"accept-ranges\") === \"bytes\";\n if (!supportRange || size < ((_b = opts == null ? void 0 : opts.cacheBelow) != null ? _b : 1e6)) {\n return await (await customFetch(url)).blob();\n }\n return new WebBlob(url, 0, size, contentType, true, customFetch);\n }\n get size() {\n return this.end - this.start;\n }\n get type() {\n return this.contentType;\n }\n slice(start = 0, end = this.size) {\n if (start < 0 || end < 0) {\n new TypeError(\"Unsupported negative start/end on FileBlob.slice\");\n }\n const slice = new WebBlob(\n this.url,\n this.start + start,\n Math.min(this.start + end, this.end),\n this.contentType,\n start === 0 && end === this.size ? this.full : false,\n this.fetch\n );\n return slice;\n }\n async arrayBuffer() {\n const result = await this.fetchRange();\n return result.arrayBuffer();\n }\n async text() {\n const result = await this.fetchRange();\n return result.text();\n }\n stream() {\n const stream = new TransformStream();\n this.fetchRange().then((response) => {\n var _a;\n return (_a = response.body) == null ? void 0 : _a.pipeThrough(stream);\n }).catch((error) => stream.writable.abort(error.message));\n return stream.readable;\n }\n fetchRange() {\n const fetch2 = this.fetch;\n if (this.full) {\n return fetch2(this.url);\n }\n return fetch2(this.url, {\n headers: {\n Range: `bytes=${this.start}-${this.end - 1}`\n }\n });\n }\n};\n\n// src/utils/createBlob.ts\nasync function createBlob(url, opts) {\n if (url.protocol === \"http:\" || url.protocol === \"https:\") {\n return WebBlob.create(url, { fetch: opts == null ? void 0 : opts.fetch });\n }\n if (isFrontend) {\n throw new TypeError(`Unsupported URL protocol \"${url.protocol}\"`);\n }\n if (url.protocol === \"file:\") {\n const { FileBlob } = await import(\"./FileBlob-7MRLQ6TG.mjs\");\n return FileBlob.create(url);\n }\n throw new TypeError(`Unsupported URL protocol \"${url.protocol}\"`);\n}\n\n// src/utils/base64FromBytes.ts\nfunction base64FromBytes(arr) {\n if (globalThis.Buffer) {\n return globalThis.Buffer.from(arr).toString(\"base64\");\n } else {\n const bin = [];\n arr.forEach((byte) => {\n bin.push(String.fromCharCode(byte));\n });\n return globalThis.btoa(bin.join(\"\"));\n }\n}\n\n// src/lib/commit.ts\nvar CONCURRENT_SHAS = 5;\nvar CONCURRENT_LFS_UPLOADS = 5;\nvar MULTIPART_PARALLEL_UPLOAD = 5;\nfunction isFileOperation(op) {\n const ret = op.operation === \"addOrUpdate\";\n if (ret && !(op.content instanceof Blob)) {\n throw new TypeError(\"Precondition failed: op.content should be a Blob\");\n }\n return ret;\n}\nasync function* commitIter(params) {\n var _a, _b, _c, _d, _e, _f, _g;\n const accessToken = checkCredentials(params);\n const repoId = toRepoId(params.repo);\n yield { event: \"phase\", phase: \"preuploading\" };\n const lfsShas = /* @__PURE__ */ new Map();\n const abortController = new AbortController();\n const abortSignal = abortController.signal;\n if (!abortSignal.throwIfAborted) {\n abortSignal.throwIfAborted = () => {\n if (abortSignal.aborted) {\n throw new DOMException(\"Aborted\", \"AbortError\");\n }\n };\n }\n if (params.abortSignal) {\n params.abortSignal.addEventListener(\"abort\", () => abortController.abort());\n }\n try {\n const allOperations = await Promise.all(\n params.operations.map(async (operation) => {\n if (operation.operation !== \"addOrUpdate\") {\n return operation;\n }\n if (!(operation.content instanceof URL)) {\n return { ...operation, content: operation.content };\n }\n const lazyBlob = await createBlob(operation.content, { fetch: params.fetch });\n abortSignal == null ? void 0 : abortSignal.throwIfAborted();\n return {\n ...operation,\n content: lazyBlob\n };\n })\n );\n const gitAttributes = (_a = allOperations.filter(isFileOperation).find((op) => op.path === \".gitattributes\")) == null ? void 0 : _a.content;\n for (const operations of chunk(allOperations.filter(isFileOperation), 100)) {\n const payload = {\n gitAttributes: gitAttributes && await gitAttributes.text(),\n files: await Promise.all(\n operations.map(async (operation) => ({\n path: operation.path,\n size: operation.content.size,\n sample: base64FromBytes(new Uint8Array(await operation.content.slice(0, 512).arrayBuffer()))\n }))\n )\n };\n abortSignal == null ? void 0 : abortSignal.throwIfAborted();\n const res = await ((_b = params.fetch) != null ? _b : fetch)(\n `${(_c = params.hubUrl) != null ? _c : HUB_URL}/api/${repoId.type}s/${repoId.name}/preupload/${encodeURIComponent(\n (_d = params.branch) != null ? _d : \"main\"\n )}` + (params.isPullRequest ? \"?create_pr=1\" : \"\"),\n {\n method: \"POST\",\n headers: {\n ...accessToken && { Authorization: `Bearer ${accessToken}` },\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify(payload),\n signal: abortSignal\n }\n );\n if (!res.ok) {\n throw await createApiError(res);\n }\n const json = await res.json();\n for (const file of json.files) {\n if (file.uploadMode === \"lfs\") {\n lfsShas.set(file.path, null);\n }\n }\n }\n yield { event: \"phase\", phase: \"uploadingLargeFiles\" };\n for (const operations of chunk(\n allOperations.filter(isFileOperation).filter((op) => lfsShas.has(op.path)),\n 100\n )) {\n const shas = yield* eventToGenerator((yieldCallback, returnCallback, rejectCallack) => {\n return promisesQueue(\n operations.map((op) => async () => {\n const iterator = sha256(op.content, { useWebWorker: params.useWebWorkers, abortSignal });\n let res2;\n do {\n res2 = await iterator.next();\n if (!res2.done) {\n yieldCallback({ event: \"fileProgress\", path: op.path, progress: res2.value, state: \"hashing\" });\n }\n } while (!res2.done);\n const sha = res2.value;\n lfsShas.set(op.path, res2.value);\n return sha;\n }),\n CONCURRENT_SHAS\n ).then(returnCallback, rejectCallack);\n });\n abortSignal == null ? void 0 : abortSignal.throwIfAborted();\n const payload = {\n operation: \"upload\",\n // multipart is a custom protocol for HF\n transfers: [\"basic\", \"multipart\"],\n hash_algo: \"sha_256\",\n ...!params.isPullRequest && {\n ref: {\n name: (_e = params.branch) != null ? _e : \"main\"\n }\n },\n objects: operations.map((op, i) => ({\n oid: shas[i],\n size: op.content.size\n }))\n };\n const res = await ((_f = params.fetch) != null ? _f : fetch)(\n `${(_g = params.hubUrl) != null ? _g : HUB_URL}/${repoId.type === \"model\" ? \"\" : repoId.type + \"s/\"}${repoId.name}.git/info/lfs/objects/batch`,\n {\n method: \"POST\",\n headers: {\n ...accessToken && { Authorization: `Bearer ${accessToken}` },\n Accept: \"application/vnd.git-lfs+json\",\n \"Content-Type\": \"application/vnd.git-lfs+json\"\n },\n body: JSON.stringify(payload),\n signal: abortSignal\n }\n );\n if (!res.ok) {\n throw await createApiError(res);\n }\n const json = await res.json();\n const batchRequestId = res.headers.get(\"X-Request-Id\") || void 0;\n const shaToOperation = new Map(operations.map((op, i) => [shas[i], op]));\n yield* eventToGenerator((yieldCallback, returnCallback, rejectCallback) => {\n return promisesQueueStreaming(\n json.objects.map((obj) => async () => {\n var _a2, _b2, _c2;\n const op = shaToOperation.get(obj.oid);\n if (!op) {\n throw new InvalidApiResponseFormatError(\"Unrequested object ID in response\");\n }\n abortSignal == null ? void 0 : abortSignal.throwIfAborted();\n if (obj.error) {\n const errorMessage = `Error while doing LFS batch call for ${operations[shas.indexOf(obj.oid)].path}: ${obj.error.message}${batchRequestId ? ` - Request ID: ${batchRequestId}` : \"\"}`;\n throw new HubApiError(res.url, obj.error.code, batchRequestId, errorMessage);\n }\n if (!((_a2 = obj.actions) == null ? void 0 : _a2.upload)) {\n yieldCallback({\n event: \"fileProgress\",\n path: op.path,\n progress: 1,\n state: \"uploading\"\n });\n return;\n }\n yieldCallback({\n event: \"fileProgress\",\n path: op.path,\n progress: 0,\n state: \"uploading\"\n });\n const content = op.content;\n const header = obj.actions.upload.header;\n if (header == null ? void 0 : header.chunk_size) {\n const chunkSize = parseInt(header.chunk_size);\n const completionUrl = obj.actions.upload.href;\n const parts = Object.keys(header).filter((key) => /^[0-9]+$/.test(key));\n if (parts.length !== Math.ceil(content.size / chunkSize)) {\n throw new Error(\"Invalid server response to upload large LFS file, wrong number of parts\");\n }\n const completeReq = {\n oid: obj.oid,\n parts: parts.map((part) => ({\n partNumber: +part,\n etag: \"\"\n }))\n };\n const progressCallback = (progress) => yieldCallback({ event: \"fileProgress\", path: op.path, progress, state: \"uploading\" });\n await promisesQueueStreaming(\n parts.map((part) => async () => {\n var _a3;\n abortSignal == null ? void 0 : abortSignal.throwIfAborted();\n const index = parseInt(part) - 1;\n const slice = content.slice(index * chunkSize, (index + 1) * chunkSize);\n const res3 = await ((_a3 = params.fetch) != null ? _a3 : fetch)(header[part], {\n method: \"PUT\",\n /** Unfortunately, browsers don't support our inherited version of Blob in fetch calls */\n body: slice instanceof WebBlob && isFrontend ? await slice.arrayBuffer() : slice,\n signal: abortSignal,\n ...{\n progressHint: {\n path: op.path,\n part: index,\n numParts: parts.length,\n progressCallback\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }\n });\n if (!res3.ok) {\n throw await createApiError(res3, {\n requestId: batchRequestId,\n message: `Error while uploading part ${part} of ${operations[shas.indexOf(obj.oid)].path} to LFS storage`\n });\n }\n const eTag = res3.headers.get(\"ETag\");\n if (!eTag) {\n throw new Error(\"Cannot get ETag of part during multipart upload\");\n }\n completeReq.parts[Number(part) - 1].etag = eTag;\n }),\n MULTIPART_PARALLEL_UPLOAD\n );\n abortSignal == null ? void 0 : abortSignal.throwIfAborted();\n const res2 = await ((_b2 = params.fetch) != null ? _b2 : fetch)(completionUrl, {\n method: \"POST\",\n body: JSON.stringify(completeReq),\n headers: {\n Accept: \"application/vnd.git-lfs+json\",\n \"Content-Type\": \"application/vnd.git-lfs+json\"\n },\n signal: abortSignal\n });\n if (!res2.ok) {\n throw await createApiError(res2, {\n requestId: batchRequestId,\n message: `Error completing multipart upload of ${operations[shas.indexOf(obj.oid)].path} to LFS storage`\n });\n }\n yieldCallback({\n event: \"fileProgress\",\n path: op.path,\n progress: 1,\n state: \"uploading\"\n });\n } else {\n const res2 = await ((_c2 = params.fetch) != null ? _c2 : fetch)(obj.actions.upload.href, {\n method: \"PUT\",\n headers: {\n ...batchRequestId ? { \"X-Request-Id\": batchRequestId } : void 0\n },\n /** Unfortunately, browsers don't support our inherited version of Blob in fetch calls */\n body: content instanceof WebBlob && isFrontend ? await content.arrayBuffer() : content,\n signal: abortSignal,\n ...{\n progressHint: {\n path: op.path,\n progressCallback: (progress) => yieldCallback({\n event: \"fileProgress\",\n path: op.path,\n progress,\n state: \"uploading\"\n })\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }\n });\n if (!res2.ok) {\n throw await createApiError(res2, {\n requestId: batchRequestId,\n message: `Error while uploading ${operations[shas.indexOf(obj.oid)].path} to LFS storage`\n });\n }\n yieldCallback({\n event: \"fileProgress\",\n path: op.path,\n progress: 1,\n state: \"uploading\"\n });\n }\n }),\n CONCURRENT_LFS_UPLOADS\n ).then(returnCallback, rejectCallback);\n });\n }\n abortSignal == null ? void 0 : abortSignal.throwIfAborted();\n yield { event: \"phase\", phase: \"committing\" };\n return yield* eventToGenerator(\n async (yieldCallback, returnCallback, rejectCallback) => {\n var _a2, _b2, _c2;\n return ((_a2 = params.fetch) != null ? _a2 : fetch)(\n `${(_b2 = params.hubUrl) != null ? _b2 : HUB_URL}/api/${repoId.type}s/${repoId.name}/commit/${encodeURIComponent(\n (_c2 = params.branch) != null ? _c2 : \"main\"\n )}` + (params.isPullRequest ? \"?create_pr=1\" : \"\"),\n {\n method: \"POST\",\n headers: {\n ...accessToken && { Authorization: `Bearer ${accessToken}` },\n \"Content-Type\": \"application/x-ndjson\"\n },\n body: [\n {\n key: \"header\",\n value: {\n summary: params.title,\n description: params.description,\n parentCommit: params.parentCommit\n }\n },\n ...await Promise.all(\n allOperations.map((operation) => {\n if (isFileOperation(operation)) {\n const sha = lfsShas.get(operation.path);\n if (sha) {\n return {\n key: \"lfsFile\",\n value: {\n path: operation.path,\n algo: \"sha256\",\n size: operation.content.size,\n oid: sha\n }\n };\n }\n }\n return convertOperationToNdJson(operation);\n })\n )\n ].map((x) => JSON.stringify(x)).join(\"\\n\"),\n signal: abortSignal,\n ...{\n progressHint: {\n progressCallback: (progress) => {\n for (const op of allOperations) {\n if (isFileOperation(op) && !lfsShas.has(op.path)) {\n yieldCallback({\n event: \"fileProgress\",\n path: op.path,\n progress,\n state: \"uploading\"\n });\n }\n }\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }\n }\n ).then(async (res) => {\n if (!res.ok) {\n throw await createApiError(res);\n }\n const json = await res.json();\n returnCallback({\n pullRequestUrl: json.pullRequestUrl,\n commit: {\n oid: json.commitOid,\n url: json.commitUrl\n },\n hookOutput: json.hookOutput\n });\n }).catch(rejectCallback);\n }\n );\n } catch (err) {\n abortController.abort();\n throw err;\n }\n}\nasync function commit(params) {\n const iterator = commitIter(params);\n let res = await iterator.next();\n while (!res.done) {\n res = await iterator.next();\n }\n return res.value;\n}\nasync function convertOperationToNdJson(operation) {\n switch (operation.operation) {\n case \"addOrUpdate\": {\n return {\n key: \"file\",\n value: {\n content: base64FromBytes(new Uint8Array(await operation.content.arrayBuffer())),\n path: operation.path,\n encoding: \"base64\"\n }\n };\n }\n case \"delete\": {\n return {\n key: \"deletedFile\",\n value: {\n path: operation.path\n }\n };\n }\n default:\n throw new TypeError(\"Unknown operation: \" + operation.operation);\n }\n}\n\n// src/lib/count-commits.ts\nasync function countCommits(params) {\n var _a, _b, _c, _d;\n const accessToken = checkCredentials(params);\n const repoId = toRepoId(params.repo);\n const url = `${(_a = params.hubUrl) != null ? _a : HUB_URL}/api/${repoId.type}s/${repoId.name}/commits/${(_b = params.revision) != null ? _b : \"main\"}?limit=1`;\n const res = await ((_c = params.fetch) != null ? _c : fetch)(url, {\n headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : {}\n });\n if (!res.ok) {\n throw await createApiError(res);\n }\n return parseInt((_d = res.headers.get(\"x-total-count\")) != null ? _d : \"0\", 10);\n}\n\n// src/lib/create-repo.ts\nasync function createRepo(params) {\n var _a, _b;\n const accessToken = checkCredentials(params);\n const repoId = toRepoId(params.repo);\n const [namespace, repoName] = repoId.name.split(\"/\");\n if (!namespace || !repoName) {\n throw new TypeError(\n `\"${repoId.name}\" is not a fully qualified repo name. It should be of the form \"{namespace}/{repoName}\".`\n );\n }\n const res = await ((_a = params.fetch) != null ? _a : fetch)(`${(_b = params.hubUrl) != null ? _b : HUB_URL}/api/repos/create`, {\n method: \"POST\",\n body: JSON.stringify({\n name: repoName,\n private: params.private,\n organization: namespace,\n license: params.license,\n ...repoId.type === \"space\" ? {\n type: \"space\",\n sdk: \"static\"\n } : {\n type: repoId.type\n },\n files: params.files ? await Promise.all(\n params.files.map(async (file) => ({\n encoding: \"base64\",\n path: file.path,\n content: base64FromBytes(\n new Uint8Array(file.content instanceof Blob ? await file.content.arrayBuffer() : file.content)\n )\n }))\n ) : void 0\n }),\n headers: {\n Authorization: `Bearer ${accessToken}`,\n \"Content-Type\": \"application/json\"\n }\n });\n if (!res.ok) {\n throw await createApiError(res);\n }\n const output = await res.json();\n return { repoUrl: output.url };\n}\n\n// src/utils/pick.ts\nfunction pick(o, props) {\n return Object.assign(\n {},\n ...props.map((prop) => {\n if (o[prop] !== void 0) {\n return { [prop]: o[prop] };\n }\n })\n );\n}\n\n// src/utils/parseLinkHeader.ts\nfunction parseLinkHeader(header) {\n const regex = /<(https?:[/][/][^>]+)>;\\s+rel=\"([^\"]+)\"/g;\n return Object.fromEntries([...header.matchAll(regex)].map(([, url, rel]) => [rel, url]));\n}\n\n// src/lib/list-datasets.ts\nvar DATASET_EXPAND_KEYS = [\n \"private\",\n \"downloads\",\n \"gated\",\n \"likes\",\n \"lastModified\"\n];\nvar DATASET_EXPANDABLE_KEYS = [\n \"author\",\n \"cardData\",\n \"citation\",\n \"createdAt\",\n \"disabled\",\n \"description\",\n \"downloads\",\n \"downloadsAllTime\",\n \"gated\",\n \"gitalyUid\",\n \"lastModified\",\n \"likes\",\n \"paperswithcode_id\",\n \"private\",\n // \"siblings\",\n \"sha\",\n \"tags\"\n];\nasync function* listDatasets(params) {\n var _a, _b, _c, _d, _e, _f, _g, _h, _i;\n const accessToken = params && checkCredentials(params);\n let totalToFetch = (_a = params == null ? void 0 : params.limit) != null ? _a : Infinity;\n const search = new URLSearchParams([\n ...Object.entries({\n limit: String(Math.min(totalToFetch, 500)),\n ...((_b = params == null ? void 0 : params.search) == null ? void 0 : _b.owner) ? { author: params.search.owner } : void 0,\n ...((_c = params == null ? void 0 : params.search) == null ? void 0 : _c.query) ? { search: params.search.query } : void 0\n }),\n ...(_f = (_e = (_d = params == null ? void 0 : params.search) == null ? void 0 : _d.tags) == null ? void 0 : _e.map((tag) => [\"filter\", tag])) != null ? _f : [],\n ...DATASET_EXPAND_KEYS.map((val) => [\"expand\", val]),\n ...(_h = (_g = params == null ? void 0 : params.additionalFields) == null ? void 0 : _g.map((val) => [\"expand\", val])) != null ? _h : []\n ]).toString();\n let url = `${(params == null ? void 0 : params.hubUrl) || HUB_URL}/api/datasets` + (search ? \"?\" + search : \"\");\n while (url) {\n const res = await ((_i = params == null ? void 0 : params.fetch) != null ? _i : fetch)(url, {\n headers: {\n accept: \"application/json\",\n ...accessToken ? { Authorization: `Bearer ${accessToken}` } : void 0\n }\n });\n if (!res.ok) {\n throw await createApiError(res);\n }\n const items = await res.json();\n for (const item of items) {\n yield {\n ...(params == null ? void 0 : params.additionalFields) && pick(item, params.additionalFields),\n id: item._id,\n name: item.id,\n private: item.private,\n downloads: item.downloads,\n likes: item.likes,\n gated: item.gated,\n updatedAt: new Date(item.lastModified)\n };\n totalToFetch--;\n if (totalToFetch <= 0) {\n return;\n }\n }\n const linkHeader = res.headers.get(\"Link\");\n url = linkHeader ? parseLinkHeader(linkHeader).next : void 0;\n }\n}\n\n// src/lib/dataset-info.ts\nasync function datasetInfo(params) {\n var _a, _b, _c;\n const accessToken = params && checkCredentials(params);\n const search = new URLSearchParams([\n ...DATASET_EXPAND_KEYS.map((val) => [\"expand\", val]),\n ...(_b = (_a = params == null ? void 0 : params.additionalFields) == null ? void 0 : _a.map((val) => [\"expand\", val])) != null ? _b : []\n ]).toString();\n const response = await (params.fetch || fetch)(\n `${(params == null ? void 0 : params.hubUrl) || HUB_URL}/api/datasets/${params.name}/revision/${encodeURIComponent(\n (_c = params.revision) != null ? _c : \"HEAD\"\n )}?${search.toString()}`,\n {\n headers: {\n ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},\n Accepts: \"application/json\"\n }\n }\n );\n if (!response.ok) {\n throw await createApiError(response);\n }\n const data = await response.json();\n return {\n ...(params == null ? void 0 : params.additionalFields) && pick(data, params.additionalFields),\n id: data._id,\n name: data.id,\n private: data.private,\n downloads: data.downloads,\n likes: data.likes,\n gated: data.gated,\n updatedAt: new Date(data.lastModified)\n };\n}\n\n// src/lib/delete-file.ts\nfunction deleteFile(params) {\n var _a;\n return commit({\n ...params.accessToken ? { accessToken: params.accessToken } : { credentials: params.credentials },\n repo: params.repo,\n operations: [\n {\n operation: \"delete\",\n path: params.path\n }\n ],\n title: (_a = params.commitTitle) != null ? _a : `Delete ${params.path}`,\n description: params.commitDescription,\n hubUrl: params.hubUrl,\n branch: params.branch,\n isPullRequest: params.isPullRequest,\n parentCommit: params.parentCommit,\n fetch: params.fetch\n });\n}\n\n// src/lib/delete-files.ts\nfunction deleteFiles(params) {\n var _a;\n return commit({\n ...params.accessToken ? { accessToken: params.accessToken } : { credentials: params.credentials },\n repo: params.repo,\n operations: params.paths.map((path) => ({\n operation: \"delete\",\n path\n })),\n title: (_a = params.commitTitle) != null ? _a : `Deletes ${params.paths.length} files`,\n description: params.commitDescription,\n hubUrl: params.hubUrl,\n branch: params.branch,\n isPullRequest: params.isPullRequest,\n parentCommit: params.parentCommit,\n fetch: params.fetch\n });\n}\n\n// src/lib/delete-repo.ts\nasync function deleteRepo(params) {\n var _a, _b;\n const accessToken = checkCredentials(params);\n const repoId = toRepoId(params.repo);\n const [namespace, repoName] = repoId.name.split(\"/\");\n const res = await ((_a = params.fetch) != null ? _a : fetch)(`${(_b = params.hubUrl) != null ? _b : HUB_URL}/api/repos/delete`, {\n method: \"DELETE\",\n body: JSON.stringify({\n name: repoName,\n organization: namespace,\n type: repoId.type\n }),\n headers: {\n Authorization: `Bearer ${accessToken}`,\n \"Content-Type\": \"application/json\"\n }\n });\n if (!res.ok) {\n throw await createApiError(res);\n }\n}\n\n// src/lib/download-file.ts\nasync function downloadFile(params) {\n var _a, _b, _c;\n const accessToken = checkCredentials(params);\n const repoId = toRepoId(params.repo);\n const url = `${(_a = params.hubUrl) != null ? _a : HUB_URL}/${repoId.type === \"model\" ? \"\" : `${repoId.type}s/`}${repoId.name}/${params.raw ? \"raw\" : \"resolve\"}/${encodeURIComponent((_b = params.revision) != null ? _b : \"main\")}/${params.path}`;\n const resp = await ((_c = params.fetch) != null ? _c : fetch)(url, {\n headers: {\n ...accessToken ? {\n Authorization: `Bearer ${accessToken}`\n } : {},\n ...params.range ? {\n Range: `bytes=${params.range[0]}-${params.range[1]}`\n } : {}\n }\n });\n if (resp.status === 404 && resp.headers.get(\"X-Error-Code\") === \"EntryNotFound\") {\n return null;\n } else if (!resp.ok) {\n throw await createApiError(resp);\n }\n return resp;\n}\n\n// src/lib/file-download-info.ts\nasync function fileDownloadInfo(params) {\n var _a, _b, _c;\n const accessToken = checkCredentials(params);\n const repoId = toRepoId(params.repo);\n const hubUrl = (_a = params.hubUrl) != null ? _a : HUB_URL;\n const url = `${hubUrl}/${repoId.type === \"model\" ? \"\" : `${repoId.type}s/`}${repoId.name}/${params.raw ? \"raw\" : \"resolve\"}/${encodeURIComponent((_b = params.revision) != null ? _b : \"main\")}/${params.path}` + (params.noContentDisposition ? \"?noContentDisposition=1\" : \"\");\n const resp = await ((_c = params.fetch) != null ? _c : fetch)(url, {\n method: \"GET\",\n headers: {\n ...accessToken && {\n Authorization: `Bearer ${accessToken}`\n },\n Range: \"bytes=0-0\"\n }\n });\n if (resp.status === 404 && resp.headers.get(\"X-Error-Code\") === \"EntryNotFound\") {\n return null;\n }\n if (!resp.ok) {\n throw await createApiError(resp);\n }\n const etag = resp.headers.get(\"ETag\");\n if (!etag) {\n throw new InvalidApiResponseFormatError(\"Expected ETag\");\n }\n const contentRangeHeader = resp.headers.get(\"content-range\");\n if (!contentRangeHeader) {\n throw new InvalidApiResponseFormatError(\"Expected size information\");\n }\n const [, parsedSize] = contentRangeHeader.split(\"/\");\n const size = parseInt(parsedSize);\n if (isNaN(size)) {\n throw new InvalidApiResponseFormatError(\"Invalid file size received\");\n }\n return {\n etag,\n size,\n downloadLink: new URL(resp.url).hostname !== new URL(hubUrl).hostname ? resp.url : null\n };\n}\n\n// src/lib/file-exists.ts\nasync function fileExists(params) {\n var _a, _b, _c;\n const accessToken = checkCredentials(params);\n const repoId = toRepoId(params.repo);\n const hubUrl = (_a = params.hubUrl) != null ? _a : HUB_URL;\n const url = `${hubUrl}/${repoId.type === \"model\" ? \"\" : `${repoId.type}s/`}${repoId.name}/raw/${encodeURIComponent(\n (_b = params.revision) != null ? _b : \"main\"\n )}/${params.path}`;\n const resp = await ((_c = params.fetch) != null ? _c : fetch)(url, {\n method: \"HEAD\",\n headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : {}\n });\n if (resp.status === 404) {\n return false;\n }\n if (!resp.ok) {\n throw await createApiError(resp);\n }\n return true;\n}\n\n// src/lib/list-commits.ts\nasync function* listCommits(params) {\n var _a, _b, _c, _d;\n const accessToken = checkCredentials(params);\n const repoId = toRepoId(params.repo);\n let url = `${(_a = params.hubUrl) != null ? _a : HUB_URL}/api/${repoId.type}s/${repoId.name}/commits/${(_b = params.revision) != null ? _b : \"main\"}?limit=${(_c = params.batchSize) != null ? _c : 100}`;\n while (url) {\n const res = await ((_d = params.fetch) != null ? _d : fetch)(url, {\n headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : {}\n });\n if (!res.ok) {\n throw await createApiError(res);\n }\n const resJson = await res.json();\n for (const commit2 of resJson) {\n yield {\n oid: commit2.id,\n title: commit2.title,\n message: commit2.message,\n authors: commit2.authors.map((author) => ({\n username: author.user,\n avatarUrl: author.avatar\n })),\n date: new Date(commit2.date)\n };\n }\n const linkHeader = res.headers.get(\"Link\");\n url = linkHeader ? parseLinkHeader(linkHeader).next : void 0;\n }\n}\n\n// src/lib/list-files.ts\nasync function* listFiles(params) {\n var _a;\n const accessToken = checkCredentials(params);\n const repoId = toRepoId(params.repo);\n let url = `${params.hubUrl || HUB_URL}/api/${repoId.type}s/${repoId.name}/tree/${params.revision || \"main\"}${params.path ? \"/\" + params.path : \"\"}?recursive=${!!params.recursive}&expand=${!!params.expand}`;\n while (url) {\n const res = await ((_a = params.fetch) != null ? _a : fetch)(url, {\n headers: {\n accept: \"application/json\",\n ...accessToken ? { Authorization: `Bearer ${accessToken}` } : void 0\n }\n });\n if (!res.ok) {\n throw await createApiError(res);\n }\n const items = await res.json();\n for (const item of items) {\n yield item;\n }\n const linkHeader = res.headers.get(\"Link\");\n url = linkHeader ? parseLinkHeader(linkHeader).next : void 0;\n }\n}\n\n// src/lib/list-models.ts\nvar MODEL_EXPAND_KEYS = [\n \"pipeline_tag\",\n \"private\",\n \"gated\",\n \"downloads\",\n \"likes\",\n \"lastModified\"\n];\nvar MODEL_EXPANDABLE_KEYS = [\n \"author\",\n \"cardData\",\n \"config\",\n \"createdAt\",\n \"disabled\",\n \"downloads\",\n \"downloadsAllTime\",\n \"gated\",\n \"gitalyUid\",\n \"inferenceProviderMapping\",\n \"lastModified\",\n \"library_name\",\n \"likes\",\n \"model-index\",\n \"pipeline_tag\",\n \"private\",\n \"safetensors\",\n \"sha\",\n // \"siblings\",\n \"spaces\",\n \"tags\",\n \"transformersInfo\"\n];\nasync function* listModels(params) {\n var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;\n const accessToken = params && checkCredentials(params);\n let totalToFetch = (_a = params == null ? void 0 : params.limit) != null ? _a : Infinity;\n const search = new URLSearchParams([\n ...Object.entries({\n limit: String(Math.min(totalToFetch, 500)),\n ...((_b = params == null ? void 0 : params.search) == null ? void 0 : _b.owner) ? { author: params.search.owner } : void 0,\n ...((_c = params == null ? void 0 : params.search) == null ? void 0 : _c.task) ? { pipeline_tag: params.search.task } : void 0,\n ...((_d = params == null ? void 0 : params.search) == null ? void 0 : _d.query) ? { search: params.search.query } : void 0\n }),\n ...(_g = (_f = (_e = params == null ? void 0 : params.search) == null ? void 0 : _e.tags) == null ? void 0 : _f.map((tag) => [\"filter\", tag])) != null ? _g : [],\n ...MODEL_EXPAND_KEYS.map((val) => [\"expand\", val]),\n ...(_i = (_h = params == null ? void 0 : params.additionalFields) == null ? void 0 : _h.map((val) => [\"expand\", val])) != null ? _i : []\n ]).toString();\n let url = `${(params == null ? void 0 : params.hubUrl) || HUB_URL}/api/models?${search}`;\n while (url) {\n const res = await ((_j = params == null ? void 0 : params.fetch) != null ? _j : fetch)(url, {\n headers: {\n accept: \"application/json\",\n ...accessToken ? { Authorization: `Bearer ${accessToken}` } : void 0\n }\n });\n if (!res.ok) {\n throw await createApiError(res);\n }\n const items = await res.json();\n for (const item of items) {\n yield {\n ...(params == null ? void 0 : params.additionalFields) && pick(item, params.additionalFields),\n id: item._id,\n name: item.id,\n private: item.private,\n task: item.pipeline_tag,\n downloads: item.downloads,\n gated: item.gated,\n likes: item.likes,\n updatedAt: new Date(item.lastModified)\n };\n totalToFetch--;\n if (totalToFetch <= 0) {\n return;\n }\n }\n const linkHeader = res.headers.get(\"Link\");\n url = linkHeader ? parseLinkHeader(linkHeader).next : void 0;\n }\n}\n\n// src/lib/list-spaces.ts\nvar SPACE_EXPAND_KEYS = [\n \"sdk\",\n \"likes\",\n \"private\",\n \"lastModified\"\n];\nvar SPACE_EXPANDABLE_KEYS = [\n \"author\",\n \"cardData\",\n \"datasets\",\n \"disabled\",\n \"gitalyUid\",\n \"lastModified\",\n \"createdAt\",\n \"likes\",\n \"private\",\n \"runtime\",\n \"sdk\",\n // \"siblings\",\n \"sha\",\n \"subdomain\",\n \"tags\",\n \"models\"\n];\nasync function* listSpaces(params) {\n var _a, _b, _c, _d, _e, _f, _g;\n const accessToken = params && checkCredentials(params);\n const search = new URLSearchParams([\n ...Object.entries({\n limit: \"500\",\n ...((_a = params == null ? void 0 : params.search) == null ? void 0 : _a.owner) ? { author: params.search.owner } : void 0,\n ...((_b = params == null ? void 0 : params.search) == null ? void 0 : _b.query) ? { search: params.search.query } : void 0\n }),\n ...(_e = (_d = (_c = params == null ? void 0 : params.search) == null ? void 0 : _c.tags) == null ? void 0 : _d.map((tag) => [\"filter\", tag])) != null ? _e : [],\n ...[...SPACE_EXPAND_KEYS, ...(_f = params == null ? void 0 : params.additionalFields) != null ? _f : []].map(\n (val) => [\"expand\", val]\n )\n ]).toString();\n let url = `${(params == null ? void 0 : params.hubUrl) || HUB_URL}/api/spaces?${search}`;\n while (url) {\n const res = await ((_g = params == null ? void 0 : params.fetch) != null ? _g : fetch)(url, {\n headers: {\n accept: \"application/json\",\n ...accessToken ? { Authorization: `Bearer ${accessToken}` } : void 0\n }\n });\n if (!res.ok) {\n throw await createApiError(res);\n }\n const items = await res.json();\n for (const item of items) {\n yield {\n ...(params == null ? void 0 : params.additionalFields) && pick(item, params.additionalFields),\n id: item._id,\n name: item.id,\n sdk: item.sdk,\n likes: item.likes,\n private: item.private,\n updatedAt: new Date(item.lastModified)\n };\n }\n const linkHeader = res.headers.get(\"Link\");\n url = linkHeader ? parseLinkHeader(linkHeader).next : void 0;\n }\n}\n\n// src/lib/model-info.ts\nasync function modelInfo(params) {\n var _a, _b, _c;\n const accessToken = params && checkCredentials(params);\n const search = new URLSearchParams([\n ...MODEL_EXPAND_KEYS.map((val) => [\"expand\", val]),\n ...(_b = (_a = params == null ? void 0 : params.additionalFields) == null ? void 0 : _a.map((val) => [\"expand\", val])) != null ? _b : []\n ]).toString();\n const response = await (params.fetch || fetch)(\n `${(params == null ? void 0 : params.hubUrl) || HUB_URL}/api/models/${params.name}/revision/${encodeURIComponent(\n (_c = params.revision) != null ? _c : \"HEAD\"\n )}?${search.toString()}`,\n {\n headers: {\n ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},\n Accepts: \"application/json\"\n }\n }\n );\n if (!response.ok) {\n throw await createApiError(response);\n }\n const data = await response.json();\n return {\n ...(params == null ? void 0 : params.additionalFields) && pick(data, params.additionalFields),\n id: data._id,\n name: data.id,\n private: data.private,\n task: data.pipeline_tag,\n downloads: data.downloads,\n gated: data.gated,\n likes: data.likes,\n updatedAt: new Date(data.lastModified)\n };\n}\n\n// src/lib/oauth-handle-redirect.ts\nasync function oauthHandleRedirect(opts) {\n var _a, _b, _c;\n if (typeof window === \"undefined\" && !(opts == null ? void 0 : opts.redirectedUrl)) {\n throw new Error(\"oauthHandleRedirect is only available in the browser, unless you provide redirectedUrl\");\n }\n if (typeof localStorage === \"undefined\" && (!(opts == null ? void 0 : opts.nonce) || !(opts == null ? void 0 : opts.codeVerifier))) {\n throw new Error(\n \"oauthHandleRedirect requires localStorage to be available, unless you provide nonce and codeVerifier\"\n );\n }\n const redirectedUrl = (_a = opts == null ? void 0 : opts.redirectedUrl) != null ? _a : window.location.href;\n const searchParams = (() => {\n try {\n return new URL(redirectedUrl).searchParams;\n } catch (err) {\n throw new Error(\"Failed to parse redirected URL: \" + redirectedUrl);\n }\n })();\n const [error, errorDescription] = [searchParams.get(\"error\"), searchParams.get(\"error_description\")];\n if (error) {\n throw new Error(`${error}: ${errorDescription}`);\n }\n const code = searchParams.get(\"code\");\n const nonce = (_b = opts == null ? void 0 : opts.nonce) != null ? _b : localStorage.getItem(\"huggingface.co:oauth:nonce\");\n if (!code) {\n throw new Error(\"Missing oauth code from query parameters in redirected URL: \" + redirectedUrl);\n }\n if (!nonce) {\n throw new Error(\"Missing oauth nonce from localStorage\");\n }\n const codeVerifier = (_c = opts == null ? void 0 : opts.codeVerifier) != null ? _c : localStorage.getItem(\"huggingface.co:oauth:code_verifier\");\n if (!codeVerifier) {\n throw new Error(\"Missing oauth code_verifier from localStorage\");\n }\n const state = searchParams.get(\"state\");\n if (!state) {\n throw new Error(\"Missing oauth state from query parameters in redirected URL\");\n }\n let parsedState;\n try {\n parsedState = JSON.parse(state);\n } catch (e) {\n throw new Error(\"Invalid oauth state in redirected URL, unable to parse JSON: \" + state);\n }\n if (parsedState.nonce !== nonce) {\n throw new Error(\"Invalid oauth state in redirected URL\");\n }\n const hubUrl = (opts == null ? void 0 : opts.hubUrl) || HUB_URL;\n const openidConfigUrl = `${new URL(hubUrl).origin}/.well-known/openid-configuration`;\n const openidConfigRes = await fetch(openidConfigUrl, {\n headers: {\n Accept: \"application/json\"\n }\n });\n if (!openidConfigRes.ok) {\n throw await createApiError(openidConfigRes);\n }\n const openidConfig = await openidConfigRes.json();\n const tokenRes = await fetch(openidConfig.token_endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\"\n },\n body: new URLSearchParams({\n grant_type: \"authorization_code\",\n code,\n redirect_uri: parsedState.redirectUri,\n code_verifier: codeVerifier\n }).toString()\n });\n if (!(opts == null ? void 0 : opts.codeVerifier)) {\n localStorage.removeItem(\"huggingface.co:oauth:code_verifier\");\n }\n if (!(opts == null ? void 0 : opts.nonce)) {\n localStorage.removeItem(\"huggingface.co:oauth:nonce\");\n }\n if (!tokenRes.ok) {\n throw await createApiError(tokenRes);\n }\n const token = await tokenRes.json();\n const accessTokenExpiresAt = new Date(Date.now() + token.expires_in * 1e3);\n const userInfoRes = await fetch(openidConfig.userinfo_endpoint, {\n headers: {\n Authorization: `Bearer ${token.access_token}`\n }\n });\n if (!userInfoRes.ok) {\n throw await createApiError(userInfoRes);\n }\n const userInfo = await userInfoRes.json();\n return {\n accessToken: token.access_token,\n accessTokenExpiresAt,\n userInfo,\n state: parsedState.state,\n scope: token.scope\n };\n}\nasync function oauthHandleRedirectIfPresent(opts) {\n var _a;\n if (typeof window === \"undefined\" && !(opts == null ? void 0 : opts.redirectedUrl)) {\n throw new Error(\"oauthHandleRedirect is only available in the browser, unless you provide redirectedUrl\");\n }\n if (typeof localStorage === \"undefined\" && (!(opts == null ? void 0 : opts.nonce) || !(opts == null ? void 0 : opts.codeVerifier))) {\n throw new Error(\n \"oauthHandleRedirect requires localStorage to be available, unless you provide nonce and codeVerifier\"\n );\n }\n const searchParams = new URLSearchParams((_a = opts == null ? void 0 : opts.redirectedUrl) != null ? _a : window.location.search);\n if (searchParams.has(\"error\")) {\n return oauthHandleRedirect(opts);\n }\n if (searchParams.has(\"code\")) {\n if (!localStorage.getItem(\"huggingface.co:oauth:nonce\")) {\n console.warn(\n \"Missing oauth nonce from localStorage. This can happen when the user refreshes the page after logging in, without changing the URL.\"\n );\n return false;\n }\n return oauthHandleRedirect(opts);\n }\n return false;\n}\n\n// src/lib/oauth-login-url.ts\nasync function oauthLoginUrl(opts) {\n var _a, _b;\n if (typeof window === \"undefined\" && (!(opts == null ? void 0 : opts.redirectUrl) || !(opts == null ? void 0 : opts.clientId))) {\n throw new Error(\"oauthLogin is only available in the browser, unless you provide clientId and redirectUrl\");\n }\n if (typeof localStorage === \"undefined\" && !(opts == null ? void 0 : opts.localStorage)) {\n throw new Error(\n \"oauthLogin requires localStorage to be available in the context, unless you provide a localStorage empty object as argument\"\n );\n }\n const hubUrl = (opts == null ? void 0 : opts.hubUrl) || HUB_URL;\n const openidConfigUrl = `${new URL(hubUrl).origin}/.well-known/openid-configuration`;\n const openidConfigRes = await fetch(openidConfigUrl, {\n headers: {\n Accept: \"application/json\"\n }\n });\n if (!openidConfigRes.ok) {\n throw await createApiError(openidConfigRes);\n }\n const opendidConfig = await openidConfigRes.json();\n const newNonce = globalThis.crypto.randomUUID();\n const newCodeVerifier = globalThis.crypto.randomUUID() + globalThis.crypto.randomUUID();\n if (opts == null ? void 0 : opts.localStorage) {\n if (opts.localStorage.codeVerifier !== void 0 && opts.localStorage.codeVerifier !== null) {\n throw new Error(\n \"localStorage.codeVerifier must be a initially set to null or undefined, and will be filled by oauthLoginUrl\"\n );\n }\n if (opts.localStorage.nonce !== void 0 && opts.localStorage.nonce !== null) {\n throw new Error(\n \"localStorage.nonce must be a initially set to null or undefined, and will be filled by oauthLoginUrl\"\n );\n }\n opts.localStorage.codeVerifier = newCodeVerifier;\n opts.localStorage.nonce = newNonce;\n } else {\n localStorage.setItem(\"huggingface.co:oauth:nonce\", newNonce);\n localStorage.setItem(\"huggingface.co:oauth:code_verifier\", newCodeVerifier);\n }\n const redirectUri = (opts == null ? void 0 : opts.redirectUrl) || (typeof window !== \"undefined\" ? window.location.href : void 0);\n if (!redirectUri) {\n throw new Error(\"Missing redirectUrl\");\n }\n const state = JSON.stringify({\n nonce: newNonce,\n redirectUri,\n state: opts == null ? void 0 : opts.state\n });\n const variables = (\n // @ts-expect-error window.huggingface is defined inside static Spaces.\n typeof window !== \"undefined\" ? (_b = (_a = window.huggingface) == null ? void 0 : _a.variables) != null ? _b : null : null\n );\n const clientId = (opts == null ? void 0 : opts.clientId) || (variables == null ? void 0 : variables.OAUTH_CLIENT_ID);\n if (!clientId) {\n if (variables) {\n throw new Error(\"Missing clientId, please add hf_oauth: true to the README.md's metadata in your static Space\");\n }\n throw new Error(\"Missing clientId\");\n }\n const challenge = base64FromBytes(\n new Uint8Array(await globalThis.crypto.subtle.digest(\"SHA-256\", new TextEncoder().encode(newCodeVerifier)))\n ).replace(/[+]/g, \"-\").replace(/[/]/g, \"_\").replace(/=/g, \"\");\n return `${opendidConfig.authorization_endpoint}?${new URLSearchParams({\n client_id: clientId,\n scope: (opts == null ? void 0 : opts.scopes) || (variables == null ? void 0 : variables.OAUTH_SCOPES) || \"openid profile\",\n response_type: \"code\",\n redirect_uri: redirectUri,\n state,\n code_challenge: challenge,\n code_challenge_method: \"S256\"\n }).toString()}`;\n}\n\n// src/utils/typedInclude.ts\nfunction typedInclude(arr, v) {\n return arr.includes(v);\n}\n\n// src/utils/omit.ts\nfunction omit(o, props) {\n const propsArr = Array.isArray(props) ? props : [props];\n const letsKeep = Object.keys(o).filter((prop) => !typedInclude(propsArr, prop));\n return pick(o, letsKeep);\n}\n\n// src/utils/typedEntries.ts\nfunction typedEntries(obj) {\n return Object.entries(obj);\n}\n\n// src/lib/parse-safetensors-metadata.ts\nvar SAFETENSORS_FILE = \"model.safetensors\";\nvar SAFETENSORS_INDEX_FILE = \"model.safetensors.index.json\";\nvar RE_SAFETENSORS_FILE = /\\.safetensors$/;\nvar RE_SAFETENSORS_INDEX_FILE = /\\.safetensors\\.index\\.json$/;\nvar RE_SAFETENSORS_SHARD_FILE = /^(?<prefix>(?<basePrefix>.*?)[_-])(?<shard>\\d{5})-of-(?<total>\\d{5})\\.safetensors$/;\nfunction parseSafetensorsShardFilename(filename) {\n const match = RE_SAFETENSORS_SHARD_FILE.exec(filename);\n if (match && match.groups) {\n return {\n prefix: match.groups[\"prefix\"],\n basePrefix: match.groups[\"basePrefix\"],\n shard: match.groups[\"shard\"],\n total: match.groups[\"total\"]\n };\n }\n return null;\n}\nvar PARALLEL_DOWNLOADS = 20;\nvar MAX_HEADER_LENGTH = 25e6;\nvar SafetensorParseError = class extends Error {\n};\nasync function parseSingleFile(path, params) {\n const firstResp = await downloadFile({\n ...params,\n path,\n range: [0, 7]\n });\n if (!firstResp) {\n throw new SafetensorParseError(`Failed to parse file ${path}: failed to fetch safetensors header length.`);\n }\n const bufLengthOfHeaderLE = await firstResp.arrayBuffer();\n const lengthOfHeader = new DataView(bufLengthOfHeaderLE).getBigUint64(0, true);\n if (lengthOfHeader <= 0) {\n throw new SafetensorParseError(`Failed to parse file ${path}: safetensors header is malformed.`);\n }\n if (lengthOfHeader > MAX_HEADER_LENGTH) {\n throw new SafetensorParseError(\n `Failed to parse file ${path}: safetensor header is too big. Maximum supported size is ${MAX_HEADER_LENGTH} bytes.`\n );\n }\n const secondResp = await downloadFile({ ...params, path, range: [8, 7 + Number(lengthOfHeader)] });\n if (!secondResp) {\n throw new SafetensorParseError(`Failed to parse file ${path}: failed to fetch safetensors header.`);\n }\n try {\n const header = await secondResp.json();\n return header;\n } catch (err) {\n throw new SafetensorParseError(`Failed to parse file ${path}: safetensors header is not valid JSON.`);\n }\n}\nasync function parseShardedIndex(path, params) {\n const indexResp = await downloadFile({\n ...params,\n path,\n range: [0, 1e7]\n });\n if (!indexResp) {\n throw new SafetensorParseError(`Failed to parse file ${path}: failed to fetch safetensors index.`);\n }\n let index;\n try {\n index = await indexResp.json();\n } catch (error) {\n throw new SafetensorParseError(`Failed to parse file ${path}: not a valid JSON.`);\n }\n const pathPrefix = path.slice(0, path.lastIndexOf(\"/\") + 1);\n const filenames = [...new Set(Object.values(index.weight_map))];\n const shardedMap = Object.fromEntries(\n await promisesQueue(\n filenames.map(\n (filename) => async () => [filename, await parseSingleFile(pathPrefix + filename, params)]\n ),\n PARALLEL_DOWNLOADS\n )\n );\n return { index, headers: shardedMap };\n}\nasync function parseSafetensorsMetadata(params) {\n var _a, _b, _c, _d;\n const repoId = toRepoId(params.repo);\n if (repoId.type !== \"model\") {\n throw new TypeError(\"Only model repos should contain safetensors files.\");\n }\n if (RE_SAFETENSORS_FILE.test((_a = params.path) != null ? _a : \"\") || await fileExists({ ...params, path: SAFETENSORS_FILE })) {\n const header = await parseSingleFile((_b = params.path) != null ? _b : SAFETENSORS_FILE, params);\n return {\n sharded: false,\n header,\n ...params.computeParametersCount && {\n parameterCount: computeNumOfParamsByDtypeSingleFile(header)\n }\n };\n } else if (RE_SAFETENSORS_INDEX_FILE.test((_c = params.path) != null ? _c : \"\") || await fileExists({ ...params, path: SAFETENSORS_INDEX_FILE })) {\n const { index, headers } = await parseShardedIndex((_d = params.path) != null ? _d : SAFETENSORS_INDEX_FILE, params);\n return {\n sharded: true,\n index,\n headers,\n ...params.computeParametersCount && {\n parameterCount: computeNumOfParamsByDtypeSharded(headers)\n }\n };\n } else {\n throw new Error(\"model id does not seem to contain safetensors weights\");\n }\n}\nfunction computeNumOfParamsByDtypeSingleFile(header) {\n var _a;\n const counter = {};\n const tensors = omit(header, \"__metadata__\");\n for (const [, v] of typedEntries(tensors)) {\n if (v.shape.length === 0) {\n continue;\n }\n counter[v.dtype] = ((_a = counter[v.dtype]) != null ? _a : 0) + v.shape.reduce((a, b) => a * b);\n }\n return counter;\n}\nfunction computeNumOfParamsByDtypeSharded(shardedMap) {\n var _a;\n const counter = {};\n for (const header of Object.values(shardedMap)) {\n for (const [k, v] of typedEntries(computeNumOfParamsByDtypeSingleFile(header))) {\n counter[k] = ((_a = counter[k]) != null ? _a : 0) + (v != null ? v : 0);\n }\n }\n return counter;\n}\n\n// src/lib/paths-info.ts\nasync function pathsInfo(params) {\n var _a, _b, _c;\n const accessToken = checkCredentials(params);\n const repoId = toRepoId(params.repo);\n const hubUrl = (_a = params.hubUrl) != null ? _a : HUB_URL;\n const url = `${hubUrl}/api/${repoId.type}s/${repoId.name}/paths-info/${encodeURIComponent(\n (_b = params.revision) != null ? _b : \"main\"\n )}`;\n const resp = await ((_c = params.fetch) != null ? _c : fetch)(url, {\n method: \"POST\",\n headers: {\n ...accessToken && {\n Authorization: `Bearer ${accessToken}`\n },\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify({\n paths: params.paths,\n expand: params.expand\n })\n });\n if (!resp.ok) {\n throw await createApiError(resp);\n }\n const json = await resp.json();\n if (!Array.isArray(json))\n throw new Error(\"malformed response: expected array\");\n return json.map((item) => ({\n path: item.path,\n lfs: item.lfs,\n type: item.type,\n oid: item.oid,\n size: item.size,\n // expand fields\n securityFileStatus: item.securityFileStatus,\n lastCommit: item.lastCommit ? {\n date: new Date(item.lastCommit.date),\n title: item.lastCommit.title,\n id: item.lastCommit.id\n } : void 0\n }));\n}\n\n// src/lib/space-info.ts\nasync function spaceInfo(params) {\n var _a, _b, _c;\n const accessToken = params && checkCredentials(params);\n const search = new URLSearchParams([\n ...SPACE_EXPAND_KEYS.map((val) => [\"expand\", val]),\n ...(_b = (_a = params == null ? void 0 : params.additionalFields) == null ? void 0 : _a.map((val) => [\"expand\", val])) != null ? _b : []\n ]).toString();\n const response = await (params.fetch || fetch)(\n `${(params == null ? void 0 : params.hubUrl) || HUB_URL}/api/spaces/${params.name}/revision/${encodeURIComponent(\n (_c = params.revision) != null ? _c : \"HEAD\"\n )}?${search.toString()}`,\n {\n headers: {\n ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},\n Accepts: \"application/json\"\n }\n }\n );\n if (!response.ok) {\n throw await createApiError(response);\n }\n const data = await response.json();\n return {\n ...(params == null ? void 0 : params.additionalFields) && pick(data, params.additionalFields),\n id: data._id,\n name: data.id,\n sdk: data.sdk,\n likes: data.likes,\n private: data.private,\n updatedAt: new Date(data.lastModified)\n };\n}\n\n// src/lib/upload-file.ts\nfunction uploadFile(params) {\n var _a, _b;\n const path = params.file instanceof URL ? (_a = params.file.pathname.split(\"/\").at(-1)) != null ? _a : \"file\" : \"path\" in params.file ? params.file.path : params.file.name;\n return commit({\n ...params.accessToken ? { accessToken: params.accessToken } : { credentials: params.credentials },\n repo: params.repo,\n operations: [\n {\n operation: \"addOrUpdate\",\n path,\n content: \"content\" in params.file ? params.file.content : params.file\n }\n ],\n title: (_b = params.commitTitle) != null ? _b : `Add ${path}`,\n description: params.commitDescription,\n hubUrl: params.hubUrl,\n branch: params.branch,\n isPullRequest: params.isPullRequest,\n parentCommit: params.parentCommit,\n fetch: params.fetch,\n useWebWorkers: params.useWebWorkers,\n abortSignal: params.abortSignal\n });\n}\n\n// src/lib/upload-files.ts\nfunction uploadFiles(params) {\n var _a;\n return commit({\n ...params.accessToken ? { accessToken: params.accessToken } : { credentials: params.credentials },\n repo: params.repo,\n operations: params.files.map((file) => {\n var _a2;\n return {\n operation: \"addOrUpdate\",\n path: file instanceof URL ? (_a2 = file.pathname.split(\"/\").at(-1)) != null ? _a2 : \"file\" : \"path\" in file ? file.path : file.name,\n content: \"content\" in file ? file.content : file\n };\n }),\n title: (_a = params.commitTitle) != null ? _a : `Add ${params.files.length} files`,\n description: params.commitDescription,\n hubUrl: params.hubUrl,\n branch: params.branch,\n isPullRequest: params.isPullRequest,\n parentCommit: params.parentCommit,\n fetch: params.fetch,\n useWebWorkers: params.useWebWorkers,\n abortSignal: params.abortSignal\n });\n}\n\n// src/lib/upload-files-with-progress.ts\nvar multipartUploadTracking = /* @__PURE__ */ new WeakMap();\nasync function* uploadFilesWithProgress(params) {\n var _a;\n return yield* commitIter({\n ...params.accessToken ? { accessToken: params.accessToken } : { credentials: params.credentials },\n repo: params.repo,\n operations: params.files.map((file) => {\n var _a2;\n return {\n operation: \"addOrUpdate\",\n path: file instanceof URL ? (_a2 = file.pathname.split(\"/\").at(-1)) != null ? _a2 : \"file\" : \"path\" in file ? file.path : file.name,\n content: \"content\" in file ? file.content : file\n };\n }),\n title: (_a = params.commitTitle) != null ? _a : `Add ${params.files.length} files`,\n description: params.commitDescription,\n hubUrl: params.hubUrl,\n branch: params.branch,\n isPullRequest: params.isPullRequest,\n parentCommit: params.parentCommit,\n useWebWorkers: params.useWebWorkers,\n abortSignal: params.abortSignal,\n fetch: async (input, init) => {\n var _a2;\n if (!init) {\n return fetch(input);\n }\n if (!typedInclude([\"PUT\", \"POST\"], init.method) || !(\"progressHint\" in init) || !init.progressHint || typeof XMLHttpRequest === \"undefined\" || typeof input !== \"string\" || !(init.body instanceof ArrayBuffer) && !(init.body instanceof Blob) && !(init.body instanceof File) && typeof init.body !== \"string\") {\n return fetch(input, init);\n }\n const progressHint = init.progressHint;\n const progressCallback = progressHint.progressCallback;\n const xhr = new XMLHttpRequest();\n xhr.upload.addEventListener(\"progress\", (event) => {\n if (event.lengthComputable) {\n if (progressHint.part !== void 0) {\n let tracking = multipartUploadTracking.get(progressCallback);\n if (!tracking) {\n tracking = { numParts: progressHint.numParts, partsProgress: {} };\n multipartUploadTracking.set(progressCallback, tracking);\n }\n tracking.partsProgress[progressHint.part] = event.loaded / event.total;\n let totalProgress = 0;\n for (const partProgress of Object.values(tracking.partsProgress)) {\n totalProgress += partProgress;\n }\n if (totalProgress === tracking.numParts) {\n progressCallback(0.9999999999);\n } else {\n progressCallback(totalProgress / tracking.numParts);\n }\n } else {\n if (event.loaded === event.total) {\n progressCallback(0.9999999999);\n } else {\n progressCallback(event.loaded / event.total);\n }\n }\n }\n });\n xhr.open(init.method, input, true);\n if (init.headers) {\n const headers = new Headers(init.headers);\n headers.forEach((value, key) => {\n xhr.setRequestHeader(key, value);\n });\n }\n (_a2 = init.signal) == null ? void 0 : _a2.throwIfAborted();\n xhr.send(init.body);\n return new Promise((resolve2, reject) => {\n xhr.addEventListener(\"load\", () => {\n resolve2(\n new Response(xhr.responseText, {\n status: xhr.status,\n statusText: xhr.statusText,\n headers: Object.fromEntries(\n xhr.getAllResponseHeaders().trim().split(\"\\n\").map((header) => [header.slice(0, header.indexOf(\":\")), header.slice(header.indexOf(\":\") + 1).trim()])\n )\n })\n );\n });\n xhr.addEventListener(\"error\", () => {\n reject(new Error(xhr.statusText));\n });\n if (init.signal) {\n init.signal.addEventListener(\"abort\", () => {\n var _a3;\n xhr.abort();\n try {\n (_a3 = init.signal) == null ? void 0 : _a3.throwIfAborted();\n } catch (err) {\n reject(err);\n }\n });\n }\n });\n }\n });\n}\n\n// src/lib/who-am-i.ts\nasync function whoAmI(params) {\n var _a, _b, _c;\n const accessToken = checkCredentials(params);\n const res = await ((_a = params.fetch) != null ? _a : fetch)(`${(_b = params.hubUrl) != null ? _b : HUB_URL}/api/whoami-v2`, {\n headers: {\n Authorization: `Bearer ${accessToken}`\n }\n });\n if (!res.ok) {\n throw await createApiError(res);\n }\n const response = await res.json();\n if (typeof ((_c = response.auth.accessToken) == null ? void 0 : _c.createdAt) === \"string\") {\n response.auth.accessToken.createdAt = new Date(response.auth.accessToken.createdAt);\n }\n return response;\n}\nexport {\n DATASET_EXPANDABLE_KEYS,\n DATASET_EXPAND_KEYS,\n HubApiError,\n InvalidApiResponseFormatError,\n MODEL_EXPANDABLE_KEYS,\n MODEL_EXPAND_KEYS,\n RE_SAFETENSORS_FILE,\n RE_SAFETENSORS_INDEX_FILE,\n RE_SAFETENSORS_SHARD_FILE,\n SAFETENSORS_FILE,\n SAFETENSORS_INDEX_FILE,\n SPACE_EXPANDABLE_KEYS,\n SPACE_EXPAND_KEYS,\n sha256 as __internal_sha256,\n checkRepoAccess,\n commit,\n commitIter,\n countCommits,\n createRepo,\n datasetInfo,\n deleteFile,\n deleteFiles,\n deleteRepo,\n downloadFile,\n fileDownloadInfo,\n fileExists,\n listCommits,\n listDatasets,\n listFiles,\n listModels,\n listSpaces,\n modelInfo,\n oauthHandleRedirect,\n oauthHandleRedirectIfPresent,\n oauthLoginUrl,\n parseSafetensorsMetadata,\n parseSafetensorsShardFilename,\n pathsInfo,\n spaceInfo,\n uploadFile,\n uploadFiles,\n uploadFilesWithProgress,\n whoAmI\n};\n","import { oauthLoginUrl, oauthHandleRedirectIfPresent } from \"@huggingface/hub\";\n\n// Get UI elements\nconst signinButton = document.getElementById(\"signin\") as HTMLImageElement;\nconst signoutButton = document.getElementById(\"signout\") as HTMLButtonElement;\nconst preElement = document.querySelector(\"pre\") as HTMLPreElement;\n\n// Show/hide UI elements based on auth state\nfunction updateUI(isLoggedIn: boolean) {\n signinButton.style.display = isLoggedIn ? \"none\" : \"block\";\n signoutButton.style.display = isLoggedIn ? \"block\" : \"none\";\n}\n\nasync function handleOAuth() {\n try {\n const oauthResult = await oauthHandleRedirectIfPresent();\n\n if (oauthResult) {\n // We have OAuth results, display them\n preElement.textContent = JSON.stringify(oauthResult, null, 2);\n updateUI(true);\n } else {\n // No OAuth results, show sign-in button\n updateUI(false);\n }\n\n return oauthResult;\n } catch (error) {\n console.error(\"OAuth error:\", error);\n preElement.textContent = \"Error: \" + (error as Error).message;\n updateUI(false);\n throw error;\n }\n}\n\n// Handle sign-in click\nsigninButton.addEventListener(\"click\", async () => {\n const loginUrl = await oauthLoginUrl();\n window.location.href = loginUrl;\n});\n\n// Handle sign-out click\nsignoutButton.addEventListener(\"click\", () => {\n // Clear the display and reset UI\n preElement.textContent = \"\";\n updateUI(false);\n // You might want to add additional logout logic here\n});\n\n// Initialize OAuth handling\nhandleOAuth().catch(console.error);\n"],"names":["__defProp","__defNormalProp","obj","key","value","__publicField","HUB_URL","createApiError","response","opts","_a","_b","error","HubApiError","trailer","json","url","statusCode","requestId","message","r","base64FromBytes","arr","bin","byte","oauthHandleRedirect","_c","redirectedUrl","searchParams","errorDescription","code","nonce","codeVerifier","state","parsedState","hubUrl","openidConfigUrl","openidConfigRes","openidConfig","tokenRes","token","accessTokenExpiresAt","userInfoRes","userInfo","oauthHandleRedirectIfPresent","oauthLoginUrl","opendidConfig","newNonce","newCodeVerifier","redirectUri","variables","clientId","challenge","signinButton","signoutButton","preElement","updateUI","isLoggedIn","handleOAuth","oauthResult","loginUrl"],"mappings":"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","x_google_ignoreList":[0,1]}
dist/index.html CHANGED
@@ -1,35 +1,21 @@
1
  <!DOCTYPE html>
2
- <html lang="en">
3
 
4
- <head>
5
- <meta charset="UTF-8">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <title>HF OAuth Demo</title>
8
- <link rel="stylesheet" href="styles.css">
9
- </head>
10
 
11
  <body>
12
- <div class="container">
13
- <h1>Welcome to HF OAuth Demo</h1>
14
-
15
- <!-- Login section (shown when logged out) -->
16
- <div id="login-section">
17
- <button id="login-button" class="btn">Sign in with Hugging Face</button>
18
- </div>
19
-
20
- <!-- Profile section (shown when logged in) -->
21
- <div id="profile-section" style="display: none;">
22
- <div class="profile-info">
23
- <img id="avatar" class="avatar" src="" alt="Profile picture">
24
- <h2 id="username"></h2>
25
- </div>
26
- <button id="logout-button" class="btn">Logout</button>
27
- </div>
28
  </div>
29
-
30
- <!-- Load HuggingFace.js -->
31
- <script src="https://unpkg.com/@huggingface/[email protected]/dist/hub.min.js"></script>
32
- <script type="module" src="./app.js"></script>
33
  </body>
34
 
35
  </html>
 
1
  <!DOCTYPE html>
2
+ <html>
3
 
4
+ <script type="module" crossorigin src="/assets/index-DH6LWxsk.js"></script>
 
 
 
 
 
5
 
6
  <body>
7
+ <div class="card" style="margin-bottom: 2rem;">
8
+ <h1>OAuth in a static Space</h1>
9
+ <p>Checkout the <a href="https://huggingface.co/spaces/huggingfacejs/client-side-oauth/blob/main/index.html"
10
+ target="_blank">index.html</a> file to see the few lines of code
11
+ enabling this space</p>
12
+ <p>After clicking "Signin with HF", you will be redirected to this space and the access token + user info will
13
+ be displayed.</p>
 
 
 
 
 
 
 
 
 
14
  </div>
15
+ <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-xl-dark.svg"
16
+ alt="Sign in with Hugging Face" style="cursor: pointer; display: none;" id="signin">
17
+ <button id="signout" style="display: none">Sign out</button>
18
+ <pre></pre>
19
  </body>
20
 
21
  </html>
dist/index.js DELETED
@@ -1,31 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { oauthLoginUrl, oauthHandleRedirectIfPresent } from "@huggingface/hub";
11
- function handleOAuth() {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- try {
14
- const oauthResult = yield oauthHandleRedirectIfPresent();
15
- console.log({ oauthResult });
16
- if (!oauthResult) {
17
- // If no OAuth result, we need to initiate the login
18
- const loginUrl = yield oauthLoginUrl();
19
- window.location.href = loginUrl;
20
- }
21
- return oauthResult;
22
- }
23
- catch (error) {
24
- console.error("OAuth error:", error);
25
- throw error;
26
- }
27
- });
28
- }
29
- // Initialize OAuth handling
30
- handleOAuth().catch(console.error);
31
- //# sourceMappingURL=index.js.map
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAE/E,SAAe,WAAW;;QACxB,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,MAAM,4BAA4B,EAAE,CAAC;YACzD,OAAO,CAAC,GAAG,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;YAE7B,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,oDAAoD;gBACpD,MAAM,QAAQ,GAAG,MAAM,aAAa,EAAE,CAAC;gBACvC,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC;YAClC,CAAC;YAED,OAAO,WAAW,CAAC;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;YACrC,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CAAA;AAED,4BAA4B;AAC5B,WAAW,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
 
 
dist/styles.css DELETED
@@ -1,68 +0,0 @@
1
- * {
2
- margin: 0;
3
- padding: 0;
4
- box-sizing: border-box;
5
- }
6
-
7
- body {
8
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
9
- Ubuntu, Cantarell, sans-serif;
10
- line-height: 1.6;
11
- background-color: #f5f8fa;
12
- color: #333;
13
- }
14
-
15
- .container {
16
- max-width: 800px;
17
- margin: 2rem auto;
18
- padding: 2rem;
19
- background-color: white;
20
- border-radius: 10px;
21
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
22
- text-align: center;
23
- }
24
-
25
- h1 {
26
- margin-bottom: 2rem;
27
- color: #2d3748;
28
- }
29
-
30
- .btn {
31
- background-color: #4a5568;
32
- color: white;
33
- padding: 0.75rem 1.5rem;
34
- border: none;
35
- border-radius: 5px;
36
- font-size: 1rem;
37
- cursor: pointer;
38
- transition: background-color 0.2s;
39
- }
40
-
41
- .btn:hover {
42
- background-color: #2d3748;
43
- }
44
-
45
- .profile-info {
46
- margin: 2rem 0;
47
- }
48
-
49
- .avatar {
50
- width: 100px;
51
- height: 100px;
52
- border-radius: 50%;
53
- margin-bottom: 1rem;
54
- }
55
-
56
- #username {
57
- color: #2d3748;
58
- font-size: 1.5rem;
59
- margin-bottom: 1rem;
60
- }
61
-
62
- #logout-button {
63
- background-color: #e53e3e;
64
- }
65
-
66
- #logout-button:hover {
67
- background-color: #c53030;
68
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
index.html CHANGED
@@ -13,10 +13,8 @@
13
  <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-xl-dark.svg"
14
  alt="Sign in with Hugging Face" style="cursor: pointer; display: none;" id="signin">
15
  <button id="signout" style="display: none">Sign out</button>
16
- <pre>
17
-
18
- </pre>
19
- <script type="module" src="dist/index.js"></script>
20
  </body>
21
 
22
  </html>
 
13
  <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-xl-dark.svg"
14
  alt="Sign in with Hugging Face" style="cursor: pointer; display: none;" id="signin">
15
  <button id="signout" style="display: none">Sign out</button>
16
+ <pre></pre>
17
+ <script type="module" src="/src/index.ts"></script>
 
 
18
  </body>
19
 
20
  </html>
package-lock.json CHANGED
@@ -12,7 +12,408 @@
12
  "typescript": "^5.7.3"
13
  },
14
  "devDependencies": {
15
- "@types/node": "^22.13.1"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  }
17
  },
18
  "node_modules/@huggingface/hub": {
@@ -31,6 +432,259 @@
31
  "resolved": "https://registry.npmjs.org/@huggingface/tasks/-/tasks-0.15.9.tgz",
32
  "integrity": "sha512-cbnZcpMHKdhURWIplVP4obHxAZcxjyRm0zI7peTPksZN4CtIOMmJC4ZqGEymo0lk+0VNkXD7ULwFJ3JjT/VpkQ=="
33
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  "node_modules/@types/node": {
35
  "version": "22.13.1",
36
  "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.1.tgz",
@@ -40,6 +694,159 @@
40
  "undici-types": "~6.20.0"
41
  }
42
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  "node_modules/typescript": {
44
  "version": "5.7.3",
45
  "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz",
@@ -57,6 +864,77 @@
57
  "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
58
  "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
59
  "dev": true
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  }
61
  }
62
  }
 
12
  "typescript": "^5.7.3"
13
  },
14
  "devDependencies": {
15
+ "@types/node": "^22.13.1",
16
+ "vite": "^6.1.0"
17
+ }
18
+ },
19
+ "node_modules/@esbuild/aix-ppc64": {
20
+ "version": "0.24.2",
21
+ "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.24.2.tgz",
22
+ "integrity": "sha512-thpVCb/rhxE/BnMLQ7GReQLLN8q9qbHmI55F4489/ByVg2aQaQ6kbcLb6FHkocZzQhxc4gx0sCk0tJkKBFzDhA==",
23
+ "cpu": [
24
+ "ppc64"
25
+ ],
26
+ "dev": true,
27
+ "optional": true,
28
+ "os": [
29
+ "aix"
30
+ ],
31
+ "engines": {
32
+ "node": ">=18"
33
+ }
34
+ },
35
+ "node_modules/@esbuild/android-arm": {
36
+ "version": "0.24.2",
37
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.24.2.tgz",
38
+ "integrity": "sha512-tmwl4hJkCfNHwFB3nBa8z1Uy3ypZpxqxfTQOcHX+xRByyYgunVbZ9MzUUfb0RxaHIMnbHagwAxuTL+tnNM+1/Q==",
39
+ "cpu": [
40
+ "arm"
41
+ ],
42
+ "dev": true,
43
+ "optional": true,
44
+ "os": [
45
+ "android"
46
+ ],
47
+ "engines": {
48
+ "node": ">=18"
49
+ }
50
+ },
51
+ "node_modules/@esbuild/android-arm64": {
52
+ "version": "0.24.2",
53
+ "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.24.2.tgz",
54
+ "integrity": "sha512-cNLgeqCqV8WxfcTIOeL4OAtSmL8JjcN6m09XIgro1Wi7cF4t/THaWEa7eL5CMoMBdjoHOTh/vwTO/o2TRXIyzg==",
55
+ "cpu": [
56
+ "arm64"
57
+ ],
58
+ "dev": true,
59
+ "optional": true,
60
+ "os": [
61
+ "android"
62
+ ],
63
+ "engines": {
64
+ "node": ">=18"
65
+ }
66
+ },
67
+ "node_modules/@esbuild/android-x64": {
68
+ "version": "0.24.2",
69
+ "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.24.2.tgz",
70
+ "integrity": "sha512-B6Q0YQDqMx9D7rvIcsXfmJfvUYLoP722bgfBlO5cGvNVb5V/+Y7nhBE3mHV9OpxBf4eAS2S68KZztiPaWq4XYw==",
71
+ "cpu": [
72
+ "x64"
73
+ ],
74
+ "dev": true,
75
+ "optional": true,
76
+ "os": [
77
+ "android"
78
+ ],
79
+ "engines": {
80
+ "node": ">=18"
81
+ }
82
+ },
83
+ "node_modules/@esbuild/darwin-arm64": {
84
+ "version": "0.24.2",
85
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.24.2.tgz",
86
+ "integrity": "sha512-kj3AnYWc+CekmZnS5IPu9D+HWtUI49hbnyqk0FLEJDbzCIQt7hg7ucF1SQAilhtYpIujfaHr6O0UHlzzSPdOeA==",
87
+ "cpu": [
88
+ "arm64"
89
+ ],
90
+ "dev": true,
91
+ "optional": true,
92
+ "os": [
93
+ "darwin"
94
+ ],
95
+ "engines": {
96
+ "node": ">=18"
97
+ }
98
+ },
99
+ "node_modules/@esbuild/darwin-x64": {
100
+ "version": "0.24.2",
101
+ "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.24.2.tgz",
102
+ "integrity": "sha512-WeSrmwwHaPkNR5H3yYfowhZcbriGqooyu3zI/3GGpF8AyUdsrrP0X6KumITGA9WOyiJavnGZUwPGvxvwfWPHIA==",
103
+ "cpu": [
104
+ "x64"
105
+ ],
106
+ "dev": true,
107
+ "optional": true,
108
+ "os": [
109
+ "darwin"
110
+ ],
111
+ "engines": {
112
+ "node": ">=18"
113
+ }
114
+ },
115
+ "node_modules/@esbuild/freebsd-arm64": {
116
+ "version": "0.24.2",
117
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.24.2.tgz",
118
+ "integrity": "sha512-UN8HXjtJ0k/Mj6a9+5u6+2eZ2ERD7Edt1Q9IZiB5UZAIdPnVKDoG7mdTVGhHJIeEml60JteamR3qhsr1r8gXvg==",
119
+ "cpu": [
120
+ "arm64"
121
+ ],
122
+ "dev": true,
123
+ "optional": true,
124
+ "os": [
125
+ "freebsd"
126
+ ],
127
+ "engines": {
128
+ "node": ">=18"
129
+ }
130
+ },
131
+ "node_modules/@esbuild/freebsd-x64": {
132
+ "version": "0.24.2",
133
+ "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.24.2.tgz",
134
+ "integrity": "sha512-TvW7wE/89PYW+IevEJXZ5sF6gJRDY/14hyIGFXdIucxCsbRmLUcjseQu1SyTko+2idmCw94TgyaEZi9HUSOe3Q==",
135
+ "cpu": [
136
+ "x64"
137
+ ],
138
+ "dev": true,
139
+ "optional": true,
140
+ "os": [
141
+ "freebsd"
142
+ ],
143
+ "engines": {
144
+ "node": ">=18"
145
+ }
146
+ },
147
+ "node_modules/@esbuild/linux-arm": {
148
+ "version": "0.24.2",
149
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.24.2.tgz",
150
+ "integrity": "sha512-n0WRM/gWIdU29J57hJyUdIsk0WarGd6To0s+Y+LwvlC55wt+GT/OgkwoXCXvIue1i1sSNWblHEig00GBWiJgfA==",
151
+ "cpu": [
152
+ "arm"
153
+ ],
154
+ "dev": true,
155
+ "optional": true,
156
+ "os": [
157
+ "linux"
158
+ ],
159
+ "engines": {
160
+ "node": ">=18"
161
+ }
162
+ },
163
+ "node_modules/@esbuild/linux-arm64": {
164
+ "version": "0.24.2",
165
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.24.2.tgz",
166
+ "integrity": "sha512-7HnAD6074BW43YvvUmE/35Id9/NB7BeX5EoNkK9obndmZBUk8xmJJeU7DwmUeN7tkysslb2eSl6CTrYz6oEMQg==",
167
+ "cpu": [
168
+ "arm64"
169
+ ],
170
+ "dev": true,
171
+ "optional": true,
172
+ "os": [
173
+ "linux"
174
+ ],
175
+ "engines": {
176
+ "node": ">=18"
177
+ }
178
+ },
179
+ "node_modules/@esbuild/linux-ia32": {
180
+ "version": "0.24.2",
181
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.24.2.tgz",
182
+ "integrity": "sha512-sfv0tGPQhcZOgTKO3oBE9xpHuUqguHvSo4jl+wjnKwFpapx+vUDcawbwPNuBIAYdRAvIDBfZVvXprIj3HA+Ugw==",
183
+ "cpu": [
184
+ "ia32"
185
+ ],
186
+ "dev": true,
187
+ "optional": true,
188
+ "os": [
189
+ "linux"
190
+ ],
191
+ "engines": {
192
+ "node": ">=18"
193
+ }
194
+ },
195
+ "node_modules/@esbuild/linux-loong64": {
196
+ "version": "0.24.2",
197
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.24.2.tgz",
198
+ "integrity": "sha512-CN9AZr8kEndGooS35ntToZLTQLHEjtVB5n7dl8ZcTZMonJ7CCfStrYhrzF97eAecqVbVJ7APOEe18RPI4KLhwQ==",
199
+ "cpu": [
200
+ "loong64"
201
+ ],
202
+ "dev": true,
203
+ "optional": true,
204
+ "os": [
205
+ "linux"
206
+ ],
207
+ "engines": {
208
+ "node": ">=18"
209
+ }
210
+ },
211
+ "node_modules/@esbuild/linux-mips64el": {
212
+ "version": "0.24.2",
213
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.24.2.tgz",
214
+ "integrity": "sha512-iMkk7qr/wl3exJATwkISxI7kTcmHKE+BlymIAbHO8xanq/TjHaaVThFF6ipWzPHryoFsesNQJPE/3wFJw4+huw==",
215
+ "cpu": [
216
+ "mips64el"
217
+ ],
218
+ "dev": true,
219
+ "optional": true,
220
+ "os": [
221
+ "linux"
222
+ ],
223
+ "engines": {
224
+ "node": ">=18"
225
+ }
226
+ },
227
+ "node_modules/@esbuild/linux-ppc64": {
228
+ "version": "0.24.2",
229
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.24.2.tgz",
230
+ "integrity": "sha512-shsVrgCZ57Vr2L8mm39kO5PPIb+843FStGt7sGGoqiiWYconSxwTiuswC1VJZLCjNiMLAMh34jg4VSEQb+iEbw==",
231
+ "cpu": [
232
+ "ppc64"
233
+ ],
234
+ "dev": true,
235
+ "optional": true,
236
+ "os": [
237
+ "linux"
238
+ ],
239
+ "engines": {
240
+ "node": ">=18"
241
+ }
242
+ },
243
+ "node_modules/@esbuild/linux-riscv64": {
244
+ "version": "0.24.2",
245
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.24.2.tgz",
246
+ "integrity": "sha512-4eSFWnU9Hhd68fW16GD0TINewo1L6dRrB+oLNNbYyMUAeOD2yCK5KXGK1GH4qD/kT+bTEXjsyTCiJGHPZ3eM9Q==",
247
+ "cpu": [
248
+ "riscv64"
249
+ ],
250
+ "dev": true,
251
+ "optional": true,
252
+ "os": [
253
+ "linux"
254
+ ],
255
+ "engines": {
256
+ "node": ">=18"
257
+ }
258
+ },
259
+ "node_modules/@esbuild/linux-s390x": {
260
+ "version": "0.24.2",
261
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.24.2.tgz",
262
+ "integrity": "sha512-S0Bh0A53b0YHL2XEXC20bHLuGMOhFDO6GN4b3YjRLK//Ep3ql3erpNcPlEFed93hsQAjAQDNsvcK+hV90FubSw==",
263
+ "cpu": [
264
+ "s390x"
265
+ ],
266
+ "dev": true,
267
+ "optional": true,
268
+ "os": [
269
+ "linux"
270
+ ],
271
+ "engines": {
272
+ "node": ">=18"
273
+ }
274
+ },
275
+ "node_modules/@esbuild/linux-x64": {
276
+ "version": "0.24.2",
277
+ "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.24.2.tgz",
278
+ "integrity": "sha512-8Qi4nQcCTbLnK9WoMjdC9NiTG6/E38RNICU6sUNqK0QFxCYgoARqVqxdFmWkdonVsvGqWhmm7MO0jyTqLqwj0Q==",
279
+ "cpu": [
280
+ "x64"
281
+ ],
282
+ "dev": true,
283
+ "optional": true,
284
+ "os": [
285
+ "linux"
286
+ ],
287
+ "engines": {
288
+ "node": ">=18"
289
+ }
290
+ },
291
+ "node_modules/@esbuild/netbsd-arm64": {
292
+ "version": "0.24.2",
293
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.24.2.tgz",
294
+ "integrity": "sha512-wuLK/VztRRpMt9zyHSazyCVdCXlpHkKm34WUyinD2lzK07FAHTq0KQvZZlXikNWkDGoT6x3TD51jKQ7gMVpopw==",
295
+ "cpu": [
296
+ "arm64"
297
+ ],
298
+ "dev": true,
299
+ "optional": true,
300
+ "os": [
301
+ "netbsd"
302
+ ],
303
+ "engines": {
304
+ "node": ">=18"
305
+ }
306
+ },
307
+ "node_modules/@esbuild/netbsd-x64": {
308
+ "version": "0.24.2",
309
+ "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.24.2.tgz",
310
+ "integrity": "sha512-VefFaQUc4FMmJuAxmIHgUmfNiLXY438XrL4GDNV1Y1H/RW3qow68xTwjZKfj/+Plp9NANmzbH5R40Meudu8mmw==",
311
+ "cpu": [
312
+ "x64"
313
+ ],
314
+ "dev": true,
315
+ "optional": true,
316
+ "os": [
317
+ "netbsd"
318
+ ],
319
+ "engines": {
320
+ "node": ">=18"
321
+ }
322
+ },
323
+ "node_modules/@esbuild/openbsd-arm64": {
324
+ "version": "0.24.2",
325
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.24.2.tgz",
326
+ "integrity": "sha512-YQbi46SBct6iKnszhSvdluqDmxCJA+Pu280Av9WICNwQmMxV7nLRHZfjQzwbPs3jeWnuAhE9Jy0NrnJ12Oz+0A==",
327
+ "cpu": [
328
+ "arm64"
329
+ ],
330
+ "dev": true,
331
+ "optional": true,
332
+ "os": [
333
+ "openbsd"
334
+ ],
335
+ "engines": {
336
+ "node": ">=18"
337
+ }
338
+ },
339
+ "node_modules/@esbuild/openbsd-x64": {
340
+ "version": "0.24.2",
341
+ "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.24.2.tgz",
342
+ "integrity": "sha512-+iDS6zpNM6EnJyWv0bMGLWSWeXGN/HTaF/LXHXHwejGsVi+ooqDfMCCTerNFxEkM3wYVcExkeGXNqshc9iMaOA==",
343
+ "cpu": [
344
+ "x64"
345
+ ],
346
+ "dev": true,
347
+ "optional": true,
348
+ "os": [
349
+ "openbsd"
350
+ ],
351
+ "engines": {
352
+ "node": ">=18"
353
+ }
354
+ },
355
+ "node_modules/@esbuild/sunos-x64": {
356
+ "version": "0.24.2",
357
+ "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.24.2.tgz",
358
+ "integrity": "sha512-hTdsW27jcktEvpwNHJU4ZwWFGkz2zRJUz8pvddmXPtXDzVKTTINmlmga3ZzwcuMpUvLw7JkLy9QLKyGpD2Yxig==",
359
+ "cpu": [
360
+ "x64"
361
+ ],
362
+ "dev": true,
363
+ "optional": true,
364
+ "os": [
365
+ "sunos"
366
+ ],
367
+ "engines": {
368
+ "node": ">=18"
369
+ }
370
+ },
371
+ "node_modules/@esbuild/win32-arm64": {
372
+ "version": "0.24.2",
373
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.24.2.tgz",
374
+ "integrity": "sha512-LihEQ2BBKVFLOC9ZItT9iFprsE9tqjDjnbulhHoFxYQtQfai7qfluVODIYxt1PgdoyQkz23+01rzwNwYfutxUQ==",
375
+ "cpu": [
376
+ "arm64"
377
+ ],
378
+ "dev": true,
379
+ "optional": true,
380
+ "os": [
381
+ "win32"
382
+ ],
383
+ "engines": {
384
+ "node": ">=18"
385
+ }
386
+ },
387
+ "node_modules/@esbuild/win32-ia32": {
388
+ "version": "0.24.2",
389
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.24.2.tgz",
390
+ "integrity": "sha512-q+iGUwfs8tncmFC9pcnD5IvRHAzmbwQ3GPS5/ceCyHdjXubwQWI12MKWSNSMYLJMq23/IUCvJMS76PDqXe1fxA==",
391
+ "cpu": [
392
+ "ia32"
393
+ ],
394
+ "dev": true,
395
+ "optional": true,
396
+ "os": [
397
+ "win32"
398
+ ],
399
+ "engines": {
400
+ "node": ">=18"
401
+ }
402
+ },
403
+ "node_modules/@esbuild/win32-x64": {
404
+ "version": "0.24.2",
405
+ "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.24.2.tgz",
406
+ "integrity": "sha512-7VTgWzgMGvup6aSqDPLiW5zHaxYJGTO4OokMjIlrCtf+VpEL+cXKtCvg723iguPYI5oaUNdS+/V7OU2gvXVWEg==",
407
+ "cpu": [
408
+ "x64"
409
+ ],
410
+ "dev": true,
411
+ "optional": true,
412
+ "os": [
413
+ "win32"
414
+ ],
415
+ "engines": {
416
+ "node": ">=18"
417
  }
418
  },
419
  "node_modules/@huggingface/hub": {
 
432
  "resolved": "https://registry.npmjs.org/@huggingface/tasks/-/tasks-0.15.9.tgz",
433
  "integrity": "sha512-cbnZcpMHKdhURWIplVP4obHxAZcxjyRm0zI7peTPksZN4CtIOMmJC4ZqGEymo0lk+0VNkXD7ULwFJ3JjT/VpkQ=="
434
  },
435
+ "node_modules/@rollup/rollup-android-arm-eabi": {
436
+ "version": "4.34.6",
437
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.34.6.tgz",
438
+ "integrity": "sha512-+GcCXtOQoWuC7hhX1P00LqjjIiS/iOouHXhMdiDSnq/1DGTox4SpUvO52Xm+div6+106r+TcvOeo/cxvyEyTgg==",
439
+ "cpu": [
440
+ "arm"
441
+ ],
442
+ "dev": true,
443
+ "optional": true,
444
+ "os": [
445
+ "android"
446
+ ]
447
+ },
448
+ "node_modules/@rollup/rollup-android-arm64": {
449
+ "version": "4.34.6",
450
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.34.6.tgz",
451
+ "integrity": "sha512-E8+2qCIjciYUnCa1AiVF1BkRgqIGW9KzJeesQqVfyRITGQN+dFuoivO0hnro1DjT74wXLRZ7QF8MIbz+luGaJA==",
452
+ "cpu": [
453
+ "arm64"
454
+ ],
455
+ "dev": true,
456
+ "optional": true,
457
+ "os": [
458
+ "android"
459
+ ]
460
+ },
461
+ "node_modules/@rollup/rollup-darwin-arm64": {
462
+ "version": "4.34.6",
463
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.34.6.tgz",
464
+ "integrity": "sha512-z9Ib+OzqN3DZEjX7PDQMHEhtF+t6Mi2z/ueChQPLS/qUMKY7Ybn5A2ggFoKRNRh1q1T03YTQfBTQCJZiepESAg==",
465
+ "cpu": [
466
+ "arm64"
467
+ ],
468
+ "dev": true,
469
+ "optional": true,
470
+ "os": [
471
+ "darwin"
472
+ ]
473
+ },
474
+ "node_modules/@rollup/rollup-darwin-x64": {
475
+ "version": "4.34.6",
476
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.34.6.tgz",
477
+ "integrity": "sha512-PShKVY4u0FDAR7jskyFIYVyHEPCPnIQY8s5OcXkdU8mz3Y7eXDJPdyM/ZWjkYdR2m0izD9HHWA8sGcXn+Qrsyg==",
478
+ "cpu": [
479
+ "x64"
480
+ ],
481
+ "dev": true,
482
+ "optional": true,
483
+ "os": [
484
+ "darwin"
485
+ ]
486
+ },
487
+ "node_modules/@rollup/rollup-freebsd-arm64": {
488
+ "version": "4.34.6",
489
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.34.6.tgz",
490
+ "integrity": "sha512-YSwyOqlDAdKqs0iKuqvRHLN4SrD2TiswfoLfvYXseKbL47ht1grQpq46MSiQAx6rQEN8o8URtpXARCpqabqxGQ==",
491
+ "cpu": [
492
+ "arm64"
493
+ ],
494
+ "dev": true,
495
+ "optional": true,
496
+ "os": [
497
+ "freebsd"
498
+ ]
499
+ },
500
+ "node_modules/@rollup/rollup-freebsd-x64": {
501
+ "version": "4.34.6",
502
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.34.6.tgz",
503
+ "integrity": "sha512-HEP4CgPAY1RxXwwL5sPFv6BBM3tVeLnshF03HMhJYCNc6kvSqBgTMmsEjb72RkZBAWIqiPUyF1JpEBv5XT9wKQ==",
504
+ "cpu": [
505
+ "x64"
506
+ ],
507
+ "dev": true,
508
+ "optional": true,
509
+ "os": [
510
+ "freebsd"
511
+ ]
512
+ },
513
+ "node_modules/@rollup/rollup-linux-arm-gnueabihf": {
514
+ "version": "4.34.6",
515
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.34.6.tgz",
516
+ "integrity": "sha512-88fSzjC5xeH9S2Vg3rPgXJULkHcLYMkh8faix8DX4h4TIAL65ekwuQMA/g2CXq8W+NJC43V6fUpYZNjaX3+IIg==",
517
+ "cpu": [
518
+ "arm"
519
+ ],
520
+ "dev": true,
521
+ "optional": true,
522
+ "os": [
523
+ "linux"
524
+ ]
525
+ },
526
+ "node_modules/@rollup/rollup-linux-arm-musleabihf": {
527
+ "version": "4.34.6",
528
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.34.6.tgz",
529
+ "integrity": "sha512-wM4ztnutBqYFyvNeR7Av+reWI/enK9tDOTKNF+6Kk2Q96k9bwhDDOlnCUNRPvromlVXo04riSliMBs/Z7RteEg==",
530
+ "cpu": [
531
+ "arm"
532
+ ],
533
+ "dev": true,
534
+ "optional": true,
535
+ "os": [
536
+ "linux"
537
+ ]
538
+ },
539
+ "node_modules/@rollup/rollup-linux-arm64-gnu": {
540
+ "version": "4.34.6",
541
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.34.6.tgz",
542
+ "integrity": "sha512-9RyprECbRa9zEjXLtvvshhw4CMrRa3K+0wcp3KME0zmBe1ILmvcVHnypZ/aIDXpRyfhSYSuN4EPdCCj5Du8FIA==",
543
+ "cpu": [
544
+ "arm64"
545
+ ],
546
+ "dev": true,
547
+ "optional": true,
548
+ "os": [
549
+ "linux"
550
+ ]
551
+ },
552
+ "node_modules/@rollup/rollup-linux-arm64-musl": {
553
+ "version": "4.34.6",
554
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.34.6.tgz",
555
+ "integrity": "sha512-qTmklhCTyaJSB05S+iSovfo++EwnIEZxHkzv5dep4qoszUMX5Ca4WM4zAVUMbfdviLgCSQOu5oU8YoGk1s6M9Q==",
556
+ "cpu": [
557
+ "arm64"
558
+ ],
559
+ "dev": true,
560
+ "optional": true,
561
+ "os": [
562
+ "linux"
563
+ ]
564
+ },
565
+ "node_modules/@rollup/rollup-linux-loongarch64-gnu": {
566
+ "version": "4.34.6",
567
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loongarch64-gnu/-/rollup-linux-loongarch64-gnu-4.34.6.tgz",
568
+ "integrity": "sha512-4Qmkaps9yqmpjY5pvpkfOerYgKNUGzQpFxV6rnS7c/JfYbDSU0y6WpbbredB5cCpLFGJEqYX40WUmxMkwhWCjw==",
569
+ "cpu": [
570
+ "loong64"
571
+ ],
572
+ "dev": true,
573
+ "optional": true,
574
+ "os": [
575
+ "linux"
576
+ ]
577
+ },
578
+ "node_modules/@rollup/rollup-linux-powerpc64le-gnu": {
579
+ "version": "4.34.6",
580
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.34.6.tgz",
581
+ "integrity": "sha512-Zsrtux3PuaxuBTX/zHdLaFmcofWGzaWW1scwLU3ZbW/X+hSsFbz9wDIp6XvnT7pzYRl9MezWqEqKy7ssmDEnuQ==",
582
+ "cpu": [
583
+ "ppc64"
584
+ ],
585
+ "dev": true,
586
+ "optional": true,
587
+ "os": [
588
+ "linux"
589
+ ]
590
+ },
591
+ "node_modules/@rollup/rollup-linux-riscv64-gnu": {
592
+ "version": "4.34.6",
593
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.34.6.tgz",
594
+ "integrity": "sha512-aK+Zp+CRM55iPrlyKiU3/zyhgzWBxLVrw2mwiQSYJRobCURb781+XstzvA8Gkjg/hbdQFuDw44aUOxVQFycrAg==",
595
+ "cpu": [
596
+ "riscv64"
597
+ ],
598
+ "dev": true,
599
+ "optional": true,
600
+ "os": [
601
+ "linux"
602
+ ]
603
+ },
604
+ "node_modules/@rollup/rollup-linux-s390x-gnu": {
605
+ "version": "4.34.6",
606
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.34.6.tgz",
607
+ "integrity": "sha512-WoKLVrY9ogmaYPXwTH326+ErlCIgMmsoRSx6bO+l68YgJnlOXhygDYSZe/qbUJCSiCiZAQ+tKm88NcWuUXqOzw==",
608
+ "cpu": [
609
+ "s390x"
610
+ ],
611
+ "dev": true,
612
+ "optional": true,
613
+ "os": [
614
+ "linux"
615
+ ]
616
+ },
617
+ "node_modules/@rollup/rollup-linux-x64-gnu": {
618
+ "version": "4.34.6",
619
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.34.6.tgz",
620
+ "integrity": "sha512-Sht4aFvmA4ToHd2vFzwMFaQCiYm2lDFho5rPcvPBT5pCdC+GwHG6CMch4GQfmWTQ1SwRKS0dhDYb54khSrjDWw==",
621
+ "cpu": [
622
+ "x64"
623
+ ],
624
+ "dev": true,
625
+ "optional": true,
626
+ "os": [
627
+ "linux"
628
+ ]
629
+ },
630
+ "node_modules/@rollup/rollup-linux-x64-musl": {
631
+ "version": "4.34.6",
632
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.34.6.tgz",
633
+ "integrity": "sha512-zmmpOQh8vXc2QITsnCiODCDGXFC8LMi64+/oPpPx5qz3pqv0s6x46ps4xoycfUiVZps5PFn1gksZzo4RGTKT+A==",
634
+ "cpu": [
635
+ "x64"
636
+ ],
637
+ "dev": true,
638
+ "optional": true,
639
+ "os": [
640
+ "linux"
641
+ ]
642
+ },
643
+ "node_modules/@rollup/rollup-win32-arm64-msvc": {
644
+ "version": "4.34.6",
645
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.34.6.tgz",
646
+ "integrity": "sha512-3/q1qUsO/tLqGBaD4uXsB6coVGB3usxw3qyeVb59aArCgedSF66MPdgRStUd7vbZOsko/CgVaY5fo2vkvPLWiA==",
647
+ "cpu": [
648
+ "arm64"
649
+ ],
650
+ "dev": true,
651
+ "optional": true,
652
+ "os": [
653
+ "win32"
654
+ ]
655
+ },
656
+ "node_modules/@rollup/rollup-win32-ia32-msvc": {
657
+ "version": "4.34.6",
658
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.34.6.tgz",
659
+ "integrity": "sha512-oLHxuyywc6efdKVTxvc0135zPrRdtYVjtVD5GUm55I3ODxhU/PwkQFD97z16Xzxa1Fz0AEe4W/2hzRtd+IfpOA==",
660
+ "cpu": [
661
+ "ia32"
662
+ ],
663
+ "dev": true,
664
+ "optional": true,
665
+ "os": [
666
+ "win32"
667
+ ]
668
+ },
669
+ "node_modules/@rollup/rollup-win32-x64-msvc": {
670
+ "version": "4.34.6",
671
+ "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.34.6.tgz",
672
+ "integrity": "sha512-0PVwmgzZ8+TZ9oGBmdZoQVXflbvuwzN/HRclujpl4N/q3i+y0lqLw8n1bXA8ru3sApDjlmONaNAuYr38y1Kr9w==",
673
+ "cpu": [
674
+ "x64"
675
+ ],
676
+ "dev": true,
677
+ "optional": true,
678
+ "os": [
679
+ "win32"
680
+ ]
681
+ },
682
+ "node_modules/@types/estree": {
683
+ "version": "1.0.6",
684
+ "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz",
685
+ "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==",
686
+ "dev": true
687
+ },
688
  "node_modules/@types/node": {
689
  "version": "22.13.1",
690
  "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.1.tgz",
 
694
  "undici-types": "~6.20.0"
695
  }
696
  },
697
+ "node_modules/esbuild": {
698
+ "version": "0.24.2",
699
+ "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.24.2.tgz",
700
+ "integrity": "sha512-+9egpBW8I3CD5XPe0n6BfT5fxLzxrlDzqydF3aviG+9ni1lDC/OvMHcxqEFV0+LANZG5R1bFMWfUrjVsdwxJvA==",
701
+ "dev": true,
702
+ "hasInstallScript": true,
703
+ "bin": {
704
+ "esbuild": "bin/esbuild"
705
+ },
706
+ "engines": {
707
+ "node": ">=18"
708
+ },
709
+ "optionalDependencies": {
710
+ "@esbuild/aix-ppc64": "0.24.2",
711
+ "@esbuild/android-arm": "0.24.2",
712
+ "@esbuild/android-arm64": "0.24.2",
713
+ "@esbuild/android-x64": "0.24.2",
714
+ "@esbuild/darwin-arm64": "0.24.2",
715
+ "@esbuild/darwin-x64": "0.24.2",
716
+ "@esbuild/freebsd-arm64": "0.24.2",
717
+ "@esbuild/freebsd-x64": "0.24.2",
718
+ "@esbuild/linux-arm": "0.24.2",
719
+ "@esbuild/linux-arm64": "0.24.2",
720
+ "@esbuild/linux-ia32": "0.24.2",
721
+ "@esbuild/linux-loong64": "0.24.2",
722
+ "@esbuild/linux-mips64el": "0.24.2",
723
+ "@esbuild/linux-ppc64": "0.24.2",
724
+ "@esbuild/linux-riscv64": "0.24.2",
725
+ "@esbuild/linux-s390x": "0.24.2",
726
+ "@esbuild/linux-x64": "0.24.2",
727
+ "@esbuild/netbsd-arm64": "0.24.2",
728
+ "@esbuild/netbsd-x64": "0.24.2",
729
+ "@esbuild/openbsd-arm64": "0.24.2",
730
+ "@esbuild/openbsd-x64": "0.24.2",
731
+ "@esbuild/sunos-x64": "0.24.2",
732
+ "@esbuild/win32-arm64": "0.24.2",
733
+ "@esbuild/win32-ia32": "0.24.2",
734
+ "@esbuild/win32-x64": "0.24.2"
735
+ }
736
+ },
737
+ "node_modules/fsevents": {
738
+ "version": "2.3.3",
739
+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
740
+ "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
741
+ "dev": true,
742
+ "hasInstallScript": true,
743
+ "optional": true,
744
+ "os": [
745
+ "darwin"
746
+ ],
747
+ "engines": {
748
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
749
+ }
750
+ },
751
+ "node_modules/nanoid": {
752
+ "version": "3.3.8",
753
+ "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz",
754
+ "integrity": "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==",
755
+ "dev": true,
756
+ "funding": [
757
+ {
758
+ "type": "github",
759
+ "url": "https://github.com/sponsors/ai"
760
+ }
761
+ ],
762
+ "bin": {
763
+ "nanoid": "bin/nanoid.cjs"
764
+ },
765
+ "engines": {
766
+ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
767
+ }
768
+ },
769
+ "node_modules/picocolors": {
770
+ "version": "1.1.1",
771
+ "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
772
+ "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
773
+ "dev": true
774
+ },
775
+ "node_modules/postcss": {
776
+ "version": "8.5.2",
777
+ "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.2.tgz",
778
+ "integrity": "sha512-MjOadfU3Ys9KYoX0AdkBlFEF1Vx37uCCeN4ZHnmwm9FfpbsGWMZeBLMmmpY+6Ocqod7mkdZ0DT31OlbsFrLlkA==",
779
+ "dev": true,
780
+ "funding": [
781
+ {
782
+ "type": "opencollective",
783
+ "url": "https://opencollective.com/postcss/"
784
+ },
785
+ {
786
+ "type": "tidelift",
787
+ "url": "https://tidelift.com/funding/github/npm/postcss"
788
+ },
789
+ {
790
+ "type": "github",
791
+ "url": "https://github.com/sponsors/ai"
792
+ }
793
+ ],
794
+ "dependencies": {
795
+ "nanoid": "^3.3.8",
796
+ "picocolors": "^1.1.1",
797
+ "source-map-js": "^1.2.1"
798
+ },
799
+ "engines": {
800
+ "node": "^10 || ^12 || >=14"
801
+ }
802
+ },
803
+ "node_modules/rollup": {
804
+ "version": "4.34.6",
805
+ "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.34.6.tgz",
806
+ "integrity": "sha512-wc2cBWqJgkU3Iz5oztRkQbfVkbxoz5EhnCGOrnJvnLnQ7O0WhQUYyv18qQI79O8L7DdHrrlJNeCHd4VGpnaXKQ==",
807
+ "dev": true,
808
+ "dependencies": {
809
+ "@types/estree": "1.0.6"
810
+ },
811
+ "bin": {
812
+ "rollup": "dist/bin/rollup"
813
+ },
814
+ "engines": {
815
+ "node": ">=18.0.0",
816
+ "npm": ">=8.0.0"
817
+ },
818
+ "optionalDependencies": {
819
+ "@rollup/rollup-android-arm-eabi": "4.34.6",
820
+ "@rollup/rollup-android-arm64": "4.34.6",
821
+ "@rollup/rollup-darwin-arm64": "4.34.6",
822
+ "@rollup/rollup-darwin-x64": "4.34.6",
823
+ "@rollup/rollup-freebsd-arm64": "4.34.6",
824
+ "@rollup/rollup-freebsd-x64": "4.34.6",
825
+ "@rollup/rollup-linux-arm-gnueabihf": "4.34.6",
826
+ "@rollup/rollup-linux-arm-musleabihf": "4.34.6",
827
+ "@rollup/rollup-linux-arm64-gnu": "4.34.6",
828
+ "@rollup/rollup-linux-arm64-musl": "4.34.6",
829
+ "@rollup/rollup-linux-loongarch64-gnu": "4.34.6",
830
+ "@rollup/rollup-linux-powerpc64le-gnu": "4.34.6",
831
+ "@rollup/rollup-linux-riscv64-gnu": "4.34.6",
832
+ "@rollup/rollup-linux-s390x-gnu": "4.34.6",
833
+ "@rollup/rollup-linux-x64-gnu": "4.34.6",
834
+ "@rollup/rollup-linux-x64-musl": "4.34.6",
835
+ "@rollup/rollup-win32-arm64-msvc": "4.34.6",
836
+ "@rollup/rollup-win32-ia32-msvc": "4.34.6",
837
+ "@rollup/rollup-win32-x64-msvc": "4.34.6",
838
+ "fsevents": "~2.3.2"
839
+ }
840
+ },
841
+ "node_modules/source-map-js": {
842
+ "version": "1.2.1",
843
+ "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
844
+ "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
845
+ "dev": true,
846
+ "engines": {
847
+ "node": ">=0.10.0"
848
+ }
849
+ },
850
  "node_modules/typescript": {
851
  "version": "5.7.3",
852
  "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz",
 
864
  "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
865
  "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
866
  "dev": true
867
+ },
868
+ "node_modules/vite": {
869
+ "version": "6.1.0",
870
+ "resolved": "https://registry.npmjs.org/vite/-/vite-6.1.0.tgz",
871
+ "integrity": "sha512-RjjMipCKVoR4hVfPY6GQTgveinjNuyLw+qruksLDvA5ktI1150VmcMBKmQaEWJhg/j6Uaf6dNCNA0AfdzUb/hQ==",
872
+ "dev": true,
873
+ "dependencies": {
874
+ "esbuild": "^0.24.2",
875
+ "postcss": "^8.5.1",
876
+ "rollup": "^4.30.1"
877
+ },
878
+ "bin": {
879
+ "vite": "bin/vite.js"
880
+ },
881
+ "engines": {
882
+ "node": "^18.0.0 || ^20.0.0 || >=22.0.0"
883
+ },
884
+ "funding": {
885
+ "url": "https://github.com/vitejs/vite?sponsor=1"
886
+ },
887
+ "optionalDependencies": {
888
+ "fsevents": "~2.3.3"
889
+ },
890
+ "peerDependencies": {
891
+ "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0",
892
+ "jiti": ">=1.21.0",
893
+ "less": "*",
894
+ "lightningcss": "^1.21.0",
895
+ "sass": "*",
896
+ "sass-embedded": "*",
897
+ "stylus": "*",
898
+ "sugarss": "*",
899
+ "terser": "^5.16.0",
900
+ "tsx": "^4.8.1",
901
+ "yaml": "^2.4.2"
902
+ },
903
+ "peerDependenciesMeta": {
904
+ "@types/node": {
905
+ "optional": true
906
+ },
907
+ "jiti": {
908
+ "optional": true
909
+ },
910
+ "less": {
911
+ "optional": true
912
+ },
913
+ "lightningcss": {
914
+ "optional": true
915
+ },
916
+ "sass": {
917
+ "optional": true
918
+ },
919
+ "sass-embedded": {
920
+ "optional": true
921
+ },
922
+ "stylus": {
923
+ "optional": true
924
+ },
925
+ "sugarss": {
926
+ "optional": true
927
+ },
928
+ "terser": {
929
+ "optional": true
930
+ },
931
+ "tsx": {
932
+ "optional": true
933
+ },
934
+ "yaml": {
935
+ "optional": true
936
+ }
937
+ }
938
  }
939
  }
940
  }
package.json CHANGED
@@ -1,16 +1,20 @@
1
  {
2
  "name": "apidemo",
3
  "version": "1.0.0",
4
- "main": "index.js",
5
  "dependencies": {
6
  "@huggingface/hub": "^1.0.1",
7
  "typescript": "^5.7.3"
8
  },
9
  "scripts": {
10
- "build": "tsc",
11
- "start": "node dist/index.js"
 
 
 
12
  },
13
  "devDependencies": {
14
- "@types/node": "^22.13.1"
 
15
  }
16
  }
 
1
  {
2
  "name": "apidemo",
3
  "version": "1.0.0",
4
+ "type": "module",
5
  "dependencies": {
6
  "@huggingface/hub": "^1.0.1",
7
  "typescript": "^5.7.3"
8
  },
9
  "scripts": {
10
+ "typecheck": "tsc --noEmit",
11
+ "dev": "vite",
12
+ "build": "tsc --noEmit && vite build",
13
+ "preview": "vite preview",
14
+ "start": "vite preview"
15
  },
16
  "devDependencies": {
17
+ "@types/node": "^22.13.1",
18
+ "vite": "^5.0.0"
19
  }
20
  }
src/index.ts CHANGED
@@ -1,22 +1,51 @@
1
  import { oauthLoginUrl, oauthHandleRedirectIfPresent } from "@huggingface/hub";
2
 
 
 
 
 
 
 
 
 
 
 
 
3
  async function handleOAuth() {
4
  try {
5
  const oauthResult = await oauthHandleRedirectIfPresent();
6
- console.log({ oauthResult });
7
 
8
- if (!oauthResult) {
9
- // If no OAuth result, we need to initiate the login
10
- const loginUrl = await oauthLoginUrl();
11
- window.location.href = loginUrl;
 
 
 
12
  }
13
 
14
  return oauthResult;
15
  } catch (error) {
16
  console.error("OAuth error:", error);
 
 
17
  throw error;
18
  }
19
  }
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  // Initialize OAuth handling
22
  handleOAuth().catch(console.error);
 
1
  import { oauthLoginUrl, oauthHandleRedirectIfPresent } from "@huggingface/hub";
2
 
3
+ // Get UI elements
4
+ const signinButton = document.getElementById("signin") as HTMLImageElement;
5
+ const signoutButton = document.getElementById("signout") as HTMLButtonElement;
6
+ const preElement = document.querySelector("pre") as HTMLPreElement;
7
+
8
+ // Show/hide UI elements based on auth state
9
+ function updateUI(isLoggedIn: boolean) {
10
+ signinButton.style.display = isLoggedIn ? "none" : "block";
11
+ signoutButton.style.display = isLoggedIn ? "block" : "none";
12
+ }
13
+
14
  async function handleOAuth() {
15
  try {
16
  const oauthResult = await oauthHandleRedirectIfPresent();
 
17
 
18
+ if (oauthResult) {
19
+ // We have OAuth results, display them
20
+ preElement.textContent = JSON.stringify(oauthResult, null, 2);
21
+ updateUI(true);
22
+ } else {
23
+ // No OAuth results, show sign-in button
24
+ updateUI(false);
25
  }
26
 
27
  return oauthResult;
28
  } catch (error) {
29
  console.error("OAuth error:", error);
30
+ preElement.textContent = "Error: " + (error as Error).message;
31
+ updateUI(false);
32
  throw error;
33
  }
34
  }
35
 
36
+ // Handle sign-in click
37
+ signinButton.addEventListener("click", async () => {
38
+ const loginUrl = await oauthLoginUrl();
39
+ window.location.href = loginUrl;
40
+ });
41
+
42
+ // Handle sign-out click
43
+ signoutButton.addEventListener("click", () => {
44
+ // Clear the display and reset UI
45
+ preElement.textContent = "";
46
+ updateUI(false);
47
+ // You might want to add additional logout logic here
48
+ });
49
+
50
  // Initialize OAuth handling
51
  handleOAuth().catch(console.error);
vite.config.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { defineConfig } from "vite";
2
+
3
+ export default defineConfig({
4
+ build: {
5
+ outDir: "dist",
6
+ emptyOutDir: true,
7
+ sourcemap: true,
8
+ },
9
+ server: {
10
+ open: true,
11
+ },
12
+ });