openclaw-seatalk 0.1.0 → 0.1.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.
- package/README.md +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +6 -6
- package/src/media-local.ts +14 -0
- package/src/media.ts +21 -29
package/README.md
CHANGED
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openclaw-seatalk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "OpenClaw SeaTalk channel plugin",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -14,11 +14,7 @@
|
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">=18.0.0"
|
|
16
16
|
},
|
|
17
|
-
"files": [
|
|
18
|
-
"index.ts",
|
|
19
|
-
"src/",
|
|
20
|
-
"openclaw.plugin.json"
|
|
21
|
-
],
|
|
17
|
+
"files": ["index.ts", "src/", "openclaw.plugin.json"],
|
|
22
18
|
"scripts": {
|
|
23
19
|
"format": "biome format --write .",
|
|
24
20
|
"format:check": "biome format .",
|
|
@@ -49,6 +45,10 @@
|
|
|
49
45
|
"blurb": "SeaTalk messaging integration",
|
|
50
46
|
"order": 70,
|
|
51
47
|
"quickstartAllowFrom": true
|
|
48
|
+
},
|
|
49
|
+
"install": {
|
|
50
|
+
"npmSpec": "openclaw-seatalk",
|
|
51
|
+
"defaultChoice": "npm"
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
|
|
5
|
+
export function readLocalMedia(mediaUrl: string): { buffer: Buffer; name: string } {
|
|
6
|
+
const resolved = mediaUrl.startsWith("~")
|
|
7
|
+
? path.join(os.homedir(), mediaUrl.slice(1))
|
|
8
|
+
: mediaUrl.replace(/^file:\/\//, "");
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(resolved)) {
|
|
11
|
+
throw new Error(`Media file not found: ${resolved}`);
|
|
12
|
+
}
|
|
13
|
+
return { buffer: fs.readFileSync(resolved), name: path.basename(resolved) };
|
|
14
|
+
}
|
package/src/media.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
1
|
import * as path from "node:path";
|
|
3
2
|
import type { SeaTalkClient } from "./client.js";
|
|
3
|
+
import { readLocalMedia } from "./media-local.js";
|
|
4
4
|
import { getSeatalkRuntime } from "./runtime.js";
|
|
5
5
|
import type { SeaTalkMediaInfo, SeaTalkMessage, SeaTalkOutboundMedia } from "./types.js";
|
|
6
6
|
|
|
@@ -93,36 +93,28 @@ export async function resolveInboundMedia(params: {
|
|
|
93
93
|
return null;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
const res = await fetch(mediaUrl, { signal: controller.signal });
|
|
105
|
-
if (!res.ok) {
|
|
106
|
-
throw new Error(`Failed to fetch media from ${mediaUrl}: HTTP ${res.status}`);
|
|
107
|
-
}
|
|
108
|
-
const arrayBuffer = await res.arrayBuffer();
|
|
109
|
-
buffer = Buffer.from(arrayBuffer);
|
|
110
|
-
} finally {
|
|
111
|
-
clearTimeout(timeout);
|
|
96
|
+
async function fetchRemoteMedia(url: string): Promise<{ buffer: Buffer; name: string }> {
|
|
97
|
+
const controller = new AbortController();
|
|
98
|
+
const timeout = setTimeout(() => controller.abort(), 30_000);
|
|
99
|
+
try {
|
|
100
|
+
const res = await fetch(url, { signal: controller.signal });
|
|
101
|
+
if (!res.ok) {
|
|
102
|
+
throw new Error(`Failed to fetch media from ${url}: HTTP ${res.status}`);
|
|
112
103
|
}
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (!fs.existsSync(resolved)) {
|
|
121
|
-
throw new Error(`Media file not found: ${resolved}`);
|
|
122
|
-
}
|
|
123
|
-
buffer = fs.readFileSync(resolved);
|
|
124
|
-
detectedName = path.basename(resolved);
|
|
104
|
+
const arrayBuffer = await res.arrayBuffer();
|
|
105
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
106
|
+
const urlPath = new URL(url).pathname;
|
|
107
|
+
return { buffer, name: path.basename(urlPath) || "file" };
|
|
108
|
+
} finally {
|
|
109
|
+
clearTimeout(timeout);
|
|
125
110
|
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function prepareOutboundMedia(mediaUrl: string): Promise<SeaTalkOutboundMedia | null> {
|
|
114
|
+
const isRemote = mediaUrl.startsWith("http://") || mediaUrl.startsWith("https://");
|
|
115
|
+
const { buffer, name: detectedName } = isRemote
|
|
116
|
+
? await fetchRemoteMedia(mediaUrl)
|
|
117
|
+
: readLocalMedia(mediaUrl);
|
|
126
118
|
|
|
127
119
|
if (buffer.length > MAX_OUTBOUND_RAW_BYTES) {
|
|
128
120
|
throw new Error(
|