@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.
- package/dist/engine/accept-steering.js +1 -15
- package/dist/engine/agent-loop.js +1 -533
- package/dist/engine/agent.js +1 -538
- package/dist/engine/compaction.js +1 -268
- package/dist/engine/context-manager.js +1 -13
- package/dist/engine/message-manager.js +1 -39
- package/dist/engine/steering.js +1 -72
- package/dist/engine/tool-result-content.js +1 -39
- package/dist/engine/watchdog.js +1 -73
- package/dist/index.js +1 -99
- package/dist/llm/context-window.js +1 -46
- package/dist/llm/image-tokens.js +1 -11
- package/dist/llm/model-discovery.js +1 -18
- package/dist/llm/model-registry.js +1 -370
- package/dist/llm/output-limit-recovery.js +1 -263
- package/dist/llm/output-limits.js +1 -283
- package/dist/llm/provider.js +1 -171
- package/dist/llm/providers/anthropic.js +1 -514
- package/dist/llm/providers/google.js +1 -464
- package/dist/llm/providers/index.js +1 -205
- package/dist/llm/providers/openai.js +1 -520
- package/dist/llm/providers/tool-result-images.js +1 -52
- package/dist/llm/retry.js +1 -948
- package/dist/llm/sse-parser.js +1 -103
- package/dist/llm/stream-utils.js +1 -118
- package/dist/llm/types.js +1 -17
- package/dist/sandbox/console-capture.js +1 -56
- package/dist/sandbox/http-bridge.js +1 -143
- package/dist/sandbox/isolated-vm-sandbox.js +1 -226
- package/dist/sandbox/tool-bridge.js +1 -98
- package/dist/sandbox/types.js +1 -8
- package/dist/skills/constants.js +1 -179
- package/dist/skills/disclosure.js +1 -788
- package/dist/skills/frontmatter.js +1 -177
- package/dist/skills/index.js +1 -18
- package/dist/skills/skill-find-tool.js +1 -117
- package/dist/skills/skill-registry.js +1 -208
- package/dist/skills/skill-tool.js +1 -96
- package/dist/skills/tool-policy.js +1 -272
- package/dist/skills/types.js +1 -8
- package/dist/skills/validate.js +1 -264
- package/dist/tools/executor.js +1 -281
- package/dist/tools/helpers.js +1 -87
- package/dist/tools/registry.js +1 -119
- package/dist/tools/types.js +1 -7
- package/dist/tools/validator.js +1 -210
- package/dist/types.js +1 -7
- package/package.json +3 -2
package/dist/llm/sse-parser.js
CHANGED
|
@@ -1,103 +1 @@
|
|
|
1
|
-
export const SSE_FRAME_LIMIT =
|
|
2
|
-
/** A single SSE frame exceeded its UTF-16 capacity; retrying cannot repair it. */
|
|
3
|
-
export class SseFrameLimitError extends Error {
|
|
4
|
-
constructor() {
|
|
5
|
-
super(`SSE frame exceeds ${SSE_FRAME_LIMIT} UTF-16 code units`);
|
|
6
|
-
this.name = 'SseFrameLimitError';
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
/** Incremental model-stream parser; IDs are local to each event, not reconnect state. */
|
|
10
|
-
export class SseParser {
|
|
11
|
-
line = '';
|
|
12
|
-
dataLines = [];
|
|
13
|
-
event;
|
|
14
|
-
id;
|
|
15
|
-
frameUnits = 0;
|
|
16
|
-
skipNextLf = false;
|
|
17
|
-
atStart = true;
|
|
18
|
-
/** Consume decoded text lazily, throwing SseFrameLimitError on an oversized frame. */
|
|
19
|
-
*push(text) {
|
|
20
|
-
for (let index = 0; index < text.length; index++) {
|
|
21
|
-
const char = text[index];
|
|
22
|
-
if (this.atStart) {
|
|
23
|
-
this.atStart = false;
|
|
24
|
-
if (char === '\uFEFF')
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
if (this.skipNextLf) {
|
|
28
|
-
this.skipNextLf = false;
|
|
29
|
-
if (char === '\n') {
|
|
30
|
-
// A blank CR already dispatched/reset the frame. Its optional LF
|
|
31
|
-
// belongs to that delimiter, never to the next frame's budget.
|
|
32
|
-
if (this.frameUnits > 0)
|
|
33
|
-
this.countUnit();
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
this.countUnit();
|
|
38
|
-
if (char !== '\r' && char !== '\n') {
|
|
39
|
-
this.line += char;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
this.skipNextLf = char === '\r';
|
|
43
|
-
const event = this.finishLine();
|
|
44
|
-
if (event)
|
|
45
|
-
yield event;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/** Preserve the model adapters' complete-last-line compatibility at normal EOF. */
|
|
49
|
-
*finish() {
|
|
50
|
-
if (this.line.length > 0)
|
|
51
|
-
this.finishLine();
|
|
52
|
-
const event = this.dispatch();
|
|
53
|
-
if (event)
|
|
54
|
-
yield event;
|
|
55
|
-
}
|
|
56
|
-
/** Discard uncommitted input without dispatching it, including on cancellation. */
|
|
57
|
-
clear() {
|
|
58
|
-
this.line = '';
|
|
59
|
-
this.dataLines = [];
|
|
60
|
-
this.event = undefined;
|
|
61
|
-
this.id = undefined;
|
|
62
|
-
this.frameUnits = 0;
|
|
63
|
-
}
|
|
64
|
-
countUnit() {
|
|
65
|
-
this.frameUnits++;
|
|
66
|
-
if (this.frameUnits <= SSE_FRAME_LIMIT)
|
|
67
|
-
return;
|
|
68
|
-
this.clear();
|
|
69
|
-
throw new SseFrameLimitError();
|
|
70
|
-
}
|
|
71
|
-
finishLine() {
|
|
72
|
-
const line = this.line;
|
|
73
|
-
this.line = '';
|
|
74
|
-
if (line.length === 0)
|
|
75
|
-
return this.dispatch();
|
|
76
|
-
if (line.startsWith(':'))
|
|
77
|
-
return;
|
|
78
|
-
const colon = line.indexOf(':');
|
|
79
|
-
const field = colon < 0 ? line : line.slice(0, colon);
|
|
80
|
-
let value = colon < 0 ? '' : line.slice(colon + 1);
|
|
81
|
-
if (value.startsWith(' '))
|
|
82
|
-
value = value.slice(1);
|
|
83
|
-
switch (field) {
|
|
84
|
-
case 'data':
|
|
85
|
-
this.dataLines.push(value);
|
|
86
|
-
break;
|
|
87
|
-
case 'event':
|
|
88
|
-
this.event = value;
|
|
89
|
-
break;
|
|
90
|
-
case 'id':
|
|
91
|
-
if (!value.includes('\0'))
|
|
92
|
-
this.id = value;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
dispatch() {
|
|
97
|
-
const event = this.dataLines.length > 0 || this.event !== undefined
|
|
98
|
-
? { event: this.event, data: this.dataLines.join('\n'), id: this.id }
|
|
99
|
-
: undefined;
|
|
100
|
-
this.clear();
|
|
101
|
-
return event;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
1
|
+
const _0x29b4a6=_0x52bc;function _0x47cb(){const _0xb6b40d=['y29Uy2f0','zNjHBwvvBML0CW','C3rHCNrZv2L0Aa','ifvurI0XnIbJB2rLihvUAxrZ','AM9PBG','nJuZmJq1q1zdEffe','m2nhAvPIsW','nJeWmJLmrKnZwwu','Aw5JBhvKzxm','yxrtDgfYDa','zgLZCgf0y2G','BgvUz3rO','u1nfigzYyw1Ligv4y2vLzhmG','mNnPyLzMDW','zgf0yq','mteWnZmWmJL4rxz2rvO','mJrSzfr1wNe','ndmWnJG1ntjSyuThwMW','ChvZAa','nZK0ntKZzLruru9M','oe5NtvP6BW','Aw5KzxHpzG','zMLUAxnOtgLUzq','zxzLBNq','y291BNrvBML0','C2TPCe5LEhrmzG','mteZnJC4nKXbwuTlAW','zgf0yuXPBMvZ','C2XPy2u','y2XLyxi','ndaWBu12ue9L','BgLUzq','nJm5otKZmK9mwKjZDa'];_0x47cb=function(){return _0xb6b40d;};return _0x47cb();}(function(_0x3a04ed,_0x52d474){const _0x391fb4=_0x52bc,_0x2c02ea=_0x3a04ed();while(!![]){try{const _0x2c0cea=parseInt(_0x391fb4(0x15d))/0x1*(-parseInt(_0x391fb4(0x178))/0x2)+-parseInt(_0x391fb4(0x171))/0x3*(parseInt(_0x391fb4(0x16a))/0x4)+parseInt(_0x391fb4(0x170))/0x5*(parseInt(_0x391fb4(0x17b))/0x6)+-parseInt(_0x391fb4(0x164))/0x7*(parseInt(_0x391fb4(0x15e))/0x8)+-parseInt(_0x391fb4(0x172))/0x9*(-parseInt(_0x391fb4(0x168))/0xa)+-parseInt(_0x391fb4(0x17a))/0xb+parseInt(_0x391fb4(0x17c))/0xc;if(_0x2c0cea===_0x52d474)break;else _0x2c02ea['push'](_0x2c02ea['shift']());}catch(_0x2ca6e0){_0x2c02ea['push'](_0x2c02ea['shift']());}}}(_0x47cb,0xc8045));export const SSE_FRAME_LIMIT=0x100000;export class SseFrameLimitError extends Error{constructor(){const _0x28c73b=_0x52bc;super(_0x28c73b(0x177)[_0x28c73b(0x16b)](SSE_FRAME_LIMIT,_0x28c73b(0x16e))),this['name']='SseFrameLimitError';}}function _0x52bc(_0x5316f7,_0x15553d){_0x5316f7=_0x5316f7-0x15d;const _0x47cb32=_0x47cb();let _0x52bcd6=_0x47cb32[_0x5316f7];if(_0x52bc['NgwlkH']===undefined){var _0xcad316=function(_0x14b5cc){const _0xf5304='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0xf2879f='',_0x47b04e='';for(let _0x26a8b1=0x0,_0x367441,_0x286689,_0xdc2399=0x0;_0x286689=_0x14b5cc['charAt'](_0xdc2399++);~_0x286689&&(_0x367441=_0x26a8b1%0x4?_0x367441*0x40+_0x286689:_0x286689,_0x26a8b1++%0x4)?_0xf2879f+=String['fromCharCode'](0xff&_0x367441>>(-0x2*_0x26a8b1&0x6)):0x0){_0x286689=_0xf5304['indexOf'](_0x286689);}for(let _0x5e896e=0x0,_0x4eb1ca=_0xf2879f['length'];_0x5e896e<_0x4eb1ca;_0x5e896e++){_0x47b04e+='%'+('00'+_0xf2879f['charCodeAt'](_0x5e896e)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x47b04e);};_0x52bc['OvXYoR']=_0xcad316,_0x52bc['DteqzX']={},_0x52bc['NgwlkH']=!![];}const _0x3527c9=_0x47cb32[0x0];_0x52bc['RHbMhu']!==_0x3527c9&&(_0x52bc['DteqzX']={},_0x52bc['RHbMhu']=_0x3527c9);const _0x12d0d1=_0x52bc['DteqzX'][_0x5316f7];return _0x12d0d1===undefined?(_0x52bcd6=_0x52bc['OvXYoR'](_0x52bcd6),_0x52bc['DteqzX'][_0x5316f7]=_0x52bcd6):_0x52bcd6=_0x12d0d1,_0x52bcd6;}export class SseParser{['line']='';[_0x29b4a6(0x165)]=[];['event'];['id'];['frameUnits']=0x0;[_0x29b4a6(0x163)]=![];[_0x29b4a6(0x174)]=!![];*[_0x29b4a6(0x17d)](_0x47b04e){const _0x4ae4e0=_0x29b4a6;for(let _0x26a8b1=0x0;_0x26a8b1<_0x47b04e[_0x4ae4e0(0x176)];_0x26a8b1++){const _0x367441=_0x47b04e[_0x26a8b1];if(this[_0x4ae4e0(0x174)]){this[_0x4ae4e0(0x174)]=![];if(_0x367441==='\uFEFF')continue;}if(this[_0x4ae4e0(0x163)]){this[_0x4ae4e0(0x163)]=![];if(_0x367441==='\x0a'){if(this[_0x4ae4e0(0x16c)]>0x0)this['countUnit']();continue;}}this[_0x4ae4e0(0x162)]();if(_0x367441!=='\x0d'&&_0x367441!=='\x0a'){this[_0x4ae4e0(0x169)]+=_0x367441;continue;}this[_0x4ae4e0(0x163)]=_0x367441==='\x0d';const _0x286689=this[_0x4ae4e0(0x160)]();if(_0x286689)yield _0x286689;}}*['finish'](){const _0x29a814=_0x29b4a6;if(this[_0x29a814(0x169)][_0x29a814(0x176)]>0x0)this['finishLine']();const _0xdc2399=this[_0x29a814(0x175)]();if(_0xdc2399)yield _0xdc2399;}['clear'](){const _0xb8fb79=_0x29b4a6;this['line']='',this[_0xb8fb79(0x165)]=[],this[_0xb8fb79(0x161)]=undefined,this['id']=undefined,this[_0xb8fb79(0x16c)]=0x0;}['countUnit'](){const _0xb17449=_0x29b4a6;this['frameUnits']++;if(this['frameUnits']<=SSE_FRAME_LIMIT)return;this[_0xb17449(0x167)]();throw new SseFrameLimitError();}[_0x29b4a6(0x160)](){const _0x11e8c9=_0x29b4a6,_0x5e896e=this[_0x11e8c9(0x169)];this[_0x11e8c9(0x169)]='';if(_0x5e896e['length']===0x0)return this[_0x11e8c9(0x175)]();if(_0x5e896e[_0x11e8c9(0x16d)](':'))return;const _0x4eb1ca=_0x5e896e[_0x11e8c9(0x15f)](':'),_0x13a000=_0x4eb1ca<0x0?_0x5e896e:_0x5e896e[_0x11e8c9(0x166)](0x0,_0x4eb1ca);let _0x181b4c=_0x4eb1ca<0x0?'':_0x5e896e[_0x11e8c9(0x166)](_0x4eb1ca+0x1);if(_0x181b4c[_0x11e8c9(0x16d)]('\x20'))_0x181b4c=_0x181b4c[_0x11e8c9(0x166)](0x1);switch(_0x13a000){case _0x11e8c9(0x179):this['dataLines']['push'](_0x181b4c);break;case _0x11e8c9(0x161):this['event']=_0x181b4c;break;case'id':if(!_0x181b4c[_0x11e8c9(0x173)]('\x00'))this['id']=_0x181b4c;break;}}[_0x29b4a6(0x175)](){const _0x26a37b=_0x29b4a6,_0x5a88a7=this[_0x26a37b(0x165)][_0x26a37b(0x176)]>0x0||this[_0x26a37b(0x161)]!==undefined?{'event':this[_0x26a37b(0x161)],'data':this['dataLines'][_0x26a37b(0x16f)]('\x0a'),'id':this['id']}:undefined;return this['clear'](),_0x5a88a7;}}
|
package/dist/llm/stream-utils.js
CHANGED
|
@@ -1,118 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* SSE stream parser and convenience helpers for LLM streaming.
|
|
3
|
-
*/
|
|
4
|
-
import { SseParser } from './sse-parser.js';
|
|
5
|
-
// ---------------------------------------------------------------------------
|
|
6
|
-
// Generic SSE parser
|
|
7
|
-
// ---------------------------------------------------------------------------
|
|
8
|
-
/**
|
|
9
|
-
* Parse model SSE frames, retaining the normal EOF compatibility extension.
|
|
10
|
-
* Abort drops pending data; all early exits cancel once without awaiting cleanup.
|
|
11
|
-
* Throws SseFrameLimitError when an individual frame exceeds its capacity.
|
|
12
|
-
*/
|
|
13
|
-
export async function* parseSSEStream(body, signal) {
|
|
14
|
-
if (signal?.aborted)
|
|
15
|
-
return;
|
|
16
|
-
const reader = body.getReader();
|
|
17
|
-
const decoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
18
|
-
const parser = new SseParser();
|
|
19
|
-
let reachedEof = false;
|
|
20
|
-
let cancelled = false;
|
|
21
|
-
const cancelOnce = () => {
|
|
22
|
-
if (cancelled)
|
|
23
|
-
return;
|
|
24
|
-
cancelled = true;
|
|
25
|
-
try {
|
|
26
|
-
// A transport can reject or never settle its cleanup promise.
|
|
27
|
-
void reader.cancel().catch(() => { });
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
// A synchronous transport cleanup failure must not mask the stream result.
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
signal?.addEventListener('abort', cancelOnce, { once: true });
|
|
34
|
-
try {
|
|
35
|
-
if (signal?.aborted) {
|
|
36
|
-
cancelOnce();
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
while (!signal?.aborted) {
|
|
40
|
-
const { done, value } = await reader.read();
|
|
41
|
-
if (signal?.aborted)
|
|
42
|
-
return;
|
|
43
|
-
if (done) {
|
|
44
|
-
reachedEof = true;
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
for (const event of decodeChunk(value, decoder, parser)) {
|
|
48
|
-
if (signal?.aborted)
|
|
49
|
-
return;
|
|
50
|
-
yield event;
|
|
51
|
-
if (signal?.aborted)
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (signal?.aborted)
|
|
56
|
-
return;
|
|
57
|
-
for (const event of parser.push(decoder.decode())) {
|
|
58
|
-
if (signal?.aborted)
|
|
59
|
-
return;
|
|
60
|
-
yield event;
|
|
61
|
-
}
|
|
62
|
-
if (signal?.aborted)
|
|
63
|
-
return;
|
|
64
|
-
for (const event of parser.finish()) {
|
|
65
|
-
if (signal?.aborted)
|
|
66
|
-
return;
|
|
67
|
-
yield event;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
catch (err) {
|
|
71
|
-
cancelOnce();
|
|
72
|
-
if (signal?.aborted)
|
|
73
|
-
return;
|
|
74
|
-
throw err;
|
|
75
|
-
}
|
|
76
|
-
finally {
|
|
77
|
-
signal?.removeEventListener('abort', cancelOnce);
|
|
78
|
-
parser.clear();
|
|
79
|
-
if (!reachedEof)
|
|
80
|
-
cancelOnce();
|
|
81
|
-
reader.releaseLock();
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function* decodeChunk(bytes, decoder, parser) {
|
|
85
|
-
const decodeSliceBytes = 16 * 1024;
|
|
86
|
-
for (let offset = 0; offset < bytes.length; offset += decodeSliceBytes) {
|
|
87
|
-
const slice = bytes.subarray(offset, offset + decodeSliceBytes);
|
|
88
|
-
yield* parser.push(decoder.decode(slice, { stream: true }));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
// ---------------------------------------------------------------------------
|
|
92
|
-
// Convenience: streamLLM / completeLLM
|
|
93
|
-
// ---------------------------------------------------------------------------
|
|
94
|
-
// These are re-exported from providers/index.ts where the ProviderRegistry
|
|
95
|
-
// singleton is available. Declared here as standalone signatures for the
|
|
96
|
-
// module's public API documentation.
|
|
97
|
-
/**
|
|
98
|
-
* Consume a StreamEvent iterator and return the final AssistantMessage.
|
|
99
|
-
*
|
|
100
|
-
* This is the generic "complete" implementation that any provider can use:
|
|
101
|
-
* it iterates the stream, discards incremental deltas, and returns the
|
|
102
|
-
* assembled message from the `done` event.
|
|
103
|
-
*/
|
|
104
|
-
export async function consumeStream(stream) {
|
|
105
|
-
let result;
|
|
106
|
-
for await (const event of stream) {
|
|
107
|
-
if (event.type === 'done') {
|
|
108
|
-
result = event.message;
|
|
109
|
-
}
|
|
110
|
-
else if (event.type === 'error') {
|
|
111
|
-
throw event.error;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (!result) {
|
|
115
|
-
throw new Error('Stream ended without a done event');
|
|
116
|
-
}
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
1
|
+
(function(_0x4c1f3e,_0x3fef89){const _0x983b76=_0x1809,_0x53b4a8=_0x4c1f3e();while(!![]){try{const _0x1c842d=-parseInt(_0x983b76(0x8a))/0x1*(-parseInt(_0x983b76(0x9b))/0x2)+-parseInt(_0x983b76(0x98))/0x3*(-parseInt(_0x983b76(0x8e))/0x4)+parseInt(_0x983b76(0xa3))/0x5*(parseInt(_0x983b76(0x92))/0x6)+-parseInt(_0x983b76(0x9a))/0x7*(parseInt(_0x983b76(0x96))/0x8)+parseInt(_0x983b76(0x88))/0x9*(-parseInt(_0x983b76(0x8d))/0xa)+parseInt(_0x983b76(0x90))/0xb+-parseInt(_0x983b76(0x9f))/0xc*(parseInt(_0x983b76(0xa1))/0xd);if(_0x1c842d===_0x3fef89)break;else _0x53b4a8['push'](_0x53b4a8['shift']());}catch(_0x2c2514){_0x53b4a8['push'](_0x53b4a8['shift']());}}}(_0x2258,0xa9254));function _0x1809(_0x212bff,_0x52837f){_0x212bff=_0x212bff-0x87;const _0x22588b=_0x2258();let _0x1809b3=_0x22588b[_0x212bff];if(_0x1809['wyKBwG']===undefined){var _0x1337d1=function(_0x1602c0){const _0x23df5b='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x5bd553='',_0x150459='';for(let _0x43220e=0x0,_0x58152a,_0x5578bf,_0x256d0a=0x0;_0x5578bf=_0x1602c0['charAt'](_0x256d0a++);~_0x5578bf&&(_0x58152a=_0x43220e%0x4?_0x58152a*0x40+_0x5578bf:_0x5578bf,_0x43220e++%0x4)?_0x5bd553+=String['fromCharCode'](0xff&_0x58152a>>(-0x2*_0x43220e&0x6)):0x0){_0x5578bf=_0x23df5b['indexOf'](_0x5578bf);}for(let _0x2683b5=0x0,_0x31d7b7=_0x5bd553['length'];_0x2683b5<_0x31d7b7;_0x2683b5++){_0x150459+='%'+('00'+_0x5bd553['charCodeAt'](_0x2683b5)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x150459);};_0x1809['fLqaPr']=_0x1337d1,_0x1809['NyHHKU']={},_0x1809['wyKBwG']=!![];}const _0x28e450=_0x22588b[0x0];_0x1809['Pzcflr']!==_0x28e450&&(_0x1809['NyHHKU']={},_0x1809['Pzcflr']=_0x28e450);const _0x21e63b=_0x1809['NyHHKU'][_0x212bff];return _0x21e63b===undefined?(_0x1809b3=_0x1809['fLqaPr'](_0x1809b3),_0x1809['NyHHKU'][_0x212bff]=_0x1809b3):_0x1809b3=_0x21e63b,_0x1809b3;}import{SseParser}from'./sse-parser.js';function _0x2258(){const _0x2044c9=['ndC2odi5mvfWv3HmsW','y2f0y2G','mtu0odG1ognyA3Hlqq','ywjVCNrLza','CMvTB3zLrxzLBNrmAxn0zw5LCG','zxjYB3i','mtaXmZG3mKjwBfjSwG','u3rYzwfTigvUzgvKihDPDgHVDxqGysbKB25Ligv2zw50','mZG4mJa5r1HfrNfR','DhLWzq','mtrewNDKwLG','mKXQrK55Dq','y2fUy2vS','z2v0uMvHzgvY','DxrMltG','nZe2nhrPDeXwsG','ChvZAa','mtG3ndz3DhLSEfG','zgvJB2rL','nuDorLfJva','CMvSzwfZzuXVy2S','mtqWndm2vvDmDhbn','ywrKrxzLBNrmAxn0zw5LCG','mtm2nZa5m1LNufHbAG','BgvUz3rO','zMLUAxnO','ndeWqxn1qLb4','mtjqCwHWBg0','BwvZC2fNzq'];_0x2258=function(){return _0x2044c9;};return _0x2258();}export async function*parseSSEStream(_0x150459,_0x43220e){const _0x3c62ca=_0x1809;if(_0x43220e?.[_0x3c62ca(0x93)])return;const _0x58152a=_0x150459[_0x3c62ca(0x9d)](),_0x5578bf=new TextDecoder(_0x3c62ca(0x9e),{'ignoreBOM':!![]}),_0x256d0a=new SseParser();let _0x2683b5=![],_0x31d7b7=![];const _0x422c90=()=>{const _0x45e78f=_0x3c62ca;if(_0x31d7b7)return;_0x31d7b7=!![];try{void _0x58152a[_0x45e78f(0x9c)]()[_0x45e78f(0x91)](()=>{});}catch{}};_0x43220e?.[_0x3c62ca(0x89)]('abort',_0x422c90,{'once':!![]});try{if(_0x43220e?.['aborted']){_0x422c90();return;}while(!_0x43220e?.['aborted']){const {done:_0x5cf405,value:_0x24d7d6}=await _0x58152a['read']();if(_0x43220e?.[_0x3c62ca(0x93)])return;if(_0x5cf405){_0x2683b5=!![];break;}for(const _0x40b137 of decodeChunk(_0x24d7d6,_0x5578bf,_0x256d0a)){if(_0x43220e?.[_0x3c62ca(0x93)])return;yield _0x40b137;if(_0x43220e?.[_0x3c62ca(0x93)])return;}}if(_0x43220e?.['aborted'])return;for(const _0x5c1be7 of _0x256d0a[_0x3c62ca(0xa0)](_0x5578bf[_0x3c62ca(0xa2)]())){if(_0x43220e?.[_0x3c62ca(0x93)])return;yield _0x5c1be7;}if(_0x43220e?.[_0x3c62ca(0x93)])return;for(const _0x51e55a of _0x256d0a[_0x3c62ca(0x8c)]()){if(_0x43220e?.['aborted'])return;yield _0x51e55a;}}catch(_0x583842){_0x422c90();if(_0x43220e?.['aborted'])return;throw _0x583842;}finally{_0x43220e?.[_0x3c62ca(0x94)]('abort',_0x422c90),_0x256d0a['clear']();if(!_0x2683b5)_0x422c90();_0x58152a[_0x3c62ca(0x87)]();}}function*decodeChunk(_0x339221,_0x2eafd3,_0x43cc98){const _0x7d2bbe=_0x1809,_0xddfa5c=0x10*0x400;for(let _0x171b45=0x0;_0x171b45<_0x339221[_0x7d2bbe(0x8b)];_0x171b45+=_0xddfa5c){const _0x2f90ce=_0x339221['subarray'](_0x171b45,_0x171b45+_0xddfa5c);yield*_0x43cc98[_0x7d2bbe(0xa0)](_0x2eafd3[_0x7d2bbe(0xa2)](_0x2f90ce,{'stream':!![]}));}}export async function consumeStream(_0x1c2a41){const _0x4d89d8=_0x1809;let _0x2ec31b;for await(const _0x3beaee of _0x1c2a41){if(_0x3beaee[_0x4d89d8(0x99)]==='done')_0x2ec31b=_0x3beaee[_0x4d89d8(0x8f)];else{if(_0x3beaee['type']===_0x4d89d8(0x95))throw _0x3beaee[_0x4d89d8(0x95)];}}if(!_0x2ec31b)throw new Error(_0x4d89d8(0x97));return _0x2ec31b;}
|
package/dist/llm/types.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Core LLM types — provider-agnostic message, content, and streaming types.
|
|
3
|
-
*
|
|
4
|
-
* These types form the universal contract between the provider adapters and
|
|
5
|
-
* the agent engine. Every provider adapter converts its native wire format
|
|
6
|
-
* into these types so the rest of the system never touches provider-specific
|
|
7
|
-
* structures.
|
|
8
|
-
*/
|
|
9
|
-
/** Map ThinkingLevel to Anthropic budget_tokens values. */
|
|
10
|
-
export const THINKING_BUDGET = {
|
|
11
|
-
off: 0,
|
|
12
|
-
minimal: 1024,
|
|
13
|
-
low: 4096,
|
|
14
|
-
medium: 10240,
|
|
15
|
-
high: 32768,
|
|
16
|
-
xhigh: 65536,
|
|
17
|
-
};
|
|
1
|
+
(function(_0x29d86e,_0x3b89af){const _0x2c7a65=_0x4471,_0x25cf8b=_0x29d86e();while(!![]){try{const _0x567d9c=-parseInt(_0x2c7a65(0x157))/0x1*(parseInt(_0x2c7a65(0x151))/0x2)+-parseInt(_0x2c7a65(0x152))/0x3+parseInt(_0x2c7a65(0x155))/0x4+-parseInt(_0x2c7a65(0x159))/0x5*(-parseInt(_0x2c7a65(0x153))/0x6)+parseInt(_0x2c7a65(0x156))/0x7*(-parseInt(_0x2c7a65(0x150))/0x8)+-parseInt(_0x2c7a65(0x15a))/0x9*(parseInt(_0x2c7a65(0x158))/0xa)+parseInt(_0x2c7a65(0x154))/0xb;if(_0x567d9c===_0x3b89af)break;else _0x25cf8b['push'](_0x25cf8b['shift']());}catch(_0x4fd6cb){_0x25cf8b['push'](_0x25cf8b['shift']());}}}(_0x33b9,0x314d9));function _0x4471(_0x6538e1,_0x585224){_0x6538e1=_0x6538e1-0x150;const _0x33b989=_0x33b9();let _0x447160=_0x33b989[_0x6538e1];if(_0x4471['FtvkuB']===undefined){var _0x859132=function(_0x4d6729){const _0x1a7518='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x381131='',_0xacf9d5='';for(let _0x1c5660=0x0,_0x1d19d0,_0x5eb967,_0x36c779=0x0;_0x5eb967=_0x4d6729['charAt'](_0x36c779++);~_0x5eb967&&(_0x1d19d0=_0x1c5660%0x4?_0x1d19d0*0x40+_0x5eb967:_0x5eb967,_0x1c5660++%0x4)?_0x381131+=String['fromCharCode'](0xff&_0x1d19d0>>(-0x2*_0x1c5660&0x6)):0x0){_0x5eb967=_0x1a7518['indexOf'](_0x5eb967);}for(let _0x1e7f1b=0x0,_0x2ccb4a=_0x381131['length'];_0x1e7f1b<_0x2ccb4a;_0x1e7f1b++){_0xacf9d5+='%'+('00'+_0x381131['charCodeAt'](_0x1e7f1b)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0xacf9d5);};_0x4471['FvKhmT']=_0x859132,_0x4471['pnKDEX']={},_0x4471['FtvkuB']=!![];}const _0x201a4d=_0x33b989[0x0];_0x4471['mQFjyc']!==_0x201a4d&&(_0x4471['pnKDEX']={},_0x4471['mQFjyc']=_0x201a4d);const _0xf9f074=_0x4471['pnKDEX'][_0x6538e1];return _0xf9f074===undefined?(_0x447160=_0x4471['FvKhmT'](_0x447160),_0x4471['pnKDEX'][_0x6538e1]=_0x447160):_0x447160=_0xf9f074,_0x447160;}function _0x33b9(){const _0x4ebd7c=['mteWmZmXyxHtA3f1','mte2nta3mKXqBKn6qG','odu2shD4uhfA','ndCYmZCXqMXZEgD6','mJuZogP3zMDRCW','mJu4ndy3mhPqBK9hBq','mtu5mZC2ognYD3zNrW','n3bJtwXeBa','mZGZCenkEvHI','mJbht09hzxG','nZeWALjRzwLx'];_0x33b9=function(){return _0x4ebd7c;};return _0x33b9();}export const THINKING_BUDGET={'off':0x0,'minimal':0x400,'low':0x1000,'medium':0x2800,'high':0x8000,'xhigh':0x10000};
|
|
@@ -1,56 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* CodeAct Sandbox — Console Capture
|
|
3
|
-
*
|
|
4
|
-
* Captures console.log/warn/error/info calls from inside the isolated-vm
|
|
5
|
-
* sandbox and buffers them on the host side. Uses synchronous ivm.Reference
|
|
6
|
-
* callbacks (applySync) so console calls behave naturally in sandbox code.
|
|
7
|
-
*/
|
|
8
|
-
import ivm from 'isolated-vm';
|
|
9
|
-
/** Maximum number of console entries to buffer before discarding oldest. */
|
|
10
|
-
const MAX_BUFFER_SIZE = 1000;
|
|
11
|
-
/**
|
|
12
|
-
* ConsoleCapture intercepts console method calls inside an isolated-vm
|
|
13
|
-
* Context and stores them as ConsoleEntry records on the host.
|
|
14
|
-
*/
|
|
15
|
-
export class ConsoleCapture {
|
|
16
|
-
entries = [];
|
|
17
|
-
/**
|
|
18
|
-
* Inject console overrides into the given isolated-vm context.
|
|
19
|
-
*
|
|
20
|
-
* Replaces globalThis.console with an object whose log/warn/error/info
|
|
21
|
-
* methods forward arguments (stringified) to the host via a synchronous
|
|
22
|
-
* ivm.Reference callback.
|
|
23
|
-
*/
|
|
24
|
-
async inject(context) {
|
|
25
|
-
const captureRef = new ivm.Reference((level, message) => {
|
|
26
|
-
const entry = {
|
|
27
|
-
level: level,
|
|
28
|
-
args: [message],
|
|
29
|
-
timestamp: Date.now(),
|
|
30
|
-
};
|
|
31
|
-
if (this.entries.length >= MAX_BUFFER_SIZE) {
|
|
32
|
-
// Discard the oldest entry to stay within the buffer limit.
|
|
33
|
-
this.entries.shift();
|
|
34
|
-
}
|
|
35
|
-
this.entries.push(entry);
|
|
36
|
-
});
|
|
37
|
-
await context.evalClosure(`
|
|
38
|
-
const _capture = $0;
|
|
39
|
-
globalThis.console = {
|
|
40
|
-
log: (...args) => _capture.applySync(undefined, ['log', args.map(String).join(' ')]),
|
|
41
|
-
warn: (...args) => _capture.applySync(undefined, ['warn', args.map(String).join(' ')]),
|
|
42
|
-
error: (...args) => _capture.applySync(undefined, ['error', args.map(String).join(' ')]),
|
|
43
|
-
info: (...args) => _capture.applySync(undefined, ['info', args.map(String).join(' ')]),
|
|
44
|
-
};
|
|
45
|
-
`, [captureRef], { arguments: { reference: true } });
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Return all captured console entries and clear the internal buffer.
|
|
49
|
-
* Typically called after each execute() to collect output.
|
|
50
|
-
*/
|
|
51
|
-
drain() {
|
|
52
|
-
const result = this.entries;
|
|
53
|
-
this.entries = [];
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
const _0x5761d9=_0x3d7a;function _0x46df(){const _0x510946=['zhjHAw4','mtuZC1b6B2T3','mJG4v3jgsMHZ','C2HPzNq','nZa0mJq5mgT5BK5KrW','nde0mdKXq1LRwez5','BgvUz3rO','mZe4mJe2meTRvNjnBq','zw50CMLLCW','mtC1mdaWwg5gC0fl','BM93','mJy1ngzeBxPysW','ChvZAa','mJe5mZK2ofrxr2jkqq','Aw5Qzwn0','mJq2mJzVt2rTB0u','nJe4q1frq2Lj','uMvMzxjLBMnL','zxzHBenSB3n1CMu'];_0x46df=function(){return _0x510946;};return _0x46df();}(function(_0x1e7182,_0x1224e7){const _0x4a7092=_0x3d7a,_0x24eb66=_0x1e7182();while(!![]){try{const _0x2913bd=parseInt(_0x4a7092(0x128))/0x1+parseInt(_0x4a7092(0x11b))/0x2*(-parseInt(_0x4a7092(0x120))/0x3)+-parseInt(_0x4a7092(0x11d))/0x4+parseInt(_0x4a7092(0x12a))/0x5+parseInt(_0x4a7092(0x125))/0x6*(-parseInt(_0x4a7092(0x11f))/0x7)+parseInt(_0x4a7092(0x12c))/0x8*(-parseInt(_0x4a7092(0x124))/0x9)+parseInt(_0x4a7092(0x127))/0xa;if(_0x2913bd===_0x1224e7)break;else _0x24eb66['push'](_0x24eb66['shift']());}catch(_0x5542da){_0x24eb66['push'](_0x24eb66['shift']());}}}(_0x46df,0x5fbf3));import _0x121a19 from'isolated-vm';const MAX_BUFFER_SIZE=0x3e8;function _0x3d7a(_0x554afc,_0x4950a5){_0x554afc=_0x554afc-0x11a;const _0x46dfd9=_0x46df();let _0x3d7ad0=_0x46dfd9[_0x554afc];if(_0x3d7a['vqCzcX']===undefined){var _0x59b4e2=function(_0x543187){const _0x3d33d9='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x4cae53='',_0x121a19='';for(let _0x3698b7=0x0,_0x2e3eb5,_0x2117ea,_0x1989f9=0x0;_0x2117ea=_0x543187['charAt'](_0x1989f9++);~_0x2117ea&&(_0x2e3eb5=_0x3698b7%0x4?_0x2e3eb5*0x40+_0x2117ea:_0x2117ea,_0x3698b7++%0x4)?_0x4cae53+=String['fromCharCode'](0xff&_0x2e3eb5>>(-0x2*_0x3698b7&0x6)):0x0){_0x2117ea=_0x3d33d9['indexOf'](_0x2117ea);}for(let _0x51497a=0x0,_0x26799c=_0x4cae53['length'];_0x51497a<_0x26799c;_0x51497a++){_0x121a19+='%'+('00'+_0x4cae53['charCodeAt'](_0x51497a)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x121a19);};_0x3d7a['qeMSpz']=_0x59b4e2,_0x3d7a['ceFanh']={},_0x3d7a['vqCzcX']=!![];}const _0x1577f4=_0x46dfd9[0x0];_0x3d7a['qJAucI']!==_0x1577f4&&(_0x3d7a['ceFanh']={},_0x3d7a['qJAucI']=_0x1577f4);const _0x4f00b2=_0x3d7a['ceFanh'][_0x554afc];return _0x4f00b2===undefined?(_0x3d7ad0=_0x3d7a['qeMSpz'](_0x3d7ad0),_0x3d7a['ceFanh'][_0x554afc]=_0x3d7ad0):_0x3d7ad0=_0x4f00b2,_0x3d7ad0;}export class ConsoleCapture{['entries']=[];async[_0x5761d9(0x11e)](_0x3698b7){const _0x414423=_0x5761d9,_0x2e3eb5=new _0x121a19[(_0x414423(0x121))]((_0x2117ea,_0x1989f9)=>{const _0x11d054=_0x414423,_0x51497a={'level':_0x2117ea,'args':[_0x1989f9],'timestamp':Date[_0x11d054(0x11a)]()};this[_0x11d054(0x12b)][_0x11d054(0x129)]>=MAX_BUFFER_SIZE&&this[_0x11d054(0x12b)][_0x11d054(0x126)](),this[_0x11d054(0x12b)][_0x11d054(0x11c)](_0x51497a);});await _0x3698b7[_0x414423(0x122)]('\x0a\x20\x20\x20\x20\x20\x20const\x20_capture\x20=\x20$0;\x0a\x20\x20\x20\x20\x20\x20globalThis.console\x20=\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20log:\x20\x20\x20(...args)\x20=>\x20_capture.applySync(undefined,\x20[\x27log\x27,\x20\x20\x20args.map(String).join(\x27\x20\x27)]),\x0a\x20\x20\x20\x20\x20\x20\x20\x20warn:\x20\x20(...args)\x20=>\x20_capture.applySync(undefined,\x20[\x27warn\x27,\x20\x20args.map(String).join(\x27\x20\x27)]),\x0a\x20\x20\x20\x20\x20\x20\x20\x20error:\x20(...args)\x20=>\x20_capture.applySync(undefined,\x20[\x27error\x27,\x20args.map(String).join(\x27\x20\x27)]),\x0a\x20\x20\x20\x20\x20\x20\x20\x20info:\x20\x20(...args)\x20=>\x20_capture.applySync(undefined,\x20[\x27info\x27,\x20\x20args.map(String).join(\x27\x20\x27)]),\x0a\x20\x20\x20\x20\x20\x20};\x0a\x20\x20\x20\x20\x20\x20',[_0x2e3eb5],{'arguments':{'reference':!![]}});}[_0x5761d9(0x123)](){const _0x29939f=_0x5761d9,_0x26799c=this[_0x29939f(0x12b)];return this[_0x29939f(0x12b)]=[],_0x26799c;}}
|
|
@@ -1,143 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* CodeAct Sandbox — HTTP Bridge
|
|
3
|
-
*
|
|
4
|
-
* Provides a domain-whitelisted `fetch` function inside the isolated-vm
|
|
5
|
-
* sandbox. All HTTP requests are proxied through the host process using
|
|
6
|
-
* Node.js native fetch, with configurable timeout and response size limits.
|
|
7
|
-
*/
|
|
8
|
-
import ivm from 'isolated-vm';
|
|
9
|
-
/** Default request timeout (10 seconds). */
|
|
10
|
-
const DEFAULT_TIMEOUT = 10_000;
|
|
11
|
-
/** Default maximum response body size (1 MB). */
|
|
12
|
-
const DEFAULT_MAX_RESPONSE_SIZE = 1_048_576;
|
|
13
|
-
/**
|
|
14
|
-
* HttpBridge injects a `globalThis.fetch` function into the sandbox that
|
|
15
|
-
* proxies requests through the host with domain whitelisting.
|
|
16
|
-
*/
|
|
17
|
-
export class HttpBridge {
|
|
18
|
-
allowedHosts;
|
|
19
|
-
timeout;
|
|
20
|
-
maxResponseSize;
|
|
21
|
-
constructor(config) {
|
|
22
|
-
this.allowedHosts = new Set(config.allowedHosts.map((h) => h.toLowerCase()));
|
|
23
|
-
this.timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
24
|
-
this.maxResponseSize = config.maxResponseSize ?? DEFAULT_MAX_RESPONSE_SIZE;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Inject the `fetch` global async function into the given context.
|
|
28
|
-
* Sandbox signature: `async function fetch(url, options?) => { status, statusText, headers, body }`
|
|
29
|
-
*/
|
|
30
|
-
async inject(context) {
|
|
31
|
-
const fetchRef = new ivm.Reference(async (requestJson) => {
|
|
32
|
-
const { url, options } = JSON.parse(requestJson);
|
|
33
|
-
// --- Domain whitelist check ---
|
|
34
|
-
const hostname = this.extractHostname(url);
|
|
35
|
-
if (!this.allowedHosts.has(hostname.toLowerCase())) {
|
|
36
|
-
throw new Error(`HTTP request blocked: hostname "${hostname}" is not in the allowed hosts list`);
|
|
37
|
-
}
|
|
38
|
-
// --- Execute host-side fetch with timeout ---
|
|
39
|
-
const controller = new AbortController();
|
|
40
|
-
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
41
|
-
try {
|
|
42
|
-
const response = await fetch(url, {
|
|
43
|
-
method: options?.method ?? 'GET',
|
|
44
|
-
headers: options?.headers,
|
|
45
|
-
body: options?.body,
|
|
46
|
-
signal: controller.signal,
|
|
47
|
-
// SECURITY: Do not follow redirects automatically.
|
|
48
|
-
// A whitelisted domain could redirect to an internal service (SSRF).
|
|
49
|
-
redirect: 'manual',
|
|
50
|
-
});
|
|
51
|
-
// Read body with size limit enforcement.
|
|
52
|
-
const body = await this.readBodyWithLimit(response);
|
|
53
|
-
// Collect response headers into a plain object.
|
|
54
|
-
const headers = {};
|
|
55
|
-
response.headers.forEach((value, key) => {
|
|
56
|
-
headers[key] = value;
|
|
57
|
-
});
|
|
58
|
-
const result = {
|
|
59
|
-
status: response.status,
|
|
60
|
-
statusText: response.statusText,
|
|
61
|
-
headers,
|
|
62
|
-
body,
|
|
63
|
-
};
|
|
64
|
-
return JSON.stringify(result);
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
if (err instanceof DOMException && err.name === 'AbortError') {
|
|
68
|
-
throw new Error(`HTTP request timed out after ${this.timeout}ms`);
|
|
69
|
-
}
|
|
70
|
-
throw err;
|
|
71
|
-
}
|
|
72
|
-
finally {
|
|
73
|
-
clearTimeout(timer);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
// Register fetch in the sandbox. The sandbox function serializes
|
|
77
|
-
// arguments to JSON, sends to host, and deserializes the response.
|
|
78
|
-
await context.evalClosure(`globalThis.fetch = async function(url, options) {
|
|
79
|
-
const requestJson = JSON.stringify({ url, options });
|
|
80
|
-
const responseJson = await $0.apply(undefined, [requestJson], { result: { promise: true } });
|
|
81
|
-
return JSON.parse(responseJson);
|
|
82
|
-
}`, [fetchRef], { arguments: { reference: true } });
|
|
83
|
-
}
|
|
84
|
-
// ---------------------------------------------------------------------------
|
|
85
|
-
// Private helpers
|
|
86
|
-
// ---------------------------------------------------------------------------
|
|
87
|
-
/** Allowed URL protocols. Blocks file://, data://, etc. */
|
|
88
|
-
static ALLOWED_PROTOCOLS = new Set(['http:', 'https:']);
|
|
89
|
-
/**
|
|
90
|
-
* Extract hostname from a URL string and validate protocol.
|
|
91
|
-
* Throws if the URL is malformed or uses a disallowed protocol.
|
|
92
|
-
*/
|
|
93
|
-
extractHostname(url) {
|
|
94
|
-
let parsed;
|
|
95
|
-
try {
|
|
96
|
-
parsed = new URL(url);
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
throw new Error(`Invalid URL: "${url}"`);
|
|
100
|
-
}
|
|
101
|
-
// SECURITY: Only allow http/https to prevent file://, data://, etc.
|
|
102
|
-
if (!HttpBridge.ALLOWED_PROTOCOLS.has(parsed.protocol)) {
|
|
103
|
-
throw new Error(`Blocked URL protocol "${parsed.protocol}" — only http: and https: are allowed`);
|
|
104
|
-
}
|
|
105
|
-
return parsed.hostname;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Read the response body as text, enforcing the maximum size limit.
|
|
109
|
-
* If the body exceeds the limit, it is truncated and a warning appended.
|
|
110
|
-
*
|
|
111
|
-
* NOTE: We always stream-read to enforce the limit, regardless of
|
|
112
|
-
* Content-Length header (which can be spoofed by the remote server).
|
|
113
|
-
*/
|
|
114
|
-
async readBodyWithLimit(response) {
|
|
115
|
-
// Stream-read with size enforcement.
|
|
116
|
-
const reader = response.body?.getReader();
|
|
117
|
-
if (!reader) {
|
|
118
|
-
return '';
|
|
119
|
-
}
|
|
120
|
-
const decoder = new TextDecoder();
|
|
121
|
-
const chunks = [];
|
|
122
|
-
let totalBytes = 0;
|
|
123
|
-
try {
|
|
124
|
-
while (true) {
|
|
125
|
-
const { done, value } = await reader.read();
|
|
126
|
-
if (done)
|
|
127
|
-
break;
|
|
128
|
-
totalBytes += value.byteLength;
|
|
129
|
-
if (totalBytes > this.maxResponseSize) {
|
|
130
|
-
// Decode what we have so far and truncate.
|
|
131
|
-
chunks.push(decoder.decode(value, { stream: false }));
|
|
132
|
-
chunks.push(`\n\n[Response truncated at ${this.maxResponseSize} bytes]`);
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
chunks.push(decoder.decode(value, { stream: true }));
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
finally {
|
|
139
|
-
reader.releaseLock();
|
|
140
|
-
}
|
|
141
|
-
return chunks.join('');
|
|
142
|
-
}
|
|
143
|
-
}
|
|
1
|
+
function _0x6161(){const _0x417c3f=['yNL0zuXLBMD0Aa','CMvSzwfZzuXVy2S','sfruucbYzxf1zxn0igjSB2nRzwq6igHVC3rUyw1Lici','AgfZ','zxzHBenSB3n1CMu','nJu1ofzOCw9hvW','mtG2mdzTBvbADhC','C3rYAw5NAwz5','zM9YrwfJAa','nda4sKTXAKLX','ywjVCNq','DgLTzw91Da','CgfYC2u','uMvMzxjLBMnL','CMvHza','mtbwqKroEe8','Bwv0Ag9K','mtu4mJu0og5Pqujewq','cGPBuMvZCg9UC2uGDhj1BMnHDgvKigf0ia','Bwf4uMvZCg9UC2vtAxPL','sw52ywXPzcbvuKW6ici','AgvHzgvYCW','mta4otq1meXgDKvrsG','Aw5Qzwn0','nxHjthDlDq','y29Uy2f0','ChvZAa','zxH0CMfJDeHVC3rUyw1L','Ahr0CdO','otyWodi0DhbcEe5j','zgvJB2rL','Dg9mB3DLCKnHC2u','AM9PBG','mtuYnJeYoxHdAK9xyW','Ahr0Chm6','mJzeBhDgtwq','igj5DgvZxq','qwjVCNrfCNjVCG','quXmt1Dfrf9quK9ut0nptfm','n2XIEwrqza','yM9KEq','mtjKqurlvhC','ywXSB3DLzeHVC3rZ','z2v0uMvHzgvY','sfruucbYzxf1zxn0ihrPBwvKig91DcbHzNrLCIa','C3rHDhvZvgv4Da','otCYnZi4owDOv2P1zq','BMfTzq','BwfW','iIbPCYbUB3qGAw4GDgHLigfSBg93zwqGAg9ZDhmGBgLZDa','ChjVDg9JB2W','CMvHzejVzhLxAxrOtgLTAxq'];_0x6161=function(){return _0x417c3f;};return _0x6161();}const _0xd8fac0=_0x3df0;(function(_0x27d0d7,_0x234f4c){const _0x47f759=_0x3df0,_0x2fc92e=_0x27d0d7();while(!![]){try{const _0x5579de=parseInt(_0x47f759(0x1d9))/0x1*(-parseInt(_0x47f759(0x1f0))/0x2)+parseInt(_0x47f759(0x1ef))/0x3*(-parseInt(_0x47f759(0x1f3))/0x4)+-parseInt(_0x47f759(0x202))/0x5*(parseInt(_0x47f759(0x1fb))/0x6)+-parseInt(_0x47f759(0x1dd))/0x7*(-parseInt(_0x47f759(0x207))/0x8)+-parseInt(_0x47f759(0x200))/0x9+-parseInt(_0x47f759(0x1f9))/0xa*(-parseInt(_0x47f759(0x1d7))/0xb)+-parseInt(_0x47f759(0x1df))/0xc*(-parseInt(_0x47f759(0x1e4))/0xd);if(_0x5579de===_0x234f4c)break;else _0x2fc92e['push'](_0x2fc92e['shift']());}catch(_0x1eab20){_0x2fc92e['push'](_0x2fc92e['shift']());}}}(_0x6161,0x266fd));import _0x5c14b6 from'isolated-vm';function _0x3df0(_0x48bfe8,_0x4f6d40){_0x48bfe8=_0x48bfe8-0x1d4;const _0x61612e=_0x6161();let _0x3df086=_0x61612e[_0x48bfe8];if(_0x3df0['YWHOzy']===undefined){var _0x2fce3d=function(_0x5551c){const _0x7d61a9='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x448678='',_0x5c14b6='';for(let _0x1ba873=0x0,_0x15de5e,_0x1aa100,_0x4cd9e4=0x0;_0x1aa100=_0x5551c['charAt'](_0x4cd9e4++);~_0x1aa100&&(_0x15de5e=_0x1ba873%0x4?_0x15de5e*0x40+_0x1aa100:_0x1aa100,_0x1ba873++%0x4)?_0x448678+=String['fromCharCode'](0xff&_0x15de5e>>(-0x2*_0x1ba873&0x6)):0x0){_0x1aa100=_0x7d61a9['indexOf'](_0x1aa100);}for(let _0x4e5097=0x0,_0x54c043=_0x448678['length'];_0x4e5097<_0x54c043;_0x4e5097++){_0x5c14b6+='%'+('00'+_0x448678['charCodeAt'](_0x4e5097)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x5c14b6);};_0x3df0['WRkacH']=_0x2fce3d,_0x3df0['CsjTfl']={},_0x3df0['YWHOzy']=!![];}const _0x342eaa=_0x61612e[0x0];_0x3df0['aDBVIN']!==_0x342eaa&&(_0x3df0['CsjTfl']={},_0x3df0['aDBVIN']=_0x342eaa);const _0x5bd582=_0x3df0['CsjTfl'][_0x48bfe8];return _0x5bd582===undefined?(_0x3df086=_0x3df0['WRkacH'](_0x3df086),_0x3df0['CsjTfl'][_0x48bfe8]=_0x3df086):_0x3df086=_0x5bd582,_0x3df086;}const DEFAULT_TIMEOUT=0x2710,DEFAULT_MAX_RESPONSE_SIZE=0x100000;export class HttpBridge{[_0xd8fac0(0x1e0)];['timeout'];[_0xd8fac0(0x1fd)];constructor(_0x1ba873){const _0xebf45b=_0xd8fac0;this[_0xebf45b(0x1e0)]=new Set(_0x1ba873[_0xebf45b(0x1e0)][_0xebf45b(0x1e6)](_0x15de5e=>_0x15de5e[_0xebf45b(0x1d5)]())),this[_0xebf45b(0x1f5)]=_0x1ba873[_0xebf45b(0x1f5)]??DEFAULT_TIMEOUT,this[_0xebf45b(0x1fd)]=_0x1ba873[_0xebf45b(0x1fd)]??DEFAULT_MAX_RESPONSE_SIZE;}async[_0xd8fac0(0x201)](_0x1aa100){const _0x54de8c=_0xd8fac0,_0x4cd9e4=new _0x5c14b6[(_0x54de8c(0x1f7))](async _0x4e5097=>{const _0x20955b=_0x54de8c,{url:_0x54c043,options:_0x5cdd91}=JSON[_0x20955b(0x1f6)](_0x4e5097),_0x2cfaf7=this[_0x20955b(0x205)](_0x54c043);if(!this[_0x20955b(0x1e0)][_0x20955b(0x1ed)](_0x2cfaf7[_0x20955b(0x1d5)]()))throw new Error(_0x20955b(0x1ec)['concat'](_0x2cfaf7,_0x20955b(0x1e7)));const _0x2d2c8c=new AbortController(),_0x1776c0=setTimeout(()=>_0x2d2c8c[_0x20955b(0x1f4)](),this[_0x20955b(0x1f5)]);try{const _0x28a765=await fetch(_0x54c043,{'method':_0x5cdd91?.[_0x20955b(0x1fa)]??'GET','headers':_0x5cdd91?.[_0x20955b(0x1ff)],'body':_0x5cdd91?.[_0x20955b(0x1de)],'signal':_0x2d2c8c['signal'],'redirect':'manual'}),_0x1dcdee=await this[_0x20955b(0x1e9)](_0x28a765),_0x3a39e0={};_0x28a765[_0x20955b(0x1ff)][_0x20955b(0x1f2)]((_0x4bb84c,_0x3c0e3d)=>{_0x3a39e0[_0x3c0e3d]=_0x4bb84c;});const _0x1e3596={'status':_0x28a765['status'],'statusText':_0x28a765[_0x20955b(0x1e3)],'headers':_0x3a39e0,'body':_0x1dcdee};return JSON[_0x20955b(0x1f1)](_0x1e3596);}catch(_0xaf868f){if(_0xaf868f instanceof DOMException&&_0xaf868f[_0x20955b(0x1e5)]===_0x20955b(0x1db))throw new Error(_0x20955b(0x1e2)[_0x20955b(0x203)](this[_0x20955b(0x1f5)],'ms'));throw _0xaf868f;}finally{clearTimeout(_0x1776c0);}});await _0x1aa100[_0x54de8c(0x1ee)]('globalThis.fetch\x20=\x20async\x20function(url,\x20options)\x20{\x0a\x20\x20\x20\x20\x20\x20\x20\x20const\x20requestJson\x20=\x20JSON.stringify({\x20url,\x20options\x20});\x0a\x20\x20\x20\x20\x20\x20\x20\x20const\x20responseJson\x20=\x20await\x20$0.apply(undefined,\x20[requestJson],\x20{\x20result:\x20{\x20promise:\x20true\x20}\x20});\x0a\x20\x20\x20\x20\x20\x20\x20\x20return\x20JSON.parse(responseJson);\x0a\x20\x20\x20\x20\x20\x20}',[_0x4cd9e4],{'arguments':{'reference':!![]}});}static [_0xd8fac0(0x1dc)]=new Set([_0xd8fac0(0x206),_0xd8fac0(0x1d8)]);[_0xd8fac0(0x205)](_0x37a625){const _0x33cd35=_0xd8fac0;let _0x5ec971;try{_0x5ec971=new URL(_0x37a625);}catch{throw new Error(_0x33cd35(0x1fe)[_0x33cd35(0x203)](_0x37a625,'\x22'));}if(!HttpBridge[_0x33cd35(0x1dc)][_0x33cd35(0x1ed)](_0x5ec971[_0x33cd35(0x1e8)]))throw new Error('Blocked\x20URL\x20protocol\x20\x22'['concat'](_0x5ec971[_0x33cd35(0x1e8)],'\x22\x20—\x20only\x20http:\x20and\x20https:\x20are\x20allowed'));return _0x5ec971['hostname'];}async['readBodyWithLimit'](_0x17a52f){const _0x5f9051=_0xd8fac0,_0x55bf94=_0x17a52f['body']?.[_0x5f9051(0x1e1)]();if(!_0x55bf94)return'';const _0x355918=new TextDecoder(),_0x19d7c1=[];let _0x4fa466=0x0;try{while(!![]){const {done:_0x3976aa,value:_0x55beea}=await _0x55bf94[_0x5f9051(0x1f8)]();if(_0x3976aa)break;_0x4fa466+=_0x55beea[_0x5f9051(0x1ea)];if(_0x4fa466>this[_0x5f9051(0x1fd)]){_0x19d7c1['push'](_0x355918[_0x5f9051(0x1d4)](_0x55beea,{'stream':![]})),_0x19d7c1[_0x5f9051(0x204)](_0x5f9051(0x1fc)[_0x5f9051(0x203)](this[_0x5f9051(0x1fd)],_0x5f9051(0x1da)));break;}_0x19d7c1['push'](_0x355918[_0x5f9051(0x1d4)](_0x55beea,{'stream':!![]}));}}finally{_0x55bf94[_0x5f9051(0x1eb)]();}return _0x19d7c1[_0x5f9051(0x1d6)]('');}}
|