@wso2/am-core-ui 0.0.18 → 0.0.19

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 (45) hide show
  1. package/dist/APIKeysManager-C0phJriD.js +241 -0
  2. package/dist/CatalogKindListing-DtFI2YMG.js +118 -0
  3. package/dist/CodeBlock-mB_Loq7I.js +21736 -0
  4. package/dist/EnvironmentCard-09h1XRxx.js +310 -0
  5. package/dist/EnvironmentSelector-B7Bl93s2.js +48 -0
  6. package/dist/MCPLogo-D9IJzzl7.js +30 -0
  7. package/dist/PolicyListSection-o4k9e8XO.js +2475 -0
  8. package/dist/ResourceListShell-Cx6mdeqv.js +463 -0
  9. package/dist/SwaggerSpecViewer-BvkhoKsi.js +106 -0
  10. package/dist/clipboard-YAzStmkw.js +23 -0
  11. package/dist/debounce-BV83M53b.js +208 -0
  12. package/dist/format-BEZZRyE2.js +29 -0
  13. package/dist/formatDistanceToNow-TErllcH8.js +100 -0
  14. package/dist/gatewayScripts-D8O45W8u.js +72 -0
  15. package/dist/highlight-BsUzxSR3.js +454 -0
  16. package/dist/index-B52h3RHg.js +1290 -0
  17. package/dist/index-BP5drcF2.js +1265 -0
  18. package/dist/index-BZ4vxviI.js +7981 -0
  19. package/dist/index-B_Z0MwXk.js +25012 -0
  20. package/dist/index-BfjzUWDa.js +1397 -0
  21. package/dist/{index-DYV1jEai.js → index-BnV-PkwM.js} +22 -20
  22. package/dist/index-CGDYgUCH.js +711 -0
  23. package/dist/index-COt7nJIf.js +2286 -0
  24. package/dist/index-CWZjOy1h.js +2247 -0
  25. package/dist/index-CezvogTQ.js +116 -0
  26. package/dist/index-CgCWbWzN.js +2342 -0
  27. package/dist/index-CjCkcuuI.js +322 -0
  28. package/dist/index-CjXvuf9m.js +1354 -0
  29. package/dist/index-DD4qF7gq.js +2340 -0
  30. package/dist/index-DeQ-9KTC.js +737 -0
  31. package/dist/index-Df6OBy4E.js +3041 -0
  32. package/dist/index-KRsV2L4V.js +1564 -0
  33. package/dist/index-PUuASE1F.js +2507 -0
  34. package/dist/index-PWsNvJB-.js +546 -0
  35. package/dist/index-UqDmyMSA.js +119 -0
  36. package/dist/index-_0Pj_ZtW.js +459 -0
  37. package/dist/{index-CnXsN5I3.js → index-sr-mWz4T.js} +31 -30
  38. package/dist/index.d.ts +496 -200
  39. package/dist/index.js +462 -439
  40. package/dist/llmProviderPayload-CzihkdNa.js +332 -0
  41. package/dist/schemas-DFScWdSL.js +2969 -0
  42. package/package.json +1 -1
  43. package/dist/index-B47EJCom.js +0 -236
  44. package/dist/index-Bl1Y7Sro.js +0 -3037
  45. package/dist/index-DlS9Lybj.js +0 -80691
