opencode-avatar 0.3.17 → 0.3.19
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/dist/index.js +18 -11
- 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(
|
|
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(
|
|
12752
|
+
stmt.run(registeredName, registeredName, toolName, Date.now());
|
|
12743
12753
|
}
|
|
12744
12754
|
function normalizeAgentName(name) {
|
|
12745
12755
|
return name.toLowerCase().replace(/\s+/g, "_");
|
|
@@ -13057,9 +13067,8 @@ var AvatarPlugin = async ({ client }) => {
|
|
|
13057
13067
|
if (userMessage?.text && !isThinking) {
|
|
13058
13068
|
idleTriggered = false;
|
|
13059
13069
|
isThinking = true;
|
|
13060
|
-
const sessionId = input.sessionID ||
|
|
13061
|
-
|
|
13062
|
-
updateToolUsage(client, trackingName, sessionId, "thinking").catch((err) => {
|
|
13070
|
+
const sessionId = input.sessionID || currentAgentName || "unknown-session";
|
|
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(() => {
|
|
@@ -13069,9 +13078,8 @@ var AvatarPlugin = async ({ client }) => {
|
|
|
13069
13078
|
},
|
|
13070
13079
|
"tool.execute.before": async (input) => {
|
|
13071
13080
|
const toolName = input.tool;
|
|
13072
|
-
const sessionId = input.sessionID ||
|
|
13073
|
-
|
|
13074
|
-
updateToolUsage(client, trackingName, sessionId, toolName).catch((err) => {
|
|
13081
|
+
const sessionId = input.sessionID || currentAgentName || "unknown-session";
|
|
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);
|
|
@@ -13102,9 +13110,8 @@ var AvatarPlugin = async ({ client }) => {
|
|
|
13102
13110
|
isThinking = false;
|
|
13103
13111
|
isToolActive = false;
|
|
13104
13112
|
currentRequestId = null;
|
|
13105
|
-
const sessionId = event.
|
|
13106
|
-
|
|
13107
|
-
updateToolUsage(client, trackingName, sessionId, "idle").catch((err) => {
|
|
13113
|
+
const sessionId = event.properties?.sessionId || currentAgentName || "unknown-session";
|
|
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);
|