lynkr 7.2.5 → 8.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.
Files changed (124) hide show
  1. package/README.md +3 -3
  2. package/config/model-tiers.json +89 -0
  3. package/install.sh +6 -1
  4. package/package.json +4 -2
  5. package/scripts/setup.js +0 -1
  6. package/src/agents/executor.js +14 -6
  7. package/src/api/middleware/session.js +15 -2
  8. package/src/api/openai-router.js +162 -37
  9. package/src/api/providers-handler.js +15 -1
  10. package/src/api/router.js +107 -2
  11. package/src/budget/index.js +4 -3
  12. package/src/clients/databricks.js +431 -234
  13. package/src/clients/gpt-utils.js +181 -0
  14. package/src/clients/ollama-utils.js +66 -140
  15. package/src/clients/routing.js +0 -1
  16. package/src/clients/standard-tools.js +99 -3
  17. package/src/config/index.js +133 -35
  18. package/src/context/toon.js +173 -0
  19. package/src/logger/index.js +23 -0
  20. package/src/orchestrator/index.js +688 -213
  21. package/src/routing/agentic-detector.js +320 -0
  22. package/src/routing/complexity-analyzer.js +202 -2
  23. package/src/routing/cost-optimizer.js +305 -0
  24. package/src/routing/index.js +168 -159
  25. package/src/routing/model-tiers.js +365 -0
  26. package/src/server.js +4 -14
  27. package/src/sessions/cleanup.js +3 -3
  28. package/src/sessions/record.js +10 -1
  29. package/src/sessions/store.js +7 -2
  30. package/src/tools/agent-task.js +48 -1
  31. package/src/tools/index.js +19 -2
  32. package/src/tools/lazy-loader.js +7 -0
  33. package/src/tools/tinyfish.js +358 -0
  34. package/src/tools/truncate.js +1 -0
  35. package/.github/FUNDING.yml +0 -15
  36. package/.github/workflows/README.md +0 -215
  37. package/.github/workflows/ci.yml +0 -69
  38. package/.github/workflows/index.yml +0 -62
  39. package/.github/workflows/web-tools-tests.yml +0 -56
  40. package/CITATIONS.bib +0 -6
  41. package/CLAWROUTER_ROUTING_PLAN.md +0 -910
  42. package/DEPLOYMENT.md +0 -1001
  43. package/LYNKR-TUI-PLAN.md +0 -984
  44. package/PERFORMANCE-REPORT.md +0 -866
  45. package/PLAN-per-client-model-routing.md +0 -252
  46. package/ROUTER_COMPARISON.md +0 -173
  47. package/TIER_ROUTING_PLAN.md +0 -771
  48. package/docs/42642f749da6234f41b6b425c3bb07c9.txt +0 -1
  49. package/docs/BingSiteAuth.xml +0 -4
  50. package/docs/docs-style.css +0 -478
  51. package/docs/docs.html +0 -197
  52. package/docs/google5be250e608e6da39.html +0 -1
  53. package/docs/index.html +0 -577
  54. package/docs/index.md +0 -577
  55. package/docs/robots.txt +0 -4
  56. package/docs/sitemap.xml +0 -44
  57. package/docs/style.css +0 -1223
  58. package/documentation/README.md +0 -100
  59. package/documentation/api.md +0 -806
  60. package/documentation/claude-code-cli.md +0 -672
  61. package/documentation/codex-cli.md +0 -397
  62. package/documentation/contributing.md +0 -571
  63. package/documentation/cursor-integration.md +0 -731
  64. package/documentation/docker.md +0 -867
  65. package/documentation/embeddings.md +0 -760
  66. package/documentation/faq.md +0 -659
  67. package/documentation/features.md +0 -396
  68. package/documentation/headroom.md +0 -519
  69. package/documentation/installation.md +0 -706
  70. package/documentation/memory-system.md +0 -476
  71. package/documentation/production.md +0 -601
  72. package/documentation/providers.md +0 -906
  73. package/documentation/testing.md +0 -629
  74. package/documentation/token-optimization.md +0 -323
  75. package/documentation/tools.md +0 -697
  76. package/documentation/troubleshooting.md +0 -893
  77. package/final-test.js +0 -33
  78. package/headroom-sidecar/config.py +0 -93
  79. package/headroom-sidecar/requirements.txt +0 -14
  80. package/headroom-sidecar/server.py +0 -451
  81. package/monitor-agents.sh +0 -31
  82. package/scripts/audit-log-reader.js +0 -399
  83. package/scripts/compact-dictionary.js +0 -204
  84. package/scripts/test-deduplication.js +0 -448
  85. package/src/db/database.sqlite +0 -0
  86. package/test/README.md +0 -212
  87. package/test/azure-openai-config.test.js +0 -204
  88. package/test/azure-openai-error-resilience.test.js +0 -238
  89. package/test/azure-openai-format-conversion.test.js +0 -354
  90. package/test/azure-openai-integration.test.js +0 -281
  91. package/test/azure-openai-routing.test.js +0 -177
  92. package/test/azure-openai-streaming.test.js +0 -171
  93. package/test/bedrock-integration.test.js +0 -471
  94. package/test/comprehensive-test-suite.js +0 -928
  95. package/test/config-validation.test.js +0 -207
  96. package/test/cursor-integration.test.js +0 -484
  97. package/test/format-conversion.test.js +0 -578
  98. package/test/hybrid-routing-integration.test.js +0 -254
  99. package/test/hybrid-routing-performance.test.js +0 -418
  100. package/test/llamacpp-integration.test.js +0 -863
  101. package/test/lmstudio-integration.test.js +0 -335
  102. package/test/memory/extractor.test.js +0 -398
  103. package/test/memory/retriever.test.js +0 -613
  104. package/test/memory/retriever.test.js.bak +0 -585
  105. package/test/memory/search.test.js +0 -537
  106. package/test/memory/search.test.js.bak +0 -389
  107. package/test/memory/store.test.js +0 -344
  108. package/test/memory/store.test.js.bak +0 -312
  109. package/test/memory/surprise.test.js +0 -300
  110. package/test/memory-performance.test.js +0 -472
  111. package/test/openai-integration.test.js +0 -686
  112. package/test/openrouter-error-resilience.test.js +0 -418
  113. package/test/passthrough-mode.test.js +0 -385
  114. package/test/performance-benchmark.js +0 -351
  115. package/test/performance-tests.js +0 -528
  116. package/test/routing.test.js +0 -219
  117. package/test/web-tools.test.js +0 -329
  118. package/test-agents-simple.js +0 -43
  119. package/test-cli-connection.sh +0 -33
  120. package/test-learning-unit.js +0 -126
  121. package/test-learning.js +0 -112
  122. package/test-parallel-agents.sh +0 -124
  123. package/test-parallel-direct.js +0 -155
  124. 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,281 +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
