mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 01:05:30 +08:00
feat: 新增拓展中心功能, 提供 关键词回复 去水印模板
This commit is contained in:
1 parent
aca103cb96
commit
b9ad4e1d71
85 files changed
+14750
-106
No files matched your search
@@ -0,0 +1,27 @@
|
||||
# @tracememo/extension-sdk
|
||||
|
||||
TraceMemo 扩展 SDK v1 的**类型定义**。运行期不需要安装或打包这个包:宿主在扩展后台进程里注入全局 `tm`。
|
||||
|
||||
## 用法
|
||||
|
||||
把 `index.d.ts` 复制进扩展仓库(或作为 devDependency),然后:
|
||||
|
||||
```ts
|
||||
import type { TraceMemoApi } from './extension-sdk'
|
||||
|
||||
module.exports = function activate(tm: TraceMemoApi): void {
|
||||
tm.events.on('message.received', async (event) => {
|
||||
if (event.isSelf || event.type !== 'text') return
|
||||
if (!event.text?.includes('你好')) return
|
||||
await tm.wechat.send({ to: event.conversationId, text: '你好呀!', dedupeKey: event.eventId })
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
## 约定
|
||||
|
||||
- 所有能力都要在 `manifest.json` 里声明权限;未声明的调用返回 `PERMISSION_DENIED`。
|
||||
- 后台是**独立 Node 子进程**,不是强沙箱:安装即表示信任该扩展代码。
|
||||
- 页面运行在 `sandbox="allow-scripts"` 的 iframe 里,只能通过 postMessage 调用
|
||||
`storage.*` / `capabilities.get` / `extension.info`,不能发送微信消息。
|
||||
- 发送永远经过宿主 Gateway:权限、授权校验、限流、审计与幂等都在宿主侧执行。
|
||||
Vendored
+188
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
* TraceMemo 扩展 SDK v1 —— 仅类型定义。
|
||||
*
|
||||
* 运行期没有这个包:宿主在后台子进程里注入全局 `tm`,扩展入口只需要
|
||||
* `module.exports = function activate(tm: TraceMemoApi) {}`。
|
||||
* 把本文件放进扩展仓库即可获得补全与类型检查。
|
||||
*/
|
||||
|
||||
export type ExtensionMessageType =
|
||||
| 'text'
|
||||
| 'image'
|
||||
| 'voice'
|
||||
| 'video'
|
||||
| 'sticker'
|
||||
| 'file'
|
||||
| 'link'
|
||||
| 'system'
|
||||
| 'other'
|
||||
|
||||
export interface TraceMemoMessageEvent {
|
||||
/** 同一条微信消息稳定不变:`message:<sha1(sessionId:localId)>`。 */
|
||||
eventId: string
|
||||
accountId: string
|
||||
conversationId: string
|
||||
messageId: string
|
||||
senderId?: string
|
||||
senderName?: string
|
||||
isGroup: boolean
|
||||
isSelf: boolean
|
||||
type: ExtensionMessageType
|
||||
text?: string
|
||||
/** 真正 @ 到当前登录账号,不是正文里的 `@昵称`。 */
|
||||
mentionsMe: boolean
|
||||
/** epoch 毫秒。 */
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
export interface TraceMemoQueriedMessage {
|
||||
messageId: string
|
||||
conversationId: string
|
||||
senderId?: string
|
||||
senderName?: string
|
||||
isSelf: boolean
|
||||
type: string
|
||||
text?: string
|
||||
/** epoch 毫秒。 */
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
export interface TraceMemoSendTextRequest {
|
||||
/** 缺省为 text。 */
|
||||
type?: 'text'
|
||||
/** 群为 `xxx@chatroom`,私聊为 wxid。 */
|
||||
to: string
|
||||
text: string
|
||||
at?: Record<string, string>
|
||||
/** 相同键的重复请求会被 Gateway 审计短路。 */
|
||||
dedupeKey?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片发送。
|
||||
*/
|
||||
export interface TraceMemoSendImageRequest {
|
||||
type: 'image'
|
||||
to: string
|
||||
path: string
|
||||
dedupeKey?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 视频发送。原生 Host 以 `{toWxid, type:'video', msg:<路径>}` 提交。
|
||||
* 路径必须位于扩展数据目录或系统临时目录。
|
||||
*/
|
||||
export interface TraceMemoSendVideoRequest {
|
||||
type: 'video'
|
||||
to: string
|
||||
path: string
|
||||
dedupeKey?: string
|
||||
}
|
||||
|
||||
export type TraceMemoSendRequest =
|
||||
| TraceMemoSendTextRequest
|
||||
| TraceMemoSendImageRequest
|
||||
| TraceMemoSendVideoRequest
|
||||
|
||||
export interface TraceMemoAutomationActionDefinition {
|
||||
id: string
|
||||
title: string
|
||||
description?: string
|
||||
inputSchema?: {
|
||||
type: 'object'
|
||||
properties?: Record<string, { type?: 'string' | 'number' | 'boolean'; description?: string }>
|
||||
required?: string[]
|
||||
}
|
||||
handler: (input: Record<string, unknown>) => unknown | Promise<unknown>
|
||||
}
|
||||
|
||||
export interface TraceMemoAutomationActionOutput {
|
||||
success: boolean
|
||||
output?: Record<string, unknown>
|
||||
/** 宿主经 Gateway 发回原会话;扩展自己不发消息。 */
|
||||
reply?: { type: 'text'; text: string; at?: Record<string, string> }
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface TraceMemoCapabilities {
|
||||
extensionId: string
|
||||
enabled: boolean
|
||||
permissions: string[]
|
||||
platform: string
|
||||
databaseReady: boolean
|
||||
send: {
|
||||
supported: boolean
|
||||
ready: boolean
|
||||
canSendText: boolean
|
||||
canSendImage: boolean
|
||||
canSendVideo: boolean
|
||||
licensed: boolean
|
||||
message: string
|
||||
}
|
||||
ai: { configured: boolean; modelName: string }
|
||||
}
|
||||
|
||||
export interface TraceMemoApi {
|
||||
extension: {
|
||||
readonly id: string
|
||||
/** 扩展私有数据目录;下载与生成的文件应放在这里。 */
|
||||
readonly dataDir: string
|
||||
readonly permissions: string[]
|
||||
}
|
||||
events: {
|
||||
on(
|
||||
name: 'message.received',
|
||||
handler: (event: TraceMemoMessageEvent) => void | Promise<void>
|
||||
): () => void
|
||||
off(
|
||||
name: 'message.received',
|
||||
handler: (event: TraceMemoMessageEvent) => void | Promise<void>
|
||||
): void
|
||||
}
|
||||
messages: {
|
||||
query(request: {
|
||||
conversationId: string
|
||||
/** epoch 毫秒;默认最近 24 小时。 */
|
||||
startTime?: number
|
||||
/** epoch 毫秒;默认现在。 */
|
||||
endTime?: number
|
||||
limit?: number
|
||||
}): Promise<{ messages: TraceMemoQueriedMessage[] }>
|
||||
}
|
||||
wechat: {
|
||||
send(request: TraceMemoSendRequest): Promise<{ actionId: string; status: 'sent' }>
|
||||
}
|
||||
ai: {
|
||||
chat(messages: Array<{ role: string; content: string }>): Promise<{ text: string }>
|
||||
}
|
||||
storage: {
|
||||
get(key: string): Promise<unknown>
|
||||
set(key: string, value: unknown): Promise<void>
|
||||
remove(key: string): Promise<boolean>
|
||||
list(): Promise<Array<{ key: string; value: unknown }>>
|
||||
}
|
||||
automation: {
|
||||
registerAction(definition: TraceMemoAutomationActionDefinition): void
|
||||
}
|
||||
capabilities: {
|
||||
get(): Promise<TraceMemoCapabilities>
|
||||
}
|
||||
log: {
|
||||
info(message: unknown): void
|
||||
warn(message: unknown): void
|
||||
error(message: unknown): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台入口签名。
|
||||
*
|
||||
* ```js
|
||||
* module.exports = function activate(tm) { ... }
|
||||
* ```
|
||||
*/
|
||||
export type TraceMemoActivate = (tm: TraceMemoApi) => void | Promise<void>
|
||||
|
||||
declare global {
|
||||
var tm: TraceMemoApi
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "@tracememo/extension-sdk",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "TraceMemo 扩展 SDK 的类型定义(v1)。运行期由宿主注入 tm 对象,无需打包进扩展。",
|
||||
"types": "index.d.ts",
|
||||
"files": ["index.d.ts", "README.md"],
|
||||
"license": "MIT"
|
||||
}
|
||||
Reference in new issue
Block a user