@gradio/core 0.27.0 → 0.27.2

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 (42) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/src/Blocks.svelte +12 -21
  3. package/dist/src/Blocks.svelte.d.ts +11 -9
  4. package/dist/src/Embed.svelte.d.ts +4 -2
  5. package/dist/src/Login.svelte.d.ts +2 -0
  6. package/dist/src/MountComponents.svelte.d.ts +3 -1
  7. package/dist/src/Render.svelte +12 -13
  8. package/dist/src/Render.svelte.d.ts +3 -1
  9. package/dist/src/RenderComponent.svelte +3 -6
  10. package/dist/src/RenderComponent.svelte.d.ts +2 -0
  11. package/dist/src/api_docs/ApiBanner.svelte.d.ts +3 -1
  12. package/dist/src/api_docs/ApiDocs.svelte +28 -18
  13. package/dist/src/api_docs/ApiDocs.svelte.d.ts +3 -1
  14. package/dist/src/api_docs/ApiRecorder.svelte.d.ts +3 -1
  15. package/dist/src/api_docs/CodeSnippet.svelte +40 -40
  16. package/dist/src/api_docs/CodeSnippet.svelte.d.ts +4 -1
  17. package/dist/src/api_docs/CopyButton.svelte.d.ts +2 -0
  18. package/dist/src/api_docs/EndpointDetail.svelte +23 -1
  19. package/dist/src/api_docs/EndpointDetail.svelte.d.ts +5 -2
  20. package/dist/src/api_docs/InputPayload.svelte.d.ts +2 -0
  21. package/dist/src/api_docs/InstallSnippet.svelte.d.ts +2 -0
  22. package/dist/src/api_docs/MCPSnippet.svelte +89 -44
  23. package/dist/src/api_docs/MCPSnippet.svelte.d.ts +7 -2
  24. package/dist/src/api_docs/NoApi.svelte.d.ts +2 -0
  25. package/dist/src/api_docs/ParametersSnippet.svelte.d.ts +2 -0
  26. package/dist/src/api_docs/RecordingSnippet.svelte.d.ts +4 -2
  27. package/dist/src/api_docs/ResponseSnippet.svelte.d.ts +2 -0
  28. package/dist/src/api_docs/Settings.svelte.d.ts +4 -2
  29. package/dist/src/api_docs/SettingsBanner.svelte.d.ts +2 -0
  30. package/dist/src/api_docs/TryButton.svelte.d.ts +2 -0
  31. package/dist/src/api_docs/img/clear.svelte.d.ts +2 -0
  32. package/dist/src/api_docs/utils.d.ts +2 -0
  33. package/dist/src/api_docs/utils.js +14 -0
  34. package/dist/src/stories/I18nMultiLanguageTestComponent.svelte.d.ts +3 -3
  35. package/dist/src/stories/I18nTestSetup.svelte +1 -2
  36. package/dist/src/stories/I18nTestSetup.svelte.d.ts +3 -1
  37. package/package.json +31 -31
  38. package/src/api_docs/ApiDocs.svelte +24 -3
  39. package/src/api_docs/CodeSnippet.svelte +38 -36
  40. package/src/api_docs/EndpointDetail.svelte +24 -1
  41. package/src/api_docs/MCPSnippet.svelte +68 -17
  42. package/src/api_docs/utils.ts +14 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @gradio/core
2
2
 
