wherever-dev 0.21.1 → 0.22.0

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.
Files changed (103) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/assistant-channels.d.ts +242 -0
  3. package/dist/assistant-channels.d.ts.map +1 -0
  4. package/dist/assistant-channels.js +270 -0
  5. package/dist/assistant-channels.js.map +1 -0
  6. package/dist/assistant-controller.d.ts +228 -0
  7. package/dist/assistant-controller.d.ts.map +1 -0
  8. package/dist/assistant-controller.js +314 -0
  9. package/dist/assistant-controller.js.map +1 -0
  10. package/dist/assistant-cron.d.ts +87 -0
  11. package/dist/assistant-cron.d.ts.map +1 -0
  12. package/dist/assistant-cron.js +352 -0
  13. package/dist/assistant-cron.js.map +1 -0
  14. package/dist/assistant-folder.d.ts +161 -0
  15. package/dist/assistant-folder.d.ts.map +1 -0
  16. package/dist/assistant-folder.js +333 -0
  17. package/dist/assistant-folder.js.map +1 -0
  18. package/dist/assistant-schedule.d.ts +236 -0
  19. package/dist/assistant-schedule.d.ts.map +1 -0
  20. package/dist/assistant-schedule.js +454 -0
  21. package/dist/assistant-schedule.js.map +1 -0
  22. package/dist/assistant-scheduler.d.ts +210 -0
  23. package/dist/assistant-scheduler.d.ts.map +1 -0
  24. package/dist/assistant-scheduler.js +472 -0
  25. package/dist/assistant-scheduler.js.map +1 -0
  26. package/dist/assistant-tool-text.d.ts +40 -0
  27. package/dist/assistant-tool-text.d.ts.map +1 -0
  28. package/dist/assistant-tool-text.js +102 -0
  29. package/dist/assistant-tool-text.js.map +1 -0
  30. package/dist/assistant-tools.d.ts +207 -0
  31. package/dist/assistant-tools.d.ts.map +1 -0
  32. package/dist/assistant-tools.js +390 -0
  33. package/dist/assistant-tools.js.map +1 -0
  34. package/dist/cli-requests.d.ts +90 -0
  35. package/dist/cli-requests.d.ts.map +1 -0
  36. package/dist/cli-requests.js +75 -0
  37. package/dist/cli-requests.js.map +1 -0
  38. package/dist/index.js +396 -7
  39. package/dist/index.js.map +1 -1
  40. package/dist/protocol.d.ts +43 -0
  41. package/dist/protocol.d.ts.map +1 -1
  42. package/dist/reply-routing.d.ts +106 -0
  43. package/dist/reply-routing.d.ts.map +1 -0
  44. package/dist/reply-routing.js +174 -0
  45. package/dist/reply-routing.js.map +1 -0
  46. package/dist/session-pool.d.ts +232 -4
  47. package/dist/session-pool.d.ts.map +1 -1
  48. package/dist/session-pool.js +446 -100
  49. package/dist/session-pool.js.map +1 -1
  50. package/dist/telegram-channel.d.ts +272 -0
  51. package/dist/telegram-channel.d.ts.map +1 -0
  52. package/dist/telegram-channel.js +701 -0
  53. package/dist/telegram-channel.js.map +1 -0
  54. package/dist/telegram-files.d.ts +101 -0
  55. package/dist/telegram-files.d.ts.map +1 -0
  56. package/dist/telegram-files.js +145 -0
  57. package/dist/telegram-files.js.map +1 -0
  58. package/dist/telegram-pairing.d.ts +119 -0
  59. package/dist/telegram-pairing.d.ts.map +1 -0
  60. package/dist/telegram-pairing.js +97 -0
  61. package/dist/telegram-pairing.js.map +1 -0
  62. package/dist/telegram-replies.d.ts +94 -0
  63. package/dist/telegram-replies.d.ts.map +1 -0
  64. package/dist/telegram-replies.js +329 -0
  65. package/dist/telegram-replies.js.map +1 -0
  66. package/dist/telegram-token.d.ts +55 -0
  67. package/dist/telegram-token.d.ts.map +1 -0
  68. package/dist/telegram-token.js +86 -0
  69. package/dist/telegram-token.js.map +1 -0
  70. package/dist/web-push.d.ts +167 -0
  71. package/dist/web-push.d.ts.map +1 -0
  72. package/dist/web-push.js +387 -0
  73. package/dist/web-push.js.map +1 -0
  74. package/package.json +1 -1
  75. package/public/_app/immutable/assets/0.BkzT3rFr.css +1 -0
  76. package/public/_app/immutable/chunks/CExVgK9Z.js +2 -0
  77. package/public/_app/immutable/chunks/CExVgK9Z.js.map +1 -0
  78. package/public/_app/immutable/chunks/CkOw6fRa.js +2 -0
  79. package/public/_app/immutable/chunks/{BQ9B_G4h.js.map → CkOw6fRa.js.map} +1 -1
  80. package/public/_app/immutable/chunks/DyHllYtq.js +2 -0
  81. package/public/_app/immutable/chunks/{BUONgvl4.js.map → DyHllYtq.js.map} +1 -1
  82. package/public/_app/immutable/entry/{app.BZO7Xckk.js → app.D3PEFbtP.js} +3 -3
  83. package/public/_app/immutable/entry/{app.BZO7Xckk.js.map → app.D3PEFbtP.js.map} +1 -1
  84. package/public/_app/immutable/entry/start.BR00Qps5.js +2 -0
  85. package/public/_app/immutable/entry/start.BR00Qps5.js.map +1 -0
  86. package/public/_app/immutable/nodes/{0.Czz2XmZU.js → 0.DG3L8hMN.js} +3 -3
  87. package/public/_app/immutable/nodes/{0.Czz2XmZU.js.map → 0.DG3L8hMN.js.map} +1 -1
  88. package/public/_app/immutable/nodes/{1.DDvrriUW.js → 1.BCpuoZxW.js} +2 -2
  89. package/public/_app/immutable/nodes/{1.DDvrriUW.js.map → 1.BCpuoZxW.js.map} +1 -1
  90. package/public/_app/immutable/nodes/2.D2auiZW1.js +122 -0
  91. package/public/_app/immutable/nodes/2.D2auiZW1.js.map +1 -0
  92. package/public/_app/version.json +1 -1
  93. package/public/index.html +11 -11
  94. package/public/service-worker.js +1 -1
  95. package/public/_app/immutable/assets/0.BKJ49K71.css +0 -1
  96. package/public/_app/immutable/chunks/BQ9B_G4h.js +0 -2
  97. package/public/_app/immutable/chunks/BUONgvl4.js +0 -2
  98. package/public/_app/immutable/chunks/DauELski.js +0 -2
  99. package/public/_app/immutable/chunks/DauELski.js.map +0 -1
  100. package/public/_app/immutable/entry/start.DWD60uNu.js +0 -2
  101. package/public/_app/immutable/entry/start.DWD60uNu.js.map +0 -1
  102. package/public/_app/immutable/nodes/2.C7E8EMKX.js +0 -120
  103. package/public/_app/immutable/nodes/2.C7E8EMKX.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # wherever-dev
