dsh-client-auto-continue 0.8.0 → 0.8.2

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.
@@ -0,0 +1,458 @@
1
+ /** 共享核心: 平台无关的纯逻辑与类型。
2
+ *
3
+ * 被 host 引擎(src/host/engine.ts)与浏览器半侧共用: 配置解析、错误分类、
4
+ * 模板填充、自适应退避、幂等护栏的工具结果提取、循环守卫的会话状态机,
5
+ * 以及回显识别。引擎迁入 host 后(0.8.0), 浏览器半侧只 re-export 本模块。
6
+ */
7
+ import type { SessionEvent, SessionId } from '@deepseek-ai/dsh-session/types';
8
+
9
+ /** The `auto-continue` settings section (all fields optional on the wire; the host schema carries defaults). */
10
+ export interface AutoContinueSettings {
11
+ /** Text automatically sent after an interruption. */
12
+ continueText?: string;
13
+ /** Text sent when the output token ceiling is reached (same placeholders as `continueText`). */
14
+ continueTextMaxTokens?: string;
15
+ /** Idempotency guard: inspect the last tool call before resuming and steer the model. */
16
+ guardTools?: boolean;
17
+ /** Guard text appended when the last tool call has no confirmed result (it may have partially executed). */
18
+ guardPendingText?: string;
19
+ /** Guard text appended when the last tool call completed successfully (don't rerun it). */
20
+ guardDoneText?: string;
21
+ /** Grace period after an interruption before auto-sending (ms). */
22
+ graceMs?: number;
23
+ /** Minimum interval between two auto-continues per session (ms). */
24
+ cooldownMs?: number;
25
+ /** Max consecutive auto-continues per session before stopping. */
26
+ maxConsecutive?: number;
27
+ /** Scan recently interrupted sessions on page load / reconnect. */
28
+ scanOnBoot?: boolean;
29
+ /** Max sessions the scan checks (most recently updated). */
30
+ scanLimit?: number;
31
+ /** Scan only considers interruptions inside this window (ms). */
32
+ freshMs?: number;
33
+ /** Log `[auto-continue]` lines to the browser console. */
34
+ verbose?: boolean;
35
+ /** Classify failures: auto-continue transient errors only; permanent ones (auth/balance/model) are skipped and notified. */
36
+ classify?: boolean;
37
+ /** Cooldown multiplier per consecutive failure (adaptive backoff). */
38
+ backoffFactor?: number;
39
+ /** Cap on the effective backoff interval (ms). */
40
+ backoffMaxMs?: number;
41
+ /** Show browser notifications for auto-continue events. */
42
+ notify?: boolean;
43
+ /** Globally pause auto-continue: no live or scan send, queued pending sends cancelled. */
44
+ paused?: boolean;
45
+ /** Loop guard: detect a running turn spinning in place (short talk without tools, or the same tool repeating) and restart it. */
46
+ loopGuard?: boolean;
47
+ /** A model message shorter than this many chars counts as a "short sentence" (loop signal). */
48
+ loopShortChars?: number;
49
+ /** Consecutive short sentences within this window (ms) with no tool call in between trip the loop guard. */
50
+ loopWindowMs?: number;
51
+ /** Consecutive short sentences trip the loop guard. */
52
+ loopShortCount?: number;
53
+ /** Consecutive identical tool calls with identical arguments AND identical results trip the loop guard. */
54
+ loopToolRepeat?: number;
55
+ /** Consecutive identical short sentences trip the loop guard (strongest spinning signal). */
56
+ loopRepeatText?: number;
57
+ /** Text sent after the loop guard cancels and restarts a turn (supports {tool}). */
58
+ loopText?: string;
59
+ }
60
+
61
+ /** Fully resolved configuration (built-in defaults + user overrides). */
62
+ export type AutoContinueConfig = Required<AutoContinueSettings>;
63
+
64
+ /** Built-in defaults — must match the host schema defaults in src/index.ts. */
65
+ export const DEFAULT_CONFIG: AutoContinueConfig = {
66
+ continueText: '继续',
67
+ continueTextMaxTokens: '继续',
68
+ guardTools: true,
69
+ guardPendingText: '(上一步工具「{tool}」可能未完成, 先确认状态再继续, 不要重复执行)',
70
+ guardDoneText: '(上一步工具「{tool}」已完成, 结果: {result}; 不要重复执行, 直接继续)',
71
+ graceMs: 3000,
72
+ cooldownMs: 20000,
73
+ maxConsecutive: 3,
74
+ scanOnBoot: true,
75
+ scanLimit: 8,
76
+ freshMs: 15 * 60 * 1000,
77
+ verbose: true,
78
+ classify: true,
79
+ backoffFactor: 2,
80
+ backoffMaxMs: 300000,
81
+ notify: false,
82
+ paused: false,
83
+ loopGuard: true,
84
+ loopShortChars: 40,
85
+ loopWindowMs: 30000,
86
+ loopShortCount: 12,
87
+ loopRepeatText: 4,
88
+ loopToolRepeat: 5,
89
+ loopText: '(检测到你可能陷入循环, 请停止重复刚才的动作, 换一种方式继续)',
90
+ };
91
+
92
+ function numberOr(value: unknown, fallback: number): number {
93
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : fallback;
94
+ }
95
+
96
+ function booleanOr(value: unknown, fallback: boolean): boolean {
97
+ return typeof value === 'boolean' ? value : fallback;
98
+ }
99
+
100
+ /** Resolve a (possibly partial / not-yet-loaded) settings section to a full config. */
101
+ export function resolveConfig(section: AutoContinueSettings | undefined): AutoContinueConfig {
102
+ const value = section ?? {};
103
+ const text =
104
+ typeof value.continueText === 'string' && value.continueText.trim() !== ''
105
+ ? value.continueText
106
+ : DEFAULT_CONFIG.continueText;
107
+ const maxTokensText =
108
+ typeof value.continueTextMaxTokens === 'string' && value.continueTextMaxTokens.trim() !== ''
109
+ ? value.continueTextMaxTokens
110
+ : DEFAULT_CONFIG.continueTextMaxTokens;
111
+ const guardPendingText =
112
+ typeof value.guardPendingText === 'string' && value.guardPendingText.trim() !== ''
113
+ ? value.guardPendingText
114
+ : DEFAULT_CONFIG.guardPendingText;
115
+ const guardDoneText =
116
+ typeof value.guardDoneText === 'string' && value.guardDoneText.trim() !== ''
117
+ ? value.guardDoneText
118
+ : DEFAULT_CONFIG.guardDoneText;
119
+ return {
120
+ continueText: text,
121
+ continueTextMaxTokens: maxTokensText,
122
+ guardTools: booleanOr(value.guardTools, DEFAULT_CONFIG.guardTools),
123
+ guardPendingText,
124
+ guardDoneText,
125
+ graceMs: numberOr(value.graceMs, DEFAULT_CONFIG.graceMs),
126
+ cooldownMs: numberOr(value.cooldownMs, DEFAULT_CONFIG.cooldownMs),
127
+ maxConsecutive: Math.max(1, numberOr(value.maxConsecutive, DEFAULT_CONFIG.maxConsecutive)),
128
+ scanOnBoot: booleanOr(value.scanOnBoot, DEFAULT_CONFIG.scanOnBoot),
129
+ scanLimit: Math.max(1, numberOr(value.scanLimit, DEFAULT_CONFIG.scanLimit)),
130
+ freshMs: numberOr(value.freshMs, DEFAULT_CONFIG.freshMs),
131
+ verbose: booleanOr(value.verbose, DEFAULT_CONFIG.verbose),
132
+ classify: booleanOr(value.classify, DEFAULT_CONFIG.classify),
133
+ backoffFactor: Math.max(1, numberOr(value.backoffFactor, DEFAULT_CONFIG.backoffFactor)),
134
+ backoffMaxMs: numberOr(value.backoffMaxMs, DEFAULT_CONFIG.backoffMaxMs),
135
+ notify: booleanOr(value.notify, DEFAULT_CONFIG.notify),
136
+ paused: booleanOr(value.paused, DEFAULT_CONFIG.paused),
137
+ loopGuard: booleanOr(value.loopGuard, DEFAULT_CONFIG.loopGuard),
138
+ loopShortChars: Math.max(1, numberOr(value.loopShortChars, DEFAULT_CONFIG.loopShortChars)),
139
+ loopWindowMs: Math.max(1000, numberOr(value.loopWindowMs, DEFAULT_CONFIG.loopWindowMs)),
140
+ loopShortCount: Math.max(2, numberOr(value.loopShortCount, DEFAULT_CONFIG.loopShortCount)),
141
+ loopRepeatText: Math.max(2, numberOr(value.loopRepeatText, DEFAULT_CONFIG.loopRepeatText)),
142
+ loopToolRepeat: Math.max(2, numberOr(value.loopToolRepeat, DEFAULT_CONFIG.loopToolRepeat)),
143
+ loopText:
144
+ typeof value.loopText === 'string' && value.loopText.trim() !== ''
145
+ ? value.loopText
146
+ : DEFAULT_CONFIG.loopText,
147
+ };
148
+ }
149
+
150
+ /**
151
+ * 视为「非人为中断」的回合结束原因, 用于启动/重连扫描。
152
+ * - `interrupted` 只由崩溃修复在宿主重载时写入(loop 永不实时发出), 因此仅在扫描路径处理;
153
+ * - 实时事件路径只对 `error` / `max-tokens` 自动续跑;
154
+ * - `aborted`(用户停止)与 `blocked`(策略拒绝)永不自动继续。
155
+ */
156
+ type NonHumanReason = 'error' | 'interrupted' | 'max-tokens';
157
+
158
+ export function isNonHumanReason(kind: string): kind is NonHumanReason {
159
+ return kind === 'error' || kind === 'interrupted' || kind === 'max-tokens';
160
+ }
161
+
162
+ /** 一次回合失败的机器可读事实(turn/end error 的 LlmFailure 载荷)。 */
163
+ export interface FailureFacts {
164
+ /** 稳定机器路由码(如 UPSTREAM、RATE_LIMIT_EXCEEDED、INVALID_API_KEY)。 */
165
+ code: string;
166
+ /** 人类可读的失败描述。 */
167
+ message: string;
168
+ /** 供应商 HTTP 状态码(可用时)。 */
169
+ status?: number;
170
+ }
171
+
172
+ /**
173
+ * 错误分类: 该失败是否值得自动继续。
174
+ * 永久性失败(认证/余额/模型不存在/上下文超限等)重试也不会成功, 应跳过并通知用户;
175
+ * 其余(网络、超时、5xx、429 等)视为临时性失败, 允许自动恢复。
176
+ */
177
+ export function isTransientFailure(failure: FailureFacts): boolean {
178
+ const haystack = `${failure.code} ${failure.message}`.toLowerCase();
179
+ const status = failure.status;
180
+ if (status !== undefined && (status === 401 || status === 403)) return false;
181
+ const permanent =
182
+ /auth|unauthor|forbidden|credential|api[_-]?key|permission/i.test(haystack) ||
183
+ /insufficient.*(balance|quota)|billing|payment|quota.*exceeded.*(?!retry)/i.test(haystack) ||
184
+ /model.*not[_-]?found|unknown[_-]?model|model[_-]?not[_-]?found|not.*support.*model/i.test(haystack) ||
185
+ /context.*(length|limit|overflow|exceed)|token.*limit|max.*context/i.test(haystack) ||
186
+ /invalid[_-]?request|bad[_-]?request/i.test(haystack);
187
+ return !permanent;
188
+ }
189
+
190
+ /**
191
+ * host/agent-error 消息分类: 仅明确属于网络/传输类的临时错误才自动继续。
192
+ * 其余(序列化失败、配置/宿主内部错误等)视为永久性——重试无益, 且用户停止导致的
193
+ * 序列化失败(如 Windows 下 abort 的 DOMException reason)绝不能自动续跑。
194
+ */
195
+ export function isTransientAgentError(message: string): boolean {
196
+ return /network|timeout|timed ?out|econn|etimedout|socket|5\d\d|\b429\b|upstream|temporar/i.test(message);
197
+ }
198
+
199
+ /** 通知上的一个操作按钮(action 标识 + 显示文案)。 */
200
+ export interface NotifyAction {
201
+ /** 稳定动作标识, 点击时经 onAction 回调传出。 */
202
+ action: string;
203
+ /** 按钮显示文案。 */
204
+ title: string;
205
+ }
206
+
207
+ /** 通知的可选行为: 操作按钮列表与点击回调。 */
208
+ export interface NotifyOptions {
209
+ actions?: NotifyAction[];
210
+ onAction?: (action: string) => void;
211
+ }
212
+
213
+ /** 浏览器通知(不可用时静默跳过); 点击通知聚焦窗口, 操作按钮走 onAction。 */
214
+ /** 把毫秒格式化为人类可读的经过时长(如 65s → 1m5s)。 */
215
+ function formatElapsed(ms: number | undefined): string {
216
+ if (ms === undefined || !Number.isFinite(ms) || ms < 0) return '';
217
+ if (ms < 1000) return `${Math.round(ms)}ms`;
218
+ const s = Math.round(ms / 1000);
219
+ if (s < 60) return `${s}s`;
220
+ return `${Math.floor(s / 60)}m${s % 60 > 0 ? `${s % 60}s` : ''}`;
221
+ }
222
+
223
+ /** 模板填充所需的上下文(全部可选, 缺失的占位符填为空串)。 */
224
+ export interface TemplateContext {
225
+ /** 失败事实(错误码/消息/HTTP 状态), 对应 {code}/{message}/{status}。 */
226
+ facts?: FailureFacts;
227
+ /** 失败前最后一次工具调用的名称, 对应 {tool}。 */
228
+ tool?: string;
229
+ /** 失败回合的编号, 对应 {turn}。 */
230
+ turn?: number;
231
+ /** 连续失败次数(含本次), 对应 {errorCount}。 */
232
+ errorCount?: number;
233
+ /** 会话标题(来自 session.list 投影, 可用时), 对应 {sessionTitle}。 */
234
+ sessionTitle?: string;
235
+ /** 自失败发生以来的毫秒数, 对应 {elapsed}。 */
236
+ elapsedMs?: number;
237
+ /** 上一步工具结果摘要(截断), 对应 {result}(护栏模板用)。 */
238
+ result?: string;
239
+ }
240
+
241
+ /** 用失败事实与回合信息填充 continueText 模板占位符({code}/{message}/{status}/{tool}/{turn}/{errorCount}/{sessionTitle}/{elapsed}/{result})。 */
242
+ export function fillTemplate(template: string, ctx: TemplateContext): string {
243
+ return template
244
+ .replace(/\{code\}/g, ctx.facts?.code ?? '')
245
+ .replace(/\{message\}/g, ctx.facts?.message ?? '')
246
+ .replace(/\{status\}/g, ctx.facts?.status !== undefined ? String(ctx.facts.status) : '')
247
+ .replace(/\{tool\}/g, ctx.tool ?? '')
248
+ .replace(/\{turn\}/g, ctx.turn !== undefined ? String(ctx.turn) : '')
249
+ .replace(/\{errorCount\}/g, ctx.errorCount !== undefined ? String(ctx.errorCount) : '')
250
+ .replace(/\{sessionTitle\}/g, ctx.sessionTitle ?? '')
251
+ .replace(/\{elapsed\}/g, formatElapsed(ctx.elapsedMs))
252
+ .replace(/\{result\}/g, ctx.result ?? '');
253
+ }
254
+
255
+ // ---------- 幂等护栏: 上一步工具调用的执行状态 ----------
256
+
257
+ /** 工具结果摘要的最大长度(护栏模板 {result} 用)。 */
258
+ const TOOL_RESULT_CAP = 160;
259
+
260
+ /** 从任意内容块里递归收集文本(结果为模型可见的工具输出)。 */
261
+ function extractText(blocks: unknown, cap: number): string {
262
+ let out = '';
263
+ const walk = (value: unknown): void => {
264
+ if (out.length >= cap) return;
265
+ if (Array.isArray(value)) {
266
+ for (const item of value) walk(item);
267
+ return;
268
+ }
269
+ if (typeof value !== 'object' || value === null) return;
270
+ const record = value as Record<string, unknown>;
271
+ if (record['type'] === 'text' && typeof record['text'] === 'string') {
272
+ out += record['text'];
273
+ return;
274
+ }
275
+ for (const child of Object.values(record)) walk(child);
276
+ };
277
+ walk(blocks);
278
+ return out.slice(0, cap);
279
+ }
280
+
281
+ /** 上一步工具调用的判定结果: 是否已确认完成, 以及文本摘要。 */
282
+ export interface ToolResultFacts {
283
+ /** 工具是否成功完成(内部失败或 isError 视为未成功)。 */
284
+ ok: boolean;
285
+ /** 工具输出的文本摘要(截断)。 */
286
+ excerpt: string;
287
+ }
288
+
289
+ /** 从 tool/result 事件载荷提取成功与否与文本摘要。 */
290
+ export function toolResultFacts(data: {
291
+ error?: { name?: string; code?: string };
292
+ message?: { content?: Array<{ type?: string; content?: unknown; isError?: boolean }> };
293
+ }): ToolResultFacts {
294
+ const failed = data.error !== undefined || data.message?.content?.[0]?.isError === true;
295
+ return { ok: !failed, excerpt: extractText(data.message?.content?.[0]?.content, TOOL_RESULT_CAP) };
296
+ }
297
+
298
+ /** 自适应退避: 同一会话连续失败时的有效冷却间隔。 */
299
+ export function effectiveCooldown(
300
+ consecutive: number,
301
+ base: number,
302
+ factor: number,
303
+ max: number,
304
+ ): number {
305
+ // consecutive = 已连续自动继续的次数; 第 1 次后开始按 factor 递增
306
+ const multiplier = Math.pow(factor, consecutive);
307
+ return Math.min(Math.max(base, base * multiplier), Math.max(base, max));
308
+ }
309
+
310
+ export function sleep(ms: number): Promise<void> {
311
+ return new Promise((resolve) => setTimeout(resolve, ms));
312
+ }
313
+
314
+ /** 浏览器当前 IANA 时区; 不可用时省略(宿主允许省略)。 */
315
+ function clientTimeZone(): string | undefined {
316
+ try {
317
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || undefined;
318
+ } catch {
319
+ return undefined;
320
+ }
321
+ }
322
+
323
+ /** 一天的自动继续统计(host 单实例内存态)。 */
324
+ export interface DayStats {
325
+ /** 本地日期 YYYY-MM-DD。 */
326
+ date: string;
327
+ /** 自动发送次数。 */
328
+ sent: number;
329
+ /** 因永久性错误跳过的次数。 */
330
+ skipped: number;
331
+ /** 发送后回合成功完成(恢复成功)的次数。 */
332
+ recovered: number;
333
+ /** 发送后再次失败的次数。 */
334
+ failed: number;
335
+ /** 达到连续上限而停止的次数(按停止事件计)。 */
336
+ gaveUp: number;
337
+ /** loop guard 打断并重启回合的次数。 */
338
+ looped: number;
339
+ /** 按错误码计数的失败分布。 */
340
+ byCode: Record<string, number>;
341
+ }
342
+
343
+ export function todayKey(): string {
344
+ const d = new Date();
345
+ const mm = String(d.getMonth() + 1).padStart(2, '0');
346
+ const dd = String(d.getDate()).padStart(2, '0');
347
+ return `${d.getFullYear()}-${mm}-${dd}`;
348
+ }
349
+
350
+ /** 空统计桶。 */
351
+ export function emptyDayStats(): DayStats {
352
+ return { date: todayKey(), sent: 0, skipped: 0, recovered: 0, failed: 0, gaveUp: 0, looped: 0, byCode: {} };
353
+ }
354
+
355
+ /** 每会话运行时状态。 */
356
+ export interface SessionState {
357
+ /** 连续自动「继续」次数; 成功回合或用户手动介入后归零。 */
358
+ consecutive: number;
359
+ /** 上次自动「继续」时间戳。 */
360
+ lastAutoAt: number;
361
+ /** 上次自动「继续」尝试(成功或失败)时间戳; 防止失败场景下的快速重试循环。 */
362
+ lastAttemptAt: number;
363
+ /** 我们上次自动发送的文本(用于识别自己的回显)。 */
364
+ lastSentText: string;
365
+ /** 宽限期定时器(进行中的待发送)。 */
366
+ pendingTimer: ReturnType<typeof setTimeout> | undefined;
367
+ /** 宿主权威 running 位(来自 host/session-status 与回合事件)。 */
368
+ running: boolean | undefined;
369
+ /** 当前排队消息数(来自 session/queue 帧)。 */
370
+ queued: number;
371
+ /** 子代理会话(host/session-added 带 parentSessionId)。 */
372
+ subagent: boolean;
373
+ /** 最近一次回合失败的事实(用于分类与模板填充)。 */
374
+ lastFailure: FailureFacts | undefined;
375
+ /** 最近一次失败的发生时间(模板 {elapsed} 与恢复统计用)。 */
376
+ lastFailureAt: number;
377
+ /** 失败前最后一次工具调用的名称(模板 {tool} 与幂等护栏用)。 */
378
+ lastTool: string | undefined;
379
+ /** 上一步工具调用的结果状态: 'pending' = 已发起未见结果(可能已部分执行)。 */
380
+ lastToolResult: 'pending' | ToolResultFacts | undefined;
381
+ /** 失败回合的编号(模板 {turn})。 */
382
+ lastTurn: number | undefined;
383
+ /** 我们最近一次自动发送的时间戳; 0 = 没有待确认的恢复。 */
384
+ pendingRecoveryAt: number;
385
+ /** 当前连续短句数(loop guard 信号 1: 空转)。 */
386
+ shortRun: number;
387
+ /** 最后一条短句的时间(时间窗判定用)。 */
388
+ lastShortAt: number;
389
+ /** 最后一条模型消息的文本(相同文本重复判定用)。 */
390
+ lastAssistantText: string;
391
+ /** 连续相同文本消息数(最强空转信号, 不限长度)。 */
392
+ sameTextRun: number;
393
+ /**
394
+ * 工具重复信号(loop guard 信号 2: 死循环)。
395
+ * 只有「同工具 + 同参数 + 同结果」的连续调用才累计; 参数或结果有变化视为有进展, 计数重置。
396
+ */
397
+ toolRun:
398
+ | {
399
+ /** 工具名 + 参数(用于判定是否同一调用)。 */
400
+ key: string;
401
+ /** 连续相同调用数(结果确认后更新)。 */
402
+ count: number;
403
+ /** 上次该调用的结果摘要(比较用)。 */
404
+ lastResult: string | undefined;
405
+ /** 本次调用等待结果确认。 */
406
+ waiting: boolean;
407
+ }
408
+ | undefined;
409
+ /** 本回合已触发过 loop guard(防重复打断)。 */
410
+ loopFired: boolean;
411
+ /** loop 重启的延迟定时器(冷却结束后再 schedule)。 */
412
+ loopRetryTimer: ReturnType<typeof setTimeout> | undefined;
413
+ /** 我们主动 cancel 过本回合(区分用户停止)。 */
414
+ loopCancelled: boolean;
415
+ }
416
+
417
+ export const freshState = (): SessionState => ({
418
+ consecutive: 0,
419
+ lastAutoAt: 0,
420
+ lastAttemptAt: 0,
421
+ lastSentText: '',
422
+ pendingTimer: undefined,
423
+ running: undefined,
424
+ queued: 0,
425
+ subagent: false,
426
+ lastFailure: undefined,
427
+ lastFailureAt: 0,
428
+ lastTool: undefined,
429
+ lastToolResult: undefined,
430
+ lastTurn: undefined,
431
+ pendingRecoveryAt: 0,
432
+ shortRun: 0,
433
+ lastShortAt: 0,
434
+ lastAssistantText: '',
435
+ sameTextRun: 0,
436
+ toolRun: undefined,
437
+ loopFired: false,
438
+ loopCancelled: false,
439
+ loopRetryTimer: undefined,
440
+ });
441
+
442
+
443
+ export const RECOVERY_WINDOW_MS = 10 * 60 * 1000;
444
+
445
+ export const ECHO_WINDOW_MS = 10 * 60 * 1000;
446
+
447
+ export function isOurEcho(state: SessionState, event: SessionEvent): boolean {
448
+ if (event.type !== 'user/message') return false;
449
+ const message = event.data;
450
+ if (message.source.kind !== 'user') return false;
451
+ if (state.lastSentText === '') return false;
452
+ if (Date.now() - state.lastAutoAt > ECHO_WINDOW_MS) return false;
453
+ const text = message.content
454
+ .filter((part): part is { type: 'text'; text: string } => part.type === 'text')
455
+ .map((part) => part.text)
456
+ .join('');
457
+ return text === state.lastSentText;
458
+ }