opencode-anthropic-fix 0.2.1 → 0.3.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/README.md +24 -0
- package/index.mjs +155 -149
- package/lib/config.mjs +47 -25
- package/lib/mimicry/adapter-input.mjs +671 -0
- package/lib/mimicry/context-hint-threshold.mjs +127 -0
- package/lib/mimicry/headers.mjs +71 -64
- package/lib/mimicry/request-body.mjs +23 -22
- package/lib/mimicry/system-prompt.mjs +54 -23
- package/lib/mimicry/wire-compat.mjs +305 -0
- package/package.json +3 -3
- package/lib/account-state.test.mjs +0 -109
- package/lib/accounts.test.mjs +0 -912
- package/lib/adaptive-thinking-models.test.mjs +0 -30
- package/lib/backoff.test.mjs +0 -411
- package/lib/cc-credentials.test.mjs +0 -391
- package/lib/config.test.mjs +0 -764
- package/lib/context-hint-persist.mjs +0 -68
- package/lib/diagnose.test.mjs +0 -122
- package/lib/env.test.mjs +0 -25
- package/lib/haiku-call.test.mjs +0 -72
- package/lib/message-transform.test.mjs +0 -173
- package/lib/mimicry/cache.test.mjs +0 -112
- package/lib/mimicry/headers.test.mjs +0 -50
- package/lib/mimicry/models.test.mjs +0 -132
- package/lib/mimicry/request-body.test.mjs +0 -34
- package/lib/mimicry/request-helpers.test.mjs +0 -155
- package/lib/mimicry/response-stream.test.mjs +0 -127
- package/lib/mimicry/system-prompt.test.mjs +0 -73
- package/lib/oauth.test.mjs +0 -343
- package/lib/redact.test.mjs +0 -154
- package/lib/refresh-lock.test.mjs +0 -131
- package/lib/request-headers.test.mjs +0 -164
- package/lib/retry/overload-loop.test.mjs +0 -107
- package/lib/rotation.test.mjs +0 -392
- package/lib/session-metrics.test.mjs +0 -67
- package/lib/storage.test.mjs +0 -696
- package/lib/token-economy/microcompact.test.mjs +0 -28
- package/lib/token-economy/transforms.test.mjs +0 -192
- package/lib/tuning.test.mjs +0 -89
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { createInitialSessionMetrics, sessionMetrics, getAverageCacheHitRate } from "./session-metrics.mjs";
|
|
3
|
-
|
|
4
|
-
describe("session-metrics", () => {
|
|
5
|
-
describe("createInitialSessionMetrics", () => {
|
|
6
|
-
it("returns a fresh object with the documented zeroed shape", () => {
|
|
7
|
-
const m = createInitialSessionMetrics();
|
|
8
|
-
expect(m.turns).toBe(0);
|
|
9
|
-
expect(m.totalInput).toBe(0);
|
|
10
|
-
expect(m.totalOutput).toBe(0);
|
|
11
|
-
expect(m.totalCacheRead).toBe(0);
|
|
12
|
-
expect(m.totalCacheWrite).toBe(0);
|
|
13
|
-
expect(m.recentCacheRates).toEqual([]);
|
|
14
|
-
expect(m.sessionCostUsd).toBe(0);
|
|
15
|
-
expect(m.costBreakdown).toEqual({ input: 0, output: 0, cacheRead: 0, cacheWrite: 0 });
|
|
16
|
-
expect(m.lastStopReason).toBeNull();
|
|
17
|
-
expect(m.perModel).toEqual({});
|
|
18
|
-
expect(m.lastModelId).toBeNull();
|
|
19
|
-
expect(m.lastRequestBody).toBeNull();
|
|
20
|
-
expect(m.tokenBudget).toEqual({ limit: 0, used: 0, continuations: 0, outputHistory: [] });
|
|
21
|
-
expect(m.usedTools).toBeInstanceOf(Set);
|
|
22
|
-
expect(m.usedTools.size).toBe(0);
|
|
23
|
-
expect(m.lastQuota.fiveHour).toEqual({
|
|
24
|
-
utilization: 0,
|
|
25
|
-
resets_at: null,
|
|
26
|
-
status: null,
|
|
27
|
-
surpassedThreshold: null,
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("does not alias nested state between calls (fresh Set/objects/arrays)", () => {
|
|
32
|
-
const a = createInitialSessionMetrics();
|
|
33
|
-
const b = createInitialSessionMetrics();
|
|
34
|
-
expect(a.usedTools).not.toBe(b.usedTools);
|
|
35
|
-
expect(a.lastQuota).not.toBe(b.lastQuota);
|
|
36
|
-
expect(a.tokenBudget).not.toBe(b.tokenBudget);
|
|
37
|
-
expect(a.recentCacheRates).not.toBe(b.recentCacheRates);
|
|
38
|
-
a.usedTools.add("Bash");
|
|
39
|
-
expect(b.usedTools.size).toBe(0);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe("sessionMetrics singleton", () => {
|
|
44
|
-
it("is a shared object reference whose mutations persist", () => {
|
|
45
|
-
const before = sessionMetrics.turns;
|
|
46
|
-
sessionMetrics.turns = before + 1;
|
|
47
|
-
expect(sessionMetrics.turns).toBe(before + 1);
|
|
48
|
-
sessionMetrics.turns = before; // restore
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe("getAverageCacheHitRate", () => {
|
|
53
|
-
it("returns 0 when there are no recent rates", () => {
|
|
54
|
-
const saved = sessionMetrics.recentCacheRates;
|
|
55
|
-
sessionMetrics.recentCacheRates = [];
|
|
56
|
-
expect(getAverageCacheHitRate()).toBe(0);
|
|
57
|
-
sessionMetrics.recentCacheRates = saved;
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("returns the arithmetic mean of the rolling window", () => {
|
|
61
|
-
const saved = sessionMetrics.recentCacheRates;
|
|
62
|
-
sessionMetrics.recentCacheRates = [0.2, 0.4, 0.6];
|
|
63
|
-
expect(getAverageCacheHitRate()).toBeCloseTo(0.4, 10);
|
|
64
|
-
sessionMetrics.recentCacheRates = saved;
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|