2
2
 
3
+ ## 0.22.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5dabe0a: Add the opt-in `assistantFolder` config key, the foundation of the upcoming assistant. Unset (the default) changes nothing. When set, the server creates the folder at start and seeds it once (never overwriting) with a default `AGENTS.md`, `jobs/AGENTS.md` and a `.gitignore`, and takes a folder lock `.assistant.lock` (pid, host, boot id, process start time). A second server on the same folder refuses the assistant with a clear log line; a stale same-host lock (dead pid, reused pid, other boot) is taken over, and a lock from another host never is. The assistant status (configured, folder, active, lock) is exposed to the web in `GET /config`. Changing `assistantFolder` takes effect on restart.
8
+ - 2c174eb: Give the assistant a current session and a reset. With `assistantFolder` set, the server keeps a pointer to the CURRENT assistant session in its state dir (`assistant-session.json`), surviving restarts and idle eviction. The web gains an "Assistant" entry in the sidebar that opens the current session (creating one when there is none) and a Reset button on it; `/new` and `/reset` typed in the assistant session reset it too. A reset aborts the old session's running turn, clears and records its queued messages, and makes a fresh session in the folder current, even while another tab still views the old one. Sessions created in `jobs/` or elsewhere never move the pointer. `GET /config` reports the current session id. With `assistantFolder` unset nothing changes.
9
+ - 28d33ce: Let agents manage the assistant's schedule and the user's timezone. With `assistantFolder` set, every server-built session (not only the assistant's) gets four tools: `assistant_schedule_add` (writes a job to the assistant's `schedule.json`, stamping the calling session as its origin; the job always runs as the assistant), `assistant_schedule_list` (every job with its state and last / next run, marking the caller's, plus done and invalid entries), `assistant_schedule_remove` and `assistant_set_timezone` (a validated IANA name). Bad input returns a tool error and writes nothing; on a server refused by the folder lock the tools answer a clear lock-state error. Every turn in the assistant folder (and its `jobs/`) now carries `User's current timezone: <tz>` in its system prompt. The web reports its browser timezone on connect, which becomes the user's current timezone when it differs; every timezone change is pushed to CLI bridges (`assistant_info_changed`) and to the web, `assistant_info` returns the timezone, and the sidebar's Assistant entry shows it. With `assistantFolder` unset nothing changes: no tools, no timezone line, and the web's report is ignored.
10
+ - 9f742e0: Add the assistant scheduler. With `assistantFolder` set (and this server holding the folder lock), the server fires the jobs listed in `<assistantFolder>/schedule.json` (`{ "jobs": [...] }`, each with a 5-field `cron` or a one-shot `at` date-time or `"now"`, an optional pinned `tz`, `mode` `inline` or `isolated`, a `prompt` and `enabled`). Inline jobs are delivered into the current assistant session once it has settled with nothing queued, as `[schedule:<name>] ...` (a `/command` prompt is sent as-is so skills and templates still expand); isolated jobs start at once, in parallel, in a fresh session in `jobs/`. Jobs without `tz` follow the user's current timezone (server state in the state dir, initialised to the system timezone). Run history goes to an append-only `assistant-runs.jsonl` in the state dir; `schedule.json` is never written with run bookkeeping. Malformed entries are logged and skipped without stopping the others, prompts starting with `!` are refused, and runs missed while the server was down fire once on restart if the latest is within the new `assistantScheduleGraceMinutes` window (default 60), otherwise they are skipped and recorded. After an aborted turn the assistant session's leftover queued messages are now cleared (and recorded) so scheduled jobs can be delivered again. With `assistantFolder` unset nothing changes.
11
+ - 8fc8e34: Make wherever a chat app for its assistant: push notifications and the `assistant_notify` tool. With `assistantFolder` set (and this server holding the folder lock), every server session gets `assistant_notify {title, body, navigateSessionId?, jobId?}`, the one way an agent reaches you proactively: it is delivered at once (even mid-turn) to every channel, and tapping it opens `navigateSessionId`, or for a scheduled job the session that scheduled it, or else the calling session. A scheduled turn that does not call it stays silent. The first channel is Web Push, sent by wherever itself (no extra service, no new dependency): turn on "Assistant notifications" in the settings on each device; the VAPID keys are generated on first use in the state dir, subscriptions are stored there behind the token, every subscribed device gets each push, and devices the push service reports gone are pruned. New optional config: `assistantWebPush` (`enabled`, default true; `subject`, the VAPID contact) and `publicUrl`. Clicking an in-app notification while the app is open now opens its session (it did not). Messages dropped by an assistant reset or an aborted turn are now attributed to the channel they came from, ready for Telegram. With `assistantFolder` unset nothing changes: no keys, no push routes, no `assistant_notify`, no settings toggle.
12
+ - 1a5ed97: The CLI bridge's `cli_request` path answers the five ops behind the terminal `pi` twins of the assistant tools: `schedule_add`, `schedule_list`, `schedule_remove`, `set_timezone` and `notify`. They run the same code as the server sessions' assistant tools, with the calling terminal session (resolved from its bridge registration) as the origin. With `assistantFolder` unset they answer "not configured", and with the folder lock held by another server the same lock-state error as the server tools.
13
+ - 2ba32b4: The server side of the richer CLI bridge. A `cli_register` with `isNew: true` fires the session-created callback, so starting a fresh terminal `pi` in `assistantFolder` makes it the current assistant session (`pi -c`, reconnects and older extensions do not). The extension's `capabilities` are recorded per CLI session. A new `cli_request` / `cli_response` path answers requests from a registered bridge, resolving the caller from its registration; its first op, `assistant_info`, reports the active assistant folder (or that the assistant is not configured), and unknown ops answer an error. A forwarded `agent_settled` reaches the pool's event fan-out without sending anything to the web. With `assistantFolder` unset nothing is written.
14
+ - 65bfb8b: Photos and images sent to the assistant on Telegram now reach the model as images, not only as file paths. Every received file that is an image (a photo, or an image sent as a document) is passed to the assistant session as a model image input, and its `[Uploaded file: <path>]` line stays in the message so the agent can still open, move or attach the file. This works for server-built sessions and, through the CLI bridge, for a terminal `pi` attached to wherever. A text-only model gets pi's "image omitted" note instead. Messages without images are sent exactly as before, and reply routing is unchanged.
15
+ - 055bace: Talk to the assistant from Telegram. Once the bot is paired, your messages go to the current assistant session: an idle session starts a turn, and a message sent mid-turn steers it (shown by a ✍ reaction on your message, or a short "Added to the current reply" note when reactions are unavailable). Replies to your Telegram messages stream back as a draft (`sendMessageDraft`, falling back to a message edited in place) and are split below Telegram's 4096-character limit; output answering web, terminal or scheduled messages is never sent to Telegram. `stop` aborts the running turn, `/new` and `/reset` reset the assistant, `!` shell commands are refused with an explanation, and other `/` text (such as `/skill:`) is passed through untouched. `assistant_notify` arrives as its own `🔔 <source>: <title>` message, with a link to the session when `publicUrl` is configured, immediately even mid-reply. Messages dropped by a reset or a stop are listed back on Telegram.
16
+ - 34487fd: Files now flow both ways on the assistant's Telegram channel. A photo, an album or a document from the paired user is downloaded into the upload dir (where a web upload into the assistant session lands) and reaches the assistant as `[Uploaded file: <path>]` lines, exactly as a web upload does, with the caption as the text. When the assistant calls `attach_file` in a reply to a Telegram message, the file is sent on Telegram (as a photo for jpg, png and webp images up to 10 MB, as a document otherwise), and a file over Telegram's 50 MB limit gets a clear note instead. Files attached in web, terminal or scheduled turns are never sent to Telegram.
17
+ - b500a10: The assistant can now be reached on Telegram, and only by you. With `assistantFolder` set (and this server holding the folder lock), set `"assistantTelegram": {"enabled": true}` and give the bot token through `WHEREVER_TELEGRAM_TOKEN`, `WHEREVER_TELEGRAM_TOKEN_FILE` (a file holding the token, for secret managers) or `assistantTelegram.token`, never on the command line. Both variables are removed from the server's environment at startup so the agent's shell cannot read them. If the token file cannot be read, Telegram is disabled with a loud error and the server keeps running. wherever long-polls the Bot API and saves the polling offset in the state dir, so a restart neither replays nor loses messages. Pairing needs a one-time code shown in the new "Assistant on Telegram" settings section: send `/pair <code>` to the bot. Anyone else writing to the bot is ignored and gets no answer. `assistantTelegram.userId` pairs a fixed user instead. Once paired, `/start` and `/pair` are refused, and "Re-pair" in the settings drops the pairing and issues a new code. This release covers connecting and pairing: your messages already reach the assistant session (visible in the web), and replies on Telegram come next. With `assistantFolder` unset, or Telegram not enabled, nothing changes: the token file is not read, nothing polls and nothing is written.
18
+
19
+ ### Patch Changes
20
+
21
+ - a4ef0b1: The session pool now keeps per-user-message reply routing for the assistant (ADR 0014): each send can carry an origin (`telegram`, `schedule:<jobId>`, ...; web sends record `none`), and every reply is attributed to the origin of the user message it answers, across prompts, steers and follow-ups, extension-handled `/commands`, `!` shell sends, aborts and CLI-bridge sessions. The pool also gains an event fan-out beside the WS broadcaster. Server sends now all go through pi's `prompt()` (plain text exactly as before; `/skill:` and prompt templates still expand). Nothing a user or client sees changes.
22
+
3
23
  ## 0.21.1
4
24
 
5
25
  ### Patch Changes
@@ -0,0 +1,242 @@
1
+ import type { ImageContent } from '@earendil-works/pi-ai';
2
+ import type { DroppedMessages } from './assistant-controller.js';
3
+ /**
4
+ * The assistant's CHANNEL SEAM (spec `assistant-session-and-channels`, ADRs 0014
5
+ * and 0017): the one interface every transport implements (Web Push now,
6
+ * Telegram next, WhatsApp later), and the dispatcher that connects the channels
7
+ * to the controller and the session pool.
8
+ *
9
+ * A channel's `name` is also its ROUTING ORIGIN (ADR 0014): a user message it
10
+ * feeds in is sent with `origin = name`, and output whose current destination
11
+ * is that origin is handed back to it as a reply. Everything else the assistant
12
+ * says reaches a channel ONLY through `notify` (`assistant_notify`), which is
13
+ * always immediate: it never waits for a running turn.
14
+ *
15
+ * Every capability but `start` / `stop` is optional: Web Push implements
16
+ * `notify` only (it never originates a message and never shows replies).
17
+ *
18
+ * Channels exist only while the assistant is ACTIVE (configured AND this server
19
+ * holds the folder lock): `server/src/index.ts` builds the dispatcher beside the
20
+ * controller and scheduler, so with `assistantFolder` unset or refused no
21
+ * channel is built, started or polled.
22
+ */
23
+ /** A file a channel received with a user message (downloaded to a local path by the channel). */
24
+ export interface ChannelFile {
25
+ path: string;
26
+ name?: string;
27
+ mimeType?: string;
28
+ }
29
+ /** A user message a channel received (Telegram text, ...). */
30
+ export interface ChannelUserMessage {
31
+ /** The channel's name (= the routing origin the reply comes back to). */
32
+ channel: string;
33
+ text: string;
34
+ files?: ChannelFile[];
35
+ /** The channel-side sender (a Telegram user id, ...), for logs. */
36
+ senderId?: string;
37
+ }
38
+ /** What `onUserMessage` answers: refused messages never reach the pool. */
39
+ export type ChannelInboundResult = {
40
+ accepted: true;
41
+ } | {
42
+ accepted: false;
43
+ reason: string;
44
+ };
45
+ /** Hooks of one inbound message. */
46
+ export interface ChannelInboundHooks {
47
+ /**
48
+ * Called once the message is handed to the assistant session, BEFORE the
49
+ * send resolves (which, for a message that starts a turn, is only at the end
50
+ * of that turn): `steered` is true when it went into a running turn as a
51
+ * steer (ADR 0003), false when it started one.
52
+ */
53
+ onDispatched?(d: {
54
+ steered: boolean;
55
+ }): void;
56
+ }
57
+ /** A channel command's answer (`/new`, `/reset`). */
58
+ export type ChannelCommandResult = {
59
+ ok: true;
60
+ } | {
61
+ ok: false;
62
+ error: string;
63
+ };
64
+ /** The context a channel gets at `start`. */
65
+ export interface ChannelContext {
66
+ /**
67
+ * Feed a user message to the CURRENT assistant session (controller `send`,
68
+ * origin = the channel). Into a running turn it STEERS, as the web composer
69
+ * does (ADR 0003); `hooks.onDispatched` tells which happened.
70
+ */
71
+ onUserMessage(message: ChannelUserMessage, hooks?: ChannelInboundHooks): Promise<ChannelInboundResult>;
72
+ /** Reset the assistant (a channel's `/new` / `/reset`): the controller's reset. Never throws. */
73
+ resetSession(): Promise<ChannelCommandResult>;
74
+ /** Abort the current assistant session's running turn (a channel's `stop`). Never throws. */
75
+ abortTurn(): Promise<{
76
+ aborted: boolean;
77
+ }>;
78
+ }
79
+ /**
80
+ * One `assistant_notify`, channel-agnostic. `navigate` is the SESSION ID a tap
81
+ * opens (each channel builds its own link: Web Push `/#<sessionId>`).
82
+ */
83
+ export interface ChannelNotification {
84
+ title: string;
85
+ body: string;
86
+ /** Who notified: the origin folder (or session) name. */
87
+ source: string;
88
+ /** The session id the notification opens. */
89
+ navigate: string;
90
+ files?: ChannelFile[];
91
+ }
92
+ export type ChannelNotifyResult = {
93
+ ok: true;
94
+ detail?: string;
95
+ } | {
96
+ ok: false;
97
+ error: string;
98
+ };
99
+ /** A pool event whose current destination is this channel (a reply to its message). */
100
+ export interface ChannelReply {
101
+ sessionFile: string;
102
+ /** The routing destination (the channel's name, possibly `name:<sub>`). */
103
+ destination: string;
104
+ event: {
105
+ type: string;
106
+ [k: string]: unknown;
107
+ };
108
+ }
109
+ /** Queued messages from this channel that a reset or an aborted settle dropped. */
110
+ export interface ChannelDroppedReport {
111
+ sessionFile: string;
112
+ reason: DroppedMessages['reason'];
113
+ /** The dropped texts that came from this channel, oldest first. */
114
+ messages: string[];
115
+ at: string;
116
+ }
117
+ export interface AssistantChannel {
118
+ /** Unique channel name, also its routing origin (`webpush`, `telegram`). */
119
+ readonly name: string;
120
+ start(ctx: ChannelContext): void | Promise<void>;
121
+ stop(): void | Promise<void>;
122
+ /** Deliver a notification NOW (never waits for a turn). */
123
+ notify?(notification: ChannelNotification): Promise<ChannelNotifyResult>;
124
+ /** Output answering a message this channel fed in. */
125
+ deliverReply?(reply: ChannelReply): void | Promise<void>;
126
+ /** Report messages from this channel that were dropped. */
127
+ reportDropped?(report: ChannelDroppedReport): void | Promise<void>;
128
+ }
129
+ /** The slice of the controller the dispatcher drives (faked in tests). */
130
+ export interface ChannelControllerPort {
131
+ send(text: string, origin: string, streamingBehavior?: 'steer' | 'followUp', opts?: {
132
+ onDispatch?: (d: {
133
+ sessionFile: string;
134
+ steered: boolean;
135
+ }) => void;
136
+ images?: ImageContent[];
137
+ }): Promise<void>;
138
+ /** The assistant reset (optional in fakes; a channel's `/new` then answers an error). */
139
+ reset?(): Promise<unknown>;
140
+ /** Abort the current session's running turn; true when one was running. */
141
+ abortCurrent?(): Promise<boolean>;
142
+ }
143
+ /** The slice of the session pool the dispatcher listens to (faked in tests). */
144
+ export interface ChannelPoolPort {
145
+ subscribeEvents(listener: (sessionFile: string, event: {
146
+ type: string;
147
+ [k: string]: unknown;
148
+ }, destination: string | null) => void): () => void;
149
+ }
150
+ /** One channel's answer to a notify. */
151
+ export interface NotifyDelivery {
152
+ channel: string;
153
+ result: ChannelNotifyResult;
154
+ }
155
+ /** The whole notify: ok when at least one channel delivered. */
156
+ export type NotifyOutcome = {
157
+ ok: true;
158
+ deliveries: NotifyDelivery[];
159
+ } | {
160
+ ok: false;
161
+ error: string;
162
+ deliveries: NotifyDelivery[];
163
+ };
164
+ /** Why a channel's `!` / `!!` message is refused (the pool's shell path is never reached). */
165
+ export declare const CHANNEL_SHELL_REFUSAL = "shell commands (\"!\") cannot be run from a channel; ask the assistant instead";
166
+ /** The error `assistant_notify` answers when no channel can notify. */
167
+ export declare const NO_CHANNEL_ERROR = "no notification channel is enabled on this server (turn on push notifications in the wherever settings on a device, or configure a channel such as Telegram)";
168
+ /**
169
+ * The text a channel message reaches the assistant as: its text, then one
170
+ * `[Uploaded file: <path>]` line per file, or, with no text of its own, an
171
+ * explicit "I have uploaded the following file(s) for you:" before them.
172
+ * EXACTLY what the web composer sends for an upload (`buildAttachmentMessage`
173
+ * in web/src/lib/core/attachments.ts; keep the two in step), so the agent reads
174
+ * a Telegram file as it reads a web one.
175
+ */
176
+ export declare function channelMessageText(text: string, files: ChannelFile[] | undefined): string;
177
+ /**
178
+ * The model IMAGE INPUTS of a channel message (task `pool-send-images`): every
179
+ * file whose MIME type is `image/*` (a Telegram photo, or an image sent as a
180
+ * document), or, with no MIME type, whose extension is a common image one,
181
+ * read from its saved path as base64. The file stays a path in the text as well
182
+ * (`channelMessageText`), so the agent can still open, move or attach it; pi
183
+ * converts or resizes what the model needs, and drops it with a note for a
184
+ * text-only model. A file that cannot be read is logged and left as a path only.
185
+ */
186
+ export declare function channelImages(files: ChannelFile[] | undefined): Promise<ImageContent[]>;
187
+ /** True when a routing destination belongs to `channel` (`telegram`, or `telegram:<sub>`). */
188
+ export declare function destinationIsChannel(destination: string | null, channel: string): boolean;
189
+ /**
190
+ * Group dropped texts by their routing origin. `origins` is aligned with the
191
+ * texts (null = not known); a record without origins attributes nothing.
192
+ */
193
+ export declare function droppedByOrigin(dropped: DroppedMessages): Map<string, string[]>;
194
+ export interface ChannelDispatcherOptions {
195
+ controller: ChannelControllerPort;
196
+ pool: ChannelPoolPort;
197
+ channels: AssistantChannel[];
198
+ }
199
+ export declare class ChannelDispatcher {
200
+ private readonly controller;
201
+ private readonly pool;
202
+ private readonly channels;
203
+ private started;
204
+ private unsubscribe;
205
+ constructor(opts: ChannelDispatcherOptions);
206
+ /**
207
+ * Start every channel (one that fails to start is logged and left out, so it
208
+ * never takes the others or the server down) and subscribe to the pool's
209
+ * event fan-out for replies.
210
+ */
211
+ start(): Promise<void>;
212
+ stop(): Promise<void>;
213
+ /** The started channels that can notify. */
214
+ notifyChannels(): string[];
215
+ /**
216
+ * Deliver to EVERY started channel that can notify, in parallel and at once.
217
+ * Ok when at least one delivered; with none able to notify, the clear
218
+ * `NO_CHANNEL_ERROR`.
219
+ */
220
+ notify(n: ChannelNotification): Promise<NotifyOutcome>;
221
+ /**
222
+ * The controller's `onDropped`: report each dropped message to the channel of
223
+ * its routing origin. Messages from the web (`none`), the scheduler or no
224
+ * known origin are reported to nobody (the web shows the session itself).
225
+ */
226
+ reportDropped(dropped: DroppedMessages): void;
227
+ /**
228
+ * A channel's inbound message: to the controller with origin = the channel.
229
+ * `!` / `!!` (the pool's shell path) is refused here for every channel, so no
230
+ * transport can run a shell command without an agent turn (story 16).
231
+ * Attached files (already saved by the channel) are written into the text
232
+ * as the web composer does (`channelMessageText`), and image files are also
233
+ * sent as model image inputs (`channelImages`).
234
+ */
235
+ private onUserMessage;
236
+ /** A channel's `/new` / `/reset`: the controller's reset. */
237
+ private resetSession;
238
+ /** A channel's `stop`: abort the current session's running turn. */
239
+ private abortTurn;
240
+ private route;
241
+ }
242
+ //# sourceMappingURL=assistant-channels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assistant-channels.d.ts","sourceRoot":"","sources":["../src/assistant-channels.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,iGAAiG;AACjG,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,8DAA8D;AAC9D,MAAM,WAAW,kBAAkB;IACjC,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,2EAA2E;AAC3E,MAAM,MAAM,oBAAoB,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5F,oCAAoC;AACpC,MAAM,W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eAAe,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAc/E;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,qBAAqB,CAAC;IAClC,IAAI,EAAE,eAAe,CAAC;IACtB,QAAQ,EAAE,gBAAgB,EAAE,CAAC;CAC9B;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAwB;IACnD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAkB;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,OAAO,CAA+B;IAC9C,OAAO,CAAC,WAAW,CAA6B;gBAEpC,IAAI,EAAE,wBAAwB;IAW1C;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB3B,4CAA4C;IAC5C,cAAc,IAAI,MAAM,EAAE;IAI1B;;;;OAIG;IACG,MAAM,CAAC,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;IAiB5D;;;;OAIG;IACH,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAc7C;;;;;;;OAOG;YACW,aAAa;IAyB3B,6DAA6D;YAC/C,YAAY;IAW1B,oEAAoE;YACtD,SAAS;IAUvB,OAAO,CAAC,KAAK;CAcd"}
@@ -0,0 +1,270 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ /** Why a channel's `!` / `!!` message is refused (the pool's shell path is never reached). */
4
+ export const CHANNEL_SHELL_REFUSAL = 'shell commands ("!") cannot be run from a channel; ask the assistant instead';
5
+ /** The error `assistant_notify` answers when no channel can notify. */
6
+ export const NO_CHANNEL_ERROR = 'no notification channel is enabled on this server (turn on push notifications in the wherever settings on a device, or configure a channel such as Telegram)';
7
+ /**
8
+ * The text a channel message reaches the assistant as: its text, then one
9
+ * `[Uploaded file: <path>]` line per file, or, with no text of its own, an
10
+ * explicit "I have uploaded the following file(s) for you:" before them.
11
+ * EXACTLY what the web composer sends for an upload (`buildAttachmentMessage`
12
+ * in web/src/lib/core/attachments.ts; keep the two in step), so the agent reads
13
+ * a Telegram file as it reads a web one.
14
+ */
15
+ export function channelMessageText(text, files) {
16
+ const trimmed = text.trim();
17
+ const paths = (files ?? []).map((f) => f.path).filter((p) => typeof p === 'string' && p);
18
+ if (paths.length === 0)
19
+ return trimmed;
20
+ const fileLines = paths.map((p) => `[Uploaded file: ${p}]`).join('\n');
21
+ return trimmed ? `${trimmed}\n\n${fileLines}` : `I have uploaded the following file(s) for you:\n${fileLines}`;
22
+ }
23
+ /** Image extensions recognised for a channel file that carries no MIME type. */
24
+ const IMAGE_EXTENSION_MIME = {
25
+ '.jpg': 'image/jpeg',
26
+ '.jpeg': 'image/jpeg',
27
+ '.png': 'image/png',
28
+ '.gif': 'image/gif',
29
+ '.webp': 'image/webp',
30
+ };
31
+ /**
32
+ * The model IMAGE INPUTS of a channel message (task `pool-send-images`): every
33
+ * file whose MIME type is `image/*` (a Telegram photo, or an image sent as a
34
+ * document), or, with no MIME type, whose extension is a common image one,
35
+ * read from its saved path as base64. The file stays a path in the text as well
36
+ * (`channelMessageText`), so the agent can still open, move or attach it; pi
37
+ * converts or resizes what the model needs, and drops it with a note for a
38
+ * text-only model. A file that cannot be read is logged and left as a path only.
39
+ */
40
+ export async function channelImages(files) {
41
+ const out = [];
42
+ for (const f of files ?? []) {
43
+ if (typeof f?.path !== 'string' || !f.path)
44
+ continue;
45
+ const mimeType = f.mimeType
46
+ ? f.mimeType.toLowerCase().startsWith('image/')
47
+ ? f.mimeType
48
+ : null
49
+ : (IMAGE_EXTENSION_MIME[path.extname(f.path).toLowerCase()] ?? null);
50
+ if (!mimeType)
51
+ continue;
52
+ try {
53
+ const bytes = await fs.readFile(f.path);
54
+ out.push({ type: 'image', data: bytes.toString('base64'), mimeType });
55
+ }
56
+ catch (err) {
57
+ console.warn(`[wherever] assistant channel: could not read image ${f.path} (${errMessage(err)}); sending its path only`);
58
+ }
59
+ }
60
+ return out;
61
+ }
62
+ /** True when a routing destination belongs to `channel` (`telegram`, or `telegram:<sub>`). */
63
+ export function destinationIsChannel(destination, channel) {
64
+ return !!destination && (destination === channel || destination.startsWith(`${channel}:`));
65
+ }
66
+ /**
67
+ * Group dropped texts by their routing origin. `origins` is aligned with the
68
+ * texts (null = not known); a record without origins attributes nothing.
69
+ */
70
+ export function droppedByOrigin(dropped) {
71
+ const out = new Map();
72
+ const add = (texts, origins) => {
73
+ texts.forEach((text, i) => {
74
+ const origin = origins?.[i];
75
+ if (!origin)
76
+ return;
77
+ const list = out.get(origin) ?? [];
78
+ list.push(text);
79
+ out.set(origin, list);
80
+ });
81
+ };
82
+ add(dropped.steering, dropped.origins?.steering);
83
+ add(dropped.followUp, dropped.origins?.followUp);
84
+ return out;
85
+ }
86
+ export class ChannelDispatcher {
87
+ controller;
88
+ pool;
89
+ channels;
90
+ started = new Set();
91
+ unsubscribe = null;
92
+ constructor(opts) {
93
+ const names = new Set();
94
+ for (const c of opts.channels) {
95
+ if (names.has(c.name))
96
+ throw new Error(`two assistant channels are named "${c.name}"`);
97
+ names.add(c.name);
98
+ }
99
+ this.controller = opts.controller;
100
+ this.pool = opts.pool;
101
+ this.channels = [...opts.channels];
102
+ }
103
+ /**
104
+ * Start every channel (one that fails to start is logged and left out, so it
105
+ * never takes the others or the server down) and subscribe to the pool's
106
+ * event fan-out for replies.
107
+ */
108
+ async start() {
109
+ if (this.unsubscribe)
110
+ return;
111
+ this.unsubscribe = this.pool.subscribeEvents((file, event, destination) => this.route(file, event, destination));
112
+ for (const channel of this.channels) {
113
+ try {
114
+ await channel.start({
115
+ onUserMessage: (m, hooks) => this.onUserMessage(channel, m, hooks),
116
+ resetSession: () => this.resetSession(channel),
117
+ abortTurn: () => this.abortTurn(channel),
118
+ });
119
+ this.started.add(channel);
120
+ }
121
+ catch (err) {
122
+ console.error(`[wherever] assistant channel "${channel.name}" failed to start: ${errMessage(err)}`);
123
+ }
124
+ }
125
+ }
126
+ async stop() {
127
+ this.unsubscribe?.();
128
+ this.unsubscribe = null;
129
+ const running = [...this.started];
130
+ this.started.clear();
131
+ await Promise.all(running.map(async (c) => {
132
+ try {
133
+ await c.stop();
134
+ }
135
+ catch (err) {
136
+ console.error(`[wherever] assistant channel "${c.name}" failed to stop: ${errMessage(err)}`);
137
+ }
138
+ }));
139
+ }
140
+ /** The started channels that can notify. */
141
+ notifyChannels() {
142
+ return this.channels.filter((c) => this.started.has(c) && c.notify).map((c) => c.name);
143
+ }
144
+ /**
145
+ * Deliver to EVERY started channel that can notify, in parallel and at once.
146
+ * Ok when at least one delivered; with none able to notify, the clear
147
+ * `NO_CHANNEL_ERROR`.
148
+ */
149
+ async notify(n) {
150
+ const targets = this.channels.filter((c) => this.started.has(c) && c.notify);
151
+ if (targets.length === 0)
152
+ return { ok: false, error: NO_CHANNEL_ERROR, deliveries: [] };
153
+ const deliveries = await Promise.all(targets.map(async (c) => {
154
+ try {
155
+ return { channel: c.name, result: await c.notify(n) };
156
+ }
157
+ catch (err) {
158
+ return { channel: c.name, result: { ok: false, error: errMessage(err) } };
159
+ }
160
+ }));
161
+ if (deliveries.some((d) => d.result.ok))
162
+ return { ok: true, deliveries };
163
+ const why = deliveries.map((d) => `${d.channel}: ${d.result.ok ? 'ok' : d.result.error}`).join('; ');
164
+ return { ok: false, error: `the notification reached no device (${why})`, deliveries };
165
+ }
166
+ /**
167
+ * The controller's `onDropped`: report each dropped message to the channel of
168
+ * its routing origin. Messages from the web (`none`), the scheduler or no
169
+ * known origin are reported to nobody (the web shows the session itself).
170
+ */
171
+ reportDropped(dropped) {
172
+ const byOrigin = droppedByOrigin(dropped);
173
+ for (const channel of this.channels) {
174
+ if (!this.started.has(channel) || !channel.reportDropped)
175
+ continue;
176
+ const messages = [];
177
+ for (const [origin, texts] of byOrigin)
178
+ if (destinationIsChannel(origin, channel.name))
179
+ messages.push(...texts);
180
+ if (messages.length === 0)
181
+ continue;
182
+ const report = { sessionFile: dropped.sessionFile, reason: dropped.reason, messages, at: dropped.at };
183
+ void Promise.resolve()
184
+ .then(() => channel.reportDropped(report))
185
+ .catch((err) => console.error(`[wherever] assistant channel "${channel.name}" failed to report dropped messages: ${errMessage(err)}`));
186
+ }
187
+ }
188
+ /**
189
+ * A channel's inbound message: to the controller with origin = the channel.
190
+ * `!` / `!!` (the pool's shell path) is refused here for every channel, so no
191
+ * transport can run a shell command without an agent turn (story 16).
192
+ * Attached files (already saved by the channel) are written into the text
193
+ * as the web composer does (`channelMessageText`), and image files are also
194
+ * sent as model image inputs (`channelImages`).
195
+ */
196
+ async onUserMessage(channel, m, hooks) {
197
+ if (!this.started.has(channel))
198
+ return { accepted: false, reason: 'the channel is not running' };
199
+ const raw = typeof m.text === 'string' ? m.text : '';
200
+ const text = channelMessageText(raw, m.files);
201
+ if (!text)
202
+ return { accepted: false, reason: 'empty message' };
203
+ if (raw.trimStart().startsWith('!')) {
204
+ return { accepted: false, reason: CHANNEL_SHELL_REFUSAL };
205
+ }
206
+ // Always 'steer': pi only uses it when a turn is running (ADR 0003), and it
207
+ // keeps a message that races the start of a turn from being refused by pi
208
+ // ("already processing") instead of steering it.
209
+ const images = await channelImages(m.files);
210
+ await this.controller.send(m.files?.length ? text : raw, channel.name, 'steer', {
211
+ ...(images.length ? { images } : {}),
212
+ onDispatch: (d) => {
213
+ try {
214
+ hooks?.onDispatched?.({ steered: d.steered });
215
+ }
216
+ catch (err) {
217
+ console.error(`[wherever] assistant channel "${channel.name}" dispatch hook failed: ${errMessage(err)}`);
218
+ }
219
+ },
220
+ });
221
+ return { accepted: true };
222
+ }
223
+ /** A channel's `/new` / `/reset`: the controller's reset. */
224
+ async resetSession(channel) {
225
+ if (!this.started.has(channel))
226
+ return { ok: false, error: 'the channel is not running' };
227
+ if (!this.controller.reset)
228
+ return { ok: false, error: 'reset is not available' };
229
+ try {
230
+ await this.controller.reset();
231
+ return { ok: true };
232
+ }
233
+ catch (err) {
234
+ return { ok: false, error: errMessage(err) };
235
+ }
236
+ }
237
+ /** A channel's `stop`: abort the current session's running turn. */
238
+ async abortTurn(channel) {
239
+ if (!this.started.has(channel) || !this.controller.abortCurrent)
240
+ return { aborted: false };
241
+ try {
242
+ return { aborted: await this.controller.abortCurrent() };
243
+ }
244
+ catch (err) {
245
+ console.error(`[wherever] assistant channel "${channel.name}": stopping the turn failed: ${errMessage(err)}`);
246
+ return { aborted: false };
247
+ }
248
+ }
249
+ route(sessionFile, event, destination) {
250
+ if (!destination)
251
+ return;
252
+ for (const channel of this.channels) {
253
+ if (!channel.deliverReply || !this.started.has(channel) || !destinationIsChannel(destination, channel.name))
254
+ continue;
255
+ try {
256
+ const out = channel.deliverReply({ sessionFile, destination, event });
257
+ if (out && typeof out.then === 'function') {
258
+ out.catch((err) => console.error(`[wherever] assistant channel "${channel.name}" reply failed: ${errMessage(err)}`));
259
+ }
260
+ }
261
+ catch (err) {
262
+ console.error(`[wherever] assistant channel "${channel.name}" reply failed: ${errMessage(err)}`);
263
+ }
264
+ }
265
+ }
266
+ }
267
+ function errMessage(err) {
268
+ return err instanceof Error ? err.message : String(err);
269
+ }
270
+ //# sourceMappingURL=assistant-channels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assistant-channels.js","sourceRoot":"","sources":["../src/assistant-channels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAqJ7B,8FAA8F;AAC9F,MAAM,CAAC,MAAM,qBAAqB,GAAG,8EAA8E,CAAC;AAEpH,uEAAuE;AACvE,MAAM,CAAC,MAAM,gBAAgB,GAC3B,8JAA8J,CAAC;AAEjK;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,KAAgC;IAC/E,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,MAAM,KAAK,GAAG,CAAC,KAAK,IA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