@gradio/core 1.2.0 → 1.4.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/src/Blocks.svelte +39 -18
  3. package/dist/src/MountComponents.svelte +11 -2
  4. package/dist/src/MountComponents.svelte.d.ts +1 -1
  5. package/dist/src/MountCustomComponent.svelte +38 -0
  6. package/dist/src/MountCustomComponent.svelte.d.ts +6 -0
  7. package/dist/src/api_docs/ApiBanner.svelte +6 -2
  8. package/dist/src/api_docs/ApiBanner.svelte.d.ts +1 -1
  9. package/dist/src/api_docs/ApiDocs.svelte +41 -25
  10. package/dist/src/api_docs/CodeSnippet.svelte +67 -170
  11. package/dist/src/api_docs/CodeSnippet.svelte.d.ts +2 -6
  12. package/dist/src/api_docs/CopyMarkdown.svelte +7 -2
  13. package/dist/src/api_docs/CopyMarkdown.svelte.d.ts +1 -1
  14. package/dist/src/api_docs/InstallSnippet.svelte +6 -1
  15. package/dist/src/api_docs/InstallSnippet.svelte.d.ts +1 -1
  16. package/dist/src/api_docs/ParametersSnippet.svelte +6 -1
  17. package/dist/src/api_docs/ParametersSnippet.svelte.d.ts +1 -1
  18. package/dist/src/api_docs/RecordingSnippet.svelte +6 -1
  19. package/dist/src/api_docs/RecordingSnippet.svelte.d.ts +1 -1
  20. package/dist/src/api_docs/ResponseSnippet.svelte +6 -1
  21. package/dist/src/api_docs/ResponseSnippet.svelte.d.ts +1 -1
  22. package/dist/src/api_docs/SkillSnippet.svelte +125 -0
  23. package/dist/src/api_docs/SkillSnippet.svelte.d.ts +20 -0
  24. package/dist/src/api_docs/img/skill.svg +10 -0
  25. package/dist/src/api_docs/utils.d.ts +0 -1
  26. package/dist/src/api_docs/utils.js +0 -22
  27. package/dist/src/dependency.d.ts +3 -1
  28. package/dist/src/dependency.js +19 -1
  29. package/dist/src/init.svelte.d.ts +1 -1
  30. package/dist/src/init.svelte.js +108 -34
  31. package/dist/src/init_utils.d.ts +4 -1
  32. package/dist/src/init_utils.js +1 -1
  33. package/dist/src/types.d.ts +2 -0
  34. package/dist/src/vite-env-override.d.ts +1 -0
  35. package/package.json +55 -55
  36. package/src/Blocks.svelte +39 -18
  37. package/src/MountComponents.svelte +11 -2
  38. package/src/MountCustomComponent.svelte +38 -0
  39. package/src/api_docs/ApiBanner.svelte +6 -2
  40. package/src/api_docs/ApiDocs.svelte +41 -25
  41. package/src/api_docs/CodeSnippet.svelte +67 -170
  42. package/src/api_docs/CopyMarkdown.svelte +7 -2
  43. package/src/api_docs/InstallSnippet.svelte +6 -1
  44. package/src/api_docs/ParametersSnippet.svelte +6 -1
  45. package/src/api_docs/RecordingSnippet.svelte +6 -1
  46. package/src/api_docs/ResponseSnippet.svelte +6 -1
  47. package/src/api_docs/SkillSnippet.svelte +125 -0
  48. package/src/api_docs/img/skill.svg +10 -0
  49. package/src/api_docs/utils.ts +0 -25
  50. package/src/dependency.ts +19 -1
  51. package/src/init.svelte.ts +139 -43
  52. package/src/init.test.ts +1 -1
  53. package/src/init_utils.ts +2 -2
  54. package/src/types.ts +2 -1
  55. package/src/vite-env-override.d.ts +1 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,67 @@
1
1
  # @gradio/core
2
2
 
