@fw_dxs/openclaw-puter-ai 2.0.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.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # OpenClaw Puter AI Plugin
2
+
3
+ Adds AI capabilities to OpenClaw using Puter.
4
+
5
+ Commands:
6
+
7
+ /ai chat
8
+ /ai summarize
9
+ /ai image
10
+ /ai code
11
+ /ai analyze
12
+ /ai search
13
+
14
+ Install:
15
+
16
+ 1. Place folder in /plugins
17
+ 2. Run npm install
18
+ 3. Restart OpenClaw
package/agent.js ADDED
@@ -0,0 +1,23 @@
1
+ const webSearch = require("./tools/webSearch");
2
+ const codeGen = require("./tools/codeGen");
3
+
4
+ async function runAgent(prompt) {
5
+
6
+ const systemPrompt = `
7
+ You are an AI agent with tools:
8
+
9
+ webSearch(query) → search the internet
10
+ codeGen(prompt) → generate code
11
+
12
+ Use them when helpful.
13
+ `;
14
+
15
+ const response = await puter.ai.chat([
16
+ { role: "system", content: systemPrompt },
17
+ { role: "user", content: prompt }
18
+ ]);
19
+
20
+ return response;
21
+ }
22
+
23
+ module.exports = { runAgent };
package/index.js ADDED
@@ -0,0 +1,61 @@
1
+ console.log("Puter AI plugin loaded");
2
+ const ai = require("./puterClient");
3
+ const memory = require("./memory/conversation");
4
+ const agent = require("./agent");
5
+
6
+ module.exports = {
7
+
8
+ name: "puter-ai",
9
+
10
+ async handleCommand(command, args, user, stream) {
11
+
12
+ const prompt = args.join(" ");
13
+
14
+ if (command === "/ai chat") {
15
+
16
+ const history = memory.getHistory(user);
17
+
18
+ let result = "";
19
+
20
+ await ai.chat(
21
+ [...history, { role: "user", content: prompt }],
22
+ token => {
23
+ result += token;
24
+ if (stream) stream(token);
25
+ }
26
+ );
27
+
28
+ memory.addMessage(user, "user", prompt);
29
+ memory.addMessage(user, "assistant", result);
30
+
31
+ return result;
32
+ }
33
+
34
+ if (command === "/ai summarize") {
35
+
36
+ const response = await ai.chat([
37
+ { role: "system", content: "Summarize the following text." },
38
+ { role: "user", content: prompt }
39
+ ]);
40
+
41
+ return response;
42
+ }
43
+
44
+ if (command === "/ai image") {
45
+ return await ai.image(prompt);
46
+ }
47
+
48
+ if (command === "/ai code") {
49
+ return await agent.runAgent("Write code for: " + prompt);
50
+ }
51
+
52
+ if (command === "/ai search") {
53
+ return await agent.runAgent(prompt);
54
+ }
55
+
56
+ if (command === "/ai analyze") {
57
+ return await agent.runAgent("Analyze the following content:\n" + prompt);
58
+ }
59
+
60
+ }
61
+ };
@@ -0,0 +1,45 @@
1
+ const fs = require("fs");
2
+
3
+ const FILE = "./plugins/openclaw-puter-ai/memory.json";
4
+
5
+ function load() {
6
+
7
+ if (!fs.existsSync(FILE)) {
8
+ fs.writeFileSync(FILE, JSON.stringify({}));
9
+ }
10
+
11
+ return JSON.parse(fs.readFileSync(FILE));
12
+ }
13
+
14
+ function save(data) {
15
+ fs.writeFileSync(FILE, JSON.stringify(data, null, 2));
16
+ }
17
+
18
+ function getHistory(user) {
19
+
20
+ const data = load();
21
+
22
+ if (!data[user]) data[user] = [];
23
+
24
+ return data[user];
25
+ }
26
+
27
+ function addMessage(user, role, content) {
28
+
29
+ const data = load();
30
+
31
+ if (!data[user]) data[user] = [];
32
+
33
+ data[user].push({ role, content });
34
+
35
+ if (data[user].length > 20) {
36
+ data[user].shift();
37
+ }
38
+
39
+ save(data);
40
+ }
41
+
42
+ module.exports = {
43
+ getHistory,
44
+ addMessage
45
+ };
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": " @fw_dxs/openclaw-puter-ai",
3
+ "version": "2.0.0",
4
+ "description": "Advanced AI plugin for OpenClaw using Puter",
5
+ "main": "index.js",
6
+ "type": "commonjs",
7
+ "dependencies": {
8
+ "node-fetch": "^3.3.2",
9
+ "eventemitter3": "^5.0.1"
10
+ }
11
+ }
package/plugin.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "puter-ai",
3
+ "version": "2.0.0",
4
+ "description": "Adds AI commands powered by Puter",
5
+ "commands": [
6
+ "/ai chat",
7
+ "/ai summarize",
8
+ "/ai image",
9
+ "/ai code",
10
+ "/ai analyze",
11
+ "/ai search"
12
+ ]
13
+ }
package/puterClient.js ADDED
@@ -0,0 +1,20 @@
1
+ async function chat(messages, streamCallback) {
2
+
3
+ const response = await puter.ai.chat(messages, {
4
+ stream: true,
5
+ onToken: token => {
6
+ if (streamCallback) streamCallback(token);
7
+ }
8
+ });
9
+
10
+ return response;
11
+ }
12
+
13
+ async function image(prompt) {
14
+ return await puter.ai.image(prompt);
15
+ }
16
+
17
+ module.exports = {
18
+ chat,
19
+ image
20
+ };
@@ -0,0 +1,17 @@
1
+ async function codeGen(prompt) {
2
+
3
+ const response = await puter.ai.chat([
4
+ {
5
+ role: "system",
6
+ content: "You generate clean, working code."
7
+ },
8
+ {
9
+ role: "user",
10
+ content: prompt
11
+ }
12
+ ]);
13
+
14
+ return response;
15
+ }
16
+
17
+ module.exports = codeGen;
@@ -0,0 +1,13 @@
1
+ const fetch = require("node-fetch");
2
+
3
+ async function webSearch(query) {
4
+
5
+ const url = `https://api.duckduckgo.com/?q=${encodeURIComponent(query)}&format=json`;
6
+
7
+ const res = await fetch(url);
8
+ const data = await res.json();
9
+
10
+ return data.AbstractText || "No results found.";
11
+ }
12
+
13
+ module.exports = webSearch;