@memori.ai/memori-api-client 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -805,34 +805,26 @@ export declare type CustomWord = {
805
805
  lastChangeTimestamp: string;
806
806
  lastChangeSessionID: string;
807
807
  };
808
- export declare type ImportWarning = {
809
- warningType: 'Existing Similar Memory' | 'Internal Error';
810
- rowNumber?: number;
811
- csvRow: string;
812
- text?: string;
813
- similarTexts?: {
814
- text: string;
815
- similarityLevel: 'HIGH' | 'MEDIUM' | 'LOW';
816
- }[];
817
- };
818
- export declare type ImportReponse = {
819
- importID: string;
820
- importedMemories?: number;
821
- importWarnings?: ImportWarning[];
822
- };
823
- export declare type ImportCSVParams = {
824
- includedRows?: number[];
808
+ export interface ImportCSVParams {
825
809
  hasHeaders?: boolean;
826
810
  headerNames?: string[];
827
- forceImport?: boolean;
828
811
  questionColumnName: string;
829
812
  answerColumnName: string;
830
813
  contextVarsToMatchColumnName?: string;
831
814
  contextVarsToSetColumnName?: string;
832
815
  csvSeparator?: string;
833
816
  questionTitleVariantsSeparator?: string;
834
- };
835
- export declare type ExportCSVParams = {
817
+ }
818
+ export interface ImportTxtParams {
819
+ newLinesPerParagraphs?: number;
820
+ }
821
+ export interface ImportParams {
822
+ includedRows?: number[];
823
+ forceImport?: boolean;
824
+ csvSpecs?: ImportCSVParams;
825
+ txtSpecs?: ImportTxtParams;
826
+ }
827
+ export interface ExportCSVParams {
836
828
  newLine: '\n' | '\r\n';
837
829
  hasHeaders?: boolean;
838
830
  questionColumnName: string;
@@ -841,4 +833,65 @@ export declare type ExportCSVParams = {
841
833
  contextVarsToSetColumnName?: string;
842
834
  csvSeparator?: string;
843
835
  questionTitleVariantsSeparator?: string;
844
- };
836
+ }
837
+ export interface ImportWarning {
838
+ warningType: 'Existing Similar Memory' | 'Internal Error';
839
+ rowNumber?: number;
840
+ row: string;
841
+ text?: string;
842
+ similarTexts?: {
843
+ text: string;
844
+ similarityLevel: 'HIGH' | 'MEDIUM' | 'LOW';
845
+ }[];
846
+ }
847
+ export interface ImportReponse {
848
+ importID: string;
849
+ status: {
850
+ /**
851
+ * @type {string}
852
+ * minLength: 1
853
+ * Current status of the Import process (starting, running etc.).
854
+ * May be one of the following:
855
+ * - Starting: the Import process is preparing to start, but has not started yet. Will advance to Running automatically.
856
+ * - Running: the Import process has been started and is actively processing Memory objects.
857
+ * - Stopped: the Import process has been stopped manually, not all Memory objects may have been processed.
858
+ * - Completed: the Import process finished successfully, all the Memory objects have been processed.
859
+ * - Failed: the Import process terminated due to an unexpected error, not all Memory objects may have been processed.
860
+ */
861
+ status: 'Starting' | 'Running' | 'Stopped' | 'Completed' | 'Failed';
862
+ /**
863
+ * @type {string=}
864
+ * If the Status is Failed, reports the error that caused the Import process to fail. Null otherwise.
865
+ */
866
+ error?: string;
867
+ /**
868
+ * @type {number}
869
+ * Progress of the Import process as a fraction of 1.
870
+ */
871
+ progress: number;
872
+ /**
873
+ * @type {string=}
874
+ * Timestamp of start of the Import process. Null until the Import process is in Starting status.
875
+ */
876
+ begin?: string;
877
+ /**
878
+ * @type {string=}
879
+ * Timestamp of end of the Import process. Null until the Import process is in Starting or Running status.
880
+ */
881
+ end?: string;
882
+ /**
883
+ * @type {number=}
884
+ * Estimated time required to complete the Import process, in seconds.
885
+ */
886
+ eta?: number;
887
+ /**
888
+ * @type {number=}
889
+ * Number of Imported Memory objects so far.
890
+ */
891
+ importedMemories?: number;
892
+ /**
893
+ * List of Import Warning objects. May be empty.
894
+ */
895
+ importWarnings?: ImportWarning[];
896
+ };
897
+ }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.0",
2
+ "version": "1.2.0",
3
3
  "name": "@memori.ai/memori-api-client",
4
4
  "description": "React library to integrate a Memori in your app or website",
5
5
  "license": "Apache-2.0",
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  ResponseSpec,
3
3
  ImportReponse,
4
- ImportCSVParams,
5
4
  ExportCSVParams,
5
+ ImportParams,
6
6
  } from '../types';
