@w6w/embed 0.2.26 → 0.2.28

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 (54) hide show
  1. package/dist/{CreateFunctionModal-DScxp_LN.js → CreateFunctionModal-B3LpcuI9.js} +2 -2
  2. package/dist/{CreateFunctionModal-DScxp_LN.js.map → CreateFunctionModal-B3LpcuI9.js.map} +1 -1
  3. package/dist/DocumentFormModal-DieWYFi4.js +175 -0
  4. package/dist/DocumentFormModal-DieWYFi4.js.map +1 -0
  5. package/dist/{ImportSpecModal-VdYN1QeZ.js → ImportSpecModal-xwTzj4KB.js} +2 -2
  6. package/dist/{ImportSpecModal-VdYN1QeZ.js.map → ImportSpecModal-xwTzj4KB.js.map} +1 -1
  7. package/dist/ModelRoutesManager-DtByS4mE.js +422 -0
  8. package/dist/ModelRoutesManager-DtByS4mE.js.map +1 -0
  9. package/dist/{WorkflowEditor-CGKoeSG7.js → WorkflowEditor-CvWkVmFn.js} +2 -2
  10. package/dist/{WorkflowEditor-CGKoeSG7.js.map → WorkflowEditor-CvWkVmFn.js.map} +1 -1
  11. package/dist/ai-keys-D676ly41.js +53 -0
  12. package/dist/ai-keys-D676ly41.js.map +1 -0
  13. package/dist/credentials-4Nf2GfMc.js +212 -0
  14. package/dist/credentials-4Nf2GfMc.js.map +1 -0
  15. package/dist/{editor-tools-Brw0cv2F.js → editor-tools-CVYTsVFN.js} +326 -326
  16. package/dist/editor-tools-CVYTsVFN.js.map +1 -0
  17. package/dist/editor.mjs +1 -1
  18. package/dist/editors.mjs +7 -7
  19. package/dist/{endpoints-DSRo1Lc5.js → endpoints-DArAqoLT.js} +15 -15
  20. package/dist/endpoints-DArAqoLT.js.map +1 -0
  21. package/dist/forms/ModelRoutesManager.d.ts +8 -0
  22. package/dist/forms.mjs +128 -133
  23. package/dist/forms.mjs.map +1 -1
  24. package/dist/index.mjs +16 -16
  25. package/dist/lib/callable-descriptors.d.ts +1 -1
  26. package/dist/lib/document-upload.d.ts +8 -0
  27. package/dist/lists/MyAiKeys.d.ts +5 -0
  28. package/dist/lists/TagChips.d.ts +4 -0
  29. package/dist/lists.d.ts +2 -0
  30. package/dist/lists.mjs +1552 -1072
  31. package/dist/lists.mjs.map +1 -1
  32. package/dist/models-CI0vLJ6o.js +346 -0
  33. package/dist/models-CI0vLJ6o.js.map +1 -0
  34. package/dist/rail.mjs +1 -1
  35. package/dist/repos/ai-keys.d.ts +14 -0
  36. package/dist/repos/credentials.d.ts +14 -14
  37. package/dist/repos/index.d.ts +1 -0
  38. package/dist/repos/models.d.ts +53 -4
  39. package/dist/repos.mjs +177 -162
  40. package/dist/repos.mjs.map +1 -1
  41. package/dist/{spec-import-SWOonsNr.js → spec-import-0B6oUewa.js} +5 -5
  42. package/dist/{spec-import-SWOonsNr.js.map → spec-import-0B6oUewa.js.map} +1 -1
  43. package/package.json +5 -5
  44. package/src/styles.css +23 -0
  45. package/dist/DocumentFormModal-Br4s8wmi.js +0 -89
  46. package/dist/DocumentFormModal-Br4s8wmi.js.map +0 -1
  47. package/dist/ModelRoutesManager-Bv6qefnq.js +0 -345
  48. package/dist/ModelRoutesManager-Bv6qefnq.js.map +0 -1
  49. package/dist/credentials-CMR_wEvx.js +0 -196
  50. package/dist/credentials-CMR_wEvx.js.map +0 -1
  51. package/dist/editor-tools-Brw0cv2F.js.map +0 -1
  52. package/dist/endpoints-DSRo1Lc5.js.map +0 -1
  53. package/dist/models-CK1KHd39.js +0 -311
  54. package/dist/models-CK1KHd39.js.map +0 -1
