zapry-openclaw-plugin 0.0.1 → 0.0.3

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.
Files changed (46) hide show
  1. package/README.md +6 -4
  2. package/dist/index.d.ts +12 -0
  3. package/dist/index.js +344 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/src/actions.d.ts +14 -0
  6. package/dist/src/actions.js +2026 -0
  7. package/dist/src/actions.js.map +1 -0
  8. package/dist/src/api-client.d.ts +96 -0
  9. package/dist/src/api-client.js +252 -0
  10. package/dist/src/api-client.js.map +1 -0
  11. package/dist/src/channel.d.ts +127 -0
  12. package/dist/src/channel.js +248 -0
  13. package/dist/src/channel.js.map +1 -0
  14. package/dist/src/config.d.ts +4 -0
  15. package/dist/src/config.js +58 -0
  16. package/dist/src/config.js.map +1 -0
  17. package/dist/src/inbound.d.ts +27 -0
  18. package/dist/src/inbound.js +2826 -0
  19. package/dist/src/inbound.js.map +1 -0
  20. package/dist/src/monitor.d.ts +18 -0
  21. package/dist/src/monitor.js +113 -0
  22. package/dist/src/monitor.js.map +1 -0
  23. package/dist/src/profile-sync.d.ts +5 -0
  24. package/dist/src/profile-sync.js +153 -0
  25. package/dist/src/profile-sync.js.map +1 -0
  26. package/dist/src/runtime.d.ts +18 -0
  27. package/dist/src/runtime.js +41 -0
  28. package/dist/src/runtime.js.map +1 -0
  29. package/dist/src/send.d.ts +6 -0
  30. package/dist/src/send.js +222 -0
  31. package/dist/src/send.js.map +1 -0
  32. package/dist/src/types.d.ts +152 -0
  33. package/dist/src/types.js +3 -0
  34. package/dist/src/types.js.map +1 -0
  35. package/package.json +16 -4
  36. package/index.ts +0 -345
  37. package/src/actions.ts +0 -2241
  38. package/src/api-client.ts +0 -357
  39. package/src/channel.ts +0 -268
  40. package/src/config.ts +0 -68
  41. package/src/inbound.ts +0 -3494
  42. package/src/monitor.ts +0 -144
  43. package/src/profile-sync.ts +0 -195
  44. package/src/runtime.ts +0 -66
  45. package/src/send.ts +0 -257
  46. package/src/types.ts +0 -175