@@ -0,0 +1,2340 @@
1
+ import { jsxs as a, jsx as n, Fragment as qt } from "react/jsx-runtime";
2
+ import { c as Se } from "react/compiler-runtime";
3
+ import { useTheme as kt, Stack as E, Typography as $, Alert as ce, Card as Pe, Chip as ue, FormControl as ge, FormLabel as ve, TextField as Le, InputAdornment as ot, Tooltip as Ge, IconButton as Qe, Divider as $e, Box as se, Button as de, ListingTable as B, Avatar as Wt, TablePagination as ct, Skeleton as ee, Grid as D, Select as Xe, MenuItem as _e, Collapse as Ze, CircularProgress as Et, SearchBar as At, Accordion as je, AccordionSummary as Ue, AccordionDetails as Be, Tabs as Mt, Tab as at, ToggleButtonGroup as Ot, ToggleButton as yt, Paper as lt, Switch as _t } from "@wso2/oxygen-ui";
4
+ import { useState as N, useMemo as Q, useCallback as H, useEffect as oe, useRef as Ke, Suspense as Ft } from "react";
5
+ import { Copy as gt, Key as Gt, Trash as vt, ServerCog as bt, EyeOff as $t, Eye as jt, Users as Ut, ArrowRight as Bt, Plus as xt, ShieldAlert as Vt, Search as Kt, ChevronDown as Ve, Save as Ht, Download as Yt, FileCode as Jt, BrainCircuit as Qt } from "@wso2/oxygen-ui-icons-react";
6
+ import { useNavigate as dt, useParams as De, Link as Xt, generatePath as Ne, useSearchParams as Zt, Route as tt, Routes as Dt, Navigate as en } from "react-router-dom";
7
+ import { G as tn, b0 as nn, be as rn, a6 as ut, I as sn, g as ze, bf as on, bg as Nt, bh as an, bi as ln, bj as cn, bk as dn, p as zt, bl as un, bm as hn, bn as mn, P as ht, H as Fe, a_ as pn } from "./index-B_Z0MwXk.js";
8
+ import "@tanstack/react-query";
9
+ import { f as fn } from "./format-BEZZRyE2.js";
10
+ import { R as yn, A as gn } from "./ResourceListShell-Cx6mdeqv.js";
11
+ import { j as vn, a as bn } from "./PolicyListSection-o4k9e8XO.js";
12
+ import { i as xn, A as Cn } from "./APIKeysManager-C0phJriD.js";
13
+ import { s as pe, o as Re, c as mt, r as wn, e as Pn, b as Rt, _ as Ct } from "./schemas-DFScWdSL.js";
14
+ import { S as Ln } from "./SwaggerSpecViewer-BvkhoKsi.js";
15
+ import { m as Sn, b as In, A as kn } from "./llmProviderPayload-CzihkdNa.js";
16
+ import { t as Ir } from "./llmProviderPayload-CzihkdNa.js";
17
+ const nt = "__unassigned__";
18
+ function wt(t) {
19
+ return navigator.clipboard.writeText(t);
20
+ }
21
+ function En({
22
+ endpoints: t,
23
+ onGenerateApiKey: e,
24
+ isGeneratingApiKey: r,
25
+ apiKeyError: o,
26
+ generatedApiKey: i,
27
+ onClearApiKeyError: l,
28
+ emptyMessage: c = "No invoke URLs available. Deploy to an AI gateway to see invoke URLs and generate API keys."
29
+ }) {
30
+ const y = kt(), [d, u] = N(null), [L, v] = N(!1), P = Q(() => {
31
+ const h = /* @__PURE__ */ new Map();
32
+ for (const b of t) {
33
+ const s = b.environment, f = s?.id || s?.name || nt, M = h.get(f);
34
+ M ? M.endpoints.push(b) : h.set(f, {
35
+ key: f,
36
+ environment: s,
37
+ endpoints: [b]
38
+ });
39
+ }
40
+ return Array.from(h.values()).sort((b, s) => {
41
+ if (b.key === nt) return 1;
42
+ if (s.key === nt) return -1;
43
+ const f = b.environment?.isProduction ? 0 : 1, M = s.environment?.isProduction ? 0 : 1;
44
+ if (f !== M) return f - M;
45
+ const w = b.environment?.displayName || b.environment?.name || "", x = s.environment?.displayName || s.environment?.name || "";
46
+ return w.localeCompare(x);
47
+ });
48
+ }, [t]), S = H(async (h) => {
49
+ if (h.url)
50
+ try {
51
+ await wt(h.url), u(h.gatewayId), setTimeout(() => u(null), 2e3);
52
+ } catch {
53
+ }
54
+ }, []), I = H(async () => {
55
+ if (i)
56
+ try {
57
+ await wt(i), v(!0), setTimeout(() => v(!1), 2e3);
58
+ } catch {
59
+ }
60
+ }, [i]), p = {
61
+ "& .MuiInputBase-input": {
62
+ fontFamily: "monospace",
63
+ fontSize: y.typography.body2?.fontSize,
64
+ wordBreak: "break-all"
65
+ }
66
+ };
67
+ return /* @__PURE__ */ a(E, { spacing: 2.5, sx: {
68
+ width: "100%"
69
+ }, children: [
70
+ /* @__PURE__ */ n($, { variant: "subtitle2", color: "text.secondary", sx: {
71
+ fontWeight: 600
72
+ }, children: "Invoke URL & API Key" }),
73
+ t.length === 0 ? /* @__PURE__ */ n(ce, { severity: "info", children: c }) : /* @__PURE__ */ a(E, { spacing: 2, children: [
74
+ P.map((h) => {
75
+ const b = h.environment?.displayName || h.environment?.name, s = b ? /environment/i.test(b) ? b : `${b} Environment` : "Unassigned";
76
+ return /* @__PURE__ */ n(Pe, { variant: "outlined", sx: {
77
+ p: 2
78
+ }, children: /* @__PURE__ */ a(E, { spacing: 1.5, children: [
79
+ /* @__PURE__ */ a(E, { direction: "row", alignItems: "center", gap: 1, children: [
80
+ /* @__PURE__ */ n($, { variant: "body2", sx: {
81
+ fontWeight: 600
82
+ }, children: s }),
83
+ h.environment?.isProduction && /* @__PURE__ */ n(ue, { size: "small", variant: "outlined", color: "success", label: "Production" })
84
+ ] }),
85
+ h.endpoints.map((f) => /* @__PURE__ */ a(ge, { fullWidth: !0, size: "small", children: [
86
+ /* @__PURE__ */ n(ve, { sx: {
87
+ mb: 0.5
88
+ }, children: f.displayName || f.name || f.gatewayId }),
89
+ /* @__PURE__ */ n(Le, { size: "small", fullWidth: !0, value: f.url, slotProps: {
90
+ input: {
91
+ readOnly: !0,
92
+ endAdornment: /* @__PURE__ */ n(ot, { position: "end", children: /* @__PURE__ */ n(Ge, { title: d === f.gatewayId ? "Copied!" : "Copy", children: /* @__PURE__ */ n(Qe, { size: "small", onClick: () => S(f), "aria-label": "Copy Invoke URL", children: /* @__PURE__ */ n(gt, { size: 16 }) }) }) })
93
+ }
94
+ }, sx: p })
95
+ ] }, f.gatewayId))
96
+ ] }) }, h.key);
97
+ }),
98
+ /* @__PURE__ */ n($e, {}),
99
+ /* @__PURE__ */ n(Pe, { variant: "outlined", sx: {
100
+ p: 2
101
+ }, children: /* @__PURE__ */ a(E, { spacing: 1.5, children: [
102
+ /* @__PURE__ */ a(se, { children: [
103
+ /* @__PURE__ */ n($, { variant: "subtitle2", sx: {
104
+ fontWeight: 600
105
+ }, children: "Generate API Key" }),
106
+ /* @__PURE__ */ n($, { variant: "body2", color: "text.secondary", children: "One API key works across all environments above." })
107
+ ] }),
108
+ /* @__PURE__ */ n(se, { children: /* @__PURE__ */ n(de, { variant: "outlined", size: "medium", startIcon: /* @__PURE__ */ n(Gt, { size: 16 }), onClick: e, disabled: r, children: r ? "Generating..." : "Generate API Key" }) }),
109
+ o && /* @__PURE__ */ n(ce, { severity: "error", onClose: l, children: o }),
110
+ i && /* @__PURE__ */ a(ce, { severity: "success", sx: {
111
+ "& .MuiAlert-message": {
112
+ flexGrow: 1
113
+ }
114
+ }, children: [
115
+ /* @__PURE__ */ n($, { variant: "subtitle2", sx: {
116
+ mb: 0.5
117
+ }, children: "API Key Generated" }),
118
+ /* @__PURE__ */ n($, { variant: "body2", sx: {
119
+ mb: 1
120
+ }, children: "Copy this API key now. It will not be shown again." }),
121
+ /* @__PURE__ */ n(E, { direction: "row", spacing: 1, flexGrow: 1, alignItems: "center", children: /* @__PURE__ */ n(Le, { size: "small", fullWidth: !0, value: i, slotProps: {
122
+ input: {
123
+ readOnly: !0,
124
+ endAdornment: /* @__PURE__ */ n(ot, { position: "end", children: /* @__PURE__ */ n(Ge, { title: L ? "Copied!" : "Copy", children: /* @__PURE__ */ n(Qe, { size: "small", onClick: I, "aria-label": "Copy API Key", children: /* @__PURE__ */ n(gt, { size: 16 }) }) }) })
125
+ }
126
+ }, sx: p }) })
127
+ ] })
128
+ ] }) })
129
+ ] })
130
+ ] });
131
+ }
132
+ const Pt = () => {
133
+ const t = Se(1);
134
+ let e;
135
+ return t[0] === Symbol.for("react.memo_cache_sentinel") ? (e = /* @__PURE__ */ a(se, { sx: {
136
+ p: 3
137
+ }, children: [
138
+ /* @__PURE__ */ n($, { variant: "h5", gutterBottom: !0, children: "Component-level LLM Provider management" }),
139
+ /* @__PURE__ */ n($, { variant: "body1", color: "text.secondary", children: "This is an empty placeholder view for managing LLM providers at the component level." })
140
+ ] }), t[0] = e) : e = t[0], e;
141
+ };
142
+ function An() {
143
+ const t = dt(), {
144
+ orgId: e
145
+ } = De(), [r, o] = N(""), [i, l] = N(0), [c, y] = N(5), [d, u] = N(null), {
146
+ addConfirmation: L
147
+ } = tn(), {
148
+ data: v,
149
+ isLoading: P,
150
+ error: S
151
+ } = nn({
152
+ orgName: e
153
+ }), {
154
+ mutate: I
155
+ } = rn(), {
156
+ data: p
157
+ } = ut({
158
+ orgName: e
159
+ }), h = Q(() => p?.templates ? p.templates.reduce((w, x) => {
160
+ const U = x.metadata?.logoUrl;
161
+ return U && (w[x.id] = U), w;
162
+ }, {}) : {}, [p]), b = Q(() => p?.templates ? p.templates.reduce((w, x) => (x.name && (w[x.id] = x.name), w), {}) : {}, [p]), s = Q(() => v?.providers ?? [], [v]), f = Q(() => {
163
+ const w = r.trim().toLowerCase();
164
+ return w ? s.filter((x) => {
165
+ const U = x.name ?? x.displayName ?? "", _ = b[x.template] ?? x.template;
166
+ return [U, x.name, x.displayName, x.id, x.template, _, x.status ?? ""].filter(Boolean).join(" ").toLowerCase().includes(w);
167
+ }) : s;
168
+ }, [s, r, b]);
169
+ oe(() => {
170
+ i !== 0 && i * c >= f.length && l(0);
171
+ }, [f.length, i, c]);
172
+ const M = f.slice(i * c, i * c + c);
173
+ return /* @__PURE__ */ a(yn, { searchValue: r, onSearchChange: o, searchPlaceholder: "Search providers...", addButton: {
174
+ label: "Add Service Provider",
175
+ component: Xt,
176
+ to: Ne(ze.children.org.children.llmProviders.children.add.path, {
177
+ orgId: e
178
+ })
179
+ }, error: S, isLoading: P, isEmpty: !s.length, isSearchEmpty: !f.length, emptyState: {
180
+ illustration: /* @__PURE__ */ n(bt, { size: 64 }),
181
+ title: "No LLM service providers yet",
182
+ description: "Add an LLM service provider to start routing AI traffic through the gateway."
183
+ }, searchEmptyState: {
184
+ illustration: /* @__PURE__ */ n(bt, { size: 64 }),
185
+ title: "No providers match your search",
186
+ description: "Try a different keyword or clear the search filter."
187
+ }, children: [
188
+ /* @__PURE__ */ n(E, { children: /* @__PURE__ */ a(B, { variant: "card", children: [
189
+ /* @__PURE__ */ n(B.Head, { children: /* @__PURE__ */ a(B.Row, { children: [
190
+ /* @__PURE__ */ n(B.Cell, { width: "300px", children: "Name" }),
191
+ /* @__PURE__ */ n(B.Cell, { align: "left", width: "120px", children: "Template" }),
192
+ /* @__PURE__ */ n(B.Cell, { width: "140px", align: "right", children: "Last Updated" })
193
+ ] }) }),
194
+ /* @__PURE__ */ n(B.Body, { children: M.map((w) => {
195
+ const x = w.name ?? w.displayName ?? w.uuid, U = b[w.template] ?? w.template;
196
+ return /* @__PURE__ */ a(B.Row, { variant: "card", hover: !0, clickable: !0, onClick: () => t(Ne(ze.children.org.children.llmProviders.children.view.path, {
197
+ orgId: e,
198
+ providerId: w.uuid
199
+ })), onMouseEnter: () => u(w.uuid), onMouseLeave: () => u(null), onFocus: () => u(w.uuid), onBlur: () => u(null), children: [
200
+ /* @__PURE__ */ n(B.Cell, { children: /* @__PURE__ */ a(E, { direction: "row", alignItems: "center", spacing: 2, children: [
201
+ /* @__PURE__ */ n(Wt, { sx: {
202
+ bgcolor: "primary.main",
203
+ color: "primary.contrastText",
204
+ fontSize: 16,
205
+ height: 36,
206
+ width: 36,
207
+ flexShrink: 0
208
+ }, children: x.charAt(0).toUpperCase() }),
209
+ /* @__PURE__ */ n($, { variant: "body2", fontWeight: 500, children: x })
210
+ ] }) }),
211
+ /* @__PURE__ */ n(B.Cell, { align: "left", children: /* @__PURE__ */ n(ue, { label: U, size: "small", icon: h[w.template] ? /* @__PURE__ */ n(se, { component: "img", src: h[w.template], alt: w.template, sx: {
212
+ width: 14,
213
+ height: 14,
214
+ objectFit: "contain",
215
+ bgcolor: "grey.200",
216
+ flexShrink: 0,
217
+ borderRadius: 1
218
+ } }) : void 0, variant: "outlined", sx: {
219
+ maxWidth: 130
220
+ } }) }),
221
+ /* @__PURE__ */ n(B.Cell, { align: "right", onClick: (_) => _.stopPropagation(), children: /* @__PURE__ */ n(E, { direction: "row", alignItems: "center", spacing: 1, justifyContent: "flex-end", children: d === w.uuid ? /* @__PURE__ */ n(sn, { children: /* @__PURE__ */ n(Ge, { title: "Delete provider", children: /* @__PURE__ */ n(Qe, { color: "error", size: "small", onClick: () => L({
222
+ title: "Delete LLM Provider",
223
+ description: "Are you sure you want to delete this provider? This action cannot be undone.",
224
+ confirmButtonText: "Delete",
225
+ confirmButtonColor: "error",
226
+ confirmButtonIcon: /* @__PURE__ */ n(vt, { size: 16 }),
227
+ onConfirm: () => I({
228
+ orgName: e,
229
+ providerId: w.uuid
230
+ })
231
+ }), children: /* @__PURE__ */ n(vt, { size: 16 }) }) }) }) : w.createdAt ? /* @__PURE__ */ n($, { variant: "caption", color: "text.secondary", children: fn(w.createdAt) }) : null }) })
232
+ ] }, w.uuid);
233
+ }) })
234
+ ] }) }),
235
+ f.length > 5 && /* @__PURE__ */ n(ct, { component: "div", count: f.length, page: i, rowsPerPage: c, onPageChange: (w, x) => l(x), onRowsPerPageChange: (w) => {
236
+ y(parseInt(w.target.value, 10)), l(0);
237
+ }, rowsPerPageOptions: [5, 10, 25] })
238
+ ] });
239
+ }
240
+ const Lt = /* @__PURE__ */ new Map();
241
+ function pt(t, e) {
242
+ const r = Se(12), [o, i] = N(e ?? ""), [l, c] = N(!1), [y, d] = N(null);
243
+ let u, L;
244
+ r[0] !== e ? (u = () => {
245
+ i(e ?? "");
246
+ }, L = [e], r[0] = e, r[1] = u, r[2] = L) : (u = r[1], L = r[2]), oe(u, L);
247
+ let v, P;
248
+ r[3] !== e || r[4] !== t ? (v = () => {
249
+ if (!t || (e ?? "").trim())
250
+ return;
251
+ const h = Lt.get(t);
252
+ if (h) {
253
+ i(h);
254
+ return;
255
+ }
256
+ const b = new AbortController();
257
+ return c(!0), d(null), fetch(t, {
258
+ signal: b.signal
259
+ }).then(Mn).then((s) => {
260
+ Lt.set(t, s), i(s);
261
+ }).catch((s) => {
262
+ s?.name !== "AbortError" && d(s instanceof Error ? s : new Error(String(s)));
263
+ }).finally(() => c(!1)), () => b.abort();
264
+ }, P = [t, e], r[3] = e, r[4] = t, r[5] = v, r[6] = P) : (v = r[5], P = r[6]), oe(v, P);
265
+ let S;
266
+ r[7] === Symbol.for("react.memo_cache_sentinel") ? (S = (h) => {
267
+ i(h);
268
+ }, r[7] = S) : S = r[7];
269
+ const I = S;
270
+ let p;
271
+ return r[8] !== y || r[9] !== l || r[10] !== o ? (p = {
272
+ text: o,
273
+ setText: I,
274
+ isLoading: l,
275
+ error: y
276
+ }, r[8] = y, r[9] = l, r[10] = o, r[11] = p) : p = r[11], p;
277
+ }
278
+ function Mn(t) {
279
+ if (!t.ok)
280
+ throw new Error(`Failed to fetch: ${t.status} ${t.statusText}`);
281
+ return t.text();
282
+ }
283
+ const Kn = /* @__PURE__ */ new Set(["get", "post", "put", "delete", "patch", "head", "options", "trace"]);
284
+ function He(t) {
285
+ if (!t?.trim()) return null;
286
+ try {
287
+ const e = JSON.parse(t);
288
+ return e && typeof e == "object" ? e : null;
289
+ } catch {
290
+ try {
291
+ const e = vn.load(t);
292
+ return e && typeof e == "object" ? e : null;
293
+ } catch {
294
+ return null;
295
+ }
296
+ }
297
+ }
298
+ function ft(t) {
299
+ const e = t?.paths;
300
+ if (!e || typeof e != "object") return [];
301
+ const r = [];
302
+ for (const o of Object.keys(e)) {
303
+ const i = e[o];
304
+ if (!(!i || typeof i != "object"))
305
+ for (const l of Object.keys(i)) {
306
+ if (!Kn.has(l.toLowerCase())) continue;
307
+ const c = i[l] || {};
308
+ r.push({
309
+ method: l.toUpperCase(),
310
+ path: o,
311
+ summary: c?.summary || c?.description
312
+ });
313
+ }
314
+ }
315
+ return r.sort((o, i) => {
316
+ const l = o.path.localeCompare(i.path);
317
+ return l !== 0 ? l : o.method.localeCompare(i.method);
318
+ }), r;
319
+ }
320
+ function Oe(t, e = "::") {
321
+ return `${t.method}${e}${t.path}`;
322
+ }
323
+ function Tt(t) {
324
+ const e = t.toUpperCase();
325
+ return e === "GET" ? "info" : e === "POST" ? "success" : e === "DELETE" ? "error" : "default";
326
+ }
327
+ function Nn(t, e, r) {
328
+ const o = e.toLowerCase(), l = t.paths?.[r], c = l?.[o];
329
+ if (!c) return null;
330
+ const y = {
331
+ [o]: c
332
+ };
333
+ return ["parameters", "servers", "summary", "description"].forEach((u) => {
334
+ l?.[u] !== void 0 && (y[u] = l[u]);
335
+ }), {
336
+ ...t.openapi ? {
337
+ openapi: t.openapi
338
+ } : {},
339
+ ...t.swagger ? {
340
+ swagger: t.swagger
341
+ } : {},
342
+ ...t.info ? {
343
+ info: t.info
344
+ } : {},
345
+ ...t.servers ? {
346
+ servers: t.servers
347
+ } : {},
348
+ ...t.components ? {
349
+ components: t.components
350
+ } : {},
351
+ ...t.security ? {
352
+ security: t.security
353
+ } : {},
354
+ ...t.tags ? {
355
+ tags: t.tags
356
+ } : {},
357
+ ...t.basePath ? {
358
+ basePath: t.basePath
359
+ } : {},
360
+ ...t.host ? {
361
+ host: t.host
362
+ } : {},
363
+ ...t.schemes ? {
364
+ schemes: t.schemes
365
+ } : {},
366
+ ...t.consumes ? {
367
+ consumes: t.consumes
368
+ } : {},
369
+ ...t.produces ? {
370
+ produces: t.produces
371
+ } : {},
372
+ ...t.definitions ? {
373
+ definitions: t.definitions
374
+ } : {},
375
+ ...t.securityDefinitions ? {
376
+ securityDefinitions: t.securityDefinitions
377
+ } : {},
378
+ paths: {
379
+ [r]: y
380
+ }
381
+ };
382
+ }
383
+ function zn({
384
+ providerData: t,
385
+ openapiSpecUrl: e,
386
+ isLoading: r = !1,
387
+ onUpdate: o,
388
+ isUpdating: i
389
+ }) {
390
+ const l = Ke(null), [c, y] = N("allow"), [d, u] = N([]), L = t?.openapi?.trim() ?? "", {
391
+ text: v,
392
+ setText: P,
393
+ isLoading: S,
394
+ error: I
395
+ } = pt(e, L), [p, h] = N(null);
396
+ oe(() => {
397
+ I && h({
398
+ message: "Failed to load OpenAPI spec.",
399
+ severity: "error"
400
+ });
401
+ }, [I]), oe(() => {
402
+ if (!t) return;
403
+ const C = String(t.accessControl?.mode || "").toLowerCase().replace(/-/g, "_") === "deny_all" ? "deny" : "allow", g = t.openapi?.trim() ?? "", A = (t.accessControl?.exceptions || []).flatMap((T) => (T.methods ?? ["GET"]).map((Y) => ({
404
+ method: Y,
405
+ path: T.path ?? ""
406
+ }))).map((T) => Oe(T));
407
+ y(C), u(A), l.current = {
408
+ mode: C,
409
+ exceptionKeys: A,
410
+ openapi: g
411
+ };
412
+ }, [t]);
413
+ const b = H((K) => {
414
+ if (!K.trim()) return [];
415
+ const C = He(K);
416
+ return C ? ft(C) : [];
417
+ }, []), s = Q(() => b(v).map((C) => ({
418
+ ...C,
419
+ method: C.method.toUpperCase()
420
+ })), [v, b]), f = Q(() => He(v), [v]), M = Q(() => s.map((K) => {
421
+ const C = f ? Nn(f, K.method, K.path) : null;
422
+ return {
423
+ key: Oe(K),
424
+ method: K.method,
425
+ path: K.path,
426
+ summary: K.summary,
427
+ operationSpec: C
428
+ };
429
+ }), [s, f]), w = Q(() => {
430
+ const K = l.current;
431
+ if (!K) return !1;
432
+ const C = [...d].sort().join("\0"), g = [...K.exceptionKeys].sort().join("\0");
433
+ return c !== K.mode || C !== g || v !== K.openapi;
434
+ }, [c, d, v]), x = H(async () => {
435
+ if (!t) return;
436
+ const K = c === "allow" ? "allow_all" : "deny_all", C = /* @__PURE__ */ new Map();
437
+ s.forEach((O) => C.set(Oe(O), O));
438
+ const g = /* @__PURE__ */ new Map();
439
+ for (const O of d) {
440
+ const A = C.get(O);
441
+ if (!A) continue;
442
+ const T = A.path ?? "", Y = g.get(T) ?? [];
443
+ Y.includes(A.method) || Y.push(A.method), g.set(T, Y);
444
+ }
445
+ const F = Array.from(g.entries()).map(([O, A]) => ({
446
+ path: O,
447
+ methods: A
448
+ }));
449
+ try {
450
+ await o({
451
+ accessControl: {
452
+ mode: K,
453
+ exceptions: F
454
+ }
455
+ }), l.current = {
456
+ mode: c,
457
+ exceptionKeys: [...d],
458
+ openapi: v
459
+ }, h({
460
+ message: "Access control updated successfully.",
461
+ severity: "success"
462
+ });
463
+ } catch {
464
+ h({
465
+ message: "Failed to update access control.",
466
+ severity: "error"
467
+ });
468
+ }
469
+ }, [t, c, d, s, v, o]), U = H(async (K) => {
470
+ try {
471
+ const C = await K.text();
472
+ if (!b(C).length) {
473
+ h({
474
+ message: "No resources found in specification.",
475
+ severity: "error"
476
+ });
477
+ return;
478
+ }
479
+ P(C), h({
480
+ message: "Specification imported. Click Save to apply.",
481
+ severity: "success"
482
+ });
483
+ } catch {
484
+ h({
485
+ message: "Failed to import specification.",
486
+ severity: "error"
487
+ });
488
+ }
489
+ }, [b, P]), _ = H(() => {
490
+ const K = l.current;
491
+ if (K)
492
+ y(K.mode), u([...K.exceptionKeys]), P(K.openapi);
493
+ else if (t) {
494
+ const g = String(t.accessControl?.mode || "").toLowerCase().replace(/-/g, "_") === "deny_all" ? "deny" : "allow", O = (t.accessControl?.exceptions || []).flatMap((A) => (A.methods ?? ["GET"]).map((T) => ({
495
+ method: T,
496
+ path: A.path ?? ""
497
+ })));
498
+ y(g), u(O.map((A) => Oe(A))), P(t.openapi?.trim() ?? "");
499
+ }
500
+ h(null);
501
+ }, [t, P]);
502
+ return !r && !S && !t ? null : /* @__PURE__ */ n(gn, { items: M, mode: c, onModeChange: y, exceptionKeys: d, onExceptionKeysChange: u, isLoading: r || S, isSaving: i, isDirty: w, onSave: () => void x(), onDiscard: _, status: p, onClearStatus: () => h(null), showImportButton: !0, onImportSpec: U, availableEmptyTitle: "No available resources", availableEmptyDescription: "Import a specification or use a template with OpenAPI to see resources here." });
503
+ }
504
+ function Rn(t) {
505
+ const e = Se(24), {
506
+ providerData: r,
507
+ orgName: o,
508
+ providerId: i,
509
+ isLoading: l,
510
+ error: c
511
+ } = t, y = l === void 0 ? !1 : l, d = c === void 0 ? null : c, u = xn(r?.security), L = u ? o : void 0, v = u ? i : void 0;
512
+ let P;
513
+ e[0] !== L || e[1] !== v ? (P = {
514
+ orgName: L,
515
+ providerId: v
516
+ }, e[0] = L, e[1] = v, e[2] = P) : P = e[2];
517
+ const {
518
+ data: S,
519
+ isLoading: I,
520
+ isError: p
521
+ } = on(P), {
522
+ mutateAsync: h,
523
+ isPending: b
524
+ } = Nt(), {
525
+ mutate: s,
526
+ isPending: f
527
+ } = an();
528
+ let M;
529
+ e[3] !== h || e[4] !== o || e[5] !== r?.id || e[6] !== i ? (M = async (C) => {
530
+ const {
531
+ displayName: g,
532
+ expiresAt: F
533
+ } = C;
534
+ if (!o || !i)
535
+ return;
536
+ const O = Math.random().toString(36).slice(2, 10), A = `provider-${r?.id ?? i}-${O}`;
537
+ return (await h({
538
+ params: {
539
+ orgName: o,
540
+ providerId: i
541
+ },
542
+ body: {
543
+ name: A,
544
+ displayName: g,
545
+ expiresAt: F
546
+ }
547
+ })).apiKey;
548
+ }, e[3] = h, e[4] = o, e[5] = r?.id, e[6] = i, e[7] = M) : M = e[7];
549
+ const w = M;
550
+ let x;
551
+ e[8] !== o || e[9] !== i || e[10] !== s ? (x = (C) => {
552
+ !o || !i || s({
553
+ orgName: o,
554
+ providerId: i,
555
+ keyName: C
556
+ });
557
+ }, e[8] = o, e[9] = i, e[10] = s, e[11] = x) : x = e[11];
558
+ const U = x;
559
+ if (y) {
560
+ let C;
561
+ return e[12] === Symbol.for("react.memo_cache_sentinel") ? (C = /* @__PURE__ */ n(ee, { variant: "rectangular", width: "100%", height: 200 }), e[12] = C) : C = e[12], C;
562
+ }
563
+ if (d) {
564
+ const C = d.message || "Failed to load the LLM provider.";
565
+ let g;
566
+ return e[13] !== C ? (g = /* @__PURE__ */ n(ce, { severity: "error", children: C }), e[13] = C, e[14] = g) : g = e[14], g;
567
+ }
568
+ if (!r)
569
+ return null;
570
+ if (!u) {
571
+ let C;
572
+ return e[15] === Symbol.for("react.memo_cache_sentinel") ? (C = /* @__PURE__ */ n(ce, { severity: "info", children: "Enable API key authentication from the Security tab to manage API keys." }), e[15] = C) : C = e[15], C;
573
+ }
574
+ const _ = S?.keys;
575
+ let K;
576
+ return e[16] !== w || e[17] !== U || e[18] !== b || e[19] !== p || e[20] !== I || e[21] !== f || e[22] !== _ ? (K = /* @__PURE__ */ n(Cn, { keys: _, isLoading: I, isError: p, isCreating: b, isRevoking: f, emptyDescription: "Create an API key to authenticate requests to this LLM provider.", onCreate: w, onRevoke: U }), e[16] = w, e[17] = U, e[18] = b, e[19] = p, e[20] = I, e[21] = f, e[22] = _, e[23] = K) : K = e[23], K;
577
+ }
578
+ const Te = "••••••••••••", Tn = pe().min(1, "Provider Endpoint is required").url("Please enter a valid URL"), Me = "api-key", qn = [{
579
+ value: "api-key",
580
+ label: "API Key"
581
+ }, {
582
+ value: "bearer",
583
+ label: "Bearer"
584
+ }, {
585
+ value: "basic",
586
+ label: "Basic"
587
+ }, {
588
+ value: "none",
589
+ label: "None"
590
+ }];
591
+ function Wn({
592
+ providerData: t,
593
+ valuePrefix: e = "",
594
+ isLoading: r = !1,
595
+ onUpdate: o,
596
+ isUpdating: i
597
+ }) {
598
+ const l = Ke(null), c = Ke(!1), [y, d] = N(""), [u, L] = N(Me), [v, P] = N(""), [S, I] = N(""), [p, h] = N(!1), [b, s] = N(!1), [f, M] = N(null), [w, x] = N(null);
599
+ oe(() => {
600
+ if (!t) return;
601
+ const g = t.uuid;
602
+ l.current !== g && (l.current = g, d(t.upstream?.main?.url ?? ""), L(t.upstream?.main?.auth?.type ?? Me), P(t.upstream?.main?.auth?.header ?? ""), I(Te), h(!0), x(null));
603
+ }, [t]);
604
+ const U = Q(() => {
605
+ if (!t) return !1;
606
+ const g = t.upstream?.main, F = (g?.url ?? "").trim(), O = g?.auth?.type ?? Me, A = (g?.auth?.header ?? "").trim();
607
+ return y.trim() !== F || (u || Me) !== O || v.trim() !== A || !p && S.trim() !== Te;
608
+ }, [t, y, u, v, S, p]), _ = H((g) => {
609
+ const F = Tn.safeParse(g.trim());
610
+ if (F.success)
611
+ return x(null), null;
612
+ const O = F.error.flatten().formErrors[0] ?? "Invalid URL";
613
+ return x(O), O;
614
+ }, []), K = H(() => {
615
+ t && (d(t.upstream?.main?.url ?? ""), L(t.upstream?.main?.auth?.type ?? Me), P(t.upstream?.main?.auth?.header ?? ""), I(Te), h(!0), x(null), M(null));
616
+ }, [t]), C = H(async () => {
617
+ if (!t) return;
618
+ const g = y.trim(), F = _(y);
619
+ if (F) {
620
+ M({
621
+ message: F,
622
+ severity: "error"
623
+ });
624
+ return;
625
+ }
626
+ let O = t.upstream?.main?.auth?.value ?? "";
627
+ if (!p && S.trim() !== Te)
628
+ if (S.trim() === "" && !c.current)
629
+ O = t.upstream?.main?.auth?.value ?? "";
630
+ else {
631
+ const T = S.trim();
632
+ O = e ? T.startsWith(e) ? T : `${e}${T}` : T;
633
+ }
634
+ const A = u === "none" ? {
635
+ type: "none",
636
+ header: "",
637
+ value: ""
638
+ } : {
639
+ type: u || Me,
640
+ header: v.trim() || "",
641
+ value: O
642
+ };
643
+ try {
644
+ await o({
645
+ upstream: {
646
+ main: {
647
+ url: g,
648
+ auth: A
649
+ }
650
+ }
651
+ }), M({
652
+ message: "Connection updated successfully.",
653
+ severity: "success"
654
+ }), !p && S.trim() !== Te && (I(Te), h(!0));
655
+ } catch {
656
+ M({
657
+ message: "Failed to update connection.",
658
+ severity: "error"
659
+ });
660
+ }
661
+ }, [t, y, u, v, S, e, p, o, _]);
662
+ return r ? /* @__PURE__ */ n(E, { spacing: 2, children: /* @__PURE__ */ n(E, { spacing: 2, children: [1, 2, 3, 4].map((g) => /* @__PURE__ */ a(E, { spacing: 0.5, children: [
663
+ /* @__PURE__ */ n(ee, { variant: "text", width: 120, height: 16 }),
664
+ /* @__PURE__ */ n(ee, { variant: "rounded", height: 40 })
665
+ ] }, g)) }) }) : t ? /* @__PURE__ */ n(qt, { children: /* @__PURE__ */ n(E, { spacing: 2, children: /* @__PURE__ */ a(D, { container: !0, spacing: 3, children: [
666
+ /* @__PURE__ */ n(D, { size: {
667
+ xs: 12
668
+ }, children: /* @__PURE__ */ a(ge, { fullWidth: !0, children: [
669
+ /* @__PURE__ */ n(ve, { children: "Provider Endpoint" }),
670
+ /* @__PURE__ */ n(Le, { size: "small", value: y, onChange: (g) => {
671
+ d(g.target.value), w && _(g.target.value);
672
+ }, onBlur: () => _(y), error: !!w, helperText: w, sx: {
673
+ "& .MuiInputBase-input": {
674
+ fontFamily: "monospace",
675
+ fontSize: "0.875rem"
676
+ }
677
+ } })
678
+ ] }) }),
679
+ /* @__PURE__ */ n(D, { size: {
680
+ xs: 12,
681
+ sm: 6
682
+ }, children: /* @__PURE__ */ a(ge, { fullWidth: !0, children: [
683
+ /* @__PURE__ */ n(ve, { children: "Authentication" }),
684
+ /* @__PURE__ */ n(Xe, { size: "small", value: u || Me, onChange: (g) => L(g.target.value), children: qn.map((g) => /* @__PURE__ */ n(_e, { value: g.value, children: g.label }, g.value)) })
685
+ ] }) }),
686
+ /* @__PURE__ */ n(D, { size: {
687
+ xs: 12,
688
+ sm: 6
689
+ }, children: /* @__PURE__ */ a(ge, { fullWidth: !0, children: [
690
+ /* @__PURE__ */ n(ve, { children: "Authentication Header" }),
691
+ /* @__PURE__ */ n(Le, { size: "small", value: v, onChange: (g) => P(g.target.value) })
692
+ ] }) }),
693
+ /* @__PURE__ */ n(D, { size: {
694
+ xs: 12
695
+ }, children: /* @__PURE__ */ a(ge, { fullWidth: !0, children: [
696
+ /* @__PURE__ */ n(ve, { children: "Credentials" }),
697
+ /* @__PURE__ */ n(Le, { size: "small", type: b ? "text" : "password", value: S, onFocus: () => {
698
+ p && (I(""), h(!1), c.current = !1);
699
+ }, onChange: (g) => {
700
+ c.current = !0, I(g.target.value);
701
+ }, slotProps: {
702
+ input: {
703
+ endAdornment: /* @__PURE__ */ n(ot, { position: "end", children: /* @__PURE__ */ n(Qe, { size: "small", onClick: () => s((g) => !g), "aria-label": b ? "Hide credentials" : "Show credentials", children: b ? /* @__PURE__ */ n($t, { size: 18 }) : /* @__PURE__ */ n(jt, { size: 18 }) }) })
704
+ }
705
+ }, sx: {
706
+ "& .MuiInputBase-input": {
707
+ fontFamily: "monospace"
708
+ }
709
+ } })
710
+ ] }) }),
711
+ /* @__PURE__ */ n(D, { size: {
712
+ xs: 12
713
+ }, children: /* @__PURE__ */ a(E, { spacing: 1.5, width: "100%", children: [
714
+ /* @__PURE__ */ n(Ze, { in: !!f, timeout: 300, children: f && /* @__PURE__ */ n(ce, { severity: f.severity, onClose: () => M(null), sx: {
715
+ width: "100%"
716
+ }, children: f.message }) }),
717
+ /* @__PURE__ */ a(E, { direction: "row", spacing: 1.5, justifyContent: "flex-end", children: [
718
+ /* @__PURE__ */ n(de, { variant: "outlined", onClick: K, disabled: !U || i, children: "Discard" }),
719
+ /* @__PURE__ */ n(de, { variant: "contained", onClick: () => void C(), disabled: i || !U || !!w, children: i ? "Saving..." : "Save" })
720
+ ] })
721
+ ] }) })
722
+ ] }) }) }) : null;
723
+ }
724
+ function On(t, e) {
725
+ if (e.consumerType === "agent")
726
+ return Ne(ze.children.org.children.projects.children.agents.children.configure.path, {
727
+ orgId: t,
728
+ projectId: e.projectName,
729
+ agentId: e.consumerName
730
+ });
731
+ }
732
+ const _n = (t) => {
733
+ const e = Se(19), {
734
+ orgName: r,
735
+ providerId: o
736
+ } = t, i = dt();
737
+ let l;
738
+ e[0] !== r || e[1] !== o ? (l = {
739
+ orgName: r,
740
+ providerId: o
741
+ }, e[0] = r, e[1] = o, e[2] = l) : l = e[2];
742
+ const {
743
+ data: c,
744
+ isLoading: y,
745
+ error: d
746
+ } = ln(l);
747
+ if (y) {
748
+ let p;
749
+ return e[3] === Symbol.for("react.memo_cache_sentinel") ? (p = /* @__PURE__ */ n(se, { sx: {
750
+ display: "flex",
751
+ justifyContent: "center",
752
+ py: 6
753
+ }, children: /* @__PURE__ */ n(Et, {}) }), e[3] = p) : p = e[3], p;
754
+ }
755
+ if (d) {
756
+ let p;
757
+ return e[4] === Symbol.for("react.memo_cache_sentinel") ? (p = /* @__PURE__ */ n(ce, { severity: "error", sx: {
758
+ mt: 2
759
+ }, children: "Failed to load consumers." }), e[4] = p) : p = e[4], p;
760
+ }
761
+ let u;
762
+ e[5] !== c?.consumers ? (u = c?.consumers ?? [], e[5] = c?.consumers, e[6] = u) : u = e[6];
763
+ const L = u;
764
+ if (L.length === 0) {
765
+ let p;
766
+ return e[7] === Symbol.for("react.memo_cache_sentinel") ? (p = /* @__PURE__ */ n(B.Container, { children: /* @__PURE__ */ n(B.EmptyState, { illustration: /* @__PURE__ */ n(Ut, { size: 64 }), title: "No consumers yet", description: "Agents and monitors that use an LLM proxy pointing to this provider will appear here." }) }), e[7] = p) : p = e[7], p;
767
+ }
768
+ let v;
769
+ e[8] === Symbol.for("react.memo_cache_sentinel") ? (v = {
770
+ pt: 2
771
+ }, e[8] = v) : v = e[8];
772
+ let P;
773
+ e[9] === Symbol.for("react.memo_cache_sentinel") ? (P = /* @__PURE__ */ n(B.Head, { children: /* @__PURE__ */ a(B.Row, { children: [
774
+ /* @__PURE__ */ n(B.Cell, { children: "Name" }),
775
+ /* @__PURE__ */ n(B.Cell, { children: "Type" }),
776
+ /* @__PURE__ */ n(B.Cell, { children: "Project" }),
777
+ /* @__PURE__ */ n(B.Cell, { width: "140px" })
778
+ ] }) }), e[9] = P) : P = e[9];
779
+ let S;
780
+ if (e[10] !== L || e[11] !== i || e[12] !== r) {
781
+ let p;
782
+ e[14] !== i || e[15] !== r ? (p = (h, b) => {
783
+ const s = r ? On(r, h) : void 0;
784
+ return /* @__PURE__ */ a(B.Row, { hover: !0, sx: {
785
+ "& .row-action": {
786
+ visibility: "hidden"
787
+ },
788
+ "&:hover .row-action, &:focus-within .row-action": {
789
+ visibility: "visible"
790
+ }
791
+ }, children: [
792
+ /* @__PURE__ */ n(B.Cell, { children: /* @__PURE__ */ n($, { variant: "body2", sx: {
793
+ fontWeight: 500
794
+ }, children: h.consumerName }) }),
795
+ /* @__PURE__ */ n(B.Cell, { children: h.consumerType === "agent" ? /* @__PURE__ */ n(ue, { label: "Agent", size: "small", variant: "outlined", color: "primary" }) : /* @__PURE__ */ n(ue, { label: "Monitor", size: "small", variant: "outlined", color: "default" }) }),
796
+ /* @__PURE__ */ n(B.Cell, { children: /* @__PURE__ */ n($, { variant: "body2", color: "text.secondary", children: h.projectName }) }),
797
+ /* @__PURE__ */ n(B.Cell, { align: "right", padding: "none", sx: {
798
+ pr: 1.5
799
+ }, children: s && /* @__PURE__ */ n(de, { className: "row-action", variant: "outlined", size: "small", endIcon: /* @__PURE__ */ n(Bt, { size: 14 }), onClick: () => i(s), "aria-label": `Go to ${h.consumerType} ${h.consumerName}`, sx: {
800
+ minWidth: 120
801
+ }, children: `Go to ${h.consumerType}` }) })
802
+ ] }, b);
803
+ }, e[14] = i, e[15] = r, e[16] = p) : p = e[16], S = L.map(p), e[10] = L, e[11] = i, e[12] = r, e[13] = S;
804
+ } else
805
+ S = e[13];
806
+ let I;
807
+ return e[17] !== S ? (I = /* @__PURE__ */ n(se, { sx: v, children: /* @__PURE__ */ a(B, { children: [
808
+ P,
809
+ /* @__PURE__ */ n(B.Body, { children: S })
810
+ ] }) }), e[17] = S, e[18] = I) : I = e[18], I;
811
+ }, Fn = Re({
812
+ path: pe(),
813
+ methods: mt(pe()),
814
+ params: wn(pe(), Pn()).optional()
815
+ }), Gn = Re({
816
+ name: pe().min(1),
817
+ version: pe().min(1),
818
+ paths: mt(Fn).optional()
819
+ }), $n = Re({
820
+ policies: mt(Gn)
821
+ });
822
+ function rt(t) {
823
+ return t.path === "/*" && (t.methods?.includes("*") ?? !1);
824
+ }
825
+ function St(t, e, r) {
826
+ return t.path !== e ? !1 : (t.methods ?? []).some((i) => i.toUpperCase() === r.toUpperCase());
827
+ }
828
+ function jn(t, e) {
829
+ const r = [...e.methods ?? []].sort();
830
+ return t.some((o) => {
831
+ if (o.path !== e.path) return !1;
832
+ const i = [...o.methods ?? []].sort();
833
+ return i.length === r.length && i.every((l, c) => l === r[c]);
834
+ });
835
+ }
836
+ function Un({
837
+ providerData: t,
838
+ openapiSpecUrl: e,
839
+ isLoading: r = !1,
840
+ error: o = null,
841
+ onUpdate: i,
842
+ isUpdating: l
843
+ }) {
844
+ const {
845
+ data: c
846
+ } = cn(), y = Q(() => c?.data ?? [], [c]), [d, u] = N(null), L = t?.openapi?.trim() ?? "", {
847
+ text: v,
848
+ isLoading: P,
849
+ error: S
850
+ } = pt(e, L), [I, p] = N(!1), [h, b] = N(null), [s, f] = N(null), [M, w] = N(/* @__PURE__ */ new Set()), [x, U] = N(0), [_, K] = N(""), C = 10, g = Q(() => t?.policies ?? [], [t?.policies]), [F, O] = N([]), A = Ke(JSON.stringify(g));
851
+ oe(() => {
852
+ O(g), A.current = JSON.stringify(g);
853
+ }, [g]);
854
+ const T = F;
855
+ oe(() => {
856
+ S && u({
857
+ message: "Failed to load OpenAPI spec.",
858
+ severity: "error"
859
+ });
860
+ }, [S]);
861
+ const Y = Q(() => {
862
+ if (!v.trim()) return [];
863
+ const m = He(v);
864
+ return m ? ft(m) : [];
865
+ }, [v]);
866
+ oe(() => {
867
+ U(0);
868
+ }, [Y]), oe(() => {
869
+ U(0);
870
+ }, [_]);
871
+ const ae = Q(() => {
872
+ const m = [];
873
+ return T.forEach((G, k) => {
874
+ (G.paths ?? []).forEach((z, R) => {
875
+ rt(z) && m.push({
876
+ policyIndex: k,
877
+ pathIndex: R,
878
+ policy: G,
879
+ path: z
880
+ });
881
+ });
882
+ }), m;
883
+ }, [T]), q = H((m) => {
884
+ const G = [];
885
+ return T.forEach((k, z) => {
886
+ (k.paths ?? []).forEach((R, W) => {
887
+ St(R, m.path, m.method) && G.push({
888
+ policyIndex: z,
889
+ pathIndex: W,
890
+ policy: k,
891
+ path: R
892
+ });
893
+ });
894
+ }), G;
895
+ }, [T]), V = Q(() => A.current === null ? !1 : JSON.stringify(F) !== A.current, [F]), X = H(async () => {
896
+ const m = $n.safeParse({
897
+ policies: F
898
+ });
899
+ if (!m.success) {
900
+ const G = m.error.issues[0];
901
+ u({
902
+ message: G?.message ?? "Validation failed",
903
+ severity: "error"
904
+ });
905
+ return;
906
+ }
907
+ try {
908
+ const G = m.data.policies.map((k) => ({
909
+ ...k,
910
+ paths: k.paths ?? []
911
+ }));
912
+ await i({
913
+ policies: G
914
+ }), A.current = JSON.stringify(F), u({
915
+ message: "Guardrails saved successfully.",
916
+ severity: "success"
917
+ });
918
+ } catch {
919
+ u({
920
+ message: "Failed to save guardrails.",
921
+ severity: "error"
922
+ });
923
+ }
924
+ }, [F, i]), J = H(() => {
925
+ O(g), A.current = JSON.stringify(g), u(null);
926
+ }, [g]), he = H((m, G) => {
927
+ if (!h) return;
928
+ const k = G ?? {}, z = h.type === "global" ? {
929
+ path: "/*",
930
+ methods: ["*"],
931
+ params: k
932
+ } : {
933
+ path: h.path,
934
+ methods: [h.method],
935
+ params: k
936
+ }, R = T.find((j) => j.name === m.name && j.version === m.version);
937
+ let W;
938
+ if (R) {
939
+ const j = R.paths ?? [], Z = jn(j, z) ? j : [...j, z];
940
+ W = T.map((ie) => ie.name === m.name && ie.version === m.version ? {
941
+ ...ie,
942
+ paths: Z
943
+ } : ie);
944
+ } else
945
+ W = [...T, {
946
+ name: m.name,
947
+ version: m.version,
948
+ paths: [z]
949
+ }];
950
+ O(W);
951
+ }, [h, T]), ne = H((m, G) => {
952
+ const k = T[m];
953
+ if (!k) return;
954
+ const z = (k.paths ?? []).filter((W, j) => j !== G), R = z.length === 0 ? T.filter((W, j) => j !== m) : T.map((W, j) => j === m ? {
955
+ ...W,
956
+ paths: z
957
+ } : W);
958
+ O(R);
959
+ }, [T]), re = H((m, G) => {
960
+ if (!s) return;
961
+ const k = G ?? {}, z = T.map((R, W) => W !== s.policyIndex ? R : {
962
+ ...R,
963
+ paths: (R.paths ?? []).map((j, Z) => Z === s.pathIndex ? {
964
+ ...j,
965
+ params: k
966
+ } : j)
967
+ });
968
+ O(z);
969
+ }, [s, T]), xe = H((m) => {
970
+ b(m), f(null), p(!0);
971
+ }, []), le = H((m) => {
972
+ if (!y.find((R) => R.name === m.policy.name && R.version === m.policy.version)) return;
973
+ const k = m.path, z = rt(k) ? {
974
+ type: "global"
975
+ } : {
976
+ type: "resource",
977
+ method: k.methods[0] ?? "",
978
+ path: k.path
979
+ };
980
+ b(z), f({
981
+ policyIndex: m.policyIndex,
982
+ pathIndex: m.pathIndex,
983
+ guardrailName: m.policy.name,
984
+ guardrailVersion: m.policy.version,
985
+ params: k.params ?? {}
986
+ }), p(!0);
987
+ }, [y]), te = H(() => {
988
+ p(!1), b(null), f(null);
989
+ }, []), fe = H((m, G) => {
990
+ s ? re(m, G) : h && he(m, G), te();
991
+ }, [h, s, he, re, te]), be = H((m) => y.find((k) => k.name === m.name && k.version === m.version)?.displayName ?? m.name, [y]), me = Q(() => {
992
+ if (!_.trim()) return Y;
993
+ const m = _.toLowerCase();
994
+ return Y.filter((G) => G.path.toLowerCase().includes(m) || G.method.toLowerCase().includes(m) || (G.summary ?? "").toLowerCase().includes(m));
995
+ }, [Y, _]), Ie = Q(() => me.slice(x * C, (x + 1) * C), [me, x]);
996
+ return r ? /* @__PURE__ */ a(E, { spacing: 3, children: [
997
+ /* @__PURE__ */ n(ee, { variant: "rounded", height: 120 }),
998
+ /* @__PURE__ */ n(ee, { variant: "rounded", height: 200 })
999
+ ] }) : !t && !o ? null : /* @__PURE__ */ a(se, { sx: {
1000
+ display: "flex",
1001
+ flexDirection: "column",
1002
+ height: "100%"
1003
+ }, children: [
1004
+ /* @__PURE__ */ n(se, { sx: {
1005
+ flex: 1,
1006
+ overflowY: "auto",
1007
+ pb: 2
1008
+ }, children: /* @__PURE__ */ a(E, { spacing: 3, children: [
1009
+ o && /* @__PURE__ */ n(ce, { severity: "error", sx: {
1010
+ width: "100%"
1011
+ }, children: o instanceof Error ? o.message : "Failed to load provider." }),
1012
+ /* @__PURE__ */ n(Ze, { in: !!d && (d.severity === "error" || !V), timeout: 300, children: d && /* @__PURE__ */ n(ce, { severity: d.severity, onClose: () => u(null), sx: {
1013
+ width: "100%"
1014
+ }, children: d.message }) }),
1015
+ /* @__PURE__ */ a(E, { spacing: 3, children: [
1016
+ /* @__PURE__ */ a(se, { children: [
1017
+ /* @__PURE__ */ n($, { variant: "h6", component: "h2", sx: {
1018
+ mb: 0.5
1019
+ }, children: "Global Guardrails" }),
1020
+ /* @__PURE__ */ n($, { variant: "body2", color: "text.secondary", sx: {
1021
+ mb: 2
1022
+ }, children: "Applies for all resources" }),
1023
+ /* @__PURE__ */ a(E, { direction: "row", spacing: 1, flexWrap: "wrap", useFlexGap: !0, children: [
1024
+ ae.map((m) => /* @__PURE__ */ n(ue, { label: `${be(m.policy)} (v${m.policy.version})`, color: "warning", variant: "outlined", onClick: () => le(m), onDelete: () => ne(m.policyIndex, m.pathIndex), disabled: l, sx: {
1025
+ cursor: "pointer"
1026
+ } }, `${m.policyIndex}-${m.pathIndex}`)),
1027
+ /* @__PURE__ */ n(de, { variant: "contained", size: "small", startIcon: /* @__PURE__ */ n(xt, { size: 16 }), onClick: () => xe({
1028
+ type: "global"
1029
+ }), disabled: l, children: "Add Guardrail" })
1030
+ ] })
1031
+ ] }),
1032
+ /* @__PURE__ */ a(se, { children: [
1033
+ /* @__PURE__ */ n($, { variant: "h6", component: "h2", sx: {
1034
+ mb: 2
1035
+ }, children: "Resource-wise Guardrails" }),
1036
+ P ? /* @__PURE__ */ a(E, { direction: "row", spacing: 1, alignItems: "center", sx: {
1037
+ py: 2
1038
+ }, children: [
1039
+ /* @__PURE__ */ n(ee, { variant: "circular", width: 16, height: 16 }),
1040
+ /* @__PURE__ */ n($, { variant: "body2", color: "text.secondary", children: "Loading OpenAPI spec…" })
1041
+ ] }) : Y.length === 0 ? /* @__PURE__ */ n(B.Container, { children: /* @__PURE__ */ n(B.EmptyState, { illustration: /* @__PURE__ */ n(Vt, { size: 64 }), title: "No resources found", description: "Add an OpenAPI specification to define resources for resource-wise guardrails." }) }) : /* @__PURE__ */ a(se, { children: [
1042
+ /* @__PURE__ */ n(At, { placeholder: "Search resources…", value: _, onChange: (m) => K(m.target.value), sx: {
1043
+ mb: 1,
1044
+ width: "100%"
1045
+ } }),
1046
+ me.length === 0 ? /* @__PURE__ */ n(B.Container, { children: /* @__PURE__ */ n(B.EmptyState, { illustration: /* @__PURE__ */ n(Kt, { size: 64 }), title: "No resources match your search", description: "Try a different keyword or clear the search filter." }) }) : /* @__PURE__ */ n(E, { spacing: 0, children: Ie.map((m) => {
1047
+ const G = Oe(m), k = M.has(G), z = q(m);
1048
+ return /* @__PURE__ */ a(je, { expanded: k, onChange: (R, W) => w((j) => {
1049
+ const Z = new Set(j);
1050
+ return W ? Z.add(G) : Z.delete(G), Z;
1051
+ }), disableGutters: !0, children: [
1052
+ /* @__PURE__ */ n(Ue, { expandIcon: /* @__PURE__ */ n(Ve, { size: 18 }), children: /* @__PURE__ */ a(E, { direction: "row", alignItems: "center", spacing: 1, children: [
1053
+ /* @__PURE__ */ n(ue, { label: m.method, size: "small", variant: "outlined", color: Tt(m.method), sx: {
1054
+ minWidth: 72,
1055
+ justifyContent: "center"
1056
+ } }),
1057
+ /* @__PURE__ */ n($, { variant: "body2", children: m.path })
1058
+ ] }) }),
1059
+ /* @__PURE__ */ a(Be, { children: [
1060
+ /* @__PURE__ */ n($, { variant: "subtitle2", sx: {
1061
+ mb: 1
1062
+ }, children: "Guardrails" }),
1063
+ /* @__PURE__ */ n(E, { direction: "row", spacing: 1, flexWrap: "wrap", useFlexGap: !0, sx: {
1064
+ mb: 1
1065
+ }, children: z.length === 0 ? /* @__PURE__ */ n($, { variant: "body2", color: "text.secondary", children: "No guardrails added yet." }) : z.map((R) => /* @__PURE__ */ n(ue, { label: `${be(R.policy)} (v${R.policy.version})`, color: "warning", variant: "outlined", onClick: () => le(R), onDelete: () => ne(R.policyIndex, R.pathIndex), disabled: l, sx: {
1066
+ cursor: "pointer"
1067
+ } }, `${m.path}-${R.policyIndex}-${R.pathIndex}`)) }),
1068
+ /* @__PURE__ */ n(de, { variant: "outlined", size: "small", startIcon: /* @__PURE__ */ n(xt, { size: 16 }), onClick: () => xe({
1069
+ type: "resource",
1070
+ method: m.method,
1071
+ path: m.path
1072
+ }), disabled: l, children: "Add Guardrail" })
1073
+ ] })
1074
+ ] }, G);
1075
+ }) }),
1076
+ me.length > C && /* @__PURE__ */ n(ct, { component: "div", count: me.length, page: x, rowsPerPage: C, rowsPerPageOptions: [C], onPageChange: (m, G) => U(G) })
1077
+ ] })
1078
+ ] })
1079
+ ] })
1080
+ ] }) }),
1081
+ /* @__PURE__ */ n($e, {}),
1082
+ /* @__PURE__ */ a(E, { direction: "row", spacing: 1.5, justifyContent: "flex-end", sx: {
1083
+ pt: 2
1084
+ }, children: [
1085
+ /* @__PURE__ */ n(de, { variant: "outlined", onClick: J, disabled: !V || l, children: "Discard" }),
1086
+ /* @__PURE__ */ n(de, { variant: "contained", onClick: () => void X(), disabled: !V || l, children: l ? "Saving..." : "Save" })
1087
+ ] }),
1088
+ /* @__PURE__ */ n(bn, { open: I, onClose: te, onSubmit: fe, policyNoun: "guardrail", loadingLabel: "Loading guardrails...", searchPlaceholder: "Search guardrails...", catalogErrorLabel: "Failed to load guardrails.", emptySearchTitle: "No guardrails match your search", emptyCatalogTitle: "No guardrails available", emptyCatalogDescription: "No guardrail policies are available in the catalog.", disabledPolicyKeys: s ? [] : T.filter((m) => h?.type === "global" ? (m.paths ?? []).some(rt) : h?.type === "resource" ? (m.paths ?? []).some((G) => St(G, h.path, h.method)) : !1).map((m) => `${m.name}@${m.version}`), existingSettings: s?.params, editPolicyKey: s ? `${s.guardrailName}@${s.guardrailVersion}` : void 0, title: s ? "Edit Guardrail" : "Guardrails", subtitle: s ? "Update the guardrail configuration." : "Choose a guardrail to configure advanced options.", minWidth: 600, maxWidth: 600 })
1089
+ ] });
1090
+ }
1091
+ function Bn(t, e) {
1092
+ const r = t.startsWith("http") ? t : `https://${t}`, o = e.startsWith("/") ? e : `/${e}`;
1093
+ return `${r.replace(/\/$/, "")}${o}`;
1094
+ }
1095
+ function Vn({
1096
+ providerData: t,
1097
+ openapiSpecUrl: e,
1098
+ orgName: r,
1099
+ providerId: o,
1100
+ isLoading: i = !1,
1101
+ error: l = null,
1102
+ onUpdate: c,
1103
+ isUpdating: y
1104
+ }) {
1105
+ const d = kt(), [u, L] = N(!1), [v, P] = N(null), S = t?.openapi?.trim() ?? e ?? "", [I, p] = N(S), [h, b] = N(null), s = Ke(!1);
1106
+ oe(() => {
1107
+ const q = (t?.openapi?.trim() ?? e ?? "").trim();
1108
+ I.trim() === q ? p(t?.openapi?.trim() ?? e ?? "") : !s.current && q && (p(t?.openapi?.trim() ?? e ?? ""), s.current = !0);
1109
+ }, [t?.openapi, e]);
1110
+ const f = H(async () => {
1111
+ b(null);
1112
+ try {
1113
+ await c({
1114
+ openapi: I.trim() || void 0
1115
+ });
1116
+ } catch (q) {
1117
+ b(q instanceof Error ? q.message : "Failed to save OpenAPI spec");
1118
+ }
1119
+ }, [I, c]), M = I.trim() !== (t?.openapi?.trim() ?? e ?? "").trim(), w = Q(() => {
1120
+ const q = I.trim();
1121
+ if (!q) return null;
1122
+ if (q.startsWith("http://") || q.startsWith("https://"))
1123
+ return {
1124
+ type: "url",
1125
+ value: q
1126
+ };
1127
+ const V = He(q);
1128
+ return V ? {
1129
+ type: "spec",
1130
+ value: V
1131
+ } : null;
1132
+ }, [I]), {
1133
+ data: x
1134
+ } = dn({
1135
+ orgName: r ?? "",
1136
+ providerId: o ?? ""
1137
+ }, {
1138
+ status: "DEPLOYED"
1139
+ }), {
1140
+ data: U
1141
+ } = zt({
1142
+ orgName: r ?? ""
1143
+ }, {
1144
+ limit: 500
1145
+ }), _ = Q(() => {
1146
+ if (!t?.context || !r || !o) return [];
1147
+ const q = Array.isArray(x) ? x : [], V = U?.gateways ?? [], X = new Set(q.map((J) => J.gatewayId).filter(Boolean));
1148
+ return V.filter((J) => X.has(J.uuid)).map((J) => ({
1149
+ gatewayId: J.uuid,
1150
+ url: Bn(J.vhost, t.context),
1151
+ displayName: J.displayName,
1152
+ name: J.name,
1153
+ environment: J.environments?.[0]
1154
+ }));
1155
+ }, [t?.context, x, U, r, o]), [K, C] = N(null), [g, F] = N(null), O = Nt(), A = un(), T = H((q) => {
1156
+ if (q && typeof q == "object") {
1157
+ if ((q.status ?? q.statusCode) === 409) return !0;
1158
+ const X = String(q.message ?? q.error ?? "").toLowerCase();
1159
+ if (X.includes("already exists") || X.includes("key exists") || X.includes("conflict"))
1160
+ return !0;
1161
+ }
1162
+ return !1;
1163
+ }, []), Y = H(async () => {
1164
+ if (!r || !o || _.length === 0) return;
1165
+ F(null), C(null);
1166
+ const q = Math.random().toString(36).slice(2, 10), V = `provider-${t?.id ?? "unknown"}-${q}`;
1167
+ try {
1168
+ const X = await O.mutateAsync({
1169
+ params: {
1170
+ orgName: r,
1171
+ providerId: o
1172
+ },
1173
+ body: {
1174
+ name: V,
1175
+ displayName: V
1176
+ }
1177
+ });
1178
+ X.apiKey && C(X.apiKey);
1179
+ } catch (X) {
1180
+ if (T(X))
1181
+ try {
1182
+ const J = await A.mutateAsync({
1183
+ params: {
1184
+ orgName: r,
1185
+ providerId: o,
1186
+ keyName: V
1187
+ },
1188
+ body: {}
1189
+ });
1190
+ J.apiKey && C(J.apiKey);
1191
+ } catch (J) {
1192
+ F(J instanceof Error ? J.message : "Failed to rotate API key");
1193
+ }
1194
+ else
1195
+ F(X instanceof Error ? X.message : "Failed to generate API key");
1196
+ }
1197
+ }, [r, o, _.length, O, A, T]), ae = H(async () => {
1198
+ const q = I.trim().startsWith("http") ? I.trim() : null;
1199
+ if (q) {
1200
+ L(!0), P(null);
1201
+ try {
1202
+ const V = await fetch(q);
1203
+ if (!V.ok)
1204
+ throw new Error(`Failed to download spec: ${V.status} ${V.statusText}`);
1205
+ const X = await V.text(), J = q.endsWith(".json") ? "json" : "yaml", he = new Blob([X], {
1206
+ type: J === "json" ? "application/json" : "text/yaml"
1207
+ }), ne = URL.createObjectURL(he), re = document.createElement("a");
1208
+ re.href = ne, re.download = `openapi-spec.${J}`, re.click(), URL.revokeObjectURL(ne);
1209
+ } catch (V) {
1210
+ P(V instanceof Error ? V.message : "Failed to download spec.");
1211
+ } finally {
1212
+ L(!1);
1213
+ }
1214
+ }
1215
+ }, [I]);
1216
+ return i ? /* @__PURE__ */ a(E, { spacing: 2, children: [
1217
+ /* @__PURE__ */ n(D, { container: !0, spacing: 2, children: [1, 2, 3, 4, 5].map((q) => /* @__PURE__ */ n(D, { size: {
1218
+ xs: 12,
1219
+ sm: 6,
1220
+ md: 4
1221
+ }, children: /* @__PURE__ */ n(Pe, { variant: "outlined", sx: {
1222
+ p: 2,
1223
+ height: "100%"
1224
+ }, children: /* @__PURE__ */ a(E, { spacing: 1, children: [
1225
+ /* @__PURE__ */ n(ee, { variant: "text", width: "40%", height: 16 }),
1226
+ /* @__PURE__ */ n(ee, { variant: "text", width: "80%", height: 20 })
1227
+ ] }) }) }, q)) }),
1228
+ /* @__PURE__ */ n($e, {}),
1229
+ /* @__PURE__ */ a(E, { spacing: 1.5, sx: {
1230
+ mt: 3
1231
+ }, children: [
1232
+ /* @__PURE__ */ n(ee, { variant: "text", width: 140, height: 20 }),
1233
+ /* @__PURE__ */ a(E, { direction: "row", spacing: 1, alignItems: "center", children: [
1234
+ /* @__PURE__ */ n(ee, { variant: "rounded", height: 40, sx: {
1235
+ flex: 1
1236
+ } }),
1237
+ /* @__PURE__ */ n(ee, { variant: "rounded", width: 120, height: 40 })
1238
+ ] }),
1239
+ /* @__PURE__ */ n(ee, { variant: "rounded", height: 400 })
1240
+ ] })
1241
+ ] }) : !t && !l ? null : l && !i ? /* @__PURE__ */ n(ce, { severity: "error", sx: {
1242
+ width: "100%"
1243
+ }, children: l instanceof Error ? l.message : "Failed to load provider." }) : t ? /* @__PURE__ */ a(E, { spacing: 3, children: [
1244
+ /* @__PURE__ */ a(D, { container: !0, spacing: 2, children: [
1245
+ t.context && /* @__PURE__ */ n(D, { size: {
1246
+ xs: 12,
1247
+ sm: 6,
1248
+ md: 4
1249
+ }, children: /* @__PURE__ */ n(Pe, { variant: "outlined", sx: {
1250
+ p: 2,
1251
+ height: "100%"
1252
+ }, children: /* @__PURE__ */ a(E, { spacing: 0.5, children: [
1253
+ /* @__PURE__ */ n($, { variant: "caption", color: "text.secondary", sx: {
1254
+ fontWeight: 500
1255
+ }, children: "Context" }),
1256
+ /* @__PURE__ */ n($, { variant: "body2", sx: {
1257
+ fontFamily: d.typography?.fontFamilyMonospace ?? "monospace"
1258
+ }, children: t.context })
1259
+ ] }) }) }),
1260
+ t.upstream?.main?.url && /* @__PURE__ */ n(D, { size: {
1261
+ xs: 12,
1262
+ sm: 6,
1263
+ md: 4
1264
+ }, children: /* @__PURE__ */ n(Pe, { variant: "outlined", sx: {
1265
+ p: 2,
1266
+ height: "100%"
1267
+ }, children: /* @__PURE__ */ a(E, { spacing: 0.5, children: [
1268
+ /* @__PURE__ */ n($, { variant: "caption", color: "text.secondary", sx: {
1269
+ fontWeight: 500
1270
+ }, children: "Upstream URL" }),
1271
+ /* @__PURE__ */ n($, { variant: "body2", sx: {
1272
+ fontFamily: d.typography?.fontFamilyMonospace ?? "monospace",
1273
+ wordBreak: "break-all"
1274
+ }, children: t.upstream.main.url })
1275
+ ] }) }) }),
1276
+ t.upstream?.main?.auth?.type && /* @__PURE__ */ n(D, { size: {
1277
+ xs: 12,
1278
+ sm: 6,
1279
+ md: 4
1280
+ }, children: /* @__PURE__ */ n(Pe, { variant: "outlined", sx: {
1281
+ p: 2,
1282
+ height: "100%"
1283
+ }, children: /* @__PURE__ */ a(E, { spacing: 0.5, children: [
1284
+ /* @__PURE__ */ n($, { variant: "caption", color: "text.secondary", sx: {
1285
+ fontWeight: 500
1286
+ }, children: "Auth Type" }),
1287
+ /* @__PURE__ */ n($, { variant: "body2", children: t.upstream.main.auth.type })
1288
+ ] }) }) }),
1289
+ t.accessControl?.mode && /* @__PURE__ */ n(D, { size: {
1290
+ xs: 12,
1291
+ sm: 6,
1292
+ md: 4
1293
+ }, children: /* @__PURE__ */ n(Pe, { variant: "outlined", sx: {
1294
+ p: 2,
1295
+ height: "100%"
1296
+ }, children: /* @__PURE__ */ a(E, { spacing: 0.5, children: [
1297
+ /* @__PURE__ */ n($, { variant: "caption", color: "text.secondary", sx: {
1298
+ fontWeight: 500
1299
+ }, children: "Access Control" }),
1300
+ /* @__PURE__ */ n(ue, { label: t.accessControl.mode, size: "small", variant: "outlined", sx: {
1301
+ width: "fit-content",
1302
+ textTransform: "capitalize"
1303
+ } })
1304
+ ] }) }) }),
1305
+ /* @__PURE__ */ n(D, { size: {
1306
+ xs: 12,
1307
+ sm: 6,
1308
+ md: 4
1309
+ }, children: /* @__PURE__ */ n(Pe, { variant: "outlined", sx: {
1310
+ p: 2,
1311
+ height: "100%"
1312
+ }, children: /* @__PURE__ */ a(E, { spacing: 0.5, children: [
1313
+ /* @__PURE__ */ n($, { variant: "caption", color: "text.secondary", sx: {
1314
+ fontWeight: 500
1315
+ }, children: "In Catalog" }),
1316
+ /* @__PURE__ */ n(ue, { label: t.inCatalog ? "Yes" : "No", size: "small", color: t.inCatalog ? "success" : "default", variant: "outlined", sx: {
1317
+ width: "fit-content"
1318
+ } })
1319
+ ] }) }) })
1320
+ ] }),
1321
+ r && o && /* @__PURE__ */ n(En, { endpoints: _, onGenerateApiKey: Y, isGeneratingApiKey: O.isPending || A.isPending, apiKeyError: g, generatedApiKey: K, onClearApiKeyError: () => F(null), emptyMessage: "No invoke URLs available. Deploy this provider to an AI gateway to see invoke URLs and generate API keys." }),
1322
+ /* @__PURE__ */ n($e, {}),
1323
+ /* @__PURE__ */ a(E, { spacing: 1.5, sx: {
1324
+ mt: 3
1325
+ }, children: [
1326
+ /* @__PURE__ */ n($, { variant: "subtitle2", color: "text.secondary", sx: {
1327
+ fontWeight: 600
1328
+ }, children: "OpenAPI Resources" }),
1329
+ /* @__PURE__ */ n($, { variant: "body2", color: "text.secondary", children: "Enter a URL and Click Save to persist changes to the provider." }),
1330
+ /* @__PURE__ */ a(E, { direction: "row", spacing: 1, alignItems: "flex-start", children: [
1331
+ /* @__PURE__ */ n(Le, { size: "small", fullWidth: !0, value: I, onChange: (q) => {
1332
+ p(q.target.value), b(null);
1333
+ }, placeholder: "https://example.com/openapi.json", sx: {
1334
+ "& .MuiInputBase-input": {
1335
+ fontFamily: d.typography?.fontFamilyMonospace ?? "monospace",
1336
+ fontSize: d.typography.body2?.fontSize
1337
+ }
1338
+ } }),
1339
+ /* @__PURE__ */ a(E, { direction: "row", spacing: 1, flexShrink: 0, children: [
1340
+ /* @__PURE__ */ n(de, { variant: "contained", size: "medium", startIcon: /* @__PURE__ */ n(Ht, { size: 16 }), onClick: f, disabled: !M || y || !r || !o, children: y ? "Saving..." : "Save" }),
1341
+ /* @__PURE__ */ n(de, { variant: "outlined", size: "medium", startIcon: /* @__PURE__ */ n(Yt, { size: 16 }), onClick: ae, disabled: u || !I.trim().startsWith("http"), children: u ? "Downloading..." : "Download" })
1342
+ ] })
1343
+ ] }),
1344
+ h && /* @__PURE__ */ n(ce, { severity: "error", onClose: () => b(null), children: h }),
1345
+ v && /* @__PURE__ */ n(ce, { severity: "error", onClose: () => P(null), children: v }),
1346
+ w ? /* @__PURE__ */ n(E, { spacing: 1, children: /* @__PURE__ */ a(je, { disableGutters: !0, children: [
1347
+ /* @__PURE__ */ n(Ue, { expandIcon: /* @__PURE__ */ n(Ve, { size: 18 }), children: /* @__PURE__ */ n($, { variant: "subtitle2", color: "text.secondary", children: "API Preview" }) }),
1348
+ /* @__PURE__ */ n(Be, { children: /* @__PURE__ */ n(Ft, { fallback: /* @__PURE__ */ a(E, { spacing: 1, sx: {
1349
+ py: 3
1350
+ }, children: [
1351
+ /* @__PURE__ */ n(ee, { variant: "rounded", height: 48 }),
1352
+ /* @__PURE__ */ n(ee, { variant: "rounded", height: 200 }),
1353
+ /* @__PURE__ */ n(ee, { variant: "rounded", height: 400 })
1354
+ ] }), children: /* @__PURE__ */ n(Ln, { ...w.type === "url" ? {
1355
+ url: w.value
1356
+ } : {
1357
+ spec: w.value
1358
+ }, docExpansion: "list", hideInfoSection: !0, hideServers: !0, hideAuthorizeButton: !0, hideOperationHeader: !0 }) }) })
1359
+ ] }) }) : /* @__PURE__ */ n(ce, { severity: "info", children: "Enter a URL or paste an OpenAPI spec above to preview it here." })
1360
+ ] })
1361
+ ] }) : null;
1362
+ }
1363
+ const Hn = [{
1364
+ value: "minute",
1365
+ label: "Minute(s)"
1366
+ }, {
1367
+ value: "hour",
1368
+ label: "Hour(s)"
1369
+ }, {
1370
+ value: "day",
1371
+ label: "Day(s)"
1372
+ }, {
1373
+ value: "week",
1374
+ label: "Week(s)"
1375
+ }, {
1376
+ value: "month",
1377
+ label: "Month(s)"
1378
+ }], It = Re({
1379
+ enabled: Rt(),
1380
+ quota: pe(),
1381
+ duration: pe(),
1382
+ unit: pe()
1383
+ }).refine((t) => {
1384
+ if (!t.enabled) return !0;
1385
+ const e = Number(t.quota);
1386
+ return !Number.isNaN(e) && e >= 1;
1387
+ }, {
1388
+ message: "Quota must be >= 1",
1389
+ path: ["quota"]
1390
+ }).refine((t) => {
1391
+ if (!t.enabled) return !0;
1392
+ const e = Number(t.duration);
1393
+ return !Number.isNaN(e) && Number.isInteger(e) && e >= 1;
1394
+ }, {
1395
+ message: "Duration must be a whole number >= 1",
1396
+ path: ["duration"]
1397
+ }), Yn = Re({
1398
+ enabled: Rt(),
1399
+ quota: pe(),
1400
+ duration: pe(),
1401
+ unit: pe()
1402
+ }).refine((t) => {
1403
+ if (!t.enabled) return !0;
1404
+ const e = Number(t.quota);
1405
+ return !Number.isNaN(e) && e > 0;
1406
+ }, {
1407
+ message: "Budget must be > 0",
1408
+ path: ["quota"]
1409
+ }).refine((t) => {
1410
+ if (!t.enabled) return !0;
1411
+ const e = Number(t.duration);
1412
+ return !Number.isNaN(e) && Number.isInteger(e) && e >= 1;
1413
+ }, {
1414
+ message: "Duration must be a whole number >= 1",
1415
+ path: ["duration"]
1416
+ }), Jn = Re({
1417
+ request: It,
1418
+ token: It,
1419
+ cost: Yn
1420
+ }), it = (t) => Oe(t, "-"), Ce = {
1421
+ request: {
1422
+ enabled: !1,
1423
+ quota: "",
1424
+ duration: "1",
1425
+ unit: "hour"
1426
+ },
1427
+ token: {
1428
+ enabled: !1,
1429
+ quota: "",
1430
+ duration: "1",
1431
+ unit: "hour"
1432
+ },
1433
+ cost: {
1434
+ enabled: !1,
1435
+ quota: "",
1436
+ duration: "1",
1437
+ unit: "day"
1438
+ }
1439
+ };
1440
+ function Ye(t) {
1441
+ const e = {
1442
+ ...Ce
1443
+ };
1444
+ return t && (t.request && (e.request = {
1445
+ enabled: t.request.enabled,
1446
+ quota: String(t.request.count ?? ""),
1447
+ duration: String(t.request.reset?.duration ?? 1),
1448
+ unit: t.request.reset?.unit ?? "hour"
1449
+ }), t.token && (e.token = {
1450
+ enabled: t.token.enabled,
1451
+ quota: String(t.token.count ?? ""),
1452
+ duration: String(t.token.reset?.duration ?? 1),
1453
+ unit: t.token.reset?.unit ?? "hour"
1454
+ }), t.cost && (e.cost = {
1455
+ enabled: t.cost.enabled,
1456
+ quota: String(t.cost.amount ?? ""),
1457
+ duration: String(t.cost.reset?.duration ?? 1),
1458
+ unit: t.cost.reset?.unit ?? "day"
1459
+ })), e;
1460
+ }
1461
+ function qe(t) {
1462
+ const e = Number(t);
1463
+ return Number.isFinite(e) ? e : void 0;
1464
+ }
1465
+ function Ee(t) {
1466
+ const e = {};
1467
+ if (t.request.enabled) {
1468
+ const r = qe(t.request.quota), o = qe(t.request.duration);
1469
+ r !== void 0 && o !== void 0 && (e.request = {
1470
+ enabled: !0,
1471
+ count: r,
1472
+ reset: {
1473
+ duration: o,
1474
+ unit: t.request.unit
1475
+ }
1476
+ });
1477
+ }
1478
+ if (t.token.enabled) {
1479
+ const r = qe(t.token.quota), o = qe(t.token.duration);
1480
+ r !== void 0 && o !== void 0 && (e.token = {
1481
+ enabled: !0,
1482
+ count: r,
1483
+ reset: {
1484
+ duration: o,
1485
+ unit: t.token.unit
1486
+ }
1487
+ });
1488
+ }
1489
+ if (t.cost.enabled) {
1490
+ const r = qe(t.cost.quota), o = qe(t.cost.duration);
1491
+ r !== void 0 && o !== void 0 && (e.cost = {
1492
+ enabled: !0,
1493
+ amount: r,
1494
+ reset: {
1495
+ duration: o,
1496
+ unit: t.cost.unit
1497
+ }
1498
+ });
1499
+ }
1500
+ return e;
1501
+ }
1502
+ function Qn(t) {
1503
+ const e = Jn.safeParse(t);
1504
+ if (e.success) return {};
1505
+ const r = {};
1506
+ for (const o of e.error.issues) {
1507
+ const i = o.path.join(".");
1508
+ r[i] || (r[i] = o.message);
1509
+ }
1510
+ return r;
1511
+ }
1512
+ function We(t) {
1513
+ return t.request.enabled && Number(t.request.quota) >= 1 || t.token.enabled && Number(t.token.quota) >= 1 || t.cost.enabled && Number(t.cost.quota) > 0;
1514
+ }
1515
+ function Xn(t) {
1516
+ return t.request.enabled || t.token.enabled || t.cost.enabled;
1517
+ }
1518
+ function st(t) {
1519
+ const e = Se(77), {
1520
+ label: r,
1521
+ quotaLabel: o,
1522
+ quotaPlaceholder: i,
1523
+ quotaMin: l,
1524
+ quotaStep: c,
1525
+ criterionKey: y,
1526
+ value: d,
1527
+ onChange: u,
1528
+ disabled: L,
1529
+ fieldErrors: v
1530
+ } = t, P = L === void 0 ? !1 : L, [S, I] = N(d.enabled);
1531
+ let p, h;
1532
+ e[0] !== d.enabled ? (p = () => {
1533
+ I(d.enabled);
1534
+ }, h = [d.enabled], e[0] = d.enabled, e[1] = p, e[2] = h) : (p = e[1], h = e[2]), oe(p, h);
1535
+ const b = `${y}.quota`, s = `${y}.duration`, f = P ? 0.6 : 1;
1536
+ let M;
1537
+ e[3] !== f ? (M = {
1538
+ borderRadius: 2,
1539
+ overflow: "hidden",
1540
+ opacity: f
1541
+ }, e[3] = f, e[4] = M) : M = e[4];
1542
+ let w;
1543
+ e[5] === Symbol.for("react.memo_cache_sentinel") ? (w = (we, et) => I(et), e[5] = w) : w = e[5];
1544
+ let x;
1545
+ e[6] === Symbol.for("react.memo_cache_sentinel") ? (x = {
1546
+ background: "transparent",
1547
+ "&:before": {
1548
+ display: "none"
1549
+ }
1550
+ }, e[6] = x) : x = e[6];
1551
+ let U, _;
1552
+ e[7] === Symbol.for("react.memo_cache_sentinel") ? (U = /* @__PURE__ */ n(Ve, { size: 18 }), _ = {
1553
+ px: 2,
1554
+ py: 1
1555
+ }, e[7] = U, e[8] = _) : (U = e[7], _ = e[8]);
1556
+ let K;
1557
+ e[9] !== r ? (K = /* @__PURE__ */ n($, { variant: "subtitle2", children: r }), e[9] = r, e[10] = K) : K = e[10];
1558
+ let C;
1559
+ e[11] !== d.enabled ? (C = d.enabled && /* @__PURE__ */ n(ue, { label: "Enabled", size: "small", color: "primary", variant: "outlined", sx: {
1560
+ height: 20,
1561
+ fontSize: "0.7rem"
1562
+ } }), e[11] = d.enabled, e[12] = C) : C = e[12];
1563
+ let g;
1564
+ e[13] !== K || e[14] !== C ? (g = /* @__PURE__ */ a(E, { direction: "row", alignItems: "center", spacing: 1, children: [
1565
+ K,
1566
+ C
1567
+ ] }), e[13] = K, e[14] = C, e[15] = g) : g = e[15];
1568
+ let F;
1569
+ e[16] !== u ? (F = (we, et) => u({
1570
+ enabled: et
1571
+ }), e[16] = u, e[17] = F) : F = e[17];
1572
+ let O;
1573
+ e[18] !== P || e[19] !== F || e[20] !== d.enabled ? (O = /* @__PURE__ */ n(_t, { size: "small", checked: d.enabled, onChange: F, disabled: P, onClick: Dn }), e[18] = P, e[19] = F, e[20] = d.enabled, e[21] = O) : O = e[21];
1574
+ let A;
1575
+ e[22] !== g || e[23] !== O ? (A = /* @__PURE__ */ n(Ue, { expandIcon: U, sx: _, children: /* @__PURE__ */ a(E, { direction: "row", alignItems: "center", justifyContent: "space-between", width: "100%", pr: 1, children: [
1576
+ g,
1577
+ O
1578
+ ] }) }), e[22] = g, e[23] = O, e[24] = A) : A = e[24];
1579
+ let T;
1580
+ e[25] === Symbol.for("react.memo_cache_sentinel") ? (T = {
1581
+ px: 2,
1582
+ pb: 2,
1583
+ pt: 0
1584
+ }, e[25] = T) : T = e[25];
1585
+ let Y;
1586
+ e[26] === Symbol.for("react.memo_cache_sentinel") ? (Y = {
1587
+ xs: 12,
1588
+ sm: 4
1589
+ }, e[26] = Y) : Y = e[26];
1590
+ let ae;
1591
+ e[27] !== o ? (ae = /* @__PURE__ */ n(ve, { children: o }), e[27] = o, e[28] = ae) : ae = e[28];
1592
+ let q;
1593
+ e[29] !== y || e[30] !== u ? (q = (we) => u({
1594
+ quota: y === "cost" ? we.target.value : we.target.value === "" ? "" : String(Math.trunc(Number(we.target.value)))
1595
+ }), e[29] = y, e[30] = u, e[31] = q) : q = e[31];
1596
+ const V = P || !d.enabled, X = !!v?.[b], J = v?.[b];
1597
+ let he;
1598
+ e[32] !== l || e[33] !== c ? (he = {
1599
+ input: {
1600
+ inputProps: {
1601
+ min: l,
1602
+ step: c
1603
+ }
1604
+ }
1605
+ }, e[32] = l, e[33] = c, e[34] = he) : he = e[34];
1606
+ let ne;
1607
+ e[35] !== i || e[36] !== q || e[37] !== V || e[38] !== X || e[39] !== J || e[40] !== he || e[41] !== d.quota ? (ne = /* @__PURE__ */ n(Le, { size: "small", type: "number", placeholder: i, value: d.quota, onChange: q, disabled: V, error: X, helperText: J, slotProps: he }), e[35] = i, e[36] = q, e[37] = V, e[38] = X, e[39] = J, e[40] = he, e[41] = d.quota, e[42] = ne) : ne = e[42];
1608
+ let re;
1609
+ e[43] !== ae || e[44] !== ne ? (re = /* @__PURE__ */ n(D, { size: Y, children: /* @__PURE__ */ a(ge, { fullWidth: !0, size: "small", children: [
1610
+ ae,
1611
+ ne
1612
+ ] }) }), e[43] = ae, e[44] = ne, e[45] = re) : re = e[45];
1613
+ let xe;
1614
+ e[46] === Symbol.for("react.memo_cache_sentinel") ? (xe = {
1615
+ xs: 12,
1616
+ sm: 4
1617
+ }, e[46] = xe) : xe = e[46];
1618
+ let le;
1619
+ e[47] === Symbol.for("react.memo_cache_sentinel") ? (le = /* @__PURE__ */ n(ve, { children: "Duration" }), e[47] = le) : le = e[47];
1620
+ let te;
1621
+ e[48] !== u ? (te = (we) => u({
1622
+ duration: we.target.value
1623
+ }), e[48] = u, e[49] = te) : te = e[49];
1624
+ const fe = P || !d.enabled, be = !!v?.[s], me = v?.[s];
1625
+ let Ie;
1626
+ e[50] === Symbol.for("react.memo_cache_sentinel") ? (Ie = {
1627
+ input: {
1628
+ inputProps: {
1629
+ min: 1,
1630
+ step: 1
1631
+ }
1632
+ }
1633
+ }, e[50] = Ie) : Ie = e[50];
1634
+ let m;
1635
+ e[51] !== te || e[52] !== fe || e[53] !== be || e[54] !== me || e[55] !== d.duration ? (m = /* @__PURE__ */ n(D, { size: xe, children: /* @__PURE__ */ a(ge, { fullWidth: !0, size: "small", children: [
1636
+ le,
1637
+ /* @__PURE__ */ n(Le, { size: "small", type: "number", placeholder: "e.g. 1", value: d.duration, onChange: te, disabled: fe, error: be, helperText: me, slotProps: Ie })
1638
+ ] }) }), e[51] = te, e[52] = fe, e[53] = be, e[54] = me, e[55] = d.duration, e[56] = m) : m = e[56];
1639
+ let G;
1640
+ e[57] === Symbol.for("react.memo_cache_sentinel") ? (G = {
1641
+ xs: 12,
1642
+ sm: 4
1643
+ }, e[57] = G) : G = e[57];
1644
+ let k;
1645
+ e[58] === Symbol.for("react.memo_cache_sentinel") ? (k = /* @__PURE__ */ n(ve, { children: "Unit" }), e[58] = k) : k = e[58];
1646
+ const z = d.unit;
1647
+ let R;
1648
+ e[59] !== u ? (R = (we) => u({
1649
+ unit: we.target.value
1650
+ }), e[59] = u, e[60] = R) : R = e[60];
1651
+ const W = P || !d.enabled;
1652
+ let j;
1653
+ e[61] === Symbol.for("react.memo_cache_sentinel") ? (j = Hn.map(Zn), e[61] = j) : j = e[61];
1654
+ let Z;
1655
+ e[62] !== R || e[63] !== W || e[64] !== d.unit ? (Z = /* @__PURE__ */ n(D, { size: G, children: /* @__PURE__ */ a(ge, { fullWidth: !0, size: "small", children: [
1656
+ k,
1657
+ /* @__PURE__ */ n(Xe, { size: "small", value: z, onChange: R, disabled: W, children: j })
1658
+ ] }) }), e[62] = R, e[63] = W, e[64] = d.unit, e[65] = Z) : Z = e[65];
1659
+ let ie;
1660
+ e[66] !== re || e[67] !== m || e[68] !== Z ? (ie = /* @__PURE__ */ n(Be, { sx: T, children: /* @__PURE__ */ a(D, { container: !0, spacing: 2, children: [
1661
+ re,
1662
+ m,
1663
+ Z
1664
+ ] }) }), e[66] = re, e[67] = m, e[68] = Z, e[69] = ie) : ie = e[69];
1665
+ let ye;
1666
+ e[70] !== S || e[71] !== A || e[72] !== ie ? (ye = /* @__PURE__ */ a(je, { expanded: S, onChange: w, disableGutters: !0, elevation: 0, sx: x, children: [
1667
+ A,
1668
+ ie
1669
+ ] }), e[70] = S, e[71] = A, e[72] = ie, e[73] = ye) : ye = e[73];
1670
+ let ke;
1671
+ return e[74] !== ye || e[75] !== M ? (ke = /* @__PURE__ */ n(lt, { variant: "outlined", sx: M, children: ye }), e[74] = ye, e[75] = M, e[76] = ke) : ke = e[76], ke;
1672
+ }
1673
+ function Zn(t) {
1674
+ return /* @__PURE__ */ n(_e, { value: t.value, children: t.label }, t.value);
1675
+ }
1676
+ function Dn(t) {
1677
+ return t.stopPropagation();
1678
+ }
1679
+ function Je(t) {
1680
+ const e = Se(27), {
1681
+ criteria: r,
1682
+ onChange: o,
1683
+ disabled: i,
1684
+ showCost: l,
1685
+ fieldErrors: c
1686
+ } = t, y = i === void 0 ? !1 : i, d = l === void 0 ? !0 : l;
1687
+ let u;
1688
+ e[0] !== r || e[1] !== o ? (u = (b, s) => {
1689
+ o({
1690
+ ...r,
1691
+ [b]: {
1692
+ ...r[b],
1693
+ ...s
1694
+ }
1695
+ });
1696
+ }, e[0] = r, e[1] = o, e[2] = u) : u = e[2];
1697
+ const L = u;
1698
+ let v;
1699
+ e[3] !== L ? (v = (b) => L("request", b), e[3] = L, e[4] = v) : v = e[4];
1700
+ let P;
1701
+ e[5] !== r.request || e[6] !== y || e[7] !== c || e[8] !== v ? (P = /* @__PURE__ */ n(st, { label: "Request Counts", quotaLabel: "Quota (requests)", quotaPlaceholder: "e.g. 1000", quotaMin: 1, quotaStep: 1, criterionKey: "request", value: r.request, onChange: v, disabled: y, fieldErrors: c }), e[5] = r.request, e[6] = y, e[7] = c, e[8] = v, e[9] = P) : P = e[9];
1702
+ let S;
1703
+ e[10] !== L ? (S = (b) => L("token", b), e[10] = L, e[11] = S) : S = e[11];
1704
+ let I;
1705
+ e[12] !== r.token || e[13] !== y || e[14] !== c || e[15] !== S ? (I = /* @__PURE__ */ n(st, { label: "Token Count", quotaLabel: "Quota (tokens)", quotaPlaceholder: "e.g. 500000", quotaMin: 1, quotaStep: 1, criterionKey: "token", value: r.token, onChange: S, disabled: y, fieldErrors: c }), e[12] = r.token, e[13] = y, e[14] = c, e[15] = S, e[16] = I) : I = e[16];
1706
+ let p;
1707
+ e[17] !== r.cost || e[18] !== y || e[19] !== c || e[20] !== d || e[21] !== L ? (p = d && /* @__PURE__ */ n(st, { label: "Cost", quotaLabel: "Budget (USD)", quotaPlaceholder: "e.g. 10.00", quotaMin: 1e-6, quotaStep: 1e-6, criterionKey: "cost", value: r.cost, onChange: (b) => L("cost", b), disabled: y, fieldErrors: c }), e[17] = r.cost, e[18] = y, e[19] = c, e[20] = d, e[21] = L, e[22] = p) : p = e[22];
1708
+ let h;
1709
+ return e[23] !== P || e[24] !== I || e[25] !== p ? (h = /* @__PURE__ */ a(E, { spacing: 1.5, children: [
1710
+ P,
1711
+ I,
1712
+ p
1713
+ ] }), e[23] = P, e[24] = I, e[25] = p, e[26] = h) : h = e[26], h;
1714
+ }
1715
+ function er({
1716
+ providerData: t,
1717
+ openapiSpecUrl: e,
1718
+ isLoading: r = !1,
1719
+ onUpdate: o,
1720
+ isUpdating: i
1721
+ }) {
1722
+ const [l, c] = Zt(), [y, d] = N(0), [u, L] = N(null), v = t?.openapi?.trim() ?? "", {
1723
+ text: P,
1724
+ isLoading: S,
1725
+ error: I
1726
+ } = pt(e, v);
1727
+ oe(() => {
1728
+ I && L({
1729
+ message: "Failed to load OpenAPI spec.",
1730
+ severity: "error"
1731
+ });
1732
+ }, [I]);
1733
+ const p = Q(() => {
1734
+ if (!P.trim()) return [];
1735
+ const k = He(P);
1736
+ return k ? ft(k) : [];
1737
+ }, [P]), h = l.get("mode"), b = h === "global" || h === "resourceWise" ? h : "global", [s, f] = N(b), [M, w] = N(Ce), [x, U] = N(Ce), [_, K] = N({}), [C, g] = N(""), [F, O] = N(/* @__PURE__ */ new Set()), [A, T] = N({}), [Y, ae] = N(Ce), q = Q(() => We(M), [M]), V = Q(() => We(x) ? !0 : Object.values(_).some(We), [x, _]), X = Ke(null), [J, he] = N(0), ne = H(() => {
1738
+ const k = Ee(M), z = Ee(x), R = Object.entries(_).filter(([, W]) => We(W)).map(([W, j]) => ({
1739
+ resource: W,
1740
+ limit: Ee(j)
1741
+ })).sort((W, j) => W.resource.localeCompare(j.resource));
1742
+ return JSON.stringify({
1743
+ global: k,
1744
+ resourceWise: {
1745
+ default: z,
1746
+ resources: R
1747
+ },
1748
+ consumerGlobal: Ee(Y)
1749
+ });
1750
+ }, [M, x, _, Y]), re = H(() => {
1751
+ if (!t) return;
1752
+ const k = l.get("mode"), z = t.rateLimiting?.providerLevel;
1753
+ let R = "global";
1754
+ if (z?.resourceWise) {
1755
+ R = "resourceWise", f("resourceWise"), w(Ce), U(Ye(z.resourceWise.default));
1756
+ const j = {};
1757
+ for (const Z of z.resourceWise.resources ?? [])
1758
+ j[Z.resource] = Ye(Z.limit);
1759
+ K(j);
1760
+ } else z?.global ? (R = "global", f("global"), w(Ye(z.global)), U(Ce), K({})) : (f("global"), w(Ce), U(Ce), K({}));
1761
+ k || c((j) => {
1762
+ const Z = new URLSearchParams(j);
1763
+ return Z.set("mode", R), Z;
1764
+ }, {
1765
+ replace: !0
1766
+ });
1767
+ const W = t.rateLimiting?.consumerLevel;
1768
+ W?.global ? ae(Ye(W.global)) : ae(Ce), he(Date.now());
1769
+ }, [t, l, c]);
1770
+ oe(() => {
1771
+ re();
1772
+ }, [re]), oe(() => {
1773
+ const k = l.get("mode");
1774
+ (k === "global" || k === "resourceWise") && f(k);
1775
+ }, [l]);
1776
+ const xe = Ke("");
1777
+ xe.current = ne(), oe(() => {
1778
+ J > 0 && t && (X.current = xe.current);
1779
+ }, [J, t]);
1780
+ const le = Q(() => !t || X.current === null ? !1 : ne() !== X.current, [t, ne]), te = Q(() => {
1781
+ if (!C.trim()) return p;
1782
+ const k = C.toLowerCase();
1783
+ return p.filter((z) => it(z).toLowerCase().includes(k) || z.path.toLowerCase().includes(k) || (z.summary ?? "").toLowerCase().includes(k));
1784
+ }, [p, C]), fe = 10, [be, me] = N(0);
1785
+ oe(() => {
1786
+ me(0);
1787
+ }, [te]);
1788
+ const Ie = Q(() => te.slice(be * fe, (be + 1) * fe), [te, be]), m = H(async () => {
1789
+ if (!t || r) return;
1790
+ if (s === "global" && V) {
1791
+ L({
1792
+ message: "Provider Level cannot have both Provider-wide and Per Resource values. Remove one side and try again.",
1793
+ severity: "error"
1794
+ });
1795
+ return;
1796
+ }
1797
+ if (s === "resourceWise" && q) {
1798
+ L({
1799
+ message: "Provider Level cannot have both Provider-wide and Per Resource values. Remove one side and try again.",
1800
+ severity: "error"
1801
+ });
1802
+ return;
1803
+ }
1804
+ const k = [];
1805
+ s === "global" ? k.push({
1806
+ c: M,
1807
+ blockKey: "global"
1808
+ }) : (k.push({
1809
+ c: x,
1810
+ blockKey: "resourceWise-default"
1811
+ }), Object.entries(_).forEach(([R, W]) => {
1812
+ Xn(W) && k.push({
1813
+ c: W,
1814
+ blockKey: `resourceWise-${R}`
1815
+ });
1816
+ })), k.push({
1817
+ c: Y,
1818
+ blockKey: "consumer-global"
1819
+ });
1820
+ for (const {
1821
+ c: R,
1822
+ blockKey: W
1823
+ } of k) {
1824
+ const j = Qn(R);
1825
+ if (Object.keys(j).length > 0) {
1826
+ if (T({
1827
+ [W]: j
1828
+ }), W === "consumer-global")
1829
+ d(1);
1830
+ else if (d(0), W.startsWith("resourceWise-") && W !== "resourceWise-default") {
1831
+ const Z = W.replace("resourceWise-", "");
1832
+ O((ye) => new Set(ye).add(Z));
1833
+ const ie = te.findIndex((ye) => it(ye) === Z);
1834
+ ie >= 0 && me(Math.floor(ie / fe));
1835
+ }
1836
+ return;
1837
+ }
1838
+ }
1839
+ T({});
1840
+ const z = () => {
1841
+ if (s === "global")
1842
+ return {
1843
+ global: Ee(M),
1844
+ resourceWise: void 0
1845
+ };
1846
+ const R = Object.entries(_).filter(([, W]) => We(W)).map(([W, j]) => ({
1847
+ resource: W,
1848
+ limit: Ee(j)
1849
+ }));
1850
+ return {
1851
+ global: void 0,
1852
+ resourceWise: {
1853
+ default: Ee(x),
1854
+ resources: R
1855
+ }
1856
+ };
1857
+ };
1858
+ try {
1859
+ await o({
1860
+ rateLimiting: {
1861
+ providerLevel: z(),
1862
+ consumerLevel: {
1863
+ global: Ee(Y),
1864
+ resourceWise: void 0
1865
+ }
1866
+ }
1867
+ }), L({
1868
+ message: "Rate limits updated successfully.",
1869
+ severity: "success"
1870
+ }), T({}), X.current = ne();
1871
+ } catch {
1872
+ L({
1873
+ message: "Failed to update rate limits.",
1874
+ severity: "error"
1875
+ });
1876
+ }
1877
+ }, [t, r, s, M, x, _, q, V, Y, o, ne, te]), G = H(() => {
1878
+ re(), L(null), T({});
1879
+ }, [re]);
1880
+ return r ? /* @__PURE__ */ a(E, { spacing: 3, children: [
1881
+ /* @__PURE__ */ n(ee, { variant: "rounded", height: 48 }),
1882
+ /* @__PURE__ */ n(ee, { variant: "rounded", height: 120 }),
1883
+ /* @__PURE__ */ n(ee, { variant: "rounded", height: 120 })
1884
+ ] }) : t ? /* @__PURE__ */ a(E, { spacing: 3, children: [
1885
+ /* @__PURE__ */ n(se, { sx: {
1886
+ borderBottom: 1,
1887
+ borderColor: "divider"
1888
+ }, children: /* @__PURE__ */ a(Mt, { value: y, onChange: (k, z) => d(z), children: [
1889
+ /* @__PURE__ */ n(at, { label: "Provider Level" }),
1890
+ /* @__PURE__ */ n(at, { label: "Consumer Level" })
1891
+ ] }) }),
1892
+ y === 0 && /* @__PURE__ */ a(E, { spacing: 2, children: [
1893
+ /* @__PURE__ */ n($, { variant: "body2", color: "text.secondary", children: "Aggregate limits enforced on the upstream LLM provider across all consumers." }),
1894
+ /* @__PURE__ */ a(ge, { children: [
1895
+ /* @__PURE__ */ n(ve, { sx: {
1896
+ mb: 1
1897
+ }, children: "Mode" }),
1898
+ /* @__PURE__ */ a(Ot, { value: s, exclusive: !0, color: "primary", onChange: (k, z) => {
1899
+ z && (f(z), c((R) => {
1900
+ const W = new URLSearchParams(R);
1901
+ return W.set("mode", z), W;
1902
+ }, {
1903
+ replace: !0
1904
+ }));
1905
+ }, size: "small", children: [
1906
+ /* @__PURE__ */ n(Ge, { title: s === "resourceWise" && (V || le) ? "Remove Per Resource values first to switch to Provider-wide." : "", children: /* @__PURE__ */ n(se, { component: "span", children: /* @__PURE__ */ n(yt, { value: "global", sx: {
1907
+ textTransform: "none"
1908
+ }, disabled: le || s === "resourceWise" && V, children: "Provider-wide" }) }) }),
1909
+ /* @__PURE__ */ n(Ge, { title: s === "global" && (q || le) ? "Remove Provider-wide values first to switch to Per Resource." : "", children: /* @__PURE__ */ n(se, { component: "span", children: /* @__PURE__ */ n(yt, { value: "resourceWise", sx: {
1910
+ textTransform: "none"
1911
+ }, disabled: le || s === "global" && q, children: "Per Resource" }) }) })
1912
+ ] })
1913
+ ] }),
1914
+ s === "global" && /* @__PURE__ */ n(Je, { criteria: M, onChange: w, fieldErrors: A.global }),
1915
+ s === "resourceWise" && /* @__PURE__ */ a(E, { spacing: 2, children: [
1916
+ /* @__PURE__ */ n(lt, { variant: "outlined", sx: {
1917
+ borderRadius: 2
1918
+ }, children: /* @__PURE__ */ a(je, { defaultExpanded: !0, disableGutters: !0, elevation: 0, sx: {
1919
+ background: "transparent",
1920
+ "&:before": {
1921
+ display: "none"
1922
+ }
1923
+ }, children: [
1924
+ /* @__PURE__ */ n(Ue, { expandIcon: /* @__PURE__ */ n(Ve, { size: 18 }), sx: {
1925
+ px: 2
1926
+ }, children: /* @__PURE__ */ a(E, { spacing: 0.25, children: [
1927
+ /* @__PURE__ */ n($, { variant: "subtitle2", children: "Default Resource Limit" }),
1928
+ /* @__PURE__ */ n($, { variant: "caption", color: "text.secondary", children: "Applied to any resource that has no specific override below." })
1929
+ ] }) }),
1930
+ /* @__PURE__ */ n(Be, { sx: {
1931
+ px: 2,
1932
+ pb: 2
1933
+ }, children: /* @__PURE__ */ n(Je, { criteria: x, onChange: U, fieldErrors: A["resourceWise-default"] }) })
1934
+ ] }) }),
1935
+ /* @__PURE__ */ n(At, { placeholder: "Search resources…", value: C, onChange: (k) => g(k.target.value) }),
1936
+ S ? /* @__PURE__ */ a(se, { sx: {
1937
+ display: "flex",
1938
+ alignItems: "center",
1939
+ gap: 1,
1940
+ py: 2
1941
+ }, children: [
1942
+ /* @__PURE__ */ n(Et, { size: 16 }),
1943
+ /* @__PURE__ */ n($, { variant: "body2", color: "text.secondary", children: "Loading OpenAPI spec…" })
1944
+ ] }) : te.length === 0 ? /* @__PURE__ */ n(B.Container, { children: /* @__PURE__ */ n(B.EmptyState, { illustration: C.trim() ? /* @__PURE__ */ n(Kt, { size: 64 }) : /* @__PURE__ */ n(Jt, { size: 64 }), title: C.trim() ? "No resources match your search" : "No resources found", description: C.trim() ? "Try a different keyword or clear the search filter." : "No resources are available from the OpenAPI spec. Add an OpenAPI specification to define resources." }) }) : /* @__PURE__ */ a(E, { spacing: 1, children: [
1945
+ Ie.map((k) => {
1946
+ const z = it(k), R = F.has(z), W = _[z] ?? Ce, j = We(W);
1947
+ return /* @__PURE__ */ n(lt, { variant: "outlined", sx: {
1948
+ borderRadius: 2,
1949
+ overflow: "hidden"
1950
+ }, children: /* @__PURE__ */ a(je, { expanded: R, onChange: (Z, ie) => O((ye) => {
1951
+ const ke = new Set(ye);
1952
+ return ie ? ke.add(z) : ke.delete(z), ke;
1953
+ }), disableGutters: !0, elevation: 0, sx: {
1954
+ background: "transparent",
1955
+ "&:before": {
1956
+ display: "none"
1957
+ }
1958
+ }, children: [
1959
+ /* @__PURE__ */ n(Ue, { expandIcon: /* @__PURE__ */ n(Ve, { size: 16 }), sx: {
1960
+ px: 2
1961
+ }, children: /* @__PURE__ */ a(E, { direction: "row", alignItems: "center", spacing: 1, children: [
1962
+ /* @__PURE__ */ n(ue, { label: k.method, size: "small", variant: "outlined", color: Tt(k.method), sx: {
1963
+ minWidth: 72,
1964
+ justifyContent: "center"
1965
+ } }),
1966
+ /* @__PURE__ */ n($, { variant: "body2", children: k.path }),
1967
+ j && /* @__PURE__ */ n(ue, { label: "Custom", size: "small", color: "primary", sx: {
1968
+ height: 18,
1969
+ fontSize: "0.65rem"
1970
+ } })
1971
+ ] }) }),
1972
+ R && /* @__PURE__ */ n(Be, { sx: {
1973
+ px: 2,
1974
+ pb: 2
1975
+ }, children: /* @__PURE__ */ n(Je, { criteria: W, onChange: (Z) => K((ie) => ({
1976
+ ...ie,
1977
+ [z]: Z
1978
+ })), fieldErrors: A[`resourceWise-${z}`] }) })
1979
+ ] }) }, z);
1980
+ }),
1981
+ te.length > fe && /* @__PURE__ */ n(ct, { component: "div", count: te.length, page: be, rowsPerPage: fe, rowsPerPageOptions: [fe], onPageChange: (k, z) => me(z) })
1982
+ ] })
1983
+ ] })
1984
+ ] }),
1985
+ y === 1 && /* @__PURE__ */ a(E, { spacing: 2, children: [
1986
+ /* @__PURE__ */ n($, { variant: "body2", color: "text.secondary", children: "Limits applied per agent (consumer). Each connected agent gets its own independent quota — enabling a criterion here prevents any single agent from exhausting the shared provider limit." }),
1987
+ /* @__PURE__ */ n(Je, { criteria: Y, onChange: ae, fieldErrors: A["consumer-global"] })
1988
+ ] }),
1989
+ /* @__PURE__ */ a(E, { spacing: 1.5, width: "100%", children: [
1990
+ /* @__PURE__ */ n(Ze, { in: !!u && (u.severity === "error" || !le), timeout: 300, children: u && /* @__PURE__ */ n(ce, { severity: u.severity, onClose: () => L(null), sx: {
1991
+ width: "100%"
1992
+ }, children: u.message }) }),
1993
+ /* @__PURE__ */ a(E, { direction: "row", spacing: 1.5, justifyContent: "flex-end", children: [
1994
+ /* @__PURE__ */ n(de, { variant: "outlined", onClick: G, disabled: !le || i, children: "Discard" }),
1995
+ /* @__PURE__ */ n(de, { variant: "contained", onClick: () => void m(), disabled: !le || i, children: i ? "Saving..." : "Save" })
1996
+ ] })
1997
+ ] })
1998
+ ] }) : null;
1999
+ }
2000
+ const tr = [{
2001
+ value: "header",
2002
+ label: "header"
2003
+ }, {
2004
+ value: "query",
2005
+ label: "query"
2006
+ }], nr = Re({
2007
+ authenticationType: Ct(["apiKey", ""]),
2008
+ keyValue: pe(),
2009
+ keyIn: Ct(["header", "query"])
2010
+ }).refine((t) => t.authenticationType === "apiKey" ? t.keyValue.trim().length > 0 : !0, {
2011
+ message: "API Key is required when using API Key authentication",
2012
+ path: ["keyValue"]
2013
+ });
2014
+ function rr({
2015
+ providerData: t,
2016
+ isLoading: e = !1,
2017
+ onUpdate: r,
2018
+ isUpdating: o
2019
+ }) {
2020
+ const [i, l] = N("apiKey"), [c, y] = N(""), [d, u] = N("header"), [L, v] = N(null), [P, S] = N({}), I = Q(() => {
2021
+ if (!t) return !1;
2022
+ const s = t.security?.apiKey, M = !!s && s.enabled !== !1 && !!(s.key ?? "").trim() ? "apiKey" : "", w = t.security?.apiKey?.key ?? "", x = t.security?.apiKey?.in ?? "header";
2023
+ return i !== M || c.trim() !== w || d !== x;
2024
+ }, [t, i, c, d]);
2025
+ oe(() => {
2026
+ if (!t) return;
2027
+ const s = t.security?.apiKey, f = !!s && s.enabled !== !1 && !!(s.key ?? "").trim();
2028
+ l(f ? "apiKey" : ""), y(t.security?.apiKey?.key ?? ""), u(t.security?.apiKey?.in ?? "header"), S({});
2029
+ }, [t]);
2030
+ const p = H(() => {
2031
+ if (!t) return;
2032
+ const s = t.security?.apiKey, f = !!s && s.enabled !== !1 && !!(s.key ?? "").trim();
2033
+ l(f ? "apiKey" : ""), y(t.security?.apiKey?.key ?? ""), u(t.security?.apiKey?.in ?? "header"), S({}), v(null);
2034
+ }, [t]), h = H(async () => {
2035
+ if (!t) return;
2036
+ const s = nr.safeParse({
2037
+ authenticationType: i || "",
2038
+ keyValue: c,
2039
+ keyIn: d
2040
+ });
2041
+ if (!s.success) {
2042
+ const w = s.error.flatten(), x = w.formErrors[0];
2043
+ S({
2044
+ keyValue: w.fieldErrors.keyValue?.[0]
2045
+ }), v({
2046
+ message: x ?? "Validation failed.",
2047
+ severity: "error"
2048
+ });
2049
+ return;
2050
+ }
2051
+ S({});
2052
+ const f = s.data.keyValue.trim(), M = s.data.keyIn;
2053
+ try {
2054
+ await r({
2055
+ security: {
2056
+ enabled: t.security?.enabled ?? !0,
2057
+ apiKey: {
2058
+ enabled: i === "apiKey",
2059
+ key: i === "apiKey" ? f : "",
2060
+ in: M
2061
+ }
2062
+ }
2063
+ }), S({}), v({
2064
+ message: "Updated security settings.",
2065
+ severity: "success"
2066
+ });
2067
+ } catch {
2068
+ v({
2069
+ message: "Failed to update security.",
2070
+ severity: "error"
2071
+ });
2072
+ }
2073
+ }, [t, i, c, d, r]), b = e || !t;
2074
+ return e ? /* @__PURE__ */ a(E, { spacing: 2, children: [
2075
+ /* @__PURE__ */ n($, { variant: "h6", children: "Authentication" }),
2076
+ /* @__PURE__ */ n(E, { spacing: 2, children: [1, 2, 3].map((s) => /* @__PURE__ */ a(E, { spacing: 0.5, children: [
2077
+ /* @__PURE__ */ n(ee, { variant: "text", width: 120, height: 16 }),
2078
+ /* @__PURE__ */ n(ee, { variant: "rounded", height: 40 })
2079
+ ] }, s)) })
2080
+ ] }) : t ? /* @__PURE__ */ a(E, { spacing: 2, children: [
2081
+ /* @__PURE__ */ n($, { variant: "h6", children: "Authentication" }),
2082
+ /* @__PURE__ */ n(D, { container: !0, spacing: 3, children: /* @__PURE__ */ n(D, { size: {
2083
+ xs: 12,
2084
+ md: 5
2085
+ }, children: /* @__PURE__ */ a(ge, { fullWidth: !0, disabled: b, children: [
2086
+ /* @__PURE__ */ n(ve, { children: "Authentication Method" }),
2087
+ /* @__PURE__ */ a(Xe, { size: "small", value: i || "", onChange: (s) => l(s.target.value || ""), children: [
2088
+ /* @__PURE__ */ n(_e, { value: "", children: "None" }),
2089
+ /* @__PURE__ */ n(_e, { value: "apiKey", children: "apiKey" })
2090
+ ] })
2091
+ ] }) }) }),
2092
+ i === "apiKey" && /* @__PURE__ */ a(D, { container: !0, spacing: 3, children: [
2093
+ /* @__PURE__ */ n(D, { size: {
2094
+ xs: 12,
2095
+ md: 5
2096
+ }, children: /* @__PURE__ */ a(ge, { fullWidth: !0, disabled: b, children: [
2097
+ /* @__PURE__ */ n(ve, { children: "Key Location" }),
2098
+ /* @__PURE__ */ n(Xe, { size: "small", value: d, onChange: (s) => u(s.target.value), children: tr.map((s) => /* @__PURE__ */ n(_e, { value: s.value, children: s.label }, s.value)) })
2099
+ ] }) }),
2100
+ /* @__PURE__ */ n(D, { size: {
2101
+ xs: 12,
2102
+ md: 5
2103
+ }, children: /* @__PURE__ */ a(ge, { fullWidth: !0, disabled: b, error: !!P.keyValue, children: [
2104
+ /* @__PURE__ */ n(ve, { children: d === "query" ? "Query Param Key" : "Header Key" }),
2105
+ /* @__PURE__ */ n(Le, { size: "small", value: c, onChange: (s) => {
2106
+ y(s.target.value), P.keyValue && S({});
2107
+ }, error: !!P.keyValue, helperText: P.keyValue, sx: {
2108
+ "& .MuiInputBase-input": {
2109
+ fontFamily: "monospace"
2110
+ }
2111
+ } })
2112
+ ] }) })
2113
+ ] }),
2114
+ /* @__PURE__ */ a(E, { spacing: 1.5, width: "100%", children: [
2115
+ /* @__PURE__ */ n(Ze, { in: !!L && !I, timeout: 300, children: L && /* @__PURE__ */ n(ce, { severity: L.severity, onClose: () => v(null), sx: {
2116
+ width: "100%",
2117
+ maxWidth: 480
2118
+ }, children: L.message }) }),
2119
+ /* @__PURE__ */ a(E, { direction: "row", spacing: 1.5, justifyContent: "flex-end", children: [
2120
+ /* @__PURE__ */ n(de, { variant: "outlined", onClick: p, disabled: !I || o, children: "Discard" }),
2121
+ /* @__PURE__ */ n(de, { variant: "contained", onClick: () => void h(), disabled: o || !I, children: o ? "Saving..." : "Save" })
2122
+ ] })
2123
+ ] })
2124
+ ] }) : null;
2125
+ }
2126
+ const ir = [
2127
+ "Overview",
2128
+ "Connection",
2129
+ "Access Control",
2130
+ "Security",
2131
+ "API Keys",
2132
+ "Rate Limiting",
2133
+ "Guardrails",
2134
+ "Consumers"
2135
+ // "Models",
2136
+ ];
2137
+ function Ae(t) {
2138
+ const e = Se(4), {
2139
+ value: r,
2140
+ index: o,
2141
+ children: i
2142
+ } = t, l = r !== o;
2143
+ let c;
2144
+ e[0] === Symbol.for("react.memo_cache_sentinel") ? (c = {
2145
+ pt: 2
2146
+ }, e[0] = c) : c = e[0];
2147
+ const y = r === o ? i : null;
2148
+ let d;
2149
+ return e[1] !== l || e[2] !== y ? (d = /* @__PURE__ */ n(se, { role: "tabpanel", hidden: l, sx: c, children: y }), e[1] = l, e[2] = y, e[3] = d) : d = e[3], d;
2150
+ }
2151
+ const sr = () => {
2152
+ const [t, e] = N(0), {
2153
+ providerId: r,
2154
+ orgId: o
2155
+ } = De(), {
2156
+ data: i,
2157
+ isLoading: l,
2158
+ error: c
2159
+ } = hn({
2160
+ orgName: o,
2161
+ providerId: r
2162
+ }), {
2163
+ mutateAsync: y,
2164
+ isPending: d
2165
+ } = mn(), u = H(async (f) => y({
2166
+ params: {
2167
+ orgName: o,
2168
+ providerId: r
2169
+ },
2170
+ body: {
2171
+ ...i,
2172
+ ...f
2173
+ }
2174
+ }), [o, r, i, y]), {
2175
+ data: L
2176
+ } = ut({
2177
+ orgName: o
2178
+ }), v = Q(() => {
2179
+ const f = i?.template;
2180
+ return !f || !L?.templates ? null : L.templates.find((M) => M.name === f || M.id === f) ?? null;
2181
+ }, [i?.template, L?.templates]), P = v?.metadata?.logoUrl, S = v?.name ?? i?.template ?? "", I = v?.metadata?.openapiSpecUrl, p = v?.metadata?.auth?.valuePrefix ?? "", h = i?.name ?? r ?? "", b = i?.version, s = i?.description?.trim();
2182
+ return /* @__PURE__ */ n(ht, { title: h, description: s, backHref: Ne(ze.children.org.children.llmProviders.path, {
2183
+ orgId: o ?? ""
2184
+ }), backLabel: "Back to LLM Providers", isLoading: l, titleTail: /* @__PURE__ */ a(E, { direction: "row", spacing: 1, alignItems: "center", sx: {
2185
+ ml: 1
2186
+ }, children: [
2187
+ S && /* @__PURE__ */ n(ue, { label: S, icon: P ? /* @__PURE__ */ n(se, { component: "img", src: P, alt: S, sx: {
2188
+ width: 14,
2189
+ height: 14
2190
+ } }) : void 0, size: "small" }),
2191
+ b && /* @__PURE__ */ n(ue, { label: b, size: "small", variant: "outlined" })
2192
+ ] }), children: /* @__PURE__ */ n(E, { spacing: 3, children: /* @__PURE__ */ a(Pe, { variant: "outlined", children: [
2193
+ /* @__PURE__ */ n(Mt, { value: t, onChange: (f, M) => e(M), variant: "scrollable", allowScrollButtonsMobile: !0, children: ir.map((f) => /* @__PURE__ */ n(at, { label: f }, f)) }),
2194
+ /* @__PURE__ */ n($e, {}),
2195
+ /* @__PURE__ */ a(se, { sx: {
2196
+ px: 3,
2197
+ pb: 3
2198
+ }, children: [
2199
+ /* @__PURE__ */ n(Ae, { value: t, index: 0, children: /* @__PURE__ */ n(Vn, { providerData: i, openapiSpecUrl: I, orgName: o, providerId: r, isLoading: l, error: c instanceof Error ? c : c ? new Error(Fe(c)) : null, onUpdate: u, isUpdating: d }) }),
2200
+ /* @__PURE__ */ n(Ae, { value: t, index: 1, children: /* @__PURE__ */ n(Wn, { providerData: i, valuePrefix: p, isLoading: l, onUpdate: u, isUpdating: d }) }),
2201
+ /* @__PURE__ */ n(Ae, { value: t, index: 2, children: /* @__PURE__ */ n(zn, { providerData: i, openapiSpecUrl: I, isLoading: l, onUpdate: u, isUpdating: d }) }),
2202
+ /* @__PURE__ */ n(Ae, { value: t, index: 3, children: /* @__PURE__ */ n(rr, { providerData: i, isLoading: l, onUpdate: u, isUpdating: d }) }),
2203
+ /* @__PURE__ */ n(Ae, { value: t, index: 4, children: /* @__PURE__ */ n(Rn, { providerData: i, orgName: o, providerId: r, isLoading: l, error: c instanceof Error ? c : c ? new Error(Fe(c)) : null }) }),
2204
+ /* @__PURE__ */ n(Ae, { value: t, index: 5, children: /* @__PURE__ */ n(er, { providerData: i, openapiSpecUrl: I, isLoading: l, onUpdate: u, isUpdating: d }) }),
2205
+ /* @__PURE__ */ n(Ae, { value: t, index: 6, children: /* @__PURE__ */ n(Un, { providerData: i, openapiSpecUrl: I, isLoading: l, error: c instanceof Error ? c : c ? new Error(Fe(c)) : null, onUpdate: u, isUpdating: d }) }),
2206
+ /* @__PURE__ */ n(Ae, { value: t, index: 7, children: /* @__PURE__ */ n(_n, { orgName: o, providerId: r }) })
2207
+ ] })
2208
+ ] }) }) });
2209
+ }, or = () => {
2210
+ const t = Se(6), {
2211
+ orgId: e
2212
+ } = De();
2213
+ let r;
2214
+ t[0] === Symbol.for("react.memo_cache_sentinel") ? (r = /* @__PURE__ */ n(tt, { index: !0, element: /* @__PURE__ */ n(ht, { title: "LLM Service Providers", disableIcon: !0, children: /* @__PURE__ */ n(An, {}) }) }), t[0] = r) : r = t[0];
2215
+ let o;
2216
+ t[1] === Symbol.for("react.memo_cache_sentinel") ? (o = /* @__PURE__ */ n(tt, { path: "view/:providerId", element: /* @__PURE__ */ n(sr, {}) }), t[1] = o) : o = t[1];
2217
+ let i;
2218
+ t[2] !== e ? (i = Ne(ze.children.org.children.llmProviders.path, {
2219
+ orgId: e
2220
+ }), t[2] = e, t[3] = i) : i = t[3];
2221
+ let l;
2222
+ return t[4] !== i ? (l = /* @__PURE__ */ a(Dt, { children: [
2223
+ r,
2224
+ o,
2225
+ /* @__PURE__ */ n(tt, { path: "*", element: /* @__PURE__ */ n(en, { to: i, replace: !0 }) })
2226
+ ] }), t[4] = i, t[5] = l) : l = t[5], l;
2227
+ }, ar = () => {
2228
+ const t = Se(33), {
2229
+ orgId: e
2230
+ } = De(), r = dt();
2231
+ let o;
2232
+ t[0] !== e ? (o = e ? Ne(ze.children.org.children.llmProviders.path, {
2233
+ orgId: e
2234
+ }) : "#", t[0] = e, t[1] = o) : o = t[1];
2235
+ const i = o, l = e ?? "";
2236
+ let c;
2237
+ t[2] !== l ? (c = {
2238
+ orgName: l
2239
+ }, t[2] = l, t[3] = c) : c = t[3];
2240
+ let y;
2241
+ t[4] === Symbol.for("react.memo_cache_sentinel") ? (y = {
2242
+ limit: 50,
2243
+ offset: 0
2244
+ }, t[4] = y) : y = t[4];
2245
+ const {
2246
+ data: d,
2247
+ isLoading: u,
2248
+ error: L
2249
+ } = ut(c, y), v = e ?? "";
2250
+ let P;
2251
+ t[5] !== v ? (P = {
2252
+ orgName: v
2253
+ }, t[5] = v, t[6] = P) : P = t[6];
2254
+ const {
2255
+ error: S
2256
+ } = zt(P), {
2257
+ mutate: I,
2258
+ isPending: p,
2259
+ error: h
2260
+ } = pn(), b = d?.templates;
2261
+ let s;
2262
+ t[7] !== b ? (s = Sn(b), t[7] = b, t[8] = s) : s = t[8];
2263
+ const f = s;
2264
+ let M;
2265
+ e: {
2266
+ if (!e) {
2267
+ M = "Organization is required to add an LLM provider.";
2268
+ break e;
2269
+ }
2270
+ M = null;
2271
+ }
2272
+ const w = M;
2273
+ let x;
2274
+ e: {
2275
+ if (L) {
2276
+ let A;
2277
+ t[9] !== L ? (A = Fe(L), t[9] = L, t[10] = A) : A = t[10], x = A;
2278
+ break e;
2279
+ }
2280
+ if (S) {
2281
+ let A;
2282
+ t[11] !== S ? (A = Fe(S), t[11] = S, t[12] = A) : A = t[12], x = A;
2283
+ break e;
2284
+ }
2285
+ if (h) {
2286
+ x = h?.message || "Failed to create LLM provider";
2287
+ break e;
2288
+ }
2289
+ x = null;
2290
+ }
2291
+ const U = x;
2292
+ let _;
2293
+ t[13] !== I || t[14] !== r || t[15] !== e || t[16] !== f ? (_ = (A, T) => {
2294
+ if (!e)
2295
+ return;
2296
+ const Y = In(A, T, f);
2297
+ I({
2298
+ params: {
2299
+ orgName: e
2300
+ },
2301
+ body: Y
2302
+ }, {
2303
+ onSuccess: (ae) => {
2304
+ const q = Ne(ze.children.org.children.llmProviders.children.view.path, {
2305
+ orgId: e,
2306
+ providerId: ae.uuid
2307
+ });
2308
+ r(q);
2309
+ }
2310
+ });
2311
+ }, t[13] = I, t[14] = r, t[15] = e, t[16] = f, t[17] = _) : _ = t[17];
2312
+ const K = _, C = e ?? "";
2313
+ let g;
2314
+ t[18] !== i || t[19] !== r ? (g = () => r(i), t[18] = i, t[19] = r, t[20] = g) : g = t[20];
2315
+ let F;
2316
+ t[21] !== U || t[22] !== K || t[23] !== p || t[24] !== u || t[25] !== w || t[26] !== C || t[27] !== g || t[28] !== f ? (F = /* @__PURE__ */ n(kn, { orgId: C, templates: f, isLoadingTemplates: u, missingParamsMessage: w, errorMessage: U, isSubmitting: p, onCancel: g, onSubmit: K }), t[21] = U, t[22] = K, t[23] = p, t[24] = u, t[25] = w, t[26] = C, t[27] = g, t[28] = f, t[29] = F) : F = t[29];
2317
+ let O;
2318
+ return t[30] !== i || t[31] !== F ? (O = /* @__PURE__ */ n(ht, { title: "Add LLM Service Provider", backHref: i, disableIcon: !0, backLabel: "Back to Providers List", children: F }), t[30] = i, t[31] = F, t[32] = O) : O = t[32], O;
2319
+ }, Pr = {
2320
+ title: "LLM Service Providers",
2321
+ description: "A page component for LLM Service Provider management",
2322
+ icon: Qt,
2323
+ path: "/llm-providers",
2324
+ component: Pt,
2325
+ levels: {
2326
+ component: Pt,
2327
+ organization: or,
2328
+ addLLMProvidersOrganization: ar
2329
+ }
2330
+ };
2331
+ export {
2332
+ kn as AddLLMProviderForm,
2333
+ ar as AddLLMProvidersOrganization,
2334
+ Pt as LLMProvidersComponent,
2335
+ or as LLMProvidersOrganization,
2336
+ In as buildCreateLLMProviderRequest,
2337
+ Sn as mapLLMProviderTemplatesToCards,
2338
+ Pr as metaData,
2339
+ Ir as toProviderId
2340
+ };