@@ -1,345 +0,0 @@
1
- import { jsx as t, jsxs as l, Fragment as U } from "react/jsx-runtime";
2
- import { ApiError as W } from "@w6w/sdk";
3
- import { EmptyState as B, DataTable as K, EditButton as Y, DeleteButton as q, useEnterSubmit as z } from "@w6w/ui";
4
- import { useState as h } from "react";
5
- import { C as G, M as J } from "./ConfirmModal-Pv2-A_3U.js";
6
- import { u as V } from "./project-context-Tvp-La7A.js";
7
- import { u as X } from "./connections-CzsCyIxY.js";
8
- import { u as Z, a as ee, b as te, c as ne, d as oe, e as le, f as ae } from "./models-CK1KHd39.js";
9
- const L = {
10
- invalid_route_name: "That route name is not valid. Use lowercase letters, digits and dashes (e.g. gpt-4o-fast): 3 to 39 characters, starting with a letter, no double dashes, not ending in a dash."
11
- };
12
- function H(e) {
13
- return e instanceof W ? Object.hasOwn(L, e.code) ? L[e.code] : e.message : e instanceof Error ? e.message : String(e);
14
- }
15
- function O(e) {
16
- const a = e.fallbacks.length, i = a === 0 ? "" : ` · ${a} fallback${a === 1 ? "" : "s"}`;
17
- return `${e.modelId} via ${e.connectionId}${i}`;
18
- }
19
- function ge(e) {
20
- var I;
21
- const a = V(e.projectId), [i, c] = h(
22
- () => e.initialEditRouteId ? { routeId: e.initialEditRouteId, connection: e.initialConnection } : null
23
- ), [s, b] = h(null), [r, n] = h(null), u = Z(a ?? void 0), g = ee(), f = u.data ?? [], M = a != null, C = (i == null ? void 0 : i.routeId) == null ? void 0 : f.find((o) => o.id === i.routeId), E = i != null && (i.routeId == null || C != null), y = [
24
- {
25
- key: "name",
26
- header: "Route",
27
- render: (o) => /* @__PURE__ */ l("div", { className: "list-main", style: { maxWidth: 0, minWidth: "100%" }, children: [
28
- /* @__PURE__ */ t("strong", { className: "list-name", title: o.name, children: o.name }),
29
- " ",
30
- /* @__PURE__ */ t("span", { className: o.status === "broken" ? "tag warn" : "tag", children: o.status }),
31
- /* @__PURE__ */ t("div", { className: "muted small list-preview", title: O(o), children: O(o) })
32
- ] })
33
- },
34
- {
35
- key: "connection",
36
- header: "Connection",
37
- render: (o) => /* @__PURE__ */ t("code", { children: o.connectionId })
38
- },
39
- {
40
- key: "actions",
41
- header: "",
42
- align: "right",
43
- link: !1,
44
- render: (o) => /* @__PURE__ */ l("div", { style: { display: "flex", gap: "var(--w6w-sp-1-5)" }, children: [
45
- /* @__PURE__ */ t(
46
- Y,
47
- {
48
- label: "Edit",
49
- onClick: () => c({ routeId: o.id }),
50
- "data-testid": `model-route-edit-${o.name}`
51
- }
52
- ),
53
- /* @__PURE__ */ t(
54
- q,
55
- {
56
- label: "Delete",
57
- onClick: () => b(o),
58
- disabled: g.isPending,
59
- "data-testid": `model-route-delete-${o.name}`
60
- }
61
- )
62
- ] })
63
- }
64
- ];
65
- return /* @__PURE__ */ t("div", { className: "w6w-embed-root", children: /* @__PURE__ */ l("section", { className: "section", children: [
66
- /* @__PURE__ */ l("div", { className: "section-head", children: [
67
- /* @__PURE__ */ l("div", { children: [
68
- /* @__PURE__ */ t("h3", { children: "Model routes" }),
69
- /* @__PURE__ */ t("p", { className: "muted small", children: "The names callers ask for. Each route resolves to a model through a connection, with fallbacks when that model cannot answer." })
70
- ] }),
71
- /* @__PURE__ */ t(
72
- "button",
73
- {
74
- type: "button",
75
- className: "btn",
76
- disabled: !M,
77
- onClick: () => c({ routeId: null }),
78
- "data-testid": "model-route-add",
79
- children: "+ Add route"
80
- }
81
- )
82
- ] }),
83
- r && /* @__PURE__ */ t("div", { className: "result error", role: "alert", "data-testid": "model-route-delete-error", children: r }),
84
- /* @__PURE__ */ l("div", { children: [
85
- u.isLoading && /* @__PURE__ */ t("p", { className: "muted", children: "Loading…" }),
86
- ((I = u.data) == null ? void 0 : I.length) === 0 && /* @__PURE__ */ t(B, { testId: "model-routes-empty", children: "No model routes yet. Add one to give callers a stable name for a model." }),
87
- f.length > 0 && /* @__PURE__ */ t(
88
- K,
89
- {
90
- columns: y,
91
- rows: f,
92
- rowKey: (o) => o.id,
93
- testId: "model-routes-table"
94
- }
95
- )
96
- ] }),
97
- E && a != null && i != null && /* @__PURE__ */ t(
98
- ie,
99
- {
100
- project: a,
101
- initial: C,
102
- initialConnection: i.connection,
103
- onClose: () => c(null),
104
- onSaved: () => c(null)
105
- }
106
- ),
107
- s != null && a != null && /* @__PURE__ */ t(
108
- G,
109
- {
110
- title: "Delete model route",
111
- message: `Delete the model route "${s.name}"? Calls that name it will fail until another route covers the model.`,
112
- confirmLabel: "Delete",
113
- onConfirm: () => {
114
- const o = s.name;
115
- n(null), g.mutate(
116
- { project: a, name: o },
117
- {
118
- onError: (N) => n(`Could not delete "${o}": ${H(N)}`)
119
- }
120
- ), b(null);
121
- },
122
- onClose: () => b(null)
123
- }
124
- )
125
- ] }) });
126
- }
127
- function ie(e) {
128
- var D, A, Q, F, T;
129
- const a = !!e.initial, [i, c] = h(((D = e.initial) == null ? void 0 : D.name) ?? ""), [s, b] = h(((A = e.initial) == null ? void 0 : A.modelId) ?? ""), [r, n] = h(
130
- e.initialConnection ?? ((Q = e.initial) == null ? void 0 : Q.connectionId) ?? ""
131
- ), [u, g] = h(((F = e.initial) == null ? void 0 : F.fallbacks) ?? []), [f, M] = h(null), C = te({ status: "active" }), E = X(), y = ((T = C.data) == null ? void 0 : T.models) ?? [], I = ne(), o = oe(
132
- E.data ?? [],
133
- I.data ?? [],
134
- "complete"
135
- ), N = C.isSuccess && y.length === 0, p = le(), x = ae(), R = p.isPending || x.isPending, P = !!i && !!s && !!r && u.every((d) => !!d.model && !!d.connection) && !R;
136
- function j() {
137
- M(null);
138
- const d = {
139
- onSuccess: () => e.onSaved(),
140
- onError: (m) => M(H(m))
141
- };
142
- if (e.initial) {
143
- x.mutate(
144
- {
145
- project: e.project,
146
- name: e.initial.name,
147
- patch: { model: s, connection: r, fallbacks: u }
148
- },
149
- d
150
- );
151
- return;
152
- }
153
- p.mutate(
154
- {
155
- project: e.project,
156
- input: { name: i, model: s, connection: r, ...u.length > 0 ? { fallbacks: u } : {} }
157
- },
158
- d
159
- );
160
- }
161
- const w = z(j, { enabled: P });
162
- return /* @__PURE__ */ l(
163
- J,
164
- {
165
- title: e.initial ? `Edit ${e.initial.name}` : "Add model route",
166
- onClose: e.onClose,
167
- children: [
168
- /* @__PURE__ */ l("div", { className: "modal-body", children: [
169
- /* @__PURE__ */ l("label", { className: "field", children: [
170
- /* @__PURE__ */ t("span", { children: "Name" }),
171
- /* @__PURE__ */ t(
172
- "input",
173
- {
174
- type: "text",
175
- value: i,
176
- disabled: a,
177
- onChange: (d) => c(d.target.value),
178
- placeholder: "e.g. gpt-4o-fast",
179
- maxLength: 64,
180
- "data-testid": "model-route-name",
181
- ...w
182
- }
183
- ),
184
- !a && /* @__PURE__ */ t("span", { className: "hint", children: "3 to 39 characters: lowercase letters, digits and dashes, starting with a letter, no double dashes, not ending in a dash. Callers use this name; it cannot be renamed later." })
185
- ] }),
186
- N && /* @__PURE__ */ t(B, { testId: "model-route-catalog-empty", children: "The model catalog is empty. Open the Catalog tab to discover models; until then you can type ids by hand." }),
187
- /* @__PURE__ */ t(
188
- _,
189
- {
190
- label: "",
191
- model: s,
192
- connection: r,
193
- onModel: b,
194
- onConnection: n,
195
- models: y,
196
- connections: o,
197
- catalogEmpty: N,
198
- testIdPrefix: "model-route",
199
- enterSubmit: w
200
- }
201
- ),
202
- /* @__PURE__ */ t("span", { className: "hint", children: "The connection holds the credentials for the model. Changing it fixes a broken route." }),
203
- /* @__PURE__ */ l("div", { className: "field", children: [
204
- /* @__PURE__ */ t("span", { children: "Fallbacks" }),
205
- u.map((d, m) => (
206
- // biome-ignore lint/suspicious/noArrayIndexKey: rows have no identity beyond position
207
- /* @__PURE__ */ l("div", { style: { display: "flex", gap: "var(--w6w-sp-1-5)" }, children: [
208
- /* @__PURE__ */ t(
209
- _,
210
- {
211
- label: `Fallback ${m + 1} `,
212
- model: d.model,
213
- connection: d.connection,
214
- onModel: (k) => g(($) => $.map((v, S) => S === m ? { ...v, model: k } : v)),
215
- onConnection: (k) => g(($) => $.map((v, S) => S === m ? { ...v, connection: k } : v)),
216
- models: y,
217
- connections: o,
218
- catalogEmpty: N,
219
- testIdPrefix: `model-route-fallback-${m}`,
220
- enterSubmit: w
221
- }
222
- ),
223
- /* @__PURE__ */ t(
224
- "button",
225
- {
226
- type: "button",
227
- className: "btn ghost",
228
- onClick: () => g((k) => k.filter(($, v) => v !== m)),
229
- "data-testid": `model-route-fallback-${m}-remove`,
230
- children: "Remove"
231
- }
232
- )
233
- ] }, m)
234
- )),
235
- /* @__PURE__ */ t(
236
- "button",
237
- {
238
- type: "button",
239
- className: "btn ghost",
240
- onClick: () => g((d) => [...d, { model: "", connection: "" }]),
241
- "data-testid": "model-route-fallback-add",
242
- children: "+ Add fallback"
243
- }
244
- )
245
- ] }),
246
- f && /* @__PURE__ */ t("div", { className: "result error", "data-testid": "model-route-error", children: f })
247
- ] }),
248
- /* @__PURE__ */ l("div", { className: "modal-actions", children: [
249
- /* @__PURE__ */ t("button", { type: "button", className: "btn ghost", onClick: e.onClose, children: "Cancel" }),
250
- /* @__PURE__ */ t(
251
- "button",
252
- {
253
- type: "button",
254
- className: "btn",
255
- disabled: !P,
256
- onClick: j,
257
- "data-testid": "model-route-save",
258
- children: R ? "Saving…" : a ? "Save changes" : "Save route"
259
- }
260
- )
261
- ] })
262
- ]
263
- }
264
- );
265
- }
266
- function _(e) {
267
- const a = e.models.find((n) => n.id === e.model), i = a ? e.connections.filter((n) => n.appId === a.providerAppId) : e.connections, c = a != null && i.length > 0, s = c ? i : e.connections, b = s.some((n) => n.id === e.connection), r = e.models.some((n) => n.id === e.model);
268
- return /* @__PURE__ */ l(U, { children: [
269
- /* @__PURE__ */ l("div", { className: "field", children: [
270
- /* @__PURE__ */ l("span", { children: [
271
- e.label,
272
- "Model"
273
- ] }),
274
- e.catalogEmpty ? /* @__PURE__ */ t(
275
- "input",
276
- {
277
- type: "text",
278
- value: e.model,
279
- onChange: (n) => e.onModel(n.target.value),
280
- placeholder: "model id",
281
- "aria-label": `${e.label}Model`,
282
- "data-testid": `${e.testIdPrefix}-model`,
283
- ...e.enterSubmit
284
- }
285
- ) : /* @__PURE__ */ l(
286
- "select",
287
- {
288
- value: e.model,
289
- onChange: (n) => e.onModel(n.target.value),
290
- "aria-label": `${e.label}Model`,
291
- "data-testid": `${e.testIdPrefix}-model`,
292
- children: [
293
- /* @__PURE__ */ t("option", { value: "", children: "Select a model…" }),
294
- e.model && !r && /* @__PURE__ */ t("option", { value: e.model, children: e.model }),
295
- e.models.map((n) => /* @__PURE__ */ l("option", { value: n.id, children: [
296
- n.displayName,
297
- " (",
298
- n.provider,
299
- ")"
300
- ] }, n.id))
301
- ]
302
- }
303
- )
304
- ] }),
305
- /* @__PURE__ */ l("div", { className: "field", children: [
306
- /* @__PURE__ */ l("span", { children: [
307
- e.label,
308
- "Connection"
309
- ] }),
310
- e.catalogEmpty && e.connections.length === 0 ? /* @__PURE__ */ t(
311
- "input",
312
- {
313
- type: "text",
314
- value: e.connection,
315
- onChange: (n) => e.onConnection(n.target.value),
316
- placeholder: "connection id",
317
- "aria-label": `${e.label}Connection`,
318
- "data-testid": `${e.testIdPrefix}-connection`,
319
- ...e.enterSubmit
320
- }
321
- ) : /* @__PURE__ */ l(
322
- "select",
323
- {
324
- value: e.connection,
325
- onChange: (n) => e.onConnection(n.target.value),
326
- "aria-label": `${e.label}Connection`,
327
- "data-testid": `${e.testIdPrefix}-connection`,
328
- children: [
329
- /* @__PURE__ */ t("option", { value: "", children: "Select a connection…" }),
330
- e.connection && !b && /* @__PURE__ */ t("option", { value: e.connection, children: e.connection }),
331
- s.map((n) => /* @__PURE__ */ l("option", { value: n.id, disabled: n.disabledReason != null, children: [
332
- n.displayName,
333
- c ? "" : ` (${n.appId})`,
334
- n.disabledReason != null ? ` — ${n.disabledReason}` : ""
335
- ] }, n.id))
336
- ]
337
- }
338
- )
339
- ] })
340
- ] });
341
- }
342
- export {
343
- ge as M
344
- };
345
- //# sourceMappingURL=ModelRoutesManager-Bv6qefnq.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ModelRoutesManager-Bv6qefnq.js","sources":["../src/forms/ModelRoutesManager.tsx"],"sourcesContent":["/**\n * `<ModelRoutesManager>` — list, add, edit and delete the project's model routes. A route is the\n * name callers ask for; it resolves to one model reached through one connection, plus optional\n * fallbacks. `broken` marks a route whose connection stopped working, so it stays visible (and\n * editable) instead of silently disappearing from the list.\n *\n * The project comes from `useEditorProject(projectId)`: omitted defers to `<W6WEmbedProvider\n * project>`; `null` or `\"\"` REFUSES — the list query is disabled, no `/model-routes` request is\n * sent and \"Add\" is disabled. Every write names the resolved project, never `undefined`.\n *\n * `initialEditRouteId` (with `initialConnection`) opens that route's editor on mount, prefilled:\n * the connection dependents view's reconnect affordance lands here, naming the replacement\n * connection. Both are read ONCE — remount to reopen the editor.\n */\nimport { ApiError } from \"@w6w/sdk\";\nimport {\n DataTable,\n type DataTableColumn,\n DeleteButton,\n EditButton,\n EmptyState,\n useEnterSubmit,\n} from \"@w6w/ui\";\nimport { type ReactNode, useState } from \"react\";\nimport { ConfirmModal } from \"../chrome/ConfirmModal.tsx\";\nimport { Modal } from \"../chrome/Modal.tsx\";\nimport { useEditorProject } from \"../project-context.ts\";\nimport { useConnectionsQuery } from \"../repos/connections.ts\";\nimport {\n type ConnectionChoice,\n type Model,\n type ModelFallback,\n type ModelRoute,\n connectionChoices,\n useAllModelCatalogQuery,\n useCreateModelRouteMutation,\n useDeleteModelRouteMutation,\n useModelProvidersQuery,\n useModelRoutesQuery,\n useUpdateModelRouteMutation,\n} from \"../repos/models.ts\";\n\n/**\n * Actionable copy for the route write failures the server names by code. `invalid_route_name` is\n * a 400 the NAME field caused, so it states the rule instead of only echoing the server's\n * sentence; any other error falls back to its own message.\n */\nconst COPY: Record<string, string> = {\n invalid_route_name:\n \"That route name is not valid. Use lowercase letters, digits and dashes (e.g. gpt-4o-fast): 3 to 39 characters, starting with a letter, no double dashes, not ending in a dash.\",\n};\n\nexport function modelRouteErrorCopy(e: unknown): string {\n if (e instanceof ApiError) {\n if (Object.hasOwn(COPY, e.code)) return COPY[e.code];\n return e.message;\n }\n return e instanceof Error ? e.message : String(e);\n}\n\nexport interface ModelRoutesManagerProps {\n /**\n * The project whose routes are managed. Omitted: the `<W6WEmbedProvider project>`. `null` or\n * `\"\"`: no project — nothing is requested and nothing can be written.\n */\n projectId?: string | null;\n /** Open this route's editor on mount (read once). The dependents view's reconnect passes it. */\n initialEditRouteId?: string;\n /** Prefill the editor's connection — a reconnect names the connection that should replace it. */\n initialConnection?: string;\n}\n\n/** Which route the editor has open: `routeId: null` is the create form. */\ninterface EditorState {\n routeId: string | null;\n connection?: string;\n}\n\n/** One-line summary of a route's resolution, safe against long ids. */\nfunction routeSummary(r: ModelRoute): string {\n const fallbacks = r.fallbacks.length;\n const tail = fallbacks === 0 ? \"\" : ` · ${fallbacks} fallback${fallbacks === 1 ? \"\" : \"s\"}`;\n return `${r.modelId} via ${r.connectionId}${tail}`;\n}\n\nexport function ModelRoutesManager(props: ModelRoutesManagerProps): ReactNode {\n const project = useEditorProject(props.projectId);\n const [editor, setEditor] = useState<EditorState | null>(() =>\n props.initialEditRouteId\n ? { routeId: props.initialEditRouteId, connection: props.initialConnection }\n : null,\n );\n const [pending, setPending] = useState<ModelRoute | null>(null);\n const [deleteError, setDeleteError] = useState<string | null>(null);\n\n const routesQuery = useModelRoutesQuery(project ?? undefined);\n const deleteMut = useDeleteModelRouteMutation();\n const routes = routesQuery.data ?? [];\n const canCreate = project != null;\n // The reconnect flow names a route by id; the row itself arrives with the list.\n const editing = editor?.routeId == null ? undefined : routes.find((r) => r.id === editor.routeId);\n const editorReady = editor != null && (editor.routeId == null || editing != null);\n\n const columns: DataTableColumn<ModelRoute>[] = [\n {\n key: \"name\",\n header: \"Route\",\n render: (r) => (\n <div className=\"list-main\" style={{ maxWidth: 0, minWidth: \"100%\" }}>\n <strong className=\"list-name\" title={r.name}>\n {r.name}\n </strong>{\" \"}\n <span className={r.status === \"broken\" ? \"tag warn\" : \"tag\"}>{r.status}</span>\n <div className=\"muted small list-preview\" title={routeSummary(r)}>\n {routeSummary(r)}\n </div>\n </div>\n ),\n },\n {\n key: \"connection\",\n header: \"Connection\",\n render: (r) => <code>{r.connectionId}</code>,\n },\n {\n key: \"actions\",\n header: \"\",\n align: \"right\",\n link: false,\n render: (r) => (\n <div style={{ display: \"flex\", gap: \"var(--w6w-sp-1-5)\" }}>\n <EditButton\n label=\"Edit\"\n onClick={() => setEditor({ routeId: r.id })}\n data-testid={`model-route-edit-${r.name}`}\n />\n <DeleteButton\n label=\"Delete\"\n onClick={() => setPending(r)}\n disabled={deleteMut.isPending}\n data-testid={`model-route-delete-${r.name}`}\n />\n </div>\n ),\n },\n ];\n\n return (\n <div className=\"w6w-embed-root\">\n <section className=\"section\">\n <div className=\"section-head\">\n <div>\n <h3>Model routes</h3>\n <p className=\"muted small\">\n The names callers ask for. Each route resolves to a model through a connection, with\n fallbacks when that model cannot answer.\n </p>\n </div>\n <button\n type=\"button\"\n className=\"btn\"\n disabled={!canCreate}\n onClick={() => setEditor({ routeId: null })}\n data-testid=\"model-route-add\"\n >\n + Add route\n </button>\n </div>\n\n {deleteError && (\n <div className=\"result error\" role=\"alert\" data-testid=\"model-route-delete-error\">\n {deleteError}\n </div>\n )}\n\n <div>\n {routesQuery.isLoading && <p className=\"muted\">Loading…</p>}\n {routesQuery.data?.length === 0 && (\n <EmptyState testId=\"model-routes-empty\">\n No model routes yet. Add one to give callers a stable name for a model.\n </EmptyState>\n )}\n {routes.length > 0 && (\n <DataTable\n columns={columns}\n rows={routes}\n rowKey={(r) => r.id}\n testId=\"model-routes-table\"\n />\n )}\n </div>\n\n {editorReady && project != null && editor != null && (\n <RouteModal\n project={project}\n initial={editing}\n initialConnection={editor.connection}\n onClose={() => setEditor(null)}\n onSaved={() => setEditor(null)}\n />\n )}\n\n {pending != null && project != null && (\n <ConfirmModal\n title=\"Delete model route\"\n message={`Delete the model route \"${pending.name}\"? Calls that name it will fail until another route covers the model.`}\n confirmLabel=\"Delete\"\n onConfirm={() => {\n const name = pending.name;\n setDeleteError(null);\n deleteMut.mutate(\n { project, name },\n {\n onError: (e: unknown) =>\n setDeleteError(`Could not delete \"${name}\": ${modelRouteErrorCopy(e)}`),\n },\n );\n setPending(null);\n }}\n onClose={() => setPending(null)}\n />\n )}\n </section>\n </div>\n );\n}\n\n/**\n * Create/edit modal. The name is the route's address, so it is fixed once created (the server\n * patches by name); model and connection stay editable — a reconnect is exactly a connection\n * change.\n */\nfunction RouteModal(props: {\n project: string;\n initial?: ModelRoute;\n initialConnection?: string;\n onClose: () => void;\n onSaved: () => void;\n}) {\n const isEdit = !!props.initial;\n const [name, setName] = useState(props.initial?.name ?? \"\");\n const [model, setModel] = useState(props.initial?.modelId ?? \"\");\n const [connection, setConnection] = useState(\n props.initialConnection ?? props.initial?.connectionId ?? \"\",\n );\n const [fallbacks, setFallbacks] = useState<ModelFallback[]>(props.initial?.fallbacks ?? []);\n const [error, setError] = useState<string | null>(null);\n\n const catalog = useAllModelCatalogQuery({ status: \"active\" });\n const connectionsQuery = useConnectionsQuery();\n const models = catalog.data?.models ?? [];\n const providersQuery = useModelProvidersQuery();\n // Descriptor-driven: only designated providers, disabled with a reason when `complete` is not\n // supported. Never an app id or category guess.\n const connections = connectionChoices(\n connectionsQuery.data ?? [],\n providersQuery.data ?? [],\n \"complete\",\n );\n const catalogEmpty = catalog.isSuccess && models.length === 0;\n\n const createMut = useCreateModelRouteMutation();\n const updateMut = useUpdateModelRouteMutation();\n const saving = createMut.isPending || updateMut.isPending;\n const canSave =\n !!name &&\n !!model &&\n !!connection &&\n fallbacks.every((f) => !!f.model && !!f.connection) &&\n !saving;\n\n function save() {\n setError(null);\n const onSettled = {\n onSuccess: () => props.onSaved(),\n onError: (e: unknown) => setError(modelRouteErrorCopy(e)),\n };\n if (props.initial) {\n updateMut.mutate(\n {\n project: props.project,\n name: props.initial.name,\n patch: { model, connection, fallbacks },\n },\n onSettled,\n );\n return;\n }\n createMut.mutate(\n {\n project: props.project,\n input: { name, model, connection, ...(fallbacks.length > 0 ? { fallbacks } : {}) },\n },\n onSettled,\n );\n }\n\n const enterSubmit = useEnterSubmit(save, { enabled: canSave });\n\n return (\n <Modal\n title={props.initial ? `Edit ${props.initial.name}` : \"Add model route\"}\n onClose={props.onClose}\n >\n <div className=\"modal-body\">\n <label className=\"field\">\n <span>Name</span>\n <input\n type=\"text\"\n value={name}\n disabled={isEdit}\n onChange={(e) => setName(e.target.value)}\n placeholder=\"e.g. gpt-4o-fast\"\n maxLength={64}\n data-testid=\"model-route-name\"\n {...enterSubmit}\n />\n {!isEdit && (\n <span className=\"hint\">\n 3 to 39 characters: lowercase letters, digits and dashes, starting with a letter, no\n double dashes, not ending in a dash. Callers use this name; it cannot be renamed\n later.\n </span>\n )}\n </label>\n\n {catalogEmpty && (\n <EmptyState testId=\"model-route-catalog-empty\">\n The model catalog is empty. Open the Catalog tab to discover models; until then you can\n type ids by hand.\n </EmptyState>\n )}\n\n <PairFields\n label=\"\"\n model={model}\n connection={connection}\n onModel={setModel}\n onConnection={setConnection}\n models={models}\n connections={connections}\n catalogEmpty={catalogEmpty}\n testIdPrefix=\"model-route\"\n enterSubmit={enterSubmit}\n />\n <span className=\"hint\">\n The connection holds the credentials for the model. Changing it fixes a broken route.\n </span>\n\n <div className=\"field\">\n <span>Fallbacks</span>\n {fallbacks.map((f, i) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: rows have no identity beyond position\n <div key={i} style={{ display: \"flex\", gap: \"var(--w6w-sp-1-5)\" }}>\n <PairFields\n label={`Fallback ${i + 1} `}\n model={f.model}\n connection={f.connection}\n onModel={(v) =>\n setFallbacks((fs) => fs.map((x, j) => (j === i ? { ...x, model: v } : x)))\n }\n onConnection={(v) =>\n setFallbacks((fs) => fs.map((x, j) => (j === i ? { ...x, connection: v } : x)))\n }\n models={models}\n connections={connections}\n catalogEmpty={catalogEmpty}\n testIdPrefix={`model-route-fallback-${i}`}\n enterSubmit={enterSubmit}\n />\n <button\n type=\"button\"\n className=\"btn ghost\"\n onClick={() => setFallbacks((fs) => fs.filter((_, j) => j !== i))}\n data-testid={`model-route-fallback-${i}-remove`}\n >\n Remove\n </button>\n </div>\n ))}\n <button\n type=\"button\"\n className=\"btn ghost\"\n onClick={() => setFallbacks((fs) => [...fs, { model: \"\", connection: \"\" }])}\n data-testid=\"model-route-fallback-add\"\n >\n + Add fallback\n </button>\n </div>\n\n {error && (\n <div className=\"result error\" data-testid=\"model-route-error\">\n {error}\n </div>\n )}\n </div>\n <div className=\"modal-actions\">\n <button type=\"button\" className=\"btn ghost\" onClick={props.onClose}>\n Cancel\n </button>\n <button\n type=\"button\"\n className=\"btn\"\n disabled={!canSave}\n onClick={save}\n data-testid=\"model-route-save\"\n >\n {saving ? \"Saving…\" : isEdit ? \"Save changes\" : \"Save route\"}\n </button>\n </div>\n </Modal>\n );\n}\n\ninterface PairFieldsProps {\n label: string;\n model: string;\n connection: string;\n onModel: (v: string) => void;\n onConnection: (v: string) => void;\n models: Model[];\n connections: ConnectionChoice[];\n catalogEmpty: boolean;\n testIdPrefix: string;\n enterSubmit: Record<string, unknown>;\n}\n\n/**\n * A model + connection pair as selects fed by the catalog and the connections list. Connections\n * narrow to the chosen model's provider app; if none match, all are listed (labelled) so the\n * route can still be saved. An empty catalog falls back to free text.\n */\nfunction PairFields(p: PairFieldsProps) {\n const picked = p.models.find((m) => m.id === p.model);\n const matching = picked\n ? p.connections.filter((c) => c.appId === picked.providerAppId)\n : p.connections;\n const narrowed = picked != null && matching.length > 0;\n const options = narrowed ? matching : p.connections;\n const connHas = options.some((c) => c.id === p.connection);\n const modelHas = p.models.some((m) => m.id === p.model);\n return (\n <>\n <div className=\"field\">\n <span>{p.label}Model</span>\n {p.catalogEmpty ? (\n <input\n type=\"text\"\n value={p.model}\n onChange={(e) => p.onModel(e.target.value)}\n placeholder=\"model id\"\n aria-label={`${p.label}Model`}\n data-testid={`${p.testIdPrefix}-model`}\n {...p.enterSubmit}\n />\n ) : (\n <select\n value={p.model}\n onChange={(e) => p.onModel(e.target.value)}\n aria-label={`${p.label}Model`}\n data-testid={`${p.testIdPrefix}-model`}\n >\n <option value=\"\">Select a model…</option>\n {p.model && !modelHas && <option value={p.model}>{p.model}</option>}\n {p.models.map((m) => (\n <option key={m.id} value={m.id}>\n {m.displayName} ({m.provider})\n </option>\n ))}\n </select>\n )}\n </div>\n <div className=\"field\">\n <span>{p.label}Connection</span>\n {p.catalogEmpty && p.connections.length === 0 ? (\n <input\n type=\"text\"\n value={p.connection}\n onChange={(e) => p.onConnection(e.target.value)}\n placeholder=\"connection id\"\n aria-label={`${p.label}Connection`}\n data-testid={`${p.testIdPrefix}-connection`}\n {...p.enterSubmit}\n />\n ) : (\n <select\n value={p.connection}\n onChange={(e) => p.onConnection(e.target.value)}\n aria-label={`${p.label}Connection`}\n data-testid={`${p.testIdPrefix}-connection`}\n >\n <option value=\"\">Select a connection…</option>\n {p.connection && !connHas && <option value={p.connection}>{p.connection}</option>}\n {options.map((c) => (\n <option key={c.id} value={c.id} disabled={c.disabledReason != null}>\n {c.displayName}\n {narrowed ? \"\" : ` (${c.appId})`}\n {c.disabledReason != null ? ` — ${c.disabledReason}` : \"\"}\n </option>\n ))}\n </select>\n )}\n </div>\n </>\n );\n}\n"],"names":["COPY","modelRouteErrorCopy","ApiError","routeSummary","r","fallbacks","tail","ModelRoutesManager","props","project","useEditorProject","editor","setEditor","useState","pending","setPending","deleteError","setDeleteError","routesQuery","useModelRoutesQuery","deleteMut","useDeleteModelRouteMutation","routes","canCreate","editing","editorReady","columns","jsxs","jsx","EditButton","DeleteButton","_a","EmptyState","DataTable","RouteModal","ConfirmModal","name","e","isEdit","setName","model","setModel","_b","connection","setConnection","_c","setFallbacks","_d","error","setError","catalog","useAllModelCatalogQuery","connectionsQuery","useConnectionsQuery","models","_e","providersQuery","useModelProvidersQuery","connections","connectionChoices","catalogEmpty","createMut","useCreateModelRouteMutation","updateMut","useUpdateModelRouteMutation","saving","canSave","f","save","onSettled","enterSubmit","useEnterSubmit","Modal","PairFields","i","v","fs","x","j","_","p","picked","m","matching","c","narrowed","options","connHas","modelHas","Fragment"],"mappings":";;;;;;;;AA+CA,MAAMA,IAA+B;AAAA,EACnC,oBACE;AACJ;AAEO,SAASC,EAAoB,GAAoB;AACtD,SAAI,aAAaC,IACX,OAAO,OAAOF,GAAM,EAAE,IAAI,IAAUA,EAAK,EAAE,IAAI,IAC5C,EAAE,UAEJ,aAAa,Q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AE,YAAa,UAAAA,EAAE,WAAA,CAAW;AAAA,YACvEM,EAAQ,IAAI,CAACF,MACZ,gBAAAzD,EAAC,UAAA,EAAkB,OAAOyD,EAAE,IAAI,UAAUA,EAAE,kBAAkB,MAC3D,UAAA;AAAA,cAAAA,EAAE;AAAA,cACFC,IAAW,KAAK,KAAKD,EAAE,KAAK;AAAA,cAC5BA,EAAE,kBAAkB,OAAO,MAAMA,EAAE,cAAc,KAAK;AAAA,YAAA,EAAA,GAH5CA,EAAE,EAIf,CACD;AAAA,UAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IACH,EAAA,CAEJ;AAAA,EAAA,GACF;AAEJ;"}
@@ -1,196 +0,0 @@
1
- import { useQueryClient as c, useMutation as i, useQuery as l } from "@tanstack/react-query";
2
- import { u as s } from "./client-context-CX61Bgw-.js";
3
- import { c as w } from "./connections-CzsCyIxY.js";
4
- const u = ["credentials"], d = (e) => ["credential", e], Q = ["credential-types"], v = (e) => ["credential-dependents", e];
5
- function y(e, t) {
6
- e.invalidateQueries({ queryKey: u }), e.invalidateQueries({ queryKey: d(t) }), e.invalidateQueries({ queryKey: w }), e.invalidateQueries({ queryKey: ["connection"] }), e.invalidateQueries({ queryKey: ["app-connections"] });
7
- }
8
- function f(e, t) {
9
- return e.console.credentials.list(t);
10
- }
11
- function T(e) {
12
- return e.console.credentials.types();
13
- }
14
- function C(e, t) {
15
- return e.console.credentials.get(t);
16
- }
17
- function p(e, t) {
18
- return e.console.credentials.create(t);
19
- }
20
- function S(e, t, n) {
21
- return e.console.credentials.update(t, n);
22
- }
23
- function m(e, t, n) {
24
- return e.console.credentials.rotate(t, n);
25
- }
26
- function h(e, t, n) {
27
- return n === "disabled" ? e.console.credentials.disable(t) : e.console.credentials.enable(t);
28
- }
29
- function q(e, t) {
30
- return e.console.credentials.test(t);
31
- }
32
- function K(e, t) {
33
- return e.console.credentials.dependents(t);
34
- }
35
- async function F(e, t) {
36
- var n, r;
37
- try {
38
- return await e.console.credentials.delete(t), { ok: !0 };
39
- } catch (a) {
40
- const o = a;
41
- if ((o == null ? void 0 : o.status) === 409 && o.code === "credential_in_use")
42
- return {
43
- ok: !1,
44
- dependents: { connections: ((r = (n = (o.raw ?? {}).error) == null ? void 0 : n.dependents) == null ? void 0 : r.connections) ?? [] }
45
- };
46
- throw a;
47
- }
48
- }
49
- function k(e, t) {
50
- const n = e ?? {}, r = t === "create" ? "create" : "rotate";
51
- return n.status === 401 || n.status === 403 ? `You are not allowed to ${r} this credential.` : n.status === 409 ? "A credential with that name already exists." : n.status === 400 || n.status === 422 ? "The server rejected those values. Check them and try again." : n.status === 0 ? `Could not reach the server to ${r} the credential.` : `Could not ${r} the credential.`;
52
- }
53
- function x(e) {
54
- const t = s();
55
- return l({
56
- queryKey: e ? [...u, e] : u,
57
- queryFn: () => f(t, e)
58
- });
59
- }
60
- function A() {
61
- const e = s();
62
- return l({
63
- queryKey: Q,
64
- queryFn: () => T(e),
65
- staleTime: Number.POSITIVE_INFINITY,
66
- retry: !1
67
- });
68
- }
69
- function N(e) {
70
- const t = s();
71
- return l({ queryKey: d(e), queryFn: () => C(t, e) });
72
- }
73
- function _(e, t = !0) {
74
- const n = s();
75
- return l({
76
- queryKey: v(e),
77
- queryFn: () => K(n, e),
78
- enabled: t,
79
- retry: !1
80
- });
81
- }
82
- function j() {
83
- const e = s(), t = c();
84
- return i({
85
- mutationFn: (n) => p(e, n),
86
- // The variables carry the typed secret: do not keep a settled mutation (or its variables) in
87
- // the cache once the form has reset it.
88
- gcTime: 0,
89
- onSuccess: () => t.invalidateQueries({ queryKey: u })
90
- });
91
- }
92
- function $(e) {
93
- const t = s(), n = c();
94
- return i({
95
- mutationFn: (r) => S(t, e, r),
96
- onSuccess: () => {
97
- n.invalidateQueries({ queryKey: u }), n.invalidateQueries({ queryKey: d(e) });
98
- }
99
- });
100
- }
101
- function O(e) {
102
- const t = s(), n = c();
103
- return i({
104
- mutationFn: (r) => m(t, e, r),
105
- gcTime: 0,
106
- // the variables carry the typed secret
107
- onSuccess: () => y(n, e)
108
- });
109
- }
110
- function R(e) {
111
- const t = s(), n = c();
112
- return i({
113
- mutationFn: (r) => h(t, e, r),
114
- onSuccess: () => y(n, e)
115
- });
116
- }
117
- function U(e) {
118
- const t = s();
119
- return i({
120
- mutationFn: () => q(t, e)
121
- });
122
- }
123
- function W() {
124
- const e = s(), t = c();
125
- return i({
126
- mutationFn: (n) => F(e, n),
127
- onSuccess: (n, r) => {
128
- n.ok && y(t, r);
129
- }
130
- });
131
- }
132
- const g = [
133
- "listCredentials",
134
- "createCredential",
135
- "getCredential",
136
- "rotateCredential",
137
- "setCredentialStatus",
138
- "testCredential",
139
- "credentialDependents",
140
- "deleteCredential"
141
- ];
142
- function M(e) {
143
- return {
144
- listCredentials: (t) => f(e, t),
145
- createCredential: (t) => p(e, t),
146
- getCredential: (t) => C(e, t),
147
- rotateCredential: (t, n) => m(e, t, n),
148
- setCredentialStatus: (t, n) => h(e, t, n),
149
- testCredential: (t) => q(e, t),
150
- credentialDependents: (t) => K(e, t),
151
- deleteCredential: async (t) => {
152
- try {
153
- await e.console.credentials.delete(t);
154
- } catch (n) {
155
- throw n && typeof n == "object" && "raw" in n && (n.body = n.raw), n;
156
- }
157
- }
158
- };
159
- }
160
- function Y(e, t) {
161
- const n = M(t), r = e;
162
- for (const a of g)
163
- typeof r[a] != "function" && (r[a] = n[a]);
164
- return e;
165
- }
166
- export {
167
- $ as A,
168
- Y as B,
169
- v as a,
170
- d as b,
171
- p as c,
172
- Q as d,
173
- M as e,
174
- k as f,
175
- u as g,
176
- F as h,
177
- C as i,
178
- K as j,
179
- y as k,
180
- T as l,
181
- f as m,
182
- j as n,
183
- _ as o,
184
- N as p,
185
- A as q,
186
- m as r,
187
- h as s,
188
- q as t,
189
- S as u,
190
- x as v,
191
- W as w,
192
- O as x,
193
- R as y,
194
- U as z
195
- };
196
- //# sourceMappingURL=credentials-CMR_wEvx.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"credentials-CMR_wEvx.js","sources":["../src/repos/credentials.ts"],"sourcesContent":["/**\n * The stored-credentials repo — list, single, create, rename, rotate, enable/disable, test,\n * dependents and delete, over `client.console.credentials.*`. Mirrors `connections.ts`.\n *\n * `invalidateAfterCredentialWrite` is the one place that knows a credential write can change what\n * a connection shows (its status, its untested flag), so it also stales every cached connection.\n * `credentialUiMethods` / `withCredentialMethods` are how both hosts (`W6WEmbedProvider` and\n * Studio's facade) supply the eight optional `W6WApi` credential methods from one implementation.\n */\nimport { type QueryClient, useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport type { W6WClient } from \"@w6w/sdk\";\nimport type {\n CredentialDependents,\n CredentialListFilter,\n CredentialSummary,\n CredentialTestResult,\n CredentialTypeDescriptor,\n} from \"@w6w/sdk/console\";\nimport { useEmbedClient } from \"../draft/client-context.ts\";\nimport { connectionsKey } from \"./connections.ts\";\n\nexport type {\n CredentialDependents,\n CredentialListFilter,\n CredentialSummary,\n CredentialTestResult,\n CredentialTypeDescriptor,\n CredentialTypeField,\n} from \"@w6w/sdk/console\";\n\n// ── keys ──────────────────────────────────────────────────────────────\n\nexport const credentialsKey = [\"credentials\"] as const;\nexport const credentialKey = (id: string) => [\"credential\", id] as const;\nexport const credentialTypesKey = [\"credential-types\"] as const;\nexport const credentialDependentsKey = (id: string) => [\"credential-dependents\", id] as const;\n\n/**\n * A credential write (rotate, enable/disable, delete) changes what every connection on it\n * reports, so the credential keys AND every cached connection (single and per-app) go stale.\n */\nexport function invalidateAfterCredentialWrite(qc: QueryClient, id: string): void {\n qc.invalidateQueries({ queryKey: credentialsKey });\n qc.invalidateQueries({ queryKey: credentialKey(id) });\n qc.invalidateQueries({ queryKey: connectionsKey });\n qc.invalidateQueries({ queryKey: [\"connection\"] });\n qc.invalidateQueries({ queryKey: [\"app-connections\"] });\n}\n\n// ── fetchers ──────────────────────────────────────────────────────────\n\nexport function listCredentials(\n client: W6WClient,\n filter?: CredentialListFilter,\n): Promise<CredentialSummary[]> {\n return client.console.credentials.list(filter);\n}\n\n/** The credential types the server can store and the fields each collects, in server order. */\nexport function listCredentialTypes(client: W6WClient): Promise<CredentialTypeDescriptor[]> {\n return client.console.credentials.types();\n}\n\nexport function getCredential(client: W6WClient, id: string): Promise<CredentialSummary> {\n return client.console.credentials.get(id);\n}\n\nexport function createCredential(\n client: W6WClient,\n body: { name: string; contract: string; source: Record<string, unknown> },\n): Promise<CredentialSummary> {\n return client.console.credentials.create(body);\n}\n\n/** Rename. */\nexport function updateCredential(\n client: W6WClient,\n id: string,\n body: { name: string },\n): Promise<CredentialSummary> {\n return client.console.credentials.update(id, body);\n}\n\nexport function rotateCredential(\n client: W6WClient,\n id: string,\n body: { source: Record<string, unknown> },\n): Promise<CredentialSummary> {\n return client.console.credentials.rotate(id, body);\n}\n\nexport function setCredentialStatus(\n client: W6WClient,\n id: string,\n status: \"active\" | \"disabled\",\n): Promise<CredentialSummary> {\n return status === \"disabled\"\n ? client.console.credentials.disable(id)\n : client.console.credentials.enable(id);\n}\n\nexport function testCredential(client: W6WClient, id: string): Promise<CredentialTestResult> {\n return client.console.credentials.test(id);\n}\n\nexport function getCredentialDependents(\n client: W6WClient,\n id: string,\n): Promise<CredentialDependents> {\n return client.console.credentials.dependents(id);\n}\n\nexport type DeleteCredentialResult = { ok: true } | { ok: false; dependents: CredentialDependents };\n\n/**\n * Delete. A 409 `credential_in_use` is data — `{ ok: false, dependents }` — not a thrown error;\n * every other failure rejects. There is no `force`: a credential in use is never deleted.\n * Wire (RECONCILE R-11): `{ error: { code, message, dependents: { connections } } }`.\n */\nexport async function deleteCredential(\n client: W6WClient,\n id: string,\n): Promise<DeleteCredentialResult> {\n try {\n await client.console.credentials.delete(id);\n return { ok: true };\n } catch (e) {\n const err = e as { status?: unknown; code?: unknown; raw?: unknown };\n if (err?.status === 409 && err.code === \"credential_in_use\") {\n const raw = (err.raw ?? {}) as {\n error?: { dependents?: Partial<CredentialDependents> };\n };\n return {\n ok: false,\n dependents: { connections: raw.error?.dependents?.connections ?? [] },\n };\n }\n throw e;\n }\n}\n\n/**\n * Fixed, secret-free text for a failed credential write, chosen by the server's status / error\n * code. The server's own message is never shown: a value the user typed could be echoed in it.\n */\nexport function credentialWriteErrorText(e: unknown, verb: \"create\" | \"rotate\"): string {\n const err = (e ?? {}) as { status?: unknown; code?: unknown };\n const what = verb === \"create\" ? \"create\" : \"rotate\";\n if (err.status === 401 || err.status === 403)\n return `You are not allowed to ${what} this credential.`;\n if (err.status === 409) return \"A credential with that name already exists.\";\n if (err.status === 400 || err.status === 422)\n return \"The server rejected those values. Check them and try again.\";\n if (err.status === 0) return `Could not reach the server to ${what} the credential.`;\n return `Could not ${what} the credential.`;\n}\n\n// ── hooks ─────────────────────────────────────────────────────────────\n\nexport function useCredentialsQuery(filter?: CredentialListFilter) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: filter ? [...credentialsKey, filter] : credentialsKey,\n queryFn: () => listCredentials(client, filter),\n });\n}\n\n/**\n * The descriptors that drive the create form, the list's type label and the rotate fields. They\n * change only with a server release, so they are cached for the session; a failure is not retried\n * (the callers degrade to the contract id / the JSON rotate box).\n */\nexport function useCredentialTypesQuery() {\n const client = useEmbedClient();\n return useQuery({\n queryKey: credentialTypesKey,\n queryFn: () => listCredentialTypes(client),\n staleTime: Number.POSITIVE_INFINITY,\n retry: false,\n });\n}\n\nexport function useCredentialQuery(id: string) {\n const client = useEmbedClient();\n return useQuery({ queryKey: credentialKey(id), queryFn: () => getCredential(client, id) });\n}\n\nexport function useCredentialDependentsQuery(id: string, enabled = true) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: credentialDependentsKey(id),\n queryFn: () => getCredentialDependents(client, id),\n enabled,\n retry: false,\n });\n}\n\nexport function useCreateCredentialMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (body: { name: string; contract: string; source: Record<string, unknown> }) =>\n createCredential(client, body),\n // The variables carry the typed secret: do not keep a settled mutation (or its variables) in\n // the cache once the form has reset it.\n gcTime: 0,\n onSuccess: () => qc.invalidateQueries({ queryKey: credentialsKey }),\n });\n}\n\n/** Rename touches only the credential keys: no connection's state changes. */\nexport function useUpdateCredentialMutation(id: string) {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (body: { name: string }) => updateCredential(client, id, body),\n onSuccess: () => {\n qc.invalidateQueries({ queryKey: credentialsKey });\n qc.invalidateQueries({ queryKey: credentialKey(id) });\n },\n });\n}\n\nexport function useRotateCredentialMutation(id: string) {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (body: { source: Record<string, unknown> }) => rotateCredential(client, id, body),\n gcTime: 0, // the variables carry the typed secret\n onSuccess: () => invalidateAfterCredentialWrite(qc, id),\n });\n}\n\nexport function useSetCredentialStatusMutation(id: string) {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (status: \"active\" | \"disabled\") => setCredentialStatus(client, id, status),\n onSuccess: () => invalidateAfterCredentialWrite(qc, id),\n });\n}\n\nexport function useTestCredentialMutation(id: string) {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (): Promise<CredentialTestResult> => testCredential(client, id),\n });\n}\n\nexport function useDeleteCredentialMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (id: string) => deleteCredential(client, id),\n onSuccess: (r, id) => {\n if (r.ok) invalidateAfterCredentialWrite(qc, id);\n },\n });\n}\n\n// ── W6WApi bridge ─────────────────────────────────────────────────────\n\ntype CredentialMethodName =\n | \"listCredentials\"\n | \"createCredential\"\n | \"getCredential\"\n | \"rotateCredential\"\n | \"setCredentialStatus\"\n | \"testCredential\"\n | \"credentialDependents\"\n | \"deleteCredential\";\n\nconst CREDENTIAL_METHODS: readonly CredentialMethodName[] = [\n \"listCredentials\",\n \"createCredential\",\n \"getCredential\",\n \"rotateCredential\",\n \"setCredentialStatus\",\n \"testCredential\",\n \"credentialDependents\",\n \"deleteCredential\",\n];\n\n/**\n * The eight optional `W6WApi` credential methods over `client` (this module may not import\n * `@w6w/ui`, so the signatures are checked where they are spread into a `W6WApi`: Studio's\n * facade, and `W6WEmbedProvider`'s bridge). `deleteCredential` rejects on a\n * 409 with the response body attached as `.body` (as `withApiErrorBody` does in the react adapter).\n */\nexport function credentialUiMethods(client: W6WClient) {\n return {\n listCredentials: (filter?: CredentialListFilter) => listCredentials(client, filter),\n createCredential: (body: { name: string; contract: string; source: Record<string, unknown> }) =>\n createCredential(client, body),\n getCredential: (id: string) => getCredential(client, id),\n rotateCredential: (id: string, body: { source: Record<string, unknown> }) =>\n rotateCredential(client, id, body),\n setCredentialStatus: (id: string, status: \"active\" | \"disabled\") =>\n setCredentialStatus(client, id, status),\n testCredential: (id: string) => testCredential(client, id),\n credentialDependents: (id: string) => getCredentialDependents(client, id),\n deleteCredential: async (id: string) => {\n try {\n await client.console.credentials.delete(id);\n } catch (e) {\n if (e && typeof e === \"object\" && \"raw\" in e) {\n (e as { body?: unknown }).body = (e as { raw?: unknown }).raw;\n }\n throw e;\n }\n },\n };\n}\n\n/** Fills ONLY the credential methods that are not functions on `adapter`; keeps the rest. */\nexport function withCredentialMethods<T extends object>(adapter: T, client: W6WClient): T {\n const ours = credentialUiMethods(client);\n const target = adapter as Record<string, unknown>;\n for (const name of CREDENTIAL_METHODS) {\n if (typeof target[name] !== \"function\") target[name] = ours[name];\n }\n return adapter;\n}\n"],"names":["credentialsKey","credentialKey","id","credentialTypesKey","credentialDependentsKey","invalidateAfterCredentialWrite","qc","connectionsKey","listCredentials","client","filter","listCredentialTypes","getCredential","createCredential","body","updateCredential","rotateCredential","setCredentialStatus","status","testCredential","getCredentialDependents","deleteCredential","e","err","_b","_a","credentialWriteErrorText","verb","what","useCredentialsQuery","useEmbedClient","useQuery","useCredentialTypesQuery","useCredentialQuery","useCredentialDependentsQuery","enabled","useCreateCredentialMutation","useQueryClient","useMutation","useUpdateCredentialMutation","useRotateCredentialMutation","useSetCredentialStatusMutation","useTestCredentialMutation","useDeleteCredentialMutation","r","CREDENTIAL_METHODS","credentialUiMethods","withCredentialMethods","adapter","ours","target","name"],"mappings":";;;AAgCO,MAAMA,IAAiB,CAAC,aAAa,GAC/BC,IAAgB,CAACC,MAAe,CAAC,cAAcA,CAAE,GACjDC,IAAqB,CAAC,kBAAkB,GACxCC,IAA0B,CAACF,MAAe,CAAC,yBAAyBA,CAAE;AAM5E,SAASG,EAA+BC,GAAiBJ,GAAkB;AAChF,EAAAI,EAAG,kBAAkB,EAAE,UAAUN,EAAA,CAAgB,GACjDM,EAAG,kBAAkB,EAAE,UAAUL,EAAcC,CAAE,GAAG,GACpDI,EAAG,kBAAkB,EAAE,UAAUC,EAAA,CAAgB,GACjDD,EAAG,kBAAkB,EAAE,UAAU,CAAC,YAAY,GAAG,GACjDA,EAAG,kBAAkB,EAAE,UAAU,CAAC,iBAAiB,GAAG;AACxD;AAIO,SAASE,EACdC,GACAC,GAC8B;AAC9B,SAAOD,EAAO,QAAQ,YAAY,KAAKC,CAAM;AAC/C;AAGO,SAASC,EAAoBF,GAAwD;AAC1F,SAAOA,EAAO,QAAQ,YAAY,MAAA;AACpC;AAEO,SAASG,EAAcH,GAAmBP,GAAwC;AACvF,SAAOO,EAAO,QAAQ,YAAY,IAAIP,CAAE;AAC1C;AAEO,SAASW,EACdJ,GACAK,GAC4B;AAC5B,SAAOL,EAAO,QAAQ,YAAY,OAAOK,CAAI;AAC/C;AAGO,SAASC,EACdN,GACAP,GACAY,GAC4B;AAC5B,SAAOL,EAAO,QAAQ,YAAY,OAAOP,GAAIY,CAAI;AACnD;AAEO,SAASE,EACdP,GACAP,GACAY,GAC4B;AAC5B,SAAOL,EAAO,QAAQ,YAAY,OAAOP,GAAIY,CAAI;AACnD;AAEO,SAASG,EACdR,GACAP,GACAgB,GAC4B;AAC5B,SAAOA,MAAW,aACdT,EAAO,QAAQ,YAAY,QAAQP,CAAE,IACrCO,EAAO,QAAQ,YAAY,OAAOP,CAAE;AAC1C;AAEO,SAASiB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