@gradio/core 0.29.2 → 1.0.0-dev.3
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 +103 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/src/Blocks.svelte +518 -999
- package/dist/src/Blocks.svelte.d.ts +31 -46
- 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 +338 -246
- package/dist/src/api_docs/ApiDocs.svelte.d.ts +26 -24
- package/dist/src/api_docs/ApiRecorder.svelte +9 -3
- package/dist/src/api_docs/ApiRecorder.svelte.d.ts +19 -17
- package/dist/src/api_docs/CodeSnippet.svelte +60 -30
- package/dist/src/api_docs/CodeSnippet.svelte.d.ts +27 -24
- 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 +8 -6
- package/dist/src/api_docs/EndpointDetail.svelte.d.ts +20 -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 +119 -99
- package/dist/src/api_docs/MCPSnippet.svelte.d.ts +59 -58
- package/dist/src/api_docs/NoApi.svelte +8 -5
- 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/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 +142 -0
- package/dist/src/dependency.js +653 -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 +29 -25
- package/index.ts +1 -1
- package/package.json +59 -59
- package/src/Blocks.svelte +344 -1059
- package/src/MountComponents.svelte +17 -27
- package/src/{init.ts → _init.ts} +49 -126
- package/src/api_docs/ApiDocs.svelte +67 -62
- package/src/api_docs/ApiRecorder.svelte +3 -0
- package/src/api_docs/CodeSnippet.svelte +20 -5
- package/src/api_docs/CopyButton.svelte +61 -7
- package/src/api_docs/CopyMarkdown.svelte +734 -0
- 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 +24 -46
- package/src/api_docs/NoApi.svelte +1 -1
- package/src/api_docs/ParametersSnippet.svelte +1 -1
- 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 +880 -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 +54 -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;
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"https://www.gradio.app/guides/building-mcp-server-with-gradio";
|
|
41
42
|
|
|
42
43
|
let api_count = dependencies.filter(
|
|
43
|
-
(dependency) => dependency.
|
|
44
|
+
(dependency) => dependency.api_visibility === "public"
|
|
44
45
|
).length;
|
|
45
46
|
|
|
46
47
|
if (root === "") {
|
|
@@ -126,25 +127,12 @@
|
|
|
126
127
|
$: selected_tools_array = Array.from(selected_tools);
|
|
127
128
|
$: selected_tools_without_prefix =
|
|
128
129
|
selected_tools_array.map(remove_tool_prefix);
|
|
129
|
-
$: mcp_server_url = `${root}gradio_api/mcp/sse`;
|
|
130
130
|
$: mcp_server_url_streamable =
|
|
131
131
|
selected_tools_array.length > 0 &&
|
|
132
132
|
selected_tools_array.length < tools.length
|
|
133
133
|
? `${root}gradio_api/mcp/?tools=${selected_tools_without_prefix.join(",")}`
|
|
134
134
|
: `${root}gradio_api/mcp/`;
|
|
135
135
|
|
|
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
136
|
interface ToolParameter {
|
|
149
137
|
title?: string;
|
|
150
138
|
type: string;
|
|
@@ -167,7 +155,6 @@
|
|
|
167
155
|
|
|
168
156
|
let tools: Tool[] = [];
|
|
169
157
|
let headers: string[] = [];
|
|
170
|
-
let mcp_json_sse: any;
|
|
171
158
|
let mcp_json_stdio: any;
|
|
172
159
|
let file_data_present = false;
|
|
173
160
|
let selected_tools: Set<string> = new Set();
|
|
@@ -212,29 +199,15 @@
|
|
|
212
199
|
selected_tools = new Set(tools.map((tool) => tool.name));
|
|
213
200
|
headers = schema.map((tool: any) => tool.meta?.headers || []).flat();
|
|
214
201
|
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
202
|
mcp_json_stdio = {
|
|
230
203
|
mcpServers: {
|
|
231
204
|
gradio: {
|
|
232
205
|
command: "npx",
|
|
233
206
|
args: [
|
|
234
207
|
"mcp-remote",
|
|
235
|
-
|
|
208
|
+
mcp_server_url_streamable,
|
|
236
209
|
"--transport",
|
|
237
|
-
"
|
|
210
|
+
"streamable-http",
|
|
238
211
|
...headers
|
|
239
212
|
.map((header) => [
|
|
240
213
|
"--header",
|
|
@@ -246,24 +219,20 @@
|
|
|
246
219
|
}
|
|
247
220
|
};
|
|
248
221
|
} else {
|
|
249
|
-
mcp_json_sse = {
|
|
250
|
-
mcpServers: {
|
|
251
|
-
gradio: {
|
|
252
|
-
url: mcp_server_url
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
222
|
mcp_json_stdio = {
|
|
257
223
|
mcpServers: {
|
|
258
224
|
gradio: {
|
|
259
225
|
command: "npx",
|
|
260
|
-
args: [
|
|
226
|
+
args: [
|
|
227
|
+
"mcp-remote",
|
|
228
|
+
mcp_server_url_streamable,
|
|
229
|
+
"--transport",
|
|
230
|
+
"streamable-http"
|
|
231
|
+
]
|
|
261
232
|
}
|
|
262
233
|
}
|
|
263
234
|
};
|
|
264
235
|
if (file_data_present) {
|
|
265
|
-
mcp_json_sse.mcpServers.upload_files_to_gradio =
|
|
266
|
-
upload_file_mcp_server;
|
|
267
236
|
mcp_json_stdio.mcpServers.upload_files_to_gradio =
|
|
268
237
|
upload_file_mcp_server;
|
|
269
238
|
}
|
|
@@ -274,6 +243,14 @@
|
|
|
274
243
|
}
|
|
275
244
|
}
|
|
276
245
|
|
|
246
|
+
let markdown_code_snippets: Record<string, Record<string, string>> = {};
|
|
247
|
+
|
|
248
|
+
$: markdown_code_snippets;
|
|
249
|
+
|
|
250
|
+
let config_snippets: Record<string, string> = {};
|
|
251
|
+
|
|
252
|
+
$: config_snippets;
|
|
253
|
+
|
|
277
254
|
onMount(() => {
|
|
278
255
|
const controller = new AbortController();
|
|
279
256
|
const signal = controller.signal;
|
|
@@ -288,8 +265,8 @@
|
|
|
288
265
|
current_language = lang_param as "python" | "javascript" | "bash" | "mcp";
|
|
289
266
|
}
|
|
290
267
|
|
|
291
|
-
|
|
292
|
-
fetch(
|
|
268
|
+
const mcp_schema_url = `${root}gradio_api/mcp/schema`;
|
|
269
|
+
fetch(mcp_schema_url, { signal: signal })
|
|
293
270
|
.then((response) => {
|
|
294
271
|
mcp_server_active = response.ok;
|
|
295
272
|
if (mcp_server_active) {
|
|
@@ -326,10 +303,32 @@
|
|
|
326
303
|
</div>
|
|
327
304
|
|
|
328
305
|
<div class="docs-wrap">
|
|
329
|
-
<div
|
|
306
|
+
<div
|
|
307
|
+
class="client-doc"
|
|
308
|
+
style="display: flex; align-items: center; justify-content: space-between;"
|
|
309
|
+
>
|
|
330
310
|
<p style="font-size: var(--text-lg);">
|
|
331
311
|
Choose one of the following ways to interact with the API.
|
|
332
312
|
</p>
|
|
313
|
+
<CopyMarkdown
|
|
314
|
+
{current_language}
|
|
315
|
+
{space_id}
|
|
316
|
+
{root}
|
|
317
|
+
{api_count}
|
|
318
|
+
{tools}
|
|
319
|
+
{py_docs}
|
|
320
|
+
{js_docs}
|
|
321
|
+
{bash_docs}
|
|
322
|
+
{mcp_docs}
|
|
323
|
+
{spaces_docs_suffix}
|
|
324
|
+
{mcp_server_active}
|
|
325
|
+
{mcp_server_url_streamable}
|
|
326
|
+
{config_snippets}
|
|
327
|
+
{markdown_code_snippets}
|
|
328
|
+
{dependencies}
|
|
329
|
+
{info}
|
|
330
|
+
{js_info}
|
|
331
|
+
/>
|
|
333
332
|
</div>
|
|
334
333
|
<div class="endpoint">
|
|
335
334
|
<div class="snippets">
|
|
@@ -392,25 +391,26 @@
|
|
|
392
391
|
href={current_language == "python" ? py_docs : js_docs}
|
|
393
392
|
target="_blank">docs</a
|
|
394
393
|
>) 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}
|
|
394
|
+
{:else if current_language == "bash"}
|
|
410
395
|
1. Confirm that you have cURL installed on your system.
|
|
411
396
|
{/if}
|
|
412
397
|
</p>
|
|
413
398
|
|
|
399
|
+
<div class:hidden={current_language !== "mcp"}>
|
|
400
|
+
<MCPSnippet
|
|
401
|
+
{mcp_server_active}
|
|
402
|
+
{mcp_server_url_streamable}
|
|
403
|
+
tools={tools.filter((tool) => selected_tools.has(tool.name))}
|
|
404
|
+
all_tools={tools}
|
|
405
|
+
bind:selected_tools
|
|
406
|
+
{mcp_json_stdio}
|
|
407
|
+
{file_data_present}
|
|
408
|
+
{mcp_docs}
|
|
409
|
+
{analytics}
|
|
410
|
+
bind:config_snippets
|
|
411
|
+
/>
|
|
412
|
+
</div>
|
|
413
|
+
|
|
414
414
|
{#if current_language !== "mcp"}
|
|
415
415
|
<InstallSnippet {current_language} />
|
|
416
416
|
|
|
@@ -464,9 +464,9 @@
|
|
|
464
464
|
{/if}
|
|
465
465
|
{/if}
|
|
466
466
|
|
|
467
|
-
{
|
|
467
|
+
<div class:hidden={current_language === "mcp"}>
|
|
468
468
|
{#each dependencies as dependency}
|
|
469
|
-
{#if dependency.
|
|
469
|
+
{#if dependency.api_visibility === "public" && info.named_endpoints["/" + dependency.api_name]}
|
|
470
470
|
<div class="endpoint-container">
|
|
471
471
|
<CodeSnippet
|
|
472
472
|
endpoint_parameters={info.named_endpoints[
|
|
@@ -482,6 +482,7 @@
|
|
|
482
482
|
"/" + dependency.api_name
|
|
483
483
|
].description}
|
|
484
484
|
{analytics}
|
|
485
|
+
bind:markdown_code_snippets
|
|
485
486
|
/>
|
|
486
487
|
|
|
487
488
|
<ParametersSnippet
|
|
@@ -506,7 +507,7 @@
|
|
|
506
507
|
</div>
|
|
507
508
|
{/if}
|
|
508
509
|
{/each}
|
|
509
|
-
|
|
510
|
+
</div>
|
|
510
511
|
</div>
|
|
511
512
|
</div>
|
|
512
513
|
{:else}
|
|
@@ -701,4 +702,8 @@
|
|
|
701
702
|
.api-name {
|
|
702
703
|
color: var(--color-accent);
|
|
703
704
|
}
|
|
705
|
+
|
|
706
|
+
.hidden {
|
|
707
|
+
display: none;
|
|
708
|
+
}
|
|
704
709
|
</style>
|
|
@@ -20,9 +20,10 @@
|
|
|
20
20
|
export let space_id: string | null;
|
|
21
21
|
export let endpoint_parameters: any;
|
|
22
22
|
export let username: string | null;
|
|
23
|
-
export let current_language: "python" | "javascript" | "bash";
|
|
23
|
+
export let current_language: "python" | "javascript" | "bash" | "mcp";
|
|
24
24
|
export let api_description: string | null = null;
|
|
25
25
|
export let analytics: Record<string, any>;
|
|
26
|
+
export let markdown_code_snippets: Record<string, Record<string, string>>;
|
|
26
27
|
|
|
27
28
|
let python_code: HTMLElement;
|
|
28
29
|
let js_code: HTMLElement;
|
|
@@ -39,6 +40,14 @@
|
|
|
39
40
|
|
|
40
41
|
$: normalised_api_prefix = api_prefix ? api_prefix : "/";
|
|
41
42
|
$: normalised_root = root.replace(/\/$/, "");
|
|
43
|
+
|
|
44
|
+
$: markdown_code_snippets[
|
|
45
|
+
dependency.api_name as keyof typeof markdown_code_snippets
|
|
46
|
+
] = {
|
|
47
|
+
python: python_code?.innerText || "",
|
|
48
|
+
javascript: js_code?.innerText || "",
|
|
49
|
+
bash: bash_post_code?.innerText || ""
|
|
50
|
+
};
|
|
42
51
|
</script>
|
|
43
52
|
|
|
44
53
|
<div class="container">
|
|
@@ -47,7 +56,7 @@
|
|
|
47
56
|
description={api_description}
|
|
48
57
|
{analytics}
|
|
49
58
|
/>
|
|
50
|
-
{
|
|
59
|
+
<div class:hidden={current_language !== "python"}>
|
|
51
60
|
<Block>
|
|
52
61
|
<code>
|
|
53
62
|
<div class="copy">
|
|
@@ -82,7 +91,8 @@ result = client.<span class="highlight">predict</span
|
|
|
82
91
|
</div>
|
|
83
92
|
</code>
|
|
84
93
|
</Block>
|
|
85
|
-
|
|
94
|
+
</div>
|
|
95
|
+
<div class:hidden={current_language !== "javascript"}>
|
|
86
96
|
<Block>
|
|
87
97
|
<code>
|
|
88
98
|
<div class="copy">
|
|
@@ -131,7 +141,8 @@ result = client.<span class="highlight">predict</span
|
|
|
131
141
|
</div>
|
|
132
142
|
</code>
|
|
133
143
|
</Block>
|
|
134
|
-
|
|
144
|
+
</div>
|
|
145
|
+
<div class:hidden={current_language !== "bash"}>
|
|
135
146
|
<Block>
|
|
136
147
|
<code>
|
|
137
148
|
<div class="copy">
|
|
@@ -155,7 +166,7 @@ result = client.<span class="highlight">predict</span
|
|
|
155
166
|
</div>
|
|
156
167
|
</code>
|
|
157
168
|
</Block>
|
|
158
|
-
|
|
169
|
+
</div>
|
|
159
170
|
</div>
|
|
160
171
|
|
|
161
172
|
<style>
|
|
@@ -199,4 +210,8 @@ result = client.<span class="highlight">predict</span
|
|
|
199
210
|
.api-name {
|
|
200
211
|
color: var(--color-accent);
|
|
201
212
|
}
|
|
213
|
+
|
|
214
|
+
.hidden {
|
|
215
|
+
display: none;
|
|
216
|
+
}
|
|
202
217
|
</style>
|