gthinking 1.2.1 → 2.1.1

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.
Files changed (271) hide show
  1. package/.eslintrc.js +34 -0
  2. package/ANALYSIS_SUMMARY.md +363 -0
  3. package/README.md +230 -245
  4. package/dist/analysis/analysis-engine.d.ts +63 -0
  5. package/dist/analysis/analysis-engine.d.ts.map +1 -0
  6. package/dist/analysis/analysis-engine.js +322 -0
  7. package/dist/analysis/analysis-engine.js.map +1 -0
  8. package/dist/core/config.d.ts +1419 -0
  9. package/dist/core/config.d.ts.map +1 -0
  10. package/dist/core/config.js +361 -0
  11. package/dist/core/config.js.map +1 -0
  12. package/dist/core/engine.d.ts +176 -0
  13. package/dist/core/engine.d.ts.map +1 -0
  14. package/dist/core/engine.js +604 -0
  15. package/dist/core/engine.js.map +1 -0
  16. package/dist/core/errors.d.ts +153 -0
  17. package/dist/core/errors.d.ts.map +1 -0
  18. package/dist/core/errors.js +287 -0
  19. package/dist/core/errors.js.map +1 -0
  20. package/dist/core/index.d.ts +7 -0
  21. package/dist/core/index.d.ts.map +1 -0
  22. package/dist/{types.js → core/index.js} +8 -4
  23. package/dist/core/index.js.map +1 -0
  24. package/dist/core/pipeline.d.ts +121 -0
  25. package/dist/core/pipeline.d.ts.map +1 -0
  26. package/dist/core/pipeline.js +289 -0
  27. package/dist/core/pipeline.js.map +1 -0
  28. package/dist/core/rate-limiter.d.ts +58 -0
  29. package/dist/core/rate-limiter.d.ts.map +1 -0
  30. package/dist/core/rate-limiter.js +133 -0
  31. package/dist/core/rate-limiter.js.map +1 -0
  32. package/dist/core/session-manager.d.ts +96 -0
  33. package/dist/core/session-manager.d.ts.map +1 -0
  34. package/dist/core/session-manager.js +223 -0
  35. package/dist/core/session-manager.js.map +1 -0
  36. package/dist/creativity/creativity-engine.d.ts +6 -0
  37. package/dist/creativity/creativity-engine.d.ts.map +1 -0
  38. package/dist/creativity/creativity-engine.js +17 -0
  39. package/dist/creativity/creativity-engine.js.map +1 -0
  40. package/dist/index.d.ts +24 -32
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +130 -104
  43. package/dist/index.js.map +1 -1
  44. package/dist/learning/learning-engine.d.ts +6 -0
  45. package/dist/learning/learning-engine.d.ts.map +1 -0
  46. package/dist/learning/learning-engine.js +17 -0
  47. package/dist/learning/learning-engine.js.map +1 -0
  48. package/dist/llm/index.d.ts +10 -0
  49. package/dist/llm/index.d.ts.map +1 -0
  50. package/dist/llm/index.js +26 -0
  51. package/dist/llm/index.js.map +1 -0
  52. package/dist/llm/llm-service.d.ts +109 -0
  53. package/dist/llm/llm-service.d.ts.map +1 -0
  54. package/dist/llm/llm-service.js +224 -0
  55. package/dist/llm/llm-service.js.map +1 -0
  56. package/dist/llm/providers/base.d.ts +85 -0
  57. package/dist/llm/providers/base.d.ts.map +1 -0
  58. package/dist/llm/providers/base.js +57 -0
  59. package/dist/llm/providers/base.js.map +1 -0
  60. package/dist/llm/providers/cli.d.ts +23 -0
  61. package/dist/llm/providers/cli.d.ts.map +1 -0
  62. package/dist/llm/providers/cli.js +158 -0
  63. package/dist/llm/providers/cli.js.map +1 -0
  64. package/dist/llm/providers/gemini.d.ts +30 -0
  65. package/dist/llm/providers/gemini.d.ts.map +1 -0
  66. package/dist/llm/providers/gemini.js +168 -0
  67. package/dist/llm/providers/gemini.js.map +1 -0
  68. package/dist/llm/sanitization.d.ts +50 -0
  69. package/dist/llm/sanitization.d.ts.map +1 -0
  70. package/dist/llm/sanitization.js +149 -0
  71. package/dist/llm/sanitization.js.map +1 -0
  72. package/dist/{server.d.ts.map → mcp/server.d.ts.map} +1 -1
  73. package/dist/mcp/server.js +108 -0
  74. package/dist/mcp/server.js.map +1 -0
  75. package/dist/planning/planning-engine.d.ts +6 -0
  76. package/dist/planning/planning-engine.d.ts.map +1 -0
  77. package/dist/planning/planning-engine.js +17 -0
  78. package/dist/planning/planning-engine.js.map +1 -0
  79. package/dist/reasoning/reasoning-engine.d.ts +6 -0
  80. package/dist/reasoning/reasoning-engine.d.ts.map +1 -0
  81. package/dist/reasoning/reasoning-engine.js +17 -0
  82. package/dist/reasoning/reasoning-engine.js.map +1 -0
  83. package/dist/search/search-engine.d.ts +99 -0
  84. package/dist/search/search-engine.d.ts.map +1 -0
  85. package/dist/search/search-engine.js +271 -0
  86. package/dist/search/search-engine.js.map +1 -0
  87. package/dist/synthesis/synthesis-engine.d.ts +6 -0
  88. package/dist/synthesis/synthesis-engine.d.ts.map +1 -0
  89. package/dist/synthesis/synthesis-engine.js +17 -0
  90. package/dist/synthesis/synthesis-engine.js.map +1 -0
  91. package/dist/types/analysis.d.ts +1534 -49
  92. package/dist/types/analysis.d.ts.map +1 -1
  93. package/dist/types/analysis.js +250 -0
  94. package/dist/types/analysis.js.map +1 -1
  95. package/dist/types/core.d.ts +257 -30
  96. package/dist/types/core.d.ts.map +1 -1
  97. package/dist/types/core.js +148 -18
  98. package/dist/types/core.js.map +1 -1
  99. package/dist/types/creativity.d.ts +2871 -56
  100. package/dist/types/creativity.d.ts.map +1 -1
  101. package/dist/types/creativity.js +195 -0
  102. package/dist/types/creativity.js.map +1 -1
  103. package/dist/types/index.d.ts +6 -2
  104. package/dist/types/index.d.ts.map +1 -1
  105. package/dist/types/index.js +17 -2
  106. package/dist/types/index.js.map +1 -1
  107. package/dist/types/learning.d.ts +851 -61
  108. package/dist/types/learning.d.ts.map +1 -1
  109. package/dist/types/learning.js +155 -0
  110. package/dist/types/learning.js.map +1 -1
  111. package/dist/types/planning.d.ts +2223 -71
  112. package/dist/types/planning.d.ts.map +1 -1
  113. package/dist/types/planning.js +190 -0
  114. package/dist/types/planning.js.map +1 -1
  115. package/dist/types/reasoning.d.ts +2209 -72
  116. package/dist/types/reasoning.d.ts.map +1 -1
  117. package/dist/types/reasoning.js +200 -1
  118. package/dist/types/reasoning.js.map +1 -1
  119. package/dist/types/search.d.ts +981 -53
  120. package/dist/types/search.d.ts.map +1 -1
  121. package/dist/types/search.js +137 -0
  122. package/dist/types/search.js.map +1 -1
  123. package/dist/types/synthesis.d.ts +583 -37
  124. package/dist/types/synthesis.d.ts.map +1 -1
  125. package/dist/types/synthesis.js +138 -0
  126. package/dist/types/synthesis.js.map +1 -1
  127. package/dist/utils/cache.d.ts +144 -0
  128. package/dist/utils/cache.d.ts.map +1 -0
  129. package/dist/utils/cache.js +288 -0
  130. package/dist/utils/cache.js.map +1 -0
  131. package/dist/utils/id-generator.d.ts +89 -0
  132. package/dist/utils/id-generator.d.ts.map +1 -0
  133. package/dist/utils/id-generator.js +132 -0
  134. package/dist/utils/id-generator.js.map +1 -0
  135. package/dist/utils/index.d.ts +11 -0
  136. package/dist/utils/index.d.ts.map +1 -0
  137. package/dist/utils/index.js +33 -0
  138. package/dist/utils/index.js.map +1 -0
  139. package/dist/utils/logger.d.ts +142 -0
  140. package/dist/utils/logger.d.ts.map +1 -0
  141. package/dist/utils/logger.js +248 -0
  142. package/dist/utils/logger.js.map +1 -0
  143. package/dist/utils/metrics.d.ts +149 -0
  144. package/dist/utils/metrics.d.ts.map +1 -0
  145. package/dist/utils/metrics.js +296 -0
  146. package/dist/utils/metrics.js.map +1 -0
  147. package/dist/utils/timer.d.ts +7 -0
  148. package/dist/utils/timer.d.ts.map +1 -0
  149. package/dist/utils/timer.js +17 -0
  150. package/dist/utils/timer.js.map +1 -0
  151. package/dist/utils/validation.d.ts +147 -0
  152. package/dist/utils/validation.d.ts.map +1 -0
  153. package/dist/utils/validation.js +275 -0
  154. package/dist/utils/validation.js.map +1 -0
  155. package/docs/API.md +411 -0
  156. package/docs/ARCHITECTURE.md +271 -0
  157. package/docs/CHANGELOG.md +283 -0
  158. package/jest.config.js +28 -0
  159. package/package.json +43 -30
  160. package/src/analysis/analysis-engine.ts +383 -0
  161. package/src/core/config.ts +406 -0
  162. package/src/core/engine.ts +785 -0
  163. package/src/core/errors.ts +349 -0
  164. package/src/core/index.ts +12 -0
  165. package/src/core/pipeline.ts +424 -0
  166. package/src/core/rate-limiter.ts +155 -0
  167. package/src/core/session-manager.ts +269 -0
  168. package/src/creativity/creativity-engine.ts +14 -0
  169. package/src/index.ts +178 -0
  170. package/src/learning/learning-engine.ts +14 -0
  171. package/src/llm/index.ts +10 -0
  172. package/src/llm/llm-service.ts +285 -0
  173. package/src/llm/providers/base.ts +146 -0
  174. package/src/llm/providers/cli.ts +186 -0
  175. package/src/llm/providers/gemini.ts +201 -0
  176. package/src/llm/sanitization.ts +178 -0
  177. package/src/mcp/server.ts +117 -0
  178. package/src/planning/planning-engine.ts +14 -0
  179. package/src/reasoning/reasoning-engine.ts +14 -0
  180. package/src/search/search-engine.ts +333 -0
  181. package/src/synthesis/synthesis-engine.ts +14 -0
  182. package/src/types/analysis.ts +337 -0
  183. package/src/types/core.ts +342 -0
  184. package/src/types/creativity.ts +268 -0
  185. package/src/types/index.ts +31 -0
  186. package/src/types/learning.ts +215 -0
  187. package/src/types/planning.ts +251 -0
  188. package/src/types/reasoning.ts +288 -0
  189. package/src/types/search.ts +192 -0
  190. package/src/types/synthesis.ts +187 -0
  191. package/src/utils/cache.ts +363 -0
  192. package/src/utils/id-generator.ts +135 -0
  193. package/src/utils/index.ts +22 -0
  194. package/src/utils/logger.ts +290 -0
  195. package/src/utils/metrics.ts +380 -0
  196. package/src/utils/timer.ts +15 -0
  197. package/src/utils/validation.ts +297 -0
  198. package/tests/setup.ts +22 -0
  199. package/tests/unit/cache.test.ts +189 -0
  200. package/tests/unit/engine.test.ts +179 -0
  201. package/tests/unit/validation.test.ts +218 -0
  202. package/tsconfig.json +17 -12
  203. package/GEMINI.md +0 -68
  204. package/analysis.ts +0 -1063
  205. package/creativity.ts +0 -1055
  206. package/dist/analysis.d.ts +0 -54
  207. package/dist/analysis.d.ts.map +0 -1
  208. package/dist/analysis.js +0 -866
  209. package/dist/analysis.js.map +0 -1
  210. package/dist/creativity.d.ts +0 -81
  211. package/dist/creativity.d.ts.map +0 -1
  212. package/dist/creativity.js +0 -828
  213. package/dist/creativity.js.map +0 -1
  214. package/dist/engine.d.ts +0 -90
  215. package/dist/engine.d.ts.map +0 -1
  216. package/dist/engine.js +0 -677
  217. package/dist/engine.js.map +0 -1
  218. package/dist/examples.d.ts +0 -7
  219. package/dist/examples.d.ts.map +0 -1
  220. package/dist/examples.js +0 -506
  221. package/dist/examples.js.map +0 -1
  222. package/dist/learning.d.ts +0 -72
  223. package/dist/learning.d.ts.map +0 -1
  224. package/dist/learning.js +0 -615
  225. package/dist/learning.js.map +0 -1
  226. package/dist/llm-service.d.ts +0 -21
  227. package/dist/llm-service.d.ts.map +0 -1
  228. package/dist/llm-service.js +0 -100
  229. package/dist/llm-service.js.map +0 -1
  230. package/dist/planning.d.ts +0 -58
  231. package/dist/planning.d.ts.map +0 -1
  232. package/dist/planning.js +0 -824
  233. package/dist/planning.js.map +0 -1
  234. package/dist/reasoning.d.ts +0 -73
  235. package/dist/reasoning.d.ts.map +0 -1
  236. package/dist/reasoning.js +0 -845
  237. package/dist/reasoning.js.map +0 -1
  238. package/dist/search-discovery.d.ts +0 -73
  239. package/dist/search-discovery.d.ts.map +0 -1
  240. package/dist/search-discovery.js +0 -548
  241. package/dist/search-discovery.js.map +0 -1
  242. package/dist/server.js +0 -113
  243. package/dist/server.js.map +0 -1
  244. package/dist/types/engine.d.ts +0 -55
  245. package/dist/types/engine.d.ts.map +0 -1
  246. package/dist/types/engine.js +0 -3
  247. package/dist/types/engine.js.map +0 -1
  248. package/dist/types.d.ts +0 -6
  249. package/dist/types.d.ts.map +0 -1
  250. package/dist/types.js.map +0 -1
  251. package/engine.ts +0 -947
  252. package/examples.ts +0 -717
  253. package/index.ts +0 -106
  254. package/learning.ts +0 -779
  255. package/llm-service.ts +0 -120
  256. package/planning.ts +0 -1028
  257. package/reasoning.ts +0 -1079
  258. package/search-discovery.ts +0 -700
  259. package/server.ts +0 -115
  260. package/types/analysis.ts +0 -69
  261. package/types/core.ts +0 -90
  262. package/types/creativity.ts +0 -72
  263. package/types/engine.ts +0 -60
  264. package/types/index.ts +0 -9
  265. package/types/learning.ts +0 -69
  266. package/types/planning.ts +0 -85
  267. package/types/reasoning.ts +0 -92
  268. package/types/search.ts +0 -58
  269. package/types/synthesis.ts +0 -42
  270. package/types.ts +0 -6
  271. /package/dist/{server.d.ts → mcp/server.d.ts} +0 -0
