@aragon-agent/core 0.2.65 → 0.2.66
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/dist/llm/provider.d.ts +4 -0
- package/dist/llm/provider.js +54 -1
- package/package.json +1 -1
package/dist/llm/provider.d.ts
CHANGED
|
@@ -112,5 +112,9 @@ export declare class LLMError extends Error {
|
|
|
112
112
|
export declare function classifyHttpError(statusCode: number, body: string, provider: string, headers?: Headers): LLMError;
|
|
113
113
|
/**
|
|
114
114
|
* Wrap a network-level fetch error (DNS, TLS, abort, etc.) into an LLMError.
|
|
115
|
+
*
|
|
116
|
+
* The message keeps the historic `<provider> network error: <message>` prefix and
|
|
117
|
+
* appends the cause in parentheses when there is one, so a string match on the
|
|
118
|
+
* prefix still works and `raw` is still the original error.
|
|
115
119
|
*/
|
|
116
120
|
export declare function wrapFetchError(err: unknown, provider: string): LLMError;
|
package/dist/llm/provider.js
CHANGED
|
@@ -101,8 +101,60 @@ export function classifyHttpError(statusCode, body, provider, headers) {
|
|
|
101
101
|
const retryAfterMs = parseRetryAfterMs(headers);
|
|
102
102
|
return new LLMError(`${provider} API error ${statusCode}: ${truncated}`, provider, errorType, retryable, statusCode, body, retryAfterMs);
|
|
103
103
|
}
|
|
104
|
+
/** Longest cause message copied into a network-error message. */
|
|
105
|
+
const FETCH_CAUSE_MESSAGE_MAX_CHARS = 120;
|
|
106
|
+
/** How many `cause` links the summary follows before giving up. */
|
|
107
|
+
const FETCH_CAUSE_MAX_DEPTH = 3;
|
|
108
|
+
function codeOf(node) {
|
|
109
|
+
const code = node?.code;
|
|
110
|
+
return typeof code === 'string' && code.length > 0 ? code : undefined;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The real reason behind undici's `TypeError: fetch failed`, as one short clause.
|
|
114
|
+
*
|
|
115
|
+
* THE MESSAGE IS ALWAYS "fetch failed" and the reason lives in `err.cause`
|
|
116
|
+
* (`UND_ERR_SOCKET`, `UND_ERR_CONNECT_TIMEOUT`, `ECONNREFUSED`, a TLS code ...).
|
|
117
|
+
* `raw` already carried it, but nothing downstream reads `raw`, so the card and the
|
|
118
|
+
* log said the same four words for every cause and a report could not be told apart
|
|
119
|
+
* from any other (compaction-network-error-fetch-failed RC-1).
|
|
120
|
+
*
|
|
121
|
+
* Walks at most {@link FETCH_CAUSE_MAX_DEPTH} links and, for an `AggregateError`
|
|
122
|
+
* (Node's happy-eyeballs wrapper), also its first member. The first node with a string
|
|
123
|
+
* `code` names the cause; without one the first cause's `name` does. `undefined` when
|
|
124
|
+
* there is no cause, so the message stays byte-identical to what it was.
|
|
125
|
+
*/
|
|
126
|
+
function describeFetchCause(err) {
|
|
127
|
+
const chain = [];
|
|
128
|
+
let link = err?.cause;
|
|
129
|
+
for (let depth = 0; depth < FETCH_CAUSE_MAX_DEPTH && link != null; depth += 1) {
|
|
130
|
+
chain.push(link);
|
|
131
|
+
const members = link.errors;
|
|
132
|
+
if (Array.isArray(members) && members.length > 0)
|
|
133
|
+
chain.push(members[0]);
|
|
134
|
+
link = link.cause;
|
|
135
|
+
}
|
|
136
|
+
const named = chain.find((node) => codeOf(node) !== undefined) ?? chain[0];
|
|
137
|
+
if (named === undefined)
|
|
138
|
+
return undefined;
|
|
139
|
+
const label = codeOf(named) ??
|
|
140
|
+
(typeof named === 'object' && typeof named.name === 'string'
|
|
141
|
+
? named.name : undefined);
|
|
142
|
+
const raw = typeof named === 'object'
|
|
143
|
+
? named.message : named;
|
|
144
|
+
let detail = typeof raw === 'string' ? raw.replace(/\s+/g, ' ').trim() : '';
|
|
145
|
+
if (detail.length > FETCH_CAUSE_MESSAGE_MAX_CHARS) {
|
|
146
|
+
detail = detail.slice(0, FETCH_CAUSE_MESSAGE_MAX_CHARS) + '...';
|
|
147
|
+
}
|
|
148
|
+
const parts = [label, detail && detail !== label ? detail : undefined]
|
|
149
|
+
.filter((part) => !!part);
|
|
150
|
+
return parts.length > 0 ? parts.join(': ') : undefined;
|
|
151
|
+
}
|
|
104
152
|
/**
|
|
105
153
|
* Wrap a network-level fetch error (DNS, TLS, abort, etc.) into an LLMError.
|
|
154
|
+
*
|
|
155
|
+
* The message keeps the historic `<provider> network error: <message>` prefix and
|
|
156
|
+
* appends the cause in parentheses when there is one, so a string match on the
|
|
157
|
+
* prefix still works and `raw` is still the original error.
|
|
106
158
|
*/
|
|
107
159
|
export function wrapFetchError(err, provider) {
|
|
108
160
|
if (err instanceof LLMError)
|
|
@@ -114,5 +166,6 @@ export function wrapFetchError(err, provider) {
|
|
|
114
166
|
if (err instanceof Error && err.name === 'AbortError') {
|
|
115
167
|
return new LLMError(`${provider} request aborted: ${message}`, provider, 'timeout', true);
|
|
116
168
|
}
|
|
117
|
-
|
|
169
|
+
const cause = describeFetchCause(err);
|
|
170
|
+
return new LLMError(`${provider} network error: ${message}${cause ? ` (${cause})` : ''}`, provider, 'network_error', true, undefined, err);
|
|
118
171
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aragon-agent/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.66",
|
|
4
4
|
"description": "AragonAgent core engine — LLM provider adapters, streaming, tool registry/execution, steering, idle watchdog, and an optional isolated-vm sandbox.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "AragonAgent contributors",
|