@khanglvm/llm-router 2.0.2 → 2.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanglvm/llm-router",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "LLM Router: single gateway endpoint for multi-provider LLMs with unified OpenAI+Anthropic format and seamless fallback",
5
5
  "keywords": [
6
6
  "llm-router",
@@ -31,7 +31,8 @@
31
31
  "deploy:worker": "node ./src/cli-entry.js deploy",
32
32
  "test:provider-live": "node --test --test-concurrency=1 ./test/live-provider-suite.test.js",
33
33
  "test:provider-smoke": "npm run test:provider-live",
34
- "test:amp-smoke": "node ./scripts/amp-smoke-suite.mjs"
34
+ "test:amp-smoke": "node ./scripts/amp-smoke-suite.mjs",
35
+ "prepublishOnly": "npm run test:provider-live"
35
36
  },
36
37
  "dependencies": {
37
38
  "@levu/snap": "^0.3.13"
@@ -80,7 +80,7 @@ const READ_WEB_PAGE_FUNCTION_PARAMETERS = {
80
80
  additionalProperties: true
81
81
  };
82
82
 
83
- const OPENAI_WEB_SEARCH_TOOL = Object.freeze({
83
+ const OPENAI_CHAT_WEB_SEARCH_TOOL = Object.freeze({
84
84
  type: "function",
85
85
  function: {
86
86
  name: SEARCH_TOOL_NAME,
@@ -89,13 +89,20 @@ const OPENAI_WEB_SEARCH_TOOL = Object.freeze({
89
89
  }
90
90
  });
91
91
 
92
+ const OPENAI_RESPONSES_WEB_SEARCH_TOOL = Object.freeze({
93
+ type: "function",
94
+ name: SEARCH_TOOL_NAME,
95
+ description: "Search the web for current information, news, documentation, or real-time facts.",
96
+ parameters: WEB_SEARCH_FUNCTION_PARAMETERS
97
+ });
98
+
92
99
  const CLAUDE_WEB_SEARCH_TOOL = Object.freeze({
93
100
  name: SEARCH_TOOL_NAME,
94
101
  description: "Search the web for current information, news, documentation, or real-time facts.",
95
102
  input_schema: WEB_SEARCH_FUNCTION_PARAMETERS
96
103
  });
97
104
 
98
- const OPENAI_READ_WEB_PAGE_TOOL = Object.freeze({
105
+ const OPENAI_CHAT_READ_WEB_PAGE_TOOL = Object.freeze({
99
106
  type: "function",
100
107
  function: {
101
108
  name: READ_WEB_PAGE_TOOL_NAME,
@@ -104,6 +111,13 @@ const OPENAI_READ_WEB_PAGE_TOOL = Object.freeze({
104
111
  }
105
112
  });
106
113
 
114
+ const OPENAI_RESPONSES_READ_WEB_PAGE_TOOL = Object.freeze({
115
+ type: "function",
116
+ name: READ_WEB_PAGE_TOOL_NAME,
117
+ description: "Fetch and extract the readable text and table content from a web page URL.",
118
+ parameters: READ_WEB_PAGE_FUNCTION_PARAMETERS
119
+ });
120
+
107
121
  const CLAUDE_READ_WEB_PAGE_TOOL = Object.freeze({
108
122
  name: READ_WEB_PAGE_TOOL_NAME,
109
123
  description: "Fetch and extract the readable text and table content from a web page URL.",
@@ -1269,7 +1283,20 @@ export function shouldInterceptAmpWebSearch({ clientType, originalBody, runtimeC
1269
1283
  return true;
1270
1284
  }
1271
1285
 
1272
- export function rewriteProviderBodyForAmpWebSearch(providerBody, targetFormat) {
1286
+ function getOpenAIInterceptToolDefinitions(requestKind) {
1287
+ if (requestKind === "responses") {
1288
+ return {
1289
+ webSearch: OPENAI_RESPONSES_WEB_SEARCH_TOOL,
1290
+ readWebPage: OPENAI_RESPONSES_READ_WEB_PAGE_TOOL
1291
+ };
1292
+ }
1293
+ return {
1294
+ webSearch: OPENAI_CHAT_WEB_SEARCH_TOOL,
1295
+ readWebPage: OPENAI_CHAT_READ_WEB_PAGE_TOOL
1296
+ };
1297
+ }
1298
+
1299
+ export function rewriteProviderBodyForAmpWebSearch(providerBody, targetFormat, requestKind = undefined) {
1273
1300
  const tools = Array.isArray(providerBody?.tools) ? providerBody.tools : [];
1274
1301
  if (tools.length === 0) {
1275
1302
  return {
@@ -1301,8 +1328,9 @@ export function rewriteProviderBodyForAmpWebSearch(providerBody, targetFormat) {
1301
1328
  }
1302
1329
 
1303
1330
  if (targetFormat === FORMATS.OPENAI) {
1304
- if (interceptedToolNames.has(SEARCH_TOOL_NAME)) nextTools.push(OPENAI_WEB_SEARCH_TOOL);
1305
- if (interceptedToolNames.has(READ_WEB_PAGE_TOOL_NAME)) nextTools.push(OPENAI_READ_WEB_PAGE_TOOL);
1331
+ const toolDefinitions = getOpenAIInterceptToolDefinitions(requestKind);
1332
+ if (interceptedToolNames.has(SEARCH_TOOL_NAME)) nextTools.push(toolDefinitions.webSearch);
1333
+ if (interceptedToolNames.has(READ_WEB_PAGE_TOOL_NAME)) nextTools.push(toolDefinitions.readWebPage);
1306
1334
  } else if (targetFormat === FORMATS.CLAUDE) {
1307
1335
  if (interceptedToolNames.has(SEARCH_TOOL_NAME)) nextTools.push(CLAUDE_WEB_SEARCH_TOOL);
1308
1336
  if (interceptedToolNames.has(READ_WEB_PAGE_TOOL_NAME)) nextTools.push(CLAUDE_READ_WEB_PAGE_TOOL);
@@ -516,7 +516,7 @@ export async function makeProviderCall({
516
516
  providerBody = declaredOpenAIHostedWebSearchRewrite.providerBody;
517
517
  }
518
518
  if (interceptAmpWebSearch) {
519
- providerBody = rewriteProviderBodyForAmpWebSearch(providerBody, targetFormat).providerBody;
519
+ providerBody = rewriteProviderBodyForAmpWebSearch(providerBody, targetFormat, requestKind).providerBody;
520
520
  }
521
521
  logToolRouting({
522
522
  env,