dsh-llm-verifier 0.1.13 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -22
- package/README.md +328 -301
- package/cordis.patch.yml +4 -4
- package/lib/caller-BWwSVNZf.js.map +1 -0
- package/lib/client.js +176 -14
- package/lib/client.js.map +1 -0
- package/lib/core.js.map +1 -0
- package/lib/index.js +400 -51
- package/lib/index.js.map +1 -0
- package/lib/types/auto.d.ts.map +1 -0
- package/lib/types/auto.js +8 -2
- package/lib/types/auto.js.map +1 -0
- package/lib/types/cache.d.ts.map +1 -0
- package/lib/types/cache.js.map +1 -0
- package/lib/types/caller.d.ts.map +1 -0
- package/lib/types/caller.js.map +1 -0
- package/lib/types/client-i18n.d.ts +27 -0
- package/lib/types/client-i18n.d.ts.map +1 -0
- package/lib/types/client-i18n.js +18 -0
- package/lib/types/client-i18n.js.map +1 -0
- package/lib/types/client.d.ts +15 -2
- package/lib/types/client.d.ts.map +1 -0
- package/lib/types/client.js +137 -10
- package/lib/types/client.js.map +1 -0
- package/lib/types/config.d.ts +4 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +5 -3
- package/lib/types/config.js.map +1 -0
- package/lib/types/core.d.ts.map +1 -0
- package/lib/types/core.js.map +1 -0
- package/lib/types/engine.d.ts.map +1 -0
- package/lib/types/engine.js.map +1 -0
- package/lib/types/images.d.ts.map +1 -0
- package/lib/types/images.js.map +1 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +162 -9
- package/lib/types/index.js.map +1 -0
- package/lib/types/plan-gate.d.ts +27 -0
- package/lib/types/plan-gate.d.ts.map +1 -0
- package/lib/types/plan-gate.js +60 -0
- package/lib/types/plan-gate.js.map +1 -0
- package/lib/types/router.d.ts +28 -32
- package/lib/types/router.d.ts.map +1 -0
- package/lib/types/router.js +41 -9
- package/lib/types/router.js.map +1 -0
- package/lib/types/session.d.ts +11 -0
- package/lib/types/session.d.ts.map +1 -0
- package/lib/types/session.js +41 -11
- package/lib/types/session.js.map +1 -0
- package/lib/types/statistics.d.ts.map +1 -0
- package/lib/types/statistics.js.map +1 -0
- package/lib/types/team-gate.d.ts +20 -0
- package/lib/types/team-gate.d.ts.map +1 -0
- package/lib/types/team-gate.js +59 -0
- package/lib/types/team-gate.js.map +1 -0
- package/lib/types/top-logprobs.d.ts.map +1 -0
- package/lib/types/top-logprobs.js.map +1 -0
- package/lib/types/topic-storage.d.ts.map +1 -0
- package/lib/types/topic-storage.js.map +1 -0
- package/package.json +114 -112
- package/src/auto.test.ts +95 -86
- package/src/auto.ts +140 -133
- package/src/cache.ts +115 -115
- package/src/caller.test.ts +34 -34
- package/src/caller.ts +151 -151
- package/src/client-i18n.ts +18 -0
- package/src/client.tsx +383 -213
- package/src/config.ts +189 -183
- package/src/core.test.ts +71 -71
- package/src/core.ts +205 -205
- package/src/engine.test.ts +136 -136
- package/src/engine.ts +140 -140
- package/src/images.ts +33 -33
- package/src/index.ts +394 -247
- package/src/parity.test.ts +85 -85
- package/src/plan-gate.test.ts +56 -0
- package/src/plan-gate.ts +66 -0
- package/src/router.test.ts +107 -89
- package/src/router.ts +361 -309
- package/src/session.test.ts +71 -36
- package/src/session.ts +132 -103
- package/src/statistics.test.ts +80 -80
- package/src/statistics.ts +328 -328
- package/src/team-gate.test.ts +92 -0
- package/src/team-gate.ts +80 -0
- package/src/top-logprobs.test.ts +84 -84
- package/src/top-logprobs.ts +153 -153
- package/src/topic-storage.test.ts +31 -31
- package/src/topic-storage.ts +42 -42
package/src/images.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import type { VerifierImage } from './caller.ts'
|
|
2
|
-
|
|
3
|
-
const TYPES = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/gif'])
|
|
4
|
-
const MAX_IMAGE_BYTES = 20 * 1024 * 1024
|
|
5
|
-
|
|
6
|
-
function parseDataUrl(value: string): VerifierImage | undefined {
|
|
7
|
-
const match = /^data:(image\/(?:png|jpeg|webp|gif));base64,([A-Za-z0-9+/=\s]+)$/i.exec(value)
|
|
8
|
-
if (!match) return undefined
|
|
9
|
-
const data = Buffer.from(match[2]!.replace(/\s/g, ''), 'base64')
|
|
10
|
-
if (data.byteLength > MAX_IMAGE_BYTES) throw new Error('llm-verifier: image exceeds 20 MiB')
|
|
11
|
-
return { mediaType: match[1]!.toLowerCase() as VerifierImage['mediaType'], data }
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function loadVerifierImages(inputs: readonly string[] | undefined, signal?: AbortSignal): Promise<VerifierImage[]> {
|
|
15
|
-
const images: VerifierImage[] = []
|
|
16
|
-
for (const input of inputs ?? []) {
|
|
17
|
-
const data = parseDataUrl(input)
|
|
18
|
-
if (data !== undefined) { images.push(data); continue }
|
|
19
|
-
let url: URL
|
|
20
|
-
try { url = new URL(input) } catch { throw new Error('llm-verifier: images accept only HTTPS URLs or data:image/...;base64 URLs') }
|
|
21
|
-
if (url.protocol !== 'https:') throw new Error('llm-verifier: remote images must use HTTPS')
|
|
22
|
-
const response = await fetch(url, { redirect: 'error', signal })
|
|
23
|
-
if (!response.ok) throw new Error('llm-verifier: image fetch returned HTTP ' + response.status)
|
|
24
|
-
const type = (response.headers.get('content-type') ?? '').split(';')[0]!.toLowerCase()
|
|
25
|
-
if (!TYPES.has(type)) throw new Error('llm-verifier: unsupported image media type ' + type)
|
|
26
|
-
const declared = Number(response.headers.get('content-length') ?? 0)
|
|
27
|
-
if (declared > MAX_IMAGE_BYTES) throw new Error('llm-verifier: image exceeds 20 MiB')
|
|
28
|
-
const bytes = new Uint8Array(await response.arrayBuffer())
|
|
29
|
-
if (bytes.byteLength > MAX_IMAGE_BYTES) throw new Error('llm-verifier: image exceeds 20 MiB')
|
|
30
|
-
images.push({ mediaType: type as VerifierImage['mediaType'], data: bytes })
|
|
31
|
-
}
|
|
32
|
-
return images
|
|
33
|
-
}
|
|
1
|
+
import type { VerifierImage } from './caller.ts'
|
|
2
|
+
|
|
3
|
+
const TYPES = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/gif'])
|
|
4
|
+
const MAX_IMAGE_BYTES = 20 * 1024 * 1024
|
|
5
|
+
|
|
6
|
+
function parseDataUrl(value: string): VerifierImage | undefined {
|
|
7
|
+
const match = /^data:(image\/(?:png|jpeg|webp|gif));base64,([A-Za-z0-9+/=\s]+)$/i.exec(value)
|
|
8
|
+
if (!match) return undefined
|
|
9
|
+
const data = Buffer.from(match[2]!.replace(/\s/g, ''), 'base64')
|
|
10
|
+
if (data.byteLength > MAX_IMAGE_BYTES) throw new Error('llm-verifier: image exceeds 20 MiB')
|
|
11
|
+
return { mediaType: match[1]!.toLowerCase() as VerifierImage['mediaType'], data }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function loadVerifierImages(inputs: readonly string[] | undefined, signal?: AbortSignal): Promise<VerifierImage[]> {
|
|
15
|
+
const images: VerifierImage[] = []
|
|
16
|
+
for (const input of inputs ?? []) {
|
|
17
|
+
const data = parseDataUrl(input)
|
|
18
|
+
if (data !== undefined) { images.push(data); continue }
|
|
19
|
+
let url: URL
|
|
20
|
+
try { url = new URL(input) } catch { throw new Error('llm-verifier: images accept only HTTPS URLs or data:image/...;base64 URLs') }
|
|
21
|
+
if (url.protocol !== 'https:') throw new Error('llm-verifier: remote images must use HTTPS')
|
|
22
|
+
const response = await fetch(url, { redirect: 'error', signal })
|
|
23
|
+
if (!response.ok) throw new Error('llm-verifier: image fetch returned HTTP ' + response.status)
|
|
24
|
+
const type = (response.headers.get('content-type') ?? '').split(';')[0]!.toLowerCase()
|
|
25
|
+
if (!TYPES.has(type)) throw new Error('llm-verifier: unsupported image media type ' + type)
|
|
26
|
+
const declared = Number(response.headers.get('content-length') ?? 0)
|
|
27
|
+
if (declared > MAX_IMAGE_BYTES) throw new Error('llm-verifier: image exceeds 20 MiB')
|
|
28
|
+
const bytes = new Uint8Array(await response.arrayBuffer())
|
|
29
|
+
if (bytes.byteLength > MAX_IMAGE_BYTES) throw new Error('llm-verifier: image exceeds 20 MiB')
|
|
30
|
+
images.push({ mediaType: type as VerifierImage['mediaType'], data: bytes })
|
|
31
|
+
}
|
|
32
|
+
return images
|
|
33
|
+
}
|