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.
Files changed (90) hide show
  1. package/LICENSE +22 -22
  2. package/README.md +328 -301
  3. package/cordis.patch.yml +4 -4
  4. package/lib/caller-BWwSVNZf.js.map +1 -0
  5. package/lib/client.js +176 -14
  6. package/lib/client.js.map +1 -0
  7. package/lib/core.js.map +1 -0
  8. package/lib/index.js +400 -51
  9. package/lib/index.js.map +1 -0
  10. package/lib/types/auto.d.ts.map +1 -0
  11. package/lib/types/auto.js +8 -2
  12. package/lib/types/auto.js.map +1 -0
  13. package/lib/types/cache.d.ts.map +1 -0
  14. package/lib/types/cache.js.map +1 -0
  15. package/lib/types/caller.d.ts.map +1 -0
  16. package/lib/types/caller.js.map +1 -0
  17. package/lib/types/client-i18n.d.ts +27 -0
  18. package/lib/types/client-i18n.d.ts.map +1 -0
  19. package/lib/types/client-i18n.js +18 -0
  20. package/lib/types/client-i18n.js.map +1 -0
  21. package/lib/types/client.d.ts +15 -2
  22. package/lib/types/client.d.ts.map +1 -0
  23. package/lib/types/client.js +137 -10
  24. package/lib/types/client.js.map +1 -0
  25. package/lib/types/config.d.ts +4 -0
  26. package/lib/types/config.d.ts.map +1 -0
  27. package/lib/types/config.js +5 -3
  28. package/lib/types/config.js.map +1 -0
  29. package/lib/types/core.d.ts.map +1 -0
  30. package/lib/types/core.js.map +1 -0
  31. package/lib/types/engine.d.ts.map +1 -0
  32. package/lib/types/engine.js.map +1 -0
  33. package/lib/types/images.d.ts.map +1 -0
  34. package/lib/types/images.js.map +1 -0
  35. package/lib/types/index.d.ts +2 -0
  36. package/lib/types/index.d.ts.map +1 -0
  37. package/lib/types/index.js +162 -9
  38. package/lib/types/index.js.map +1 -0
  39. package/lib/types/plan-gate.d.ts +27 -0
  40. package/lib/types/plan-gate.d.ts.map +1 -0
  41. package/lib/types/plan-gate.js +60 -0
  42. package/lib/types/plan-gate.js.map +1 -0
  43. package/lib/types/router.d.ts +28 -32
  44. package/lib/types/router.d.ts.map +1 -0
  45. package/lib/types/router.js +41 -9
  46. package/lib/types/router.js.map +1 -0
  47. package/lib/types/session.d.ts +11 -0
  48. package/lib/types/session.d.ts.map +1 -0
  49. package/lib/types/session.js +41 -11
  50. package/lib/types/session.js.map +1 -0
  51. package/lib/types/statistics.d.ts.map +1 -0
  52. package/lib/types/statistics.js.map +1 -0
  53. package/lib/types/team-gate.d.ts +20 -0
  54. package/lib/types/team-gate.d.ts.map +1 -0
  55. package/lib/types/team-gate.js +59 -0
  56. package/lib/types/team-gate.js.map +1 -0
  57. package/lib/types/top-logprobs.d.ts.map +1 -0
  58. package/lib/types/top-logprobs.js.map +1 -0
  59. package/lib/types/topic-storage.d.ts.map +1 -0
  60. package/lib/types/topic-storage.js.map +1 -0
  61. package/package.json +114 -112
  62. package/src/auto.test.ts +95 -86
  63. package/src/auto.ts +140 -133
  64. package/src/cache.ts +115 -115
  65. package/src/caller.test.ts +34 -34
  66. package/src/caller.ts +151 -151
  67. package/src/client-i18n.ts +18 -0
  68. package/src/client.tsx +383 -213
  69. package/src/config.ts +189 -183
  70. package/src/core.test.ts +71 -71
  71. package/src/core.ts +205 -205
  72. package/src/engine.test.ts +136 -136
  73. package/src/engine.ts +140 -140
  74. package/src/images.ts +33 -33
  75. package/src/index.ts +394 -247
  76. package/src/parity.test.ts +85 -85
  77. package/src/plan-gate.test.ts +56 -0
  78. package/src/plan-gate.ts +66 -0
  79. package/src/router.test.ts +107 -89
  80. package/src/router.ts +361 -309
  81. package/src/session.test.ts +71 -36
  82. package/src/session.ts +132 -103
  83. package/src/statistics.test.ts +80 -80
  84. package/src/statistics.ts +328 -328
  85. package/src/team-gate.test.ts +92 -0
  86. package/src/team-gate.ts +80 -0
  87. package/src/top-logprobs.test.ts +84 -84
  88. package/src/top-logprobs.ts +153 -153
  89. package/src/topic-storage.test.ts +31 -31
  90. 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
+ }