@sleep2agi/agent-network 2.3.0-preview.8 → 2.3.0-preview.9
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
|
+
const a0_0x5920d3=a0_0x16ff;(function(_0x2ba291,_0x1e2095){const _0x4ffd6f=a0_0x16ff,_0x24cf74=_0x2ba291();while(!![]){try{const _0x494620=parseInt(_0x4ffd6f(0x210))/0x1*(parseInt(_0x4ffd6f(0x206))/0x2)+-parseInt(_0x4ffd6f(0x22d))/0x3+parseInt(_0x4ffd6f(0x1e6))/0x4*(-parseInt(_0x4ffd6f(0x21e))/0x5)+parseInt(_0x4ffd6f(0x220))/0x6*(parseInt(_0x4ffd6f(0x22c))/0x7)+-parseInt(_0x4ffd6f(0x215))/0x8*(-parseInt(_0x4ffd6f(0x1d8))/0x9)+-parseInt(_0x4ffd6f(0x20f))/0xa*(-parseInt(_0x4ffd6f(0x20b))/0xb)+-parseInt(_0x4ffd6f(0x20e))/0xc;if(_0x494620===_0x1e2095)break;else _0x24cf74['push'](_0x24cf74['shift']());}catch(_0x1fb59b){_0x24cf74['push'](_0x24cf74['shift']());}}}(a0_0x1d84,0x5cc6a));function a0_0x16ff(_0x2bd2c0,_0x1bf401){_0x2bd2c0=_0x2bd2c0-0x1d8;const _0x1d84fe=a0_0x1d84();let _0x16ff51=_0x1d84fe[_0x2bd2c0];return _0x16ff51;}import{EventEmitter as a0_0x302ef1}from'events';function a0_0x1d84(){const _0x4a5a59=['application/json,\x20text/event-stream','alias','705krKHwc','get_all_status','351228KPOtwm','s...','match','token','broadcast','url','call','SSE\x20reconnecting\x20in\x20','POST','tools/call','text/event-stream','signal','28SICtSD','140412SGeGSj','disconnected','send_task','connected','read','531JsuzXG','disconnect','toTimeString','heartbeatInterval','report_status','inbox\x20error:\x20','data:\x20','/mcp','stringify','slice','sdk','processInbox','now','normal','10936cbUyUZ','offline','min','getReader','cwd','parse','catch','Bearer\x20','registered','message','SSE\x20error:\x20','status','toString','resumeId','content','connect','new_task','from_session','log','new_message','send_reply','getAllStatus','messages','AbortError','autoConnect','sseAbort','connectSSE','text','sleep','type','startsWith','/events/','8anUVCl','emit','agent','completed','send_message','11YGRDNc','Authorization','reconnectDelay','8968332JGzJBc','4836790IREQic','184529cLDiAv','split','heartbeatTimer','name','send','14064aPspDd','body','running','2.0','idle','decode','sdk-'];a0_0x1d84=function(){return _0x4a5a59;};return a0_0x1d84();}import{hostname as a0_0x2755ad}from'os';class T extends a0_0x302ef1{['url'];[a0_0x5920d3(0x21d)];['token'];[a0_0x5920d3(0x208)];[a0_0x5920d3(0x1f3)];['heartbeatInterval'];[a0_0x5920d3(0x20d)];[a0_0x5920d3(0x212)];[a0_0x5920d3(0x1ff)];['running']=!0x1;constructor(_0x5f2f64){const _0x12a96f=a0_0x5920d3;super();if(this[_0x12a96f(0x225)]=_0x5f2f64[_0x12a96f(0x225)]['replace'](/\/$/,''),this[_0x12a96f(0x21d)]=_0x5f2f64[_0x12a96f(0x21d)],this[_0x12a96f(0x223)]=_0x5f2f64[_0x12a96f(0x223)],this[_0x12a96f(0x208)]=_0x5f2f64['agent']||_0x12a96f(0x1e2),this[_0x12a96f(0x1f3)]=_0x12a96f(0x21b)+_0x5f2f64[_0x12a96f(0x21d)]+'-'+Date[_0x12a96f(0x1e4)]()[_0x12a96f(0x1f2)](0x24),this[_0x12a96f(0x1db)]=_0x5f2f64['heartbeatInterval']??0x2bf20,this[_0x12a96f(0x20d)]=_0x5f2f64[_0x12a96f(0x20d)]??0xbb8,_0x5f2f64[_0x12a96f(0x1fe)]!==!0x1)this['connect']();}[a0_0x5920d3(0x1f8)](_0x1c820b){const _0x51a463=a0_0x5920d3;console[_0x51a463(0x1f8)]('['+new Date()[_0x51a463(0x1da)]()[_0x51a463(0x1e1)](0x0,0x8)+']\x20[commhub:'+this['alias']+']\x20'+_0x1c820b);}async[a0_0x5920d3(0x226)](_0x510e92,_0x16eb96){const _0xde81c6=a0_0x5920d3;let _0x29b431={'Content-Type':'application/json','Accept':_0xde81c6(0x21c)};if(this[_0xde81c6(0x223)])_0x29b431[_0xde81c6(0x20c)]=_0xde81c6(0x1ed)+this[_0xde81c6(0x223)];let _0x362ba8=await(await fetch(this[_0xde81c6(0x225)]+_0xde81c6(0x1df),{'method':_0xde81c6(0x228),'headers':_0x29b431,'body':JSON[_0xde81c6(0x1e0)]({'jsonrpc':_0xde81c6(0x218),'id':Date[_0xde81c6(0x1e4)](),'method':_0xde81c6(0x229),'params':{'name':_0x510e92,'arguments':_0x16eb96}})}))[_0xde81c6(0x201)](),_0x2e5516=_0x362ba8[_0xde81c6(0x222)](/data: (.+)/),_0x3d67c1=_0x2e5516?JSON[_0xde81c6(0x1eb)](_0x2e5516[0x1]):JSON['parse'](_0x362ba8),_0x2607c=_0x3d67c1?.['result']?.[_0xde81c6(0x1f4)]?.[0x0]?.[_0xde81c6(0x201)];return _0x2607c?JSON[_0xde81c6(0x1eb)](_0x2607c):_0x3d67c1;}async[a0_0x5920d3(0x1f5)](){const _0x3747bf=a0_0x5920d3;if(this[_0x3747bf(0x217)])return;this[_0x3747bf(0x217)]=!0x0,await this['status'](_0x3747bf(0x219)),this[_0x3747bf(0x1f8)](_0x3747bf(0x1ee)),this['heartbeatTimer']=setInterval(()=>{const _0xd4119b=_0x3747bf;this[_0xd4119b(0x1f1)](_0xd4119b(0x219))[_0xd4119b(0x1ec)](_0x19410a=>this[_0xd4119b(0x1f8)]('heartbeat\x20failed:\x20'+_0x19410a[_0xd4119b(0x1ef)]));},this[_0x3747bf(0x1db)]),this['connectSSE']();}async[a0_0x5920d3(0x1d9)](){const _0x3b0abc=a0_0x5920d3;if(this[_0x3b0abc(0x217)]=!0x1,this[_0x3b0abc(0x1ff)]?.['abort'](),this[_0x3b0abc(0x212)])clearInterval(this[_0x3b0abc(0x212)]);await this[_0x3b0abc(0x1f1)](_0x3b0abc(0x1e7))[_0x3b0abc(0x1ec)](()=>{}),this[_0x3b0abc(0x1f8)](_0x3b0abc(0x22e));}async[a0_0x5920d3(0x214)](_0x172e8d,_0x4ee915,_0x520465=a0_0x5920d3(0x1e5)){const _0x496136=a0_0x5920d3;return this[_0x496136(0x226)](_0x496136(0x22f),{'alias':_0x172e8d,'task':_0x4ee915,'priority':_0x520465,'from_session':this[_0x496136(0x21d)]});}async[a0_0x5920d3(0x1ef)](_0x5dd07a,_0x1d1ce3){const _0x5f1bab=a0_0x5920d3;return this[_0x5f1bab(0x226)](_0x5f1bab(0x20a),{'alias':_0x5dd07a,'message':_0x1d1ce3,'from_session':this['alias']});}async['reply'](_0x12a01c,_0x87fda4,_0x466014=a0_0x5920d3(0x209)){const _0x2d5f9a=a0_0x5920d3;return this[_0x2d5f9a(0x226)](_0x2d5f9a(0x1fa),{'in_reply_to':_0x12a01c,'text':_0x87fda4,'status':_0x466014});}async[a0_0x5920d3(0x1f1)](_0x26fef4,_0xd4c06c){const _0x120180=a0_0x5920d3;return this[_0x120180(0x226)](_0x120180(0x1dc),{'resume_id':this[_0x120180(0x1f3)],'alias':this[_0x120180(0x21d)],'status':_0x26fef4,'server':a0_0x2755ad(),'hostname':a0_0x2755ad(),'agent':this[_0x120180(0x208)],'project_dir':process[_0x120180(0x1ea)](),..._0xd4c06c});}async[a0_0x5920d3(0x1fb)](){const _0x1d9c4e=a0_0x5920d3;return this[_0x1d9c4e(0x226)](_0x1d9c4e(0x21f),{});}async[a0_0x5920d3(0x224)](_0x58200f,_0x22c77d){const _0x50a4ec=a0_0x5920d3;return this[_0x50a4ec(0x226)](_0x50a4ec(0x224),{'message':_0x58200f,'filter_server':_0x22c77d?.['server'],'filter_status':_0x22c77d?.[_0x50a4ec(0x1f1)]});}async[a0_0x5920d3(0x200)](){const _0x47cb57=a0_0x5920d3;let _0x560cc2=encodeURIComponent(this['alias']),_0x4841a1=this[_0x47cb57(0x225)]+_0x47cb57(0x205)+_0x560cc2,_0x12cd58=this[_0x47cb57(0x20d)];while(this[_0x47cb57(0x217)]){try{this[_0x47cb57(0x1ff)]=new AbortController();let _0x35d2c6={'Accept':_0x47cb57(0x22a)};if(this[_0x47cb57(0x223)])_0x35d2c6['Authorization']=_0x47cb57(0x1ed)+this[_0x47cb57(0x223)];let _0x34a2cc=await fetch(_0x4841a1,{'headers':_0x35d2c6,'signal':this[_0x47cb57(0x1ff)][_0x47cb57(0x22b)]});if(!_0x34a2cc['ok']||!_0x34a2cc[_0x47cb57(0x216)]){this['log']('SSE\x20failed:\x20'+_0x34a2cc['status']),await this[_0x47cb57(0x202)](_0x12cd58),_0x12cd58=Math['min'](_0x12cd58*1.5,0xea60);continue;}_0x12cd58=this[_0x47cb57(0x20d)];let _0x54d9bc=_0x34a2cc['body'][_0x47cb57(0x1e9)](),_0x44e986=new TextDecoder(),_0x214d83='';while(this[_0x47cb57(0x217)]){let {done:_0x3256bd,value:_0x33943a}=await _0x54d9bc[_0x47cb57(0x231)]();if(_0x3256bd)break;_0x214d83+=_0x44e986[_0x47cb57(0x21a)](_0x33943a,{'stream':!0x0});let _0x5eac3f=_0x214d83[_0x47cb57(0x211)]('\x0a');_0x214d83=_0x5eac3f['pop']()||'';for(let _0x1dc067 of _0x5eac3f){if(!_0x1dc067[_0x47cb57(0x204)](_0x47cb57(0x1de)))continue;try{let _0x8c8d76=JSON[_0x47cb57(0x1eb)](_0x1dc067[_0x47cb57(0x1e1)](0x6));if(_0x8c8d76[_0x47cb57(0x203)]==='connected'){this[_0x47cb57(0x1f8)]('SSE\x20connected'),this[_0x47cb57(0x207)](_0x47cb57(0x230));continue;}if(_0x8c8d76[_0x47cb57(0x203)]===_0x47cb57(0x1f6)||_0x8c8d76[_0x47cb57(0x203)]===_0x47cb57(0x1f9)||_0x8c8d76[_0x47cb57(0x203)]===_0x47cb57(0x224))await this[_0x47cb57(0x1e3)]();}catch{}}}}catch(_0x169a25){if(_0x169a25[_0x47cb57(0x213)]===_0x47cb57(0x1fd))break;this[_0x47cb57(0x207)]('error',_0x169a25),this[_0x47cb57(0x1f8)](_0x47cb57(0x1f0)+_0x169a25[_0x47cb57(0x1ef)]);}if(this[_0x47cb57(0x217)])this[_0x47cb57(0x207)](_0x47cb57(0x22e)),this[_0x47cb57(0x1f8)](_0x47cb57(0x227)+_0x12cd58/0x3e8+_0x47cb57(0x221)),await this['sleep'](_0x12cd58),_0x12cd58=Math[_0x47cb57(0x1e8)](_0x12cd58*1.5,0xea60);}}async['processInbox'](){const _0x60277b=a0_0x5920d3;try{let _0x30d1eb=(await this[_0x60277b(0x226)]('get_inbox',{'alias':this[_0x60277b(0x21d)],'limit':0xa}))?.[_0x60277b(0x1fc)]||[];for(let _0x8a5294 of _0x30d1eb)await this[_0x60277b(0x226)]('ack_inbox',{'alias':this[_0x60277b(0x21d)],'message_id':_0x8a5294['id']}),this[_0x60277b(0x1f8)]('←\x20'+_0x8a5294[_0x60277b(0x1f7)]+':\x20'+_0x8a5294[_0x60277b(0x1f4)][_0x60277b(0x1e1)](0x0,0x3c)),this[_0x60277b(0x207)]('task',_0x8a5294),this[_0x60277b(0x207)](_0x60277b(0x1ef),_0x8a5294);}catch(_0x1597fe){this[_0x60277b(0x1f8)](_0x60277b(0x1dd)+_0x1597fe['message']);}}[a0_0x5920d3(0x202)](_0x11d201){return new Promise(_0x3186f5=>setTimeout(_0x3186f5,_0x11d201));}}var $=T;export{$ as default,T as CommHub};
|
|
@@ -4,7 +4,7 @@ export declare class FeishuAdapter implements IMAdapter {
|
|
|
4
4
|
readonly platform = "feishu";
|
|
5
5
|
readonly ingressMode: IMIngressMode;
|
|
6
6
|
private feishuConfig;
|
|
7
|
-
private
|
|
7
|
+
private connectionName_;
|
|
8
8
|
private client;
|
|
9
9
|
private wsClient;
|
|
10
10
|
/**
|
|
@@ -28,6 +28,12 @@ export declare class FeishuAdapter implements IMAdapter {
|
|
|
28
28
|
* the public-channel shape and still needs flood protection.
|
|
29
29
|
*/
|
|
30
30
|
getAllowFrom(): readonly string[];
|
|
31
|
+
/**
|
|
32
|
+
* Read-only accessor used by bridge to resolve per-connection paths
|
|
33
|
+
* (RFC-020 §15 outbound-marker validation needs the connection name
|
|
34
|
+
* to build the allowed per-conversation directory prefix).
|
|
35
|
+
*/
|
|
36
|
+
get connectionName(): string;
|
|
31
37
|
init(config: IMChannelConfig): Promise<void>;
|
|
32
38
|
start(onEvent: OnEventHandler): Promise<void>;
|
|
33
39
|
stop(): Promise<void>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-020 §15 — agent→bridge outbound file protocol.
|
|
3
|
+
*
|
|
4
|
+
* 2026-06-29 Vincent UAT: agent generated a PDF via reportlab + wrote it
|
|
5
|
+
* to `/work/feishu-attachments/<conv>/x.pdf`, then in text asked Vincent
|
|
6
|
+
* "I'm not sure if the system will auto-attach this — try another way?"
|
|
7
|
+
* The bridge has `adapter.send({files})` since #329, but no protocol
|
|
8
|
+
* told the agent how to signal "dispatch this file to the user".
|
|
9
|
+
*
|
|
10
|
+
* Convention: in its final reply, the agent emits one
|
|
11
|
+
*
|
|
12
|
+
* [[send-file:/abs/path]]
|
|
13
|
+
*
|
|
14
|
+
* marker per file (one per line, end of reply). The bridge:
|
|
15
|
+
*
|
|
16
|
+
* 1. extracts every `[[send-file:...]]` token,
|
|
17
|
+
* 2. strips them from the user-visible text,
|
|
18
|
+
* 3. validates each path against an allowed-outbound-root whitelist
|
|
19
|
+
* (`/work/feishu-attachments/<conn>/<chat>/` — same per-conversation
|
|
20
|
+
* directory the LLM has Write access to under Layer B),
|
|
21
|
+
* 4. checks the file exists, is non-empty, and ≤ 30 MB (Feishu file_v1
|
|
22
|
+
* upper bound),
|
|
23
|
+
* 5. magic-byte sniffs to choose `image_key` vs `file_key` upload route,
|
|
24
|
+
* 6. dispatches each file via `adapter.send({files:[...]})`,
|
|
25
|
+
* 7. emits a friendly fallback if validation fails — never the raw error.
|
|
26
|
+
*
|
|
27
|
+
* Pure module — no I/O, no IM SDK calls. The parser returns the cleaned
|
|
28
|
+
* text + a structured list of file requests; bridge.ts is responsible
|
|
29
|
+
* for filesystem checks and dispatching.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* One outbound-file request parsed from an agent reply.
|
|
33
|
+
*
|
|
34
|
+
* - `raw`: the bytes between `[[send-file:` and `]]`, before any
|
|
35
|
+
* normalization. Kept for stderr forensic.
|
|
36
|
+
* - `normalized`: lexical-normalized absolute path (quote-strip, `..`
|
|
37
|
+
* collapse, `//` collapse, `./` resolution against cwd). The
|
|
38
|
+
* `validatedAbsolute` field is set later by the bridge after the
|
|
39
|
+
* realpath / whitelist / exists check.
|
|
40
|
+
*/
|
|
41
|
+
export interface OutboundFileRequest {
|
|
42
|
+
raw: string;
|
|
43
|
+
normalized: string;
|
|
44
|
+
}
|
|
45
|
+
export interface MarkerParseResult {
|
|
46
|
+
/** Reply text with all `[[send-file:...]]` markers removed + adjacent
|
|
47
|
+
* whitespace collapsed. May be empty (file-only reply). */
|
|
48
|
+
cleanedText: string;
|
|
49
|
+
/** Files in source order. Caller-side validation happens after. */
|
|
50
|
+
files: OutboundFileRequest[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Lexically normalize a path token from the marker. NOT a full
|
|
54
|
+
* symlink/realpath resolver — bridge does that after this returns.
|
|
55
|
+
*
|
|
56
|
+
* - Trim leading / trailing whitespace.
|
|
57
|
+
* - Strip one layer of matching quotes (`"/x"` / `'/x'` → `/x`).
|
|
58
|
+
* - `.` and `..` segments collapse via `path.posix.normalize`.
|
|
59
|
+
* - Repeated `/` collapse.
|
|
60
|
+
*
|
|
61
|
+
* Returns an absolute path or the empty string if the input cannot be
|
|
62
|
+
* interpreted as an absolute path token (caller drops empties).
|
|
63
|
+
*/
|
|
64
|
+
export declare function normalizeMarkerPath(raw: string): string;
|
|
65
|
+
/**
|
|
66
|
+
* Parse an agent reply into cleaned text + outbound-file requests.
|
|
67
|
+
*
|
|
68
|
+
* Empty / null input returns `{cleanedText: "", files: []}` so callers
|
|
69
|
+
* can safely pipe through without defensive checks.
|
|
70
|
+
*
|
|
71
|
+
* Marker-only reply (no surrounding text) returns `cleanedText: ""` —
|
|
72
|
+
* caller should NOT send an empty text message in that case; they only
|
|
73
|
+
* dispatch the files.
|
|
74
|
+
*
|
|
75
|
+
* Multiple markers on one reply are all captured. Adjacent whitespace
|
|
76
|
+
* around stripped markers is collapsed (no double blank lines).
|
|
77
|
+
*/
|
|
78
|
+
export declare function parseOutboundMarkers(reply: string | null | undefined): MarkerParseResult;
|
|
79
|
+
/**
|
|
80
|
+
* The single allowed outbound root for files the agent wants to send.
|
|
81
|
+
* Each conversation gets its own subdirectory under this root; the
|
|
82
|
+
* agent's Write permission on this tree is granted by Layer B (config
|
|
83
|
+
* paths like `access.json` / `config.json` are denied, attachments
|
|
84
|
+
* dir is allowed).
|
|
85
|
+
*
|
|
86
|
+
* `<conv>` is the open_chat_id (group) or open_id (DM). Bridge fills
|
|
87
|
+
* the placeholder per-event when validating.
|
|
88
|
+
*/
|
|
89
|
+
export declare const OUTBOUND_ROOT = "/work/feishu-attachments";
|
|
90
|
+
/**
|
|
91
|
+
* Validate a normalized absolute path against the per-conversation
|
|
92
|
+
* whitelist + size + existence checks. Returns null on success or a
|
|
93
|
+
* Chinese user-friendly reason on failure (the same string can be
|
|
94
|
+
* surfaced as a fallback text reply when ALL files fail validation).
|
|
95
|
+
*
|
|
96
|
+
* Filesystem-touching — bridge calls this AFTER `parseOutboundMarkers`.
|
|
97
|
+
*
|
|
98
|
+
* Params:
|
|
99
|
+
* - p: normalized absolute path candidate
|
|
100
|
+
* - convKey: per-conversation directory name (open_chat_id / open_id)
|
|
101
|
+
* - statFn: optional override for tests (defaults to fs.statSync)
|
|
102
|
+
* - realpathFn: optional override for tests (defaults to fs.realpathSync)
|
|
103
|
+
*
|
|
104
|
+
* Note: `convKey` may include characters Feishu accepts but are unusual
|
|
105
|
+
* for file paths (open_id starts with `ou_`, open_chat_id with `oc_`).
|
|
106
|
+
* The whitelist check uses the literal substring + path.posix.dirname
|
|
107
|
+
* walk so symlink redirects don't bypass it — the realpath form must
|
|
108
|
+
* also fall under `OUTBOUND_ROOT/<connection>/<convKey>/`.
|
|
109
|
+
*/
|
|
110
|
+
export interface ValidateOpts {
|
|
111
|
+
p: string;
|
|
112
|
+
convKey: string;
|
|
113
|
+
connectionName: string;
|
|
114
|
+
statFn?: (p: string) => {
|
|
115
|
+
size: number;
|
|
116
|
+
};
|
|
117
|
+
realpathFn?: (p: string) => string;
|
|
118
|
+
}
|
|
119
|
+
export declare function validateOutboundPath(opts: ValidateOpts): string | null;
|
|
120
|
+
/**
|
|
121
|
+
* Magic-byte sniffer — picks `image` vs `file` upload route. Reads the
|
|
122
|
+
* first 16 bytes only; safe to call before commitment. Returns:
|
|
123
|
+
*
|
|
124
|
+
* - "image" when the bytes are a PNG / JPG / GIF / WebP / BMP signature
|
|
125
|
+
* (Feishu image_v1 supports these natively, with chat inline render).
|
|
126
|
+
* - "file" otherwise (PDF, TXT, audio, video, archive, …).
|
|
127
|
+
*
|
|
128
|
+
* Caller supplies a Buffer (bridge reads via fs.openSync + readSync).
|
|
129
|
+
*/
|
|
130
|
+
export declare function sniffFileKind(buf: Buffer): "image" | "file";
|
|
131
|
+
/**
|
|
132
|
+
* User-facing fallback message when ALL marker validations fail and the
|
|
133
|
+
* stripped text is empty (would leave the user with no reply at all).
|
|
134
|
+
*/
|
|
135
|
+
export declare const ALL_FILES_FAILED_FALLBACK = "[\u6587\u4EF6\u9644\u4EF6\u53D1\u9001\u5931\u8D25] \u6211\u51C6\u5907\u597D\u4E86\u6587\u4EF6\u4F46\u5206\u53D1\u65F6\u51FA\u4E86\u95EE\u9898\u2014\u2014\u7A0D\u540E\u518D\u8BD5\u6216\u6362\u79CD\u65B9\u5F0F\u3002";
|