@gloablehive/celphone-wechat-plugin 1.0.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/INSTALL.md +231 -0
- package/README.md +259 -0
- package/dist/index-simple.js +9 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +77 -0
- package/dist/mock-server.d.ts +6 -0
- package/dist/mock-server.js +203 -0
- package/dist/openclaw.plugin.json +96 -0
- package/dist/setup-entry.d.ts +9 -0
- package/dist/setup-entry.js +8 -0
- package/dist/src/cache/compactor.d.ts +36 -0
- package/dist/src/cache/compactor.js +154 -0
- package/dist/src/cache/extractor.d.ts +48 -0
- package/dist/src/cache/extractor.js +120 -0
- package/dist/src/cache/index.d.ts +15 -0
- package/dist/src/cache/index.js +16 -0
- package/dist/src/cache/indexer.d.ts +41 -0
- package/dist/src/cache/indexer.js +262 -0
- package/dist/src/cache/manager.d.ts +113 -0
- package/dist/src/cache/manager.js +271 -0
- package/dist/src/cache/message-queue.d.ts +59 -0
- package/dist/src/cache/message-queue.js +147 -0
- package/dist/src/cache/saas-connector.d.ts +94 -0
- package/dist/src/cache/saas-connector.js +289 -0
- package/dist/src/cache/syncer.d.ts +60 -0
- package/dist/src/cache/syncer.js +177 -0
- package/dist/src/cache/types.d.ts +198 -0
- package/dist/src/cache/types.js +43 -0
- package/dist/src/cache/writer.d.ts +81 -0
- package/dist/src/cache/writer.js +461 -0
- package/dist/src/channel.d.ts +65 -0
- package/dist/src/channel.js +334 -0
- package/dist/src/client.d.ts +280 -0
- package/dist/src/client.js +248 -0
- package/index-simple.ts +11 -0
- package/index.ts +89 -0
- package/mock-server.ts +237 -0
- package/openclaw.plugin.json +98 -0
- package/package.json +37 -0
- package/setup-entry.ts +10 -0
- package/src/channel.ts +398 -0
- package/src/client.ts +412 -0
- package/test-cache.ts +260 -0
- package/test-integration.ts +319 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Types - Type definitions for WeChat cache system
|
|
3
|
+
*
|
|
4
|
+
* Aligned with Claude Code memory system:
|
|
5
|
+
* - 4 types: user, conversation, template, policy
|
|
6
|
+
* - YAML frontmatter format
|
|
7
|
+
* - Per-account isolation
|
|
8
|
+
*/
|
|
9
|
+
export type CacheType = 'user' | 'conversation' | 'template' | 'policy';
|
|
10
|
+
export type ConversationSubtype = 'friend' | 'chatroom';
|
|
11
|
+
export type MessageDirection = 'inbound' | 'outbound';
|
|
12
|
+
export interface CacheFrontmatter {
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
type: CacheType;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ConversationFrontmatter extends CacheFrontmatter {
|
|
20
|
+
type: 'conversation';
|
|
21
|
+
subtype: ConversationSubtype;
|
|
22
|
+
wechatId: string;
|
|
23
|
+
accountId: string;
|
|
24
|
+
accountWechatId: string;
|
|
25
|
+
lastContact: string;
|
|
26
|
+
messageCount: number;
|
|
27
|
+
}
|
|
28
|
+
export interface UserProfileFrontmatter extends CacheFrontmatter {
|
|
29
|
+
type: 'user';
|
|
30
|
+
wechatId: string;
|
|
31
|
+
accountId: string;
|
|
32
|
+
tags: string[];
|
|
33
|
+
addedAt: string;
|
|
34
|
+
lastContact: string;
|
|
35
|
+
}
|
|
36
|
+
export interface TemplateFrontmatter extends CacheFrontmatter {
|
|
37
|
+
type: 'template';
|
|
38
|
+
trigger?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface PolicyFrontmatter extends CacheFrontmatter {
|
|
41
|
+
type: 'policy';
|
|
42
|
+
version: string;
|
|
43
|
+
effectiveFrom: string;
|
|
44
|
+
}
|
|
45
|
+
export interface WeChatMessage {
|
|
46
|
+
messageId: string;
|
|
47
|
+
msgSvrId?: string;
|
|
48
|
+
accountId: string;
|
|
49
|
+
conversationType: ConversationSubtype;
|
|
50
|
+
conversationId: string;
|
|
51
|
+
senderId: string;
|
|
52
|
+
content: string;
|
|
53
|
+
messageType: number;
|
|
54
|
+
timestamp: number;
|
|
55
|
+
isSelf: boolean;
|
|
56
|
+
direction: MessageDirection;
|
|
57
|
+
}
|
|
58
|
+
export interface MessageBlock {
|
|
59
|
+
timestamp: string;
|
|
60
|
+
sender: string;
|
|
61
|
+
content: string;
|
|
62
|
+
}
|
|
63
|
+
export interface UserProfile {
|
|
64
|
+
wechatId: string;
|
|
65
|
+
accountId: string;
|
|
66
|
+
remark: string;
|
|
67
|
+
nickName: string;
|
|
68
|
+
avatarUrl?: string;
|
|
69
|
+
tags: string[];
|
|
70
|
+
customFields: Record<string, any>;
|
|
71
|
+
conversationSummary?: string;
|
|
72
|
+
preferenceHints?: string;
|
|
73
|
+
riskFlags: string[];
|
|
74
|
+
addedAt: string;
|
|
75
|
+
lastContact: string;
|
|
76
|
+
}
|
|
77
|
+
export interface ProfileUpdate {
|
|
78
|
+
remark?: string;
|
|
79
|
+
tags?: string[];
|
|
80
|
+
customFields?: Record<string, any>;
|
|
81
|
+
conversationSummary?: string;
|
|
82
|
+
preferenceHints?: string;
|
|
83
|
+
riskFlags?: string[];
|
|
84
|
+
}
|
|
85
|
+
export interface SessionMemory {
|
|
86
|
+
sessionTitle: string;
|
|
87
|
+
currentState: string;
|
|
88
|
+
taskSpecification: string;
|
|
89
|
+
filesAndFunctions: string;
|
|
90
|
+
workflow: string;
|
|
91
|
+
errorsAndCorrections: string;
|
|
92
|
+
codebaseDocumentation: string;
|
|
93
|
+
learnings: string;
|
|
94
|
+
keyResults: string;
|
|
95
|
+
worklog: string;
|
|
96
|
+
}
|
|
97
|
+
export interface MemoryItem {
|
|
98
|
+
path: string;
|
|
99
|
+
name: string;
|
|
100
|
+
description: string;
|
|
101
|
+
type: CacheType;
|
|
102
|
+
lastModified: number;
|
|
103
|
+
relevanceScore?: number;
|
|
104
|
+
}
|
|
105
|
+
export interface MemorySearchResult {
|
|
106
|
+
items: MemoryItem[];
|
|
107
|
+
query: string;
|
|
108
|
+
searchTime: number;
|
|
109
|
+
}
|
|
110
|
+
export interface ExtractionResult {
|
|
111
|
+
summary: string;
|
|
112
|
+
keyPoints: string[];
|
|
113
|
+
userProfileUpdate: Partial<ProfileUpdate>;
|
|
114
|
+
learnings: string;
|
|
115
|
+
actionItems?: string[];
|
|
116
|
+
}
|
|
117
|
+
export interface CompactConfig {
|
|
118
|
+
microCompactKeep: number;
|
|
119
|
+
microCompactThreshold: number;
|
|
120
|
+
autoCompactThreshold: number;
|
|
121
|
+
fullCompactThreshold: number;
|
|
122
|
+
sessionCompactThreshold: number;
|
|
123
|
+
}
|
|
124
|
+
export declare const DEFAULT_COMPACT_CONFIG: CompactConfig;
|
|
125
|
+
export type SyncMode = 'realtime' | 'interval' | 'manual';
|
|
126
|
+
export interface SyncConfig {
|
|
127
|
+
databaseUrl: string;
|
|
128
|
+
syncMode: SyncMode;
|
|
129
|
+
syncIntervalMs: number;
|
|
130
|
+
lastSyncTimestamp: number;
|
|
131
|
+
}
|
|
132
|
+
export interface SyncResult {
|
|
133
|
+
recordsSynced: number;
|
|
134
|
+
duration: number;
|
|
135
|
+
errors: string[];
|
|
136
|
+
}
|
|
137
|
+
export interface SyncLog {
|
|
138
|
+
id: string;
|
|
139
|
+
syncType: 'full' | 'incremental';
|
|
140
|
+
startedAt: number;
|
|
141
|
+
completedAt?: number;
|
|
142
|
+
recordsCount: number;
|
|
143
|
+
status: 'pending' | 'completed' | 'failed';
|
|
144
|
+
error?: string;
|
|
145
|
+
}
|
|
146
|
+
export interface SAASConfig {
|
|
147
|
+
apiBaseUrl: string;
|
|
148
|
+
apiKey: string;
|
|
149
|
+
timeout: number;
|
|
150
|
+
retryAttempts: number;
|
|
151
|
+
offlineThreshold: number;
|
|
152
|
+
}
|
|
153
|
+
export interface ConnectionStatus {
|
|
154
|
+
isOnline: boolean;
|
|
155
|
+
lastConnected: number;
|
|
156
|
+
consecutiveFailures: number;
|
|
157
|
+
offlineDuration: number;
|
|
158
|
+
}
|
|
159
|
+
export declare const DEFAULT_SAAS_CONFIG: SAASConfig;
|
|
160
|
+
export type QueuedMessageStatus = 'pending' | 'synced' | 'failed';
|
|
161
|
+
export interface QueuedMessage {
|
|
162
|
+
id: string;
|
|
163
|
+
message: WeChatMessage;
|
|
164
|
+
retryCount: number;
|
|
165
|
+
createdAt: number;
|
|
166
|
+
status: QueuedMessageStatus;
|
|
167
|
+
lastRetryAt?: number;
|
|
168
|
+
error?: string;
|
|
169
|
+
}
|
|
170
|
+
export interface WeChatAccount {
|
|
171
|
+
accountId: string;
|
|
172
|
+
wechatAccountId: string;
|
|
173
|
+
wechatId: string;
|
|
174
|
+
nickName: string;
|
|
175
|
+
enabled: boolean;
|
|
176
|
+
}
|
|
177
|
+
export interface IndexEntry {
|
|
178
|
+
path: string;
|
|
179
|
+
name: string;
|
|
180
|
+
description: string;
|
|
181
|
+
type: CacheType;
|
|
182
|
+
lastContact?: string;
|
|
183
|
+
messageCount?: number;
|
|
184
|
+
}
|
|
185
|
+
export interface AccountIndex {
|
|
186
|
+
accountId: string;
|
|
187
|
+
wechatId: string;
|
|
188
|
+
entries: IndexEntry[];
|
|
189
|
+
totalFriends: number;
|
|
190
|
+
totalChatrooms: number;
|
|
191
|
+
lastUpdated: number;
|
|
192
|
+
}
|
|
193
|
+
export declare function getAccountCachePath(basePath: string, accountId: string): string;
|
|
194
|
+
export declare function getFriendPath(basePath: string, accountId: string, wechatId: string): string;
|
|
195
|
+
export declare function getChatroomPath(basePath: string, accountId: string, chatroomId: string): string;
|
|
196
|
+
export declare function getProfilePath(basePath: string, accountId: string, wechatId: string): string;
|
|
197
|
+
export declare function getMonthlyFilePath(wechatId: string, date: Date): string;
|
|
198
|
+
export declare function getConversationId(wechatId: string, accountId: string): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Types - Type definitions for WeChat cache system
|
|
3
|
+
*
|
|
4
|
+
* Aligned with Claude Code memory system:
|
|
5
|
+
* - 4 types: user, conversation, template, policy
|
|
6
|
+
* - YAML frontmatter format
|
|
7
|
+
* - Per-account isolation
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_COMPACT_CONFIG = {
|
|
10
|
+
microCompactKeep: 10,
|
|
11
|
+
microCompactThreshold: 5000,
|
|
12
|
+
autoCompactThreshold: 167000,
|
|
13
|
+
fullCompactThreshold: 180000,
|
|
14
|
+
sessionCompactThreshold: 100000,
|
|
15
|
+
};
|
|
16
|
+
export const DEFAULT_SAAS_CONFIG = {
|
|
17
|
+
apiBaseUrl: '',
|
|
18
|
+
apiKey: '',
|
|
19
|
+
timeout: 5000,
|
|
20
|
+
retryAttempts: 3,
|
|
21
|
+
offlineThreshold: 5 * 60 * 1000, // 5 minutes
|
|
22
|
+
};
|
|
23
|
+
// ========== File Path Helpers ==========
|
|
24
|
+
export function getAccountCachePath(basePath, accountId) {
|
|
25
|
+
return `${basePath}/accounts/${accountId}`;
|
|
26
|
+
}
|
|
27
|
+
export function getFriendPath(basePath, accountId, wechatId) {
|
|
28
|
+
return `${basePath}/accounts/${accountId}/friends/${wechatId}`;
|
|
29
|
+
}
|
|
30
|
+
export function getChatroomPath(basePath, accountId, chatroomId) {
|
|
31
|
+
return `${basePath}/accounts/${accountId}/chatrooms/${chatroomId}`;
|
|
32
|
+
}
|
|
33
|
+
export function getProfilePath(basePath, accountId, wechatId) {
|
|
34
|
+
return `${basePath}/accounts/${accountId}/profiles/${wechatId}.md`;
|
|
35
|
+
}
|
|
36
|
+
export function getMonthlyFilePath(wechatId, date) {
|
|
37
|
+
const year = date.getFullYear();
|
|
38
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
39
|
+
return `${year}-${month}.md`;
|
|
40
|
+
}
|
|
41
|
+
export function getConversationId(wechatId, accountId) {
|
|
42
|
+
return `${accountId}:${wechatId}`;
|
|
43
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache Writer - File writing with monthly partition
|
|
3
|
+
*
|
|
4
|
+
* Aligned with Claude Code memory system:
|
|
5
|
+
* - YAML frontmatter for metadata
|
|
6
|
+
* - Markdown content
|
|
7
|
+
* - Monthly file partitioning
|
|
8
|
+
*/
|
|
9
|
+
import { WeChatMessage, ConversationSubtype, UserProfile, SessionMemory } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Get or create conversation directory
|
|
12
|
+
*/
|
|
13
|
+
export declare function ensureConversationDir(basePath: string, accountId: string, subtype: ConversationSubtype, conversationId: string): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Get monthly conversation file path
|
|
16
|
+
*/
|
|
17
|
+
export declare function getConversationFilePath(basePath: string, accountId: string, subtype: ConversationSubtype, conversationId: string, date: Date): string;
|
|
18
|
+
/**
|
|
19
|
+
* Check if conversation file exists
|
|
20
|
+
*/
|
|
21
|
+
export declare function conversationFileExists(filePath: string): Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Read conversation file
|
|
24
|
+
*/
|
|
25
|
+
export declare function readConversationFile(filePath: string): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Create new conversation file with frontmatter
|
|
28
|
+
*/
|
|
29
|
+
export declare function createConversationFile(filePath: string, wechatId: string, accountId: string, accountWechatId: string, subtype: ConversationSubtype): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Append message to conversation file
|
|
32
|
+
*/
|
|
33
|
+
export declare function appendMessageToConversation(filePath: string, message: WeChatMessage, remark?: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Get profile file path
|
|
36
|
+
*/
|
|
37
|
+
export declare function getProfileFilePath(basePath: string, accountId: string, wechatId: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Create or update profile file
|
|
40
|
+
*/
|
|
41
|
+
export declare function writeProfile(filePath: string, profile: UserProfile): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Read profile file
|
|
44
|
+
*/
|
|
45
|
+
export declare function readProfile(filePath: string): Promise<UserProfile | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Update profile fields
|
|
48
|
+
*/
|
|
49
|
+
export declare function updateProfileFields(filePath: string, updates: Partial<UserProfile>): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Get session memory file path
|
|
52
|
+
*/
|
|
53
|
+
export declare function getSessionMemoryPath(basePath: string, accountId: string, conversationId: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Write session memory (aligned with Claude Code 10-section template)
|
|
56
|
+
*/
|
|
57
|
+
export declare function writeSessionMemory(filePath: string, session: SessionMemory): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Read session memory
|
|
60
|
+
*/
|
|
61
|
+
export declare function readSessionMemory(filePath: string): Promise<SessionMemory | null>;
|
|
62
|
+
/**
|
|
63
|
+
* Get summary file path
|
|
64
|
+
*/
|
|
65
|
+
export declare function getSummaryPath(basePath: string, accountId: string, subtype: ConversationSubtype, conversationId: string, yearMonth: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* Write AI summary
|
|
68
|
+
*/
|
|
69
|
+
export declare function writeSummary(filePath: string, summary: string, keyPoints: string[], learnings: string, actionItems?: string[]): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Ensure directory exists
|
|
72
|
+
*/
|
|
73
|
+
export declare function ensureDir(dirPath: string): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Delete file if exists
|
|
76
|
+
*/
|
|
77
|
+
export declare function deleteFile(filePath: string): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* List files in directory
|
|
80
|
+
*/
|
|
81
|
+
export declare function listFiles(dirPath: string, pattern?: string): Promise<string[]>;
|