@salesforce/lds-adapters-sfap-einstein-ai-gateway 1.265.0 → 1.266.0-dev2

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.
@@ -4,11 +4,10 @@
4
4
  * For full license text, see the LICENSE.txt file
5
5
  */
6
6
 
7
- import { serializeStructuredKey, ingestShape, deepFreeze, buildNetworkSnapshotCachePolicy as buildNetworkSnapshotCachePolicy$1, typeCheckConfig as typeCheckConfig$2, StoreKeyMap, createResourceParams as createResourceParams$2 } from '@luvio/engine';
7
+ import { serializeStructuredKey, ingestShape, deepFreeze, StoreKeyMap, createResourceParams as createResourceParams$2, typeCheckConfig as typeCheckConfig$2 } from '@luvio/engine';
8
8
 
9
9
  const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
10
10
  const { keys: ObjectKeys$1, create: ObjectCreate$1 } = Object;
11
- const { stringify: JSONStringify$1 } = JSON;
12
11
  const { isArray: ArrayIsArray$1 } = Array;
13
12
  /**
14
13
  * Validates an adapter config is well-formed.
@@ -42,68 +41,6 @@ function untrustedIsObject(untrusted) {
42
41
  function areRequiredParametersPresent(config, configPropertyNames) {
43
42
  return configPropertyNames.parameters.required.every(req => req in config);
44
43
  }
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
44
  function generateParamConfigMetadata(name, required, resourceType, typeCheckShape, isArrayShape = false, coerceFn) {
108
45
  return {
109
46
  name,
@@ -622,7 +559,8 @@ function equals$2(existing, incoming) {
622
559
  return true;
623
560
  }
624
561
 
625
- const VERSION$1 = "4f085d3ce8f948d5a3d38e9e24ce4f63";
562
+ const TTL$1 = 100;
563
+ const VERSION$1 = "ad6b1f255df73e241341ce190bfafe29";
626
564
  function validate$1(obj, path = 'GenerationResponse') {
627
565
  const v_error = (() => {
628
566
  if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
@@ -696,6 +634,15 @@ function validate$1(obj, path = 'GenerationResponse') {
696
634
  return v_error === undefined ? null : v_error;
697
635
  }
698
636
  const RepresentationType$1 = 'GenerationResponse';
637
+ function keyBuilder$1(luvio, config) {
638
+ return keyPrefix + '::' + RepresentationType$1 + ':' + config.id;
639
+ }
640
+ function keyBuilderFromType$1(luvio, object) {
641
+ const keyParams = {
642
+ id: object.id
643
+ };
644
+ return keyBuilder$1(luvio, keyParams);
645
+ }
699
646
  function normalize$1(input, existing, path, luvio, store, timestamp) {
700
647
  return input;
701
648
  }
@@ -785,14 +732,14 @@ const ingest$1 = function GenerationResponseIngest(input, path, luvio, store, ti
785
732
  throw validateError;
786
733
  }
787
734
  }
788
- const key = path.fullPath;
789
- const ttlToUse = path.ttl !== undefined ? path.ttl : 100;
735
+ const key = keyBuilderFromType$1(luvio, input);
736
+ const ttlToUse = TTL$1;
790
737
  ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize$1, "einstein-ai-gateway", VERSION$1, RepresentationType$1, equals$1);
791
738
  return createLink(key);
792
739
  };
793
740
  function getTypeCacheKeys$1(rootKeySet, luvio, input, fullPathFactory) {
794
741
  // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
795
- const rootKey = fullPathFactory();
742
+ const rootKey = keyBuilderFromType$1(luvio, input);
796
743
  rootKeySet.set(rootKey, {
797
744
  namespace: keyPrefix,
798
745
  representationName: RepresentationType$1,
@@ -803,21 +750,18 @@ function getTypeCacheKeys$1(rootKeySet, luvio, input, fullPathFactory) {
803
750
  function select$2(luvio, params) {
804
751
  return select$3();
805
752
  }
806
- function keyBuilder$2(luvio, params) {
807
- return keyPrefix + '::GenerationResponse:(' + 'xClientFeatureId:' + params.headers.xClientFeatureId + ',' + 'xLLMProvider:' + params.headers.xLLMProvider + ',' + 'prompt:' + params.body.prompt + '::' + (params.body.num_generations === undefined ? 'num_generations' : 'num_generations:' + params.body.num_generations) + '::' + (params.body.max_tokens === undefined ? 'max_tokens' : 'max_tokens:' + params.body.max_tokens) + '::' + (params.body.enable_pii_masking === undefined ? 'enable_pii_masking' : 'enable_pii_masking:' + params.body.enable_pii_masking) + '::' + (params.body.temperature === undefined ? 'temperature' : 'temperature:' + params.body.temperature) + '::' + (params.body.stop_sequences === undefined ? 'stop_sequences' : 'stop_sequences:' + params.body.stop_sequences) + '::' + (params.body.frequency_penalty === undefined ? 'frequency_penalty' : 'frequency_penalty:' + params.body.frequency_penalty) + '::' + (params.body.presence_penalty === undefined ? 'presence_penalty' : 'presence_penalty:' + params.body.presence_penalty) + '::' + (params.body.model === undefined ? 'model' : 'model:' + params.body.model) + '::' + stableJSONStringify(params.body.parameters) + '::' + stableJSONStringify(params.body.tags) + ')';
808
- }
809
753
  function getResponseCacheKeys$1(storeKeyMap, luvio, resourceParams, response) {
810
- getTypeCacheKeys$1(storeKeyMap, luvio, response, () => keyBuilder$2(luvio, resourceParams));
754
+ getTypeCacheKeys$1(storeKeyMap, luvio, response);
811
755
  }
812
- function ingestSuccess$1(luvio, resourceParams, response, snapshotRefresh) {
756
+ function ingestSuccess$1(luvio, resourceParams, response) {
813
757
  const { body } = response;
814
- const key = keyBuilder$2(luvio, resourceParams);
758
+ const key = keyBuilderFromType$1(luvio, body);
815
759
  luvio.storeIngest(key, ingest$1, body);
816
760
  const snapshot = luvio.storeLookup({
817
761
  recordId: key,
818
762
  node: select$2(),
819
763
  variables: {},
820
- }, snapshotRefresh);
764
+ });
821
765
  if (process.env.NODE_ENV !== 'production') {
822
766
  if (snapshot.state !== 'Fulfilled') {
823
767
  throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
@@ -826,12 +770,6 @@ function ingestSuccess$1(luvio, resourceParams, response, snapshotRefresh) {
826
770
  deepFreeze(snapshot.data);
827
771
  return snapshot;
828
772
  }
829
- function ingestError(luvio, params, error, snapshotRefresh) {
830
- const key = keyBuilder$2(luvio, params);
831
- const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
832
- luvio.storeIngestError(key, errorSnapshot);
833
- return errorSnapshot;
834
- }
835
773
  function createResourceRequest$1(config) {
836
774
  const headers = {};
837
775
  headers['x-client-feature-id'] = config.headers.xClientFeatureId;
@@ -866,10 +804,6 @@ const getGenerations_ConfigPropertyMetadata = [
866
804
  ];
867
805
  const getGenerations_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$1, getGenerations_ConfigPropertyMetadata);
868
806
  const createResourceParams$1 = /*#__PURE__*/ createResourceParams$2(getGenerations_ConfigPropertyMetadata);
