@songsid/agend 2.4.0-beta.16 → 2.4.0-beta.18
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/dist/auth-api.js +2 -0
- package/dist/auth-api.js.map +1 -1
- package/dist/backend/claude-code.d.ts +10 -1
- package/dist/backend/claude-code.js +7 -2
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/claude-transcript-errors.d.ts +4 -0
- package/dist/backend/claude-transcript-errors.js +5 -1
- package/dist/backend/claude-transcript-errors.js.map +1 -1
- package/dist/backend/types.d.ts +6 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/claude-credential-launch.d.ts +1 -0
- package/dist/claude-credential-launch.js +13 -2
- package/dist/claude-credential-launch.js.map +1 -1
- package/dist/claude-credential-vault.d.ts +7 -1
- package/dist/claude-credential-vault.js +26 -1
- package/dist/claude-credential-vault.js.map +1 -1
- package/dist/claude-request-observation.d.ts +7 -0
- package/dist/claude-request-observation.js +26 -0
- package/dist/claude-request-observation.js.map +1 -0
- package/dist/cli-audited.js +11 -8
- package/dist/cli-audited.js.map +1 -1
- package/dist/daemon.d.ts +8 -0
- package/dist/daemon.js +68 -13
- package/dist/daemon.js.map +1 -1
- package/dist/fleet-context.d.ts +1 -0
- package/dist/fleet-manager.d.ts +28 -0
- package/dist/fleet-manager.js +222 -10
- package/dist/fleet-manager.js.map +1 -1
- package/dist/fleet-windows-runtime.d.ts +1 -1
- package/dist/fleet-windows-runtime.js +1 -1
- package/dist/fleet-windows-runtime.js.map +1 -1
- package/dist/fleet-yaml-stringify.d.ts +3 -0
- package/dist/fleet-yaml-stringify.js +79 -0
- package/dist/fleet-yaml-stringify.js.map +1 -0
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +17 -3
- package/dist/host-monitoring-alert-policy.d.ts +71 -0
- package/dist/host-monitoring-alert-policy.js +150 -0
- package/dist/host-monitoring-alert-policy.js.map +1 -0
- package/dist/host-monitoring-alert-resources.d.ts +11 -0
- package/dist/host-monitoring-alert-resources.js +16 -0
- package/dist/host-monitoring-alert-resources.js.map +1 -0
- package/dist/host-monitoring-alert-settings.d.ts +14 -0
- package/dist/host-monitoring-alert-settings.js +63 -0
- package/dist/host-monitoring-alert-settings.js.map +1 -0
- package/dist/host-monitoring-alert-store.d.ts +49 -0
- package/dist/host-monitoring-alert-store.js +228 -0
- package/dist/host-monitoring-alert-store.js.map +1 -0
- package/dist/host-monitoring-alert-text.d.ts +7 -0
- package/dist/host-monitoring-alert-text.js +10 -0
- package/dist/host-monitoring-alert-text.js.map +1 -0
- package/dist/host-monitoring-alerts.d.ts +76 -0
- package/dist/host-monitoring-alerts.js +261 -0
- package/dist/host-monitoring-alerts.js.map +1 -0
- package/dist/host-monitoring-config.d.ts +2 -1
- package/dist/host-monitoring-config.js +8 -3
- package/dist/host-monitoring-config.js.map +1 -1
- package/dist/host-monitoring-footprint-policy.d.ts +45 -0
- package/dist/host-monitoring-footprint-policy.js +150 -0
- package/dist/host-monitoring-footprint-policy.js.map +1 -0
- package/dist/host-monitoring-footprint.d.ts +42 -0
- package/dist/host-monitoring-footprint.js +169 -0
- package/dist/host-monitoring-footprint.js.map +1 -0
- package/dist/host-monitoring-history-files.d.ts +2 -0
- package/dist/host-monitoring-history-files.js +16 -0
- package/dist/host-monitoring-history-files.js.map +1 -0
- package/dist/host-monitoring-history-policy.d.ts +57 -0
- package/dist/host-monitoring-history-policy.js +107 -0
- package/dist/host-monitoring-history-policy.js.map +1 -0
- package/dist/host-monitoring-history-store.d.ts +52 -0
- package/dist/host-monitoring-history-store.js +178 -0
- package/dist/host-monitoring-history-store.js.map +1 -0
- package/dist/host-monitoring-history-worker.d.ts +1 -0
- package/dist/host-monitoring-history-worker.js +66 -0
- package/dist/host-monitoring-history-worker.js.map +1 -0
- package/dist/host-monitoring-history.d.ts +80 -0
- package/dist/host-monitoring-history.js +301 -0
- package/dist/host-monitoring-history.js.map +1 -0
- package/dist/host-monitoring-platform.d.ts +73 -0
- package/dist/host-monitoring-platform.js +273 -0
- package/dist/host-monitoring-platform.js.map +1 -0
- package/dist/host-monitoring-process-identity.d.ts +8 -0
- package/dist/host-monitoring-process-identity.js +81 -0
- package/dist/host-monitoring-process-identity.js.map +1 -0
- package/dist/host-monitoring-runtime.d.ts +42 -0
- package/dist/host-monitoring-runtime.js +95 -0
- package/dist/host-monitoring-runtime.js.map +1 -0
- package/dist/host-monitoring-settings-store.d.ts +5 -0
- package/dist/host-monitoring-settings-store.js +49 -0
- package/dist/host-monitoring-settings-store.js.map +1 -0
- package/dist/host-monitoring.d.ts +108 -0
- package/dist/host-monitoring.js +157 -0
- package/dist/host-monitoring.js.map +1 -0
- package/dist/instance-lifecycle.js +2 -2
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/needs-you-hub.d.ts +1 -0
- package/dist/needs-you-hub.js +1 -0
- package/dist/needs-you-hub.js.map +1 -1
- package/dist/needs-you.d.ts +3 -2
- package/dist/needs-you.js +1 -0
- package/dist/needs-you.js.map +1 -1
- package/dist/public-web-gateway.js +11 -1
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/runtime-cli-install.js +17 -16
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/settings-api.d.ts +5 -0
- package/dist/settings-api.js +70 -7
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-baseline.d.ts +1 -0
- package/dist/settings-baseline.js +6 -4
- package/dist/settings-baseline.js.map +1 -1
- package/dist/settings-change.js +8 -0
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-effect.d.ts +4 -0
- package/dist/settings-effect.js +25 -4
- package/dist/settings-effect.js.map +1 -1
- package/dist/topic-commands.js +4 -0
- package/dist/topic-commands.js.map +1 -1
- package/dist/transcript-monitor.d.ts +1 -0
- package/dist/transcript-monitor.js +18 -0
- package/dist/transcript-monitor.js.map +1 -1
- package/dist/ui/accounts-view.js +7 -5
- package/dist/ui/chat-store.js +21 -4
- package/dist/ui/claude-credentials.js +12 -1
- package/dist/ui/fleet-office-pack.js +2 -2
- package/dist/ui/fleet-office-play.js +142 -3
- package/dist/ui/fleet-office-skin.js +67 -2
- package/dist/ui/fleet-office-store.js +41 -0
- package/dist/ui/fleet-office-zones.js +15 -8
- package/dist/ui/fleet-office.js +126 -21
- package/dist/ui/host-alerts.js +23 -0
- package/dist/ui/host-footprint.js +17 -0
- package/dist/ui/host-health-model.js +42 -0
- package/dist/ui/host-health.js +79 -0
- package/dist/ui/host-time.js +5 -0
- package/dist/ui/panel-chat.js +101 -43
- package/dist/ui/panel-fleet.js +24 -11
- package/dist/ui/panel-hub.js +5 -1
- package/dist/ui/panel-needs.js +27 -16
- package/dist/ui/panel-settings.js +4 -3
- package/dist/ui/search-dialog.js +8 -1
- package/dist/ui/settings-capabilities.js +2 -0
- package/dist/ui/settings-host-alerts.js +22 -0
- package/dist/ui/settings-host-monitoring.js +37 -18
- package/dist/ui/settings-registry.js +4 -1
- package/dist/ui/shared/accounts.css +8 -4
- package/dist/ui/shared/agent-sheet.js +5 -2
- package/dist/ui/shared/app-i18n.js +2 -2
- package/dist/ui/shared/app-route.js +1 -1
- package/dist/ui/shared/app.css +87 -9
- package/dist/ui/shared/app.js +1 -0
- package/dist/ui/shared/chat-render.js +24 -9
- package/dist/ui/shared/chat-strings.js +4 -4
- package/dist/ui/shared/chat-thread.js +45 -11
- package/dist/ui/shared/instance-nav.js +47 -5
- package/dist/ui/shared/jump-idle.js +36 -0
- package/dist/ui/shared/theme.js +6 -2
- package/dist/ui/shared/ui-menu.js +17 -11
- package/dist/web-api.d.ts +3 -0
- package/dist/web-api.js +249 -4
- package/dist/web-api.js.map +1 -1
- package/dist/web-chat-history.d.ts +47 -2
- package/dist/web-chat-history.js +149 -11
- package/dist/web-chat-history.js.map +1 -1
- package/dist/web-guest-access.js +4 -4
- package/dist/web-guest-access.js.map +1 -1
- package/dist/web-shell-routes.d.ts +1 -1
- package/dist/web-shell-routes.js +1 -1
- package/dist/web-shell-routes.js.map +1 -1
- package/dist/web-upload.d.ts +1 -1
- package/dist/web-upload.js.map +1 -1
- package/package.json +1 -1
|
@@ -51,6 +51,13 @@ export interface WebChatPoll {
|
|
|
51
51
|
counts?: number[];
|
|
52
52
|
voters?: string[][];
|
|
53
53
|
}
|
|
54
|
+
/** Retry ownership is assigned by the accepted server path, never by a message body. */
|
|
55
|
+
export interface WebChatRetry {
|
|
56
|
+
owner: string;
|
|
57
|
+
attempt: number;
|
|
58
|
+
failedAt?: number;
|
|
59
|
+
acknowledged?: true;
|
|
60
|
+
}
|
|
54
61
|
export interface WebChatMessage {
|
|
55
62
|
contactTicket?: ContactBadge;
|
|
56
63
|
/** Files shown with the message (absent when none); a restored one that cannot be served again is `gone` (#1565). */
|
|
@@ -68,6 +75,8 @@ export interface WebChatMessage {
|
|
|
68
75
|
boot: string;
|
|
69
76
|
/** Where a web user's message has got (absent: nothing reported yet, or not the web user's). */
|
|
70
77
|
delivery?: WebDeliveryState;
|
|
78
|
+
/** A new attempt explicitly resets the tick on the same retained bubble. */
|
|
79
|
+
retry?: WebChatRetry;
|
|
71
80
|
id: number;
|
|
72
81
|
instance: string;
|
|
73
82
|
/** A live web delivery id, or a native runtime turn's durable history identity. */
|
|
@@ -110,7 +119,7 @@ export interface WebChatMessage {
|
|
|
110
119
|
/**
|
|
111
120
|
* #2272: the message a person's message replies to — its row (`boot`, `id`) and what the bubble quotes: who wrote it
|
|
112
121
|
* and its first words, taken by the server from that row when the reply was sent (never from the page). `media`: a
|
|
113
|
-
* row with files and no text. A person's messages
|
|
122
|
+
* row with files and no text. A person's messages, and (M-3491) an agent's reply whose `reply_to` names a kept row.
|
|
114
123
|
*/
|
|
115
124
|
replyTo?: WebChatReplyRef;
|
|
116
125
|
/**
|
|
@@ -194,6 +203,13 @@ export interface WebChatHistoryOptions {
|
|
|
194
203
|
export interface StoredWebChatMessage {
|
|
195
204
|
contactTicket?: ContactBadge;
|
|
196
205
|
previews?: ReplyPreviewSpec[];
|
|
206
|
+
retry?: {
|
|
207
|
+
info: WebChatRetry;
|
|
208
|
+
messageId: string;
|
|
209
|
+
delivery: WebDeliveryState;
|
|
210
|
+
};
|
|
211
|
+
/** Import/reference identities only: never accepted by delivery status lookup. */
|
|
212
|
+
retiredNativeIds?: string[];
|
|
197
213
|
boot: string;
|
|
198
214
|
id: number;
|
|
199
215
|
instance: string;
|
|
@@ -306,6 +322,7 @@ export declare class WebChatHistory {
|
|
|
306
322
|
private readonly restoredBoots;
|
|
307
323
|
/** #2281: each row's platform posts, beside it (never a field of it). Gone with the row. */
|
|
308
324
|
private readonly posts;
|
|
325
|
+
private readonly retiredNativeIds;
|
|
309
326
|
/** M-3272: where messages leaving the window go (web-chat-archive.ts); none: they are dropped, as before. */
|
|
310
327
|
private archive;
|
|
311
328
|
constructor(opts?: WebChatHistoryOptions);
|
|
@@ -329,7 +346,7 @@ export declare class WebChatHistory {
|
|
|
329
346
|
/**
|
|
330
347
|
* #1565: the messages this instance had in an earlier fleet process, as stored (web-chat-store.ts) — validated
|
|
331
348
|
* here, never trusted: a row that is not ours in shape is dropped; text is cut; the role is kept as stored and is
|
|
332
|
-
* never made `agent` (anything else is a person's message);
|
|
349
|
+
* never made `agent` (anything else is a person's message); legacy rows restore no interactive state. A bounded owned failed-delivery descriptor is the exception: it keeps the retry attempt and attention episode.
|
|
333
350
|
* Bounds as for record(). Then each kept message's files are served again under their ids, by the file ledger's
|
|
334
351
|
* checks; a file that fails one — or is missing — is `gone` (its name shown as unavailable). Returns how many
|
|
335
352
|
* messages it restored. Only for an instance with nothing recorded yet in this process.
|
|
@@ -358,6 +375,7 @@ export declare class WebChatHistory {
|
|
|
358
375
|
messageId?: string;
|
|
359
376
|
anchor?: string;
|
|
360
377
|
role?: string;
|
|
378
|
+
retryOwner?: unknown;
|
|
361
379
|
buttons?: unknown;
|
|
362
380
|
previews?: unknown;
|
|
363
381
|
click?: unknown;
|
|
@@ -408,6 +426,14 @@ export declare class WebChatHistory {
|
|
|
408
426
|
postsOf(row: WebChatMessage): readonly WebChatPost[];
|
|
409
427
|
/** #2281: a web message's channel copies, once sent (by its message id); kept on disk with it. */
|
|
410
428
|
addPosts(instance: string, messageId: string, raw: readonly WebChatPost[]): void;
|
|
429
|
+
/**
|
|
430
|
+
* M-3491: the kept message an agent's `reply_to` names. An agent may quote any message it was shown: by its web
|
|
431
|
+
* `message_id` (a web message or click), by the id its own `reply` call returned (`anchor`), or by any platform copy's
|
|
432
|
+
* id (`posts`: a Discord or Telegram message, buttons message included). Newest first; undefined when none matches.
|
|
433
|
+
*/
|
|
434
|
+
findByReplyId(instance: string, id: string): WebChatMessage | undefined;
|
|
435
|
+
/** Native journal imports may recognize a superseded attempt without accepting its status reports. */
|
|
436
|
+
findByNativeHistoryId(instance: string, messageId: string): WebChatMessage | undefined;
|
|
411
437
|
findByMessageId(instance: string, messageId: string): WebChatMessage | undefined;
|
|
412
438
|
/**
|
|
413
439
|
* Link old native imports to their authoritative turn ids before importing anything missing. Earlier versions
|
|
@@ -443,6 +469,22 @@ export declare class WebChatHistory {
|
|
|
443
469
|
* A delivery report for one of this instance's messages. Returns the message when its state changed (so the
|
|
444
470
|
* caller tells the pages), null when there is no such message or the report would move it back.
|
|
445
471
|
*/
|
|
472
|
+
/** Claim one failed attempt synchronously: two tabs cannot enqueue two resends. */
|
|
473
|
+
beginResend(instance: string, boot: string, id: number, attempt: number, owner: string, messageId: string, nativeJournalIds?: ReadonlySet<string>): {
|
|
474
|
+
kind: "started" | "already";
|
|
475
|
+
message: WebChatMessage;
|
|
476
|
+
} | {
|
|
477
|
+
kind: "refused";
|
|
478
|
+
};
|
|
479
|
+
failedWebDeliveries(since: number): Array<{
|
|
480
|
+
deliveryId: string;
|
|
481
|
+
state: "failed";
|
|
482
|
+
source: string;
|
|
483
|
+
target: string;
|
|
484
|
+
kind: string;
|
|
485
|
+
finishedAt: number;
|
|
486
|
+
}>;
|
|
487
|
+
acknowledgeWebDelivery(deliveryId: string): boolean;
|
|
446
488
|
setDelivery(instance: string, messageId: string, state: WebDeliveryState): WebChatMessage | null;
|
|
447
489
|
/**
|
|
448
490
|
* A Stop on this instance: the web user's messages still waiting (nothing reported, or queued) were dropped
|
|
@@ -459,6 +501,9 @@ export declare class WebChatHistory {
|
|
|
459
501
|
instance: string;
|
|
460
502
|
messageId: string;
|
|
461
503
|
delivery: WebDeliveryState;
|
|
504
|
+
boot?: string;
|
|
505
|
+
id?: number;
|
|
506
|
+
retry?: WebChatRetry;
|
|
462
507
|
}>;
|
|
463
508
|
cancelPending(instance: string): WebChatMessage[];
|
|
464
509
|
/** Forget an instance (deleted) — and its file (#1565): a later instance of the same name starts empty. */
|
package/dist/web-chat-history.js
CHANGED
|
@@ -78,6 +78,16 @@ function webChatButtons(raw) {
|
|
|
78
78
|
...(state === "chosen" && typeof b.by === "string" ? { by: b.by.slice(0, 64) } : {}),
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
+
function retryInfo(raw) {
|
|
82
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
83
|
+
return null;
|
|
84
|
+
const r = raw;
|
|
85
|
+
if (typeof r.owner !== "string" || !r.owner || r.owner.length > 256 || /\s/.test(r.owner)
|
|
86
|
+
|| !Number.isSafeInteger(r.attempt) || r.attempt < 0)
|
|
87
|
+
return null;
|
|
88
|
+
const failedAt = typeof r.failedAt === "number" && Number.isFinite(r.failedAt) && r.failedAt > 0 ? r.failedAt : undefined;
|
|
89
|
+
return { owner: r.owner, attempt: r.attempt, ...(failedAt ? { failedAt } : {}), ...(r.acknowledged === true ? { acknowledged: true } : {}) };
|
|
90
|
+
}
|
|
81
91
|
/** #2341: a status line's card numbers (M-3, S-34), each once, at most this many; anything else is dropped. */
|
|
82
92
|
const CARD_CODE = /^[MS]-\d{1,9}$/;
|
|
83
93
|
export const WEB_CHAT_CARDS_MAX = 500;
|
|
@@ -177,6 +187,8 @@ function webChatClick(raw) {
|
|
|
177
187
|
return { label: c.label.slice(0, CLICK_LABEL_MAX), ...(typeof c.of === "string" && /^[0-9a-f]{32}$/.test(c.of) ? { of: c.of } : {}) };
|
|
178
188
|
}
|
|
179
189
|
export const WEB_CHAT_TEXT_MAX = 16_000;
|
|
190
|
+
// /ui/send accepts 16 KiB of text. A retry must retain that complete payload.
|
|
191
|
+
const WEB_CHAT_RETRY_TEXT_MAX = 16_384;
|
|
180
192
|
/** A native turn id is inert history identity, never a revived web delivery or interactive control. */
|
|
181
193
|
function nativeHistoryMessageId(value, role) {
|
|
182
194
|
if (typeof value !== "string")
|
|
@@ -209,6 +221,7 @@ export class WebChatHistory {
|
|
|
209
221
|
restoredBoots = new Map();
|
|
210
222
|
/** #2281: each row's platform posts, beside it (never a field of it). Gone with the row. */
|
|
211
223
|
posts = new WeakMap();
|
|
224
|
+
retiredNativeIds = new WeakMap();
|
|
212
225
|
/** M-3272: where messages leaving the window go (web-chat-archive.ts); none: they are dropped, as before. */
|
|
213
226
|
archive = null;
|
|
214
227
|
constructor(opts = {}) {
|
|
@@ -247,8 +260,13 @@ export class WebChatHistory {
|
|
|
247
260
|
...(m.replyTo ? { replyTo: m.replyTo } : {}), ...(m.reactions?.length ? { reactions: [...m.reactions] } : {}), ...(m.cards?.length ? { cards: [...m.cards] } : {}), ...(m.role === "agent" && m.previews?.length ? { previews: m.previews } : {}) };
|
|
248
261
|
if (nativeHistoryMessageId(m.messageId, m.role))
|
|
249
262
|
row.messageId = m.messageId;
|
|
263
|
+
const retired = this.retiredNativeIds.get(m);
|
|
264
|
+
if (retired?.length)
|
|
265
|
+
row.retiredNativeIds = [...retired];
|
|
250
266
|
if (m.contactTicket)
|
|
251
267
|
row.contactTicket = { ...m.contactTicket };
|
|
268
|
+
if (m.retry?.failedAt && m.messageId && m.delivery)
|
|
269
|
+
row.retry = { info: { ...m.retry }, messageId: m.messageId, delivery: m.delivery };
|
|
252
270
|
const posts = this.posts.get(m);
|
|
253
271
|
if (posts?.length)
|
|
254
272
|
row.posts = posts.map(p => ({ ...p }));
|
|
@@ -291,7 +309,7 @@ export class WebChatHistory {
|
|
|
291
309
|
/**
|
|
292
310
|
* #1565: the messages this instance had in an earlier fleet process, as stored (web-chat-store.ts) — validated
|
|
293
311
|
* here, never trusted: a row that is not ours in shape is dropped; text is cut; the role is kept as stored and is
|
|
294
|
-
* never made `agent` (anything else is a person's message);
|
|
312
|
+
* never made `agent` (anything else is a person's message); legacy rows restore no interactive state. A bounded owned failed-delivery descriptor is the exception: it keeps the retry attempt and attention episode.
|
|
295
313
|
* Bounds as for record(). Then each kept message's files are served again under their ids, by the file ledger's
|
|
296
314
|
* checks; a file that fails one — or is missing — is `gone` (its name shown as unavailable). Returns how many
|
|
297
315
|
* messages it restored. Only for an instance with nothing recorded yet in this process.
|
|
@@ -319,6 +337,8 @@ export class WebChatHistory {
|
|
|
319
337
|
const message = this.restoreFiles(r, instance);
|
|
320
338
|
if (r.posts.length)
|
|
321
339
|
this.posts.set(message, r.posts);
|
|
340
|
+
if (r.retiredNativeIds.length)
|
|
341
|
+
this.retiredNativeIds.set(message, r.retiredNativeIds);
|
|
322
342
|
return message;
|
|
323
343
|
});
|
|
324
344
|
if (!kept.length)
|
|
@@ -389,7 +409,7 @@ export class WebChatHistory {
|
|
|
389
409
|
// Anything not one of the three — or absent — is a person's message.
|
|
390
410
|
role: typeof msg.role === "string" && ROLES.has(msg.role) ? msg.role : "user",
|
|
391
411
|
sender: String(msg.sender),
|
|
392
|
-
text: String(msg.text ?? "").slice(0, WEB_CHAT_TEXT_MAX),
|
|
412
|
+
text: msg.retryOwner ? String(msg.text ?? "").slice(0, WEB_CHAT_RETRY_TEXT_MAX) : String(msg.text ?? "").slice(0, WEB_CHAT_TEXT_MAX),
|
|
393
413
|
ts: String(msg.ts),
|
|
394
414
|
...(msg.attachments && msg.attachments.length ? { attachments: msg.attachments.slice(0, 20).map(a => ({ id: a.id, kind: a.kind, name: a.name, size: a.size, mime: a.mime, ...drawnSize(a) })) } : {}),
|
|
395
415
|
...(typeof msg.messageId === "string" && msg.messageId ? { messageId: msg.messageId.slice(0, 64) } : {}),
|
|
@@ -398,6 +418,11 @@ export class WebChatHistory {
|
|
|
398
418
|
const anchor = typeof msg.anchor === "string" && msg.anchor ? msg.anchor : entry.messageId;
|
|
399
419
|
if (anchor && ANCHOR_ID.test(anchor))
|
|
400
420
|
entry.anchor = anchor.slice(0, 80);
|
|
421
|
+
if (entry.role === "user" && entry.messageId && typeof msg.retryOwner === "string") {
|
|
422
|
+
const retry = retryInfo({ owner: msg.retryOwner, attempt: 0 });
|
|
423
|
+
if (retry)
|
|
424
|
+
entry.retry = retry;
|
|
425
|
+
}
|
|
401
426
|
const buttons = msg.role === "agent" ? webChatButtons(msg.buttons) : undefined;
|
|
402
427
|
if (buttons)
|
|
403
428
|
entry.buttons = buttons;
|
|
@@ -423,8 +448,8 @@ export class WebChatHistory {
|
|
|
423
448
|
entry.channel = true;
|
|
424
449
|
if (entry.role === "user" && typeof msg.from === "string" && FROM.test(msg.from))
|
|
425
450
|
entry.from = msg.from;
|
|
426
|
-
// #2272:
|
|
427
|
-
const replyTo = entry.role === "user" ? webChatReplyRefOf(msg.replyTo) : undefined;
|
|
451
|
+
// #2272: a person's message replies to another; M-3491: so does an agent's reply (its `reply_to`, resolved by the server).
|
|
452
|
+
const replyTo = entry.role === "user" || entry.role === "agent" ? webChatReplyRefOf(msg.replyTo) : undefined;
|
|
428
453
|
if (replyTo)
|
|
429
454
|
entry.replyTo = replyTo;
|
|
430
455
|
// #2281: where it is on a platform, beside the row (the caller that sent or received it knows).
|
|
@@ -544,6 +569,29 @@ export class WebChatHistory {
|
|
|
544
569
|
this.posts.set(m, posts);
|
|
545
570
|
this.persist(instance);
|
|
546
571
|
}
|
|
572
|
+
/**
|
|
573
|
+
* M-3491: the kept message an agent's `reply_to` names. An agent may quote any message it was shown: by its web
|
|
574
|
+
* `message_id` (a web message or click), by the id its own `reply` call returned (`anchor`), or by any platform copy's
|
|
575
|
+
* id (`posts`: a Discord or Telegram message, buttons message included). Newest first; undefined when none matches.
|
|
576
|
+
*/
|
|
577
|
+
findByReplyId(instance, id) {
|
|
578
|
+
if (!id)
|
|
579
|
+
return undefined;
|
|
580
|
+
const messages = this.byInstance.get(instance)?.messages ?? [];
|
|
581
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
582
|
+
const m = messages[i];
|
|
583
|
+
if (m.messageId === id || m.anchor === id || this.retiredNativeIds.get(m)?.includes(id) || this.posts.get(m)?.some(p => p.messageId === id))
|
|
584
|
+
return m;
|
|
585
|
+
}
|
|
586
|
+
return undefined;
|
|
587
|
+
}
|
|
588
|
+
/** Native journal imports may recognize a superseded attempt without accepting its status reports. */
|
|
589
|
+
findByNativeHistoryId(instance, messageId) {
|
|
590
|
+
const current = this.findByMessageId(instance, messageId);
|
|
591
|
+
if (current || !nativeHistoryMessageId(messageId, "user"))
|
|
592
|
+
return current;
|
|
593
|
+
return this.byInstance.get(instance)?.messages.find(m => this.retiredNativeIds.get(m)?.includes(messageId));
|
|
594
|
+
}
|
|
547
595
|
findByMessageId(instance, messageId) {
|
|
548
596
|
const messages = this.byInstance.get(instance)?.messages ?? [];
|
|
549
597
|
for (let i = messages.length - 1; i >= 0; i--)
|
|
@@ -668,6 +716,73 @@ export class WebChatHistory {
|
|
|
668
716
|
* A delivery report for one of this instance's messages. Returns the message when its state changed (so the
|
|
669
717
|
* caller tells the pages), null when there is no such message or the report would move it back.
|
|
670
718
|
*/
|
|
719
|
+
/** Claim one failed attempt synchronously: two tabs cannot enqueue two resends. */
|
|
720
|
+
beginResend(instance, boot, id, attempt, owner, messageId, nativeJournalIds) {
|
|
721
|
+
const m = this.find(instance, boot, id), r = m?.retry;
|
|
722
|
+
if (!m || m.role !== "user" || !r || r.owner !== owner)
|
|
723
|
+
return { kind: "refused" };
|
|
724
|
+
if (r.attempt === attempt + 1 && m.delivery !== "failed")
|
|
725
|
+
return { kind: "already", message: m };
|
|
726
|
+
if (m.delivery !== "failed" || r.attempt !== attempt || r.attempt >= Number.MAX_SAFE_INTEGER || !r.failedAt)
|
|
727
|
+
return { kind: "refused" };
|
|
728
|
+
const previousId = m.messageId, previousRetired = this.retiredNativeIds.get(m);
|
|
729
|
+
// WindowsAgents keeps ten journal turns. Keep that same bounded import
|
|
730
|
+
// horizon privately, including through reloads; never expose it as status authority.
|
|
731
|
+
if (nativeHistoryMessageId(previousId, "user")) {
|
|
732
|
+
const aliases = [...new Set([...(previousRetired ?? []), previousId])];
|
|
733
|
+
this.retiredNativeIds.set(m, aliases.filter(id => !nativeJournalIds || nativeJournalIds.has(id)).slice(-10));
|
|
734
|
+
}
|
|
735
|
+
r.attempt++;
|
|
736
|
+
m.messageId = messageId;
|
|
737
|
+
m.delivery = "queued";
|
|
738
|
+
// failedAt survives queued/processing: attention clears only on confirmed delivery.
|
|
739
|
+
try {
|
|
740
|
+
this.persist(instance);
|
|
741
|
+
}
|
|
742
|
+
catch (error) {
|
|
743
|
+
r.attempt--;
|
|
744
|
+
m.messageId = previousId;
|
|
745
|
+
m.delivery = "failed";
|
|
746
|
+
if (previousRetired)
|
|
747
|
+
this.retiredNativeIds.set(m, previousRetired);
|
|
748
|
+
else
|
|
749
|
+
this.retiredNativeIds.delete(m);
|
|
750
|
+
throw error;
|
|
751
|
+
}
|
|
752
|
+
return { kind: "started", message: m };
|
|
753
|
+
}
|
|
754
|
+
failedWebDeliveries(since) {
|
|
755
|
+
const out = [];
|
|
756
|
+
for (const [instance, slot] of this.byInstance)
|
|
757
|
+
for (const m of slot.messages) {
|
|
758
|
+
if (m.retry?.failedAt && !m.retry.acknowledged && m.retry.failedAt >= since)
|
|
759
|
+
out.push({
|
|
760
|
+
deliveryId: `web:${m.boot}:${m.id}`, state: "failed", source: m.sender, target: instance,
|
|
761
|
+
kind: "web", finishedAt: m.retry.failedAt,
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
return out.sort((a, b) => b.finishedAt - a.finishedAt).slice(0, 50);
|
|
765
|
+
}
|
|
766
|
+
acknowledgeWebDelivery(deliveryId) {
|
|
767
|
+
const match = /^web:([0-9a-f]{1,32}):([1-9][0-9]*)$/.exec(deliveryId);
|
|
768
|
+
if (!match)
|
|
769
|
+
return false;
|
|
770
|
+
for (const [instance, slot] of this.byInstance) {
|
|
771
|
+
const m = slot.messages.find(row => row.boot === match[1] && row.id === Number(match[2]));
|
|
772
|
+
if (!m?.retry?.failedAt || m.retry.acknowledged)
|
|
773
|
+
continue;
|
|
774
|
+
m.retry.acknowledged = true;
|
|
775
|
+
try {
|
|
776
|
+
this.persist(instance);
|
|
777
|
+
}
|
|
778
|
+
catch (error) {
|
|
779
|
+
delete m.retry.acknowledged;
|
|
780
|
+
throw error;
|
|
781
|
+
}
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
return false;
|
|
785
|
+
}
|
|
671
786
|
setDelivery(instance, messageId, state) {
|
|
672
787
|
const messages = this.byInstance.get(instance)?.messages ?? [];
|
|
673
788
|
let m;
|
|
@@ -680,6 +795,16 @@ export class WebChatHistory {
|
|
|
680
795
|
if (next === m.delivery)
|
|
681
796
|
return null;
|
|
682
797
|
m.delivery = next;
|
|
798
|
+
if (m.retry) {
|
|
799
|
+
if (next === "failed") {
|
|
800
|
+
m.retry.failedAt = Date.now();
|
|
801
|
+
delete m.retry.acknowledged;
|
|
802
|
+
}
|
|
803
|
+
if (next === "delivered") {
|
|
804
|
+
delete m.retry.failedAt;
|
|
805
|
+
delete m.retry.acknowledged;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
683
808
|
this.persist(instance);
|
|
684
809
|
return m;
|
|
685
810
|
}
|
|
@@ -699,7 +824,7 @@ export class WebChatHistory {
|
|
|
699
824
|
for (const [instance, slot] of this.byInstance) {
|
|
700
825
|
for (const m of slot.messages)
|
|
701
826
|
if (m.messageId !== undefined && m.delivery !== undefined)
|
|
702
|
-
out.push({ instance, messageId: m.messageId, delivery: m.delivery });
|
|
827
|
+
out.push({ instance, messageId: m.messageId, delivery: m.delivery, ...(m.retry ? { boot: m.boot, id: m.id, retry: { ...m.retry } } : {}) });
|
|
703
828
|
}
|
|
704
829
|
return out;
|
|
705
830
|
}
|
|
@@ -904,6 +1029,7 @@ export class WebChatHistory {
|
|
|
904
1029
|
* Only what was said comes back: no buttons, delivery tick or ordinary web delivery id. A strict native turn id is
|
|
905
1030
|
* inert history identity and survives. #2305: the instance's reactions (what was answered) survive too. Restored
|
|
906
1031
|
* messages keep their original boot/id rather than taking a new cursor in this process.
|
|
1032
|
+
* Validated owned failed-delivery descriptors also retain their retry attempt.
|
|
907
1033
|
*/
|
|
908
1034
|
/** An anchor id: what a transcript can name a message by (web-…, a platform's digits, a tool result's id). */
|
|
909
1035
|
const ANCHOR_ID = /^[A-Za-z0-9._:-]{1,80}$/;
|
|
@@ -919,14 +1045,26 @@ function restoredRow(raw, instance, thisBoot) {
|
|
|
919
1045
|
return null;
|
|
920
1046
|
// The role as stored — a person's message unless it is one of the three; never upgraded to `agent`.
|
|
921
1047
|
const role = typeof r.role === "string" && ROLES.has(r.role) ? r.role : "user";
|
|
922
|
-
const message = { boot: r.boot, id: r.id, instance, role, sender: r.sender.slice(0, 256), text: r.text.slice(0, WEB_CHAT_TEXT_MAX), ts: r.ts.slice(0, 64) };
|
|
1048
|
+
const message = { boot: r.boot, id: r.id, instance, role, sender: r.sender.slice(0, 256), text: r.retry ? r.text.slice(0, WEB_CHAT_RETRY_TEXT_MAX) : r.text.slice(0, WEB_CHAT_TEXT_MAX), ts: r.ts.slice(0, 64) };
|
|
1049
|
+
if (role === "user" && typeof r.from === "string" && FROM.test(r.from))
|
|
1050
|
+
message.from = r.from;
|
|
1051
|
+
if (role === "user" && r.retry && typeof r.retry === "object") {
|
|
1052
|
+
const saved = r.retry, retry = retryInfo(saved.info);
|
|
1053
|
+
if (retry?.failedAt && typeof saved.messageId === "string" && (isWebMessageId(saved.messageId) || nativeHistoryMessageId(saved.messageId, role)) && saved.messageId.length <= 64
|
|
1054
|
+
&& typeof saved.delivery === "string" && ["queued", "processing", "failed", "cancelled"].includes(saved.delivery)
|
|
1055
|
+
&& (message.from ? retry.owner === message.from : retry.owner === "web:operator")) {
|
|
1056
|
+
message.retry = retry;
|
|
1057
|
+
message.messageId = saved.messageId;
|
|
1058
|
+
message.delivery = saved.delivery;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
923
1061
|
const badge = contactBadge(r.contactTicket);
|
|
924
1062
|
if (badge)
|
|
925
1063
|
message.contactTicket = badge;
|
|
926
1064
|
const previews = role === "agent" ? replyPreviews(r.previews) : null;
|
|
927
1065
|
if (previews?.length)
|
|
928
1066
|
message.previews = previews;
|
|
929
|
-
if (nativeHistoryMessageId(r.messageId, role))
|
|
1067
|
+
if (!message.retry && nativeHistoryMessageId(r.messageId, role))
|
|
930
1068
|
message.messageId = r.messageId;
|
|
931
1069
|
// A click comes back as its label only (the link to its buttons belonged to the process that ended).
|
|
932
1070
|
const click = role === "user" ? webChatClick(r.click) : undefined;
|
|
@@ -941,14 +1079,12 @@ function restoredRow(raw, instance, thisBoot) {
|
|
|
941
1079
|
// #1920: as recorded — a row from before these were written has neither, so a guest is never shown it.
|
|
942
1080
|
if (r.channel === true)
|
|
943
1081
|
message.channel = true;
|
|
944
|
-
if (role === "user" && typeof r.from === "string" && FROM.test(r.from))
|
|
945
|
-
message.from = r.from;
|
|
946
1082
|
// #2085 (made the channel's late) and #1774 (recorded late): either way, where it stands in its boot's sequence.
|
|
947
1083
|
if (typeof r.seenSeq === "number" && Number.isSafeInteger(r.seenSeq) && r.seenSeq > r.id)
|
|
948
1084
|
message.seenSeq = r.seenSeq;
|
|
949
1085
|
if (typeof r.anchor === "string" && ANCHOR_ID.test(r.anchor))
|
|
950
1086
|
message.anchor = r.anchor;
|
|
951
|
-
const replyTo = role === "user" ? webChatReplyRefOf(r.replyTo) : undefined;
|
|
1087
|
+
const replyTo = role === "user" || role === "agent" ? webChatReplyRefOf(r.replyTo) : undefined;
|
|
952
1088
|
if (replyTo)
|
|
953
1089
|
message.replyTo = replyTo;
|
|
954
1090
|
const reactions = webReactionsOf(r.reactions);
|
|
@@ -966,7 +1102,9 @@ function restoredRow(raw, instance, thisBoot) {
|
|
|
966
1102
|
size: typeof f.size === "number" && Number.isSafeInteger(f.size) && f.size >= 0 ? f.size : 0, mime: typeof f.mime === "string" ? f.mime.slice(0, 128) : "",
|
|
967
1103
|
}];
|
|
968
1104
|
});
|
|
969
|
-
|
|
1105
|
+
const retiredNativeIds = role === "user" && Array.isArray(r.retiredNativeIds)
|
|
1106
|
+
? [...new Set(r.retiredNativeIds.filter((id) => nativeHistoryMessageId(id, "user")))].slice(-10) : [];
|
|
1107
|
+
return { message, files, posts: webChatPosts(r.posts), retiredNativeIds };
|
|
970
1108
|
}
|
|
971
1109
|
/** A photo's drawn size as the page gets it (both positive integers), or nothing. Measured from the file, never kept. */
|
|
972
1110
|
function drawnSize(a) {
|