Seed 20 Odoo+AI prospects and enforce model-only chat responses

This commit is contained in:
Ruslan Bakiev
2026-02-18 21:50:41 +07:00
parent fdc85d5c42
commit 693faa8621
3 changed files with 293 additions and 157 deletions

View File

@@ -100,6 +100,7 @@ const tabs: { id: TabId; label: string }[] = [
];
const selectedTab = ref<TabId>("communications");
const pilotSettingsOpen = ref(false);
function dayKey(date: Date) {
const y = date.getFullYear();
@@ -221,6 +222,19 @@ const loginPassword = ref("");
const loginError = ref<string | null>(null);
const loginBusy = ref(false);
const userMood = computed(() => {
const hour = new Date().getHours();
if (hour < 12) return "⚡";
if (hour < 18) return "🚀";
return "🌙";
});
const userInitial = computed(() => {
const name = authMe.value?.user?.name?.trim();
if (!name) return "U";
return name.charAt(0).toUpperCase();
});
const activeChatConversation = computed<ChatConversation | null>(() => {
const activeId = authMe.value?.conversation.id;
if (!activeId) return null;
@@ -734,6 +748,13 @@ watchEffect(() => {
const selectedDocument = computed(() => documents.value.find((item) => item.id === selectedDocumentId.value));
function openPilotDocument(docId: string) {
if (!docId) return;
selectedTab.value = "documents";
selectedDocumentId.value = docId;
pilotSettingsOpen.value = false;
}
const peopleLeftMode = ref<PeopleLeftMode>("contacts");
const peopleListMode = ref<"contacts" | "deals">("contacts");
const peopleSearch = ref("");
@@ -1049,6 +1070,12 @@ function openDealThread(deal: Deal) {
}
function openThreadFromCalendarItem(event: CalendarEvent) {
if (!event.contact?.trim()) {
selectedTab.value = "communications";
peopleLeftMode.value = "calendar";
pickDate(event.start.slice(0, 10));
return;
}
openCommunicationThread(event.contact);
selectedCommChannel.value = "All";
}
@@ -1179,8 +1206,8 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</script>
<template>
<div class="min-h-screen p-3 md:p-5">
<div v-if="!authMe" class="flex min-h-[calc(100vh-2.5rem)] items-center justify-center">
<div class="h-[100dvh] overflow-hidden bg-base-200/35">
<div v-if="!authMe" class="flex h-full items-center justify-center px-3">
<div class="card w-full max-w-sm border border-base-300 bg-base-100 shadow-sm">
<div class="card-body p-5">
<h1 class="text-lg font-semibold">Login</h1>
@@ -1210,9 +1237,9 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</div>
<template v-else>
<div class="grid gap-3 lg:grid-cols-12 lg:gap-4">
<aside class="pilot-shell card min-h-0 border border-base-300 shadow-sm lg:col-span-3 lg:sticky lg:top-5 lg:h-[calc(100vh-2.5rem)]">
<div class="card-body h-full min-h-0 p-0">
<div class="grid h-full min-h-0 grid-cols-1 gap-0 lg:grid-cols-[320px_minmax(0,1fr)]">
<aside class="pilot-shell min-h-0 border-r border-base-300">
<div class="flex h-full min-h-0 flex-col p-0">
<div class="pilot-header">
<div>
<h2 class="text-sm font-semibold uppercase tracking-wide text-white/75">Pilot Chat</h2>
@@ -1220,7 +1247,31 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
{{ authMe.team.name }} · {{ authMe.user.name }} · {{ authMe.conversation.title }}
</p>
</div>
<button class="btn btn-ghost btn-xs text-white/80 hover:bg-white/10" @click="logout">Logout</button>
<button
class="btn btn-ghost btn-xs btn-square text-white/80 hover:bg-white/10"
title="Pilot settings"
@click="pilotSettingsOpen = !pilotSettingsOpen"
>
<svg viewBox="0 0 24 24" class="h-4 w-4 fill-current">
<path d="M19.14 12.94a7.43 7.43 0 0 0 .05-.94 7.43 7.43 0 0 0-.05-.94l2.03-1.58a.5.5 0 0 0 .12-.64l-1.92-3.32a.5.5 0 0 0-.6-.22l-2.39.96a7.28 7.28 0 0 0-1.62-.94l-.36-2.54A.5.5 0 0 0 14.9 2h-3.8a.5.5 0 0 0-.49.42l-.36 2.54c-.58.22-1.12.53-1.62.94l-2.39-.96a.5.5 0 0 0-.6.22L3.72 8.84a.5.5 0 0 0 .12.64l2.03 1.58c-.03.31-.05.63-.05.94s.02.63.05.94l-2.03 1.58a.5.5 0 0 0-.12.64l1.92 3.32c.13.23.4.32.64.22l2.39-.96c.5.41 1.04.72 1.62.94l.36 2.54c.04.24.25.42.49.42h3.8c.24 0 .45-.18.49-.42l.36-2.54c.58-.22 1.12-.53 1.62-.94l2.39.96c.24.1.51.01.64-.22l1.92-3.32a.5.5 0 0 0-.12-.64zM13 15.5A3.5 3.5 0 1 1 13 8.5a3.5 3.5 0 0 1 0 7z" />
</svg>
</button>
</div>
<div v-if="pilotSettingsOpen" class="pilot-settings-panel">
<p class="text-[11px] font-semibold uppercase tracking-wide text-white/65">Pilot Settings</p>
<p class="mt-1 text-xs text-white/70">Prompt sources from workspace documents.</p>
<div class="mt-2 max-h-44 space-y-1 overflow-y-auto pr-1">
<button
v-for="doc in documents.slice(0, 10)"
:key="`pilot-doc-${doc.id}`"
class="w-full rounded-lg border border-white/10 bg-white/5 px-2 py-1.5 text-left text-xs text-white/85 transition hover:bg-white/10"
@click="openPilotDocument(doc.id)"
>
<p class="truncate font-medium">{{ doc.title }}</p>
<p class="truncate text-[11px] text-white/55">{{ doc.type }} · {{ doc.owner }}</p>
</button>
<p v-if="documents.length === 0" class="text-xs text-white/55">No documents yet.</p>
</div>
</div>
<div class="pilot-threads">
@@ -1327,10 +1378,22 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</div>
</aside>
<main class="card border border-base-300 bg-base-100 shadow-sm lg:col-span-9">
<div class="card-body flex flex-col p-3 pb-20 md:p-4 md:pb-24">
<div class="flex-1">
<section v-if="selectedTab === 'communications' && peopleLeftMode === 'calendar'" class="space-y-3">
<main class="min-h-0 bg-base-100">
<div class="flex h-full min-h-0 flex-col pb-20 md:pb-24">
<div class="workspace-topbar border-b border-base-300 px-3 py-2 md:px-4">
<div class="ml-auto flex items-center gap-2">
<div class="inline-flex items-center gap-2 rounded-xl border border-base-300 bg-base-100 px-2 py-1.5">
<div class="inline-flex h-8 w-8 items-center justify-center rounded-full bg-primary/15 text-sm font-semibold text-primary">{{ userInitial }}</div>
<div class="min-w-0">
<p class="truncate text-xs font-semibold">{{ authMe.user.name }} {{ userMood }}</p>
<p class="truncate text-[11px] text-base-content/60">{{ authMe.user.phone }}</p>
</div>
</div>
<button class="btn btn-sm btn-outline" @click="logout">Logout</button>
</div>
</div>
<div class="min-h-0 flex-1 p-3 md:p-4">
<section v-if="selectedTab === 'communications' && peopleLeftMode === 'calendar'" class="flex h-full min-h-0 flex-col gap-3">
<div class="mb-1 flex justify-end">
<div class="join">
<button class="btn btn-sm join-item btn-ghost" @click="peopleLeftMode = 'contacts'">Contacts</button>
@@ -1361,6 +1424,7 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</div>
</div>
<div class="min-h-0 flex-1 overflow-y-auto pr-1">
<div v-if="calendarView === 'month'" class="space-y-1">
<div class="grid grid-cols-7 gap-1 text-center text-xs font-semibold text-base-content/60">
<span>Sun</span>
@@ -1384,9 +1448,14 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
@click="pickDate(cell.key)"
>
<p class="mb-1 text-xs font-semibold">{{ cell.day }}</p>
<p v-for="event in cell.events.slice(0, 2)" :key="event.id" class="truncate text-[10px] text-base-content/70">
<button
v-for="event in cell.events.slice(0, 2)"
:key="event.id"
class="block w-full truncate text-left text-[10px] text-base-content/70 hover:underline"
@click.stop="openThreadFromCalendarItem(event)"
>
{{ formatTime(event.start) }} {{ event.title }}
</p>
</button>
</button>
</div>
</div>
@@ -1401,21 +1470,31 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
>
<p class="mb-2 text-sm font-semibold">{{ day.label }} {{ day.day }}</p>
<div class="space-y-1">
<p v-for="event in day.events" :key="event.id" class="rounded bg-base-200 px-2 py-1 text-xs">
<button
v-for="event in day.events"
:key="event.id"
class="block w-full rounded bg-base-200 px-2 py-1 text-left text-xs hover:bg-base-300/80"
@click.stop="openThreadFromCalendarItem(event)"
>
{{ formatTime(event.start) }} - {{ event.title }} ({{ event.contact }})
</p>
</button>
<p v-if="day.events.length === 0" class="text-xs text-base-content/50">No events</p>
</div>
</article>
</div>
<div v-else-if="calendarView === 'day'" class="space-y-2">
<article v-for="event in selectedDayEvents" :key="event.id" class="rounded-xl border border-base-300 p-3">
<button
v-for="event in selectedDayEvents"
:key="event.id"
class="block w-full rounded-xl border border-base-300 p-3 text-left transition hover:bg-base-200/60"
@click="openThreadFromCalendarItem(event)"
>
<p class="font-medium">{{ event.title }}</p>
<p class="text-xs text-base-content/60">{{ event.contact }}</p>
<p class="text-xs text-base-content/60">{{ formatTime(event.start) }} - {{ formatTime(event.end) }}</p>
<p class="mt-1 text-sm text-base-content/80">{{ event.note }}</p>
</article>
</button>
<p v-if="selectedDayEvents.length === 0" class="text-sm text-base-content/60">No events on this day.</p>
</div>
@@ -1428,19 +1507,29 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
>
<p class="font-medium">{{ item.label }}</p>
<p class="text-xs text-base-content/60">{{ item.count }} events</p>
<p v-if="item.first" class="mt-1 text-xs text-base-content/70">
<button
v-if="item.first"
class="mt-1 block w-full text-left text-xs text-base-content/70 hover:underline"
@click.stop="openThreadFromCalendarItem(item.first)"
>
{{ formatDay(item.first.start) }} · {{ item.first.title }}
</p>
</button>
</button>
</div>
<div v-else class="space-y-2">
<article v-for="event in sortedEvents" :key="event.id" class="rounded-xl border border-base-300 p-3">
<button
v-for="event in sortedEvents"
:key="event.id"
class="block w-full rounded-xl border border-base-300 p-3 text-left transition hover:bg-base-200/60"
@click="openThreadFromCalendarItem(event)"
>
<p class="font-medium">{{ event.title }}</p>
<p class="text-xs text-base-content/60">{{ event.contact }}</p>
<p class="text-xs text-base-content/60">{{ formatDay(event.start) }} · {{ formatTime(event.start) }} - {{ formatTime(event.end) }}</p>
<p class="mt-1 text-sm text-base-content/80">{{ event.note }}</p>
</article>
</button>
</div>
</div>
</section>
@@ -1623,15 +1712,15 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</div>
</section>
<section v-else-if="selectedTab === 'communications' && peopleLeftMode === 'contacts'" class="space-y-3">
<section v-else-if="selectedTab === 'communications' && peopleLeftMode === 'contacts'" class="flex h-full min-h-0 flex-col gap-3">
<div class="mb-1 flex justify-end">
<div class="join">
<button class="btn btn-sm join-item btn-primary" @click="peopleLeftMode = 'contacts'">Contacts</button>
<button class="btn btn-sm join-item btn-ghost" @click="peopleLeftMode = 'calendar'">Calendar</button>
</div>
</div>
<div class="grid gap-3 md:grid-cols-[220px_minmax(0,1fr)_320px]">
<aside class="min-h-0 rounded-xl border border-base-300">
<div class="grid min-h-0 flex-1 gap-0 md:grid-cols-[220px_minmax(0,1fr)_320px]">
<aside class="min-h-0 border-r border-base-300 flex flex-col">
<div class="sticky top-0 z-20 border-b border-base-300 bg-base-100 p-2">
<div class="mb-2 flex items-center gap-1">
<button
@@ -1687,7 +1776,7 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</div>
</div>
<div class="min-h-0 space-y-1.5 overflow-y-auto p-2">
<div class="min-h-0 flex-1 space-y-1.5 overflow-y-auto p-2">
<button
v-if="peopleListMode === 'contacts'"
v-for="thread in peopleContactList"
@@ -1752,7 +1841,7 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</div>
</aside>
<article class="min-h-0 rounded-xl border border-base-300">
<article class="min-h-0 border-r border-base-300 flex flex-col">
<div v-if="false" class="p-3">
<div class="grid grid-cols-[auto_1fr_auto] items-center gap-2">
<div class="flex items-center gap-1">
@@ -1881,7 +1970,7 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</div>
</div>
<div v-else-if="selectedCommThread" class="relative flex flex-col p-3">
<div v-else-if="selectedCommThread" class="relative flex h-full min-h-0 flex-col p-3">
<div class="mb-3 flex items-start justify-between gap-2 border-b border-base-300 pb-2">
<div>
<p class="font-medium">{{ selectedCommThread.contact }}</p>
@@ -1933,7 +2022,7 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</button>
</div>
<div class="space-y-2 pr-1">
<div class="min-h-0 flex-1 space-y-2 overflow-y-auto pr-1">
<div v-for="entry in threadStreamItems" :key="entry.id">
<div v-if="entry.kind === 'call'" class="flex justify-center">
<div class="call-wave-card w-full max-w-[460px] rounded-2xl border border-base-300 px-4 py-3 text-center">
@@ -2036,8 +2125,8 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</div>
</article>
<aside class="min-h-0 rounded-xl border border-base-300">
<div v-if="selectedWorkspaceContact" class="h-full p-3">
<aside class="min-h-0">
<div v-if="selectedWorkspaceContact" class="flex h-full min-h-0 flex-col p-3">
<div class="mb-3 flex items-start justify-between gap-2 border-b border-base-300 pb-2">
<div>
<p class="font-medium">{{ selectedWorkspaceContact.name }}</p>
@@ -2058,6 +2147,7 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</button>
</div>
<div class="min-h-0 flex-1 overflow-y-auto pr-1">
<div v-if="rightSidebarMode === 'pinned'" class="space-y-2">
<article
v-for="item in selectedCommPinnedStream"
@@ -2106,6 +2196,7 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
/>
</div>
</template>
</div>
</div>
<div v-else class="flex h-full items-center justify-center text-sm text-base-content/60">
@@ -2115,7 +2206,7 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</div>
</section>
<section v-else-if="selectedTab === 'documents'" class="space-y-3">
<section v-else-if="selectedTab === 'documents'" class="flex h-full min-h-0 flex-col gap-3">
<div class="rounded-xl border border-base-300 p-3">
<div class="grid gap-2 md:grid-cols-[1fr_220px]">
<label class="form-control">
@@ -2137,9 +2228,9 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</div>
</div>
<div class="grid gap-3 md:grid-cols-12">
<aside class="min-h-0 rounded-xl border border-base-300 md:col-span-4">
<div class="min-h-0 space-y-2 overflow-y-auto p-2">
<div class="grid min-h-0 flex-1 gap-0 md:grid-cols-12">
<aside class="min-h-0 border-r border-base-300 md:col-span-4 flex flex-col">
<div class="min-h-0 flex-1 space-y-2 overflow-y-auto p-2">
<button
v-for="doc in filteredDocuments"
:key="doc.id"
@@ -2155,8 +2246,8 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
</div>
</aside>
<article class="min-h-0 rounded-xl border border-base-300 md:col-span-8">
<div v-if="selectedDocument" class="p-3 md:p-4">
<article class="min-h-0 md:col-span-8 flex flex-col">
<div v-if="selectedDocument" class="flex h-full min-h-0 flex-col p-3 md:p-4">
<div class="border-b border-base-300 pb-2">
<p class="font-medium">{{ selectedDocument.title }}</p>
<p class="text-xs text-base-content/60">
@@ -2165,7 +2256,7 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
<p class="mt-1 text-sm text-base-content/80">{{ selectedDocument.summary }}</p>
</div>
<div class="mt-3">
<div class="mt-3 min-h-0 flex-1 overflow-y-auto">
<ContactCollaborativeEditor
:key="`doc-editor-${selectedDocument.id}`"
v-model="selectedDocument.body"
@@ -2226,12 +2317,19 @@ async function decideFeedCard(card: FeedCard, decision: "accepted" | "rejected")
.pilot-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
padding: 12px;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
background: rgba(8, 10, 16, 0.2);
}
.pilot-settings-panel {
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
background: rgba(8, 10, 16, 0.34);
padding: 10px;
}
.pilot-threads {
padding: 10px 10px 8px;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);

View File

@@ -55,52 +55,44 @@ function plusMinutes(date, minutes) {
return d;
}
function buildContacts(teamId, count) {
const firstNames = [
"Alex", "Mia", "Leo", "Sofia", "Noah", "Emma", "Liam", "Ava", "Ethan", "Luna",
"Mason", "Chloe", "Logan", "Mila", "Lucas", "Nora", "Elijah", "Zoey", "James", "Aria",
"Daniel", "Nina", "Henry", "Layla", "Oliver", "Iris", "Oscar", "Diana", "Max", "Eva",
];
const lastNames = [
"Carter", "Meyer", "Ali", "Petrov", "Rivera", "Ivanova", "Fisher", "Khan", "Wright", "Cole",
"Silva", "Morris", "King", "Anderson", "Lopez", "Walker", "Young", "Scott", "Green", "Parker",
];
const companies = [
"Northline", "Connecta", "Volta", "Blueport", "Skyline", "PrimeGrid", "Helio", "CoreLabs", "NovaTrade", "Astera",
];
const locations = [
{ country: "USA", city: "New York" },
{ country: "USA", city: "Austin" },
{ country: "Germany", city: "Berlin" },
{ country: "UAE", city: "Dubai" },
{ country: "Spain", city: "Barcelona" },
{ country: "Armenia", city: "Yerevan" },
{ country: "UK", city: "London" },
{ country: "France", city: "Paris" },
{ country: "Singapore", city: "Singapore" },
{ country: "Canada", city: "Toronto" },
function buildOdooAiContacts(teamId) {
const prospects = [
{ name: "Olivia Reed", company: "RetailNova", country: "USA", location: "New York", email: "olivia.reed@retailnova.com", phone: "+1 555 120 0101" },
{ name: "Daniel Kim", company: "ForgePeak Manufacturing", country: "USA", location: "Chicago", email: "daniel.kim@forgepeak.com", phone: "+1 555 120 0102" },
{ name: "Marta Alonso", company: "Iberia Foods Group", country: "Spain", location: "Barcelona", email: "marta.alonso@iberiafoods.es", phone: "+34 91 555 0103" },
{ name: "Youssef Haddad", company: "GulfTrade Distribution", country: "UAE", location: "Dubai", email: "youssef.haddad@gulftrade.ae", phone: "+971 4 555 0104" },
{ name: "Emma Collins", company: "NorthBridge Logistics", country: "UK", location: "London", email: "emma.collins@northbridge.co.uk", phone: "+44 20 5550 0105" },
{ name: "Noah Fischer", company: "Bergmann Auto Parts", country: "Germany", location: "Munich", email: "noah.fischer@bergmann-auto.de", phone: "+49 89 5550 0106" },
{ name: "Ava Choi", company: "Pacific MedTech Supply", country: "Singapore", location: "Singapore", email: "ava.choi@pacificmedtech.sg", phone: "+65 6555 0107" },
{ name: "Liam Dubois", company: "HexaCommerce", country: "France", location: "Paris", email: "liam.dubois@hexacommerce.fr", phone: "+33 1 55 50 0108" },
{ name: "Maya Shah", company: "Zenith Consumer Brands", country: "Canada", location: "Toronto", email: "maya.shah@zenithbrands.ca", phone: "+1 416 555 0109" },
{ name: "Arman Petrosyan", company: "Ararat Electronics", country: "Armenia", location: "Yerevan", email: "arman.petrosyan@ararat-electronics.am", phone: "+374 10 555110" },
{ name: "Sophia Martinez", company: "Sunline Home Goods", country: "USA", location: "Austin", email: "sophia.martinez@sunlinehg.com", phone: "+1 555 120 0111" },
{ name: "Leo Novak", company: "CentralBuild Materials", country: "Germany", location: "Berlin", email: "leo.novak@centralbuild.de", phone: "+49 30 5550 0112" },
{ name: "Isla Grant", company: "BlueHarbor Pharma", country: "UK", location: "Manchester", email: "isla.grant@blueharbor.co.uk", phone: "+44 161 555 0113" },
{ name: "Mateo Rossi", company: "Milano Fashion House", country: "Italy", location: "Milan", email: "mateo.rossi@milanofh.it", phone: "+39 02 5550 0114" },
{ name: "Nina Volkova", company: "Polar AgriTech", country: "Kazakhstan", location: "Almaty", email: "nina.volkova@polaragri.kz", phone: "+7 727 555 0115" },
{ name: "Ethan Park", company: "Vertex Components", country: "South Korea", location: "Seoul", email: "ethan.park@vertexcomponents.kr", phone: "+82 2 555 0116" },
{ name: "Zara Khan", company: "Crescent Retail Chain", country: "UAE", location: "Abu Dhabi", email: "zara.khan@crescentretail.ae", phone: "+971 2 555 0117" },
{ name: "Hugo Silva", company: "Luso Industrial Systems", country: "Portugal", location: "Lisbon", email: "hugo.silva@lusois.pt", phone: "+351 21 555 0118" },
{ name: "Chloe Bernard", company: "Santex Clinics Network", country: "France", location: "Lyon", email: "chloe.bernard@santex.fr", phone: "+33 4 55 50 0119" },
{ name: "James Walker", company: "Metro Wholesale Group", country: "USA", location: "Los Angeles", email: "james.walker@metrowholesale.com", phone: "+1 555 120 0120" },
];
const rows = [];
for (let i = 0; i < count; i += 1) {
const first = firstNames[i % firstNames.length];
const last = lastNames[Math.floor(i / firstNames.length) % lastNames.length];
const company = `${companies[i % companies.length]} ${String.fromCharCode(65 + (i % 26))}`;
const loc = locations[i % locations.length];
const female = i % 2 === 0;
const picIdx = (i % 70) + 1;
rows.push({
return prospects.map((p, idx) => {
const female = idx % 2 === 0;
const picIdx = (idx % 70) + 1;
return {
teamId,
name: `${first} ${last} ${i + 1}`,
company,
country: loc.country,
location: loc.city,
name: p.name,
company: p.company,
country: p.country,
location: p.location,
avatarUrl: `https://randomuser.me/api/portraits/${female ? "women" : "men"}/${picIdx}.jpg`,
email: `${first.toLowerCase()}.${last.toLowerCase()}${i + 1}@${company.toLowerCase().replace(/\s+/g, "")}.example`,
phone: `+1 555 01${String(i).padStart(4, "0")}`,
});
}
return rows;
email: p.email,
phone: p.phone,
};
});
}
async function main() {
@@ -152,18 +144,27 @@ async function main() {
]);
const contacts = await prisma.contact.createManyAndReturn({
data: buildContacts(team.id, 220),
data: buildOdooAiContacts(team.id),
select: { id: true, name: true, company: true },
});
const integrationModules = [
"Sales + CRM + forecasting copilot",
"Inventory + demand prediction",
"Purchase + supplier risk scoring",
"Accounting + AI anomaly detection",
"Helpdesk + ticket triage assistant",
"Manufacturing + production planning AI",
];
await prisma.contactNote.createMany({
data: contacts.map((c, idx) => ({
contactId: c.id,
content:
`Summary for ${c.name}. Main objective: move the account to a predictable weekly rhythm. ` +
`Current context: ${c.company ?? "Account"} is active in at least one channel. ` +
`Recommended path: keep messages short, lock a concrete next step, and update the note after each interaction. ` +
`Priority signal ${idx % 5 === 0 ? "high" : "normal"}.`,
`${c.company ?? c.name} is evaluating Odoo implementation with AI extensions. ` +
`Primary integration scope: ${integrationModules[idx % integrationModules.length]}. ` +
`Main buying trigger: reduce manual operations and shorten decision cycles. ` +
`Next milestone: run discovery workshop, confirm data owners, and approve pilot KPI pack.`,
})),
});
@@ -178,7 +179,7 @@ async function main() {
kind: "MESSAGE",
direction: "IN",
channel: channels[i % channels.length],
content: `Hi, this is ${contact.name}. Can we sync on timeline this week?`,
content: `Hi, we are reviewing Odoo + AI rollout for ${contact.company}. Can we align on integration timeline this week?`,
occurredAt: base,
});
@@ -187,7 +188,7 @@ async function main() {
kind: "MESSAGE",
direction: "OUT",
channel: channels[(i + 1) % channels.length],
content: `Sure. I suggest two slots and a clear agenda.`,
content: "Sure. I suggest a 45-min discovery focused on workflows, API constraints, and pilot KPIs.",
occurredAt: plusMinutes(base, 22),
});
@@ -196,21 +197,21 @@ async function main() {
kind: "MESSAGE",
direction: i % 3 === 0 ? "OUT" : "IN",
channel: channels[(i + 2) % channels.length],
content: `Status update: legal owner and decision date are the two blockers now.`,
content: "Status update: technical scope is clear; blocker is budget owner approval and security questionnaire.",
occurredAt: plusMinutes(base, 65),
});
if (i % 4 === 0) {
if (i % 3 === 0) {
contactMessages.push({
contactId: contact.id,
kind: "CALL",
direction: "OUT",
channel: "PHONE",
content: "Voice call from CRM",
content: "Discovery call: Odoo modules, data flows, AI use-cases",
durationSec: 180 + ((i * 23) % 420),
transcriptJson: [
`${contact.name}: We need a clear owner for approval.`,
`You: Agreed, let's lock this today and set the next checkpoint.`,
`${contact.name}: We need phased rollout, starting from Sales and Inventory.`,
"You: Agreed. We can run a 6-week pilot with KPI baseline and weekly checkpoints.",
],
occurredAt: plusMinutes(base, 110),
});
@@ -226,39 +227,42 @@ async function main() {
{
teamId: team.id,
contactId: c.id,
title: `Follow-up with ${c.name}`,
title: `Discovery: Odoo + AI with ${c.company ?? c.name}`,
startsAt: firstStart,
endsAt: plusMinutes(firstStart, 30),
note: "Confirm owner, timeline, and next concrete action.",
note: "Confirm integration scope, current stack, and pilot success metrics.",
status: "planned",
},
{
teamId: team.id,
contactId: c.id,
title: `Checkpoint: ${c.company ?? c.name}`,
title: `Architecture workshop: ${c.company ?? c.name}`,
startsAt: secondStart,
endsAt: plusMinutes(secondStart, 45),
note: "Review progress and unblock pending decisions.",
note: "Review API mapping, ETL boundaries, and AI assistant guardrails.",
status: idx % 6 === 0 ? "done" : "planned",
},
];
}),
});
const stages = ["Qualification", "Proposal", "Negotiation", "Contract"];
const stages = ["Lead", "Discovery", "Solution Fit", "Proposal", "Negotiation", "Pilot", "Contract Review"];
await prisma.deal.createMany({
data: contacts
.filter((_, idx) => idx % 5 !== 0)
.map((c, idx) => ({
data: contacts.map((c, idx) => ({
teamId: team.id,
contactId: c.id,
title: `${c.company ?? "Account"} expansion`,
title: `${c.company ?? "Account"} Odoo + AI integration`,
stage: stages[idx % stages.length],
amount: 8000 + (idx % 17) * 1500,
nextStep: "Lock next sync and owner on client side.",
summary: "Deal is active. Focus on speed and explicit decision checkpoints.",
amount: 18000 + (idx % 8) * 7000,
nextStep:
idx % 4 === 0
? "Send pilot proposal and finalize integration backlog."
: "Run solution workshop and align commercial owner on timeline.",
summary:
"Potential deal for phased Odoo implementation with AI copilots for ops, sales, and planning. " +
"Commercial model: discovery + pilot + rollout.",
})),
});
});
await prisma.contactPin.createMany({
data: contacts.map((c, idx) => ({
@@ -266,8 +270,8 @@ async function main() {
contactId: c.id,
text:
idx % 3 === 0
? "Pinned: calendar event is near, prepare a concise follow-up note."
: "Pinned: keep one explicit ask in each message.",
? "Pinned: ask for ERP owner, data owner, and target go-live quarter."
: "Pinned: keep communication around one KPI and one next action.",
})),
});
@@ -281,14 +285,14 @@ async function main() {
contactId: c.id,
happenedAt: atOffset(-(idx % 6), 9 + (idx % 8), (idx * 9) % 60),
text:
`I analyzed the latest contact activity for ${c.name}. ` +
`There is enough momentum to push one concrete action now and reduce response latency.`,
`I reviewed ${c.company ?? c.name} account activity for the Odoo + AI opportunity. ` +
"There is enough momentum to move the deal one stage with a concrete next action.",
proposalJson: {
title: idx % 2 === 0 ? "Add focused follow-up event" : "Draft a concise unblock message",
title: idx % 2 === 0 ? "Schedule pilot scoping call" : "Send unblock note for budget owner",
details: [
`Contact: ${c.name}`,
idx % 2 === 0 ? "Timing: in the next 60 minutes" : "Timing: send in the primary active channel",
"Goal: lock owner and next exact date",
idx % 2 === 0 ? "Timing: this week, 45 minutes" : "Timing: today in primary channel",
"Goal: confirm scope, owner, and next commercial checkpoint",
],
key: proposalKeys[idx % proposalKeys.length],
},
@@ -299,62 +303,62 @@ async function main() {
data: [
{
teamId: team.id,
title: "Response time regulation",
title: "Odoo integration discovery checklist",
type: "Regulation",
owner: "Revenue Ops",
scope: "All active deals",
summary: "Rules for first response and follow-up SLA across channels.",
body: "## SLA\n- First response in under 30 minutes for active threads.\n- Escalate if no owner is assigned.\n\n## Rule\nAlways end a message with one explicit next step.",
owner: "Solution Team",
scope: "Pre-sale discovery",
summary: "Mandatory questions before estimation of Odoo + AI rollout.",
body: "## Must capture\n- Current ERP modules\n- Integration endpoints\n- Data owner per domain\n- Security constraints\n- Pilot KPI baseline",
updatedAt: atOffset(-1, 11, 10),
},
{
teamId: team.id,
title: "Discovery playbook",
title: "AI copilot playbook for Odoo",
type: "Playbook",
owner: "Sales Lead",
scope: "Discovery and qualification",
summary: "Consistent structure for discovery calls and follow-up notes.",
body: "## Flow\n1. Pain\n2. Impact\n3. Owner\n4. Timeline\n5. Next step\n\n## Output\nStore concise summary in the contact card.",
owner: "AI Practice Lead",
scope: "Use-case qualification",
summary: "How to position forecasting, assistant, and anomaly detection features.",
body: "## Flow\n1. Process pain\n2. Data quality\n3. Model target\n4. Success KPI\n5. Pilot scope",
updatedAt: atOffset(-2, 15, 0),
},
{
teamId: team.id,
title: "AI action policy",
title: "Pilot pricing matrix",
type: "Policy",
owner: "Founders",
scope: "AI recommendations",
summary: "What can be auto-drafted and what always needs explicit approval.",
body: "## Allowed\n- Draft suggestions\n- Summaries\n\n## Requires approval\n- Outbound send\n- Event creation\n- Deal stage change",
owner: "Commercial Ops",
scope: "Discovery and pilot contracts",
summary: "Price ranges for discovery, pilot, and production rollout phases.",
body: "## Typical ranges\n- Discovery: 5k-12k\n- Pilot: 15k-45k\n- Rollout: 50k+\n\nAlways tie cost to scope and timeline.",
updatedAt: atOffset(-3, 9, 30),
},
{
teamId: team.id,
title: "Post-call template",
title: "Security and compliance template",
type: "Template",
owner: "Enablement",
scope: "Any completed call",
summary: "Template for short post-call summary with owners and deadlines.",
body: "## Template\n- Aligned\n- Open items\n- Owner per action\n- Next date\n\nKeep it under 6 lines.",
owner: "Delivery Office",
scope: "Enterprise prospects",
summary: "Template answers for data residency, RBAC, audit trail, and PII handling.",
body: "## Sections\n- Hosting model\n- Access control\n- Logging and audit\n- Data retention\n- Incident response",
updatedAt: atOffset(-4, 13, 45),
},
{
teamId: team.id,
title: "Objection handling map",
title: "Integration architecture blueprint",
type: "Playbook",
owner: "Commercial",
scope: "Late-stage objections",
summary: "Common objections and concise response strategy.",
body: "## Objections\n- Timing\n- Budget\n- Legal\n\n## Response\nAcknowledge, clarify owner, set a concrete checkpoint.",
owner: "Architecture Team",
scope: "Technical workshops",
summary: "Reference architecture for Odoo connectors, ETL, and AI service layer.",
body: "## Layers\n- Odoo core modules\n- Integration bus\n- Data warehouse\n- AI service endpoints\n- Monitoring",
updatedAt: atOffset(-5, 10, 0),
},
{
teamId: team.id,
title: "Pipeline hygiene",
title: "Go-live readiness checklist",
type: "Regulation",
owner: "Operations",
scope: "Pipeline updates",
summary: "Minimal mandatory updates after each interaction.",
body: "## Required\n- Last touch timestamp\n- Next step\n- Risk marker\n\nNo long forms, only concise text.",
owner: "PMO",
scope: "Pilot to production transition",
summary: "Checklist to move from pilot acceptance to production launch.",
body: "## Required\n- Pilot KPIs approved\n- Rollout backlog prioritized\n- Owners assigned\n- Support model defined",
updatedAt: atOffset(-6, 16, 15),
},
],

View File

@@ -856,30 +856,64 @@ export async function runLangGraphCrmAgentFor(input: {
{ recursionLimit: 30 },
);
const extractText = (value: unknown, depth = 0): string => {
if (depth > 5 || value == null) return "";
if (typeof value === "string") return value.trim();
if (Array.isArray(value)) {
const parts = value
.map((item) => extractText(item, depth + 1))
.filter(Boolean);
return parts.join("\n").trim();
}
if (typeof value !== "object") return "";
const obj = value as Record<string, unknown>;
for (const key of ["text", "content", "answer", "output_text", "final_text"]) {
const text = extractText(obj[key], depth + 1);
if (text) return text;
}
if (Array.isArray(obj.parts)) {
const text = extractText(obj.parts, depth + 1);
if (text) return text;
}
return "";
};
const messageType = (msg: any): string => {
if (typeof msg?._getType === "function") {
try {
return String(msg._getType() ?? "");
} catch {
// ignore
}
}
return String(msg?.type ?? msg?.role ?? msg?.constructor?.name ?? "");
};
const structured = res?.structuredResponse as { answer?: string; plan?: string[] } | undefined;
const fallbackText = (() => {
const messages = Array.isArray(res?.messages) ? res.messages : [];
for (let i = messages.length - 1; i >= 0; i -= 1) {
const msg = messages[i];
const type = String(msg?.type ?? "").toLowerCase();
if (type !== "ai") continue;
const content = msg?.content;
if (typeof content === "string" && content.trim()) return content.trim();
if (Array.isArray(content)) {
const text = content
.map((part: any) => (typeof part?.text === "string" ? part.text : ""))
.filter(Boolean)
.join("\n")
.trim();
if (text) return text;
}
const type = messageType(msg).toLowerCase();
if (!type.includes("ai") && !type.includes("assistant")) continue;
const text = extractText(msg?.content) || extractText(msg);
if (text) return text;
}
return "";
return (
extractText(res?.output) ||
extractText(res?.response) ||
extractText(res?.finalResponse) ||
""
);
})();
const text = structured?.answer?.trim() || fallbackText || "Готово.";
const plan = Array.isArray(structured?.plan) && structured.plan.length
? structured.plan
: ["Собрать данные", "Сформировать ответ"];
const text = structured?.answer?.trim() || fallbackText;
if (!text) {
throw new Error("Model returned empty response");
}
const plan = Array.isArray(structured?.plan) ? structured.plan : [];
return {
text,