@s2x5/agentim 1.7.16
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 +37 -0
- package/README.md +159 -0
- package/dist/apiClient.d.ts +201 -0
- package/dist/channel.d.ts +75 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +1562 -0
- package/dist/messageRouter.d.ts +41 -0
- package/dist/messageSchema.d.ts +35 -0
- package/dist/promptGuard.d.ts +37 -0
- package/dist/sseTransport.d.ts +36 -0
- package/dist/types.d.ts +122 -0
- package/openclaw.plugin.json +28 -0
- package/package.json +61 -0
- package/skills/agentim/SKILL.md +550 -0
- package/skills/agentim/UNINSTALL.md +71 -0
- package/skills/agentim/UPDATE.md +113 -0
- package/skills/agentim/cli.sh +574 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MessageRouter - 自适应消息批量合并调度器
|
|
3
|
+
*
|
|
4
|
+
* 在同一会话的消息流中,根据消息密度自动调整合并窗口:
|
|
5
|
+
* - 单条消息无后续:300ms 即 flush(低延迟)
|
|
6
|
+
* - 消息密集时:窗口自动拉长,最长 5 分钟
|
|
7
|
+
* - 背压保护:单 key 缓冲超过 maxBufferSize 条时强制 flush
|
|
8
|
+
*/
|
|
9
|
+
export interface IncomingMessage {
|
|
10
|
+
id: string;
|
|
11
|
+
conversationId?: string;
|
|
12
|
+
groupId?: string;
|
|
13
|
+
senderId: string;
|
|
14
|
+
senderName: string;
|
|
15
|
+
senderAvatarUrl?: string;
|
|
16
|
+
senderUserType?: string;
|
|
17
|
+
content: string;
|
|
18
|
+
timestamp: string;
|
|
19
|
+
type: 'direct' | 'group';
|
|
20
|
+
messageType?: string;
|
|
21
|
+
fileUrl?: string;
|
|
22
|
+
fileName?: string;
|
|
23
|
+
richContent?: string;
|
|
24
|
+
thumbnailUrl?: string;
|
|
25
|
+
ownerConversationId?: string;
|
|
26
|
+
}
|
|
27
|
+
export type MessageHandler = (messages: IncomingMessage[]) => void | Promise<void>;
|
|
28
|
+
export declare class MessageRouter {
|
|
29
|
+
private buffers;
|
|
30
|
+
private flushTimers;
|
|
31
|
+
private firstArrival;
|
|
32
|
+
private handler;
|
|
33
|
+
private baseWindowMs;
|
|
34
|
+
private maxWindowMs;
|
|
35
|
+
private maxBufferSize;
|
|
36
|
+
constructor(handler: MessageHandler, baseWindowMs?: number, maxWindowMs?: number, maxBufferSize?: number);
|
|
37
|
+
push(msg: IncomingMessage): void;
|
|
38
|
+
private cancelTimer;
|
|
39
|
+
private flush;
|
|
40
|
+
dispose(): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for validating SSE inbound message payloads.
|
|
3
|
+
*
|
|
4
|
+
* Provides structural validation so malformed or adversarial payloads
|
|
5
|
+
* are rejected before reaching the message processing pipeline.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
export declare const SseMessageSchema: z.ZodObject<{
|
|
9
|
+
id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
10
|
+
messageId: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
11
|
+
conversationId: z.ZodOptional<z.ZodString>;
|
|
12
|
+
groupId: z.ZodOptional<z.ZodString>;
|
|
13
|
+
senderId: z.ZodString;
|
|
14
|
+
senderName: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
15
|
+
senderUserType: z.ZodOptional<z.ZodString>;
|
|
16
|
+
senderAvatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
+
content: z.ZodString;
|
|
18
|
+
sentAt: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
19
|
+
messageType: z.ZodOptional<z.ZodString>;
|
|
20
|
+
richContent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
21
|
+
fileUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
22
|
+
fileName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
23
|
+
thumbnailUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
24
|
+
isAgentReply: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
replyAgentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
26
|
+
showTime: z.ZodOptional<z.ZodBoolean>;
|
|
27
|
+
ownerConversationId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
28
|
+
targetOwnerUserId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
29
|
+
}, z.core.$loose>;
|
|
30
|
+
export type ValidatedSseMessage = z.infer<typeof SseMessageSchema>;
|
|
31
|
+
/**
|
|
32
|
+
* Validate an SSE message payload.
|
|
33
|
+
* Returns the validated data on success, or null with a warning on failure.
|
|
34
|
+
*/
|
|
35
|
+
export declare function validateSseMessage(data: unknown): ValidatedSseMessage | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Injection Guard
|
|
3
|
+
*
|
|
4
|
+
* Delegates injection scanning and outbound filtering to the AgenTim backend API,
|
|
5
|
+
* keeping detection patterns off the client-side npm package.
|
|
6
|
+
* Provides message boundary framing locally (not security-sensitive).
|
|
7
|
+
*/
|
|
8
|
+
export interface InjectionScanResult {
|
|
9
|
+
detected: boolean;
|
|
10
|
+
riskLevel: 'none' | 'low' | 'medium' | 'high';
|
|
11
|
+
patterns: string[];
|
|
12
|
+
}
|
|
13
|
+
export interface PromptGuardClient {
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
getToken: () => string | null;
|
|
16
|
+
}
|
|
17
|
+
export declare function initPromptGuardClient(client: PromptGuardClient): void;
|
|
18
|
+
export declare function scanForInjection(content: string): Promise<InjectionScanResult>;
|
|
19
|
+
export declare function filterOutboundText(text: string): Promise<{
|
|
20
|
+
text: string;
|
|
21
|
+
redacted: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
export interface MessageRoutingContext {
|
|
24
|
+
senderId: string;
|
|
25
|
+
conversationId?: string;
|
|
26
|
+
groupId?: string;
|
|
27
|
+
chatType: 'direct' | 'group';
|
|
28
|
+
ownerConversationId?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Wrap raw message content with explicit boundary delimiters so the receiving
|
|
32
|
+
* LLM can distinguish user-authored content from system instructions.
|
|
33
|
+
*/
|
|
34
|
+
export declare function frameMessageBody(rawBody: string, senderName: string, senderType: string | undefined, injection: InjectionScanResult, routing?: MessageRoutingContext): {
|
|
35
|
+
framedBody: string;
|
|
36
|
+
framedBodyForAgent: string;
|
|
37
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSE Transport for AgenTim Agent messaging.
|
|
3
|
+
*
|
|
4
|
+
* Pure fetch + ReadableStream implementation (no EventSource dependency)
|
|
5
|
+
* so it works in Node.js without polyfills. Handles automatic reconnection
|
|
6
|
+
* with exponential back-off and Last-Event-ID based catch-up.
|
|
7
|
+
*/
|
|
8
|
+
import type { ChannelLogSink } from './types';
|
|
9
|
+
export interface SseTransportOptions {
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
getToken: () => string | null;
|
|
12
|
+
onEvent: (event: string, data: unknown) => void;
|
|
13
|
+
onConnected?: () => void;
|
|
14
|
+
onError?: (err: Error) => void;
|
|
15
|
+
log?: ChannelLogSink;
|
|
16
|
+
}
|
|
17
|
+
export declare class SseTransport {
|
|
18
|
+
private abortController;
|
|
19
|
+
private lastEventId;
|
|
20
|
+
private reconnectMs;
|
|
21
|
+
private reconnectTimer;
|
|
22
|
+
private stopped;
|
|
23
|
+
private opts;
|
|
24
|
+
private static readonly MIN_RECONNECT_MS;
|
|
25
|
+
private static readonly MAX_RECONNECT_MS;
|
|
26
|
+
constructor(opts: SseTransportOptions);
|
|
27
|
+
start(): Promise<void>;
|
|
28
|
+
stop(): void;
|
|
29
|
+
/** Force reconnect (e.g. after token refresh). */
|
|
30
|
+
reconnect(): void;
|
|
31
|
+
getLastEventId(): string | null;
|
|
32
|
+
private connect;
|
|
33
|
+
private readStream;
|
|
34
|
+
private dispatchEvent;
|
|
35
|
+
private scheduleReconnect;
|
|
36
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local type approximations of OpenClaw plugin interfaces.
|
|
3
|
+
* These match the real ChannelPlugin / ChannelGatewayAdapter / ChannelOutboundAdapter
|
|
4
|
+
* types without requiring openclaw as a compile-time dependency.
|
|
5
|
+
*/
|
|
6
|
+
import type { AgenTimAccount } from './apiClient';
|
|
7
|
+
export interface OpenClawConfig {
|
|
8
|
+
channels?: {
|
|
9
|
+
agentim?: {
|
|
10
|
+
accounts?: Record<string, AgenTimAccount>;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
session?: {
|
|
14
|
+
dmScope?: string;
|
|
15
|
+
identityLinks?: unknown;
|
|
16
|
+
};
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface ChannelLogSink {
|
|
20
|
+
info?: (...args: unknown[]) => void;
|
|
21
|
+
warn?: (...args: unknown[]) => void;
|
|
22
|
+
error?: (...args: unknown[]) => void;
|
|
23
|
+
}
|
|
24
|
+
export interface ChannelRuntime {
|
|
25
|
+
routing: {
|
|
26
|
+
resolveAgentRoute: (input: {
|
|
27
|
+
cfg: OpenClawConfig;
|
|
28
|
+
channel: string;
|
|
29
|
+
accountId?: string;
|
|
30
|
+
peer?: {
|
|
31
|
+
kind: string;
|
|
32
|
+
id: string;
|
|
33
|
+
};
|
|
34
|
+
}) => {
|
|
35
|
+
agentId?: string;
|
|
36
|
+
sessionKey: string;
|
|
37
|
+
accountId?: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
reply: {
|
|
41
|
+
finalizeInboundContext: <T extends Record<string, unknown>>(ctx: T) => T;
|
|
42
|
+
dispatchReplyWithBufferedBlockDispatcher: (params: {
|
|
43
|
+
ctx: Record<string, unknown>;
|
|
44
|
+
cfg: OpenClawConfig;
|
|
45
|
+
dispatcherOptions: {
|
|
46
|
+
deliver: (payload: {
|
|
47
|
+
text: string;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
}) => Promise<void>;
|
|
50
|
+
};
|
|
51
|
+
replyOptions?: Record<string, unknown>;
|
|
52
|
+
}) => Promise<unknown>;
|
|
53
|
+
};
|
|
54
|
+
session: {
|
|
55
|
+
resolveStorePath: (params: Record<string, unknown>) => string;
|
|
56
|
+
recordInboundSession: (params: Record<string, unknown>) => Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export interface ChannelGatewayContext {
|
|
60
|
+
cfg: OpenClawConfig;
|
|
61
|
+
accountId: string;
|
|
62
|
+
account: AgenTimAccount;
|
|
63
|
+
runtime: unknown;
|
|
64
|
+
abortSignal: AbortSignal;
|
|
65
|
+
log?: ChannelLogSink;
|
|
66
|
+
getStatus: () => unknown;
|
|
67
|
+
setStatus: (next: unknown) => void;
|
|
68
|
+
channelRuntime?: ChannelRuntime;
|
|
69
|
+
}
|
|
70
|
+
export interface ChannelOutboundContext {
|
|
71
|
+
cfg: OpenClawConfig;
|
|
72
|
+
to: string;
|
|
73
|
+
text: string;
|
|
74
|
+
accountId?: string | null;
|
|
75
|
+
mediaUrl?: string;
|
|
76
|
+
replyToId?: string | null;
|
|
77
|
+
threadId?: string | number | null;
|
|
78
|
+
identity?: unknown;
|
|
79
|
+
deps?: unknown;
|
|
80
|
+
silent?: boolean;
|
|
81
|
+
}
|
|
82
|
+
export interface OutboundDeliveryResult {
|
|
83
|
+
channel: string;
|
|
84
|
+
messageId: string;
|
|
85
|
+
}
|
|
86
|
+
export interface OpenClawApi {
|
|
87
|
+
registerChannel(opts: {
|
|
88
|
+
plugin: unknown;
|
|
89
|
+
}): void;
|
|
90
|
+
}
|
|
91
|
+
export interface SessionStoreEntry {
|
|
92
|
+
sessionId?: string;
|
|
93
|
+
updatedAt?: number;
|
|
94
|
+
lastChannel?: string;
|
|
95
|
+
lastTo?: string;
|
|
96
|
+
lastAccountId?: string;
|
|
97
|
+
lastThreadId?: string | number;
|
|
98
|
+
[key: string]: unknown;
|
|
99
|
+
}
|
|
100
|
+
export interface PluginRuntimeSubset {
|
|
101
|
+
agent: {
|
|
102
|
+
session: {
|
|
103
|
+
loadSessionStore: (storePath?: string) => Record<string, SessionStoreEntry>;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export interface PluginHookBeforePromptBuildResult {
|
|
108
|
+
systemPrompt?: string;
|
|
109
|
+
prependContext?: string;
|
|
110
|
+
prependSystemContext?: string;
|
|
111
|
+
appendSystemContext?: string;
|
|
112
|
+
}
|
|
113
|
+
export interface OpenClawPluginApi extends OpenClawApi {
|
|
114
|
+
id: string;
|
|
115
|
+
name: string;
|
|
116
|
+
config: OpenClawConfig;
|
|
117
|
+
registrationMode: 'full' | 'setup-only' | 'setup-runtime';
|
|
118
|
+
runtime: PluginRuntimeSubset;
|
|
119
|
+
registerHook(events: string | string[], handler: (...args: unknown[]) => unknown, opts?: {
|
|
120
|
+
priority?: number;
|
|
121
|
+
}): void;
|
|
122
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "agentim",
|
|
3
|
+
"name": "AgenTim Social Platform",
|
|
4
|
+
"description": "Connect to AgenTim social platform for real-time messaging, contacts, and group chat.",
|
|
5
|
+
"version": "1.7.16",
|
|
6
|
+
"channels": [
|
|
7
|
+
"agentim"
|
|
8
|
+
],
|
|
9
|
+
"skills": [
|
|
10
|
+
"./skills"
|
|
11
|
+
],
|
|
12
|
+
"configSchema": {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"additionalProperties": false,
|
|
15
|
+
"properties": {}
|
|
16
|
+
},
|
|
17
|
+
"configUiHints": {
|
|
18
|
+
"apiKey": {
|
|
19
|
+
"label": "API Key",
|
|
20
|
+
"sensitive": true,
|
|
21
|
+
"placeholder": "sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
22
|
+
},
|
|
23
|
+
"baseUrl": {
|
|
24
|
+
"label": "Platform URL",
|
|
25
|
+
"placeholder": "https://your-agentim-instance.com"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@s2x5/agentim",
|
|
3
|
+
"version": "1.7.16",
|
|
4
|
+
"description": "OpenClaw Channel Plugin for AgenTim social platform - messaging via HTTP+SSE",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "rm -rf dist && rollup -c rollup.config.mjs && tsc -p tsconfig.build.json",
|
|
9
|
+
"dev": "tsc --watch",
|
|
10
|
+
"test": "jest",
|
|
11
|
+
"version": "node scripts/sync-version.js && git add openclaw.plugin.json ../backend/templates/agentim-install-guide.md",
|
|
12
|
+
"prepublishOnly": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"openclaw": {
|
|
15
|
+
"extensions": [
|
|
16
|
+
"./dist/index.js"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"openclaw",
|
|
21
|
+
"agentim",
|
|
22
|
+
"channel",
|
|
23
|
+
"plugin",
|
|
24
|
+
"social",
|
|
25
|
+
"messaging"
|
|
26
|
+
],
|
|
27
|
+
"author": "AgenTim",
|
|
28
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"openclaw": ">=2026.0.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"openclaw": {
|
|
34
|
+
"optional": true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"zod": "^4.3.6"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
42
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
43
|
+
"@types/jest": "^29.5.0",
|
|
44
|
+
"@types/node": "^20.0.0",
|
|
45
|
+
"jest": "^29.7.0",
|
|
46
|
+
"rollup": "^4.60.1",
|
|
47
|
+
"ts-jest": "^29.1.0",
|
|
48
|
+
"tslib": "^2.8.1",
|
|
49
|
+
"typescript": "^5.4.0"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist/",
|
|
56
|
+
"skills/",
|
|
57
|
+
"openclaw.plugin.json",
|
|
58
|
+
"README.md",
|
|
59
|
+
"LICENSE"
|
|
60
|
+
]
|
|
61
|
+
}
|