multi-openim-channel 0.1.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/LICENSE +21 -0
- package/README.md +255 -0
- package/SCHEMA.md +167 -0
- package/dist/channel.d.ts +57 -0
- package/dist/channel.js +104 -0
- package/dist/clients.d.ts +20 -0
- package/dist/clients.js +329 -0
- package/dist/config.d.ts +37 -0
- package/dist/config.js +256 -0
- package/dist/context.d.ts +7 -0
- package/dist/context.js +8 -0
- package/dist/friend-guard.d.ts +19 -0
- package/dist/friend-guard.js +66 -0
- package/dist/inbound.d.ts +17 -0
- package/dist/inbound.js +639 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +71 -0
- package/dist/media.d.ts +10 -0
- package/dist/media.js +157 -0
- package/dist/polyfills.d.ts +5 -0
- package/dist/polyfills.js +27 -0
- package/dist/setup.d.ts +10 -0
- package/dist/setup.js +69 -0
- package/dist/targets.d.ts +7 -0
- package/dist/targets.js +38 -0
- package/dist/token-refresh.d.ts +50 -0
- package/dist/token-refresh.js +383 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +153 -0
- package/dist/types.d.ts +183 -0
- package/dist/types.js +4 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +68 -0
- package/openclaw.plugin.json +258 -0
- package/package.json +59 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional shield for the OpenIM SDK's friend-relationship methods. When the
|
|
3
|
+
* channel-level `disableFriendSdk` flag is true (the default), every friend
|
|
4
|
+
* SDK method on a connected client is replaced by a throwing stub that
|
|
5
|
+
* surfaces a grep-able error code (`MULTI_OPENIM_FRIEND_API_DISABLED`).
|
|
6
|
+
*
|
|
7
|
+
* Use case: when an external system (your own backend, a CRM, a directory
|
|
8
|
+
* service, etc.) is the authoritative store for friend relationships,
|
|
9
|
+
* letting the SDK's friend methods run directly would split the source of
|
|
10
|
+
* truth and — under multi-account load — has been observed to raise
|
|
11
|
+
* uncaught rejections during token rotation. Operators who want raw SDK
|
|
12
|
+
* friend behavior can opt out per channel or per account via
|
|
13
|
+
* `disableFriendSdk: false`.
|
|
14
|
+
*/
|
|
15
|
+
import { logTag } from "./utils.js";
|
|
16
|
+
export const FRIEND_API_DISABLED_CODE = "MULTI_OPENIM_FRIEND_API_DISABLED";
|
|
17
|
+
const FRIEND_METHOD_NAMES = [
|
|
18
|
+
"addFriend",
|
|
19
|
+
"addFriendV2",
|
|
20
|
+
"applyFriend",
|
|
21
|
+
"acceptFriendApplication",
|
|
22
|
+
"refuseFriendApplication",
|
|
23
|
+
"deleteFriend",
|
|
24
|
+
"checkFriend",
|
|
25
|
+
"setFriendRemark",
|
|
26
|
+
"addBlack",
|
|
27
|
+
"removeBlack",
|
|
28
|
+
"getFriendApplicationListAsApplicant",
|
|
29
|
+
"getFriendApplicationListAsRecipient",
|
|
30
|
+
"getFriendApplicationList",
|
|
31
|
+
"getRecvFriendApplicationList",
|
|
32
|
+
"getSendFriendApplicationList",
|
|
33
|
+
"getFriendList",
|
|
34
|
+
];
|
|
35
|
+
export function applyFriendGuard(sdk, account, logger) {
|
|
36
|
+
if (!sdk)
|
|
37
|
+
return 0;
|
|
38
|
+
if (!account.disableFriendSdk) {
|
|
39
|
+
logger?.info?.(`${logTag("friend-guard")} account=${account.accountId} disableFriendSdk=false — leaving raw SDK friend APIs intact`);
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
const sdkObj = sdk;
|
|
43
|
+
if (sdkObj.__multiOpenimFriendGuardApplied)
|
|
44
|
+
return 0;
|
|
45
|
+
let shimmed = 0;
|
|
46
|
+
for (const name of FRIEND_METHOD_NAMES) {
|
|
47
|
+
const current = sdkObj[name];
|
|
48
|
+
if (typeof current !== "function")
|
|
49
|
+
continue;
|
|
50
|
+
sdkObj[name] = async (..._args) => {
|
|
51
|
+
const message = `${FRIEND_API_DISABLED_CODE}: SDK ${name}() is disabled by multi-openim-channel` +
|
|
52
|
+
` (account=${account.accountId}). Route friend operations through your own backend.`;
|
|
53
|
+
logger?.warn?.(`${logTag("friend-guard")} blocked SDK ${name}() on account=${account.accountId}`);
|
|
54
|
+
throw new Error(message);
|
|
55
|
+
};
|
|
56
|
+
shimmed++;
|
|
57
|
+
}
|
|
58
|
+
sdkObj.__multiOpenimFriendGuardApplied = true;
|
|
59
|
+
if (shimmed > 0) {
|
|
60
|
+
logger?.info?.(`${logTag("friend-guard")} account=${account.accountId}: shimmed ${shimmed} friend SDK method(s) (set disableFriendSdk=false to opt out)`);
|
|
61
|
+
}
|
|
62
|
+
return shimmed;
|
|
63
|
+
}
|
|
64
|
+
export function listGuardedMethods() {
|
|
65
|
+
return FRIEND_METHOD_NAMES;
|
|
66
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound message dispatcher.
|
|
3
|
+
*
|
|
4
|
+
* Pipeline per message:
|
|
5
|
+
* 1. Filter (self-sent ignore, dedup, whitelist gating, group @-mention).
|
|
6
|
+
* 2. Extract a structured body (text + media items + quote unwrapping).
|
|
7
|
+
* 3. Optionally materialize image bytes for downstream multimodal agents.
|
|
8
|
+
* 4. Build a session key that always includes accountId for direct chats
|
|
9
|
+
* so two accounts in the same conversation never collide.
|
|
10
|
+
* 5. Hand off to the host runtime's reply pipeline with a deliver()
|
|
11
|
+
* callback that routes the agent reply back via the SDK.
|
|
12
|
+
*/
|
|
13
|
+
import type { MessageItem } from "@openim/client-sdk";
|
|
14
|
+
import type { PluginContext } from "./context.js";
|
|
15
|
+
import type { ClientState } from "./types.js";
|
|
16
|
+
export declare function processInboundMessage(ctx: PluginContext, state: ClientState, msg: MessageItem): Promise<void>;
|
|
17
|
+
export declare function _internal_clearInboundDedup(): void;
|