@truedat/ai 8.10.3 → 8.10.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/ai",
3
- "version": "8.10.3",
3
+ "version": "8.10.5",
4
4
  "description": "Truedat Web Artificial Intelligence package",
5
5
  "sideEffects": false,
6
6
  "module": "src/index.js",
@@ -53,7 +53,7 @@
53
53
  "@testing-library/jest-dom": "^6.6.3",
54
54
  "@testing-library/react": "^16.3.0",
55
55
  "@testing-library/user-event": "^14.6.1",
56
- "@truedat/test": "8.10.3",
56
+ "@truedat/test": "8.10.5",
57
57
  "identity-obj-proxy": "^3.0.0",
58
58
  "jest": "^29.7.0",
59
59
  "redux-saga-test-plan": "^4.0.6"
@@ -83,5 +83,5 @@
83
83
  "semantic-ui-react": "^3.0.0-beta.2",
84
84
  "swr": "^2.3.3"
85
85
  },
86
- "gitHead": "39f6a32de360216dbd10f5987e6a91f53bdd5a8e"
86
+ "gitHead": "59a1ba19e914ae07d503aa2eea46d77ea11f05ab"
87
87
  }
package/src/api.js CHANGED
@@ -2,8 +2,6 @@ const API_ACTION = "/api/actions/:id";
2
2
  const API_ACTIONS = "/api/actions";
3
3
  const API_ACTIONS_SEARCH = "/api/actions/search";
4
4
  const API_ACTION_SET_ACTIVE = "/api/actions/:id/set_active";
5
- const API_RESOURCE_MAPPINGS = "/api/resource_mappings";
6
- const API_RESOURCE_MAPPING = "/api/resource_mappings/:id";
7
5
  const API_PROMPTS = "/api/prompts";
8
6
  const API_PROMPT = "/api/prompts/:id";
9
7
  const API_PROMPT_SET_ACTIVE = "/api/prompts/:id/set_active";
