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.
- package/CHANGELOG.md +20 -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 +207 -0
- package/dist/assistant-tools.d.ts.map +1 -0
- package/dist/assistant-tools.js +390 -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 +396 -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 +232 -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 +272 -0
- package/dist/telegram-channel.d.ts.map +1 -0
- package/dist/telegram-channel.js +701 -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 +94 -0
- package/dist/telegram-replies.d.ts.map +1 -0
- package/dist/telegram-replies.js +329 -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.BkzT3rFr.css +1 -0
- package/public/_app/immutable/chunks/CExVgK9Z.js +2 -0
- package/public/_app/immutable/chunks/CExVgK9Z.js.map +1 -0
- package/public/_app/immutable/chunks/CkOw6fRa.js +2 -0
- package/public/_app/immutable/chunks/{BQ9B_G4h.js.map → CkOw6fRa.js.map} +1 -1
- package/public/_app/immutable/chunks/DyHllYtq.js +2 -0
- package/public/_app/immutable/chunks/{BUONgvl4.js.map → DyHllYtq.js.map} +1 -1
- package/public/_app/immutable/entry/{app.BZO7Xckk.js → app.D3PEFbtP.js} +3 -3
- package/public/_app/immutable/entry/{app.BZO7Xckk.js.map → app.D3PEFbtP.js.map} +1 -1
- package/public/_app/immutable/entry/start.BR00Qps5.js +2 -0
- package/public/_app/immutable/entry/start.BR00Qps5.js.map +1 -0
- package/public/_app/immutable/nodes/{0.Czz2XmZU.js → 0.DG3L8hMN.js} +3 -3
- package/public/_app/immutable/nodes/{0.Czz2XmZU.js.map → 0.DG3L8hMN.js.map} +1 -1
- package/public/_app/immutable/nodes/{1.DDvrriUW.js → 1.BCpuoZxW.js} +2 -2
- package/public/_app/immutable/nodes/{1.DDvrriUW.js.map → 1.BCpuoZxW.js.map} +1 -1
- package/public/_app/immutable/nodes/2.D2auiZW1.js +122 -0
- package/public/_app/immutable/nodes/2.D2auiZW1.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,228 @@
|
|
|
1
|
+
import type { ImageContent } from '@earendil-works/pi-ai';
|
|
2
|
+
/**
|
|
3
|
+
* The assistant CONTROLLER (spec `assistant-session-and-channels`, ADRs 0014 to
|
|
4
|
+
* 0018): owns WHICH session is the current assistant session, and resets it.
|
|
5
|
+
*
|
|
6
|
+
* The session is disposable; the folder is the memory. So exactly one session in
|
|
7
|
+
* `assistantFolder` (never in `jobs/`) is CURRENT, recorded as a POINTER (a
|
|
8
|
+
* session file path) in the STATE dir (ADR 0006: server-written state never goes
|
|
9
|
+
* in the config dir). A reset makes a fresh session in the folder the pointer
|
|
10
|
+
* target.
|
|
11
|
+
*
|
|
12
|
+
* Exists only while the assistant is ACTIVE (configured AND this server holds the
|
|
13
|
+
* folder lock, see assistant-folder.ts). With `assistantFolder` unset no
|
|
14
|
+
* controller is built and no session-created callback is registered, so the pool
|
|
15
|
+
* behaves exactly as before.
|
|
16
|
+
*
|
|
17
|
+
* Every pointer transition (open, reset, a session created in the folder) runs
|
|
18
|
+
* through ONE serial queue. That is what makes the move idempotent and a reset
|
|
19
|
+
* abort exactly once: the controller's own creation also fires the pool's
|
|
20
|
+
* session-created callback, and by the time that callback's turn in the queue
|
|
21
|
+
* comes, the pointer already names the new session, so it is a no-op.
|
|
22
|
+
*/
|
|
23
|
+
/** Pointer file, at the root of the state dir (beside ADR 0015's `assistant-runs.jsonl`). */
|
|
24
|
+
export declare const ASSISTANT_POINTER_FILE = "assistant-session.json";
|
|
25
|
+
/**
|
|
26
|
+
* Where a message fed to the assistant came from (`telegram`, `schedule:<jobId>`,
|
|
27
|
+
* ...). `send` threads it into the pool, which records it in the session's
|
|
28
|
+
* per-user-message reply routing (ADR 0014, `reply-routing.ts`).
|
|
29
|
+
*/
|
|
30
|
+
export type AssistantOrigin = string;
|
|
31
|
+
/** The slice of `SessionPool` the controller drives (the seam the tests fake). */
|
|
32
|
+
export interface AssistantPoolPort {
|
|
33
|
+
createNewSession(cwd: string, modelStr?: string, gitInit?: boolean, createRemote?: boolean, repoVisibility?: 'private' | 'public', forceNew?: boolean): Promise<{
|
|
34
|
+
tracked: {
|
|
35
|
+
sessionId: string;
|
|
36
|
+
sessionFile: string;
|
|
37
|
+
cwd: string;
|
|
38
|
+
};
|
|
39
|
+
error?: string;
|
|
40
|
+
sessionFile?: string;
|
|
41
|
+
}>;
|
|
42
|
+
loadSession(sessionFile: string): Promise<{
|
|
43
|
+
tracked: {
|
|
44
|
+
sessionId: string;
|
|
45
|
+
sessionFile: string;
|
|
46
|
+
cwd: string;
|
|
47
|
+
};
|
|
48
|
+
error?: string;
|
|
49
|
+
}>;
|
|
50
|
+
getSession(sessionFile: string): {
|
|
51
|
+
sessionId: string;
|
|
52
|
+
sessionFile: string;
|
|
53
|
+
cwd: string;
|
|
54
|
+
} | null;
|
|
55
|
+
isStreaming(sessionFile: string): boolean;
|
|
56
|
+
abortSession(sessionFile: string): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Clear pi's steer + followUp queues, returning what was dropped; null when not
|
|
59
|
+
* resident / not readable (CLI). `origins`, when given, is each text's routing
|
|
60
|
+
* origin (aligned by index, null = unknown).
|
|
61
|
+
*/
|
|
62
|
+
clearQueuedMessages(sessionFile: string): {
|
|
63
|
+
steering: string[];
|
|
64
|
+
followUp: string[];
|
|
65
|
+
origins?: {
|
|
66
|
+
steering: Array<string | null>;
|
|
67
|
+
followUp: Array<string | null>;
|
|
68
|
+
};
|
|
69
|
+
} | null;
|
|
70
|
+
sendUserMessage(sessionFile: string, text: string, streamingBehavior?: 'steer' | 'followUp', conversationMode?: boolean, origin?: AssistantOrigin, images?: ImageContent[]): Promise<void>;
|
|
71
|
+
pinSession(sessionFile: string): void;
|
|
72
|
+
unpinSession(sessionFile: string): void;
|
|
73
|
+
}
|
|
74
|
+
/** Options of `AssistantController.send`. */
|
|
75
|
+
export interface AssistantSendOptions {
|
|
76
|
+
/**
|
|
77
|
+
* Called once the target session is known, right BEFORE the message is handed
|
|
78
|
+
* to the pool: `steered` is true when it goes into a running turn as a steer
|
|
79
|
+
* (ADR 0003), false when it starts one. A channel uses it to show the steer
|
|
80
|
+
* marker and to order its next message after this one, since the send itself
|
|
81
|
+
* resolves only when a started turn ends.
|
|
82
|
+
*/
|
|
83
|
+
onDispatch?: (d: {
|
|
84
|
+
sessionFile: string;
|
|
85
|
+
steered: boolean;
|
|
86
|
+
}) => void;
|
|
87
|
+
/**
|
|
88
|
+
* Model image inputs sent with the message (a channel's photos, task
|
|
89
|
+
* `pool-send-images`); handed to the pool send unchanged. Absent or empty =
|
|
90
|
+
* the text-only send.
|
|
91
|
+
*/
|
|
92
|
+
images?: ImageContent[];
|
|
93
|
+
}
|
|
94
|
+
/** What `GET /config`'s `assistant` gains from the controller. */
|
|
95
|
+
export interface AssistantPointerStatus {
|
|
96
|
+
currentSessionId: string | null;
|
|
97
|
+
currentSessionFile: string | null;
|
|
98
|
+
}
|
|
99
|
+
/** The current assistant session, as handed to a caller that opens it. */
|
|
100
|
+
export interface AssistantCurrentSession {
|
|
101
|
+
sessionFile: string;
|
|
102
|
+
sessionId: string;
|
|
103
|
+
cwd: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Messages pi still held queued (steer / followUp) on a session the controller
|
|
107
|
+
* retired. An abort leaves pi's queues populated (ADR 0014), so a reset clears
|
|
108
|
+
* them and RECORDS them here; the channel seam (`assistant-channels.ts`) reports them to
|
|
109
|
+
* the channels of their routing origins.
|
|
110
|
+
*/
|
|
111
|
+
export interface DroppedMessages {
|
|
112
|
+
sessionFile: string;
|
|
113
|
+
/** `reset`: the session was retired; `aborted`: its turn was aborted (the scheduler clears after an aborted settle). */
|
|
114
|
+
reason: 'reset' | 'aborted';
|
|
115
|
+
steering: string[];
|
|
116
|
+
followUp: string[];
|
|
117
|
+
/**
|
|
118
|
+
* The routing origin of each dropped text (ADR 0014), aligned by index with
|
|
119
|
+
* `steering` / `followUp`; null where unknown. The channel seam reports each
|
|
120
|
+
* message to the channel it came from (assistant-channels.ts).
|
|
121
|
+
*/
|
|
122
|
+
origins?: {
|
|
123
|
+
steering: Array<AssistantOrigin | null>;
|
|
124
|
+
followUp: Array<AssistantOrigin | null>;
|
|
125
|
+
};
|
|
126
|
+
at: string;
|
|
127
|
+
}
|
|
128
|
+
export interface AssistantControllerOptions {
|
|
129
|
+
pool: AssistantPoolPort;
|
|
130
|
+
/** The ACTIVE assistant folder (absolute). */
|
|
131
|
+
folder: string;
|
|
132
|
+
/** The wherever state dir (`getWhereverStateDir()`). */
|
|
133
|
+
stateDir: string;
|
|
134
|
+
/** Called after the pointer moved (the server rebroadcasts the status). */
|
|
135
|
+
onChange?: (status: AssistantPointerStatus) => void;
|
|
136
|
+
/** Called with each non-empty batch of dropped messages. */
|
|
137
|
+
onDropped?: (dropped: DroppedMessages) => void;
|
|
138
|
+
}
|
|
139
|
+
export declare class AssistantController {
|
|
140
|
+
private readonly pool;
|
|
141
|
+
private readonly folder;
|
|
142
|
+
private readonly pointerPath;
|
|
143
|
+
private readonly onChange?;
|
|
144
|
+
private readonly onDropped?;
|
|
145
|
+
private pointer;
|
|
146
|
+
private dropped;
|
|
147
|
+
private queue;
|
|
148
|
+
/**
|
|
149
|
+
* Sessions the controller created itself. Their session-created callback is
|
|
150
|
+
* queued BEHIND the operation that created them, so by its turn the pointer may
|
|
151
|
+
* already have moved on (e.g. `send` replacing a pointer it just created): it
|
|
152
|
+
* must never move the pointer back.
|
|
153
|
+
*/
|
|
154
|
+
private ownCreations;
|
|
155
|
+
constructor(opts: AssistantControllerOptions);
|
|
156
|
+
status(): AssistantPointerStatus;
|
|
157
|
+
/** Every batch of dropped messages recorded so far (bounded), oldest first. */
|
|
158
|
+
droppedMessages(): DroppedMessages[];
|
|
159
|
+
/** Resolves once every queued pointer transition has run (tests, shutdown). */
|
|
160
|
+
idle(): Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* The current assistant session, creating one (and pointing at it) when there
|
|
163
|
+
* is none. A pointer that is neither resident nor on disk is replaced: pi
|
|
164
|
+
* writes a session file only once the conversation starts, so an evicted or
|
|
165
|
+
* pre-restart pointer to a session nobody spoke in names nothing loadable.
|
|
166
|
+
*/
|
|
167
|
+
ensureCurrent(): Promise<AssistantCurrentSession>;
|
|
168
|
+
/**
|
|
169
|
+
* Reset: retire the current session (abort a running turn, then clear and
|
|
170
|
+
* record pi's queues), create a fresh session in the folder (forceNew, so a
|
|
171
|
+
* tab still viewing the old one does not hand it back), and point at it.
|
|
172
|
+
*/
|
|
173
|
+
reset(): Promise<AssistantCurrentSession>;
|
|
174
|
+
/**
|
|
175
|
+
* The pool's session-created callback. A session created IN the assistant
|
|
176
|
+
* folder itself (not `jobs/`, not anywhere else) becomes current; the session
|
|
177
|
+
* it replaces is retired like a reset. This is how a web `/new` / `/reset`
|
|
178
|
+
* (a forceNew `session_new`) in the assistant session becomes an assistant
|
|
179
|
+
* reset with no composer change. Idempotent: a session that is already the
|
|
180
|
+
* pointer (the controller's own creation) is a no-op.
|
|
181
|
+
*/
|
|
182
|
+
handleSessionCreated(sessionFile: string, cwd: string): Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Feed a message to the current assistant session (for the channels and the
|
|
185
|
+
* scheduler). Loads the pointer first: the pool's `sendUserMessage` silently
|
|
186
|
+
* no-ops on a session that is not resident (idle eviction, restart). Into a
|
|
187
|
+
* running turn the message STEERS, as the web composer does (ADR 0003).
|
|
188
|
+
* `origin` is recorded by the pool's reply routing (ADR 0014), so the reply
|
|
189
|
+
* to this message is attributed to it.
|
|
190
|
+
*/
|
|
191
|
+
send(text: string, origin: AssistantOrigin, streamingBehavior?: 'steer' | 'followUp', opts?: AssistantSendOptions): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Abort the CURRENT session's running turn (a channel's `stop`), leaving the
|
|
194
|
+
* pointer where it is (an abort is not a reset). False when there is no
|
|
195
|
+
* current session or nothing is running. What the abort leaves queued is
|
|
196
|
+
* cleared and reported by the aborted settle (`clearAfterAbort`, called by
|
|
197
|
+
* the scheduler), exactly as for a web stop.
|
|
198
|
+
*/
|
|
199
|
+
abortCurrent(): Promise<boolean>;
|
|
200
|
+
/**
|
|
201
|
+
* After an ABORTED settle of the CURRENT session (the scheduler calls this on
|
|
202
|
+
* `agent_settled` with `aborted: true`): pi still holds the queued steer /
|
|
203
|
+
* followUp messages an abort leaves behind (ADR 0014), so "settled with
|
|
204
|
+
* nothing queued", which inline jobs wait for, would never be reached again.
|
|
205
|
+
* Clear them and record what was dropped, exactly as a reset does (reported
|
|
206
|
+
* to the channels of their origins through `onDropped`, assistant-channels.ts). A no-op
|
|
207
|
+
* for any other session, and for a CLI-bridge session (whose queues the
|
|
208
|
+
* server cannot read or clear).
|
|
209
|
+
*/
|
|
210
|
+
clearAfterAbort(sessionFile: string): DroppedMessages | null;
|
|
211
|
+
private serial;
|
|
212
|
+
private ensureCurrentUnqueued;
|
|
213
|
+
private createAndPoint;
|
|
214
|
+
/** Abort the session's running turn, if any, then clear and record its queues. Never throws. */
|
|
215
|
+
private retire;
|
|
216
|
+
/** Clear pi's queues of a session and record what was dropped (null when nothing was). Never throws. */
|
|
217
|
+
private clearAndRecord;
|
|
218
|
+
private movePointer;
|
|
219
|
+
/**
|
|
220
|
+
* The pointer from the state dir, or null. A record written for a DIFFERENT
|
|
221
|
+
* assistant folder (the config changed across a restart) is ignored: its
|
|
222
|
+
* session lives in the old folder, and the pointer must name one in this one.
|
|
223
|
+
*/
|
|
224
|
+
private readPointer;
|
|
225
|
+
/** Atomic (tmp + rename), like drafts and stars. A failure is logged; the in-memory pointer still holds. */
|
|
226
|
+
private writePointer;
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=assistant-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assistant-controller.d.ts","sourceRoot":"","sources":["../src/assistant-controller.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,6FAA6F;AAC7F,eAAO,MAAM,sBAAsB,2BAA2B,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC,kFAAkF;AAClF,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,CACd,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,OAAO,EACjB,YAAY,CAAC,EAAE,OAAO,EACtB,cAAc,CAAC,EAAE,SAAS,GAAG,QAAQ,EACrC,QAAQ,CAAC,EAAE,OAAO,GACjB,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IAOtC;;;;;;;;;OASG;IACH,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI;IAO5D,OAAO,CAAC,MAAM;YAMA,qBAAqB;YAUrB,cAAc;IAa5B,gGAAgG;YAClF,MAAM;IASpB,wGAAwG;IACxG,OAAO,CAAC,cAAc;IA+BtB,OAAO,CAAC,WAAW;IAcnB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAkBnB,4GAA4G;IAC5G,OAAO,CAAC,YAAY;CAqBrB"}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* The assistant CONTROLLER (spec `assistant-session-and-channels`, ADRs 0014 to
|
|
5
|
+
* 0018): owns WHICH session is the current assistant session, and resets it.
|
|
6
|
+
*
|
|
7
|
+
* The session is disposable; the folder is the memory. So exactly one session in
|
|
8
|
+
* `assistantFolder` (never in `jobs/`) is CURRENT, recorded as a POINTER (a
|
|
9
|
+
* session file path) in the STATE dir (ADR 0006: server-written state never goes
|
|
10
|
+
* in the config dir). A reset makes a fresh session in the folder the pointer
|
|
11
|
+
* target.
|
|
12
|
+
*
|
|
13
|
+
* Exists only while the assistant is ACTIVE (configured AND this server holds the
|
|
14
|
+
* folder lock, see assistant-folder.ts). With `assistantFolder` unset no
|
|
15
|
+
* controller is built and no session-created callback is registered, so the pool
|
|
16
|
+
* behaves exactly as before.
|
|
17
|
+
*
|
|
18
|
+
* Every pointer transition (open, reset, a session created in the folder) runs
|
|
19
|
+
* through ONE serial queue. That is what makes the move idempotent and a reset
|
|
20
|
+
* abort exactly once: the controller's own creation also fires the pool's
|
|
21
|
+
* session-created callback, and by the time that callback's turn in the queue
|
|
22
|
+
* comes, the pointer already names the new session, so it is a no-op.
|
|
23
|
+
*/
|
|
24
|
+
/** Pointer file, at the root of the state dir (beside ADR 0015's `assistant-runs.jsonl`). */
|
|
25
|
+
export const ASSISTANT_POINTER_FILE = 'assistant-session.json';
|
|
26
|
+
/** Bound on the in-memory dropped-message record (it is reported, not archived). */
|
|
27
|
+
const DROPPED_KEEP = 50;
|
|
28
|
+
export class AssistantController {
|
|
29
|
+
pool;
|
|
30
|
+
folder;
|
|
31
|
+
pointerPath;
|
|
32
|
+
onChange;
|
|
33
|
+
onDropped;
|
|
34
|
+
pointer;
|
|
35
|
+
dropped = [];
|
|
36
|
+
queue = Promise.resolve();
|
|
37
|
+
/**
|
|
38
|
+
* Sessions the controller created itself. Their session-created callback is
|
|
39
|
+
* queued BEHIND the operation that created them, so by its turn the pointer may
|
|
40
|
+
* already have moved on (e.g. `send` replacing a pointer it just created): it
|
|
41
|
+
* must never move the pointer back.
|
|
42
|
+
*/
|
|
43
|
+
ownCreations = new Set();
|
|
44
|
+
constructor(opts) {
|
|
45
|
+
this.pool = opts.pool;
|
|
46
|
+
this.folder = path.resolve(opts.folder);
|
|
47
|
+
this.pointerPath = path.join(opts.stateDir, ASSISTANT_POINTER_FILE);
|
|
48
|
+
this.onChange = opts.onChange;
|
|
49
|
+
this.onDropped = opts.onDropped;
|
|
50
|
+
this.pointer = this.readPointer();
|
|
51
|
+
if (this.pointer)
|
|
52
|
+
this.pool.pinSession(this.pointer.sessionFile);
|
|
53
|
+
}
|
|
54
|
+
status() {
|
|
55
|
+
return {
|
|
56
|
+
currentSessionId: this.pointer?.sessionId ?? null,
|
|
57
|
+
currentSessionFile: this.pointer?.sessionFile ?? null,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Every batch of dropped messages recorded so far (bounded), oldest first. */
|
|
61
|
+
droppedMessages() {
|
|
62
|
+
return [...this.dropped];
|
|
63
|
+
}
|
|
64
|
+
/** Resolves once every queued pointer transition has run (tests, shutdown). */
|
|
65
|
+
idle() {
|
|
66
|
+
return this.queue.then(() => { }, () => { });
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The current assistant session, creating one (and pointing at it) when there
|
|
70
|
+
* is none. A pointer that is neither resident nor on disk is replaced: pi
|
|
71
|
+
* writes a session file only once the conversation starts, so an evicted or
|
|
72
|
+
* pre-restart pointer to a session nobody spoke in names nothing loadable.
|
|
73
|
+
*/
|
|
74
|
+
ensureCurrent() {
|
|
75
|
+
return this.serial(() => this.ensureCurrentUnqueued());
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Reset: retire the current session (abort a running turn, then clear and
|
|
79
|
+
* record pi's queues), create a fresh session in the folder (forceNew, so a
|
|
80
|
+
* tab still viewing the old one does not hand it back), and point at it.
|
|
81
|
+
*/
|
|
82
|
+
reset() {
|
|
83
|
+
return this.serial(async () => {
|
|
84
|
+
if (this.pointer)
|
|
85
|
+
await this.retire(this.pointer.sessionFile);
|
|
86
|
+
return this.createAndPoint();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The pool's session-created callback. A session created IN the assistant
|
|
91
|
+
* folder itself (not `jobs/`, not anywhere else) becomes current; the session
|
|
92
|
+
* it replaces is retired like a reset. This is how a web `/new` / `/reset`
|
|
93
|
+
* (a forceNew `session_new`) in the assistant session becomes an assistant
|
|
94
|
+
* reset with no composer change. Idempotent: a session that is already the
|
|
95
|
+
* pointer (the controller's own creation) is a no-op.
|
|
96
|
+
*/
|
|
97
|
+
handleSessionCreated(sessionFile, cwd) {
|
|
98
|
+
if (path.resolve(cwd) !== this.folder)
|
|
99
|
+
return Promise.resolve();
|
|
100
|
+
return this.serial(async () => {
|
|
101
|
+
if (this.ownCreations.delete(sessionFile))
|
|
102
|
+
return;
|
|
103
|
+
if (this.pointer?.sessionFile === sessionFile)
|
|
104
|
+
return;
|
|
105
|
+
if (this.pointer)
|
|
106
|
+
await this.retire(this.pointer.sessionFile);
|
|
107
|
+
const sessionId = this.pool.getSession(sessionFile)?.sessionId ?? '';
|
|
108
|
+
this.movePointer(sessionFile, sessionId);
|
|
109
|
+
}).catch((err) => {
|
|
110
|
+
console.error(`[wherever] assistant: could not adopt new session ${sessionFile}: ${errMessage(err)}`);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Feed a message to the current assistant session (for the channels and the
|
|
115
|
+
* scheduler). Loads the pointer first: the pool's `sendUserMessage` silently
|
|
116
|
+
* no-ops on a session that is not resident (idle eviction, restart). Into a
|
|
117
|
+
* running turn the message STEERS, as the web composer does (ADR 0003).
|
|
118
|
+
* `origin` is recorded by the pool's reply routing (ADR 0014), so the reply
|
|
119
|
+
* to this message is attributed to it.
|
|
120
|
+
*/
|
|
121
|
+
async send(text, origin, streamingBehavior, opts) {
|
|
122
|
+
const cur = await this.serial(async () => {
|
|
123
|
+
const c = await this.ensureCurrentUnqueued();
|
|
124
|
+
const loaded = await this.pool.loadSession(c.sessionFile);
|
|
125
|
+
if (!loaded.error)
|
|
126
|
+
return c;
|
|
127
|
+
// The file vanished between the check and the load: start afresh.
|
|
128
|
+
return this.createAndPoint();
|
|
129
|
+
});
|
|
130
|
+
const streaming = this.pool.isStreaming(cur.sessionFile);
|
|
131
|
+
const behavior = streamingBehavior ?? (streaming ? 'steer' : undefined);
|
|
132
|
+
try {
|
|
133
|
+
opts?.onDispatch?.({ sessionFile: cur.sessionFile, steered: streaming && behavior === 'steer' });
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
console.error(`[wherever] assistant: onDispatch failed: ${errMessage(err)}`);
|
|
137
|
+
}
|
|
138
|
+
await this.pool.sendUserMessage(cur.sessionFile, text, behavior, false, origin, opts?.images);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Abort the CURRENT session's running turn (a channel's `stop`), leaving the
|
|
142
|
+
* pointer where it is (an abort is not a reset). False when there is no
|
|
143
|
+
* current session or nothing is running. What the abort leaves queued is
|
|
144
|
+
* cleared and reported by the aborted settle (`clearAfterAbort`, called by
|
|
145
|
+
* the scheduler), exactly as for a web stop.
|
|
146
|
+
*/
|
|
147
|
+
async abortCurrent() {
|
|
148
|
+
const file = this.pointer?.sessionFile;
|
|
149
|
+
if (!file || !this.pool.isStreaming(file))
|
|
150
|
+
return false;
|
|
151
|
+
await this.pool.abortSession(file);
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* After an ABORTED settle of the CURRENT session (the scheduler calls this on
|
|
156
|
+
* `agent_settled` with `aborted: true`): pi still holds the queued steer /
|
|
157
|
+
* followUp messages an abort leaves behind (ADR 0014), so "settled with
|
|
158
|
+
* nothing queued", which inline jobs wait for, would never be reached again.
|
|
159
|
+
* Clear them and record what was dropped, exactly as a reset does (reported
|
|
160
|
+
* to the channels of their origins through `onDropped`, assistant-channels.ts). A no-op
|
|
161
|
+
* for any other session, and for a CLI-bridge session (whose queues the
|
|
162
|
+
* server cannot read or clear).
|
|
163
|
+
*/
|
|
164
|
+
clearAfterAbort(sessionFile) {
|
|
165
|
+
if (this.pointer?.sessionFile !== sessionFile)
|
|
166
|
+
return null;
|
|
167
|
+
return this.clearAndRecord(sessionFile, 'aborted');
|
|
168
|
+
}
|
|
169
|
+
// -------------------------------------------------------------------------
|
|
170
|
+
serial(fn) {
|
|
171
|
+
const run = this.queue.then(fn, fn);
|
|
172
|
+
this.queue = run.catch(() => { });
|
|
173
|
+
return run;
|
|
174
|
+
}
|
|
175
|
+
async ensureCurrentUnqueued() {
|
|
176
|
+
if (this.pointer) {
|
|
177
|
+
const file = this.pointer.sessionFile;
|
|
178
|
+
const resident = this.pool.getSession(file);
|
|
179
|
+
if (resident)
|
|
180
|
+
return { sessionFile: file, sessionId: resident.sessionId, cwd: resident.cwd };
|
|
181
|
+
if (fs.existsSync(file))
|
|
182
|
+
return { sessionFile: file, sessionId: this.pointer.sessionId, cwd: this.folder };
|
|
183
|
+
}
|
|
184
|
+
return this.createAndPoint();
|
|
185
|
+
}
|
|
186
|
+
async createAndPoint() {
|
|
187
|
+
const result = await this.pool.createNewSession(this.folder, undefined, undefined, undefined, undefined, true);
|
|
188
|
+
if (result.error || !result.tracked) {
|
|
189
|
+
throw new Error(result.error || 'could not create the assistant session');
|
|
190
|
+
}
|
|
191
|
+
const { sessionFile, sessionId, cwd } = result.tracked;
|
|
192
|
+
this.ownCreations.add(sessionFile);
|
|
193
|
+
// Bounded backstop, should a pool ever not call back for a creation.
|
|
194
|
+
if (this.ownCreations.size > 100)
|
|
195
|
+
this.ownCreations.delete(this.ownCreations.values().next().value);
|
|
196
|
+
this.movePointer(sessionFile, sessionId);
|
|
197
|
+
return { sessionFile, sessionId, cwd };
|
|
198
|
+
}
|
|
199
|
+
/** Abort the session's running turn, if any, then clear and record its queues. Never throws. */
|
|
200
|
+
async retire(sessionFile) {
|
|
201
|
+
try {
|
|
202
|
+
if (this.pool.isStreaming(sessionFile))
|
|
203
|
+
await this.pool.abortSession(sessionFile);
|
|
204
|
+
}
|
|
205
|
+
catch (err) {
|
|
206
|
+
console.error(`[wherever] assistant: abort of ${sessionFile} on reset failed: ${errMessage(err)}`);
|
|
207
|
+
}
|
|
208
|
+
this.clearAndRecord(sessionFile, 'reset');
|
|
209
|
+
}
|
|
210
|
+
/** Clear pi's queues of a session and record what was dropped (null when nothing was). Never throws. */
|
|
211
|
+
clearAndRecord(sessionFile, reason) {
|
|
212
|
+
let cleared = null;
|
|
213
|
+
try {
|
|
214
|
+
cleared = this.pool.clearQueuedMessages(sessionFile);
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
console.error(`[wherever] assistant: clearing the queue of ${sessionFile} (${reason}) failed: ${errMessage(err)}`);
|
|
218
|
+
}
|
|
219
|
+
if (!cleared || (cleared.steering.length === 0 && cleared.followUp.length === 0))
|
|
220
|
+
return null;
|
|
221
|
+
const record = {
|
|
222
|
+
sessionFile,
|
|
223
|
+
reason,
|
|
224
|
+
steering: [...cleared.steering],
|
|
225
|
+
followUp: [...cleared.followUp],
|
|
226
|
+
...(cleared.origins
|
|
227
|
+
? { origins: { steering: [...cleared.origins.steering], followUp: [...cleared.origins.followUp] } }
|
|
228
|
+
: {}),
|
|
229
|
+
at: new Date().toISOString(),
|
|
230
|
+
};
|
|
231
|
+
this.dropped.push(record);
|
|
232
|
+
if (this.dropped.length > DROPPED_KEEP)
|
|
233
|
+
this.dropped.splice(0, this.dropped.length - DROPPED_KEEP);
|
|
234
|
+
console.log(`[wherever] assistant ${reason === 'reset' ? 'reset' : 'aborted turn'} dropped ${record.steering.length + record.followUp.length} queued message(s) of ${sessionFile}`);
|
|
235
|
+
try {
|
|
236
|
+
this.onDropped?.(record);
|
|
237
|
+
}
|
|
238
|
+
catch (err) {
|
|
239
|
+
console.error(`[wherever] assistant: onDropped failed: ${errMessage(err)}`);
|
|
240
|
+
}
|
|
241
|
+
return record;
|
|
242
|
+
}
|
|
243
|
+
movePointer(sessionFile, sessionId) {
|
|
244
|
+
const previous = this.pointer?.sessionFile;
|
|
245
|
+
if (previous === sessionFile && this.pointer?.sessionId === sessionId)
|
|
246
|
+
return;
|
|
247
|
+
if (previous && previous !== sessionFile)
|
|
248
|
+
this.pool.unpinSession(previous);
|
|
249
|
+
this.pointer = { sessionFile, sessionId };
|
|
250
|
+
this.pool.pinSession(sessionFile);
|
|
251
|
+
this.writePointer();
|
|
252
|
+
try {
|
|
253
|
+
this.onChange?.(this.status());
|
|
254
|
+
}
|
|
255
|
+
catch (err) {
|
|
256
|
+
console.error(`[wherever] assistant: onChange failed: ${errMessage(err)}`);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The pointer from the state dir, or null. A record written for a DIFFERENT
|
|
261
|
+
* assistant folder (the config changed across a restart) is ignored: its
|
|
262
|
+
* session lives in the old folder, and the pointer must name one in this one.
|
|
263
|
+
*/
|
|
264
|
+
readPointer() {
|
|
265
|
+
let raw;
|
|
266
|
+
try {
|
|
267
|
+
raw = fs.readFileSync(this.pointerPath, 'utf8');
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
const rec = JSON.parse(raw);
|
|
274
|
+
if (typeof rec.sessionFile !== 'string' || typeof rec.folder !== 'string')
|
|
275
|
+
return null;
|
|
276
|
+
if (path.resolve(rec.folder) !== this.folder)
|
|
277
|
+
return null;
|
|
278
|
+
return { sessionFile: rec.sessionFile, sessionId: typeof rec.sessionId === 'string' ? rec.sessionId : '' };
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
console.warn(`[wherever] assistant: ignoring an unreadable pointer at ${this.pointerPath}`);
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/** Atomic (tmp + rename), like drafts and stars. A failure is logged; the in-memory pointer still holds. */
|
|
286
|
+
writePointer() {
|
|
287
|
+
if (!this.pointer)
|
|
288
|
+
return;
|
|
289
|
+
const rec = {
|
|
290
|
+
folder: this.folder,
|
|
291
|
+
sessionFile: this.pointer.sessionFile,
|
|
292
|
+
sessionId: this.pointer.sessionId,
|
|
293
|
+
updatedAt: new Date().toISOString(),
|
|
294
|
+
};
|
|
295
|
+
const dir = path.dirname(this.pointerPath);
|
|
296
|
+
const tmp = path.join(dir, `.${ASSISTANT_POINTER_FILE}.${process.pid}.tmp`);
|
|
297
|
+
try {
|
|
298
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
299
|
+
fs.writeFileSync(tmp, JSON.stringify(rec, null, 2) + '\n', 'utf8');
|
|
300
|
+
fs.renameSync(tmp, this.pointerPath);
|
|
301
|
+
}
|
|
302
|
+
catch (err) {
|
|
303
|
+
console.error(`[wherever] assistant: could not write the pointer to ${this.pointerPath}: ${errMessage(err)}`);
|
|
304
|
+
try {
|
|
305
|
+
fs.rmSync(tmp, { force: true });
|
|
306
|
+
}
|
|
307
|
+
catch { }
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function errMessage(err) {
|
|
312
|
+
return err instanceof Error ? err.message : String(err);
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=assistant-controller.js.map
|
|
@@ -0,0 +1 @@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session-and-channels`,
|
|
3
|
+
* ADR 0015): a minimal 5-field cron parser, next/previous occurrence in an IANA
|
|
4
|
+
* timezone, and the `at` (one-shot) parser. Pure: no clock, no timers, no I/O.
|
|
5
|
+
*
|
|
6
|
+
* WHY a hand-written parser, not a cron library (decision, recorded here): a
|
|
7
|
+
* new runtime dependency changes `pnpm-lock.yaml` and therefore the Nix
|
|
8
|
+
* `pnpmDepsHash` every consumer build checks (ADR 0008), for ~200 lines of
|
|
9
|
+
* well-understood code. And the timezone semantics the scheduler needs are its
|
|
10
|
+
* own anyway: the zone is supplied per evaluation (a follows-the-user job is
|
|
11
|
+
* re-evaluated in the user's CURRENT zone, which changes when they travel), and
|
|
12
|
+
* the DST rules below are chosen so the local-to-instant mapping is MONOTONE,
|
|
13
|
+
* which is what lets the search stop at the first candidate. Alternatives
|
|
14
|
+
* considered: `croner` (zero-dep, timezone-aware, maintained) and `cron-parser`
|
|
15
|
+
* (pulls in luxon). Revisit if the syntax ever needs more than the 5 fields.
|
|
16
|
+
*
|
|
17
|
+
* Syntax: `minute hour day-of-month month day-of-week`, each field a comma list
|
|
18
|
+
* of `*`, `n`, `a-b`, optionally with `/step` (`*\/15`, `1-30/2`, `5/10`).
|
|
19
|
+
* Months and weekdays accept three-letter English names; weekday 0 and 7 are
|
|
20
|
+
* Sunday. Macros: `@yearly` / `@annually`, `@monthly`, `@weekly`, `@daily` /
|
|
21
|
+
* `@midnight`, `@hourly`. Day-of-month and day-of-week follow Vixie cron: when
|
|
22
|
+
* BOTH are restricted (neither starts with `*`) a day matches if EITHER does,
|
|
23
|
+
* otherwise both must match.
|
|
24
|
+
*
|
|
25
|
+
* DST (decision): a local time that does not exist (the spring-forward gap)
|
|
26
|
+
* fires at the instant the gap ends, once; a local time that occurs twice (the
|
|
27
|
+
* fall-back overlap) fires at its FIRST occurrence only. So "30 2 * * *" still
|
|
28
|
+
* runs on the spring-forward day (at 03:00 local), and nothing runs twice on the
|
|
29
|
+
* fall-back day. The cost: a sub-hourly job does not repeat during the repeated
|
|
30
|
+
* hour. Alternative: Temporal's "compatible" (shift a gap time forward by the
|
|
31
|
+
* gap length), rejected because it is not monotone (02:30 would map AFTER 03:00).
|
|
32
|
+
*/
|
|
33
|
+
export declare class CronParseError extends Error {
|
|
34
|
+
constructor(message: string);
|
|
35
|
+
}
|
|
36
|
+
export interface CronSpec {
|
|
37
|
+
readonly source: string;
|
|
38
|
+
readonly minutes: readonly boolean[];
|
|
39
|
+
readonly hours: readonly boolean[];
|
|
40
|
+
readonly daysOfMonth: readonly boolean[];
|
|
41
|
+
readonly months: readonly boolean[];
|
|
42
|
+
readonly daysOfWeek: readonly boolean[];
|
|
43
|
+
/** Vixie rule: day-of-month and day-of-week are OR-ed only when both are restricted. */
|
|
44
|
+
readonly dayOr: boolean;
|
|
45
|
+
}
|
|
46
|
+
/** Parse a 5-field cron expression (or a macro). Throws `CronParseError`. */
|
|
47
|
+
export declare function parseCron(expr: string): CronSpec;
|
|
48
|
+
/** True when `tz` is an IANA zone name this runtime knows (e.g. `Europe/Paris`, `UTC`). */
|
|
49
|
+
export declare function isValidTimeZone(tz: unknown): tz is string;
|
|
50
|
+
/** The system timezone (what a fresh server assumes the user is in). */
|
|
51
|
+
export declare function systemTimeZone(): string;
|
|
52
|
+
export interface WallClock {
|
|
53
|
+
year: number;
|
|
54
|
+
month: number;
|
|
55
|
+
day: number;
|
|
56
|
+
hour: number;
|
|
57
|
+
minute: number;
|
|
58
|
+
second: number;
|
|
59
|
+
}
|
|
60
|
+
/** The wall-clock time in `tz` at instant `ms`. */
|
|
61
|
+
export declare function wallClock(tz: string, ms: number): WallClock;
|
|
62
|
+
/**
|
|
63
|
+
* The instant at which `tz` shows the given local time. An overlap (fall-back)
|
|
64
|
+
* resolves to the EARLIER instant; a gap (spring-forward) resolves to the
|
|
65
|
+
* instant the gap ends. See the module JSDoc.
|
|
66
|
+
*/
|
|
67
|
+
export declare function zonedToUtc(tz: string, year: number, month: number, day: number, hour: number, minute: number, second?: number): number;
|
|
68
|
+
/** The first occurrence STRICTLY after `afterMs`, evaluated in `tz`; null when none within the search horizon. */
|
|
69
|
+
export declare function nextCronRun(spec: CronSpec, tz: string, afterMs: number): number | null;
|
|
70
|
+
/** The last occurrence at or before `atOrBeforeMs`, evaluated in `tz`; null when none within the search horizon. */
|
|
71
|
+
export declare function prevCronRun(spec: CronSpec, tz: string, atOrBeforeMs: number): number | null;
|
|
72
|
+
export interface ParsedAt {
|
|
73
|
+
year: number;
|
|
74
|
+
month: number;
|
|
75
|
+
day: number;
|
|
76
|
+
hour: number;
|
|
77
|
+
minute: number;
|
|
78
|
+
second: number;
|
|
79
|
+
millisecond: number;
|
|
80
|
+
/** Explicit UTC offset in ms, or null when the string carries none (read in the job's timezone). */
|
|
81
|
+
offsetMs: number | null;
|
|
82
|
+
}
|
|
83
|
+
/** Parse an ISO 8601 date-time (`at`). Null when malformed. `"now"` is NOT handled here. */
|
|
84
|
+
export declare function parseAtString(at: string): ParsedAt | null;
|
|
85
|
+
/** The instant an `at` names: its own offset when it carries one, else read as local time in `tz`. */
|
|
86
|
+
export declare function atToInstant(at: ParsedAt, tz: string): number;
|
|
87
|
+
//# sourceMappingURL=assistant-cron.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assistant-cron.d.ts","sourceRoot":"","sources":["../src/assistant-cron.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,CAAC;IACrC,QAAQ,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,SAAS,OAAO,EAAE,CAAC;IACzC,QAAQ,CAAC,MAAM,E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