@goodandready/dsh-model-sync 0.3.12 → 0.3.14
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/README.md +34 -0
- package/README.ru.md +34 -0
- package/README.zh.md +34 -0
- package/lib/adapter-registry.js +20 -3
- package/lib/client.js +994 -81
- package/lib/generic-adapter.js +23 -5
- package/lib/http.js +298 -237
- package/lib/index.js +172 -163
- package/lib/models.js +300 -282
- package/lib/policy.js +25 -2
- package/lib/reliability.js +6 -2
- package/lib/synchronizer.js +157 -3
- package/package.json +1 -1
package/lib/generic-adapter.js
CHANGED
|
@@ -31,16 +31,19 @@ export function canUseGenericAdapter(profile) {
|
|
|
31
31
|
return Boolean(profile?.baseURL) && SUPPORTED_APIS.has(profile?.api || 'openai-completions')
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function requestHeaders(apiKey) {
|
|
34
|
+
function requestHeaders(apiKey, etag, lastModified) {
|
|
35
35
|
const headers = { Accept: 'application/json' }
|
|
36
36
|
if (apiKey) headers.Authorization = `Bearer ${apiKey}`
|
|
37
|
+
if (etag) headers['If-None-Match'] = etag
|
|
38
|
+
if (lastModified) headers['If-Modified-Since'] = lastModified
|
|
37
39
|
return headers
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
async function resolveGenericRequest(profile, { resolveCredential, fetchImpl, signal }) {
|
|
42
|
+
async function resolveGenericRequest(profile, { resolveCredential, fetchImpl, signal, etag, lastModified }) {
|
|
41
43
|
const keyRef = profile.apiKeyEnv || profile.credentialRef || profile.apiKeyRef
|
|
42
44
|
const apiKey = keyRef ? await resolveCredential(keyRef) : ''
|
|
43
|
-
const response = await fetchImpl(endpointFor(profile.baseURL), { headers: requestHeaders(apiKey), signal })
|
|
45
|
+
const response = await fetchImpl(endpointFor(profile.baseURL), { headers: requestHeaders(apiKey, etag, lastModified), signal })
|
|
46
|
+
if (response.status === 304) return response
|
|
44
47
|
if (!response.ok) throw catalogRequestError(response.status, response)
|
|
45
48
|
return response
|
|
46
49
|
}
|
|
@@ -49,18 +52,33 @@ export async function discoverOpenAIModels(profile, {
|
|
|
49
52
|
resolveCredential,
|
|
50
53
|
fetchImpl = fetch,
|
|
51
54
|
signal,
|
|
55
|
+
etag,
|
|
56
|
+
lastModified,
|
|
52
57
|
} = {}) {
|
|
53
58
|
if (!canUseGenericAdapter(profile)) {
|
|
54
59
|
throw new Error('generic discovery requires an OpenAI-compatible baseURL and protocol')
|
|
55
60
|
}
|
|
56
|
-
const response = await resolveGenericRequest(profile, { resolveCredential, fetchImpl, signal })
|
|
61
|
+
const response = await resolveGenericRequest(profile, { resolveCredential, fetchImpl, signal, etag, lastModified })
|
|
62
|
+
if (response.status === 304) {
|
|
63
|
+
return { notModified: true, etag: response.headers?.get?.('etag') || etag, lastModified: response.headers?.get?.('last-modified') || lastModified }
|
|
64
|
+
}
|
|
65
|
+
const respEtag = response.headers?.get?.('etag') || undefined
|
|
66
|
+
const respLastMod = response.headers?.get?.('last-modified') || undefined
|
|
57
67
|
let payload
|
|
58
68
|
try {
|
|
59
69
|
payload = JSON.parse(await readBody(response))
|
|
60
70
|
} catch {
|
|
61
71
|
throw new Error('model catalog response is not valid JSON')
|
|
62
72
|
}
|
|
63
|
-
|
|
73
|
+
const models = normalizeModels(profile.provider ?? '', rowsFrom(payload))
|
|
74
|
+
if (respEtag || respLastMod) {
|
|
75
|
+
Object.defineProperty(models, '__httpMeta', {
|
|
76
|
+
value: { etag: respEtag, lastModified: respLastMod },
|
|
77
|
+
enumerable: false,
|
|
78
|
+
configurable: true,
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
return models
|
|
64
82
|
}
|
|
65
83
|
|
|
66
84
|
|