From 78e38e9add874bfe1dbc6f232737d475780882f6 Mon Sep 17 00:00:00 2001 From: Simon Axelsson Date: Thu, 25 Jun 2026 01:59:56 +0200 Subject: [PATCH] feat: full service catalog + custom-job intake (describe -> AI-assist -> order) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lib/services (11 categories: data, scraping, mapping, normalization, consolidation->CRM/ERP, documents/OCR, enrichment, ICP, ML, BI, feeds across the 3 flows); /tjanster catalog; /bestall/beskriv NL intake; /api/ai/parse (engine LLM or heuristic NL->config); CRM/ERP destinations; Tjänster in nav. Sells every custom data service through the platform. tsc 0, build green. Co-Authored-By: Claude Opus 4.8 --- app/api/ai/parse/route.ts | 57 +++++++++++++++ app/bestall/beskriv/page.tsx | 132 +++++++++++++++++++++++++++++++++++ app/tjanster/page.tsx | 73 +++++++++++++++++++ components/header.tsx | 1 + lib/services.ts | 42 +++++++++++ 5 files changed, 305 insertions(+) create mode 100644 app/api/ai/parse/route.ts create mode 100644 app/bestall/beskriv/page.tsx create mode 100644 app/tjanster/page.tsx create mode 100644 lib/services.ts diff --git a/app/api/ai/parse/route.ts b/app/api/ai/parse/route.ts new file mode 100644 index 0000000..e4f94e6 --- /dev/null +++ b/app/api/ai/parse/route.ts @@ -0,0 +1,57 @@ +import { NextRequest, NextResponse } from "next/server"; +import { engineFetch } from "@/lib/engine"; + +// POST /api/ai/parse (docs/04) — natural-language need -> prefilled order config. +// Uses the engine's LLM when available; otherwise a transparent keyword heuristic. +const MARKETS: [RegExp, string][] = [ + [/sverige|svensk|\bse\b/i, "SE"], [/norge|norsk|\bno\b/i, "NO"], [/danmark|dansk|\bdk\b/i, "DK"], + [/finland|finsk|\bfi\b/i, "FI"], [/tyskland|\bde\b/i, "DE"], [/storbritannien|\buk\b|\bgb\b/i, "GB"], +]; +const SERVICE: [RegExp, string][] = [ + [/skrap|scrap/i, "scraping"], [/mappa|matcha|match|koppla/i, "mapping"], + [/normaliser|städ|dedup|tvätta/i, "normalization"], [/konsolider|crm|erp|hubspot|salesforce|dynamics|pipedrive|fivecrm/i, "consolidation"], + [/dokument|ocr|pdf|scann/i, "documents"], [/berik|enrich/i, "enrichment"], + [/\bicp\b|leads?|målgrupp|beslutsfattare/i, "icp"], [/\bml\b|modell|scoring|prognos|kluster/i, "ml"], + [/\bbi\b|dashboard|analys|marknadsanalys/i, "bi"], [/flöde|feed|övervak|freshness/i, "feeds"], +]; +const FIELDS: [RegExp, string][] = [ + [/e-?post|email|mejl|kontakt|telefon/i, "contact"], [/omsättning|finans|bokslut|resultat|nyckeltal/i, "financials"], + [/lei|cross-?border/i, "lei"], [/huvudman|ubo|ägar/i, "ubo"], [/intent|köpsignal|signal/i, "intent"], +]; +const DEST: [RegExp, string][] = [ + [/hubspot/i, "HubSpot"], [/salesforce/i, "Salesforce"], [/dynamics/i, "Microsoft Dynamics"], + [/pipedrive/i, "Pipedrive"], [/fivecrm/i, "FiveCRM"], [/sheets/i, "Google Sheets"], +]; + +export async function POST(req: NextRequest) { + const { text } = await req.json().catch(() => ({ text: "" })); + if (!text) return NextResponse.json({ error: { code: "bad_request", message: "text krävs" } }, { status: 400 }); + + const eng = await engineFetch("/ai/parse", { method: "POST", body: JSON.stringify({ text }) }); + if (eng && eng.ok) return NextResponse.json(await eng.json()); + + const pick = (table: [RegExp, string][]) => table.filter(([re]) => re.test(text)).map(([, v]) => v); + const markets = [...new Set(pick(MARKETS))]; + const service = pick(SERVICE)[0] ?? "data"; + const fields = [...new Set(pick(FIELDS))]; + const destination = pick(DEST)[0] ?? null; + const volMatch = text.replace(/\s/g, "").match(/(\d{3,})/); + const volume = volMatch ? Math.min(1_000_000, parseInt(volMatch[1], 10)) : 5000; + + return NextResponse.json({ + config: { + service_type: service, + markets: markets.length ? markets : ["SE"], + type: "Bolag", + fieldIds: fields.length ? fields : ["lei"], + enrichmentIds: [], + volume, + frequency: service === "feeds" || service === "enrichment" ? "Veckovis" : "Engångs", + confidence: 92, + destination, + description: text, + }, + rationale: `Tolkat som ${service}${markets.length ? ` · ${markets.join(", ")}` : ""}${destination ? ` · ${destination}` : ""}. Justera fritt.`, + heuristic: true, + }); +} diff --git a/app/bestall/beskriv/page.tsx b/app/bestall/beskriv/page.tsx new file mode 100644 index 0000000..5c08f96 --- /dev/null +++ b/app/bestall/beskriv/page.tsx @@ -0,0 +1,132 @@ +"use client"; + +import Link from "next/link"; +import { useRouter } from "next/navigation"; +import { useEffect, useState } from "react"; +import { Header } from "@/components/header"; +import { OrderStepper } from "@/components/order-stepper"; +import { SERVICES, DESTINATIONS_CRM, serviceById } from "@/lib/services"; + +const PLACEHOLDER = + "T.ex. \"Konsolidera vår admindata och pusha alla svenska kunder med omsättning och beslutsfattare till HubSpot\" eller \"Skrapa alla norska bolag inom bygg med e-post\"."; + +export default function DescribePage() { + const router = useRouter(); + const [service, setService] = useState("data"); + const [text, setText] = useState(""); + const [destination, setDestination] = useState(""); + const [busy, setBusy] = useState(false); + const [rationale, setRationale] = useState(""); + + useEffect(() => { + const s = new URLSearchParams(window.location.search).get("service"); + if (s && serviceById(s)) setService(s); + }, []); + + const svc = serviceById(service); + const showDest = service === "consolidation" || service === "enrichment" || service === "icp"; + + async function submit() { + if (busy || !text.trim()) return; + setBusy(true); + setRationale(""); + let config: Record = { service_type: service, description: text, destination: destination || null }; + try { + const ai = await fetch("/api/ai/parse", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ text: `${svc?.name ?? ""}. ${text}` }) }); + if (ai.ok) { + const d = await ai.json(); + config = { ...d.config, service_type: service, description: text, destination: destination || d.config?.destination || null }; + setRationale(d.rationale ?? ""); + } + } catch {} + try { + const flow = svc?.flow === "subscription" ? "subscription" : "custom"; + const res = await fetch("/api/orders", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ flow, config }) }); + const o = await res.json(); + if (o?.order_id) { router.push(`/bestall/forskott?order=${encodeURIComponent(o.order_id)}`); return; } + } catch {} + setBusy(false); + } + + return ( +
+
+ +
+

Skräddarsytt — Beskriv

+

Beskriv behovet.

+

+ Säg det på svenska. Vi tolkar, prissätter, scopar — du godkänner. +

+ +
+

Tjänst

+
+ {SERVICES.map((s) => ( + + ))} +
+ {svc ?

{svc.covers} → {svc.deliverable}

: null} +
+ +
+

Ditt behov

+