@cozeclaw/coze-openclaw-plugin 0.1.1 → 0.1.2
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/index.ts +10 -0
- package/openclaw.plugin.json +0 -1
- package/package.json +2 -2
- package/src/plugin.test.ts +62 -0
package/index.ts
CHANGED
|
@@ -2,11 +2,21 @@ import type { OpenClawPluginApi } from "openclaw/plugin-sdk/core";
|
|
|
2
2
|
import { createCozeWebFetchTool } from "./src/tools/web-fetch.js";
|
|
3
3
|
import { createCozeWebSearchTool } from "./src/tools/web-search.js";
|
|
4
4
|
|
|
5
|
+
function hasApiKey(pluginConfig: OpenClawPluginApi["pluginConfig"]): boolean {
|
|
6
|
+
return typeof pluginConfig?.apiKey === "string" && pluginConfig.apiKey.trim().length > 0;
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
const plugin = {
|
|
6
10
|
id: "coze-openclaw-plugin",
|
|
7
11
|
name: "Coze OpenClaw Plugin",
|
|
8
12
|
description: "Coze web tools and bundled generation skills for OpenClaw.",
|
|
9
13
|
register(api: OpenClawPluginApi) {
|
|
14
|
+
if (!hasApiKey(api.pluginConfig)) {
|
|
15
|
+
api.logger.info?.(
|
|
16
|
+
"Skipping Coze tool registration because plugins.entries.coze-openclaw-plugin.config.apiKey is missing.",
|
|
17
|
+
);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
10
20
|
api.registerTool(
|
|
11
21
|
createCozeWebSearchTool({
|
|
12
22
|
pluginConfig: api.pluginConfig,
|
package/openclaw.plugin.json
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cozeclaw/coze-openclaw-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "OpenClaw Coze tools and bundled skills",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "vitest run src/config.test.ts src/skill-cli.test.ts src/tools/web-search.test.ts src/tools/web-fetch.test.ts"
|
|
7
|
+
"test": "vitest run src/config.test.ts src/plugin.test.ts src/skill-cli.test.ts src/tools/web-search.test.ts src/tools/web-fetch.test.ts"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"openclaw": "v2026.2.6",
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import plugin from "../index.js";
|
|
3
|
+
|
|
4
|
+
function createApi(pluginConfig: Record<string, unknown>) {
|
|
5
|
+
return {
|
|
6
|
+
id: "coze-openclaw-plugin",
|
|
7
|
+
name: "Coze OpenClaw Plugin",
|
|
8
|
+
description: "Coze OpenClaw",
|
|
9
|
+
source: "test",
|
|
10
|
+
config: {},
|
|
11
|
+
pluginConfig,
|
|
12
|
+
runtime: {} as never,
|
|
13
|
+
logger: {
|
|
14
|
+
debug() {},
|
|
15
|
+
info: vi.fn(),
|
|
16
|
+
warn() {},
|
|
17
|
+
error() {},
|
|
18
|
+
},
|
|
19
|
+
registerTool: vi.fn(),
|
|
20
|
+
registerHook() {},
|
|
21
|
+
registerHttpRoute() {},
|
|
22
|
+
registerChannel() {},
|
|
23
|
+
registerGatewayMethod() {},
|
|
24
|
+
registerCli() {},
|
|
25
|
+
registerService() {},
|
|
26
|
+
registerProvider() {},
|
|
27
|
+
registerCommand() {},
|
|
28
|
+
registerContextEngine() {},
|
|
29
|
+
resolvePath(input: string) {
|
|
30
|
+
return input;
|
|
31
|
+
},
|
|
32
|
+
on() {},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe("plugin registration", () => {
|
|
37
|
+
it("skips tool registration when apiKey is missing", () => {
|
|
38
|
+
const api = createApi({});
|
|
39
|
+
|
|
40
|
+
plugin.register?.(api);
|
|
41
|
+
|
|
42
|
+
expect(api.registerTool).not.toHaveBeenCalled();
|
|
43
|
+
expect(api.logger.info).toHaveBeenCalledWith(
|
|
44
|
+
"Skipping Coze tool registration because plugins.entries.coze-openclaw-plugin.config.apiKey is missing.",
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("registers coze web tools when apiKey exists", () => {
|
|
49
|
+
const api = createApi({ apiKey: "test-key" });
|
|
50
|
+
|
|
51
|
+
plugin.register?.(api);
|
|
52
|
+
|
|
53
|
+
expect(api.registerTool).toHaveBeenCalledTimes(2);
|
|
54
|
+
const toolNames = api.registerTool.mock.calls
|
|
55
|
+
.map((call) => {
|
|
56
|
+
const tool = call[0];
|
|
57
|
+
return typeof tool === "function" ? undefined : tool.name;
|
|
58
|
+
})
|
|
59
|
+
.filter(Boolean);
|
|
60
|
+
expect(toolNames).toEqual(["coze_web_search", "coze_web_fetch"]);
|
|
61
|
+
});
|
|
62
|
+
});
|