@infuro/cms-core 1.0.6 → 1.0.8

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.
package/dist/index.js CHANGED
@@ -751,14 +751,15 @@ function s3StoragePlugin(config) {
751
751
  // src/plugins/storage/local.ts
752
752
  function getLocalStorage(config) {
753
753
  const dir = (config.dir ?? "public/uploads").replace(/\/$/, "");
754
- const publicPath = config.publicPath ?? `/${dir.replace(/^\/+/, "").replace(/\\/g, "/")}`;
754
+ const publicPath = config.publicPath ?? (dir === "public/uploads" ? "/uploads" : `/${dir.replace(/^\/+/, "").replace(/\\/g, "/")}`);
755
755
  return {
756
756
  async upload(buffer, key, _contentType) {
757
757
  const fs = await import("fs/promises");
758
758
  const path = await import("path");
759
+ const normalizedKey = key.replace(/^\/+/, "").replace(/\.\./g, "");
760
+ const fileName = normalizedKey.replace(/^uploads\//, "");
759
761
  const fullDir = path.join(process.cwd(), dir);
760
762
  await fs.mkdir(fullDir, { recursive: true });
761
- const fileName = key.replace(/^\/+/, "").replace(/\.\./g, "");
762
763
  const filePath = path.join(fullDir, fileName);
763
764
  const fileDir = path.dirname(filePath);
764
765
  await fs.mkdir(fileDir, { recursive: true });
@@ -778,6 +779,153 @@ function localStoragePlugin(config = {}) {
778
779
  };
779
780
  }
780
781
 
782
+ // src/plugins/llm/llm-service.ts
783
+ var LlmService = class _LlmService {
784
+ constructor(baseURL, apiKey, defaultEmbeddingModel) {
785
+ this.baseURL = baseURL;
786
+ this.apiKey = apiKey;
787
+ this.defaultEmbeddingModel = defaultEmbeddingModel;
788
+ }
789
+ static embedWarned = false;
790
+ get base() {
791
+ return this.baseURL.replace(/\/$/, "");
792
+ }
793
+ get url() {
794
+ return `${this.base}/v1/chat/completions`;
795
+ }
796
+ /**
797
+ * OpenAI-compatible embeddings. Returns [] if endpoint not available or unexpected response.
798
+ * Server must implement: POST /v1/embeddings
799
+ * Body: { model: string, input: string }
800
+ * Response: { data: [ { embedding: number[] } ] } or { embedding: number[] }
801
+ */
802
+ async embed(text, options = {}) {
803
+ const model = options.model ?? this.defaultEmbeddingModel ?? "text-embedding-3-small";
804
+ const input = text.slice(0, 8e3);
805
+ const res = await fetch(`${this.base}/v1/embeddings`, {
806
+ method: "POST",
807
+ headers: {
808
+ "Content-Type": "application/json",
809
+ Authorization: `Bearer ${this.apiKey}`
810
+ },
811
+ body: JSON.stringify({
812
+ model,
813
+ input
814
+ })
815
+ });
816
+ if (!res.ok) {
817
+ const body = await res.text();
818
+ if (!_LlmService.embedWarned) {
819
+ _LlmService.embedWarned = true;
820
+ console.warn(`[LLM embed] ${res.status} ${res.statusText}: ${body.slice(0, 400)}`);
821
+ }
822
+ return [];
823
+ }
824
+ let data;
825
+ try {
826
+ data = await res.json();
827
+ } catch {
828
+ console.warn("[LLM embed] Response is not JSON");
829
+ return [];
830
+ }
831
+ let embedding = data?.data?.[0]?.embedding;
832
+ if (!Array.isArray(embedding) && Array.isArray(data?.embedding)) {
833
+ embedding = data.embedding;
834
+ }
835
+ if (!Array.isArray(embedding) && Array.isArray(data?.data?.[0])) {
836
+ const first = data.data[0];
837
+ embedding = Array.isArray(first) ? first : first?.embedding;
838
+ }
839
+ if (!Array.isArray(embedding) && !_LlmService.embedWarned) {
840
+ _LlmService.embedWarned = true;
841
+ console.warn("[LLM embed] Unexpected response shape. Keys:", Object.keys(data), "data[0] type:", Array.isArray(data?.data) ? typeof data.data[0] : "n/a");
842
+ }
843
+ return Array.isArray(embedding) ? embedding : [];
844
+ }
845
+ async chat(messages, options = {}) {
846
+ const res = await fetch(this.url, {
847
+ method: "POST",
848
+ headers: {
849
+ "Content-Type": "application/json",
850
+ Authorization: `Bearer ${this.apiKey}`
851
+ },
852
+ body: JSON.stringify({
853
+ model: options.model ?? "qwen2.5:3b-instruct",
854
+ messages,
855
+ stream: false,
856
+ temperature: options.temperature,
857
+ max_tokens: options.max_tokens
858
+ })
859
+ });
860
+ if (!res.ok) {
861
+ const text = await res.text();
862
+ throw new Error(`LLM gateway error: ${res.status} ${text}`);
863
+ }
864
+ const data = await res.json();
865
+ const content = data.choices?.[0]?.message?.content ?? "";
866
+ return { content };
867
+ }
868
+ async *streamChat(messages, options = {}) {
869
+ const res = await fetch(this.url, {
870
+ method: "POST",
871
+ headers: {
872
+ "Content-Type": "application/json",
873
+ Authorization: `Bearer ${this.apiKey}`
874
+ },
875
+ body: JSON.stringify({
876
+ model: options.model ?? "qwen2.5:3b-instruct",
877
+ messages,
878
+ stream: true,
879
+ temperature: options.temperature,
880
+ max_tokens: options.max_tokens
881
+ })
882
+ });
883
+ if (!res.ok) {
884
+ const text = await res.text();
885
+ throw new Error(`LLM gateway error: ${res.status} ${text}`);
886
+ }
887
+ const reader = res.body?.getReader();
888
+ if (!reader) return;
889
+ const decoder = new TextDecoder();
890
+ let buffer = "";
891
+ while (true) {
892
+ const { value, done } = await reader.read();
893
+ if (done) break;
894
+ buffer += decoder.decode(value, { stream: true });
895
+ const lines = buffer.split("\n");
896
+ buffer = lines.pop() ?? "";
897
+ for (const line of lines) {
898
+ if (line.startsWith("data: ") && line !== "data: [DONE]") {
899
+ try {
900
+ const json = JSON.parse(line.slice(6));
901
+ const content = json.choices?.[0]?.delta?.content;
902
+ if (content) yield content;
903
+ } catch {
904
+ }
905
+ }
906
+ }
907
+ }
908
+ }
909
+ };
910
+
911
+ // src/plugins/llm/index.ts
912
+ function llmPlugin(config = {}) {
913
+ return {
914
+ name: "llm",
915
+ version: "1.0.0",
916
+ async init(context) {
917
+ const baseURL = config.baseURL ?? context.config.LLM_GATEWAY_URL;
918
+ const apiKey = config.apiKey ?? context.config.LLM_API_KEY;
919
+ if (!baseURL || !apiKey) {
920
+ context.logger.warn("LLM plugin skipped: LLM_GATEWAY_URL or LLM_API_KEY not set");
921
+ return void 0;
922
+ }
923
+ const embeddingModel = config.embeddingModel ?? context.config.EMBEDDING_MODEL;
924
+ return new LlmService(baseURL.replace(/\/$/, ""), apiKey, embeddingModel);
925
+ }
926
+ };
927
+ }
928
+
781
929
  // src/lib/utils.ts
782
930
  import { clsx } from "clsx";
783
931
  import { twMerge } from "tailwind-merge";
@@ -1374,7 +1522,7 @@ Blog = __decorateClass([
1374
1522
  ], Blog);
1375
1523
 
1376
1524
  // src/entities/contact.entity.ts
1377
- import { Entity as Entity16, PrimaryGeneratedColumn as PrimaryGeneratedColumn16, Column as Column16, OneToMany as OneToMany7 } from "typeorm";
1525
+ import { Entity as Entity18, PrimaryGeneratedColumn as PrimaryGeneratedColumn18, Column as Column18, OneToMany as OneToMany8 } from "typeorm";
1378
1526
 
1379
1527
  // src/entities/form-submission.entity.ts
1380
1528
  import { Entity as Entity12, PrimaryGeneratedColumn as PrimaryGeneratedColumn12, Column as Column12, ManyToOne as ManyToOne6, JoinColumn as JoinColumn6 } from "typeorm";
@@ -1833,6 +1981,74 @@ Payment = __decorateClass([
1833
1981
  Entity15("payments")
1834
1982
  ], Payment);
1835
1983
 
1984
+ // src/entities/chat-conversation.entity.ts
1985
+ import { Entity as Entity17, PrimaryGeneratedColumn as PrimaryGeneratedColumn17, Column as Column17, ManyToOne as ManyToOne11, OneToMany as OneToMany7, JoinColumn as JoinColumn11 } from "typeorm";
1986
+
1987
+ // src/entities/chat-message.entity.ts
1988
+ import { Entity as Entity16, PrimaryGeneratedColumn as PrimaryGeneratedColumn16, Column as Column16, ManyToOne as ManyToOne10, JoinColumn as JoinColumn10 } from "typeorm";
1989
+ var ChatMessage = class {
1990
+ id;
1991
+ conversationId;
1992
+ role;
1993
+ content;
1994
+ createdAt;
1995
+ conversation;
1996
+ };
1997
+ __decorateClass([
1998
+ PrimaryGeneratedColumn16()
1999
+ ], ChatMessage.prototype, "id", 2);
2000
+ __decorateClass([
2001
+ Column16("int")
2002
+ ], ChatMessage.prototype, "conversationId", 2);
2003
+ __decorateClass([
2004
+ Column16("varchar")
2005
+ ], ChatMessage.prototype, "role", 2);
2006
+ __decorateClass([
2007
+ Column16("text")
2008
+ ], ChatMessage.prototype, "content", 2);
2009
+ __decorateClass([
2010
+ Column16({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2011
+ ], ChatMessage.prototype, "createdAt", 2);
2012
+ __decorateClass([
2013
+ ManyToOne10(() => ChatConversation, (c) => c.messages, { onDelete: "CASCADE" }),
2014
+ JoinColumn10({ name: "conversationId" })
2015
+ ], ChatMessage.prototype, "conversation", 2);
2016
+ ChatMessage = __decorateClass([
2017
+ Entity16("chat_messages")
2018
+ ], ChatMessage);
2019
+
2020
+ // src/entities/chat-conversation.entity.ts
2021
+ var ChatConversation = class {
2022
+ id;
2023
+ contactId;
2024
+ createdAt;
2025
+ updatedAt;
2026
+ contact;
2027
+ messages;
2028
+ };
2029
+ __decorateClass([
2030
+ PrimaryGeneratedColumn17()
2031
+ ], ChatConversation.prototype, "id", 2);
2032
+ __decorateClass([
2033
+ Column17("int")
2034
+ ], ChatConversation.prototype, "contactId", 2);
2035
+ __decorateClass([
2036
+ Column17({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2037
+ ], ChatConversation.prototype, "createdAt", 2);
2038
+ __decorateClass([
2039
+ Column17({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2040
+ ], ChatConversation.prototype, "updatedAt", 2);
2041
+ __decorateClass([
2042
+ ManyToOne11(() => Contact, (c) => c.chatConversations, { onDelete: "CASCADE" }),
2043
+ JoinColumn11({ name: "contactId" })
2044
+ ], ChatConversation.prototype, "contact", 2);
2045
+ __decorateClass([
2046
+ OneToMany7(() => ChatMessage, (m) => m.conversation)
2047
+ ], ChatConversation.prototype, "messages", 2);
2048
+ ChatConversation = __decorateClass([
2049
+ Entity17("chat_conversations")
2050
+ ], ChatConversation);
2051
+
1836
2052
  // src/entities/contact.entity.ts
1837
2053
  var Contact = class {
1838
2054
  id;
@@ -1854,70 +2070,74 @@ var Contact = class {
1854
2070
  addresses;
1855
2071
  orders;
1856
2072
  payments;
2073
+ chatConversations;
1857
2074
  };
1858
2075
  __decorateClass([
1859
- PrimaryGeneratedColumn16()
2076
+ PrimaryGeneratedColumn18()
1860
2077
  ], Contact.prototype, "id", 2);
1861
2078
  __decorateClass([
1862
- Column16("varchar")
2079
+ Column18("varchar")
1863
2080
  ], Contact.prototype, "name", 2);
1864
2081
  __decorateClass([
1865
- Column16("varchar", { unique: true })
2082
+ Column18("varchar", { unique: true })
1866
2083
  ], Contact.prototype, "email", 2);
1867
2084
  __decorateClass([
1868
- Column16("varchar", { nullable: true })
2085
+ Column18("varchar", { nullable: true })
1869
2086
  ], Contact.prototype, "phone", 2);
1870
2087
  __decorateClass([
1871
- Column16("varchar", { nullable: true })
2088
+ Column18("varchar", { nullable: true })
1872
2089
  ], Contact.prototype, "type", 2);
1873
2090
  __decorateClass([
1874
- Column16("varchar", { nullable: true })
2091
+ Column18("varchar", { nullable: true })
1875
2092
  ], Contact.prototype, "company", 2);
1876
2093
  __decorateClass([
1877
- Column16("varchar", { nullable: true })
2094
+ Column18("varchar", { nullable: true })
1878
2095
  ], Contact.prototype, "taxId", 2);
1879
2096
  __decorateClass([
1880
- Column16("text", { nullable: true })
2097
+ Column18("text", { nullable: true })
1881
2098
  ], Contact.prototype, "notes", 2);
1882
2099
  __decorateClass([
1883
- Column16({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2100
+ Column18({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
1884
2101
  ], Contact.prototype, "createdAt", 2);
1885
2102
  __decorateClass([
1886
- Column16({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2103
+ Column18({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
1887
2104
  ], Contact.prototype, "updatedAt", 2);
1888
2105
  __decorateClass([
1889
- Column16({ type: "timestamp", nullable: true })
2106
+ Column18({ type: "timestamp", nullable: true })
1890
2107
  ], Contact.prototype, "deletedAt", 2);
1891
2108
  __decorateClass([
1892
- Column16("boolean", { default: false })
2109
+ Column18("boolean", { default: false })
1893
2110
  ], Contact.prototype, "deleted", 2);
1894
2111
  __decorateClass([
1895
- Column16("int", { nullable: true })
2112
+ Column18("int", { nullable: true })
1896
2113
  ], Contact.prototype, "createdBy", 2);
1897
2114
  __decorateClass([
1898
- Column16("int", { nullable: true })
2115
+ Column18("int", { nullable: true })
1899
2116
  ], Contact.prototype, "updatedBy", 2);
1900
2117
  __decorateClass([
1901
- Column16("int", { nullable: true })
2118
+ Column18("int", { nullable: true })
1902
2119
  ], Contact.prototype, "deletedBy", 2);
1903
2120
  __decorateClass([
1904
- OneToMany7(() => FormSubmission, (fs) => fs.contact)
2121
+ OneToMany8(() => FormSubmission, (fs) => fs.contact)
1905
2122
  ], Contact.prototype, "form_submissions", 2);
1906
2123
  __decorateClass([
1907
- OneToMany7(() => Address, (a) => a.contact)
2124
+ OneToMany8(() => Address, (a) => a.contact)
1908
2125
  ], Contact.prototype, "addresses", 2);
1909
2126
  __decorateClass([
1910
- OneToMany7(() => Order, (o) => o.contact)
2127
+ OneToMany8(() => Order, (o) => o.contact)
1911
2128
  ], Contact.prototype, "orders", 2);
1912
2129
  __decorateClass([
1913
- OneToMany7(() => Payment, (p) => p.contact)
2130
+ OneToMany8(() => Payment, (p) => p.contact)
1914
2131
  ], Contact.prototype, "payments", 2);
2132
+ __decorateClass([
2133
+ OneToMany8(() => ChatConversation, (c) => c.contact)
2134
+ ], Contact.prototype, "chatConversations", 2);
1915
2135
  Contact = __decorateClass([
1916
- Entity16("contacts")
2136
+ Entity18("contacts")
1917
2137
  ], Contact);
1918
2138
 
1919
2139
  // src/entities/config.entity.ts
1920
- import { Entity as Entity17, PrimaryGeneratedColumn as PrimaryGeneratedColumn17, Column as Column17, Unique } from "typeorm";
2140
+ import { Entity as Entity19, PrimaryGeneratedColumn as PrimaryGeneratedColumn19, Column as Column19, Unique } from "typeorm";
1921
2141
  var Config = class {
1922
2142
  id;
1923
2143
  settings;
@@ -1934,51 +2154,51 @@ var Config = class {
1934
2154
  deletedBy;
1935
2155
  };
1936
2156
  __decorateClass([
1937
- PrimaryGeneratedColumn17()
2157
+ PrimaryGeneratedColumn19()
1938
2158
  ], Config.prototype, "id", 2);
1939
2159
  __decorateClass([
1940
- Column17("varchar")
2160
+ Column19("varchar")
1941
2161
  ], Config.prototype, "settings", 2);
1942
2162
  __decorateClass([
1943
- Column17("varchar")
2163
+ Column19("varchar")
1944
2164
  ], Config.prototype, "key", 2);
1945
2165
  __decorateClass([
1946
- Column17("varchar")
2166
+ Column19("varchar")
1947
2167
  ], Config.prototype, "value", 2);
1948
2168
  __decorateClass([
1949
- Column17("varchar", { default: "private" })
2169
+ Column19("varchar", { default: "private" })
1950
2170
  ], Config.prototype, "type", 2);
1951
2171
  __decorateClass([
1952
- Column17("boolean", { default: false })
2172
+ Column19("boolean", { default: false })
1953
2173
  ], Config.prototype, "encrypted", 2);
1954
2174
  __decorateClass([
1955
- Column17({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2175
+ Column19({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
1956
2176
  ], Config.prototype, "createdAt", 2);
1957
2177
  __decorateClass([
1958
- Column17({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2178
+ Column19({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
1959
2179
  ], Config.prototype, "updatedAt", 2);
1960
2180
  __decorateClass([
1961
- Column17({ type: "timestamp", nullable: true })
2181
+ Column19({ type: "timestamp", nullable: true })
1962
2182
  ], Config.prototype, "deletedAt", 2);
1963
2183
  __decorateClass([
1964
- Column17("boolean", { default: false })
2184
+ Column19("boolean", { default: false })
1965
2185
  ], Config.prototype, "deleted", 2);
1966
2186
  __decorateClass([
1967
- Column17("int", { nullable: true })
2187
+ Column19("int", { nullable: true })
1968
2188
  ], Config.prototype, "createdBy", 2);
1969
2189
  __decorateClass([
1970
- Column17("int", { nullable: true })
2190
+ Column19("int", { nullable: true })
1971
2191
  ], Config.prototype, "updatedBy", 2);
1972
2192
  __decorateClass([
1973
- Column17("int", { nullable: true })
2193
+ Column19("int", { nullable: true })
1974
2194
  ], Config.prototype, "deletedBy", 2);
1975
2195
  Config = __decorateClass([
1976
- Entity17("configs"),
2196
+ Entity19("configs"),
1977
2197
  Unique(["settings", "key"])
1978
2198
  ], Config);
1979
2199
 
1980
2200
  // src/entities/media.entity.ts
1981
- import { Entity as Entity18, PrimaryGeneratedColumn as PrimaryGeneratedColumn18, Column as Column18 } from "typeorm";
2201
+ import { Entity as Entity20, PrimaryGeneratedColumn as PrimaryGeneratedColumn20, Column as Column20 } from "typeorm";
1982
2202
  var Media = class {
1983
2203
  id;
1984
2204
  filename;
@@ -1993,44 +2213,44 @@ var Media = class {
1993
2213
  deleted;
1994
2214
  };
1995
2215
  __decorateClass([
1996
- PrimaryGeneratedColumn18()
2216
+ PrimaryGeneratedColumn20()
1997
2217
  ], Media.prototype, "id", 2);
1998
2218
  __decorateClass([
1999
- Column18("varchar")
2219
+ Column20("varchar")
2000
2220
  ], Media.prototype, "filename", 2);
2001
2221
  __decorateClass([
2002
- Column18("varchar")
2222
+ Column20("varchar")
2003
2223
  ], Media.prototype, "url", 2);
2004
2224
  __decorateClass([
2005
- Column18("varchar")
2225
+ Column20("varchar")
2006
2226
  ], Media.prototype, "mimeType", 2);
2007
2227
  __decorateClass([
2008
- Column18("int", { default: 0 })
2228
+ Column20("int", { default: 0 })
2009
2229
  ], Media.prototype, "size", 2);
2010
2230
  __decorateClass([
2011
- Column18("varchar", { nullable: true })
2231
+ Column20("varchar", { nullable: true })
2012
2232
  ], Media.prototype, "alt", 2);
2013
2233
  __decorateClass([
2014
- Column18("boolean", { default: false })
2234
+ Column20("boolean", { default: false })
2015
2235
  ], Media.prototype, "isPublic", 2);
2016
2236
  __decorateClass([
2017
- Column18({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2237
+ Column20({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2018
2238
  ], Media.prototype, "createdAt", 2);
2019
2239
  __decorateClass([
2020
- Column18({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2240
+ Column20({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2021
2241
  ], Media.prototype, "updatedAt", 2);
2022
2242
  __decorateClass([
2023
- Column18({ type: "timestamp", nullable: true })
2243
+ Column20({ type: "timestamp", nullable: true })
2024
2244
  ], Media.prototype, "deletedAt", 2);
2025
2245
  __decorateClass([
2026
- Column18("boolean", { default: false })
2246
+ Column20("boolean", { default: false })
2027
2247
  ], Media.prototype, "deleted", 2);
2028
2248
  Media = __decorateClass([
2029
- Entity18("media")
2249
+ Entity20("media")
2030
2250
  ], Media);
2031
2251
 
2032
2252
  // src/entities/page.entity.ts
2033
- import { Entity as Entity19, PrimaryGeneratedColumn as PrimaryGeneratedColumn19, Column as Column19, ManyToOne as ManyToOne10, JoinColumn as JoinColumn10 } from "typeorm";
2253
+ import { Entity as Entity21, PrimaryGeneratedColumn as PrimaryGeneratedColumn21, Column as Column21, ManyToOne as ManyToOne12, JoinColumn as JoinColumn12 } from "typeorm";
2034
2254
  var Page = class {
2035
2255
  id;
2036
2256
  title;
@@ -2051,64 +2271,64 @@ var Page = class {
2051
2271
  deletedBy;
2052
2272
  };
2053
2273
  __decorateClass([
2054
- PrimaryGeneratedColumn19()
2274
+ PrimaryGeneratedColumn21()
2055
2275
  ], Page.prototype, "id", 2);
2056
2276
  __decorateClass([
2057
- Column19("varchar")
2277
+ Column21("varchar")
2058
2278
  ], Page.prototype, "title", 2);
2059
2279
  __decorateClass([
2060
- Column19("varchar", { unique: true })
2280
+ Column21("varchar", { unique: true })
2061
2281
  ], Page.prototype, "slug", 2);
2062
2282
  __decorateClass([
2063
- Column19({ type: "jsonb", default: {} })
2283
+ Column21({ type: "jsonb", default: {} })
2064
2284
  ], Page.prototype, "content", 2);
2065
2285
  __decorateClass([
2066
- Column19("boolean", { default: false })
2286
+ Column21("boolean", { default: false })
2067
2287
  ], Page.prototype, "published", 2);
2068
2288
  __decorateClass([
2069
- Column19("varchar", { default: "default" })
2289
+ Column21("varchar", { default: "default" })
2070
2290
  ], Page.prototype, "theme", 2);
2071
2291
  __decorateClass([
2072
- Column19("int", { nullable: true })
2292
+ Column21("int", { nullable: true })
2073
2293
  ], Page.prototype, "parentId", 2);
2074
2294
  __decorateClass([
2075
- ManyToOne10(() => Page, { onDelete: "SET NULL" }),
2076
- JoinColumn10({ name: "parentId" })
2295
+ ManyToOne12(() => Page, { onDelete: "SET NULL" }),
2296
+ JoinColumn12({ name: "parentId" })
2077
2297
  ], Page.prototype, "parent", 2);
2078
2298
  __decorateClass([
2079
- Column19("int", { nullable: true })
2299
+ Column21("int", { nullable: true })
2080
2300
  ], Page.prototype, "seoId", 2);
2081
2301
  __decorateClass([
2082
- ManyToOne10(() => Seo, { onDelete: "SET NULL" }),
2083
- JoinColumn10({ name: "seoId" })
2302
+ ManyToOne12(() => Seo, { onDelete: "SET NULL" }),
2303
+ JoinColumn12({ name: "seoId" })
2084
2304
  ], Page.prototype, "seo", 2);
2085
2305
  __decorateClass([
2086
- Column19({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2306
+ Column21({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2087
2307
  ], Page.prototype, "createdAt", 2);
2088
2308
  __decorateClass([
2089
- Column19({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2309
+ Column21({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2090
2310
  ], Page.prototype, "updatedAt", 2);
2091
2311
  __decorateClass([
2092
- Column19({ type: "timestamp", nullable: true })
2312
+ Column21({ type: "timestamp", nullable: true })
2093
2313
  ], Page.prototype, "deletedAt", 2);
2094
2314
  __decorateClass([
2095
- Column19("boolean", { default: false })
2315
+ Column21("boolean", { default: false })
2096
2316
  ], Page.prototype, "deleted", 2);
2097
2317
  __decorateClass([
2098
- Column19("int", { nullable: true })
2318
+ Column21("int", { nullable: true })
2099
2319
  ], Page.prototype, "createdBy", 2);
2100
2320
  __decorateClass([
2101
- Column19("int", { nullable: true })
2321
+ Column21("int", { nullable: true })
2102
2322
  ], Page.prototype, "updatedBy", 2);
2103
2323
  __decorateClass([
2104
- Column19("int", { nullable: true })
2324
+ Column21("int", { nullable: true })
2105
2325
  ], Page.prototype, "deletedBy", 2);
2106
2326
  Page = __decorateClass([
2107
- Entity19("pages")
2327
+ Entity21("pages")
2108
2328
  ], Page);
2109
2329
 
2110
2330
  // src/entities/product-category.entity.ts
2111
- import { Entity as Entity20, PrimaryGeneratedColumn as PrimaryGeneratedColumn20, Column as Column20, ManyToOne as ManyToOne11, OneToMany as OneToMany8, JoinColumn as JoinColumn11 } from "typeorm";
2331
+ import { Entity as Entity22, PrimaryGeneratedColumn as PrimaryGeneratedColumn22, Column as Column22, ManyToOne as ManyToOne13, OneToMany as OneToMany9, JoinColumn as JoinColumn13 } from "typeorm";
2112
2332
  var ProductCategory = class {
2113
2333
  id;
2114
2334
  name;
@@ -2132,75 +2352,75 @@ var ProductCategory = class {
2132
2352
  collections;
2133
2353
  };
2134
2354
  __decorateClass([
2135
- PrimaryGeneratedColumn20()
2355
+ PrimaryGeneratedColumn22()
2136
2356
  ], ProductCategory.prototype, "id", 2);
2137
2357
  __decorateClass([
2138
- Column20("varchar")
2358
+ Column22("varchar")
2139
2359
  ], ProductCategory.prototype, "name", 2);
2140
2360
  __decorateClass([
2141
- Column20("varchar", { unique: true })
2361
+ Column22("varchar", { unique: true })
2142
2362
  ], ProductCategory.prototype, "slug", 2);
2143
2363
  __decorateClass([
2144
- Column20("int", { nullable: true })
2364
+ Column22("int", { nullable: true })
2145
2365
  ], ProductCategory.prototype, "parentId", 2);
2146
2366
  __decorateClass([
2147
- Column20("varchar", { nullable: true })
2367
+ Column22("varchar", { nullable: true })
2148
2368
  ], ProductCategory.prototype, "image", 2);
2149
2369
  __decorateClass([
2150
- Column20("text", { nullable: true })
2370
+ Column22("text", { nullable: true })
2151
2371
  ], ProductCategory.prototype, "description", 2);
2152
2372
  __decorateClass([
2153
- Column20("jsonb", { nullable: true })
2373
+ Column22("jsonb", { nullable: true })
2154
2374
  ], ProductCategory.prototype, "metadata", 2);
2155
2375
  __decorateClass([
2156
- Column20("boolean", { default: true })
2376
+ Column22("boolean", { default: true })
2157
2377
  ], ProductCategory.prototype, "active", 2);
2158
2378
  __decorateClass([
2159
- Column20("int", { default: 0 })
2379
+ Column22("int", { default: 0 })
2160
2380
  ], ProductCategory.prototype, "sortOrder", 2);
2161
2381
  __decorateClass([
2162
- Column20({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2382
+ Column22({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2163
2383
  ], ProductCategory.prototype, "createdAt", 2);
2164
2384
  __decorateClass([
2165
- Column20({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2385
+ Column22({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2166
2386
  ], ProductCategory.prototype, "updatedAt", 2);
2167
2387
  __decorateClass([
2168
- Column20({ type: "timestamp", nullable: true })
2388
+ Column22({ type: "timestamp", nullable: true })
2169
2389
  ], ProductCategory.prototype, "deletedAt", 2);
2170
2390
  __decorateClass([
2171
- Column20("boolean", { default: false })
2391
+ Column22("boolean", { default: false })
2172
2392
  ], ProductCategory.prototype, "deleted", 2);
2173
2393
  __decorateClass([
2174
- Column20("int", { nullable: true })
2394
+ Column22("int", { nullable: true })
2175
2395
  ], ProductCategory.prototype, "createdBy", 2);
2176
2396
  __decorateClass([
2177
- Column20("int", { nullable: true })
2397
+ Column22("int", { nullable: true })
2178
2398
  ], ProductCategory.prototype, "updatedBy", 2);
2179
2399
  __decorateClass([
2180
- Column20("int", { nullable: true })
2400
+ Column22("int", { nullable: true })
2181
2401
  ], ProductCategory.prototype, "deletedBy", 2);
2182
2402
  __decorateClass([
2183
- ManyToOne11(() => ProductCategory, (c) => c.children, { onDelete: "SET NULL" }),
2184
- JoinColumn11({ name: "parentId" })
2403
+ ManyToOne13(() => ProductCategory, (c) => c.children, { onDelete: "SET NULL" }),
2404
+ JoinColumn13({ name: "parentId" })
2185
2405
  ], ProductCategory.prototype, "parent", 2);
2186
2406
  __decorateClass([
2187
- OneToMany8(() => ProductCategory, (c) => c.parent)
2407
+ OneToMany9(() => ProductCategory, (c) => c.parent)
2188
2408
  ], ProductCategory.prototype, "children", 2);
2189
2409
  __decorateClass([
2190
- OneToMany8("Product", "category")
2410
+ OneToMany9("Product", "category")
2191
2411
  ], ProductCategory.prototype, "products", 2);
2192
2412
  __decorateClass([
2193
- OneToMany8("Collection", "category")
2413
+ OneToMany9("Collection", "category")
2194
2414
  ], ProductCategory.prototype, "collections", 2);
2195
2415
  ProductCategory = __decorateClass([
2196
- Entity20("product_categories")
2416
+ Entity22("product_categories")
2197
2417
  ], ProductCategory);
2198
2418
 
2199
2419
  // src/entities/collection.entity.ts
2200
- import { Entity as Entity22, PrimaryGeneratedColumn as PrimaryGeneratedColumn22, Column as Column22, ManyToOne as ManyToOne13, OneToMany as OneToMany10, JoinColumn as JoinColumn13 } from "typeorm";
2420
+ import { Entity as Entity24, PrimaryGeneratedColumn as PrimaryGeneratedColumn24, Column as Column24, ManyToOne as ManyToOne15, OneToMany as OneToMany11, JoinColumn as JoinColumn15 } from "typeorm";
2201
2421
 
2202
2422
  // src/entities/brand.entity.ts
2203
- import { Entity as Entity21, PrimaryGeneratedColumn as PrimaryGeneratedColumn21, Column as Column21, OneToMany as OneToMany9, ManyToOne as ManyToOne12, JoinColumn as JoinColumn12 } from "typeorm";
2423
+ import { Entity as Entity23, PrimaryGeneratedColumn as PrimaryGeneratedColumn23, Column as Column23, OneToMany as OneToMany10, ManyToOne as ManyToOne14, JoinColumn as JoinColumn14 } from "typeorm";
2204
2424
  var Brand = class {
2205
2425
  id;
2206
2426
  name;
@@ -2223,65 +2443,65 @@ var Brand = class {
2223
2443
  collections;
2224
2444
  };
2225
2445
  __decorateClass([
2226
- PrimaryGeneratedColumn21()
2446
+ PrimaryGeneratedColumn23()
2227
2447
  ], Brand.prototype, "id", 2);
2228
2448
  __decorateClass([
2229
- Column21("varchar")
2449
+ Column23("varchar")
2230
2450
  ], Brand.prototype, "name", 2);
2231
2451
  __decorateClass([
2232
- Column21("varchar", { unique: true })
2452
+ Column23("varchar", { unique: true })
2233
2453
  ], Brand.prototype, "slug", 2);
2234
2454
  __decorateClass([
2235
- Column21("varchar", { nullable: true })
2455
+ Column23("varchar", { nullable: true })
2236
2456
  ], Brand.prototype, "logo", 2);
2237
2457
  __decorateClass([
2238
- Column21("jsonb", { nullable: true })
2458
+ Column23("jsonb", { nullable: true })
2239
2459
  ], Brand.prototype, "metadata", 2);
2240
2460
  __decorateClass([
2241
- Column21("text", { nullable: true })
2461
+ Column23("text", { nullable: true })
2242
2462
  ], Brand.prototype, "description", 2);
2243
2463
  __decorateClass([
2244
- Column21("boolean", { default: true })
2464
+ Column23("boolean", { default: true })
2245
2465
  ], Brand.prototype, "active", 2);
2246
2466
  __decorateClass([
2247
- Column21("int", { default: 0 })
2467
+ Column23("int", { default: 0 })
2248
2468
  ], Brand.prototype, "sortOrder", 2);
2249
2469
  __decorateClass([
2250
- Column21({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2470
+ Column23({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2251
2471
  ], Brand.prototype, "createdAt", 2);
2252
2472
  __decorateClass([
2253
- Column21({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2473
+ Column23({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2254
2474
  ], Brand.prototype, "updatedAt", 2);
2255
2475
  __decorateClass([
2256
- Column21({ type: "timestamp", nullable: true })
2476
+ Column23({ type: "timestamp", nullable: true })
2257
2477
  ], Brand.prototype, "deletedAt", 2);
2258
2478
  __decorateClass([
2259
- Column21("boolean", { default: false })
2479
+ Column23("boolean", { default: false })
2260
2480
  ], Brand.prototype, "deleted", 2);
2261
2481
  __decorateClass([
2262
- Column21("int", { nullable: true })
2482
+ Column23("int", { nullable: true })
2263
2483
  ], Brand.prototype, "createdBy", 2);
2264
2484
  __decorateClass([
2265
- Column21("int", { nullable: true })
2485
+ Column23("int", { nullable: true })
2266
2486
  ], Brand.prototype, "updatedBy", 2);
2267
2487
  __decorateClass([
2268
- Column21("int", { nullable: true })
2488
+ Column23("int", { nullable: true })
2269
2489
  ], Brand.prototype, "deletedBy", 2);
2270
2490
  __decorateClass([
2271
- Column21("int", { nullable: true })
2491
+ Column23("int", { nullable: true })
2272
2492
  ], Brand.prototype, "seoId", 2);
2273
2493
  __decorateClass([
2274
- ManyToOne12(() => Seo, { onDelete: "SET NULL" }),
2275
- JoinColumn12({ name: "seoId" })
2494
+ ManyToOne14(() => Seo, { onDelete: "SET NULL" }),
2495
+ JoinColumn14({ name: "seoId" })
2276
2496
  ], Brand.prototype, "seo", 2);
2277
2497
  __decorateClass([
2278
- OneToMany9("Product", "brand")
2498
+ OneToMany10("Product", "brand")
2279
2499
  ], Brand.prototype, "products", 2);
2280
2500
  __decorateClass([
2281
- OneToMany9("Collection", "brand")
2501
+ OneToMany10("Collection", "brand")
2282
2502
  ], Brand.prototype, "collections", 2);
2283
2503
  Brand = __decorateClass([
2284
- Entity21("brands")
2504
+ Entity23("brands")
2285
2505
  ], Brand);
2286
2506
 
2287
2507
  // src/entities/collection.entity.ts
@@ -2310,80 +2530,80 @@ var Collection = class {
2310
2530
  products;
2311
2531
  };
2312
2532
  __decorateClass([
2313
- PrimaryGeneratedColumn22()
2533
+ PrimaryGeneratedColumn24()
2314
2534
  ], Collection.prototype, "id", 2);
2315
2535
  __decorateClass([
2316
- Column22("int", { nullable: true })
2536
+ Column24("int", { nullable: true })
2317
2537
  ], Collection.prototype, "categoryId", 2);
2318
2538
  __decorateClass([
2319
- Column22("int", { nullable: true })
2539
+ Column24("int", { nullable: true })
2320
2540
  ], Collection.prototype, "brandId", 2);
2321
2541
  __decorateClass([
2322
- Column22("varchar")
2542
+ Column24("varchar")
2323
2543
  ], Collection.prototype, "name", 2);
2324
2544
  __decorateClass([
2325
- Column22("varchar", { unique: true })
2545
+ Column24("varchar", { unique: true })
2326
2546
  ], Collection.prototype, "slug", 2);
2327
2547
  __decorateClass([
2328
- Column22("text", { nullable: true })
2548
+ Column24("text", { nullable: true })
2329
2549
  ], Collection.prototype, "description", 2);
2330
2550
  __decorateClass([
2331
- Column22("varchar", { nullable: true })
2551
+ Column24("varchar", { nullable: true })
2332
2552
  ], Collection.prototype, "image", 2);
2333
2553
  __decorateClass([
2334
- Column22("jsonb", { nullable: true })
2554
+ Column24("jsonb", { nullable: true })
2335
2555
  ], Collection.prototype, "metadata", 2);
2336
2556
  __decorateClass([
2337
- Column22("boolean", { default: true })
2557
+ Column24("boolean", { default: true })
2338
2558
  ], Collection.prototype, "active", 2);
2339
2559
  __decorateClass([
2340
- Column22("int", { default: 0 })
2560
+ Column24("int", { default: 0 })
2341
2561
  ], Collection.prototype, "sortOrder", 2);
2342
2562
  __decorateClass([
2343
- Column22({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2563
+ Column24({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2344
2564
  ], Collection.prototype, "createdAt", 2);
2345
2565
  __decorateClass([
2346
- Column22({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2566
+ Column24({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2347
2567
  ], Collection.prototype, "updatedAt", 2);
2348
2568
  __decorateClass([
2349
- Column22({ type: "timestamp", nullable: true })
2569
+ Column24({ type: "timestamp", nullable: true })
2350
2570
  ], Collection.prototype, "deletedAt", 2);
2351
2571
  __decorateClass([
2352
- Column22("boolean", { default: false })
2572
+ Column24("boolean", { default: false })
2353
2573
  ], Collection.prototype, "deleted", 2);
2354
2574
  __decorateClass([
2355
- Column22("int", { nullable: true })
2575
+ Column24("int", { nullable: true })
2356
2576
  ], Collection.prototype, "createdBy", 2);
2357
2577
  __decorateClass([
2358
- Column22("int", { nullable: true })
2578
+ Column24("int", { nullable: true })
2359
2579
  ], Collection.prototype, "updatedBy", 2);
2360
2580
  __decorateClass([
2361
- Column22("int", { nullable: true })
2581
+ Column24("int", { nullable: true })
2362
2582
  ], Collection.prototype, "deletedBy", 2);
2363
2583
  __decorateClass([
2364
- Column22("int", { nullable: true })
2584
+ Column24("int", { nullable: true })
2365
2585
  ], Collection.prototype, "seoId", 2);
2366
2586
  __decorateClass([
2367
- ManyToOne13(() => Seo, { onDelete: "SET NULL" }),
2368
- JoinColumn13({ name: "seoId" })
2587
+ ManyToOne15(() => Seo, { onDelete: "SET NULL" }),
2588
+ JoinColumn15({ name: "seoId" })
2369
2589
  ], Collection.prototype, "seo", 2);
2370
2590
  __decorateClass([
2371
- ManyToOne13(() => ProductCategory, (c) => c.collections, { onDelete: "SET NULL" }),
2372
- JoinColumn13({ name: "categoryId" })
2591
+ ManyToOne15(() => ProductCategory, (c) => c.collections, { onDelete: "SET NULL" }),
2592
+ JoinColumn15({ name: "categoryId" })
2373
2593
  ], Collection.prototype, "category", 2);
2374
2594
  __decorateClass([
2375
- ManyToOne13(() => Brand, (b) => b.collections, { onDelete: "SET NULL" }),
2376
- JoinColumn13({ name: "brandId" })
2595
+ ManyToOne15(() => Brand, (b) => b.collections, { onDelete: "SET NULL" }),
2596
+ JoinColumn15({ name: "brandId" })
2377
2597
  ], Collection.prototype, "brand", 2);
2378
2598
  __decorateClass([
2379
- OneToMany10("Product", "collection")
2599
+ OneToMany11("Product", "collection")
2380
2600
  ], Collection.prototype, "products", 2);
2381
2601
  Collection = __decorateClass([
2382
- Entity22("collections")
2602
+ Entity24("collections")
2383
2603
  ], Collection);
2384
2604
 
2385
2605
  // src/entities/product.entity.ts
2386
- import { Entity as Entity23, PrimaryGeneratedColumn as PrimaryGeneratedColumn23, Column as Column23, ManyToOne as ManyToOne14, OneToMany as OneToMany11, JoinColumn as JoinColumn14 } from "typeorm";
2606
+ import { Entity as Entity25, PrimaryGeneratedColumn as PrimaryGeneratedColumn25, Column as Column25, ManyToOne as ManyToOne16, OneToMany as OneToMany12, JoinColumn as JoinColumn16 } from "typeorm";
2387
2607
  var Product = class {
2388
2608
  id;
2389
2609
  collectionId;
@@ -2414,96 +2634,96 @@ var Product = class {
2414
2634
  taxes;
2415
2635
  };
2416
2636
  __decorateClass([
2417
- PrimaryGeneratedColumn23()
2637
+ PrimaryGeneratedColumn25()
2418
2638
  ], Product.prototype, "id", 2);
2419
2639
  __decorateClass([
2420
- Column23("int", { nullable: true })
2640
+ Column25("int", { nullable: true })
2421
2641
  ], Product.prototype, "collectionId", 2);
2422
2642
  __decorateClass([
2423
- Column23("int", { nullable: true })
2643
+ Column25("int", { nullable: true })
2424
2644
  ], Product.prototype, "brandId", 2);
2425
2645
  __decorateClass([
2426
- Column23("int", { nullable: true })
2646
+ Column25("int", { nullable: true })
2427
2647
  ], Product.prototype, "categoryId", 2);
2428
2648
  __decorateClass([
2429
- Column23("varchar", { nullable: true })
2649
+ Column25("varchar", { nullable: true })
2430
2650
  ], Product.prototype, "sku", 2);
2431
2651
  __decorateClass([
2432
- Column23("varchar", { unique: true, nullable: true })
2652
+ Column25("varchar", { unique: true, nullable: true })
2433
2653
  ], Product.prototype, "slug", 2);
2434
2654
  __decorateClass([
2435
- Column23("varchar", { nullable: true })
2655
+ Column25("varchar", { nullable: true })
2436
2656
  ], Product.prototype, "name", 2);
2437
2657
  __decorateClass([
2438
- Column23("decimal", { precision: 12, scale: 2 })
2658
+ Column25("decimal", { precision: 12, scale: 2 })
2439
2659
  ], Product.prototype, "price", 2);
2440
2660
  __decorateClass([
2441
- Column23("decimal", { precision: 12, scale: 2, nullable: true })
2661
+ Column25("decimal", { precision: 12, scale: 2, nullable: true })
2442
2662
  ], Product.prototype, "compareAtPrice", 2);
2443
2663
  __decorateClass([
2444
- Column23("int", { default: 0 })
2664
+ Column25("int", { default: 0 })
2445
2665
  ], Product.prototype, "quantity", 2);
2446
2666
  __decorateClass([
2447
- Column23("varchar", { default: "draft" })
2667
+ Column25("varchar", { default: "draft" })
2448
2668
  ], Product.prototype, "status", 2);
2449
2669
  __decorateClass([
2450
- Column23("boolean", { default: false })
2670
+ Column25("boolean", { default: false })
2451
2671
  ], Product.prototype, "featured", 2);
2452
2672
  __decorateClass([
2453
- Column23("jsonb", { nullable: true })
2673
+ Column25("jsonb", { nullable: true })
2454
2674
  ], Product.prototype, "metadata", 2);
2455
2675
  __decorateClass([
2456
- Column23({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2676
+ Column25({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2457
2677
  ], Product.prototype, "createdAt", 2);
2458
2678
  __decorateClass([
2459
- Column23({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2679
+ Column25({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2460
2680
  ], Product.prototype, "updatedAt", 2);
2461
2681
  __decorateClass([
2462
- Column23({ type: "timestamp", nullable: true })
2682
+ Column25({ type: "timestamp", nullable: true })
2463
2683
  ], Product.prototype, "deletedAt", 2);
2464
2684
  __decorateClass([
2465
- Column23("boolean", { default: false })
2685
+ Column25("boolean", { default: false })
2466
2686
  ], Product.prototype, "deleted", 2);
2467
2687
  __decorateClass([
2468
- Column23("int", { nullable: true })
2688
+ Column25("int", { nullable: true })
2469
2689
  ], Product.prototype, "createdBy", 2);
2470
2690
  __decorateClass([
2471
- Column23("int", { nullable: true })
2691
+ Column25("int", { nullable: true })
2472
2692
  ], Product.prototype, "updatedBy", 2);
2473
2693
  __decorateClass([
2474
- Column23("int", { nullable: true })
2694
+ Column25("int", { nullable: true })
2475
2695
  ], Product.prototype, "deletedBy", 2);
2476
2696
  __decorateClass([
2477
- Column23("int", { nullable: true })
2697
+ Column25("int", { nullable: true })
2478
2698
  ], Product.prototype, "seoId", 2);
2479
2699
  __decorateClass([
2480
- ManyToOne14(() => Seo, { onDelete: "SET NULL" }),
2481
- JoinColumn14({ name: "seoId" })
2700
+ ManyToOne16(() => Seo, { onDelete: "SET NULL" }),
2701
+ JoinColumn16({ name: "seoId" })
2482
2702
  ], Product.prototype, "seo", 2);
2483
2703
  __decorateClass([
2484
- ManyToOne14(() => Collection, (c) => c.products, { onDelete: "SET NULL" }),
2485
- JoinColumn14({ name: "collectionId" })
2704
+ ManyToOne16(() => Collection, (c) => c.products, { onDelete: "SET NULL" }),
2705
+ JoinColumn16({ name: "collectionId" })
2486
2706
  ], Product.prototype, "collection", 2);
2487
2707
  __decorateClass([
2488
- ManyToOne14(() => Brand, (b) => b.products, { onDelete: "SET NULL" }),
2489
- JoinColumn14({ name: "brandId" })
2708
+ ManyToOne16(() => Brand, (b) => b.products, { onDelete: "SET NULL" }),
2709
+ JoinColumn16({ name: "brandId" })
2490
2710
  ], Product.prototype, "brand", 2);
2491
2711
  __decorateClass([
2492
- ManyToOne14(() => ProductCategory, (c) => c.products, { onDelete: "SET NULL" }),
2493
- JoinColumn14({ name: "categoryId" })
2712
+ ManyToOne16(() => ProductCategory, (c) => c.products, { onDelete: "SET NULL" }),
2713
+ JoinColumn16({ name: "categoryId" })
2494
2714
  ], Product.prototype, "category", 2);
2495
2715
  __decorateClass([
2496
- OneToMany11("ProductAttribute", "product")
2716
+ OneToMany12("ProductAttribute", "product")
2497
2717
  ], Product.prototype, "attributes", 2);
2498
2718
  __decorateClass([
2499
- OneToMany11("ProductTax", "product")
2719
+ OneToMany12("ProductTax", "product")
2500
2720
  ], Product.prototype, "taxes", 2);
2501
2721
  Product = __decorateClass([
2502
- Entity23("products")
2722
+ Entity25("products")
2503
2723
  ], Product);
2504
2724
 
2505
2725
  // src/entities/attribute.entity.ts
2506
- import { Entity as Entity24, PrimaryGeneratedColumn as PrimaryGeneratedColumn24, Column as Column24 } from "typeorm";
2726
+ import { Entity as Entity26, PrimaryGeneratedColumn as PrimaryGeneratedColumn26, Column as Column26 } from "typeorm";
2507
2727
  var Attribute = class {
2508
2728
  id;
2509
2729
  name;
@@ -2522,56 +2742,56 @@ var Attribute = class {
2522
2742
  deletedBy;
2523
2743
  };
2524
2744
  __decorateClass([
2525
- PrimaryGeneratedColumn24()
2745
+ PrimaryGeneratedColumn26()
2526
2746
  ], Attribute.prototype, "id", 2);
2527
2747
  __decorateClass([
2528
- Column24("varchar")
2748
+ Column26("varchar")
2529
2749
  ], Attribute.prototype, "name", 2);
2530
2750
  __decorateClass([
2531
- Column24("varchar", { unique: true })
2751
+ Column26("varchar", { unique: true })
2532
2752
  ], Attribute.prototype, "slug", 2);
2533
2753
  __decorateClass([
2534
- Column24("varchar", { default: "text" })
2754
+ Column26("varchar", { default: "text" })
2535
2755
  ], Attribute.prototype, "type", 2);
2536
2756
  __decorateClass([
2537
- Column24("jsonb", { nullable: true })
2757
+ Column26("jsonb", { nullable: true })
2538
2758
  ], Attribute.prototype, "options", 2);
2539
2759
  __decorateClass([
2540
- Column24("jsonb", { nullable: true })
2760
+ Column26("jsonb", { nullable: true })
2541
2761
  ], Attribute.prototype, "metadata", 2);
2542
2762
  __decorateClass([
2543
- Column24("boolean", { default: true })
2763
+ Column26("boolean", { default: true })
2544
2764
  ], Attribute.prototype, "active", 2);
2545
2765
  __decorateClass([
2546
- Column24("int", { default: 0 })
2766
+ Column26("int", { default: 0 })
2547
2767
  ], Attribute.prototype, "sortOrder", 2);
2548
2768
  __decorateClass([
2549
- Column24({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2769
+ Column26({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2550
2770
  ], Attribute.prototype, "createdAt", 2);
2551
2771
  __decorateClass([
2552
- Column24({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2772
+ Column26({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2553
2773
  ], Attribute.prototype, "updatedAt", 2);
2554
2774
  __decorateClass([
2555
- Column24({ type: "timestamp", nullable: true })
2775
+ Column26({ type: "timestamp", nullable: true })
2556
2776
  ], Attribute.prototype, "deletedAt", 2);
2557
2777
  __decorateClass([
2558
- Column24("boolean", { default: false })
2778
+ Column26("boolean", { default: false })
2559
2779
  ], Attribute.prototype, "deleted", 2);
2560
2780
  __decorateClass([
2561
- Column24("int", { nullable: true })
2781
+ Column26("int", { nullable: true })
2562
2782
  ], Attribute.prototype, "createdBy", 2);
2563
2783
  __decorateClass([
2564
- Column24("int", { nullable: true })
2784
+ Column26("int", { nullable: true })
2565
2785
  ], Attribute.prototype, "updatedBy", 2);
2566
2786
  __decorateClass([
2567
- Column24("int", { nullable: true })
2787
+ Column26("int", { nullable: true })
2568
2788
  ], Attribute.prototype, "deletedBy", 2);
2569
2789
  Attribute = __decorateClass([
2570
- Entity24("attributes")
2790
+ Entity26("attributes")
2571
2791
  ], Attribute);
2572
2792
 
2573
2793
  // src/entities/product-attribute.entity.ts
2574
- import { Entity as Entity25, PrimaryGeneratedColumn as PrimaryGeneratedColumn25, Column as Column25, ManyToOne as ManyToOne15, JoinColumn as JoinColumn15 } from "typeorm";
2794
+ import { Entity as Entity27, PrimaryGeneratedColumn as PrimaryGeneratedColumn27, Column as Column27, ManyToOne as ManyToOne17, JoinColumn as JoinColumn17 } from "typeorm";
2575
2795
  var ProductAttribute = class {
2576
2796
  id;
2577
2797
  productId;
@@ -2584,40 +2804,40 @@ var ProductAttribute = class {
2584
2804
  attribute;
2585
2805
  };
2586
2806
  __decorateClass([
2587
- PrimaryGeneratedColumn25()
2807
+ PrimaryGeneratedColumn27()
2588
2808
  ], ProductAttribute.prototype, "id", 2);
2589
2809
  __decorateClass([
2590
- Column25("int")
2810
+ Column27("int")
2591
2811
  ], ProductAttribute.prototype, "productId", 2);
2592
2812
  __decorateClass([
2593
- Column25("int")
2813
+ Column27("int")
2594
2814
  ], ProductAttribute.prototype, "attributeId", 2);
2595
2815
  __decorateClass([
2596
- Column25("varchar")
2816
+ Column27("varchar")
2597
2817
  ], ProductAttribute.prototype, "value", 2);
2598
2818
  __decorateClass([
2599
- Column25("jsonb", { nullable: true })
2819
+ Column27("jsonb", { nullable: true })
2600
2820
  ], ProductAttribute.prototype, "metadata", 2);
2601
2821
  __decorateClass([
2602
- Column25({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2822
+ Column27({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2603
2823
  ], ProductAttribute.prototype, "createdAt", 2);
2604
2824
  __decorateClass([
2605
- Column25({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2825
+ Column27({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2606
2826
  ], ProductAttribute.prototype, "updatedAt", 2);
2607
2827
  __decorateClass([
2608
- ManyToOne15(() => Product, (p) => p.attributes, { onDelete: "CASCADE" }),
2609
- JoinColumn15({ name: "productId" })
2828
+ ManyToOne17(() => Product, (p) => p.attributes, { onDelete: "CASCADE" }),
2829
+ JoinColumn17({ name: "productId" })
2610
2830
  ], ProductAttribute.prototype, "product", 2);
2611
2831
  __decorateClass([
2612
- ManyToOne15(() => Attribute, { onDelete: "CASCADE" }),
2613
- JoinColumn15({ name: "attributeId" })
2832
+ ManyToOne17(() => Attribute, { onDelete: "CASCADE" }),
2833
+ JoinColumn17({ name: "attributeId" })
2614
2834
  ], ProductAttribute.prototype, "attribute", 2);
2615
2835
  ProductAttribute = __decorateClass([
2616
- Entity25("product_attributes")
2836
+ Entity27("product_attributes")
2617
2837
  ], ProductAttribute);
2618
2838
 
2619
2839
  // src/entities/tax.entity.ts
2620
- import { Entity as Entity26, PrimaryGeneratedColumn as PrimaryGeneratedColumn26, Column as Column26 } from "typeorm";
2840
+ import { Entity as Entity28, PrimaryGeneratedColumn as PrimaryGeneratedColumn28, Column as Column28 } from "typeorm";
2621
2841
  var Tax = class {
2622
2842
  id;
2623
2843
  name;
@@ -2636,56 +2856,56 @@ var Tax = class {
2636
2856
  deletedBy;
2637
2857
  };
2638
2858
  __decorateClass([
2639
- PrimaryGeneratedColumn26()
2859
+ PrimaryGeneratedColumn28()
2640
2860
  ], Tax.prototype, "id", 2);
2641
2861
  __decorateClass([
2642
- Column26("varchar")
2862
+ Column28("varchar")
2643
2863
  ], Tax.prototype, "name", 2);
2644
2864
  __decorateClass([
2645
- Column26("varchar", { unique: true })
2865
+ Column28("varchar", { unique: true })
2646
2866
  ], Tax.prototype, "slug", 2);
2647
2867
  __decorateClass([
2648
- Column26("decimal", { precision: 5, scale: 2 })
2868
+ Column28("decimal", { precision: 5, scale: 2 })
2649
2869
  ], Tax.prototype, "rate", 2);
2650
2870
  __decorateClass([
2651
- Column26("boolean", { default: false })
2871
+ Column28("boolean", { default: false })
2652
2872
  ], Tax.prototype, "isDefault", 2);
2653
2873
  __decorateClass([
2654
- Column26("text", { nullable: true })
2874
+ Column28("text", { nullable: true })
2655
2875
  ], Tax.prototype, "description", 2);
2656
2876
  __decorateClass([
2657
- Column26("boolean", { default: true })
2877
+ Column28("boolean", { default: true })
2658
2878
  ], Tax.prototype, "active", 2);
2659
2879
  __decorateClass([
2660
- Column26("jsonb", { nullable: true })
2880
+ Column28("jsonb", { nullable: true })
2661
2881
  ], Tax.prototype, "metadata", 2);
2662
2882
  __decorateClass([
2663
- Column26({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2883
+ Column28({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2664
2884
  ], Tax.prototype, "createdAt", 2);
2665
2885
  __decorateClass([
2666
- Column26({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2886
+ Column28({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2667
2887
  ], Tax.prototype, "updatedAt", 2);
2668
2888
  __decorateClass([
2669
- Column26({ type: "timestamp", nullable: true })
2889
+ Column28({ type: "timestamp", nullable: true })
2670
2890
  ], Tax.prototype, "deletedAt", 2);
2671
2891
  __decorateClass([
2672
- Column26("boolean", { default: false })
2892
+ Column28("boolean", { default: false })
2673
2893
  ], Tax.prototype, "deleted", 2);
2674
2894
  __decorateClass([
2675
- Column26("int", { nullable: true })
2895
+ Column28("int", { nullable: true })
2676
2896
  ], Tax.prototype, "createdBy", 2);
2677
2897
  __decorateClass([
2678
- Column26("int", { nullable: true })
2898
+ Column28("int", { nullable: true })
2679
2899
  ], Tax.prototype, "updatedBy", 2);
2680
2900
  __decorateClass([
2681
- Column26("int", { nullable: true })
2901
+ Column28("int", { nullable: true })
2682
2902
  ], Tax.prototype, "deletedBy", 2);
2683
2903
  Tax = __decorateClass([
2684
- Entity26("taxes")
2904
+ Entity28("taxes")
2685
2905
  ], Tax);
2686
2906
 
2687
2907
  // src/entities/product-tax.entity.ts
2688
- import { Entity as Entity27, PrimaryGeneratedColumn as PrimaryGeneratedColumn27, Column as Column27, ManyToOne as ManyToOne16, JoinColumn as JoinColumn16 } from "typeorm";
2908
+ import { Entity as Entity29, PrimaryGeneratedColumn as PrimaryGeneratedColumn29, Column as Column29, ManyToOne as ManyToOne18, JoinColumn as JoinColumn18 } from "typeorm";
2689
2909
  var ProductTax = class {
2690
2910
  id;
2691
2911
  productId;
@@ -2697,37 +2917,37 @@ var ProductTax = class {
2697
2917
  tax;
2698
2918
  };
2699
2919
  __decorateClass([
2700
- PrimaryGeneratedColumn27()
2920
+ PrimaryGeneratedColumn29()
2701
2921
  ], ProductTax.prototype, "id", 2);
2702
2922
  __decorateClass([
2703
- Column27("int")
2923
+ Column29("int")
2704
2924
  ], ProductTax.prototype, "productId", 2);
2705
2925
  __decorateClass([
2706
- Column27("int")
2926
+ Column29("int")
2707
2927
  ], ProductTax.prototype, "taxId", 2);
2708
2928
  __decorateClass([
2709
- Column27("decimal", { precision: 5, scale: 2, nullable: true })
2929
+ Column29("decimal", { precision: 5, scale: 2, nullable: true })
2710
2930
  ], ProductTax.prototype, "rate", 2);
2711
2931
  __decorateClass([
2712
- Column27({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2932
+ Column29({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2713
2933
  ], ProductTax.prototype, "createdAt", 2);
2714
2934
  __decorateClass([
2715
- Column27({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2935
+ Column29({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2716
2936
  ], ProductTax.prototype, "updatedAt", 2);
2717
2937
  __decorateClass([
2718
- ManyToOne16(() => Product, (p) => p.taxes, { onDelete: "CASCADE" }),
2719
- JoinColumn16({ name: "productId" })
2938
+ ManyToOne18(() => Product, (p) => p.taxes, { onDelete: "CASCADE" }),
2939
+ JoinColumn18({ name: "productId" })
2720
2940
  ], ProductTax.prototype, "product", 2);
2721
2941
  __decorateClass([
2722
- ManyToOne16(() => Tax, { onDelete: "CASCADE" }),
2723
- JoinColumn16({ name: "taxId" })
2942
+ ManyToOne18(() => Tax, { onDelete: "CASCADE" }),
2943
+ JoinColumn18({ name: "taxId" })
2724
2944
  ], ProductTax.prototype, "tax", 2);
2725
2945
  ProductTax = __decorateClass([
2726
- Entity27("product_taxes")
2946
+ Entity29("product_taxes")
2727
2947
  ], ProductTax);
2728
2948
 
2729
2949
  // src/entities/order-item.entity.ts
2730
- import { Entity as Entity28, PrimaryGeneratedColumn as PrimaryGeneratedColumn28, Column as Column28, ManyToOne as ManyToOne17, JoinColumn as JoinColumn17 } from "typeorm";
2950
+ import { Entity as Entity30, PrimaryGeneratedColumn as PrimaryGeneratedColumn30, Column as Column30, ManyToOne as ManyToOne19, JoinColumn as JoinColumn19 } from "typeorm";
2731
2951
  var OrderItem = class {
2732
2952
  id;
2733
2953
  orderId;
@@ -2743,47 +2963,118 @@ var OrderItem = class {
2743
2963
  product;
2744
2964
  };
2745
2965
  __decorateClass([
2746
- PrimaryGeneratedColumn28()
2966
+ PrimaryGeneratedColumn30()
2747
2967
  ], OrderItem.prototype, "id", 2);
2748
2968
  __decorateClass([
2749
- Column28("int")
2969
+ Column30("int")
2750
2970
  ], OrderItem.prototype, "orderId", 2);
2751
2971
  __decorateClass([
2752
- Column28("int")
2972
+ Column30("int")
2753
2973
  ], OrderItem.prototype, "productId", 2);
2754
2974
  __decorateClass([
2755
- Column28("int", { default: 1 })
2975
+ Column30("int", { default: 1 })
2756
2976
  ], OrderItem.prototype, "quantity", 2);
2757
2977
  __decorateClass([
2758
- Column28("decimal", { precision: 12, scale: 2 })
2978
+ Column30("decimal", { precision: 12, scale: 2 })
2759
2979
  ], OrderItem.prototype, "unitPrice", 2);
2760
2980
  __decorateClass([
2761
- Column28("decimal", { precision: 12, scale: 2, default: 0 })
2981
+ Column30("decimal", { precision: 12, scale: 2, default: 0 })
2762
2982
  ], OrderItem.prototype, "tax", 2);
2763
2983
  __decorateClass([
2764
- Column28("decimal", { precision: 12, scale: 2 })
2984
+ Column30("decimal", { precision: 12, scale: 2 })
2765
2985
  ], OrderItem.prototype, "total", 2);
2766
2986
  __decorateClass([
2767
- Column28("jsonb", { nullable: true })
2987
+ Column30("jsonb", { nullable: true })
2768
2988
  ], OrderItem.prototype, "metadata", 2);
2769
2989
  __decorateClass([
2770
- Column28({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2990
+ Column30({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2771
2991
  ], OrderItem.prototype, "createdAt", 2);
2772
2992
  __decorateClass([
2773
- Column28({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2993
+ Column30({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2774
2994
  ], OrderItem.prototype, "updatedAt", 2);
2775
2995
  __decorateClass([
2776
- ManyToOne17(() => Order, (o) => o.items, { onDelete: "CASCADE" }),
2777
- JoinColumn17({ name: "orderId" })
2996
+ ManyToOne19(() => Order, (o) => o.items, { onDelete: "CASCADE" }),
2997
+ JoinColumn19({ name: "orderId" })
2778
2998
  ], OrderItem.prototype, "order", 2);
2779
2999
  __decorateClass([
2780
- ManyToOne17(() => Product, { onDelete: "CASCADE" }),
2781
- JoinColumn17({ name: "productId" })
3000
+ ManyToOne19(() => Product, { onDelete: "CASCADE" }),
3001
+ JoinColumn19({ name: "productId" })
2782
3002
  ], OrderItem.prototype, "product", 2);
2783
3003
  OrderItem = __decorateClass([
2784
- Entity28("order_items")
3004
+ Entity30("order_items")
2785
3005
  ], OrderItem);
2786
3006
 
3007
+ // src/entities/knowledge-base-document.entity.ts
3008
+ import { Entity as Entity32, PrimaryGeneratedColumn as PrimaryGeneratedColumn32, Column as Column32, OneToMany as OneToMany13 } from "typeorm";
3009
+
3010
+ // src/entities/knowledge-base-chunk.entity.ts
3011
+ import { Entity as Entity31, PrimaryGeneratedColumn as PrimaryGeneratedColumn31, Column as Column31, ManyToOne as ManyToOne20, JoinColumn as JoinColumn20 } from "typeorm";
3012
+ var KnowledgeBaseChunk = class {
3013
+ id;
3014
+ documentId;
3015
+ content;
3016
+ chunkIndex;
3017
+ createdAt;
3018
+ document;
3019
+ };
3020
+ __decorateClass([
3021
+ PrimaryGeneratedColumn31()
3022
+ ], KnowledgeBaseChunk.prototype, "id", 2);
3023
+ __decorateClass([
3024
+ Column31("int")
3025
+ ], KnowledgeBaseChunk.prototype, "documentId", 2);
3026
+ __decorateClass([
3027
+ Column31("text")
3028
+ ], KnowledgeBaseChunk.prototype, "content", 2);
3029
+ __decorateClass([
3030
+ Column31("int", { default: 0 })
3031
+ ], KnowledgeBaseChunk.prototype, "chunkIndex", 2);
3032
+ __decorateClass([
3033
+ Column31({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
3034
+ ], KnowledgeBaseChunk.prototype, "createdAt", 2);
3035
+ __decorateClass([
3036
+ ManyToOne20(() => KnowledgeBaseDocument, (d) => d.chunks, { onDelete: "CASCADE" }),
3037
+ JoinColumn20({ name: "documentId" })
3038
+ ], KnowledgeBaseChunk.prototype, "document", 2);
3039
+ KnowledgeBaseChunk = __decorateClass([
3040
+ Entity31("knowledge_base_chunks")
3041
+ ], KnowledgeBaseChunk);
3042
+
3043
+ // src/entities/knowledge-base-document.entity.ts
3044
+ var KnowledgeBaseDocument = class {
3045
+ id;
3046
+ name;
3047
+ sourceUrl;
3048
+ content;
3049
+ createdAt;
3050
+ updatedAt;
3051
+ chunks;
3052
+ };
3053
+ __decorateClass([
3054
+ PrimaryGeneratedColumn32()
3055
+ ], KnowledgeBaseDocument.prototype, "id", 2);
3056
+ __decorateClass([
3057
+ Column32("varchar")
3058
+ ], KnowledgeBaseDocument.prototype, "name", 2);
3059
+ __decorateClass([
3060
+ Column32("varchar", { nullable: true })
3061
+ ], KnowledgeBaseDocument.prototype, "sourceUrl", 2);
3062
+ __decorateClass([
3063
+ Column32("text")
3064
+ ], KnowledgeBaseDocument.prototype, "content", 2);
3065
+ __decorateClass([
3066
+ Column32({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
3067
+ ], KnowledgeBaseDocument.prototype, "createdAt", 2);
3068
+ __decorateClass([
3069
+ Column32({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
3070
+ ], KnowledgeBaseDocument.prototype, "updatedAt", 2);
3071
+ __decorateClass([
3072
+ OneToMany13(() => KnowledgeBaseChunk, (c) => c.document)
3073
+ ], KnowledgeBaseDocument.prototype, "chunks", 2);
3074
+ KnowledgeBaseDocument = __decorateClass([
3075
+ Entity32("knowledge_base_documents")
3076
+ ], KnowledgeBaseDocument);
3077
+
2787
3078
  // src/entities/index.ts
2788
3079
  var CMS_ENTITY_MAP = {
2789
3080
  users: User,
@@ -2813,7 +3104,11 @@ var CMS_ENTITY_MAP = {
2813
3104
  orders: Order,
2814
3105
  order_items: OrderItem,
2815
3106
  payments: Payment,
2816
- brands: Brand
3107
+ brands: Brand,
3108
+ knowledge_base_documents: KnowledgeBaseDocument,
3109
+ knowledge_base_chunks: KnowledgeBaseChunk,
3110
+ chat_conversations: ChatConversation,
3111
+ chat_messages: ChatMessage
2817
3112
  };
2818
3113
 
2819
3114
  // src/auth/helpers.ts
@@ -4097,6 +4392,129 @@ function createSettingsApiHandlers(config) {
4097
4392
  }
4098
4393
  };
4099
4394
  }
4395
+ var KB_CHUNK_LIMIT = 10;
4396
+ var KB_CONTEXT_MAX_CHARS = 4e3;
4397
+ function getQueryTerms(message) {
4398
+ return message.replace(/[^\w\s]/g, " ").split(/\s+/).filter((w) => w.length > 2).slice(0, 6);
4399
+ }
4400
+ function createChatHandlers(config) {
4401
+ const { dataSource, entityMap, json, getCms } = config;
4402
+ const contactRepo = () => dataSource.getRepository(entityMap.contacts);
4403
+ const convRepo = () => dataSource.getRepository(entityMap.chat_conversations);
4404
+ const msgRepo = () => dataSource.getRepository(entityMap.chat_messages);
4405
+ const chunkRepo = () => dataSource.getRepository(entityMap.knowledge_base_chunks);
4406
+ return {
4407
+ async identify(req) {
4408
+ try {
4409
+ const body = await req.json();
4410
+ const name = body?.name?.trim();
4411
+ const email = body?.email?.trim();
4412
+ if (!name || !email) return json({ error: "name and email required" }, { status: 400 });
4413
+ const repo = contactRepo();
4414
+ let contact = await repo.findOne({ where: { email, deleted: false } });
4415
+ if (!contact) {
4416
+ const created = repo.create({ name, email, phone: body.phone?.trim() || null });
4417
+ contact = await repo.save(created);
4418
+ }
4419
+ const convRepoInst = convRepo();
4420
+ const conv = await convRepoInst.save(convRepoInst.create({ contactId: contact.id }));
4421
+ return json({
4422
+ contactId: contact.id,
4423
+ conversationId: conv.id
4424
+ });
4425
+ } catch (err) {
4426
+ const message = err instanceof Error ? err.message : "Failed to identify";
4427
+ return json({ error: "Failed to identify", detail: message }, { status: 500 });
4428
+ }
4429
+ },
4430
+ async getMessages(req, conversationId) {
4431
+ try {
4432
+ const conv = await convRepo().findOne({
4433
+ where: { id: parseInt(conversationId, 10) },
4434
+ relations: ["messages"]
4435
+ });
4436
+ if (!conv) return json({ error: "Conversation not found" }, { status: 404 });
4437
+ const messages = (conv.messages ?? []).sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime()).map((m) => ({ role: m.role, content: m.content }));
4438
+ return json({ messages });
4439
+ } catch {
4440
+ return json({ error: "Failed to fetch messages" }, { status: 500 });
4441
+ }
4442
+ },
4443
+ async postMessage(req) {
4444
+ try {
4445
+ const body = await req.json();
4446
+ const conversationId = body?.conversationId;
4447
+ const message = body?.message?.trim();
4448
+ if (!conversationId || !message) return json({ error: "conversationId and message required" }, { status: 400 });
4449
+ const conv = await convRepo().findOne({
4450
+ where: { id: conversationId },
4451
+ relations: ["messages"]
4452
+ });
4453
+ if (!conv) return json({ error: "Conversation not found" }, { status: 404 });
4454
+ const msgRepoInst = msgRepo();
4455
+ await msgRepoInst.save(msgRepoInst.create({ conversationId, role: "user", content: message }));
4456
+ const cms = await getCms();
4457
+ const llm = cms.getPlugin("llm");
4458
+ if (!llm?.chat) return json({ error: "LLM not configured" }, { status: 503 });
4459
+ let contextParts = [];
4460
+ const queryEmbedding = llm.embed ? await llm.embed(message) : null;
4461
+ if (queryEmbedding && queryEmbedding.length > 0) {
4462
+ const vectorStr = "[" + queryEmbedding.join(",") + "]";
4463
+ try {
4464
+ const rows = await dataSource.query(
4465
+ `SELECT id, content FROM knowledge_base_chunks WHERE embedding IS NOT NULL ORDER BY embedding <=> $1::vector LIMIT $2`,
4466
+ [vectorStr, KB_CHUNK_LIMIT]
4467
+ );
4468
+ let totalLen = 0;
4469
+ for (const r of rows) {
4470
+ const text = (r.content ?? "").trim();
4471
+ if (!text || totalLen + text.length > KB_CONTEXT_MAX_CHARS) continue;
4472
+ contextParts.push(text);
4473
+ totalLen += text.length;
4474
+ }
4475
+ } catch {
4476
+ }
4477
+ }
4478
+ if (contextParts.length === 0) {
4479
+ const terms = getQueryTerms(message);
4480
+ if (terms.length > 0) {
4481
+ const conditions = terms.map((t) => ({ content: ILike2(`%${t}%`) }));
4482
+ const chunks = await chunkRepo().find({
4483
+ where: conditions,
4484
+ take: KB_CHUNK_LIMIT,
4485
+ order: { id: "ASC" }
4486
+ });
4487
+ const seen = /* @__PURE__ */ new Set();
4488
+ let totalLen = 0;
4489
+ for (const c of chunks) {
4490
+ const text = c.content.trim();
4491
+ if (seen.has(text) || totalLen + text.length > KB_CONTEXT_MAX_CHARS) continue;
4492
+ seen.add(text);
4493
+ contextParts.push(text);
4494
+ totalLen += text.length;
4495
+ }
4496
+ }
4497
+ }
4498
+ const history = (conv.messages ?? []).sort((a, b) => new Date(a.createdAt ?? 0).getTime() - new Date(b.createdAt ?? 0).getTime()).map((m) => ({ role: m.role, content: m.content }));
4499
+ const systemContent = contextParts.length > 0 ? `Use the following context about the company and its products to answer. If the answer is not in the context, say so.
4500
+
4501
+ Context:
4502
+ ${contextParts.join("\n\n")}` : "You are a helpful assistant for the company. If you do not have specific information, say so.";
4503
+ const messages = [
4504
+ { role: "system", content: systemContent },
4505
+ ...history,
4506
+ { role: "user", content: message }
4507
+ ];
4508
+ const { content } = await llm.chat(messages);
4509
+ await msgRepoInst.save(msgRepoInst.create({ conversationId, role: "assistant", content }));
4510
+ return json({ content });
4511
+ } catch (err) {
4512
+ const msg = err instanceof Error ? err.message : "";
4513
+ return json({ error: msg || "Failed to send message" }, { status: 500 });
4514
+ }
4515
+ }
4516
+ };
4517
+ }
4100
4518
 
4101
4519
  // src/api/cms-api-handler.ts
4102
4520
  var DEFAULT_EXCLUDE = /* @__PURE__ */ new Set(["users", "password_reset_tokens", "user_groups", "permissions", "comments", "form_fields", "configs"]);
@@ -4119,7 +4537,8 @@ function createCmsApiHandler(config) {
4119
4537
  usersApi,
4120
4538
  userAvatar,
4121
4539
  userProfile,
4122
- settings: settingsConfig
4540
+ settings: settingsConfig,
4541
+ chat: chatConfig
4123
4542
  } = config;
4124
4543
  const analytics = analyticsConfig ?? (getCms ? {
4125
4544
  json: config.json,
@@ -4164,6 +4583,7 @@ function createCmsApiHandler(config) {
4164
4583
  const avatarPost = userAvatar ? createUserAvatarHandler(userAvatar) : null;
4165
4584
  const profilePut = userProfile ? createUserProfileHandler(userProfile) : null;
4166
4585
  const settingsHandlers = settingsConfig ? createSettingsApiHandlers(settingsConfig) : null;
4586
+ const chatHandlers = chatConfig ? createChatHandlers(chatConfig) : null;
4167
4587
  function resolveResource(segment) {
4168
4588
  const model = pathToModel(segment);
4169
4589
  return crudResources.includes(model) ? model : segment;
@@ -4223,6 +4643,11 @@ function createCmsApiHandler(config) {
4223
4643
  if (method === "GET") return settingsHandlers.GET(req, path[1]);
4224
4644
  if (method === "PUT") return settingsHandlers.PUT(req, path[1]);
4225
4645
  }
4646
+ if (path[0] === "chat" && chatHandlers) {
4647
+ if (path.length === 2 && path[1] === "identify" && method === "POST") return chatHandlers.identify(req);
4648
+ if (path.length === 4 && path[1] === "conversations" && path[3] === "messages" && method === "GET") return chatHandlers.getMessages(req, path[2]);
4649
+ if (path.length === 2 && path[1] === "messages" && method === "POST") return chatHandlers.postMessage(req);
4650
+ }
4226
4651
  if (path.length === 0) return config.json({ error: "Not found" }, { status: 404 });
4227
4652
  const resource = resolveResource(path[0]);
4228
4653
  if (!crudResources.includes(resource)) return config.json({ error: "Invalid resource" }, { status: 400 });
@@ -4270,6 +4695,8 @@ export {
4270
4695
  Brand,
4271
4696
  CMS_ENTITY_MAP,
4272
4697
  Category,
4698
+ ChatConversation,
4699
+ ChatMessage,
4273
4700
  Collection,
4274
4701
  Comment,
4275
4702
  Config,
@@ -4279,6 +4706,9 @@ export {
4279
4706
  Form,
4280
4707
  FormField,
4281
4708
  FormSubmission,
4709
+ KnowledgeBaseChunk,
4710
+ KnowledgeBaseDocument,
4711
+ LlmService,
4282
4712
  Media,
4283
4713
  OPEN_ENDPOINTS,
4284
4714
  Order,
@@ -4331,6 +4761,7 @@ export {
4331
4761
  getRequiredPermission,
4332
4762
  isOpenEndpoint,
4333
4763
  isPublicMethod,
4764
+ llmPlugin,
4334
4765
  localStoragePlugin,
4335
4766
  paymentPlugin,
4336
4767
  s3StoragePlugin,