@openvole/paw-xai 0.1.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 +45 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +270 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
- package/vole-paw.json +16 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @openvole/paw-xai
|
|
2
|
+
|
|
3
|
+
**Brain Paw powered by xAI Grok models.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@openvole/paw-xai)
|
|
6
|
+
|
|
7
|
+
Part of [OpenVole](https://github.com/openvole/openvole) — the microkernel AI agent framework.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @openvole/paw-xai
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Config
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"brain": "@openvole/paw-xai",
|
|
20
|
+
"paws": [
|
|
21
|
+
{
|
|
22
|
+
"name": "@openvole/paw-xai",
|
|
23
|
+
"allow": {
|
|
24
|
+
"network": ["api.x.ai"],
|
|
25
|
+
"env": ["XAI_API_KEY", "XAI_MODEL"]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Environment Variables
|
|
33
|
+
|
|
34
|
+
| Variable | Required | Description |
|
|
35
|
+
|----------|----------|-------------|
|
|
36
|
+
| `XAI_API_KEY` | Yes | xAI API key |
|
|
37
|
+
| `XAI_MODEL` | No | Model name (default: `grok-3`) |
|
|
38
|
+
|
|
39
|
+
## Brain
|
|
40
|
+
|
|
41
|
+
Implements the Think phase using xAI's OpenAI-compatible API. Supports BRAIN.md, identity files (SOUL.md, USER.md, AGENT.md), session history, and memory injection.
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
[MIT](https://github.com/openvole/pawhub/blob/main/LICENSE)
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { definePaw } from "@openvole/paw-sdk";
|
|
3
|
+
|
|
4
|
+
// src/paw.ts
|
|
5
|
+
import * as fs from "fs/promises";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
import OpenAI from "openai";
|
|
8
|
+
var client;
|
|
9
|
+
var model = "grok-3";
|
|
10
|
+
var identityContext;
|
|
11
|
+
var customBrainPrompt;
|
|
12
|
+
async function loadBrainPrompt() {
|
|
13
|
+
try {
|
|
14
|
+
const content = await fs.readFile(
|
|
15
|
+
path.resolve(process.cwd(), ".openvole", "BRAIN.md"),
|
|
16
|
+
"utf-8"
|
|
17
|
+
);
|
|
18
|
+
if (content.trim()) {
|
|
19
|
+
console.log("[paw-xai] loaded custom BRAIN.md prompt");
|
|
20
|
+
return content.trim();
|
|
21
|
+
}
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
async function loadIdentityFiles() {
|
|
27
|
+
const openvoleDir = path.resolve(process.cwd(), ".openvole");
|
|
28
|
+
const files = [
|
|
29
|
+
{ name: "SOUL.md", section: "Agent Identity" },
|
|
30
|
+
{ name: "USER.md", section: "User Profile" },
|
|
31
|
+
{ name: "AGENT.md", section: "Agent Rules" }
|
|
32
|
+
];
|
|
33
|
+
const parts = [];
|
|
34
|
+
for (const file of files) {
|
|
35
|
+
try {
|
|
36
|
+
const content = await fs.readFile(path.join(openvoleDir, file.name), "utf-8");
|
|
37
|
+
if (content.trim()) {
|
|
38
|
+
parts.push(`## ${file.section}
|
|
39
|
+
${content.trim()}`);
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return parts.join("\n\n");
|
|
45
|
+
}
|
|
46
|
+
function getClient() {
|
|
47
|
+
if (!client) {
|
|
48
|
+
const apiKey = process.env.XAI_API_KEY;
|
|
49
|
+
model = process.env.XAI_MODEL || "grok-3";
|
|
50
|
+
client = new OpenAI({ apiKey, baseURL: "https://api.x.ai/v1" });
|
|
51
|
+
}
|
|
52
|
+
return client;
|
|
53
|
+
}
|
|
54
|
+
function buildSystemPrompt(activeSkills, availableTools, metadata, identityCtx, customBrain) {
|
|
55
|
+
const now = /* @__PURE__ */ new Date();
|
|
56
|
+
const runtimeContext = `## Current Context
|
|
57
|
+
- Date: ${now.toLocaleDateString("en-US", { weekday: "long", year: "numeric", month: "long", day: "numeric" })}
|
|
58
|
+
- Time: ${now.toLocaleTimeString("en-US", { hour12: true })}
|
|
59
|
+
- Platform: ${process.platform}
|
|
60
|
+
- Model: ${model}`;
|
|
61
|
+
const basePrompt = customBrain ?? `You are an AI agent powered by OpenVole. You accomplish tasks by using tools step by step.
|
|
62
|
+
|
|
63
|
+
## How to Work
|
|
64
|
+
1. Read the conversation history first \u2014 short user messages like an email or "yes" are answers to your previous questions
|
|
65
|
+
2. Break complex tasks into clear steps and execute them one at a time
|
|
66
|
+
3. After each tool call, examine the result carefully before deciding the next action
|
|
67
|
+
4. Never repeat the same tool call if it already succeeded \u2014 move to the next step
|
|
68
|
+
5. If a tool returns an error, try a different approach or different parameters
|
|
69
|
+
6. When you read important information (API docs, instructions, credentials), save it to workspace or memory immediately
|
|
70
|
+
7. When you have enough information to respond, do so directly \u2014 don't keep searching
|
|
71
|
+
8. If you cannot complete a task (missing credentials, access denied), explain exactly what you need and stop
|
|
72
|
+
|
|
73
|
+
## Data Management
|
|
74
|
+
- **Vault** (vault_store/get): ALL sensitive data \u2014 emails, passwords, API keys, tokens, credentials, usernames, handles, personal identifiers. ALWAYS use vault for these, NEVER memory or workspace.
|
|
75
|
+
- **Memory** (memory_write/read): General knowledge, non-sensitive facts, preferences, summaries
|
|
76
|
+
- **Workspace** (workspace_write/read): Files, documents, downloaded content, API docs, drafts
|
|
77
|
+
- **Session history**: Recent conversation \u2014 automatically available, review it before each response
|
|
78
|
+
|
|
79
|
+
## Recurring Tasks
|
|
80
|
+
When the user asks you to do something regularly, repeatedly, or on a schedule:
|
|
81
|
+
- **schedule_task**: Use this for tasks with a specific interval (e.g. "post every 6 hours", "check every 30 minutes"). Creates an automatic timer \u2014 no heartbeat needed.
|
|
82
|
+
- **heartbeat_write**: Use this ONLY for open-ended checks with no specific interval (e.g. "keep an eye on server status"). These run on the global heartbeat timer.
|
|
83
|
+
- Use ONE or the OTHER \u2014 never both for the same task. If you use schedule_task, do NOT also add it to HEARTBEAT.md.
|
|
84
|
+
- Do NOT just save recurring task requests to memory \u2014 that won't make them happen.
|
|
85
|
+
|
|
86
|
+
## Safety
|
|
87
|
+
- Never attempt to bypass access controls or escalate permissions
|
|
88
|
+
- Always ask for confirmation before performing destructive or irreversible actions
|
|
89
|
+
- Store credentials and personal identifiers ONLY in the vault \u2014 never in memory or workspace`;
|
|
90
|
+
const parts = [basePrompt, "", runtimeContext];
|
|
91
|
+
if (identityCtx) {
|
|
92
|
+
parts.push("");
|
|
93
|
+
parts.push(identityCtx);
|
|
94
|
+
}
|
|
95
|
+
if (metadata?.sessionHistory && typeof metadata.sessionHistory === "string") {
|
|
96
|
+
parts.push("");
|
|
97
|
+
parts.push("## Conversation History");
|
|
98
|
+
parts.push("Previous messages in this session. Use this to understand the current context and follow-up messages:");
|
|
99
|
+
parts.push(metadata.sessionHistory);
|
|
100
|
+
}
|
|
101
|
+
if (metadata?.memory && typeof metadata.memory === "string") {
|
|
102
|
+
parts.push("");
|
|
103
|
+
parts.push("## Agent Memory");
|
|
104
|
+
parts.push(metadata.memory);
|
|
105
|
+
}
|
|
106
|
+
if (activeSkills.length > 0) {
|
|
107
|
+
parts.push("");
|
|
108
|
+
parts.push("## Available Skills");
|
|
109
|
+
parts.push(
|
|
110
|
+
"The following skills are available. Use the skill_read tool to load full instructions when a skill is relevant to the current task."
|
|
111
|
+
);
|
|
112
|
+
for (const skill of activeSkills) {
|
|
113
|
+
parts.push(`- **${skill.name}**: ${skill.description}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (availableTools.length > 0) {
|
|
117
|
+
parts.push("");
|
|
118
|
+
parts.push("## Available Tools");
|
|
119
|
+
parts.push(
|
|
120
|
+
"You have access to the following tools. Use function calling to invoke them when needed."
|
|
121
|
+
);
|
|
122
|
+
for (const tool of availableTools) {
|
|
123
|
+
parts.push(`- **${tool.name}** (from ${tool.pawName}): ${tool.description}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return parts.join("\n");
|
|
127
|
+
}
|
|
128
|
+
function convertMessages(systemPrompt, messages) {
|
|
129
|
+
const result = [
|
|
130
|
+
{ role: "system", content: systemPrompt }
|
|
131
|
+
];
|
|
132
|
+
for (const msg of messages) {
|
|
133
|
+
switch (msg.role) {
|
|
134
|
+
case "user":
|
|
135
|
+
result.push({ role: "user", content: msg.content });
|
|
136
|
+
break;
|
|
137
|
+
case "brain":
|
|
138
|
+
result.push({ role: "assistant", content: msg.content });
|
|
139
|
+
break;
|
|
140
|
+
case "tool_result":
|
|
141
|
+
result.push({
|
|
142
|
+
role: "tool",
|
|
143
|
+
content: msg.content,
|
|
144
|
+
tool_call_id: msg.toolCallId || "unknown"
|
|
145
|
+
});
|
|
146
|
+
break;
|
|
147
|
+
case "error":
|
|
148
|
+
result.push({
|
|
149
|
+
role: "tool",
|
|
150
|
+
content: `Error: ${msg.content}`,
|
|
151
|
+
tool_call_id: msg.toolCallId || "unknown"
|
|
152
|
+
});
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
function convertTools(tools) {
|
|
159
|
+
return tools.map((tool) => ({
|
|
160
|
+
type: "function",
|
|
161
|
+
function: {
|
|
162
|
+
name: tool.name,
|
|
163
|
+
description: tool.description,
|
|
164
|
+
parameters: {
|
|
165
|
+
type: "object",
|
|
166
|
+
properties: {}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
function parseToolCalls(message) {
|
|
172
|
+
if (!message.tool_calls || message.tool_calls.length === 0) {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
return message.tool_calls.map((call) => {
|
|
176
|
+
let params = {};
|
|
177
|
+
try {
|
|
178
|
+
params = JSON.parse(call.function.arguments);
|
|
179
|
+
} catch {
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
tool: call.function.name,
|
|
183
|
+
params
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
var paw = {
|
|
188
|
+
name: "@openvole/paw-xai",
|
|
189
|
+
version: "0.1.0",
|
|
190
|
+
description: "Brain Paw powered by OpenAI",
|
|
191
|
+
brain: true,
|
|
192
|
+
async think(context) {
|
|
193
|
+
const openai = getClient();
|
|
194
|
+
const start = Date.now();
|
|
195
|
+
try {
|
|
196
|
+
const systemPrompt = buildSystemPrompt(
|
|
197
|
+
context.activeSkills,
|
|
198
|
+
context.availableTools,
|
|
199
|
+
context.metadata,
|
|
200
|
+
identityContext,
|
|
201
|
+
customBrainPrompt
|
|
202
|
+
);
|
|
203
|
+
const openaiMessages = convertMessages(systemPrompt, context.messages);
|
|
204
|
+
const openaiTools = convertTools(context.availableTools);
|
|
205
|
+
const response = await openai.chat.completions.create({
|
|
206
|
+
model,
|
|
207
|
+
messages: openaiMessages,
|
|
208
|
+
...openaiTools.length > 0 ? { tools: openaiTools } : {}
|
|
209
|
+
});
|
|
210
|
+
const durationMs = Date.now() - start;
|
|
211
|
+
console.log(
|
|
212
|
+
`[paw-xai] think completed in ${durationMs}ms (model: ${model})`
|
|
213
|
+
);
|
|
214
|
+
const choice = response.choices[0];
|
|
215
|
+
if (!choice) {
|
|
216
|
+
return {
|
|
217
|
+
actions: [],
|
|
218
|
+
response: "No response from OpenAI.",
|
|
219
|
+
done: true
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const actions = parseToolCalls(choice.message);
|
|
223
|
+
if (actions.length > 0) {
|
|
224
|
+
return {
|
|
225
|
+
actions,
|
|
226
|
+
execution: "sequential"
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const text = choice.message.content || "";
|
|
230
|
+
return {
|
|
231
|
+
actions: [],
|
|
232
|
+
response: text,
|
|
233
|
+
done: choice.finish_reason === "stop"
|
|
234
|
+
};
|
|
235
|
+
} catch (error) {
|
|
236
|
+
const durationMs = Date.now() - start;
|
|
237
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
238
|
+
console.error(
|
|
239
|
+
`[paw-xai] think failed after ${durationMs}ms: ${message}`
|
|
240
|
+
);
|
|
241
|
+
return {
|
|
242
|
+
actions: [],
|
|
243
|
+
response: `Error communicating with OpenAI API: ${message}`,
|
|
244
|
+
done: true
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
async onLoad() {
|
|
249
|
+
getClient();
|
|
250
|
+
customBrainPrompt = await loadBrainPrompt();
|
|
251
|
+
identityContext = await loadIdentityFiles();
|
|
252
|
+
if (identityContext) {
|
|
253
|
+
console.log("[paw-xai] loaded identity files (SOUL.md, USER.md, AGENT.md)");
|
|
254
|
+
}
|
|
255
|
+
console.log(
|
|
256
|
+
`[paw-xai] loaded \u2014 model: ${model}`
|
|
257
|
+
);
|
|
258
|
+
},
|
|
259
|
+
async onUnload() {
|
|
260
|
+
client = void 0;
|
|
261
|
+
console.log("[paw-xai] unloaded");
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/index.ts
|
|
266
|
+
var index_default = definePaw(paw);
|
|
267
|
+
export {
|
|
268
|
+
index_default as default
|
|
269
|
+
};
|
|
270
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/paw.ts"],"sourcesContent":["import { definePaw } from '@openvole/paw-sdk'\nimport { paw } from './paw.js'\n\nexport default definePaw(paw)\n","import * as fs from 'node:fs/promises'\nimport * as path from 'node:path'\nimport OpenAI from 'openai'\nimport type {\n\tPawDefinition,\n\tAgentContext,\n\tAgentPlan,\n\tAgentMessage,\n\tActiveSkill,\n\tPlannedAction,\n\tToolSummary,\n} from '@openvole/paw-sdk'\n\nlet client: OpenAI | undefined\nlet model: string = 'grok-3'\n\n/** Cached identity files — loaded once on startup */\nlet identityContext: string | undefined\n\n/** Custom brain prompt from BRAIN.md — overrides default system prompt if present */\nlet customBrainPrompt: string | undefined\n\n/** Load BRAIN.md from .openvole/ — if it exists, it replaces the default system prompt */\nasync function loadBrainPrompt(): Promise<string | undefined> {\n\ttry {\n\t\tconst content = await fs.readFile(\n\t\t\tpath.resolve(process.cwd(), '.openvole', 'BRAIN.md'),\n\t\t\t'utf-8',\n\t\t)\n\t\tif (content.trim()) {\n\t\t\tconsole.log('[paw-xai] loaded custom BRAIN.md prompt')\n\t\t\treturn content.trim()\n\t\t}\n\t} catch {\n\t\t// No BRAIN.md — use default\n\t}\n\treturn undefined\n}\n\n/** Load identity files from .openvole/ (AGENT.md, USER.md, SOUL.md) */\nasync function loadIdentityFiles(): Promise<string> {\n\tconst openvoleDir = path.resolve(process.cwd(), '.openvole')\n\tconst files = [\n\t\t{ name: 'SOUL.md', section: 'Agent Identity' },\n\t\t{ name: 'USER.md', section: 'User Profile' },\n\t\t{ name: 'AGENT.md', section: 'Agent Rules' },\n\t]\n\n\tconst parts: string[] = []\n\tfor (const file of files) {\n\t\ttry {\n\t\t\tconst content = await fs.readFile(path.join(openvoleDir, file.name), 'utf-8')\n\t\t\tif (content.trim()) {\n\t\t\t\tparts.push(`## ${file.section}\\n${content.trim()}`)\n\t\t\t}\n\t\t} catch {\n\t\t\t// File doesn't exist — skip\n\t\t}\n\t}\n\n\treturn parts.join('\\n\\n')\n}\n\nfunction getClient(): OpenAI {\n\tif (!client) {\n\t\tconst apiKey = process.env.XAI_API_KEY\n\t\tmodel = process.env.XAI_MODEL || 'grok-3'\n\t\tclient = new OpenAI({ apiKey, baseURL: 'https://api.x.ai/v1' })\n\t}\n\treturn client\n}\n\nfunction buildSystemPrompt(\n\tactiveSkills: ActiveSkill[],\n\tavailableTools: ToolSummary[],\n\tmetadata?: Record<string, unknown>,\n\tidentityCtx?: string,\n\tcustomBrain?: string,\n): string {\n\tconst now = new Date()\n\tconst runtimeContext = `## Current Context\n- Date: ${now.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })}\n- Time: ${now.toLocaleTimeString('en-US', { hour12: true })}\n- Platform: ${process.platform}\n- Model: ${model}`\n\n\t// Use custom BRAIN.md if provided, otherwise use default prompt\n\tconst basePrompt = customBrain ?? `You are an AI agent powered by OpenVole. You accomplish tasks by using tools step by step.\n\n## How to Work\n1. Read the conversation history first — short user messages like an email or \"yes\" are answers to your previous questions\n2. Break complex tasks into clear steps and execute them one at a time\n3. After each tool call, examine the result carefully before deciding the next action\n4. Never repeat the same tool call if it already succeeded — move to the next step\n5. If a tool returns an error, try a different approach or different parameters\n6. When you read important information (API docs, instructions, credentials), save it to workspace or memory immediately\n7. When you have enough information to respond, do so directly — don't keep searching\n8. If you cannot complete a task (missing credentials, access denied), explain exactly what you need and stop\n\n## Data Management\n- **Vault** (vault_store/get): ALL sensitive data — emails, passwords, API keys, tokens, credentials, usernames, handles, personal identifiers. ALWAYS use vault for these, NEVER memory or workspace.\n- **Memory** (memory_write/read): General knowledge, non-sensitive facts, preferences, summaries\n- **Workspace** (workspace_write/read): Files, documents, downloaded content, API docs, drafts\n- **Session history**: Recent conversation — automatically available, review it before each response\n\n## Recurring Tasks\nWhen the user asks you to do something regularly, repeatedly, or on a schedule:\n- **schedule_task**: Use this for tasks with a specific interval (e.g. \"post every 6 hours\", \"check every 30 minutes\"). Creates an automatic timer — no heartbeat needed.\n- **heartbeat_write**: Use this ONLY for open-ended checks with no specific interval (e.g. \"keep an eye on server status\"). These run on the global heartbeat timer.\n- Use ONE or the OTHER — never both for the same task. If you use schedule_task, do NOT also add it to HEARTBEAT.md.\n- Do NOT just save recurring task requests to memory — that won't make them happen.\n\n## Safety\n- Never attempt to bypass access controls or escalate permissions\n- Always ask for confirmation before performing destructive or irreversible actions\n- Store credentials and personal identifiers ONLY in the vault — never in memory or workspace`\n\n\tconst parts: string[] = [basePrompt, '', runtimeContext]\n\n\t// Inject identity context (SOUL.md, USER.md, AGENT.md) if available\n\tif (identityCtx) {\n\t\tparts.push('')\n\t\tparts.push(identityCtx)\n\t}\n\n\t// Inject session history if available — this is critical for conversation continuity\n\tif (metadata?.sessionHistory && typeof metadata.sessionHistory === 'string') {\n\t\tparts.push('')\n\t\tparts.push('## Conversation History')\n\t\tparts.push('Previous messages in this session. Use this to understand the current context and follow-up messages:')\n\t\tparts.push(metadata.sessionHistory)\n\t}\n\n\t// Inject memory if available\n\tif (metadata?.memory && typeof metadata.memory === 'string') {\n\t\tparts.push('')\n\t\tparts.push('## Agent Memory')\n\t\tparts.push(metadata.memory)\n\t}\n\n\tif (activeSkills.length > 0) {\n\t\tparts.push('')\n\t\tparts.push('## Available Skills')\n\t\tparts.push(\n\t\t\t'The following skills are available. Use the skill_read tool to load full instructions when a skill is relevant to the current task.',\n\t\t)\n\t\tfor (const skill of activeSkills) {\n\t\t\tparts.push(`- **${skill.name}**: ${skill.description}`)\n\t\t}\n\t}\n\n\tif (availableTools.length > 0) {\n\t\tparts.push('')\n\t\tparts.push('## Available Tools')\n\t\tparts.push(\n\t\t\t'You have access to the following tools. Use function calling to invoke them when needed.',\n\t\t)\n\t\tfor (const tool of availableTools) {\n\t\t\tparts.push(`- **${tool.name}** (from ${tool.pawName}): ${tool.description}`)\n\t\t}\n\t}\n\n\treturn parts.join('\\n')\n}\n\nfunction convertMessages(\n\tsystemPrompt: string,\n\tmessages: AgentMessage[],\n): OpenAI.ChatCompletionMessageParam[] {\n\tconst result: OpenAI.ChatCompletionMessageParam[] = [\n\t\t{ role: 'system', content: systemPrompt },\n\t]\n\n\tfor (const msg of messages) {\n\t\tswitch (msg.role) {\n\t\t\tcase 'user':\n\t\t\t\tresult.push({ role: 'user', content: msg.content })\n\t\t\t\tbreak\n\t\t\tcase 'brain':\n\t\t\t\tresult.push({ role: 'assistant', content: msg.content })\n\t\t\t\tbreak\n\t\t\tcase 'tool_result':\n\t\t\t\tresult.push({\n\t\t\t\t\trole: 'tool',\n\t\t\t\t\tcontent: msg.content,\n\t\t\t\t\ttool_call_id: (msg as any).toolCallId || 'unknown',\n\t\t\t\t})\n\t\t\t\tbreak\n\t\t\tcase 'error':\n\t\t\t\tresult.push({\n\t\t\t\t\trole: 'tool',\n\t\t\t\t\tcontent: `Error: ${msg.content}`,\n\t\t\t\t\ttool_call_id: (msg as any).toolCallId || 'unknown',\n\t\t\t\t})\n\t\t\t\tbreak\n\t\t}\n\t}\n\n\treturn result\n}\n\nfunction convertTools(\n\ttools: ToolSummary[],\n): OpenAI.ChatCompletionTool[] {\n\treturn tools.map((tool) => ({\n\t\ttype: 'function' as const,\n\t\tfunction: {\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: {\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: {},\n\t\t\t},\n\t\t},\n\t}))\n}\n\nfunction parseToolCalls(\n\tmessage: OpenAI.ChatCompletionMessage,\n): PlannedAction[] {\n\tif (!message.tool_calls || message.tool_calls.length === 0) {\n\t\treturn []\n\t}\n\n\treturn message.tool_calls.map((call) => {\n\t\tlet params: Record<string, unknown> = {}\n\t\ttry {\n\t\t\tparams = JSON.parse(call.function.arguments)\n\t\t} catch {\n\t\t\t// If arguments can't be parsed, use empty params\n\t\t}\n\t\treturn {\n\t\t\ttool: call.function.name,\n\t\t\tparams,\n\t\t}\n\t})\n}\n\nexport const paw: PawDefinition = {\n\tname: '@openvole/paw-xai',\n\tversion: '0.1.0',\n\tdescription: 'Brain Paw powered by OpenAI',\n\tbrain: true,\n\n\tasync think(context: AgentContext): Promise<AgentPlan> {\n\t\tconst openai = getClient()\n\t\tconst start = Date.now()\n\n\t\ttry {\n\t\t\tconst systemPrompt = buildSystemPrompt(\n\t\t\t\tcontext.activeSkills,\n\t\t\t\tcontext.availableTools,\n\t\t\t\tcontext.metadata,\n\t\t\t\tidentityContext,\n\t\t\t\tcustomBrainPrompt,\n\t\t\t)\n\n\t\t\tconst openaiMessages = convertMessages(systemPrompt, context.messages)\n\t\t\tconst openaiTools = convertTools(context.availableTools)\n\n\t\t\tconst response = await openai.chat.completions.create({\n\t\t\t\tmodel,\n\t\t\t\tmessages: openaiMessages,\n\t\t\t\t...(openaiTools.length > 0 ? { tools: openaiTools } : {}),\n\t\t\t})\n\n\t\t\tconst durationMs = Date.now() - start\n\t\t\tconsole.log(\n\t\t\t\t`[paw-xai] think completed in ${durationMs}ms (model: ${model})`,\n\t\t\t)\n\n\t\t\tconst choice = response.choices[0]\n\t\t\tif (!choice) {\n\t\t\t\treturn {\n\t\t\t\t\tactions: [],\n\t\t\t\t\tresponse: 'No response from OpenAI.',\n\t\t\t\t\tdone: true,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst actions = parseToolCalls(choice.message)\n\n\t\t\tif (actions.length > 0) {\n\t\t\t\treturn {\n\t\t\t\t\tactions,\n\t\t\t\t\texecution: 'sequential',\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst text = choice.message.content || ''\n\n\t\t\treturn {\n\t\t\t\tactions: [],\n\t\t\t\tresponse: text,\n\t\t\t\tdone: choice.finish_reason === 'stop',\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst durationMs = Date.now() - start\n\t\t\tconst message =\n\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\tconsole.error(\n\t\t\t\t`[paw-xai] think failed after ${durationMs}ms: ${message}`,\n\t\t\t)\n\n\t\t\treturn {\n\t\t\t\tactions: [],\n\t\t\t\tresponse: `Error communicating with OpenAI API: ${message}`,\n\t\t\t\tdone: true,\n\t\t\t}\n\t\t}\n\t},\n\n\tasync onLoad() {\n\t\tgetClient()\n\t\tcustomBrainPrompt = await loadBrainPrompt()\n\t\tidentityContext = await loadIdentityFiles()\n\t\tif (identityContext) {\n\t\t\tconsole.log('[paw-xai] loaded identity files (SOUL.md, USER.md, AGENT.md)')\n\t\t}\n\t\tconsole.log(\n\t\t\t`[paw-xai] loaded — model: ${model}`,\n\t\t)\n\t},\n\n\tasync onUnload() {\n\t\tclient = undefined\n\t\tconsole.log('[paw-xai] unloaded')\n\t},\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;;;ACA1B,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,OAAO,YAAY;AAWnB,IAAI;AACJ,IAAI,QAAgB;AAGpB,IAAI;AAGJ,IAAI;AAGJ,eAAe,kBAA+C;AAC7D,MAAI;AACH,UAAM,UAAU,MAAS;AAAA,MACnB,aAAQ,QAAQ,IAAI,GAAG,aAAa,UAAU;AAAA,MACnD;AAAA,IACD;AACA,QAAI,QAAQ,KAAK,GAAG;AACnB,cAAQ,IAAI,yCAAyC;AACrD,aAAO,QAAQ,KAAK;AAAA,IACrB;AAAA,EACD,QAAQ;AAAA,EAER;AACA,SAAO;AACR;AAGA,eAAe,oBAAqC;AACnD,QAAM,cAAmB,aAAQ,QAAQ,IAAI,GAAG,WAAW;AAC3D,QAAM,QAAQ;AAAA,IACb,EAAE,MAAM,WAAW,SAAS,iBAAiB;AAAA,IAC7C,EAAE,MAAM,WAAW,SAAS,eAAe;AAAA,IAC3C,EAAE,MAAM,YAAY,SAAS,cAAc;AAAA,EAC5C;AAEA,QAAM,QAAkB,CAAC;AACzB,aAAW,QAAQ,OAAO;AACzB,QAAI;AACH,YAAM,UAAU,MAAS,YAAc,UAAK,aAAa,KAAK,IAAI,GAAG,OAAO;AAC5E,UAAI,QAAQ,KAAK,GAAG;AACnB,cAAM,KAAK,MAAM,KAAK,OAAO;AAAA,EAAK,QAAQ,KAAK,CAAC,EAAE;AAAA,MACnD;AAAA,IACD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,QACP;AAAA,MACD;AAEA,YAAM,UAAU,eAAe,OAAO,OAAO;AAE7C,UAAI,QAAQ,SAAS,GAAG;AACvB,eAAO;AAAA,UACN;AAAA,UACA,WAAW;AAAA,QACZ;AAAA,MACD;AAEA,YAAM,OAAO,OAAO,QAAQ,WAAW;AAEvC,aAAO;AAAA,QACN,SAAS,CAAC;AAAA,QACV,UAAU;AAAA,QACV,MAAM,OAAO,kBAAkB;AAAA,MAChC;AAAA,IACD,SAAS,OAAO;AACf,YAAM,aAAa,KAAK,IAAI,IAAI;AAChC,YAAM,UACL,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACtD,cAAQ;AAAA,QACP,gCAAgC,UAAU,OAAO,OAAO;AAAA,MACzD;AAEA,aAAO;AAAA,QACN,SAAS,CAAC;AAAA,QACV,UAAU,wCAAwC,OAAO;AAAA,QACzD,MAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM,SAAS;AACd,cAAU;AACV,wBAAoB,MAAM,gBAAgB;AAC1C,sBAAkB,MAAM,kBAAkB;AAC1C,QAAI,iBAAiB;AACpB,cAAQ,IAAI,8DAA8D;AAAA,IAC3E;AACA,YAAQ;AAAA,MACP,kCAA6B,KAAK;AAAA,IACnC;AAAA,EACD;AAAA,EAEA,MAAM,WAAW;AAChB,aAAS;AACT,YAAQ,IAAI,oBAAoB;AAAA,EACjC;AACD;;;ADrUA,IAAO,gBAAQ,UAAU,GAAG;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openvole/paw-xai",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Brain Paw powered by xAI Grok models",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsup",
|
|
16
|
+
"typecheck": "tsc --noEmit"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"openai": "^4.73.0"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@openvole/paw-sdk": "^0.3.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@openvole/paw-sdk": "^0.3.0",
|
|
26
|
+
"@types/node": "^22.0.0",
|
|
27
|
+
"tsup": "^8.3.0",
|
|
28
|
+
"typescript": "^5.6.0"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20.0.0"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"vole-paw.json",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/openvole/pawhub",
|
|
42
|
+
"directory": "paws/paw-xai"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"openvole",
|
|
46
|
+
"paw",
|
|
47
|
+
"xai",
|
|
48
|
+
"grok",
|
|
49
|
+
"brain",
|
|
50
|
+
"llm"
|
|
51
|
+
]
|
|
52
|
+
}
|
package/vole-paw.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openvole/paw-xai",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Brain Paw powered by xAI Grok models",
|
|
5
|
+
"entry": "./dist/index.js",
|
|
6
|
+
"brain": true,
|
|
7
|
+
"inProcess": false,
|
|
8
|
+
"transport": "ipc",
|
|
9
|
+
"tools": [],
|
|
10
|
+
"permissions": {
|
|
11
|
+
"network": ["api.x.ai"],
|
|
12
|
+
"listen": [],
|
|
13
|
+
"filesystem": [],
|
|
14
|
+
"env": ["XAI_API_KEY", "XAI_MODEL"]
|
|
15
|
+
}
|
|
16
|
+
}
|