feat: Add Chrome AI support
This commit is contained in:
30
src/utils/chrome.ts
Normal file
30
src/utils/chrome.ts
Normal 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"
|
||||
}
|
||||
Reference in New Issue
Block a user