lynkr 8.0.0 → 9.0.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/.lynkr/telemetry.db +0 -0
- package/.lynkr/telemetry.db-shm +0 -0
- package/.lynkr/telemetry.db-wal +0 -0
- package/README.md +196 -322
- package/lynkr-skill.tar.gz +0 -0
- package/package.json +4 -3
- package/src/api/openai-router.js +64 -13
- package/src/api/providers-handler.js +171 -3
- package/src/api/router.js +9 -2
- package/src/clients/circuit-breaker.js +10 -247
- package/src/clients/codex-process.js +342 -0
- package/src/clients/codex-utils.js +143 -0
- package/src/clients/databricks.js +210 -63
- package/src/clients/resilience.js +540 -0
- package/src/clients/retry.js +22 -167
- package/src/clients/standard-tools.js +23 -0
- package/src/config/index.js +77 -0
- package/src/context/compression.js +42 -9
- package/src/context/distill.js +492 -0
- package/src/orchestrator/index.js +48 -8
- package/src/routing/complexity-analyzer.js +258 -5
- package/src/routing/index.js +12 -2
- package/src/routing/latency-tracker.js +148 -0
- package/src/routing/model-tiers.js +2 -0
- package/src/routing/quality-scorer.js +113 -0
- package/src/routing/telemetry.js +464 -0
- package/src/server.js +13 -12
- package/src/tools/code-graph.js +538 -0
- package/src/tools/code-mode.js +304 -0
- package/src/tools/index.js +4 -0
- package/src/tools/lazy-loader.js +18 -0
- package/src/tools/mcp-remote.js +7 -0
- package/src/tools/smart-selection.js +11 -0
- package/src/tools/tinyfish.js +358 -0
- package/src/tools/truncate.js +1 -0
- package/src/utils/payload.js +206 -0
- package/src/utils/perf-timer.js +80 -0
- package/.github/FUNDING.yml +0 -15
- package/.github/workflows/README.md +0 -215
- package/.github/workflows/ci.yml +0 -69
- package/.github/workflows/index.yml +0 -62
- package/.github/workflows/web-tools-tests.yml +0 -56
- package/CITATIONS.bib +0 -6
- package/DEPLOYMENT.md +0 -1001
- package/LYNKR-TUI-PLAN.md +0 -984
- package/PERFORMANCE-REPORT.md +0 -866
- package/PLAN-per-client-model-routing.md +0 -252
- package/docs/42642f749da6234f41b6b425c3bb07c9.txt +0 -1
- package/docs/BingSiteAuth.xml +0 -4
- package/docs/docs-style.css +0 -478
- package/docs/docs.html +0 -198
- package/docs/google5be250e608e6da39.html +0 -1
- package/docs/index.html +0 -577
- package/docs/index.md +0 -584
- package/docs/robots.txt +0 -4
- package/docs/sitemap.xml +0 -44
- package/docs/style.css +0 -1223
- package/docs/toon-integration-spec.md +0 -130
- package/documentation/README.md +0 -101
- package/documentation/api.md +0 -806
- package/documentation/claude-code-cli.md +0 -679
- package/documentation/codex-cli.md +0 -397
- package/documentation/contributing.md +0 -571
- package/documentation/cursor-integration.md +0 -734
- package/documentation/docker.md +0 -874
- package/documentation/embeddings.md +0 -762
- package/documentation/faq.md +0 -713
- package/documentation/features.md +0 -403
- package/documentation/headroom.md +0 -519
- package/documentation/installation.md +0 -758
- package/documentation/memory-system.md +0 -476
- package/documentation/production.md +0 -636
- package/documentation/providers.md +0 -1009
- package/documentation/routing.md +0 -476
- package/documentation/testing.md +0 -629
- package/documentation/token-optimization.md +0 -325
- package/documentation/tools.md +0 -697
- package/documentation/troubleshooting.md +0 -969
- package/final-test.js +0 -33
- package/headroom-sidecar/config.py +0 -93
- package/headroom-sidecar/requirements.txt +0 -14
- package/headroom-sidecar/server.py +0 -451
- package/monitor-agents.sh +0 -31
- package/scripts/audit-log-reader.js +0 -399
- package/scripts/compact-dictionary.js +0 -204
- package/scripts/test-deduplication.js +0 -448
- package/src/db/database.sqlite +0 -0
- package/te +0 -11622
- package/test/README.md +0 -212
- package/test/azure-openai-config.test.js +0 -213
- package/test/azure-openai-error-resilience.test.js +0 -238
- package/test/azure-openai-format-conversion.test.js +0 -354
- package/test/azure-openai-integration.test.js +0 -287
- package/test/azure-openai-routing.test.js +0 -175
- package/test/azure-openai-streaming.test.js +0 -171
- package/test/bedrock-integration.test.js +0 -457
- package/test/comprehensive-test-suite.js +0 -928
- package/test/config-validation.test.js +0 -207
- package/test/cursor-integration.test.js +0 -484
- package/test/format-conversion.test.js +0 -578
- package/test/hybrid-routing-integration.test.js +0 -269
- package/test/hybrid-routing-performance.test.js +0 -428
- package/test/llamacpp-integration.test.js +0 -882
- package/test/lmstudio-integration.test.js +0 -347
- package/test/memory/extractor.test.js +0 -398
- package/test/memory/retriever.test.js +0 -613
- package/test/memory/retriever.test.js.bak +0 -585
- package/test/memory/search.test.js +0 -537
- package/test/memory/search.test.js.bak +0 -389
- package/test/memory/store.test.js +0 -344
- package/test/memory/store.test.js.bak +0 -312
- package/test/memory/surprise.test.js +0 -300
- package/test/memory-performance.test.js +0 -472
- package/test/openai-integration.test.js +0 -683
- package/test/openrouter-error-resilience.test.js +0 -418
- package/test/passthrough-mode.test.js +0 -385
- package/test/performance-benchmark.js +0 -351
- package/test/performance-tests.js +0 -528
- package/test/routing.test.js +0 -225
- package/test/toon-compression.test.js +0 -131
- package/test/web-tools.test.js +0 -329
- package/test-agents-simple.js +0 -43
- package/test-cli-connection.sh +0 -33
- package/test-learning-unit.js +0 -126
- package/test-learning.js +0 -112
- package/test-parallel-agents.sh +0 -124
- package/test-parallel-direct.js +0 -155
- package/test-subagents.sh +0 -117
|
@@ -1,418 +0,0 @@
|
|
|
1
|
-
const assert = require("assert");
|
|
2
|
-
const { describe, it, beforeEach, afterEach } = require("node:test");
|
|
3
|
-
|
|
4
|
-
describe("OpenRouter Error Resilience", () => {
|
|
5
|
-
let originalEnv;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
originalEnv = { ...process.env };
|
|
9
|
-
|
|
10
|
-
// Set MODEL_PROVIDER to avoid validation errors
|
|
11
|
-
process.env.MODEL_PROVIDER = "databricks";
|
|
12
|
-
process.env.DATABRICKS_API_KEY = "test-key";
|
|
13
|
-
process.env.DATABRICKS_API_BASE = "http://test.com";
|
|
14
|
-
|
|
15
|
-
// Clear module cache
|
|
16
|
-
delete require.cache[require.resolve("../src/config")];
|
|
17
|
-
delete require.cache[require.resolve("../src/clients/openrouter-utils")];
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
process.env = originalEnv;
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe("Missing Choices Array", () => {
|
|
25
|
-
it("should throw error when choices array is missing", () => {
|
|
26
|
-
const invalidResponse = {
|
|
27
|
-
error: {
|
|
28
|
-
message: "Rate limit exceeded",
|
|
29
|
-
type: "rate_limit_error",
|
|
30
|
-
code: 429
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
35
|
-
|
|
36
|
-
assert.throws(
|
|
37
|
-
() => convertOpenRouterResponseToAnthropic(invalidResponse, "test-model"),
|
|
38
|
-
/No choices in OpenRouter response/
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("should throw error when choices array is empty", () => {
|
|
43
|
-
const invalidResponse = {
|
|
44
|
-
choices: [],
|
|
45
|
-
model: "openai/gpt-4o-mini",
|
|
46
|
-
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 }
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
50
|
-
|
|
51
|
-
assert.throws(
|
|
52
|
-
() => convertOpenRouterResponseToAnthropic(invalidResponse, "test-model"),
|
|
53
|
-
/No choices in OpenRouter response/
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("should throw error when choices is null", () => {
|
|
58
|
-
const invalidResponse = {
|
|
59
|
-
choices: null,
|
|
60
|
-
model: "openai/gpt-4o-mini"
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
64
|
-
|
|
65
|
-
assert.throws(
|
|
66
|
-
() => convertOpenRouterResponseToAnthropic(invalidResponse, "test-model"),
|
|
67
|
-
/No choices in OpenRouter response/
|
|
68
|
-
);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("should throw error when choices is undefined", () => {
|
|
72
|
-
const invalidResponse = {
|
|
73
|
-
model: "openai/gpt-4o-mini",
|
|
74
|
-
usage: { prompt_tokens: 10, completion_tokens: 0, total_tokens: 10 }
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
78
|
-
|
|
79
|
-
assert.throws(
|
|
80
|
-
() => convertOpenRouterResponseToAnthropic(invalidResponse, "test-model"),
|
|
81
|
-
/No choices in OpenRouter response/
|
|
82
|
-
);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe("Error Response Formats", () => {
|
|
87
|
-
it("should detect rate limit errors", () => {
|
|
88
|
-
const rateLimitError = {
|
|
89
|
-
error: {
|
|
90
|
-
message: "Rate limit exceeded for model",
|
|
91
|
-
type: "rate_limit_error",
|
|
92
|
-
code: 429
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// Verify error structure
|
|
97
|
-
assert.strictEqual(rateLimitError.error.type, "rate_limit_error");
|
|
98
|
-
assert.strictEqual(rateLimitError.error.code, 429);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("should detect model unavailable errors", () => {
|
|
102
|
-
const unavailableError = {
|
|
103
|
-
error: {
|
|
104
|
-
message: "Model is currently unavailable",
|
|
105
|
-
type: "service_unavailable",
|
|
106
|
-
code: 503
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
assert.strictEqual(unavailableError.error.type, "service_unavailable");
|
|
111
|
-
assert.strictEqual(unavailableError.error.code, 503);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it("should detect invalid request errors", () => {
|
|
115
|
-
const invalidRequestError = {
|
|
116
|
-
error: {
|
|
117
|
-
message: "Invalid request parameters",
|
|
118
|
-
type: "invalid_request_error",
|
|
119
|
-
code: 400
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
assert.strictEqual(invalidRequestError.error.type, "invalid_request_error");
|
|
124
|
-
assert.strictEqual(invalidRequestError.error.code, 400);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("should detect authentication errors", () => {
|
|
128
|
-
const authError = {
|
|
129
|
-
error: {
|
|
130
|
-
message: "Invalid API key",
|
|
131
|
-
type: "authentication_error",
|
|
132
|
-
code: 401
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
assert.strictEqual(authError.error.type, "authentication_error");
|
|
137
|
-
assert.strictEqual(authError.error.code, 401);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe("Successful Response Validation", () => {
|
|
142
|
-
it("should successfully convert valid OpenRouter response", () => {
|
|
143
|
-
const validResponse = {
|
|
144
|
-
choices: [
|
|
145
|
-
{
|
|
146
|
-
message: {
|
|
147
|
-
role: "assistant",
|
|
148
|
-
content: "Hello, how can I help you?"
|
|
149
|
-
},
|
|
150
|
-
finish_reason: "stop"
|
|
151
|
-
}
|
|
152
|
-
],
|
|
153
|
-
model: "openai/gpt-4o-mini",
|
|
154
|
-
usage: {
|
|
155
|
-
prompt_tokens: 10,
|
|
156
|
-
completion_tokens: 8,
|
|
157
|
-
total_tokens: 18
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
162
|
-
const result = convertOpenRouterResponseToAnthropic(validResponse, "test-model");
|
|
163
|
-
|
|
164
|
-
assert.strictEqual(result.role, "assistant");
|
|
165
|
-
assert.strictEqual(Array.isArray(result.content), true);
|
|
166
|
-
assert.strictEqual(result.content.length, 1);
|
|
167
|
-
assert.strictEqual(result.content[0].type, "text");
|
|
168
|
-
assert.strictEqual(result.content[0].text, "Hello, how can I help you?");
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("should handle response with empty content gracefully", () => {
|
|
172
|
-
const responseWithEmptyContent = {
|
|
173
|
-
choices: [
|
|
174
|
-
{
|
|
175
|
-
message: {
|
|
176
|
-
role: "assistant",
|
|
177
|
-
content: ""
|
|
178
|
-
},
|
|
179
|
-
finish_reason: "stop"
|
|
180
|
-
}
|
|
181
|
-
],
|
|
182
|
-
model: "openai/gpt-4o-mini",
|
|
183
|
-
usage: { prompt_tokens: 10, completion_tokens: 0, total_tokens: 10 }
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
187
|
-
const result = convertOpenRouterResponseToAnthropic(responseWithEmptyContent, "test-model");
|
|
188
|
-
|
|
189
|
-
// Empty content results in a single empty text block (fallback behavior)
|
|
190
|
-
assert.strictEqual(result.role, "assistant");
|
|
191
|
-
assert.strictEqual(Array.isArray(result.content), true);
|
|
192
|
-
assert.strictEqual(result.content.length, 1);
|
|
193
|
-
assert.strictEqual(result.content[0].type, "text");
|
|
194
|
-
assert.strictEqual(result.content[0].text, "");
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it("should handle response with null content", () => {
|
|
198
|
-
const responseWithNullContent = {
|
|
199
|
-
choices: [
|
|
200
|
-
{
|
|
201
|
-
message: {
|
|
202
|
-
role: "assistant",
|
|
203
|
-
content: null
|
|
204
|
-
},
|
|
205
|
-
finish_reason: "stop"
|
|
206
|
-
}
|
|
207
|
-
],
|
|
208
|
-
model: "openai/gpt-4o-mini",
|
|
209
|
-
usage: { prompt_tokens: 10, completion_tokens: 0, total_tokens: 10 }
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
213
|
-
const result = convertOpenRouterResponseToAnthropic(responseWithNullContent, "test-model");
|
|
214
|
-
|
|
215
|
-
assert.strictEqual(result.role, "assistant");
|
|
216
|
-
assert.strictEqual(Array.isArray(result.content), true);
|
|
217
|
-
// Null content results in a single empty text block (fallback behavior)
|
|
218
|
-
assert.strictEqual(result.content.length, 1);
|
|
219
|
-
assert.strictEqual(result.content[0].type, "text");
|
|
220
|
-
assert.strictEqual(result.content[0].text, "");
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
describe("Tool Call Error Handling", () => {
|
|
225
|
-
it("should handle malformed tool call arguments", () => {
|
|
226
|
-
const responseWithInvalidToolArgs = {
|
|
227
|
-
choices: [
|
|
228
|
-
{
|
|
229
|
-
message: {
|
|
230
|
-
role: "assistant",
|
|
231
|
-
content: "Using tool",
|
|
232
|
-
tool_calls: [
|
|
233
|
-
{
|
|
234
|
-
id: "call_1",
|
|
235
|
-
type: "function",
|
|
236
|
-
function: {
|
|
237
|
-
name: "Write",
|
|
238
|
-
arguments: "not valid json {{"
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
]
|
|
242
|
-
},
|
|
243
|
-
finish_reason: "tool_calls"
|
|
244
|
-
}
|
|
245
|
-
],
|
|
246
|
-
model: "openai/gpt-4o-mini",
|
|
247
|
-
usage: { prompt_tokens: 10, completion_tokens: 20, total_tokens: 30 }
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
251
|
-
const result = convertOpenRouterResponseToAnthropic(responseWithInvalidToolArgs, "test-model");
|
|
252
|
-
|
|
253
|
-
// Should still convert, but with empty input object
|
|
254
|
-
assert.strictEqual(result.content.length, 2); // text + tool_use
|
|
255
|
-
assert.strictEqual(result.content[1].type, "tool_use");
|
|
256
|
-
assert.deepStrictEqual(result.content[1].input, {});
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it("should handle tool call with missing function name", () => {
|
|
260
|
-
const responseWithMissingName = {
|
|
261
|
-
choices: [
|
|
262
|
-
{
|
|
263
|
-
message: {
|
|
264
|
-
role: "assistant",
|
|
265
|
-
content: "Using tool",
|
|
266
|
-
tool_calls: [
|
|
267
|
-
{
|
|
268
|
-
id: "call_1",
|
|
269
|
-
type: "function",
|
|
270
|
-
function: {
|
|
271
|
-
arguments: JSON.stringify({ param: "value" })
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
]
|
|
275
|
-
},
|
|
276
|
-
finish_reason: "tool_calls"
|
|
277
|
-
}
|
|
278
|
-
],
|
|
279
|
-
model: "openai/gpt-4o-mini",
|
|
280
|
-
usage: { prompt_tokens: 10, completion_tokens: 20, total_tokens: 30 }
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
284
|
-
const result = convertOpenRouterResponseToAnthropic(responseWithMissingName, "test-model");
|
|
285
|
-
|
|
286
|
-
// Should use "unknown" as fallback name
|
|
287
|
-
assert.strictEqual(result.content[1].name, "unknown");
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it("should handle tool call with missing ID", () => {
|
|
291
|
-
const responseWithMissingId = {
|
|
292
|
-
choices: [
|
|
293
|
-
{
|
|
294
|
-
message: {
|
|
295
|
-
role: "assistant",
|
|
296
|
-
content: "Using tool",
|
|
297
|
-
tool_calls: [
|
|
298
|
-
{
|
|
299
|
-
type: "function",
|
|
300
|
-
function: {
|
|
301
|
-
name: "Write",
|
|
302
|
-
arguments: JSON.stringify({ file_path: "/tmp/test.txt" })
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
]
|
|
306
|
-
},
|
|
307
|
-
finish_reason: "tool_calls"
|
|
308
|
-
}
|
|
309
|
-
],
|
|
310
|
-
model: "openai/gpt-4o-mini",
|
|
311
|
-
usage: { prompt_tokens: 10, completion_tokens: 20, total_tokens: 30 }
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
315
|
-
const result = convertOpenRouterResponseToAnthropic(responseWithMissingId, "test-model");
|
|
316
|
-
|
|
317
|
-
// Should generate an ID
|
|
318
|
-
assert.strictEqual(typeof result.content[1].id, "string");
|
|
319
|
-
assert.strictEqual(result.content[1].id.startsWith("toolu_"), true);
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
describe("Usage Metadata Handling", () => {
|
|
324
|
-
it("should handle missing usage metadata", () => {
|
|
325
|
-
const responseWithoutUsage = {
|
|
326
|
-
choices: [
|
|
327
|
-
{
|
|
328
|
-
message: {
|
|
329
|
-
role: "assistant",
|
|
330
|
-
content: "Response"
|
|
331
|
-
},
|
|
332
|
-
finish_reason: "stop"
|
|
333
|
-
}
|
|
334
|
-
],
|
|
335
|
-
model: "openai/gpt-4o-mini"
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
339
|
-
const result = convertOpenRouterResponseToAnthropic(responseWithoutUsage, "test-model");
|
|
340
|
-
|
|
341
|
-
// Should have default usage with zeros
|
|
342
|
-
assert.strictEqual(typeof result.usage, "object");
|
|
343
|
-
assert.strictEqual(result.usage.input_tokens, 0);
|
|
344
|
-
assert.strictEqual(result.usage.output_tokens, 0);
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
it("should correctly map OpenRouter usage to Anthropic format", () => {
|
|
348
|
-
const responseWithUsage = {
|
|
349
|
-
choices: [
|
|
350
|
-
{
|
|
351
|
-
message: {
|
|
352
|
-
role: "assistant",
|
|
353
|
-
content: "Response"
|
|
354
|
-
},
|
|
355
|
-
finish_reason: "stop"
|
|
356
|
-
}
|
|
357
|
-
],
|
|
358
|
-
model: "openai/gpt-4o-mini",
|
|
359
|
-
usage: {
|
|
360
|
-
prompt_tokens: 100,
|
|
361
|
-
completion_tokens: 50,
|
|
362
|
-
total_tokens: 150
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
367
|
-
const result = convertOpenRouterResponseToAnthropic(responseWithUsage, "test-model");
|
|
368
|
-
|
|
369
|
-
// Should map prompt_tokens -> input_tokens, completion_tokens -> output_tokens
|
|
370
|
-
assert.strictEqual(result.usage.input_tokens, 100);
|
|
371
|
-
assert.strictEqual(result.usage.output_tokens, 50);
|
|
372
|
-
});
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
describe("Model ID Handling", () => {
|
|
376
|
-
it("should use requested model as the model ID", () => {
|
|
377
|
-
const response = {
|
|
378
|
-
choices: [
|
|
379
|
-
{
|
|
380
|
-
message: {
|
|
381
|
-
role: "assistant",
|
|
382
|
-
content: "Response"
|
|
383
|
-
},
|
|
384
|
-
finish_reason: "stop"
|
|
385
|
-
}
|
|
386
|
-
],
|
|
387
|
-
model: "openai/gpt-4o-mini",
|
|
388
|
-
usage: { prompt_tokens: 10, completion_tokens: 10, total_tokens: 20 }
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
392
|
-
const result = convertOpenRouterResponseToAnthropic(response, "claude-sonnet-4-5");
|
|
393
|
-
|
|
394
|
-
// The conversion uses the requested model, not the OpenRouter response model
|
|
395
|
-
assert.strictEqual(result.model, "claude-sonnet-4-5");
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
it("should use requested model as fallback when OpenRouter model missing", () => {
|
|
399
|
-
const response = {
|
|
400
|
-
choices: [
|
|
401
|
-
{
|
|
402
|
-
message: {
|
|
403
|
-
role: "assistant",
|
|
404
|
-
content: "Response"
|
|
405
|
-
},
|
|
406
|
-
finish_reason: "stop"
|
|
407
|
-
}
|
|
408
|
-
],
|
|
409
|
-
usage: { prompt_tokens: 10, completion_tokens: 10, total_tokens: 20 }
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
413
|
-
const result = convertOpenRouterResponseToAnthropic(response, "claude-sonnet-4-5");
|
|
414
|
-
|
|
415
|
-
assert.strictEqual(result.model, "claude-sonnet-4-5");
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
|
-
});
|