@wzfukui/ani 2026.3.28
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/README.md +154 -0
- package/index.ts +45 -0
- package/openclaw.plugin.json +74 -0
- package/package.json +65 -0
- package/src/channel.ts +242 -0
- package/src/config-schema.ts +15 -0
- package/src/monitor/debounce.ts +68 -0
- package/src/monitor/handler.ts +1070 -0
- package/src/monitor/index.ts +168 -0
- package/src/monitor/send.ts +546 -0
- package/src/outbound.ts +183 -0
- package/src/runtime.ts +14 -0
- package/src/sdk-compat.ts +59 -0
- package/src/tools.ts +602 -0
- package/src/types.ts +50 -0
- package/src/utils.ts +60 -0
package/src/utils.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getAniRuntime } from "./runtime.js";
|
|
2
|
+
|
|
3
|
+
/** Normalize an ANI server URL: trim, remove trailing slashes. */
|
|
4
|
+
export function normalizeAniServerUrl(url: string | undefined | null): string {
|
|
5
|
+
return (url ?? "").replace(/\/+$/, "").trim();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shared MIME type mapping for common text file extensions.
|
|
10
|
+
* Used by tools.ts (ani_send_file) and handler.ts (attachment processing).
|
|
11
|
+
*/
|
|
12
|
+
const MIME_MAP: Record<string, string> = {
|
|
13
|
+
// Text
|
|
14
|
+
".md": "text/markdown", ".txt": "text/plain", ".csv": "text/csv",
|
|
15
|
+
".json": "application/json", ".xml": "application/xml",
|
|
16
|
+
".yaml": "text/yaml", ".yml": "text/yaml",
|
|
17
|
+
".html": "text/html", ".css": "text/css",
|
|
18
|
+
".js": "text/javascript", ".ts": "text/typescript",
|
|
19
|
+
".py": "text/x-python", ".go": "text/x-go",
|
|
20
|
+
".sql": "text/x-sql", ".sh": "text/x-shellscript",
|
|
21
|
+
".log": "text/plain", ".toml": "text/toml", ".ini": "text/plain",
|
|
22
|
+
// Images
|
|
23
|
+
".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg",
|
|
24
|
+
".gif": "image/gif", ".svg": "image/svg+xml", ".webp": "image/webp",
|
|
25
|
+
".bmp": "image/bmp", ".ico": "image/x-icon",
|
|
26
|
+
// Audio
|
|
27
|
+
".mp3": "audio/mpeg", ".wav": "audio/wav", ".ogg": "audio/ogg",
|
|
28
|
+
".m4a": "audio/mp4", ".flac": "audio/flac", ".aac": "audio/aac",
|
|
29
|
+
// Video
|
|
30
|
+
".mp4": "video/mp4", ".webm": "video/webm", ".mov": "video/quicktime",
|
|
31
|
+
".avi": "video/x-msvideo", ".mkv": "video/x-matroska",
|
|
32
|
+
// Documents
|
|
33
|
+
".pdf": "application/pdf",
|
|
34
|
+
".doc": "application/msword", ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
35
|
+
".xls": "application/vnd.ms-excel", ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
36
|
+
".ppt": "application/vnd.ms-powerpoint", ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
37
|
+
// Archives
|
|
38
|
+
".zip": "application/zip", ".tar": "application/x-tar", ".gz": "application/gzip",
|
|
39
|
+
".7z": "application/x-7z-compressed", ".rar": "application/vnd.rar",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Get MIME type for a filename based on its extension. Falls back to "application/octet-stream" for binary. */
|
|
43
|
+
export function getMimeType(filename: string): string {
|
|
44
|
+
const ext = filename.includes(".")
|
|
45
|
+
? filename.slice(filename.lastIndexOf(".")).toLowerCase()
|
|
46
|
+
: "";
|
|
47
|
+
return MIME_MAP[ext] ?? "application/octet-stream";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Resolve ANI serverUrl and apiKey from config. Throws if not configured. */
|
|
51
|
+
export function resolveAniCredentials(): { serverUrl: string; apiKey: string } {
|
|
52
|
+
const core = getAniRuntime();
|
|
53
|
+
const cfg = core.config.loadConfig() as { channels?: { ani?: { serverUrl?: string; apiKey?: string } } };
|
|
54
|
+
const serverUrl = normalizeAniServerUrl(cfg.channels?.ani?.serverUrl);
|
|
55
|
+
const apiKey = cfg.channels?.ani?.apiKey ?? "";
|
|
56
|
+
if (!serverUrl || !apiKey) {
|
|
57
|
+
throw new Error("ANI: serverUrl and apiKey required");
|
|
58
|
+
}
|
|
59
|
+
return { serverUrl, apiKey };
|
|
60
|
+
}
|