@infuro/cms-core 1.0.7 → 1.0.9

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
@@ -779,6 +779,153 @@ function localStoragePlugin(config = {}) {
779
779
  };
780
780
  }
781
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
+
782
929
  // src/lib/utils.ts
783
930
  import { clsx } from "clsx";
784
931
  import { twMerge } from "tailwind-merge";
@@ -1375,7 +1522,7 @@ Blog = __decorateClass([
1375
1522
  ], Blog);
1376
1523
 
1377
1524
  // src/entities/contact.entity.ts
1378
- 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";
1379
1526
 
1380
1527
  // src/entities/form-submission.entity.ts
1381
1528
  import { Entity as Entity12, PrimaryGeneratedColumn as PrimaryGeneratedColumn12, Column as Column12, ManyToOne as ManyToOne6, JoinColumn as JoinColumn6 } from "typeorm";
@@ -1834,6 +1981,74 @@ Payment = __decorateClass([
1834
1981
  Entity15("payments")
1835
1982
  ], Payment);
1836
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
+
1837
2052
  // src/entities/contact.entity.ts
1838
2053
  var Contact = class {
1839
2054
  id;
@@ -1855,70 +2070,74 @@ var Contact = class {
1855
2070
  addresses;
1856
2071
  orders;
1857
2072
  payments;
2073
+ chatConversations;
1858
2074
  };
1859
2075
  __decorateClass([
1860
- PrimaryGeneratedColumn16()
2076
+ PrimaryGeneratedColumn18()
1861
2077
  ], Contact.prototype, "id", 2);
1862
2078
  __decorateClass([
1863
- Column16("varchar")
2079
+ Column18("varchar")
1864
2080
  ], Contact.prototype, "name", 2);
1865
2081
  __decorateClass([
1866
- Column16("varchar", { unique: true })
2082
+ Column18("varchar", { unique: true })
1867
2083
  ], Contact.prototype, "email", 2);
1868
2084
  __decorateClass([
1869
- Column16("varchar", { nullable: true })
2085
+ Column18("varchar", { nullable: true })
1870
2086
  ], Contact.prototype, "phone", 2);
1871
2087
  __decorateClass([
1872
- Column16("varchar", { nullable: true })
2088
+ Column18("varchar", { nullable: true })
1873
2089
  ], Contact.prototype, "type", 2);
1874
2090
  __decorateClass([
1875
- Column16("varchar", { nullable: true })
2091
+ Column18("varchar", { nullable: true })
1876
2092
  ], Contact.prototype, "company", 2);
1877
2093
  __decorateClass([
1878
- Column16("varchar", { nullable: true })
2094
+ Column18("varchar", { nullable: true })
1879
2095
  ], Contact.prototype, "taxId", 2);
1880
2096
  __decorateClass([
1881
- Column16("text", { nullable: true })
2097
+ Column18("text", { nullable: true })
1882
2098
  ], Contact.prototype, "notes", 2);
1883
2099
  __decorateClass([
1884
- Column16({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2100
+ Column18({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
1885
2101
  ], Contact.prototype, "createdAt", 2);
1886
2102
  __decorateClass([
1887
- Column16({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2103
+ Column18({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
1888
2104
  ], Contact.prototype, "updatedAt", 2);
1889
2105
  __decorateClass([
1890
- Column16({ type: "timestamp", nullable: true })
2106
+ Column18({ type: "timestamp", nullable: true })
1891
2107
  ], Contact.prototype, "deletedAt", 2);
1892
2108
  __decorateClass([
1893
- Column16("boolean", { default: false })
2109
+ Column18("boolean", { default: false })
1894
2110
  ], Contact.prototype, "deleted", 2);
1895
2111
  __decorateClass([
1896
- Column16("int", { nullable: true })
2112
+ Column18("int", { nullable: true })
1897
2113
  ], Contact.prototype, "createdBy", 2);
1898
2114
  __decorateClass([
1899
- Column16("int", { nullable: true })
2115
+ Column18("int", { nullable: true })
1900
2116
  ], Contact.prototype, "updatedBy", 2);
1901
2117
  __decorateClass([
1902
- Column16("int", { nullable: true })
2118
+ Column18("int", { nullable: true })
1903
2119
  ], Contact.prototype, "deletedBy", 2);
1904
2120
  __decorateClass([
1905
- OneToMany7(() => FormSubmission, (fs) => fs.contact)
2121
+ OneToMany8(() => FormSubmission, (fs) => fs.contact)
1906
2122
  ], Contact.prototype, "form_submissions", 2);
1907
2123
  __decorateClass([
1908
- OneToMany7(() => Address, (a) => a.contact)
2124
+ OneToMany8(() => Address, (a) => a.contact)
1909
2125
  ], Contact.prototype, "addresses", 2);
1910
2126
  __decorateClass([
1911
- OneToMany7(() => Order, (o) => o.contact)
2127
+ OneToMany8(() => Order, (o) => o.contact)
1912
2128
  ], Contact.prototype, "orders", 2);
1913
2129
  __decorateClass([
1914
- OneToMany7(() => Payment, (p) => p.contact)
2130
+ OneToMany8(() => Payment, (p) => p.contact)
1915
2131
  ], Contact.prototype, "payments", 2);
2132
+ __decorateClass([
2133
+ OneToMany8(() => ChatConversation, (c) => c.contact)
2134
+ ], Contact.prototype, "chatConversations", 2);
1916
2135
  Contact = __decorateClass([
1917
- Entity16("contacts")
2136
+ Entity18("contacts")
1918
2137
  ], Contact);
1919
2138
 
1920
2139
  // src/entities/config.entity.ts
1921
- 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";
1922
2141
  var Config = class {
1923
2142
  id;
1924
2143
  settings;
@@ -1935,51 +2154,51 @@ var Config = class {
1935
2154
  deletedBy;
1936
2155
  };
1937
2156
  __decorateClass([
1938
- PrimaryGeneratedColumn17()
2157
+ PrimaryGeneratedColumn19()
1939
2158
  ], Config.prototype, "id", 2);
1940
2159
  __decorateClass([
1941
- Column17("varchar")
2160
+ Column19("varchar")
1942
2161
  ], Config.prototype, "settings", 2);
1943
2162
  __decorateClass([
1944
- Column17("varchar")
2163
+ Column19("varchar")
1945
2164
  ], Config.prototype, "key", 2);
1946
2165
  __decorateClass([
1947
- Column17("varchar")
2166
+ Column19("varchar")
1948
2167
  ], Config.prototype, "value", 2);
1949
2168
  __decorateClass([
1950
- Column17("varchar", { default: "private" })
2169
+ Column19("varchar", { default: "private" })
1951
2170
  ], Config.prototype, "type", 2);
1952
2171
  __decorateClass([
1953
- Column17("boolean", { default: false })
2172
+ Column19("boolean", { default: false })
1954
2173
  ], Config.prototype, "encrypted", 2);
1955
2174
  __decorateClass([
1956
- Column17({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2175
+ Column19({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
1957
2176
  ], Config.prototype, "createdAt", 2);
1958
2177
  __decorateClass([
1959
- Column17({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2178
+ Column19({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
1960
2179
  ], Config.prototype, "updatedAt", 2);
1961
2180
  __decorateClass([
1962
- Column17({ type: "timestamp", nullable: true })
2181
+ Column19({ type: "timestamp", nullable: true })
1963
2182
  ], Config.prototype, "deletedAt", 2);
1964
2183
  __decorateClass([
1965
- Column17("boolean", { default: false })
2184
+ Column19("boolean", { default: false })
1966
2185
  ], Config.prototype, "deleted", 2);
1967
2186
  __decorateClass([
1968
- Column17("int", { nullable: true })
2187
+ Column19("int", { nullable: true })
1969
2188
  ], Config.prototype, "createdBy", 2);
1970
2189
  __decorateClass([
1971
- Column17("int", { nullable: true })
2190
+ Column19("int", { nullable: true })
1972
2191
  ], Config.prototype, "updatedBy", 2);
1973
2192
  __decorateClass([
1974
- Column17("int", { nullable: true })
2193
+ Column19("int", { nullable: true })
1975
2194
  ], Config.prototype, "deletedBy", 2);
1976
2195
  Config = __decorateClass([
1977
- Entity17("configs"),
2196
+ Entity19("configs"),
1978
2197
  Unique(["settings", "key"])
1979
2198
  ], Config);
1980
2199
 
1981
2200
  // src/entities/media.entity.ts
1982
- 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";
1983
2202
  var Media = class {
1984
2203
  id;
1985
2204
  filename;
@@ -1994,44 +2213,44 @@ var Media = class {
1994
2213
  deleted;
1995
2214
  };
1996
2215
  __decorateClass([
1997
- PrimaryGeneratedColumn18()
2216
+ PrimaryGeneratedColumn20()
1998
2217
  ], Media.prototype, "id", 2);
1999
2218
  __decorateClass([
2000
- Column18("varchar")
2219
+ Column20("varchar")
2001
2220
  ], Media.prototype, "filename", 2);
2002
2221
  __decorateClass([
2003
- Column18("varchar")
2222
+ Column20("varchar")
2004
2223
  ], Media.prototype, "url", 2);
2005
2224
  __decorateClass([
2006
- Column18("varchar")
2225
+ Column20("varchar")
2007
2226
  ], Media.prototype, "mimeType", 2);
2008
2227
  __decorateClass([
2009
- Column18("int", { default: 0 })
2228
+ Column20("int", { default: 0 })
2010
2229
  ], Media.prototype, "size", 2);
2011
2230
  __decorateClass([
2012
- Column18("varchar", { nullable: true })
2231
+ Column20("varchar", { nullable: true })
2013
2232
  ], Media.prototype, "alt", 2);
2014
2233
  __decorateClass([
2015
- Column18("boolean", { default: false })
2234
+ Column20("boolean", { default: false })
2016
2235
  ], Media.prototype, "isPublic", 2);
2017
2236
  __decorateClass([
2018
- Column18({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2237
+ Column20({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2019
2238
  ], Media.prototype, "createdAt", 2);
2020
2239
  __decorateClass([
2021
- Column18({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2240
+ Column20({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2022
2241
  ], Media.prototype, "updatedAt", 2);
2023
2242
  __decorateClass([
2024
- Column18({ type: "timestamp", nullable: true })
2243
+ Column20({ type: "timestamp", nullable: true })
2025
2244
  ], Media.prototype, "deletedAt", 2);
2026
2245
  __decorateClass([
2027
- Column18("boolean", { default: false })
2246
+ Column20("boolean", { default: false })
2028
2247
  ], Media.prototype, "deleted", 2);
2029
2248
  Media = __decorateClass([
2030
- Entity18("media")
2249
+ Entity20("media")
2031
2250
  ], Media);
2032
2251
 
2033
2252
  // src/entities/page.entity.ts
2034
- 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";
2035
2254
  var Page = class {
2036
2255
  id;
2037
2256
  title;
@@ -2052,64 +2271,64 @@ var Page = class {
2052
2271
  deletedBy;
2053
2272
  };
2054
2273
  __decorateClass([
2055
- PrimaryGeneratedColumn19()
2274
+ PrimaryGeneratedColumn21()
2056
2275
  ], Page.prototype, "id", 2);
2057
2276
  __decorateClass([
2058
- Column19("varchar")
2277
+ Column21("varchar")
2059
2278
  ], Page.prototype, "title", 2);
2060
2279
  __decorateClass([
2061
- Column19("varchar", { unique: true })
2280
+ Column21("varchar", { unique: true })
2062
2281
  ], Page.prototype, "slug", 2);
2063
2282
  __decorateClass([
2064
- Column19({ type: "jsonb", default: {} })
2283
+ Column21({ type: "jsonb", default: {} })
2065
2284
  ], Page.prototype, "content", 2);
2066
2285
  __decorateClass([
2067
- Column19("boolean", { default: false })
2286
+ Column21("boolean", { default: false })
2068
2287
  ], Page.prototype, "published", 2);
2069
2288
  __decorateClass([
2070
- Column19("varchar", { default: "default" })
2289
+ Column21("varchar", { default: "default" })
2071
2290
  ], Page.prototype, "theme", 2);
2072
2291
  __decorateClass([
2073
- Column19("int", { nullable: true })
2292
+ Column21("int", { nullable: true })
2074
2293
  ], Page.prototype, "parentId", 2);
2075
2294
  __decorateClass([
2076
- ManyToOne10(() => Page, { onDelete: "SET NULL" }),
2077
- JoinColumn10({ name: "parentId" })
2295
+ ManyToOne12(() => Page, { onDelete: "SET NULL" }),
2296
+ JoinColumn12({ name: "parentId" })
2078
2297
  ], Page.prototype, "parent", 2);
2079
2298
  __decorateClass([
2080
- Column19("int", { nullable: true })
2299
+ Column21("int", { nullable: true })
2081
2300
  ], Page.prototype, "seoId", 2);
2082
2301
  __decorateClass([
2083
- ManyToOne10(() => Seo, { onDelete: "SET NULL" }),
2084
- JoinColumn10({ name: "seoId" })
2302
+ ManyToOne12(() => Seo, { onDelete: "SET NULL" }),
2303
+ JoinColumn12({ name: "seoId" })
2085
2304
  ], Page.prototype, "seo", 2);
2086
2305
  __decorateClass([
2087
- Column19({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2306
+ Column21({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2088
2307
  ], Page.prototype, "createdAt", 2);
2089
2308
  __decorateClass([
2090
- Column19({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2309
+ Column21({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2091
2310
  ], Page.prototype, "updatedAt", 2);
2092
2311
  __decorateClass([
2093
- Column19({ type: "timestamp", nullable: true })
2312
+ Column21({ type: "timestamp", nullable: true })
2094
2313
  ], Page.prototype, "deletedAt", 2);
2095
2314
  __decorateClass([
2096
- Column19("boolean", { default: false })
2315
+ Column21("boolean", { default: false })
2097
2316
  ], Page.prototype, "deleted", 2);
2098
2317
  __decorateClass([
2099
- Column19("int", { nullable: true })
2318
+ Column21("int", { nullable: true })
2100
2319
  ], Page.prototype, "createdBy", 2);
2101
2320
  __decorateClass([
2102
- Column19("int", { nullable: true })
2321
+ Column21("int", { nullable: true })
2103
2322
  ], Page.prototype, "updatedBy", 2);
2104
2323
  __decorateClass([
2105
- Column19("int", { nullable: true })
2324
+ Column21("int", { nullable: true })
2106
2325
  ], Page.prototype, "deletedBy", 2);
2107
2326
  Page = __decorateClass([
2108
- Entity19("pages")
2327
+ Entity21("pages")
2109
2328
  ], Page);
2110
2329
 
2111
2330
  // src/entities/product-category.entity.ts
2112
- 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";
2113
2332
  var ProductCategory = class {
2114
2333
  id;
2115
2334
  name;
@@ -2133,75 +2352,75 @@ var ProductCategory = class {
2133
2352
  collections;
2134
2353
  };
2135
2354
  __decorateClass([
2136
- PrimaryGeneratedColumn20()
2355
+ PrimaryGeneratedColumn22()
2137
2356
  ], ProductCategory.prototype, "id", 2);
2138
2357
  __decorateClass([
2139
- Column20("varchar")
2358
+ Column22("varchar")
2140
2359
  ], ProductCategory.prototype, "name", 2);
2141
2360
  __decorateClass([
2142
- Column20("varchar", { unique: true })
2361
+ Column22("varchar", { unique: true })
2143
2362
  ], ProductCategory.prototype, "slug", 2);
2144
2363
  __decorateClass([
2145
- Column20("int", { nullable: true })
2364
+ Column22("int", { nullable: true })
2146
2365
  ], ProductCategory.prototype, "parentId", 2);
2147
2366
  __decorateClass([
2148
- Column20("varchar", { nullable: true })
2367
+ Column22("varchar", { nullable: true })
2149
2368
  ], ProductCategory.prototype, "image", 2);
2150
2369
  __decorateClass([
2151
- Column20("text", { nullable: true })
2370
+ Column22("text", { nullable: true })
2152
2371
  ], ProductCategory.prototype, "description", 2);
2153
2372
  __decorateClass([
2154
- Column20("jsonb", { nullable: true })
2373
+ Column22("jsonb", { nullable: true })
2155
2374
  ], ProductCategory.prototype, "metadata", 2);
2156
2375
  __decorateClass([
2157
- Column20("boolean", { default: true })
2376
+ Column22("boolean", { default: true })
2158
2377
  ], ProductCategory.prototype, "active", 2);
2159
2378
  __decorateClass([
2160
- Column20("int", { default: 0 })
2379
+ Column22("int", { default: 0 })
2161
2380
  ], ProductCategory.prototype, "sortOrder", 2);
2162
2381
  __decorateClass([
2163
- Column20({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2382
+ Column22({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2164
2383
  ], ProductCategory.prototype, "createdAt", 2);
2165
2384
  __decorateClass([
2166
- Column20({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2385
+ Column22({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2167
2386
  ], ProductCategory.prototype, "updatedAt", 2);
2168
2387
  __decorateClass([
2169
- Column20({ type: "timestamp", nullable: true })
2388
+ Column22({ type: "timestamp", nullable: true })
2170
2389
  ], ProductCategory.prototype, "deletedAt", 2);
2171
2390
  __decorateClass([
2172
- Column20("boolean", { default: false })
2391
+ Column22("boolean", { default: false })
2173
2392
  ], ProductCategory.prototype, "deleted", 2);
2174
2393
  __decorateClass([
2175
- Column20("int", { nullable: true })
2394
+ Column22("int", { nullable: true })
2176
2395
  ], ProductCategory.prototype, "createdBy", 2);
2177
2396
  __decorateClass([
2178
- Column20("int", { nullable: true })
2397
+ Column22("int", { nullable: true })
2179
2398
  ], ProductCategory.prototype, "updatedBy", 2);
2180
2399
  __decorateClass([
2181
- Column20("int", { nullable: true })
2400
+ Column22("int", { nullable: true })
2182
2401
  ], ProductCategory.prototype, "deletedBy", 2);
2183
2402
  __decorateClass([
2184
- ManyToOne11(() => ProductCategory, (c) => c.children, { onDelete: "SET NULL" }),
2185
- JoinColumn11({ name: "parentId" })
2403
+ ManyToOne13(() => ProductCategory, (c) => c.children, { onDelete: "SET NULL" }),
2404
+ JoinColumn13({ name: "parentId" })
2186
2405
  ], ProductCategory.prototype, "parent", 2);
2187
2406
  __decorateClass([
2188
- OneToMany8(() => ProductCategory, (c) => c.parent)
2407
+ OneToMany9(() => ProductCategory, (c) => c.parent)
2189
2408
  ], ProductCategory.prototype, "children", 2);
2190
2409
  __decorateClass([
2191
- OneToMany8("Product", "category")
2410
+ OneToMany9("Product", "category")
2192
2411
  ], ProductCategory.prototype, "products", 2);
2193
2412
  __decorateClass([
2194
- OneToMany8("Collection", "category")
2413
+ OneToMany9("Collection", "category")
2195
2414
  ], ProductCategory.prototype, "collections", 2);
2196
2415
  ProductCategory = __decorateClass([
2197
- Entity20("product_categories")
2416
+ Entity22("product_categories")
2198
2417
  ], ProductCategory);
2199
2418
 
2200
2419
  // src/entities/collection.entity.ts
2201
- 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";
2202
2421
 
2203
2422
  // src/entities/brand.entity.ts
2204
- 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";
2205
2424
  var Brand = class {
2206
2425
  id;
2207
2426
  name;
@@ -2224,65 +2443,65 @@ var Brand = class {
2224
2443
  collections;
2225
2444
  };
2226
2445
  __decorateClass([
2227
- PrimaryGeneratedColumn21()
2446
+ PrimaryGeneratedColumn23()
2228
2447
  ], Brand.prototype, "id", 2);
2229
2448
  __decorateClass([
2230
- Column21("varchar")
2449
+ Column23("varchar")
2231
2450
  ], Brand.prototype, "name", 2);
2232
2451
  __decorateClass([
2233
- Column21("varchar", { unique: true })
2452
+ Column23("varchar", { unique: true })
2234
2453
  ], Brand.prototype, "slug", 2);
2235
2454
  __decorateClass([
2236
- Column21("varchar", { nullable: true })
2455
+ Column23("varchar", { nullable: true })
2237
2456
  ], Brand.prototype, "logo", 2);
2238
2457
  __decorateClass([
2239
- Column21("jsonb", { nullable: true })
2458
+ Column23("jsonb", { nullable: true })
2240
2459
  ], Brand.prototype, "metadata", 2);
2241
2460
  __decorateClass([
2242
- Column21("text", { nullable: true })
2461
+ Column23("text", { nullable: true })
2243
2462
  ], Brand.prototype, "description", 2);
2244
2463
  __decorateClass([
2245
- Column21("boolean", { default: true })
2464
+ Column23("boolean", { default: true })
2246
2465
  ], Brand.prototype, "active", 2);
2247
2466
  __decorateClass([
2248
- Column21("int", { default: 0 })
2467
+ Column23("int", { default: 0 })
2249
2468
  ], Brand.prototype, "sortOrder", 2);
2250
2469
  __decorateClass([
2251
- Column21({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2470
+ Column23({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2252
2471
  ], Brand.prototype, "createdAt", 2);
2253
2472
  __decorateClass([
2254
- Column21({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2473
+ Column23({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2255
2474
  ], Brand.prototype, "updatedAt", 2);
2256
2475
  __decorateClass([
2257
- Column21({ type: "timestamp", nullable: true })
2476
+ Column23({ type: "timestamp", nullable: true })
2258
2477
  ], Brand.prototype, "deletedAt", 2);
2259
2478
  __decorateClass([
2260
- Column21("boolean", { default: false })
2479
+ Column23("boolean", { default: false })
2261
2480
  ], Brand.prototype, "deleted", 2);
2262
2481
  __decorateClass([
2263
- Column21("int", { nullable: true })
2482
+ Column23("int", { nullable: true })
2264
2483
  ], Brand.prototype, "createdBy", 2);
2265
2484
  __decorateClass([
2266
- Column21("int", { nullable: true })
2485
+ Column23("int", { nullable: true })
2267
2486
  ], Brand.prototype, "updatedBy", 2);
2268
2487
  __decorateClass([
2269
- Column21("int", { nullable: true })
2488
+ Column23("int", { nullable: true })
2270
2489
  ], Brand.prototype, "deletedBy", 2);
2271
2490
  __decorateClass([
2272
- Column21("int", { nullable: true })
2491
+ Column23("int", { nullable: true })
2273
2492
  ], Brand.prototype, "seoId", 2);
2274
2493
  __decorateClass([
2275
- ManyToOne12(() => Seo, { onDelete: "SET NULL" }),
2276
- JoinColumn12({ name: "seoId" })
2494
+ ManyToOne14(() => Seo, { onDelete: "SET NULL" }),
2495
+ JoinColumn14({ name: "seoId" })
2277
2496
  ], Brand.prototype, "seo", 2);
2278
2497
  __decorateClass([
2279
- OneToMany9("Product", "brand")
2498
+ OneToMany10("Product", "brand")
2280
2499
  ], Brand.prototype, "products", 2);
2281
2500
  __decorateClass([
2282
- OneToMany9("Collection", "brand")
2501
+ OneToMany10("Collection", "brand")
2283
2502
  ], Brand.prototype, "collections", 2);
2284
2503
  Brand = __decorateClass([
2285
- Entity21("brands")
2504
+ Entity23("brands")
2286
2505
  ], Brand);
2287
2506
 
2288
2507
  // src/entities/collection.entity.ts
@@ -2311,80 +2530,80 @@ var Collection = class {
2311
2530
  products;
2312
2531
  };
2313
2532
  __decorateClass([
2314
- PrimaryGeneratedColumn22()
2533
+ PrimaryGeneratedColumn24()
2315
2534
  ], Collection.prototype, "id", 2);
2316
2535
  __decorateClass([
2317
- Column22("int", { nullable: true })
2536
+ Column24("int", { nullable: true })
2318
2537
  ], Collection.prototype, "categoryId", 2);
2319
2538
  __decorateClass([
2320
- Column22("int", { nullable: true })
2539
+ Column24("int", { nullable: true })
2321
2540
  ], Collection.prototype, "brandId", 2);
2322
2541
  __decorateClass([
2323
- Column22("varchar")
2542
+ Column24("varchar")
2324
2543
  ], Collection.prototype, "name", 2);
2325
2544
  __decorateClass([
2326
- Column22("varchar", { unique: true })
2545
+ Column24("varchar", { unique: true })
2327
2546
  ], Collection.prototype, "slug", 2);
2328
2547
  __decorateClass([
2329
- Column22("text", { nullable: true })
2548
+ Column24("text", { nullable: true })
2330
2549
  ], Collection.prototype, "description", 2);
2331
2550
  __decorateClass([
2332
- Column22("varchar", { nullable: true })
2551
+ Column24("varchar", { nullable: true })
2333
2552
  ], Collection.prototype, "image", 2);
2334
2553
  __decorateClass([
2335
- Column22("jsonb", { nullable: true })
2554
+ Column24("jsonb", { nullable: true })
2336
2555
  ], Collection.prototype, "metadata", 2);
2337
2556
  __decorateClass([
2338
- Column22("boolean", { default: true })
2557
+ Column24("boolean", { default: true })
2339
2558
  ], Collection.prototype, "active", 2);
2340
2559
  __decorateClass([
2341
- Column22("int", { default: 0 })
2560
+ Column24("int", { default: 0 })
2342
2561
  ], Collection.prototype, "sortOrder", 2);
2343
2562
  __decorateClass([
2344
- Column22({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2563
+ Column24({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2345
2564
  ], Collection.prototype, "createdAt", 2);
2346
2565
  __decorateClass([
2347
- Column22({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2566
+ Column24({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2348
2567
  ], Collection.prototype, "updatedAt", 2);
2349
2568
  __decorateClass([
2350
- Column22({ type: "timestamp", nullable: true })
2569
+ Column24({ type: "timestamp", nullable: true })
2351
2570
  ], Collection.prototype, "deletedAt", 2);
2352
2571
  __decorateClass([
2353
- Column22("boolean", { default: false })
2572
+ Column24("boolean", { default: false })
2354
2573
  ], Collection.prototype, "deleted", 2);
2355
2574
  __decorateClass([
2356
- Column22("int", { nullable: true })
2575
+ Column24("int", { nullable: true })
2357
2576
  ], Collection.prototype, "createdBy", 2);
2358
2577
  __decorateClass([
2359
- Column22("int", { nullable: true })
2578
+ Column24("int", { nullable: true })
2360
2579
  ], Collection.prototype, "updatedBy", 2);
2361
2580
  __decorateClass([
2362
- Column22("int", { nullable: true })
2581
+ Column24("int", { nullable: true })
2363
2582
  ], Collection.prototype, "deletedBy", 2);
2364
2583
  __decorateClass([
2365
- Column22("int", { nullable: true })
2584
+ Column24("int", { nullable: true })
2366
2585
  ], Collection.prototype, "seoId", 2);
2367
2586
  __decorateClass([
2368
- ManyToOne13(() => Seo, { onDelete: "SET NULL" }),
2369
- JoinColumn13({ name: "seoId" })
2587
+ ManyToOne15(() => Seo, { onDelete: "SET NULL" }),
2588
+ JoinColumn15({ name: "seoId" })
2370
2589
  ], Collection.prototype, "seo", 2);
2371
2590
  __decorateClass([
2372
- ManyToOne13(() => ProductCategory, (c) => c.collections, { onDelete: "SET NULL" }),
2373
- JoinColumn13({ name: "categoryId" })
2591
+ ManyToOne15(() => ProductCategory, (c) => c.collections, { onDelete: "SET NULL" }),
2592
+ JoinColumn15({ name: "categoryId" })
2374
2593
  ], Collection.prototype, "category", 2);
2375
2594
  __decorateClass([
2376
- ManyToOne13(() => Brand, (b) => b.collections, { onDelete: "SET NULL" }),
2377
- JoinColumn13({ name: "brandId" })
2595
+ ManyToOne15(() => Brand, (b) => b.collections, { onDelete: "SET NULL" }),
2596
+ JoinColumn15({ name: "brandId" })
2378
2597
  ], Collection.prototype, "brand", 2);
2379
2598
  __decorateClass([
2380
- OneToMany10("Product", "collection")
2599
+ OneToMany11("Product", "collection")
2381
2600
  ], Collection.prototype, "products", 2);
2382
2601
  Collection = __decorateClass([
2383
- Entity22("collections")
2602
+ Entity24("collections")
2384
2603
  ], Collection);
2385
2604
 
2386
2605
  // src/entities/product.entity.ts
2387
- 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";
2388
2607
  var Product = class {
2389
2608
  id;
2390
2609
  collectionId;
@@ -2415,96 +2634,96 @@ var Product = class {
2415
2634
  taxes;
2416
2635
  };
2417
2636
  __decorateClass([
2418
- PrimaryGeneratedColumn23()
2637
+ PrimaryGeneratedColumn25()
2419
2638
  ], Product.prototype, "id", 2);
2420
2639
  __decorateClass([
2421
- Column23("int", { nullable: true })
2640
+ Column25("int", { nullable: true })
2422
2641
  ], Product.prototype, "collectionId", 2);
2423
2642
  __decorateClass([
2424
- Column23("int", { nullable: true })
2643
+ Column25("int", { nullable: true })
2425
2644
  ], Product.prototype, "brandId", 2);
2426
2645
  __decorateClass([
2427
- Column23("int", { nullable: true })
2646
+ Column25("int", { nullable: true })
2428
2647
  ], Product.prototype, "categoryId", 2);
2429
2648
  __decorateClass([
2430
- Column23("varchar", { nullable: true })
2649
+ Column25("varchar", { nullable: true })
2431
2650
  ], Product.prototype, "sku", 2);
2432
2651
  __decorateClass([
2433
- Column23("varchar", { unique: true, nullable: true })
2652
+ Column25("varchar", { unique: true, nullable: true })
2434
2653
  ], Product.prototype, "slug", 2);
2435
2654
  __decorateClass([
2436
- Column23("varchar", { nullable: true })
2655
+ Column25("varchar", { nullable: true })
2437
2656
  ], Product.prototype, "name", 2);
2438
2657
  __decorateClass([
2439
- Column23("decimal", { precision: 12, scale: 2 })
2658
+ Column25("decimal", { precision: 12, scale: 2 })
2440
2659
  ], Product.prototype, "price", 2);
2441
2660
  __decorateClass([
2442
- Column23("decimal", { precision: 12, scale: 2, nullable: true })
2661
+ Column25("decimal", { precision: 12, scale: 2, nullable: true })
2443
2662
  ], Product.prototype, "compareAtPrice", 2);
2444
2663
  __decorateClass([
2445
- Column23("int", { default: 0 })
2664
+ Column25("int", { default: 0 })
2446
2665
  ], Product.prototype, "quantity", 2);
2447
2666
  __decorateClass([
2448
- Column23("varchar", { default: "draft" })
2667
+ Column25("varchar", { default: "draft" })
2449
2668
  ], Product.prototype, "status", 2);
2450
2669
  __decorateClass([
2451
- Column23("boolean", { default: false })
2670
+ Column25("boolean", { default: false })
2452
2671
  ], Product.prototype, "featured", 2);
2453
2672
  __decorateClass([
2454
- Column23("jsonb", { nullable: true })
2673
+ Column25("jsonb", { nullable: true })
2455
2674
  ], Product.prototype, "metadata", 2);
2456
2675
  __decorateClass([
2457
- Column23({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2676
+ Column25({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2458
2677
  ], Product.prototype, "createdAt", 2);
2459
2678
  __decorateClass([
2460
- Column23({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2679
+ Column25({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2461
2680
  ], Product.prototype, "updatedAt", 2);
2462
2681
  __decorateClass([
2463
- Column23({ type: "timestamp", nullable: true })
2682
+ Column25({ type: "timestamp", nullable: true })
2464
2683
  ], Product.prototype, "deletedAt", 2);
2465
2684
  __decorateClass([
2466
- Column23("boolean", { default: false })
2685
+ Column25("boolean", { default: false })
2467
2686
  ], Product.prototype, "deleted", 2);
2468
2687
  __decorateClass([
2469
- Column23("int", { nullable: true })
2688
+ Column25("int", { nullable: true })
2470
2689
  ], Product.prototype, "createdBy", 2);
2471
2690
  __decorateClass([
2472
- Column23("int", { nullable: true })
2691
+ Column25("int", { nullable: true })
2473
2692
  ], Product.prototype, "updatedBy", 2);
2474
2693
  __decorateClass([
2475
- Column23("int", { nullable: true })
2694
+ Column25("int", { nullable: true })
2476
2695
  ], Product.prototype, "deletedBy", 2);
2477
2696
  __decorateClass([
2478
- Column23("int", { nullable: true })
2697
+ Column25("int", { nullable: true })
2479
2698
  ], Product.prototype, "seoId", 2);
2480
2699
  __decorateClass([
2481
- ManyToOne14(() => Seo, { onDelete: "SET NULL" }),
2482
- JoinColumn14({ name: "seoId" })
2700
+ ManyToOne16(() => Seo, { onDelete: "SET NULL" }),
2701
+ JoinColumn16({ name: "seoId" })
2483
2702
  ], Product.prototype, "seo", 2);
2484
2703
  __decorateClass([
2485
- ManyToOne14(() => Collection, (c) => c.products, { onDelete: "SET NULL" }),
2486
- JoinColumn14({ name: "collectionId" })
2704
+ ManyToOne16(() => Collection, (c) => c.products, { onDelete: "SET NULL" }),
2705
+ JoinColumn16({ name: "collectionId" })
2487
2706
  ], Product.prototype, "collection", 2);
2488
2707
  __decorateClass([
2489
- ManyToOne14(() => Brand, (b) => b.products, { onDelete: "SET NULL" }),
2490
- JoinColumn14({ name: "brandId" })
2708
+ ManyToOne16(() => Brand, (b) => b.products, { onDelete: "SET NULL" }),
2709
+ JoinColumn16({ name: "brandId" })
2491
2710
  ], Product.prototype, "brand", 2);
2492
2711
  __decorateClass([
2493
- ManyToOne14(() => ProductCategory, (c) => c.products, { onDelete: "SET NULL" }),
2494
- JoinColumn14({ name: "categoryId" })
2712
+ ManyToOne16(() => ProductCategory, (c) => c.products, { onDelete: "SET NULL" }),
2713
+ JoinColumn16({ name: "categoryId" })
2495
2714
  ], Product.prototype, "category", 2);
2496
2715
  __decorateClass([
2497
- OneToMany11("ProductAttribute", "product")
2716
+ OneToMany12("ProductAttribute", "product")
2498
2717
  ], Product.prototype, "attributes", 2);
2499
2718
  __decorateClass([
2500
- OneToMany11("ProductTax", "product")
2719
+ OneToMany12("ProductTax", "product")
2501
2720
  ], Product.prototype, "taxes", 2);
2502
2721
  Product = __decorateClass([
2503
- Entity23("products")
2722
+ Entity25("products")
2504
2723
  ], Product);
2505
2724
 
2506
2725
  // src/entities/attribute.entity.ts
2507
- 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";
2508
2727
  var Attribute = class {
2509
2728
  id;
2510
2729
  name;
@@ -2523,56 +2742,56 @@ var Attribute = class {
2523
2742
  deletedBy;
2524
2743
  };
2525
2744
  __decorateClass([
2526
- PrimaryGeneratedColumn24()
2745
+ PrimaryGeneratedColumn26()
2527
2746
  ], Attribute.prototype, "id", 2);
2528
2747
  __decorateClass([
2529
- Column24("varchar")
2748
+ Column26("varchar")
2530
2749
  ], Attribute.prototype, "name", 2);
2531
2750
  __decorateClass([
2532
- Column24("varchar", { unique: true })
2751
+ Column26("varchar", { unique: true })
2533
2752
  ], Attribute.prototype, "slug", 2);
2534
2753
  __decorateClass([
2535
- Column24("varchar", { default: "text" })
2754
+ Column26("varchar", { default: "text" })
2536
2755
  ], Attribute.prototype, "type", 2);
2537
2756
  __decorateClass([
2538
- Column24("jsonb", { nullable: true })
2757
+ Column26("jsonb", { nullable: true })
2539
2758
  ], Attribute.prototype, "options", 2);
2540
2759
  __decorateClass([
2541
- Column24("jsonb", { nullable: true })
2760
+ Column26("jsonb", { nullable: true })
2542
2761
  ], Attribute.prototype, "metadata", 2);
2543
2762
  __decorateClass([
2544
- Column24("boolean", { default: true })
2763
+ Column26("boolean", { default: true })
2545
2764
  ], Attribute.prototype, "active", 2);
2546
2765
  __decorateClass([
2547
- Column24("int", { default: 0 })
2766
+ Column26("int", { default: 0 })
2548
2767
  ], Attribute.prototype, "sortOrder", 2);
2549
2768
  __decorateClass([
2550
- Column24({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2769
+ Column26({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2551
2770
  ], Attribute.prototype, "createdAt", 2);
2552
2771
  __decorateClass([
2553
- Column24({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2772
+ Column26({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2554
2773
  ], Attribute.prototype, "updatedAt", 2);
2555
2774
  __decorateClass([
2556
- Column24({ type: "timestamp", nullable: true })
2775
+ Column26({ type: "timestamp", nullable: true })
2557
2776
  ], Attribute.prototype, "deletedAt", 2);
2558
2777
  __decorateClass([
2559
- Column24("boolean", { default: false })
2778
+ Column26("boolean", { default: false })
2560
2779
  ], Attribute.prototype, "deleted", 2);
2561
2780
  __decorateClass([
2562
- Column24("int", { nullable: true })
2781
+ Column26("int", { nullable: true })
2563
2782
  ], Attribute.prototype, "createdBy", 2);
2564
2783
  __decorateClass([
2565
- Column24("int", { nullable: true })
2784
+ Column26("int", { nullable: true })
2566
2785
  ], Attribute.prototype, "updatedBy", 2);
2567
2786
  __decorateClass([
2568
- Column24("int", { nullable: true })
2787
+ Column26("int", { nullable: true })
2569
2788
  ], Attribute.prototype, "deletedBy", 2);
2570
2789
  Attribute = __decorateClass([
2571
- Entity24("attributes")
2790
+ Entity26("attributes")
2572
2791
  ], Attribute);
2573
2792
 
2574
2793
  // src/entities/product-attribute.entity.ts
2575
- 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";
2576
2795
  var ProductAttribute = class {
2577
2796
  id;
2578
2797
  productId;
@@ -2585,40 +2804,40 @@ var ProductAttribute = class {
2585
2804
  attribute;
2586
2805
  };
2587
2806
  __decorateClass([
2588
- PrimaryGeneratedColumn25()
2807
+ PrimaryGeneratedColumn27()
2589
2808
  ], ProductAttribute.prototype, "id", 2);
2590
2809
  __decorateClass([
2591
- Column25("int")
2810
+ Column27("int")
2592
2811
  ], ProductAttribute.prototype, "productId", 2);
2593
2812
  __decorateClass([
2594
- Column25("int")
2813
+ Column27("int")
2595
2814
  ], ProductAttribute.prototype, "attributeId", 2);
2596
2815
  __decorateClass([
2597
- Column25("varchar")
2816
+ Column27("varchar")
2598
2817
  ], ProductAttribute.prototype, "value", 2);
2599
2818
  __decorateClass([
2600
- Column25("jsonb", { nullable: true })
2819
+ Column27("jsonb", { nullable: true })
2601
2820
  ], ProductAttribute.prototype, "metadata", 2);
2602
2821
  __decorateClass([
2603
- Column25({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2822
+ Column27({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2604
2823
  ], ProductAttribute.prototype, "createdAt", 2);
2605
2824
  __decorateClass([
2606
- Column25({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2825
+ Column27({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2607
2826
  ], ProductAttribute.prototype, "updatedAt", 2);
2608
2827
  __decorateClass([
2609
- ManyToOne15(() => Product, (p) => p.attributes, { onDelete: "CASCADE" }),
2610
- JoinColumn15({ name: "productId" })
2828
+ ManyToOne17(() => Product, (p) => p.attributes, { onDelete: "CASCADE" }),
2829
+ JoinColumn17({ name: "productId" })
2611
2830
  ], ProductAttribute.prototype, "product", 2);
2612
2831
  __decorateClass([
2613
- ManyToOne15(() => Attribute, { onDelete: "CASCADE" }),
2614
- JoinColumn15({ name: "attributeId" })
2832
+ ManyToOne17(() => Attribute, { onDelete: "CASCADE" }),
2833
+ JoinColumn17({ name: "attributeId" })
2615
2834
  ], ProductAttribute.prototype, "attribute", 2);
2616
2835
  ProductAttribute = __decorateClass([
2617
- Entity25("product_attributes")
2836
+ Entity27("product_attributes")
2618
2837
  ], ProductAttribute);
2619
2838
 
2620
2839
  // src/entities/tax.entity.ts
2621
- 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";
2622
2841
  var Tax = class {
2623
2842
  id;
2624
2843
  name;
@@ -2637,56 +2856,56 @@ var Tax = class {
2637
2856
  deletedBy;
2638
2857
  };
2639
2858
  __decorateClass([
2640
- PrimaryGeneratedColumn26()
2859
+ PrimaryGeneratedColumn28()
2641
2860
  ], Tax.prototype, "id", 2);
2642
2861
  __decorateClass([
2643
- Column26("varchar")
2862
+ Column28("varchar")
2644
2863
  ], Tax.prototype, "name", 2);
2645
2864
  __decorateClass([
2646
- Column26("varchar", { unique: true })
2865
+ Column28("varchar", { unique: true })
2647
2866
  ], Tax.prototype, "slug", 2);
2648
2867
  __decorateClass([
2649
- Column26("decimal", { precision: 5, scale: 2 })
2868
+ Column28("decimal", { precision: 5, scale: 2 })
2650
2869
  ], Tax.prototype, "rate", 2);
2651
2870
  __decorateClass([
2652
- Column26("boolean", { default: false })
2871
+ Column28("boolean", { default: false })
2653
2872
  ], Tax.prototype, "isDefault", 2);
2654
2873
  __decorateClass([
2655
- Column26("text", { nullable: true })
2874
+ Column28("text", { nullable: true })
2656
2875
  ], Tax.prototype, "description", 2);
2657
2876
  __decorateClass([
2658
- Column26("boolean", { default: true })
2877
+ Column28("boolean", { default: true })
2659
2878
  ], Tax.prototype, "active", 2);
2660
2879
  __decorateClass([
2661
- Column26("jsonb", { nullable: true })
2880
+ Column28("jsonb", { nullable: true })
2662
2881
  ], Tax.prototype, "metadata", 2);
2663
2882
  __decorateClass([
2664
- Column26({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2883
+ Column28({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2665
2884
  ], Tax.prototype, "createdAt", 2);
2666
2885
  __decorateClass([
2667
- Column26({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2886
+ Column28({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2668
2887
  ], Tax.prototype, "updatedAt", 2);
2669
2888
  __decorateClass([
2670
- Column26({ type: "timestamp", nullable: true })
2889
+ Column28({ type: "timestamp", nullable: true })
2671
2890
  ], Tax.prototype, "deletedAt", 2);
2672
2891
  __decorateClass([
2673
- Column26("boolean", { default: false })
2892
+ Column28("boolean", { default: false })
2674
2893
  ], Tax.prototype, "deleted", 2);
2675
2894
  __decorateClass([
2676
- Column26("int", { nullable: true })
2895
+ Column28("int", { nullable: true })
2677
2896
  ], Tax.prototype, "createdBy", 2);
2678
2897
  __decorateClass([
2679
- Column26("int", { nullable: true })
2898
+ Column28("int", { nullable: true })
2680
2899
  ], Tax.prototype, "updatedBy", 2);
2681
2900
  __decorateClass([
2682
- Column26("int", { nullable: true })
2901
+ Column28("int", { nullable: true })
2683
2902
  ], Tax.prototype, "deletedBy", 2);
2684
2903
  Tax = __decorateClass([
2685
- Entity26("taxes")
2904
+ Entity28("taxes")
2686
2905
  ], Tax);
2687
2906
 
2688
2907
  // src/entities/product-tax.entity.ts
2689
- 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";
2690
2909
  var ProductTax = class {
2691
2910
  id;
2692
2911
  productId;
@@ -2698,37 +2917,37 @@ var ProductTax = class {
2698
2917
  tax;
2699
2918
  };
2700
2919
  __decorateClass([
2701
- PrimaryGeneratedColumn27()
2920
+ PrimaryGeneratedColumn29()
2702
2921
  ], ProductTax.prototype, "id", 2);
2703
2922
  __decorateClass([
2704
- Column27("int")
2923
+ Column29("int")
2705
2924
  ], ProductTax.prototype, "productId", 2);
2706
2925
  __decorateClass([
2707
- Column27("int")
2926
+ Column29("int")
2708
2927
  ], ProductTax.prototype, "taxId", 2);
2709
2928
  __decorateClass([
2710
- Column27("decimal", { precision: 5, scale: 2, nullable: true })
2929
+ Column29("decimal", { precision: 5, scale: 2, nullable: true })
2711
2930
  ], ProductTax.prototype, "rate", 2);
2712
2931
  __decorateClass([
2713
- Column27({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2932
+ Column29({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2714
2933
  ], ProductTax.prototype, "createdAt", 2);
2715
2934
  __decorateClass([
2716
- Column27({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2935
+ Column29({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2717
2936
  ], ProductTax.prototype, "updatedAt", 2);
2718
2937
  __decorateClass([
2719
- ManyToOne16(() => Product, (p) => p.taxes, { onDelete: "CASCADE" }),
2720
- JoinColumn16({ name: "productId" })
2938
+ ManyToOne18(() => Product, (p) => p.taxes, { onDelete: "CASCADE" }),
2939
+ JoinColumn18({ name: "productId" })
2721
2940
  ], ProductTax.prototype, "product", 2);
2722
2941
  __decorateClass([
2723
- ManyToOne16(() => Tax, { onDelete: "CASCADE" }),
2724
- JoinColumn16({ name: "taxId" })
2942
+ ManyToOne18(() => Tax, { onDelete: "CASCADE" }),
2943
+ JoinColumn18({ name: "taxId" })
2725
2944
  ], ProductTax.prototype, "tax", 2);
2726
2945
  ProductTax = __decorateClass([
2727
- Entity27("product_taxes")
2946
+ Entity29("product_taxes")
2728
2947
  ], ProductTax);
2729
2948
 
2730
2949
  // src/entities/order-item.entity.ts
2731
- 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";
2732
2951
  var OrderItem = class {
2733
2952
  id;
2734
2953
  orderId;
@@ -2744,47 +2963,118 @@ var OrderItem = class {
2744
2963
  product;
2745
2964
  };
2746
2965
  __decorateClass([
2747
- PrimaryGeneratedColumn28()
2966
+ PrimaryGeneratedColumn30()
2748
2967
  ], OrderItem.prototype, "id", 2);
2749
2968
  __decorateClass([
2750
- Column28("int")
2969
+ Column30("int")
2751
2970
  ], OrderItem.prototype, "orderId", 2);
2752
2971
  __decorateClass([
2753
- Column28("int")
2972
+ Column30("int")
2754
2973
  ], OrderItem.prototype, "productId", 2);
2755
2974
  __decorateClass([
2756
- Column28("int", { default: 1 })
2975
+ Column30("int", { default: 1 })
2757
2976
  ], OrderItem.prototype, "quantity", 2);
2758
2977
  __decorateClass([
2759
- Column28("decimal", { precision: 12, scale: 2 })
2978
+ Column30("decimal", { precision: 12, scale: 2 })
2760
2979
  ], OrderItem.prototype, "unitPrice", 2);
2761
2980
  __decorateClass([
2762
- Column28("decimal", { precision: 12, scale: 2, default: 0 })
2981
+ Column30("decimal", { precision: 12, scale: 2, default: 0 })
2763
2982
  ], OrderItem.prototype, "tax", 2);
2764
2983
  __decorateClass([
2765
- Column28("decimal", { precision: 12, scale: 2 })
2984
+ Column30("decimal", { precision: 12, scale: 2 })
2766
2985
  ], OrderItem.prototype, "total", 2);
2767
2986
  __decorateClass([
2768
- Column28("jsonb", { nullable: true })
2987
+ Column30("jsonb", { nullable: true })
2769
2988
  ], OrderItem.prototype, "metadata", 2);
2770
2989
  __decorateClass([
2771
- Column28({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2990
+ Column30({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2772
2991
  ], OrderItem.prototype, "createdAt", 2);
2773
2992
  __decorateClass([
2774
- Column28({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2993
+ Column30({ type: "timestamp", default: () => "CURRENT_TIMESTAMP" })
2775
2994
  ], OrderItem.prototype, "updatedAt", 2);
2776
2995
  __decorateClass([
2777
- ManyToOne17(() => Order, (o) => o.items, { onDelete: "CASCADE" }),
2778
- JoinColumn17({ name: "orderId" })
2996
+ ManyToOne19(() => Order, (o) => o.items, { onDelete: "CASCADE" }),
2997
+ JoinColumn19({ name: "orderId" })
2779
2998
  ], OrderItem.prototype, "order", 2);
2780
2999
  __decorateClass([
2781
- ManyToOne17(() => Product, { onDelete: "CASCADE" }),
2782
- JoinColumn17({ name: "productId" })
3000
+ ManyToOne19(() => Product, { onDelete: "CASCADE" }),
3001
+ JoinColumn19({ name: "productId" })
2783
3002
  ], OrderItem.prototype, "product", 2);
2784
3003
  OrderItem = __decorateClass([
2785
- Entity28("order_items")
3004
+ Entity30("order_items")
2786
3005
  ], OrderItem);
2787
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
+
2788
3078
  // src/entities/index.ts
2789
3079
  var CMS_ENTITY_MAP = {
2790
3080
  users: User,
@@ -2814,7 +3104,11 @@ var CMS_ENTITY_MAP = {
2814
3104
  orders: Order,
2815
3105
  order_items: OrderItem,
2816
3106
  payments: Payment,
2817
- brands: Brand
3107
+ brands: Brand,
3108
+ knowledge_base_documents: KnowledgeBaseDocument,
3109
+ knowledge_base_chunks: KnowledgeBaseChunk,
3110
+ chat_conversations: ChatConversation,
3111
+ chat_messages: ChatMessage
2818
3112
  };
2819
3113
 
2820
3114
  // src/auth/helpers.ts
@@ -4098,6 +4392,129 @@ function createSettingsApiHandlers(config) {
4098
4392
  }
4099
4393
  };
4100
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
+ }
4101
4518
 
4102
4519
  // src/api/cms-api-handler.ts
4103
4520
  var DEFAULT_EXCLUDE = /* @__PURE__ */ new Set(["users", "password_reset_tokens", "user_groups", "permissions", "comments", "form_fields", "configs"]);
@@ -4120,7 +4537,8 @@ function createCmsApiHandler(config) {
4120
4537
  usersApi,
4121
4538
  userAvatar,
4122
4539
  userProfile,
4123
- settings: settingsConfig
4540
+ settings: settingsConfig,
4541
+ chat: chatConfig
4124
4542
  } = config;
4125
4543
  const analytics = analyticsConfig ?? (getCms ? {
4126
4544
  json: config.json,
@@ -4165,6 +4583,7 @@ function createCmsApiHandler(config) {
4165
4583
  const avatarPost = userAvatar ? createUserAvatarHandler(userAvatar) : null;
4166
4584
  const profilePut = userProfile ? createUserProfileHandler(userProfile) : null;
4167
4585
  const settingsHandlers = settingsConfig ? createSettingsApiHandlers(settingsConfig) : null;
4586
+ const chatHandlers = chatConfig ? createChatHandlers(chatConfig) : null;
4168
4587
  function resolveResource(segment) {
4169
4588
  const model = pathToModel(segment);
4170
4589
  return crudResources.includes(model) ? model : segment;
@@ -4224,6 +4643,11 @@ function createCmsApiHandler(config) {
4224
4643
  if (method === "GET") return settingsHandlers.GET(req, path[1]);
4225
4644
  if (method === "PUT") return settingsHandlers.PUT(req, path[1]);
4226
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
+ }
4227
4651
  if (path.length === 0) return config.json({ error: "Not found" }, { status: 404 });
4228
4652
  const resource = resolveResource(path[0]);
4229
4653
  if (!crudResources.includes(resource)) return config.json({ error: "Invalid resource" }, { status: 400 });
@@ -4271,6 +4695,8 @@ export {
4271
4695
  Brand,
4272
4696
  CMS_ENTITY_MAP,
4273
4697
  Category,
4698
+ ChatConversation,
4699
+ ChatMessage,
4274
4700
  Collection,
4275
4701
  Comment,
4276
4702
  Config,
@@ -4280,6 +4706,9 @@ export {
4280
4706
  Form,
4281
4707
  FormField,
4282
4708
  FormSubmission,
4709
+ KnowledgeBaseChunk,
4710
+ KnowledgeBaseDocument,
4711
+ LlmService,
4283
4712
  Media,
4284
4713
  OPEN_ENDPOINTS,
4285
4714
  Order,
@@ -4332,6 +4761,7 @@ export {
4332
4761
  getRequiredPermission,
4333
4762
  isOpenEndpoint,
4334
4763
  isPublicMethod,
4764
+ llmPlugin,
4335
4765
  localStoragePlugin,
4336
4766
  paymentPlugin,
4337
4767
  s3StoragePlugin,