feat: Add Chrome AI support

This commit is contained in:
n4ze3m
2024-06-30 20:45:06 +05:30
parent 52f9a2953a
commit d41ec2a89c
36 changed files with 463 additions and 47 deletions

30
src/utils/chrome.ts Normal file
View File

@@ -0,0 +1,30 @@
export const getChromeAISupported = async () => {
try {
let browserInfo = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)
let version = browserInfo ? parseInt(browserInfo[2], 10) : 0
if (version < 127) {
return "browser_not_supported"
}
if (!("ai" in globalThis)) {
return "ai_not_supported"
}
//@ts-ignore
const createSession = await ai?.canCreateGenericSession()
if (createSession !== "readily") {
return "ai_not_ready"
}
return "success"
} catch (e) {
console.error(e)
return "internal_error"
}
}
export const isChromeAISupported = async () => {
const result = await getChromeAISupported()
return result === "success"
}