Skip to content

Commit 1b8d56c

Browse files
committed
fix: support external plugin upgrades
1 parent 62767aa commit 1b8d56c

7 files changed

Lines changed: 59 additions & 454 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ openclaw config set plugins.entries.aitoearn.config.apiKey \
4545
npx -y @aitoearn/openclaw-plugin
4646
```
4747

48+
升级插件:
49+
50+
```bash
51+
npx -y @aitoearn/openclaw-plugin upgrade
52+
```
53+
4854
完成配置后,重启 Gateway:
4955

5056
```bash

openclaw.plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "aitoearn",
33
"name": "AiToEarn",
44
"description": "AiToEarn social media management tools",
5-
"version": "1.0.4",
5+
"version": "1.0.5",
66
"configSchema": {
77
"type": "object",
88
"additionalProperties": false,

package-lock.json

Lines changed: 6 additions & 441 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aitoearn/openclaw-plugin",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"type": "module",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
@@ -44,13 +44,10 @@
4444
"@modelcontextprotocol/sdk": "^1.12.0",
4545
"@sinclair/typebox": "^0.34.0",
4646
"json5": "^2.2.3",
47+
"openclaw": ">=2026.3.24",
4748
"zod": "^3.24.0"
4849
},
49-
"peerDependencies": {
50-
"openclaw": ">=2026.3.24"
51-
},
5250
"devDependencies": {
53-
"openclaw": ">=2026.3.24",
5451
"typescript": "^5.4.0",
5552
"vitest": "^3.0.0"
5653
}

src/cli.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ describe("runSetupCli", () => {
131131
expect(writeConfig).not.toHaveBeenCalled();
132132
});
133133

134+
it("upgrades plugin files without rerunning setup", async () => {
135+
installPlugin.mockResolvedValue({
136+
replacedExisting: true,
137+
targetDir: "/tmp/.openclaw/extensions/aitoearn",
138+
});
139+
140+
const exitCode = await runSetupCli(["upgrade"], {
141+
prompts,
142+
loadPackageContext,
143+
installPlugin,
144+
readConfig,
145+
writeConfig,
146+
runSetupFlow,
147+
});
148+
149+
expect(exitCode).toBe(0);
150+
expect(installPlugin).toHaveBeenCalledWith(packageContext);
151+
expect(runSetupFlow).not.toHaveBeenCalled();
152+
expect(writeConfig).not.toHaveBeenCalled();
153+
expect(prompts.outro).toHaveBeenCalledWith(
154+
'Upgrade complete! Run "openclaw gateway restart" to apply.'
155+
);
156+
});
157+
134158
it("surfaces installation errors", async () => {
135159
installPlugin.mockRejectedValue(new Error("copy failed"));
136160

src/cli.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ interface CliDependencies {
3939
runSetupFlow: (options?: { showIntro?: boolean }) => Promise<SetupFlowResult>;
4040
}
4141

42-
const HELP_TEXT = `Usage: npx -y @aitoearn/openclaw-plugin
42+
const HELP_TEXT = `Usage: npx -y @aitoearn/openclaw-plugin [upgrade]
4343
4444
Bootstrap installer for the AiToEarn OpenClaw plugin.
4545
4646
Examples:
47-
npx -y @aitoearn/openclaw-plugin`;
47+
npx -y @aitoearn/openclaw-plugin
48+
npx -y @aitoearn/openclaw-plugin upgrade`;
4849

4950
export async function runSetupCli(
5051
args: string[],
@@ -57,12 +58,17 @@ export async function runSetupCli(
5758

5859
if (
5960
args.length > 1 ||
60-
(args.length === 1 && args[0] !== "setup" && args[0] !== "install")
61+
(args.length === 1 &&
62+
args[0] !== "setup" &&
63+
args[0] !== "install" &&
64+
args[0] !== "upgrade")
6165
) {
6266
console.error(HELP_TEXT);
6367
return 1;
6468
}
6569

70+
const command = args[0] ?? "install";
71+
6672
deps.prompts.intro("AiToEarn OpenClaw Setup");
6773

6874
let packageContext: PackageContext;
@@ -91,6 +97,13 @@ export async function runSetupCli(
9197
: "AiToEarn plugin installed."
9298
);
9399

100+
if (command === "upgrade") {
101+
deps.prompts.outro(
102+
'Upgrade complete! Run "openclaw gateway restart" to apply.'
103+
);
104+
return 0;
105+
}
106+
94107
const setupResult = await deps.runSetupFlow({ showIntro: false });
95108
if (setupResult.status === "cancelled") {
96109
return 0;

src/tool-discovery-worker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { workerData } from "node:worker_threads";
2+
import { resolveConfiguredSecretInputString } from "openclaw/plugin-sdk/config-runtime";
3+
import { getMcpClient } from "./mcp-client.js";
24
import { runToolDiscoveryHelper } from "./tool-discovery-helper.js";
35

46
interface ToolDiscoveryWorkerData {
@@ -28,10 +30,8 @@ async function main(): Promise<void> {
2830
const data = workerData as ToolDiscoveryWorkerData;
2931
const result = await runToolDiscoveryHelper(data.payload, {
3032
env: data.env ?? process.env,
31-
getMcpClient: (await import("./mcp-client.js")).getMcpClient,
32-
resolveConfiguredSecretInputString: (
33-
await import("openclaw/plugin-sdk/config-runtime")
34-
).resolveConfiguredSecretInputString,
33+
getMcpClient,
34+
resolveConfiguredSecretInputString,
3535
});
3636

3737
writeResult(result);

0 commit comments

Comments
 (0)