@uipath/apollo-wind 2.94.1 → 2.95.1

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.
@@ -0,0 +1,1263 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { AlertCircle, Building2, Check, ChevronDown, ChevronRight, CircleCheck, KeyRound } from "lucide-react";
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { Alert, AlertDescription, AlertTitle } from "../alert.js";
5
+ import { Button } from "../button.js";
6
+ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../collapsible.js";
7
+ import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "../command.js";
8
+ import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "../dialog.js";
9
+ import { Input } from "../input.js";
10
+ import { Label } from "../label.js";
11
+ import { Popover, PopoverContent, PopoverTrigger } from "../popover.js";
12
+ import { RadioGroup, RadioGroupItem } from "../radio-group.js";
13
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select.js";
14
+ import { Spinner } from "../spinner.js";
15
+ import { cn } from "../../../lib/index.js";
16
+ import { resolveByoModelDialogLabels } from "./labels.js";
17
+ function ByoModelDialog({ open, onOpenChange, ...rest }) {
18
+ return /*#__PURE__*/ jsx(Dialog, {
19
+ open: open,
20
+ onOpenChange: onOpenChange,
21
+ children: open && /*#__PURE__*/ jsx(DialogBody, {
22
+ ...rest,
23
+ onClose: ()=>onOpenChange(false)
24
+ })
25
+ });
26
+ }
27
+ const NEW = '__new__';
28
+ const NO_FORM = {
29
+ status: 'idle',
30
+ form: {
31
+ authTypes: [],
32
+ defaultAuthType: null,
33
+ fields: []
34
+ }
35
+ };
36
+ const NO_MODELS = {
37
+ status: 'idle',
38
+ models: {
39
+ compatible: [],
40
+ incompatible: []
41
+ }
42
+ };
43
+ function defaultConnectionName(providerName, connections) {
44
+ const base = `${providerName} – personal`;
45
+ const taken = new Set(connections.map((c)=>c.name.toLowerCase()));
46
+ if (!taken.has(base.toLowerCase())) return base;
47
+ let n = 2;
48
+ while(taken.has(`${base} ${n}`.toLowerCase()))n += 1;
49
+ return `${base} ${n}`;
50
+ }
51
+ const shownFields = (form, authType)=>form.fields.filter((f)=>!f.group || f.group === authType);
52
+ const defaultsOf = (form)=>Object.fromEntries(form.fields.filter((f)=>f.defaultValue).map((f)=>[
53
+ f.key,
54
+ f.defaultValue
55
+ ]));
56
+ function DialogBody({ api: apiProp, onSaved, editing, labels: labelOverrides, container, onClose }) {
57
+ const labels = resolveByoModelDialogLabels(labelOverrides);
58
+ const [api] = useState(apiProp);
59
+ const [editTarget] = useState(editing);
60
+ const generation = useRef(0);
61
+ const formLoad = useRef(0);
62
+ useEffect(()=>()=>{
63
+ generation.current += 1;
64
+ formLoad.current += 1;
65
+ }, []);
66
+ const [context, setContext] = useState({
67
+ status: 'running'
68
+ });
69
+ const [connections, setConnections] = useState([]);
70
+ const [modelToEdit, setModelToEdit] = useState(null);
71
+ const [providerId, setProviderId] = useState('');
72
+ const [connectionChoice, setConnectionChoice] = useState(NEW);
73
+ const [connName, setConnName] = useState('');
74
+ const [folderId, setFolderId] = useState('');
75
+ const [formState, setFormState] = useState(NO_FORM);
76
+ const [authType, setAuthType] = useState(null);
77
+ const [savedAuthType, setSavedAuthType] = useState(null);
78
+ const [values, setValues] = useState({});
79
+ const [moreOpen, setMoreOpen] = useState(false);
80
+ const [editingConnection, setEditingConnection] = useState(false);
81
+ const [loadingConnectionValues, setLoadingConnectionValues] = useState(false);
82
+ const [connect, setConnect] = useState({
83
+ status: 'idle'
84
+ });
85
+ const [modelsState, setModelsState] = useState(NO_MODELS);
86
+ const [modelId, setModelId] = useState('');
87
+ const [modelQuery, setModelQuery] = useState('');
88
+ const [modelListOpen, setModelListOpen] = useState(false);
89
+ const [name, setName] = useState('');
90
+ const [nameTouched, setNameTouched] = useState(false);
91
+ const [useAs, setUseAs] = useState('own');
92
+ const [replaces, setReplaces] = useState('');
93
+ const [apiType, setApiType] = useState('');
94
+ const [test, setTest] = useState({
95
+ status: 'idle'
96
+ });
97
+ const ctx = 'ok' === context.status ? context.value : null;
98
+ const providers = ctx?.providers ?? [];
99
+ const folders = ctx?.folders ?? [];
100
+ const folderLabel = (id)=>folders.find((f)=>f.id === id)?.label ?? id;
101
+ const provider = providers.find((p)=>p.id === providerId);
102
+ const providerName = provider?.name ?? '';
103
+ const providerConnections = connections.filter((c)=>c.providerId === providerId);
104
+ const form = formState.form;
105
+ const isNew = connectionChoice === NEW;
106
+ const connection = connections.find((c)=>c.id === connectionChoice) ?? null;
107
+ const connectOutcome = 'ok' === connect.status ? connect.value : null;
108
+ const connected = Boolean(connection) && !editingConnection;
109
+ const loadModels = async (pid, conn, gen)=>{
110
+ if (!conn) return void setModelsState(NO_MODELS);
111
+ setModelsState({
112
+ ...NO_MODELS,
113
+ status: 'loading'
114
+ });
115
+ try {
116
+ const result = await api.listModels(pid, conn);
117
+ if (gen !== generation.current) return;
118
+ result.ok ? setModelsState({
119
+ status: 'ok',
120
+ models: result.value
121
+ }) : setModelsState({
122
+ ...NO_MODELS,
123
+ status: 'error',
124
+ failure: result.failure
125
+ });
126
+ } catch (err) {
127
+ if (gen === generation.current) setModelsState({
128
+ ...NO_MODELS,
129
+ status: 'error',
130
+ failure: unexpected(err)
131
+ });
132
+ }
133
+ };
134
+ const loadForm = async (pid, folder)=>{
135
+ formLoad.current += 1;
136
+ const load = formLoad.current;
137
+ setFormState({
138
+ ...NO_FORM,
139
+ status: 'loading'
140
+ });
141
+ setValues({});
142
+ try {
143
+ const result = await api.loadForm(pid, folder || null);
144
+ if (load !== formLoad.current) return;
145
+ if (!result.ok) return void setFormState({
146
+ ...NO_FORM,
147
+ status: 'error',
148
+ failure: result.failure
149
+ });
150
+ setFormState({
151
+ status: 'ok',
152
+ form: result.value
153
+ });
154
+ setAuthType(result.value.defaultAuthType);
155
+ setValues(defaultsOf(result.value));
156
+ } catch (err) {
157
+ if (load === formLoad.current) setFormState({
158
+ ...NO_FORM,
159
+ status: 'error',
160
+ failure: unexpected(err)
161
+ });
162
+ }
163
+ };
164
+ const resetFormValues = ()=>{
165
+ setAuthType(form.defaultAuthType);
166
+ setValues(defaultsOf(form));
167
+ };
168
+ const startFromSavedModel = (model, loaded, defaultFolder)=>{
169
+ const gen = generation.current;
170
+ const savedConnection = loaded.connections.find((c)=>c.id === model.connectionId) ?? null;
171
+ const savedProvider = loaded.providers.find((p)=>p.id === model.providerId);
172
+ setModelToEdit(model);
173
+ setProviderId(model.providerId);
174
+ setConnectionChoice(savedConnection ? savedConnection.id : NEW);
175
+ setConnName(defaultConnectionName(savedProvider?.name ?? model.providerId, loaded.connections));
176
+ setModelId(model.modelId);
177
+ setName(model.replaces ? '' : model.name);
178
+ setNameTouched(true);
179
+ setUseAs(model.replaces ? 'replacement' : 'own');
180
+ setReplaces(model.replaces ?? '');
181
+ setApiType(model.apiType ?? '');
182
+ loadModels(model.providerId, savedConnection, gen);
183
+ loadForm(model.providerId, savedConnection?.folderId ?? defaultFolder);
184
+ };
185
+ useEffect(()=>{
186
+ const gen = generation.current;
187
+ const load = async ()=>{
188
+ const contextResult = await api.loadContext();
189
+ if (gen !== generation.current) return;
190
+ if (!contextResult.ok) return void setContext({
191
+ status: 'error',
192
+ failure: contextResult.failure
193
+ });
194
+ const loaded = contextResult.value;
195
+ let savedModel = null;
196
+ if (editTarget) {
197
+ const modelResult = await api.loadModel(editTarget);
198
+ if (gen !== generation.current) return;
199
+ if (!modelResult.ok) return void setContext({
200
+ status: 'error',
201
+ failure: modelResult.failure
202
+ });
203
+ savedModel = modelResult.value;
204
+ }
205
+ const defaultFolder = loaded.defaultFolderId ?? loaded.folders[0]?.id ?? '';
206
+ setContext({
207
+ status: 'ok',
208
+ value: loaded
209
+ });
210
+ setConnections(loaded.connections);
211
+ setFolderId(defaultFolder);
212
+ if (!loaded.allowsNewNames) setUseAs('replacement');
213
+ if (savedModel) startFromSavedModel(savedModel, loaded, defaultFolder);
214
+ };
215
+ load().catch((err)=>{
216
+ if (gen === generation.current) setContext({
217
+ status: 'error',
218
+ failure: unexpected(err)
219
+ });
220
+ });
221
+ }, [
222
+ api,
223
+ editTarget
224
+ ]);
225
+ const resetDownstream = ()=>{
226
+ setModelQuery('');
227
+ setModelListOpen(false);
228
+ setModelId('');
229
+ setName('');
230
+ setNameTouched(false);
231
+ setTest({
232
+ status: 'idle'
233
+ });
234
+ };
235
+ const chooseProvider = (id)=>{
236
+ if (id === providerId) return;
237
+ generation.current += 1;
238
+ const gen = generation.current;
239
+ const p = providers.find((candidate)=>candidate.id === id);
240
+ const existing = connections.filter((c)=>c.providerId === id);
241
+ setProviderId(id);
242
+ setConnectionChoice(existing[0]?.id ?? NEW);
243
+ setConnName(defaultConnectionName(p?.name ?? id, connections));
244
+ setMoreOpen(false);
245
+ setEditingConnection(false);
246
+ setConnect({
247
+ status: 'idle'
248
+ });
249
+ resetDownstream();
250
+ setUseAs(ctx?.allowsNewNames === false ? 'replacement' : 'own');
251
+ setReplaces('');
252
+ setApiType('');
253
+ loadModels(id, existing[0] ?? null, gen);
254
+ loadForm(id, folderId);
255
+ };
256
+ const chooseConnection = (id)=>{
257
+ generation.current += 1;
258
+ setConnectionChoice(id);
259
+ if (id === NEW) setConnName(defaultConnectionName(providerName, connections));
260
+ setEditingConnection(false);
261
+ setConnect({
262
+ status: 'idle'
263
+ });
264
+ resetFormValues();
265
+ resetDownstream();
266
+ loadModels(providerId, connections.find((c)=>c.id === id) ?? null, generation.current);
267
+ };
268
+ const failConnectionEdit = (failure)=>{
269
+ setEditingConnection(false);
270
+ resetFormValues();
271
+ setConnect({
272
+ status: 'error',
273
+ failure
274
+ });
275
+ loadModels(providerId, connection, generation.current);
276
+ };
277
+ const startConnectionEdit = async ()=>{
278
+ if (!connection) return;
279
+ generation.current += 1;
280
+ const gen = generation.current;
281
+ setEditingConnection(true);
282
+ setConnName(connection.name);
283
+ setMoreOpen(false);
284
+ setConnect({
285
+ status: 'idle'
286
+ });
287
+ setTest({
288
+ status: 'idle'
289
+ });
290
+ resetFormValues();
291
+ setLoadingConnectionValues(true);
292
+ try {
293
+ const result = await api.loadConnectionValues(providerId, connection);
294
+ if (gen !== generation.current) return;
295
+ if (!result.ok) return void failConnectionEdit(result.failure);
296
+ const saved = result.value.authType ?? form.defaultAuthType;
297
+ setSavedAuthType(saved);
298
+ setAuthType(saved);
299
+ setValues({
300
+ ...defaultsOf(form),
301
+ ...result.value.values
302
+ });
303
+ } catch (err) {
304
+ if (gen === generation.current) failConnectionEdit(unexpected(err));
305
+ } finally{
306
+ if (gen === generation.current) setLoadingConnectionValues(false);
307
+ }
308
+ };
309
+ const cancelConnectionEdit = ()=>{
310
+ generation.current += 1;
311
+ setEditingConnection(false);
312
+ setLoadingConnectionValues(false);
313
+ setConnect({
314
+ status: 'idle'
315
+ });
316
+ resetFormValues();
317
+ loadModels(providerId, connection, generation.current);
318
+ };
319
+ const setValue = (key, v)=>{
320
+ setValues((prev)=>({
321
+ ...prev,
322
+ [key]: v
323
+ }));
324
+ if ('error' === connect.status) setConnect({
325
+ status: 'idle'
326
+ });
327
+ };
328
+ const showConnectionForm = Boolean(provider) && (isNew || editingConnection);
329
+ const formFolderId = editingConnection && connection ? connection.folderId : folderId;
330
+ const keepsCurrentValue = (f)=>editingConnection && f.secret && (!f.group || f.group === savedAuthType);
331
+ const isRequired = (f)=>f.required && !keepsCurrentValue(f);
332
+ const fields = shownFields(form, authType);
333
+ const mainFields = fields.filter((f)=>!f.advanced);
334
+ const advancedFields = fields.filter((f)=>f.advanced);
335
+ const requiredFilled = 'ok' === formState.status && fields.filter(isRequired).every((f)=>(values[f.key] ?? '').trim());
336
+ const otherConnections = editingConnection ? connections.filter((c)=>c.id !== connection?.id) : connections;
337
+ const connNameClash = showConnectionForm && otherConnections.some((c)=>c.name.toLowerCase() === connName.trim().toLowerCase());
338
+ const keyLocked = 'running' === connect.status || loadingConnectionValues;
339
+ const canConnect = showConnectionForm && requiredFilled && Boolean(connName.trim()) && Boolean(formFolderId) && !connNameClash && !keyLocked;
340
+ const runConnect = async ()=>{
341
+ if (!canConnect) return;
342
+ const gen = generation.current;
343
+ const existing = editingConnection && connection ? connection : void 0;
344
+ setConnect({
345
+ status: 'running'
346
+ });
347
+ let result;
348
+ try {
349
+ result = await api.connect({
350
+ providerId,
351
+ form,
352
+ authType,
353
+ values,
354
+ name: connName.trim(),
355
+ folderId: formFolderId,
356
+ existing
357
+ });
358
+ } catch (err) {
359
+ result = {
360
+ ok: false,
361
+ failure: unexpected(err)
362
+ };
363
+ }
364
+ if (gen !== generation.current) return;
365
+ if (!result.ok) return void setConnect({
366
+ status: 'error',
367
+ failure: result.failure
368
+ });
369
+ const saved = result.value;
370
+ existing ? setConnections((prev)=>prev.map((c)=>c.id === saved.id ? saved : c)) : setConnections((prev)=>[
371
+ ...prev,
372
+ saved
373
+ ]);
374
+ setConnectionChoice(saved.id);
375
+ setEditingConnection(false);
376
+ resetFormValues();
377
+ setConnect({
378
+ status: 'ok',
379
+ value: {
380
+ connection: saved,
381
+ updated: Boolean(existing)
382
+ }
383
+ });
384
+ loadModels(providerId, saved, gen);
385
+ };
386
+ const pickModel = (id)=>{
387
+ setModelId(id);
388
+ if (!nameTouched) setName(id);
389
+ setTest({
390
+ status: 'idle'
391
+ });
392
+ };
393
+ const takenNames = new Set((ctx?.takenModelNames ?? []).map((n)=>n.toLowerCase()));
394
+ if (editTarget) takenNames.delete(editTarget.name.toLowerCase());
395
+ const reservedNames = new Set((ctx?.reservedModelNames ?? []).map((n)=>n.toLowerCase()));
396
+ const ownName = name.trim();
397
+ let nameProblem = null;
398
+ if (ownName && takenNames.has(ownName.toLowerCase())) nameProblem = labels.nameTaken(ownName);
399
+ else if (ownName && reservedNames.has(ownName.toLowerCase())) nameProblem = labels.nameReserved(ownName);
400
+ const replacementOptions = (ctx?.replaceableModels ?? []).filter((m)=>(!m.replaced || m.name === modelToEdit?.replaces) && Boolean(provider) && api.apiTypes(providerId, m.name).length > 0);
401
+ const canUseOwnName = ctx?.allowsNewNames ?? false;
402
+ const replacing = 'replacement' === useAs;
403
+ const replacement = replacementOptions.find((m)=>m.name === replaces) ?? null;
404
+ const chosenName = replacing ? replacement?.name ?? '' : ownName;
405
+ const nameReady = replacing ? Boolean(replacement) : Boolean(ownName) && !nameProblem;
406
+ const apiTypeOptions = provider && (!replacing || replacement) ? api.apiTypes(providerId, replacing ? replacement?.name ?? null : null) : [];
407
+ const apiTypeKey = apiTypeOptions.map((t)=>t.value).join('|');
408
+ useEffect(()=>{
409
+ if (apiTypeOptions.some((t)=>t.value === apiType)) return;
410
+ const first = apiTypeOptions[0]?.value ?? '';
411
+ setApiType(replacing || 1 === apiTypeOptions.length ? first : '');
412
+ }, [
413
+ apiTypeKey,
414
+ replacing,
415
+ apiType
416
+ ]);
417
+ const apiTypeReady = apiTypeOptions.some((t)=>t.value === apiType);
418
+ const busy = keyLocked || 'running' === test.status || 'ok' === test.status;
419
+ const hasModel = Boolean(modelId.trim());
420
+ const readyToSave = connected && hasModel && nameReady && apiTypeReady;
421
+ const runTest = async ()=>{
422
+ if (!connection || !readyToSave || busy) return;
423
+ const gen = generation.current;
424
+ setTest({
425
+ status: 'running'
426
+ });
427
+ let result;
428
+ try {
429
+ result = await api.testAndSave({
430
+ providerId,
431
+ connection,
432
+ modelId: modelId.trim(),
433
+ name: chosenName,
434
+ replaces: replacing ? chosenName : null,
435
+ apiType,
436
+ editing: modelToEdit ?? void 0
437
+ });
438
+ } catch (err) {
439
+ result = {
440
+ ok: false,
441
+ failure: unexpected(err)
442
+ };
443
+ }
444
+ const stillOpen = gen === generation.current;
445
+ if (!result.ok) {
446
+ if (stillOpen) setTest({
447
+ status: 'error',
448
+ failure: result.failure
449
+ });
450
+ return;
451
+ }
452
+ if (stillOpen) onClose();
453
+ try {
454
+ await onSaved(result.value);
455
+ } catch (err) {
456
+ console.error('ByoModelDialog: onSaved failed after the model was saved', err);
457
+ }
458
+ };
459
+ const models = modelsState.models;
460
+ const q = modelQuery.trim().toLowerCase();
461
+ const shownCompatible = models.compatible.filter((m)=>m.id.toLowerCase().includes(q));
462
+ const shownIncompatible = models.incompatible.filter((m)=>m.id.toLowerCase().includes(q));
463
+ const freeTextModel = 'ok' === modelsState.status && models.compatible.length + models.incompatible.length === 0;
464
+ const modelTriggerRef = useRef(null);
465
+ const modelSearchRef = useRef(null);
466
+ useEffect(()=>{
467
+ if ('ok' === connect.status && 'ok' === modelsState.status) modelTriggerRef.current?.focus();
468
+ }, [
469
+ connect.status,
470
+ modelsState.status
471
+ ]);
472
+ const fieldInput = (f, main)=>/*#__PURE__*/ jsx(Field, {
473
+ id: `byo-${f.key}`,
474
+ label: f.label,
475
+ hint: keepsCurrentValue(f) ? labels.secretKeepHint : f.hint,
476
+ required: isRequired(f),
477
+ children: f.options?.length ? /*#__PURE__*/ jsxs(Select, {
478
+ value: values[f.key] || void 0,
479
+ onValueChange: (v)=>setValue(f.key, v),
480
+ disabled: keyLocked,
481
+ children: [
482
+ /*#__PURE__*/ jsx(SelectTrigger, {
483
+ id: `byo-${f.key}`,
484
+ className: "w-full",
485
+ "aria-required": isRequired(f) || void 0,
486
+ children: /*#__PURE__*/ jsx(SelectValue, {
487
+ placeholder: f.placeholder || void 0
488
+ })
489
+ }),
490
+ /*#__PURE__*/ jsx(SelectContent, {
491
+ container: container,
492
+ children: f.options.map((o)=>/*#__PURE__*/ jsx(SelectItem, {
493
+ value: o.value,
494
+ children: o.label
495
+ }, o.value))
496
+ })
497
+ ]
498
+ }) : /*#__PURE__*/ jsx(Input, {
499
+ id: `byo-${f.key}`,
500
+ type: f.secret ? 'password' : 'text',
501
+ autoComplete: "off",
502
+ spellCheck: false,
503
+ placeholder: f.placeholder,
504
+ value: values[f.key] ?? '',
505
+ disabled: keyLocked,
506
+ "aria-required": isRequired(f) || void 0,
507
+ onChange: (e)=>setValue(f.key, e.target.value),
508
+ onKeyDown: main ? (e)=>{
509
+ if ('Enter' === e.key) runConnect();
510
+ } : void 0,
511
+ className: f.secret ? 'font-mono' : void 0
512
+ })
513
+ }, f.key);
514
+ const modelTriggerText = (()=>{
515
+ if (!connected) return labels.modelNeedsConnection(providerName);
516
+ if ('loading' === modelsState.status) return labels.modelsLoading(providerName);
517
+ if ('error' === modelsState.status) return labels.modelsFailed(providerName);
518
+ return labels.modelSelect(models.compatible.length);
519
+ })();
520
+ const connectMessage = (()=>{
521
+ if (!connectOutcome || editingConnection) return null;
522
+ if (connectionChoice !== connectOutcome.connection.id) return null;
523
+ if (connectOutcome.updated) return labels.connectionUpdated;
524
+ return labels.connectedIn(folderLabel(connectOutcome.connection.folderId));
525
+ })();
526
+ let failure = null;
527
+ if ('error' === connect.status) failure = connect.failure;
528
+ else if ('error' === test.status) failure = test.failure;
529
+ else if ('error' === modelsState.status) failure = modelsState.failure ?? null;
530
+ const title = editTarget ? labels.editTitle : labels.title;
531
+ const description = editTarget ? labels.editDescription : labels.description;
532
+ const saveLabel = editTarget ? labels.testAndSave : labels.testAndAdd;
533
+ const saveHint = editTarget ? labels.testAndSaveHint : labels.testAndAddHint;
534
+ return /*#__PURE__*/ jsxs(DialogContent, {
535
+ container: container,
536
+ strings: {
537
+ close: labels.close
538
+ },
539
+ className: "!flex h-[min(780px,90vh)] !max-w-[600px] flex-col gap-0 overflow-hidden p-0",
540
+ children: [
541
+ /*#__PURE__*/ jsxs(DialogHeader, {
542
+ className: "shrink-0 px-6 pt-6 pb-4",
543
+ children: [
544
+ /*#__PURE__*/ jsx(DialogTitle, {
545
+ children: title
546
+ }),
547
+ /*#__PURE__*/ jsx(DialogDescription, {
548
+ children: description
549
+ })
550
+ ]
551
+ }),
552
+ /*#__PURE__*/ jsxs("div", {
553
+ className: "flex min-h-0 min-w-0 flex-1 flex-col gap-6 overflow-y-auto overflow-x-hidden px-6 pb-4",
554
+ children: [
555
+ 'running' === context.status && /*#__PURE__*/ jsxs("div", {
556
+ className: "flex items-center gap-2 text-xs text-foreground-muted",
557
+ children: [
558
+ /*#__PURE__*/ jsx(Spinner, {
559
+ size: "sm"
560
+ }),
561
+ " ",
562
+ editTarget ? labels.loadingModel : labels.loadingContext
563
+ ]
564
+ }),
565
+ 'error' === context.status && /*#__PURE__*/ jsx(FailureAlert, {
566
+ failure: context.failure,
567
+ labels: labels
568
+ }),
569
+ ctx && /*#__PURE__*/ jsxs(Fragment, {
570
+ children: [
571
+ /*#__PURE__*/ jsx(Step, {
572
+ n: 1,
573
+ title: labels.providerStep,
574
+ done: Boolean(provider),
575
+ children: /*#__PURE__*/ jsxs(Select, {
576
+ value: providerId || void 0,
577
+ onValueChange: chooseProvider,
578
+ disabled: busy,
579
+ children: [
580
+ /*#__PURE__*/ jsx(SelectTrigger, {
581
+ className: "w-full",
582
+ "aria-label": labels.providerStep,
583
+ children: /*#__PURE__*/ jsx(SelectValue, {
584
+ placeholder: labels.providerPlaceholder
585
+ })
586
+ }),
587
+ /*#__PURE__*/ jsx(SelectContent, {
588
+ container: container,
589
+ children: providers.map((p)=>/*#__PURE__*/ jsx(SelectItem, {
590
+ value: p.id,
591
+ children: p.name
592
+ }, p.id))
593
+ })
594
+ ]
595
+ })
596
+ }),
597
+ /*#__PURE__*/ jsx(Step, {
598
+ n: 2,
599
+ title: labels.connectionStep,
600
+ done: connected,
601
+ disabled: !provider,
602
+ children: /*#__PURE__*/ jsxs("div", {
603
+ className: "flex flex-col gap-3",
604
+ children: [
605
+ !provider && /*#__PURE__*/ jsx(Input, {
606
+ disabled: true,
607
+ "aria-label": labels.connectionStep,
608
+ placeholder: labels.connectionNeedsProvider
609
+ }),
610
+ provider && providerConnections.length > 0 && /*#__PURE__*/ jsxs(Select, {
611
+ value: connectionChoice,
612
+ onValueChange: chooseConnection,
613
+ disabled: busy,
614
+ children: [
615
+ /*#__PURE__*/ jsx(SelectTrigger, {
616
+ className: "w-full",
617
+ "aria-label": labels.connectionStep,
618
+ children: /*#__PURE__*/ jsx(SelectValue, {})
619
+ }),
620
+ /*#__PURE__*/ jsxs(SelectContent, {
621
+ container: container,
622
+ children: [
623
+ providerConnections.map((c)=>/*#__PURE__*/ jsx(SelectItem, {
624
+ value: c.id,
625
+ children: labels.savedConnection(c.name, folderLabel(c.folderId))
626
+ }, c.id)),
627
+ /*#__PURE__*/ jsx(SelectItem, {
628
+ value: NEW,
629
+ children: labels.newConnection
630
+ })
631
+ ]
632
+ })
633
+ ]
634
+ }),
635
+ connectMessage && /*#__PURE__*/ jsxs("p", {
636
+ className: "flex items-center gap-1.5 text-xs text-success",
637
+ children: [
638
+ /*#__PURE__*/ jsx(CircleCheck, {
639
+ size: 14,
640
+ className: "shrink-0"
641
+ }),
642
+ connectMessage
643
+ ]
644
+ }),
645
+ connection && !editingConnection && /*#__PURE__*/ jsx("div", {
646
+ children: /*#__PURE__*/ jsx(Button, {
647
+ variant: "link",
648
+ size: "2xs",
649
+ className: "h-auto p-0 text-xs",
650
+ disabled: busy || 'ok' !== formState.status,
651
+ onClick: startConnectionEdit,
652
+ children: labels.editConnection
653
+ })
654
+ }),
655
+ showConnectionForm && /*#__PURE__*/ jsxs(Fragment, {
656
+ children: [
657
+ /*#__PURE__*/ jsxs(Group, {
658
+ icon: KeyRound,
659
+ title: labels.credentialsTitle(providerName),
660
+ caption: labels.credentialsCaption(providerName),
661
+ children: [
662
+ 'loading' === formState.status && /*#__PURE__*/ jsxs("div", {
663
+ className: "flex items-center gap-2 text-xs text-foreground-muted",
664
+ children: [
665
+ /*#__PURE__*/ jsx(Spinner, {
666
+ size: "sm"
667
+ }),
668
+ " ",
669
+ labels.loadingForm(providerName)
670
+ ]
671
+ }),
672
+ 'error' === formState.status && /*#__PURE__*/ jsx(FailureAlert, {
673
+ failure: formState.failure,
674
+ labels: labels
675
+ }),
676
+ loadingConnectionValues && /*#__PURE__*/ jsxs("div", {
677
+ className: "flex items-center gap-2 text-xs text-foreground-muted",
678
+ children: [
679
+ /*#__PURE__*/ jsx(Spinner, {
680
+ size: "sm"
681
+ }),
682
+ " ",
683
+ labels.loadingConnection
684
+ ]
685
+ }),
686
+ form.authTypes.length > 1 && /*#__PURE__*/ jsx(Field, {
687
+ id: "byo-auth-type",
688
+ label: labels.authType,
689
+ children: /*#__PURE__*/ jsxs(Select, {
690
+ value: authType ?? void 0,
691
+ onValueChange: setAuthType,
692
+ disabled: keyLocked,
693
+ children: [
694
+ /*#__PURE__*/ jsx(SelectTrigger, {
695
+ id: "byo-auth-type",
696
+ className: "w-full",
697
+ children: /*#__PURE__*/ jsx(SelectValue, {})
698
+ }),
699
+ /*#__PURE__*/ jsx(SelectContent, {
700
+ container: container,
701
+ children: form.authTypes.map((t)=>/*#__PURE__*/ jsx(SelectItem, {
702
+ value: t.value,
703
+ children: t.label
704
+ }, t.value))
705
+ })
706
+ ]
707
+ })
708
+ }),
709
+ mainFields.map((f)=>fieldInput(f, true)),
710
+ advancedFields.length > 0 && /*#__PURE__*/ jsxs(Collapsible, {
711
+ open: moreOpen,
712
+ onOpenChange: setMoreOpen,
713
+ children: [
714
+ /*#__PURE__*/ jsxs(CollapsibleTrigger, {
715
+ className: "flex items-center gap-1 text-xs font-medium text-foreground-muted hover:text-foreground",
716
+ children: [
717
+ /*#__PURE__*/ jsx(ChevronRight, {
718
+ size: 14,
719
+ className: cn('transition-transform', moreOpen && 'rotate-90')
720
+ }),
721
+ labels.moreSettings(providerName),
722
+ /*#__PURE__*/ jsxs("span", {
723
+ className: "font-normal text-foreground-subtle",
724
+ children: [
725
+ "\xb7 ",
726
+ labels.optional
727
+ ]
728
+ })
729
+ ]
730
+ }),
731
+ /*#__PURE__*/ jsx(CollapsibleContent, {
732
+ className: "mt-3 flex flex-col gap-3",
733
+ children: advancedFields.map((f)=>fieldInput(f, false))
734
+ })
735
+ ]
736
+ })
737
+ ]
738
+ }),
739
+ /*#__PURE__*/ jsxs(Group, {
740
+ icon: Building2,
741
+ title: labels.inUiPathTitle,
742
+ caption: labels.inUiPathCaption(providerName),
743
+ children: [
744
+ /*#__PURE__*/ jsxs("div", {
745
+ className: "grid min-w-0 grid-cols-2 gap-3",
746
+ children: [
747
+ /*#__PURE__*/ jsx(Field, {
748
+ id: "byo-conn-name",
749
+ label: labels.connectionName,
750
+ children: /*#__PURE__*/ jsx(Input, {
751
+ id: "byo-conn-name",
752
+ value: connName,
753
+ disabled: keyLocked,
754
+ onChange: (e)=>setConnName(e.target.value),
755
+ "aria-invalid": connNameClash
756
+ })
757
+ }),
758
+ /*#__PURE__*/ jsx(Field, {
759
+ id: "byo-folder",
760
+ label: labels.folder,
761
+ children: /*#__PURE__*/ jsxs(Select, {
762
+ value: formFolderId || void 0,
763
+ onValueChange: setFolderId,
764
+ disabled: keyLocked || editingConnection,
765
+ children: [
766
+ /*#__PURE__*/ jsx(SelectTrigger, {
767
+ id: "byo-folder",
768
+ className: "w-full",
769
+ children: /*#__PURE__*/ jsx(SelectValue, {})
770
+ }),
771
+ /*#__PURE__*/ jsx(SelectContent, {
772
+ container: container,
773
+ children: folders.map((f)=>/*#__PURE__*/ jsx(SelectItem, {
774
+ value: f.id,
775
+ children: f.label
776
+ }, f.id))
777
+ })
778
+ ]
779
+ })
780
+ })
781
+ ]
782
+ }),
783
+ /*#__PURE__*/ jsx("p", {
784
+ className: cn('text-xs', connNameClash ? 'text-error' : 'text-foreground-muted'),
785
+ children: connNameClash ? labels.connectionNameTaken : labels.folderHint
786
+ })
787
+ ]
788
+ }),
789
+ /*#__PURE__*/ jsxs("div", {
790
+ className: "flex items-center gap-2",
791
+ children: [
792
+ /*#__PURE__*/ jsx(Button, {
793
+ variant: "secondary",
794
+ size: "sm",
795
+ disabled: !canConnect,
796
+ onClick: runConnect,
797
+ children: /*#__PURE__*/ jsx(ConnectButtonText, {
798
+ running: 'running' === connect.status,
799
+ editing: editingConnection,
800
+ labels: labels
801
+ })
802
+ }),
803
+ editingConnection && /*#__PURE__*/ jsx(Button, {
804
+ variant: "ghost",
805
+ size: "sm",
806
+ disabled: 'running' === connect.status,
807
+ onClick: cancelConnectionEdit,
808
+ children: labels.cancelConnectionEdit
809
+ })
810
+ ]
811
+ })
812
+ ]
813
+ })
814
+ ]
815
+ })
816
+ }),
817
+ /*#__PURE__*/ jsx(Step, {
818
+ n: 3,
819
+ title: labels.modelStep,
820
+ done: hasModel,
821
+ disabled: !connected,
822
+ children: freeTextModel ? /*#__PURE__*/ jsx(Input, {
823
+ ref: modelTriggerRef,
824
+ "aria-label": labels.modelIdLabel,
825
+ placeholder: labels.modelIdPlaceholder,
826
+ value: modelId,
827
+ disabled: busy,
828
+ onChange: (e)=>pickModel(e.target.value)
829
+ }) : /*#__PURE__*/ jsxs(Popover, {
830
+ open: modelListOpen,
831
+ onOpenChange: (next)=>{
832
+ setModelListOpen(next);
833
+ if (!next) setModelQuery('');
834
+ },
835
+ modal: true,
836
+ children: [
837
+ /*#__PURE__*/ jsx(PopoverTrigger, {
838
+ asChild: true,
839
+ children: /*#__PURE__*/ jsxs(Button, {
840
+ ref: modelTriggerRef,
841
+ variant: "outline",
842
+ role: "combobox",
843
+ "aria-expanded": modelListOpen,
844
+ "aria-label": labels.modelStep,
845
+ disabled: !connected || busy || 'ok' !== modelsState.status,
846
+ className: "w-full justify-between font-normal",
847
+ children: [
848
+ modelId ? /*#__PURE__*/ jsx("span", {
849
+ className: "truncate font-mono text-xs",
850
+ children: modelId
851
+ }) : /*#__PURE__*/ jsx("span", {
852
+ className: "truncate text-foreground-muted",
853
+ children: modelTriggerText
854
+ }),
855
+ /*#__PURE__*/ jsx(ChevronDown, {
856
+ className: "shrink-0 opacity-50"
857
+ })
858
+ ]
859
+ })
860
+ }),
861
+ /*#__PURE__*/ jsx(PopoverContent, {
862
+ container: container,
863
+ align: "start",
864
+ className: "w-[var(--radix-popover-trigger-width)] overflow-hidden p-0",
865
+ onOpenAutoFocus: (e)=>{
866
+ e.preventDefault();
867
+ modelSearchRef.current?.focus();
868
+ },
869
+ children: /*#__PURE__*/ jsxs(Command, {
870
+ shouldFilter: false,
871
+ children: [
872
+ /*#__PURE__*/ jsx(CommandInput, {
873
+ ref: modelSearchRef,
874
+ "aria-label": labels.modelStep,
875
+ placeholder: labels.modelSearch(models.compatible.length + models.incompatible.length),
876
+ value: modelQuery,
877
+ onValueChange: setModelQuery
878
+ }),
879
+ /*#__PURE__*/ jsxs(CommandList, {
880
+ className: "max-h-[280px]",
881
+ children: [
882
+ /*#__PURE__*/ jsx(CommandEmpty, {
883
+ children: labels.modelNoMatch(modelQuery)
884
+ }),
885
+ shownCompatible.length > 0 && /*#__PURE__*/ jsx(CommandGroup, {
886
+ heading: labels.compatibleGroup(shownCompatible.length),
887
+ children: shownCompatible.map((m)=>/*#__PURE__*/ jsx(ModelRow, {
888
+ model: m,
889
+ selected: m.id === modelId,
890
+ onSelect: ()=>{
891
+ pickModel(m.id);
892
+ setModelListOpen(false);
893
+ setModelQuery('');
894
+ }
895
+ }, m.id))
896
+ }),
897
+ shownIncompatible.length > 0 && /*#__PURE__*/ jsx(CommandGroup, {
898
+ heading: labels.incompatibleGroup(shownIncompatible.length),
899
+ children: shownIncompatible.map((m)=>/*#__PURE__*/ jsx(ModelRow, {
900
+ model: m,
901
+ disabled: true
902
+ }, m.id))
903
+ })
904
+ ]
905
+ })
906
+ ]
907
+ })
908
+ })
909
+ ]
910
+ })
911
+ }),
912
+ /*#__PURE__*/ jsx(Step, {
913
+ n: 4,
914
+ title: labels.nameStep,
915
+ done: hasModel && nameReady,
916
+ disabled: !hasModel,
917
+ children: /*#__PURE__*/ jsxs("div", {
918
+ className: "flex flex-col gap-3",
919
+ children: [
920
+ canUseOwnName && replacementOptions.length > 0 && /*#__PURE__*/ jsxs(RadioGroup, {
921
+ value: useAs,
922
+ onValueChange: (v)=>{
923
+ setUseAs(v);
924
+ setTest({
925
+ status: 'idle'
926
+ });
927
+ },
928
+ disabled: busy,
929
+ "aria-label": labels.nameStep,
930
+ className: "flex flex-wrap gap-4",
931
+ children: [
932
+ /*#__PURE__*/ jsxs("div", {
933
+ className: "flex items-center gap-2",
934
+ children: [
935
+ /*#__PURE__*/ jsx(RadioGroupItem, {
936
+ value: "own",
937
+ id: "byo-use-own"
938
+ }),
939
+ /*#__PURE__*/ jsx(Label, {
940
+ htmlFor: "byo-use-own",
941
+ className: "text-xs font-normal",
942
+ children: labels.useOwnName
943
+ })
944
+ ]
945
+ }),
946
+ /*#__PURE__*/ jsxs("div", {
947
+ className: "flex items-center gap-2",
948
+ children: [
949
+ /*#__PURE__*/ jsx(RadioGroupItem, {
950
+ value: "replacement",
951
+ id: "byo-use-replacement"
952
+ }),
953
+ /*#__PURE__*/ jsx(Label, {
954
+ htmlFor: "byo-use-replacement",
955
+ className: "text-xs font-normal",
956
+ children: labels.useReplacement
957
+ })
958
+ ]
959
+ })
960
+ ]
961
+ }),
962
+ replacing ? /*#__PURE__*/ jsxs("div", {
963
+ className: "flex flex-col gap-1.5",
964
+ children: [
965
+ /*#__PURE__*/ jsxs(Select, {
966
+ value: replacement?.name,
967
+ onValueChange: (v)=>{
968
+ setReplaces(v);
969
+ setTest({
970
+ status: 'idle'
971
+ });
972
+ },
973
+ disabled: busy,
974
+ children: [
975
+ /*#__PURE__*/ jsx(SelectTrigger, {
976
+ className: "w-full",
977
+ "aria-label": labels.useReplacement,
978
+ children: /*#__PURE__*/ jsx(SelectValue, {
979
+ placeholder: labels.replacementPlaceholder
980
+ })
981
+ }),
982
+ /*#__PURE__*/ jsx(SelectContent, {
983
+ container: container,
984
+ children: replacementOptions.map((m)=>/*#__PURE__*/ jsxs(SelectItem, {
985
+ value: m.name,
986
+ children: [
987
+ /*#__PURE__*/ jsx("span", {
988
+ className: "font-mono text-xs",
989
+ children: m.name
990
+ }),
991
+ m.retiresOn && /*#__PURE__*/ jsx("span", {
992
+ className: "ml-2 text-xs text-foreground-muted",
993
+ children: labels.deprecated
994
+ })
995
+ ]
996
+ }, m.name))
997
+ })
998
+ ]
999
+ }),
1000
+ /*#__PURE__*/ jsx("p", {
1001
+ className: cn('text-xs', replacement?.retiresOn ? 'text-warning' : 'text-foreground-muted'),
1002
+ children: replacement?.retiresOn ? labels.retiresOn(replacement.retiresOn) : labels.replacementHint
1003
+ })
1004
+ ]
1005
+ }) : /*#__PURE__*/ jsxs("div", {
1006
+ className: "flex flex-col gap-1.5",
1007
+ children: [
1008
+ /*#__PURE__*/ jsx(Input, {
1009
+ "aria-label": labels.nameStep,
1010
+ value: name,
1011
+ disabled: busy,
1012
+ onChange: (e)=>{
1013
+ setName(e.target.value);
1014
+ setNameTouched(true);
1015
+ setTest({
1016
+ status: 'idle'
1017
+ });
1018
+ },
1019
+ "aria-invalid": Boolean(nameProblem)
1020
+ }),
1021
+ /*#__PURE__*/ jsx("p", {
1022
+ className: cn('text-xs', nameProblem ? 'text-error' : 'text-foreground-muted'),
1023
+ children: nameProblem ?? labels.nameHint
1024
+ })
1025
+ ]
1026
+ })
1027
+ ]
1028
+ })
1029
+ }),
1030
+ /*#__PURE__*/ jsx(Step, {
1031
+ n: 5,
1032
+ title: labels.apiTypeStep,
1033
+ done: readyToSave,
1034
+ disabled: !hasModel || !nameReady,
1035
+ children: /*#__PURE__*/ jsxs("div", {
1036
+ className: "flex flex-col gap-1.5",
1037
+ children: [
1038
+ /*#__PURE__*/ jsxs(Select, {
1039
+ value: apiTypeReady ? apiType : void 0,
1040
+ onValueChange: (v)=>{
1041
+ setApiType(v);
1042
+ setTest({
1043
+ status: 'idle'
1044
+ });
1045
+ },
1046
+ disabled: busy || 0 === apiTypeOptions.length,
1047
+ children: [
1048
+ /*#__PURE__*/ jsx(SelectTrigger, {
1049
+ className: "w-full",
1050
+ "aria-label": labels.apiTypeStep,
1051
+ children: /*#__PURE__*/ jsx(SelectValue, {
1052
+ placeholder: labels.apiTypePlaceholder
1053
+ })
1054
+ }),
1055
+ /*#__PURE__*/ jsx(SelectContent, {
1056
+ container: container,
1057
+ children: apiTypeOptions.map((t)=>/*#__PURE__*/ jsx(SelectItem, {
1058
+ value: t.value,
1059
+ children: t.label
1060
+ }, t.value))
1061
+ })
1062
+ ]
1063
+ }),
1064
+ /*#__PURE__*/ jsx("p", {
1065
+ className: "text-xs text-foreground-muted",
1066
+ children: hasModel && nameReady && 0 === apiTypeOptions.length ? labels.apiTypeNone(providerName) : labels.apiTypeHint
1067
+ })
1068
+ ]
1069
+ })
1070
+ })
1071
+ ]
1072
+ })
1073
+ ]
1074
+ }),
1075
+ failure && /*#__PURE__*/ jsx("div", {
1076
+ className: "max-h-[40%] shrink-0 overflow-y-auto border-t border-border-subtle px-6 py-3",
1077
+ children: /*#__PURE__*/ jsx(FailureAlert, {
1078
+ failure: failure,
1079
+ labels: labels
1080
+ })
1081
+ }),
1082
+ /*#__PURE__*/ jsxs(DialogFooter, {
1083
+ className: "shrink-0 items-center border-t border-border-subtle px-6 py-4",
1084
+ children: [
1085
+ /*#__PURE__*/ jsx(Button, {
1086
+ variant: "secondary",
1087
+ onClick: onClose,
1088
+ children: labels.cancel
1089
+ }),
1090
+ /*#__PURE__*/ jsx("span", {
1091
+ title: provider ? saveHint(providerName) : void 0,
1092
+ children: /*#__PURE__*/ jsx(Button, {
1093
+ onClick: runTest,
1094
+ disabled: !readyToSave || busy,
1095
+ children: 'running' === test.status ? /*#__PURE__*/ jsxs(Fragment, {
1096
+ children: [
1097
+ /*#__PURE__*/ jsx(Spinner, {
1098
+ size: "sm"
1099
+ }),
1100
+ " ",
1101
+ labels.testing
1102
+ ]
1103
+ }) : saveLabel
1104
+ })
1105
+ })
1106
+ ]
1107
+ })
1108
+ ]
1109
+ });
1110
+ }
1111
+ function ConnectButtonText({ running, editing, labels }) {
1112
+ if (running) return /*#__PURE__*/ jsxs(Fragment, {
1113
+ children: [
1114
+ /*#__PURE__*/ jsx(Spinner, {
1115
+ size: "sm"
1116
+ }),
1117
+ " ",
1118
+ editing ? labels.savingConnection : labels.connecting
1119
+ ]
1120
+ });
1121
+ return /*#__PURE__*/ jsx(Fragment, {
1122
+ children: editing ? labels.saveConnection : labels.connect
1123
+ });
1124
+ }
1125
+ const unexpected = (err)=>({
1126
+ title: err instanceof Error ? err.message : String(err)
1127
+ });
1128
+ function Step({ n, title, done, disabled, children }) {
1129
+ return /*#__PURE__*/ jsxs("fieldset", {
1130
+ disabled: disabled,
1131
+ className: cn('m-0 min-w-0 border-0 p-0', disabled && 'opacity-40'),
1132
+ children: [
1133
+ /*#__PURE__*/ jsxs("legend", {
1134
+ className: "mb-2 flex items-center gap-2 p-0",
1135
+ children: [
1136
+ /*#__PURE__*/ jsx("span", {
1137
+ className: cn('grid size-5 shrink-0 place-items-center rounded-full text-xs font-semibold', done ? 'bg-brand text-foreground-on-accent' : 'border border-border text-foreground-muted'),
1138
+ children: done ? /*#__PURE__*/ jsx(Check, {
1139
+ size: 12
1140
+ }) : n
1141
+ }),
1142
+ /*#__PURE__*/ jsx("span", {
1143
+ className: "text-sm font-medium text-foreground",
1144
+ children: title
1145
+ })
1146
+ ]
1147
+ }),
1148
+ /*#__PURE__*/ jsx("div", {
1149
+ className: "min-w-0 pl-7",
1150
+ children: children
1151
+ })
1152
+ ]
1153
+ });
1154
+ }
1155
+ function Group({ icon: Icon, title, caption, children }) {
1156
+ return /*#__PURE__*/ jsxs("div", {
1157
+ className: "flex min-w-0 flex-col gap-3 rounded-xl border border-border-subtle p-3",
1158
+ children: [
1159
+ /*#__PURE__*/ jsxs("div", {
1160
+ className: "flex items-center gap-1.5 text-xs",
1161
+ children: [
1162
+ /*#__PURE__*/ jsx(Icon, {
1163
+ size: 13,
1164
+ className: "shrink-0 text-foreground-muted"
1165
+ }),
1166
+ /*#__PURE__*/ jsx("span", {
1167
+ className: "font-semibold text-foreground",
1168
+ children: title
1169
+ }),
1170
+ /*#__PURE__*/ jsxs("span", {
1171
+ className: "truncate text-foreground-muted",
1172
+ children: [
1173
+ "\xb7 ",
1174
+ caption
1175
+ ]
1176
+ })
1177
+ ]
1178
+ }),
1179
+ children
1180
+ ]
1181
+ });
1182
+ }
1183
+ function Field({ id, label, hint, required, children }) {
1184
+ return /*#__PURE__*/ jsxs("div", {
1185
+ className: "flex flex-col gap-1.5",
1186
+ children: [
1187
+ /*#__PURE__*/ jsxs(Label, {
1188
+ htmlFor: id,
1189
+ className: "text-xs",
1190
+ children: [
1191
+ label,
1192
+ required && /*#__PURE__*/ jsx("span", {
1193
+ "aria-hidden": true,
1194
+ className: "text-error",
1195
+ children: ' *'
1196
+ })
1197
+ ]
1198
+ }),
1199
+ children,
1200
+ hint && /*#__PURE__*/ jsx("p", {
1201
+ className: "text-xs text-foreground-muted",
1202
+ children: hint
1203
+ })
1204
+ ]
1205
+ });
1206
+ }
1207
+ function FailureAlert({ failure, labels }) {
1208
+ const [showRaw, setShowRaw] = useState(false);
1209
+ return /*#__PURE__*/ jsxs(Alert, {
1210
+ variant: "destructive",
1211
+ className: "min-w-0",
1212
+ children: [
1213
+ /*#__PURE__*/ jsx(AlertCircle, {}),
1214
+ /*#__PURE__*/ jsx(AlertTitle, {
1215
+ children: failure.title
1216
+ }),
1217
+ failure.detail && /*#__PURE__*/ jsxs(AlertDescription, {
1218
+ className: "break-words",
1219
+ children: [
1220
+ /*#__PURE__*/ jsx(Button, {
1221
+ variant: "link",
1222
+ size: "2xs",
1223
+ className: "mt-1 block h-auto p-0 text-xs",
1224
+ onClick: ()=>setShowRaw((v)=>!v),
1225
+ children: showRaw ? labels.hideResponse : labels.showResponse
1226
+ }),
1227
+ showRaw && /*#__PURE__*/ jsx("pre", {
1228
+ className: "mt-2 max-h-40 overflow-y-auto whitespace-pre-wrap break-words rounded-md bg-surface p-2 font-mono text-xs leading-4 text-foreground-muted",
1229
+ children: failure.detail
1230
+ })
1231
+ ]
1232
+ }),
1233
+ !failure.detail && failure.message && /*#__PURE__*/ jsx(AlertDescription, {
1234
+ className: "break-words",
1235
+ children: failure.message
1236
+ })
1237
+ ]
1238
+ });
1239
+ }
1240
+ function ModelRow({ model, selected, disabled, onSelect }) {
1241
+ return /*#__PURE__*/ jsxs(CommandItem, {
1242
+ value: model.id,
1243
+ onSelect: onSelect,
1244
+ disabled: disabled,
1245
+ title: model.reason,
1246
+ className: "gap-2 py-1.5 data-[disabled=true]:pointer-events-auto data-[disabled=true]:cursor-default",
1247
+ children: [
1248
+ /*#__PURE__*/ jsx(Check, {
1249
+ size: 14,
1250
+ className: cn('shrink-0', selected ? 'text-foreground-accent' : 'opacity-0')
1251
+ }),
1252
+ /*#__PURE__*/ jsx("span", {
1253
+ className: "min-w-0 truncate font-mono text-xs text-foreground",
1254
+ children: model.id
1255
+ }),
1256
+ /*#__PURE__*/ jsx("span", {
1257
+ className: "ml-auto min-w-0 shrink truncate pl-2 text-right text-xs text-foreground-muted",
1258
+ children: model.short ?? model.note
1259
+ })
1260
+ ]
1261
+ });
1262
+ }
1263
+ export { ByoModelDialog };