7
7
  import { apiFetcher } from '../apiFetcher';
8
8
 
@@ -16,19 +16,55 @@ export default (apiUrl: string) => ({
16
16
  /**
17
17
  * Imports memories from a CSV file.
18
18
  * @param {string} sessionId The session ID
19
- * @param {string[]} csvRows Rows of the CSV file.
20
- * @param {ImportCSVParams} params The specifications and content of the CSV file
19
+ * @param {string[]} rows Rows of the CSV file.
20
+ * @param {ImportParams} params The specifications and content of the CSV file
21
21
  */
22
- importCSV: async (
22
+ importCSV: async (sessionId: string, rows: string[], params: ImportParams) =>
23
+ apiFetcher(`/ImportExport/ImportCSV/${sessionId}`, {
24
+ method: 'POST',
25
+ apiUrl,
26
+ body: {
27
+ rows,
28
+ ...params,
29
+ },
30
+ }) as Promise<ResponseSpec & ImportReponse>,
31
+
32
+ /**
33
+ * Gets the status of an ongoing Import process.
34
+ * @param {string} importID The import process ID
35
+ */
36
+ importStatus: async (importID: string) =>
37
+ apiFetcher(`/ImportExport/ImportStatus/${importID}`, {
38
+ method: 'GET',
39
+ apiUrl,
40
+ }) as Promise<ResponseSpec & ImportReponse>,
41
+
42
+ /**
43
+ * Interrupts an ongoing Import process.
44
+ * @param {string} importID The import process ID
45
+ */
46
+ stopImport: async (importID: string) =>
47
+ apiFetcher(`/ImportExport/StopImport/${importID}`, {
48
+ method: 'POST',
49
+ apiUrl,
50
+ }) as Promise<ResponseSpec & ImportReponse>,
51
+
52
+ /**
53
+ * Imports memories from a TXT file.
54
+ * @param {string} sessionId The session ID
55
+ * @param {string[]} rows Rows of the TXT file.
56
+ * @param {ImportCSVParams} params The specifications and content of the TXT file
57
+ */
58
+ importTXT: async (
23
59
  sessionId: string,
24
- csvRows: string[],
25
- params: ImportCSVParams
60
+ rows: string[],
61
+ params: Omit<ImportParams, 'csvSpecs'>
26
62
  ) =>
27
- apiFetcher(`/ImportExport/ImportCSV/${sessionId}`, {
63
+ apiFetcher(`/ImportExport/ImportTXT/${sessionId}`, {
28
64
  method: 'POST',
29
65
  apiUrl,
30
66
  body: {
31
- csvRows,
67
+ rows,
32
68
  ...params,
33
69
  },
34
70
  }) as Promise<ResponseSpec & ImportReponse>,
package/src/types.ts CHANGED
@@ -844,37 +844,28 @@ export type CustomWord = {
844
844
  lastChangeSessionID: string;
845
845
  };
846
846
 
847
- export type ImportWarning = {
848
- warningType: 'Existing Similar Memory' | 'Internal Error';
849
- rowNumber?: number;
850
- csvRow: string;
851
- text?: string;
852
- similarTexts?: {
853
- text: string;
854
- similarityLevel: 'HIGH' | 'MEDIUM' | 'LOW';
855
- }[];
856
- };
857
-
858
- export type ImportReponse = {
859
- importID: string;
860
- importedMemories?: number;
861
- importWarnings?: ImportWarning[];
862
- };
863
-
864
- export type ImportCSVParams = {
865
- includedRows?: number[];
847
+ export interface ImportCSVParams {
866
848
  hasHeaders?: boolean;
867
849
  headerNames?: string[];
868
- forceImport?: boolean;
869
850
  questionColumnName: string;
870
851
  answerColumnName: string;
871
852
  contextVarsToMatchColumnName?: string;
872
853
  contextVarsToSetColumnName?: string;
873
854
  csvSeparator?: string;
874
855
  questionTitleVariantsSeparator?: string;
875
- };
856
+ }
857
+
858
+ export interface ImportTxtParams {
859
+ newLinesPerParagraphs?: number;
860
+ }
876
861
 
877
- export type ExportCSVParams = {
862
+ export interface ImportParams {
863
+ includedRows?: number[];
864
+ forceImport?: boolean;
865
+ csvSpecs?: ImportCSVParams;
866
+ txtSpecs?: ImportTxtParams;
867
+ }
868
+ export interface ExportCSVParams {
878
869
  newLine: '\n' | '\r\n';
879
870
  hasHeaders?: boolean;
880
871
  questionColumnName: string;
@@ -883,4 +874,68 @@ export type ExportCSVParams = {
883
874
  contextVarsToSetColumnName?: string;
884
875
  csvSeparator?: string;
885
876
  questionTitleVariantsSeparator?: string;
886
- };
877
+ }
878
+
879
+ export interface ImportWarning {
880
+ warningType: 'Existing Similar Memory' | 'Internal Error';
881
+ rowNumber?: number;
882
+ row: string;
883
+ text?: string;
884
+ similarTexts?: {
885
+ text: string;
886
+ similarityLevel: 'HIGH' | 'MEDIUM' | 'LOW';
887
+ }[];
888
+ }
889
+
890
+ export interface ImportReponse {
891
+ importID: string;
892
+ status: {
893
+ /**
894
+ * @type {string}
895
+ * minLength: 1
896
+ * Current status of the Import process (starting, running etc.).
897
+ * May be one of the following:
898
+ * - Starting: the Import process is preparing to start, but has not started yet. Will advance to Running automatically.
899
+ * - Running: the Import process has been started and is actively processing Memory objects.
900
+ * - Stopped: the Import process has been stopped manually, not all Memory objects may have been processed.
901
+ * - Completed: the Import process finished successfully, all the Memory objects have been processed.
902
+ * - Failed: the Import process terminated due to an unexpected error, not all Memory objects may have been processed.
903
+ */
904
+ status: 'Starting' | 'Running' | 'Stopped' | 'Completed' | 'Failed';
905
+ /**
906
+ * @type {string=}
907
+ * If the Status is Failed, reports the error that caused the Import process to fail. Null otherwise.
908
+ */
909
+ error?: string;
910
+ /**
911
+ * @type {number}
912
+ * Progress of the Import process as a fraction of 1.
913
+ */
914
+ progress: number;
915
+ /**
916
+ * @type {string=}
917
+ * Timestamp of start of the Import process. Null until the Import process is in Starting status.
918
+ */
919
+ begin?: string;
920
+ /**
921
+ * @type {string=}
922
+ * Timestamp of end of the Import process. Null until the Import process is in Starting or Running status.
923
+ */
924
+ end?: string;
925
+ /**
926
+ * @type {number=}
927
+ * Estimated time required to complete the Import process, in seconds.
928
+ */
929
+ eta?: number;
930
+
931
+ /**
932
+ * @type {number=}
933
+ * Number of Imported Memory objects so far.
934
+ */
935
+ importedMemories?: number;
936
+ /**
937
+ * List of Import Warning objects. May be empty.
938
+ */
939
+ importWarnings?: ImportWarning[];
940
+ };
941
+ }