@primusclaw/personal-agent 0.15.3 → 0.15.5

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.
@@ -48,8 +48,15 @@ export interface AssistantChatOptions {
48
48
  readonly enabled: boolean;
49
49
  /** ASSISTANT_USERS, lower case (empty: everybody the switch is on for). */
50
50
  readonly users: ReadonlySet<string>;
51
- /** PA_ASSISTANT_UNDERSTANDING_USERS, lower case (empty: nobody). */
51
+ /** PA_ASSISTANT_UNDERSTANDING on for everybody the assistant is on for (no names, or "*"); absent: the named people only. */
52
+ readonly understandingAll?: boolean;
53
+ /** PA_ASSISTANT_UNDERSTANDING_USERS, lower case (empty: nobody named). */
52
54
  readonly understanding: ReadonlySet<string>;
55
+ /**
56
+ * PUBLIC_BASE_URL: where the console page that gives a `/link` code is, for a person Claw holds no key of (absent: such a
57
+ * refusal is told as any other refusal of the message is).
58
+ */
59
+ readonly publicBaseUrl?: string;
53
60
  /** CLAW_PLUGIN_ID: named on each message; undefined for none. */
54
61
  readonly pluginId: number | undefined;
55
62
  /**
@@ -87,7 +94,11 @@ export declare class AssistantChat {
87
94
  * turn of the old kind is still running for them.
88
95
  */
89
96
  on(userId: string): boolean;
90
- /** Every 1:1 message of this person that is not an exact command goes to their assistant first. */
97
+ /**
98
+ * Every 1:1 message of this person that is not an exact command goes to their assistant first: they are named, or the switch is
99
+ * on for everybody, and the assistant is on for them. (Whether it can be reached now is `reachable`: the router reads that too,
100
+ * and a person it cannot reach is read the ordinary way.)
101
+ */
91
102
  understands(userId: string): boolean;
92
103
  /** The assistant can answer this person: their subscription has its events and their Claw user id is known. */
93
104
  reachable(userId: string): boolean;
@@ -106,7 +117,8 @@ export declare class AssistantChat {
106
117
  private langOf;
107
118
  /**
108
119
  * A message of a person the assistant understands, with the chat's context. True when the assistant has it; otherwise the
109
- * person was told it could not be reached and nothing else was done with it.
120
+ * person was told it could not be reached and nothing else was done with it. (The router reads a person the assistant cannot
121
+ * reach the ordinary way and does not come here: this is for one that stopped being reachable since.)
110
122
  */
111
123
  understand(request: {
112
124
  userId: string;
@@ -126,6 +138,7 @@ export declare class AssistantChat {
126
138
  route(request: {
127
139
  userId: string;
128
140
  credential: string;
141
+ modelKey?: string;
129
142
  prompt: string;
130
143
  conversation: Conversation;
131
144
  files: readonly InboundFile[];
@@ -160,6 +173,12 @@ export declare class AssistantChat {
160
173
  */
161
174
  private acknowledge;
162
175
  private attachedReader;
176
+ /**
177
+ * What a person is told when Claw refused their message: when it holds no API key of theirs to run it with (403
178
+ * `platform_key_required`, `claw-api/platform-key.ts`), which key and how to link one, since a retry cannot cure that and their
179
+ * linked key was not rejected (they have none); otherwise `otherwise`.
180
+ */
181
+ private refusedAs;
163
182
  /** The message did not reach the assistant: said in the receipt's place when one is open (it closes it), else as a message. */
164
183
  private notTaken;
165
184
  /**
@@ -115,7 +115,13 @@ export interface AssistantSettings {
115
115
  readonly users: ReadonlySet<string>;
116
116
  /** ASSISTANT_REPLY_WINDOW_SECONDS (default 1800). */
117
117
  readonly replyWindowSeconds: number;
118
- /** PA_ASSISTANT_UNDERSTANDING(_USERS): whose every message the assistant understands first (empty: nobody). */
118
+ /**
119
+ * PA_ASSISTANT_UNDERSTANDING with no names (or "*") while the assistant is on for everybody: the assistant understands the
120
+ * first message of every person it is on for. A flag, not a list: `understandingUsers` is empty then. `readSettings` always
121
+ * sets it; absent (a value built by hand) means false.
122
+ */
123
+ readonly understandingAll?: boolean;
124
+ /** PA_ASSISTANT_UNDERSTANDING(_USERS): the named people whose every message the assistant understands first (empty: nobody named). */
119
125
  readonly understandingUsers: ReadonlySet<string>;
120
126
  }
121
127
  /** How many in a window; `count` 0: no limit. */
@@ -0,0 +1,6 @@
1
+ export declare const keyNeededText: import("./catalog.js").Catalog<{
2
+ keyNeeded: (p: {
3
+ page: string;
4
+ channel: string;
5
+ }) => string;
6
+ }>;
@@ -27,6 +27,7 @@ export declare const linkText: import("./catalog.js").Catalog<{
27
27
  linkingPaused: string;
28
28
  badCode: string;
29
29
  identityRefused: string;
30
+ identityFallback: string;
30
31
  }>;
31
32
  /**
32
33
  * The console's page that gives a `/link` code for the channel `channel` (`SurfaceCaps.channel`), e.g.
@@ -0,0 +1,6 @@
1
+ export declare const modelKeyText: import("./catalog.js").Catalog<{
2
+ invalid: string;
3
+ missing: string;
4
+ leadInvalid: string;
5
+ leadMissing: string;
6
+ }>;
@@ -214,6 +214,8 @@ export declare const remoteText: import("./catalog.js").Catalog<{
214
214
  typedInTerminal: (p: {
215
215
  quoted: string;
216
216
  }) => string;
217
+ /** What a message that showed a prompt typed in the terminal is changed to when the terminal took the prompt back and the chat cannot delete it. */
218
+ typedTakenBack: string;
217
219
  shareConnect: string;
218
220
  shareWatch: string;
219
221
  shareNoteTyped: string;
@@ -6,7 +6,11 @@ import type { Lang } from "../locales/lang.js";
6
6
  * `fallbackLead`, and when there is no fallback or it fails too the person is told `guidance` instead of a raw error.
7
7
  */
8
8
  export interface ModelRefusal {
9
- /** Which refusal, in the policy's own words ("missing", "invalid", ...). */
9
+ /**
10
+ * Which refusal, in the policy's own words ("missing", "invalid", ...). `missing` and `invalid` are also what the engine
11
+ * asks `guidance` and `fallbackLead` for when Claw's failure code names the refusal (`model_key_missing`, `model_key_invalid`)
12
+ * and `classify` read nothing: a policy that has no wording for them returns "", and the person is told in the catalog's.
13
+ */
10
14
  readonly kind: string;
11
15
  }
12
16
  export interface ModelRefusalPolicy {
@@ -3,3 +3,5 @@ export * from "./reviews.js";
3
3
  export * from "./assistant-events.js";
4
4
  export * from "./notifications.js";
5
5
  export * from "./session-events.js";
6
+ export * from "./model-key.js";
7
+ export * from "./platform-key.js";
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The model gateway's refusal of the user's own key, and the codes a failed turn names it by.
3
+ *
4
+ * Claw calls a model with the user's key, and the gateway maps that key to the subscription key the user bound for the model's
5
+ * provider. When that subscription key is refused (revoked, expired, mistyped) or was never bound, the call fails with a 401 or a
6
+ * 403 whose body is the provider's and the router's sentences, and only the user can cure it. Brain classifies the failure
7
+ * (`classifyTaskFailure`) and ends the turn with one of two codes, so that what reads the end of a turn (the API's assistant, the
8
+ * personal agent) says what to do instead of showing the gateway's JSON.
9
+ *
10
+ * Two kinds:
11
+ * - `missing`: no subscription key is bound for the user: the gateway's 403 for a user with no binding at all, and the
12
+ * provider's 401 for a request that carried no subscription key;
13
+ * - `invalid`: a subscription key was bound and sent, and the provider refused it (401 "invalid subscription key").
14
+ *
15
+ * Nothing else is a refusal of the user's key: a 5xx, a 401 about the platform's own key (`invalid x-api-key`), and a 401 that
16
+ * wraps an upstream connection failure keep their handling.
17
+ */
18
+ /** The field of a failed turn's `ResultMessage` (and of its `exec_complete`) that names why the turn failed. */
19
+ export declare const TURN_FAILURE_REASON_FIELD = "failure_reason";
20
+ /** The failure code of a turn whose subscription key the gateway refused as invalid. */
21
+ export declare const MODEL_KEY_INVALID = "model_key_invalid";
22
+ /** The failure code of a turn the gateway refused because no subscription key is bound for the user. */
23
+ export declare const MODEL_KEY_MISSING = "model_key_missing";
24
+ export type ModelKeyRefusal = "missing" | "invalid";
25
+ /** Which refusal of the user's key a failed call's text is, or null for any other text. */
26
+ export declare function modelKeyRefusalOf(text: unknown): ModelKeyRefusal | null;
27
+ /** The failure code a refusal ends a turn with. */
28
+ export declare function modelKeyFailureCode(refusal: ModelKeyRefusal): string;
29
+ /** Which refusal a failure code names, or null for any other value. */
30
+ export declare function modelKeyRefusalOfCode(code: unknown): ModelKeyRefusal | null;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The `error` word of the 403 a turn is refused with when its caller was verified without a platform key
3
+ * (`POST /v1/sessions` with a first message, `POST /v1/sessions/:id/messages`).
4
+ *
5
+ * A service that speaks for a person with a delegated identity token has to bring the person's own API key beside it
6
+ * (`x-api-key`) wherever the identity service is the one that verifies callers: nothing else finds that key. Claw refuses the turn
7
+ * at the door in these words instead of starting a run that fails with the model gateway's "token not present", so the service
8
+ * can tell the person to link a key. The assistant routes refuse a keyless caller with the same word.
9
+ */
10
+ export declare const PLATFORM_KEY_REQUIRED = "platform_key_required";
@@ -1,3 +1,4 @@
1
+ import { TypedEchoes } from "./follow/echoes.js";
1
2
  import type { Follower } from "./follow/follower.js";
2
3
  import type { Task } from "./tasks.js";
3
4
  import type { TurnDisplay } from "./turns/display.js";
@@ -62,6 +63,8 @@ export declare class ChatRegistry {
62
63
  /** Whether the agent of the attached session can take over a conversation a terminal has open. */
63
64
  readonly agentTakeover: Map<string, boolean>;
64
65
  private readonly typed;
66
+ /** The messages that show what was typed at the terminal the chat shares, to take one away when the terminal takes its prompt back. */
67
+ private readonly echoes;
65
68
  private readonly readOnly;
66
69
  private readonly readOnlyKnown;
67
70
  private readonly terminalInput;
@@ -103,6 +106,8 @@ export declare class ChatRegistry {
103
106
  markTerminal(chatKey: string, sessionId: string, terminal: boolean): void;
104
107
  /** True the first time for a chat's session: the chat is to be told its terminal's registry row cannot be read. */
105
108
  firstRowHint(chatKey: string, sessionId: string): boolean;
109
+ /** The chat's record of the messages that show prompts typed at its terminal. */
110
+ echoesOf(chatKey: string): TypedEchoes;
106
111
  /** What is sent to the chat's session is typed into a terminal on the machine. */
107
112
  typesIntoTerminal(chatKey: string, sessionId: string | null): boolean;
108
113
  /**
@@ -67,6 +67,13 @@ export interface RemoteStep {
67
67
  readonly queuedHeld: boolean;
68
68
  /** What the person typed at the terminal of a conversation shared with the chat. */
69
69
  readonly typed: string | null;
70
+ /** The id that prompt has in the terminal's conversation (`messageId`), null when the connector does not say. */
71
+ readonly typedId: string | null;
72
+ /**
73
+ * The id of a prompt typed at the terminal that the terminal took back (`user_message_retracted`): Claude Code put it back into the
74
+ * box and the person sent another in its place, so the terminal no longer shows it.
75
+ */
76
+ readonly retracted: string | null;
70
77
  /** What is sent is typed into a terminal on the machine (`input: "terminal"`). */
71
78
  readonly terminal: boolean | null;
72
79
  /** That terminal's permission mode as its connector read it at the start. */
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The chat messages that show what was typed at the terminal the chat shares, by the id the prompt has in the terminal's
3
+ * conversation. A prompt typed there is shown in the chat as it is typed (one message for each block of text in it); when the
4
+ * terminal takes it back (the person pressed Esc before anything came of it and Claude Code put the text back into the box), the
5
+ * messages are taken away, so the chat shows what the terminal shows. A message that could not be taken away stays here, marked, for
6
+ * the next try. Kept in memory for the few prompts a person has under way: a worker that restarts has forgotten them, and what it
7
+ * showed before stays.
8
+ */
9
+ import type { MessageId } from "../../ports/surface.js";
10
+ /** How many prompts' messages are kept per chat. */
11
+ export declare const ECHOES_KEPT = 16;
12
+ export declare class TypedEchoes {
13
+ private readonly posted;
14
+ /** Prompts the terminal took back before any message of theirs was recorded (a post that landed late may still be). */
15
+ private readonly early;
16
+ /** `message` shows `prompt` (or one more block of it). */
17
+ remember(prompt: string, message: MessageId): void;
18
+ /** The messages that show `prompt`, oldest first; none when it was not shown (or was let go). */
19
+ of(prompt: string): readonly MessageId[];
20
+ /**
21
+ * The terminal took `prompt` back: false when it was not shown (nothing to take away now). One whose post is still in flight (it
22
+ * lands after the reader was cancelled) is remembered as taken back, so that its message goes as soon as it is recorded.
23
+ */
24
+ takeBack(prompt: string): boolean;
25
+ /** The prompts the terminal took back whose messages are still to be taken away, with the tries each has had since the first. */
26
+ pending(): ReadonlyMap<string, number>;
27
+ /** Another try at `prompt` is made: counted. */
28
+ tried(prompt: string): void;
29
+ /** `left` are the messages of `prompt` still to be taken away (a taking away that failed): none forgets the prompt. */
30
+ settle(prompt: string, left: readonly MessageId[]): void;
31
+ }
@@ -77,7 +77,7 @@ export declare class Follower {
77
77
  /** Fold one event in. False when the reader has nothing more to do. */
78
78
  private handle;
79
79
  private askOrResolve;
80
- /** What is said between two stretches of the agent's text: a prompt typed at the terminal, the connector coming back. */
80
+ /** What is said between two stretches of the agent's text: a prompt typed at the terminal (or taken back), the connector coming back. */
81
81
  private sayBetween;
82
82
  private advance;
83
83
  private flush;
@@ -0,0 +1,27 @@
1
+ import type { Lang } from "../../locales/lang.js";
2
+ import type { Clock } from "../../ports/clock.js";
3
+ import type { Logger } from "../../ports/logger.js";
4
+ import { type Conversation } from "../../ports/surface.js";
5
+ import type { TypedEchoes } from "./echoes.js";
6
+ /** How many times the messages of a prompt the terminal took back are tried at once, and how many later events try them once more. */
7
+ export declare const RETRACT_TRIES = 3;
8
+ export declare const RETRACT_DRAINS = 5;
9
+ /** What taking a message away needs. */
10
+ export interface RetractContext {
11
+ readonly clock: Clock;
12
+ readonly logger: Logger;
13
+ /** The wait before the second try (doubled for the third); `RETRACT_RETRY_MS` when not given. */
14
+ readonly retryMs?: number;
15
+ readonly lang: () => Lang;
16
+ /** Aborted when the reader is cancelled: what waits is given up (the message stays kept for whoever reads on). */
17
+ readonly cutOff?: AbortSignal;
18
+ }
19
+ /**
20
+ * `work`, or a rejection as soon as `signal` aborts (the work itself is left to settle on its own). Every wait of a reader's on the
21
+ * chat goes through it: a cancelled reader is never held by one that does not come back (Python's task cancel ends any await).
22
+ */
23
+ export declare function unlessCutOff<T>(work: Promise<T>, signal: AbortSignal | undefined): Promise<T>;
24
+ /** Take away what shows the prompt `prompt`, each message in up to `tries` tries; what stays is kept for the next try. */
25
+ export declare function takeAwayAll(echoes: TypedEchoes, prompt: string, to: Conversation, tries: number, cx: RetractContext): Promise<void>;
26
+ /** One more try at every prompt the terminal took back whose messages stay; a prompt that has had `RETRACT_DRAINS` of them is let go. */
27
+ export declare function drainTakenBack(echoes: TypedEchoes, to: Conversation, cx: RetractContext): Promise<void>;
@@ -8,6 +8,7 @@ import type { RemoteStateRepository } from "../../ports/store/remote.js";
8
8
  import { type Conversation } from "../../ports/surface.js";
9
9
  import { type RemoteStep } from "../events.js";
10
10
  import { type RemoteTurnState } from "../turn-state.js";
11
+ import type { TypedEchoes } from "./echoes.js";
11
12
  import { type FollowTimings } from "./timings.js";
12
13
  /** Whether a person may be woken now, and where what they may not be told yet is held (`proactive`). */
13
14
  export interface FollowReach {
@@ -28,6 +29,8 @@ export interface SpeakerDeps {
28
29
  readonly reach: FollowReach;
29
30
  readonly remoteState: RemoteStateRepository;
30
31
  readonly references: ConversationRefRepository;
32
+ /** The messages that show what was typed at the terminal (to take one away when the terminal takes its prompt back). */
33
+ readonly echoes: TypedEchoes;
31
34
  /** The conversation a stored reference posts to. */
32
35
  conversationFor(reference: JsonObject): Conversation;
33
36
  showPermission(chatKey: string, sessionId: string, request: Readonly<Record<string, unknown>>, to: Conversation): Promise<void>;
@@ -109,8 +112,22 @@ export declare class BurstSpeaker {
109
112
  settleWindow(): Promise<void>;
110
113
  /** A permission request gets its card at once, and none while the person may not be woken. */
111
114
  ask(request: Readonly<Record<string, unknown>>): Promise<void>;
112
- /** A prompt typed at the terminal the chat shares: one message, so the reply that follows reads as its answer. */
113
- typed(text: string): Promise<void>;
115
+ /**
116
+ * A prompt typed at the terminal the chat shares: one message, so the reply that follows reads as its answer. `id`: what the
117
+ * terminal's conversation calls the prompt; the message is kept under it so that `retract` can take it away.
118
+ */
119
+ typed(text: string, id?: string | null): Promise<void>;
120
+ /**
121
+ * The terminal took a prompt back (Claude Code put the text into its box again and the person sent another): the messages that
122
+ * showed it go, so the chat shows what the terminal shows. Each is deleted; when the chat cannot delete it, it is edited down to a
123
+ * line saying so; a refusal is tried again a few times at once. A message that stays (every try failed, the chat was out of reach)
124
+ * is tried again at each of the next events of the session, a few times (`drainRetractions`). Nothing when the prompt was not shown
125
+ * (the person could not be woken then, or the worker restarted since), and no one is woken by a message going.
126
+ */
127
+ retract(id: string): Promise<void>;
128
+ /** The messages of the prompts that could not be taken away yet are tried again, once each, until a few events went by. */
129
+ drainRetractions(): Promise<void>;
130
+ private retractContext;
114
131
  /** The connector restarted and this session is back: one line, never to wake anyone. */
115
132
  recovered(interrupted: boolean, continuing: boolean): Promise<void>;
116
133
  /**
@@ -121,4 +138,6 @@ export declare class BurstSpeaker {
121
138
  /** The chat to tell now, or null: nobody to tell, or (`unlessPaused`: also a pause) the person may not be woken. */
122
139
  private reachable;
123
140
  private tell;
141
+ /** `tell`, keeping the message's id under `prompt` so that it can be taken away later. */
142
+ private tellAs;
124
143
  }
@@ -14,6 +14,8 @@ export interface FollowTimings {
14
14
  readonly retryMs?: number;
15
15
  /** How long a stop waits for the reader to deliver what it read (`STOP_WAIT_MS` when not given). */
16
16
  readonly stopWaitMs?: number;
17
+ /** The wait before the second try of taking away the message of a prompt the terminal took back, doubled for the third (`RETRACT_RETRY_MS` when not given). */
18
+ readonly retractRetryMs?: number;
17
19
  }
18
20
  export declare const DEFAULT_TIMINGS: FollowTimings;
19
21
  /** How a watched conversation (open in a terminal, read-only) is followed: told after a few quiet seconds, not half a minute. */
@@ -21,6 +23,8 @@ export declare const WATCH_TIMINGS: FollowTimings;
21
23
  export declare const RECONNECT_MAX_MS = 60000;
22
24
  /** A message that could not be sent is tried again after this long. */
23
25
  export declare const RETRY_MS = 15000;
26
+ /** A message of a prompt the terminal took back that could not be taken away is tried again after this long. */
27
+ export declare const RETRACT_RETRY_MS = 2000;
24
28
  /** `stop` waits this long for the reader to finish what it was doing. */
25
29
  export declare const STOP_WAIT_MS = 15000;
26
30
  /** Events between two writes of the read position (a write also follows every delivery). */
@@ -35,6 +35,9 @@ export declare const TYPED_CHARS_MAX = 4000;
35
35
  * link, an image or a tag, nor an address the rich text links by itself (whoever types at that terminal reaches the chat through the
36
36
  * connector: what they typed is shown, never followed). */
37
37
  export declare function typedLine(text: string, lang: Lang): string;
38
+ /** What a message that showed a prompt typed at the terminal is edited down to when the terminal took the prompt back and the chat
39
+ * cannot delete the message. */
40
+ export declare function typedTakenBackLine(lang: Lang): string;
38
41
  /**
39
42
  * Teams' floating status (an informative update) is cut on a phone after a few characters. Microsoft documents only an upper
40
43
  * bound (1000 characters) and no display width; the one measurement is a phone, which showed four Chinese
@@ -69,6 +69,17 @@ export declare class TurnRunner {
69
69
  /** One stream, read until it ends or the turn does. */
70
70
  private readStream;
71
71
  private apply;
72
+ /** What the terminal's own doing says to the chat while this turn reads the session: a prompt it took back, a registry row it cannot read. */
73
+ private terminalNotes;
74
+ /**
75
+ * The terminal took back a prompt the chat showed (said while this turn reads the session, so the follower does not hear it): the
76
+ * message that shows it goes now, in one try; what stays is tried again by the follower, at its next events.
77
+ */
78
+ private takeBack;
79
+ /** One more try, at an event of the turn, at the messages of prompts the terminal took back that could not be taken away yet. */
80
+ private takeBackAgain;
81
+ /** What taking a message away needs here: the turn being cancelled gives up what waits (the message stays kept for the follower). */
82
+ private retractContext;
72
83
  /**
73
84
  * This turn's message waits for the turn the terminal is running: the person is told at once, in the chat, once per message, and
74
85
  * how to take it back (in the terminal when its own queue holds it; else /stop). A message queued behind a turn of this chat was
@@ -13,6 +13,13 @@ export declare class CredentialUnavailable extends Error {
13
13
  export declare const IDENTITY_CARD_INTERVAL_SECONDS: number;
14
14
  /** Its kind in the store's notice record (`claimGithubNotice`): the time it was last sent to the person. */
15
15
  export declare const IDENTITY_CARD_NOTICE = "identity_card";
16
+ /**
17
+ * The identity card beside a message the assistant could not take (`identityAfterFallback`) goes to a person once, and again
18
+ * only after this long if they still have not confirmed.
19
+ */
20
+ export declare const FALLBACK_CARD_INTERVAL_SECONDS: number;
21
+ /** Its kind in the same record. */
22
+ export declare const FALLBACK_CARD_NOTICE = "identity_card_fallback";
16
23
  type CredentialDeps = Pick<RouterDeps, "store" | "exchange" | "config" | "logger">;
17
24
  /**
18
25
  * What an action of the person's outside a turn (a thumb on an answer) calls Claw with: what their chats run on, so it acts
@@ -46,6 +53,16 @@ export declare class Credentials {
46
53
  * before such an answer: connecting a machine and the rest of what a key may do are not held behind it.
47
54
  */
48
55
  identityAfterRefusal(chat: Chat): Promise<boolean>;
56
+ /**
57
+ * After a message of a person the assistant is set to read first, which it could not take now and which went the ordinary way
58
+ * instead: the card that confirms their identity, with a line that says what happened, once (`FALLBACK_CARD_INTERVAL_SECONDS`;
59
+ * kept in the store, as `identityAfterRefusal`'s is). Only where confirming adds something: chats run on the exchange and the
60
+ * person has not confirmed. Nothing otherwise (a person with no key is asked to bind by `credential`, which this card must not
61
+ * double), and a card that was not sent leaves the allowance unspent.
62
+ */
63
+ identityAfterFallback(chat: Chat): Promise<boolean>;
64
+ /** The binding card with the catalog's line `lead`, at most once per `interval` seconds, only to a person who has not confirmed. */
65
+ private identityOnce;
49
66
  /** The binding card with `lead`; false (nothing sent) when the identity service gives no link: a key's owner is not sent the `/link` steps. */
50
67
  private sendIdentityCard;
51
68
  /** A fresh credential per call when chats run on exchanged tokens (they expire); undefined: the key as it is. */
@@ -15,6 +15,11 @@ export type CredentialProvider = (() => Promise<string>) | undefined;
15
15
  export interface AssistantRouteRequest {
16
16
  readonly userId: string;
17
17
  readonly credential: string;
18
+ /**
19
+ * The person's linked key beside `credential` when that is an exchanged token (absent: they linked none, or `credential` is the
20
+ * key itself): Claw runs the message on it, as it does one the assistant reads first (`UnderstandRequest.modelKey`).
21
+ */
22
+ readonly modelKey?: string;
18
23
  readonly prompt: string;
19
24
  readonly conversation: Conversation;
20
25
  readonly files: readonly InboundFile[];
@@ -33,6 +33,18 @@ export declare class PersonalRouter {
33
33
  /** Linked before the Claw user id was kept: it is read now. */
34
34
  private backfill;
35
35
  private message;
36
+ /**
37
+ * Whether the assistant reads this person's messages first now (`understood`), and whether it is set to but cannot be reached
38
+ * (`unreached`). A person it cannot reach is read the ordinary way, as one who is not listed is (the rule layer, then the
39
+ * assistant or a turn of Claw's), not told "cannot reach" and left with no turn.
40
+ */
41
+ private reading;
42
+ /**
43
+ * A person the assistant is set to read first but cannot reach now, whose message goes the ordinary way: told once, where
44
+ * confirming their identity would help, with the card that does it. A card that cannot be sent is logged and does not fail
45
+ * their message.
46
+ */
47
+ private toldOnFallback;
36
48
  /** What a 1:1 message can do with no account: true when it was taken. */
37
49
  private beforeCredential;
38
50
  private handlerOf;
@@ -16,6 +16,12 @@ export interface TurnRun {
16
16
  readonly userId: string;
17
17
  /** The person this turn acts for: their key, or an exchanged token. */
18
18
  readonly credential: string;
19
+ /**
20
+ * The person's own linked key, sent beside `credential` when that is an exchanged token (a chat turn only: a review's is
21
+ * `review.turn.modelKey`). Claw runs the turn on it: a service's identity token alone carries no key where the identity service
22
+ * verifies callers. Absent when the person has linked none, or `credential` is that key itself.
23
+ */
24
+ readonly modelKey?: string;
19
25
  readonly provider: CredentialProvider;
20
26
  /** The session to continue; null: Claw creates one with this message. */
21
27
  readonly sessionId: string | null;
@@ -102,6 +102,12 @@ export declare class TurnStarter {
102
102
  private ownThumbs;
103
103
  /** What the run reads of the chat's session: its id, the model it has, the repository a new one is bound to. */
104
104
  private sessionPart;
105
+ /**
106
+ * The person's linked key, for a chat turn that runs on their exchanged token: it goes beside the token, as it does on the
107
+ * assistant's path and for a review, because a service's token alone carries no key where the identity service verifies callers.
108
+ * Nothing for a review (its own), for a person with no linked key, and for a credential that is the key itself.
109
+ */
110
+ private modelKeyOf;
105
111
  private runOf;
106
112
  /**
107
113
  * The language a chat turn is to be answered in (a review's answer follows its request's language). In a 1:1 chat the one the
@@ -16,7 +16,7 @@ export interface SubscriptionsOptions {
16
16
  readonly baseUrl: string;
17
17
  /** ASSISTANT_ENABLED: subscriptions also get the assistant's event types. */
18
18
  readonly assistant?: boolean;
19
- /** PA_ASSISTANT_UNDERSTANDING_USERS: whose subscription also asks for `assistant.action`. */
19
+ /** PA_ASSISTANT_UNDERSTANDING(_USERS): whose subscription also asks for `assistant.action` (everybody's when no one is named). */
20
20
  readonly understood?: (aadId: string) => boolean;
21
21
  /** ASSISTANT_USERS: whose subscription gets the assistant's types (an empty list: everybody's). */
22
22
  readonly assistantFor?: (aadId: string) => boolean;
@@ -0,0 +1,10 @@
1
+ import type { Lang } from "../../locales/lang.js";
2
+ import type { ModelRefusal } from "../../plugins/model-refusal-policy.js";
3
+ import type { TurnState } from "../turn-state.js";
4
+ import type { TurnContext } from "./context.js";
5
+ /** The refusal a turn ended with: the policy's reading of its answer, else Claw's code for it. */
6
+ export declare function refusalOf(ctx: TurnContext, state: TurnState): ModelRefusal | undefined;
7
+ /** What the person is told instead of the refused answer (markdown, in `lang`): the policy's wording, else the catalog's. */
8
+ export declare function guidanceOf(ctx: TurnContext, refusal: ModelRefusal, lang: Lang): string;
9
+ /** The line in front of an answer the fallback model gave (markdown, in `lang`): the policy's wording, else the catalog's. */
10
+ export declare function leadOf(ctx: TurnContext, refusal: ModelRefusal, lang: Lang): string;
@@ -42,6 +42,8 @@ export declare class TurnState {
42
42
  prSummary: string;
43
43
  /** How Claw ended the turn; undefined: not yet. */
44
44
  failed: boolean | undefined;
45
+ /** Why Claw says the turn failed (its `failure_reason`, a code); '' when it said none, or the turn did not fail. */
46
+ failureReason: string;
45
47
  /**
46
48
  * @param messageId undefined: Claw queued the message; its turn is the first queue-run turn newer than `behind`.
47
49
  * @param behind queued only: the turn Claw was running when the message was sent (undefined: unknown).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primusclaw/personal-agent",
3
- "version": "0.15.3",
3
+ "version": "0.15.5",
4
4
  "description": "The personal agent's channel-neutral core: domain logic, ports and plugin interfaces.",
5
5
  "license": "MIT",
6
6
  "repository": {