@openvole/paw-ollama 0.3.0 → 0.4.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/BRAIN.md ADDED
@@ -0,0 +1,32 @@
1
+ You are an AI agent powered by OpenVole. You accomplish tasks by using tools step by step.
2
+
3
+ ## How to Work
4
+ 1. Read the conversation history first — short user messages like an email or "yes" are answers to your previous questions
5
+ 2. Break complex tasks into clear steps and execute them one at a time
6
+ 3. After each tool call, examine the result carefully before deciding the next action
7
+ 4. Never repeat the same tool call if it already succeeded — move to the next step
8
+ 5. If a tool returns an error, try a different approach or different parameters
9
+ 6. When you read important information (API docs, instructions, credentials), save it to workspace or memory immediately
10
+ 7. When you have enough information to respond, do so directly — don't keep searching
11
+ 8. If you cannot complete a task (missing credentials, access denied), explain exactly what you need and stop
12
+ 9. Your responses are for the user only — never include tool calls, function names, system commands, JSON, or any technical execution details in your response text. Execute tools silently via function calling, then respond with the human-readable result.
13
+ 10. Complete all tool calls before responding. If you need to save data, fetch a URL, or perform any action — do it as a tool call first, then respond after the results are in.
14
+ 11. ALWAYS include a response when you are done. Never complete a task silently — the user is waiting for confirmation of what you did.
15
+
16
+ ## Data Management
17
+ - **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.
18
+ - **Memory** (memory_write/read): General knowledge, non-sensitive facts, preferences, summaries
19
+ - **Workspace** (workspace_write/read): Files, documents, downloaded content, API docs, drafts
20
+ - **Session history**: Recent conversation — automatically available, review it before each response
21
+
22
+ ## Recurring Tasks
23
+ When the user asks you to do something regularly, repeatedly, or on a schedule:
24
+ - **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.
25
+ - **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.
26
+ - Use ONE or the OTHER — never both for the same task. If you use schedule_task, do NOT also add it to HEARTBEAT.md.
27
+ - Do NOT just save recurring task requests to memory — that won't make them happen.
28
+
29
+ ## Safety
30
+ - Never attempt to bypass access controls or escalate permissions
31
+ - Always ask for confirmation before performing destructive or irreversible actions
32
+ - Store credentials and personal identifiers ONLY in the vault — never in memory or workspace
package/README.md CHANGED
@@ -35,6 +35,12 @@ npm install @openvole/paw-ollama
35
35
 
36
36
  Implements the Think phase — receives the conversation context and registered tools, returns the next assistant message and any tool calls. Uses a locally running Ollama instance.
37
37
 
38
+ ## BRAIN.md
39
+
40
+ The system prompt is loaded from `.openvole/paws/paw-ollama/BRAIN.md`. On first startup, the paw scaffolds a default prompt there. Edit this file to customize how the Brain reasons and responds.
41
+
42
+ The old `.openvole/BRAIN.md` path is no longer used.
43
+
38
44
  ## License
39
45
 
