gradio-pr-bot commited on
Commit
f384af7
·
verified ·
1 Parent(s): d7ccfcc

Upload folder using huggingface_hub

Browse files
6.12.1/statustracker/index.ts ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ export { default as StatusTracker } from "./static/index.svelte";
2
+ export { default as Toast } from "./static/Toast.svelte";
3
+ export { default as Loader } from "./static/Loader.svelte";
4
+ export { default as StreamingBar } from "./static/StreamingBar.svelte";
5
+ export type * from "./static/types";
6
+ export { default } from "./static/index.svelte";
7
+ export { LoadingStatus } from "./static/state.svelte.js";
6.12.1/statustracker/package.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/statustracker",
3
+ "version": "0.14.0",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "main": "./index.ts",
7
+ "author": "",
8
+ "license": "ISC",
9
+ "main_changeset": true,
10
+ "exports": {
11
+ ".": {
12
+ "gradio": "./index.ts",
13
+ "svelte": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
18
+ "dependencies": {
19
+ "@gradio/atoms": "workspace:^",
20
+ "@gradio/icons": "workspace:^",
21
+ "@gradio/sanitize": "^0.2.0",
22
+ "@gradio/utils": "workspace:^"
23
+ },
24
+ "devDependencies": {
25
+ "@gradio/preview": "workspace:^"
26
+ },
27
+ "peerDependencies": {
28
+ "svelte": "^5.48.0"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/gradio-app/gradio.git",
33
+ "directory": "js/statustracker"
34
+ }
35
+ }
6.12.1/statustracker/static/Loader.svelte ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { spring } from "svelte/motion";
3
+
4
+ interface Props {
5
+ margin?: boolean;
6
+ }
7
+
8
+ let { margin = true }: Props = $props();
9
+
10
+ const top = spring([0, 0]);
11
+ const bottom = spring([0, 0]);
12
+
13
+ let dismounted = $state(false);
14
+
15
+ async function animate(): Promise<void> {
16
+ await Promise.all([top.set([125, 140]), bottom.set([-125, -140])]);
17
+ await Promise.all([top.set([-125, 140]), bottom.set([125, -140])]);
18
+ await Promise.all([top.set([-125, 0]), bottom.set([125, -0])]);
19
+ await Promise.all([top.set([125, 0]), bottom.set([-125, 0])]);
20
+ }
21
+
22
+ async function run(): Promise<void> {
23
+ await animate();
24
+ if (!dismounted) run();
25
+ }
26
+
27
+ async function loading(): Promise<void> {
28
+ await Promise.all([top.set([125, 0]), bottom.set([-125, 0])]);
29
+
30
+ run();
31
+ }
32
+
33
+ $effect(() => {
34
+ loading();
35
+ return () => {
36
+ dismounted = true;
37
+ };
38
+ });
39
+ </script>
40
+
41
+ <div class:margin>
42
+ <svg
43
+ viewBox="-1200 -1200 3000 3000"
44
+ fill="none"
45
+ xmlns="http://www.w3.org/2000/svg"
46
+ >
47
+ <g style="transform: translate({$top[0]}px, {$top[1]}px);">
48
+ <path
49
+ d="M255.926 0.754768L509.702 139.936V221.027L255.926 81.8465V0.754768Z"
50
+ fill="#FF7C00"
51
+ fill-opacity="0.4"
52
+ />
53
+ <path
54
+ d="M509.69 139.936L254.981 279.641V361.255L509.69 221.55V139.936Z"
55
+ fill="#FF7C00"
56
+ />
57
+ <path
58
+ d="M0.250138 139.937L254.981 279.641V361.255L0.250138 221.55V139.937Z"
59
+ fill="#FF7C00"
60
+ fill-opacity="0.4"
61
+ />
62
+ <path
63
+ d="M255.923 0.232622L0.236328 139.936V221.55L255.923 81.8469V0.232622Z"
64
+ fill="#FF7C00"
65
+ />
66
+ </g>
67
+ <g style="transform: translate({$bottom[0]}px, {$bottom[1]}px);">
68
+ <path
69
+ d="M255.926 141.5L509.702 280.681V361.773L255.926 222.592V141.5Z"
70
+ fill="#FF7C00"
71
+ fill-opacity="0.4"
72
+ />
73
+ <path
74
+ d="M509.69 280.679L254.981 420.384V501.998L509.69 362.293V280.679Z"
75
+ fill="#FF7C00"
76
+ />
77
+ <path
78
+ d="M0.250138 280.681L254.981 420.386V502L0.250138 362.295V280.681Z"
79
+ fill="#FF7C00"
80
+ fill-opacity="0.4"
81
+ />
82
+ <path
83
+ d="M255.923 140.977L0.236328 280.68V362.294L255.923 222.591V140.977Z"
84
+ fill="#FF7C00"
85
+ />
86
+ </g>
87
+ </svg>
88
+ </div>
89
+
90
+ <style>
91
+ svg {
92
+ width: var(--size-20);
93
+ height: var(--size-20);
94
+ }
95
+
96
+ svg path {
97
+ fill: var(--loader-color);
98
+ }
99
+
100
+ div {
101
+ z-index: var(--layer-2);
102
+ }
103
+
104
+ .margin {
105
+ margin: var(--size-4);
106
+ }
107
+ </style>
6.12.1/statustracker/static/StreamingBar.svelte ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ interface Props {
3
+ time_limit: number | null;
4
+ }
5
+
6
+ let { time_limit }: Props = $props();
7
+ </script>
8
+
9
+ {#if time_limit}
10
+ <div class="streaming-bar" style:animation-duration="{time_limit}s"></div>
11
+ {/if}
12
+
13
+ <style>
14
+ .streaming-bar {
15
+ position: absolute;
16
+ bottom: 0;
17
+ left: 0;
18
+ right: 0;
19
+ height: 4px;
20
+ background-color: var(--primary-600);
21
+ animation: countdown linear forwards;
22
+ z-index: 1;
23
+ }
24
+
25
+ @keyframes countdown {
26
+ from {
27
+ transform: translateX(0%);
28
+ }
29
+ to {
30
+ transform: translateX(-100%);
31
+ }
32
+ }
33
+ </style>
6.12.1/statustracker/static/Toast.svelte ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { ToastMessage, GroupedToastMessage } from "./types";
3
+ import ToastContent from "./ToastContent.svelte";
4
+ import { spring } from "svelte/motion";
5
+
6
+ interface Props {
7
+ messages?: ToastMessage[];
8
+ on_close: (id: number) => void;
9
+ }
10
+
11
+ let { messages = [], on_close }: Props = $props();
12
+ const top = spring(0, { stiffness: 0.4, damping: 0.5 });
13
+
14
+ let grouped_messages: GroupedToastMessage[] = $state([]);
15
+
16
+ $effect(() => {
17
+ scroll_to_top(messages);
18
+ });
19
+
20
+ $effect(() => {
21
+ grouped_messages = group_messages(messages);
22
+ });
23
+
24
+ function group_messages(msgs: ToastMessage[]): GroupedToastMessage[] {
25
+ const groups = new Map<string, GroupedToastMessage>();
26
+
27
+ msgs.forEach((msg) => {
28
+ const key = msg.type;
29
+ if (!groups.has(key)) {
30
+ groups.set(key, {
31
+ type: msg.type,
32
+ messages: [],
33
+ expanded: true
34
+ });
35
+ }
36
+ groups.get(key)!.messages.push(msg);
37
+ });
38
+
39
+ return Array.from(groups.values());
40
+ }
41
+
42
+ function scroll_to_top(_messages: ToastMessage[]): void {
43
+ if (_messages.length > 0) {
44
+ if ("parentIFrame" in window) {
45
+ window.parentIFrame?.getPageInfo((page_info) => {
46
+ if (page_info.scrollTop < page_info.offsetTop) {
47
+ top.set(0);
48
+ } else {
49
+ top.set(page_info.scrollTop - page_info.offsetTop);
50
+ }
51
+ });
52
+ }
53
+ }
54
+ }
55
+
56
+ function toggle_group(type: string): void {
57
+ grouped_messages = grouped_messages.map((group) => {
58
+ if (group.type === type) {
59
+ return { ...group, expanded: !group.expanded };
60
+ }
61
+ return group;
62
+ });
63
+ }
64
+ </script>
65
+
66
+ <div class="toast-wrap" style="--toast-top: {$top}px;">
67
+ {#each grouped_messages as group (group.type)}
68
+ <div class="toast-item">
69
+ <ToastContent
70
+ type={group.type}
71
+ messages={group.messages}
72
+ expanded={group.expanded}
73
+ ontoggle={() => toggle_group(group.type)}
74
+ onclose={(id) => on_close(id)}
75
+ />
76
+ </div>
77
+ {/each}
78
+ </div>
79
+
80
+ <style>
81
+ .toast-wrap {
82
+ --toast-top: var(--size-4);
83
+ display: flex;
84
+ position: fixed;
85
+ top: calc(var(--toast-top) + var(--size-3));
86
+ flex-direction: column;
87
+ gap: var(--size-2);
88
+ z-index: var(--layer-top);
89
+ right: var(--size-3);
90
+ left: var(--size-3);
91
+ align-items: end;
92
+ max-width: none;
93
+ }
94
+
95
+ .toast-item {
96
+ width: 100%;
97
+ }
98
+
99
+ @media (min-width: 640px) {
100
+ .toast-wrap {
101
+ left: auto;
102
+ width: calc(var(--size-96) + var(--size-10));
103
+ }
104
+ }
105
+ </style>
6.12.1/statustracker/static/ToastContent.svelte ADDED
@@ -0,0 +1,396 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { Error, Info, Warning, Success, ChevronDown } from "@gradio/icons";
3
+ import { sanitize } from "@gradio/sanitize";
4
+ import { fade, slide } from "svelte/transition";
5
+ import type { ToastMessage } from "./types";
6
+
7
+ interface Props {
8
+ type: ToastMessage["type"];
9
+ messages?: ToastMessage[];
10
+ expanded?: boolean;
11
+ ontoggle?: () => void;
12
+ onclose?: (id: number) => void;
13
+ }
14
+
15
+ let {
16
+ type,
17
+ messages = [],
18
+ expanded = true,
19
+ ontoggle,
20
+ onclose
21
+ }: Props = $props();
22
+
23
+ let touch_start_x = $state(0);
24
+ let touch_start_y = $state(0);
25
+ let offset_x = $state(0);
26
+ let is_dragging = $state(false);
27
+ let toast_element: HTMLElement;
28
+
29
+ const default_messages: Record<ToastMessage["type"], string> = {
30
+ error: "An error occurred.",
31
+ warning: "Warning.",
32
+ success: "Success.",
33
+ info: "Info."
34
+ };
35
+
36
+ let count = $derived(messages.length);
37
+ let first_message = $derived(messages[0]);
38
+ let type_label = $derived(type.charAt(0).toUpperCase() + type.slice(1));
39
+ let has_duration = $derived(first_message?.duration !== null);
40
+ let timer_duration = $derived(
41
+ has_duration ? `${first_message.duration}s` : "0s"
42
+ );
43
+
44
+ function handle_toggle(): void {
45
+ ontoggle?.();
46
+ }
47
+
48
+ function close_all(): void {
49
+ messages.forEach((msg) => {
50
+ onclose?.(msg.id);
51
+ });
52
+ }
53
+
54
+ function handle_touch_start(e: TouchEvent): void {
55
+ touch_start_x = e.touches[0].clientX;
56
+ touch_start_y = e.touches[0].clientY;
57
+ is_dragging = true;
58
+ }
59
+
60
+ function handle_touch_move(e: TouchEvent): void {
61
+ if (!is_dragging) return;
62
+
63
+ const touch_x = e.touches[0].clientX;
64
+ const touch_y = e.touches[0].clientY;
65
+ const delta_x = touch_x - touch_start_x;
66
+ const delta_y = touch_y - touch_start_y;
67
+
68
+ if (Math.abs(delta_x) > Math.abs(delta_y) && Math.abs(delta_x) > 10) {
69
+ e.preventDefault();
70
+ offset_x = delta_x;
71
+ }
72
+ }
73
+
74
+ function handle_touch_end(): void {
75
+ if (!is_dragging) return;
76
+
77
+ if (Math.abs(offset_x) > 100) {
78
+ close_all();
79
+ } else {
80
+ offset_x = 0;
81
+ }
82
+
83
+ is_dragging = false;
84
+ }
85
+
86
+ $effect(() => {
87
+ if (has_duration && messages.length === 1) {
88
+ setTimeout(close_all, first_message.duration! * 1000);
89
+ }
90
+ });
91
+ </script>
92
+
93
+ <div
94
+ bind:this={toast_element}
95
+ class="toast-body {type}"
96
+ role="status"
97
+ aria-live="polite"
98
+ data-testid="toast-body"
99
+ ontouchstart={handle_touch_start}
100
+ ontouchmove={handle_touch_move}
101
+ ontouchend={handle_touch_end}
102
+ in:fade={{ duration: 200, delay: 100 }}
103
+ out:fade={{ duration: 200 }}
104
+ style="transform: translateX({offset_x}px); opacity: {1 -
105
+ Math.abs(offset_x) / 300};"
106
+ >
107
+ <div
108
+ class="toast-header"
109
+ onclick={handle_toggle}
110
+ role="button"
111
+ tabindex="0"
112
+ onkeydown={(e) => {
113
+ if (e.key === "Enter" || e.key === " ") {
114
+ handle_toggle();
115
+ }
116
+ }}
117
+ >
118
+ <div class="toast-icon {type}">
119
+ {#if type === "warning"}
120
+ <Warning />
121
+ {:else if type === "info"}
122
+ <Info />
123
+ {:else if type === "success"}
124
+ <Success />
125
+ {:else if type === "error"}
126
+ <Error />
127
+ {/if}
128
+ </div>
129
+
130
+ <div class="toast-title-row">
131
+ <span class="toast-title {type}">
132
+ {type_label}
133
+ {#if count > 1}
134
+ <span class="toast-count">({count})</span>
135
+ {/if}
136
+ </span>
137
+ <div class="chevron" class:expanded class:visible={count > 0}>
138
+ <ChevronDown />
139
+ </div>
140
+ </div>
141
+
142
+ <button
143
+ onclick={(e) => {
144
+ e.stopPropagation();
145
+ close_all();
146
+ }}
147
+ class="toast-close {type}"
148
+ type="button"
149
+ aria-label="Close"
150
+ data-testid="toast-close"
151
+ >
152
+ <span aria-hidden="true">&#215;</span>
153
+ </button>
154
+ </div>
155
+
156
+ {#if expanded}
157
+ <div class="toast-messages" transition:slide={{ duration: 200 }}>
158
+ {#each messages as message, i (message.id)}
159
+ <div class="toast-message-item {type}">
160
+ <div class="toast-message-text {type}" data-testid="toast-text">
161
+ {@html sanitize(message.message || default_messages[type])}
162
+ </div>
163
+ </div>
164
+ {#if i < messages.length - 1}
165
+ <div class="toast-separator" />
166
+ {/if}
167
+ {/each}
168
+ </div>
169
+ {/if}
170
+
171
+ {#if has_duration}
172
+ <div class="timer {type}" style="animation-duration: {timer_duration}" />
173
+ {/if}
174
+ </div>
175
+
176
+ <!-- s-csdrBJqpTpqa -->
177
+ <style>
178
+ .toast-body {
179
+ display: flex;
180
+ flex-direction: column;
181
+ position: relative;
182
+ right: 0;
183
+ left: 0;
184
+ margin: auto;
185
+ border-radius: var(--radius-sm);
186
+ overflow: hidden;
187
+ pointer-events: auto;
188
+ background: var(--background-fill-secondary);
189
+ border: 1px solid var(--border-color-primary);
190
+ box-shadow: var(--shadow-drop);
191
+ touch-action: pan-y;
192
+ user-select: none;
193
+ }
194
+
195
+ :global(.dark) .toast-body {
196
+ background: var(--background-fill-primary);
197
+ }
198
+
199
+ .toast-body.error {
200
+ --toast-color: var(--color-red-700);
201
+ }
202
+
203
+ .toast-body.warning {
204
+ --toast-color: var(--color-yellow-700);
205
+ }
206
+
207
+ .toast-body.info {
208
+ --toast-color: var(--color-grey-700);
209
+ }
210
+
211
+ .toast-body.success {
212
+ --toast-color: var(--color-green-700);
213
+ }
214
+
215
+ :global(.dark) .toast-body.error {
216
+ --toast-color: var(--color-red-500);
217
+ }
218
+
219
+ :global(.dark) .toast-body.warning {
220
+ --toast-color: var(--color-yellow-500);
221
+ }
222
+
223
+ :global(.dark) .toast-body.info {
224
+ --toast-color: var(--color-grey-500);
225
+ }
226
+
227
+ :global(.dark) .toast-body.success {
228
+ --toast-color: var(--color-green-500);
229
+ }
230
+
231
+ .toast-header {
232
+ display: flex;
233
+ align-items: center;
234
+ padding: var(--size-3) var(--size-3);
235
+ cursor: pointer;
236
+ }
237
+
238
+ .toast-header:hover {
239
+ opacity: 0.9;
240
+ }
241
+
242
+ .toast-title-row {
243
+ flex: 1;
244
+ display: flex;
245
+ align-items: center;
246
+ gap: var(--size-2);
247
+ }
248
+
249
+ .chevron {
250
+ display: flex;
251
+ align-items: center;
252
+ width: var(--size-4);
253
+ height: var(--size-4);
254
+ transition: transform 0.2s ease;
255
+ opacity: 0.6;
256
+ }
257
+
258
+ .chevron.visible {
259
+ opacity: 1;
260
+ }
261
+
262
+ .chevron.expanded {
263
+ transform: rotate(180deg);
264
+ }
265
+
266
+ .toast-title {
267
+ display: flex;
268
+ align-items: center;
269
+ font-weight: var(--weight-bold);
270
+ font-size: var(--text-lg);
271
+ line-height: var(--line-sm);
272
+ }
273
+
274
+ .toast-count {
275
+ margin-left: var(--size-1);
276
+ font-weight: var(--weight-semibold);
277
+ }
278
+
279
+ .toast-close {
280
+ margin: 0 var(--size-1);
281
+ border-radius: var(--radius-lg);
282
+ padding: var(--size-1);
283
+ font-size: var(--text-xl);
284
+ line-height: 1;
285
+ background: transparent;
286
+ border: none;
287
+ cursor: pointer;
288
+ transition: all 0.2s ease;
289
+ display: flex;
290
+ align-items: center;
291
+ justify-content: center;
292
+ width: var(--size-7);
293
+ height: var(--size-7);
294
+ opacity: 0.6;
295
+ flex-shrink: 0;
296
+ }
297
+
298
+ .toast-close:hover {
299
+ opacity: 1;
300
+ transform: scale(1.1);
301
+ }
302
+
303
+ .toast-close:active {
304
+ transform: scale(0.95);
305
+ }
306
+
307
+ .toast-close {
308
+ color: var(--body-text-color);
309
+ }
310
+
311
+ .toast-icon {
312
+ display: flex;
313
+ position: relative;
314
+ flex-shrink: 0;
315
+ justify-content: center;
316
+ align-items: center;
317
+ margin-right: var(--size-2);
318
+ border-radius: var(--radius-full);
319
+ padding: var(--size-1-5);
320
+ width: var(--size-8);
321
+ height: var(--size-8);
322
+ }
323
+
324
+ .toast-icon {
325
+ color: var(--toast-color);
326
+ }
327
+
328
+ .toast-messages {
329
+ display: flex;
330
+ flex-direction: column;
331
+ gap: var(--size-2);
332
+ padding: 0 var(--size-3) var(--size-2) var(--size-3);
333
+ }
334
+
335
+ .toast-message-item {
336
+ padding: var(--size-1-5) var(--size-1-5) var(--size-1-5) var(--size-1-5);
337
+ border-radius: var(--radius-lg);
338
+ }
339
+
340
+ .toast-separator {
341
+ height: 1px;
342
+ background: var(--border-color-primary);
343
+ margin: 0;
344
+ }
345
+
346
+ .toast-message-text {
347
+ font-size: var(--text-md);
348
+ line-height: 1.5;
349
+ word-wrap: break-word;
350
+ overflow-wrap: break-word;
351
+ word-break: break-word;
352
+ color: var(--body-text-color);
353
+ }
354
+
355
+ .toast-message-text :global(a) {
356
+ text-decoration: underline;
357
+ }
358
+
359
+ @keyframes countdown {
360
+ from {
361
+ transform: scaleX(1);
362
+ }
363
+ to {
364
+ transform: scaleX(0);
365
+ }
366
+ }
367
+
368
+ .timer {
369
+ position: absolute;
370
+ bottom: 0;
371
+ left: 0;
372
+ transform-origin: 0 0;
373
+ animation: countdown 10s linear forwards;
374
+ width: 100%;
375
+ height: var(--size-1);
376
+ }
377
+
378
+ .timer {
379
+ background: var(--toast-color);
380
+ }
381
+
382
+ @media (max-width: 640px) {
383
+ .toast-header {
384
+ padding: var(--size-2) var(--size-2);
385
+ }
386
+
387
+ .toast-messages {
388
+ gap: var(--size-1);
389
+ padding: 0 var(--size-2) var(--size-1-5) var(--size-2);
390
+ }
391
+
392
+ .toast-message-item {
393
+ padding: 0 var(--size-1) var(--size-1) var(--size-1);
394
+ }
395
+ }
396
+ </style>
6.12.1/statustracker/static/index.svelte ADDED
@@ -0,0 +1,646 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script context="module" lang="ts">
2
+ import { tick, untrack } from "svelte";
3
+ import { pretty_si } from "./utils";
4
+
5
+ let items: HTMLDivElement[] = [];
6
+
7
+ let called = false;
8
+
9
+ const is_browser = typeof window !== "undefined";
10
+ const raf = is_browser
11
+ ? window.requestAnimationFrame
12
+ : (cb: (...args: any[]) => void) => {};
13
+
14
+ async function scroll_into_view(
15
+ el: HTMLDivElement,
16
+ enable: boolean | null = true
17
+ ): Promise<void> {
18
+ if (
19
+ window.__gradio_mode__ === "website" ||
20
+ (window.__gradio_mode__ !== "app" && enable !== true)
21
+ ) {
22
+ return;
23
+ }
24
+
25
+ items.push(el);
26
+ if (!called) called = true;
27
+ else return;
28
+
29
+ await tick();
30
+
31
+ raf(() => {
32
+ let min = [0, 0];
33
+
34
+ for (let i = 0; i < items.length; i++) {
35
+ const element = items[i];
36
+
37
+ const box = element.getBoundingClientRect();
38
+ if (i === 0 || box.top + window.scrollY <= min[0]) {
39
+ min[0] = box.top + window.scrollY;
40
+ min[1] = i;
41
+ }
42
+ }
43
+
44
+ window.scrollTo({ top: min[0] - 20, behavior: "smooth" });
45
+
46
+ called = false;
47
+ items = [];
48
+ });
49
+ }
50
+ </script>
51
+
52
+ <script lang="ts">
53
+ import Loader from "./Loader.svelte";
54
+ import type { LoadingStatus } from "./types";
55
+ import type { I18nFormatter } from "@gradio/utils";
56
+
57
+ import { IconButton } from "@gradio/atoms";
58
+ import { Clear } from "@gradio/icons";
59
+
60
+ interface Props {
61
+ i18n: I18nFormatter;
62
+ eta?: number | null;
63
+ queue_position: number | null;
64
+ queue_size: number | null;
65
+ status:
66
+ | "complete"
67
+ | "pending"
68
+ | "error"
69
+ | "generating"
70
+ | "streaming"
71
+ | null;
72
+ scroll_to_output?: boolean;
73
+ timer?: boolean;
74
+ show_progress?: "full" | "minimal" | "hidden";
75
+ message?: string | null;
76
+ progress?: LoadingStatus["progress"] | null | undefined;
77
+ variant?: "default" | "center";
78
+ loading_text?: string;
79
+ absolute?: boolean;
80
+ translucent?: boolean;
81
+ border?: boolean;
82
+ autoscroll: boolean;
83
+ validation_error?: string | null;
84
+ show_validation_error?: boolean;
85
+ type?: "input" | "output" | null;
86
+ on_clear_status?: () => void;
87
+ used_cache?: "full" | "partial" | null;
88
+ cache_duration?: number | null;
89
+ avg_time?: number | null;
90
+ }
91
+
92
+ interface ProgressLevel {
93
+ progress_level: (number | undefined)[] | null;
94
+ last_progress_level: number | undefined;
95
+ progress_bar_transition: string;
96
+ }
97
+
98
+ let {
99
+ i18n,
100
+ eta = null,
101
+ queue_position,
102
+ queue_size,
103
+ status,
104
+ scroll_to_output = false,
105
+ timer = true,
106
+ show_progress = "full",
107
+ message = null,
108
+ progress = null,
109
+ variant = "default",
110
+ loading_text = "Loading...",
111
+ absolute = true,
112
+ translucent = false,
113
+ border = false,
114
+ autoscroll,
115
+ validation_error = null,
116
+ show_validation_error = true,
117
+ type = null,
118
+ on_clear_status,
119
+ used_cache = null,
120
+ cache_duration = null,
121
+ avg_time = null
122
+ }: Props = $props();
123
+
124
+ let el: HTMLDivElement;
125
+
126
+ let _timer = false;
127
+ let timer_start = $state(0);
128
+ let old_eta = $state<number | null>(null);
129
+ let eta_from_start = $state<number | null>(null);
130
+ let message_visible = $state(false);
131
+ let formatted_eta = $state<string | null>(null);
132
+ let show_message_timeout = $state<NodeJS.Timeout | null>(null);
133
+ let show_cache_indicator = $state(false);
134
+ let cache_indicator_fading = $state(false);
135
+ let cache_display_time = $state<string | null>(null);
136
+ let cache_display_avg = $state<string | null>(null);
137
+ let cache_indicator_label = $state("from cache");
138
+ let show_cache_avg = $state(false);
139
+ let cache_timeout: ReturnType<typeof setTimeout> | null = null;
140
+ let cache_fade_timeout: ReturnType<typeof setTimeout> | null = null;
141
+
142
+ const should_hide = $derived(
143
+ !(show_validation_error && validation_error) &&
144
+ (type === "input" ||
145
+ !status ||
146
+ status === "complete" ||
147
+ show_progress === "hidden" ||
148
+ status == "streaming")
149
+ );
150
+
151
+ let timer_diff = $state(0);
152
+
153
+ const eta_level = $derived(
154
+ eta_from_start === null || eta_from_start <= 0 || !timer_diff
155
+ ? 0
156
+ : Math.min(timer_diff / eta_from_start, 1)
157
+ );
158
+
159
+ const formatted_timer = $derived(timer_diff.toFixed(1));
160
+
161
+ let show_eta_bar = $derived(progress != null ? false : true);
162
+ let effective_eta = $derived(eta ?? old_eta);
163
+
164
+ function run(): void {
165
+ raf(() => {
166
+ timer_diff = (performance.now() - timer_start) / 1000;
167
+ if (_timer) run();
168
+ });
169
+ }
170
+
171
+ let progress_level = $derived.by<ProgressLevel>(() => {
172
+ let _progress_level: (number | undefined)[] | null = null;
173
+ if (progress != null) {
174
+ _progress_level = progress.map((p) => {
175
+ if (p.index != null && p.length != null) {
176
+ return p.index / p.length;
177
+ } else if (p.progress != null) {
178
+ return p.progress;
179
+ }
180
+ return undefined;
181
+ });
182
+ } else {
183
+ _progress_level = null;
184
+ }
185
+
186
+ let _last_progress_level: number | undefined;
187
+ let transition = "";
188
+ if (_progress_level) {
189
+ _last_progress_level = _progress_level[_progress_level.length - 1];
190
+
191
+ if (_last_progress_level === 0) {
192
+ transition = "0";
193
+ } else {
194
+ transition = "150ms";
195
+ }
196
+ } else {
197
+ _last_progress_level = undefined;
198
+ }
199
+
200
+ return {
201
+ progress_level: _progress_level,
202
+ last_progress_level: _last_progress_level,
203
+ progress_bar_transition: transition
204
+ };
205
+ });
206
+
207
+ function start_timer(): void {
208
+ if (_timer) return;
209
+
210
+ old_eta = formatted_eta = null;
211
+ timer_start = performance.now();
212
+
213
+ _timer = true;
214
+ run();
215
+ }
216
+
217
+ function stop_timer(): void {
218
+ old_eta = formatted_eta = null;
219
+ if (!_timer) return;
220
+ _timer = false;
221
+ }
222
+
223
+ $effect(() => {
224
+ if (status === "pending") {
225
+ start_timer();
226
+ } else {
227
+ untrack(() => {
228
+ stop_timer();
229
+ });
230
+ }
231
+ });
232
+
233
+ $effect(() => {
234
+ if (
235
+ el &&
236
+ scroll_to_output &&
237
+ (status === "pending" || status === "complete")
238
+ ) {
239
+ scroll_into_view(el, autoscroll);
240
+ }
241
+ });
242
+
243
+ $effect(() => {
244
+ if (effective_eta != null && old_eta !== effective_eta) {
245
+ eta_from_start = (performance.now() - timer_start) / 1000 + effective_eta;
246
+ formatted_eta = eta_from_start.toFixed(1);
247
+ old_eta = effective_eta;
248
+ }
249
+ });
250
+
251
+ function close_message(): void {
252
+ message_visible = false;
253
+ if (show_message_timeout !== null) {
254
+ clearTimeout(show_message_timeout);
255
+ }
256
+ }
257
+
258
+ $effect(() => {
259
+ untrack(() => {
260
+ close_message();
261
+ });
262
+
263
+ if (status === "error" && message) {
264
+ message_visible = true;
265
+ }
266
+ });
267
+
268
+ $effect(() => {
269
+ if (
270
+ status === "complete" &&
271
+ type === "output" &&
272
+ used_cache &&
273
+ cache_duration != null
274
+ ) {
275
+ cache_display_time = cache_duration.toFixed(1);
276
+ cache_indicator_label =
277
+ used_cache === "full" ? "from cache" : "used cache";
278
+ show_cache_avg =
279
+ avg_time != null && avg_time > cache_duration && avg_time > 0;
280
+ cache_display_avg = show_cache_avg ? avg_time!.toFixed(1) : null;
281
+ show_cache_indicator = true;
282
+ cache_indicator_fading = false;
283
+
284
+ if (cache_timeout) clearTimeout(cache_timeout);
285
+ if (cache_fade_timeout) clearTimeout(cache_fade_timeout);
286
+ cache_timeout = setTimeout(() => {
287
+ cache_indicator_fading = true;
288
+ cache_fade_timeout = setTimeout(() => {
289
+ show_cache_indicator = false;
290
+ cache_indicator_fading = false;
291
+ }, 500);
292
+ }, 1750);
293
+ }
294
+ });
295
+ </script>
296
+
297
+ <div
298
+ class="wrap {variant} {show_progress}"
299
+ class:no-click={validation_error && show_validation_error}
300
+ class:hide={should_hide}
301
+ class:translucent={(variant === "center" &&
302
+ (status === "pending" || status === "error")) ||
303
+ translucent ||
304
+ show_progress === "minimal" ||
305
+ validation_error}
306
+ class:generating={status === "generating" && show_progress === "full"}
307
+ class:border
308
+ style:position={absolute ? "absolute" : "static"}
309
+ style:padding={absolute ? "0" : "var(--size-8) 0"}
310
+ data-testid="status-tracker"
311
+ bind:this={el}
312
+ >
313
+ {#if validation_error && show_validation_error}
314
+ <div class="validation-error">
315
+ {validation_error}
316
+ <button
317
+ ><IconButton
318
+ Icon={Clear}
319
+ label={i18n ? i18n("common.clear") : "Clear"}
320
+ disabled={false}
321
+ size="x-small"
322
+ background="var(--background-fill-primary)"
323
+ color="var(--error-background-text)"
324
+ border="var(--border-color-primary)"
325
+ onclick={() => (validation_error = null)}
326
+ /></button
327
+ >
328
+ </div>
329
+ {/if}
330
+ {#if status === "pending"}
331
+ {#if variant === "default" && show_eta_bar && show_progress === "full"}
332
+ <div
333
+ class="eta-bar"
334
+ style:transform="translateX({(eta_level || 0) * 100 - 100}%)"
335
+ />
336
+ {/if}
337
+ <div
338
+ class:meta-text-center={variant === "center"}
339
+ class:meta-text={variant === "default"}
340
+ class="progress-text"
341
+ >
342
+ {#if progress}
343
+ {#each progress as p}
344
+ {#if p.index != null}
345
+ {#if p.length != null}
346
+ {pretty_si(p.index || 0)}/{pretty_si(p.length)}
347
+ {:else}
348
+ {pretty_si(p.index || 0)}
349
+ {/if}
350
+ {p.unit} | {" "}
351
+ {/if}
352
+ {/each}
353
+ {:else if queue_position !== null && queue_size !== undefined && queue_position >= 0}
354
+ queue: {queue_position + 1}/{queue_size} |
355
+ {:else if queue_position === 0}
356
+ processing |
357
+ {/if}
358
+
359
+ {#if timer}
360
+ {formatted_timer}{eta ? `/${formatted_eta}` : ""}s
361
+ {/if}
362
+ </div>
363
+
364
+ {#if progress_level.last_progress_level != null}
365
+ <div class="progress-level">
366
+ <div class="progress-level-inner">
367
+ {#if progress != null}
368
+ {#each progress as p, i}
369
+ {#if p.desc != null || (progress_level.progress_level && progress_level.progress_level[i] != null)}
370
+ {#if i !== 0}
371
+ &nbsp;/
372
+ {/if}
373
+ {#if p.desc != null}
374
+ {p.desc}
375
+ {/if}
376
+ {#if p.desc != null && progress_level.progress_level && progress_level.progress_level[i] != null}
377
+ -
378
+ {/if}
379
+ {#if progress_level.progress_level != null}
380
+ {(100 * (progress_level.progress_level[i] || 0)).toFixed(1)}%
381
+ {/if}
382
+ {/if}
383
+ {/each}
384
+ {/if}
385
+ </div>
386
+
387
+ <div class="progress-bar-wrap">
388
+ <div
389
+ class="progress-bar"
390
+ style:width="{progress_level.last_progress_level * 100}%"
391
+ style:transition={progress_level.progress_bar_transition}
392
+ />
393
+ </div>
394
+ </div>
395
+ {:else if show_progress === "full"}
396
+ <Loader margin={variant === "default"} />
397
+ {/if}
398
+
399
+ {#if !timer}
400
+ <p class="loading">{loading_text}</p>
401
+ <slot name="additional-loading-text" />
402
+ {/if}
403
+ {:else if status === "error"}
404
+ <div class="clear-status">
405
+ <IconButton
406
+ Icon={Clear}
407
+ label={i18n("common.clear")}
408
+ disabled={false}
409
+ on:click={() => {
410
+ on_clear_status?.();
411
+ }}
412
+ />
413
+ </div>
414
+ <span class="error">{i18n("common.error")}</span>
415
+ <slot name="error" />
416
+ {/if}
417
+ </div>
418
+
419
+ {#if show_cache_indicator}
420
+ <div
421
+ class="cache-indicator"
422
+ class:fade-out={cache_indicator_fading}
423
+ style:position={absolute ? "absolute" : "static"}
424
+ >
425
+ &#9889; {cache_indicator_label}: {#if show_cache_avg}~{cache_display_avg}s
426
+ &rarr;&nbsp;
427
+ {/if}{cache_display_time}s
428
+ </div>
429
+ {/if}
430
+
431
+ <style>
432
+ .wrap {
433
+ display: flex;
434
+ flex-direction: column;
435
+ justify-content: center;
436
+ align-items: center;
437
+ z-index: var(--layer-3);
438
+ transition: opacity 0.1s ease-in-out;
439
+ border-radius: var(--block-radius);
440
+ background: var(--block-background-fill);
441
+ padding: 0 var(--size-6);
442
+ overflow: hidden;
443
+ }
444
+ .no-click {
445
+ pointer-events: none;
446
+ }
447
+
448
+ .wrap.center {
449
+ top: 0;
450
+ right: 0px;
451
+ left: 0px;
452
+ }
453
+
454
+ .wrap.default {
455
+ top: 0px;
456
+ right: 0px;
457
+ bottom: 0px;
458
+ left: 0px;
459
+ }
460
+
461
+ .hide {
462
+ opacity: 0;
463
+ pointer-events: none;
464
+ }
465
+
466
+ .generating {
467
+ animation:
468
+ pulseStart 1s cubic-bezier(0.4, 0, 0.6, 1),
469
+ pulse 2s cubic-bezier(0.4, 0, 0.6, 1) 1s infinite;
470
+ border: 2px solid var(--color-accent);
471
+ background: transparent;
472
+ z-index: var(--layer-1);
473
+ pointer-events: none;
474
+ }
475
+
476
+ .translucent {
477
+ background: none;
478
+ }
479
+
480
+ @keyframes pulseStart {
481
+ 0% {
482
+ opacity: 0;
483
+ }
484
+ 100% {
485
+ opacity: 1;
486
+ }
487
+ }
488
+
489
+ @keyframes pulse {
490
+ 0%,
491
+ 100% {
492
+ opacity: 1;
493
+ }
494
+ 50% {
495
+ opacity: 0.5;
496
+ }
497
+ }
498
+
499
+ .loading {
500
+ z-index: var(--layer-2);
501
+ color: var(--body-text-color);
502
+ }
503
+ .eta-bar {
504
+ position: absolute;
505
+ top: 0;
506
+ right: 0;
507
+ bottom: 0;
508
+ left: 0;
509
+ transform-origin: left;
510
+ opacity: 0.8;
511
+ z-index: var(--layer-1);
512
+ transition: 10ms;
513
+ background: var(--background-fill-secondary);
514
+ }
515
+ .progress-bar-wrap {
516
+ border: 1px solid var(--border-color-primary);
517
+ background: var(--background-fill-primary);
518
+ width: 55.5%;
519
+ height: var(--size-4);
520
+ }
521
+ .progress-bar {
522
+ transform-origin: left;
523
+ background-color: var(--loader-color);
524
+ width: var(--size-full);
525
+ height: var(--size-full);
526
+ }
527
+
528
+ .progress-level {
529
+ display: flex;
530
+ flex-direction: column;
531
+ align-items: center;
532
+ gap: 1;
533
+ z-index: var(--layer-2);
534
+ width: var(--size-full);
535
+ }
536
+
537
+ .progress-level-inner {
538
+ margin: var(--size-2) auto;
539
+ color: var(--body-text-color);
540
+ font-size: var(--text-sm);
541
+ font-family: var(--font-mono);
542
+ }
543
+
544
+ .meta-text {
545
+ position: absolute;
546
+ bottom: 0;
547
+ right: 0;
548
+ z-index: var(--layer-2);
549
+ padding: var(--size-1) var(--size-2);
550
+ font-size: var(--text-sm);
551
+ font-family: var(--font-mono);
552
+ }
553
+
554
+ .meta-text-center {
555
+ display: flex;
556
+ position: absolute;
557
+ top: 0;
558
+ right: 0;
559
+ justify-content: center;
560
+ align-items: center;
561
+ transform: translateY(var(--size-6));
562
+ z-index: var(--layer-2);
563
+ padding: var(--size-1) var(--size-2);
564
+ font-size: var(--text-sm);
565
+ font-family: var(--font-mono);
566
+ text-align: center;
567
+ }
568
+
569
+ .error {
570
+ box-shadow: var(--shadow-drop);
571
+ border: solid 1px var(--error-border-color);
572
+ border-radius: var(--radius-full);
573
+ background: var(--error-background-fill);
574
+ padding-right: var(--size-4);
575
+ padding-left: var(--size-4);
576
+ color: var(--error-text-color);
577
+ font-weight: var(--weight-semibold);
578
+ font-size: var(--text-lg);
579
+ line-height: var(--line-lg);
580
+ font-family: var(--font);
581
+ }
582
+
583
+ .validation-error {
584
+ pointer-events: auto;
585
+ color: var(--error-text-color);
586
+ font-weight: var(--weight-semibold);
587
+ font-size: var(--text-lg);
588
+ line-height: var(--line-lg);
589
+ font-family: var(--font);
590
+ position: absolute;
591
+ background: var(--error-background-fill);
592
+ top: 0;
593
+ right: 0;
594
+ z-index: var(--layer-3);
595
+ padding: var(--size-1) var(--size-2);
596
+ font-size: var(--text-md);
597
+ text-align: center;
598
+ border-bottom-left-radius: var(--radius-sm);
599
+ border-bottom: 1px solid var(--error-border-color);
600
+ border-left: 1px solid var(--error-border-color);
601
+ display: flex;
602
+ justify-content: space-between;
603
+ align-items: center;
604
+ gap: var(--spacing-xl);
605
+ }
606
+
607
+ .minimal {
608
+ pointer-events: none;
609
+ }
610
+
611
+ .minimal .progress-text {
612
+ background: var(--block-background-fill);
613
+ }
614
+
615
+ .border {
616
+ border: 1px solid var(--border-color-primary);
617
+ }
618
+
619
+ .clear-status {
620
+ position: absolute;
621
+ display: flex;
622
+ top: var(--size-2);
623
+ right: var(--size-2);
624
+ justify-content: flex-end;
625
+ gap: var(--spacing-sm);
626
+ z-index: var(--layer-1);
627
+ }
628
+
629
+ .cache-indicator {
630
+ position: absolute;
631
+ bottom: 0;
632
+ right: 0;
633
+ z-index: var(--layer-2);
634
+ padding: var(--size-1) var(--size-2);
635
+ font-size: var(--text-sm);
636
+ font-family: var(--font-mono);
637
+ pointer-events: none;
638
+ background: var(--block-background-fill);
639
+ opacity: 1;
640
+ transition: opacity 0.5s ease-out;
641
+ }
642
+
643
+ .cache-indicator.fade-out {
644
+ opacity: 0;
645
+ }
646
+ </style>
6.12.1/statustracker/static/index.ts ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export { default as StatusTracker } from "./index.svelte";
2
+ export { default as Toast } from "./Toast.svelte";
3
+ export { default as Loader } from "./Loader.svelte";
4
+ export { default as StreamingBar } from "./StreamingBar.svelte";
5
+ export type {
6
+ ILoadingStatus,
7
+ LoadingStatusArgs,
8
+ GroupedToastMessage,
9
+ ToastMessage
10
+ } from "./types";
11
+ export { default } from "./index.svelte";
6.12.1/statustracker/static/state.svelte.ts ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { ILoadingStatus, LoadingStatusArgs } from "./types.js";
2
+
3
+ export class LoadingStatus {
4
+ current: Record<string, ILoadingStatus> = {};
5
+ fn_outputs: Record<number, number[]> = {};
6
+ fn_inputs: Record<number, number[]> = {};
7
+ pending_outputs = new Map<number, number>();
8
+ fn_status: Record<number, ILoadingStatus["status"]> = {};
9
+ show_progress: Record<number, "full" | "minimal" | "hidden"> = {};
10
+
11
+ register(
12
+ dependency_id: number,
13
+ outputs: number[],
14
+ inputs: number[],
15
+ show_progress: "full" | "minimal" | "hidden"
16
+ ): void {
17
+ this.fn_outputs[dependency_id] = outputs;
18
+ this.fn_inputs[dependency_id] = inputs;
19
+ this.show_progress[dependency_id] = show_progress;
20
+ }
21
+
22
+ clear(id: number): void {
23
+ if (id in this.current) {
24
+ //@ts-ignore
25
+ this.current[id] = {};
26
+ }
27
+ }
28
+
29
+ update(args: LoadingStatusArgs): void {
30
+ const updates = this.resolve_args(args);
31
+
32
+ updates.forEach(
33
+ ({
34
+ id,
35
+ queue_position,
36
+ queue_size,
37
+ eta,
38
+ status,
39
+ message,
40
+ progress,
41
+ stream_state,
42
+ time_limit,
43
+ type,
44
+ used_cache,
45
+ cache_duration,
46
+ avg_time
47
+ }) => {
48
+ this.current[id] = {
49
+ queue: args.queue || false,
50
+ queue_size: queue_size,
51
+ queue_position: queue_position,
52
+ eta: eta,
53
+ stream_state: stream_state,
54
+ message: message,
55
+ progress: progress || undefined,
56
+ status,
57
+ fn_index: args.fn_index,
58
+ time_limit,
59
+ type,
60
+ show_progress: this.show_progress[args.fn_index],
61
+ used_cache,
62
+ cache_duration,
63
+ avg_time
64
+ };
65
+ }
66
+ );
67
+ }
68
+
69
+ set_status(id: number, status: ILoadingStatus["status"]): void {
70
+ this.current[id].status = status;
71
+ }
72
+
73
+ resolve_args(args: LoadingStatusArgs) {
74
+ const {
75
+ fn_index,
76
+ status,
77
+ size = undefined,
78
+ position = null,
79
+ eta = null,
80
+ message = null,
81
+ stream_state = null,
82
+ time_limit = null,
83
+ progress_data = null,
84
+ used_cache = null,
85
+ cache_duration = null,
86
+ avg_time = null
87
+ } = args;
88
+
89
+ const outputs = this.fn_outputs[fn_index];
90
+ const last_status = this.fn_status[fn_index];
91
+ const inputs = this.fn_inputs[fn_index];
92
+
93
+ const all_ids = outputs.concat(inputs);
94
+
95
+ // from (pending -> error) | complete - decrement pending count
96
+ return all_ids
97
+ .map((id) => {
98
+ let new_status: ILoadingStatus["status"];
99
+
100
+ const pending_count = this.pending_outputs.get(id) || 0;
101
+
102
+ // from (pending -> error) | complete - decrement pending count
103
+ if (last_status === "pending" && status !== "pending") {
104
+ let new_count = pending_count - 1;
105
+
106
+ this.pending_outputs.set(id, new_count < 0 ? 0 : new_count);
107
+
108
+ new_status = new_count > 0 ? "pending" : status;
109
+
110
+ // from pending -> pending - do nothing
111
+ } else if (last_status === "pending" && status === "pending") {
112
+ new_status = "pending";
113
+
114
+ // (error | complete) -> pending - - increment pending count
115
+ } else if (last_status !== "pending" && status === "pending") {
116
+ new_status = "pending";
117
+ this.pending_outputs.set(id, pending_count + 1);
118
+ } else {
119
+ new_status = status;
120
+ }
121
+
122
+ // We update the status tracker only for input components of streaming events
123
+ // or for outputs of the dependency
124
+ const type = (
125
+ inputs.includes(id) && stream_state
126
+ ? "input"
127
+ : outputs.includes(id)
128
+ ? "output"
129
+ : "skip"
130
+ ) as "input" | "output" | "skip";
131
+
132
+ return {
133
+ id,
134
+ queue_position: position,
135
+ queue_size: size,
136
+ eta: eta,
137
+ status: new_status,
138
+ message: message,
139
+ progress: progress_data,
140
+ stream_state: stream_state,
141
+ time_limit,
142
+ type: type,
143
+ used_cache,
144
+ cache_duration,
145
+ avg_time
146
+ };
147
+ })
148
+ .filter((update) => update.type !== "skip");
149
+ }
150
+ }
6.12.1/statustracker/static/types.ts ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export interface ILoadingStatus {
2
+ eta: number | null;
3
+ status: "pending" | "error" | "complete" | "generating" | "streaming";
4
+ queue: boolean;
5
+ queue_position: number | null;
6
+ queue_size?: number;
7
+ fn_index: number;
8
+ message?: string | null;
9
+ scroll_to_output?: boolean;
10
+ show_progress?: "full" | "minimal" | "hidden";
11
+ time_limit?: number | null | undefined;
12
+ progress?: {
13
+ progress: number | null;
14
+ index: number | null;
15
+ length: number | null;
16
+ unit: string | null;
17
+ desc: string | null;
18
+ }[];
19
+ validation_error?: string | null;
20
+ type: "input" | "output";
21
+ stream_state: "open" | "closed" | "waiting" | null;
22
+ used_cache?: "full" | "partial" | null;
23
+ cache_duration?: number | null;
24
+ avg_time?: number | null;
25
+ }
26
+
27
+ export interface LoadingStatusArgs {
28
+ fn_index: ILoadingStatus["fn_index"];
29
+ status: ILoadingStatus["status"];
30
+ queue?: ILoadingStatus["queue"];
31
+ size?: ILoadingStatus["queue_size"];
32
+ position?: ILoadingStatus["queue_position"];
33
+ eta?: ILoadingStatus["eta"];
34
+ message?: ILoadingStatus["message"];
35
+ progress_data?: ILoadingStatus["progress"];
36
+ time_limit?: ILoadingStatus["time_limit"];
37
+ type?: "input" | "output";
38
+ stream_state: "open" | "closed" | "waiting" | null;
39
+ validation_error?: string;
40
+ show_validation_error?: boolean;
41
+ used_cache?: "full" | "partial" | null;
42
+ cache_duration?: number | null;
43
+ avg_time?: number | null;
44
+ }
45
+
46
+ export interface ToastMessage {
47
+ type: "error" | "warning" | "info" | "success";
48
+ title: string;
49
+ message: string;
50
+ id: number;
51
+ duration: number | null;
52
+ visible: boolean;
53
+ }
54
+
55
+ export interface GroupedToastMessage {
56
+ type: "error" | "warning" | "info" | "success";
57
+ messages: ToastMessage[];
58
+ expanded: boolean;
59
+ }
6.12.1/statustracker/static/utils.ts ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ export function pretty_si(num: number): string {
2
+ let units = ["", "k", "M", "G", "T", "P", "E", "Z"];
3
+ let i = 0;
4
+ while (num > 1000 && i < units.length - 1) {
5
+ num /= 1000;
6
+ i++;
7
+ }
8
+ let unit = units[i];
9
+ return (Number.isInteger(num) ? num : num.toFixed(1)) + unit;
10
+ }