@getlupa/vue 0.7.1 → 0.7.3

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.
@@ -1745,12 +1745,12 @@ const escapeHtml = (value) => {
1745
1745
  });
1746
1746
  return output;
1747
1747
  };
1748
- const inputMatches = (input, possibleValues) => {
1748
+ const inputsAreEqual = (input, possibleValues) => {
1749
1749
  if (!input) {
1750
1750
  return false;
1751
1751
  }
1752
1752
  const normalizedInput = getNormalizedString(input);
1753
- return possibleValues.some((v) => getNormalizedString(v).startsWith(normalizedInput));
1753
+ return possibleValues.some((v) => getNormalizedString(v) === normalizedInput);
1754
1754
  };
1755
1755
  const initAnalyticsTracking = (analyticsOptions) => {
1756
1756
  try {
@@ -2757,7 +2757,7 @@ const useRedirectionStore = defineStore("redirections", () => {
2757
2757
  if (!((_b = (_a = redirections.value) == null ? void 0 : _a.rules) == null ? void 0 : _b.length)) {
2758
2758
  return false;
2759
2759
  }
2760
- const redirectTo = redirections.value.rules.find((r) => inputMatches(input, r.sources));
2760
+ const redirectTo = redirections.value.rules.find((r) => inputsAreEqual(input, r.sources));
2761
2761
  if (!redirectTo) {
2762
2762
  return false;
2763
2763
  }
@@ -16347,7 +16347,7 @@ const suggestSearchChatPhrases = (options, request, chatSettings) => __async(exp
16347
16347
  return { success: false, errors: [e] };
16348
16348
  }
16349
16349
  });
16350
- const suggestPhraseAlternatives = (_0, _1, _2) => __async(exports, [_0, _1, _2], function* (options, { phrases }, chatSettings) {
16350
+ const suggestPhraseAlternatives = (options, request, chatSettings) => __async(exports, null, function* () {
16351
16351
  var _a, _b, _c;
16352
16352
  const { environment, customBaseUrl } = options;
16353
16353
  const model = (chatSettings == null ? void 0 : chatSettings.model) ? `?model=${chatSettings.model}` : ``;
@@ -16355,7 +16355,7 @@ const suggestPhraseAlternatives = (_0, _1, _2) => __async(exports, [_0, _1, _2],
16355
16355
  const res = yield fetch(
16356
16356
  `${getApiUrl(environment, customBaseUrl)}chat/phraseAlternatives${model}`,
16357
16357
  __spreadProps(__spreadValues({}, defaultConfig), {
16358
- body: JSON.stringify({ phrases }),
16358
+ body: JSON.stringify(request),
16359
16359
  headers: __spreadValues(__spreadValues({}, headers), (_a = options.customHeaders) != null ? _a : {})
16360
16360
  })
16361
16361
  );
@@ -16371,38 +16371,13 @@ const suggestPhraseAlternatives = (_0, _1, _2) => __async(exports, [_0, _1, _2],
16371
16371
  return { success: false, errors: [e] };
16372
16372
  }
16373
16373
  });
16374
- const suggestSimplifiedPhrases = (_0, _1, _2) => __async(exports, [_0, _1, _2], function* (options, { phrases }, chatSettings) {
16375
- var _a, _b, _c;
16376
- const { environment, customBaseUrl } = options;
16377
- const model = (chatSettings == null ? void 0 : chatSettings.model) ? `?model=${chatSettings.model}` : ``;
16378
- try {
16379
- const res = yield fetch(`${getApiUrl(environment, customBaseUrl)}chat/simplify${model}`, __spreadProps(__spreadValues({}, defaultConfig), {
16380
- body: JSON.stringify({ phrases }),
16381
- headers: __spreadValues(__spreadValues({}, headers), (_a = options.customHeaders) != null ? _a : {})
16382
- }));
16383
- if (res.status < 400) {
16384
- const data = yield res.json();
16385
- return __spreadProps(__spreadValues({}, data), { success: true });
16386
- }
16387
- const errors = yield res.json();
16388
- (_b = options == null ? void 0 : options.onError) == null ? void 0 : _b.call(options, errors);
16389
- return { success: false, errors };
16390
- } catch (e) {
16391
- (_c = options == null ? void 0 : options.onError) == null ? void 0 : _c.call(options, e);
16392
- return { success: false, errors: [e] };
16393
- }
16394
- });
16395
- const suggestBestProductMatches = (_0, _1, _2) => __async(exports, [_0, _1, _2], function* (options, {
16396
- initialQuery,
16397
- productStrings,
16398
- messageHistory
16399
- }, chatSettings) {
16374
+ const suggestBestProductMatches = (options, request, chatSettings) => __async(exports, null, function* () {
16400
16375
  var _a, _b, _c;
16401
16376
  const { environment, customBaseUrl } = options;
16402
16377
  const model = (chatSettings == null ? void 0 : chatSettings.model) ? `?model=${chatSettings.model}` : ``;
16403
16378
  try {
16404
16379
  const res = yield fetch(`${getApiUrl(environment, customBaseUrl)}chat/bestProducts${model}`, __spreadProps(__spreadValues({}, defaultConfig), {
16405
- body: JSON.stringify({ initialQuery, messageHistory, productStrings }),
16380
+ body: JSON.stringify(request),
16406
16381
  headers: __spreadValues(__spreadValues({}, headers), (_a = options.customHeaders) != null ? _a : {})
16407
16382
  }));
16408
16383
  if (res.status < 400) {
@@ -16438,11 +16413,11 @@ const prepareChatHistory = (chatLog) => {
16438
16413
  }
16439
16414
  return history;
16440
16415
  };
16441
- const getTextResponseChunkStream = (options, { initialQuery, messageHistory }, onChunkReceived, chatSettings) => {
16416
+ const getTextResponseChunkStream = (options, request, onChunkReceived, chatSettings) => {
16442
16417
  var _a;
16443
16418
  const model = (chatSettings == null ? void 0 : chatSettings.model) ? `?model=${chatSettings.model}` : ``;
16444
16419
  fetch(`${getApiUrl(options.environment, options.customBaseUrl)}chat/text${model}`, __spreadProps(__spreadValues({}, defaultConfig), {
16445
- body: JSON.stringify({ initialQuery, messageHistory }),
16420
+ body: JSON.stringify(request),
16446
16421
  headers: __spreadValues(__spreadValues({}, headers), (_a = options.customHeaders) != null ? _a : {})
16447
16422
  })).then((response) => {
16448
16423
  const reader = response.body.getReader();
@@ -16462,7 +16437,6 @@ const getTextResponseChunkStream = (options, { initialQuery, messageHistory }, o
16462
16437
  const ChatService = {
16463
16438
  suggestSearchChatPhrases,
16464
16439
  suggestPhraseAlternatives,
16465
- suggestSimplifiedPhrases,
16466
16440
  suggestBestProductMatches,
16467
16441
  prepareChatHistory,
16468
16442
  getTextResponseChunkStream
@@ -16584,7 +16558,8 @@ const _sfc_main$4 = /* @__PURE__ */ vue.defineComponent({
16584
16558
  const { phrases } = yield ChatService.suggestPhraseAlternatives(
16585
16559
  props.options.sdkOptions,
16586
16560
  {
16587
- phrases: [props.phrase]
16561
+ phrases: [props.phrase],
16562
+ queryKey: props.options.displayOptions.queryKey
16588
16563
  },
16589
16564
  props.options.chatSettings
16590
16565
  );
@@ -16657,7 +16632,8 @@ const _sfc_main$3 = /* @__PURE__ */ vue.defineComponent({
16657
16632
  {
16658
16633
  initialQuery: props.entry.userInput,
16659
16634
  productStrings: productResultStrings,
16660
- messageHistory: (_a = props.history) != null ? _a : []
16635
+ messageHistory: (_a = props.history) != null ? _a : [],
16636
+ queryKey: props.options.displayOptions.queryKey
16661
16637
  },
16662
16638
  props.options.chatSettings
16663
16639
  );
@@ -16731,7 +16707,8 @@ const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
16731
16707
  props.options.sdkOptions,
16732
16708
  {
16733
16709
  initialQuery: props.content,
16734
- messageHistory: (_a = props.history) != null ? _a : []
16710
+ messageHistory: (_a = props.history) != null ? _a : [],
16711
+ queryKey: props.options.displayOptions.queryKey
16735
16712
  },
16736
16713
  processChunk,
16737
16714
  props.options.chatSettings
@@ -1743,12 +1743,12 @@ const escapeHtml = (value) => {
1743
1743
  });
1744
1744
  return output;
1745
1745
  };
1746
- const inputMatches = (input, possibleValues) => {
1746
+ const inputsAreEqual = (input, possibleValues) => {
1747
1747
  if (!input) {
1748
1748
  return false;
1749
1749
  }
1750
1750
  const normalizedInput = getNormalizedString(input);
1751
- return possibleValues.some((v) => getNormalizedString(v).startsWith(normalizedInput));
1751
+ return possibleValues.some((v) => getNormalizedString(v) === normalizedInput);
1752
1752
  };
1753
1753
  const initAnalyticsTracking = (analyticsOptions) => {
1754
1754
  try {
@@ -2755,7 +2755,7 @@ const useRedirectionStore = defineStore("redirections", () => {
2755
2755
  if (!((_b = (_a = redirections.value) == null ? void 0 : _a.rules) == null ? void 0 : _b.length)) {
2756
2756
  return false;
2757
2757
  }
2758
- const redirectTo = redirections.value.rules.find((r) => inputMatches(input, r.sources));
2758
+ const redirectTo = redirections.value.rules.find((r) => inputsAreEqual(input, r.sources));
2759
2759
  if (!redirectTo) {
2760
2760
  return false;
2761
2761
  }
@@ -16345,7 +16345,7 @@ const suggestSearchChatPhrases = (options, request, chatSettings) => __async(voi
16345
16345
  return { success: false, errors: [e] };
16346
16346
  }
16347
16347
  });
16348
- const suggestPhraseAlternatives = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (options, { phrases }, chatSettings) {
16348
+ const suggestPhraseAlternatives = (options, request, chatSettings) => __async(void 0, null, function* () {
16349
16349
  var _a, _b, _c;
16350
16350
  const { environment, customBaseUrl } = options;
16351
16351
  const model = (chatSettings == null ? void 0 : chatSettings.model) ? `?model=${chatSettings.model}` : ``;
@@ -16353,7 +16353,7 @@ const suggestPhraseAlternatives = (_0, _1, _2) => __async(void 0, [_0, _1, _2],
16353
16353
  const res = yield fetch(
16354
16354
  `${getApiUrl(environment, customBaseUrl)}chat/phraseAlternatives${model}`,
16355
16355
  __spreadProps(__spreadValues({}, defaultConfig), {
16356
- body: JSON.stringify({ phrases }),
16356
+ body: JSON.stringify(request),
16357
16357
  headers: __spreadValues(__spreadValues({}, headers), (_a = options.customHeaders) != null ? _a : {})
16358
16358
  })
16359
16359
  );
@@ -16369,38 +16369,13 @@ const suggestPhraseAlternatives = (_0, _1, _2) => __async(void 0, [_0, _1, _2],
16369
16369
  return { success: false, errors: [e] };
16370
16370
  }
16371
16371
  });
16372
- const suggestSimplifiedPhrases = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (options, { phrases }, chatSettings) {
16373
- var _a, _b, _c;
16374
- const { environment, customBaseUrl } = options;
16375
- const model = (chatSettings == null ? void 0 : chatSettings.model) ? `?model=${chatSettings.model}` : ``;
16376
- try {
16377
- const res = yield fetch(`${getApiUrl(environment, customBaseUrl)}chat/simplify${model}`, __spreadProps(__spreadValues({}, defaultConfig), {
16378
- body: JSON.stringify({ phrases }),
16379
- headers: __spreadValues(__spreadValues({}, headers), (_a = options.customHeaders) != null ? _a : {})
16380
- }));
16381
- if (res.status < 400) {
16382
- const data = yield res.json();
16383
- return __spreadProps(__spreadValues({}, data), { success: true });
16384
- }
16385
- const errors = yield res.json();
16386
- (_b = options == null ? void 0 : options.onError) == null ? void 0 : _b.call(options, errors);
16387
- return { success: false, errors };
16388
- } catch (e) {
16389
- (_c = options == null ? void 0 : options.onError) == null ? void 0 : _c.call(options, e);
16390
- return { success: false, errors: [e] };
16391
- }
16392
- });
16393
- const suggestBestProductMatches = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (options, {
16394
- initialQuery,
16395
- productStrings,
16396
- messageHistory
16397
- }, chatSettings) {
16372
+ const suggestBestProductMatches = (options, request, chatSettings) => __async(void 0, null, function* () {
16398
16373
  var _a, _b, _c;
16399
16374
  const { environment, customBaseUrl } = options;
16400
16375
  const model = (chatSettings == null ? void 0 : chatSettings.model) ? `?model=${chatSettings.model}` : ``;
16401
16376
  try {
16402
16377
  const res = yield fetch(`${getApiUrl(environment, customBaseUrl)}chat/bestProducts${model}`, __spreadProps(__spreadValues({}, defaultConfig), {
16403
- body: JSON.stringify({ initialQuery, messageHistory, productStrings }),
16378
+ body: JSON.stringify(request),
16404
16379
  headers: __spreadValues(__spreadValues({}, headers), (_a = options.customHeaders) != null ? _a : {})
16405
16380
  }));
16406
16381
  if (res.status < 400) {
@@ -16436,11 +16411,11 @@ const prepareChatHistory = (chatLog) => {
16436
16411
  }
16437
16412
  return history;
16438
16413
  };
16439
- const getTextResponseChunkStream = (options, { initialQuery, messageHistory }, onChunkReceived, chatSettings) => {
16414
+ const getTextResponseChunkStream = (options, request, onChunkReceived, chatSettings) => {
16440
16415
  var _a;
16441
16416
  const model = (chatSettings == null ? void 0 : chatSettings.model) ? `?model=${chatSettings.model}` : ``;
16442
16417
  fetch(`${getApiUrl(options.environment, options.customBaseUrl)}chat/text${model}`, __spreadProps(__spreadValues({}, defaultConfig), {
16443
- body: JSON.stringify({ initialQuery, messageHistory }),
16418
+ body: JSON.stringify(request),
16444
16419
  headers: __spreadValues(__spreadValues({}, headers), (_a = options.customHeaders) != null ? _a : {})
16445
16420
  })).then((response) => {
16446
16421
  const reader = response.body.getReader();
@@ -16460,7 +16435,6 @@ const getTextResponseChunkStream = (options, { initialQuery, messageHistory }, o
16460
16435
  const ChatService = {
16461
16436
  suggestSearchChatPhrases,
16462
16437
  suggestPhraseAlternatives,
16463
- suggestSimplifiedPhrases,
16464
16438
  suggestBestProductMatches,
16465
16439
  prepareChatHistory,
16466
16440
  getTextResponseChunkStream
@@ -16582,7 +16556,8 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
16582
16556
  const { phrases } = yield ChatService.suggestPhraseAlternatives(
16583
16557
  props.options.sdkOptions,
16584
16558
  {
16585
- phrases: [props.phrase]
16559
+ phrases: [props.phrase],
16560
+ queryKey: props.options.displayOptions.queryKey
16586
16561
  },
16587
16562
  props.options.chatSettings
16588
16563
  );
@@ -16655,7 +16630,8 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
16655
16630
  {
16656
16631
  initialQuery: props.entry.userInput,
16657
16632
  productStrings: productResultStrings,
16658
- messageHistory: (_a = props.history) != null ? _a : []
16633
+ messageHistory: (_a = props.history) != null ? _a : [],
16634
+ queryKey: props.options.displayOptions.queryKey
16659
16635
  },
16660
16636
  props.options.chatSettings
16661
16637
  );
@@ -16729,7 +16705,8 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
16729
16705
  props.options.sdkOptions,
16730
16706
  {
16731
16707
  initialQuery: props.content,
16732
- messageHistory: (_a = props.history) != null ? _a : []
16708
+ messageHistory: (_a = props.history) != null ? _a : [],
16709
+ queryKey: props.options.displayOptions.queryKey
16733
16710
  },
16734
16711
  processChunk,
16735
16712
  props.options.chatSettings
@@ -1,5 +1,5 @@
1
1
  import { SdkOptions } from '..';
2
- import { ChatMessage, SearchChatRequest } from '../types/chat/SearchChatRequest';
2
+ import { ChatMessage, SearchChatBestProductMatchesRequest, SearchChatPraseAlternativesRequest, SearchChatRequest, SearchChatTextRequest } from '../types/chat/SearchChatRequest';
3
3
  import { SearchChatResponse } from '../types/chat/SearchChatResponse';
4
4
  import { ChatContent } from '../types/chat/ChatLog';
5
5
  import { ChatSettings } from '../types/chat/ChatOptions';
@@ -8,31 +8,16 @@ declare const _default: {
8
8
  success: boolean;
9
9
  errors: any;
10
10
  }>;
11
- suggestPhraseAlternatives: (options: SdkOptions, { phrases }: {
12
- phrases: string[];
13
- }, chatSettings?: ChatSettings) => Promise<Partial<SearchChatResponse> & {
11
+ suggestPhraseAlternatives: (options: SdkOptions, request: SearchChatPraseAlternativesRequest, chatSettings?: ChatSettings) => Promise<Partial<SearchChatResponse> & {
14
12
  success: boolean;
15
13
  errors: any;
16
14
  }>;
17
- suggestSimplifiedPhrases: (options: SdkOptions, { phrases }: {
18
- phrases: string[];
19
- }, chatSettings?: ChatSettings) => Promise<Partial<SearchChatResponse> & {
20
- success: boolean;
21
- errors: any;
22
- }>;
23
- suggestBestProductMatches: (options: SdkOptions, { initialQuery, productStrings, messageHistory }: {
24
- initialQuery: string;
25
- productStrings: string[];
26
- messageHistory: ChatMessage[];
27
- }, chatSettings?: ChatSettings) => Promise<{
15
+ suggestBestProductMatches: (options: SdkOptions, request: SearchChatBestProductMatchesRequest, chatSettings?: ChatSettings) => Promise<{
28
16
  products?: string[];
29
17
  success: boolean;
30
18
  errors: any;
31
19
  }>;
32
20
  prepareChatHistory: (chatLog: ChatContent[]) => ChatMessage[];
33
- getTextResponseChunkStream: (options: SdkOptions, { initialQuery, messageHistory }: {
34
- initialQuery: string;
35
- messageHistory: ChatMessage[];
36
- }, onChunkReceived: (chunk: string) => void, chatSettings?: ChatSettings) => void;
21
+ getTextResponseChunkStream: (options: SdkOptions, request: SearchChatTextRequest, onChunkReceived: (chunk: string) => void, chatSettings?: ChatSettings) => void;
37
22
  };
38
23
  export default _default;
@@ -2,8 +2,22 @@ export type ChatMessage = {
2
2
  role: 'user' | 'assistant';
3
3
  content: string;
4
4
  };
5
- export type SearchChatRequest = {
5
+ export type SearchChatRequestBase = {
6
+ queryKey: string;
7
+ };
8
+ export type SearchChatRequest = SearchChatRequestBase & {
6
9
  userPrompt: string;
7
10
  messageHistory: ChatMessage[];
8
- queryKey: string;
11
+ };
12
+ export type SearchChatPraseAlternativesRequest = SearchChatRequestBase & {
13
+ phrases: string[];
14
+ };
15
+ export type SearchChatBestProductMatchesRequest = SearchChatRequestBase & {
16
+ initialQuery: string;
17
+ productStrings: string[];
18
+ messageHistory: ChatMessage[];
19
+ };
20
+ export type SearchChatTextRequest = SearchChatRequestBase & {
21
+ initialQuery: string;
22
+ messageHistory: ChatMessage[];
9
23
  };
@@ -8,3 +8,4 @@ export declare const getProductKey: (index: string, product: Document, idKey: st
8
8
  export declare const normalizeFloat: (value?: string) => number;
9
9
  export declare const escapeHtml: (value?: string) => string;
10
10
  export declare const inputMatches: (input: string, possibleValues: string[]) => boolean;
11
+ export declare const inputsAreEqual: (input: string, possibleValues: string[]) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getlupa/vue",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "main": "dist/lupaSearch.js",
5
5
  "module": "dist/lupaSearch.mjs",
6
6
  "types": "dist/src/index.d.ts",