@gradio/core 1.0.0-dev.0 → 1.0.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/CHANGELOG.md +110 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/src/Blocks.svelte +534 -1001
- package/dist/src/Blocks.svelte.d.ts +32 -45
- package/dist/src/Embed.svelte +82 -55
- package/dist/src/Embed.svelte.d.ts +39 -30
- package/dist/src/Login.svelte +33 -29
- package/dist/src/Login.svelte.d.ts +21 -19
- package/dist/src/MountComponents.svelte +19 -25
- package/dist/src/MountComponents.svelte.d.ts +5 -28
- package/dist/src/{init.d.ts → _init.d.ts} +5 -4
- package/dist/src/{init.js → _init.js} +31 -108
- package/dist/src/api_docs/ApiBanner.svelte +12 -8
- package/dist/src/api_docs/ApiBanner.svelte.d.ts +22 -20
- package/dist/src/api_docs/ApiDocs.svelte +356 -247
- package/dist/src/api_docs/ApiDocs.svelte.d.ts +27 -24
- package/dist/src/api_docs/ApiRecorder.svelte +6 -3
- package/dist/src/api_docs/ApiRecorder.svelte.d.ts +19 -17
- package/dist/src/api_docs/CodeSnippet.svelte +122 -48
- package/dist/src/api_docs/CodeSnippet.svelte.d.ts +29 -25
- package/dist/src/api_docs/CopyButton.svelte +69 -13
- package/dist/src/api_docs/CopyButton.svelte.d.ts +18 -16
- package/dist/src/api_docs/CopyMarkdown.svelte +734 -0
- package/dist/src/api_docs/CopyMarkdown.svelte.d.ts +37 -0
- package/dist/src/api_docs/EndpointDetail.svelte +81 -23
- package/dist/src/api_docs/EndpointDetail.svelte.d.ts +23 -18
- package/dist/src/api_docs/IconArrowUpRight.svelte +34 -0
- package/dist/src/api_docs/IconArrowUpRight.svelte.d.ts +20 -0
- package/dist/src/api_docs/IconCaret.svelte +39 -0
- package/dist/src/api_docs/IconCaret.svelte.d.ts +20 -0
- package/dist/src/api_docs/IconHuggingChat.svelte +62 -0
- package/dist/src/api_docs/IconHuggingChat.svelte.d.ts +20 -0
- package/dist/src/api_docs/InputPayload.svelte +17 -11
- package/dist/src/api_docs/InputPayload.svelte.d.ts +25 -23
- package/dist/src/api_docs/InstallSnippet.svelte +9 -6
- package/dist/src/api_docs/InstallSnippet.svelte.d.ts +18 -16
- package/dist/src/api_docs/MCPSnippet.svelte +139 -126
- package/dist/src/api_docs/MCPSnippet.svelte.d.ts +60 -58
- package/dist/src/api_docs/NoApi.svelte +7 -4
- package/dist/src/api_docs/NoApi.svelte.d.ts +20 -18
- package/dist/src/api_docs/ParametersSnippet.svelte +8 -6
- package/dist/src/api_docs/ParametersSnippet.svelte.d.ts +21 -19
- package/dist/src/api_docs/PercentileChart.svelte +125 -0
- package/dist/src/api_docs/PercentileChart.svelte.d.ts +22 -0
- package/dist/src/api_docs/RecordingSnippet.svelte +124 -110
- package/dist/src/api_docs/RecordingSnippet.svelte.d.ts +24 -22
- package/dist/src/api_docs/ResponseSnippet.svelte +7 -5
- package/dist/src/api_docs/ResponseSnippet.svelte.d.ts +21 -19
- package/dist/src/api_docs/Settings.svelte +73 -62
- package/dist/src/api_docs/Settings.svelte.d.ts +25 -23
- package/dist/src/api_docs/SettingsBanner.svelte +11 -8
- package/dist/src/api_docs/SettingsBanner.svelte.d.ts +20 -18
- package/dist/src/api_docs/TryButton.svelte +5 -3
- package/dist/src/api_docs/TryButton.svelte.d.ts +19 -17
- package/dist/src/api_docs/img/IconCheck.svelte +33 -0
- package/dist/src/api_docs/img/IconCheck.svelte.d.ts +26 -0
- package/dist/src/api_docs/img/IconCopy.svelte +40 -0
- package/dist/src/api_docs/img/IconCopy.svelte.d.ts +26 -0
- package/dist/src/api_docs/img/clear.svelte.d.ts +22 -21
- package/dist/src/dependency.d.ts +145 -0
- package/dist/src/dependency.js +668 -0
- package/dist/src/init.svelte.d.ts +78 -0
- package/dist/src/init.svelte.js +469 -0
- package/dist/src/init_utils.d.ts +32 -0
- package/dist/src/init_utils.js +73 -0
- package/dist/src/lang/en.json +10 -1
- package/dist/src/lang/get_lang_names.js +0 -3
- package/dist/src/lang/ru.json +10 -1
- package/dist/src/stores.d.ts +0 -21
- package/dist/src/stories/I18nMultiLanguageTestComponent.svelte +5 -3
- package/dist/src/stories/I18nMultiLanguageTestComponent.svelte.d.ts +16 -14
- package/dist/src/stories/I18nTestSetup.svelte +14 -10
- package/dist/src/stories/I18nTestSetup.svelte.d.ts +18 -16
- package/dist/src/types.d.ts +31 -26
- package/index.ts +1 -1
- package/package.json +62 -63
- package/src/Blocks.svelte +360 -1063
- package/src/MountComponents.svelte +17 -27
- package/src/{init.ts → _init.ts} +49 -126
- package/src/api_docs/ApiDocs.svelte +84 -62
- package/src/api_docs/CodeSnippet.svelte +83 -24
- package/src/api_docs/CopyButton.svelte +61 -7
- package/src/api_docs/CopyMarkdown.svelte +734 -0
- package/src/api_docs/EndpointDetail.svelte +73 -17
- package/src/api_docs/IconArrowUpRight.svelte +34 -0
- package/src/api_docs/IconCaret.svelte +39 -0
- package/src/api_docs/IconHuggingChat.svelte +62 -0
- package/src/api_docs/MCPSnippet.svelte +44 -73
- package/src/api_docs/ParametersSnippet.svelte +1 -1
- package/src/api_docs/PercentileChart.svelte +125 -0
- package/src/api_docs/ResponseSnippet.svelte +1 -1
- package/src/api_docs/Settings.svelte +11 -11
- package/src/api_docs/img/IconCheck.svelte +33 -0
- package/src/api_docs/img/IconCopy.svelte +40 -0
- package/src/dependency.ts +909 -0
- package/src/init.svelte.ts +717 -0
- package/src/init_utils.ts +99 -0
- package/src/lang/en.json +10 -1
- package/src/lang/get_lang_names.js +0 -3
- package/src/lang/ru.json +10 -1
- package/src/stores.ts +22 -22
- package/src/types.ts +55 -43
- package/dist/src/Render.svelte +0 -105
- package/dist/src/Render.svelte.d.ts +0 -31
- package/dist/src/RenderComponent.svelte +0 -72
- package/dist/src/RenderComponent.svelte.d.ts +0 -33
- package/src/Render.svelte +0 -126
- package/src/RenderComponent.svelte +0 -91
|
@@ -1,32 +1,22 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import Render from "./Render.svelte";
|
|
2
|
+
import Self from "./MountComponents.svelte";
|
|
3
|
+
let { node } = $props();
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
export let root: any;
|
|
8
|
-
export let target: any;
|
|
9
|
-
export let theme_mode: any;
|
|
10
|
-
export let version: any;
|
|
11
|
-
export let autoscroll: boolean;
|
|
12
|
-
export let max_file_size: number | null = null;
|
|
13
|
-
export let client: Client;
|
|
14
|
-
|
|
15
|
-
const dispatch = createEventDispatcher<{ mount?: never }>();
|
|
16
|
-
onMount(() => {
|
|
17
|
-
dispatch("mount");
|
|
18
|
-
});
|
|
5
|
+
let component = $derived(await node.component);
|
|
19
6
|
</script>
|
|
20
7
|
|
|
21
|
-
{#if
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
8
|
+
{#if node && component}
|
|
9
|
+
{#if node.props.shared_props.visible}
|
|
10
|
+
<svelte:component
|
|
11
|
+
this={component.default}
|
|
12
|
+
shared_props={node.props.shared_props}
|
|
13
|
+
props={node.props.props}
|
|
14
|
+
>
|
|
15
|
+
{#if node.children && node.children.length}
|
|
16
|
+
{#each node.children as _node}
|
|
17
|
+
<Self node={_node} />
|
|
18
|
+
{/each}
|
|
19
|
+
{/if}
|
|
20
|
+
</svelte:component>
|
|
21
|
+
{/if}
|
|
32
22
|
{/if}
|
package/src/{init.ts → _init.ts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { writable, type Writable
|
|
1
|
+
import { writable, type Writable } from "svelte/store";
|
|
2
2
|
import { dequal } from "dequal";
|
|
3
3
|
|
|
4
4
|
import type {
|
|
@@ -13,6 +13,7 @@ import type { client_return } from "@gradio/client";
|
|
|
13
13
|
import { create_loading_status_store } from "./stores";
|
|
14
14
|
import { _ } from "svelte-i18n";
|
|
15
15
|
import { i18n_marker } from "./i18n";
|
|
16
|
+
import type { SharedProps } from "@gradio/utils";
|
|
16
17
|
|
|
17
18
|
export interface UpdateTransaction {
|
|
18
19
|
id: number;
|
|
@@ -20,11 +21,17 @@ export interface UpdateTransaction {
|
|
|
20
21
|
prop: string;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const shared_props: (keyof SharedProps)[] = [
|
|
25
|
+
"elem_id",
|
|
26
|
+
"elem_classes",
|
|
27
|
+
"components",
|
|
28
|
+
"visible",
|
|
29
|
+
"interactive",
|
|
30
|
+
"server_fns"
|
|
31
|
+
] as const;
|
|
32
|
+
|
|
33
|
+
type set_data_type = (data: Record<string, unknown>) => void;
|
|
34
|
+
type get_data_type = () => Promise<Record<string, unknown>>;
|
|
28
35
|
|
|
29
36
|
/**
|
|
30
37
|
* Create a store with the layout and a map of targets
|
|
@@ -41,13 +48,12 @@ export function create_components(
|
|
|
41
48
|
): {
|
|
42
49
|
layout: Writable<ComponentMeta>;
|
|
43
50
|
targets: Writable<TargetMap>;
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
get_data: (id: number) => Promise<unknown> | void;
|
|
52
|
+
set_data: (id: number, data: Record<string, unknown>) => void;
|
|
46
53
|
modify_stream: (id: number, state: "open" | "waiting" | "closed") => void;
|
|
47
54
|
get_stream_state: (id: number) => "open" | "waiting" | "closed" | "not_set";
|
|
48
55
|
set_time_limit: (id: number, time_limit: number | undefined) => void;
|
|
49
56
|
loading_status: ReturnType<typeof create_loading_status_store>;
|
|
50
|
-
scheduled_updates: Writable<boolean>;
|
|
51
57
|
create_layout: (args: {
|
|
52
58
|
app: client_return;
|
|
53
59
|
components: ComponentMeta[];
|
|
@@ -65,7 +71,11 @@ export function create_components(
|
|
|
65
71
|
root: string;
|
|
66
72
|
dependencies: Dependency[];
|
|
67
73
|
}) => void;
|
|
68
|
-
|
|
74
|
+
register_component: (
|
|
75
|
+
id: number,
|
|
76
|
+
set: set_data_type,
|
|
77
|
+
get: get_data_type
|
|
78
|
+
) => void;
|
|
69
79
|
} {
|
|
70
80
|
let _component_map: Map<number, ComponentMeta>;
|
|
71
81
|
|
|
@@ -83,16 +93,22 @@ export function create_components(
|
|
|
83
93
|
let keys_per_render_id: Record<number, (string | number)[]> = {};
|
|
84
94
|
let _rootNode: ComponentMeta;
|
|
85
95
|
|
|
86
|
-
let value_change_cb: ((id: number, value: any) => void) | null = null;
|
|
87
|
-
|
|
88
|
-
function value_change(cb: (id: number, value: any) => void): void {
|
|
89
|
-
value_change_cb = cb;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
96
|
let current_layout: LayoutNode;
|
|
93
97
|
let current_root: string;
|
|
94
98
|
|
|
95
|
-
|
|
99
|
+
const get_callbacks = new Map<number, get_data_type>();
|
|
100
|
+
const set_callbacks = new Map<number, set_data_type>();
|
|
101
|
+
|
|
102
|
+
function register_component(
|
|
103
|
+
id: number,
|
|
104
|
+
_set_data: set_data_type,
|
|
105
|
+
_get_data: get_data_type
|
|
106
|
+
): void {
|
|
107
|
+
set_callbacks.set(id, _set_data);
|
|
108
|
+
get_callbacks.set(id, _get_data);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function get_event_specific_args(dependencies: Dependency[]): void {
|
|
96
112
|
dependencies.forEach((dep) => {
|
|
97
113
|
dep.targets.forEach((target) => {
|
|
98
114
|
const instance = instance_map?.[target[0]];
|
|
@@ -122,7 +138,6 @@ export function create_components(
|
|
|
122
138
|
fill_height: boolean;
|
|
123
139
|
};
|
|
124
140
|
}): Promise<void> {
|
|
125
|
-
flush();
|
|
126
141
|
app = _app;
|
|
127
142
|
|
|
128
143
|
if (instance_map) {
|
|
@@ -135,13 +150,15 @@ export function create_components(
|
|
|
135
150
|
c.props.value = matching_instance.props.value;
|
|
136
151
|
}
|
|
137
152
|
}
|
|
153
|
+
|
|
154
|
+
const { shared_props, props } = gather_props(c.props);
|
|
155
|
+
c.props = { props, shared_props };
|
|
138
156
|
});
|
|
139
157
|
}
|
|
140
158
|
|
|
141
159
|
_components = components;
|
|
142
160
|
inputs = new Set();
|
|
143
161
|
outputs = new Set();
|
|
144
|
-
pending_updates = [];
|
|
145
162
|
constructor_map = new Map();
|
|
146
163
|
_component_map = new Map();
|
|
147
164
|
instance_map = {};
|
|
@@ -216,13 +233,13 @@ export function create_components(
|
|
|
216
233
|
root: string;
|
|
217
234
|
dependencies: Dependency[];
|
|
218
235
|
}): void {
|
|
219
|
-
components.forEach((c) => {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
});
|
|
236
|
+
// components.forEach((c) => {
|
|
237
|
+
// for (const prop in c.props) {
|
|
238
|
+
// if (c.props[prop] === null) {
|
|
239
|
+
// c.props[prop] = undefined;
|
|
240
|
+
// }
|
|
241
|
+
// }
|
|
242
|
+
// });
|
|
226
243
|
let replacement_components: ComponentMeta[] = [];
|
|
227
244
|
let new_components: ComponentMeta[] = [];
|
|
228
245
|
components.forEach((c) => {
|
|
@@ -428,9 +445,6 @@ export function create_components(
|
|
|
428
445
|
return instance;
|
|
429
446
|
}
|
|
430
447
|
|
|
431
|
-
let update_scheduled = false;
|
|
432
|
-
let update_scheduled_store = writable(false);
|
|
433
|
-
|
|
434
448
|
/**
|
|
435
449
|
* Load newly visible components after visibility changes
|
|
436
450
|
* @param newly_visible_ids Set of component IDs that are now visible
|
|
@@ -496,102 +510,12 @@ export function create_components(
|
|
|
496
510
|
);
|
|
497
511
|
}
|
|
498
512
|
|
|
499
|
-
function
|
|
500
|
-
|
|
501
|
-
let previous_visible_ids: Set<number> | undefined;
|
|
502
|
-
const all_components = _component_map
|
|
503
|
-
? [..._component_map.values()]
|
|
504
|
-
: _components;
|
|
505
|
-
|
|
506
|
-
if (had_visibility_changes && current_layout) {
|
|
507
|
-
previous_visible_ids = determine_visible_components(
|
|
508
|
-
current_layout,
|
|
509
|
-
all_components
|
|
510
|
-
);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
layout_store.update((layout) => {
|
|
514
|
-
for (let i = 0; i < pending_updates.length; i++) {
|
|
515
|
-
for (let j = 0; j < pending_updates[i].length; j++) {
|
|
516
|
-
const update = pending_updates[i][j];
|
|
517
|
-
if (!update) continue;
|
|
518
|
-
const instance = instance_map?.[update.id];
|
|
519
|
-
if (!instance) continue;
|
|
520
|
-
let new_value;
|
|
521
|
-
const old_value = instance.props[update.prop];
|
|
522
|
-
if (update.value instanceof Map) new_value = new Map(update.value);
|
|
523
|
-
else if (update.value instanceof Set)
|
|
524
|
-
new_value = new Set(update.value);
|
|
525
|
-
else if (Array.isArray(update.value)) new_value = [...update.value];
|
|
526
|
-
else if (update.value == null) new_value = null;
|
|
527
|
-
else if (typeof update.value === "object")
|
|
528
|
-
new_value = { ...update.value };
|
|
529
|
-
else new_value = update.value;
|
|
530
|
-
instance.props[update.prop] = new_value;
|
|
531
|
-
|
|
532
|
-
if (
|
|
533
|
-
update.prop === "value" &&
|
|
534
|
-
!is_visible(instance) &&
|
|
535
|
-
!dequal(old_value, new_value)
|
|
536
|
-
) {
|
|
537
|
-
value_change_cb?.(update.id, new_value);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
return layout;
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
if (had_visibility_changes && current_layout && previous_visible_ids) {
|
|
546
|
-
raf(async () => {
|
|
547
|
-
const new_visible_ids = determine_visible_components(
|
|
548
|
-
current_layout,
|
|
549
|
-
all_components
|
|
550
|
-
);
|
|
551
|
-
const newly_visible_ids = new Set<number>();
|
|
552
|
-
|
|
553
|
-
for (const id of new_visible_ids) {
|
|
554
|
-
if (!previous_visible_ids!.has(id)) {
|
|
555
|
-
newly_visible_ids.add(id);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
await load_newly_visible_components(newly_visible_ids, all_components);
|
|
560
|
-
|
|
561
|
-
if (newly_visible_ids.size > 0) {
|
|
562
|
-
layout_store.update((layout) => layout);
|
|
563
|
-
}
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
pending_updates = [];
|
|
568
|
-
update_scheduled = false;
|
|
569
|
-
update_scheduled_store.set(false);
|
|
513
|
+
async function get_data(id: number): Promise<unknown | void> {
|
|
514
|
+
return get_callbacks.get(id)?.();
|
|
570
515
|
}
|
|
571
516
|
|
|
572
|
-
function
|
|
573
|
-
|
|
574
|
-
pending_updates.push(updates);
|
|
575
|
-
|
|
576
|
-
if (!update_scheduled) {
|
|
577
|
-
update_scheduled = true;
|
|
578
|
-
update_scheduled_store.set(true);
|
|
579
|
-
raf(flush);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
function get_data(id: number): any | Promise<any> {
|
|
583
|
-
let comp = _component_map.get(id);
|
|
584
|
-
if (!comp) {
|
|
585
|
-
const layout = get(layout_store);
|
|
586
|
-
comp = findComponentById(layout, id);
|
|
587
|
-
}
|
|
588
|
-
if (!comp) {
|
|
589
|
-
return null;
|
|
590
|
-
}
|
|
591
|
-
if (comp.instance?.get_value) {
|
|
592
|
-
return comp.instance.get_value() as Promise<any>;
|
|
593
|
-
}
|
|
594
|
-
return comp.props.value;
|
|
517
|
+
function set_data(id: number, data: Record<string, unknown>): void {
|
|
518
|
+
set_callbacks.get(id)?.(data);
|
|
595
519
|
}
|
|
596
520
|
|
|
597
521
|
function findComponentById(
|
|
@@ -641,16 +565,15 @@ export function create_components(
|
|
|
641
565
|
return {
|
|
642
566
|
layout: layout_store,
|
|
643
567
|
targets: target_map,
|
|
644
|
-
update_value,
|
|
645
568
|
get_data,
|
|
569
|
+
set_data,
|
|
646
570
|
modify_stream,
|
|
647
571
|
get_stream_state,
|
|
648
572
|
set_time_limit,
|
|
649
573
|
loading_status,
|
|
650
|
-
scheduled_updates: update_scheduled_store,
|
|
651
574
|
create_layout: create_layout,
|
|
652
575
|
rerender_layout,
|
|
653
|
-
|
|
576
|
+
register_component
|
|
654
577
|
};
|
|
655
578
|
}
|
|
656
579
|
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
import ResponseSnippet from "./ResponseSnippet.svelte";
|
|
22
22
|
import mcp from "./img/mcp.svg";
|
|
23
23
|
import MCPSnippet from "./MCPSnippet.svelte";
|
|
24
|
+
import CopyMarkdown from "./CopyMarkdown.svelte";
|
|
24
25
|
|
|
25
26
|
export let dependencies: Dependency[];
|
|
26
27
|
export let root: string;
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
export let space_id: string | null;
|
|
29
30
|
export let root_node: ComponentMeta;
|
|
30
31
|
export let username: string | null;
|
|
32
|
+
export let last_api_call: Payload | null = null;
|
|
31
33
|
|
|
32
34
|
const js_docs =
|
|
33
35
|
"https://www.gradio.app/guides/getting-started-with-the-js-client";
|
|
@@ -53,6 +55,20 @@
|
|
|
53
55
|
export let api_calls: Payload[] = [];
|
|
54
56
|
let current_language: "python" | "javascript" | "bash" | "mcp" = "python";
|
|
55
57
|
|
|
58
|
+
$: sorted_dependencies = (() => {
|
|
59
|
+
const valid = dependencies.filter(
|
|
60
|
+
(dep) =>
|
|
61
|
+
dep.api_visibility === "public" &&
|
|
62
|
+
info?.named_endpoints?.["/" + dep.api_name]
|
|
63
|
+
);
|
|
64
|
+
if (info && last_api_call) {
|
|
65
|
+
const mostRecent = valid.find((dep) => dep.id === last_api_call.fn_index);
|
|
66
|
+
const others = valid.filter((dep) => dep.id !== last_api_call.fn_index);
|
|
67
|
+
return mostRecent ? [mostRecent, ...others] : valid;
|
|
68
|
+
}
|
|
69
|
+
return valid;
|
|
70
|
+
})();
|
|
71
|
+
|
|
56
72
|
function set_query_param(key: string, value: string) {
|
|
57
73
|
const url = new URL(window.location.href);
|
|
58
74
|
url.searchParams.set(key, value);
|
|
@@ -126,25 +142,12 @@
|
|
|
126
142
|
$: selected_tools_array = Array.from(selected_tools);
|
|
127
143
|
$: selected_tools_without_prefix =
|
|
128
144
|
selected_tools_array.map(remove_tool_prefix);
|
|
129
|
-
$: mcp_server_url = `${root}gradio_api/mcp/sse`;
|
|
130
145
|
$: mcp_server_url_streamable =
|
|
131
146
|
selected_tools_array.length > 0 &&
|
|
132
147
|
selected_tools_array.length < tools.length
|
|
133
148
|
? `${root}gradio_api/mcp/?tools=${selected_tools_without_prefix.join(",")}`
|
|
134
149
|
: `${root}gradio_api/mcp/`;
|
|
135
150
|
|
|
136
|
-
$: if (mcp_json_sse && selected_tools.size > 0) {
|
|
137
|
-
const baseUrl =
|
|
138
|
-
selected_tools_array.length > 0 &&
|
|
139
|
-
selected_tools_array.length < tools.length
|
|
140
|
-
? `${root}gradio_api/mcp/sse?tools=${selected_tools_without_prefix.join(",")}`
|
|
141
|
-
: `${root}gradio_api/mcp/sse`;
|
|
142
|
-
mcp_json_sse.mcpServers.gradio.url = baseUrl;
|
|
143
|
-
if (mcp_json_stdio) {
|
|
144
|
-
mcp_json_stdio.mcpServers.gradio.args[1] = baseUrl;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
151
|
interface ToolParameter {
|
|
149
152
|
title?: string;
|
|
150
153
|
type: string;
|
|
@@ -167,7 +170,6 @@
|
|
|
167
170
|
|
|
168
171
|
let tools: Tool[] = [];
|
|
169
172
|
let headers: string[] = [];
|
|
170
|
-
let mcp_json_sse: any;
|
|
171
173
|
let mcp_json_stdio: any;
|
|
172
174
|
let file_data_present = false;
|
|
173
175
|
let selected_tools: Set<string> = new Set();
|
|
@@ -212,29 +214,15 @@
|
|
|
212
214
|
selected_tools = new Set(tools.map((tool) => tool.name));
|
|
213
215
|
headers = schema.map((tool: any) => tool.meta?.headers || []).flat();
|
|
214
216
|
if (headers.length > 0) {
|
|
215
|
-
mcp_json_sse = {
|
|
216
|
-
mcpServers: {
|
|
217
|
-
gradio: {
|
|
218
|
-
url: mcp_server_url,
|
|
219
|
-
headers: headers.reduce(
|
|
220
|
-
(accumulator: Record<string, string>, current_key: string) => {
|
|
221
|
-
accumulator[current_key] = "<YOUR_HEADER_VALUE>";
|
|
222
|
-
return accumulator;
|
|
223
|
-
},
|
|
224
|
-
{}
|
|
225
|
-
)
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
217
|
mcp_json_stdio = {
|
|
230
218
|
mcpServers: {
|
|
231
219
|
gradio: {
|
|
232
220
|
command: "npx",
|
|
233
221
|
args: [
|
|
234
222
|
"mcp-remote",
|
|
235
|
-
|
|
223
|
+
mcp_server_url_streamable,
|
|
236
224
|
"--transport",
|
|
237
|
-
"
|
|
225
|
+
"streamable-http",
|
|
238
226
|
...headers
|
|
239
227
|
.map((header) => [
|
|
240
228
|
"--header",
|
|
@@ -246,24 +234,20 @@
|
|
|
246
234
|
}
|
|
247
235
|
};
|
|
248
236
|
} else {
|
|
249
|
-
mcp_json_sse = {
|
|
250
|
-
mcpServers: {
|
|
251
|
-
gradio: {
|
|
252
|
-
url: mcp_server_url
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
237
|
mcp_json_stdio = {
|
|
257
238
|
mcpServers: {
|
|
258
239
|
gradio: {
|
|
259
240
|
command: "npx",
|
|
260
|
-
args: [
|
|
241
|
+
args: [
|
|
242
|
+
"mcp-remote",
|
|
243
|
+
mcp_server_url_streamable,
|
|
244
|
+
"--transport",
|
|
245
|
+
"streamable-http"
|
|
246
|
+
]
|
|
261
247
|
}
|
|
262
248
|
}
|
|
263
249
|
};
|
|
264
250
|
if (file_data_present) {
|
|
265
|
-
mcp_json_sse.mcpServers.upload_files_to_gradio =
|
|
266
|
-
upload_file_mcp_server;
|
|
267
251
|
mcp_json_stdio.mcpServers.upload_files_to_gradio =
|
|
268
252
|
upload_file_mcp_server;
|
|
269
253
|
}
|
|
@@ -274,6 +258,14 @@
|
|
|
274
258
|
}
|
|
275
259
|
}
|
|
276
260
|
|
|
261
|
+
let markdown_code_snippets: Record<string, Record<string, string>> = {};
|
|
262
|
+
|
|
263
|
+
$: markdown_code_snippets;
|
|
264
|
+
|
|
265
|
+
let config_snippets: Record<string, string> = {};
|
|
266
|
+
|
|
267
|
+
$: config_snippets;
|
|
268
|
+
|
|
277
269
|
onMount(() => {
|
|
278
270
|
const controller = new AbortController();
|
|
279
271
|
const signal = controller.signal;
|
|
@@ -288,8 +280,8 @@
|
|
|
288
280
|
current_language = lang_param as "python" | "javascript" | "bash" | "mcp";
|
|
289
281
|
}
|
|
290
282
|
|
|
291
|
-
|
|
292
|
-
fetch(
|
|
283
|
+
const mcp_schema_url = `${root}gradio_api/mcp/schema`;
|
|
284
|
+
fetch(mcp_schema_url, { signal: signal })
|
|
293
285
|
.then((response) => {
|
|
294
286
|
mcp_server_active = response.ok;
|
|
295
287
|
if (mcp_server_active) {
|
|
@@ -326,10 +318,32 @@
|
|
|
326
318
|
</div>
|
|
327
319
|
|
|
328
320
|
<div class="docs-wrap">
|
|
329
|
-
<div
|
|
321
|
+
<div
|
|
322
|
+
class="client-doc"
|
|
323
|
+
style="display: flex; align-items: center; justify-content: space-between;"
|
|
324
|
+
>
|
|
330
325
|
<p style="font-size: var(--text-lg);">
|
|
331
326
|
Choose one of the following ways to interact with the API.
|
|
332
327
|
</p>
|
|
328
|
+
<CopyMarkdown
|
|
329
|
+
{current_language}
|
|
330
|
+
{space_id}
|
|
331
|
+
{root}
|
|
332
|
+
{api_count}
|
|
333
|
+
{tools}
|
|
334
|
+
{py_docs}
|
|
335
|
+
{js_docs}
|
|
336
|
+
{bash_docs}
|
|
337
|
+
{mcp_docs}
|
|
338
|
+
{spaces_docs_suffix}
|
|
339
|
+
{mcp_server_active}
|
|
340
|
+
{mcp_server_url_streamable}
|
|
341
|
+
{config_snippets}
|
|
342
|
+
{markdown_code_snippets}
|
|
343
|
+
{dependencies}
|
|
344
|
+
{info}
|
|
345
|
+
{js_info}
|
|
346
|
+
/>
|
|
333
347
|
</div>
|
|
334
348
|
<div class="endpoint">
|
|
335
349
|
<div class="snippets">
|
|
@@ -392,25 +406,27 @@
|
|
|
392
406
|
href={current_language == "python" ? py_docs : js_docs}
|
|
393
407
|
target="_blank">docs</a
|
|
394
408
|
>) if you don't already have it installed.
|
|
395
|
-
{:else if current_language == "
|
|
396
|
-
<MCPSnippet
|
|
397
|
-
{mcp_server_active}
|
|
398
|
-
{mcp_server_url}
|
|
399
|
-
{mcp_server_url_streamable}
|
|
400
|
-
tools={tools.filter((tool) => selected_tools.has(tool.name))}
|
|
401
|
-
all_tools={tools}
|
|
402
|
-
bind:selected_tools
|
|
403
|
-
{mcp_json_sse}
|
|
404
|
-
{mcp_json_stdio}
|
|
405
|
-
{file_data_present}
|
|
406
|
-
{mcp_docs}
|
|
407
|
-
{analytics}
|
|
408
|
-
/>
|
|
409
|
-
{:else}
|
|
409
|
+
{:else if current_language == "bash"}
|
|
410
410
|
1. Confirm that you have cURL installed on your system.
|
|
411
411
|
{/if}
|
|
412
412
|
</p>
|
|
413
413
|
|
|
414
|
+
<div class:hidden={current_language !== "mcp"}>
|
|
415
|
+
<MCPSnippet
|
|
416
|
+
{mcp_server_active}
|
|
417
|
+
{mcp_server_url_streamable}
|
|
418
|
+
tools={tools.filter((tool) => selected_tools.has(tool.name))}
|
|
419
|
+
all_tools={tools}
|
|
420
|
+
bind:selected_tools
|
|
421
|
+
{mcp_json_stdio}
|
|
422
|
+
{file_data_present}
|
|
423
|
+
{mcp_docs}
|
|
424
|
+
{analytics}
|
|
425
|
+
{root}
|
|
426
|
+
bind:config_snippets
|
|
427
|
+
/>
|
|
428
|
+
</div>
|
|
429
|
+
|
|
414
430
|
{#if current_language !== "mcp"}
|
|
415
431
|
<InstallSnippet {current_language} />
|
|
416
432
|
|
|
@@ -464,9 +480,9 @@
|
|
|
464
480
|
{/if}
|
|
465
481
|
{/if}
|
|
466
482
|
|
|
467
|
-
{
|
|
468
|
-
{#each
|
|
469
|
-
{#if
|
|
483
|
+
<div class:hidden={current_language === "mcp"}>
|
|
484
|
+
{#each sorted_dependencies as dependency}
|
|
485
|
+
{#if info.named_endpoints["/" + dependency.api_name]}
|
|
470
486
|
<div class="endpoint-container">
|
|
471
487
|
<CodeSnippet
|
|
472
488
|
endpoint_parameters={info.named_endpoints[
|
|
@@ -482,6 +498,8 @@
|
|
|
482
498
|
"/" + dependency.api_name
|
|
483
499
|
].description}
|
|
484
500
|
{analytics}
|
|
501
|
+
{last_api_call}
|
|
502
|
+
bind:markdown_code_snippets
|
|
485
503
|
/>
|
|
486
504
|
|
|
487
505
|
<ParametersSnippet
|
|
@@ -506,7 +524,7 @@
|
|
|
506
524
|
</div>
|
|
507
525
|
{/if}
|
|
508
526
|
{/each}
|
|
509
|
-
|
|
527
|
+
</div>
|
|
510
528
|
</div>
|
|
511
529
|
</div>
|
|
512
530
|
{:else}
|
|
@@ -701,4 +719,8 @@
|
|
|
701
719
|
.api-name {
|
|
702
720
|
color: var(--color-accent);
|
|
703
721
|
}
|
|
722
|
+
|
|
723
|
+
.hidden {
|
|
724
|
+
display: none;
|
|
725
|
+
}
|
|
704
726
|
</style>
|