@salesforce/lds-adapters-sfap-einstein-ai-gateway 0.1.0-dev1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE.txt +82 -0
  2. package/README.md +18 -0
  3. package/dist/es/es2018/sfap-einstein-ai-gateway.js +1792 -0
  4. package/dist/es/es2018/types/src/generated/adapters/adapter-utils.d.ts +62 -0
  5. package/dist/es/es2018/types/src/generated/adapters/getEmbeddings.d.ts +37 -0
  6. package/dist/es/es2018/types/src/generated/adapters/getGenerations.d.ts +32 -0
  7. package/dist/es/es2018/types/src/generated/adapters/registerFeedback.d.ts +27 -0
  8. package/dist/es/es2018/types/src/generated/artifacts/main.d.ts +3 -0
  9. package/dist/es/es2018/types/src/generated/artifacts/sfdc.d.ts +5 -0
  10. package/dist/es/es2018/types/src/generated/resources/postAiGptV1Embeddings.d.ts +27 -0
  11. package/dist/es/es2018/types/src/generated/resources/postAiGptV1Feedback.d.ts +26 -0
  12. package/dist/es/es2018/types/src/generated/resources/postAiGptV1Generations.d.ts +31 -0
  13. package/dist/es/es2018/types/src/generated/types/ChatMessage.d.ts +46 -0
  14. package/dist/es/es2018/types/src/generated/types/ContentQualityRepresentation.d.ts +28 -0
  15. package/dist/es/es2018/types/src/generated/types/ConversationalMemorySettings.d.ts +31 -0
  16. package/dist/es/es2018/types/src/generated/types/EmbeddingErrorRepresentation.d.ts +53 -0
  17. package/dist/es/es2018/types/src/generated/types/EmbeddingRequest.d.ts +44 -0
  18. package/dist/es/es2018/types/src/generated/types/EmbeddingResponse.d.ts +37 -0
  19. package/dist/es/es2018/types/src/generated/types/Embeddings.d.ts +31 -0
  20. package/dist/es/es2018/types/src/generated/types/Error.d.ts +28 -0
  21. package/dist/es/es2018/types/src/generated/types/FeedbackErrorRepresentation.d.ts +28 -0
  22. package/dist/es/es2018/types/src/generated/types/FeedbackRequest.d.ts +56 -0
  23. package/dist/es/es2018/types/src/generated/types/FeedbackResponse202Representation.d.ts +28 -0
  24. package/dist/es/es2018/types/src/generated/types/FeedbackResponseRepresentation.d.ts +38 -0
  25. package/dist/es/es2018/types/src/generated/types/GenerationDetails.d.ts +32 -0
  26. package/dist/es/es2018/types/src/generated/types/GenerationRequest.d.ts +66 -0
  27. package/dist/es/es2018/types/src/generated/types/GenerationResponse.d.ts +55 -0
  28. package/dist/es/es2018/types/src/generated/types/GenerationResponseGenerations.d.ts +44 -0
  29. package/dist/es/es2018/types/src/generated/types/GenerationSettings.d.ts +50 -0
  30. package/dist/es/es2018/types/src/generated/types/GenerationsErrorRepresentation.d.ts +28 -0
  31. package/dist/es/es2018/types/src/generated/types/HyperLink.d.ts +28 -0
  32. package/dist/es/es2018/types/src/generated/types/LLMProviderDetails.d.ts +43 -0
  33. package/dist/es/es2018/types/src/generated/types/LLMProviderResponse.d.ts +31 -0
  34. package/dist/es/es2018/types/src/generated/types/Links.d.ts +32 -0
  35. package/dist/es/es2018/types/src/generated/types/Localization.d.ts +35 -0
  36. package/dist/es/es2018/types/src/generated/types/ModelResponse.d.ts +31 -0
  37. package/dist/es/es2018/types/src/generated/types/PluginGenerationRequest.d.ts +25 -0
  38. package/dist/es/es2018/types/src/generated/types/PluginGenerationResponse.d.ts +25 -0
  39. package/dist/es/es2018/types/src/generated/types/ProbableLocale.d.ts +30 -0
  40. package/dist/es/es2018/types/src/generated/types/SafetyCategoryScores.d.ts +41 -0
  41. package/dist/es/es2018/types/src/generated/types/SafetyScoreRepresentation.d.ts +31 -0
  42. package/dist/es/es2018/types/src/generated/types/type-utils.d.ts +32 -0
  43. package/dist/es/es2018/types/src/raml-artifacts/resources/postAiGptV1Embeddings/createResourceRequest.d.ts +20 -0
  44. package/dist/es/es2018/types/src/raml-artifacts/resources/postAiGptV1Feedback/createResourceRequest.d.ts +21 -0
  45. package/dist/es/es2018/types/src/raml-artifacts/resources/postAiGptV1Generations/createResourceRequest.d.ts +26 -0
  46. package/package.json +76 -0
  47. package/sfdc/index.d.ts +1 -0
  48. package/sfdc/index.js +1831 -0
  49. package/src/raml/api.raml +1003 -0
  50. package/src/raml/luvio.raml +38 -0
