@agentvault/muse-bridge 0.1.38 → 0.1.40

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.
@@ -50,12 +50,21 @@ export declare class MuseDriver {
50
50
  start(): Promise<string>;
51
51
  sessionId(): string | null;
52
52
  ownerSessionId(): string | null;
53
+ /**
54
+ * One turn on the lane's stored session. `freshSession` (#1560) runs it on a
55
+ * NEW session id instead, and only when that turn succeeds does the new id
56
+ * replace the lane's stored one (the first id ever replaced is kept in
57
+ * `<file>.prev`, never overwritten). A fresh turn that fails changes nothing.
58
+ */
53
59
  runTurn(prompt: string, opts?: {
54
60
  ownerTurn?: boolean;
61
+ freshSession?: boolean;
55
62
  }): Promise<{
56
63
  text: string;
57
64
  spoke: boolean;
58
65
  }>;
66
+ /** #1560: the lane's stored session is replaced by `id`, which just answered. */
67
+ private replaceSession;
59
68
  noteSaid(_text: string): void;
60
69
  stop(): Promise<void>;
61
70
  /** SIGTERM, then SIGKILL if still alive after 2s. Does not fulfill runTurn. */
@@ -3,6 +3,8 @@ export interface MuseProviderAdapter {
3
3
  close(): Promise<void>;
4
4
  /** #1467: the last error status Meta returned this turn; undefined if none. */
5
5
  upstreamStatus?(): number | undefined;
6
+ /** #1560: a request this turn could not reach Meta at all (no HTTP answer). */
7
+ transportFailed?(): boolean;
6
8
  }
7
9
  export declare function limitHeaderNote(headers: Headers): string;
8
10
  export interface MuseProviderAdapterOptions {
@@ -1,18 +1,34 @@
1
+ import { type ToolConversation, type TurnFailureCode } from "@agentvault/agentvault";
2
+ export interface PushOpts {
3
+ autoReplyOnText?: boolean;
4
+ replyExpected?: boolean;
5
+ ownerTurn?: boolean;
6
+ /** #1560: the chat this turn answers — names the failure report. */
7
+ conversation?: ToolConversation;
8
+ /** #1560: that chat's recent messages, used ONLY if the stored session is
9
+ * gone and this turn has to start a fresh one. The bridge decides what may
10
+ * seed which lane; the session never builds a seed itself. */
11
+ seed?: string;
12
+ }
1
13
  export interface RoomSession {
2
- push(text: string, reply?: (text: string) => Promise<void>, opts?: {
3
- autoReplyOnText?: boolean;
4
- replyExpected?: boolean;
5
- ownerTurn?: boolean;
6
- }): void;
14
+ push(text: string, reply?: (text: string) => Promise<void>, opts?: PushOpts): void;
7
15
  }
8
16
  export interface DriverLike {
9
17
  runTurn(prompt: string, opts?: {
10
18
  ownerTurn?: boolean;
19
+ freshSession?: boolean;
11
20
  }): Promise<{
12
21
  text: string;
13
22
  spoke: boolean;
14
23
  }>;
15
24
  }
25
+ /** #1560: what the failure report gets. A code, never the error's text. */
26
+ export interface TurnFailedReport {
27
+ code: TurnFailureCode;
28
+ exitCode?: number;
29
+ conversation: ToolConversation;
30
+ durationMs: number;
31
+ }
16
32
  /**
17
33
  * Serializes inbound messages onto MuseDriver.runTurn and routes the say back.
18
34
  *
@@ -20,8 +36,9 @@ export interface DriverLike {
20
36
  * cannot redirect a private 1:1 reply, because the newer message only becomes
21
37
  * current when its own turn starts.
22
38
  */
23
- /** #1467: what is safe to keep about a failed turn — never its message text. */
24
- export interface TurnFailure {
39
+ /** #1467: what is safe to keep about a failed turn — never its message text.
40
+ * (Not the plugin's `TurnFailure` class; that name is not shadowed here.) */
41
+ export interface TurnFailureInfo {
25
42
  /** The error status Meta's API returned this turn, when it returned one. */
26
43
  upstreamStatus?: number;
27
44
  /** The provider's error type, e.g. "invalid_request_error" — only a short
@@ -29,7 +46,9 @@ export interface TurnFailure {
29
46
  errorType?: string;
30
47
  }
31
48
  /** A failed turn → what to report, or null when the turn was stopped on purpose. */
32
- export declare function describeTurnFailure(err: unknown): TurnFailure | null;
49
+ export declare function describeTurnFailure(err: unknown): TurnFailureInfo | null;
50
+ /** #1560: the fixed line this bridge posted before — never seed material. */
51
+ export declare const LEGACY_FAILURE_NOTICE = "I couldn't complete this reply. Please try again.";
33
52
  export declare class MuseSession implements RoomSession {
34
53
  private readonly driver;
35
54
  private readonly opts;
@@ -37,23 +56,39 @@ export declare class MuseSession implements RoomSession {
37
56
  private running;
38
57
  private current;
39
58
  private saidThisTurn;
59
+ /** One failure notice per turn (re-review N1 split this from saidThisTurn). */
60
+ private noticedThisTurn;
40
61
  private drain;
41
62
  constructor(driver: DriverLike, opts?: {
42
63
  onSay?: (text: string) => Promise<void>;
43
64
  log?: (m: string) => void;
44
65
  identity?: string;
45
- /** #1467: a turn failed (not stopped). Fire-and-forget; a throw is swallowed. */
46
- onTurnFailed?: (failure: TurnFailure) => void;
66
+ /** #1560: the name the owner reads in a failure notice. */
67
+ agentName?: () => string | undefined;
68
+ /** #1467/#1560: a turn failed (not stopped). Fire-and-forget; a throw is swallowed. */
69
+ onTurnFailed?: (report: TurnFailedReport) => void;
47
70
  });
48
- push(text: string, reply?: (text: string) => Promise<void>, opts?: {
49
- autoReplyOnText?: boolean;
50
- replyExpected?: boolean;
51
- ownerTurn?: boolean;
52
- }): void;
71
+ push(text: string, reply?: (text: string) => Promise<void>, opts?: PushOpts): void;
53
72
  sayHandler(): (text: string) => void;
54
73
  idle(): Promise<void>;
55
74
  private log;
56
75
  private run;
76
+ private prompt;
77
+ /**
78
+ * #1560: one turn on the stored session. If Meta says that session can no
79
+ * longer be continued, ONE fresh session, seeded with this chat's recent
80
+ * messages, answers instead, and the driver keeps it. Once per turn: a
81
+ * fresh session that fails is a real failure for the caller to report. A
82
+ * model that already spoke this turn is never re-run (no double answer).
83
+ */
84
+ private runWithRecovery;
85
+ /**
86
+ * #1560: RECORD FIRST (the report and the log line), then the notice, so a
87
+ * notice that stalls or fails cannot lose the record. Only the code, the exit
88
+ * status and #1467's safe parts (Meta's status number, an error-type token)
89
+ * are logged; never the error's text.
90
+ */
91
+ private turnFailed;
57
92
  private failureNotice;
58
93
  /**
59
94
  * Room/DM fallback only when this turn authorised a reply AND the model
@@ -0,0 +1,39 @@
1
+ /**
2
+ * #1560 — why a Muse turn failed, as one code from the shared closed set
3
+ * (`TURN_FAILURE_CODES` in @agentvault/agentvault), and whether the stored
4
+ * Muse session itself is gone.
5
+ *
6
+ * The classifier reads only FACTS the driver attached to the error: Meta's
7
+ * HTTP status as seen by our own loopback adapter (a number), and two flags
8
+ * (`providerUnreachable`, `museToolUnsupported`). It never reads, keeps or
9
+ * returns provider text. A cause this bridge cannot detect stays
10
+ * `model_error`; nothing is guessed (403, for one, is not mapped: no Meta
11
+ * 403 has been observed).
12
+ *
13
+ * Every code is a literal `return "<code>"` so the plugin's code scan
14
+ * (`tool-error-codes.test.ts`) sees each one this file can emit.
15
+ */
16
+ import type { TurnFailureCode } from "@agentvault/agentvault";
17
+ /** The facts a failed turn's error may carry. Numbers and flags only. */
18
+ export interface MuseFailureFacts {
19
+ /** The last error status Meta answered this turn (adapter-observed). */
20
+ upstreamStatus?: number;
21
+ /** The muse child's exit status, when it exited with one. */
22
+ exitCode?: number;
23
+ /** Our adapter could not reach Meta at all (DNS, refused, reset). */
24
+ providerUnreachable?: boolean;
25
+ /** The muse binary is missing, not executable, or lacks `exec --json --session-id`. */
26
+ museToolUnsupported?: boolean;
27
+ }
28
+ /** Meta's status when it is a real HTTP error status, else undefined. */
29
+ export declare function upstreamStatusOf(err: unknown): number | undefined;
30
+ /** The child's exit status when it is an integer, else undefined. */
31
+ export declare function exitCodeOf(err: unknown): number | undefined;
32
+ export declare function classifyMuseFailure(err: unknown): TurnFailureCode;
33
+ /**
34
+ * The stored session cannot be continued: Meta refuses the encrypted
35
+ * reasoning it holds. Recorded on wowzer 64 times over 10 days on one session
36
+ * id. The text is tested here, in a local, and never kept.
37
+ */
38
+ export declare function isStaleSession(err: unknown): boolean;
39
+ //# sourceMappingURL=turn-failure.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentvault/muse-bridge",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "type": "module",
5
5
  "description": "AgentVault Muse Bridge — daemon bridging a Muse agent into E2E-encrypted AgentVault direct messages and rooms.",
6
6
  "main": "dist/index.js",