@goodandready/dsh-model-sync 0.3.12 → 0.3.13
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 +15 -0
- package/README.ru.md +15 -0
- package/README.zh.md +15 -0
- package/lib/adapter-registry.js +20 -3
- package/lib/client.js +15 -6
- package/lib/generic-adapter.js +23 -5
- package/lib/http.js +247 -237
- package/lib/models.js +300 -282
- package/lib/policy.js +1 -1
- package/lib/reliability.js +6 -2
- package/lib/synchronizer.js +13 -2
- package/package.json +1 -1
package/lib/synchronizer.js
CHANGED
|
@@ -132,6 +132,7 @@ export function createModelSynchronizer(ctx, { getConfig = () => ({}), saveConfi
|
|
|
132
132
|
const credentialOutcomes = new Map()
|
|
133
133
|
let lastReport = null
|
|
134
134
|
let transientNotifications = []
|
|
135
|
+
const providerHttpMeta = new Map()
|
|
135
136
|
|
|
136
137
|
function recordCredentialOutcome(provider, outcome) {
|
|
137
138
|
credentialOutcomes.set(provider, { ...outcome, at: Date.now() })
|
|
@@ -240,11 +241,12 @@ export function createModelSynchronizer(ctx, { getConfig = () => ({}), saveConfi
|
|
|
240
241
|
}
|
|
241
242
|
}
|
|
242
243
|
let retries = 0
|
|
244
|
+
const existingMeta = providerHttpMeta.get(row.provider)
|
|
243
245
|
try {
|
|
244
|
-
const
|
|
246
|
+
const result = await retryWithBackoff(async () => {
|
|
245
247
|
const timed = createTimeoutSignal(signal, reliability.timeoutMs)
|
|
246
248
|
try {
|
|
247
|
-
return await adapter.discover(profile, { signal: timed.signal })
|
|
249
|
+
return await adapter.discover(profile, { signal: timed.signal, etag: existingMeta?.etag, lastModified: existingMeta?.lastModified })
|
|
248
250
|
} finally {
|
|
249
251
|
timed.cleanup()
|
|
250
252
|
}
|
|
@@ -257,6 +259,15 @@ export function createModelSynchronizer(ctx, { getConfig = () => ({}), saveConfi
|
|
|
257
259
|
})
|
|
258
260
|
circuits.delete(row.provider)
|
|
259
261
|
recordCredentialOutcome(row.provider, { status: 'ok', retries })
|
|
262
|
+
if (result && result.notModified) {
|
|
263
|
+
const config = getConfig() ?? {}
|
|
264
|
+
const cached = normalizeModels(row.provider, config.modelCatalogs?.[row.provider] ?? row.models ?? [])
|
|
265
|
+
return { provider: row.provider, status: 'ok', models: cached, retries, notModified: true }
|
|
266
|
+
}
|
|
267
|
+
const models = Array.isArray(result) ? result : []
|
|
268
|
+
if (result?.__httpMeta) {
|
|
269
|
+
providerHttpMeta.set(row.provider, result.__httpMeta)
|
|
270
|
+
}
|
|
260
271
|
return { provider: row.provider, status: 'ok', models, retries }
|
|
261
272
|
} catch (error) {
|
|
262
273
|
if (!signal?.aborted) recordFailure(row.provider, reliability, error)
|