@@ -0,0 +1,1792 @@
1
+ /**
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ import { serializeStructuredKey, ingestShape, deepFreeze, StoreKeyMap, createResourceParams as createResourceParams$3, typeCheckConfig as typeCheckConfig$3, buildNetworkSnapshotCachePolicy as buildNetworkSnapshotCachePolicy$1 } from '@luvio/engine';
8
+
9
+ const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
10
+ const { keys: ObjectKeys$1, create: ObjectCreate$1 } = Object;
11
+ const { stringify: JSONStringify$1 } = JSON;
12
+ const { isArray: ArrayIsArray$1 } = Array;
13
+ /**
14
+ * Validates an adapter config is well-formed.
15
+ * @param config The config to validate.
16
+ * @param adapter The adapter validation configuration.
17
+ * @param oneOf The keys the config must contain at least one of.
18
+ * @throws A TypeError if config doesn't satisfy the adapter's config validation.
19
+ */
20
+ function validateConfig(config, adapter, oneOf) {
21
+ const { displayName } = adapter;
22
+ const { required, optional, unsupported } = adapter.parameters;
23
+ if (config === undefined ||
24
+ required.every(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
25
+ throw new TypeError(`adapter ${displayName} configuration must specify ${required.sort().join(', ')}`);
26
+ }
27
+ if (oneOf && oneOf.some(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
28
+ throw new TypeError(`adapter ${displayName} configuration must specify one of ${oneOf.sort().join(', ')}`);
29
+ }
30
+ if (unsupported !== undefined &&
31
+ unsupported.some(req => ObjectPrototypeHasOwnProperty.call(config, req))) {
32
+ throw new TypeError(`adapter ${displayName} does not yet support ${unsupported.sort().join(', ')}`);
33
+ }
34
+ const supported = required.concat(optional);
35
+ if (ObjectKeys$1(config).some(key => !supported.includes(key))) {
36
+ throw new TypeError(`adapter ${displayName} configuration supports only ${supported.sort().join(', ')}`);
37
+ }
38
+ }
39
+ function untrustedIsObject(untrusted) {
40
+ return typeof untrusted === 'object' && untrusted !== null && ArrayIsArray$1(untrusted) === false;
41
+ }
42
+ function areRequiredParametersPresent(config, configPropertyNames) {
43
+ return configPropertyNames.parameters.required.every(req => req in config);
44
+ }
45
+ const snapshotRefreshOptions = {
46
+ overrides: {
47
+ headers: {
48
+ 'Cache-Control': 'no-cache',
49
+ },
50
+ }
51
+ };
52
+ /**
53
+ * A deterministic JSON stringify implementation. Heavily adapted from https://github.com/epoberezkin/fast-json-stable-stringify.
54
+ * This is needed because insertion order for JSON.stringify(object) affects output:
55
+ * JSON.stringify({a: 1, b: 2})
56
+ * "{"a":1,"b":2}"
57
+ * JSON.stringify({b: 2, a: 1})
58
+ * "{"b":2,"a":1}"
59
+ * @param data Data to be JSON-stringified.
60
+ * @returns JSON.stringified value with consistent ordering of keys.
61
+ */
62
+ function stableJSONStringify(node) {
63
+ // This is for Date values.
64
+ if (node && node.toJSON && typeof node.toJSON === 'function') {
65
+ // eslint-disable-next-line no-param-reassign
66
+ node = node.toJSON();
67
+ }
68
+ if (node === undefined) {
69
+ return;
70
+ }
71
+ if (typeof node === 'number') {
72
+ return isFinite(node) ? '' + node : 'null';
73
+ }
74
+ if (typeof node !== 'object') {
75
+ return JSONStringify$1(node);
76
+ }
77
+ let i;
78
+ let out;
79
+ if (ArrayIsArray$1(node)) {
80
+ out = '[';
81
+ for (i = 0; i < node.length; i++) {
82
+ if (i) {
83
+ out += ',';
84
+ }
85
+ out += stableJSONStringify(node[i]) || 'null';
86
+ }
87
+ return out + ']';
88
+ }
89
+ if (node === null) {
90
+ return 'null';
91
+ }
92
+ const keys = ObjectKeys$1(node).sort();
93
+ out = '';
94
+ for (i = 0; i < keys.length; i++) {
95
+ const key = keys[i];
96
+ const value = stableJSONStringify(node[key]);
97
+ if (!value) {
98
+ continue;
99
+ }
100
+ if (out) {
101
+ out += ',';
102
+ }
103
+ out += JSONStringify$1(key) + ':' + value;
104
+ }
105
+ return '{' + out + '}';
106
+ }
107
+ function generateParamConfigMetadata(name, required, resourceType, typeCheckShape, isArrayShape = false, coerceFn) {
108
+ return {
109
+ name,
110
+ required,
111
+ resourceType,
112
+ typeCheckShape,
113
+ isArrayShape,
114
+ coerceFn,
115
+ };
116
+ }
117
+ function buildAdapterValidationConfig(displayName, paramsMeta) {
118
+ const required = paramsMeta.filter(p => p.required).map(p => p.name);
119
+ const optional = paramsMeta.filter(p => !p.required).map(p => p.name);
120
+ return {
121
+ displayName,
122
+ parameters: {
123
+ required,
124
+ optional,
125
+ }
126
+ };
127
+ }
128
+ const keyPrefix = 'einstein-ai-gateway';
129
+
130
+ const { keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
131
+ const { isArray: ArrayIsArray } = Array;
132
+ const { stringify: JSONStringify } = JSON;
133
+ function equalsArray(a, b, equalsItem) {
134
+ const aLength = a.length;
135
+ const bLength = b.length;
136
+ if (aLength !== bLength) {
137
+ return false;
138
+ }
139
+ for (let i = 0; i < aLength; i++) {
140
+ if (equalsItem(a[i], b[i]) === false) {
141
+ return false;
142
+ }
143
+ }
144
+ return true;
145
+ }
146
+ function equalsObject(a, b, equalsProp) {
147
+ const aKeys = ObjectKeys(a).sort();
148
+ const bKeys = ObjectKeys(b).sort();
149
+ const aKeysLength = aKeys.length;
150
+ const bKeysLength = bKeys.length;
151
+ if (aKeysLength !== bKeysLength) {
152
+ return false;
153
+ }
154
+ for (let i = 0; i < aKeys.length; i++) {
155
+ const key = aKeys[i];
156
+ if (key !== bKeys[i]) {
157
+ return false;
158
+ }
159
+ if (equalsProp(a[key], b[key]) === false) {
160
+ return false;
161
+ }
162
+ }
163
+ return true;
164
+ }
165
+ function createLink(ref) {
166
+ return {
167
+ __ref: serializeStructuredKey(ref),
168
+ };
169
+ }
170
+
171
+ const VERSION$7 = "1536a256eead5e0f6ed4af90b4a4e6f0";
172
+ function validate$9(obj, path = 'ContentQualityRepresentation') {
173
+ const v_error = (() => {
174
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
175
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
176
+ }
177
+ if (obj.is_toxicity_detected !== undefined) {
178
+ const obj_is_toxicity_detected = obj.is_toxicity_detected;
179
+ const path_is_toxicity_detected = path + '.is_toxicity_detected';
180
+ if (typeof obj_is_toxicity_detected !== 'boolean') {
181
+ return new TypeError('Expected "boolean" but received "' + typeof obj_is_toxicity_detected + '" (at "' + path_is_toxicity_detected + '")');
182
+ }
183
+ }
184
+ })();
185
+ return v_error === undefined ? null : v_error;
186
+ }
187
+ const select$a = function ContentQualityRepresentationSelect() {
188
+ return {
189
+ kind: 'Fragment',
190
+ version: VERSION$7,
191
+ private: [],
192
+ selections: [
193
+ {
194
+ name: 'is_toxicity_detected',
195
+ kind: 'Scalar',
196
+ required: false
197
+ }
198
+ ]
199
+ };
200
+ };
201
+ function equals$7(existing, incoming) {
202
+ const existing_is_toxicity_detected = existing.is_toxicity_detected;
203
+ const incoming_is_toxicity_detected = incoming.is_toxicity_detected;
204
+ // if at least one of these optionals is defined
205
+ if (existing_is_toxicity_detected !== undefined || incoming_is_toxicity_detected !== undefined) {
206
+ // if one of these is not defined we know the other is defined and therefore
207
+ // not equal
208
+ if (existing_is_toxicity_detected === undefined || incoming_is_toxicity_detected === undefined) {
209
+ return false;
210
+ }
211
+ if (!(existing_is_toxicity_detected === incoming_is_toxicity_detected)) {
212
+ return false;
213
+ }
214
+ }
215
+ return true;
216
+ }
217
+
218
+ const VERSION$6 = "13f57c52293c993afc8242f865b3f15b";
219
+ function validate$8(obj, path = 'SafetyCategoryScores') {
220
+ const v_error = (() => {
221
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
222
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
223
+ }
224
+ if (obj.biased !== undefined) {
225
+ const obj_biased = obj.biased;
226
+ const path_biased = path + '.biased';
227
+ if (typeof obj_biased !== 'number') {
228
+ return new TypeError('Expected "number" but received "' + typeof obj_biased + '" (at "' + path_biased + '")');
229
+ }
230
+ }
231
+ if (obj.hate !== undefined) {
232
+ const obj_hate = obj.hate;
233
+ const path_hate = path + '.hate';
234
+ if (typeof obj_hate !== 'number') {
235
+ return new TypeError('Expected "number" but received "' + typeof obj_hate + '" (at "' + path_hate + '")');
236
+ }
237
+ }
238
+ if (obj.identity !== undefined) {
239
+ const obj_identity = obj.identity;
240
+ const path_identity = path + '.identity';
241
+ if (typeof obj_identity !== 'number') {
242
+ return new TypeError('Expected "number" but received "' + typeof obj_identity + '" (at "' + path_identity + '")');
243
+ }
244
+ }
245
+ if (obj.physical !== undefined) {
246
+ const obj_physical = obj.physical;
247
+ const path_physical = path + '.physical';
248
+ if (typeof obj_physical !== 'number') {
249
+ return new TypeError('Expected "number" but received "' + typeof obj_physical + '" (at "' + path_physical + '")');
250
+ }
251
+ }
252
+ if (obj.profanity !== undefined) {
253
+ const obj_profanity = obj.profanity;
254
+ const path_profanity = path + '.profanity';
255
+ if (typeof obj_profanity !== 'number') {
256
+ return new TypeError('Expected "number" but received "' + typeof obj_profanity + '" (at "' + path_profanity + '")');
257
+ }
258
+ }
259
+ if (obj.sexual !== undefined) {
260
+ const obj_sexual = obj.sexual;
261
+ const path_sexual = path + '.sexual';
262
+ if (typeof obj_sexual !== 'number') {
263
+ return new TypeError('Expected "number" but received "' + typeof obj_sexual + '" (at "' + path_sexual + '")');
264
+ }
265
+ }
266
+ if (obj.toxicity !== undefined) {
267
+ const obj_toxicity = obj.toxicity;
268
+ const path_toxicity = path + '.toxicity';
269
+ if (typeof obj_toxicity !== 'number') {
270
+ return new TypeError('Expected "number" but received "' + typeof obj_toxicity + '" (at "' + path_toxicity + '")');
271
+ }
272
+ }
273
+ if (obj.violence !== undefined) {
274
+ const obj_violence = obj.violence;
275
+ const path_violence = path + '.violence';
276
+ if (typeof obj_violence !== 'number') {
277
+ return new TypeError('Expected "number" but received "' + typeof obj_violence + '" (at "' + path_violence + '")');
278
+ }
279
+ }
280
+ })();
281
+ return v_error === undefined ? null : v_error;
282
+ }
283
+ const select$9 = function SafetyCategoryScoresSelect() {
284
+ return {
285
+ kind: 'Fragment',
286
+ version: VERSION$6,
287
+ private: [],
288
+ selections: [
289
+ {
290
+ name: 'biased',
291
+ kind: 'Scalar',
292
+ required: false
293
+ },
294
+ {
295
+ name: 'hate',
296
+ kind: 'Scalar',
297
+ required: false
298
+ },
299
+ {
300
+ name: 'identity',
301
+ kind: 'Scalar',
302
+ required: false
303
+ },
304
+ {
305
+ name: 'physical',
306
+ kind: 'Scalar',
307
+ required: false
308
+ },
309
+ {
310
+ name: 'profanity',
311
+ kind: 'Scalar',
312
+ required: false
313
+ },
314
+ {
315
+ name: 'sexual',
316
+ kind: 'Scalar',
317
+ required: false
318
+ },
319
+ {
320
+ name: 'toxicity',
321
+ kind: 'Scalar',
322
+ required: false
323
+ },
324
+ {
325
+ name: 'violence',
326
+ kind: 'Scalar',
327
+ required: false
328
+ }
329
+ ]
330
+ };
331
+ };
332
+ function equals$6(existing, incoming) {
333
+ const existing_biased = existing.biased;
334
+ const incoming_biased = incoming.biased;
335
+ // if at least one of these optionals is defined
336
+ if (existing_biased !== undefined || incoming_biased !== undefined) {
337
+ // if one of these is not defined we know the other is defined and therefore
338
+ // not equal
339
+ if (existing_biased === undefined || incoming_biased === undefined) {
340
+ return false;
341
+ }
342
+ if (!(existing_biased === incoming_biased)) {
343
+ return false;
344
+ }
345
+ }
346
+ const existing_hate = existing.hate;
347
+ const incoming_hate = incoming.hate;
348
+ // if at least one of these optionals is defined
349
+ if (existing_hate !== undefined || incoming_hate !== undefined) {
350
+ // if one of these is not defined we know the other is defined and therefore
351
+ // not equal
352
+ if (existing_hate === undefined || incoming_hate === undefined) {
353
+ return false;
354
+ }
355
+ if (!(existing_hate === incoming_hate)) {
356
+ return false;
357
+ }
358
+ }
359
+ const existing_identity = existing.identity;
360
+ const incoming_identity = incoming.identity;
361
+ // if at least one of these optionals is defined
362
+ if (existing_identity !== undefined || incoming_identity !== undefined) {
363
+ // if one of these is not defined we know the other is defined and therefore
364
+ // not equal
365
+ if (existing_identity === undefined || incoming_identity === undefined) {
366
+ return false;
367
+ }
368
+ if (!(existing_identity === incoming_identity)) {
369
+ return false;
370
+ }
371
+ }
372
+ const existing_physical = existing.physical;
373
+ const incoming_physical = incoming.physical;
374
+ // if at least one of these optionals is defined
375
+ if (existing_physical !== undefined || incoming_physical !== undefined) {
376
+ // if one of these is not defined we know the other is defined and therefore
377
+ // not equal
378
+ if (existing_physical === undefined || incoming_physical === undefined) {
379
+ return false;
380
+ }
381
+ if (!(existing_physical === incoming_physical)) {
382
+ return false;
383
+ }
384
+ }
385
+ const existing_profanity = existing.profanity;
386
+ const incoming_profanity = incoming.profanity;
387
+ // if at least one of these optionals is defined
388
+ if (existing_profanity !== undefined || incoming_profanity !== undefined) {
389
+ // if one of these is not defined we know the other is defined and therefore
390
+ // not equal
391
+ if (existing_profanity === undefined || incoming_profanity === undefined) {
392
+ return false;
393
+ }
394
+ if (!(existing_profanity === incoming_profanity)) {
395
+ return false;
396
+ }
397
+ }
398
+ const existing_sexual = existing.sexual;
399
+ const incoming_sexual = incoming.sexual;
400
+ // if at least one of these optionals is defined
401
+ if (existing_sexual !== undefined || incoming_sexual !== undefined) {
402
+ // if one of these is not defined we know the other is defined and therefore
403
+ // not equal
404
+ if (existing_sexual === undefined || incoming_sexual === undefined) {
405
+ return false;
406
+ }
407
+ if (!(existing_sexual === incoming_sexual)) {
408
+ return false;
409
+ }
410
+ }
411
+ const existing_toxicity = existing.toxicity;
412
+ const incoming_toxicity = incoming.toxicity;
413
+ // if at least one of these optionals is defined
414
+ if (existing_toxicity !== undefined || incoming_toxicity !== undefined) {
415
+ // if one of these is not defined we know the other is defined and therefore
416
+ // not equal
417
+ if (existing_toxicity === undefined || incoming_toxicity === undefined) {
418
+ return false;
419
+ }
420
+ if (!(existing_toxicity === incoming_toxicity)) {
421
+ return false;
422
+ }
423
+ }
424
+ const existing_violence = existing.violence;
425
+ const incoming_violence = incoming.violence;
426
+ // if at least one of these optionals is defined
427
+ if (existing_violence !== undefined || incoming_violence !== undefined) {
428
+ // if one of these is not defined we know the other is defined and therefore
429
+ // not equal
430
+ if (existing_violence === undefined || incoming_violence === undefined) {
431
+ return false;
432
+ }
433
+ if (!(existing_violence === incoming_violence)) {
434
+ return false;
435
+ }
436
+ }
437
+ return true;
438
+ }
439
+
440
+ const VERSION$5 = "24a5fffc6e46c3c67de0b0430d230c56";
441
+ function validate$7(obj, path = 'SafetyScoreRepresentation') {
442
+ const v_error = (() => {
443
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
444
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
445
+ }
446
+ if (obj.category_scores !== undefined) {
447
+ const obj_category_scores = obj.category_scores;
448
+ const path_category_scores = path + '.category_scores';
449
+ let obj_category_scores_union0 = null;
450
+ const obj_category_scores_union0_error = (() => {
451
+ const referencepath_category_scoresValidationError = validate$8(obj_category_scores, path_category_scores);
452
+ if (referencepath_category_scoresValidationError !== null) {
453
+ let message = 'Object doesn\'t match SafetyCategoryScores (at "' + path_category_scores + '")\n';
454
+ message += referencepath_category_scoresValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
455
+ return new TypeError(message);
456
+ }
457
+ })();
458
+ if (obj_category_scores_union0_error != null) {
459
+ obj_category_scores_union0 = obj_category_scores_union0_error.message;
460
+ }
461
+ let obj_category_scores_union1 = null;
462
+ const obj_category_scores_union1_error = (() => {
463
+ if (obj_category_scores !== null) {
464
+ return new TypeError('Expected "null" but received "' + typeof obj_category_scores + '" (at "' + path_category_scores + '")');
465
+ }
466
+ })();
467
+ if (obj_category_scores_union1_error != null) {
468
+ obj_category_scores_union1 = obj_category_scores_union1_error.message;
469
+ }
470
+ if (obj_category_scores_union0 && obj_category_scores_union1) {
471
+ let message = 'Object doesn\'t match union (at "' + path_category_scores + '")';
472
+ message += '\n' + obj_category_scores_union0.split('\n').map((line) => '\t' + line).join('\n');
473
+ message += '\n' + obj_category_scores_union1.split('\n').map((line) => '\t' + line).join('\n');
474
+ return new TypeError(message);
475
+ }
476
+ }
477
+ if (obj.safety_score !== undefined) {
478
+ const obj_safety_score = obj.safety_score;
479
+ const path_safety_score = path + '.safety_score';
480
+ if (typeof obj_safety_score !== 'number') {
481
+ return new TypeError('Expected "number" but received "' + typeof obj_safety_score + '" (at "' + path_safety_score + '")');
482
+ }
483
+ }
484
+ })();
485
+ return v_error === undefined ? null : v_error;
486
+ }
487
+ const select$8 = function SafetyScoreRepresentationSelect() {
488
+ const { selections: SafetyCategoryScores__selections, opaque: SafetyCategoryScores__opaque, } = select$9();
489
+ return {
490
+ kind: 'Fragment',
491
+ version: VERSION$5,
492
+ private: [],
493
+ selections: [
494
+ {
495
+ name: 'category_scores',
496
+ kind: 'Object',
497
+ nullable: true,
498
+ selections: SafetyCategoryScores__selections,
499
+ required: false
500
+ },
501
+ {
502
+ name: 'safety_score',
503
+ kind: 'Scalar',
504
+ required: false
505
+ }
506
+ ]
507
+ };
508
+ };
509
+ function equals$5(existing, incoming) {
510
+ const existing_safety_score = existing.safety_score;
511
+ const incoming_safety_score = incoming.safety_score;
512
+ // if at least one of these optionals is defined
513
+ if (existing_safety_score !== undefined || incoming_safety_score !== undefined) {
514
+ // if one of these is not defined we know the other is defined and therefore
515
+ // not equal
516
+ if (existing_safety_score === undefined || incoming_safety_score === undefined) {
517
+ return false;
518
+ }
519
+ if (!(existing_safety_score === incoming_safety_score)) {
520
+ return false;
521
+ }
522
+ }
523
+ const existing_category_scores = existing.category_scores;
524
+ const incoming_category_scores = incoming.category_scores;
525
+ // if at least one of these optionals is defined
526
+ if (existing_category_scores !== undefined || incoming_category_scores !== undefined) {
527
+ // if one of these is not defined we know the other is defined and therefore
528
+ // not equal
529
+ if (existing_category_scores === undefined || incoming_category_scores === undefined) {
530
+ return false;
531
+ }
532
+ if (!(existing_category_scores === incoming_category_scores
533
+ || (existing_category_scores != null &&
534
+ incoming_category_scores != null &&
535
+ equals$6(existing_category_scores, incoming_category_scores)))) {
536
+ return false;
537
+ }
538
+ }
539
+ return true;
540
+ }
541
+
542
+ const VERSION$4 = "8777be1ae9f7cf216ac8618fd17a03c9";
543
+ function validate$6(obj, path = 'GenerationResponseGenerations') {
544
+ const v_error = (() => {
545
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
546
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
547
+ }
548
+ if (obj.generation_content_quality !== undefined) {
549
+ const obj_generation_content_quality = obj.generation_content_quality;
550
+ const path_generation_content_quality = path + '.generation_content_quality';
551
+ let obj_generation_content_quality_union0 = null;
552
+ const obj_generation_content_quality_union0_error = (() => {
553
+ const referencepath_generation_content_qualityValidationError = validate$9(obj_generation_content_quality, path_generation_content_quality);
554
+ if (referencepath_generation_content_qualityValidationError !== null) {
555
+ let message = 'Object doesn\'t match ContentQualityRepresentation (at "' + path_generation_content_quality + '")\n';
556
+ message += referencepath_generation_content_qualityValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
557
+ return new TypeError(message);
558
+ }
559
+ })();
560
+ if (obj_generation_content_quality_union0_error != null) {
561
+ obj_generation_content_quality_union0 = obj_generation_content_quality_union0_error.message;
562
+ }
563
+ let obj_generation_content_quality_union1 = null;
564
+ const obj_generation_content_quality_union1_error = (() => {
565
+ if (obj_generation_content_quality !== null) {
566
+ return new TypeError('Expected "null" but received "' + typeof obj_generation_content_quality + '" (at "' + path_generation_content_quality + '")');
567
+ }
568
+ })();
569
+ if (obj_generation_content_quality_union1_error != null) {
570
+ obj_generation_content_quality_union1 = obj_generation_content_quality_union1_error.message;
571
+ }
572
+ if (obj_generation_content_quality_union0 && obj_generation_content_quality_union1) {
573
+ let message = 'Object doesn\'t match union (at "' + path_generation_content_quality + '")';
574
+ message += '\n' + obj_generation_content_quality_union0.split('\n').map((line) => '\t' + line).join('\n');
575
+ message += '\n' + obj_generation_content_quality_union1.split('\n').map((line) => '\t' + line).join('\n');
576
+ return new TypeError(message);
577
+ }
578
+ }
579
+ if (obj.generation_safety_score !== undefined) {
580
+ const obj_generation_safety_score = obj.generation_safety_score;
581
+ const path_generation_safety_score = path + '.generation_safety_score';
582
+ let obj_generation_safety_score_union0 = null;
583
+ const obj_generation_safety_score_union0_error = (() => {
584
+ const referencepath_generation_safety_scoreValidationError = validate$7(obj_generation_safety_score, path_generation_safety_score);
585
+ if (referencepath_generation_safety_scoreValidationError !== null) {
586
+ let message = 'Object doesn\'t match SafetyScoreRepresentation (at "' + path_generation_safety_score + '")\n';
587
+ message += referencepath_generation_safety_scoreValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
588
+ return new TypeError(message);
589
+ }
590
+ })();
591
+ if (obj_generation_safety_score_union0_error != null) {
592
+ obj_generation_safety_score_union0 = obj_generation_safety_score_union0_error.message;
593
+ }
594
+ let obj_generation_safety_score_union1 = null;
595
+ const obj_generation_safety_score_union1_error = (() => {
596
+ if (obj_generation_safety_score !== null) {
597
+ return new TypeError('Expected "null" but received "' + typeof obj_generation_safety_score + '" (at "' + path_generation_safety_score + '")');
598
+ }
599
+ })();
600
+ if (obj_generation_safety_score_union1_error != null) {
601
+ obj_generation_safety_score_union1 = obj_generation_safety_score_union1_error.message;
602
+ }
603
+ if (obj_generation_safety_score_union0 && obj_generation_safety_score_union1) {
604
+ let message = 'Object doesn\'t match union (at "' + path_generation_safety_score + '")';
605
+ message += '\n' + obj_generation_safety_score_union0.split('\n').map((line) => '\t' + line).join('\n');
606
+ message += '\n' + obj_generation_safety_score_union1.split('\n').map((line) => '\t' + line).join('\n');
607
+ return new TypeError(message);
608
+ }
609
+ }
610
+ if (obj.id !== undefined) {
611
+ const obj_id = obj.id;
612
+ const path_id = path + '.id';
613
+ if (typeof obj_id !== 'string') {
614
+ return new TypeError('Expected "string" but received "' + typeof obj_id + '" (at "' + path_id + '")');
615
+ }
616
+ }
617
+ if (obj.parameters !== undefined) {
618
+ const obj_parameters = obj.parameters;
619
+ const path_parameters = path + '.parameters';
620
+ if (typeof obj_parameters !== 'object' || ArrayIsArray(obj_parameters) || obj_parameters === null) {
621
+ return new TypeError('Expected "object" but received "' + typeof obj_parameters + '" (at "' + path_parameters + '")');
622
+ }
623
+ const obj_parameters_keys = ObjectKeys(obj_parameters);
624
+ for (let i = 0; i < obj_parameters_keys.length; i++) {
625
+ const key = obj_parameters_keys[i];
626
+ const obj_parameters_prop = obj_parameters[key];
627
+ const path_parameters_prop = path_parameters + '["' + key + '"]';
628
+ if (obj_parameters_prop === undefined) {
629
+ return new TypeError('Expected "defined" but received "' + typeof obj_parameters_prop + '" (at "' + path_parameters_prop + '")');
630
+ }
631
+ }
632
+ }
633
+ const obj_text = obj.text;
634
+ const path_text = path + '.text';
635
+ if (typeof obj_text !== 'string') {
636
+ return new TypeError('Expected "string" but received "' + typeof obj_text + '" (at "' + path_text + '")');
637
+ }
638
+ })();
639
+ return v_error === undefined ? null : v_error;
640
+ }
641
+ const select$7 = function GenerationResponseGenerationsSelect() {
642
+ const { selections: ContentQualityRepresentation__selections, opaque: ContentQualityRepresentation__opaque, } = select$a();
643
+ const { selections: SafetyScoreRepresentation__selections, opaque: SafetyScoreRepresentation__opaque, } = select$8();
644
+ return {
645
+ kind: 'Fragment',
646
+ version: VERSION$4,
647
+ private: [],
648
+ selections: [
649
+ {
650
+ name: 'generation_content_quality',
651
+ kind: 'Object',
652
+ nullable: true,
653
+ selections: ContentQualityRepresentation__selections,
654
+ required: false
655
+ },
656
+ {
657
+ name: 'generation_safety_score',
658
+ kind: 'Object',
659
+ nullable: true,
660
+ selections: SafetyScoreRepresentation__selections,
661
+ required: false
662
+ },
663
+ {
664
+ name: 'id',
665
+ kind: 'Scalar',
666
+ required: false
667
+ },
668
+ {
669
+ name: 'parameters',
670
+ kind: 'Object',
671
+ // any
672
+ },
673
+ {
674
+ name: 'text',
675
+ kind: 'Scalar'
676
+ }
677
+ ]
678
+ };
679
+ };
680
+ function equals$4(existing, incoming) {
681
+ const existing_id = existing.id;
682
+ const incoming_id = incoming.id;
683
+ // if at least one of these optionals is defined
684
+ if (existing_id !== undefined || incoming_id !== undefined) {
685
+ // if one of these is not defined we know the other is defined and therefore
686
+ // not equal
687
+ if (existing_id === undefined || incoming_id === undefined) {
688
+ return false;
689
+ }
690
+ if (!(existing_id === incoming_id)) {
691
+ return false;
692
+ }
693
+ }
694
+ const existing_text = existing.text;
695
+ const incoming_text = incoming.text;
696
+ if (!(existing_text === incoming_text)) {
697
+ return false;
698
+ }
699
+ const existing_generation_content_quality = existing.generation_content_quality;
700
+ const incoming_generation_content_quality = incoming.generation_content_quality;
701
+ // if at least one of these optionals is defined
702
+ if (existing_generation_content_quality !== undefined || incoming_generation_content_quality !== undefined) {
703
+ // if one of these is not defined we know the other is defined and therefore
704
+ // not equal
705
+ if (existing_generation_content_quality === undefined || incoming_generation_content_quality === undefined) {
706
+ return false;
707
+ }
708
+ if (!(existing_generation_content_quality === incoming_generation_content_quality
709
+ || (existing_generation_content_quality != null &&
710
+ incoming_generation_content_quality != null &&
711
+ equals$7(existing_generation_content_quality, incoming_generation_content_quality)))) {
712
+ return false;
713
+ }
714
+ }
715
+ const existing_generation_safety_score = existing.generation_safety_score;
716
+ const incoming_generation_safety_score = incoming.generation_safety_score;
717
+ // if at least one of these optionals is defined
718
+ if (existing_generation_safety_score !== undefined || incoming_generation_safety_score !== undefined) {
719
+ // if one of these is not defined we know the other is defined and therefore
720
+ // not equal
721
+ if (existing_generation_safety_score === undefined || incoming_generation_safety_score === undefined) {
722
+ return false;
723
+ }
724
+ if (!(existing_generation_safety_score === incoming_generation_safety_score
725
+ || (existing_generation_safety_score != null &&
726
+ incoming_generation_safety_score != null &&
727
+ equals$5(existing_generation_safety_score, incoming_generation_safety_score)))) {
728
+ return false;
729
+ }
730
+ }
731
+ const existing_parameters = existing.parameters;
732
+ const incoming_parameters = incoming.parameters;
733
+ // if at least one of these optionals is defined
734
+ if (existing_parameters !== undefined || incoming_parameters !== undefined) {
735
+ // if one of these is not defined we know the other is defined and therefore
736
+ // not equal
737
+ if (existing_parameters === undefined || incoming_parameters === undefined) {
738
+ return false;
739
+ }
740
+ const equals_parameters_props = equalsObject(existing_parameters, incoming_parameters, (existing_parameters_prop, incoming_parameters_prop) => {
741
+ if (JSONStringify(incoming_parameters_prop) !== JSONStringify(existing_parameters_prop)) {
742
+ return false;
743
+ }
744
+ });
745
+ if (equals_parameters_props === false) {
746
+ return false;
747
+ }
748
+ }
749
+ return true;
750
+ }
751
+
752
+ const TTL$2 = 100;
753
+ const VERSION$3 = "4bce29cece0fd6272204a8fbdc02c35b";
754
+ function validate$5(obj, path = 'GenerationResponse') {
755
+ const v_error = (() => {
756
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
757
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
758
+ }
759
+ const obj_generations = obj.generations;
760
+ const path_generations = path + '.generations';
761
+ if (!ArrayIsArray(obj_generations)) {
762
+ return new TypeError('Expected "array" but received "' + typeof obj_generations + '" (at "' + path_generations + '")');
763
+ }
764
+ for (let i = 0; i < obj_generations.length; i++) {
765
+ const obj_generations_item = obj_generations[i];
766
+ const path_generations_item = path_generations + '[' + i + ']';
767
+ const referencepath_generations_itemValidationError = validate$6(obj_generations_item, path_generations_item);
768
+ if (referencepath_generations_itemValidationError !== null) {
769
+ let message = 'Object doesn\'t match GenerationResponseGenerations (at "' + path_generations_item + '")\n';
770
+ message += referencepath_generations_itemValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
771
+ return new TypeError(message);
772
+ }
773
+ }
774
+ const obj_id = obj.id;
775
+ const path_id = path + '.id';
776
+ if (typeof obj_id !== 'string') {
777
+ return new TypeError('Expected "string" but received "' + typeof obj_id + '" (at "' + path_id + '")');
778
+ }
779
+ if (obj.input_safety_score !== undefined) {
780
+ const obj_input_safety_score = obj.input_safety_score;
781
+ const path_input_safety_score = path + '.input_safety_score';
782
+ let obj_input_safety_score_union0 = null;
783
+ const obj_input_safety_score_union0_error = (() => {
784
+ const referencepath_input_safety_scoreValidationError = validate$7(obj_input_safety_score, path_input_safety_score);
785
+ if (referencepath_input_safety_scoreValidationError !== null) {
786
+ let message = 'Object doesn\'t match SafetyScoreRepresentation (at "' + path_input_safety_score + '")\n';
787
+ message += referencepath_input_safety_scoreValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
788
+ return new TypeError(message);
789
+ }
790
+ })();
791
+ if (obj_input_safety_score_union0_error != null) {
792
+ obj_input_safety_score_union0 = obj_input_safety_score_union0_error.message;
793
+ }
794
+ let obj_input_safety_score_union1 = null;
795
+ const obj_input_safety_score_union1_error = (() => {
796
+ if (obj_input_safety_score !== null) {
797
+ return new TypeError('Expected "null" but received "' + typeof obj_input_safety_score + '" (at "' + path_input_safety_score + '")');
798
+ }
799
+ })();
800
+ if (obj_input_safety_score_union1_error != null) {
801
+ obj_input_safety_score_union1 = obj_input_safety_score_union1_error.message;
802
+ }
803
+ if (obj_input_safety_score_union0 && obj_input_safety_score_union1) {
804
+ let message = 'Object doesn\'t match union (at "' + path_input_safety_score + '")';
805
+ message += '\n' + obj_input_safety_score_union0.split('\n').map((line) => '\t' + line).join('\n');
806
+ message += '\n' + obj_input_safety_score_union1.split('\n').map((line) => '\t' + line).join('\n');
807
+ return new TypeError(message);
808
+ }
809
+ }
810
+ if (obj.parameters !== undefined) {
811
+ const obj_parameters = obj.parameters;
812
+ const path_parameters = path + '.parameters';
813
+ if (typeof obj_parameters !== 'object' || ArrayIsArray(obj_parameters) || obj_parameters === null) {
814
+ return new TypeError('Expected "object" but received "' + typeof obj_parameters + '" (at "' + path_parameters + '")');
815
+ }
816
+ const obj_parameters_keys = ObjectKeys(obj_parameters);
817
+ for (let i = 0; i < obj_parameters_keys.length; i++) {
818
+ const key = obj_parameters_keys[i];
819
+ const obj_parameters_prop = obj_parameters[key];
820
+ const path_parameters_prop = path_parameters + '["' + key + '"]';
821
+ if (obj_parameters_prop === undefined) {
822
+ return new TypeError('Expected "defined" but received "' + typeof obj_parameters_prop + '" (at "' + path_parameters_prop + '")');
823
+ }
824
+ }
825
+ }
826
+ if (obj.prompt !== undefined) {
827
+ const obj_prompt = obj.prompt;
828
+ const path_prompt = path + '.prompt';
829
+ let obj_prompt_union0 = null;
830
+ const obj_prompt_union0_error = (() => {
831
+ if (typeof obj_prompt !== 'string') {
832
+ return new TypeError('Expected "string" but received "' + typeof obj_prompt + '" (at "' + path_prompt + '")');
833
+ }
834
+ })();
835
+ if (obj_prompt_union0_error != null) {
836
+ obj_prompt_union0 = obj_prompt_union0_error.message;
837
+ }
838
+ let obj_prompt_union1 = null;
839
+ const obj_prompt_union1_error = (() => {
840
+ if (obj_prompt !== null) {
841
+ return new TypeError('Expected "null" but received "' + typeof obj_prompt + '" (at "' + path_prompt + '")');
842
+ }
843
+ })();
844
+ if (obj_prompt_union1_error != null) {
845
+ obj_prompt_union1 = obj_prompt_union1_error.message;
846
+ }
847
+ if (obj_prompt_union0 && obj_prompt_union1) {
848
+ let message = 'Object doesn\'t match union (at "' + path_prompt + '")';
849
+ message += '\n' + obj_prompt_union0.split('\n').map((line) => '\t' + line).join('\n');
850
+ message += '\n' + obj_prompt_union1.split('\n').map((line) => '\t' + line).join('\n');
851
+ return new TypeError(message);
852
+ }
853
+ }
854
+ })();
855
+ return v_error === undefined ? null : v_error;
856
+ }
857
+ const RepresentationType$2 = 'GenerationResponse';
858
+ function keyBuilder$3(luvio, config) {
859
+ return keyPrefix + '::' + RepresentationType$2 + ':' + config.id;
860
+ }
861
+ function keyBuilderFromType$1(luvio, object) {
862
+ const keyParams = {
863
+ id: object.id
864
+ };
865
+ return keyBuilder$3(luvio, keyParams);
866
+ }
867
+ function normalize$2(input, existing, path, luvio, store, timestamp) {
868
+ return input;
869
+ }
870
+ const select$6 = function GenerationResponseSelect() {
871
+ const { selections: GenerationResponseGenerations__selections, opaque: GenerationResponseGenerations__opaque, } = select$7();
872
+ const { selections: SafetyScoreRepresentation__selections, opaque: SafetyScoreRepresentation__opaque, } = select$8();
873
+ return {
874
+ kind: 'Fragment',
875
+ version: VERSION$3,
876
+ private: [],
877
+ selections: [
878
+ {
879
+ name: 'generations',
880
+ kind: 'Object',
881
+ plural: true,
882
+ selections: GenerationResponseGenerations__selections
883
+ },
884
+ {
885
+ name: 'id',
886
+ kind: 'Scalar'
887
+ },
888
+ {
889
+ name: 'input_safety_score',
890
+ kind: 'Object',
891
+ nullable: true,
892
+ selections: SafetyScoreRepresentation__selections,
893
+ required: false
894
+ },
895
+ {
896
+ name: 'parameters',
897
+ kind: 'Object',
898
+ // any
899
+ },
900
+ {
901
+ name: 'prompt',
902
+ kind: 'Scalar',
903
+ required: false
904
+ }
905
+ ]
906
+ };
907
+ };
908
+ function equals$3(existing, incoming) {
909
+ const existing_id = existing.id;
910
+ const incoming_id = incoming.id;
911
+ if (!(existing_id === incoming_id)) {
912
+ return false;
913
+ }
914
+ const existing_generations = existing.generations;
915
+ const incoming_generations = incoming.generations;
916
+ const equals_generations_items = equalsArray(existing_generations, incoming_generations, (existing_generations_item, incoming_generations_item) => {
917
+ if (!(equals$4(existing_generations_item, incoming_generations_item))) {
918
+ return false;
919
+ }
920
+ });
921
+ if (equals_generations_items === false) {
922
+ return false;
923
+ }
924
+ const existing_input_safety_score = existing.input_safety_score;
925
+ const incoming_input_safety_score = incoming.input_safety_score;
926
+ // if at least one of these optionals is defined
927
+ if (existing_input_safety_score !== undefined || incoming_input_safety_score !== undefined) {
928
+ // if one of these is not defined we know the other is defined and therefore
929
+ // not equal
930
+ if (existing_input_safety_score === undefined || incoming_input_safety_score === undefined) {
931
+ return false;
932
+ }
933
+ if (!(existing_input_safety_score === incoming_input_safety_score
934
+ || (existing_input_safety_score != null &&
935
+ incoming_input_safety_score != null &&
936
+ equals$5(existing_input_safety_score, incoming_input_safety_score)))) {
937
+ return false;
938
+ }
939
+ }
940
+ const existing_parameters = existing.parameters;
941
+ const incoming_parameters = incoming.parameters;
942
+ // if at least one of these optionals is defined
943
+ if (existing_parameters !== undefined || incoming_parameters !== undefined) {
944
+ // if one of these is not defined we know the other is defined and therefore
945
+ // not equal
946
+ if (existing_parameters === undefined || incoming_parameters === undefined) {
947
+ return false;
948
+ }
949
+ const equals_parameters_props = equalsObject(existing_parameters, incoming_parameters, (existing_parameters_prop, incoming_parameters_prop) => {
950
+ if (JSONStringify(incoming_parameters_prop) !== JSONStringify(existing_parameters_prop)) {
951
+ return false;
952
+ }
953
+ });
954
+ if (equals_parameters_props === false) {
955
+ return false;
956
+ }
957
+ }
958
+ const existing_prompt = existing.prompt;
959
+ const incoming_prompt = incoming.prompt;
960
+ // if at least one of these optionals is defined
961
+ if (existing_prompt !== undefined || incoming_prompt !== undefined) {
962
+ // if one of these is not defined we know the other is defined and therefore
963
+ // not equal
964
+ if (existing_prompt === undefined || incoming_prompt === undefined) {
965
+ return false;
966
+ }
967
+ if (!(existing_prompt === incoming_prompt)) {
968
+ return false;
969
+ }
970
+ }
971
+ return true;
972
+ }
973
+ const ingest$2 = function GenerationResponseIngest(input, path, luvio, store, timestamp) {
974
+ if (process.env.NODE_ENV !== 'production') {
975
+ const validateError = validate$5(input);
976
+ if (validateError !== null) {
977
+ throw validateError;
978
+ }
979
+ }
980
+ const key = keyBuilderFromType$1(luvio, input);
981
+ const ttlToUse = TTL$2;
982
+ ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize$2, "einstein-ai-gateway", VERSION$3, RepresentationType$2, equals$3);
983
+ return createLink(key);
984
+ };
985
+ function getTypeCacheKeys$2(rootKeySet, luvio, input, fullPathFactory) {
986
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
987
+ const rootKey = keyBuilderFromType$1(luvio, input);
988
+ rootKeySet.set(rootKey, {
989
+ namespace: keyPrefix,
990
+ representationName: RepresentationType$2,
991
+ mergeable: false
992
+ });
993
+ }
994
+
995
+ function select$5(luvio, params) {
996
+ return select$6();
997
+ }
998
+ function getResponseCacheKeys$2(storeKeyMap, luvio, resourceParams, response) {
999
+ getTypeCacheKeys$2(storeKeyMap, luvio, response);
1000
+ }
1001
+ function ingestSuccess$2(luvio, resourceParams, response) {
1002
+ const { body } = response;
1003
+ const key = keyBuilderFromType$1(luvio, body);
1004
+ luvio.storeIngest(key, ingest$2, body);
1005
+ const snapshot = luvio.storeLookup({
1006
+ recordId: key,
1007
+ node: select$5(),
1008
+ variables: {},
1009
+ });
1010
+ if (process.env.NODE_ENV !== 'production') {
1011
+ if (snapshot.state !== 'Fulfilled') {
1012
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
1013
+ }
1014
+ }
1015
+ deepFreeze(snapshot.data);
1016
+ return snapshot;
1017
+ }
1018
+
1019
+ function createResourceRequest$2(config) {
1020
+ const headers = {};
1021
+ headers['x-client-feature-id'] = config.headers.xClientFeatureId;
1022
+ const header_xSfdcAppContext = config.headers.xSfdcAppContext || 'EinsteinGPT'; /* Hand rolled default value*/
1023
+ if (header_xSfdcAppContext !== undefined) {
1024
+ headers['x-sfdc-app-context'] = header_xSfdcAppContext;
1025
+ }
1026
+ const header_xLLMProvider = config.headers.xLLMProvider;
1027
+ if (header_xLLMProvider !== undefined) {
1028
+ headers['x-LLM-Provider'] = header_xLLMProvider;
1029
+ }
1030
+ return {
1031
+ baseUri: 'api.salesforce.com',
1032
+ basePath: '/ai/gpt/v1/generations',
1033
+ method: 'post',
1034
+ body: config.body,
1035
+ urlParams: {},
1036
+ queryParams: {},
1037
+ headers,
1038
+ priority: 'normal',
1039
+ };
1040
+ }
1041
+
1042
+ const adapterName$2 = 'getGenerations';
1043
+ const getGenerations_ConfigPropertyMetadata = [
1044
+ generateParamConfigMetadata('prompt', true, 2 /* Body */, 0 /* String */),
1045
+ generateParamConfigMetadata('num_generations', false, 2 /* Body */, 3 /* Integer */),
1046
+ generateParamConfigMetadata('max_tokens', false, 2 /* Body */, 3 /* Integer */),
1047
+ generateParamConfigMetadata('enable_pii_masking', false, 2 /* Body */, 1 /* Boolean */),
1048
+ generateParamConfigMetadata('temperature', false, 2 /* Body */, 2 /* Number */),
1049
+ generateParamConfigMetadata('stop_sequences', false, 2 /* Body */, 0 /* String */, true),
1050
+ generateParamConfigMetadata('frequency_penalty', false, 2 /* Body */, 2 /* Number */),
1051
+ generateParamConfigMetadata('presence_penalty', false, 2 /* Body */, 2 /* Number */),
1052
+ generateParamConfigMetadata('model', false, 2 /* Body */, 0 /* String */),
1053
+ generateParamConfigMetadata('parameters', false, 2 /* Body */, 4 /* Unsupported */),
1054
+ generateParamConfigMetadata('tags', false, 2 /* Body */, 4 /* Unsupported */),
1055
+ generateParamConfigMetadata('xClientFeatureId', true, 3 /* Header */, 0 /* String */),
1056
+ generateParamConfigMetadata('xSfdcAppContext', false, 3 /* Header */, 0 /* String */),
1057
+ generateParamConfigMetadata('xLLMProvider', false, 3 /* Header */, 0 /* String */),
1058
+ ];
1059
+ const getGenerations_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$2, getGenerations_ConfigPropertyMetadata);
1060
+ const createResourceParams$2 = /*#__PURE__*/ createResourceParams$3(getGenerations_ConfigPropertyMetadata);
1061
+ function typeCheckConfig$2(untrustedConfig) {
1062
+ const config = {};
1063
+ typeCheckConfig$3(untrustedConfig, config, getGenerations_ConfigPropertyMetadata);
1064
+ const untrustedConfig_parameters = untrustedConfig.parameters;
1065
+ if (untrustedIsObject(untrustedConfig_parameters)) {
1066
+ const untrustedConfig_parameters_object = {};
1067
+ const untrustedConfig_parameters_keys = Object.keys(untrustedConfig_parameters);
1068
+ for (let i = 0, arrayLength = untrustedConfig_parameters_keys.length; i < arrayLength; i++) {
1069
+ const key = untrustedConfig_parameters_keys[i];
1070
+ const untrustedConfig_parameters_prop = untrustedConfig_parameters[key];
1071
+ if (untrustedConfig_parameters_object !== undefined) {
1072
+ untrustedConfig_parameters_object[key] = untrustedConfig_parameters_prop;
1073
+ }
1074
+ }
1075
+ if (untrustedConfig_parameters_object !== undefined && Object.keys(untrustedConfig_parameters_object).length >= 0) {
1076
+ config.parameters = untrustedConfig_parameters_object;
1077
+ }
1078
+ }
1079
+ const untrustedConfig_tags = untrustedConfig.tags;
1080
+ if (untrustedIsObject(untrustedConfig_tags)) {
1081
+ const untrustedConfig_tags_object = {};
1082
+ const untrustedConfig_tags_keys = Object.keys(untrustedConfig_tags);
1083
+ for (let i = 0, arrayLength = untrustedConfig_tags_keys.length; i < arrayLength; i++) {
1084
+ const key = untrustedConfig_tags_keys[i];
1085
+ const untrustedConfig_tags_prop = untrustedConfig_tags[key];
1086
+ if (untrustedConfig_tags_object !== undefined) {
1087
+ untrustedConfig_tags_object[key] = untrustedConfig_tags_prop;
1088
+ }
1089
+ }
1090
+ if (untrustedConfig_tags_object !== undefined && Object.keys(untrustedConfig_tags_object).length >= 0) {
1091
+ config.tags = untrustedConfig_tags_object;
1092
+ }
1093
+ }
1094
+ return config;
1095
+ }
1096
+ function validateAdapterConfig$2(untrustedConfig, configPropertyNames) {
1097
+ if (!untrustedIsObject(untrustedConfig)) {
1098
+ return null;
1099
+ }
1100
+ if (process.env.NODE_ENV !== 'production') {
1101
+ validateConfig(untrustedConfig, configPropertyNames);
1102
+ }
1103
+ const config = typeCheckConfig$2(untrustedConfig);
1104
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
1105
+ return null;
1106
+ }
1107
+ return config;
1108
+ }
1109
+ function buildNetworkSnapshot$2(luvio, config, options) {
1110
+ const resourceParams = createResourceParams$2(config);
1111
+ const request = createResourceRequest$2(resourceParams);
1112
+ return luvio.dispatchResourceRequest(request, options)
1113
+ .then((response) => {
1114
+ return luvio.handleSuccessResponse(() => {
1115
+ const snapshot = ingestSuccess$2(luvio, resourceParams, response);
1116
+ return luvio.storeBroadcast().then(() => snapshot);
1117
+ }, () => {
1118
+ const cache = new StoreKeyMap();
1119
+ getResponseCacheKeys$2(cache, luvio, resourceParams, response.body);
1120
+ return cache;
1121
+ });
1122
+ }, (response) => {
1123
+ deepFreeze(response);
1124
+ throw response;
1125
+ });
1126
+ }
1127
+ const getGenerationsAdapterFactory = (luvio) => {
1128
+ return function getGenerations(untrustedConfig) {
1129
+ const config = validateAdapterConfig$2(untrustedConfig, getGenerations_ConfigPropertyNames);
1130
+ // Invalid or incomplete config
1131
+ if (config === null) {
1132
+ throw new Error('Invalid config for "getGenerations"');
1133
+ }
1134
+ return buildNetworkSnapshot$2(luvio, config);
1135
+ };
1136
+ };
1137
+
1138
+ const TTL$1 = 100;
1139
+ const VERSION$2 = "f29dcf556357658d72f8330fc3a9d1ac";
1140
+ function validate$4(obj, path = 'FeedbackResponseRepresentation') {
1141
+ const v_error = (() => {
1142
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
1143
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
1144
+ }
1145
+ const obj_message = obj.message;
1146
+ const path_message = path + '.message';
1147
+ if (typeof obj_message !== 'string') {
1148
+ return new TypeError('Expected "string" but received "' + typeof obj_message + '" (at "' + path_message + '")');
1149
+ }
1150
+ })();
1151
+ return v_error === undefined ? null : v_error;
1152
+ }
1153
+ const RepresentationType$1 = 'FeedbackResponseRepresentation';
1154
+ function keyBuilder$2(luvio, config) {
1155
+ return keyPrefix + '::' + RepresentationType$1 + ':' + config.message;
1156
+ }
1157
+ function keyBuilderFromType(luvio, object) {
1158
+ const keyParams = {
1159
+ message: object.message
1160
+ };
1161
+ return keyBuilder$2(luvio, keyParams);
1162
+ }
1163
+ function normalize$1(input, existing, path, luvio, store, timestamp) {
1164
+ return input;
1165
+ }
1166
+ const select$4 = function FeedbackResponseRepresentationSelect() {
1167
+ return {
1168
+ kind: 'Fragment',
1169
+ version: VERSION$2,
1170
+ private: [],
1171
+ selections: [
1172
+ {
1173
+ name: 'message',
1174
+ kind: 'Scalar'
1175
+ }
1176
+ ]
1177
+ };
1178
+ };
1179
+ function equals$2(existing, incoming) {
1180
+ const existing_message = existing.message;
1181
+ const incoming_message = incoming.message;
1182
+ if (!(existing_message === incoming_message)) {
1183
+ return false;
1184
+ }
1185
+ return true;
1186
+ }
1187
+ const ingest$1 = function FeedbackResponseRepresentationIngest(input, path, luvio, store, timestamp) {
1188
+ if (process.env.NODE_ENV !== 'production') {
1189
+ const validateError = validate$4(input);
1190
+ if (validateError !== null) {
1191
+ throw validateError;
1192
+ }
1193
+ }
1194
+ const key = keyBuilderFromType(luvio, input);
1195
+ const ttlToUse = TTL$1;
1196
+ ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize$1, "einstein-ai-gateway", VERSION$2, RepresentationType$1, equals$2);
1197
+ return createLink(key);
1198
+ };
1199
+ function getTypeCacheKeys$1(rootKeySet, luvio, input, fullPathFactory) {
1200
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
1201
+ const rootKey = keyBuilderFromType(luvio, input);
1202
+ rootKeySet.set(rootKey, {
1203
+ namespace: keyPrefix,
1204
+ representationName: RepresentationType$1,
1205
+ mergeable: false
1206
+ });
1207
+ }
1208
+
1209
+ function select$3(luvio, params) {
1210
+ return select$4();
1211
+ }
1212
+ function getResponseCacheKeys$1(storeKeyMap, luvio, resourceParams, response) {
1213
+ getTypeCacheKeys$1(storeKeyMap, luvio, response);
1214
+ }
1215
+ function ingestSuccess$1(luvio, resourceParams, response) {
1216
+ const { body } = response;
1217
+ const key = keyBuilderFromType(luvio, body);
1218
+ luvio.storeIngest(key, ingest$1, body);
1219
+ const snapshot = luvio.storeLookup({
1220
+ recordId: key,
1221
+ node: select$3(),
1222
+ variables: {},
1223
+ });
1224
+ if (process.env.NODE_ENV !== 'production') {
1225
+ if (snapshot.state !== 'Fulfilled') {
1226
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
1227
+ }
1228
+ }
1229
+ deepFreeze(snapshot.data);
1230
+ return snapshot;
1231
+ }
1232
+
1233
+ function createResourceRequest$1(config) {
1234
+ const headers = {};
1235
+ headers['x-client-feature-id'] = config.headers.xClientFeatureId;
1236
+ headers['x-sfdc-app-context'] =
1237
+ config.headers.xSfdcAppContext || 'EinsteinGPT'; /* Hand rolled default value*/
1238
+ return {
1239
+ baseUri: 'api.salesforce.com',
1240
+ basePath: '/ai/gpt/v1/feedback',
1241
+ method: 'post',
1242
+ body: config.body,
1243
+ urlParams: {},
1244
+ queryParams: {},
1245
+ headers,
1246
+ priority: 'normal',
1247
+ };
1248
+ }
1249
+
1250
+ const adapterName$1 = 'registerFeedback';
1251
+ const registerFeedback_ConfigPropertyMetadata = [
1252
+ generateParamConfigMetadata('id', true, 2 /* Body */, 0 /* String */),
1253
+ generateParamConfigMetadata('generation_id', false, 2 /* Body */, 0 /* String */),
1254
+ generateParamConfigMetadata('turn_id', false, 2 /* Body */, 0 /* String */),
1255
+ generateParamConfigMetadata('app_generation_id', false, 2 /* Body */, 0 /* String */),
1256
+ generateParamConfigMetadata('app_generation', false, 2 /* Body */, 0 /* String */),
1257
+ generateParamConfigMetadata('feedback', false, 2 /* Body */, 4 /* Unsupported */),
1258
+ generateParamConfigMetadata('feedback_text', false, 2 /* Body */, 0 /* String */),
1259
+ generateParamConfigMetadata('source', false, 2 /* Body */, 0 /* String */),
1260
+ generateParamConfigMetadata('app_feedback', false, 2 /* Body */, 4 /* Unsupported */),
1261
+ generateParamConfigMetadata('xClientFeatureId', true, 3 /* Header */, 0 /* String */),
1262
+ generateParamConfigMetadata('xSfdcAppContext', false, 3 /* Header */, 0 /* String */),
1263
+ ];
1264
+ const registerFeedback_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$1, registerFeedback_ConfigPropertyMetadata);
1265
+ const createResourceParams$1 = /*#__PURE__*/ createResourceParams$3(registerFeedback_ConfigPropertyMetadata);
1266
+ function typeCheckConfig$1(untrustedConfig) {
1267
+ const config = {};
1268
+ typeCheckConfig$3(untrustedConfig, config, registerFeedback_ConfigPropertyMetadata);
1269
+ const untrustedConfig_feedback = untrustedConfig.feedback;
1270
+ if (typeof untrustedConfig_feedback === 'string') {
1271
+ config.feedback = untrustedConfig_feedback;
1272
+ }
1273
+ if (untrustedConfig_feedback === null) {
1274
+ config.feedback = untrustedConfig_feedback;
1275
+ }
1276
+ const untrustedConfig_app_feedback = untrustedConfig.app_feedback;
1277
+ if (untrustedIsObject(untrustedConfig_app_feedback)) {
1278
+ const untrustedConfig_app_feedback_object = {};
1279
+ const untrustedConfig_app_feedback_keys = Object.keys(untrustedConfig_app_feedback);
1280
+ for (let i = 0, arrayLength = untrustedConfig_app_feedback_keys.length; i < arrayLength; i++) {
1281
+ const key = untrustedConfig_app_feedback_keys[i];
1282
+ const untrustedConfig_app_feedback_prop = untrustedConfig_app_feedback[key];
1283
+ if (untrustedConfig_app_feedback_object !== undefined) {
1284
+ untrustedConfig_app_feedback_object[key] = untrustedConfig_app_feedback_prop;
1285
+ }
1286
+ }
1287
+ if (untrustedConfig_app_feedback_object !== undefined && Object.keys(untrustedConfig_app_feedback_object).length >= 0) {
1288
+ config.app_feedback = untrustedConfig_app_feedback_object;
1289
+ }
1290
+ }
1291
+ return config;
1292
+ }
1293
+ function validateAdapterConfig$1(untrustedConfig, configPropertyNames) {
1294
+ if (!untrustedIsObject(untrustedConfig)) {
1295
+ return null;
1296
+ }
1297
+ if (process.env.NODE_ENV !== 'production') {
1298
+ validateConfig(untrustedConfig, configPropertyNames);
1299
+ }
1300
+ const config = typeCheckConfig$1(untrustedConfig);
1301
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
1302
+ return null;
1303
+ }
1304
+ return config;
1305
+ }
1306
+ function buildNetworkSnapshot$1(luvio, config, options) {
1307
+ const resourceParams = createResourceParams$1(config);
1308
+ const request = createResourceRequest$1(resourceParams);
1309
+ return luvio.dispatchResourceRequest(request, options)
1310
+ .then((response) => {
1311
+ return luvio.handleSuccessResponse(() => {
1312
+ const snapshot = ingestSuccess$1(luvio, resourceParams, response);
1313
+ return luvio.storeBroadcast().then(() => snapshot);
1314
+ }, () => {
1315
+ const cache = new StoreKeyMap();
1316
+ getResponseCacheKeys$1(cache, luvio, resourceParams, response.body);
1317
+ return cache;
1318
+ });
1319
+ }, (response) => {
1320
+ deepFreeze(response);
1321
+ throw response;
1322
+ });
1323
+ }
1324
+ const registerFeedbackAdapterFactory = (luvio) => {
1325
+ return function registerFeedback(untrustedConfig) {
1326
+ const config = validateAdapterConfig$1(untrustedConfig, registerFeedback_ConfigPropertyNames);
1327
+ // Invalid or incomplete config
1328
+ if (config === null) {
1329
+ throw new Error('Invalid config for "registerFeedback"');
1330
+ }
1331
+ return buildNetworkSnapshot$1(luvio, config);
1332
+ };
1333
+ };
1334
+
1335
+ function validate$3(obj, path = 'ProbableLocale') {
1336
+ const v_error = (() => {
1337
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
1338
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
1339
+ }
1340
+ const obj_locale = obj.locale;
1341
+ const path_locale = path + '.locale';
1342
+ if (typeof obj_locale !== 'string') {
1343
+ return new TypeError('Expected "string" but received "' + typeof obj_locale + '" (at "' + path_locale + '")');
1344
+ }
1345
+ if (obj.probability !== undefined) {
1346
+ const obj_probability = obj.probability;
1347
+ const path_probability = path + '.probability';
1348
+ if (typeof obj_probability !== 'number') {
1349
+ return new TypeError('Expected "number" but received "' + typeof obj_probability + '" (at "' + path_probability + '")');
1350
+ }
1351
+ }
1352
+ })();
1353
+ return v_error === undefined ? null : v_error;
1354
+ }
1355
+
1356
+ function validate$2(obj, path = 'Localization') {
1357
+ const v_error = (() => {
1358
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
1359
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
1360
+ }
1361
+ const obj_defaultLocale = obj.defaultLocale;
1362
+ const path_defaultLocale = path + '.defaultLocale';
1363
+ if (typeof obj_defaultLocale !== 'string') {
1364
+ return new TypeError('Expected "string" but received "' + typeof obj_defaultLocale + '" (at "' + path_defaultLocale + '")');
1365
+ }
1366
+ if (obj.expectedLocales !== undefined) {
1367
+ const obj_expectedLocales = obj.expectedLocales;
1368
+ const path_expectedLocales = path + '.expectedLocales';
1369
+ if (!ArrayIsArray(obj_expectedLocales)) {
1370
+ return new TypeError('Expected "array" but received "' + typeof obj_expectedLocales + '" (at "' + path_expectedLocales + '")');
1371
+ }
1372
+ for (let i = 0; i < obj_expectedLocales.length; i++) {
1373
+ const obj_expectedLocales_item = obj_expectedLocales[i];
1374
+ const path_expectedLocales_item = path_expectedLocales + '[' + i + ']';
1375
+ if (typeof obj_expectedLocales_item !== 'string') {
1376
+ return new TypeError('Expected "string" but received "' + typeof obj_expectedLocales_item + '" (at "' + path_expectedLocales_item + '")');
1377
+ }
1378
+ }
1379
+ }
1380
+ if (obj.inputLocales !== undefined) {
1381
+ const obj_inputLocales = obj.inputLocales;
1382
+ const path_inputLocales = path + '.inputLocales';
1383
+ if (!ArrayIsArray(obj_inputLocales)) {
1384
+ return new TypeError('Expected "array" but received "' + typeof obj_inputLocales + '" (at "' + path_inputLocales + '")');
1385
+ }
1386
+ for (let i = 0; i < obj_inputLocales.length; i++) {
1387
+ const obj_inputLocales_item = obj_inputLocales[i];
1388
+ const path_inputLocales_item = path_inputLocales + '[' + i + ']';
1389
+ const referencepath_inputLocales_itemValidationError = validate$3(obj_inputLocales_item, path_inputLocales_item);
1390
+ if (referencepath_inputLocales_itemValidationError !== null) {
1391
+ let message = 'Object doesn\'t match ProbableLocale (at "' + path_inputLocales_item + '")\n';
1392
+ message += referencepath_inputLocales_itemValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
1393
+ return new TypeError(message);
1394
+ }
1395
+ }
1396
+ }
1397
+ })();
1398
+ return v_error === undefined ? null : v_error;
1399
+ }
1400
+
1401
+ const VERSION$1 = "9e6bda93c37ac7a0994be9a1413932c6";
1402
+ function validate$1(obj, path = 'Embeddings') {
1403
+ const v_error = (() => {
1404
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
1405
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
1406
+ }
1407
+ if (obj.embedding !== undefined) {
1408
+ const obj_embedding = obj.embedding;
1409
+ const path_embedding = path + '.embedding';
1410
+ if (!ArrayIsArray(obj_embedding)) {
1411
+ return new TypeError('Expected "array" but received "' + typeof obj_embedding + '" (at "' + path_embedding + '")');
1412
+ }
1413
+ for (let i = 0; i < obj_embedding.length; i++) {
1414
+ const obj_embedding_item = obj_embedding[i];
1415
+ const path_embedding_item = path_embedding + '[' + i + ']';
1416
+ if (typeof obj_embedding_item !== 'number') {
1417
+ return new TypeError('Expected "number" but received "' + typeof obj_embedding_item + '" (at "' + path_embedding_item + '")');
1418
+ }
1419
+ }
1420
+ }
1421
+ if (obj.index !== undefined) {
1422
+ const obj_index = obj.index;
1423
+ const path_index = path + '.index';
1424
+ if (typeof obj_index !== 'number' || (typeof obj_index === 'number' && Math.floor(obj_index) !== obj_index)) {
1425
+ return new TypeError('Expected "integer" but received "' + typeof obj_index + '" (at "' + path_index + '")');
1426
+ }
1427
+ }
1428
+ })();
1429
+ return v_error === undefined ? null : v_error;
1430
+ }
1431
+ const select$2 = function EmbeddingsSelect() {
1432
+ return {
1433
+ kind: 'Fragment',
1434
+ version: VERSION$1,
1435
+ private: [],
1436
+ selections: [
1437
+ {
1438
+ name: 'embedding',
1439
+ kind: 'Scalar',
1440
+ plural: true,
1441
+ required: false
1442
+ },
1443
+ {
1444
+ name: 'index',
1445
+ kind: 'Scalar',
1446
+ required: false
1447
+ }
1448
+ ]
1449
+ };
1450
+ };
1451
+ function equals$1(existing, incoming) {
1452
+ const existing_index = existing.index;
1453
+ const incoming_index = incoming.index;
1454
+ // if at least one of these optionals is defined
1455
+ if (existing_index !== undefined || incoming_index !== undefined) {
1456
+ // if one of these is not defined we know the other is defined and therefore
1457
+ // not equal
1458
+ if (existing_index === undefined || incoming_index === undefined) {
1459
+ return false;
1460
+ }
1461
+ if (!(existing_index === incoming_index)) {
1462
+ return false;
1463
+ }
1464
+ }
1465
+ const existing_embedding = existing.embedding;
1466
+ const incoming_embedding = incoming.embedding;
1467
+ // if at least one of these optionals is defined
1468
+ if (existing_embedding !== undefined || incoming_embedding !== undefined) {
1469
+ // if one of these is not defined we know the other is defined and therefore
1470
+ // not equal
1471
+ if (existing_embedding === undefined || incoming_embedding === undefined) {
1472
+ return false;
1473
+ }
1474
+ const equals_embedding_items = equalsArray(existing_embedding, incoming_embedding, (existing_embedding_item, incoming_embedding_item) => {
1475
+ if (!(existing_embedding_item === incoming_embedding_item)) {
1476
+ return false;
1477
+ }
1478
+ });
1479
+ if (equals_embedding_items === false) {
1480
+ return false;
1481
+ }
1482
+ }
1483
+ return true;
1484
+ }
1485
+
1486
+ const TTL = 100;
1487
+ const VERSION = "93a316d52ad6c5e482831b43f15666b9";
1488
+ function validate(obj, path = 'EmbeddingResponse') {
1489
+ const v_error = (() => {
1490
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
1491
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
1492
+ }
1493
+ if (obj.embeddings !== undefined) {
1494
+ const obj_embeddings = obj.embeddings;
1495
+ const path_embeddings = path + '.embeddings';
1496
+ if (!ArrayIsArray(obj_embeddings)) {
1497
+ return new TypeError('Expected "array" but received "' + typeof obj_embeddings + '" (at "' + path_embeddings + '")');
1498
+ }
1499
+ for (let i = 0; i < obj_embeddings.length; i++) {
1500
+ const obj_embeddings_item = obj_embeddings[i];
1501
+ const path_embeddings_item = path_embeddings + '[' + i + ']';
1502
+ const referencepath_embeddings_itemValidationError = validate$1(obj_embeddings_item, path_embeddings_item);
1503
+ if (referencepath_embeddings_itemValidationError !== null) {
1504
+ let message = 'Object doesn\'t match Embeddings (at "' + path_embeddings_item + '")\n';
1505
+ message += referencepath_embeddings_itemValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
1506
+ return new TypeError(message);
1507
+ }
1508
+ }
1509
+ }
1510
+ if (obj.parameters !== undefined) {
1511
+ const obj_parameters = obj.parameters;
1512
+ const path_parameters = path + '.parameters';
1513
+ if (typeof obj_parameters !== 'object' || ArrayIsArray(obj_parameters) || obj_parameters === null) {
1514
+ return new TypeError('Expected "object" but received "' + typeof obj_parameters + '" (at "' + path_parameters + '")');
1515
+ }
1516
+ const obj_parameters_keys = ObjectKeys(obj_parameters);
1517
+ for (let i = 0; i < obj_parameters_keys.length; i++) {
1518
+ const key = obj_parameters_keys[i];
1519
+ const obj_parameters_prop = obj_parameters[key];
1520
+ const path_parameters_prop = path_parameters + '["' + key + '"]';
1521
+ if (obj_parameters_prop === undefined) {
1522
+ return new TypeError('Expected "defined" but received "' + typeof obj_parameters_prop + '" (at "' + path_parameters_prop + '")');
1523
+ }
1524
+ }
1525
+ }
1526
+ })();
1527
+ return v_error === undefined ? null : v_error;
1528
+ }
1529
+ const RepresentationType = 'EmbeddingResponse';
1530
+ function normalize(input, existing, path, luvio, store, timestamp) {
1531
+ return input;
1532
+ }
1533
+ const select$1 = function EmbeddingResponseSelect() {
1534
+ const { selections: Embeddings__selections, opaque: Embeddings__opaque, } = select$2();
1535
+ return {
1536
+ kind: 'Fragment',
1537
+ version: VERSION,
1538
+ private: [],
1539
+ selections: [
1540
+ {
1541
+ name: 'embeddings',
1542
+ kind: 'Object',
1543
+ plural: true,
1544
+ selections: Embeddings__selections,
1545
+ required: false
1546
+ },
1547
+ {
1548
+ name: 'parameters',
1549
+ kind: 'Object',
1550
+ // any
1551
+ }
1552
+ ]
1553
+ };
1554
+ };
1555
+ function equals(existing, incoming) {
1556
+ const existing_embeddings = existing.embeddings;
1557
+ const incoming_embeddings = incoming.embeddings;
1558
+ // if at least one of these optionals is defined
1559
+ if (existing_embeddings !== undefined || incoming_embeddings !== undefined) {
1560
+ // if one of these is not defined we know the other is defined and therefore
1561
+ // not equal
1562
+ if (existing_embeddings === undefined || incoming_embeddings === undefined) {
1563
+ return false;
1564
+ }
1565
+ const equals_embeddings_items = equalsArray(existing_embeddings, incoming_embeddings, (existing_embeddings_item, incoming_embeddings_item) => {
1566
+ if (!(equals$1(existing_embeddings_item, incoming_embeddings_item))) {
1567
+ return false;
1568
+ }
1569
+ });
1570
+ if (equals_embeddings_items === false) {
1571
+ return false;
1572
+ }
1573
+ }
1574
+ const existing_parameters = existing.parameters;
1575
+ const incoming_parameters = incoming.parameters;
1576
+ // if at least one of these optionals is defined
1577
+ if (existing_parameters !== undefined || incoming_parameters !== undefined) {
1578
+ // if one of these is not defined we know the other is defined and therefore
1579
+ // not equal
1580
+ if (existing_parameters === undefined || incoming_parameters === undefined) {
1581
+ return false;
1582
+ }
1583
+ const equals_parameters_props = equalsObject(existing_parameters, incoming_parameters, (existing_parameters_prop, incoming_parameters_prop) => {
1584
+ if (JSONStringify(incoming_parameters_prop) !== JSONStringify(existing_parameters_prop)) {
1585
+ return false;
1586
+ }
1587
+ });
1588
+ if (equals_parameters_props === false) {
1589
+ return false;
1590
+ }
1591
+ }
1592
+ return true;
1593
+ }
1594
+ const ingest = function EmbeddingResponseIngest(input, path, luvio, store, timestamp) {
1595
+ if (process.env.NODE_ENV !== 'production') {
1596
+ const validateError = validate(input);
1597
+ if (validateError !== null) {
1598
+ throw validateError;
1599
+ }
1600
+ }
1601
+ const key = path.fullPath;
1602
+ const ttlToUse = TTL;
1603
+ ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize, "einstein-ai-gateway", VERSION, RepresentationType, equals);
1604
+ return createLink(key);
1605
+ };
1606
+ function getTypeCacheKeys(rootKeySet, luvio, input, fullPathFactory) {
1607
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
1608
+ const rootKey = fullPathFactory();
1609
+ rootKeySet.set(rootKey, {
1610
+ namespace: keyPrefix,
1611
+ representationName: RepresentationType,
1612
+ mergeable: false
1613
+ });
1614
+ }
1615
+
1616
+ function select(luvio, params) {
1617
+ return select$1();
1618
+ }
1619
+ function keyBuilder$1(luvio, params) {
1620
+ var _a, _b, _c, _d, _e, _f;
1621
+ return keyPrefix + '::EmbeddingResponse:(' + 'xClientFeatureId:' + params.headers.xClientFeatureId + ',' + 'xSfdcAppContext:' + params.headers.xSfdcAppContext + ',' + 'xLLMProvider:' + params.headers.xLLMProvider + ',' + 'input:' + params.body.input + '::' + (params.body.model === undefined ? 'model' : 'model:' + params.body.model) + '::' + (params.body.enable_pii_masking === undefined ? 'enable_pii_masking' : 'enable_pii_masking:' + params.body.enable_pii_masking) + '::' + (((_a = params.body.localization) === null || _a === void 0 ? void 0 : _a.defaultLocale) === undefined ? 'localization.defaultLocale' : 'localization.defaultLocale:' + ((_b = params.body.localization) === null || _b === void 0 ? void 0 : _b.defaultLocale)) + '::' + (((_c = params.body.localization) === null || _c === void 0 ? void 0 : _c.inputLocales) === undefined ? undefined : ('[' + ((_d = params.body.localization) === null || _d === void 0 ? void 0 : _d.inputLocales.map(element => 'localization.inputLocales.locale:' + element.locale + '::' + (element.probability === undefined ? 'localization.inputLocales.probability' : 'localization.inputLocales.probability:' + element.probability)).join(',')) + ']')) + '::' + (((_e = params.body.localization) === null || _e === void 0 ? void 0 : _e.expectedLocales) === undefined ? 'localization.expectedLocales' : 'localization.expectedLocales:' + ((_f = params.body.localization) === null || _f === void 0 ? void 0 : _f.expectedLocales)) + '::' + stableJSONStringify(params.body.parameters) + ')';
1622
+ }
1623
+ function getResponseCacheKeys(storeKeyMap, luvio, resourceParams, response) {
1624
+ getTypeCacheKeys(storeKeyMap, luvio, response, () => keyBuilder$1(luvio, resourceParams));
1625
+ }
1626
+ function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
1627
+ const { body } = response;
1628
+ const key = keyBuilder$1(luvio, resourceParams);
1629
+ luvio.storeIngest(key, ingest, body);
1630
+ const snapshot = luvio.storeLookup({
1631
+ recordId: key,
1632
+ node: select(),
1633
+ variables: {},
1634
+ }, snapshotRefresh);
1635
+ if (process.env.NODE_ENV !== 'production') {
1636
+ if (snapshot.state !== 'Fulfilled') {
1637
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
1638
+ }
1639
+ }
1640
+ deepFreeze(snapshot.data);
1641
+ return snapshot;
1642
+ }
1643
+ function ingestError(luvio, params, error, snapshotRefresh) {
1644
+ const key = keyBuilder$1(luvio, params);
1645
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
1646
+ const storeMetadataParams = {
1647
+ ttl: TTL,
1648
+ namespace: keyPrefix,
1649
+ version: VERSION,
1650
+ representationName: RepresentationType
1651
+ };
1652
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
1653
+ return errorSnapshot;
1654
+ }
1655
+
1656
+ function createResourceRequest(config) {
1657
+ const headers = {};
1658
+ headers['x-client-feature-id'] = config.headers.xClientFeatureId;
1659
+ const header_xSfdcAppContext = config.headers.xSfdcAppContext || 'EinsteinGPT'; /* Hand rolled default value*/
1660
+ if (header_xSfdcAppContext !== undefined) {
1661
+ headers['x-sfdc-app-context'] = header_xSfdcAppContext;
1662
+ }
1663
+ const header_xLLMProvider = config.headers.xLLMProvider;
1664
+ if (header_xLLMProvider !== undefined) {
1665
+ headers['x-LLM-Provider'] = header_xLLMProvider;
1666
+ }
1667
+ return {
1668
+ baseUri: 'api.salesforce.com',
1669
+ basePath: '/ai/gpt/v1/embeddings',
1670
+ method: 'post',
1671
+ body: config.body,
1672
+ urlParams: {},
1673
+ queryParams: {},
1674
+ headers,
1675
+ priority: 'normal',
1676
+ };
1677
+ }
1678
+
1679
+ const adapterName = 'getEmbeddings';
1680
+ const getEmbeddings_ConfigPropertyMetadata = [
1681
+ generateParamConfigMetadata('input', true, 2 /* Body */, 0 /* String */, true),
1682
+ generateParamConfigMetadata('model', false, 2 /* Body */, 0 /* String */),
1683
+ generateParamConfigMetadata('enable_pii_masking', false, 2 /* Body */, 1 /* Boolean */),
1684
+ generateParamConfigMetadata('localization', false, 2 /* Body */, 4 /* Unsupported */),
1685
+ generateParamConfigMetadata('parameters', false, 2 /* Body */, 4 /* Unsupported */),
1686
+ generateParamConfigMetadata('xClientFeatureId', true, 3 /* Header */, 0 /* String */),
1687
+ generateParamConfigMetadata('xSfdcAppContext', false, 3 /* Header */, 0 /* String */),
1688
+ generateParamConfigMetadata('xLLMProvider', false, 3 /* Header */, 0 /* String */),
1689
+ ];
1690
+ const getEmbeddings_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName, getEmbeddings_ConfigPropertyMetadata);
1691
+ const createResourceParams = /*#__PURE__*/ createResourceParams$3(getEmbeddings_ConfigPropertyMetadata);
1692
+ function keyBuilder(luvio, config) {
1693
+ const resourceParams = createResourceParams(config);
1694
+ return keyBuilder$1(luvio, resourceParams);
1695
+ }
1696
+ function typeCheckConfig(untrustedConfig) {
1697
+ const config = {};
1698
+ typeCheckConfig$3(untrustedConfig, config, getEmbeddings_ConfigPropertyMetadata);
1699
+ const untrustedConfig_localization = untrustedConfig.localization;
1700
+ const referenceLocalizationValidationError = validate$2(untrustedConfig_localization);
1701
+ if (referenceLocalizationValidationError === null) {
1702
+ config.localization = untrustedConfig_localization;
1703
+ }
1704
+ const untrustedConfig_parameters = untrustedConfig.parameters;
1705
+ if (untrustedIsObject(untrustedConfig_parameters)) {
1706
+ const untrustedConfig_parameters_object = {};
1707
+ const untrustedConfig_parameters_keys = Object.keys(untrustedConfig_parameters);
1708
+ for (let i = 0, arrayLength = untrustedConfig_parameters_keys.length; i < arrayLength; i++) {
1709
+ const key = untrustedConfig_parameters_keys[i];
1710
+ const untrustedConfig_parameters_prop = untrustedConfig_parameters[key];
1711
+ if (untrustedConfig_parameters_object !== undefined) {
1712
+ untrustedConfig_parameters_object[key] = untrustedConfig_parameters_prop;
1713
+ }
1714
+ }
1715
+ if (untrustedConfig_parameters_object !== undefined && Object.keys(untrustedConfig_parameters_object).length >= 0) {
1716
+ config.parameters = untrustedConfig_parameters_object;
1717
+ }
1718
+ }
1719
+ return config;
1720
+ }
1721
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
1722
+ if (!untrustedIsObject(untrustedConfig)) {
1723
+ return null;
1724
+ }
1725
+ if (process.env.NODE_ENV !== 'production') {
1726
+ validateConfig(untrustedConfig, configPropertyNames);
1727
+ }
1728
+ const config = typeCheckConfig(untrustedConfig);
1729
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
1730
+ return null;
1731
+ }
1732
+ return config;
1733
+ }
1734
+ function adapterFragment(luvio, config) {
1735
+ createResourceParams(config);
1736
+ return select();
1737
+ }
1738
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
1739
+ const snapshot = ingestSuccess(luvio, resourceParams, response, {
1740
+ config,
1741
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
1742
+ });
1743
+ return luvio.storeBroadcast().then(() => snapshot);
1744
+ }
1745
+ function onFetchResponseError(luvio, config, resourceParams, response) {
1746
+ const snapshot = ingestError(luvio, resourceParams, response, {
1747
+ config,
1748
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
1749
+ });
1750
+ return luvio.storeBroadcast().then(() => snapshot);
1751
+ }
1752
+ function buildNetworkSnapshot(luvio, config, options) {
1753
+ const resourceParams = createResourceParams(config);
1754
+ const request = createResourceRequest(resourceParams);
1755
+ return luvio.dispatchResourceRequest(request, options)
1756
+ .then((response) => {
1757
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => {
1758
+ const cache = new StoreKeyMap();
1759
+ getResponseCacheKeys(cache, luvio, resourceParams, response.body);
1760
+ return cache;
1761
+ });
1762
+ }, (response) => {
1763
+ return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
1764
+ });
1765
+ }
1766
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
1767
+ return buildNetworkSnapshotCachePolicy$1(context, coercedAdapterRequestContext, buildNetworkSnapshot, 'get', false);
1768
+ }
1769
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
1770
+ const { luvio, config } = context;
1771
+ const selector = {
1772
+ recordId: keyBuilder(luvio, config),
1773
+ node: adapterFragment(luvio, config),
1774
+ variables: {},
1775
+ };
1776
+ const cacheSnapshot = storeLookup(selector, {
1777
+ config,
1778
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
1779
+ });
1780
+ return cacheSnapshot;
1781
+ }
1782
+ const getEmbeddingsAdapterFactory = (luvio) => function einsteinAiGateway__getEmbeddings(untrustedConfig, requestContext) {
1783
+ const config = validateAdapterConfig(untrustedConfig, getEmbeddings_ConfigPropertyNames);
1784
+ // Invalid or incomplete config
1785
+ if (config === null) {
1786
+ return null;
1787
+ }
1788
+ return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
1789
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
1790
+ };
1791
+
1792
+ export { getEmbeddingsAdapterFactory, getGenerationsAdapterFactory, registerFeedbackAdapterFactory };