wherever-dev 0.21.1 → 0.22.1
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/CHANGELOG.md +28 -0
- package/dist/assistant-channels.d.ts +242 -0
- package/dist/assistant-channels.d.ts.map +1 -0
- package/dist/assistant-channels.js +270 -0
- package/dist/assistant-channels.js.map +1 -0
- package/dist/assistant-controller.d.ts +228 -0
- package/dist/assistant-controller.d.ts.map +1 -0
- package/dist/assistant-controller.js +314 -0
- package/dist/assistant-controller.js.map +1 -0
- package/dist/assistant-cron.d.ts +87 -0
- package/dist/assistant-cron.d.ts.map +1 -0
- package/dist/assistant-cron.js +352 -0
- package/dist/assistant-cron.js.map +1 -0
- package/dist/assistant-folder.d.ts +161 -0
- package/dist/assistant-folder.d.ts.map +1 -0
- package/dist/assistant-folder.js +333 -0
- package/dist/assistant-folder.js.map +1 -0
- package/dist/assistant-schedule.d.ts +236 -0
- package/dist/assistant-schedule.d.ts.map +1 -0
- package/dist/assistant-schedule.js +454 -0
- package/dist/assistant-schedule.js.map +1 -0
- package/dist/assistant-scheduler.d.ts +210 -0
- package/dist/assistant-scheduler.d.ts.map +1 -0
- package/dist/assistant-scheduler.js +472 -0
- package/dist/assistant-scheduler.js.map +1 -0
- package/dist/assistant-tool-text.d.ts +40 -0
- package/dist/assistant-tool-text.d.ts.map +1 -0
- package/dist/assistant-tool-text.js +102 -0
- package/dist/assistant-tool-text.js.map +1 -0
- package/dist/assistant-tools.d.ts +222 -0
- package/dist/assistant-tools.d.ts.map +1 -0
- package/dist/assistant-tools.js +411 -0
- package/dist/assistant-tools.js.map +1 -0
- package/dist/cli-requests.d.ts +90 -0
- package/dist/cli-requests.d.ts.map +1 -0
- package/dist/cli-requests.js +75 -0
- package/dist/cli-requests.js.map +1 -0
- package/dist/index.js +427 -7
- package/dist/index.js.map +1 -1
- package/dist/protocol.d.ts +43 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/reply-routing.d.ts +106 -0
- package/dist/reply-routing.d.ts.map +1 -0
- package/dist/reply-routing.js +174 -0
- package/dist/reply-routing.js.map +1 -0
- package/dist/session-pool.d.ts +235 -4
- package/dist/session-pool.d.ts.map +1 -1
- package/dist/session-pool.js +446 -100
- package/dist/session-pool.js.map +1 -1
- package/dist/telegram-channel.d.ts +275 -0
- package/dist/telegram-channel.d.ts.map +1 -0
- package/dist/telegram-channel.js +702 -0
- package/dist/telegram-channel.js.map +1 -0
- package/dist/telegram-files.d.ts +101 -0
- package/dist/telegram-files.d.ts.map +1 -0
- package/dist/telegram-files.js +145 -0
- package/dist/telegram-files.js.map +1 -0
- package/dist/telegram-pairing.d.ts +119 -0
- package/dist/telegram-pairing.d.ts.map +1 -0
- package/dist/telegram-pairing.js +97 -0
- package/dist/telegram-pairing.js.map +1 -0
- package/dist/telegram-replies.d.ts +140 -0
- package/dist/telegram-replies.d.ts.map +1 -0
- package/dist/telegram-replies.js +474 -0
- package/dist/telegram-replies.js.map +1 -0
- package/dist/telegram-token.d.ts +55 -0
- package/dist/telegram-token.d.ts.map +1 -0
- package/dist/telegram-token.js +86 -0
- package/dist/telegram-token.js.map +1 -0
- package/dist/web-push.d.ts +167 -0
- package/dist/web-push.d.ts.map +1 -0
- package/dist/web-push.js +387 -0
- package/dist/web-push.js.map +1 -0
- package/package.json +1 -1
- package/public/_app/immutable/assets/0.hWfYEET-.css +1 -0
- package/public/_app/immutable/chunks/Cuh9gHb6.js +2 -0
- package/public/_app/immutable/chunks/Cuh9gHb6.js.map +1 -0
- package/public/_app/immutable/chunks/DEUwJYqt.js +2 -0
- package/public/_app/immutable/chunks/{BQ9B_G4h.js.map → DEUwJYqt.js.map} +1 -1
- package/public/_app/immutable/chunks/DSPDB3Gw.js +2 -0
- package/public/_app/immutable/chunks/{BUONgvl4.js.map → DSPDB3Gw.js.map} +1 -1
- package/public/_app/immutable/entry/{app.BZO7Xckk.js → app.BkV4f8p8.js} +3 -3
- package/public/_app/immutable/entry/{app.BZO7Xckk.js.map → app.BkV4f8p8.js.map} +1 -1
- package/public/_app/immutable/entry/start.D5TsAoxn.js +2 -0
- package/public/_app/immutable/entry/start.D5TsAoxn.js.map +1 -0
- package/public/_app/immutable/nodes/{0.Czz2XmZU.js → 0.DR4K9Ylw.js} +3 -3
- package/public/_app/immutable/nodes/{0.Czz2XmZU.js.map → 0.DR4K9Ylw.js.map} +1 -1
- package/public/_app/immutable/nodes/{1.DDvrriUW.js → 1.DdqkeKC4.js} +2 -2
- package/public/_app/immutable/nodes/{1.DDvrriUW.js.map → 1.DdqkeKC4.js.map} +1 -1
- package/public/_app/immutable/nodes/2.n5lfdeec.js +122 -0
- package/public/_app/immutable/nodes/2.n5lfdeec.js.map +1 -0
- package/public/_app/version.json +1 -1
- package/public/index.html +11 -11
- package/public/service-worker.js +1 -1
- package/public/_app/immutable/assets/0.BKJ49K71.css +0 -1
- package/public/_app/immutable/chunks/BQ9B_G4h.js +0 -2
- package/public/_app/immutable/chunks/BUONgvl4.js +0 -2
- package/public/_app/immutable/chunks/DauELski.js +0 -2
- package/public/_app/immutable/chunks/DauELski.js.map +0 -1
- package/public/_app/immutable/entry/start.DWD60uNu.js +0 -2
- package/public/_app/immutable/entry/start.DWD60uNu.js.map +0 -1
- package/public/_app/immutable/nodes/2.C7E8EMKX.js +0 -120
- package/public/_app/immutable/nodes/2.C7E8EMKX.js.map +0 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram REPLY delivery (task `telegram-conversation`): turns the pool events
|
|
3
|
+
* whose current destination is `telegram` (ADR 0014, handed over by the channel
|
|
4
|
+
* dispatcher) into Telegram messages. The mechanics are ported from the MIT
|
|
5
|
+
* `badlogic/pi-telegram` extension (`index.ts`):
|
|
6
|
+
*
|
|
7
|
+
* - STREAMING: while an assistant message streams (`message_update`), its text
|
|
8
|
+
* is shown as a DRAFT with `sendMessageDraft`; at its `message_end` the final
|
|
9
|
+
* text is sent as a real message. When the Bot API refuses drafts (an older
|
|
10
|
+
* Bot API, a self-hosted server), the preview falls back to `sendMessage` +
|
|
11
|
+
* `editMessageText`, and that is remembered for every later reply
|
|
12
|
+
* (`draftSupport`).
|
|
13
|
+
* - CLEARING A DRAFT: the Bot API has NO call that removes a draft. An EMPTY
|
|
14
|
+
* `sendMessageDraft` is not a clear: it shows a "Thinking..." placeholder
|
|
15
|
+
* (the animated dots), which lingers until the draft's ~30 s expiry. A draft
|
|
16
|
+
* disappears when the bot SENDS A MESSAGE to the chat. So an empty draft is
|
|
17
|
+
* never sent, and a visible draft is always ended by a real message: the
|
|
18
|
+
* final text at `message_end`; the text so far at a `tool_execution_start`,
|
|
19
|
+
* `turn_end` or `agent_end` that arrives while its message is still open
|
|
20
|
+
* (and not repeated at that message's `message_end`); on an ABORT, the
|
|
21
|
+
* partial text the user saw plus `ABORTED_MARK`, silently.
|
|
22
|
+
* - THROTTLE: the first preview of a message goes out at once (the user sees
|
|
23
|
+
* the assistant started); later ones at most every `throttleMs` (750 ms).
|
|
24
|
+
* - SPLITTING: text longer than `TELEGRAM_TEXT_LIMIT` is split by paragraph,
|
|
25
|
+
* then by line, then hard (never inside a surrogate pair). A preview is
|
|
26
|
+
* truncated to the limit; the final message is sent in parts.
|
|
27
|
+
* - ENDS: an assistant message with no text (tool calls only) sends nothing;
|
|
28
|
+
* an ERROR one is reported as `⚠️ The assistant failed: ...`.
|
|
29
|
+
* - TOOL CALLS (`assistantTelegram.toolCalls`): `off` (default) sends nothing
|
|
30
|
+
* for a tool call; `compact` sends one plain line per call at its
|
|
31
|
+
* `tool_execution_start` (`toolCallSummary`: `🔧 bash: <first line>`,
|
|
32
|
+
* `🔧 read: <path>`, secrets redacted), with `disable_notification`.
|
|
33
|
+
*
|
|
34
|
+
* - FILES (task `telegram-files`): a successful `attach_file` call's
|
|
35
|
+
* `tool_execution_end` sends its file (`sendPhoto` / `sendDocument`, by
|
|
36
|
+
* telegram-files.ts's `attachmentPlan`), or a clear note when it is too large
|
|
37
|
+
* or Telegram refuses it. It joins the same serial chain, so the file lands
|
|
38
|
+
* after the text the assistant wrote before the call.
|
|
39
|
+
*
|
|
40
|
+
* One stream per session file (a reply in an old session, after a reset, never
|
|
41
|
+
* mixes with the new one), and every Bot API call of every stream goes through
|
|
42
|
+
* ONE serial chain, so the messages arrive in the order the events did.
|
|
43
|
+
*
|
|
44
|
+
* Decision (recorded in work/notes/observations/telegram-conversation-decisions.md):
|
|
45
|
+
* EACH assistant message with text is delivered at its own `message_end` (a
|
|
46
|
+
* turn with tool calls in between may send several messages), rather than only
|
|
47
|
+
* the last one at `agent_end` as pi-telegram does: per-message routing (ADR
|
|
48
|
+
* 0014) can change the destination in the middle of a run (a steer), so the
|
|
49
|
+
* natural unit is the message, and `message_start` is not forwarded for CLI
|
|
50
|
+
* sessions.
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* The longest text sent in one message. Telegram's limit is 4096 characters;
|
|
54
|
+
* JavaScript lengths are UTF-16 code units (never fewer than Telegram counts),
|
|
55
|
+
* and the margin keeps every part safely UNDER the limit.
|
|
56
|
+
*/
|
|
57
|
+
export declare const TELEGRAM_TEXT_LIMIT = 4000;
|
|
58
|
+
export declare const PREVIEW_THROTTLE_MS = 750;
|
|
59
|
+
/** Appended to the partial text of an aborted reply (kept, since the user saw it as a draft). */
|
|
60
|
+
export declare const ABORTED_MARK = "\u23F9 (stopped)";
|
|
61
|
+
/** The longest tool-call detail in a compact line (`assistantTelegram.toolCalls: "compact"`). */
|
|
62
|
+
export declare const TOOL_SUMMARY_MAX = 80;
|
|
63
|
+
/** `assistantTelegram.toolCalls`: what a tool call shows on Telegram. */
|
|
64
|
+
export type TelegramToolCalls = 'off' | 'compact';
|
|
65
|
+
/** The `toolCalls` config value, normalized (anything but `"compact"` is `"off"`). */
|
|
66
|
+
export declare function normalizeToolCalls(value: unknown): TelegramToolCalls;
|
|
67
|
+
export type BotCall = <T>(method: string, params: Record<string, unknown>) => Promise<T>;
|
|
68
|
+
/** A multipart Bot API call sending one local file in `fileField` (`sendPhoto` / `sendDocument`). */
|
|
69
|
+
export type BotUpload = (method: string, fields: Record<string, string>, fileField: string, filePath: string, fileName: string) => Promise<unknown>;
|
|
70
|
+
export interface TelegramRepliesOptions {
|
|
71
|
+
call: BotCall;
|
|
72
|
+
/** Sends attached files; without it an `attach_file` is not delivered. */
|
|
73
|
+
upload?: BotUpload;
|
|
74
|
+
/** The paired chat (null while unpaired: nothing is sent). */
|
|
75
|
+
chatId: () => string | null;
|
|
76
|
+
throttleMs?: number;
|
|
77
|
+
/** `assistantTelegram.toolCalls` (default `off`: a tool call sends nothing). */
|
|
78
|
+
toolCalls?: TelegramToolCalls;
|
|
79
|
+
log?: Pick<Console, 'log' | 'warn' | 'error'>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Replace secret-looking values with `***`: `key=value` / `key: value` for
|
|
83
|
+
* secret-ish names, `Bearer` / `Basic` credentials, `--password x`-style flags,
|
|
84
|
+
* `user:pass@` in URLs, and any long opaque run of letters AND digits (API
|
|
85
|
+
* keys, bot tokens, hashes).
|
|
86
|
+
*/
|
|
87
|
+
export declare function redactSecrets(text: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* The compact line for one tool call: `🔧 <tool>`, plus `: <detail>` for the
|
|
90
|
+
* tools in `SUMMARY_ARG` (bash: the command's first non-empty line; file tools:
|
|
91
|
+
* the path). Control characters are dropped, secrets redacted BEFORE the cut,
|
|
92
|
+
* and the detail truncated to `TOOL_SUMMARY_MAX` characters. Never any other
|
|
93
|
+
* argument and never tool output.
|
|
94
|
+
*/
|
|
95
|
+
export declare function toolCallSummary(toolName: string, args: unknown): string;
|
|
96
|
+
/** Split `text` into parts of at most `limit` UTF-16 units (paragraph, line, then hard). */
|
|
97
|
+
export declare function splitTelegramText(text: string, limit?: number): string[];
|
|
98
|
+
/** The text blocks of a pi message's `content`, joined and trimmed. */
|
|
99
|
+
export declare function assistantText(content: unknown): string;
|
|
100
|
+
export declare class TelegramReplies {
|
|
101
|
+
private readonly call;
|
|
102
|
+
private readonly upload;
|
|
103
|
+
private readonly chatId;
|
|
104
|
+
private readonly throttleMs;
|
|
105
|
+
private readonly toolCalls;
|
|
106
|
+
private readonly log;
|
|
107
|
+
private readonly streams;
|
|
108
|
+
private draftSupport;
|
|
109
|
+
private nextDraftId;
|
|
110
|
+
private chain;
|
|
111
|
+
private timers;
|
|
112
|
+
constructor(opts: TelegramRepliesOptions);
|
|
113
|
+
/** One pool event whose destination is Telegram. */
|
|
114
|
+
handle(sessionFile: string, event: {
|
|
115
|
+
type: string;
|
|
116
|
+
[k: string]: unknown;
|
|
117
|
+
}): void;
|
|
118
|
+
/** Resolves once every pending preview and send has run (tests, shutdown). */
|
|
119
|
+
idle(): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* A boundary (tool call start, turn end) while an assistant message's draft
|
|
122
|
+
* may still be showing: send its text so far as a real message (the only way
|
|
123
|
+
* to end a draft) and remember it, so the message's `message_end` sends only
|
|
124
|
+
* what comes after. Nothing happens without a shown draft.
|
|
125
|
+
*/
|
|
126
|
+
private closeOpenDraft;
|
|
127
|
+
/** Drop every stream's pending preview (the channel stopped). */
|
|
128
|
+
stop(): void;
|
|
129
|
+
private streamFor;
|
|
130
|
+
private enqueue;
|
|
131
|
+
private allocateDraftId;
|
|
132
|
+
/** Show the stream's pending text (draft, else the fallback preview message). */
|
|
133
|
+
private flush;
|
|
134
|
+
private finish;
|
|
135
|
+
/** A compact tool-call line: plain text, without a notification of its own. */
|
|
136
|
+
private sendSilent;
|
|
137
|
+
/** An `attach_file`'s file: sent as a photo or a document, else a note saying why not. */
|
|
138
|
+
private sendAttachment;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=telegram-replies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram-replies.d.ts","sourceRoot":"","sources":["../src/telegram-replies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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E,cAAc;CA6B7B"}
|
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram REPLY delivery (task `telegram-conversation`): turns the pool events
|
|
3
|
+
* whose current destination is `telegram` (ADR 0014, handed over by the channel
|
|
4
|
+
* dispatcher) into Telegram messages. The mechanics are ported from the MIT
|
|
5
|
+
* `badlogic/pi-telegram` extension (`index.ts`):
|
|
6
|
+
*
|
|
7
|
+
* - STREAMING: while an assistant message streams (`message_update`), its text
|
|
8
|
+
* is shown as a DRAFT with `sendMessageDraft`; at its `message_end` the final
|
|
9
|
+
* text is sent as a real message. When the Bot API refuses drafts (an older
|
|
10
|
+
* Bot API, a self-hosted server), the preview falls back to `sendMessage` +
|
|
11
|
+
* `editMessageText`, and that is remembered for every later reply
|
|
12
|
+
* (`draftSupport`).
|
|
13
|
+
* - CLEARING A DRAFT: the Bot API has NO call that removes a draft. An EMPTY
|
|
14
|
+
* `sendMessageDraft` is not a clear: it shows a "Thinking..." placeholder
|
|
15
|
+
* (the animated dots), which lingers until the draft's ~30 s expiry. A draft
|
|
16
|
+
* disappears when the bot SENDS A MESSAGE to the chat. So an empty draft is
|
|
17
|
+
* never sent, and a visible draft is always ended by a real message: the
|
|
18
|
+
* final text at `message_end`; the text so far at a `tool_execution_start`,
|
|
19
|
+
* `turn_end` or `agent_end` that arrives while its message is still open
|
|
20
|
+
* (and not repeated at that message's `message_end`); on an ABORT, the
|
|
21
|
+
* partial text the user saw plus `ABORTED_MARK`, silently.
|
|
22
|
+
* - THROTTLE: the first preview of a message goes out at once (the user sees
|
|
23
|
+
* the assistant started); later ones at most every `throttleMs` (750 ms).
|
|
24
|
+
* - SPLITTING: text longer than `TELEGRAM_TEXT_LIMIT` is split by paragraph,
|
|
25
|
+
* then by line, then hard (never inside a surrogate pair). A preview is
|
|
26
|
+
* truncated to the limit; the final message is sent in parts.
|
|
27
|
+
* - ENDS: an assistant message with no text (tool calls only) sends nothing;
|
|
28
|
+
* an ERROR one is reported as `⚠️ The assistant failed: ...`.
|
|
29
|
+
* - TOOL CALLS (`assistantTelegram.toolCalls`): `off` (default) sends nothing
|
|
30
|
+
* for a tool call; `compact` sends one plain line per call at its
|
|
31
|
+
* `tool_execution_start` (`toolCallSummary`: `🔧 bash: <first line>`,
|
|
32
|
+
* `🔧 read: <path>`, secrets redacted), with `disable_notification`.
|
|
33
|
+
*
|
|
34
|
+
* - FILES (task `telegram-files`): a successful `attach_file` call's
|
|
35
|
+
* `tool_execution_end` sends its file (`sendPhoto` / `sendDocument`, by
|
|
36
|
+
* telegram-files.ts's `attachmentPlan`), or a clear note when it is too large
|
|
37
|
+
* or Telegram refuses it. It joins the same serial chain, so the file lands
|
|
38
|
+
* after the text the assistant wrote before the call.
|
|
39
|
+
*
|
|
40
|
+
* One stream per session file (a reply in an old session, after a reset, never
|
|
41
|
+
* mixes with the new one), and every Bot API call of every stream goes through
|
|
42
|
+
* ONE serial chain, so the messages arrive in the order the events did.
|
|
43
|
+
*
|
|
44
|
+
* Decision (recorded in work/notes/observations/telegram-conversation-decisions.md):
|
|
45
|
+
* EACH assistant message with text is delivered at its own `message_end` (a
|
|
46
|
+
* turn with tool calls in between may send several messages), rather than only
|
|
47
|
+
* the last one at `agent_end` as pi-telegram does: per-message routing (ADR
|
|
48
|
+
* 0014) can change the destination in the middle of a run (a steer), so the
|
|
49
|
+
* natural unit is the message, and `message_start` is not forwarded for CLI
|
|
50
|
+
* sessions.
|
|
51
|
+
*/
|
|
52
|
+
import { attachedFileOf, attachmentFailedNote, attachmentPlan, attachmentTooLargeNote, fileSize } from './telegram-files.js';
|
|
53
|
+
/**
|
|
54
|
+
* The longest text sent in one message. Telegram's limit is 4096 characters;
|
|
55
|
+
* JavaScript lengths are UTF-16 code units (never fewer than Telegram counts),
|
|
56
|
+
* and the margin keeps every part safely UNDER the limit.
|
|
57
|
+
*/
|
|
58
|
+
export const TELEGRAM_TEXT_LIMIT = 4000;
|
|
59
|
+
export const PREVIEW_THROTTLE_MS = 750;
|
|
60
|
+
const DRAFT_ID_MAX = 2_147_483_647;
|
|
61
|
+
/** Appended to the partial text of an aborted reply (kept, since the user saw it as a draft). */
|
|
62
|
+
export const ABORTED_MARK = '⏹ (stopped)';
|
|
63
|
+
/** The longest tool-call detail in a compact line (`assistantTelegram.toolCalls: "compact"`). */
|
|
64
|
+
export const TOOL_SUMMARY_MAX = 80;
|
|
65
|
+
/** The `toolCalls` config value, normalized (anything but `"compact"` is `"off"`). */
|
|
66
|
+
export function normalizeToolCalls(value) {
|
|
67
|
+
return value === 'compact' ? 'compact' : 'off';
|
|
68
|
+
}
|
|
69
|
+
/** The argument a compact tool-call line shows, per tool (anything else shows the name only). */
|
|
70
|
+
const SUMMARY_ARG = {
|
|
71
|
+
bash: 'command',
|
|
72
|
+
read: 'path',
|
|
73
|
+
write: 'path',
|
|
74
|
+
edit: 'path',
|
|
75
|
+
ls: 'path',
|
|
76
|
+
find: 'path',
|
|
77
|
+
grep: 'path',
|
|
78
|
+
attach_file: 'path',
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Replace secret-looking values with `***`: `key=value` / `key: value` for
|
|
82
|
+
* secret-ish names, `Bearer` / `Basic` credentials, `--password x`-style flags,
|
|
83
|
+
* `user:pass@` in URLs, and any long opaque run of letters AND digits (API
|
|
84
|
+
* keys, bot tokens, hashes).
|
|
85
|
+
*/
|
|
86
|
+
export function redactSecrets(text) {
|
|
87
|
+
const secretName = String.raw `[\w.-]*(?:token|secret|passw(?:or)?d|pwd|api[_-]?key|apikey|auth\w*|credential|private[_-]?key|access[_-]?key|session)[\w.-]*`;
|
|
88
|
+
return text
|
|
89
|
+
.replace(/:\/\/[^/\s:@]+:[^/\s@]+@/g, '://***@')
|
|
90
|
+
// curl -u user:pass, --user user:pass
|
|
91
|
+
.replace(/(\s(?:-u|--user)\s+)[^\s:]+:\S+/g, '$1***')
|
|
92
|
+
// mysql -pPASS (attached), sshpass -p PASS
|
|
93
|
+
.replace(/(\bmysql\b[^\n]*?\s-p)(?!\s)\S+/g, '$1***')
|
|
94
|
+
.replace(/(\bsshpass\s+-p\s+)\S+/g, '$1***')
|
|
95
|
+
.replace(/\b(bearer|basic|token)\s+[A-Za-z0-9._~+/=-]+/gi, '$1 ***')
|
|
96
|
+
.replace(new RegExp(String.raw `(--?${secretName})(=|\s+)("[^"]*"|'[^']*'|\S+)`, 'gi'), '$1$2***')
|
|
97
|
+
.replace(new RegExp(String.raw `\b(${secretName})(\s*[=:]\s*)("[^"]*"|'[^']*'|\S+)`, 'gi'), '$1$2***')
|
|
98
|
+
.replace(/[A-Za-z0-9_+=-]{20,}/g, (run) => (/[0-9]/.test(run) && /[A-Za-z]/.test(run) ? '***' : run));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The compact line for one tool call: `🔧 <tool>`, plus `: <detail>` for the
|
|
102
|
+
* tools in `SUMMARY_ARG` (bash: the command's first non-empty line; file tools:
|
|
103
|
+
* the path). Control characters are dropped, secrets redacted BEFORE the cut,
|
|
104
|
+
* and the detail truncated to `TOOL_SUMMARY_MAX` characters. Never any other
|
|
105
|
+
* argument and never tool output.
|
|
106
|
+
*/
|
|
107
|
+
export function toolCallSummary(toolName, args) {
|
|
108
|
+
const clean = (s) => s.replace(/[\u0000-\u001f\u007f]/g, ' ').replace(/\s+/g, ' ').trim();
|
|
109
|
+
const name = truncateWithEllipsis(clean(toolName) || 'tool', 60);
|
|
110
|
+
const field = SUMMARY_ARG[toolName];
|
|
111
|
+
const raw = field && args && typeof args === 'object' ? args[field] : undefined;
|
|
112
|
+
if (typeof raw !== 'string')
|
|
113
|
+
return `🔧 ${name}`;
|
|
114
|
+
// Bounded before the regexes (a one-line heredoc can be huge); only the first
|
|
115
|
+
// TOOL_SUMMARY_MAX characters are shown, so a secret there is redacted whole.
|
|
116
|
+
const firstLine = (raw.split(/\r?\n/).find((l) => l.trim().length > 0) ?? '').slice(0, 1000);
|
|
117
|
+
const detail = truncateWithEllipsis(clean(redactSecrets(firstLine)), TOOL_SUMMARY_MAX);
|
|
118
|
+
return detail ? `🔧 ${name}: ${detail}` : `🔧 ${name}`;
|
|
119
|
+
}
|
|
120
|
+
function truncateWithEllipsis(text, max) {
|
|
121
|
+
if (text.length <= max)
|
|
122
|
+
return text;
|
|
123
|
+
let j = max;
|
|
124
|
+
if (/[\uD800-\uDBFF]/.test(text[j - 1]))
|
|
125
|
+
j -= 1;
|
|
126
|
+
return `${text.slice(0, j).trimEnd()}…`;
|
|
127
|
+
}
|
|
128
|
+
/** Split `text` into parts of at most `limit` UTF-16 units (paragraph, line, then hard). */
|
|
129
|
+
export function splitTelegramText(text, limit = TELEGRAM_TEXT_LIMIT) {
|
|
130
|
+
if (text.length <= limit)
|
|
131
|
+
return [text];
|
|
132
|
+
const out = [];
|
|
133
|
+
let current = '';
|
|
134
|
+
const pushPart = (part, sep) => {
|
|
135
|
+
const candidate = current.length === 0 ? part : `${current}${sep}${part}`;
|
|
136
|
+
if (candidate.length <= limit) {
|
|
137
|
+
current = candidate;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (current.trim().length > 0)
|
|
141
|
+
out.push(current);
|
|
142
|
+
current = part;
|
|
143
|
+
};
|
|
144
|
+
for (const paragraph of text.replace(/\r\n/g, '\n').split(/\n\n+/)) {
|
|
145
|
+
if (paragraph.length === 0)
|
|
146
|
+
continue;
|
|
147
|
+
if (paragraph.length <= limit) {
|
|
148
|
+
pushPart(paragraph, '\n\n');
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
// A long paragraph: by line, then hard. Its pieces join with '\n'.
|
|
152
|
+
let first = true;
|
|
153
|
+
for (const line of paragraph.split('\n')) {
|
|
154
|
+
const pieces = line.length <= limit ? [line] : hardSplit(line, limit);
|
|
155
|
+
for (const piece of pieces) {
|
|
156
|
+
pushPart(piece, first ? '\n\n' : '\n');
|
|
157
|
+
first = false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (current.trim().length > 0)
|
|
162
|
+
out.push(current);
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
function hardSplit(line, limit) {
|
|
166
|
+
const out = [];
|
|
167
|
+
let i = 0;
|
|
168
|
+
while (i < line.length) {
|
|
169
|
+
let j = Math.min(line.length, i + limit);
|
|
170
|
+
// Never end a part on a high surrogate (it would split a pair).
|
|
171
|
+
if (j < line.length && /[\uD800-\uDBFF]/.test(line[j - 1]))
|
|
172
|
+
j -= 1;
|
|
173
|
+
out.push(line.slice(i, j));
|
|
174
|
+
i = j;
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
/** The first `limit` units of `text`, never ending inside a surrogate pair. */
|
|
179
|
+
function truncate(text, limit = TELEGRAM_TEXT_LIMIT) {
|
|
180
|
+
if (text.length <= limit)
|
|
181
|
+
return text;
|
|
182
|
+
let j = limit;
|
|
183
|
+
if (/[\uD800-\uDBFF]/.test(text[j - 1]))
|
|
184
|
+
j -= 1;
|
|
185
|
+
return text.slice(0, j);
|
|
186
|
+
}
|
|
187
|
+
/** The text blocks of a pi message's `content`, joined and trimmed. */
|
|
188
|
+
export function assistantText(content) {
|
|
189
|
+
if (typeof content === 'string')
|
|
190
|
+
return content.trim();
|
|
191
|
+
if (!Array.isArray(content))
|
|
192
|
+
return '';
|
|
193
|
+
return content
|
|
194
|
+
.filter((b) => !!b && typeof b === 'object' && b.type === 'text' && typeof b.text === 'string')
|
|
195
|
+
.map((b) => b.text)
|
|
196
|
+
.join('')
|
|
197
|
+
.trim();
|
|
198
|
+
}
|
|
199
|
+
export class TelegramReplies {
|
|
200
|
+
call;
|
|
201
|
+
upload;
|
|
202
|
+
chatId;
|
|
203
|
+
throttleMs;
|
|
204
|
+
toolCalls;
|
|
205
|
+
log;
|
|
206
|
+
streams = new Map();
|
|
207
|
+
draftSupport = 'unknown';
|
|
208
|
+
nextDraftId = 0;
|
|
209
|
+
chain = Promise.resolve();
|
|
210
|
+
timers = 0;
|
|
211
|
+
constructor(opts) {
|
|
212
|
+
this.call = opts.call;
|
|
213
|
+
this.upload = opts.upload;
|
|
214
|
+
this.chatId = opts.chatId;
|
|
215
|
+
this.throttleMs = opts.throttleMs ?? PREVIEW_THROTTLE_MS;
|
|
216
|
+
this.toolCalls = normalizeToolCalls(opts.toolCalls);
|
|
217
|
+
this.log = opts.log ?? console;
|
|
218
|
+
}
|
|
219
|
+
/** One pool event whose destination is Telegram. */
|
|
220
|
+
handle(sessionFile, event) {
|
|
221
|
+
const attached = attachedFileOf(event);
|
|
222
|
+
if (attached) {
|
|
223
|
+
this.enqueue(() => this.sendAttachment(attached.path, attached.filename));
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (event.type === 'tool_execution_start') {
|
|
227
|
+
// A user `!` command (forceCommand) is not the assistant's tool call.
|
|
228
|
+
if (event.forceCommand === true)
|
|
229
|
+
return;
|
|
230
|
+
this.closeOpenDraft(sessionFile);
|
|
231
|
+
if (this.toolCalls === 'compact' && typeof event.toolName === 'string') {
|
|
232
|
+
const line = toolCallSummary(event.toolName, event.args);
|
|
233
|
+
this.enqueue(() => this.sendSilent(line));
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (event.type === 'turn_end' || event.type === 'agent_end') {
|
|
238
|
+
this.closeOpenDraft(sessionFile);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const message = event.message;
|
|
242
|
+
if (!message || message.role !== 'assistant')
|
|
243
|
+
return;
|
|
244
|
+
if (event.type === 'message_update') {
|
|
245
|
+
const stream = this.streamFor(sessionFile);
|
|
246
|
+
stream.pending = assistantText(message.content);
|
|
247
|
+
if (!stream.pending)
|
|
248
|
+
return;
|
|
249
|
+
if (!stream.flushed && !stream.timer) {
|
|
250
|
+
stream.flushed = true;
|
|
251
|
+
this.enqueue(() => this.flush(stream));
|
|
252
|
+
}
|
|
253
|
+
else if (!stream.timer) {
|
|
254
|
+
this.timers += 1;
|
|
255
|
+
stream.timer = setTimeout(() => {
|
|
256
|
+
this.timers -= 1;
|
|
257
|
+
stream.timer = undefined;
|
|
258
|
+
this.enqueue(() => this.flush(stream));
|
|
259
|
+
}, this.throttleMs);
|
|
260
|
+
}
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (event.type === 'message_end') {
|
|
264
|
+
const stream = this.streams.get(sessionFile);
|
|
265
|
+
this.streams.delete(sessionFile);
|
|
266
|
+
if (stream?.timer) {
|
|
267
|
+
clearTimeout(stream.timer);
|
|
268
|
+
stream.timer = undefined;
|
|
269
|
+
this.timers -= 1;
|
|
270
|
+
}
|
|
271
|
+
// The already-sent prefix (`delivered`) is cut inside the chain, in
|
|
272
|
+
// finish(): a queued boundary may not have recorded it yet.
|
|
273
|
+
const text = assistantText(message.content);
|
|
274
|
+
const stopReason = typeof message.stopReason === 'string' ? message.stopReason : undefined;
|
|
275
|
+
const errorMessage = typeof message.errorMessage === 'string' ? message.errorMessage : undefined;
|
|
276
|
+
this.enqueue(() => this.finish(stream, text, stopReason, errorMessage));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/** Resolves once every pending preview and send has run (tests, shutdown). */
|
|
280
|
+
async idle() {
|
|
281
|
+
for (;;) {
|
|
282
|
+
const chain = this.chain;
|
|
283
|
+
await chain;
|
|
284
|
+
if (this.timers > 0) {
|
|
285
|
+
await new Promise((r) => setTimeout(r, Math.max(5, this.throttleMs)));
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (chain === this.chain)
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* A boundary (tool call start, turn end) while an assistant message's draft
|
|
294
|
+
* may still be showing: send its text so far as a real message (the only way
|
|
295
|
+
* to end a draft) and remember it, so the message's `message_end` sends only
|
|
296
|
+
* what comes after. Nothing happens without a shown draft.
|
|
297
|
+
*/
|
|
298
|
+
closeOpenDraft(sessionFile) {
|
|
299
|
+
const stream = this.streams.get(sessionFile);
|
|
300
|
+
if (!stream || stream.mode !== 'draft')
|
|
301
|
+
return;
|
|
302
|
+
if (stream.timer) {
|
|
303
|
+
clearTimeout(stream.timer);
|
|
304
|
+
stream.timer = undefined;
|
|
305
|
+
this.timers -= 1;
|
|
306
|
+
}
|
|
307
|
+
this.enqueue(async () => {
|
|
308
|
+
// Decided in the chain: an earlier flush may have just shown a draft.
|
|
309
|
+
if (stream.draftId === undefined || !stream.lastSent)
|
|
310
|
+
return;
|
|
311
|
+
const chatId = this.chatId();
|
|
312
|
+
if (!chatId)
|
|
313
|
+
return;
|
|
314
|
+
const text = afterDelivered(stream, stream.pending);
|
|
315
|
+
if (text) {
|
|
316
|
+
for (const part of splitTelegramText(text))
|
|
317
|
+
await this.call('sendMessage', { chat_id: chatId, text: part });
|
|
318
|
+
}
|
|
319
|
+
stream.delivered = stream.pending;
|
|
320
|
+
// The next text of this message (if any) is a new draft.
|
|
321
|
+
stream.draftId = undefined;
|
|
322
|
+
stream.lastSent = '';
|
|
323
|
+
stream.flushed = false;
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
/** Drop every stream's pending preview (the channel stopped). */
|
|
327
|
+
stop() {
|
|
328
|
+
for (const s of this.streams.values()) {
|
|
329
|
+
if (s.timer) {
|
|
330
|
+
clearTimeout(s.timer);
|
|
331
|
+
this.timers -= 1;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
this.streams.clear();
|
|
335
|
+
}
|
|
336
|
+
// -------------------------------------------------------------------------
|
|
337
|
+
streamFor(sessionFile) {
|
|
338
|
+
let s = this.streams.get(sessionFile);
|
|
339
|
+
if (!s) {
|
|
340
|
+
s = { mode: this.draftSupport === 'unsupported' ? 'message' : 'draft', pending: '', lastSent: '', flushed: false };
|
|
341
|
+
this.streams.set(sessionFile, s);
|
|
342
|
+
}
|
|
343
|
+
return s;
|
|
344
|
+
}
|
|
345
|
+
enqueue(op) {
|
|
346
|
+
this.chain = this.chain.then(op).catch((err) => this.log.warn(`[wherever] telegram: reply delivery failed: ${errMessage(err)}`));
|
|
347
|
+
}
|
|
348
|
+
allocateDraftId() {
|
|
349
|
+
this.nextDraftId = this.nextDraftId >= DRAFT_ID_MAX ? 1 : this.nextDraftId + 1;
|
|
350
|
+
return this.nextDraftId;
|
|
351
|
+
}
|
|
352
|
+
/** Show the stream's pending text (draft, else the fallback preview message). */
|
|
353
|
+
async flush(stream) {
|
|
354
|
+
const chatId = this.chatId();
|
|
355
|
+
if (!chatId)
|
|
356
|
+
return;
|
|
357
|
+
const text = truncate(afterDelivered(stream, stream.pending));
|
|
358
|
+
if (!text || text === stream.lastSent)
|
|
359
|
+
return;
|
|
360
|
+
if (stream.mode === 'draft' && this.draftSupport !== 'unsupported') {
|
|
361
|
+
stream.draftId ??= this.allocateDraftId();
|
|
362
|
+
try {
|
|
363
|
+
await this.call('sendMessageDraft', { chat_id: chatId, draft_id: stream.draftId, text });
|
|
364
|
+
this.draftSupport = 'supported';
|
|
365
|
+
stream.lastSent = text;
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
catch (err) {
|
|
369
|
+
this.log.log(`[wherever] telegram: sendMessageDraft unavailable (${errMessage(err)}); falling back to sendMessage + editMessageText`);
|
|
370
|
+
this.draftSupport = 'unsupported';
|
|
371
|
+
stream.mode = 'message';
|
|
372
|
+
stream.draftId = undefined;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
stream.mode = 'message';
|
|
376
|
+
if (stream.messageId === undefined) {
|
|
377
|
+
const sent = await this.call('sendMessage', { chat_id: chatId, text });
|
|
378
|
+
stream.messageId = sent?.message_id;
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
await this.call('editMessageText', { chat_id: chatId, message_id: stream.messageId, text });
|
|
382
|
+
}
|
|
383
|
+
stream.lastSent = text;
|
|
384
|
+
}
|
|
385
|
+
async finish(stream, fullText, stopReason, errorMessage) {
|
|
386
|
+
const chatId = this.chatId();
|
|
387
|
+
if (!chatId)
|
|
388
|
+
return;
|
|
389
|
+
const text = stream ? afterDelivered(stream, fullText) : fullText.trim();
|
|
390
|
+
if (stopReason === 'aborted') {
|
|
391
|
+
// A shown draft can only be ended by a message: keep what the user saw, silently.
|
|
392
|
+
if (stream?.mode === 'draft' && stream.draftId !== undefined && stream.lastSent) {
|
|
393
|
+
const partial = text || stream.lastSent;
|
|
394
|
+
for (const part of splitTelegramText(`${partial}\n\n${ABORTED_MARK}`)) {
|
|
395
|
+
await this.call('sendMessage', { chat_id: chatId, text: part, disable_notification: true });
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (text) {
|
|
401
|
+
// Sending the final message also ends the draft (Telegram removes a draft
|
|
402
|
+
// once the bot sends a message); no empty draft, which would show "Thinking...".
|
|
403
|
+
const parts = splitTelegramText(text);
|
|
404
|
+
let rest = parts;
|
|
405
|
+
if (stream?.mode === 'message' && stream.messageId !== undefined) {
|
|
406
|
+
// The fallback preview message becomes the first part.
|
|
407
|
+
if (parts[0] !== stream.lastSent) {
|
|
408
|
+
await this.call('editMessageText', { chat_id: chatId, message_id: stream.messageId, text: parts[0] });
|
|
409
|
+
}
|
|
410
|
+
rest = parts.slice(1);
|
|
411
|
+
}
|
|
412
|
+
for (const part of rest)
|
|
413
|
+
await this.call('sendMessage', { chat_id: chatId, text: part });
|
|
414
|
+
}
|
|
415
|
+
if (stopReason === 'error') {
|
|
416
|
+
await this.call('sendMessage', { chat_id: chatId, text: `⚠️ The assistant failed: ${errorMessage || 'unknown error'}` });
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
/** A compact tool-call line: plain text, without a notification of its own. */
|
|
420
|
+
async sendSilent(text) {
|
|
421
|
+
const chatId = this.chatId();
|
|
422
|
+
if (!chatId || !text.trim())
|
|
423
|
+
return;
|
|
424
|
+
await this.call('sendMessage', { chat_id: chatId, text, disable_notification: true });
|
|
425
|
+
}
|
|
426
|
+
/** An `attach_file`'s file: sent as a photo or a document, else a note saying why not. */
|
|
427
|
+
async sendAttachment(filePath, filename) {
|
|
428
|
+
const chatId = this.chatId();
|
|
429
|
+
if (!chatId || !this.upload)
|
|
430
|
+
return;
|
|
431
|
+
const size = fileSize(filePath);
|
|
432
|
+
if (size === null) {
|
|
433
|
+
await this.call('sendMessage', { chat_id: chatId, text: attachmentFailedNote(filename, 'the file is no longer there') });
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
const plan = attachmentPlan(filePath, size);
|
|
437
|
+
if (plan.kind === 'too-large') {
|
|
438
|
+
await this.call('sendMessage', { chat_id: chatId, text: attachmentTooLargeNote(filename, size, plan.limit, filePath) });
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (plan.kind === 'photo') {
|
|
442
|
+
try {
|
|
443
|
+
await this.upload('sendPhoto', { chat_id: chatId }, 'photo', filePath, filename);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
catch (err) {
|
|
447
|
+
// Telegram refuses some images as photos (dimensions, ratio): send the file as is.
|
|
448
|
+
this.log.log(`[wherever] telegram: sendPhoto refused ${filename} (${errMessage(err)}); sending it as a document`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
try {
|
|
452
|
+
await this.upload('sendDocument', { chat_id: chatId }, 'document', filePath, filename);
|
|
453
|
+
}
|
|
454
|
+
catch (err) {
|
|
455
|
+
this.log.warn(`[wherever] telegram: sending ${filename} failed: ${errMessage(err)}`);
|
|
456
|
+
await this.call('sendMessage', { chat_id: chatId, text: attachmentFailedNote(filename, errMessage(err)) });
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
/** `text` without the prefix a boundary already sent as a message (`delivered`), trimmed. */
|
|
461
|
+
function afterDelivered(stream, text) {
|
|
462
|
+
const d = stream.delivered;
|
|
463
|
+
if (d !== undefined && d.length > 0) {
|
|
464
|
+
if (text.startsWith(d))
|
|
465
|
+
return text.slice(d.length).trim();
|
|
466
|
+
if (text.trimStart().startsWith(d.trim()))
|
|
467
|
+
return text.trimStart().slice(d.trim().length).trim();
|
|
468
|
+
}
|
|
469
|
+
return text.trim();
|
|
470
|
+
}
|
|
471
|
+
function errMessage(err) {
|
|
472
|
+
return err instanceof Error ? err.message : String(err);
|
|
473
|
+
}
|
|
474
|
+
//# sourceMappingURL=telegram-replies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telegram-replies.js","sourceRoot":"","sources":["../src/telegram-replies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,cAAc,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE7H;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACxC,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AACvC,MAAM,YAAY,GAAG,aAAa,CAAC;AACnC,iGAAiG;AACjG,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;AAC1C,iGAAiG;AACjG,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAKnC,sFAAsF;AACtF,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC;AACjD,CAAC;AAmCD,iGAAiG;AACjG,MAAM,WAAW,GAA2B;IAC1C,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,MAAM;IACZ,EAAE,EAAE,MAAM;IACV,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,MAAM;CACpB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM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