opencode-avatar 0.3.19 → 0.3.21

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.
Files changed (2) hide show
  1. package/dist/index.js +0 -99
  2. package/package.json +1 -3
package/dist/index.js CHANGED
@@ -12682,75 +12682,12 @@ import * as path from "path";
12682
12682
  import * as http from "http";
12683
12683
  import * as fs from "fs";
12684
12684
  import * as os from "os";
12685
- import { Database } from "bun:sqlite";
12686
12685
  var __dirname = "/var/home/wizard/opencode-avatar";
12687
12686
  var PLUGIN_DIR = __dirname;
12688
12687
  var AVATAR_DIR = path.join(os.homedir(), ".config", "opencode");
12689
12688
  var DEFAULT_AVATAR = "avatar.png";
12690
12689
  var THINKING_PROMPT = "thinking hard";
12691
12690
  var AVATAR_PORT = 47291;
12692
- var dbFile = null;
12693
- var db = null;
12694
- var sessionToAvatarMap = new Map;
12695
- async function getDbFile(client) {
12696
- if (!dbFile) {
12697
- const result = await client.path.get();
12698
- dbFile = path.join(result.data.config, "avatar.db");
12699
- }
12700
- return dbFile;
12701
- }
12702
- async function getDatabase(client) {
12703
- if (!db) {
12704
- const file2 = await getDbFile(client);
12705
- db = new Database(file2);
12706
- db.run("PRAGMA journal_mode = WAL");
12707
- db.exec(`
12708
- CREATE TABLE IF NOT EXISTS latest_tool_usage (
12709
- id INTEGER PRIMARY KEY AUTOINCREMENT,
12710
- name TEXT NOT NULL,
12711
- session_id TEXT NOT NULL,
12712
- tool_name TEXT NOT NULL,
12713
- timestamp INTEGER NOT NULL,
12714
- UNIQUE(name, session_id)
12715
- )
12716
- `);
12717
- db.exec(`
12718
- CREATE INDEX IF NOT EXISTS idx_tool_usage_name_session ON latest_tool_usage(name, session_id)
12719
- `);
12720
- }
12721
- return db;
12722
- }
12723
- async function registerAvatarName(client, name, sessionId) {
12724
- const normalizedName = name.toLowerCase();
12725
- sessionToAvatarMap.set(sessionId, normalizedName);
12726
- const database = await getDatabase(client);
12727
- const stmt = database.prepare(`
12728
- INSERT INTO latest_tool_usage (name, session_id, tool_name, timestamp)
12729
- VALUES (?, ?, ?, ?)
12730
- ON CONFLICT(name, session_id) DO UPDATE SET
12731
- tool_name = excluded.tool_name,
12732
- timestamp = excluded.timestamp
12733
- `);
12734
- stmt.run(normalizedName, normalizedName, "registered", Date.now());
12735
- }
12736
- function getRegisteredAvatarName(sessionId) {
12737
- return sessionToAvatarMap.get(sessionId) || null;
12738
- }
12739
- async function updateToolUsage(client, name, sessionId, toolName) {
12740
- const registeredName = getRegisteredAvatarName(sessionId);
12741
- if (!registeredName) {
12742
- return;
12743
- }
12744
- const database = await getDatabase(client);
12745
- const stmt = database.prepare(`
12746
- INSERT INTO latest_tool_usage (name, session_id, tool_name, timestamp)
12747
- VALUES (?, ?, ?, ?)
12748
- ON CONFLICT(name, session_id) DO UPDATE SET
12749
- tool_name = excluded.tool_name,
12750
- timestamp = excluded.timestamp
12751
- `);
12752
- stmt.run(registeredName, registeredName, toolName, Date.now());
12753
- }
12754
12691
  function normalizeAgentName(name) {
12755
12692
  return name.toLowerCase().replace(/\s+/g, "_");
12756
12693
  }
@@ -13035,42 +12972,13 @@ var AvatarPlugin = async ({ client }) => {
13035
12972
  const message = error45 instanceof Error ? error45.message : "Unknown error";
13036
12973
  showErrorToast(`Failed to start avatar: ${message}`);
13037
12974
  }