40
46
  [MIT](https://github.com/openvole/pawhub/blob/main/LICENSE)
package/dist/index.js CHANGED
@@ -27,37 +27,7 @@ var OllamaClient = class {
27
27
  - Time: ${now.toLocaleTimeString("en-US", { hour12: true })}
28
28
  - Platform: ${process.platform}
29
29
  - Model: ${this.model}`;
30
- const basePrompt = customBrainPrompt2 ?? `You are an AI agent powered by OpenVole. You accomplish tasks by using tools step by step.
31
-
32
- ## How to Work
33
- 1. Read the conversation history first \u2014 short user messages like an email or "yes" are answers to your previous questions
34
- 2. Break complex tasks into clear steps and execute them one at a time
35
- 3. After each tool call, examine the result carefully before deciding the next action
36
- 4. Never repeat the same tool call if it already succeeded \u2014 move to the next step
37
- 5. If a tool returns an error, try a different approach or different parameters
38
- 6. When you read important information (API docs, instructions, credentials), save it to workspace or memory immediately
39
- 7. When you have enough information to respond, do so directly \u2014 don't keep searching
40
- 8. If you cannot complete a task (missing credentials, access denied), explain exactly what you need and stop
41
- 9. Your responses are for the user only \u2014 never include tool calls, function names, system commands, JSON, or any technical execution details in your response text. Execute tools silently via function calling, then respond with the human-readable result.
42
- 10. Complete all tool calls before responding. If you need to save data, fetch a URL, or perform any action \u2014 do it as a tool call first, then respond after the results are in.
43
-
44
- ## Data Management
45
- - **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.
46
- - **Memory** (memory_write/read): General knowledge, non-sensitive facts, preferences, summaries
47
- - **Workspace** (workspace_write/read): Files, documents, downloaded content, API docs, drafts
48
- - **Session history**: Recent conversation \u2014 automatically available, review it before each response
49
-
50
- ## Recurring Tasks
51
- When the user asks you to do something regularly, repeatedly, or on a schedule:
52
- - **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.
53
- - **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.
54
- - 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.
55
- - Do NOT just save recurring task requests to memory \u2014 that won't make them happen.
56
-
57
- ## Safety
58
- - Never attempt to bypass access controls or escalate permissions
59
- - Always ask for confirmation before performing destructive or irreversible actions
60
- - Store credentials and personal identifiers ONLY in the vault \u2014 never in memory or workspace`;
30
+ const basePrompt = customBrainPrompt2 ?? "You are an AI agent powered by OpenVole. You accomplish tasks by using tools step by step.";
61
31
  const parts = [basePrompt, "", runtimeContext];
62
32
  if (identityContext2) {
63
33
  parts.push("");
@@ -176,13 +146,23 @@ var client;
176
146
  var identityContext;
177
147
  var customBrainPrompt;
178
148
  async function loadBrainPrompt() {
149
+ const brainPath = path.resolve(process.cwd(), ".openvole", "paws", "paw-ollama", "BRAIN.md");
179
150
  try {
180
- const content = await fs.readFile(
181
- path.resolve(process.cwd(), ".openvole", "BRAIN.md"),
182
- "utf-8"
183
- );
151
+ await fs.access(brainPath);
152
+ } catch {
153
+ try {
154
+ const pkgPath = path.resolve(path.dirname(new URL(import.meta.url).pathname), "..", "BRAIN.md");
155
+ const defaultContent = await fs.readFile(pkgPath, "utf-8");
156
+ await fs.mkdir(path.dirname(brainPath), { recursive: true });
157
+ await fs.writeFile(brainPath, defaultContent, "utf-8");
158
+ console.log("[paw-ollama] scaffolded BRAIN.md to .openvole/paws/paw-ollama/");
159
+ } catch (err) {
160
+ console.error("[paw-ollama] failed to scaffold BRAIN.md:", err);
161
+ }
162
+ }
163
+ try {
164
+ const content = await fs.readFile(brainPath, "utf-8");
184
165
  if (content.trim()) {
185
- console.log("[paw-ollama] loaded custom BRAIN.md prompt");
186
166
  return content.trim();
187
167
  }
188
168
  } catch {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/paw.ts","../src/ollama.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 type { PawDefinition, AgentContext, AgentPlan } from '@openvole/paw-sdk'\nimport { OllamaClient } from './ollama.js'\n\nlet client: OllamaClient | undefined\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-ollama] 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(): OllamaClient {\n\tif (!client) {\n\t\tconst host = process.env.OLLAMA_HOST || 'http://localhost:11434'\n\t\tconst model = process.env.OLLAMA_MODEL || 'qwen3:latest'\n\t\tclient = new OllamaClient(host, model)\n\t}\n\treturn client\n}\n\nexport const paw: PawDefinition = {\n\tname: '@openvole/paw-ollama',\n\tversion: '0.1.0',\n\tdescription: 'Brain Paw powered by Ollama for local LLM inference',\n\tbrain: true,\n\n\tasync think(context: AgentContext): Promise<AgentPlan> {\n\t\tconst ollamaClient = getClient()\n\t\tconst start = Date.now()\n\n\t\ttry {\n\t\t\tconst systemPrompt = ollamaClient.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 response = await ollamaClient.chat(\n\t\t\t\tsystemPrompt,\n\t\t\t\tcontext.messages,\n\t\t\t\tcontext.availableTools,\n\t\t\t)\n\n\t\t\tconst durationMs = Date.now() - start\n\t\t\tconsole.log(\n\t\t\t\t`[paw-ollama] think completed in ${durationMs}ms (model: ${ollamaClient.getModel()})`,\n\t\t\t)\n\n\t\t\tconst actions = ollamaClient.parseToolCalls(response)\n\n\t\t\tconsole.log(\n\t\t\t\t`[paw-ollama] response — role: ${response.message.role}, content: ${(response.message.content || '').substring(0, 100)}, tool_calls: ${response.message.tool_calls?.length ?? 0}, actions: ${actions.length}`,\n\t\t\t)\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 = response.message.content || ''\n\n\t\t\t// If the model produced a text response, return it as done\n\t\t\treturn {\n\t\t\t\tactions: [],\n\t\t\t\tresponse: text,\n\t\t\t\tdone: true,\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\tconst stack =\n\t\t\t\terror instanceof Error ? error.stack : undefined\n\t\t\tconsole.error(\n\t\t\t\t`[paw-ollama] think failed after ${durationMs}ms: ${message}`,\n\t\t\t)\n\t\t\tif (stack) console.error(`[paw-ollama] stack: ${stack}`)\n\t\t\t// Log request details for debugging\n\t\t\tconsole.error(\n\t\t\t\t`[paw-ollama] model: ${ollamaClient.getModel()}, host: ${process.env.OLLAMA_HOST || 'http://localhost:11434'}, messages: ${context.messages.length}, tools: ${context.availableTools.length}`,\n\t\t\t)\n\n\t\t\t// Check for connection errors (Ollama not running)\n\t\t\tconst isConnectionError =\n\t\t\t\tmessage.includes('ECONNREFUSED') ||\n\t\t\t\tmessage.includes('fetch failed') ||\n\t\t\t\tmessage.includes('ENOTFOUND')\n\n\t\t\treturn {\n\t\t\t\tactions: [],\n\t\t\t\tresponse: isConnectionError\n\t\t\t\t\t? 'Ollama is not running or unreachable. Please start Ollama and try again.'\n\t\t\t\t\t: `Error communicating with Ollama: ${message}`,\n\t\t\t\tdone: true,\n\t\t\t}\n\t\t}\n\t},\n\n\tasync onLoad() {\n\t\tconst ollamaClient = getClient()\n\t\tcustomBrainPrompt = await loadBrainPrompt()\n\t\tidentityContext = await loadIdentityFiles()\n\t\tif (identityContext) {\n\t\t\tconsole.log('[paw-ollama] loaded identity files (SOUL.md, USER.md, AGENT.md)')\n\t\t}\n\t\tconsole.log(\n\t\t\t`[paw-ollama] loaded — model: ${ollamaClient.getModel()}, host: ${process.env.OLLAMA_HOST || 'http://localhost:11434'}`,\n\t\t)\n\t},\n\n\tasync onUnload() {\n\t\tclient = undefined\n\t\tconsole.log('[paw-ollama] unloaded')\n\t},\n}\n","import { Ollama, type ChatResponse, type Message, type Tool } from 'ollama'\nimport type {\n\tAgentMessage,\n\tActiveSkill,\n\tPlannedAction,\n\tToolSummary,\n} from '@openvole/paw-sdk'\n\nexport class OllamaClient {\n\tprivate client: Ollama\n\tprivate model: string\n\n\tconstructor(\n\t\thost: string = 'http://localhost:11434',\n\t\tmodel: string = 'qwen3:latest',\n\t) {\n\t\tthis.client = new Ollama({ host })\n\t\tthis.model = model\n\t}\n\n\tgetModel(): string {\n\t\treturn this.model\n\t}\n\n\t/**\n\t * Build the system prompt from active skills and available tools.\n\t */\n\tbuildSystemPrompt(\n\t\tactiveSkills: ActiveSkill[],\n\t\tavailableTools: ToolSummary[],\n\t\tmetadata?: Record<string, unknown>,\n\t\tidentityContext?: string,\n\t\tcustomBrainPrompt?: string,\n\t): string {\n\t\tconst now = new Date()\n\t\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: ${this.model}`\n\n\t\t// Use custom BRAIN.md if provided, otherwise use default prompt\n\t\tconst basePrompt = customBrainPrompt ?? `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\n9. Your responses are for the user only — never include tool calls, function names, system commands, JSON, or any technical execution details in your response text. Execute tools silently via function calling, then respond with the human-readable result.\n10. Complete all tool calls before responding. If you need to save data, fetch a URL, or perform any action — do it as a tool call first, then respond after the results are in.\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\t\tconst parts: string[] = [basePrompt, '', runtimeContext]\n\n\t\t// Inject identity context (SOUL.md, USER.md, AGENT.md) if available\n\t\tif (identityContext) {\n\t\t\tparts.push('')\n\t\t\tparts.push(identityContext)\n\t\t}\n\n\t\t// Inject session history if available — this is critical for conversation continuity\n\t\tif (metadata?.sessionHistory && typeof metadata.sessionHistory === 'string') {\n\t\t\tparts.push('')\n\t\t\tparts.push('## Conversation History')\n\t\t\tparts.push('Previous messages in this session. Use this to understand the current context and follow-up messages:')\n\t\t\tparts.push(metadata.sessionHistory)\n\t\t}\n\n\t\t// Inject memory if available\n\t\tif (metadata?.memory && typeof metadata.memory === 'string') {\n\t\t\tparts.push('')\n\t\t\tparts.push('## Agent Memory')\n\t\t\tparts.push(metadata.memory)\n\t\t}\n\n\t\tif (activeSkills.length > 0) {\n\t\t\tparts.push('')\n\t\t\tparts.push('## Available Skills')\n\t\t\tparts.push(\n\t\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\t)\n\t\t\tfor (const skill of activeSkills) {\n\t\t\t\tparts.push(`- **${skill.name}**: ${skill.description}`)\n\t\t\t}\n\t\t}\n\n\t\tif (availableTools.length > 0) {\n\t\t\tparts.push('')\n\t\t\tparts.push('## Available Tools')\n\t\t\tparts.push(\n\t\t\t\t'You have access to the following tools. Use function calling to invoke them when needed.',\n\t\t\t)\n\t\t\tfor (const tool of availableTools) {\n\t\t\t\tparts.push(`- **${tool.name}** (from ${tool.pawName}): ${tool.description}`)\n\t\t\t}\n\t\t}\n\n\t\treturn parts.join('\\n')\n\t}\n\n\t/**\n\t * Convert AgentMessage[] to Ollama Message[].\n\t */\n\tconvertMessages(\n\t\tsystemPrompt: string,\n\t\tmessages: AgentMessage[],\n\t): Message[] {\n\t\tconst result: Message[] = [{ role: 'system', content: systemPrompt }]\n\n\t\tfor (const msg of messages) {\n\t\t\tswitch (msg.role) {\n\t\t\t\tcase 'user':\n\t\t\t\t\tresult.push({ role: 'user', content: msg.content })\n\t\t\t\t\tbreak\n\t\t\t\tcase 'brain':\n\t\t\t\t\tresult.push({ role: 'assistant', content: msg.content })\n\t\t\t\t\tbreak\n\t\t\t\tcase 'tool_result':\n\t\t\t\t\tresult.push({ role: 'tool', content: msg.content })\n\t\t\t\t\tbreak\n\t\t\t\tcase 'error':\n\t\t\t\t\tresult.push({\n\t\t\t\t\t\trole: 'tool',\n\t\t\t\t\t\tcontent: `Error: ${msg.content}`,\n\t\t\t\t\t})\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\treturn result\n\t}\n\n\t/**\n\t * Convert ToolSummary[] to Ollama Tool[] for function calling.\n\t */\n\tconvertTools(tools: ToolSummary[]): Tool[] {\n\t\treturn tools.map((tool) => {\n\t\t\t// Parameters are pre-converted to JSON Schema by the core\n\t\t\tconst params = (tool as { parameters?: Record<string, unknown> }).parameters\n\n\t\t\treturn {\n\t\t\t\ttype: 'function',\n\t\t\t\tfunction: {\n\t\t\t\t\tname: tool.name,\n\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\tparameters: params ?? {\n\t\t\t\t\t\ttype: 'object',\n\t\t\t\t\t\tproperties: {},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Send a chat request to Ollama and return the raw response.\n\t */\n\tasync chat(\n\t\tsystemPrompt: string,\n\t\tmessages: AgentMessage[],\n\t\ttools: ToolSummary[],\n\t): Promise<ChatResponse> {\n\t\tconst ollamaMessages = this.convertMessages(systemPrompt, messages)\n\t\tconst ollamaTools = this.convertTools(tools)\n\n\t\tconsole.log(\n\t\t\t`[paw-ollama] chat request — model: ${this.model}, messages: ${ollamaMessages.length}, tools: ${ollamaTools.length}`,\n\t\t)\n\t\treturn this.client.chat({\n\t\t\tmodel: this.model,\n\t\t\tmessages: ollamaMessages,\n\t\t\ttools: ollamaTools.length > 0 ? ollamaTools : undefined,\n\t\t\tstream: false,\n\t\t})\n\t}\n\n\t/**\n\t * Extract PlannedAction[] from Ollama tool_calls.\n\t */\n\tparseToolCalls(response: ChatResponse): PlannedAction[] {\n\t\tif (!response.message.tool_calls || response.message.tool_calls.length === 0) {\n\t\t\treturn []\n\t\t}\n\n\t\treturn response.message.tool_calls.map((call) => ({\n\t\t\ttool: call.function.name,\n\t\t\tparams: call.function.arguments,\n\t\t}))\n\t}\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;;;ACA1B,YAAY,QAAQ;AACpB,YAAY,UAAU;;;ACDtB,SAAS,cAA0D;AAQ5D,IAAM,eAAN,MAAmB;AAAA,EACjB;AAAA,EACA;AAAA,EAER,YACC,OAAe,0BACf,QAAgB,gBACf;AACD,SAAK,SAAS,IAAI,OA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;;;AD9JA,IAAO,gBAAQ,UAAU,GAAG;","names":["identityContext","customBrainPrompt"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/paw.ts","../src/ollama.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 type { PawDefinition, AgentContext, AgentPlan } from '@openvole/paw-sdk'\nimport { OllamaClient } from './ollama.js'\n\nlet client: OllamaClient | undefined\n\n/** Cached identity files — loaded once on startup */\nlet identityContext: string | undefined\n\n/** Brain prompt — loaded from user's local dir or packaged default */\nlet customBrainPrompt: string | undefined\n\n/** Load BRAIN.md from .openvole/paws/paw-ollama/BRAIN.md — scaffolds from packaged default on first run */\nasync function loadBrainPrompt(): Promise<string | undefined> {\n\tconst brainPath = path.resolve(process.cwd(), '.openvole', 'paws', 'paw-ollama', 'BRAIN.md')\n\n\t// Scaffold on first run: copy packaged BRAIN.md to local paw data dir\n\ttry {\n\t\tawait fs.access(brainPath)\n\t} catch {\n\t\ttry {\n\t\t\tconst pkgPath = path.resolve(path.dirname(new URL(import.meta.url).pathname), '..', 'BRAIN.md')\n\t\t\tconst defaultContent = await fs.readFile(pkgPath, 'utf-8')\n\t\t\tawait fs.mkdir(path.dirname(brainPath), { recursive: true })\n\t\t\tawait fs.writeFile(brainPath, defaultContent, 'utf-8')\n\t\t\tconsole.log('[paw-ollama] scaffolded BRAIN.md to .openvole/paws/paw-ollama/')\n\t\t} catch (err) {\n\t\t\tconsole.error('[paw-ollama] failed to scaffold BRAIN.md:', err)\n\t\t}\n\t}\n\n\t// Always read from the local paw data dir\n\ttry {\n\t\tconst content = await fs.readFile(brainPath, 'utf-8')\n\t\tif (content.trim()) {\n\t\t\treturn content.trim()\n\t\t}\n\t} catch {\n\t\t// No BRAIN.md\n\t}\n\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(): OllamaClient {\n\tif (!client) {\n\t\tconst host = process.env.OLLAMA_HOST || 'http://localhost:11434'\n\t\tconst model = process.env.OLLAMA_MODEL || 'qwen3:latest'\n\t\tclient = new OllamaClient(host, model)\n\t}\n\treturn client\n}\n\nexport const paw: PawDefinition = {\n\tname: '@openvole/paw-ollama',\n\tversion: '0.1.0',\n\tdescription: 'Brain Paw powered by Ollama for local LLM inference',\n\tbrain: true,\n\n\tasync think(context: AgentContext): Promise<AgentPlan> {\n\t\tconst ollamaClient = getClient()\n\t\tconst start = Date.now()\n\n\t\ttry {\n\t\t\tconst systemPrompt = ollamaClient.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 response = await ollamaClient.chat(\n\t\t\t\tsystemPrompt,\n\t\t\t\tcontext.messages,\n\t\t\t\tcontext.availableTools,\n\t\t\t)\n\n\t\t\tconst durationMs = Date.now() - start\n\t\t\tconsole.log(\n\t\t\t\t`[paw-ollama] think completed in ${durationMs}ms (model: ${ollamaClient.getModel()})`,\n\t\t\t)\n\n\t\t\tconst actions = ollamaClient.parseToolCalls(response)\n\n\t\t\tconsole.log(\n\t\t\t\t`[paw-ollama] response — role: ${response.message.role}, content: ${(response.message.content || '').substring(0, 100)}, tool_calls: ${response.message.tool_calls?.length ?? 0}, actions: ${actions.length}`,\n\t\t\t)\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 = response.message.content || ''\n\n\t\t\t// If the model produced a text response, return it as done\n\t\t\treturn {\n\t\t\t\tactions: [],\n\t\t\t\tresponse: text,\n\t\t\t\tdone: true,\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\tconst stack =\n\t\t\t\terror instanceof Error ? error.stack : undefined\n\t\t\tconsole.error(\n\t\t\t\t`[paw-ollama] think failed after ${durationMs}ms: ${message}`,\n\t\t\t)\n\t\t\tif (stack) console.error(`[paw-ollama] stack: ${stack}`)\n\t\t\t// Log request details for debugging\n\t\t\tconsole.error(\n\t\t\t\t`[paw-ollama] model: ${ollamaClient.getModel()}, host: ${process.env.OLLAMA_HOST || 'http://localhost:11434'}, messages: ${context.messages.length}, tools: ${context.availableTools.length}`,\n\t\t\t)\n\n\t\t\t// Check for connection errors (Ollama not running)\n\t\t\tconst isConnectionError =\n\t\t\t\tmessage.includes('ECONNREFUSED') ||\n\t\t\t\tmessage.includes('fetch failed') ||\n\t\t\t\tmessage.includes('ENOTFOUND')\n\n\t\t\treturn {\n\t\t\t\tactions: [],\n\t\t\t\tresponse: isConnectionError\n\t\t\t\t\t? 'Ollama is not running or unreachable. Please start Ollama and try again.'\n\t\t\t\t\t: `Error communicating with Ollama: ${message}`,\n\t\t\t\tdone: true,\n\t\t\t}\n\t\t}\n\t},\n\n\tasync onLoad() {\n\t\tconst ollamaClient = getClient()\n\t\tcustomBrainPrompt = await loadBrainPrompt()\n\t\tidentityContext = await loadIdentityFiles()\n\t\tif (identityContext) {\n\t\t\tconsole.log('[paw-ollama] loaded identity files (SOUL.md, USER.md, AGENT.md)')\n\t\t}\n\t\tconsole.log(\n\t\t\t`[paw-ollama] loaded — model: ${ollamaClient.getModel()}, host: ${process.env.OLLAMA_HOST || 'http://localhost:11434'}`,\n\t\t)\n\t},\n\n\tasync onUnload() {\n\t\tclient = undefined\n\t\tconsole.log('[paw-ollama] unloaded')\n\t},\n}\n","import { Ollama, type ChatResponse, type Message, type Tool } from 'ollama'\nimport type {\n\tAgentMessage,\n\tActiveSkill,\n\tPlannedAction,\n\tToolSummary,\n} from '@openvole/paw-sdk'\n\nexport class OllamaClient {\n\tprivate client: Ollama\n\tprivate model: string\n\n\tconstructor(\n\t\thost: string = 'http://localhost:11434',\n\t\tmodel: string = 'qwen3:latest',\n\t) {\n\t\tthis.client = new Ollama({ host })\n\t\tthis.model = model\n\t}\n\n\tgetModel(): string {\n\t\treturn this.model\n\t}\n\n\t/**\n\t * Build the system prompt from active skills and available tools.\n\t */\n\tbuildSystemPrompt(\n\t\tactiveSkills: ActiveSkill[],\n\t\tavailableTools: ToolSummary[],\n\t\tmetadata?: Record<string, unknown>,\n\t\tidentityContext?: string,\n\t\tcustomBrainPrompt?: string,\n\t): string {\n\t\tconst now = new Date()\n\t\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: ${this.model}`\n\n\t\t// Use BRAIN.md prompt (loaded from user's local dir or packaged default)\n\t\tconst basePrompt = customBrainPrompt ?? 'You are an AI agent powered by OpenVole. You accomplish tasks by using tools step by step.'\n\n\t\tconst parts: string[] = [basePrompt, '', runtimeContext]\n\n\t\t// Inject identity context (SOUL.md, USER.md, AGENT.md) if available\n\t\tif (identityContext) {\n\t\t\tparts.push('')\n\t\t\tparts.push(identityContext)\n\t\t}\n\n\t\t// Inject session history if available — this is critical for conversation continuity\n\t\tif (metadata?.sessionHistory && typeof metadata.sessionHistory === 'string') {\n\t\t\tparts.push('')\n\t\t\tparts.push('## Conversation History')\n\t\t\tparts.push('Previous messages in this session. Use this to understand the current context and follow-up messages:')\n\t\t\tparts.push(metadata.sessionHistory)\n\t\t}\n\n\t\t// Inject memory if available\n\t\tif (metadata?.memory && typeof metadata.memory === 'string') {\n\t\t\tparts.push('')\n\t\t\tparts.push('## Agent Memory')\n\t\t\tparts.push(metadata.memory)\n\t\t}\n\n\t\tif (activeSkills.length > 0) {\n\t\t\tparts.push('')\n\t\t\tparts.push('## Available Skills')\n\t\t\tparts.push(\n\t\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\t)\n\t\t\tfor (const skill of activeSkills) {\n\t\t\t\tparts.push(`- **${skill.name}**: ${skill.description}`)\n\t\t\t}\n\t\t}\n\n\t\tif (availableTools.length > 0) {\n\t\t\tparts.push('')\n\t\t\tparts.push('## Available Tools')\n\t\t\tparts.push(\n\t\t\t\t'You have access to the following tools. Use function calling to invoke them when needed.',\n\t\t\t)\n\t\t\tfor (const tool of availableTools) {\n\t\t\t\tparts.push(`- **${tool.name}** (from ${tool.pawName}): ${tool.description}`)\n\t\t\t}\n\t\t}\n\n\t\treturn parts.join('\\n')\n\t}\n\n\t/**\n\t * Convert AgentMessage[] to Ollama Message[].\n\t */\n\tconvertMessages(\n\t\tsystemPrompt: string,\n\t\tmessages: AgentMessage[],\n\t): Message[] {\n\t\tconst result: Message[] = [{ role: 'system', content: systemPrompt }]\n\n\t\tfor (const msg of messages) {\n\t\t\tswitch (msg.role) {\n\t\t\t\tcase 'user':\n\t\t\t\t\tresult.push({ role: 'user', content: msg.content })\n\t\t\t\t\tbreak\n\t\t\t\tcase 'brain':\n\t\t\t\t\tresult.push({ role: 'assistant', content: msg.content })\n\t\t\t\t\tbreak\n\t\t\t\tcase 'tool_result':\n\t\t\t\t\tresult.push({ role: 'tool', content: msg.content })\n\t\t\t\t\tbreak\n\t\t\t\tcase 'error':\n\t\t\t\t\tresult.push({\n\t\t\t\t\t\trole: 'tool',\n\t\t\t\t\t\tcontent: `Error: ${msg.content}`,\n\t\t\t\t\t})\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\treturn result\n\t}\n\n\t/**\n\t * Convert ToolSummary[] to Ollama Tool[] for function calling.\n\t */\n\tconvertTools(tools: ToolSummary[]): Tool[] {\n\t\treturn tools.map((tool) => {\n\t\t\t// Parameters are pre-converted to JSON Schema by the core\n\t\t\tconst params = (tool as { parameters?: Record<string, unknown> }).parameters\n\n\t\t\treturn {\n\t\t\t\ttype: 'function',\n\t\t\t\tfunction: {\n\t\t\t\t\tname: tool.name,\n\t\t\t\t\tdescription: tool.description,\n\t\t\t\t\tparameters: params ?? {\n\t\t\t\t\t\ttype: 'object',\n\t\t\t\t\t\tproperties: {},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Send a chat request to Ollama and return the raw response.\n\t */\n\tasync chat(\n\t\tsystemPrompt: string,\n\t\tmessages: AgentMessage[],\n\t\ttools: ToolSummary[],\n\t): Promise<ChatResponse> {\n\t\tconst ollamaMessages = this.convertMessages(systemPrompt, messages)\n\t\tconst ollamaTools = this.convertTools(tools)\n\n\t\tconsole.log(\n\t\t\t`[paw-ollama] chat request — model: ${this.model}, messages: ${ollamaMessages.length}, tools: ${ollamaTools.length}`,\n\t\t)\n\t\treturn this.client.chat({\n\t\t\tmodel: this.model,\n\t\t\tmessages: ollamaMessages,\n\t\t\ttools: ollamaTools.length > 0 ? ollamaTools : undefined,\n\t\t\tstream: false,\n\t\t})\n\t}\n\n\t/**\n\t * Extract PlannedAction[] from Ollama tool_calls.\n\t */\n\tparseToolCalls(response: ChatResponse): PlannedAction[] {\n\t\tif (!response.message.tool_calls || response.message.tool_calls.length === 0) {\n\t\t\treturn []\n\t\t}\n\n\t\treturn response.message.tool_calls.map((call) => ({\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WAAW;AAE7B,aAAO;AAAA,QACN,SAAS,CAAC;AAAA,QACV,UAAU,oBACP,6EACA,oCAAoC,OAAO;AAAA,QAC9C,MAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM,SAAS;AACd,UAAM,eAAe,UAAU;AAC/B,wBAAoB,MAAM,gBAAgB;AAC1C,sBAAkB,MAAM,kBAAkB;AAC1C,QAAI,iBAAiB;AACpB,cAAQ,IAAI,iEAAiE;AAAA,IAC9E;AACA,YAAQ;AAAA,MACP,qCAAgC,aAAa,SAAS,CAAC,WAAW,QAAQ,IAAI,eAAe,wBAAwB;AAAA,IACtH;AAAA,EACD;AAAA,EAEA,MAAM,WAAW;AAChB,aAAS;AACT,YAAQ,IAAI,uBAAuB;AAAA,EACpC;AACD;;;AD7KA,IAAO,gBAAQ,UAAU,GAAG;","names":["identityContext","customBrainPrompt"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openvole/paw-ollama",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Brain Paw powered by Ollama for local LLM inference",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -30,6 +30,7 @@
30
30
  "files": [
31
31
  "dist",
32
32
  "vole-paw.json",
33
+ "BRAIN.md",
33
34
  "README.md"
34
35
  ],
35
36
  "license": "MIT",