social-cli 0.0.1
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/LICENSE +21 -0
- package/README.md +306 -0
- package/SKILL.md +147 -0
- package/dist/bin/socialpilot.cjs +3348 -0
- package/dist/bin/socialpilot.js +3267 -0
- package/dist/src/client.cjs +127 -0
- package/dist/src/client.js +127 -0
- package/package.json +39 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/client.js
|
|
20
|
+
var client_exports = {};
|
|
21
|
+
__export(client_exports, {
|
|
22
|
+
callTool: () => callTool,
|
|
23
|
+
output: () => output,
|
|
24
|
+
uploadFile: () => uploadFile
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(client_exports);
|
|
27
|
+
var import_fs = require("fs");
|
|
28
|
+
var import_path = require("path");
|
|
29
|
+
var BACKEND_URL = "http://localhost:4000";
|
|
30
|
+
var getConfig = () => {
|
|
31
|
+
const apiKey = process.env.SOCIAL_CLI_API_KEY || process.env.SOCIALPILOT_API_KEY;
|
|
32
|
+
const apiUrl = process.env.SOCIAL_CLI_API_URL || process.env.SOCIALPILOT_API_URL || BACKEND_URL;
|
|
33
|
+
if (!apiKey) {
|
|
34
|
+
console.error(JSON.stringify({ status: "ERROR", message: "API key not set. Run: social-cli auth:set --key sk_your_key", data: null }));
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
return { apiKey, apiUrl };
|
|
38
|
+
};
|
|
39
|
+
async function callTool(toolName, args = {}) {
|
|
40
|
+
const { apiKey, apiUrl } = getConfig();
|
|
41
|
+
const body = {
|
|
42
|
+
jsonrpc: "2.0",
|
|
43
|
+
id: Date.now(),
|
|
44
|
+
method: "tools/call",
|
|
45
|
+
params: { name: toolName, arguments: args }
|
|
46
|
+
};
|
|
47
|
+
let res;
|
|
48
|
+
try {
|
|
49
|
+
res = await fetch(`${apiUrl}/mcp/socialpilot`, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
headers: {
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
"Accept": "application/json, text/event-stream",
|
|
54
|
+
"x-api-key": apiKey
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify(body),
|
|
57
|
+
signal: AbortSignal.timeout(3e4)
|
|
58
|
+
});
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return { status: "ERROR", message: `Cannot reach backend at ${apiUrl}: ${e.message}`, data: null };
|
|
61
|
+
}
|
|
62
|
+
const json = await res.json();
|
|
63
|
+
const text = json?.result?.content?.[0]?.text ?? "";
|
|
64
|
+
let parsed;
|
|
65
|
+
try {
|
|
66
|
+
parsed = JSON.parse(text);
|
|
67
|
+
} catch {
|
|
68
|
+
parsed = { status: "ERROR", message: text, data: null };
|
|
69
|
+
}
|
|
70
|
+
return parsed;
|
|
71
|
+
}
|
|
72
|
+
async function uploadFile(filePath) {
|
|
73
|
+
const { apiKey, apiUrl } = getConfig();
|
|
74
|
+
let fileBuffer;
|
|
75
|
+
try {
|
|
76
|
+
fileBuffer = (0, import_fs.readFileSync)(filePath);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
return { status: "ERROR", message: `Cannot read file: ${filePath} \u2014 ${e.message}`, data: null };
|
|
79
|
+
}
|
|
80
|
+
const ext = (0, import_path.extname)(filePath).toLowerCase().replace(".", "");
|
|
81
|
+
const mimeMap = {
|
|
82
|
+
jpg: "image/jpeg",
|
|
83
|
+
jpeg: "image/jpeg",
|
|
84
|
+
png: "image/png",
|
|
85
|
+
gif: "image/gif",
|
|
86
|
+
webp: "image/webp",
|
|
87
|
+
mp4: "video/mp4",
|
|
88
|
+
mov: "video/quicktime",
|
|
89
|
+
avi: "video/avi",
|
|
90
|
+
webm: "video/webm",
|
|
91
|
+
mpeg: "video/mpeg",
|
|
92
|
+
pdf: "application/pdf"
|
|
93
|
+
};
|
|
94
|
+
const fileType = mimeMap[ext] ?? "application/octet-stream";
|
|
95
|
+
const fileName = filePath.split(/[\\/]/).pop();
|
|
96
|
+
const presignRes = await callTool("get_upload_url", { fileName, fileType, fileSize: fileBuffer.length });
|
|
97
|
+
if (presignRes?.status !== "SUCCESS") return presignRes;
|
|
98
|
+
const { uploadUrl, publicUrl, type } = presignRes.data;
|
|
99
|
+
try {
|
|
100
|
+
const putRes = await fetch(uploadUrl, {
|
|
101
|
+
method: "PUT",
|
|
102
|
+
headers: { "Content-Type": fileType, "Content-Length": String(fileBuffer.length) },
|
|
103
|
+
body: fileBuffer,
|
|
104
|
+
signal: AbortSignal.timeout(12e4)
|
|
105
|
+
});
|
|
106
|
+
if (!putRes.ok) {
|
|
107
|
+
return { status: "ERROR", message: `Upload failed: ${putRes.status} ${putRes.statusText}`, data: null };
|
|
108
|
+
}
|
|
109
|
+
} catch (e) {
|
|
110
|
+
return { status: "ERROR", message: `Upload error: ${e.message}`, data: null };
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
status: "SUCCESS",
|
|
114
|
+
message: `File uploaded successfully. Use publicUrl in posts:create --media`,
|
|
115
|
+
data: { publicUrl, type: type ?? (fileType.startsWith("video") ? "video" : "image"), fileName }
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function output(result) {
|
|
119
|
+
console.log(JSON.stringify(result, null, 2));
|
|
120
|
+
process.exit(result?.status === "SUCCESS" ? 0 : 1);
|
|
121
|
+
}
|
|
122
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
+
0 && (module.exports = {
|
|
124
|
+
callTool,
|
|
125
|
+
output,
|
|
126
|
+
uploadFile
|
|
127
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/client.js
|
|
21
|
+
var client_exports = {};
|
|
22
|
+
__export(client_exports, {
|
|
23
|
+
callTool: () => callTool,
|
|
24
|
+
output: () => output,
|
|
25
|
+
uploadFile: () => uploadFile
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(client_exports);
|
|
28
|
+
var import_fs = require("fs");
|
|
29
|
+
var import_path = require("path");
|
|
30
|
+
var getConfig = () => {
|
|
31
|
+
const apiKey = process.env.SOCIALPILOT_API_KEY;
|
|
32
|
+
const apiUrl = (process.env.SOCIALPILOT_API_URL ?? "http://localhost:4000").replace(/\/$/, "");
|
|
33
|
+
if (!apiKey) {
|
|
34
|
+
console.error(JSON.stringify({ status: "ERROR", message: "SOCIALPILOT_API_KEY environment variable not set. Run: export SOCIALPILOT_API_KEY=sk_your_key", data: null }));
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
return { apiKey, apiUrl };
|
|
38
|
+
};
|
|
39
|
+
async function callTool(toolName, args = {}) {
|
|
40
|
+
const { apiKey, apiUrl } = getConfig();
|
|
41
|
+
const body = {
|
|
42
|
+
jsonrpc: "2.0",
|
|
43
|
+
id: Date.now(),
|
|
44
|
+
method: "tools/call",
|
|
45
|
+
params: { name: toolName, arguments: args }
|
|
46
|
+
};
|
|
47
|
+
let res;
|
|
48
|
+
try {
|
|
49
|
+
res = await fetch(`${apiUrl}/mcp/socialpilot`, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
headers: {
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
"Accept": "application/json, text/event-stream",
|
|
54
|
+
"x-api-key": apiKey
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify(body),
|
|
57
|
+
signal: AbortSignal.timeout(3e4)
|
|
58
|
+
});
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return { status: "ERROR", message: `Cannot reach backend at ${apiUrl}: ${e.message}`, data: null };
|
|
61
|
+
}
|
|
62
|
+
const json = await res.json();
|
|
63
|
+
const text = json?.result?.content?.[0]?.text ?? "";
|
|
64
|
+
let parsed;
|
|
65
|
+
try {
|
|
66
|
+
parsed = JSON.parse(text);
|
|
67
|
+
} catch {
|
|
68
|
+
parsed = { status: "ERROR", message: text, data: null };
|
|
69
|
+
}
|
|
70
|
+
return parsed;
|
|
71
|
+
}
|
|
72
|
+
async function uploadFile(filePath) {
|
|
73
|
+
const { apiKey, apiUrl } = getConfig();
|
|
74
|
+
let fileBuffer;
|
|
75
|
+
try {
|
|
76
|
+
fileBuffer = (0, import_fs.readFileSync)(filePath);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
return { status: "ERROR", message: `Cannot read file: ${filePath} \u2014 ${e.message}`, data: null };
|
|
79
|
+
}
|
|
80
|
+
const ext = (0, import_path.extname)(filePath).toLowerCase().replace(".", "");
|
|
81
|
+
const mimeMap = {
|
|
82
|
+
jpg: "image/jpeg",
|
|
83
|
+
jpeg: "image/jpeg",
|
|
84
|
+
png: "image/png",
|
|
85
|
+
gif: "image/gif",
|
|
86
|
+
webp: "image/webp",
|
|
87
|
+
mp4: "video/mp4",
|
|
88
|
+
mov: "video/quicktime",
|
|
89
|
+
avi: "video/avi",
|
|
90
|
+
webm: "video/webm",
|
|
91
|
+
mpeg: "video/mpeg",
|
|
92
|
+
pdf: "application/pdf"
|
|
93
|
+
};
|
|
94
|
+
const fileType = mimeMap[ext] ?? "application/octet-stream";
|
|
95
|
+
const fileName = filePath.split(/[\\/]/).pop();
|
|
96
|
+
const presignRes = await callTool("get_upload_url", { fileName, fileType, fileSize: fileBuffer.length });
|
|
97
|
+
if (presignRes?.status !== "SUCCESS") return presignRes;
|
|
98
|
+
const { uploadUrl, publicUrl, type } = presignRes.data;
|
|
99
|
+
try {
|
|
100
|
+
const putRes = await fetch(uploadUrl, {
|
|
101
|
+
method: "PUT",
|
|
102
|
+
headers: { "Content-Type": fileType, "Content-Length": String(fileBuffer.length) },
|
|
103
|
+
body: fileBuffer,
|
|
104
|
+
signal: AbortSignal.timeout(12e4)
|
|
105
|
+
});
|
|
106
|
+
if (!putRes.ok) {
|
|
107
|
+
return { status: "ERROR", message: `Upload failed: ${putRes.status} ${putRes.statusText}`, data: null };
|
|
108
|
+
}
|
|
109
|
+
} catch (e) {
|
|
110
|
+
return { status: "ERROR", message: `Upload error: ${e.message}`, data: null };
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
status: "SUCCESS",
|
|
114
|
+
message: `File uploaded successfully. Use publicUrl in posts:create --media`,
|
|
115
|
+
data: { publicUrl, type: type ?? (fileType.startsWith("video") ? "video" : "image"), fileName }
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function output(result) {
|
|
119
|
+
console.log(JSON.stringify(result, null, 2));
|
|
120
|
+
process.exit(result?.status === "SUCCESS" ? 0 : 1);
|
|
121
|
+
}
|
|
122
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
+
0 && (module.exports = {
|
|
124
|
+
callTool,
|
|
125
|
+
output,
|
|
126
|
+
uploadFile
|
|
127
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "social-cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Social media CLI for AI agents — post, schedule, and manage across 14 platforms",
|
|
5
|
+
"bin": {
|
|
6
|
+
"social-cli": "dist/bin/socialpilot.cjs",
|
|
7
|
+
"socialcli": "dist/bin/socialpilot.cjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"SKILL.md",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"start": "node bin/socialpilot.js",
|
|
16
|
+
"build": "node build.js",
|
|
17
|
+
"prepublishOnly": "npm run build",
|
|
18
|
+
"test": "node dist/bin/socialpilot.cjs --help"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"social-media", "cli", "ai-agent", "mcp",
|
|
22
|
+
"twitter", "instagram", "scheduling", "social-cli", "socialcli"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"commander": "^12.1.0",
|
|
28
|
+
"chalk": "^5.3.0",
|
|
29
|
+
"node-fetch": "^3.3.2",
|
|
30
|
+
"form-data": "^4.0.1",
|
|
31
|
+
"dotenv": "^16.4.5"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"esbuild": "^0.25.0"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|