freddie 0.0.111 → 0.0.112
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/agent/acptoapi-bridge.js +17 -5
package/package.json
CHANGED
|
@@ -32,11 +32,23 @@ export async function callLLM({ messages, tools = [], model } = {}) {
|
|
|
32
32
|
const headers = { 'content-type': 'application/json', authorization: 'Bearer none' }
|
|
33
33
|
const cwd = process.cwd()
|
|
34
34
|
if (Array.isArray(tools) && tools.length) headers['x-cwd'] = cwd
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
})
|
|
35
|
+
// Fast-fail timeout + skip loopback when page is on a remote origin
|
|
36
|
+
// (gh-pages → http://localhost:4800 hangs forever under Chrome private-network rules).
|
|
37
|
+
const _u = (() => { try { return new URL(base, (typeof location !== 'undefined' && location.href) || 'http://_/') } catch { return null } })()
|
|
38
|
+
const _isLb = _u && /^(localhost|127\.0\.0\.1|0\.0\.0\.0|::1)$/i.test(_u.hostname)
|
|
39
|
+
const _pageLb = (() => { try { const h = ((typeof location !== 'undefined' && location.hostname) || '').toLowerCase(); return h === 'localhost' || h === '127.0.0.1' || h === '' || h === '::1' } catch { return true } })()
|
|
40
|
+
if (_isLb && !_pageLb) throw new Error(`acptoapi unreachable: page on ${typeof location !== 'undefined' ? location.hostname : '?'} cannot reach loopback ${base}`)
|
|
41
|
+
const _ac = new AbortController()
|
|
42
|
+
const _tid = setTimeout(() => _ac.abort(new Error('acptoapi fetch timeout')), 8000)
|
|
43
|
+
let res
|
|
44
|
+
try {
|
|
45
|
+
res = await fetch(base.replace(/\/$/, '') + '/chat/completions', {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
headers,
|
|
48
|
+
body: JSON.stringify(body),
|
|
49
|
+
signal: _ac.signal,
|
|
50
|
+
})
|
|
51
|
+
} finally { clearTimeout(_tid) }
|
|
40
52
|
if (!res.ok) {
|
|
41
53
|
const text = await res.text()
|
|
42
54
|
throw new Error(`acptoapi ${res.status}: ${text.slice(0, 400)}`)
|