@sleep2agi/agent-network 2.3.0-preview.6 → 2.3.0-preview.8
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/src/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function a0_0x1a4b(_0x5ed33c,_0x30db5b){_0x5ed33c=_0x5ed33c-0x1af;const _0x540cb8=a0_0x540c();let _0x1a4b8b=_0x540cb8[_0x5ed33c];return _0x1a4b8b;}function a0_0x540c(){const _0x3398ef=['token','application/json,\x20text/event-stream','url','3914220FIWCCn','send','/mcp','reply','normal','startsWith','sleep','11863380WleNBg','call','disconnected','task','autoConnect','content','heartbeatTimer','reconnectDelay','1545160KwkaFo','155352EoYLMU','resumeId','registered','slice','6095826qgqwrY','now','completed','toString','getReader','1593675CrzaxG','SSE\x20connected','Authorization','running','sseAbort','log','356WNFEnM','match','name','/events/','heartbeatInterval','processInbox','send_reply','abort','pop','message','offline','connect','AbortError','new_message','4924LlUXBE','text','2.0','emit','report_status','broadcast','sdk','type','status','min','error','get_all_status','Bearer\x20','cwd','sdk-','read','idle','connected','catch','agent','connectSSE','4lWDeOd','alias','parse','new_task','231oYXYZH','application/json','SSE\x20reconnecting\x20in\x20','text/event-stream','result','signal','stringify'];a0_0x540c=function(){return _0x3398ef;};return a0_0x540c();}const a0_0x999825=a0_0x1a4b;(function(_0x4c66d1,_0x418324){const _0x1d1d05=a0_0x1a4b,_0xd91cc0=_0x4c66d1();while(!![]){try{const _0x1f6b79=-parseInt(_0x1d1d05(0x1db))/0x1*(parseInt(_0x1d1d05(0x1cd))/0x2)+parseInt(_0x1d1d05(0x1c7))/0x3+-parseInt(_0x1d1d05(0x1f0))/0x4*(-parseInt(_0x1d1d05(0x1bd))/0x5)+parseInt(_0x1d1d05(0x1fe))/0x6+parseInt(_0x1d1d05(0x1f4))/0x7*(-parseInt(_0x1d1d05(0x1be))/0x8)+-parseInt(_0x1d1d05(0x1c2))/0x9+parseInt(_0x1d1d05(0x1b5))/0xa;if(_0x1f6b79===_0x418324)break;else _0xd91cc0['push'](_0xd91cc0['shift']());}catch(_0x32d0bb){_0xd91cc0['push'](_0xd91cc0['shift']());}}}(a0_0x540c,0x76400));import{EventEmitter as a0_0x5183e4}from'events';import{hostname as a0_0x40be42}from'os';class T extends a0_0x5183e4{[a0_0x999825(0x1fd)];[a0_0x999825(0x1f1)];['token'];[a0_0x999825(0x1ee)];[a0_0x999825(0x1bf)];[a0_0x999825(0x1d1)];[a0_0x999825(0x1bc)];[a0_0x999825(0x1bb)];[a0_0x999825(0x1cb)];[a0_0x999825(0x1ca)]=!0x1;constructor(_0x4f27da){const _0xac7ce3=a0_0x999825;super();if(this[_0xac7ce3(0x1fd)]=_0x4f27da[_0xac7ce3(0x1fd)]['replace'](/\/$/,''),this[_0xac7ce3(0x1f1)]=_0x4f27da['alias'],this['token']=_0x4f27da[_0xac7ce3(0x1fb)],this[_0xac7ce3(0x1ee)]=_0x4f27da[_0xac7ce3(0x1ee)]||_0xac7ce3(0x1e1),this[_0xac7ce3(0x1bf)]=_0xac7ce3(0x1e9)+_0x4f27da['alias']+'-'+Date[_0xac7ce3(0x1c3)]()[_0xac7ce3(0x1c5)](0x24),this[_0xac7ce3(0x1d1)]=_0x4f27da[_0xac7ce3(0x1d1)]??0x2bf20,this[_0xac7ce3(0x1bc)]=_0x4f27da[_0xac7ce3(0x1bc)]??0xbb8,_0x4f27da[_0xac7ce3(0x1b9)]!==!0x1)this[_0xac7ce3(0x1d8)]();}[a0_0x999825(0x1cc)](_0x9d2f4){const _0x25f00c=a0_0x999825;console[_0x25f00c(0x1cc)]('['+new Date()['toTimeString']()[_0x25f00c(0x1c1)](0x0,0x8)+']\x20[commhub:'+this[_0x25f00c(0x1f1)]+']\x20'+_0x9d2f4);}async[a0_0x999825(0x1b6)](_0x2d02b7,_0x5e23f1){const _0x582642=a0_0x999825;let _0x1f8b3d={'Content-Type':_0x582642(0x1f5),'Accept':_0x582642(0x1fc)};if(this[_0x582642(0x1fb)])_0x1f8b3d[_0x582642(0x1c9)]=_0x582642(0x1e7)+this[_0x582642(0x1fb)];let _0x13e135=await(await fetch(this[_0x582642(0x1fd)]+_0x582642(0x1b0),{'method':'POST','headers':_0x1f8b3d,'body':JSON[_0x582642(0x1fa)]({'jsonrpc':_0x582642(0x1dd),'id':Date[_0x582642(0x1c3)](),'method':'tools/call','params':{'name':_0x2d02b7,'arguments':_0x5e23f1}})}))[_0x582642(0x1dc)](),_0x38ecf4=_0x13e135[_0x582642(0x1ce)](/data: (.+)/),_0x23767f=_0x38ecf4?JSON[_0x582642(0x1f2)](_0x38ecf4[0x1]):JSON[_0x582642(0x1f2)](_0x13e135),_0x56f3dc=_0x23767f?.[_0x582642(0x1f8)]?.[_0x582642(0x1ba)]?.[0x0]?.['text'];return _0x56f3dc?JSON[_0x582642(0x1f2)](_0x56f3dc):_0x23767f;}async[a0_0x999825(0x1d8)](){const _0x183084=a0_0x999825;if(this[_0x183084(0x1ca)])return;this[_0x183084(0x1ca)]=!0x0,await this[_0x183084(0x1e3)](_0x183084(0x1eb)),this['log'](_0x183084(0x1c0)),this['heartbeatTimer']=setInterval(()=>{const _0x153a01=_0x183084;this[_0x153a01(0x1e3)](_0x153a01(0x1eb))['catch'](_0xf3a729=>this[_0x153a01(0x1cc)]('heartbeat\x20failed:\x20'+_0xf3a729[_0x153a01(0x1d6)]));},this[_0x183084(0x1d1)]),this[_0x183084(0x1ef)]();}async['disconnect'](){const _0x3cdf0b=a0_0x999825;if(this['running']=!0x1,this[_0x3cdf0b(0x1cb)]?.[_0x3cdf0b(0x1d4)](),this[_0x3cdf0b(0x1bb)])clearInterval(this[_0x3cdf0b(0x1bb)]);await this['status'](_0x3cdf0b(0x1d7))[_0x3cdf0b(0x1ed)](()=>{}),this['log'](_0x3cdf0b(0x1b7));}async[a0_0x999825(0x1af)](_0x3f7ba0,_0x566f3b,_0x3da99c=a0_0x999825(0x1b2)){const _0x241cdf=a0_0x999825;return this[_0x241cdf(0x1b6)]('send_task',{'alias':_0x3f7ba0,'task':_0x566f3b,'priority':_0x3da99c,'from_session':this[_0x241cdf(0x1f1)]});}async['message'](_0x13f328,_0x254f4e){const _0x1d713b=a0_0x999825;return this[_0x1d713b(0x1b6)]('send_message',{'alias':_0x13f328,'message':_0x254f4e,'from_session':this[_0x1d713b(0x1f1)]});}async[a0_0x999825(0x1b1)](_0xe7466a,_0x478922,_0x2f203e=a0_0x999825(0x1c4)){const _0x21f4a5=a0_0x999825;return this[_0x21f4a5(0x1b6)](_0x21f4a5(0x1d3),{'in_reply_to':_0xe7466a,'text':_0x478922,'status':_0x2f203e});}async['status'](_0x5c6444,_0x5095b1){const _0x449cc6=a0_0x999825;return this[_0x449cc6(0x1b6)](_0x449cc6(0x1df),{'resume_id':this[_0x449cc6(0x1bf)],'alias':this[_0x449cc6(0x1f1)],'status':_0x5c6444,'server':a0_0x40be42(),'hostname':a0_0x40be42(),'agent':this[_0x449cc6(0x1ee)],'project_dir':process[_0x449cc6(0x1e8)](),..._0x5095b1});}async['getAllStatus'](){const _0x1f1762=a0_0x999825;return this[_0x1f1762(0x1b6)](_0x1f1762(0x1e6),{});}async[a0_0x999825(0x1e0)](_0x581001,_0x5c146d){const _0x229538=a0_0x999825;return this['call'](_0x229538(0x1e0),{'message':_0x581001,'filter_server':_0x5c146d?.['server'],'filter_status':_0x5c146d?.[_0x229538(0x1e3)]});}async[a0_0x999825(0x1ef)](){const _0x468c96=a0_0x999825;let _0x243ca8=encodeURIComponent(this['alias']),_0x13ba31=this[_0x468c96(0x1fd)]+_0x468c96(0x1d0)+_0x243ca8,_0x320db5=this[_0x468c96(0x1bc)];while(this[_0x468c96(0x1ca)]){try{this['sseAbort']=new AbortController();let _0x5c46cb={'Accept':_0x468c96(0x1f7)};if(this['token'])_0x5c46cb[_0x468c96(0x1c9)]=_0x468c96(0x1e7)+this[_0x468c96(0x1fb)];let _0x2a4087=await fetch(_0x13ba31,{'headers':_0x5c46cb,'signal':this[_0x468c96(0x1cb)][_0x468c96(0x1f9)]});if(!_0x2a4087['ok']||!_0x2a4087['body']){this['log']('SSE\x20failed:\x20'+_0x2a4087[_0x468c96(0x1e3)]),await this[_0x468c96(0x1b4)](_0x320db5),_0x320db5=Math[_0x468c96(0x1e4)](_0x320db5*1.5,0xea60);continue;}_0x320db5=this[_0x468c96(0x1bc)];let _0x24dc80=_0x2a4087['body'][_0x468c96(0x1c6)](),_0x2e483c=new TextDecoder(),_0x1c1ce3='';while(this[_0x468c96(0x1ca)]){let {done:_0x20fc68,value:_0x1314c0}=await _0x24dc80[_0x468c96(0x1ea)]();if(_0x20fc68)break;_0x1c1ce3+=_0x2e483c['decode'](_0x1314c0,{'stream':!0x0});let _0x45d15e=_0x1c1ce3['split']('\x0a');_0x1c1ce3=_0x45d15e[_0x468c96(0x1d5)]()||'';for(let _0x234929 of _0x45d15e){if(!_0x234929[_0x468c96(0x1b3)]('data:\x20'))continue;try{let _0x37ea62=JSON[_0x468c96(0x1f2)](_0x234929[_0x468c96(0x1c1)](0x6));if(_0x37ea62[_0x468c96(0x1e2)]===_0x468c96(0x1ec)){this['log'](_0x468c96(0x1c8)),this[_0x468c96(0x1de)](_0x468c96(0x1ec));continue;}if(_0x37ea62['type']===_0x468c96(0x1f3)||_0x37ea62[_0x468c96(0x1e2)]===_0x468c96(0x1da)||_0x37ea62[_0x468c96(0x1e2)]==='broadcast')await this[_0x468c96(0x1d2)]();}catch{}}}}catch(_0x26936b){if(_0x26936b[_0x468c96(0x1cf)]===_0x468c96(0x1d9))break;this[_0x468c96(0x1de)](_0x468c96(0x1e5),_0x26936b),this[_0x468c96(0x1cc)]('SSE\x20error:\x20'+_0x26936b[_0x468c96(0x1d6)]);}if(this[_0x468c96(0x1ca)])this[_0x468c96(0x1de)](_0x468c96(0x1b7)),this[_0x468c96(0x1cc)](_0x468c96(0x1f6)+_0x320db5/0x3e8+'s...'),await this['sleep'](_0x320db5),_0x320db5=Math[_0x468c96(0x1e4)](_0x320db5*1.5,0xea60);}}async[a0_0x999825(0x1d2)](){const _0x578893=a0_0x999825;try{let _0x2392a8=(await this['call']('get_inbox',{'alias':this['alias'],'limit':0xa}))?.['messages']||[];for(let _0x4474fc of _0x2392a8)await this[_0x578893(0x1b6)]('ack_inbox',{'alias':this[_0x578893(0x1f1)],'message_id':_0x4474fc['id']}),this[_0x578893(0x1cc)]('←\x20'+_0x4474fc['from_session']+':\x20'+_0x4474fc[_0x578893(0x1ba)]['slice'](0x0,0x3c)),this[_0x578893(0x1de)](_0x578893(0x1b8),_0x4474fc),this['emit'](_0x578893(0x1d6),_0x4474fc);}catch(_0x1c4649){this[_0x578893(0x1cc)]('inbox\x20error:\x20'+_0x1c4649['message']);}}['sleep'](_0x5b8686){return new Promise(_0x304075=>setTimeout(_0x304075,_0x5b8686));}}var $=T;export{$ as default,T as CommHub};
|
|
@@ -17,6 +17,17 @@ export declare class FeishuAdapter implements IMAdapter {
|
|
|
17
17
|
/** Where to persist downloaded inbound media (M5c). */
|
|
18
18
|
private mediaDir;
|
|
19
19
|
private health_;
|
|
20
|
+
/**
|
|
21
|
+
* Snapshot of the current `access.allowFrom` list (from access.json).
|
|
22
|
+
* Used by the bridge's rate-limiter to exempt operator-vouched explicit
|
|
23
|
+
* sender ids from the DM flood limit (2026-06-29: Vincent's multi-turn
|
|
24
|
+
* heavy work was tripping the 3-msg/60s DM limit; explicit-listed
|
|
25
|
+
* users are already operator-trusted via the access whitelist, no
|
|
26
|
+
* need to also flood-limit them). Returns `[]` before `init()`. The
|
|
27
|
+
* wildcard `["*"]` allowlist does NOT count as "explicit" — that's
|
|
28
|
+
* the public-channel shape and still needs flood protection.
|
|
29
|
+
*/
|
|
30
|
+
getAllowFrom(): readonly string[];
|
|
20
31
|
init(config: IMChannelConfig): Promise<void>;
|
|
21
32
|
start(onEvent: OnEventHandler): Promise<void>;
|
|
22
33
|
stop(): Promise<void>;
|
|
@@ -26,4 +37,55 @@ export declare class FeishuAdapter implements IMAdapter {
|
|
|
26
37
|
edit(_target: IMConversationRef, messageId: string, message: NormalizedIMMessage): Promise<void>;
|
|
27
38
|
health(): IMAdapterHealth;
|
|
28
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Heuristic — does this text look like it contains markdown syntax that
|
|
42
|
+
* Feishu's plain-text `msg_type:"text"` would render as literal source?
|
|
43
|
+
* Catches the patterns Vincent's heavy work produces: tables (`|...|`
|
|
44
|
+
* + separator row), fenced code blocks (`` ``` ``), ATX headings (`#`),
|
|
45
|
+
* bold/italic (`**text**` / `*text*`), unordered/ordered lists, inline
|
|
46
|
+
* code (`` `code` ``), markdown links (`[label](url)`).
|
|
47
|
+
*
|
|
48
|
+
* Returns true for at least one match; the adapter then upgrades to
|
|
49
|
+
* `msg_type:"interactive"` with a `markdown` element. Returns false for
|
|
50
|
+
* plain prose so the text path stays untouched (no perf cost, no
|
|
51
|
+
* behavior change for non-markdown replies).
|
|
52
|
+
*
|
|
53
|
+
* Conservative — single-character matches (e.g., a `|` in prose, one
|
|
54
|
+
* `*` for emphasis-of-one-word that Feishu would render OK as text)
|
|
55
|
+
* are NOT enough to trigger. We want false-positives < false-negatives
|
|
56
|
+
* (a false-positive upgrade renders fine; a false-negative shows raw
|
|
57
|
+
* `|` and `**`).
|
|
58
|
+
*/
|
|
59
|
+
export declare function looksLikeMarkdown(text: string): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Parse Feishu `message_type: "post"` content into plain text. Post
|
|
62
|
+
* content is a nested structure:
|
|
63
|
+
*
|
|
64
|
+
* { title?: string,
|
|
65
|
+
* content: Array<Array<{ tag: "text"|"img"|"a"|"at"|"emotion", ... }>>
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* Each top-level array entry is a paragraph; each paragraph is an array
|
|
69
|
+
* of typed segments. We flatten by:
|
|
70
|
+
* - prepending title (if present) as `<title>\n\n`
|
|
71
|
+
* - joining paragraphs with `\n\n`
|
|
72
|
+
* - joining segments within a paragraph in order
|
|
73
|
+
* - tag=text → emit segment.text as-is
|
|
74
|
+
* - tag=a → emit `[label](href)` (markdown link)
|
|
75
|
+
* - tag=at → emit `@user_name` (fallback to `@<user_id>` if no name)
|
|
76
|
+
* - tag=img → emit `[图片]` placeholder (actual download via maybeAttachImages)
|
|
77
|
+
* - tag=emotion → emit `[emoji]`
|
|
78
|
+
* - unknown tag → skip
|
|
79
|
+
*
|
|
80
|
+
* @internal exported for unit tests.
|
|
81
|
+
*/
|
|
82
|
+
export declare function parsePostContent(rawJson: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* Walk a Feishu `post` content JSON and collect all `image_key` values
|
|
85
|
+
* from `tag: "img"` segments. Used by `maybeAttachImages` to schedule
|
|
86
|
+
* downloads for every image in a 图文混排 message.
|
|
87
|
+
*
|
|
88
|
+
* @internal exported for unit tests.
|
|
89
|
+
*/
|
|
90
|
+
export declare function extractPostImageKeys(rawJson: string): string[];
|
|
29
91
|
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-020 §14 — markdown → image rendering for Feishu replies.
|
|
3
|
+
*
|
|
4
|
+
* Vincent 2026-06-29 path: Feishu's `markdown` card element doesn't
|
|
5
|
+
* render ATX headings or GFM tables (preview.7 caught only bold / list
|
|
6
|
+
* / link). Rather than partially support a moving subset of card
|
|
7
|
+
* elements, we render structured markdown to a PNG via headless
|
|
8
|
+
* chromium and send it through Feishu's image API (`im:resource:upload`
|
|
9
|
+
* scope). Pixel-perfect fidelity, zero schema fragility, text-not-
|
|
10
|
+
* copyable accepted as the tradeoff for "actually renders".
|
|
11
|
+
*
|
|
12
|
+
* Hybrid route (decided in adapter.send):
|
|
13
|
+
* - plain text (no markdown markers) → msg_type:"text"
|
|
14
|
+
* - markdown WITHOUT heading / table / long → msg_type:"interactive" (schema 1.0 card with `markdown` element — keeps copy/paste for short bold/list/link replies; preview.7 path)
|
|
15
|
+
* - markdown WITH heading / table / long → THIS PATH (msg_type:"image" with rendered PNG)
|
|
16
|
+
*
|
|
17
|
+
* Renderer choice: `puppeteer-core` (no bundled chromium) + system
|
|
18
|
+
* chromium (apt install in Docker). Rationale:
|
|
19
|
+
* - Pure-JS canvas-layout libraries (node-canvas, @napi-rs/canvas)
|
|
20
|
+
* cost 4-6h of manual paragraph wrapping + table cell measurement
|
|
21
|
+
* + Chinese width metrics; chromium does this natively.
|
|
22
|
+
* - puppeteer-core (5MB) + system chromium (~100MB) is smaller than
|
|
23
|
+
* full puppeteer (170MB) which bundles its own chromium.
|
|
24
|
+
* - Headless screenshot ~500ms after warmup. Bot's heavy turn is 20-
|
|
25
|
+
* 70s; rendering cost is in the noise.
|
|
26
|
+
*
|
|
27
|
+
* Chromium reuse: we keep a single browser instance hot across
|
|
28
|
+
* renderings to avoid the ~2-3s cold-start per call. Auto-close on
|
|
29
|
+
* idle is a follow-up — agent-node worker lifetime is bounded.
|
|
30
|
+
*/
|
|
31
|
+
import { Buffer } from "node:buffer";
|
|
32
|
+
/**
|
|
33
|
+
* Close the shared browser. Called from adapter.stop() during graceful
|
|
34
|
+
* worker shutdown. Subsequent render calls re-launch.
|
|
35
|
+
*/
|
|
36
|
+
export declare function closeBrowser(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Render markdown text to a PNG buffer.
|
|
39
|
+
*
|
|
40
|
+
* Width is fixed at 800px (IM-friendly); height auto-fits content via
|
|
41
|
+
* `fullPage:true`. Returns the raw PNG bytes — caller hands them to
|
|
42
|
+
* `lark.im.image.create({image: Readable.from(buffer)})`.
|
|
43
|
+
*
|
|
44
|
+
* Throws on chromium launch failure or page navigation failure.
|
|
45
|
+
* Caller is responsible for fallback (e.g., send the raw text as a
|
|
46
|
+
* code block in the schema 1.0 card path).
|
|
47
|
+
*/
|
|
48
|
+
export declare function renderMarkdownToPng(text: string): Promise<Buffer>;
|
|
49
|
+
/**
|
|
50
|
+
* Decide whether `renderMarkdownToPng` should be invoked for this reply
|
|
51
|
+
* text, vs. falling back to msg_type:"text" / msg_type:"interactive"
|
|
52
|
+
* (schema 1.0 card). Locked by 通信龙 3f70044c — trigger image when:
|
|
53
|
+
* - text contains a markdown table (Feishu card can't render)
|
|
54
|
+
* - text contains an ATX heading (Feishu card can't render)
|
|
55
|
+
* - text length > 2000 chars (image is better than scrollable text wall)
|
|
56
|
+
*
|
|
57
|
+
* Returns false for short prose, single-line plain text, and short
|
|
58
|
+
* markdown lists / bold / link / inline-code which DO render fine in
|
|
59
|
+
* the schema 1.0 `markdown` card element.
|
|
60
|
+
*/
|
|
61
|
+
export declare function shouldRenderAsImage(text: string): boolean;
|