mohdel 0.117.2 → 0.118.0

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/src/lib/common.js CHANGED
@@ -210,13 +210,3 @@ export const getExcludedModels = excludedOps.load
210
210
  export const saveExcludedModels = excludedOps.save
211
211
  export const getProvidersConfig = providersConfigOps.load
212
212
  export const saveProvidersConfig = providersConfigOps.save
213
-
214
- export const getDefaultModelId = async () => {
215
- const config = await getConfig()
216
-
217
- if (config.defaultModel) {
218
- return config.defaultModel
219
- }
220
-
221
- throw new Error('No default model configured. Run \'mo default\' to set up a default model.')
222
- }
@@ -115,11 +115,6 @@ export const expandModelAliasSync = (modelId) => {
115
115
  return expandModelAliasInternal(modelId)
116
116
  }
117
117
 
118
- export const expandModelAlias = async (modelId) => {
119
- await ensureCuratedCache()
120
- return expandModelAliasInternal(modelId)
121
- }
122
-
123
118
  export const persistCuratedCache = async () => {
124
119
  if (!curatedCache) {
125
120
  await ensureCuratedCache()
@@ -130,17 +125,6 @@ export const persistCuratedCache = async () => {
130
125
  return curatedCache
131
126
  }
132
127
 
133
- export const overwriteCuratedCache = async (nextCache) => {
134
- curatedCache = nextCache || {}
135
- return persistCuratedCache()
136
- }
137
-
138
- export const reloadCuratedCache = async () => {
139
- curatedCache = null
140
- aliasMapCache = null
141
- return ensureCuratedCache()
142
- }
143
-
144
128
  export const clearCuratedCache = () => {
145
129
  curatedCache = null
146
130
  aliasMapCache = null
@@ -1,63 +0,0 @@
1
- import { Severity, MohdelError } from './errors.js'
2
- import { silent } from './logger.js'
3
-
4
- const createCooldownTracker = (threshold = 3, durationMs = 60000, { logger = silent } = {}) => {
5
- // key → { failCount, until, reason }
6
- const entries = new Map()
7
-
8
- const check = (key) => {
9
- const entry = entries.get(key)
10
- if (!entry || !entry.until) return null
11
- if (Date.now() >= entry.until) {
12
- entries.delete(key)
13
- logger.debug({ key }, '[mohdel:cooldown] expired')
14
- return null
15
- }
16
- return entry
17
- }
18
-
19
- const recordFailure = (key, { immediate = false, cause } = {}) => {
20
- const entry = entries.get(key) || { failCount: 0, until: null, reason: null }
21
- entry.failCount++
22
- if (cause) entry.lastCause = cause
23
- const shouldCooldown = immediate || entry.failCount >= threshold
24
- if (shouldCooldown) {
25
- entry.until = Date.now() + durationMs
26
- entry.reason = immediate ? 'auth' : 'consecutive_failures'
27
- entries.set(key, entry)
28
- logger.info({
29
- key,
30
- reason: entry.reason,
31
- failCount: entry.failCount,
32
- durationMs,
33
- triggeredBy: entry.lastCause || null
34
- }, '[mohdel:cooldown] activated')
35
- return true
36
- }
37
- entries.set(key, entry)
38
- return false
39
- }
40
-
41
- const reset = (key) => {
42
- const had = entries.has(key)
43
- entries.delete(key)
44
- if (had) logger.debug({ key }, '[mohdel:cooldown] reset')
45
- }
46
-
47
- const throwIfCoolingDown = (key, span) => {
48
- const entry = check(key)
49
- if (!entry) return
50
- const secsLeft = Math.ceil((entry.until - Date.now()) / 1000)
51
- logger.trace({ key, secsLeft }, '[mohdel:cooldown] fast-fail')
52
- throw new MohdelError('PROVIDER_COOLDOWN', {
53
- severity: Severity.WARN,
54
- retryable: true,
55
- detail: `Provider ${key} is in cooldown for ${secsLeft}s after ${entry.failCount} consecutive failures (${entry.reason}).`,
56
- context: { provider: key, failCount: entry.failCount, reason: entry.reason, cooldownUntil: entry.until }
57
- })
58
- }
59
-
60
- return { check, recordFailure, reset, throwIfCoolingDown }
61
- }
62
-
63
- export default createCooldownTracker
package/src/lib/errors.js DELETED
@@ -1,43 +0,0 @@
1
- export const Severity = Object.freeze({
2
- TRACE: Symbol('TRACE'),
3
- DEBUG: Symbol('DEBUG'),
4
- INFO: Symbol('INFO'),
5
- WARN: Symbol('WARN'),
6
- ERROR: Symbol('ERROR'),
7
- FATAL: Symbol('FATAL')
8
- })
9
-
10
- export const getSeverityNumber = (severitySymbol) => {
11
- switch (severitySymbol) {
12
- case Severity.TRACE:
13
- return 1
14
- case Severity.DEBUG:
15
- return 5
16
- case Severity.INFO:
17
- return 9
18
- case Severity.WARN:
19
- return 13
20
- case Severity.ERROR:
21
- return 17
22
- case Severity.FATAL:
23
- return 21
24
- default:
25
- throw new Error(`[mohdel] unknown severity symbol: ${String(severitySymbol)}`)
26
- }
27
- }
28
-
29
- export class MohdelError extends Error {
30
- constructor (
31
- message,
32
- { cause, severity, detail, context, component = 'inference', retryable = false, silent = false } = {}
33
- ) {
34
- super(message, { cause })
35
- this.name = 'MohdelError'
36
- this.severity = severity
37
- this.detail = detail
38
- this.context = context
39
- this.component = component
40
- this.retryable = retryable
41
- this.silent = silent
42
- }
43
- }