@truedat/ai 7.5.9 → 7.5.10

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 (69) hide show
  1. package/package.json +39 -59
  2. package/src/components/AiRoutes.js +39 -46
  3. package/src/components/TranslationModal.js +8 -10
  4. package/src/components/__tests__/TranslationModal.spec.js +0 -1
  5. package/src/components/actions/Action.js +1 -2
  6. package/src/components/actions/ActionActions.js +4 -5
  7. package/src/components/actions/ActionBreadcrumbs.js +1 -2
  8. package/src/components/actions/ActionDetail.js +4 -3
  9. package/src/components/actions/ActionEdit.js +3 -3
  10. package/src/components/actions/ActionForm.js +7 -7
  11. package/src/components/actions/ActionNew.js +1 -1
  12. package/src/components/actions/Actions.js +1 -2
  13. package/src/components/actions/ActionsContext.js +3 -7
  14. package/src/components/actions/ActionsTable.js +1 -2
  15. package/src/components/actions/__tests__/Action.spec.js +14 -36
  16. package/src/components/actions/__tests__/ActionActions.spec.js +2 -20
  17. package/src/components/actions/__tests__/ActionBreadcrumbs.spec.js +1 -10
  18. package/src/components/actions/__tests__/ActionDetail.spec.js +5 -23
  19. package/src/components/actions/__tests__/ActionEdit.spec.js +7 -31
  20. package/src/components/actions/__tests__/ActionForm.spec.js +11 -27
  21. package/src/components/actions/__tests__/ActionNew.spec.js +7 -53
  22. package/src/components/actions/__tests__/Actions.spec.js +6 -15
  23. package/src/components/actions/__tests__/ActionsTable.spec.js +3 -23
  24. package/src/components/actions/__tests__/__snapshots__/Action.spec.js.snap +39 -11
  25. package/src/components/actions/__tests__/__snapshots__/ActionActions.spec.js.snap +4 -4
  26. package/src/components/actions/__tests__/__snapshots__/ActionBreadcrumbs.spec.js.snap +2 -1
  27. package/src/components/actions/__tests__/__snapshots__/ActionDetail.spec.js.snap +26 -3
  28. package/src/components/actions/__tests__/__snapshots__/ActionEdit.spec.js.snap +11 -73
  29. package/src/components/actions/__tests__/__snapshots__/ActionForm.spec.js.snap +91 -13
  30. package/src/components/actions/__tests__/__snapshots__/ActionNew.spec.js.snap +16 -263
  31. package/src/components/actions/__tests__/__snapshots__/Actions.spec.js.snap +5 -4
  32. package/src/components/actions/__tests__/__snapshots__/ActionsTable.spec.js.snap +7 -5
  33. package/src/components/aiSandbox/AiSandbox.js +3 -6
  34. package/src/components/aiSandbox/RequestForm.js +6 -4
  35. package/src/components/prompts/PromptEditor.js +1 -8
  36. package/src/components/prompts/Prompts.js +2 -6
  37. package/src/components/prompts/__tests__/PromptEditor.spec.js +62 -54
  38. package/src/components/prompts/__tests__/Prompts.spec.js +0 -2
  39. package/src/components/prompts/__tests__/__snapshots__/PromptEditor.spec.js.snap +115 -10
  40. package/src/components/providers/ProviderEditor.js +1 -5
  41. package/src/components/providers/Providers.js +1 -2
  42. package/src/components/providers/__tests__/ProviderEditor.spec.js +54 -75
  43. package/src/components/providers/__tests__/Providers.spec.js +0 -2
  44. package/src/components/providers/__tests__/__snapshots__/ProviderEditor.spec.js.snap +0 -4
  45. package/src/components/providers/providerProperties/AzureOpenai.js +0 -1
  46. package/src/components/providers/providerProperties/BedrockClaude.js +0 -1
  47. package/src/components/providers/providerProperties/Gemini.js +0 -1
  48. package/src/components/providers/providerProperties/Openai.js +0 -1
  49. package/src/components/resourceMappings/ResourceMappingEditor.js +2 -5
  50. package/src/components/resourceMappings/ResourceMappingFields.js +3 -2
  51. package/src/components/resourceMappings/ResourceMappings.js +4 -2
  52. package/src/components/resourceMappings/__tests__/ResourceMappingEditor.spec.js +51 -93
  53. package/src/components/resourceMappings/__tests__/ResourceMappings.spec.js +0 -2
  54. package/src/components/resourceMappings/__tests__/__snapshots__/ResourceMappingEditor.spec.js.snap +4 -4
  55. package/src/components/resourceMappings/selectors/DataStructureSelector.js +0 -1
  56. package/src/components/resourceMappings/selectors/index.js +0 -1
  57. package/src/components/suggestions/SuggestionsWidget.js +1 -1
  58. package/src/components/suggestions/__tests__/SuggestionsWidget.spec.js +3 -3
  59. package/src/components/suggestions/__tests__/__snapshots__/SuggestionsWidget.spec.js.snap +0 -3
  60. package/src/hooks/__mocks__/useActions.js +44 -0
  61. package/src/hooks/__mocks__/useSuggestions.js +5 -0
  62. package/src/hooks/__tests__/usePrompts.spec.js +5 -5
  63. package/src/hooks/__tests__/{useProviders.js → useProviders.spec.js} +5 -5
  64. package/src/hooks/__tests__/useResourceMappings.spec.js +5 -5
  65. package/src/hooks/useActions.js +5 -4
  66. package/src/hooks/usePrompts.js +6 -6
  67. package/src/hooks/useProviders.js +5 -5
  68. package/src/hooks/useResourceMappings.js +4 -4
  69. package/src/index.js +2 -1
