The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Ask about CRM migration at the start of the workspace setup chat (#24013)
Raphaël Bosib0a3dced7997
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/__tests__/build-workspace-setup-prompt-text.util.spec.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/__tests__/build-workspace-setup-prompt-text.util.spec.tsindex e06a8ad29b8..0cf0a28763c 100644--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/__tests__/build-workspace-setup-prompt-text.util.spec.ts+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/__tests__/build-workspace-setup-prompt-text.util.spec.ts@@ -43,7 +43,7 @@ describe('buildWorkspaceSetupPromptText', () => {expect(result).toContain('what you already know about their company');expect(result).toContain('When their job title is in your user context');expect(result).toContain('when it is missing, do not guess it');- expect(result).toContain('what they want to use Twenty for');+ expect(result).not.toContain('what they want to use Twenty for');expect(result).not.toContain('You do not know what this company does yet');});@@ -55,6 +55,9 @@ describe('buildWorkspaceSetupPromptText', () => {expect(result).toContain('required ask_questions call');expect(result).toContain('A written question does not count');+ expect(result).toContain(+ 'a heading with nothing under it is not an ending',+ );expect(result).toContain('needs no skill and no learn_tools step');expect(result).toContain('do not call load_skills, learn_tools, execute_tool, or web search',@@ -95,12 +98,75 @@ describe('buildWorkspaceSetupPromptText', () => {});expect(result).toContain('You do not know what this company does yet');- expect(result).toContain(- 'call ask_questions to learn what the business does',- );+ expect(result).toContain('ask_questions to learn what the business does');+ expect(result).toContain('when they start fresh');expect(result).not.toContain('tailored to their business');});+ it.each([+ ['a full enrichment', companyEnrichment],+ ['a null enrichment', null],+ ])(+ 'should open with the migration-or-scratch question when %s is provided',+ (_label, enrichment) => {+ const result = buildWorkspaceSetupPromptText({+ companyEnrichment: enrichment,+ locale: 'en',+ });++ expect(result).toContain(+ 'moving over from another CRM or starting fresh',+ );+ expect(result).toContain('follow the migration path below');+ },+ );++ it('should request the CRM export in plain text so the upload composer stays available', () => {+ const result = buildWorkspaceSetupPromptText({+ companyEnrichment,+ locale: 'en',+ });++ expect(result).toContain('end that reply without calling ask_questions');+ expect(result).toContain('cannot take attachments');+ expect(result).toContain('upload all their CSV exports at once');+ });++ it('should tolerate spreadsheets, propose right away, and fall back to scratch without an export', () => {+ const result = buildWorkspaceSetupPromptText({+ companyEnrichment,+ locale: 'en',+ });++ expect(result).toContain('spreadsheet their CRM produces');+ expect(result).toContain('as separate files');+ expect(result).toContain('read them right away');+ expect(result).toContain('continue as if they had chosen to start fresh');+ });++ it('should inspect uploaded exports through code_interpreter before proposing the model', () => {+ const result = buildWorkspaceSetupPromptText({+ companyEnrichment,+ locale: 'en',+ });++ expect(result).toContain('code_interpreter');+ expect(result).toContain('headers and a few sample rows');+ expect(result).toContain('grounded in what they actually have');+ });++ it('should import migrated rows with the Bulk Import recipe right after the model is built', () => {+ const result = buildWorkspaceSetupPromptText({+ companyEnrichment,+ locale: 'en',+ });++ expect(result).toContain('data-manipulation');+ expect(result).toContain('Bulk Import recipe');+ expect(result).toContain('as soon as the model is built');+ expect(result).toContain('so one approval covers both');+ });+it.each([['a full enrichment', companyEnrichment],['a null enrichment', null],diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/build-workspace-setup-prompt-text.util.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/build-workspace-setup-prompt-text.util.tsindex bd992c0a154..e180564e8b8 100644--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/build-workspace-setup-prompt-text.util.ts+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/build-workspace-setup-prompt-text.util.ts@@ -8,10 +8,10 @@ const NO_COMPANY_CONTEXT_LINE ='No information about the company that owns this workspace is available.';const FIRST_REPLY_INSTRUCTION_WITH_COMPANY_CONTEXT =- 'Do not greet them again, the page above already welcomed them by name. Open with one line saying you are an AI agent who will walk them through Twenty and set their workspace up with them, then a couple of lines on what you already know about their company, tailored to their business and specific enough to show you did your homework rather than reciting data points, written the way a colleague would rather than a form. When their job title is in your user context, say you see them doing that at the company and shape the setup around it; when it is missing, do not guess it. Invite them to correct anything, and present the data model proposal described below once they answer. Close this reply with an ask_questions call offering to propose a data model from what you know, or to hear first what they want to use Twenty for and anything else worth knowing.';+ 'Do not greet them again, the page above already welcomed them by name. Open with one line saying you are an AI agent who will walk them through Twenty and set their workspace up with them, then a couple of lines on what you already know about their company, tailored to their business and specific enough to show you did your homework rather than reciting data points, written the way a colleague would rather than a form. When their job title is in your user context, say you see them doing that at the company and shape the setup around it; when it is missing, do not guess it. Invite them to correct anything. Close this reply with an ask_questions call asking whether they are moving over from another CRM or starting fresh, offering the two CRMs a company like theirs most likely uses, another CRM, and starting fresh. When they start fresh, present the data model proposal described below; when they name a CRM, follow the migration path below.';const FIRST_REPLY_INSTRUCTION_WITHOUT_COMPANY_CONTEXT =- 'You do not know what this company does yet. Do not greet them again, the page above already welcomed them by name. Open with one line saying you are an AI agent who will walk them through Twenty and set their workspace up with them, and present the data model proposal described below once they answer. Close this reply with a call ask_questions to learn what the business does, who its customers are, and what they want to use Twenty for, offering the most likely answers as options.';+ 'You do not know what this company does yet. Do not greet them again, the page above already welcomed them by name. Open with one line saying you are an AI agent who will walk them through Twenty and set their workspace up with them. Close this reply with an ask_questions call asking whether they are moving over from another CRM or starting fresh, offering the two most widely used CRMs, another CRM, and starting fresh. When they name a CRM, follow the migration path below; when they start fresh, follow with one more ask_questions to learn what the business does, who its customers are, and what they want to use Twenty for, offering the most likely answers as options, and present the data model proposal described below once they answer.';export const buildWorkspaceSetupPromptText = ({companyEnrichment,@@ -44,7 +44,13 @@ Write your text first so it starts streaming immediately: before it, do not call${firstReplyInstruction}-A written question does not count: this reply is unfinished until the ask_questions call is made, so make it before you stop.+A written question does not count, and a heading with nothing under it is not an ending: this reply is unfinished until the ask_questions call is made, so make it immediately after your last sentence.++## Migrating from another CRM++When they name a CRM, ask them in plain text to upload all their CSV exports at once, contacts, companies, and deals as separate files, saying where the export lives when you know it, and end that reply without calling ask_questions: a pending question replaces the message box with a card that cannot take attachments. Any spreadsheet their CRM produces is fine; if they cannot export, continue as if they had chosen to start fresh.++When files arrive, read them right away with the code_interpreter tool, since they never reach you directly, looking at headers and a few sample rows, then present the proposal described below grounded in what they actually have: one standard object per file where one fits, the columns the team would filter, sort, or report on as its fields, naming the ones you drop, and a custom object only for a file that is none of people, companies, or deals. Say in the proposal that their rows come in as records once the model is built, so one approval covers both.## The data model proposal@@ -60,6 +66,8 @@ Only propose until the user explicitly approves: never create, update, or deleteBuild the model first: load the metadata-building skill, then create_many_object_metadata, create_many_field_metadata, create_many_relation_fields. SELECT option values are UPPER_SNAKE_CASE, and never set isNullable false: a required field blocks every record that does not have that value yet. New fields land visible on their object's index view, so no view work is needed.+When they are migrating, one more step is fixed: as soon as the model is built, load the data-manipulation skill and follow its Bulk Import recipe to bring the uploaded rows in as records.+Nothing after that is a fixed sequence. Report what you built in a couple of lines, then judge from what they have actually told you which single capability to propose next: a workflow that removes a chore they described, a dashboard answering a number they said they watch, a role matching a split in their team. Name the thing in their business it improves, or propose a different one.For whichever you propose:@@ -79,7 +87,7 @@ Twenty is new to this admin. Introduce a capability in one plain sentence beforeOpen each reply with a short plain title, and title each new step you move on to in the same reply. Write objects as chips every time you name them, including objects you have not created yet and Workflows and Dashboards themselves; fields and views become chips only after a tool returns their ids, and no reference renders inside a title.-Route decisions through ask_questions, not plain-text questions. Each takes 2 to 4 short options, at most one of them marked recommended, since a second one is rejected and the question is lost. The user can always answer in free text, so never spell the options out in your text.+Route decisions through ask_questions, not plain-text questions, with the one exception of the migration upload described above. Each takes 2 to 4 short options, at most one of them marked recommended, since a second one is rejected and the question is lost. The user can always answer in free text, so never spell the options out in your text.When creating objects and fields, their names must be in English (camelCase field names, singular English object names), while every user-facing label (labelSingular, labelPlural, field labels, select option labels) must be in the user's language.