@flowselections/mailbox-orders 1.0.1 → 1.0.3

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.
@@ -1,8 +1,25 @@
1
1
  export const Constants = {
2
2
  public: {
3
3
  Enums: {
4
- app_role: ["admin", "manager", "warehouse", "sales", "developer"],
4
+ app_role: [
5
+ "admin",
6
+ "manager",
7
+ "warehouse",
8
+ "sales",
9
+ "developer",
10
+ "receptie",
11
+ ],
5
12
  exact_env: ["staging", "live"],
13
+ quote_status: [
14
+ "concept",
15
+ "verzonden",
16
+ "bekeken",
17
+ "in_behandeling",
18
+ "geaccepteerd",
19
+ "afgewezen",
20
+ "verlopen",
21
+ "gearchiveerd",
22
+ ],
6
23
  },
7
24
  },
8
25
  };
@@ -25,7 +25,7 @@ export interface ParsedOrder {
25
25
  }>;
26
26
  overall_confidence: number;
27
27
  }
28
- export declare function parseOrderEmail(bodyText: string, subject: string, templateFields: TemplateFieldSpec[], productCatalog: Array<{
28
+ export declare function parseOrderEmail(_bodyText: string, _subject: string, _templateFields: TemplateFieldSpec[], _productCatalog: Array<{
29
29
  id: string;
30
30
  name: string;
31
31
  }>): Promise<ParsedOrder>;
@@ -1 +1 @@
1
- {"version":3,"file":"mailbox-ai.server.d.ts","sourceRoot":"","sources":["../../src/lib/mailbox-ai.server.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC/C;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,GAAG,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,E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AAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACzC,KAAK,EAAE,KAAK,CAAC;QACX,gBAAgB,EAAE,MAAM,CAAC;QACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC,CAAC;IACH,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,wBAAsB,eAAe,CACnC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,iBAAiB,EAAE,EACpC,eAAe,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GACnD,OAAO,CAAC,WAAW,CAAC,CAItB"}
@@ -1,107 +1,7 @@
1
- // Schema-driven AI parser via Lovable AI Gateway.
2
- export async function parseOrderEmail(bodyText, subject, templateFields, productCatalog) {
3
- const apiKey = process.env.LOVABLE_API_KEY;
4
- if (!apiKey)
5
- throw new Error("LOVABLE_API_KEY ontbreekt");
6
- const fieldSpec = templateFields.map((f) => {
7
- const base = {
8
- key: f.key,
9
- label: f.label,
10
- type: f.field_type,
11
- hint: f.ai_hint ?? undefined,
12
- };
13
- if (f.allowed && f.allowed.length > 0) {
14
- // Beperk lijst zodat de prompt niet over de token-limiet gaat.
15
- base.allowed_values = f.allowed.slice(0, 250).map((a) => ({ id: a.id, name: a.name }));
16
- base.rule = "Kies een id uit allowed_values, of zet value=null en needs_review=true.";
17
- }
18
- return base;
19
- });
20
- const catalogSnippet = productCatalog
21
- .slice(0, 250)
22
- .map((p) => `- ${p.id} :: ${p.name}`)
23
- .join("\n");
24
- const systemPrompt = `Je bent een assistent die bestel-e-mails uitleest voor een groothandel in planten/bloemen.
25
- Vul per veld in het meegegeven schema een waarde in op basis van de e-mail.
26
- - Voor velden met "allowed_values": geef ALLEEN een id uit die lijst. Bij twijfel: value=null en needs_review=true.
27
- - Voor type "date": gebruik formaat YYYY-MM-DD.
28
- - Voor type "boolean": true/false.
29
- - Voor type "number": een getal.
30
- - Confidence: 0.0 tot 1.0. Markeer needs_review=true bij confidence < 0.6 of als info ontbreekt.
31
- - Detecteer ook bestelregels (producten + aantallen) en match ze tegen de productcatalogus.
32
- Antwoord ALLEEN met geldige JSON volgens het gevraagde schema.`;
33
- const userPrompt = `Onderwerp: ${subject}
34
-
35
- E-mail:
36
- ${bodyText}
37
-
38
- Templatevelden (vul elk in):
39
- ${JSON.stringify(fieldSpec, null, 2)}
40
-
41
- Productcatalogus (id :: naam):
42
- ${catalogSnippet || "(leeg)"}
43
-
44
- Geef terug:
45
- {
46
- "overall_confidence": 0.0-1.0,
47
- "fields": {
48
- "<field_key>": { "value": ..., "confidence": 0.0-1.0, "needs_review": bool, "reason": "optioneel" }
49
- },
50
- "lines": [
51
- { "raw_product_text": "...", "product_id": "uuid of null", "quantity": number of null, "unit": "stuks/bos/etc of null", "match_confidence": 0.0-1.0 }
52
- ]
53
- }`;
54
- const res = await fetch("https://ai.gateway.lovable.dev/v1/chat/completions", {
55
- method: "POST",
56
- headers: {
57
- "Content-Type": "application/json",
58
- "Lovable-API-Key": apiKey,
59
- },
60
- body: JSON.stringify({
61
- model: "google/gemini-3-flash-preview",
62
- messages: [
63
- { role: "system", content: systemPrompt },
64
- { role: "user", content: userPrompt },
65
- ],
66
- response_format: { type: "json_object" },
67
- }),
68
- });
69
- if (!res.ok) {
70
- const errBody = await res.text().catch(() => "");
71
- throw new Error(`AI Gateway ${res.status}: ${errBody.slice(0, 300)}`);
72
- }
73
- const data = await res.json();
74
- const content = data?.choices?.[0]?.message?.content ?? "{}";
75
- let parsed = {};
76
- try {
77
- parsed = typeof content === "string" ? JSON.parse(content) : content;
78
- }
79
- catch {
80
- parsed = {};
81
- }
82
- const fields = {};
83
- if (parsed.fields && typeof parsed.fields === "object") {
84
- for (const key of Object.keys(parsed.fields)) {
85
- const f = parsed.fields[key] ?? {};
86
- fields[key] = {
87
- value: f.value ?? null,
88
- confidence: typeof f.confidence === "number" ? f.confidence : 0,
89
- needs_review: !!f.needs_review || (typeof f.confidence === "number" && f.confidence < 0.6),
90
- reason: f.reason ?? undefined,
91
- };
92
- }
93
- }
94
- return {
95
- overall_confidence: typeof parsed.overall_confidence === "number" ? parsed.overall_confidence : 0,
96
- fields,
97
- lines: Array.isArray(parsed.lines)
98
- ? parsed.lines.map((l) => ({
99
- raw_product_text: String(l.raw_product_text ?? ""),
100
- product_id: typeof l.product_id === "string" && l.product_id.length === 36 ? l.product_id : null,
101
- quantity: typeof l.quantity === "number" ? l.quantity : null,
102
- unit: l.unit ? String(l.unit) : null,
103
- match_confidence: typeof l.match_confidence === "number" ? l.match_confidence : 0,
104
- }))
105
- : [],
106
- };
1
+ // AI-parsing is uitgeschakeld. We stappen over op een extern model dat later
2
+ // gekoppeld wordt. Dit bestand bewaart alleen de types zodat de rest van de
3
+ // module blijft compileren; elke aanroep van parseOrderEmail gooit direct een
4
+ // fout zodat er geen tokens bij Lovable AI verbruikt worden.
5
+ export async function parseOrderEmail(_bodyText, _subject, _templateFields, _productCatalog) {
6
+ throw new Error("AI-parsing is uitgeschakeld — wacht op de externe model-koppeling.");
107
7
  }