@memori.ai/memori-api-client 0.1.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.
Files changed (70) hide show
  1. package/LICENSE +18 -0
  2. package/README.md +188 -0
  3. package/dist/apiFetcher.d.ts +13 -0
  4. package/dist/backend/asset.d.ts +44 -0
  5. package/dist/backend/integration.d.ts +55 -0
  6. package/dist/backend/invitation.d.ts +82 -0
  7. package/dist/backend/memori.d.ts +125 -0
  8. package/dist/backend/user.d.ts +109 -0
  9. package/dist/backend.d.ts +273 -0
  10. package/dist/constants.d.ts +2 -0
  11. package/dist/engine/correlationPairs.d.ts +20 -0
  12. package/dist/engine/dialog.d.ts +88 -0
  13. package/dist/engine/importExport.d.ts +34 -0
  14. package/dist/engine/intents.d.ts +65 -0
  15. package/dist/engine/localizationKeys.d.ts +50 -0
  16. package/dist/engine/media.d.ts +48 -0
  17. package/dist/engine/memori.d.ts +30 -0
  18. package/dist/engine/memories.d.ts +50 -0
  19. package/dist/engine/nlp.d.ts +25 -0
  20. package/dist/engine/people.d.ts +46 -0
  21. package/dist/engine/promptedQuestions.d.ts +37 -0
  22. package/dist/engine/search.d.ts +30 -0
  23. package/dist/engine/session.d.ts +28 -0
  24. package/dist/engine/stats.d.ts +25 -0
  25. package/dist/engine/unansweredQuestions.d.ts +22 -0
  26. package/dist/engine/webhooks.d.ts +21 -0
  27. package/dist/engine.d.ts +297 -0
  28. package/dist/helpers/asset.d.ts +20 -0
  29. package/dist/helpers/getApiUrl.d.ts +1 -0
  30. package/dist/index.d.ts +582 -0
  31. package/dist/index.js +8 -0
  32. package/dist/memori-api-client.cjs.development.js +3666 -0
  33. package/dist/memori-api-client.cjs.development.js.map +1 -0
  34. package/dist/memori-api-client.cjs.production.min.js +2 -0
  35. package/dist/memori-api-client.cjs.production.min.js.map +1 -0
  36. package/dist/memori-api-client.esm.js +3660 -0
  37. package/dist/memori-api-client.esm.js.map +1 -0
  38. package/dist/speech.d.ts +10 -0
  39. package/dist/types.d.ts +410 -0
  40. package/package.json +125 -0
  41. package/src/apiFetcher.ts +29 -0
  42. package/src/backend/asset.ts +86 -0
  43. package/src/backend/integration.ts +98 -0
  44. package/src/backend/invitation.ts +115 -0
  45. package/src/backend/memori.ts +223 -0
  46. package/src/backend/user.ts +186 -0
  47. package/src/backend.ts +20 -0
  48. package/src/constants.ts +21 -0
  49. package/src/engine/correlationPairs.ts +31 -0
  50. package/src/engine/dialog.ts +158 -0
  51. package/src/engine/importExport.ts +43 -0
  52. package/src/engine/intents.ts +116 -0
  53. package/src/engine/localizationKeys.ts +94 -0
  54. package/src/engine/media.ts +79 -0
  55. package/src/engine/memori.ts +51 -0
  56. package/src/engine/memories.ts +89 -0
  57. package/src/engine/nlp.ts +39 -0
  58. package/src/engine/people.ts +82 -0
  59. package/src/engine/promptedQuestions.ts +63 -0
  60. package/src/engine/search.ts +49 -0
  61. package/src/engine/session.ts +49 -0
  62. package/src/engine/stats.ts +44 -0
  63. package/src/engine/unansweredQuestions.ts +38 -0
  64. package/src/engine/webhooks.ts +32 -0
  65. package/src/engine.ts +51 -0
  66. package/src/helpers/asset.ts +52 -0
  67. package/src/helpers/getApiUrl.ts +6 -0
  68. package/src/index.ts +20 -0
  69. package/src/speech.ts +242 -0
  70. package/src/types.ts +440 -0
