@djangocfg/ui-tools 2.1.334 → 2.1.336

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 (196) hide show
  1. package/README.md +68 -2
  2. package/dist/ChatRoot-IIYQEWUU.mjs +5 -0
  3. package/dist/ChatRoot-IIYQEWUU.mjs.map +1 -0
  4. package/dist/ChatRoot-PNNGQCYF.css +7 -0
  5. package/dist/ChatRoot-PNNGQCYF.css.map +1 -0
  6. package/dist/ChatRoot-UUKTYM4N.cjs +14 -0
  7. package/dist/ChatRoot-UUKTYM4N.cjs.map +1 -0
  8. package/dist/{CronScheduler.client-3O3VU4CI.mjs → CronScheduler.client-DLMXCPAJ.mjs} +4 -4
  9. package/dist/{CronScheduler.client-3O3VU4CI.mjs.map → CronScheduler.client-DLMXCPAJ.mjs.map} +1 -1
  10. package/dist/{CronScheduler.client-A4GO6YBY.cjs → CronScheduler.client-WEJF4PWQ.cjs} +14 -14
  11. package/dist/{CronScheduler.client-A4GO6YBY.cjs.map → CronScheduler.client-WEJF4PWQ.cjs.map} +1 -1
  12. package/dist/{DocsLayout-XLDB6CJ2.cjs → DocsLayout-N5ZJZPBY.cjs} +200 -199
  13. package/dist/DocsLayout-N5ZJZPBY.cjs.map +1 -0
  14. package/dist/{DocsLayout-CTJINVBM.mjs → DocsLayout-VFPPNKSQ.mjs} +7 -6
  15. package/dist/DocsLayout-VFPPNKSQ.mjs.map +1 -0
  16. package/dist/JsonSchemaForm-DD7CLRIG.cjs +13 -0
  17. package/dist/{JsonSchemaForm-OSPUUUHM.cjs.map → JsonSchemaForm-DD7CLRIG.cjs.map} +1 -1
  18. package/dist/JsonSchemaForm-XKUIVELK.mjs +4 -0
  19. package/dist/{JsonSchemaForm-TSLX2GRO.mjs.map → JsonSchemaForm-XKUIVELK.mjs.map} +1 -1
  20. package/dist/JsonTree-55625VVH.mjs +5 -0
  21. package/dist/{JsonTree-F27RMYSI.cjs.map → JsonTree-55625VVH.mjs.map} +1 -1
  22. package/dist/JsonTree-DCM5QGWF.cjs +11 -0
  23. package/dist/{JsonTree-QTJYSHCV.mjs.map → JsonTree-DCM5QGWF.cjs.map} +1 -1
  24. package/dist/{LottiePlayer.client-6WVWDO75.cjs → LottiePlayer.client-2S7ISJ2S.cjs} +6 -6
  25. package/dist/{LottiePlayer.client-6WVWDO75.cjs.map → LottiePlayer.client-2S7ISJ2S.cjs.map} +1 -1
  26. package/dist/{LottiePlayer.client-B4I6WNZM.mjs → LottiePlayer.client-5LDSSJWS.mjs} +4 -4
  27. package/dist/{LottiePlayer.client-B4I6WNZM.mjs.map → LottiePlayer.client-5LDSSJWS.mjs.map} +1 -1
  28. package/dist/{MapContainer-RYG4HPH4.cjs → MapContainer-76YL2JXL.cjs} +8 -8
  29. package/dist/{MapContainer-RYG4HPH4.cjs.map → MapContainer-76YL2JXL.cjs.map} +1 -1
  30. package/dist/{MapContainer-GXQLP5WY.mjs → MapContainer-7HXBI3OH.mjs} +3 -3
  31. package/dist/{MapContainer-GXQLP5WY.mjs.map → MapContainer-7HXBI3OH.mjs.map} +1 -1
  32. package/dist/{Mermaid.client-SXRRI2YW.mjs → Mermaid.client-NL4SVR7F.mjs} +4 -4
  33. package/dist/{Mermaid.client-SXRRI2YW.mjs.map → Mermaid.client-NL4SVR7F.mjs.map} +1 -1
  34. package/dist/{Mermaid.client-W76R5AKJ.cjs → Mermaid.client-NNTI6DFX.cjs} +26 -26
  35. package/dist/{Mermaid.client-W76R5AKJ.cjs.map → Mermaid.client-NNTI6DFX.cjs.map} +1 -1
  36. package/dist/Player-BRV7XTWR.mjs +4 -0
  37. package/dist/{Player-M3GC3VPE.mjs.map → Player-BRV7XTWR.mjs.map} +1 -1
  38. package/dist/Player-PM7F7DD7.cjs +13 -0
  39. package/dist/{Player-ZL2X5LGG.cjs.map → Player-PM7F7DD7.cjs.map} +1 -1
  40. package/dist/{PrettyCode.client-RPDIE5CH.cjs → PrettyCode.client-KOHDVPPN.cjs} +13 -13
  41. package/dist/{PrettyCode.client-RPDIE5CH.cjs.map → PrettyCode.client-KOHDVPPN.cjs.map} +1 -1
  42. package/dist/{PrettyCode.client-SPMTQEG4.mjs → PrettyCode.client-ZGYGKE7G.mjs} +4 -4
  43. package/dist/{PrettyCode.client-SPMTQEG4.mjs.map → PrettyCode.client-ZGYGKE7G.mjs.map} +1 -1
  44. package/dist/TreeRoot-N72OYKXU.cjs +19 -0
  45. package/dist/{TreeRoot-A3J65L6F.mjs.map → TreeRoot-N72OYKXU.cjs.map} +1 -1
  46. package/dist/TreeRoot-VGAIXCUA.mjs +4 -0
  47. package/dist/{TreeRoot-DSK5JILT.cjs.map → TreeRoot-VGAIXCUA.mjs.map} +1 -1
  48. package/dist/chunk-2ZLKZ5VR.mjs +631 -0
  49. package/dist/chunk-2ZLKZ5VR.mjs.map +1 -0
  50. package/dist/{chunk-LFWQ36LJ.mjs → chunk-5G5YBFS6.mjs} +4 -4
  51. package/dist/{chunk-LFWQ36LJ.mjs.map → chunk-5G5YBFS6.mjs.map} +1 -1
  52. package/dist/{chunk-IHAY6FO6.cjs → chunk-5I5QNGUG.cjs} +17 -17
  53. package/dist/{chunk-IHAY6FO6.cjs.map → chunk-5I5QNGUG.cjs.map} +1 -1
  54. package/dist/{chunk-F2CMIIOH.cjs → chunk-76NNDZH6.cjs} +42 -42
  55. package/dist/{chunk-F2CMIIOH.cjs.map → chunk-76NNDZH6.cjs.map} +1 -1
  56. package/dist/chunk-B5AWZOHJ.cjs +649 -0
  57. package/dist/chunk-B5AWZOHJ.cjs.map +1 -0
  58. package/dist/{chunk-KR6B3LVY.mjs → chunk-B6IR5KSC.mjs} +3 -3
  59. package/dist/{chunk-KR6B3LVY.mjs.map → chunk-B6IR5KSC.mjs.map} +1 -1
  60. package/dist/{chunk-5LBDYFWH.mjs → chunk-C6GXVH5J.mjs} +3 -3
  61. package/dist/{chunk-5LBDYFWH.mjs.map → chunk-C6GXVH5J.mjs.map} +1 -1
  62. package/dist/{chunk-4IW7GZFQ.cjs → chunk-FEN5S772.cjs} +74 -48
  63. package/dist/chunk-FEN5S772.cjs.map +1 -0
  64. package/dist/{chunk-2SMCH62O.cjs → chunk-FP2RLYQZ.cjs} +11 -11
  65. package/dist/{chunk-2SMCH62O.cjs.map → chunk-FP2RLYQZ.cjs.map} +1 -1
  66. package/dist/{chunk-MOME6KYD.mjs → chunk-G5IEC7SR.mjs} +3 -3
  67. package/dist/{chunk-MOME6KYD.mjs.map → chunk-G5IEC7SR.mjs.map} +1 -1
  68. package/dist/{chunk-EXGXUK2N.mjs → chunk-GYIO7W7M.mjs} +41 -15
  69. package/dist/chunk-GYIO7W7M.mjs.map +1 -0
  70. package/dist/{chunk-3Z3A7FHA.cjs → chunk-IEEAENLX.cjs} +48 -48
  71. package/dist/{chunk-3Z3A7FHA.cjs.map → chunk-IEEAENLX.cjs.map} +1 -1
  72. package/dist/{chunk-DFTVB66S.cjs → chunk-KNDLV4PI.cjs} +85 -85
  73. package/dist/{chunk-DFTVB66S.cjs.map → chunk-KNDLV4PI.cjs.map} +1 -1
  74. package/dist/{chunk-SSUOENAZ.mjs → chunk-KNEQRUBA.mjs} +3 -3
  75. package/dist/{chunk-SSUOENAZ.mjs.map → chunk-KNEQRUBA.mjs.map} +1 -1
  76. package/dist/chunk-KRETIZU6.mjs +2218 -0
  77. package/dist/chunk-KRETIZU6.mjs.map +1 -0
  78. package/dist/{chunk-CGILA3WO.mjs → chunk-N2XQF2OL.mjs} +5 -3
  79. package/dist/{chunk-CGILA3WO.mjs.map → chunk-N2XQF2OL.mjs.map} +1 -1
  80. package/dist/{chunk-EUADAUBQ.mjs → chunk-N4MZYNR4.mjs} +4 -4
  81. package/dist/{chunk-EUADAUBQ.mjs.map → chunk-N4MZYNR4.mjs.map} +1 -1
  82. package/dist/chunk-NRXYYO5V.cjs +2257 -0
  83. package/dist/chunk-NRXYYO5V.cjs.map +1 -0
  84. package/dist/{chunk-GGKGH5PM.mjs → chunk-OBRSGM64.mjs} +4 -4
  85. package/dist/{chunk-GGKGH5PM.mjs.map → chunk-OBRSGM64.mjs.map} +1 -1
  86. package/dist/{chunk-6JTB2X72.mjs → chunk-ODO4GMW7.mjs} +3 -3
  87. package/dist/{chunk-6JTB2X72.mjs.map → chunk-ODO4GMW7.mjs.map} +1 -1
  88. package/dist/{chunk-WGEGR3DF.cjs → chunk-OLISEQHS.cjs} +5 -2
  89. package/dist/{chunk-WGEGR3DF.cjs.map → chunk-OLISEQHS.cjs.map} +1 -1
  90. package/dist/{chunk-PZKAH7WQ.mjs → chunk-PVAX67JG.mjs} +3 -3
  91. package/dist/{chunk-PZKAH7WQ.mjs.map → chunk-PVAX67JG.mjs.map} +1 -1
  92. package/dist/{chunk-PRPG2T2E.cjs → chunk-QJ6GTUCO.cjs} +6 -6
  93. package/dist/{chunk-PRPG2T2E.cjs.map → chunk-QJ6GTUCO.cjs.map} +1 -1
  94. package/dist/chunk-QW4RBGHN.cjs +961 -0
  95. package/dist/chunk-QW4RBGHN.cjs.map +1 -0
  96. package/dist/{chunk-33AMWFBZ.cjs → chunk-SGP7V2UW.cjs} +15 -15
  97. package/dist/{chunk-33AMWFBZ.cjs.map → chunk-SGP7V2UW.cjs.map} +1 -1
  98. package/dist/{chunk-FX2QFYWF.mjs → chunk-VWQ5WOIL.mjs} +3 -3
  99. package/dist/{chunk-FX2QFYWF.mjs.map → chunk-VWQ5WOIL.mjs.map} +1 -1
  100. package/dist/{chunk-ZLQHUZDU.cjs → chunk-YDPDTOSP.cjs} +139 -139
  101. package/dist/{chunk-ZLQHUZDU.cjs.map → chunk-YDPDTOSP.cjs.map} +1 -1
  102. package/dist/{chunk-77HQWEQ6.cjs → chunk-YW5IVWHQ.cjs} +33 -33
  103. package/dist/{chunk-77HQWEQ6.cjs.map → chunk-YW5IVWHQ.cjs.map} +1 -1
  104. package/dist/{chunk-YXBOAGIM.cjs → chunk-YXZ6GU7H.cjs} +7 -7
  105. package/dist/{chunk-YXBOAGIM.cjs.map → chunk-YXZ6GU7H.cjs.map} +1 -1
  106. package/dist/{chunk-62Y65TGK.mjs → chunk-ZUFTH5IR.mjs} +8 -631
  107. package/dist/chunk-ZUFTH5IR.mjs.map +1 -0
  108. package/dist/components-EHOGXATG.cjs +22 -0
  109. package/dist/{components-5UXYNAKR.cjs.map → components-EHOGXATG.cjs.map} +1 -1
  110. package/dist/components-MQ6DR7TX.cjs +26 -0
  111. package/dist/{components-CFXOEVPN.mjs.map → components-MQ6DR7TX.cjs.map} +1 -1
  112. package/dist/components-XRX7QGLB.mjs +5 -0
  113. package/dist/{components-WYEZL5TE.cjs.map → components-XRX7QGLB.mjs.map} +1 -1
  114. package/dist/components-YATKRWLH.mjs +5 -0
  115. package/dist/{components-ZAGG2PBO.mjs.map → components-YATKRWLH.mjs.map} +1 -1
  116. package/dist/file-icon/index.cjs +6 -6
  117. package/dist/file-icon/index.mjs +1 -1
  118. package/dist/index.cjs +735 -215
  119. package/dist/index.cjs.map +1 -1
  120. package/dist/index.d.cts +972 -39
  121. package/dist/index.d.ts +972 -39
  122. package/dist/index.mjs +387 -31
  123. package/dist/index.mjs.map +1 -1
  124. package/dist/tree/index.cjs +38 -38
  125. package/dist/tree/index.d.cts +2 -2
  126. package/dist/tree/index.d.ts +2 -2
  127. package/dist/tree/index.mjs +3 -3
  128. package/package.json +6 -6
  129. package/src/index.ts +5 -0
  130. package/src/stories/index.ts +3 -1
  131. package/src/tools/Chat/Chat.story.tsx +1006 -0
  132. package/src/tools/Chat/README.md +528 -0
  133. package/src/tools/Chat/components/Attachments.tsx +192 -0
  134. package/src/tools/Chat/components/ChatRoot.tsx +201 -0
  135. package/src/tools/Chat/components/Composer.tsx +134 -0
  136. package/src/tools/Chat/components/EmptyState.tsx +47 -0
  137. package/src/tools/Chat/components/ErrorBanner.tsx +47 -0
  138. package/src/tools/Chat/components/JumpToLatest.tsx +30 -0
  139. package/src/tools/Chat/components/MessageActions.tsx +72 -0
  140. package/src/tools/Chat/components/MessageBubble.tsx +228 -0
  141. package/src/tools/Chat/components/MessageList.tsx +82 -0
  142. package/src/tools/Chat/components/Sources.tsx +55 -0
  143. package/src/tools/Chat/components/StreamingIndicator.tsx +29 -0
  144. package/src/tools/Chat/components/ToolCalls.tsx +172 -0
  145. package/src/tools/Chat/components/index.ts +24 -0
  146. package/src/tools/Chat/config.ts +55 -0
  147. package/src/tools/Chat/context/ChatProvider.tsx +122 -0
  148. package/src/tools/Chat/context/index.ts +9 -0
  149. package/src/tools/Chat/core/audio/audioBus.ts +172 -0
  150. package/src/tools/Chat/core/audio/index.ts +8 -0
  151. package/src/tools/Chat/core/audio/preferences.ts +68 -0
  152. package/src/tools/Chat/core/audio/types.ts +49 -0
  153. package/src/tools/Chat/core/ids.ts +16 -0
  154. package/src/tools/Chat/core/index.ts +5 -0
  155. package/src/tools/Chat/core/markdown.ts +56 -0
  156. package/src/tools/Chat/core/payload-dispatch.ts +54 -0
  157. package/src/tools/Chat/core/persona.ts +35 -0
  158. package/src/tools/Chat/core/reducer.ts +335 -0
  159. package/src/tools/Chat/core/transport/http.ts +167 -0
  160. package/src/tools/Chat/core/transport/index.ts +13 -0
  161. package/src/tools/Chat/core/transport/mock.ts +134 -0
  162. package/src/tools/Chat/core/transport/sse.ts +116 -0
  163. package/src/tools/Chat/core/transport/types.ts +24 -0
  164. package/src/tools/Chat/hooks/index.ts +26 -0
  165. package/src/tools/Chat/hooks/useChat.ts +440 -0
  166. package/src/tools/Chat/hooks/useChatAudio.ts +191 -0
  167. package/src/tools/Chat/hooks/useChatComposer.ts +227 -0
  168. package/src/tools/Chat/hooks/useChatHistory.ts +59 -0
  169. package/src/tools/Chat/hooks/useChatLayout.ts +111 -0
  170. package/src/tools/Chat/hooks/useChatLightbox.ts +34 -0
  171. package/src/tools/Chat/hooks/useChatScroll.ts +132 -0
  172. package/src/tools/Chat/index.ts +158 -0
  173. package/src/tools/Chat/lazy.tsx +14 -0
  174. package/src/tools/Chat/types.ts +237 -0
  175. package/src/tools/Chat/utils/collectImageAttachments.ts +13 -0
  176. package/src/tools/JsonForm/JsonSchemaForm.tsx +32 -1
  177. package/src/tools/Map/README.md +384 -0
  178. package/dist/DocsLayout-CTJINVBM.mjs.map +0 -1
  179. package/dist/DocsLayout-XLDB6CJ2.cjs.map +0 -1
  180. package/dist/JsonSchemaForm-OSPUUUHM.cjs +0 -13
  181. package/dist/JsonSchemaForm-TSLX2GRO.mjs +0 -4
  182. package/dist/JsonTree-F27RMYSI.cjs +0 -11
  183. package/dist/JsonTree-QTJYSHCV.mjs +0 -5
  184. package/dist/Player-M3GC3VPE.mjs +0 -4
  185. package/dist/Player-ZL2X5LGG.cjs +0 -13
  186. package/dist/TreeRoot-A3J65L6F.mjs +0 -4
  187. package/dist/TreeRoot-DSK5JILT.cjs +0 -19
  188. package/dist/chunk-4IW7GZFQ.cjs.map +0 -1
  189. package/dist/chunk-62Y65TGK.mjs.map +0 -1
  190. package/dist/chunk-EXGXUK2N.mjs.map +0 -1
  191. package/dist/chunk-TKSFZHCG.cjs +0 -1597
  192. package/dist/chunk-TKSFZHCG.cjs.map +0 -1
  193. package/dist/components-5UXYNAKR.cjs +0 -22
  194. package/dist/components-CFXOEVPN.mjs +0 -5
  195. package/dist/components-WYEZL5TE.cjs +0 -26
  196. package/dist/components-ZAGG2PBO.mjs +0 -5
