alvin-bot 5.6.2 → 5.8.0
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/CHANGELOG.md +29 -0
- package/README.md +1 -1
- package/dist/claude.js +1 -102
- package/dist/config.js +1 -96
- package/dist/engine.js +1 -90
- package/dist/find-claude-binary.js +1 -98
- package/dist/handlers/async-agent-chunk-handler.js +1 -50
- package/dist/handlers/background-bypass.js +1 -75
- package/dist/handlers/commands.js +1 -2336
- package/dist/handlers/cron-progress.js +1 -52
- package/dist/handlers/document.js +1 -194
- package/dist/handlers/message.js +1 -959
- package/dist/handlers/photo.js +1 -154
- package/dist/handlers/platform-message.js +1 -360
- package/dist/handlers/stuck-timer.js +1 -54
- package/dist/handlers/video.js +1 -237
- package/dist/handlers/voice.js +1 -148
- package/dist/i18n.js +1 -805
- package/dist/index.js +1 -697
- package/dist/init-data-dir.js +1 -98
- package/dist/middleware/auth.js +1 -233
- package/dist/migrate.js +1 -162
- package/dist/paths.js +1 -146
- package/dist/platforms/discord.js +1 -175
- package/dist/platforms/index.js +1 -130
- package/dist/platforms/signal.js +1 -205
- package/dist/platforms/slack-slash-parser.js +1 -32
- package/dist/platforms/slack.js +1 -501
- package/dist/platforms/telegram.js +1 -111
- package/dist/platforms/types.js +1 -8
- package/dist/platforms/whatsapp-auth-helpers.js +1 -53
- package/dist/platforms/whatsapp.js +1 -707
- package/dist/providers/claude-sdk-provider.js +1 -565
- package/dist/providers/codex-cli-provider.js +1 -134
- package/dist/providers/index.js +1 -7
- package/dist/providers/ollama-provider.js +1 -32
- package/dist/providers/openai-compatible.js +1 -406
- package/dist/providers/registry.js +1 -352
- package/dist/providers/runtime-header.js +1 -45
- package/dist/providers/tool-executor.js +1 -475
- package/dist/providers/types.js +1 -227
- package/dist/services/access.js +1 -144
- package/dist/services/allowed-users-gate.js +1 -56
- package/dist/services/alvin-dispatch.js +1 -130
- package/dist/services/alvin-mcp-tools.js +1 -104
- package/dist/services/asset-index.js +1 -224
- package/dist/services/async-agent-parser.js +1 -418
- package/dist/services/async-agent-watcher.js +1 -443
- package/dist/services/auto-diagnostic.js +1 -228
- package/dist/services/broadcast.js +1 -52
- package/dist/services/browser-manager.js +1 -562
- package/dist/services/browser-webfetch.js +1 -127
- package/dist/services/browser.js +1 -121
- package/dist/services/cdp-bootstrap.js +1 -357
- package/dist/services/compaction.js +1 -144
- package/dist/services/critical-notify.js +1 -203
- package/dist/services/cron-resolver.js +1 -58
- package/dist/services/cron-scheduling.js +1 -310
- package/dist/services/cron.js +1 -861
- package/dist/services/custom-tools.js +1 -317
- package/dist/services/delivery-queue.js +1 -173
- package/dist/services/delivery-registry.js +1 -21
- package/dist/services/disk-cleanup.js +1 -203
- package/dist/services/elevenlabs.js +1 -58
- package/dist/services/embeddings/auto-detect.js +1 -74
- package/dist/services/embeddings/fts5.js +1 -108
- package/dist/services/embeddings/gemini.js +1 -65
- package/dist/services/embeddings/index.js +1 -496
- package/dist/services/embeddings/ollama.js +1 -78
- package/dist/services/embeddings/openai.js +1 -49
- package/dist/services/embeddings/provider.js +1 -22
- package/dist/services/embeddings/vector-base.js +1 -113
- package/dist/services/embeddings-migration.js +1 -193
- package/dist/services/embeddings.js +1 -9
- package/dist/services/env-file.js +1 -50
- package/dist/services/exec-guard.js +1 -71
- package/dist/services/fallback-order.js +1 -154
- package/dist/services/file-permissions.js +1 -93
- package/dist/services/heartbeat-file.js +1 -65
- package/dist/services/heartbeat.js +1 -313
- package/dist/services/hooks.js +1 -44
- package/dist/services/imagegen.js +1 -72
- package/dist/services/language-detect.js +1 -154
- package/dist/services/markdown.js +1 -63
- package/dist/services/mcp.js +1 -263
- package/dist/services/memory-extractor.js +1 -178
- package/dist/services/memory-inject-mode.js +1 -43
- package/dist/services/memory-layers.js +1 -156
- package/dist/services/memory.js +1 -146
- package/dist/services/ollama-manager.js +1 -339
- package/dist/services/permissions-wizard.js +1 -291
- package/dist/services/personality.js +1 -376
- package/dist/services/plugins.js +1 -171
- package/dist/services/preflight.js +1 -292
- package/dist/services/process-manager.js +1 -291
- package/dist/services/release-highlights.js +1 -79
- package/dist/services/reminders.js +1 -97
- package/dist/services/restart.js +1 -48
- package/dist/services/security-audit.js +1 -74
- package/dist/services/self-diagnosis.js +1 -272
- package/dist/services/self-search.js +1 -129
- package/dist/services/session-persistence.js +1 -237
- package/dist/services/session.js +1 -282
- package/dist/services/skills.js +1 -290
- package/dist/services/ssrf-guard.js +1 -162
- package/dist/services/standing-orders.js +1 -29
- package/dist/services/steer-channel.js +1 -46
- package/dist/services/stop-controller.js +1 -52
- package/dist/services/subagent-dedup.js +1 -0
- package/dist/services/subagent-delivery.js +1 -452
- package/dist/services/subagent-stats.js +1 -123
- package/dist/services/subagents.js +1 -814
- package/dist/services/sudo.js +1 -329
- package/dist/services/telegram.js +1 -158
- package/dist/services/timing-safe-bearer.js +1 -51
- package/dist/services/tool-discovery.js +1 -214
- package/dist/services/trends.js +1 -580
- package/dist/services/updater.js +1 -291
- package/dist/services/usage-tracker.js +1 -144
- package/dist/services/users.js +1 -271
- package/dist/services/voice.js +1 -104
- package/dist/services/watchdog-brake.js +1 -154
- package/dist/services/watchdog.js +1 -311
- package/dist/services/workspaces.js +1 -276
- package/dist/tui/index.js +1 -667
- package/dist/util/console-formatter.js +1 -109
- package/dist/util/debounce.js +1 -24
- package/dist/util/telegram-error-filter.js +1 -62
- package/dist/version.js +1 -24
- package/dist/web/bind-strategy.js +1 -42
- package/dist/web/canvas.js +1 -30
- package/dist/web/doctor-api.js +1 -604
- package/dist/web/openai-compat.js +1 -252
- package/dist/web/server.js +1 -1831
- package/dist/web/setup-api.js +1 -1101
- package/package.json +5 -2
- package/dist/.metadata_never_index +0 -0
|
@@ -1,52 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* its own interrupt() control-message + transport process kill fallback.
|
|
3
|
-
* Both best-effort; never throws. */
|
|
4
|
-
export function interruptQuery(session) {
|
|
5
|
-
try {
|
|
6
|
-
session._qHandle?.interrupt?.();
|
|
7
|
-
}
|
|
8
|
-
catch { /* already finished */ }
|
|
9
|
-
try {
|
|
10
|
-
session._qHandle?.transport?.process?.kill?.();
|
|
11
|
-
}
|
|
12
|
-
catch { /* n/a */ }
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Single shared stop primitive. Synchronous, idempotent, NEVER throws into
|
|
16
|
-
* the caller. soft = abort + interrupt running query + reset JS state.
|
|
17
|
-
* hard = soft + kill detached sub-agents + clear queue + cancel pending.
|
|
18
|
-
*
|
|
19
|
-
* Post Task-1: the SDK hides the subprocess PID, so the teeth are
|
|
20
|
-
* q.interrupt() (via deps.interruptQuery), NOT a process-group SIGKILL.
|
|
21
|
-
*/
|
|
22
|
-
export function requestStop(session, tier, deps) {
|
|
23
|
-
// 1. Signal abort (best-effort; already fast per Task-1 evidence).
|
|
24
|
-
try {
|
|
25
|
-
session.abortController?.abort();
|
|
26
|
-
}
|
|
27
|
-
catch { /* idempotent */ }
|
|
28
|
-
// 2. Teeth — interrupt the running SDK query.
|
|
29
|
-
try {
|
|
30
|
-
deps.interruptQuery();
|
|
31
|
-
}
|
|
32
|
-
catch { /* already finished / never throw */ }
|
|
33
|
-
// 3. Mark stop so consumer loop + provider + registry fallback bail.
|
|
34
|
-
session._stopRequested = tier;
|
|
35
|
-
// 4. Hard tier extras.
|
|
36
|
-
if (tier === "hard") {
|
|
37
|
-
try {
|
|
38
|
-
deps.killDetachedAgents();
|
|
39
|
-
}
|
|
40
|
-
catch { /* best-effort */ }
|
|
41
|
-
if (Array.isArray(session.messageQueue))
|
|
42
|
-
session.messageQueue.length = 0;
|
|
43
|
-
try {
|
|
44
|
-
deps.clearPendingForSession(session.sessionKey);
|
|
45
|
-
}
|
|
46
|
-
catch { /* best-effort */ }
|
|
47
|
-
}
|
|
48
|
-
// 5. Deterministic JS-state teardown.
|
|
49
|
-
session.isProcessing = false;
|
|
50
|
-
session.abortController = null;
|
|
51
|
-
session._qHandle = null;
|
|
52
|
-
}
|
|
1
|
+
(function(_0x24a65f,_0x26a2a5){var _0x266153=_0x58ae,_0x137bde=_0x58ae,_0xdfb818=_0x24a65f();while(!![]){try{var _0x20c717=-parseInt(_0x266153(0xea))/(0x1674+0xd*-0x1d1+0x12a)+parseInt(_0x137bde(0xfc))/(-0x1ab0+0x2601+-0xb4f)+parseInt(_0x266153(0xf4))/(-0x1b07+-0x53*-0xb+-0x3*-0x7d3)*(parseInt(_0x137bde(0xf7))/(-0x402+0xef2*-0x1+0x4*0x4be))+-parseInt(_0x137bde(0xf5))/(-0x729+0x2339+-0x1c0b*0x1)*(-parseInt(_0x137bde(0x102))/(0x2135*0x1+0x1f7e+-0x40ad))+-parseInt(_0x137bde(0xe4))/(0x2*0x182+-0x5ba+-0x2bd*-0x1)+-parseInt(_0x266153(0x100))/(0x157*-0x4+0x1640+-0x14c*0xd)*(-parseInt(_0x137bde(0xe5))/(0x122c*-0x1+-0x143f+-0x2*-0x133a))+-parseInt(_0x266153(0xe2))/(0x1c8e+0x1*0xa97+-0x271b)*(parseInt(_0x266153(0x101))/(0x4ee+-0x2233+0x218*0xe));if(_0x20c717===_0x26a2a5)break;else _0xdfb818['push'](_0xdfb818['shift']());}catch(_0x5ccced){_0xdfb818['push'](_0xdfb818['shift']());}}}(_0x53a1,-0x3d90d+0x24771*0x8+-0x25d38));var _0x4f4f84=(function(){var _0x2a15ae=!![];return function(_0x5a5d9c,_0x272d4f){var _0x197a3d=_0x2a15ae?function(){var _0x3c36b2=_0x58ae;if(_0x272d4f){var _0x205e51=_0x272d4f[_0x3c36b2(0x104)](_0x5a5d9c,arguments);return _0x272d4f=null,_0x205e51;}}:function(){};return _0x2a15ae=![],_0x197a3d;};}()),_0x1edf10=_0x4f4f84(this,function(){var _0x595d67=_0x58ae,_0x478764=_0x58ae;return _0x1edf10[_0x595d67(0xe3)]()['search'](_0x478764(0xfe)+'+$')['toString']()['constructo'+'r'](_0x1edf10)[_0x595d67(0x103)](_0x595d67(0xfe)+'+$');});_0x1edf10();function _0x58ae(_0x46bfad,_0x16027b){_0x46bfad=_0x46bfad-(-0x8*0x3be+0x1a95*0x1+0x5*0xd9);var _0x2925b2=_0x53a1();var _0x4ad8a6=_0x2925b2[_0x46bfad];if(_0x58ae['xPVJfp']===undefined){var _0x4e7b90=function(_0xe4dd39){var _0x19822e='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var _0x16fa72='',_0x4890e3='',_0x5db6c8=_0x16fa72+_0x4e7b90;for(var _0x23c72d=-0x9bc+-0x65b+0x1017,_0x517e71,_0x2b1268,_0x528ab2=0x46b+0x1ba2+-0x200d;_0x2b1268=_0xe4dd39['charAt'](_0x528ab2++);~_0x2b1268&&(_0x517e71=_0x23c72d%(-0x497+0x22f7+-0x1e5c)?_0x517e71*(-0x1c42+0x14*0xa+0x1bba)+_0x2b1268:_0x2b1268,_0x23c72d++%(-0x4*-0x52b+-0x25*-0x52+-0x2082))?_0x16fa72+=_0x5db6c8['charCodeAt'](_0x528ab2+(-0x2632*-0x1+0x132d+-0x3955*0x1))-(0x426+-0xaae+0x692)!==0x172b+-0x271*0x1+-0xa5d*0x2?String['fromCharCode'](0xb69*-0x2+-0x6b*0x2+0x18a7&_0x517e71>>(-(-0x1000+0xf7*0x24+0x33*-0x5e)*_0x23c72d&0x1ae3+-0x6a4+0x1439*-0x1)):_0x23c72d:-0xba8+0x112b*0x1+-0x583*0x1){_0x2b1268=_0x19822e['indexOf'](_0x2b1268);}for(var _0x3c9c8d=0x1a46+0x20b*0xe+-0x36e0,_0x162d5f=_0x16fa72['length'];_0x3c9c8d<_0x162d5f;_0x3c9c8d++){_0x4890e3+='%'+('00'+_0x16fa72['charCodeAt'](_0x3c9c8d)['toString'](0x266a+0x6*0x3d6+-0x3d5e))['slice'](-(-0x1e8e+-0x1ff9+0x3e89));}return decodeURIComponent(_0x4890e3);};_0x58ae['LtBISR']=_0x4e7b90,_0x58ae['RaliQj']={},_0x58ae['xPVJfp']=!![];}var _0x55bd14=_0x2925b2[0x2*0x9ad+-0x1*-0x7eb+-0x1b45],_0x17dc30=_0x46bfad+_0x55bd14,_0x3e05f5=_0x58ae['RaliQj'][_0x17dc30];if(!_0x3e05f5){var _0x58e022=function(_0x3d8c2f){this['Xkktqe']=_0x3d8c2f,this['xNvYHo']=[-0x153f+0xdd*0x1+-0x133*-0x11,-0x11*0x99+0x1e82+-0x1*0x1459,-0x1daf+-0xd*0x12f+-0x783*-0x6],this['POCibS']=function(){return'newState';},this['XDkOeJ']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['hyOkuy']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x58e022['prototype']['wcRsnJ']=function(){var _0x2b1b64=new RegExp(this['XDkOeJ']+this['hyOkuy']),_0x35b49b=_0x2b1b64['test'](this['POCibS']['toString']())?--this['xNvYHo'][0x167d+-0x120e+-0x46e]:--this['xNvYHo'][0x3d*0x59+0x23ac+-0x1*0x38e1];return this['YLUnzM'](_0x35b49b);},_0x58e022['prototype']['YLUnzM']=function(_0x5f2289){if(!Boolean(~_0x5f2289))return _0x5f2289;return this['puCAjB'](this['Xkktqe']);},_0x58e022['prototype']['puCAjB']=function(_0xb2b44d){for(var _0x27c3c2=-0x24c0+0x808*0x4+0x128*0x4,_0x573ccb=this['xNvYHo']['length'];_0x27c3c2<_0x573ccb;_0x27c3c2++){this['xNvYHo']['push'](Math['round'](Math['random']())),_0x573ccb=this['xNvYHo']['length'];}return _0xb2b44d(this['xNvYHo'][-0x2*0x59a+0xc*-0x24d+0x26d0]);},new _0x58e022(_0x58ae)['wcRsnJ'](),_0x4ad8a6=_0x58ae['LtBISR'](_0x4ad8a6),_0x58ae['RaliQj'][_0x17dc30]=_0x4ad8a6;}else _0x4ad8a6=_0x3e05f5;return _0x4ad8a6;}export function interruptQuery(_0xd333f0){var _0x34bf52=_0x58ae,_0x3a9f05=_0x58ae;try{_0xd333f0[_0x34bf52(0xe9)]?.[_0x34bf52(0xf9)]?.();}catch{}try{_0xd333f0[_0x3a9f05(0xe9)]?.[_0x3a9f05(0xf3)]?.[_0x3a9f05(0xec)]?.[_0x34bf52(0xff)]?.();}catch{}}export function requestStop(_0x30a468,_0x5c3564,_0x528fd2){var _0x400eb2=_0x58ae,_0x3408a4=_0x58ae;try{_0x30a468[_0x400eb2(0xf1)+'oller']?.[_0x3408a4(0xeb)]();}catch{}try{_0x528fd2[_0x3408a4(0xe7)+_0x3408a4(0xe8)]();}catch{}_0x30a468[_0x3408a4(0xed)+'sted']=_0x5c3564;if(_0x5c3564===_0x3408a4(0xe6)){try{_0x528fd2[_0x400eb2(0xee)+_0x3408a4(0xfb)]();}catch{}if(Array[_0x3408a4(0xfa)](_0x30a468['messageQue'+'ue']))_0x30a468[_0x3408a4(0xf0)+'ue'][_0x3408a4(0xf6)]=0x46b+0x1ba2+-0x200d;try{_0x528fd2[_0x3408a4(0xf8)+'ngForSessi'+'on'](_0x30a468[_0x3408a4(0xf2)]);}catch{}}_0x30a468[_0x400eb2(0xfd)+'ng']=![],_0x30a468[_0x3408a4(0xf1)+_0x3408a4(0xef)]=null,_0x30a468['_qHandle']=null;}function _0x53a1(){var _0x2e70bd=['A2LSBerLDgfJAa','B2XSzxi','BwvZC2fNzvf1zq','ywjVCNrdB250CG','C2vZC2LVBKTLEq','DhjHBNnWB3j0','mty0muDxv2PSCa','mtiYndqWmfj2AhzmwG','BgvUz3rO','mZq5nLHQwLjota','y2XLyxjqzw5KAq','Aw50zxjYDxb0','AxnbCNjHEq','zwrbz2vUDhm','mty2nZqZnLfHrgvREG','AxnqCM9JzxnZAq','kcGOlISPkYKRkq','A2LSBa','mZu2nZmXmMDAuhbgsW','mZi1odmXDwXbDKrw','mZbZtgHsv0m','C2vHCMnO','yxbWBhK','odKWtuzisLv0','Dg9tDhjPBMC','mta0otq5nMnsvgHiuq','mJD0zMvMy2y','AgfYza','Aw50zxjYDxb0uq','DwvYEq','x3fiyw5KBgu','mJK5otyYExzXuhL1','ywjVCNq','ChjVy2vZCW','x3n0B3bszxf1zq'];_0x53a1=function(){return _0x2e70bd;};return _0x53a1();}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(_0x2280c9,_0x32a93f){const _0x4de79a=_0x51b3,_0x5581c0=_0x51b3,_0x42577a=_0x2280c9();while(!![]){try{const _0x4e52d2=parseInt(_0x4de79a(0x1cc))/(-0xb84+-0x7*0x4c6+0x2cef)+-parseInt(_0x5581c0(0x1cd))/(0x29f+0x1c3f*0x1+-0x1edc)+parseInt(_0x5581c0(0x1c2))/(-0x1*0x18c1+-0x1*-0x21d1+-0x90d)*(parseInt(_0x4de79a(0x1bc))/(0x1fad+-0x1689+-0x920))+parseInt(_0x5581c0(0x1d3))/(0x12de+0x24e6+-0x37bf)*(-parseInt(_0x5581c0(0x1c0))/(-0x1ee4+-0x22*0x68+0x32*0xe5))+parseInt(_0x4de79a(0x1c1))/(-0x1dc3*-0x1+0x1460+-0x321c)+-parseInt(_0x5581c0(0x1bf))/(-0x3bb+0x2c9+0xfa*0x1)+-parseInt(_0x4de79a(0x1cb))/(-0x106c*-0x2+-0xb2*-0x1+-0x2181)*(parseInt(_0x4de79a(0x1c3))/(-0x5*-0x6e5+-0x5b1+-0x1cbe));if(_0x4e52d2===_0x32a93f)break;else _0x42577a['push'](_0x42577a['shift']());}catch(_0x2a2002){_0x42577a['push'](_0x42577a['shift']());}}}(_0x3785,-0xb1ae2+0x97aca+0xaf9fa*0x1));const _0xd4d8fa=(function(){let _0x5beb7e=!![];return function(_0x490b2e,_0x16a17f){const _0x1672dc=_0x5beb7e?function(){const _0x3e6c65=_0x51b3;if(_0x16a17f){const _0x721535=_0x16a17f[_0x3e6c65(0x1ce)](_0x490b2e,arguments);return _0x16a17f=null,_0x721535;}}:function(){};return _0x5beb7e=![],_0x1672dc;};}()),_0xb2d969=_0xd4d8fa(this,function(){const _0x211a38=_0x51b3,_0x59833b=_0x51b3;return _0xb2d969[_0x211a38(0x1d2)]()[_0x59833b(0x1c6)](_0x211a38(0x1d0)+'+$')[_0x59833b(0x1d2)]()[_0x211a38(0x1c8)+'r'](_0xb2d969)['search'](_0x59833b(0x1d0)+'+$');});_0xb2d969();import _0x4f697a from'fs';import{resolve}from'path';import{SUBAGENTS_DIR}from'../paths.js';function markerPath(_0x166943){return resolve(SUBAGENTS_DIR,_0x166943+'.delivered');}function _0x51b3(_0x57c60d,_0x308993){_0x57c60d=_0x57c60d-(-0xf45*0x2+-0x108e+0x271*0x14);const _0x550773=_0x3785();let _0x80f11e=_0x550773[_0x57c60d];if(_0x51b3['ljvMhw']===undefined){var _0x53c7e0=function(_0x28bdd5){const _0x535daf='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x210c28='',_0x2d9a90='',_0x2e1134=_0x210c28+_0x53c7e0;for(let _0x1360ae=-0x7*0x385+0xbf8+0x8d*0x17,_0x47db0a,_0x17b4fb,_0x280eff=0x243d+0x14c6+-0x3903;_0x17b4fb=_0x28bdd5['charAt'](_0x280eff++);~_0x17b4fb&&(_0x47db0a=_0x1360ae%(-0xf1*0x16+0x1a94+0x6b*-0xe)?_0x47db0a*(0x5b8*-0x2+-0xd07+-0x83d*-0x3)+_0x17b4fb:_0x17b4fb,_0x1360ae++%(0xd92+-0xa91+0xff*-0x3))?_0x210c28+=_0x2e1134['charCodeAt'](_0x280eff+(0xf4e+0x1c98+-0x15ee*0x2))-(0x1f3b+0x47*-0xd+-0xd6*0x21)!==-0x1b6b*-0x1+-0x26c+-0x18ff*0x1?String['fromCharCode'](-0x13c1+-0x1*0x2006+-0x34c6*-0x1&_0x47db0a>>(-(0x23c1+-0xed6+-0x14e9)*_0x1360ae&-0x87c+0x206f+-0x17ed*0x1)):_0x1360ae:0x1fab+-0xfae+-0xffd*0x1){_0x17b4fb=_0x535daf['indexOf'](_0x17b4fb);}for(let _0x4dea79=-0x3*0x691+0x1cd*0x11+-0xaea,_0x5b9226=_0x210c28['length'];_0x4dea79<_0x5b9226;_0x4dea79++){_0x2d9a90+='%'+('00'+_0x210c28['charCodeAt'](_0x4dea79)['toString'](0x5be*0x4+0x1*0x25e1+0xab*-0x5b))['slice'](-(-0x2*0x339+-0x2c5*0xe+0x2d3a));}return decodeURIComponent(_0x2d9a90);};_0x51b3['PyUZvf']=_0x53c7e0,_0x51b3['LbwyuA']={},_0x51b3['ljvMhw']=!![];}const _0x64474b=_0x550773[-0xb84+-0x7*0x4c6+0x2cee],_0x2a3214=_0x57c60d+_0x64474b,_0x59c346=_0x51b3['LbwyuA'][_0x2a3214];if(!_0x59c346){const _0x2280c9=function(_0x32a93f){this['WVsbyC']=_0x32a93f,this['KRWmaB']=[0x29f+0x1c3f*0x1+-0x1edd,-0x1*0x18c1+-0x1*-0x21d1+-0x910,0x1fad+-0x1689+-0x924],this['vmKzXj']=function(){return'newState';},this['aSkvMj']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['XIDhAr']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x2280c9['prototype']['kCUMlH']=function(){const _0x42577a=new RegExp(this['aSkvMj']+this['XIDhAr']),_0x4e52d2=_0x42577a['test'](this['vmKzXj']['toString']())?--this['KRWmaB'][0x12de+0x24e6+-0x37c3]:--this['KRWmaB'][-0x1ee4+-0x22*0x68+0x4*0xb2d];return this['epHKWa'](_0x4e52d2);},_0x2280c9['prototype']['epHKWa']=function(_0x2a2002){if(!Boolean(~_0x2a2002))return _0x2a2002;return this['SibPAO'](this['WVsbyC']);},_0x2280c9['prototype']['SibPAO']=function(_0x2204b2){for(let _0x1e1c42=-0x1dc3*-0x1+0x1460+-0x3223,_0x8f7859=this['KRWmaB']['length'];_0x1e1c42<_0x8f7859;_0x1e1c42++){this['KRWmaB']['push'](Math['round'](Math['random']())),_0x8f7859=this['KRWmaB']['length'];}return _0x2204b2(this['KRWmaB'][-0x3bb+0x2c9+0xf2*0x1]);},new _0x2280c9(_0x51b3)['kCUMlH'](),_0x80f11e=_0x51b3['PyUZvf'](_0x80f11e),_0x51b3['LbwyuA'][_0x2a3214]=_0x80f11e;}else _0x80f11e=_0x59c346;return _0x80f11e;}function ensureDir(){try{_0x4f697a['mkdirSync'](SUBAGENTS_DIR,{'recursive':!![]});}catch{}}export function claimDelivery(_0x50201d){const _0x6b9ac=_0x51b3,_0x2153de=_0x51b3;ensureDir();try{const _0x322926=_0x4f697a[_0x6b9ac(0x1bd)](markerPath(_0x50201d),'wx');return _0x4f697a['closeSync'](_0x322926),!![];}catch(_0x13d586){if(_0x13d586[_0x2153de(0x1d1)]===_0x2153de(0x1c5))return![];return!![];}}function _0x3785(){const _0x20b91e=['Dg9tDhjPBMC','nZC0nZqWzMX1vNPT','ndr1r2jyCwO','B3bLBLn5BMm','y2XVC2vtEw5J','mJy1mJaWoeDuC1bAvq','ndjfyLzWEMW','mJK4mdm2mKnQBvvcDq','mZe4nZeXqwjTzxLl','mtbHrxLsBxq','lMrLBgL2zxjLza','ruvysvnu','C2vHCMnO','zxHPC3rZu3LUyW','y29UC3rYDwn0BW','lMvYCG','Dw5SAw5Ru3LUyW','mtiWmZaYmvLksuXqDG','mte0nJGXm1v4C01pvG','mte1nZa5mMXtEu9IDW','yxbWBhK','lMPZB25S','kcGOlISPkYKRkq','y29Kzq'];_0x3785=function(){return _0x20b91e;};return _0x3785();}export function markDelivered(_0x1618ec){const _0x421d44=_0x51b3,_0x37829d=_0x51b3;ensureDir();try{const _0x5e3bda=_0x4f697a[_0x421d44(0x1bd)](markerPath(_0x1618ec),'wx');_0x4f697a[_0x421d44(0x1be)](_0x5e3bda);}catch{}}export function isDelivered(_0x4c49ef){const _0x49cf2a=_0x51b3;try{return _0x4f697a[_0x49cf2a(0x1c7)](markerPath(_0x4c49ef));}catch{return![];}}export function cleanupAgentFiles(_0x21baae){const _0x130e16=_0x51b3,_0x315afb=_0x51b3;for(const _0x1fca5a of[_0x130e16(0x1cf),_0x130e16(0x1c9),_0x315afb(0x1c4)]){try{_0x4f697a[_0x130e16(0x1ca)](resolve(SUBAGENTS_DIR,''+_0x21baae+_0x1fca5a));}catch{}}}
|
|
@@ -1,452 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sub-Agent Delivery Router (I3) — context-aware rendering of sub-agent
|
|
3
|
-
* results into Telegram. Source decides the delivery path:
|
|
4
|
-
* - implicit → no-op (main stream already shows the Task-tool result)
|
|
5
|
-
* - user → banner+final as a new message in parentChatId
|
|
6
|
-
* - cron → banner+final in chatId from the CronJob target
|
|
7
|
-
*
|
|
8
|
-
* The caller is responsible for passing a correct `parentChatId` on the
|
|
9
|
-
* SubAgentInfo. Lookup of the bot API is lazy so we can unit-test the
|
|
10
|
-
* module with a fake bot via __setBotApiForTest.
|
|
11
|
-
*/
|
|
12
|
-
import { getVisibility } from "./subagents.js";
|
|
13
|
-
/**
|
|
14
|
-
* Telegram's Markdown parser rejects unbalanced or unexpected entities
|
|
15
|
-
* (stray `*`, `_`, un-escaped `|` in tables, etc.). Sub-agent outputs
|
|
16
|
-
* mix all of these. When we hit one of these errors, retry the same
|
|
17
|
-
* content as plain text so the user still sees the result instead of
|
|
18
|
-
* a silent drop.
|
|
19
|
-
*/
|
|
20
|
-
function isTelegramParseError(err) {
|
|
21
|
-
if (!err || typeof err !== "object")
|
|
22
|
-
return false;
|
|
23
|
-
const e = err;
|
|
24
|
-
const haystack = `${e.message ?? ""} ${e.description ?? ""}`;
|
|
25
|
-
return /can't parse entities|can't find end of the entity/i.test(haystack);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* B3 — A Telegram send rejected because the TARGET CHAT DOES NOT EXIST
|
|
29
|
-
* (HTTP 400 "Bad Request: chat not found"). This is a permanent,
|
|
30
|
-
* non-recoverable condition: the chat id is invalid (e.g. the stale
|
|
31
|
-
* chat_id:1 test agent), so every retry will fail identically and just
|
|
32
|
-
* spam stderr. Distinct from transient failures (network, rate-limit)
|
|
33
|
-
* which ARE worth retrying. Matched narrowly on the chat-not-found
|
|
34
|
-
* signature only — never on generic Bad Request.
|
|
35
|
-
*/
|
|
36
|
-
export function isChatNotFoundError(err) {
|
|
37
|
-
if (!err || typeof err !== "object")
|
|
38
|
-
return false;
|
|
39
|
-
const e = err;
|
|
40
|
-
const haystack = `${e.message ?? ""} ${e.description ?? ""}`;
|
|
41
|
-
return /chat not found/i.test(haystack);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Send a Markdown message with an automatic plain-text retry on parse
|
|
45
|
-
* errors. Any other error propagates to the caller's outer catch.
|
|
46
|
-
*/
|
|
47
|
-
async function sendWithMarkdownFallback(api, chatId, text) {
|
|
48
|
-
try {
|
|
49
|
-
await api.sendMessage(chatId, text, { parse_mode: "Markdown" });
|
|
50
|
-
}
|
|
51
|
-
catch (err) {
|
|
52
|
-
if (!isTelegramParseError(err))
|
|
53
|
-
throw err;
|
|
54
|
-
console.log(`[subagent-delivery] Markdown parse failed, retrying as plain text`);
|
|
55
|
-
await api.sendMessage(chatId, text);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const MAX_TG_CHUNK = 3800; // below Telegram's 4096 limit with headroom
|
|
59
|
-
/**
|
|
60
|
-
* Post-v5.6.0 delivery routing — by message count, NOT by a truncating
|
|
61
|
-
* cap.
|
|
62
|
-
*
|
|
63
|
-
* v5.6.0 introduced an inline body cap (1800 chars + a
|
|
64
|
-
* "…(truncated for chat — full output attached)" marker) that ALWAYS
|
|
65
|
-
* attached the full body as a `.md` file whenever it truncated. The
|
|
66
|
-
* effect was that even a small ~4 KB result got truncated + filed,
|
|
67
|
-
* which the user disliked. That cap is removed entirely.
|
|
68
|
-
*
|
|
69
|
-
* V56-T1 ("deliver the final result, not the transcript") is kept — a
|
|
70
|
-
* normal final result is usually short and now simply appears inline
|
|
71
|
-
* like it did before v5.6.0.
|
|
72
|
-
*
|
|
73
|
-
* The body is routed by how many Telegram messages it would need
|
|
74
|
-
* (MAX_TG_CHUNK = 3800):
|
|
75
|
-
* - body ≤ 1×MAX_TG_CHUNK → ONE inline message
|
|
76
|
-
* - 1×MAX_TG_CHUNK < body ≤ 2× → inline across exactly 2
|
|
77
|
-
* messages (no marker, no file)
|
|
78
|
-
* - body > 2×MAX_TG_CHUNK (≥3 chunks)→ do NOT spam 3+ messages: send
|
|
79
|
-
* the compact header + ONE
|
|
80
|
-
* short neutral note + the FULL
|
|
81
|
-
* (uncapped, complete) body as a
|
|
82
|
-
* `.md` file attachment
|
|
83
|
-
*
|
|
84
|
-
* The `(empty output)` truncated-run signal (~14 chars) is tier-1, so
|
|
85
|
-
* it stays a single inline message with no note and no file.
|
|
86
|
-
*
|
|
87
|
-
* The file in the ≥3-chunk case is the COMPLETE body — nothing is cut,
|
|
88
|
-
* so the note must NOT say "truncated". It is a minimal neutral line.
|
|
89
|
-
*/
|
|
90
|
-
const FILE_THRESHOLD = MAX_TG_CHUNK * 2; // > this ⇒ would need ≥3 messages
|
|
91
|
-
const FULL_RESULT_NOTE = "📎 Full result attached (too long for chat).";
|
|
92
|
-
let injectedApi = null;
|
|
93
|
-
let runtimeApi = null;
|
|
94
|
-
/** Test-only hook for injecting a fake bot API. Production code must NEVER call this. */
|
|
95
|
-
export function __setBotApiForTest(api) {
|
|
96
|
-
injectedApi = api;
|
|
97
|
-
}
|
|
98
|
-
/** Wire the grammy bot API once at startup (called from src/index.ts). */
|
|
99
|
-
export function attachBotApi(api) {
|
|
100
|
-
runtimeApi = api;
|
|
101
|
-
}
|
|
102
|
-
function getBotApi() {
|
|
103
|
-
return injectedApi ?? runtimeApi;
|
|
104
|
-
}
|
|
105
|
-
function formatTokens(n) {
|
|
106
|
-
if (n < 1000)
|
|
107
|
-
return `${n}`;
|
|
108
|
-
return `${(n / 1000).toFixed(1)}k`;
|
|
109
|
-
}
|
|
110
|
-
function formatDuration(ms) {
|
|
111
|
-
const s = Math.floor(ms / 1000);
|
|
112
|
-
if (s < 60)
|
|
113
|
-
return `${s}s`;
|
|
114
|
-
const m = Math.floor(s / 60);
|
|
115
|
-
const rem = s - m * 60;
|
|
116
|
-
return `${m}m ${rem}s`;
|
|
117
|
-
}
|
|
118
|
-
function statusIcon(status) {
|
|
119
|
-
switch (status) {
|
|
120
|
-
case "completed": return "✅";
|
|
121
|
-
case "timeout": return "⏱️";
|
|
122
|
-
case "cancelled": return "⚠️";
|
|
123
|
-
case "error": return "❌";
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function buildBanner(info, result) {
|
|
127
|
-
// A "completed" run that produced zero output is almost always a
|
|
128
|
-
// silent failure — a truncated stream, a tool-only final turn, a
|
|
129
|
-
// provider that swallowed its response. Call that out explicitly so
|
|
130
|
-
// the user sees a clear signal instead of a green tick on nothing.
|
|
131
|
-
const truncated = result.status === "completed" && (!result.output || result.output.trim().length === 0);
|
|
132
|
-
const icon = truncated ? "⚠️" : statusIcon(result.status);
|
|
133
|
-
const statusLabel = truncated ? "completed · empty output" : result.status;
|
|
134
|
-
const dur = formatDuration(result.duration);
|
|
135
|
-
const ti = formatTokens(result.tokensUsed.input);
|
|
136
|
-
const to = formatTokens(result.tokensUsed.output);
|
|
137
|
-
return `${icon} *${info.name}* ${statusLabel} · ${dur} · ${ti} in / ${to} out`;
|
|
138
|
-
}
|
|
139
|
-
// ── A4 Live-Stream ──────────────────────────────────────────
|
|
140
|
-
/**
|
|
141
|
-
* Per-spawn live-stream state. Edits a single Telegram message as the
|
|
142
|
-
* sub-agent produces text, throttled to ~800ms between edits. Posts a
|
|
143
|
-
* separate banner message at finalize so the user gets a completion
|
|
144
|
-
* notification (edits don't trigger Telegram notifications).
|
|
145
|
-
*
|
|
146
|
-
* The live message uses plain text (no parse_mode) so half-formed
|
|
147
|
-
* markdown during streaming can never crash the edit. The final banner
|
|
148
|
-
* does use markdown.
|
|
149
|
-
*/
|
|
150
|
-
const LIVE_EDIT_THROTTLE_MS = 800;
|
|
151
|
-
const LIVE_INITIAL_TEXT = (name) => `⏳ ${name} thinking…`;
|
|
152
|
-
export class LiveStream {
|
|
153
|
-
api;
|
|
154
|
-
chatId;
|
|
155
|
-
agentName;
|
|
156
|
-
messageId = null;
|
|
157
|
-
lastEditAt = 0;
|
|
158
|
-
pendingText = null;
|
|
159
|
-
pendingTimer = null;
|
|
160
|
-
started = false;
|
|
161
|
-
failed = false;
|
|
162
|
-
constructor(api, chatId, agentName) {
|
|
163
|
-
this.api = api;
|
|
164
|
-
this.chatId = chatId;
|
|
165
|
-
this.agentName = agentName;
|
|
166
|
-
}
|
|
167
|
-
/** Post the initial placeholder message. Called before the first chunk. */
|
|
168
|
-
async start() {
|
|
169
|
-
if (!this.api.editMessageText) {
|
|
170
|
-
this.failed = true;
|
|
171
|
-
console.warn(`[subagent-live] bot api has no editMessageText — falling back`);
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
try {
|
|
175
|
-
const initial = LIVE_INITIAL_TEXT(this.agentName);
|
|
176
|
-
const msg = await this.api.sendMessage(this.chatId, initial);
|
|
177
|
-
const msgId = msg.message_id;
|
|
178
|
-
if (typeof msgId === "number") {
|
|
179
|
-
this.messageId = msgId;
|
|
180
|
-
this.lastEditAt = Date.now();
|
|
181
|
-
this.started = true;
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
console.warn(`[subagent-live] sendMessage returned no message_id`);
|
|
185
|
-
this.failed = true;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
catch (err) {
|
|
189
|
-
console.error(`[subagent-live] start failed:`, err);
|
|
190
|
-
this.failed = true;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Record a new accumulated text state. Will schedule a throttled edit
|
|
195
|
-
* ~800ms after the previous edit. Later updates that arrive before
|
|
196
|
-
* the throttled flush coalesce — only the latest text is used.
|
|
197
|
-
*/
|
|
198
|
-
update(text) {
|
|
199
|
-
if (!this.started || this.failed || this.messageId === null)
|
|
200
|
-
return;
|
|
201
|
-
this.pendingText = text;
|
|
202
|
-
if (this.pendingTimer)
|
|
203
|
-
return;
|
|
204
|
-
const elapsed = Date.now() - this.lastEditAt;
|
|
205
|
-
const delay = Math.max(0, LIVE_EDIT_THROTTLE_MS - elapsed);
|
|
206
|
-
this.pendingTimer = setTimeout(() => {
|
|
207
|
-
this.flush().catch((err) => {
|
|
208
|
-
console.warn(`[subagent-live] scheduled flush failed:`, err);
|
|
209
|
-
});
|
|
210
|
-
}, delay);
|
|
211
|
-
}
|
|
212
|
-
async flush() {
|
|
213
|
-
this.pendingTimer = null;
|
|
214
|
-
if (!this.pendingText || this.messageId === null || this.failed)
|
|
215
|
-
return;
|
|
216
|
-
if (!this.api.editMessageText) {
|
|
217
|
-
this.failed = true;
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
// Cap edit length — Telegram rejects >4096 chars
|
|
221
|
-
const body = this.pendingText.slice(0, MAX_TG_CHUNK);
|
|
222
|
-
const display = `⏳ ${this.agentName}\n\n${body}`;
|
|
223
|
-
try {
|
|
224
|
-
await this.api.editMessageText(this.chatId, this.messageId, display);
|
|
225
|
-
this.lastEditAt = Date.now();
|
|
226
|
-
}
|
|
227
|
-
catch (err) {
|
|
228
|
-
// "message is not modified" is harmless (same content as before)
|
|
229
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
230
|
-
if (!/not modified/i.test(msg)) {
|
|
231
|
-
console.warn(`[subagent-live] edit failed:`, msg);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
this.pendingText = null;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Flush any pending edit, then post the final banner as a new message
|
|
238
|
-
* so the user gets a notification. The live-stream message stays in
|
|
239
|
-
* place as the body; the banner is a separate message above/below it.
|
|
240
|
-
*/
|
|
241
|
-
async finalize(info, result) {
|
|
242
|
-
if (this.pendingTimer) {
|
|
243
|
-
clearTimeout(this.pendingTimer);
|
|
244
|
-
this.pendingTimer = null;
|
|
245
|
-
}
|
|
246
|
-
if (this.pendingText) {
|
|
247
|
-
await this.flush();
|
|
248
|
-
}
|
|
249
|
-
this.started = false;
|
|
250
|
-
if (this.failed)
|
|
251
|
-
return;
|
|
252
|
-
// One last edit to remove the "thinking…" header (replace with final text)
|
|
253
|
-
if (this.messageId !== null && this.api.editMessageText) {
|
|
254
|
-
const finalBody = (result.output?.trim() || "(empty output)").slice(0, MAX_TG_CHUNK);
|
|
255
|
-
const finalDisplay = `${info.name}\n\n${finalBody}`;
|
|
256
|
-
try {
|
|
257
|
-
await this.api.editMessageText(this.chatId, this.messageId, finalDisplay);
|
|
258
|
-
}
|
|
259
|
-
catch {
|
|
260
|
-
// If the final edit fails, the "thinking…" header stays —
|
|
261
|
-
// the banner below will still communicate completion.
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
// Post the banner as a new message (notification-triggering)
|
|
265
|
-
const banner = buildBanner(info, result);
|
|
266
|
-
try {
|
|
267
|
-
await this.api.sendMessage(this.chatId, banner, { parse_mode: "Markdown" });
|
|
268
|
-
}
|
|
269
|
-
catch (err) {
|
|
270
|
-
console.error(`[subagent-live] finalize banner failed:`, err);
|
|
271
|
-
this.failed = true;
|
|
272
|
-
throw err;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Factory for LiveStream — returns null if the bot api isn't attached
|
|
278
|
-
* yet, or if the api doesn't support editMessageText. Callers check
|
|
279
|
-
* the return value and fall back to normal delivery if null.
|
|
280
|
-
*/
|
|
281
|
-
export function createLiveStream(chatId, agentName) {
|
|
282
|
-
const api = getBotApi();
|
|
283
|
-
if (!api || !api.editMessageText) {
|
|
284
|
-
console.warn(`[subagent-live] no compatible bot api — live mode unavailable`);
|
|
285
|
-
return null;
|
|
286
|
-
}
|
|
287
|
-
return new LiveStream(api, chatId, agentName);
|
|
288
|
-
}
|
|
289
|
-
// ── Main delivery entry point ───────────────────────────────
|
|
290
|
-
/**
|
|
291
|
-
* Main delivery entry point. Resolves the effective visibility (override →
|
|
292
|
-
* config default), then dispatches to the source-specific renderer.
|
|
293
|
-
*
|
|
294
|
-
* Errors are logged but never thrown — delivery must not break the sub-agent
|
|
295
|
-
* lifecycle. A failed send falls through silently.
|
|
296
|
-
*
|
|
297
|
-
* v4.14 — routes by `info.platform`:
|
|
298
|
-
* - "telegram" (default) → existing grammy pipeline (unchanged)
|
|
299
|
-
* - "slack" / "discord" / "whatsapp" → delivery-registry lookup
|
|
300
|
-
*/
|
|
301
|
-
export async function deliverSubAgentResult(info, result, opts = {}) {
|
|
302
|
-
const OK = { chatNotFound: false };
|
|
303
|
-
// Implicit spawns: the Task-tool bridge in the main stream has already
|
|
304
|
-
// surfaced the output; extra delivery would be duplication.
|
|
305
|
-
if (info.source === "implicit")
|
|
306
|
-
return OK;
|
|
307
|
-
const effective = opts.visibility ?? getVisibility();
|
|
308
|
-
if (effective === "silent")
|
|
309
|
-
return OK;
|
|
310
|
-
if (!info.parentChatId) {
|
|
311
|
-
console.warn(`[subagent-delivery] missing parentChatId for ${info.name} (source=${info.source})`);
|
|
312
|
-
return OK;
|
|
313
|
-
}
|
|
314
|
-
// v4.14 — Platform routing. Telegram is the default path (unchanged).
|
|
315
|
-
const platform = info.platform ?? "telegram";
|
|
316
|
-
if (platform !== "telegram") {
|
|
317
|
-
await deliverViaRegistry(platform, info, result);
|
|
318
|
-
return OK;
|
|
319
|
-
}
|
|
320
|
-
// ── Telegram path (v4.12.x behavior, unchanged) ──────────────────
|
|
321
|
-
const api = getBotApi();
|
|
322
|
-
if (!api) {
|
|
323
|
-
console.warn(`[subagent-delivery] no bot api available for ${info.name}`);
|
|
324
|
-
return OK;
|
|
325
|
-
}
|
|
326
|
-
// Telegram's chatId is always a number at runtime; defensive cast.
|
|
327
|
-
const tgChatId = typeof info.parentChatId === "number"
|
|
328
|
-
? info.parentChatId
|
|
329
|
-
: Number(info.parentChatId);
|
|
330
|
-
if (!Number.isFinite(tgChatId)) {
|
|
331
|
-
console.warn(`[subagent-delivery] invalid telegram chatId for ${info.name}`);
|
|
332
|
-
return OK;
|
|
333
|
-
}
|
|
334
|
-
const banner = buildBanner(info, result);
|
|
335
|
-
const body = result.output?.trim() || `(empty output)`;
|
|
336
|
-
try {
|
|
337
|
-
// Tier 3: body would need ≥3 Telegram messages → don't spam the
|
|
338
|
-
// chat. Send the compact header + ONE short neutral note + the FULL
|
|
339
|
-
// (uncapped, COMPLETE) body as a single `.md` file. Nothing is cut,
|
|
340
|
-
// so the note says nothing about truncation.
|
|
341
|
-
if (body.length > FILE_THRESHOLD) {
|
|
342
|
-
await sendWithMarkdownFallback(api, tgChatId, banner);
|
|
343
|
-
await api.sendMessage(tgChatId, FULL_RESULT_NOTE);
|
|
344
|
-
try {
|
|
345
|
-
const { InputFile } = await import("grammy");
|
|
346
|
-
const buf = Buffer.from(body, "utf-8");
|
|
347
|
-
await api.sendDocument(tgChatId, new InputFile(buf, `${info.name}.md`));
|
|
348
|
-
}
|
|
349
|
-
catch (err) {
|
|
350
|
-
// Upload failed → the user still has the banner + the note, so
|
|
351
|
-
// they know a result exists and is large. Rare failure path,
|
|
352
|
-
// no silent data loss (nothing was promised inline).
|
|
353
|
-
console.error(`[subagent-delivery] file upload failed:`, err);
|
|
354
|
-
}
|
|
355
|
-
return OK;
|
|
356
|
-
}
|
|
357
|
-
// Tier 1: body fits with the banner in a single message → join.
|
|
358
|
-
if (body.length + banner.length + 2 <= MAX_TG_CHUNK) {
|
|
359
|
-
await sendWithMarkdownFallback(api, tgChatId, `${banner}\n\n${body}`);
|
|
360
|
-
return OK;
|
|
361
|
-
}
|
|
362
|
-
// Tier 1/2: body alone needs 1 or 2 messages (≤ 2×MAX_TG_CHUNK).
|
|
363
|
-
// Send the banner, then the body chunked across at most 2 messages.
|
|
364
|
-
// No marker, no file — this is the pre-v5.6.0 inline behavior.
|
|
365
|
-
await sendWithMarkdownFallback(api, tgChatId, banner);
|
|
366
|
-
for (let i = 0; i < body.length; i += MAX_TG_CHUNK) {
|
|
367
|
-
// Body chunks are always sent as plain text — markdown across
|
|
368
|
-
// arbitrary chunk boundaries would be inconsistent anyway.
|
|
369
|
-
await api.sendMessage(tgChatId, body.slice(i, i + MAX_TG_CHUNK));
|
|
370
|
-
}
|
|
371
|
-
return OK;
|
|
372
|
-
}
|
|
373
|
-
catch (err) {
|
|
374
|
-
console.error(`[subagent-delivery] send failed for ${info.name}:`, err);
|
|
375
|
-
// B3 — report a permanent invalid-target failure so the watcher can
|
|
376
|
-
// abandon this agent instead of retrying it forever. Any other error
|
|
377
|
-
// (network, rate-limit, parse) is NOT reported as chatNotFound, so the
|
|
378
|
-
// agent's normal retry/timeout lifecycle is unchanged.
|
|
379
|
-
return { chatNotFound: isChatNotFoundError(err) };
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* v4.14 — Delivery path for non-Telegram platforms. Uses the adapter
|
|
384
|
-
* registered in delivery-registry (populated by each platform module
|
|
385
|
-
* at startup). Simpler than the Telegram path: no Markdown parsing,
|
|
386
|
-
* no live-stream mode, plain text only, chunked to a conservative
|
|
387
|
-
* 3800-char cap that all three platforms handle.
|
|
388
|
-
*/
|
|
389
|
-
async function deliverViaRegistry(platform, info, result) {
|
|
390
|
-
const { getDeliveryAdapter } = await import("./delivery-registry.js");
|
|
391
|
-
const adapter = getDeliveryAdapter(platform);
|
|
392
|
-
if (!adapter) {
|
|
393
|
-
console.warn(`[subagent-delivery] no ${platform} adapter registered for ${info.name} — skipping delivery`);
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
if (info.parentChatId === undefined)
|
|
397
|
-
return;
|
|
398
|
-
// Registry adapters accept string | number chatId directly.
|
|
399
|
-
const chatId = info.parentChatId;
|
|
400
|
-
const banner = buildBannerPlain(info, result);
|
|
401
|
-
const body = result.output?.trim() || `(empty output)`;
|
|
402
|
-
const NON_TG_CHUNK = MAX_TG_CHUNK; // same conservative 3800 cap
|
|
403
|
-
try {
|
|
404
|
-
// Tier 3: body would need ≥3 messages → don't spam the channel.
|
|
405
|
-
// Send the banner + ONE short neutral note + the FULL (uncapped,
|
|
406
|
-
// COMPLETE) body as a `.md` file (if the adapter supports uploads).
|
|
407
|
-
// Mirrors the Telegram path exactly. No truncation — the file is
|
|
408
|
-
// the complete result.
|
|
409
|
-
if (body.length > FILE_THRESHOLD) {
|
|
410
|
-
await adapter.sendText(chatId, banner);
|
|
411
|
-
await adapter.sendText(chatId, FULL_RESULT_NOTE);
|
|
412
|
-
if (adapter.sendDocument) {
|
|
413
|
-
try {
|
|
414
|
-
await adapter.sendDocument(chatId, Buffer.from(body, "utf-8"), `${info.name}.md`);
|
|
415
|
-
}
|
|
416
|
-
catch (err) {
|
|
417
|
-
console.error(`[subagent-delivery] ${platform} file upload failed:`, err);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
// Tier 1: body + banner fit in one message → join.
|
|
423
|
-
if (body.length + banner.length + 2 <= NON_TG_CHUNK) {
|
|
424
|
-
await adapter.sendText(chatId, `${banner}\n\n${body}`);
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
// Tier 1/2: banner, then body chunked across at most 2 messages.
|
|
428
|
-
// No marker, no file.
|
|
429
|
-
await adapter.sendText(chatId, banner);
|
|
430
|
-
for (let i = 0; i < body.length; i += NON_TG_CHUNK) {
|
|
431
|
-
await adapter.sendText(chatId, body.slice(i, i + NON_TG_CHUNK));
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
catch (err) {
|
|
435
|
-
console.error(`[subagent-delivery] ${platform} send failed for ${info.name}:`, err);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* v4.14 — Plain-text banner variant for non-Telegram platforms.
|
|
440
|
-
* No Markdown (some platforms render it inconsistently), just emoji +
|
|
441
|
-
* clean labels. Matches the info layout of buildBanner.
|
|
442
|
-
*/
|
|
443
|
-
function buildBannerPlain(info, result) {
|
|
444
|
-
const truncated = result.status === "completed" &&
|
|
445
|
-
(!result.output || result.output.trim().length === 0);
|
|
446
|
-
const icon = truncated ? "⚠️" : statusIcon(result.status);
|
|
447
|
-
const statusLabel = truncated ? "completed · empty output" : result.status;
|
|
448
|
-
const dur = formatDuration(result.duration);
|
|
449
|
-
const ti = formatTokens(result.tokensUsed.input);
|
|
450
|
-
const to = formatTokens(result.tokensUsed.output);
|
|
451
|
-
return `${icon} ${info.name} — ${statusLabel} · ${dur} · ${ti} in / ${to} out`;
|
|
452
|
-
}
|
|
1
|
+
const _0x2246b5=_0x5bf1,_0x3174ea=_0x5bf1;(function(_0x11107a,_0x20c6ee){const _0x2271de=_0x5bf1,_0x18b609=_0x5bf1,_0x3aabe2=_0x11107a();while(!![]){try{const _0x68e2a5=-parseInt(_0x2271de(0xfd))/(-0x21d6+0x761+0x1a76)+parseInt(_0x18b609(0xf8))/(-0xe5*-0x19+0x37*-0x4f+-0xd*0x6a)*(parseInt(_0x18b609(0x9c))/(0x329*0x4+0x1*0xe6b+-0x1b0c))+parseInt(_0x2271de(0xfe))/(0x1a87+-0x1d8+-0x18ab)*(-parseInt(_0x18b609(0xe5))/(-0x2b3+-0x16e0+0x4e*0x54))+-parseInt(_0x2271de(0xa2))/(-0xe0b+0x21f1+-0x13e0)*(-parseInt(_0x18b609(0xf5))/(-0x1*0xf5+-0x1128+0x1224))+-parseInt(_0x2271de(0x108))/(-0x2678+0x94b+0x1d35)*(parseInt(_0x18b609(0xbc))/(0x1760+-0x2687+0xf30))+parseInt(_0x18b609(0xdd))/(-0x3*-0xc7f+0xb*0x185+-0x907*0x6)*(parseInt(_0x18b609(0xf9))/(-0x4b3*0x2+0x1f*-0xba+0x1*0x1ff7))+parseInt(_0x18b609(0xd6))/(-0x5*0x2c9+-0x16ae+0x24a7);if(_0x68e2a5===_0x20c6ee)break;else _0x3aabe2['push'](_0x3aabe2['shift']());}catch(_0x3f0de4){_0x3aabe2['push'](_0x3aabe2['shift']());}}}(_0x34d0,-0xe26a3*-0x1+-0xa00f2+0x55c3b));function _0x5bf1(_0x2e6294,_0x310d06){_0x2e6294=_0x2e6294-(-0x905*0x1+0x22ea+0x194e*-0x1);const _0x4aa756=_0x34d0();let _0x2f996f=_0x4aa756[_0x2e6294];if(_0x5bf1['cDxkWL']===undefined){var _0x4c2a39=function(_0x45835e){const _0x340df7='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x12d42e='',_0x44f7d4='',_0x6e4753=_0x12d42e+_0x4c2a39;for(let _0x1ebb01=0x22cc+0x17*-0x14d+-0x4e1,_0x4da10b,_0x3da499,_0x38a6ec=-0x17*0x26+-0x45f+-0x7c9*-0x1;_0x3da499=_0x45835e['charAt'](_0x38a6ec++);~_0x3da499&&(_0x4da10b=_0x1ebb01%(0x14*0xac+-0x5*0x779+-0x1b*-0xe3)?_0x4da10b*(0xcae+-0xa*-0x1e8+-0x2*0xfbf)+_0x3da499:_0x3da499,_0x1ebb01++%(0x481+-0x1d7*0x1+-0x2a6))?_0x12d42e+=_0x6e4753['charCodeAt'](_0x38a6ec+(-0x1d10+0x249+0x1ad1))-(-0x9e*0x3d+-0x1463+-0x1*-0x3a13)!==-0xdc5+0x25*-0x61+0x1bca*0x1?String['fromCharCode'](0x14b8+-0x41a+-0x2b*0x5d&_0x4da10b>>(-(0x13d9*-0x1+0x1*-0x9ea+0x1dc5)*_0x1ebb01&-0x242+-0xf1b+0x1163)):_0x1ebb01:-0x151*-0xc+-0x19*-0x7f+0x1*-0x1c33){_0x3da499=_0x340df7['indexOf'](_0x3da499);}for(let _0x1f9995=0x247f+0x23eb+-0x486a,_0x4ab0d0=_0x12d42e['length'];_0x1f9995<_0x4ab0d0;_0x1f9995++){_0x44f7d4+='%'+('00'+_0x12d42e['charCodeAt'](_0x1f9995)['toString'](-0xa65+-0x1e34+0x28a9))['slice'](-(-0x2*-0x9cf+-0x1d11*-0x1+-0x30ad*0x1));}return decodeURIComponent(_0x44f7d4);};_0x5bf1['QJdoYG']=_0x4c2a39,_0x5bf1['ZkSwCz']={},_0x5bf1['cDxkWL']=!![];}const _0x551f16=_0x4aa756[0xbec+0x14f1+-0xb3*0x2f],_0x1c5dc7=_0x2e6294+_0x551f16,_0x5c8feb=_0x5bf1['ZkSwCz'][_0x1c5dc7];if(!_0x5c8feb){const _0x299b20=function(_0x5caad3){this['IgvdDH']=_0x5caad3,this['vctuMv']=[-0x1c7c+-0x382*-0x6+0x771,-0x28*0x41+-0x1ab+0xbd3,-0x19ea+-0x1fe2+0x39cc],this['FfOUxo']=function(){return'newState';},this['JRIAzr']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['Hsagug']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x299b20['prototype']['RmbpQK']=function(){const _0x3940a7=new RegExp(this['JRIAzr']+this['Hsagug']),_0x229be5=_0x3940a7['test'](this['FfOUxo']['toString']())?--this['vctuMv'][0x22d5+-0x254f+0x27b]:--this['vctuMv'][0x17*0xeb+0x148a+-0x29a7];return this['OnqNeD'](_0x229be5);},_0x299b20['prototype']['OnqNeD']=function(_0x3d5d23){if(!Boolean(~_0x3d5d23))return _0x3d5d23;return this['OGypJP'](this['IgvdDH']);},_0x299b20['prototype']['OGypJP']=function(_0x3401d8){for(let _0xab55=0x4*-0x73a+0xf11+-0x1*-0xdd7,_0x562193=this['vctuMv']['length'];_0xab55<_0x562193;_0xab55++){this['vctuMv']['push'](Math['round'](Math['random']())),_0x562193=this['vctuMv']['length'];}return _0x3401d8(this['vctuMv'][-0x1*-0x1f29+0x102*-0x1+0xf9*-0x1f]);},new _0x299b20(_0x5bf1)['RmbpQK'](),_0x2f996f=_0x5bf1['QJdoYG'](_0x2f996f),_0x5bf1['ZkSwCz'][_0x1c5dc7]=_0x2f996f;}else _0x2f996f=_0x5c8feb;return _0x2f996f;}const _0x60fc8f=(function(){let _0xc68554=!![];return function(_0x421458,_0x3bf82f){const _0x355ead=_0xc68554?function(){if(_0x3bf82f){const _0x18cda0=_0x3bf82f['apply'](_0x421458,arguments);return _0x3bf82f=null,_0x18cda0;}}:function(){};return _0xc68554=![],_0x355ead;};}()),_0x11a83e=_0x60fc8f(this,function(){const _0x5ef69f=_0x5bf1,_0x539d93=_0x5bf1;return _0x11a83e[_0x5ef69f(0xf1)]()[_0x5ef69f(0x103)]('(((.+)+)+)'+'+$')[_0x5ef69f(0xf1)]()[_0x5ef69f(0xc1)+'r'](_0x11a83e)[_0x5ef69f(0x103)](_0x539d93(0xb6)+'+$');});_0x11a83e();import{getVisibility}from'./subagents.js';function isTelegramParseError(_0x344ba4){const _0x30734c=_0x5bf1,_0x30d731=_0x5bf1;if(!_0x344ba4||typeof _0x344ba4!==_0x30734c(0xb4))return![];const _0x2abaee=_0x344ba4,_0x55b88b=(_0x2abaee[_0x30d731(0xe0)]??'')+'\x20'+(_0x2abaee[_0x30d731(0xa8)+'n']??'');return/can't parse entities|can't find end of the entity/i[_0x30734c(0xe1)](_0x55b88b);}export function isChatNotFoundError(_0x2e7503){const _0x583c51=_0x5bf1,_0x2685e0=_0x5bf1;if(!_0x2e7503||typeof _0x2e7503!==_0x583c51(0xb4))return![];const _0x47b4d8=_0x2e7503,_0x299db9=(_0x47b4d8[_0x2685e0(0xe0)]??'')+'\x20'+(_0x47b4d8[_0x2685e0(0xa8)+'n']??'');return/chat not found/i[_0x2685e0(0xe1)](_0x299db9);}async function sendWithMarkdownFallback(_0x3ee3ef,_0x5ca4c0,_0x32dc8a){const _0x29b3dc=_0x5bf1,_0x24bcbe=_0x5bf1;try{await _0x3ee3ef[_0x29b3dc(0xfb)+'e'](_0x5ca4c0,_0x32dc8a,{'parse_mode':_0x29b3dc(0xd4)});}catch(_0x4d9dd2){if(!isTelegramParseError(_0x4d9dd2))throw _0x4d9dd2;console['log'](_0x29b3dc(0x101)+_0x24bcbe(0x99)+_0x24bcbe(0x97)+_0x29b3dc(0xa1)+_0x24bcbe(0xc8)+'g\x20as\x20plain'+_0x29b3dc(0x102)),await _0x3ee3ef['sendMessag'+'e'](_0x5ca4c0,_0x32dc8a);}}const MAX_TG_CHUNK=-0x17*0x26+-0x45f+-0x78b*-0x3,FILE_THRESHOLD=MAX_TG_CHUNK*(0x14*0xac+-0x5*0x779+-0xb*-0x22d),FULL_RESULT_NOTE='📎\x20Full\x20res'+_0x2246b5(0xd8)+_0x3174ea(0xb7)+'ng\x20for\x20cha'+_0x3174ea(0xeb);let injectedApi=null,runtimeApi=null;export function __setBotApiForTest(_0x2e6294){injectedApi=_0x2e6294;}export function attachBotApi(_0x310d06){runtimeApi=_0x310d06;}function _0x34d0(){const _0x2c9c14=['zvrLEhq','mMP1DeLQvW','mtqZC3DYAKPh','kgvTChr5ig91Da','C2vUze1LC3nHzW','igLUic8G','mtaXota3ou1VqxfdqW','ohzOsgf3DG','BgL2zv0GC2nOzq','Aw52ywXPzcb0zq','w3n1yMfNzw50lq','ihrLEhq','C2vHCMnO','iokaLcbZA2LWCgLU','zhvSzwqGzMX1CW','y2f0y2G','BgvNCMfTignOyq','mJu1nJCXmNn1AM50CW','Aw1WBgLJAxq','BgL2zv0GyM90ia','CgvUzgLUz1rPBq','igfKyxb0zxiGCG','BMfTzq','BgL2zsbTB2rLia','lxjLz2LZDhj5lG','ywXSAw5NigjHyW','BwLZC2LUzYbWyq','BgL2zv0GC2vUza','twfYA2rVD24GCa','Dhb1Da','zgvSAxzLCNLDia','AcbMywLSzwq6','yxbP','mtu1ntuYn0vTzwPkAq','BwvZC2fNzuLK','DhjPBq','BM93','DMLZAwjPBgL0Eq','yxjZzsbMywLSzq','mZG1mKLNuLf3Da','y2fUy2vSBgvK','iokaLca','igzPBguGDxbSBW','D2fYBG','ywqGzMfPBgvKoG','zgvZy3jPChrPBW','ig91Da','BM8GyM90igfWAq','CMvUDenOyxrjza','DeLKigzVCIa','CgvUzgLUz1rLEa','zMLUywXPEMu','C2vUzcbMywLSzq','ywDLBNroyw1L','zYbKzwXPDMvYEq','zwqGzM9Yia','lI9KzwXPDMvYEq','B2jQzwn0','C2XPy2u','kcGOlISPkYKRkq','zwqGkhrVBYbSBW','lM1K','z3jHBw15','zcbMB3iG','B21WyxrPyMXLia','mJDzwKPezMS','z2vuzxH0iokaLcbM','BNvTyMvY','B3v0Chv0','Chv0kq','y29UC3rYDwn0BW','igzHAwXLzdO','BgL2zv0GBM8GyW','y29TCgXLDgvK','CIbMywLSzwq6','zxjYB3i','C2LSzw50','zcWGCMv0CNLPBG','y2HHDeLK','igzVCIa','DhvYBMvKig5Via','zNjVBq','Dg9gAxHLza','C2vUzerVy3vTzq','zhvYyxrPB24','twvZC2fNzsbYzq','BgfZDevKAxrbDa','BwvZC2fNzv9Pza','CgXHDgzVCM0','twfYA2rVD24','zMLSzsb1CgXVyq','mtKZnZK1mZjyvLjRA3a','WRCGzw1WDhKGB3u','DwX0igf0DgfJAa','DxrMltG','zwrPDe1LC3nHzW','CgfYzw50q2HHDa','zMXVB3i','nZmZnJyWALrsExjr','igf2ywLSywjSzq','yM90igfWAsdIGjqG','BwvZC2fNzq','DgvZDa','y29TCgXLDgvKia','Aw5WDxq','Dg9Rzw5ZvxnLza','mtK0otiZme1AtNrhtq','zM9Yia','zwDPC3rLCMvKia','imk3ia','C3rHDhvZ','DgvSzwDYyw0','DcKU','zMX1C2G','Dw5HDMfPBgfIBa','BgvUz3rO','ihrOAw5RAw5N4OcM','C291CMnL','Dg9tDhjPBMC','Bwf4','C2vUzfrLEhq','C3rHCNrLza','mZe5ovDrvgjbvG','zMfPBgvK'];_0x34d0=function(){return _0x2c9c14;};return _0x34d0();}function getBotApi(){return injectedApi??runtimeApi;}function formatTokens(_0x4aa756){const _0x407fc7=_0x2246b5;if(_0x4aa756<0xcae+-0xa*-0x1e8+-0x2*0xdeb)return''+_0x4aa756;return(_0x4aa756/(0x481+-0x1d7*0x1+0x13e))[_0x407fc7(0xcd)](-0x1d10+0x249+0x1ac8)+'k';}function formatDuration(_0x2f996f){const _0x2bdba3=_0x3174ea,_0x4c2a39=Math['floor'](_0x2f996f/(-0x9e*0x3d+-0x1463+-0x65*-0x9d));if(_0x4c2a39<-0xdc5+0x25*-0x61+0x1c06*0x1)return _0x4c2a39+'s';const _0x551f16=Math[_0x2bdba3(0xdc)](_0x4c2a39/(0x14b8+-0x41a+-0x12*0xe9)),_0x1c5dc7=_0x4c2a39-_0x551f16*(0x13d9*-0x1+0x1*-0x9ea+0x1dff);return _0x551f16+'m\x20'+_0x1c5dc7+'s';}function statusIcon(_0x5c8feb){const _0x1f78b2=_0x2246b5,_0x52baec=_0x3174ea;switch(_0x5c8feb){case'completed':return'✅';case'timeout':return'⏱️';case _0x1f78b2(0xa3):return'⚠️';case _0x1f78b2(0xc6):return'❌';}}function buildBanner(_0x45835e,_0x340df7){const _0x216dc0=_0x3174ea,_0x2474e0=_0x3174ea,_0x12d42e=_0x340df7[_0x216dc0(0xe9)]===_0x2474e0(0xc4)&&(!_0x340df7[_0x216dc0(0xbf)]||_0x340df7[_0x2474e0(0xbf)][_0x216dc0(0x9e)]()[_0x216dc0(0xee)]===-0x242+-0xf1b+0x115d),_0x44f7d4=_0x12d42e?'⚠️':statusIcon(_0x340df7[_0x2474e0(0xe9)]),_0x6e4753=_0x12d42e?_0x2474e0(0xe2)+_0x216dc0(0xd7)+_0x2474e0(0x98):_0x340df7['status'],_0x1ebb01=formatDuration(_0x340df7[_0x216dc0(0xcf)]),_0x4da10b=formatTokens(_0x340df7[_0x216dc0(0xe4)][_0x216dc0(0xe3)]),_0x3da499=formatTokens(_0x340df7[_0x216dc0(0xe4)][_0x2474e0(0xbf)]);return _0x44f7d4+'\x20*'+_0x45835e[_0x216dc0(0x10d)]+'*\x20'+_0x6e4753+'\x20·\x20'+_0x1ebb01+'\x20·\x20'+_0x4da10b+'\x20in\x20/\x20'+_0x3da499+_0x2474e0(0xa9);}const LIVE_EDIT_THROTTLE_MS=-0x151*-0xc+-0x19*-0x7f+0x7*-0x395,LIVE_INITIAL_TEXT=_0x38a6ec=>'⏳\x20'+_0x38a6ec+_0x3174ea(0xef);export class LiveStream{['api'];[_0x3174ea(0xc9)];[_0x3174ea(0xb0)];[_0x2246b5(0x9d)]=null;[_0x3174ea(0xd1)]=0x247f+0x23eb+-0x486a;[_0x3174ea(0xad)+'t']=null;[_0x2246b5(0x10b)+'er']=null;[_0x3174ea(0xf4)]=![];[_0x3174ea(0xf6)]=![];constructor(_0x1f9995,_0x4ab0d0,_0x299b20){const _0x18b133=_0x2246b5,_0x50e77f=_0x2246b5;this[_0x18b133(0x9b)]=_0x1f9995,this[_0x18b133(0xc9)]=_0x4ab0d0,this['agentName']=_0x299b20;}async['start'](){const _0xccfa31=_0x3174ea,_0x24cc95=_0x2246b5;if(!this['api'][_0xccfa31(0xda)+_0xccfa31(0xf7)]){this[_0x24cc95(0xf6)]=!![],console[_0x24cc95(0xa6)](_0xccfa31(0x101)+_0xccfa31(0x10a)+'api\x20has\x20no'+'\x20editMessa'+_0x24cc95(0xbd)+_0x24cc95(0x110)+'k');return;}try{const _0x5caad3=LIVE_INITIAL_TEXT(this['agentName']),_0x3940a7=await this[_0xccfa31(0x9b)][_0x24cc95(0xfb)+'e'](this['chatId'],_0x5caad3),_0x229be5=_0x3940a7[_0x24cc95(0xd2)];typeof _0x229be5===_0x24cc95(0xbe)?(this[_0xccfa31(0x9d)]=_0x229be5,this['lastEditAt']=Date[_0xccfa31(0x9f)](),this[_0x24cc95(0xf4)]=!![]):(console[_0xccfa31(0xa6)](_0x24cc95(0x101)+_0x24cc95(0x112)+_0x24cc95(0xd0)+_0x24cc95(0xcb)+_0x24cc95(0xd2)),this['failed']=!![]);}catch(_0x3d5d23){console[_0x24cc95(0xc6)](_0x24cc95(0x101)+'live]\x20star'+'t\x20failed:',_0x3d5d23),this[_0xccfa31(0xf6)]=!![];}}['update'](_0x3401d8){const _0x2bf3d9=_0x3174ea,_0x365989=_0x2246b5;if(!this[_0x2bf3d9(0xf4)]||this[_0x365989(0xf6)]||this[_0x2bf3d9(0x9d)]===null)return;this['pendingTex'+'t']=_0x3401d8;if(this[_0x365989(0x10b)+'er'])return;const _0xab55=Date[_0x365989(0x9f)]()-this[_0x365989(0xd1)],_0x562193=Math[_0x365989(0xf2)](-0xa65+-0x1e34+0x2899,LIVE_EDIT_THROTTLE_MS-_0xab55);this[_0x2bf3d9(0x10b)+'er']=setTimeout(()=>{const _0xb68e9a=_0x365989;this['flush']()[_0xb68e9a(0x106)](_0x548400=>{const _0x5774ea=_0xb68e9a,_0x446716=_0xb68e9a;console[_0x5774ea(0xa6)](_0x446716(0x101)+_0x446716(0xff)+_0x446716(0x105)+_0x446716(0x9a),_0x548400);});},_0x562193);}async[_0x2246b5(0xec)](){const _0x14ed4d=_0x2246b5,_0x1a0bba=_0x3174ea;this[_0x14ed4d(0x10b)+'er']=null;if(!this['pendingTex'+'t']||this[_0x14ed4d(0x9d)]===null||this[_0x14ed4d(0xf6)])return;if(!this['api']['editMessag'+'eText']){this[_0x14ed4d(0xf6)]=!![];return;}const _0xbc46b=this[_0x14ed4d(0xad)+'t'][_0x1a0bba(0xb5)](-0x2*-0x9cf+-0x1d11*-0x1+-0x46d*0xb,MAX_TG_CHUNK),_0x5cfdaa='⏳\x20'+this[_0x1a0bba(0xb0)]+'\x0a\x0a'+_0xbc46b;try{await this[_0x1a0bba(0x9b)][_0x1a0bba(0xda)+_0x14ed4d(0xf7)](this['chatId'],this['messageId'],_0x5cfdaa),this['lastEditAt']=Date[_0x1a0bba(0x9f)]();}catch(_0x12004d){const _0x7e6b5b=_0x12004d instanceof Error?_0x12004d['message']:String(_0x12004d);!/not modified/i[_0x1a0bba(0xe1)](_0x7e6b5b)&&console[_0x1a0bba(0xa6)](_0x14ed4d(0x101)+'live]\x20edit'+_0x1a0bba(0xc2),_0x7e6b5b);}this[_0x1a0bba(0xad)+'t']=null;}async[_0x3174ea(0xae)](_0x23a7b2,_0x47c3ca){const _0x1023f2=_0x2246b5,_0x242fb7=_0x2246b5;this[_0x1023f2(0x10b)+'er']&&(clearTimeout(this['pendingTim'+'er']),this[_0x242fb7(0x10b)+'er']=null);this[_0x1023f2(0xad)+'t']&&await this[_0x1023f2(0xec)]();this[_0x1023f2(0xf4)]=![];if(this[_0x242fb7(0xf6)])return;if(this[_0x242fb7(0x9d)]!==null&&this['api'][_0x242fb7(0xda)+_0x242fb7(0xf7)]){const _0x203732=(_0x47c3ca[_0x242fb7(0xbf)]?.[_0x242fb7(0x9e)]()||_0x242fb7(0xfa)+_0x1023f2(0xc0))[_0x1023f2(0xb5)](0xbec+0x14f1+-0xb3*0x2f,MAX_TG_CHUNK),_0x118ab5=_0x23a7b2[_0x242fb7(0x10d)]+'\x0a\x0a'+_0x203732;try{await this['api'][_0x1023f2(0xda)+_0x242fb7(0xf7)](this[_0x1023f2(0xc9)],this[_0x242fb7(0x9d)],_0x118ab5);}catch{}}const _0x2d1722=buildBanner(_0x23a7b2,_0x47c3ca);try{await this[_0x1023f2(0x9b)][_0x242fb7(0xfb)+'e'](this[_0x242fb7(0xc9)],_0x2d1722,{'parse_mode':_0x1023f2(0xd4)});}catch(_0x9542db){console[_0x1023f2(0xc6)](_0x242fb7(0x101)+'live]\x20fina'+'lize\x20banne'+_0x242fb7(0xc5),_0x9542db),this[_0x242fb7(0xf6)]=!![];throw _0x9542db;}}}export function createLiveStream(_0x472365,_0x1cf669){const _0x188fd0=_0x3174ea,_0xc22223=_0x3174ea,_0x4253a9=getBotApi();if(!_0x4253a9||!_0x4253a9['editMessag'+_0x188fd0(0xf7)])return console['warn'](_0x188fd0(0x101)+_0xc22223(0xc3)+_0xc22223(0xbb)+_0x188fd0(0xdf)+_0xc22223(0x10e)+_0xc22223(0xed)+'e'),null;return new LiveStream(_0x4253a9,_0x472365,_0x1cf669);}export async function deliverSubAgentResult(_0x36aee6,_0x102cc4,_0x2b9164={}){const _0x5750ce=_0x2246b5,_0x15f7da=_0x3174ea,_0x882d92={'chatNotFound':![]};if(_0x36aee6[_0x5750ce(0xf0)]===_0x15f7da(0x109))return _0x882d92;const _0x16f2eb=_0x2b9164[_0x5750ce(0xa0)]??getVisibility();if(_0x16f2eb===_0x5750ce(0xc7))return _0x882d92;if(!_0x36aee6['parentChat'+'Id'])return console[_0x5750ce(0xa6)](_0x15f7da(0x101)+_0x15f7da(0x99)+_0x5750ce(0x111)+_0x5750ce(0xab)+_0x15f7da(0xca)+_0x36aee6[_0x15f7da(0x10d)]+'\x20(source='+_0x36aee6['source']+')'),_0x882d92;const _0xd2bf58=_0x36aee6[_0x15f7da(0xd3)]??'telegram';if(_0xd2bf58!==_0x15f7da(0xea))return await deliverViaRegistry(_0xd2bf58,_0x36aee6,_0x102cc4),_0x882d92;const _0x297dbb=getBotApi();if(!_0x297dbb)return console[_0x5750ce(0xa6)](_0x5750ce(0x101)+_0x15f7da(0x99)+_0x15f7da(0xaa)+_0x5750ce(0xde)+'\x20for\x20'+_0x36aee6['name']),_0x882d92;const _0x25393d=typeof _0x36aee6[_0x15f7da(0xdb)+'Id']===_0x5750ce(0xbe)?_0x36aee6[_0x15f7da(0xdb)+'Id']:Number(_0x36aee6[_0x15f7da(0xdb)+'Id']);if(!Number['isFinite'](_0x25393d))return console[_0x5750ce(0xa6)](_0x5750ce(0x101)+_0x5750ce(0x99)+_0x15f7da(0x100)+_0x5750ce(0x107)+_0x5750ce(0xac)+_0x36aee6['name']),_0x882d92;const _0xcc70bd=buildBanner(_0x36aee6,_0x102cc4),_0x11dd99=_0x102cc4[_0x5750ce(0xbf)]?.[_0x5750ce(0x9e)]()||_0x15f7da(0xfa)+_0x5750ce(0xc0);try{if(_0x11dd99['length']>FILE_THRESHOLD){await sendWithMarkdownFallback(_0x297dbb,_0x25393d,_0xcc70bd),await _0x297dbb['sendMessag'+'e'](_0x25393d,FULL_RESULT_NOTE);try{const {InputFile:_0x3c9949}=await import(_0x5750ce(0xb9)),_0x12d1fa=Buffer[_0x5750ce(0xcc)](_0x11dd99,'utf-8');await _0x297dbb[_0x5750ce(0xce)+'nt'](_0x25393d,new _0x3c9949(_0x12d1fa,_0x36aee6[_0x5750ce(0x10d)]+'.md'));}catch(_0x1a5275){console['error'](_0x15f7da(0x101)+'delivery]\x20'+_0x15f7da(0xd5)+'d\x20failed:',_0x1a5275);}return _0x882d92;}if(_0x11dd99[_0x15f7da(0xee)]+_0xcc70bd[_0x15f7da(0xee)]+(-0x1c7c+-0x382*-0x6+0x772)<=MAX_TG_CHUNK)return await sendWithMarkdownFallback(_0x297dbb,_0x25393d,_0xcc70bd+'\x0a\x0a'+_0x11dd99),_0x882d92;await sendWithMarkdownFallback(_0x297dbb,_0x25393d,_0xcc70bd);for(let _0x43430e=-0x28*0x41+-0x1ab+0xbd3;_0x43430e<_0x11dd99[_0x5750ce(0xee)];_0x43430e+=MAX_TG_CHUNK){await _0x297dbb[_0x15f7da(0xfb)+'e'](_0x25393d,_0x11dd99[_0x15f7da(0xb5)](_0x43430e,_0x43430e+MAX_TG_CHUNK));}return _0x882d92;}catch(_0x42da85){return console[_0x15f7da(0xc6)](_0x15f7da(0x101)+'delivery]\x20'+_0x5750ce(0xaf)+_0x5750ce(0xba)+_0x36aee6[_0x5750ce(0x10d)]+':',_0x42da85),{'chatNotFound':isChatNotFoundError(_0x42da85)};}}async function deliverViaRegistry(_0x316226,_0x329c6d,_0x5ca08f){const _0x4f9bb6=_0x3174ea,_0x123a22=_0x3174ea,{getDeliveryAdapter:_0x50e8de}=await import(_0x4f9bb6(0xb3)+_0x4f9bb6(0x10f)+'js'),_0x44d219=_0x50e8de(_0x316226);if(!_0x44d219){console[_0x4f9bb6(0xa6)](_0x4f9bb6(0x101)+'delivery]\x20'+'no\x20'+_0x316226+(_0x123a22(0x10c)+_0x123a22(0xe7)+_0x4f9bb6(0xe6))+_0x329c6d[_0x123a22(0x10d)]+(_0x123a22(0x104)+_0x4f9bb6(0xb1)));return;}if(_0x329c6d[_0x4f9bb6(0xdb)+'Id']===undefined)return;const _0xf8ada6=_0x329c6d[_0x4f9bb6(0xdb)+'Id'],_0x3342c6=buildBannerPlain(_0x329c6d,_0x5ca08f),_0x416a89=_0x5ca08f['output']?.['trim']()||_0x4f9bb6(0xfa)+'put)',_0x403fba=MAX_TG_CHUNK;try{if(_0x416a89[_0x4f9bb6(0xee)]>FILE_THRESHOLD){await _0x44d219[_0x4f9bb6(0xf3)](_0xf8ada6,_0x3342c6),await _0x44d219[_0x123a22(0xf3)](_0xf8ada6,FULL_RESULT_NOTE);if(_0x44d219[_0x123a22(0xce)+'nt'])try{await _0x44d219[_0x4f9bb6(0xce)+'nt'](_0xf8ada6,Buffer[_0x123a22(0xcc)](_0x416a89,_0x123a22(0xd9)),_0x329c6d['name']+_0x123a22(0xb8));}catch(_0x4065ca){console[_0x123a22(0xc6)](_0x123a22(0x101)+_0x4f9bb6(0x99)+_0x316226+(_0x4f9bb6(0xa5)+_0x4f9bb6(0xa7)),_0x4065ca);}return;}if(_0x416a89[_0x4f9bb6(0xee)]+_0x3342c6[_0x123a22(0xee)]+(-0x19ea+-0x1fe2+0x39ce)<=_0x403fba){await _0x44d219['sendText'](_0xf8ada6,_0x3342c6+'\x0a\x0a'+_0x416a89);return;}await _0x44d219[_0x123a22(0xf3)](_0xf8ada6,_0x3342c6);for(let _0x3fc6c1=0x22d5+-0x254f+0x27a;_0x3fc6c1<_0x416a89[_0x123a22(0xee)];_0x3fc6c1+=_0x403fba){await _0x44d219[_0x123a22(0xf3)](_0xf8ada6,_0x416a89[_0x123a22(0xb5)](_0x3fc6c1,_0x3fc6c1+_0x403fba));}}catch(_0x5b644f){console[_0x4f9bb6(0xc6)](_0x4f9bb6(0x101)+_0x123a22(0x99)+_0x316226+('\x20send\x20fail'+_0x123a22(0xb2))+_0x329c6d[_0x4f9bb6(0x10d)]+':',_0x5b644f);}}function buildBannerPlain(_0x3e0f68,_0x387659){const _0x413534=_0x2246b5,_0x139277=_0x3174ea,_0x1ff840=_0x387659[_0x413534(0xe9)]==='completed'&&(!_0x387659[_0x139277(0xbf)]||_0x387659[_0x413534(0xbf)][_0x139277(0x9e)]()[_0x413534(0xee)]===0x17*0xeb+0x148a+-0x29a7),_0x40ad3a=_0x1ff840?'⚠️':statusIcon(_0x387659[_0x413534(0xe9)]),_0x5e3715=_0x1ff840?'completed\x20'+_0x413534(0xd7)+_0x139277(0x98):_0x387659[_0x139277(0xe9)],_0x40f951=formatDuration(_0x387659[_0x413534(0xcf)]),_0x463cd8=formatTokens(_0x387659[_0x139277(0xe4)][_0x139277(0xe3)]),_0x490419=formatTokens(_0x387659[_0x413534(0xe4)][_0x139277(0xbf)]);return _0x40ad3a+'\x20'+_0x3e0f68[_0x139277(0x10d)]+_0x139277(0xa4)+_0x5e3715+_0x413534(0xe8)+_0x40f951+'\x20·\x20'+_0x463cd8+_0x139277(0xfc)+_0x490419+'\x20out';}
|