web_fetch updates
This commit is contained in:
+40
-4
@@ -1665,6 +1665,43 @@ async function bareAgentCompleteOnce(opts) {
|
||||
|
||||
/** HTTP fetch + HTML extract helpers for agent `web_fetch` tool (preamble for /bin/agent). */
|
||||
|
||||
/**
|
||||
* @param {unknown} e
|
||||
* @returns {string}
|
||||
*/
|
||||
function bareWebFmtErr(e) {
|
||||
if (e == null) return '(null)'
|
||||
if (typeof e === 'string') return e
|
||||
if (typeof e !== 'object') return String(e)
|
||||
const o = /** @type {Record<string, unknown>} */ (e)
|
||||
const msg = o.message
|
||||
if (typeof msg === 'string' && msg.trim()) return msg
|
||||
if (typeof msg === 'number' || typeof msg === 'boolean') return String(msg)
|
||||
const nm = o.name
|
||||
const code = o.code
|
||||
/** @type {string[]} */
|
||||
const bits = []
|
||||
if (typeof nm === 'string' && nm.trim()) bits.push(nm)
|
||||
if (code !== undefined && code !== null && String(code) !== '')
|
||||
bits.push('code=' + String(code))
|
||||
if (bits.length) return bits.join(' ')
|
||||
try {
|
||||
const j = JSON.stringify(o)
|
||||
if (j && j !== '{}' && j !== '[]') return j.slice(0, 400)
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
try {
|
||||
if (typeof (/** @type {{ toString?: () => string }} */ (o)).toString === 'function') {
|
||||
const t = /** @type {{ toString: () => string }} */ (o).toString()
|
||||
if (t && t !== '[object Object]') return t.slice(0, 400)
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
return 'unknown_error'
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Record<string, unknown>} ctx
|
||||
* @returns {typeof fetch | null}
|
||||
@@ -2075,7 +2112,7 @@ async function bareWebRunTool(o) {
|
||||
res = await fetchFn(currentUrl, init)
|
||||
} catch (e) {
|
||||
clearTimeout(timer)
|
||||
const msg = e && typeof e === 'object' && 'message' in e ? String(e.message) : String(e)
|
||||
const msg = bareWebFmtErr(e)
|
||||
return {
|
||||
ok: false,
|
||||
error: 'web_fetch: request failed: ' + msg.slice(0, 400),
|
||||
@@ -2147,7 +2184,7 @@ async function bareWebRunTool(o) {
|
||||
try {
|
||||
bodyRead = await bareWebReadBodyLimited(res, maxBytes, signal || undefined)
|
||||
} catch (e) {
|
||||
const msg = e && typeof e === 'object' && 'message' in e ? String(e.message) : String(e)
|
||||
const msg = bareWebFmtErr(e)
|
||||
return {
|
||||
ok: false,
|
||||
error: 'web_fetch: read body failed: ' + msg.slice(0, 400),
|
||||
@@ -3438,8 +3475,7 @@ async function bareAgentDispatchTool(o) {
|
||||
})
|
||||
return bareAgentJsonResult(out)
|
||||
} catch (e) {
|
||||
const msg =
|
||||
e && typeof e === 'object' && 'message' in e ? String(e.message) : String(e)
|
||||
const msg = bareWebFmtErr(e)
|
||||
return bareAgentJsonResult({ ok: false, error: msg })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"schema": 2,
|
||||
"profileId": "bare-os-posix-like",
|
||||
"generatedAt": "2026-04-22T04:14:01.274Z",
|
||||
"generatedAt": "2026-04-22T05:30:18.374Z",
|
||||
"note": "Sparse POSIX Issue 7 coverage hints for /bin utilities. Omitted command names are not yet profiled here.",
|
||||
"commandIndex": [
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"atMs": 1776831241273,
|
||||
"atMs": 1776835818373,
|
||||
"commands": [
|
||||
"agent",
|
||||
"arch",
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user