mohdel 1.5.0 → 1.5.1
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/js/session/run.js +34 -0
- package/package.json +2 -2
package/js/session/run.js
CHANGED
|
@@ -85,6 +85,9 @@ export async function * run (envelope, {
|
|
|
85
85
|
if (norm.error) { yield norm.error; return }
|
|
86
86
|
envelope = norm.envelope
|
|
87
87
|
|
|
88
|
+
const cacheErr = cacheMarkerError(envelope.prompt)
|
|
89
|
+
if (cacheErr) { yield cacheErr; return }
|
|
90
|
+
|
|
88
91
|
const provider = providerOf(envelope.model)
|
|
89
92
|
const span = openSpan(envelope)
|
|
90
93
|
const log = scopedLogger(logger, envelope, span)
|
|
@@ -357,6 +360,37 @@ export function normalizeModelId (envelope, resolveSpec) {
|
|
|
357
360
|
return { envelope: next, key: base, spec: baseSpec }
|
|
358
361
|
}
|
|
359
362
|
|
|
363
|
+
/**
|
|
364
|
+
* A `cache` marker is honoured on `text` parts only, with a TTL the
|
|
365
|
+
* adapters know. The adapters would ignore any other marker, so it is
|
|
366
|
+
* refused rather than dropped.
|
|
367
|
+
*
|
|
368
|
+
* @param {import('#core/envelope.js').CallEnvelope['prompt']} prompt
|
|
369
|
+
* @returns {import('#core/events.js').ErrorEvent | undefined}
|
|
370
|
+
*/
|
|
371
|
+
function cacheMarkerError (prompt) {
|
|
372
|
+
if (!Array.isArray(prompt)) return undefined
|
|
373
|
+
for (const m of prompt) {
|
|
374
|
+
if (!Array.isArray(m?.content)) continue
|
|
375
|
+
for (const p of m.content) {
|
|
376
|
+
if (p?.cache == null) continue
|
|
377
|
+
if (p.type !== 'text') {
|
|
378
|
+
return errorEvent(
|
|
379
|
+
`\`cache\` is accepted on text parts only, not on a ${p.type} part (${m.role} message)`,
|
|
380
|
+
'SESSION_INVALID_PROMPT'
|
|
381
|
+
)
|
|
382
|
+
}
|
|
383
|
+
if (p.cache !== '5m' && p.cache !== '1h') {
|
|
384
|
+
return errorEvent(
|
|
385
|
+
`\`cache\` on a text part must be '5m' or '1h' (got ${JSON.stringify(p.cache)})`,
|
|
386
|
+
'SESSION_INVALID_PROMPT'
|
|
387
|
+
)
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return undefined
|
|
392
|
+
}
|
|
393
|
+
|
|
360
394
|
/**
|
|
361
395
|
* The two lane guards, in caller-then-internal order. Returns an
|
|
362
396
|
* error event, or `undefined` when the lane is usable.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mohdel",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Christophe Le Bars",
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
"@opentelemetry/exporter-trace-otlp-grpc": "^0.222.0",
|
|
137
137
|
"@opentelemetry/sdk-node": "^0.222.0",
|
|
138
138
|
"chalk": "^6.0.0",
|
|
139
|
-
"mohdel-thin-gate-linux-x64-gnu": "1.5.
|
|
139
|
+
"mohdel-thin-gate-linux-x64-gnu": "1.5.1"
|
|
140
140
|
},
|
|
141
141
|
"dependencies": {
|
|
142
142
|
"@anthropic-ai/sdk": "^0.128.0",
|