-
-
Notifications
You must be signed in to change notification settings - Fork 638
Expand file tree
/
Copy pathutils.ts
More file actions
37 lines (29 loc) · 967 Bytes
/
utils.ts
File metadata and controls
37 lines (29 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import consola from "consola"
import { getModels } from "~/services/copilot/get-models"
import { getVSCodeVersion } from "~/services/get-vscode-version"
import { state } from "./state"
export const sleep = (ms: number) =>
new Promise((resolve) => {
setTimeout(resolve, ms)
})
export const isNullish = (value: unknown): value is null | undefined =>
value === null || value === undefined
export async function cacheModels(): Promise<void> {
const models = await getModels()
state.models = models
}
export const cacheVSCodeVersion = async () => {
const response = await getVSCodeVersion()
state.vsCodeVersion = response
consola.info(`Using VSCode version: ${response}`)
}
export const constantTimeEqual = (a: string, b: string): boolean => {
if (a.length !== b.length) {
return false
}
let result = 0
for (let i = 0; i < a.length; i++) {
result |= (a.codePointAt(i) ?? 0) ^ (b.codePointAt(i) ?? 0)
}
return result === 0
}