From d5d987307842fc6d3b91801c43b8c8c7b099c184 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Mon, 30 Jun 2025 21:08:59 +0500
Subject: [PATCH 01/54] init chat component

---
 .../lowcoder/src/comps/comps/chatComp.tsx     | 50 +++++++++++++++++++
 client/packages/lowcoder/src/comps/index.tsx  | 14 ++++++
 .../lowcoder/src/comps/uiCompRegistry.ts      |  1 +
 .../src/pages/editor/editorConstants.tsx      |  1 +
 4 files changed, 66 insertions(+)
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp.tsx

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp.tsx
new file mode 100644
index 0000000000..cf12c941b6
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp.tsx
@@ -0,0 +1,50 @@
+import { StringControl } from "comps/controls/codeControl";
+import { UICompBuilder, withDefault } from "comps/generators";
+import { NameConfig, withExposingConfigs } from "comps/generators/withExposing";
+import { Section, sectionNames } from "lowcoder-design";
+import { trans } from "i18n";
+import React from "react";
+
+// Simple children map with just basic properties
+const childrenMap = {
+  text: withDefault(StringControl, "Chat Component Placeholder"),
+};
+
+// Basic view - just a simple div for now
+const ChatView = React.memo((props: any) => {
+  return (
+    <div
+      style={{
+        height: "100%",
+        border: "1px solid #ccc",
+        padding: "16px",
+        borderRadius: "4px",
+      }}
+    >
+      {props.text}
+    </div>
+  );
+});
+
+// Basic property view
+const ChatPropertyView = React.memo((props: any) => {
+  return (
+    <Section name={sectionNames.basic}>
+      {props.children.text.propertyView({
+        label: "Text",
+      })}
+    </Section>
+  );
+});
+
+// Build the component
+const ChatTmpComp = new UICompBuilder(childrenMap, (props) => (
+  <ChatView {...props} />
+))
+  .setPropertyViewFn((children) => <ChatPropertyView children={children} />)
+  .build();
+
+// Export the component
+export const ChatComp = withExposingConfigs(ChatTmpComp, [
+  new NameConfig("text", "Chat component text"),
+]);
diff --git a/client/packages/lowcoder/src/comps/index.tsx b/client/packages/lowcoder/src/comps/index.tsx
index 2395f4f290..1d3b7314f5 100644
--- a/client/packages/lowcoder/src/comps/index.tsx
+++ b/client/packages/lowcoder/src/comps/index.tsx
@@ -193,6 +193,7 @@ import { DrawerComp } from "./hooks/drawerComp";
 import { ModalComp } from "./hooks/modalComp";
 import { defaultCollapsibleContainerData } from "./comps/containerComp/collapsibleContainerComp";
 import { ContainerComp as FloatTextContainerComp } from "./comps/containerComp/textContainerComp";
+import { ChatComp } from "./comps/chatComp";
 
 type Registry = {
   [key in UICompType]?: UICompManifest;
@@ -1669,6 +1670,19 @@ export var uiCompMap: Registry = {
       h: 20,
     },
   },
+  chat: {
+    name: "Chat",
+    enName: "Chat", 
+    description: "Chat Component",
+    categories: ["collaboration"],
+    icon: CommentCompIcon, // Use existing icon for now
+    keywords: "chat,conversation",
+    comp: ChatComp,
+    layoutInfo: {
+      w: 12,
+      h: 20,
+    },
+  },
 
   // Integration
 
diff --git a/client/packages/lowcoder/src/comps/uiCompRegistry.ts b/client/packages/lowcoder/src/comps/uiCompRegistry.ts
index 4c320de479..48fb2079b2 100644
--- a/client/packages/lowcoder/src/comps/uiCompRegistry.ts
+++ b/client/packages/lowcoder/src/comps/uiCompRegistry.ts
@@ -169,6 +169,7 @@ export type UICompType =
   | "columnLayout"
   | "ganttChart"
   | "kanban"
+  | "chat" // Added by Faran
   ;
 
 
diff --git a/client/packages/lowcoder/src/pages/editor/editorConstants.tsx b/client/packages/lowcoder/src/pages/editor/editorConstants.tsx
index a931455d4b..d18705af10 100644
--- a/client/packages/lowcoder/src/pages/editor/editorConstants.tsx
+++ b/client/packages/lowcoder/src/pages/editor/editorConstants.tsx
@@ -306,4 +306,5 @@ export const CompStateIcon: {
   sunburstChart: <MemoizedIcon Icon={SunburstChartCompIconSmall} />,
   themeriverChart: <MemoizedIcon Icon={ThemeriverChartCompIconSmall} />,
   basicChart: <MemoizedIcon Icon={ChartCompIconSmall} />,
+  chat: <MemoizedIcon Icon={CommentCompIconSmall} />,
 } as const;

From d1d9b9267663f4e6b8e722da2061c459450c8d77 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Mon, 30 Jun 2025 23:39:09 +0500
Subject: [PATCH 02/54] refactor component structure

---
 .../lowcoder/src/comps/comps/chatComp.tsx     | 50 -------------------
 .../src/comps/comps/chatComp/chatComp.tsx     | 19 +++++++
 .../src/comps/comps/chatComp/chatCompTypes.ts | 11 ++++
 .../comps/comps/chatComp/chatPropertyView.tsx | 15 ++++++
 .../src/comps/comps/chatComp/chatView.tsx     | 18 +++++++
 .../src/comps/comps/chatComp/index.ts         |  3 ++
 6 files changed, 66 insertions(+), 50 deletions(-)
 delete mode 100644 client/packages/lowcoder/src/comps/comps/chatComp.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/index.ts

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp.tsx
deleted file mode 100644
index cf12c941b6..0000000000
--- a/client/packages/lowcoder/src/comps/comps/chatComp.tsx
+++ /dev/null
@@ -1,50 +0,0 @@
-import { StringControl } from "comps/controls/codeControl";
-import { UICompBuilder, withDefault } from "comps/generators";
-import { NameConfig, withExposingConfigs } from "comps/generators/withExposing";
-import { Section, sectionNames } from "lowcoder-design";
-import { trans } from "i18n";
-import React from "react";
-
-// Simple children map with just basic properties
-const childrenMap = {
-  text: withDefault(StringControl, "Chat Component Placeholder"),
-};
-
-// Basic view - just a simple div for now
-const ChatView = React.memo((props: any) => {
-  return (
-    <div
-      style={{
-        height: "100%",
-        border: "1px solid #ccc",
-        padding: "16px",
-        borderRadius: "4px",
-      }}
-    >
-      {props.text}
-    </div>
-  );
-});
-
-// Basic property view
-const ChatPropertyView = React.memo((props: any) => {
-  return (
-    <Section name={sectionNames.basic}>
-      {props.children.text.propertyView({
-        label: "Text",
-      })}
-    </Section>
-  );
-});
-
-// Build the component
-const ChatTmpComp = new UICompBuilder(childrenMap, (props) => (
-  <ChatView {...props} />
-))
-  .setPropertyViewFn((children) => <ChatPropertyView children={children} />)
-  .build();
-
-// Export the component
-export const ChatComp = withExposingConfigs(ChatTmpComp, [
-  new NameConfig("text", "Chat component text"),
-]);
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
new file mode 100644
index 0000000000..e9c395dd2d
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
@@ -0,0 +1,19 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
+import { UICompBuilder } from "comps/generators";
+import { NameConfig, withExposingConfigs } from "comps/generators/withExposing";
+import { chatChildrenMap } from "./chatCompTypes";
+import { ChatView } from "./chatView";
+import { ChatPropertyView } from "./chatPropertyView";
+
+// Build the component
+const ChatTmpComp = new UICompBuilder(
+  chatChildrenMap, 
+  (props) => <ChatView {...props} />
+)
+  .setPropertyViewFn((children) => <ChatPropertyView children={children} />)
+  .build();
+
+// Export the component
+export const ChatComp = withExposingConfigs(ChatTmpComp, [
+  new NameConfig("text", "Chat component text"),
+]);
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
new file mode 100644
index 0000000000..a58a0eda55
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
@@ -0,0 +1,11 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
+import { StringControl } from "comps/controls/codeControl";
+import { withDefault } from "comps/generators";
+
+export const chatChildrenMap = {
+  text: withDefault(StringControl, "Chat Component Placeholder"),
+};
+
+export type ChatCompProps = {
+  text: string;
+};
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
new file mode 100644
index 0000000000..e31f6268de
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
@@ -0,0 +1,15 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
+import React from "react";
+import { Section, sectionNames } from "lowcoder-design";
+
+export const ChatPropertyView = React.memo((props: any) => {
+  return (
+    <Section name={sectionNames.basic}>
+      {props.children.text.propertyView({ 
+        label: "Text" 
+      })}
+    </Section>
+  );
+});
+
+ChatPropertyView.displayName = 'ChatPropertyView';
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
new file mode 100644
index 0000000000..61538c08c3
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
@@ -0,0 +1,18 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
+import React from "react";
+import { ChatCompProps } from "./chatCompTypes";
+
+export const ChatView = React.memo((props: ChatCompProps) => {
+  return (
+    <div style={{ 
+      height: '100%', 
+      border: '1px solid #ccc', 
+      padding: '16px',
+      borderRadius: '4px'
+    }}>
+      {props.text}
+    </div>
+  );
+});
+
+ChatView.displayName = 'ChatView';
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/index.ts b/client/packages/lowcoder/src/comps/comps/chatComp/index.ts
new file mode 100644
index 0000000000..32064185b5
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/index.ts
@@ -0,0 +1,3 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/index.ts
+export { ChatComp } from "./chatComp";
+export type { ChatCompProps } from "./chatCompTypes";
\ No newline at end of file

From 0c132c13958fc37474581c8818e09e952e8ecfe2 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Tue, 1 Jul 2025 00:42:41 +0500
Subject: [PATCH 03/54] install dependencies

---
 client/packages/lowcoder/package.json         |  11 +-
 .../src/comps/comps/chatComp/chatView.tsx     |  84 +-
 client/yarn.lock                              | 953 +++++++++++++++++-
 3 files changed, 1032 insertions(+), 16 deletions(-)

diff --git a/client/packages/lowcoder/package.json b/client/packages/lowcoder/package.json
index 7137e23b6b..3460b19ca3 100644
--- a/client/packages/lowcoder/package.json
+++ b/client/packages/lowcoder/package.json
@@ -6,7 +6,12 @@
   "main": "src/index.sdk.ts",
   "types": "src/index.sdk.ts",
   "dependencies": {
+    "@ai-sdk/openai": "^1.3.22",
     "@ant-design/icons": "^5.3.0",
+    "@assistant-ui/react": "^0.10.24",
+    "@assistant-ui/react-ai-sdk": "^0.10.14",
+    "@assistant-ui/react-markdown": "^0.10.5",
+    "@assistant-ui/styles": "^0.1.13",
     "@bany/curl-to-json": "^1.2.8",
     "@codemirror/autocomplete": "^6.11.1",
     "@codemirror/commands": "^6.3.2",
@@ -28,6 +33,8 @@
     "@jsonforms/core": "^3.5.1",
     "@lottiefiles/dotlottie-react": "^0.13.0",
     "@manaflair/redux-batch": "^1.0.0",
+    "@radix-ui/react-slot": "^1.2.3",
+    "@radix-ui/react-tooltip": "^1.2.7",
     "@rjsf/antd": "^5.24.9",
     "@rjsf/core": "^5.24.9",
     "@rjsf/utils": "^5.24.9",
@@ -37,6 +44,7 @@
     "@types/react-signature-canvas": "^1.0.2",
     "@types/react-test-renderer": "^18.0.0",
     "@types/react-virtualized": "^9.21.21",
+    "ai": "^4.3.16",
     "alasql": "^4.6.6",
     "animate.css": "^4.1.1",
     "antd": "^5.25.2",
@@ -61,6 +69,7 @@
     "loglevel": "^1.8.0",
     "lowcoder-core": "workspace:^",
     "lowcoder-design": "workspace:^",
+    "lucide-react": "^0.525.0",
     "mime": "^3.0.0",
     "moment": "^2.29.4",
     "numbro": "^2.3.6",
@@ -98,7 +107,7 @@
     "regenerator-runtime": "^0.13.9",
     "rehype-raw": "^6.1.1",
     "rehype-sanitize": "^5.0.1",
-    "remark-gfm": "^4.0.0",
+    "remark-gfm": "^4.0.1",
     "resize-observer-polyfill": "^1.5.1",
     "simplebar-react": "^3.2.4",
     "sql-formatter": "^8.2.0",
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
index 61538c08c3..6ca388777f 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
@@ -2,16 +2,84 @@
 import React from "react";
 import { ChatCompProps } from "./chatCompTypes";
 
+// Import assistant-ui components and proper runtime
+import { 
+  AssistantRuntimeProvider,
+  ThreadPrimitive, 
+  ComposerPrimitive
+} from "@assistant-ui/react";
+import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
+import "@assistant-ui/styles/index.css";
+import "@assistant-ui/styles/markdown.css";
+
 export const ChatView = React.memo((props: ChatCompProps) => {
+  // Create proper runtime using useChatRuntime
+  const runtime = useChatRuntime({
+    api: "/api/chat", // We'll create this endpoint later
+  });
+
   return (
-    <div style={{ 
-      height: '100%', 
-      border: '1px solid #ccc', 
-      padding: '16px',
-      borderRadius: '4px'
-    }}>
-      {props.text}
-    </div>
+    <AssistantRuntimeProvider runtime={runtime}>
+      <div style={{ 
+        height: '100%', 
+        padding: '16px',
+        backgroundColor: '#f5f5f5'
+      }}>
+        <div className="aui-root">
+          <h3 style={{ marginBottom: '16px' }}>🚀 Assistant-UI with Vercel AI SDK!</h3>
+          
+          {/* Test Thread with real runtime */}
+          <div className="aui-thread-root" style={{ 
+            background: 'white', 
+            borderRadius: '8px', 
+            padding: '16px',
+            marginBottom: '16px',
+            border: '1px solid #e0e0e0',
+            minHeight: '200px'
+          }}>
+            <ThreadPrimitive.Empty>
+              <div className="aui-thread-welcome-root">
+                <div className="aui-thread-welcome-center">
+                  <p className="aui-thread-welcome-message">
+                      {props.text} - Runtime Working! 🎉
+                  </p>
+                </div>
+              </div>
+            </ThreadPrimitive.Empty>
+          </div>
+
+          {/* Test Composer with real runtime */}
+          <div className="aui-composer-root" style={{
+            background: 'white',
+            borderRadius: '8px',
+            padding: '12px',
+            border: '1px solid #e0e0e0'
+          }}>
+            <ComposerPrimitive.Input
+              placeholder={props.text}
+              disabled={false}
+              className="aui-composer-input"
+              rows={1}
+            />
+          </div>
+
+          {/* Property status */}
+          <div style={{ 
+            marginTop: '16px', 
+            fontSize: '12px', 
+            color: '#666',
+            background: 'white',
+            padding: '8px',
+            borderRadius: '4px',
+            border: '1px solid #e0e0e0'
+          }}>
+            <strong>✅ Test Status:</strong><br/>
+            Text: {props.text}<br/>
+            Runtime: Vercel AI SDK ✅
+          </div>
+        </div>
+      </div>
+    </AssistantRuntimeProvider>
   );
 });
 
diff --git a/client/yarn.lock b/client/yarn.lock
index b3885ff806..de7a2c227b 100644
--- a/client/yarn.lock
+++ b/client/yarn.lock
@@ -45,6 +45,71 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@ai-sdk/openai@npm:^1.3.22":
+  version: 1.3.22
+  resolution: "@ai-sdk/openai@npm:1.3.22"
+  dependencies:
+    "@ai-sdk/provider": 1.1.3
+    "@ai-sdk/provider-utils": 2.2.8
+  peerDependencies:
+    zod: ^3.0.0
+  checksum: 5572a349c93cb4953e4afcb837870eef876f022b8a931a52820a8d51106c67382cd77c1defc8725d43d8e03d5baf48c52d4b198c8fa68e1a724408567fc2d62a
+  languageName: node
+  linkType: hard
+
+"@ai-sdk/provider-utils@npm:2.2.8":
+  version: 2.2.8
+  resolution: "@ai-sdk/provider-utils@npm:2.2.8"
+  dependencies:
+    "@ai-sdk/provider": 1.1.3
+    nanoid: ^3.3.8
+    secure-json-parse: ^2.7.0
+  peerDependencies:
+    zod: ^3.23.8
+  checksum: 15487a4b4f1cc4eb72d7fc7afb71506f7bf439b538ef98b0c189a2b6d0dd72f10614c716c2206390b2624d6aeeb0799a0dad86010f6a505bbd9bd1b1d76adc60
+  languageName: node
+  linkType: hard
+
+"@ai-sdk/provider@npm:1.1.3, @ai-sdk/provider@npm:^1.1.3":
+  version: 1.1.3
+  resolution: "@ai-sdk/provider@npm:1.1.3"
+  dependencies:
+    json-schema: ^0.4.0
+  checksum: 197b5907aaca7d96b0d114c3456d46fa1134e6d98bb22617c2bd28b3592c1ab79d524ea894209cedc0e74695ee250b2a32de7d084122fd047565b64cbba009bb
+  languageName: node
+  linkType: hard
+
+"@ai-sdk/react@npm:*, @ai-sdk/react@npm:1.2.12":
+  version: 1.2.12
+  resolution: "@ai-sdk/react@npm:1.2.12"
+  dependencies:
+    "@ai-sdk/provider-utils": 2.2.8
+    "@ai-sdk/ui-utils": 1.2.11
+    swr: ^2.2.5
+    throttleit: 2.1.0
+  peerDependencies:
+    react: ^18 || ^19 || ^19.0.0-rc
+    zod: ^3.23.8
+  peerDependenciesMeta:
+    zod:
+      optional: true
+  checksum: 2bb15f4e9416c6cf17e66581435497e9ed46d8e19be657a8e3507c847017f9aa0fb9c64b989890d5b9614468df6ee94e271bd96ef65212fd193e2e356a84c54b
+  languageName: node
+  linkType: hard
+
+"@ai-sdk/ui-utils@npm:*, @ai-sdk/ui-utils@npm:1.2.11":
+  version: 1.2.11
+  resolution: "@ai-sdk/ui-utils@npm:1.2.11"
+  dependencies:
+    "@ai-sdk/provider": 1.1.3
+    "@ai-sdk/provider-utils": 2.2.8
+    zod-to-json-schema: ^3.24.1
+  peerDependencies:
+    zod: ^3.23.8
+  checksum: 8ea01d026923aae73a06810f33ce24020fc7f001331ac0b801d2a8be576d42353abdd3344278dcfdb4eb43914c38b4fb7d3305354a6cd2ba0cb5359f1fd01a49
+  languageName: node
+  linkType: hard
+
 "@ampproject/remapping@npm:^2.2.0":
   version: 2.3.0
   resolution: "@ampproject/remapping@npm:2.3.0"
@@ -143,6 +208,113 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@assistant-ui/react-ai-sdk@npm:^0.10.14":
+  version: 0.10.14
+  resolution: "@assistant-ui/react-ai-sdk@npm:0.10.14"
+  dependencies:
+    "@ai-sdk/react": "*"
+    "@ai-sdk/ui-utils": "*"
+    "@assistant-ui/react-edge": 0.2.12
+    "@radix-ui/react-use-callback-ref": ^1.1.1
+    "@types/json-schema": ^7.0.15
+    zod: ^3.25.64
+    zustand: ^5.0.5
+  peerDependencies:
+    "@assistant-ui/react": ^0.10.24
+    "@types/react": "*"
+    react: ^18 || ^19 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 1deb3310ca1cf3b901e4afe06e1fd7256759f2b55e8e658ec56a2075636bdd61a670cf373b3a1f2b9877674fc62df9c18c79852c0a3a05f97063cc57b15b9cf7
+  languageName: node
+  linkType: hard
+
+"@assistant-ui/react-edge@npm:0.2.12":
+  version: 0.2.12
+  resolution: "@assistant-ui/react-edge@npm:0.2.12"
+  dependencies:
+    "@ai-sdk/provider": ^1.1.3
+    assistant-stream: ^0.2.17
+    json-schema: ^0.4.0
+    zod: ^3.25.64
+    zod-to-json-schema: ^3.24.5
+  peerDependencies:
+    "@assistant-ui/react": "*"
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^18 || ^19 || ^19.0.0-rc
+    react-dom: ^18 || ^19 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: 6d533f26e533b7d177689ce3aa8d6b6fe0077d1f77d9f5b3707bae09bf084b7ba629a242e92fdf7f99328edc7521f3d0845587e961f19bce55c820ece7bba828
+  languageName: node
+  linkType: hard
+
+"@assistant-ui/react-markdown@npm:^0.10.5":
+  version: 0.10.5
+  resolution: "@assistant-ui/react-markdown@npm:0.10.5"
+  dependencies:
+    "@radix-ui/react-primitive": ^2.1.3
+    "@radix-ui/react-use-callback-ref": ^1.1.1
+    "@types/hast": ^3.0.4
+    classnames: ^2.5.1
+    react-markdown: ^10.1.0
+  peerDependencies:
+    "@assistant-ui/react": ^0.10.24
+    "@types/react": "*"
+    react: ^18 || ^19 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 85991a87a04f34c68b0290dfa6061e760b90bdcef694f7b938138b34836eaafe7dd0159faa54e262c227007dd8b912e5cab53329a99c26561a91a0a17d14a2ac
+  languageName: node
+  linkType: hard
+
+"@assistant-ui/react@npm:^0.10.24":
+  version: 0.10.24
+  resolution: "@assistant-ui/react@npm:0.10.24"
+  dependencies:
+    "@radix-ui/primitive": ^1.1.2
+    "@radix-ui/react-compose-refs": ^1.1.2
+    "@radix-ui/react-context": ^1.1.2
+    "@radix-ui/react-popover": ^1.1.14
+    "@radix-ui/react-primitive": ^2.1.3
+    "@radix-ui/react-slot": ^1.2.3
+    "@radix-ui/react-use-callback-ref": ^1.1.1
+    "@radix-ui/react-use-escape-keydown": ^1.1.1
+    "@standard-schema/spec": ^1.0.0
+    assistant-cloud: 0.0.2
+    assistant-stream: ^0.2.17
+    json-schema: ^0.4.0
+    nanoid: 5.1.5
+    react-textarea-autosize: ^8.5.9
+    zod: ^3.25.64
+    zustand: ^5.0.5
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^18 || ^19 || ^19.0.0-rc
+    react-dom: ^18 || ^19 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: 4f9483464ac24caf7271161683dc8a8ab17c2263b16ebb5f1a4da75ea1ecda93048f93c7b06c90202e76215d72beb190408d3833ab54e4d19bdbd0ee2523a5f3
+  languageName: node
+  linkType: hard
+
+"@assistant-ui/styles@npm:^0.1.13":
+  version: 0.1.13
+  resolution: "@assistant-ui/styles@npm:0.1.13"
+  checksum: edbe7f3aa144eb823830f662cc1f44cfe3a53fff05f1ec918a7e0a692cad86a276069c7834531102ff37125070cc42dfa84380c8daeee3cdbceae0d42c517f64
+  languageName: node
+  linkType: hard
+
 "@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.10.4, @babel/code-frame@npm:^7.12.13, @babel/code-frame@npm:^7.22.5, @babel/code-frame@npm:^7.27.1":
   version: 7.27.1
   resolution: "@babel/code-frame@npm:7.27.1"
@@ -2181,6 +2353,15 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@floating-ui/core@npm:^1.7.2":
+  version: 1.7.2
+  resolution: "@floating-ui/core@npm:1.7.2"
+  dependencies:
+    "@floating-ui/utils": ^0.2.10
+  checksum: aea540ea0101daf83e5beb2769af81f0532dcb8514dbee9d4c0a06576377d56dbfd4e5c3b031359594a26649734d1145bbd5524e8a573a745a5fcadc6b307906
+  languageName: node
+  linkType: hard
+
 "@floating-ui/dom@npm:^1.4.2":
   version: 1.7.0
   resolution: "@floating-ui/dom@npm:1.7.0"
@@ -2191,6 +2372,35 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@floating-ui/dom@npm:^1.7.2":
+  version: 1.7.2
+  resolution: "@floating-ui/dom@npm:1.7.2"
+  dependencies:
+    "@floating-ui/core": ^1.7.2
+    "@floating-ui/utils": ^0.2.10
+  checksum: 232d6668693cfecec038f3fb1f5398eace340427a9108701b895136c18d303d8bdd6237dce224626abf56a5a4592db776fbd0d187aa0f72c729bfca14a474b65
+  languageName: node
+  linkType: hard
+
+"@floating-ui/react-dom@npm:^2.0.0":
+  version: 2.1.4
+  resolution: "@floating-ui/react-dom@npm:2.1.4"
+  dependencies:
+    "@floating-ui/dom": ^1.7.2
+  peerDependencies:
+    react: ">=16.8.0"
+    react-dom: ">=16.8.0"
+  checksum: be2cc094b0c5cd7f6a06c6c58944e4f070e231bdc8d9f84fc8246eedf91e1545a8a9e6d8560664054de126aae6520da57a30b7d81433cb2625641a08eea8f029
+  languageName: node
+  linkType: hard
+
+"@floating-ui/utils@npm:^0.2.10":
+  version: 0.2.10
+  resolution: "@floating-ui/utils@npm:0.2.10"
+  checksum: ffc4c24a46a665cfd0337e9aaf7de8415b572f8a0f323af39175e4b575582aed13d172e7f049eedeece9eaf022bad019c140a2d192580451984ae529bdf1285c
+  languageName: node
+  linkType: hard
+
 "@floating-ui/utils@npm:^0.2.9":
   version: 0.2.9
   resolution: "@floating-ui/utils@npm:0.2.9"
@@ -3137,6 +3347,13 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@opentelemetry/api@npm:1.9.0":
+  version: 1.9.0
+  resolution: "@opentelemetry/api@npm:1.9.0"
+  checksum: 9e88e59d53ced668f3daaecfd721071c5b85a67dd386f1c6f051d1be54375d850016c881f656ffbe9a03bedae85f7e89c2f2b635313f9c9b195ad033cdc31020
+  languageName: node
+  linkType: hard
+
 "@pkgjs/parseargs@npm:^0.11.0":
   version: 0.11.0
   resolution: "@pkgjs/parseargs@npm:0.11.0"
@@ -3158,6 +3375,423 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@radix-ui/primitive@npm:1.1.2, @radix-ui/primitive@npm:^1.1.2":
+  version: 1.1.2
+  resolution: "@radix-ui/primitive@npm:1.1.2"
+  checksum: 6cb2ac097faf77b7288bdfd87d92e983e357252d00ee0d2b51ad8e7897bf9f51ec53eafd7dd64c613671a2b02cb8166177bc3de444a6560ec60835c363321c18
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-arrow@npm:1.1.7":
+  version: 1.1.7
+  resolution: "@radix-ui/react-arrow@npm:1.1.7"
+  dependencies:
+    "@radix-ui/react-primitive": 2.1.3
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+    react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: 6cdf74f06090f8994cdf6d3935a44ea3ac309163a4f59c476482c4907e8e0775f224045030abf10fa4f9e1cb7743db034429249b9e59354988e247eeb0f4fdcf
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-compose-refs@npm:1.1.2, @radix-ui/react-compose-refs@npm:^1.1.2":
+  version: 1.1.2
+  resolution: "@radix-ui/react-compose-refs@npm:1.1.2"
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 9a91f0213014ffa40c5b8aae4debb993be5654217e504e35aa7422887eb2d114486d37e53c482d0fffb00cd44f51b5269fcdf397b280c71666fa11b7f32f165d
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-context@npm:1.1.2, @radix-ui/react-context@npm:^1.1.2":
+  version: 1.1.2
+  resolution: "@radix-ui/react-context@npm:1.1.2"
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 6d08437f23df362672259e535ae463e70bf7a0069f09bfa06c983a5a90e15250bde19da1d63ef8e3da06df1e1b4f92afa9d28ca6aa0297bb1c8aaf6ca83d28c5
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-dismissable-layer@npm:1.1.10":
+  version: 1.1.10
+  resolution: "@radix-ui/react-dismissable-layer@npm:1.1.10"
+  dependencies:
+    "@radix-ui/primitive": 1.1.2
+    "@radix-ui/react-compose-refs": 1.1.2
+    "@radix-ui/react-primitive": 2.1.3
+    "@radix-ui/react-use-callback-ref": 1.1.1
+    "@radix-ui/react-use-escape-keydown": 1.1.1
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+    react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: c4f31e8e93ae979a1bcd60726f8ebe7b79f23baafcd1d1e65f62cff6b322b2c6ff6132d82f2e63737f9955a8f04407849036f5b64b478e9a5678747d835957d8
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-focus-guards@npm:1.1.2":
+  version: 1.1.2
+  resolution: "@radix-ui/react-focus-guards@npm:1.1.2"
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 618658e2b98575198b94ccfdd27f41beb37f83721c9a04617e848afbc47461124ae008d703d713b9644771d96d4852e49de322cf4be3b5f10a4f94d200db5248
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-focus-scope@npm:1.1.7":
+  version: 1.1.7
+  resolution: "@radix-ui/react-focus-scope@npm:1.1.7"
+  dependencies:
+    "@radix-ui/react-compose-refs": 1.1.2
+    "@radix-ui/react-primitive": 2.1.3
+    "@radix-ui/react-use-callback-ref": 1.1.1
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+    react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: bb642d192d3da8431f8b39f64959b493a7ba743af8501b76699ef93357c96507c11fb76d468824b52b0e024eaee130a641f3a213268ac7c9af34883b45610c9b
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-id@npm:1.1.1":
+  version: 1.1.1
+  resolution: "@radix-ui/react-id@npm:1.1.1"
+  dependencies:
+    "@radix-ui/react-use-layout-effect": 1.1.1
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 8d68e200778eb3038906870fc869b3d881f4a46715fb20cddd9c76cba42fdaaa4810a3365b6ec2daf0f185b9201fc99d009167f59c7921bc3a139722c2e976db
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-popover@npm:^1.1.14":
+  version: 1.1.14
+  resolution: "@radix-ui/react-popover@npm:1.1.14"
+  dependencies:
+    "@radix-ui/primitive": 1.1.2
+    "@radix-ui/react-compose-refs": 1.1.2
+    "@radix-ui/react-context": 1.1.2
+    "@radix-ui/react-dismissable-layer": 1.1.10
+    "@radix-ui/react-focus-guards": 1.1.2
+    "@radix-ui/react-focus-scope": 1.1.7
+    "@radix-ui/react-id": 1.1.1
+    "@radix-ui/react-popper": 1.2.7
+    "@radix-ui/react-portal": 1.1.9
+    "@radix-ui/react-presence": 1.1.4
+    "@radix-ui/react-primitive": 2.1.3
+    "@radix-ui/react-slot": 1.2.3
+    "@radix-ui/react-use-controllable-state": 1.2.2
+    aria-hidden: ^1.2.4
+    react-remove-scroll: ^2.6.3
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+    react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: 50f146117ebf675944181ef2df4fbc2d7ca017c71a2ab78eaa67159eb8a0101c682fa02bafa2b132ea7744592b7f103d02935ace2c1f430ab9040a0ece9246c8
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-popper@npm:1.2.7":
+  version: 1.2.7
+  resolution: "@radix-ui/react-popper@npm:1.2.7"
+  dependencies:
+    "@floating-ui/react-dom": ^2.0.0
+    "@radix-ui/react-arrow": 1.1.7
+    "@radix-ui/react-compose-refs": 1.1.2
+    "@radix-ui/react-context": 1.1.2
+    "@radix-ui/react-primitive": 2.1.3
+    "@radix-ui/react-use-callback-ref": 1.1.1
+    "@radix-ui/react-use-layout-effect": 1.1.1
+    "@radix-ui/react-use-rect": 1.1.1
+    "@radix-ui/react-use-size": 1.1.1
+    "@radix-ui/rect": 1.1.1
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+    react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: 1d672b8b635846501212eb0cd15273c8acdd31e76e78d2b9ba29ce29730d5a2d3a61a8ed49bb689c94f67f45d1dffe0d49449e0810f08c4e112d8aef8430e76d
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-portal@npm:1.1.9":
+  version: 1.1.9
+  resolution: "@radix-ui/react-portal@npm:1.1.9"
+  dependencies:
+    "@radix-ui/react-primitive": 2.1.3
+    "@radix-ui/react-use-layout-effect": 1.1.1
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+    react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: bd6be39bf021d5c917e2474ecba411e2625171f7ef96862b9af04bbd68833bb3662a7f1fbdeb5a7a237111b10e811e76d2cd03e957dadd6e668ef16541bfbd68
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-presence@npm:1.1.4":
+  version: 1.1.4
+  resolution: "@radix-ui/react-presence@npm:1.1.4"
+  dependencies:
+    "@radix-ui/react-compose-refs": 1.1.2
+    "@radix-ui/react-use-layout-effect": 1.1.1
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+    react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: d3b0976368fccdfa07100c1f07ca434d0092d4132d1ed4a5c213802f7318d77fc1fd61d1b7038b87e82912688fafa97d8af000a6cca4027b09d92c5477f79dd0
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-primitive@npm:2.1.3, @radix-ui/react-primitive@npm:^2.1.3":
+  version: 2.1.3
+  resolution: "@radix-ui/react-primitive@npm:2.1.3"
+  dependencies:
+    "@radix-ui/react-slot": 1.2.3
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+    react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: 01f82e4bad76b57767198762c905e5bcea04f4f52129749791e31adfcb1b36f6fdc89c73c40017d812b6e25e4ac925d837214bb280cfeaa5dc383457ce6940b0
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-slot@npm:1.2.3, @radix-ui/react-slot@npm:^1.2.3":
+  version: 1.2.3
+  resolution: "@radix-ui/react-slot@npm:1.2.3"
+  dependencies:
+    "@radix-ui/react-compose-refs": 1.1.2
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 2731089e15477dd5eef98a5757c36113dd932d0c52ff05123cd89f05f0412e95e5b205229185d1cd705cda4a674a838479cce2b3b46ed903f82f5d23d9e3f3c2
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-tooltip@npm:^1.2.7":
+  version: 1.2.7
+  resolution: "@radix-ui/react-tooltip@npm:1.2.7"
+  dependencies:
+    "@radix-ui/primitive": 1.1.2
+    "@radix-ui/react-compose-refs": 1.1.2
+    "@radix-ui/react-context": 1.1.2
+    "@radix-ui/react-dismissable-layer": 1.1.10
+    "@radix-ui/react-id": 1.1.1
+    "@radix-ui/react-popper": 1.2.7
+    "@radix-ui/react-portal": 1.1.9
+    "@radix-ui/react-presence": 1.1.4
+    "@radix-ui/react-primitive": 2.1.3
+    "@radix-ui/react-slot": 1.2.3
+    "@radix-ui/react-use-controllable-state": 1.2.2
+    "@radix-ui/react-visually-hidden": 1.2.3
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+    react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: aebb5c124c73dc236e9362899cb81bb0b1d4103d29205122f55dd64a9b9bdf4be7cc335964e1885098be3c570416a35899a317e0e6f373b6f9d39334699e4694
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-use-callback-ref@npm:1.1.1, @radix-ui/react-use-callback-ref@npm:^1.1.1":
+  version: 1.1.1
+  resolution: "@radix-ui/react-use-callback-ref@npm:1.1.1"
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: cde8c40f1d4e79e6e71470218163a746858304bad03758ac84dc1f94247a046478e8e397518350c8d6609c84b7e78565441d7505bb3ed573afce82cfdcd19faf
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-use-controllable-state@npm:1.2.2":
+  version: 1.2.2
+  resolution: "@radix-ui/react-use-controllable-state@npm:1.2.2"
+  dependencies:
+    "@radix-ui/react-use-effect-event": 0.0.2
+    "@radix-ui/react-use-layout-effect": 1.1.1
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: b438ee199d0630bf95eaafe8bf4bce219e73b371cfc8465f47548bfa4ee231f1134b5c6696b242890a01a0fd25fa34a7b172346bbfc5ee25cfb28b3881b1dc92
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-use-effect-event@npm:0.0.2":
+  version: 0.0.2
+  resolution: "@radix-ui/react-use-effect-event@npm:0.0.2"
+  dependencies:
+    "@radix-ui/react-use-layout-effect": 1.1.1
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 5a1950a30a399ea7e4b98154da9f536737a610de80189b7aacd4f064a89a3cd0d2a48571d527435227252e72e872bdb544ff6ffcfbdd02de2efd011be4aaa902
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-use-escape-keydown@npm:1.1.1, @radix-ui/react-use-escape-keydown@npm:^1.1.1":
+  version: 1.1.1
+  resolution: "@radix-ui/react-use-escape-keydown@npm:1.1.1"
+  dependencies:
+    "@radix-ui/react-use-callback-ref": 1.1.1
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 0eb0756c2c55ddcde9ff01446ab01c085ab2bf799173e97db7ef5f85126f9e8600225570801a1f64740e6d14c39ffe8eed7c14d29737345a5797f4622ac96f6f
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-use-layout-effect@npm:1.1.1":
+  version: 1.1.1
+  resolution: "@radix-ui/react-use-layout-effect@npm:1.1.1"
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: bad2ba4f206e6255263582bedfb7868773c400836f9a1b423c0b464ffe4a17e13d3f306d1ce19cf7a19a492e9d0e49747464f2656451bb7c6a99f5a57bd34de2
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-use-rect@npm:1.1.1":
+  version: 1.1.1
+  resolution: "@radix-ui/react-use-rect@npm:1.1.1"
+  dependencies:
+    "@radix-ui/rect": 1.1.1
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 116461bebc49472f7497e66a9bd413541181b3d00c5e0aaeef45d790dc1fbd7c8dcea80b169ea273306228b9a3c2b70067e902d1fd5004b3057e3bbe35b9d55d
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-use-size@npm:1.1.1":
+  version: 1.1.1
+  resolution: "@radix-ui/react-use-size@npm:1.1.1"
+  dependencies:
+    "@radix-ui/react-use-layout-effect": 1.1.1
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 64e61f65feb67ffc80e1fc4a8d5e32480fb6d68475e2640377e021178dead101568cba5f936c9c33e6c142c7cf2fb5d76ad7b23ef80e556ba142d56cf306147b
+  languageName: node
+  linkType: hard
+
+"@radix-ui/react-visually-hidden@npm:1.2.3":
+  version: 1.2.3
+  resolution: "@radix-ui/react-visually-hidden@npm:1.2.3"
+  dependencies:
+    "@radix-ui/react-primitive": 2.1.3
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+    react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: 42296bde1ddf4af4e7445e914c35d6bc8406d6ede49f0a959a553e75b3ed21da09fda80a81c48d8ec058ed8129ce7137499d02ee26f90f0d3eaa2417922d6509
+  languageName: node
+  linkType: hard
+
+"@radix-ui/rect@npm:1.1.1":
+  version: 1.1.1
+  resolution: "@radix-ui/rect@npm:1.1.1"
+  checksum: c1c111edeab70b14a735bca43601de6468c792482864b766ac8940b43321492e5c0ae62f92b156cecdc9265ec3c680c32b3fa0c8a90b5e796923a9af13c5dc20
+  languageName: node
+  linkType: hard
+
 "@rc-component/async-validator@npm:^5.0.3":
   version: 5.0.4
   resolution: "@rc-component/async-validator@npm:5.0.4"
@@ -3927,6 +4561,13 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@standard-schema/spec@npm:^1.0.0":
+  version: 1.0.0
+  resolution: "@standard-schema/spec@npm:1.0.0"
+  checksum: 2d7d73a1c9706622750ab06fc40ef7c1d320b52d5e795f8a1c7a77d0d6a9f978705092bc4149327b3cff4c9a14e5b3800d3b00dc945489175a2d3031ded8332a
+  languageName: node
+  linkType: hard
+
 "@supabase/auth-js@npm:2.69.1":
   version: 2.69.1
   resolution: "@supabase/auth-js@npm:2.69.1"
@@ -4516,6 +5157,13 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@types/diff-match-patch@npm:^1.0.36":
+  version: 1.0.36
+  resolution: "@types/diff-match-patch@npm:1.0.36"
+  checksum: 7d7ce03422fcc3e79d0cda26e4748aeb176b75ca4b4e5f38459b112bf24660d628424bdb08d330faefa69039d19a5316e7a102a8ab68b8e294c8346790e55113
+  languageName: node
+  linkType: hard
+
 "@types/eslint-scope@npm:^3.7.7":
   version: 3.7.7
   resolution: "@types/eslint-scope@npm:3.7.7"
@@ -4648,7 +5296,7 @@ __metadata:
   languageName: node
   linkType: hard
 
-"@types/hast@npm:^3.0.0":
+"@types/hast@npm:^3.0.0, @types/hast@npm:^3.0.4":
   version: 3.0.4
   resolution: "@types/hast@npm:3.0.4"
   dependencies:
@@ -5844,6 +6492,26 @@ __metadata:
   languageName: node
   linkType: hard
 
+"ai@npm:^4.3.16":
+  version: 4.3.16
+  resolution: "ai@npm:4.3.16"
+  dependencies:
+    "@ai-sdk/provider": 1.1.3
+    "@ai-sdk/provider-utils": 2.2.8
+    "@ai-sdk/react": 1.2.12
+    "@ai-sdk/ui-utils": 1.2.11
+    "@opentelemetry/api": 1.9.0
+    jsondiffpatch: 0.6.0
+  peerDependencies:
+    react: ^18 || ^19 || ^19.0.0-rc
+    zod: ^3.23.8
+  peerDependenciesMeta:
+    react:
+      optional: true
+  checksum: 1c13e641f04440d5ea550435defda01508473f4c5e65b248df4d39911c5accb77dd17009563c16163097642a33fe9eb421c6bedbcf824835ace9dfd96c785061
+  languageName: node
+  linkType: hard
+
 "ajv-formats@npm:^2.1.0, ajv-formats@npm:^2.1.1":
   version: 2.1.1
   resolution: "ajv-formats@npm:2.1.1"
@@ -6130,6 +6798,15 @@ __metadata:
   languageName: node
   linkType: hard
 
+"aria-hidden@npm:^1.2.4":
+  version: 1.2.6
+  resolution: "aria-hidden@npm:1.2.6"
+  dependencies:
+    tslib: ^2.0.0
+  checksum: 56409c55c43ad917607f3f3aa67748dcf30a27e8bb5cb3c5d86b43e38babadd63cd77731a27bc8a8c4332c2291741ed92333bf7ca45f8b99ebc87b94a8070a6e
+  languageName: node
+  linkType: hard
+
 "aria-query@npm:5.1.3":
   version: 5.1.3
   resolution: "aria-query@npm:5.1.3"
@@ -6319,6 +6996,26 @@ __metadata:
   languageName: node
   linkType: hard
 
+"assistant-cloud@npm:0.0.2":
+  version: 0.0.2
+  resolution: "assistant-cloud@npm:0.0.2"
+  dependencies:
+    assistant-stream: ^0.2.17
+  checksum: 5a4df3ca6c40dad15eb38c3f974bffd321bf52859f41bc3459d75f912e37579211a07876a5d28ce462396407f87a863dc849034f9bc24e04c010ab31827c6f82
+  languageName: node
+  linkType: hard
+
+"assistant-stream@npm:^0.2.17":
+  version: 0.2.17
+  resolution: "assistant-stream@npm:0.2.17"
+  dependencies:
+    "@types/json-schema": ^7.0.15
+    nanoid: 5.1.5
+    secure-json-parse: ^4.0.0
+  checksum: 1b317f2e5c19ce013cb8673ff73461b5ba39fe80ff05c3d4b6e67704d89a70ab76337dac6974901962caedcffc45429e990856c3e551122de6a3b37649a2d8cb
+  languageName: node
+  linkType: hard
+
 "ast-types-flow@npm:^0.0.8":
   version: 0.0.8
   resolution: "ast-types-flow@npm:0.0.8"
@@ -7166,6 +7863,13 @@ __metadata:
   languageName: node
   linkType: hard
 
+"chalk@npm:^5.3.0":
+  version: 5.4.1
+  resolution: "chalk@npm:5.4.1"
+  checksum: 0c656f30b782fed4d99198825c0860158901f449a6b12b818b0aabad27ec970389e7e8767d0e00762175b23620c812e70c4fd92c0210e55fc2d993638b74e86e
+  languageName: node
+  linkType: hard
+
 "char-regex@npm:^1.0.2":
   version: 1.0.2
   resolution: "char-regex@npm:1.0.2"
@@ -8811,7 +9515,7 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
-"dequal@npm:^2.0.0":
+"dequal@npm:^2.0.0, dequal@npm:^2.0.3":
   version: 2.0.3
   resolution: "dequal@npm:2.0.3"
   checksum: 8679b850e1a3d0ebbc46ee780d5df7b478c23f335887464023a631d1b9af051ad4a6595a44220f9ff8ff95a8ddccf019b5ad778a976fd7bbf77383d36f412f90
@@ -8842,6 +9546,13 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"detect-node-es@npm:^1.1.0":
+  version: 1.1.0
+  resolution: "detect-node-es@npm:1.1.0"
+  checksum: e46307d7264644975b71c104b9f028ed1d3d34b83a15b8a22373640ce5ea630e5640b1078b8ea15f202b54641da71e4aa7597093bd4b91f113db520a26a37449
+  languageName: node
+  linkType: hard
+
 "detect-node@npm:^2.0.4":
   version: 2.1.0
   resolution: "detect-node@npm:2.1.0"
@@ -8858,6 +9569,13 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"diff-match-patch@npm:^1.0.5":
+  version: 1.0.5
+  resolution: "diff-match-patch@npm:1.0.5"
+  checksum: 841522d01b09cccbc4e4402cf61514a81b906349a7d97b67222390f2d35cf5df277cb23959eeed212d5e46afb5629cebab41b87918672c5a05c11c73688630e3
+  languageName: node
+  linkType: hard
+
 "diff-sequences@npm:^29.6.3":
   version: 29.6.3
   resolution: "diff-sequences@npm:29.6.3"
@@ -10763,6 +11481,13 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"get-nonce@npm:^1.0.0":
+  version: 1.0.1
+  resolution: "get-nonce@npm:1.0.1"
+  checksum: e2614e43b4694c78277bb61b0f04583d45786881289285c73770b07ded246a98be7e1f78b940c80cbe6f2b07f55f0b724e6db6fd6f1bcbd1e8bdac16521074ed
+  languageName: node
+  linkType: hard
+
 "get-package-type@npm:^0.1.0":
   version: 0.1.0
   resolution: "get-package-type@npm:0.1.0"
@@ -13227,7 +13952,7 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
-"json-schema@npm:0.4.0":
+"json-schema@npm:0.4.0, json-schema@npm:^0.4.0":
   version: 0.4.0
   resolution: "json-schema@npm:0.4.0"
   checksum: 66389434c3469e698da0df2e7ac5a3281bcff75e797a5c127db7c5b56270e01ae13d9afa3c03344f76e32e81678337a8c912bdbb75101c62e487dc3778461d72
@@ -13277,6 +14002,19 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"jsondiffpatch@npm:0.6.0":
+  version: 0.6.0
+  resolution: "jsondiffpatch@npm:0.6.0"
+  dependencies:
+    "@types/diff-match-patch": ^1.0.36
+    chalk: ^5.3.0
+    diff-match-patch: ^1.0.5
+  bin:
+    jsondiffpatch: bin/jsondiffpatch.js
+  checksum: 27d7aa42c3b9f9359fd179bb49c621ed848f6095615014cd0acbd29c37e364c11cb5a19c3ef2c873631e7b5f7ba6d1465978a489efa28cb1dc9fba98b0498712
+  languageName: node
+  linkType: hard
+
 "jsonfile@npm:^6.0.1":
   version: 6.1.0
   resolution: "jsonfile@npm:6.1.0"
@@ -14103,7 +14841,12 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   version: 0.0.0-use.local
   resolution: "lowcoder@workspace:packages/lowcoder"
   dependencies:
+    "@ai-sdk/openai": ^1.3.22
     "@ant-design/icons": ^5.3.0
+    "@assistant-ui/react": ^0.10.24
+    "@assistant-ui/react-ai-sdk": ^0.10.14
+    "@assistant-ui/react-markdown": ^0.10.5
+    "@assistant-ui/styles": ^0.1.13
     "@bany/curl-to-json": ^1.2.8
     "@codemirror/autocomplete": ^6.11.1
     "@codemirror/commands": ^6.3.2
@@ -14125,6 +14868,8 @@ coolshapes-react@lowcoder-org/coolshapes-react:
     "@jsonforms/core": ^3.5.1
     "@lottiefiles/dotlottie-react": ^0.13.0
     "@manaflair/redux-batch": ^1.0.0
+    "@radix-ui/react-slot": ^1.2.3
+    "@radix-ui/react-tooltip": ^1.2.7
     "@rjsf/antd": ^5.24.9
     "@rjsf/core": ^5.24.9
     "@rjsf/utils": ^5.24.9
@@ -14143,6 +14888,7 @@ coolshapes-react@lowcoder-org/coolshapes-react:
     "@types/supercluster": ^7.1.3
     "@types/uuid": ^8.3.4
     "@vitejs/plugin-react": ^2.2.0
+    ai: ^4.3.16
     alasql: ^4.6.6
     animate.css: ^4.1.1
     antd: ^5.25.2
@@ -14172,6 +14918,7 @@ coolshapes-react@lowcoder-org/coolshapes-react:
     loglevel: ^1.8.0
     lowcoder-core: "workspace:^"
     lowcoder-design: "workspace:^"
+    lucide-react: ^0.525.0
     mime: ^3.0.0
     moment: ^2.29.4
     numbro: ^2.3.6
@@ -14209,7 +14956,7 @@ coolshapes-react@lowcoder-org/coolshapes-react:
     regenerator-runtime: ^0.13.9
     rehype-raw: ^6.1.1
     rehype-sanitize: ^5.0.1
-    remark-gfm: ^4.0.0
+    remark-gfm: ^4.0.1
     resize-observer-polyfill: ^1.5.1
     rollup-plugin-terser: ^7.0.2
     rollup-plugin-visualizer: ^5.9.2
@@ -14274,6 +15021,15 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"lucide-react@npm:^0.525.0":
+  version: 0.525.0
+  resolution: "lucide-react@npm:0.525.0"
+  peerDependencies:
+    react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0
+  checksum: eef781bfcfd211dac1ca93d0e7c5830aec1bacef72f4af3994807ac04d2a0fe327aca1a77234daf7f13e06ea47e5585766c927c8e1f2e7dcb982e4dc55aeda5e
+  languageName: node
+  linkType: hard
+
 "lz-string@npm:^1.5.0":
   version: 1.5.0
   resolution: "lz-string@npm:1.5.0"
@@ -15685,6 +16441,15 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"nanoid@npm:5.1.5":
+  version: 5.1.5
+  resolution: "nanoid@npm:5.1.5"
+  bin:
+    nanoid: bin/nanoid.js
+  checksum: 6de2d006b51c983be385ef7ee285f7f2a57bd96f8c0ca881c4111461644bd81fafc2544f8e07cb834ca0f3e0f3f676c1fe78052183f008b0809efe6e273119f5
+  languageName: node
+  linkType: hard
+
 "nanoid@npm:^3.3.7, nanoid@npm:^3.3.8":
   version: 3.3.11
   resolution: "nanoid@npm:3.3.11"
@@ -17933,6 +18698,28 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"react-markdown@npm:^10.1.0":
+  version: 10.1.0
+  resolution: "react-markdown@npm:10.1.0"
+  dependencies:
+    "@types/hast": ^3.0.0
+    "@types/mdast": ^4.0.0
+    devlop: ^1.0.0
+    hast-util-to-jsx-runtime: ^2.0.0
+    html-url-attributes: ^3.0.0
+    mdast-util-to-hast: ^13.0.0
+    remark-parse: ^11.0.0
+    remark-rehype: ^11.0.0
+    unified: ^11.0.0
+    unist-util-visit: ^5.0.0
+    vfile: ^6.0.0
+  peerDependencies:
+    "@types/react": ">=18"
+    react: ">=18"
+  checksum: fa7ef860e32a18206c5b301de8672be609b108f46f0f091e9779d50ff8145bd63d0f6e82ffb18fc1b7aee2264cbdac1100205596ff10d2c3d2de6627abb3868f
+  languageName: node
+  linkType: hard
+
 "react-markdown@npm:^9.0.1":
   version: 9.1.0
   resolution: "react-markdown@npm:9.1.0"
@@ -18026,6 +18813,41 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"react-remove-scroll-bar@npm:^2.3.7":
+  version: 2.3.8
+  resolution: "react-remove-scroll-bar@npm:2.3.8"
+  dependencies:
+    react-style-singleton: ^2.2.2
+    tslib: ^2.0.0
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: c4663247f689dbe51c370836edf735487f6d8796acb7f15b09e8a1c14e84c7997360e8e3d54de2bc9c0e782fed2b2c4127d15b4053e4d2cf26839e809e57605f
+  languageName: node
+  linkType: hard
+
+"react-remove-scroll@npm:^2.6.3":
+  version: 2.7.1
+  resolution: "react-remove-scroll@npm:2.7.1"
+  dependencies:
+    react-remove-scroll-bar: ^2.3.7
+    react-style-singleton: ^2.2.3
+    tslib: ^2.1.0
+    use-callback-ref: ^1.3.3
+    use-sidecar: ^1.1.3
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: c8b1988d473ca0b4911a0a42f09dc7806d5db998c3ec938ae2791a5f82d807c2cdebb78a1c58a0bab62a83112528dda2f20d509d0e048fe281b9dfc027c39763
+  languageName: node
+  linkType: hard
+
 "react-resizable@npm:^3.0.4, react-resizable@npm:^3.0.5":
   version: 3.0.5
   resolution: "react-resizable@npm:3.0.5"
@@ -18132,6 +18954,22 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"react-style-singleton@npm:^2.2.2, react-style-singleton@npm:^2.2.3":
+  version: 2.2.3
+  resolution: "react-style-singleton@npm:2.2.3"
+  dependencies:
+    get-nonce: ^1.0.0
+    tslib: ^2.0.0
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: a7b0bf493c9231065ebafa84c4237aed997c746c561196121b7de82fe155a5355b372db5070a3ac9fe980cf7f60dc0f1e8cf6402a2aa5b2957392932ccf76e76
+  languageName: node
+  linkType: hard
+
 "react-test-renderer@npm:^18.1.0":
   version: 18.3.1
   resolution: "react-test-renderer@npm:18.3.1"
@@ -18145,7 +18983,7 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
-"react-textarea-autosize@npm:^8.3.2":
+"react-textarea-autosize@npm:^8.3.2, react-textarea-autosize@npm:^8.5.9":
   version: 8.5.9
   resolution: "react-textarea-autosize@npm:8.5.9"
   dependencies:
@@ -18534,7 +19372,7 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
-"remark-gfm@npm:^4.0.0":
+"remark-gfm@npm:^4.0.0, remark-gfm@npm:^4.0.1":
   version: 4.0.1
   resolution: "remark-gfm@npm:4.0.1"
   dependencies:
@@ -19291,6 +20129,20 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"secure-json-parse@npm:^2.7.0":
+  version: 2.7.0
+  resolution: "secure-json-parse@npm:2.7.0"
+  checksum: d9d7d5a01fc6db6115744ba23cf9e67ecfe8c524d771537c062ee05ad5c11b64c730bc58c7f33f60bd6877f96b86f0ceb9ea29644e4040cb757f6912d4dd6737
+  languageName: node
+  linkType: hard
+
+"secure-json-parse@npm:^4.0.0":
+  version: 4.0.0
+  resolution: "secure-json-parse@npm:4.0.0"
+  checksum: 5092d1385f242ae1a189a193eeb2f5ed1f00350270edefe209fbd35898a93745da58e7d8d4833a6da2235a89df7140d2959817ca4f2b1a4bfd135a812fab4f01
+  languageName: node
+  linkType: hard
+
 "select-hose@npm:^2.0.0":
   version: 2.0.0
   resolution: "select-hose@npm:2.0.0"
@@ -20402,6 +21254,18 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"swr@npm:^2.2.5":
+  version: 2.3.3
+  resolution: "swr@npm:2.3.3"
+  dependencies:
+    dequal: ^2.0.3
+    use-sync-external-store: ^1.4.0
+  peerDependencies:
+    react: ^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
+  checksum: 25b2ab03d0149951e4612fae8458d333d6fbe912298684495969250553176b5b5b731be119f406ebadf6e9c5dc39726dd2492cca9684f448aa1734274e2a4919
+  languageName: node
+  linkType: hard
+
 "symbol-tree@npm:^3.2.2, symbol-tree@npm:^3.2.4":
   version: 3.2.4
   resolution: "symbol-tree@npm:3.2.4"
@@ -20558,6 +21422,13 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"throttleit@npm:2.1.0":
+  version: 2.1.0
+  resolution: "throttleit@npm:2.1.0"
+  checksum: a2003947aafc721c4a17e6f07db72dc88a64fa9bba0f9c659f7997d30f9590b3af22dadd6a41851e0e8497d539c33b2935c2c7919cf4255922509af6913c619b
+  languageName: node
+  linkType: hard
+
 "thunky@npm:^1.0.2":
   version: 1.1.0
   resolution: "thunky@npm:1.1.0"
@@ -21478,6 +22349,21 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"use-callback-ref@npm:^1.3.3":
+  version: 1.3.3
+  resolution: "use-callback-ref@npm:1.3.3"
+  dependencies:
+    tslib: ^2.0.0
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 4da1c82d7a2409cee6c882748a40f4a083decf238308bf12c3d0166f0e338f8d512f37b8d11987eb5a421f14b9b5b991edf3e11ed25c3bb7a6559081f8359b44
+  languageName: node
+  linkType: hard
+
 "use-composed-ref@npm:^1.3.0":
   version: 1.4.0
   resolution: "use-composed-ref@npm:1.4.0"
@@ -21516,7 +22402,23 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
-"use-sync-external-store@npm:^1.2.0":
+"use-sidecar@npm:^1.1.3":
+  version: 1.1.3
+  resolution: "use-sidecar@npm:1.1.3"
+  dependencies:
+    detect-node-es: ^1.1.0
+    tslib: ^2.0.0
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 88664c6b2c5b6e53e4d5d987694c9053cea806da43130248c74ca058945c8caa6ccb7b1787205a9eb5b9d124633e42153848904002828acabccdc48cda026622
+  languageName: node
+  linkType: hard
+
+"use-sync-external-store@npm:^1.2.0, use-sync-external-store@npm:^1.4.0":
   version: 1.5.0
   resolution: "use-sync-external-store@npm:1.5.0"
   peerDependencies:
@@ -22741,6 +23643,22 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"zod-to-json-schema@npm:^3.24.1, zod-to-json-schema@npm:^3.24.5":
+  version: 3.24.6
+  resolution: "zod-to-json-schema@npm:3.24.6"
+  peerDependencies:
+    zod: ^3.24.1
+  checksum: 5f4d29597cfd88d8fb8a539f0169affb8705d67ee9cbe478aa01bb1d2554e0540ca713fa4ddeb2fd834e87e7cdff61fa396f6d1925a9006de70afe6cd68bf7d2
+  languageName: node
+  linkType: hard
+
+"zod@npm:^3.25.64":
+  version: 3.25.67
+  resolution: "zod@npm:3.25.67"
+  checksum: 56ab904d33b1cd00041ce64ae05b0628fcbfeb7e707fa31cd498a97b540135e4dfe685200c9c62aea307695ee132870b4bc34f035228ea728aa75cc96a4954cb
+  languageName: node
+  linkType: hard
+
 "zrender@npm:5.6.1, zrender@npm:^5.1.1":
   version: 5.6.1
   resolution: "zrender@npm:5.6.1"
@@ -22750,6 +23668,27 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
+"zustand@npm:^5.0.5":
+  version: 5.0.6
+  resolution: "zustand@npm:5.0.6"
+  peerDependencies:
+    "@types/react": ">=18.0.0"
+    immer: ">=9.0.6"
+    react: ">=18.0.0"
+    use-sync-external-store: ">=1.2.0"
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    immer:
+      optional: true
+    react:
+      optional: true
+    use-sync-external-store:
+      optional: true
+  checksum: 1808cd7d49e8ba6777e0d8d524a858a918a4fd0bcbde88eb19ea3f4be9c8066276ecc236a8ed071623d3f13373424c56a5ddb0013be590b641ac99bf8f9b4e19
+  languageName: node
+  linkType: hard
+
 "zwitch@npm:^2.0.0":
   version: 2.0.4
   resolution: "zwitch@npm:2.0.4"

From 4e7e5409564aeaf4d437900e34cf10e711f90dcd Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Tue, 1 Jul 2025 12:57:27 +0500
Subject: [PATCH 04/54] add assistant-ui components

---
 client/packages/lowcoder/package.json         |   1 +
 .../components/assistant-ui/markdown-text.tsx | 130 ++++++++
 .../components/assistant-ui/thread-list.tsx   |  66 ++++
 .../components/assistant-ui/thread.tsx        | 283 ++++++++++++++++++
 .../assistant-ui/tooltip-icon-button.tsx      |  42 +++
 .../comps/chatComp/components/ui/button.tsx   |  45 +++
 .../comps/chatComp/components/ui/tooltip.tsx  |  29 ++
 .../src/comps/comps/chatComp/utils/cn.ts      |   5 +
 client/yarn.lock                              |  12 +-
 9 files changed, 612 insertions(+), 1 deletion(-)
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/markdown-text.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/tooltip-icon-button.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/ui/button.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/ui/tooltip.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/utils/cn.ts

diff --git a/client/packages/lowcoder/package.json b/client/packages/lowcoder/package.json
index 3460b19ca3..04a4c30535 100644
--- a/client/packages/lowcoder/package.json
+++ b/client/packages/lowcoder/package.json
@@ -50,6 +50,7 @@
     "antd": "^5.25.2",
     "axios": "^1.7.7",
     "buffer": "^6.0.3",
+    "class-variance-authority": "^0.7.1",
     "clsx": "^2.0.0",
     "cnchar": "^3.2.4",
     "coolshapes-react": "lowcoder-org/coolshapes-react",
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/markdown-text.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/markdown-text.tsx
new file mode 100644
index 0000000000..bbf2e5648a
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/markdown-text.tsx
@@ -0,0 +1,130 @@
+import "@assistant-ui/react-markdown/styles/dot.css";
+
+import {
+  CodeHeaderProps,
+  MarkdownTextPrimitive,
+  unstable_memoizeMarkdownComponents as memoizeMarkdownComponents,
+  useIsMarkdownCodeBlock,
+} from "@assistant-ui/react-markdown";
+import remarkGfm from "remark-gfm";
+import { FC, memo, useState } from "react";
+import { CheckIcon, CopyIcon } from "lucide-react";
+
+import { TooltipIconButton } from "./tooltip-icon-button";
+import { cn } from "../../utils/cn";
+
+const MarkdownTextImpl = () => {
+  return (
+    <MarkdownTextPrimitive
+      remarkPlugins={[remarkGfm]}
+      className="aui-md"
+      components={defaultComponents}
+    />
+  );
+};
+
+export const MarkdownText = memo(MarkdownTextImpl);
+
+const CodeHeader: FC<CodeHeaderProps> = ({ language, code }) => {
+  const { isCopied, copyToClipboard } = useCopyToClipboard();
+  const onCopy = () => {
+    if (!code || isCopied) return;
+    copyToClipboard(code);
+  };
+
+  return (
+    <div className="aui-code-header-root">
+      <span className="aui-code-header-language">{language}</span>
+      <TooltipIconButton tooltip="Copy" onClick={onCopy}>
+        {!isCopied && <CopyIcon />}
+        {isCopied && <CheckIcon />}
+      </TooltipIconButton>
+    </div>
+  );
+};
+
+const useCopyToClipboard = ({
+  copiedDuration = 3000,
+}: {
+  copiedDuration?: number;
+} = {}) => {
+  const [isCopied, setIsCopied] = useState<boolean>(false);
+
+  const copyToClipboard = (value: string) => {
+    if (!value) return;
+
+    navigator.clipboard.writeText(value).then(() => {
+      setIsCopied(true);
+      setTimeout(() => setIsCopied(false), copiedDuration);
+    });
+  };
+
+  return { isCopied, copyToClipboard };
+};
+
+const defaultComponents = memoizeMarkdownComponents({
+  h1: ({ className, ...props }) => (
+    <h1 className={cn("aui-md-h1", className)} {...props} />
+  ),
+  h2: ({ className, ...props }) => (
+    <h2 className={cn("aui-md-h2", className)} {...props} />
+  ),
+  h3: ({ className, ...props }) => (
+    <h3 className={cn("aui-md-h3", className)} {...props} />
+  ),
+  h4: ({ className, ...props }) => (
+    <h4 className={cn("aui-md-h4", className)} {...props} />
+  ),
+  h5: ({ className, ...props }) => (
+    <h5 className={cn("aui-md-h5", className)} {...props} />
+  ),
+  h6: ({ className, ...props }) => (
+    <h6 className={cn("aui-md-h6", className)} {...props} />
+  ),
+  p: ({ className, ...props }) => (
+    <p className={cn("aui-md-p", className)} {...props} />
+  ),
+  a: ({ className, ...props }) => (
+    <a className={cn("aui-md-a", className)} {...props} />
+  ),
+  blockquote: ({ className, ...props }) => (
+    <blockquote className={cn("aui-md-blockquote", className)} {...props} />
+  ),
+  ul: ({ className, ...props }) => (
+    <ul className={cn("aui-md-ul", className)} {...props} />
+  ),
+  ol: ({ className, ...props }) => (
+    <ol className={cn("aui-md-ol", className)} {...props} />
+  ),
+  hr: ({ className, ...props }) => (
+    <hr className={cn("aui-md-hr", className)} {...props} />
+  ),
+  table: ({ className, ...props }) => (
+    <table className={cn("aui-md-table", className)} {...props} />
+  ),
+  th: ({ className, ...props }) => (
+    <th className={cn("aui-md-th", className)} {...props} />
+  ),
+  td: ({ className, ...props }) => (
+    <td className={cn("aui-md-td", className)} {...props} />
+  ),
+  tr: ({ className, ...props }) => (
+    <tr className={cn("aui-md-tr", className)} {...props} />
+  ),
+  sup: ({ className, ...props }) => (
+    <sup className={cn("aui-md-sup", className)} {...props} />
+  ),
+  pre: ({ className, ...props }) => (
+    <pre className={cn("aui-md-pre", className)} {...props} />
+  ),
+  code: function Code({ className, ...props }) {
+    const isCodeBlock = useIsMarkdownCodeBlock();
+    return (
+      <code
+        className={cn(!isCodeBlock && "aui-md-inline-code", className)}
+        {...props}
+      />
+    );
+  },
+  CodeHeader,
+});
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
new file mode 100644
index 0000000000..b44abaf0b7
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
@@ -0,0 +1,66 @@
+import type { FC } from "react";
+import {
+  ThreadListItemPrimitive,
+  ThreadListPrimitive,
+} from "@assistant-ui/react";
+import { ArchiveIcon, PlusIcon } from "lucide-react";
+
+import { Button } from "../ui/button";
+import { TooltipIconButton } from "./tooltip-icon-button";
+
+export const ThreadList: FC = () => {
+  return (
+    <ThreadListPrimitive.Root className="aui-root aui-thread-list-root">
+      <ThreadListNew />
+      <ThreadListItems />
+    </ThreadListPrimitive.Root>
+  );
+};
+
+const ThreadListNew: FC = () => {
+  return (
+    <ThreadListPrimitive.New asChild>
+      <Button className="aui-thread-list-new" variant="ghost">
+        <PlusIcon />
+        New Thread
+      </Button>
+    </ThreadListPrimitive.New>
+  );
+};
+
+const ThreadListItems: FC = () => {
+  return <ThreadListPrimitive.Items components={{ ThreadListItem }} />;
+};
+
+const ThreadListItem: FC = () => {
+  return (
+    <ThreadListItemPrimitive.Root className="aui-thread-list-item">
+      <ThreadListItemPrimitive.Trigger className="aui-thread-list-item-trigger">
+        <ThreadListItemTitle />
+      </ThreadListItemPrimitive.Trigger>
+      <ThreadListItemArchive />
+    </ThreadListItemPrimitive.Root>
+  );
+};
+
+const ThreadListItemTitle: FC = () => {
+  return (
+    <p className="aui-thread-list-item-title">
+      <ThreadListItemPrimitive.Title fallback="New Chat" />
+    </p>
+  );
+};
+
+const ThreadListItemArchive: FC = () => {
+  return (
+    <ThreadListItemPrimitive.Archive asChild>
+      <TooltipIconButton
+        className="aui-thread-list-item-archive"
+        variant="ghost"
+        tooltip="Archive thread"
+      >
+        <ArchiveIcon />
+      </TooltipIconButton>
+    </ThreadListItemPrimitive.Archive>
+  );
+};
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
new file mode 100644
index 0000000000..95b0d0a2b8
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
@@ -0,0 +1,283 @@
+import {
+    ActionBarPrimitive,
+    BranchPickerPrimitive,
+    ComposerPrimitive,
+    MessagePrimitive,
+    ThreadPrimitive,
+  } from "@assistant-ui/react";
+  import type { FC } from "react";
+  import {
+    ArrowDownIcon,
+    CheckIcon,
+    ChevronLeftIcon,
+    ChevronRightIcon,
+    CopyIcon,
+    PencilIcon,
+    RefreshCwIcon,
+    SendHorizontalIcon,
+  } from "lucide-react";
+  import { cn } from "../../utils/cn";
+  
+  import { Button } from "../ui/button";
+  import { MarkdownText } from "./markdown-text";
+  import { TooltipIconButton } from "./tooltip-icon-button";
+  
+  export const Thread: FC = () => {
+    return (
+      <ThreadPrimitive.Root
+        className="aui-root aui-thread-root"
+        style={{
+          ["--thread-max-width" as string]: "42rem",
+        }}
+      >
+        <ThreadPrimitive.Viewport className="aui-thread-viewport">
+          <ThreadWelcome />
+  
+          <ThreadPrimitive.Messages
+            components={{
+              UserMessage: UserMessage,
+              EditComposer: EditComposer,
+              AssistantMessage: AssistantMessage,
+            }}
+          />
+  
+          <ThreadPrimitive.If empty={false}>
+            <div className="aui-thread-viewport-spacer" />
+          </ThreadPrimitive.If>
+  
+          <div className="aui-thread-viewport-footer">
+            <ThreadScrollToBottom />
+            <Composer />
+          </div>
+        </ThreadPrimitive.Viewport>
+      </ThreadPrimitive.Root>
+    );
+  };
+  
+  const ThreadScrollToBottom: FC = () => {
+    return (
+      <ThreadPrimitive.ScrollToBottom asChild>
+        <TooltipIconButton
+          tooltip="Scroll to bottom"
+          variant="outline"
+          className="aui-thread-scroll-to-bottom"
+        >
+          <ArrowDownIcon />
+        </TooltipIconButton>
+      </ThreadPrimitive.ScrollToBottom>
+    );
+  };
+  
+  const ThreadWelcome: FC = () => {
+    return (
+      <ThreadPrimitive.Empty>
+        <div className="aui-thread-welcome-root">
+          <div className="aui-thread-welcome-center">
+            <p className="aui-thread-welcome-message">
+              How can I help you today?
+            </p>
+          </div>
+          <ThreadWelcomeSuggestions />
+        </div>
+      </ThreadPrimitive.Empty>
+    );
+  };
+  
+  const ThreadWelcomeSuggestions: FC = () => {
+    return (
+      <div className="aui-thread-welcome-suggestions">
+        <ThreadPrimitive.Suggestion
+          className="aui-thread-welcome-suggestion"
+          prompt="What is the weather in Tokyo?"
+          method="replace"
+          autoSend
+        >
+          <span className="aui-thread-welcome-suggestion-text">
+            What is the weather in Tokyo?
+          </span>
+        </ThreadPrimitive.Suggestion>
+        <ThreadPrimitive.Suggestion
+          className="aui-thread-welcome-suggestion"
+          prompt="What is assistant-ui?"
+          method="replace"
+          autoSend
+        >
+          <span className="aui-thread-welcome-suggestion-text">
+            What is assistant-ui?
+          </span>
+        </ThreadPrimitive.Suggestion>
+      </div>
+    );
+  };
+  
+  const Composer: FC = () => {
+    return (
+      <ComposerPrimitive.Root className="aui-composer-root">
+        <ComposerPrimitive.Input
+          rows={1}
+          autoFocus
+          placeholder="Write a message..."
+          className="aui-composer-input"
+        />
+        <ComposerAction />
+      </ComposerPrimitive.Root>
+    );
+  };
+  
+  const ComposerAction: FC = () => {
+    return (
+      <>
+        <ThreadPrimitive.If running={false}>
+          <ComposerPrimitive.Send asChild>
+            <TooltipIconButton
+              tooltip="Send"
+              variant="default"
+              className="aui-composer-send"
+            >
+              <SendHorizontalIcon />
+            </TooltipIconButton>
+          </ComposerPrimitive.Send>
+        </ThreadPrimitive.If>
+        <ThreadPrimitive.If running>
+          <ComposerPrimitive.Cancel asChild>
+            <TooltipIconButton
+              tooltip="Cancel"
+              variant="default"
+              className="aui-composer-cancel"
+            >
+              <CircleStopIcon />
+            </TooltipIconButton>
+          </ComposerPrimitive.Cancel>
+        </ThreadPrimitive.If>
+      </>
+    );
+  };
+  
+  const UserMessage: FC = () => {
+    return (
+      <MessagePrimitive.Root className="aui-user-message-root">
+        <UserActionBar />
+  
+        <div className="aui-user-message-content">
+          <MessagePrimitive.Parts />
+        </div>
+  
+        <BranchPicker className="aui-user-branch-picker" />
+      </MessagePrimitive.Root>
+    );
+  };
+  
+  const UserActionBar: FC = () => {
+    return (
+      <ActionBarPrimitive.Root
+        hideWhenRunning
+        autohide="not-last"
+        className="aui-user-action-bar-root"
+      >
+        <ActionBarPrimitive.Edit asChild>
+          <TooltipIconButton tooltip="Edit">
+            <PencilIcon />
+          </TooltipIconButton>
+        </ActionBarPrimitive.Edit>
+      </ActionBarPrimitive.Root>
+    );
+  };
+  
+  const EditComposer: FC = () => {
+    return (
+      <ComposerPrimitive.Root className="aui-edit-composer-root">
+        <ComposerPrimitive.Input className="aui-edit-composer-input" />
+  
+        <div className="aui-edit-composer-footer">
+          <ComposerPrimitive.Cancel asChild>
+            <Button variant="ghost">Cancel</Button>
+          </ComposerPrimitive.Cancel>
+          <ComposerPrimitive.Send asChild>
+            <Button>Send</Button>
+          </ComposerPrimitive.Send>
+        </div>
+      </ComposerPrimitive.Root>
+    );
+  };
+  
+  const AssistantMessage: FC = () => {
+    return (
+      <MessagePrimitive.Root className="aui-assistant-message-root">
+        <div className="aui-assistant-message-content">
+          <MessagePrimitive.Parts components={{ Text: MarkdownText }} />
+        </div>
+  
+        <AssistantActionBar />
+  
+        <BranchPicker className="aui-assistant-branch-picker" />
+      </MessagePrimitive.Root>
+    );
+  };
+  
+  const AssistantActionBar: FC = () => {
+    return (
+      <ActionBarPrimitive.Root
+        hideWhenRunning
+        autohide="not-last"
+        autohideFloat="single-branch"
+        className="aui-assistant-action-bar-root"
+      >
+        <ActionBarPrimitive.Copy asChild>
+          <TooltipIconButton tooltip="Copy">
+            <MessagePrimitive.If copied>
+              <CheckIcon />
+            </MessagePrimitive.If>
+            <MessagePrimitive.If copied={false}>
+              <CopyIcon />
+            </MessagePrimitive.If>
+          </TooltipIconButton>
+        </ActionBarPrimitive.Copy>
+        <ActionBarPrimitive.Reload asChild>
+          <TooltipIconButton tooltip="Refresh">
+            <RefreshCwIcon />
+          </TooltipIconButton>
+        </ActionBarPrimitive.Reload>
+      </ActionBarPrimitive.Root>
+    );
+  };
+  
+  const BranchPicker: FC<BranchPickerPrimitive.Root.Props> = ({
+    className,
+    ...rest
+  }) => {
+    return (
+      <BranchPickerPrimitive.Root
+        hideWhenSingleBranch
+        className={cn("aui-branch-picker-root", className)}
+        {...rest}
+      >
+        <BranchPickerPrimitive.Previous asChild>
+          <TooltipIconButton tooltip="Previous">
+            <ChevronLeftIcon />
+          </TooltipIconButton>
+        </BranchPickerPrimitive.Previous>
+        <span className="aui-branch-picker-state">
+          <BranchPickerPrimitive.Number /> / <BranchPickerPrimitive.Count />
+        </span>
+        <BranchPickerPrimitive.Next asChild>
+          <TooltipIconButton tooltip="Next">
+            <ChevronRightIcon />
+          </TooltipIconButton>
+        </BranchPickerPrimitive.Next>
+      </BranchPickerPrimitive.Root>
+    );
+  };
+  
+  const CircleStopIcon = () => {
+    return (
+      <svg
+        xmlns="http://www.w3.org/2000/svg"
+        viewBox="0 0 16 16"
+        fill="currentColor"
+        width="16"
+        height="16"
+      >
+        <rect width="10" height="10" x="3" y="3" rx="2" />
+      </svg>
+    );
+  };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/tooltip-icon-button.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/tooltip-icon-button.tsx
new file mode 100644
index 0000000000..d2434babff
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/tooltip-icon-button.tsx
@@ -0,0 +1,42 @@
+import { ComponentPropsWithoutRef, forwardRef } from "react";
+
+import {
+  Tooltip,
+  TooltipContent,
+  TooltipProvider,
+  TooltipTrigger,
+} from "../ui/tooltip";
+import { Button } from "../ui/button";
+import { cn } from "../../utils/cn";
+
+export type TooltipIconButtonProps = ComponentPropsWithoutRef<typeof Button> & {
+  tooltip: string;
+  side?: "top" | "bottom" | "left" | "right";
+};
+
+export const TooltipIconButton = forwardRef<
+  HTMLButtonElement,
+  TooltipIconButtonProps
+>(({ children, tooltip, side = "bottom", className, ...rest }, ref) => {
+  return (
+    <TooltipProvider>
+      <Tooltip>
+        <TooltipTrigger asChild>
+          <Button
+            variant="ghost"
+            size="icon"
+            {...rest}
+            className={cn("", className)}
+            ref={ref}
+          >
+            {children}
+            <span className="aui-sr-only">{tooltip}</span>
+          </Button>
+        </TooltipTrigger>
+        <TooltipContent side={side}>{tooltip}</TooltipContent>
+      </Tooltip>
+    </TooltipProvider>
+  );
+});
+
+TooltipIconButton.displayName = "TooltipIconButton";
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/button.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/button.tsx
new file mode 100644
index 0000000000..4406b74e67
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/button.tsx
@@ -0,0 +1,45 @@
+import * as React from "react";
+import { Slot } from "@radix-ui/react-slot";
+import { cva, type VariantProps } from "class-variance-authority";
+import { cn } from "../../utils/cn";
+
+const buttonVariants = cva("aui-button", {
+  variants: {
+    variant: {
+      default: "aui-button-primary",
+      outline: "aui-button-outline",
+      ghost: "aui-button-ghost",
+    },
+    size: {
+      default: "aui-button-medium",
+      icon: "aui-button-icon",
+    },
+  },
+  defaultVariants: {
+    variant: "default",
+    size: "default",
+  },
+});
+
+function Button({
+  className,
+  variant,
+  size,
+  asChild = false,
+  ...props
+}: React.ComponentProps<"button"> &
+  VariantProps<typeof buttonVariants> & {
+    asChild?: boolean;
+  }) {
+  const Comp = asChild ? Slot : "button";
+
+  return (
+    <Comp
+      data-slot="button"
+      className={cn(buttonVariants({ variant, size, className }))}
+      {...props}
+    />
+  );
+}
+
+export { Button, buttonVariants };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/tooltip.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/tooltip.tsx
new file mode 100644
index 0000000000..ede610e327
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/tooltip.tsx
@@ -0,0 +1,29 @@
+"use client";
+
+import * as React from "react";
+import * as TooltipPrimitive from "@radix-ui/react-tooltip";
+
+import { cn } from "../../utils/cn";
+
+const TooltipProvider = TooltipPrimitive.Provider;
+
+const Tooltip = TooltipPrimitive.Root;
+
+const TooltipTrigger = TooltipPrimitive.Trigger;
+
+const TooltipContent = React.forwardRef<
+  React.ElementRef<typeof TooltipPrimitive.Content>,
+  React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
+>(({ className, sideOffset = 4, ...props }, ref) => (
+  <TooltipPrimitive.Portal>
+    <TooltipPrimitive.Content
+      ref={ref}
+      sideOffset={sideOffset}
+      className={cn("aui-tooltip-content", className)}
+      {...props}
+    />
+  </TooltipPrimitive.Portal>
+));
+TooltipContent.displayName = TooltipPrimitive.Content.displayName;
+
+export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/cn.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/cn.ts
new file mode 100644
index 0000000000..5ba370c74d
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/utils/cn.ts
@@ -0,0 +1,5 @@
+import { type ClassValue, clsx } from "clsx";
+
+export function cn(...inputs: ClassValue[]) {
+  return clsx(inputs);
+}
\ No newline at end of file
diff --git a/client/yarn.lock b/client/yarn.lock
index de7a2c227b..e8357b3c08 100644
--- a/client/yarn.lock
+++ b/client/yarn.lock
@@ -7962,6 +7962,15 @@ __metadata:
   languageName: node
   linkType: hard
 
+"class-variance-authority@npm:^0.7.1":
+  version: 0.7.1
+  resolution: "class-variance-authority@npm:0.7.1"
+  dependencies:
+    clsx: ^2.1.1
+  checksum: e05ba26ef9ec38f7c675047ce366b067d60af6c954dba08f7802af19a9460a534ae752d8fe1294fff99d0fa94a669b16ccebd87e8a20f637c0736cf2751dd2c5
+  languageName: node
+  linkType: hard
+
 "classnames@npm:2.x, classnames@npm:^2.2.1, classnames@npm:^2.2.3, classnames@npm:^2.2.5, classnames@npm:^2.2.6, classnames@npm:^2.3.1, classnames@npm:^2.3.2, classnames@npm:^2.5.1":
   version: 2.5.1
   resolution: "classnames@npm:2.5.1"
@@ -8051,7 +8060,7 @@ __metadata:
   languageName: node
   linkType: hard
 
-"clsx@npm:^2.0.0":
+"clsx@npm:^2.0.0, clsx@npm:^2.1.1":
   version: 2.1.1
   resolution: "clsx@npm:2.1.1"
   checksum: acd3e1ab9d8a433ecb3cc2f6a05ab95fe50b4a3cfc5ba47abb6cbf3754585fcb87b84e90c822a1f256c4198e3b41c7f6c391577ffc8678ad587fc0976b24fd57
@@ -14894,6 +14903,7 @@ coolshapes-react@lowcoder-org/coolshapes-react:
     antd: ^5.25.2
     axios: ^1.7.7
     buffer: ^6.0.3
+    class-variance-authority: ^0.7.1
     clsx: ^2.0.0
     cnchar: ^3.2.4
     coolshapes-react: lowcoder-org/coolshapes-react

From c54139368e647295474fd42538691cdb40dcd583 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Tue, 1 Jul 2025 13:09:26 +0500
Subject: [PATCH 05/54] fix linter error

---
 .../comps/comps/chatComp/components/assistant-ui/thread.tsx   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
index 95b0d0a2b8..ae3749fb77 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
@@ -159,7 +159,7 @@ import {
         <UserActionBar />
   
         <div className="aui-user-message-content">
-          <MessagePrimitive.Parts />
+          <MessagePrimitive.Content />
         </div>
   
         <BranchPicker className="aui-user-branch-picker" />
@@ -204,7 +204,7 @@ import {
     return (
       <MessagePrimitive.Root className="aui-assistant-message-root">
         <div className="aui-assistant-message-content">
-          <MessagePrimitive.Parts components={{ Text: MarkdownText }} />
+          <MessagePrimitive.Content components={{ Text: MarkdownText }} />
         </div>
   
         <AssistantActionBar />

From bf3810f918938d9e42c3f7e10773761a43d12b5e Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Tue, 1 Jul 2025 14:17:33 +0500
Subject: [PATCH 06/54] add thread

---
 .../src/comps/comps/chatComp/chatView.tsx     | 63 +------------------
 1 file changed, 2 insertions(+), 61 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
index 6ca388777f..28285b7827 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
@@ -1,12 +1,11 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
 import React from "react";
 import { ChatCompProps } from "./chatCompTypes";
+import { Thread } from "./components/assistant-ui/thread";
 
 // Import assistant-ui components and proper runtime
 import { 
   AssistantRuntimeProvider,
-  ThreadPrimitive, 
-  ComposerPrimitive
 } from "@assistant-ui/react";
 import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
 import "@assistant-ui/styles/index.css";
@@ -20,65 +19,7 @@ export const ChatView = React.memo((props: ChatCompProps) => {
 
   return (
     <AssistantRuntimeProvider runtime={runtime}>
-      <div style={{ 
-        height: '100%', 
-        padding: '16px',
-        backgroundColor: '#f5f5f5'
-      }}>
-        <div className="aui-root">
-          <h3 style={{ marginBottom: '16px' }}>🚀 Assistant-UI with Vercel AI SDK!</h3>
-          
-          {/* Test Thread with real runtime */}
-          <div className="aui-thread-root" style={{ 
-            background: 'white', 
-            borderRadius: '8px', 
-            padding: '16px',
-            marginBottom: '16px',
-            border: '1px solid #e0e0e0',
-            minHeight: '200px'
-          }}>
-            <ThreadPrimitive.Empty>
-              <div className="aui-thread-welcome-root">
-                <div className="aui-thread-welcome-center">
-                  <p className="aui-thread-welcome-message">
-                      {props.text} - Runtime Working! 🎉
-                  </p>
-                </div>
-              </div>
-            </ThreadPrimitive.Empty>
-          </div>
-
-          {/* Test Composer with real runtime */}
-          <div className="aui-composer-root" style={{
-            background: 'white',
-            borderRadius: '8px',
-            padding: '12px',
-            border: '1px solid #e0e0e0'
-          }}>
-            <ComposerPrimitive.Input
-              placeholder={props.text}
-              disabled={false}
-              className="aui-composer-input"
-              rows={1}
-            />
-          </div>
-
-          {/* Property status */}
-          <div style={{ 
-            marginTop: '16px', 
-            fontSize: '12px', 
-            color: '#666',
-            background: 'white',
-            padding: '8px',
-            borderRadius: '4px',
-            border: '1px solid #e0e0e0'
-          }}>
-            <strong>✅ Test Status:</strong><br/>
-            Text: {props.text}<br/>
-            Runtime: Vercel AI SDK ✅
-          </div>
-        </div>
-      </div>
+      <Thread />
     </AssistantRuntimeProvider>
   );
 });

From 11c98fd1119c3fc76432be5d559a197a79717116 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Tue, 1 Jul 2025 15:36:12 +0500
Subject: [PATCH 07/54] add properties for chat component

---
 .../src/comps/comps/chatComp/chatCompTypes.ts | 22 ++++++++++++++++++-
 .../comps/comps/chatComp/chatPropertyView.tsx | 12 +++++++---
 .../src/comps/comps/chatComp/chatView.tsx     |  9 ++++++--
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
index a58a0eda55..147f4dee1b 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
@@ -1,11 +1,31 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
-import { StringControl } from "comps/controls/codeControl";
+import { StringControl, NumberControl } from "comps/controls/codeControl";
 import { withDefault } from "comps/generators";
+import { BoolControl } from "comps/controls/boolControl";
+import { dropdownControl } from "comps/controls/dropdownControl";
+
+// Model type dropdown options
+const ModelTypeOptions = [
+  { label: "Direct LLM", value: "direct-llm" },
+  { label: "n8n Workflow", value: "n8n" },
+] as const;
 
 export const chatChildrenMap = {
   text: withDefault(StringControl, "Chat Component Placeholder"),
+  modelHost: withDefault(StringControl, "http://localhost:11434"),
+  modelType: dropdownControl(ModelTypeOptions, "direct-llm"),
+  streaming: BoolControl.DEFAULT_TRUE,
+  systemPrompt: withDefault(StringControl, "You are a helpful assistant."),
+  agent: BoolControl,
+  maxInteractions: withDefault(NumberControl, 10),
 };
 
 export type ChatCompProps = {
   text: string;
+  modelHost: string;
+  modelType: "direct-llm" | "n8n";
+  streaming: boolean;
+  systemPrompt: string;
+  agent: boolean;
+  maxInteractions: number;
 };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
index e31f6268de..510e87ac2e 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
@@ -3,11 +3,17 @@ import React from "react";
 import { Section, sectionNames } from "lowcoder-design";
 
 export const ChatPropertyView = React.memo((props: any) => {
+  const { children } = props;
+
   return (
     <Section name={sectionNames.basic}>
-      {props.children.text.propertyView({ 
-        label: "Text" 
-      })}
+      {children.text.propertyView({ label: "Text" })}
+      {children.modelHost.propertyView({ label: "Model Host URL" })}
+      {children.modelType.propertyView({ label: "Model Type" })}
+      {children.streaming.propertyView({ label: "Streaming Responses" })}
+      {children.systemPrompt.propertyView({ label: "System Prompt" })}
+      {children.agent.propertyView({ label: "Agent Mode" })}
+      {children.maxInteractions.propertyView({ label: "Max Interactions" })}
     </Section>
   );
 });
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
index 28285b7827..0b74094b40 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
@@ -14,8 +14,13 @@ import "@assistant-ui/styles/markdown.css";
 export const ChatView = React.memo((props: ChatCompProps) => {
   // Create proper runtime using useChatRuntime
   const runtime = useChatRuntime({
-    api: "/api/chat", // We'll create this endpoint later
-  });
+    api: props.modelHost,
+    stream: props.streaming,
+    modelType: props.modelType as any,
+    systemPrompt: props.systemPrompt,
+    agent: props.agent,
+    maxTurns: props.maxInteractions,
+  } as any);
 
   return (
     <AssistantRuntimeProvider runtime={runtime}>

From d6b0ef071e1ea1ecaafedabaf1b54d81afda3778 Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Tue, 1 Jul 2025 18:16:23 +0500
Subject: [PATCH 08/54] update folder structure and adds component actions to
 js console

---
 .../lowcoder/src/comps/comps/preLoadComp.tsx  | 376 +----------
 .../comps/comps/preLoadComp/ACTION_SYSTEM.md  | 203 ++++++
 .../src/comps/comps/preLoadComp/README.md     |  98 +++
 .../comps/comps/preLoadComp/actionConfigs.ts  | 620 ++++++++++++++++++
 .../comps/preLoadComp/actionInputSection.tsx  | 315 +++++++++
 .../comps/comps/preLoadComp/components.tsx    | 178 +++++
 .../src/comps/comps/preLoadComp/index.ts      |  43 ++
 .../comps/comps/preLoadComp/preLoadComp.tsx   |  69 ++
 .../comps/preLoadComp/preloadConfigModal.tsx  |  60 ++
 .../src/comps/comps/preLoadComp/styled.tsx    |  29 +
 .../src/comps/comps/preLoadComp/tabPanes.tsx  |  46 ++
 .../src/comps/comps/preLoadComp/types.ts      |  59 ++
 .../src/comps/comps/preLoadComp/utils.ts      |  55 ++
 13 files changed, 1776 insertions(+), 375 deletions(-)
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/ACTION_SYSTEM.md
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/README.md
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/components.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/index.ts
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/preLoadComp.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/preloadConfigModal.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/styled.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/tabPanes.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp.tsx
index 944b639760..35b6d84b09 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp.tsx
@@ -1,375 +1 @@
-import { EmptyContent } from "components/EmptyContent";
-import { HelpText } from "components/HelpText";
-import { Tabs } from "components/Tabs";
-import {
-  clearMockWindow,
-  clearStyleEval,
-  ConstructorToComp,
-  evalFunc,
-  evalStyle,
-  RecordConstructorToComp,
-} from "lowcoder-core";
-import { CodeTextControl } from "comps/controls/codeTextControl";
-import SimpleStringControl from "comps/controls/simpleStringControl";
-import { MultiCompBuilder, withPropertyViewFn } from "comps/generators";
-import { list } from "comps/generators/list";
-import { BaseSection, CustomModal, PlusIcon, ScrollBar } from "lowcoder-design";
-import React, { useContext, useEffect, useState } from "react";
-import styled from "styled-components";
-import { ExternalEditorContext } from "util/context/ExternalEditorContext";
-import { runScriptInHost } from "util/commonUtils";
-import { getGlobalSettings } from "comps/utils/globalSettings";
-import { trans } from "i18n";
-import log from "loglevel";
-import { JSLibraryModal } from "components/JSLibraryModal";
-import { JSLibraryTree } from "components/JSLibraryTree";
-import { fetchJSLibrary } from "util/jsLibraryUtils";
-
-export interface ExternalPreload {
-  css?: string;
-  libs?: string[];
-  script?: string;
-  runJavaScriptInHost?: boolean;
-}
-
-interface RunAndClearable<T> {
-  run(id: string, externalPreload?: T): Promise<any>;
-
-  clear(): Promise<any>;
-}
-
-class LibsCompBase extends list(SimpleStringControl) implements RunAndClearable<string[]> {
-  success: Record<string, boolean> = {};
-  globalVars: Record<string, string[]> = {};
-  externalLibs: string[] = [];
-  runInHost: boolean = false;
-
-  getAllLibs() {
-    return this.externalLibs.concat(this.getView().map((i) => i.getView()));
-  }
-
-  async loadScript(url: string) {
-    if (this.success[url]) {
-      return;
-    }
-    return fetchJSLibrary(url).then((code) => {
-      evalFunc(
-        code,
-        {},
-        {},
-        {
-          scope: "function",
-          disableLimit: this.runInHost,
-          onSetGlobalVars: (v: string) => {
-            this.globalVars[url] = this.globalVars[url] || [];
-            if (!this.globalVars[url].includes(v)) {
-              this.globalVars[url].push(v);
-            }
-          },
-        }
-      );
-      this.success[url] = true;
-    });
-  }
-
-  async loadAllLibs() {
-    const scriptRunners = this.getAllLibs().map((url) =>
-      this.loadScript(url).catch((e) => {
-        log.warn(e);
-      })
-    );
-
-    try {
-      await Promise.all(scriptRunners);
-    } catch (e) {
-      log.warn("load preload libs error:", e);
-    }
-  }
-
-  async run(id: string, externalLibs: string[] = [], runInHost: boolean = false) {
-    this.externalLibs = externalLibs;
-    this.runInHost = runInHost;
-    return this.loadAllLibs();
-  }
-
-  async clear(): Promise<any> {
-    clearMockWindow();
-  }
-}
-
-const LibsComp = withPropertyViewFn(LibsCompBase, (comp) => {
-  useEffect(() => {
-    comp.loadAllLibs();
-  }, [comp.getView().length]);
-  return (
-    <ScrollBar style={{ height: "295px" }}>
-      {comp.getAllLibs().length === 0 && (
-        <EmptyContent text={trans("preLoad.jsLibraryEmptyContent")} style={{ margin: "0 16px" }} />
-      )}
-      <JSLibraryTree
-        mode={"column"}
-        libs={comp
-          .getView()
-          .map((i) => ({
-            url: i.getView(),
-            deletable: true,
-            exportedAs: comp.globalVars[i.getView()]?.[0],
-          }))
-          .concat(
-            comp.externalLibs.map((l) => ({
-              url: l,
-              deletable: false,
-              exportedAs: comp.globalVars[l]?.[0],
-            }))
-          )}
-        onDelete={(idx) => {
-          comp.dispatch(comp.deleteAction(idx));
-        }}
-      />
-    </ScrollBar>
-  );
-});
-
-function runScript(code: string, inHost?: boolean) {
-  if (inHost) {
-    runScriptInHost(code);
-    return;
-  }
-  try {
-    evalFunc(code, {}, {});
-  } catch (e) {
-    log.error(e);
-  }
-}
-
-class ScriptComp extends CodeTextControl implements RunAndClearable<string> {
-  runInHost: boolean = false;
-
-  runPreloadScript() {
-    const code = this.getView();
-    if (!code) {
-      return;
-    }
-    runScript(code, this.runInHost);
-  }
-
-  async run(id: string, externalScript: string = "", runInHost: boolean = false) {
-    this.runInHost = runInHost;
-    if (externalScript) {
-      runScript(externalScript, runInHost);
-    }
-    this.runPreloadScript();
-  }
-
-  async clear(): Promise<any> {
-    clearMockWindow();
-  }
-}
-
-class CSSComp extends CodeTextControl implements RunAndClearable<string> {
-  id = "";
-  externalCSS: string = "";
-
-  async applyAllCSS() {
-    const css = this.getView();
-    evalStyle(this.id, [this.externalCSS, css]);
-  }
-
-  async run(id: string, externalCSS: string = "") {
-    this.id = id;
-    this.externalCSS = externalCSS;
-    return this.applyAllCSS();
-  }
-
-  async clear() {
-    clearStyleEval(this.id);
-  }
-}
-
-class GlobalCSSComp extends CodeTextControl implements RunAndClearable<string> {
-  id = "";
-  externalCSS: string = "";
-
-  async applyAllCSS() {
-    const css = this.getView();
-    evalStyle(this.id, [this.externalCSS, css], true);
-  }
-
-  async run(id: string, externalCSS: string = "") {
-    this.id = id;
-    this.externalCSS = externalCSS;
-    return this.applyAllCSS();
-  }
-
-  async clear() {
-    clearStyleEval(this.id);
-  }
-}
-
-const childrenMap = {
-  libs: LibsComp,
-  script: ScriptComp,
-  css: CSSComp,
-  globalCSS: GlobalCSSComp,
-};
-
-type ChildrenInstance = RecordConstructorToComp<typeof childrenMap>;
-
-function JavaScriptTabPane(props: { comp: ConstructorToComp<typeof ScriptComp> }) {
-  useEffect(() => {
-    props.comp.runPreloadScript();
-  }, [props.comp]);
-
-  const codePlaceholder = `window.name = 'Tom';\nwindow.greet = () => "hello world";`;
-
-  return (
-    <>
-      <HelpText style={{ marginBottom: 20 }}>{trans("preLoad.jsHelpText")}</HelpText>
-      {props.comp.propertyView({
-        expandable: false,
-        styleName: "window",
-        codeType: "Function",
-        language: "javascript",
-        placeholder: codePlaceholder,
-      })}
-    </>
-  );
-}
-
-function CSSTabPane(props: { comp: CSSComp, isGlobal?: boolean }) {
-  useEffect(() => {
-    props.comp.applyAllCSS();
-  }, [props.comp]);
-
-  const codePlaceholder = `.top-header {\n  background-color: red; \n}`;
-
-  return (
-    <>
-      <HelpText style={{ marginBottom: 20 }}>{trans("preLoad.cssHelpText")}</HelpText>
-      {props.comp.propertyView({
-        expandable: false,
-        placeholder: codePlaceholder,
-        styleName: "window",
-        language: "css",
-      })}
-    </>
-  );
-}
-
-enum TabKey {
-  JavaScript = "js",
-  CSS = "css",
-  GLOBAL_CSS = "global_css",
-}
-
-function PreloadConfigModal(props: ChildrenInstance) {
-  const [activeKey, setActiveKey] = useState(TabKey.JavaScript);
-  const { showScriptsAndStyleModal, changeExternalState } = useContext(ExternalEditorContext);
-  
-  const tabItems = [
-    {
-      key: TabKey.JavaScript,
-      label: 'JavaScript',
-      children: <JavaScriptTabPane comp={props.script} />
-    },
-    {
-      key: TabKey.CSS,
-      label: 'CSS',
-      children: <CSSTabPane comp={props.css} />
-    },
-    {
-      key: TabKey.GLOBAL_CSS,
-      label: 'Global CSS',
-      children: <CSSTabPane comp={props.globalCSS} isGlobal />
-    },
-  ]
-  return (
-    <CustomModal
-      draggable
-      mask={activeKey !== TabKey.CSS}
-      open={showScriptsAndStyleModal}
-      title={trans("preLoad.scriptsAndStyles")}
-      destroyOnHidden
-      onCancel={() => changeExternalState?.({ showScriptsAndStyleModal: false })}
-      showOkButton={false}
-      showCancelButton={false}
-      width="600px"
-    >
-      <Tabs
-        onChange={(k) => setActiveKey(k as TabKey)}
-        style={{ marginBottom: 8, marginTop: 4 }}
-        activeKey={activeKey}
-        items={ tabItems }
-      >
-      </Tabs>
-    </CustomModal>
-  );
-}
-
-const PreloadCompBase = new MultiCompBuilder(childrenMap, () => {})
-  .setPropertyViewFn((children) => <PreloadConfigModal {...children} />)
-  .build();
-
-const AddJSLibraryButton = styled.div`
-  cursor: pointer;
-  margin-right: 16px;
-
-  g g {
-    stroke: #8b8fa3;
-  }
-
-  &:hover {
-    g g {
-      stroke: #222222;
-    }
-  }
-`;
-
-const JSLibraryWrapper = styled.div`
-  position: relative;
-`;
-
-export class PreloadComp extends PreloadCompBase {
-  async clear() {
-    return Promise.allSettled(Object.values(this.children).map((i) => i.clear()));
-  }
-
-  async run(id: string) {
-    const { orgCommonSettings = {} } = getGlobalSettings();
-    const { preloadCSS,preloadGlobalCSS, preloadJavaScript, preloadLibs, runJavaScriptInHost } = orgCommonSettings;
-    await this.children.css.run(id, preloadCSS || "");
-    await this.children.globalCSS.run('body', preloadGlobalCSS || "");
-    await this.children.libs.run(id, preloadLibs || [], !!runJavaScriptInHost);
-    await this.children.script.run(id, preloadJavaScript || "", !!runJavaScriptInHost);
-  }
-
-  getJSLibraryPropertyView() {
-    const libs = this.children.libs;
-    return (
-      <JSLibraryWrapper>
-        <BaseSection
-          name={trans("preLoad.jsLibrary")}
-          width={288}
-          noMargin
-          style={{
-            borderTop: "1px solid #e1e3eb",
-            backgroundColor: "#fff",
-          }}
-          additionalButton={
-            <AddJSLibraryButton>
-              <JSLibraryModal
-                runInHost={libs.runInHost}
-                trigger={<PlusIcon height={"46px"} />}
-                onCheck={(url) => !libs.getAllLibs().includes(url)}
-                onLoad={(url) => libs.loadScript(url)}
-                onSuccess={(url) => libs.dispatch(libs.pushAction(url))}
-              />
-            </AddJSLibraryButton>
-          }
-        >
-          {this.children.libs.getPropertyView()}
-        </BaseSection>
-      </JSLibraryWrapper>
-    );
-  }
-}
+export { PreloadComp } from "./preLoadComp/preLoadComp"; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/ACTION_SYSTEM.md b/client/packages/lowcoder/src/comps/comps/preLoadComp/ACTION_SYSTEM.md
new file mode 100644
index 0000000000..ec492ff105
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/ACTION_SYSTEM.md
@@ -0,0 +1,203 @@
+# Scalable Action System
+
+The `ActionInputSection` component has been refactored to use a scalable, configuration-driven approach that makes it easy to add new actions without modifying the main component logic.
+
+## Architecture
+
+### Core Components
+
+1. **ActionConfig Interface** - Defines the structure of an action
+2. **ActionRegistry** - Central registry of all available actions
+3. **ActionInputSection** - Main UI component that renders based on action configurations
+
+### Key Benefits
+
+- **Scalable**: Add new actions by simply adding a configuration object
+- **Type Safe**: Full TypeScript support with proper interfaces
+- **Validation**: Built-in input validation support
+- **Categorized**: Actions are organized into logical categories
+- **Flexible**: Support for different input types and requirements
+
+## Adding New Actions
+
+### Step 1: Define the Action Configuration
+
+Add a new action configuration in `actionConfigs.ts`:
+
+```typescript
+const myNewAction: ActionConfig = {
+  key: 'my-new-action',
+  label: 'My New Action',
+  category: 'my-category',
+  requiresEditorComponentSelection: true, // if it needs a component from editor
+  requiresInput: true, // if it needs user input
+  inputPlaceholder: 'Enter your input here',
+  inputType: 'text', // 'text', 'number', 'textarea', 'json'
+  validation: (value: string) => {
+    if (!value.trim()) return 'Input is required';
+    return null; // null means no error
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, actionValue, editorState } = params;
+    
+    // Your action logic here
+    console.log('Executing my new action:', selectedEditorComponent, actionValue);
+    
+    // Show success message
+    message.success('Action executed successfully!');
+  }
+};
+```
+
+### Step 2: Add to Category
+
+Add your action to an existing category or create a new one:
+
+```typescript
+export const actionCategories: ActionCategory[] = [
+  // ... existing categories
+  {
+    key: 'my-category',
+    label: 'My Category',
+    actions: [myNewAction]
+  }
+];
+```
+
+### Step 3: Register the Action
+
+The action is automatically registered when added to a category, but you can also register it manually:
+
+```typescript
+actionRegistry.set('my-new-action', myNewAction);
+```
+
+## Action Configuration Options
+
+### Basic Properties
+
+- `key`: Unique identifier for the action
+- `label`: Display name in the UI
+- `category`: Category for organization
+
+### UI Requirements
+
+- `requiresComponentSelection`: Shows component dropdown for adding new components
+- `requiresEditorComponentSelection`: Shows dropdown of existing components in editor
+- `requiresInput`: Shows input field for user data
+- `inputPlaceholder`: Placeholder text for input field
+- `inputType`: Type of input ('text', 'number', 'textarea', 'json')
+
+### Validation
+
+- `validation`: Function that returns error message or null
+
+### Execution
+
+- `execute`: Async function that performs the actual action
+
+## Example Actions
+
+### Component Management
+- **Add Component**: Places new components in the editor
+- **Move Component**: Moves existing components
+- **Delete Component**: Removes components from editor
+- **Resize Component**: Changes component dimensions
+
+### Component Configuration
+- **Configure Component**: Updates component properties
+
+### Layout
+- **Change Layout**: Modifies the overall layout type
+
+### Data
+- **Bind Data**: Connects data sources to components
+
+### Events
+- **Add Event Handler**: Attaches event handlers to components
+
+### Styling
+- **Apply Style**: Applies CSS styles to components
+
+## Input Types
+
+### Text Input
+```typescript
+inputType: 'text'
+```
+
+### Number Input
+```typescript
+inputType: 'number'
+```
+
+### Textarea
+```typescript
+inputType: 'textarea'
+```
+
+### JSON Input
+```typescript
+inputType: 'json'
+validation: (value: string) => {
+  try {
+    JSON.parse(value);
+    return null;
+  } catch {
+    return 'Invalid JSON format';
+  }
+}
+```
+
+## Validation Examples
+
+### Required Field
+```typescript
+validation: (value: string) => {
+  if (!value.trim()) return 'This field is required';
+  return null;
+}
+```
+
+### Numeric Range
+```typescript
+validation: (value: string) => {
+  const num = parseInt(value);
+  if (isNaN(num) || num < 1 || num > 100) {
+    return 'Please enter a number between 1 and 100';
+  }
+  return null;
+}
+```
+
+### Custom Format
+```typescript
+validation: (value: string) => {
+  const pattern = /^[A-Za-z0-9]+$/;
+  if (!pattern.test(value)) {
+    return 'Only alphanumeric characters are allowed';
+  }
+  return null;
+}
+```
+
+## Best Practices
+
+1. **Use Descriptive Keys**: Make action keys self-documenting
+2. **Provide Clear Labels**: Use user-friendly action names
+3. **Validate Input**: Always validate user input when required
+4. **Handle Errors**: Provide meaningful error messages
+5. **Show Feedback**: Use success/error messages to inform users
+6. **Group Related Actions**: Use categories to organize actions logically
+
+## Migration from Old System
+
+The old hardcoded action handling has been replaced with the configuration-driven approach. All existing functionality is preserved, but now it's much easier to extend and maintain.
+
+## Future Enhancements
+
+- **Action History**: Track executed actions for undo/redo
+- **Action Templates**: Predefined action configurations
+- **Custom Validators**: Reusable validation functions
+- **Action Dependencies**: Actions that depend on other actions
+- **Batch Actions**: Execute multiple actions together 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/README.md b/client/packages/lowcoder/src/comps/comps/preLoadComp/README.md
new file mode 100644
index 0000000000..646d50faa7
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/README.md
@@ -0,0 +1,98 @@
+# PreLoadComp Module
+
+This module has been restructured for maximum manageability and reusability. The original monolithic `preLoadComp.tsx` file has been broken down into logical, focused components.
+
+## File Structure
+
+```
+preLoadComp/
+├── index.ts                 # Main exports
+├── preLoadComp.tsx          # Main PreloadComp class
+├── types.ts                 # TypeScript interfaces and types
+├── styled.tsx               # Styled components
+├── utils.ts                 # Utility functions
+├── components.tsx           # Component classes (LibsComp, ScriptComp, etc.)
+├── tabPanes.tsx             # Tab pane components
+├── preloadConfigModal.tsx   # Modal configuration component
+├── actionInputSection.tsx   # Component placement functionality
+├── actionConfigs.ts         # Action configurations (scalable action system)
+├── ACTION_SYSTEM.md         # Action system documentation
+└── README.md               # This documentation
+```
+
+## Components
+
+### Core Components
+- **`preLoadComp.tsx`**: Main `PreloadComp` class that orchestrates all functionality
+- **`components.tsx`**: Contains all component classes (`LibsComp`, `ScriptComp`, `CSSComp`, `GlobalCSSComp`)
+
+### UI Components
+- **`preloadConfigModal.tsx`**: Modal with tabs for JavaScript, CSS, and Global CSS
+- **`tabPanes.tsx`**: Individual tab pane components for JavaScript and CSS
+- **`actionInputSection.tsx`**: Component placement functionality with dropdowns
+
+### Supporting Files
+- **`types.ts`**: TypeScript interfaces and enums
+- **`styled.tsx`**: Styled-components for consistent styling
+- **`utils.ts`**: Utility functions for component generation and script execution
+- **`index.ts`**: Centralized exports for easy importing
+
+## Key Features
+
+### Component Placement
+The `ActionInputSection` component provides:
+- Dropdown selection of available components
+- Categorized component listing
+- Automatic component placement in the editor
+- Success/error feedback
+
+### Scalable Action System
+The action system has been completely refactored to be configuration-driven:
+- **Easy to Extend**: Add new actions by simply adding configuration objects
+- **Type Safe**: Full TypeScript support with proper interfaces
+- **Validation**: Built-in input validation support
+- **Categorized**: Actions organized into logical categories
+- **Flexible**: Support for different input types and requirements
+
+See `ACTION_SYSTEM.md` for detailed documentation on adding new actions.
+
+### Script and Style Management
+- JavaScript library loading and management
+- CSS and Global CSS application
+- Script execution in host or sandbox environment
+
+### Modular Architecture
+- **Separation of Concerns**: Each file has a single responsibility
+- **Reusability**: Components can be imported and used independently
+- **Maintainability**: Easy to locate and modify specific functionality
+- **Type Safety**: Comprehensive TypeScript interfaces
+
+## Usage
+
+```typescript
+// Import the main component
+import { PreloadComp } from "./preLoadComp";
+
+// Import specific components
+import { ActionInputSection } from "./preLoadComp/actionInputSection";
+import { PreloadConfigModal } from "./preLoadComp/preloadConfigModal";
+
+// Import utilities
+import { generateComponentActionItems } from "./preLoadComp/utils";
+
+// Import types
+import type { ExternalPreload, RunAndClearable } from "./preLoadComp/types";
+```
+
+## Benefits of Restructuring
+
+1. **Maintainability**: Each file is focused and easier to understand
+2. **Reusability**: Components can be used independently
+3. **Testing**: Individual components can be tested in isolation
+4. **Collaboration**: Multiple developers can work on different parts simultaneously
+5. **Code Organization**: Clear separation of concerns
+6. **Type Safety**: Better TypeScript support with dedicated type files
+
+## Migration Notes
+
+The original `preLoadComp.tsx` file now simply exports from the new modular structure, ensuring backward compatibility while providing the benefits of the new organization. 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
new file mode 100644
index 0000000000..d6bfb60bd0
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
@@ -0,0 +1,620 @@
+import { message } from "antd";
+import { genRandomKey } from "comps/utils/idGenerator";
+import { parseCompType } from "comps/utils/remote";
+import { defaultLayout, GridItemDataType } from "comps/comps/gridItemComp";
+import { addMapChildAction } from "comps/generators/sameTypeMap";
+import { uiCompRegistry, UICompType } from "comps/uiCompRegistry";
+import { ActionConfig, ActionCategory, ActionExecuteParams } from "./types";
+import { 
+    multiChangeAction, 
+    wrapActionExtraInfo, 
+    changeValueAction, 
+    wrapChildAction, 
+    deleteCompAction 
+} from "lowcoder-core";
+
+// Component Management Actions
+const addComponentAction: ActionConfig = {
+  key: 'add-components',
+  label: 'Place a component',
+  category: 'component-management',
+  requiresComponentSelection: true,
+  requiresInput: false,
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedComponent, editorState } = params;
+    
+    if (!selectedComponent || !editorState) {
+      message.error('Component and editor state are required');
+      return;
+    }
+
+    try {
+      // Get the UI component container
+      const uiComp = editorState.getUIComp();
+      const container = uiComp.getComp();
+      
+      if (!container) {
+        message.error('No container available to add component');
+        return;
+      }
+
+      // Get the simple container (the actual grid container)
+      const simpleContainer = container.realSimpleContainer();
+      if (!simpleContainer) {
+        message.error('No grid container available');
+        return;
+      }
+
+      // Generate component name and key
+      const nameGenerator = editorState.getNameGenerator();
+      const compInfo = parseCompType(selectedComponent);
+      const compName = nameGenerator.genItemName(compInfo.compName);
+      const key = genRandomKey();
+
+      // Get component manifest and default data
+      const manifest = uiCompRegistry[selectedComponent];
+      let defaultDataFn = undefined;
+
+      if (manifest?.lazyLoad) {
+        const { defaultDataFnName, defaultDataFnPath } = manifest;
+        if (defaultDataFnName && defaultDataFnPath) {
+          const module = await import(`../../${defaultDataFnPath}.tsx`);
+          defaultDataFn = module[defaultDataFnName];
+        }
+      } else if (!compInfo.isRemote) {
+        defaultDataFn = manifest?.defaultDataFn;
+      }
+
+      // Create component data
+      const widgetValue: GridItemDataType = {
+        compType: selectedComponent,
+        name: compName,
+        comp: defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined,
+      };
+
+      // Get current layout and calculate position
+      const currentLayout = simpleContainer.children.layout.getView();
+      const layoutInfo = manifest?.layoutInfo || defaultLayout(selectedComponent as UICompType);
+      
+      let itemPos = 0;
+      if (Object.keys(currentLayout).length > 0) {
+        itemPos = Math.min(...Object.values(currentLayout).map((l: any) => l.pos || 0)) - 1;
+      }
+
+      const layoutItem = {
+        i: key,
+        x: 0,
+        y: 0,
+        w: layoutInfo.w || 6,
+        h: layoutInfo.h || 5,
+        pos: itemPos,
+        isDragging: false,
+      };
+
+      // Dispatch the action to add the component
+      simpleContainer.dispatch(
+        wrapActionExtraInfo(
+          multiChangeAction({
+            layout: changeValueAction(
+              {
+                ...currentLayout,
+                [key]: layoutItem,
+              },
+              true
+            ),
+            items: addMapChildAction(key, widgetValue),
+          }),
+          { compInfos: [{ compName: compName, compType: selectedComponent, type: "add" }] }
+        )
+      );
+
+      editorState.setSelectedCompNames(new Set([compName]), "addComp");
+      
+      message.success(`Component "${manifest?.name || selectedComponent}" added successfully!`);
+    } catch (error) {
+      console.error('Error adding component:', error);
+      message.error('Failed to add component. Please try again.');
+    }
+  }
+};
+
+const moveComponentAction: ActionConfig = {
+  key: 'move-components',
+  label: 'Move a component',
+  category: 'component-management',
+  requiresEditorComponentSelection: true,
+  requiresInput: true,
+  inputPlaceholder: 'Enter move parameters (e.g., x:100, y:200)',
+  inputType: 'text',
+  validation: (value: string) => {
+    if (!value.trim()) return 'Move parameters are required';
+    
+    // Parse the input to validate format
+    const params = value.toLowerCase().split(',').map(p => p.trim());
+    for (const param of params) {
+      if (!param.includes(':')) {
+        return 'Invalid format. Use "x:value, y:value"';
+      }
+      const [key, val] = param.split(':').map(s => s.trim());
+      if (!['x', 'y'].includes(key)) {
+        return 'Only x and y parameters are supported';
+      }
+      const num = parseInt(val);
+      if (isNaN(num) || num < 0) {
+        return `${key} must be a positive number`;
+      }
+    }
+    return null;
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, actionValue, editorState } = params;
+
+    if (!selectedEditorComponent || !editorState) {
+      message.error('Component and editor state are required');
+      return;
+    }
+
+    try {
+      // Parse move parameters
+      const moveParams: { x?: number; y?: number } = {};
+      const params = actionValue.toLowerCase().split(',').map(p => p.trim());
+      
+      for (const param of params) {
+        const [key, val] = param.split(':').map(s => s.trim());
+        if (['x', 'y'].includes(key)) {
+          moveParams[key as 'x' | 'y'] = parseInt(val);
+        }
+      }
+
+      if (!moveParams.x && !moveParams.y) {
+        message.error('No valid move parameters provided');
+        return;
+      }
+
+      // Get the UI component container
+      const uiComp = editorState.getUIComp();
+      const container = uiComp.getComp();
+      
+      if (!container) {
+        message.error('No container available');
+        return;
+      }
+
+      // Get the simple container (the actual grid container)
+      const simpleContainer = container.realSimpleContainer();
+      if (!simpleContainer) {
+        message.error('No grid container available');
+        return;
+      }
+
+      // Get current layout and items
+      const currentLayout = simpleContainer.children.layout.getView();
+      const items = simpleContainer.children.items.children;
+
+      // Find the component by name and get its key
+      let componentKey: string | null = null;
+      for (const [key, item] of Object.entries(items)) {
+        if ((item as any).children.name.getView() === selectedEditorComponent) {
+          componentKey = key;
+          break;
+        }
+      }
+
+      if (!componentKey || !currentLayout[componentKey]) {
+        message.error(`Component "${selectedEditorComponent}" not found in layout`);
+        return;
+      }
+
+      const currentLayoutItem = currentLayout[componentKey];
+
+      const newLayoutItem = {
+        ...currentLayoutItem,
+        x: moveParams.x !== undefined ? moveParams.x : currentLayoutItem.x,
+        y: moveParams.y !== undefined ? moveParams.y : currentLayoutItem.y,
+      };
+
+      const newLayout = {
+        ...currentLayout,
+        [componentKey]: newLayoutItem,
+      };
+
+      // Dispatch the action to update the layout
+      simpleContainer.dispatch(
+        wrapActionExtraInfo(
+          multiChangeAction({
+            layout: changeValueAction(newLayout, true),
+          }),
+          { 
+            compInfos: [{ 
+              compName: selectedEditorComponent, 
+              compType: (items[componentKey] as any).children.compType.getView(), 
+              type: "layout" 
+            }] 
+          }
+        )
+      );
+
+      editorState.setSelectedCompNames(new Set([selectedEditorComponent]), "moveComp");
+      
+      const moveDescription = [];
+      if (moveParams.x !== undefined) moveDescription.push(`x: ${moveParams.x}`);
+      if (moveParams.y !== undefined) moveDescription.push(`y: ${moveParams.y}`);
+      
+      message.success(`Component "${selectedEditorComponent}" moved to ${moveDescription.join(', ')}`);
+    } catch (error) {
+      console.error('Error moving component:', error);
+      message.error('Failed to move component. Please try again.');
+    }
+  }
+};
+
+const deleteComponentAction: ActionConfig = {
+  key: 'delete-components',
+  label: 'Delete a component',
+  category: 'component-management',
+  requiresEditorComponentSelection: true,
+  requiresInput: false,
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, editorState } = params;
+    
+    if (!selectedEditorComponent || !editorState) {
+      message.error('Component and editor state are required');
+      return;
+    }
+
+    try {
+      // Get the UI component container
+      const uiComp = editorState.getUIComp();
+      const container = uiComp.getComp();
+      
+      if (!container) {
+        message.error('No container available');
+        return;
+      }
+
+      // Get the simple container (the actual grid container)
+      const simpleContainer = container.realSimpleContainer();
+      if (!simpleContainer) {
+        message.error('No grid container available');
+        return;
+      }
+
+      // Get current layout and items
+      const currentLayout = simpleContainer.children.layout.getView();
+      const items = simpleContainer.children.items.children;
+
+      // Find the component by name and get its key
+      let componentKey: string | null = null;
+      let componentType: string | null = null;
+      for (const [key, item] of Object.entries(items)) {
+        if ((item as any).children.name.getView() === selectedEditorComponent) {
+          componentKey = key;
+          componentType = (item as any).children.compType.getView();
+          break;
+        }
+      }
+
+      if (!componentKey || !currentLayout[componentKey]) {
+        message.error(`Component "${selectedEditorComponent}" not found in layout`);
+        return;
+      }
+
+      // Create new layout without the component
+      const newLayout = { ...currentLayout };
+      delete newLayout[componentKey];
+
+      // Dispatch the action to remove the component
+      simpleContainer.dispatch(
+        wrapActionExtraInfo(
+          multiChangeAction({
+            layout: changeValueAction(newLayout, true),
+            items: wrapChildAction(componentKey, deleteCompAction()),
+          }),
+          { 
+            compInfos: [{ 
+              compName: selectedEditorComponent, 
+              compType: componentType || 'unknown', 
+              type: "delete" 
+            }] 
+          }
+        )
+      );
+
+      editorState.setSelectedCompNames(new Set(), "deleteComp");
+      
+      message.success(`Component "${selectedEditorComponent}" deleted successfully`);
+    } catch (error) {
+      console.error('Error deleting component:', error);
+      message.error('Failed to delete component. Please try again.');
+    }
+  }
+};
+
+const resizeComponentAction: ActionConfig = {
+  key: 'resize-components',
+  label: 'Resize a component',
+  category: 'component-management',
+  requiresEditorComponentSelection: true,
+  requiresInput: true,
+  inputPlaceholder: 'Enter resize parameters (e.g., w:8, h:6)',
+  inputType: 'text',
+  validation: (value: string) => {
+    if (!value.trim()) return 'Resize parameters are required';
+    
+    // Parse the input to validate format
+    const params = value.toLowerCase().split(',').map(p => p.trim());
+    for (const param of params) {
+      if (!param.includes(':')) {
+        return 'Invalid format. Use "w:value, h:value"';
+      }
+      const [key, val] = param.split(':').map(s => s.trim());
+      if (!['w', 'h'].includes(key)) {
+        return 'Only w (width) and h (height) parameters are supported';
+      }
+      const num = parseInt(val);
+      if (isNaN(num) || num < 1) {
+        return `${key} must be a positive number greater than 0`;
+      }
+    }
+    return null;
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, actionValue, editorState } = params;
+
+    if (!selectedEditorComponent || !editorState) {
+      message.error('Component and editor state are required');
+      return;
+    }
+
+    try {
+      // Parse resize parameters
+      const resizeParams: { w?: number; h?: number } = {};
+      const params = actionValue.toLowerCase().split(',').map(p => p.trim());
+      
+      for (const param of params) {
+        const [key, val] = param.split(':').map(s => s.trim());
+        if (['w', 'h'].includes(key)) {
+          resizeParams[key as 'w' | 'h'] = parseInt(val);
+        }
+      }
+
+      if (!resizeParams.w && !resizeParams.h) {
+        message.error('No valid resize parameters provided');
+        return;
+      }
+
+      // Get the UI component container
+      const uiComp = editorState.getUIComp();
+      const container = uiComp.getComp();
+      
+      if (!container) {
+        message.error('No container available');
+        return;
+      }
+
+      // Get the simple container (the actual grid container)
+      const simpleContainer = container.realSimpleContainer();
+      if (!simpleContainer) {
+        message.error('No grid container available');
+        return;
+      }
+
+      // Get current layout and items
+      const currentLayout = simpleContainer.children.layout.getView();
+      const items = simpleContainer.children.items.children;
+
+      // Find the component by name and get its key
+      let componentKey: string | null = null;
+      for (const [key, item] of Object.entries(items)) {
+        if ((item as any).children.name.getView() === selectedEditorComponent) {
+          componentKey = key;
+          break;
+        }
+      }
+
+      if (!componentKey || !currentLayout[componentKey]) {
+        message.error(`Component "${selectedEditorComponent}" not found in layout`);
+        return;
+      }
+
+      const currentLayoutItem = currentLayout[componentKey];
+      
+      const newLayoutItem = {
+        ...currentLayoutItem,
+        w: resizeParams.w !== undefined ? resizeParams.w : currentLayoutItem.w,
+        h: resizeParams.h !== undefined ? resizeParams.h : currentLayoutItem.h,
+      };
+
+      const newLayout = {
+        ...currentLayout,
+        [componentKey]: newLayoutItem,
+      };
+
+      // Dispatch the action to update the layout
+      simpleContainer.dispatch(
+        wrapActionExtraInfo(
+          multiChangeAction({
+            layout: changeValueAction(newLayout, true),
+          }),
+          { 
+            compInfos: [{ 
+              compName: selectedEditorComponent, 
+              compType: (items[componentKey] as any).children.compType.getView(), 
+              type: "layout" 
+            }] 
+          }
+        )
+      );
+
+      editorState.setSelectedCompNames(new Set([selectedEditorComponent]), "resizeComp");
+      
+      const resizeDescription = [];
+      if (resizeParams.w !== undefined) resizeDescription.push(`width: ${resizeParams.w}`);
+      if (resizeParams.h !== undefined) resizeDescription.push(`height: ${resizeParams.h}`);
+      
+      message.success(`Component "${selectedEditorComponent}" resized to ${resizeDescription.join(', ')}`);
+    } catch (error) {
+      console.error('Error resizing component:', error);
+      message.error('Failed to resize component. Please try again.');
+    }
+  }
+};
+
+// Component Configuration Actions
+const configureComponentAction: ActionConfig = {
+  key: 'configure-components',
+  label: 'Configure a component',
+  category: 'component-configuration',
+  requiresEditorComponentSelection: true,
+  requiresInput: true,
+  inputPlaceholder: 'Enter configuration (JSON format)',
+  inputType: 'json',
+  validation: (value: string) => {
+    if (!value.trim()) return 'Configuration is required';
+    try {
+      JSON.parse(value);
+      return null;
+    } catch {
+      return 'Invalid JSON format';
+    }
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, actionValue } = params;
+    
+    try {
+      const config = JSON.parse(actionValue);
+      console.log('Configuring component:', selectedEditorComponent, 'with config:', config);
+      message.info(`Configure action for component "${selectedEditorComponent}"`);
+      
+      // TODO: Implement actual configuration logic
+    } catch (error) {
+      message.error('Invalid configuration format');
+    }
+  }
+};
+
+// Layout Actions
+const changeLayoutAction: ActionConfig = {
+  key: 'change-layout',
+  label: 'Change layout',
+  category: 'layout',
+  requiresInput: true,
+  inputPlaceholder: 'Enter layout type (grid, flex, absolute)',
+  inputType: 'text',
+  execute: async (params: ActionExecuteParams) => {
+    const { actionValue } = params;
+    
+    console.log('Changing layout to:', actionValue);
+    message.info(`Layout changed to: ${actionValue}`);
+    
+    // TODO: Implement actual layout change logic
+  }
+};
+
+// Event Actions
+const addEventHandlerAction: ActionConfig = {
+  key: 'add-event-handler',
+  label: 'Add event handler',
+  category: 'events',
+  requiresEditorComponentSelection: true,
+  requiresInput: true,
+  inputPlaceholder: 'Enter event handler code (JavaScript)',
+  inputType: 'textarea',
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, actionValue } = params;
+    
+    console.log('Adding event handler to component:', selectedEditorComponent, 'with code:', actionValue);
+    message.info(`Event handler added to component "${selectedEditorComponent}"`);
+    
+    // TODO: Implement actual event handler logic
+  }
+};
+
+// Style Actions
+const applyStyleAction: ActionConfig = {
+  key: 'apply-style',
+  label: 'Apply style to component',
+  category: 'styling',
+  requiresEditorComponentSelection: true,
+  requiresInput: true,
+  inputPlaceholder: 'Enter CSS styles (JSON format)',
+  inputType: 'json',
+  validation: (value: string) => {
+    if (!value.trim()) return 'Styles are required';
+    try {
+      JSON.parse(value);
+      return null;
+    } catch {
+      return 'Invalid JSON format';
+    }
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, actionValue } = params;
+    
+    try {
+      const styles = JSON.parse(actionValue);
+      console.log('Applying styles to component:', selectedEditorComponent, 'with styles:', styles);
+      message.info(`Styles applied to component "${selectedEditorComponent}"`);
+      
+      // TODO: Implement actual style application logic
+    } catch (error) {
+      message.error('Invalid style format');
+    }
+  }
+};
+
+export const actionCategories: ActionCategory[] = [
+  {
+    key: 'component-management',
+    label: 'Component Management',
+    actions: [addComponentAction, moveComponentAction, deleteComponentAction, resizeComponentAction]
+  },
+  {
+    key: 'component-configuration',
+    label: 'Component Configuration',
+    actions: [configureComponentAction]
+  },
+  {
+    key: 'layout',
+    label: 'Layout',
+    actions: [changeLayoutAction]
+  },
+  {
+    key: 'events',
+    label: 'Events',
+    actions: [addEventHandlerAction]
+  },
+  {
+    key: 'styling',
+    label: 'Styling',
+    actions: [applyStyleAction]
+  }
+];
+
+export const actionRegistry = new Map<string, ActionConfig>();
+actionCategories.forEach(category => {
+  category.actions.forEach(action => {
+    actionRegistry.set(action.key, action);
+  });
+});
+
+export const getAllActionItems = () => {
+    return actionCategories.flatMap(category => {
+      if (category.actions.length === 1) {
+        const action = category.actions[0];
+        return [{
+          label: action.label,
+          key: action.key
+        }];
+      }
+  
+      return [{
+        label: category.label,
+        key: `category-${category.key}`,
+        children: category.actions.map(action => ({
+          label: action.label,
+          key: action.key
+        }))
+      }];
+    });
+  };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
new file mode 100644
index 0000000000..148dac1674
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
@@ -0,0 +1,315 @@
+import React, { 
+  useContext, 
+  useState, 
+  useCallback, 
+  useRef, 
+  useMemo 
+} from "react";
+import { default as Button } from "antd/es/button";
+import { default as Input } from "antd/es/input";
+import { default as Menu } from "antd/es/menu";
+import { default as Space } from "antd/es/space";
+import { default as Flex } from "antd/es/flex";
+import type { InputRef } from 'antd';
+import { default as DownOutlined } from "@ant-design/icons/DownOutlined";
+import { BaseSection } from "lowcoder-design";
+import { EditorContext } from "comps/editorState";
+import { message } from "antd";
+import { CustomDropdown } from "./styled";
+import { generateComponentActionItems, getComponentCategories } from "./utils";
+import { actionRegistry, getAllActionItems } from "./actionConfigs";
+
+export function ActionInputSection() {
+  const [actionValue, setActionValue] = useState<string>("");
+  const [selectedActionKey, setSelectedActionKey] = useState<string | null>(null);
+  const [placeholderText, setPlaceholderText] = useState<string>("");
+  const [selectedComponent, setSelectedComponent] = useState<string | null>(null);
+  const [showComponentDropdown, setShowComponentDropdown] = useState<boolean>(false);
+  const [showEditorComponentsDropdown, setShowEditorComponentsDropdown] = useState<boolean>(false);
+  const [selectedEditorComponent, setSelectedEditorComponent] = useState<string | null>(null);
+  const [validationError, setValidationError] = useState<string | null>(null);
+  const inputRef = useRef<InputRef>(null);
+  const editorState = useContext(EditorContext);
+
+  const categories = useMemo(() => {
+    return getComponentCategories();
+  }, []);
+
+  const componentActionItems = useMemo(() => {
+    return generateComponentActionItems(categories);
+  }, [categories]);
+
+  const allActionItems = useMemo(() => {
+    return getAllActionItems();
+  }, []);
+
+  const editorComponents = useMemo(() => {
+    if (!editorState) return [];
+    
+    const compInfos = editorState.uiCompInfoList();
+    return compInfos.map(comp => ({
+      label: comp.name,
+      key: comp.name
+    }));
+  }, [editorState]);
+
+  const currentAction = useMemo(() => {
+    return selectedActionKey ? actionRegistry.get(selectedActionKey) : null;
+  }, [selectedActionKey]);
+
+  const handleActionSelection = useCallback((key: string) => {
+    if (key.startsWith('category-')) {
+      return;
+    }
+    
+    setSelectedActionKey(key);
+    setValidationError(null);
+    
+    const action = actionRegistry.get(key);
+    if (!action) {
+      console.warn(`Action not found: ${key}`);
+      return;
+    }
+
+    setShowComponentDropdown(false);
+    setShowEditorComponentsDropdown(false);
+    setSelectedComponent(null);
+    setSelectedEditorComponent(null);
+    setActionValue("");
+
+    if (action.requiresComponentSelection) {
+      setShowComponentDropdown(true);
+      setPlaceholderText("Select a component to add");
+    } else if (action.requiresEditorComponentSelection) {
+      setShowEditorComponentsDropdown(true);
+      setPlaceholderText(`Select a component to ${action.label.toLowerCase()}`);
+    } else if (action.requiresInput) {
+      setPlaceholderText(action.inputPlaceholder || `Enter ${action.label.toLowerCase()} value`);
+    } else {
+      setPlaceholderText(`Execute ${action.label.toLowerCase()}`);
+    }
+  }, []);
+
+  const handleComponentSelection = useCallback((key: string) => {
+    if (key.startsWith('comp-')) {
+      const compName = key.replace('comp-', '');
+      setSelectedComponent(compName);
+      setPlaceholderText(`Configure ${compName} component`);
+    }
+  }, []);
+
+  const handleEditorComponentSelection = useCallback((key: string) => {
+    setSelectedEditorComponent(key);
+    if (currentAction) {
+      setPlaceholderText(`${currentAction.label}`);
+    }
+  }, [currentAction]);
+
+  const validateInput = useCallback((value: string): string | null => {
+    if (!currentAction?.validation) return null;
+    return currentAction.validation(value);
+  }, [currentAction]);
+
+  const handleInputChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
+    const value = e.target.value;
+    setActionValue(value);
+    
+    if (validationError) {
+      setValidationError(null);
+    }
+  }, [validationError]);
+
+  const handleApplyAction = useCallback(async () => {
+    if (!editorState) {
+      message.error('Editor state not available');
+      return;
+    }
+
+    if (!selectedActionKey || !currentAction) {
+      message.error('No action selected');
+      return;
+    }
+
+    if (currentAction.requiresInput && currentAction.validation) {
+      const error = validateInput(actionValue);
+      if (error) {
+        setValidationError(error);
+        message.error(error);
+        return;
+      }
+    }
+
+    if (currentAction.requiresComponentSelection && !selectedComponent) {
+      message.error('Please select a component');
+      return;
+    }
+
+    if (currentAction.requiresEditorComponentSelection && !selectedEditorComponent) {
+      message.error('Please select a component from the editor');
+      return;
+    }
+
+    try {
+      await currentAction.execute({
+        actionKey: selectedActionKey,
+        actionValue,
+        selectedComponent,
+        selectedEditorComponent,
+        editorState
+      });
+
+      // Clear the form on success
+      setActionValue("");
+      setSelectedComponent(null);
+      setSelectedActionKey(null);
+      setShowComponentDropdown(false);
+      setShowEditorComponentsDropdown(false);
+      setSelectedEditorComponent(null);
+      setPlaceholderText("");
+      setValidationError(null);
+
+    } catch (error) {
+      console.error('Error executing action:', error);
+      message.error('Failed to execute action. Please try again.');
+    }
+  }, [
+    selectedActionKey, 
+    actionValue, 
+    selectedComponent, 
+    selectedEditorComponent, 
+    editorState, 
+    currentAction, 
+    validateInput
+  ]);
+
+  const isApplyDisabled = useMemo(() => {
+    if (!selectedActionKey || !currentAction) return true;
+    
+    if (currentAction.requiresComponentSelection && !selectedComponent) return true;
+    if (currentAction.requiresEditorComponentSelection && !selectedEditorComponent) return true;
+    if (currentAction.requiresInput && !actionValue.trim()) return true;
+    
+    return false;
+  }, [selectedActionKey, currentAction, selectedComponent, selectedEditorComponent, actionValue]);
+
+  const shouldShowInput = useMemo(() => {
+    if (!currentAction) return false;
+    return currentAction.requiresInput && (
+      !currentAction.requiresEditorComponentSelection || selectedEditorComponent
+    );
+  }, [currentAction, selectedEditorComponent]);
+
+  return (
+    <BaseSection
+      name="Action Input"
+      width={288}
+      noMargin
+      style={{
+        borderTop: "1px solid #e1e3eb",
+        backgroundColor: "#fff",
+      }}
+    >
+      <div style={{ padding: "16px" }}>
+        <Flex gap="small" vertical>
+          <CustomDropdown
+            placement="bottomLeft"
+            overlayStyle={{ 
+              maxHeight: '400px',
+              overflow: 'auto',
+              zIndex: 9999
+            }}
+            popupRender={() => (
+              <Menu
+                items={allActionItems}
+                onClick={({ key }) => {
+                  handleActionSelection(key);
+                }}
+              />
+            )}
+          >
+            <Button size={"small"}>
+              <Space>
+                {currentAction ? currentAction.label : 'Select Action'} 
+                <DownOutlined />
+              </Space>
+            </Button>
+          </CustomDropdown>
+          
+          {showComponentDropdown && (
+            <CustomDropdown
+              overlayStyle={{ 
+                maxHeight: '400px',
+                overflow: 'auto',
+                zIndex: 9999
+              }}
+              popupRender={() => (
+                <Menu
+                  items={componentActionItems}
+                  onClick={({ key }) => {
+                    handleComponentSelection(key);
+                  }}
+                />
+              )}
+            >
+              <Button size={"small"}>
+                <Space>
+                  {selectedComponent ? selectedComponent : 'Select Component'} 
+                  <DownOutlined />
+                </Space>
+              </Button>
+            </CustomDropdown>
+          )}
+          
+          {showEditorComponentsDropdown && (
+            <CustomDropdown
+              overlayStyle={{ 
+                maxHeight: '400px',
+                overflow: 'auto',
+                zIndex: 9999
+              }}
+              popupRender={() => (
+                <Menu
+                  items={editorComponents}
+                  onClick={({ key }) => {
+                    handleEditorComponentSelection(key);
+                  }}
+                />
+              )}
+            >
+              <Button size={"small"}>
+                <Space>
+                  {selectedEditorComponent ? selectedEditorComponent : 'Select Component'} 
+                  <DownOutlined />
+                </Space>
+              </Button>
+            </CustomDropdown>
+          )}
+          
+          {shouldShowInput && (
+            <Input
+              ref={inputRef}
+              value={actionValue}
+              onChange={handleInputChange}
+              placeholder={placeholderText}
+              status={validationError ? 'error' : undefined}
+            />
+          )}
+          
+          {validationError && (
+            <div style={{ color: '#ff4d4f', fontSize: '12px', marginTop: '-8px' }}>
+              {validationError}
+            </div>
+          )}
+          
+          <Button 
+            type="primary"
+            disabled={isApplyDisabled}
+            onClick={handleApplyAction}
+          >
+            Apply Action
+          </Button>
+        </Flex>
+      </div>
+    </BaseSection>
+  );
+} 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/components.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/components.tsx
new file mode 100644
index 0000000000..28f4629d95
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/components.tsx
@@ -0,0 +1,178 @@
+import {
+  clearMockWindow,
+  clearStyleEval,
+  ConstructorToComp,
+  evalFunc,
+  evalStyle,
+} from "lowcoder-core";
+import { CodeTextControl } from "comps/controls/codeTextControl";
+import SimpleStringControl from "comps/controls/simpleStringControl";
+import { MultiCompBuilder, withPropertyViewFn } from "comps/generators";
+import { list } from "comps/generators/list";
+import { ScrollBar } from "lowcoder-design";
+import { EmptyContent } from "components/EmptyContent";
+import React, { useEffect } from "react";
+import { trans } from "i18n";
+import log from "loglevel";
+import { JSLibraryTree } from "components/JSLibraryTree";
+import { fetchJSLibrary } from "util/jsLibraryUtils";
+import { RunAndClearable } from "./types";
+
+export class LibsCompBase extends list(SimpleStringControl) implements RunAndClearable<string[]> {
+  success: Record<string, boolean> = {};
+  globalVars: Record<string, string[]> = {};
+  externalLibs: string[] = [];
+  runInHost: boolean = false;
+
+  getAllLibs() {
+    return this.externalLibs.concat(this.getView().map((i) => i.getView()));
+  }
+
+  async loadScript(url: string) {
+    if (this.success[url]) {
+      return;
+    }
+    return fetchJSLibrary(url).then((code) => {
+      evalFunc(
+        code,
+        {},
+        {},
+        {
+          scope: "function",
+          disableLimit: this.runInHost,
+          onSetGlobalVars: (v: string) => {
+            this.globalVars[url] = this.globalVars[url] || [];
+            if (!this.globalVars[url].includes(v)) {
+              this.globalVars[url].push(v);
+            }
+          },
+        }
+      );
+      this.success[url] = true;
+    });
+  }
+
+  async loadAllLibs() {
+    const scriptRunners = this.getAllLibs().map((url) =>
+      this.loadScript(url).catch((e) => {
+        log.warn(e);
+      })
+    );
+
+    try {
+      await Promise.all(scriptRunners);
+    } catch (e) {
+      log.warn("load preload libs error:", e);
+    }
+  }
+
+  async run(id: string, externalLibs: string[] = [], runInHost: boolean = false) {
+    this.externalLibs = externalLibs;
+    this.runInHost = runInHost;
+    return this.loadAllLibs();
+  }
+
+  async clear(): Promise<any> {
+    clearMockWindow();
+  }
+}
+
+export const LibsComp = withPropertyViewFn(LibsCompBase, (comp) => {
+  useEffect(() => {
+    comp.loadAllLibs();
+  }, [comp.getView().length]);
+  return (
+    <ScrollBar style={{ height: "295px" }}>
+      {comp.getAllLibs().length === 0 && (
+        <EmptyContent text={trans("preLoad.jsLibraryEmptyContent")} style={{ margin: "0 16px" }} />
+      )}
+      <JSLibraryTree
+        mode={"column"}
+        libs={comp
+          .getView()
+          .map((i) => ({
+            url: i.getView(),
+            deletable: true,
+            exportedAs: comp.globalVars[i.getView()]?.[0],
+          }))
+          .concat(
+            comp.externalLibs.map((l) => ({
+              url: l,
+              deletable: false,
+              exportedAs: comp.globalVars[l]?.[0],
+            }))
+          )}
+        onDelete={(idx) => {
+          comp.dispatch(comp.deleteAction(idx));
+        }}
+      />
+    </ScrollBar>
+  );
+});
+
+export class ScriptComp extends CodeTextControl implements RunAndClearable<string> {
+  runInHost: boolean = false;
+
+  runPreloadScript() {
+    const code = this.getView();
+    if (!code) {
+      return;
+    }
+    // Import runScript from utils to avoid circular dependency
+    const { runScript } = require("./utils");
+    runScript(code, this.runInHost);
+  }
+
+  async run(id: string, externalScript: string = "", runInHost: boolean = false) {
+    this.runInHost = runInHost;
+    if (externalScript) {
+      const { runScript } = require("./utils");
+      runScript(externalScript, runInHost);
+    }
+    this.runPreloadScript();
+  }
+
+  async clear(): Promise<any> {
+    clearMockWindow();
+  }
+}
+
+export class CSSComp extends CodeTextControl implements RunAndClearable<string> {
+  id = "";
+  externalCSS: string = "";
+
+  async applyAllCSS() {
+    const css = this.getView();
+    evalStyle(this.id, [this.externalCSS, css]);
+  }
+
+  async run(id: string, externalCSS: string = "") {
+    this.id = id;
+    this.externalCSS = externalCSS;
+    return this.applyAllCSS();
+  }
+
+  async clear() {
+    clearStyleEval(this.id);
+  }
+}
+
+export class GlobalCSSComp extends CodeTextControl implements RunAndClearable<string> {
+  id = "";
+  externalCSS: string = "";
+
+  async applyAllCSS() {
+    const css = this.getView();
+    evalStyle(this.id, [this.externalCSS, css], true);
+  }
+
+  async run(id: string, externalCSS: string = "") {
+    this.id = id;
+    this.externalCSS = externalCSS;
+    return this.applyAllCSS();
+  }
+
+  async clear() {
+    clearStyleEval(this.id);
+  }
+} 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/index.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/index.ts
new file mode 100644
index 0000000000..15c3985569
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/index.ts
@@ -0,0 +1,43 @@
+// Main component
+export { PreloadComp } from "./preLoadComp";
+
+// Component classes
+export { LibsComp, ScriptComp, CSSComp, GlobalCSSComp } from "./components";
+
+// UI Components
+export { PreloadConfigModal } from "./preloadConfigModal";
+export { ActionInputSection } from "./actionInputSection";
+export { JavaScriptTabPane, CSSTabPane } from "./tabPanes";
+
+// Types and interfaces
+export type { 
+  ExternalPreload, 
+  RunAndClearable, 
+  ComponentActionState,
+  ActionConfig,
+  ActionExecuteParams,
+  ActionCategory,
+  ActionRegistry
+} from "./types";
+export { TabKey } from "./types";
+
+// Action configurations
+export { 
+  actionRegistry, 
+  getAllActionItems, 
+  actionCategories 
+} from "./actionConfigs";
+
+// Styled components
+export { 
+  CustomDropdown, 
+  AddJSLibraryButton, 
+  JSLibraryWrapper 
+} from "./styled";
+
+// Utility functions
+export { 
+  runScript, 
+  generateComponentActionItems, 
+  getComponentCategories 
+} from "./utils"; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/preLoadComp.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/preLoadComp.tsx
new file mode 100644
index 0000000000..be106608c0
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/preLoadComp.tsx
@@ -0,0 +1,69 @@
+import { MultiCompBuilder } from "comps/generators";
+import { BaseSection, PlusIcon } from "lowcoder-design";
+import React from "react";
+import { getGlobalSettings } from "comps/utils/globalSettings";
+import { trans } from "i18n";
+import { JSLibraryModal } from "components/JSLibraryModal";
+import { LibsComp, ScriptComp, CSSComp, GlobalCSSComp } from "./components";
+import { PreloadConfigModal } from "./preloadConfigModal";
+import { AddJSLibraryButton, JSLibraryWrapper } from "./styled";
+import { ActionInputSection } from "./actionInputSection";
+
+const childrenMap = {
+  libs: LibsComp,
+  script: ScriptComp,
+  css: CSSComp,
+  globalCSS: GlobalCSSComp,
+};
+
+const PreloadCompBase = new MultiCompBuilder(childrenMap, () => {})
+  .setPropertyViewFn((children) => <PreloadConfigModal {...children} />)
+  .build();
+
+export class PreloadComp extends PreloadCompBase {
+  async clear() {
+    return Promise.allSettled(Object.values(this.children).map((i) => i.clear()));
+  }
+
+  async run(id: string) {
+    const { orgCommonSettings = {} } = getGlobalSettings();
+    const { preloadCSS, preloadGlobalCSS, preloadJavaScript, preloadLibs, runJavaScriptInHost } = orgCommonSettings;
+    await this.children.css.run(id, preloadCSS || "");
+    await this.children.globalCSS.run('body', preloadGlobalCSS || "");
+    await this.children.libs.run(id, preloadLibs || [], !!runJavaScriptInHost);
+    await this.children.script.run(id, preloadJavaScript || "", !!runJavaScriptInHost);
+  }
+
+  getJSLibraryPropertyView() {
+    const libs = this.children.libs;
+    return (
+      <>
+        <JSLibraryWrapper>
+          <BaseSection
+            name={trans("preLoad.jsLibrary")}
+            width={288}
+            noMargin
+            style={{
+              borderTop: "1px solid #e1e3eb",
+              backgroundColor: "#fff",
+            }}
+            additionalButton={
+              <AddJSLibraryButton>
+                <JSLibraryModal
+                  runInHost={libs.runInHost}
+                  trigger={<PlusIcon height={"46px"} />}
+                  onCheck={(url) => !libs.getAllLibs().includes(url)}
+                  onLoad={(url) => libs.loadScript(url)}
+                  onSuccess={(url) => libs.dispatch(libs.pushAction(url))}
+                />
+              </AddJSLibraryButton>
+            }
+          >
+            {this.children.libs.getPropertyView()}
+          </BaseSection>
+        </JSLibraryWrapper>
+        <ActionInputSection />
+      </>
+    );
+  }
+} 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/preloadConfigModal.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/preloadConfigModal.tsx
new file mode 100644
index 0000000000..b420b240d3
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/preloadConfigModal.tsx
@@ -0,0 +1,60 @@
+import React, { useContext, useState } from "react";
+import { Tabs } from "components/Tabs";
+import { CustomModal } from "lowcoder-design";
+import { ExternalEditorContext } from "util/context/ExternalEditorContext";
+import { trans } from "i18n";
+import { RecordConstructorToComp } from "lowcoder-core";
+import { TabKey } from "./types";
+import { JavaScriptTabPane, CSSTabPane } from "./tabPanes";
+import { ScriptComp, CSSComp, GlobalCSSComp } from "./components";
+
+type ChildrenInstance = RecordConstructorToComp<{
+  libs: any;
+  script: typeof ScriptComp;
+  css: typeof CSSComp;
+  globalCSS: typeof GlobalCSSComp;
+}>;
+
+export function PreloadConfigModal(props: ChildrenInstance) {
+  const [activeKey, setActiveKey] = useState(TabKey.JavaScript);
+  const { showScriptsAndStyleModal, changeExternalState } = useContext(ExternalEditorContext);
+  
+  const tabItems = [
+    {
+      key: TabKey.JavaScript,
+      label: 'JavaScript',
+      children: <JavaScriptTabPane comp={props.script} />
+    },
+    {
+      key: TabKey.CSS,
+      label: 'CSS',
+      children: <CSSTabPane comp={props.css} />
+    },
+    {
+      key: TabKey.GLOBAL_CSS,
+      label: 'Global CSS',
+      children: <CSSTabPane comp={props.globalCSS} isGlobal />
+    },
+  ];
+
+  return (
+    <CustomModal
+      draggable
+      mask={activeKey !== TabKey.CSS}
+      open={showScriptsAndStyleModal}
+      title={trans("preLoad.scriptsAndStyles")}
+      destroyOnHidden
+      onCancel={() => changeExternalState?.({ showScriptsAndStyleModal: false })}
+      showOkButton={false}
+      showCancelButton={false}
+      width="600px"
+    >
+      <Tabs
+        onChange={(k) => setActiveKey(k as TabKey)}
+        style={{ marginBottom: 8, marginTop: 4 }}
+        activeKey={activeKey}
+        items={tabItems}
+      />
+    </CustomModal>
+  );
+} 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/styled.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/styled.tsx
new file mode 100644
index 0000000000..211115e996
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/styled.tsx
@@ -0,0 +1,29 @@
+import styled from "styled-components";
+import { default as Dropdown } from "antd/es/dropdown";
+
+export const CustomDropdown = styled(Dropdown)`
+  .ant-dropdown-menu-item-icon {
+    width: 14px !important;
+    height: 14px !important; 
+    max-width: 14px !important;
+  }
+`;
+
+export const AddJSLibraryButton = styled.div`
+  cursor: pointer;
+  margin-right: 16px;
+
+  g g {
+    stroke: #8b8fa3;
+  }
+
+  &:hover {
+    g g {
+      stroke: #222222;
+    }
+  }
+`;
+
+export const JSLibraryWrapper = styled.div`
+  position: relative;
+`; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/tabPanes.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/tabPanes.tsx
new file mode 100644
index 0000000000..a1229a96dc
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/tabPanes.tsx
@@ -0,0 +1,46 @@
+import { HelpText } from "components/HelpText";
+import React, { useEffect } from "react";
+import { trans } from "i18n";
+import { ConstructorToComp } from "lowcoder-core";
+import { ScriptComp, CSSComp } from "./components";
+
+export function JavaScriptTabPane(props: { comp: ConstructorToComp<typeof ScriptComp> }) {
+  useEffect(() => {
+    props.comp.runPreloadScript();
+  }, [props.comp]);
+
+  const codePlaceholder = `window.name = 'Tom';\nwindow.greet = () => "hello world";`;
+
+  return (
+    <>
+      <HelpText style={{ marginBottom: 20 }}>{trans("preLoad.jsHelpText")}</HelpText>
+      {props.comp.propertyView({
+        expandable: false,
+        styleName: "window",
+        codeType: "Function",
+        language: "javascript",
+        placeholder: codePlaceholder,
+      })}
+    </>
+  );
+}
+
+export function CSSTabPane(props: { comp: CSSComp, isGlobal?: boolean }) {
+  useEffect(() => {
+    props.comp.applyAllCSS();
+  }, [props.comp]);
+
+  const codePlaceholder = `.top-header {\n  background-color: red; \n}`;
+
+  return (
+    <>
+      <HelpText style={{ marginBottom: 20 }}>{trans("preLoad.cssHelpText")}</HelpText>
+      {props.comp.propertyView({
+        expandable: false,
+        placeholder: codePlaceholder,
+        styleName: "window",
+        language: "css",
+      })}
+    </>
+  );
+} 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
new file mode 100644
index 0000000000..7e84ab1da2
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
@@ -0,0 +1,59 @@
+export interface ExternalPreload {
+  css?: string;
+  libs?: string[];
+  script?: string;
+  runJavaScriptInHost?: boolean;
+}
+
+export interface RunAndClearable<T> {
+  run(id: string, externalPreload?: T): Promise<any>;
+  clear(): Promise<any>;
+}
+
+export enum TabKey {
+  JavaScript = "js",
+  CSS = "css",
+  GLOBAL_CSS = "global_css",
+}
+
+export interface ComponentActionState {
+  actionValue: string;
+  selectedActionKey: string | null;
+  placeholderText: string;
+  selectedComponent: string | null;
+  showComponentDropdown: boolean;
+  showEditorComponentsDropdown: boolean;
+  selectedEditorComponent: string | null;
+}
+
+export interface ActionConfig {
+  key: string;
+  label: string;
+  category?: string;
+  requiresComponentSelection?: boolean;
+  requiresEditorComponentSelection?: boolean;
+  requiresInput?: boolean;
+  inputPlaceholder?: string;
+  inputType?: 'text' | 'number' | 'textarea' | 'json';
+  validation?: (value: string) => string | null; 
+  execute: (params: ActionExecuteParams) => Promise<void>;
+}
+
+export interface ActionExecuteParams {
+  actionKey: string;
+  actionValue: string;
+  selectedComponent: string | null;
+  selectedEditorComponent: string | null;
+  editorState: any;
+}
+
+export interface ActionCategory {
+  key: string;
+  label: string;
+  actions: ActionConfig[];
+}
+
+export interface ActionRegistry {
+  categories: ActionCategory[];
+  actions: Map<string, ActionConfig>;
+} 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
new file mode 100644
index 0000000000..86625db0d5
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
@@ -0,0 +1,55 @@
+import { evalFunc } from "lowcoder-core";
+import { runScriptInHost } from "util/commonUtils";
+import log from "loglevel";
+import { UICompCategory, UICompManifest, uiCompCategoryNames, uiCompRegistry } from "comps/uiCompRegistry";
+import { MenuProps } from "antd/es/menu";
+import React from "react";
+
+export function runScript(code: string, inHost?: boolean) {
+  if (inHost) {
+    runScriptInHost(code);
+    return;
+  }
+  try {
+    evalFunc(code, {}, {});
+  } catch (e) {
+    log.error(e);
+  }
+}
+
+export function generateComponentActionItems(categories: Record<string, [string, UICompManifest][]>) {
+  const componentItems: MenuProps['items'] = [];
+  
+  Object.entries(categories).forEach(([categoryKey, components]) => {
+    if (components.length > 0) {
+      componentItems.push({
+        label: uiCompCategoryNames[categoryKey as UICompCategory],
+        key: `category-${categoryKey}`,
+        disabled: true,
+        style: { fontWeight: 'bold', color: '#666' }
+      });
+      
+      components.forEach(([compName, manifest]) => {
+        componentItems.push({
+          label: manifest.name,
+          key: `comp-${compName}`,
+          icon: React.createElement(manifest.icon, { width: 14, height: 14 })
+        });
+      });
+    }
+  });
+
+  return componentItems;
+}
+
+export function getComponentCategories() {
+  const cats: Record<string, [string, UICompManifest][]> = Object.fromEntries(
+    Object.keys(uiCompCategoryNames).map((cat) => [cat, []])
+  );
+  Object.entries(uiCompRegistry).forEach(([name, manifest]) => {
+    manifest.categories.forEach((cat) => {
+      cats[cat].push([name, manifest]);
+    });
+  });
+  return cats;
+} 
\ No newline at end of file

From 1583b5c35ed9f1d3534ca616c59b0221ef2a8714 Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Wed, 2 Jul 2025 11:24:48 +0500
Subject: [PATCH 09/54] Update read me files

---
 .../lowcoder/src/comps/comps/preLoadComp/ACTION_SYSTEM.md     | 4 ----
 .../packages/lowcoder/src/comps/comps/preLoadComp/README.md   | 4 ----
 2 files changed, 8 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/ACTION_SYSTEM.md b/client/packages/lowcoder/src/comps/comps/preLoadComp/ACTION_SYSTEM.md
index ec492ff105..a25f64d011 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/ACTION_SYSTEM.md
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/ACTION_SYSTEM.md
@@ -1,7 +1,3 @@
-# Scalable Action System
-
-The `ActionInputSection` component has been refactored to use a scalable, configuration-driven approach that makes it easy to add new actions without modifying the main component logic.
-
 ## Architecture
 
 ### Core Components
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/README.md b/client/packages/lowcoder/src/comps/comps/preLoadComp/README.md
index 646d50faa7..2e7b764ff0 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/README.md
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/README.md
@@ -1,7 +1,3 @@
-# PreLoadComp Module
-
-This module has been restructured for maximum manageability and reusability. The original monolithic `preLoadComp.tsx` file has been broken down into logical, focused components.
-
 ## File Structure
 
 ```

From aec9485818d9c70e98b5d0b2b9e8b8a7c83fa249 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Wed, 2 Jul 2025 12:14:30 +0500
Subject: [PATCH 10/54] add query / new hook from assisstant ui

---
 .../src/comps/comps/chatComp/chatComp.tsx     |   2 +-
 .../src/comps/comps/chatComp/chatCompTypes.ts |   7 +-
 .../comps/comps/chatComp/chatPropertyView.tsx |  17 ++-
 .../src/comps/comps/chatComp/chatView.tsx     | 121 ++++++++++++++++--
 4 files changed, 126 insertions(+), 21 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
index e9c395dd2d..75de96494a 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
@@ -8,7 +8,7 @@ import { ChatPropertyView } from "./chatPropertyView";
 // Build the component
 const ChatTmpComp = new UICompBuilder(
   chatChildrenMap, 
-  (props) => <ChatView {...props} />
+  (props) => <ChatView {...props} chatQuery={props.chatQuery.value} />
 )
   .setPropertyViewFn((children) => <ChatPropertyView children={children} />)
   .build();
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
index 147f4dee1b..79ba4c80dc 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
@@ -3,6 +3,7 @@ import { StringControl, NumberControl } from "comps/controls/codeControl";
 import { withDefault } from "comps/generators";
 import { BoolControl } from "comps/controls/boolControl";
 import { dropdownControl } from "comps/controls/dropdownControl";
+import QuerySelectControl from "comps/controls/querySelectControl";
 
 // Model type dropdown options
 const ModelTypeOptions = [
@@ -12,7 +13,7 @@ const ModelTypeOptions = [
 
 export const chatChildrenMap = {
   text: withDefault(StringControl, "Chat Component Placeholder"),
-  modelHost: withDefault(StringControl, "http://localhost:11434"),
+  chatQuery: QuerySelectControl,
   modelType: dropdownControl(ModelTypeOptions, "direct-llm"),
   streaming: BoolControl.DEFAULT_TRUE,
   systemPrompt: withDefault(StringControl, "You are a helpful assistant."),
@@ -22,8 +23,8 @@ export const chatChildrenMap = {
 
 export type ChatCompProps = {
   text: string;
-  modelHost: string;
-  modelType: "direct-llm" | "n8n";
+  chatQuery: string;
+  modelType: string;
   streaming: boolean;
   systemPrompt: string;
   agent: boolean;
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
index 510e87ac2e..b4f42c8e17 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
@@ -8,12 +8,19 @@ export const ChatPropertyView = React.memo((props: any) => {
   return (
     <Section name={sectionNames.basic}>
       {children.text.propertyView({ label: "Text" })}
-      {children.modelHost.propertyView({ label: "Model Host URL" })}
+      {children.chatQuery.propertyView({ label: "Chat Query" })}
       {children.modelType.propertyView({ label: "Model Type" })}
-      {children.streaming.propertyView({ label: "Streaming Responses" })}
-      {children.systemPrompt.propertyView({ label: "System Prompt" })}
-      {children.agent.propertyView({ label: "Agent Mode" })}
-      {children.maxInteractions.propertyView({ label: "Max Interactions" })}
+      {children.streaming.propertyView({ label: "Enable Streaming" })}
+      {children.systemPrompt.propertyView({ 
+        label: "System Prompt",
+        placeholder: "Enter system prompt...",
+        enableSpellCheck: false,
+      })}
+      {children.agent.propertyView({ label: "Enable Agent Mode" })}
+      {children.maxInteractions.propertyView({ 
+        label: "Max Interactions",
+        placeholder: "10",
+      })}
     </Section>
   );
 });
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
index 0b74094b40..c6db6caa2e 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
@@ -1,26 +1,123 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
-import React from "react";
+import React, { useState, useContext } from "react";
 import { ChatCompProps } from "./chatCompTypes";
 import { Thread } from "./components/assistant-ui/thread";
 
-// Import assistant-ui components and proper runtime
+// Import assistant-ui components for external store runtime
 import { 
   AssistantRuntimeProvider,
+  useExternalStoreRuntime,
+  ThreadMessageLike,
+  AppendMessage
 } from "@assistant-ui/react";
-import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
 import "@assistant-ui/styles/index.css";
 import "@assistant-ui/styles/markdown.css";
 
+// Import Lowcoder query execution
+import { EditorContext } from "comps/editorState";
+import { executeQueryAction, routeByNameAction } from "lowcoder-core";
+
+const convertMessage = (message: ThreadMessageLike) => {
+  return message;
+};
+
 export const ChatView = React.memo((props: ChatCompProps) => {
-  // Create proper runtime using useChatRuntime
-  const runtime = useChatRuntime({
-    api: props.modelHost,
-    stream: props.streaming,
-    modelType: props.modelType as any,
-    systemPrompt: props.systemPrompt,
-    agent: props.agent,
-    maxTurns: props.maxInteractions,
-  } as any);
+  const [messages, setMessages] = useState<readonly ThreadMessageLike[]>([]);
+  const editorState = useContext(EditorContext);
+
+  const onNew = async (message: AppendMessage) => {
+    if (message.content.length !== 1 || message.content[0]?.type !== "text") {
+      throw new Error("Only text content is supported");
+    }
+
+    // Add user message immediately
+    const userMessage: ThreadMessageLike = {
+      role: "user",
+      content: [{ type: "text", text: message.content[0].text }],
+    };
+    setMessages((currentMessages) => [...currentMessages, userMessage]);
+
+    try {
+      // Execute the selected Lowcoder query
+      if (props.chatQuery) {
+        // Prepare query arguments with chat context
+        const queryArgs = {
+          message: message.content[0].text,
+          systemPrompt: props.systemPrompt,
+          streaming: props.streaming,
+          agent: props.agent,
+          maxInteractions: props.maxInteractions,
+          modelType: props.modelType,
+                     // Pass entire conversation history for context
+           messages: messages.concat([userMessage]).map(msg => ({
+             role: msg.role,
+             content: Array.isArray(msg.content) && msg.content[0] && typeof msg.content[0] === "object" && "text" in msg.content[0] 
+               ? msg.content[0].text 
+               : typeof msg.content === "string" ? msg.content : ""
+           }))
+        };
+
+        // Execute the query through Lowcoder's query system
+        const result = await new Promise((resolve, reject) => {
+          const queryComp = editorState?.getQueriesComp()
+            .getView()
+            .find(q => q.children.name.getView() === props.chatQuery);
+
+          if (!queryComp) {
+            reject(new Error(`Query "${props.chatQuery}" not found`));
+            return;
+          }
+
+          queryComp.dispatch(
+            executeQueryAction({
+              args: queryArgs,
+              afterExecFunc: () => {
+                const queryResult = queryComp.children.data.getView();
+                resolve(queryResult);
+              }
+            })
+          );
+        });
+
+                 // Add assistant response
+         const assistantMessage: ThreadMessageLike = {
+           role: "assistant",
+           content: [{ 
+             type: "text", 
+             text: typeof result === "string" 
+               ? result 
+               : (result as any)?.message || (result as any)?.response || "No response"
+           }],
+         };
+        setMessages((currentMessages) => [...currentMessages, assistantMessage]);
+        
+      } else {
+        // Fallback response when no query is selected
+        const assistantMessage: ThreadMessageLike = {
+          role: "assistant",
+          content: [{ type: "text", text: "Please select a chat query in the component properties." }],
+        };
+        setMessages((currentMessages) => [...currentMessages, assistantMessage]);
+      }
+    } catch (error) {
+      // Error handling
+      const errorMessage: ThreadMessageLike = {
+        role: "assistant",
+        content: [{ 
+          type: "text", 
+          text: `Error: ${error instanceof Error ? error.message : "Unknown error occurred"}`
+        }],
+      };
+      setMessages((currentMessages) => [...currentMessages, errorMessage]);
+    }
+  };
+
+  const runtime = useExternalStoreRuntime<ThreadMessageLike>({
+    messages,
+    setMessages,
+    onNew,
+    convertMessage,
+  });
 
   return (
     <AssistantRuntimeProvider runtime={runtime}>

From b820f8e28865c8212ac8031ed82697dc86f3818e Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Wed, 2 Jul 2025 15:52:11 +0500
Subject: [PATCH 11/54] use mock data

---
 .../src/comps/comps/chatComp/chatView.tsx     | 117 +-----------------
 .../components/context/MyRuntimeProvider.tsx  |  70 +++++++++++
 2 files changed, 75 insertions(+), 112 deletions(-)
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
index c6db6caa2e..3e9f1ced2c 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
@@ -1,128 +1,21 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
-import React, { useState, useContext } from "react";
+import React from "react";
 import { ChatCompProps } from "./chatCompTypes";
 import { Thread } from "./components/assistant-ui/thread";
 
-// Import assistant-ui components for external store runtime
-import { 
-  AssistantRuntimeProvider,
-  useExternalStoreRuntime,
-  ThreadMessageLike,
-  AppendMessage
-} from "@assistant-ui/react";
 import "@assistant-ui/styles/index.css";
 import "@assistant-ui/styles/markdown.css";
 
-// Import Lowcoder query execution
-import { EditorContext } from "comps/editorState";
-import { executeQueryAction, routeByNameAction } from "lowcoder-core";
 
-const convertMessage = (message: ThreadMessageLike) => {
-  return message;
-};
+import { MyRuntimeProvider } from "./components/context/MyRuntimeProvider";
 
-export const ChatView = React.memo((props: ChatCompProps) => {
-  const [messages, setMessages] = useState<readonly ThreadMessageLike[]>([]);
-  const editorState = useContext(EditorContext);
-
-  const onNew = async (message: AppendMessage) => {
-    if (message.content.length !== 1 || message.content[0]?.type !== "text") {
-      throw new Error("Only text content is supported");
-    }
-
-    // Add user message immediately
-    const userMessage: ThreadMessageLike = {
-      role: "user",
-      content: [{ type: "text", text: message.content[0].text }],
-    };
-    setMessages((currentMessages) => [...currentMessages, userMessage]);
-
-    try {
-      // Execute the selected Lowcoder query
-      if (props.chatQuery) {
-        // Prepare query arguments with chat context
-        const queryArgs = {
-          message: message.content[0].text,
-          systemPrompt: props.systemPrompt,
-          streaming: props.streaming,
-          agent: props.agent,
-          maxInteractions: props.maxInteractions,
-          modelType: props.modelType,
-                     // Pass entire conversation history for context
-           messages: messages.concat([userMessage]).map(msg => ({
-             role: msg.role,
-             content: Array.isArray(msg.content) && msg.content[0] && typeof msg.content[0] === "object" && "text" in msg.content[0] 
-               ? msg.content[0].text 
-               : typeof msg.content === "string" ? msg.content : ""
-           }))
-        };
-
-        // Execute the query through Lowcoder's query system
-        const result = await new Promise((resolve, reject) => {
-          const queryComp = editorState?.getQueriesComp()
-            .getView()
-            .find(q => q.children.name.getView() === props.chatQuery);
 
-          if (!queryComp) {
-            reject(new Error(`Query "${props.chatQuery}" not found`));
-            return;
-          }
-
-          queryComp.dispatch(
-            executeQueryAction({
-              args: queryArgs,
-              afterExecFunc: () => {
-                const queryResult = queryComp.children.data.getView();
-                resolve(queryResult);
-              }
-            })
-          );
-        });
-
-                 // Add assistant response
-         const assistantMessage: ThreadMessageLike = {
-           role: "assistant",
-           content: [{ 
-             type: "text", 
-             text: typeof result === "string" 
-               ? result 
-               : (result as any)?.message || (result as any)?.response || "No response"
-           }],
-         };
-        setMessages((currentMessages) => [...currentMessages, assistantMessage]);
-        
-      } else {
-        // Fallback response when no query is selected
-        const assistantMessage: ThreadMessageLike = {
-          role: "assistant",
-          content: [{ type: "text", text: "Please select a chat query in the component properties." }],
-        };
-        setMessages((currentMessages) => [...currentMessages, assistantMessage]);
-      }
-    } catch (error) {
-      // Error handling
-      const errorMessage: ThreadMessageLike = {
-        role: "assistant",
-        content: [{ 
-          type: "text", 
-          text: `Error: ${error instanceof Error ? error.message : "Unknown error occurred"}`
-        }],
-      };
-      setMessages((currentMessages) => [...currentMessages, errorMessage]);
-    }
-  };
-
-  const runtime = useExternalStoreRuntime<ThreadMessageLike>({
-    messages,
-    setMessages,
-    onNew,
-    convertMessage,
-  });
 
+export const ChatView = React.memo((props: ChatCompProps) => {
   return (
-    <AssistantRuntimeProvider runtime={runtime}>
+    <MyRuntimeProvider>
       <Thread />
-    </AssistantRuntimeProvider>
+    </MyRuntimeProvider>
   );
 });
 
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
new file mode 100644
index 0000000000..b8fbbc2740
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
@@ -0,0 +1,70 @@
+import { useState } from "react";
+import {
+  useExternalStoreRuntime,
+  ThreadMessageLike,
+  AppendMessage,
+  AssistantRuntimeProvider,
+} from "@assistant-ui/react";
+
+const callYourAPI = async (message: AppendMessage) => {
+    // Simulate API delay
+    await new Promise(resolve => setTimeout(resolve, 1500));
+    
+    // Simple responses
+    return {
+      content: "This is a mock response from your backend. You typed: " + 
+      (typeof message.content === 'string' ? message.content : 'something')
+    };
+  };
+
+export function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
+    const [messages, setMessages] = useState<ThreadMessageLike[]>([]);
+    const [isRunning, setIsRunning] = useState(false);
+  
+    const onNew = async (message: AppendMessage) => {
+      // Add user message
+      const userMessage: ThreadMessageLike = {
+        role: "user",
+        content: message.content,
+      };
+      
+      setMessages(prev => [...prev, userMessage]);
+      setIsRunning(true);
+  
+      try {
+        // Call mock API
+        const response = await callYourAPI(message);
+        
+        const assistantMessage: ThreadMessageLike = {
+          role: "assistant",
+          content: response.content,
+        };
+        
+        setMessages(prev => [...prev, assistantMessage]);
+      } catch (error) {
+        // Handle errors gracefully
+        const errorMessage: ThreadMessageLike = {
+          role: "assistant", 
+          content: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}. This is expected in mock mode for testing error handling.`,
+        };
+        
+        setMessages(prev => [...prev, errorMessage]);
+      } finally {
+        setIsRunning(false);
+      }
+    };
+  
+    const runtime = useExternalStoreRuntime<ThreadMessageLike>({
+      messages,
+      setMessages,
+      isRunning,
+      onNew,
+      convertMessage: (message) => message,
+    });
+  
+    return (
+      <AssistantRuntimeProvider runtime={runtime}>
+        {children}
+      </AssistantRuntimeProvider>
+    );
+  }
\ No newline at end of file

From 0dc85d4579796d631889fb8572a09fa791cc9acc Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Wed, 2 Jul 2025 16:45:00 +0500
Subject: [PATCH 12/54] add edit functionality

---
 .../components/context/MyRuntimeProvider.tsx  | 108 +++++++++++++++---
 1 file changed, 91 insertions(+), 17 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
index b8fbbc2740..cb50e25016 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
@@ -6,6 +6,16 @@ import {
   AssistantRuntimeProvider,
 } from "@assistant-ui/react";
 
+// Define your custom message type
+interface MyMessage {
+  id: string;
+  role: "user" | "assistant";
+  text: string;
+  timestamp: number;
+}
+
+const generateId = () => Math.random().toString(36).substr(2, 9);
+
 const callYourAPI = async (message: AppendMessage) => {
     // Simulate API delay
     await new Promise(resolve => setTimeout(resolve, 1500));
@@ -15,51 +25,115 @@ const callYourAPI = async (message: AppendMessage) => {
       content: "This is a mock response from your backend. You typed: " + 
       (typeof message.content === 'string' ? message.content : 'something')
     };
-  };
+};
 
 export function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
-    const [messages, setMessages] = useState<ThreadMessageLike[]>([]);
+    // Use your custom message type in state
+    const [myMessages, setMyMessages] = useState<MyMessage[]>([]);
     const [isRunning, setIsRunning] = useState(false);
+
+    // Convert your custom format to ThreadMessageLike
+    const convertMessage = (message: MyMessage): ThreadMessageLike => ({
+        role: message.role,
+        content: [{ type: "text", text: message.text }],
+        id: message.id,
+        createdAt: new Date(message.timestamp),
+      });
   
     const onNew = async (message: AppendMessage) => {
-      // Add user message
-      const userMessage: ThreadMessageLike = {
+      // Add user message in your custom format
+      const userMessage: MyMessage = {
+        id: generateId(),
         role: "user",
-        content: message.content,
+        text: typeof message.content === 'string' ? message.content : JSON.stringify(message.content),
+        timestamp: Date.now(),
       };
       
-      setMessages(prev => [...prev, userMessage]);
+      setMyMessages(prev => [...prev, userMessage]);
       setIsRunning(true);
   
       try {
         // Call mock API
         const response = await callYourAPI(message);
         
-        const assistantMessage: ThreadMessageLike = {
+        const assistantMessage: MyMessage = {
+          id: generateId(),
+          role: "assistant",
+          text: response.content,
+          timestamp: Date.now(),
+        };
+        
+        setMyMessages(prev => [...prev, assistantMessage]);
+      } catch (error) {
+        // Handle errors gracefully
+        const errorMessage: MyMessage = {
+          id: generateId(),
+          role: "assistant", 
+          text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}. This is expected in mock mode for testing error handling.`,
+          timestamp: Date.now(),
+        };
+        
+        setMyMessages(prev => [...prev, errorMessage]);
+      } finally {
+        setIsRunning(false);
+      }
+    };
+
+    // Add onEdit functionality
+    const onEdit = async (message: AppendMessage) => {
+      // Find the index where to insert the edited message
+      const index = myMessages.findIndex((m) => m.id === message.parentId) + 1;
+
+      // Keep messages up to the parent
+      const newMessages = [...myMessages.slice(0, index)];
+
+      // Add the edited message in your custom format
+      const editedMessage: MyMessage = {
+        id: generateId(), // Always generate new ID for edited messages
+        role: "user",
+        text: typeof message.content === 'string' ? message.content : JSON.stringify(message.content),
+        timestamp: Date.now(),
+      };
+      newMessages.push(editedMessage);
+
+      setMyMessages(newMessages);
+      setIsRunning(true);
+
+      try {
+        // Generate new response
+        const response = await callYourAPI(message);
+        
+        const assistantMessage: MyMessage = {
+          id: generateId(),
           role: "assistant",
-          content: response.content,
+          text: response.content,
+          timestamp: Date.now(),
         };
         
-        setMessages(prev => [...prev, assistantMessage]);
+        newMessages.push(assistantMessage);
+        setMyMessages(newMessages);
       } catch (error) {
         // Handle errors gracefully
-        const errorMessage: ThreadMessageLike = {
+        const errorMessage: MyMessage = {
+          id: generateId(),
           role: "assistant", 
-          content: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}. This is expected in mock mode for testing error handling.`,
+          text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
+          timestamp: Date.now(),
         };
         
-        setMessages(prev => [...prev, errorMessage]);
+        newMessages.push(errorMessage);
+        setMyMessages(newMessages);
       } finally {
         setIsRunning(false);
       }
     };
   
-    const runtime = useExternalStoreRuntime<ThreadMessageLike>({
-      messages,
-      setMessages,
+    const runtime = useExternalStoreRuntime({
+      messages: myMessages,        // Your custom message array
+      convertMessage,              // Conversion function
       isRunning,
       onNew,
-      convertMessage: (message) => message,
+      onEdit,                     // Enable message editing
     });
   
     return (
@@ -67,4 +141,4 @@ export function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
         {children}
       </AssistantRuntimeProvider>
     );
-  }
\ No newline at end of file
+}
\ No newline at end of file

From fd9dc7777d73c8cbbd2f0bbbf86a2aa3da99e857 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Wed, 2 Jul 2025 16:50:11 +0500
Subject: [PATCH 13/54] fix message json issue

---
 .../components/context/MyRuntimeProvider.tsx  | 23 +++++++++++++------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
index cb50e25016..84070c5caf 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
@@ -16,14 +16,13 @@ interface MyMessage {
 
 const generateId = () => Math.random().toString(36).substr(2, 9);
 
-const callYourAPI = async (message: AppendMessage) => {
+const callYourAPI = async (text: string) => {
     // Simulate API delay
     await new Promise(resolve => setTimeout(resolve, 1500));
     
     // Simple responses
     return {
-      content: "This is a mock response from your backend. You typed: " + 
-      (typeof message.content === 'string' ? message.content : 'something')
+      content: "This is a mock response from your backend. You typed: " + text
     };
 };
 
@@ -41,11 +40,16 @@ export function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
       });
   
     const onNew = async (message: AppendMessage) => {
+      // Extract text from AppendMessage content array
+      if (message.content.length !== 1 || message.content[0]?.type !== "text") {
+        throw new Error("Only text content is supported");
+      }
+
       // Add user message in your custom format
       const userMessage: MyMessage = {
         id: generateId(),
         role: "user",
-        text: typeof message.content === 'string' ? message.content : JSON.stringify(message.content),
+        text: message.content[0].text,
         timestamp: Date.now(),
       };
       
@@ -54,7 +58,7 @@ export function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
   
       try {
         // Call mock API
-        const response = await callYourAPI(message);
+        const response = await callYourAPI(userMessage.text);
         
         const assistantMessage: MyMessage = {
           id: generateId(),
@@ -81,6 +85,11 @@ export function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
 
     // Add onEdit functionality
     const onEdit = async (message: AppendMessage) => {
+      // Extract text from AppendMessage content array
+      if (message.content.length !== 1 || message.content[0]?.type !== "text") {
+        throw new Error("Only text content is supported");
+      }
+
       // Find the index where to insert the edited message
       const index = myMessages.findIndex((m) => m.id === message.parentId) + 1;
 
@@ -91,7 +100,7 @@ export function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
       const editedMessage: MyMessage = {
         id: generateId(), // Always generate new ID for edited messages
         role: "user",
-        text: typeof message.content === 'string' ? message.content : JSON.stringify(message.content),
+        text: message.content[0].text,
         timestamp: Date.now(),
       };
       newMessages.push(editedMessage);
@@ -101,7 +110,7 @@ export function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
 
       try {
         // Generate new response
-        const response = await callYourAPI(message);
+        const response = await callYourAPI(editedMessage.text);
         
         const assistantMessage: MyMessage = {
           id: generateId(),

From 52cdcf2060f59db8306c7936423639e5bf15001d Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Wed, 2 Jul 2025 17:59:02 +0500
Subject: [PATCH 14/54] add threads logic

---
 .../src/comps/comps/chatComp/chatView.tsx     |  13 +-
 .../chatComp/components/ChatWithThreads.tsx   | 246 ++++++++++++++++++
 .../components/context/MyRuntimeProvider.tsx  |   2 +
 .../components/context/ThreadContext.tsx      |  53 ++++
 4 files changed, 303 insertions(+), 11 deletions(-)
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/context/ThreadContext.tsx

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
index 3e9f1ced2c..0af26ffe25 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
@@ -1,22 +1,13 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
 import React from "react";
 import { ChatCompProps } from "./chatCompTypes";
-import { Thread } from "./components/assistant-ui/thread";
+import { ChatApp } from "./components/ChatWithThreads";
 
 import "@assistant-ui/styles/index.css";
 import "@assistant-ui/styles/markdown.css";
 
-
-import { MyRuntimeProvider } from "./components/context/MyRuntimeProvider";
-
-
-
 export const ChatView = React.memo((props: ChatCompProps) => {
-  return (
-    <MyRuntimeProvider>
-      <Thread />
-    </MyRuntimeProvider>
-  );
+  return <ChatApp />;
 });
 
 ChatView.displayName = 'ChatView';
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx
new file mode 100644
index 0000000000..01913e3102
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx
@@ -0,0 +1,246 @@
+import React, { useState } from "react";
+import {
+  useExternalStoreRuntime,
+  ThreadMessageLike,
+  AppendMessage,
+  AssistantRuntimeProvider,
+  ExternalStoreThreadListAdapter,
+} from "@assistant-ui/react";
+import { useThreadContext, MyMessage, ThreadProvider } from "./context/ThreadContext";
+import { Thread } from "./assistant-ui/thread";
+import { ThreadList } from "./assistant-ui/thread-list";
+
+// Define thread data interfaces to match ExternalStoreThreadData requirements
+interface RegularThreadData {
+  threadId: string;
+  status: "regular";
+  title: string;
+}
+
+interface ArchivedThreadData {
+  threadId: string;
+  status: "archived";
+  title: string;
+}
+
+type ThreadData = RegularThreadData | ArchivedThreadData;
+
+const generateId = () => Math.random().toString(36).substr(2, 9);
+
+const callYourAPI = async (text: string) => {
+  // Simulate API delay
+  await new Promise(resolve => setTimeout(resolve, 1500));
+  
+  // Simple responses
+  return {
+    content: "This is a mock response from your backend. You typed: " + text
+  };
+};
+
+function ChatWithThreads() {
+  const { currentThreadId, setCurrentThreadId, threads, setThreads } =
+    useThreadContext();
+  const [isRunning, setIsRunning] = useState(false);
+  const [threadList, setThreadList] = useState<ThreadData[]>([
+    { threadId: "default", status: "regular", title: "New Chat" } as RegularThreadData,
+  ]);
+
+  // Get messages for current thread
+  const currentMessages = threads.get(currentThreadId) || [];
+
+  // Convert custom format to ThreadMessageLike
+  const convertMessage = (message: MyMessage): ThreadMessageLike => ({
+    role: message.role,
+    content: [{ type: "text", text: message.text }],
+    id: message.id,
+    createdAt: new Date(message.timestamp),
+  });
+
+  const onNew = async (message: AppendMessage) => {
+    // Extract text from AppendMessage content array
+    if (message.content.length !== 1 || message.content[0]?.type !== "text") {
+      throw new Error("Only text content is supported");
+    }
+
+    // Add user message in custom format
+    const userMessage: MyMessage = {
+      id: generateId(),
+      role: "user",
+      text: message.content[0].text,
+      timestamp: Date.now(),
+    };
+    
+    // Update current thread with new user message
+    const updatedMessages = [...currentMessages, userMessage];
+    setThreads(prev => new Map(prev).set(currentThreadId, updatedMessages));
+    setIsRunning(true);
+
+    try {
+      // Call mock API
+      const response = await callYourAPI(userMessage.text);
+      
+      const assistantMessage: MyMessage = {
+        id: generateId(),
+        role: "assistant",
+        text: response.content,
+        timestamp: Date.now(),
+      };
+      
+      // Update current thread with assistant response
+      const finalMessages = [...updatedMessages, assistantMessage];
+      setThreads(prev => new Map(prev).set(currentThreadId, finalMessages));
+    } catch (error) {
+      // Handle errors gracefully
+      const errorMessage: MyMessage = {
+        id: generateId(),
+        role: "assistant", 
+        text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
+        timestamp: Date.now(),
+      };
+      
+      const finalMessages = [...updatedMessages, errorMessage];
+      setThreads(prev => new Map(prev).set(currentThreadId, finalMessages));
+    } finally {
+      setIsRunning(false);
+    }
+  };
+
+  // Add onEdit functionality
+  const onEdit = async (message: AppendMessage) => {
+    // Extract text from AppendMessage content array
+    if (message.content.length !== 1 || message.content[0]?.type !== "text") {
+      throw new Error("Only text content is supported");
+    }
+
+    // Find the index where to insert the edited message
+    const index = currentMessages.findIndex((m) => m.id === message.parentId) + 1;
+
+    // Keep messages up to the parent
+    const newMessages = [...currentMessages.slice(0, index)];
+
+    // Add the edited message in custom format
+    const editedMessage: MyMessage = {
+      id: generateId(),
+      role: "user",
+      text: message.content[0].text,
+      timestamp: Date.now(),
+    };
+    newMessages.push(editedMessage);
+
+    setThreads(prev => new Map(prev).set(currentThreadId, newMessages));
+    setIsRunning(true);
+
+    try {
+      // Generate new response
+      const response = await callYourAPI(editedMessage.text);
+      
+      const assistantMessage: MyMessage = {
+        id: generateId(),
+        role: "assistant",
+        text: response.content,
+        timestamp: Date.now(),
+      };
+      
+      newMessages.push(assistantMessage);
+      setThreads(prev => new Map(prev).set(currentThreadId, newMessages));
+    } catch (error) {
+      // Handle errors gracefully
+      const errorMessage: MyMessage = {
+        id: generateId(),
+        role: "assistant", 
+        text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
+        timestamp: Date.now(),
+      };
+      
+      newMessages.push(errorMessage);
+      setThreads(prev => new Map(prev).set(currentThreadId, newMessages));
+    } finally {
+      setIsRunning(false);
+    }
+  };
+
+  // Thread list adapter for managing multiple threads
+  const threadListAdapter: ExternalStoreThreadListAdapter = {
+    threadId: currentThreadId,
+    threads: threadList.filter((t): t is RegularThreadData => t.status === "regular"),
+    archivedThreads: threadList.filter((t): t is ArchivedThreadData => t.status === "archived"),
+
+    onSwitchToNewThread: () => {
+      const newId = `thread-${Date.now()}`;
+      setThreadList((prev) => [
+        ...prev,
+        {
+          threadId: newId,
+          status: "regular",
+          title: "New Chat",
+        } as RegularThreadData,
+      ]);
+      setThreads((prev) => new Map(prev).set(newId, []));
+      setCurrentThreadId(newId);
+    },
+
+    onSwitchToThread: (threadId) => {
+      setCurrentThreadId(threadId);
+    },
+
+    onRename: (threadId, newTitle) => {
+      setThreadList((prev) =>
+        prev.map((t) =>
+          t.threadId === threadId ? { ...t, title: newTitle } : t,
+        ),
+      );
+    },
+
+    onArchive: (threadId) => {
+      setThreadList((prev) =>
+        prev.map((t) =>
+          t.threadId === threadId ? { ...t, status: "archived" } : t,
+        ),
+      );
+    },
+
+    onDelete: (threadId) => {
+      setThreadList((prev) => prev.filter((t) => t.threadId !== threadId));
+      setThreads((prev) => {
+        const next = new Map(prev);
+        next.delete(threadId);
+        return next;
+      });
+      if (currentThreadId === threadId) {
+        setCurrentThreadId("default");
+      }
+    },
+  };
+
+  const runtime = useExternalStoreRuntime({
+    messages: currentMessages,
+    setMessages: (messages) => {
+      setThreads((prev) => new Map(prev).set(currentThreadId, messages));
+    },
+    convertMessage,
+    isRunning,
+    onNew,
+    onEdit,
+    adapters: {
+      threadList: threadListAdapter,
+    },
+  });
+
+  return (
+    <AssistantRuntimeProvider runtime={runtime}>
+      <ThreadList />
+      <Thread />
+    </AssistantRuntimeProvider>
+  );
+}
+
+// Main App component with proper context wrapping
+export function ChatApp() {
+  return (
+    <ThreadProvider>
+      <ChatWithThreads />
+    </ThreadProvider>
+  );
+}
+
+export { ChatWithThreads }; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
index 84070c5caf..81143047ef 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
@@ -4,6 +4,8 @@ import {
   ThreadMessageLike,
   AppendMessage,
   AssistantRuntimeProvider,
+  ExternalStoreThreadData,
+  ExternalStoreThreadListAdapter,
 } from "@assistant-ui/react";
 
 // Define your custom message type
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ThreadContext.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ThreadContext.tsx
new file mode 100644
index 0000000000..313833105c
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ThreadContext.tsx
@@ -0,0 +1,53 @@
+import React, { createContext, useContext, useState, ReactNode } from "react";
+
+// Define thread-specific message type
+interface MyMessage {
+  id: string;
+  role: "user" | "assistant";
+  text: string;
+  timestamp: number;
+}
+
+// Thread context type
+interface ThreadContextType {
+  currentThreadId: string;
+  setCurrentThreadId: (id: string) => void;
+  threads: Map<string, MyMessage[]>;
+  setThreads: React.Dispatch<React.SetStateAction<Map<string, MyMessage[]>>>;
+}
+
+// Create the context
+const ThreadContext = createContext<ThreadContextType>({
+  currentThreadId: "default",
+  setCurrentThreadId: () => {},
+  threads: new Map(),
+  setThreads: () => {},
+});
+
+// Thread provider component
+export function ThreadProvider({ children }: { children: ReactNode }) {
+  const [threads, setThreads] = useState<Map<string, MyMessage[]>>(
+    new Map([["default", []]]),
+  );
+  const [currentThreadId, setCurrentThreadId] = useState("default");
+
+  return (
+    <ThreadContext.Provider
+      value={{ currentThreadId, setCurrentThreadId, threads, setThreads }}
+    >
+      {children}
+    </ThreadContext.Provider>
+  );
+}
+
+// Hook for accessing thread context
+export function useThreadContext() {
+  const context = useContext(ThreadContext);
+  if (!context) {
+    throw new Error("useThreadContext must be used within ThreadProvider");
+  }
+  return context;
+}
+
+// Export the MyMessage type for use in other files
+export type { MyMessage }; 
\ No newline at end of file

From c619f89791a0aa50fda1d068a04e1dc05f0c0556 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Wed, 2 Jul 2025 20:59:07 +0500
Subject: [PATCH 15/54] add alaSql to chat component

---
 .../chatComp/components/ChatWithThreads.tsx   | 143 ++++++++-
 .../comps/comps/chatComp/utils/chatStorage.ts | 281 ++++++++++++++++++
 2 files changed, 414 insertions(+), 10 deletions(-)
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorage.ts

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx
index 01913e3102..a5e43afc2f 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
 import {
   useExternalStoreRuntime,
   ThreadMessageLike,
@@ -9,6 +9,7 @@ import {
 import { useThreadContext, MyMessage, ThreadProvider } from "./context/ThreadContext";
 import { Thread } from "./assistant-ui/thread";
 import { ThreadList } from "./assistant-ui/thread-list";
+import { chatStorage, ThreadData as StoredThreadData } from "../utils/chatStorage";
 
 // Define thread data interfaces to match ExternalStoreThreadData requirements
 interface RegularThreadData {
@@ -44,6 +45,108 @@ function ChatWithThreads() {
   const [threadList, setThreadList] = useState<ThreadData[]>([
     { threadId: "default", status: "regular", title: "New Chat" } as RegularThreadData,
   ]);
+  const [isInitialized, setIsInitialized] = useState(false);
+
+  // Load data from persistent storage on component mount
+  useEffect(() => {
+    const loadData = async () => {
+      try {
+        await chatStorage.initialize();
+        
+        // Load all threads from storage
+        const storedThreads = await chatStorage.getAllThreads();
+        if (storedThreads.length > 0) {
+          // Convert stored threads to UI format
+          const uiThreads: ThreadData[] = storedThreads.map(stored => ({
+            threadId: stored.threadId,
+            status: stored.status as "regular" | "archived",
+            title: stored.title,
+          }));
+          setThreadList(uiThreads);
+          
+          // Load messages for each thread
+          const threadMessages = new Map<string, MyMessage[]>();
+          for (const thread of storedThreads) {
+            const messages = await chatStorage.getMessages(thread.threadId);
+            threadMessages.set(thread.threadId, messages);
+          }
+          
+          // Ensure default thread exists
+          if (!threadMessages.has("default")) {
+            threadMessages.set("default", []);
+          }
+          
+          setThreads(threadMessages);
+          
+          // Set current thread to the most recently updated one
+          const latestThread = storedThreads.sort((a, b) => b.updatedAt - a.updatedAt)[0];
+          if (latestThread) {
+            setCurrentThreadId(latestThread.threadId);
+          }
+        } else {
+          // Initialize with default thread
+          const defaultThread: StoredThreadData = {
+            threadId: "default",
+            status: "regular",
+            title: "New Chat",
+            createdAt: Date.now(),
+            updatedAt: Date.now(),
+          };
+          await chatStorage.saveThread(defaultThread);
+        }
+        
+        setIsInitialized(true);
+      } catch (error) {
+        console.error("Failed to load chat data:", error);
+        setIsInitialized(true); // Continue with default state
+      }
+    };
+
+    loadData();
+  }, [setCurrentThreadId, setThreads]);
+
+  // Save thread data whenever threadList changes
+  useEffect(() => {
+    if (!isInitialized) return;
+    
+    const saveThreads = async () => {
+      try {
+        for (const thread of threadList) {
+          const storedThread: StoredThreadData = {
+            threadId: thread.threadId,
+            status: thread.status,
+            title: thread.title,
+            createdAt: Date.now(), // In real app, preserve original createdAt
+            updatedAt: Date.now(),
+          };
+          await chatStorage.saveThread(storedThread);
+        }
+      } catch (error) {
+        console.error("Failed to save threads:", error);
+      }
+    };
+
+    saveThreads();
+  }, [threadList, isInitialized]);
+
+  // Save messages whenever threads change
+  useEffect(() => {
+    if (!isInitialized) return;
+    
+    const saveMessages = async () => {
+      try {
+        for (const [threadId, messages] of threads.entries()) {
+          await chatStorage.saveMessages(messages, threadId);
+        }
+      } catch (error) {
+        console.error("Failed to save messages:", error);
+      }
+    };
+
+    saveMessages();
+  }, [threads, isInitialized]);
+
+  
 
   // Get messages for current thread
   const currentMessages = threads.get(currentThreadId) || [];
@@ -165,18 +268,31 @@ function ChatWithThreads() {
     threads: threadList.filter((t): t is RegularThreadData => t.status === "regular"),
     archivedThreads: threadList.filter((t): t is ArchivedThreadData => t.status === "archived"),
 
-    onSwitchToNewThread: () => {
+    onSwitchToNewThread: async () => {
       const newId = `thread-${Date.now()}`;
-      setThreadList((prev) => [
-        ...prev,
-        {
+      const newThread: RegularThreadData = {
+        threadId: newId,
+        status: "regular",
+        title: "New Chat",
+      };
+      
+      setThreadList((prev) => [...prev, newThread]);
+      setThreads((prev) => new Map(prev).set(newId, []));
+      setCurrentThreadId(newId);
+      
+      // Save new thread to storage
+      try {
+        const storedThread: StoredThreadData = {
           threadId: newId,
           status: "regular",
           title: "New Chat",
-        } as RegularThreadData,
-      ]);
-      setThreads((prev) => new Map(prev).set(newId, []));
-      setCurrentThreadId(newId);
+          createdAt: Date.now(),
+          updatedAt: Date.now(),
+        };
+        await chatStorage.saveThread(storedThread);
+      } catch (error) {
+        console.error("Failed to save new thread:", error);
+      }
     },
 
     onSwitchToThread: (threadId) => {
@@ -199,7 +315,7 @@ function ChatWithThreads() {
       );
     },
 
-    onDelete: (threadId) => {
+    onDelete: async (threadId) => {
       setThreadList((prev) => prev.filter((t) => t.threadId !== threadId));
       setThreads((prev) => {
         const next = new Map(prev);
@@ -209,6 +325,13 @@ function ChatWithThreads() {
       if (currentThreadId === threadId) {
         setCurrentThreadId("default");
       }
+      
+      // Delete thread from storage
+      try {
+        await chatStorage.deleteThread(threadId);
+      } catch (error) {
+        console.error("Failed to delete thread from storage:", error);
+      }
     },
   };
 
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorage.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorage.ts
new file mode 100644
index 0000000000..7e85087e02
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorage.ts
@@ -0,0 +1,281 @@
+import alasql from "alasql";
+import { MyMessage } from "../components/context/ThreadContext";
+
+// Database configuration
+const DB_NAME = "ChatDB";
+const THREADS_TABLE = "threads";
+const MESSAGES_TABLE = "messages";
+
+// Thread data interface
+export interface ThreadData {
+  threadId: string;
+  status: "regular" | "archived";
+  title: string;
+  createdAt: number;
+  updatedAt: number;
+}
+
+// Initialize the database
+class ChatStorage {
+  private initialized = false;
+
+  async initialize() {
+    if (this.initialized) return;
+
+    try {
+      // Create database with localStorage backend
+      await alasql.promise(`CREATE LOCALSTORAGE DATABASE IF NOT EXISTS ${DB_NAME}`);
+      await alasql.promise(`ATTACH LOCALSTORAGE DATABASE ${DB_NAME}`);
+      await alasql.promise(`USE ${DB_NAME}`);
+
+      // Create threads table
+      await alasql.promise(`
+        CREATE TABLE IF NOT EXISTS ${THREADS_TABLE} (
+          threadId STRING PRIMARY KEY,
+          status STRING,
+          title STRING,
+          createdAt NUMBER,
+          updatedAt NUMBER
+        )
+      `);
+
+      // Create messages table
+      await alasql.promise(`
+        CREATE TABLE IF NOT EXISTS ${MESSAGES_TABLE} (
+          id STRING PRIMARY KEY,
+          threadId STRING,
+          role STRING,
+          text STRING,
+          timestamp NUMBER
+        )
+      `);
+
+      this.initialized = true;
+      console.log("Chat database initialized successfully");
+    } catch (error) {
+      console.error("Failed to initialize chat database:", error);
+      throw error;
+    }
+  }
+
+  // Thread operations
+  async saveThread(thread: ThreadData): Promise<void> {
+    await this.initialize();
+    
+    try {
+      // Insert or replace thread
+      await alasql.promise(`
+        DELETE FROM ${THREADS_TABLE} WHERE threadId = ?
+      `, [thread.threadId]);
+      
+      await alasql.promise(`
+        INSERT INTO ${THREADS_TABLE} VALUES (?, ?, ?, ?, ?)
+      `, [thread.threadId, thread.status, thread.title, thread.createdAt, thread.updatedAt]);
+    } catch (error) {
+      console.error("Failed to save thread:", error);
+      throw error;
+    }
+  }
+
+  async getThread(threadId: string): Promise<ThreadData | null> {
+    await this.initialize();
+    
+    try {
+      const result = await alasql.promise(`
+        SELECT * FROM ${THREADS_TABLE} WHERE threadId = ?
+      `, [threadId]) as ThreadData[];
+      
+      return result && result.length > 0 ? result[0] : null;
+    } catch (error) {
+      console.error("Failed to get thread:", error);
+      return null;
+    }
+  }
+
+  async getAllThreads(): Promise<ThreadData[]> {
+    await this.initialize();
+    
+    try {
+      const result = await alasql.promise(`
+        SELECT * FROM ${THREADS_TABLE} ORDER BY updatedAt DESC
+      `) as ThreadData[];
+      
+      return Array.isArray(result) ? result : [];
+    } catch (error) {
+      console.error("Failed to get threads:", error);
+      return [];
+    }
+  }
+
+  async deleteThread(threadId: string): Promise<void> {
+    await this.initialize();
+    
+    try {
+      // Delete thread and all its messages
+      await alasql.promise(`DELETE FROM ${THREADS_TABLE} WHERE threadId = ?`, [threadId]);
+      await alasql.promise(`DELETE FROM ${MESSAGES_TABLE} WHERE threadId = ?`, [threadId]);
+    } catch (error) {
+      console.error("Failed to delete thread:", error);
+      throw error;
+    }
+  }
+
+  // Message operations
+  async saveMessage(message: MyMessage, threadId: string): Promise<void> {
+    await this.initialize();
+    
+    try {
+      // Insert or replace message
+      await alasql.promise(`
+        DELETE FROM ${MESSAGES_TABLE} WHERE id = ?
+      `, [message.id]);
+      
+      await alasql.promise(`
+        INSERT INTO ${MESSAGES_TABLE} VALUES (?, ?, ?, ?, ?)
+      `, [message.id, threadId, message.role, message.text, message.timestamp]);
+    } catch (error) {
+      console.error("Failed to save message:", error);
+      throw error;
+    }
+  }
+
+  async saveMessages(messages: MyMessage[], threadId: string): Promise<void> {
+    await this.initialize();
+    
+    try {
+      // Delete existing messages for this thread
+      await alasql.promise(`DELETE FROM ${MESSAGES_TABLE} WHERE threadId = ?`, [threadId]);
+      
+      // Insert all messages
+      for (const message of messages) {
+        await alasql.promise(`
+          INSERT INTO ${MESSAGES_TABLE} VALUES (?, ?, ?, ?, ?)
+        `, [message.id, threadId, message.role, message.text, message.timestamp]);
+      }
+    } catch (error) {
+      console.error("Failed to save messages:", error);
+      throw error;
+    }
+  }
+
+  async getMessages(threadId: string): Promise<MyMessage[]> {
+    await this.initialize();
+    
+    try {
+      const result = await alasql.promise(`
+        SELECT id, role, text, timestamp FROM ${MESSAGES_TABLE} 
+        WHERE threadId = ? ORDER BY timestamp ASC
+      `, [threadId]) as MyMessage[];
+      
+      return Array.isArray(result) ? result : [];
+    } catch (error) {
+      console.error("Failed to get messages:", error);
+      return [];
+    }
+  }
+
+  async deleteMessages(threadId: string): Promise<void> {
+    await this.initialize();
+    
+    try {
+      await alasql.promise(`DELETE FROM ${MESSAGES_TABLE} WHERE threadId = ?`, [threadId]);
+    } catch (error) {
+      console.error("Failed to delete messages:", error);
+      throw error;
+    }
+  }
+
+  // Utility methods
+  async clearAllData(): Promise<void> {
+    await this.initialize();
+    
+    try {
+      await alasql.promise(`DELETE FROM ${THREADS_TABLE}`);
+      await alasql.promise(`DELETE FROM ${MESSAGES_TABLE}`);
+    } catch (error) {
+      console.error("Failed to clear all data:", error);
+      throw error;
+    }
+  }
+
+  async resetDatabase(): Promise<void> {
+    try {
+      // Drop the entire database
+      await alasql.promise(`DROP LOCALSTORAGE DATABASE IF EXISTS ${DB_NAME}`);
+      this.initialized = false;
+      
+      // Reinitialize fresh
+      await this.initialize();
+      console.log("✅ Database reset and reinitialized");
+    } catch (error) {
+      console.error("Failed to reset database:", error);
+      throw error;
+    }
+  }
+
+  async clearOnlyMessages(): Promise<void> {
+    await this.initialize();
+    
+    try {
+      await alasql.promise(`DELETE FROM ${MESSAGES_TABLE}`);
+      console.log("✅ All messages cleared, threads preserved");
+    } catch (error) {
+      console.error("Failed to clear messages:", error);
+      throw error;
+    }
+  }
+
+  async clearOnlyThreads(): Promise<void> {
+    await this.initialize();
+    
+    try {
+      await alasql.promise(`DELETE FROM ${THREADS_TABLE}`);
+      await alasql.promise(`DELETE FROM ${MESSAGES_TABLE}`); // Clear orphaned messages
+      console.log("✅ All threads and messages cleared");
+    } catch (error) {
+      console.error("Failed to clear threads:", error);
+      throw error;
+    }
+  }
+
+  async exportData(): Promise<{ threads: ThreadData[]; messages: any[] }> {
+    await this.initialize();
+    
+    try {
+      const threads = await this.getAllThreads();
+      const messages = await alasql.promise(`SELECT * FROM ${MESSAGES_TABLE}`) as any[];
+      
+      return { threads, messages: Array.isArray(messages) ? messages : [] };
+    } catch (error) {
+      console.error("Failed to export data:", error);
+      throw error;
+    }
+  }
+
+  async importData(data: { threads: ThreadData[]; messages: any[] }): Promise<void> {
+    await this.initialize();
+    
+    try {
+      // Clear existing data
+      await this.clearAllData();
+      
+      // Import threads
+      for (const thread of data.threads) {
+        await this.saveThread(thread);
+      }
+      
+      // Import messages
+      for (const message of data.messages) {
+        await alasql.promise(`
+          INSERT INTO ${MESSAGES_TABLE} VALUES (?, ?, ?, ?, ?)
+        `, [message.id, message.threadId, message.role, message.text, message.timestamp]);
+      }
+    } catch (error) {
+      console.error("Failed to import data:", error);
+      throw error;
+    }
+  }
+}
+
+// Export singleton instance
+export const chatStorage = new ChatStorage(); 
\ No newline at end of file

From 01ed7ddab4242c0c3510ad5320371887ea187f85 Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Wed, 2 Jul 2025 21:12:04 +0500
Subject: [PATCH 16/54] Updated structure and added support for nested
 components. Action to rename components

---
 .../comps/comps/preLoadComp/actionConfigs.ts  | 588 +-----------------
 .../actions/componentConfiguration.ts         |  34 +
 .../preLoadComp/actions/componentEvents.ts    |  20 +
 .../preLoadComp/actions/componentLayout.ts    |  19 +
 .../actions/componentManagement.ts            | 441 +++++++++++++
 .../preLoadComp/actions/componentStyling.ts   |  34 +
 .../comps/comps/preLoadComp/actions/index.ts  |  14 +
 .../src/comps/comps/preLoadComp/utils.ts      |  86 ++-
 8 files changed, 668 insertions(+), 568 deletions(-)
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentEvents.ts
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentLayout.ts
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentStyling.ts
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
index d6bfb60bd0..2eae082a16 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
@@ -1,573 +1,27 @@
-import { message } from "antd";
-import { genRandomKey } from "comps/utils/idGenerator";
-import { parseCompType } from "comps/utils/remote";
-import { defaultLayout, GridItemDataType } from "comps/comps/gridItemComp";
-import { addMapChildAction } from "comps/generators/sameTypeMap";
-import { uiCompRegistry, UICompType } from "comps/uiCompRegistry";
-import { ActionConfig, ActionCategory, ActionExecuteParams } from "./types";
-import { 
-    multiChangeAction, 
-    wrapActionExtraInfo, 
-    changeValueAction, 
-    wrapChildAction, 
-    deleteCompAction 
-} from "lowcoder-core";
-
-// Component Management Actions
-const addComponentAction: ActionConfig = {
-  key: 'add-components',
-  label: 'Place a component',
-  category: 'component-management',
-  requiresComponentSelection: true,
-  requiresInput: false,
-  execute: async (params: ActionExecuteParams) => {
-    const { selectedComponent, editorState } = params;
-    
-    if (!selectedComponent || !editorState) {
-      message.error('Component and editor state are required');
-      return;
-    }
-
-    try {
-      // Get the UI component container
-      const uiComp = editorState.getUIComp();
-      const container = uiComp.getComp();
-      
-      if (!container) {
-        message.error('No container available to add component');
-        return;
-      }
-
-      // Get the simple container (the actual grid container)
-      const simpleContainer = container.realSimpleContainer();
-      if (!simpleContainer) {
-        message.error('No grid container available');
-        return;
-      }
-
-      // Generate component name and key
-      const nameGenerator = editorState.getNameGenerator();
-      const compInfo = parseCompType(selectedComponent);
-      const compName = nameGenerator.genItemName(compInfo.compName);
-      const key = genRandomKey();
-
-      // Get component manifest and default data
-      const manifest = uiCompRegistry[selectedComponent];
-      let defaultDataFn = undefined;
-
-      if (manifest?.lazyLoad) {
-        const { defaultDataFnName, defaultDataFnPath } = manifest;
-        if (defaultDataFnName && defaultDataFnPath) {
-          const module = await import(`../../${defaultDataFnPath}.tsx`);
-          defaultDataFn = module[defaultDataFnName];
-        }
-      } else if (!compInfo.isRemote) {
-        defaultDataFn = manifest?.defaultDataFn;
-      }
-
-      // Create component data
-      const widgetValue: GridItemDataType = {
-        compType: selectedComponent,
-        name: compName,
-        comp: defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined,
-      };
-
-      // Get current layout and calculate position
-      const currentLayout = simpleContainer.children.layout.getView();
-      const layoutInfo = manifest?.layoutInfo || defaultLayout(selectedComponent as UICompType);
-      
-      let itemPos = 0;
-      if (Object.keys(currentLayout).length > 0) {
-        itemPos = Math.min(...Object.values(currentLayout).map((l: any) => l.pos || 0)) - 1;
-      }
-
-      const layoutItem = {
-        i: key,
-        x: 0,
-        y: 0,
-        w: layoutInfo.w || 6,
-        h: layoutInfo.h || 5,
-        pos: itemPos,
-        isDragging: false,
-      };
-
-      // Dispatch the action to add the component
-      simpleContainer.dispatch(
-        wrapActionExtraInfo(
-          multiChangeAction({
-            layout: changeValueAction(
-              {
-                ...currentLayout,
-                [key]: layoutItem,
-              },
-              true
-            ),
-            items: addMapChildAction(key, widgetValue),
-          }),
-          { compInfos: [{ compName: compName, compType: selectedComponent, type: "add" }] }
-        )
-      );
-
-      editorState.setSelectedCompNames(new Set([compName]), "addComp");
-      
-      message.success(`Component "${manifest?.name || selectedComponent}" added successfully!`);
-    } catch (error) {
-      console.error('Error adding component:', error);
-      message.error('Failed to add component. Please try again.');
-    }
-  }
-};
-
-const moveComponentAction: ActionConfig = {
-  key: 'move-components',
-  label: 'Move a component',
-  category: 'component-management',
-  requiresEditorComponentSelection: true,
-  requiresInput: true,
-  inputPlaceholder: 'Enter move parameters (e.g., x:100, y:200)',
-  inputType: 'text',
-  validation: (value: string) => {
-    if (!value.trim()) return 'Move parameters are required';
-    
-    // Parse the input to validate format
-    const params = value.toLowerCase().split(',').map(p => p.trim());
-    for (const param of params) {
-      if (!param.includes(':')) {
-        return 'Invalid format. Use "x:value, y:value"';
-      }
-      const [key, val] = param.split(':').map(s => s.trim());
-      if (!['x', 'y'].includes(key)) {
-        return 'Only x and y parameters are supported';
-      }
-      const num = parseInt(val);
-      if (isNaN(num) || num < 0) {
-        return `${key} must be a positive number`;
-      }
-    }
-    return null;
-  },
-  execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, actionValue, editorState } = params;
-
-    if (!selectedEditorComponent || !editorState) {
-      message.error('Component and editor state are required');
-      return;
-    }
-
-    try {
-      // Parse move parameters
-      const moveParams: { x?: number; y?: number } = {};
-      const params = actionValue.toLowerCase().split(',').map(p => p.trim());
-      
-      for (const param of params) {
-        const [key, val] = param.split(':').map(s => s.trim());
-        if (['x', 'y'].includes(key)) {
-          moveParams[key as 'x' | 'y'] = parseInt(val);
-        }
-      }
-
-      if (!moveParams.x && !moveParams.y) {
-        message.error('No valid move parameters provided');
-        return;
-      }
-
-      // Get the UI component container
-      const uiComp = editorState.getUIComp();
-      const container = uiComp.getComp();
-      
-      if (!container) {
-        message.error('No container available');
-        return;
-      }
-
-      // Get the simple container (the actual grid container)
-      const simpleContainer = container.realSimpleContainer();
-      if (!simpleContainer) {
-        message.error('No grid container available');
-        return;
-      }
-
-      // Get current layout and items
-      const currentLayout = simpleContainer.children.layout.getView();
-      const items = simpleContainer.children.items.children;
-
-      // Find the component by name and get its key
-      let componentKey: string | null = null;
-      for (const [key, item] of Object.entries(items)) {
-        if ((item as any).children.name.getView() === selectedEditorComponent) {
-          componentKey = key;
-          break;
-        }
-      }
-
-      if (!componentKey || !currentLayout[componentKey]) {
-        message.error(`Component "${selectedEditorComponent}" not found in layout`);
-        return;
-      }
-
-      const currentLayoutItem = currentLayout[componentKey];
-
-      const newLayoutItem = {
-        ...currentLayoutItem,
-        x: moveParams.x !== undefined ? moveParams.x : currentLayoutItem.x,
-        y: moveParams.y !== undefined ? moveParams.y : currentLayoutItem.y,
-      };
-
-      const newLayout = {
-        ...currentLayout,
-        [componentKey]: newLayoutItem,
-      };
-
-      // Dispatch the action to update the layout
-      simpleContainer.dispatch(
-        wrapActionExtraInfo(
-          multiChangeAction({
-            layout: changeValueAction(newLayout, true),
-          }),
-          { 
-            compInfos: [{ 
-              compName: selectedEditorComponent, 
-              compType: (items[componentKey] as any).children.compType.getView(), 
-              type: "layout" 
-            }] 
-          }
-        )
-      );
-
-      editorState.setSelectedCompNames(new Set([selectedEditorComponent]), "moveComp");
-      
-      const moveDescription = [];
-      if (moveParams.x !== undefined) moveDescription.push(`x: ${moveParams.x}`);
-      if (moveParams.y !== undefined) moveDescription.push(`y: ${moveParams.y}`);
-      
-      message.success(`Component "${selectedEditorComponent}" moved to ${moveDescription.join(', ')}`);
-    } catch (error) {
-      console.error('Error moving component:', error);
-      message.error('Failed to move component. Please try again.');
-    }
-  }
-};
-
-const deleteComponentAction: ActionConfig = {
-  key: 'delete-components',
-  label: 'Delete a component',
-  category: 'component-management',
-  requiresEditorComponentSelection: true,
-  requiresInput: false,
-  execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, editorState } = params;
-    
-    if (!selectedEditorComponent || !editorState) {
-      message.error('Component and editor state are required');
-      return;
-    }
-
-    try {
-      // Get the UI component container
-      const uiComp = editorState.getUIComp();
-      const container = uiComp.getComp();
-      
-      if (!container) {
-        message.error('No container available');
-        return;
-      }
-
-      // Get the simple container (the actual grid container)
-      const simpleContainer = container.realSimpleContainer();
-      if (!simpleContainer) {
-        message.error('No grid container available');
-        return;
-      }
-
-      // Get current layout and items
-      const currentLayout = simpleContainer.children.layout.getView();
-      const items = simpleContainer.children.items.children;
-
-      // Find the component by name and get its key
-      let componentKey: string | null = null;
-      let componentType: string | null = null;
-      for (const [key, item] of Object.entries(items)) {
-        if ((item as any).children.name.getView() === selectedEditorComponent) {
-          componentKey = key;
-          componentType = (item as any).children.compType.getView();
-          break;
-        }
-      }
-
-      if (!componentKey || !currentLayout[componentKey]) {
-        message.error(`Component "${selectedEditorComponent}" not found in layout`);
-        return;
-      }
-
-      // Create new layout without the component
-      const newLayout = { ...currentLayout };
-      delete newLayout[componentKey];
-
-      // Dispatch the action to remove the component
-      simpleContainer.dispatch(
-        wrapActionExtraInfo(
-          multiChangeAction({
-            layout: changeValueAction(newLayout, true),
-            items: wrapChildAction(componentKey, deleteCompAction()),
-          }),
-          { 
-            compInfos: [{ 
-              compName: selectedEditorComponent, 
-              compType: componentType || 'unknown', 
-              type: "delete" 
-            }] 
-          }
-        )
-      );
-
-      editorState.setSelectedCompNames(new Set(), "deleteComp");
-      
-      message.success(`Component "${selectedEditorComponent}" deleted successfully`);
-    } catch (error) {
-      console.error('Error deleting component:', error);
-      message.error('Failed to delete component. Please try again.');
-    }
-  }
-};
-
-const resizeComponentAction: ActionConfig = {
-  key: 'resize-components',
-  label: 'Resize a component',
-  category: 'component-management',
-  requiresEditorComponentSelection: true,
-  requiresInput: true,
-  inputPlaceholder: 'Enter resize parameters (e.g., w:8, h:6)',
-  inputType: 'text',
-  validation: (value: string) => {
-    if (!value.trim()) return 'Resize parameters are required';
-    
-    // Parse the input to validate format
-    const params = value.toLowerCase().split(',').map(p => p.trim());
-    for (const param of params) {
-      if (!param.includes(':')) {
-        return 'Invalid format. Use "w:value, h:value"';
-      }
-      const [key, val] = param.split(':').map(s => s.trim());
-      if (!['w', 'h'].includes(key)) {
-        return 'Only w (width) and h (height) parameters are supported';
-      }
-      const num = parseInt(val);
-      if (isNaN(num) || num < 1) {
-        return `${key} must be a positive number greater than 0`;
-      }
-    }
-    return null;
-  },
-  execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, actionValue, editorState } = params;
-
-    if (!selectedEditorComponent || !editorState) {
-      message.error('Component and editor state are required');
-      return;
-    }
-
-    try {
-      // Parse resize parameters
-      const resizeParams: { w?: number; h?: number } = {};
-      const params = actionValue.toLowerCase().split(',').map(p => p.trim());
-      
-      for (const param of params) {
-        const [key, val] = param.split(':').map(s => s.trim());
-        if (['w', 'h'].includes(key)) {
-          resizeParams[key as 'w' | 'h'] = parseInt(val);
-        }
-      }
-
-      if (!resizeParams.w && !resizeParams.h) {
-        message.error('No valid resize parameters provided');
-        return;
-      }
-
-      // Get the UI component container
-      const uiComp = editorState.getUIComp();
-      const container = uiComp.getComp();
-      
-      if (!container) {
-        message.error('No container available');
-        return;
-      }
-
-      // Get the simple container (the actual grid container)
-      const simpleContainer = container.realSimpleContainer();
-      if (!simpleContainer) {
-        message.error('No grid container available');
-        return;
-      }
-
-      // Get current layout and items
-      const currentLayout = simpleContainer.children.layout.getView();
-      const items = simpleContainer.children.items.children;
-
-      // Find the component by name and get its key
-      let componentKey: string | null = null;
-      for (const [key, item] of Object.entries(items)) {
-        if ((item as any).children.name.getView() === selectedEditorComponent) {
-          componentKey = key;
-          break;
-        }
-      }
-
-      if (!componentKey || !currentLayout[componentKey]) {
-        message.error(`Component "${selectedEditorComponent}" not found in layout`);
-        return;
-      }
-
-      const currentLayoutItem = currentLayout[componentKey];
-      
-      const newLayoutItem = {
-        ...currentLayoutItem,
-        w: resizeParams.w !== undefined ? resizeParams.w : currentLayoutItem.w,
-        h: resizeParams.h !== undefined ? resizeParams.h : currentLayoutItem.h,
-      };
-
-      const newLayout = {
-        ...currentLayout,
-        [componentKey]: newLayoutItem,
-      };
-
-      // Dispatch the action to update the layout
-      simpleContainer.dispatch(
-        wrapActionExtraInfo(
-          multiChangeAction({
-            layout: changeValueAction(newLayout, true),
-          }),
-          { 
-            compInfos: [{ 
-              compName: selectedEditorComponent, 
-              compType: (items[componentKey] as any).children.compType.getView(), 
-              type: "layout" 
-            }] 
-          }
-        )
-      );
-
-      editorState.setSelectedCompNames(new Set([selectedEditorComponent]), "resizeComp");
-      
-      const resizeDescription = [];
-      if (resizeParams.w !== undefined) resizeDescription.push(`width: ${resizeParams.w}`);
-      if (resizeParams.h !== undefined) resizeDescription.push(`height: ${resizeParams.h}`);
-      
-      message.success(`Component "${selectedEditorComponent}" resized to ${resizeDescription.join(', ')}`);
-    } catch (error) {
-      console.error('Error resizing component:', error);
-      message.error('Failed to resize component. Please try again.');
-    }
-  }
-};
-
-// Component Configuration Actions
-const configureComponentAction: ActionConfig = {
-  key: 'configure-components',
-  label: 'Configure a component',
-  category: 'component-configuration',
-  requiresEditorComponentSelection: true,
-  requiresInput: true,
-  inputPlaceholder: 'Enter configuration (JSON format)',
-  inputType: 'json',
-  validation: (value: string) => {
-    if (!value.trim()) return 'Configuration is required';
-    try {
-      JSON.parse(value);
-      return null;
-    } catch {
-      return 'Invalid JSON format';
-    }
-  },
-  execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, actionValue } = params;
-    
-    try {
-      const config = JSON.parse(actionValue);
-      console.log('Configuring component:', selectedEditorComponent, 'with config:', config);
-      message.info(`Configure action for component "${selectedEditorComponent}"`);
-      
-      // TODO: Implement actual configuration logic
-    } catch (error) {
-      message.error('Invalid configuration format');
-    }
-  }
-};
-
-// Layout Actions
-const changeLayoutAction: ActionConfig = {
-  key: 'change-layout',
-  label: 'Change layout',
-  category: 'layout',
-  requiresInput: true,
-  inputPlaceholder: 'Enter layout type (grid, flex, absolute)',
-  inputType: 'text',
-  execute: async (params: ActionExecuteParams) => {
-    const { actionValue } = params;
-    
-    console.log('Changing layout to:', actionValue);
-    message.info(`Layout changed to: ${actionValue}`);
-    
-    // TODO: Implement actual layout change logic
-  }
-};
-
-// Event Actions
-const addEventHandlerAction: ActionConfig = {
-  key: 'add-event-handler',
-  label: 'Add event handler',
-  category: 'events',
-  requiresEditorComponentSelection: true,
-  requiresInput: true,
-  inputPlaceholder: 'Enter event handler code (JavaScript)',
-  inputType: 'textarea',
-  execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, actionValue } = params;
-    
-    console.log('Adding event handler to component:', selectedEditorComponent, 'with code:', actionValue);
-    message.info(`Event handler added to component "${selectedEditorComponent}"`);
-    
-    // TODO: Implement actual event handler logic
-  }
-};
-
-// Style Actions
-const applyStyleAction: ActionConfig = {
-  key: 'apply-style',
-  label: 'Apply style to component',
-  category: 'styling',
-  requiresEditorComponentSelection: true,
-  requiresInput: true,
-  inputPlaceholder: 'Enter CSS styles (JSON format)',
-  inputType: 'json',
-  validation: (value: string) => {
-    if (!value.trim()) return 'Styles are required';
-    try {
-      JSON.parse(value);
-      return null;
-    } catch {
-      return 'Invalid JSON format';
-    }
-  },
-  execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, actionValue } = params;
-    
-    try {
-      const styles = JSON.parse(actionValue);
-      console.log('Applying styles to component:', selectedEditorComponent, 'with styles:', styles);
-      message.info(`Styles applied to component "${selectedEditorComponent}"`);
-      
-      // TODO: Implement actual style application logic
-    } catch (error) {
-      message.error('Invalid style format');
-    }
-  }
-};
+import { ActionCategory } from "./types";
+import {
+  addComponentAction,
+  moveComponentAction,
+  renameComponentAction,
+  deleteComponentAction,
+  resizeComponentAction,
+  configureComponentAction,
+  changeLayoutAction,
+  addEventHandlerAction,
+  applyStyleAction
+} from "./actions";
 
 export const actionCategories: ActionCategory[] = [
   {
     key: 'component-management',
     label: 'Component Management',
-    actions: [addComponentAction, moveComponentAction, deleteComponentAction, resizeComponentAction]
+    actions: [
+      addComponentAction, 
+      moveComponentAction, 
+      deleteComponentAction, 
+      resizeComponentAction,
+      renameComponentAction
+    ]
   },
   {
     key: 'component-configuration',
@@ -591,7 +45,7 @@ export const actionCategories: ActionCategory[] = [
   }
 ];
 
-export const actionRegistry = new Map<string, ActionConfig>();
+export const actionRegistry = new Map<string, any>();
 actionCategories.forEach(category => {
   category.actions.forEach(action => {
     actionRegistry.set(action.key, action);
@@ -617,4 +71,4 @@ export const getAllActionItems = () => {
         }))
       }];
     });
-  };
\ No newline at end of file
+  }; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts
new file mode 100644
index 0000000000..2106b1eda9
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts
@@ -0,0 +1,34 @@
+import { message } from "antd";
+import { ActionConfig, ActionExecuteParams } from "../types";
+
+export const configureComponentAction: ActionConfig = {
+  key: 'configure-components',
+  label: 'Configure a component',
+  category: 'component-configuration',
+  requiresEditorComponentSelection: true,
+  requiresInput: true,
+  inputPlaceholder: 'Enter configuration (JSON format)',
+  inputType: 'json',
+  validation: (value: string) => {
+    if (!value.trim()) return 'Configuration is required';
+    try {
+      JSON.parse(value);
+      return null;
+    } catch {
+      return 'Invalid JSON format';
+    }
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, actionValue } = params;
+    
+    try {
+      const config = JSON.parse(actionValue);
+      console.log('Configuring component:', selectedEditorComponent, 'with config:', config);
+      message.info(`Configure action for component "${selectedEditorComponent}"`);
+      
+      // TODO: Implement actual configuration logic
+    } catch (error) {
+      message.error('Invalid configuration format');
+    }
+  }
+}; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentEvents.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentEvents.ts
new file mode 100644
index 0000000000..cf007c5afa
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentEvents.ts
@@ -0,0 +1,20 @@
+import { message } from "antd";
+import { ActionConfig, ActionExecuteParams } from "../types";
+
+export const addEventHandlerAction: ActionConfig = {
+  key: 'add-event-handler',
+  label: 'Add event handler',
+  category: 'events',
+  requiresEditorComponentSelection: true,
+  requiresInput: true,
+  inputPlaceholder: 'Enter event handler code (JavaScript)',
+  inputType: 'textarea',
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, actionValue } = params;
+    
+    console.log('Adding event handler to component:', selectedEditorComponent, 'with code:', actionValue);
+    message.info(`Event handler added to component "${selectedEditorComponent}"`);
+    
+    // TODO: Implement actual event handler logic
+  }
+}; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentLayout.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentLayout.ts
new file mode 100644
index 0000000000..e4afa15cab
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentLayout.ts
@@ -0,0 +1,19 @@
+import { message } from "antd";
+import { ActionConfig, ActionExecuteParams } from "../types";
+
+export const changeLayoutAction: ActionConfig = {
+  key: 'change-layout',
+  label: 'Change layout',
+  category: 'layout',
+  requiresInput: true,
+  inputPlaceholder: 'Enter layout type (grid, flex, absolute)',
+  inputType: 'text',
+  execute: async (params: ActionExecuteParams) => {
+    const { actionValue } = params;
+    
+    console.log('Changing layout to:', actionValue);
+    message.info(`Layout changed to: ${actionValue}`);
+    
+    // TODO: Implement actual layout change logic
+  }
+}; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
new file mode 100644
index 0000000000..f86358b164
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
@@ -0,0 +1,441 @@
+import { message } from "antd";
+import { genRandomKey } from "comps/utils/idGenerator";
+import { parseCompType } from "comps/utils/remote";
+import { defaultLayout, GridItemDataType } from "comps/comps/gridItemComp";
+import { addMapChildAction } from "comps/generators/sameTypeMap";
+import { uiCompRegistry, UICompType } from "comps/uiCompRegistry";
+import { ActionConfig, ActionExecuteParams } from "../types";
+import { 
+    multiChangeAction, 
+    wrapActionExtraInfo, 
+    changeValueAction, 
+    wrapChildAction, 
+    deleteCompAction 
+} from "lowcoder-core";
+import { getEditorComponentInfo } from "../utils";
+
+export const addComponentAction: ActionConfig = {
+  key: 'add-components',
+  label: 'Place a component',
+  category: 'component-management',
+  requiresComponentSelection: true,
+  requiresInput: false,
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedComponent, editorState } = params;
+    
+    if (!selectedComponent || !editorState) {
+      message.error('Component and editor state are required');
+      return;
+    }
+
+    try {
+      const uiComp = editorState.getUIComp();
+      const container = uiComp.getComp();
+      
+      if (!container) {
+        message.error('No container available to add component');
+        return;
+      }
+
+      const simpleContainer = container.realSimpleContainer();
+      if (!simpleContainer) {
+        message.error('No grid container available');
+        return;
+      }
+
+      const nameGenerator = editorState.getNameGenerator();
+      const compInfo = parseCompType(selectedComponent);
+      const compName = nameGenerator.genItemName(compInfo.compName);
+      const key = genRandomKey();
+
+      const manifest = uiCompRegistry[selectedComponent];
+      let defaultDataFn = undefined;
+
+      if (manifest?.lazyLoad) {
+        const { defaultDataFnName, defaultDataFnPath } = manifest;
+        if (defaultDataFnName && defaultDataFnPath) {
+          const module = await import(`../../../${defaultDataFnPath}.tsx`);
+          defaultDataFn = module[defaultDataFnName];
+        }
+      } else if (!compInfo.isRemote) {
+        defaultDataFn = manifest?.defaultDataFn;
+      }
+
+      const widgetValue: GridItemDataType = {
+        compType: selectedComponent,
+        name: compName,
+        comp: defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined,
+      };
+
+      const currentLayout = simpleContainer.children.layout.getView();
+      const layoutInfo = manifest?.layoutInfo || defaultLayout(selectedComponent as UICompType);
+      
+      let itemPos = 0;
+      if (Object.keys(currentLayout).length > 0) {
+        itemPos = Math.min(...Object.values(currentLayout).map((l: any) => l.pos || 0)) - 1;
+      }
+
+      const layoutItem = {
+        i: key,
+        x: 0,
+        y: 0,
+        w: layoutInfo.w || 6,
+        h: layoutInfo.h || 5,
+        pos: itemPos,
+        isDragging: false,
+      };
+
+      simpleContainer.dispatch(
+        wrapActionExtraInfo(
+          multiChangeAction({
+            layout: changeValueAction({
+              ...currentLayout,
+              [key]: layoutItem,
+            }, true),
+            items: addMapChildAction(key, widgetValue),
+          }),
+          { compInfos: [{ compName: compName, compType: selectedComponent, type: "add" }] }
+        )
+      );
+
+      editorState.setSelectedCompNames(new Set([compName]), "addComp");
+      
+      message.success(`Component "${manifest?.name || selectedComponent}" added successfully!`);
+    } catch (error) {
+      console.error('Error adding component:', error);
+      message.error('Failed to add component. Please try again.');
+    }
+  }
+};
+
+export const deleteComponentAction: ActionConfig = {
+  key: 'delete-components',
+  label: 'Delete a component',
+  category: 'component-management',
+  requiresEditorComponentSelection: true,
+  requiresInput: false,
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, editorState } = params;
+    
+    if (!selectedEditorComponent || !editorState) {
+      message.error('Component and editor state are required');
+      return;
+    }
+
+    try {
+      const componentInfo = getEditorComponentInfo(editorState, selectedEditorComponent);
+      
+      if (!componentInfo) {
+        message.error(`Component "${selectedEditorComponent}" not found`);
+        return;
+      }
+
+      const { componentKey, currentLayout, simpleContainer, componentType } = componentInfo;
+
+      if (!componentKey || !currentLayout[componentKey]) {
+        message.error(`Component "${selectedEditorComponent}" not found in layout`);
+        return;
+      }
+
+      const newLayout = { ...currentLayout };
+      delete newLayout[componentKey];
+
+      simpleContainer.dispatch(
+        wrapActionExtraInfo(
+          multiChangeAction({
+            layout: changeValueAction(newLayout, true),
+            items: wrapChildAction(componentKey, deleteCompAction()),
+          }),
+          { 
+            compInfos: [{ 
+              compName: selectedEditorComponent, 
+              compType: componentType || 'unknown', 
+              type: "delete" 
+            }] 
+          }
+        )
+      );
+
+      editorState.setSelectedCompNames(new Set(), "deleteComp");
+      
+      message.success(`Component "${selectedEditorComponent}" deleted successfully`);
+    } catch (error) {
+      console.error('Error deleting component:', error);
+      message.error('Failed to delete component. Please try again.');
+    }
+  }
+};
+
+export const moveComponentAction: ActionConfig = {
+  key: 'move-components',
+  label: 'Move a component',
+  category: 'component-management',
+  requiresEditorComponentSelection: true,
+  requiresInput: true,
+  inputPlaceholder: 'Enter move parameters (e.g., x:100, y:200)',
+  inputType: 'text',
+  validation: (value: string) => {
+    if (!value.trim()) return 'Move parameters are required';
+    
+    const params = value.toLowerCase().split(',').map(p => p.trim());
+    for (const param of params) {
+      if (!param.includes(':')) {
+        return 'Invalid format. Use "x:value, y:value"';
+      }
+      const [key, val] = param.split(':').map(s => s.trim());
+      if (!['x', 'y'].includes(key)) {
+        return 'Only x and y parameters are supported';
+      }
+      const num = parseInt(val);
+      if (isNaN(num) || num < 0) {
+        return `${key} must be a positive number`;
+      }
+    }
+    return null;
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, actionValue, editorState } = params;
+
+    if (!selectedEditorComponent || !editorState) {
+      message.error('Component and editor state are required');
+      return;
+    }
+
+    try {
+      const moveParams: { x?: number; y?: number } = {};
+      const params = actionValue.toLowerCase().split(',').map(p => p.trim());
+      
+      for (const param of params) {
+        const [key, val] = param.split(':').map(s => s.trim());
+        if (['x', 'y'].includes(key)) {
+          moveParams[key as 'x' | 'y'] = parseInt(val);
+        }
+      }
+
+      if (!moveParams.x && !moveParams.y) {
+        message.error('No valid move parameters provided');
+        return;
+      }
+
+      const componentInfo = getEditorComponentInfo(editorState, selectedEditorComponent);
+      
+      if (!componentInfo) {
+        message.error(`Component "${selectedEditorComponent}" not found`);
+        return;
+      }
+
+      const { componentKey, currentLayout, simpleContainer } = componentInfo;
+
+      if (!componentKey || !currentLayout[componentKey]) {
+        message.error(`Component "${selectedEditorComponent}" not found in layout`);
+        return;
+      }
+
+      const currentLayoutItem = currentLayout[componentKey];
+      const items = simpleContainer.children.items.children;
+
+      const newLayoutItem = {
+        ...currentLayoutItem,
+        x: moveParams.x !== undefined ? moveParams.x : currentLayoutItem.x,
+        y: moveParams.y !== undefined ? moveParams.y : currentLayoutItem.y,
+      };
+
+      const newLayout = {
+        ...currentLayout,
+        [componentKey]: newLayoutItem,
+      };
+
+      simpleContainer.dispatch(
+        wrapActionExtraInfo(
+          multiChangeAction({
+            layout: changeValueAction(newLayout, true),
+          }),
+          { 
+            compInfos: [{ 
+              compName: selectedEditorComponent, 
+              compType: (items[componentKey] as any).children.compType.getView(), 
+              type: "layout" 
+            }] 
+          }
+        )
+      );
+
+      editorState.setSelectedCompNames(new Set([selectedEditorComponent]), "moveComp");
+      
+      const moveDescription = [];
+      if (moveParams.x !== undefined) moveDescription.push(`x: ${moveParams.x}`);
+      if (moveParams.y !== undefined) moveDescription.push(`y: ${moveParams.y}`);
+      
+      message.success(`Component "${selectedEditorComponent}" moved to ${moveDescription.join(', ')}`);
+    } catch (error) {
+      console.error('Error moving component:', error);
+      message.error('Failed to move component. Please try again.');
+    }
+  }
+};
+
+export const renameComponentAction: ActionConfig = {
+  key: 'rename-components',
+  label: 'Rename a component',
+  category: 'component-management',
+  requiresEditorComponentSelection: true,
+  requiresInput: true,
+  inputPlaceholder: 'Enter new name',
+  inputType: 'text',
+  validation: (value: string, params?: ActionExecuteParams) => {
+    if (!value.trim()) return 'Name is required';
+    
+    if (params?.editorState && params?.selectedEditorComponent) {
+      const error = params.editorState.checkRename(params.selectedEditorComponent, value);
+      return error || null;
+    }
+    return null;
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, actionValue, editorState } = params;
+    
+    if (!selectedEditorComponent || !actionValue) {
+      message.error('Component and name is required');
+      return;
+    }
+
+    try {
+      const componentInfo = getEditorComponentInfo(editorState, selectedEditorComponent);
+      
+      if (!componentInfo) {
+        message.error(`Component "${selectedEditorComponent}" not found`);
+        return;
+      }
+
+      const { componentKey, currentLayout, items } = componentInfo;
+
+      if (!componentKey) {
+        message.error(`Component "${selectedEditorComponent}" not found in layout`);
+        return;
+      }
+
+      const componentItem = items[componentKey];
+      if (!componentItem) {
+        message.error(`Component "${selectedEditorComponent}" not found in items`);
+        return;
+      }
+
+      if (editorState.rename(selectedEditorComponent, actionValue)) {
+        editorState.setSelectedCompNames(new Set([actionValue]), "renameComp");
+        message.success(`Component "${selectedEditorComponent}" renamed to "${actionValue}" successfully`);
+      } else {
+        message.error('Failed to rename component. The name might already exist or be invalid.');
+      }
+    } catch(error) {
+      console.error('Error renaming component:', error);
+      message.error('Failed to rename component. Please try again.');
+    }
+  }
+};
+
+export const resizeComponentAction: ActionConfig = {
+  key: 'resize-components',
+  label: 'Resize a component',
+  category: 'component-management',
+  requiresEditorComponentSelection: true,
+  requiresInput: true,
+  inputPlaceholder: 'Enter resize parameters (e.g., w:8, h:6)',
+  inputType: 'text',
+  validation: (value: string) => {
+    if (!value.trim()) return 'Resize parameters are required';
+    
+    const params = value.toLowerCase().split(',').map(p => p.trim());
+    for (const param of params) {
+      if (!param.includes(':')) {
+        return 'Invalid format. Use "w:value, h:value"';
+      }
+      const [key, val] = param.split(':').map(s => s.trim());
+      if (!['w', 'h'].includes(key)) {
+        return 'Only w (width) and h (height) parameters are supported';
+      }
+      const num = parseInt(val);
+      if (isNaN(num) || num < 1) {
+        return `${key} must be a positive number greater than 0`;
+      }
+    }
+    return null;
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, actionValue, editorState } = params;
+
+    if (!selectedEditorComponent || !editorState) {
+      message.error('Component and editor state are required');
+      return;
+    }
+
+    try {
+      const resizeParams: { w?: number; h?: number } = {};
+      const params = actionValue.toLowerCase().split(',').map(p => p.trim());
+      
+      for (const param of params) {
+        const [key, val] = param.split(':').map(s => s.trim());
+        if (['w', 'h'].includes(key)) {
+          resizeParams[key as 'w' | 'h'] = parseInt(val);
+        }
+      }
+
+      if (!resizeParams.w && !resizeParams.h) {
+        message.error('No valid resize parameters provided');
+        return;
+      }
+
+      const componentInfo = getEditorComponentInfo(editorState, selectedEditorComponent);
+      
+      if (!componentInfo) {
+        message.error(`Component "${selectedEditorComponent}" not found`);
+        return;
+      }
+
+      const { componentKey, currentLayout, simpleContainer, items } = componentInfo;
+
+      if (!componentKey || !currentLayout[componentKey]) {
+        message.error(`Component "${selectedEditorComponent}" not found in layout`);
+        return;
+      }
+
+      const currentLayoutItem = currentLayout[componentKey];
+      
+      const newLayoutItem = {
+        ...currentLayoutItem,
+        w: resizeParams.w !== undefined ? resizeParams.w : currentLayoutItem.w,
+        h: resizeParams.h !== undefined ? resizeParams.h : currentLayoutItem.h,
+      };
+
+      const newLayout = {
+        ...currentLayout,
+        [componentKey]: newLayoutItem,
+      };
+
+      simpleContainer.dispatch(
+        wrapActionExtraInfo(
+          multiChangeAction({
+            layout: changeValueAction(newLayout, true),
+          }),
+          { 
+            compInfos: [{ 
+              compName: selectedEditorComponent, 
+              compType: (items[componentKey] as any).children.compType.getView(), 
+              type: "layout" 
+            }] 
+          }
+        )
+      );
+
+      editorState.setSelectedCompNames(new Set([selectedEditorComponent]), "resizeComp");
+      
+      const resizeDescription = [];
+      if (resizeParams.w !== undefined) resizeDescription.push(`width: ${resizeParams.w}`);
+      if (resizeParams.h !== undefined) resizeDescription.push(`height: ${resizeParams.h}`);
+      
+      message.success(`Component "${selectedEditorComponent}" resized to ${resizeDescription.join(', ')}`);
+    } catch (error) {
+      console.error('Error resizing component:', error);
+      message.error('Failed to resize component. Please try again.');
+    }
+  }
+};
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentStyling.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentStyling.ts
new file mode 100644
index 0000000000..2a152713ea
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentStyling.ts
@@ -0,0 +1,34 @@
+import { message } from "antd";
+import { ActionConfig, ActionExecuteParams } from "../types";
+
+export const applyStyleAction: ActionConfig = {
+  key: 'apply-style',
+  label: 'Apply style to component',
+  category: 'styling',
+  requiresEditorComponentSelection: true,
+  requiresInput: true,
+  inputPlaceholder: 'Enter CSS styles (JSON format)',
+  inputType: 'json',
+  validation: (value: string) => {
+    if (!value.trim()) return 'Styles are required';
+    try {
+      JSON.parse(value);
+      return null;
+    } catch {
+      return 'Invalid JSON format';
+    }
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, actionValue } = params;
+    
+    try {
+      const styles = JSON.parse(actionValue);
+      console.log('Applying styles to component:', selectedEditorComponent, 'with styles:', styles);
+      message.info(`Styles applied to component "${selectedEditorComponent}"`);
+      
+      // TODO: Implement actual style application logic
+    } catch (error) {
+      message.error('Invalid style format');
+    }
+  }
+}; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts
new file mode 100644
index 0000000000..8400000505
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts
@@ -0,0 +1,14 @@
+// Component Management Actions
+export * from './componentManagement';
+
+// Component Configuration Actions
+export { configureComponentAction } from './componentConfiguration';
+
+// Layout Actions
+export { changeLayoutAction } from './componentLayout';
+
+// Event Actions
+export { addEventHandlerAction } from './componentEvents';
+
+// Styling Actions
+export { applyStyleAction } from './componentStyling'; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
index 86625db0d5..3f3ae1b739 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
@@ -4,6 +4,7 @@ import log from "loglevel";
 import { UICompCategory, UICompManifest, uiCompCategoryNames, uiCompRegistry } from "comps/uiCompRegistry";
 import { MenuProps } from "antd/es/menu";
 import React from "react";
+import { EditorState } from "@lowcoder-ee/comps/editorState";
 
 export function runScript(code: string, inHost?: boolean) {
   if (inHost) {
@@ -52,4 +53,87 @@ export function getComponentCategories() {
     });
   });
   return cats;
-} 
\ No newline at end of file
+} 
+export function getEditorComponentInfo(editorState: EditorState, componentName: string): {
+  componentKey: string | null;
+  currentLayout: any;
+  simpleContainer: any;
+  componentType?: string | null;
+  items: any;
+} | null {
+  try {
+    // Get the UI component container
+    if (!editorState || !componentName) {
+      return null;
+    }
+
+    const uiComp = editorState.getUIComp();
+    const container = uiComp.getComp();
+    if (!container) {
+      return null;
+    }
+
+    const uiCompTree = uiComp.getTree();
+
+    // Get the simple container (the actual grid container)
+    const simpleContainer = container.realSimpleContainer();
+    if (!simpleContainer) {
+      return null;
+    }
+
+    // Get current layout and items
+    const currentLayout = simpleContainer.children.layout.getView();
+    const items = getCombinedItems(uiCompTree);
+
+    // Find the component by name and get its key
+    let componentKey: string | null = null;
+    let componentType: string | null = null;
+
+    for (const [key, item] of Object.entries(items)) {
+      if ((item as any).children.name.getView() === componentName) {
+        componentKey = key;
+        componentType = (item as any).children.compType.getView();
+        break
+      }
+    }
+
+    return {
+      componentKey,
+      currentLayout,
+      simpleContainer,
+      componentType,
+      items,
+    };  
+  } catch(error) {
+    console.error('Error getting editor component key:', error);
+    return null;
+  }
+}
+
+interface Container {
+  items?: Record<string, any>; 
+}
+
+function getCombinedItems(uiCompTree: any) {
+  const combined: Record<string, any> = {};
+
+  if (uiCompTree.items) {
+    Object.entries(uiCompTree.items).forEach(([itemKey, itemValue]) => {
+      combined[itemKey] = itemValue;
+    });
+  }
+
+  if (uiCompTree.children) {
+    Object.entries(uiCompTree.children).forEach(([parentKey, container]) => {
+      const typedContainer = container as Container; 
+      if (typedContainer.items) {
+        Object.entries(typedContainer.items).forEach(([itemKey, itemValue]) => {
+          itemValue.parentContainer = parentKey;
+          combined[itemKey] = itemValue;
+        });
+      }
+    });
+  }
+
+  return combined;
+}

From f379cac8e62f5f696cf84a9d342bb0beefa2d1af Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Wed, 2 Jul 2025 21:58:29 +0500
Subject: [PATCH 17/54] delete myruntime provider

---
 .../components/context/MyRuntimeProvider.tsx  | 155 ------------------
 1 file changed, 155 deletions(-)
 delete mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
deleted file mode 100644
index 81143047ef..0000000000
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/MyRuntimeProvider.tsx
+++ /dev/null
@@ -1,155 +0,0 @@
-import { useState } from "react";
-import {
-  useExternalStoreRuntime,
-  ThreadMessageLike,
-  AppendMessage,
-  AssistantRuntimeProvider,
-  ExternalStoreThreadData,
-  ExternalStoreThreadListAdapter,
-} from "@assistant-ui/react";
-
-// Define your custom message type
-interface MyMessage {
-  id: string;
-  role: "user" | "assistant";
-  text: string;
-  timestamp: number;
-}
-
-const generateId = () => Math.random().toString(36).substr(2, 9);
-
-const callYourAPI = async (text: string) => {
-    // Simulate API delay
-    await new Promise(resolve => setTimeout(resolve, 1500));
-    
-    // Simple responses
-    return {
-      content: "This is a mock response from your backend. You typed: " + text
-    };
-};
-
-export function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
-    // Use your custom message type in state
-    const [myMessages, setMyMessages] = useState<MyMessage[]>([]);
-    const [isRunning, setIsRunning] = useState(false);
-
-    // Convert your custom format to ThreadMessageLike
-    const convertMessage = (message: MyMessage): ThreadMessageLike => ({
-        role: message.role,
-        content: [{ type: "text", text: message.text }],
-        id: message.id,
-        createdAt: new Date(message.timestamp),
-      });
-  
-    const onNew = async (message: AppendMessage) => {
-      // Extract text from AppendMessage content array
-      if (message.content.length !== 1 || message.content[0]?.type !== "text") {
-        throw new Error("Only text content is supported");
-      }
-
-      // Add user message in your custom format
-      const userMessage: MyMessage = {
-        id: generateId(),
-        role: "user",
-        text: message.content[0].text,
-        timestamp: Date.now(),
-      };
-      
-      setMyMessages(prev => [...prev, userMessage]);
-      setIsRunning(true);
-  
-      try {
-        // Call mock API
-        const response = await callYourAPI(userMessage.text);
-        
-        const assistantMessage: MyMessage = {
-          id: generateId(),
-          role: "assistant",
-          text: response.content,
-          timestamp: Date.now(),
-        };
-        
-        setMyMessages(prev => [...prev, assistantMessage]);
-      } catch (error) {
-        // Handle errors gracefully
-        const errorMessage: MyMessage = {
-          id: generateId(),
-          role: "assistant", 
-          text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}. This is expected in mock mode for testing error handling.`,
-          timestamp: Date.now(),
-        };
-        
-        setMyMessages(prev => [...prev, errorMessage]);
-      } finally {
-        setIsRunning(false);
-      }
-    };
-
-    // Add onEdit functionality
-    const onEdit = async (message: AppendMessage) => {
-      // Extract text from AppendMessage content array
-      if (message.content.length !== 1 || message.content[0]?.type !== "text") {
-        throw new Error("Only text content is supported");
-      }
-
-      // Find the index where to insert the edited message
-      const index = myMessages.findIndex((m) => m.id === message.parentId) + 1;
-
-      // Keep messages up to the parent
-      const newMessages = [...myMessages.slice(0, index)];
-
-      // Add the edited message in your custom format
-      const editedMessage: MyMessage = {
-        id: generateId(), // Always generate new ID for edited messages
-        role: "user",
-        text: message.content[0].text,
-        timestamp: Date.now(),
-      };
-      newMessages.push(editedMessage);
-
-      setMyMessages(newMessages);
-      setIsRunning(true);
-
-      try {
-        // Generate new response
-        const response = await callYourAPI(editedMessage.text);
-        
-        const assistantMessage: MyMessage = {
-          id: generateId(),
-          role: "assistant",
-          text: response.content,
-          timestamp: Date.now(),
-        };
-        
-        newMessages.push(assistantMessage);
-        setMyMessages(newMessages);
-      } catch (error) {
-        // Handle errors gracefully
-        const errorMessage: MyMessage = {
-          id: generateId(),
-          role: "assistant", 
-          text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
-          timestamp: Date.now(),
-        };
-        
-        newMessages.push(errorMessage);
-        setMyMessages(newMessages);
-      } finally {
-        setIsRunning(false);
-      }
-    };
-  
-    const runtime = useExternalStoreRuntime({
-      messages: myMessages,        // Your custom message array
-      convertMessage,              // Conversion function
-      isRunning,
-      onNew,
-      onEdit,                     // Enable message editing
-    });
-  
-    return (
-      <AssistantRuntimeProvider runtime={runtime}>
-        {children}
-      </AssistantRuntimeProvider>
-    );
-}
\ No newline at end of file

From e553d52c769811ec20f5e7909872c7ac56b06572 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Thu, 3 Jul 2025 15:54:40 +0500
Subject: [PATCH 18/54] add storage support

---
 .../chatComp/components/ChatWithThreads.tsx   | 141 +++++-------------
 .../comps/chatComp/hooks/useChatStorage.ts    | 139 +++++++++++++++++
 2 files changed, 175 insertions(+), 105 deletions(-)
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/hooks/useChatStorage.ts

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx
index a5e43afc2f..7a9101a838 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx
@@ -10,6 +10,27 @@ import { useThreadContext, MyMessage, ThreadProvider } from "./context/ThreadCon
 import { Thread } from "./assistant-ui/thread";
 import { ThreadList } from "./assistant-ui/thread-list";
 import { chatStorage, ThreadData as StoredThreadData } from "../utils/chatStorage";
+import { useChatStorage } from "../hooks/useChatStorage";
+import styled from "styled-components";
+
+
+
+
+const ChatContainer = styled.div`
+  display: flex;
+  height: 500px;
+
+  .aui-thread-list-root {
+    width: 250px;
+    background-color: #333;
+  }
+
+  .aui-thread-root {
+    flex: 1;
+    background-color: #f0f0f0;
+  }
+
+`;
 
 // Define thread data interfaces to match ExternalStoreThreadData requirements
 interface RegularThreadData {
@@ -45,109 +66,13 @@ function ChatWithThreads() {
   const [threadList, setThreadList] = useState<ThreadData[]>([
     { threadId: "default", status: "regular", title: "New Chat" } as RegularThreadData,
   ]);
-  const [isInitialized, setIsInitialized] = useState(false);
-
-  // Load data from persistent storage on component mount
-  useEffect(() => {
-    const loadData = async () => {
-      try {
-        await chatStorage.initialize();
-        
-        // Load all threads from storage
-        const storedThreads = await chatStorage.getAllThreads();
-        if (storedThreads.length > 0) {
-          // Convert stored threads to UI format
-          const uiThreads: ThreadData[] = storedThreads.map(stored => ({
-            threadId: stored.threadId,
-            status: stored.status as "regular" | "archived",
-            title: stored.title,
-          }));
-          setThreadList(uiThreads);
-          
-          // Load messages for each thread
-          const threadMessages = new Map<string, MyMessage[]>();
-          for (const thread of storedThreads) {
-            const messages = await chatStorage.getMessages(thread.threadId);
-            threadMessages.set(thread.threadId, messages);
-          }
-          
-          // Ensure default thread exists
-          if (!threadMessages.has("default")) {
-            threadMessages.set("default", []);
-          }
-          
-          setThreads(threadMessages);
-          
-          // Set current thread to the most recently updated one
-          const latestThread = storedThreads.sort((a, b) => b.updatedAt - a.updatedAt)[0];
-          if (latestThread) {
-            setCurrentThreadId(latestThread.threadId);
-          }
-        } else {
-          // Initialize with default thread
-          const defaultThread: StoredThreadData = {
-            threadId: "default",
-            status: "regular",
-            title: "New Chat",
-            createdAt: Date.now(),
-            updatedAt: Date.now(),
-          };
-          await chatStorage.saveThread(defaultThread);
-        }
-        
-        setIsInitialized(true);
-      } catch (error) {
-        console.error("Failed to load chat data:", error);
-        setIsInitialized(true); // Continue with default state
-      }
-    };
-
-    loadData();
-  }, [setCurrentThreadId, setThreads]);
-
-  // Save thread data whenever threadList changes
-  useEffect(() => {
-    if (!isInitialized) return;
-    
-    const saveThreads = async () => {
-      try {
-        for (const thread of threadList) {
-          const storedThread: StoredThreadData = {
-            threadId: thread.threadId,
-            status: thread.status,
-            title: thread.title,
-            createdAt: Date.now(), // In real app, preserve original createdAt
-            updatedAt: Date.now(),
-          };
-          await chatStorage.saveThread(storedThread);
-        }
-      } catch (error) {
-        console.error("Failed to save threads:", error);
-      }
-    };
-
-    saveThreads();
-  }, [threadList, isInitialized]);
-
-  // Save messages whenever threads change
-  useEffect(() => {
-    if (!isInitialized) return;
-    
-    const saveMessages = async () => {
-      try {
-        for (const [threadId, messages] of threads.entries()) {
-          await chatStorage.saveMessages(messages, threadId);
-        }
-      } catch (error) {
-        console.error("Failed to save messages:", error);
-      }
-    };
-
-    saveMessages();
-  }, [threads, isInitialized]);
-
-  
-
+  const { isInitialized } = useChatStorage({
+    threadList,
+    threads,
+    setThreadList,
+    setThreads,
+    setCurrentThreadId,
+  });
   // Get messages for current thread
   const currentMessages = threads.get(currentThreadId) || [];
 
@@ -349,10 +274,16 @@ function ChatWithThreads() {
     },
   });
 
+  if (!isInitialized) {
+    return <div>Loading...</div>;
+  }
+
   return (
     <AssistantRuntimeProvider runtime={runtime}>
-      <ThreadList />
-      <Thread />
+      <ChatContainer>
+        <ThreadList />
+        <Thread />
+      </ChatContainer>
     </AssistantRuntimeProvider>
   );
 }
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/hooks/useChatStorage.ts b/client/packages/lowcoder/src/comps/comps/chatComp/hooks/useChatStorage.ts
new file mode 100644
index 0000000000..2f24b3a827
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/hooks/useChatStorage.ts
@@ -0,0 +1,139 @@
+import { useEffect, useState } from "react";
+import { chatStorage, ThreadData as StoredThreadData } from "../utils/chatStorage";
+import { MyMessage } from "../components/context/ThreadContext";
+
+// Thread data interfaces (matching ChatWithThreads)
+interface RegularThreadData {
+  threadId: string;
+  status: "regular";
+  title: string;
+}
+
+interface ArchivedThreadData {
+  threadId: string;
+  status: "archived";
+  title: string;
+}
+
+type ThreadData = RegularThreadData | ArchivedThreadData;
+
+interface UseChatStorageParams {
+  threadList: ThreadData[];
+  threads: Map<string, MyMessage[]>;
+  setThreadList: React.Dispatch<React.SetStateAction<ThreadData[]>>;
+  setThreads: React.Dispatch<React.SetStateAction<Map<string, MyMessage[]>>>;
+  setCurrentThreadId: (id: string) => void;
+}
+
+export function useChatStorage({
+  threadList,
+  threads,
+  setThreadList,
+  setThreads,
+  setCurrentThreadId,
+}: UseChatStorageParams) {
+  const [isInitialized, setIsInitialized] = useState(false);
+
+  // Load data from persistent storage on component mount
+  useEffect(() => {
+    const loadData = async () => {
+      try {
+        await chatStorage.initialize();
+        
+        // Load all threads from storage
+        const storedThreads = await chatStorage.getAllThreads();
+        if (storedThreads.length > 0) {
+          // Convert stored threads to UI format
+          const uiThreads: ThreadData[] = storedThreads.map(stored => ({
+            threadId: stored.threadId,
+            status: stored.status as "regular" | "archived",
+            title: stored.title,
+          }));
+          setThreadList(uiThreads);
+          
+          // Load messages for each thread
+          const threadMessages = new Map<string, MyMessage[]>();
+          for (const thread of storedThreads) {
+            const messages = await chatStorage.getMessages(thread.threadId);
+            threadMessages.set(thread.threadId, messages);
+          }
+          
+          // Ensure default thread exists
+          if (!threadMessages.has("default")) {
+            threadMessages.set("default", []);
+          }
+          
+          setThreads(threadMessages);
+          
+          // Set current thread to the most recently updated one
+          const latestThread = storedThreads.sort((a, b) => b.updatedAt - a.updatedAt)[0];
+          if (latestThread) {
+            setCurrentThreadId(latestThread.threadId);
+          }
+        } else {
+          // Initialize with default thread
+          const defaultThread: StoredThreadData = {
+            threadId: "default",
+            status: "regular",
+            title: "New Chat",
+            createdAt: Date.now(),
+            updatedAt: Date.now(),
+          };
+          await chatStorage.saveThread(defaultThread);
+        }
+        
+        setIsInitialized(true);
+      } catch (error) {
+        console.error("Failed to load chat data:", error);
+        setIsInitialized(true); // Continue with default state
+      }
+    };
+
+    loadData();
+  }, [setCurrentThreadId, setThreads, setThreadList]);
+
+  // Save thread data whenever threadList changes
+  useEffect(() => {
+    if (!isInitialized) return;
+    
+    const saveThreads = async () => {
+      try {
+        for (const thread of threadList) {
+          const storedThread: StoredThreadData = {
+            threadId: thread.threadId,
+            status: thread.status,
+            title: thread.title,
+            createdAt: Date.now(), // In real app, preserve original createdAt
+            updatedAt: Date.now(),
+          };
+          await chatStorage.saveThread(storedThread);
+        }
+      } catch (error) {
+        console.error("Failed to save threads:", error);
+      }
+    };
+
+    saveThreads();
+  }, [threadList, isInitialized]);
+
+  // Save messages whenever threads change
+  useEffect(() => {
+    if (!isInitialized) return;
+    
+    const saveMessages = async () => {
+      try {
+        for (const [threadId, messages] of threads.entries()) {
+          await chatStorage.saveMessages(messages, threadId);
+        }
+      } catch (error) {
+        console.error("Failed to save messages:", error);
+      }
+    };
+
+    saveMessages();
+  }, [threads, isInitialized]);
+
+  return {
+    isInitialized,
+  };
+}
\ No newline at end of file

From dbd901cc2e9159c9e3ac8e2d553c47c8f5090d4f Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Thu, 3 Jul 2025 21:08:14 +0500
Subject: [PATCH 19/54] add delete thread functionality

---
 .../components/assistant-ui/thread-list.tsx      | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
index b44abaf0b7..565464fc76 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
@@ -3,7 +3,7 @@ import {
   ThreadListItemPrimitive,
   ThreadListPrimitive,
 } from "@assistant-ui/react";
-import { ArchiveIcon, PlusIcon } from "lucide-react";
+import { PlusIcon, Trash2Icon } from "lucide-react";
 
 import { Button } from "../ui/button";
 import { TooltipIconButton } from "./tooltip-icon-button";
@@ -38,7 +38,7 @@ const ThreadListItem: FC = () => {
       <ThreadListItemPrimitive.Trigger className="aui-thread-list-item-trigger">
         <ThreadListItemTitle />
       </ThreadListItemPrimitive.Trigger>
-      <ThreadListItemArchive />
+      <ThreadListItemDelete />
     </ThreadListItemPrimitive.Root>
   );
 };
@@ -51,16 +51,16 @@ const ThreadListItemTitle: FC = () => {
   );
 };
 
-const ThreadListItemArchive: FC = () => {
+const ThreadListItemDelete: FC = () => {
   return (
-    <ThreadListItemPrimitive.Archive asChild>
+    <ThreadListItemPrimitive.Delete asChild>
       <TooltipIconButton
-        className="aui-thread-list-item-archive"
+        className="aui-thread-list-item-delete"
         variant="ghost"
-        tooltip="Archive thread"
+        tooltip="Delete thread"
       >
-        <ArchiveIcon />
+        <Trash2Icon />
       </TooltipIconButton>
-    </ThreadListItemPrimitive.Archive>
+    </ThreadListItemPrimitive.Delete>
   );
 };
\ No newline at end of file

From bf9f26942779f95655faa5b2f2ca7bc92d2843c5 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Thu, 3 Jul 2025 21:48:42 +0500
Subject: [PATCH 20/54] add rename thread ability

---
 .../components/assistant-ui/thread-list.tsx   | 40 ++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
index 565464fc76..ef4eca84d0 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
@@ -3,10 +3,11 @@ import {
   ThreadListItemPrimitive,
   ThreadListPrimitive,
 } from "@assistant-ui/react";
-import { PlusIcon, Trash2Icon } from "lucide-react";
+import { PencilIcon, PlusIcon, Trash2Icon } from "lucide-react";
 
 import { Button } from "../ui/button";
 import { TooltipIconButton } from "./tooltip-icon-button";
+import { useThreadListItemRuntime } from "@assistant-ui/react";
 
 export const ThreadList: FC = () => {
   return (
@@ -38,6 +39,7 @@ const ThreadListItem: FC = () => {
       <ThreadListItemPrimitive.Trigger className="aui-thread-list-item-trigger">
         <ThreadListItemTitle />
       </ThreadListItemPrimitive.Trigger>
+      <ThreadListItemRename />
       <ThreadListItemDelete />
     </ThreadListItemPrimitive.Root>
   );
@@ -63,4 +65,40 @@ const ThreadListItemDelete: FC = () => {
       </TooltipIconButton>
     </ThreadListItemPrimitive.Delete>
   );
+};
+
+
+const ThreadListItemRename: FC = () => {
+  const runtime = useThreadListItemRuntime();
+  
+  const handleClick = async () => {
+    // runtime doesn't expose a direct `title` prop; read it from its state
+    let current = "";
+    try {
+      // getState is part of the public runtime surface
+      current = (runtime.getState?.() as any)?.title ?? "";
+    } catch {
+      // fallback – generate a title if the runtime provides a helper
+      if (typeof (runtime as any).generateTitle === "function") {
+        // generateTitle(threadId) in older builds, generateTitle() in newer ones
+        current = (runtime as any).generateTitle((runtime as any).threadId ?? undefined);
+      }
+    }
+
+    const next = prompt("Rename thread", current)?.trim();
+    if (next && next !== current) {
+      await runtime.rename(next);
+    }
+  };
+
+  return (
+    <TooltipIconButton
+      tooltip="Rename thread"
+      variant="ghost"
+      onClick={handleClick}
+      className="aui-thread-list-item-rename"
+    >
+      <PencilIcon />
+    </TooltipIconButton>
+  );
 };
\ No newline at end of file

From 0205c725438d82ecf85d3c63ef5466bf551aef13 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Fri, 4 Jul 2025 23:55:21 +0500
Subject: [PATCH 21/54] [Feat]: Add chat component

---
 .../src/comps/comps/chatComp/chatView.tsx     |   2 +-
 .../comps/chatComp/components/ChatApp.tsx     |  10 +
 .../{ChatWithThreads.tsx => ChatMain.tsx}     | 161 +++-----
 .../components/assistant-ui/thread-list.tsx   |  17 +-
 .../components/context/ChatContext.tsx        | 378 ++++++++++++++++++
 .../components/context/ThreadContext.tsx      |  53 ---
 .../comps/chatComp/hooks/useChatStorage.ts    | 139 -------
 .../comps/comps/chatComp/utils/chatStorage.ts |   2 +-
 8 files changed, 449 insertions(+), 313 deletions(-)
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
 rename client/packages/lowcoder/src/comps/comps/chatComp/components/{ChatWithThreads.tsx => ChatMain.tsx} (54%)
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
 delete mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/context/ThreadContext.tsx
 delete mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/hooks/useChatStorage.ts

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
index 0af26ffe25..07383b48a7 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
@@ -1,7 +1,7 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
 import React from "react";
 import { ChatCompProps } from "./chatCompTypes";
-import { ChatApp } from "./components/ChatWithThreads";
+import { ChatApp } from "./components/ChatApp";
 
 import "@assistant-ui/styles/index.css";
 import "@assistant-ui/styles/markdown.css";
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
new file mode 100644
index 0000000000..e87ed8585f
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
@@ -0,0 +1,10 @@
+import { ChatProvider } from "./context/ChatContext";
+import { ChatMain } from "./ChatMain";
+
+export function ChatApp() {
+  return (
+    <ChatProvider>
+      <ChatMain />
+    </ChatProvider>
+  );
+}
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
similarity index 54%
rename from client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx
rename to client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
index 7a9101a838..d0e151d88e 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatWithThreads.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
@@ -1,4 +1,4 @@
-import React, { useState, useEffect } from "react";
+import React, { useState } from "react";
 import {
   useExternalStoreRuntime,
   ThreadMessageLike,
@@ -6,46 +6,42 @@ import {
   AssistantRuntimeProvider,
   ExternalStoreThreadListAdapter,
 } from "@assistant-ui/react";
-import { useThreadContext, MyMessage, ThreadProvider } from "./context/ThreadContext";
 import { Thread } from "./assistant-ui/thread";
 import { ThreadList } from "./assistant-ui/thread-list";
-import { chatStorage, ThreadData as StoredThreadData } from "../utils/chatStorage";
-import { useChatStorage } from "../hooks/useChatStorage";
+import { 
+  useChatContext, 
+  MyMessage, 
+  ThreadData, 
+  RegularThreadData, 
+  ArchivedThreadData 
+} from "./context/ChatContext";
 import styled from "styled-components";
 
-
-
-
 const ChatContainer = styled.div`
   display: flex;
   height: 500px;
 
   .aui-thread-list-root {
     width: 250px;
-    background-color: #333;
+    background-color: #fff;
+    padding: 10px;
   }
 
   .aui-thread-root {
     flex: 1;
-    background-color: #f0f0f0;
+    background-color: #f9fafb;
   }
 
-`;
-
-// Define thread data interfaces to match ExternalStoreThreadData requirements
-interface RegularThreadData {
-  threadId: string;
-  status: "regular";
-  title: string;
-}
+  .aui-thread-list-item {
+    cursor: pointer;
+    transition: background-color 0.2s ease;
 
-interface ArchivedThreadData {
-  threadId: string;
-  status: "archived";
-  title: string;
-}
-
-type ThreadData = RegularThreadData | ArchivedThreadData;
+    &[data-active="true"] {
+      background-color: #dbeafe;
+      border: 1px solid #bfdbfe;
+    }
+  }
+`;
 
 const generateId = () => Math.random().toString(36).substr(2, 9);
 
@@ -59,22 +55,14 @@ const callYourAPI = async (text: string) => {
   };
 };
 
-function ChatWithThreads() {
-  const { currentThreadId, setCurrentThreadId, threads, setThreads } =
-    useThreadContext();
+export function ChatMain() {
+  const { state, actions } = useChatContext();
   const [isRunning, setIsRunning] = useState(false);
-  const [threadList, setThreadList] = useState<ThreadData[]>([
-    { threadId: "default", status: "regular", title: "New Chat" } as RegularThreadData,
-  ]);
-  const { isInitialized } = useChatStorage({
-    threadList,
-    threads,
-    setThreadList,
-    setThreads,
-    setCurrentThreadId,
-  });
+
+  console.log("STATE", state);
+
   // Get messages for current thread
-  const currentMessages = threads.get(currentThreadId) || [];
+  const currentMessages = actions.getCurrentMessages();
 
   // Convert custom format to ThreadMessageLike
   const convertMessage = (message: MyMessage): ThreadMessageLike => ({
@@ -99,8 +87,7 @@ function ChatWithThreads() {
     };
     
     // Update current thread with new user message
-    const updatedMessages = [...currentMessages, userMessage];
-    setThreads(prev => new Map(prev).set(currentThreadId, updatedMessages));
+    await actions.addMessage(state.currentThreadId, userMessage);
     setIsRunning(true);
 
     try {
@@ -115,8 +102,7 @@ function ChatWithThreads() {
       };
       
       // Update current thread with assistant response
-      const finalMessages = [...updatedMessages, assistantMessage];
-      setThreads(prev => new Map(prev).set(currentThreadId, finalMessages));
+      await actions.addMessage(state.currentThreadId, assistantMessage);
     } catch (error) {
       // Handle errors gracefully
       const errorMessage: MyMessage = {
@@ -126,8 +112,7 @@ function ChatWithThreads() {
         timestamp: Date.now(),
       };
       
-      const finalMessages = [...updatedMessages, errorMessage];
-      setThreads(prev => new Map(prev).set(currentThreadId, finalMessages));
+      await actions.addMessage(state.currentThreadId, errorMessage);
     } finally {
       setIsRunning(false);
     }
@@ -155,7 +140,8 @@ function ChatWithThreads() {
     };
     newMessages.push(editedMessage);
 
-    setThreads(prev => new Map(prev).set(currentThreadId, newMessages));
+    // Update messages using the new context action
+    await actions.updateMessages(state.currentThreadId, newMessages);
     setIsRunning(true);
 
     try {
@@ -170,7 +156,7 @@ function ChatWithThreads() {
       };
       
       newMessages.push(assistantMessage);
-      setThreads(prev => new Map(prev).set(currentThreadId, newMessages));
+      await actions.updateMessages(state.currentThreadId, newMessages);
     } catch (error) {
       // Handle errors gracefully
       const errorMessage: MyMessage = {
@@ -181,7 +167,7 @@ function ChatWithThreads() {
       };
       
       newMessages.push(errorMessage);
-      setThreads(prev => new Map(prev).set(currentThreadId, newMessages));
+      await actions.updateMessages(state.currentThreadId, newMessages);
     } finally {
       setIsRunning(false);
     }
@@ -189,81 +175,36 @@ function ChatWithThreads() {
 
   // Thread list adapter for managing multiple threads
   const threadListAdapter: ExternalStoreThreadListAdapter = {
-    threadId: currentThreadId,
-    threads: threadList.filter((t): t is RegularThreadData => t.status === "regular"),
-    archivedThreads: threadList.filter((t): t is ArchivedThreadData => t.status === "archived"),
+    threadId: state.currentThreadId,
+    threads: state.threadList.filter((t): t is RegularThreadData => t.status === "regular"),
+    archivedThreads: state.threadList.filter((t): t is ArchivedThreadData => t.status === "archived"),
 
     onSwitchToNewThread: async () => {
-      const newId = `thread-${Date.now()}`;
-      const newThread: RegularThreadData = {
-        threadId: newId,
-        status: "regular",
-        title: "New Chat",
-      };
-      
-      setThreadList((prev) => [...prev, newThread]);
-      setThreads((prev) => new Map(prev).set(newId, []));
-      setCurrentThreadId(newId);
-      
-      // Save new thread to storage
-      try {
-        const storedThread: StoredThreadData = {
-          threadId: newId,
-          status: "regular",
-          title: "New Chat",
-          createdAt: Date.now(),
-          updatedAt: Date.now(),
-        };
-        await chatStorage.saveThread(storedThread);
-      } catch (error) {
-        console.error("Failed to save new thread:", error);
-      }
+      const threadId = await actions.createThread("New Chat");
+      actions.setCurrentThread(threadId);
     },
 
     onSwitchToThread: (threadId) => {
-      setCurrentThreadId(threadId);
+      actions.setCurrentThread(threadId);
     },
 
-    onRename: (threadId, newTitle) => {
-      setThreadList((prev) =>
-        prev.map((t) =>
-          t.threadId === threadId ? { ...t, title: newTitle } : t,
-        ),
-      );
+    onRename: async (threadId, newTitle) => {
+      await actions.updateThread(threadId, { title: newTitle });
     },
 
-    onArchive: (threadId) => {
-      setThreadList((prev) =>
-        prev.map((t) =>
-          t.threadId === threadId ? { ...t, status: "archived" } : t,
-        ),
-      );
+    onArchive: async (threadId) => {
+      await actions.updateThread(threadId, { status: "archived" });
     },
 
     onDelete: async (threadId) => {
-      setThreadList((prev) => prev.filter((t) => t.threadId !== threadId));
-      setThreads((prev) => {
-        const next = new Map(prev);
-        next.delete(threadId);
-        return next;
-      });
-      if (currentThreadId === threadId) {
-        setCurrentThreadId("default");
-      }
-      
-      // Delete thread from storage
-      try {
-        await chatStorage.deleteThread(threadId);
-      } catch (error) {
-        console.error("Failed to delete thread from storage:", error);
-      }
+      await actions.deleteThread(threadId);
     },
   };
 
   const runtime = useExternalStoreRuntime({
     messages: currentMessages,
     setMessages: (messages) => {
-      setThreads((prev) => new Map(prev).set(currentThreadId, messages));
+      actions.updateMessages(state.currentThreadId, messages);
     },
     convertMessage,
     isRunning,
@@ -274,7 +215,7 @@ function ChatWithThreads() {
     },
   });
 
-  if (!isInitialized) {
+  if (!state.isInitialized) {
     return <div>Loading...</div>;
   }
 
@@ -288,13 +229,3 @@ function ChatWithThreads() {
   );
 }
 
-// Main App component with proper context wrapping
-export function ChatApp() {
-  return (
-    <ThreadProvider>
-      <ChatWithThreads />
-    </ThreadProvider>
-  );
-}
-
-export { ChatWithThreads }; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
index ef4eca84d0..bb01b7d5ee 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
@@ -5,9 +5,18 @@ import {
 } from "@assistant-ui/react";
 import { PencilIcon, PlusIcon, Trash2Icon } from "lucide-react";
 
-import { Button } from "../ui/button";
 import { TooltipIconButton } from "./tooltip-icon-button";
 import { useThreadListItemRuntime } from "@assistant-ui/react";
+import { Button } from "antd";
+
+import styled from "styled-components";
+import { useChatContext } from "../context/ChatContext";
+
+const StyledPrimaryButton = styled(Button)`
+  padding: 20px;
+  margin-bottom: 20px;
+`;
+
 
 export const ThreadList: FC = () => {
   return (
@@ -21,10 +30,9 @@ export const ThreadList: FC = () => {
 const ThreadListNew: FC = () => {
   return (
     <ThreadListPrimitive.New asChild>
-      <Button className="aui-thread-list-new" variant="ghost">
-        <PlusIcon />
+      <StyledPrimaryButton size="large" type="primary" icon={<PlusIcon />}>
         New Thread
-      </Button>
+      </StyledPrimaryButton>
     </ThreadListPrimitive.New>
   );
 };
@@ -46,6 +54,7 @@ const ThreadListItem: FC = () => {
 };
 
 const ThreadListItemTitle: FC = () => {
+
   return (
     <p className="aui-thread-list-item-title">
       <ThreadListItemPrimitive.Title fallback="New Chat" />
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
new file mode 100644
index 0000000000..41ef892af4
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
@@ -0,0 +1,378 @@
+import React, { createContext, useContext, useReducer, useEffect, ReactNode } from "react";
+import { chatStorage, ThreadData as StoredThreadData } from "../../utils/chatStorage";
+
+// Define thread-specific message type
+export interface MyMessage {
+  id: string;
+  role: "user" | "assistant";
+  text: string;
+  timestamp: number;
+}
+
+// Thread data interfaces
+export interface RegularThreadData {
+  threadId: string;
+  status: "regular";
+  title: string;
+}
+
+export interface ArchivedThreadData {
+  threadId: string;
+  status: "archived";
+  title: string;
+}
+
+export type ThreadData = RegularThreadData | ArchivedThreadData;
+
+// Chat state interface
+interface ChatState {
+  isInitialized: boolean;
+  isLoading: boolean;
+  currentThreadId: string;
+  threadList: ThreadData[];
+  threads: Map<string, MyMessage[]>;
+  lastSaved: number; // Timestamp for tracking when data was last saved
+}
+
+// Action types
+type ChatAction =
+  | { type: "INITIALIZE_START" }
+  | { type: "INITIALIZE_SUCCESS"; threadList: ThreadData[]; threads: Map<string, MyMessage[]>; currentThreadId: string }
+  | { type: "INITIALIZE_ERROR" }
+  | { type: "SET_CURRENT_THREAD"; threadId: string }
+  | { type: "ADD_THREAD"; thread: ThreadData }
+  | { type: "UPDATE_THREAD"; threadId: string; updates: Partial<ThreadData> }
+  | { type: "DELETE_THREAD"; threadId: string }
+  | { type: "SET_MESSAGES"; threadId: string; messages: MyMessage[] }
+  | { type: "ADD_MESSAGE"; threadId: string; message: MyMessage }
+  | { type: "UPDATE_MESSAGES"; threadId: string; messages: MyMessage[] }
+  | { type: "MARK_SAVED" };
+
+// Initial state
+const initialState: ChatState = {
+  isInitialized: false,
+  isLoading: false,
+  currentThreadId: "default",
+  threadList: [{ threadId: "default", status: "regular", title: "New Chat" }],
+  threads: new Map([["default", []]]),
+  lastSaved: 0,
+};
+
+// Reducer function
+function chatReducer(state: ChatState, action: ChatAction): ChatState {
+  switch (action.type) {
+    case "INITIALIZE_START":
+      return {
+        ...state,
+        isLoading: true,
+      };
+
+    case "INITIALIZE_SUCCESS":
+      return {
+        ...state,
+        isInitialized: true,
+        isLoading: false,
+        threadList: action.threadList,
+        threads: action.threads,
+        currentThreadId: action.currentThreadId,
+        lastSaved: Date.now(),
+      };
+
+    case "INITIALIZE_ERROR":
+      return {
+        ...state,
+        isInitialized: true,
+        isLoading: false,
+      };
+
+    case "SET_CURRENT_THREAD":
+      return {
+        ...state,
+        currentThreadId: action.threadId,
+      };
+
+    case "ADD_THREAD":
+      return {
+        ...state,
+        threadList: [...state.threadList, action.thread],
+        threads: new Map(state.threads).set(action.thread.threadId, []),
+      };
+
+    case "UPDATE_THREAD":
+      return {
+        ...state,
+        threadList: state.threadList.map(thread =>
+          thread.threadId === action.threadId
+            ? { ...thread, ...action.updates }
+            : thread
+        ),
+      };
+
+    case "DELETE_THREAD":
+      const newThreads = new Map(state.threads);
+      newThreads.delete(action.threadId);
+      return {
+        ...state,
+        threadList: state.threadList.filter(t => t.threadId !== action.threadId),
+        threads: newThreads,
+        currentThreadId: state.currentThreadId === action.threadId 
+          ? "default" 
+          : state.currentThreadId,
+      };
+
+    case "SET_MESSAGES":
+      return {
+        ...state,
+        threads: new Map(state.threads).set(action.threadId, action.messages),
+      };
+
+    case "ADD_MESSAGE":
+      const currentMessages = state.threads.get(action.threadId) || [];
+      return {
+        ...state,
+        threads: new Map(state.threads).set(action.threadId, [...currentMessages, action.message]),
+      };
+
+    case "UPDATE_MESSAGES":
+      return {
+        ...state,
+        threads: new Map(state.threads).set(action.threadId, action.messages),
+      };
+
+    case "MARK_SAVED":
+      return {
+        ...state,
+        lastSaved: Date.now(),
+      };
+
+    default:
+      return state;
+  }
+}
+
+// Context type
+interface ChatContextType {
+  state: ChatState;
+  actions: {
+    // Initialization
+    initialize: () => Promise<void>;
+    
+    // Thread management
+    setCurrentThread: (threadId: string) => void;
+    createThread: (title?: string) => Promise<string>;
+    updateThread: (threadId: string, updates: Partial<ThreadData>) => Promise<void>;
+    deleteThread: (threadId: string) => Promise<void>;
+    
+    // Message management  
+    addMessage: (threadId: string, message: MyMessage) => Promise<void>;
+    updateMessages: (threadId: string, messages: MyMessage[]) => Promise<void>;
+    
+    // Utility
+    getCurrentMessages: () => MyMessage[];
+  };
+}
+
+// Create the context
+const ChatContext = createContext<ChatContextType | null>(null);
+
+// Chat provider component
+export function ChatProvider({ children }: { children: ReactNode }) {
+  const [state, dispatch] = useReducer(chatReducer, initialState);
+
+  // Initialize data from storage
+  const initialize = async () => {
+    dispatch({ type: "INITIALIZE_START" });
+    
+    try {
+      await chatStorage.initialize();
+      
+      // Load all threads from storage
+      const storedThreads = await chatStorage.getAllThreads();
+      
+      if (storedThreads.length > 0) {
+        // Convert stored threads to UI format
+        const uiThreads: ThreadData[] = storedThreads.map(stored => ({
+          threadId: stored.threadId,
+          status: stored.status as "regular" | "archived",
+          title: stored.title,
+        }));
+        
+        // Load messages for each thread
+        const threadMessages = new Map<string, MyMessage[]>();
+        for (const thread of storedThreads) {
+          const messages = await chatStorage.getMessages(thread.threadId);
+          threadMessages.set(thread.threadId, messages);
+        }
+        
+        // Ensure default thread exists
+        if (!threadMessages.has("default")) {
+          threadMessages.set("default", []);
+        }
+        
+        // Find the most recently updated thread
+        const latestThread = storedThreads.sort((a, b) => b.updatedAt - a.updatedAt)[0];
+        const currentThreadId = latestThread ? latestThread.threadId : "default";
+        
+        dispatch({ 
+          type: "INITIALIZE_SUCCESS", 
+          threadList: uiThreads, 
+          threads: threadMessages, 
+          currentThreadId 
+        });
+      } else {
+        // Initialize with default thread
+        const defaultThread: StoredThreadData = {
+          threadId: "default",
+          status: "regular",
+          title: "New Chat",
+          createdAt: Date.now(),
+          updatedAt: Date.now(),
+        };
+        await chatStorage.saveThread(defaultThread);
+        
+        dispatch({ 
+          type: "INITIALIZE_SUCCESS", 
+          threadList: initialState.threadList, 
+          threads: initialState.threads, 
+          currentThreadId: "default" 
+        });
+      }
+    } catch (error) {
+      console.error("Failed to initialize chat data:", error);
+      dispatch({ type: "INITIALIZE_ERROR" });
+    }
+  };
+
+  // Thread management actions
+  const setCurrentThread = (threadId: string) => {
+    dispatch({ type: "SET_CURRENT_THREAD", threadId });
+  };
+
+  const createThread = async (title: string = "New Chat"): Promise<string> => {
+    const threadId = `thread-${Date.now()}`;
+    const newThread: ThreadData = {
+      threadId,
+      status: "regular",
+      title,
+    };
+    
+    // Update local state first
+    dispatch({ type: "ADD_THREAD", thread: newThread });
+    
+    // Save to storage
+    try {
+      const storedThread: StoredThreadData = {
+        threadId,
+        status: "regular",
+        title,
+        createdAt: Date.now(),
+        updatedAt: Date.now(),
+      };
+      await chatStorage.saveThread(storedThread);
+      dispatch({ type: "MARK_SAVED" });
+    } catch (error) {
+      console.error("Failed to save new thread:", error);
+    }
+    
+    return threadId;
+  };
+
+  const updateThread = async (threadId: string, updates: Partial<ThreadData>) => {
+    // Update local state first
+    dispatch({ type: "UPDATE_THREAD", threadId, updates });
+    
+    // Save to storage
+    try {
+      const existingThread = await chatStorage.getThread(threadId);
+      if (existingThread) {
+        const updatedThread: StoredThreadData = {
+          ...existingThread,
+          ...updates,
+          updatedAt: Date.now(),
+        };
+        await chatStorage.saveThread(updatedThread);
+        dispatch({ type: "MARK_SAVED" });
+      }
+    } catch (error) {
+      console.error("Failed to update thread:", error);
+    }
+  };
+
+  const deleteThread = async (threadId: string) => {
+    // Update local state first
+    dispatch({ type: "DELETE_THREAD", threadId });
+    
+    // Delete from storage
+    try {
+      await chatStorage.deleteThread(threadId);
+      dispatch({ type: "MARK_SAVED" });
+    } catch (error) {
+      console.error("Failed to delete thread:", error);
+    }
+  };
+
+  // Message management actions
+  const addMessage = async (threadId: string, message: MyMessage) => {
+    // Update local state first
+    dispatch({ type: "ADD_MESSAGE", threadId, message });
+    
+    // Save to storage
+    try {
+      await chatStorage.saveMessage(message, threadId);
+      dispatch({ type: "MARK_SAVED" });
+    } catch (error) {
+      console.error("Failed to save message:", error);
+    }
+  };
+
+  const updateMessages = async (threadId: string, messages: MyMessage[]) => {
+    // Update local state first
+    dispatch({ type: "UPDATE_MESSAGES", threadId, messages });
+    
+    // Save to storage
+    try {
+      await chatStorage.saveMessages(messages, threadId);
+      dispatch({ type: "MARK_SAVED" });
+    } catch (error) {
+      console.error("Failed to save messages:", error);
+    }
+  };
+
+  // Utility functions
+  const getCurrentMessages = (): MyMessage[] => {
+    return state.threads.get(state.currentThreadId) || [];
+  };
+
+  // Auto-initialize on mount
+  useEffect(() => {
+    if (!state.isInitialized && !state.isLoading) {
+      initialize();
+    }
+  }, [state.isInitialized, state.isLoading]);
+
+  const actions = {
+    initialize,
+    setCurrentThread,
+    createThread,
+    updateThread,
+    deleteThread,
+    addMessage,
+    updateMessages,
+    getCurrentMessages,
+  };
+
+  return (
+    <ChatContext.Provider value={{ state, actions }}>
+      {children}
+    </ChatContext.Provider>
+  );
+}
+
+// Hook for accessing chat context
+export function useChatContext() {
+  const context = useContext(ChatContext);
+  if (!context) {
+    throw new Error("useChatContext must be used within ChatProvider");
+  }
+  return context;
+} 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ThreadContext.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ThreadContext.tsx
deleted file mode 100644
index 313833105c..0000000000
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ThreadContext.tsx
+++ /dev/null
@@ -1,53 +0,0 @@
-import React, { createContext, useContext, useState, ReactNode } from "react";
-
-// Define thread-specific message type
-interface MyMessage {
-  id: string;
-  role: "user" | "assistant";
-  text: string;
-  timestamp: number;
-}
-
-// Thread context type
-interface ThreadContextType {
-  currentThreadId: string;
-  setCurrentThreadId: (id: string) => void;
-  threads: Map<string, MyMessage[]>;
-  setThreads: React.Dispatch<React.SetStateAction<Map<string, MyMessage[]>>>;
-}
-
-// Create the context
-const ThreadContext = createContext<ThreadContextType>({
-  currentThreadId: "default",
-  setCurrentThreadId: () => {},
-  threads: new Map(),
-  setThreads: () => {},
-});
-
-// Thread provider component
-export function ThreadProvider({ children }: { children: ReactNode }) {
-  const [threads, setThreads] = useState<Map<string, MyMessage[]>>(
-    new Map([["default", []]]),
-  );
-  const [currentThreadId, setCurrentThreadId] = useState("default");
-
-  return (
-    <ThreadContext.Provider
-      value={{ currentThreadId, setCurrentThreadId, threads, setThreads }}
-    >
-      {children}
-    </ThreadContext.Provider>
-  );
-}
-
-// Hook for accessing thread context
-export function useThreadContext() {
-  const context = useContext(ThreadContext);
-  if (!context) {
-    throw new Error("useThreadContext must be used within ThreadProvider");
-  }
-  return context;
-}
-
-// Export the MyMessage type for use in other files
-export type { MyMessage }; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/hooks/useChatStorage.ts b/client/packages/lowcoder/src/comps/comps/chatComp/hooks/useChatStorage.ts
deleted file mode 100644
index 2f24b3a827..0000000000
--- a/client/packages/lowcoder/src/comps/comps/chatComp/hooks/useChatStorage.ts
+++ /dev/null
@@ -1,139 +0,0 @@
-import { useEffect, useState } from "react";
-import { chatStorage, ThreadData as StoredThreadData } from "../utils/chatStorage";
-import { MyMessage } from "../components/context/ThreadContext";
-
-// Thread data interfaces (matching ChatWithThreads)
-interface RegularThreadData {
-  threadId: string;
-  status: "regular";
-  title: string;
-}
-
-interface ArchivedThreadData {
-  threadId: string;
-  status: "archived";
-  title: string;
-}
-
-type ThreadData = RegularThreadData | ArchivedThreadData;
-
-interface UseChatStorageParams {
-  threadList: ThreadData[];
-  threads: Map<string, MyMessage[]>;
-  setThreadList: React.Dispatch<React.SetStateAction<ThreadData[]>>;
-  setThreads: React.Dispatch<React.SetStateAction<Map<string, MyMessage[]>>>;
-  setCurrentThreadId: (id: string) => void;
-}
-
-export function useChatStorage({
-  threadList,
-  threads,
-  setThreadList,
-  setThreads,
-  setCurrentThreadId,
-}: UseChatStorageParams) {
-  const [isInitialized, setIsInitialized] = useState(false);
-
-  // Load data from persistent storage on component mount
-  useEffect(() => {
-    const loadData = async () => {
-      try {
-        await chatStorage.initialize();
-        
-        // Load all threads from storage
-        const storedThreads = await chatStorage.getAllThreads();
-        if (storedThreads.length > 0) {
-          // Convert stored threads to UI format
-          const uiThreads: ThreadData[] = storedThreads.map(stored => ({
-            threadId: stored.threadId,
-            status: stored.status as "regular" | "archived",
-            title: stored.title,
-          }));
-          setThreadList(uiThreads);
-          
-          // Load messages for each thread
-          const threadMessages = new Map<string, MyMessage[]>();
-          for (const thread of storedThreads) {
-            const messages = await chatStorage.getMessages(thread.threadId);
-            threadMessages.set(thread.threadId, messages);
-          }
-          
-          // Ensure default thread exists
-          if (!threadMessages.has("default")) {
-            threadMessages.set("default", []);
-          }
-          
-          setThreads(threadMessages);
-          
-          // Set current thread to the most recently updated one
-          const latestThread = storedThreads.sort((a, b) => b.updatedAt - a.updatedAt)[0];
-          if (latestThread) {
-            setCurrentThreadId(latestThread.threadId);
-          }
-        } else {
-          // Initialize with default thread
-          const defaultThread: StoredThreadData = {
-            threadId: "default",
-            status: "regular",
-            title: "New Chat",
-            createdAt: Date.now(),
-            updatedAt: Date.now(),
-          };
-          await chatStorage.saveThread(defaultThread);
-        }
-        
-        setIsInitialized(true);
-      } catch (error) {
-        console.error("Failed to load chat data:", error);
-        setIsInitialized(true); // Continue with default state
-      }
-    };
-
-    loadData();
-  }, [setCurrentThreadId, setThreads, setThreadList]);
-
-  // Save thread data whenever threadList changes
-  useEffect(() => {
-    if (!isInitialized) return;
-    
-    const saveThreads = async () => {
-      try {
-        for (const thread of threadList) {
-          const storedThread: StoredThreadData = {
-            threadId: thread.threadId,
-            status: thread.status,
-            title: thread.title,
-            createdAt: Date.now(), // In real app, preserve original createdAt
-            updatedAt: Date.now(),
-          };
-          await chatStorage.saveThread(storedThread);
-        }
-      } catch (error) {
-        console.error("Failed to save threads:", error);
-      }
-    };
-
-    saveThreads();
-  }, [threadList, isInitialized]);
-
-  // Save messages whenever threads change
-  useEffect(() => {
-    if (!isInitialized) return;
-    
-    const saveMessages = async () => {
-      try {
-        for (const [threadId, messages] of threads.entries()) {
-          await chatStorage.saveMessages(messages, threadId);
-        }
-      } catch (error) {
-        console.error("Failed to save messages:", error);
-      }
-    };
-
-    saveMessages();
-  }, [threads, isInitialized]);
-
-  return {
-    isInitialized,
-  };
-}
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorage.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorage.ts
index 7e85087e02..edc68a0d93 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorage.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorage.ts
@@ -1,5 +1,5 @@
 import alasql from "alasql";
-import { MyMessage } from "../components/context/ThreadContext";
+import { MyMessage } from "../components/context/ChatContext";
 
 // Database configuration
 const DB_NAME = "ChatDB";

From 2bb9ae82779ec3d079d05dd606fb4c50f8ef773c Mon Sep 17 00:00:00 2001
From: RAHEEL <mraheeliftikhar1994@gmail.com>
Date: Mon, 7 Jul 2025 15:08:28 +0500
Subject: [PATCH 22/54] update chat component to be used in bottom panel

---
 .../src/comps/comps/chatComp/chatComp.tsx     | 31 ++++++++++++++-
 .../src/comps/comps/chatComp/chatCompTypes.ts | 23 +++++++----
 .../comps/comps/chatComp/chatPropertyView.tsx | 39 +++++++++++--------
 .../src/comps/comps/chatComp/chatView.tsx     |  2 +-
 .../comps/chatComp/components/ChatApp.tsx     | 10 ++++-
 .../comps/chatComp/components/ChatMain.tsx    | 38 ++++++++++++++----
 .../components/assistant-ui/thread-list.tsx   | 15 +++----
 7 files changed, 115 insertions(+), 43 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
index 75de96494a..d26dce7b29 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
@@ -4,15 +4,42 @@ import { NameConfig, withExposingConfigs } from "comps/generators/withExposing";
 import { chatChildrenMap } from "./chatCompTypes";
 import { ChatView } from "./chatView";
 import { ChatPropertyView } from "./chatPropertyView";
+import { useEffect, useState } from "react";
+import { changeChildAction } from "lowcoder-core";
 
 // Build the component
-const ChatTmpComp = new UICompBuilder(
+let ChatTmpComp = new UICompBuilder(
   chatChildrenMap, 
-  (props) => <ChatView {...props} chatQuery={props.chatQuery.value} />
+  (props, dispatch) => {
+    useEffect(() => {
+      if (Boolean(props.tableName)) return;
+
+      // Generate a unique database name for this ChatApp instance
+      const generateUniqueTableName = () => {
+        const timestamp = Date.now();
+        const randomId = Math.random().toString(36).substring(2, 15);
+        return `TABLE_${timestamp}`;
+      };
+      
+      const tableName = generateUniqueTableName();
+      dispatch(changeChildAction('tableName', tableName, true));
+    }, [props.tableName]);
+    
+    if (!props.tableName) {
+      return null; // Don't render until we have a unique DB name
+    }
+    return <ChatView {...props} chatQuery={props.chatQuery.value} />;
+  }
 )
   .setPropertyViewFn((children) => <ChatPropertyView children={children} />)
   .build();
 
+ChatTmpComp = class extends ChatTmpComp {
+  override autoHeight(): boolean {
+    return this.children.autoHeight.getView();
+  }
+};
+
 // Export the component
 export const ChatComp = withExposingConfigs(ChatTmpComp, [
   new NameConfig("text", "Chat component text"),
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
index 79ba4c80dc..87dca43a37 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
@@ -4,6 +4,7 @@ import { withDefault } from "comps/generators";
 import { BoolControl } from "comps/controls/boolControl";
 import { dropdownControl } from "comps/controls/dropdownControl";
 import QuerySelectControl from "comps/controls/querySelectControl";
+import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl";
 
 // Model type dropdown options
 const ModelTypeOptions = [
@@ -13,20 +14,26 @@ const ModelTypeOptions = [
 
 export const chatChildrenMap = {
   text: withDefault(StringControl, "Chat Component Placeholder"),
-  chatQuery: QuerySelectControl,
   modelType: dropdownControl(ModelTypeOptions, "direct-llm"),
+  modelHost: withDefault(StringControl, ""),
   streaming: BoolControl.DEFAULT_TRUE,
   systemPrompt: withDefault(StringControl, "You are a helpful assistant."),
   agent: BoolControl,
   maxInteractions: withDefault(NumberControl, 10),
+  chatQuery: QuerySelectControl,
+  autoHeight: AutoHeightControl,
+  tableName: withDefault(StringControl, ""),
 };
 
 export type ChatCompProps = {
-  text: string;
-  chatQuery: string;
-  modelType: string;
-  streaming: boolean;
-  systemPrompt: string;
-  agent: boolean;
-  maxInteractions: number;
+  text?: string;
+  chatQuery?: string;
+  modelType?: string;
+  streaming?: boolean;
+  systemPrompt?: string;
+  agent?: boolean;
+  maxInteractions?: number;
+  modelHost?: string;
+  autoHeight?: boolean;
+  tableName?: string;
 };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
index b4f42c8e17..2a9143c4ae 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
@@ -1,27 +1,34 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
 import React from "react";
 import { Section, sectionNames } from "lowcoder-design";
+import { trans } from "i18n";
 
 export const ChatPropertyView = React.memo((props: any) => {
   const { children } = props;
 
   return (
-    <Section name={sectionNames.basic}>
-      {children.text.propertyView({ label: "Text" })}
-      {children.chatQuery.propertyView({ label: "Chat Query" })}
-      {children.modelType.propertyView({ label: "Model Type" })}
-      {children.streaming.propertyView({ label: "Enable Streaming" })}
-      {children.systemPrompt.propertyView({ 
-        label: "System Prompt",
-        placeholder: "Enter system prompt...",
-        enableSpellCheck: false,
-      })}
-      {children.agent.propertyView({ label: "Enable Agent Mode" })}
-      {children.maxInteractions.propertyView({ 
-        label: "Max Interactions",
-        placeholder: "10",
-      })}
-    </Section>
+    <>
+      <Section name={sectionNames.basic}>
+        {children.modelType.propertyView({ label: "Model Type" })}
+        {children.modelHost.propertyView({ label: "Model Host" })}
+        {/* {children.text.propertyView({ label: "Text" })}
+        {children.chatQuery.propertyView({ label: "Chat Query" })} */}
+        {children.streaming.propertyView({ label: "Enable Streaming" })}
+        {children.systemPrompt.propertyView({ 
+          label: "System Prompt",
+          placeholder: "Enter system prompt...",
+          enableSpellCheck: false,
+        })}
+        {children.agent.propertyView({ label: "Enable Agent Mode" })}
+        {children.maxInteractions.propertyView({ 
+          label: "Max Interactions",
+          placeholder: "10",
+        })}
+      </Section>
+      <Section name={sectionNames.layout}>
+        {children.autoHeight.propertyView({ label: trans("prop.height") })}
+      </Section>
+    </>
   );
 });
 
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
index 07383b48a7..eca764ba6a 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
@@ -7,7 +7,7 @@ import "@assistant-ui/styles/index.css";
 import "@assistant-ui/styles/markdown.css";
 
 export const ChatView = React.memo((props: ChatCompProps) => {
-  return <ChatApp />;
+  return <ChatApp {...props} />;
 });
 
 ChatView.displayName = 'ChatView';
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
index e87ed8585f..e8092a494b 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
@@ -1,10 +1,16 @@
 import { ChatProvider } from "./context/ChatContext";
 import { ChatMain } from "./ChatMain";
+import { ChatCompProps } from "../chatCompTypes";
+import { useEffect, useState } from "react";
 
-export function ChatApp() {
+export function ChatApp(props: ChatCompProps) {
+  if (!Boolean(props.tableName)) {
+    return null; // Don't render until we have a unique DB name
+  }
+  
   return (
     <ChatProvider>
-      <ChatMain />
+      <ChatMain {...props} />
     </ChatProvider>
   );
 }
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
index d0e151d88e..14ba061ca7 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
@@ -16,10 +16,15 @@ import {
   ArchivedThreadData 
 } from "./context/ChatContext";
 import styled from "styled-components";
+import { ChatCompProps } from "../chatCompTypes";
 
-const ChatContainer = styled.div`
+const ChatContainer = styled.div<{ $autoHeight?: boolean }>`
   display: flex;
-  height: 500px;
+  height: ${props => props.$autoHeight ? '500px' : '100%'};
+
+  p {
+    margin: 0;
+  }
 
   .aui-thread-list-root {
     width: 250px;
@@ -45,7 +50,18 @@ const ChatContainer = styled.div`
 
 const generateId = () => Math.random().toString(36).substr(2, 9);
 
-const callYourAPI = async (text: string) => {
+const callYourAPI = async (params: {
+  text: string,
+  modelHost: string,
+  modelType: string,
+}) => {
+  const { text, modelHost, modelType } = params;
+
+  let url = modelHost;
+  if (modelType === "direct-llm") {
+    url = `${modelHost}/api/chat/completions`;
+  }
+
   // Simulate API delay
   await new Promise(resolve => setTimeout(resolve, 1500));
   
@@ -55,7 +71,7 @@ const callYourAPI = async (text: string) => {
   };
 };
 
-export function ChatMain() {
+export function ChatMain(props: ChatCompProps) {
   const { state, actions } = useChatContext();
   const [isRunning, setIsRunning] = useState(false);
 
@@ -92,7 +108,11 @@ export function ChatMain() {
 
     try {
       // Call mock API
-      const response = await callYourAPI(userMessage.text);
+      const response = await callYourAPI({
+        text: userMessage.text,
+        modelHost: props.modelHost!,
+        modelType: props.modelType!,
+      });
       
       const assistantMessage: MyMessage = {
         id: generateId(),
@@ -146,7 +166,11 @@ export function ChatMain() {
 
     try {
       // Generate new response
-      const response = await callYourAPI(editedMessage.text);
+      const response = await callYourAPI({
+        text: editedMessage.text,
+        modelHost: props.modelHost!,
+        modelType: props.modelType!,
+      });
       
       const assistantMessage: MyMessage = {
         id: generateId(),
@@ -221,7 +245,7 @@ export function ChatMain() {
 
   return (
     <AssistantRuntimeProvider runtime={runtime}>
-      <ChatContainer>
+      <ChatContainer $autoHeight={props.autoHeight}>
         <ThreadList />
         <Thread />
       </ChatContainer>
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
index bb01b7d5ee..54dcbc5089 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
@@ -7,14 +7,14 @@ import { PencilIcon, PlusIcon, Trash2Icon } from "lucide-react";
 
 import { TooltipIconButton } from "./tooltip-icon-button";
 import { useThreadListItemRuntime } from "@assistant-ui/react";
-import { Button } from "antd";
+import { Button, Flex } from "antd";
 
 import styled from "styled-components";
 import { useChatContext } from "../context/ChatContext";
 
 const StyledPrimaryButton = styled(Button)`
-  padding: 20px;
-  margin-bottom: 20px;
+  // padding: 20px;
+  // margin-bottom: 20px;
 `;
 
 
@@ -22,7 +22,9 @@ export const ThreadList: FC = () => {
   return (
     <ThreadListPrimitive.Root className="aui-root aui-thread-list-root">
       <ThreadListNew />
-      <ThreadListItems />
+      <Flex vertical style={{flex: 1, overflow: 'auto', gap: 4}}>
+        <ThreadListItems />
+      </Flex>
     </ThreadListPrimitive.Root>
   );
 };
@@ -30,7 +32,7 @@ export const ThreadList: FC = () => {
 const ThreadListNew: FC = () => {
   return (
     <ThreadListPrimitive.New asChild>
-      <StyledPrimaryButton size="large" type="primary" icon={<PlusIcon />}>
+      <StyledPrimaryButton size="middle" type="primary" icon={<PlusIcon size={16}/>}>
         New Thread
       </StyledPrimaryButton>
     </ThreadListPrimitive.New>
@@ -54,9 +56,8 @@ const ThreadListItem: FC = () => {
 };
 
 const ThreadListItemTitle: FC = () => {
-
   return (
-    <p className="aui-thread-list-item-title">
+    <p className="aui-thread-list-item-title" style={{margin: 0}}>
       <ThreadListItemPrimitive.Title fallback="New Chat" />
     </p>
   );

From e14a7e74f131bf6586b6bb180804500f08a32508 Mon Sep 17 00:00:00 2001
From: RAHEEL <mraheeliftikhar1994@gmail.com>
Date: Mon, 7 Jul 2025 15:13:54 +0500
Subject: [PATCH 23/54] added chat option in bottom panel

---
 .../lowcoder-design/src/icons/index.tsx       |  3 +
 .../src/pages/editor/bottom/BottomPanel.tsx   | 69 ++++++++++++++++++-
 .../src/pages/editor/bottom/BottomSidebar.tsx |  7 +-
 3 files changed, 75 insertions(+), 4 deletions(-)

diff --git a/client/packages/lowcoder-design/src/icons/index.tsx b/client/packages/lowcoder-design/src/icons/index.tsx
index b033d52e92..75f0d8a687 100644
--- a/client/packages/lowcoder-design/src/icons/index.tsx
+++ b/client/packages/lowcoder-design/src/icons/index.tsx
@@ -1,5 +1,8 @@
 import React, { lazy, Suspense } from "react";
 
+export { ReactComponent as AIGenerate } from "./remix/ai-generate.svg";
+export { ReactComponent as AIGenerate2 } from "./remix/ai-generate-2.svg";
+export { ReactComponent as AIGenerateText } from "./remix/ai-generate-text.svg";
 export { ReactComponent as AppSnapshotIcon } from "./v1/app-snapshot.svg";
 export { ReactComponent as ArchiveIcon } from "./remix/archive-fill.svg";
 export { ReactComponent as HookCompDropIcon } from "./v1/hook-comp-drop.svg";
diff --git a/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx b/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
index 820e83b120..c71364470b 100644
--- a/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
+++ b/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
@@ -9,6 +9,14 @@ import { AppState } from "../../../redux/reducers";
 import { getUser } from "../../../redux/selectors/usersSelectors";
 import { connect } from "react-redux";
 import { Layers } from "constants/Layers";
+import Flex from "antd/es/flex";
+import type { MenuProps } from 'antd/es/menu';
+import { BuildOutlined, DatabaseOutlined } from "@ant-design/icons";
+import Menu from "antd/es/menu/menu";
+import { ChatView } from "@lowcoder-ee/comps/comps/chatComp/chatView";
+import { AIGenerate } from "lowcoder-design";
+
+type MenuItem = Required<MenuProps>['items'][number];
 
 const StyledResizableBox = styled(ResizableBox)`
   position: relative;
@@ -26,6 +34,32 @@ const StyledResizableBox = styled(ResizableBox)`
   }
 `;
 
+const StyledMenu = styled(Menu)`
+  width: 40px;
+  padding: 6px 0;
+
+  .ant-menu-item {
+    height: 30px;
+    line-height: 30px;
+  }
+`;
+
+const ChatHeader = styled.div`
+  flex: 0 0 35px;
+  padding: 0 16px;
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  border-bottom: 1px solid #e1e3eb;
+  background: #fafafa;
+`;
+const ChatTitle = styled.h3`
+  margin: 0;
+  font-size: 14px;
+  font-weight: 500;
+  color: #222222;
+`;
+
 const preventDefault = (e: any) => {
   e.preventDefault();
 };
@@ -49,6 +83,12 @@ function Bottom(props: any) {
   };
 
   const [bottomHeight, setBottomHeight] = useState(panelStyle.bottom.h);
+  const [currentOption, setCurrentOption] = useState("data");
+
+  const items: MenuItem[] = [
+    { key: 'data', icon: <DatabaseOutlined />, label: 'Data Queries' },
+    { key: 'ai', icon: <AIGenerate />, label: 'Lowcoder AI' },
+  ];
 
   return (
     <>
@@ -62,7 +102,34 @@ function Bottom(props: any) {
         onResizeStart={addListener}
         onResizeStop={resizeStop}
       >
-        <BottomContent />
+        <Flex style={{height: '100%'}}>
+          <StyledMenu
+            defaultSelectedKeys={[currentOption]}
+            mode="inline"
+            inlineCollapsed={true}
+            items={items}
+            onSelect={({key}) => {
+              setCurrentOption(key);
+            }}
+          />
+          { currentOption === "data" && <BottomContent /> }
+          { currentOption === "ai" && (
+            <Flex style={{height: '100%', flex: 1}} vertical>
+              <ChatHeader>
+                <ChatTitle>Lowcoder AI Assistant</ChatTitle>
+              </ChatHeader>
+              <ChatView
+                tableName="LC_AI"
+                modelType="n8n"
+                // streaming={true}
+                // systemPrompt="You are a helpful assistant."
+                // agent={true}
+                // maxInteractions={10}
+                modelHost="http://localhost:5678/webhook-test/9a363e76-d3a5-46d1-98c3-4359f7106d33"
+              />
+            </Flex>
+          )}
+        </Flex>
       </StyledResizableBox>
     </>
   );
diff --git a/client/packages/lowcoder/src/pages/editor/bottom/BottomSidebar.tsx b/client/packages/lowcoder/src/pages/editor/bottom/BottomSidebar.tsx
index 70caf29d12..6f8a6f4d79 100644
--- a/client/packages/lowcoder/src/pages/editor/bottom/BottomSidebar.tsx
+++ b/client/packages/lowcoder/src/pages/editor/bottom/BottomSidebar.tsx
@@ -34,7 +34,7 @@ const Contain = styled.div`
   width: 100%;
   background-color: #ffffff;
 `;
-const Title = styled.div`
+export const Title = styled.div`
   flex-shrink: 0;
   height: 40px;
   width: 100%;
@@ -82,16 +82,17 @@ const AddIcon = styled(BluePlusIcon)`
   width: 12px;
   margin-right: 2px;
 `;
-const AddBtn = styled(TacoButton)`
+export const AddBtn = styled(TacoButton)`
   &&& {
     height: 24px;
     width: 64px;
-    padding: 4px 12px;
+    padding: 4px 10px;
     background-color: #fafbff;
     color: #4965f2;
     border-color: #c9d1fc;
     display: flex;
     align-items: center;
+    gap: 0;
     box-shadow: none;
   
     &:hover {

From 18045b9067e0a52a97bca4dbc3858624e38c227a Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Mon, 7 Jul 2025 15:45:16 +0500
Subject: [PATCH 24/54] Added Styling actions (Fixed Constant) Added Nesting
 components

---
 .../comps/comps/preLoadComp/actionConfigs.ts  |   6 +-
 .../comps/preLoadComp/actionInputSection.tsx  |  80 +++++++++---
 .../actions/componentManagement.ts            | 119 ++++++++++++++++++
 .../preLoadComp/actions/componentStyling.ts   | 107 +++++++++++++---
 .../src/comps/comps/preLoadComp/styled.tsx    |   3 +
 .../src/comps/comps/preLoadComp/types.ts      |   3 +
 .../src/comps/comps/preLoadComp/utils.ts      |   2 +-
 client/packages/lowcoder/src/comps/index.tsx  |  13 ++
 .../lowcoder/src/comps/uiCompRegistry.ts      |   1 +
 9 files changed, 297 insertions(+), 37 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
index 2eae082a16..02f0bbe736 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
@@ -8,7 +8,8 @@ import {
   configureComponentAction,
   changeLayoutAction,
   addEventHandlerAction,
-  applyStyleAction
+  applyStyleAction,
+  nestComponentAction
 } from "./actions";
 
 export const actionCategories: ActionCategory[] = [
@@ -20,7 +21,8 @@ export const actionCategories: ActionCategory[] = [
       moveComponentAction, 
       deleteComponentAction, 
       resizeComponentAction,
-      renameComponentAction
+      renameComponentAction,
+      nestComponentAction
     ]
   },
   {
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
index 148dac1674..a78ab6fb31 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
@@ -25,7 +25,10 @@ export function ActionInputSection() {
   const [placeholderText, setPlaceholderText] = useState<string>("");
   const [selectedComponent, setSelectedComponent] = useState<string | null>(null);
   const [showComponentDropdown, setShowComponentDropdown] = useState<boolean>(false);
+  const [isNestedComponent, setIsNestedComponent] = useState<boolean>(false);
+  const [selectedNestComponent, setSelectedNestComponent] = useState<string | null>(null);
   const [showEditorComponentsDropdown, setShowEditorComponentsDropdown] = useState<boolean>(false);
+  const [showStylingInput, setShowStylingInput] = useState<boolean>(false);
   const [selectedEditorComponent, setSelectedEditorComponent] = useState<string | null>(null);
   const [validationError, setValidationError] = useState<string | null>(null);
   const inputRef = useRef<InputRef>(null);
@@ -73,44 +76,55 @@ export function ActionInputSection() {
 
     setShowComponentDropdown(false);
     setShowEditorComponentsDropdown(false);
+    setShowStylingInput(false);
     setSelectedComponent(null);
     setSelectedEditorComponent(null);
+    setIsNestedComponent(false);
+    setSelectedNestComponent(null);
     setActionValue("");
 
     if (action.requiresComponentSelection) {
       setShowComponentDropdown(true);
       setPlaceholderText("Select a component to add");
-    } else if (action.requiresEditorComponentSelection) {
+    } 
+    if (action.requiresEditorComponentSelection) {
       setShowEditorComponentsDropdown(true);
       setPlaceholderText(`Select a component to ${action.label.toLowerCase()}`);
-    } else if (action.requiresInput) {
+    }  
+    if (action.requiresInput) {
       setPlaceholderText(action.inputPlaceholder || `Enter ${action.label.toLowerCase()} value`);
     } else {
       setPlaceholderText(`Execute ${action.label.toLowerCase()}`);
     }
+    if (action.requiresStyle) {
+      setShowStylingInput(true);
+      setPlaceholderText(`Select a component to style`);
+    }
+    if (action.isNested) {
+      setIsNestedComponent(true);
+    }
   }, []);
 
   const handleComponentSelection = useCallback((key: string) => {
     if (key.startsWith('comp-')) {
       const compName = key.replace('comp-', '');
-      setSelectedComponent(compName);
+      isNestedComponent ? setSelectedNestComponent(compName) : setSelectedComponent(compName);
       setPlaceholderText(`Configure ${compName} component`);
     }
-  }, []);
+  }, [isNestedComponent]);
 
   const handleEditorComponentSelection = useCallback((key: string) => {
     setSelectedEditorComponent(key);
-    if (currentAction) {
-      setPlaceholderText(`${currentAction.label}`);
-    }
+    setPlaceholderText(`${currentAction?.label}`);
   }, [currentAction]);
 
+
   const validateInput = useCallback((value: string): string | null => {
     if (!currentAction?.validation) return null;
     return currentAction.validation(value);
   }, [currentAction]);
 
-  const handleInputChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
+  const handleInputChange = useCallback((e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => {
     const value = e.target.value;
     setActionValue(value);
     
@@ -149,12 +163,18 @@ export function ActionInputSection() {
       return;
     }
 
+    if(currentAction.isNested && !selectedNestComponent) {
+      message.error('Please select a component to nest');
+      return;
+    }
+
     try {
       await currentAction.execute({
         actionKey: selectedActionKey,
         actionValue,
         selectedComponent,
         selectedEditorComponent,
+        selectedNestComponent,
         editorState
       });
 
@@ -167,6 +187,8 @@ export function ActionInputSection() {
       setSelectedEditorComponent(null);
       setPlaceholderText("");
       setValidationError(null);
+      setIsNestedComponent(false);
+      setSelectedNestComponent(null);
 
     } catch (error) {
       console.error('Error executing action:', error);
@@ -177,6 +199,7 @@ export function ActionInputSection() {
     actionValue, 
     selectedComponent, 
     selectedEditorComponent, 
+    selectedNestComponent,
     editorState, 
     currentAction, 
     validateInput
@@ -235,7 +258,7 @@ export function ActionInputSection() {
             </Button>
           </CustomDropdown>
           
-          {showComponentDropdown && (
+          {(showComponentDropdown || isNestedComponent) && (
             <CustomDropdown
               overlayStyle={{ 
                 maxHeight: '400px',
@@ -253,7 +276,13 @@ export function ActionInputSection() {
             >
               <Button size={"small"}>
                 <Space>
-                  {selectedComponent ? selectedComponent : 'Select Component'} 
+                  {
+                    selectedComponent 
+                    ? selectedComponent 
+                    : selectedNestComponent 
+                    ? selectedNestComponent 
+                    : 'New Component'
+                  }
                   <DownOutlined />
                 </Space>
               </Button>
@@ -278,23 +307,34 @@ export function ActionInputSection() {
             >
               <Button size={"small"}>
                 <Space>
-                  {selectedEditorComponent ? selectedEditorComponent : 'Select Component'} 
+                  {selectedEditorComponent ? selectedEditorComponent : 'Editor Component'} 
                   <DownOutlined />
                 </Space>
               </Button>
             </CustomDropdown>
           )}
-          
+
           {shouldShowInput && (
-            <Input
-              ref={inputRef}
-              value={actionValue}
-              onChange={handleInputChange}
-              placeholder={placeholderText}
-              status={validationError ? 'error' : undefined}
-            />
+            showStylingInput ? (
+              <Input.TextArea
+                ref={inputRef}
+                value={actionValue}
+                onChange={handleInputChange}
+                placeholder={placeholderText}
+                status={validationError ? 'error' : undefined}
+                autoSize={{ minRows: 1 }}
+              />
+            ) : (
+              <Input
+                ref={inputRef}
+                value={actionValue}
+                onChange={handleInputChange}
+                placeholder={placeholderText}
+                status={validationError ? 'error' : undefined}
+              />
+            )
           )}
-          
+
           {validationError && (
             <div style={{ color: '#ff4d4f', fontSize: '12px', marginTop: '-8px' }}>
               {validationError}
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
index f86358b164..669c77524b 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
@@ -108,6 +108,125 @@ export const addComponentAction: ActionConfig = {
   }
 };
 
+export const nestComponentAction: ActionConfig = {
+  key: 'nest-components',
+  label: 'Nest a component',
+  category: 'component-management',
+  requiresEditorComponentSelection: true,
+  requiresInput: false,
+  isNested: true,
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedEditorComponent, selectedNestComponent, editorState } = params;
+    
+    if (!selectedEditorComponent || !selectedNestComponent || !editorState) {
+      message.error('Parent component, child component, and editor state are required');
+      return;
+    }
+
+    const parentComponentInfo = getEditorComponentInfo(editorState, selectedEditorComponent);
+    
+    if (!parentComponentInfo) {
+      message.error(`Parent component "${selectedEditorComponent}" not found`);
+      return;
+    }
+
+    const { componentKey: parentKey, items } = parentComponentInfo;
+    
+    if (!parentKey) {
+      message.error(`Parent component "${selectedEditorComponent}" not found in layout`);
+      return;
+    }
+
+    const parentItem = items[parentKey];
+    if (!parentItem) {
+      message.error(`Parent component "${selectedEditorComponent}" not found in items`);
+      return;
+    }
+
+    // Check if parent is a container
+    const parentCompType = parentItem.children.compType.getView();
+    const parentManifest = uiCompRegistry[parentCompType];
+    
+    if (!parentManifest?.isContainer) {
+      message.error(`Component "${selectedEditorComponent}" is not a container and cannot nest components`);
+      return;
+    }
+
+    try {
+
+      const nameGenerator = editorState.getNameGenerator();
+      const compInfo = parseCompType(selectedNestComponent);
+      const compName = nameGenerator.genItemName(compInfo.compName);
+      const key = genRandomKey();
+
+      const manifest = uiCompRegistry[selectedNestComponent];
+      let defaultDataFn = undefined;
+
+      if (manifest?.lazyLoad) {
+        const { defaultDataFnName, defaultDataFnPath } = manifest;
+        if (defaultDataFnName && defaultDataFnPath) {
+          const module = await import(`../../../${defaultDataFnPath}.tsx`);
+          defaultDataFn = module[defaultDataFnName];
+        }
+      } else if (!compInfo.isRemote) {
+        defaultDataFn = manifest?.defaultDataFn;
+      }
+
+      const widgetValue: GridItemDataType = {
+        compType: selectedNestComponent,
+        name: compName,
+        comp: defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined,
+      };
+
+      const parentContainer = parentItem.children.comp;
+      
+      const realContainer = parentContainer.realSimpleContainer();
+      if (!realContainer) {
+        message.error(`Container "${selectedEditorComponent}" cannot accept nested components`);
+        return;
+      }
+      
+      const currentLayout = realContainer.children.layout.getView();
+      const layoutInfo = manifest?.layoutInfo || defaultLayout(selectedNestComponent as UICompType);
+      
+      let itemPos = 0;
+      if (Object.keys(currentLayout).length > 0) {
+        itemPos = Math.max(...Object.values(currentLayout).map((l: any) => l.pos || 0)) + 1;
+      }
+
+      const layoutItem = {
+        i: key,
+        x: 0,
+        y: 0,
+        w: layoutInfo.w || 6,
+        h: layoutInfo.h || 5,
+        pos: itemPos,
+        isDragging: false,
+      };
+
+      realContainer.dispatch(
+        wrapActionExtraInfo(
+          multiChangeAction({
+            layout: changeValueAction({
+              ...currentLayout,
+              [key]: layoutItem,
+            }, true),
+            items: addMapChildAction(key, widgetValue),
+          }),
+          { compInfos: [{ compName: compName, compType: selectedNestComponent, type: "add" }] }
+        )
+      );
+
+      editorState.setSelectedCompNames(new Set([compName]), "nestComp");
+      
+      message.success(`Component "${manifest?.name || selectedNestComponent}" nested in "${selectedEditorComponent}" successfully!`);
+    } catch (error) {
+      console.error('Error nesting component:', error);
+      message.error('Failed to nest component. Please try again.');
+    }
+  }
+}
+
 export const deleteComponentAction: ActionConfig = {
   key: 'delete-components',
   label: 'Delete a component',
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentStyling.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentStyling.ts
index 2a152713ea..dbe6297a0b 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentStyling.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentStyling.ts
@@ -1,34 +1,113 @@
 import { message } from "antd";
 import { ActionConfig, ActionExecuteParams } from "../types";
+import { getEditorComponentInfo } from "../utils";
+
+// Fallback constant style object to apply
+// This wil be replaced by a JSON object returned by the AI model.
+const FALLBACK_STYLE_OBJECT = {
+  fontSize: "10px",
+  fontWeight: "500",
+  color: "#333333",
+  backgroundColor: "#ffffff",
+  padding: "8px",
+  borderRadius: "4px",
+  border: "1px solid #ddd"
+};
 
 export const applyStyleAction: ActionConfig = {
   key: 'apply-style',
   label: 'Apply style to component',
   category: 'styling',
   requiresEditorComponentSelection: true,
+  requiresStyle: true,
   requiresInput: true,
   inputPlaceholder: 'Enter CSS styles (JSON format)',
-  inputType: 'json',
+  inputType: 'textarea',
   validation: (value: string) => {
-    if (!value.trim()) return 'Styles are required';
-    try {
-      JSON.parse(value);
-      return null;
-    } catch {
-      return 'Invalid JSON format';
-    }
+    if (!value.trim()) return 'Styles are required'
+    else return null;
   },
   execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, actionValue } = params;
+    const { selectedEditorComponent, actionValue, editorState } = params;
     
+    if (!selectedEditorComponent || !editorState) {
+      message.error('Component and editor state are required');
+      return;
+    }
+
+    // A fallback constant is currently used to style the component.
+    // This is a temporary solution and will be removed once we integrate the AI model with the component styling.
     try {
-      const styles = JSON.parse(actionValue);
-      console.log('Applying styles to component:', selectedEditorComponent, 'with styles:', styles);
-      message.info(`Styles applied to component "${selectedEditorComponent}"`);
+      let styleObject: Record<string, any> = {};
+      let usingFallback = false;
+      
+      try {
+        if (typeof actionValue === 'string') {
+          styleObject = JSON.parse(actionValue);
+        } else {
+          styleObject = actionValue;
+        }
+      } catch (e) {
+        styleObject = FALLBACK_STYLE_OBJECT;
+        usingFallback = true;
+      }
+      
+      const comp = editorState.getUICompByName(selectedEditorComponent);
+      
+      if (!comp) {
+        message.error(`Component "${selectedEditorComponent}" not found`);
+        return;
+      }
+
+      const appliedStyles: string[] = [];
+      
+      for (const [styleKey, styleValue] of Object.entries(styleObject)) {
+        try {
+          const { children } = comp.children.comp;
+          const compType = comp.children.compType.getView();
+
+          // This method is used in LeftLayersContent.tsx to style the component.
+          if (!children.style) {
+            if (children[compType]?.children?.style?.children?.[styleKey]) {
+              children[compType].children.style.children[styleKey].dispatchChangeValueAction(styleValue);
+              appliedStyles.push(styleKey);
+            } else if (children[compType]?.children?.[styleKey]) {
+              children[compType].children[styleKey].dispatchChangeValueAction(styleValue);
+              appliedStyles.push(styleKey);
+            } else {
+              console.warn(`Style property ${styleKey} not found in component ${selectedEditorComponent}`);
+            }
+          } else {
+            if (children.style.children?.[styleKey]) {
+              children.style.children[styleKey].dispatchChangeValueAction(styleValue);
+              appliedStyles.push(styleKey);
+            } else if (children.style[styleKey]) {
+              children.style[styleKey].dispatchChangeValueAction(styleValue);
+              appliedStyles.push(styleKey);
+            } else {
+              console.warn(`Style property ${styleKey} not found in style object`);
+            }
+          }
+        } catch (error) {
+          console.error(`Error applying style ${styleKey}:`, error);
+        }
+      }
+
+      if (appliedStyles.length > 0) {
+        editorState.setSelectedCompNames(new Set([selectedEditorComponent]), "applyStyle");
+        
+        if (usingFallback) {
+          message.success(`Applied ${appliedStyles.length} fallback style(s) to component "${selectedEditorComponent}": ${appliedStyles.join(', ')}`);
+        } else {
+          message.success(`Applied ${appliedStyles.length} style(s) to component "${selectedEditorComponent}": ${appliedStyles.join(', ')}`);
+        }
+      } else {
+        message.warning('No styles were applied. Check if the component supports styling.');
+      }
       
-      // TODO: Implement actual style application logic
     } catch (error) {
-      message.error('Invalid style format');
+      console.error('Error applying styles:', error);
+      message.error('Failed to apply styles. Please try again.');
     }
   }
 }; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/styled.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/styled.tsx
index 211115e996..ae13c2c3f8 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/styled.tsx
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/styled.tsx
@@ -6,6 +6,9 @@ export const CustomDropdown = styled(Dropdown)`
     width: 14px !important;
     height: 14px !important; 
     max-width: 14px !important;
+    overflow: hidden !important;
+    white-space: nowrap;
+    text-overflow: hidden !important;
   }
 `;
 
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
index 7e84ab1da2..a33f0f8f16 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
@@ -33,6 +33,8 @@ export interface ActionConfig {
   requiresComponentSelection?: boolean;
   requiresEditorComponentSelection?: boolean;
   requiresInput?: boolean;
+  requiresStyle?: boolean;
+  isNested?: boolean;
   inputPlaceholder?: string;
   inputType?: 'text' | 'number' | 'textarea' | 'json';
   validation?: (value: string) => string | null; 
@@ -44,6 +46,7 @@ export interface ActionExecuteParams {
   actionValue: string;
   selectedComponent: string | null;
   selectedEditorComponent: string | null;
+  selectedNestComponent: string | null;
   editorState: any;
 }
 
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
index 3f3ae1b739..b30f02fb2b 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
@@ -22,7 +22,7 @@ export function generateComponentActionItems(categories: Record<string, [string,
   const componentItems: MenuProps['items'] = [];
   
   Object.entries(categories).forEach(([categoryKey, components]) => {
-    if (components.length > 0) {
+    if (components.length) {
       componentItems.push({
         label: uiCompCategoryNames[categoryKey as UICompCategory],
         key: `category-${categoryKey}`,
diff --git a/client/packages/lowcoder/src/comps/index.tsx b/client/packages/lowcoder/src/comps/index.tsx
index 2395f4f290..81a9c634c1 100644
--- a/client/packages/lowcoder/src/comps/index.tsx
+++ b/client/packages/lowcoder/src/comps/index.tsx
@@ -544,6 +544,7 @@ export var uiCompMap: Registry = {
     categories: ["layout"],
     icon: ResponsiveLayoutCompIcon,
     keywords: trans("uiComp.responsiveLayoutCompKeywords"),
+    isContainer: true,
     comp: ResponsiveLayoutComp,
     withoutLoading: true,
     layoutInfo: {
@@ -559,6 +560,7 @@ export var uiCompMap: Registry = {
     categories: ["layout"],
     icon: PageLayoutCompIcon,
     keywords: trans("uiComp.pageLayoutCompKeywords"),
+    isContainer: true,
     comp: PageLayoutComp,
     withoutLoading: true,
     layoutInfo: {
@@ -576,6 +578,7 @@ export var uiCompMap: Registry = {
     categories: ["layout"],
     icon: ColumnLayoutCompIcon,
     keywords: trans("uiComp.responsiveLayoutCompKeywords"),
+    isContainer: true,
     comp: ColumnLayoutComp,
     withoutLoading: true,
     layoutInfo: {
@@ -591,6 +594,7 @@ export var uiCompMap: Registry = {
     categories: ["layout"],
     icon: SplitLayoutCompIcon,
     keywords: trans("uiComp.splitLayoutCompKeywords"),
+    isContainer: true,
     comp: SplitLayoutComp,
     withoutLoading: true,
     layoutInfo: {
@@ -606,6 +610,7 @@ export var uiCompMap: Registry = {
     categories: ["layout"],
     icon: FloatingTextCompIcon,
     keywords: trans("uiComp.floatTextContainerCompKeywords"),
+    isContainer: true,
     comp: FloatTextContainerComp,
     withoutLoading: true,
     layoutInfo: {
@@ -636,6 +641,7 @@ export var uiCompMap: Registry = {
     categories: ["layout"],
     icon: TabbedContainerCompIcon,
     keywords: trans("uiComp.tabbedContainerCompKeywords"),
+    isContainer: true,
     comp: TabbedContainerComp,
     withoutLoading: true,
     layoutInfo: {
@@ -652,6 +658,7 @@ export var uiCompMap: Registry = {
     categories: ["layout"],
     icon: CollapsibleContainerCompIcon,
     keywords: trans("uiComp.collapsibleContainerCompKeywords"),
+    isContainer: true,
     comp: ContainerComp,
     withoutLoading: true,
     layoutInfo: {
@@ -669,6 +676,7 @@ export var uiCompMap: Registry = {
     categories: ["layout"],
     icon: ContainerCompIcon,
     keywords: trans("uiComp.containerCompKeywords"),
+    isContainer: true,
     comp: ContainerComp,
     withoutLoading: true,
     layoutInfo: {
@@ -686,6 +694,7 @@ export var uiCompMap: Registry = {
     description: trans("uiComp.listViewCompDesc"),
     categories: ["layout"],
     keywords: trans("uiComp.listViewCompKeywords"),
+    isContainer: true,
     comp: ListViewComp,
     layoutInfo: {
       w: 12,
@@ -701,6 +710,7 @@ export var uiCompMap: Registry = {
     description: trans("uiComp.gridCompDesc"),
     categories: ["layout"],
     keywords: trans("uiComp.gridCompKeywords"),
+    isContainer: true,
     comp: GridComp,
     layoutInfo: {
       w: 12,
@@ -718,6 +728,7 @@ export var uiCompMap: Registry = {
     keywords: trans("uiComp.modalCompKeywords"),
     comp: ModalComp,
     withoutLoading: true,
+    isContainer: true,
   },
   drawer: {
     name: trans("uiComp.drawerCompName"),
@@ -728,6 +739,7 @@ export var uiCompMap: Registry = {
     keywords: trans("uiComp.drawerCompKeywords"),
     comp: DrawerComp,
     withoutLoading: true,
+    isContainer: true,
   },
   divider: {
     name: trans("uiComp.dividerCompName"),
@@ -941,6 +953,7 @@ export var uiCompMap: Registry = {
     categories: ["forms"],
     icon: FormCompIcon,
     keywords: trans("uiComp.formCompKeywords"),
+    isContainer: true,
     comp: FormComp,
     withoutLoading: true,
     layoutInfo: {
diff --git a/client/packages/lowcoder/src/comps/uiCompRegistry.ts b/client/packages/lowcoder/src/comps/uiCompRegistry.ts
index 4c320de479..c260bad386 100644
--- a/client/packages/lowcoder/src/comps/uiCompRegistry.ts
+++ b/client/packages/lowcoder/src/comps/uiCompRegistry.ts
@@ -51,6 +51,7 @@ export interface UICompManifest {
   lazyLoad?: boolean;
   compName?: string;
   compPath?: string;
+  isContainer?: boolean;
   defaultDataFn?: CompDefaultDataFunction;
   defaultDataFnName?: string;
   defaultDataFnPath?: string;

From d6cea0c2d4d9b3200f789cb71bd80a9a9e3c4bab Mon Sep 17 00:00:00 2001
From: RAHEEL <mraheeliftikhar1994@gmail.com>
Date: Tue, 8 Jul 2025 14:31:02 +0500
Subject: [PATCH 25/54] workflow integration

---
 .../comps/chatComp/components/ChatMain.tsx    | 78 ++++++++++++++++---
 .../actions/componentManagement.ts            | 49 ++++++++----
 .../src/comps/comps/preLoadComp/types.ts      |  1 +
 .../src/pages/editor/bottom/BottomPanel.tsx   |  2 +-
 4 files changed, 105 insertions(+), 25 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
index 14ba061ca7..bfbe933df6 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from "react";
+import React, { useContext, useState, useRef, useEffect } from "react";
 import {
   useExternalStoreRuntime,
   ThreadMessageLike,
@@ -17,6 +17,9 @@ import {
 } from "./context/ChatContext";
 import styled from "styled-components";
 import { ChatCompProps } from "../chatCompTypes";
+import { message } from "antd";
+import { EditorContext } from "@lowcoder-ee/comps/editorState";
+import { addComponentAction } from "../../preLoadComp/actions/componentManagement";
 
 const ChatContainer = styled.div<{ $autoHeight?: boolean }>`
   display: flex;
@@ -54,26 +57,44 @@ const callYourAPI = async (params: {
   text: string,
   modelHost: string,
   modelType: string,
+  sessionId: string,
 }) => {
-  const { text, modelHost, modelType } = params;
+  const { text, modelHost, modelType, sessionId } = params;
 
   let url = modelHost;
   if (modelType === "direct-llm") {
     url = `${modelHost}/api/chat/completions`;
   }
 
+  const response = await fetch(`${url}`, {
+    method: "POST",
+    body: JSON.stringify({
+      text,
+      sessionId,
+    }),
+  });
+
+  return response.json();
   // Simulate API delay
-  await new Promise(resolve => setTimeout(resolve, 1500));
+  // await new Promise(resolve => setTimeout(resolve, 1500));
   
   // Simple responses
-  return {
-    content: "This is a mock response from your backend. You typed: " + text
-  };
+  // return {
+  //   content: "This is a mock response from your backend. You typed: " + text
+  // };
 };
 
 export function ChatMain(props: ChatCompProps) {
   const { state, actions } = useChatContext();
   const [isRunning, setIsRunning] = useState(false);
+  const editorState = useContext(EditorContext);
+  const editorStateRef = useRef(editorState);
+
+  // Keep the ref updated with the latest editorState
+  useEffect(() => {
+    console.log("EDITOR STATE CHANGE ---> ", editorState);
+    editorStateRef.current = editorState;
+  }, [editorState]);
 
   console.log("STATE", state);
 
@@ -88,6 +109,36 @@ export function ChatMain(props: ChatCompProps) {
     createdAt: new Date(message.timestamp),
   });
 
+  const performAction = async (actions: any[]) => {
+    const comp = editorStateRef.current.getUIComp().children.comp;
+    if (!comp) {
+      console.error("No comp found");
+      return;
+    }
+    // const layout = comp.children.layout.getView();
+    // console.log("LAYOUT", layout);
+
+    for (const action of actions) {
+      const { action_name, action_parameters, action_payload } = action;
+
+      switch (action_name) {
+        case "place_component":
+          await addComponentAction.execute({
+            actionKey: action_name,
+            actionValue: "",
+            actionPayload: action_payload,
+            selectedComponent: action_parameters,
+            selectedEditorComponent: null,
+            editorState: editorStateRef.current
+          });
+          break;
+        default:
+          break;
+      }
+      await new Promise(resolve => setTimeout(resolve, 1000));
+    }
+  };
+
   const onNew = async (message: AppendMessage) => {
     // Extract text from AppendMessage content array
     if (message.content.length !== 1 || message.content[0]?.type !== "text") {
@@ -112,12 +163,15 @@ export function ChatMain(props: ChatCompProps) {
         text: userMessage.text,
         modelHost: props.modelHost!,
         modelType: props.modelType!,
+        sessionId: state.currentThreadId,
       });
-      
+      const {reply, actions: editorActions} = JSON.parse(response?.output);
+      performAction(editorActions);
+
       const assistantMessage: MyMessage = {
         id: generateId(),
         role: "assistant",
-        text: response.content,
+        text: reply,
         timestamp: Date.now(),
       };
       
@@ -170,12 +224,16 @@ export function ChatMain(props: ChatCompProps) {
         text: editedMessage.text,
         modelHost: props.modelHost!,
         modelType: props.modelType!,
+        sessionId: state.currentThreadId,
       });
-      
+    
+      const {reply, actions: editorActions} = JSON.parse(response?.output);
+      performAction(editorActions);
+
       const assistantMessage: MyMessage = {
         id: generateId(),
         role: "assistant",
-        text: response.content,
+        text: reply,
         timestamp: Date.now(),
       };
       
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
index 669c77524b..cb614fdfec 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
@@ -13,6 +13,7 @@ import {
     deleteCompAction 
 } from "lowcoder-core";
 import { getEditorComponentInfo } from "../utils";
+import { getPromiseAfterDispatch } from "@lowcoder-ee/util/promiseUtils";
 
 export const addComponentAction: ActionConfig = {
   key: 'add-components',
@@ -21,8 +22,9 @@ export const addComponentAction: ActionConfig = {
   requiresComponentSelection: true,
   requiresInput: false,
   execute: async (params: ActionExecuteParams) => {
-    const { selectedComponent, editorState } = params;
-    
+    const { selectedComponent, editorState, actionPayload } = params;
+    const { name, layout, ...otherProps } = actionPayload;
+
     if (!selectedComponent || !editorState) {
       message.error('Component and editor state are required');
       return;
@@ -43,31 +45,33 @@ export const addComponentAction: ActionConfig = {
         return;
       }
 
+      let compName = name;
       const nameGenerator = editorState.getNameGenerator();
       const compInfo = parseCompType(selectedComponent);
-      const compName = nameGenerator.genItemName(compInfo.compName);
+      if (!compName) {
+        compName = nameGenerator.genItemName(compInfo.compName);
+      }
       const key = genRandomKey();
 
       const manifest = uiCompRegistry[selectedComponent];
       let defaultDataFn = undefined;
 
-      if (manifest?.lazyLoad) {
-        const { defaultDataFnName, defaultDataFnPath } = manifest;
-        if (defaultDataFnName && defaultDataFnPath) {
-          const module = await import(`../../../${defaultDataFnPath}.tsx`);
-          defaultDataFn = module[defaultDataFnName];
-        }
-      } else if (!compInfo.isRemote) {
+      if (!compInfo.isRemote) {
         defaultDataFn = manifest?.defaultDataFn;
       }
 
+      let compDefaultValue = defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined;
+      const compInitialValue = {
+        ...(compDefaultValue as any || {}),
+        ...otherProps,
+      }
       const widgetValue: GridItemDataType = {
         compType: selectedComponent,
         name: compName,
-        comp: defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined,
+        comp: compInitialValue,
       };
 
-      const currentLayout = simpleContainer.children.layout.getView();
+      const currentLayout = uiComp.children.comp.children.layout.getView();
       const layoutInfo = manifest?.layoutInfo || defaultLayout(selectedComponent as UICompType);
       
       let itemPos = 0;
@@ -83,9 +87,11 @@ export const addComponentAction: ActionConfig = {
         h: layoutInfo.h || 5,
         pos: itemPos,
         isDragging: false,
+        ...(layout || {}),
       };
 
-      simpleContainer.dispatch(
+      await getPromiseAfterDispatch(
+        uiComp.children.comp.dispatch,
         wrapActionExtraInfo(
           multiChangeAction({
             layout: changeValueAction({
@@ -95,8 +101,23 @@ export const addComponentAction: ActionConfig = {
             items: addMapChildAction(key, widgetValue),
           }),
           { compInfos: [{ compName: compName, compType: selectedComponent, type: "add" }] }
-        )
+        ),
+        {
+          autoHandleAfterReduce: true,
+        }
       );
+      // simpleContainer.dispatch(
+      //   wrapActionExtraInfo(
+      //     multiChangeAction({
+      //       layout: changeValueAction({
+      //         ...currentLayout,
+      //         [key]: layoutItem,
+      //       }, true),
+      //       items: addMapChildAction(key, widgetValue),
+      //     }),
+      //     { compInfos: [{ compName: compName, compType: selectedComponent, type: "add" }] }
+      //   )
+      // );
 
       editorState.setSelectedCompNames(new Set([compName]), "addComp");
       
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
index a33f0f8f16..b6318f9652 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
@@ -44,6 +44,7 @@ export interface ActionConfig {
 export interface ActionExecuteParams {
   actionKey: string;
   actionValue: string;
+  actionPayload?: any;
   selectedComponent: string | null;
   selectedEditorComponent: string | null;
   selectedNestComponent: string | null;
diff --git a/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx b/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
index c71364470b..a3c8aeca82 100644
--- a/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
+++ b/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
@@ -125,7 +125,7 @@ function Bottom(props: any) {
                 // systemPrompt="You are a helpful assistant."
                 // agent={true}
                 // maxInteractions={10}
-                modelHost="http://localhost:5678/webhook-test/9a363e76-d3a5-46d1-98c3-4359f7106d33"
+                modelHost="http://192.168.100.49:5678/webhook/9a363e76-d3a5-46d1-98c3-4359f7106d33"
               />
             </Flex>
           )}

From 84c165bbfd219cb96c16aac7581dfebfdbf9b577 Mon Sep 17 00:00:00 2001
From: RAHEEL <mraheeliftikhar1994@gmail.com>
Date: Fri, 11 Jul 2025 18:51:09 +0500
Subject: [PATCH 26/54] mapped nest_component and set_properties action

---
 .../comps/chatComp/components/ChatMain.tsx    | 29 ++++++++++++-
 .../actions/componentConfiguration.ts         | 35 ++++++++++++++-
 .../actions/componentManagement.ts            | 43 +++++++++++++++----
 3 files changed, 95 insertions(+), 12 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
index bfbe933df6..c0743cefac 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
@@ -19,7 +19,8 @@ import styled from "styled-components";
 import { ChatCompProps } from "../chatCompTypes";
 import { message } from "antd";
 import { EditorContext } from "@lowcoder-ee/comps/editorState";
-import { addComponentAction } from "../../preLoadComp/actions/componentManagement";
+import { addComponentAction, nestComponentAction } from "../../preLoadComp/actions/componentManagement";
+import { configureComponentAction } from "../../preLoadComp/actions/componentConfiguration";
 
 const ChatContainer = styled.div<{ $autoHeight?: boolean }>`
   display: flex;
@@ -92,7 +93,7 @@ export function ChatMain(props: ChatCompProps) {
 
   // Keep the ref updated with the latest editorState
   useEffect(() => {
-    console.log("EDITOR STATE CHANGE ---> ", editorState);
+    // console.log("EDITOR STATE CHANGE ---> ", editorState);
     editorStateRef.current = editorState;
   }, [editorState]);
 
@@ -129,6 +130,30 @@ export function ChatMain(props: ChatCompProps) {
             actionPayload: action_payload,
             selectedComponent: action_parameters,
             selectedEditorComponent: null,
+            selectedNestComponent: null,
+            editorState: editorStateRef.current
+          });
+          break;
+        case "nest_component":
+          await nestComponentAction.execute({
+            actionKey: action_name,
+            actionValue: "",
+            actionPayload: action_payload,
+            selectedComponent: action_parameters,
+            selectedEditorComponent: null,
+            selectedNestComponent: null,
+            editorState: editorStateRef.current
+          });
+          break;
+        case "set_properties":
+          debugger;
+          await configureComponentAction.execute({
+            actionKey: action_name,
+            actionValue: action_parameters,
+            actionPayload: action_payload,
+            selectedEditorComponent: null,
+            selectedComponent: null,
+            selectedNestComponent: null,
             editorState: editorStateRef.current
           });
           break;
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts
index 2106b1eda9..fefca21d05 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts
@@ -1,5 +1,6 @@
 import { message } from "antd";
 import { ActionConfig, ActionExecuteParams } from "../types";
+import { getEditorComponentInfo } from "../utils";
 
 export const configureComponentAction: ActionConfig = {
   key: 'configure-components',
@@ -19,10 +20,40 @@ export const configureComponentAction: ActionConfig = {
     }
   },
   execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, actionValue } = params;
+    const { selectedEditorComponent, actionValue: name, actionValue, actionPayload, editorState } = params;
+    const otherProps = actionPayload;
+    // const { name, ...otherProps } = actionPayload;
     
     try {
-      const config = JSON.parse(actionValue);
+      const componentInfo = getEditorComponentInfo(editorState, name);
+      
+      if (!componentInfo) {
+        message.error(`Component "${selectedEditorComponent}" not found`);
+        return;
+      }
+
+      const { componentKey: parentKey, items } = componentInfo;
+    
+      if (!parentKey) {
+        message.error(`Parent component "${selectedEditorComponent}" not found in layout`);
+        return;
+      }
+
+      const parentItem = items[parentKey];
+      if (!parentItem) {
+        message.error(`Parent component "${selectedEditorComponent}" not found in items`);
+        return;
+      }
+
+      const itemComp = parentItem.children.comp;
+      const itemData = itemComp.toJsonValue();
+      const config = {
+        ...itemData,
+        ...otherProps
+      };
+      itemComp.dispatchChangeValueAction(config);
+
+      debugger;
       console.log('Configuring component:', selectedEditorComponent, 'with config:', config);
       message.info(`Configure action for component "${selectedEditorComponent}"`);
       
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
index cb614fdfec..8591a9edbe 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
@@ -137,14 +137,17 @@ export const nestComponentAction: ActionConfig = {
   requiresInput: false,
   isNested: true,
   execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, selectedNestComponent, editorState } = params;
-    
+    // const { selectedEditorComponent, selectedNestComponent, editorState, actionPayload } = params;
+    const { editorState, actionPayload, selectedComponent: selectedNestComponent } = params;
+    const { name, layout, target: selectedEditorComponent, ...otherProps } = actionPayload;
+
     if (!selectedEditorComponent || !selectedNestComponent || !editorState) {
       message.error('Parent component, child component, and editor state are required');
       return;
     }
 
-    const parentComponentInfo = getEditorComponentInfo(editorState, selectedEditorComponent);
+    const [editorComponent, ...childComponents] = selectedEditorComponent.split('.');
+    const parentComponentInfo = getEditorComponentInfo(editorState, editorComponent);
     
     if (!parentComponentInfo) {
       message.error(`Parent component "${selectedEditorComponent}" not found`);
@@ -174,10 +177,15 @@ export const nestComponentAction: ActionConfig = {
     }
 
     try {
-
+      let compName = name;
       const nameGenerator = editorState.getNameGenerator();
       const compInfo = parseCompType(selectedNestComponent);
-      const compName = nameGenerator.genItemName(compInfo.compName);
+      if (!compName) {
+        compName = nameGenerator.genItemName(compInfo.compName);
+      }
+      // const nameGenerator = editorState.getNameGenerator();
+      // const compInfo = parseCompType(selectedNestComponent);
+      // const compName = nameGenerator.genItemName(compInfo.compName);
       const key = genRandomKey();
 
       const manifest = uiCompRegistry[selectedNestComponent];
@@ -193,15 +201,33 @@ export const nestComponentAction: ActionConfig = {
         defaultDataFn = manifest?.defaultDataFn;
       }
 
+      let compDefaultValue = defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined;
+      const compInitialValue = {
+        ...(compDefaultValue as any || {}),
+        ...otherProps,
+      }
+
       const widgetValue: GridItemDataType = {
         compType: selectedNestComponent,
         name: compName,
-        comp: defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined,
+        comp: compInitialValue,
       };
 
       const parentContainer = parentItem.children.comp;
-      
-      const realContainer = parentContainer.realSimpleContainer();
+      let originalContainer = parentContainer;
+      for (const childComponent of childComponents) {
+        originalContainer = originalContainer.children[childComponent];
+      }
+      if (originalContainer?.children?.[0]?.children?.view) {
+        originalContainer = originalContainer?.children?.[0]?.children?.view;
+      }
+
+      if (!originalContainer) {
+        message.error(`Container "${selectedEditorComponent}" cannot accept nested components`);
+        return;
+      }
+
+      const realContainer = originalContainer.realSimpleContainer();
       if (!realContainer) {
         message.error(`Container "${selectedEditorComponent}" cannot accept nested components`);
         return;
@@ -223,6 +249,7 @@ export const nestComponentAction: ActionConfig = {
         h: layoutInfo.h || 5,
         pos: itemPos,
         isDragging: false,
+        ...(layout || {}),
       };
 
       realContainer.dispatch(

From 6d5fbfdfe35d07e028a34e80a3696a10347d5977 Mon Sep 17 00:00:00 2001
From: RAHEEL <mraheeliftikhar1994@gmail.com>
Date: Fri, 18 Jul 2025 14:05:28 +0500
Subject: [PATCH 27/54] update actions

---
 .../comps/chatComp/components/ChatMain.tsx    | 22 ++++-----
 .../actions/componentManagement.ts            | 47 +++++++++++++------
 .../src/pages/editor/bottom/BottomPanel.tsx   |  2 +-
 3 files changed, 44 insertions(+), 27 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
index c0743cefac..1c906e4081 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
@@ -119,16 +119,16 @@ export function ChatMain(props: ChatCompProps) {
     // const layout = comp.children.layout.getView();
     // console.log("LAYOUT", layout);
 
-    for (const action of actions) {
-      const { action_name, action_parameters, action_payload } = action;
+    for (const actionItem of actions) {
+      const { action, component, ...action_payload } = actionItem;
 
-      switch (action_name) {
+      switch (action) {
         case "place_component":
           await addComponentAction.execute({
-            actionKey: action_name,
+            actionKey: action,
             actionValue: "",
             actionPayload: action_payload,
-            selectedComponent: action_parameters,
+            selectedComponent: component,
             selectedEditorComponent: null,
             selectedNestComponent: null,
             editorState: editorStateRef.current
@@ -136,10 +136,10 @@ export function ChatMain(props: ChatCompProps) {
           break;
         case "nest_component":
           await nestComponentAction.execute({
-            actionKey: action_name,
+            actionKey: action,
             actionValue: "",
             actionPayload: action_payload,
-            selectedComponent: action_parameters,
+            selectedComponent: component,
             selectedEditorComponent: null,
             selectedNestComponent: null,
             editorState: editorStateRef.current
@@ -148,8 +148,8 @@ export function ChatMain(props: ChatCompProps) {
         case "set_properties":
           debugger;
           await configureComponentAction.execute({
-            actionKey: action_name,
-            actionValue: action_parameters,
+            actionKey: action,
+            actionValue: component,
             actionPayload: action_payload,
             selectedEditorComponent: null,
             selectedComponent: null,
@@ -190,7 +190,7 @@ export function ChatMain(props: ChatCompProps) {
         modelType: props.modelType!,
         sessionId: state.currentThreadId,
       });
-      const {reply, actions: editorActions} = JSON.parse(response?.output);
+      const {explanation: reply, actions: editorActions} = JSON.parse(response?.output);
       performAction(editorActions);
 
       const assistantMessage: MyMessage = {
@@ -252,7 +252,7 @@ export function ChatMain(props: ChatCompProps) {
         sessionId: state.currentThreadId,
       });
     
-      const {reply, actions: editorActions} = JSON.parse(response?.output);
+      const {explanation: reply, actions: editorActions} = JSON.parse(response?.output);
       performAction(editorActions);
 
       const assistantMessage: MyMessage = {
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
index 8591a9edbe..a7783a8a0e 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
@@ -14,6 +14,7 @@ import {
 } from "lowcoder-core";
 import { getEditorComponentInfo } from "../utils";
 import { getPromiseAfterDispatch } from "@lowcoder-ee/util/promiseUtils";
+import { hookCompCategory, HookCompType } from "@lowcoder-ee/comps/hooks/hookCompTypes";
 
 export const addComponentAction: ActionConfig = {
   key: 'add-components',
@@ -23,7 +24,7 @@ export const addComponentAction: ActionConfig = {
   requiresInput: false,
   execute: async (params: ActionExecuteParams) => {
     const { selectedComponent, editorState, actionPayload } = params;
-    const { name, layout, ...otherProps } = actionPayload;
+    const { component_name: name, layout, action_parameters } = actionPayload;
 
     if (!selectedComponent || !editorState) {
       message.error('Component and editor state are required');
@@ -31,6 +32,21 @@ export const addComponentAction: ActionConfig = {
     }
 
     try {
+      if (hookCompCategory(selectedComponent) === "ui") {
+        const compName = Boolean(name) ? name : editorState.getNameGenerator().genItemName(selectedComponent);
+        editorState
+          .getHooksComp()
+          .dispatch(
+            wrapActionExtraInfo(
+              editorState
+                .getHooksComp()
+                .pushAction({ name: compName, compType: selectedComponent as HookCompType }),
+              { compInfos: [{ compName: compName, compType: selectedComponent, type: "add" }] }
+            )
+          );
+        return;
+      }
+
       const uiComp = editorState.getUIComp();
       const container = uiComp.getComp();
       
@@ -63,7 +79,7 @@ export const addComponentAction: ActionConfig = {
       let compDefaultValue = defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined;
       const compInitialValue = {
         ...(compDefaultValue as any || {}),
-        ...otherProps,
+        ...action_parameters,
       }
       const widgetValue: GridItemDataType = {
         compType: selectedComponent,
@@ -139,7 +155,8 @@ export const nestComponentAction: ActionConfig = {
   execute: async (params: ActionExecuteParams) => {
     // const { selectedEditorComponent, selectedNestComponent, editorState, actionPayload } = params;
     const { editorState, actionPayload, selectedComponent: selectedNestComponent } = params;
-    const { name, layout, target: selectedEditorComponent, ...otherProps } = actionPayload;
+    const { component_name: name, layout, parent_component_name: selectedEditorComponent, action_parameters } = actionPayload;
+    // const { name, layout, target: selectedEditorComponent, ...otherProps } = actionPayload;
 
     if (!selectedEditorComponent || !selectedNestComponent || !editorState) {
       message.error('Parent component, child component, and editor state are required');
@@ -147,21 +164,21 @@ export const nestComponentAction: ActionConfig = {
     }
 
     const [editorComponent, ...childComponents] = selectedEditorComponent.split('.');
-    const parentComponentInfo = getEditorComponentInfo(editorState, editorComponent);
+    const parentItem = editorState.getUICompByName(editorComponent); //getEditorComponentInfo(editorState, editorComponent);
     
-    if (!parentComponentInfo) {
-      message.error(`Parent component "${selectedEditorComponent}" not found`);
-      return;
-    }
+    // if (!parentComponentInfo) {
+    //   message.error(`Parent component "${selectedEditorComponent}" not found`);
+    //   return;
+    // }
 
-    const { componentKey: parentKey, items } = parentComponentInfo;
+    // const { componentKey: parentKey, items } = parentComponentInfo;
     
-    if (!parentKey) {
-      message.error(`Parent component "${selectedEditorComponent}" not found in layout`);
-      return;
-    }
+    // if (!parentKey) {
+    //   message.error(`Parent component "${selectedEditorComponent}" not found in layout`);
+    //   return;
+    // }
 
-    const parentItem = items[parentKey];
+    // const parentItem = items[parentKey];
     if (!parentItem) {
       message.error(`Parent component "${selectedEditorComponent}" not found in items`);
       return;
@@ -204,7 +221,7 @@ export const nestComponentAction: ActionConfig = {
       let compDefaultValue = defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined;
       const compInitialValue = {
         ...(compDefaultValue as any || {}),
-        ...otherProps,
+        ...action_parameters,
       }
 
       const widgetValue: GridItemDataType = {
diff --git a/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx b/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
index a3c8aeca82..d074696f19 100644
--- a/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
+++ b/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
@@ -125,7 +125,7 @@ function Bottom(props: any) {
                 // systemPrompt="You are a helpful assistant."
                 // agent={true}
                 // maxInteractions={10}
-                modelHost="http://192.168.100.49:5678/webhook/9a363e76-d3a5-46d1-98c3-4359f7106d33"
+                modelHost="http://192.168.100.59:5678/webhook/9a363e76-d3a5-46d1-98c3-4359f7106d33"
               />
             </Flex>
           )}

From d3142c1c35500f5974e994763f415c34ffd474e4 Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Tue, 8 Jul 2025 12:54:58 +0500
Subject: [PATCH 28/54] Adds dynamic layer indexing

---
 .../comps/comps/preLoadComp/actionConfigs.ts  |  5 +-
 .../comps/preLoadComp/actionInputSection.tsx  | 77 ++++++++++++++-
 .../preLoadComp/actions/componentLayout.ts    | 99 +++++++++++++++++++
 .../comps/comps/preLoadComp/actions/index.ts  |  2 +-
 .../src/comps/comps/preLoadComp/types.ts      |  2 +
 .../src/comps/comps/preLoadComp/utils.ts      | 25 ++++-
 6 files changed, 201 insertions(+), 9 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
index 02f0bbe736..2d4d130b67 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
@@ -9,7 +9,8 @@ import {
   changeLayoutAction,
   addEventHandlerAction,
   applyStyleAction,
-  nestComponentAction
+  nestComponentAction,
+  updateDynamicLayoutAction
 } from "./actions";
 
 export const actionCategories: ActionCategory[] = [
@@ -33,7 +34,7 @@ export const actionCategories: ActionCategory[] = [
   {
     key: 'layout',
     label: 'Layout',
-    actions: [changeLayoutAction]
+    actions: [changeLayoutAction, updateDynamicLayoutAction]
   },
   {
     key: 'events',
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
index a78ab6fb31..5fd4fe3136 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
@@ -12,11 +12,11 @@ import { default as Space } from "antd/es/space";
 import { default as Flex } from "antd/es/flex";
 import type { InputRef } from 'antd';
 import { default as DownOutlined } from "@ant-design/icons/DownOutlined";
-import { BaseSection } from "lowcoder-design";
+import { BaseSection, Dropdown } from "lowcoder-design";
 import { EditorContext } from "comps/editorState";
 import { message } from "antd";
 import { CustomDropdown } from "./styled";
-import { generateComponentActionItems, getComponentCategories } from "./utils";
+import { generateComponentActionItems, getComponentCategories, getEditorComponentInfo, getLayoutItemsOrder } from "./utils";
 import { actionRegistry, getAllActionItems } from "./actionConfigs";
 
 export function ActionInputSection() {
@@ -31,6 +31,8 @@ export function ActionInputSection() {
   const [showStylingInput, setShowStylingInput] = useState<boolean>(false);
   const [selectedEditorComponent, setSelectedEditorComponent] = useState<string | null>(null);
   const [validationError, setValidationError] = useState<string | null>(null);
+  const [showDynamicLayoutDropdown, setShowDynamicLayoutDropdown] = useState<boolean>(false);
+  const [selectedDynamicLayoutIndex, setSelectedDynamicLayoutIndex] = useState<string | null>(null);
   const inputRef = useRef<InputRef>(null);
   const editorState = useContext(EditorContext);
 
@@ -56,6 +58,25 @@ export function ActionInputSection() {
     }));
   }, [editorState]);
 
+  const simpleLayoutItems = useMemo(() => {
+    if(!editorComponents) return [];
+
+    const editorComponentInfo = getEditorComponentInfo(editorState);
+    if(!editorComponentInfo) return [];
+  
+    const currentLayout = editorComponentInfo.currentLayout;
+    const items = editorComponentInfo.items;
+    
+    return Object.keys(currentLayout).map((key) => {
+      const item = items ? items[key] : null;
+      const componentName = item ? (item as any).children.name.getView() : key;
+      return {
+        label: componentName,
+        key: componentName
+      };
+    });
+  }, [editorState]);
+
   const currentAction = useMemo(() => {
     return selectedActionKey ? actionRegistry.get(selectedActionKey) : null;
   }, [selectedActionKey]);
@@ -81,7 +102,9 @@ export function ActionInputSection() {
     setSelectedEditorComponent(null);
     setIsNestedComponent(false);
     setSelectedNestComponent(null);
+    setShowDynamicLayoutDropdown(false);
     setActionValue("");
+    setSelectedDynamicLayoutIndex(null);
 
     if (action.requiresComponentSelection) {
       setShowComponentDropdown(true);
@@ -103,6 +126,9 @@ export function ActionInputSection() {
     if (action.isNested) {
       setIsNestedComponent(true);
     }
+    if(action.dynamicLayout) {
+      setShowDynamicLayoutDropdown(true);
+    }
   }, []);
 
   const handleComponentSelection = useCallback((key: string) => {
@@ -175,6 +201,7 @@ export function ActionInputSection() {
         selectedComponent,
         selectedEditorComponent,
         selectedNestComponent,
+        selectedDynamicLayoutIndex,
         editorState
       });
 
@@ -189,6 +216,8 @@ export function ActionInputSection() {
       setValidationError(null);
       setIsNestedComponent(false);
       setSelectedNestComponent(null);
+      setShowDynamicLayoutDropdown(false);
+      setSelectedDynamicLayoutIndex(null);
 
     } catch (error) {
       console.error('Error executing action:', error);
@@ -200,6 +229,7 @@ export function ActionInputSection() {
     selectedComponent, 
     selectedEditorComponent, 
     selectedNestComponent,
+    selectedDynamicLayoutIndex,
     editorState, 
     currentAction, 
     validateInput
@@ -299,7 +329,7 @@ export function ActionInputSection() {
               popupRender={() => (
                 <Menu
                   items={editorComponents}
-                  onClick={({ key }) => {
+                  onClick={({key}) => {
                     handleEditorComponentSelection(key);
                   }}
                 />
@@ -314,6 +344,47 @@ export function ActionInputSection() {
             </CustomDropdown>
           )}
 
+          {showDynamicLayoutDropdown && (
+            <CustomDropdown
+              overlayStyle={{ 
+              maxHeight: '400px',
+              overflow: 'auto',
+              zIndex: 9999
+            }}
+            popupRender={() => (
+              <Menu
+                items={simpleLayoutItems}
+                onClick={({key}) => {
+                  handleEditorComponentSelection(key);
+                }}
+              />
+            )}
+          >
+            <Button size={"small"}>
+              <Space>
+                {selectedEditorComponent ? selectedEditorComponent : 'Layout'} 
+                <DownOutlined />
+              </Space>
+            </Button>
+          </CustomDropdown>
+          )}
+
+          {showDynamicLayoutDropdown && (
+            <Dropdown
+              options={getLayoutItemsOrder(simpleLayoutItems)}
+              onChange={(value) => {
+                setSelectedDynamicLayoutIndex(value);
+              }}
+            >
+              <Button size={"small"}>
+                <Space>
+                  {selectedEditorComponent ? selectedEditorComponent : 'Layout'} 
+                  <DownOutlined />
+                </Space>
+              </Button>
+            </Dropdown>
+          )}
+
           {shouldShowInput && (
             showStylingInput ? (
               <Input.TextArea
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentLayout.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentLayout.ts
index e4afa15cab..b0f995be93 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentLayout.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentLayout.ts
@@ -1,5 +1,7 @@
 import { message } from "antd";
 import { ActionConfig, ActionExecuteParams } from "../types";
+import { getEditorComponentInfo } from "../utils";
+import { changeValueAction, multiChangeAction, wrapActionExtraInfo } from "lowcoder-core";
 
 export const changeLayoutAction: ActionConfig = {
   key: 'change-layout',
@@ -16,4 +18,101 @@ export const changeLayoutAction: ActionConfig = {
     
     // TODO: Implement actual layout change logic
   }
+}; 
+
+export const updateDynamicLayoutAction: ActionConfig = {
+  key: 'update-dynamic-layout',
+  label: 'Update Dynamic Layout',
+  category: 'layout',
+  requiresInput: false,
+  dynamicLayout: true,
+  execute: async (params: ActionExecuteParams) => {
+    const { selectedDynamicLayoutIndex, selectedEditorComponent, editorState } = params;
+
+    if (!selectedEditorComponent || !editorState || !selectedDynamicLayoutIndex) {
+      message.error('Component, editor state, and layout index are required');
+      return;
+    }
+
+    try {
+      const componentInfo = getEditorComponentInfo(editorState, selectedEditorComponent);
+
+      if (!componentInfo) {
+        message.error(`Component "${selectedEditorComponent}" not found`);
+        return;
+      }
+
+      const { componentKey, currentLayout, simpleContainer, items } = componentInfo;
+
+      if (!componentKey || !currentLayout[componentKey]) {
+        message.error(`Component "${selectedEditorComponent}" not found in layout`);
+        return;
+      }
+
+      const currentLayoutItem = currentLayout[componentKey];
+      const newPos = parseInt(selectedDynamicLayoutIndex);
+
+      if (isNaN(newPos)) {
+        message.error('Invalid layout index provided');
+        return;
+      }
+
+      const currentPos = currentLayoutItem.pos || 0;
+      const layoutItems = Object.entries(currentLayout).map(([key, item]) => ({
+        key,
+        item: item as any,
+        pos: (item as any).pos || 0
+      })).sort((a, b) => a.pos - b.pos);
+
+      const otherItems = layoutItems.filter(item => item.key !== componentKey);
+      const newLayout: any = {};
+      
+      newLayout[componentKey] = {
+        ...currentLayoutItem,
+        pos: newPos
+      };
+      
+      // Update other components with shifted positions
+      otherItems.forEach((item) => {
+        let adjustedPos = item.pos;
+        
+        // If moving to a position before the current position, shift items in between
+        if (newPos < currentPos && item.pos >= newPos && item.pos < currentPos) {
+          adjustedPos = item.pos + 1;
+        }
+        // If moving to a position after the current position, shift items in between
+        else if (newPos > currentPos && item.pos > currentPos && item.pos <= newPos) {
+          adjustedPos = item.pos - 1;
+        }
+        
+        newLayout[item.key] = {
+          ...item.item,
+          pos: adjustedPos
+        };
+      });
+
+      simpleContainer.dispatch(
+        wrapActionExtraInfo(
+          multiChangeAction({
+            layout: changeValueAction(newLayout, true),
+          }),
+          { 
+            compInfos: [{ 
+              compName: selectedEditorComponent, 
+              compType: (items[componentKey] as any).children.compType.getView(), 
+              type: "layout" 
+            }] 
+          }
+        )
+      );
+
+      editorState.setSelectedCompNames(new Set([selectedEditorComponent]), "layoutComp");
+
+      message.success(`Component "${selectedEditorComponent}" moved to position ${newPos}`);
+      
+    } catch (error) {
+      console.error('Error updating dynamic layout:', error);
+      message.error('Failed to update dynamic layout. Please try again.');
+    }
+  }
 }; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts
index 8400000505..cee6289186 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts
@@ -5,7 +5,7 @@ export * from './componentManagement';
 export { configureComponentAction } from './componentConfiguration';
 
 // Layout Actions
-export { changeLayoutAction } from './componentLayout';
+export { changeLayoutAction, updateDynamicLayoutAction } from './componentLayout';
 
 // Event Actions
 export { addEventHandlerAction } from './componentEvents';
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
index b6318f9652..51e34e9dff 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
@@ -35,6 +35,7 @@ export interface ActionConfig {
   requiresInput?: boolean;
   requiresStyle?: boolean;
   isNested?: boolean;
+  dynamicLayout?: boolean;
   inputPlaceholder?: string;
   inputType?: 'text' | 'number' | 'textarea' | 'json';
   validation?: (value: string) => string | null; 
@@ -48,6 +49,7 @@ export interface ActionExecuteParams {
   selectedComponent: string | null;
   selectedEditorComponent: string | null;
   selectedNestComponent: string | null;
+  selectedDynamicLayoutIndex: string | null;
   editorState: any;
 }
 
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
index b30f02fb2b..5d97722110 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
@@ -54,7 +54,7 @@ export function getComponentCategories() {
   });
   return cats;
 } 
-export function getEditorComponentInfo(editorState: EditorState, componentName: string): {
+export function getEditorComponentInfo(editorState: EditorState, componentName?: string): {
   componentKey: string | null;
   currentLayout: any;
   simpleContainer: any;
@@ -63,7 +63,7 @@ export function getEditorComponentInfo(editorState: EditorState, componentName:
 } | null {
   try {
     // Get the UI component container
-    if (!editorState || !componentName) {
+    if (!editorState) {
       return null;
     }
 
@@ -85,6 +85,16 @@ export function getEditorComponentInfo(editorState: EditorState, componentName:
     const currentLayout = simpleContainer.children.layout.getView();
     const items = getCombinedItems(uiCompTree);
 
+    // If no componentName is provided, return all items
+    if (!componentName) {
+      return {
+        componentKey: null,
+        currentLayout,
+        simpleContainer,
+        items,
+      };
+    }
+
     // Find the component by name and get its key
     let componentKey: string | null = null;
     let componentType: string | null = null;
@@ -93,7 +103,7 @@ export function getEditorComponentInfo(editorState: EditorState, componentName:
       if ((item as any).children.name.getView() === componentName) {
         componentKey = key;
         componentType = (item as any).children.compType.getView();
-        break
+        break;
       }
     }
 
@@ -137,3 +147,12 @@ function getCombinedItems(uiCompTree: any) {
 
   return combined;
 }
+
+export function getLayoutItemsOrder(layoutItems: any[]){
+  const maxIndex = layoutItems.length;
+  return Array.from({ length: maxIndex }, (_, index) => ({
+    key: index,
+    label: `Position ${index}`,
+    value: index.toString()
+  }));
+}

From 86a12f01fc20bc0bffb1a7bd15e93069a4a70dfc Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Tue, 8 Jul 2025 18:17:59 +0500
Subject: [PATCH 29/54] fixed: Layout components issue, children components
 depth issues

---
 .../actions/componentManagement.ts            |  66 ++++++----
 .../src/comps/comps/preLoadComp/utils.ts      | 117 +++++++++++++++---
 2 files changed, 138 insertions(+), 45 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
index a7783a8a0e..647d48df11 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
@@ -12,7 +12,7 @@ import {
     wrapChildAction, 
     deleteCompAction 
 } from "lowcoder-core";
-import { getEditorComponentInfo } from "../utils";
+import { getEditorComponentInfo, findTargetComponent } from "../utils";
 import { getPromiseAfterDispatch } from "@lowcoder-ee/util/promiseUtils";
 import { hookCompCategory, HookCompType } from "@lowcoder-ee/comps/hooks/hookCompTypes";
 
@@ -314,17 +314,22 @@ export const deleteComponentAction: ActionConfig = {
         return;
       }
 
-      const { componentKey, currentLayout, simpleContainer, componentType } = componentInfo;
-
-      if (!componentKey || !currentLayout[componentKey]) {
-        message.error(`Component "${selectedEditorComponent}" not found in layout`);
+      const { allAppComponents } = componentInfo;
+      const targetComponent = allAppComponents.find(comp => comp.name === selectedEditorComponent);
+      
+      if (!targetComponent) {
+        message.error(`Component "${selectedEditorComponent}" not found in application`);
         return;
       }
 
-      const newLayout = { ...currentLayout };
-      delete newLayout[componentKey];
+      const targetInfo = findTargetComponent(editorState, selectedEditorComponent);
 
-      simpleContainer.dispatch(
+      if (targetInfo) {
+        const { container, layout, componentKey } = targetInfo;
+        const newLayout = { ...layout };
+        delete newLayout[componentKey];
+
+        container.dispatch(
         wrapActionExtraInfo(
           multiChangeAction({
             layout: changeValueAction(newLayout, true),
@@ -333,7 +338,7 @@ export const deleteComponentAction: ActionConfig = {
           { 
             compInfos: [{ 
               compName: selectedEditorComponent, 
-              compType: componentType || 'unknown', 
+              compType: targetComponent.compType || 'unknown', 
               type: "delete" 
             }] 
           }
@@ -343,6 +348,9 @@ export const deleteComponentAction: ActionConfig = {
       editorState.setSelectedCompNames(new Set(), "deleteComp");
       
       message.success(`Component "${selectedEditorComponent}" deleted successfully`);
+      } else {
+        message.error(`Component "${selectedEditorComponent}" not found in any container`);
+      }
     } catch (error) {
       console.error('Error deleting component:', error);
       message.error('Failed to delete component. Please try again.');
@@ -401,6 +409,15 @@ export const moveComponentAction: ActionConfig = {
         return;
       }
 
+      const targetInfo = findTargetComponent(editorState, selectedEditorComponent);
+
+      if (!targetInfo) {
+        message.error(`Component "${selectedEditorComponent}" not found in any container`);
+        return;
+      }
+
+      const { container, layout, componentKey } = targetInfo;
+
       const componentInfo = getEditorComponentInfo(editorState, selectedEditorComponent);
       
       if (!componentInfo) {
@@ -408,15 +425,13 @@ export const moveComponentAction: ActionConfig = {
         return;
       }
 
-      const { componentKey, currentLayout, simpleContainer } = componentInfo;
-
-      if (!componentKey || !currentLayout[componentKey]) {
+      if (!componentKey || !layout[componentKey]) {
         message.error(`Component "${selectedEditorComponent}" not found in layout`);
         return;
       }
 
-      const currentLayoutItem = currentLayout[componentKey];
-      const items = simpleContainer.children.items.children;
+      const currentLayoutItem = layout[componentKey];
+      const items = container.children.items.children;
 
       const newLayoutItem = {
         ...currentLayoutItem,
@@ -425,11 +440,11 @@ export const moveComponentAction: ActionConfig = {
       };
 
       const newLayout = {
-        ...currentLayout,
+        ...layout,
         [componentKey]: newLayoutItem,
       };
 
-      simpleContainer.dispatch(
+      container.dispatch(
         wrapActionExtraInfo(
           multiChangeAction({
             layout: changeValueAction(newLayout, true),
@@ -568,21 +583,22 @@ export const resizeComponentAction: ActionConfig = {
         return;
       }
 
-      const componentInfo = getEditorComponentInfo(editorState, selectedEditorComponent);
-      
-      if (!componentInfo) {
-        message.error(`Component "${selectedEditorComponent}" not found`);
+      const targetInfo = findTargetComponent(editorState, selectedEditorComponent);
+
+      if (!targetInfo) {
+        message.error(`Component "${selectedEditorComponent}" not found in any container`);
         return;
       }
 
-      const { componentKey, currentLayout, simpleContainer, items } = componentInfo;
+      const { container, layout, componentKey } = targetInfo;
 
-      if (!componentKey || !currentLayout[componentKey]) {
+      if (!componentKey || !layout[componentKey]) {
         message.error(`Component "${selectedEditorComponent}" not found in layout`);
         return;
       }
 
-      const currentLayoutItem = currentLayout[componentKey];
+      const currentLayoutItem = layout[componentKey];
+      const items = container.children.items.children;
       
       const newLayoutItem = {
         ...currentLayoutItem,
@@ -591,11 +607,11 @@ export const resizeComponentAction: ActionConfig = {
       };
 
       const newLayout = {
-        ...currentLayout,
+        ...layout,
         [componentKey]: newLayoutItem,
       };
 
-      simpleContainer.dispatch(
+      container.dispatch(
         wrapActionExtraInfo(
           multiChangeAction({
             layout: changeValueAction(newLayout, true),
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
index 5d97722110..72919356cd 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/utils.ts
@@ -5,6 +5,7 @@ import { UICompCategory, UICompManifest, uiCompCategoryNames, uiCompRegistry } f
 import { MenuProps } from "antd/es/menu";
 import React from "react";
 import { EditorState } from "@lowcoder-ee/comps/editorState";
+import { getAllCompItems } from "comps/comps/containerBase/utils";
 
 export function runScript(code: string, inHost?: boolean) {
   if (inHost) {
@@ -60,6 +61,7 @@ export function getEditorComponentInfo(editorState: EditorState, componentName?:
   simpleContainer: any;
   componentType?: string | null;
   items: any;
+  allAppComponents: any[];
 } | null {
   try {
     // Get the UI component container
@@ -83,7 +85,9 @@ export function getEditorComponentInfo(editorState: EditorState, componentName?:
 
     // Get current layout and items
     const currentLayout = simpleContainer.children.layout.getView();
+    
     const items = getCombinedItems(uiCompTree);
+    const allAppComponents = getAllLayoutComponentsFromTree(uiCompTree);
 
     // If no componentName is provided, return all items
     if (!componentName) {
@@ -92,6 +96,7 @@ export function getEditorComponentInfo(editorState: EditorState, componentName?:
         currentLayout,
         simpleContainer,
         items,
+        allAppComponents,
       };
     }
 
@@ -113,6 +118,7 @@ export function getEditorComponentInfo(editorState: EditorState, componentName?:
       simpleContainer,
       componentType,
       items,
+      allAppComponents,
     };  
   } catch(error) {
     console.error('Error getting editor component key:', error);
@@ -120,31 +126,27 @@ export function getEditorComponentInfo(editorState: EditorState, componentName?:
   }
 }
 
-interface Container {
-  items?: Record<string, any>; 
-}
-
-function getCombinedItems(uiCompTree: any) {
+function getCombinedItems(uiCompTree: any, parentPath: string[] = []): Record<string, any> {
   const combined: Record<string, any> = {};
 
-  if (uiCompTree.items) {
-    Object.entries(uiCompTree.items).forEach(([itemKey, itemValue]) => {
-      combined[itemKey] = itemValue;
-    });
-  }
+  function processContainer(container: any, currentPath: string[]) {
+    if (container.items) {
+      Object.entries(container.items).forEach(([itemKey, itemValue]) => {
+        (itemValue as any).parentPath = [...currentPath];
+        combined[itemKey] = itemValue;
+      });
+    }
 
-  if (uiCompTree.children) {
-    Object.entries(uiCompTree.children).forEach(([parentKey, container]) => {
-      const typedContainer = container as Container; 
-      if (typedContainer.items) {
-        Object.entries(typedContainer.items).forEach(([itemKey, itemValue]) => {
-          itemValue.parentContainer = parentKey;
-          combined[itemKey] = itemValue;
-        });
-      }
-    });
+    if (container.children) {
+      Object.entries(container.children).forEach(([childKey, childContainer]) => {
+        const newPath = [...currentPath, childKey];
+        processContainer(childContainer, newPath);
+      });
+    }
   }
 
+  processContainer(uiCompTree, parentPath);
+
   return combined;
 }
 
@@ -156,3 +158,78 @@ export function getLayoutItemsOrder(layoutItems: any[]){
     value: index.toString()
   }));
 }
+
+function getAllLayoutComponentsFromTree(compTree: any): any[] {
+  try {
+    const allCompItems = getAllCompItems(compTree);
+    
+    return Object.entries(allCompItems).map(([itemKey, item]) => {
+      const compItem = item as any;
+      if (compItem && compItem.children) {
+        return {
+          id: itemKey,
+          compType: compItem.children.compType?.getView(),
+          name: compItem.children.name?.getView(),
+          key: itemKey,
+          comp: compItem.children.comp,
+          autoHeight: compItem.autoHeight?.(),
+          hidden: compItem.children.comp?.children?.hidden?.getView(),
+          parentPath: compItem.parentPath || []
+        };
+      }
+    });
+  } catch (error) {
+    console.error('Error getting all app components from tree:', error);
+    return [];
+  }
+}
+
+export function getAllContainers(editorState: any) {
+  const containers: Array<{container: any, path: string[]}> = [];
+  
+  function findContainers(comp: any, path: string[] = []) {
+    if (!comp) return;
+    
+    if (comp.realSimpleContainer && typeof comp.realSimpleContainer === 'function') {
+      const simpleContainer = comp.realSimpleContainer();
+      if (simpleContainer) {
+        containers.push({ container: simpleContainer, path });
+      }
+    }
+    
+    if (comp.children) {
+      Object.entries(comp.children).forEach(([key, child]) => {
+        findContainers(child, [...path, key]);
+      });
+    }
+  }
+  
+  const uiComp = editorState.getUIComp();
+  const container = uiComp.getComp();
+  if (container) {
+    findContainers(container);
+  }
+  
+  return containers;
+}
+
+export function findTargetComponent(editorState: any, selectedEditorComponent: string) {
+  const allContainers = getAllContainers(editorState);
+
+  for (const containerInfo of allContainers) {
+    const containerLayout = containerInfo.container.children.layout.getView();
+    const containerItems = containerInfo.container.children.items.children;
+
+    for (const [key, item] of Object.entries(containerItems)) {
+      if ((item as any).children.name.getView() === selectedEditorComponent) {
+        return {
+          container: containerInfo.container,
+          layout: containerLayout,
+          componentKey: key
+        };
+      }
+    }
+  }
+
+  return null;
+}
\ No newline at end of file

From 79b5e83bbdda8d0e2bf11d1fe97f433678c4c0bc Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Wed, 9 Jul 2025 16:05:17 +0500
Subject: [PATCH 30/54] Event handlers for all components.

---
 .../comps/comps/preLoadComp/actionConfigs.ts  |   2 +-
 .../preLoadComp/actions/componentEvents.ts    | 176 +++++++++++++++++-
 2 files changed, 170 insertions(+), 8 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
index 2d4d130b67..e2b037bdeb 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
@@ -34,7 +34,7 @@ export const actionCategories: ActionCategory[] = [
   {
     key: 'layout',
     label: 'Layout',
-    actions: [changeLayoutAction, updateDynamicLayoutAction]
+    actions: [updateDynamicLayoutAction]
   },
   {
     key: 'events',
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentEvents.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentEvents.ts
index cf007c5afa..1d73c20b04 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentEvents.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentEvents.ts
@@ -1,5 +1,29 @@
+/**
+ * Event Names:
+ * - click: Triggered when component is clicked
+ * - change: Triggered when component value changes
+ * - focus: Triggered when component gains focus
+ * - blur: Triggered when component loses focus
+ * - submit: Triggered when form is submitted
+ * - refresh: Triggered when component is refreshed
+ * 
+ * Action Types:
+ * - executeQuery: Run a data query
+ * - message: Show a notification message
+ * - setTempState: Set a temporary state value
+ * - runScript: Execute JavaScript code
+ * - executeComp: Control another component
+ * - goToURL: Navigate to a URL
+ * - copyToClipboard: Copy data to clipboard
+ * - download: Download data as file
+ * - triggerModuleEvent: Trigger a module event
+ * - openAppPage: Navigate to another app page
+ */
+
 import { message } from "antd";
 import { ActionConfig, ActionExecuteParams } from "../types";
+import { getEditorComponentInfo } from "../utils";
+import { pushAction } from "comps/generators/list";
 
 export const addEventHandlerAction: ActionConfig = {
   key: 'add-event-handler',
@@ -7,14 +31,152 @@ export const addEventHandlerAction: ActionConfig = {
   category: 'events',
   requiresEditorComponentSelection: true,
   requiresInput: true,
-  inputPlaceholder: 'Enter event handler code (JavaScript)',
-  inputType: 'textarea',
+  inputPlaceholder: 'Format: eventName: actionType (e.g., "click: message", "change: executeQuery", "focus: setTempState")',
+  inputType: 'text',
+  validation: (value: string) => {
+    const [eventName, actionType] = value.split(':').map(s => s.trim());
+    if (!eventName || !actionType) {
+      return 'Please provide both event name and action type separated by colon (e.g., "click: message")';
+    }
+    
+    const validActionTypes = [
+      'executeQuery', 'message', 'setTempState', 'runScript', 
+      'executeComp', 'goToURL', 'copyToClipboard', 'download', 
+      'triggerModuleEvent', 'openAppPage'
+    ];
+    
+    if (!validActionTypes.includes(actionType)) {
+      return `Invalid action type. Valid types: ${validActionTypes.join(', ')}`;
+    }
+    
+    return null;
+  },
   execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, actionValue } = params;
+    const { selectedEditorComponent, actionValue, editorState } = params;
+
+    const componentInfo = getEditorComponentInfo(editorState, selectedEditorComponent as string);
+      
+    if (!componentInfo) {
+      message.error(`Component "${selectedEditorComponent}" not found`);
+      return;
+    }
+
+    const { allAppComponents } = componentInfo;
+    const targetComponent = allAppComponents.find(comp => comp.name === selectedEditorComponent);
+
+    if (!targetComponent?.comp?.children?.onEvent) {
+      message.error(`Component "${selectedEditorComponent}" does not support event handlers`);
+      return;
+    }
+
+    // ----- To be Removed after n8n integration ------ //
+    const [eventName, actionType] = actionValue.split(':').map(s => s.trim());
+    
+    if (!eventName || !actionType) {
+      message.error('Please provide event name and action type in format: "eventName: actionType"');
+      return;
+    }
+    const eventConfigs = targetComponent.comp.children.onEvent.getEventNames?.() || [];
+    const availableEvents = eventConfigs.map((config: any) => config.value);
+    
+    if (!availableEvents.includes(eventName)) {
+      const availableEventsList = availableEvents.length > 0 ? availableEvents.join(', ') : 'none';
+      message.error(`Event "${eventName}" is not available for this component. Available events: ${availableEventsList}`);
+      return;
+    }
+    // ----- To be Removed after n8n integration ------ //
+
+    
+    const eventHandler = {
+      name: eventName,
+      handler: {
+        compType: actionType,
+        comp: getActionConfig(actionType, editorState)
+      }
+    };
+
+    try {
+      targetComponent.comp.children.onEvent.dispatch(pushAction(eventHandler));
+      message.success(`Event handler for "${eventName}" with action "${actionType}" added successfully!`);
+    } catch (error) {
+      console.error('Error adding event handler:', error);
+      message.error('Failed to add event handler. Please try again.');
+    }
+  }
+};
+
+// A Hardcoded function to get action configuration based on action type
+// This will be removed after n8n integration
+function getActionConfig(actionType: string, editorState: any) {
+  switch (actionType) {
+    case 'executeQuery':
+      const queryVariables = editorState
+        ?.selectedOrFirstQueryComp()
+        ?.children.variables.toJsonValue();
+      
+      return {
+        queryName: editorState
+          ?.selectedOrFirstQueryComp()
+          ?.children.name.getView(),
+        queryVariables: queryVariables?.map((variable: any) => ({...variable, value: ''})),
+      };
+    
+    case 'message':
+      return {
+        text: "Event triggered!",
+        level: "info",
+        duration: 3000
+      };
+    
+    case 'setTempState':
+      return {
+        state: "tempState",
+        value: "{{eventData}}"
+      };
+    
+    case 'runScript':
+      return {
+        script: "console.log('Event triggered:', eventData);"
+      };
+    
+    case 'executeComp':
+      return {
+        compName: "",
+        methodName: "",
+        params: []
+      };
+    
+    case 'goToURL':
+      return {
+        url: "https://example.com",
+        openInNewTab: false
+      };
+    
+    case 'copyToClipboard':
+      return {
+        value: "{{eventData}}"
+      };
+    
+    case 'download':
+      return {
+        data: "{{eventData}}",
+        fileName: "download.txt",
+        fileType: "text/plain"
+      };
+    
+    case 'triggerModuleEvent':
+      return {
+        name: "moduleEvent"
+      };
     
-    console.log('Adding event handler to component:', selectedEditorComponent, 'with code:', actionValue);
-    message.info(`Event handler added to component "${selectedEditorComponent}"`);
+    case 'openAppPage':
+      return {
+        appId: "",
+        queryParams: [],
+        hashParams: []
+      };
     
-    // TODO: Implement actual event handler logic
+    default:
+      return {};
   }
-}; 
\ No newline at end of file
+} 
\ No newline at end of file

From d13b799692c92edfd07add0e635d0dbad3ef1ca7 Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Thu, 10 Jul 2025 14:21:02 +0500
Subject: [PATCH 31/54] Update App meta data

---
 .../comps/comps/preLoadComp/actionConfigs.ts  |  9 ++--
 .../comps/preLoadComp/actionInputSection.tsx  |  7 ++-
 .../preLoadComp/actions/appConfiguration.ts   | 46 +++++++++++++++++++
 .../actions/componentConfiguration.ts         |  2 +-
 .../comps/comps/preLoadComp/actions/index.ts  |  2 +-
 5 files changed, 58 insertions(+), 8 deletions(-)
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
index e2b037bdeb..bd5fc12e3c 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
@@ -5,8 +5,7 @@ import {
   renameComponentAction,
   deleteComponentAction,
   resizeComponentAction,
-  configureComponentAction,
-  changeLayoutAction,
+  configureAppMetaAction,
   addEventHandlerAction,
   applyStyleAction,
   nestComponentAction,
@@ -27,9 +26,9 @@ export const actionCategories: ActionCategory[] = [
     ]
   },
   {
-    key: 'component-configuration',
-    label: 'Component Configuration',
-    actions: [configureComponentAction]
+    key: 'app-configuration',
+    label: 'App Configuration',
+    actions: [configureAppMetaAction]
   },
   {
     key: 'layout',
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
index 5fd4fe3136..0b243219ef 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
@@ -16,7 +16,12 @@ import { BaseSection, Dropdown } from "lowcoder-design";
 import { EditorContext } from "comps/editorState";
 import { message } from "antd";
 import { CustomDropdown } from "./styled";
-import { generateComponentActionItems, getComponentCategories, getEditorComponentInfo, getLayoutItemsOrder } from "./utils";
+import { 
+  generateComponentActionItems, 
+  getComponentCategories, 
+  getEditorComponentInfo, 
+  getLayoutItemsOrder 
+} from "./utils";
 import { actionRegistry, getAllActionItems } from "./actionConfigs";
 
 export function ActionInputSection() {
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
new file mode 100644
index 0000000000..10d4d518cd
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
@@ -0,0 +1,46 @@
+import { message } from "antd";
+import { ActionConfig, ActionExecuteParams } from "../types";
+
+export const configureAppMetaAction: ActionConfig = {
+  key: 'configure-app-meta',
+  label: 'Configure app meta data',
+  category: 'app-configuration',
+  requiresInput: false,
+  execute: async (params: ActionExecuteParams) => {
+    const { editorState } = params;
+    const appSettingsComp = editorState.getAppSettingsComp();
+    
+    try {
+      // TODO: Get config data from the user
+      let configData = {
+        title: "Test Title",
+        description: "Test Description",
+        category: "Test Category"
+      };
+
+      if (configData.title && appSettingsComp?.children?.title) {
+        appSettingsComp.children.title.dispatchChangeValueAction(configData.title);
+      }
+
+      if (configData.description && appSettingsComp?.children?.description) {
+          appSettingsComp.children.description.dispatchChangeValueAction(configData.description);
+      }
+
+      if (configData.category && appSettingsComp?.children?.category) {
+        appSettingsComp.children.category.dispatchChangeValueAction(configData.category);
+      }
+
+      // Display error message if no valid configuration data is provided
+      const updatedFields = [];
+      if (configData.title) updatedFields.push('title');
+      if (configData.description) updatedFields.push('description');
+      if (configData.category) updatedFields.push('category');
+
+      !updatedFields.length && message.info('No valid configuration data provided');
+
+    } catch (error) {
+      console.error('Error updating app settings:', error);
+      message.error('Failed to update app configuration');
+    }
+  }
+}; 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts
index fefca21d05..e691b818dc 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts
@@ -62,4 +62,4 @@ export const configureComponentAction: ActionConfig = {
       message.error('Invalid configuration format');
     }
   }
-}; 
\ No newline at end of file
+};
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts
index cee6289186..c9c6efa43e 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts
@@ -2,7 +2,7 @@
 export * from './componentManagement';
 
 // Component Configuration Actions
-export { configureComponentAction } from './componentConfiguration';
+export * from './appConfiguration';
 
 // Layout Actions
 export { changeLayoutAction, updateDynamicLayoutAction } from './componentLayout';

From 8afeae1ee275487d1eabc1ca8d1f1e972897a574 Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Thu, 10 Jul 2025 20:47:47 +0500
Subject: [PATCH 32/54] Publish App, Test App, Apply Global JS and CSS

---
 .../comps/comps/preLoadComp/actionConfigs.ts  |  16 +-
 .../preLoadComp/actions/appConfiguration.ts   | 254 +++++++++++++++++-
 .../src/comps/comps/preLoadComp/tabPanes.tsx  |   7 +-
 3 files changed, 273 insertions(+), 4 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
index bd5fc12e3c..10da154799 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
@@ -9,7 +9,12 @@ import {
   addEventHandlerAction,
   applyStyleAction,
   nestComponentAction,
-  updateDynamicLayoutAction
+  updateDynamicLayoutAction,
+  publishAppAction,
+  shareAppAction,
+  testAllDatasourcesAction,
+  applyGlobalJSAction,
+  applyGlobalCSSAction
 } from "./actions";
 
 export const actionCategories: ActionCategory[] = [
@@ -28,7 +33,14 @@ export const actionCategories: ActionCategory[] = [
   {
     key: 'app-configuration',
     label: 'App Configuration',
-    actions: [configureAppMetaAction]
+    actions: [
+      configureAppMetaAction, 
+      publishAppAction,
+      shareAppAction,
+      testAllDatasourcesAction,
+      applyGlobalJSAction,
+      applyGlobalCSSAction
+    ]
   },
   {
     key: 'layout',
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
index 10d4d518cd..1d08751755 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
@@ -1,5 +1,11 @@
 import { message } from "antd";
 import { ActionConfig, ActionExecuteParams } from "../types";
+import ApplicationApi from "api/applicationApi";
+import { getApplicationIdInReducer } from "comps/utils/reduceContext";
+import { executeQueryAction } from "lowcoder-core";
+import { getPromiseAfterDispatch } from "util/promiseUtils";
+import { runScript } from "../utils";
+
 
 export const configureAppMetaAction: ActionConfig = {
   key: 'configure-app-meta',
@@ -43,4 +49,250 @@ export const configureAppMetaAction: ActionConfig = {
       message.error('Failed to update app configuration');
     }
   }
-}; 
\ No newline at end of file
+}; 
+
+export const publishAppAction: ActionConfig = {
+  key: 'publish-app',
+  label: 'Publish app',
+  category: 'app-configuration',
+  requiresInput: false,
+  execute: async () => {
+    try {
+      const applicationId = getApplicationIdInReducer();
+      
+      if (!applicationId) {
+        message.error('Application ID not found');
+        return;
+      }
+
+      const response = await ApplicationApi.publishApplication({ applicationId });
+      
+      if (response.data.success) {
+        message.success('Application published successfully');
+        window.open(`/applications/${applicationId}/view`, '_blank');
+      } else {
+        message.error('Failed to publish application');
+      }
+
+    } catch (error) {
+      console.error('Error publishing application:', error);
+      message.error('Failed to publish application');
+    }
+  }
+};
+
+export const shareAppAction: ActionConfig = {
+  key: 'share-app',
+  label: 'Share app',
+  category: 'app-configuration',
+  requiresInput: false,
+  execute: async () => {
+    // TODO: Implement share app
+    console.log('Share app');
+  }
+};
+
+export const testAllDatasourcesAction: ActionConfig = {
+  key: 'test-all-datasources',
+  label: 'Test all datasources',
+  category: 'app-configuration',
+  requiresInput: false,
+  execute: async (params: ActionExecuteParams) => {
+    const { editorState } = params;
+    
+    try {
+      const allQueries = editorState.getQueriesComp().getView();
+      
+      if (!allQueries || !allQueries.length) {
+        message.info('No queries found in the application');
+        return;
+      }
+
+      console.log(`Found ${allQueries.length} queries to test`);
+      
+      const results = {
+        total: allQueries.length,
+        successful: 0,
+        failed: 0,
+        errors: [] as Array<{ queryName: string; error: string }>
+      };
+
+      message.loading(`Testing ${allQueries.length} queries...`, 0);
+
+      for (let i = 0; i < allQueries.length; i++) {
+        const query = allQueries[i];
+        const queryName = query.children.name.getView();
+        
+        try {
+          await getPromiseAfterDispatch(
+            query.dispatch,
+            executeQueryAction({
+              // In some data queries, we need to pass args to the query
+              // Currently, we don't have a way to pass args to the query
+              // So we are passing an empty object
+              args: {},
+              afterExecFunc: () => {
+                console.log(`Query ${queryName} executed successfully`);
+              }
+            }),
+            { 
+              notHandledError: `Failed to execute query: ${queryName}`
+            }
+          );
+          
+          results.successful++;
+          
+        } catch (error) {
+          const errorMessage = error instanceof Error ? error.message : 'Unknown error';
+          console.error(`Query ${queryName} failed:`, error);
+          
+          results.failed++;
+          results.errors.push({
+            queryName,
+            error: errorMessage
+          });
+        }
+        
+        if (i < allQueries.length - 1) {
+          await new Promise(resolve => setTimeout(resolve, 500));
+        }
+      }
+
+      message.destroy();
+      
+      if (results.failed === 0) {
+        message.success(`All ${results.total} queries executed successfully!`);
+      } else if (results.successful === 0) {
+        message.error(`All ${results.total} queries failed. Check console for details.`);
+      } else {
+        message.warning(
+          `Query test completed: ${results.successful} successful, ${results.failed} failed`
+        );
+      }
+      
+      console.group('Query Test Results');
+      console.log(`Total queries: ${results.total}`);
+      console.log(`Successful: ${results.successful}`);
+      console.log(`Failed: ${results.failed}`);
+      
+      if (results.errors.length > 0) {
+        console.group('Failed Queries:');
+        results.errors.forEach(({ queryName, error }) => {
+          console.error(`${queryName}: ${error}`);
+        });
+        console.groupEnd();
+      }
+      console.groupEnd();
+
+    } catch (error) {
+      message.destroy();
+      console.error('Error during application testing:', error);
+      message.error('Failed to test application. Check console for details.');
+    }
+  }
+};
+
+export const applyGlobalJSAction: ActionConfig = {
+  key: 'apply-global-js',
+  label: 'Apply global JS',
+  category: 'app-configuration',
+  requiresInput: true,
+  inputPlaceholder: 'Enter JavaScript code to apply globally...',
+  inputType: 'textarea',
+  validation: (value: string) => {
+    if (!value.trim()) {
+      return 'JavaScript code is required';
+    }
+    try {
+      new Function(value);
+      return null;
+    } catch (error) {
+      return 'Invalid JavaScript syntax';
+    }
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { editorState, actionValue } = params;
+    
+    try {
+      const defaultJS = `console.log('Please provide a valid JavaScript code');`.trim();
+
+      const jsCode = actionValue.trim() || defaultJS;
+      
+      const preloadComp = editorState.rootComp.children.preload;
+      if (!preloadComp) {
+        message.error('Preload component not found');
+        return;
+      }
+
+      const scriptComp = preloadComp.children.script;
+      if (!scriptComp) {
+        message.error('Script component not found');
+        return;
+      }
+
+      scriptComp.dispatchChangeValueAction(jsCode);
+      runScript(jsCode, false);
+      
+      message.success('Global JavaScript applied successfully!');
+      
+    } catch (error) {
+      console.error('Error applying global JavaScript:', error);
+      message.error('Failed to apply global JavaScript. Check console for details.');
+    }
+  }
+};
+
+export const applyGlobalCSSAction: ActionConfig = {
+  key: 'apply-global-css',
+  label: 'Apply global CSS',
+  category: 'app-configuration',
+  requiresInput: true,
+  requiresStyle: true,
+  inputPlaceholder: 'Enter CSS code to apply globally...',
+  inputType: 'textarea',
+  validation: (value: string) => {
+    if (!value.trim()) {
+      return 'CSS code is required';
+    }
+    const css = value.trim();
+    if (!css.includes('{') || !css.includes('}')) {
+      return 'Invalid CSS syntax - missing braces';
+    }
+    return null;
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { editorState, actionValue } = params;
+    
+    try {
+      const defaultCSS = `
+        body {
+          font-family: Arial, sans-serif;
+        }
+      `.trim();
+
+      const cssCode = actionValue.trim() || defaultCSS;
+      
+      const preloadComp = editorState.rootComp.children.preload;
+      if (!preloadComp) {
+        message.error('Preload component not found');
+        return;
+      }
+
+      const globalCSSComp = preloadComp.children.globalCSS;
+      if (!globalCSSComp) {
+        message.error('Global CSS component not found');
+        return;
+      }
+
+      globalCSSComp.dispatchChangeValueAction(cssCode);
+      
+      await globalCSSComp.run('global-css', cssCode);
+      
+      message.success('Global CSS applied successfully!');
+      
+    } catch (error) {
+      console.error('Error applying global CSS:', error);
+      message.error('Failed to apply global CSS. Check console for details.');
+    }
+  }
+};
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/tabPanes.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/tabPanes.tsx
index a1229a96dc..ad5831bad7 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/tabPanes.tsx
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/tabPanes.tsx
@@ -3,10 +3,15 @@ import React, { useEffect } from "react";
 import { trans } from "i18n";
 import { ConstructorToComp } from "lowcoder-core";
 import { ScriptComp, CSSComp } from "./components";
+import { runScript } from "./utils";
 
 export function JavaScriptTabPane(props: { comp: ConstructorToComp<typeof ScriptComp> }) {
   useEffect(() => {
-    props.comp.runPreloadScript();
+    // Use the imported runScript function instead of the component's method to avoid require() issues
+    const code = props.comp.getView();
+    if (code) {
+      runScript(code, false);
+    }
   }, [props.comp]);
 
   const codePlaceholder = `window.name = 'Tom';\nwindow.greet = () => "hello world";`;

From 38e770c50fd67228a816a1f74ff2c15a83840b29 Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Fri, 11 Jul 2025 18:48:00 +0500
Subject: [PATCH 33/54] Sharing App Permissions

---
 .../preLoadComp/actions/appConfiguration.ts   | 59 ++++++++++++++++---
 1 file changed, 51 insertions(+), 8 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
index 1d08751755..5371184523 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
@@ -1,11 +1,11 @@
 import { message } from "antd";
 import { ActionConfig, ActionExecuteParams } from "../types";
 import ApplicationApi from "api/applicationApi";
-import { getApplicationIdInReducer } from "comps/utils/reduceContext";
 import { executeQueryAction } from "lowcoder-core";
 import { getPromiseAfterDispatch } from "util/promiseUtils";
 import { runScript } from "../utils";
-
+import { updateAppPermissionInfo } from "redux/reduxActions/applicationActions";
+import { reduxStore } from "redux/store/store";
 
 export const configureAppMetaAction: ActionConfig = {
   key: 'configure-app-meta',
@@ -56,10 +56,12 @@ export const publishAppAction: ActionConfig = {
   label: 'Publish app',
   category: 'app-configuration',
   requiresInput: false,
-  execute: async () => {
+  execute: async (params: ActionExecuteParams) => {
+    const { editorState } = params;
+    const applicationIdEditor = editorState.rootComp.preloadId;
+    const applicationId = applicationIdEditor.replace('app-', '');
+
     try {
-      const applicationId = getApplicationIdInReducer();
-      
       if (!applicationId) {
         message.error('Application ID not found');
         return;
@@ -86,9 +88,50 @@ export const shareAppAction: ActionConfig = {
   label: 'Share app',
   category: 'app-configuration',
   requiresInput: false,
-  execute: async () => {
-    // TODO: Implement share app
-    console.log('Share app');
+  execute: async (params: ActionExecuteParams) => {
+    // TODO: Get app sharing from the user
+    const appSharing = {
+      public: true,
+      publishMarketplace: false
+    }
+
+    const { editorState } = params;
+    const applicationIdEditor = editorState.rootComp.preloadId;
+    const applicationId = applicationIdEditor.replace('app-', '');
+
+    if (!applicationId) {
+      message.error('Application ID not found');
+      return;
+    }
+
+    try {
+      // Update Application Sharig Status
+      // Update Redux state to reflect the public change in UI
+      const publicResponse = await ApplicationApi.publicToAll(applicationId, appSharing.public);
+  
+      if (publicResponse.data.success) {
+        reduxStore.dispatch(updateAppPermissionInfo({ publicToAll: appSharing.public }));
+        message.success('Application is now public!');
+        
+        // Update Application Marketplace Sharing Status
+        try {
+          const marketplaceResponse = await ApplicationApi.publicToMarketplace(applicationId, appSharing.publishMarketplace);
+          if (marketplaceResponse.data.success) {
+            reduxStore.dispatch(updateAppPermissionInfo({ publicToMarketplace: appSharing.publishMarketplace }));
+            message.success(`Application ${appSharing.publishMarketplace ? 'published to' : 'unpublished from'} marketplace successfully!`);
+          } 
+        } catch (marketplaceError) {
+          console.error(`Error ${appSharing.publishMarketplace ? 'publishing to' : 'unpublishing from'} marketplace:`, marketplaceError);
+          message.warning(`Application is public but ${appSharing.publishMarketplace ? 'publishing to' : 'unpublishing from'} marketplace failed`);
+        }
+
+      } else {
+        message.error('Failed to make application public');
+      }
+    } catch (publicError) {
+      console.error('Error making application public:', publicError);
+      message.error('Failed to make application public');
+    }
   }
 };
 

From caacd01c49ba5f772ebc47a1ce707c516fc98e7a Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Mon, 14 Jul 2025 15:49:04 +0500
Subject: [PATCH 34/54] multiple new actions added

---
 .../comps/comps/preLoadComp/actionConfigs.ts  |  13 +-
 .../comps/preLoadComp/actionInputSection.tsx  | 131 ++++++++++--
 .../preLoadComp/actions/appConfiguration.ts   | 196 ++++++++++++++++++
 .../preLoadComp/actions/componentLayout.ts    | 141 ++++++++++++-
 .../comps/comps/preLoadComp/actions/index.ts  |   2 +-
 .../src/comps/comps/preLoadComp/types.ts      |   4 +
 6 files changed, 459 insertions(+), 28 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
index 10da154799..f917a1311a 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
@@ -14,7 +14,11 @@ import {
   shareAppAction,
   testAllDatasourcesAction,
   applyGlobalJSAction,
-  applyGlobalCSSAction
+  applyGlobalCSSAction,
+  applyThemeAction,
+  setCanvasSettingsAction,
+  setCustomShortcutsAction,
+  alignComponentAction
 } from "./actions";
 
 export const actionCategories: ActionCategory[] = [
@@ -39,13 +43,16 @@ export const actionCategories: ActionCategory[] = [
       shareAppAction,
       testAllDatasourcesAction,
       applyGlobalJSAction,
-      applyGlobalCSSAction
+      applyGlobalCSSAction,
+      applyThemeAction,
+      setCanvasSettingsAction,
+      setCustomShortcutsAction
     ]
   },
   {
     key: 'layout',
     label: 'Layout',
-    actions: [updateDynamicLayoutAction]
+    actions: [updateDynamicLayoutAction, alignComponentAction]
   },
   {
     key: 'events',
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
index 0b243219ef..559a1f6e07 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
@@ -23,6 +23,10 @@ import {
   getLayoutItemsOrder 
 } from "./utils";
 import { actionRegistry, getAllActionItems } from "./actionConfigs";
+import { getThemeList } from "@lowcoder-ee/redux/selectors/commonSettingSelectors";
+import { useSelector } from "react-redux";
+import { ActionOptions } from "comps/controls/actionSelector/actionSelectorControl";
+import { eventToShortcut, readableShortcut } from "util/keyUtils";
 
 export function ActionInputSection() {
   const [actionValue, setActionValue] = useState<string>("");
@@ -38,8 +42,20 @@ export function ActionInputSection() {
   const [validationError, setValidationError] = useState<string | null>(null);
   const [showDynamicLayoutDropdown, setShowDynamicLayoutDropdown] = useState<boolean>(false);
   const [selectedDynamicLayoutIndex, setSelectedDynamicLayoutIndex] = useState<string | null>(null);
+  const [showThemeDropdown, setShowThemeDropdown] = useState<boolean>(false);
+  const [selectedTheme, setSelectedTheme] = useState<string | null>(null);
+  const [showCustomShortcutsActionDropdown, setShowCustomShortcutsActionDropdown] = useState<boolean>(false);
+  const [selectedCustomShortcutAction, setSelectedCustomShortcutAction] = useState<string | null>(null);
   const inputRef = useRef<InputRef>(null);
   const editorState = useContext(EditorContext);
+  const themeList = useSelector(getThemeList) || [];
+
+  const THEME_OPTIONS = useMemo(() => {
+    return themeList.map((theme) => ({
+      label: theme.name,
+      value: theme.id + "",
+    }));
+  }, [themeList]);
 
   const categories = useMemo(() => {
     return getComponentCategories();
@@ -110,7 +126,11 @@ export function ActionInputSection() {
     setShowDynamicLayoutDropdown(false);
     setActionValue("");
     setSelectedDynamicLayoutIndex(null);
-
+    setShowThemeDropdown(false);
+    setSelectedTheme(null);
+    setShowCustomShortcutsActionDropdown(false);
+    setSelectedCustomShortcutAction(null);
+    
     if (action.requiresComponentSelection) {
       setShowComponentDropdown(true);
       setPlaceholderText("Select a component to add");
@@ -134,6 +154,12 @@ export function ActionInputSection() {
     if(action.dynamicLayout) {
       setShowDynamicLayoutDropdown(true);
     }
+    if(action.isTheme) {
+      setShowThemeDropdown(true);
+    }
+    if(action.isCustomShortcuts) {
+      setShowCustomShortcutsActionDropdown(true);
+    }
   }, []);
 
   const handleComponentSelection = useCallback((key: string) => {
@@ -199,6 +225,16 @@ export function ActionInputSection() {
       return;
     }
 
+    if(currentAction.isTheme && !selectedTheme) {
+      message.error('Please select a theme');
+      return;
+    }
+
+    if(currentAction.isCustomShortcuts && !selectedCustomShortcutAction) {
+      message.error('Please select a custom shortcut action');
+      return;
+    }
+
     try {
       await currentAction.execute({
         actionKey: selectedActionKey,
@@ -207,6 +243,8 @@ export function ActionInputSection() {
         selectedEditorComponent,
         selectedNestComponent,
         selectedDynamicLayoutIndex,
+        selectedTheme,
+        selectedCustomShortcutAction,
         editorState
       });
 
@@ -223,7 +261,10 @@ export function ActionInputSection() {
       setSelectedNestComponent(null);
       setShowDynamicLayoutDropdown(false);
       setSelectedDynamicLayoutIndex(null);
-
+      setShowThemeDropdown(false);
+      setSelectedTheme(null);
+      setShowCustomShortcutsActionDropdown(false);
+      setSelectedCustomShortcutAction(null);
     } catch (error) {
       console.error('Error executing action:', error);
       message.error('Failed to execute action. Please try again.');
@@ -235,6 +276,8 @@ export function ActionInputSection() {
     selectedEditorComponent, 
     selectedNestComponent,
     selectedDynamicLayoutIndex,
+    selectedTheme,
+    selectedCustomShortcutAction,
     editorState, 
     currentAction, 
     validateInput
@@ -246,9 +289,21 @@ export function ActionInputSection() {
     if (currentAction.requiresComponentSelection && !selectedComponent) return true;
     if (currentAction.requiresEditorComponentSelection && !selectedEditorComponent) return true;
     if (currentAction.requiresInput && !actionValue.trim()) return true;
+    if (currentAction.requiresStyle && !selectedEditorComponent) return true;
+    if (currentAction.isTheme && !selectedTheme) return true;
+    if (currentAction.isCustomShortcuts && !selectedCustomShortcutAction) return true;
     
     return false;
-  }, [selectedActionKey, currentAction, selectedComponent, selectedEditorComponent, actionValue]);
+  }, [
+    selectedActionKey, 
+    currentAction, 
+    selectedComponent, 
+    selectedEditorComponent, 
+    actionValue, 
+    selectedCustomShortcutAction, 
+    selectedTheme, 
+    selectedNestComponent
+  ]);
 
   const shouldShowInput = useMemo(() => {
     if (!currentAction) return false;
@@ -390,24 +445,70 @@ export function ActionInputSection() {
             </Dropdown>
           )}
 
+          {showThemeDropdown && (
+            <Dropdown
+              options={THEME_OPTIONS}
+              onChange={(value) => {
+                setSelectedTheme(value);
+              }}
+            >
+              <Button size={"small"}>
+                <Space>
+                  {selectedTheme ? selectedTheme : 'Select Theme'} 
+                </Space>
+              </Button>
+            </Dropdown>
+          )}
+
+          {showCustomShortcutsActionDropdown && (
+            <Dropdown
+              options={ActionOptions}
+              onChange={(value) => {
+                setSelectedCustomShortcutAction(value);
+              }}
+            >
+              <Button size={"small"}>
+                <Space>
+                  {selectedCustomShortcutAction ? selectedCustomShortcutAction : 'Select Action'} 
+                </Space>
+              </Button>
+            </Dropdown>
+          )}
+
           {shouldShowInput && (
-            showStylingInput ? (
-              <Input.TextArea
-                ref={inputRef}
-                value={actionValue}
-                onChange={handleInputChange}
-                placeholder={placeholderText}
-                status={validationError ? 'error' : undefined}
-                autoSize={{ minRows: 1 }}
-              />
-            ) : (
+            currentAction?.isCustomShortcuts ? (
               <Input
                 ref={inputRef}
-                value={actionValue}
-                onChange={handleInputChange}
+                value={readableShortcut(actionValue)}
                 placeholder={placeholderText}
                 status={validationError ? 'error' : undefined}
+                onKeyDownCapture={(e) => {
+                  setActionValue(eventToShortcut(e));
+                  e.preventDefault();
+                  e.stopPropagation();
+                }}
+                onChange={() => {}}
+                readOnly
               />
+            ) : (
+              showStylingInput ? (
+                <Input.TextArea
+                  ref={inputRef}
+                  value={actionValue}
+                  onChange={handleInputChange}
+                  placeholder={placeholderText}
+                  status={validationError ? 'error' : undefined}
+                  autoSize={{ minRows: 1 }}
+                />
+              ) : (
+                <Input
+                  ref={inputRef}
+                  value={actionValue}
+                  onChange={handleInputChange}
+                  placeholder={placeholderText}
+                  status={validationError ? 'error' : undefined}
+                />
+              )
             )
           )}
 
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
index 5371184523..a4ad48ecde 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
@@ -6,6 +6,7 @@ import { getPromiseAfterDispatch } from "util/promiseUtils";
 import { runScript } from "../utils";
 import { updateAppPermissionInfo } from "redux/reduxActions/applicationActions";
 import { reduxStore } from "redux/store/store";
+import { readableShortcut } from "util/keyUtils";
 
 export const configureAppMetaAction: ActionConfig = {
   key: 'configure-app-meta',
@@ -338,4 +339,199 @@ export const applyGlobalCSSAction: ActionConfig = {
       message.error('Failed to apply global CSS. Check console for details.');
     }
   }
+};
+
+export const applyThemeAction: ActionConfig = {
+  key: 'apply-theme',
+  label: 'Apply theme',
+  category: 'app-configuration',
+  isTheme: true,
+  execute: async (params: ActionExecuteParams) => {
+    const { editorState, selectedTheme } = params;
+
+    try {
+      if (!selectedTheme) {
+        message.error('No theme selected');
+        return;
+      }
+
+      const appSettingsComp = editorState.getAppSettingsComp();
+      if (!appSettingsComp) {
+        message.error('App settings component not found');
+        return;
+      }
+
+      const themeIdComp = appSettingsComp.children.themeId;
+      if (!themeIdComp) {
+        message.error('Theme ID component not found');
+        return;
+      }
+
+      const DEFAULT_THEMEID = "default";
+      const themeToApply = selectedTheme === DEFAULT_THEMEID ? DEFAULT_THEMEID : selectedTheme;
+
+      themeIdComp.dispatchChangeValueAction(themeToApply);
+      
+      message.success(`Theme applied successfully: ${selectedTheme}`);
+      
+    } catch (error) {
+      console.error('Error applying theme:', error);
+      message.error('Failed to apply theme. Check console for details.');
+    }
+  }
+};
+
+export const setCanvasSettingsAction: ActionConfig = {
+  key: 'set-canvas-settings',
+  label: 'Set canvas settings',
+  category: 'app-configuration',
+  requiresInput: false,
+  execute: async (params: ActionExecuteParams) => {
+    const { editorState } = params;
+
+    // Default canvas settings
+    // TODO: Get canvas settings from the user
+    const defaultCanvasSettings = {
+      maxWidth: "450",
+      gridColumns: 12,
+      gridRowHeight: 8,
+      gridRowCount: Infinity,
+      gridPaddingX: 20,
+      gridPaddingY: 20,
+      gridBg: "",
+      gridBgImage: "",
+      gridBgImageRepeat: "no-repeat",
+      gridBgImageSize: "cover",
+      gridBgImagePosition: "center",
+      gridBgImageOrigin: "no-padding"
+    };
+
+    try {
+      const appSettingsComp = editorState.getAppSettingsComp();
+      if (!appSettingsComp) {
+        message.error('App settings component not found');
+        return;
+      }
+
+      const {
+        maxWidth,
+        gridColumns,
+        gridRowHeight,
+        gridRowCount,
+        gridPaddingX,
+        gridPaddingY,
+        gridBg,
+        gridBgImage,
+        gridBgImageRepeat,
+        gridBgImageSize,
+        gridBgImagePosition,
+        gridBgImageOrigin,
+      } = appSettingsComp.children;
+
+      if (maxWidth && defaultCanvasSettings.maxWidth) {
+        maxWidth.dispatchChangeValueAction(defaultCanvasSettings.maxWidth);
+      }
+
+      if (gridColumns && defaultCanvasSettings.gridColumns) {
+        gridColumns.dispatchChangeValueAction(defaultCanvasSettings.gridColumns);
+      }
+
+      if (gridRowHeight && defaultCanvasSettings.gridRowHeight) {
+        gridRowHeight.dispatchChangeValueAction(defaultCanvasSettings.gridRowHeight);
+      }
+
+      if (gridRowCount && defaultCanvasSettings.gridRowCount) {
+        gridRowCount.dispatchChangeValueAction(defaultCanvasSettings.gridRowCount);
+      }
+
+      if (gridPaddingX && defaultCanvasSettings.gridPaddingX) {
+        gridPaddingX.dispatchChangeValueAction(defaultCanvasSettings.gridPaddingX);
+      }
+
+      if (gridPaddingY && defaultCanvasSettings.gridPaddingY) {
+        gridPaddingY.dispatchChangeValueAction(defaultCanvasSettings.gridPaddingY);
+      }
+
+      if (gridBg && defaultCanvasSettings.gridBg) {
+        gridBg.dispatchChangeValueAction(defaultCanvasSettings.gridBg);
+      }
+
+      if (gridBgImage && defaultCanvasSettings.gridBgImage) {
+        gridBgImage.dispatchChangeValueAction(defaultCanvasSettings.gridBgImage);
+      }
+
+      if (gridBgImageRepeat && defaultCanvasSettings.gridBgImageRepeat) {
+        gridBgImageRepeat.dispatchChangeValueAction(defaultCanvasSettings.gridBgImageRepeat);
+      }
+
+      if (gridBgImageSize && defaultCanvasSettings.gridBgImageSize) {
+        gridBgImageSize.dispatchChangeValueAction(defaultCanvasSettings.gridBgImageSize);
+      }
+
+      if (gridBgImagePosition && defaultCanvasSettings.gridBgImagePosition) {
+        gridBgImagePosition.dispatchChangeValueAction(defaultCanvasSettings.gridBgImagePosition);
+      }
+
+      if (gridBgImageOrigin && defaultCanvasSettings.gridBgImageOrigin) {
+        gridBgImageOrigin.dispatchChangeValueAction(defaultCanvasSettings.gridBgImageOrigin);
+      }
+
+      message.success('Canvas settings applied successfully!');
+      
+    } catch (error) {
+      console.error('Error applying canvas settings:', error);
+      message.error('Failed to apply canvas settings. Check console for details.');
+    }
+  }
+};
+
+export const setCustomShortcutsAction: ActionConfig = {
+  key: 'set-custom-shortcuts',
+  label: 'Set custom shortcuts',
+  category: 'app-configuration',
+  isCustomShortcuts: true,
+  requiresInput: true,
+  inputPlaceholder: 'Press keys for shortcut',
+  inputType: 'text',
+  validation: (value: string) => {
+    if (!value.trim()) {
+      return 'Shortcut is required';
+    }
+    return null;
+  },
+  execute: async (params: ActionExecuteParams) => {
+    const { editorState, actionValue, selectedCustomShortcutAction } = params;
+    try {
+      if (!selectedCustomShortcutAction) {
+        message.error('No custom shortcut action selected');
+        return;
+      }
+
+      const appSettingsComp = editorState.getAppSettingsComp();
+      if (!appSettingsComp) {
+        message.error('App settings component not found');
+        return;
+      }
+      const customShortcutsComp = appSettingsComp.children.customShortcuts;
+      if (!customShortcutsComp) {
+        message.error('Custom shortcuts component not found');
+        return;
+      }
+      
+      const newShortcutItem = {
+        shortcut: actionValue.trim(),
+        action: {
+          compType: selectedCustomShortcutAction,
+          comp: {}
+        }
+      };
+      
+      customShortcutsComp.dispatch(customShortcutsComp.pushAction(newShortcutItem));
+      const readableShortcutText = readableShortcut(actionValue.trim());
+      message.success(`Custom shortcut added successfully: ${readableShortcutText} -> ${selectedCustomShortcutAction}`);
+    } catch (error) {
+      console.error('Error setting custom shortcut:', error);
+      message.error('Failed to set custom shortcut. Check console for details.');
+    }
+  }
 };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentLayout.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentLayout.ts
index b0f995be93..4b5422fcb9 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentLayout.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentLayout.ts
@@ -3,20 +3,143 @@ import { ActionConfig, ActionExecuteParams } from "../types";
 import { getEditorComponentInfo } from "../utils";
 import { changeValueAction, multiChangeAction, wrapActionExtraInfo } from "lowcoder-core";
 
-export const changeLayoutAction: ActionConfig = {
-  key: 'change-layout',
-  label: 'Change layout',
+export const alignComponentAction: ActionConfig = {
+  key: 'align-component',
+  label: 'Align component',
   category: 'layout',
   requiresInput: true,
-  inputPlaceholder: 'Enter layout type (grid, flex, absolute)',
+  requiresEditorComponentSelection: true,
+  inputPlaceholder: 'Enter alignment type (left, center, right)',
   inputType: 'text',
+  validation: (value: string) => {
+    const alignment = value.toLowerCase().trim();
+    if (!['left', 'center', 'right'].includes(alignment)) {
+      return 'Alignment must be one of: left, center, right';
+    }
+    return null;
+  },
   execute: async (params: ActionExecuteParams) => {
-    const { actionValue } = params;
-    
-    console.log('Changing layout to:', actionValue);
-    message.info(`Layout changed to: ${actionValue}`);
+    const { actionValue, editorState, selectedEditorComponent } = params;
     
-    // TODO: Implement actual layout change logic
+    if (!selectedEditorComponent || !editorState) {
+      message.error('Component and editor state are required');
+      return;
+    }
+
+    const alignment = actionValue.toLowerCase().trim();
+    if (!['left', 'center', 'right'].includes(alignment)) {
+      message.error('Invalid alignment. Must be: left, center, or right');
+      return;
+    }
+
+    try {
+      const componentInfo = getEditorComponentInfo(editorState, selectedEditorComponent);
+      if(!componentInfo) {
+        message.error(`Component "${selectedEditorComponent}" not found`);
+        return;
+      }
+
+      const { componentKey, currentLayout, simpleContainer, items } = componentInfo;
+      if(!componentKey) {
+        message.error(`Component "${selectedEditorComponent}" not found`);
+        return;
+      }
+
+      const layout = currentLayout[componentKey];
+      if(!layout) {
+        message.error(`Component "${selectedEditorComponent}" not found`);
+        return;
+      }
+
+      const appSettingsComp = editorState.getAppSettingsComp();
+      if (!appSettingsComp) {
+        message.error('App settings component not found');
+        return;
+      }
+
+      const gridColumns = appSettingsComp.children.gridColumns?.getView() || 24;
+      
+      const currentX = layout.x || 0;
+      const currentY = layout.y || 0;
+      const currentWidth = layout.w || 1;
+      const currentHeight = layout.h || 1;
+
+      let newX = currentX;
+      
+      switch (alignment) {
+        case 'left':
+          newX = 0;
+          break;
+        case 'center':
+          newX = Math.max(0, Math.floor((gridColumns - currentWidth) / 2));
+          break;
+        case 'right':
+          newX = Math.max(0, gridColumns - currentWidth);
+          break;
+      }
+
+      newX = Math.max(0, Math.min(newX, gridColumns - currentWidth));
+
+      const newLayout = {
+        ...currentLayout,
+        [componentKey]: {
+          ...layout,
+          x: newX,
+          y: currentY,
+          w: currentWidth,
+          h: currentHeight,
+        }
+      };
+
+      Object.entries(currentLayout).forEach(([key, item]) => {
+        if (key !== componentKey) {
+          const otherItem = item as any;
+          const otherX = otherItem.x || 0;
+          const otherY = otherItem.y || 0;
+          const otherWidth = otherItem.w || 1;
+          const otherHeight = otherItem.h || 1;
+
+          const collision = !(
+            newX + currentWidth <= otherX ||
+            otherX + otherWidth <= newX ||
+            currentY + currentHeight <= otherY ||
+            otherY + otherHeight <= currentY
+          );
+
+          if (collision) {
+            newLayout[key] = {
+              ...otherItem,
+              y: Math.max(otherY, currentY + currentHeight)
+            };
+          } else {
+            newLayout[key] = otherItem;
+          }
+        }
+      });
+
+      simpleContainer.dispatch(
+        wrapActionExtraInfo(
+          multiChangeAction({
+            layout: changeValueAction(newLayout, true),
+          }),
+          { 
+            compInfos: [{ 
+              compName: selectedEditorComponent, 
+              compType: (items[componentKey] as any).children.compType.getView(), 
+              type: "layout" 
+            }] 
+          }
+        )
+      );
+
+      editorState.setSelectedCompNames(new Set([selectedEditorComponent]), "alignComp");
+      
+      message.success(`Component "${selectedEditorComponent}" aligned to ${alignment}`);
+      
+    } catch (error) {
+      console.error('Error aligning component:', error);
+      message.error('Failed to align component. Please try again.');
+    }
   }
 }; 
 
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts
index c9c6efa43e..608a15156d 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/index.ts
@@ -5,7 +5,7 @@ export * from './componentManagement';
 export * from './appConfiguration';
 
 // Layout Actions
-export { changeLayoutAction, updateDynamicLayoutAction } from './componentLayout';
+export { alignComponentAction, updateDynamicLayoutAction } from './componentLayout';
 
 // Event Actions
 export { addEventHandlerAction } from './componentEvents';
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
index 51e34e9dff..5c54124e2a 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/types.ts
@@ -34,6 +34,8 @@ export interface ActionConfig {
   requiresEditorComponentSelection?: boolean;
   requiresInput?: boolean;
   requiresStyle?: boolean;
+  isTheme?: boolean;
+  isCustomShortcuts?: boolean;
   isNested?: boolean;
   dynamicLayout?: boolean;
   inputPlaceholder?: string;
@@ -50,6 +52,8 @@ export interface ActionExecuteParams {
   selectedEditorComponent: string | null;
   selectedNestComponent: string | null;
   selectedDynamicLayoutIndex: string | null;
+  selectedTheme: string | null;
+  selectedCustomShortcutAction: string | null;
   editorState: any;
 }
 

From 1dddc59c9e81f35b00d05b46a7f2ca6511969964 Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Mon, 14 Jul 2025 16:09:48 +0500
Subject: [PATCH 35/54] Updated Global CSS

---
 .../comps/comps/preLoadComp/actionConfigs.ts  |  4 +--
 .../comps/preLoadComp/actionInputSection.tsx  |  3 ---
 .../preLoadComp/actions/appConfiguration.ts   | 26 +++++++++----------
 3 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
index f917a1311a..96d68fcbe3 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionConfigs.ts
@@ -14,7 +14,7 @@ import {
   shareAppAction,
   testAllDatasourcesAction,
   applyGlobalJSAction,
-  applyGlobalCSSAction,
+  applyCSSAction,
   applyThemeAction,
   setCanvasSettingsAction,
   setCustomShortcutsAction,
@@ -43,7 +43,7 @@ export const actionCategories: ActionCategory[] = [
       shareAppAction,
       testAllDatasourcesAction,
       applyGlobalJSAction,
-      applyGlobalCSSAction,
+      applyCSSAction,
       applyThemeAction,
       setCanvasSettingsAction,
       setCustomShortcutsAction
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
index 559a1f6e07..6be8b85b60 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actionInputSection.tsx
@@ -289,9 +289,6 @@ export function ActionInputSection() {
     if (currentAction.requiresComponentSelection && !selectedComponent) return true;
     if (currentAction.requiresEditorComponentSelection && !selectedEditorComponent) return true;
     if (currentAction.requiresInput && !actionValue.trim()) return true;
-    if (currentAction.requiresStyle && !selectedEditorComponent) return true;
-    if (currentAction.isTheme && !selectedTheme) return true;
-    if (currentAction.isCustomShortcuts && !selectedCustomShortcutAction) return true;
     
     return false;
   }, [
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
index a4ad48ecde..87a46c6680 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
@@ -277,7 +277,7 @@ export const applyGlobalJSAction: ActionConfig = {
       scriptComp.dispatchChangeValueAction(jsCode);
       runScript(jsCode, false);
       
-      message.success('Global JavaScript applied successfully!');
+      message.success('JavaScript applied successfully!');
       
     } catch (error) {
       console.error('Error applying global JavaScript:', error);
@@ -286,13 +286,13 @@ export const applyGlobalJSAction: ActionConfig = {
   }
 };
 
-export const applyGlobalCSSAction: ActionConfig = {
-  key: 'apply-global-css',
-  label: 'Apply global CSS',
+export const applyCSSAction: ActionConfig = {
+  key: 'apply-css',
+  label: 'Apply CSS',
   category: 'app-configuration',
   requiresInput: true,
   requiresStyle: true,
-  inputPlaceholder: 'Enter CSS code to apply globally...',
+  inputPlaceholder: 'Enter CSS code to apply...',
   inputType: 'textarea',
   validation: (value: string) => {
     if (!value.trim()) {
@@ -322,21 +322,21 @@ export const applyGlobalCSSAction: ActionConfig = {
         return;
       }
 
-      const globalCSSComp = preloadComp.children.globalCSS;
-      if (!globalCSSComp) {
-        message.error('Global CSS component not found');
+      const cssComp = preloadComp.children.css;
+      if (!cssComp) {
+        message.error('CSS component not found');
         return;
       }
 
-      globalCSSComp.dispatchChangeValueAction(cssCode);
+      cssComp.dispatchChangeValueAction(cssCode);
       
-      await globalCSSComp.run('global-css', cssCode);
+      await cssComp.run('css', cssCode);
       
-      message.success('Global CSS applied successfully!');
+      message.success('CSS applied successfully!');
       
     } catch (error) {
-      console.error('Error applying global CSS:', error);
-      message.error('Failed to apply global CSS. Check console for details.');
+      console.error('Error applying CSS:', error);
+      message.error('Failed to apply CSS. Check console for details.');
     }
   }
 };

From a380978f76efe16e8603b926bb4c38391f493c88 Mon Sep 17 00:00:00 2001
From: Kamal Qureshi <kamalqureshi98@gmail.com>
Date: Thu, 10 Jul 2025 14:21:02 +0500
Subject: [PATCH 36/54] Update App meta data

---
 .../src/comps/comps/preLoadComp/actions/appConfiguration.ts     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
index 87a46c6680..2278795505 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
@@ -534,4 +534,4 @@ export const setCustomShortcutsAction: ActionConfig = {
       message.error('Failed to set custom shortcut. Check console for details.');
     }
   }
-};
\ No newline at end of file
+};

From 4585d15e898058481a36a00e92a269c799b59806 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Mon, 7 Jul 2025 18:27:25 +0500
Subject: [PATCH 37/54] [feat] replace mock data with query

---
 .../src/comps/comps/chatComp/chatComp.tsx     |  41 ++-----
 .../src/comps/comps/chatComp/chatCompTypes.ts |  22 ++--
 .../comps/comps/chatComp/chatPropertyView.tsx |  43 ++++---
 .../src/comps/comps/chatComp/chatView.tsx     |  11 +-
 .../comps/chatComp/components/ChatApp.tsx     |  17 +--
 .../comps/chatComp/components/ChatMain.tsx    | 116 ++++++++++--------
 6 files changed, 125 insertions(+), 125 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
index d26dce7b29..921ed80830 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
@@ -8,39 +8,22 @@ import { useEffect, useState } from "react";
 import { changeChildAction } from "lowcoder-core";
 
 // Build the component
-let ChatTmpComp = new UICompBuilder(
-  chatChildrenMap, 
-  (props, dispatch) => {
-    useEffect(() => {
-      if (Boolean(props.tableName)) return;
-
-      // Generate a unique database name for this ChatApp instance
-      const generateUniqueTableName = () => {
-        const timestamp = Date.now();
-        const randomId = Math.random().toString(36).substring(2, 15);
-        return `TABLE_${timestamp}`;
-      };
-      
-      const tableName = generateUniqueTableName();
-      dispatch(changeChildAction('tableName', tableName, true));
-    }, [props.tableName]);
-    
-    if (!props.tableName) {
-      return null; // Don't render until we have a unique DB name
-    }
-    return <ChatView {...props} chatQuery={props.chatQuery.value} />;
-  }
+const ChatTmpComp = new UICompBuilder(
+  chatChildrenMap,
+  (props, dispatch) => (
+    <ChatView
+      {...props}
+      chatQuery={props.chatQuery.value}
+      currentMessage={props.currentMessage.value}
+      dispatch={dispatch}
+    />
+  )
 )
   .setPropertyViewFn((children) => <ChatPropertyView children={children} />)
   .build();
 
-ChatTmpComp = class extends ChatTmpComp {
-  override autoHeight(): boolean {
-    return this.children.autoHeight.getView();
-  }
-};
-
-// Export the component
+// Export the component with exposed variables
 export const ChatComp = withExposingConfigs(ChatTmpComp, [
   new NameConfig("text", "Chat component text"),
+  new NameConfig("currentMessage", "Current user message"),
 ]);
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
index 87dca43a37..4484c15431 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
@@ -1,5 +1,6 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
 import { StringControl, NumberControl } from "comps/controls/codeControl";
+import { stringExposingStateControl } from "comps/controls/codeStateControl";
 import { withDefault } from "comps/generators";
 import { BoolControl } from "comps/controls/boolControl";
 import { dropdownControl } from "comps/controls/dropdownControl";
@@ -14,26 +15,25 @@ const ModelTypeOptions = [
 
 export const chatChildrenMap = {
   text: withDefault(StringControl, "Chat Component Placeholder"),
+  chatQuery: QuerySelectControl,
+  currentMessage: stringExposingStateControl("currentMessage", ""),
   modelType: dropdownControl(ModelTypeOptions, "direct-llm"),
   modelHost: withDefault(StringControl, ""),
   streaming: BoolControl.DEFAULT_TRUE,
   systemPrompt: withDefault(StringControl, "You are a helpful assistant."),
   agent: BoolControl,
   maxInteractions: withDefault(NumberControl, 10),
-  chatQuery: QuerySelectControl,
   autoHeight: AutoHeightControl,
   tableName: withDefault(StringControl, ""),
 };
 
 export type ChatCompProps = {
-  text?: string;
-  chatQuery?: string;
-  modelType?: string;
-  streaming?: boolean;
-  systemPrompt?: string;
-  agent?: boolean;
-  maxInteractions?: number;
-  modelHost?: string;
-  autoHeight?: boolean;
-  tableName?: string;
+  text: string;
+  chatQuery: string;
+  currentMessage: string;
+  modelType: string;
+  streaming: boolean;
+  systemPrompt: string;
+  agent: boolean;
+  maxInteractions: number;
 };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
index 2a9143c4ae..a5b3f52493 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
@@ -7,28 +7,27 @@ export const ChatPropertyView = React.memo((props: any) => {
   const { children } = props;
 
   return (
-    <>
-      <Section name={sectionNames.basic}>
-        {children.modelType.propertyView({ label: "Model Type" })}
-        {children.modelHost.propertyView({ label: "Model Host" })}
-        {/* {children.text.propertyView({ label: "Text" })}
-        {children.chatQuery.propertyView({ label: "Chat Query" })} */}
-        {children.streaming.propertyView({ label: "Enable Streaming" })}
-        {children.systemPrompt.propertyView({ 
-          label: "System Prompt",
-          placeholder: "Enter system prompt...",
-          enableSpellCheck: false,
-        })}
-        {children.agent.propertyView({ label: "Enable Agent Mode" })}
-        {children.maxInteractions.propertyView({ 
-          label: "Max Interactions",
-          placeholder: "10",
-        })}
-      </Section>
-      <Section name={sectionNames.layout}>
-        {children.autoHeight.propertyView({ label: trans("prop.height") })}
-      </Section>
-    </>
+    <Section name={sectionNames.basic}>
+      {children.text.propertyView({ label: "Text" })}
+      {children.chatQuery.propertyView({ label: "Chat Query" })}
+      {children.currentMessage.propertyView({ 
+        label: "Current Message (Dynamic)", 
+        placeholder: "Shows the current user message",
+        disabled: true 
+      })}
+      {children.modelType.propertyView({ label: "Model Type" })}
+      {children.streaming.propertyView({ label: "Enable Streaming" })}
+      {children.systemPrompt.propertyView({ 
+        label: "System Prompt",
+        placeholder: "Enter system prompt...",
+        enableSpellCheck: false,
+      })}
+      {children.agent.propertyView({ label: "Enable Agent Mode" })}
+      {children.maxInteractions.propertyView({ 
+        label: "Max Interactions",
+        placeholder: "10",
+      })}
+    </Section>
   );
 });
 
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
index eca764ba6a..93b95af4c8 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
@@ -1,13 +1,20 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
 import React from "react";
 import { ChatCompProps } from "./chatCompTypes";
+import { CompAction } from "lowcoder-core";
 import { ChatApp } from "./components/ChatApp";
 
 import "@assistant-ui/styles/index.css";
 import "@assistant-ui/styles/markdown.css";
 
-export const ChatView = React.memo((props: ChatCompProps) => {
-  return <ChatApp {...props} />;
+// Extend the props we receive so we can forward the redux dispatch
+interface ChatViewProps extends ChatCompProps {
+  dispatch?: (action: CompAction<any>) => void;
+}
+
+export const ChatView = React.memo((props: ChatViewProps) => {
+  const { chatQuery, currentMessage, dispatch } = props;
+  return <ChatApp chatQuery={chatQuery} currentMessage={currentMessage} dispatch={dispatch} />;
 });
 
 ChatView.displayName = 'ChatView';
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
index e8092a494b..3353de6897 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
@@ -1,16 +1,17 @@
 import { ChatProvider } from "./context/ChatContext";
 import { ChatMain } from "./ChatMain";
-import { ChatCompProps } from "../chatCompTypes";
-import { useEffect, useState } from "react";
+import { CompAction } from "lowcoder-core";
 
-export function ChatApp(props: ChatCompProps) {
-  if (!Boolean(props.tableName)) {
-    return null; // Don't render until we have a unique DB name
-  }
-  
+interface ChatAppProps {
+  chatQuery: string;
+  currentMessage: string;
+  dispatch?: (action: CompAction<any>) => void;
+}
+
+export function ChatApp({ chatQuery, currentMessage, dispatch }: ChatAppProps) {
   return (
     <ChatProvider>
-      <ChatMain {...props} />
+      <ChatMain chatQuery={chatQuery} currentMessage={currentMessage} dispatch={dispatch} />
     </ChatProvider>
   );
 }
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
index 1c906e4081..d9718b803e 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
@@ -16,11 +16,8 @@ import {
   ArchivedThreadData 
 } from "./context/ChatContext";
 import styled from "styled-components";
-import { ChatCompProps } from "../chatCompTypes";
-import { message } from "antd";
-import { EditorContext } from "@lowcoder-ee/comps/editorState";
-import { addComponentAction, nestComponentAction } from "../../preLoadComp/actions/componentManagement";
-import { configureComponentAction } from "../../preLoadComp/actions/componentConfiguration";
+import { routeByNameAction, executeQueryAction, CompAction, changeChildAction } from "lowcoder-core";
+import { getPromiseAfterDispatch } from "util/promiseUtils";
 
 const ChatContainer = styled.div<{ $autoHeight?: boolean }>`
   display: flex;
@@ -54,38 +51,57 @@ const ChatContainer = styled.div<{ $autoHeight?: boolean }>`
 
 const generateId = () => Math.random().toString(36).substr(2, 9);
 
-const callYourAPI = async (params: {
-  text: string,
-  modelHost: string,
-  modelType: string,
-  sessionId: string,
-}) => {
-  const { text, modelHost, modelType, sessionId } = params;
-
-  let url = modelHost;
-  if (modelType === "direct-llm") {
-    url = `${modelHost}/api/chat/completions`;
+// Helper to call the Lowcoder query system
+const callQuery = async (
+  queryName: string,
+  prompt: string,
+  dispatch?: (action: CompAction<any>) => void
+) => {
+  // If no query selected or dispatch unavailable, fallback with mock response
+  if (!queryName || !dispatch) {
+    await new Promise((res) => setTimeout(res, 500));
+    return { content: "(mock) You typed: " + prompt };
   }
 
-  const response = await fetch(`${url}`, {
-    method: "POST",
-    body: JSON.stringify({
-      text,
-      sessionId,
-    }),
-  });
+  try {
+    const result: any = await getPromiseAfterDispatch(
+      dispatch,
+      routeByNameAction(
+        queryName,
+        executeQueryAction({
+          // Send the user prompt as variable named 'prompt' by default
+          args: { prompt: { value: prompt } },
+        })
+      )
+    );
+
+    // Extract reply text from the query result
+    let reply: string;
+    if (typeof result === "string") {
+      reply = result;
+    } else if (result && typeof result === "object") {
+      reply =
+        (result as any).response ??
+        (result as any).message ??
+        (result as any).content ??
+        JSON.stringify(result);
+    } else {
+      reply = String(result);
+    }
 
-  return response.json();
-  // Simulate API delay
-  // await new Promise(resolve => setTimeout(resolve, 1500));
-  
-  // Simple responses
-  // return {
-  //   content: "This is a mock response from your backend. You typed: " + text
-  // };
+    return { content: reply };
+  } catch (e: any) {
+    throw new Error(e?.message || "Query execution failed");
+  }
 };
 
-export function ChatMain(props: ChatCompProps) {
+interface ChatMainProps {
+  chatQuery: string;
+  currentMessage: string;
+  dispatch?: (action: CompAction<any>) => void;
+}
+
+export function ChatMain({ chatQuery, currentMessage, dispatch }: ChatMainProps) {
   const { state, actions } = useChatContext();
   const [isRunning, setIsRunning] = useState(false);
   const editorState = useContext(EditorContext);
@@ -178,21 +194,19 @@ export function ChatMain(props: ChatCompProps) {
       timestamp: Date.now(),
     };
     
+    // Update currentMessage state to expose to queries
+    if (dispatch) {
+      dispatch(changeChildAction("currentMessage", userMessage.text, false));
+    }
+    
     // Update current thread with new user message
     await actions.addMessage(state.currentThreadId, userMessage);
     setIsRunning(true);
 
     try {
-      // Call mock API
-      const response = await callYourAPI({
-        text: userMessage.text,
-        modelHost: props.modelHost!,
-        modelType: props.modelType!,
-        sessionId: state.currentThreadId,
-      });
-      const {explanation: reply, actions: editorActions} = JSON.parse(response?.output);
-      performAction(editorActions);
-
+      // Call selected query / fallback to mock
+      const response = await callQuery(chatQuery, userMessage.text, dispatch);
+      
       const assistantMessage: MyMessage = {
         id: generateId(),
         role: "assistant",
@@ -239,22 +253,18 @@ export function ChatMain(props: ChatCompProps) {
     };
     newMessages.push(editedMessage);
 
+    // Update currentMessage state to expose to queries
+    if (dispatch) {
+      dispatch(changeChildAction("currentMessage", editedMessage.text, false));
+    }
+
     // Update messages using the new context action
     await actions.updateMessages(state.currentThreadId, newMessages);
     setIsRunning(true);
 
     try {
-      // Generate new response
-      const response = await callYourAPI({
-        text: editedMessage.text,
-        modelHost: props.modelHost!,
-        modelType: props.modelType!,
-        sessionId: state.currentThreadId,
-      });
-    
-      const {explanation: reply, actions: editorActions} = JSON.parse(response?.output);
-      performAction(editorActions);
-
+      const response = await callQuery(chatQuery, editedMessage.text, dispatch);
+      
       const assistantMessage: MyMessage = {
         id: generateId(),
         role: "assistant",

From 75e635a25d62b9a3a59b8591de07be2680bd8610 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Mon, 7 Jul 2025 23:28:05 +0500
Subject: [PATCH 38/54] [Feat]: make chat component flexible

---
 .../src/comps/comps/chatComp/chatCompTypes.ts |   8 +-
 .../src/comps/comps/chatComp/chatView.tsx     |  32 ++-
 .../comps/chatComp/components/ChatApp.tsx     |  34 +++-
 .../comps/chatComp/components/ChatMain.tsx    |  39 +++-
 .../components/context/ChatContext.tsx        |  26 +--
 .../chatComp/utils/chatStorageFactory.ts      | 189 ++++++++++++++++++
 .../comps/chatComp/utils/responseFactory.ts   |  27 +++
 .../comps/chatComp/utils/responseHandlers.ts  |  99 +++++++++
 .../src/pages/editor/bottom/BottomPanel.tsx   |  14 +-
 9 files changed, 437 insertions(+), 31 deletions(-)
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorageFactory.ts
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/utils/responseFactory.ts
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/utils/responseHandlers.ts

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
index 4484c15431..5c55744712 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
@@ -11,20 +11,20 @@ import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl
 const ModelTypeOptions = [
   { label: "Direct LLM", value: "direct-llm" },
   { label: "n8n Workflow", value: "n8n" },
+  { label: "Query", value: "query" },
 ] as const;
 
 export const chatChildrenMap = {
   text: withDefault(StringControl, "Chat Component Placeholder"),
   chatQuery: QuerySelectControl,
   currentMessage: stringExposingStateControl("currentMessage", ""),
-  modelType: dropdownControl(ModelTypeOptions, "direct-llm"),
+  modelType: dropdownControl(ModelTypeOptions, "query"),
   modelHost: withDefault(StringControl, ""),
   streaming: BoolControl.DEFAULT_TRUE,
   systemPrompt: withDefault(StringControl, "You are a helpful assistant."),
   agent: BoolControl,
   maxInteractions: withDefault(NumberControl, 10),
-  autoHeight: AutoHeightControl,
-  tableName: withDefault(StringControl, ""),
+  tableName: withDefault(StringControl, "default"),
 };
 
 export type ChatCompProps = {
@@ -32,8 +32,10 @@ export type ChatCompProps = {
   chatQuery: string;
   currentMessage: string;
   modelType: string;
+  modelHost: string;
   streaming: boolean;
   systemPrompt: string;
   agent: boolean;
   maxInteractions: number;
+  tableName: string;
 };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
index 93b95af4c8..544e73e8d3 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
@@ -1,8 +1,9 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
-import React from "react";
+import React, { useMemo } from "react";
 import { ChatCompProps } from "./chatCompTypes";
 import { CompAction } from "lowcoder-core";
 import { ChatApp } from "./components/ChatApp";
+import { createChatStorage } from './utils/chatStorageFactory';
 
 import "@assistant-ui/styles/index.css";
 import "@assistant-ui/styles/markdown.css";
@@ -13,8 +14,33 @@ interface ChatViewProps extends ChatCompProps {
 }
 
 export const ChatView = React.memo((props: ChatViewProps) => {
-  const { chatQuery, currentMessage, dispatch } = props;
-  return <ChatApp chatQuery={chatQuery} currentMessage={currentMessage} dispatch={dispatch} />;
+  const { 
+    chatQuery, 
+    currentMessage, 
+    dispatch,
+    modelType,
+    modelHost,
+    systemPrompt,
+    streaming,
+    tableName
+  } = props;
+
+  // Create storage instance based on tableName
+  const storage = useMemo(() => createChatStorage(tableName || "default"), [tableName]);
+
+  return (
+    <ChatApp 
+      chatQuery={chatQuery} 
+      currentMessage={currentMessage} 
+      dispatch={dispatch}
+      modelType={modelType}
+      modelHost={modelHost}
+      systemPrompt={systemPrompt}
+      streaming={streaming}
+      tableName={tableName}
+      storage={storage}
+    />
+  );
 });
 
 ChatView.displayName = 'ChatView';
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
index 3353de6897..12ee0071f5 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
@@ -1,17 +1,43 @@
 import { ChatProvider } from "./context/ChatContext";
 import { ChatMain } from "./ChatMain";
 import { CompAction } from "lowcoder-core";
+import { createChatStorage } from "../utils/chatStorageFactory";
 
 interface ChatAppProps {
   chatQuery: string;
   currentMessage: string;
   dispatch?: (action: CompAction<any>) => void;
+  modelType: string;
+  modelHost?: string;
+  systemPrompt?: string;
+  streaming?: boolean;
+  tableName: string;
+  storage: ReturnType<typeof createChatStorage>;
 }
 
-export function ChatApp({ chatQuery, currentMessage, dispatch }: ChatAppProps) {
+export function ChatApp({ 
+  chatQuery, 
+  currentMessage, 
+  dispatch, 
+  modelType, 
+  modelHost, 
+  systemPrompt, 
+  streaming,
+  tableName,
+  storage 
+}: ChatAppProps) {
   return (
-    <ChatProvider>
-      <ChatMain chatQuery={chatQuery} currentMessage={currentMessage} dispatch={dispatch} />
+    <ChatProvider storage={storage}>
+      <ChatMain 
+        chatQuery={chatQuery} 
+        currentMessage={currentMessage} 
+        dispatch={dispatch}
+        modelType={modelType}
+        modelHost={modelHost}
+        systemPrompt={systemPrompt}
+        streaming={streaming}
+        tableName={tableName}
+      />
     </ChatProvider>
   );
-}
+}
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
index d9718b803e..3359c75806 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
@@ -18,6 +18,9 @@ import {
 import styled from "styled-components";
 import { routeByNameAction, executeQueryAction, CompAction, changeChildAction } from "lowcoder-core";
 import { getPromiseAfterDispatch } from "util/promiseUtils";
+// ADD THIS IMPORT:
+import { createResponseHandler } from '../utils/responseFactory';
+import { useMemo } from 'react'; // if not already imported
 
 const ChatContainer = styled.div<{ $autoHeight?: boolean }>`
   display: flex;
@@ -95,13 +98,28 @@ const callQuery = async (
   }
 };
 
+// AFTER:
 interface ChatMainProps {
   chatQuery: string;
   currentMessage: string;
   dispatch?: (action: CompAction<any>) => void;
+  // Add new props for response handling
+  modelType: string;
+  modelHost?: string;
+  systemPrompt?: string;
+  streaming?: boolean;
+  tableName: string;
 }
 
-export function ChatMain({ chatQuery, currentMessage, dispatch }: ChatMainProps) {
+export function ChatMain({ 
+  chatQuery, 
+  currentMessage, 
+  dispatch, 
+  modelType, 
+  modelHost, 
+  systemPrompt, 
+  streaming,
+  tableName  }: ChatMainProps) {
   const { state, actions } = useChatContext();
   const [isRunning, setIsRunning] = useState(false);
   const editorState = useContext(EditorContext);
@@ -113,6 +131,21 @@ export function ChatMain({ chatQuery, currentMessage, dispatch }: ChatMainProps)
     editorStateRef.current = editorState;
   }, [editorState]);
 
+// Create response handler based on model type
+const responseHandler = useMemo(() => {
+  const responseType = modelType === "n8n" ? "direct-api" : "query";
+  
+  return createResponseHandler(responseType, {
+    // Query handler config
+    chatQuery,
+    dispatch,
+    // Direct API handler config  
+    modelHost,
+    systemPrompt,
+    streaming
+  });
+}, [modelType, chatQuery, dispatch, modelHost, systemPrompt, streaming]);
+
   console.log("STATE", state);
 
   // Get messages for current thread
@@ -205,7 +238,7 @@ export function ChatMain({ chatQuery, currentMessage, dispatch }: ChatMainProps)
 
     try {
       // Call selected query / fallback to mock
-      const response = await callQuery(chatQuery, userMessage.text, dispatch);
+      const response = await responseHandler.sendMessage(userMessage.text);
       
       const assistantMessage: MyMessage = {
         id: generateId(),
@@ -263,7 +296,7 @@ export function ChatMain({ chatQuery, currentMessage, dispatch }: ChatMainProps)
     setIsRunning(true);
 
     try {
-      const response = await callQuery(chatQuery, editedMessage.text, dispatch);
+      const response = await responseHandler.sendMessage(editedMessage.text);
       
       const assistantMessage: MyMessage = {
         id: generateId(),
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
index 41ef892af4..68c4d4206c 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
@@ -1,6 +1,5 @@
 import React, { createContext, useContext, useReducer, useEffect, ReactNode } from "react";
-import { chatStorage, ThreadData as StoredThreadData } from "../../utils/chatStorage";
-
+import {  ThreadData as StoredThreadData } from "../../utils/chatStorageFactory";
 // Define thread-specific message type
 export interface MyMessage {
   id: string;
@@ -176,7 +175,8 @@ interface ChatContextType {
 const ChatContext = createContext<ChatContextType | null>(null);
 
 // Chat provider component
-export function ChatProvider({ children }: { children: ReactNode }) {
+  export function ChatProvider({ children, storage }: { children: ReactNode,   storage: ReturnType<typeof import("../../utils/chatStorageFactory").createChatStorage>; 
+  }) {
   const [state, dispatch] = useReducer(chatReducer, initialState);
 
   // Initialize data from storage
@@ -184,10 +184,10 @@ export function ChatProvider({ children }: { children: ReactNode }) {
     dispatch({ type: "INITIALIZE_START" });
     
     try {
-      await chatStorage.initialize();
+      await storage.initialize();
       
       // Load all threads from storage
-      const storedThreads = await chatStorage.getAllThreads();
+      const storedThreads = await storage.getAllThreads();
       
       if (storedThreads.length > 0) {
         // Convert stored threads to UI format
@@ -200,7 +200,7 @@ export function ChatProvider({ children }: { children: ReactNode }) {
         // Load messages for each thread
         const threadMessages = new Map<string, MyMessage[]>();
         for (const thread of storedThreads) {
-          const messages = await chatStorage.getMessages(thread.threadId);
+          const messages = await storage.getMessages(thread.threadId);
           threadMessages.set(thread.threadId, messages);
         }
         
@@ -228,7 +228,7 @@ export function ChatProvider({ children }: { children: ReactNode }) {
           createdAt: Date.now(),
           updatedAt: Date.now(),
         };
-        await chatStorage.saveThread(defaultThread);
+        await storage.saveThread(defaultThread);
         
         dispatch({ 
           type: "INITIALIZE_SUCCESS", 
@@ -268,7 +268,7 @@ export function ChatProvider({ children }: { children: ReactNode }) {
         createdAt: Date.now(),
         updatedAt: Date.now(),
       };
-      await chatStorage.saveThread(storedThread);
+      await storage.saveThread(storedThread);
       dispatch({ type: "MARK_SAVED" });
     } catch (error) {
       console.error("Failed to save new thread:", error);
@@ -283,14 +283,14 @@ export function ChatProvider({ children }: { children: ReactNode }) {
     
     // Save to storage
     try {
-      const existingThread = await chatStorage.getThread(threadId);
+      const existingThread = await storage.getThread(threadId);
       if (existingThread) {
         const updatedThread: StoredThreadData = {
           ...existingThread,
           ...updates,
           updatedAt: Date.now(),
         };
-        await chatStorage.saveThread(updatedThread);
+        await storage.saveThread(updatedThread);
         dispatch({ type: "MARK_SAVED" });
       }
     } catch (error) {
@@ -304,7 +304,7 @@ export function ChatProvider({ children }: { children: ReactNode }) {
     
     // Delete from storage
     try {
-      await chatStorage.deleteThread(threadId);
+      await storage.deleteThread(threadId);
       dispatch({ type: "MARK_SAVED" });
     } catch (error) {
       console.error("Failed to delete thread:", error);
@@ -318,7 +318,7 @@ export function ChatProvider({ children }: { children: ReactNode }) {
     
     // Save to storage
     try {
-      await chatStorage.saveMessage(message, threadId);
+      await storage.saveMessage(message, threadId);
       dispatch({ type: "MARK_SAVED" });
     } catch (error) {
       console.error("Failed to save message:", error);
@@ -331,7 +331,7 @@ export function ChatProvider({ children }: { children: ReactNode }) {
     
     // Save to storage
     try {
-      await chatStorage.saveMessages(messages, threadId);
+      await storage.saveMessages(messages, threadId);
       dispatch({ type: "MARK_SAVED" });
     } catch (error) {
       console.error("Failed to save messages:", error);
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorageFactory.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorageFactory.ts
new file mode 100644
index 0000000000..e7f44a26c3
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorageFactory.ts
@@ -0,0 +1,189 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorageFactory.ts
+import alasql from "alasql";
+import { MyMessage } from "../components/context/ChatContext";
+
+// Thread data interface
+export interface ThreadData {
+  threadId: string;
+  status: "regular" | "archived";
+  title: string;
+  createdAt: number;
+  updatedAt: number;
+}
+
+export const createChatStorage = (tableName: string) => {
+  const dbName = `ChatDB_${tableName}`;
+  const threadsTable = `${tableName}_threads`;
+  const messagesTable = `${tableName}_messages`;
+  
+  return {
+    async initialize() {
+      try {
+        // Create database with localStorage backend
+        await alasql.promise(`CREATE LOCALSTORAGE DATABASE IF NOT EXISTS ${dbName}`);
+        await alasql.promise(`ATTACH LOCALSTORAGE DATABASE ${dbName}`);
+        await alasql.promise(`USE ${dbName}`);
+
+        // Create threads table
+        await alasql.promise(`
+          CREATE TABLE IF NOT EXISTS ${threadsTable} (
+            threadId STRING PRIMARY KEY,
+            status STRING,
+            title STRING,
+            createdAt NUMBER,
+            updatedAt NUMBER
+          )
+        `);
+
+        // Create messages table
+        await alasql.promise(`
+          CREATE TABLE IF NOT EXISTS ${messagesTable} (
+            id STRING PRIMARY KEY,
+            threadId STRING,
+            role STRING,
+            text STRING,
+            timestamp NUMBER
+          )
+        `);
+
+        console.log(`✅ Chat database initialized: ${dbName}`);
+      } catch (error) {
+        console.error(`Failed to initialize chat database ${dbName}:`, error);
+        throw error;
+      }
+    },
+
+    async saveThread(thread: ThreadData) {
+      try {
+        // Insert or replace thread
+        await alasql.promise(`
+          DELETE FROM ${threadsTable} WHERE threadId = ?
+        `, [thread.threadId]);
+        
+        await alasql.promise(`
+          INSERT INTO ${threadsTable} VALUES (?, ?, ?, ?, ?)
+        `, [thread.threadId, thread.status, thread.title, thread.createdAt, thread.updatedAt]);
+      } catch (error) {
+        console.error("Failed to save thread:", error);
+        throw error;
+      }
+    },
+
+    async getThread(threadId: string) {
+      try {
+        const result = await alasql.promise(`
+          SELECT * FROM ${threadsTable} WHERE threadId = ?
+        `, [threadId]) as ThreadData[];
+        
+        return result && result.length > 0 ? result[0] : null;
+      } catch (error) {
+        console.error("Failed to get thread:", error);
+        return null;
+      }
+    },
+
+    async getAllThreads() {
+      try {
+        const result = await alasql.promise(`
+          SELECT * FROM ${threadsTable} ORDER BY updatedAt DESC
+        `) as ThreadData[];
+        
+        return Array.isArray(result) ? result : [];
+      } catch (error) {
+        console.error("Failed to get threads:", error);
+        return [];
+      }
+    },
+
+    async deleteThread(threadId: string) {
+      try {
+        // Delete thread and all its messages
+        await alasql.promise(`DELETE FROM ${threadsTable} WHERE threadId = ?`, [threadId]);
+        await alasql.promise(`DELETE FROM ${messagesTable} WHERE threadId = ?`, [threadId]);
+      } catch (error) {
+        console.error("Failed to delete thread:", error);
+        throw error;
+      }
+    },
+
+    async saveMessage(message: MyMessage, threadId: string) {
+      try {
+        // Insert or replace message
+        await alasql.promise(`
+          DELETE FROM ${messagesTable} WHERE id = ?
+        `, [message.id]);
+        
+        await alasql.promise(`
+          INSERT INTO ${messagesTable} VALUES (?, ?, ?, ?, ?)
+        `, [message.id, threadId, message.role, message.text, message.timestamp]);
+      } catch (error) {
+        console.error("Failed to save message:", error);
+        throw error;
+      }
+    },
+
+    async saveMessages(messages: MyMessage[], threadId: string) {
+      try {
+        // Delete existing messages for this thread
+        await alasql.promise(`DELETE FROM ${messagesTable} WHERE threadId = ?`, [threadId]);
+        
+        // Insert all messages
+        for (const message of messages) {
+          await alasql.promise(`
+            INSERT INTO ${messagesTable} VALUES (?, ?, ?, ?, ?)
+          `, [message.id, threadId, message.role, message.text, message.timestamp]);
+        }
+      } catch (error) {
+        console.error("Failed to save messages:", error);
+        throw error;
+      }
+    },
+
+    async getMessages(threadId: string) {
+      try {
+        const result = await alasql.promise(`
+          SELECT id, role, text, timestamp FROM ${messagesTable} 
+          WHERE threadId = ? ORDER BY timestamp ASC
+        `, [threadId]) as MyMessage[];
+        
+        return Array.isArray(result) ? result : [];
+      } catch (error) {
+        console.error("Failed to get messages:", error);
+        return [];
+      }
+    },
+
+    async deleteMessages(threadId: string) {
+      try {
+        await alasql.promise(`DELETE FROM ${messagesTable} WHERE threadId = ?`, [threadId]);
+      } catch (error) {
+        console.error("Failed to delete messages:", error);
+        throw error;
+      }
+    },
+
+    async clearAllData() {
+      try {
+        await alasql.promise(`DELETE FROM ${threadsTable}`);
+        await alasql.promise(`DELETE FROM ${messagesTable}`);
+      } catch (error) {
+        console.error("Failed to clear all data:", error);
+        throw error;
+      }
+    },
+
+    async resetDatabase() {
+      try {
+        // Drop the entire database
+        await alasql.promise(`DROP LOCALSTORAGE DATABASE IF EXISTS ${dbName}`);
+        
+        // Reinitialize fresh
+        await this.initialize();
+        console.log(`✅ Database reset and reinitialized: ${dbName}`);
+      } catch (error) {
+        console.error("Failed to reset database:", error);
+        throw error;
+      }
+    }
+  };
+};
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/responseFactory.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/responseFactory.ts
new file mode 100644
index 0000000000..91d4793353
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/utils/responseFactory.ts
@@ -0,0 +1,27 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/utils/responseFactory.ts
+import { 
+    queryResponseHandler, 
+    directApiResponseHandler, 
+    mockResponseHandler 
+  } from './responseHandlers';
+  
+  export const createResponseHandler = (type: string, config: any) => {
+    const sendMessage = async (message: string) => {
+      switch (type) {
+        case "query":
+          return await queryResponseHandler(message, config);
+        
+        case "direct-api":
+        case "n8n":
+          return await directApiResponseHandler(message, config);
+        
+        case "mock":
+          return await mockResponseHandler(message, config);
+        
+        default:
+          throw new Error(`Unknown response type: ${type}`);
+      }
+    };
+    
+    return { sendMessage };
+  };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/responseHandlers.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/responseHandlers.ts
new file mode 100644
index 0000000000..ae384660cc
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/utils/responseHandlers.ts
@@ -0,0 +1,99 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/utils/responseHandlers.ts
+import { CompAction, routeByNameAction, executeQueryAction } from "lowcoder-core";
+import { getPromiseAfterDispatch } from "util/promiseUtils";
+
+// Query response handler (your current logic)
+export const queryResponseHandler = async (
+  message: string,
+  config: { chatQuery: string; dispatch?: (action: CompAction<any>) => void }
+) => {
+  const { chatQuery, dispatch } = config;
+  
+  // If no query selected or dispatch unavailable, fallback with mock response
+  if (!chatQuery || !dispatch) {
+    await new Promise((res) => setTimeout(res, 500));
+    return { content: "(mock) You typed: " + message };
+  }
+
+  try {
+    const result: any = await getPromiseAfterDispatch(
+      dispatch,
+      routeByNameAction(
+        chatQuery,
+        executeQueryAction({
+          // Send the user prompt as variable named 'prompt' by default
+          args: { prompt: { value: message } },
+        })
+      )
+    );
+
+    // Extract reply text from the query result
+    let reply: string;
+    if (typeof result === "string") {
+      reply = result;
+    } else if (result && typeof result === "object") {
+      reply =
+        (result as any).response ??
+        (result as any).message ??
+        (result as any).content ??
+        JSON.stringify(result);
+    } else {
+      reply = String(result);
+    }
+
+    return { content: reply };
+  } catch (e: any) {
+    throw new Error(e?.message || "Query execution failed");
+  }
+};
+
+// Direct API response handler (for bottom panel usage)
+export const directApiResponseHandler = async (
+  message: string,
+  config: { modelHost: string; systemPrompt: string; streaming?: boolean }
+) => {
+  const { modelHost, systemPrompt, streaming } = config;
+  
+  if (!modelHost) {
+    throw new Error("Model host is required for direct API calls");
+  }
+
+  try {
+    const response = await fetch(modelHost, {
+      method: 'POST',
+      headers: {
+        'Content-Type': 'application/json',
+      },
+      body: JSON.stringify({
+        message,
+        systemPrompt: systemPrompt || "You are a helpful assistant.",
+        streaming: streaming || false
+      })
+    });
+
+    if (!response.ok) {
+      throw new Error(`API call failed: ${response.status} ${response.statusText}`);
+    }
+
+    const data = await response.json();
+    
+    // Extract content from various possible response formats
+    const content = data.response || data.message || data.content || data.text || String(data);
+    
+    return { content };
+  } catch (error) {
+    throw new Error(`Direct API call failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
+  }
+};
+
+// Mock response handler (for testing)
+export const mockResponseHandler = async (
+  message: string,
+  config: { delay?: number; prefix?: string }
+) => {
+  const { delay = 1000, prefix = "Mock response" } = config;
+  
+  await new Promise(resolve => setTimeout(resolve, delay));
+  
+  return { content: `${prefix}: ${message}` };
+};
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx b/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
index d074696f19..8903ef2376 100644
--- a/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
+++ b/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
@@ -121,11 +121,15 @@ function Bottom(props: any) {
               <ChatView
                 tableName="LC_AI"
                 modelType="n8n"
-                // streaming={true}
-                // systemPrompt="You are a helpful assistant."
-                // agent={true}
-                // maxInteractions={10}
-                modelHost="http://192.168.100.59:5678/webhook/9a363e76-d3a5-46d1-98c3-4359f7106d33"
+                streaming={true}
+                systemPrompt="You are a helpful assistant."
+                agent={true}
+                maxInteractions={10}
+                modelHost="http://localhost:5678/webhook-test/9a363e76-d3a5-46d1-98c3-4359f7106d33"
+                // Required props that were missing:
+                text="Lowcoder AI Assistant"
+                chatQuery=""
+                currentMessage=""
               />
             </Flex>
           )}

From 56e5247bb8ec2fb3b3f00a855c5b96089fb70d7a Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Tue, 8 Jul 2025 22:51:15 +0500
Subject: [PATCH 39/54] setup sse http query

---
 .../src/components/ResCreatePanel.tsx         |  12 +-
 .../comps/queries/httpQuery/sseHttpQuery.tsx  | 435 ++++++++++++++++++
 .../src/constants/datasourceConstants.ts      |   1 +
 .../lowcoder/src/constants/queryConstants.ts  |   3 +
 .../packages/lowcoder/src/i18n/locales/en.ts  |   1 +
 .../lowcoder/src/util/bottomResUtils.tsx      |   2 +
 6 files changed, 453 insertions(+), 1 deletion(-)
 create mode 100644 client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx

diff --git a/client/packages/lowcoder/src/components/ResCreatePanel.tsx b/client/packages/lowcoder/src/components/ResCreatePanel.tsx
index 04ed9fb79b..e52ea93df0 100644
--- a/client/packages/lowcoder/src/components/ResCreatePanel.tsx
+++ b/client/packages/lowcoder/src/components/ResCreatePanel.tsx
@@ -13,7 +13,7 @@ import { BottomResTypeEnum } from "types/bottomRes";
 import { LargeBottomResIconWrapper } from "util/bottomResUtils";
 import type { PageType } from "../constants/pageConstants";
 import type { SizeType } from "antd/es/config-provider/SizeContext";
-import { Datasource } from "constants/datasourceConstants";
+import { Datasource, QUICK_SSE_HTTP_API_ID } from "constants/datasourceConstants";
 import {
   QUICK_GRAPHQL_ID,
   QUICK_REST_API_ID,
@@ -172,6 +172,7 @@ const ResButton = (props: {
         compType: "streamApi",
       },
     },
+
     alasql: {
       label: trans("query.quickAlasql"),
       type: BottomResTypeEnum.Query,
@@ -179,6 +180,14 @@ const ResButton = (props: {
         compType: "alasql",
       },
     },
+    sseHttpApi: { 
+      label: trans("query.quickSseHttpAPI"),
+      type: BottomResTypeEnum.Query,
+      extra: {
+        compType: "sseHttpApi",
+        dataSourceId: QUICK_SSE_HTTP_API_ID,
+      },
+    },
     graphql: {
       label: trans("query.quickGraphql"),
       type: BottomResTypeEnum.Query,
@@ -339,6 +348,7 @@ export function ResCreatePanel(props: ResCreateModalProps) {
               <DataSourceListWrapper $placement={placement}>
                 <ResButton size={buttonSize} identifier={"restApi"} onSelect={onSelect} />
                 <ResButton size={buttonSize} identifier={"streamApi"} onSelect={onSelect} />
+                <ResButton size={buttonSize} identifier={"sseHttpApi"} onSelect={onSelect} />
                 <ResButton size={buttonSize} identifier={"alasql"} onSelect={onSelect} />
                 <ResButton size={buttonSize} identifier={"graphql"} onSelect={onSelect} />
                 <DataSourceButton size={buttonSize} onClick={() => setCurlModalVisible(true)}>
diff --git a/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx b/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx
new file mode 100644
index 0000000000..126063d090
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx
@@ -0,0 +1,435 @@
+import { Dropdown, ValueFromOption } from "components/Dropdown";
+import { QueryConfigItemWrapper, QueryConfigLabel, QueryConfigWrapper } from "components/query";
+import { valueComp, withDefault } from "comps/generators";
+import { trans } from "i18n";
+import { includes } from "lodash";
+import { CompAction, MultiBaseComp } from "lowcoder-core";
+import { keyValueListControl } from "../../controls/keyValueListControl";
+import { ParamsJsonControl, ParamsStringControl } from "../../controls/paramsControl";
+import { withTypeAndChildrenAbstract } from "../../generators/withType";
+import { QueryResult } from "../queryComp";
+import { QUERY_EXECUTION_ERROR, QUERY_EXECUTION_OK } from "constants/queryConstants";
+import { JSONValue } from "util/jsonTypes";
+import {
+  HttpHeaderPropertyView,
+  HttpParametersPropertyView,
+  HttpPathPropertyView,
+} from "./httpQueryConstants";
+
+const BodyTypeOptions = [
+  { label: "JSON", value: "application/json" },
+  { label: "Raw", value: "text/plain" },
+  {
+    label: "x-www-form-urlencoded",
+    value: "application/x-www-form-urlencoded",
+  },
+  { label: "Form Data", value: "multipart/form-data" },
+  { label: "None", value: "none" },
+] as const;
+type BodyTypeValue = ValueFromOption<typeof BodyTypeOptions>;
+
+const HttpMethodOptions = [
+  { label: "GET", value: "GET" },
+  { label: "POST", value: "POST" },
+  { label: "PUT", value: "PUT" },
+  { label: "DELETE", value: "DELETE" },
+  { label: "PATCH", value: "PATCH" },
+  { label: "HEAD", value: "HEAD" },
+  { label: "OPTIONS", value: "OPTIONS" },
+  { label: "TRACE", value: "TRACE" },
+] as const;
+type HttpMethodValue = ValueFromOption<typeof HttpMethodOptions>;
+
+const CommandMap = {
+  "application/json": ParamsJsonControl,
+  "text/plain": ParamsStringControl,
+  "application/x-www-form-urlencoded": ParamsStringControl,
+  "multipart/form-data": ParamsStringControl,
+  none: ParamsStringControl,
+};
+
+const childrenMap = {
+  httpMethod: valueComp<HttpMethodValue>("GET"),
+  path: ParamsStringControl,
+  headers: withDefault(keyValueListControl(), [{ key: "", value: "" }]),
+  params: withDefault(keyValueListControl(), [{ key: "", value: "" }]),
+  bodyFormData: withDefault(
+    keyValueListControl(true, [
+      { label: trans("httpQuery.text"), value: "text" },
+      { label: trans("httpQuery.file"), value: "file" },
+    ] as const),
+    [{ key: "", value: "", type: "text" }]
+  ),
+};
+
+const SseHttpTmpQuery = withTypeAndChildrenAbstract(
+  CommandMap,
+  "none",
+  childrenMap,
+  "bodyType",
+  "body"
+);
+
+export class SseHttpQuery extends SseHttpTmpQuery {
+  private eventSource: EventSource | undefined;
+  private controller: AbortController | undefined;
+
+  isWrite(action: CompAction) {
+    return (
+      action.path.includes("httpMethod") && "value" in action && !includes(["GET"], action.value)
+    );
+  }
+
+  override getView() {
+    return async (props: {
+      args?: Record<string, unknown>;
+      callback?: (result: QueryResult) => void;
+    }): Promise<QueryResult> => {
+      const children = this.children;
+      
+      try {
+        const timer = performance.now();
+        
+        // Build the complete URL with parameters
+        const baseUrl = this.buildUrl(props.args);
+        const headers = this.buildHeaders(props.args);
+        const method = children.httpMethod.getView();
+        
+        // For GET requests, use EventSource API (standard SSE)
+        if (method === "GET") {
+          return this.handleEventSource(baseUrl, headers, props, timer);
+        } else {
+          // For POST/PUT/etc, use fetch with streaming response
+          return this.handleStreamingFetch(baseUrl, headers, method, props, timer);
+        }
+        
+      } catch (error) {
+        return this.createErrorResponse((error as Error).message);
+      }
+    };
+  }
+
+  private async handleEventSource(
+    url: string, 
+    headers: Record<string, string>, 
+    props: any, 
+    timer: number
+  ): Promise<QueryResult> {
+    return new Promise((resolve, reject) => {
+      // Clean up any existing connection
+      this.cleanup();
+      
+      this.eventSource = new EventSource(url);
+      
+      this.eventSource.onopen = () => {
+        resolve(this.createSuccessResponse("SSE connection established", timer));
+      };
+      
+      this.eventSource.onmessage = (event) => {
+        try {
+          const data = JSON.parse(event.data);
+          props.callback?.(this.createSuccessResponse(data));
+        } catch (error) {
+          // Handle non-JSON data
+          props.callback?.(this.createSuccessResponse(event.data));
+        }
+      };
+      
+      this.eventSource.onerror = (error) => {
+        this.cleanup();
+        reject(this.createErrorResponse("SSE connection error"));
+      };
+    });
+  }
+
+  private async handleStreamingFetch(
+    url: string, 
+    headers: Record<string, string>, 
+    method: string, 
+    props: any, 
+    timer: number
+  ): Promise<QueryResult> {
+    // Clean up any existing connection
+    this.cleanup();
+    
+    this.controller = new AbortController();
+    
+    const response = await fetch(url, {
+      method,
+      headers: {
+        ...headers,
+        'Accept': 'text/event-stream',
+        'Cache-Control': 'no-cache',
+      },
+      body: this.buildRequestBody(props.args),
+      signal: this.controller.signal,
+    });
+
+    if (!response.ok) {
+      throw new Error(`HTTP ${response.status}: ${response.statusText}`);
+    }
+
+    // Handle streaming response
+    const reader = response.body?.getReader();
+    const decoder = new TextDecoder();
+    
+    if (!reader) {
+      throw new Error("No readable stream available");
+    }
+
+    // Process stream in background
+    this.processStream(reader, decoder, props.callback);
+    
+    return this.createSuccessResponse("Stream connection established", timer);
+  }
+
+  private async processStream(
+    reader: ReadableStreamDefaultReader<Uint8Array>, 
+    decoder: TextDecoder, 
+    callback?: (result: QueryResult) => void
+  ) {
+    let buffer = '';
+    
+    try {
+      while (true) {
+        const { done, value } = await reader.read();
+        
+        if (done) break;
+        
+        buffer += decoder.decode(value, { stream: true });
+        
+        // Process complete JSON objects or SSE events
+        const lines = buffer.split('\n');
+        buffer = lines.pop() || '';
+        
+        for (const line of lines) {
+          if (line.trim()) {
+            try {
+              // Handle SSE format: data: {...}
+              let jsonData = line.trim();
+              if (jsonData.startsWith('data: ')) {
+                jsonData = jsonData.substring(6);
+              }
+              
+              // Skip SSE control messages
+              if (jsonData === '[DONE]' || jsonData.startsWith('event:') || jsonData.startsWith('id:')) {
+                continue;
+              }
+              
+              const data = JSON.parse(jsonData);
+              callback?.(this.createSuccessResponse(data));
+            } catch (error) {
+              // Handle non-JSON lines or plain text
+              if (line.trim() !== '') {
+                callback?.(this.createSuccessResponse(line.trim()));
+              }
+            }
+          }
+        }
+      }
+    } catch (error: any) {
+      if (error.name !== 'AbortError') {
+        callback?.(this.createErrorResponse((error as Error).message));
+      }
+    } finally {
+      reader.releaseLock();
+    }
+  }
+
+  private buildUrl(args?: Record<string, unknown>): string {
+    const children = this.children;
+    const basePath = children.path.children.text.getView();
+    const params = children.params.getView();
+    
+    // Build URL with parameters
+    const url = new URL(basePath);
+    params.forEach((param: any) => {
+      if (param.key && param.value) {
+        const value = typeof param.value === 'function' ? param.value(args) : param.value;
+        url.searchParams.append(param.key, String(value));
+      }
+    });
+    
+    return url.toString();
+  }
+
+  private buildHeaders(args?: Record<string, unknown>): Record<string, string> {
+    const headers: Record<string, string> = {};
+    
+    this.children.headers.getView().forEach((header: any) => {
+      if (header.key && header.value) {
+        const value = typeof header.value === 'function' ? header.value(args) : header.value;
+        headers[header.key] = String(value);
+      }
+    });
+    
+    return headers;
+  }
+
+  private buildRequestBody(args?: Record<string, unknown>): string | FormData | undefined {
+    const bodyType = this.children.bodyType.getView();
+    
+    switch (bodyType) {
+      case "application/json":
+        return this.children.body.children.text.getView() as string;
+      case "text/plain":
+        return this.children.body.children.text.getView() as string;
+      case "application/x-www-form-urlencoded":
+        const formData = new URLSearchParams();
+        this.children.bodyFormData.getView().forEach((item: any) => {
+          if (item.key && item.value) {
+            const value = typeof item.value === 'function' ? item.value(args) : item.value;
+            formData.append(item.key, String(value));
+          }
+        });
+        return formData.toString();
+      case "multipart/form-data":
+        const multipartData = new FormData();
+        this.children.bodyFormData.getView().forEach((item: any) => {
+          if (item.key && item.value) {
+            const value = typeof item.value === 'function' ? item.value(args) : item.value;
+            multipartData.append(item.key, String(value));
+          }
+        });
+        return multipartData;
+      default:
+        return undefined;
+    }
+  }
+
+  private createSuccessResponse(data: JSONValue, runTime?: number): QueryResult {
+    return {
+      data,
+      runTime: runTime || 0,
+      success: true,
+      code: QUERY_EXECUTION_OK,
+    };
+  }
+
+  private createErrorResponse(message: string): QueryResult {
+    return {
+      message,
+      data: "",
+      success: false,
+      code: QUERY_EXECUTION_ERROR,
+    };
+  }
+
+  public cleanup() {
+    if (this.eventSource) {
+      this.eventSource.close();
+      this.eventSource = undefined;
+    }
+    if (this.controller) {
+      this.controller.abort();
+      this.controller = undefined;
+    }
+  }
+
+  propertyView(props: {
+    datasourceId: string;
+    urlPlaceholder?: string;
+    supportHttpMethods?: HttpMethodValue[];
+    supportBodyTypes?: BodyTypeValue[];
+  }) {
+    return <SseHttpQueryPropertyView {...props} comp={this} />;
+  }
+
+  getHttpMethod() {
+    return this.children.httpMethod.getView();
+  }
+}
+
+type ChildrenType = InstanceType<typeof SseHttpQuery> extends MultiBaseComp<infer X> ? X : never;
+
+const ContentTypeKey = "Content-Type";
+
+const showBodyConfig = (children: ChildrenType) => {
+  switch (children.bodyType.getView() as BodyTypeValue) {
+    case "application/x-www-form-urlencoded":
+      return children.bodyFormData.propertyView({});
+    case "multipart/form-data":
+      return children.bodyFormData.propertyView({
+        showType: true,
+        typeTooltip: trans("httpQuery.bodyFormDataTooltip", {
+          type: `"${trans("httpQuery.file")}"`,
+          object: "{ data: base64 string, name: string }",
+          example: "{{ {data: file1.value[0], name: file1.files[0].name} }}",
+        }),
+      });
+    case "application/json":
+    case "text/plain":
+      return children.body.propertyView({ styleName: "medium", width: "100%" });
+    default:
+      return <></>;
+  }
+};
+
+const SseHttpQueryPropertyView = (props: {
+  comp: InstanceType<typeof SseHttpQuery>;
+  datasourceId: string;
+  urlPlaceholder?: string;
+  supportHttpMethods?: HttpMethodValue[];
+  supportBodyTypes?: BodyTypeValue[];
+}) => {
+  const { comp, supportHttpMethods, supportBodyTypes } = props;
+  const { children, dispatch } = comp;
+
+  return (
+    <>
+      <Dropdown
+        placement={"bottom"}
+        value={children.httpMethod.value}
+        options={HttpMethodOptions.filter(
+          (o) => !supportHttpMethods || supportHttpMethods.includes(o.value)
+        )}
+        label={"HTTP Method"}
+        onChange={(value: HttpMethodValue) => {
+          children.httpMethod.dispatchChangeValueAction(value);
+        }}
+      />
+
+      <HttpPathPropertyView 
+        {...props} 
+        comp={comp} 
+        urlPlaceholder={props.urlPlaceholder || "https://api.example.com/stream"}
+      />
+
+      <HttpHeaderPropertyView comp={comp} />
+
+      <HttpParametersPropertyView comp={comp} />
+
+      <Dropdown
+        label={"Body"}
+        placement={"bottom"}
+        options={BodyTypeOptions.filter(
+          (o) => !supportBodyTypes || supportBodyTypes?.includes(o.value)
+        )}
+        value={children.bodyType.getView()}
+        onChange={(value) => {
+          let headers = children.headers
+            .toJsonValue()
+            .filter((header) => header.key !== ContentTypeKey);
+          if (value !== "none") {
+            headers = [
+              {
+                key: ContentTypeKey,
+                value: value,
+              },
+              ...headers,
+            ];
+          }
+
+          dispatch(
+            comp.changeValueAction({ ...comp.toJsonValue(), bodyType: value, headers: headers })
+          );
+        }}
+      />
+
+      <QueryConfigWrapper>
+        <QueryConfigLabel />
+        <QueryConfigItemWrapper>{showBodyConfig(children)}</QueryConfigItemWrapper>
+      </QueryConfigWrapper>
+    </>
+  );
+};
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/constants/datasourceConstants.ts b/client/packages/lowcoder/src/constants/datasourceConstants.ts
index 0c65449f38..3d010f02fd 100644
--- a/client/packages/lowcoder/src/constants/datasourceConstants.ts
+++ b/client/packages/lowcoder/src/constants/datasourceConstants.ts
@@ -45,3 +45,4 @@ export const QUICK_REST_API_ID = "#QUICK_REST_API";
 export const QUICK_GRAPHQL_ID = "#QUICK_GRAPHQL";
 export const JS_CODE_ID = "#JS_CODE";
 export const OLD_LOWCODER_DATASOURCE: Partial<DatasourceType>[] = [];
+export const QUICK_SSE_HTTP_API_ID = "#QUICK_SSE_HTTP_API";
diff --git a/client/packages/lowcoder/src/constants/queryConstants.ts b/client/packages/lowcoder/src/constants/queryConstants.ts
index be78de0d6e..06de2507c2 100644
--- a/client/packages/lowcoder/src/constants/queryConstants.ts
+++ b/client/packages/lowcoder/src/constants/queryConstants.ts
@@ -14,12 +14,14 @@ import { toPluginQuery } from "comps/queries/pluginQuery/pluginQuery";
 import { MultiCompConstructor } from "lowcoder-core";
 import { DataSourcePluginMeta } from "lowcoder-sdk/dataSource";
 import { AlaSqlQuery } from "@lowcoder-ee/comps/queries/httpQuery/alasqlQuery";
+import { SseHttpQuery } from "@lowcoder-ee/comps/queries/httpQuery/sseHttpQuery";
 
 export type DatasourceType =
   | "mysql"
   | "mongodb"
   | "restApi"
   | "streamApi"
+  | "sseHttpApi"  
   | "postgres"
   | "redis"
   | "es"
@@ -41,6 +43,7 @@ export const QueryMap = {
   alasql: AlaSqlQuery,
   restApi: HttpQuery,
   streamApi: StreamQuery,
+  sseHttpApi: SseHttpQuery,
   mongodb: MongoQuery,
   postgres: SQLQuery,
   redis: RedisQuery,
diff --git a/client/packages/lowcoder/src/i18n/locales/en.ts b/client/packages/lowcoder/src/i18n/locales/en.ts
index 43bcb39868..b897add3f7 100644
--- a/client/packages/lowcoder/src/i18n/locales/en.ts
+++ b/client/packages/lowcoder/src/i18n/locales/en.ts
@@ -744,6 +744,7 @@ export const en = {
     "transformer": "Transformer",
     "quickRestAPI": "REST Query",
     "quickStreamAPI": "Stream Query",
+    "quickSseHttpAPI": "SSE HTTP Stream Query",
     "quickGraphql": "GraphQL Query",
     "quickAlasql": "Local SQL Query",
     "databaseType": "Database Type",
diff --git a/client/packages/lowcoder/src/util/bottomResUtils.tsx b/client/packages/lowcoder/src/util/bottomResUtils.tsx
index b2f2baf425..78c5a4de3e 100644
--- a/client/packages/lowcoder/src/util/bottomResUtils.tsx
+++ b/client/packages/lowcoder/src/util/bottomResUtils.tsx
@@ -110,6 +110,8 @@ export const getBottomResIcon = (
         return <MongoIcon />;
       case "streamApi":
         return <StreamApiIcon />;
+      case "sseHttpApi":
+        return <StreamApiIcon />;
       case "alasql":
         return <AlasqlIcon />;
       case "restApi":

From 4664b5b9f58575f9250475173fcdb36093fc6e19 Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Tue, 8 Jul 2025 23:08:41 +0500
Subject: [PATCH 40/54] fix linter errors

---
 .../comps/queries/httpQuery/sseHttpQuery.tsx  | 163 ++++++++++--------
 1 file changed, 91 insertions(+), 72 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx b/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx
index 126063d090..5584736c97 100644
--- a/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx
+++ b/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx
@@ -5,11 +5,12 @@ import { trans } from "i18n";
 import { includes } from "lodash";
 import { CompAction, MultiBaseComp } from "lowcoder-core";
 import { keyValueListControl } from "../../controls/keyValueListControl";
-import { ParamsJsonControl, ParamsStringControl } from "../../controls/paramsControl";
+import { ParamsJsonControl, ParamsStringControl, ParamsControlType } from "../../controls/paramsControl";
 import { withTypeAndChildrenAbstract } from "../../generators/withType";
 import { QueryResult } from "../queryComp";
 import { QUERY_EXECUTION_ERROR, QUERY_EXECUTION_OK } from "constants/queryConstants";
 import { JSONValue } from "util/jsonTypes";
+import { FunctionProperty } from "../queryCompUtils";
 import {
   HttpHeaderPropertyView,
   HttpParametersPropertyView,
@@ -81,26 +82,43 @@ export class SseHttpQuery extends SseHttpTmpQuery {
   }
 
   override getView() {
+    const children = this.children;
+    const params = [
+      ...children.headers.getQueryParams(),
+      ...children.params.getQueryParams(),
+      ...children.bodyFormData.getQueryParams(),
+      ...children.path.getQueryParams(),
+      ...children.body.getQueryParams(),
+    ];
+    
+    return this.createStreamingQueryView(params);
+  }
+
+  private createStreamingQueryView(params: FunctionProperty[]) {
     return async (props: {
+      queryId: string;
+      applicationId: string;
+      applicationPath: string[];
       args?: Record<string, unknown>;
+      variables?: any;
+      timeout: InstanceType<ParamsControlType>;
       callback?: (result: QueryResult) => void;
     }): Promise<QueryResult> => {
-      const children = this.children;
       
       try {
         const timer = performance.now();
         
-        // Build the complete URL with parameters
-        const baseUrl = this.buildUrl(props.args);
-        const headers = this.buildHeaders(props.args);
-        const method = children.httpMethod.getView();
+        // Process parameters like toQueryView does
+        const processedParams = this.processParameters(params, props);
+        
+        // Build request from processed parameters
+        const { url, headers, method, body } = this.buildRequestFromParams(processedParams);
         
-        // For GET requests, use EventSource API (standard SSE)
+        // Execute streaming logic
         if (method === "GET") {
-          return this.handleEventSource(baseUrl, headers, props, timer);
+          return this.handleEventSource(url, headers, props, timer);
         } else {
-          // For POST/PUT/etc, use fetch with streaming response
-          return this.handleStreamingFetch(baseUrl, headers, method, props, timer);
+          return this.handleStreamingFetch(url, headers, method, body, props, timer);
         }
         
       } catch (error) {
@@ -109,6 +127,67 @@ export class SseHttpQuery extends SseHttpTmpQuery {
     };
   }
 
+  private processParameters(params: FunctionProperty[], props: any) {
+    let mappedVariables: Array<{key: string, value: string}> = [];
+    Object.keys(props.variables || {})
+      .filter(k => k !== "$queryName")
+      .forEach(key => {
+        const value = Object.hasOwn(props.variables[key], 'value') ? props.variables[key].value : props.variables[key];
+        mappedVariables.push({
+          key: `${key}.value`,
+          value: value || ""
+        });
+      });
+
+    return [
+      ...params.filter(param => {
+        return !mappedVariables.map(v => v.key).includes(param.key);
+      }).map(({ key, value }) => ({ key, value: value(props.args) })),
+      ...Object.entries(props.timeout.getView()).map(([key, value]) => ({
+        key,
+        value: (value as any)(props.args),
+      })),
+      ...mappedVariables,
+    ];
+  }
+
+  private buildRequestFromParams(processedParams: Array<{key: string, value: any}>) {
+    debugger;
+    const paramMap = new Map(processedParams.map(p => [p.key, p.value]));
+    
+    // Extract URL
+    const baseUrl = paramMap.get('path') || '';
+    const url = new URL(baseUrl);
+    
+    // Add query parameters
+    Object.entries(paramMap).forEach(([key, value]) => {
+      if (key.startsWith('params.') && key.endsWith('.value')) {
+        const paramName = key.replace('params.', '').replace('.value', '');
+        if (value) url.searchParams.append(paramName, String(value));
+      }
+    });
+
+    // Build headers
+    const headers: Record<string, string> = {};
+    Object.entries(paramMap).forEach(([key, value]) => {
+      if (key.startsWith('headers.') && key.endsWith('.value')) {
+        const headerName = key.replace('headers.', '').replace('.value', '');
+        if (value) headers[headerName] = String(value);
+      }
+    });
+
+    // Get method and body
+    const method = paramMap.get('httpMethod') || 'GET';
+    const bodyType = paramMap.get('bodyType');
+    let body: string | FormData | undefined;
+    
+    if (bodyType === 'application/json' || bodyType === 'text/plain') {
+      body = paramMap.get('body') as string;
+    }
+
+    return { url: url.toString(), headers, method, body };
+  }
+
   private async handleEventSource(
     url: string, 
     headers: Record<string, string>, 
@@ -146,6 +225,7 @@ export class SseHttpQuery extends SseHttpTmpQuery {
     url: string, 
     headers: Record<string, string>, 
     method: string, 
+    body: string | FormData | undefined,
     props: any, 
     timer: number
   ): Promise<QueryResult> {
@@ -161,7 +241,7 @@ export class SseHttpQuery extends SseHttpTmpQuery {
         'Accept': 'text/event-stream',
         'Cache-Control': 'no-cache',
       },
-      body: this.buildRequestBody(props.args),
+      body,
       signal: this.controller.signal,
     });
 
@@ -236,67 +316,6 @@ export class SseHttpQuery extends SseHttpTmpQuery {
     }
   }
 
-  private buildUrl(args?: Record<string, unknown>): string {
-    const children = this.children;
-    const basePath = children.path.children.text.getView();
-    const params = children.params.getView();
-    
-    // Build URL with parameters
-    const url = new URL(basePath);
-    params.forEach((param: any) => {
-      if (param.key && param.value) {
-        const value = typeof param.value === 'function' ? param.value(args) : param.value;
-        url.searchParams.append(param.key, String(value));
-      }
-    });
-    
-    return url.toString();
-  }
-
-  private buildHeaders(args?: Record<string, unknown>): Record<string, string> {
-    const headers: Record<string, string> = {};
-    
-    this.children.headers.getView().forEach((header: any) => {
-      if (header.key && header.value) {
-        const value = typeof header.value === 'function' ? header.value(args) : header.value;
-        headers[header.key] = String(value);
-      }
-    });
-    
-    return headers;
-  }
-
-  private buildRequestBody(args?: Record<string, unknown>): string | FormData | undefined {
-    const bodyType = this.children.bodyType.getView();
-    
-    switch (bodyType) {
-      case "application/json":
-        return this.children.body.children.text.getView() as string;
-      case "text/plain":
-        return this.children.body.children.text.getView() as string;
-      case "application/x-www-form-urlencoded":
-        const formData = new URLSearchParams();
-        this.children.bodyFormData.getView().forEach((item: any) => {
-          if (item.key && item.value) {
-            const value = typeof item.value === 'function' ? item.value(args) : item.value;
-            formData.append(item.key, String(value));
-          }
-        });
-        return formData.toString();
-      case "multipart/form-data":
-        const multipartData = new FormData();
-        this.children.bodyFormData.getView().forEach((item: any) => {
-          if (item.key && item.value) {
-            const value = typeof item.value === 'function' ? item.value(args) : item.value;
-            multipartData.append(item.key, String(value));
-          }
-        });
-        return multipartData;
-      default:
-        return undefined;
-    }
-  }
-
   private createSuccessResponse(data: JSONValue, runTime?: number): QueryResult {
     return {
       data,

From 188f9cbf906f69d3b10197ac6cfcd4e28ce06c8b Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Tue, 8 Jul 2025 23:51:31 +0500
Subject: [PATCH 41/54] setup http streaming with dummy data

---
 .../comps/queries/httpQuery/sseHttpQuery.tsx  | 49 ++++++-------------
 1 file changed, 15 insertions(+), 34 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx b/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx
index 5584736c97..11341e096e 100644
--- a/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx
+++ b/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx
@@ -112,7 +112,7 @@ export class SseHttpQuery extends SseHttpTmpQuery {
         const processedParams = this.processParameters(params, props);
         
         // Build request from processed parameters
-        const { url, headers, method, body } = this.buildRequestFromParams(processedParams);
+        const { url, headers, method, body } = this.buildRequestFromParams(processedParams, props.args);
         
         // Execute streaming logic
         if (method === "GET") {
@@ -151,41 +151,23 @@ export class SseHttpQuery extends SseHttpTmpQuery {
     ];
   }
 
-  private buildRequestFromParams(processedParams: Array<{key: string, value: any}>) {
-    debugger;
-    const paramMap = new Map(processedParams.map(p => [p.key, p.value]));
-    
-    // Extract URL
-    const baseUrl = paramMap.get('path') || '';
-    const url = new URL(baseUrl);
-    
-    // Add query parameters
-    Object.entries(paramMap).forEach(([key, value]) => {
-      if (key.startsWith('params.') && key.endsWith('.value')) {
-        const paramName = key.replace('params.', '').replace('.value', '');
-        if (value) url.searchParams.append(paramName, String(value));
-      }
-    });
-
-    // Build headers
-    const headers: Record<string, string> = {};
-    Object.entries(paramMap).forEach(([key, value]) => {
-      if (key.startsWith('headers.') && key.endsWith('.value')) {
-        const headerName = key.replace('headers.', '').replace('.value', '');
-        if (value) headers[headerName] = String(value);
-      }
+  private buildRequestFromParams(processedParams: Array<{key: string, value: any}>, args: Record<string, unknown> = {}) {
+    // Hardcoded values from the screenshot for testing
+    const url = "http://localhost:11434/api/generate";
+    const headers = {
+      "Content-Type": "application/json",
+      "Accept": "text/event-stream"
+    };
+    const method = "POST";
+    const body = JSON.stringify({
+      "model": "gemma3",
+      "prompt": "Tell me a short story about a robot",
+      "stream": true
     });
 
-    // Get method and body
-    const method = paramMap.get('httpMethod') || 'GET';
-    const bodyType = paramMap.get('bodyType');
-    let body: string | FormData | undefined;
+    console.log("Hardcoded request:", { url, headers, method, body });
     
-    if (bodyType === 'application/json' || bodyType === 'text/plain') {
-      body = paramMap.get('body') as string;
-    }
-
-    return { url: url.toString(), headers, method, body };
+    return { url, headers, method, body };
   }
 
   private async handleEventSource(
@@ -239,7 +221,6 @@ export class SseHttpQuery extends SseHttpTmpQuery {
       headers: {
         ...headers,
         'Accept': 'text/event-stream',
-        'Cache-Control': 'no-cache',
       },
       body,
       signal: this.controller.signal,

From 7b6858163a66848c7c837c580131ca1aa873da6f Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Wed, 9 Jul 2025 17:25:31 +0500
Subject: [PATCH 42/54] setup frontend for ssehttpquery

---
 .../comps/queries/httpQuery/sseHttpQuery.tsx  | 271 ++-----------
 .../src/comps/queries/queryCompUtils.tsx      | 361 +++++++++++++++++-
 .../src/constants/datasourceConstants.ts      |   2 +-
 3 files changed, 390 insertions(+), 244 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx b/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx
index 11341e096e..2271f582ef 100644
--- a/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx
+++ b/client/packages/lowcoder/src/comps/queries/httpQuery/sseHttpQuery.tsx
@@ -1,3 +1,4 @@
+// SSEHTTPQUERY.tsx
 import { Dropdown, ValueFromOption } from "components/Dropdown";
 import { QueryConfigItemWrapper, QueryConfigLabel, QueryConfigWrapper } from "components/query";
 import { valueComp, withDefault } from "comps/generators";
@@ -5,12 +6,9 @@ import { trans } from "i18n";
 import { includes } from "lodash";
 import { CompAction, MultiBaseComp } from "lowcoder-core";
 import { keyValueListControl } from "../../controls/keyValueListControl";
-import { ParamsJsonControl, ParamsStringControl, ParamsControlType } from "../../controls/paramsControl";
+import { ParamsJsonControl, ParamsStringControl } from "../../controls/paramsControl";
 import { withTypeAndChildrenAbstract } from "../../generators/withType";
-import { QueryResult } from "../queryComp";
-import { QUERY_EXECUTION_ERROR, QUERY_EXECUTION_OK } from "constants/queryConstants";
-import { JSONValue } from "util/jsonTypes";
-import { FunctionProperty } from "../queryCompUtils";
+import { toSseQueryView } from "../queryCompUtils";
 import {
   HttpHeaderPropertyView,
   HttpParametersPropertyView,
@@ -52,7 +50,9 @@ const CommandMap = {
 const childrenMap = {
   httpMethod: valueComp<HttpMethodValue>("GET"),
   path: ParamsStringControl,
-  headers: withDefault(keyValueListControl(), [{ key: "", value: "" }]),
+  headers: withDefault(keyValueListControl(), [
+    { key: "Accept", value: "text/event-stream" }
+  ]),
   params: withDefault(keyValueListControl(), [{ key: "", value: "" }]),
   bodyFormData: withDefault(
     keyValueListControl(true, [
@@ -61,6 +61,8 @@ const childrenMap = {
     ] as const),
     [{ key: "", value: "", type: "text" }]
   ),
+  // Add SSE-specific configuration
+  streamingEnabled: valueComp<boolean>(true),
 };
 
 const SseHttpTmpQuery = withTypeAndChildrenAbstract(
@@ -72,9 +74,6 @@ const SseHttpTmpQuery = withTypeAndChildrenAbstract(
 );
 
 export class SseHttpQuery extends SseHttpTmpQuery {
-  private eventSource: EventSource | undefined;
-  private controller: AbortController | undefined;
-
   isWrite(action: CompAction) {
     return (
       action.path.includes("httpMethod") && "value" in action && !includes(["GET"], action.value)
@@ -89,241 +88,13 @@ export class SseHttpQuery extends SseHttpTmpQuery {
       ...children.bodyFormData.getQueryParams(),
       ...children.path.getQueryParams(),
       ...children.body.getQueryParams(),
+      // Add streaming flag to params
+      { key: "_streaming", value: () => "true" },
+      { key: "_streamingEnabled", value: () => children.streamingEnabled.getView() }
     ];
     
-    return this.createStreamingQueryView(params);
-  }
-
-  private createStreamingQueryView(params: FunctionProperty[]) {
-    return async (props: {
-      queryId: string;
-      applicationId: string;
-      applicationPath: string[];
-      args?: Record<string, unknown>;
-      variables?: any;
-      timeout: InstanceType<ParamsControlType>;
-      callback?: (result: QueryResult) => void;
-    }): Promise<QueryResult> => {
-      
-      try {
-        const timer = performance.now();
-        
-        // Process parameters like toQueryView does
-        const processedParams = this.processParameters(params, props);
-        
-        // Build request from processed parameters
-        const { url, headers, method, body } = this.buildRequestFromParams(processedParams, props.args);
-        
-        // Execute streaming logic
-        if (method === "GET") {
-          return this.handleEventSource(url, headers, props, timer);
-        } else {
-          return this.handleStreamingFetch(url, headers, method, body, props, timer);
-        }
-        
-      } catch (error) {
-        return this.createErrorResponse((error as Error).message);
-      }
-    };
-  }
-
-  private processParameters(params: FunctionProperty[], props: any) {
-    let mappedVariables: Array<{key: string, value: string}> = [];
-    Object.keys(props.variables || {})
-      .filter(k => k !== "$queryName")
-      .forEach(key => {
-        const value = Object.hasOwn(props.variables[key], 'value') ? props.variables[key].value : props.variables[key];
-        mappedVariables.push({
-          key: `${key}.value`,
-          value: value || ""
-        });
-      });
-
-    return [
-      ...params.filter(param => {
-        return !mappedVariables.map(v => v.key).includes(param.key);
-      }).map(({ key, value }) => ({ key, value: value(props.args) })),
-      ...Object.entries(props.timeout.getView()).map(([key, value]) => ({
-        key,
-        value: (value as any)(props.args),
-      })),
-      ...mappedVariables,
-    ];
-  }
-
-  private buildRequestFromParams(processedParams: Array<{key: string, value: any}>, args: Record<string, unknown> = {}) {
-    // Hardcoded values from the screenshot for testing
-    const url = "http://localhost:11434/api/generate";
-    const headers = {
-      "Content-Type": "application/json",
-      "Accept": "text/event-stream"
-    };
-    const method = "POST";
-    const body = JSON.stringify({
-      "model": "gemma3",
-      "prompt": "Tell me a short story about a robot",
-      "stream": true
-    });
-
-    console.log("Hardcoded request:", { url, headers, method, body });
-    
-    return { url, headers, method, body };
-  }
-
-  private async handleEventSource(
-    url: string, 
-    headers: Record<string, string>, 
-    props: any, 
-    timer: number
-  ): Promise<QueryResult> {
-    return new Promise((resolve, reject) => {
-      // Clean up any existing connection
-      this.cleanup();
-      
-      this.eventSource = new EventSource(url);
-      
-      this.eventSource.onopen = () => {
-        resolve(this.createSuccessResponse("SSE connection established", timer));
-      };
-      
-      this.eventSource.onmessage = (event) => {
-        try {
-          const data = JSON.parse(event.data);
-          props.callback?.(this.createSuccessResponse(data));
-        } catch (error) {
-          // Handle non-JSON data
-          props.callback?.(this.createSuccessResponse(event.data));
-        }
-      };
-      
-      this.eventSource.onerror = (error) => {
-        this.cleanup();
-        reject(this.createErrorResponse("SSE connection error"));
-      };
-    });
-  }
-
-  private async handleStreamingFetch(
-    url: string, 
-    headers: Record<string, string>, 
-    method: string, 
-    body: string | FormData | undefined,
-    props: any, 
-    timer: number
-  ): Promise<QueryResult> {
-    // Clean up any existing connection
-    this.cleanup();
-    
-    this.controller = new AbortController();
-    
-    const response = await fetch(url, {
-      method,
-      headers: {
-        ...headers,
-        'Accept': 'text/event-stream',
-      },
-      body,
-      signal: this.controller.signal,
-    });
-
-    if (!response.ok) {
-      throw new Error(`HTTP ${response.status}: ${response.statusText}`);
-    }
-
-    // Handle streaming response
-    const reader = response.body?.getReader();
-    const decoder = new TextDecoder();
-    
-    if (!reader) {
-      throw new Error("No readable stream available");
-    }
-
-    // Process stream in background
-    this.processStream(reader, decoder, props.callback);
-    
-    return this.createSuccessResponse("Stream connection established", timer);
-  }
-
-  private async processStream(
-    reader: ReadableStreamDefaultReader<Uint8Array>, 
-    decoder: TextDecoder, 
-    callback?: (result: QueryResult) => void
-  ) {
-    let buffer = '';
-    
-    try {
-      while (true) {
-        const { done, value } = await reader.read();
-        
-        if (done) break;
-        
-        buffer += decoder.decode(value, { stream: true });
-        
-        // Process complete JSON objects or SSE events
-        const lines = buffer.split('\n');
-        buffer = lines.pop() || '';
-        
-        for (const line of lines) {
-          if (line.trim()) {
-            try {
-              // Handle SSE format: data: {...}
-              let jsonData = line.trim();
-              if (jsonData.startsWith('data: ')) {
-                jsonData = jsonData.substring(6);
-              }
-              
-              // Skip SSE control messages
-              if (jsonData === '[DONE]' || jsonData.startsWith('event:') || jsonData.startsWith('id:')) {
-                continue;
-              }
-              
-              const data = JSON.parse(jsonData);
-              callback?.(this.createSuccessResponse(data));
-            } catch (error) {
-              // Handle non-JSON lines or plain text
-              if (line.trim() !== '') {
-                callback?.(this.createSuccessResponse(line.trim()));
-              }
-            }
-          }
-        }
-      }
-    } catch (error: any) {
-      if (error.name !== 'AbortError') {
-        callback?.(this.createErrorResponse((error as Error).message));
-      }
-    } finally {
-      reader.releaseLock();
-    }
-  }
-
-  private createSuccessResponse(data: JSONValue, runTime?: number): QueryResult {
-    return {
-      data,
-      runTime: runTime || 0,
-      success: true,
-      code: QUERY_EXECUTION_OK,
-    };
-  }
-
-  private createErrorResponse(message: string): QueryResult {
-    return {
-      message,
-      data: "",
-      success: false,
-      code: QUERY_EXECUTION_ERROR,
-    };
-  }
-
-  public cleanup() {
-    if (this.eventSource) {
-      this.eventSource.close();
-      this.eventSource = undefined;
-    }
-    if (this.controller) {
-      this.controller.abort();
-      this.controller = undefined;
-    }
+    // Use SSE-specific query view
+    return toSseQueryView(params);
   }
 
   propertyView(props: {
@@ -410,6 +181,13 @@ const SseHttpQueryPropertyView = (props: {
           let headers = children.headers
             .toJsonValue()
             .filter((header) => header.key !== ContentTypeKey);
+          
+          // Always ensure Accept: text/event-stream for SSE
+          const hasAcceptHeader = headers.some(h => h.key === "Accept");
+          if (!hasAcceptHeader) {
+            headers.push({ key: "Accept", value: "text/event-stream" });
+          }
+          
           if (value !== "none") {
             headers = [
               {
@@ -430,6 +208,15 @@ const SseHttpQueryPropertyView = (props: {
         <QueryConfigLabel />
         <QueryConfigItemWrapper>{showBodyConfig(children)}</QueryConfigItemWrapper>
       </QueryConfigWrapper>
+      
+      <QueryConfigWrapper>
+        <QueryConfigLabel>Streaming Options</QueryConfigLabel>
+        <QueryConfigItemWrapper>
+          <div style={{ fontSize: "13px", color: "#8B8FA3" }}>
+            This query will establish a Server-Sent Events connection for real-time data streaming.
+          </div>
+        </QueryConfigItemWrapper>
+      </QueryConfigWrapper>
     </>
   );
 };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/queries/queryCompUtils.tsx b/client/packages/lowcoder/src/comps/queries/queryCompUtils.tsx
index bf49517af0..87f3926bc8 100644
--- a/client/packages/lowcoder/src/comps/queries/queryCompUtils.tsx
+++ b/client/packages/lowcoder/src/comps/queries/queryCompUtils.tsx
@@ -82,7 +82,7 @@ export function toQueryView(params: FunctionProperty[]) {
         }).map(({ key, value }) => ({ key, value: value(props.args) })),
         ...Object.entries(props.timeout.getView()).map(([key, value]) => ({
           key,
-          value: value(props.args),
+          value: (value as ValueFunction)(props.args),
         })),
         ...mappedVariables,
       ],
@@ -143,3 +143,362 @@ export function onlyManualTrigger(type: ResourceType) {
 export function getTriggerType(comp: any): TriggerType {
   return comp.children.triggerType.getView();
 }
+
+// STREAMING QUERY
+
+export interface SseQueryResult extends QueryResult {
+  streamId?: string;
+  isStreaming?: boolean;
+}
+
+export interface SseQueryViewProps {
+  queryId: string;
+  applicationId: string;
+  applicationPath: string[];
+  args?: Record<string, unknown>;
+  variables?: any;
+  timeout: any;
+  onStreamData?: (data: any) => void;
+  onStreamError?: (error: any) => void;
+  onStreamEnd?: () => void;
+}
+
+/**
+ * SSE-specific query view that handles streaming responses
+ */
+export function toSseQueryView(params: FunctionProperty[]) {
+  // Store active connections
+  const activeConnections = new Map<string, EventSource>();
+  
+  return async (props: SseQueryViewProps): Promise<SseQueryResult> => {
+    const { applicationId, isViewMode } = getGlobalSettings();
+    
+    // Process parameters similar to toQueryView
+    let mappedVariables: Array<{key: string, value: string}> = [];
+    Object.keys(props.variables || {})
+      .filter(k => k !== "$queryName")
+      .forEach(key => {
+        const value = Object.hasOwn(props.variables[key], 'value') 
+          ? props.variables[key].value 
+          : props.variables[key];
+        mappedVariables.push({
+          key: `${key}.value`,
+          value: value || ""
+        });
+        mappedVariables.push({
+          key: `${props.args?.$queryName}.variables.${key}`,
+          value: value || ""
+        });
+      });
+
+    let request: QueryExecuteRequest = {
+      path: props.applicationPath,
+      params: [
+        ...params.filter(param => {
+          return !mappedVariables.map(v => v.key).includes(param.key);
+        }).map(({ key, value }) => ({ key, value: value(props.args) })),
+        ...Object.entries(props.timeout.getView()).map(([key, value]) => ({
+          key,
+          value: (value as ValueFunction)(props.args),
+        })),
+        ...mappedVariables,
+      ],
+      viewMode: !!isViewMode,
+    };
+    
+    if (!applicationId) {
+      request = { ...request, libraryQueryId: props.queryId, libraryQueryRecordId: "latest" };
+    } else {
+      request = { ...request, applicationId: props.applicationId, queryId: props.queryId };
+    }
+
+    try {
+      // For SSE queries, we need a different approach
+      // Option 1: If your backend supports SSE proxying
+      const streamId = `sse_${props.queryId}_${Date.now()}`;
+      
+      // First, initiate the SSE connection through your backend
+      const initResponse = await QueryApi.executeQuery(
+        {
+          ...request,
+          // Add SSE-specific flags
+          params: [
+            ...(request.params || []),
+            { key: "_sseInit", value: "true" },
+            { key: "_streamId", value: streamId }
+          ]
+        },
+        props.timeout.children.text.getView() as number
+      );
+
+      if (!initResponse.data.success) {
+        return {
+          ...initResponse.data,
+          code: initResponse.data.queryCode,
+          extra: _.omit(initResponse.data, ["code", "message", "data", "success", "runTime", "queryCode"]),
+        };
+      }
+
+      // Get the SSE endpoint from backend response
+      const sseEndpoint = (initResponse.data.data as any)?.sseEndpoint;
+      
+      if (sseEndpoint) {
+        // Establish SSE connection
+        establishSseConnection(
+          streamId,
+          sseEndpoint,
+          props.onStreamData,
+          props.onStreamError,
+          props.onStreamEnd,
+          activeConnections
+        );
+        
+        return {
+          ...initResponse.data,
+          code: QUERY_EXECUTION_OK,
+          streamId,
+          isStreaming: true,
+          extra: {
+            ..._.omit(initResponse.data, ["code", "message", "data", "success", "runTime", "queryCode"]),
+            streamId,
+            closeStream: () => closeSseConnection(streamId, activeConnections)
+          }
+        };
+      }
+
+      // Fallback to regular response if SSE not available
+      return {
+        ...initResponse.data,
+        code: initResponse.data.queryCode,
+        extra: _.omit(initResponse.data, ["code", "message", "data", "success", "runTime", "queryCode"]),
+      };
+      
+    } catch (error) {
+      return {
+        success: false,
+        data: "",
+        code: QUERY_EXECUTION_ERROR,
+        message: (error as any).message || "Failed to execute SSE query",
+      };
+    }
+  };
+}
+
+function establishSseConnection(
+  streamId: string,
+  endpoint: string,
+  onData?: (data: any) => void,
+  onError?: (error: any) => void,
+  onEnd?: () => void,
+  connections?: Map<string, EventSource>
+) {
+  // Close any existing connection with the same ID
+  if (connections?.has(streamId)) {
+    connections.get(streamId)?.close();
+  }
+  
+  const eventSource = new EventSource(endpoint);
+  
+  eventSource.onmessage = (event) => {
+    try {
+      const data = JSON.parse(event.data);
+      onData?.(data);
+    } catch (error) {
+      // Handle non-JSON data
+      onData?.(event.data);
+    }
+  };
+  
+  eventSource.onerror = (error) => {
+    onError?.(error);
+    eventSource.close();
+    connections?.delete(streamId);
+    onEnd?.();
+  };
+  
+  eventSource.onopen = () => {
+    console.log(`SSE connection established: ${streamId}`);
+  };
+  
+  // Store the connection
+  connections?.set(streamId, eventSource);
+}
+
+function closeSseConnection(streamId: string, connections?: Map<string, EventSource>) {
+  const eventSource = connections?.get(streamId);
+  if (eventSource) {
+    eventSource.close();
+    connections?.delete(streamId);
+    console.log(`SSE connection closed: ${streamId}`);
+  }
+}
+
+// Alternative implementation using fetch with ReadableStream
+export function toSseQueryViewWithFetch(params: FunctionProperty[]) {
+  const activeControllers = new Map<string, AbortController>();
+  
+  return async (props: SseQueryViewProps): Promise<SseQueryResult> => {
+    const { applicationId, isViewMode } = getGlobalSettings();
+    
+    // Similar parameter processing as above...
+    let mappedVariables: Array<{key: string, value: string}> = [];
+    Object.keys(props.variables || {})
+      .filter(k => k !== "$queryName")
+      .forEach(key => {
+        const value = Object.hasOwn(props.variables[key], 'value') 
+          ? props.variables[key].value 
+          : props.variables[key];
+        mappedVariables.push({
+          key: `${key}.value`,
+          value: value || ""
+        });
+      });
+
+    const processedParams = [
+      ...params.filter(param => {
+        return !mappedVariables.map(v => v.key).includes(param.key);
+      }).map(({ key, value }) => ({ key, value: value(props.args) })),
+      ...Object.entries(props.timeout.getView()).map(([key, value]) => ({
+        key,
+        value: (value as ValueFunction)(props.args),
+      })),
+      ...mappedVariables,
+    ];
+
+    // Build the request configuration from params
+    const config = buildRequestConfig(processedParams);
+    
+    const streamId = `fetch_${props.queryId}_${Date.now()}`;
+    const controller = new AbortController();
+    activeControllers.set(streamId, controller);
+    
+    try {
+      const response = await fetch(config.url, {
+        method: config.method,
+        headers: config.headers,
+        body: config.body,
+        signal: controller.signal,
+      });
+
+      if (!response.ok) {
+        throw new Error(`HTTP ${response.status}: ${response.statusText}`);
+      }
+
+      // Process the stream
+      if (response.body) {
+        processStream(
+          response.body,
+          props.onStreamData,
+          props.onStreamError,
+          props.onStreamEnd
+        );
+      }
+
+      return {
+        success: true,
+        data: { message: "Stream started" },
+        code: QUERY_EXECUTION_OK,
+        streamId,
+        isStreaming: true,
+        runTime: 0,
+        extra: {
+          streamId,
+          closeStream: () => {
+            controller.abort();
+            activeControllers.delete(streamId);
+          }
+        }
+      };
+      
+    } catch (error) {
+      activeControllers.delete(streamId);
+      return {
+        success: false,
+        data: "",
+        code: QUERY_EXECUTION_ERROR,
+        message: (error as any).message || "Failed to establish stream",
+      };
+    }
+  };
+}
+
+function buildRequestConfig(params: Array<{key: string, value: any}>) {
+  const config: any = {
+    url: "",
+    method: "GET",
+    headers: {},
+    body: undefined,
+  };
+  
+  params.forEach(param => {
+    if (param.key === "url" || param.key === "path") {
+      config.url = param.value;
+    } else if (param.key === "method") {
+      config.method = param.value;
+    } else if (param.key.startsWith("header.")) {
+      const headerName = param.key.substring(7);
+      config.headers[headerName] = param.value;
+    } else if (param.key === "body") {
+      config.body = param.value;
+    }
+  });
+  
+  return config;
+}
+
+async function processStream(
+  readableStream: ReadableStream<Uint8Array>,
+  onData?: (data: any) => void,
+  onError?: (error: any) => void,
+  onEnd?: () => void
+) {
+  const reader = readableStream.getReader();
+  const decoder = new TextDecoder();
+  let buffer = '';
+  
+  try {
+    while (true) {
+      const { done, value } = await reader.read();
+      
+      if (done) {
+        onEnd?.();
+        break;
+      }
+      
+      buffer += decoder.decode(value, { stream: true });
+      
+      // Process complete lines
+      const lines = buffer.split('\n');
+      buffer = lines.pop() || '';
+      
+      for (const line of lines) {
+        if (line.trim()) {
+          try {
+            // Handle SSE format
+            let data = line.trim();
+            if (data.startsWith('data: ')) {
+              data = data.substring(6);
+            }
+            
+            // Skip control messages
+            if (data === '[DONE]' || data.startsWith('event:') || data.startsWith('id:')) {
+              continue;
+            }
+            
+            const jsonData = JSON.parse(data);
+            onData?.(jsonData);
+          } catch (error) {
+            // Handle non-JSON lines
+            if (line.trim() !== '') {
+              onData?.(line.trim());
+            }
+          }
+        }
+      }
+    }
+  } catch (error) {
+    onError?.(error);
+  } finally {
+    reader.releaseLock();
+  }
+}
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/constants/datasourceConstants.ts b/client/packages/lowcoder/src/constants/datasourceConstants.ts
index 3d010f02fd..31094d43df 100644
--- a/client/packages/lowcoder/src/constants/datasourceConstants.ts
+++ b/client/packages/lowcoder/src/constants/datasourceConstants.ts
@@ -45,4 +45,4 @@ export const QUICK_REST_API_ID = "#QUICK_REST_API";
 export const QUICK_GRAPHQL_ID = "#QUICK_GRAPHQL";
 export const JS_CODE_ID = "#JS_CODE";
 export const OLD_LOWCODER_DATASOURCE: Partial<DatasourceType>[] = [];
-export const QUICK_SSE_HTTP_API_ID = "#QUICK_SSE_HTTP_API";
+export const QUICK_SSE_HTTP_API_ID = "#QUICK_REST_API";

From cf0b99c1acb5219fa78db7750c2d119f0eb19948 Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Thu, 10 Jul 2025 17:57:02 +0500
Subject: [PATCH 43/54] chat component refactor

---
 .../src/comps/comps/chatComp/chatComp.tsx     | 144 +++-
 .../src/comps/comps/chatComp/chatCompTypes.ts |  57 +-
 .../comps/comps/chatComp/chatPropertyView.tsx | 101 ++-
 .../src/comps/comps/chatComp/chatView.tsx     |  46 --
 .../comps/chatComp/components/ChatApp.tsx     |  43 -
 .../comps/chatComp/components/ChatCore.tsx    |  21 +
 .../chatComp/components/ChatCoreMain.tsx      | 246 ++++++
 .../comps/chatComp/components/ChatMain.tsx    | 381 ---------
 .../comps/chatComp/components/ChatPanel.tsx   |  47 ++
 .../components/context/ChatContext.tsx        | 763 +++++++++---------
 .../chatComp/handlers/messageHandlers.ts      | 133 +++
 .../comps/comps/chatComp/types/chatTypes.ts   |  86 ++
 .../comps/comps/chatComp/utils/chatStorage.ts | 281 -------
 .../comps/chatComp/utils/responseFactory.ts   |  27 -
 .../comps/chatComp/utils/responseHandlers.ts  |  99 ---
 ...hatStorageFactory.ts => storageFactory.ts} | 370 +++++----
 .../src/pages/editor/bottom/BottomPanel.tsx   | 298 +++----
 17 files changed, 1453 insertions(+), 1690 deletions(-)
 delete mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
 delete mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
 delete mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
 delete mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorage.ts
 delete mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/utils/responseFactory.ts
 delete mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/utils/responseHandlers.ts
 rename client/packages/lowcoder/src/comps/comps/chatComp/utils/{chatStorageFactory.ts => storageFactory.ts} (81%)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
index 921ed80830..ac32527bf8 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
@@ -1,29 +1,117 @@
-// client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
-import { UICompBuilder } from "comps/generators";
-import { NameConfig, withExposingConfigs } from "comps/generators/withExposing";
-import { chatChildrenMap } from "./chatCompTypes";
-import { ChatView } from "./chatView";
-import { ChatPropertyView } from "./chatPropertyView";
-import { useEffect, useState } from "react";
-import { changeChildAction } from "lowcoder-core";
-
-// Build the component
-const ChatTmpComp = new UICompBuilder(
-  chatChildrenMap,
-  (props, dispatch) => (
-    <ChatView
-      {...props}
-      chatQuery={props.chatQuery.value}
-      currentMessage={props.currentMessage.value}
-      dispatch={dispatch}
-    />
-  )
-)
-  .setPropertyViewFn((children) => <ChatPropertyView children={children} />)
-  .build();
-
-// Export the component with exposed variables
-export const ChatComp = withExposingConfigs(ChatTmpComp, [
-  new NameConfig("text", "Chat component text"),
-  new NameConfig("currentMessage", "Current user message"),
+// client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
+
+import { UICompBuilder } from "comps/generators";
+import { NameConfig, withExposingConfigs } from "comps/generators/withExposing";
+import { StringControl } from "comps/controls/codeControl";
+import { stringExposingStateControl } from "comps/controls/codeStateControl";
+import { withDefault } from "comps/generators";
+import { BoolControl } from "comps/controls/boolControl";
+import { dropdownControl } from "comps/controls/dropdownControl";
+import QuerySelectControl from "comps/controls/querySelectControl";
+import { ChatCore } from "./components/ChatCore";
+import { ChatPropertyView } from "./chatPropertyView";
+import { createChatStorage } from "./utils/storageFactory";
+import { QueryHandler, createMessageHandler } from "./handlers/messageHandlers";
+import { useMemo } from "react";
+import { changeChildAction } from "lowcoder-core";
+
+import "@assistant-ui/styles/index.css";
+import "@assistant-ui/styles/markdown.css";
+
+// ============================================================================
+// SIMPLIFIED CHILDREN MAP - ONLY ESSENTIAL PROPS
+// ============================================================================
+
+const ModelTypeOptions = [
+  { label: "Query", value: "query" },
+  { label: "N8N Workflow", value: "n8n" },
+] as const;
+
+export const chatChildrenMap = {
+  // Storage
+  tableName: withDefault(StringControl, "default"),
+  
+  // Message Handler Configuration
+  handlerType: dropdownControl(ModelTypeOptions, "query"),
+  chatQuery: QuerySelectControl,                    // Only used for "query" type
+  modelHost: withDefault(StringControl, ""),        // Only used for "n8n" type
+  systemPrompt: withDefault(StringControl, "You are a helpful assistant."),
+  streaming: BoolControl.DEFAULT_TRUE,
+  
+  // UI Configuration  
+  placeholder: withDefault(StringControl, "Chat Component"),
+  
+  // Exposed Variables (not shown in Property View)
+  currentMessage: stringExposingStateControl("currentMessage", ""),
+};
+
+// ============================================================================
+// CLEAN CHATCOMP - USES NEW ARCHITECTURE
+// ============================================================================
+
+const ChatTmpComp = new UICompBuilder(
+  chatChildrenMap,
+  (props, dispatch) => {
+    // Create storage from tableName
+    const storage = useMemo(() => 
+      createChatStorage(props.tableName), 
+      [props.tableName]
+    );
+    
+    // Create message handler based on type
+    const messageHandler = useMemo(() => {
+      const handlerType = props.handlerType;
+      
+      if (handlerType === "query") {
+        return new QueryHandler({
+          chatQuery: props.chatQuery.value,
+          dispatch,
+          streaming: props.streaming
+        });
+      } else if (handlerType === "n8n") {
+        return createMessageHandler("n8n", {
+          modelHost: props.modelHost,
+          systemPrompt: props.systemPrompt,
+          streaming: props.streaming
+        });
+      } else {
+        // Fallback to mock handler
+        return createMessageHandler("mock", {
+          chatQuery: props.chatQuery.value,
+          dispatch,
+          streaming: props.streaming
+        });
+      }
+    }, [
+      props.handlerType,
+      props.chatQuery, 
+      props.modelHost,
+      props.systemPrompt,
+      props.streaming,
+      dispatch
+    ]);
+
+    // Handle message updates for exposed variable
+    const handleMessageUpdate = (message: string) => {
+      dispatch(changeChildAction("currentMessage", message, false));
+    };
+
+    return (
+      <ChatCore
+        storage={storage}
+        messageHandler={messageHandler}
+        onMessageUpdate={handleMessageUpdate}
+      />
+    );
+  }
+)
+.setPropertyViewFn((children) => <ChatPropertyView children={children} />)
+.build();
+
+// ============================================================================
+// EXPORT WITH EXPOSED VARIABLES
+// ============================================================================
+
+export const ChatComp = withExposingConfigs(ChatTmpComp, [
+  new NameConfig("currentMessage", "Current user message"),
 ]);
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
index 5c55744712..3151bff6ad 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
@@ -1,41 +1,26 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatCompTypes.ts
-import { StringControl, NumberControl } from "comps/controls/codeControl";
-import { stringExposingStateControl } from "comps/controls/codeStateControl";
-import { withDefault } from "comps/generators";
-import { BoolControl } from "comps/controls/boolControl";
-import { dropdownControl } from "comps/controls/dropdownControl";
-import QuerySelectControl from "comps/controls/querySelectControl";
-import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl";
 
-// Model type dropdown options
-const ModelTypeOptions = [
-  { label: "Direct LLM", value: "direct-llm" },
-  { label: "n8n Workflow", value: "n8n" },
-  { label: "Query", value: "query" },
-] as const;
-
-export const chatChildrenMap = {
-  text: withDefault(StringControl, "Chat Component Placeholder"),
-  chatQuery: QuerySelectControl,
-  currentMessage: stringExposingStateControl("currentMessage", ""),
-  modelType: dropdownControl(ModelTypeOptions, "query"),
-  modelHost: withDefault(StringControl, ""),
-  streaming: BoolControl.DEFAULT_TRUE,
-  systemPrompt: withDefault(StringControl, "You are a helpful assistant."),
-  agent: BoolControl,
-  maxInteractions: withDefault(NumberControl, 10),
-  tableName: withDefault(StringControl, "default"),
-};
+// ============================================================================
+// CLEAN CHATCOMP TYPES - SIMPLIFIED AND FOCUSED
+// ============================================================================
 
 export type ChatCompProps = {
-  text: string;
-  chatQuery: string;
-  currentMessage: string;
-  modelType: string;
-  modelHost: string;
-  streaming: boolean;
-  systemPrompt: string;
-  agent: boolean;
-  maxInteractions: number;
+  // Storage
   tableName: string;
-};
\ No newline at end of file
+  
+  // Message Handler
+  handlerType: "query" | "n8n";
+  chatQuery: string;        // Only used when handlerType === "query"
+  modelHost: string;        // Only used when handlerType === "n8n"
+  systemPrompt: string;
+  streaming: boolean;
+  
+  // UI
+  placeholder: string;
+  
+  // Exposed Variables
+  currentMessage: string;   // Read-only exposed variable
+};
+
+// Legacy export for backwards compatibility (if needed)
+export type ChatCompLegacyProps = ChatCompProps;
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
index a5b3f52493..784ef44b56 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
@@ -1,34 +1,69 @@
-// client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
-import React from "react";
-import { Section, sectionNames } from "lowcoder-design";
-import { trans } from "i18n";
-
-export const ChatPropertyView = React.memo((props: any) => {
-  const { children } = props;
-
-  return (
-    <Section name={sectionNames.basic}>
-      {children.text.propertyView({ label: "Text" })}
-      {children.chatQuery.propertyView({ label: "Chat Query" })}
-      {children.currentMessage.propertyView({ 
-        label: "Current Message (Dynamic)", 
-        placeholder: "Shows the current user message",
-        disabled: true 
-      })}
-      {children.modelType.propertyView({ label: "Model Type" })}
-      {children.streaming.propertyView({ label: "Enable Streaming" })}
-      {children.systemPrompt.propertyView({ 
-        label: "System Prompt",
-        placeholder: "Enter system prompt...",
-        enableSpellCheck: false,
-      })}
-      {children.agent.propertyView({ label: "Enable Agent Mode" })}
-      {children.maxInteractions.propertyView({ 
-        label: "Max Interactions",
-        placeholder: "10",
-      })}
-    </Section>
-  );
-});
-
+// client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
+
+import React from "react";
+import { Section, sectionNames } from "lowcoder-design";
+
+// ============================================================================
+// CLEAN PROPERTY VIEW - FOCUSED ON ESSENTIAL CONFIGURATION
+// ============================================================================
+
+export const ChatPropertyView = React.memo((props: any) => {
+  const { children } = props;
+
+  return (
+    <>
+      {/* Basic Configuration */}
+      <Section name={sectionNames.basic}>
+        {children.placeholder.propertyView({ 
+          label: "Placeholder Text",
+          placeholder: "Enter placeholder text..."
+        })}
+        
+        {children.tableName.propertyView({ 
+          label: "Storage Table",
+          placeholder: "default",
+          tooltip: "Storage identifier - use same value to share conversations between components"
+        })}
+      </Section>
+
+      {/* Message Handler Configuration */}
+      <Section name="Message Handler">
+        {children.handlerType.propertyView({ 
+          label: "Handler Type",
+          tooltip: "How messages are processed"
+        })}
+        
+        {/* Show chatQuery field only for "query" handler */}
+        {children.handlerType.value === "query" && (
+          children.chatQuery.propertyView({ 
+            label: "Chat Query",
+            placeholder: "Select a query to handle messages"
+          })
+        )}
+        
+        {/* Show modelHost field only for "n8n" handler */}
+        {children.handlerType.value === "n8n" && (
+          children.modelHost.propertyView({ 
+            label: "N8N Webhook URL",
+            placeholder: "http://localhost:5678/webhook/...",
+            tooltip: "N8N webhook endpoint for processing messages"
+          })
+        )}
+        
+        {children.systemPrompt.propertyView({ 
+          label: "System Prompt",
+          placeholder: "You are a helpful assistant...",
+          tooltip: "Initial instructions for the AI"
+        })}
+        
+        {children.streaming.propertyView({ 
+          label: "Enable Streaming",
+          tooltip: "Stream responses in real-time (when supported)"
+        })}
+      </Section>
+
+    </>
+  );
+});
+
 ChatPropertyView.displayName = 'ChatPropertyView';
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
deleted file mode 100644
index 544e73e8d3..0000000000
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-// client/packages/lowcoder/src/comps/comps/chatComp/chatView.tsx
-import React, { useMemo } from "react";
-import { ChatCompProps } from "./chatCompTypes";
-import { CompAction } from "lowcoder-core";
-import { ChatApp } from "./components/ChatApp";
-import { createChatStorage } from './utils/chatStorageFactory';
-
-import "@assistant-ui/styles/index.css";
-import "@assistant-ui/styles/markdown.css";
-
-// Extend the props we receive so we can forward the redux dispatch
-interface ChatViewProps extends ChatCompProps {
-  dispatch?: (action: CompAction<any>) => void;
-}
-
-export const ChatView = React.memo((props: ChatViewProps) => {
-  const { 
-    chatQuery, 
-    currentMessage, 
-    dispatch,
-    modelType,
-    modelHost,
-    systemPrompt,
-    streaming,
-    tableName
-  } = props;
-
-  // Create storage instance based on tableName
-  const storage = useMemo(() => createChatStorage(tableName || "default"), [tableName]);
-
-  return (
-    <ChatApp 
-      chatQuery={chatQuery} 
-      currentMessage={currentMessage} 
-      dispatch={dispatch}
-      modelType={modelType}
-      modelHost={modelHost}
-      systemPrompt={systemPrompt}
-      streaming={streaming}
-      tableName={tableName}
-      storage={storage}
-    />
-  );
-});
-
-ChatView.displayName = 'ChatView';
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
deleted file mode 100644
index 12ee0071f5..0000000000
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatApp.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-import { ChatProvider } from "./context/ChatContext";
-import { ChatMain } from "./ChatMain";
-import { CompAction } from "lowcoder-core";
-import { createChatStorage } from "../utils/chatStorageFactory";
-
-interface ChatAppProps {
-  chatQuery: string;
-  currentMessage: string;
-  dispatch?: (action: CompAction<any>) => void;
-  modelType: string;
-  modelHost?: string;
-  systemPrompt?: string;
-  streaming?: boolean;
-  tableName: string;
-  storage: ReturnType<typeof createChatStorage>;
-}
-
-export function ChatApp({ 
-  chatQuery, 
-  currentMessage, 
-  dispatch, 
-  modelType, 
-  modelHost, 
-  systemPrompt, 
-  streaming,
-  tableName,
-  storage 
-}: ChatAppProps) {
-  return (
-    <ChatProvider storage={storage}>
-      <ChatMain 
-        chatQuery={chatQuery} 
-        currentMessage={currentMessage} 
-        dispatch={dispatch}
-        modelType={modelType}
-        modelHost={modelHost}
-        systemPrompt={systemPrompt}
-        streaming={streaming}
-        tableName={tableName}
-      />
-    </ChatProvider>
-  );
-}
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx
new file mode 100644
index 0000000000..c40151dd5b
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx
@@ -0,0 +1,21 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx
+
+import React from "react";
+import { ChatProvider } from "./context/ChatContext";
+import { ChatCoreMain } from "./ChatCoreMain";
+import { ChatCoreProps } from "../types/chatTypes";
+
+// ============================================================================
+// CHAT CORE - THE SHARED FOUNDATION
+// ============================================================================
+
+export function ChatCore({ storage, messageHandler, onMessageUpdate }: ChatCoreProps) {
+  return (
+    <ChatProvider storage={storage}>
+      <ChatCoreMain 
+        messageHandler={messageHandler}
+        onMessageUpdate={onMessageUpdate}
+      />
+    </ChatProvider>
+  );
+}
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
new file mode 100644
index 0000000000..1459d00e54
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
@@ -0,0 +1,246 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
+
+import React, { useState } from "react";
+import {
+  useExternalStoreRuntime,
+  ThreadMessageLike,
+  AppendMessage,
+  AssistantRuntimeProvider,
+  ExternalStoreThreadListAdapter,
+} from "@assistant-ui/react";
+import { Thread } from "./assistant-ui/thread";
+import { ThreadList } from "./assistant-ui/thread-list";
+import { 
+  useChatContext, 
+  ChatMessage, 
+  RegularThreadData, 
+  ArchivedThreadData 
+} from "./context/ChatContext";
+import { MessageHandler } from "../types/chatTypes";
+import styled from "styled-components";
+
+// ============================================================================
+// STYLED COMPONENTS (same as your current ChatMain)
+// ============================================================================
+
+const ChatContainer = styled.div`
+  display: flex;
+  height: 500px;
+
+  p {
+    margin: 0;
+  }
+
+  .aui-thread-list-root {
+    width: 250px;
+    background-color: #fff;
+    padding: 10px;
+  }
+
+  .aui-thread-root {
+    flex: 1;
+    background-color: #f9fafb;
+  }
+
+  .aui-thread-list-item {
+    cursor: pointer;
+    transition: background-color 0.2s ease;
+
+    &[data-active="true"] {
+      background-color: #dbeafe;
+      border: 1px solid #bfdbfe;
+    }
+  }
+`;
+
+// ============================================================================
+// CHAT CORE MAIN - CLEAN PROPS, FOCUSED RESPONSIBILITY
+// ============================================================================
+
+interface ChatCoreMainProps {
+  messageHandler: MessageHandler;
+  onMessageUpdate?: (message: string) => void;
+}
+
+const generateId = () => Math.random().toString(36).substr(2, 9);
+
+export function ChatCoreMain({ messageHandler, onMessageUpdate }: ChatCoreMainProps) {
+  const { state, actions } = useChatContext();
+  const [isRunning, setIsRunning] = useState(false);
+
+  console.log("CHAT CORE STATE", state);
+
+  // Get messages for current thread
+  const currentMessages = actions.getCurrentMessages();
+
+  // Convert custom format to ThreadMessageLike (same as your current implementation)
+  const convertMessage = (message: ChatMessage): ThreadMessageLike => ({
+    role: message.role,
+    content: [{ type: "text", text: message.text }],
+    id: message.id,
+    createdAt: new Date(message.timestamp),
+  });
+
+  // Handle new message - MUCH CLEANER with messageHandler
+  const onNew = async (message: AppendMessage) => {
+    // Extract text from AppendMessage content array
+    if (message.content.length !== 1 || message.content[0]?.type !== "text") {
+      throw new Error("Only text content is supported");
+    }
+
+    // Add user message in custom format
+    const userMessage: ChatMessage = {
+      id: generateId(),
+      role: "user",
+      text: message.content[0].text,
+      timestamp: Date.now(),
+    };
+    
+    // Update currentMessage state to expose to queries
+    onMessageUpdate?.(userMessage.text);
+    
+    // Update current thread with new user message
+    await actions.addMessage(state.currentThreadId, userMessage);
+    setIsRunning(true);
+
+    try {
+      // Use the message handler (no more complex logic here!)
+      const response = await messageHandler.sendMessage(userMessage.text);
+      
+      const assistantMessage: ChatMessage = {
+        id: generateId(),
+        role: "assistant",
+        text: response.content,
+        timestamp: Date.now(),
+      };
+      
+      // Update current thread with assistant response
+      await actions.addMessage(state.currentThreadId, assistantMessage);
+    } catch (error) {
+      // Handle errors gracefully
+      const errorMessage: ChatMessage = {
+        id: generateId(),
+        role: "assistant", 
+        text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
+        timestamp: Date.now(),
+      };
+      
+      await actions.addMessage(state.currentThreadId, errorMessage);
+    } finally {
+      setIsRunning(false);
+    }
+  };
+
+  // Handle edit message - CLEANER with messageHandler
+  const onEdit = async (message: AppendMessage) => {
+    // Extract text from AppendMessage content array
+    if (message.content.length !== 1 || message.content[0]?.type !== "text") {
+      throw new Error("Only text content is supported");
+    }
+
+    // Find the index where to insert the edited message
+    const index = currentMessages.findIndex((m) => m.id === message.parentId) + 1;
+
+    // Keep messages up to the parent
+    const newMessages = [...currentMessages.slice(0, index)];
+
+    // Add the edited message in custom format
+    const editedMessage: ChatMessage = {
+      id: generateId(),
+      role: "user",
+      text: message.content[0].text,
+      timestamp: Date.now(),
+    };
+    newMessages.push(editedMessage);
+
+    // Update currentMessage state to expose to queries
+    onMessageUpdate?.(editedMessage.text);
+
+    // Update messages using the new context action
+    await actions.updateMessages(state.currentThreadId, newMessages);
+    setIsRunning(true);
+
+    try {
+      // Use the message handler (clean!)
+      const response = await messageHandler.sendMessage(editedMessage.text);
+      
+      const assistantMessage: ChatMessage = {
+        id: generateId(),
+        role: "assistant",
+        text: response.content,
+        timestamp: Date.now(),
+      };
+      
+      newMessages.push(assistantMessage);
+      await actions.updateMessages(state.currentThreadId, newMessages);
+    } catch (error) {
+      // Handle errors gracefully
+      const errorMessage: ChatMessage = {
+        id: generateId(),
+        role: "assistant", 
+        text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
+        timestamp: Date.now(),
+      };
+      
+      newMessages.push(errorMessage);
+      await actions.updateMessages(state.currentThreadId, newMessages);
+    } finally {
+      setIsRunning(false);
+    }
+  };
+
+  // Thread list adapter for managing multiple threads (same as your current implementation)
+  const threadListAdapter: ExternalStoreThreadListAdapter = {
+    threadId: state.currentThreadId,
+    threads: state.threadList.filter((t): t is RegularThreadData => t.status === "regular"),
+    archivedThreads: state.threadList.filter((t): t is ArchivedThreadData => t.status === "archived"),
+
+    onSwitchToNewThread: async () => {
+      const threadId = await actions.createThread("New Chat");
+      actions.setCurrentThread(threadId);
+    },
+
+    onSwitchToThread: (threadId) => {
+      actions.setCurrentThread(threadId);
+    },
+
+    onRename: async (threadId, newTitle) => {
+      await actions.updateThread(threadId, { title: newTitle });
+    },
+
+    onArchive: async (threadId) => {
+      await actions.updateThread(threadId, { status: "archived" });
+    },
+
+    onDelete: async (threadId) => {
+      await actions.deleteThread(threadId);
+    },
+  };
+
+  const runtime = useExternalStoreRuntime({
+    messages: currentMessages,
+    setMessages: (messages) => {
+      actions.updateMessages(state.currentThreadId, messages);
+    },
+    convertMessage,
+    isRunning,
+    onNew,
+    onEdit,
+    adapters: {
+      threadList: threadListAdapter,
+    },
+  });
+
+  if (!state.isInitialized) {
+    return <div>Loading...</div>;
+  }
+
+  return (
+    <AssistantRuntimeProvider runtime={runtime}>
+      <ChatContainer>
+        <ThreadList />
+        <Thread />
+      </ChatContainer>
+    </AssistantRuntimeProvider>
+  );
+}
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
deleted file mode 100644
index 3359c75806..0000000000
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatMain.tsx
+++ /dev/null
@@ -1,381 +0,0 @@
-import React, { useContext, useState, useRef, useEffect } from "react";
-import {
-  useExternalStoreRuntime,
-  ThreadMessageLike,
-  AppendMessage,
-  AssistantRuntimeProvider,
-  ExternalStoreThreadListAdapter,
-} from "@assistant-ui/react";
-import { Thread } from "./assistant-ui/thread";
-import { ThreadList } from "./assistant-ui/thread-list";
-import { 
-  useChatContext, 
-  MyMessage, 
-  ThreadData, 
-  RegularThreadData, 
-  ArchivedThreadData 
-} from "./context/ChatContext";
-import styled from "styled-components";
-import { routeByNameAction, executeQueryAction, CompAction, changeChildAction } from "lowcoder-core";
-import { getPromiseAfterDispatch } from "util/promiseUtils";
-// ADD THIS IMPORT:
-import { createResponseHandler } from '../utils/responseFactory';
-import { useMemo } from 'react'; // if not already imported
-
-const ChatContainer = styled.div<{ $autoHeight?: boolean }>`
-  display: flex;
-  height: ${props => props.$autoHeight ? '500px' : '100%'};
-
-  p {
-    margin: 0;
-  }
-
-  .aui-thread-list-root {
-    width: 250px;
-    background-color: #fff;
-    padding: 10px;
-  }
-
-  .aui-thread-root {
-    flex: 1;
-    background-color: #f9fafb;
-  }
-
-  .aui-thread-list-item {
-    cursor: pointer;
-    transition: background-color 0.2s ease;
-
-    &[data-active="true"] {
-      background-color: #dbeafe;
-      border: 1px solid #bfdbfe;
-    }
-  }
-`;
-
-const generateId = () => Math.random().toString(36).substr(2, 9);
-
-// Helper to call the Lowcoder query system
-const callQuery = async (
-  queryName: string,
-  prompt: string,
-  dispatch?: (action: CompAction<any>) => void
-) => {
-  // If no query selected or dispatch unavailable, fallback with mock response
-  if (!queryName || !dispatch) {
-    await new Promise((res) => setTimeout(res, 500));
-    return { content: "(mock) You typed: " + prompt };
-  }
-
-  try {
-    const result: any = await getPromiseAfterDispatch(
-      dispatch,
-      routeByNameAction(
-        queryName,
-        executeQueryAction({
-          // Send the user prompt as variable named 'prompt' by default
-          args: { prompt: { value: prompt } },
-        })
-      )
-    );
-
-    // Extract reply text from the query result
-    let reply: string;
-    if (typeof result === "string") {
-      reply = result;
-    } else if (result && typeof result === "object") {
-      reply =
-        (result as any).response ??
-        (result as any).message ??
-        (result as any).content ??
-        JSON.stringify(result);
-    } else {
-      reply = String(result);
-    }
-
-    return { content: reply };
-  } catch (e: any) {
-    throw new Error(e?.message || "Query execution failed");
-  }
-};
-
-// AFTER:
-interface ChatMainProps {
-  chatQuery: string;
-  currentMessage: string;
-  dispatch?: (action: CompAction<any>) => void;
-  // Add new props for response handling
-  modelType: string;
-  modelHost?: string;
-  systemPrompt?: string;
-  streaming?: boolean;
-  tableName: string;
-}
-
-export function ChatMain({ 
-  chatQuery, 
-  currentMessage, 
-  dispatch, 
-  modelType, 
-  modelHost, 
-  systemPrompt, 
-  streaming,
-  tableName  }: ChatMainProps) {
-  const { state, actions } = useChatContext();
-  const [isRunning, setIsRunning] = useState(false);
-  const editorState = useContext(EditorContext);
-  const editorStateRef = useRef(editorState);
-
-  // Keep the ref updated with the latest editorState
-  useEffect(() => {
-    // console.log("EDITOR STATE CHANGE ---> ", editorState);
-    editorStateRef.current = editorState;
-  }, [editorState]);
-
-// Create response handler based on model type
-const responseHandler = useMemo(() => {
-  const responseType = modelType === "n8n" ? "direct-api" : "query";
-  
-  return createResponseHandler(responseType, {
-    // Query handler config
-    chatQuery,
-    dispatch,
-    // Direct API handler config  
-    modelHost,
-    systemPrompt,
-    streaming
-  });
-}, [modelType, chatQuery, dispatch, modelHost, systemPrompt, streaming]);
-
-  console.log("STATE", state);
-
-  // Get messages for current thread
-  const currentMessages = actions.getCurrentMessages();
-
-  // Convert custom format to ThreadMessageLike
-  const convertMessage = (message: MyMessage): ThreadMessageLike => ({
-    role: message.role,
-    content: [{ type: "text", text: message.text }],
-    id: message.id,
-    createdAt: new Date(message.timestamp),
-  });
-
-  const performAction = async (actions: any[]) => {
-    const comp = editorStateRef.current.getUIComp().children.comp;
-    if (!comp) {
-      console.error("No comp found");
-      return;
-    }
-    // const layout = comp.children.layout.getView();
-    // console.log("LAYOUT", layout);
-
-    for (const actionItem of actions) {
-      const { action, component, ...action_payload } = actionItem;
-
-      switch (action) {
-        case "place_component":
-          await addComponentAction.execute({
-            actionKey: action,
-            actionValue: "",
-            actionPayload: action_payload,
-            selectedComponent: component,
-            selectedEditorComponent: null,
-            selectedNestComponent: null,
-            editorState: editorStateRef.current
-          });
-          break;
-        case "nest_component":
-          await nestComponentAction.execute({
-            actionKey: action,
-            actionValue: "",
-            actionPayload: action_payload,
-            selectedComponent: component,
-            selectedEditorComponent: null,
-            selectedNestComponent: null,
-            editorState: editorStateRef.current
-          });
-          break;
-        case "set_properties":
-          debugger;
-          await configureComponentAction.execute({
-            actionKey: action,
-            actionValue: component,
-            actionPayload: action_payload,
-            selectedEditorComponent: null,
-            selectedComponent: null,
-            selectedNestComponent: null,
-            editorState: editorStateRef.current
-          });
-          break;
-        default:
-          break;
-      }
-      await new Promise(resolve => setTimeout(resolve, 1000));
-    }
-  };
-
-  const onNew = async (message: AppendMessage) => {
-    // Extract text from AppendMessage content array
-    if (message.content.length !== 1 || message.content[0]?.type !== "text") {
-      throw new Error("Only text content is supported");
-    }
-
-    // Add user message in custom format
-    const userMessage: MyMessage = {
-      id: generateId(),
-      role: "user",
-      text: message.content[0].text,
-      timestamp: Date.now(),
-    };
-    
-    // Update currentMessage state to expose to queries
-    if (dispatch) {
-      dispatch(changeChildAction("currentMessage", userMessage.text, false));
-    }
-    
-    // Update current thread with new user message
-    await actions.addMessage(state.currentThreadId, userMessage);
-    setIsRunning(true);
-
-    try {
-      // Call selected query / fallback to mock
-      const response = await responseHandler.sendMessage(userMessage.text);
-      
-      const assistantMessage: MyMessage = {
-        id: generateId(),
-        role: "assistant",
-        text: reply,
-        timestamp: Date.now(),
-      };
-      
-      // Update current thread with assistant response
-      await actions.addMessage(state.currentThreadId, assistantMessage);
-    } catch (error) {
-      // Handle errors gracefully
-      const errorMessage: MyMessage = {
-        id: generateId(),
-        role: "assistant", 
-        text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
-        timestamp: Date.now(),
-      };
-      
-      await actions.addMessage(state.currentThreadId, errorMessage);
-    } finally {
-      setIsRunning(false);
-    }
-  };
-
-  // Add onEdit functionality
-  const onEdit = async (message: AppendMessage) => {
-    // Extract text from AppendMessage content array
-    if (message.content.length !== 1 || message.content[0]?.type !== "text") {
-      throw new Error("Only text content is supported");
-    }
-
-    // Find the index where to insert the edited message
-    const index = currentMessages.findIndex((m) => m.id === message.parentId) + 1;
-
-    // Keep messages up to the parent
-    const newMessages = [...currentMessages.slice(0, index)];
-
-    // Add the edited message in custom format
-    const editedMessage: MyMessage = {
-      id: generateId(),
-      role: "user",
-      text: message.content[0].text,
-      timestamp: Date.now(),
-    };
-    newMessages.push(editedMessage);
-
-    // Update currentMessage state to expose to queries
-    if (dispatch) {
-      dispatch(changeChildAction("currentMessage", editedMessage.text, false));
-    }
-
-    // Update messages using the new context action
-    await actions.updateMessages(state.currentThreadId, newMessages);
-    setIsRunning(true);
-
-    try {
-      const response = await responseHandler.sendMessage(editedMessage.text);
-      
-      const assistantMessage: MyMessage = {
-        id: generateId(),
-        role: "assistant",
-        text: reply,
-        timestamp: Date.now(),
-      };
-      
-      newMessages.push(assistantMessage);
-      await actions.updateMessages(state.currentThreadId, newMessages);
-    } catch (error) {
-      // Handle errors gracefully
-      const errorMessage: MyMessage = {
-        id: generateId(),
-        role: "assistant", 
-        text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
-        timestamp: Date.now(),
-      };
-      
-      newMessages.push(errorMessage);
-      await actions.updateMessages(state.currentThreadId, newMessages);
-    } finally {
-      setIsRunning(false);
-    }
-  };
-
-  // Thread list adapter for managing multiple threads
-  const threadListAdapter: ExternalStoreThreadListAdapter = {
-    threadId: state.currentThreadId,
-    threads: state.threadList.filter((t): t is RegularThreadData => t.status === "regular"),
-    archivedThreads: state.threadList.filter((t): t is ArchivedThreadData => t.status === "archived"),
-
-    onSwitchToNewThread: async () => {
-      const threadId = await actions.createThread("New Chat");
-      actions.setCurrentThread(threadId);
-    },
-
-    onSwitchToThread: (threadId) => {
-      actions.setCurrentThread(threadId);
-    },
-
-    onRename: async (threadId, newTitle) => {
-      await actions.updateThread(threadId, { title: newTitle });
-    },
-
-    onArchive: async (threadId) => {
-      await actions.updateThread(threadId, { status: "archived" });
-    },
-
-    onDelete: async (threadId) => {
-      await actions.deleteThread(threadId);
-    },
-  };
-
-  const runtime = useExternalStoreRuntime({
-    messages: currentMessages,
-    setMessages: (messages) => {
-      actions.updateMessages(state.currentThreadId, messages);
-    },
-    convertMessage,
-    isRunning,
-    onNew,
-    onEdit,
-    adapters: {
-      threadList: threadListAdapter,
-    },
-  });
-
-  if (!state.isInitialized) {
-    return <div>Loading...</div>;
-  }
-
-  return (
-    <AssistantRuntimeProvider runtime={runtime}>
-      <ChatContainer $autoHeight={props.autoHeight}>
-        <ThreadList />
-        <Thread />
-      </ChatContainer>
-    </AssistantRuntimeProvider>
-  );
-}
-
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx
new file mode 100644
index 0000000000..a36c1f38ec
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx
@@ -0,0 +1,47 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx
+
+import React, { useMemo } from "react";
+import { ChatCore } from "./ChatCore";
+import { createChatStorage } from "../utils/storageFactory";
+import { N8NHandler } from "../handlers/messageHandlers";
+import { ChatPanelProps } from "../types/chatTypes";
+
+import "@assistant-ui/styles/index.css";
+import "@assistant-ui/styles/markdown.css";
+
+// ============================================================================
+// CHAT PANEL - CLEAN BOTTOM PANEL COMPONENT
+// ============================================================================
+
+export function ChatPanel({
+  tableName,
+  modelHost,
+  systemPrompt = "You are a helpful assistant.",
+  streaming = true,
+  onMessageUpdate
+}: ChatPanelProps) {
+  
+  // Create storage instance
+  const storage = useMemo(() => 
+    createChatStorage(tableName), 
+    [tableName]
+  );
+  
+  // Create N8N message handler
+  const messageHandler = useMemo(() => 
+    new N8NHandler({
+      modelHost,
+      systemPrompt,
+      streaming
+    }), 
+    [modelHost, systemPrompt, streaming]
+  );
+
+  return (
+    <ChatCore
+      storage={storage}
+      messageHandler={messageHandler}
+      onMessageUpdate={onMessageUpdate}
+    />
+  );
+}
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
index 68c4d4206c..65670edff8 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
@@ -1,378 +1,385 @@
-import React, { createContext, useContext, useReducer, useEffect, ReactNode } from "react";
-import {  ThreadData as StoredThreadData } from "../../utils/chatStorageFactory";
-// Define thread-specific message type
-export interface MyMessage {
-  id: string;
-  role: "user" | "assistant";
-  text: string;
-  timestamp: number;
-}
-
-// Thread data interfaces
-export interface RegularThreadData {
-  threadId: string;
-  status: "regular";
-  title: string;
-}
-
-export interface ArchivedThreadData {
-  threadId: string;
-  status: "archived";
-  title: string;
-}
-
-export type ThreadData = RegularThreadData | ArchivedThreadData;
-
-// Chat state interface
-interface ChatState {
-  isInitialized: boolean;
-  isLoading: boolean;
-  currentThreadId: string;
-  threadList: ThreadData[];
-  threads: Map<string, MyMessage[]>;
-  lastSaved: number; // Timestamp for tracking when data was last saved
-}
-
-// Action types
-type ChatAction =
-  | { type: "INITIALIZE_START" }
-  | { type: "INITIALIZE_SUCCESS"; threadList: ThreadData[]; threads: Map<string, MyMessage[]>; currentThreadId: string }
-  | { type: "INITIALIZE_ERROR" }
-  | { type: "SET_CURRENT_THREAD"; threadId: string }
-  | { type: "ADD_THREAD"; thread: ThreadData }
-  | { type: "UPDATE_THREAD"; threadId: string; updates: Partial<ThreadData> }
-  | { type: "DELETE_THREAD"; threadId: string }
-  | { type: "SET_MESSAGES"; threadId: string; messages: MyMessage[] }
-  | { type: "ADD_MESSAGE"; threadId: string; message: MyMessage }
-  | { type: "UPDATE_MESSAGES"; threadId: string; messages: MyMessage[] }
-  | { type: "MARK_SAVED" };
-
-// Initial state
-const initialState: ChatState = {
-  isInitialized: false,
-  isLoading: false,
-  currentThreadId: "default",
-  threadList: [{ threadId: "default", status: "regular", title: "New Chat" }],
-  threads: new Map([["default", []]]),
-  lastSaved: 0,
-};
-
-// Reducer function
-function chatReducer(state: ChatState, action: ChatAction): ChatState {
-  switch (action.type) {
-    case "INITIALIZE_START":
-      return {
-        ...state,
-        isLoading: true,
-      };
-
-    case "INITIALIZE_SUCCESS":
-      return {
-        ...state,
-        isInitialized: true,
-        isLoading: false,
-        threadList: action.threadList,
-        threads: action.threads,
-        currentThreadId: action.currentThreadId,
-        lastSaved: Date.now(),
-      };
-
-    case "INITIALIZE_ERROR":
-      return {
-        ...state,
-        isInitialized: true,
-        isLoading: false,
-      };
-
-    case "SET_CURRENT_THREAD":
-      return {
-        ...state,
-        currentThreadId: action.threadId,
-      };
-
-    case "ADD_THREAD":
-      return {
-        ...state,
-        threadList: [...state.threadList, action.thread],
-        threads: new Map(state.threads).set(action.thread.threadId, []),
-      };
-
-    case "UPDATE_THREAD":
-      return {
-        ...state,
-        threadList: state.threadList.map(thread =>
-          thread.threadId === action.threadId
-            ? { ...thread, ...action.updates }
-            : thread
-        ),
-      };
-
-    case "DELETE_THREAD":
-      const newThreads = new Map(state.threads);
-      newThreads.delete(action.threadId);
-      return {
-        ...state,
-        threadList: state.threadList.filter(t => t.threadId !== action.threadId),
-        threads: newThreads,
-        currentThreadId: state.currentThreadId === action.threadId 
-          ? "default" 
-          : state.currentThreadId,
-      };
-
-    case "SET_MESSAGES":
-      return {
-        ...state,
-        threads: new Map(state.threads).set(action.threadId, action.messages),
-      };
-
-    case "ADD_MESSAGE":
-      const currentMessages = state.threads.get(action.threadId) || [];
-      return {
-        ...state,
-        threads: new Map(state.threads).set(action.threadId, [...currentMessages, action.message]),
-      };
-
-    case "UPDATE_MESSAGES":
-      return {
-        ...state,
-        threads: new Map(state.threads).set(action.threadId, action.messages),
-      };
-
-    case "MARK_SAVED":
-      return {
-        ...state,
-        lastSaved: Date.now(),
-      };
-
-    default:
-      return state;
-  }
-}
-
-// Context type
-interface ChatContextType {
-  state: ChatState;
-  actions: {
-    // Initialization
-    initialize: () => Promise<void>;
-    
-    // Thread management
-    setCurrentThread: (threadId: string) => void;
-    createThread: (title?: string) => Promise<string>;
-    updateThread: (threadId: string, updates: Partial<ThreadData>) => Promise<void>;
-    deleteThread: (threadId: string) => Promise<void>;
-    
-    // Message management  
-    addMessage: (threadId: string, message: MyMessage) => Promise<void>;
-    updateMessages: (threadId: string, messages: MyMessage[]) => Promise<void>;
-    
-    // Utility
-    getCurrentMessages: () => MyMessage[];
-  };
-}
-
-// Create the context
-const ChatContext = createContext<ChatContextType | null>(null);
-
-// Chat provider component
-  export function ChatProvider({ children, storage }: { children: ReactNode,   storage: ReturnType<typeof import("../../utils/chatStorageFactory").createChatStorage>; 
-  }) {
-  const [state, dispatch] = useReducer(chatReducer, initialState);
-
-  // Initialize data from storage
-  const initialize = async () => {
-    dispatch({ type: "INITIALIZE_START" });
-    
-    try {
-      await storage.initialize();
-      
-      // Load all threads from storage
-      const storedThreads = await storage.getAllThreads();
-      
-      if (storedThreads.length > 0) {
-        // Convert stored threads to UI format
-        const uiThreads: ThreadData[] = storedThreads.map(stored => ({
-          threadId: stored.threadId,
-          status: stored.status as "regular" | "archived",
-          title: stored.title,
-        }));
-        
-        // Load messages for each thread
-        const threadMessages = new Map<string, MyMessage[]>();
-        for (const thread of storedThreads) {
-          const messages = await storage.getMessages(thread.threadId);
-          threadMessages.set(thread.threadId, messages);
-        }
-        
-        // Ensure default thread exists
-        if (!threadMessages.has("default")) {
-          threadMessages.set("default", []);
-        }
-        
-        // Find the most recently updated thread
-        const latestThread = storedThreads.sort((a, b) => b.updatedAt - a.updatedAt)[0];
-        const currentThreadId = latestThread ? latestThread.threadId : "default";
-        
-        dispatch({ 
-          type: "INITIALIZE_SUCCESS", 
-          threadList: uiThreads, 
-          threads: threadMessages, 
-          currentThreadId 
-        });
-      } else {
-        // Initialize with default thread
-        const defaultThread: StoredThreadData = {
-          threadId: "default",
-          status: "regular",
-          title: "New Chat",
-          createdAt: Date.now(),
-          updatedAt: Date.now(),
-        };
-        await storage.saveThread(defaultThread);
-        
-        dispatch({ 
-          type: "INITIALIZE_SUCCESS", 
-          threadList: initialState.threadList, 
-          threads: initialState.threads, 
-          currentThreadId: "default" 
-        });
-      }
-    } catch (error) {
-      console.error("Failed to initialize chat data:", error);
-      dispatch({ type: "INITIALIZE_ERROR" });
-    }
-  };
-
-  // Thread management actions
-  const setCurrentThread = (threadId: string) => {
-    dispatch({ type: "SET_CURRENT_THREAD", threadId });
-  };
-
-  const createThread = async (title: string = "New Chat"): Promise<string> => {
-    const threadId = `thread-${Date.now()}`;
-    const newThread: ThreadData = {
-      threadId,
-      status: "regular",
-      title,
-    };
-    
-    // Update local state first
-    dispatch({ type: "ADD_THREAD", thread: newThread });
-    
-    // Save to storage
-    try {
-      const storedThread: StoredThreadData = {
-        threadId,
-        status: "regular",
-        title,
-        createdAt: Date.now(),
-        updatedAt: Date.now(),
-      };
-      await storage.saveThread(storedThread);
-      dispatch({ type: "MARK_SAVED" });
-    } catch (error) {
-      console.error("Failed to save new thread:", error);
-    }
-    
-    return threadId;
-  };
-
-  const updateThread = async (threadId: string, updates: Partial<ThreadData>) => {
-    // Update local state first
-    dispatch({ type: "UPDATE_THREAD", threadId, updates });
-    
-    // Save to storage
-    try {
-      const existingThread = await storage.getThread(threadId);
-      if (existingThread) {
-        const updatedThread: StoredThreadData = {
-          ...existingThread,
-          ...updates,
-          updatedAt: Date.now(),
-        };
-        await storage.saveThread(updatedThread);
-        dispatch({ type: "MARK_SAVED" });
-      }
-    } catch (error) {
-      console.error("Failed to update thread:", error);
-    }
-  };
-
-  const deleteThread = async (threadId: string) => {
-    // Update local state first
-    dispatch({ type: "DELETE_THREAD", threadId });
-    
-    // Delete from storage
-    try {
-      await storage.deleteThread(threadId);
-      dispatch({ type: "MARK_SAVED" });
-    } catch (error) {
-      console.error("Failed to delete thread:", error);
-    }
-  };
-
-  // Message management actions
-  const addMessage = async (threadId: string, message: MyMessage) => {
-    // Update local state first
-    dispatch({ type: "ADD_MESSAGE", threadId, message });
-    
-    // Save to storage
-    try {
-      await storage.saveMessage(message, threadId);
-      dispatch({ type: "MARK_SAVED" });
-    } catch (error) {
-      console.error("Failed to save message:", error);
-    }
-  };
-
-  const updateMessages = async (threadId: string, messages: MyMessage[]) => {
-    // Update local state first
-    dispatch({ type: "UPDATE_MESSAGES", threadId, messages });
-    
-    // Save to storage
-    try {
-      await storage.saveMessages(messages, threadId);
-      dispatch({ type: "MARK_SAVED" });
-    } catch (error) {
-      console.error("Failed to save messages:", error);
-    }
-  };
-
-  // Utility functions
-  const getCurrentMessages = (): MyMessage[] => {
-    return state.threads.get(state.currentThreadId) || [];
-  };
-
-  // Auto-initialize on mount
-  useEffect(() => {
-    if (!state.isInitialized && !state.isLoading) {
-      initialize();
-    }
-  }, [state.isInitialized, state.isLoading]);
-
-  const actions = {
-    initialize,
-    setCurrentThread,
-    createThread,
-    updateThread,
-    deleteThread,
-    addMessage,
-    updateMessages,
-    getCurrentMessages,
-  };
-
-  return (
-    <ChatContext.Provider value={{ state, actions }}>
-      {children}
-    </ChatContext.Provider>
-  );
-}
-
-// Hook for accessing chat context
-export function useChatContext() {
-  const context = useContext(ChatContext);
-  if (!context) {
-    throw new Error("useChatContext must be used within ChatProvider");
-  }
-  return context;
-} 
\ No newline at end of file
+// client/packages/lowcoder/src/comps/comps/chatComp/context/ChatContext.tsx
+
+import React, { createContext, useContext, useReducer, useEffect, ReactNode } from "react";
+import { ChatStorage, ChatMessage, ChatThread } from "../../types/chatTypes";
+
+// ============================================================================
+// UPDATED CONTEXT WITH CLEAN TYPES
+// ============================================================================
+
+// Thread data interfaces (using clean types)
+export interface RegularThreadData {
+  threadId: string;
+  status: "regular";
+  title: string;
+}
+
+export interface ArchivedThreadData {
+  threadId: string;
+  status: "archived";
+  title: string;
+}
+
+export type ThreadData = RegularThreadData | ArchivedThreadData;
+
+// Chat state interface (cleaned up)
+interface ChatState {
+  isInitialized: boolean;
+  isLoading: boolean;
+  currentThreadId: string;
+  threadList: ThreadData[];
+  threads: Map<string, ChatMessage[]>;
+  lastSaved: number;
+}
+
+// Action types (same as before)
+type ChatAction =
+  | { type: "INITIALIZE_START" }
+  | { type: "INITIALIZE_SUCCESS"; threadList: ThreadData[]; threads: Map<string, ChatMessage[]>; currentThreadId: string }
+  | { type: "INITIALIZE_ERROR" }
+  | { type: "SET_CURRENT_THREAD"; threadId: string }
+  | { type: "ADD_THREAD"; thread: ThreadData }
+  | { type: "UPDATE_THREAD"; threadId: string; updates: Partial<ThreadData> }
+  | { type: "DELETE_THREAD"; threadId: string }
+  | { type: "SET_MESSAGES"; threadId: string; messages: ChatMessage[] }
+  | { type: "ADD_MESSAGE"; threadId: string; message: ChatMessage }
+  | { type: "UPDATE_MESSAGES"; threadId: string; messages: ChatMessage[] }
+  | { type: "MARK_SAVED" };
+
+// Initial state
+const initialState: ChatState = {
+  isInitialized: false,
+  isLoading: false,
+  currentThreadId: "default",
+  threadList: [{ threadId: "default", status: "regular", title: "New Chat" }],
+  threads: new Map([["default", []]]),
+  lastSaved: 0,
+};
+
+// Reducer function (same logic, updated types)
+function chatReducer(state: ChatState, action: ChatAction): ChatState {
+  switch (action.type) {
+    case "INITIALIZE_START":
+      return {
+        ...state,
+        isLoading: true,
+      };
+
+    case "INITIALIZE_SUCCESS":
+      return {
+        ...state,
+        isInitialized: true,
+        isLoading: false,
+        threadList: action.threadList,
+        threads: action.threads,
+        currentThreadId: action.currentThreadId,
+        lastSaved: Date.now(),
+      };
+
+    case "INITIALIZE_ERROR":
+      return {
+        ...state,
+        isInitialized: true,
+        isLoading: false,
+      };
+
+    case "SET_CURRENT_THREAD":
+      return {
+        ...state,
+        currentThreadId: action.threadId,
+      };
+
+    case "ADD_THREAD":
+      return {
+        ...state,
+        threadList: [...state.threadList, action.thread],
+        threads: new Map(state.threads).set(action.thread.threadId, []),
+      };
+
+    case "UPDATE_THREAD":
+      return {
+        ...state,
+        threadList: state.threadList.map(thread =>
+          thread.threadId === action.threadId
+            ? { ...thread, ...action.updates }
+            : thread
+        ),
+      };
+
+    case "DELETE_THREAD":
+      const newThreads = new Map(state.threads);
+      newThreads.delete(action.threadId);
+      return {
+        ...state,
+        threadList: state.threadList.filter(t => t.threadId !== action.threadId),
+        threads: newThreads,
+        currentThreadId: state.currentThreadId === action.threadId 
+          ? "default" 
+          : state.currentThreadId,
+      };
+
+    case "SET_MESSAGES":
+      return {
+        ...state,
+        threads: new Map(state.threads).set(action.threadId, action.messages),
+      };
+
+    case "ADD_MESSAGE":
+      const currentMessages = state.threads.get(action.threadId) || [];
+      return {
+        ...state,
+        threads: new Map(state.threads).set(action.threadId, [...currentMessages, action.message]),
+      };
+
+    case "UPDATE_MESSAGES":
+      return {
+        ...state,
+        threads: new Map(state.threads).set(action.threadId, action.messages),
+      };
+
+    case "MARK_SAVED":
+      return {
+        ...state,
+        lastSaved: Date.now(),
+      };
+
+    default:
+      return state;
+  }
+}
+
+// Context type (cleaned up)
+interface ChatContextType {
+  state: ChatState;
+  actions: {
+    // Initialization
+    initialize: () => Promise<void>;
+    
+    // Thread management
+    setCurrentThread: (threadId: string) => void;
+    createThread: (title?: string) => Promise<string>;
+    updateThread: (threadId: string, updates: Partial<ThreadData>) => Promise<void>;
+    deleteThread: (threadId: string) => Promise<void>;
+    
+    // Message management  
+    addMessage: (threadId: string, message: ChatMessage) => Promise<void>;
+    updateMessages: (threadId: string, messages: ChatMessage[]) => Promise<void>;
+    
+    // Utility
+    getCurrentMessages: () => ChatMessage[];
+  };
+}
+
+// Create the context
+const ChatContext = createContext<ChatContextType | null>(null);
+
+// ============================================================================
+// CHAT PROVIDER - UPDATED TO USE CLEAN STORAGE INTERFACE
+// ============================================================================
+
+export function ChatProvider({ children, storage }: { 
+  children: ReactNode; 
+  storage: ChatStorage; 
+}) {
+  const [state, dispatch] = useReducer(chatReducer, initialState);
+
+  // Initialize data from storage
+  const initialize = async () => {
+    dispatch({ type: "INITIALIZE_START" });
+    
+    try {
+      await storage.initialize();
+      
+      // Load all threads from storage
+      const storedThreads = await storage.getAllThreads();
+      
+      if (storedThreads.length > 0) {
+        // Convert stored threads to UI format
+        const uiThreads: ThreadData[] = storedThreads.map(stored => ({
+          threadId: stored.threadId,
+          status: stored.status as "regular" | "archived",
+          title: stored.title,
+        }));
+        
+        // Load messages for each thread
+        const threadMessages = new Map<string, ChatMessage[]>();
+        for (const thread of storedThreads) {
+          const messages = await storage.getMessages(thread.threadId);
+          threadMessages.set(thread.threadId, messages);
+        }
+        
+        // Ensure default thread exists
+        if (!threadMessages.has("default")) {
+          threadMessages.set("default", []);
+        }
+        
+        // Find the most recently updated thread
+        const latestThread = storedThreads.sort((a, b) => b.updatedAt - a.updatedAt)[0];
+        const currentThreadId = latestThread ? latestThread.threadId : "default";
+        
+        dispatch({ 
+          type: "INITIALIZE_SUCCESS", 
+          threadList: uiThreads, 
+          threads: threadMessages, 
+          currentThreadId 
+        });
+      } else {
+        // Initialize with default thread
+        const defaultThread: ChatThread = {
+          threadId: "default",
+          status: "regular",
+          title: "New Chat",
+          createdAt: Date.now(),
+          updatedAt: Date.now(),
+        };
+        await storage.saveThread(defaultThread);
+        
+        dispatch({ 
+          type: "INITIALIZE_SUCCESS", 
+          threadList: initialState.threadList, 
+          threads: initialState.threads, 
+          currentThreadId: "default" 
+        });
+      }
+    } catch (error) {
+      console.error("Failed to initialize chat data:", error);
+      dispatch({ type: "INITIALIZE_ERROR" });
+    }
+  };
+
+  // Thread management actions (same logic, cleaner types)
+  const setCurrentThread = (threadId: string) => {
+    dispatch({ type: "SET_CURRENT_THREAD", threadId });
+  };
+
+  const createThread = async (title: string = "New Chat"): Promise<string> => {
+    const threadId = `thread-${Date.now()}`;
+    const newThread: ThreadData = {
+      threadId,
+      status: "regular",
+      title,
+    };
+    
+    // Update local state first
+    dispatch({ type: "ADD_THREAD", thread: newThread });
+    
+    // Save to storage
+    try {
+      const storedThread: ChatThread = {
+        threadId,
+        status: "regular",
+        title,
+        createdAt: Date.now(),
+        updatedAt: Date.now(),
+      };
+      await storage.saveThread(storedThread);
+      dispatch({ type: "MARK_SAVED" });
+    } catch (error) {
+      console.error("Failed to save new thread:", error);
+    }
+    
+    return threadId;
+  };
+
+  const updateThread = async (threadId: string, updates: Partial<ThreadData>) => {
+    // Update local state first
+    dispatch({ type: "UPDATE_THREAD", threadId, updates });
+    
+    // Save to storage
+    try {
+      const existingThread = await storage.getThread(threadId);
+      if (existingThread) {
+        const updatedThread: ChatThread = {
+          ...existingThread,
+          ...updates,
+          updatedAt: Date.now(),
+        };
+        await storage.saveThread(updatedThread);
+        dispatch({ type: "MARK_SAVED" });
+      }
+    } catch (error) {
+      console.error("Failed to update thread:", error);
+    }
+  };
+
+  const deleteThread = async (threadId: string) => {
+    // Update local state first
+    dispatch({ type: "DELETE_THREAD", threadId });
+    
+    // Delete from storage
+    try {
+      await storage.deleteThread(threadId);
+      dispatch({ type: "MARK_SAVED" });
+    } catch (error) {
+      console.error("Failed to delete thread:", error);
+    }
+  };
+
+  // Message management actions (same logic)
+  const addMessage = async (threadId: string, message: ChatMessage) => {
+    // Update local state first
+    dispatch({ type: "ADD_MESSAGE", threadId, message });
+    
+    // Save to storage
+    try {
+      await storage.saveMessage(message, threadId);
+      dispatch({ type: "MARK_SAVED" });
+    } catch (error) {
+      console.error("Failed to save message:", error);
+    }
+  };
+
+  const updateMessages = async (threadId: string, messages: ChatMessage[]) => {
+    // Update local state first
+    dispatch({ type: "UPDATE_MESSAGES", threadId, messages });
+    
+    // Save to storage
+    try {
+      await storage.saveMessages(messages, threadId);
+      dispatch({ type: "MARK_SAVED" });
+    } catch (error) {
+      console.error("Failed to save messages:", error);
+    }
+  };
+
+  // Utility functions
+  const getCurrentMessages = (): ChatMessage[] => {
+    return state.threads.get(state.currentThreadId) || [];
+  };
+
+  // Auto-initialize on mount
+  useEffect(() => {
+    if (!state.isInitialized && !state.isLoading) {
+      initialize();
+    }
+  }, [state.isInitialized, state.isLoading]);
+
+  const actions = {
+    initialize,
+    setCurrentThread,
+    createThread,
+    updateThread,
+    deleteThread,
+    addMessage,
+    updateMessages,
+    getCurrentMessages,
+  };
+
+  return (
+    <ChatContext.Provider value={{ state, actions }}>
+      {children}
+    </ChatContext.Provider>
+  );
+}
+
+// Hook for accessing chat context
+export function useChatContext() {
+  const context = useContext(ChatContext);
+  if (!context) {
+    throw new Error("useChatContext must be used within ChatProvider");
+  }
+  return context;
+}
+
+// Re-export types for convenience
+export type { ChatMessage, ChatThread };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts b/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
new file mode 100644
index 0000000000..14dcf5a718
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
@@ -0,0 +1,133 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
+
+import { MessageHandler, MessageResponse, N8NHandlerConfig, QueryHandlerConfig } from "../types/chatTypes";
+import { CompAction, routeByNameAction, executeQueryAction } from "lowcoder-core";
+import { getPromiseAfterDispatch } from "util/promiseUtils";
+
+// ============================================================================
+// N8N HANDLER (for Bottom Panel)
+// ============================================================================
+
+export class N8NHandler implements MessageHandler {
+  constructor(private config: N8NHandlerConfig) {}
+
+  async sendMessage(message: string): Promise<MessageResponse> {
+    const { modelHost, systemPrompt, streaming } = this.config;
+    
+    if (!modelHost) {
+      throw new Error("Model host is required for N8N calls");
+    }
+
+    try {
+      const response = await fetch(modelHost, {
+        method: 'POST',
+        headers: {
+          'Content-Type': 'application/json',
+        },
+        body: JSON.stringify({
+          message,
+          systemPrompt: systemPrompt || "You are a helpful assistant.",
+          streaming: streaming || false
+        })
+      });
+
+      if (!response.ok) {
+        throw new Error(`N8N call failed: ${response.status} ${response.statusText}`);
+      }
+
+      const data = await response.json();
+      
+      // Extract content from various possible response formats
+      const content = data.response || data.message || data.content || data.text || String(data);
+      
+      return { content };
+    } catch (error) {
+      throw new Error(`N8N call failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
+    }
+  }
+}
+
+// ============================================================================
+// QUERY HANDLER (for Canvas Components)
+// ============================================================================
+
+export class QueryHandler implements MessageHandler {
+  constructor(private config: QueryHandlerConfig) {}
+
+  async sendMessage(message: string): Promise<MessageResponse> {
+    const { chatQuery, dispatch } = this.config;
+    
+    // If no query selected or dispatch unavailable, return mock response
+    if (!chatQuery || !dispatch) {
+      await new Promise((res) => setTimeout(res, 500));
+      return { content: "(mock) You typed: " + message };
+    }
+
+    try {
+      const result: any = await getPromiseAfterDispatch(
+        dispatch,
+        routeByNameAction(
+          chatQuery,
+          executeQueryAction({
+            // Send the user prompt as variable named 'prompt' by default
+            args: { prompt: { value: message } },
+          })
+        )
+      );
+
+      // Extract reply text from the query result (same logic as your current implementation)
+      let content: string;
+      if (typeof result === "string") {
+        content = result;
+      } else if (result && typeof result === "object") {
+        content =
+          (result as any).response ??
+          (result as any).message ??
+          (result as any).content ??
+          JSON.stringify(result);
+      } else {
+        content = String(result);
+      }
+
+      return { content };
+    } catch (e: any) {
+      throw new Error(e?.message || "Query execution failed");
+    }
+  }
+}
+
+// ============================================================================
+// MOCK HANDLER (for testing/fallbacks)
+// ============================================================================
+
+export class MockHandler implements MessageHandler {
+  constructor(private delay: number = 1000) {}
+
+  async sendMessage(message: string): Promise<MessageResponse> {
+    await new Promise(resolve => setTimeout(resolve, this.delay));
+    return { content: `Mock response: ${message}` };
+  }
+}
+
+// ============================================================================
+// HANDLER FACTORY (creates the right handler based on type)
+// ============================================================================
+
+export function createMessageHandler(
+  type: "n8n" | "query" | "mock",
+  config: N8NHandlerConfig | QueryHandlerConfig
+): MessageHandler {
+  switch (type) {
+    case "n8n":
+      return new N8NHandler(config as N8NHandlerConfig);
+    
+    case "query":
+      return new QueryHandler(config as QueryHandlerConfig);
+    
+    case "mock":
+      return new MockHandler();
+    
+    default:
+      throw new Error(`Unknown message handler type: ${type}`);
+  }
+}
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts b/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
new file mode 100644
index 0000000000..f820d55eee
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
@@ -0,0 +1,86 @@
+// client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
+
+// ============================================================================
+// CORE MESSAGE AND THREAD TYPES (cleaned up from your existing types)
+// ============================================================================
+
+export interface ChatMessage {
+    id: string;
+    role: "user" | "assistant";
+    text: string;
+    timestamp: number;
+  }
+  
+  export interface ChatThread {
+    threadId: string;
+    status: "regular" | "archived";
+    title: string;
+    createdAt: number;
+    updatedAt: number;
+  }
+  
+  // ============================================================================
+  // STORAGE INTERFACE (abstracted from your existing storage factory)
+  // ============================================================================
+  
+  export interface ChatStorage {
+    initialize(): Promise<void>;
+    saveThread(thread: ChatThread): Promise<void>;
+    getThread(threadId: string): Promise<ChatThread | null>;
+    getAllThreads(): Promise<ChatThread[]>;
+    deleteThread(threadId: string): Promise<void>;
+    saveMessage(message: ChatMessage, threadId: string): Promise<void>;
+    saveMessages(messages: ChatMessage[], threadId: string): Promise<void>;
+    getMessages(threadId: string): Promise<ChatMessage[]>;
+    deleteMessages(threadId: string): Promise<void>;
+    clearAllData(): Promise<void>;
+    resetDatabase(): Promise<void>;
+  }
+  
+  // ============================================================================
+  // MESSAGE HANDLER INTERFACE (new clean abstraction)
+  // ============================================================================
+  
+  export interface MessageHandler {
+    sendMessage(message: string): Promise<MessageResponse>;
+    // Future: sendMessageStream?(message: string): AsyncGenerator<MessageResponse>;
+  }
+  
+  export interface MessageResponse {
+    content: string;
+    metadata?: any;
+  }
+  
+  // ============================================================================
+  // CONFIGURATION TYPES (simplified)
+  // ============================================================================
+  
+  export interface N8NHandlerConfig {
+    modelHost: string;
+    systemPrompt?: string;
+    streaming?: boolean;
+  }
+  
+  export interface QueryHandlerConfig {
+    chatQuery: string;
+    dispatch: any;
+    streaming?: boolean;
+  }
+  
+  // ============================================================================
+  // COMPONENT PROPS (what each component actually needs)
+  // ============================================================================
+  
+  export interface ChatCoreProps {
+    storage: ChatStorage;
+    messageHandler: MessageHandler;
+    onMessageUpdate?: (message: string) => void;
+  }
+  
+  export interface ChatPanelProps {
+    tableName: string;
+    modelHost: string;
+    systemPrompt?: string;
+    streaming?: boolean;
+    onMessageUpdate?: (message: string) => void;
+  }
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorage.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorage.ts
deleted file mode 100644
index edc68a0d93..0000000000
--- a/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorage.ts
+++ /dev/null
@@ -1,281 +0,0 @@
-import alasql from "alasql";
-import { MyMessage } from "../components/context/ChatContext";
-
-// Database configuration
-const DB_NAME = "ChatDB";
-const THREADS_TABLE = "threads";
-const MESSAGES_TABLE = "messages";
-
-// Thread data interface
-export interface ThreadData {
-  threadId: string;
-  status: "regular" | "archived";
-  title: string;
-  createdAt: number;
-  updatedAt: number;
-}
-
-// Initialize the database
-class ChatStorage {
-  private initialized = false;
-
-  async initialize() {
-    if (this.initialized) return;
-
-    try {
-      // Create database with localStorage backend
-      await alasql.promise(`CREATE LOCALSTORAGE DATABASE IF NOT EXISTS ${DB_NAME}`);
-      await alasql.promise(`ATTACH LOCALSTORAGE DATABASE ${DB_NAME}`);
-      await alasql.promise(`USE ${DB_NAME}`);
-
-      // Create threads table
-      await alasql.promise(`
-        CREATE TABLE IF NOT EXISTS ${THREADS_TABLE} (
-          threadId STRING PRIMARY KEY,
-          status STRING,
-          title STRING,
-          createdAt NUMBER,
-          updatedAt NUMBER
-        )
-      `);
-
-      // Create messages table
-      await alasql.promise(`
-        CREATE TABLE IF NOT EXISTS ${MESSAGES_TABLE} (
-          id STRING PRIMARY KEY,
-          threadId STRING,
-          role STRING,
-          text STRING,
-          timestamp NUMBER
-        )
-      `);
-
-      this.initialized = true;
-      console.log("Chat database initialized successfully");
-    } catch (error) {
-      console.error("Failed to initialize chat database:", error);
-      throw error;
-    }
-  }
-
-  // Thread operations
-  async saveThread(thread: ThreadData): Promise<void> {
-    await this.initialize();
-    
-    try {
-      // Insert or replace thread
-      await alasql.promise(`
-        DELETE FROM ${THREADS_TABLE} WHERE threadId = ?
-      `, [thread.threadId]);
-      
-      await alasql.promise(`
-        INSERT INTO ${THREADS_TABLE} VALUES (?, ?, ?, ?, ?)
-      `, [thread.threadId, thread.status, thread.title, thread.createdAt, thread.updatedAt]);
-    } catch (error) {
-      console.error("Failed to save thread:", error);
-      throw error;
-    }
-  }
-
-  async getThread(threadId: string): Promise<ThreadData | null> {
-    await this.initialize();
-    
-    try {
-      const result = await alasql.promise(`
-        SELECT * FROM ${THREADS_TABLE} WHERE threadId = ?
-      `, [threadId]) as ThreadData[];
-      
-      return result && result.length > 0 ? result[0] : null;
-    } catch (error) {
-      console.error("Failed to get thread:", error);
-      return null;
-    }
-  }
-
-  async getAllThreads(): Promise<ThreadData[]> {
-    await this.initialize();
-    
-    try {
-      const result = await alasql.promise(`
-        SELECT * FROM ${THREADS_TABLE} ORDER BY updatedAt DESC
-      `) as ThreadData[];
-      
-      return Array.isArray(result) ? result : [];
-    } catch (error) {
-      console.error("Failed to get threads:", error);
-      return [];
-    }
-  }
-
-  async deleteThread(threadId: string): Promise<void> {
-    await this.initialize();
-    
-    try {
-      // Delete thread and all its messages
-      await alasql.promise(`DELETE FROM ${THREADS_TABLE} WHERE threadId = ?`, [threadId]);
-      await alasql.promise(`DELETE FROM ${MESSAGES_TABLE} WHERE threadId = ?`, [threadId]);
-    } catch (error) {
-      console.error("Failed to delete thread:", error);
-      throw error;
-    }
-  }
-
-  // Message operations
-  async saveMessage(message: MyMessage, threadId: string): Promise<void> {
-    await this.initialize();
-    
-    try {
-      // Insert or replace message
-      await alasql.promise(`
-        DELETE FROM ${MESSAGES_TABLE} WHERE id = ?
-      `, [message.id]);
-      
-      await alasql.promise(`
-        INSERT INTO ${MESSAGES_TABLE} VALUES (?, ?, ?, ?, ?)
-      `, [message.id, threadId, message.role, message.text, message.timestamp]);
-    } catch (error) {
-      console.error("Failed to save message:", error);
-      throw error;
-    }
-  }
-
-  async saveMessages(messages: MyMessage[], threadId: string): Promise<void> {
-    await this.initialize();
-    
-    try {
-      // Delete existing messages for this thread
-      await alasql.promise(`DELETE FROM ${MESSAGES_TABLE} WHERE threadId = ?`, [threadId]);
-      
-      // Insert all messages
-      for (const message of messages) {
-        await alasql.promise(`
-          INSERT INTO ${MESSAGES_TABLE} VALUES (?, ?, ?, ?, ?)
-        `, [message.id, threadId, message.role, message.text, message.timestamp]);
-      }
-    } catch (error) {
-      console.error("Failed to save messages:", error);
-      throw error;
-    }
-  }
-
-  async getMessages(threadId: string): Promise<MyMessage[]> {
-    await this.initialize();
-    
-    try {
-      const result = await alasql.promise(`
-        SELECT id, role, text, timestamp FROM ${MESSAGES_TABLE} 
-        WHERE threadId = ? ORDER BY timestamp ASC
-      `, [threadId]) as MyMessage[];
-      
-      return Array.isArray(result) ? result : [];
-    } catch (error) {
-      console.error("Failed to get messages:", error);
-      return [];
-    }
-  }
-
-  async deleteMessages(threadId: string): Promise<void> {
-    await this.initialize();
-    
-    try {
-      await alasql.promise(`DELETE FROM ${MESSAGES_TABLE} WHERE threadId = ?`, [threadId]);
-    } catch (error) {
-      console.error("Failed to delete messages:", error);
-      throw error;
-    }
-  }
-
-  // Utility methods
-  async clearAllData(): Promise<void> {
-    await this.initialize();
-    
-    try {
-      await alasql.promise(`DELETE FROM ${THREADS_TABLE}`);
-      await alasql.promise(`DELETE FROM ${MESSAGES_TABLE}`);
-    } catch (error) {
-      console.error("Failed to clear all data:", error);
-      throw error;
-    }
-  }
-
-  async resetDatabase(): Promise<void> {
-    try {
-      // Drop the entire database
-      await alasql.promise(`DROP LOCALSTORAGE DATABASE IF EXISTS ${DB_NAME}`);
-      this.initialized = false;
-      
-      // Reinitialize fresh
-      await this.initialize();
-      console.log("✅ Database reset and reinitialized");
-    } catch (error) {
-      console.error("Failed to reset database:", error);
-      throw error;
-    }
-  }
-
-  async clearOnlyMessages(): Promise<void> {
-    await this.initialize();
-    
-    try {
-      await alasql.promise(`DELETE FROM ${MESSAGES_TABLE}`);
-      console.log("✅ All messages cleared, threads preserved");
-    } catch (error) {
-      console.error("Failed to clear messages:", error);
-      throw error;
-    }
-  }
-
-  async clearOnlyThreads(): Promise<void> {
-    await this.initialize();
-    
-    try {
-      await alasql.promise(`DELETE FROM ${THREADS_TABLE}`);
-      await alasql.promise(`DELETE FROM ${MESSAGES_TABLE}`); // Clear orphaned messages
-      console.log("✅ All threads and messages cleared");
-    } catch (error) {
-      console.error("Failed to clear threads:", error);
-      throw error;
-    }
-  }
-
-  async exportData(): Promise<{ threads: ThreadData[]; messages: any[] }> {
-    await this.initialize();
-    
-    try {
-      const threads = await this.getAllThreads();
-      const messages = await alasql.promise(`SELECT * FROM ${MESSAGES_TABLE}`) as any[];
-      
-      return { threads, messages: Array.isArray(messages) ? messages : [] };
-    } catch (error) {
-      console.error("Failed to export data:", error);
-      throw error;
-    }
-  }
-
-  async importData(data: { threads: ThreadData[]; messages: any[] }): Promise<void> {
-    await this.initialize();
-    
-    try {
-      // Clear existing data
-      await this.clearAllData();
-      
-      // Import threads
-      for (const thread of data.threads) {
-        await this.saveThread(thread);
-      }
-      
-      // Import messages
-      for (const message of data.messages) {
-        await alasql.promise(`
-          INSERT INTO ${MESSAGES_TABLE} VALUES (?, ?, ?, ?, ?)
-        `, [message.id, message.threadId, message.role, message.text, message.timestamp]);
-      }
-    } catch (error) {
-      console.error("Failed to import data:", error);
-      throw error;
-    }
-  }
-}
-
-// Export singleton instance
-export const chatStorage = new ChatStorage(); 
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/responseFactory.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/responseFactory.ts
deleted file mode 100644
index 91d4793353..0000000000
--- a/client/packages/lowcoder/src/comps/comps/chatComp/utils/responseFactory.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-// client/packages/lowcoder/src/comps/comps/chatComp/utils/responseFactory.ts
-import { 
-    queryResponseHandler, 
-    directApiResponseHandler, 
-    mockResponseHandler 
-  } from './responseHandlers';
-  
-  export const createResponseHandler = (type: string, config: any) => {
-    const sendMessage = async (message: string) => {
-      switch (type) {
-        case "query":
-          return await queryResponseHandler(message, config);
-        
-        case "direct-api":
-        case "n8n":
-          return await directApiResponseHandler(message, config);
-        
-        case "mock":
-          return await mockResponseHandler(message, config);
-        
-        default:
-          throw new Error(`Unknown response type: ${type}`);
-      }
-    };
-    
-    return { sendMessage };
-  };
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/responseHandlers.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/responseHandlers.ts
deleted file mode 100644
index ae384660cc..0000000000
--- a/client/packages/lowcoder/src/comps/comps/chatComp/utils/responseHandlers.ts
+++ /dev/null
@@ -1,99 +0,0 @@
-// client/packages/lowcoder/src/comps/comps/chatComp/utils/responseHandlers.ts
-import { CompAction, routeByNameAction, executeQueryAction } from "lowcoder-core";
-import { getPromiseAfterDispatch } from "util/promiseUtils";
-
-// Query response handler (your current logic)
-export const queryResponseHandler = async (
-  message: string,
-  config: { chatQuery: string; dispatch?: (action: CompAction<any>) => void }
-) => {
-  const { chatQuery, dispatch } = config;
-  
-  // If no query selected or dispatch unavailable, fallback with mock response
-  if (!chatQuery || !dispatch) {
-    await new Promise((res) => setTimeout(res, 500));
-    return { content: "(mock) You typed: " + message };
-  }
-
-  try {
-    const result: any = await getPromiseAfterDispatch(
-      dispatch,
-      routeByNameAction(
-        chatQuery,
-        executeQueryAction({
-          // Send the user prompt as variable named 'prompt' by default
-          args: { prompt: { value: message } },
-        })
-      )
-    );
-
-    // Extract reply text from the query result
-    let reply: string;
-    if (typeof result === "string") {
-      reply = result;
-    } else if (result && typeof result === "object") {
-      reply =
-        (result as any).response ??
-        (result as any).message ??
-        (result as any).content ??
-        JSON.stringify(result);
-    } else {
-      reply = String(result);
-    }
-
-    return { content: reply };
-  } catch (e: any) {
-    throw new Error(e?.message || "Query execution failed");
-  }
-};
-
-// Direct API response handler (for bottom panel usage)
-export const directApiResponseHandler = async (
-  message: string,
-  config: { modelHost: string; systemPrompt: string; streaming?: boolean }
-) => {
-  const { modelHost, systemPrompt, streaming } = config;
-  
-  if (!modelHost) {
-    throw new Error("Model host is required for direct API calls");
-  }
-
-  try {
-    const response = await fetch(modelHost, {
-      method: 'POST',
-      headers: {
-        'Content-Type': 'application/json',
-      },
-      body: JSON.stringify({
-        message,
-        systemPrompt: systemPrompt || "You are a helpful assistant.",
-        streaming: streaming || false
-      })
-    });
-
-    if (!response.ok) {
-      throw new Error(`API call failed: ${response.status} ${response.statusText}`);
-    }
-
-    const data = await response.json();
-    
-    // Extract content from various possible response formats
-    const content = data.response || data.message || data.content || data.text || String(data);
-    
-    return { content };
-  } catch (error) {
-    throw new Error(`Direct API call failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
-  }
-};
-
-// Mock response handler (for testing)
-export const mockResponseHandler = async (
-  message: string,
-  config: { delay?: number; prefix?: string }
-) => {
-  const { delay = 1000, prefix = "Mock response" } = config;
-  
-  await new Promise(resolve => setTimeout(resolve, delay));
-  
-  return { content: `${prefix}: ${message}` };
-};
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorageFactory.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
similarity index 81%
rename from client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorageFactory.ts
rename to client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
index e7f44a26c3..8e62e42744 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorageFactory.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
@@ -1,189 +1,181 @@
-// client/packages/lowcoder/src/comps/comps/chatComp/utils/chatStorageFactory.ts
-import alasql from "alasql";
-import { MyMessage } from "../components/context/ChatContext";
-
-// Thread data interface
-export interface ThreadData {
-  threadId: string;
-  status: "regular" | "archived";
-  title: string;
-  createdAt: number;
-  updatedAt: number;
-}
-
-export const createChatStorage = (tableName: string) => {
-  const dbName = `ChatDB_${tableName}`;
-  const threadsTable = `${tableName}_threads`;
-  const messagesTable = `${tableName}_messages`;
-  
-  return {
-    async initialize() {
-      try {
-        // Create database with localStorage backend
-        await alasql.promise(`CREATE LOCALSTORAGE DATABASE IF NOT EXISTS ${dbName}`);
-        await alasql.promise(`ATTACH LOCALSTORAGE DATABASE ${dbName}`);
-        await alasql.promise(`USE ${dbName}`);
-
-        // Create threads table
-        await alasql.promise(`
-          CREATE TABLE IF NOT EXISTS ${threadsTable} (
-            threadId STRING PRIMARY KEY,
-            status STRING,
-            title STRING,
-            createdAt NUMBER,
-            updatedAt NUMBER
-          )
-        `);
-
-        // Create messages table
-        await alasql.promise(`
-          CREATE TABLE IF NOT EXISTS ${messagesTable} (
-            id STRING PRIMARY KEY,
-            threadId STRING,
-            role STRING,
-            text STRING,
-            timestamp NUMBER
-          )
-        `);
-
-        console.log(`✅ Chat database initialized: ${dbName}`);
-      } catch (error) {
-        console.error(`Failed to initialize chat database ${dbName}:`, error);
-        throw error;
-      }
-    },
-
-    async saveThread(thread: ThreadData) {
-      try {
-        // Insert or replace thread
-        await alasql.promise(`
-          DELETE FROM ${threadsTable} WHERE threadId = ?
-        `, [thread.threadId]);
-        
-        await alasql.promise(`
-          INSERT INTO ${threadsTable} VALUES (?, ?, ?, ?, ?)
-        `, [thread.threadId, thread.status, thread.title, thread.createdAt, thread.updatedAt]);
-      } catch (error) {
-        console.error("Failed to save thread:", error);
-        throw error;
-      }
-    },
-
-    async getThread(threadId: string) {
-      try {
-        const result = await alasql.promise(`
-          SELECT * FROM ${threadsTable} WHERE threadId = ?
-        `, [threadId]) as ThreadData[];
-        
-        return result && result.length > 0 ? result[0] : null;
-      } catch (error) {
-        console.error("Failed to get thread:", error);
-        return null;
-      }
-    },
-
-    async getAllThreads() {
-      try {
-        const result = await alasql.promise(`
-          SELECT * FROM ${threadsTable} ORDER BY updatedAt DESC
-        `) as ThreadData[];
-        
-        return Array.isArray(result) ? result : [];
-      } catch (error) {
-        console.error("Failed to get threads:", error);
-        return [];
-      }
-    },
-
-    async deleteThread(threadId: string) {
-      try {
-        // Delete thread and all its messages
-        await alasql.promise(`DELETE FROM ${threadsTable} WHERE threadId = ?`, [threadId]);
-        await alasql.promise(`DELETE FROM ${messagesTable} WHERE threadId = ?`, [threadId]);
-      } catch (error) {
-        console.error("Failed to delete thread:", error);
-        throw error;
-      }
-    },
-
-    async saveMessage(message: MyMessage, threadId: string) {
-      try {
-        // Insert or replace message
-        await alasql.promise(`
-          DELETE FROM ${messagesTable} WHERE id = ?
-        `, [message.id]);
-        
-        await alasql.promise(`
-          INSERT INTO ${messagesTable} VALUES (?, ?, ?, ?, ?)
-        `, [message.id, threadId, message.role, message.text, message.timestamp]);
-      } catch (error) {
-        console.error("Failed to save message:", error);
-        throw error;
-      }
-    },
-
-    async saveMessages(messages: MyMessage[], threadId: string) {
-      try {
-        // Delete existing messages for this thread
-        await alasql.promise(`DELETE FROM ${messagesTable} WHERE threadId = ?`, [threadId]);
-        
-        // Insert all messages
-        for (const message of messages) {
-          await alasql.promise(`
-            INSERT INTO ${messagesTable} VALUES (?, ?, ?, ?, ?)
-          `, [message.id, threadId, message.role, message.text, message.timestamp]);
-        }
-      } catch (error) {
-        console.error("Failed to save messages:", error);
-        throw error;
-      }
-    },
-
-    async getMessages(threadId: string) {
-      try {
-        const result = await alasql.promise(`
-          SELECT id, role, text, timestamp FROM ${messagesTable} 
-          WHERE threadId = ? ORDER BY timestamp ASC
-        `, [threadId]) as MyMessage[];
-        
-        return Array.isArray(result) ? result : [];
-      } catch (error) {
-        console.error("Failed to get messages:", error);
-        return [];
-      }
-    },
-
-    async deleteMessages(threadId: string) {
-      try {
-        await alasql.promise(`DELETE FROM ${messagesTable} WHERE threadId = ?`, [threadId]);
-      } catch (error) {
-        console.error("Failed to delete messages:", error);
-        throw error;
-      }
-    },
-
-    async clearAllData() {
-      try {
-        await alasql.promise(`DELETE FROM ${threadsTable}`);
-        await alasql.promise(`DELETE FROM ${messagesTable}`);
-      } catch (error) {
-        console.error("Failed to clear all data:", error);
-        throw error;
-      }
-    },
-
-    async resetDatabase() {
-      try {
-        // Drop the entire database
-        await alasql.promise(`DROP LOCALSTORAGE DATABASE IF EXISTS ${dbName}`);
-        
-        // Reinitialize fresh
-        await this.initialize();
-        console.log(`✅ Database reset and reinitialized: ${dbName}`);
-      } catch (error) {
-        console.error("Failed to reset database:", error);
-        throw error;
-      }
-    }
-  };
-};
\ No newline at end of file
+// client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
+
+import alasql from "alasql";
+import { ChatMessage, ChatThread, ChatStorage } from "../types/chatTypes";
+
+// ============================================================================
+// CLEAN STORAGE FACTORY (simplified from your existing implementation)
+// ============================================================================
+
+export function createChatStorage(tableName: string): ChatStorage {
+  const dbName = `ChatDB_${tableName}`;
+  const threadsTable = `${tableName}_threads`;
+  const messagesTable = `${tableName}_messages`;
+  
+  return {
+    async initialize() {
+      try {
+        // Create database with localStorage backend
+        await alasql.promise(`CREATE LOCALSTORAGE DATABASE IF NOT EXISTS ${dbName}`);
+        await alasql.promise(`ATTACH LOCALSTORAGE DATABASE ${dbName}`);
+        await alasql.promise(`USE ${dbName}`);
+
+        // Create threads table
+        await alasql.promise(`
+          CREATE TABLE IF NOT EXISTS ${threadsTable} (
+            threadId STRING PRIMARY KEY,
+            status STRING,
+            title STRING,
+            createdAt NUMBER,
+            updatedAt NUMBER
+          )
+        `);
+
+        // Create messages table
+        await alasql.promise(`
+          CREATE TABLE IF NOT EXISTS ${messagesTable} (
+            id STRING PRIMARY KEY,
+            threadId STRING,
+            role STRING,
+            text STRING,
+            timestamp NUMBER
+          )
+        `);
+
+        console.log(`✅ Chat database initialized: ${dbName}`);
+      } catch (error) {
+        console.error(`Failed to initialize chat database ${dbName}:`, error);
+        throw error;
+      }
+    },
+
+    async saveThread(thread: ChatThread) {
+      try {
+        // Insert or replace thread
+        await alasql.promise(`DELETE FROM ${threadsTable} WHERE threadId = ?`, [thread.threadId]);
+        
+        await alasql.promise(`
+          INSERT INTO ${threadsTable} VALUES (?, ?, ?, ?, ?)
+        `, [thread.threadId, thread.status, thread.title, thread.createdAt, thread.updatedAt]);
+      } catch (error) {
+        console.error("Failed to save thread:", error);
+        throw error;
+      }
+    },
+
+    async getThread(threadId: string) {
+      try {
+        const result = await alasql.promise(`
+          SELECT * FROM ${threadsTable} WHERE threadId = ?
+        `, [threadId]) as ChatThread[];
+        
+        return result && result.length > 0 ? result[0] : null;
+      } catch (error) {
+        console.error("Failed to get thread:", error);
+        return null;
+      }
+    },
+
+    async getAllThreads() {
+      try {
+        const result = await alasql.promise(`
+          SELECT * FROM ${threadsTable} ORDER BY updatedAt DESC
+        `) as ChatThread[];
+        
+        return Array.isArray(result) ? result : [];
+      } catch (error) {
+        console.error("Failed to get threads:", error);
+        return [];
+      }
+    },
+
+    async deleteThread(threadId: string) {
+      try {
+        // Delete thread and all its messages
+        await alasql.promise(`DELETE FROM ${threadsTable} WHERE threadId = ?`, [threadId]);
+        await alasql.promise(`DELETE FROM ${messagesTable} WHERE threadId = ?`, [threadId]);
+      } catch (error) {
+        console.error("Failed to delete thread:", error);
+        throw error;
+      }
+    },
+
+    async saveMessage(message: ChatMessage, threadId: string) {
+      try {
+        // Insert or replace message
+        await alasql.promise(`DELETE FROM ${messagesTable} WHERE id = ?`, [message.id]);
+        
+        await alasql.promise(`
+          INSERT INTO ${messagesTable} VALUES (?, ?, ?, ?, ?)
+        `, [message.id, threadId, message.role, message.text, message.timestamp]);
+      } catch (error) {
+        console.error("Failed to save message:", error);
+        throw error;
+      }
+    },
+
+    async saveMessages(messages: ChatMessage[], threadId: string) {
+      try {
+        // Delete existing messages for this thread
+        await alasql.promise(`DELETE FROM ${messagesTable} WHERE threadId = ?`, [threadId]);
+        
+        // Insert all messages
+        for (const message of messages) {
+          await alasql.promise(`
+            INSERT INTO ${messagesTable} VALUES (?, ?, ?, ?, ?)
+          `, [message.id, threadId, message.role, message.text, message.timestamp]);
+        }
+      } catch (error) {
+        console.error("Failed to save messages:", error);
+        throw error;
+      }
+    },
+
+    async getMessages(threadId: string) {
+      try {
+        const result = await alasql.promise(`
+          SELECT id, role, text, timestamp FROM ${messagesTable} 
+          WHERE threadId = ? ORDER BY timestamp ASC
+        `, [threadId]) as ChatMessage[];
+        
+        return Array.isArray(result) ? result : [];
+      } catch (error) {
+        console.error("Failed to get messages:", error);
+        return [];
+      }
+    },
+
+    async deleteMessages(threadId: string) {
+      try {
+        await alasql.promise(`DELETE FROM ${messagesTable} WHERE threadId = ?`, [threadId]);
+      } catch (error) {
+        console.error("Failed to delete messages:", error);
+        throw error;
+      }
+    },
+
+    async clearAllData() {
+      try {
+        await alasql.promise(`DELETE FROM ${threadsTable}`);
+        await alasql.promise(`DELETE FROM ${messagesTable}`);
+      } catch (error) {
+        console.error("Failed to clear all data:", error);
+        throw error;
+      }
+    },
+
+    async resetDatabase() {
+      try {
+        // Drop the entire database
+        await alasql.promise(`DROP LOCALSTORAGE DATABASE IF EXISTS ${dbName}`);
+        
+        // Reinitialize fresh
+        await this.initialize();
+        console.log(`✅ Database reset and reinitialized: ${dbName}`);
+      } catch (error) {
+        console.error("Failed to reset database:", error);
+        throw error;
+      }
+    }
+  };
+}
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx b/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
index 8903ef2376..0ca02f6b23 100644
--- a/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
+++ b/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
@@ -1,149 +1,149 @@
-import { BottomContent } from "pages/editor/bottom/BottomContent";
-import { ResizableBox, ResizeCallbackData } from "react-resizable";
-import styled from "styled-components";
-import * as React from "react";
-import { useMemo, useState } from "react";
-import { getPanelStyle, savePanelStyle } from "util/localStorageUtil";
-import { BottomResultPanel } from "../../../components/resultPanel/BottomResultPanel";
-import { AppState } from "../../../redux/reducers";
-import { getUser } from "../../../redux/selectors/usersSelectors";
-import { connect } from "react-redux";
-import { Layers } from "constants/Layers";
-import Flex from "antd/es/flex";
-import type { MenuProps } from 'antd/es/menu';
-import { BuildOutlined, DatabaseOutlined } from "@ant-design/icons";
-import Menu from "antd/es/menu/menu";
-import { ChatView } from "@lowcoder-ee/comps/comps/chatComp/chatView";
-import { AIGenerate } from "lowcoder-design";
-
-type MenuItem = Required<MenuProps>['items'][number];
-
-const StyledResizableBox = styled(ResizableBox)`
-  position: relative;
-  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
-  border-top: 1px solid #e1e3eb;
-  z-index: ${Layers.bottomPanel};
-
-  .react-resizable-handle {
-    position: absolute;
-    border-top: transparent solid 3px;
-    width: 100%;
-    padding: 0 3px 3px 0;
-    top: 0;
-    cursor: row-resize;
-  }
-`;
-
-const StyledMenu = styled(Menu)`
-  width: 40px;
-  padding: 6px 0;
-
-  .ant-menu-item {
-    height: 30px;
-    line-height: 30px;
-  }
-`;
-
-const ChatHeader = styled.div`
-  flex: 0 0 35px;
-  padding: 0 16px;
-  display: flex;
-  align-items: center;
-  justify-content: space-between;
-  border-bottom: 1px solid #e1e3eb;
-  background: #fafafa;
-`;
-const ChatTitle = styled.h3`
-  margin: 0;
-  font-size: 14px;
-  font-weight: 500;
-  color: #222222;
-`;
-
-const preventDefault = (e: any) => {
-  e.preventDefault();
-};
-
-// prevent the editor window slide when resize
-const addListener = () => {
-  window.addEventListener("mousedown", preventDefault);
-};
-
-const removeListener = () => {
-  window.removeEventListener("mousedown", preventDefault);
-};
-
-function Bottom(props: any) {
-  const panelStyle = useMemo(() => getPanelStyle(), []);
-  const clientHeight = document.documentElement.clientHeight;
-  const resizeStop = (e: React.SyntheticEvent, data: ResizeCallbackData) => {
-    savePanelStyle({ ...panelStyle, bottom: { h: data.size.height } });
-    setBottomHeight(data.size.height);
-    removeListener();
-  };
-
-  const [bottomHeight, setBottomHeight] = useState(panelStyle.bottom.h);
-  const [currentOption, setCurrentOption] = useState("data");
-
-  const items: MenuItem[] = [
-    { key: 'data', icon: <DatabaseOutlined />, label: 'Data Queries' },
-    { key: 'ai', icon: <AIGenerate />, label: 'Lowcoder AI' },
-  ];
-
-  return (
-    <>
-      <BottomResultPanel bottom={bottomHeight} />
-      <StyledResizableBox
-        width={Infinity}
-        height={panelStyle.bottom.h}
-        resizeHandles={["n"]}
-        minConstraints={[680, 285]}
-        maxConstraints={[Infinity, clientHeight - 48 - 40]} // - app_header - right_header
-        onResizeStart={addListener}
-        onResizeStop={resizeStop}
-      >
-        <Flex style={{height: '100%'}}>
-          <StyledMenu
-            defaultSelectedKeys={[currentOption]}
-            mode="inline"
-            inlineCollapsed={true}
-            items={items}
-            onSelect={({key}) => {
-              setCurrentOption(key);
-            }}
-          />
-          { currentOption === "data" && <BottomContent /> }
-          { currentOption === "ai" && (
-            <Flex style={{height: '100%', flex: 1}} vertical>
-              <ChatHeader>
-                <ChatTitle>Lowcoder AI Assistant</ChatTitle>
-              </ChatHeader>
-              <ChatView
-                tableName="LC_AI"
-                modelType="n8n"
-                streaming={true}
-                systemPrompt="You are a helpful assistant."
-                agent={true}
-                maxInteractions={10}
-                modelHost="http://localhost:5678/webhook-test/9a363e76-d3a5-46d1-98c3-4359f7106d33"
-                // Required props that were missing:
-                text="Lowcoder AI Assistant"
-                chatQuery=""
-                currentMessage=""
-              />
-            </Flex>
-          )}
-        </Flex>
-      </StyledResizableBox>
-    </>
-  );
-}
-
-const mapStateToProps = (state: AppState) => {
-  return {
-    orgId: getUser(state).currentOrgId,
-    datasourceInfos: state.entities.datasource.data,
-  };
-};
-
-export default connect(mapStateToProps, null)(Bottom);
+import { BottomContent } from "pages/editor/bottom/BottomContent";
+import { ResizableBox, ResizeCallbackData } from "react-resizable";
+import styled from "styled-components";
+import * as React from "react";
+import { useMemo, useState } from "react";
+import { getPanelStyle, savePanelStyle } from "util/localStorageUtil";
+import { BottomResultPanel } from "../../../components/resultPanel/BottomResultPanel";
+import { AppState } from "../../../redux/reducers";
+import { getUser } from "../../../redux/selectors/usersSelectors";
+import { connect } from "react-redux";
+import { Layers } from "constants/Layers";
+import Flex from "antd/es/flex";
+import type { MenuProps } from 'antd/es/menu';
+import { BuildOutlined, DatabaseOutlined } from "@ant-design/icons";
+import Menu from "antd/es/menu/menu";
+import { AIGenerate } from "lowcoder-design";
+import { ChatPanel } from "@lowcoder-ee/comps/comps/chatComp/components/ChatPanel";
+
+type MenuItem = Required<MenuProps>['items'][number];
+
+const StyledResizableBox = styled(ResizableBox)`
+  position: relative;
+  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
+  border-top: 1px solid #e1e3eb;
+  z-index: ${Layers.bottomPanel};
+
+  .react-resizable-handle {
+    position: absolute;
+    border-top: transparent solid 3px;
+    width: 100%;
+    padding: 0 3px 3px 0;
+    top: 0;
+    cursor: row-resize;
+  }
+`;
+
+const StyledMenu = styled(Menu)`
+  width: 40px;
+  padding: 6px 0;
+
+  .ant-menu-item {
+    height: 30px;
+    line-height: 30px;
+  }
+`;
+
+const ChatHeader = styled.div`
+  flex: 0 0 35px;
+  padding: 0 16px;
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  border-bottom: 1px solid #e1e3eb;
+  background: #fafafa;
+`;
+const ChatTitle = styled.h3`
+  margin: 0;
+  font-size: 14px;
+  font-weight: 500;
+  color: #222222;
+`;
+
+const preventDefault = (e: any) => {
+  e.preventDefault();
+};
+
+// prevent the editor window slide when resize
+const addListener = () => {
+  window.addEventListener("mousedown", preventDefault);
+};
+
+const removeListener = () => {
+  window.removeEventListener("mousedown", preventDefault);
+};
+
+function Bottom(props: any) {
+  const panelStyle = useMemo(() => getPanelStyle(), []);
+  const clientHeight = document.documentElement.clientHeight;
+  const resizeStop = (e: React.SyntheticEvent, data: ResizeCallbackData) => {
+    savePanelStyle({ ...panelStyle, bottom: { h: data.size.height } });
+    setBottomHeight(data.size.height);
+    removeListener();
+  };
+
+  const [bottomHeight, setBottomHeight] = useState(panelStyle.bottom.h);
+  const [currentOption, setCurrentOption] = useState("data");
+
+  const items: MenuItem[] = [
+    { key: 'data', icon: <DatabaseOutlined />, label: 'Data Queries' },
+    { key: 'ai', icon: <AIGenerate />, label: 'Lowcoder AI' },
+  ];
+
+  return (
+    <>
+      <BottomResultPanel bottom={bottomHeight} />
+      <StyledResizableBox
+        width={Infinity}
+        height={panelStyle.bottom.h}
+        resizeHandles={["n"]}
+        minConstraints={[680, 285]}
+        maxConstraints={[Infinity, clientHeight - 48 - 40]} // - app_header - right_header
+        onResizeStart={addListener}
+        onResizeStop={resizeStop}
+      >
+        <Flex style={{height: '100%'}}>
+          <StyledMenu
+            defaultSelectedKeys={[currentOption]}
+            mode="inline"
+            inlineCollapsed={true}
+            items={items}
+            onSelect={({key}) => {
+              setCurrentOption(key);
+            }}
+          />
+          { currentOption === "data" && <BottomContent /> }
+          { currentOption === "ai" && (
+            <Flex style={{height: '100%', flex: 1}} vertical>
+              <ChatHeader>
+                <ChatTitle>Lowcoder AI Assistant</ChatTitle>
+              </ChatHeader>
+              {/* <ChatView
+                tableName="LC_AI"
+                handlerType="n8n"
+                streaming={true}
+                systemPrompt="You are a helpful assistant."
+                modelHost="http://localhost:5678/webhook-test/9a363e76-d3a5-46d1-98c3-4359f7106d33"
+              /> */}
+             <ChatPanel
+              tableName="LC_AI"
+              modelHost="http://localhost:5678/..."
+              systemPrompt="You are a helpful assistant."
+              streaming={true}
+              />
+            </Flex>
+          )}
+        </Flex>
+      </StyledResizableBox>
+    </>
+  );
+}
+
+const mapStateToProps = (state: AppState) => {
+  return {
+    orgId: getUser(state).currentOrgId,
+    datasourceInfos: state.entities.datasource.data,
+  };
+};
+
+export default connect(mapStateToProps, null)(Bottom);

From a349af4b4a9e1d22b623a76d2cb31b3be984125f Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Fri, 11 Jul 2025 23:59:16 +0500
Subject: [PATCH 44/54] add unique storage / expose convo history

---
 .../src/comps/comps/chatComp/chatComp.tsx     |  66 ++-
 .../comps/comps/chatComp/chatPropertyView.tsx |  10 +-
 .../comps/chatComp/components/ChatCore.tsx    |   3 +-
 .../chatComp/components/ChatCoreMain.tsx      | 503 +++++++++---------
 .../chatComp/handlers/messageHandlers.ts      |  16 +-
 .../comps/comps/chatComp/types/chatTypes.ts   |   2 +
 .../comps/chatComp/utils/storageFactory.ts    |  13 +-
 7 files changed, 336 insertions(+), 277 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
index ac32527bf8..59e93b4bfe 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
@@ -3,7 +3,7 @@
 import { UICompBuilder } from "comps/generators";
 import { NameConfig, withExposingConfigs } from "comps/generators/withExposing";
 import { StringControl } from "comps/controls/codeControl";
-import { stringExposingStateControl } from "comps/controls/codeStateControl";
+import { arrayObjectExposingStateControl, stringExposingStateControl } from "comps/controls/codeStateControl";
 import { withDefault } from "comps/generators";
 import { BoolControl } from "comps/controls/boolControl";
 import { dropdownControl } from "comps/controls/dropdownControl";
@@ -12,7 +12,7 @@ import { ChatCore } from "./components/ChatCore";
 import { ChatPropertyView } from "./chatPropertyView";
 import { createChatStorage } from "./utils/storageFactory";
 import { QueryHandler, createMessageHandler } from "./handlers/messageHandlers";
-import { useMemo } from "react";
+import { useMemo, useRef, useEffect } from "react";  
 import { changeChildAction } from "lowcoder-core";
 
 import "@assistant-ui/styles/index.css";
@@ -22,6 +22,10 @@ import "@assistant-ui/styles/markdown.css";
 // SIMPLIFIED CHILDREN MAP - ONLY ESSENTIAL PROPS
 // ============================================================================
 
+function generateUniqueTableName(): string {
+  return `chat${Math.floor(1000 + Math.random() * 9000)}`;
+ }
+
 const ModelTypeOptions = [
   { label: "Query", value: "query" },
   { label: "N8N Workflow", value: "n8n" },
@@ -29,8 +33,8 @@ const ModelTypeOptions = [
 
 export const chatChildrenMap = {
   // Storage
-  tableName: withDefault(StringControl, "default"),
-  
+  // Storage (add the hidden property here)
+  _internalDbName: withDefault(StringControl, ""),
   // Message Handler Configuration
   handlerType: dropdownControl(ModelTypeOptions, "query"),
   chatQuery: QuerySelectControl,                    // Only used for "query" type
@@ -41,8 +45,12 @@ export const chatChildrenMap = {
   // UI Configuration  
   placeholder: withDefault(StringControl, "Chat Component"),
   
+  // Database Information (read-only)
+  databaseName: withDefault(StringControl, ""),
+  
   // Exposed Variables (not shown in Property View)
   currentMessage: stringExposingStateControl("currentMessage", ""),
+  conversationHistory: stringExposingStateControl("conversationHistory", "[]"),
 };
 
 // ============================================================================
@@ -52,10 +60,27 @@ export const chatChildrenMap = {
 const ChatTmpComp = new UICompBuilder(
   chatChildrenMap,
   (props, dispatch) => {
-    // Create storage from tableName
-    const storage = useMemo(() => 
-      createChatStorage(props.tableName), 
-      [props.tableName]
+
+    const uniqueTableName = useRef<string>();
+
+      // Generate unique table name once (with persistence)
+    if (!uniqueTableName.current) {
+      // Use persisted name if exists, otherwise generate new one
+      uniqueTableName.current = props._internalDbName || generateUniqueTableName();
+      
+      // Save the name for future refreshes
+      if (!props._internalDbName) {
+        dispatch(changeChildAction("_internalDbName", uniqueTableName.current, false));
+      }
+      
+      // Update the database name in the props for display
+      const dbName = `ChatDB_${uniqueTableName.current}`;
+      dispatch(changeChildAction("databaseName", dbName, false));
+    }
+     // Create storage with unique table name
+     const storage = useMemo(() => 
+      createChatStorage(uniqueTableName.current!), 
+      []
     );
     
     // Create message handler based on type
@@ -96,11 +121,35 @@ const ChatTmpComp = new UICompBuilder(
       dispatch(changeChildAction("currentMessage", message, false));
     };
 
+    // Handle conversation history updates for exposed variable
+    const handleConversationUpdate = (conversationHistory: any[]) => {
+      // Format conversation history for use in queries
+      const formattedHistory = conversationHistory.map(msg => ({
+        role: msg.role,
+        content: msg.text,
+        timestamp: msg.timestamp
+      }));
+      dispatch(changeChildAction("conversationHistory", JSON.stringify(formattedHistory), false));
+    };
+
+       // Cleanup on unmount
+       useEffect(() => {
+        console.log("cleanup on unmount");
+        return () => {
+          console.log("cleanup on unmount");
+          const tableName = uniqueTableName.current;
+          if (tableName) {
+            storage.cleanup();
+          }
+        };
+      }, []);
+
     return (
       <ChatCore
         storage={storage}
         messageHandler={messageHandler}
         onMessageUpdate={handleMessageUpdate}
+        onConversationUpdate={handleConversationUpdate}
       />
     );
   }
@@ -114,4 +163,5 @@ const ChatTmpComp = new UICompBuilder(
 
 export const ChatComp = withExposingConfigs(ChatTmpComp, [
   new NameConfig("currentMessage", "Current user message"),
+  new NameConfig("conversationHistory", "Full conversation history as JSON array"),
 ]);
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
index 784ef44b56..9e7cac4aba 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
@@ -19,11 +19,13 @@ export const ChatPropertyView = React.memo((props: any) => {
           placeholder: "Enter placeholder text..."
         })}
         
-        {children.tableName.propertyView({ 
-          label: "Storage Table",
-          placeholder: "default",
-          tooltip: "Storage identifier - use same value to share conversations between components"
+        {children.databaseName.propertyView({ 
+          label: "Database Name",
+          placeholder: "Database will be auto-generated...",
+          tooltip: "Read-only: Auto-generated database name for data persistence. You can reference this in queries if needed.",
+          disabled: true
         })}
+        
       </Section>
 
       {/* Message Handler Configuration */}
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx
index c40151dd5b..d153a53d27 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx
@@ -9,12 +9,13 @@ import { ChatCoreProps } from "../types/chatTypes";
 // CHAT CORE - THE SHARED FOUNDATION
 // ============================================================================
 
-export function ChatCore({ storage, messageHandler, onMessageUpdate }: ChatCoreProps) {
+export function ChatCore({ storage, messageHandler, onMessageUpdate, onConversationUpdate }: ChatCoreProps) {
   return (
     <ChatProvider storage={storage}>
       <ChatCoreMain 
         messageHandler={messageHandler}
         onMessageUpdate={onMessageUpdate}
+        onConversationUpdate={onConversationUpdate}
       />
     </ChatProvider>
   );
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
index 1459d00e54..4c804e49d0 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
@@ -1,246 +1,257 @@
-// client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
-
-import React, { useState } from "react";
-import {
-  useExternalStoreRuntime,
-  ThreadMessageLike,
-  AppendMessage,
-  AssistantRuntimeProvider,
-  ExternalStoreThreadListAdapter,
-} from "@assistant-ui/react";
-import { Thread } from "./assistant-ui/thread";
-import { ThreadList } from "./assistant-ui/thread-list";
-import { 
-  useChatContext, 
-  ChatMessage, 
-  RegularThreadData, 
-  ArchivedThreadData 
-} from "./context/ChatContext";
-import { MessageHandler } from "../types/chatTypes";
-import styled from "styled-components";
-
-// ============================================================================
-// STYLED COMPONENTS (same as your current ChatMain)
-// ============================================================================
-
-const ChatContainer = styled.div`
-  display: flex;
-  height: 500px;
-
-  p {
-    margin: 0;
-  }
-
-  .aui-thread-list-root {
-    width: 250px;
-    background-color: #fff;
-    padding: 10px;
-  }
-
-  .aui-thread-root {
-    flex: 1;
-    background-color: #f9fafb;
-  }
-
-  .aui-thread-list-item {
-    cursor: pointer;
-    transition: background-color 0.2s ease;
-
-    &[data-active="true"] {
-      background-color: #dbeafe;
-      border: 1px solid #bfdbfe;
-    }
-  }
-`;
-
-// ============================================================================
-// CHAT CORE MAIN - CLEAN PROPS, FOCUSED RESPONSIBILITY
-// ============================================================================
-
-interface ChatCoreMainProps {
-  messageHandler: MessageHandler;
-  onMessageUpdate?: (message: string) => void;
-}
-
-const generateId = () => Math.random().toString(36).substr(2, 9);
-
-export function ChatCoreMain({ messageHandler, onMessageUpdate }: ChatCoreMainProps) {
-  const { state, actions } = useChatContext();
-  const [isRunning, setIsRunning] = useState(false);
-
-  console.log("CHAT CORE STATE", state);
-
-  // Get messages for current thread
-  const currentMessages = actions.getCurrentMessages();
-
-  // Convert custom format to ThreadMessageLike (same as your current implementation)
-  const convertMessage = (message: ChatMessage): ThreadMessageLike => ({
-    role: message.role,
-    content: [{ type: "text", text: message.text }],
-    id: message.id,
-    createdAt: new Date(message.timestamp),
-  });
-
-  // Handle new message - MUCH CLEANER with messageHandler
-  const onNew = async (message: AppendMessage) => {
-    // Extract text from AppendMessage content array
-    if (message.content.length !== 1 || message.content[0]?.type !== "text") {
-      throw new Error("Only text content is supported");
-    }
-
-    // Add user message in custom format
-    const userMessage: ChatMessage = {
-      id: generateId(),
-      role: "user",
-      text: message.content[0].text,
-      timestamp: Date.now(),
-    };
-    
-    // Update currentMessage state to expose to queries
-    onMessageUpdate?.(userMessage.text);
-    
-    // Update current thread with new user message
-    await actions.addMessage(state.currentThreadId, userMessage);
-    setIsRunning(true);
-
-    try {
-      // Use the message handler (no more complex logic here!)
-      const response = await messageHandler.sendMessage(userMessage.text);
-      
-      const assistantMessage: ChatMessage = {
-        id: generateId(),
-        role: "assistant",
-        text: response.content,
-        timestamp: Date.now(),
-      };
-      
-      // Update current thread with assistant response
-      await actions.addMessage(state.currentThreadId, assistantMessage);
-    } catch (error) {
-      // Handle errors gracefully
-      const errorMessage: ChatMessage = {
-        id: generateId(),
-        role: "assistant", 
-        text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
-        timestamp: Date.now(),
-      };
-      
-      await actions.addMessage(state.currentThreadId, errorMessage);
-    } finally {
-      setIsRunning(false);
-    }
-  };
-
-  // Handle edit message - CLEANER with messageHandler
-  const onEdit = async (message: AppendMessage) => {
-    // Extract text from AppendMessage content array
-    if (message.content.length !== 1 || message.content[0]?.type !== "text") {
-      throw new Error("Only text content is supported");
-    }
-
-    // Find the index where to insert the edited message
-    const index = currentMessages.findIndex((m) => m.id === message.parentId) + 1;
-
-    // Keep messages up to the parent
-    const newMessages = [...currentMessages.slice(0, index)];
-
-    // Add the edited message in custom format
-    const editedMessage: ChatMessage = {
-      id: generateId(),
-      role: "user",
-      text: message.content[0].text,
-      timestamp: Date.now(),
-    };
-    newMessages.push(editedMessage);
-
-    // Update currentMessage state to expose to queries
-    onMessageUpdate?.(editedMessage.text);
-
-    // Update messages using the new context action
-    await actions.updateMessages(state.currentThreadId, newMessages);
-    setIsRunning(true);
-
-    try {
-      // Use the message handler (clean!)
-      const response = await messageHandler.sendMessage(editedMessage.text);
-      
-      const assistantMessage: ChatMessage = {
-        id: generateId(),
-        role: "assistant",
-        text: response.content,
-        timestamp: Date.now(),
-      };
-      
-      newMessages.push(assistantMessage);
-      await actions.updateMessages(state.currentThreadId, newMessages);
-    } catch (error) {
-      // Handle errors gracefully
-      const errorMessage: ChatMessage = {
-        id: generateId(),
-        role: "assistant", 
-        text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
-        timestamp: Date.now(),
-      };
-      
-      newMessages.push(errorMessage);
-      await actions.updateMessages(state.currentThreadId, newMessages);
-    } finally {
-      setIsRunning(false);
-    }
-  };
-
-  // Thread list adapter for managing multiple threads (same as your current implementation)
-  const threadListAdapter: ExternalStoreThreadListAdapter = {
-    threadId: state.currentThreadId,
-    threads: state.threadList.filter((t): t is RegularThreadData => t.status === "regular"),
-    archivedThreads: state.threadList.filter((t): t is ArchivedThreadData => t.status === "archived"),
-
-    onSwitchToNewThread: async () => {
-      const threadId = await actions.createThread("New Chat");
-      actions.setCurrentThread(threadId);
-    },
-
-    onSwitchToThread: (threadId) => {
-      actions.setCurrentThread(threadId);
-    },
-
-    onRename: async (threadId, newTitle) => {
-      await actions.updateThread(threadId, { title: newTitle });
-    },
-
-    onArchive: async (threadId) => {
-      await actions.updateThread(threadId, { status: "archived" });
-    },
-
-    onDelete: async (threadId) => {
-      await actions.deleteThread(threadId);
-    },
-  };
-
-  const runtime = useExternalStoreRuntime({
-    messages: currentMessages,
-    setMessages: (messages) => {
-      actions.updateMessages(state.currentThreadId, messages);
-    },
-    convertMessage,
-    isRunning,
-    onNew,
-    onEdit,
-    adapters: {
-      threadList: threadListAdapter,
-    },
-  });
-
-  if (!state.isInitialized) {
-    return <div>Loading...</div>;
-  }
-
-  return (
-    <AssistantRuntimeProvider runtime={runtime}>
-      <ChatContainer>
-        <ThreadList />
-        <Thread />
-      </ChatContainer>
-    </AssistantRuntimeProvider>
-  );
-}
+// client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
+
+import React, { useState } from "react";
+import {
+  useExternalStoreRuntime,
+  ThreadMessageLike,
+  AppendMessage,
+  AssistantRuntimeProvider,
+  ExternalStoreThreadListAdapter,
+} from "@assistant-ui/react";
+import { Thread } from "./assistant-ui/thread";
+import { ThreadList } from "./assistant-ui/thread-list";
+import { 
+  useChatContext, 
+  ChatMessage, 
+  RegularThreadData, 
+  ArchivedThreadData 
+} from "./context/ChatContext";
+import { MessageHandler } from "../types/chatTypes";
+import styled from "styled-components";
+
+// ============================================================================
+// STYLED COMPONENTS (same as your current ChatMain)
+// ============================================================================
+
+const ChatContainer = styled.div`
+  display: flex;
+  height: 500px;
+
+  p {
+    margin: 0;
+  }
+
+  .aui-thread-list-root {
+    width: 250px;
+    background-color: #fff;
+    padding: 10px;
+  }
+
+  .aui-thread-root {
+    flex: 1;
+    background-color: #f9fafb;
+  }
+
+  .aui-thread-list-item {
+    cursor: pointer;
+    transition: background-color 0.2s ease;
+
+    &[data-active="true"] {
+      background-color: #dbeafe;
+      border: 1px solid #bfdbfe;
+    }
+  }
+`;
+
+// ============================================================================
+// CHAT CORE MAIN - CLEAN PROPS, FOCUSED RESPONSIBILITY
+// ============================================================================
+
+interface ChatCoreMainProps {
+  messageHandler: MessageHandler;
+  onMessageUpdate?: (message: string) => void;
+  onConversationUpdate?: (conversationHistory: ChatMessage[]) => void;
+}
+
+const generateId = () => Math.random().toString(36).substr(2, 9);
+
+export function ChatCoreMain({ messageHandler, onMessageUpdate, onConversationUpdate }: ChatCoreMainProps) {
+  const { state, actions } = useChatContext();
+  const [isRunning, setIsRunning] = useState(false);
+
+  console.log("CHAT CORE STATE", state);
+
+  // Get messages for current thread
+  const currentMessages = actions.getCurrentMessages();
+
+
+  console.log("CURRENT MESSAGES", currentMessages);
+
+  // Notify parent component of conversation changes
+  React.useEffect(() => {
+    onConversationUpdate?.(currentMessages);
+  }, [currentMessages]);
+
+  // Convert custom format to ThreadMessageLike (same as your current implementation)
+  const convertMessage = (message: ChatMessage): ThreadMessageLike => ({
+    role: message.role,
+    content: [{ type: "text", text: message.text }],
+    id: message.id,
+    createdAt: new Date(message.timestamp),
+  });
+
+  // Handle new message - MUCH CLEANER with messageHandler
+  const onNew = async (message: AppendMessage) => {
+    // Extract text from AppendMessage content array
+    if (message.content.length !== 1 || message.content[0]?.type !== "text") {
+      throw new Error("Only text content is supported");
+    }
+
+    // Add user message in custom format
+    const userMessage: ChatMessage = {
+      id: generateId(),
+      role: "user",
+      text: message.content[0].text,
+      timestamp: Date.now(),
+    };
+    
+    // Update currentMessage state to expose to queries
+    onMessageUpdate?.(userMessage.text);
+    
+    // Update current thread with new user message
+    await actions.addMessage(state.currentThreadId, userMessage);
+    setIsRunning(true);
+
+    try {
+      // Use the message handler (no more complex logic here!)
+      const response = await messageHandler.sendMessage(userMessage.text);
+
+      console.log("AI RESPONSE", response);
+      
+      const assistantMessage: ChatMessage = {
+        id: generateId(),
+        role: "assistant",
+        text: response.content,
+        timestamp: Date.now(),
+      };
+      
+      // Update current thread with assistant response
+      await actions.addMessage(state.currentThreadId, assistantMessage);
+    } catch (error) {
+      // Handle errors gracefully
+      const errorMessage: ChatMessage = {
+        id: generateId(),
+        role: "assistant", 
+        text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
+        timestamp: Date.now(),
+      };
+      
+      await actions.addMessage(state.currentThreadId, errorMessage);
+    } finally {
+      setIsRunning(false);
+    }
+  };
+
+  // Handle edit message - CLEANER with messageHandler
+  const onEdit = async (message: AppendMessage) => {
+    // Extract text from AppendMessage content array
+    if (message.content.length !== 1 || message.content[0]?.type !== "text") {
+      throw new Error("Only text content is supported");
+    }
+
+    // Find the index where to insert the edited message
+    const index = currentMessages.findIndex((m) => m.id === message.parentId) + 1;
+
+    // Keep messages up to the parent
+    const newMessages = [...currentMessages.slice(0, index)];
+
+    // Add the edited message in custom format
+    const editedMessage: ChatMessage = {
+      id: generateId(),
+      role: "user",
+      text: message.content[0].text,
+      timestamp: Date.now(),
+    };
+    newMessages.push(editedMessage);
+
+    // Update currentMessage state to expose to queries
+    onMessageUpdate?.(editedMessage.text);
+
+    // Update messages using the new context action
+    await actions.updateMessages(state.currentThreadId, newMessages);
+    setIsRunning(true);
+
+    try {
+      // Use the message handler (clean!)
+      const response = await messageHandler.sendMessage(editedMessage.text);
+      
+      const assistantMessage: ChatMessage = {
+        id: generateId(),
+        role: "assistant",
+        text: response.content,
+        timestamp: Date.now(),
+      };
+      
+      newMessages.push(assistantMessage);
+      await actions.updateMessages(state.currentThreadId, newMessages);
+    } catch (error) {
+      // Handle errors gracefully
+      const errorMessage: ChatMessage = {
+        id: generateId(),
+        role: "assistant", 
+        text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
+        timestamp: Date.now(),
+      };
+      
+      newMessages.push(errorMessage);
+      await actions.updateMessages(state.currentThreadId, newMessages);
+    } finally {
+      setIsRunning(false);
+    }
+  };
+
+  // Thread list adapter for managing multiple threads (same as your current implementation)
+  const threadListAdapter: ExternalStoreThreadListAdapter = {
+    threadId: state.currentThreadId,
+    threads: state.threadList.filter((t): t is RegularThreadData => t.status === "regular"),
+    archivedThreads: state.threadList.filter((t): t is ArchivedThreadData => t.status === "archived"),
+
+    onSwitchToNewThread: async () => {
+      const threadId = await actions.createThread("New Chat");
+      actions.setCurrentThread(threadId);
+    },
+
+    onSwitchToThread: (threadId) => {
+      actions.setCurrentThread(threadId);
+    },
+
+    onRename: async (threadId, newTitle) => {
+      await actions.updateThread(threadId, { title: newTitle });
+    },
+
+    onArchive: async (threadId) => {
+      await actions.updateThread(threadId, { status: "archived" });
+    },
+
+    onDelete: async (threadId) => {
+      await actions.deleteThread(threadId);
+    },
+  };
+
+  const runtime = useExternalStoreRuntime({
+    messages: currentMessages,
+    setMessages: (messages) => {
+      actions.updateMessages(state.currentThreadId, messages);
+    },
+    convertMessage,
+    isRunning,
+    onNew,
+    onEdit,
+    adapters: {
+      threadList: threadListAdapter,
+    },
+  });
+
+  if (!state.isInitialized) {
+    return <div>Loading...</div>;
+  }
+
+  return (
+    <AssistantRuntimeProvider runtime={runtime}>
+      <ChatContainer>
+        <ThreadList />
+        <Thread />
+      </ChatContainer>
+    </AssistantRuntimeProvider>
+  );
+}
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts b/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
index 14dcf5a718..53287d1ccd 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
@@ -75,21 +75,7 @@ export class QueryHandler implements MessageHandler {
         )
       );
 
-      // Extract reply text from the query result (same logic as your current implementation)
-      let content: string;
-      if (typeof result === "string") {
-        content = result;
-      } else if (result && typeof result === "object") {
-        content =
-          (result as any).response ??
-          (result as any).message ??
-          (result as any).content ??
-          JSON.stringify(result);
-      } else {
-        content = String(result);
-      }
-
-      return { content };
+     return result.message
     } catch (e: any) {
       throw new Error(e?.message || "Query execution failed");
     }
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts b/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
index f820d55eee..caab3e8585 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
@@ -35,6 +35,7 @@ export interface ChatMessage {
     deleteMessages(threadId: string): Promise<void>;
     clearAllData(): Promise<void>;
     resetDatabase(): Promise<void>;
+    cleanup(): Promise<void>;
   }
   
   // ============================================================================
@@ -75,6 +76,7 @@ export interface ChatMessage {
     storage: ChatStorage;
     messageHandler: MessageHandler;
     onMessageUpdate?: (message: string) => void;
+    onConversationUpdate?: (conversationHistory: ChatMessage[]) => void;
   }
   
   export interface ChatPanelProps {
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
index 8e62e42744..0ef893c75f 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
@@ -9,8 +9,8 @@ import { ChatMessage, ChatThread, ChatStorage } from "../types/chatTypes";
 
 export function createChatStorage(tableName: string): ChatStorage {
   const dbName = `ChatDB_${tableName}`;
-  const threadsTable = `${tableName}_threads`;
-  const messagesTable = `${tableName}_messages`;
+  const threadsTable = `${dbName}.${tableName}_threads`;
+  const messagesTable = `${dbName}.${tableName}_messages`;
   
   return {
     async initialize() {
@@ -18,7 +18,6 @@ export function createChatStorage(tableName: string): ChatStorage {
         // Create database with localStorage backend
         await alasql.promise(`CREATE LOCALSTORAGE DATABASE IF NOT EXISTS ${dbName}`);
         await alasql.promise(`ATTACH LOCALSTORAGE DATABASE ${dbName}`);
-        await alasql.promise(`USE ${dbName}`);
 
         // Create threads table
         await alasql.promise(`
@@ -176,6 +175,14 @@ export function createChatStorage(tableName: string): ChatStorage {
         console.error("Failed to reset database:", error);
         throw error;
       }
+    },
+    async cleanup() {
+      try {
+        await alasql.promise(`DROP LOCALSTORAGE DATABASE IF EXISTS ${dbName}`);
+      } catch (error) {
+        console.error("Failed to cleanup database:", error);
+        throw error;
+      }
     }
   };
 }
\ No newline at end of file

From 5d88dbe0deb34341548ba2cccffd1964ddcfb4d9 Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Tue, 15 Jul 2025 00:31:52 +0500
Subject: [PATCH 45/54] add event listeners for the chat component

---
 .../src/comps/comps/chatComp/chatComp.tsx     | 87 ++++++++++++++++---
 .../comps/comps/chatComp/chatPropertyView.tsx | 41 +++++----
 .../comps/chatComp/components/ChatCore.tsx    | 11 ++-
 .../chatComp/components/ChatCoreMain.tsx      | 26 +++++-
 .../components/assistant-ui/thread.tsx        | 12 ++-
 .../comps/comps/chatComp/types/chatTypes.ts   |  3 +
 6 files changed, 140 insertions(+), 40 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
index 59e93b4bfe..51164c1423 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
@@ -8,6 +8,7 @@ import { withDefault } from "comps/generators";
 import { BoolControl } from "comps/controls/boolControl";
 import { dropdownControl } from "comps/controls/dropdownControl";
 import QuerySelectControl from "comps/controls/querySelectControl";
+import { eventHandlerControl, EventConfigType } from "comps/controls/eventHandlerControl";
 import { ChatCore } from "./components/ChatCore";
 import { ChatPropertyView } from "./chatPropertyView";
 import { createChatStorage } from "./utils/storageFactory";
@@ -19,7 +20,58 @@ import "@assistant-ui/styles/index.css";
 import "@assistant-ui/styles/markdown.css";
 
 // ============================================================================
-// SIMPLIFIED CHILDREN MAP - ONLY ESSENTIAL PROPS
+// CHAT-SPECIFIC EVENTS
+// ============================================================================
+
+export const componentLoadEvent: EventConfigType = {
+  label: "Component Load",
+  value: "componentLoad",
+  description: "Triggered when the chat component finishes loading - Load existing data from backend",
+};
+
+export const messageSentEvent: EventConfigType = {
+  label: "Message Sent",
+  value: "messageSent",
+  description: "Triggered when a user sends a message - Auto-save user messages",
+};
+
+export const messageReceivedEvent: EventConfigType = {
+  label: "Message Received", 
+  value: "messageReceived",
+  description: "Triggered when a response is received from the AI - Auto-save AI responses",
+};
+
+export const threadCreatedEvent: EventConfigType = {
+  label: "Thread Created",
+  value: "threadCreated",
+  description: "Triggered when a new thread is created - Auto-save new threads",
+};
+
+export const threadUpdatedEvent: EventConfigType = {
+  label: "Thread Updated",
+  value: "threadUpdated",
+  description: "Triggered when a thread is updated - Auto-save thread changes",
+};
+
+export const threadDeletedEvent: EventConfigType = {
+  label: "Thread Deleted",
+  value: "threadDeleted",
+  description: "Triggered when a thread is deleted - Delete thread from backend",
+};
+
+const ChatEventOptions = [
+  componentLoadEvent,
+  messageSentEvent,
+  messageReceivedEvent,
+  threadCreatedEvent,
+  threadUpdatedEvent,
+  threadDeletedEvent,
+] as const;
+
+export const ChatEventHandlerControl = eventHandlerControl(ChatEventOptions);
+
+// ============================================================================
+// SIMPLIFIED CHILDREN MAP - WITH EVENT HANDLERS
 // ============================================================================
 
 function generateUniqueTableName(): string {
@@ -48,6 +100,9 @@ export const chatChildrenMap = {
   // Database Information (read-only)
   databaseName: withDefault(StringControl, ""),
   
+  // Event Handlers
+  onEvent: ChatEventHandlerControl,
+  
   // Exposed Variables (not shown in Property View)
   currentMessage: stringExposingStateControl("currentMessage", ""),
   conversationHistory: stringExposingStateControl("conversationHistory", "[]"),
@@ -119,6 +174,8 @@ const ChatTmpComp = new UICompBuilder(
     // Handle message updates for exposed variable
     const handleMessageUpdate = (message: string) => {
       dispatch(changeChildAction("currentMessage", message, false));
+      // Trigger messageSent event
+      props.onEvent("messageSent");
     };
 
     // Handle conversation history updates for exposed variable
@@ -130,26 +187,32 @@ const ChatTmpComp = new UICompBuilder(
         timestamp: msg.timestamp
       }));
       dispatch(changeChildAction("conversationHistory", JSON.stringify(formattedHistory), false));
+      
+      // Trigger messageReceived event when bot responds
+      const lastMessage = conversationHistory[conversationHistory.length - 1];
+      if (lastMessage && lastMessage.role === 'assistant') {
+        props.onEvent("messageReceived");
+      }
     };
 
-       // Cleanup on unmount
-       useEffect(() => {
-        console.log("cleanup on unmount");
-        return () => {
-          console.log("cleanup on unmount");
-          const tableName = uniqueTableName.current;
-          if (tableName) {
-            storage.cleanup();
-          }
-        };
-      }, []);
+    // Cleanup on unmount
+    useEffect(() => {
+      return () => {
+        const tableName = uniqueTableName.current;
+        if (tableName) {
+          storage.cleanup();
+        }
+      };
+    }, []);
 
     return (
       <ChatCore
         storage={storage}
         messageHandler={messageHandler}
+        placeholder={props.placeholder}
         onMessageUpdate={handleMessageUpdate}
         onConversationUpdate={handleConversationUpdate}
+        onEvent={props.onEvent}
       />
     );
   }
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
index 9e7cac4aba..bfa72bf762 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
@@ -1,7 +1,8 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
 
-import React from "react";
+import React, { useMemo } from "react";
 import { Section, sectionNames } from "lowcoder-design";
+import { placeholderPropertyView } from "../../utils/propertyUtils";
 
 // ============================================================================
 // CLEAN PROPERTY VIEW - FOCUSED ON ESSENTIAL CONFIGURATION
@@ -10,24 +11,8 @@ import { Section, sectionNames } from "lowcoder-design";
 export const ChatPropertyView = React.memo((props: any) => {
   const { children } = props;
 
-  return (
+  return useMemo(() => (
     <>
-      {/* Basic Configuration */}
-      <Section name={sectionNames.basic}>
-        {children.placeholder.propertyView({ 
-          label: "Placeholder Text",
-          placeholder: "Enter placeholder text..."
-        })}
-        
-        {children.databaseName.propertyView({ 
-          label: "Database Name",
-          placeholder: "Database will be auto-generated...",
-          tooltip: "Read-only: Auto-generated database name for data persistence. You can reference this in queries if needed.",
-          disabled: true
-        })}
-        
-      </Section>
-
       {/* Message Handler Configuration */}
       <Section name="Message Handler">
         {children.handlerType.propertyView({ 
@@ -64,8 +49,26 @@ export const ChatPropertyView = React.memo((props: any) => {
         })}
       </Section>
 
+      {/* UI Configuration */}
+      <Section name="UI Configuration">
+        {placeholderPropertyView(children)}
+      </Section>
+
+      {/* Database Information */}
+      <Section name="Database">
+        {children.databaseName.propertyView({ 
+          label: "Database Name",
+          tooltip: "Auto-generated database name for this chat component (read-only)"
+        })}
+      </Section>
+
+      {/* STANDARD EVENT HANDLERS SECTION */}
+      <Section name={sectionNames.interaction}>
+        {children.onEvent.getPropertyView()}
+      </Section>
+
     </>
-  );
+  ), [children]);
 });
 
 ChatPropertyView.displayName = 'ChatPropertyView';
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx
index d153a53d27..af867b7f5b 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCore.tsx
@@ -9,13 +9,22 @@ import { ChatCoreProps } from "../types/chatTypes";
 // CHAT CORE - THE SHARED FOUNDATION
 // ============================================================================
 
-export function ChatCore({ storage, messageHandler, onMessageUpdate, onConversationUpdate }: ChatCoreProps) {
+export function ChatCore({ 
+  storage, 
+  messageHandler, 
+  placeholder,
+  onMessageUpdate, 
+  onConversationUpdate,
+  onEvent
+}: ChatCoreProps) {
   return (
     <ChatProvider storage={storage}>
       <ChatCoreMain 
         messageHandler={messageHandler}
+        placeholder={placeholder}
         onMessageUpdate={onMessageUpdate}
         onConversationUpdate={onConversationUpdate}
+        onEvent={onEvent}
       />
     </ChatProvider>
   );
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
index 4c804e49d0..3efa451bb1 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
@@ -1,6 +1,6 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
 
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
 import {
   useExternalStoreRuntime,
   ThreadMessageLike,
@@ -59,13 +59,22 @@ const ChatContainer = styled.div`
 
 interface ChatCoreMainProps {
   messageHandler: MessageHandler;
+  placeholder?: string;
   onMessageUpdate?: (message: string) => void;
   onConversationUpdate?: (conversationHistory: ChatMessage[]) => void;
+  // STANDARD LOWCODER EVENT PATTERN - SINGLE CALLBACK (OPTIONAL)
+  onEvent?: (eventName: string) => void;
 }
 
 const generateId = () => Math.random().toString(36).substr(2, 9);
 
-export function ChatCoreMain({ messageHandler, onMessageUpdate, onConversationUpdate }: ChatCoreMainProps) {
+export function ChatCoreMain({ 
+  messageHandler, 
+  placeholder,
+  onMessageUpdate, 
+  onConversationUpdate,
+  onEvent
+}: ChatCoreMainProps) {
   const { state, actions } = useChatContext();
   const [isRunning, setIsRunning] = useState(false);
 
@@ -78,10 +87,15 @@ export function ChatCoreMain({ messageHandler, onMessageUpdate, onConversationUp
   console.log("CURRENT MESSAGES", currentMessages);
 
   // Notify parent component of conversation changes
-  React.useEffect(() => {
+  useEffect(() => {
     onConversationUpdate?.(currentMessages);
   }, [currentMessages]);
 
+  // Trigger component load event on mount
+  useEffect(() => {
+    onEvent?.("componentLoad");
+  }, [onEvent]);
+
   // Convert custom format to ThreadMessageLike (same as your current implementation)
   const convertMessage = (message: ChatMessage): ThreadMessageLike => ({
     role: message.role,
@@ -209,6 +223,7 @@ export function ChatCoreMain({ messageHandler, onMessageUpdate, onConversationUp
     onSwitchToNewThread: async () => {
       const threadId = await actions.createThread("New Chat");
       actions.setCurrentThread(threadId);
+      onEvent?.("threadCreated");
     },
 
     onSwitchToThread: (threadId) => {
@@ -217,14 +232,17 @@ export function ChatCoreMain({ messageHandler, onMessageUpdate, onConversationUp
 
     onRename: async (threadId, newTitle) => {
       await actions.updateThread(threadId, { title: newTitle });
+      onEvent?.("threadUpdated");
     },
 
     onArchive: async (threadId) => {
       await actions.updateThread(threadId, { status: "archived" });
+      onEvent?.("threadUpdated");
     },
 
     onDelete: async (threadId) => {
       await actions.deleteThread(threadId);
+      onEvent?.("threadDeleted");
     },
   };
 
@@ -250,7 +268,7 @@ export function ChatCoreMain({ messageHandler, onMessageUpdate, onConversationUp
     <AssistantRuntimeProvider runtime={runtime}>
       <ChatContainer>
         <ThreadList />
-        <Thread />
+        <Thread placeholder={placeholder} />
       </ChatContainer>
     </AssistantRuntimeProvider>
   );
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
index ae3749fb77..d7c27a07f1 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
@@ -22,7 +22,11 @@ import {
   import { MarkdownText } from "./markdown-text";
   import { TooltipIconButton } from "./tooltip-icon-button";
   
-  export const Thread: FC = () => {
+  interface ThreadProps {
+    placeholder?: string;
+  }
+  
+  export const Thread: FC<ThreadProps> = ({ placeholder = "Write a message..." }) => {
     return (
       <ThreadPrimitive.Root
         className="aui-root aui-thread-root"
@@ -47,7 +51,7 @@ import {
   
           <div className="aui-thread-viewport-footer">
             <ThreadScrollToBottom />
-            <Composer />
+            <Composer placeholder={placeholder} />
           </div>
         </ThreadPrimitive.Viewport>
       </ThreadPrimitive.Root>
@@ -110,13 +114,13 @@ import {
     );
   };
   
-  const Composer: FC = () => {
+  const Composer: FC<{ placeholder?: string }> = ({ placeholder = "Write a message..." }) => {
     return (
       <ComposerPrimitive.Root className="aui-composer-root">
         <ComposerPrimitive.Input
           rows={1}
           autoFocus
-          placeholder="Write a message..."
+          placeholder={placeholder}
           className="aui-composer-input"
         />
         <ComposerAction />
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts b/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
index caab3e8585..7efb658d47 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
@@ -75,8 +75,11 @@ export interface ChatMessage {
   export interface ChatCoreProps {
     storage: ChatStorage;
     messageHandler: MessageHandler;
+    placeholder?: string;
     onMessageUpdate?: (message: string) => void;
     onConversationUpdate?: (conversationHistory: ChatMessage[]) => void;
+    // STANDARD LOWCODER EVENT PATTERN - SINGLE CALLBACK
+    onEvent?: (eventName: string) => void;
   }
   
   export interface ChatPanelProps {

From ac38c66b242f0451f63f5d107855de382ff42f96 Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Tue, 15 Jul 2025 22:38:35 +0500
Subject: [PATCH 46/54] add system prompt and improve edit UI

---
 .../src/comps/comps/chatComp/chatComp.tsx     | 64 +++++++++-----
 .../chatComp/components/ChatCoreMain.tsx      |  1 +
 .../components/assistant-ui/thread-list.tsx   | 85 +++++++++++++------
 .../chatComp/handlers/messageHandlers.ts      | 11 ++-
 .../comps/comps/chatComp/types/chatTypes.ts   |  1 +
 5 files changed, 113 insertions(+), 49 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
index 51164c1423..eb227b23f6 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
@@ -15,6 +15,7 @@ import { createChatStorage } from "./utils/storageFactory";
 import { QueryHandler, createMessageHandler } from "./handlers/messageHandlers";
 import { useMemo, useRef, useEffect } from "react";  
 import { changeChildAction } from "lowcoder-core";
+import { ChatMessage } from "./types/chatTypes";
 
 import "@assistant-ui/styles/index.css";
 import "@assistant-ui/styles/markdown.css";
@@ -74,6 +75,30 @@ export const ChatEventHandlerControl = eventHandlerControl(ChatEventOptions);
 // SIMPLIFIED CHILDREN MAP - WITH EVENT HANDLERS
 // ============================================================================
 
+
+export function addSystemPromptToHistory(
+  conversationHistory: ChatMessage[], 
+  systemPrompt: string
+): Array<{ role: string; content: string; timestamp: number }> {
+  // Format conversation history for use in queries
+  const formattedHistory = conversationHistory.map(msg => ({
+    role: msg.role,
+    content: msg.text,
+    timestamp: msg.timestamp
+  }));
+  
+  // Create system message (always exists since we have default)
+  const systemMessage = [{
+    role: "system" as const,
+    content: systemPrompt,
+    timestamp: Date.now() - 1000000 // Ensure it's always first chronologically
+  }];
+  
+  // Return complete history with system prompt prepended
+  return [...systemMessage, ...formattedHistory];
+}
+
+
 function generateUniqueTableName(): string {
   return `chat${Math.floor(1000 + Math.random() * 9000)}`;
  }
@@ -117,7 +142,6 @@ const ChatTmpComp = new UICompBuilder(
   (props, dispatch) => {
 
     const uniqueTableName = useRef<string>();
-
       // Generate unique table name once (with persistence)
     if (!uniqueTableName.current) {
       // Use persisted name if exists, otherwise generate new one
@@ -146,7 +170,7 @@ const ChatTmpComp = new UICompBuilder(
         return new QueryHandler({
           chatQuery: props.chatQuery.value,
           dispatch,
-          streaming: props.streaming
+          streaming: props.streaming,
         });
       } else if (handlerType === "n8n") {
         return createMessageHandler("n8n", {
@@ -168,7 +192,7 @@ const ChatTmpComp = new UICompBuilder(
       props.modelHost,
       props.systemPrompt,
       props.streaming,
-      dispatch
+      dispatch,
     ]);
 
     // Handle message updates for exposed variable
@@ -179,21 +203,23 @@ const ChatTmpComp = new UICompBuilder(
     };
 
     // Handle conversation history updates for exposed variable
-    const handleConversationUpdate = (conversationHistory: any[]) => {
-      // Format conversation history for use in queries
-      const formattedHistory = conversationHistory.map(msg => ({
-        role: msg.role,
-        content: msg.text,
-        timestamp: msg.timestamp
-      }));
-      dispatch(changeChildAction("conversationHistory", JSON.stringify(formattedHistory), false));
-      
-      // Trigger messageReceived event when bot responds
-      const lastMessage = conversationHistory[conversationHistory.length - 1];
-      if (lastMessage && lastMessage.role === 'assistant') {
-        props.onEvent("messageReceived");
-      }
-    };
+   // Handle conversation history updates for exposed variable
+const handleConversationUpdate = (conversationHistory: any[]) => {
+  // Use utility function to create complete history with system prompt
+  const historyWithSystemPrompt = addSystemPromptToHistory(
+    conversationHistory, 
+    props.systemPrompt
+  );
+  
+  // Expose the complete history (with system prompt) for use in queries
+  dispatch(changeChildAction("conversationHistory", JSON.stringify(historyWithSystemPrompt), false));
+  
+  // Trigger messageReceived event when bot responds
+  const lastMessage = conversationHistory[conversationHistory.length - 1];
+  if (lastMessage && lastMessage.role === 'assistant') {
+    props.onEvent("messageReceived");
+  }
+};
 
     // Cleanup on unmount
     useEffect(() => {
@@ -226,5 +252,5 @@ const ChatTmpComp = new UICompBuilder(
 
 export const ChatComp = withExposingConfigs(ChatTmpComp, [
   new NameConfig("currentMessage", "Current user message"),
-  new NameConfig("conversationHistory", "Full conversation history as JSON array"),
+  new NameConfig("conversationHistory", "Full conversation history as JSON array (includes system prompt for API calls)"),
 ]);
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
index 3efa451bb1..79a6272ce8 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
@@ -127,6 +127,7 @@ export function ChatCoreMain({
     setIsRunning(true);
 
     try {
+      
       // Use the message handler (no more complex logic here!)
       const response = await messageHandler.sendMessage(userMessage.text);
 
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
index 54dcbc5089..af703048cf 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
@@ -1,16 +1,16 @@
 import type { FC } from "react";
+import { useState } from "react";
 import {
   ThreadListItemPrimitive,
   ThreadListPrimitive,
+  useThreadListItem,
 } from "@assistant-ui/react";
 import { PencilIcon, PlusIcon, Trash2Icon } from "lucide-react";
-
 import { TooltipIconButton } from "./tooltip-icon-button";
 import { useThreadListItemRuntime } from "@assistant-ui/react";
-import { Button, Flex } from "antd";
+import { Button, Flex, Input } from "antd";
 
 import styled from "styled-components";
-import { useChatContext } from "../context/ChatContext";
 
 const StyledPrimaryButton = styled(Button)`
   // padding: 20px;
@@ -44,12 +44,23 @@ const ThreadListItems: FC = () => {
 };
 
 const ThreadListItem: FC = () => {
+  const [editing, setEditing] = useState(false);
+  
   return (
     <ThreadListItemPrimitive.Root className="aui-thread-list-item">
       <ThreadListItemPrimitive.Trigger className="aui-thread-list-item-trigger">
-        <ThreadListItemTitle />
+        {editing ? (
+          <ThreadListItemEditInput 
+            onFinish={() => setEditing(false)} 
+          />
+        ) : (
+          <ThreadListItemTitle />
+        )}
       </ThreadListItemPrimitive.Trigger>
-      <ThreadListItemRename />
+      <ThreadListItemRename 
+        onStartEdit={() => setEditing(true)} 
+        editing={editing}
+      />
       <ThreadListItemDelete />
     </ThreadListItemPrimitive.Root>
   );
@@ -78,37 +89,57 @@ const ThreadListItemDelete: FC = () => {
 };
 
 
-const ThreadListItemRename: FC = () => {
-  const runtime = useThreadListItemRuntime();
+
+const ThreadListItemEditInput: FC<{ onFinish: () => void }> = ({ onFinish }) => {
+  const threadItem = useThreadListItem();
+  const threadRuntime = useThreadListItemRuntime();
   
-  const handleClick = async () => {
-    // runtime doesn't expose a direct `title` prop; read it from its state
-    let current = "";
-    try {
-      // getState is part of the public runtime surface
-      current = (runtime.getState?.() as any)?.title ?? "";
-    } catch {
-      // fallback – generate a title if the runtime provides a helper
-      if (typeof (runtime as any).generateTitle === "function") {
-        // generateTitle(threadId) in older builds, generateTitle() in newer ones
-        current = (runtime as any).generateTitle((runtime as any).threadId ?? undefined);
-      }
+  const currentTitle = threadItem?.title || "New Chat";
+  
+  const handleRename = async (newTitle: string) => {
+    if (!newTitle.trim() || newTitle === currentTitle){
+      onFinish();
+      return;
     }
-
-    const next = prompt("Rename thread", current)?.trim();
-    if (next && next !== current) {
-      await runtime.rename(next);
+    
+    try {
+      await threadRuntime.rename(newTitle);
+      onFinish();
+    } catch (error) {
+      console.error("Failed to rename thread:", error);
     }
   };
 
+  return (
+    <Input
+      size="small"
+      defaultValue={currentTitle}
+      onBlur={(e) => handleRename(e.target.value)}
+      onPressEnter={(e) => handleRename((e.target as HTMLInputElement).value)}
+      onKeyDown={(e) => {
+        if (e.key === 'Escape') onFinish();
+      }}
+      autoFocus
+      style={{ fontSize: '14px', padding: '2px 8px' }}
+    />
+  );
+};
+
+
+const ThreadListItemRename: FC<{ onStartEdit: () => void; editing: boolean }> = ({ 
+  onStartEdit, 
+  editing 
+}) => {
+  if (editing) return null;
+
   return (
     <TooltipIconButton
-      tooltip="Rename thread"
       variant="ghost"
-      onClick={handleClick}
-      className="aui-thread-list-item-rename"
+      tooltip="Rename thread"
+      onClick={onStartEdit}
     >
       <PencilIcon />
     </TooltipIconButton>
   );
-};
\ No newline at end of file
+};
+  
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts b/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
index 53287d1ccd..a4f20ec123 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
@@ -55,7 +55,7 @@ export class QueryHandler implements MessageHandler {
   constructor(private config: QueryHandlerConfig) {}
 
   async sendMessage(message: string): Promise<MessageResponse> {
-    const { chatQuery, dispatch } = this.config;
+    const { chatQuery, dispatch} = this.config;
     
     // If no query selected or dispatch unavailable, return mock response
     if (!chatQuery || !dispatch) {
@@ -64,17 +64,22 @@ export class QueryHandler implements MessageHandler {
     }
 
     try {
+
       const result: any = await getPromiseAfterDispatch(
         dispatch,
         routeByNameAction(
           chatQuery,
           executeQueryAction({
-            // Send the user prompt as variable named 'prompt' by default
-            args: { prompt: { value: message } },
+            // Send both individual prompt and full conversation history
+            args: { 
+              prompt: { value: message },
+            },
           })
         )
       );
 
+      console.log("QUERY RESULT", result);
+
      return result.message
     } catch (e: any) {
       throw new Error(e?.message || "Query execution failed");
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts b/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
index 7efb658d47..25595b44df 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
@@ -66,6 +66,7 @@ export interface ChatMessage {
     chatQuery: string;
     dispatch: any;
     streaming?: boolean;
+    systemPrompt?: string;
   }
   
   // ============================================================================

From b2dcf3fb22bb6900c2a2159016fe39b8d1f1fe8b Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Tue, 15 Jul 2025 22:57:32 +0500
Subject: [PATCH 47/54] add docs button in chat component

---
 .../src/comps/comps/chatComp/chatPropertyView.tsx   | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
index bfa72bf762..793da2b5f1 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
@@ -1,7 +1,7 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
 
 import React, { useMemo } from "react";
-import { Section, sectionNames } from "lowcoder-design";
+import { Section, sectionNames, DocLink } from "lowcoder-design";
 import { placeholderPropertyView } from "../../utils/propertyUtils";
 
 // ============================================================================
@@ -13,6 +13,17 @@ export const ChatPropertyView = React.memo((props: any) => {
 
   return useMemo(() => (
     <>
+      {/* Help & Documentation - Outside of Section */}
+      <div style={{ padding: "8px 16px", marginBottom: "16px", borderBottom: "1px solid #f0f0f0" }}>
+        <DocLink 
+          style={{ marginTop: 8 }} 
+          href="https://docs.lowcoder.cloud/lowcoder-documentation" 
+          title="Open Lowcoder Documentation"
+        >
+          📖 View Documentation
+        </DocLink>
+      </div>
+
       {/* Message Handler Configuration */}
       <Section name="Message Handler">
         {children.handlerType.propertyView({ 

From 35b061459fe0289ff4caa483c9f91d48dda83cfc Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Wed, 16 Jul 2025 18:39:15 +0500
Subject: [PATCH 48/54] fix no threads infinite re render

---
 .../comps/chatComp/components/context/ChatContext.tsx  | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
index 65670edff8..e126109da2 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
@@ -303,6 +303,9 @@ export function ChatProvider({ children, storage }: {
   };
 
   const deleteThread = async (threadId: string) => {
+    // Determine if this is the last remaining thread BEFORE we delete it
+    const isLastThread = state.threadList.length === 1;
+
     // Update local state first
     dispatch({ type: "DELETE_THREAD", threadId });
     
@@ -310,6 +313,13 @@ export function ChatProvider({ children, storage }: {
     try {
       await storage.deleteThread(threadId);
       dispatch({ type: "MARK_SAVED" });
+      // avoid deleting the last thread
+      // if there are no threads left, create a new one
+      // avoid infinite re-renders
+      if (isLastThread) {
+        const newThreadId = await createThread("New Chat");
+        setCurrentThread(newThreadId);
+      }
     } catch (error) {
       console.error("Failed to delete thread:", error);
     }

From b2d9d118929c3079bb0142f346bf90af13960f94 Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Wed, 16 Jul 2025 22:31:40 +0500
Subject: [PATCH 49/54] fix table name for better queries

---
 .../packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx   | 1 +
 .../lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
index eb227b23f6..da3bf6be1e 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
@@ -253,4 +253,5 @@ const handleConversationUpdate = (conversationHistory: any[]) => {
 export const ChatComp = withExposingConfigs(ChatTmpComp, [
   new NameConfig("currentMessage", "Current user message"),
   new NameConfig("conversationHistory", "Full conversation history as JSON array (includes system prompt for API calls)"),
+  new NameConfig("databaseName", "Database name for SQL queries (ChatDB_<componentName>)"),
 ]);
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
index 0ef893c75f..b4d092af59 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
@@ -9,8 +9,8 @@ import { ChatMessage, ChatThread, ChatStorage } from "../types/chatTypes";
 
 export function createChatStorage(tableName: string): ChatStorage {
   const dbName = `ChatDB_${tableName}`;
-  const threadsTable = `${dbName}.${tableName}_threads`;
-  const messagesTable = `${dbName}.${tableName}_messages`;
+  const threadsTable = `${dbName}.threads`;
+  const messagesTable = `${dbName}.messages`;
   
   return {
     async initialize() {

From aa405854e2c2978ab6a71869dc35a369c130bfd8 Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Thu, 17 Jul 2025 00:19:04 +0500
Subject: [PATCH 50/54] add custom loader

---
 .../components/assistant-ui/thread.tsx        | 36 +++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
index d7c27a07f1..d28bc07c9e 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
@@ -21,6 +21,34 @@ import {
   import { Button } from "../ui/button";
   import { MarkdownText } from "./markdown-text";
   import { TooltipIconButton } from "./tooltip-icon-button";
+  import { Spin, Flex } from "antd";
+  import { LoadingOutlined } from "@ant-design/icons";
+  import styled from "styled-components";
+  const SimpleANTDLoader = () => {
+    const antIcon = <LoadingOutlined style={{ fontSize: 24 }} spin />;
+    
+    return (
+      <div style={{ textAlign: 'left', width: '100%' }}>
+        <Flex align="center" gap={12} style={{ paddingLeft: '16px' }}>
+          <Spin indicator={antIcon} size="small" />
+          <span style={{ color: '#666', fontSize: '14px' }}>Working on it...</span>
+        </Flex>
+      </div>
+    );
+  };
+
+  const StyledThreadRoot = styled(ThreadPrimitive.Root)`
+  /* Hide entire assistant message container when it contains running status */
+  .aui-assistant-message-root:has([data-status="running"]) {
+    display: none;
+  }
+  
+  /* Fallback for older browsers that don't support :has() */
+  .aui-assistant-message-content [data-status="running"] {
+    display: none;
+  }
+`;
+
   
   interface ThreadProps {
     placeholder?: string;
@@ -28,7 +56,7 @@ import {
   
   export const Thread: FC<ThreadProps> = ({ placeholder = "Write a message..." }) => {
     return (
-      <ThreadPrimitive.Root
+      <StyledThreadRoot
         className="aui-root aui-thread-root"
         style={{
           ["--thread-max-width" as string]: "42rem",
@@ -44,6 +72,10 @@ import {
               AssistantMessage: AssistantMessage,
             }}
           />
+
+          <ThreadPrimitive.If running>
+            <SimpleANTDLoader />
+          </ThreadPrimitive.If>
   
           <ThreadPrimitive.If empty={false}>
             <div className="aui-thread-viewport-spacer" />
@@ -54,7 +86,7 @@ import {
             <Composer placeholder={placeholder} />
           </div>
         </ThreadPrimitive.Viewport>
-      </ThreadPrimitive.Root>
+      </StyledThreadRoot>
     );
   };
   

From b1bc01a609103c3ca00392eaa93c436a790622cd Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Fri, 18 Jul 2025 21:06:16 +0500
Subject: [PATCH 51/54] add translations for the chat component

---
 .../src/comps/comps/chatComp/chatComp.tsx     | 35 +++++-----
 .../comps/comps/chatComp/chatPropertyView.tsx | 62 +++++++++--------
 .../chatComp/components/ChatCoreMain.tsx      |  7 +-
 .../comps/chatComp/components/ChatPanel.tsx   |  3 +-
 .../components/assistant-ui/thread-list.tsx   |  7 +-
 .../components/assistant-ui/thread.tsx        | 15 ++--
 .../components/context/ChatContext.tsx        |  9 +--
 client/packages/lowcoder/src/comps/index.tsx  |  8 +--
 .../packages/lowcoder/src/i18n/locales/en.ts  | 69 ++++++++++++++++++-
 9 files changed, 146 insertions(+), 69 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
index da3bf6be1e..0091ed6ab4 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatComp.tsx
@@ -16,6 +16,7 @@ import { QueryHandler, createMessageHandler } from "./handlers/messageHandlers";
 import { useMemo, useRef, useEffect } from "react";  
 import { changeChildAction } from "lowcoder-core";
 import { ChatMessage } from "./types/chatTypes";
+import { trans } from "i18n";
 
 import "@assistant-ui/styles/index.css";
 import "@assistant-ui/styles/markdown.css";
@@ -25,39 +26,39 @@ import "@assistant-ui/styles/markdown.css";
 // ============================================================================
 
 export const componentLoadEvent: EventConfigType = {
-  label: "Component Load",
+  label: trans("chat.componentLoad"),
   value: "componentLoad",
-  description: "Triggered when the chat component finishes loading - Load existing data from backend",
+  description: trans("chat.componentLoadDesc"),
 };
 
 export const messageSentEvent: EventConfigType = {
-  label: "Message Sent",
+  label: trans("chat.messageSent"),
   value: "messageSent",
-  description: "Triggered when a user sends a message - Auto-save user messages",
+  description: trans("chat.messageSentDesc"),
 };
 
 export const messageReceivedEvent: EventConfigType = {
-  label: "Message Received", 
-  value: "messageReceived",
-  description: "Triggered when a response is received from the AI - Auto-save AI responses",
+  label: trans("chat.messageReceived"),
+  value: "messageReceived", 
+  description: trans("chat.messageReceivedDesc"),
 };
 
 export const threadCreatedEvent: EventConfigType = {
-  label: "Thread Created",
+  label: trans("chat.threadCreated"),
   value: "threadCreated",
-  description: "Triggered when a new thread is created - Auto-save new threads",
+  description: trans("chat.threadCreatedDesc"),
 };
 
 export const threadUpdatedEvent: EventConfigType = {
-  label: "Thread Updated",
+  label: trans("chat.threadUpdated"),
   value: "threadUpdated",
-  description: "Triggered when a thread is updated - Auto-save thread changes",
+  description: trans("chat.threadUpdatedDesc"),
 };
 
 export const threadDeletedEvent: EventConfigType = {
-  label: "Thread Deleted",
+  label: trans("chat.threadDeleted"),
   value: "threadDeleted",
-  description: "Triggered when a thread is deleted - Delete thread from backend",
+  description: trans("chat.threadDeletedDesc"),
 };
 
 const ChatEventOptions = [
@@ -104,8 +105,8 @@ function generateUniqueTableName(): string {
  }
 
 const ModelTypeOptions = [
-  { label: "Query", value: "query" },
-  { label: "N8N Workflow", value: "n8n" },
+  { label: trans("chat.handlerTypeQuery"), value: "query" },
+  { label: trans("chat.handlerTypeN8N"), value: "n8n" },
 ] as const;
 
 export const chatChildrenMap = {
@@ -116,11 +117,11 @@ export const chatChildrenMap = {
   handlerType: dropdownControl(ModelTypeOptions, "query"),
   chatQuery: QuerySelectControl,                    // Only used for "query" type
   modelHost: withDefault(StringControl, ""),        // Only used for "n8n" type
-  systemPrompt: withDefault(StringControl, "You are a helpful assistant."),
+  systemPrompt: withDefault(StringControl, trans("chat.defaultSystemPrompt")),
   streaming: BoolControl.DEFAULT_TRUE,
   
   // UI Configuration  
-  placeholder: withDefault(StringControl, "Chat Component"),
+  placeholder: withDefault(StringControl, trans("chat.defaultPlaceholder")),
   
   // Database Information (read-only)
   databaseName: withDefault(StringControl, ""),
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
index 793da2b5f1..0e2fd02901 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/chatPropertyView.tsx
@@ -3,6 +3,7 @@
 import React, { useMemo } from "react";
 import { Section, sectionNames, DocLink } from "lowcoder-design";
 import { placeholderPropertyView } from "../../utils/propertyUtils";
+import { trans } from "i18n";
 
 // ============================================================================
 // CLEAN PROPERTY VIEW - FOCUSED ON ESSENTIAL CONFIGURATION
@@ -25,51 +26,56 @@ export const ChatPropertyView = React.memo((props: any) => {
       </div>
 
       {/* Message Handler Configuration */}
-      <Section name="Message Handler">
+      <Section name={trans("chat.messageHandler")}>
         {children.handlerType.propertyView({ 
-          label: "Handler Type",
-          tooltip: "How messages are processed"
+          label: trans("chat.handlerType"),
+          tooltip: trans("chat.handlerTypeTooltip"),
         })}
-        
-        {/* Show chatQuery field only for "query" handler */}
-        {children.handlerType.value === "query" && (
+
+        {/* Conditional Query Selection */}
+        {children.handlerType.getView() === "query" && (
           children.chatQuery.propertyView({ 
-            label: "Chat Query",
-            placeholder: "Select a query to handle messages"
+            label: trans("chat.chatQuery"),
+            placeholder: trans("chat.chatQueryPlaceholder"),
           })
         )}
-        
-        {/* Show modelHost field only for "n8n" handler */}
-        {children.handlerType.value === "n8n" && (
+
+        {/* Conditional N8N Configuration */}
+        {children.handlerType.getView() === "n8n" && (
           children.modelHost.propertyView({ 
-            label: "N8N Webhook URL",
-            placeholder: "http://localhost:5678/webhook/...",
-            tooltip: "N8N webhook endpoint for processing messages"
+            label: trans("chat.modelHost"),
+            placeholder: trans("chat.modelHostPlaceholder"),
+            tooltip: trans("chat.modelHostTooltip"),
           })
         )}
-        
+
         {children.systemPrompt.propertyView({ 
-          label: "System Prompt",
-          placeholder: "You are a helpful assistant...",
-          tooltip: "Initial instructions for the AI"
+          label: trans("chat.systemPrompt"),
+          placeholder: trans("chat.systemPromptPlaceholder"),
+          tooltip: trans("chat.systemPromptTooltip"),
         })}
-        
-        {children.streaming.propertyView({ 
-          label: "Enable Streaming",
-          tooltip: "Stream responses in real-time (when supported)"
+
+          {children.streaming.propertyView({ 
+          label: trans("chat.streaming"),
+          tooltip: trans("chat.streamingTooltip"),
         })}
       </Section>
 
       {/* UI Configuration */}
-      <Section name="UI Configuration">
-        {placeholderPropertyView(children)}
+      <Section name={trans("chat.uiConfiguration")}>
+          {children.placeholder.propertyView({ 
+            label: trans("chat.placeholderLabel"),
+            placeholder: trans("chat.defaultPlaceholder"),
+            tooltip: trans("chat.placeholderTooltip"),
+          })}
       </Section>
 
-      {/* Database Information */}
-      <Section name="Database">
+      {/* Database Section */}
+      <Section name={trans("chat.database")}>
         {children.databaseName.propertyView({ 
-          label: "Database Name",
-          tooltip: "Auto-generated database name for this chat component (read-only)"
+          label: trans("chat.databaseName"),
+          tooltip: trans("chat.databaseNameTooltip"),
+          readonly: true
         })}
       </Section>
 
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
index 79a6272ce8..0de9525848 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
@@ -18,6 +18,7 @@ import {
 } from "./context/ChatContext";
 import { MessageHandler } from "../types/chatTypes";
 import styled from "styled-components";
+import { trans } from "i18n";
 
 // ============================================================================
 // STYLED COMPONENTS (same as your current ChatMain)
@@ -147,7 +148,7 @@ export function ChatCoreMain({
       const errorMessage: ChatMessage = {
         id: generateId(),
         role: "assistant", 
-        text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
+        text: trans("chat.errorUnknown"),
         timestamp: Date.now(),
       };
       
@@ -204,7 +205,7 @@ export function ChatCoreMain({
       const errorMessage: ChatMessage = {
         id: generateId(),
         role: "assistant", 
-        text: `Sorry, I encountered an error: ${error instanceof Error ? error.message : 'Unknown error'}`,
+        text: trans("chat.errorUnknown"),
         timestamp: Date.now(),
       };
       
@@ -222,7 +223,7 @@ export function ChatCoreMain({
     archivedThreads: state.threadList.filter((t): t is ArchivedThreadData => t.status === "archived"),
 
     onSwitchToNewThread: async () => {
-      const threadId = await actions.createThread("New Chat");
+      const threadId = await actions.createThread(trans("chat.newChatTitle"));
       actions.setCurrentThread(threadId);
       onEvent?.("threadCreated");
     },
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx
index a36c1f38ec..530c3fce31 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx
@@ -5,6 +5,7 @@ import { ChatCore } from "./ChatCore";
 import { createChatStorage } from "../utils/storageFactory";
 import { N8NHandler } from "../handlers/messageHandlers";
 import { ChatPanelProps } from "../types/chatTypes";
+import { trans } from "i18n";
 
 import "@assistant-ui/styles/index.css";
 import "@assistant-ui/styles/markdown.css";
@@ -16,7 +17,7 @@ import "@assistant-ui/styles/markdown.css";
 export function ChatPanel({
   tableName,
   modelHost,
-  systemPrompt = "You are a helpful assistant.",
+  systemPrompt = trans("chat.defaultSystemPrompt"),
   streaming = true,
   onMessageUpdate
 }: ChatPanelProps) {
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
index af703048cf..46bf98eed4 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread-list.tsx
@@ -9,6 +9,7 @@ import { PencilIcon, PlusIcon, Trash2Icon } from "lucide-react";
 import { TooltipIconButton } from "./tooltip-icon-button";
 import { useThreadListItemRuntime } from "@assistant-ui/react";
 import { Button, Flex, Input } from "antd";
+import { trans } from "i18n";
 
 import styled from "styled-components";
 
@@ -33,7 +34,7 @@ const ThreadListNew: FC = () => {
   return (
     <ThreadListPrimitive.New asChild>
       <StyledPrimaryButton size="middle" type="primary" icon={<PlusIcon size={16}/>}>
-        New Thread
+        {trans("chat.newThread")}
       </StyledPrimaryButton>
     </ThreadListPrimitive.New>
   );
@@ -69,7 +70,7 @@ const ThreadListItem: FC = () => {
 const ThreadListItemTitle: FC = () => {
   return (
     <p className="aui-thread-list-item-title" style={{margin: 0}}>
-      <ThreadListItemPrimitive.Title fallback="New Chat" />
+      <ThreadListItemPrimitive.Title fallback={trans("chat.newChatTitle")} />
     </p>
   );
 };
@@ -94,7 +95,7 @@ const ThreadListItemEditInput: FC<{ onFinish: () => void }> = ({ onFinish }) =>
   const threadItem = useThreadListItem();
   const threadRuntime = useThreadListItemRuntime();
   
-  const currentTitle = threadItem?.title || "New Chat";
+  const currentTitle = threadItem?.title || trans("chat.newChatTitle");
   
   const handleRename = async (newTitle: string) => {
     if (!newTitle.trim() || newTitle === currentTitle){
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
index d28bc07c9e..8a2de20f0d 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
@@ -6,6 +6,7 @@ import {
     ThreadPrimitive,
   } from "@assistant-ui/react";
   import type { FC } from "react";
+  import { trans } from "i18n";
   import {
     ArrowDownIcon,
     CheckIcon,
@@ -54,7 +55,7 @@ import {
     placeholder?: string;
   }
   
-  export const Thread: FC<ThreadProps> = ({ placeholder = "Write a message..." }) => {
+  export const Thread: FC<ThreadProps> = ({ placeholder = trans("chat.composerPlaceholder") }) => {
     return (
       <StyledThreadRoot
         className="aui-root aui-thread-root"
@@ -110,7 +111,7 @@ import {
         <div className="aui-thread-welcome-root">
           <div className="aui-thread-welcome-center">
             <p className="aui-thread-welcome-message">
-              How can I help you today?
+              {trans("chat.welcomeMessage")}
             </p>
           </div>
           <ThreadWelcomeSuggestions />
@@ -124,29 +125,29 @@ import {
       <div className="aui-thread-welcome-suggestions">
         <ThreadPrimitive.Suggestion
           className="aui-thread-welcome-suggestion"
-          prompt="What is the weather in Tokyo?"
+          prompt={trans("chat.suggestionWeather")}
           method="replace"
           autoSend
         >
           <span className="aui-thread-welcome-suggestion-text">
-            What is the weather in Tokyo?
+            {trans("chat.suggestionWeather")}
           </span>
         </ThreadPrimitive.Suggestion>
         <ThreadPrimitive.Suggestion
           className="aui-thread-welcome-suggestion"
-          prompt="What is assistant-ui?"
+          prompt={trans("chat.suggestionAssistant")}
           method="replace"
           autoSend
         >
           <span className="aui-thread-welcome-suggestion-text">
-            What is assistant-ui?
+            {trans("chat.suggestionAssistant")}
           </span>
         </ThreadPrimitive.Suggestion>
       </div>
     );
   };
   
-  const Composer: FC<{ placeholder?: string }> = ({ placeholder = "Write a message..." }) => {
+  const Composer: FC<{ placeholder?: string }> = ({ placeholder = trans("chat.composerPlaceholder") }) => {
     return (
       <ComposerPrimitive.Root className="aui-composer-root">
         <ComposerPrimitive.Input
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
index e126109da2..1a31222a9a 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/context/ChatContext.tsx
@@ -2,6 +2,7 @@
 
 import React, { createContext, useContext, useReducer, useEffect, ReactNode } from "react";
 import { ChatStorage, ChatMessage, ChatThread } from "../../types/chatTypes";
+import { trans } from "i18n";
 
 // ============================================================================
 // UPDATED CONTEXT WITH CLEAN TYPES
@@ -51,7 +52,7 @@ const initialState: ChatState = {
   isInitialized: false,
   isLoading: false,
   currentThreadId: "default",
-  threadList: [{ threadId: "default", status: "regular", title: "New Chat" }],
+  threadList: [{ threadId: "default", status: "regular", title: trans("chat.newChatTitle") }],
   threads: new Map([["default", []]]),
   lastSaved: 0,
 };
@@ -228,7 +229,7 @@ export function ChatProvider({ children, storage }: {
         const defaultThread: ChatThread = {
           threadId: "default",
           status: "regular",
-          title: "New Chat",
+          title: trans("chat.newChatTitle"),
           createdAt: Date.now(),
           updatedAt: Date.now(),
         };
@@ -252,7 +253,7 @@ export function ChatProvider({ children, storage }: {
     dispatch({ type: "SET_CURRENT_THREAD", threadId });
   };
 
-  const createThread = async (title: string = "New Chat"): Promise<string> => {
+  const createThread = async (title: string = trans("chat.newChatTitle")): Promise<string> => {
     const threadId = `thread-${Date.now()}`;
     const newThread: ThreadData = {
       threadId,
@@ -317,7 +318,7 @@ export function ChatProvider({ children, storage }: {
       // if there are no threads left, create a new one
       // avoid infinite re-renders
       if (isLastThread) {
-        const newThreadId = await createThread("New Chat");
+        const newThreadId = await createThread(trans("chat.newChatTitle"));
         setCurrentThread(newThreadId);
       }
     } catch (error) {
diff --git a/client/packages/lowcoder/src/comps/index.tsx b/client/packages/lowcoder/src/comps/index.tsx
index b6eb5ad312..bd4d0f54e6 100644
--- a/client/packages/lowcoder/src/comps/index.tsx
+++ b/client/packages/lowcoder/src/comps/index.tsx
@@ -1684,12 +1684,12 @@ export var uiCompMap: Registry = {
     },
   },
   chat: {
-    name: "Chat",
-    enName: "Chat", 
-    description: "Chat Component",
+    name: trans("uiComp.chatCompName"),
+    enName: "AI Chat", 
+    description: trans("uiComp.chatCompDesc"),
     categories: ["collaboration"],
     icon: CommentCompIcon, // Use existing icon for now
-    keywords: "chat,conversation",
+    keywords: trans("uiComp.chatCompKeywords"),
     comp: ChatComp,
     layoutInfo: {
       w: 12,
diff --git a/client/packages/lowcoder/src/i18n/locales/en.ts b/client/packages/lowcoder/src/i18n/locales/en.ts
index b897add3f7..05ab251a06 100644
--- a/client/packages/lowcoder/src/i18n/locales/en.ts
+++ b/client/packages/lowcoder/src/i18n/locales/en.ts
@@ -1413,12 +1413,77 @@ export const en = {
     "timerCompDesc": "A component that displays a countdown or elapsed time, useful for tracking durations and deadlines.",
     "timerCompKeywords": "timer, countdown, elapsed time, tracking, durations, deadlines",
 
+    "chatCompName": "AI Chat",
+    "chatCompDesc": "An interactive chat component for AI conversations with support for multiple message handlers and streaming responses.",
+    "chatCompKeywords": "chat, ai, conversation, assistant, messaging, streaming",
   },
 
-
+  
+  "chat": {
+    // Property View Labels & Tooltips
+    "handlerType": "Handler Type",
+    "handlerTypeTooltip": "How messages are processed",
+    "chatQuery": "Chat Query", 
+    "chatQueryPlaceholder": "Select a query to handle messages",
+    "modelHost": "N8N Webhook URL",
+    "modelHostPlaceholder": "http://localhost:5678/webhook/...",
+    "modelHostTooltip": "N8N webhook endpoint for processing messages",
+    "systemPrompt": "System Prompt",
+    "systemPromptPlaceholder": "You are a helpful assistant...",
+    "systemPromptTooltip": "Initial instructions for the AI",
+    "streaming": "Enable Streaming", 
+    "streamingTooltip": "Stream responses in real-time (when supported)",
+    "databaseName": "Database Name",
+    "databaseNameTooltip": "Auto-generated database name for this chat component (read-only)",
+    
+    // Default Values & Placeholders
+    "defaultSystemPrompt": "You are a helpful assistant.",
+    "defaultPlaceholder": "Type your message here...",
+    "composerPlaceholder": "Write a message...",
+    "defaultErrorMessage": "Sorry, I encountered an error. Please try again.",
+    "newChatTitle": "New Chat",
+    "placeholderLabel": "Placeholder",
+    "placeholderTooltip": "Placeholder text for the composer input",
+    "newThread": "New Thread",
+    "welcomeMessage": "How can I help you today?",
+    "suggestionWeather": "What's the weather in Tokyo?",
+    "suggestionAssistant": "What's the news today?",
+    
+    
+    
+    // Error Messages
+    "errorUnknown": "Sorry, I encountered an error. Please try again.",
+    
+    // Handler Types
+    "handlerTypeQuery": "Query",
+    "handlerTypeN8N": "N8N Workflow",
+    
+    // Section Names
+    "messageHandler": "Message Handler",
+    "uiConfiguration": "UI Configuration", 
+    "database": "Database",
+    
+    // Event Labels & Descriptions
+    "componentLoad": "Component Load",
+    "componentLoadDesc": "Triggered when the chat component finishes loading - Load existing data from backend",
+    "messageSent": "Message Sent",
+    "messageSentDesc": "Triggered when a user sends a message - Auto-save user messages", 
+    "messageReceived": "Message Received",
+    "messageReceivedDesc": "Triggered when a response is received from the AI - Auto-save AI responses",
+    "threadCreated": "Thread Created", 
+    "threadCreatedDesc": "Triggered when a new thread is created - Auto-save new threads",
+    "threadUpdated": "Thread Updated",
+    "threadUpdatedDesc": "Triggered when a thread is updated - Auto-save thread changes",
+    "threadDeleted": "Thread Deleted",
+    "threadDeletedDesc": "Triggered when a thread is deleted - Delete thread from backend",
+    
+    // Exposed Variables (for documentation)
+    "currentMessage": "Current user message",
+    "conversationHistory": "Full conversation history as JSON array",
+    "databaseNameExposed": "Database name for SQL queries (ChatDB_<componentName>)"
+  },
   // eighth part
 
-
   "comp": {
     "menuViewDocs": "View Documentation",
     "menuViewPlayground": "View interactive Playground",

From 68b2802559fefdd0c324f2f0bc8770e788507e23 Mon Sep 17 00:00:00 2001
From: Faran Javed <faran1997@outlook.com>
Date: Fri, 18 Jul 2025 21:09:23 +0500
Subject: [PATCH 52/54] remove console logs

---
 .../src/comps/comps/chatComp/components/ChatCoreMain.tsx   | 7 -------
 .../src/comps/comps/chatComp/handlers/messageHandlers.ts   | 4 +---
 .../src/comps/comps/chatComp/utils/storageFactory.ts       | 2 --
 3 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
index 0de9525848..4bc7363b9a 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
@@ -79,14 +79,9 @@ export function ChatCoreMain({
   const { state, actions } = useChatContext();
   const [isRunning, setIsRunning] = useState(false);
 
-  console.log("CHAT CORE STATE", state);
-
   // Get messages for current thread
   const currentMessages = actions.getCurrentMessages();
 
-
-  console.log("CURRENT MESSAGES", currentMessages);
-
   // Notify parent component of conversation changes
   useEffect(() => {
     onConversationUpdate?.(currentMessages);
@@ -132,8 +127,6 @@ export function ChatCoreMain({
       // Use the message handler (no more complex logic here!)
       const response = await messageHandler.sendMessage(userMessage.text);
 
-      console.log("AI RESPONSE", response);
-      
       const assistantMessage: ChatMessage = {
         id: generateId(),
         role: "assistant",
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts b/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
index a4f20ec123..1d674d04eb 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
@@ -78,9 +78,7 @@ export class QueryHandler implements MessageHandler {
         )
       );
 
-      console.log("QUERY RESULT", result);
-
-     return result.message
+      return result.message
     } catch (e: any) {
       throw new Error(e?.message || "Query execution failed");
     }
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts b/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
index b4d092af59..cc563ba66d 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/utils/storageFactory.ts
@@ -41,7 +41,6 @@ export function createChatStorage(tableName: string): ChatStorage {
           )
         `);
 
-        console.log(`✅ Chat database initialized: ${dbName}`);
       } catch (error) {
         console.error(`Failed to initialize chat database ${dbName}:`, error);
         throw error;
@@ -170,7 +169,6 @@ export function createChatStorage(tableName: string): ChatStorage {
         
         // Reinitialize fresh
         await this.initialize();
-        console.log(`✅ Database reset and reinitialized: ${dbName}`);
       } catch (error) {
         console.error("Failed to reset database:", error);
         throw error;

From 4f9fbbafb9847168098d8999dd5d12d3c993a9e8 Mon Sep 17 00:00:00 2001
From: FARAN <faran1997@outlook.com>
Date: Tue, 22 Jul 2025 20:29:18 +0500
Subject: [PATCH 53/54] add file attachments components

---
 client/packages/lowcoder/package.json         |   2 +
 .../components/assistant-ui/thread.tsx        |   3 +
 .../chatComp/components/ui/attachment.tsx     | 346 ++++++++++++++++++
 .../comps/chatComp/components/ui/avatar.tsx   |  72 ++++
 .../comps/chatComp/components/ui/dialog.tsx   | 230 ++++++++++++
 client/yarn.lock                              |  74 +++-
 6 files changed, 726 insertions(+), 1 deletion(-)
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/ui/attachment.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/ui/avatar.tsx
 create mode 100644 client/packages/lowcoder/src/comps/comps/chatComp/components/ui/dialog.tsx

diff --git a/client/packages/lowcoder/package.json b/client/packages/lowcoder/package.json
index 04a4c30535..323a2a7b7f 100644
--- a/client/packages/lowcoder/package.json
+++ b/client/packages/lowcoder/package.json
@@ -33,6 +33,8 @@
     "@jsonforms/core": "^3.5.1",
     "@lottiefiles/dotlottie-react": "^0.13.0",
     "@manaflair/redux-batch": "^1.0.0",
+    "@radix-ui/react-avatar": "^1.1.10",
+    "@radix-ui/react-dialog": "^1.1.14",
     "@radix-ui/react-slot": "^1.2.3",
     "@radix-ui/react-tooltip": "^1.2.7",
     "@rjsf/antd": "^5.24.9",
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
index 8a2de20f0d..4018cbe5da 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/assistant-ui/thread.tsx
@@ -25,6 +25,7 @@ import {
   import { Spin, Flex } from "antd";
   import { LoadingOutlined } from "@ant-design/icons";
   import styled from "styled-components";
+import { ComposerAddAttachment, ComposerAttachments } from "../ui/attachment";
   const SimpleANTDLoader = () => {
     const antIcon = <LoadingOutlined style={{ fontSize: 24 }} spin />;
     
@@ -150,6 +151,8 @@ import {
   const Composer: FC<{ placeholder?: string }> = ({ placeholder = trans("chat.composerPlaceholder") }) => {
     return (
       <ComposerPrimitive.Root className="aui-composer-root">
+        <ComposerAttachments />
+        <ComposerAddAttachment />
         <ComposerPrimitive.Input
           rows={1}
           autoFocus
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/attachment.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/attachment.tsx
new file mode 100644
index 0000000000..1e430e5b32
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/attachment.tsx
@@ -0,0 +1,346 @@
+"use client";
+
+import { PropsWithChildren, useEffect, useState, type FC } from "react";
+import { CircleXIcon, FileIcon, PaperclipIcon } from "lucide-react";
+import {
+  AttachmentPrimitive,
+  ComposerPrimitive,
+  MessagePrimitive,
+  useAttachment,
+} from "@assistant-ui/react";
+import styled from "styled-components";
+import {
+  Tooltip,
+  TooltipContent,
+  TooltipTrigger,
+} from "./tooltip";
+import {
+  Dialog,
+  DialogTitle,
+  DialogTrigger,
+  DialogOverlay,
+  DialogPortal,
+  DialogContent,
+} from "./dialog";
+import { Avatar, AvatarImage, AvatarFallback } from "./avatar";
+import { TooltipIconButton } from "../assistant-ui/tooltip-icon-button";
+
+// ============================================================================
+// STYLED COMPONENTS
+// ============================================================================
+
+const StyledDialogTrigger = styled(DialogTrigger)`
+  cursor: pointer;
+  transition: background-color 0.2s;
+  padding: 2px;
+  border-radius: 4px;
+
+  &:hover {
+    background-color: rgba(0, 0, 0, 0.05);
+  }
+`;
+
+const StyledAvatar = styled(Avatar)`
+  background-color: #f1f5f9;
+  display: flex;
+  width: 40px;
+  height: 40px;
+  align-items: center;
+  justify-content: center;
+  border-radius: 8px;
+  border: 1px solid #e2e8f0;
+  font-size: 14px;
+`;
+
+const AttachmentContainer = styled.div`
+  display: flex;
+  height: 48px;
+  width: 160px;
+  align-items: center;
+  justify-content: center;
+  gap: 8px;
+  border-radius: 8px;
+  border: 1px solid #e2e8f0;
+  padding: 4px;
+`;
+
+const AttachmentTextContainer = styled.div`
+  flex-grow: 1;
+  flex-basis: 0;
+  overflow: hidden;
+`;
+
+const AttachmentName = styled.p`
+  color: #64748b;
+  font-size: 12px;
+  font-weight: bold;
+  overflow: hidden;
+  text-overflow: ellipsis;
+  white-space: nowrap;
+  word-break: break-all;
+  margin: 0;
+  line-height: 16px;
+`;
+
+const AttachmentType = styled.p`
+  color: #64748b;
+  font-size: 12px;
+  margin: 0;
+  line-height: 16px;
+`;
+
+const AttachmentRoot = styled(AttachmentPrimitive.Root)`
+  position: relative;
+  margin-top: 12px;
+`;
+
+const StyledTooltipIconButton = styled(TooltipIconButton)`
+  color: #64748b;
+  position: absolute;
+  right: -12px;
+  top: -12px;
+  width: 24px;
+  height: 24px;
+
+  & svg {
+    background-color: white;
+    width: 16px;
+    height: 16px;
+    border-radius: 50%;
+  }
+`;
+
+const UserAttachmentsContainer = styled.div`
+  display: flex;
+  width: 100%;
+  flex-direction: row;
+  gap: 12px;
+  grid-column: 1 / -1;
+  grid-row-start: 1;
+  justify-content: flex-end;
+`;
+
+const ComposerAttachmentsContainer = styled.div`
+  display: flex;
+  width: 100%;
+  flex-direction: row;
+  gap: 12px;
+  overflow-x: auto;
+`;
+
+const StyledComposerButton = styled(TooltipIconButton)`
+  margin: 10px 0;
+  width: 32px;
+  height: 32px;
+  padding: 8px;
+  transition: opacity 0.2s ease-in;
+`;
+
+const ScreenReaderOnly = styled.span`
+  position: absolute;
+  left: -10000px;
+  width: 1px;
+  height: 1px;
+  overflow: hidden;
+`;
+
+// ============================================================================
+// UTILITY HOOKS
+// ============================================================================
+
+// Simple replacement for useShallow (removes zustand dependency)
+const useShallow = <T,>(selector: (state: any) => T): ((state: any) => T) => selector;
+
+const useFileSrc = (file: File | undefined) => {
+  const [src, setSrc] = useState<string | undefined>(undefined);
+
+  useEffect(() => {
+    if (!file) {
+      setSrc(undefined);
+      return;
+    }
+
+    const objectUrl = URL.createObjectURL(file);
+    setSrc(objectUrl);
+
+    return () => {
+      URL.revokeObjectURL(objectUrl);
+    };
+  }, [file]);
+
+  return src;
+};
+
+const useAttachmentSrc = () => {
+  const { file, src } = useAttachment(
+    useShallow((a): { file?: File; src?: string } => {
+      if (a.type !== "image") return {};
+      if (a.file) return { file: a.file };
+      const src = a.content?.filter((c: any) => c.type === "image")[0]?.image;
+      if (!src) return {};
+      return { src };
+    })
+  );
+
+  return useFileSrc(file) ?? src;
+};
+
+// ============================================================================
+// ATTACHMENT COMPONENTS
+// ============================================================================
+
+type AttachmentPreviewProps = {
+  src: string;
+};
+
+const AttachmentPreview: FC<AttachmentPreviewProps> = ({ src }) => {
+  const [isLoaded, setIsLoaded] = useState(false);
+
+  return (
+    <img
+      src={src}
+      style={{
+        width: "auto",
+        height: "auto",
+        maxWidth: "75dvh",
+        maxHeight: "75dvh",
+        display: isLoaded ? "block" : "none",
+        overflow: "clip",
+      }}
+      onLoad={() => setIsLoaded(true)}
+      alt="Preview"
+    />
+  );
+};
+
+const AttachmentPreviewDialog: FC<PropsWithChildren> = ({ children }) => {
+  const src = useAttachmentSrc();
+
+  if (!src) return <>{children}</>;
+
+  return (
+    <Dialog>
+      <StyledDialogTrigger asChild>
+        {children}
+      </StyledDialogTrigger>
+      <AttachmentDialogContent>
+        <DialogTitle>
+          <ScreenReaderOnly>Image Attachment Preview</ScreenReaderOnly>
+        </DialogTitle>
+        <AttachmentPreview src={src} />
+      </AttachmentDialogContent>
+    </Dialog>
+  );
+};
+
+const AttachmentThumb: FC = () => {
+  const isImage = useAttachment((a) => a.type === "image");
+  const src = useAttachmentSrc();
+  return (
+    <StyledAvatar>
+      <AvatarFallback delayMs={isImage ? 200 : 0}>
+        <FileIcon />
+      </AvatarFallback>
+      <AvatarImage src={src} />
+    </StyledAvatar>
+  );
+};
+
+const AttachmentUI: FC = () => {
+  const canRemove = useAttachment((a) => a.source !== "message");
+  const typeLabel = useAttachment((a) => {
+    const type = a.type;
+    switch (type) {
+      case "image":
+        return "Image";
+      case "document":
+        return "Document";
+      case "file":
+        return "File";
+      default:
+        const _exhaustiveCheck: never = type;
+        throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);
+    }
+  });
+  
+  return (
+    <Tooltip>
+      <AttachmentRoot>
+        <AttachmentPreviewDialog>
+          <TooltipTrigger asChild>
+            <AttachmentContainer>
+              <AttachmentThumb />
+              <AttachmentTextContainer>
+                <AttachmentName>
+                  <AttachmentPrimitive.Name />
+                </AttachmentName>
+                <AttachmentType>{typeLabel}</AttachmentType>
+              </AttachmentTextContainer>
+            </AttachmentContainer>
+          </TooltipTrigger>
+        </AttachmentPreviewDialog>
+        {canRemove && <AttachmentRemove />}
+      </AttachmentRoot>
+      <TooltipContent side="top">
+        <AttachmentPrimitive.Name />
+      </TooltipContent>
+    </Tooltip>
+  );
+};
+
+const AttachmentRemove: FC = () => {
+  return (
+    <AttachmentPrimitive.Remove asChild>
+      <StyledTooltipIconButton
+        tooltip="Remove file"
+        side="top"
+      >
+        <CircleXIcon />
+      </StyledTooltipIconButton>
+    </AttachmentPrimitive.Remove>
+  );
+};
+
+// ============================================================================
+// EXPORTED COMPONENTS
+// ============================================================================
+
+export const UserMessageAttachments: FC = () => {
+  return (
+    <UserAttachmentsContainer>
+      <MessagePrimitive.Attachments components={{ Attachment: AttachmentUI }} />
+    </UserAttachmentsContainer>
+  );
+};
+
+export const ComposerAttachments: FC = () => {
+  return (
+    <ComposerAttachmentsContainer>
+      <ComposerPrimitive.Attachments
+        components={{ Attachment: AttachmentUI }}
+      />
+    </ComposerAttachmentsContainer>
+  );
+};
+
+export const ComposerAddAttachment: FC = () => {
+  return (
+    <ComposerPrimitive.AddAttachment asChild>
+      <StyledComposerButton
+        tooltip="Add Attachment"
+        variant="ghost"
+      >
+        <PaperclipIcon />
+      </StyledComposerButton>
+    </ComposerPrimitive.AddAttachment>
+  );
+};
+
+const AttachmentDialogContent: FC<PropsWithChildren> = ({ children }) => (
+  <DialogPortal>
+    <DialogOverlay />
+    <DialogContent className="aui-dialog-content">
+      {children}
+    </DialogContent>
+  </DialogPortal>
+);
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/avatar.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/avatar.tsx
new file mode 100644
index 0000000000..aa9032abc1
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/avatar.tsx
@@ -0,0 +1,72 @@
+"use client"
+
+import * as React from "react"
+import * as AvatarPrimitive from "@radix-ui/react-avatar"
+import styled from "styled-components"
+
+const StyledAvatarRoot = styled(AvatarPrimitive.Root)`
+  position: relative;
+  display: flex;
+  width: 32px;
+  height: 32px;
+  flex-shrink: 0;
+  overflow: hidden;
+  border-radius: 50%;
+`;
+
+const StyledAvatarImage = styled(AvatarPrimitive.Image)`
+  aspect-ratio: 1;
+  width: 100%;
+  height: 100%;
+`;
+
+const StyledAvatarFallback = styled(AvatarPrimitive.Fallback)`
+  background-color: #f1f5f9;
+  display: flex;
+  width: 100%;
+  height: 100%;
+  align-items: center;
+  justify-content: center;
+  border-radius: 50%;
+`;
+
+function Avatar({
+  className,
+  ...props
+}: Omit<React.ComponentProps<typeof AvatarPrimitive.Root>, 'ref'>) {
+  return (
+    <StyledAvatarRoot
+      data-slot="avatar"
+      className={className}
+      {...props}
+    />
+  )
+}
+
+function AvatarImage({
+  className,
+  ...props
+}: Omit<React.ComponentProps<typeof AvatarPrimitive.Image>, 'ref'>) {
+  return (
+    <StyledAvatarImage
+      data-slot="avatar-image"
+      className={className}
+      {...props}
+    />
+  )
+}
+
+function AvatarFallback({
+  className,
+  ...props
+}: Omit<React.ComponentProps<typeof AvatarPrimitive.Fallback>, 'ref'>) {
+  return (
+    <StyledAvatarFallback
+      data-slot="avatar-fallback"
+      className={className}
+      {...props}
+    />
+  )
+}
+
+export { Avatar, AvatarImage, AvatarFallback }
\ No newline at end of file
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/dialog.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/dialog.tsx
new file mode 100644
index 0000000000..058caebae3
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ui/dialog.tsx
@@ -0,0 +1,230 @@
+"use client"
+
+import * as React from "react"
+import * as DialogPrimitive from "@radix-ui/react-dialog"
+import { XIcon } from "lucide-react"
+import styled from "styled-components"
+
+const StyledDialogOverlay = styled(DialogPrimitive.Overlay)`
+  position: fixed;
+  inset: 0;
+  z-index: 50;
+  background-color: rgba(0, 0, 0, 0.5);
+`;
+
+const StyledDialogContent = styled(DialogPrimitive.Content)`
+  background-color: white;
+  position: fixed;
+  top: 50%;
+  left: 50%;
+  z-index: 50;
+  display: grid;
+  width: 100%;
+  max-width: calc(100% - 2rem);
+  transform: translate(-50%, -50%);
+  gap: 16px;
+  border-radius: 8px;
+  border: 1px solid #e2e8f0;
+  padding: 24px;
+  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
+
+  @media (min-width: 640px) {
+    max-width: 512px;
+  }
+`;
+
+const StyledDialogClose = styled(DialogPrimitive.Close)`
+  position: absolute;
+  top: 16px;
+  right: 16px;
+  border-radius: 4px;
+  opacity: 0.7;
+  transition: opacity 0.2s;
+  border: none;
+  background: none;
+  cursor: pointer;
+  padding: 4px;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+
+  &:hover {
+    opacity: 1;
+  }
+
+  & svg {
+    width: 16px;
+    height: 16px;
+  }
+`;
+
+const StyledDialogHeader = styled.div`
+  display: flex;
+  flex-direction: column;
+  gap: 8px;
+  text-align: center;
+
+  @media (min-width: 640px) {
+    text-align: left;
+  }
+`;
+
+const StyledDialogFooter = styled.div`
+  display: flex;
+  flex-direction: column-reverse;
+  gap: 8px;
+
+  @media (min-width: 640px) {
+    flex-direction: row;
+    justify-content: flex-end;
+  }
+`;
+
+const StyledDialogTitle = styled(DialogPrimitive.Title)`
+  font-size: 18px;
+  line-height: 1;
+  font-weight: 600;
+`;
+
+const StyledDialogDescription = styled(DialogPrimitive.Description)`
+  color: #64748b;
+  font-size: 14px;
+`;
+
+const ScreenReaderOnly = styled.span`
+  position: absolute;
+  left: -10000px;
+  width: 1px;
+  height: 1px;
+  overflow: hidden;
+`;
+
+function Dialog({
+  ...props
+}: React.ComponentProps<typeof DialogPrimitive.Root>) {
+  return <DialogPrimitive.Root data-slot="dialog" {...props} />
+}
+
+function DialogTrigger({
+  ...props
+}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
+  return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
+}
+
+function DialogPortal({
+  ...props
+}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
+  return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
+}
+
+function DialogClose({
+  ...props
+}: React.ComponentProps<typeof DialogPrimitive.Close>) {
+  return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
+}
+
+function DialogOverlay({
+  className,
+  ...props
+}: Omit<React.ComponentProps<typeof DialogPrimitive.Overlay>, 'ref'>) {
+  return (
+    <StyledDialogOverlay
+      data-slot="dialog-overlay"
+      className={className}
+      {...props}
+    />
+  )
+}
+
+function DialogContent({
+  className,
+  children,
+  showCloseButton = true,
+  ...props
+}: Omit<React.ComponentProps<typeof DialogPrimitive.Content>, 'ref'> & {
+  showCloseButton?: boolean
+}) {
+  return (
+    <DialogPortal data-slot="dialog-portal">
+      <DialogOverlay />
+      <StyledDialogContent
+        data-slot="dialog-content"
+        className={className}
+        {...props}
+      >
+        {children}
+        {showCloseButton && (
+          <StyledDialogClose data-slot="dialog-close">
+            <XIcon />
+            <ScreenReaderOnly>Close</ScreenReaderOnly>
+          </StyledDialogClose>
+        )}
+      </StyledDialogContent>
+    </DialogPortal>
+  )
+}
+
+function DialogHeader({ 
+  className, 
+  ...props 
+}: React.ComponentProps<"div">) {
+  return (
+    <StyledDialogHeader
+      data-slot="dialog-header"
+      className={className}
+      {...props}
+    />
+  )
+}
+
+function DialogFooter({ 
+  className, 
+  ...props 
+}: React.ComponentProps<"div">) {
+  return (
+    <StyledDialogFooter
+      data-slot="dialog-footer"
+      className={className}
+      {...props}
+    />
+  )
+}
+
+function DialogTitle({
+  className,
+  ...props
+}: Omit<React.ComponentProps<typeof DialogPrimitive.Title>, 'ref'>) {
+  return (
+    <StyledDialogTitle
+      data-slot="dialog-title"
+      className={className}
+      {...props}
+    />
+  )
+}
+
+function DialogDescription({
+  className,
+  ...props
+}: Omit<React.ComponentProps<typeof DialogPrimitive.Description>, 'ref'>) {
+  return (
+    <StyledDialogDescription
+      data-slot="dialog-description"
+      className={className}
+      {...props}
+    />
+  )
+}
+
+export {
+  Dialog,
+  DialogClose,
+  DialogContent,
+  DialogDescription,
+  DialogFooter,
+  DialogHeader,
+  DialogOverlay,
+  DialogPortal,
+  DialogTitle,
+  DialogTrigger,
+}
\ No newline at end of file
diff --git a/client/yarn.lock b/client/yarn.lock
index e8357b3c08..10f5dafee8 100644
--- a/client/yarn.lock
+++ b/client/yarn.lock
@@ -3401,6 +3401,29 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@radix-ui/react-avatar@npm:^1.1.10":
+  version: 1.1.10
+  resolution: "@radix-ui/react-avatar@npm:1.1.10"
+  dependencies:
+    "@radix-ui/react-context": 1.1.2
+    "@radix-ui/react-primitive": 2.1.3
+    "@radix-ui/react-use-callback-ref": 1.1.1
+    "@radix-ui/react-use-is-hydrated": 0.1.0
+    "@radix-ui/react-use-layout-effect": 1.1.1
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+    react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: 3d63c9b99549c574be0f3f24028ab3f339e51ca85fc0821887f83e30af1342a41b3a3f40bf0fc12cdb2814340342530b4aba6b758deda9e99f6846b41d2f987f
+  languageName: node
+  linkType: hard
+
 "@radix-ui/react-compose-refs@npm:1.1.2, @radix-ui/react-compose-refs@npm:^1.1.2":
   version: 1.1.2
   resolution: "@radix-ui/react-compose-refs@npm:1.1.2"
@@ -3427,6 +3450,38 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@radix-ui/react-dialog@npm:^1.1.14":
+  version: 1.1.14
+  resolution: "@radix-ui/react-dialog@npm:1.1.14"
+  dependencies:
+    "@radix-ui/primitive": 1.1.2
+    "@radix-ui/react-compose-refs": 1.1.2
+    "@radix-ui/react-context": 1.1.2
+    "@radix-ui/react-dismissable-layer": 1.1.10
+    "@radix-ui/react-focus-guards": 1.1.2
+    "@radix-ui/react-focus-scope": 1.1.7
+    "@radix-ui/react-id": 1.1.1
+    "@radix-ui/react-portal": 1.1.9
+    "@radix-ui/react-presence": 1.1.4
+    "@radix-ui/react-primitive": 2.1.3
+    "@radix-ui/react-slot": 1.2.3
+    "@radix-ui/react-use-controllable-state": 1.2.2
+    aria-hidden: ^1.2.4
+    react-remove-scroll: ^2.6.3
+  peerDependencies:
+    "@types/react": "*"
+    "@types/react-dom": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+    react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+    "@types/react-dom":
+      optional: true
+  checksum: 4928c0bf84b3a054eb3b4659b8e87192d8c120333d8437fcbd9d9311502d5eea9e9c87173929d4bfbc0db61b1134fcd98015756011d67ddcd2aed1b4a0134d7c
+  languageName: node
+  linkType: hard
+
 "@radix-ui/react-dismissable-layer@npm:1.1.10":
   version: 1.1.10
   resolution: "@radix-ui/react-dismissable-layer@npm:1.1.10"
@@ -3723,6 +3778,21 @@ __metadata:
   languageName: node
   linkType: hard
 
+"@radix-ui/react-use-is-hydrated@npm:0.1.0":
+  version: 0.1.0
+  resolution: "@radix-ui/react-use-is-hydrated@npm:0.1.0"
+  dependencies:
+    use-sync-external-store: ^1.5.0
+  peerDependencies:
+    "@types/react": "*"
+    react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
+  peerDependenciesMeta:
+    "@types/react":
+      optional: true
+  checksum: 72e68a85a7a4a6dafd255a0cc87b6410bf0356c5e296e2eb82c265559408a735204cd150408b9c0d598057dafad3d51086e0362633bd728e95655b3bfd70ae26
+  languageName: node
+  linkType: hard
+
 "@radix-ui/react-use-layout-effect@npm:1.1.1":
   version: 1.1.1
   resolution: "@radix-ui/react-use-layout-effect@npm:1.1.1"
@@ -14877,6 +14947,8 @@ coolshapes-react@lowcoder-org/coolshapes-react:
     "@jsonforms/core": ^3.5.1
     "@lottiefiles/dotlottie-react": ^0.13.0
     "@manaflair/redux-batch": ^1.0.0
+    "@radix-ui/react-avatar": ^1.1.10
+    "@radix-ui/react-dialog": ^1.1.14
     "@radix-ui/react-slot": ^1.2.3
     "@radix-ui/react-tooltip": ^1.2.7
     "@rjsf/antd": ^5.24.9
@@ -22428,7 +22500,7 @@ coolshapes-react@lowcoder-org/coolshapes-react:
   languageName: node
   linkType: hard
 
-"use-sync-external-store@npm:^1.2.0, use-sync-external-store@npm:^1.4.0":
+"use-sync-external-store@npm:^1.2.0, use-sync-external-store@npm:^1.4.0, use-sync-external-store@npm:^1.5.0":
   version: 1.5.0
   resolution: "use-sync-external-store@npm:1.5.0"
   peerDependencies:

From 3536b2b76e4a208552d3c11e4b34c4fb17557584 Mon Sep 17 00:00:00 2001
From: RAHEEL <mraheeliftikhar1994@gmail.com>
Date: Mon, 28 Jul 2025 18:41:53 +0500
Subject: [PATCH 54/54] integrations more actions

---
 .../chatComp/components/ChatCoreMain.tsx      |  170 +-
 .../comps/chatComp/components/ChatPanel.tsx   |    3 +-
 .../chatComp/handlers/messageHandlers.ts      |   14 +-
 .../comps/comps/chatComp/types/chatTypes.ts   |    5 +-
 .../preLoadComp/actions/Latest_prompt.md      | 4702 +++++++++++++++++
 .../preLoadComp/actions/appConfiguration.ts   |  104 +-
 .../actions/componentConfiguration.ts         |   35 +-
 .../actions/componentManagement.ts            |   52 +-
 .../src/pages/editor/bottom/BottomPanel.tsx   |    8 +-
 9 files changed, 4981 insertions(+), 112 deletions(-)
 create mode 100644 client/packages/lowcoder/src/comps/comps/preLoadComp/actions/Latest_prompt.md

diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
index 4bc7363b9a..2e579ad25e 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
@@ -1,6 +1,6 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/components/ChatCoreMain.tsx
 
-import React, { useState, useEffect } from "react";
+import React, { useState, useEffect, useRef, useContext } from "react";
 import {
   useExternalStoreRuntime,
   ThreadMessageLike,
@@ -19,6 +19,10 @@ import {
 import { MessageHandler } from "../types/chatTypes";
 import styled from "styled-components";
 import { trans } from "i18n";
+import { EditorContext, EditorState } from "@lowcoder-ee/comps/editorState";
+import { configureComponentAction } from "../../preLoadComp/actions/componentConfiguration";
+import { addComponentAction, moveComponentAction, nestComponentAction, resizeComponentAction } from "../../preLoadComp/actions/componentManagement";
+import { applyThemeAction, configureAppMetaAction, setCanvasSettingsAction } from "../../preLoadComp/actions/appConfiguration";
 
 // ============================================================================
 // STYLED COMPONENTS (same as your current ChatMain)
@@ -78,6 +82,14 @@ export function ChatCoreMain({
 }: ChatCoreMainProps) {
   const { state, actions } = useChatContext();
   const [isRunning, setIsRunning] = useState(false);
+  const editorState = useContext(EditorContext);
+  const editorStateRef = useRef(editorState);
+
+  // Keep the ref updated with the latest editorState
+  useEffect(() => {
+    // console.log("EDITOR STATE CHANGE ---> ", editorState);
+    editorStateRef.current = editorState;
+  }, [editorState]);
 
   // Get messages for current thread
   const currentMessages = actions.getCurrentMessages();
@@ -92,6 +104,143 @@ export function ChatCoreMain({
     onEvent?.("componentLoad");
   }, [onEvent]);
 
+  const performAction = async (actions: any[]) => {
+    if (!editorStateRef.current) {
+      console.error("No editorStateRef found");
+      return;
+    }
+  
+    const comp = editorStateRef.current.getUIComp().children.comp;
+    if (!comp) {
+      console.error("No comp found");
+      return;
+    }
+    // const layout = comp.children.layout.getView();
+    // console.log("LAYOUT", layout);
+  
+    for (const actionItem of actions) {
+      const { action, component, ...action_payload } = actionItem;
+  
+      switch (action) {
+        case "place_component":
+          await addComponentAction.execute({
+            actionKey: action,
+            actionValue: "",
+            actionPayload: action_payload,
+            selectedComponent: component,
+            selectedEditorComponent: null,
+            selectedNestComponent: null,
+            editorState: editorStateRef.current,
+            selectedDynamicLayoutIndex: null,
+            selectedTheme: null,
+            selectedCustomShortcutAction: null
+          });
+          break;
+        case "nest_component":
+          await nestComponentAction.execute({
+            actionKey: action,
+            actionValue: "",
+            actionPayload: action_payload,
+            selectedComponent: component,
+            selectedEditorComponent: null,
+            selectedNestComponent: null,
+            editorState: editorStateRef.current,
+            selectedDynamicLayoutIndex: null,
+            selectedTheme: null,
+            selectedCustomShortcutAction: null
+          });
+          break;
+        case "move_component":
+          await moveComponentAction.execute({
+            actionKey: action,
+            actionValue: "",
+            actionPayload: action_payload,
+            selectedComponent: component,
+            selectedEditorComponent: null,
+            selectedNestComponent: null,
+            editorState: editorStateRef.current,
+            selectedDynamicLayoutIndex: null,
+            selectedTheme: null,
+            selectedCustomShortcutAction: null
+          });
+          break;
+        case "resize_component":
+          await resizeComponentAction.execute({
+            actionKey: action,
+            actionValue: "",
+            actionPayload: action_payload,
+            selectedComponent: component,
+            selectedEditorComponent: null,
+            selectedNestComponent: null,
+            editorState: editorStateRef.current,
+            selectedDynamicLayoutIndex: null,
+            selectedTheme: null,
+            selectedCustomShortcutAction: null
+          });
+          break;
+        case "set_properties":
+          await configureComponentAction.execute({
+            actionKey: action,
+            actionValue: component,
+            actionPayload: action_payload,
+            selectedEditorComponent: null,
+            selectedComponent: null,
+            selectedNestComponent: null,
+            editorState: editorStateRef.current,
+            selectedDynamicLayoutIndex: null,
+            selectedTheme: null,
+            selectedCustomShortcutAction: null
+          });
+          break;
+        case "set_theme":
+          await applyThemeAction.execute({
+            actionKey: action,
+            actionValue: component,
+            actionPayload: action_payload,
+            selectedEditorComponent: null,
+            selectedComponent: null,
+            selectedNestComponent: null,
+            editorState: editorStateRef.current,
+            selectedDynamicLayoutIndex: null,
+            selectedTheme: null,
+            selectedCustomShortcutAction: null
+          });
+          break;
+        case "set_app_metadata":
+          await configureAppMetaAction.execute({
+            actionKey: action,
+            actionValue: component,
+            actionPayload: action_payload,
+            selectedEditorComponent: null,
+            selectedComponent: null,
+            selectedNestComponent: null,
+            editorState: editorStateRef.current,
+            selectedDynamicLayoutIndex: null,
+            selectedTheme: null,
+            selectedCustomShortcutAction: null
+          });
+          break;
+        case "set_canvas_setting":
+          await setCanvasSettingsAction.execute({
+            actionKey: action,
+            actionValue: component,
+            actionPayload: action_payload,
+            selectedEditorComponent: null,
+            selectedComponent: null,
+            selectedNestComponent: null,
+            editorState: editorStateRef.current,
+            selectedDynamicLayoutIndex: null,
+            selectedTheme: null,
+            selectedCustomShortcutAction: null
+          });
+          break;
+        default:
+          break;
+      }
+      await new Promise(resolve => setTimeout(resolve, 1000));
+    }
+  };
+
   // Convert custom format to ThreadMessageLike (same as your current implementation)
   const convertMessage = (message: ChatMessage): ThreadMessageLike => ({
     role: message.role,
@@ -123,9 +272,15 @@ export function ChatCoreMain({
     setIsRunning(true);
 
     try {
-      
       // Use the message handler (no more complex logic here!)
-      const response = await messageHandler.sendMessage(userMessage.text);
+      const response = await messageHandler.sendMessage(
+        userMessage.text,
+        state.currentThreadId,
+      );
+
+      if (response?.actions?.length) {
+        performAction(response.actions);
+      }
 
       const assistantMessage: ChatMessage = {
         id: generateId(),
@@ -182,8 +337,15 @@ export function ChatCoreMain({
 
     try {
       // Use the message handler (clean!)
-      const response = await messageHandler.sendMessage(editedMessage.text);
+      const response = await messageHandler.sendMessage(
+        editedMessage.text,
+        state.currentThreadId,
+      );
       
+      if (response?.actions?.length) {
+        performAction(response.actions);
+      }
+
       const assistantMessage: ChatMessage = {
         id: generateId(),
         role: "assistant",
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx
index 530c3fce31..1c9af4f55b 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx
@@ -1,6 +1,6 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/components/ChatPanel.tsx
 
-import React, { useMemo } from "react";
+import { useMemo } from "react";
 import { ChatCore } from "./ChatCore";
 import { createChatStorage } from "../utils/storageFactory";
 import { N8NHandler } from "../handlers/messageHandlers";
@@ -21,7 +21,6 @@ export function ChatPanel({
   streaming = true,
   onMessageUpdate
 }: ChatPanelProps) {
-  
   // Create storage instance
   const storage = useMemo(() => 
     createChatStorage(tableName), 
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts b/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
index 1d674d04eb..13443ac00c 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
@@ -1,7 +1,7 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/handlers/messageHandlers.ts
 
 import { MessageHandler, MessageResponse, N8NHandlerConfig, QueryHandlerConfig } from "../types/chatTypes";
-import { CompAction, routeByNameAction, executeQueryAction } from "lowcoder-core";
+import { routeByNameAction, executeQueryAction } from "lowcoder-core";
 import { getPromiseAfterDispatch } from "util/promiseUtils";
 
 // ============================================================================
@@ -11,7 +11,7 @@ import { getPromiseAfterDispatch } from "util/promiseUtils";
 export class N8NHandler implements MessageHandler {
   constructor(private config: N8NHandlerConfig) {}
 
-  async sendMessage(message: string): Promise<MessageResponse> {
+  async sendMessage(message: string, sessionId?: string): Promise<MessageResponse> {
     const { modelHost, systemPrompt, streaming } = this.config;
     
     if (!modelHost) {
@@ -25,6 +25,7 @@ export class N8NHandler implements MessageHandler {
           'Content-Type': 'application/json',
         },
         body: JSON.stringify({
+          sessionId,
           message,
           systemPrompt: systemPrompt || "You are a helpful assistant.",
           streaming: streaming || false
@@ -36,7 +37,10 @@ export class N8NHandler implements MessageHandler {
       }
 
       const data = await response.json();
-      
+      if (data.output) {
+        const { explanation, actions } = JSON.parse(data.output);
+        return { content: explanation, actions };
+      }
       // Extract content from various possible response formats
       const content = data.response || data.message || data.content || data.text || String(data);
       
@@ -54,7 +58,7 @@ export class N8NHandler implements MessageHandler {
 export class QueryHandler implements MessageHandler {
   constructor(private config: QueryHandlerConfig) {}
 
-  async sendMessage(message: string): Promise<MessageResponse> {
+  async sendMessage(message: string, sessionId?: string): Promise<MessageResponse> {
     const { chatQuery, dispatch} = this.config;
     
     // If no query selected or dispatch unavailable, return mock response
@@ -92,7 +96,7 @@ export class QueryHandler implements MessageHandler {
 export class MockHandler implements MessageHandler {
   constructor(private delay: number = 1000) {}
 
-  async sendMessage(message: string): Promise<MessageResponse> {
+  async sendMessage(message: string, sessionId?: string): Promise<MessageResponse> {
     await new Promise(resolve => setTimeout(resolve, this.delay));
     return { content: `Mock response: ${message}` };
   }
diff --git a/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts b/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
index 25595b44df..f57e656a05 100644
--- a/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
+++ b/client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
@@ -1,5 +1,7 @@
 // client/packages/lowcoder/src/comps/comps/chatComp/types/chatTypes.ts
 
+import { EditorState } from "@lowcoder-ee/comps/editorState";
+
 // ============================================================================
 // CORE MESSAGE AND THREAD TYPES (cleaned up from your existing types)
 // ============================================================================
@@ -43,13 +45,14 @@ export interface ChatMessage {
   // ============================================================================
   
   export interface MessageHandler {
-    sendMessage(message: string): Promise<MessageResponse>;
+    sendMessage(message: string, sessionId?: string): Promise<MessageResponse>;
     // Future: sendMessageStream?(message: string): AsyncGenerator<MessageResponse>;
   }
   
   export interface MessageResponse {
     content: string;
     metadata?: any;
+    actions?: any[];
   }
   
   // ============================================================================
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/Latest_prompt.md b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/Latest_prompt.md
new file mode 100644
index 0000000000..4230c1574f
--- /dev/null
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/Latest_prompt.md
@@ -0,0 +1,4702 @@
+# 🧠 System Prompt for n8n AI Agent — Lowcoder App Builder
+
+## 🎯 Role Definition
+
+You are a visual app-building assistant inside **Lowcoder**, a drag-and-drop low-code platform. Your goal is to convert user queries into a valid sequence of UI actions using allowed actions and components. You must strictly adhere to the defined actions and supported components. When information is incomplete or ambiguous, do not make assumptions—ask for clarification instead of inferring intent.
+
+> 🔐 Always return a raw JSON object. Do **not** use markdown code blocks or any non-JSON formatting. All content must be JSON-serializable.
+
+---
+
+## ✅ Allowed Actions (with Purpose)
+
+### 🧱 Layout & Component Actions
+
+| Action             | Purpose                                                                         |
+| ------------------ | ------------------------------------------------------------------------------- |
+| `place_component`  | Place a new component on the canvas and directly set its properties             |
+| `nest_component`   | Nest a component inside a nested container path and directly set its properties |
+| `move_component`   | Move an existing component to a new position                                    |
+| `resize_component` | Adjust size of a component                                                      |
+| `align_components` | Align multiple components                                                       |
+| `set_properties`   | Set one or more properties on an existing component using its unique name       |
+
+### 🎨 Styling & Appearance
+
+| Action               | Purpose                        |
+| -------------------- | ------------------------------ |
+| `set_style`          | Apply style properties         |
+| `set_theme`          | Change the theme of the app    |
+| `set_canvas_setting` | Update canvas-related settings |
+| `set_global_css`     | Set global CSS rules           |
+
+> For all style and appearance actions (`set_theme`, `set_canvas_setting`, `set_global_css`), use `action_payload` instead of `action_parameters`.
+
+### ⚙️ App-Level Configuration
+
+| Action              | Purpose                     |
+| ------------------- | --------------------------- |
+| `set_app_metadata`  | Update app-level metadata   |
+| `set_key_shortcuts` | Define keyboard shortcuts   |
+| `set_sharing`       | Manage app sharing settings |
+| `publish_app`       | Publish the app for users   |
+
+### 🧠 Logic & Behavior
+
+| Action                  | Purpose                     |
+| ----------------------- | --------------------------- |
+| `set_global_javascript` | Set global JavaScript logic |
+| `test_app`              | Test the current app setup  |
+
+---
+
+## 🛠️ Configuration Actions: App Metadata & Canvas
+
+### `set_app_metadata`
+
+Set high-level metadata for the app:
+
+* `title` (string)
+* `description` (string)
+
+### `set_canvas_setting`
+
+Control layout grid and canvas appearance:
+
+* `maxWidth`: string (must be one of: `"450"`, `"800"`, `"1440"`, `"1920"`, `"3200"`, `"Infinity"`, or `"USER_DEFINE"`). Default: `"1920"`
+* `gridColumns`: number (1–48, default: `24`)
+* `gridRowHeight`: number (4–100, default: `8`)
+* `gridRowCount`: number (default: `Infinity`)
+* `gridPaddingX`, `gridPaddingY`: pixel values (default: `20`)
+* `gridBg`, `gridBgImage`, `gridBgImageRepeat`, `gridBgImageSize`, `gridBgImagePosition`, `gridBgImageOrigin`: visual settings
+
+---
+
+## ✅ General App Rules: Validity, UX, Structure, Component Use
+
+### ✅ Structural Consistency (Default Layout)
+
+For CRUD flows, task lists, and similar apps:
+
+* Title using `text`
+* Search input and status dropdown above data views
+* Primary action button always included
+* Use `modal` or `drawer` for `create`/`edit` flows. For both, always use a flat `container` object — never include `body`, `header`, or `footer` inside the `container`. Nest components directly under `parent_component_name = modal.container` or `drawer.container` — without defining `container.body`, `header`, or `footer`. This rule applies consistently, even when the modal or drawer is placed standalone. The container object must always be empty and flat.
+* Use `table` or `listView` with inline `edit`/`delete` buttons
+* Maintain consistency across similar app types unless user specifies otherwise
+
+### 1. ✅ App Structure Principles
+
+* Separate **Create**, **Edit**, and **List** views
+* Do not nest `table`/`listView` inside `form`
+* Add search/filter inputs above data views
+
+### 2. ✅ Purpose-Driven Component Choice
+
+* Use `table` for tabular data
+* Use `listView`/`card` for visuals or item groups
+* Use `chart`, `timeline`, `step` for summaries and flows. When the user explicitly requests a multi-step form or workflow, and the use of `step` implies data input or interactive flow, use of `step` should reflect the user's intent. If the user explicitly asks for a multi-step form or input collection, the agent should pair the `step` component with a relevant data input component like `form`. Note: the `step` component does not provide a `container` structure for direct nesting — components for each step must be placed outside and logically associated with the step content. Additionally, each step value must be a number and the sequence should start from `1` by default unless a different starting value is explicitly defined using the `initialValue` property in the `step` component. — components for each step must be placed outside and logically associated with the step content.. to capture data or user input.
+* Use `form` inside `modal` or `drawer` for data input **when the user intent requires inline, interruptible, or overlay-style interactions**, such as editing individual records or submitting short tasks. Avoid placing forms inside modals or drawers for primary workflows like login, signup, or onboarding unless the user explicitly requests it. When using `modal` or `drawer`, only use a flat `container` object and directly nest components using `parent_component_name = modal.container` or `drawer.container`. Do not define `container.body`, `header`, or `footer` under any circumstance — even if the component is placed alone.. The `container` field must never include `header`, `body`, or `footer` — even if no other components are present at the time.
+* Use `pageLayout`, `splitLayout`, `tabbedContainer` to organize content
+* Apply **Simplicity Principle**: use the simplest fulfilling component. Avoid over-nesting layout components unless the user explicitly requests it. Default to flat structure whenever possible. For simple pages like login screens or portfolio websites, prefer placing components directly on the canvas — like title, media/image, and content sections — without unnecessary containers or layout wrappers. Avoid wrapping visual or data components like `listView`, `table`, or `card` inside other layout components unless required by logic or explicitly requested. When generating login or signup pages, follow modern UX practices by including a centered `form`, a page title using the `text` component, and a logo image using the `image` component (with a real logo URL) positioned above the form. Avoid using modals for signup or login unless the user specifically requests it. by including a centered `form`, a page title using the `text` component, and a logo image using the `image` component (with a real logo URL) positioned above the form. Avoid using modals for signup or login unless the user specifically requests it — these forms should be placed directly on the page for better usability.. Avoid over-nesting layout components unless the user explicitly requests it. For simple pages like login screens, prefer placing a `form` component directly on the canvas rather than wrapping it inside `pageLayout` or `container` unnecessarily.
+
+### 3. ✅ Action Structure and Data Rules
+
+* Every action must include a valid `layout` object and a properly set `parent_component_name`, consistent with nesting rules.
+
+  * For nested containers (`modal`, `drawer`, `grid`, `listView`, `tabbedContainer`), use a **flat `container` object**. Do **not** define `body`, `header`, or `footer` — these components do not support nested regions. Components must always be directly nested using `parent_component_name = <component>.container`. For `grid` and `listView`, this container represents the repeated item layout and **must never include paths like `container.body.0.view`**. Nest components directly under `grid.container` or `listView.container` using a flat structure, regardless of whether they appear inside a larger app or independently.. Nest components directly under `<component>.container`.
+  * For regular containers, use proper nesting: `container.body.0.view`, `container.header`, or `container.footer` where applicable.
+
+* For `move_component`, ensure the `layout` object includes `x` and `y` values:
+
+  * `x + layout.w` must not exceed canvas `gridColumns`.
+  * `y + layout.h` must not exceed `gridRowCount` (unless `Infinity`).
+  * Validate layout against canvas limits when users request absolute positions.
+
+* For `video` components:
+
+  * Set `layout.h >= 10`
+  * Always include `controls: true` unless explicitly disabled
+
+* For all media components (`video`, `image`, `carousel`):
+
+  * `src` must be a real, publicly accessible URL (e.g., YouTube, Unsplash)
+  * Do not use placeholder or broken links unless explicitly provided
+
+* For `table`:
+
+  * Use stringified JSON for the `data` field
+  * Include 2–3 fully defined columns
+  * Use `{{currentCell}}` in `columns.render` unless user specifies otherwise
+
+* For `timeline`:
+
+  * `value` must be a stringified JSON array of timeline entries
+
+* For `listView` and `grid` components:
+
+  * The `container` defines a visual template for a **single item**.
+  * You may nest multiple components (e.g., image, title, button) inside `listView.container` or `grid.container`.
+  * This template is automatically repeated using the `itemDataName` reference.
+  * Do not define `container.body`, `header`, or `footer` in these components — only layout for the item.
+
+* Populate all data-driven components (e.g., `listView`, `grid`, `table`) with **3+ realistic sample entries**.
+
+* Return a **single valid JSON object** with two top-level fields:
+
+  * `explanation`: A bullet-point summary of the app or change
+  * `actions`: An array of valid UI actions
+
+* If the user input is invalid, vague, or unsupported:
+
+  * Ask for clarification in `explanation`
+  * Return `actions: []`
+  * Do not generate actions without explicit user approval
+
+If an invalid or unsupported request is made, include an error in `explanation` and return an empty `actions` array.
+
+---
+
+## 🧰 Component Handling Strategy
+
+### ✅ Decision Flow
+
+* Determine whether the query is:
+
+  * **Fully specified** (clear features and layout): Build and return valid `actions`.
+  * **Known pattern but underspecified** (e.g., "create a todo app", "create a portfolio website"):
+
+    * Return a **bullet-point plan** in the `explanation`.
+    * Set `actions: []`.
+    * Ask the user to confirm or customize before proceeding.
+  * **Ambiguous or vague**: Ask for clarification in `explanation`, do not generate actions.
+
+* Always format `explanation` as bullet points.
+
+* Only generate and return actions after receiving explicit confirmation (e.g., "go ahead", "implement this").
+
+* Once approved, generate a complete and valid UI action sequence with:
+
+  * Accurate `layout`, valid nesting, and realistic sample data
+  * All required fields populated and compliant with container rules
+
+### ✅ Component Properties Reference (Required + Optional)
+
+#### 📍 Component: `audio`
+
+**Required Fields:**
+- `src` (string): Audio source URL
+
+**Optional Fields:**
+- `autoPlay` (boolean): Autoplay audio
+- `controls` (boolean): Show controls
+- `loop` (boolean): Loop audio
+- `style` (object): Audio style
+
+**Example Output:**
+```json
+{
+  "autoPlay": <boolean>,
+  "controls": <boolean>,
+  "loop": <boolean>,
+  "src": <string>,
+  "style": <object>
+}
+```
+
+---
+
+#### 📍 Component: `autoComplete`
+
+**Required Fields:**
+
+- `items` (string): A stringified array of `{ value, label }` objects.
+- `value` (string): The currently selected value.
+- `label` (object): Includes `text`, `width`, `widthUnit`, and `position`.
+- `allowClear` (boolean): Whether the user can clear the input.
+
+**Optional Fields:**
+- `defaultValue` (string): Default selection when the component loads.
+- `filterOptionsByInput` (boolean): Filter the dropdown list as the user types.
+- `ignoreCase` (boolean): Case-insensitive matching.
+- `searchFirstPY` (boolean): Match based on first letter of pinyin.
+- `searchLabelOnly` (boolean): Only search within label field.
+- `valueOrLabel` (string): Use `"value"` or `"label"` in the output.
+- `valueInItems` (boolean|string): Whether the value must be in the items list.
+- `selectedOption` (object|string): Selected item’s full object (if needed).
+- `autocompleteIconColor` (string): Icon color (e.g., `"blue"`).
+- `autoCompleteType` (string): Autocomplete mode, typically `"normal"`.
+- `componentSize` (string): `"small"`, `"medium"`, or `"large"`.
+- `showDataLoadingIndicators` (boolean): Whether to show loading indicator.
+- `animationStyle`, `childrenInputFieldStyle`, `inputFieldStyle`, `labelStyle`, `style`: UI styling objects.
+- `prefixIcon` / suffixIcon (icon): Icon config for either side.
+- `tabIndex` (number), `viewRef` (ref): Accessibility and programmatic control.
+
+**Example Output:**
+```json
+{
+  "value": "",
+  "defaultValue": "",
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "validationType": "Text",
+  "allowClear": true,
+  "items": "[\n  { \"value\": \"1-BeiJing\", \"label\": \"北京\" },\n  { \"value\": \"2-ShangHai\", \"label\": \"上海\" },\n  { \"value\": \"3-GuangDong\", \"label\": \"广东\" },\n  { \"value\": \"4-ShenZhen\", \"label\": \"深圳\" }\n]",
+  "filterOptionsByInput": true,
+  "ignoreCase": true,
+  "searchFirstPY": true,
+  "searchLabelOnly": true,
+  "valueOrLabel": "label",
+  "autoCompleteType": "normal",
+  "autocompleteIconColor": "blue",
+  "componentSize": "small",
+  "valueInItems": true,
+  "selectedOption": {},
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always provide items as a JSON.stringify version of an array of `{ value, label }` objects.
+> - When building region/city-based inputs, combine `searchFirstPY` and `searchLabelOnly` for better UX.
+> - Ensure the `value` exists in `items` when `valueInItems` is true or enforced.
+
+---
+
+#### 📍 Component: `avatar`
+
+**Required Fields:**
+- `icon` (string): Icon path used if no image is provided.
+- `iconSize` (number|string): Size of the icon/avatar.
+- `avatarLabel` (string): Text shown next to the avatar (e.g., user name).
+- `avatarCatption` (string): Secondary label (e.g., email address).
+
+**Optional Fields:**
+- `shape` (string): Avatar shape — `"circle"` or `"square"`.
+- `src` (string): Image source URL (used if `icon` is not set).
+- `title` (string): Tooltip text or fallback title.
+- `labelPosition` (string): `"left"` or `"right"` — controls avatar label alignment.
+- `alignmentPosition` (string): `"left"` or `"right"` — aligns the entire avatar group.
+- `badgeType` (string): Type of badge (e.g., `"dot"` or `"number"`).
+- `badgeCount` (number|string): Count shown on the badge.
+- `badgeSize` (string|number): Size of the badge (`"default"`, `"small"`, or pixel value).
+- `badgeTitle` (string): Tooltip/title for the badge.
+- `overflowCount` (number|string): Maximum value before showing `+N`.
+- `options` (object): Dropdown menu configuration.
+  - Must follow structure:
+    ```json
+    {
+      "optionType": "manual",
+      "manual": {
+        "manual": [{ "label": "Option 1" }, { "label": "Option 2" }]
+      },
+      "mapData": { "data": "[]" }
+    }
+    ```
+- `showDataLoadingIndicators` (boolean): Show loading spinner when avatar is fetching data.
+- `style`, `labelStyle`, `avatarStyle`, `captionStyle` (object): Custom CSS styling for different parts.
+
+**Example Output:**
+```json
+{
+  "icon": "/icon:solid/user",
+  "iconSize": "40",
+  "shape": "circle",
+  "title": "",
+  "src": "",
+  "avatarLabel": "{{'{{'}}{{'currentUser.name'}}{{'\}}'}}",
+  "avatarCatption": "{{'{{'}}{{'currentUser.email'}}{{'\}}'}}",
+  "labelPosition": "left",
+  "alignmentPosition": "left",
+  "options": {
+    "optionType": "manual",
+    "manual": {
+      "manual": [
+        { "label": "Option 1" },
+        { "label": "Option 2" }
+      ]
+    },
+    "mapData": {
+      "data": "[]"
+    }
+  },
+  "badgeType": "number",
+  "badgeCount": "0",
+  "badgeSize": "default",
+  "overflowCount": "99",
+  "badgeTitle": "",
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Any field can be populated using a dynamic expression (e.g., `{{'{{'}}{{'currentUser.name'}}{{'\}}'}}`) or a static literal (e.g., `"John Doe"`).
+> - If no `src` is provided, use `icon` and `iconSize` to render the avatar.
+> - `options` should be defined for dropdown-enabled avatars.
+> - Use `shape: "circle"` by default for better visual appearance.
+> - Always ensure labels and captions are meaningful, even when using dynamic bindings.
+
+---
+
+#### 📍 Component: `avatarGroup`
+
+**Required Fields:**
+- `avatars` (object): Defines the avatar list. Must include:
+  - `optionType`: `"manual"` or `"mapData"`
+  - `manual.manual`: Array of avatar objects, each with:
+    - `src` (string): Image URL
+    - `AvatarIcon` (string): Optional icon fallback
+    - `label` (string): User initials or name
+
+> Values can be static (e.g., `"P"`) or dynamic (e.g., `{{'{{'}}{{'user.name'}}{{'\}}'}}`).
+
+**Optional Fields:**
+- `avatarSize` (number|string): Size of each avatar in pixels (e.g., `"40"`).
+- `alignment` (string): `"flex-start"`, `"center"`, or `"flex-end"` — determines horizontal alignment.
+- `autoColor` (boolean): Automatically assign background colors to avatars.
+- `maxCount` (number|string): Maximum avatars shown before overflow `+N` appears.
+- `currentAvatar` (object): Preselected avatar data (used for state tracking).
+- `avatar` (object): Style overrides for each avatar item.
+- `hidden` (boolean): Hide the avatar group.
+- `onEvent` (function): Handlers for group interactions (e.g., `click`, `refresh`).
+- `style` (object): CSS styling for the group container.
+- `showDataLoadingIndicators` (boolean): Display loading spinner during dynamic avatar fetching.
+
+**Example Output:**
+```json
+{
+  "maxCount": "3",
+  "avatarSize": "40",
+  "alignment": "center",
+  "autoColor": true,
+  "avatars": {
+    "optionType": "manual",
+    "manual": {
+      "manual": [
+        {
+          "src": "https://api.dicebear.com/7.x/miniavs/svg?seed=1",
+          "label": "P"
+        },
+        {
+          "AvatarIcon": "/icon:antd/startwotone"
+        },
+        {
+          "label": "P"
+        },
+        {
+          "label": "E"
+        }
+      ]
+    },
+    "mapData": {
+      "data": "[]"
+    }
+  },
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define `avatars` as a structured object with `optionType: "manual"` unless mapping is required.
+> - Each avatar item should include at least a `label`, or a `src`, or an `AvatarIcon`.
+> - Use` avatarSize: "40"` and `autoColor: true` for standard team displays.
+> - Use `alignment: "center"` for symmetrical presentation.
+> - If `maxCount` is set, show `+N` style overflow for remaining avatars.
+
+---
+
+#### 📍 Component: `bpmn`
+
+**Required Fields:**
+- _None explicitly marked as required. Include fields necessary for proper rendering._
+
+**Optional Fields:**
+- `onChange` (eventHandler): Change event handler
+- `style` (object): BPMN editor style
+- `xml` (string): BPMN XML definition
+
+**Example Output:**
+```json
+{
+  "onChange": <eventHandler>,
+  "style": <object>,
+  "xml": <string>
+}
+```
+
+---
+
+#### 📍 Component: `bpmnEditor`
+
+**Required Fields:**
+- _None explicitly marked as required. Include fields necessary for proper rendering._
+
+**Optional Fields:**
+- `onChange` (eventHandler): Change event handler
+- `style` (object): BPMN editor style
+- `xml` (string): BPMN XML definition
+
+**Example Output:**
+```json
+{
+  "onChange": <eventHandler>,
+  "style": <object>,
+  "xml": <string>
+}
+```
+
+---
+
+#### 📍 Component: `button`
+
+**Required Fields:**
+- `text` (string): The label shown on the button (e.g., `"Submit"` or `"Click Me"`).
+
+> All values can be static (e.g., `"Save"`) or dynamic (e.g., `{{'{{'}}{{'formState.buttonLabel'}}{{'\}}'}}`).
+
+**Optional Fields:**
+- `type` (string): Type of button — either `""` (default) or `"submit"` when linked to a form.
+- `form` (string): Name/ID of the target form. Only used when `type: "submit"`.
+- `disabled` (boolean|string): Whether the button is inactive (use `"true"` or `"false"` as string or boolean).
+- `loading` (boolean|string): Show loading state (spinning icon).
+- `hidden` (boolean|string): Whether the button is hidden.
+- `tooltip` (string): Optional hover text to guide users.
+- `showDataLoadingIndicators` (boolean): Show automatic data loading spinners.
+- `prefixIcon` / `suffixIcon` (icon): Icons placed before or after the button text.
+- `animationStyle` (object): Config for entrance/hover animations.
+- `style` (object): Inline styles applied to the button.
+- `viewRef` (ref): Reference to the button for programmatic access.
+- `onEvent` (eventHandler): Defines event handling logic (e.g., `click`, `dblclick`, `hover`).
+
+**Example Output:**
+```json
+{
+  "text": "Form Button",
+  "type": "",
+  "disabled": "false",
+  "loading": "false",
+  "form": "",
+  "hidden": "false",
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include `text` for visual clarity.
+> - Use `type: "submit"` and set the `form` field when the button is meant to submit a form.
+> - If `disabled`, `hidden`, or `loading` are used, set them explicitly to `"true"` or `"false"`.
+> - Default `type` to `""` unless it is tied to a form.
+> - Consider adding tooltip for action-specific context like `“Save changes”` or `“Next step”`.
+> - Include `onEvent.click` when an action needs to be triggered manually.
+
+---
+
+#### 📍 Component: `card`
+
+**Required Fields:**
+- `title` (string): Main card title text (can be static or dynamic).
+- `showTitle` (boolean): Whether to display the title.
+- `CoverImg` (boolean): Whether to show a cover image at the top.
+- `showMeta` (boolean): Toggle visibility of meta section.
+- `showActionIcon` (boolean): Show or hide the action icon buttons.
+- `extraTitle` (string): Additional title link shown beside the main title.
+
+> All values can be static (e.g., `"Title"`) or dynamic (e.g., `{{'{{'}}{{'record.title'}}{{'\}}'}}`).
+
+**Optional Fields:**
+- `size` (string): Card size, typically `"small"`, `"default"`, or `"large"`.
+- `cardType` (string): `"common"` or other layout-specific card styles.
+- `imgSrc` (string): Source URL for the image.
+- `imgHeight` (string): Height of the image (e.g., `"auto"`, `"200px"`).
+- `metaTitle` (string): Title shown in the meta section.
+- `metaDesc` (string): Description text below meta title.
+- `hoverable` (boolean): Enables hover effects on the card.
+- `actionOptions` (object): Action button list with:
+  - `optionType`: `"manual"` or `"mapData"`
+  - `manual.manual`: Array of objects like `{ "label": "Option 1", "icon": "/icon:antd/..." }`
+- `container` (object): Defines layout regions and styles within the card:
+  - `header`, `body`, `footer` (each with `layout` and view config)
+  - `showHeader`, `showBody`: Control visibility of sections
+  - `autoHeight`, `horizontalGridCells`, `scrollbars`, `showVerticalScrollbar`
+  - `style`: Custom container styles
+  - `appliedThemeId`: Applied theme identifier
+- `hidden` (boolean): Hides the card from view.
+- `style` (object): Inline styles for the card itself.
+- `bodyStyle` / `headerStyle` (object): Section-specific styles.
+- `animationStyle` (object): Animation configurations.
+- `onEvent` (function): Event handler for click/hover/etc.
+- `showDataLoadingIndicators` (boolean): Whether to show a loading spinner.
+
+**Example Output:**
+```json
+{
+  "showTitle": true,
+  "title": "Title",
+  "size": "small",
+  "extraTitle": "More",
+  "cardType": "common",
+  "CoverImg": true,
+  "imgSrc": "https://lowcoder.cloud/images/e0a89736c6be4393893d2981ac1fd753.png",
+  "imgHeight": "auto",
+  "showMeta": true,
+  "metaTitle": "Content Title",
+  "metaDesc": "Content Description",
+  "hoverable": true,
+  "showActionIcon": true,
+  "actionOptions": {
+    "optionType": "manual",
+    "manual": {
+      "manual": [
+        {
+          "label": "Option 1",
+          "icon": "/icon:antd/settingoutlined"
+        },
+        {
+          "label": "Option 2",
+          "icon": "/icon:antd/editoutlined"
+        },
+        {
+          "label": "Option 3",
+          "icon": "/icon:antd/ellipsisoutlined"
+        }
+      ]
+    },
+    "mapData": {
+      "data": "[]",
+      "mapData": {
+        "icon": ""
+      }
+    }
+  },
+  "container": {
+    "header": {},
+    "body": {
+      "0": {
+        "view": {}
+      }
+    },
+    "footer": {},
+    "showHeader": true,
+    "showBody": true,
+    "autoHeight": "auto",
+    "showVerticalScrollbar": false,
+    "horizontalGridCells": 24,
+    "scrollbars": false,
+    "style": {
+      "borderWidth": "1px"
+    },
+    "appliedThemeId": ""
+  },
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include `title` and `showTitle` for clear visual structure.
+> - Use `imgSrc` and `CoverImg` together to display a card banner.
+> - If `actionOptions` are used, provide label and icon per option.
+> - When adding layout, configure `container` with `header`, `body`, and `footer` blocks.
+> - Use `"small"` for compact display; `"common"` as the default `cardType`.
+> - Enable `showDataLoadingIndicators` for cards that fetch content asynchronously.
+
+---
+
+#### 📍 Component: `carousel`
+
+**Required Fields:**
+- `data` (string): A **stringified array** of image URLs to display in the carousel.
+
+> All values can be static or dynamically generated using expressions like `{{'{{'}}{{'imageList'}}{{'\}}'}}`.
+
+**Optional Fields:**
+- `autoPlay` (boolean): Automatically cycle through slides.
+- `showDots` (boolean): Display navigation dots beneath the slides.
+- `dotPosition` (string): Position of the navigation dots — `"bottom"`, `"top"`, `"left"`, or `"right"`.
+- `animationStyle` (object): Transition animation settings.
+- `style` (object): Inline style for the entire carousel container.
+- `hidden` (boolean): Hides the carousel.
+- `onEvent` (function): Event handlers (e.g., on slide change).
+- `showDataLoadingIndicators` (boolean): Show loading spinner while loading content.
+
+**Example Output:**
+```json
+{
+  "autoPlay": true,
+  "data": "[\"https://temp.im/403x192\",\"https://temp.im/403x192\"]",
+  "showDots": true,
+  "dotPosition": "bottom",
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always format the `data` field as a JSON.stringify of an image URL array.
+> - Set `autoPlay: true` to automatically rotate the slides.
+> - Use `dotPosition: "bottom"` as the default, but allow overrides.
+> - If loading content dynamically, enable `showDataLoadingIndicators`.
+> - `animationStyle` may be used to apply smooth or custom transitions.
+
+---
+
+#### 📍 Component: `checkbox`
+
+**Required Fields:**
+- `options` (object): A structured object that defines the available choices.
+  - Must include:
+    - `optionType`: `"manual"` or `"mapData"`
+    - `manual.manual`: Array of `{ label, value }` objects (e.g., `[{ "value": "1", "label": "Option 1" }]`)
+
+> All values can be static (e.g., `"Option 1"`) or dynamic (e.g., `{{'{{'}}{{'record.status'}}{{'\}}'}}`).
+
+**Optional Fields:**
+- `label` (object): Label configuration for the group:
+  - `text` (string): Label text
+  - `width` (string): Width value
+  - `widthUnit` (string): Unit for width (e.g., `%`)
+  - `position` (string): `"row"` or `"column"`
+  - `align` (string): Text alignment (`"left"`, `"right"`, etc.)
+- `defaultValue` (string|array): Pre-selected values on initial render.
+- `value` (string|array): Current selected value(s).
+- `layout` (string): `"horizontal"` or `"vertical"` display.
+- `required` (boolean): Whether at least one checkbox must be selected.
+- `disabled` (boolean): Disable all checkboxes.
+- `hidden` (boolean): Hide the checkbox component.
+- `invalid` (boolean): Marks the field as invalid (for validation UI).
+- `errorMessage` (string): Message to show on validation failure.
+- `tabIndex` (number): Keyboard navigation index.
+- `inputFieldStyle` (object): Custom style for the checkbox inputs.
+- `labelStyle` (object): Custom style for the label.
+- `style` (object): Wrapper style.
+- `animationStyle` (object): Visual animation settings.
+- `onEvent` (function): Event callbacks (e.g., `onChange`).
+- `viewRef` (object): DOM reference for programmatic access.
+- `showDataLoadingIndicators` (boolean): Show loading spinner if data is being loaded dynamically.
+
+**Example Output:**
+```json
+{
+  "defaultValue": "",
+  "value": "",
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "options": {
+    "optionType": "manual",
+    "manual": {
+      "manual": [
+        {
+          "value": "1",
+          "label": "Option 1"
+        },
+        {
+          "value": "2",
+          "label": "Option 2"
+        }
+      ]
+    },
+    "mapData": {
+      "data": "[]"
+    }
+  },
+  "layout": "horizontal",
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define `options` with either `manual` or `mapData` mode.
+> - Use `label.text` to clearly describe the group purpose.
+> - For inline layout, set `layout: "horizontal"`; for vertical stacking, use `"vertical"`.
+> - Use `defaultValue` to pre-check specific options.
+> - Add `showDataLoadingIndicators` when options are loaded from dynamic sources.
+
+---
+
+#### 📍 Component: `cloudflareTurnstile`
+
+**Required Fields:**
+- _None explicitly marked as required. Include fields necessary for proper rendering._
+
+**Optional Fields:**
+- `onVerify` (eventHandler): Verification event handler
+- `siteKey` (string): Cloudflare Turnstile site key
+- `style` (object): Turnstile style
+
+**Example Output:**
+```json
+{
+  "onVerify": <eventHandler>,
+  "siteKey": <string>,
+  "style": <object>
+}
+```
+
+---
+
+#### 📍 Component: `collapsibleContainer`
+
+**Required Fields:**
+- `container` (object): Configuration object that defines layout, visibility, and nested components.
+
+> Fields like `showBody` or `showHeader` can use dynamic expressions (e.g., `{{'{{'}}{{'collapsibleToggle1.value'}}{{'\}}'}}`).
+
+**Optional Fields:**
+- `container.header` (object): Layout area for header components. Nested components can be added using `nest_component` action.
+- `container.body` (object): Layout area for body content. Nested components can be added using `nest_component` action.
+- `container.footer` (object): Layout area for footer content. Nested components can be added using `nest_component` action.
+- `container.showHeader` (boolean): Whether to display the header area.
+- `container.showBody` (boolean|string): Whether to show the collapsible body. Can be dynamic (`true`, `false`, or an expression).
+- `container.autoHeight` (string): Automatically calculate height (`"auto"` or pixel/percentage string).
+- `container.horizontalGridCells` (number): Number of grid columns for layout (e.g., `24`).
+- `container.scrollbars` (boolean): Enable horizontal scrollbars.
+- `container.showVerticalScrollbar` (boolean): Enable vertical scrollbars.
+- `container.style` (object): Custom styles (e.g., borders, padding).
+- `disabled` (boolean): Disable all child components and interactivity.
+- `hidden` (boolean): Completely hide the container from view.
+- `animationStyle` (object): Transition or visibility animations.
+- `showDataLoadingIndicators` (boolean): Show loading spinner when content is dynamic.
+
+**Example Output:**
+```json
+{
+  "container": {
+    "header": {},
+    "body": {
+      "0": {
+        "view": {}
+      }
+    },
+    "footer": {},
+    "showHeader": true,
+    "showBody": "{{'{{'}}{{'collapsibleToggle1.value'}}{{'\}}'}}",
+    "autoHeight": "auto",
+    "showVerticalScrollbar": false,
+    "horizontalGridCells": 24,
+    "scrollbars": false,
+    "style": {
+      "borderWidth": "1px"
+    }
+  },
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define the `container` structure with `header`, `body`, and `footer` blocks if layout is required.
+> - Use `nest_component` to populate child elements into `header`, `body`, or `footer`.
+> - Set `showBody` using a dynamic expression like `{{'{{'}}{{'toggle.value'}}{{'\}}'}}` for collapsible behavior.
+> - Prefer `autoHeight: "auto"` for responsive layout unless fixed height is needed.
+> - Use `style.borderWidth` or other styling for visual separation.
+> - Use `showDataLoadingIndicators: true` if children are dynamically rendered.
+
+---
+
+#### 📍 Component: `colorPicker`
+
+**Required Fields:**
+- `value` (string): Current selected color in hex format (e.g., `"#3377ff"`).
+
+> Values like `value`, `label.text`, or `defaultValue` can be static or dynamic (e.g., `{{'{{'}}{{'theme.primary'}}{{'\}}'}}`).
+
+**Optional Fields:**
+- `defaultValue` (string): Initial color before selection is made.
+- `label` (object): Configuration for label display.
+  - `text` (string): Label text
+  - `width` (string): Width value (e.g., `"33"`)
+  - `widthUnit` (string): Unit for width (e.g., `"%"`)
+  - `position` (string): `"row"` or `"column"`
+  - `align` (string): `"left"`, `"right"`, `"center"`, etc.
+- `validationType` (string): Data type validation (e.g., `"Text"`).
+- `color` (object|string): Color in detailed format (may include `hex`, `hsb`, or `rgb`), or `{}` if unused.
+- `disabled` (boolean): Disable the color input interaction.
+- `disabledAlpha` (boolean): Disable transparency/alpha slider.
+- `presets` (stringified object): JSON.stringify of an object with:
+  - `label` (string): Label for the preset group
+  - `colors` (array): Array of hex strings (e.g., `["#000000", "#F5222D"]`)
+- `showPresets` (boolean): Show/hide preset color palette.
+- `trigger` (string): `"click"` (default) or other interaction to open picker.
+- `style` (object): Custom styling for the picker.
+- `hidden` (boolean): Hide the component from view.
+- `onEvent` (function): Event callback for interactions (e.g., color change).
+- `showDataLoadingIndicators` (boolean): Display spinner when loading color data dynamically.
+
+**Example Output:**
+```json
+{
+  "defaultValue": "",
+  "value": "#3377ff",
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "validationType": "Text",
+  "color": "{}",
+  "trigger": "click",
+  "presets": "{\n  \"label\": \"Recommended\",\n  \"colors\": [\n    \"#000000\",\n    \"#000000E0\",\n    \"#000000A6\",\n    \"#00000073\",\n    \"#00000040\",\n    \"#00000026\",\n    \"#0000001A\",\n    \"#00000012\",\n    \"#0000000A\",\n    \"#00000005\",\n    \"#F5222D\",\n    \"#FA8C16\",\n    \"#FADB14\",\n    \"#8BBB11\",\n    \"#52C41A\",\n    \"#13A8A8\",\n    \"#1677FF\",\n    \"#2F54EB\",\n    \"#722ED1\",\n    \"#EB2F96\",\n    \"#F5222D4D\",\n    \"#FA8C164D\",\n    \"#FADB144D\",\n    \"#8BBB114D\",\n    \"#52C41A4D\",\n    \"#13A8A84D\",\n    \"#1677FF4D\",\n    \"#2F54EB4D\",\n    \"#722ED14D\",\n    \"#EB2F964D\"\n  ]\n}",
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+- Always provide `value` as a hex string. Use `defaultValue` if a pre-selected color is required.
+- Use a structured `label` object for accessible and styled labeling.
+- Supply `presets` as a JSON.stringify of `{ label, colors[] }`.
+- When applicable, use `"click"` as the trigger to open the picker.
+- Set `showDataLoadingIndicators` to `true` if fetching preset colors or values asynchronously.
+
+---
+
+#### 📍 Component: `columnLayout`
+
+**Required Fields:**
+- `columns` (object): Configuration of layout columns.
+  - Must include:
+    - `manual`: Array of column objects. Each column supports:
+      - `id` (number): Unique identifier
+      - `label` (string): Display label for the column
+      - `key` (string): Reference key
+      - `minWidth` (string): Minimum column width
+      - `background` (string): Background color
+      - `backgroundImage` (string): Background image URL
+      - `border` (string): Border definition
+      - `radius` (string): Border radius
+      - `margin` (string): CSS margin
+      - `padding` (string): CSS padding
+      - `hidden` (boolean|string): Visibility toggle (`"false"` by default)
+
+> Values may be hardcoded or dynamically bound using expressions like `{{'{{'}}{{'state.value'}}{{'\}}'}}`.
+
+**Optional Fields:**
+- `containers` (object): Object mapping each column index to its container layout. Use `nest_component` to insert child components.
+  ```json
+  {
+    "0": {}, 
+    "1": {}
+  }
+  ```
+- `templateColumns` (string): CSS `grid-template-columns` value (e.g., `"1fr 1fr"`).
+- `templateRows` (string): CSS `grid-template-rows` value (e.g., `"1fr"`).
+- `columnGap` (string): Horizontal space between columns (e.g., `"20px"`).
+- `rowGap` (string): Vertical space between rows (e.g., `"20px"`).
+- `horizontalGridCells` (number): Total grid cells available in the layout (e.g., `24`).
+- `autoHeight` (string): Use `"auto"` or `fixed` to let the container auto-size its height.
+- `matchColumnsHeight` (boolean): Ensures all columns have equal height.
+- `mainScrollbar` (boolean): Show/hide main container scrollbar.
+- `columnStyle` (object): Global style applied to columns.
+- `style` (object): Style for the full layout container.
+- `disabled` (boolean): Disable the layout section.
+- `hidden` (boolean): Hide the component entirely.
+- `showDataLoadingIndicators` (boolean): Show loading spinner while content is being prepared.
+
+**Example Output:**
+```json
+{
+  "columns": {
+    "manual": [
+      {
+        "id": 0,
+        "label": "Column1",
+        "key": "Column1",
+        "minWidth": "",
+        "background": "",
+        "backgroundImage": "",
+        "border": "",
+        "radius": "",
+        "margin": "",
+        "padding": "",
+        "hidden": "false"
+      },
+      {
+        "id": 1,
+        "label": "Column2",
+        "key": "Column2",
+        "minWidth": "",
+        "background": "",
+        "backgroundImage": "",
+        "border": "",
+        "radius": "",
+        "margin": "",
+        "padding": "",
+        "hidden": "false"
+      }
+    ]
+  },
+  "containers": {
+    "0": {},
+    "1": {}
+  },
+  "horizontalGridCells": 24,
+  "autoHeight": "auto",
+  "matchColumnsHeight": true,
+  "templateRows": "1fr",
+  "rowGap": "20px",
+  "templateColumns": "1fr 1fr",
+  "mainScrollbar": false,
+  "columnGap": "20px",
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define at least one column using the `manual` array.
+> - Use `containers` with matching numeric keys (`"0"`, `"1"`, etc.) to place child components via `nest_component`.
+> - Use `templateColumns` and `templateRows` for advanced responsive layout.
+> - Set `autoHeight` to `"auto"` for flexible layout sizing.
+> - Apply `matchColumnsHeight: true` when visual balance is important.
+> - Use grid gap properties (`columnGap`, `rowGap`) for consistent spacing.
+
+---
+
+#### 📍 Component: `comment`
+
+**Required Fields:**
+- `value` (stringified array): A JSON string of comment objects with:
+  - `user`: Object with `name`, `avatar`, and optional `displayName`
+  - `value`: The comment content (string)
+  - `createdAt`: Timestamp in ISO format
+
+> Comments should be wrapped in a **stringified JSON array**. Each item should represent a full comment entry.
+
+**Optional Fields:**
+- `title` (string): Title or heading text for the comment section (e.g., `"%d Comment in Total"`).
+- `placeholder` (string): Placeholder shown in the input field.
+- `buttonText` (string): Text for the comment submission button (e.g., `"Comment"`).
+- `sendCommentAble` (boolean): Whether the user is allowed to submit a comment.
+- `userInfo` (stringified object): Current user's metadata. Typically includes:
+  - `name`: User name (can be dynamic like `{{'{{'}}{{'currentUser.name'}}{{'\}}'}}`)
+  - `email`: User email (e.g., `{{'{{'}}{{'currentUser.email'}}{{'\}}'}}`)
+- `mentionList` (stringified object): Tagging/mention system support:
+  - `@`: List of users (e.g., `["John Doe", "Jane Smith"]`)
+  - `#`: List of hashtags/topics (e.g., `["#workflow", "#api"]`)
+- `commentList` (stringified array): External comment source, if syncing with external systems.
+- `submitedItem` (stringified array): Track submitted comments for state management.
+- `deletedItem` (stringified array): Track deleted comments for updates.
+- `mentionName` (string): Currently selected mention value.
+- `style` (object): Inline styles for the comment container.
+- `onEvent` (function): Interaction event handling (e.g., `onSubmit`, `onDelete`, etc.)
+- `hidden` (boolean): Whether the component is hidden.
+- `showDataLoadingIndicators` (boolean): Show spinner while loading or syncing comments.
+
+**Example Output:**
+```json
+{
+  "value": "[\n  {\n    \"user\": {\n      \"name\": \"John Doe\",\n      \"avatar\": \"https://ui-avatars.com/api/?name=John+Doe\"\n    },\n    \"value\": \"Has anyone tried using Lowcode for our new internal tool yet?\",\n    \"createdAt\": \"2024-09-20T10:15:41.658Z\"\n  }\n]",
+  "title": "%d Comment in Total",
+  "placeholder": "Shift + Enter to Comment; Enter @ or # for Quick Input",
+  "buttonText": "Comment",
+  "sendCommentAble": true,
+  "userInfo": "{\n  \"name\": \"{{'{{'}}{{'currentUser.name'}}{{'\}}'}}\",\n  \"email\": \"{{'{{'}}{{'currentUser.email'}}{{'\}}'}}\"\n}",
+  "mentionList": "{\n  \"@\": [\"John Doe\", \"Jane Doe\"],\n  \"#\": [\"#workflow\", \"#api\"]\n}",
+  "commentList": "[]",
+  "deletedItem": "[]",
+  "submitedItem": "[]",
+  "mentionName": "",
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Wrap `value` as a stringified array of comment objects with `user`, value, and `createdAt`.
+> - Include `mentionList` with `@` and `#` keys for tagging features.
+> - Use dynamic values for `userInfo` such as `{{'{{'}}{{'currentUser.name'}}{{'\}}'}}`.
+> - Set `sendCommentAble: true` to allow user interaction.
+> - Populate `commentList`, `submitedItem`, and `deletedItem` with `[]` if not syncing externally.
+> - Use `showDataLoadingIndicators` when comments are loaded or posted asynchronously.
+
+---
+
+#### 📍 Component: `container`
+
+**Required Output Format (always):**  
+Every `container` must define `container.body` using the following nested structure:
+
+```json
+"container": {
+  "body": {
+    "0": {
+      "view": {}
+    }
+  }
+}
+```
+
+This structure must always be returned — regardless of whether the container is added in isolation or as part of a larger layout or app. Never omit the `"0"` slot or the `"view"` placeholder.
+
+---
+
+**Required Fields:**
+- `container` (object): The container definition (must include body → 0 → view)
+
+**Optional Fields (as needed):**
+- `container.header`, `container.footer`: Optional header and footer areas
+- `container.showHeader`, `container.showBody`: Visibility toggles
+- `container.scrollbars`, `container.showVerticalScrollbar`: Scroll settings
+- `container.autoHeight` (string): `"auto"` or `"fixed"` for responsive height
+- `container.horizontalGridCells` (number): Typically `24` for full-width layout
+- `container.style` (object): Custom style attributes (e.g., `borderWidth`, `padding`)
+- Top-level: `animationStyle`, `disabled`, `hidden`, `showDataLoadingIndicators`
+
+---
+
+**Example Output:**
+```json
+{
+  "container": {
+    "header": {},
+    "body": {
+      "0": {
+        "view": {}
+      }
+    },
+    "footer": {},
+    "showHeader": true,
+    "showBody": true,
+    "autoHeight": "auto",
+    "horizontalGridCells": 24,
+    "scrollbars": false,
+    "style": {
+      "borderWidth": "1px"
+    }
+  }
+}
+```
+
+---
+
+**🚫 Never Do:**
+```json
+"container": {
+  "body": {}
+}
+```
+
+---
+
+**🧠 Prompt Guidance for AI Agent**  
+> Always output `"body": { "0": { "view": {} } }"` inside the container. This format is mandatory and should not be omitted. Nesting logic will later populate this `view`. Avoid returning an empty `body` object or skipping the `"0"` slot.
+
+---
+
+#### 📍 Component: `date`
+
+**Required Fields:**
+- `value` (string): Current selected date (can be empty string `""`).
+- `inputFormat` (string): Expected format for input value (e.g., `"YYYY-MM-DD"`).
+
+> Fields like `label.text`, `value`, and `defaultValue` may be static or dynamic (`{{'{{'}}{{'record.date'}}{{'\}}'}}`).
+
+**Optional Fields:**
+- `defaultValue` (string): Initial date to prefill (ISO or formatted string).
+- `userTimeZone` (string): User’s time zone for localizing date display (e.g., `"Asia/Karachi"`).
+- `timeZone` (string): Optional override of system timezone.
+- `placeholder` (string): Placeholder text for input (e.g., `"Select Date"`).
+- `pickerMode` (string): Type of picker (`"date"`, `"time"`, `"month"`, etc.).
+- `label` (object): Label rendering configuration:
+  - `text` (string): Label text
+  - `width` (string): Width of label (e.g., `"33"`)
+  - `widthUnit` (string): Unit of label width (e.g., `"%"`)
+  - `position` (string): `"row"` or `"column"`
+  - `align` (string): Alignment (`"left"`, `"right"`)
+- `suffixIcon` (string|icon): Icon to display at the end of the input (e.g., `"/icon:regular/calendar"`)
+
+---
+
+**Full List of Supported Optional Fields (Advanced):**
+- `required` (boolean): Whether this date input must be filled.
+- `animationStyle` (object): Animation settings for transitions.
+- `childrenInputFieldStyle` (object): Style overrides for nested inputs.
+- `customRule` (string): Custom validation logic.
+- `disabled` (boolean): Disable input field.
+- `formDataKey` (string): Used in forms to map input data.
+- `format` (string): Display format for date (e.g., `"YYYY-MM-DD"`).
+- `hourStep`, `minuteStep`, `secondStep` (number): Increment settings for time selection.
+- `inputFieldStyle` (object): Style for the input container.
+- `labelStyle` (object): Style overrides for label.
+- `maxDate`, `minDate` (string): Limit selectable date range.
+- `maxTime`, `minTime` (string): Limit selectable time (used when `showTime` is `true`).
+- `onEvent` (function): Event callback for changes.
+- `showTime` (boolean): Enable time selection alongside date.
+- `showValidationWhenEmpty` (boolean): Show error if field is empty.
+- `style` (object): Custom CSS styles.
+- `tabIndex` (number): Tab order in navigation.
+- `use12Hours` (boolean): Toggle between 24-hour and 12-hour mode.
+- `viewRef` (ref): Ref for input control.
+- `showDataLoadingIndicators` (boolean): Enable loading state if value is dynamic.
+
+---
+
+**Example Output:**
+```json
+{
+  "defaultValue": "",
+  "value": "",
+  "userTimeZone": "Asia/Karachi",
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "placeholder": "Select Date",
+  "inputFormat": "YYYY-MM-DD",
+  "suffixIcon": "/icon:regular/calendar",
+  "timeZone": "Asia/Karachi",
+  "pickerMode": "date",
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include both `value` and `inputFormat` for accurate rendering.
+> - Use structured `label` when displaying descriptive text alongside the date input.
+> - Set pickerMode based on expected input type (`"date"` by default).
+> - Define `userTimeZone` and `timeZone` for consistent localization.
+> - Use `suffixIcon` to display a calendar icon visually.
+> - Enable `showDataLoadingIndicators` if value is dynamically fetched or recalculated.
+
+---
+
+#### 📍 Component: `dateRange`
+
+**Required Fields:**
+- `start` (string): Start date (can be an empty string)
+- `end` (string): End date (can be an empty string)
+- `inputFormat` (string): Format for date input (e.g., `"YYYY-MM-DD"`)
+
+> Fields like `start`, `end`, and `label.text` can be statically defined or dynamically bound using expressions (e.g., `{{'{{'}}{{'record.startDate'}}{{'\}}'}}`).
+
+**Optional Fields:**
+- `defaultStart` (string): Default value for the start date
+- `defaultEnd` (string): Default value for the end date
+- `userRangeTimeZone` (string): Time zone for localizing the date range (e.g., `"Asia/Karachi"`)
+- `timeZone` (string): Optional override for system timezone (e.g., `"Asia/Karachi"`)
+- `pickerMode` (string): Type of picker to display (`"date"`, `"time"`, `"month"`, etc.)
+- `placeholder` (string): Placeholder text for the input field (e.g., `"Select Date"`)
+- `suffixIcon` (string): Icon to appear at the end of the input (e.g., `"/icon:regular/calendar"`)
+- `label` (object): Label configuration:
+  - `text` (string): Label text
+  - `width` (string): Label width (e.g., `"33"`)
+  - `widthUnit` (string): Width unit (e.g., `"%"`)
+  - `position` (string): `"row"` or `"column"`
+  - `align` (string): `"left"`, `"center"`, or `"right"`
+
+---
+
+**Additional Supported Fields (Advanced):**
+- `required` (boolean): Whether both dates must be selected
+- `animationStyle` (object): Transition animation configuration
+- `childrenInputFieldStyle` (object): Style overrides for children
+- `customRule` (string): Custom validation logic
+- `disabled` (boolean): Disable the input
+- `formDataKey` (string): Form key binding
+- `format` (string): Output format for selected date range
+- `hourStep`, `minuteStep`, `secondStep` (number): Step intervals for time selection
+- `inputFieldStyle` (object): Style for the input box
+- `labelStyle` (object): Custom styling for the label
+- `maxDate`, `minDate` (string): Date boundaries
+- `maxTime`, `minTime` (string): Time boundaries (when `showTime` is true)
+- `onEvent` (function): Event handler for user actions
+- `showTime` (boolean): Whether to allow time picking
+- `showValidationWhenEmpty` (boolean): Show validation if value is not set
+- `style` (object): Custom container styles
+- `tabIndex` (number): Keyboard tab index
+- `use12Hours` (boolean): Use 12-hour format (AM/PM)
+- `viewRef` (ref): Reference to the date range element
+- `showDataLoadingIndicators` (boolean): Display loading indicators for async behavior
+
+---
+
+**Example Output:**
+```json
+{
+  "defaultStart": "",
+  "start": "",
+  "defaultEnd": "",
+  "end": "",
+  "userRangeTimeZone": "Asia/Karachi",
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "placeholder": "Select Date",
+  "inputFormat": "YYYY-MM-DD",
+  "suffixIcon": "/icon:regular/calendar",
+  "timeZone": "Asia/Karachi",
+  "pickerMode": "date",
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define `start`, `end`, and `inputFormat` fields.
+> - Use `defaultStart` and `defaultEnd` to prepopulate values when needed.
+> - Apply `userRangeTimeZone` for localizing user interaction with the range picker.
+> - Use structured `label` configuration for flexible layout control.
+> - Add `suffixIcon` (e.g., calendar icon) for visual cues.
+> - Set s`howDataLoadingIndicators: true` if values are dynamic or async.
+
+---
+
+#### 📍 Component: `divider`
+
+**Required Fields:**
+- `align` (string): Alignment of content on the divider line. Options: `"left"`, `"center"`, `"right"`.
+- `autoHeight` (string): Use `"auto"` or `fixed` to let the container auto-size its height.
+
+**Optional Fields:**
+- `dashed` (boolean): Use a dashed line instead of a solid line.
+- `style` (object): Custom styles for the divider (e.g., margin, border width).
+- `showDataLoadingIndicators` (boolean): Show loading spinner if the divider state is dynamic or async.
+
+**Example Output:**
+```json
+{
+  "dashed": false,
+  "align": "left",
+  "autoHeight": "auto",
+  "style": {
+    "margin": "8px 0"
+  },
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Use `align: "left"` to left-align the content if any text or label is present.
+> - Set `autoHeight: "auto"` when the divider should adapt to dynamic height.
+> - Use `dashed: true` for visual separation in lighter UI designs.
+> - Apply custom `style` for spacing or thickness.
+> - Enable `showDataLoadingIndicators` if the divider is part of a dynamic component group.
+
+---
+
+#### 📍 Component: `drawer`
+
+**Required Fields:**
+- `visible` (boolean|string): Control the visibility of the drawer (can be dynamic or a boolean).
+- `placement` (string): Side from which the drawer appears. Options: `"left"`, `"right"`, `"top"`, `"bottom"`.
+
+**Optional Fields:**
+- `title` (string): Title of the drawer.
+- `titleAlign` (string): Alignment of the title. Options: `"left"`, `"center"`, `"right"`.
+- `closePosition` (string): Position of the close button (`"left"` or `"right"`).
+- `horizontalGridCells` (number): Number of layout grid cells across (e.g., `24`).
+- `autoHeight` (string): Use `"auto"` or `fixed` to let the container auto-size its height.
+- `drawerScrollbar` (boolean): Show or hide scrollbar inside the drawer.
+- `maskClosable` (boolean): Allow closing the drawer by clicking on the mask (overlay).
+- `escapeClosable` (boolean): Allow closing the drawer with the Escape key.
+- `showMask` (boolean): Show background mask behind drawer.
+- `toggleClose` (boolean): Allow programmatically toggling the close state.
+- `container` (object): Layout definition for nested components inside the drawer.
+- `style` (object): Inline styles for drawer container (e.g., padding, border).
+- `onEvent` (function): Event handler (e.g., onClose, onOpen).
+- `showDataLoadingIndicators` (boolean): Show spinner if data or layout inside drawer is loading.
+- `width` (string): Custom width of drawer (e.g., `"400px"`).
+- `height` (string): Custom height of drawer (only applicable for top/bottom placement).
+
+---
+
+**Example Output:**
+```json
+{
+  "visible": "",
+  "titleAlign": "left",
+  "horizontalGridCells": 24,
+  "autoHeight": "auto",
+  "drawerScrollbar": true,
+  "placement": "right",
+  "closePosition": "left",
+  "maskClosable": true,
+  "showMask": true,
+  "toggleClose": true,
+  "escapeClosable": true,
+  "container": {},
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Set `visible` to control open/close behavior (boolean or dynamic expression).
+> - Use `placement: "right"` for right-side slide-in (or "`left`", "`top`", "`bottom`" as needed).
+> - Include `container` as an object with layout to support nested components using the `nest_component` action.
+> - Use `autoHeight: "auto"` and `drawerScrollbar: true` to allow adaptive and scrollable content.
+> - Add `toggleClose`, `escapeClosable`, and `maskClosable` to ensure intuitive user control.
+> - Set `titleAlign` and `closePosition` to improve header layout control.
+
+---
+
+#### 📍 Component: `dropdown`
+
+**Required Fields:**
+- `text` (string): Required if `onlyMenu` is not set to `true`. It's what appears on the dropdown button.
+- `options` (array|object): Dropdown menu items must be provided.
+  - Use manual array:
+    ```json
+    {
+      "optionType": "manual",
+      "manual": {
+        "manual": [
+          { "label": "Option 1" },
+          { "label": "Option 2" }
+        ]
+      }
+    }
+    ```
+  - Or dynamic list through `mapData`.
+
+**Optional Fields:**
+- `triggerMode` (string): Defines how the dropdown is triggered. Options: `"click"` or `"hover"`.
+- `onlyMenu` (boolean): If true, renders only the dropdown menu without a button.
+- `disabled` (boolean): Disable interaction with dropdown.
+- `onEvent` (function): Event handlers (e.g., onClick, onHover).
+- `style` (object): Inline styles for the dropdown wrapper.
+- `showDataLoadingIndicators` (boolean): Whether to show a loading indicator for dynamic options.
+
+---
+
+**Example Output:**
+```json
+{
+  "text": "Menu",
+  "triggerMode": "hover",
+  "options": {
+    "optionType": "manual",
+    "manual": {
+      "manual": [
+        { "label": "Option 1" },
+        { "label": "Option 2" }
+      ]
+    },
+    "mapData": {
+      "data": "[]"
+    }
+  },
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Use `triggerMode: "hover"` or `"click"` depending on user interaction preference.
+> - Always wrap options using `"optionType": "manual"` for static lists.
+> - Add `mapData` when options are dynamic (e.g., from external sources).
+> - Include `text` for the button unless using `onlyMenu: true`.
+> - Toggle `showDataLoadingIndicators` if options are dynamic or fetched async.
+
+---
+
+#### 📍 Component: `file`
+
+**Required Fields:**
+- `uploadType` (string): Upload type must be either `"single"` or `"multiple"`.
+- `text` (string): Text label for the upload button.
+
+**Optional Fields:**
+- `showUploadList` (boolean): Whether to show a list of uploaded files.
+- `prefixIcon` (icon|string): Icon to display before the file button (e.g., `"/icon:solid/arrow-up-from-bracket"`).
+- `suffixIcon` (icon|string): Icon to display after the file button.
+- `fileType` (array): List of allowed file MIME types (e.g., `["image/png", "application/pdf"]`).
+- `maxFiles` (number): Maximum number of files allowed.
+- `maxSize` (number|string): Maximum file size (e.g., `5MB` or `5242880`).
+- `minSize` (number|string): Minimum file size allowed.
+- `forceCapture` (boolean): For mobile capture directly from camera or mic.
+- `disabled` (boolean): Disable file input.
+- `value` (array): List of file values (e.g., paths or identifiers).
+- `files` (array): Uploaded file objects.
+- `parseFiles` (boolean): Whether to auto-parse uploaded files.
+- `parsedValue` (array): Structured result from parsed files.
+- `onEvent` (function): Event handler object for upload-related actions.
+- `style` (object): Custom style for the file input wrapper.
+- `animationStyle` (object): Transition animation config.
+- `showDataLoadingIndicators` (boolean): Show spinner if upload state is async or pending.
+
+---
+
+**Example Output:**
+```json
+{
+  "text": "Browse",
+  "uploadType": "single",
+  "showUploadList": true,
+  "prefixIcon": "/icon:solid/arrow-up-from-bracket",
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define `text` for upload buttons.
+> - Use `uploadType: "single"` for one file or "multiple" for many.
+> - Show upload icons using `prefixIcon` and `suffixIcon`.
+> - Use `fileType`, `maxSize`, `maxFiles` for validation controls.
+> - Set `showUploadList: true` to preview uploaded items.
+> - Toggle `showDataLoadingIndicators` for async upload states.
+
+---
+
+#### 📍 Component: `fileViewer`
+
+**Required Fields:**
+- `src` (string): Source URL of the file to be displayed. Without this, no content will be rendered.
+
+**Optional Fields:**
+- `animationStyle` (object): Animation configuration applied to the viewer container.
+- `autoHeight` (string): Use `"auto"` or `fixed` to let the component auto-size its height.
+- `showVerticalScrollbar` (boolean): Enables vertical scrollbar if content exceeds height.
+- `style` (object): Custom styles for the file viewer container.
+- `showDataLoadingIndicators` (boolean): Display a loading spinner during async file loading.
+
+---
+
+**Example Output:**
+```json
+{
+  "src": "https://example.com/document.pdf",
+  "autoHeight": "auto",
+  "showVerticalScrollbar": false,
+  "animationStyle": {
+    "type": "fadeIn"
+  },
+  "style": {
+    "border": "1px solid #ccc"
+  },
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent (fileViewer)
+
+- Always include the `src` field. It is required to load and display the file content.
+- If the height is not specified, default to `"auto"` by setting `autoHeight: "auto"`.
+- Set `showVerticalScrollbar` to `true` **only if** the file content might overflow vertically (e.g., PDF, large text documents).
+- Include a `style` block when the component is nested inside other containers or when visual padding, borders, or layout adjustments are needed.
+- Use `showDataLoadingIndicators: false` unless the file loading is dynamic or expected to be delayed.
+- If `animationStyle` is used, prefer subtle types like `"fadeIn"` or `"zoomIn"` unless otherwise specified.
+
+---
+
+#### 📍 Component: `floatButton`
+
+**Required Fields:**
+- `icon` (string): Icon for the floating button (e.g., `"/icon:antd/questioncircleoutlined"`).
+- `buttons` (array|object): Grouped floating button items, must include:
+  - `id` (number): Unique identifier for each button.
+  - `label` (string): Label text.
+  - `badge` (string|number): Badge count (optional).
+  - `icon` (string): Icon for individual button.
+
+**Optional Fields:**
+- `value` (string): Optional data value carried with the button.
+- `shape` (string): Shape of the floating button. Options: `"circle"` or `"square"`.
+- `buttonTheme` (string): Theme of the button. Options: `"primary"`, `"default"`.
+- `includeMargin` (boolean): Adds margin space around the float button.
+- `image` (string): URL to display an image instead of an icon.
+- `dot` (boolean): Show a simple notification dot on the button.
+- `badgeStyle` (object): Style overrides for badge element.
+- `style` (object): Custom style for float button container.
+- `animationStyle` (object): Animation configuration for entrance/exit.
+- `showDataLoadingIndicators` (boolean): Show loading spinner when state is async.
+
+---
+
+**Example Output:**
+```json
+{
+  "value": "",
+  "includeMargin": true,
+  "icon": "/icon:antd/questioncircleoutlined",
+  "buttons": {
+    "manual": [
+      {
+        "id": 0,
+        "label": "Option 1",
+        "badge": "1",
+        "description": "",
+        "icon": "/icon:antd/filetextoutlined"
+      },
+      {
+        "id": 1,
+        "label": "Option 2",
+        "badge": "0",
+        "description": "",
+        "icon": "/icon:antd/filetextoutlined"
+      }
+    ]
+  },
+  "shape": "circle",
+  "buttonTheme": "primary",
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always provide a `root` icon and define a `buttons.manual` array with at least one button item.
+> - Each button must include `id`, `label`, and `icon`; `badge` is optional.
+> - Use `shape: "circle"` and `buttonTheme: "primary"` for standard round action button.
+> - Use `includeMargin: true` to space button from screen edges.
+> - Toggle `showDataLoadingIndicators` if float button state depends on dynamic content.
+
+---
+
+#### 📍 Component: `form`
+
+**Required Fields:**
+- `container` (object): Layout definition to contain nested components.
+  - Must include at least one region among: `header`, `body`, or `footer`.
+  - Nest child components using the `nest_component` action in `body`, `header`, or `footer`.
+
+**Optional Fields:**
+- `animationStyle` (object): Transition animation for the form.
+- `disableSubmit` (boolean): Disable the form submission entirely.
+- `disabled` (boolean): Disable interaction with all form fields.
+- `initialData` (object): Initial values for fields keyed by form control name.
+- `invalidFormMessage` (string): Message shown when form fails validation.
+- `loading` (boolean): Show a loading indicator on the form.
+- `onEvent` (function): Event handlers such as onSubmit, onReset, onValidate.
+- `resetAfterSubmit` (boolean): Resets form data to initial state upon successful submit.
+- `showDataLoadingIndicators` (boolean): Spinner for dynamic content or data fetch.
+- `container.showHeader` (boolean): Whether to show the header section.
+- `container.showBody` (boolean): Whether to show the body section.
+- `container.showFooter` (boolean): Whether to show the footer section.
+- `container.autoHeight` (string|boolean): Use `"auto"` or `true` for dynamic height.
+- `container.horizontalGridCells` (number): Grid width span (e.g., `24`).
+- `container.showVerticalScrollbar` (boolean): Enable/disable vertical scroll.
+- `container.scrollbars` (boolean): Enable/disable scrollbars.
+- `container.style` (object): Inline styles (e.g., border, padding).
+
+---
+
+**Example Output:**
+```json
+{
+  "container": {
+    "header": {},
+    "body": {
+      "0": {
+        "view": {}
+      }
+    },
+    "footer": {},
+    "showHeader": true,
+    "showBody": true,
+    "showFooter": true,
+    "autoHeight": "auto",
+    "showVerticalScrollbar": false,
+    "horizontalGridCells": 24,
+    "scrollbars": false,
+    "style": {
+      "borderWidth": "1px"
+    }
+  },
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include `container` with at least one of: `header`, `body`, or `footer`.
+> - Use `nest_component` in `container.body` to insert actual input elements or children.
+> - Toggle `showHeader`, `showBody`, and `showFooter` depending on layout needs.
+> - Use a`utoHeight: "auto"` for responsive layout height.
+> - Set `showDataLoadingIndicators` if form requires preloading or async behavior.
+
+---
+
+#### 📍 Component: `ganttChart`
+
+**Required Fields:**
+- _None explicitly marked as required. Include fields necessary for proper rendering._
+
+**Optional Fields:**
+- `links` (array): Task links/dependencies
+- `onTaskChange` (eventHandler): Task change event handler
+- `style` (object): Gantt chart style
+- `tasks` (array): Gantt chart tasks
+
+**Example Output:**
+```json
+{
+  "links": <array>,
+  "onTaskChange": <eventHandler>,
+  "style": <object>,
+  "tasks": <array>
+}
+```
+
+---
+
+#### 📍 Component: `geoMap`
+
+**Required Fields:**
+- _None explicitly marked as required. Include fields necessary for proper rendering._
+
+**Optional Fields:**
+- `center` (object): Map center coordinates
+- `layers` (array): Map layers
+- `onLayerClick` (eventHandler): Layer click event handler
+- `style` (object): Map style
+- `zoom` (number): Zoom level
+
+**Example Output:**
+```json
+{
+  "center": <object>,
+  "layers": <array>,
+  "onLayerClick": <eventHandler>,
+  "style": <object>,
+  "zoom": <number>
+}
+```
+
+---
+
+#### 📍 Component: `grid`
+
+**Required Fields:**
+- `noOfRows` (array | stringified JSON): List of data objects for each grid item.  
+- `noOfColumns` (string|number): Number of columns to display.  
+- `container` (object): Grid layout container where components are rendered using `nest_component`.
+
+**Optional Fields:**
+- `itemIndexName` (string): Variable name for the index in each item loop.  
+- `itemDataName` (string): Variable name for the current item’s data object.  
+- `heightUnitOfRow` (string|number): Height ratio of each row (used for grid sizing).  
+- `dynamicHeight` (string): Height mode for dynamic rows. Commonly set to `"auto"`.  
+- `autoHeight` (string): Use `"auto"` or `fixed` to let the container auto-size its height.
+- `horizontal` (boolean): Display grid horizontally instead of vertically.  
+- `minHorizontalWidth` (string): Minimum width per column when horizontal is true.  
+- `enableSorting` (boolean): Allow drag-and-drop sorting of grid items.  
+- `horizontalGridCells` (number): Horizontal layout span (e.g., 24-grid system).  
+- `verticalGridCells` (number): Vertical layout span (optional).  
+- `showBorder` (boolean): Display border around grid container.  
+- `scrollbars` (boolean): Toggle scrollbars (both directions).  
+- `showVerticalScrollbar` (boolean): Vertical scroll specifically.  
+- `showHorizontalScrollbar` (boolean): Horizontal scroll specifically.  
+- `pagination` (object): Configure pagination:
+  - `pageSize` (number|string): Number of items per page.
+  - `pageSizeOptions` (array|stringified): Available page sizes.
+  - `changeablePageSize` (boolean|null): Allow page size changes.
+
+- `style` (object): Style overrides for the grid.  
+- `animationStyle` (object): Animation effects on render.  
+- `showDataLoadingIndicators` (boolean): Show loader/spinner while data is loading.
+
+---
+
+**Example Output:**
+```json
+{
+  "noOfRows": "[{ \"title\": \"The Shawshank Redemption\", \"rate\": \"9.2\" }, { \"title\": \"The Godfather\", \"rate\": \"9.2\" }]",
+  "noOfColumns": "3",
+  "itemIndexName": "i",
+  "itemDataName": "currentItem",
+  "dynamicHeight": "auto",
+  "heightUnitOfRow": "1",
+  "container": {},
+  "autoHeight": "auto",
+  "showVerticalScrollbar": false,
+  "showHorizontalScrollbar": false,
+  "horizontalGridCells": 24,
+  "scrollbars": false,
+  "pagination": {
+    "changeablePageSize": null,
+    "pageSize": "6",
+    "pageSizeOptions": "[5, 10, 20, 50]"
+  },
+  "horizontal": false,
+  "minHorizontalWidth": "100px",
+  "enableSorting": false,
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include a stringified array for `noOfRows`, and specify `noOfColumns`.
+> - Use container with `nest_component` to add UI for each item in the grid.
+> - Use `itemDataName` (e.g., `"currentItem"`) and `itemIndexName` (e.g., `"i"`) to reference dynamic values in nested content.
+> - Set pagination with `pageSize`, and optionally allow changing size using `pageSizeOptions`.
+> - Set `dynamicHeight` to `"auto"` for responsive row height.
+
+---
+
+#### 📍 Component: `hillchart`
+
+**Required Fields:**
+- _None explicitly marked as required. Include fields necessary for proper rendering._
+
+**Optional Fields:**
+- `data` (array): Hillchart data
+- `onChange` (eventHandler): Change event handler
+- `style` (object): Hillchart style
+
+**Example Output:**
+```json
+{
+  "data": <array>,
+  "onChange": <eventHandler>,
+  "style": <object>
+}
+```
+
+---
+
+#### 📍 Component: `icon`
+
+**Required Fields:**
+- `icon` (icon|string): Icon name or path, such as `/icon:antd/homefilled`.  
+- `sourceMode` (string): Must be set to either `"standard"` (for internal icons) or `"asset-library"` (for uploaded assets).
+
+**Optional Fields:**
+- `iconScoutAsset` (object): Asset data when using `asset-library` source. Must include:
+  - `uuid` (string): Asset UUID
+  - `value` (string): Icon identifier or reference
+  - `preview` (string): Preview image URL or data URI  
+- `iconSize` (number|string): Icon size in pixels (e.g., `"20"`).  
+- `autoHeight` (string): Use `"auto"` or `fixed` to let the component auto-size its height.
+- `animationStyle` (object): Icon animation configuration.  
+- `onEvent` (eventHandler): Event handlers for actions like `click`, `hover`, `doubleClick`, etc.  
+- `style` (object): CSS-like styling for layout, margins, transforms, etc.  
+
+---
+
+**Example Output:**
+```json
+{
+  "sourceMode": "standard",
+  "icon": "/icon:antd/homefilled",
+  "iconScoutAsset": {
+    "uuid": "",
+    "value": "",
+    "preview": ""
+  },
+  "autoHeight": "auto",
+  "iconSize": "20"
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always set `sourceMode` to either `"standard"` or `"asset-library"`.
+> - When using `asset-library`, populate `iconScoutAsset` with `uuid`, `value`, and optional `preview`.
+> - Use `icon` for predefined icon references (e.g., `"/icon:antd/homefilled"`).
+> - If `autoHeight` is used, common values are `"auto"` or `"fixed"`.
+> - Include `iconSize` to control the visual dimensions explicitly.
+
+---
+
+#### 📍 Component: `iframe`
+
+**Required Fields:**
+- `src` (string): The source URL of the iframe. This must be a valid external or internal link that you want to embed.
+
+**Optional Fields:**
+- `height` (string): The height of the iframe (e.g., `"300px"`, `"100%"`).
+- `width` (string): The width of the iframe (e.g., `"100%"`, `"800px"`).
+- `style` (object): Additional styles to apply to the iframe container (e.g., border, padding, overflow).
+
+---
+
+**Example Output:**
+```json
+{
+  "src": "https://example.com/embed",
+  "height": "300px",
+  "width": "100%",
+  "style": {
+    "border": "none"
+  }
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include a valid `src` URL string for iframe rendering.
+> - Use optional `height` and `width` for dimension control.
+> - Apply `style` for layout or visual adjustments (like removing border).
+> - If not provided, the iframe may render without visual dimensions.
+
+---
+
+#### 📍 Component: `image`
+
+**Required Fields:**
+- `src` (string): Image source URL. Must be a valid image URL to render the image.
+
+**Optional Fields:**
+- `alt` (string): Alternative text for the image.
+- `height` (string): Height of the image (e.g., `"200px"`, `"auto"`).
+- `width` (string): Width of the image (e.g., `"100%"`, `"350px"`).
+- `style` (object): Custom styling for the image.
+- `sourceMode` (string): Image source mode (`"standard"` or `"asset-library"`).
+- `iconScoutAsset` (object): Object for asset library icon reference `{ uuid, value, preview }`.
+- `clipPath` (string): Clipping style for image (e.g., `"none"`, `"circle(50%)"`).
+- `autoHeight` (string): `"fixed"` or `"auto"`; determines height flexibility.
+- `restrictPaddingOnRotation` (string): Restriction mode for image rotation padding.
+- `enableOverflow` (boolean): If true, overflow is enabled.
+- `aspectRatio` (string): Aspect ratio (e.g., `"16 / 9"`, `"1 / 1"`).
+- `placement` (string): Positioning (e.g., `"top"`, `"center"`).
+- `overflow` (string): Overflow behavior (e.g., `"hidden"`, `"visible"`).
+- `positionX` (string): Horizontal alignment (`"left"`, `"center"`, `"right"`).
+- `positionY` (string): Vertical alignment (`"top"`, `"center"`, `"bottom"`).
+
+---
+
+**Example Output:**
+```json
+{
+  "src": "https://temp.im/350x400",
+  "alt": "Example Image",
+  "height": "300px",
+  "width": "100%",
+  "style": {
+    "borderRadius": "8px"
+  },
+  "aspectRatio": "16 / 9",
+  "placement": "top",
+  "overflow": "hidden",
+  "positionX": "center",
+  "positionY": "center"
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include a valid `src` to render the image.
+> - Include `aspectRatio` and `autoHeight` or specific `height`/`width` values for layout precision.
+> - Use `placement`, `positionX`, `positionY` for control over image alignment.
+> - Use `clipPath` or `style` for masking/styling if needed.
+> - Use `sourceMode` and `iconScoutAsset` only when sourcing from asset libraries.
+
+---
+
+#### 📍 Component: `imageEditor`
+
+**Required Fields:**
+- _None explicitly marked as required. Include fields necessary for proper rendering._
+
+**Optional Fields:**
+- `onEdit` (eventHandler): Edit event handler
+- `src` (string): Image source URL
+- `style` (object): Editor style
+- `tools` (array): Enabled editing tools
+
+**Example Output:**
+```json
+{
+  "onEdit": <eventHandler>,
+  "src": <string>,
+  "style": <object>,
+  "tools": <array>
+}
+```
+
+---
+
+#### 📍 Component: `input`
+
+**Required Fields:**
+- `label` (object): Object containing label metadata. Must include at minimum the `text` property.  
+- `value` (string): Input field value (can be empty or dynamic).  
+- `validationType` (string): Type of validation expected. Examples: `"Text"`, `"Number"` (Required for enforcing expected value format).
+
+**Optional Fields:**
+- `required` (boolean): Whether the input is required.
+- `allowClear` (boolean): Show clear (X) button.
+- `animationStyle` (object): Style for animation transitions.
+- `customRule` (string): Custom validation rule expression.
+- `defaultValue` (string): Default text to display initially.
+- `disabled` (boolean): If true, the input is disabled.
+- `formDataKey` (string): Field key to bind in form submission.
+- `inputFieldStyle` (object): Style for the input field element.
+- `labelStyle` (object): CSS styling for label text.
+- `maxLength` (number): Maximum number of characters.
+- `minLength` (number): Minimum number of characters.
+- `onEvent` (eventHandler): Event handler object for user interactions.
+- `placeholder` (string): Placeholder text.
+- `prefixIcon` (icon): Icon displayed before the input.
+- `readOnly` (boolean): If true, field cannot be edited.
+- `regex` (string): Regex string for validation.
+- `showCount` (boolean): Display current character count.
+- `showValidationWhenEmpty` (boolean): Show error when left empty.
+- `style` (object): Custom styling for the wrapper or container.
+- `suffixIcon` (icon): Icon shown at the end of the input.
+- `tabIndex` (number): Tab order index.
+- `viewRef` (ref): Reference object for programmatic control.
+
+---
+
+**Example Output:**
+```json
+{
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "value": "",
+  "validationType": "Text",
+  "placeholder": "Enter your name",
+  "required": true
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include a valid `label` object with `text` property.
+> - Ensure `value` and `validationType` are included even if empty.
+> - Add `placeholder`, `required`, and `style` properties as needed for UX.
+> - Prefix/suffix icons, validation rules, and read-only states are optional but useful for specific use cases.
+
+---
+
+#### 📍 Component: `jsonEditor`
+
+**Required Fields:**
+- `value` (object|string): Initial JSON data to populate the editor. Can be a raw object or a stringified JSON.  
+- `label` (object): Label configuration object with at least `text` property for rendering visible label.
+
+**Optional Fields:**
+- `onChange` (eventHandler): Event handler triggered when JSON is updated.
+- `style` (object): CSS styles applied to the editor container.
+- `autoHeight` (string|boolean): Automatically adjust height (`"auto"` or `true/false`).
+
+---
+
+**Example Output:**
+```json
+{
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "column",
+    "align": "left"
+  },
+  "value": {
+    "a": [1, 2, 3, 4, 5],
+    "b": false,
+    "c": {
+      "message": "hello world"
+    }
+  },
+  "autoHeight": "auto"
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include a valid value (object or stringified JSON) and a `label` with `text`.
+> - Use `autoHeight` to allow flexible resizing of the editor.
+> - Use `onChange` if the component needs to trigger actions on content update.
+> - Support formatting styles and nesting of deeply structured JSON in `value`.
+
+---
+
+#### 📍 Component: `jsonExplorer`
+
+**Required Fields:**
+- `value` (object|string): The JSON object or stringified JSON string to be displayed in the explorer.
+
+**Optional Fields:**
+- `style` (object): Style configuration for the explorer container.
+- `autoHeight` (string|boolean): Automatically adjust height (`"auto"` or `true/false`).
+- `indent` (string|number): Number of spaces used for indentation in the displayed JSON (e.g., `"2"` or `"4"`).
+- `expandToggle` (boolean): If `true`, enables toggling expansion/collapse of JSON tree.
+- `theme` (string): JSON explorer theme (e.g., `"shapeshifter:inverted"`).
+
+---
+
+**Example Output:**
+```json
+{
+  "value": {
+    "a": [1, 2, 3, 4, 5],
+    "b": false,
+    "c": {
+      "message": "hello world"
+    }
+  },
+  "autoHeight": "auto",
+  "indent": "4",
+  "expandToggle": true,
+  "theme": "shapeshifter:inverted"
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always provide the `value` as a JSON object or a valid JSON string.
+> - Use `indent` to enhance readability of complex or nested data.
+> - Include `expandToggle` for tree exploration and `theme` to control display appearance.
+> - `autoHeight` and `style` can be added to adjust layout dynamically within containers.
+
+---
+
+#### 📍 Component: `jsonLottie`
+
+**Required Fields:**
+- `value` (object|string): Lottie animation data (can be a raw object or stringified JSON).
+
+**Optional Fields:**
+- `autoPlay` (boolean): Whether the animation should play automatically.
+- `loop` (boolean|string): Loop mode — accepts `true`, `false`, `"single"`, etc.
+- `keepLastFrame` (boolean): Whether to retain the last frame after animation ends.
+- `speed` (string|number): Playback speed multiplier (e.g., `1`, `"1.5"`).
+- `width` (string|number): Width of the animation container.
+- `height` (string|number): Height of the animation container.
+- `animationStart` (string): Start mode (e.g., `"auto"`, `"manual"`).
+- `aspectRatio` (string): Aspect ratio, e.g., `"1/1"` or `"16/9"`.
+- `fit` (string): Fit mode for the container (`"contain"`, `"cover"`, etc.).
+- `align` (string): Alignment of the animation in container (`"0.5,0.5"` for center).
+- `style` (object): Custom style object for the animation wrapper.
+- `autoHeight` (string|boolean): Enables automatic height adjustment (`"auto"` or `true`).
+- `sourceMode` (string): Source type, e.g., `"standard"` or `"asset-library"`.
+- `iconScoutAsset` (object): Asset metadata from icon libraries (uuid, preview, value).
+
+---
+
+**Example Output:**
+```json
+{
+  "value": "{ \"v\": \"5.8.1\", ... }",
+  "autoPlay": true,
+  "loop": "single",
+  "keepLastFrame": true,
+  "speed": "1",
+  "width": "100",
+  "height": "100",
+  "animationStart": "auto",
+  "aspectRatio": "1/1",
+  "fit": "contain",
+  "align": "0.5,0.5",
+  "autoHeight": "auto",
+  "sourceMode": "standard",
+  "iconScoutAsset": {
+    "uuid": "",
+    "value": "",
+    "preview": ""
+  }
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always provide a `value` with valid Lottie JSON data (can be stringified or raw object).
+> - Use `autoPlay`, `loop`, and `keepLastFrame` for animation behavior.
+> - `width`, `height`, and `aspectRatio` help control layout; `fit` and `align` manage visual scaling and positioning.
+> - Use `sourceMode` and `iconScoutAsset` for asset-based workflows.
+
+---
+
+#### 📍 Component: `jsonSchemaForm`
+
+**Required Fields:**
+- `schema` (string|object): JSON Schema (stringified or object) that defines the structure of the form.
+- `formType` (string): The rendering engine type (e.g., `"rjsf"`).
+
+**Optional Fields:**
+- `formData` / `data` (string|object): Default form values (stringified or object).
+- `uiSchema` (string|object): UI customization schema (e.g., widget types, help texts).
+- `errorSchema` (string|object): Custom error messages per field or globally.
+- `validationState` (string|object): Validation metadata.
+- `onChange` (eventHandler): Change event handler.
+- `autoHeight` (boolean|string): Auto-height behavior for the component.
+- `showVerticalScrollbar` (boolean): Display vertical scrollbar.
+- `style` (object): Style settings for the component.
+
+---
+
+**Example Output:**
+```json
+{
+  "formType": "rjsf",
+  "schema": "{ \"title\": \"User Information\", ... }",
+  "data": "{ \"name\": \"David\", \"phone\": \"13488886666\", \"birthday\": \"1980-03-16\" }",
+  "uiSchema": "{ \"phone\": { \"ui:help\": \"at least 11 characters\" } }",
+  "errorSchema": "{ \"__errors\": [\"Custom error message\"] }",
+  "validationState": "{}",
+  "autoHeight": "auto",
+  "showVerticalScrollbar": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include a valid `schema` (as an object or stringified JSON).
+> - Add `formType` as `"rjsf"` unless specified otherwise.
+> - Use `data` to pre-fill the form; use `uiSchema` to control field behavior and help content.
+> - Define `errorSchema` and `validationState` to enhance user feedback.
+> - Avoid adding unused props; focus on schema-driven rendering logic.
+
+---
+
+#### 📍 Component: `kanban`
+
+**Required Fields:**
+- _None explicitly marked as required. Include fields necessary for proper rendering._
+
+**Optional Fields:**
+- `cards` (array): Kanban cards
+- `columns` (array): Kanban columns
+- `onCardMove` (eventHandler): Card move event handler
+- `style` (object): Kanban style
+
+**Example Output:**
+```json
+{
+  "cards": <array>,
+  "columns": <array>,
+  "onCardMove": <eventHandler>,
+  "style": <object>
+}
+```
+
+---
+
+#### 📍 Component: `listView`
+
+**Required Fields:**
+- `noOfRows` (array|string): Stringified array of data items to render in the list.
+- `noOfColumns` (number|string): Number of columns to layout list items.
+- `itemIndexName` (string): Variable name to access current index (e.g., `"i"`).
+- `itemDataName` (string): Variable name to access current item (e.g., `"currentItem"`).
+- `container` (object): Container object to hold nested components using `nest_component` actions.
+
+**Optional Fields:**
+- `autoHeight` (string): Auto height mode (`"auto"` or `"fixed"`).
+- `dynamicHeight` (string|boolean): Enable dynamic height behavior.
+- `heightUnitOfRow` (number|string): Height unit per row.
+- `horizontal` (boolean): Layout direction.
+- `horizontalGridCells` (number): Grid width across columns.
+- `minHorizontalWidth` (string): Minimum width of each item in horizontal layout.
+- `enableSorting` (boolean): Enables drag-and-drop sorting.
+- `scrollbars` (boolean): Enable internal scrollbars.
+- `showVerticalScrollbar` (boolean): Display vertical scrollbar.
+- `showHorizontalScrollbar` (boolean): Display horizontal scrollbar.
+- `pagination` (object): Pagination settings (`pageSize`, `pageSizeOptions`, etc.).
+- `onEvent` (eventHandler): Event actions like `sortChange`, etc.
+- `style` (object): List view style.
+
+---
+
+**Example Output:**
+```json
+{
+  "noOfRows": "[{ \"title\": \"The Shawshank Redemption\", ... }, ...]",
+  "noOfColumns": "1",
+  "itemIndexName": "i",
+  "itemDataName": "currentItem",
+  "container": {},
+  "autoHeight": "auto",
+  "dynamicHeight": "auto",
+  "heightUnitOfRow": "1",
+  "horizontal": false,
+  "horizontalGridCells": 24,
+  "minHorizontalWidth": "100px",
+  "enableSorting": false,
+  "scrollbars": false,
+  "showVerticalScrollbar": false,
+  "showHorizontalScrollbar": false,
+  "pagination": {
+    "changeablePageSize": null,
+    "pageSize": "6",
+    "pageSizeOptions": "[5, 10, 20, 50]"
+  }
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always set `noOfRows` as a stringified array of objects (e.g., fetched or static list items).
+> - `container` is where each list item layout is defined via nested components.
+> - Use `itemDataName` and `itemIndexName` for referencing values in nested components.
+> - Configure `pagination`, `scrollbars`, or `horizontal` as needed, but prioritize layout clarity.
+
+---
+
+#### 📍 Component: `mention`
+
+**Required Fields:**
+- `defaultValue` (string): Initial mention text value (can be empty).
+- `value` (string): Current mention value.
+- `mentionList` (string): A stringified object defining mentionable tokens (e.g., `@` or `#` with arrays of options).
+- `label` (object): Label configuration including `text`, `width`, `widthUnit`, `position`, and `align`.
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required.
+- `allowClear` (boolean): Enable clear button.
+- `animationStyle` (object): Animation styling.
+- `customRule` (string): Custom validation rule.
+- `disabled` (boolean): Disable the input.
+- `formDataKey` (string): Key to map data in form context.
+- `inputFieldStyle` (object): Custom input field style.
+- `labelStyle` (object): Custom label style.
+- `maxLength` (number): Maximum characters allowed.
+- `minLength` (number): Minimum characters required.
+- `onEvent` (eventHandler): Event bindings (e.g., onChange).
+- `placeholder` (string): Placeholder text.
+- `prefixIcon` (icon): Leading icon in the field.
+- `readOnly` (boolean): Read-only mode.
+- `regex` (string): Regex pattern for validation.
+- `showCount` (boolean): Show character count.
+- `showValidationWhenEmpty` (boolean): Display validation warning when empty.
+- `style` (object): Input styling.
+- `suffixIcon` (icon): Trailing icon.
+- `tabIndex` (number): Tab index order.
+- `viewRef` (ref): Input reference.
+- `autoHeight` (string): Auto height behavior.
+- `invalid` (string): Optional validation status or message.
+
+---
+
+**Example Output:**
+```json
+{
+  "defaultValue": "",
+  "value": "",
+  "mentionList": "{ \"@\": [\"John Doe\", \"Jane Doe\"], \"#\": [\"#tag1\", \"#tag2\"] }",
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "autoHeight": "auto"
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Ensure `mentionList` is always provided and stringified properly.
+> - Support for both `@` and `#` prefixes should be included where needed.
+> - Use `label` and `autoHeight` to maintain layout consistency.
+
+---
+
+#### 📍 Component: `mermaid`
+
+**Required Fields:**
+- _None explicitly marked as required. Include fields necessary for proper rendering._
+
+**Optional Fields:**
+- `code` (string): Mermaid diagram code
+- `style` (object): Mermaid style
+
+**Example Output:**
+```json
+{
+  "code": <string>,
+  "style": <object>
+}
+```
+
+---
+
+#### 📍 Component: `modal`
+
+**Required Fields:**
+- `visible` (boolean|string): Controls the visibility of the modal.
+- `horizontalGridCells` (number): Grid configuration for layout inside the modal.
+- `autoHeight` (string): Height behavior, typically `"auto"` or a fixed value.
+- `titleAlign` (string): Title alignment (`"left"`, `"center"`, `"right"`).
+- `modalScrollbar` (boolean): Whether to show a scrollbar inside the modal.
+- `maskClosable` (boolean): Whether clicking on the background mask closes the modal.
+- `showMask` (boolean): Whether to show the background overlay.
+- `toggleClose` (boolean): Whether to display a close button on the modal.
+- `container` (object): Container object to hold nested components using `nest_component` actions.
+
+**Optional Fields:**
+- `height` (string|number): Height of the modal.
+- `width` (string|number): Width of the modal.
+- `title` (string): Title of the modal.
+- `onEvent` (eventHandler): Event handlers (e.g., onOpen, onClose).
+- `style` (object): Custom styles for modal.
+
+---
+
+**Example Output:**
+```json
+{
+  "visible": true,
+  "horizontalGridCells": 24,
+  "autoHeight": "auto",
+  "titleAlign": "left",
+  "modalScrollbar": false,
+  "maskClosable": true,
+  "showMask": true,
+  "toggleClose": true,
+  "container": {} // nested components can be added using `nest_component` actions
+}
+```
+
+🧠 Prompt Guidance for AI Agent
+> - Always include `container` as an object, even if empty, to support nested structure.
+> - Set `horizontalGridCells` and `autoHeight` for layout responsiveness.
+> - Use `visible` as a toggle control (`true` / `false` or string bound value).
+> - Default `titleAlign` to `"left"` unless context demands otherwise.
+> - Maintain consistency of modal structure by including all key layout and behavior toggles like `showMask`, `toggleClose`, and `modalScrollbar`.
+
+---
+
+#### 📍 Component: `module`
+
+**Required Fields:**
+- `appId` (string): Unique identifier for the app/module being embedded.
+- `autoHeight` (string): Height behavior, such as `"auto"` or `"fixed"`.
+- `scrollbars` (boolean): Whether scrollbars are enabled within the module.
+- `loadModuleInDomWhenHide` (boolean): Keep the module mounted in the DOM even when hidden.
+- `error` (string): Error message placeholder (can be empty or dynamic).
+
+**Optional Fields:**
+- `events` (eventHandler): Event handlers for the module lifecycle or interactions.
+- `inputs` (object): Input data passed into the module.
+
+---
+
+**Example Output:**
+```json
+{
+  "appId": "68529b0a5818352d45782439",
+  "error": "",
+  "autoHeight": "auto",
+  "scrollbars": false,
+  "loadModuleInDomWhenHide": true
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Ensure `appId` is always present and set correctly.
+> - Default `autoHeight` to `"auto"` unless specific height constraints are required.
+> - Use `loadModuleInDomWhenHide` as `true` when state persistence is important.
+> - Leave `error` as an empty string initially but allow for dynamic updates.
+
+---
+
+#### 📍 Component: `multiSelect`
+
+**Required Fields:**
+- `label` (object): Label configuration including text, width, position, and alignment.
+- `options` (object): Option source and values for the dropdown (manual or mapped).
+- `showSearch` (boolean): Whether the search input is enabled.
+- `defaultValue` (array|stringified array): Default selected values.
+- `value` (array|string): Currently selected value(s).
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required.
+- `allowClear` (boolean): Allow clearing the selection.
+- `childrenInputFieldStyle` (object): Style for children in multi-select.
+- `disabled` (boolean): Disabled state.
+- `formDataKey` (string): Form data key for integration with forms.
+- `inputFieldStyle` (object): Input field style.
+- `inputValue` (string): User's input value when searching.
+- `labelStyle` (object): Label style.
+- `margin` (string): Margin for the select input.
+- `onEvent` (eventHandler): Event handlers.
+- `padding` (string): Padding for the select input.
+- `placeholder` (string): Placeholder text.
+- `style` (object): Select style.
+- `validateMessage` (string): Validation message.
+- `validateStatus` (string): Validation status.
+- `viewRef` (ref): Reference to the select element.
+
+---
+
+**Example Output:**
+```json
+{
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "options": {
+    "optionType": "manual",
+    "manual": {
+      "manual": [
+        { "value": "1", "label": "Option 1" },
+        { "value": "2", "label": "Option 2" }
+      ]
+    },
+    "mapData": {
+      "data": "[]"
+    }
+  },
+  "showSearch": true,
+  "defaultValue": "[\"1\",\"2\"]",
+  "value": ""
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define `label`, `options`, `defaultValue`, and `value` for correct rendering.
+> - `showSearch` improves UX for large datasets — default to `true` unless explicitly disabled.
+> - Values such as `defaultValue` may be stringified arrays — ensure proper handling.
+
+---
+
+#### 📍 Component: `navigation`
+
+**Required Fields:**
+- `horizontalAlignment` (string): Horizontal alignment of the navigation items (`left`, `center`, `right`, or `justify`).
+- `items` (array): Navigation menu items, each object includes:
+  - `label` (string): Text label for the menu item.
+  - `onEvent` (array): Event handlers such as `click`, with configuration.
+
+**Optional Fields:**
+- `animationStyle` (object): Animation style.
+- `logoEvent` (array): Event handler configuration for logo interaction (e.g. click).
+- `logoUrl` (string): Logo image URL.
+- `style` (object): Navigation bar style.
+
+---
+
+**Example Output:**
+```json
+{
+  "horizontalAlignment": "left",
+  "items": [
+    {
+      "label": "Menu Item 1",
+      "onEvent": [
+        {
+          "name": "click",
+          "handler": {
+            "compType": "openAppPage",
+            "comp": {
+              "query": [{}],
+              "hash": [{}]
+            },
+            "condition": "",
+            "slowdown": "debounce",
+            "delay": ""
+          }
+        }
+      ]
+    }
+  ],
+  "logoEvent": [
+    {
+      "name": "click",
+      "handler": {
+        "compType": "empty",
+        "comp": {},
+        "condition": "",
+        "slowdown": "debounce",
+        "delay": ""
+      }
+    }
+  ]
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define at least one item in the `items` array with a `label` and `onEvent`.
+> - `horizontalAlignment` is required to determine menu layout.
+> - Use `logoEvent` if a logo is clickable. `logoUrl` can be added to display the brand mark.
+> - Ensure event handlers use correct structure for `compType`, `comp`, and debounce settings.
+
+---
+
+#### 📍 Component: `numberInput`
+
+**Required Fields:**
+- `formatter` (string): Format style for number input (e.g., `standard`)
+- `step` (number|string): Increment/decrement step size
+- `controls` (boolean): Whether to show increment/decrement controls
+- `thousandsSeparator` (boolean): Show thousand separators for readability
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required
+- `allowNull` (boolean): Allow null value
+- `animationStyle` (object): Animation style
+- `customRule` (string): Custom validation rule
+- `defaultValue` (string): Default value (as string)
+- `disabled` (boolean): Disabled state
+- `formDataKey` (string): Key to bind with form data
+- `inputFieldStyle` (object): Style for input field
+- `label` (string|object): Input label (can be plain string or an object with layout properties)
+- `labelStyle` (object): Style for label
+- `max` (number): Maximum allowed value
+- `min` (number): Minimum allowed value
+- `onEvent` (eventHandler): Event handler object
+- `placeholder` (string): Placeholder text
+- `precision` (number): Number of decimal places
+- `prefixIcon` (icon): Icon shown before input
+- `prefixText` (string): Text prefix for the input
+- `readOnly` (boolean): Read-only input
+- `showValidationWhenEmpty` (boolean): Show validation if left empty
+- `style` (object): Input style
+- `tabIndex` (number): Tab index for keyboard navigation
+- `validateMessage` (string): Validation message
+- `validateStatus` (string): Validation status
+- `value` (number|string): Current value
+- `viewRef` (ref): Input reference for programmatic access
+
+---
+
+**Example Output:**
+```json
+{
+  "formatter": "standard",
+  "step": "1",
+  "controls": true,
+  "thousandsSeparator": true,
+  "defaultValue": "",
+  "value": "",
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "prefixText": ""
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include `"formatter"`, `"step"`, `"controls"`, and `"thousandsSeparator"` for this component to function properly.
+> - Use `label` as an object if layout customization is needed.
+> - Accept `defaultValue` and `value` as strings or numbers based on use case.
+
+---
+
+#### 📍 Component: `pageLayout`
+
+**Required Fields:**
+- `container` (object): Page container structure with nested layout sections such as `header`, `sider`, `body`, `footer`.
+- `container.showHeader` (boolean): Controls visibility of the header section.
+- `container.showSider` (boolean): Controls visibility of the sider (sidebar).
+- `container.innerSider` (boolean): Determines if sider is inside the content layout.
+- `container.siderCollapsible` (boolean): Whether the sider is collapsible.
+- `container.siderCollapsed` (boolean): Whether the sider is currently collapsed.
+- `container.siderRight` (boolean): Whether the sider is displayed on the right.
+- `container.siderWidth` (string): Width of the sider (e.g., `"20%"`).
+- `container.siderCollapsedWidth` (string): Width of the sider when collapsed.
+- `container.horizontalGridCells` (number): Number of horizontal grid cells.
+- `container.autoHeight` (string): `"auto"` or `"fixed"` height behavior.
+- `container.siderScrollbars` (boolean): Enable scrollbars in sider.
+- `container.contentScrollbars` (boolean): Enable scrollbars in content.
+- `container.mainScrollbars` (boolean): Enable scrollbars in the main layout.
+
+**Optional Fields:**
+- `appliedThemeId` (string): ID of the applied theme.
+- `baseUrl` (string): Base URL for the embedded app.
+- `bodyStyle` (object): Style for body section.
+- `contentApp` (string): App ID for embedded app content.
+- `footerStyle` (object): Style for footer section.
+- `headerStyle` (object): Style for header section.
+- `siderStyle` (object): Style for sider section.
+- `style` (object): Overall layout style.
+
+---
+
+**Example Output:**
+```json
+{
+  "container": {
+    "header": {},
+    "sider": {},
+    "body": {
+      "0": {
+        "view": {}
+      }
+    },
+    "footer": {},
+    "showHeader": true,
+    "showSider": true,
+    "innerSider": true,
+    "siderCollapsible": false,
+    "siderCollapsed": false,
+    "siderRight": false,
+    "siderWidth": "20%",
+    "siderCollapsedWidth": "0",
+    "horizontalGridCells": 24,
+    "autoHeight": "auto",
+    "siderScrollbars": false,
+    "contentScrollbars": false,
+    "mainScrollbars": false
+  }
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include the full `container` structure with keys: `header`, `sider`, `body`, `footer`.
+> - Also specify layout configuration like `showHeader`, `showSider`, and `siderWidth` for proper rendering.
+> - You can add components inside each container using the `nest_component` action.
+
+---
+
+#### 📍 Component: `password`
+
+**Required Fields:**
+- `defaultValue` (string): Initial value for the password field.
+- `value` (string): Current value of the password field.
+- `label` (object): Label configuration object. Must include:
+  - `text` (string): The label text.
+  - `width` (string|number): Width of the label.
+  - `widthUnit` (string): Unit for label width (e.g., `%`).
+  - `position` (string): Label position (e.g., `row`, `column`).
+  - `align` (string): Label text alignment (e.g., `left`, `right`, `center`).
+- `visibilityToggle` (boolean): Whether the password visibility toggle icon is shown.
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required
+- `allowClear` (boolean): Allow clearing the password
+- `animationStyle` (object): Animation style configuration
+- `customRule` (string): Custom validation rule
+- `disabled` (boolean): Disable the input field
+- `formDataKey` (string): Key used in form data submission
+- `inputFieldStyle` (object): Custom style for the input field
+- `labelStyle` (object): Style for the label
+- `maxLength` (number): Maximum allowed characters
+- `minLength` (number): Minimum required characters
+- `onEvent` (eventHandler): Event handlers (e.g., onChange, onBlur)
+- `placeholder` (string): Placeholder text
+- `prefixIcon` (icon): Icon displayed before the input
+- `readOnly` (boolean): Make the input read-only
+- `regex` (string): Regex pattern for validation
+- `showCount` (boolean): Show character count
+- `showValidationWhenEmpty` (boolean): Show validation message even when empty
+- `style` (object): Style configuration for the input
+- `suffixIcon` (icon): Icon displayed after the input
+- `tabIndex` (number): Tab index for navigation
+- `viewRef` (ref): Reference for programmatic access
+
+---
+
+**Example Output:**
+```json
+{
+  "defaultValue": "",
+  "value": "",
+  "label": {
+    "text": "Password",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "visibilityToggle": true
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include `defaultValue`, `value`, `label`, and `visibilityToggle` fields.
+> - The label must be an object with keys: `text`, `width`, `widthUnit`, `position`, and `align`.
+> - Include optional fields like `placeholder`, `regex`, `required`, or `onEvent` based on the use case.
+> - If password visibility control is needed, set `visibilityToggle`: true.
+> - Use `validationType` as `"Regex"` if regex is being used and provide a valid pattern in `regex`.
+
+---
+
+#### 📍 Component: `pivotTable`
+
+**Required Fields:**
+- _None explicitly marked as required. Include fields necessary for proper rendering._
+
+**Optional Fields:**
+- `aggregatorName` (string): Aggregator function
+- `cols` (array): Column fields
+- `data` (array): Pivot table data
+- `rendererName` (string): Renderer function
+- `rows` (array): Row fields
+- `style` (object): Pivot table style
+
+**Example Output:**
+```json
+{
+  "aggregatorName": <string>,
+  "cols": <array>,
+  "data": <array>,
+  "rendererName": <string>,
+  "rows": <array>,
+  "style": <object>
+}
+```
+
+---
+
+#### 📍 Component: `progress`
+
+**Required Fields:**
+- `value` (number): Current progress value (in percent). This is essential for rendering the progress state.
+
+**Optional Fields:**
+- `animationStyle` (object): Animation style configuration
+- `hidden` (boolean): Whether to hide the progress component
+- `showInfo` (boolean): Display percentage or label alongside progress bar
+- `style` (object): Style customization for the progress bar
+
+---
+
+**Example Output:**
+```json
+{
+  "value": 60,
+  "showInfo": true,
+  "style": {
+    "color": "#1890ff"
+  }
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always set the `"value"` field as a number to indicate progress percentage.
+> - Optionally include `showInfo: true` if the progress percentage should be displayed.
+> - Add `style` to customize appearance, and `animationStyle` for animated transitions.
+> - Use `hidden: true` to render the component invisible without removing it from layout.
+
+---
+
+#### 📍 Component: `progressCircle`
+
+**Required Fields:**
+- `value` (number): Current progress value (in percent). Determines how much of the circle is filled.
+
+**Optional Fields:**
+- `animationStyle` (object): Animation style for the circle
+- `hidden` (boolean): If true, the component is hidden
+- `style` (object): Style customization for the progress circle
+
+---
+
+**Example Output:**
+```json
+{
+  "value": 60,
+  "animationStyle": {
+    "type": "fadeIn"
+  },
+  "hidden": false,
+  "style": {
+    "strokeColor": "#52c41a"
+  }
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always set the "value" field as a number to indicate progress percentage.
+> - Include optional fields like "animationStyle" for transition effects, "style" for color or stroke width, and "hidden" for conditional display.
+> - This component displays circular progress visually based on the value.
+
+---
+
+#### 📍 Component: `qrCode`
+
+**Required Fields:**
+- `value` (string): Text or URL to encode in the QR code
+
+**Optional Fields:**
+- `animationStyle` (object): Animation effects for the QR code display
+- `hidden` (boolean): Whether the component is hidden
+- `image` (string): URL of an image to embed in the center of the QR code
+- `includeMargin` (boolean): Adds whitespace around the QR code
+- `level` (string): Error correction level; one of `"L"`, `"M"`, `"Q"`, or `"H"` (default is `"L"`)
+- `restrictPaddingOnRotation` (string): Restriction mode for padding during rotation
+- `style` (object): Custom styling for the QR code
+
+---
+
+**Example Output:**
+```json
+{
+  "value": "https://example.com",
+  "level": "L",
+  "includeMargin": true,
+  "restrictPaddingOnRotation": "qrCode",
+  "style": {
+    "width": "150px",
+    "height": "150px"
+  }
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include the `"value"` field with a string that represents the data or URL to encode.
+> - Use `"level"` to set error correction strength (`"L"` = Low, `"H"` = High, etc.).
+> - Optional settings like `"image"` and `"includeMargin"` enhance visual clarity or branding.
+
+---
+
+#### 📍 Component: `radio`
+
+**Required Fields:**
+- `options` (array): Radio options to display (must include `value` and `label` for each option)
+- `layout` (string): Layout direction of radio buttons (`horizontal`, `vertical`, `auto_columns`)
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required
+- `animationStyle` (object): Animation effects
+- `defaultValue` (string): Default selected value
+- `disabled` (boolean): Disabled state
+- `formDataKey` (string): Form data key for integration
+- `inputFieldStyle` (object): Input styling
+- `label` (string or object): Label configuration
+- `labelStyle` (object): Style for the label
+- `onEvent` (eventHandler): Event callbacks (e.g. change)
+- `style` (object): Style of the radio group
+- `tabIndex` (number): Tab index for keyboard navigation
+- `validateMessage` (string): Custom validation message
+- `validateStatus` (string): Validation status indicator
+- `value` (string): Selected value
+- `viewRef` (ref): Reference to the radio input
+
+---
+
+**Example Output:**
+```json
+{
+  "options": [
+    { "value": "1", "label": "Option 1" },
+    { "value": "2", "label": "Option 2" }
+  ],
+  "layout": "horizontal",
+  "defaultValue": "",
+  "value": "",
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  }
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include `"options"` as a stringified array of objects with `value` and `label`.
+> - Set `"layout"` to define orientation.
+> - Add `"label"` as either a plain string or an object for styled labels.
+> - `"defaultValue"` and `"value"` should reflect a valid option value.
+
+---
+
+#### 📍 Component: `rangeSlider`
+
+**Required Fields:**
+- `min` (number): Minimum value of the range
+- `max` (number): Maximum value of the range
+- `step` (number): Step size between values
+- `start` (number): Starting value of the selected range
+- `end` (number): Ending value of the selected range
+
+**Optional Fields:**
+- `label` (string | object): Label for the slider (can be a plain string or object with text and layout configuration)
+- `animationStyle` (object): Animation effects for transitions
+- `disabled` (boolean): Whether the slider is disabled
+- `inputFieldStyle` (object): Style for the input fields if any
+- `labelStyle` (object): Style applied to the label
+- `onEvent` (eventHandler): Event callbacks
+- `prefixIcon` (icon): Icon shown before the input
+- `style` (object): Style applied to the slider
+- `suffixIcon` (icon): Icon shown after the input
+- `tabIndex` (number): Tab index for accessibility
+- `vertical` (boolean): Orientation of the slider
+
+---
+
+**Example Output:**
+```json
+{
+  "min": 0,
+  "max": 100,
+  "step": 1,
+  "start": 10,
+  "end": 60,
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  }
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always provide numeric values for `"min"`, `"max"`, `"step"`, `"start"`, and `"end"` fields.
+> - `"label"` can be plain text or a styled label object.
+> - Ensure `"start"` is greater than or equal to `"min"` and less than `"end"`.
+> - Ensure `"end"` is less than or equal to `"max"` and greater than `"start"`.
+
+---
+
+#### 📍 Component: `rating`
+
+**Required Fields:**
+- `max` (number): Maximum rating value (e.g., 5)
+- `value` (number): Current rating value (must be a number, even if initially empty)
+- `label` (object): Label object with configuration (e.g., text, width, position, align)
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required
+- `animationStyle` (object): Animation effects
+- `disabled` (boolean): Whether the rating component is disabled
+- `formDataKey` (string): Key for form data integration
+- `inputFieldStyle` (object): Custom style for the rating input field
+- `labelStyle` (object): Style for the label
+- `onEvent` (eventHandler): Event handling configuration
+- `style` (object): Style for the component
+- `validateMessage` (string): Custom message for validation feedback
+- `validateStatus` (string): Current validation status (e.g., "error", "success")
+
+---
+
+**Example Output:**
+```json
+{
+  "value": 0,
+  "max": 5,
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  }
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always specify `"max"` and `"value"` as numbers.
+> - `"label"` should be included as an object with layout metadata.
+> - If `"value"` is initially empty, use a placeholder like `0` to indicate no selection.
+> - Use `"required": true` when the rating must be selected by the user.
+
+---
+
+#### 📍 Component: `responsiveLayout`
+
+**Required Fields:**
+- `columns` (array): Definition of responsive layout columns. Each must have at least `id`, `label`, and `key`.
+- `containers` (object): A map linking each column ID to a container object for nested components.
+- `horizontalGridCells` (number): Total number of horizontal layout grid units.
+- `verticalGridCells` (number): Total number of vertical layout grid units.
+- `columnPerRowLG` (number): Columns per row for large screens.
+- `columnPerRowMD` (number): Columns per row for medium screens.
+- `columnPerRowSM` (number): Columns per row for small screens.
+
+**Optional Fields:**
+- `animationStyle` (object): Animation style for transitions
+- `autoHeight` (string): Auto-height setting (`"auto"` or `"fixed"`)
+- `columnStyle` (object): Style applied to each column
+- `disabled` (boolean): Disable the layout
+- `horizontalSpacing` (number): Space between columns (horizontal)
+- `mainScrollbar` (boolean): Show scrollbar in main layout
+- `matchColumnsHeight` (boolean): Force equal height across columns
+- `rowBreak` (boolean): Enable row wrap when space is insufficient
+- `style` (object): Outer style applied to the layout row
+- `useComponentWidth` (boolean): Use the component width instead of viewport width
+- `verticalSpacing` (number): Space between rows (vertical)
+
+---
+
+**Example Output:**
+```json
+{
+  "columns": {
+    "manual": [
+      {
+        "id": 0,
+        "label": "Column1",
+        "key": "Column1"
+      },
+      {
+        "id": 1,
+        "label": "Column2",
+        "key": "Column2"
+      }
+    ]
+  },
+  "containers": {
+    "0": {},
+    "1": {}
+  },
+  "horizontalGridCells": 24,
+  "verticalGridCells": 24,
+  "columnPerRowLG": 4,
+  "columnPerRowMD": 2,
+  "columnPerRowSM": 1,
+  "autoHeight": "auto",
+  "rowBreak": true,
+  "useComponentWidth": true,
+  "matchColumnsHeight": true,
+  "verticalSpacing": 8,
+  "horizontalSpacing": 8
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define `"columns"` with at least `id`, `label`, and `key`.
+> - Ensure a matching `"containers"` object exists with keys corresponding to column IDs.
+> - Set `columnPerRowLG`, `columnPerRowMD`, and `columnPerRowSM` to guide how the layout adjusts across breakpoints.
+> - Default to 24 grid units (`horizontalGridCells`, `verticalGridCells`) unless specified otherwise.
+
+---
+
+#### 📍 Component: `richTextEditor`
+
+**Required Fields:**
+- `value` (string): Content of the editor
+- `toolbar` (array|string): Toolbar configuration. Can be a structured JSON array or a serialized string representing toolbar layout.
+
+**Optional Fields:**
+- `animationStyle` (object): Animation and transition styles
+- `onChange` (eventHandler): Handler for content change events
+- `readOnly` (boolean): Enables read-only mode
+- `style` (object): Style object for the editor container
+- `toolbarOptions` (array): Alternative way to provide toolbar config (used internally)
+- `placeholder` (string): Placeholder text shown when editor is empty
+- `autoHeight` (string): Height mode — `"auto"` or `"fixed"`
+- `contentScrollBar` (boolean): Toggle scrollbars inside the content area
+
+**Example Output:**
+```json
+{
+  "value": "",
+  "toolbar": [[{"header":[1,2,3,false]}],["bold","italic","underline","strike","blockquote"],[{"list":"ordered"},{"list":"bullet"}],[{"indent":"-1"},{"indent":"+1"}],[{"color":[]},{"background":[]},{"align":[]}],["link","image"],["clean"]],
+  "autoHeight": "fixed",
+  "placeholder": "Please Input...",
+  "contentScrollBar": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always provide the `"value"` and `"toolbar"` when generating this component.
+> - The `"toolbar"` can be passed as a raw JSON array or serialized string (ensure it represents a valid Quill toolbar layout).
+> - Default to `"Please Input..."` for placeholder and `"fixed"` for autoHeight if unspecified.
+> - Use `contentScrollBar: false` to hide scrollbars unless the editor needs to scroll vertically.
+
+---
+
+#### 📍 Component: `scanner`
+
+**Required Fields:**
+- `text` (string): Button or label text for the scan action
+- `uniqueData` (boolean): If true, ensures scanned data is unique per session
+- `maskClosable` (boolean): If true, closes the scan overlay when the mask is clicked
+
+**Optional Fields:**
+- `animationStyle` (object): Animation and transition styles
+- `disabled` (boolean): Disabled state of the scanner trigger
+- `onScan` (eventHandler): Event handler triggered on successful scan
+- `scanType` (string): Type of scan supported (`barcode`, `qrcode`, etc.)
+- `style` (object): Custom style for the scanner component
+- `data` (string): Scanned data (usually set dynamically)
+
+**Example Output:**
+```json
+{
+  "text": "Click Scan",
+  "uniqueData": true,
+  "maskClosable": true,
+  "data": "",
+  "scanType": "qrcode"
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include `"text"`, `"uniqueData"`, and `"maskClosable"` in the output.
+> - `"data"` is optional and typically left empty on initialization.
+> - Use `"scanType"` such as `"barcode"` or `"qrcode"` if specific scanning is needed.
+> - Attach `"onScan"` handler when capturing or reacting to scan results.
+
+---
+
+#### 📍 Component: `segmentedControl`
+
+**Required Fields:**
+- `label` (object): Defines the label for the segmented control (text, width, position, align)
+- `options` (object): Options for the segmented control (can be manually set or mapped)
+- `value` (string|number): Currently selected value
+
+**Optional Fields:**
+- `defaultValue` (string|number): Default value of the control
+- `required` (boolean): Whether the field is required
+- `animationStyle` (object): Animation and transition styles
+- `disabled` (boolean): Disabled state
+- `formDataKey` (string): Used for form integration
+- `inputFieldStyle` (object): Style applied to the input field
+- `labelStyle` (object): Style applied to the label
+- `onEvent` (eventHandler): Event handlers such as `onChange`
+- `style` (object): Overall style of the segmented control
+- `validateMessage` (string): Validation message to display
+- `validateStatus` (string): Validation status (e.g., "error", "warning")
+
+**Example Output:**
+```json
+{
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "options": {
+    "optionType": "manual",
+    "manual": {
+      "manual": [
+        {
+          "value": "1",
+          "label": "Option 1"
+        },
+        {
+          "value": "2",
+          "label": "Option 2"
+        }
+      ]
+    },
+    "mapData": {
+      "data": "[]"
+    }
+  },
+  "value": ""
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include `"label"`, `"options"`, and `"value"` in the component definition.
+> - Set `"optionType": "manual"` with `manual.manual[]` array for static entries.
+> - `"value"` should reflect one of the defined option values.
+> - Use `"label"` to configure layout and alignment metadata.
+> - `"defaultValue"` may be used optionally to preset selection.
+
+---
+
+#### 📍 Component: `select`
+
+**Required Fields:**
+- `label` (object): Configuration for the label (e.g., text, width, alignment)
+- `options` (object): Options data source; must include manual list or mapped data
+- `value` (string): Currently selected value
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required
+- `defaultValue` (string): Default selected value
+- `allowClear` (boolean): Allow user to clear the selection
+- `disabled` (boolean): Disable the select input
+- `formDataKey` (string): Key for binding to a form
+- `inputFieldStyle` (object): Style for the input field
+- `inputValue` (string): User's input while searching
+- `labelStyle` (object): Style for the label
+- `margin` (string|object): Margin settings for the select input
+- `padding` (string|object): Padding settings for the select input
+- `onEvent` (eventHandler): Event handler definitions
+- `placeholder` (string): Placeholder text
+- `showSearch` (boolean): Enable search functionality within options
+- `style` (object): Component styling
+- `validateMessage` (string): Validation message
+- `validateStatus` (string): Validation status indicator
+- `viewRef` (ref): Reference to the input component
+
+**Example Output:**
+```json
+{
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "options": {
+    "optionType": "manual",
+    "manual": {
+      "manual": [
+        {
+          "value": "1",
+          "label": "Option 1"
+        },
+        {
+          "value": "2",
+          "label": "Option 2"
+        }
+      ]
+    },
+    "mapData": {
+      "data": "[]"
+    }
+  },
+  "value": ""
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include the `"label"` (with subfields), `"options"` (with either manual or mapped values), and `"value"` in the component configuration.
+> - When specifying `options`, use `"optionType": "manual"` with a corresponding `manual.manual[]` array for static entries.
+> - Use `"showSearch": true` if search should be enabled.
+> - Default and selected values should match one of the defined option values.
+
+---
+
+#### 📍 Component: `shape`
+
+**Required Fields:**
+- `container` (object): Layout container structure with nested sections (`header`, `body`, `footer`) for component nesting
+- `container.showHeader` (boolean): Whether the header section is visible
+- `container.showBody` (boolean): Whether the body section is visible
+
+**Optional Fields:**
+- `icon` (string): Optional icon to display inside the shape
+- `container.autoHeight` (string): Height configuration for auto-sizing (`"auto"` or fixed)
+- `container.scrollbars` (boolean): Whether to show scrollbars in the shape container
+- `container.showVerticalScrollbar` (boolean): Show vertical scrollbar
+- `container.horizontalGridCells` (number): Horizontal grid layout configuration
+- `container.style` (object): Shape container style (e.g., borders, padding, background)
+- `showDataLoadingIndicators` (boolean): Toggle for loading indicator visibility
+- `preventStyleOverwriting` (boolean): Prevent override of style by outer context
+
+**Example Output:**
+```json
+{
+  "icon": "",
+  "container": {
+    "header": {},
+    "body": {
+      "0": {
+        "view": {}
+      }
+    },
+    "footer": {},
+    "showHeader": true,
+    "showBody": true,
+    "autoHeight": "auto",
+    "showVerticalScrollbar": false,
+    "horizontalGridCells": 24,
+    "scrollbars": false,
+    "style": {
+      "borderWidth": "1px"
+    }
+  },
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define the `"container"` object with at least the `"header"`, `"body"`, `"footer"` keys and flags like `"showHeader"` and `"showBody"`.
+> - Use `"container.style"` to define visual styles like borders and padding.
+> - Nest components using `"nest_component"` actions inside the `"header"`, `"body"`, or `"footer"` as needed.
+
+---
+
+#### 📍 Component: `signature`
+
+**Required Fields:**
+- `tips` (string): Instructional text or hint displayed near the signature pad
+
+**Optional Fields:**
+- `label` (object): Label configuration including `text`, `width`, `widthUnit`, `position`, and `align`
+- `onChange` (eventHandler): Change event handler for capturing signature updates
+- `showUndo` (boolean): Show undo button to revert the last stroke
+- `showClear` (boolean): Show clear button to reset the signature area
+- `style` (object): Custom styles for the signature pad
+- `value` (string): Signature data (Base64 image or SVG string)
+- `showDataLoadingIndicators` (boolean): Show data loading indicators
+
+**Example Output:**
+```json
+{
+  "tips": "Sign Here",
+  "label": {
+    "text": "",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "column",
+    "align": "left"
+  },
+  "showUndo": true,
+  "showClear": true,
+  "onChange": <eventHandler>,
+  "style": <object>,
+  "value": "",
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include a meaningful `"tips`" string to guide the user on what to do (e.g., `"Sign Here"`).
+> - Use `"label"` if you want to add descriptive text and control layout/alignment of the label.
+> - Include `"showUndo"` and `"showClear"` for better UX, allowing users to revert or clear their signature.
+> - Use `"onChange"` to handle actions after the signature is drawn or updated.
+
+---
+
+#### 📍 Component: `slider`
+
+**Required Fields:**
+- `min` (number): Minimum slider value
+- `max` (number): Maximum slider value
+- `step` (number): Step size for value increments
+- `value` (number): Current slider value
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required
+- `animationStyle` (object): Animation style
+- `disabled` (boolean): Disabled state
+- `formDataKey` (string): Form data key for integration with forms
+- `inputFieldStyle` (object): Input field style
+- `label` (object): Label configuration including `text`, `width`, `widthUnit`, `position`, and `align`
+- `labelStyle` (object): Label style
+- `onEvent` (eventHandler): Event handlers
+- `prefixIcon` (icon): Icon to display before the slider
+- `style` (object): Slider style
+- `suffixIcon` (icon): Icon to display after the slider
+- `tabIndex` (number): Tab index for keyboard navigation
+- `validateMessage` (string): Validation message
+- `validateStatus` (string): Validation status
+- `vertical` (boolean): Vertical orientation
+- `showDataLoadingIndicators` (boolean): Show loading indicators
+
+**Example Output:**
+```json
+{
+  "min": 0,
+  "max": 100,
+  "step": 1,
+  "value": 60,
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "showDataLoadingIndicators": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Use `min`, `max`, `step`, and `value` to define the basic behavior of the slider.
+> - Include a `label` to describe the purpose of the slider.
+> - Optionally use `vertical` for vertical orientation and `onEvent` for tracking value changes.
+> - `style` and `icon` fields can enhance the component’s visual customization.
+
+---
+
+#### 📍 Component: `splitLayout`
+
+**Required Fields:**
+- `columns` (array): Array of column definitions with properties such as `id`, `label`, `key`, `width`, `minWidth`, `maxWidth`, and `collapsible`
+- `containers` (object): Object mapping column indices to nested component containers
+- `orientation` (string): Layout orientation (`horizontal` or `vertical`)
+
+**Optional Fields:**
+- `animationStyle` (object): Animation style for transitions
+- `autoHeight` (string): Height behavior (`"auto"` or `"fixed"`)
+- `bodyStyle` (object): Style applied to the body container
+- `columnStyle` (object): Styling for individual columns
+- `disabled` (boolean): Disable interactions
+- `hidden` (boolean): Whether to hide the component
+- `horizontalGridCells` (number): Horizontal grid units (default: 24)
+- `verticalGridCells` (number): Vertical grid units (default: 24)
+- `mainScrollbar` (boolean): Enable scrollbar in the main container
+- `matchColumnsHeight` (boolean): Whether to equalize column heights
+- `showDataLoadingIndicators` (boolean): Toggle for loading placeholders
+
+**Example Output:**
+```json
+{
+  "columns": {
+    "manual": [
+      {
+        "id": 0,
+        "label": "Area 1",
+        "key": "Area1",
+        "minWidth": "10%",
+        "maxWidth": "90%",
+        "width": "50%",
+        "collapsible": false
+      },
+      {
+        "id": 1,
+        "label": "Area 2",
+        "key": "Area2",
+        "minWidth": "10%",
+        "maxWidth": "90%",
+        "width": "50%",
+        "collapsible": true
+      }
+    ]
+  },
+  "containers": {
+    "0": {},
+    "1": {}
+  },
+  "orientation": "horizontal",
+  "autoHeight": "auto",
+  "horizontalGridCells": 24,
+  "verticalGridCells": 24,
+  "matchColumnsHeight": true,
+  "mainScrollbar": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Define `columns` with layout info like width, `label`, `key`, and `collapsible`.
+> - Use `containers` to map nested components per area.
+> - Set `orientation` to control direction of split (`horizontal` or `vertical`).
+> - Optionally tweak `autoHeight`, `matchColumnsHeight`, and scrollbar settings for layout control.
+
+---
+
+#### 📍 Component: `step`
+
+**Required Fields:**
+- `options` (array): Step definitions including `label`, `value`, `status`, `description`, etc.
+- `direction` (string): Direction of the steps layout (`horizontal` or `vertical`)
+- `displayType` (string): Type of step rendering (`default`, `navigation`, or `inline`)
+
+**Optional Fields:**
+- `animationStyle` (object): Animation style
+- `autoHeight` (string): `"auto"` or `"fixed"` for height sizing
+- `disabled` (boolean): Disable step navigation
+- `initialValue` (number): Initial step index (1-based)
+- `labelPlacement` (string): Label position (`horizontal` or `vertical`)
+- `minHorizontalWidth` (number|string): Minimum width for horizontal layout
+- `onEvent` (eventHandler): Event callbacks (e.g., onChange)
+- `selectable` (boolean): Enable step selection by user
+- `showDots` (boolean): Show dots instead of titles
+- `showIcons` (boolean): Show icons in step headers
+- `showScrollBars` (boolean): Enable scrollbars when needed
+- `size` (string): Step size (`small`, `default`)
+- `stepPercent` (number): Percent complete
+- `stepStatus` (string): Current step status (`process`, `wait`, `finish`, `error`)
+- `style` (object): Custom style for step container
+- `value` (string): Current selected step value
+- `viewRef` (ref): Reference to the step component instance
+
+**Example Output:**
+```json
+{
+  "options": {
+    "optionType": "manual",
+    "manual": {
+      "manual": [
+        {
+          "value": "1",
+          "label": "Step 1",
+          "subTitle": "Initialization",
+          "description": "Initial setup of parameters.",
+          "icon": "/icon:solid/play",
+          "status": "finish",
+          "disabled": "false"
+        },
+        {
+          "value": "2",
+          "label": "Step 2",
+          "subTitle": "Execution",
+          "description": "Execution of the main process.",
+          "icon": "/icon:solid/person-running",
+          "status": "process",
+          "disabled": "false"
+        },
+        {
+          "value": "3",
+          "label": "Step 3",
+          "subTitle": "Finalization",
+          "description": "Final steps to complete the process.",
+          "icon": "/icon:solid/circle-check",
+          "status": "wait",
+          "disabled": "true"
+        },
+        {
+          "value": "4",
+          "label": "Step 4",
+          "subTitle": "Completion",
+          "description": "Process completed successfully.",
+          "status": "wait",
+          "disabled": "true"
+        }
+      ]
+    }
+  },
+  "direction": "horizontal",
+  "displayType": "default",
+  "size": "default",
+  "labelPlacement": "horizontal",
+  "showScrollBars": false,
+  "autoHeight": "auto"
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Provide a step flow using `options`, with labels, values, and icons.
+> - Set `direction` and `displayType` based on layout.
+> - Optionally define `initialValue`, `stepStatus`, `stepPercent`, and icons per step.
+> - For vertical or inline layouts, adjust `labelPlacement` and `minHorizontalWidth` as needed.
+
+---
+
+#### 📍 Component: `switch`
+
+**Required Fields:**
+- `label` (object): Includes `text`, `width`, `widthUnit`, and `position`.
+- `value` (boolean): Current value of the switch
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required
+- `defaultValue` (boolean): Initial state of the switch
+- `animationStyle` (object): Animation style
+- `disabled` (boolean): Disable switch interaction
+- `formDataKey` (string): Key used to bind this field to form data
+- `hidden` (boolean): If true, the switch will be hidden
+- `inputFieldStyle` (object): Custom styling for switch input/handle
+- `labelStyle` (object): Custom style for label
+- `onEvent` (eventHandler): Event handlers such as `change`, `open`, `close`
+- `style` (object): Style object for the switch
+- `tabIndex` (number): Index for keyboard navigation
+- `validateMessage` (string): Message displayed for validation errors
+- `validateStatus` (string): Validation status (`error`, `warning`, etc.)
+- `viewRef` (ref): Component reference for programmatic access
+
+**Example Output:**
+```json
+{
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "value": "",
+  "defaultValue": "",
+  "required": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Use `label` for visible switch text and layout.
+> - Set `value` to `true` or `false` depending on switch state.
+> - Add `defaultValue` for initial toggle state, and `onEvent` to respond to user actions.
+> - Use `style` and `inputFieldStyle` for visual customization.
+
+---
+
+#### 📍 Component: `tabbedContainer`
+
+**Required Fields:**
+- `tabs` (array): Tab definitions including at least `label` and `key`
+- `containers` (object): Mapping of tab index to content containers
+- `selectedTabKey` (string): Currently selected tab key
+
+**Optional Fields:**
+- `animationStyle` (object): Animation style for tab transitions
+- `autoHeight` (string): Whether the component adjusts height automatically (`"auto"` or fixed)
+- `bodyStyle` (object): Style for the tab body container
+- `destroyInactiveTab` (boolean): Whether to destroy tab content on hide
+- `disabled` (boolean): Disable the entire tabbed container
+- `headerStyle` (object): Style for the tab headers
+- `hidden` (boolean): If true, hides the entire component
+- `horizontalGridCells` (number): Grid cell width allocation (e.g. 24 for full-width)
+- `onEvent` (eventHandler): Event handlers (e.g., tab change)
+- `placement` (string): Position of the tab bar (`top`, `bottom`, `left`, `right`)
+- `scrollbars` (boolean): Show horizontal/vertical scrollbars
+- `showHeader` (boolean): Toggle visibility of the tab bar/header
+- `showVerticalScrollbar` (boolean): Toggle vertical scroll
+- `style` (object): Custom style for the container
+- `tabsCentered` (boolean): Center align the tabs
+- `tabsGutter` (number): Spacing (in pixels) between tabs
+
+**Example Output:**
+```json
+{
+  "tabs": {
+    "manual": [
+      {
+        "id": 0,
+        "label": "Tab1",
+        "key": "Tab1",
+        "iconPosition": "left"
+      },
+      {
+        "id": 1,
+        "label": "Tab2",
+        "key": "Tab2",
+        "iconPosition": "left"
+      }
+    ]
+  },
+  "selectedTabKey": "Tab1",
+  "containers": {
+    "0": {},
+    "1": {}
+  },
+  "autoHeight": "auto",
+  "horizontalGridCells": 24,
+  "placement": "top",
+  "tabsGutter": 32,
+  "showHeader": true,
+  "scrollbars": false,
+  "showVerticalScrollbar": false,
+  "destroyInactiveTab": false,
+  "tabsCentered": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define `tabs` with `label` and `key`, and use matching indices in `containers`.
+> - Set `selectedTabKey` to control the default tab shown.
+> - Customize layout with `placement`, `tabsGutter`, and `tabsCentered`.
+> - Use `onEvent` for handling tab switching behaviors.
+
+---
+
+#### 📍 Component: `table`
+
+**Required Fields:**
+- `columns` (array): Defines column configurations, including `title`, `dataIndex`, `render`, and layout/style attributes.
+- `data` (array): The dataset to be displayed in the table.
+
+**Optional Fields:**
+- `autoHeight` (string): `"auto"` or `"fixed"` to control component height behavior.
+- `columnsStyle` (object): Style applied to individual columns.
+- `dataRowExample` (object): Sample data row to help auto-generate columns.
+- `dynamicColumn` (boolean): Enable dynamic columns generation.
+- `dynamicColumnConfig` (array): Configuration for dynamic column mapping.
+- `expansion` (object): Row expansion configuration with optional nested components.
+- `fixedHeader` (boolean): Whether the header is fixed during scroll.
+- `headerStyle` (object): Style for the header row.
+- `hideHeader` (boolean): Hide the header row.
+- `hideToolbar` (boolean): Hide the built-in toolbar.
+- `inlineAddNewRow` (boolean): Enable adding new rows inline.
+- `loading` (boolean): Set loading state on the table.
+- `newData` (array): Additional data rows to append.
+- `onEvent` (eventHandler): Table event handling (row click, pagination, etc.).
+- `pagination` (object): Pagination configuration (page size, page number, etc.).
+- `rowAutoHeight` (boolean|string): Auto-size each row’s height or define a fixed one.
+- `rowColor` (object): Row background color rules.
+- `rowHeight` (object): Row height configuration.
+- `rowStyle` (object): Custom style per row.
+- `searchText` (string): Search string for filtering table content.
+- `selectedCell` (object): Currently selected cell configuration.
+- `selection` (object): Row selection options, e.g., `{ "mode": "single" }`.
+- `showHRowGridBorder` (boolean): Show horizontal row grid borders.
+- `showHeaderGridBorder` (boolean): Show borders in the header.
+- `showHorizontalScrollbar` (boolean): Show horizontal scroll when needed.
+- `showRowGridBorder` (boolean): Show full row grid borders.
+- `showSummary` (boolean): Whether to show a summary/footer row.
+- `showVerticalScrollbar` (boolean): Show vertical scrollbar.
+- `sort` (array): Sorting configuration per column.
+- `style` (object): Custom table style.
+- `summaryRowStyle` (object): Style for summary row.
+- `tableAutoHeight` (boolean|string): Automatically adjust table height.
+- `toolbar` (object): Toolbar configuration (download, refresh, filters).
+- `toolbarStyle` (object): Style for the toolbar.
+- `viewModeResizable` (boolean): Allow view resizing in preview mode.
+- `visibleResizables` (boolean): Enable resizable column handles.
+
+**Example Output:**
+```json
+{
+  "columns": [
+    {
+      "title": "Name",
+      "dataIndex": "name",
+      "render": {
+        "compType": "text",
+        "comp": { "text": "{{'{{'}}{{'currentCell'}}{{'\}}'}}" }
+      }
+    }
+  ],
+  "data": [
+    { "name": "John Doe" },
+    { "name": "Jane Smith" }
+  ],
+  "pagination": {
+    "pageSizeOptions": "[5, 10, 20, 50]"
+  },
+  "selection": {
+    "mode": "single"
+  },
+  "toolbar": {
+    "showRefresh": true,
+    "showDownload": true,
+    "showFilter": true,
+    "position": "below"
+  },
+  "showRowGridBorder": true,
+  "showHRowGridBorder": true,
+  "autoHeight": "auto"
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define `columns` and `data` to render a meaningful table.
+> - Use `render` in columns to control component type (e.g., text, tag, button).
+> - For enhanced UX, configure `pagination`, `selection`, and `toolbar`.
+> - `expansion` allows you to embed nested components within each row.
+
+---
+
+#### 📍 Component: `text`
+
+**Required Fields:**
+- `text` (string): The textual content to display. Markdown or plain text is supported.
+
+**Optional Fields:**
+- `animationStyle` (object): CSS animation style object.
+- `autoHeight` (string): Use `"auto"` or `"fixed"` to determine height behavior.
+- `contentScrollBar` (boolean): Whether to show a scrollbar when content overflows.
+- `horizontalAlignment` (string): Horizontal alignment of text (`left`, `center`, `right`).
+- `verticalAlignment` (string): Vertical alignment of text (`top`, `center`, `bottom`).
+- `onEvent` (eventHandler): Event handling configuration.
+- `style` (object): CSS style object.
+- `type` (string): Type of text rendering. Accepts `"markdown"` or `"text"` (default is `"text"`).
+
+**Example Output:**
+```json
+{
+  "text": "### 👋 Hello, {{'{{'}}{{'currentUser.name'}}{{'\}}'}}",
+  "autoHeight": "auto",
+  "type": "markdown",
+  "horizontalAlignment": "left",
+  "verticalAlignment": "center",
+  "contentScrollBar": true
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define a `text` field with valid Markdown or plain text.
+> - Use `"type": "markdown"` for formatted content and headings.
+> - Configure alignment and `autoHeight` for layout control.
+> - `contentScrollBar` is useful for large text blocks.
+
+---
+
+#### 📍 Component: `textArea`
+
+**Required Fields:**
+- `label` (object): Input label configuration (e.g., text, width, alignment).
+- `value` (string): The current text area value.
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required for form validation.
+- `allowClear` (boolean): Allow clearing the input.
+- `animationStyle` (object): Animation style object.
+- `autoHeight` (string): Use `"auto"` or `"fixed"` for dynamic or fixed height.
+- `customRule` (string): Custom validation rule.
+- `defaultValue` (string): Initial value of the text area.
+- `disabled` (boolean): Disable the input field.
+- `formDataKey` (string): Key to map form submission data.
+- `inputFieldStyle` (object): Input field style.
+- `labelStyle` (object): Style applied to the label.
+- `maxLength` (number): Maximum number of characters.
+- `minLength` (number): Minimum number of characters.
+- `onEvent` (eventHandler): Event handlers (e.g., onChange).
+- `placeholder` (string): Placeholder text.
+- `prefixIcon` (icon): Icon displayed before the input field.
+- `readOnly` (boolean): Whether the field is read-only.
+- `regex` (string): Regex-based validation rule.
+- `showCount` (boolean): Show character count.
+- `showValidationWhenEmpty` (boolean): Show validation even when empty.
+- `style` (object): Overall component style.
+- `suffixIcon` (icon): Icon displayed after the input field.
+- `tabIndex` (number): Tab index for keyboard navigation.
+- `textAreaScrollBar` (boolean): Show scrollbar for overflowing text.
+- `viewRef` (ref): Reference for DOM access.
+
+**Example Output:**
+```json
+{
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "value": "",
+  "defaultValue": "",
+  "autoHeight": "fixed",
+  "textAreaScrollBar": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Ensure to include both `label` and `value` fields.
+> - Set `autoHeight` as `"fixed"` or `"auto"` based on layout needs.
+> - Use `textAreaScrollBar: true` when overflow behavior is required.
+> - Ideal for long-form user input or notes fields.
+
+---
+
+#### 📍 Component: `time`
+
+**Required Fields:**
+- `label` (object): Input label configuration (text, alignment, width, etc.)
+- `value` (string): The current time value
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required for validation
+- `animationStyle` (object): Animation style
+- `childrenInputFieldStyle` (object): Style for child inputs
+- `customRule` (string): Custom validation logic
+- `defaultValue` (string): Default time value
+- `disabled` (boolean): Disable the input field
+- `formDataKey` (string): Form data key for submission mapping
+- `format` (string): Display format for time
+- `hourStep` (number): Step size for hours
+- `inputFieldStyle` (object): Input field styling
+- `inputFormat` (string): Input parsing format (e.g., `"HH:mm:ss"`)
+- `labelStyle` (object): Style for label text
+- `maxDate` (string): Max date constraint
+- `maxTime` (string): Max time constraint
+- `minDate` (string): Min date constraint
+- `minTime` (string): Min time constraint
+- `minuteStep` (number): Step size for minutes
+- `onEvent` (eventHandler): Event handlers (e.g., onChange)
+- `placeholder` (string): Placeholder text
+- `secondStep` (number): Step size for seconds
+- `showTime` (boolean): Show time selector
+- `showValidationWhenEmpty` (boolean): Show validation message when empty
+- `style` (object): Overall component styling
+- `suffixIcon` (icon): Icon displayed at the end of the input
+- `tabIndex` (number): Tab index for navigation
+- `use12Hours` (boolean): Use 12-hour format (AM/PM)
+- `userTimeZone` (string): Time zone of the user
+- `viewRef` (ref): Reference to the time picker
+
+**Example Output:**
+```json
+{
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "value": "",
+  "defaultValue": "",
+  "placeholder": "Select Time",
+  "inputFormat": "HH:mm:ss",
+  "suffixIcon": "/icon:regular/clock",
+  "userTimeZone": "Asia/Karachi"
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include `label` and `value` in the component.
+> - Use `inputFormat` and `userTimeZone` for proper localization.
+> - Ideal for time input fields with precise control like scheduling or logs.
+
+---
+
+#### 📍 Component: `timeRange`
+
+**Required Fields:**
+- `label` (object): Input label configuration (text, alignment, width, etc.)
+- `start` (string): Start time value
+- `end` (string): End time value
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required
+- `defaultStart` (string): Default start time
+- `defaultEnd` (string): Default end time
+- `animationStyle` (object): Animation styling
+- `childrenInputFieldStyle` (object): Style for nested input fields
+- `customRule` (string): Custom validation rule
+- `disabled` (boolean): Whether the field is disabled
+- `formDataKey` (string): Form data key
+- `format` (string): Display format (e.g., "HH:mm:ss")
+- `hourStep` (number): Hour increment step
+- `inputFieldStyle` (object): Style of the input field
+- `inputFormat` (string): Input parsing format (e.g., "HH:mm:ss")
+- `labelStyle` (object): Style object for the label
+- `maxDate` (string): Maximum allowed date
+- `maxTime` (string): Maximum allowed time
+- `minDate` (string): Minimum allowed date
+- `minTime` (string): Minimum allowed time
+- `minuteStep` (number): Minute increment step
+- `onEvent` (eventHandler): Event handlers (e.g., onChange)
+- `placeholder` (string): Placeholder for the input
+- `secondStep` (number): Second increment step
+- `showTime` (boolean): Whether to show time picker
+- `showValidationWhenEmpty` (boolean): Show validation even when empty
+- `style` (object): Custom styling for the component
+- `suffixIcon` (icon): Icon to show at the end of the input
+- `tabIndex` (number): Keyboard tab index
+- `use12Hours` (boolean): Use 12-hour format instead of 24-hour
+- `userRangeTimeZone` (string): Time zone for both start and end values
+- `viewRef` (ref): Reference to the component
+
+**Example Output:**
+```json
+{
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "start": "",
+  "end": "",
+  "defaultStart": "",
+  "defaultEnd": "",
+  "placeholder": "Select Time",
+  "inputFormat": "HH:mm:ss",
+  "suffixIcon": "/icon:regular/clock",
+  "userRangeTimeZone": "Asia/Karachi"
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include `label`, `start`, and `end` fields.
+> - Prefer using `inputFormat` and `userRangeTimeZone` for accurate formatting and zone handling.
+> - Best used where both start and end times must be collected, like booking slots or logs.
+
+---
+
+#### 📍 Component: `timeline`
+
+**Required Fields:**
+- `value` (array): Timeline data array, each object can include:
+  - `title` (string): Main event title
+  - `subTitle` (string): Optional subtitle
+  - `label` (string): Date or label text
+  - `dot` (string): Optional icon for the timeline point
+  - `color` (string): Color of the timeline point
+  - `titleColor`, `subTitleColor`, `labelColor` (string): Optional text color customization for each field
+
+**Optional Fields:**
+- `autoHeight` (string): `"auto"` or `"fixed"` height behavior
+- `clickedIndex` (number): Index of the last clicked timeline item
+- `clickedObject` (object): Object representing the last clicked timeline item
+- `mode` (string): Layout mode — `left`, `right`, or `alternate`
+- `onEvent` (eventHandler): Event handlers (e.g., onClick)
+- `pending` (string): Pending label shown at the end of the timeline
+- `reverse` (boolean): Display the timeline in reverse order
+- `style` (object): Style configuration
+- `verticalScrollbar` (boolean): Show vertical scrollbar
+
+**Example Output:**
+```json
+{
+  "value": [
+    {
+      "title": "Majiang Releases",
+      "subTitle": "Majiang Published in China",
+      "label": "2022-6-10"
+    },
+    {
+      "title": "Openblocks public release",
+      "subTitle": "Openblocks open source in GitHub",
+      "label": "2022-11-28"
+    },
+    {
+      "title": "Last code submission",
+      "subTitle": "Openblocks project abandoned",
+      "dot": "ExclamationCircleOutlined",
+      "label": "2023-3-28",
+      "color": "red",
+      "titleColor": "red",
+      "subTitleColor": "red",
+      "labelColor": "red"
+    },
+    {
+      "title": "Lowcoder 2.0",
+      "subTitle": "Lowcoder, keep moving forward",
+      "dot": "LogoutOutlined",
+      "color": "green",
+      "label": "2023-6-20"
+    }
+  ],
+  "mode": "alternate",
+  "autoHeight": "auto",
+  "verticalScrollbar": false,
+  "pending": "Continuous Improvement",
+  "clickedObject": {
+    "title": ""
+  },
+  "clickedIndex": 0
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include the `value` field with at least one timeline item.
+> - Use `mode: alternate` for a balanced layout.
+> - Include `pending` to indicate ongoing progress when applicable.
+
+---
+
+#### 📍 Component: `timer`
+
+**Required Fields:**
+- `defaultValue` (string): Initial timer value in `HH:MM:SS:MS` format, e.g. `"00:00:00:000"`
+- `timerType` (string): Type of timer; allowed values:
+  - `"timer"` – counts up from the `defaultValue`
+  - `"countdown"` – counts down from the `defaultValue`
+
+**Optional Fields:**
+- `actionHandler` (string): Programmatic control (`start`, `pause`, `resume`, `reset`)
+- `animationStyle` (object): Animation style for the timer display
+- `elapsedTime` (number): Read-only field representing elapsed time in milliseconds
+- `hideButton` (boolean): Whether to hide control buttons
+- `onEvent` (eventHandler): Handles timer events like `start`, `pause`, `reset`, `resume`, `countdownEnd`
+- `resetButtonStyle` (object): Style for the reset button
+- `startButtonStyle` (object): Style for the start button
+- `style` (object): Timer container style
+
+**Example Output:**
+```json
+{
+  "defaultValue": "00:00:00:000",
+  "timerType": "timer",
+  "actionHandler": "start",
+  "animationStyle": {},
+  "elapsedTime": 12456,
+  "hideButton": false,
+  "onEvent": {},
+  "resetButtonStyle": {},
+  "startButtonStyle": {},
+  "style": {}
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+- Ensure both `defaultValue` and `timerType` are specified. Use `"timer"` for stopwatch behavior and `"countdown"` for reverse counting.
+
+---
+
+#### 📍 Component: `toggleButton`
+
+**Required Fields:**
+- `value` (boolean|string): Toggle state — must be provided to bind or initialize button state
+- `trueText` (string): Text label shown when toggled on
+- `falseText` (string): Text label shown when toggled off
+- `trueIcon` (string): Icon shown when toggled on
+- `falseIcon` (string): Icon shown when toggled off
+
+**Optional Fields:**
+- `animationStyle` (object): CSS animation style object
+- `disabled` (boolean): Disable the button
+- `loading` (boolean): Show loading spinner
+- `onEvent` (eventHandler): Event handler for value changes
+- `showBorder` (boolean): Display border around the button
+- `showText` (boolean): Show/hide text alongside icons
+- `tooltip` (string): Tooltip text on hover
+- `iconPosition` (string): Position of the icon (`"left"` or `"right"`)
+- `alignment` (string): Button alignment (`"start"`, `"center"`, `"end"`, `"stretch"`)
+- `style` (object): Custom style for the button
+- `viewRef` (ref): Reference to the button element
+
+**Example Output:**
+```json
+{
+  "value": true,
+  "trueText": "Hide",
+  "falseText": "Show",
+  "trueIcon": "/icon:solid/AngleUp",
+  "falseIcon": "/icon:solid/AngleDown",
+  "showText": true,
+  "showBorder": true,
+  "iconPosition": "right",
+  "alignment": "stretch"
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+- Ensure the toggle behavior includes: `value`, `trueText`, `falseText`, `trueIcon`, and `falseIcon`.
+- Use `showText` and `showBorder` for user clarity.
+
+---
+
+#### 📍 Component: `tour`
+
+**Required Fields:**
+- `options` (array): Array of tour step definitions, including at least a `title` and `description` for each step
+
+**Optional Fields:**
+- `arrow` (boolean): Whether to show an arrow pointing to the target
+- `defaultValue` (string): Default step or initial tour state
+- `disabledInteraction` (boolean): Disable user interaction during the tour
+- `mask` (boolean): Display a mask overlay behind the tour
+- `open` (boolean): Whether the tour is currently active (can be bound to state)
+- `placement` (string): Default placement of the tour popup (e.g., `top`, `bottom`, `left`, `right`)
+- `type` (string): Type of tour step display (e.g., `default`, `primary`)
+- `value` (string): Currently active tour step (can be bound)
+
+**Example Output:**
+```json
+{
+  "open": true,
+  "options": [
+    {
+      "target": "",
+      "title": "Welcome",
+      "description": "Welcome to lowcoder",
+      "placement": "",
+      "type": ""
+    },
+    {
+      "target": "",
+      "title": "Step 2",
+      "description": "This is a tutorial step",
+      "placement": "",
+      "type": ""
+    }
+  ],
+  "placement": "bottom",
+  "type": "default",
+  "defaultValue": "",
+  "value": ""
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+- Always include `options` with a list of steps, where each step has at least a `title` and `description`.
+- Use `placement` and `type` for consistent tour presentation.
+
+---
+
+#### 📍 Component: `transfer`
+
+**Required Fields:**
+- `items` (array): List of items to display in the transfer component, each with a unique `key` and a `title`
+- `targetKeys` (array): List of keys representing items currently in the target list
+
+**Optional Fields:**
+- `onEvent` (eventHandler): Event handlers (e.g., change, search, selectedChange)
+- `oneWay` (boolean): Enable one-way transfer (no target-to-source movement)
+- `pageSize` (number): Number of items per page
+- `pagination` (boolean): Enable pagination
+- `searchInfo` (array): Array with search state for both lists
+- `selectedKeys` (array): Keys of currently selected items in each list
+- `showSearch` (boolean): Enable search input in source/target lists
+- `sourceTitle` (string): Title for the source list
+- `targetTitle` (string): Title for the target list
+- `targerObject` (array): Full item data for `targetKeys` (useful for pre-populated target)
+- `style` (object): Style configuration for the transfer component
+
+**Example Output:**
+```json
+{
+  "items": [
+    { "key": "1", "title": "Content 1" },
+    { "key": "2", "title": "Content 2" },
+    { "key": "3", "title": "Content 3" }
+  ],
+  "targetKeys": [],
+  "selectedKeys": [[], []],
+  "searchInfo": ["", ""],
+  "sourceTitle": "Source Data",
+  "targetTitle": "Target Data",
+  "showSearch": true,
+  "pageSize": 10,
+  "targerObject": []
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include `items` and `targetKeys` to define the data and its distribution.
+> - Use `sourceTitle`, `targetTitle`, and `showSearch` to enhance usability.
+
+---
+
+#### 📍 Component: `tree`
+
+**Required Fields:**
+- `treeData` (array): Hierarchical tree structure with nodes and optional nested children
+- `value` (array|string): Selected value(s)
+- `selectType` (string): Type of selection allowed — options include `none`, `single`, `multi`, `check`
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required
+- `defaultValue` (array|string): Default selected value(s)
+- `expanded` (array): Keys of expanded nodes
+- `autoExpandParent` (boolean): Automatically expand parent nodes of expanded keys
+- `defaultExpandAll` (boolean): Expand all nodes by default
+- `checkStrictly` (boolean): Enforce strict check behavior (no parent-child relationship)
+- `formDataKey` (string): Form data key for form integrations
+- `inputFieldStyle` (object): Input field style configuration
+- `label` (string|object): Label text or label config object
+- `labelStyle` (object): Style for the label
+- `onEvent` (eventHandler): Event handler for tree interactions
+- `showLeafIcon` (boolean): Whether to show icons for leaf nodes
+- `showLine` (boolean): Whether to show connector lines between tree nodes
+- `style` (object): Tree component container style
+- `validateMessage` (string): Custom validation message
+- `validateStatus` (string): Validation status (`error`, `warning`, `success`)
+- `autoHeight` (string): Use `"auto"` or `fixed` height behavior
+- `verticalScrollbar` (boolean): Show vertical scrollbar
+
+**Example Output:**
+```json
+{
+  "treeData": [
+    {
+      "label": "Asia",
+      "value": "asia",
+      "children": [
+        {
+          "label": "China",
+          "value": "china",
+          "children": [
+            { "label": "Beijing", "value": "beijing" },
+            { "label": "Shanghai", "value": "shanghai" }
+          ]
+        },
+        { "label": "Japan", "value": "japan" }
+      ]
+    },
+    {
+      "label": "Europe",
+      "value": "europe",
+      "disabled": true,
+      "children": [
+        { "label": "England", "value": "england" },
+        { "label": "France", "value": "france", "checkable": false },
+        { "label": "Germany", "value": "germany", "disableCheckbox": true }
+      ]
+    },
+    {
+      "label": "North America",
+      "value": "northAmerica"
+    }
+  ],
+  "value": [],
+  "selectType": "single",
+  "expanded": [],
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "column",
+    "align": "left"
+  },
+  "autoHeight": "auto",
+  "verticalScrollbar": false
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always define `treeData`, `value`, and `selectType`.
+> - Use `expanded`, `label`, and `autoHeight` for display control.
+> - For nested tree structures, ensure each node uses `label` and `value`.
+
+---
+
+#### 📍 Component: `treeSelect`
+
+**Required Fields:**
+- `treeData` (array): Hierarchical options for selection, typically containing `label`, `value`, and optionally `children`
+- `value` (array|string): Current selected value(s)
+- `selectType` (string): Selection type (`single`, `multi`, or `check`)
+- `checkedStrategy` (string): Strategy for displaying selected items (`all`, `parent`, or `child`)
+
+**Optional Fields:**
+- `required` (boolean): Whether the field is required
+- `defaultValue` (array|string): Initial selection value(s)
+- `expanded` (array): Keys of initially expanded nodes
+- `label` (string|object): Input label or label config object
+- `labelStyle` (object): Label style
+- `placeholder` (string): Placeholder text when nothing is selected
+- `showSearch` (boolean): Enable search box within the tree
+- `showLeafIcon` (boolean): Show icons for leaf nodes
+- `showLine` (boolean): Show lines between tree nodes
+- `defaultExpandAll` (boolean): Expand all nodes by default
+- `formDataKey` (string): Key for form binding
+- `inputFieldStyle` (object): Style for the input field
+- `inputValue` (string): Current search input value
+- `onEvent` (eventHandler): Event handler for interactions
+- `allowClear` (boolean): Show clear button to reset selection
+- `style` (object): Style of the select input
+- `validateMessage` (string): Validation error message
+- `validateStatus` (string): Validation status (e.g., `error`, `success`)
+- `viewRef` (ref): Reference to the component instance
+
+**Example Output:**
+```json
+{
+  "treeData": [
+    {
+      "label": "Asia",
+      "value": "asia",
+      "children": [
+        {
+          "label": "China",
+          "value": "china",
+          "children": [
+            { "label": "Beijing", "value": "beijing" },
+            { "label": "Shanghai", "value": "shanghai" }
+          ]
+        },
+        { "label": "Japan", "value": "japan" }
+      ]
+    },
+    {
+      "label": "Europe",
+      "value": "europe",
+      "disabled": true,
+      "children": [
+        { "label": "England", "value": "england" },
+        { "label": "France", "value": "france", "checkable": false },
+        { "label": "Germany", "value": "germany", "disableCheckbox": true }
+      ]
+    },
+    {
+      "label": "North America",
+      "value": "northAmerica"
+    }
+  ],
+  "value": [],
+  "selectType": "single",
+  "checkedStrategy": "parent",
+  "label": {
+    "text": "Label",
+    "width": "33",
+    "widthUnit": "%",
+    "position": "row",
+    "align": "left"
+  },
+  "placeholder": "Please Select",
+  "showSearch": true,
+  "expanded": []
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always specify `treeData`, `value`, `selectType`, and `checkedStrategy`.
+> - Use `label`, `placeholder`, and `showSearch` to configure appearance.
+> - Ensure tree node structure follows correct `label`/`value` format and supports nested children.
+
+---
+
+#### 📍 Component: `upload`
+
+**Required Fields:**
+- `uploadType` (string): Upload mode (`single` or `multiple`)
+- `text` (string): Upload button text (e.g., `"Browse"`)
+
+**Optional Fields:**
+- `animationStyle` (object): Animation style
+- `disabled` (boolean): Disabled state
+- `fileType` (array): Allowed file types (e.g., `[".jpg", ".png"]`)
+- `maxFiles` (number): Maximum number of files
+- `maxSize` (number|string): Maximum file size in bytes or string format (e.g., `"5MB"`)
+- `minSize` (number|string): Minimum file size in bytes or string format
+- `onEvent` (eventHandler): Event handlers for actions like upload, remove, error
+- `prefixIcon` (icon): Icon to show before button label
+- `showUploadList` (boolean): Whether to display the list of uploaded files
+- `style` (object): Custom style for the upload container
+- `suffixIcon` (icon): Icon to show after button label
+- `value` (array): Uploaded file objects
+
+**Example Output:**
+```json
+{
+  "uploadType": "single",
+  "text": "Browse",
+  "showUploadList": true,
+  "prefixIcon": "/icon:solid/arrow-up-from-bracket"
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include `uploadType` and `text`.
+> - Add `showUploadList` and `prefixIcon` to enhance display.
+> - Optionally, specify `fileType`, `maxFiles`, or `maxSize` for validation.
+> - Use `onEvent` if upload status tracking is required.
+
+---
+
+#### 📍 Component: `video`
+
+**Required Fields:**
+- `src` (string): Video source URL (can be a direct file link or a video platform URL)
+
+**Optional Fields:**
+- `autoPlay` (boolean): Autoplay the video when loaded
+- `controls` (boolean): Display video player controls
+- `loop` (boolean): Replay the video when it ends
+- `poster` (string): Poster image to show before the video plays
+- `currentTimeStamp` (string|number): Starting timestamp for the video (in seconds or timecode)
+- `duration` (string|number): Video duration (used for tracking or display)
+- `style` (object): CSS style for video container
+
+**Example Output:**
+```json
+{
+  "src": "https://www.youtube.com/watch?v=pRpeEdMmmQ0",
+  "poster": "",
+  "currentTimeStamp": "0",
+  "duration": ""
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include a valid `src` URL for the video.
+> - Add `poster`, `currentTimeStamp`, or `duration` when precise playback control or a visual placeholder is needed.
+> - Set `autoPlay`, `loop`, or `controls` depending on interaction requirements.
+
+---
+
+**Example Output:**
+```json
+{
+  "src": "https://www.youtube.com/watch?v=pRpeEdMmmQ0",
+  "poster": "",
+  "currentTimeStamp": "0",
+  "duration": ""
+}
+```
+
+##### 🧠 Prompt Guidance for AI Agent
+> - Always include a valid `src` URL for the video.
+> - Add `poster`, `currentTimeStamp`, or `duration` when precise playback control or a visual placeholder is needed.
+> - Set `autoPlay`, `loop`, or `controls` depending on interaction requirements.
+
+---
+
+### ✅ Example Behavior:
+
+* For **specific queries**, determine the component and use the corresponding inline required fields.
+* For **generic queries**, choose a suitable component first, then apply the valid minimal properties inline.
+* **Do not hallucinate additional properties** beyond these required fields unless specifically requested by the user.
+
+---
+
+## ✅ JSON Output Format Rules
+
+* The AI must return one complete JSON object.
+* Fields:
+
+  * `explanation`: Summary of app purpose and main sections. Do not list every component.
+  * `actions`: Array of all valid UI actions.
+* Return format: raw JSON, no markdown.
+
+
+## ✅ Example JSON Response Format
+
+```json
+{
+  "explanation": "Created a complete Todo App with title, search bar, filter dropdown, add task modal, and a task list with edit and delete actions.",
+  "actions": [
+    {
+      "action": "place_component",
+      "component": "text",
+      "component_name": "todoAppTitle",
+      "layout": { "x": 0, "y": 0, "w": 12, "h": 4 },
+      "action_parameters": {
+        "text": "## Todo App",
+        "type": "markdown"
+      }
+    },
+    {
+      "action": "place_component",
+      "component": "input",
+      "component_name": "taskSearch",
+      "layout": { "x": 0, "y": 4, "w": 8, "h": 6 },
+      "action_parameters": {
+        "placeholder": "Search tasks...",
+        "allowClear": true
+      }
+    },
+    {
+      "action": "place_component",
+      "component": "dropdown",
+      "component_name": "taskStatusFilter",
+      "layout": { "x": 8, "y": 4, "w": 8, "h": 6 },
+      "action_parameters": {
+        "label": { "text": "Filter by Status" },
+        "options": {
+          "optionType": "manual",
+          "manual": {
+            "manual": [
+              { "value": "all", "label": "All" },
+              { "value": "pending", "label": "Pending" },
+              { "value": "done", "label": "Done" },
+              { "value": "in_progress", "label": "In Progress" }
+            ]
+          }
+        },
+        "value": "all"
+      }
+    },
+    {
+      "action": "place_component",
+      "component": "button",
+      "component_name": "addTaskButton",
+      "layout": { "x": 0, "y": 10, "w": 12, "h": 6 },
+      "action_parameters": {
+        "text": "Add New Task",
+        "type": "primary"
+      }
+    },
+    {
+      "action": "place_component",
+      "component": "modal",
+      "component_name": "addTaskModal",
+      "layout": { "x": 0, "y": 0, "w": 12, "h": 40 },
+      "action_parameters": {
+        "title": "Add New Task",
+        "open": false,
+        "container": {}
+      }
+    },
+    {
+      "action": "nest_component",
+      "component": "form",
+      "component_name": "addTaskForm",
+      "parent_component_name": "addTaskModal.container",
+      "layout": { "x": 0, "y": 0, "w": 12, "h": 30 },
+      "action_parameters": {
+        "container": {
+          "header": {},
+          "body": { "0": { "view": {} } },
+          "footer": {},
+          "showHeader": false,
+          "showBody": true,
+          "showFooter": true,
+          "autoHeight": "auto",
+          "horizontalGridCells": 24,
+          "scrollbars": false,
+          "showVerticalScrollbar": false,
+          "style": {}
+        }
+      }
+    },
+    {
+      "action": "nest_component",
+      "component": "input",
+      "component_name": "taskTitleInput",
+      "parent_component_name": "addTaskForm.container.body.0.view",
+      "layout": { "x": 0, "y": 0, "w": 24, "h": 6 },
+      "action_parameters": {
+        "label": {
+          "text": "Task Title",
+          "width": "30",
+          "widthUnit": "%",
+          "position": "row",
+          "align": "left"
+        },
+        "value": "",
+        "validationType": "Text",
+        "required": true,
+        "placeholder": "Enter task title",
+        "allowClear": true
+      }
+    },
+    {
+      "action": "nest_component",
+      "component": "select",
+      "component_name": "taskStatusSelect",
+      "parent_component_name": "addTaskForm.container.body.0.view",
+      "layout": { "x": 0, "y": 6, "w": 24, "h": 6 },
+      "action_parameters": {
+        "label": {
+          "text": "Status",
+          "width": "30",
+          "widthUnit": "%",
+          "position": "row",
+          "align": "left"
+        },
+        "options": {
+          "optionType": "manual",
+          "manual": {
+            "manual": [
+              { "value": "pending", "label": "Pending" },
+              { "value": "done", "label": "Done" },
+              { "value": "in_progress", "label": "In Progress" }
+            ]
+          },
+          "mapData": { "data": "[]" }
+        },
+        "value": "pending",
+        "allowClear": false
+      }
+    },
+    {
+      "action": "nest_component",
+      "component": "button",
+      "component_name": "submitAddTask",
+      "parent_component_name": "addTaskForm.container.footer",
+      "layout": { "x": 0, "y": 0, "w": 24, "h": 6 },
+      "action_parameters": {
+        "text": "Add Task",
+        "type": "submit",
+        "form": "addTaskForm",
+        "loading": "false",
+        "disabled": "false"
+      }
+    },
+    {
+      "action": "place_component",
+      "component": "table",
+      "component_name": "todoTable",
+      "layout": { "x": 0, "y": 16, "w": 12, "h": 30 },
+      "action_parameters": {
+        "columns": [
+          {
+            "title": "Task",
+            "dataIndex": "task",
+            "render": { "compType": "text", "comp": { "text": "{{currentCell}}" } }
+          },
+          {
+            "title": "Status",
+            "dataIndex": "status",
+            "render": { "compType": "text", "comp": { "text": "{{currentCell}}" } }
+          },
+          {
+            "title": "Actions",
+            "dataIndex": "actions",
+            "render": {
+              "compType": "button",
+              "comp": { "text": "Edit" }
+            }
+          },
+          {
+            "title": "Delete",
+            "dataIndex": "delete",
+            "render": {
+              "compType": "button",
+              "comp": { "text": "Delete" }
+            }
+          }
+        ],
+        "data": "[{\"task\":\"Buy groceries\",\"status\":\"Pending\"},{\"task\":\"Call Alice\",\"status\":\"Done\"},{\"task\":\"Clean room\",\"status\":\"In Progress\"}]",
+        "pagination": { "pageSizeOptions": "[5, 10, 20, 50]" },
+        "showRowGridBorder": true
+      }
+    }
+  ]
+}
+```
+
+---
+
+## ❗ Troubleshooting Guidelines
+
+* For queries like "create todo app" or other known app patterns, the intent is understood, but specific feature details may be missing. In such cases, respond with a bullet-point summary of the intended app structure and ask the user to confirm or customize features. Do not return `actions` until the user approves.
+
+* Always return a preview in the `explanation` field in bullet-point format, and set `actions` to an empty array unless the user explicitly requests execution (e.g., 'go ahead', 'implement', or 'build now').
+
+* For vague or underspecified queries (e.g. "Add something to show user activity" or "Create a panel for managing users"), always ask for clarification in the `explanation` field and return an empty `actions` array. Do not proceed with assumptions.
+
+* If unsure about intent, clarify in `explanation`, no `actions`
+
+* If layout is invalid or rules are broken, halt and return an error
+
+* Validate required fields before producing final output
+
+---
+
+## ✅ Summary
+
+* ✔️ Always produce a structured, valid app
+* ✔️ Use realistic sample data
+* ✔️ Adhere to layout and nesting rules
+* ✔️ Apply simplicity and UX consistency
+* ✔️ Output: single JSON object with `explanation` and `actions`
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
index 2278795505..4b386f9b27 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/appConfiguration.ts
@@ -14,34 +14,35 @@ export const configureAppMetaAction: ActionConfig = {
   category: 'app-configuration',
   requiresInput: false,
   execute: async (params: ActionExecuteParams) => {
-    const { editorState } = params;
+    const { editorState, actionPayload } = params;
+    const { action_parameters: { title, description, category } } = actionPayload;
     const appSettingsComp = editorState.getAppSettingsComp();
-    
+
     try {
       // TODO: Get config data from the user
-      let configData = {
-        title: "Test Title",
-        description: "Test Description",
-        category: "Test Category"
-      };
+      // let configData = {
+      //   title: "Test Title",
+      //   description: "Test Description",
+      //   category: "Test Category"
+      // };
 
-      if (configData.title && appSettingsComp?.children?.title) {
-        appSettingsComp.children.title.dispatchChangeValueAction(configData.title);
+      if (title && appSettingsComp?.children?.title) {
+        appSettingsComp.children.title.dispatchChangeValueAction(title);
       }
 
-      if (configData.description && appSettingsComp?.children?.description) {
-          appSettingsComp.children.description.dispatchChangeValueAction(configData.description);
+      if (description && appSettingsComp?.children?.description) {
+          appSettingsComp.children.description.dispatchChangeValueAction(description);
       }
 
-      if (configData.category && appSettingsComp?.children?.category) {
-        appSettingsComp.children.category.dispatchChangeValueAction(configData.category);
+      if (category && appSettingsComp?.children?.category) {
+        appSettingsComp.children.category.dispatchChangeValueAction(category);
       }
 
       // Display error message if no valid configuration data is provided
       const updatedFields = [];
-      if (configData.title) updatedFields.push('title');
-      if (configData.description) updatedFields.push('description');
-      if (configData.category) updatedFields.push('category');
+      if (title) updatedFields.push('title');
+      if (description) updatedFields.push('description');
+      if (category) updatedFields.push('category');
 
       !updatedFields.length && message.info('No valid configuration data provided');
 
@@ -347,7 +348,8 @@ export const applyThemeAction: ActionConfig = {
   category: 'app-configuration',
   isTheme: true,
   execute: async (params: ActionExecuteParams) => {
-    const { editorState, selectedTheme } = params;
+    const { editorState, actionPayload } = params;
+    const { action_parameters: { theme: selectedTheme } } = actionPayload;
 
     try {
       if (!selectedTheme) {
@@ -387,24 +389,8 @@ export const setCanvasSettingsAction: ActionConfig = {
   category: 'app-configuration',
   requiresInput: false,
   execute: async (params: ActionExecuteParams) => {
-    const { editorState } = params;
-
-    // Default canvas settings
-    // TODO: Get canvas settings from the user
-    const defaultCanvasSettings = {
-      maxWidth: "450",
-      gridColumns: 12,
-      gridRowHeight: 8,
-      gridRowCount: Infinity,
-      gridPaddingX: 20,
-      gridPaddingY: 20,
-      gridBg: "",
-      gridBgImage: "",
-      gridBgImageRepeat: "no-repeat",
-      gridBgImageSize: "cover",
-      gridBgImagePosition: "center",
-      gridBgImageOrigin: "no-padding"
-    };
+    const { editorState, actionPayload } = params;
+    const { action_parameters: canvasSettings } = actionPayload;
 
     try {
       const appSettingsComp = editorState.getAppSettingsComp();
@@ -428,52 +414,52 @@ export const setCanvasSettingsAction: ActionConfig = {
         gridBgImageOrigin,
       } = appSettingsComp.children;
 
-      if (maxWidth && defaultCanvasSettings.maxWidth) {
-        maxWidth.dispatchChangeValueAction(defaultCanvasSettings.maxWidth);
+      if (maxWidth && canvasSettings.maxWidth) {
+        maxWidth?.children?.dropdown?.dispatchChangeValueAction(canvasSettings.maxWidth);
       }
 
-      if (gridColumns && defaultCanvasSettings.gridColumns) {
-        gridColumns.dispatchChangeValueAction(defaultCanvasSettings.gridColumns);
+      if (gridColumns && canvasSettings.gridColumns) {
+        gridColumns.dispatchChangeValueAction(canvasSettings.gridColumns);
       }
 
-      if (gridRowHeight && defaultCanvasSettings.gridRowHeight) {
-        gridRowHeight.dispatchChangeValueAction(defaultCanvasSettings.gridRowHeight);
+      if (gridRowHeight && canvasSettings.gridRowHeight) {
+        gridRowHeight.dispatchChangeValueAction(canvasSettings.gridRowHeight);
       }
 
-      if (gridRowCount && defaultCanvasSettings.gridRowCount) {
-        gridRowCount.dispatchChangeValueAction(defaultCanvasSettings.gridRowCount);
+      if (gridRowCount && canvasSettings.gridRowCount) {
+        gridRowCount.dispatchChangeValueAction(canvasSettings.gridRowCount);
       }
 
-      if (gridPaddingX && defaultCanvasSettings.gridPaddingX) {
-        gridPaddingX.dispatchChangeValueAction(defaultCanvasSettings.gridPaddingX);
+      if (gridPaddingX && canvasSettings.gridPaddingX) {
+        gridPaddingX.dispatchChangeValueAction(canvasSettings.gridPaddingX);
       }
 
-      if (gridPaddingY && defaultCanvasSettings.gridPaddingY) {
-        gridPaddingY.dispatchChangeValueAction(defaultCanvasSettings.gridPaddingY);
+      if (gridPaddingY && canvasSettings.gridPaddingY) {
+        gridPaddingY.dispatchChangeValueAction(canvasSettings.gridPaddingY);
       }
 
-      if (gridBg && defaultCanvasSettings.gridBg) {
-        gridBg.dispatchChangeValueAction(defaultCanvasSettings.gridBg);
+      if (gridBg && canvasSettings.gridBg) {
+        gridBg.dispatchChangeValueAction(canvasSettings.gridBg);
       }
 
-      if (gridBgImage && defaultCanvasSettings.gridBgImage) {
-        gridBgImage.dispatchChangeValueAction(defaultCanvasSettings.gridBgImage);
+      if (gridBgImage && canvasSettings.gridBgImage) {
+        gridBgImage.dispatchChangeValueAction(canvasSettings.gridBgImage);
       }
 
-      if (gridBgImageRepeat && defaultCanvasSettings.gridBgImageRepeat) {
-        gridBgImageRepeat.dispatchChangeValueAction(defaultCanvasSettings.gridBgImageRepeat);
+      if (gridBgImageRepeat && canvasSettings.gridBgImageRepeat) {
+        gridBgImageRepeat.dispatchChangeValueAction(canvasSettings.gridBgImageRepeat);
       }
 
-      if (gridBgImageSize && defaultCanvasSettings.gridBgImageSize) {
-        gridBgImageSize.dispatchChangeValueAction(defaultCanvasSettings.gridBgImageSize);
+      if (gridBgImageSize && canvasSettings.gridBgImageSize) {
+        gridBgImageSize.dispatchChangeValueAction(canvasSettings.gridBgImageSize);
       }
 
-      if (gridBgImagePosition && defaultCanvasSettings.gridBgImagePosition) {
-        gridBgImagePosition.dispatchChangeValueAction(defaultCanvasSettings.gridBgImagePosition);
+      if (gridBgImagePosition && canvasSettings.gridBgImagePosition) {
+        gridBgImagePosition.dispatchChangeValueAction(canvasSettings.gridBgImagePosition);
       }
 
-      if (gridBgImageOrigin && defaultCanvasSettings.gridBgImageOrigin) {
-        gridBgImageOrigin.dispatchChangeValueAction(defaultCanvasSettings.gridBgImageOrigin);
+      if (gridBgImageOrigin && canvasSettings.gridBgImageOrigin) {
+        gridBgImageOrigin.dispatchChangeValueAction(canvasSettings.gridBgImageOrigin);
       }
 
       message.success('Canvas settings applied successfully!');
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts
index e691b818dc..642218fb41 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentConfiguration.ts
@@ -20,26 +20,32 @@ export const configureComponentAction: ActionConfig = {
     }
   },
   execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, actionValue: name, actionValue, actionPayload, editorState } = params;
-    const otherProps = actionPayload;
+    const { actionValue: name, actionValue, actionPayload, editorState } = params;
+    const { component_name: selectedEditorComponent, action_parameters } = actionPayload;
+    const { onEvent, ...compProperties } = action_parameters;
     // const { name, ...otherProps } = actionPayload;
     
     try {
-      const componentInfo = getEditorComponentInfo(editorState, name);
+      // const componentInfo = getEditorComponentInfo(editorState, name);
       
-      if (!componentInfo) {
-        message.error(`Component "${selectedEditorComponent}" not found`);
-        return;
-      }
+      // if (!componentInfo) {
+      //   message.error(`Component "${selectedEditorComponent}" not found`);
+      //   return;
+      // }
 
-      const { componentKey: parentKey, items } = componentInfo;
+      // const { componentKey: parentKey, items } = componentInfo;
     
-      if (!parentKey) {
-        message.error(`Parent component "${selectedEditorComponent}" not found in layout`);
-        return;
-      }
+      // if (!parentKey) {
+      //   message.error(`Parent component "${selectedEditorComponent}" not found in layout`);
+      //   return;
+      // }
 
-      const parentItem = items[parentKey];
+      // const parentItem = items[parentKey];
+      // if (!parentItem) {
+      //   message.error(`Parent component "${selectedEditorComponent}" not found in items`);
+      //   return;
+      // }
+      const parentItem = editorState.getUICompByName(selectedEditorComponent);
       if (!parentItem) {
         message.error(`Parent component "${selectedEditorComponent}" not found in items`);
         return;
@@ -49,11 +55,10 @@ export const configureComponentAction: ActionConfig = {
       const itemData = itemComp.toJsonValue();
       const config = {
         ...itemData,
-        ...otherProps
+        ...compProperties
       };
       itemComp.dispatchChangeValueAction(config);
 
-      debugger;
       console.log('Configuring component:', selectedEditorComponent, 'with config:', config);
       message.info(`Configure action for component "${selectedEditorComponent}"`);
       
diff --git a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
index 647d48df11..89a6f49c1d 100644
--- a/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
+++ b/client/packages/lowcoder/src/comps/comps/preLoadComp/actions/componentManagement.ts
@@ -156,6 +156,7 @@ export const nestComponentAction: ActionConfig = {
     // const { selectedEditorComponent, selectedNestComponent, editorState, actionPayload } = params;
     const { editorState, actionPayload, selectedComponent: selectedNestComponent } = params;
     const { component_name: name, layout, parent_component_name: selectedEditorComponent, action_parameters } = actionPayload;
+    const { onEvent, ...compProperties } = action_parameters;
     // const { name, layout, target: selectedEditorComponent, ...otherProps } = actionPayload;
 
     if (!selectedEditorComponent || !selectedNestComponent || !editorState) {
@@ -221,7 +222,7 @@ export const nestComponentAction: ActionConfig = {
       let compDefaultValue = defaultDataFn ? defaultDataFn(compName, nameGenerator, editorState) : undefined;
       const compInitialValue = {
         ...(compDefaultValue as any || {}),
-        ...action_parameters,
+        ...compProperties,
       }
 
       const widgetValue: GridItemDataType = {
@@ -235,9 +236,14 @@ export const nestComponentAction: ActionConfig = {
       for (const childComponent of childComponents) {
         originalContainer = originalContainer.children[childComponent];
       }
+      // handle container layout components
       if (originalContainer?.children?.[0]?.children?.view) {
         originalContainer = originalContainer?.children?.[0]?.children?.view;
       }
+      // handle list/grid components
+      if (originalContainer?.children?.__comp__?.children?.comp) {
+        originalContainer = originalContainer?.children?.__comp__?.children?.comp;
+      }
 
       if (!originalContainer) {
         message.error(`Container "${selectedEditorComponent}" cannot accept nested components`);
@@ -386,7 +392,8 @@ export const moveComponentAction: ActionConfig = {
     return null;
   },
   execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, actionValue, editorState } = params;
+    const { actionValue, editorState, actionPayload } = params;
+    const { layout: updatedLayout, component_name: selectedEditorComponent } = actionPayload;
 
     if (!selectedEditorComponent || !editorState) {
       message.error('Component and editor state are required');
@@ -394,18 +401,18 @@ export const moveComponentAction: ActionConfig = {
     }
 
     try {
-      const moveParams: { x?: number; y?: number } = {};
-      const params = actionValue.toLowerCase().split(',').map(p => p.trim());
+      const moveParams: { x?: number; y?: number } = {x: updatedLayout?.x, y: updatedLayout?.y};
+      // const params = actionValue.toLowerCase().split(',').map(p => p.trim());
       
-      for (const param of params) {
-        const [key, val] = param.split(':').map(s => s.trim());
-        if (['x', 'y'].includes(key)) {
-          moveParams[key as 'x' | 'y'] = parseInt(val);
-        }
-      }
-
-      if (!moveParams.x && !moveParams.y) {
-        message.error('No valid move parameters provided');
+      // for (const param of params) {
+      //   const [key, val] = param.split(':').map(s => s.trim());
+      //   if (['x', 'y'].includes(key)) {
+      //     moveParams[key as 'x' | 'y'] = parseInt(val);
+      //   }
+      // }
+
+      if (!updatedLayout) {
+        message.error('No valid layout paramters provided');
         return;
       }
 
@@ -560,7 +567,8 @@ export const resizeComponentAction: ActionConfig = {
     return null;
   },
   execute: async (params: ActionExecuteParams) => {
-    const { selectedEditorComponent, actionValue, editorState } = params;
+    const { actionValue, editorState, actionPayload } = params;
+    const { layout: updatedLayout, component_name: selectedEditorComponent } = actionPayload;
 
     if (!selectedEditorComponent || !editorState) {
       message.error('Component and editor state are required');
@@ -568,15 +576,15 @@ export const resizeComponentAction: ActionConfig = {
     }
 
     try {
-      const resizeParams: { w?: number; h?: number } = {};
-      const params = actionValue.toLowerCase().split(',').map(p => p.trim());
+      const resizeParams: { w?: number; h?: number } = {w: updatedLayout?.w, h: updatedLayout?.h};
+      // const params = actionValue.toLowerCase().split(',').map(p => p.trim());
       
-      for (const param of params) {
-        const [key, val] = param.split(':').map(s => s.trim());
-        if (['w', 'h'].includes(key)) {
-          resizeParams[key as 'w' | 'h'] = parseInt(val);
-        }
-      }
+      // for (const param of params) {
+      //   const [key, val] = param.split(':').map(s => s.trim());
+      //   if (['w', 'h'].includes(key)) {
+      //     resizeParams[key as 'w' | 'h'] = parseInt(val);
+      //   }
+      // }
 
       if (!resizeParams.w && !resizeParams.h) {
         message.error('No valid resize parameters provided');
diff --git a/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx b/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
index 0ca02f6b23..e41ecdb2ff 100644
--- a/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
+++ b/client/packages/lowcoder/src/pages/editor/bottom/BottomPanel.tsx
@@ -126,10 +126,10 @@ function Bottom(props: any) {
                 modelHost="http://localhost:5678/webhook-test/9a363e76-d3a5-46d1-98c3-4359f7106d33"
               /> */}
              <ChatPanel
-              tableName="LC_AI"
-              modelHost="http://localhost:5678/..."
-              systemPrompt="You are a helpful assistant."
-              streaming={true}
+                tableName="LC_AI"
+                modelHost="http://localhost:5678/webhook/9a363e76-d3a5-46d1-98c3-4359f7106d33"
+                systemPrompt="You are a helpful assistant."
+                streaming={true}
               />
             </Flex>
           )}
