@aragon-agent/core 0.2.93 → 0.2.94

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 (48) hide show
  1. package/dist/engine/accept-steering.js +1 -15
  2. package/dist/engine/agent-loop.js +1 -533
  3. package/dist/engine/agent.js +1 -538
  4. package/dist/engine/compaction.js +1 -268
  5. package/dist/engine/context-manager.js +1 -13
  6. package/dist/engine/message-manager.js +1 -39
  7. package/dist/engine/steering.js +1 -72
  8. package/dist/engine/tool-result-content.js +1 -39
  9. package/dist/engine/watchdog.js +1 -73
  10. package/dist/index.js +1 -99
  11. package/dist/llm/context-window.js +1 -46
  12. package/dist/llm/image-tokens.js +1 -11
  13. package/dist/llm/model-discovery.js +1 -18
  14. package/dist/llm/model-registry.js +1 -370
  15. package/dist/llm/output-limit-recovery.js +1 -263
  16. package/dist/llm/output-limits.js +1 -283
  17. package/dist/llm/provider.js +1 -171
  18. package/dist/llm/providers/anthropic.js +1 -514
  19. package/dist/llm/providers/google.js +1 -464
  20. package/dist/llm/providers/index.js +1 -205
  21. package/dist/llm/providers/openai.js +1 -520
  22. package/dist/llm/providers/tool-result-images.js +1 -52
  23. package/dist/llm/retry.js +1 -948
  24. package/dist/llm/sse-parser.js +1 -103
  25. package/dist/llm/stream-utils.js +1 -118
  26. package/dist/llm/types.js +1 -17
  27. package/dist/sandbox/console-capture.js +1 -56
  28. package/dist/sandbox/http-bridge.js +1 -143
  29. package/dist/sandbox/isolated-vm-sandbox.js +1 -226
  30. package/dist/sandbox/tool-bridge.js +1 -98
  31. package/dist/sandbox/types.js +1 -8
  32. package/dist/skills/constants.js +1 -179
  33. package/dist/skills/disclosure.js +1 -788
  34. package/dist/skills/frontmatter.js +1 -177
  35. package/dist/skills/index.js +1 -18
  36. package/dist/skills/skill-find-tool.js +1 -117
  37. package/dist/skills/skill-registry.js +1 -208
  38. package/dist/skills/skill-tool.js +1 -96
  39. package/dist/skills/tool-policy.js +1 -272
  40. package/dist/skills/types.js +1 -8
  41. package/dist/skills/validate.js +1 -264
  42. package/dist/tools/executor.js +1 -281
  43. package/dist/tools/helpers.js +1 -87
  44. package/dist/tools/registry.js +1 -119
  45. package/dist/tools/types.js +1 -7
  46. package/dist/tools/validator.js +1 -210
  47. package/dist/types.js +1 -7
  48. package/package.json +3 -2
