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