@@ -24,8 +22,6 @@ export {
24
22
  API_ACTIONS,
25
23
  API_ACTIONS_SEARCH,
26
24
  API_ACTION_SET_ACTIVE,
27
- API_RESOURCE_MAPPINGS,
28
- API_RESOURCE_MAPPING,
29
25
  API_PROMPTS,
30
26
  API_PROMPT,
31
27
  API_PROMPT_SET_ACTIVE,
@@ -3,7 +3,6 @@ import { Navigate, Route, Routes } from "react-router";
3
3
  import { ProtectedRoute } from "@truedat/core/router";
4
4
  import { useCanAssistant } from "./assistant/hooks/useAgentConversation";
5
5
 
6
- import ResourceMappings from "./resourceMappings/ResourceMappings";
7
6
  import Prompts from "./prompts/Prompts";
8
7
  import Providers from "./providers/Providers";
9
8
  import AiSandbox from "./aiSandbox/AiSandbox";
@@ -22,13 +21,6 @@ const AssistantPageGuard = () => {
22
21
  export default function AiRoutes() {
23
22
  return (
24
23
  <Routes>
25
- <Route
26
- path={"resource_mappings"}
27
- element={<ProtectedRoute authorization={"manage_ai"} />}
28
- >
29
- <Route index element={<ResourceMappings />} />
30
- </Route>
31
-
32
24
  <Route
33
25
  path={"prompts"}
34
26
  element={<ProtectedRoute authorization={"manage_ai"} />}
@@ -1,9 +1,7 @@
1
1
  import _ from "lodash/fp";
2
2
  import { useIntl } from "react-intl";
3
3
 
4
- export const resourceTypes = ["data_structure", "business_concept"];
5
-
6
- export const promptResourceTypes = [...resourceTypes, "translation"];
4
+ export const promptResourceTypes = ["translation"];
7
5
 
8
6
  export const providerTypes = [
9
7
  "openai",
@@ -15,8 +13,6 @@ export const providerTypes = [
15
13
 
16
14
  export const agentTypes = ["fast", "high", "thinking"];
17
15
 
18
- export const useResourceTypeOptions = () =>
19
- useOptions(resourceTypes, "resourceMappings.resourceType");
20
16
  export const usePromptResourceTypeOptions = () =>
21
17
  useOptions(promptResourceTypes, "resourceMappings.resourceType");
22
18
  export const useProviderTypeOptions = () =>
@@ -1,5 +1,4 @@
1
- import _ from "lodash/fp";
2
- import { Fragment, useEffect, useState } from "react";
1
+ import { Fragment, useEffect } from "react";
3
2
  import PropTypes from "prop-types";
4
3
  import { useIntl } from "react-intl";
5
4
  import {
@@ -27,20 +26,15 @@ export default function PromptEditor({
27
26
  }) {
28
27
  const { formatMessage } = useIntl();
29
28
  const resourceTypeOptions = usePromptResourceTypeOptions();
30
- const { defaultLang, enabledLangs } = useLanguage();
31
- const [isTranslationPrompt, setIsTranslationPrompt] = useState(
32
- selectedPrompt?.resource_type === "translation",
33
- );
34
-
35
- const localeOptions = _.map((key) => ({
36
- key,
37
- text: key,
38
- value: key,
39
- }))(enabledLangs);
29
+ const { defaultLang } = useLanguage();
40
30
 
41
31
  const form = useForm({
42
32
  mode: "onTouched",
43
- defaultValues: selectedPrompt,
33
+ defaultValues: {
34
+ ...selectedPrompt,
35
+ resource_type: "translation",
36
+ language: selectedPrompt?.id ? selectedPrompt.language : defaultLang,
37
+ },
44
38
  });
45
39
  const { control, handleSubmit, watch, formState } = form;
46
40
  const { isDirty, isValid } = formState;
@@ -51,15 +45,6 @@ export default function PromptEditor({
51
45
 
52
46
  if (!selectedPrompt) return null;
53
47
 
54
- const handleResourceTypeChange = (value, onChange) => {
55
- const isValueTranslation = value === "translation";
56
- setIsTranslationPrompt(isValueTranslation);
57
- onChange(value);
58
- if (isValueTranslation) {
59
- form.setValue("language", defaultLang);
60
- }
61
- };
62
-
63
48
  const name =
64
49
  watch("name") ||
65
50
  formatMessage({
@@ -119,7 +104,7 @@ export default function PromptEditor({
119
104
  },
120
105
  ),
121
106
  }}
122
- render={({ field: { onBlur, onChange, value } }) => (
107
+ render={({ field: { onBlur, value } }) => (
123
108
  <Form.Field required>
124
109
  <label>
125
110
  {formatMessage({
@@ -127,59 +112,16 @@ export default function PromptEditor({
127
112
  })}
128
113
  </label>
129
114
  <Dropdown
115
+ disabled
130
116
  selection
131
117
  onBlur={onBlur}
132
118
  options={resourceTypeOptions}
133
- onChange={(_e, { value }) =>
134
- handleResourceTypeChange(value, onChange)
135
- }
136
- value={value}
137
- />
138
- </Form.Field>
139
- )}
140
- />
141
- <Controller
142
- control={control}
143
- name="language"
144
- rules={{
145
- required: formatMessage(
146
- { id: "form.validation.required" },
147
- {
148
- prop: formatMessage({
149
- id: "prompts.form.language",
150
- }),
151
- },
152
- ),
153
- }}
154
- render={({ field: { onBlur, onChange, value } }) => (
155
- <Form.Field
156
- required
157
- data-tooltip={
158
- isTranslationPrompt
159
- ? formatMessage({
160
- id: "prompts.form.language.tooltip.disabled",
161
- defaultMessage:
162
- "Language is disabled for translations type prompts",
163
- })
164
- : null
165
- }
166
- >
167
- <label>
168
- {formatMessage({
169
- id: "prompts.form.language",
170
- })}
171
- </label>
172
- <Dropdown
173
- disabled={isTranslationPrompt}
174
- selection
175
- onBlur={onBlur}
176
- options={localeOptions}
177
- onChange={(_e, { value }) => onChange(value)}
178
119
  value={value}
179
120
  />
180
121
  </Form.Field>
181
122
  )}
182
123
  />
124
+ <Controller control={control} name="language" render={() => null} />
183
125
  <Controller
184
126
  control={control}
185
127
  name="system_prompt"
@@ -24,7 +24,7 @@ import PromptEditor from "./PromptEditor";
24
24
 
25
25
  const NEW_PROMPT = {
26
26
  name: "",
27
- resource_type: "data_structure",
27
+ resource_type: "translation",
28
28
  language: "en",
29
29
  system_prompt: "",
30
30
  user_prompt_template: "",
@@ -40,7 +40,9 @@ export default function Prompts() {
40
40
  const [isDirty, setDirty] = useState(false);
41
41
 
42
42
  const loading = loadingPrompts || loadingProviders;
43
- const prompts = data?.data;
43
+ const prompts = data?.data?.filter(
44
+ ({ resource_type }) => resource_type === "translation",
45
+ );
44
46
 
45
47
  const providersOptions = _.flow(
46
48
  _.prop("data"),
@@ -1,7 +1,6 @@
1
1
  import userEvent from "@testing-library/user-event";
2
2
  import { waitFor } from "@testing-library/react";
3
3
  import { render, waitForLoad } from "@truedat/test/render";
4
- import _ from "lodash/fp";
5
4
  import PromptEditor from "../PromptEditor";
6
5
 
7
6
  jest.mock("@truedat/core/hooks", () => ({
@@ -16,7 +15,7 @@ const props = {
16
15
  selectedPrompt: {
17
16
  id: 1,
18
17
  name: "prompt1",
19
- resource_type: "data_structure",
18
+ resource_type: "translation",
20
19
  language: "en",
21
20
  system_prompt: "system_prompt",
22
21
  user_prompt_template: "user_prompt",
@@ -26,7 +25,7 @@ const props = {
26
25
  {
27
26
  id: 1,
28
27
  name: "prompt1",
29
- resource_type: "data_structure",
28
+ resource_type: "translation",
30
29
  language: "en",
31
30
  system_prompt: "system_prompt",
32
31
  user_prompt_template: "user_prompt",
@@ -48,7 +47,7 @@ describe("<PromptEditor />", () => {
48
47
  expect(rendered.container).toMatchSnapshot();
49
48
  });
50
49
 
51
- it("matches snapshot without selected resource mapping", async () => {
50
+ it("matches snapshot without selectedPrompt", async () => {
52
51
  const props = { setDirty: jest.fn() };
53
52
  const rendered = render(<PromptEditor {...props} />);
54
53
  await waitForLoad(rendered);
@@ -56,17 +55,6 @@ describe("<PromptEditor />", () => {
56
55
  expect(rendered.container).toMatchSnapshot();
57
56
  });
58
57
 
59
- it("matches snapshot for translation resource type", async () => {
60
- const translationProps = _.set(
61
- "selectedPrompt.resource_type",
62
- "translation",
63
- )(props);
64
- const rendered = render(<PromptEditor {...translationProps} />);
65
- await waitForLoad(rendered);
66
-
67
- expect(rendered.container).toMatchSnapshot();
68
- });
69
-
70
58
  it("matches snapshot without onDelete", async () => {
71
59
  const thisProps = {
72
60
  ...props,
@@ -174,7 +162,7 @@ describe("<PromptEditor />", () => {
174
162
  language: "en",
175
163
  name: "prompt1name",
176
164
  provider_id: 1,
177
- resource_type: "data_structure",
165
+ resource_type: "translation",
178
166
  system_prompt: "system_prompt",
179
167
  user_prompt_template: "user_prompt",
180
168
  });
@@ -12,10 +12,24 @@ jest.mock("@truedat/ai/hooks/usePrompts", () => {
12
12
  data: {
13
13
  data: [
14
14
  {
15
- name: "rm1",
16
- resource_type: "boolean",
17
- fields: [{ source: "s1", target: "t1" }],
18
- selector: { system_external_id: 1 },
15
+ id: 1,
16
+ name: "tr1",
17
+ resource_type: "translation",
18
+ language: "en",
19
+ active: true,
20
+ system_prompt: "system prompt",
21
+ user_prompt_template: "user prompt",
22
+ provider_id: 1,
23
+ },
24
+ {
25
+ id: 2,
26
+ name: "legacy",
27
+ resource_type: "data_structure",
28
+ language: "en",
29
+ active: true,
30
+ system_prompt: "legacy system prompt",
31
+ user_prompt_template: "legacy user prompt",
32
+ provider_id: 1,
19
33
  },
20
34
  ],
21
35
  },
@@ -88,6 +102,8 @@ describe("<Prompts />", () => {
88
102
  it("matches the latest snapshot", async () => {
89
103
  const { container, queryByText } = render(<Prompts />, renderOpts);
90
104
  await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
105
+ expect(queryByText("tr1")).toBeInTheDocument();
106
+ expect(queryByText("legacy")).not.toBeInTheDocument();
91
107
  expect(container).toMatchSnapshot();
92
108
  });
93
109
  });