@@ -1,171 +1 @@
1
- /**
2
- * LLM Provider interface, request types, and error classification.
3
- */
4
- /**
5
- * A DELIBERATE MODULE CYCLE, and it is safe for one specific reason:
6
- * `retry.ts` imports `LLMError` from here and uses it only INSIDE a function
7
- * body, while this module uses `parseRetryAfterMs` only inside
8
- * `classifyHttpError`. Neither side touches the other's binding during module
9
- * evaluation, so whichever loads first the other's top level completes cleanly.
10
- *
11
- * A future top-level `LLMError` reference in `retry.ts`, or a top-level
12
- * `parseRetryAfterMs` call here, WOULD hit the TDZ and throw at import time.
13
- * Keep both usages inside functions.
14
- */
15
- import { parseRetryAfterMs } from './retry.js';
16
- import { SseFrameLimitError } from './sse-parser.js';
17
- export class LLMError extends Error {
18
- provider;
19
- errorType;
20
- retryable;
21
- statusCode;
22
- raw;
23
- retryAfterMs;
24
- constructor(message, provider, errorType, retryable, statusCode, raw,
25
- /**
26
- * The wait the SERVER asked for, in ms (llm-api-retry-backoff §4.4).
27
- *
28
- * A 7th OPTIONAL POSITIONAL FIELD, so every existing construction site
29
- * compiles unchanged. Read structurally by `withRetry` — never through
30
- * `instanceof LLMError`, for the reason `isRetryableError` records.
31
- */
32
- retryAfterMs) {
33
- super(message);
34
- this.provider = provider;
35
- this.errorType = errorType;
36
- this.retryable = retryable;
37
- this.statusCode = statusCode;
38
- this.raw = raw;
39
- this.retryAfterMs = retryAfterMs;
40
- this.name = 'LLMError';
41
- }
42
- }
43
- /**
44
- * Classify an HTTP status code into an {@link LLMErrorType} and determine
45
- * whether the request is retryable.
46
- *
47
- * `headers` is OPTIONAL and additive: when supplied, a server-stated
48
- * `Retry-After` (or a provider rate-limit reset header) rides out on
49
- * `LLMError.retryAfterMs`, which is the only channel a retry policy has for
50
- * honouring it. Adapters that cannot reach the headers — Anthropic's IN-STREAM
51
- * `error` event, which arrives after the connection is already open — simply
52
- * omit it and fall back to the plain backoff ladder.
53
- */
54
- export function classifyHttpError(statusCode, body, provider, headers) {
55
- let errorType;
56
- let retryable;
57
- switch (statusCode) {
58
- case 400:
59
- // Check for context overflow indicators
60
- if (/context|token|length/i.test(body)) {
61
- errorType = 'context_overflow';
62
- retryable = false;
63
- }
64
- else {
65
- errorType = 'invalid_request';
66
- retryable = false;
67
- }
68
- break;
69
- case 401:
70
- case 403:
71
- errorType = 'auth_error';
72
- retryable = false;
73
- break;
74
- // A REQUEST TIMEOUT IS TRANSIENT, and it used to fall into `default` ->
75
- // `unknown` / non-retryable. The abort exclusion that makes `timeout` safe to
76
- // retry lives in `isRetryableError` (check 1), not here.
77
- case 408:
78
- errorType = 'timeout';
79
- retryable = true;
80
- break;
81
- case 429:
82
- errorType = 'rate_limit';
83
- retryable = true;
84
- break;
85
- case 529:
86
- errorType = 'overloaded';
87
- retryable = true;
88
- break;
89
- default:
90
- if (statusCode >= 500) {
91
- errorType = 'server_error';
92
- retryable = true;
93
- }
94
- else {
95
- errorType = 'unknown';
96
- retryable = false;
97
- }
98
- }
99
- // Truncate body for the error message to avoid huge payloads
100
- const truncated = body.length > 300 ? body.slice(0, 300) + '...' : body;
101
- const retryAfterMs = parseRetryAfterMs(headers);
102
- return new LLMError(`${provider} API error ${statusCode}: ${truncated}`, provider, errorType, retryable, statusCode, body, retryAfterMs);
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
- }
152
- /**
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.
158
- */
159
- export function wrapFetchError(err, provider) {
160
- if (err instanceof LLMError)
161
- return err;
162
- if (err instanceof SseFrameLimitError) {
163
- return new LLMError('SSE_FRAME_TOO_LARGE', provider, 'unknown', false);
164
- }
165
- const message = err instanceof Error ? err.message : String(err);
166
- if (err instanceof Error && err.name === 'AbortError') {
167
- return new LLMError(`${provider} request aborted: ${message}`, provider, 'timeout', true);
168
- }
169
- const cause = describeFetchCause(err);
170
- return new LLMError(`${provider} network error: ${message}${cause ? ` (${cause})` : ''}`, provider, 'network_error', true, undefined, err);
171
- }
1
+ const _0x4c63fa=_0xc51e;function _0x30fd(){const _0x23f875=['mtv5whPhrgy','y2f1C2u','y29Uy2f0','BMfTzq','otm4AhjtEu5X','BMv0D29YA19LCNjVCG','mJaWntq4mhjStwr5ta','iefqssbLCNjVCIa','mZm1vgnOCNf3','CMf0zv9SAw1PDa','y29UDgv4Df9VDMvYzMXVDW','ig5LDhDVCMSGzxjYB3i6ia','AM9PBG','ndm1otnHrLHhy3O','ChjVDMLKzxi','y29Kzq','ihjLCxvLC3qGywjVCNrLzdOG','BwvZC2fNzq','Aw52ywXPzf9Yzxf1zxn0','mti1odu4n0jNBxjwEa','teXnrxjYB3i','zMLSDgvY','Dw5RBM93BG','zxjYB3juExbL','mJmXmtuWmg1PCwLYEG','yxv0Af9LCNjVCG','mJe3nZziuxv5rLi','DhjPBq','ndC2nKjusKHTBq','C3rHDhvZq29Kzq','CMv0CNLHyMXL','zMLUza','DgvZDa','C2XPy2u','mJC0otHYthzAz0C','qwjVCNrfCNjVCG','C3rYAw5N','CMvWBgfJzq','C2vYDMvYx2vYCM9Y','CMv0CNLbzNrLCK1Z','B2jQzwn0','CMf3','BgvUz3rO','ChvZAa'];_0x30fd=function(){return _0x23f875;};return _0x30fd();}function _0xc51e(_0x4bceef,_0x1511b4){_0x4bceef=_0x4bceef-0x19d;const _0x30fdd6=_0x30fd();let _0xc51e44=_0x30fdd6[_0x4bceef];if(_0xc51e['VNRMJm']===undefined){var _0x1d239b=function(_0x5c0511){const _0x26ae78='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x5796db='',_0x3257b0='';for(let _0x31731e=0x0,_0x492f64,_0x340049,_0x49ee37=0x0;_0x340049=_0x5c0511['charAt'](_0x49ee37++);~_0x340049&&(_0x492f64=_0x31731e%0x4?_0x492f64*0x40+_0x340049:_0x340049,_0x31731e++%0x4)?_0x5796db+=String['fromCharCode'](0xff&_0x492f64>>(-0x2*_0x31731e&0x6)):0x0){_0x340049=_0x26ae78['indexOf'](_0x340049);}for(let _0x42aee5=0x0,_0x597355=_0x5796db['length'];_0x42aee5<_0x597355;_0x42aee5++){_0x3257b0+='%'+('00'+_0x5796db['charCodeAt'](_0x42aee5)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x3257b0);};_0xc51e['sfVKUz']=_0x1d239b,_0xc51e['pwwvHP']={},_0xc51e['VNRMJm']=!![];}const _0x27a7f3=_0x30fdd6[0x0];_0xc51e['deAANR']!==_0x27a7f3&&(_0xc51e['pwwvHP']={},_0xc51e['deAANR']=_0x27a7f3);const _0x340059=_0xc51e['pwwvHP'][_0x4bceef];return _0x340059===undefined?(_0xc51e44=_0xc51e['sfVKUz'](_0xc51e44),_0xc51e['pwwvHP'][_0x4bceef]=_0xc51e44):_0xc51e44=_0x340059,_0xc51e44;}(function(_0x40c731,_0x16dc75){const _0x1dce4f=_0xc51e,_0x17cc0c=_0x40c731();while(!![]){try{const _0x55f030=parseInt(_0x1dce4f(0x1c7))/0x1+-parseInt(_0x1dce4f(0x1aa))/0x2*(-parseInt(_0x1dce4f(0x1ba))/0x3)+parseInt(_0x1dce4f(0x1c0))/0x4+-parseInt(_0x1dce4f(0x1c2))/0x5*(parseInt(_0x1dce4f(0x1b0))/0x6)+parseInt(_0x1dce4f(0x1be))/0x7*(-parseInt(_0x1dce4f(0x1a8))/0x8)+parseInt(_0x1dce4f(0x1a1))/0x9+parseInt(_0x1dce4f(0x1a6))/0xa;if(_0x55f030===_0x16dc75)break;else _0x17cc0c['push'](_0x17cc0c['shift']());}catch(_0x4b25dc){_0x17cc0c['push'](_0x17cc0c['shift']());}}}(_0x30fd,0x3e83e));import{parseRetryAfterMs}from'./retry.js';import{SseFrameLimitError}from'./sse-parser.js';export class LLMError extends Error{[_0x4c63fa(0x1c8)];[_0x4c63fa(0x1a5)];['retryable'];[_0x4c63fa(0x1ab)];[_0x4c63fa(0x1b7)];[_0x4c63fa(0x1b5)];constructor(_0x3257b0,_0x31731e,_0x492f64,_0x340049,_0x49ee37,_0x42aee5,_0x597355){const _0x2a0895=_0x4c63fa;super(_0x3257b0),this[_0x2a0895(0x1c8)]=_0x31731e,this['errorType']=_0x492f64,this[_0x2a0895(0x1ac)]=_0x340049,this['statusCode']=_0x49ee37,this[_0x2a0895(0x1b7)]=_0x42aee5,this[_0x2a0895(0x1b5)]=_0x597355,this[_0x2a0895(0x1bd)]=_0x2a0895(0x1a2);}}export function classifyHttpError(_0x1436dc,_0x3f410a,_0x18a5ae,_0x7dedcb){const _0x4586c2=_0x4c63fa;let _0x9b0da5,_0x516293;switch(_0x1436dc){case 0x190:/context|token|length/i[_0x4586c2(0x1ae)](_0x3f410a)?(_0x9b0da5=_0x4586c2(0x1c4),_0x516293=![]):(_0x9b0da5=_0x4586c2(0x1a0),_0x516293=![]);break;case 0x191:case 0x193:_0x9b0da5=_0x4586c2(0x1a7),_0x516293=![];break;case 0x198:_0x9b0da5='timeout',_0x516293=!![];break;case 0x1ad:_0x9b0da5=_0x4586c2(0x1c3),_0x516293=!![];break;case 0x211:_0x9b0da5='overloaded',_0x516293=!![];break;default:_0x1436dc>=0x1f4?(_0x9b0da5=_0x4586c2(0x1b4),_0x516293=!![]):(_0x9b0da5=_0x4586c2(0x1a4),_0x516293=![]);}const _0xa5189e=_0x3f410a[_0x4586c2(0x1b8)]>0x12c?_0x3f410a[_0x4586c2(0x1af)](0x0,0x12c)+'...':_0x3f410a,_0x2bffbc=parseRetryAfterMs(_0x7dedcb);return new LLMError(''[_0x4586c2(0x1bc)](_0x18a5ae,_0x4586c2(0x1c1))['concat'](_0x1436dc,':\x20')[_0x4586c2(0x1bc)](_0xa5189e),_0x18a5ae,_0x9b0da5,_0x516293,_0x1436dc,_0x3f410a,_0x2bffbc);}const FETCH_CAUSE_MESSAGE_MAX_CHARS=0x78,FETCH_CAUSE_MAX_DEPTH=0x3;function codeOf(_0x2abf09){const _0x4568bc=_0x4c63fa,_0x506f35=_0x2abf09?.[_0x4568bc(0x19d)];return typeof _0x506f35===_0x4568bc(0x1b2)&&_0x506f35[_0x4568bc(0x1b8)]>0x0?_0x506f35:undefined;}function describeFetchCause(_0x1b3ca4){const _0x34f973=_0x4c63fa,_0x473a8c=[];let _0x1a2251=_0x1b3ca4?.[_0x34f973(0x1bb)];for(let _0x41043c=0x0;_0x41043c<FETCH_CAUSE_MAX_DEPTH&&_0x1a2251!=null;_0x41043c+=0x1){_0x473a8c[_0x34f973(0x1b9)](_0x1a2251);const _0x128563=_0x1a2251['errors'];if(Array['isArray'](_0x128563)&&_0x128563['length']>0x0)_0x473a8c[_0x34f973(0x1b9)](_0x128563[0x0]);_0x1a2251=_0x1a2251[_0x34f973(0x1bb)];}const _0x45f970=_0x473a8c[_0x34f973(0x1ad)](_0x5900f3=>codeOf(_0x5900f3)!==undefined)??_0x473a8c[0x0];if(_0x45f970===undefined)return undefined;const _0x504009=codeOf(_0x45f970)??(typeof _0x45f970===_0x34f973(0x1b6)&&typeof _0x45f970[_0x34f973(0x1bd)]===_0x34f973(0x1b2)?_0x45f970[_0x34f973(0x1bd)]:undefined),_0x1cc16e=typeof _0x45f970===_0x34f973(0x1b6)?_0x45f970[_0x34f973(0x19f)]:_0x45f970;let _0x3cf1a8=typeof _0x1cc16e===_0x34f973(0x1b2)?_0x1cc16e[_0x34f973(0x1b3)](/\s+/g,'\x20')[_0x34f973(0x1a9)]():'';_0x3cf1a8[_0x34f973(0x1b8)]>FETCH_CAUSE_MESSAGE_MAX_CHARS&&(_0x3cf1a8=_0x3cf1a8['slice'](0x0,FETCH_CAUSE_MESSAGE_MAX_CHARS)+'...');const _0x2a0974=[_0x504009,_0x3cf1a8&&_0x3cf1a8!==_0x504009?_0x3cf1a8:undefined][_0x34f973(0x1a3)](_0x1fbd20=>!!_0x1fbd20);return _0x2a0974[_0x34f973(0x1b8)]>0x0?_0x2a0974[_0x34f973(0x1c6)](':\x20'):undefined;}export function wrapFetchError(_0x307c12,_0x41da83){const _0x1387ca=_0x4c63fa;if(_0x307c12 instanceof LLMError)return _0x307c12;if(_0x307c12 instanceof SseFrameLimitError)return new LLMError('SSE_FRAME_TOO_LARGE',_0x41da83,_0x1387ca(0x1a4),![]);const _0x27105b=_0x307c12 instanceof Error?_0x307c12[_0x1387ca(0x19f)]:String(_0x307c12);if(_0x307c12 instanceof Error&&_0x307c12[_0x1387ca(0x1bd)]===_0x1387ca(0x1b1))return new LLMError(''[_0x1387ca(0x1bc)](_0x41da83,_0x1387ca(0x19e))['concat'](_0x27105b),_0x41da83,'timeout',!![]);const _0x394352=describeFetchCause(_0x307c12);return new LLMError(''[_0x1387ca(0x1bc)](_0x41da83,_0x1387ca(0x1c5))[_0x1387ca(0x1bc)](_0x27105b)['concat'](_0x394352?'\x20('['concat'](_0x394352,')'):''),_0x41da83,_0x1387ca(0x1bf),!![],undefined,_0x307c12);}