@@ -70,7 +70,7 @@ exports[`<ResourceMappingEditor /> matches snapshot without onDelete 1`] = `
70
70
  <span
71
71
  class="text"
72
72
  >
73
- business concept
73
+ resourceMappings.resourceType.business_concept
74
74
  </span>
75
75
  </div>
76
76
  </div>
@@ -268,7 +268,7 @@ exports[`<ResourceMappingEditor /> matches the latest snapshot 1`] = `
268
268
  <span
269
269
  class="text"
270
270
  >
271
- business concept
271
+ resourceMappings.resourceType.business_concept
272
272
  </span>
273
273
  </div>
274
274
  </div>
@@ -469,7 +469,7 @@ exports[`<ResourceMappingEditor /> test cancel button with confirm 1`] = `
469
469
  <span
470
470
  class="text"
471
471
  >
472
- business concept
472
+ resourceMappings.resourceType.business_concept
473
473
  </span>
474
474
  </div>
475
475
  </div>
@@ -668,7 +668,7 @@ exports[`<ResourceMappingEditor /> test delete button 1`] = `
668
668
  <span
669
669
  class="text"
670
670
  >
671
- business concept
671
+ resourceMappings.resourceType.business_concept
672
672
  </span>
673
673
  </div>
674
674
  </div>
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { useIntl } from "react-intl";
3
2
  import { Controller, useFormContext } from "react-hook-form";
4
3
  import { Form } from "semantic-ui-react";
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import DataStructureSelector from "./DataStructureSelector";
3
2
 
4
3
  export function selectorFor(resourceType) {
@@ -1,5 +1,5 @@
1
1
  import _ from "lodash/fp";
2
- import React, { useState } from "react";
2
+ import { useState } from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import {
5
5
  Button,
@@ -1,4 +1,4 @@
1
- import React, { Suspense } from "react";
1
+ import { Suspense } from "react";
2
2
  import { waitFor } from "@testing-library/react";
3
3
  import userEvent from "@testing-library/user-event";
4
4
  import { render } from "@truedat/test/render";
@@ -28,8 +28,8 @@ const requestAiSuggestion = (mock) => (callback) => {
28
28
  mock === "suggestions"
29
29
  ? mockSuggestions
30
30
  : mock === "error_message"
31
- ? ["error", { error: { message: "ERROR MESSAGE" } }]
32
- : ["error", "ERROR TEXT"],
31
+ ? ["error", { error: { message: "ERROR MESSAGE" } }]
32
+ : ["error", "ERROR TEXT"],
33
33
  },
34
34
  });
