@sisu-ai/tool-web-search-openai 1.0.0 → 2.0.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.
Files changed (2) hide show
  1. package/dist/index.js +6 -19
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -31,11 +31,7 @@ export const openAIWebSearch = {
31
31
  };
32
32
  const DEBUG = String(process.env.DEBUG_LLM || '').toLowerCase() === 'true' || process.env.DEBUG_LLM === '1';
33
33
  if (DEBUG) {
34
- try {
35
- // eslint-disable-next-line no-console
36
- console.error('[DEBUG_LLM] request', { url, headers: { Authorization: 'Bearer ***', 'Content-Type': 'application/json', Accept: 'application/json' }, body });
37
- }
38
- catch { }
34
+ console.error('[DEBUG_LLM] request', { url, headers: { Authorization: 'Bearer ***', 'Content-Type': 'application/json', Accept: 'application/json' }, body });
39
35
  }
40
36
  const doRequest = async (modelToUse) => fetch(url, {
41
37
  method: 'POST',
@@ -54,9 +50,8 @@ export const openAIWebSearch = {
54
50
  const j = JSON.parse(raw);
55
51
  details = j.error?.message ?? raw;
56
52
  }
57
- catch { }
53
+ catch { /* ignore JSON parse error */ }
58
54
  if (DEBUG) {
59
- // eslint-disable-next-line no-console
60
55
  console.error('[DEBUG_LLM] response_error', { status: res.status, statusText: res.statusText, body: typeof raw === 'string' ? raw.slice(0, 500) : raw });
61
56
  }
62
57
  // Retry once with a safe default model if we suspect model/tool mismatch
@@ -68,7 +63,7 @@ export const openAIWebSearch = {
68
63
  try {
69
64
  console.error('[DEBUG_LLM] retrying with fallback model', { from: model, to: fallback });
70
65
  }
71
- catch { }
66
+ catch { /* ignore JSON parse error */ }
72
67
  }
73
68
  model = fallback;
74
69
  res = await doRequest(model);
@@ -79,7 +74,7 @@ export const openAIWebSearch = {
79
74
  const j2 = JSON.parse(raw);
80
75
  d2 = j2.error?.message ?? raw;
81
76
  }
82
- catch { }
77
+ catch { /* ignore JSON parse error */ }
83
78
  throw new Error(`OpenAI web search failed: ${res.status} ${res.statusText} — ${String(d2).slice(0, 500)}`);
84
79
  }
85
80
  }
@@ -90,21 +85,13 @@ export const openAIWebSearch = {
90
85
  const ct = res.headers.get('content-type') || '';
91
86
  if (!ct.toLowerCase().includes('application/json')) {
92
87
  if (DEBUG) {
93
- try {
94
- // eslint-disable-next-line no-console
95
- console.error('[DEBUG_LLM] non_json_response', { contentType: ct, snippet: typeof raw === 'string' ? raw.slice(0, 200) : raw });
96
- }
97
- catch { }
88
+ console.error('[DEBUG_LLM] non_json_response', { contentType: ct, snippet: typeof raw === 'string' ? raw.slice(0, 200) : raw });
98
89
  }
99
90
  throw new Error(`OpenAI web search returned non-JSON content (content-type: ${ct}). Check OPENAI_BASE_URL/BASE_URL and API key. Snippet: ${String(raw).slice(0, 200)}`);
100
91
  }
101
92
  const json = raw ? JSON.parse(raw) : {};
102
93
  if (DEBUG) {
103
- try {
104
- // eslint-disable-next-line no-console
105
- console.error('[DEBUG_LLM] response_ok', { keys: Object.keys(json ?? {}), outputType: Array.isArray(json?.output) ? 'array' : typeof json?.output });
106
- }
107
- catch { }
94
+ console.log('[DEBUG_LLM] response_ok', { keys: Object.keys(json ?? {}), outputType: Array.isArray(json?.output) ? 'array' : typeof json?.output });
108
95
  }
109
96
  const results = json.output?.find?.((p) => p.type === 'web_search_results')?.web_search_results
110
97
  ?? json.output?.[0]?.content?.find?.((c) => c.type === 'web_search_results')?.web_search_results;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sisu-ai/tool-web-search-openai",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "zod": "^3.23.8"
15
15
  },
16
16
  "peerDependencies": {
17
- "@sisu-ai/core": "0.3.0"
17
+ "@sisu-ai/core": "1.0.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",