3
+ ## 1.4.0
4
+
5
+ ### Features
6
+
7
+ - [#12879](https://github.com/gradio-app/gradio/pull/12879) [`c498688`](https://github.com/gradio-app/gradio/commit/c4986883b267570d76b442899c6fc09d14e3e222) - Ensure svelte version mismatches do not break custom components. Thanks @pngwn!
8
+
9
+ ### Fixes
10
+
11
+ - [#12970](https://github.com/gradio-app/gradio/pull/12970) [`7326ea3`](https://github.com/gradio-app/gradio/commit/7326ea312bee7ccdaf4a1e4e11ace8f11b607ca5) - remove new console logs. Thanks @hannahblair!
12
+ - [#12968](https://github.com/gradio-app/gradio/pull/12968) [`fe95534`](https://github.com/gradio-app/gradio/commit/fe955348f24115744015d85639e170b8518b28c1) - Fix custom component reload mode. Thanks @freddyaboulton!
13
+ - [#12956](https://github.com/gradio-app/gradio/pull/12956) [`e8dadd6`](https://github.com/gradio-app/gradio/commit/e8dadd648483b6016913a9b7fa2580dbc08cb823) - Fix fill_height not working after Svelte 5 migration. Thanks @hysts!
14
+
15
+ ### Dependency updates
16
+
17
+ - @gradio/button@0.6.5
18
+ - @gradio/code@0.17.4
19
+ - @gradio/html@0.11.1
20
+ - @gradio/paramviewer@0.9.5
21
+ - @gradio/statustracker@0.12.5
22
+ - @gradio/tabitem@0.6.6
23
+ - @gradio/tabs@0.5.8
24
+ - @gradio/utils@0.12.0
25
+ - @gradio/column@0.3.2
26
+ - @gradio/atoms@0.22.2
27
+ - @gradio/upload@0.17.7
28
+ - @gradio/image@0.25.4
29
+ - @gradio/gallery@0.17.3
30
+ - @gradio/plot@0.10.5
31
+ - @gradio/checkbox@0.6.4
32
+ - @gradio/textbox@0.13.5
33
+ - @gradio/dropdown@0.11.5
34
+ - @gradio/file@0.14.4
35
+ - @gradio/video@0.20.4
36
+ - @gradio/audio@0.22.4
37
+
38
+ ## 1.3.0
39
+
40
+ ### Dependency updates
41
+
42
+ - @gradio/html@0.11.0
43
+
44
+ ## 1.3.0
45
+
46
+ ### Features
47
+
48
+ - [#12918](https://github.com/gradio-app/gradio/pull/12918) [`e29e1cc`](https://github.com/gradio-app/gradio/commit/e29e1ccd5874cb98b813ed4f7f72d9fef2935016) - Add Space-specific skill generation to `gradio skills add`. Thanks @abidlabs!
49
+ - [#12929](https://github.com/gradio-app/gradio/pull/12929) [`978bc6e`](https://github.com/gradio-app/gradio/commit/978bc6ea5094aa11e10994cdd662c4c663a86a83) - Add server functions support to gr.HTML. Thanks @aliabid94!
50
+ - [#12907](https://github.com/gradio-app/gradio/pull/12907) [`3e625a0`](https://github.com/gradio-app/gradio/commit/3e625a0ecfab6e74b7561b68adbe55341ecbc47a) - Better error handling when connection to server is lost. Thanks @abidlabs!
51
+
52
+ ### Fixes
53
+
54
+ - [#12904](https://github.com/gradio-app/gradio/pull/12904) [`7c3fa2a`](https://github.com/gradio-app/gradio/commit/7c3fa2a6900cfa3c87cb61ffa9b34b75d1ae49ba) - Fix Loading Spinner Issue Caused by Events Targeting Components In Inactive Tabs. Thanks @freddyaboulton!
55
+ - [#12903](https://github.com/gradio-app/gradio/pull/12903) [`57707c7`](https://github.com/gradio-app/gradio/commit/57707c72edd0e9fee9821882f75ab322ce110fe3) - Fix Tab i18n issue. Thanks @freddyaboulton!
56
+ - [#12906](https://github.com/gradio-app/gradio/pull/12906) [`81482b5`](https://github.com/gradio-app/gradio/commit/81482b58706ee9948d0f04e84e632ebb8d4bf7ea) - Lazy load sub-tab and accordion components. Thanks @dawoodkhan82!
57
+
58
+ ### Dependency updates
59
+
60
+ - @gradio/client@2.1.0
61
+ - @gradio/button@0.6.4
62
+ - @gradio/html@0.10.0
63
+ - @gradio/tabs@0.5.7
64
+
3
65
  ## 1.2.0
4
66
 
5
67
  ### Features
@@ -4,18 +4,15 @@
4
4
  import { Client } from "@gradio/client";
5
5
  import { writable } from "svelte/store";
6
6
 
7
- // import type { LoadingStatus, LoadingStatusCollection } from "./stores";
8
-
9
7
  import type {
10
8
  ComponentMeta,
11
9
  Dependency as IDependency,
12
10
  LayoutNode
13
11
  } from "./types";
14
- // import type { UpdateTransaction } from "./_init";
15
12
  import type { ThemeMode, Payload } from "./types";
16
13
  import { Toast } from "@gradio/statustracker";
17
14
  import type { ToastMessage } from "@gradio/statustracker";
18
- import { type ShareData, type ValueData, GRADIO_ROOT } from "@gradio/utils";
15
+ import { type ShareData, GRADIO_ROOT } from "@gradio/utils";
19
16
 
20
17
  import MountComponents from "./MountComponents.svelte";
21
18
  import { prefix_css } from "./css";
@@ -24,18 +21,13 @@
24
21
  import type ApiDocsInterface from "./api_docs/ApiDocs.svelte";
25
22
  import type ApiRecorderInterface from "./api_docs/ApiRecorder.svelte";
26
23
  import type SettingsInterface from "./api_docs/Settings.svelte";
27
- // import type { ComponentType } from "svelte";
28
24
 
29
25
  import logo from "./images/logo.svg";
30
26
  import api_logo from "./api_docs/img/api-logo.svg";
31
27
  import settings_logo from "./api_docs/img/settings-logo.svg";
32
28
  import record_stop from "./api_docs/img/record-stop.svg";
33
29
  import { AppTree } from "./init.svelte";
34
- // import type {
35
- // LogMessage,
36
- // RenderMessage,
37
- // StatusMessage,
38
- // } from "@gradio/client";
30
+
39
31
  import * as screen_recorder from "./screen_recorder";
40
32
 
41
33
  import { DependencyManager } from "./dependency";
@@ -104,6 +96,7 @@
104
96
  });
105
97
 
106
98
  let messages: (ToastMessage & { fn_index: number })[] = $state([]);
99
+ let reconnect_interval: ReturnType<typeof setInterval> | null = null;
107
100
 
108
101
  function gradio_event_dispatcher(
109
102
  id: number,
@@ -170,7 +163,8 @@
170
163
  version,
171
164
  api_prefix,
172
165
  max_file_size,
173
- autoscroll
166
+ autoscroll,
167
+ fill_height
174
168
  },
175
169
  app,
176
170
  $reactive_formatter,
@@ -190,11 +184,6 @@
190
184
  });
191
185
  }
192
186
 
193
- setContext(GRADIO_ROOT, {
194
- register: app_tree.register_component.bind(app_tree),
195
- dispatcher: gradio_event_dispatcher
196
- });
197
-
198
187
  let api_calls: Payload[] = $state([]);
199
188
  let last_api_call: Payload | null = $state(null);
200
189
  // We need a callback to add to api_calls from the DependencyManager
@@ -206,6 +195,35 @@
206
195
  api_calls = [...api_calls, last_api_call];
207
196
  };
208
197
 
198
+ function handle_connection_lost(): void {
199
+ messages = messages.filter((m) => m.type !== "error");
200
+
201
+ ++_error_id;
202
+ messages.push({
203
+ title: "Connection Lost",
204
+ message: LOST_CONNECTION_MESSAGE,
205
+ fn_index: -1,
206
+ type: "error",
207
+ id: _error_id,
208
+ duration: null,
209
+ visible: true
210
+ });
211
+
212
+ reconnect_interval = setInterval(async () => {
213
+ try {
214
+ const status = await app.reconnect();
215
+ if (status === "connected" || status === "changed") {
216
+ clearInterval(reconnect_interval!);
217
+ reconnect_interval = null;
218
+ window.location.reload();
219
+ }
220
+ } catch (e) {
221
+ // server still unreachable
222
+ console.debug(e);
223
+ }
224
+ }, 2000);
225
+ }
226
+
209
227
  let dep_manager = new DependencyManager(
210
228
  dependencies,
211
229
  app,
@@ -213,7 +231,8 @@
213
231
  app_tree.get_state.bind(app_tree),
214
232
  app_tree.rerender.bind(app_tree),
215
233
  new_message,
216
- add_to_api_calls
234
+ add_to_api_calls,
235
+ handle_connection_lost
217
236
  );
218
237
 
219
238
  $effect(() => {
@@ -225,7 +244,8 @@
225
244
  version,
226
245
  api_prefix,
227
246
  max_file_size,
228
- autoscroll
247
+ autoscroll,
248
+ fill_height
229
249
  });
230
250
  dep_manager.reload(
231
251
  dependencies,
@@ -426,6 +446,7 @@
426
446
  return () => {
427
447
  mut.disconnect();
428
448
  res.disconnect();
449
+ if (reconnect_interval) clearInterval(reconnect_interval);
429
450
  };
430
451
  });
431
452
 
@@ -1,12 +1,13 @@
1
1
  <script lang="ts">
2
2
  import Self from "./MountComponents.svelte";
3
- let { node } = $props();
3
+ import MountCustomComponent from "./MountCustomComponent.svelte";
4
+ let { node, ...rest } = $props();
4
5
 
5
6
  let component = $derived(await node.component);
6
7
  </script>
7
8
 
8
9
  {#if node && component}
9
- {#if node.props.shared_props.visible}
10
+ {#if node.props.shared_props.visible && !node.runtime}
10
11
  <svelte:component
11
12
  this={component.default}
12
13
  shared_props={node.props.shared_props}
@@ -18,5 +19,13 @@
18
19
  {/each}
19
20
  {/if}
20
21
  </svelte:component>
22
+ {:else if node.props.shared_props.visible && node.runtime}
23
+ <MountCustomComponent {...rest} {node}>
24
+ {#if node.children && node.children.length}
25
+ {#each node.children as _node}
26
+ <Self node={_node} />
27
+ {/each}
28
+ {/if}
29
+ </MountCustomComponent>
21
30
  {/if}
22
31
  {/if}
@@ -1,5 +1,5 @@
1
1
  declare const MountComponents: import("svelte").Component<{
2
2
  node: any;
3
- }, {}, "">;
3
+ } & Record<string, any>, {}, "">;
4
4
  type MountComponents = ReturnType<typeof MountComponents>;
5
5
  export default MountComponents;
@@ -0,0 +1,38 @@
1
+ <script lang="ts">
2
+ let { node, children, ...rest } = $props();
3
+
4
+ let component = $derived(await node.component);
5
+ let runtime = $derived(
6
+ (await node.runtime) as {
7
+ mount: typeof import("svelte").mount;
8
+ unmount: typeof import("svelte").unmount;
9
+ }
10
+ );
11
+ let el: HTMLElement = $state(null);
12
+
13
+ $effect(() => {
14
+ if (!el || !runtime || !component) return;
15
+
16
+ // Read prop references so the effect re-runs when the node is
17
+ // replaced during a dev reload (new objects are created by
18
+ // app_tree.reload).
19
+ const _shared_props = node.props.shared_props;
20
+ const _props = node.props.props;
21
+ const _runtime = runtime;
22
+
23
+ const mounted = _runtime.mount(component.default, {
24
+ target: el,
25
+ props: {
26
+ shared_props: _shared_props,
27
+ props: _props,
28
+ children
29
+ }
30
+ });
31
+
32
+ return () => {
33
+ _runtime.unmount(mounted);
34
+ };
35
+ });
36
+ </script>
37
+
38
+ <span bind:this={el}></span>
@@ -0,0 +1,6 @@
1
+ declare const MountCustomComponent: import("svelte").Component<{
2
+ node: any;
3
+ children: any;
4
+ } & Record<string, any>, {}, "">;
5
+ type MountCustomComponent = ReturnType<typeof MountCustomComponent>;
6
+ export default MountCustomComponent;
@@ -6,8 +6,12 @@
6
6
 
7
7
  export let root: string;
8
8
  export let api_count: number;
9
- export let current_language: "python" | "javascript" | "bash" | "mcp" =
10
- "python";
9
+ export let current_language:
10
+ | "python"
11
+ | "javascript"
12
+ | "bash"
13
+ | "skill"
14
+ | "mcp" = "python";
11
15
 
12
16
  const dispatch = createEventDispatcher();
13
17
  </script>
@@ -14,7 +14,7 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
14
14
  declare const ApiBanner: $$__sveltets_2_IsomorphicComponent<{
15
15
  root: string;
16
16
  api_count: number;
17
- current_language?: "python" | "javascript" | "bash" | "mcp";
17
+ current_language?: "python" | "javascript" | "bash" | "skill" | "mcp";
18
18
  }, {
19
19
  close: CustomEvent<any>;
20
20
  } & {
@@ -19,6 +19,8 @@
19
19
  import javascript from "./img/javascript.svg";
20
20
  import bash from "./img/bash.svg";
21
21
  import ResponseSnippet from "./ResponseSnippet.svelte";
22
+ import skill from "./img/skill.svg";
23
+ import SkillSnippet from "./SkillSnippet.svelte";
22
24
  import mcp from "./img/mcp.svg";
23
25
  import MCPSnippet from "./MCPSnippet.svelte";
24
26
  import CopyMarkdown from "./CopyMarkdown.svelte";
@@ -53,7 +55,8 @@
53
55
  }
54
56
 
55
57
  export let api_calls: Payload[] = [];
56
- let current_language: "python" | "javascript" | "bash" | "mcp" = "python";
58
+ let current_language: "python" | "javascript" | "bash" | "skill" | "mcp" =
59
+ "python";
57
60
 
58
61
  $: sorted_dependencies = (() => {
59
62
  const valid = dependencies.filter(
@@ -81,13 +84,16 @@
81
84
  }
82
85
 
83
86
  function is_valid_language(lang: string | null): boolean {
84
- return ["python", "javascript", "bash", "mcp"].includes(lang ?? "");
87
+ return ["python", "javascript", "bash", "skill", "mcp"].includes(
88
+ lang ?? ""
89
+ );
85
90
  }
86
91
 
87
- const langs = [
92
+ $: langs = [
88
93
  ["python", "Python", python],
89
94
  ["javascript", "JavaScript", javascript],
90
95
  ["bash", "cURL", bash],
96
+ ...(space_id ? [["skill", "Skill", skill] as const] : []),
91
97
  ["mcp", "MCP", mcp]
92
98
  ] as const;
93
99
 
@@ -277,7 +283,12 @@
277
283
 
278
284
  const lang_param = get_query_param("lang");
279
285
  if (is_valid_language(lang_param)) {
280
- current_language = lang_param as "python" | "javascript" | "bash" | "mcp";
286
+ current_language = lang_param as
287
+ | "python"
288
+ | "javascript"
289
+ | "bash"
290
+ | "skill"
291
+ | "mcp";
281
292
  }
282
293
 
283
294
  const mcp_schema_url = `${root}gradio_api/mcp/schema`;
@@ -398,18 +409,25 @@
398
409
  API Documentation
399
410
  </p>
400
411
  {:else}
401
- <p class="padded">
402
- {#if current_language == "python" || current_language == "javascript"}
403
- 1. Install the
404
- <span style="text-transform:capitalize">{current_language}</span>
405
- client (<a
406
- href={current_language == "python" ? py_docs : js_docs}
407
- target="_blank">docs</a
408
- >) if you don't already have it installed.
409
- {:else if current_language == "bash"}
410
- 1. Confirm that you have cURL installed on your system.
411
- {/if}
412
- </p>
412
+ {#if current_language !== "skill"}
413
+ <p class="padded">
414
+ {#if current_language == "python" || current_language == "javascript"}
415
+ 1. Install the
416
+ <span style="text-transform:capitalize">{current_language}</span
417
+ >
418
+ client (<a
419
+ href={current_language == "python" ? py_docs : js_docs}
420
+ target="_blank">docs</a
421
+ >) if you don't already have it installed.
422
+ {:else if current_language == "bash"}
423
+ 1. Confirm that you have cURL installed on your system.
424
+ {/if}
425
+ </p>
426
+ {/if}
427
+
428
+ <div class:hidden={current_language !== "skill"}>
429
+ <SkillSnippet {space_id} />
430
+ </div>
413
431
 
414
432
  <div class:hidden={current_language !== "mcp"}>
415
433
  <MCPSnippet
@@ -427,7 +445,7 @@
427
445
  />
428
446
  </div>
429
447
 
430
- {#if current_language !== "mcp"}
448
+ {#if current_language !== "mcp" && current_language !== "skill"}
431
449
  <InstallSnippet {current_language} />
432
450
 
433
451
  <p class="padded">
@@ -480,25 +498,23 @@
480
498
  {/if}
481
499
  {/if}
482
500
 
483
- <div class:hidden={current_language === "mcp"}>
501
+ <div
502
+ class:hidden={current_language === "mcp" ||
503
+ current_language === "skill"}
504
+ >
484
505
  {#each sorted_dependencies as dependency}
485
506
  {#if info.named_endpoints["/" + dependency.api_name]}
486
507
  <div class="endpoint-container">
487
508
  <CodeSnippet
488
- endpoint_parameters={info.named_endpoints[
489
- "/" + dependency.api_name
490
- ].parameters}
491
509
  {dependency}
492
510
  {current_language}
493
- {root}
494
- {space_id}
495
- {username}
496
- api_prefix={app.api_prefix}
497
511
  api_description={info.named_endpoints[
498
512
  "/" + dependency.api_name
499
513
  ].description}
500
514
  {analytics}
501
515
  {last_api_call}
516
+ code_snippets={info.named_endpoints["/" + dependency.api_name]
517
+ .code_snippets}
502
518
  bind:markdown_code_snippets
503
519
  />
504
520