opencode-avatar 0.3.17 → 0.3.18

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 +15 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -12691,6 +12691,7 @@ var THINKING_PROMPT = "thinking hard";
12691
12691
  var AVATAR_PORT = 47291;
12692
12692
  var dbFile = null;
12693
12693
  var db = null;
12694
+ var sessionToAvatarMap = new Map;
12694
12695
  async function getDbFile(client) {
12695
12696
  if (!dbFile) {
12696
12697
  const result = await client.path.get();
@@ -12720,6 +12721,8 @@ async function getDatabase(client) {
12720
12721
  return db;
12721
12722
  }
12722
12723
  async function registerAvatarName(client, name, sessionId) {
12724
+ const normalizedName = name.toLowerCase();
12725
+ sessionToAvatarMap.set(sessionId, normalizedName);
12723
12726
  const database = await getDatabase(client);
12724
12727
  const stmt = database.prepare(`
12725
12728
  INSERT INTO latest_tool_usage (name, session_id, tool_name, timestamp)
@@ -12728,9 +12731,16 @@ async function registerAvatarName(client, name, sessionId) {
12728
12731
  tool_name = excluded.tool_name,
12729
12732
  timestamp = excluded.timestamp
12730
12733
  `);
12731
- stmt.run(name.toLowerCase(), sessionId, "registered", Date.now());
12734
+ stmt.run(normalizedName, normalizedName, "registered", Date.now());
12735
+ }
12736
+ function getRegisteredAvatarName(sessionId) {
12737
+ return sessionToAvatarMap.get(sessionId) || null;
12732
12738
  }
12733
12739
  async function updateToolUsage(client, name, sessionId, toolName) {
12740
+ const registeredName = getRegisteredAvatarName(sessionId);
12741
+ if (!registeredName) {
12742
+ return;
12743
+ }
12734
12744
  const database = await getDatabase(client);
12735
12745
  const stmt = database.prepare(`
12736
12746
  INSERT INTO latest_tool_usage (name, session_id, tool_name, timestamp)
@@ -12739,7 +12749,7 @@ async function updateToolUsage(client, name, sessionId, toolName) {
12739
12749
  tool_name = excluded.tool_name,
12740
12750
  timestamp = excluded.timestamp
12741
12751
  `);
12742
- stmt.run(name.toLowerCase(), sessionId, toolName, Date.now());
12752
+ stmt.run(registeredName, registeredName, toolName, Date.now());
12743
12753
  }
12744
12754
  function normalizeAgentName(name) {
12745
12755
  return name.toLowerCase().replace(/\s+/g, "_");
@@ -13058,8 +13068,7 @@ var AvatarPlugin = async ({ client }) => {
13058
13068
  idleTriggered = false;
13059
13069
  isThinking = true;
13060
13070
  const sessionId = input.sessionID || output.sessionID || currentAgentName || "unknown-session";
13061
- const trackingName = currentAgentName || sessionId;
13062
- updateToolUsage(client, trackingName, sessionId, "thinking").catch((err) => {
13071
+ updateToolUsage(client, sessionId, sessionId, "thinking").catch((err) => {
13063
13072
  console.error(`[Avatar] Failed to update thinking state:`, err);
13064
13073
  });
13065
13074
  requestAvatarGeneration(THINKING_PROMPT, false).catch(() => {
@@ -13070,8 +13079,7 @@ var AvatarPlugin = async ({ client }) => {
13070
13079
  "tool.execute.before": async (input) => {
13071
13080
  const toolName = input.tool;
13072
13081
  const sessionId = input.sessionID || input.sessionId || currentAgentName || "unknown-session";
13073
- const trackingName = currentAgentName || sessionId;
13074
- updateToolUsage(client, trackingName, sessionId, toolName).catch((err) => {
13082
+ updateToolUsage(client, sessionId, sessionId, toolName).catch((err) => {
13075
13083
  console.error(`[Avatar] Failed to update tool usage:`, err);
13076
13084
  });
13077
13085
  const toolDescription = getToolDescription(toolName);
@@ -13103,8 +13111,7 @@ var AvatarPlugin = async ({ client }) => {
13103
13111
  isToolActive = false;
13104
13112
  currentRequestId = null;
13105
13113
  const sessionId = event.sessionID || event.sessionId || currentAgentName || "unknown-session";
13106
- const trackingName = currentAgentName || sessionId;
13107
- updateToolUsage(client, trackingName, sessionId, "idle").catch((err) => {
13114
+ updateToolUsage(client, sessionId, sessionId, "idle").catch((err) => {
13108
13115
  console.error(`[Avatar] Failed to update idle state:`, err);
13109
13116
  });
13110
13117
  await setAvatarViaHttp(undefined, undefined, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-avatar",
3
- "version": "0.3.17",
3
+ "version": "0.3.18",
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",