package/index.ts DELETED
@@ -1,345 +0,0 @@
1
- if (typeof globalThis.DOMMatrix === "undefined") {
2
- (globalThis as any).DOMMatrix = class DOMMatrix {
3
- a: number; b: number; c: number; d: number; e: number; f: number;
4
- m11: number; m12: number; m21: number; m22: number; m41: number; m42: number;
5
- is2D = true; isIdentity = false;
6
- constructor(init?: number[] | string) {
7
- const v = Array.isArray(init) ? init : [];
8
- this.a = this.m11 = v[0] ?? 1; this.b = this.m12 = v[1] ?? 0;
9
- this.c = this.m21 = v[2] ?? 0; this.d = this.m22 = v[3] ?? 1;
10
- this.e = this.m41 = v[4] ?? 0; this.f = this.m42 = v[5] ?? 0;
11
- }
12
- inverse() { return new DOMMatrix(); }
13
- multiply() { return new DOMMatrix(); }
14
- scale() { return new DOMMatrix(); }
15
- translate() { return new DOMMatrix(); }
16
- transformPoint(p?: any) { return { x: p?.x ?? 0, y: p?.y ?? 0, z: 0, w: 1 }; }
17
- static fromMatrix() { return new DOMMatrix(); }
18
- static fromFloat32Array(a: Float32Array) { return new DOMMatrix(Array.from(a)); }
19
- static fromFloat64Array(a: Float64Array) { return new DOMMatrix(Array.from(a)); }
20
- };
21
- }
22
-
23
- try {
24
- const { createRequire } = require("node:module");
25
- const { pathToFileURL } = require("node:url");
26
- const _r = createRequire(require("node:path").join(process.cwd(), "package.json"));
27
- const _pdfjsAbs = _r.resolve("pdfjs-dist/legacy/build/pdf.mjs");
28
- const _workerAbs = _r.resolve("pdfjs-dist/legacy/build/pdf.worker.mjs");
29
- import(pathToFileURL(_pdfjsAbs).href).then((pdfjs: any) => {
30
- if (pdfjs?.GlobalWorkerOptions && !pdfjs.GlobalWorkerOptions.workerSrc) {
31
- pdfjs.GlobalWorkerOptions.workerSrc = _workerAbs;
32
- }
33
- }).catch(() => {});
34
- } catch {}
35
-
36
- import { zapryPlugin } from "./src/channel.js";
37
- import {
38
- buildZaprySkillRequestHeaders,
39
- getZaprySkillInvocationContext,
40
- resolveZaprySkillRequestHeaders,
41
- setZapryRuntime,
42
- } from "./src/runtime.js";
43
- import { resolveZapryAccount } from "./src/config.js";
44
- import { handleZapryAction } from "./src/actions.js";
45
-
46
- const ZAPRY_ACTION_TOOL_ACTIONS = [
47
- "send", "send-message",
48
- "send-photo", "send-video", "send-document", "send-audio", "send-voice", "send-animation",
49
- "generate-audio",
50
- "delete-message", "answer-callback-query",
51
- "get-file", "get-my-profile", "get-me",
52
- "get-my-groups", "get-my-chats",
53
- "get-chat-member", "get-chat-members", "get-chat-member-count", "get-chat-administrators",
54
- "mute-chat-member", "kick-chat-member", "set-chat-title", "set-chat-description",
55
- "get-user-profile-photos", "set-my-wallet-address", "set-my-friend-verify",
56
- "get-my-contacts", "get-my-friend-requests",
57
- "accept-friend-request", "reject-friend-request", "add-friend", "delete-friend",
58
- "set-my-soul", "get-my-soul", "set-my-skills", "get-my-skills",
59
- "set-my-name", "set-my-description",
60
- "get-trending-posts", "get-latest-posts", "get-my-posts", "search-posts",
61
- "delete-post", "comment-post", "like-post", "share-post",
62
- "get-updates", "set-webhook", "get-webhook-info", "delete-webhook", "webhooks-token",
63
- "get-chat-history",
64
- ] as const;
65
-
66
- async function resolveRuntimeConfig(api: any): Promise<any> {
67
- const runtimeConfig = api?.runtime?.config;
68
- const loadConfig = runtimeConfig?.loadConfig;
69
- if (typeof loadConfig === "function") {
70
- try {
71
- return await Promise.resolve(loadConfig());
72
- } catch {
73
- // fall through
74
- }
75
- }
76
- return runtimeConfig ?? {};
77
- }
78
-
79
- function sameUserIdentity(left: string, right: string): boolean {
80
- const normalizedLeft = left.trim();
81
- const normalizedRight = right.trim();
82
- if (!normalizedLeft || !normalizedRight) {
83
- return false;
84
- }
85
- if (normalizedLeft === normalizedRight) {
86
- return true;
87
- }
88
-
89
- const leftNum = Number(normalizedLeft);
90
- const rightNum = Number(normalizedRight);
91
- return Number.isFinite(leftNum) && Number.isFinite(rightNum) && leftNum === rightNum;
92
- }
93
-
94
- function resolveOwnerIdFromBotToken(botToken: string): string {
95
- const trimmed = String(botToken ?? "").trim();
96
- const separatorIdx = trimmed.indexOf(":");
97
- if (separatorIdx <= 0) {
98
- return "";
99
- }
100
- return trimmed.slice(0, separatorIdx).trim();
101
- }
102
-
103
- function resolveToolAccount(toolCtx: any, cfg: any, requestedAccountId?: string) {
104
- return resolveZapryAccount(cfg, requestedAccountId ?? toolCtx?.agentAccountId);
105
- }
106
-
107
- function resolveToolSenderId(toolCtx: any): string {
108
- return String(toolCtx?.requesterSenderId ?? "").trim();
109
- }
110
-
111
- function resolveToolSenderIsOwner(toolCtx: any, account: { botToken: string }): boolean {
112
- if (toolCtx?.senderIsOwner === true) {
113
- return true;
114
- }
115
- if (toolCtx?.senderIsOwner === false) {
116
- return false;
117
- }
118
- const senderId = resolveToolSenderId(toolCtx);
119
- const ownerId = resolveOwnerIdFromBotToken(account.botToken);
120
- return sameUserIdentity(senderId, ownerId);
121
- }
122
-
123
- function shouldExposeZapryOwnerTools(toolCtx: any, account: { botToken: string }): boolean {
124
- if (toolCtx?.messageChannel !== "zapry") {
125
- return true;
126
- }
127
- const senderId = resolveToolSenderId(toolCtx);
128
- if (!senderId) {
129
- return false;
130
- }
131
- return resolveToolSenderIsOwner(toolCtx, account);
132
- }
133
-
134
- function resolveToolRequestHeaders(toolCtx: any): Record<string, string> {
135
- const senderId = resolveToolSenderId(toolCtx);
136
- if (senderId) {
137
- const invocationCtx = getZaprySkillInvocationContext();
138
- return buildZaprySkillRequestHeaders({
139
- senderId,
140
- messageSid: invocationCtx?.messageSid,
141
- });
142
- }
143
- return resolveZaprySkillRequestHeaders();
144
- }
145
-
146
- function ownerDeniedToolResult(): string {
147
- return JSON.stringify({
148
- ok: false,
149
- error: "只能是主人才可以调用",
150
- });
151
- }
152
-
153
- const plugin = {
154
- id: "zapry",
155
- name: "Zapry",
156
- description: "Zapry social platform channel plugin — messaging, groups, feed, clubs, and bot self-management",
157
- configSchema: {
158
- type: "object" as const,
159
- additionalProperties: false,
160
- properties: {},
161
- },
162
- register(api: any) {
163
- setZapryRuntime(api.runtime);
164
- api.registerChannel({ plugin: zapryPlugin });
165
-
166
- api.registerTool((toolCtx: any) => {
167
- const toolCfg = toolCtx?.config ?? api?.runtime?.config ?? {};
168
- const account = resolveToolAccount(toolCtx, toolCfg);
169
- if (!shouldExposeZapryOwnerTools(toolCtx, account)) {
170
- return null;
171
- }
172
- return {
173
- name: "zapry_post",
174
- label: "Zapry Post to Feed",
175
- description:
176
- "Post to Zapry public feed (广场). This is the ONLY way to create a feed post. " +
177
- "Pass content and optionally images. No target or routing needed.",
178
- parameters: {
179
- type: "object" as const,
180
- properties: {
181
- content: {
182
- type: "string" as const,
183
- description: "Post text content (required)",
184
- },
185
- images: {
186
- type: "array" as const,
187
- items: { type: "string" as const },
188
- description:
189
- "Array of image sources: local file paths, data: URIs, HTTP(S) URLs, or Zapry file IDs (mf_*)",
190
- },
191
- },
192
- required: ["content"],
193
- },
194
- execute: async (_toolCallId: string, args: Record<string, any>) => {
195
- try {
196
- const cfg = await resolveRuntimeConfig(api);
197
- const account = resolveToolAccount(toolCtx, cfg);
198
- if (!shouldExposeZapryOwnerTools(toolCtx, account)) {
199
- return ownerDeniedToolResult();
200
- }
201
- const result = await handleZapryAction({
202
- action: "create-post",
203
- channel: "zapry",
204
- account,
205
- params: { content: args.content, images: args.images },
206
- requestHeaders: resolveToolRequestHeaders(toolCtx),
207
- });
208
- return JSON.stringify(result, null, 2);
209
- } catch (err) {
210
- return JSON.stringify({
211
- ok: false,
212
- error: err instanceof Error ? err.message : String(err),
213
- });
214
- }
215
- },
216
- };
217
- });
218
-
219
- api.registerTool((toolCtx: any) => {
220
- const toolCfg = toolCtx?.config ?? api?.runtime?.config ?? {};
221
- const account = resolveToolAccount(toolCtx, toolCfg);
222
- if (!shouldExposeZapryOwnerTools(toolCtx, account)) {
223
- return null;
224
- }
225
- return {
226
- name: "zapry_action",
227
- label: "Zapry Platform Action",
228
- description:
229
- "Execute a Zapry platform action. Use this for: " +
230
- "sending media (send-photo, send-video, send-audio, send-document, send-voice, send-animation) to any chat including groups. " +
231
- "IMPORTANT: For send-photo, if user asks for an image without providing one, use 'prompt' parameter (e.g. action='send-photo', prompt='bitcoin logo') — image is auto-generated, NO photo/URL needed. " +
232
- "profile queries (get-my-profile, get-me), friend operations " +
233
- "(get-my-friend-requests, accept-friend-request, add-friend, etc.), " +
234
- "group management (get-chat-members, mute-chat-member, kick-chat-member, etc.), " +
235
- "feed reading (get-trending-posts, get-latest-posts, search-posts, etc.), " +
236
- "feed interactions (delete-post, comment-post, like-post, share-post), " +
237
- "bot settings (set-my-soul, set-my-skills, set-my-name, etc.), " +
238
- "chat history (get-chat-history), " +
239
- "and webhook/file operations (get-file, set-webhook, get-updates, etc.). " +
240
- "Pass the action name and action-specific parameters as top-level fields.",
241
- parameters: {
242
- type: "object" as const,
243
- properties: {
244
- action: {
245
- type: "string" as const,
246
- description: "The Zapry action to execute",
247
- enum: [...ZAPRY_ACTION_TOOL_ACTIONS],
248
- },
249
- chat_id: {
250
- type: "string" as const,
251
- description: "Chat/group ID (for group management actions like get-chat-members, mute-chat-member, etc.)",
252
- },
253
- user_id: {
254
- type: "string" as const,
255
- description: "User ID (for friend actions, chat member actions, etc.)",
256
- },
257
- file_id: {
258
- type: "string" as const,
259
- description: "File ID (for get-file)",
260
- },
261
- keyword: {
262
- type: "string" as const,
263
- description: "Search keyword (for search-posts)",
264
- },
265
- dynamic_id: {
266
- type: "string" as const,
267
- description: "Post/dynamic ID (for delete-post, comment-post, like-post, share-post)",
268
- },
269
- photo: {
270
- type: "string" as const,
271
- description: "Photo source: external URL (auto-downloaded), data URI, local path, or /_temp/media URL (for send-photo). If omitted but 'prompt' is provided, image will be auto-generated.",
272
- },
273
- prompt: {
274
- type: "string" as const,
275
- description: "PREFERRED for send-photo when user asks for an image: describe what to generate (e.g. 'bitcoin logo', 'cute cat'). Image is auto-generated and sent — no photo/URL needed.",
276
- },
277
- video: {
278
- type: "string" as const,
279
- description: "Video source (for send-video)",
280
- },
281
- document: {
282
- type: "string" as const,
283
- description: "Document source (for send-document)",
284
- },
285
- audio: {
286
- type: "string" as const,
287
- description: "Audio source (for send-audio)",
288
- },
289
- voice: {
290
- type: "string" as const,
291
- description: "Voice source (for send-voice)",
292
- },
293
- animation: {
294
- type: "string" as const,
295
- description: "Animation/GIF source (for send-animation)",
296
- },
297
- content: {
298
- type: "string" as const,
299
- description: "Text content (for comment-post)",
300
- },
301
- limit: {
302
- type: "number" as const,
303
- description: "Limit for results (for get-chat-history, default 50, max 50)",
304
- },
305
- page: {
306
- type: "number" as const,
307
- description: "Page number for paginated results",
308
- },
309
- page_size: {
310
- type: "number" as const,
311
- description: "Page size for paginated results",
312
- },
313
- },
314
- required: ["action"],
315
- additionalProperties: true,
316
- },
317
- execute: async (_toolCallId: string, args: Record<string, any>) => {
318
- try {
319
- const { action, channel: _ch, accountId: reqAccountId, ...params } = args ?? {};
320
- const cfg = await resolveRuntimeConfig(api);
321
- const account = resolveToolAccount(toolCtx, cfg, reqAccountId);
322
- if (!shouldExposeZapryOwnerTools(toolCtx, account)) {
323
- return ownerDeniedToolResult();
324
- }
325
- const result = await handleZapryAction({
326
- action,
327
- channel: "zapry",
328
- account,
329
- params,
330
- requestHeaders: resolveToolRequestHeaders(toolCtx),
331
- });
332
- return JSON.stringify(result, null, 2);
333
- } catch (err) {
334
- return JSON.stringify({
335
- ok: false,
336
- error: err instanceof Error ? err.message : String(err),
337
- });
338
- }
339
- },
340
- };
341
- });
342
- },
343
- };
344
-
345
- export default plugin;