3
+ ## 0.27.2
4
+
5
+ ### Features
6
+
7
+ - [#11764](https://github.com/gradio-app/gradio/pull/11764) [`e6ce731`](https://github.com/gradio-app/gradio/commit/e6ce731bbcf2889c8147e57bc2ca97e2c731ddf5) - Display performance metrics for API/MCP requests in View API page. Thanks @freddyaboulton!
8
+
9
+ ### Dependency updates
10
+
11
+ - @gradio/statustracker@0.10.18
12
+
13
+ ## 0.27.1
14
+
15
+ ### Features
16
+
17
+ - [#11767](https://github.com/gradio-app/gradio/pull/11767) [`f67faa4`](https://github.com/gradio-app/gradio/commit/f67faa464add0ef6a4a58d60eb2ae850125ebb87) - Use icons instead of Emojis in MCP page. Thanks @freddyaboulton!
18
+
19
+ ### Dependency updates
20
+
21
+ - @gradio/icons@0.13.1
22
+ - @gradio/upload@0.16.16
23
+
3
24
  ## 0.27.0
4
25
 
5
26
  ### Features
@@ -53,17 +53,15 @@ let {
53
53
  } = create_components({
54
54
  initial_layout
55
55
  });
56
- $:
57
- components, layout, dependencies, root, app, fill_height, target, run();
56
+ $: components, layout, dependencies, root, app, fill_height, target, run();
58
57
  $: {
59
58
  ready = !!$_layout;
60
59
  }
61
60
  let old_dependencies = dependencies;
62
- $:
63
- if (dependencies !== old_dependencies && render_complete && !layout_creating) {
64
- handle_load_triggers();
65
- old_dependencies = dependencies;
66
- }
61
+ $: if (dependencies !== old_dependencies && render_complete && !layout_creating) {
62
+ handle_load_triggers();
63
+ old_dependencies = dependencies;
64
+ }
67
65
  let vibe_editor_width = 350;
68
66
  async function run() {
69
67
  await setupi18n(app.config?.i18n_translations || void 0);
@@ -94,10 +92,8 @@ async function loadApiDocs() {
94
92
  if (!ApiDocs || !ApiRecorder) {
95
93
  const api_docs_module = await import("./api_docs/ApiDocs.svelte");
96
94
  const api_recorder_module = await import("./api_docs/ApiRecorder.svelte");
97
- if (!ApiDocs)
98
- ApiDocs = api_docs_module.default;
99
- if (!ApiRecorder)
100
- ApiRecorder = api_recorder_module.default;
95
+ if (!ApiDocs) ApiDocs = api_docs_module.default;
96
+ if (!ApiRecorder) ApiRecorder = api_recorder_module.default;
101
97
  }
102
98
  }
103
99
  async function loadApiRecorder() {
@@ -405,8 +401,7 @@ async function trigger_api_call(dep_index, trigger_id = null, event_data = null)
405
401
  );
406
402
  } catch (e) {
407
403
  const fn_index = 0;
408
- if (app.closed)
409
- return;
404
+ if (app.closed) return;
410
405
  messages = [
411
406
  new_message("Error", String(e), fn_index, "error"),
412
407
  ...messages
@@ -637,11 +632,9 @@ async function handle_mount() {
637
632
  a[i].setAttribute("target", "_blank");
638
633
  }
639
634
  handle_load_triggers();
640
- if (!target || render_complete)
641
- return;
635
+ if (!target || render_complete) return;
642
636
  target.addEventListener("prop_change", (e) => {
643
- if (!isCustomEvent(e))
644
- throw new Error("not a custom event");
637
+ if (!isCustomEvent(e)) throw new Error("not a custom event");
645
638
  const { id, prop, value } = e.detail;
646
639
  update_value([{ id, prop, value }]);
647
640
  if (prop === "input_ready" && value === false) {
@@ -652,8 +645,7 @@ async function handle_mount() {
652
645
  }
653
646
  });
654
647
  target.addEventListener("gradio", (e) => {
655
- if (!isCustomEvent(e))
656
- throw new Error("not a custom event");
648
+ if (!isCustomEvent(e)) throw new Error("not a custom event");
657
649
  const { id, event, data } = e.detail;
658
650
  if (event === "share") {
659
651
  const { title: title2, description } = data;
@@ -701,8 +693,7 @@ const handle_load_triggers = () => {
701
693
  }
702
694
  });
703
695
  };
704
- $:
705
- set_status($loading_status);
696
+ $: set_status($loading_status);
706
697
  function update_status(id, status, data) {
707
698
  data.status = status;
708
699
  update_value([
@@ -9,34 +9,36 @@ declare const __propDef: {
9
9
  components: ComponentMeta[];
10
10
  layout: LayoutNode;
11
11
  dependencies: Dependency[];
12
- title?: string | undefined;
12
+ title?: string;
13
13
  target: HTMLElement;
14
14
  autoscroll: boolean;
15
- show_api?: boolean | undefined;
16
- show_footer?: boolean | undefined;
17
- control_page_title?: boolean | undefined;
15
+ show_api?: boolean;
16
+ show_footer?: boolean;
17
+ control_page_title?: boolean;
18
18
  app_mode: boolean;
19
19
  theme_mode: ThemeMode;
20
20
  app: Awaited<ReturnType<typeof Client.connect>>;
21
21
  space_id: string | null;
22
22
  version: string;
23
23
  js: string | null;
24
- fill_height?: boolean | undefined;
24
+ fill_height?: boolean;
25
25
  ready: boolean;
26
26
  username: string | null;
27
- api_prefix?: string | undefined;
27
+ api_prefix?: string;
28
28
  max_file_size?: number | undefined;
29
29
  initial_layout?: ComponentMeta | undefined;
30
30
  css?: string | null | undefined;
31
- vibe_mode?: boolean | undefined;
31
+ vibe_mode?: boolean;
32
32
  search_params: URLSearchParams;
33
- render_complete?: boolean | undefined;
34
- add_new_message?: ((title: string, message: string, type: ToastMessage["type"]) => void) | undefined;
33
+ render_complete?: boolean;
34
+ add_new_message?: (title: string, message: string, type: ToastMessage["type"]) => void;
35
35
  };
36
36
  events: {
37
37
  [evt: string]: CustomEvent<any>;
38
38
  };
39
39
  slots: {};
40
+ exports?: {} | undefined;
41
+ bindings?: string | undefined;
40
42
  };
41
43
  export type BlocksProps = typeof __propDef.props;
42
44
  export type BlocksEvents = typeof __propDef.events;
@@ -11,8 +11,8 @@ declare const __propDef: {
11
11
  display: boolean;
12
12
  info: boolean;
13
13
  loaded: boolean;
14
- pages?: [string, string][] | undefined;
15
- current_page?: string | undefined;
14
+ pages?: [string, string][];
15
+ current_page?: string;
16
16
  root: string;
17
17
  };
18
18
  events: {
@@ -21,6 +21,8 @@ declare const __propDef: {
21
21
  slots: {
22
22
  default: {};
23
23
  };
24
+ exports?: {} | undefined;
25
+ bindings?: string | undefined;
24
26
  };
25
27
  export type EmbedProps = typeof __propDef.props;
26
28
  export type EmbedEvents = typeof __propDef.events;
@@ -10,6 +10,8 @@ declare const __propDef: {
10
10
  [evt: string]: CustomEvent<any>;
11
11
  };
12
12
  slots: {};
13
+ exports?: {} | undefined;
14
+ bindings?: string | undefined;
13
15
  };
14
16
  export type LoginProps = typeof __propDef.props;
15
17
  export type LoginEvents = typeof __propDef.events;
@@ -8,7 +8,7 @@ declare const __propDef: {
8
8
  theme_mode: any;
9
9
  version: any;
10
10
  autoscroll: boolean;
11
- max_file_size?: (number | null) | undefined;
11
+ max_file_size?: number | null;
12
12
  client: Client;
13
13
  };
14
14
  events: {
@@ -17,6 +17,8 @@ declare const __propDef: {
17
17
  [evt: string]: CustomEvent<any>;
18
18
  };
19
19
  slots: {};
20
+ exports?: {} | undefined;
21
+ bindings?: string | undefined;
20
22
  };
21
23
  export type MountComponentsProps = typeof __propDef.props;
22
24
  export type MountComponentsEvents = typeof __propDef.events;
@@ -48,19 +48,18 @@ $: {
48
48
  }
49
49
  }
50
50
  }
51
- $:
52
- node.props.gradio = new Gradio(
53
- node.id,
54
- target,
55
- theme_mode,
56
- version,
57
- root,
58
- autoscroll,
59
- max_file_size,
60
- $reactive_formatter,
61
- client,
62
- load_component
63
- );
51
+ $: node.props.gradio = new Gradio(
52
+ node.id,
53
+ target,
54
+ theme_mode,
55
+ version,
56
+ root,
57
+ autoscroll,
58
+ max_file_size,
59
+ $reactive_formatter,
60
+ client,
61
+ load_component
62
+ );
64
63
  </script>
65
64
 
66
65
  {#if node.component}
@@ -5,7 +5,7 @@ declare const __propDef: {
5
5
  props: {
6
6
  root: string;
7
7
  node: ComponentMeta;
8
- parent?: (string | null) | undefined;
8
+ parent?: string | null;
9
9
  target: HTMLElement;
10
10
  theme_mode: ThemeMode;
11
11
  version: string;
@@ -20,6 +20,8 @@ declare const __propDef: {
20
20
  [evt: string]: CustomEvent<any>;
21
21
  };
22
22
  slots: {};
23
+ exports?: {} | undefined;
24
+ bindings?: string | undefined;
23
25
  };
24
26
  export type RenderProps = typeof __propDef.props;
25
27
  export type RenderEvents = typeof __propDef.events;
@@ -20,8 +20,7 @@ function wrap(component2) {
20
20
  const props = Object.keys(instance2.$$.props);
21
21
  function report(props2) {
22
22
  return function(propargs) {
23
- if (!target)
24
- return;
23
+ if (!target) return;
25
24
  const ev = s(_id, props2, propargs);
26
25
  target.dispatchEvent(ev);
27
26
  };
@@ -50,10 +49,8 @@ function translate_prop(obj) {
50
49
  }
51
50
  }
52
51
  }
53
- $:
54
- translate_prop($$restProps);
55
- $:
56
- value = translate_if_needed(value);
52
+ $: translate_prop($$restProps);
53
+ $: value = translate_if_needed(value);
57
54
  </script>
58
55
 
59
56
  {#if visible}
@@ -22,6 +22,8 @@ declare const __propDef: {
22
22
  slots: {
23
23
  default: {};
24
24
  };
25
+ exports?: undefined;
26
+ bindings?: undefined;
25
27
  };
26
28
  export type RenderComponentProps = typeof __propDef.props;
27
29
  export type RenderComponentEvents = typeof __propDef.events;
@@ -3,7 +3,7 @@ declare const __propDef: {
3
3
  props: {
4
4
  root: string;
5
5
  api_count: number;
6
- current_language?: ("python" | "javascript" | "bash" | "mcp") | undefined;
6
+ current_language?: "python" | "javascript" | "bash" | "mcp";
7
7
  };
8
8
  events: {
9
9
  close: CustomEvent<any>;
@@ -11,6 +11,8 @@ declare const __propDef: {
11
11
  [evt: string]: CustomEvent<any>;
12
12
  };
13
13
  slots: {};
14
+ exports?: {} | undefined;
15
+ bindings?: string | undefined;
14
16
  };
15
17
  export type ApiBannerProps = typeof __propDef.props;
16
18
  export type ApiBannerEvents = typeof __propDef.events;
@@ -69,29 +69,33 @@ async function get_js_info() {
69
69
  }
70
70
  let info;
71
71
  let js_info;
72
+ let analytics;
72
73
  get_info().then((data) => {
73
74
  info = data;
74
75
  });
75
76
  get_js_info().then((js_api_info) => {
76
77
  js_info = js_api_info;
77
78
  });
79
+ async function get_summary() {
80
+ let response = await fetch(root.replace(/\/$/, "") + "/monitoring/summary");
81
+ let data = await response.json();
82
+ return data;
83
+ }
84
+ get_summary().then((summary) => {
85
+ analytics = summary.functions;
86
+ });
78
87
  const dispatch = createEventDispatcher();
79
- $:
80
- selected_tools_array = Array.from(selected_tools);
81
- $:
82
- selected_tools_without_prefix = selected_tools_array.map(remove_tool_prefix);
83
- $:
84
- mcp_server_url = `${root}gradio_api/mcp/sse`;
85
- $:
86
- mcp_server_url_streamable = selected_tools_array.length > 0 && selected_tools_array.length < tools.length ? `${root}gradio_api/mcp/?tools=${selected_tools_without_prefix.join(",")}` : `${root}gradio_api/mcp/`;
87
- $:
88
- if (mcp_json_sse && selected_tools.size > 0) {
89
- const baseUrl = selected_tools_array.length > 0 && selected_tools_array.length < tools.length ? `${root}gradio_api/mcp/sse?tools=${selected_tools_without_prefix.join(",")}` : `${root}gradio_api/mcp/sse`;
90
- mcp_json_sse.mcpServers.gradio.url = baseUrl;
91
- if (mcp_json_stdio) {
92
- mcp_json_stdio.mcpServers.gradio.args[1] = baseUrl;
93
- }
88
+ $: selected_tools_array = Array.from(selected_tools);
89
+ $: selected_tools_without_prefix = selected_tools_array.map(remove_tool_prefix);
90
+ $: mcp_server_url = `${root}gradio_api/mcp/sse`;
91
+ $: mcp_server_url_streamable = selected_tools_array.length > 0 && selected_tools_array.length < tools.length ? `${root}gradio_api/mcp/?tools=${selected_tools_without_prefix.join(",")}` : `${root}gradio_api/mcp/`;
92
+ $: if (mcp_json_sse && selected_tools.size > 0) {
93
+ const baseUrl = selected_tools_array.length > 0 && selected_tools_array.length < tools.length ? `${root}gradio_api/mcp/sse?tools=${selected_tools_without_prefix.join(",")}` : `${root}gradio_api/mcp/sse`;
94
+ mcp_json_sse.mcpServers.gradio.url = baseUrl;
95
+ if (mcp_json_stdio) {
96
+ mcp_json_stdio.mcpServers.gradio.args[1] = baseUrl;
94
97
  }
98
+ }
95
99
  let tools = [];
96
100
  let headers = [];
97
101
  let mcp_json_sse;
@@ -127,7 +131,8 @@ async function fetch_mcp_tools() {
127
131
  description: tool.description || "",
128
132
  parameters: tool.inputSchema?.properties || {},
129
133
  meta: tool.meta,
130
- expanded: false
134
+ expanded: false,
135
+ endpoint_name: tool.endpoint_name
131
136
  }));
132
137
  selected_tools = new Set(tools.map((tool) => tool.name));
133
138
  headers = schema.map((tool) => tool.meta?.headers || []).flat();
@@ -190,6 +195,8 @@ async function fetch_mcp_tools() {
190
195
  }
191
196
  }
192
197
  onMount(() => {
198
+ const controller = new AbortController();
199
+ const signal = controller.signal;
193
200
  document.body.style.overflow = "hidden";
194
201
  if ("parentIFrame" in window) {
195
202
  window.parentIFrame?.scrollTo(0, 0);
@@ -198,7 +205,7 @@ onMount(() => {
198
205
  if (is_valid_language(lang_param)) {
199
206
  current_language = lang_param;
200
207
  }
201
- fetch(mcp_server_url).then((response) => {
208
+ fetch(mcp_server_url, { signal }).then((response) => {
202
209
  mcp_server_active = response.ok;
203
210
  if (mcp_server_active) {
204
211
  fetch_mcp_tools();
@@ -210,6 +217,7 @@ onMount(() => {
210
217
  current_language = "python";
211
218
  }
212
219
  }
220
+ controller.abort();
213
221
  }).catch(() => {
214
222
  mcp_server_active = false;
215
223
  });
@@ -219,7 +227,7 @@ onMount(() => {
219
227
  });
220
228
  </script>
221
229
 
222
- {#if info}
230
+ {#if info && analytics}
223
231
  {#if api_count}
224
232
  <div class="banner-wrap">
225
233
  <ApiBanner
@@ -309,6 +317,7 @@ onMount(() => {
309
317
  {mcp_json_stdio}
310
318
  {file_data_present}
311
319
  {mcp_docs}
320
+ {analytics}
312
321
  />
313
322
  {:else}
314
323
  1. Confirm that you have cURL installed on your system.
@@ -385,6 +394,7 @@ onMount(() => {
385
394
  api_description={info.named_endpoints[
386
395
  "/" + dependency.api_name
387
396
  ].description}
397
+ {analytics}
388
398
  />
389
399
 
390
400
  <ParametersSnippet
@@ -10,7 +10,7 @@ declare const __propDef: {
10
10
  space_id: string | null;
11
11
  root_node: ComponentMeta;
12
12
  username: string | null;
13
- api_calls?: Payload[] | undefined;
13
+ api_calls?: Payload[];
14
14
  };
15
15
  events: {
16
16
  close: CustomEvent<any>;
@@ -18,6 +18,8 @@ declare const __propDef: {
18
18
  [evt: string]: CustomEvent<any>;
19
19
  };
20
20
  slots: {};
21
+ exports?: {} | undefined;
22
+ bindings?: string | undefined;
21
23
  };
22
24
  export type ApiDocsProps = typeof __propDef.props;
23
25
  export type ApiDocsEvents = typeof __propDef.events;
@@ -2,13 +2,15 @@ import { SvelteComponent } from "svelte";
2
2
  import type { Payload, Dependency } from "../types";
3
3
  declare const __propDef: {
4
4
  props: {
5
- api_calls?: Payload[] | undefined;
5
+ api_calls?: Payload[];
6
6
  dependencies: Dependency[];
7
7
  };
8
8
  events: {
9
9
  [evt: string]: CustomEvent<any>;
10
10
  };
11
11
  slots: {};
12
+ exports?: {} | undefined;
13
+ bindings?: string | undefined;
12
14
  };
13
15
  export type ApiRecorderProps = typeof __propDef.props;
14
16
  export type ApiRecorderEvents = typeof __propDef.events;
@@ -10,6 +10,7 @@ export let endpoint_parameters;
10
10
  export let username;
11
11
  export let current_language;
12
12
  export let api_description = null;
13
+ export let analytics;
13
14
  let python_code;
14
15
  let js_code;
15
16
  let bash_post_code;
@@ -21,16 +22,15 @@ let blob_components = ["Audio", "File", "Image", "Video"];
21
22
  let blob_examples = endpoint_parameters.filter(
22
23
  (param) => blob_components.includes(param.component)
23
24
  );
24
- $:
25
- normalised_api_prefix = api_prefix ? api_prefix : "/";
26
- $:
27
- normalised_root = root.replace(/\/$/, "");
25
+ $: normalised_api_prefix = api_prefix ? api_prefix : "/";
26
+ $: normalised_root = root.replace(/\/$/, "");
28
27
  </script>
29
28
 
30
29
  <div class="container">
31
30
  <EndpointDetail
32
31
  api_name={dependency.api_name}
33
32
  description={api_description}
33
+ {analytics}
34
34
  />
35
35
  {#if current_language === "python"}
36
36
  <Block>
@@ -43,13 +43,13 @@ $:
43
43
  class="highlight">import</span
44
44
  > Client{#if has_file_path}, handle_file{/if}
45
45
 
46
- client = Client(<span class="token string">"{space_id || root}"</span
46
+ client = Client(<span class="token string">"{space_id || root}"</span
47
47
  >{#if username !== null}, auth=("{username}", **password**){/if})
48
- result = client.<span class="highlight">predict</span
48
+ result = client.<span class="highlight">predict</span
49
49
  >(<!--
50
- -->{#each endpoint_parameters as { python_type, example_input, parameter_name, parameter_has_default, parameter_default }, i}<!--
51
- -->
52
- {parameter_name
50
+ -->{#each endpoint_parameters as { python_type, example_input, parameter_name, parameter_has_default, parameter_default }, i}<!--
51
+ -->
52
+ {parameter_name
53
53
  ? parameter_name + "="
54
54
  : ""}<span
55
55
  >{represent_value(
@@ -59,11 +59,11 @@ result = client.<span class="highlight">predict</span
59
59
  )}</span
60
60
  >,{/each}<!--
61
61
 
62
- -->
63
- api_name=<span class="api-name">"/{dependency.api_name}"</span><!--
64
- -->
65
- )
66
- <span class="highlight">print</span>(result)</pre>
62
+ -->
63
+ api_name=<span class="api-name">"/{dependency.api_name}"</span><!--
64
+ -->
65
+ )
66
+ <span class="highlight">print</span>(result)</pre>
67
67
  </div>
68
68
  </code>
69
69
  </Block>
@@ -75,44 +75,44 @@ result = client.<span class="highlight">predict</span
75
75
  </div>
76
76
  <div bind:this={js_code}>
77
77
  <pre>import &lbrace; Client &rbrace; from "@gradio/client";
78
- {#each blob_examples as { component, example_input }, i}<!--
79
- -->
80
- const response_{i} = await fetch("{example_input.url}");
81
- const example{component} = await response_{i}.blob();
78
+ {#each blob_examples as { component, example_input }, i}<!--
79
+ -->
80
+ const response_{i} = await fetch("{example_input.url}");
81
+ const example{component} = await response_{i}.blob();
82
82
  {/each}<!--
83
- -->
84
- const client = await Client.connect(<span class="token string"
83
+ -->
84
+ const client = await Client.connect(<span class="token string"
85
85
  >"{space_id || root}"</span
86
86
  >{#if username !== null}, &lbrace;auth: ["{username}", **password**]&rbrace;{/if});
87
- const result = await client.predict(<span class="api-name"
87
+ const result = await client.predict(<span class="api-name"
88
88
  >"/{dependency.api_name}"</span
89
89
  >, &lbrace; <!--
90
- -->{#each endpoint_parameters as { label, parameter_name, type, python_type, component, example_input, serializer }, i}<!--
91
- -->{#if blob_components.includes(component)}<!--
92
- -->
93
- <span
90
+ -->{#each endpoint_parameters as { label, parameter_name, type, python_type, component, example_input, serializer }, i}<!--
91
+ -->{#if blob_components.includes(component)}<!--
92
+ -->
93
+ <span
94
94
  class="example-inputs"
95
95
  >{parameter_name}: example{component}</span
96
96
  >, <!--
97
- --><span class="desc"><!--
98
- --></span
97
+ --><span class="desc"><!--
98
+ --></span
99
99
  ><!--
100
- -->{:else}<!--
101
- -->
102
- <span class="example-inputs"
100
+ -->{:else}<!--
101
+ -->
102
+ <span class="example-inputs"
103
103
  >{parameter_name}: {represent_value(
104
104
  example_input,
105
105
  python_type.type,
106
106
  "js"
107
107
  )}</span
108
108
  >, <!--
109
- --><!--
110
- -->{/if}
109
+ --><!--
110
+ -->{/if}
111
111
  {/each}
112
- &rbrace;);
112
+ &rbrace;);
113
113
 
114
- console.log(result.data);
115
- </pre>
114
+ console.log(result.data);
115
+ </pre>
116
116
  </div>
117
117
  </code>
118
118
  </Block>
@@ -125,18 +125,18 @@ console.log(result.data);
125
125
 
126
126
  <div bind:this={bash_post_code}>
127
127
  <pre>curl -X POST {normalised_root}{normalised_api_prefix}/call/{dependency.api_name} -s -H "Content-Type: application/json" -d '{"{"}
128
- "data": [{#each endpoint_parameters as { label, parameter_name, type, python_type, component, example_input, serializer }, i}
128
+ "data": [{#each endpoint_parameters as { label, parameter_name, type, python_type, component, example_input, serializer }, i}
129
129
  <!--
130
- -->{represent_value(
130
+ -->{represent_value(
131
131
  example_input,
132
132
  python_type.type,
133
133
  "bash"
134
134
  )}{#if i < endpoint_parameters.length - 1},
135
135
  {/if}
136
136
  {/each}
137
- ]{"}"}' \
138
- | awk -F'"' '{"{"} print $4{"}"}' \
139
- | read EVENT_ID; curl -N {normalised_root}{normalised_api_prefix}/call/{dependency.api_name}/$EVENT_ID</pre>
137
+ ]{"}"}' \
138
+ | awk -F'"' '{"{"} print $4{"}"}' \
139
+ | read EVENT_ID; curl -N {normalised_root}{normalised_api_prefix}/call/{dependency.api_name}/$EVENT_ID</pre>
140
140
  </div>
141
141
  </code>
142
142
  </Block>
@@ -9,12 +9,15 @@ declare const __propDef: {
9
9
  endpoint_parameters: any;
10
10
  username: string | null;
11
11
  current_language: "python" | "javascript" | "bash";
12
- api_description?: (string | null) | undefined;
12
+ api_description?: string | null;
13
+ analytics: Record<string, any>;
13
14
  };
14
15
  events: {
15
16
  [evt: string]: CustomEvent<any>;
16
17
  };
17
18
  slots: {};
19
+ exports?: {} | undefined;
20
+ bindings?: string | undefined;
18
21
  };
19
22
  export type CodeSnippetProps = typeof __propDef.props;
20
23
  export type CodeSnippetEvents = typeof __propDef.events;
@@ -7,6 +7,8 @@ declare const __propDef: {
7
7
  [evt: string]: CustomEvent<any>;
8
8
  };
9
9
  slots: {};
10
+ exports?: {} | undefined;
11
+ bindings?: string | undefined;
10
12
  };
11
13
  export type CopyButtonProps = typeof __propDef.props;
12
14
  export type CopyButtonEvents = typeof __propDef.events;
@@ -1,11 +1,28 @@
1
1
  <script>export let api_name = null;
2
2
  export let description = null;
3
+ export let analytics;
4
+ import { format_latency, get_color_from_success_rate } from "./utils";
5
+ const success_rate = api_name ? analytics[api_name]?.success_rate : 0;
6
+ const color = get_color_from_success_rate(success_rate);
3
7
  </script>
4
8
 
5
9
  <h3>
6
10
  API name:
7
11
  <span class="post">{"/" + api_name}</span>
8
12
  <span class="desc">{description}</span>
13
+ {#if analytics && api_name && analytics[api_name]}
14
+ <span class="analytics">
15
+ Total requests: {analytics[api_name].total_requests} (<span style={color}
16
+ >{Math.round(success_rate * 100)}%</span
17
+ >
18
+ successful) &nbsp;|&nbsp; p50/p90/p99:
19
+ {format_latency(analytics[api_name].process_time_percentiles["50th"])}
20
+ /
21
+ {format_latency(analytics[api_name].process_time_percentiles["90th"])}
22
+ /
23
+ {format_latency(analytics[api_name].process_time_percentiles["99th"])}
24
+ </span>
25
+ {/if}
9
26
  </h3>
10
27
 
11
28
  <style>
@@ -27,8 +44,13 @@ export let description = null;
27
44
  font-weight: var(--weight-semibold);
28
45
  }
29
46
 
30
- .desc {
47
+ .analytics {
31
48
  color: var(--body-text-color-subdued);
49
+ margin-top: var(--size-1);
50
+ }
51
+
52
+ .desc {
53
+ color: var(--body-text-color);
32
54
  font-size: var(--text-lg);
33
55
  margin-top: var(--size-1);
34
56
  }