13038
- const registerAvatarNameTool = tool3({
13039
- description: "Register a name for this avatar session. This associates a name with the current session ID for tracking purposes.",
13040
- args: {
13041
- name: z.string().describe("Name to register for this avatar session. This will be associated with the current session ID.")
13042
- },
13043
- async execute(args, toolCtx) {
13044
- const name = args.name.toLowerCase();
13045
- const sessionId = toolCtx.sessionID;
13046
- try {
13047
- await registerAvatarName(client, name, sessionId);
13048
- return `Avatar name "${args.name}" registered for session ${sessionId}`;
13049
- } catch (error45) {
13050
- console.error(`[Avatar] Failed to register name:`, error45);
13051
- throw error45;
13052
- }
13053
- }
13054
- });
13055
12975
  return {
13056
- tool: {
13057
- register_avatar_name: registerAvatarNameTool
13058
- },
13059
- config: async (input) => {
13060
- input.experimental ??= {};
13061
- input.experimental.primary_tools ??= [];
13062
- input.experimental.primary_tools.push("register_avatar_name");
13063
- },
13064
12976
  "chat.message": async (input, output) => {
13065
12977
  const userMessage = output.parts.find((part) => part.type === "text" && part.messageID === input.messageID);
13066
12978
  if (userMessage?.text) {}
13067
12979
  if (userMessage?.text && !isThinking) {
13068
12980
  idleTriggered = false;
13069
12981
  isThinking = true;
13070
- const sessionId = input.sessionID || currentAgentName || "unknown-session";
13071
- updateToolUsage(client, sessionId, sessionId, "thinking").catch((err) => {
13072
- console.error(`[Avatar] Failed to update thinking state:`, err);
13073
- });
13074
12982
  requestAvatarGeneration(THINKING_PROMPT, false).catch(() => {
13075
12983
  isThinking = false;
13076
12984
  });
@@ -13079,9 +12987,6 @@ var AvatarPlugin = async ({ client }) => {
13079
12987
  "tool.execute.before": async (input) => {
13080
12988
  const toolName = input.tool;
13081
12989
  const sessionId = input.sessionID || currentAgentName || "unknown-session";
13082
- updateToolUsage(client, sessionId, sessionId, toolName).catch((err) => {
13083
- console.error(`[Avatar] Failed to update tool usage:`, err);
13084
- });
13085
12990
  const toolDescription = getToolDescription(toolName);
13086
12991
  const prompt = getToolPrompt(toolName, toolDescription);
13087
12992
  idleTriggered = false;
@@ -13110,10 +13015,6 @@ var AvatarPlugin = async ({ client }) => {
13110
13015
  isThinking = false;
13111
13016
  isToolActive = false;
13112
13017
  currentRequestId = null;
13113
- const sessionId = event.properties?.sessionId || currentAgentName || "unknown-session";
13114
- updateToolUsage(client, sessionId, sessionId, "idle").catch((err) => {
13115
- console.error(`[Avatar] Failed to update idle state:`, err);
13116
- });
13117
13018
  await setAvatarViaHttp(undefined, undefined, true);
13118
13019
  }
13119
13020
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-avatar",
3
- "version": "0.3.19",
3
+ "version": "0.3.21",
4
4
  "description": "Dynamic desktop avatar plugin for OpenCode that reacts to your coding activities",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,7 +24,6 @@
24
24
  "prepublishOnly": "bun run build"
25
25
  },
26
26
  "devDependencies": {
27
- "@types/better-sqlite3": "^7.6.13",
28
27
  "@types/bun": "^1.2.2",
29
28
  "@types/node": "^25.0.10",
30
29
  "electron": "^28.0.0",
@@ -34,7 +33,6 @@
34
33
  "@opencode-ai/plugin": "^1.1.25"
35
34
  },
36
35
  "dependencies": {
37
- "better-sqlite3": "^12.6.2",
38
36
  "dotenv": "^17.2.3"
39
37
  },
40
38
  "keywords": [