arisa 4.0.3 → 4.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arisa",
3
- "version": "4.0.3",
3
+ "version": "4.0.4",
4
4
  "description": "Telegram + Pi Agent modular assistant",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -23,6 +23,25 @@ function requiresProviderAuth(model) {
23
23
  return !isLocalBaseUrl(model?.baseUrl);
24
24
  }
25
25
 
26
+ async function promptAndThrowOnAssistantError(session, prompt) {
27
+ let assistantErrorMessage = "";
28
+ const unsubscribe = session.subscribe((event) => {
29
+ if (event.type === "message_end" && event.message?.stopReason === "error") {
30
+ assistantErrorMessage = event.message.errorMessage || "assistant message ended with error";
31
+ }
32
+ });
33
+
34
+ try {
35
+ await session.prompt(prompt);
36
+ } finally {
37
+ unsubscribe();
38
+ }
39
+
40
+ if (assistantErrorMessage) {
41
+ throw new Error(assistantErrorMessage);
42
+ }
43
+ }
44
+
26
45
  function mimeMatches(pattern, mimeType = "") {
27
46
  if (!pattern || !mimeType) return false;
28
47
  if (pattern === mimeType) return true;
@@ -72,6 +91,10 @@ export class AgentManager {
72
91
  this.pendingNewSessions.add(sessionKey);
73
92
  }
74
93
 
94
+ clearSessionCache(chatId) {
95
+ this.sessions.delete(String(chatId));
96
+ }
97
+
75
98
  createSessionManager(chatId) {
76
99
  const sessionKey = String(chatId);
77
100
  const sessionDir = getChatPiSessionsDir(sessionKey);
@@ -103,7 +126,7 @@ export class AgentManager {
103
126
  model,
104
127
  sessionManager: SessionManager.inMemory(),
105
128
  });
106
- await withTimeout(session.prompt("Reply with exactly: OK"), {
129
+ await withTimeout(promptAndThrowOnAssistantError(session, "Reply with exactly: OK"), {
107
130
  timeoutMs: piValidationTimeoutMs,
108
131
  label: "Pi validation prompt"
109
132
  });
@@ -532,6 +532,7 @@ export async function createTelegramBot({ config, artifactStore, toolRegistry, t
532
532
  await withTyping(ctx, async () => {
533
533
  try {
534
534
  await agentManager.validatePiAgent();
535
+ agentManager.clearSessionCache(ctx.chat.id);
535
536
  await ctx.reply(buildPiAuthTelegramMessage({ config, verified: true }));
536
537
  } catch (error) {
537
538
  const issue = getPiAuthIssue(error) || { kind: "validation-failed", message: getErrorMessage(error) };