35
35
  };
@@ -43,7 +43,6 @@ exports[`<SuggestionsWidget /> component lifecycle 1`] = `
43
43
  readonly=""
44
44
  tabindex="0"
45
45
  type="checkbox"
46
- value=""
47
46
  />
48
47
  <label
49
48
  for="editable_field"
@@ -96,7 +95,6 @@ exports[`<SuggestionsWidget /> component lifecycle 1`] = `
96
95
  readonly=""
97
96
  tabindex="-1"
98
97
  type="checkbox"
99
- value=""
100
98
  />
101
99
  <label
102
100
  for="non_editable_field"
@@ -134,7 +132,6 @@ exports[`<SuggestionsWidget /> component lifecycle 1`] = `
134
132
  readonly=""
135
133
  tabindex="0"
136
134
  type="checkbox"
137
- value=""
138
135
  />
139
136
  <label
140
137
  for="unselect_field"
@@ -0,0 +1,44 @@
1
+ export const useActions = jest.fn(() => ({
2
+ data: [],
3
+ error: null,
4
+ loading: false,
5
+ mutate: jest.fn(),
6
+ }));
7
+
8
+ export const useActionsSearch = jest.fn(() => ({
9
+ trigger: jest.fn(() => ({
10
+ then: jest.fn(),
11
+ })),
12
+ }));
13
+
14
+ export const useAction = jest.fn(() => ({
15
+ data: {},
16
+ action: {},
17
+ error: null,
18
+ loading: false,
19
+ mutate: jest.fn(),
20
+ }));
21
+
22
+ export const useActionCreate = jest.fn(() => ({
23
+ trigger: jest.fn(() => ({
24
+ then: jest.fn(),
25
+ })),
26
+ }));
27
+
28
+ export const useActionUpdate = jest.fn(() => ({
29
+ trigger: jest.fn(() => ({
30
+ then: jest.fn(),
31
+ })),
32
+ }));
33
+
34
+ export const useActionDelete = jest.fn(() => ({
35
+ trigger: jest.fn(() => ({
36
+ then: jest.fn(),
37
+ })),
38
+ }));
39
+
40
+ export const useActionSetActive = jest.fn(() => ({
41
+ trigger: jest.fn(() => ({
42
+ then: jest.fn(),
43
+ })),
44
+ }));
@@ -0,0 +1,5 @@
1
+ export const useAvailabilityCheck = jest.fn(() => ({
2
+ trigger: () => ({
3
+ then: () => ({ data: { data: { status: "ok" } } }),
4
+ }),
5
+ }));
@@ -2,7 +2,7 @@ import _ from "lodash/fp";
2
2
  import { compile } from "path-to-regexp";
3
3
  import useSWR from "swr";
4
4
  import useSWRMutations from "swr/mutation";
5
- import { renderHook } from "@testing-library/react-hooks";
5
+ import { renderHook } from "@testing-library/react";
6
6
  import {
7
7
  apiJson,
8
8
  apiJsonPost,
@@ -63,7 +63,7 @@ describe("usePrompts", () => {
63
63
  expect(apiJsonPost).toHaveBeenCalledWith(url, arg);
64
64
  });
65
65
  it("usePromptUpdate calls useSWRMutations with correct api route", () => {
66
- const id = 8;
66
+ const id = "8";
67
67
  renderHook(() => usePromptUpdate({ id }));
68
68
  const [url, func] = _.last(useSWRMutations.mock.calls);
69
69
  const arg = { some: "arg" };
@@ -76,12 +76,12 @@ describe("usePrompts", () => {
76
76
  renderHook(() => usePromptUpdate());
77
77
  const [url, func] = _.last(useSWRMutations.mock.calls);
78
78
  const arg = { some: "arg" };
79
- expect(url).toBe(compile(API_PROMPT)({ id: 0 }));
79
+ expect(url).toBe(compile(API_PROMPT)({ id: "0" }));
80
80
  func(url, { arg });
81
81
  expect(apiJsonPatch).toHaveBeenCalledWith(url, arg);
82
82
  });
83
83
  it("usePromptDelete calls useSWRMutations with correct api route", () => {
84
- const id = 8;
84
+ const id = "8";
85
85
  renderHook(() => usePromptDelete({ id }));
86
86
  const [url, func] = _.last(useSWRMutations.mock.calls);
87
87
  const arg = { some: "arg" };
@@ -94,7 +94,7 @@ describe("usePrompts", () => {
94
94
  renderHook(() => usePromptDelete());
95
95
  const [url, func] = _.last(useSWRMutations.mock.calls);
96
96
  const arg = { some: "arg" };
97
- expect(url).toBe(compile(API_PROMPT)({ id: 0 }));
97
+ expect(url).toBe(compile(API_PROMPT)({ id: "0" }));
98
98
  func(url, { arg });
99
99
  expect(apiJsonDelete).toHaveBeenCalledWith(url, arg);
100
100
  });
@@ -2,7 +2,7 @@ import _ from "lodash/fp";
2
2
  import { compile } from "path-to-regexp";
3
3
  import useSWR from "swr";
4
4
  import useSWRMutations from "swr/mutation";
5
- import { renderHook } from "@testing-library/react-hooks";
5
+ import { renderHook } from "@testing-library/react";
6
6
  import {
7
7
  apiJson,
8
8
  apiJsonPost,
@@ -63,7 +63,7 @@ describe("useProviders", () => {
63
63
  expect(apiJsonPost).toHaveBeenCalledWith(url, arg);
64
64
  });
65
65
  it("useProviderUpdate calls useSWRMutations with correct api route", () => {
66
- const id = 8;
66
+ const id = "8";
67
67
  renderHook(() => useProviderUpdate({ id }));
68
68
  const [url, func] = _.last(useSWRMutations.mock.calls);
69
69
  const arg = { some: "arg" };
@@ -76,12 +76,12 @@ describe("useProviders", () => {
76
76
  renderHook(() => useProviderUpdate());
77
77
  const [url, func] = _.last(useSWRMutations.mock.calls);
78
78
  const arg = { some: "arg" };
79
- expect(url).toBe(compile(API_PROVIDER)({ id: 0 }));
79
+ expect(url).toBe(compile(API_PROVIDER)({ id: "0" }));
80
80
  func(url, { arg });
81
81
  expect(apiJsonPatch).toHaveBeenCalledWith(url, arg);
82
82
  });
83
83
  it("useProviderDelete calls useSWRMutations with correct api route", () => {
84
- const id = 8;
84
+ const id = "8";
85
85
  renderHook(() => useProviderDelete({ id }));
86
86
  const [url, func] = _.last(useSWRMutations.mock.calls);
87
87
  const arg = { some: "arg" };
@@ -94,7 +94,7 @@ describe("useProviders", () => {
94
94
  renderHook(() => useProviderDelete());
95
95
  const [url, func] = _.last(useSWRMutations.mock.calls);
96
96
  const arg = { some: "arg" };
97
- expect(url).toBe(compile(API_PROVIDER)({ id: 0 }));
97
+ expect(url).toBe(compile(API_PROVIDER)({ id: "0" }));
98
98
  func(url, { arg });
99
99
  expect(apiJsonDelete).toHaveBeenCalledWith(url, arg);
100
100
  });
@@ -2,7 +2,7 @@ import _ from "lodash/fp";
2
2
  import { compile } from "path-to-regexp";
3
3
  import useSWR from "swr";
4
4
  import useSWRMutations from "swr/mutation";
5
- import { renderHook } from "@testing-library/react-hooks";
5
+ import { renderHook } from "@testing-library/react";
6
6
  import {
7
7
  apiJson,
8
8
  apiJsonPost,
@@ -63,7 +63,7 @@ describe("useResourceMappings", () => {
63
63
  expect(apiJsonPost).toHaveBeenCalledWith(url, arg);
64
64
  });
65
65
  it("useResourceMappingUpdate calls useSWRMutations with correct api route", () => {
66
- const id = 8;
66
+ const id = "8";
67
67
  renderHook(() => useResourceMappingUpdate({ id }));
68
68
  const [url, func] = _.last(useSWRMutations.mock.calls);
69
69
  const arg = { some: "arg" };
@@ -76,12 +76,12 @@ describe("useResourceMappings", () => {
76
76
  renderHook(() => useResourceMappingUpdate());
77
77
  const [url, func] = _.last(useSWRMutations.mock.calls);
78
78
  const arg = { some: "arg" };
79
- expect(url).toBe(compile(API_RESOURCE_MAPPING)({ id: 0 }));
79
+ expect(url).toBe(compile(API_RESOURCE_MAPPING)({ id: "0" }));
80
80
  func(url, { arg });
81
81
  expect(apiJsonPatch).toHaveBeenCalledWith(url, arg);
82
82
  });
83
83
  it("useResourceMappingDelete calls useSWRMutations with correct api route", () => {
84
- const id = 8;
84
+ const id = "8";
85
85
  renderHook(() => useResourceMappingDelete({ id }));
86
86
  const [url, func] = _.last(useSWRMutations.mock.calls);
87
87
  const arg = { some: "arg" };
@@ -94,7 +94,7 @@ describe("useResourceMappings", () => {
94
94
  renderHook(() => useResourceMappingDelete());
95
95
  const [url, func] = _.last(useSWRMutations.mock.calls);
96
96
  const arg = { some: "arg" };
97
- expect(url).toBe(compile(API_RESOURCE_MAPPING)({ id: 0 }));
97
+ expect(url).toBe(compile(API_RESOURCE_MAPPING)({ id: "0" }));
98
98
  func(url, { arg });
99
99
  expect(apiJsonDelete).toHaveBeenCalledWith(url, arg);
100
100
  });
@@ -28,7 +28,7 @@ export const useActionsSearch = () => {
28
28
  };
29
29
 
30
30
  export const useAction = (id) => {
31
- const url = compile(API_ACTION)({ id });
31
+ const url = compile(API_ACTION)({ id: `${id}` });
32
32
  const { data, error, mutate } = useSWRImmutable(url, apiJson);
33
33
  return {
34
34
  data: data?.data,
@@ -44,20 +44,21 @@ export const useActionCreate = () => {
44
44
  };
45
45
 
46
46
  export const useActionUpdate = (id) => {
47
- const url = compile(API_ACTION)({ id });
47
+ const url = compile(API_ACTION)({ id: `${id}` });
48
48
  return useSWRMutations(url, (url, { arg }) => apiJsonPatch(url, arg));
49
49
  };
50
50
 
51
51
  export const useActionDelete = (payload) => {
52
52
  const id = payload?.id || 0;
53
53
  const logical = payload?.logical || true;
54
- const url = compile(API_ACTION)({ id }) + "?logical=" + logical;
54
+ const url = compile(API_ACTION)({ id: `${id}` }) + "?logical=" + logical;
55
55
  return useSWRMutations(url, (url, { arg }) => apiJsonDelete(url, arg));
56
56
  };
57
57
 
58
58
  export const useActionSetActive = (payload) => {
59
59
  const id = payload?.id || 0;
60
60
  const active = _.propOr(true, "active")(payload);
61
- const url = compile(API_ACTION_SET_ACTIVE)({ id }) + "?active=" + active;
61
+ const url =
62
+ compile(API_ACTION_SET_ACTIVE)({ id: `${id}` }) + "?active=" + active;
62
63
  return useSWRMutations(url, (url, { arg }) => apiJsonPost(url, arg));
63
64
  };
@@ -19,19 +19,19 @@ export const usePromptCreate = () => {
19
19
  };
20
20
 
21
21
  export const usePromptUpdate = (func) => {
22
- const id = func?.id || 0;
23
- const url = compile(API_PROMPT)({ id });
22
+ const id = func?.id || "0";
23
+ const url = compile(API_PROMPT)({ id: `${id}` });
24
24
  return useSWRMutations(url, (url, { arg }) => apiJsonPatch(url, arg));
25
25
  };
26
26
 
27
27
  export const usePromptSetActive = (func) => {
28
- const id = func?.id || 0;
29
- const url = compile(API_PROMPT_SET_ACTIVE)({ id });
28
+ const id = func?.id || "0";
29
+ const url = compile(API_PROMPT_SET_ACTIVE)({ id: `${id}` });
30
30
  return useSWRMutations(url, (url) => apiJsonPatch(url));
31
31
  };
32
32
 
33
33
  export const usePromptDelete = (func) => {
34
- const id = func?.id || 0;
35
- const url = compile(API_PROMPT)({ id });
34
+ const id = func?.id || "0";
35
+ const url = compile(API_PROMPT)({ id: `${id}` });
36
36
  return useSWRMutations(url, (url, { arg }) => apiJsonDelete(url, arg));
37
37
  };
@@ -21,18 +21,18 @@ export const useProviderCreate = () => {
21
21
  };
22
22
 
23
23
  export const useProviderUpdate = (payload) => {
24
- const id = payload?.id || 0;
25
- const url = compile(API_PROVIDER)({ id });
24
+ const id = payload?.id || "0";
25
+ const url = compile(API_PROVIDER)({ id: `${id}` });
26
26
  return useSWRMutations(url, (url, { arg }) => apiJsonPatch(url, arg));
27
27
  };
28
28
 
29
29
  export const useProviderChatCompletion = (id) => {
30
- const url = compile(API_PROVIDER_CHAT)({ id });
30
+ const url = compile(API_PROVIDER_CHAT)({ id: `${id}` });
31
31
  return useSWRMutations(url, (url, { arg }) => apiJsonPost(url, arg));
32
32
  };
33
33
 
34
34
  export const useProviderDelete = (payload) => {
35
- const id = payload?.id || 0;
36
- const url = compile(API_PROVIDER)({ id });
35
+ const id = payload?.id || "0";
36
+ const url = compile(API_PROVIDER)({ id: `${id}` });
37
37
  return useSWRMutations(url, (url, { arg }) => apiJsonDelete(url, arg));
38
38
  };
@@ -21,13 +21,13 @@ export const useResourceMappingCreate = () => {
21
21
  };
22
22
 
23
23
  export const useResourceMappingUpdate = (func) => {
24
- const id = func?.id || 0;
25
- const url = compile(API_RESOURCE_MAPPING)({ id });
24
+ const id = func?.id || "0";
25
+ const url = compile(API_RESOURCE_MAPPING)({ id: `${id}` });
26
26
  return useSWRMutations(url, (url, { arg }) => apiJsonPatch(url, arg));
27
27
  };
28
28
 
29
29
  export const useResourceMappingDelete = (func) => {
30
- const id = func?.id || 0;
31
- const url = compile(API_RESOURCE_MAPPING)({ id });
30
+ const id = func?.id || "0";
31
+ const url = compile(API_RESOURCE_MAPPING)({ id: `${id}` });
32
32
  return useSWRMutations(url, (url, { arg }) => apiJsonDelete(url, arg));
33
33
  };
package/src/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as components from "./components";
2
2
  import * as api from "./api";
3
+ import * as mocks from "./mocks";
3
4
 
4
- export { components, api };
5
+ export { components, api, mocks };