869
- function keyBuilder$1(luvio, config) {
870
- const resourceParams = createResourceParams$1(config);
871
- return keyBuilder$2(luvio, resourceParams);
872
- }
873
807
  function typeCheckConfig$1(untrustedConfig) {
874
808
  const config = {};
875
809
  typeCheckConfig$2(untrustedConfig, config, getGenerations_ConfigPropertyMetadata);
@@ -918,62 +852,33 @@ function validateAdapterConfig$1(untrustedConfig, configPropertyNames) {
918
852
  }
919
853
  return config;
920
854
  }
921
- function adapterFragment(luvio, config) {
922
- createResourceParams$1(config);
923
- return select$2();
924
- }
925
- function onFetchResponseSuccess(luvio, config, resourceParams, response) {
926
- const snapshot = ingestSuccess$1(luvio, resourceParams, response, {
927
- config,
928
- resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
929
- });
930
- return luvio.storeBroadcast().then(() => snapshot);
931
- }
932
- function onFetchResponseError(luvio, config, resourceParams, response) {
933
- const snapshot = ingestError(luvio, resourceParams, response, {
934
- config,
935
- resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
936
- });
937
- return luvio.storeBroadcast().then(() => snapshot);
938
- }
939
855
  function buildNetworkSnapshot$1(luvio, config, options) {
940
856
  const resourceParams = createResourceParams$1(config);
941
857
  const request = createResourceRequest$1(resourceParams);
942
858
  return luvio.dispatchResourceRequest(request, options)
943
859
  .then((response) => {
944
- return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => {
860
+ return luvio.handleSuccessResponse(() => {
861
+ const snapshot = ingestSuccess$1(luvio, resourceParams, response);
862
+ return luvio.storeBroadcast().then(() => snapshot);
863
+ }, () => {
945
864
  const cache = new StoreKeyMap();
946
865
  getResponseCacheKeys$1(cache, luvio, resourceParams, response.body);
947
866
  return cache;
948
867
  });
949
868
  }, (response) => {
950
- return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
869
+ deepFreeze(response);
870
+ throw response;
951
871
  });
952
872
  }
953
- function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
954
- return buildNetworkSnapshotCachePolicy$1(context, coercedAdapterRequestContext, buildNetworkSnapshot$1, 'get', false);
955
- }
956
- function buildCachedSnapshotCachePolicy(context, storeLookup) {
957
- const { luvio, config } = context;
958
- const selector = {
959
- recordId: keyBuilder$1(luvio, config),
960
- node: adapterFragment(luvio, config),
961
- variables: {},
873
+ const getGenerationsAdapterFactory = (luvio) => {
874
+ return function getGenerations(untrustedConfig) {
875
+ const config = validateAdapterConfig$1(untrustedConfig, getGenerations_ConfigPropertyNames);
876
+ // Invalid or incomplete config
877
+ if (config === null) {
878
+ throw new Error('Invalid config for "getGenerations"');
879
+ }
880
+ return buildNetworkSnapshot$1(luvio, config);
962
881
  };
963
- const cacheSnapshot = storeLookup(selector, {
964
- config,
965
- resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
966
- });
967
- return cacheSnapshot;
968
- }
969
- const getGenerationsAdapterFactory = (luvio) => function einsteinAiGateway__getGenerations(untrustedConfig, requestContext) {
970
- const config = validateAdapterConfig$1(untrustedConfig, getGenerations_ConfigPropertyNames);
971
- // Invalid or incomplete config
972
- if (config === null) {
973
- return null;
974
- }
975
- return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
976
- buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
977
882
  };
978
883
 
979
884
  const TTL = 100;
@@ -1,4 +1,4 @@
1
- import { AdapterConfigMetadata as $64$luvio_engine_AdapterConfigMetadata, Luvio as $64$luvio_engine_Luvio, NormalizedKeyMetadata as $64$luvio_engine_NormalizedKeyMetadata, Fragment as $64$luvio_engine_Fragment, Snapshot as $64$luvio_engine_Snapshot, FetchResponse as $64$luvio_engine_FetchResponse, ErrorResponse as $64$luvio_engine_ErrorResponse, DispatchResourceRequestContext as $64$luvio_engine_DispatchResourceRequestContext, CoercedAdapterRequestContext as $64$luvio_engine_CoercedAdapterRequestContext, StoreLookup as $64$luvio_engine_StoreLookup, AdapterFactory as $64$luvio_engine_AdapterFactory } from '@luvio/engine';
1
+ import { AdapterConfigMetadata as $64$luvio_engine_AdapterConfigMetadata, Luvio as $64$luvio_engine_Luvio, DispatchResourceRequestContext as $64$luvio_engine_DispatchResourceRequestContext, AdapterFactory as $64$luvio_engine_AdapterFactory } from '@luvio/engine';
2
2
  import { Untrusted as adapter$45$utils_Untrusted, AdapterValidationConfig as adapter$45$utils_AdapterValidationConfig } from './adapter-utils';
3
3
  import { ResourceRequestConfig as resources_postAiGptV1Generations_ResourceRequestConfig } from '../resources/postAiGptV1Generations';
4
4
  import { GenerationResponse as types_GenerationResponse_GenerationResponse } from '../types/GenerationResponse';
@@ -25,19 +25,7 @@ export interface GetGenerationsConfig {
25
25
  };
26
26
  }
27
27
  export declare const createResourceParams: (config: GetGenerationsConfig) => resources_postAiGptV1Generations_ResourceRequestConfig;
28
- export declare function keyBuilder(luvio: $64$luvio_engine_Luvio, config: GetGenerationsConfig): string;
29
- export declare function keyBuilder_StructuredKey(luvio: $64$luvio_engine_Luvio, config: GetGenerationsConfig): $64$luvio_engine_NormalizedKeyMetadata;
30
28
  export declare function typeCheckConfig(untrustedConfig: adapter$45$utils_Untrusted<GetGenerationsConfig>): adapter$45$utils_Untrusted<GetGenerationsConfig>;
31
29
  export declare function validateAdapterConfig(untrustedConfig: unknown, configPropertyNames: adapter$45$utils_AdapterValidationConfig): GetGenerationsConfig | null;
32
- export declare function adapterFragment(luvio: $64$luvio_engine_Luvio, config: GetGenerationsConfig): $64$luvio_engine_Fragment;
33
- export declare function buildCachedSnapshot(luvio: $64$luvio_engine_Luvio, config: GetGenerationsConfig): $64$luvio_engine_Snapshot<types_GenerationResponse_GenerationResponse, any>;
34
- export declare function onFetchResponseSuccess(luvio: $64$luvio_engine_Luvio, config: GetGenerationsConfig, resourceParams: resources_postAiGptV1Generations_ResourceRequestConfig, response: $64$luvio_engine_FetchResponse<types_GenerationResponse_GenerationResponse>): Promise<import("@luvio/engine").FulfilledSnapshot<types_GenerationResponse_GenerationResponse, {}> | import("@luvio/engine").StaleSnapshot<types_GenerationResponse_GenerationResponse, {}> | import("@luvio/engine").PendingSnapshot<types_GenerationResponse_GenerationResponse, any>>;
35
- export declare function onFetchResponseError(luvio: $64$luvio_engine_Luvio, config: GetGenerationsConfig, resourceParams: resources_postAiGptV1Generations_ResourceRequestConfig, response: $64$luvio_engine_ErrorResponse): Promise<import("@luvio/engine").ErrorSnapshot>;
36
- export declare function buildNetworkSnapshot(luvio: $64$luvio_engine_Luvio, config: GetGenerationsConfig, options?: $64$luvio_engine_DispatchResourceRequestContext): Promise<$64$luvio_engine_Snapshot<types_GenerationResponse_GenerationResponse, any>>;
37
- export type BuildSnapshotContext = {
38
- luvio: $64$luvio_engine_Luvio;
39
- config: GetGenerationsConfig;
40
- };
41
- export declare function buildNetworkSnapshotCachePolicy(context: BuildSnapshotContext, coercedAdapterRequestContext: $64$luvio_engine_CoercedAdapterRequestContext): Promise<$64$luvio_engine_Snapshot<types_GenerationResponse_GenerationResponse, any>>;
42
- export declare function buildCachedSnapshotCachePolicy(context: BuildSnapshotContext, storeLookup: $64$luvio_engine_StoreLookup<types_GenerationResponse_GenerationResponse>): $64$luvio_engine_Snapshot<types_GenerationResponse_GenerationResponse, any>;
30
+ export declare function buildNetworkSnapshot(luvio: $64$luvio_engine_Luvio, config: GetGenerationsConfig, options?: $64$luvio_engine_DispatchResourceRequestContext): Promise<import("@luvio/engine").FulfilledSnapshot<types_GenerationResponse_GenerationResponse, {}> | import("@luvio/engine").StaleSnapshot<types_GenerationResponse_GenerationResponse, {}> | import("@luvio/engine").PendingSnapshot<types_GenerationResponse_GenerationResponse, any>>;
43
31
  export declare const getGenerationsAdapterFactory: $64$luvio_engine_AdapterFactory<GetGenerationsConfig, types_GenerationResponse_GenerationResponse>;
@@ -1,4 +1,3 @@
1
1
  declare let getGenerations: any;
2
2
  declare let registerFeedback: any;
3
- declare let getGenerations_imperative: any;
4
- export { getGenerations, registerFeedback, getGenerations_imperative };
3
+ export { getGenerations, registerFeedback };
@@ -1,4 +1,4 @@
1
- import { Luvio as $64$luvio_engine_Luvio, Fragment as $64$luvio_engine_Fragment, NormalizedKeyMetadata as $64$luvio_engine_NormalizedKeyMetadata, FetchResponse as $64$luvio_engine_FetchResponse, SnapshotRefresh as $64$luvio_engine_SnapshotRefresh, FulfilledSnapshot as $64$luvio_engine_FulfilledSnapshot, StaleSnapshot as $64$luvio_engine_StaleSnapshot, PendingSnapshot as $64$luvio_engine_PendingSnapshot, ErrorResponse as $64$luvio_engine_ErrorResponse, ErrorSnapshot as $64$luvio_engine_ErrorSnapshot, ResourceRequest as $64$luvio_engine_ResourceRequest } from '@luvio/engine';
1
+ import { Luvio as $64$luvio_engine_Luvio, Fragment as $64$luvio_engine_Fragment, FetchResponse as $64$luvio_engine_FetchResponse, FulfilledSnapshot as $64$luvio_engine_FulfilledSnapshot, StaleSnapshot as $64$luvio_engine_StaleSnapshot, PendingSnapshot as $64$luvio_engine_PendingSnapshot, ResourceRequest as $64$luvio_engine_ResourceRequest } from '@luvio/engine';
2
2
  import { GenerationResponse as types_GenerationResponse_GenerationResponse } from '../types/GenerationResponse';
3
3
  export interface ResourceRequestConfig {
4
4
  body: {
@@ -24,10 +24,7 @@ export interface ResourceRequestConfig {
24
24
  };
25
25
  }
26
26
  export declare function select(luvio: $64$luvio_engine_Luvio, params: ResourceRequestConfig): $64$luvio_engine_Fragment;
27
- export declare function keyBuilder(luvio: $64$luvio_engine_Luvio, params: ResourceRequestConfig): string;
28
- export declare function keyBuilder_StructuredKey(luvio: $64$luvio_engine_Luvio, params: ResourceRequestConfig): $64$luvio_engine_NormalizedKeyMetadata;
29
27
  export declare function getResponseCacheKeys(storeKeyMap: any, luvio: $64$luvio_engine_Luvio, resourceParams: ResourceRequestConfig, response: types_GenerationResponse_GenerationResponse): void;
30
- export declare function ingestSuccess(luvio: $64$luvio_engine_Luvio, resourceParams: ResourceRequestConfig, response: $64$luvio_engine_FetchResponse<types_GenerationResponse_GenerationResponse>, snapshotRefresh?: $64$luvio_engine_SnapshotRefresh<types_GenerationResponse_GenerationResponse>): $64$luvio_engine_FulfilledSnapshot<types_GenerationResponse_GenerationResponse, {}> | $64$luvio_engine_StaleSnapshot<types_GenerationResponse_GenerationResponse, {}> | $64$luvio_engine_PendingSnapshot<types_GenerationResponse_GenerationResponse, any>;
31
- export declare function ingestError(luvio: $64$luvio_engine_Luvio, params: ResourceRequestConfig, error: $64$luvio_engine_ErrorResponse, snapshotRefresh?: $64$luvio_engine_SnapshotRefresh<types_GenerationResponse_GenerationResponse>): $64$luvio_engine_ErrorSnapshot;
28
+ export declare function ingestSuccess(luvio: $64$luvio_engine_Luvio, resourceParams: ResourceRequestConfig, response: $64$luvio_engine_FetchResponse<types_GenerationResponse_GenerationResponse>): $64$luvio_engine_FulfilledSnapshot<types_GenerationResponse_GenerationResponse, {}> | $64$luvio_engine_StaleSnapshot<types_GenerationResponse_GenerationResponse, {}> | $64$luvio_engine_PendingSnapshot<types_GenerationResponse_GenerationResponse, any>;
32
29
  export declare function createResourceRequest(config: ResourceRequestConfig): $64$luvio_engine_ResourceRequest;
33
30
  export default createResourceRequest;
@@ -1,8 +1,18 @@
1
1
  import { GenerationResponseGenerations as GenerationResponseGenerations_GenerationResponseGenerations } from './GenerationResponseGenerations';
2
- import { IngestPath as $64$luvio_engine_IngestPath, Luvio as $64$luvio_engine_Luvio, Store as $64$luvio_engine_Store, FragmentSelection as $64$luvio_engine_FragmentSelection, ResourceIngest as $64$luvio_engine_ResourceIngest, DurableStoreKeyMetadataMap as $64$luvio_engine_DurableStoreKeyMetadataMap, NormalizedKeyMetadata as $64$luvio_engine_NormalizedKeyMetadata } from '@luvio/engine';
3
- export declare const VERSION = "4f085d3ce8f948d5a3d38e9e24ce4f63";
2
+ import { KeyMetadata as $64$luvio_engine_KeyMetadata, NormalizedKeyMetadata as $64$luvio_engine_NormalizedKeyMetadata, Luvio as $64$luvio_engine_Luvio, IngestPath as $64$luvio_engine_IngestPath, Store as $64$luvio_engine_Store, FragmentSelection as $64$luvio_engine_FragmentSelection, ResourceIngest as $64$luvio_engine_ResourceIngest, DurableStoreKeyMetadataMap as $64$luvio_engine_DurableStoreKeyMetadataMap } from '@luvio/engine';
3
+ export declare const TTL = 100;
4
+ export declare const VERSION = "ad6b1f255df73e241341ce190bfafe29";
4
5
  export declare function validate(obj: any, path?: string): TypeError | null;
5
6
  export declare const RepresentationType: string;
7
+ export interface KeyParams extends $64$luvio_engine_KeyMetadata {
8
+ id: string;
9
+ }
10
+ export type GenerationResponseNormalizedKeyMetadata = KeyParams & $64$luvio_engine_NormalizedKeyMetadata;
11
+ export type PartialGenerationResponseNormalizedKeyMetadata = Partial<KeyParams> & $64$luvio_engine_NormalizedKeyMetadata;
12
+ export declare function keyBuilder(luvio: $64$luvio_engine_Luvio, config: KeyParams): string;
13
+ export declare function keyBuilder_StructuredKey(luvio: $64$luvio_engine_Luvio, config: KeyParams): GenerationResponseNormalizedKeyMetadata;
14
+ export declare function keyBuilderFromType(luvio: $64$luvio_engine_Luvio, object: GenerationResponse): string;
15
+ export declare function keyBuilderFromType_StructuredKey(luvio: $64$luvio_engine_Luvio, object: GenerationResponse): $64$luvio_engine_NormalizedKeyMetadata;
6
16
  export declare function normalize(input: GenerationResponse, existing: GenerationResponseNormalized, path: $64$luvio_engine_IngestPath, luvio: $64$luvio_engine_Luvio, store: $64$luvio_engine_Store, timestamp: number): GenerationResponseNormalized;
7
17
  export declare const select: () => $64$luvio_engine_FragmentSelection;
8
18
  export declare function equals(existing: GenerationResponseNormalized, incoming: GenerationResponseNormalized): boolean;
@@ -12,7 +22,7 @@ export declare function getTypeCacheKeys(rootKeySet: $64$luvio_engine_DurableSto
12
22
  *
13
23
  *
14
24
  * Keys:
15
- * (none)
25
+ * id (string): id
16
26
  */
17
27
  export interface GenerationResponseNormalized {
18
28
  /** List of generated text items. */
@@ -30,7 +40,7 @@ export interface GenerationResponseNormalized {
30
40
  *
31
41
  *
32
42
  * Keys:
33
- * (none)
43
+ * id (string): id
34
44
  */
35
45
  export interface GenerationResponse {
36
46
  generations: Array<GenerationResponseGenerations_GenerationResponseGenerations>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-adapters-sfap-einstein-ai-gateway",
3
- "version": "1.265.0",
3
+ "version": "1.266.0-dev2",
4
4
  "description": "LLM Gateway API's",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "dist/es/es2018/sfap-einstein-ai-gateway.js",
@@ -40,10 +40,10 @@
40
40
  "test:unit": "jest"
41
41
  },
42
42
  "dependencies": {
43
- "@salesforce/lds-bindings": "^1.265.0"
43
+ "@salesforce/lds-bindings": "^1.266.0-dev2"
44
44
  },
45
45
  "devDependencies": {
46
- "@salesforce/lds-compiler-plugins": "^1.265.0"
46
+ "@salesforce/lds-compiler-plugins": "^1.266.0-dev2"
47
47
  },
48
48
  "nx": {
49
49
  "targets": {
package/sfdc/index.js CHANGED
@@ -12,13 +12,11 @@
12
12
  * *******************************************************************************************
13
13
  */
14
14
  /* proxy-compat-disable */
15
- import { createInstrumentedAdapter, createLDSAdapter, createWireAdapterConstructor, createImperativeAdapter } from 'force/ldsBindings';
16
15
  import { withDefaultLuvio } from 'force/ldsEngine';
17
- import { serializeStructuredKey, ingestShape, deepFreeze, buildNetworkSnapshotCachePolicy as buildNetworkSnapshotCachePolicy$1, typeCheckConfig as typeCheckConfig$2, StoreKeyMap, createResourceParams as createResourceParams$2 } from 'force/luvioEngine';
16
+ import { serializeStructuredKey, ingestShape, deepFreeze, StoreKeyMap, createResourceParams as createResourceParams$2, typeCheckConfig as typeCheckConfig$2 } from 'force/luvioEngine';
18
17
 
19
18
  const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
20
19
  const { keys: ObjectKeys$1, create: ObjectCreate$1 } = Object;
21
- const { stringify: JSONStringify$1 } = JSON;
22
20
  const { isArray: ArrayIsArray$1 } = Array;
23
21
  /**
24
22
  * Validates an adapter config is well-formed.
@@ -52,68 +50,6 @@ function untrustedIsObject(untrusted) {
52
50
  function areRequiredParametersPresent(config, configPropertyNames) {
53
51
  return configPropertyNames.parameters.required.every(req => req in config);
54
52
  }
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
53
  function generateParamConfigMetadata(name, required, resourceType, typeCheckShape, isArrayShape = false, coerceFn) {
118
54
  return {
119
55
  name,
@@ -632,7 +568,8 @@ function equals$2(existing, incoming) {
632
568
  return true;
633
569
  }
634
570
 
635
- const VERSION$1 = "4f085d3ce8f948d5a3d38e9e24ce4f63";
571
+ const TTL$1 = 100;
572
+ const VERSION$1 = "ad6b1f255df73e241341ce190bfafe29";
636
573
  function validate$1(obj, path = 'GenerationResponse') {
637
574
  const v_error = (() => {
638
575
  if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
@@ -706,6 +643,15 @@ function validate$1(obj, path = 'GenerationResponse') {
706
643
  return v_error === undefined ? null : v_error;
707
644
  }
708
645
  const RepresentationType$1 = 'GenerationResponse';
646
+ function keyBuilder$1(luvio, config) {
647
+ return keyPrefix + '::' + RepresentationType$1 + ':' + config.id;
648
+ }
649
+ function keyBuilderFromType$1(luvio, object) {
650
+ const keyParams = {
651
+ id: object.id
652
+ };
653
+ return keyBuilder$1(luvio, keyParams);
654
+ }
709
655
  function normalize$1(input, existing, path, luvio, store, timestamp) {
710
656
  return input;
711
657
  }
@@ -795,14 +741,14 @@ const ingest$1 = function GenerationResponseIngest(input, path, luvio, store, ti
795
741
  throw validateError;
796
742
  }
797
743
  }
798
- const key = path.fullPath;
799
- const ttlToUse = path.ttl !== undefined ? path.ttl : 100;
744
+ const key = keyBuilderFromType$1(luvio, input);
745
+ const ttlToUse = TTL$1;
800
746
  ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize$1, "einstein-ai-gateway", VERSION$1, RepresentationType$1, equals$1);
801
747
  return createLink(key);
802
748
  };
803
749
  function getTypeCacheKeys$1(rootKeySet, luvio, input, fullPathFactory) {
804
750
  // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
805
- const rootKey = fullPathFactory();
751
+ const rootKey = keyBuilderFromType$1(luvio, input);
806
752
  rootKeySet.set(rootKey, {
807
753
  namespace: keyPrefix,
808
754
  representationName: RepresentationType$1,
@@ -813,21 +759,18 @@ function getTypeCacheKeys$1(rootKeySet, luvio, input, fullPathFactory) {
813
759
  function select$2(luvio, params) {
814
760
  return select$3();
815
761
  }
816
- function keyBuilder$2(luvio, params) {
817
- return keyPrefix + '::GenerationResponse:(' + 'xClientFeatureId:' + params.headers.xClientFeatureId + ',' + 'xLLMProvider:' + params.headers.xLLMProvider + ',' + 'prompt:' + params.body.prompt + '::' + (params.body.num_generations === undefined ? 'num_generations' : 'num_generations:' + params.body.num_generations) + '::' + (params.body.max_tokens === undefined ? 'max_tokens' : 'max_tokens:' + params.body.max_tokens) + '::' + (params.body.enable_pii_masking === undefined ? 'enable_pii_masking' : 'enable_pii_masking:' + params.body.enable_pii_masking) + '::' + (params.body.temperature === undefined ? 'temperature' : 'temperature:' + params.body.temperature) + '::' + (params.body.stop_sequences === undefined ? 'stop_sequences' : 'stop_sequences:' + params.body.stop_sequences) + '::' + (params.body.frequency_penalty === undefined ? 'frequency_penalty' : 'frequency_penalty:' + params.body.frequency_penalty) + '::' + (params.body.presence_penalty === undefined ? 'presence_penalty' : 'presence_penalty:' + params.body.presence_penalty) + '::' + (params.body.model === undefined ? 'model' : 'model:' + params.body.model) + '::' + stableJSONStringify(params.body.parameters) + '::' + stableJSONStringify(params.body.tags) + ')';
818
- }
819
762
  function getResponseCacheKeys$1(storeKeyMap, luvio, resourceParams, response) {
820
- getTypeCacheKeys$1(storeKeyMap, luvio, response, () => keyBuilder$2(luvio, resourceParams));
763
+ getTypeCacheKeys$1(storeKeyMap, luvio, response);
821
764
  }
822
- function ingestSuccess$1(luvio, resourceParams, response, snapshotRefresh) {
765
+ function ingestSuccess$1(luvio, resourceParams, response) {
823
766
  const { body } = response;
824
- const key = keyBuilder$2(luvio, resourceParams);
767
+ const key = keyBuilderFromType$1(luvio, body);
825
768
  luvio.storeIngest(key, ingest$1, body);
826
769
  const snapshot = luvio.storeLookup({
827
770
  recordId: key,
828
771
  node: select$2(),
829
772
  variables: {},
830
- }, snapshotRefresh);
773
+ });
831
774
  if (process.env.NODE_ENV !== 'production') {
832
775
  if (snapshot.state !== 'Fulfilled') {
833
776
  throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
@@ -836,12 +779,6 @@ function ingestSuccess$1(luvio, resourceParams, response, snapshotRefresh) {
836
779
  deepFreeze(snapshot.data);
837
780
  return snapshot;
838
781
  }
839
- function ingestError(luvio, params, error, snapshotRefresh) {
840
- const key = keyBuilder$2(luvio, params);
841
- const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
842
- luvio.storeIngestError(key, errorSnapshot);
843
- return errorSnapshot;
844
- }
845
782
  function createResourceRequest$1(config) {
846
783
  const headers = {};
847
784
  headers['x-client-feature-id'] = config.headers.xClientFeatureId;
@@ -876,10 +813,6 @@ const getGenerations_ConfigPropertyMetadata = [
876
813
  ];
877
814
  const getGenerations_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$1, getGenerations_ConfigPropertyMetadata);
878
815
  const createResourceParams$1 = /*#__PURE__*/ createResourceParams$2(getGenerations_ConfigPropertyMetadata);
879
- function keyBuilder$1(luvio, config) {
880
- const resourceParams = createResourceParams$1(config);
881
- return keyBuilder$2(luvio, resourceParams);
882
- }
883
816
  function typeCheckConfig$1(untrustedConfig) {
884
817
  const config = {};
885
818
  typeCheckConfig$2(untrustedConfig, config, getGenerations_ConfigPropertyMetadata);
@@ -928,62 +861,33 @@ function validateAdapterConfig$1(untrustedConfig, configPropertyNames) {
928
861
  }
929
862
  return config;
930
863
  }
931
- function adapterFragment(luvio, config) {
932
- createResourceParams$1(config);
933
- return select$2();
934
- }
935
- function onFetchResponseSuccess(luvio, config, resourceParams, response) {
936
- const snapshot = ingestSuccess$1(luvio, resourceParams, response, {
937
- config,
938
- resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
939
- });
940
- return luvio.storeBroadcast().then(() => snapshot);
941
- }
942
- function onFetchResponseError(luvio, config, resourceParams, response) {
943
- const snapshot = ingestError(luvio, resourceParams, response, {
944
- config,
945
- resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
946
- });
947
- return luvio.storeBroadcast().then(() => snapshot);
948
- }
949
864
  function buildNetworkSnapshot$1(luvio, config, options) {
950
865
  const resourceParams = createResourceParams$1(config);
951
866
  const request = createResourceRequest$1(resourceParams);
952
867
  return luvio.dispatchResourceRequest(request, options)
953
868
  .then((response) => {
954
- return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => {
869
+ return luvio.handleSuccessResponse(() => {
870
+ const snapshot = ingestSuccess$1(luvio, resourceParams, response);
871
+ return luvio.storeBroadcast().then(() => snapshot);
872
+ }, () => {
955
873
  const cache = new StoreKeyMap();
956
874
  getResponseCacheKeys$1(cache, luvio, resourceParams, response.body);
957
875
  return cache;
958
876
  });
959
877
  }, (response) => {
960
- return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
878
+ deepFreeze(response);
879
+ throw response;
961
880
  });
962
881
  }
963
- function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
964
- return buildNetworkSnapshotCachePolicy$1(context, coercedAdapterRequestContext, buildNetworkSnapshot$1, 'get', false);
965
- }
966
- function buildCachedSnapshotCachePolicy(context, storeLookup) {
967
- const { luvio, config } = context;
968
- const selector = {
969
- recordId: keyBuilder$1(luvio, config),
970
- node: adapterFragment(luvio, config),
971
- variables: {},
882
+ const getGenerationsAdapterFactory = (luvio) => {
883
+ return function getGenerations(untrustedConfig) {
884
+ const config = validateAdapterConfig$1(untrustedConfig, getGenerations_ConfigPropertyNames);
885
+ // Invalid or incomplete config
886
+ if (config === null) {
887
+ throw new Error('Invalid config for "getGenerations"');
888
+ }
889
+ return buildNetworkSnapshot$1(luvio, config);
972
890
  };
973
- const cacheSnapshot = storeLookup(selector, {
974
- config,
975
- resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
976
- });
977
- return cacheSnapshot;
978
- }
979
- const getGenerationsAdapterFactory = (luvio) => function einsteinAiGateway__getGenerations(untrustedConfig, requestContext) {
980
- const config = validateAdapterConfig$1(untrustedConfig, getGenerations_ConfigPropertyNames);
981
- // Invalid or incomplete config
982
- if (config === null) {
983
- return null;
984
- }
985
- return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
986
- buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
987
891
  };
988
892
 
989
893
  const TTL = 100;
@@ -1178,29 +1082,23 @@ const registerFeedbackAdapterFactory = (luvio) => {
1178
1082
 
1179
1083
  let getGenerations;
1180
1084
  let registerFeedback;
1181
- // Imperative GET Adapters
1182
- let getGenerations_imperative;
1183
- // Adapter Metadata
1184
- const getGenerationsMetadata = { apiFamily: 'einsteinai-gateway', name: 'getGenerations' };
1185
1085
  // Notify Update Available
1186
1086
  function bindExportsTo(luvio) {
1187
1087
  // LDS Adapters
1188
- const getGenerations_ldsAdapter = createInstrumentedAdapter(createLDSAdapter(luvio, 'getGenerations', getGenerationsAdapterFactory), getGenerationsMetadata);
1189
1088
  function unwrapSnapshotData(factory) {
1190
1089
  const adapter = factory(luvio);
1191
1090
  return (config) => adapter(config).then((snapshot) => snapshot.data);
1192
1091
  }
1193
1092
  return {
1194
- getGenerations: createWireAdapterConstructor(luvio, getGenerations_ldsAdapter, getGenerationsMetadata),
1093
+ getGenerations: unwrapSnapshotData(getGenerationsAdapterFactory),
1195
1094
  registerFeedback: unwrapSnapshotData(registerFeedbackAdapterFactory),
1196
1095
  // Imperative GET Adapters
1197
- getGenerations_imperative: createImperativeAdapter(luvio, getGenerations_ldsAdapter, getGenerationsMetadata),
1198
1096
  // Notify Update Availables
1199
1097
  };
1200
1098
  }
1201
1099
  withDefaultLuvio((luvio) => {
1202
- ({ getGenerations, registerFeedback, getGenerations_imperative } = bindExportsTo(luvio));
1100
+ ({ getGenerations, registerFeedback } = bindExportsTo(luvio));
1203
1101
  });
1204
1102
 
1205
- export { getGenerations, getGenerations_imperative, registerFeedback };
1206
- // version: 1.265.0-25488bd30
1103
+ export { getGenerations, registerFeedback };
1104
+ // version: 1.266.0-dev2-e69d357fb
@@ -10,6 +10,10 @@ uses:
10
10
  (luvio.ttl): 100
11
11
 
12
12
  types:
13
+ GenerationResponse:
14
+ (luvio.ttl): 100
15
+ (luvio.key):
16
+ id: id
13
17
  FeedbackResponseRepresentation:
14
18
  (luvio.ttl): 100
15
19
  (luvio.key):
@@ -17,7 +21,6 @@ types:
17
21
 
18
22
  /ai/gpt/v1/generations:
19
23
  post:
20
- (luvio.method): get
21
24
  (luvio.adapter):
22
25
  name: getGenerations
23
26