-
22
- afterEach(() => {
23
- // Restore original environment
24
- process.env = originalConfig;
25
- });
26
-
27
- describe("End-to-End Request Flow", () => {
28
- it("should construct valid Azure OpenAI request URL", () => {
29
- process.env.AZURE_OPENAI_ENDPOINT = "https://test-resource.openai.azure.com";
30
- process.env.AZURE_OPENAI_DEPLOYMENT = "gpt-4o";
31
- process.env.AZURE_OPENAI_API_VERSION = "2024-08-01-preview";
32
-
33
- const config = require("../src/config");
34
-
35
- const expectedURL = `${config.azureOpenAI.endpoint}/openai/deployments/${config.azureOpenAI.deployment}/chat/completions?api-version=${config.azureOpenAI.apiVersion}`;
36
-
37
- assert.strictEqual(
38
- expectedURL,
39
- "https://test-resource.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview"
40
- );
41
- });
42
-
43
- it("should construct valid request headers with api-key", () => {
44
- process.env.AZURE_OPENAI_API_KEY = "test-api-key-12345";
45
-
46
- const config = require("../src/config");
47
-
48
- const headers = {
49
- "api-key": config.azureOpenAI.apiKey,
50
- "Content-Type": "application/json"
51
- };
52
-
53
- assert.strictEqual(headers["api-key"], "test-api-key-12345");
54
- assert.strictEqual(headers["Content-Type"], "application/json");
55
- });
56
-
57
- it("should construct request body with messages and tools", () => {
58
- const { convertAnthropicMessagesToOpenRouter, convertAnthropicToolsToOpenRouter } = require("../src/clients/openrouter-utils");
59
-
60
- const anthropicMessages = [
61
- { role: "user", content: "Read /app/test.js" }
62
- ];
63
-
64
- const anthropicTools = [
65
- {
66
- name: "Read",
67
- description: "Read file",
68
- input_schema: {
69
- type: "object",
70
- properties: { file_path: { type: "string" } },
71
- required: ["file_path"]
72
- }
73
- }
74
- ];
75
-
76
- const messages = convertAnthropicMessagesToOpenRouter(anthropicMessages);
77
- const tools = convertAnthropicToolsToOpenRouter(anthropicTools);
78
-
79
- const requestBody = {
80
- messages,
81
- tools,
82
- temperature: 0.7,
83
- max_tokens: 4096,
84
- stream: false
85
- };
86
-
87
- assert.ok(Array.isArray(requestBody.messages));
88
- assert.strictEqual(requestBody.messages[0].content, "Read /app/test.js");
89
- assert.ok(Array.isArray(requestBody.tools));
90
- assert.strictEqual(requestBody.tools[0].function.name, "Read");
91
- });
92
- });
93
-
94
- describe("Tool Calling Round Trip", () => {
95
- it("should handle complete tool calling flow", () => {
96
- const { convertAnthropicToolsToOpenRouter, convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
97
-
98
- // Step 1: Convert Anthropic tools to Azure OpenAI format
99
- const anthropicTools = [
100
- {
101
- name: "Bash",
102
- description: "Execute bash command",
103
- input_schema: {
104
- type: "object",
105
- properties: { command: { type: "string" } },
106
- required: ["command"]
107
- }
108
- }
109
- ];
110
-
111
- const azureTools = convertAnthropicToolsToOpenRouter(anthropicTools);
112
-
113
- assert.strictEqual(azureTools[0].type, "function");
114
- assert.strictEqual(azureTools[0].function.name, "Bash");
115
-
116
- // Step 2: Simulate Azure OpenAI response with tool call
117
- const azureResponse = {
118
- choices: [
119
- {
120
- message: {
121
- role: "assistant",
122
- content: "I'll run that command",
123
- tool_calls: [
124
- {
125
- id: "call_123",
126
- type: "function",
127
- function: {
128
- name: "Bash",
129
- arguments: '{"command":"ls -la"}'
130
- }
131
- }
132
- ]
133
- },
134
- finish_reason: "tool_calls"
135
- }
136
- ],
137
- usage: {
138
- prompt_tokens: 50,
139
- completion_tokens: 20
140
- }
141
- };
142
-
143
- // Step 3: Convert Azure OpenAI response to Anthropic format
144
- const anthropicResponse = convertOpenRouterResponseToAnthropic(azureResponse, "gpt-4o");
145
-
146
- assert.strictEqual(anthropicResponse.role, "assistant");
147
- assert.strictEqual(anthropicResponse.stop_reason, "tool_use");
148
-
149
- const textContent = anthropicResponse.content.find(c => c.type === "text");
150
- const toolUse = anthropicResponse.content.find(c => c.type === "tool_use");
151
-
152
- assert.strictEqual(textContent.text, "I'll run that command");
153
- assert.strictEqual(toolUse.name, "Bash");
154
- assert.deepStrictEqual(toolUse.input, { command: "ls -la" });
155
- });
156
- });
157
-
158
- describe("Provider Selection Integration", () => {
159
- it("should select azure-openai as primary provider", () => {
160
- process.env.MODEL_PROVIDER = "azure-openai";
161
- process.env.AZURE_OPENAI_ENDPOINT = "https://test.openai.azure.com";
162
- process.env.AZURE_OPENAI_API_KEY = "test-key";
163
-
164
- const config = require("../src/config");
165
-
166
- assert.strictEqual(config.modelProvider.type, "azure-openai");
167
- assert.strictEqual(config.azureOpenAI.endpoint, "https://test.openai.azure.com");
168
- assert.strictEqual(config.azureOpenAI.apiKey, "test-key");
169
- });
170
-
171
- it("should select azure-openai as fallback provider", () => {
172
- process.env.PREFER_OLLAMA = "true";
173
- process.env.OLLAMA_ENDPOINT = "http://localhost:11434";
174
- process.env.OLLAMA_MODEL = "qwen2.5-coder:latest";
175
- process.env.FALLBACK_ENABLED = "true";
176
- process.env.FALLBACK_PROVIDER = "azure-openai";
177
- process.env.AZURE_OPENAI_ENDPOINT = "https://test.openai.azure.com";
178
- process.env.AZURE_OPENAI_API_KEY = "test-key";
179
- process.env.DATABRICKS_API_KEY = "test-key";
180
- process.env.DATABRICKS_API_BASE = "http://test.com";
181
-
182
- const config = require("../src/config");
183
-
184
- assert.strictEqual(config.modelProvider.fallbackProvider, "azure-openai");
185
- assert.strictEqual(config.modelProvider.fallbackEnabled, true);
186
- });
187
- });
188
-
189
- describe("Response Conversion Integration", () => {
190
- it("should handle text-only response conversion", () => {
191
- const { convertOpenRouterResponseToAnthropic } = require("../src/clients/openrouter-utils");
192
-
193
- const azureResponse = {
194
- id: "chatcmpl-abc123",
195
- object: "chat.completion",
196
- created: 1677652288,
197
- model: "gpt-4o",
198
- choices: [
199
- {
200
- index: 0,
201
- message: {
202
- role: "assistant",
203
- content: "The file contains JavaScript code for a web server."
204
- },
205
- finish_reason: "stop"
206
- }
207
- ],
208
- usage: {
209
- prompt_tokens: 100,
210
- completion_tokens: 50,
211
- total_tokens: 150
212
- }
213
- };
214
-
215
- const anthropicResponse = convertOpenRouterResponseToAnthropic(azureResponse, "gpt-4o");
216
-
217
- assert.strictEqual(anthropicResponse.role, "assistant");
218
- assert.strictEqual(anthropicResponse.stop_reason, "end_turn");
219
- assert.strictEqual(anthropicResponse.model, "gpt-4o");
220
- assert.strictEqual(anthropicResponse.usage.input_tokens, 100);
221
- assert.strictEqual(anthropicResponse.usage.output_tokens, 50);
222
- assert.strictEqual(anthropicResponse.content[0].type, "text");
223
- assert.strictEqual(anthropicResponse.content[0].text, "The file contains JavaScript code for a web server.");
224
- });
225
-
226
- it("should handle multi-turn conversation", () => {
227
- const { convertAnthropicMessagesToOpenRouter } = require("../src/clients/openrouter-utils");
228
-
229
- const anthropicMessages = [
230
- { role: "user", content: "What is 2+2?" },
231
- { role: "assistant", content: [{ type: "text", text: "2+2 equals 4." }] },
232
- { role: "user", content: "What about 3+3?" }
233
- ];
234
-
235
- const azureMessages = convertAnthropicMessagesToOpenRouter(anthropicMessages);
236
-
237
- assert.strictEqual(azureMessages.length, 3);
238
- assert.strictEqual(azureMessages[0].role, "user");
239
- assert.strictEqual(azureMessages[0].content, "What is 2+2?");
240
- assert.strictEqual(azureMessages[1].role, "assistant");
241
- assert.strictEqual(azureMessages[1].content, "2+2 equals 4.");
242
- assert.strictEqual(azureMessages[2].role, "user");
243
- assert.strictEqual(azureMessages[2].content, "What about 3+3?");
244
- });
245
- });
246
-
247
- describe("Multiple Deployments Support", () => {
248
- it("should support gpt-4o deployment", () => {
249
- process.env.AZURE_OPENAI_DEPLOYMENT = "gpt-4o";
250
- process.env.MODEL_PROVIDER = "databricks";
251
- process.env.DATABRICKS_API_KEY = "test-key";
252
- process.env.DATABRICKS_API_BASE = "http://test.com";
253
-
254
- const config = require("../src/config");
255
-
256
- assert.strictEqual(config.azureOpenAI.deployment, "gpt-4o");
257
- });
258
-
259
- it("should support gpt-5 deployment", () => {
260
- process.env.AZURE_OPENAI_DEPLOYMENT = "gpt-5";
261
- process.env.MODEL_PROVIDER = "databricks";
262
- process.env.DATABRICKS_API_KEY = "test-key";
263
- process.env.DATABRICKS_API_BASE = "http://test.com";
264
-
265
- const config = require("../src/config");
266
-
267
- assert.strictEqual(config.azureOpenAI.deployment, "gpt-5");
268
- });
269
-
270
- it("should support custom deployment names", () => {
271
- process.env.AZURE_OPENAI_DEPLOYMENT = "my-custom-gpt-5-codex";
272
- process.env.MODEL_PROVIDER = "databricks";
273
- process.env.DATABRICKS_API_KEY = "test-key";
274
- process.env.DATABRICKS_API_BASE = "http://test.com";
275
-
276
- const config = require("../src/config");
277
-
278
- assert.strictEqual(config.azureOpenAI.deployment, "my-custom-gpt-5-codex");
279
- });
280
- });
281
- });