@uipath/apollo-react 7.32.0 → 7.34.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/canvas/styles/tailwind.canvas.css +1 -1
- package/dist/canvas/utils/icon-registry.cjs +13 -29
- package/dist/canvas/utils/icon-registry.d.ts.map +1 -1
- package/dist/canvas/utils/icon-registry.js +15 -31
- package/dist/chat/styles/tailwind.chat.css +1 -1
- package/dist/decision-table/styles/tailwind.decision-table.css +1 -1
- package/dist/decision-table/useGridLayout.cjs +2 -2
- package/dist/decision-table/useGridLayout.d.ts.map +1 -1
- package/dist/decision-table/useGridLayout.js +2 -2
- package/dist/icons/APIWorkflowGlyph.cjs +1 -0
- package/dist/icons/APIWorkflowGlyph.d.ts +2 -0
- package/dist/icons/APIWorkflowGlyph.js +2 -0
- package/dist/icons/AgentGlyph.cjs +1 -0
- package/dist/icons/AgentGlyph.d.ts +2 -0
- package/dist/icons/AgentGlyph.js +2 -0
- package/dist/icons/FunctionGlyph.cjs +1 -0
- package/dist/icons/FunctionGlyph.d.ts +2 -0
- package/dist/icons/FunctionGlyph.js +2 -0
- package/dist/icons/RpaGlyph.cjs +1 -0
- package/dist/icons/RpaGlyph.d.ts +2 -0
- package/dist/icons/RpaGlyph.js +2 -0
- package/dist/material/components/ap-model-picker/ModelPicker.cjs +101 -6
- package/dist/material/components/ap-model-picker/ModelPicker.d.ts +8 -0
- package/dist/material/components/ap-model-picker/ModelPicker.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/ModelPicker.js +101 -6
- package/dist/material/components/ap-model-picker/communityByoApi.cjs +946 -0
- package/dist/material/components/ap-model-picker/communityByoApi.d.ts +20 -0
- package/dist/material/components/ap-model-picker/communityByoApi.d.ts.map +1 -0
- package/dist/material/components/ap-model-picker/communityByoApi.js +909 -0
- package/dist/material/components/ap-model-picker/communityByoLabels.cjs +387 -0
- package/dist/material/components/ap-model-picker/communityByoLabels.d.ts +5 -0
- package/dist/material/components/ap-model-picker/communityByoLabels.d.ts.map +1 -0
- package/dist/material/components/ap-model-picker/communityByoLabels.js +350 -0
- package/dist/material/components/ap-model-picker/index.cjs +8 -1
- package/dist/material/components/ap-model-picker/index.d.ts +3 -1
- package/dist/material/components/ap-model-picker/index.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/index.js +2 -1
- package/dist/material/components/ap-model-picker/locales/de.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/de.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/de.js +1 -1
- package/dist/material/components/ap-model-picker/locales/en.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/en.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/en.js +1 -1
- package/dist/material/components/ap-model-picker/locales/es-MX.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/es-MX.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/es-MX.js +1 -1
- package/dist/material/components/ap-model-picker/locales/es.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/es.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/es.js +1 -1
- package/dist/material/components/ap-model-picker/locales/fr.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/fr.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/fr.js +1 -1
- package/dist/material/components/ap-model-picker/locales/ja.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/ja.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/ja.js +1 -1
- package/dist/material/components/ap-model-picker/locales/ko.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/ko.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/ko.js +1 -1
- package/dist/material/components/ap-model-picker/locales/pt-BR.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/pt-BR.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/pt-BR.js +1 -1
- package/dist/material/components/ap-model-picker/locales/pt.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/pt.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/pt.js +1 -1
- package/dist/material/components/ap-model-picker/locales/ro.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/ro.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/ro.js +1 -1
- package/dist/material/components/ap-model-picker/locales/ru.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/ru.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/ru.js +1 -1
- package/dist/material/components/ap-model-picker/locales/tr.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/tr.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/tr.js +1 -1
- package/dist/material/components/ap-model-picker/locales/zh-CN.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/zh-CN.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/zh-CN.js +1 -1
- package/dist/material/components/ap-model-picker/locales/zh-TW.cjs +1 -1
- package/dist/material/components/ap-model-picker/locales/zh-TW.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/locales/zh-TW.js +1 -1
- package/dist/material/components/ap-model-picker/usePlatformAccess.cjs +10 -4
- package/dist/material/components/ap-model-picker/usePlatformAccess.d.ts +2 -0
- package/dist/material/components/ap-model-picker/usePlatformAccess.d.ts.map +1 -1
- package/dist/material/components/ap-model-picker/usePlatformAccess.js +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,909 @@
|
|
|
1
|
+
import { buildGatewayUrl, resolveToken } from "./usePlatformAccess.js";
|
|
2
|
+
const communityByoApi_field = (key, label, spec = {})=>({
|
|
3
|
+
key,
|
|
4
|
+
label,
|
|
5
|
+
secret: false,
|
|
6
|
+
required: true,
|
|
7
|
+
advanced: false,
|
|
8
|
+
group: null,
|
|
9
|
+
defaultValue: '',
|
|
10
|
+
placeholder: '',
|
|
11
|
+
hint: '',
|
|
12
|
+
...spec
|
|
13
|
+
});
|
|
14
|
+
const secret = (key, label, spec = {})=>communityByoApi_field(key, label, {
|
|
15
|
+
secret: true,
|
|
16
|
+
...spec
|
|
17
|
+
});
|
|
18
|
+
const advanced = (key, label, spec = {})=>communityByoApi_field(key, label, {
|
|
19
|
+
required: false,
|
|
20
|
+
advanced: true,
|
|
21
|
+
...spec
|
|
22
|
+
});
|
|
23
|
+
const singleAuth = (...fields)=>({
|
|
24
|
+
authTypes: [],
|
|
25
|
+
defaultAuthType: null,
|
|
26
|
+
fields
|
|
27
|
+
});
|
|
28
|
+
const AWS_REGIONS = [
|
|
29
|
+
[
|
|
30
|
+
'us-east-1',
|
|
31
|
+
'US East (N. Virginia)'
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
'us-east-2',
|
|
35
|
+
'US East (Ohio)'
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
'us-west-1',
|
|
39
|
+
'US West (N. California)'
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
'us-west-2',
|
|
43
|
+
'US West (Oregon)'
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
'ca-central-1',
|
|
47
|
+
'Canada (Central)'
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
'sa-east-1',
|
|
51
|
+
'South America (Sao Paulo)'
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
'eu-central-1',
|
|
55
|
+
'EU (Frankfurt)'
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
'eu-north-1',
|
|
59
|
+
'EU (Stockholm)'
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
'eu-south-1',
|
|
63
|
+
'EU (Milan)'
|
|
64
|
+
],
|
|
65
|
+
[
|
|
66
|
+
'eu-west-1',
|
|
67
|
+
'EU (Ireland)'
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
'eu-west-2',
|
|
71
|
+
'EU (London)'
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
'eu-west-3',
|
|
75
|
+
'EU (Paris)'
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
'me-south-1',
|
|
79
|
+
'Middle East (Bahrain)'
|
|
80
|
+
],
|
|
81
|
+
[
|
|
82
|
+
'af-south-1',
|
|
83
|
+
'Africa (Cape Town)'
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
'ap-east-1',
|
|
87
|
+
'Asia Pacific (Hong Kong)'
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
'ap-south-1',
|
|
91
|
+
'Asia Pacific (Mumbai)'
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
'ap-northeast-1',
|
|
95
|
+
'Asia Pacific (Tokyo)'
|
|
96
|
+
],
|
|
97
|
+
[
|
|
98
|
+
'ap-northeast-2',
|
|
99
|
+
'Asia Pacific (Seoul)'
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
'ap-northeast-3',
|
|
103
|
+
'Asia Pacific (Osaka)'
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
'ap-southeast-1',
|
|
107
|
+
'Asia Pacific (Singapore)'
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
'ap-southeast-2',
|
|
111
|
+
'Asia Pacific (Sydney)'
|
|
112
|
+
]
|
|
113
|
+
];
|
|
114
|
+
const IAM_ROLE_PLACEHOLDER = 'arn:aws:iam::123456789012:role/my-role';
|
|
115
|
+
const COMMUNITY_BYO_PROVIDERS = [
|
|
116
|
+
{
|
|
117
|
+
id: 'openai',
|
|
118
|
+
name: 'OpenAI',
|
|
119
|
+
connector: 'uipath-openai-openai',
|
|
120
|
+
connectorType: 'OpenAi',
|
|
121
|
+
form: singleAuth(secret('Authorization', 'API key', {
|
|
122
|
+
placeholder: 'sk-…',
|
|
123
|
+
hint: 'Find it in the OpenAI dashboard, under API keys.'
|
|
124
|
+
}))
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: 'azure-openai',
|
|
128
|
+
name: 'Azure OpenAI',
|
|
129
|
+
connector: 'uipath-microsoft-azureopenai',
|
|
130
|
+
connectorType: 'AzureOpenAi',
|
|
131
|
+
form: {
|
|
132
|
+
authTypes: [
|
|
133
|
+
{
|
|
134
|
+
value: 'customApiKey',
|
|
135
|
+
label: 'API key'
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
value: 'oauth2ClientCredentials',
|
|
139
|
+
label: 'Client credentials (Entra app)'
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
defaultAuthType: 'customApiKey',
|
|
143
|
+
fields: [
|
|
144
|
+
communityByoApi_field('url', 'Endpoint', {
|
|
145
|
+
placeholder: 'https://<resource>.openai.azure.com'
|
|
146
|
+
}),
|
|
147
|
+
secret('api-key', 'API key', {
|
|
148
|
+
group: 'customApiKey',
|
|
149
|
+
hint: "Find it in the Azure portal, on the resource's Keys and Endpoint page."
|
|
150
|
+
}),
|
|
151
|
+
communityByoApi_field('oauth.api.key', 'Client ID', {
|
|
152
|
+
group: 'oauth2ClientCredentials'
|
|
153
|
+
}),
|
|
154
|
+
secret('oauth.api.secret', 'Client secret', {
|
|
155
|
+
group: 'oauth2ClientCredentials'
|
|
156
|
+
}),
|
|
157
|
+
communityByoApi_field('tenantID', 'Tenant ID', {
|
|
158
|
+
group: 'oauth2ClientCredentials'
|
|
159
|
+
}),
|
|
160
|
+
advanced('api-version', 'API version', {
|
|
161
|
+
defaultValue: '2023-10-01-preview'
|
|
162
|
+
})
|
|
163
|
+
]
|
|
164
|
+
},
|
|
165
|
+
derive: (values)=>{
|
|
166
|
+
try {
|
|
167
|
+
const subdomain = values.url ? new URL(values.url).hostname.split('.')[0] : void 0;
|
|
168
|
+
return subdomain ? {
|
|
169
|
+
subdomain
|
|
170
|
+
} : {};
|
|
171
|
+
} catch {
|
|
172
|
+
return {};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
id: 'bedrock',
|
|
178
|
+
name: 'Amazon Bedrock',
|
|
179
|
+
connector: 'uipath-amazon-webservices',
|
|
180
|
+
connectorType: 'AmazonWebServices',
|
|
181
|
+
form: {
|
|
182
|
+
authTypes: [
|
|
183
|
+
{
|
|
184
|
+
value: 'accessKey',
|
|
185
|
+
label: 'Access key'
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
value: 'assumeRole',
|
|
189
|
+
label: 'Assume role'
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
defaultAuthType: 'accessKey',
|
|
193
|
+
fields: [
|
|
194
|
+
communityByoApi_field('aws.region', 'Region', {
|
|
195
|
+
placeholder: 'Select a region',
|
|
196
|
+
options: AWS_REGIONS.map(([value, label])=>({
|
|
197
|
+
value,
|
|
198
|
+
label: `${label} · ${value}`
|
|
199
|
+
}))
|
|
200
|
+
}),
|
|
201
|
+
communityByoApi_field('aws.api.key', 'Access key ID', {
|
|
202
|
+
group: 'accessKey'
|
|
203
|
+
}),
|
|
204
|
+
secret('aws.api.secret', 'Secret access key', {
|
|
205
|
+
group: 'accessKey'
|
|
206
|
+
}),
|
|
207
|
+
advanced('aws.temporary.session.token', 'Session token', {
|
|
208
|
+
secret: true,
|
|
209
|
+
group: 'accessKey',
|
|
210
|
+
hint: 'Only for temporary credentials.'
|
|
211
|
+
}),
|
|
212
|
+
communityByoApi_field('assume.role.aws.api.key', 'Access key ID', {
|
|
213
|
+
group: 'assumeRole'
|
|
214
|
+
}),
|
|
215
|
+
secret('assume.role.aws.api.secret', 'Secret access key', {
|
|
216
|
+
group: 'assumeRole'
|
|
217
|
+
}),
|
|
218
|
+
communityByoApi_field('assume.role.aws.iam.role', 'IAM role ARN', {
|
|
219
|
+
group: 'assumeRole',
|
|
220
|
+
placeholder: IAM_ROLE_PLACEHOLDER,
|
|
221
|
+
hint: 'The role these credentials assume to call Bedrock.'
|
|
222
|
+
}),
|
|
223
|
+
advanced('assume.role.aws.temporary.session.token', 'Session token', {
|
|
224
|
+
secret: true,
|
|
225
|
+
group: 'assumeRole',
|
|
226
|
+
hint: 'Only for temporary credentials.'
|
|
227
|
+
})
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
id: 'anthropic',
|
|
233
|
+
name: 'Anthropic',
|
|
234
|
+
connector: 'uipath-anthropic-claude',
|
|
235
|
+
connectorType: 'Anthropic',
|
|
236
|
+
form: singleAuth(secret('x-api-key', 'API key', {
|
|
237
|
+
placeholder: 'sk-ant-…'
|
|
238
|
+
}))
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
id: 'vertex',
|
|
242
|
+
name: 'Google Vertex',
|
|
243
|
+
connector: 'uipath-google-vertex',
|
|
244
|
+
connectorType: 'GoogleVertex',
|
|
245
|
+
form: singleAuth(communityByoApi_field('project.id', 'Project ID'), communityByoApi_field('region', 'Location', {
|
|
246
|
+
defaultValue: 'us-central1'
|
|
247
|
+
}), secret('service.account.key', 'Service account key', {
|
|
248
|
+
hint: "The service account's JSON key."
|
|
249
|
+
}))
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
id: 'nvidia-nim',
|
|
253
|
+
name: 'Nvidia NIM',
|
|
254
|
+
connector: 'uipath-nvidia-nim',
|
|
255
|
+
connectorType: 'NvidiaNim',
|
|
256
|
+
form: singleAuth(communityByoApi_field('url', 'Base URL', {
|
|
257
|
+
defaultValue: 'https://integrate.api.nvidia.com'
|
|
258
|
+
}), secret('apikey', 'API key'), communityByoApi_field('api_version', 'API version', {
|
|
259
|
+
defaultValue: 'v1'
|
|
260
|
+
}))
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
id: 'openai-compatible',
|
|
264
|
+
name: 'OpenAI-compatible',
|
|
265
|
+
connector: 'uipath-openai-openaiv1compliant',
|
|
266
|
+
connectorType: 'OpenAiV1Compatible',
|
|
267
|
+
form: singleAuth(communityByoApi_field('url', 'Base URL', {
|
|
268
|
+
placeholder: 'https://api.example.com',
|
|
269
|
+
hint: 'Without /v1: the connector adds it.'
|
|
270
|
+
}), secret('apikey', 'API key'))
|
|
271
|
+
}
|
|
272
|
+
];
|
|
273
|
+
const flavorsOf = (probes)=>[
|
|
274
|
+
...new Set((probes ?? []).flatMap((p)=>p.apiFlavor ? [
|
|
275
|
+
p.apiFlavor
|
|
276
|
+
] : []))
|
|
277
|
+
];
|
|
278
|
+
const retirementOf = (model)=>model.usageEndDate && 'N/A' !== model.usageEndDate ? model.usageEndDate : void 0;
|
|
279
|
+
const own = (map, key)=>Object.hasOwn(map, key) ? map[key] : void 0;
|
|
280
|
+
function connectorTypesByModelOf(data) {
|
|
281
|
+
const byModel = {};
|
|
282
|
+
for (const [connectorType, models] of Object.entries(data ?? {})){
|
|
283
|
+
if (!Array.isArray(models)) continue;
|
|
284
|
+
let group = [
|
|
285
|
+
connectorType
|
|
286
|
+
];
|
|
287
|
+
if (BEDROCK_CONNECTORS.includes(connectorType)) group = BEDROCK_CONNECTORS;
|
|
288
|
+
else if (OPENAI_CONNECTORS.includes(connectorType)) group = OPENAI_CONNECTORS;
|
|
289
|
+
for (const model of models)byModel[String(model)] = group;
|
|
290
|
+
}
|
|
291
|
+
return byModel;
|
|
292
|
+
}
|
|
293
|
+
const connectorsCarrying = (apiType)=>Object.entries(CONNECTOR_API_TYPES).flatMap(([type, apiTypes])=>apiTypes.includes(apiType) ? [
|
|
294
|
+
type
|
|
295
|
+
] : []);
|
|
296
|
+
const NOT_CHAT = [
|
|
297
|
+
[
|
|
298
|
+
/embed|rerank/i,
|
|
299
|
+
'Embedding model'
|
|
300
|
+
],
|
|
301
|
+
[
|
|
302
|
+
/moderation/i,
|
|
303
|
+
'Moderation model'
|
|
304
|
+
],
|
|
305
|
+
[
|
|
306
|
+
/tts|whisper|transcribe|audio/i,
|
|
307
|
+
'Audio model'
|
|
308
|
+
],
|
|
309
|
+
[
|
|
310
|
+
/realtime/i,
|
|
311
|
+
'Realtime model'
|
|
312
|
+
],
|
|
313
|
+
[
|
|
314
|
+
/image|dall-e|sora|imagen|veo-|nova-canvas|nova-reel|flux|stability\./i,
|
|
315
|
+
'Image or video model'
|
|
316
|
+
],
|
|
317
|
+
[
|
|
318
|
+
/davinci|babbage/i,
|
|
319
|
+
'Completions only'
|
|
320
|
+
]
|
|
321
|
+
];
|
|
322
|
+
const OPENAI_API_TYPES = [
|
|
323
|
+
'OpenAiChatCompletions',
|
|
324
|
+
'OpenAiResponses',
|
|
325
|
+
'OpenAiEmbeddings'
|
|
326
|
+
];
|
|
327
|
+
const CONNECTOR_API_TYPES = {
|
|
328
|
+
OpenAi: OPENAI_API_TYPES,
|
|
329
|
+
AzureOpenAi: OPENAI_API_TYPES,
|
|
330
|
+
AwsBedrock: [],
|
|
331
|
+
AmazonWebServices: [
|
|
332
|
+
'AwsBedrockInvoke',
|
|
333
|
+
'AwsBedrockConverse'
|
|
334
|
+
],
|
|
335
|
+
GoogleVertex: [
|
|
336
|
+
'GeminiGenerateContent',
|
|
337
|
+
'GeminiEmbeddings'
|
|
338
|
+
],
|
|
339
|
+
OpenAiV1Compatible: OPENAI_API_TYPES,
|
|
340
|
+
NvidiaNim: OPENAI_API_TYPES,
|
|
341
|
+
Anthropic: [
|
|
342
|
+
'AnthropicMessages'
|
|
343
|
+
]
|
|
344
|
+
};
|
|
345
|
+
const API_TYPE_LABELS = {
|
|
346
|
+
OpenAiChatCompletions: 'OpenAI Chat Completions',
|
|
347
|
+
OpenAiResponses: 'OpenAI Responses',
|
|
348
|
+
OpenAiEmbeddings: 'OpenAI Embeddings',
|
|
349
|
+
GeminiGenerateContent: 'Gemini Generate Content',
|
|
350
|
+
GeminiEmbeddings: 'Gemini Embeddings',
|
|
351
|
+
AwsBedrockInvoke: 'AWS Bedrock Invoke',
|
|
352
|
+
AwsBedrockConverse: 'AWS Bedrock Converse',
|
|
353
|
+
AnthropicMessages: 'Anthropic Messages'
|
|
354
|
+
};
|
|
355
|
+
const CHAT_COMPLETIONS = 'OpenAiChatCompletions';
|
|
356
|
+
const OPENAI_CONNECTORS = [
|
|
357
|
+
'AzureOpenAi',
|
|
358
|
+
'OpenAi',
|
|
359
|
+
'OpenAiV1Compatible'
|
|
360
|
+
];
|
|
361
|
+
const BEDROCK_CONNECTORS = [
|
|
362
|
+
'AwsBedrock',
|
|
363
|
+
'AmazonWebServices'
|
|
364
|
+
];
|
|
365
|
+
const ADD_OWN_MODELS = 'AnyModelWithOwnAdditions';
|
|
366
|
+
const NEW_CONNECTION_NOT_FOUND = 'IntegrationServiceConfigurationNotFound';
|
|
367
|
+
const MASKED_SECRET = '********';
|
|
368
|
+
const SESSION_POLLS = 20;
|
|
369
|
+
const SESSION_POLL_MS = 1500;
|
|
370
|
+
const RETRY_MS = 5000;
|
|
371
|
+
const asList = (data)=>{
|
|
372
|
+
if (Array.isArray(data)) return data;
|
|
373
|
+
if (data && 'object' == typeof data) {
|
|
374
|
+
const d = data;
|
|
375
|
+
if (Array.isArray(d.value)) return d.value;
|
|
376
|
+
if (Array.isArray(d.PageItems)) return d.PageItems;
|
|
377
|
+
}
|
|
378
|
+
return [];
|
|
379
|
+
};
|
|
380
|
+
const failure = (result, title)=>{
|
|
381
|
+
const d = result.data && 'object' == typeof result.data ? result.data : {
|
|
382
|
+
message: String(result.data ?? '')
|
|
383
|
+
};
|
|
384
|
+
const providerMessage = 'string' == typeof d.providerMessage ? d.providerMessage : '';
|
|
385
|
+
const message = providerMessage.replace(/^[A-Z]+ \S+\|\d+\|/, '') || ('string' == typeof d.message ? d.message : '') || ('string' == typeof d.Message ? d.Message : '');
|
|
386
|
+
return {
|
|
387
|
+
title: result.status ? `${title} (HTTP ${result.status})` : title,
|
|
388
|
+
message: message || void 0,
|
|
389
|
+
detail: JSON.stringify(result.data, null, 2)
|
|
390
|
+
};
|
|
391
|
+
};
|
|
392
|
+
const entryNamed = (configuration, name)=>configuration.llmConfigurations.find((entry)=>entry.desiredModel?.toLowerCase() === name.toLowerCase());
|
|
393
|
+
const prettyJson = (text)=>{
|
|
394
|
+
try {
|
|
395
|
+
return JSON.stringify(JSON.parse(text), null, 2);
|
|
396
|
+
} catch {
|
|
397
|
+
return text;
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
const ok = (value)=>({
|
|
401
|
+
ok: true,
|
|
402
|
+
value
|
|
403
|
+
});
|
|
404
|
+
const fail = (f)=>({
|
|
405
|
+
ok: false,
|
|
406
|
+
failure: f
|
|
407
|
+
});
|
|
408
|
+
function createCommunityByoApi(ctx, options) {
|
|
409
|
+
const providers = options.providers ?? COMMUNITY_BYO_PROVIDERS;
|
|
410
|
+
const sleep = options.sleep ?? ((ms)=>new Promise((r)=>setTimeout(r, ms)));
|
|
411
|
+
const graceMs = options.newConnectionGraceMs ?? 90000;
|
|
412
|
+
const product = ctx.requestingProduct ?? '';
|
|
413
|
+
const operationGroupName = options.operationGroupName ?? `${product}-${ctx.requestingFeature ?? ''}`;
|
|
414
|
+
const base = (ctx.baseUrl ?? '').replace(/\/$/, '');
|
|
415
|
+
const tenantUrl = (path)=>`${base}/${ctx.tenantName}/${path}`;
|
|
416
|
+
const byId = (id)=>providers.find((p)=>p.id === id);
|
|
417
|
+
const createdAt = new Map();
|
|
418
|
+
let openSession = null;
|
|
419
|
+
let rules = null;
|
|
420
|
+
async function whileNewConnectionInvisible(connectionId, attempt) {
|
|
421
|
+
const retryUntil = (createdAt.get(connectionId) ?? 0) + graceMs;
|
|
422
|
+
for(;;){
|
|
423
|
+
const startedAt = Date.now();
|
|
424
|
+
const result = await attempt();
|
|
425
|
+
const notFoundYet = JSON.stringify(result.data ?? '').includes(NEW_CONNECTION_NOT_FOUND);
|
|
426
|
+
if (!notFoundYet || Date.now() + RETRY_MS > retryUntil) return {
|
|
427
|
+
result,
|
|
428
|
+
startedAt
|
|
429
|
+
};
|
|
430
|
+
await sleep(RETRY_MS);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
async function call(method, url, { body, folderKey, headers } = {}) {
|
|
434
|
+
const bearer = await resolveToken(ctx.token);
|
|
435
|
+
const h = {
|
|
436
|
+
Authorization: `Bearer ${bearer}`,
|
|
437
|
+
Accept: 'application/json',
|
|
438
|
+
'Content-Type': 'application/json',
|
|
439
|
+
...headers
|
|
440
|
+
};
|
|
441
|
+
if (folderKey) h['X-UiPath-FolderKey'] = folderKey;
|
|
442
|
+
const res = await fetch(url, {
|
|
443
|
+
method,
|
|
444
|
+
headers: h,
|
|
445
|
+
body: void 0 === body ? void 0 : JSON.stringify(body)
|
|
446
|
+
});
|
|
447
|
+
const text = await res.text();
|
|
448
|
+
let data = null;
|
|
449
|
+
try {
|
|
450
|
+
data = text ? JSON.parse(text) : null;
|
|
451
|
+
} catch {
|
|
452
|
+
data = text;
|
|
453
|
+
}
|
|
454
|
+
return {
|
|
455
|
+
ok: res.ok,
|
|
456
|
+
status: res.status,
|
|
457
|
+
statusText: res.statusText,
|
|
458
|
+
data
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
async function session(provider, folderKey, connectionId = null) {
|
|
462
|
+
const reusable = openSession && openSession.connector === provider.connector && openSession.folderKey === folderKey && openSession.connectionId === connectionId && Date.now() < openSession.expiresAt - 30000;
|
|
463
|
+
if (reusable && openSession) return ok(openSession);
|
|
464
|
+
let r;
|
|
465
|
+
r = connectionId ? await call('POST', tenantUrl(`connections_/api/v1/Connections/${connectionId}/auth`), {
|
|
466
|
+
folderKey
|
|
467
|
+
}) : await call('POST', tenantUrl('connections_/api/v1/Connections/'), {
|
|
468
|
+
body: {
|
|
469
|
+
connector: provider.connector
|
|
470
|
+
},
|
|
471
|
+
folderKey
|
|
472
|
+
});
|
|
473
|
+
if (!r.ok) return fail(failure(r, 'Could not start the connection'));
|
|
474
|
+
const d = r.data;
|
|
475
|
+
openSession = {
|
|
476
|
+
id: d.sessionId,
|
|
477
|
+
connector: provider.connector,
|
|
478
|
+
folderKey,
|
|
479
|
+
connectionId,
|
|
480
|
+
expiresAt: d.expiresAt ?? Date.now() + 600000
|
|
481
|
+
};
|
|
482
|
+
return ok(openSession);
|
|
483
|
+
}
|
|
484
|
+
const sessionForm = (sid, folderKey)=>call('GET', tenantUrl(`elements_/v1/elements/normalized-instances/applications/sessions/${sid}`), {
|
|
485
|
+
folderKey
|
|
486
|
+
});
|
|
487
|
+
const configurationUrl = (configurationId)=>buildGatewayUrl(ctx, `api/byo/product/llm-configurations/${configurationId}`);
|
|
488
|
+
const loadContext = async ()=>{
|
|
489
|
+
const [folders, connections, products, vendorModels, modelApiTypes, configurations] = await Promise.all([
|
|
490
|
+
call('GET', tenantUrl('orchestrator_/api/FoldersNavigation/GetAllFoldersForCurrentUser?take=500&skip=0')),
|
|
491
|
+
call('GET', tenantUrl('connections_/api/v1/Connections?allFolders=true&folderDefaults=true')),
|
|
492
|
+
call('GET', buildGatewayUrl(ctx, 'api/byom/products')),
|
|
493
|
+
call('GET', buildGatewayUrl(ctx, 'api/byom/vendors/llms')),
|
|
494
|
+
call('GET', buildGatewayUrl(ctx, 'api/byom/vendors/llms/api-flavors')),
|
|
495
|
+
call('GET', buildGatewayUrl(ctx, 'api/byo/product/llm-configurations'))
|
|
496
|
+
]);
|
|
497
|
+
if (!folders.ok) return fail(failure(folders, 'Could not list your folders'));
|
|
498
|
+
if (!connections.ok) return fail(failure(connections, 'Could not list your connections'));
|
|
499
|
+
const notRead = 'Could not read which models you can bring';
|
|
500
|
+
for (const r of [
|
|
501
|
+
products,
|
|
502
|
+
vendorModels,
|
|
503
|
+
modelApiTypes,
|
|
504
|
+
configurations
|
|
505
|
+
])if (!r.ok) return fail(failure(r, notRead));
|
|
506
|
+
const feature = products.data?.[product]?.[operationGroupName];
|
|
507
|
+
if (!feature) return fail({
|
|
508
|
+
title: 'This feature does not take models of your own',
|
|
509
|
+
detail: `No BYO configuration for ${product} / ${operationGroupName}.`
|
|
510
|
+
});
|
|
511
|
+
if ('AllModels' === feature.modelsConfigurationOption) return fail({
|
|
512
|
+
title: 'This feature’s models are configured together in AI Trust Layer'
|
|
513
|
+
});
|
|
514
|
+
rules = {
|
|
515
|
+
feature,
|
|
516
|
+
connectorTypesByModel: connectorTypesByModelOf(vendorModels.data),
|
|
517
|
+
apiTypesByModel: modelApiTypes.data ?? {}
|
|
518
|
+
};
|
|
519
|
+
const configured = new Set(asList(configurations.data).filter((c)=>c.product === product && c.operationGroupName === operationGroupName).flatMap((c)=>asList(c.llmConfigurations ?? []).flatMap((e)=>'string' == typeof e.desiredModel ? [
|
|
520
|
+
e.desiredModel
|
|
521
|
+
] : [])));
|
|
522
|
+
const replaceableModels = (feature.models ?? []).map((m)=>({
|
|
523
|
+
name: m.model,
|
|
524
|
+
retiresOn: retirementOf(m),
|
|
525
|
+
replaced: configured.has(m.model)
|
|
526
|
+
})).sort((a, b)=>Number(Boolean(a.retiresOn)) - Number(Boolean(b.retiresOn)));
|
|
527
|
+
const rows = asList(folders.data).filter((f)=>false !== f.IsSelectable).map((f)=>({
|
|
528
|
+
folder: {
|
|
529
|
+
id: String(f.Key),
|
|
530
|
+
label: f.IsPersonal ? String(f.DisplayName) : String(f.FullyQualifiedName ?? f.DisplayName).split('/').join(' › ')
|
|
531
|
+
},
|
|
532
|
+
personal: Boolean(f.IsPersonal)
|
|
533
|
+
}));
|
|
534
|
+
rows.sort((a, b)=>Number(b.personal) - Number(a.personal));
|
|
535
|
+
const byConnector = (key)=>providers.find((p)=>p.connector === key);
|
|
536
|
+
const saved = asList(connections.data).flatMap((c)=>{
|
|
537
|
+
const connector = c.connector?.key;
|
|
538
|
+
const provider = byConnector(connector);
|
|
539
|
+
const folder = c.folder?.key;
|
|
540
|
+
return provider && folder ? [
|
|
541
|
+
{
|
|
542
|
+
id: String(c.id),
|
|
543
|
+
providerId: provider.id,
|
|
544
|
+
name: String(c.name),
|
|
545
|
+
folderId: folder
|
|
546
|
+
}
|
|
547
|
+
] : [];
|
|
548
|
+
});
|
|
549
|
+
return ok({
|
|
550
|
+
providers: providers.map(({ id, name })=>({
|
|
551
|
+
id,
|
|
552
|
+
name
|
|
553
|
+
})),
|
|
554
|
+
connections: saved,
|
|
555
|
+
folders: rows.map((r)=>r.folder),
|
|
556
|
+
defaultFolderId: rows[0]?.folder.id ?? null,
|
|
557
|
+
takenModelNames: [
|
|
558
|
+
...new Set([
|
|
559
|
+
...options.takenModelNames(),
|
|
560
|
+
...configured
|
|
561
|
+
])
|
|
562
|
+
],
|
|
563
|
+
replaceableModels,
|
|
564
|
+
allowsNewNames: feature.modelsConfigurationOption === ADD_OWN_MODELS,
|
|
565
|
+
reservedModelNames: Object.keys(rules.connectorTypesByModel)
|
|
566
|
+
});
|
|
567
|
+
};
|
|
568
|
+
const apiTypes = (providerId, replaces)=>{
|
|
569
|
+
const provider = byId(providerId);
|
|
570
|
+
if (!provider || !rules) return [];
|
|
571
|
+
const { feature, connectorTypesByModel, apiTypesByModel } = rules;
|
|
572
|
+
const addsOwn = feature.modelsConfigurationOption === ADD_OWN_MODELS;
|
|
573
|
+
const featureModel = replaces ? feature.models?.find((m)=>m.model === replaces) : void 0;
|
|
574
|
+
const probes = featureModel?.probes ?? (addsOwn ? feature.probes : void 0);
|
|
575
|
+
let supported;
|
|
576
|
+
const modelApiTypes = replaces ? own(apiTypesByModel, replaces) : null;
|
|
577
|
+
if (modelApiTypes) {
|
|
578
|
+
const featureFlavors = flavorsOf(feature.probes);
|
|
579
|
+
const withConnector = new Set(modelApiTypes.filter((t)=>connectorsCarrying(t).length));
|
|
580
|
+
withConnector.add(CHAT_COMPLETIONS);
|
|
581
|
+
supported = [
|
|
582
|
+
...withConnector
|
|
583
|
+
].filter((t)=>0 === featureFlavors.length || featureFlavors.includes(t));
|
|
584
|
+
}
|
|
585
|
+
let candidates;
|
|
586
|
+
if (probes?.length) {
|
|
587
|
+
const probeFlavors = flavorsOf(probes);
|
|
588
|
+
candidates = supported?.length ? probeFlavors.filter((t)=>supported.includes(t)) : probeFlavors;
|
|
589
|
+
} else candidates = supported?.length ? supported : Object.keys(API_TYPE_LABELS);
|
|
590
|
+
const servedBy = replaces ? own(connectorTypesByModel, replaces) : void 0;
|
|
591
|
+
const carried = CONNECTOR_API_TYPES[provider.connectorType] ?? [];
|
|
592
|
+
const shown = candidates.filter((t)=>{
|
|
593
|
+
if (!carried.includes(t)) return false;
|
|
594
|
+
if (replaces && !addsOwn && !servedBy?.includes(provider.connectorType)) return false;
|
|
595
|
+
if (t === CHAT_COMPLETIONS && servedBy && !servedBy.some((c)=>OPENAI_CONNECTORS.includes(c))) return false;
|
|
596
|
+
return true;
|
|
597
|
+
});
|
|
598
|
+
shown.sort((a, b)=>Number(a === CHAT_COMPLETIONS) - Number(b === CHAT_COMPLETIONS));
|
|
599
|
+
return shown.map((value)=>({
|
|
600
|
+
value,
|
|
601
|
+
label: API_TYPE_LABELS[value] ?? value
|
|
602
|
+
}));
|
|
603
|
+
};
|
|
604
|
+
const loadModel = async ({ configurationId, name })=>{
|
|
605
|
+
const r = await call('GET', configurationUrl(configurationId));
|
|
606
|
+
if (!r.ok) return fail(failure(r, `Could not read ${name}`));
|
|
607
|
+
const saved = r.data;
|
|
608
|
+
const entry = entryNamed(saved, name);
|
|
609
|
+
const provider = providers.find((p)=>p.connectorType.toLowerCase() === entry?.connectorType?.toLowerCase());
|
|
610
|
+
if (!entry || !provider || !entry.connectionId) return fail({
|
|
611
|
+
title: `${name} cannot be edited here`,
|
|
612
|
+
detail: JSON.stringify(saved, null, 2)
|
|
613
|
+
});
|
|
614
|
+
const savedName = entry.desiredModel ?? name;
|
|
615
|
+
const replaces = rules && own(rules.connectorTypesByModel, savedName) ? savedName : null;
|
|
616
|
+
return ok({
|
|
617
|
+
configurationId,
|
|
618
|
+
providerId: provider.id,
|
|
619
|
+
connectionId: entry.connectionId,
|
|
620
|
+
modelId: entry.customerModel ?? '',
|
|
621
|
+
name: savedName,
|
|
622
|
+
replaces,
|
|
623
|
+
apiType: entry.apiFlavor ?? null
|
|
624
|
+
});
|
|
625
|
+
};
|
|
626
|
+
const loadForm = async (providerId)=>{
|
|
627
|
+
const provider = byId(providerId);
|
|
628
|
+
if (!provider) return fail({
|
|
629
|
+
title: `Unknown provider ${providerId}`
|
|
630
|
+
});
|
|
631
|
+
return ok(provider.form);
|
|
632
|
+
};
|
|
633
|
+
const loadConnectionValues = async (providerId, connection)=>{
|
|
634
|
+
const provider = byId(providerId);
|
|
635
|
+
if (!provider) return fail({
|
|
636
|
+
title: `Unknown provider ${providerId}`
|
|
637
|
+
});
|
|
638
|
+
const { form } = provider;
|
|
639
|
+
const s = await session(provider, connection.folderId, connection.id);
|
|
640
|
+
if (!s.ok) return s;
|
|
641
|
+
const sf = await sessionForm(s.value.id, connection.folderId);
|
|
642
|
+
if (!sf.ok) return fail(failure(sf, 'Could not read the connection settings'));
|
|
643
|
+
const current = sf.data?.configs ?? {};
|
|
644
|
+
const values = {};
|
|
645
|
+
for (const field of form.fields){
|
|
646
|
+
if (field.secret) continue;
|
|
647
|
+
const value = current[field.key];
|
|
648
|
+
if (null != value && value !== MASKED_SECRET) values[field.key] = String(value);
|
|
649
|
+
}
|
|
650
|
+
const savedAuthType = current['authentication.type'];
|
|
651
|
+
const knownAuthType = form.authTypes.some((t)=>t.value === savedAuthType);
|
|
652
|
+
if (form.authTypes.length && savedAuthType && !knownAuthType) return fail({
|
|
653
|
+
title: 'Edit this connection in Integration Service',
|
|
654
|
+
message: `It uses an authentication type this dialog does not offer (${savedAuthType}).`
|
|
655
|
+
});
|
|
656
|
+
return ok({
|
|
657
|
+
authType: knownAuthType ? savedAuthType ?? null : form.defaultAuthType,
|
|
658
|
+
values
|
|
659
|
+
});
|
|
660
|
+
};
|
|
661
|
+
const connect = async ({ providerId, form, authType, values, name, folderId, existing })=>{
|
|
662
|
+
const provider = byId(providerId);
|
|
663
|
+
if (!provider) return fail({
|
|
664
|
+
title: `Unknown provider ${providerId}`
|
|
665
|
+
});
|
|
666
|
+
const entered = {};
|
|
667
|
+
for (const field of form.fields){
|
|
668
|
+
if (field.group && field.group !== authType) continue;
|
|
669
|
+
const value = (values[field.key] ?? '').trim();
|
|
670
|
+
if (value) entered[field.key] = value;
|
|
671
|
+
else if (existing && !field.secret) entered[field.key] = '';
|
|
672
|
+
}
|
|
673
|
+
const s = await session(provider, folderId, existing?.id ?? null);
|
|
674
|
+
if (!s.ok) return s;
|
|
675
|
+
const sid = s.value.id;
|
|
676
|
+
const sf = await sessionForm(sid, folderId);
|
|
677
|
+
if (!sf.ok) return fail(failure(sf, 'Could not read the connector form'));
|
|
678
|
+
const sfd = sf.data;
|
|
679
|
+
const configuration = {};
|
|
680
|
+
for (const c of sfd?.elementMetadata?.configuration ?? [])if (void 0 !== c.defaultValue && null !== c.defaultValue && '' !== c.defaultValue) configuration[c.key] = c.defaultValue;
|
|
681
|
+
Object.assign(configuration, sfd?.configs, entered, form.authTypes.length && authType ? {
|
|
682
|
+
'authentication.type': authType
|
|
683
|
+
} : {}, provider.derive?.(entered));
|
|
684
|
+
const nameInIs = existing?.name ?? new Date().toISOString();
|
|
685
|
+
const body = {
|
|
686
|
+
element: {
|
|
687
|
+
key: provider.connector
|
|
688
|
+
},
|
|
689
|
+
sessionID: sid,
|
|
690
|
+
configuration,
|
|
691
|
+
name: nameInIs
|
|
692
|
+
};
|
|
693
|
+
let method = 'POST';
|
|
694
|
+
if (existing) {
|
|
695
|
+
const instanceId = sfd?.elementInstance?.id;
|
|
696
|
+
if (!instanceId) return fail({
|
|
697
|
+
title: 'Integration Service did not return the connection to edit'
|
|
698
|
+
});
|
|
699
|
+
body.instanceID = instanceId;
|
|
700
|
+
method = 'PUT';
|
|
701
|
+
}
|
|
702
|
+
const auth = await call(method, tenantUrl('elements_/v1/elements/normalized-instances/authenticate'), {
|
|
703
|
+
folderKey: folderId,
|
|
704
|
+
body
|
|
705
|
+
});
|
|
706
|
+
if (!auth.ok) return fail(failure(auth, `${provider.name} refused the connection`));
|
|
707
|
+
let id = auth.data?.elementInstance?.connectionId;
|
|
708
|
+
let provisioned = false;
|
|
709
|
+
for(let i = 0; i < SESSION_POLLS; i += 1){
|
|
710
|
+
const st = await call('GET', tenantUrl(`connections_/api/v1/Sessions/${sid}`), {
|
|
711
|
+
folderKey: folderId
|
|
712
|
+
});
|
|
713
|
+
const d = st.data;
|
|
714
|
+
if (d?.status === 'success') {
|
|
715
|
+
id = d.connectionId || id;
|
|
716
|
+
provisioned = true;
|
|
717
|
+
break;
|
|
718
|
+
}
|
|
719
|
+
if (d?.status && 'pending' !== d.status) {
|
|
720
|
+
openSession = null;
|
|
721
|
+
return fail(failure({
|
|
722
|
+
...st,
|
|
723
|
+
data: d.errorResponse ?? d
|
|
724
|
+
}, `Connection ${d.status}`));
|
|
725
|
+
}
|
|
726
|
+
await sleep(SESSION_POLL_MS);
|
|
727
|
+
}
|
|
728
|
+
openSession = null;
|
|
729
|
+
if (!provisioned) return fail({
|
|
730
|
+
title: 'Integration Service did not finish setting up the connection'
|
|
731
|
+
});
|
|
732
|
+
if (!id) return fail({
|
|
733
|
+
title: 'Integration Service did not return the connection'
|
|
734
|
+
});
|
|
735
|
+
let savedName = nameInIs;
|
|
736
|
+
if (name !== nameInIs) {
|
|
737
|
+
const renamed = await call('PATCH', tenantUrl(`connections_/api/v1/Connections/${id}/rename`), {
|
|
738
|
+
folderKey: folderId,
|
|
739
|
+
body: {
|
|
740
|
+
newName: name
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
if (renamed.ok) savedName = name;
|
|
744
|
+
}
|
|
745
|
+
if (!existing) createdAt.set(id, Date.now());
|
|
746
|
+
return ok({
|
|
747
|
+
id,
|
|
748
|
+
providerId,
|
|
749
|
+
name: savedName,
|
|
750
|
+
folderId
|
|
751
|
+
});
|
|
752
|
+
};
|
|
753
|
+
const listModels = async (providerId, connection)=>{
|
|
754
|
+
const provider = byId(providerId);
|
|
755
|
+
if (!provider) return fail({
|
|
756
|
+
title: `Unknown provider ${providerId}`
|
|
757
|
+
});
|
|
758
|
+
const { result: r } = await whileNewConnectionInvisible(connection.id, ()=>call('POST', buildGatewayUrl(ctx, 'api/byom/available-models'), {
|
|
759
|
+
body: {
|
|
760
|
+
product,
|
|
761
|
+
connectorType: provider.connectorType,
|
|
762
|
+
configurationType: 'SelfServe',
|
|
763
|
+
connectionId: connection.id,
|
|
764
|
+
organizationId: ctx.organizationId,
|
|
765
|
+
tenantId: ctx.tenantId,
|
|
766
|
+
desiredModel: '',
|
|
767
|
+
customerModel: ''
|
|
768
|
+
}
|
|
769
|
+
}));
|
|
770
|
+
if (!r.ok) return fail(failure(r, `Could not list your ${provider.name} models`));
|
|
771
|
+
const ids = [
|
|
772
|
+
...new Set(Array.isArray(r.data) ? r.data : [])
|
|
773
|
+
];
|
|
774
|
+
const rows = ids.map((id)=>{
|
|
775
|
+
const notChat = NOT_CHAT.find(([re])=>re.test(id));
|
|
776
|
+
return notChat ? {
|
|
777
|
+
id,
|
|
778
|
+
short: notChat[1],
|
|
779
|
+
reason: `${notChat[1]}: not a chat model.`
|
|
780
|
+
} : {
|
|
781
|
+
id
|
|
782
|
+
};
|
|
783
|
+
});
|
|
784
|
+
const newestFirst = (a, b)=>b.id.localeCompare(a.id, void 0, {
|
|
785
|
+
numeric: true
|
|
786
|
+
});
|
|
787
|
+
return ok({
|
|
788
|
+
compatible: rows.filter((m)=>!m.reason).sort(newestFirst),
|
|
789
|
+
incompatible: rows.filter((m)=>m.reason).sort(newestFirst)
|
|
790
|
+
});
|
|
791
|
+
};
|
|
792
|
+
async function updateConfiguration(editing, entry, folderId) {
|
|
793
|
+
const notSaved = 'The model passed its test but could not be saved';
|
|
794
|
+
const current = await call('GET', configurationUrl(editing.configurationId));
|
|
795
|
+
if (!current.ok) return fail(failure(current, notSaved));
|
|
796
|
+
const configuration = current.data;
|
|
797
|
+
const edited = entryNamed(configuration, editing.name);
|
|
798
|
+
if (!edited) return fail({
|
|
799
|
+
title: `${editing.name} is no longer in its configuration`,
|
|
800
|
+
detail: JSON.stringify(configuration, null, 2)
|
|
801
|
+
});
|
|
802
|
+
const keepsName = edited.desiredModel === entry.desiredModel;
|
|
803
|
+
const updated = {
|
|
804
|
+
...edited,
|
|
805
|
+
...entry,
|
|
806
|
+
defaultModel: keepsName ? edited.defaultModel ?? entry.defaultModel : entry.defaultModel,
|
|
807
|
+
customFieldMappings: entry.customFieldMappings ?? null
|
|
808
|
+
};
|
|
809
|
+
const llmConfigurations = configuration.llmConfigurations.map((other)=>other === edited ? updated : other);
|
|
810
|
+
const onlyModel = 1 === configuration.llmConfigurations.length;
|
|
811
|
+
const savedFolderId = onlyModel ? folderId : configuration.folderId;
|
|
812
|
+
const saved = await call('PUT', configurationUrl(editing.configurationId), {
|
|
813
|
+
body: {
|
|
814
|
+
...configuration,
|
|
815
|
+
folderId: savedFolderId,
|
|
816
|
+
llmConfigurations
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
return saved.ok ? ok(savedFolderId) : fail(failure(saved, notSaved));
|
|
820
|
+
}
|
|
821
|
+
const testAndSave = async ({ providerId, connection, modelId, name, apiType, editing })=>{
|
|
822
|
+
const provider = byId(providerId);
|
|
823
|
+
if (!provider) return fail({
|
|
824
|
+
title: `Unknown provider ${providerId}`
|
|
825
|
+
});
|
|
826
|
+
if (!ctx.organizationId || !ctx.tenantId) return fail({
|
|
827
|
+
title: 'The picker needs organizationId and tenantId to add a model.'
|
|
828
|
+
});
|
|
829
|
+
const llmConfiguration = (customFieldMappings)=>{
|
|
830
|
+
const entry = {
|
|
831
|
+
desiredModel: name,
|
|
832
|
+
defaultModel: name,
|
|
833
|
+
customerModel: modelId,
|
|
834
|
+
connectorType: provider.connectorType,
|
|
835
|
+
connectionId: connection.id,
|
|
836
|
+
apiFlavor: apiType,
|
|
837
|
+
configurationType: 'SelfServe',
|
|
838
|
+
organizationId: ctx.organizationId,
|
|
839
|
+
tenantId: ctx.tenantId
|
|
840
|
+
};
|
|
841
|
+
if (customFieldMappings) entry.customFieldMappings = customFieldMappings;
|
|
842
|
+
return entry;
|
|
843
|
+
};
|
|
844
|
+
const newConfiguration = (customFieldMappings)=>({
|
|
845
|
+
enabled: true,
|
|
846
|
+
name: `${operationGroupName}-${Date.now()}`,
|
|
847
|
+
operationGroupName,
|
|
848
|
+
product,
|
|
849
|
+
folderId: connection.folderId,
|
|
850
|
+
organizationId: ctx.organizationId,
|
|
851
|
+
tenantId: ctx.tenantId,
|
|
852
|
+
llmConfigurations: [
|
|
853
|
+
llmConfiguration(customFieldMappings)
|
|
854
|
+
]
|
|
855
|
+
});
|
|
856
|
+
const headers = {
|
|
857
|
+
'X-UiPath-LLMGateway-AllowFull4xxResponse': 'true'
|
|
858
|
+
};
|
|
859
|
+
const feature = rules?.feature;
|
|
860
|
+
if (feature) {
|
|
861
|
+
const featureModelNamed = feature.models?.some((m)=>m.model === name) ?? false;
|
|
862
|
+
headers['X-UiPath-LlmGateway-ByoConfigMode'] = feature.modelsConfigurationOption !== ADD_OWN_MODELS || featureModelNamed ? 'replace' : 'add';
|
|
863
|
+
}
|
|
864
|
+
const { result: validation, startedAt } = await whileNewConnectionInvisible(connection.id, ()=>call('POST', buildGatewayUrl(ctx, 'api/byo/product/llm-configurations/validate'), {
|
|
865
|
+
body: newConfiguration(),
|
|
866
|
+
headers
|
|
867
|
+
}));
|
|
868
|
+
const latencyMs = Date.now() - startedAt;
|
|
869
|
+
if (!validation.ok) return fail(failure(validation, 'The gateway refused the test'));
|
|
870
|
+
const res = Object.values(validation.data ?? {})[0] ?? {};
|
|
871
|
+
if (!res.isAvailable || !res.isCompatible) {
|
|
872
|
+
const reason = res.unavailabilityReason || res.incompatibilityReason || (res.isAvailable ? 'Not compatible' : 'Not reachable');
|
|
873
|
+
const detail = res.vendorRawResponse ? prettyJson(res.vendorRawResponse) : JSON.stringify(res, null, 2);
|
|
874
|
+
return fail({
|
|
875
|
+
title: `The test call failed: ${reason}`,
|
|
876
|
+
detail
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
let savedFolderId = connection.folderId;
|
|
880
|
+
if (editing) {
|
|
881
|
+
const updated = await updateConfiguration(editing, llmConfiguration(res.customFieldMappings), connection.folderId);
|
|
882
|
+
if (!updated.ok) return updated;
|
|
883
|
+
savedFolderId = updated.value;
|
|
884
|
+
} else {
|
|
885
|
+
const saved = await call('POST', buildGatewayUrl(ctx, 'api/byo/product/llm-configurations'), {
|
|
886
|
+
body: newConfiguration(res.customFieldMappings)
|
|
887
|
+
});
|
|
888
|
+
if (!saved.ok) return fail(failure(saved, 'The model passed its test but could not be saved'));
|
|
889
|
+
}
|
|
890
|
+
return ok({
|
|
891
|
+
name,
|
|
892
|
+
modelId,
|
|
893
|
+
connectionId: connection.id,
|
|
894
|
+
folderId: savedFolderId,
|
|
895
|
+
latencyMs
|
|
896
|
+
});
|
|
897
|
+
};
|
|
898
|
+
return {
|
|
899
|
+
loadContext,
|
|
900
|
+
loadModel,
|
|
901
|
+
loadForm,
|
|
902
|
+
loadConnectionValues,
|
|
903
|
+
connect,
|
|
904
|
+
listModels,
|
|
905
|
+
apiTypes,
|
|
906
|
+
testAndSave
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
export { COMMUNITY_BYO_PROVIDERS, createCommunityByoApi };
|