@@ -0,0 +1,82 @@
1
+ import { ResponseSpec, Person } from '../types';
2
+ import { apiFetcher } from '../apiFetcher';
3
+
4
+ /******************
5
+ * *
6
+ * People *
7
+ * *
8
+ ******************/
9
+
10
+ export default (apiUrl: string) => ({
11
+ /**
12
+ * Lists all Person objects.
13
+ * @param {string} sessionId The session ID
14
+ */
15
+ getPeople: async (sessionId: string) =>
16
+ apiFetcher(`/People/${sessionId}`, {
17
+ method: 'GET',
18
+ apiUrl,
19
+ }) as Promise<
20
+ ResponseSpec & {
21
+ people: Person[];
22
+ }
23
+ >,
24
+
25
+ /**
26
+ * Gets the details of a Person object.
27
+ * @param {string} sessionId The session ID
28
+ * @param {string} personId The Person object ID
29
+ */
30
+ getPerson: async (sessionId: string, personId: string) =>
31
+ apiFetcher(`/Person/${sessionId}/${personId}`, {
32
+ method: 'GET',
33
+ apiUrl,
34
+ }) as Promise<
35
+ ResponseSpec & {
36
+ person: Person;
37
+ }
38
+ >,
39
+
40
+ /**
41
+ * Updates an existing Person object.
42
+ * @param {string} sessionId The session ID
43
+ * @param {Person} person The Person object
44
+ */
45
+ patchPerson: async (sessionId: string, person: Person) =>
46
+ apiFetcher(`/Person/${sessionId}/${person.personID!}`, {
47
+ method: 'PATCH',
48
+ body: person,
49
+ apiUrl,
50
+ }) as Promise<
51
+ ResponseSpec & {
52
+ person: Person;
53
+ }
54
+ >,
55
+
56
+ /**
57
+ * Removes an existing Person object.
58
+ * @param {string} sessionId The session ID
59
+ * @param {string} personId The Person object ID
60
+ */
61
+ deletePerson: async (sessionId: string, personId: string) =>
62
+ apiFetcher(`/Person/${sessionId}/${personId}`, {
63
+ method: 'DELETE',
64
+ apiUrl,
65
+ }) as Promise<ResponseSpec>,
66
+
67
+ /**
68
+ * Adds a new Person object.
69
+ * @param {string} sessionId - The session ID
70
+ * @param {Person} person - The Person object
71
+ */
72
+ postPerson: async (sessionId: string, person: Person) =>
73
+ apiFetcher(`/Person/${sessionId}`, {
74
+ method: 'POST',
75
+ body: person,
76
+ apiUrl,
77
+ }) as Promise<
78
+ ResponseSpec & {
79
+ person: Person;
80
+ }
81
+ >,
82
+ });
@@ -0,0 +1,63 @@
1
+ import { ResponseSpec } from '../types';
2
+ import { apiFetcher } from '../apiFetcher';
3
+
4
+ /*****************************
5
+ * *
6
+ * PromptedQuestions *
7
+ * *
8
+ *****************************/
9
+
10
+ export default (apiUrl: string) => ({
11
+ /**
12
+ * Lists all Prompted Question objects.
13
+ * @param {string} sessionId The session ID
14
+ */
15
+ getPromptedQuestions: async (sessionId: string) =>
16
+ apiFetcher(`/PromptedQuestions/${sessionId}`, {
17
+ method: 'GET',
18
+ apiUrl,
19
+ }) as Promise<ResponseSpec>,
20
+
21
+ /**
22
+ * Gets the details of a Prompted Question object.
23
+ * @param {string} sessionId The session ID
24
+ * @param {string} promptId The Prompted Question object ID
25
+ */
26
+ getPromptedQuestion: async (sessionId: string, promptId: string) =>
27
+ apiFetcher(`/PromptedQuestion/${sessionId}/${promptId}`, {
28
+ method: 'GET',
29
+ apiUrl,
30
+ }) as Promise<ResponseSpec>,
31
+
32
+ /**
33
+ * Updates an existing Prompted Question object.
34
+ * @param {string} sessionId The session ID
35
+ * @param {string} promptId The Prompted Question object ID
36
+ */
37
+ patchPromptedQuestion: async (sessionId: string, promptId: string) =>
38
+ apiFetcher(`/PromptedQuestion/${sessionId}/${promptId}`, {
39
+ method: 'GET',
40
+ apiUrl,
41
+ }) as Promise<ResponseSpec>,
42
+
43
+ /**
44
+ * Removes an existing Prompted Question object.
45
+ * @param {string} sessionId The session ID
46
+ * @param {string} promptId The Prompted Question object ID
47
+ */
48
+ deletePromptedQuestion: async (sessionId: string, promptId: string) =>
49
+ apiFetcher(`/PromptedQuestion/${sessionId}/${promptId}`, {
50
+ method: 'GET',
51
+ apiUrl,
52
+ }) as Promise<ResponseSpec>,
53
+
54
+ /**
55
+ * Adds a new Prompted Question object.
56
+ * @param {string} sessionId The session ID
57
+ */
58
+ postPromptedQuestion: async (sessionId: string) =>
59
+ apiFetcher(`/PromptedQuestion/${sessionId}`, {
60
+ method: 'GET',
61
+ apiUrl,
62
+ }) as Promise<ResponseSpec>,
63
+ });
@@ -0,0 +1,49 @@
1
+ import { ResponseSpec, SearchQuery, SearchMatches } from '../types';
2
+ import { apiFetcher } from '../apiFetcher';
3
+
4
+ /******************
5
+ * *
6
+ * Search *
7
+ * *
8
+ ******************/
9
+
10
+ export default (apiUrl: string) => ({
11
+ /**
12
+ * Searches for matching Memory objects using the same algorithm employed in the Text Entered event of the R1 state of the Dialog State Machine.
13
+ * @param {string} sessionId The session ID
14
+ * @param {SearchQuery} query Search query params
15
+ */
16
+ searchMemory: async (sessionId: string, query?: SearchQuery) =>
17
+ apiFetcher(`/Search/${sessionId}`, {
18
+ method: 'POST',
19
+ body: query,
20
+ apiUrl,
21
+ }) as Promise<
22
+ ResponseSpec & {
23
+ matches: SearchMatches[];
24
+ }
25
+ >,
26
+
27
+ /**
28
+ * Picks up to 5 random Memory objects using the same algorithm employed in the
29
+ * Timeout event of the R1 state of the Dialog State Machine.
30
+ * @param {string} sessionId The session ID
31
+ */
32
+ postRandom: async (sessionId: string) =>
33
+ apiFetcher(`/Random/${sessionId}`, {
34
+ method: 'POST',
35
+ apiUrl,
36
+ }) as Promise<ResponseSpec>,
37
+
38
+ /**
39
+ * Picks up to 20 Memory Hint objects, obtained by searching for Story objects with a date or place set,
40
+ * and clustering dates and places within an uncertainty of at least 1 year or at least 100 km.
41
+ * Each Memory Hint may either suggest a date or a place, but not both.
42
+ * @param {string} sessionId The session ID
43
+ */
44
+ postHints: async (sessionId: string) =>
45
+ apiFetcher(`/Hints/${sessionId}`, {
46
+ method: 'GET',
47
+ apiUrl,
48
+ }) as Promise<ResponseSpec>,
49
+ });
@@ -0,0 +1,49 @@
1
+ import { ResponseSpec, OpenSession, DialogState } from '../types';
2
+ import { apiFetcher } from '../apiFetcher';
3
+
4
+ /*******************
5
+ * *
6
+ * Session *
7
+ * *
8
+ *******************/
9
+
10
+ export default (apiUrl: string) => ({
11
+ /**
12
+ * Initializes a new Dialog State Machine session for an existing Memori.
13
+ */
14
+ initSession: async (params: OpenSession) =>
15
+ apiFetcher(`/Session`, {
16
+ method: 'POST',
17
+ body: params,
18
+ apiUrl,
19
+ }) as Promise<
20
+ ResponseSpec & {
21
+ sessionID: string;
22
+ currentState: DialogState;
23
+ }
24
+ >,
25
+
26
+ /**
27
+ * Returns the current state of a session's Dialog State Machine.
28
+ * @param {string} sessionId The session ID
29
+ */
30
+ getSession: async (sessionId: string) =>
31
+ apiFetcher(`/Session/${sessionId}`, {
32
+ method: 'GET',
33
+ apiUrl,
34
+ }) as Promise<
35
+ ResponseSpec & {
36
+ currentState: DialogState;
37
+ }
38
+ >,
39
+
40
+ /**
41
+ * Closes the session and disposes of its Dialog State Machine.
42
+ * @param {string} sessionId The session ID
43
+ */
44
+ deleteSession: async (sessionId: string) =>
45
+ apiFetcher(`/Session/${sessionId}`, {
46
+ method: 'DELETE',
47
+ apiUrl,
48
+ }) as Promise<ResponseSpec>,
49
+ });
@@ -0,0 +1,44 @@
1
+ import { ResponseSpec, Stats, EventLog } from '../types';
2
+ import { apiFetcher } from '../apiFetcher';
3
+
4
+ /*****************
5
+ * *
6
+ * Stats *
7
+ * *
8
+ *****************/
9
+
10
+ export default (apiUrl: string) => ({
11
+ /**
12
+ * Computes usage statistics for the Memori of the current session.
13
+ * @param {string} sessionId The session ID
14
+ */
15
+ getStatistics: async (sessionId: string) =>
16
+ apiFetcher(`/Statistics/${sessionId}`, {
17
+ method: 'GET',
18
+ apiUrl,
19
+ }) as Promise<
20
+ ResponseSpec & {
21
+ statistics: Stats;
22
+ }
23
+ >,
24
+
25
+ /**
26
+ * Get the Event Log objects for the Memori of the current session in a specific date interval
27
+ * @param {string} sessionId The session ID
28
+ * @param {string} strDateFrom The optional begin of the date interval, in UTC time, in the format yyyyMMddHHmmssfff
29
+ * @param {string} strDateTo The optional end of the date interval, in UTC time, in the format yyyyMMddHHmmssfff
30
+ */
31
+ getEventLogs: async (
32
+ sessionId: string,
33
+ strDateFrom: string,
34
+ strDateTo: string
35
+ ) =>
36
+ apiFetcher(`/EventLogs/${sessionId}/${strDateFrom}/${strDateTo}`, {
37
+ method: 'GET',
38
+ apiUrl,
39
+ }) as Promise<
40
+ ResponseSpec & {
41
+ eventLogs: EventLog[];
42
+ }
43
+ >,
44
+ });
@@ -0,0 +1,38 @@
1
+ import { ResponseSpec, UnansweredQuestion } from '../types';
2
+ import { apiFetcher } from '../apiFetcher';
3
+
4
+ /*******************************
5
+ * *
6
+ * UnansweredQuestions *
7
+ * *
8
+ *******************************/
9
+
10
+ export default (apiUrl: string) => ({
11
+ /**
12
+ * Lists all Unanswered Question objects.
13
+ * @param {string} sessionId The session ID
14
+ */
15
+ getUnansweredQuestions: async (sessionId: string) =>
16
+ apiFetcher(`/UnansweredQuestions/${sessionId}`, {
17
+ method: 'GET',
18
+ apiUrl,
19
+ }) as Promise<
20
+ ResponseSpec & {
21
+ unansweredQuestions: UnansweredQuestion[];
22
+ }
23
+ >,
24
+
25
+ /**
26
+ * Removes an existing Unanswered Question object.
27
+ * @param {string} sessionId The session ID
28
+ * @param {string} unansweredQuestionId The Unanswered Question object ID
29
+ */
30
+ deleteUnansweredQuestion: async (
31
+ sessionId: string,
32
+ unansweredQuestionId: string
33
+ ) =>
34
+ apiFetcher(`/UnansweredQuestion/${sessionId}/${unansweredQuestionId}`, {
35
+ method: 'DELETE',
36
+ apiUrl,
37
+ }) as Promise<ResponseSpec>,
38
+ });
@@ -0,0 +1,32 @@
1
+ import { ResponseSpec } from '../types';
2
+ import { apiFetcher } from '../apiFetcher';
3
+
4
+ /********************
5
+ * *
6
+ * WebHooks *
7
+ * *
8
+ ********************/
9
+
10
+ export default (apiUrl: string) => ({
11
+ /**
12
+ * Returns test slot values. Currently available test slots are:<ul><li><code>number</code>: integer numbers between 1 and 10</li><li><code>letter</code>: uppercase letters between A and Z</li><li><code>greek_letter</code>: capitalized Greek letters between Alpha and Omega</li></ul>
13
+ */
14
+ postTestSlot: async () =>
15
+ apiFetcher(`/TestSlot`, {
16
+ method: 'GET',
17
+ apiUrl,
18
+ }) as Promise<ResponseSpec>,
19
+
20
+ /**
21
+ * Returns test intent results. Currently available test intents are:<ul><li><code>ECHO</code>: emits the intent utterance as-is.</li><li><code>COMBINE_LETTER_AND_NUMBER</code>: requires a letter slot and a number slot,
22
+ emits the content of the two slots in justaxposition, e.g. "A10".</li><li><code>DATE_RANGE</code>: requires a date slot, emits the date range indicated
23
+ by the date slot in the format "yyyy/MM/dd - yyyy/MM/dd".</li><li><code>AUTOINCREMENT</code>: returns a progressive number that increments by 1
24
+ each time the intent is called.</li><li><code>FIBONACCI</code>: returns the next element of the Fibonacci series, using
25
+ context variables to store the series progression.</li></ul>
26
+ */
27
+ postTestIntent: async () =>
28
+ apiFetcher(`/TestIntent`, {
29
+ method: 'GET',
30
+ apiUrl,
31
+ }) as Promise<ResponseSpec>,
32
+ });
package/src/engine.ts ADDED
@@ -0,0 +1,51 @@
1
+ import correlationPairs from './engine/correlationPairs';
2
+ import dialog from './engine/dialog';
3
+ import importExport from './engine/importExport';
4
+ import intents from './engine/intents';
5
+ import localizationKeys from './engine/localizationKeys';
6
+ import media from './engine/media';
7
+ import memori from './engine/memori';
8
+ import memories from './engine/memories';
9
+ import nlp from './engine/nlp';
10
+ import people from './engine/people';
11
+ import promptedQuestions from './engine/promptedQuestions';
12
+ import search from './engine/search';
13
+ import session from './engine/session';
14
+ import stats from './engine/stats';
15
+ import unansweredQuestions from './engine/unansweredQuestions';
16
+ import webhooks from './engine/webhooks';
17
+
18
+ export default (apiUrl: string) => ({
19
+ correlationPairs: correlationPairs(apiUrl),
20
+ ...correlationPairs(apiUrl),
21
+ dialog: dialog(apiUrl),
22
+ ...dialog(apiUrl),
23
+ importExport: importExport(apiUrl),
24
+ ...importExport(apiUrl),
25
+ intents: intents(apiUrl),
26
+ ...intents(apiUrl),
27
+ localizationKeys: localizationKeys(apiUrl),
28
+ ...localizationKeys(apiUrl),
29
+ media: media(apiUrl),
30
+ ...media(apiUrl),
31
+ memori: memori(apiUrl),
32
+ ...memori(apiUrl),
33
+ memories: memories(apiUrl),
34
+ ...memories(apiUrl),
35
+ nlp: nlp(apiUrl),
36
+ ...nlp(apiUrl),
37
+ people: people(apiUrl),
38
+ ...people(apiUrl),
39
+ promptedQuestions: promptedQuestions(apiUrl),
40
+ ...promptedQuestions(apiUrl),
41
+ search: search(apiUrl),
42
+ ...search(apiUrl),
43
+ session: session(apiUrl),
44
+ ...session(apiUrl),
45
+ stats: stats(apiUrl),
46
+ ...stats(apiUrl),
47
+ unansweredQuestions: unansweredQuestions(apiUrl),
48
+ ...unansweredQuestions(apiUrl),
49
+ webhooks: webhooks(apiUrl),
50
+ ...webhooks(apiUrl),
51
+ });
@@ -0,0 +1,52 @@
1
+ export interface ResourceURLParams {
2
+ type?: 'avatar' | 'cover' | 'default';
3
+ resourceURI?: string;
4
+ sessionID?: string;
5
+ baseURL?: string;
6
+ }
7
+
8
+ export default (apiUrl: string) => ({
9
+ /**
10
+ * getResourceUrl
11
+ * @description Returns the correct URL of a resource from the DB.
12
+ * @param {obj} params
13
+ * @param {string=} params.type - wheather is the avatar or the cover
14
+ * @param {string=} params.resourceURI - the resource URI
15
+ * @param {string=} params.sessionID - the session ID, required for memory media attachments
16
+ * @param {string=} params.baseURL - the base URL for default static assets (defaults to https://app.twincreator.com)
17
+ * @returns {string}
18
+ */
19
+ getResourceUrl: ({
20
+ type,
21
+ resourceURI,
22
+ sessionID,
23
+ baseURL = 'https://app.twincreator.com',
24
+ }: ResourceURLParams): string => {
25
+ let defaultUri =
26
+ type === 'cover'
27
+ ? `${baseURL}/images/memoriCover.png`
28
+ : `${baseURL}/images/memoriAvatar.png`;
29
+ if (!resourceURI || resourceURI.length === 0) {
30
+ return defaultUri;
31
+ } else if (resourceURI.includes('memoriai/memory')) {
32
+ return `${resourceURI}?memori-ai-session-id=${sessionID}`;
33
+ } else if (
34
+ resourceURI.startsWith('https://') ||
35
+ resourceURI.startsWith('http://')
36
+ ) {
37
+ return `${resourceURI}${sessionID ? `/${sessionID}` : ''}`;
38
+ } else if (resourceURI.startsWith('cloud://')) {
39
+ return `${apiUrl.replace(/v2/, 'v1')}/CloudAsset/${resourceURI.replace(
40
+ 'cloud://',
41
+ ''
42
+ )}`;
43
+ } else if (resourceURI.startsWith('guid://')) {
44
+ return `${apiUrl.replace(/v2/, 'v1')}/GuidAsset/${resourceURI.replace(
45
+ 'guid://',
46
+ ''
47
+ )}`;
48
+ } else {
49
+ return defaultUri;
50
+ }
51
+ },
52
+ });
@@ -0,0 +1,6 @@
1
+ export const getApiUrl = (hostname?: string) =>
2
+ hostname
3
+ ? new URL(
4
+ hostname.startsWith('http') ? hostname : `https://${hostname}`
5
+ ).origin.replace('http://', 'https://')
6
+ : 'https://backend.memori.ai';
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { getApiUrl } from './helpers/getApiUrl';
2
+ import backend from './backend';
3
+ import engine from './engine';
4
+ import * as constants from './constants';
5
+ import speech from './speech';
6
+ import asset from './helpers/asset';
7
+
8
+ const api = (hostname?: string) => {
9
+ const apiUrl = getApiUrl(hostname);
10
+
11
+ return {
12
+ backend: backend(`${apiUrl}/api/v2`),
13
+ ...engine(`${apiUrl}/memori/v2`),
14
+ speech,
15
+ constants,
16
+ asset: asset(`${apiUrl}/api/v2`),
17
+ };
18
+ };
19
+
20
+ export default api;