From 313bd9b017b8e7132b7f1e054d093a4d03683a8e Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 30 Oct 2024 11:21:37 +0000 Subject: [PATCH 1/7] add AI column from import if already defined --- packages/builder/src/components/backend/DataTable/formula.js | 1 + .../design/settings/controls/Explanation/lines/Column.svelte | 3 +++ packages/server/src/utilities/rowProcessor/index.ts | 4 ---- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/formula.js b/packages/builder/src/components/backend/DataTable/formula.js index 7220a5ba4f..a9491abfef 100644 --- a/packages/builder/src/components/backend/DataTable/formula.js +++ b/packages/builder/src/components/backend/DataTable/formula.js @@ -8,6 +8,7 @@ const MAX_DEPTH = 1 const TYPES_TO_SKIP = [ FieldType.FORMULA, + FieldType.AI, FieldType.LONGFORM, FieldType.SIGNATURE_SINGLE, FieldType.ATTACHMENTS, diff --git a/packages/builder/src/components/design/settings/controls/Explanation/lines/Column.svelte b/packages/builder/src/components/design/settings/controls/Explanation/lines/Column.svelte index 4552a54ba3..ef2616f562 100644 --- a/packages/builder/src/components/design/settings/controls/Explanation/lines/Column.svelte +++ b/packages/builder/src/components/design/settings/controls/Explanation/lines/Column.svelte @@ -80,6 +80,9 @@ if (columnType === FieldType.FORMULA) { return "https://docs.budibase.com/docs/formula" } + if (columnType === FieldType.AI) { + return "https://docs.budibase.com/docs/ai" + } if (columnType === FieldType.OPTIONS) { return "https://docs.budibase.com/docs/options" } diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index ed74394a85..910e9d220f 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -216,10 +216,6 @@ export async function inputProcessing( if (field.type === FieldType.FORMULA) { delete clonedRow[key] } - // remove any AI values, they are to be generated - if (field.type === FieldType.AI) { - delete clonedRow[key] - } // otherwise coerce what is there to correct types else { clonedRow[key] = coerce(value, field.type) From b06074128fe666f6d6a507f2a1c2c6fd32e9d1cc Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 30 Oct 2024 11:27:49 +0000 Subject: [PATCH 2/7] unit test to cover --- .../api/controllers/table/tests/utils.spec.ts | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/table/tests/utils.spec.ts b/packages/server/src/api/controllers/table/tests/utils.spec.ts index 68b00d3268..0cac17dd06 100644 --- a/packages/server/src/api/controllers/table/tests/utils.spec.ts +++ b/packages/server/src/api/controllers/table/tests/utils.spec.ts @@ -1,4 +1,4 @@ -import { AutoFieldSubType, FieldType } from "@budibase/types" +import { AIOperationEnum, AutoFieldSubType, FieldType } from "@budibase/types" import TestConfiguration from "../../../../tests/utilities/TestConfiguration" import { importToRows } from "../utils" @@ -92,5 +92,65 @@ describe("utils", () => { expect(result).toHaveLength(3) }) }) + + it("Imports write as expected with AI columns", async () => { + await config.doInContext(config.appId, async () => { + const table = await config.createTable({ + name: "table", + type: "table", + schema: { + autoId: { + name: "autoId", + type: FieldType.NUMBER, + subtype: AutoFieldSubType.AUTO_ID, + autocolumn: true, + constraints: { + type: FieldType.NUMBER, + presence: true, + }, + }, + name: { + name: "name", + type: FieldType.STRING, + constraints: { + type: FieldType.STRING, + presence: true, + }, + }, + aicol: { + name: "aicol", + type: FieldType.AI, + operation: AIOperationEnum.PROMPT, + prompt: "Test prompt" + }, + }, + }) + + const data = [ + { name: "Alice", aicol: "test" }, + { name: "Bob", aicol: "test" }, + { name: "Claire", aicol: "test" } + ] + + const result = await importToRows(data, table, config.user?._id) + expect(result).toEqual([ + expect.objectContaining({ + autoId: 1, + name: "Alice", + aicol: "test", + }), + expect.objectContaining({ + autoId: 2, + name: "Bob", + aicol: "test", + }), + expect.objectContaining({ + autoId: 3, + name: "Claire", + aicol: "test", + }), + ]) + }) + }) }) }) From d9b685811ddf0c0c58f3a92ac4afb0664d3e119a Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 30 Oct 2024 11:32:54 +0000 Subject: [PATCH 3/7] lint --- packages/server/src/api/controllers/table/tests/utils.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/controllers/table/tests/utils.spec.ts b/packages/server/src/api/controllers/table/tests/utils.spec.ts index 0cac17dd06..f9d6d707e2 100644 --- a/packages/server/src/api/controllers/table/tests/utils.spec.ts +++ b/packages/server/src/api/controllers/table/tests/utils.spec.ts @@ -121,7 +121,7 @@ describe("utils", () => { name: "aicol", type: FieldType.AI, operation: AIOperationEnum.PROMPT, - prompt: "Test prompt" + prompt: "Test prompt", }, }, }) @@ -129,7 +129,7 @@ describe("utils", () => { const data = [ { name: "Alice", aicol: "test" }, { name: "Bob", aicol: "test" }, - { name: "Claire", aicol: "test" } + { name: "Claire", aicol: "test" }, ] const result = await importToRows(data, table, config.user?._id) From 53fc45f07ee784141631bdd93fe5d2997d3fb95c Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 30 Oct 2024 14:14:49 +0000 Subject: [PATCH 4/7] make ai columns respect feature flags --- .../src/components/automation/SetupPanel/CronBuilder.svelte | 5 ++--- .../backend/DataTable/modals/CreateEditColumn.svelte | 5 ++--- .../[application]/data/table/[tableId]/[viewId]/index.svelte | 4 ++-- .../app/[application]/data/table/[tableId]/index.svelte | 5 ++--- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte b/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte index 1bba349244..51538944f4 100644 --- a/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte +++ b/packages/builder/src/components/automation/SetupPanel/CronBuilder.svelte @@ -9,7 +9,7 @@ } from "@budibase/bbui" import { onMount, createEventDispatcher } from "svelte" import { flags } from "stores/builder" - import { licensing } from "stores/portal" + import { featureFlags } from "stores/portal" import { API } from "api" import MagicWand from "../../../../assets/MagicWand.svelte" @@ -26,8 +26,7 @@ let aiCronPrompt = "" let loadingAICronExpression = false - $: aiEnabled = - $licensing.customAIConfigsEnabled || $licensing.budibaseAIEnabled + $: aiEnabled = $featureFlags.AI_CUSTOM_CONFIGS || $featureFlags.BUDIBASE_AI $: { if (cronExpression) { try { diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 143e292c55..d16bca3203 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -26,7 +26,7 @@ import { createEventDispatcher, getContext, onMount } from "svelte" import { cloneDeep } from "lodash/fp" import { tables, datasources } from "stores/builder" - import { licensing } from "stores/portal" + import { featureFlags } from "stores/portal" import { TableNames, UNEDITABLE_USER_FIELDS } from "constants" import { FIELDS, @@ -101,8 +101,7 @@ let optionsValid = true $: rowGoldenSample = RowUtils.generateGoldenSample($rows) - $: aiEnabled = - $licensing.customAIConfigsEnabled || $licensing.budibaseAIEnabled + $: aiEnabled = $featureFlags.BUDIBASE_AI || $featureFlags.AI_CUSTOM_CONFIGS $: if (primaryDisplay) { editableColumn.constraints.presence = { allowEmpty: false } } diff --git a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte index bc21b04ad0..39b1dc4768 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/table/[tableId]/[viewId]/index.svelte @@ -1,6 +1,6 @@