mohdel 0.104.1 → 0.104.2
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.
|
@@ -22,10 +22,16 @@ import { catalogKey } from '#core/model-id.js'
|
|
|
22
22
|
* @param {string} output
|
|
23
23
|
* @param {number} inputTokens
|
|
24
24
|
* @param {number} outputTokens
|
|
25
|
+
* @param {{cacheWriteInputTokens?: number, cacheReadInputTokens?: number}} [extra]
|
|
26
|
+
* Optional cache token counts captured before cancellation. Threaded through
|
|
27
|
+
* so the cancellation-cost calculation prices any cache writes/reads that
|
|
28
|
+
* already happened before the abort.
|
|
25
29
|
* @returns {import('#core/events.js').DoneEvent}
|
|
26
30
|
*/
|
|
27
|
-
export function cancelledDone (start, first, envelope, output, inputTokens, outputTokens) {
|
|
31
|
+
export function cancelledDone (start, first, envelope, output, inputTokens, outputTokens, extra = {}) {
|
|
28
32
|
const end = String(process.hrtime.bigint())
|
|
33
|
+
const cacheWriteInputTokens = extra.cacheWriteInputTokens || 0
|
|
34
|
+
const cacheReadInputTokens = extra.cacheReadInputTokens || 0
|
|
29
35
|
return {
|
|
30
36
|
type: 'done',
|
|
31
37
|
result: {
|
|
@@ -34,9 +40,11 @@ export function cancelledDone (start, first, envelope, output, inputTokens, outp
|
|
|
34
40
|
inputTokens,
|
|
35
41
|
outputTokens,
|
|
36
42
|
thinkingTokens: 0,
|
|
43
|
+
...(cacheWriteInputTokens > 0 && { cacheWriteInputTokens }),
|
|
44
|
+
...(cacheReadInputTokens > 0 && { cacheReadInputTokens }),
|
|
37
45
|
cost: costFor(
|
|
38
46
|
catalogKey(envelope.model),
|
|
39
|
-
{ inputTokens, outputTokens, thinkingTokens: 0 }
|
|
47
|
+
{ inputTokens, outputTokens, thinkingTokens: 0, cacheWriteInputTokens, cacheReadInputTokens }
|
|
40
48
|
),
|
|
41
49
|
timestamps: { start, first: first ?? end, end },
|
|
42
50
|
warning: WARNING_CANCELLED
|
|
@@ -129,7 +129,7 @@ export async function * anthropic (envelope, deps = {}) {
|
|
|
129
129
|
|
|
130
130
|
for await (const event of stream) {
|
|
131
131
|
if (signal?.aborted) {
|
|
132
|
-
yield cancelledDone(start, first, envelope, currentOutput(), inputTokens, outputTokens)
|
|
132
|
+
yield cancelledDone(start, first, envelope, currentOutput(), inputTokens, outputTokens, { cacheWriteInputTokens: cacheWriteTokens, cacheReadInputTokens: cacheReadTokens })
|
|
133
133
|
return
|
|
134
134
|
}
|
|
135
135
|
switch (event.type) {
|
|
@@ -197,7 +197,7 @@ export async function * anthropic (envelope, deps = {}) {
|
|
|
197
197
|
}
|
|
198
198
|
} catch (e) {
|
|
199
199
|
if (signal?.aborted) {
|
|
200
|
-
yield cancelledDone(start, first, envelope, currentOutput(), inputTokens, outputTokens)
|
|
200
|
+
yield cancelledDone(start, first, envelope, currentOutput(), inputTokens, outputTokens, { cacheWriteInputTokens: cacheWriteTokens, cacheReadInputTokens: cacheReadTokens })
|
|
201
201
|
return
|
|
202
202
|
}
|
|
203
203
|
log?.warn({ err: e }, '[mohdel:anthropic] stream failed')
|
|
@@ -206,7 +206,7 @@ export async function * anthropic (envelope, deps = {}) {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
if (signal?.aborted) {
|
|
209
|
-
yield cancelledDone(start, first, envelope, currentOutput(), inputTokens, outputTokens)
|
|
209
|
+
yield cancelledDone(start, first, envelope, currentOutput(), inputTokens, outputTokens, { cacheWriteInputTokens: cacheWriteTokens, cacheReadInputTokens: cacheReadTokens })
|
|
210
210
|
return
|
|
211
211
|
}
|
|
212
212
|
|
package/js/session/run.js
CHANGED
|
@@ -376,16 +376,19 @@ function finalizeSpanOk (span, result, sawDelta = false, maxInterFrameMs = 0) {
|
|
|
376
376
|
* @param {number} startedAt
|
|
377
377
|
*/
|
|
378
378
|
function summarizeDone (result, startedAt) {
|
|
379
|
-
|
|
379
|
+
const summary = {
|
|
380
380
|
status: result?.status,
|
|
381
381
|
in: result?.inputTokens || 0,
|
|
382
382
|
out: result?.outputTokens || 0,
|
|
383
|
-
think: result?.thinkingTokens || 0
|
|
384
|
-
cost: result?.cost,
|
|
385
|
-
warning: result?.warning,
|
|
386
|
-
totalMs: Date.now() - startedAt,
|
|
387
|
-
maxInterFrameMs: result?.maxInterFrameMs
|
|
383
|
+
think: result?.thinkingTokens || 0
|
|
388
384
|
}
|
|
385
|
+
if (result?.cacheWriteInputTokens) summary.cacheW = result.cacheWriteInputTokens
|
|
386
|
+
if (result?.cacheReadInputTokens) summary.cacheR = result.cacheReadInputTokens
|
|
387
|
+
summary.cost = result?.cost
|
|
388
|
+
if (result?.warning) summary.warning = result.warning
|
|
389
|
+
summary.totalMs = Date.now() - startedAt
|
|
390
|
+
if (result?.maxInterFrameMs != null) summary.maxInterFrameMs = result.maxInterFrameMs
|
|
391
|
+
return summary
|
|
389
392
|
}
|
|
390
393
|
|
|
391
394
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mohdel",
|
|
3
|
-
"version": "0.104.
|
|
3
|
+
"version": "0.104.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Christophe Le Bars",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"@opentelemetry/exporter-trace-otlp-grpc": "^0.217.0",
|
|
88
88
|
"@opentelemetry/sdk-node": "^0.217.0",
|
|
89
89
|
"chalk": "^5.4.0",
|
|
90
|
-
"mohdel-thin-gate-linux-x64-gnu": "0.104.
|
|
90
|
+
"mohdel-thin-gate-linux-x64-gnu": "0.104.2"
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"@anthropic-ai/sdk": "^0.95.1",
|