@runtypelabs/persona 4.25.0 → 4.26.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/dist/animations/glyph-cycle.d.cts +1 -1
- package/dist/animations/glyph-cycle.d.ts +1 -1
- package/dist/animations/{types-Db61aI9J.d.cts → types-BwKTZhg9.d.cts} +14 -0
- package/dist/animations/{types-Db61aI9J.d.ts → types-BwKTZhg9.d.ts} +14 -0
- package/dist/animations/wipe.d.cts +1 -1
- package/dist/animations/wipe.d.ts +1 -1
- package/dist/animations-extra.d.cts +14 -0
- package/dist/animations-extra.d.ts +14 -0
- package/dist/approval-ui-QAKWNFNM.js +1 -0
- package/dist/approval-ui.cjs +2 -2
- package/dist/approval-ui.d.cts +180 -8
- package/dist/approval-ui.d.ts +180 -8
- package/dist/approval-ui.js +2 -2
- package/dist/{artifacts-ui-IGB5YKLO.js → artifacts-ui-NJGMM27I.js} +1 -1
- package/dist/artifacts-ui.cjs +4 -4
- package/dist/artifacts-ui.d.cts +180 -8
- package/dist/artifacts-ui.d.ts +180 -8
- package/dist/artifacts-ui.js +5 -5
- package/dist/chunk-2ANTRKTV.js +1 -0
- package/dist/chunk-4HPTPUC6.js +1 -0
- package/dist/chunk-6V3MNEKB.js +1 -0
- package/dist/chunk-HGUCGM3K.js +9 -0
- package/dist/chunk-IO5VVUKP.js +3 -0
- package/dist/chunk-J4J3Y2P2.js +1 -0
- package/dist/chunk-K6HKIP5K.js +1 -0
- package/dist/chunk-K7NA7G7J.js +1 -0
- package/dist/chunk-MXUTS3LB.js +1 -0
- package/dist/chunk-PDPVORUF.js +1 -0
- package/dist/chunk-QPPJUSZH.js +1 -0
- package/dist/chunk-QRKGQPU7.js +1 -0
- package/dist/chunk-S6PBWE75.js +1 -0
- package/dist/chunk-T7QM7YMF.js +1 -0
- package/dist/chunk-TR2H475E.js +1 -0
- package/dist/chunk-UPO4GUFC.js +1 -0
- package/dist/chunk-ZC66NAIR.js +1 -0
- package/dist/client-history-YPEG45Q4.js +1 -0
- package/dist/client-history.js +1 -0
- package/dist/client-stream-42FOI3EC.js +4 -0
- package/dist/client-stream.js +5 -0
- package/dist/codegen.cjs +1 -1
- package/dist/codegen.js +1 -1
- package/dist/context-mentions-E7HJYWO6.js +161 -0
- package/dist/{context-mentions-inline-I2RDEBAK.js → context-mentions-inline-QVESLW55.js} +1 -1
- package/dist/context-mentions.cjs +7 -7
- package/dist/context-mentions.d.cts +180 -8
- package/dist/context-mentions.d.ts +180 -8
- package/dist/context-mentions.js +8 -8
- package/dist/event-stream-view-FOIJHFQO.js +1 -0
- package/dist/event-stream-view.cjs +1 -1
- package/dist/event-stream-view.d.cts +183 -31
- package/dist/event-stream-view.d.ts +183 -31
- package/dist/event-stream-view.js +1 -1
- package/dist/forms-ui.d.cts +221 -667
- package/dist/forms-ui.d.ts +221 -667
- package/dist/history-shell-QDQ44PSE.js +3 -0
- package/dist/history-shell.js +3 -0
- package/dist/{history-view-BD6OXLNA.js → history-view-NCFBI5GR.js} +2 -2
- package/dist/history-view.cjs +2 -2
- package/dist/history-view.d.cts +35 -1
- package/dist/history-view.d.ts +35 -1
- package/dist/history-view.js +2 -2
- package/dist/index.cjs +80 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +227 -738
- package/dist/index.d.ts +227 -738
- package/dist/index.global.js +3 -215
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +81 -75
- package/dist/index.js.map +1 -1
- package/dist/install.global.js +1 -1
- package/dist/install.global.js.map +1 -1
- package/dist/launcher.global.js +3 -67
- package/dist/launcher.global.js.map +1 -1
- package/dist/markdown-parsers.js +22 -22
- package/dist/runtype-tts-entry-NFBVWR7N.js +1 -0
- package/dist/runtype-tts.js +1 -1
- package/dist/session-actions-ISSKSI66.js +1 -0
- package/dist/session-actions.js +1 -0
- package/dist/session-reconnect.d.cts +180 -8
- package/dist/session-reconnect.d.ts +180 -8
- package/dist/smart-dom-reader.cjs +13 -13
- package/dist/smart-dom-reader.d.cts +180 -8
- package/dist/smart-dom-reader.d.ts +180 -8
- package/dist/smart-dom-reader.js +11 -11
- package/dist/theme-editor-preview.cjs +116 -98
- package/dist/theme-editor-preview.d.cts +182 -8
- package/dist/theme-editor-preview.d.ts +182 -8
- package/dist/theme-editor-preview.js +49 -54
- package/dist/theme-editor.cjs +2 -2
- package/dist/theme-editor.d.cts +181 -23
- package/dist/theme-editor.d.ts +181 -23
- package/dist/theme-editor.js +2 -2
- package/dist/theme-reference.d.cts +14 -0
- package/dist/theme-reference.d.ts +14 -0
- package/dist/ui-extras-entry-WAYFKVNW.js +3 -0
- package/dist/ui-extras.js +72 -0
- package/dist/voice-runtime-UOQOFAFY.js +17 -0
- package/dist/voice-runtime.cjs +17 -1
- package/dist/voice-runtime.d.cts +11650 -232
- package/dist/voice-runtime.d.ts +11650 -232
- package/dist/voice-runtime.js +17 -1
- package/dist/voice-worklet-player.cjs +19 -4
- package/dist/voice-worklet-player.d.cts +9 -10
- package/dist/voice-worklet-player.d.ts +9 -10
- package/dist/voice-worklet-player.js +19 -4
- package/dist/webmcp-polyfill.js +1 -1
- package/dist/webmcp-runtime-V6ZWW3PI.js +6 -0
- package/dist/webmcp-runtime.cjs +2 -2
- package/dist/webmcp-runtime.d.cts +1 -33
- package/dist/webmcp-runtime.d.ts +1 -33
- package/dist/webmcp-runtime.js +2 -2
- package/dist/widget.css +1 -1
- package/package.json +11 -5
- package/src/approval-paused-tool-settle.test.ts +221 -0
- package/src/client-approve.test.ts +311 -0
- package/src/client-history-eager.ts +9 -0
- package/src/client-history-loader.ts +23 -0
- package/src/client-history.ts +579 -0
- package/src/client-resume.ts +177 -0
- package/src/client-stream-eager.ts +12 -0
- package/src/client-stream-loader.ts +25 -0
- package/src/client-stream.ts +1880 -0
- package/src/client.test.ts +31 -1
- package/src/client.ts +293 -2607
- package/src/components/approval-actions.test.ts +27 -0
- package/src/components/approval-actions.ts +27 -3
- package/src/components/message-bubble.test.ts +19 -0
- package/src/components/message-bubble.ts +2 -0
- package/src/components/registry.ts +6 -6
- package/src/components/tool-bubble.test.ts +9 -0
- package/src/components/tool-bubble.ts +1 -0
- package/src/history-shell-bundle.test.ts +54 -0
- package/src/history-shell-eager.ts +12 -0
- package/src/history-shell-loader.ts +27 -0
- package/src/history-shell.ts +2362 -0
- package/src/history-view-loader.ts +2 -0
- package/src/history-view.ts +3 -0
- package/src/index-core.ts +6 -0
- package/src/index-global.ts +90 -248
- package/src/index.ts +13 -0
- package/src/install.ts +6 -4
- package/src/internal/runtype-history-provider.test.ts +1 -0
- package/src/internal/runtype-history-provider.ts +28 -13
- package/src/plugins/registry.ts +8 -8
- package/src/session-actions-chunk.test.ts +55 -0
- package/src/session-actions-eager.ts +11 -0
- package/src/session-actions-loader.ts +37 -0
- package/src/session-actions.ts +909 -0
- package/src/session-history.test.ts +3 -1
- package/src/session.ts +852 -1536
- package/src/session.voice.test.ts +1170 -5
- package/src/styles/widget.css +58 -0
- package/src/theme-editor/state.ts +91 -91
- package/src/types.ts +198 -5
- package/src/ui-ask-user-sheet.ts +382 -0
- package/src/ui-extras-eager.ts +10 -0
- package/src/ui-extras-entry.ts +9 -0
- package/src/ui-extras-loader.ts +26 -0
- package/src/ui.artifact-rail-resize.test.ts +2 -1
- package/src/ui.ask-user-chunk.test.ts +93 -0
- package/src/ui.history-chunk.test.ts +2 -1
- package/src/ui.history-config-provider.test.ts +2 -1
- package/src/ui.history-confirm-fallback.test.ts +142 -0
- package/src/ui.history-controller.test.ts +2 -1
- package/src/ui.history-lifecycle.test.ts +2 -1
- package/src/ui.history-render-hooks.test.ts +2 -1
- package/src/ui.history-shell.test.ts +2 -1
- package/src/ui.rail-overlay.test.ts +2 -1
- package/src/ui.rail-resize.test.ts +2 -1
- package/src/ui.rail-trigger-pending.test.ts +2 -1
- package/src/ui.ts +340 -2770
- package/src/utils/attachment-manager.ts +67 -67
- package/src/utils/constants.ts +3 -0
- package/src/utils/context-mention-controller.ts +323 -323
- package/src/utils/context-mention-manager.ts +40 -40
- package/src/utils/context-mention-orchestrator.ts +28 -0
- package/src/utils/event-stream-buffer.ts +50 -50
- package/src/utils/event-stream-store.ts +43 -43
- package/src/utils/throughput-tracker.ts +34 -34
- package/src/utils/virtual-scroller.ts +67 -67
- package/src/utils/visitor-store.test.ts +50 -0
- package/src/utils/visitor-store.ts +23 -5
- package/src/voice/__fixtures__/voice-wire/README.md +1 -0
- package/src/voice/__fixtures__/voice-wire/client/cancel.json +3 -0
- package/src/voice/__fixtures__/voice-wire/client/context.json +4 -0
- package/src/voice/__fixtures__/voice-wire/client/delegation_result.json +6 -0
- package/src/voice/__fixtures__/voice-wire/client/delegation_update.json +6 -0
- package/src/voice/__fixtures__/voice-wire/client/ping.json +3 -0
- package/src/voice/__fixtures__/voice-wire/client/playback_progress.json +5 -0
- package/src/voice/__fixtures__/voice-wire/client/start.json +3 -0
- package/src/voice/__fixtures__/voice-wire/server/artifact.json +11 -0
- package/src/voice/__fixtures__/voice-wire/server/attached.json +4 -0
- package/src/voice/__fixtures__/voice-wire/server/audio_clear.json +4 -0
- package/src/voice/__fixtures__/voice-wire/server/audio_end.json +3 -0
- package/src/voice/__fixtures__/voice-wire/server/delegation_cancelled.json +5 -0
- package/src/voice/__fixtures__/voice-wire/server/delegation_completed.json +8 -0
- package/src/voice/__fixtures__/voice-wire/server/delegation_started.json +15 -0
- package/src/voice/__fixtures__/voice-wire/server/error.json +6 -0
- package/src/voice/__fixtures__/voice-wire/server/metrics.json +10 -0
- package/src/voice/__fixtures__/voice-wire/server/pong.json +3 -0
- package/src/voice/__fixtures__/voice-wire/server/session_config.json +16 -0
- package/src/voice/__fixtures__/voice-wire/server/transcript_final.json +7 -0
- package/src/voice/__fixtures__/voice-wire/server/transcript_interim.json +4 -0
- package/src/voice/__fixtures__/voice-wire/server/transcript_partial.json +6 -0
- package/src/voice/__fixtures__/voice-wire/server/transcript_update.json +10 -0
- package/src/voice/__fixtures__/voice-wire/server/warning.json +5 -0
- package/src/voice/audio-playback-manager.test.ts +57 -0
- package/src/voice/audio-playback-manager.ts +120 -98
- package/src/voice/browser-voice-provider.ts +37 -37
- package/src/voice/fallback-speech-engine.ts +22 -16
- package/src/voice/keyed-voice-transcript.ts +314 -0
- package/src/voice/mic-state-styles.ts +182 -0
- package/src/voice/read-aloud-controller.ts +46 -44
- package/src/voice/runtype-speech-engine.ts +35 -33
- package/src/voice/runtype-voice-provider.ts +670 -189
- package/src/voice/session-voice-wiring.ts +266 -0
- package/src/voice/voice-delegation.test.ts +71 -0
- package/src/voice/voice-delegation.ts +364 -0
- package/src/voice/voice-turn-tracker.ts +6 -6
- package/src/voice/voice.test.ts +981 -8
- package/src/voice/worklet-playback-engine.test.ts +81 -0
- package/src/voice/worklet-playback-engine.ts +21 -3
- package/src/voice-runtime-loader.ts +4 -1
- package/src/voice-runtime.ts +7 -0
- package/src/webmcp-runtime-entry.ts +41 -39
- package/dist/approval-ui-3NMYNXBD.js +0 -1
- package/dist/chunk-5EIIHQLQ.js +0 -1
- package/dist/chunk-7CO4T5KB.js +0 -1
- package/dist/chunk-EFJBUH5F.js +0 -1
- package/dist/chunk-R2TMIMDI.js +0 -3
- package/dist/chunk-UTVLOTWB.js +0 -9
- package/dist/context-mentions-45MODWOY.js +0 -161
- package/dist/event-stream-view-GL3ADRY2.js +0 -1
- package/dist/runtype-tts-entry-UJAEF7NZ.js +0 -1
- package/dist/voice-runtime-7DA7MJH4.js +0 -1
- package/dist/webmcp-runtime-JI7T4QYF.js +0 -6
|
@@ -123,8 +123,8 @@ function defaultClock(): number {
|
|
|
123
123
|
* event via {@link processEvent}; read the current state via {@link getMetric}.
|
|
124
124
|
*/
|
|
125
125
|
export class ThroughputTracker {
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
#metric: ThroughputMetric = { status: "idle" };
|
|
127
|
+
#run: ThroughputRunStats | null = null;
|
|
128
128
|
private readonly now: () => number;
|
|
129
129
|
|
|
130
130
|
constructor(now: () => number = defaultClock) {
|
|
@@ -136,47 +136,47 @@ export class ThroughputTracker {
|
|
|
136
136
|
// clock on each read. The view polls this every ~200ms, so without this a
|
|
137
137
|
// pause between deltas would keep showing the stale rate from the last
|
|
138
138
|
// event; recomputing lets the displayed tok/s decay as time passes.
|
|
139
|
-
const run = this
|
|
139
|
+
const run = this.#run;
|
|
140
140
|
if (
|
|
141
141
|
run &&
|
|
142
|
-
this
|
|
142
|
+
this.#metric.status === "running" &&
|
|
143
143
|
run.firstDeltaAt !== undefined &&
|
|
144
|
-
this
|
|
144
|
+
this.#metric.outputTokens !== undefined
|
|
145
145
|
) {
|
|
146
146
|
const durationMs = this.now() - run.firstDeltaAt;
|
|
147
147
|
return {
|
|
148
|
-
...this
|
|
148
|
+
...this.#metric,
|
|
149
149
|
durationMs,
|
|
150
150
|
tokensPerSecond: calculateTokensPerSecond(
|
|
151
|
-
this
|
|
151
|
+
this.#metric.outputTokens,
|
|
152
152
|
durationMs
|
|
153
153
|
),
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
|
-
return this
|
|
156
|
+
return this.#metric;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
/** Reset back to idle (e.g. when the chat is cleared). */
|
|
160
160
|
reset(): void {
|
|
161
|
-
this
|
|
162
|
-
this
|
|
161
|
+
this.#run = null;
|
|
162
|
+
this.#metric = { status: "idle" };
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
|
|
166
|
-
this
|
|
165
|
+
#startRun(now: number): void {
|
|
166
|
+
this.#run = {
|
|
167
167
|
startedAt: now,
|
|
168
168
|
visibleCharCount: 0,
|
|
169
169
|
exactOutputTokens: 0,
|
|
170
170
|
};
|
|
171
|
-
this
|
|
171
|
+
this.#metric = { status: "running" };
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
processEvent(eventType: string, payload: unknown): void {
|
|
175
175
|
if (!isRecord(payload)) {
|
|
176
176
|
// Non-object payloads can still signal lifecycle (e.g. bare "execution_error").
|
|
177
|
-
if (eventType === "execution_error" && this
|
|
178
|
-
this
|
|
179
|
-
this
|
|
177
|
+
if (eventType === "execution_error" && this.#run) {
|
|
178
|
+
this.#run = null;
|
|
179
|
+
this.#metric = { status: "error" };
|
|
180
180
|
}
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
@@ -186,13 +186,13 @@ export class ThroughputTracker {
|
|
|
186
186
|
|
|
187
187
|
if (type === "execution_start") {
|
|
188
188
|
// New request: start fresh, discarding any incomplete prior run.
|
|
189
|
-
this
|
|
189
|
+
this.#startRun(now);
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
if (STEP_START_EVENTS.has(type)) {
|
|
194
194
|
// Mid-request step marker: only begin a run if none is active.
|
|
195
|
-
if (!this
|
|
195
|
+
if (!this.#run) this.#startRun(now);
|
|
196
196
|
return;
|
|
197
197
|
}
|
|
198
198
|
|
|
@@ -201,8 +201,8 @@ export class ThroughputTracker {
|
|
|
201
201
|
if (!text) return;
|
|
202
202
|
|
|
203
203
|
// Lazily start a run if the stream began without a recognized start event.
|
|
204
|
-
if (!this
|
|
205
|
-
const stats = this
|
|
204
|
+
if (!this.#run) this.#startRun(now);
|
|
205
|
+
const stats = this.#run!;
|
|
206
206
|
|
|
207
207
|
stats.firstDeltaAt ??= now;
|
|
208
208
|
stats.visibleCharCount += text.length;
|
|
@@ -214,7 +214,7 @@ export class ThroughputTracker {
|
|
|
214
214
|
stats.exactOutputTokens +
|
|
215
215
|
estimateTokensFromCharCount(stats.visibleCharCount);
|
|
216
216
|
const durationMs = now - stats.firstDeltaAt;
|
|
217
|
-
this
|
|
217
|
+
this.#metric = {
|
|
218
218
|
status: "running",
|
|
219
219
|
tokensPerSecond: calculateTokensPerSecond(outputTokens, durationMs),
|
|
220
220
|
outputTokens,
|
|
@@ -227,8 +227,8 @@ export class ThroughputTracker {
|
|
|
227
227
|
if (INTERMEDIATE_COMPLETE_EVENTS.has(type)) {
|
|
228
228
|
// Accumulate exact usage but keep the run going: these fire per
|
|
229
229
|
// step/turn, not at the end of the whole run.
|
|
230
|
-
if (!this
|
|
231
|
-
const stats = this
|
|
230
|
+
if (!this.#run) return;
|
|
231
|
+
const stats = this.#run;
|
|
232
232
|
const exact = getOutputTokens(payload);
|
|
233
233
|
if (exact !== undefined) {
|
|
234
234
|
stats.exactOutputTokens += exact;
|
|
@@ -242,8 +242,8 @@ export class ThroughputTracker {
|
|
|
242
242
|
const outputTokens =
|
|
243
243
|
stats.exactOutputTokens +
|
|
244
244
|
estimateTokensFromCharCount(stats.visibleCharCount);
|
|
245
|
-
const durationMs = this
|
|
246
|
-
this
|
|
245
|
+
const durationMs = this.#resolveDuration(stats, payload, now);
|
|
246
|
+
this.#metric = {
|
|
247
247
|
status: "running",
|
|
248
248
|
tokensPerSecond: calculateTokensPerSecond(outputTokens, durationMs),
|
|
249
249
|
outputTokens,
|
|
@@ -254,8 +254,8 @@ export class ThroughputTracker {
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
if (type === "execution_complete") {
|
|
257
|
-
if (!this
|
|
258
|
-
const stats = this
|
|
257
|
+
if (!this.#run) return;
|
|
258
|
+
const stats = this.#run;
|
|
259
259
|
// Prefer exact output tokens from this terminal event, else accumulated
|
|
260
260
|
// usage from intermediate completes, else the text estimate.
|
|
261
261
|
const terminalExact = getOutputTokens(payload);
|
|
@@ -270,22 +270,22 @@ export class ThroughputTracker {
|
|
|
270
270
|
terminalExact !== undefined || stats.exactOutputTokens > 0
|
|
271
271
|
? "usage"
|
|
272
272
|
: "estimate";
|
|
273
|
-
const durationMs = this
|
|
274
|
-
this
|
|
273
|
+
const durationMs = this.#resolveDuration(stats, payload, now);
|
|
274
|
+
this.#metric = {
|
|
275
275
|
status: "complete",
|
|
276
276
|
tokensPerSecond: calculateTokensPerSecond(outputTokens, durationMs),
|
|
277
277
|
outputTokens,
|
|
278
278
|
durationMs,
|
|
279
279
|
source,
|
|
280
280
|
};
|
|
281
|
-
this
|
|
281
|
+
this.#run = null;
|
|
282
282
|
return;
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
if (type === "execution_error" || (type === "error" && payload.recoverable === false)) {
|
|
286
|
-
if (!this
|
|
287
|
-
this
|
|
288
|
-
this
|
|
286
|
+
if (!this.#run) return;
|
|
287
|
+
this.#run = null;
|
|
288
|
+
this.#metric = { status: "error" };
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
|
|
@@ -294,7 +294,7 @@ export class ThroughputTracker {
|
|
|
294
294
|
* threshold; otherwise fall back to provider execution time, then to the
|
|
295
295
|
* whole-request duration.
|
|
296
296
|
*/
|
|
297
|
-
|
|
297
|
+
#resolveDuration(
|
|
298
298
|
stats: ThroughputRunStats,
|
|
299
299
|
payload: Record<string, unknown>,
|
|
300
300
|
now: number
|
|
@@ -6,146 +6,146 @@ export interface VirtualScrollerOptions {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export class VirtualScroller {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
#container: HTMLElement;
|
|
10
|
+
#rowHeight: number;
|
|
11
|
+
#overscan: number;
|
|
12
|
+
#renderRow: (index: number) => HTMLElement;
|
|
13
|
+
#totalCount = 0;
|
|
14
|
+
#spacer: HTMLElement;
|
|
15
|
+
#viewport: HTMLElement;
|
|
16
|
+
#visibleRows: Map<number, HTMLElement> = new Map();
|
|
17
|
+
#scrollRAF: number | null = null;
|
|
18
|
+
#isAutoScrolling = false;
|
|
19
|
+
#onScroll: () => void;
|
|
20
20
|
|
|
21
21
|
constructor(options: VirtualScrollerOptions) {
|
|
22
|
-
this
|
|
23
|
-
this
|
|
24
|
-
this
|
|
25
|
-
this
|
|
22
|
+
this.#container = options.container;
|
|
23
|
+
this.#rowHeight = options.rowHeight ?? 40;
|
|
24
|
+
this.#overscan = options.overscan ?? 5;
|
|
25
|
+
this.#renderRow = options.renderRow;
|
|
26
26
|
|
|
27
27
|
// Create spacer (provides full scrollable height)
|
|
28
|
-
this
|
|
29
|
-
this
|
|
30
|
-
this
|
|
31
|
-
this
|
|
28
|
+
this.#spacer = document.createElement("div");
|
|
29
|
+
this.#spacer.style.position = "relative";
|
|
30
|
+
this.#spacer.style.width = "100%";
|
|
31
|
+
this.#spacer.style.height = "0px";
|
|
32
32
|
|
|
33
33
|
// Create viewport (holds visible rows)
|
|
34
|
-
this
|
|
35
|
-
this
|
|
36
|
-
this
|
|
37
|
-
this
|
|
38
|
-
this
|
|
34
|
+
this.#viewport = document.createElement("div");
|
|
35
|
+
this.#viewport.style.position = "absolute";
|
|
36
|
+
this.#viewport.style.top = "0";
|
|
37
|
+
this.#viewport.style.left = "0";
|
|
38
|
+
this.#viewport.style.right = "0";
|
|
39
39
|
|
|
40
|
-
this
|
|
41
|
-
this
|
|
40
|
+
this.#spacer.appendChild(this.#viewport);
|
|
41
|
+
this.#container.appendChild(this.#spacer);
|
|
42
42
|
|
|
43
43
|
// Throttled scroll handler via RAF
|
|
44
|
-
this
|
|
45
|
-
if (this
|
|
46
|
-
this
|
|
47
|
-
this
|
|
44
|
+
this.#onScroll = () => {
|
|
45
|
+
if (this.#scrollRAF !== null) return;
|
|
46
|
+
this.#scrollRAF = requestAnimationFrame(() => {
|
|
47
|
+
this.#scrollRAF = null;
|
|
48
48
|
this.render();
|
|
49
49
|
});
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
this
|
|
52
|
+
this.#container.addEventListener("scroll", this.#onScroll);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
setTotalCount(count: number): void {
|
|
56
|
-
this
|
|
57
|
-
this
|
|
56
|
+
this.#totalCount = count;
|
|
57
|
+
this.#spacer.style.height = `${count * this.#rowHeight}px`;
|
|
58
58
|
// Always invalidate cached rows: data may have changed even at the same count
|
|
59
|
-
for (const [, el] of this
|
|
59
|
+
for (const [, el] of this.#visibleRows) {
|
|
60
60
|
el.remove();
|
|
61
61
|
}
|
|
62
|
-
this
|
|
62
|
+
this.#visibleRows.clear();
|
|
63
63
|
this.render();
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
render(): void {
|
|
67
|
-
if (this
|
|
67
|
+
if (this.#totalCount === 0) {
|
|
68
68
|
// Clear all visible rows
|
|
69
|
-
for (const [, el] of this
|
|
69
|
+
for (const [, el] of this.#visibleRows) {
|
|
70
70
|
el.remove();
|
|
71
71
|
}
|
|
72
|
-
this
|
|
72
|
+
this.#visibleRows.clear();
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
const scrollTop = this
|
|
77
|
-
const containerHeight = this
|
|
76
|
+
const scrollTop = this.#container.scrollTop;
|
|
77
|
+
const containerHeight = this.#container.clientHeight;
|
|
78
78
|
|
|
79
79
|
const startIndex = Math.max(
|
|
80
80
|
0,
|
|
81
|
-
Math.floor(scrollTop / this
|
|
81
|
+
Math.floor(scrollTop / this.#rowHeight) - this.#overscan
|
|
82
82
|
);
|
|
83
83
|
const endIndex = Math.min(
|
|
84
|
-
this
|
|
85
|
-
Math.ceil((scrollTop + containerHeight) / this
|
|
84
|
+
this.#totalCount,
|
|
85
|
+
Math.ceil((scrollTop + containerHeight) / this.#rowHeight) + this.#overscan
|
|
86
86
|
);
|
|
87
87
|
|
|
88
88
|
// Add new rows that should be visible
|
|
89
89
|
for (let i = startIndex; i < endIndex; i++) {
|
|
90
|
-
if (!this
|
|
91
|
-
const row = this
|
|
90
|
+
if (!this.#visibleRows.has(i)) {
|
|
91
|
+
const row = this.#renderRow(i);
|
|
92
92
|
row.style.position = "absolute";
|
|
93
93
|
row.style.top = "0";
|
|
94
94
|
row.style.left = "0";
|
|
95
95
|
row.style.right = "0";
|
|
96
|
-
row.style.height = `${this
|
|
97
|
-
row.style.transform = `translateY(${i * this
|
|
98
|
-
this
|
|
99
|
-
this
|
|
96
|
+
row.style.height = `${this.#rowHeight}px`;
|
|
97
|
+
row.style.transform = `translateY(${i * this.#rowHeight}px)`;
|
|
98
|
+
this.#viewport.appendChild(row);
|
|
99
|
+
this.#visibleRows.set(i, row);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
// Remove rows that are no longer visible
|
|
104
|
-
for (const [index, el] of this
|
|
104
|
+
for (const [index, el] of this.#visibleRows) {
|
|
105
105
|
if (index < startIndex || index >= endIndex) {
|
|
106
106
|
el.remove();
|
|
107
|
-
this
|
|
107
|
+
this.#visibleRows.delete(index);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
scrollToBottom(smooth?: boolean): void {
|
|
113
|
-
this
|
|
114
|
-
const target = this
|
|
113
|
+
this.#isAutoScrolling = true;
|
|
114
|
+
const target = this.#spacer.offsetHeight - this.#container.clientHeight;
|
|
115
115
|
if (smooth) {
|
|
116
|
-
this
|
|
116
|
+
this.#container.scrollTo({ top: target, behavior: "smooth" });
|
|
117
117
|
} else {
|
|
118
|
-
this
|
|
118
|
+
this.#container.scrollTop = target;
|
|
119
119
|
}
|
|
120
120
|
// Reset flag after scroll settles
|
|
121
121
|
requestAnimationFrame(() => {
|
|
122
|
-
this
|
|
122
|
+
this.#isAutoScrolling = false;
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
isNearBottom(threshold = 50): boolean {
|
|
127
127
|
return (
|
|
128
|
-
this
|
|
129
|
-
this
|
|
130
|
-
this
|
|
128
|
+
this.#container.scrollHeight -
|
|
129
|
+
this.#container.scrollTop -
|
|
130
|
+
this.#container.clientHeight <
|
|
131
131
|
threshold
|
|
132
132
|
);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
getIsAutoScrolling(): boolean {
|
|
136
|
-
return this
|
|
136
|
+
return this.#isAutoScrolling;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
destroy(): void {
|
|
140
|
-
this
|
|
141
|
-
if (this
|
|
142
|
-
cancelAnimationFrame(this
|
|
143
|
-
this
|
|
140
|
+
this.#container.removeEventListener("scroll", this.#onScroll);
|
|
141
|
+
if (this.#scrollRAF !== null) {
|
|
142
|
+
cancelAnimationFrame(this.#scrollRAF);
|
|
143
|
+
this.#scrollRAF = null;
|
|
144
144
|
}
|
|
145
|
-
for (const [, el] of this
|
|
145
|
+
for (const [, el] of this.#visibleRows) {
|
|
146
146
|
el.remove();
|
|
147
147
|
}
|
|
148
|
-
this
|
|
149
|
-
this
|
|
148
|
+
this.#visibleRows.clear();
|
|
149
|
+
this.#spacer.remove();
|
|
150
150
|
}
|
|
151
151
|
}
|
|
@@ -422,4 +422,54 @@ describe("visitor store", () => {
|
|
|
422
422
|
expect(b).toBe("b");
|
|
423
423
|
expect(window.localStorage.getItem(leaseKey)).toBeNull();
|
|
424
424
|
}, 20_000);
|
|
425
|
+
|
|
426
|
+
it("rejects a lease waiter destroyed before another tab releases the lock", async () => {
|
|
427
|
+
const { leaseKey } = await visitorStoreKeys(CLIENT_TOKEN, PREFIX);
|
|
428
|
+
// A live foreign lease: the waiter would normally poll until it expires.
|
|
429
|
+
window.localStorage.setItem(
|
|
430
|
+
leaseKey,
|
|
431
|
+
JSON.stringify({ ownerNonce: "other-tab", expiresAt: Date.now() + 8_000 })
|
|
432
|
+
);
|
|
433
|
+
const store = makeStore();
|
|
434
|
+
await store.ready;
|
|
435
|
+
const fn = vi.fn(async () => "minted");
|
|
436
|
+
|
|
437
|
+
const pending = store.withFirstInitLock(fn);
|
|
438
|
+
await flush();
|
|
439
|
+
expect(fn).not.toHaveBeenCalled();
|
|
440
|
+
|
|
441
|
+
const started = Date.now();
|
|
442
|
+
store.destroy();
|
|
443
|
+
|
|
444
|
+
await expect(pending).rejects.toThrow(/destroyed/);
|
|
445
|
+
// destroy() wakes the waiter; it must not sit out the 500ms poll floor.
|
|
446
|
+
expect(Date.now() - started).toBeLessThan(400);
|
|
447
|
+
expect(fn).not.toHaveBeenCalled();
|
|
448
|
+
expect(window.localStorage.getItem(leaseKey)).toContain("other-tab");
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
it("rejects a Web Locks waiter destroyed before its turn", async () => {
|
|
452
|
+
installFakeLocks();
|
|
453
|
+
const store = makeStore();
|
|
454
|
+
await store.ready;
|
|
455
|
+
|
|
456
|
+
let releaseFirst: () => void = () => {};
|
|
457
|
+
const firstGate = new Promise<void>((resolve) => {
|
|
458
|
+
releaseFirst = resolve;
|
|
459
|
+
});
|
|
460
|
+
const first = store.withFirstInitLock(async () => {
|
|
461
|
+
await firstGate;
|
|
462
|
+
return "a";
|
|
463
|
+
});
|
|
464
|
+
const second = vi.fn(async () => "b");
|
|
465
|
+
const pending = store.withFirstInitLock(second);
|
|
466
|
+
await flush();
|
|
467
|
+
|
|
468
|
+
store.destroy();
|
|
469
|
+
releaseFirst();
|
|
470
|
+
|
|
471
|
+
expect(await first).toBe("a");
|
|
472
|
+
await expect(pending).rejects.toThrow(/destroyed/);
|
|
473
|
+
expect(second).not.toHaveBeenCalled();
|
|
474
|
+
});
|
|
425
475
|
});
|
|
@@ -196,18 +196,35 @@ export const createVisitorStore = (
|
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
+
/**
|
|
200
|
+
* A first init still queued behind another tab's lock when this store is
|
|
201
|
+
* destroyed must not run: it would mint a visitor and write the token and
|
|
202
|
+
* session after teardown, racing the replacement store for the same keys.
|
|
203
|
+
* The in-flight `withFirstInitLock` rejects instead; `destroy()` wakes any
|
|
204
|
+
* lease waiter so the rejection is immediate rather than up to a poll late.
|
|
205
|
+
*/
|
|
206
|
+
const leaseWaiters = new Set<() => void>();
|
|
207
|
+
const runGuarded = <T>(fn: () => Promise<T>): Promise<T> =>
|
|
208
|
+
destroyed
|
|
209
|
+
? Promise.reject(
|
|
210
|
+
new Error("Visitor store destroyed before its first init could start")
|
|
211
|
+
)
|
|
212
|
+
: fn();
|
|
213
|
+
|
|
199
214
|
/** Storage-change wakeup with a timeout floor; same-tab writers fire no event. */
|
|
200
215
|
const waitForLeaseChange = (timeoutMs: number) =>
|
|
201
216
|
new Promise<void>((resolve) => {
|
|
202
217
|
const timer = setTimeout(done, timeoutMs);
|
|
203
218
|
function done() {
|
|
204
219
|
clearTimeout(timer);
|
|
220
|
+
leaseWaiters.delete(done);
|
|
205
221
|
window.removeEventListener("storage", wake);
|
|
206
222
|
resolve();
|
|
207
223
|
}
|
|
208
224
|
function wake(event: StorageEvent) {
|
|
209
225
|
if (event.key === null || event.key === leaseKey) done();
|
|
210
226
|
}
|
|
227
|
+
leaseWaiters.add(done);
|
|
211
228
|
window.addEventListener("storage", wake);
|
|
212
229
|
});
|
|
213
230
|
|
|
@@ -216,7 +233,7 @@ export const createVisitorStore = (
|
|
|
216
233
|
.toString(36)
|
|
217
234
|
.slice(2)}`;
|
|
218
235
|
const deadline = Date.now() + LEASE_WAIT_CAP_MS;
|
|
219
|
-
while (Date.now() < deadline) {
|
|
236
|
+
while (!destroyed && Date.now() < deadline) {
|
|
220
237
|
const store = localStore();
|
|
221
238
|
if (!store) break;
|
|
222
239
|
const now = Date.now();
|
|
@@ -246,14 +263,14 @@ export const createVisitorStore = (
|
|
|
246
263
|
}
|
|
247
264
|
heldLeaseNonce = nonce;
|
|
248
265
|
try {
|
|
249
|
-
return await fn
|
|
266
|
+
return await runGuarded(fn);
|
|
250
267
|
} finally {
|
|
251
268
|
heldLeaseNonce = null;
|
|
252
269
|
removeOwnLease(nonce);
|
|
253
270
|
}
|
|
254
271
|
}
|
|
255
272
|
// Cap or storage loss: proceed unlocked, the documented rare-race mode.
|
|
256
|
-
return fn
|
|
273
|
+
return runGuarded(fn);
|
|
257
274
|
};
|
|
258
275
|
|
|
259
276
|
return {
|
|
@@ -310,10 +327,10 @@ export const createVisitorStore = (
|
|
|
310
327
|
globalThis.navigator as Navigator & { locks?: LockManagerLike }
|
|
311
328
|
)?.locks;
|
|
312
329
|
if (locks?.request) {
|
|
313
|
-
return locks.request(lockName, () => fn
|
|
330
|
+
return locks.request(lockName, () => runGuarded(fn));
|
|
314
331
|
}
|
|
315
332
|
// No-persistence and degraded-memory modes cannot coordinate tabs.
|
|
316
|
-
if (!localStore()) return fn
|
|
333
|
+
if (!localStore()) return runGuarded(fn);
|
|
317
334
|
return leaseLock(fn);
|
|
318
335
|
},
|
|
319
336
|
|
|
@@ -332,6 +349,7 @@ export const createVisitorStore = (
|
|
|
332
349
|
window.removeEventListener("storage", onStorage);
|
|
333
350
|
}
|
|
334
351
|
if (heldLeaseNonce) removeOwnLease(heldLeaseNonce);
|
|
352
|
+
for (const wake of [...leaseWaiters]) wake();
|
|
335
353
|
},
|
|
336
354
|
};
|
|
337
355
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Browser voice wire v1 fixtures (`runtype-browser-v1`, contract Amendment 5.1), copied from core #9522's schema fixtures. One JSON frame per file: `server/` is what core sends, `client/` is what a client sends. `voice.test.ts` feeds every server frame through the provider and checks the client frames Persona sends against `client/`. Refresh them from core when the wire changes.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "delegation_update",
|
|
3
|
+
"delegationId": "del_1",
|
|
4
|
+
"status": "pending_approval",
|
|
5
|
+
"text": "Placing a pickup order needs your approval in the chat. Briefly tell the user what you're about to do and ask them to approve or decline it in the chat. Don't claim it's done."
|
|
6
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "delegation_started",
|
|
3
|
+
"delegationId": "del_1",
|
|
4
|
+
"turnId": "del_1",
|
|
5
|
+
"input": {
|
|
6
|
+
"text": "What's on the menu today?",
|
|
7
|
+
"userUtteranceIds": ["utt_1"],
|
|
8
|
+
"messages": [
|
|
9
|
+
{
|
|
10
|
+
"role": "user",
|
|
11
|
+
"content": "What's on the menu today?"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
}
|