wtt-connect 0.2.22 → 0.2.24
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 +1 -1
- package/src/adapters/codex.js +44 -0
- package/src/wtt-client.js +1 -0
package/package.json
CHANGED
package/src/adapters/codex.js
CHANGED
|
@@ -98,6 +98,7 @@ export class CodexAdapter {
|
|
|
98
98
|
buildOptions(context = {}) {
|
|
99
99
|
const options = ['--skip-git-repo-check', '--json'];
|
|
100
100
|
options.push(...(this.permissions?.codexArgs() || []));
|
|
101
|
+
options.push(...codexProxyProviderOptions());
|
|
101
102
|
const model = modelForCodex(this.config, context);
|
|
102
103
|
if (model) options.push('--model', model);
|
|
103
104
|
for (const img of context.images || []) options.push('--image', img);
|
|
@@ -223,6 +224,49 @@ function normalizeCodexModel(model) {
|
|
|
223
224
|
return value;
|
|
224
225
|
}
|
|
225
226
|
|
|
227
|
+
function codexProxyProviderOptions() {
|
|
228
|
+
if (isTruthy(process.env.WTT_CONNECT_CODEX_DISABLE_PROXY_PROVIDER)) return [];
|
|
229
|
+
const baseUrl = normalizeOpenAIBaseUrl(process.env.OPENAI_BASE_URL || '');
|
|
230
|
+
const apiKey = String(process.env.OPENAI_API_KEY || '').trim();
|
|
231
|
+
if (!baseUrl || !apiKey || isDefaultOpenAIBaseUrl(baseUrl)) return [];
|
|
232
|
+
|
|
233
|
+
const provider = sanitizeCodexProviderName(process.env.WTT_CONNECT_CODEX_PROVIDER || 'wtt_proxy');
|
|
234
|
+
return [
|
|
235
|
+
'-c', `model_provider=${JSON.stringify(provider)}`,
|
|
236
|
+
'-c', `model_providers.${provider}.name=${JSON.stringify('WTT OpenAI Proxy')}`,
|
|
237
|
+
'-c', `model_providers.${provider}.base_url=${JSON.stringify(baseUrl)}`,
|
|
238
|
+
'-c', `model_providers.${provider}.env_key=${JSON.stringify('OPENAI_API_KEY')}`,
|
|
239
|
+
'-c', `model_providers.${provider}.wire_api=${JSON.stringify('responses')}`,
|
|
240
|
+
'-c', `model_providers.${provider}.supports_websockets=false`,
|
|
241
|
+
'-c', `model_providers.${provider}.requires_openai_auth=false`,
|
|
242
|
+
];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function normalizeOpenAIBaseUrl(value) {
|
|
246
|
+
return String(value || '').trim().replace(/\/+$/, '');
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function isDefaultOpenAIBaseUrl(baseUrl) {
|
|
250
|
+
try {
|
|
251
|
+
const url = new URL(baseUrl);
|
|
252
|
+
const path = url.pathname.replace(/\/+$/, '');
|
|
253
|
+
return url.protocol === 'https:' && url.hostname === 'api.openai.com' && (!path || path === '/v1');
|
|
254
|
+
} catch {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function sanitizeCodexProviderName(value) {
|
|
260
|
+
const safe = String(value || '').trim().replace(/[^A-Za-z0-9_]/g, '_').replace(/^_+|_+$/g, '');
|
|
261
|
+
if (!safe) return 'wtt_proxy';
|
|
262
|
+
if (/^[0-9]/.test(safe)) return `wtt_${safe}`;
|
|
263
|
+
return safe;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function isTruthy(value) {
|
|
267
|
+
return ['1', 'true', 'yes', 'on'].includes(String(value || '').trim().toLowerCase());
|
|
268
|
+
}
|
|
269
|
+
|
|
226
270
|
function shouldRetryFreshThread(err) {
|
|
227
271
|
const message = String(err?.message || err || '').toLowerCase();
|
|
228
272
|
return [
|
package/src/wtt-client.js
CHANGED
|
@@ -183,6 +183,7 @@ export class WTTClient {
|
|
|
183
183
|
...(options.statusText ? { status_text: options.statusText } : {}),
|
|
184
184
|
...(options.statusKind ? { status_kind: options.statusKind } : {}),
|
|
185
185
|
...(options.adapter ? { adapter: options.adapter } : {}),
|
|
186
|
+
...(options.model ? { model: options.model } : {}),
|
|
186
187
|
}, 5000);
|
|
187
188
|
} catch {}
|
|
188
189
|
}
|