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,354 +0,0 @@
|
|
|
1
|
-
const assert = require("assert");
|
|
2
|
-
const { describe, it, beforeEach } = require("node:test");
|
|
3
|
-
|
|
4
|
-
describe("Azure OpenAI Format Conversion", () => {
|
|
5
|
-
let openrouterUtils;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
// Set MODEL_PROVIDER to avoid validation errors
|
|
9
|
-
process.env.MODEL_PROVIDER = "databricks";
|
|
10
|
-
process.env.DATABRICKS_API_KEY = "test-key";
|
|
11
|
-
process.env.DATABRICKS_API_BASE = "http://test.com";
|
|
12
|
-
|
|
13
|
-
// Clear module cache
|
|
14
|
-
delete require.cache[require.resolve("../src/clients/openrouter-utils")];
|
|
15
|
-
delete require.cache[require.resolve("../src/config")];
|
|
16
|
-
openrouterUtils = require("../src/clients/openrouter-utils");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe("Anthropic to Azure OpenAI (OpenAI format) Conversion", () => {
|
|
20
|
-
it("should convert simple Anthropic messages to OpenAI format", () => {
|
|
21
|
-
const anthropicMessages = [
|
|
22
|
-
{
|
|
23
|
-
role: "user",
|
|
24
|
-
content: "Hello, Azure OpenAI!"
|
|
25
|
-
}
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
const result = openrouterUtils.convertAnthropicMessagesToOpenRouter(anthropicMessages);
|
|
29
|
-
|
|
30
|
-
assert.strictEqual(result.length, 1);
|
|
31
|
-
assert.strictEqual(result[0].role, "user");
|
|
32
|
-
assert.strictEqual(result[0].content, "Hello, Azure OpenAI!");
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("should convert Anthropic content blocks to OpenAI text content", () => {
|
|
36
|
-
const anthropicMessages = [
|
|
37
|
-
{
|
|
38
|
-
role: "user",
|
|
39
|
-
content: [
|
|
40
|
-
{ type: "text", text: "Analyze this code" },
|
|
41
|
-
{ type: "text", text: "and provide feedback" }
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
];
|
|
45
|
-
|
|
46
|
-
const result = openrouterUtils.convertAnthropicMessagesToOpenRouter(anthropicMessages);
|
|
47
|
-
|
|
48
|
-
assert.strictEqual(result.length, 1);
|
|
49
|
-
assert.strictEqual(result[0].content, "Analyze this code\nand provide feedback");
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("should convert Anthropic tool_use to OpenAI tool_calls", () => {
|
|
53
|
-
const anthropicMessages = [
|
|
54
|
-
{
|
|
55
|
-
role: "assistant",
|
|
56
|
-
content: [
|
|
57
|
-
{ type: "text", text: "I'll read that file" },
|
|
58
|
-
{
|
|
59
|
-
type: "tool_use",
|
|
60
|
-
id: "toolu_abc123",
|
|
61
|
-
name: "Read",
|
|
62
|
-
input: { file_path: "/app/test.js" }
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
}
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
const result = openrouterUtils.convertAnthropicMessagesToOpenRouter(anthropicMessages);
|
|
69
|
-
|
|
70
|
-
assert.strictEqual(result.length, 1);
|
|
71
|
-
assert.strictEqual(result[0].role, "assistant");
|
|
72
|
-
assert.strictEqual(result[0].content, "I'll read that file");
|
|
73
|
-
assert.ok(Array.isArray(result[0].tool_calls));
|
|
74
|
-
assert.strictEqual(result[0].tool_calls.length, 1);
|
|
75
|
-
assert.strictEqual(result[0].tool_calls[0].id, "toolu_abc123");
|
|
76
|
-
assert.strictEqual(result[0].tool_calls[0].type, "function");
|
|
77
|
-
assert.strictEqual(result[0].tool_calls[0].function.name, "Read");
|
|
78
|
-
assert.strictEqual(result[0].tool_calls[0].function.arguments, '{"file_path":"/app/test.js"}');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("should convert Anthropic tool definitions to OpenAI tools format", () => {
|
|
82
|
-
const anthropicTools = [
|
|
83
|
-
{
|
|
84
|
-
name: "Write",
|
|
85
|
-
description: "Write content to a file",
|
|
86
|
-
input_schema: {
|
|
87
|
-
type: "object",
|
|
88
|
-
properties: {
|
|
89
|
-
file_path: { type: "string" },
|
|
90
|
-
content: { type: "string" }
|
|
91
|
-
},
|
|
92
|
-
required: ["file_path", "content"]
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
];
|
|
96
|
-
|
|
97
|
-
const result = openrouterUtils.convertAnthropicToolsToOpenRouter(anthropicTools);
|
|
98
|
-
|
|
99
|
-
assert.strictEqual(result.length, 1);
|
|
100
|
-
assert.strictEqual(result[0].type, "function");
|
|
101
|
-
assert.strictEqual(result[0].function.name, "Write");
|
|
102
|
-
assert.strictEqual(result[0].function.description, "Write content to a file");
|
|
103
|
-
assert.deepStrictEqual(result[0].function.parameters, anthropicTools[0].input_schema);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("should handle multiple tool conversions", () => {
|
|
107
|
-
const anthropicTools = [
|
|
108
|
-
{
|
|
109
|
-
name: "Read",
|
|
110
|
-
description: "Read file",
|
|
111
|
-
input_schema: {
|
|
112
|
-
type: "object",
|
|
113
|
-
properties: { file_path: { type: "string" } }
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
name: "Write",
|
|
118
|
-
description: "Write file",
|
|
119
|
-
input_schema: {
|
|
120
|
-
type: "object",
|
|
121
|
-
properties: { file_path: { type: "string" }, content: { type: "string" } }
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
];
|
|
125
|
-
|
|
126
|
-
const result = openrouterUtils.convertAnthropicToolsToOpenRouter(anthropicTools);
|
|
127
|
-
|
|
128
|
-
assert.strictEqual(result.length, 2);
|
|
129
|
-
assert.strictEqual(result[0].function.name, "Read");
|
|
130
|
-
assert.strictEqual(result[1].function.name, "Write");
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe("Azure OpenAI to Anthropic Conversion", () => {
|
|
135
|
-
it("should convert OpenAI text response to Anthropic format", () => {
|
|
136
|
-
const azureOpenAIResponse = {
|
|
137
|
-
choices: [
|
|
138
|
-
{
|
|
139
|
-
message: {
|
|
140
|
-
role: "assistant",
|
|
141
|
-
content: "Hello from Azure OpenAI!"
|
|
142
|
-
},
|
|
143
|
-
finish_reason: "stop"
|
|
144
|
-
}
|
|
145
|
-
],
|
|
146
|
-
usage: {
|
|
147
|
-
prompt_tokens: 10,
|
|
148
|
-
completion_tokens: 5,
|
|
149
|
-
total_tokens: 15
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const result = openrouterUtils.convertOpenRouterResponseToAnthropic(
|
|
154
|
-
azureOpenAIResponse,
|
|
155
|
-
"gpt-4o"
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
assert.strictEqual(result.role, "assistant");
|
|
159
|
-
assert.ok(Array.isArray(result.content));
|
|
160
|
-
assert.strictEqual(result.content.length, 1);
|
|
161
|
-
assert.strictEqual(result.content[0].type, "text");
|
|
162
|
-
assert.strictEqual(result.content[0].text, "Hello from Azure OpenAI!");
|
|
163
|
-
assert.strictEqual(result.stop_reason, "end_turn");
|
|
164
|
-
assert.strictEqual(result.usage.input_tokens, 10);
|
|
165
|
-
assert.strictEqual(result.usage.output_tokens, 5);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("should convert OpenAI tool_calls to Anthropic tool_use", () => {
|
|
169
|
-
const azureOpenAIResponse = {
|
|
170
|
-
choices: [
|
|
171
|
-
{
|
|
172
|
-
message: {
|
|
173
|
-
role: "assistant",
|
|
174
|
-
content: "I'll execute that bash command",
|
|
175
|
-
tool_calls: [
|
|
176
|
-
{
|
|
177
|
-
id: "call_xyz789",
|
|
178
|
-
type: "function",
|
|
179
|
-
function: {
|
|
180
|
-
name: "Bash",
|
|
181
|
-
arguments: '{"command": "ls -la"}'
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
]
|
|
185
|
-
},
|
|
186
|
-
finish_reason: "tool_calls"
|
|
187
|
-
}
|
|
188
|
-
],
|
|
189
|
-
usage: {
|
|
190
|
-
prompt_tokens: 20,
|
|
191
|
-
completion_tokens: 10
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
const result = openrouterUtils.convertOpenRouterResponseToAnthropic(
|
|
196
|
-
azureOpenAIResponse,
|
|
197
|
-
"gpt-4o"
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
assert.strictEqual(result.role, "assistant");
|
|
201
|
-
assert.ok(Array.isArray(result.content));
|
|
202
|
-
assert.strictEqual(result.content.length, 2);
|
|
203
|
-
|
|
204
|
-
// Text content
|
|
205
|
-
assert.strictEqual(result.content[0].type, "text");
|
|
206
|
-
assert.strictEqual(result.content[0].text, "I'll execute that bash command");
|
|
207
|
-
|
|
208
|
-
// Tool use
|
|
209
|
-
assert.strictEqual(result.content[1].type, "tool_use");
|
|
210
|
-
assert.strictEqual(result.content[1].id, "call_xyz789");
|
|
211
|
-
assert.strictEqual(result.content[1].name, "Bash");
|
|
212
|
-
assert.deepStrictEqual(result.content[1].input, { command: "ls -la" });
|
|
213
|
-
|
|
214
|
-
assert.strictEqual(result.stop_reason, "tool_use");
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it("should handle multiple tool calls", () => {
|
|
218
|
-
const azureOpenAIResponse = {
|
|
219
|
-
choices: [
|
|
220
|
-
{
|
|
221
|
-
message: {
|
|
222
|
-
role: "assistant",
|
|
223
|
-
content: null,
|
|
224
|
-
tool_calls: [
|
|
225
|
-
{
|
|
226
|
-
id: "call_1",
|
|
227
|
-
type: "function",
|
|
228
|
-
function: {
|
|
229
|
-
name: "Read",
|
|
230
|
-
arguments: '{"file_path": "/app/file1.js"}'
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
{
|
|
234
|
-
id: "call_2",
|
|
235
|
-
type: "function",
|
|
236
|
-
function: {
|
|
237
|
-
name: "Read",
|
|
238
|
-
arguments: '{"file_path": "/app/file2.js"}'
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
]
|
|
242
|
-
},
|
|
243
|
-
finish_reason: "tool_calls"
|
|
244
|
-
}
|
|
245
|
-
]
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
const result = openrouterUtils.convertOpenRouterResponseToAnthropic(
|
|
249
|
-
azureOpenAIResponse,
|
|
250
|
-
"gpt-4o"
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
assert.strictEqual(result.content.length, 2);
|
|
254
|
-
assert.strictEqual(result.content[0].type, "tool_use");
|
|
255
|
-
assert.strictEqual(result.content[0].name, "Read");
|
|
256
|
-
assert.strictEqual(result.content[1].type, "tool_use");
|
|
257
|
-
assert.strictEqual(result.content[1].name, "Read");
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
it("should handle empty/null content gracefully", () => {
|
|
261
|
-
const azureOpenAIResponse = {
|
|
262
|
-
choices: [
|
|
263
|
-
{
|
|
264
|
-
message: {
|
|
265
|
-
role: "assistant",
|
|
266
|
-
content: null
|
|
267
|
-
},
|
|
268
|
-
finish_reason: "stop"
|
|
269
|
-
}
|
|
270
|
-
]
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
const result = openrouterUtils.convertOpenRouterResponseToAnthropic(
|
|
274
|
-
azureOpenAIResponse,
|
|
275
|
-
"gpt-4o"
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
assert.strictEqual(result.role, "assistant");
|
|
279
|
-
assert.ok(Array.isArray(result.content));
|
|
280
|
-
// OpenRouter utils creates an empty text block for null content
|
|
281
|
-
assert.strictEqual(result.content.length, 1);
|
|
282
|
-
assert.strictEqual(result.content[0].type, "text");
|
|
283
|
-
assert.strictEqual(result.content[0].text, "");
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it("should convert finish_reason correctly", () => {
|
|
287
|
-
const stopResponse = {
|
|
288
|
-
choices: [{ message: { role: "assistant", content: "Done" }, finish_reason: "stop" }]
|
|
289
|
-
};
|
|
290
|
-
const toolCallsResponse = {
|
|
291
|
-
choices: [{
|
|
292
|
-
message: { role: "assistant", content: null, tool_calls: [{ id: "1", type: "function", function: { name: "Test", arguments: "{}" } }] },
|
|
293
|
-
finish_reason: "tool_calls"
|
|
294
|
-
}]
|
|
295
|
-
};
|
|
296
|
-
const lengthResponse = {
|
|
297
|
-
choices: [{ message: { role: "assistant", content: "Text" }, finish_reason: "length" }]
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
const stopResult = openrouterUtils.convertOpenRouterResponseToAnthropic(stopResponse, "gpt-4o");
|
|
301
|
-
const toolCallsResult = openrouterUtils.convertOpenRouterResponseToAnthropic(toolCallsResponse, "gpt-4o");
|
|
302
|
-
const lengthResult = openrouterUtils.convertOpenRouterResponseToAnthropic(lengthResponse, "gpt-4o");
|
|
303
|
-
|
|
304
|
-
assert.strictEqual(stopResult.stop_reason, "end_turn");
|
|
305
|
-
assert.strictEqual(toolCallsResult.stop_reason, "tool_use");
|
|
306
|
-
assert.strictEqual(lengthResult.stop_reason, "max_tokens");
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
describe("Round-Trip Integrity", () => {
|
|
311
|
-
it("should maintain data integrity through Anthropic -> OpenAI -> Anthropic conversion", () => {
|
|
312
|
-
// Original Anthropic format
|
|
313
|
-
const originalTools = [
|
|
314
|
-
{
|
|
315
|
-
name: "Bash",
|
|
316
|
-
description: "Execute bash command",
|
|
317
|
-
input_schema: {
|
|
318
|
-
type: "object",
|
|
319
|
-
properties: {
|
|
320
|
-
command: { type: "string", description: "The command to execute" }
|
|
321
|
-
},
|
|
322
|
-
required: ["command"]
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
];
|
|
326
|
-
|
|
327
|
-
// Convert to OpenAI format
|
|
328
|
-
const openAITools = openrouterUtils.convertAnthropicToolsToOpenRouter(originalTools);
|
|
329
|
-
|
|
330
|
-
// Verify OpenAI format structure
|
|
331
|
-
assert.strictEqual(openAITools[0].type, "function");
|
|
332
|
-
assert.strictEqual(openAITools[0].function.name, "Bash");
|
|
333
|
-
assert.strictEqual(openAITools[0].function.description, "Execute bash command");
|
|
334
|
-
|
|
335
|
-
// Verify schema is preserved
|
|
336
|
-
assert.deepStrictEqual(openAITools[0].function.parameters, originalTools[0].input_schema);
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
it("should handle text-only conversation round-trip", () => {
|
|
340
|
-
const anthropicMessages = [
|
|
341
|
-
{ role: "user", content: "Hello" },
|
|
342
|
-
{ role: "assistant", content: [{ type: "text", text: "Hi there!" }] },
|
|
343
|
-
{ role: "user", content: "How are you?" }
|
|
344
|
-
];
|
|
345
|
-
|
|
346
|
-
const openAIMessages = openrouterUtils.convertAnthropicMessagesToOpenRouter(anthropicMessages);
|
|
347
|
-
|
|
348
|
-
assert.strictEqual(openAIMessages.length, 3);
|
|
349
|
-
assert.strictEqual(openAIMessages[0].content, "Hello");
|
|
350
|
-
assert.strictEqual(openAIMessages[1].content, "Hi there!");
|
|
351
|
-
assert.strictEqual(openAIMessages[2].content, "How are you?");
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
});
|
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
const assert = require("assert");
|
|
2
|
-
const { describe, it, beforeEach, afterEach } = require("node:test");
|
|
3
|
-
|
|
4
|
-
describe("Azure OpenAI Integration Tests", () => {
|
|
5
|
-
let originalConfig;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
// Clear module cache
|
|
9
|
-
delete require.cache[require.resolve("../src/config")];
|
|
10
|
-
delete require.cache[require.resolve("../src/clients/databricks")];
|
|
11
|
-
delete require.cache[require.resolve("../src/observability/metrics")];
|
|
12
|
-
|
|
13
|
-
// Store original config
|
|
14
|
-
originalConfig = { ...process.env };
|
|
15
|
-
|
|
16
|
-
// Set default provider to avoid validation errors
|
|
17
|
-
process.env.MODEL_PROVIDER = "databricks";
|
|
18
|
-
process.env.DATABRICKS_API_KEY = "test-key";
|
|
19
|
-
process.env.DATABRICKS_API_BASE = "http://test.com";
|
|
20
|
-
|
|
21
|
-
// Prevent .env TIER_* values from being picked up by dotenv
|
|
22
|
-
process.env.TIER_SIMPLE = "";
|
|
23
|
-
process.env.TIER_MEDIUM = "";
|
|
24
|
-
process.env.TIER_COMPLEX = "";
|
|
25
|
-
process.env.TIER_REASONING = "";
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
// Restore original environment
|
|
30
|
-
process.env = originalConfig;
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe("End-to-End Request Flow", () => {
|
|
34
|
-
it("should construct valid Azure OpenAI request URL", () => {
|
|
35
|
-
process.env.AZURE_OPENAI_ENDPOINT = "https://test-resource.openai.azure.com";
|
|
36
|
-
process.env.AZURE_OPENAI_DEPLOYMENT = "gpt-4o";
|
|
37
|
-
process.env.AZURE_OPENAI_API_VERSION = "2024-08-01-preview";
|
|
38
|
-
|
|
39
|
-
const config = require("../src/config");
|
|
40
|
-
|
|
41
|
-
const expectedURL = `${config.azureOpenAI.endpoint}/openai/deployments/${config.azureOpenAI.deployment}/chat/completions?api-version=${config.azureOpenAI.apiVersion}`;
|
|
42
|
-
|
|
43
|
-
assert.strictEqual(
|
|
44
|
-
expectedURL,
|
|
45
|
-
"https://test-resource.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview"
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("should construct valid request headers with api-key", () => {
|
|
50
|
-
process.env.AZURE_OPENAI_API_KEY = "test-api-key-12345";
|
|
51
|
-
|
|
52
|
-
const config = require("../src/config");
|
|
53
|
-
|
|
54
|
-
const headers = {
|
|
55
|
-
"api-key": config.azureOpenAI.apiKey,
|
|
56
|
-
"Content-Type": "application/json"
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
assert.strictEqual(headers["api-key"], "test-api-key-12345");
|
|
60
|
-
assert.strictEqual(headers["Content-Type"], "application/json");
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("should construct request body with messages and tools", () => {
|
|
64
|
-
const { convertAnthropicMessagesToOpenRouter, convertAnthropicToolsToOpenRouter } = require("../src/clients/openrouter-utils");
|
|
65
|
-
|
|
66
|
-
const anthropicMessages = [
|
|
67
|
-
{ role: "user", content: "Read /app/test.js" }
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
const anthropicTools = [
|
|
71
|
-
{
|
|
72
|
-
name: "Read",
|
|
73
|
-
description: "Read file",
|
|
74
|
-
input_schema: {
|
|
75
|
-
type: "object",
|
|
76
|
-
properties: { file_path: { type: "string" } },
|
|
77
|
-
required: ["file_path"]
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
const messages = convertAnthropicMessagesToOpenRouter(anthropicMessages);
|
|
83
|
-
const tools = convertAnthropicToolsToOpenRouter(anthropicTools);
|
|
84
|
-
|
|
85
|
-
const requestBody = {
|
|
86
|
-
messages,
|
|
87
|
-
tools,
|
|
88
|
-
temperature: 0.7,
|
|
89
|
-
max_tokens: 4096,
|
|
90
|
-
stream: false
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
assert.ok(Array.isArray(requestBody.messages));
|
|
94
|
-
assert.strictEqual(requestBody.messages[0].content, "Read /app/test.js");
|
|
95
|
-
assert.ok(Array.isArray(requestBody.tools));
|
|
96
|
-
assert.strictEqual(requestBody.tools[0].function.name, "Read");
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe("Tool Calling Round Trip", () => {
|
|
101
|
-
it("should handle complete tool calling flow", () => {
|
|
102
|
-
const { convertAnthropicToolsToOpenRouter, convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
103
|
-
|
|
104
|
-
// Step 1: Convert Anthropic tools to Azure OpenAI format
|
|
105
|
-
const anthropicTools = [
|
|
106
|
-
{
|
|
107
|
-
name: "Bash",
|
|
108
|
-
description: "Execute bash command",
|
|
109
|
-
input_schema: {
|
|
110
|
-
type: "object",
|
|
111
|
-
properties: { command: { type: "string" } },
|
|
112
|
-
required: ["command"]
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
];
|
|
116
|
-
|
|
117
|
-
const azureTools = convertAnthropicToolsToOpenRouter(anthropicTools);
|
|
118
|
-
|
|
119
|
-
assert.strictEqual(azureTools[0].type, "function");
|
|
120
|
-
assert.strictEqual(azureTools[0].function.name, "Bash");
|
|
121
|
-
|
|
122
|
-
// Step 2: Simulate Azure OpenAI response with tool call
|
|
123
|
-
const azureResponse = {
|
|
124
|
-
choices: [
|
|
125
|
-
{
|
|
126
|
-
message: {
|
|
127
|
-
role: "assistant",
|
|
128
|
-
content: "I'll run that command",
|
|
129
|
-
tool_calls: [
|
|
130
|
-
{
|
|
131
|
-
id: "call_123",
|
|
132
|
-
type: "function",
|
|
133
|
-
function: {
|
|
134
|
-
name: "Bash",
|
|
135
|
-
arguments: '{"command":"ls -la"}'
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
]
|
|
139
|
-
},
|
|
140
|
-
finish_reason: "tool_calls"
|
|
141
|
-
}
|
|
142
|
-
],
|
|
143
|
-
usage: {
|
|
144
|
-
prompt_tokens: 50,
|
|
145
|
-
completion_tokens: 20
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
// Step 3: Convert Azure OpenAI response to Anthropic format
|
|
150
|
-
const anthropicResponse = convertOpenRouterResponseToAnthropic(azureResponse, "gpt-4o");
|
|
151
|
-
|
|
152
|
-
assert.strictEqual(anthropicResponse.role, "assistant");
|
|
153
|
-
assert.strictEqual(anthropicResponse.stop_reason, "tool_use");
|
|
154
|
-
|
|
155
|
-
const textContent = anthropicResponse.content.find(c => c.type === "text");
|
|
156
|
-
const toolUse = anthropicResponse.content.find(c => c.type === "tool_use");
|
|
157
|
-
|
|
158
|
-
assert.strictEqual(textContent.text, "I'll run that command");
|
|
159
|
-
assert.strictEqual(toolUse.name, "Bash");
|
|
160
|
-
assert.deepStrictEqual(toolUse.input, { command: "ls -la" });
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe("Provider Selection Integration", () => {
|
|
165
|
-
it("should select azure-openai as primary provider", () => {
|
|
166
|
-
process.env.MODEL_PROVIDER = "azure-openai";
|
|
167
|
-
process.env.AZURE_OPENAI_ENDPOINT = "https://test.openai.azure.com";
|
|
168
|
-
process.env.AZURE_OPENAI_API_KEY = "test-key";
|
|
169
|
-
|
|
170
|
-
const config = require("../src/config");
|
|
171
|
-
|
|
172
|
-
assert.strictEqual(config.modelProvider.type, "azure-openai");
|
|
173
|
-
assert.strictEqual(config.azureOpenAI.endpoint, "https://test.openai.azure.com");
|
|
174
|
-
assert.strictEqual(config.azureOpenAI.apiKey, "test-key");
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("should select azure-openai as fallback provider", () => {
|
|
178
|
-
process.env.MODEL_PROVIDER = "ollama";
|
|
179
|
-
process.env.OLLAMA_ENDPOINT = "http://localhost:11434";
|
|
180
|
-
process.env.OLLAMA_MODEL = "qwen2.5-coder:latest";
|
|
181
|
-
process.env.FALLBACK_ENABLED = "true";
|
|
182
|
-
process.env.FALLBACK_PROVIDER = "azure-openai";
|
|
183
|
-
process.env.AZURE_OPENAI_ENDPOINT = "https://test.openai.azure.com";
|
|
184
|
-
process.env.AZURE_OPENAI_API_KEY = "test-key";
|
|
185
|
-
process.env.DATABRICKS_API_KEY = "test-key";
|
|
186
|
-
process.env.DATABRICKS_API_BASE = "http://test.com";
|
|
187
|
-
|
|
188
|
-
const config = require("../src/config");
|
|
189
|
-
|
|
190
|
-
assert.strictEqual(config.modelProvider.fallbackProvider, "azure-openai");
|
|
191
|
-
assert.strictEqual(config.modelProvider.fallbackEnabled, true);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
describe("Response Conversion Integration", () => {
|
|
196
|
-
it("should handle text-only response conversion", () => {
|
|
197
|
-
const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
|
|
198
|
-
|
|
199
|
-
const azureResponse = {
|
|
200
|
-
id: "chatcmpl-abc123",
|
|
201
|
-
object: "chat.completion",
|
|
202
|
-
created: 1677652288,
|
|
203
|
-
model: "gpt-4o",
|
|
204
|
-
choices: [
|
|
205
|
-
{
|
|
206
|
-
index: 0,
|
|
207
|
-
message: {
|
|
208
|
-
role: "assistant",
|
|
209
|
-
content: "The file contains JavaScript code for a web server."
|
|
210
|
-
},
|
|
211
|
-
finish_reason: "stop"
|
|
212
|
-
}
|
|
213
|
-
],
|
|
214
|
-
usage: {
|
|
215
|
-
prompt_tokens: 100,
|
|
216
|
-
completion_tokens: 50,
|
|
217
|
-
total_tokens: 150
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const anthropicResponse = convertOpenRouterResponseToAnthropic(azureResponse, "gpt-4o");
|
|
222
|
-
|
|
223
|
-
assert.strictEqual(anthropicResponse.role, "assistant");
|
|
224
|
-
assert.strictEqual(anthropicResponse.stop_reason, "end_turn");
|
|
225
|
-
assert.strictEqual(anthropicResponse.model, "gpt-4o");
|
|
226
|
-
assert.strictEqual(anthropicResponse.usage.input_tokens, 100);
|
|
227
|
-
assert.strictEqual(anthropicResponse.usage.output_tokens, 50);
|
|
228
|
-
assert.strictEqual(anthropicResponse.content[0].type, "text");
|
|
229
|
-
assert.strictEqual(anthropicResponse.content[0].text, "The file contains JavaScript code for a web server.");
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it("should handle multi-turn conversation", () => {
|
|
233
|
-
const { convertAnthropicMessagesToOpenRouter } = require("../src/clients/openrouter-utils");
|
|
234
|
-
|
|
235
|
-
const anthropicMessages = [
|
|
236
|
-
{ role: "user", content: "What is 2+2?" },
|
|
237
|
-
{ role: "assistant", content: [{ type: "text", text: "2+2 equals 4." }] },
|
|
238
|
-
{ role: "user", content: "What about 3+3?" }
|
|
239
|
-
];
|
|
240
|
-
|
|
241
|
-
const azureMessages = convertAnthropicMessagesToOpenRouter(anthropicMessages);
|
|
242
|
-
|
|
243
|
-
assert.strictEqual(azureMessages.length, 3);
|
|
244
|
-
assert.strictEqual(azureMessages[0].role, "user");
|
|
245
|
-
assert.strictEqual(azureMessages[0].content, "What is 2+2?");
|
|
246
|
-
assert.strictEqual(azureMessages[1].role, "assistant");
|
|
247
|
-
assert.strictEqual(azureMessages[1].content, "2+2 equals 4.");
|
|
248
|
-
assert.strictEqual(azureMessages[2].role, "user");
|
|
249
|
-
assert.strictEqual(azureMessages[2].content, "What about 3+3?");
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
describe("Multiple Deployments Support", () => {
|
|
254
|
-
it("should support gpt-4o deployment", () => {
|
|
255
|
-
process.env.AZURE_OPENAI_DEPLOYMENT = "gpt-4o";
|
|
256
|
-
process.env.MODEL_PROVIDER = "databricks";
|
|
257
|
-
process.env.DATABRICKS_API_KEY = "test-key";
|
|
258
|
-
process.env.DATABRICKS_API_BASE = "http://test.com";
|
|
259
|
-
|
|
260
|
-
const config = require("../src/config");
|
|
261
|
-
|
|
262
|
-
assert.strictEqual(config.azureOpenAI.deployment, "gpt-4o");
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it("should support gpt-5 deployment", () => {
|
|
266
|
-
process.env.AZURE_OPENAI_DEPLOYMENT = "gpt-5";
|
|
267
|
-
process.env.MODEL_PROVIDER = "databricks";
|
|
268
|
-
process.env.DATABRICKS_API_KEY = "test-key";
|
|
269
|
-
process.env.DATABRICKS_API_BASE = "http://test.com";
|
|
270
|
-
|
|
271
|
-
const config = require("../src/config");
|
|
272
|
-
|
|
273
|
-
assert.strictEqual(config.azureOpenAI.deployment, "gpt-5");
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it("should support custom deployment names", () => {
|
|
277
|
-
process.env.AZURE_OPENAI_DEPLOYMENT = "my-custom-gpt-5-codex";
|
|
278
|
-
process.env.MODEL_PROVIDER = "databricks";
|
|
279
|
-
process.env.DATABRICKS_API_KEY = "test-key";
|
|
280
|
-
process.env.DATABRICKS_API_BASE = "http://test.com";
|
|
281
|
-
|
|
282
|
-
const config = require("../src/config");
|
|
283
|
-
|
|
284
|
-
assert.strictEqual(config.azureOpenAI.deployment, "my-custom-gpt-5-codex");
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
});
|