@gui-chat-plugin/mindmap 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Mind Map Tool Definition
3
+ */
4
+ import type { ToolDefinition } from "gui-chat-protocol";
5
+ export declare const TOOL_NAME = "createMindMap";
6
+ export declare const TOOL_DEFINITION: ToolDefinition;
7
+ export declare const SYSTEM_PROMPT = "Use createMindMap to create visual mind maps when:\n- The user wants to brainstorm or explore ideas\n- Organizing complex topics with multiple related concepts\n- Explaining relationships between different concepts\n- Planning projects or workflows\n- Summarizing discussions into visual format\n\nWhen creating a mind map, start with a clear central idea and branch out with related concepts. Use add_node to expand specific branches, delete_node to remove unwanted nodes, and connect to show relationships between non-adjacent ideas.";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Mind Map Plugin - Core (Framework-agnostic)
3
+ */
4
+ export type { MindMapData, MindMapArgs, MindMapJsonData, MindMapNode, MindMapConnection, } from "./types";
5
+ export { TOOL_NAME, TOOL_DEFINITION, SYSTEM_PROMPT, executeMindMap, pluginCore, } from "./plugin";
6
+ export { samples } from "./samples";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Mind Map Plugin Core
3
+ */
4
+ import type { ToolPluginCore, ToolContext, ToolResult } from "gui-chat-protocol";
5
+ import type { MindMapData, MindMapArgs, MindMapJsonData } from "./types";
6
+ export { TOOL_NAME, TOOL_DEFINITION, SYSTEM_PROMPT } from "./definition";
7
+ export declare const executeMindMap: (context: ToolContext, args: MindMapArgs) => Promise<ToolResult<MindMapData, MindMapJsonData>>;
8
+ export declare const pluginCore: ToolPluginCore<MindMapData, MindMapJsonData, MindMapArgs>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Mind Map Plugin Samples
3
+ */
4
+ import type { ToolSample } from "gui-chat-protocol";
5
+ export declare const samples: ToolSample[];
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Mind Map Plugin - Type Definitions
3
+ */
4
+ /** A node in the mind map */
5
+ export interface MindMapNode {
6
+ id: string;
7
+ text: string;
8
+ x: number;
9
+ y: number;
10
+ color?: string;
11
+ children?: string[];
12
+ }
13
+ /** A connection between nodes */
14
+ export interface MindMapConnection {
15
+ from: string;
16
+ to: string;
17
+ label?: string;
18
+ }
19
+ /** Data stored in result.data (for UI display) */
20
+ export interface MindMapData {
21
+ title: string;
22
+ nodes: MindMapNode[];
23
+ connections: MindMapConnection[];
24
+ centerNodeId: string;
25
+ }
26
+ /** Arguments passed to the tool */
27
+ export interface MindMapArgs {
28
+ action: "create" | "add_node" | "delete_node" | "connect" | "update" | "rebalance";
29
+ title?: string;
30
+ centralIdea?: string;
31
+ ideas?: string[];
32
+ parentNodeId?: string;
33
+ newIdea?: string;
34
+ nodeIdToDelete?: string;
35
+ fromNodeId?: string;
36
+ toNodeId?: string;
37
+ connectionLabel?: string;
38
+ existingMap?: MindMapData;
39
+ }
40
+ /** JSON data returned in result.jsonData */
41
+ export interface MindMapJsonData {
42
+ nodeCount: number;
43
+ connectionCount: number;
44
+ nodes: {
45
+ id: string;
46
+ text: string;
47
+ }[];
48
+ }
package/dist/core.cjs ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M="createMindMap",A={type:"function",name:M,description:"Create or update an interactive mind map to visualize ideas, concepts, and their relationships. Use this when brainstorming, organizing thoughts, or explaining complex topics visually.",parameters:{type:"object",properties:{action:{type:"string",enum:["create","add_node","delete_node","connect","update","rebalance"],description:"Action to perform: create (new mind map), add_node (add idea to existing node), delete_node (remove a node and its connections), connect (link two nodes), update (modify existing map), rebalance (recalculate layout for better display)"},title:{type:"string",description:"Title of the mind map (required for create action)"},centralIdea:{type:"string",description:"The central concept or main topic (required for create action)"},ideas:{type:"array",items:{type:"string"},description:"List of related ideas to add as branches from the central idea (for create action)"},parentNodeId:{type:"string",description:"ID of the parent node to attach new idea to (for add_node action)"},newIdea:{type:"string",description:"New idea to add (for add_node action)"},nodeIdToDelete:{type:"string",description:"ID of the node to delete (for delete_node action). Children of this node will also be deleted."},fromNodeId:{type:"string",description:"Source node ID for connection (for connect action)"},toNodeId:{type:"string",description:"Target node ID for connection (for connect action)"},connectionLabel:{type:"string",description:"Optional label for the connection"},existingMap:{type:"object",description:"Optional: Current mind map state. Not required if updating the currently displayed mind map - the plugin will use the current state automatically."}},required:["action"]}},E=`Use ${M} to create visual mind maps when:
2
+ - The user wants to brainstorm or explore ideas
3
+ - Organizing complex topics with multiple related concepts
4
+ - Explaining relationships between different concepts
5
+ - Planning projects or workflows
6
+ - Summarizing discussions into visual format
7
+
8
+ When creating a mind map, start with a clear central idea and branch out with related concepts. Use add_node to expand specific branches, delete_node to remove unwanted nodes, and connect to show relationships between non-adjacent ideas.`,T=["#4F46E5","#0891B2","#059669","#D97706","#DC2626","#7C3AED","#2563EB","#DB2777"];function x(){return`node_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function C(n){return T[n%T.length]}const S=800,P=600,_=S/2,R=P/2,D=60;function O(n,e,t,i,o){const s=2*Math.PI*n/e-Math.PI/2;return{x:t+o*Math.cos(s),y:i+o*Math.sin(s)}}function k(n,e,t,i,o){const s=n-_,r=e-R,f=Math.atan2(r,s),a=Math.PI*.67,l=f-a/2,c=i>1?a/(i-1):0,d=l+c*t,u=120*Math.pow(.85,o-1);return{x:n+u*Math.cos(d),y:e+u*Math.sin(d)}}function v(n,e){return{x:Math.max(D,Math.min(S-D,n)),y:Math.max(D,Math.min(P-D,e))}}function j(n,e,t,i=new Set){var o;if(n===t)return 0;if(i.has(n))return 999;i.add(n);for(const s of e)if((o=s.children)!=null&&o.includes(n))return 1+j(s.id,e,t,i);return 1}function L(n,e,t){const r={id:x(),text:e,x:400,y:300,color:"#1F2937",children:[]},f=[r],a=[];return t.forEach((l,c)=>{var u;const d=O(c,t.length,400,300,200),m={id:x(),text:l,x:d.x,y:d.y,color:C(c),children:[]};f.push(m),(u=r.children)==null||u.push(m.id),a.push({from:r.id,to:m.id})}),{title:n,nodes:f,connections:a,centerNodeId:r.id}}function q(n,e,t){var p;const i=n.nodes||[],o=n.connections||[],s=i.find(g=>g.id===e);if(!s)return{...n,nodes:i,connections:o};const r=((p=s.children)==null?void 0:p.length)||0,f=r,a=r+1,l=j(e,i,n.centerNodeId||"")+1,c=k(s.x,s.y,f,a,l),d=v(c.x,c.y),m={id:x(),text:t,x:d.x,y:d.y,color:C(i.length),children:[]},u={...s,children:[...s.children||[],m.id]};return{...n,nodes:[...i.filter(g=>g.id!==e),u,m],connections:[...o,{from:e,to:m.id}]}}function F(n){const e=n.nodes||[],t=n.centerNodeId;if(!t||e.length===0||!e.find(a=>a.id===t))return n;const o=new Map(e.map(a=>[a.id,{...a}])),s=o.get(t);s.x=_,s.y=R;const r=(a,l,c)=>{const d=o.get(a);if(!d||!d.children||c.has(a))return;c.add(a);const m=d.children.filter(u=>!c.has(u));m.forEach((u,p)=>{const g=o.get(u);if(g){if(l===1){const y=O(p,m.length,d.x,d.y,160);g.x=y.x,g.y=y.y}else{const N=k(d.x,d.y,p,m.length,l),y=v(N.x,N.y);g.x=y.x,g.y=y.y}r(u,l+1,c)}})},f=new Set;return f.add(t),r(t,1,f),{...n,nodes:Array.from(o.values())}}function H(n,e,t,i){const o=n.connections||[];return o.some(r=>r.from===e&&r.to===t)?{...n,connections:o}:{...n,connections:[...o,{from:e,to:t,label:i}]}}function U(n,e){const t=n.nodes||[],i=n.connections||[];if(e===n.centerNodeId)return n;const o=new Set;function s(a){o.add(a);const l=t.find(c=>c.id===a);l!=null&&l.children&&l.children.forEach(c=>s(c))}s(e);const r=t.filter(a=>!o.has(a.id)).map(a=>{var l;return{...a,children:(l=a.children)==null?void 0:l.filter(c=>!o.has(c))}}),f=i.filter(a=>!o.has(a.from)&&!o.has(a.to));return{...n,nodes:r,connections:f}}function I(n,e){var i,o,s,r;const t=(i=n.currentResult)==null?void 0:i.data;if(console.log("[MindMap Debug] getExistingMapData:",{contextDataExists:!!t,contextDataNodes:(o=t==null?void 0:t.nodes)==null?void 0:o.length,argsMapExists:!!e,argsMapNodes:(s=e==null?void 0:e.nodes)==null?void 0:s.length,argsMapHasNodeCount:e&&"nodeCount"in e}),t!=null&&t.nodes&&t.nodes.length>0)return console.log("[MindMap Debug] Using contextData with",t.nodes.length,"nodes"),{...t,connections:t.connections||[]};if(e!=null&&e.nodes&&e.nodes.length>0)return console.log("[MindMap Debug] Using argsMap with",e.nodes.length,"nodes"),{...e,connections:e.connections||[]};if(e&&"nodeCount"in e&&e.nodes){console.log("[MindMap Debug] Reconstructing from jsonData format");const f=e,a=400,l=300,c=200,d=f.nodes.map((u,p)=>{const g=2*Math.PI*p/f.nodes.length-Math.PI/2;return{id:u.id,text:u.text,x:p===0?a:a+c*Math.cos(g),y:p===0?l:l+c*Math.sin(g),color:p===0?"#1F2937":C(p),children:[]}}),m=[];if(d.length>1){const u=d[0];for(let p=1;p<d.length;p++)m.push({from:u.id,to:d[p].id}),u.children=u.children||[],u.children.push(d[p].id)}return console.log("[MindMap Debug] Reconstructed",d.length,"nodes from jsonData"),{title:"Mind Map",nodes:d,connections:m,centerNodeId:((r=d[0])==null?void 0:r.id)||""}}return console.log("[MindMap Debug] No existing map found, returning null"),null}const $=async(n,e)=>{var l,c,d,m,u,p,g,N,y;const{action:t}=e;let i,o,s;switch(t){case"create":{if(!e.title||!e.centralIdea)return{toolName:M,message:"Title and central idea are required for creating a mind map",instructions:"Ask the user for the title and central concept."};i=L(e.title,e.centralIdea,e.ideas||[]),o=`Created mind map "${e.title}" with ${i.nodes.length} nodes`,s="Tell the user the mind map has been created. Ask if they want to add more ideas or create connections between concepts.";break}case"add_node":{const h=I(n,e.existingMap),w={hasContext:!!n,hasCurrentResult:!!(n!=null&&n.currentResult),currentResultToolName:(l=n==null?void 0:n.currentResult)==null?void 0:l.toolName,currentResultHasData:!!((c=n==null?void 0:n.currentResult)!=null&&c.data),currentResultDataNodes:(u=(m=(d=n==null?void 0:n.currentResult)==null?void 0:d.data)==null?void 0:m.nodes)==null?void 0:u.length,argsHasExistingMap:!!e.existingMap,argsExistingMapNodes:(g=(p=e.existingMap)==null?void 0:p.nodes)==null?void 0:g.length,existingMapResult:h?`${(N=h.nodes)==null?void 0:N.length} nodes`:null,parentNodeId:e.parentNodeId,newIdea:e.newIdea};if(console.log("[MindMap Debug] add_node:",JSON.stringify(w,null,2)),!h||!e.parentNodeId||!e.newIdea){const b=[];return h||b.push("existingMap"),e.parentNodeId||b.push("parentNodeId"),e.newIdea||b.push("newIdea"),{toolName:M,message:`Missing: ${b.join(", ")}. Debug: context.currentResult.data=${!!((y=n==null?void 0:n.currentResult)!=null&&y.data)}, args.existingMap=${!!e.existingMap}`,instructions:"Ask the user which node to add the new idea to."}}i=q(h,e.parentNodeId,e.newIdea),o=`Added "${e.newIdea}" to the mind map`,s="Confirm the new idea was added. Ask if they want to continue expanding or explore other branches.";break}case"delete_node":{const h=I(n,e.existingMap);if(!h||!e.nodeIdToDelete)return{toolName:M,message:"Existing map and node ID are required for deletion",instructions:"Ask which node should be deleted."};if(e.nodeIdToDelete===h.centerNodeId)return{toolName:M,message:"Cannot delete the center node",instructions:"Tell the user that the center node cannot be deleted."};const w=h.nodes.find(b=>b.id===e.nodeIdToDelete);i=U(h,e.nodeIdToDelete),o=`Deleted "${(w==null?void 0:w.text)||e.nodeIdToDelete}" from the mind map`,s="Confirm the node was deleted. Ask if they want to make any other changes.";break}case"connect":{const h=I(n,e.existingMap);if(!h||!e.fromNodeId||!e.toNodeId)return{toolName:M,message:"Existing map and both node IDs are required for connection",instructions:"Ask which concepts should be connected."};i=H(h,e.fromNodeId,e.toNodeId,e.connectionLabel),o="Connected nodes in the mind map",s="Confirm the connection was created. Ask if they want to add more relationships.";break}case"update":{const h=I(n,e.existingMap);if(!h)return{toolName:M,message:"Existing map is required for update",instructions:"The mind map data is missing."};i=h,o="Mind map updated",s="The mind map has been refreshed.";break}case"rebalance":{const h=I(n,e.existingMap);if(!h)return{toolName:M,message:"Existing map is required for rebalance",instructions:"The mind map data is missing."};i=F(h),o=`Mind map layout rebalanced with ${i.nodes.length} nodes`,s="The mind map layout has been optimized for better readability.";break}default:return{toolName:M,message:`Unknown action: ${t}`,instructions:"Invalid action specified."}}const r=i.nodes||[],f=i.connections||[],a={nodeCount:r.length,connectionCount:f.length,nodes:r.map(h=>({id:h.id,text:h.text}))};return{toolName:M,message:o,title:i.title,data:i,jsonData:a,instructions:s,updating:t!=="create"}},W={toolDefinition:A,execute:$,generatingMessage:"Creating mind map...",isEnabled:()=>!0,systemPrompt:E},Y=[{name:"AI Applications",args:{action:"create",title:"AI Applications",centralIdea:"Artificial Intelligence",ideas:["Machine Learning","Natural Language Processing","Computer Vision","Robotics","Expert Systems","Speech Recognition"]}},{name:"Web Development",args:{action:"create",title:"Modern Web Development",centralIdea:"Web Development",ideas:["Frontend","Backend","Database","DevOps","Security"]}},{name:"Project Planning",args:{action:"create",title:"New Project",centralIdea:"Project Goals",ideas:["Research","Design","Implementation","Testing","Deployment","Maintenance"]}},{name:"Creative Writing",args:{action:"create",title:"Story Ideas",centralIdea:"Adventure Story",ideas:["Main Character","Setting","Conflict","Plot Twists","Resolution"]}}];exports.SYSTEM_PROMPT=E;exports.TOOL_DEFINITION=A;exports.TOOL_NAME=M;exports.executeMindMap=$;exports.pluginCore=W;exports.samples=Y;
package/dist/core.js ADDED
@@ -0,0 +1,512 @@
1
+ const y = "createMindMap", O = {
2
+ type: "function",
3
+ name: y,
4
+ description: "Create or update an interactive mind map to visualize ideas, concepts, and their relationships. Use this when brainstorming, organizing thoughts, or explaining complex topics visually.",
5
+ parameters: {
6
+ type: "object",
7
+ properties: {
8
+ action: {
9
+ type: "string",
10
+ enum: ["create", "add_node", "delete_node", "connect", "update", "rebalance"],
11
+ description: "Action to perform: create (new mind map), add_node (add idea to existing node), delete_node (remove a node and its connections), connect (link two nodes), update (modify existing map), rebalance (recalculate layout for better display)"
12
+ },
13
+ title: {
14
+ type: "string",
15
+ description: "Title of the mind map (required for create action)"
16
+ },
17
+ centralIdea: {
18
+ type: "string",
19
+ description: "The central concept or main topic (required for create action)"
20
+ },
21
+ ideas: {
22
+ type: "array",
23
+ items: { type: "string" },
24
+ description: "List of related ideas to add as branches from the central idea (for create action)"
25
+ },
26
+ parentNodeId: {
27
+ type: "string",
28
+ description: "ID of the parent node to attach new idea to (for add_node action)"
29
+ },
30
+ newIdea: {
31
+ type: "string",
32
+ description: "New idea to add (for add_node action)"
33
+ },
34
+ nodeIdToDelete: {
35
+ type: "string",
36
+ description: "ID of the node to delete (for delete_node action). Children of this node will also be deleted."
37
+ },
38
+ fromNodeId: {
39
+ type: "string",
40
+ description: "Source node ID for connection (for connect action)"
41
+ },
42
+ toNodeId: {
43
+ type: "string",
44
+ description: "Target node ID for connection (for connect action)"
45
+ },
46
+ connectionLabel: {
47
+ type: "string",
48
+ description: "Optional label for the connection"
49
+ },
50
+ existingMap: {
51
+ type: "object",
52
+ description: "Optional: Current mind map state. Not required if updating the currently displayed mind map - the plugin will use the current state automatically."
53
+ }
54
+ },
55
+ required: ["action"]
56
+ }
57
+ }, $ = `Use ${y} to create visual mind maps when:
58
+ - The user wants to brainstorm or explore ideas
59
+ - Organizing complex topics with multiple related concepts
60
+ - Explaining relationships between different concepts
61
+ - Planning projects or workflows
62
+ - Summarizing discussions into visual format
63
+
64
+ When creating a mind map, start with a clear central idea and branch out with related concepts. Use add_node to expand specific branches, delete_node to remove unwanted nodes, and connect to show relationships between non-adjacent ideas.`, A = [
65
+ "#4F46E5",
66
+ // indigo
67
+ "#0891B2",
68
+ // cyan
69
+ "#059669",
70
+ // emerald
71
+ "#D97706",
72
+ // amber
73
+ "#DC2626",
74
+ // red
75
+ "#7C3AED",
76
+ // violet
77
+ "#2563EB",
78
+ // blue
79
+ "#DB2777"
80
+ // pink
81
+ ];
82
+ function x() {
83
+ return `node_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
84
+ }
85
+ function C(n) {
86
+ return A[n % A.length];
87
+ }
88
+ const T = 800, E = 600, R = T / 2, P = E / 2, D = 60;
89
+ function S(n, e, t, i, o) {
90
+ const s = 2 * Math.PI * n / e - Math.PI / 2;
91
+ return {
92
+ x: t + o * Math.cos(s),
93
+ y: i + o * Math.sin(s)
94
+ };
95
+ }
96
+ function _(n, e, t, i, o) {
97
+ const s = n - R, r = e - P, f = Math.atan2(r, s), a = Math.PI * 0.67, l = f - a / 2, c = i > 1 ? a / (i - 1) : 0, d = l + c * t, u = 120 * Math.pow(0.85, o - 1);
98
+ return {
99
+ x: n + u * Math.cos(d),
100
+ y: e + u * Math.sin(d)
101
+ };
102
+ }
103
+ function k(n, e) {
104
+ return {
105
+ x: Math.max(D, Math.min(T - D, n)),
106
+ y: Math.max(D, Math.min(E - D, e))
107
+ };
108
+ }
109
+ function v(n, e, t, i = /* @__PURE__ */ new Set()) {
110
+ var o;
111
+ if (n === t) return 0;
112
+ if (i.has(n)) return 999;
113
+ i.add(n);
114
+ for (const s of e)
115
+ if ((o = s.children) != null && o.includes(n))
116
+ return 1 + v(s.id, e, t, i);
117
+ return 1;
118
+ }
119
+ function j(n, e, t) {
120
+ const r = {
121
+ id: x(),
122
+ text: e,
123
+ x: 400,
124
+ y: 300,
125
+ color: "#1F2937",
126
+ // dark gray for center
127
+ children: []
128
+ }, f = [r], a = [];
129
+ return t.forEach((l, c) => {
130
+ var u;
131
+ const d = S(c, t.length, 400, 300, 200), m = {
132
+ id: x(),
133
+ text: l,
134
+ x: d.x,
135
+ y: d.y,
136
+ color: C(c),
137
+ children: []
138
+ };
139
+ f.push(m), (u = r.children) == null || u.push(m.id), a.push({
140
+ from: r.id,
141
+ to: m.id
142
+ });
143
+ }), {
144
+ title: n,
145
+ nodes: f,
146
+ connections: a,
147
+ centerNodeId: r.id
148
+ };
149
+ }
150
+ function q(n, e, t) {
151
+ var p;
152
+ const i = n.nodes || [], o = n.connections || [], s = i.find((g) => g.id === e);
153
+ if (!s)
154
+ return { ...n, nodes: i, connections: o };
155
+ const r = ((p = s.children) == null ? void 0 : p.length) || 0, f = r, a = r + 1, l = v(e, i, n.centerNodeId || "") + 1, c = _(
156
+ s.x,
157
+ s.y,
158
+ f,
159
+ a,
160
+ l
161
+ ), d = k(c.x, c.y), m = {
162
+ id: x(),
163
+ text: t,
164
+ x: d.x,
165
+ y: d.y,
166
+ color: C(i.length),
167
+ children: []
168
+ }, u = {
169
+ ...s,
170
+ children: [...s.children || [], m.id]
171
+ };
172
+ return {
173
+ ...n,
174
+ nodes: [...i.filter((g) => g.id !== e), u, m],
175
+ connections: [
176
+ ...o,
177
+ { from: e, to: m.id }
178
+ ]
179
+ };
180
+ }
181
+ function L(n) {
182
+ const e = n.nodes || [], t = n.centerNodeId;
183
+ if (!t || e.length === 0 || !e.find((a) => a.id === t))
184
+ return n;
185
+ const o = new Map(e.map((a) => [a.id, { ...a }])), s = o.get(t);
186
+ s.x = R, s.y = P;
187
+ const r = (a, l, c) => {
188
+ const d = o.get(a);
189
+ if (!d || !d.children || c.has(a)) return;
190
+ c.add(a);
191
+ const m = d.children.filter((u) => !c.has(u));
192
+ m.forEach((u, p) => {
193
+ const g = o.get(u);
194
+ if (g) {
195
+ if (l === 1) {
196
+ const M = S(
197
+ p,
198
+ m.length,
199
+ d.x,
200
+ d.y,
201
+ 160
202
+ );
203
+ g.x = M.x, g.y = M.y;
204
+ } else {
205
+ const N = _(
206
+ d.x,
207
+ d.y,
208
+ p,
209
+ m.length,
210
+ l
211
+ ), M = k(N.x, N.y);
212
+ g.x = M.x, g.y = M.y;
213
+ }
214
+ r(u, l + 1, c);
215
+ }
216
+ });
217
+ }, f = /* @__PURE__ */ new Set();
218
+ return f.add(t), r(t, 1, f), {
219
+ ...n,
220
+ nodes: Array.from(o.values())
221
+ };
222
+ }
223
+ function F(n, e, t, i) {
224
+ const o = n.connections || [];
225
+ return o.some(
226
+ (r) => r.from === e && r.to === t
227
+ ) ? { ...n, connections: o } : {
228
+ ...n,
229
+ connections: [
230
+ ...o,
231
+ { from: e, to: t, label: i }
232
+ ]
233
+ };
234
+ }
235
+ function H(n, e) {
236
+ const t = n.nodes || [], i = n.connections || [];
237
+ if (e === n.centerNodeId)
238
+ return n;
239
+ const o = /* @__PURE__ */ new Set();
240
+ function s(a) {
241
+ o.add(a);
242
+ const l = t.find((c) => c.id === a);
243
+ l != null && l.children && l.children.forEach((c) => s(c));
244
+ }
245
+ s(e);
246
+ const r = t.filter((a) => !o.has(a.id)).map((a) => {
247
+ var l;
248
+ return {
249
+ ...a,
250
+ // Remove deleted children from children arrays
251
+ children: (l = a.children) == null ? void 0 : l.filter((c) => !o.has(c))
252
+ };
253
+ }), f = i.filter(
254
+ (a) => !o.has(a.from) && !o.has(a.to)
255
+ );
256
+ return {
257
+ ...n,
258
+ nodes: r,
259
+ connections: f
260
+ };
261
+ }
262
+ function I(n, e) {
263
+ var i, o, s, r;
264
+ const t = (i = n.currentResult) == null ? void 0 : i.data;
265
+ if (console.log("[MindMap Debug] getExistingMapData:", {
266
+ contextDataExists: !!t,
267
+ contextDataNodes: (o = t == null ? void 0 : t.nodes) == null ? void 0 : o.length,
268
+ argsMapExists: !!e,
269
+ argsMapNodes: (s = e == null ? void 0 : e.nodes) == null ? void 0 : s.length,
270
+ argsMapHasNodeCount: e && "nodeCount" in e
271
+ }), t != null && t.nodes && t.nodes.length > 0)
272
+ return console.log("[MindMap Debug] Using contextData with", t.nodes.length, "nodes"), {
273
+ ...t,
274
+ connections: t.connections || []
275
+ };
276
+ if (e != null && e.nodes && e.nodes.length > 0)
277
+ return console.log("[MindMap Debug] Using argsMap with", e.nodes.length, "nodes"), {
278
+ ...e,
279
+ connections: e.connections || []
280
+ };
281
+ if (e && "nodeCount" in e && e.nodes) {
282
+ console.log("[MindMap Debug] Reconstructing from jsonData format");
283
+ const f = e, a = 400, l = 300, c = 200, d = f.nodes.map((u, p) => {
284
+ const g = 2 * Math.PI * p / f.nodes.length - Math.PI / 2;
285
+ return {
286
+ id: u.id,
287
+ text: u.text,
288
+ x: p === 0 ? a : a + c * Math.cos(g),
289
+ y: p === 0 ? l : l + c * Math.sin(g),
290
+ color: p === 0 ? "#1F2937" : C(p),
291
+ children: []
292
+ };
293
+ }), m = [];
294
+ if (d.length > 1) {
295
+ const u = d[0];
296
+ for (let p = 1; p < d.length; p++)
297
+ m.push({
298
+ from: u.id,
299
+ to: d[p].id
300
+ }), u.children = u.children || [], u.children.push(d[p].id);
301
+ }
302
+ return console.log("[MindMap Debug] Reconstructed", d.length, "nodes from jsonData"), {
303
+ title: "Mind Map",
304
+ nodes: d,
305
+ connections: m,
306
+ centerNodeId: ((r = d[0]) == null ? void 0 : r.id) || ""
307
+ };
308
+ }
309
+ return console.log("[MindMap Debug] No existing map found, returning null"), null;
310
+ }
311
+ const U = async (n, e) => {
312
+ var l, c, d, m, u, p, g, N, M;
313
+ const { action: t } = e;
314
+ let i, o, s;
315
+ switch (t) {
316
+ case "create": {
317
+ if (!e.title || !e.centralIdea)
318
+ return {
319
+ toolName: y,
320
+ message: "Title and central idea are required for creating a mind map",
321
+ instructions: "Ask the user for the title and central concept."
322
+ };
323
+ i = j(
324
+ e.title,
325
+ e.centralIdea,
326
+ e.ideas || []
327
+ ), o = `Created mind map "${e.title}" with ${i.nodes.length} nodes`, s = "Tell the user the mind map has been created. Ask if they want to add more ideas or create connections between concepts.";
328
+ break;
329
+ }
330
+ case "add_node": {
331
+ const h = I(n, e.existingMap), w = {
332
+ hasContext: !!n,
333
+ hasCurrentResult: !!(n != null && n.currentResult),
334
+ currentResultToolName: (l = n == null ? void 0 : n.currentResult) == null ? void 0 : l.toolName,
335
+ currentResultHasData: !!((c = n == null ? void 0 : n.currentResult) != null && c.data),
336
+ currentResultDataNodes: (u = (m = (d = n == null ? void 0 : n.currentResult) == null ? void 0 : d.data) == null ? void 0 : m.nodes) == null ? void 0 : u.length,
337
+ argsHasExistingMap: !!e.existingMap,
338
+ argsExistingMapNodes: (g = (p = e.existingMap) == null ? void 0 : p.nodes) == null ? void 0 : g.length,
339
+ existingMapResult: h ? `${(N = h.nodes) == null ? void 0 : N.length} nodes` : null,
340
+ parentNodeId: e.parentNodeId,
341
+ newIdea: e.newIdea
342
+ };
343
+ if (console.log("[MindMap Debug] add_node:", JSON.stringify(w, null, 2)), !h || !e.parentNodeId || !e.newIdea) {
344
+ const b = [];
345
+ return h || b.push("existingMap"), e.parentNodeId || b.push("parentNodeId"), e.newIdea || b.push("newIdea"), {
346
+ toolName: y,
347
+ message: `Missing: ${b.join(", ")}. Debug: context.currentResult.data=${!!((M = n == null ? void 0 : n.currentResult) != null && M.data)}, args.existingMap=${!!e.existingMap}`,
348
+ instructions: "Ask the user which node to add the new idea to."
349
+ };
350
+ }
351
+ i = q(
352
+ h,
353
+ e.parentNodeId,
354
+ e.newIdea
355
+ ), o = `Added "${e.newIdea}" to the mind map`, s = "Confirm the new idea was added. Ask if they want to continue expanding or explore other branches.";
356
+ break;
357
+ }
358
+ case "delete_node": {
359
+ const h = I(n, e.existingMap);
360
+ if (!h || !e.nodeIdToDelete)
361
+ return {
362
+ toolName: y,
363
+ message: "Existing map and node ID are required for deletion",
364
+ instructions: "Ask which node should be deleted."
365
+ };
366
+ if (e.nodeIdToDelete === h.centerNodeId)
367
+ return {
368
+ toolName: y,
369
+ message: "Cannot delete the center node",
370
+ instructions: "Tell the user that the center node cannot be deleted."
371
+ };
372
+ const w = h.nodes.find((b) => b.id === e.nodeIdToDelete);
373
+ i = H(h, e.nodeIdToDelete), o = `Deleted "${(w == null ? void 0 : w.text) || e.nodeIdToDelete}" from the mind map`, s = "Confirm the node was deleted. Ask if they want to make any other changes.";
374
+ break;
375
+ }
376
+ case "connect": {
377
+ const h = I(n, e.existingMap);
378
+ if (!h || !e.fromNodeId || !e.toNodeId)
379
+ return {
380
+ toolName: y,
381
+ message: "Existing map and both node IDs are required for connection",
382
+ instructions: "Ask which concepts should be connected."
383
+ };
384
+ i = F(
385
+ h,
386
+ e.fromNodeId,
387
+ e.toNodeId,
388
+ e.connectionLabel
389
+ ), o = "Connected nodes in the mind map", s = "Confirm the connection was created. Ask if they want to add more relationships.";
390
+ break;
391
+ }
392
+ case "update": {
393
+ const h = I(n, e.existingMap);
394
+ if (!h)
395
+ return {
396
+ toolName: y,
397
+ message: "Existing map is required for update",
398
+ instructions: "The mind map data is missing."
399
+ };
400
+ i = h, o = "Mind map updated", s = "The mind map has been refreshed.";
401
+ break;
402
+ }
403
+ case "rebalance": {
404
+ const h = I(n, e.existingMap);
405
+ if (!h)
406
+ return {
407
+ toolName: y,
408
+ message: "Existing map is required for rebalance",
409
+ instructions: "The mind map data is missing."
410
+ };
411
+ i = L(h), o = `Mind map layout rebalanced with ${i.nodes.length} nodes`, s = "The mind map layout has been optimized for better readability.";
412
+ break;
413
+ }
414
+ default:
415
+ return {
416
+ toolName: y,
417
+ message: `Unknown action: ${t}`,
418
+ instructions: "Invalid action specified."
419
+ };
420
+ }
421
+ const r = i.nodes || [], f = i.connections || [], a = {
422
+ nodeCount: r.length,
423
+ connectionCount: f.length,
424
+ nodes: r.map((h) => ({ id: h.id, text: h.text }))
425
+ };
426
+ return {
427
+ toolName: y,
428
+ message: o,
429
+ title: i.title,
430
+ data: i,
431
+ jsonData: a,
432
+ instructions: s,
433
+ updating: t !== "create"
434
+ };
435
+ }, W = {
436
+ toolDefinition: O,
437
+ execute: U,
438
+ generatingMessage: "Creating mind map...",
439
+ isEnabled: () => !0,
440
+ systemPrompt: $
441
+ }, z = [
442
+ {
443
+ name: "AI Applications",
444
+ args: {
445
+ action: "create",
446
+ title: "AI Applications",
447
+ centralIdea: "Artificial Intelligence",
448
+ ideas: [
449
+ "Machine Learning",
450
+ "Natural Language Processing",
451
+ "Computer Vision",
452
+ "Robotics",
453
+ "Expert Systems",
454
+ "Speech Recognition"
455
+ ]
456
+ }
457
+ },
458
+ {
459
+ name: "Web Development",
460
+ args: {
461
+ action: "create",
462
+ title: "Modern Web Development",
463
+ centralIdea: "Web Development",
464
+ ideas: [
465
+ "Frontend",
466
+ "Backend",
467
+ "Database",
468
+ "DevOps",
469
+ "Security"
470
+ ]
471
+ }
472
+ },
473
+ {
474
+ name: "Project Planning",
475
+ args: {
476
+ action: "create",
477
+ title: "New Project",
478
+ centralIdea: "Project Goals",
479
+ ideas: [
480
+ "Research",
481
+ "Design",
482
+ "Implementation",
483
+ "Testing",
484
+ "Deployment",
485
+ "Maintenance"
486
+ ]
487
+ }
488
+ },
489
+ {
490
+ name: "Creative Writing",
491
+ args: {
492
+ action: "create",
493
+ title: "Story Ideas",
494
+ centralIdea: "Adventure Story",
495
+ ideas: [
496
+ "Main Character",
497
+ "Setting",
498
+ "Conflict",
499
+ "Plot Twists",
500
+ "Resolution"
501
+ ]
502
+ }
503
+ }
504
+ ];
505
+ export {
506
+ $ as SYSTEM_PROMPT,
507
+ O as TOOL_DEFINITION,
508
+ y as TOOL_NAME,
509
+ U as executeMindMap,
510
+ W as pluginCore,
511
+ z as samples
512
+ };