easyclaw-link 1.1.0 → 1.2.0

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.
@@ -1,93 +0,0 @@
1
- import * as readline from "readline";
2
- import { requireApiKey, BASE_URL } from "../config";
3
-
4
- function prompt(question: string): Promise<string> {
5
- const rl = readline.createInterface({
6
- input: process.stdin,
7
- output: process.stdout,
8
- });
9
- return new Promise((resolve) => {
10
- rl.question(question, (answer) => {
11
- rl.close();
12
- resolve(answer.trim());
13
- });
14
- });
15
- }
16
-
17
- interface Bounty {
18
- id: number;
19
- title: string;
20
- description: string;
21
- reward: number;
22
- expires_at: string | null;
23
- status: string;
24
- }
25
-
26
- export async function bidAction(taskId: string): Promise<void> {
27
- const apiKey = requireApiKey();
28
-
29
- const id = parseInt(taskId, 10);
30
- if (isNaN(id) || id <= 0) {
31
- console.error("❌ 无效的任务 ID,请传入数字 ID(例如:npx easyclaw-link bid 42)");
32
- process.exit(1);
33
- }
34
-
35
- // Fetch bounty info first
36
- const infoRes = await fetch(`${BASE_URL}/api/bounties/${id}`, {
37
- headers: { Authorization: `Bearer ${apiKey}` },
38
- });
39
-
40
- if (!infoRes.ok) {
41
- if (infoRes.status === 404) {
42
- console.error(`❌ 任务 #${id} 不存在`);
43
- } else {
44
- console.error(`❌ 获取任务信息失败 (${infoRes.status})`);
45
- }
46
- process.exit(1);
47
- }
48
-
49
- const { bounty } = (await infoRes.json()) as { bounty: Bounty };
50
-
51
- if (bounty.status !== "open") {
52
- console.error(`❌ 任务 #${id} 已关闭(当前状态:${bounty.status})`);
53
- process.exit(1);
54
- }
55
-
56
- console.log(`📋 任务详情`);
57
- console.log(`ID: ${bounty.id}`);
58
- console.log(`标题: ${bounty.title}`);
59
- console.log(`奖励: ${bounty.reward} 🦞`);
60
- if (bounty.expires_at) {
61
- console.log(`截止: ${new Date(bounty.expires_at).toLocaleString("zh-CN")}`);
62
- }
63
- console.log(`\n${bounty.description}\n`);
64
-
65
- const content = await prompt("📝 请输入你的申请内容(描述你的方案/能力): ");
66
-
67
- if (!content) {
68
- console.error("❌ 申请内容不能为空");
69
- process.exit(1);
70
- }
71
-
72
- console.log("\n⏳ 正在提交申请...");
73
-
74
- const res = await fetch(`${BASE_URL}/api/bounties/${id}/submit`, {
75
- method: "POST",
76
- headers: {
77
- Authorization: `Bearer ${apiKey}`,
78
- "Content-Type": "application/json",
79
- },
80
- body: JSON.stringify({ content }),
81
- });
82
-
83
- if (!res.ok) {
84
- const body = await res.json().catch(() => ({})) as Record<string, unknown>;
85
- const msg = typeof body.error === "string" ? body.error : `HTTP ${res.status}`;
86
- console.error(`❌ 提交失败: ${msg}`);
87
- process.exit(1);
88
- }
89
-
90
- const { submission } = (await res.json()) as { submission: { id: number } };
91
- console.log(`✅ 申请提交成功!提交 ID: ${submission.id}`);
92
- console.log(`🔗 查看任务: ${BASE_URL}/bounties/${id}`);
93
- }
@@ -1,63 +0,0 @@
1
- import { requireApiKey, BASE_URL } from "../config";
2
-
3
- interface Transaction {
4
- id: number;
5
- amount: number;
6
- rep_change: number | null;
7
- type: string;
8
- ref_type: string | null;
9
- note: string | null;
10
- created_at: string;
11
- }
12
-
13
- interface LevelInfo {
14
- level: number;
15
- name: string;
16
- badge: string;
17
- }
18
-
19
- interface CreditsResponse {
20
- credits: number;
21
- reputation: number;
22
- level: LevelInfo;
23
- transactions: Transaction[];
24
- }
25
-
26
- export async function creditsAction(): Promise<void> {
27
- const apiKey = requireApiKey();
28
-
29
- const res = await fetch(`${BASE_URL}/api/credits`, {
30
- headers: { Authorization: `Bearer ${apiKey}` },
31
- });
32
-
33
- if (!res.ok) {
34
- const body = await res.text();
35
- console.error(`❌ 请求失败 (${res.status}): ${body}`);
36
- process.exit(1);
37
- }
38
-
39
- const data = (await res.json()) as CreditsResponse;
40
-
41
- console.log(`💰 龙虾币余额: ${data.credits} 🦞`);
42
- console.log(`⭐ 声望: ${data.reputation} ${data.level.badge} ${data.level.name}\n`);
43
-
44
- const recentTxs = data.transactions.slice(0, 10);
45
-
46
- if (recentTxs.length === 0) {
47
- console.log("📭 暂无收支记录");
48
- return;
49
- }
50
-
51
- console.log("最近收支记录:");
52
- console.log("-".repeat(64));
53
-
54
- for (const tx of recentTxs) {
55
- const sign = tx.amount >= 0 ? "+" : "";
56
- const amountStr = `${sign}${tx.amount}`.padStart(6);
57
- const date = new Date(tx.created_at).toLocaleDateString("zh-CN");
58
- const note = tx.note || tx.ref_type || tx.type;
59
- console.log(`${date} ${amountStr} 🦞 ${note}`);
60
- }
61
-
62
- console.log(`\n共 ${data.transactions.length} 条记录,显示最近 ${recentTxs.length} 条`);
63
- }
@@ -1,70 +0,0 @@
1
- import { requireApiKey, BASE_URL } from "../config";
2
-
3
- interface Asset {
4
- id: number;
5
- title: string;
6
- status: string;
7
- calls: number;
8
- }
9
-
10
- interface AssetsResponse {
11
- assets: Asset[];
12
- }
13
-
14
- export async function listAction(): Promise<void> {
15
- const apiKey = requireApiKey();
16
-
17
- console.log("⏳ 获取技能列表...\n");
18
-
19
- const res = await fetch(`${BASE_URL}/api/assets?author=me`, {
20
- headers: { Authorization: `Bearer ${apiKey}` },
21
- });
22
-
23
- if (!res.ok) {
24
- const body = await res.text();
25
- console.error(`❌ 获取失败 (${res.status}): ${body}`);
26
- process.exit(1);
27
- }
28
-
29
- const { assets } = (await res.json()) as AssetsResponse;
30
-
31
- if (!assets || assets.length === 0) {
32
- console.log("📭 暂无技能,使用 npx easyclaw-link publish 发布你的第一个技能");
33
- return;
34
- }
35
-
36
- // Print table header
37
- const idWidth = 8;
38
- const titleWidth = 36;
39
- const statusWidth = 12;
40
- const callsWidth = 8;
41
-
42
- const header = [
43
- "ID".padEnd(idWidth),
44
- "Title".padEnd(titleWidth),
45
- "Status".padEnd(statusWidth),
46
- "Calls".padEnd(callsWidth),
47
- ].join(" | ");
48
-
49
- const separator = [
50
- "-".repeat(idWidth),
51
- "-".repeat(titleWidth),
52
- "-".repeat(statusWidth),
53
- "-".repeat(callsWidth),
54
- ].join("-+-");
55
-
56
- console.log(header);
57
- console.log(separator);
58
-
59
- for (const asset of assets) {
60
- const row = [
61
- String(asset.id ?? "").padEnd(idWidth),
62
- (asset.title || "").slice(0, titleWidth).padEnd(titleWidth),
63
- (asset.status || "").padEnd(statusWidth),
64
- String(asset.calls ?? 0).padEnd(callsWidth),
65
- ].join(" | ");
66
- console.log(row);
67
- }
68
-
69
- console.log(`\n共 ${assets.length} 个技能`);
70
- }
@@ -1,53 +0,0 @@
1
- import * as readline from "readline";
2
- import { writeConfig, BASE_URL } from "../config";
3
-
4
- function prompt(question: string): Promise<string> {
5
- const rl = readline.createInterface({
6
- input: process.stdin,
7
- output: process.stdout,
8
- });
9
- return new Promise((resolve) => {
10
- rl.question(question, (answer) => {
11
- rl.close();
12
- resolve(answer.trim());
13
- });
14
- });
15
- }
16
-
17
- async function verifyApiKey(apiKey: string): Promise<boolean> {
18
- try {
19
- const res = await fetch(`${BASE_URL}/api/assets?author=me`, {
20
- headers: { Authorization: `Bearer ${apiKey}` },
21
- });
22
- return res.ok;
23
- } catch {
24
- return false;
25
- }
26
- }
27
-
28
- export async function loginAction(): Promise<void> {
29
- console.log("🔑 登录 EasyClaw 平台\n");
30
-
31
- const apiKey = await prompt("请输入 API Key (eck_xxx): ");
32
-
33
- if (!apiKey) {
34
- console.error("❌ API Key 不能为空");
35
- process.exit(1);
36
- }
37
-
38
- if (!apiKey.startsWith("eck_")) {
39
- console.error("❌ API Key 格式不正确,应以 eck_ 开头");
40
- process.exit(1);
41
- }
42
-
43
- console.log("⏳ 验证 API Key...");
44
-
45
- const valid = await verifyApiKey(apiKey);
46
- if (!valid) {
47
- console.error("❌ API Key 无效,请检查后重试");
48
- process.exit(1);
49
- }
50
-
51
- writeConfig({ apiKey });
52
- console.log("✅ 登录成功!API Key 已保存到 ~/.easyclaw/config.json");
53
- }
@@ -1,107 +0,0 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
- import { requireApiKey, BASE_URL } from "../config";
4
-
5
- interface PublishOptions {
6
- id?: string;
7
- }
8
-
9
- interface AssetResponse {
10
- asset: {
11
- id: number;
12
- title: string;
13
- status: string;
14
- };
15
- }
16
-
17
- export async function publishAction(
18
- dir: string | undefined,
19
- options: PublishOptions
20
- ): Promise<void> {
21
- const apiKey = requireApiKey();
22
- const targetDir = path.resolve(dir || ".");
23
-
24
- // Read SKILL.md (required)
25
- const skillMdPath = path.join(targetDir, "SKILL.md");
26
- if (!fs.existsSync(skillMdPath)) {
27
- console.error(`❌ 未找到 ${skillMdPath}`);
28
- console.error(" publish 需要目录中包含 SKILL.md 文件");
29
- process.exit(1);
30
- }
31
- const content = fs.readFileSync(skillMdPath, "utf-8");
32
-
33
- // Read package.json (optional)
34
- let pkgName: string | undefined;
35
- let pkgVersion: string | undefined;
36
- let pkgDescription: string | undefined;
37
-
38
- const pkgJsonPath = path.join(targetDir, "package.json");
39
- if (fs.existsSync(pkgJsonPath)) {
40
- try {
41
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
42
- pkgName = pkg.name;
43
- pkgVersion = pkg.version;
44
- pkgDescription = pkg.description;
45
- } catch {
46
- // ignore malformed package.json
47
- }
48
- }
49
-
50
- const title = pkgName || path.basename(targetDir);
51
- const description = pkgDescription || "";
52
-
53
- if (options.id) {
54
- // Update existing skill
55
- console.log(`⏳ 更新技能 ${options.id}...`);
56
-
57
- const res = await fetch(`${BASE_URL}/api/assets/${options.id}`, {
58
- method: "PATCH",
59
- headers: {
60
- Authorization: `Bearer ${apiKey}`,
61
- "Content-Type": "application/json",
62
- },
63
- body: JSON.stringify({ content }),
64
- });
65
-
66
- if (!res.ok) {
67
- const body = await res.text();
68
- console.error(`❌ 更新失败 (${res.status}): ${body}`);
69
- process.exit(1);
70
- }
71
-
72
- const { asset } = (await res.json()) as AssetResponse;
73
- const skillId = asset?.id || options.id;
74
- console.log(`✅ 技能已更新`);
75
- console.log(`🔗 ${BASE_URL}/market/${skillId}`);
76
- } else {
77
- // Publish new skill
78
- console.log(`⏳ 发布新技能: ${title}...`);
79
-
80
- const res = await fetch(`${BASE_URL}/api/assets`, {
81
- method: "POST",
82
- headers: {
83
- Authorization: `Bearer ${apiKey}`,
84
- "Content-Type": "application/json",
85
- },
86
- body: JSON.stringify({
87
- title,
88
- content,
89
- description: description || title,
90
- category: "other",
91
- }),
92
- });
93
-
94
- if (!res.ok) {
95
- const body = await res.text();
96
- console.error(`❌ 发布失败 (${res.status}): ${body}`);
97
- process.exit(1);
98
- }
99
-
100
- const { asset } = (await res.json()) as AssetResponse;
101
- console.log(`✅ 技能发布成功!`);
102
- console.log(`🔗 ${BASE_URL}/market/${asset?.id}`);
103
- if (pkgVersion) {
104
- console.log(`📦 版本: ${pkgVersion}`);
105
- }
106
- }
107
- }
@@ -1,84 +0,0 @@
1
- import { requireApiKey, BASE_URL } from "../config";
2
-
3
- interface Bounty {
4
- id: number;
5
- title: string;
6
- reward: number;
7
- status: string;
8
- expires_at: string | null;
9
- poster_username: string | null;
10
- tags: string[] | null;
11
- submission_count: number;
12
- }
13
-
14
- interface BountiesResponse {
15
- bounties: Bounty[];
16
- total: number;
17
- page: number;
18
- totalPages: number;
19
- }
20
-
21
- export async function tasksAction(): Promise<void> {
22
- const apiKey = requireApiKey();
23
-
24
- const res = await fetch(`${BASE_URL}/api/bounties?status=open&sort=date_desc`, {
25
- headers: { Authorization: `Bearer ${apiKey}` },
26
- });
27
-
28
- if (!res.ok) {
29
- const body = await res.text();
30
- console.error(`❌ 请求失败 (${res.status}): ${body}`);
31
- process.exit(1);
32
- }
33
-
34
- const data = (await res.json()) as BountiesResponse;
35
- const bounties = data.bounties ?? [];
36
-
37
- if (bounties.length === 0) {
38
- console.log("📭 当前没有可接的任务");
39
- return;
40
- }
41
-
42
- console.log(`🎯 可接任务列表 (共 ${data.total} 个)\n`);
43
-
44
- const idW = 6;
45
- const titleW = 36;
46
- const rewardW = 8;
47
- const expiresW = 12;
48
- const submissionsW = 5;
49
-
50
- const header = [
51
- "ID".padEnd(idW),
52
- "标题".padEnd(titleW),
53
- "奖励🦞".padEnd(rewardW),
54
- "截止日期".padEnd(expiresW),
55
- "投递".padEnd(submissionsW),
56
- ].join(" | ");
57
-
58
- const separator = [
59
- "-".repeat(idW),
60
- "-".repeat(titleW),
61
- "-".repeat(rewardW),
62
- "-".repeat(expiresW),
63
- "-".repeat(submissionsW),
64
- ].join("-+-");
65
-
66
- console.log(header);
67
- console.log(separator);
68
-
69
- for (const b of bounties) {
70
- const expiresStr = b.expires_at
71
- ? new Date(b.expires_at).toLocaleDateString("zh-CN")
72
- : "无期限";
73
- const row = [
74
- String(b.id).padEnd(idW),
75
- (b.title || "").slice(0, titleW).padEnd(titleW),
76
- String(b.reward).padEnd(rewardW),
77
- expiresStr.padEnd(expiresW),
78
- String(b.submission_count ?? 0).padEnd(submissionsW),
79
- ].join(" | ");
80
- console.log(row);
81
- }
82
-
83
- console.log(`\n使用 npx easyclaw-link bid <任务ID> 接取任务`);
84
- }
@@ -1,45 +0,0 @@
1
- import { requireApiKey, BASE_URL } from "../config";
2
-
3
- interface User {
4
- id: number;
5
- username: string;
6
- email: string;
7
- role: string;
8
- admin_roles: string[] | null;
9
- credits: number;
10
- reputation: number;
11
- level_num: number;
12
- }
13
-
14
- interface MeResponse {
15
- user: User | null;
16
- }
17
-
18
- export async function whoamiAction(): Promise<void> {
19
- const apiKey = requireApiKey();
20
-
21
- const res = await fetch(`${BASE_URL}/api/auth/me`, {
22
- headers: { Authorization: `Bearer ${apiKey}` },
23
- });
24
-
25
- if (!res.ok) {
26
- const body = await res.text();
27
- console.error(`❌ 请求失败 (${res.status}): ${body}`);
28
- process.exit(1);
29
- }
30
-
31
- const { user } = (await res.json()) as MeResponse;
32
-
33
- if (!user) {
34
- console.error("❌ 未登录或 API Key 已失效,请重新运行 npx easyclaw-link login");
35
- process.exit(1);
36
- }
37
-
38
- console.log("👤 当前登录用户\n");
39
- console.log(`用户名: ${user.username}`);
40
- console.log(`邮箱: ${user.email}`);
41
- console.log(`角色: ${user.role}`);
42
- console.log(`龙虾币: ${user.credits} 🦞`);
43
- console.log(`声望: ${user.reputation}`);
44
- console.log(`等级: Lv.${user.level_num}`);
45
- }
package/src/config.ts DELETED
@@ -1,45 +0,0 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
3
- import * as os from "os";
4
-
5
- const CONFIG_DIR = path.join(os.homedir(), ".easyclaw");
6
- const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
7
-
8
- export interface Config {
9
- apiKey?: string;
10
- }
11
-
12
- export function readConfig(): Config {
13
- try {
14
- if (!fs.existsSync(CONFIG_FILE)) {
15
- return {};
16
- }
17
- const raw = fs.readFileSync(CONFIG_FILE, "utf-8");
18
- return JSON.parse(raw) as Config;
19
- } catch {
20
- return {};
21
- }
22
- }
23
-
24
- export function writeConfig(config: Config): void {
25
- if (!fs.existsSync(CONFIG_DIR)) {
26
- fs.mkdirSync(CONFIG_DIR, { recursive: true });
27
- }
28
- fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), "utf-8");
29
- }
30
-
31
- export function getApiKey(): string | null {
32
- const config = readConfig();
33
- return config.apiKey ?? null;
34
- }
35
-
36
- export function requireApiKey(): string {
37
- const key = getApiKey();
38
- if (!key) {
39
- console.error("❌ 未登录,请先运行 npx easyclaw-link login");
40
- process.exit(1);
41
- }
42
- return key;
43
- }
44
-
45
- export const BASE_URL = "https://easyclaw.link";
package/src/index.ts DELETED
@@ -1,55 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from "commander";
4
- import { loginAction } from "./commands/login";
5
- import { publishAction } from "./commands/publish";
6
- import { listAction } from "./commands/list";
7
- import { whoamiAction } from "./commands/whoami";
8
- import { creditsAction } from "./commands/credits";
9
- import { tasksAction } from "./commands/tasks";
10
- import { bidAction } from "./commands/bid";
11
-
12
- const program = new Command();
13
-
14
- program
15
- .name("easyclaw-link")
16
- .description("EasyClaw Link CLI - Publish and manage skills on easyclaw.link")
17
- .version("1.1.0");
18
-
19
- program
20
- .command("login")
21
- .description("登录 EasyClaw 平台,保存 API Key")
22
- .action(loginAction);
23
-
24
- program
25
- .command("publish [dir]")
26
- .description("发布或更新技能到 EasyClaw 平台")
27
- .option("--id <id>", "指定技能 ID 进行更新")
28
- .action(publishAction);
29
-
30
- program
31
- .command("list")
32
- .description("查看我发布的所有技能")
33
- .action(listAction);
34
-
35
- program
36
- .command("whoami")
37
- .description("查看当前登录用户信息(用户名、邮箱、龙虾币余额、角色)")
38
- .action(whoamiAction);
39
-
40
- program
41
- .command("credits")
42
- .description("查看龙虾币余额和最近收支记录")
43
- .action(creditsAction);
44
-
45
- program
46
- .command("tasks")
47
- .description("浏览可接的任务/悬赏列表(status=open)")
48
- .action(tasksAction);
49
-
50
- program
51
- .command("bid <task-id>")
52
- .description("对指定任务提交申请(接活)")
53
- .action(bidAction);
54
-
55
- program.parse();
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "outDir": "dist",
6
- "rootDir": "src",
7
- "strict": true,
8
- "esModuleInterop": true,
9
- "skipLibCheck": true,
10
- "forceConsistentCasingInFileNames": true,
11
- "resolveJsonModule": true,
12
- "declaration": true,
13
- "declarationMap": true,
14
- "sourceMap": true
15
- },
16
- "include": ["src/**/*"],
17
- "exclude": ["node_modules", "dist"]
18
- }