@@ -0,0 +1,961 @@
1
+ 'use strict';
2
+
3
+ var chunkOLISEQHS_cjs = require('./chunk-OLISEQHS.cjs');
4
+ var consola2 = require('consola');
5
+ var React = require('react');
6
+ var hooks = require('@djangocfg/ui-core/hooks');
7
+ var openapiSampler = require('openapi-sampler');
8
+ var jsxRuntime = require('react/jsx-runtime');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var consola2__default = /*#__PURE__*/_interopDefault(consola2);
13
+ var React__default = /*#__PURE__*/_interopDefault(React);
14
+
15
+ // src/tools/OpenapiViewer/utils/apiKeyManager.ts
16
+ function findApiKeyById(apiKeys, keyId) {
17
+ return apiKeys.find((key) => key.id === keyId) || null;
18
+ }
19
+ chunkOLISEQHS_cjs.__name(findApiKeyById, "findApiKeyById");
20
+
21
+ // src/tools/OpenapiViewer/utils/codeSamples.ts
22
+ var CODE_SAMPLE_TARGETS = [
23
+ { id: "curl", label: "cURL", prism: "bash" },
24
+ { id: "fetch", label: "JavaScript", prism: "javascript" },
25
+ { id: "axios", label: "Node (axios)", prism: "javascript" },
26
+ { id: "python", label: "Python", prism: "python" },
27
+ { id: "go", label: "Go", prism: "go" },
28
+ { id: "php", label: "PHP", prism: "php" },
29
+ { id: "ruby", label: "Ruby", prism: "ruby" },
30
+ { id: "java", label: "Java", prism: "java" }
31
+ ];
32
+ function goRawString(s) {
33
+ return s.includes("`") ? JSON.stringify(s) : `\`${s}\``;
34
+ }
35
+ chunkOLISEQHS_cjs.__name(goRawString, "goRawString");
36
+ function rubyHeredoc(s) {
37
+ return `<<~JSON
38
+ ${s}
39
+ JSON`;
40
+ }
41
+ chunkOLISEQHS_cjs.__name(rubyHeredoc, "rubyHeredoc");
42
+ function phpHeredoc(s) {
43
+ return `<<<JSON
44
+ ${s}
45
+ JSON`;
46
+ }
47
+ chunkOLISEQHS_cjs.__name(phpHeredoc, "phpHeredoc");
48
+ function javaTextBlock(s) {
49
+ if (s.includes('"""')) return JSON.stringify(s);
50
+ return `"""
51
+ ${s}
52
+ """`;
53
+ }
54
+ chunkOLISEQHS_cjs.__name(javaTextBlock, "javaTextBlock");
55
+ function fullUrl(har) {
56
+ if (!har.queryString.length) return har.url;
57
+ const qs = har.queryString.map((p) => `${encodeURIComponent(p.name)}=${encodeURIComponent(p.value)}`).join("&");
58
+ const sep = har.url.includes("?") ? "&" : "?";
59
+ return `${har.url}${sep}${qs}`;
60
+ }
61
+ chunkOLISEQHS_cjs.__name(fullUrl, "fullUrl");
62
+ function shellEscape(value) {
63
+ return `'${value.replace(/'/g, `'\\''`)}'`;
64
+ }
65
+ chunkOLISEQHS_cjs.__name(shellEscape, "shellEscape");
66
+ function renderCurl(har) {
67
+ const lines = [`curl -X ${har.method} ${shellEscape(fullUrl(har))}`];
68
+ for (const h of har.headers) {
69
+ lines.push(` -H ${shellEscape(`${h.name}: ${h.value}`)}`);
70
+ }
71
+ if (har.postData?.text) {
72
+ lines.push(` -d ${shellEscape(har.postData.text)}`);
73
+ }
74
+ return lines.join(" \\\n");
75
+ }
76
+ chunkOLISEQHS_cjs.__name(renderCurl, "renderCurl");
77
+ function jsHeadersLiteral(har, indent) {
78
+ if (!har.headers.length) return "{}";
79
+ const entries = har.headers.map((h) => `${indent} ${JSON.stringify(h.name)}: ${JSON.stringify(h.value)}`).join(",\n");
80
+ return `{
81
+ ${entries},
82
+ ${indent}}`;
83
+ }
84
+ chunkOLISEQHS_cjs.__name(jsHeadersLiteral, "jsHeadersLiteral");
85
+ function jsTemplateLiteral(s) {
86
+ if (/[`$]/.test(s)) return JSON.stringify(s);
87
+ return `\`${s}\``;
88
+ }
89
+ chunkOLISEQHS_cjs.__name(jsTemplateLiteral, "jsTemplateLiteral");
90
+ function renderFetch(har) {
91
+ const url = fullUrl(har);
92
+ const options = [` method: ${JSON.stringify(har.method)}`];
93
+ if (har.headers.length) {
94
+ options.push(` headers: ${jsHeadersLiteral(har, " ")}`);
95
+ }
96
+ if (har.postData?.text) {
97
+ options.push(` body: ${jsTemplateLiteral(har.postData.text)}`);
98
+ }
99
+ return `const response = await fetch(${JSON.stringify(url)}, {
100
+ ${options.join(",\n")},
101
+ });
102
+ const data = await response.json();`;
103
+ }
104
+ chunkOLISEQHS_cjs.__name(renderFetch, "renderFetch");
105
+ function renderAxios(har) {
106
+ const url = fullUrl(har);
107
+ const config = [
108
+ ` method: ${JSON.stringify(har.method.toLowerCase())}`,
109
+ ` url: ${JSON.stringify(url)}`
110
+ ];
111
+ if (har.headers.length) {
112
+ config.push(` headers: ${jsHeadersLiteral(har, " ")}`);
113
+ }
114
+ if (har.postData?.text) {
115
+ config.push(` data: ${har.postData.text}`);
116
+ }
117
+ return `import axios from 'axios';
118
+
119
+ const { data } = await axios({
120
+ ${config.join(",\n")},
121
+ });`;
122
+ }
123
+ chunkOLISEQHS_cjs.__name(renderAxios, "renderAxios");
124
+ function renderPython(har) {
125
+ const lines = [`import requests`, ``];
126
+ lines.push(`url = ${JSON.stringify(fullUrl(har))}`);
127
+ if (har.headers.length) {
128
+ const headerEntries = har.headers.map((h) => ` ${JSON.stringify(h.name)}: ${JSON.stringify(h.value)}`).join(",\n");
129
+ lines.push(`headers = {
130
+ ${headerEntries},
131
+ }`);
132
+ }
133
+ if (har.postData?.text) {
134
+ lines.push(`payload = ${har.postData.text}`);
135
+ }
136
+ const args = [`url`];
137
+ if (har.headers.length) args.push(`headers=headers`);
138
+ if (har.postData?.text) args.push(`json=payload`);
139
+ lines.push(``, `response = requests.${har.method.toLowerCase()}(${args.join(", ")})`);
140
+ lines.push(`data = response.json()`);
141
+ return lines.join("\n");
142
+ }
143
+ chunkOLISEQHS_cjs.__name(renderPython, "renderPython");
144
+ function renderGo(har) {
145
+ const url = fullUrl(har);
146
+ const lines = [
147
+ `package main`,
148
+ ``,
149
+ `import (`,
150
+ ` "fmt"`,
151
+ ` "io"`
152
+ ];
153
+ if (har.postData?.text) lines.push(` "strings"`);
154
+ lines.push(` "net/http"`);
155
+ lines.push(`)`, ``, `func main() {`);
156
+ if (har.postData?.text) {
157
+ lines.push(` payload := strings.NewReader(${goRawString(har.postData.text)})`);
158
+ lines.push(` req, _ := http.NewRequest(${JSON.stringify(har.method)}, ${JSON.stringify(url)}, payload)`);
159
+ } else {
160
+ lines.push(` req, _ := http.NewRequest(${JSON.stringify(har.method)}, ${JSON.stringify(url)}, nil)`);
161
+ }
162
+ for (const h of har.headers) {
163
+ lines.push(` req.Header.Add(${JSON.stringify(h.name)}, ${JSON.stringify(h.value)})`);
164
+ }
165
+ lines.push(
166
+ ``,
167
+ ` res, _ := http.DefaultClient.Do(req)`,
168
+ ` defer res.Body.Close()`,
169
+ ` body, _ := io.ReadAll(res.Body)`,
170
+ ` fmt.Println(string(body))`,
171
+ `}`
172
+ );
173
+ return lines.join("\n");
174
+ }
175
+ chunkOLISEQHS_cjs.__name(renderGo, "renderGo");
176
+ function renderPhp(har) {
177
+ const lines = [`<?php`, ``, `$curl = curl_init();`, ``, `curl_setopt_array($curl, [`];
178
+ lines.push(` CURLOPT_URL => ${JSON.stringify(fullUrl(har))},`);
179
+ lines.push(` CURLOPT_RETURNTRANSFER => true,`);
180
+ lines.push(` CURLOPT_CUSTOMREQUEST => ${JSON.stringify(har.method)},`);
181
+ if (har.postData?.text) {
182
+ lines.push(` CURLOPT_POSTFIELDS => ${phpHeredoc(har.postData.text)},`);
183
+ }
184
+ if (har.headers.length) {
185
+ const headerList = har.headers.map((h) => ` ${JSON.stringify(`${h.name}: ${h.value}`)}`).join(",\n");
186
+ lines.push(` CURLOPT_HTTPHEADER => [
187
+ ${headerList},
188
+ ],`);
189
+ }
190
+ lines.push(`]);`, ``, `$response = curl_exec($curl);`, `curl_close($curl);`, `echo $response;`);
191
+ return lines.join("\n");
192
+ }
193
+ chunkOLISEQHS_cjs.__name(renderPhp, "renderPhp");
194
+ function renderRuby(har) {
195
+ const lines = [
196
+ `require 'net/http'`,
197
+ `require 'uri'`,
198
+ `require 'json'`,
199
+ ``,
200
+ `uri = URI(${JSON.stringify(fullUrl(har))})`,
201
+ `http = Net::HTTP.new(uri.host, uri.port)`,
202
+ `http.use_ssl = uri.scheme == 'https'`,
203
+ ``
204
+ ];
205
+ const methodClass = har.method.charAt(0) + har.method.slice(1).toLowerCase();
206
+ lines.push(`request = Net::HTTP::${methodClass}.new(uri)`);
207
+ for (const h of har.headers) {
208
+ lines.push(`request[${JSON.stringify(h.name)}] = ${JSON.stringify(h.value)}`);
209
+ }
210
+ if (har.postData?.text) {
211
+ lines.push(`request.body = ${rubyHeredoc(har.postData.text)}`);
212
+ }
213
+ lines.push(``, `response = http.request(request)`, `puts response.body`);
214
+ return lines.join("\n");
215
+ }
216
+ chunkOLISEQHS_cjs.__name(renderRuby, "renderRuby");
217
+ function renderJava(har) {
218
+ const lines = [
219
+ `OkHttpClient client = new OkHttpClient();`,
220
+ ``
221
+ ];
222
+ if (har.postData?.text) {
223
+ lines.push(
224
+ `MediaType mediaType = MediaType.parse("application/json");`,
225
+ `RequestBody body = RequestBody.create(mediaType, ${javaTextBlock(har.postData.text)});`,
226
+ ``
227
+ );
228
+ }
229
+ lines.push(`Request request = new Request.Builder()`);
230
+ lines.push(` .url(${JSON.stringify(fullUrl(har))})`);
231
+ if (har.postData?.text) {
232
+ lines.push(` .method(${JSON.stringify(har.method)}, body)`);
233
+ } else {
234
+ lines.push(` .method(${JSON.stringify(har.method)}, null)`);
235
+ }
236
+ for (const h of har.headers) {
237
+ lines.push(` .addHeader(${JSON.stringify(h.name)}, ${JSON.stringify(h.value)})`);
238
+ }
239
+ lines.push(` .build();`, ``, `Response response = client.newCall(request).execute();`);
240
+ return lines.join("\n");
241
+ }
242
+ chunkOLISEQHS_cjs.__name(renderJava, "renderJava");
243
+ var RENDERERS = {
244
+ curl: renderCurl,
245
+ fetch: renderFetch,
246
+ axios: renderAxios,
247
+ python: renderPython,
248
+ go: renderGo,
249
+ php: renderPhp,
250
+ ruby: renderRuby,
251
+ java: renderJava
252
+ };
253
+ function renderSnippet(har, targetId) {
254
+ const renderer = RENDERERS[targetId];
255
+ if (!renderer) return null;
256
+ try {
257
+ return renderer(har);
258
+ } catch {
259
+ return null;
260
+ }
261
+ }
262
+ chunkOLISEQHS_cjs.__name(renderSnippet, "renderSnippet");
263
+
264
+ // src/tools/OpenapiViewer/utils/operationToHar.ts
265
+ function buildUrl(endpoint, parameters, baseUrl) {
266
+ const pathParamNames = new Set(
267
+ (endpoint.parameters ?? []).filter((p) => endpoint.path.includes(`{${p.name}}`)).map((p) => p.name)
268
+ );
269
+ let path = endpoint.path;
270
+ for (const name of pathParamNames) {
271
+ const value = parameters[name];
272
+ if (value === void 0 || value === "") continue;
273
+ path = path.replaceAll(`{${name}}`, encodeURIComponent(value));
274
+ }
275
+ const queryString = [];
276
+ for (const param of endpoint.parameters ?? []) {
277
+ if (pathParamNames.has(param.name)) continue;
278
+ const value = parameters[param.name];
279
+ if (value === void 0 || value === "") continue;
280
+ queryString.push({ name: param.name, value });
281
+ }
282
+ const url = baseUrl ? `${baseUrl.replace(/\/+$/, "")}${path.startsWith("/") ? path : `/${path}`}` : path;
283
+ return { url, queryString };
284
+ }
285
+ chunkOLISEQHS_cjs.__name(buildUrl, "buildUrl");
286
+ function buildHarRequest(input) {
287
+ const { endpoint, body, parameters = {}, headers = {}, baseUrl } = input;
288
+ const { url, queryString } = buildUrl(endpoint, parameters, baseUrl);
289
+ const hasBody = Boolean(body && body.trim().length > 0);
290
+ const bodyMime = hasBody ? "application/json" : void 0;
291
+ const mergedHeaders = {};
292
+ if (hasBody && bodyMime) mergedHeaders["Content-Type"] = bodyMime;
293
+ mergedHeaders["Accept"] = "application/json";
294
+ for (const [k, v] of Object.entries(headers)) {
295
+ if (v === void 0 || v === "") continue;
296
+ mergedHeaders[k] = v;
297
+ }
298
+ const har = {
299
+ method: endpoint.method.toUpperCase(),
300
+ url,
301
+ httpVersion: "HTTP/1.1",
302
+ headers: Object.entries(mergedHeaders).map(([name, value]) => ({ name, value })),
303
+ queryString,
304
+ cookies: [],
305
+ headersSize: -1,
306
+ bodySize: hasBody ? new TextEncoder().encode(body).length : 0
307
+ };
308
+ if (hasBody && bodyMime) {
309
+ har.postData = { mimeType: bodyMime, text: body };
310
+ }
311
+ return har;
312
+ }
313
+ chunkOLISEQHS_cjs.__name(buildHarRequest, "buildHarRequest");
314
+
315
+ // src/tools/OpenapiViewer/utils/versionManager.ts
316
+ var API_VERSIONS = [
317
+ {
318
+ id: "v1",
319
+ name: "v1",
320
+ description: "Current stable version",
321
+ isDefault: true
322
+ }
323
+ ];
324
+ var detectEndpointVersion = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((path) => {
325
+ const versionMatch = path.match(/\/api\/[^/]+\/(v\d+)\//);
326
+ if (versionMatch && versionMatch[1]) {
327
+ return versionMatch[1];
328
+ }
329
+ return "v1";
330
+ }, "detectEndpointVersion");
331
+ var isEndpointInVersion = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((endpoint, version) => {
332
+ const endpointVersion = detectEndpointVersion(endpoint.path);
333
+ return endpointVersion === version;
334
+ }, "isEndpointInVersion");
335
+ var deduplicateEndpoints = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((endpoints, preferredVersion) => {
336
+ const endpointMap = /* @__PURE__ */ new Map();
337
+ const groupedEndpoints = /* @__PURE__ */ new Map();
338
+ endpoints.forEach((endpoint) => {
339
+ const normalizedPath = normalizeEndpointPath(endpoint.path);
340
+ if (!groupedEndpoints.has(normalizedPath)) {
341
+ groupedEndpoints.set(normalizedPath, []);
342
+ }
343
+ groupedEndpoints.get(normalizedPath).push(endpoint);
344
+ });
345
+ groupedEndpoints.forEach((endpointGroup, normalizedPath) => {
346
+ let selectedEndpoint = null;
347
+ const versionEndpoint = endpointGroup.find((ep) => isEndpointInVersion(ep, preferredVersion));
348
+ if (versionEndpoint) {
349
+ selectedEndpoint = versionEndpoint;
350
+ } else if (endpointGroup.length > 0) {
351
+ selectedEndpoint = endpointGroup[0] || null;
352
+ }
353
+ if (selectedEndpoint) {
354
+ endpointMap.set(normalizedPath, selectedEndpoint);
355
+ }
356
+ });
357
+ return Array.from(endpointMap.values());
358
+ }, "deduplicateEndpoints");
359
+ var normalizeEndpointPath = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((path) => {
360
+ return path.replace(/\/v\d+\//, "/");
361
+ }, "normalizeEndpointPath");
362
+ var getDefaultVersion = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
363
+ const defaultVersion = API_VERSIONS.find((v) => v.isDefault);
364
+ if (defaultVersion) {
365
+ return defaultVersion;
366
+ }
367
+ if (API_VERSIONS.length > 0 && API_VERSIONS[0]) {
368
+ return API_VERSIONS[0];
369
+ }
370
+ throw new Error("No API versions defined");
371
+ }, "getDefaultVersion");
372
+
373
+ // src/tools/OpenapiViewer/utils/formatters.ts
374
+ var isValidJson = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((str) => {
375
+ if (!str || typeof str !== "string") return false;
376
+ try {
377
+ JSON.parse(str);
378
+ return true;
379
+ } catch {
380
+ return false;
381
+ }
382
+ }, "isValidJson");
383
+ var parseRequestHeaders = /* @__PURE__ */ chunkOLISEQHS_cjs.__name((headersString) => {
384
+ if (!headersString || typeof headersString !== "string") {
385
+ return { "Content-Type": "application/json" };
386
+ }
387
+ try {
388
+ const parsed = JSON.parse(headersString);
389
+ return typeof parsed === "object" && parsed !== null ? parsed : { "Content-Type": "application/json" };
390
+ } catch {
391
+ return { "Content-Type": "application/json" };
392
+ }
393
+ }, "parseRequestHeaders");
394
+ function sampleSchema(schema, options = {}, spec) {
395
+ if (!schema) return null;
396
+ try {
397
+ return openapiSampler.sample(schema, options, spec);
398
+ } catch (err) {
399
+ consola2__default.default.warn("[OpenapiViewer] sampleSchema failed:", err, { schema });
400
+ return null;
401
+ }
402
+ }
403
+ chunkOLISEQHS_cjs.__name(sampleSchema, "sampleSchema");
404
+ function sampleSchemaJson(schema, options = {}, spec) {
405
+ const value = sampleSchema(schema, options, spec);
406
+ if (value === null || value === void 0) return void 0;
407
+ try {
408
+ return JSON.stringify(value, null, 2);
409
+ } catch {
410
+ return void 0;
411
+ }
412
+ }
413
+ chunkOLISEQHS_cjs.__name(sampleSchemaJson, "sampleSchemaJson");
414
+
415
+ // src/tools/OpenapiViewer/utils/url.ts
416
+ var PATH_PARAM_RE = /\{([^{}]+)\}/g;
417
+ function extractPathPlaceholders(template) {
418
+ const seen = /* @__PURE__ */ new Set();
419
+ const out = [];
420
+ for (const match of template.matchAll(PATH_PARAM_RE)) {
421
+ const name = match[1];
422
+ if (!seen.has(name)) {
423
+ seen.add(name);
424
+ out.push(name);
425
+ }
426
+ }
427
+ return out;
428
+ }
429
+ chunkOLISEQHS_cjs.__name(extractPathPlaceholders, "extractPathPlaceholders");
430
+ function substitutePath(template, values) {
431
+ return template.replace(PATH_PARAM_RE, (whole, name) => {
432
+ const v = values[name];
433
+ return v && v.trim() !== "" ? encodeURIComponent(v) : whole;
434
+ });
435
+ }
436
+ chunkOLISEQHS_cjs.__name(substitutePath, "substitutePath");
437
+ function unfilledPlaceholders(template, values) {
438
+ return extractPathPlaceholders(template).filter(
439
+ (name) => !(values[name] ?? "").trim()
440
+ );
441
+ }
442
+ chunkOLISEQHS_cjs.__name(unfilledPlaceholders, "unfilledPlaceholders");
443
+ function appendQuery(url, values, pathTemplate) {
444
+ const pathNames = new Set(extractPathPlaceholders(pathTemplate));
445
+ const queryEntries = Object.entries(values).filter(
446
+ ([name, value]) => !pathNames.has(name) && value && value.trim() !== ""
447
+ );
448
+ if (queryEntries.length === 0) return url;
449
+ const [base, existingQuery = ""] = url.split("?", 2);
450
+ const params = new URLSearchParams(existingQuery);
451
+ for (const [k, v] of queryEntries) params.set(k, v);
452
+ const qs = params.toString();
453
+ return qs ? `${base}?${qs}` : base ?? url;
454
+ }
455
+ chunkOLISEQHS_cjs.__name(appendQuery, "appendQuery");
456
+ function resolveAbsolute(url) {
457
+ if (!url) return url;
458
+ if (/^https?:\/\//i.test(url)) return url;
459
+ if (typeof window === "undefined") return url;
460
+ if (url.startsWith("//")) return `${window.location.protocol}${url}`;
461
+ if (url.startsWith("/")) return `${window.location.origin}${url}`;
462
+ return url;
463
+ }
464
+ chunkOLISEQHS_cjs.__name(resolveAbsolute, "resolveAbsolute");
465
+ function relativePath(url) {
466
+ try {
467
+ return new URL(url).pathname.replace(/%7B/gi, "{").replace(/%7D/gi, "}");
468
+ } catch {
469
+ return url;
470
+ }
471
+ }
472
+ chunkOLISEQHS_cjs.__name(relativePath, "relativePath");
473
+ function joinUrl(...parts) {
474
+ return parts.filter((p) => p !== void 0 && p !== null && p !== "").map((p, i) => {
475
+ if (i === 0) return String(p).replace(/\/+$/, "");
476
+ return String(p).replace(/^\/+|\/+$/g, "");
477
+ }).filter((p) => p !== "").join("/");
478
+ }
479
+ chunkOLISEQHS_cjs.__name(joinUrl, "joinUrl");
480
+ function resolveBaseUrl(sources) {
481
+ return sources.schemaSource || sources.config || sources.fromServers || "";
482
+ }
483
+ chunkOLISEQHS_cjs.__name(resolveBaseUrl, "resolveBaseUrl");
484
+ var _UrlBuilder = class _UrlBuilder {
485
+ constructor(endpoint, parameters) {
486
+ this.endpoint = endpoint;
487
+ this.parameters = parameters;
488
+ }
489
+ /** What ``fetch()`` receives: substituted path + query string. Origin
490
+ * is whatever the endpoint template already had (relative paths
491
+ * stay relative so the browser resolves them against the page). */
492
+ build() {
493
+ const substituted = substitutePath(this.endpoint.path, this.parameters);
494
+ return appendQuery(substituted, this.parameters, this.endpoint.path);
495
+ }
496
+ /** Same as ``build()`` but guaranteed absolute — for curl snippets
497
+ * and anywhere the URL leaves the browser context. */
498
+ buildAbsolute() {
499
+ return resolveAbsolute(this.build());
500
+ }
501
+ /** Names of required path/query params still empty. */
502
+ missingRequired() {
503
+ if (!this.endpoint.parameters) return [];
504
+ return this.endpoint.parameters.filter((p) => p.required && !(this.parameters[p.name] ?? "").trim()).map((p) => p.name);
505
+ }
506
+ /** Placeholders in the template with no matching value. Usually a
507
+ * superset of ``missingRequired`` — catches schemas that forgot
508
+ * to flag a path param as required. */
509
+ unfilledPlaceholders() {
510
+ return unfilledPlaceholders(this.endpoint.path, this.parameters);
511
+ }
512
+ };
513
+ chunkOLISEQHS_cjs.__name(_UrlBuilder, "UrlBuilder");
514
+ var UrlBuilder = _UrlBuilder;
515
+
516
+ // src/tools/OpenapiViewer/utils/schemaExport.ts
517
+ function dereferenceSchema(schema, maxDepth = 10) {
518
+ const root = schema;
519
+ function resolveRef(ref) {
520
+ if (!ref.startsWith("#/")) return null;
521
+ const parts = ref.slice(2).split("/");
522
+ let node = root;
523
+ for (const part of parts) {
524
+ if (node && typeof node === "object" && part in node) {
525
+ node = node[part];
526
+ } else {
527
+ return null;
528
+ }
529
+ }
530
+ return node;
531
+ }
532
+ chunkOLISEQHS_cjs.__name(resolveRef, "resolveRef");
533
+ function walk(value, depth) {
534
+ if (depth > maxDepth) return value;
535
+ if (Array.isArray(value)) return value.map((v) => walk(v, depth + 1));
536
+ if (value && typeof value === "object") {
537
+ const obj = value;
538
+ if (typeof obj.$ref === "string") {
539
+ const resolved = resolveRef(obj.$ref);
540
+ if (resolved === null) return obj;
541
+ return walk(resolved, depth + 1);
542
+ }
543
+ const out = {};
544
+ for (const [k, v] of Object.entries(obj)) out[k] = walk(v, depth + 1);
545
+ return out;
546
+ }
547
+ return value;
548
+ }
549
+ chunkOLISEQHS_cjs.__name(walk, "walk");
550
+ return walk(schema, 0);
551
+ }
552
+ chunkOLISEQHS_cjs.__name(dereferenceSchema, "dereferenceSchema");
553
+ var NOISY_KEYS = /* @__PURE__ */ new Set(["xml", "example", "examples", "externalDocs"]);
554
+ var MAX_DESCRIPTION_LEN = 500;
555
+ function pruneForCompact(value) {
556
+ if (Array.isArray(value)) return value.map(pruneForCompact);
557
+ if (value && typeof value === "object") {
558
+ const out = {};
559
+ for (const [k, v] of Object.entries(value)) {
560
+ if (NOISY_KEYS.has(k)) continue;
561
+ if (k === "description" && typeof v === "string" && v.length > MAX_DESCRIPTION_LEN) {
562
+ out[k] = v.slice(0, MAX_DESCRIPTION_LEN).trimEnd() + "\u2026";
563
+ continue;
564
+ }
565
+ out[k] = pruneForCompact(v);
566
+ }
567
+ return out;
568
+ }
569
+ return value;
570
+ }
571
+ chunkOLISEQHS_cjs.__name(pruneForCompact, "pruneForCompact");
572
+ function withResolvedBaseUrl(schema, baseUrl) {
573
+ if (!baseUrl) return schema;
574
+ return { ...schema, servers: [{ url: baseUrl }] };
575
+ }
576
+ chunkOLISEQHS_cjs.__name(withResolvedBaseUrl, "withResolvedBaseUrl");
577
+ function toRawJson(schema, baseUrl) {
578
+ return JSON.stringify(withResolvedBaseUrl(schema, baseUrl), null, 2);
579
+ }
580
+ chunkOLISEQHS_cjs.__name(toRawJson, "toRawJson");
581
+ function toCompactJson(schema, baseUrl) {
582
+ const resolved = dereferenceSchema(withResolvedBaseUrl(schema, baseUrl));
583
+ const pruned = pruneForCompact(resolved);
584
+ return JSON.stringify(pruned);
585
+ }
586
+ chunkOLISEQHS_cjs.__name(toCompactJson, "toCompactJson");
587
+ function endpointToMarkdown(ep) {
588
+ const lines = [];
589
+ lines.push(`### ${ep.method} ${ep.path}`);
590
+ if (ep.description) lines.push(ep.description);
591
+ const pathParams = ep.parameters?.filter((p) => ep.path.includes(`{${p.name}}`)) ?? [];
592
+ const queryParams = ep.parameters?.filter((p) => !ep.path.includes(`{${p.name}}`)) ?? [];
593
+ if (pathParams.length > 0) {
594
+ lines.push("", "**Path parameters**");
595
+ for (const p of pathParams) {
596
+ const req = p.required ? " (required)" : "";
597
+ const desc = p.description ? ` \u2014 ${p.description}` : "";
598
+ lines.push(`- \`${p.name}\`: ${p.type}${req}${desc}`);
599
+ }
600
+ }
601
+ if (queryParams.length > 0) {
602
+ lines.push("", "**Query parameters**");
603
+ for (const p of queryParams) {
604
+ const req = p.required ? " (required)" : "";
605
+ const desc = p.description ? ` \u2014 ${p.description}` : "";
606
+ lines.push(`- \`${p.name}\`: ${p.type}${req}${desc}`);
607
+ }
608
+ }
609
+ if (ep.requestBody) {
610
+ const desc = ep.requestBody.description ? ` \u2014 ${ep.requestBody.description}` : "";
611
+ lines.push("", `**Request body:** ${ep.requestBody.type}${desc}`);
612
+ }
613
+ if (ep.responses && ep.responses.length > 0) {
614
+ lines.push("", "**Responses**");
615
+ for (const r of ep.responses) {
616
+ lines.push(`- \`${r.code}\` \u2014 ${r.description}`);
617
+ }
618
+ }
619
+ return lines.join("\n");
620
+ }
621
+ chunkOLISEQHS_cjs.__name(endpointToMarkdown, "endpointToMarkdown");
622
+ function toMarkdown(schema, endpoints, baseUrl) {
623
+ const lines = [];
624
+ const info = schema.info;
625
+ const resolvedBase = resolveBaseUrl({
626
+ config: baseUrl,
627
+ fromServers: schema.servers?.[0]?.url
628
+ });
629
+ lines.push(`# ${info?.title ?? "API"}${info?.version ? ` (v${info.version})` : ""}`);
630
+ if (resolvedBase) lines.push("", `**Base URL:** \`${resolvedBase}\``);
631
+ if (info?.description) lines.push("", info.description.trim());
632
+ const grouped = /* @__PURE__ */ new Map();
633
+ for (const ep of endpoints) {
634
+ const arr = grouped.get(ep.category) ?? [];
635
+ arr.push(ep);
636
+ grouped.set(ep.category, arr);
637
+ }
638
+ const categories = Array.from(grouped.keys()).sort((a, b) => {
639
+ if (a === "Other") return 1;
640
+ if (b === "Other") return -1;
641
+ return a.localeCompare(b);
642
+ });
643
+ for (const category of categories) {
644
+ lines.push("", `## ${category}`);
645
+ const list = grouped.get(category);
646
+ for (const ep of list) {
647
+ const displayPath = relativePath(ep.path);
648
+ const sub = endpointToMarkdown({ ...ep, path: displayPath });
649
+ lines.push("", sub);
650
+ }
651
+ }
652
+ return lines.join("\n");
653
+ }
654
+ chunkOLISEQHS_cjs.__name(toMarkdown, "toMarkdown");
655
+ function formatBytes(s) {
656
+ const bytes = new Blob([s]).size;
657
+ if (bytes < 1024) return `${bytes} B`;
658
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
659
+ return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
660
+ }
661
+ chunkOLISEQHS_cjs.__name(formatBytes, "formatBytes");
662
+ var AUTH_KEY_STORAGE = "openapi-playground:auth:apiKeyId";
663
+ var AUTH_BEARER_STORAGE = "openapi-playground:auth:bearer";
664
+ var createInitialState = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => ({
665
+ currentStep: "endpoints",
666
+ steps: ["endpoints", "request", "response"],
667
+ selectedEndpoint: null,
668
+ selectedCategory: "All",
669
+ searchTerm: "",
670
+ selectedVersion: getDefaultVersion().id,
671
+ requestUrl: "",
672
+ requestMethod: "GET",
673
+ requestHeaders: '{\n "Content-Type": "application/json"\n}',
674
+ requestBody: "",
675
+ selectedApiKey: null,
676
+ manualApiToken: "",
677
+ parameters: {},
678
+ response: null,
679
+ loading: false,
680
+ sidebarOpen: false,
681
+ activeSchemaId: null
682
+ }), "createInitialState");
683
+ function reducer(state, action) {
684
+ switch (action.type) {
685
+ case "SET_STEP":
686
+ return { ...state, currentStep: action.step };
687
+ case "NEXT_STEP": {
688
+ const i = state.steps.indexOf(state.currentStep);
689
+ return i < state.steps.length - 1 ? { ...state, currentStep: state.steps[i + 1] } : state;
690
+ }
691
+ case "PREV_STEP": {
692
+ const i = state.steps.indexOf(state.currentStep);
693
+ return i > 0 ? { ...state, currentStep: state.steps[i - 1] } : state;
694
+ }
695
+ case "SELECT_ENDPOINT": {
696
+ if (!action.endpoint) return { ...state, selectedEndpoint: null };
697
+ const same = state.selectedEndpoint?.method === action.endpoint.method && state.selectedEndpoint?.path === action.endpoint.path;
698
+ const exampleBody = action.endpoint.requestBody?.example ?? "";
699
+ return {
700
+ ...state,
701
+ selectedEndpoint: action.endpoint,
702
+ requestMethod: action.endpoint.method,
703
+ requestUrl: action.endpoint.path,
704
+ parameters: same ? state.parameters : {},
705
+ requestBody: same ? state.requestBody : exampleBody,
706
+ // Switching to a different endpoint: the previous response no
707
+ // longer belongs here. Clear it so the playground panel collapses
708
+ // back to single-column until the user sends a new request.
709
+ response: same ? state.response : null,
710
+ currentStep: "request"
711
+ };
712
+ }
713
+ case "SET_CATEGORY":
714
+ return { ...state, selectedCategory: action.category };
715
+ case "SET_SEARCH":
716
+ return { ...state, searchTerm: action.term };
717
+ case "SET_VERSION":
718
+ return { ...state, selectedVersion: action.version };
719
+ case "SET_REQUEST_URL":
720
+ return { ...state, requestUrl: action.url };
721
+ case "SET_REQUEST_METHOD":
722
+ return { ...state, requestMethod: action.method };
723
+ case "SET_REQUEST_HEADERS":
724
+ return { ...state, requestHeaders: action.headers };
725
+ case "SET_REQUEST_BODY":
726
+ return { ...state, requestBody: action.body };
727
+ case "SET_API_KEY":
728
+ return { ...state, selectedApiKey: action.apiKeyId };
729
+ case "SET_MANUAL_TOKEN":
730
+ return { ...state, manualApiToken: action.token };
731
+ case "SET_PARAMETERS":
732
+ return { ...state, parameters: action.parameters };
733
+ case "SET_RESPONSE":
734
+ return { ...state, response: action.response };
735
+ case "SET_LOADING":
736
+ return { ...state, loading: action.loading };
737
+ case "REQUEST_START":
738
+ return { ...state, loading: true, response: null };
739
+ case "REQUEST_SUCCESS":
740
+ return { ...state, loading: false, response: action.response, currentStep: "response" };
741
+ case "REQUEST_ERROR":
742
+ return { ...state, loading: false, response: action.response };
743
+ case "SET_SIDEBAR":
744
+ return { ...state, sidebarOpen: action.open };
745
+ case "SET_ACTIVE_SCHEMA_ID":
746
+ return { ...state, activeSchemaId: action.id };
747
+ case "SYNC_API_KEY_HEADER":
748
+ return { ...state, requestHeaders: action.headers };
749
+ case "CLEAR_API_KEY_SELECTION":
750
+ return { ...state, selectedApiKey: null };
751
+ case "SYNC_URL":
752
+ return { ...state, requestUrl: action.url };
753
+ case "RESET":
754
+ return createInitialState();
755
+ default:
756
+ return state;
757
+ }
758
+ }
759
+ chunkOLISEQHS_cjs.__name(reducer, "reducer");
760
+ var PlaygroundContext = React.createContext(void 0);
761
+ var usePlaygroundContext = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
762
+ const context = React.useContext(PlaygroundContext);
763
+ if (!context) throw new Error("usePlaygroundContext must be used within a PlaygroundProvider");
764
+ return context;
765
+ }, "usePlaygroundContext");
766
+ var PlaygroundProvider = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(({ children, config }) => {
767
+ const [state, dispatch] = React.useReducer(reducer, void 0, createInitialState);
768
+ const abortControllerRef = React.useRef(null);
769
+ const apiKeys = React__default.default.useMemo(
770
+ () => config.apiKeys ?? [],
771
+ [config.apiKeys]
772
+ );
773
+ const isLoadingApiKeys = config.apiKeysLoading ?? false;
774
+ const [storedApiKeyId, setStoredApiKeyId] = hooks.useSessionStorage(
775
+ AUTH_KEY_STORAGE,
776
+ null
777
+ );
778
+ const [storedBearer, setStoredBearer] = hooks.useSessionStorage(
779
+ AUTH_BEARER_STORAGE,
780
+ ""
781
+ );
782
+ const hasHydratedAuthRef = React.useRef(false);
783
+ React.useEffect(() => {
784
+ if (hasHydratedAuthRef.current) return;
785
+ hasHydratedAuthRef.current = true;
786
+ if (storedApiKeyId) dispatch({ type: "SET_API_KEY", apiKeyId: storedApiKeyId });
787
+ if (storedBearer) dispatch({ type: "SET_MANUAL_TOKEN", token: storedBearer });
788
+ }, []);
789
+ React.useEffect(() => {
790
+ if (!hasHydratedAuthRef.current) return;
791
+ setStoredApiKeyId(state.selectedApiKey);
792
+ }, [state.selectedApiKey, setStoredApiKeyId]);
793
+ React.useEffect(() => {
794
+ if (!hasHydratedAuthRef.current) return;
795
+ setStoredBearer(state.manualApiToken);
796
+ }, [state.manualApiToken, setStoredBearer]);
797
+ React.useEffect(() => {
798
+ if (!hasHydratedAuthRef.current) return;
799
+ if (!isLoadingApiKeys && apiKeys.length > 0 && !state.selectedApiKey && !storedApiKeyId) {
800
+ dispatch({ type: "SET_API_KEY", apiKeyId: apiKeys[0]?.id || null });
801
+ }
802
+ }, [apiKeys, isLoadingApiKeys, state.selectedApiKey, storedApiKeyId]);
803
+ React.useEffect(() => {
804
+ try {
805
+ const headers = parseRequestHeaders(state.requestHeaders);
806
+ if (state.selectedApiKey) {
807
+ const apiKey = apiKeys.find((k) => k.id === state.selectedApiKey);
808
+ if (!apiKey) {
809
+ dispatch({ type: "CLEAR_API_KEY_SELECTION" });
810
+ return;
811
+ }
812
+ const keyValue = apiKey.secret || apiKey.id;
813
+ if (headers["X-API-Key"] !== keyValue) {
814
+ headers["X-API-Key"] = keyValue;
815
+ dispatch({ type: "SYNC_API_KEY_HEADER", headers: JSON.stringify(headers, null, 2) });
816
+ }
817
+ } else if (headers["X-API-Key"]) {
818
+ delete headers["X-API-Key"];
819
+ dispatch({ type: "SYNC_API_KEY_HEADER", headers: JSON.stringify(headers, null, 2) });
820
+ }
821
+ } catch (error) {
822
+ consola2__default.default.error("Error updating headers:", error);
823
+ }
824
+ }, [state.selectedApiKey, apiKeys]);
825
+ React.useEffect(() => {
826
+ if (!state.selectedEndpoint) return;
827
+ const updated = new UrlBuilder(state.selectedEndpoint, state.parameters).build();
828
+ if (updated !== state.requestUrl) {
829
+ dispatch({ type: "SYNC_URL", url: updated });
830
+ }
831
+ }, [state.parameters, state.selectedEndpoint]);
832
+ const setCurrentStep = React.useCallback((step) => dispatch({ type: "SET_STEP", step }), []);
833
+ const goToNextStep = React.useCallback(() => dispatch({ type: "NEXT_STEP" }), []);
834
+ const goToPreviousStep = React.useCallback(() => dispatch({ type: "PREV_STEP" }), []);
835
+ const setSelectedEndpoint = React.useCallback((endpoint) => dispatch({ type: "SELECT_ENDPOINT", endpoint }), []);
836
+ const setSelectedCategory = React.useCallback((category) => dispatch({ type: "SET_CATEGORY", category }), []);
837
+ const setSearchTerm = React.useCallback((term) => dispatch({ type: "SET_SEARCH", term }), []);
838
+ const setSelectedVersion = React.useCallback((version) => dispatch({ type: "SET_VERSION", version }), []);
839
+ const setRequestUrl = React.useCallback((url) => dispatch({ type: "SET_REQUEST_URL", url }), []);
840
+ const setRequestMethod = React.useCallback((method) => dispatch({ type: "SET_REQUEST_METHOD", method }), []);
841
+ const setRequestHeaders = React.useCallback((headers) => dispatch({ type: "SET_REQUEST_HEADERS", headers }), []);
842
+ const setRequestBody = React.useCallback((body) => dispatch({ type: "SET_REQUEST_BODY", body }), []);
843
+ const setSelectedApiKey = React.useCallback((apiKeyId) => dispatch({ type: "SET_API_KEY", apiKeyId }), []);
844
+ const setManualApiToken = React.useCallback((token) => dispatch({ type: "SET_MANUAL_TOKEN", token }), []);
845
+ const setParameters = React.useCallback((parameters) => dispatch({ type: "SET_PARAMETERS", parameters }), []);
846
+ const setResponse = React.useCallback((response) => dispatch({ type: "SET_RESPONSE", response }), []);
847
+ const setLoading = React.useCallback((loading) => dispatch({ type: "SET_LOADING", loading }), []);
848
+ const setSidebarOpen = React.useCallback((open) => dispatch({ type: "SET_SIDEBAR", open }), []);
849
+ const setActiveSchemaId = React.useCallback((id) => dispatch({ type: "SET_ACTIVE_SCHEMA_ID", id }), []);
850
+ const clearAll = React.useCallback(() => dispatch({ type: "RESET" }), []);
851
+ const sendRequest = React.useCallback(async () => {
852
+ if (!state.requestUrl) {
853
+ consola2__default.default.error("No URL provided");
854
+ return;
855
+ }
856
+ abortControllerRef.current?.abort();
857
+ const controller = new AbortController();
858
+ abortControllerRef.current = controller;
859
+ dispatch({ type: "REQUEST_START" });
860
+ const startTime = Date.now();
861
+ try {
862
+ const headers = parseRequestHeaders(state.requestHeaders);
863
+ let bearerToken = null;
864
+ if (state.manualApiToken) {
865
+ bearerToken = state.manualApiToken;
866
+ } else if (typeof window !== "undefined") {
867
+ bearerToken = window.localStorage.getItem("auth_token");
868
+ }
869
+ if (bearerToken) headers["Authorization"] = `Bearer ${bearerToken}`;
870
+ const requestOptions = {
871
+ method: state.requestMethod,
872
+ headers,
873
+ signal: controller.signal
874
+ };
875
+ if (state.requestBody && state.requestMethod !== "GET") {
876
+ requestOptions.body = state.requestBody;
877
+ }
878
+ const response = await fetch(state.requestUrl, requestOptions);
879
+ const duration = Date.now() - startTime;
880
+ const responseText = await response.text();
881
+ let responseData;
882
+ try {
883
+ responseData = JSON.parse(responseText);
884
+ } catch {
885
+ responseData = responseText;
886
+ }
887
+ dispatch({
888
+ type: "REQUEST_SUCCESS",
889
+ response: {
890
+ status: response.status,
891
+ statusText: response.statusText,
892
+ headers: Object.fromEntries(response.headers.entries()),
893
+ data: responseData,
894
+ duration
895
+ }
896
+ });
897
+ consola2__default.default.success(`${state.requestMethod} ${state.requestUrl} \u2192 ${response.status} (${duration}ms)`);
898
+ } catch (error) {
899
+ if (error instanceof DOMException && error.name === "AbortError") return;
900
+ consola2__default.default.error("Request failed:", error);
901
+ dispatch({
902
+ type: "REQUEST_ERROR",
903
+ response: {
904
+ error: error instanceof Error ? error.message : "Request failed",
905
+ duration: Date.now() - startTime
906
+ }
907
+ });
908
+ }
909
+ }, [state.requestUrl, state.requestHeaders, state.manualApiToken, state.requestMethod, state.requestBody]);
910
+ const contextValue = {
911
+ state,
912
+ config,
913
+ apiKeys,
914
+ apiKeysLoading: isLoadingApiKeys,
915
+ setCurrentStep,
916
+ goToNextStep,
917
+ goToPreviousStep,
918
+ setSelectedEndpoint,
919
+ setSelectedCategory,
920
+ setSearchTerm,
921
+ setSelectedVersion,
922
+ setRequestUrl,
923
+ setRequestMethod,
924
+ setRequestHeaders,
925
+ setRequestBody,
926
+ setSelectedApiKey,
927
+ setManualApiToken,
928
+ setParameters,
929
+ setResponse,
930
+ setLoading,
931
+ setSidebarOpen,
932
+ setActiveSchemaId,
933
+ clearAll,
934
+ sendRequest
935
+ };
936
+ return /* @__PURE__ */ jsxRuntime.jsx(PlaygroundContext.Provider, { value: contextValue, children });
937
+ }, "PlaygroundProvider");
938
+
939
+ exports.CODE_SAMPLE_TARGETS = CODE_SAMPLE_TARGETS;
940
+ exports.PlaygroundProvider = PlaygroundProvider;
941
+ exports.UrlBuilder = UrlBuilder;
942
+ exports.buildHarRequest = buildHarRequest;
943
+ exports.deduplicateEndpoints = deduplicateEndpoints;
944
+ exports.dereferenceSchema = dereferenceSchema;
945
+ exports.endpointToMarkdown = endpointToMarkdown;
946
+ exports.findApiKeyById = findApiKeyById;
947
+ exports.formatBytes = formatBytes;
948
+ exports.isValidJson = isValidJson;
949
+ exports.joinUrl = joinUrl;
950
+ exports.parseRequestHeaders = parseRequestHeaders;
951
+ exports.relativePath = relativePath;
952
+ exports.renderSnippet = renderSnippet;
953
+ exports.resolveAbsolute = resolveAbsolute;
954
+ exports.resolveBaseUrl = resolveBaseUrl;
955
+ exports.sampleSchemaJson = sampleSchemaJson;
956
+ exports.toCompactJson = toCompactJson;
957
+ exports.toMarkdown = toMarkdown;
958
+ exports.toRawJson = toRawJson;
959
+ exports.usePlaygroundContext = usePlaygroundContext;
960
+ //# sourceMappingURL=chunk-QW4RBGHN.cjs.map
961
+ //# sourceMappingURL=chunk-QW4RBGHN.cjs.map