opencode-avatar 0.3.16 → 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.
- package/dist/index.js +27 -23
- 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, "_");
|
|
@@ -13042,16 +13052,23 @@ var AvatarPlugin = async ({ client }) => {
|
|
|
13042
13052
|
}
|
|
13043
13053
|
}
|
|
13044
13054
|
});
|
|
13045
|
-
|
|
13055
|
+
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
|
+
},
|
|
13046
13064
|
"chat.message": async (input, output) => {
|
|
13047
13065
|
const userMessage = output.parts.find((part) => part.type === "text" && part.messageID === input.messageID);
|
|
13048
13066
|
if (userMessage?.text) {}
|
|
13049
13067
|
if (userMessage?.text && !isThinking) {
|
|
13050
13068
|
idleTriggered = false;
|
|
13051
13069
|
isThinking = true;
|
|
13052
|
-
const sessionId = output.sessionID || currentAgentName || "unknown";
|
|
13053
|
-
|
|
13054
|
-
updateToolUsage(client, trackingName, sessionId, "thinking").catch((err) => {
|
|
13070
|
+
const sessionId = input.sessionID || output.sessionID || currentAgentName || "unknown-session";
|
|
13071
|
+
updateToolUsage(client, sessionId, sessionId, "thinking").catch((err) => {
|
|
13055
13072
|
console.error(`[Avatar] Failed to update thinking state:`, err);
|
|
13056
13073
|
});
|
|
13057
13074
|
requestAvatarGeneration(THINKING_PROMPT, false).catch(() => {
|
|
@@ -13061,9 +13078,8 @@ var AvatarPlugin = async ({ client }) => {
|
|
|
13061
13078
|
},
|
|
13062
13079
|
"tool.execute.before": async (input) => {
|
|
13063
13080
|
const toolName = input.tool;
|
|
13064
|
-
const sessionId = input.sessionID || currentAgentName || "unknown";
|
|
13065
|
-
|
|
13066
|
-
updateToolUsage(client, trackingName, sessionId, toolName).catch((err) => {
|
|
13081
|
+
const sessionId = input.sessionID || input.sessionId || currentAgentName || "unknown-session";
|
|
13082
|
+
updateToolUsage(client, sessionId, sessionId, toolName).catch((err) => {
|
|
13067
13083
|
console.error(`[Avatar] Failed to update tool usage:`, err);
|
|
13068
13084
|
});
|
|
13069
13085
|
const toolDescription = getToolDescription(toolName);
|
|
@@ -13094,9 +13110,8 @@ var AvatarPlugin = async ({ client }) => {
|
|
|
13094
13110
|
isThinking = false;
|
|
13095
13111
|
isToolActive = false;
|
|
13096
13112
|
currentRequestId = null;
|
|
13097
|
-
const sessionId = event.sessionID || currentAgentName || "unknown";
|
|
13098
|
-
|
|
13099
|
-
updateToolUsage(client, trackingName, sessionId, "idle").catch((err) => {
|
|
13113
|
+
const sessionId = event.sessionID || event.sessionId || currentAgentName || "unknown-session";
|
|
13114
|
+
updateToolUsage(client, sessionId, sessionId, "idle").catch((err) => {
|
|
13100
13115
|
console.error(`[Avatar] Failed to update idle state:`, err);
|
|
13101
13116
|
});
|
|
13102
13117
|
await setAvatarViaHttp(undefined, undefined, true);
|
|
@@ -13104,17 +13119,6 @@ var AvatarPlugin = async ({ client }) => {
|
|
|
13104
13119
|
},
|
|
13105
13120
|
"session.end": async (_input) => {}
|
|
13106
13121
|
};
|
|
13107
|
-
return {
|
|
13108
|
-
tool: {
|
|
13109
|
-
register_avatar_name: registerAvatarNameTool
|
|
13110
|
-
},
|
|
13111
|
-
config: async (input) => {
|
|
13112
|
-
input.experimental ??= {};
|
|
13113
|
-
input.experimental.primary_tools ??= [];
|
|
13114
|
-
input.experimental.primary_tools.push("register_avatar_name");
|
|
13115
|
-
},
|
|
13116
|
-
hooks
|
|
13117
|
-
};
|
|
13118
13122
|
};
|
|
13119
13123
|
export {
|
|
13120
13124
|
AvatarPlugin
|