package/creativity.ts DELETED
@@ -1,1055 +0,0 @@
1
- /**
2
- * Creativity Module
3
- * Out-of-the-box thinking, idea generation, and concept connection
4
- */
5
-
6
- import {
7
- CreativeSession,
8
- CreativityTechnique,
9
- Idea,
10
- Connection,
11
- DivergentPhase,
12
- ConvergentPhase,
13
- OutOfBoxThinking,
14
- ReframedProblem,
15
- ThinkingEvent,
16
- ThinkingError,
17
- ThinkingStage
18
- } from './types';
19
- import { EventEmitter } from 'events';
20
- import { llmService } from './llm-service';
21
-
22
- // ============================================================================
23
- // BRAINSTORMING ENGINE
24
- // ============================================================================
25
-
26
- class BrainstormingEngine {
27
- private ideaSeeds: Map<string, string[]> = new Map([
28
- ['technology', ['AI', 'blockchain', 'IoT', 'cloud', 'quantum', 'biotech', 'nanotech']],
29
- ['business', ['subscription', 'freemium', 'marketplace', 'platform', 'ecosystem']],
30
- ['social', ['community', 'collaboration', 'sharing', 'crowdsourcing', 'network']],
31
- ['design', ['minimalist', 'responsive', 'adaptive', 'personalized', 'immersive']]
32
- ]);
33
-
34
- generateIdeas(prompt: string, count: number = 10): Idea[] {
35
- const ideas: Idea[] = [];
36
- const domains = this.identifyDomains(prompt);
37
-
38
- // Generate ideas using different approaches
39
- for (let i = 0; i < count; i++) {
40
- const technique = this.selectTechnique(i);
41
- const idea = this.createIdea(prompt, technique, domains, i);
42
- ideas.push(idea);
43
- }
44
-
45
- return ideas;
46
- }
47
-
48
- private identifyDomains(prompt: string): string[] {
49
- const domains: string[] = [];
50
- const promptLower = prompt.toLowerCase();
51
-
52
- this.ideaSeeds.forEach((_, domain) => {
53
- if (promptLower.includes(domain)) {
54
- domains.push(domain);
55
- }
56
- });
57
-
58
- return domains.length > 0 ? domains : ['general'];
59
- }
60
-
61
- private selectTechnique(index: number): CreativityTechnique {
62
- const techniques: CreativityTechnique[] = [
63
- 'brainstorming',
64
- 'analogy',
65
- 'reverse_thinking',
66
- 'random_stimulus',
67
- 'lateral_thinking'
68
- ];
69
- return techniques[index % techniques.length];
70
- }
71
-
72
- private createIdea(
73
- prompt: string,
74
- technique: CreativityTechnique,
75
- domains: string[],
76
- index: number
77
- ): Idea {
78
- const content = this.generateIdeaContent(prompt, technique, domains, index);
79
-
80
- return {
81
- id: `idea_${Date.now()}_${index}`,
82
- content,
83
- technique,
84
- novelty: this.calculateNovelity(content),
85
- feasibility: this.calculateFeasibility(content),
86
- impact: this.calculateImpact(content),
87
- relatedIdeas: [],
88
- tags: this.extractTags(content),
89
- generatedAt: new Date()
90
- };
91
- }
92
-
93
- private generateIdeaContent(
94
- prompt: string,
95
- technique: CreativityTechnique,
96
- domains: string[],
97
- index: number
98
- ): string {
99
- switch (technique) {
100
- case 'brainstorming':
101
- return this.brainstorm(prompt, domains, index);
102
- case 'analogy':
103
- return this.useAnalogy(prompt, domains, index);
104
- case 'reverse_thinking':
105
- return this.reverseThink(prompt);
106
- case 'random_stimulus':
107
- return this.randomStimulus(prompt, domains);
108
- case 'lateral_thinking':
109
- return this.lateralThink(prompt, index);
110
- default:
111
- return `Idea ${index + 1}: ${prompt}`;
112
- }
113
- }
114
-
115
- private brainstorm(prompt: string, domains: string[], index: number): string {
116
- const domain = domains[index % domains.length];
117
- const seeds = this.ideaSeeds.get(domain) || ['innovation'];
118
- const seed = seeds[index % seeds.length];
119
-
120
- return `Combine ${prompt} with ${seed} to create a ${domain} solution`;
121
- }
122
-
123
- private useAnalogy(prompt: string, domains: string[], index: number): string {
124
- const analogies = [
125
- 'like a nervous system for information flow',
126
- 'like an immune system for security',
127
- 'like an ecosystem for sustainability',
128
- 'like a language for communication',
129
- 'like a market for resource allocation'
130
- ];
131
-
132
- return `Approach ${prompt} ${analogies[index % analogies.length]}`;
133
- }
134
-
135
- private reverseThink(prompt: string): string {
136
- return `Instead of ${prompt}, what if we did the opposite? ` +
137
- `Consider: How could we achieve the inverse outcome?`;
138
- }
139
-
140
- private randomStimulus(prompt: string, domains: string[]): string {
141
- const stimuli = ['nature', 'art', 'music', 'sports', 'cooking', 'architecture'];
142
- const stimulus = stimuli[Math.floor(Math.random() * stimuli.length)];
143
-
144
- return `Apply principles from ${stimulus} to ${prompt}`;
145
- }
146
-
147
- private lateralThink(prompt: string, index: number): string {
148
- const perspectives = [
149
- 'from a child\'s perspective',
150
- 'from a future perspective (10 years ahead)',
151
- 'from a resource-constrained perspective',
152
- 'from a luxury perspective',
153
- 'from a minimalist perspective'
154
- ];
155
-
156
- return `View ${prompt} ${perspectives[index % perspectives.length]}`;
157
- }
158
-
159
- private calculateNovelity(content: string): number {
160
- // Higher novelty for more unique combinations
161
- const uniqueTerms = new Set(content.toLowerCase().split(/\s+/)).size;
162
- const totalTerms = content.split(/\s+/).length;
163
- return Math.min(0.95, uniqueTerms / totalTerms + 0.3);
164
- }
165
-
166
- private calculateFeasibility(content: string): number {
167
- // Lower feasibility for very abstract ideas
168
- const abstractTerms = ['quantum', 'neural', 'blockchain', 'revolutionary', 'paradigm'];
169
- const abstractCount = abstractTerms.filter(term =>
170
- content.toLowerCase().includes(term)
171
- ).length;
172
-
173
- return Math.max(0.3, 0.9 - abstractCount * 0.1);
174
- }
175
-
176
- private calculateImpact(content: string): number {
177
- // Higher impact for ideas addressing broad audiences or major problems
178
- const impactIndicators = ['global', 'scalable', 'transform', 'revolutionary', 'fundamental'];
179
- const matches = impactIndicators.filter(ind =>
180
- content.toLowerCase().includes(ind)
181
- ).length;
182
-
183
- return Math.min(0.95, 0.5 + matches * 0.1);
184
- }
185
-
186
- private extractTags(content: string): string[] {
187
- return content
188
- .toLowerCase()
189
- .match(/\b\w{5,}\b/g)
190
- ?.filter((w, i, arr) => arr.indexOf(w) === i)
191
- ?.slice(0, 5) || [];
192
- }
193
- }
194
-
195
- // ============================================================================
196
- // MIND MAPPING ENGINE
197
- // ============================================================================
198
-
199
- interface MindMapNode {
200
- id: string;
201
- label: string;
202
- children: MindMapNode[];
203
- connections: string[];
204
- }
205
-
206
- class MindMappingEngine {
207
- createMindMap(centerConcept: string, depth: number = 3): MindMapNode {
208
- const root: MindMapNode = {
209
- id: 'root',
210
- label: centerConcept,
211
- children: [],
212
- connections: []
213
- };
214
-
215
- this.expandNode(root, depth, 0);
216
- return root;
217
- }
218
-
219
- private expandNode(node: MindMapNode, maxDepth: number, currentDepth: number): void {
220
- if (currentDepth >= maxDepth) return;
221
-
222
- const branches = this.generateBranches(node.label, currentDepth);
223
-
224
- branches.forEach(branchLabel => {
225
- const child: MindMapNode = {
226
- id: `node_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`,
227
- label: branchLabel,
228
- children: [],
229
- connections: []
230
- };
231
-
232
- node.children.push(child);
233
- this.expandNode(child, maxDepth, currentDepth + 1);
234
- });
235
- }
236
-
237
- private generateBranches(concept: string, depth: number): string[] {
238
- const branchTypes: Record<number, string[][]> = {
239
- 0: [['What', 'Why', 'How', 'When', 'Where']],
240
- 1: [['Components', 'Features', 'Benefits', 'Challenges']],
241
- 2: [['Examples', 'Alternatives', 'Applications', 'Implications']]
242
- };
243
-
244
- const branches = branchTypes[depth] || [['Details', 'Related', 'Future']];
245
- const selectedBranch = branches[0];
246
-
247
- return selectedBranch.map(b => `${b} of ${concept}`);
248
- }
249
-
250
- findConnections(node1: MindMapNode, node2: MindMapNode): string[] {
251
- const connections: string[] = [];
252
- const concepts1 = this.extractAllConcepts(node1);
253
- const concepts2 = this.extractAllConcepts(node2);
254
-
255
- concepts1.forEach(c1 => {
256
- concepts2.forEach(c2 => {
257
- const similarity = this.calculateConceptSimilarity(c1, c2);
258
- if (similarity > 0.5) {
259
- connections.push(`Connection: ${c1} ↔ ${c2}`);
260
- }
261
- });
262
- });
263
-
264
- return connections;
265
- }
266
-
267
- private extractAllConcepts(node: MindMapNode): string[] {
268
- const concepts = [node.label];
269
- node.children.forEach(child => {
270
- concepts.push(...this.extractAllConcepts(child));
271
- });
272
- return concepts;
273
- }
274
-
275
- private calculateConceptSimilarity(c1: string, c2: string): number {
276
- const words1 = c1.toLowerCase().split(/\s+/);
277
- const words2 = c2.toLowerCase().split(/\s+/);
278
-
279
- const intersection = words1.filter(w => words2.includes(w));
280
- return intersection.length / Math.max(words1.length, words2.length);
281
- }
282
- }
283
-
284
- // ============================================================================
285
- // SCAMPER TECHNIQUE
286
- // ============================================================================
287
-
288
- interface ScamperPrompt {
289
- letter: string;
290
- action: string;
291
- prompt: string;
292
- }
293
-
294
- class ScamperEngine {
295
- private scamperPrompts: ScamperPrompt[] = [
296
- { letter: 'S', action: 'Substitute', prompt: 'What can be substituted?' },
297
- { letter: 'C', action: 'Combine', prompt: 'What can be combined?' },
298
- { letter: 'A', action: 'Adapt', prompt: 'What can be adapted?' },
299
- { letter: 'M', action: 'Modify', prompt: 'What can be modified?' },
300
- { letter: 'P', action: 'Put to other uses', prompt: 'What other uses are possible?' },
301
- { letter: 'E', action: 'Eliminate', prompt: 'What can be eliminated?' },
302
- { letter: 'R', action: 'Reverse/Rearrange', prompt: 'What can be reversed or rearranged?' }
303
- ];
304
-
305
- apply(problem: string): Array<{ technique: string; question: string; idea: string }> {
306
- return this.scamperPrompts.map(prompt => ({
307
- technique: `${prompt.letter} - ${prompt.action}`,
308
- question: prompt.prompt,
309
- idea: this.generateScamperIdea(problem, prompt)
310
- }));
311
- }
312
-
313
- private generateScamperIdea(problem: string, prompt: ScamperPrompt): string {
314
- const ideaTemplates: Record<string, string[]> = {
315
- 'Substitute': [
316
- `Replace a key component of ${problem} with something unexpected`,
317
- `Use alternative materials or methods for ${problem}`
318
- ],
319
- 'Combine': [
320
- `Merge ${problem} with a completely different concept`,
321
- `Integrate multiple versions of ${problem}`
322
- ],
323
- 'Adapt': [
324
- `Apply ${problem} in a different context`,
325
- `Borrow ideas from other fields for ${problem}`
326
- ],
327
- 'Modify': [
328
- `Change the scale or magnitude of ${problem}`,
329
- `Alter the attributes of ${problem}`
330
- ],
331
- 'Put to other uses': [
332
- `How else could ${problem} be used?`,
333
- `Who else could benefit from ${problem}?`
334
- ],
335
- 'Eliminate': [
336
- `Remove unnecessary parts of ${problem}`,
337
- `Simplify ${problem} to its essence`
338
- ],
339
- 'Reverse/Rearrange': [
340
- `Do the opposite of ${problem}`,
341
- `Change the order of steps in ${problem}`
342
- ]
343
- };
344
-
345
- const templates = ideaTemplates[prompt.action] || ['Consider a new approach'];
346
- return templates[Math.floor(Math.random() * templates.length)];
347
- }
348
- }
349
-
350
- // ============================================================================
351
- // SIX THINKING HATS
352
- // ============================================================================
353
-
354
- interface ThinkingHat {
355
- color: string;
356
- perspective: string;
357
- focus: string;
358
- }
359
-
360
- class SixThinkingHatsEngine {
361
- private hats: ThinkingHat[] = [
362
- { color: 'White', perspective: 'Objective', focus: 'facts and data' },
363
- { color: 'Red', perspective: 'Emotional', focus: 'feelings and intuition' },
364
- { color: 'Black', perspective: 'Critical', focus: 'risks and problems' },
365
- { color: 'Yellow', perspective: 'Optimistic', focus: 'benefits and value' },
366
- { color: 'Green', perspective: 'Creative', focus: 'new ideas and alternatives' },
367
- { color: 'Blue', perspective: 'Process', focus: 'overview and control' }
368
- ];
369
-
370
- analyze(topic: string): Array<{ hat: string; perspective: string; insights: string[] }> {
371
- return this.hats.map(hat => ({
372
- hat: hat.color,
373
- perspective: hat.perspective,
374
- insights: this.generateInsights(topic, hat)
375
- }));
376
- }
377
-
378
- private generateInsights(topic: string, hat: ThinkingHat): string[] {
379
- const insights: string[] = [];
380
-
381
- switch (hat.color) {
382
- case 'White':
383
- insights.push(
384
- `What data do we have about ${topic}?`,
385
- `What information is missing about ${topic}?`,
386
- `What are the verifiable facts?`
387
- );
388
- break;
389
- case 'Red':
390
- insights.push(
391
- `What is my gut feeling about ${topic}?`,
392
- `What emotions does ${topic} evoke?`,
393
- `What is my intuitive reaction?`
394
- );
395
- break;
396
- case 'Black':
397
- insights.push(
398
- `What are the risks with ${topic}?`,
399
- `What could go wrong with ${topic}?`,
400
- `What are the potential problems?`
401
- );
402
- break;
403
- case 'Yellow':
404
- insights.push(
405
- `What are the benefits of ${topic}?`,
406
- `What value does ${topic} provide?`,
407
- `What are the opportunities?`
408
- );
409
- break;
410
- case 'Green':
411
- insights.push(
412
- `What creative alternatives exist for ${topic}?`,
413
- `What new ideas can we generate?`,
414
- `How can we think differently about this?`
415
- );
416
- break;
417
- case 'Blue':
418
- insights.push(
419
- `What is our process for addressing ${topic}?`,
420
- `How should we organize our thinking?`,
421
- `What is the big picture?`
422
- );
423
- break;
424
- }
425
-
426
- return insights;
427
- }
428
- }
429
-
430
- // ============================================================================
431
- // CONCEPT CONNECTOR
432
- // ============================================================================
433
-
434
- class ConceptConnector {
435
- private conceptDatabase: Map<string, string[]> = new Map([
436
- ['innovation', ['change', 'progress', 'novelty', 'improvement', 'disruption']],
437
- ['technology', ['tools', 'systems', 'automation', 'digital', 'advancement']],
438
- ['design', ['aesthetics', 'function', 'user', 'experience', 'form']],
439
- ['business', ['value', 'profit', 'market', 'customers', 'growth']],
440
- ['sustainability', ['environment', 'future', 'resources', 'balance', 'responsibility']]
441
- ]);
442
-
443
- findConnections(concepts: string[]): Connection[] {
444
- const connections: Connection[] = [];
445
-
446
- for (let i = 0; i < concepts.length; i++) {
447
- for (let j = i + 1; j < concepts.length; j++) {
448
- const connection = this.analyzeConnection(concepts[i], concepts[j]);
449
- if (connection.strength > 0.3) {
450
- connections.push(connection);
451
- }
452
- }
453
- }
454
-
455
- return connections.sort((a, b) => b.strength - a.strength);
456
- }
457
-
458
- private analyzeConnection(concept1: string, concept2: string): Connection {
459
- const attributes1 = this.getConceptAttributes(concept1);
460
- const attributes2 = this.getConceptAttributes(concept2);
461
-
462
- // Find common attributes
463
- const common = attributes1.filter(a => attributes2.includes(a));
464
- const all = [...new Set([...attributes1, ...attributes2])];
465
-
466
- const strength = common.length / all.length;
467
-
468
- // Determine connection type
469
- let connectionType: Connection['connectionType'] = 'similarity';
470
-
471
- if (strength > 0.7) {
472
- connectionType = 'similarity';
473
- } else if (strength < 0.3) {
474
- connectionType = 'contrast';
475
- } else {
476
- connectionType = 'combination';
477
- }
478
-
479
- return {
480
- id: `conn_${Date.now()}_${Math.random().toString(36).substr(2, 5)}`,
481
- from: concept1,
482
- to: concept2,
483
- connectionType,
484
- strength,
485
- insight: this.generateInsight(concept1, concept2, common, connectionType)
486
- };
487
- }
488
-
489
- private getConceptAttributes(concept: string): string[] {
490
- const lowerConcept = concept.toLowerCase();
491
-
492
- for (const [key, attributes] of this.conceptDatabase.entries()) {
493
- if (lowerConcept.includes(key) || key.includes(lowerConcept)) {
494
- return attributes;
495
- }
496
- }
497
-
498
- // Generate attributes from concept itself
499
- return concept.toLowerCase().split(/\s+/).filter(w => w.length > 3);
500
- }
501
-
502
- private generateInsight(
503
- c1: string,
504
- c2: string,
505
- common: string[],
506
- type: Connection['connectionType']
507
- ): string {
508
- switch (type) {
509
- case 'similarity':
510
- return `${c1} and ${c2} share ${common.length > 0 ? `common ground in ${common.join(', ')}` : 'fundamental similarities'}`;
511
- case 'contrast':
512
- return `${c1} and ${c2} represent different approaches that could complement each other`;
513
- case 'combination':
514
- return `Combining ${c1} with ${c2} could create something unique`;
515
- default:
516
- return `Interesting relationship between ${c1} and ${c2}`;
517
- }
518
- }
519
-
520
- generateNovelCombinations(concepts: string[], count: number = 3): string[] {
521
- const combinations: string[] = [];
522
-
523
- for (let i = 0; i < count; i++) {
524
- const c1 = concepts[Math.floor(Math.random() * concepts.length)];
525
- const c2 = concepts[Math.floor(Math.random() * concepts.length)];
526
-
527
- if (c1 !== c2) {
528
- combinations.push(`Combine ${c1} with ${c2} to create: ${this.generateCombinationName(c1, c2)}`);
529
- }
530
- }
531
-
532
- return combinations;
533
- }
534
-
535
- private generateCombinationName(c1: string, c2: string): string {
536
- const prefixes = ['Smart', 'Dynamic', 'Integrated', 'Adaptive', 'Holistic'];
537
- const prefix = prefixes[Math.floor(Math.random() * prefixes.length)];
538
- return `${prefix} ${c1.split(' ')[0]}-${c2.split(' ')[0]} Solution`;
539
- }
540
- }
541
-
542
- // ============================================================================
543
- // OUT-OF-BOX THINKING ENGINE
544
- // ============================================================================
545
-
546
- class OutOfBoxEngine {
547
- private perspectives = [
548
- 'Beginner\'s mind - forget what you know',
549
- 'Child\'s perspective - simple and curious',
550
- 'Alien perspective - no assumptions',
551
- 'Future perspective - 50 years ahead',
552
- 'Resource-constrained - extreme limitations',
553
- 'Opposite approach - do the reverse',
554
- 'Nature-inspired - biomimicry',
555
- 'Artistic perspective - beauty and emotion'
556
- ];
557
-
558
- reframe(problem: string): OutOfBoxThinking {
559
- const reframedProblems: ReframedProblem[] = [];
560
-
561
- this.perspectives.forEach((perspective, index) => {
562
- const reframed = this.reframeFromPerspective(problem, perspective);
563
- reframedProblems.push({
564
- id: `reframe_${Date.now()}_${index}`,
565
- perspective,
566
- reframedStatement: reframed.statement,
567
- assumptionsChallenged: reframed.assumptions,
568
- newPossibilities: reframed.possibilities
569
- });
570
- });
571
-
572
- const unconventionalApproaches = this.generateUnconventionalApproaches(problem);
573
- const breakthroughPotential = this.calculateBreakthroughPotential(reframedProblems);
574
-
575
- return {
576
- id: `ootb_${Date.now()}`,
577
- originalProblem: problem,
578
- reframedProblems,
579
- unconventionalApproaches,
580
- breakthroughPotential
581
- };
582
- }
583
-
584
- private reframeFromPerspective(
585
- problem: string,
586
- perspective: string
587
- ): { statement: string; assumptions: string[]; possibilities: string[] } {
588
- const reframes: Record<string, { statement: string; assumptions: string[]; possibilities: string[] }> = {
589
- 'Beginner\'s mind': {
590
- statement: `If you knew nothing about this, how would you approach: ${problem}?`,
591
- assumptions: ['Expert knowledge is necessary', 'Current methods are optimal'],
592
- possibilities: ['Fresh approaches', 'Questioning fundamentals']
593
- },
594
- 'Child\'s perspective': {
595
- statement: `How would a 5-year-old solve: ${problem}?`,
596
- assumptions: ['Complexity is required', 'Adult approaches are better'],
597
- possibilities: ['Simple solutions', 'Playful approaches']
598
- },
599
- 'Alien perspective': {
600
- statement: `How would beings from another planet view: ${problem}?`,
601
- assumptions: ['Human perspective is universal', 'Our constraints are absolute'],
602
- possibilities: ['Radically different approaches', 'Question all assumptions']
603
- },
604
- 'Future perspective': {
605
- statement: `How will people in 2074 solve: ${problem}?`,
606
- assumptions: ['Current technology limits', 'Present constraints are permanent'],
607
- possibilities: ['Future technologies', 'Long-term thinking']
608
- },
609
- 'Resource-constrained': {
610
- statement: `How would you solve ${problem} with 1% of current resources?`,
611
- assumptions: ['Adequate resources are needed', 'Scale is important'],
612
- possibilities: ['Minimalist solutions', 'Extreme efficiency']
613
- },
614
- 'Opposite approach': {
615
- statement: `What if the solution to ${problem} is the exact opposite of what we think?`,
616
- assumptions: ['Our direction is correct', 'Conventional wisdom applies'],
617
- possibilities: ['Counter-intuitive solutions', 'Paradigm shifts']
618
- },
619
- 'Nature-inspired': {
620
- statement: `How does nature solve problems similar to ${problem}?`,
621
- assumptions: ['Human-designed solutions are superior', 'Technology is the answer'],
622
- possibilities: ['Biomimicry', 'Natural patterns']
623
- },
624
- 'Artistic perspective': {
625
- statement: `How would an artist approach ${problem}?`,
626
- assumptions: ['Technical solutions only', 'Function over form'],
627
- possibilities: ['Aesthetic solutions', 'Emotional design']
628
- }
629
- };
630
-
631
- return reframes[perspective] || {
632
- statement: `Reframe: ${problem}`,
633
- assumptions: ['Standard approach'],
634
- possibilities: ['Alternative approaches']
635
- };
636
- }
637
-
638
- private generateUnconventionalApproaches(problem: string): string[] {
639
- return [
640
- `What if ${problem} is actually an opportunity in disguise?`,
641
- `How can ${problem} be made worse, then reverse that?`,
642
- `What would make ${problem} solve itself?`,
643
- `Who benefits from ${problem} existing?`,
644
- `What if the problem and solution are the same thing?`
645
- ];
646
- }
647
-
648
- private calculateBreakthroughPotential(reframedProblems: ReframedProblem[]): number {
649
- const totalAssumptions = reframedProblems.reduce(
650
- (sum, rp) => sum + rp.assumptionsChallenged.length,
651
- 0
652
- );
653
- const totalPossibilities = reframedProblems.reduce(
654
- (sum, rp) => sum + rp.newPossibilities.length,
655
- 0
656
- );
657
-
658
- return Math.min(0.95, (totalAssumptions * 0.05 + totalPossibilities * 0.1));
659
- }
660
- }
661
-
662
- // ============================================================================
663
- // MAIN CREATIVITY ENGINE
664
- // ============================================================================
665
-
666
- export class CreativityEngine extends EventEmitter {
667
- private brainstormingEngine: BrainstormingEngine;
668
- private mindMappingEngine: MindMappingEngine;
669
- private scamperEngine: ScamperEngine;
670
- private sixHatsEngine: SixThinkingHatsEngine;
671
- private conceptConnector: ConceptConnector;
672
- private outOfBoxEngine: OutOfBoxEngine;
673
- private sessions: Map<string, CreativeSession> = new Map();
674
-
675
- constructor() {
676
- super();
677
- this.brainstormingEngine = new BrainstormingEngine();
678
- this.mindMappingEngine = new MindMappingEngine();
679
- this.scamperEngine = new ScamperEngine();
680
- this.sixHatsEngine = new SixThinkingHatsEngine();
681
- this.conceptConnector = new ConceptConnector();
682
- this.outOfBoxEngine = new OutOfBoxEngine();
683
- }
684
-
685
- /**
686
- * Start a creative session
687
- */
688
- async startSession(
689
- prompt: string,
690
- options: {
691
- techniques?: CreativityTechnique[];
692
- ideaCount?: number;
693
- duration?: number;
694
- } = {}
695
- ): Promise<CreativeSession> {
696
- const {
697
- techniques = ['brainstorming', 'analogy', 'scamper'],
698
- ideaCount = 15,
699
- duration = 30
700
- } = options;
701
-
702
- const sessionId = this.generateId();
703
- const startTime = Date.now();
704
-
705
- this.emit('creativity_start', {
706
- id: sessionId,
707
- stage: ThinkingStage.CREATIVITY,
708
- timestamp: new Date(),
709
- data: { prompt, techniques }
710
- } as ThinkingEvent);
711
-
712
- // Generate ideas
713
- let ideas: Idea[] = [];
714
-
715
- try {
716
- ideas = await this.generateIdeasWithLLM(prompt, techniques, ideaCount);
717
- } catch (error) {
718
- console.warn('LLM creativity failed, falling back to internal engine', error);
719
- }
720
-
721
- if (ideas.length === 0) {
722
- techniques.forEach(technique => {
723
- const techniqueIdeas = this.generateIdeasWithTechnique(prompt, technique, Math.ceil(ideaCount / techniques.length));
724
- ideas.push(...techniqueIdeas);
725
- });
726
- }
727
-
728
- // Find connections between ideas
729
- const connections = this.findConnections(ideas);
730
-
731
- // Divergent phase
732
- const divergentPhase: DivergentPhase = {
733
- startTime: new Date(startTime),
734
- endTime: new Date(),
735
- ideaCount: ideas.length,
736
- explorationBreadth: techniques.length
737
- };
738
-
739
- // Convergent phase - select best ideas
740
- const selectedIdeas = this.selectBestIdeas(ideas, 5);
741
- const synthesis = this.synthesizeIdeas(selectedIdeas);
742
-
743
- const convergentPhase: ConvergentPhase = {
744
- startTime: new Date(),
745
- endTime: new Date(),
746
- selectedIdeas: selectedIdeas.map(i => i.id),
747
- synthesis,
748
- actionItems: this.generateActionItems(selectedIdeas)
749
- };
750
-
751
- const session: CreativeSession = {
752
- id: sessionId,
753
- prompt,
754
- techniques,
755
- ideas,
756
- connections,
757
- sessionDuration: Date.now() - startTime,
758
- divergentPhase,
759
- convergentPhase
760
- };
761
-
762
- this.sessions.set(sessionId, session);
763
-
764
- this.emit('creativity_complete', {
765
- id: sessionId,
766
- stage: ThinkingStage.CREATIVITY,
767
- timestamp: new Date(),
768
- data: {
769
- ideaCount: ideas.length,
770
- connectionCount: connections.length,
771
- topIdeas: selectedIdeas.map(i => i.content.substring(0, 50))
772
- }
773
- } as ThinkingEvent);
774
-
775
- return session;
776
- }
777
-
778
- private async generateIdeasWithLLM(prompt: string, techniques: CreativityTechnique[], count: number): Promise<Idea[]> {
779
- const promptText = `
780
- You are a creativity engine.
781
- Prompt: "${prompt}"
782
- Techniques to use: ${techniques.join(', ')}
783
- Target count: ${count} ideas
784
-
785
- Return strictly JSON with structure:
786
- {
787
- "ideas": [
788
- {
789
- "content": "string (the idea description)",
790
- "technique": "string (which technique was used)",
791
- "novelty": number (0-1),
792
- "feasibility": number (0-1),
793
- "impact": number (0-1),
794
- "tags": ["string"]
795
- }
796
- ]
797
- }
798
- `;
799
-
800
- const response = await llmService.generateText({ prompt: promptText });
801
- const jsonMatch = response.match(/\{[\s\S]*\}/);
802
-
803
- if (jsonMatch) {
804
- const result = JSON.parse(jsonMatch[0]);
805
- if (Array.isArray(result.ideas)) {
806
- return result.ideas.map((item: any, index: number) => ({
807
- id: `idea_llm_${Date.now()}_${index}`,
808
- content: item.content,
809
- technique: item.technique as CreativityTechnique,
810
- novelty: item.novelty || 0.7,
811
- feasibility: item.feasibility || 0.7,
812
- impact: item.impact || 0.7,
813
- relatedIdeas: [],
814
- tags: item.tags || [],
815
- generatedAt: new Date()
816
- }));
817
- }
818
- }
819
- return [];
820
- }
821
-
822
- /**
823
- * Generate ideas using a specific technique
824
- */
825
- private generateIdeasWithTechnique(
826
- prompt: string,
827
- technique: CreativityTechnique,
828
- count: number
829
- ): Idea[] {
830
- switch (technique) {
831
- case 'brainstorming':
832
- case 'analogy':
833
- case 'reverse_thinking':
834
- case 'random_stimulus':
835
- case 'lateral_thinking':
836
- return this.brainstormingEngine.generateIdeas(prompt, count);
837
- case 'scamper':
838
- return this.applyScamperInternal(prompt);
839
- case 'mind_mapping':
840
- return this.generateFromMindMap(prompt, count);
841
- case 'six_thinking_hats':
842
- return this.applySixHatsInternal(prompt);
843
- default:
844
- return this.brainstormingEngine.generateIdeas(prompt, count);
845
- }
846
- }
847
-
848
- private applyScamperInternal(prompt: string): Idea[] {
849
- const scamperResults = this.scamperEngine.apply(prompt);
850
- return scamperResults.map((result, index) => ({
851
- id: `idea_scamper_${Date.now()}_${index}`,
852
- content: `${result.technique}: ${result.idea}`,
853
- technique: 'scamper',
854
- novelty: 0.7,
855
- feasibility: 0.6,
856
- impact: 0.65,
857
- relatedIdeas: [],
858
- tags: ['scamper', result.technique.toLowerCase()],
859
- generatedAt: new Date()
860
- }));
861
- }
862
-
863
- private generateFromMindMap(prompt: string, count: number): Idea[] {
864
- const mindMap = this.mindMappingEngine.createMindMap(prompt, 2);
865
- const ideas: Idea[] = [];
866
-
867
- const extractIdeas = (node: any, depth: number) => {
868
- if (ideas.length >= count) return;
869
-
870
- ideas.push({
871
- id: `idea_mindmap_${Date.now()}_${ideas.length}`,
872
- content: `Explore: ${node.label}`,
873
- technique: 'mind_mapping',
874
- novelty: 0.6 + depth * 0.1,
875
- feasibility: 0.7,
876
- impact: 0.6,
877
- relatedIdeas: [],
878
- tags: ['mindmap', `level_${depth}`],
879
- generatedAt: new Date()
880
- });
881
-
882
- node.children.forEach((child: any) => extractIdeas(child, depth + 1));
883
- };
884
-
885
- extractIdeas(mindMap, 0);
886
- return ideas.slice(0, count);
887
- }
888
-
889
- private applySixHatsInternal(prompt: string): Idea[] {
890
- const hatsResults = this.sixHatsEngine.analyze(prompt);
891
- return hatsResults.map((result, index) => ({
892
- id: `idea_hat_${Date.now()}_${index}`,
893
- content: `${result.hat} Hat perspective: ${result.insights[0]}`,
894
- technique: 'six_thinking_hats',
895
- novelty: 0.65,
896
- feasibility: 0.75,
897
- impact: 0.7,
898
- relatedIdeas: [],
899
- tags: ['six_hats', result.hat.toLowerCase()],
900
- generatedAt: new Date()
901
- }));
902
- }
903
-
904
- /**
905
- * Find connections between ideas
906
- */
907
- private findConnections(ideas: Idea[]): Connection[] {
908
- const concepts = ideas.map(i => i.content);
909
- return this.conceptConnector.findConnections(concepts);
910
- }
911
-
912
- /**
913
- * Select best ideas based on multiple criteria
914
- */
915
- private selectBestIdeas(ideas: Idea[], count: number): Idea[] {
916
- return ideas
917
- .map(idea => ({
918
- idea,
919
- score: idea.novelty * 0.3 + idea.feasibility * 0.4 + idea.impact * 0.3
920
- }))
921
- .sort((a, b) => b.score - a.score)
922
- .slice(0, count)
923
- .map(({ idea }) => idea);
924
- }
925
-
926
- /**
927
- * Synthesize selected ideas into coherent concept
928
- */
929
- private synthesizeIdeas(ideas: Idea[]): string {
930
- const themes = this.extractCommonThemes(ideas);
931
- return `Synthesis: Combining ${ideas.length} ideas reveals ${themes.length} key themes: ` +
932
- `${themes.join(', ')}. The integrated solution leverages the strengths of each approach.`;
933
- }
934
-
935
- private extractCommonThemes(ideas: Idea[]): string[] {
936
- const allTags = ideas.flatMap(i => i.tags);
937
- const tagFreq = new Map<string, number>();
938
-
939
- allTags.forEach(tag => {
940
- tagFreq.set(tag, (tagFreq.get(tag) || 0) + 1);
941
- });
942
-
943
- return Array.from(tagFreq.entries())
944
- .sort((a, b) => b[1] - a[1])
945
- .slice(0, 3)
946
- .map(([tag]) => tag);
947
- }
948
-
949
- private generateActionItems(ideas: Idea[]): string[] {
950
- return ideas.slice(0, 3).map((idea, index) =>
951
- `${index + 1}. Explore: ${idea.content.substring(0, 50)}...`
952
- );
953
- }
954
-
955
- /**
956
- * Apply out-of-box thinking to a problem
957
- */
958
- thinkOutOfBox(problem: string): OutOfBoxThinking {
959
- return this.outOfBoxEngine.reframe(problem);
960
- }
961
-
962
- /**
963
- * Generate novel combinations of concepts
964
- */
965
- generateCombinations(concepts: string[], count?: number): string[] {
966
- return this.conceptConnector.generateNovelCombinations(concepts, count);
967
- }
968
-
969
- /**
970
- * Create mind map
971
- */
972
- createMindMap(centerConcept: string, depth?: number): any {
973
- return this.mindMappingEngine.createMindMap(centerConcept, depth);
974
- }
975
-
976
- /**
977
- * Apply SCAMPER technique
978
- */
979
- applyScamper(problem: string): Array<{ technique: string; question: string; idea: string }> {
980
- return this.scamperEngine.apply(problem);
981
- }
982
-
983
- /**
984
- * Apply Six Thinking Hats
985
- */
986
- applySixHats(topic: string): Array<{ hat: string; perspective: string; insights: string[] }> {
987
- return this.sixHatsEngine.analyze(topic);
988
- }
989
-
990
- /**
991
- * Get creative session
992
- */
993
- getSession(sessionId: string): CreativeSession | undefined {
994
- return this.sessions.get(sessionId);
995
- }
996
-
997
- private generateId(): string {
998
- return `creative_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
999
- }
1000
- }
1001
-
1002
- // ============================================================================
1003
- // EXPORT SINGLETON INSTANCE
1004
- // ============================================================================
1005
-
1006
- export const creativityEngine = new CreativityEngine();
1007
-
1008
- // ============================================================================
1009
- // EXAMPLE USAGE
1010
- // ============================================================================
1011
-
1012
- /*
1013
- // Start a creative session
1014
- const session = creativityEngine.startSession(
1015
- 'How can we improve remote team collaboration?',
1016
- {
1017
- techniques: ['brainstorming', 'scamper', 'six_thinking_hats'],
1018
- ideaCount: 20
1019
- }
1020
- );
1021
-
1022
- // Out-of-box thinking
1023
- const outOfBox = creativityEngine.thinkOutOfBox(
1024
- 'Our product has low user engagement'
1025
- );
1026
-
1027
- // Generate combinations
1028
- const combinations = creativityEngine.generateCombinations(
1029
- ['AI', 'collaboration', 'gamification', 'VR'],
1030
- 5
1031
- );
1032
-
1033
- // Create mind map
1034
- const mindMap = creativityEngine.createMindMap('Innovation Strategy', 3);
1035
-
1036
- // Apply SCAMPER
1037
- const scamperResults = creativityEngine.applyScamper(
1038
- 'Traditional education system'
1039
- );
1040
-
1041
- // Apply Six Thinking Hats
1042
- const hatsAnalysis = creativityEngine.applySixHats(
1043
- 'Implementing AI in healthcare'
1044
- );
1045
-
1046
- // Access generated ideas
1047
- const topIdeas = session.ideas
1048
- .sort((a, b) => (b.novelty + b.feasibility + b.impact) - (a.novelty + a.feasibility + a.impact))
1049
- .slice(0, 5);
1050
-
1051
- // Get connections between ideas
1052
- const connections = session.connections
1053
- .filter(c => c.strength > 0.5)
1054
- .slice(0, 3);
1055
- */