@uipath/apollo-wind 2.54.1 → 2.56.0
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.
- package/dist/components/ui/index.cjs +117 -107
- package/dist/components/ui/index.d.ts +1 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/components/ui/model-picker/ModelPicker.cjs +495 -0
- package/dist/components/ui/model-picker/ModelPicker.d.ts +304 -0
- package/dist/components/ui/model-picker/ModelPicker.js +451 -0
- package/dist/components/ui/model-picker/ModelTagChip.cjs +101 -0
- package/dist/components/ui/model-picker/ModelTagChip.d.ts +29 -0
- package/dist/components/ui/model-picker/ModelTagChip.js +67 -0
- package/dist/components/ui/model-picker/badges.cjs +52 -0
- package/dist/components/ui/model-picker/badges.d.ts +41 -0
- package/dist/components/ui/model-picker/badges.js +18 -0
- package/dist/components/ui/model-picker/index.cjs +117 -0
- package/dist/components/ui/model-picker/index.d.ts +27 -0
- package/dist/components/ui/model-picker/index.js +14 -0
- package/dist/components/ui/model-picker/labels.cjs +107 -0
- package/dist/components/ui/model-picker/labels.d.ts +81 -0
- package/dist/components/ui/model-picker/labels.js +67 -0
- package/dist/components/ui/model-picker/primitives/FolderSwitcher.cjs +108 -0
- package/dist/components/ui/model-picker/primitives/FolderSwitcher.d.ts +38 -0
- package/dist/components/ui/model-picker/primitives/FolderSwitcher.js +74 -0
- package/dist/components/ui/model-picker/primitives/GroupHeader.cjs +84 -0
- package/dist/components/ui/model-picker/primitives/GroupHeader.d.ts +64 -0
- package/dist/components/ui/model-picker/primitives/GroupHeader.js +50 -0
- package/dist/components/ui/model-picker/primitives/ModelOptionRow.cjs +178 -0
- package/dist/components/ui/model-picker/primitives/ModelOptionRow.d.ts +95 -0
- package/dist/components/ui/model-picker/primitives/ModelOptionRow.js +135 -0
- package/dist/components/ui/model-picker/primitives/OptionList.cjs +295 -0
- package/dist/components/ui/model-picker/primitives/OptionList.d.ts +87 -0
- package/dist/components/ui/model-picker/primitives/OptionList.js +242 -0
- package/dist/components/ui/model-picker/primitives/PickerPopup.cjs +64 -0
- package/dist/components/ui/model-picker/primitives/PickerPopup.d.ts +39 -0
- package/dist/components/ui/model-picker/primitives/PickerPopup.js +30 -0
- package/dist/components/ui/model-picker/primitives/PickerSearchInput.cjs +77 -0
- package/dist/components/ui/model-picker/primitives/PickerSearchInput.d.ts +43 -0
- package/dist/components/ui/model-picker/primitives/PickerSearchInput.js +43 -0
- package/dist/components/ui/model-picker/primitives/PickerTrigger.cjs +112 -0
- package/dist/components/ui/model-picker/primitives/PickerTrigger.d.ts +73 -0
- package/dist/components/ui/model-picker/primitives/PickerTrigger.js +78 -0
- package/dist/components/ui/model-picker/types.cjs +18 -0
- package/dist/components/ui/model-picker/types.d.ts +154 -0
- package/dist/components/ui/model-picker/types.js +0 -0
- package/dist/components/ui/model-picker/useModelPickerState.cjs +250 -0
- package/dist/components/ui/model-picker/useModelPickerState.d.ts +135 -0
- package/dist/components/ui/model-picker/useModelPickerState.js +216 -0
- package/dist/components/ui/model-picker/utils.cjs +327 -0
- package/dist/components/ui/model-picker/utils.d.ts +121 -0
- package/dist/components/ui/model-picker/utils.js +272 -0
- package/dist/editor-themes/codemirror.cjs +27 -27
- package/dist/editor-themes/codemirror.d.ts +3 -2
- package/dist/editor-themes/codemirror.js +27 -27
- package/dist/editor-themes/monaco.cjs +157 -91
- package/dist/editor-themes/monaco.d.ts +130 -64
- package/dist/editor-themes/monaco.js +157 -91
- package/dist/index.cjs +83 -10
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -1
- package/dist/styles.css +121 -14
- package/package.json +2 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { DiscoveryModel } from '../types';
|
|
3
|
+
import { type DeriveModelTagsContext } from '../utils';
|
|
4
|
+
export interface PickerTriggerProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'id' | 'className' | 'disabled' | 'onClick' | 'placeholder'> {
|
|
5
|
+
id: string;
|
|
6
|
+
selected: DiscoveryModel | null;
|
|
7
|
+
/**
|
|
8
|
+
* Raw stored value that didn't resolve against `models`. When set,
|
|
9
|
+
* the trigger renders the id verbatim in error red with the border
|
|
10
|
+
* switched to error red — so a stale config doesn't look identical
|
|
11
|
+
* to "nothing selected". `null` for the normal case.
|
|
12
|
+
*/
|
|
13
|
+
unknownValue?: string | null;
|
|
14
|
+
/**
|
|
15
|
+
* Stored value whose model has not resolved *yet* because the catalog is
|
|
16
|
+
* still loading. Rendered as plain text — unlike `unknownValue`, this is
|
|
17
|
+
* not an error state, and showing the placeholder instead would read as
|
|
18
|
+
* "your saved model is gone" every time a form opens.
|
|
19
|
+
*/
|
|
20
|
+
pendingValue?: string | null;
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
open: boolean;
|
|
24
|
+
invalid?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Context forwarded to `deriveModelTags` for the selected model's
|
|
27
|
+
* chips. Carries the translator, `homeRegion`, test overrides, and
|
|
28
|
+
* `customTagsFor`.
|
|
29
|
+
*/
|
|
30
|
+
tagContext?: DeriveModelTagsContext;
|
|
31
|
+
/**
|
|
32
|
+
* Variant lookup for tag kinds the design system doesn't know about.
|
|
33
|
+
* Forwarded straight to `<ModelTagChip>`.
|
|
34
|
+
*/
|
|
35
|
+
tagVariants?: Record<string, string>;
|
|
36
|
+
/** Extra content rendered to the right of the model name, before the caret. */
|
|
37
|
+
extra?: React.ReactNode;
|
|
38
|
+
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
|
39
|
+
/**
|
|
40
|
+
* Tag kinds to hide from the trigger's selected-model chips. Used by
|
|
41
|
+
* the compact picker to keep the trigger uncluttered.
|
|
42
|
+
*/
|
|
43
|
+
hideTagKinds?: readonly string[];
|
|
44
|
+
/**
|
|
45
|
+
* ID of the popup's listbox, for `aria-controls`, so screen readers
|
|
46
|
+
* know which element the trigger opens.
|
|
47
|
+
*/
|
|
48
|
+
controlsId?: string;
|
|
49
|
+
/**
|
|
50
|
+
* ID of an external error message. Forwarded as `aria-describedby`
|
|
51
|
+
* so screen readers announce the error alongside the field.
|
|
52
|
+
*/
|
|
53
|
+
describedById?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Whether the field is required. Forwarded as `aria-required`, which is
|
|
56
|
+
* valid on the trigger's `combobox` role; the label's asterisk is
|
|
57
|
+
* `aria-hidden`, so this is the only place it is announced.
|
|
58
|
+
*/
|
|
59
|
+
required?: boolean;
|
|
60
|
+
className?: string;
|
|
61
|
+
'data-testid'?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The picker's field control. A plain `<button>` rather than the shared
|
|
65
|
+
* `Button` so it can carry the two-line/chips content and the invalid
|
|
66
|
+
* state without fighting `Button`'s own size and gap variants; the
|
|
67
|
+
* resting chrome deliberately matches wind's `outline` field styling so
|
|
68
|
+
* the picker sits consistently alongside other form controls.
|
|
69
|
+
*
|
|
70
|
+
* Designed to be used as a Radix `<PopoverTrigger asChild>` child, so
|
|
71
|
+
* it forwards its ref and spreads no props it doesn't own.
|
|
72
|
+
*/
|
|
73
|
+
export declare const PickerTrigger: React.ForwardRefExoticComponent<PickerTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ChevronDown } from "lucide-react";
|
|
4
|
+
import { forwardRef } from "react";
|
|
5
|
+
import { cn } from "../../../../lib/index.js";
|
|
6
|
+
import { DEFAULT_MODEL_PICKER_LABELS } from "../labels.js";
|
|
7
|
+
import { ModelTagChip } from "../ModelTagChip.js";
|
|
8
|
+
import { deriveModelTags } from "../utils.js";
|
|
9
|
+
const PickerTrigger_PickerTrigger = /*#__PURE__*/ forwardRef(function({ id, selected, unknownValue, pendingValue, placeholder = 'Select a model', disabled, open, invalid, tagContext, tagVariants, extra, onClick, hideTagKinds, controlsId, describedById, required, className, 'data-testid': dataTestId, ...rest }, ref) {
|
|
10
|
+
const labels = tagContext?.labels ?? DEFAULT_MODEL_PICKER_LABELS;
|
|
11
|
+
const effectiveCtx = tagContext ?? {
|
|
12
|
+
labels
|
|
13
|
+
};
|
|
14
|
+
const inlineTags = selected ? deriveModelTags(selected, effectiveCtx).filter((t)=>!hideTagKinds?.includes(t.kind)) : [];
|
|
15
|
+
const primary = selected ? selected.displayName ?? selected.modelName : null;
|
|
16
|
+
const ownClick = onClick ? {
|
|
17
|
+
onClick
|
|
18
|
+
} : {};
|
|
19
|
+
return /*#__PURE__*/ jsxs("button", {
|
|
20
|
+
...rest,
|
|
21
|
+
...ownClick,
|
|
22
|
+
"aria-controls": open && controlsId ? controlsId : void 0,
|
|
23
|
+
"aria-describedby": describedById,
|
|
24
|
+
"aria-expanded": open,
|
|
25
|
+
"aria-haspopup": "listbox",
|
|
26
|
+
"aria-invalid": invalid ? true : void 0,
|
|
27
|
+
"aria-required": required || void 0,
|
|
28
|
+
role: "combobox",
|
|
29
|
+
className: cn('flex min-h-9 w-full cursor-pointer items-center justify-start gap-3 rounded-md border border-input bg-transparent px-3 py-1 text-left text-sm text-foreground transition-colors', 'focus:ring-2 focus:ring-ring focus:outline-none', 'focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none', 'disabled:cursor-not-allowed disabled:opacity-50', 'aria-invalid:border-error aria-invalid:focus-visible:ring-error', 'future:h-10 future:gap-4 future:rounded-xl future:border-0 future:bg-surface-overlay future:px-4 future:py-2 future:text-sm future:font-normal future:hover:bg-surface-hover future:focus-visible:ring-offset-2 future:focus-visible:ring-offset-background future:aria-invalid:ring-1 future:aria-invalid:ring-error/40', className),
|
|
30
|
+
"data-slot": "model-picker-trigger",
|
|
31
|
+
"data-testid": dataTestId,
|
|
32
|
+
disabled: disabled,
|
|
33
|
+
id: id,
|
|
34
|
+
ref: ref,
|
|
35
|
+
type: "button",
|
|
36
|
+
children: [
|
|
37
|
+
/*#__PURE__*/ jsx("span", {
|
|
38
|
+
className: "flex min-w-0 flex-1 flex-nowrap items-center gap-1.5",
|
|
39
|
+
children: selected ? /*#__PURE__*/ jsxs(Fragment, {
|
|
40
|
+
children: [
|
|
41
|
+
/*#__PURE__*/ jsx("span", {
|
|
42
|
+
className: "max-w-full truncate text-foreground",
|
|
43
|
+
children: primary
|
|
44
|
+
}),
|
|
45
|
+
inlineTags.map((t)=>/*#__PURE__*/ jsx("span", {
|
|
46
|
+
className: "flex shrink-0 items-center",
|
|
47
|
+
children: /*#__PURE__*/ jsx(ModelTagChip, {
|
|
48
|
+
disableTooltip: true,
|
|
49
|
+
tag: t,
|
|
50
|
+
variants: tagVariants
|
|
51
|
+
})
|
|
52
|
+
}, `${t.kind}-${t.label}`))
|
|
53
|
+
]
|
|
54
|
+
}) : pendingValue ? /*#__PURE__*/ jsx("span", {
|
|
55
|
+
className: "max-w-full truncate text-foreground",
|
|
56
|
+
children: pendingValue
|
|
57
|
+
}) : unknownValue ? /*#__PURE__*/ jsx("span", {
|
|
58
|
+
className: "max-w-full truncate text-error",
|
|
59
|
+
title: labels.unknownValueTooltip(unknownValue),
|
|
60
|
+
children: unknownValue
|
|
61
|
+
}) : /*#__PURE__*/ jsx("span", {
|
|
62
|
+
className: "text-foreground-subtle",
|
|
63
|
+
children: placeholder
|
|
64
|
+
})
|
|
65
|
+
}),
|
|
66
|
+
extra && /*#__PURE__*/ jsx("span", {
|
|
67
|
+
className: "flex shrink-0 items-center",
|
|
68
|
+
onClick: (e)=>e.stopPropagation(),
|
|
69
|
+
children: extra
|
|
70
|
+
}),
|
|
71
|
+
/*#__PURE__*/ jsx(ChevronDown, {
|
|
72
|
+
"aria-hidden": true,
|
|
73
|
+
className: cn('size-[18px] shrink-0 text-foreground-muted transition-transform duration-150', open && 'rotate-180')
|
|
74
|
+
})
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
export { PickerTrigger_PickerTrigger as PickerTrigger };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model shape the picker renders. It follows the LLM Gateway
|
|
3
|
+
* `ModelDiscoveryResponse` DTO field-for-field so a host can hand Discovery
|
|
4
|
+
* rows straight through, but the picker performs no request itself — how
|
|
5
|
+
* the rows are fetched is the host's business.
|
|
6
|
+
*
|
|
7
|
+
* Kept intentionally permissive (string unions, optional fields) so the
|
|
8
|
+
* picker survives backend additions without a coordinated release.
|
|
9
|
+
*/
|
|
10
|
+
export type ModelVendor = 'OpenAi' | 'AzureOpenAi' | 'AnthropicClaude' | 'AwsBedrock' | 'VertexAi' | 'Custom' | string;
|
|
11
|
+
export type ModelSubscriptionType = 'UiPathOwned' | 'BYOMReplacedLikeForLike' | 'BYOMReplacedAlternative' | 'BYOMAdded' | string;
|
|
12
|
+
export type ModelGeography = 'EU' | 'CA' | 'US' | 'SI' | 'JA' | 'AU' | 'IN' | 'UK' | 'CH' | 'UAE' | 'SK' | 'GLOBAL' | string;
|
|
13
|
+
export type ModelType = 'RequestResponse' | 'Realtime' | string;
|
|
14
|
+
export interface DeprecationDetails {
|
|
15
|
+
usageEndDate?: string;
|
|
16
|
+
replacedBy?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ByomDetails {
|
|
19
|
+
availableOperationCodes?: string[];
|
|
20
|
+
integrationServiceConnectionId?: string;
|
|
21
|
+
defaultModel?: string;
|
|
22
|
+
customFieldMappings?: Record<string, string> | null;
|
|
23
|
+
/**
|
|
24
|
+
* Id of the `ByoProductLlmConfiguration` this model belongs to — the
|
|
25
|
+
* `:id` route segment of the AI Trust Layer LLM-configurations edit
|
|
26
|
+
* page. Served by Discovery as `byoConfigurationId` (UiPath/Arima#2659);
|
|
27
|
+
* when absent, the picker's edit affordance falls back to the
|
|
28
|
+
* configurations list page.
|
|
29
|
+
*/
|
|
30
|
+
byoConfigurationId?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Token costs in cents per million tokens (the gateway's unit). */
|
|
33
|
+
export interface ModelFlatCosts {
|
|
34
|
+
inputTokenCost?: number;
|
|
35
|
+
outputTokenCost?: number;
|
|
36
|
+
cacheReadInputTokenCost?: number;
|
|
37
|
+
cacheWriteInputTokenCost?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface ModelTieredCost extends ModelFlatCosts {
|
|
40
|
+
minimumTokens?: number;
|
|
41
|
+
maximumTokens?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface ModelCostDetails {
|
|
44
|
+
/** `Flat` | `Tiered` */
|
|
45
|
+
pricingType?: string;
|
|
46
|
+
flatCosts?: ModelFlatCosts;
|
|
47
|
+
tieredCosts?: ModelTieredCost[];
|
|
48
|
+
}
|
|
49
|
+
export interface ModelDetails {
|
|
50
|
+
maxOutputTokens?: number;
|
|
51
|
+
contextWindowTokens?: number;
|
|
52
|
+
costDetails?: ModelCostDetails;
|
|
53
|
+
shouldUseMaxCompletionTokens?: boolean;
|
|
54
|
+
shouldSkipParallelToolCalls?: boolean;
|
|
55
|
+
shouldSkipTemperature?: boolean;
|
|
56
|
+
shouldSkipTopP?: boolean;
|
|
57
|
+
shouldUseResponseApi?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface RoutingDetails {
|
|
60
|
+
geography?: ModelGeography;
|
|
61
|
+
model?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface DiscoveryModel {
|
|
64
|
+
modelId: string;
|
|
65
|
+
modelName: string;
|
|
66
|
+
/**
|
|
67
|
+
* Human-friendly display name (e.g. "Claude Sonnet 4.6"). Authored
|
|
68
|
+
* centrally in the product's Model Hub configuration and merged into
|
|
69
|
+
* the Discovery response server-side, exactly like `isRecommended`.
|
|
70
|
+
* `undefined` means the backend has not rolled the field out yet; the
|
|
71
|
+
* picker then renders the raw `modelName`. There is deliberately no
|
|
72
|
+
* per-product rename prop.
|
|
73
|
+
*/
|
|
74
|
+
displayName?: string;
|
|
75
|
+
effectiveModel?: string | null;
|
|
76
|
+
vendor: ModelVendor;
|
|
77
|
+
modelFamily?: string;
|
|
78
|
+
apiFlavor?: string;
|
|
79
|
+
modelSubscriptionType?: ModelSubscriptionType;
|
|
80
|
+
/**
|
|
81
|
+
* Whether the product team has promoted this model. Authored
|
|
82
|
+
* centrally in the product's Model Hub configuration and merged into
|
|
83
|
+
* the Discovery response server-side — products should NOT fetch the
|
|
84
|
+
* config themselves. `undefined` means the backend hasn't rolled the
|
|
85
|
+
* field out yet; the picker then falls back to a local heuristic
|
|
86
|
+
* (`UiPathOwned && !preview && !deprecating`).
|
|
87
|
+
*/
|
|
88
|
+
isRecommended?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* AITL governance verdict: the requesting org's policy blocks this
|
|
91
|
+
* model. The picker never renders blocked models — mirroring how the
|
|
92
|
+
* platform's BFFs drop them from their catalogs.
|
|
93
|
+
*/
|
|
94
|
+
isBlockedByPolicy?: boolean;
|
|
95
|
+
isPreview?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Interaction shape of the model (`RequestResponse` | `Realtime`).
|
|
98
|
+
* The picker renders every modality it is given; a product that offers
|
|
99
|
+
* text generation only passes `filter={isTextGenerationModel}`.
|
|
100
|
+
*/
|
|
101
|
+
modelType?: ModelType;
|
|
102
|
+
deprecationDetails?: DeprecationDetails | null;
|
|
103
|
+
byomDetails?: ByomDetails | null;
|
|
104
|
+
modelDetails?: ModelDetails;
|
|
105
|
+
routingDetails?: RoutingDetails | null;
|
|
106
|
+
/**
|
|
107
|
+
* Optional connection metadata. Discovery doesn't surface this directly today
|
|
108
|
+
* but BYO callers can hydrate it from `/api/byom` for richer rendering.
|
|
109
|
+
*/
|
|
110
|
+
byoConnectionLabel?: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Tags rendered as chips next to a model. Derived locally from the DTO
|
|
114
|
+
* (`deriveModelTags`) — the API does not return chip strings.
|
|
115
|
+
*
|
|
116
|
+
* Open-ended on purpose: products can mint their own kinds via
|
|
117
|
+
* `customTagsFor` (e.g. `'multimodal'`, `'on-prem'`). Built-in kinds
|
|
118
|
+
* get an Apollo MUI chip variant out of the box; unknown kinds fall
|
|
119
|
+
* back to the neutral gray `mini` chip unless overridden via
|
|
120
|
+
* `ModelPickerProps.customTagVariants` or `ModelTag.variant`.
|
|
121
|
+
*/
|
|
122
|
+
export type ModelTagKind = 'recommended' | 'preview' | 'deprecating' | 'substituted' | 'custom' | 'out-of-region' | 'thinking' | 'cost-basic' | 'cost-standard' | 'cost-premium' | string;
|
|
123
|
+
/**
|
|
124
|
+
* Categorical cost tier. By default the picker stamps the matching pool
|
|
125
|
+
* badge (`cost-basic` / `cost-standard` / `cost-premium`) on any model
|
|
126
|
+
* that carries cost data, classified by `defaultCostTier`. A host that
|
|
127
|
+
* wants different bins, or no cost chips, passes `badgesFor` — it
|
|
128
|
+
* replaces the default entirely (return `[]` to suppress).
|
|
129
|
+
*/
|
|
130
|
+
export type CostTier = 'basic' | 'standard' | 'premium';
|
|
131
|
+
export interface ModelTag {
|
|
132
|
+
kind: ModelTagKind;
|
|
133
|
+
label: string;
|
|
134
|
+
/** Optional tooltip shown on hover. */
|
|
135
|
+
tooltip?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Apollo MUI chip variant class to render this tag with. Built-in
|
|
138
|
+
* kinds resolve to a default variant automatically (e.g.
|
|
139
|
+
* `recommended` → `success-mini`). Use this for product-specific
|
|
140
|
+
* kinds, or to override the default on a built-in kind for a single
|
|
141
|
+
* tag. Falls back to `'mini'` (neutral gray) when omitted.
|
|
142
|
+
*/
|
|
143
|
+
variant?: string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* One section in the picker dropdown. The picker groups models by
|
|
147
|
+
* subscription type by default; consumers can override via `groupBy`.
|
|
148
|
+
*/
|
|
149
|
+
export interface ModelGroup {
|
|
150
|
+
key: string;
|
|
151
|
+
label: string;
|
|
152
|
+
hint?: string;
|
|
153
|
+
models: DiscoveryModel[];
|
|
154
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
useModelPickerState: ()=>useModelPickerState
|
|
28
|
+
});
|
|
29
|
+
const external_react_namespaceObject = require("react");
|
|
30
|
+
const OptionList_cjs_namespaceObject = require("./primitives/OptionList.cjs");
|
|
31
|
+
const external_utils_cjs_namespaceObject = require("./utils.cjs");
|
|
32
|
+
function useModelPickerState(opts) {
|
|
33
|
+
const { models, value, valueConnectionId, onChange, groupBy: initialGroupBy = "subscription", collapsibleGroups = true, recommendedModelIds, previewModelIds, filter, initiallyCollapsedGroups, labels } = opts;
|
|
34
|
+
const reactId = (0, external_react_namespaceObject.useId)().replace(/[^A-Za-z0-9_-]/g, '');
|
|
35
|
+
const id = `apollo-model-picker-${reactId}`;
|
|
36
|
+
const triggerRef = (0, external_react_namespaceObject.useRef)(null);
|
|
37
|
+
const searchRef = (0, external_react_namespaceObject.useRef)(null);
|
|
38
|
+
const [open, setOpen] = (0, external_react_namespaceObject.useState)(false);
|
|
39
|
+
const [query, setQuery] = (0, external_react_namespaceObject.useState)('');
|
|
40
|
+
const [activeIndex, setActiveIndex] = (0, external_react_namespaceObject.useState)(0);
|
|
41
|
+
const [groupBy, setGroupBy] = (0, external_react_namespaceObject.useState)(initialGroupBy);
|
|
42
|
+
const lastInitialGroupBy = (0, external_react_namespaceObject.useRef)(initialGroupBy);
|
|
43
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
44
|
+
if (lastInitialGroupBy.current === initialGroupBy) return;
|
|
45
|
+
lastInitialGroupBy.current = initialGroupBy;
|
|
46
|
+
setGroupBy(initialGroupBy);
|
|
47
|
+
}, [
|
|
48
|
+
initialGroupBy
|
|
49
|
+
]);
|
|
50
|
+
const [collapsedSet, setCollapsedSet] = (0, external_react_namespaceObject.useState)(()=>new Set(initiallyCollapsedGroups ?? []));
|
|
51
|
+
const visibleModels = (0, external_react_namespaceObject.useMemo)(()=>filter ? models.filter(filter) : models, [
|
|
52
|
+
models,
|
|
53
|
+
filter
|
|
54
|
+
]);
|
|
55
|
+
const annotated = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
56
|
+
const groups = (0, external_utils_cjs_namespaceObject.groupModels)(visibleModels, groupBy, {
|
|
57
|
+
recommendedModelIds,
|
|
58
|
+
previewModelIds,
|
|
59
|
+
labels
|
|
60
|
+
});
|
|
61
|
+
return groups.flatMap((g)=>g.models.map((m)=>({
|
|
62
|
+
...m,
|
|
63
|
+
groupKey: g.key,
|
|
64
|
+
groupLabel: g.label
|
|
65
|
+
})));
|
|
66
|
+
}, [
|
|
67
|
+
visibleModels,
|
|
68
|
+
groupBy,
|
|
69
|
+
recommendedModelIds,
|
|
70
|
+
previewModelIds,
|
|
71
|
+
labels
|
|
72
|
+
]);
|
|
73
|
+
const filtered = (0, external_react_namespaceObject.useMemo)(()=>(0, external_utils_cjs_namespaceObject.filterModels)(annotated, query), [
|
|
74
|
+
annotated,
|
|
75
|
+
query
|
|
76
|
+
]);
|
|
77
|
+
const groupCounts = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
78
|
+
const out = {};
|
|
79
|
+
for (const m of annotated)out[m.groupKey] = (out[m.groupKey] ?? 0) + 1;
|
|
80
|
+
return out;
|
|
81
|
+
}, [
|
|
82
|
+
annotated
|
|
83
|
+
]);
|
|
84
|
+
const matchesValue = (0, external_react_namespaceObject.useCallback)((m)=>{
|
|
85
|
+
if (valueConnectionId) {
|
|
86
|
+
const connId = m.byomDetails?.integrationServiceConnectionId;
|
|
87
|
+
if (connId !== valueConnectionId) return false;
|
|
88
|
+
}
|
|
89
|
+
return m.modelId === value || m.modelName === value;
|
|
90
|
+
}, [
|
|
91
|
+
value,
|
|
92
|
+
valueConnectionId
|
|
93
|
+
]);
|
|
94
|
+
const pickMatch = (0, external_react_namespaceObject.useCallback)((list)=>{
|
|
95
|
+
const hits = list.filter(matchesValue);
|
|
96
|
+
if (0 === hits.length) return null;
|
|
97
|
+
if (valueConnectionId) return hits[0] ?? null;
|
|
98
|
+
return hits.find((m)=>!(0, external_utils_cjs_namespaceObject.isByoModel)(m)) ?? hits[0] ?? null;
|
|
99
|
+
}, [
|
|
100
|
+
matchesValue,
|
|
101
|
+
valueConnectionId
|
|
102
|
+
]);
|
|
103
|
+
const selected = (0, external_react_namespaceObject.useMemo)(()=>pickMatch(annotated) ?? pickMatch(models), [
|
|
104
|
+
annotated,
|
|
105
|
+
models,
|
|
106
|
+
pickMatch
|
|
107
|
+
]);
|
|
108
|
+
const unknownValue = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
109
|
+
if (!value) return null;
|
|
110
|
+
if (selected) return null;
|
|
111
|
+
if (0 === models.length) return null;
|
|
112
|
+
return value;
|
|
113
|
+
}, [
|
|
114
|
+
models,
|
|
115
|
+
selected,
|
|
116
|
+
value
|
|
117
|
+
]);
|
|
118
|
+
const canCollapse = collapsibleGroups && 'flat' !== groupBy && !query.trim();
|
|
119
|
+
const collapsedGroups = (0, external_react_namespaceObject.useMemo)(()=>canCollapse ? collapsedSet : new Set(), [
|
|
120
|
+
canCollapse,
|
|
121
|
+
collapsedSet
|
|
122
|
+
]);
|
|
123
|
+
const toggleGroup = (0, external_react_namespaceObject.useCallback)((groupKey)=>{
|
|
124
|
+
setCollapsedSet((prev)=>{
|
|
125
|
+
const next = new Set(prev);
|
|
126
|
+
if (next.has(groupKey)) next.delete(groupKey);
|
|
127
|
+
else next.add(groupKey);
|
|
128
|
+
return next;
|
|
129
|
+
});
|
|
130
|
+
}, []);
|
|
131
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
132
|
+
if (open) {
|
|
133
|
+
const sel = filtered.findIndex(matchesValue);
|
|
134
|
+
setActiveIndex(sel >= 0 ? sel : 0);
|
|
135
|
+
requestAnimationFrame(()=>searchRef.current?.focus());
|
|
136
|
+
} else setQuery('');
|
|
137
|
+
}, [
|
|
138
|
+
open
|
|
139
|
+
]);
|
|
140
|
+
const isHiddenAt = (0, external_react_namespaceObject.useCallback)((i)=>{
|
|
141
|
+
const g = filtered[i]?.groupKey;
|
|
142
|
+
return void 0 !== g && (0, OptionList_cjs_namespaceObject.isCollapsibleGroup)(g) && collapsedGroups.has(g);
|
|
143
|
+
}, [
|
|
144
|
+
filtered,
|
|
145
|
+
collapsedGroups
|
|
146
|
+
]);
|
|
147
|
+
const isCollapsedStop = (0, external_react_namespaceObject.useCallback)((i)=>isHiddenAt(i) && (0 === i || filtered[i - 1]?.groupKey !== filtered[i]?.groupKey), [
|
|
148
|
+
filtered,
|
|
149
|
+
isHiddenAt
|
|
150
|
+
]);
|
|
151
|
+
const nearestStop = (0, external_react_namespaceObject.useCallback)((from, dir)=>{
|
|
152
|
+
for(let i = from; i >= 0 && i < filtered.length; i += dir)if (!isHiddenAt(i) || isCollapsedStop(i)) return i;
|
|
153
|
+
return -1;
|
|
154
|
+
}, [
|
|
155
|
+
filtered.length,
|
|
156
|
+
isHiddenAt,
|
|
157
|
+
isCollapsedStop
|
|
158
|
+
]);
|
|
159
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
160
|
+
if (activeIndex >= filtered.length) return void setActiveIndex(0);
|
|
161
|
+
if (!isHiddenAt(activeIndex) || isCollapsedStop(activeIndex)) return;
|
|
162
|
+
let i = activeIndex;
|
|
163
|
+
while(i > 0 && filtered[i - 1]?.groupKey === filtered[i]?.groupKey)i -= 1;
|
|
164
|
+
setActiveIndex(i);
|
|
165
|
+
}, [
|
|
166
|
+
filtered,
|
|
167
|
+
activeIndex,
|
|
168
|
+
isHiddenAt,
|
|
169
|
+
isCollapsedStop
|
|
170
|
+
]);
|
|
171
|
+
const activeVisible = filtered.length > 0 && !isHiddenAt(activeIndex);
|
|
172
|
+
const choose = (0, external_react_namespaceObject.useCallback)((m)=>{
|
|
173
|
+
onChange?.(m);
|
|
174
|
+
setOpen(false);
|
|
175
|
+
triggerRef.current?.focus();
|
|
176
|
+
}, [
|
|
177
|
+
onChange
|
|
178
|
+
]);
|
|
179
|
+
const onSearchKeyDown = (0, external_react_namespaceObject.useCallback)((e)=>{
|
|
180
|
+
if ('ArrowDown' === e.key) {
|
|
181
|
+
e.preventDefault();
|
|
182
|
+
setActiveIndex((i)=>{
|
|
183
|
+
const next = nearestStop(i + 1, 1);
|
|
184
|
+
return -1 === next ? i : next;
|
|
185
|
+
});
|
|
186
|
+
} else if ('ArrowUp' === e.key) {
|
|
187
|
+
e.preventDefault();
|
|
188
|
+
setActiveIndex((i)=>{
|
|
189
|
+
const prev = nearestStop(i - 1, -1);
|
|
190
|
+
return -1 === prev ? i : prev;
|
|
191
|
+
});
|
|
192
|
+
} else if ('Enter' === e.key) {
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
const m = filtered[activeIndex];
|
|
195
|
+
if (m && !isHiddenAt(activeIndex)) choose(m);
|
|
196
|
+
} else if ('ArrowLeft' === e.key || 'ArrowRight' === e.key) {
|
|
197
|
+
const groupKey = filtered[activeIndex]?.groupKey;
|
|
198
|
+
if (!groupKey || !(0, OptionList_cjs_namespaceObject.isCollapsibleGroup)(groupKey) || !canCollapse) return;
|
|
199
|
+
const collapsed = collapsedGroups.has(groupKey);
|
|
200
|
+
if ('ArrowLeft' === e.key ? !collapsed : collapsed) {
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
toggleGroup(groupKey);
|
|
203
|
+
}
|
|
204
|
+
} else if ('Escape' === e.key) {
|
|
205
|
+
e.preventDefault();
|
|
206
|
+
setOpen(false);
|
|
207
|
+
triggerRef.current?.focus();
|
|
208
|
+
}
|
|
209
|
+
}, [
|
|
210
|
+
filtered,
|
|
211
|
+
activeIndex,
|
|
212
|
+
choose,
|
|
213
|
+
collapsedGroups,
|
|
214
|
+
canCollapse,
|
|
215
|
+
toggleGroup,
|
|
216
|
+
nearestStop,
|
|
217
|
+
isHiddenAt
|
|
218
|
+
]);
|
|
219
|
+
return {
|
|
220
|
+
open,
|
|
221
|
+
setOpen,
|
|
222
|
+
query,
|
|
223
|
+
setQuery,
|
|
224
|
+
groupBy,
|
|
225
|
+
setGroupBy,
|
|
226
|
+
visibleModels,
|
|
227
|
+
annotated,
|
|
228
|
+
filtered,
|
|
229
|
+
groupCounts,
|
|
230
|
+
collapsedGroups,
|
|
231
|
+
toggleGroup,
|
|
232
|
+
selected,
|
|
233
|
+
unknownValue,
|
|
234
|
+
activeIndex,
|
|
235
|
+
setActiveIndex,
|
|
236
|
+
onSearchKeyDown,
|
|
237
|
+
choose,
|
|
238
|
+
id,
|
|
239
|
+
triggerRef,
|
|
240
|
+
searchRef,
|
|
241
|
+
activeVisible
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
exports.useModelPickerState = __webpack_exports__.useModelPickerState;
|
|
245
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
246
|
+
"useModelPickerState"
|
|
247
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
248
|
+
Object.defineProperty(exports, '__esModule', {
|
|
249
|
+
value: true
|
|
250
|
+
});
|