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
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ /**
3
+ * Validation Utility for gthinking v2.0.0
4
+ * Input sanitization and validation functions
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.validationRateLimiter = exports.ValidationRateLimiter = void 0;
8
+ exports.sanitizeInput = sanitizeInput;
9
+ exports.sanitizeForShell = sanitizeForShell;
10
+ exports.validateEmail = validateEmail;
11
+ exports.isValidURL = isValidURL;
12
+ exports.isNonEmptyString = isNonEmptyString;
13
+ exports.isPositiveInteger = isPositiveInteger;
14
+ exports.isInRange = isInRange;
15
+ exports.hasUniqueElements = hasUniqueElements;
16
+ exports.safeJsonParse = safeJsonParse;
17
+ exports.safeJsonStringify = safeJsonStringify;
18
+ exports.validateSchema = validateSchema;
19
+ exports.validateSchemaAsync = validateSchemaAsync;
20
+ exports.hasRequiredProperties = hasRequiredProperties;
21
+ exports.isValidLength = isValidLength;
22
+ exports.removeNullValues = removeNullValues;
23
+ exports.deepClone = deepClone;
24
+ exports.isPlainObject = isPlainObject;
25
+ const zod_1 = require("zod");
26
+ const errors_1 = require("../core/errors");
27
+ /**
28
+ * Sanitize user input to prevent injection attacks
29
+ * @param input - The input string to sanitize
30
+ * @returns Sanitized string
31
+ */
32
+ function sanitizeInput(input) {
33
+ if (!input)
34
+ return '';
35
+ // Remove potentially dangerous characters
36
+ return input
37
+ .replace(/[<>]/g, '') // Remove HTML tags
38
+ .replace(/[&;|`$(){}[\]\\]/g, '') // Remove shell metacharacters
39
+ .replace(/\0/g, '') // Remove null bytes
40
+ .trim();
41
+ }
42
+ /**
43
+ * Sanitize a string for use in shell commands
44
+ * @param input - The input string to sanitize
45
+ * @returns Shell-safe string
46
+ */
47
+ function sanitizeForShell(input) {
48
+ if (!input)
49
+ return '';
50
+ // More aggressive sanitization for shell usage
51
+ // Only allow alphanumeric, underscore, hyphen, dot, and space
52
+ return input
53
+ .replace(/[^a-zA-Z0-9_\-\s.]/g, '')
54
+ .trim();
55
+ }
56
+ /**
57
+ * Validate and sanitize an email address
58
+ * @param email - The email to validate
59
+ * @returns Validated email or null if invalid
60
+ */
61
+ function validateEmail(email) {
62
+ const emailSchema = zod_1.z.string().email();
63
+ const result = emailSchema.safeParse(email);
64
+ return result.success ? result.data : null;
65
+ }
66
+ /**
67
+ * Validate a URL string
68
+ * @param url - The URL to validate
69
+ * @returns True if the URL is valid
70
+ */
71
+ function isValidURL(url) {
72
+ try {
73
+ new URL(url);
74
+ return true;
75
+ }
76
+ catch {
77
+ return false;
78
+ }
79
+ }
80
+ /**
81
+ * Validate that a string is not empty or whitespace only
82
+ * @param str - The string to validate
83
+ * @returns True if the string has content
84
+ */
85
+ function isNonEmptyString(str) {
86
+ return typeof str === 'string' && str.trim().length > 0;
87
+ }
88
+ /**
89
+ * Validate that a value is a positive integer
90
+ * @param value - The value to validate
91
+ * @returns True if the value is a positive integer
92
+ */
93
+ function isPositiveInteger(value) {
94
+ return typeof value === 'number' && Number.isInteger(value) && value > 0;
95
+ }
96
+ /**
97
+ * Validate that a value is within a range
98
+ * @param value - The value to validate
99
+ * @param min - The minimum allowed value
100
+ * @param max - The maximum allowed value
101
+ * @returns True if the value is within the range
102
+ */
103
+ function isInRange(value, min, max) {
104
+ return value >= min && value <= max;
105
+ }
106
+ /**
107
+ * Validate an array has unique elements
108
+ * @param arr - The array to validate
109
+ * @returns True if all elements are unique
110
+ */
111
+ function hasUniqueElements(arr) {
112
+ return new Set(arr).size === arr.length;
113
+ }
114
+ /**
115
+ * Safe JSON parse with error handling
116
+ * @param json - The JSON string to parse
117
+ * @returns Parsed object or null if invalid
118
+ */
119
+ function safeJsonParse(json) {
120
+ try {
121
+ return JSON.parse(json);
122
+ }
123
+ catch {
124
+ return null;
125
+ }
126
+ }
127
+ /**
128
+ * Safe JSON stringify with error handling
129
+ * @param obj - The object to stringify
130
+ * @returns JSON string or null if failed
131
+ */
132
+ function safeJsonStringify(obj) {
133
+ try {
134
+ return JSON.stringify(obj);
135
+ }
136
+ catch {
137
+ return null;
138
+ }
139
+ }
140
+ /**
141
+ * Validate schema with detailed error messages
142
+ * @param schema - The Zod schema to validate against
143
+ * @param data - The data to validate
144
+ * @returns Validated data
145
+ * @throws ValidationError if validation fails
146
+ */
147
+ function validateSchema(schema, data) {
148
+ const result = schema.safeParse(data);
149
+ if (!result.success) {
150
+ const errors = result.error.errors.map(err => ({
151
+ path: err.path.join('.'),
152
+ message: err.message,
153
+ code: err.code,
154
+ }));
155
+ throw new errors_1.ValidationError(`Validation failed: ${errors.map(e => `${e.path}: ${e.message}`).join(', ')}`, { errors });
156
+ }
157
+ return result.data;
158
+ }
159
+ /**
160
+ * Validate schema asynchronously
161
+ * @param schema - The Zod schema to validate against
162
+ * @param data - The data to validate
163
+ * @returns Promise of validated data
164
+ * @throws ValidationError if validation fails
165
+ */
166
+ async function validateSchemaAsync(schema, data) {
167
+ const result = await schema.safeParseAsync(data);
168
+ if (!result.success) {
169
+ const errors = result.error.errors.map(err => ({
170
+ path: err.path.join('.'),
171
+ message: err.message,
172
+ code: err.code,
173
+ }));
174
+ throw new errors_1.ValidationError(`Validation failed: ${errors.map(e => `${e.path}: ${e.message}`).join(', ')}`, { errors });
175
+ }
176
+ return result.data;
177
+ }
178
+ /**
179
+ * Check if an object has all required properties
180
+ * @param obj - The object to check
181
+ * @param requiredProps - The required property names
182
+ * @returns True if all properties exist
183
+ */
184
+ function hasRequiredProperties(obj, requiredProps) {
185
+ return requiredProps.every(prop => prop in obj && obj[prop] !== undefined);
186
+ }
187
+ /**
188
+ * Validate that a string length is within bounds
189
+ * @param str - The string to validate
190
+ * @param min - Minimum length (inclusive)
191
+ * @param max - Maximum length (inclusive)
192
+ * @returns True if the string length is valid
193
+ */
194
+ function isValidLength(str, min, max) {
195
+ const length = str.length;
196
+ return length >= min && length <= max;
197
+ }
198
+ /**
199
+ * Remove null and undefined values from an object
200
+ * @param obj - The object to clean
201
+ * @returns Object with null/undefined values removed
202
+ */
203
+ function removeNullValues(obj) {
204
+ return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== null && v !== undefined));
205
+ }
206
+ /**
207
+ * Deep clone an object
208
+ * @param obj - The object to clone
209
+ * @returns Deep cloned object
210
+ */
211
+ function deepClone(obj) {
212
+ return JSON.parse(JSON.stringify(obj));
213
+ }
214
+ /**
215
+ * Check if a value is a plain object
216
+ * @param value - The value to check
217
+ * @returns True if the value is a plain object
218
+ */
219
+ function isPlainObject(value) {
220
+ return typeof value === 'object'
221
+ && value !== null
222
+ && !Array.isArray(value)
223
+ && value.constructor === Object;
224
+ }
225
+ /**
226
+ * Rate limiter for validation attempts
227
+ */
228
+ class ValidationRateLimiter {
229
+ attempts = new Map();
230
+ maxAttempts;
231
+ windowMs;
232
+ constructor(maxAttempts = 5, windowMs = 60000) {
233
+ this.maxAttempts = maxAttempts;
234
+ this.windowMs = windowMs;
235
+ }
236
+ /**
237
+ * Check if a key is rate limited
238
+ * @param key - The key to check
239
+ * @returns True if the key is rate limited
240
+ */
241
+ isRateLimited(key) {
242
+ const now = Date.now();
243
+ const attempts = this.attempts.get(key) || [];
244
+ // Remove old attempts outside the window
245
+ const validAttempts = attempts.filter(time => now - time < this.windowMs);
246
+ return validAttempts.length >= this.maxAttempts;
247
+ }
248
+ /**
249
+ * Record an attempt for a key
250
+ * @param key - The key to record
251
+ */
252
+ recordAttempt(key) {
253
+ const now = Date.now();
254
+ const attempts = this.attempts.get(key) || [];
255
+ attempts.push(now);
256
+ this.attempts.set(key, attempts);
257
+ }
258
+ /**
259
+ * Reset attempts for a key
260
+ * @param key - The key to reset
261
+ */
262
+ reset(key) {
263
+ this.attempts.delete(key);
264
+ }
265
+ /**
266
+ * Clear all attempts
267
+ */
268
+ clear() {
269
+ this.attempts.clear();
270
+ }
271
+ }
272
+ exports.ValidationRateLimiter = ValidationRateLimiter;
273
+ // Export a singleton instance
274
+ exports.validationRateLimiter = new ValidationRateLimiter();
275
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAUH,sCASC;AAOD,4CAQC;AAOD,sCAIC;AAOD,gCAOC;AAOD,4CAEC;AAOD,8CAEC;AASD,8BAEC;AAOD,8CAEC;AAOD,sCAMC;AAOD,8CAMC;AASD,wCAiBC;AASD,kDAoBC;AAQD,sDAKC;AASD,sCAGC;AAOD,4CAIC;AAOD,8BAEC;AAOD,sCAKC;AAzOD,6BAAwB;AACxB,2CAAiD;AAEjD;;;;GAIG;AACH,SAAgB,aAAa,CAAC,KAAa;IACzC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAEtB,0CAA0C;IAC1C,OAAO,KAAK;SACT,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,mBAAmB;SACxC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC,8BAA8B;SAC/D,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,oBAAoB;SACvC,IAAI,EAAE,CAAC;AACZ,CAAC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAEtB,+CAA+C;IAC/C,8DAA8D;IAC9D,OAAO,KAAK;SACT,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC;SAClC,IAAI,EAAE,CAAC;AACZ,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,KAAa;IACzC,MAAM,WAAW,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;IACvC,MAAM,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC,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;QACV,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF;AAlDD,sDAkDC;AAED,8BAA8B;AACjB,QAAA,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAC"}
package/docs/API.md ADDED
@@ -0,0 +1,411 @@
1
+ # gthinking v2.0.0 API Reference
2
+
3
+ ## SequentialThinkingEngine
4
+
5
+ The main orchestrator class for the sequential thinking system.
6
+
7
+ ### Constructor
8
+
9
+ ```typescript
10
+ new SequentialThinkingEngine(config?: Partial<GThinkingConfig>)
11
+ ```
12
+
13
+ **Parameters:**
14
+ - `config` - Optional configuration object
15
+
16
+ **Example:**
17
+ ```typescript
18
+ const engine = new SequentialThinkingEngine({
19
+ llm: { provider: 'gemini', apiKey: 'your-key' },
20
+ cache: { enabled: true, maxSize: 2000 },
21
+ });
22
+ ```
23
+
24
+ ### Methods
25
+
26
+ #### think()
27
+
28
+ Execute the full thinking pipeline.
29
+
30
+ ```typescript
31
+ think(request: ThinkingRequest): Promise<SynthesisResult>
32
+ ```
33
+
34
+ **Parameters:**
35
+ - `request` - The thinking request object
36
+
37
+ **Returns:** Promise resolving to SynthesisResult
38
+
39
+ **Example:**
40
+ ```typescript
41
+ const result = await engine.think({
42
+ query: 'How can we improve remote work productivity?',
43
+ preferredStages: ['search', 'analysis', 'reasoning', 'synthesis'],
44
+ options: {
45
+ depth: 'deep',
46
+ complexity: 'complex',
47
+ },
48
+ });
49
+ ```
50
+
51
+ #### quickSearch()
52
+
53
+ Execute a quick search with minimal stages.
54
+
55
+ ```typescript
56
+ quickSearch(query: string): Promise<SynthesisResult>
57
+ ```
58
+
59
+ **Example:**
60
+ ```typescript
61
+ const result = await engine.quickSearch('AI ethics guidelines');
62
+ ```
63
+
64
+ #### deepAnalysis()
65
+
66
+ Execute a comprehensive analysis with all stages.
67
+
68
+ ```typescript
69
+ deepAnalysis(query: string): Promise<SynthesisResult>
70
+ ```
71
+
72
+ **Example:**
73
+ ```typescript
74
+ const result = await engine.deepAnalysis('Climate change mitigation strategies');
75
+ ```
76
+
77
+ #### creativeSolve()
78
+
79
+ Solve a problem using creative thinking techniques.
80
+
81
+ ```typescript
82
+ creativeSolve(challenge: string): Promise<CreativeResult>
83
+ ```
84
+
85
+ **Example:**
86
+ ```typescript
87
+ const result = await engine.creativeSolve('Increase customer engagement');
88
+ ```
89
+
90
+ #### createPlan()
91
+
92
+ Create an execution plan for a goal.
93
+
94
+ ```typescript
95
+ createPlan(goal: string): Promise<Plan>
96
+ ```
97
+
98
+ **Example:**
99
+ ```typescript
100
+ const plan = await engine.createPlan('Launch a mobile app');
101
+ ```
102
+
103
+ ### Events
104
+
105
+ The engine emits the following events:
106
+
107
+ #### thinking:start
108
+
109
+ Emitted when a thinking session starts.
110
+
111
+ ```typescript
112
+ engine.on('thinking:start', ({ sessionId, request }) => {
113
+ console.log(`Session ${sessionId} started`);
114
+ });
115
+ ```
116
+
117
+ #### thinking:stage:start
118
+
119
+ Emitted when a stage starts.
120
+
121
+ ```typescript
122
+ engine.on('thinking:stage:start', ({ sessionId, stage }) => {
123
+ console.log(`Stage ${stage} started for session ${sessionId}`);
124
+ });
125
+ ```
126
+
127
+ #### thinking:stage:complete
128
+
129
+ Emitted when a stage completes.
130
+
131
+ ```typescript
132
+ engine.on('thinking:stage:complete', ({ sessionId, stage, result }) => {
133
+ console.log(`Stage ${stage} completed with confidence ${result.confidence}`);
134
+ });
135
+ ```
136
+
137
+ #### thinking:complete
138
+
139
+ Emitted when the thinking process completes.
140
+
141
+ ```typescript
142
+ engine.on('thinking:complete', ({ sessionId, result }) => {
143
+ console.log(`Session ${sessionId} completed`);
144
+ });
145
+ ```
146
+
147
+ ## Types
148
+
149
+ ### ThinkingRequest
150
+
151
+ ```typescript
152
+ interface ThinkingRequest {
153
+ id?: string; // Optional session ID
154
+ query: string; // The query to process
155
+ context?: string[]; // Additional context
156
+ preferredStages?: ThinkingStage[]; // Stages to execute
157
+ options?: {
158
+ depth?: 'shallow' | 'medium' | 'deep';
159
+ complexity?: 'simple' | 'moderate' | 'complex';
160
+ timeout?: number;
161
+ maxStages?: number;
162
+ stream?: boolean;
163
+ };
164
+ }
165
+ ```
166
+
167
+ ### SynthesisResult
168
+
169
+ ```typescript
170
+ interface SynthesisResult {
171
+ success: boolean;
172
+ confidence: number;
173
+ timestamp: Date;
174
+ duration: number;
175
+ errors: string[];
176
+ query: string;
177
+ summary: string;
178
+ keyFindings: string[];
179
+ recommendations: Recommendation[];
180
+ evaluation: EvaluationResult[];
181
+ devilsAdvocate: DevilsAdvocatePoint[];
182
+ confidenceBreakdown: ConfidenceBreakdown;
183
+ nextSteps: string[];
184
+ additionalConsiderations: string[];
185
+ sources: Source[];
186
+ metadata: Record<string, unknown>;
187
+ }
188
+ ```
189
+
190
+ ### Recommendation
191
+
192
+ ```typescript
193
+ interface Recommendation {
194
+ id: string;
195
+ priority: number; // 1-5
196
+ title: string;
197
+ description: string;
198
+ rationale: string;
199
+ confidence: number;
200
+ actions: string[];
201
+ expectedOutcome: string;
202
+ risks: string[];
203
+ resources: string[];
204
+ timeline?: string;
205
+ }
206
+ ```
207
+
208
+ ## Configuration
209
+
210
+ ### GThinkingConfig
211
+
212
+ ```typescript
213
+ interface GThinkingConfig {
214
+ version: string;
215
+ llm: LLMProviderConfig;
216
+ search: SearchConfig;
217
+ cache: CacheConfig;
218
+ logging: LoggingConfig;
219
+ pipeline: PipelineConfig;
220
+ security: SecurityConfig;
221
+ session: SessionConfig;
222
+ metrics: MetricsConfig;
223
+ }
224
+ ```
225
+
226
+ ### LLMProviderConfig
227
+
228
+ ```typescript
229
+ interface LLMProviderConfig {
230
+ provider: 'gemini' | 'claude' | 'openai' | 'kimi' | 'custom';
231
+ apiKey?: string;
232
+ baseUrl?: string;
233
+ model?: string;
234
+ timeout: number;
235
+ maxRetries: number;
236
+ rateLimitPerMinute: number;
237
+ }
238
+ ```
239
+
240
+ ### SearchConfig
241
+
242
+ ```typescript
243
+ interface SearchConfig {
244
+ enabled: boolean;
245
+ providers: ('google' | 'bing' | 'brave' | 'duckduckgo')[];
246
+ apiKeys: Record<string, string>;
247
+ maxResults: number;
248
+ timeout: number;
249
+ cacheResults: boolean;
250
+ cacheTTL: number;
251
+ }
252
+ ```
253
+
254
+ ## Error Handling
255
+
256
+ ### Error Types
257
+
258
+ ```typescript
259
+ import {
260
+ GThinkingError,
261
+ ValidationError,
262
+ TimeoutError,
263
+ StageError,
264
+ LLMError,
265
+ SearchError,
266
+ } from 'gthinking';
267
+
268
+ try {
269
+ const result = await engine.think({ query: '...' });
270
+ } catch (error) {
271
+ if (error instanceof TimeoutError) {
272
+ console.log(`Timeout in stage: ${error.stage}`);
273
+ } else if (error instanceof ValidationError) {
274
+ console.log('Validation failed:', error.details);
275
+ } else if (error instanceof StageError) {
276
+ console.log(`Stage ${error.stage} failed: ${error.message}`);
277
+ }
278
+ }
279
+ ```
280
+
281
+ ## Utility Functions
282
+
283
+ ### ID Generation
284
+
285
+ ```typescript
286
+ import { generateUUID, generateShortId, isValidUUID } from 'gthinking';
287
+
288
+ const uuid = generateUUID(); // Random UUID v4
289
+ const shortId = generateShortId(); // Short random string
290
+ const isValid = isValidUUID(uuid); // Validate UUID
291
+ ```
292
+
293
+ ### Validation
294
+
295
+ ```typescript
296
+ import { sanitizeInput, validateSchema } from 'gthinking';
297
+
298
+ const clean = sanitizeInput(userInput);
299
+ const result = validateSchema(MySchema, data);
300
+ ```
301
+
302
+ ### Logging
303
+
304
+ ```typescript
305
+ import { Logger, info, error } from 'gthinking';
306
+
307
+ const logger = new Logger('MyComponent');
308
+ logger.info('Operation completed');
309
+ logger.error('Operation failed', { error });
310
+
311
+ // Or use global functions
312
+ info('Message');
313
+ error('Error message', { details });
314
+ ```
315
+
316
+ ### Caching
317
+
318
+ ```typescript
319
+ import { Cache, cacheManager } from 'gthinking';
320
+
321
+ const cache = new Cache<string>({ maxSize: 1000, defaultTTL: 3600000 });
322
+ cache.set('key', 'value');
323
+ const value = cache.get('key');
324
+
325
+ // Or use cache manager
326
+ const searchCache = cacheManager.getCache<string>('search');
327
+ ```
328
+
329
+ ### Metrics
330
+
331
+ ```typescript
332
+ import { metricsCollector, timed } from 'gthinking';
333
+
334
+ // Record metrics
335
+ metricsCollector.counter('requests', 1);
336
+ metricsCollector.gauge('active_sessions', 5);
337
+
338
+ // Time a function
339
+ const timer = metricsCollector.startTimer('operation');
340
+ // ... do work
341
+ metricsCollector.endTimer(timer);
342
+
343
+ // Or use decorator
344
+ class MyClass {
345
+ @timed('myMethod')
346
+ async myMethod() {
347
+ // ...
348
+ }
349
+ }
350
+ ```
351
+
352
+ ## MCP Server
353
+
354
+ ### Configuration
355
+
356
+ ```json
357
+ {
358
+ "mcpServers": {
359
+ "gthinking": {
360
+ "command": "npx",
361
+ "args": ["-y", "gthinking"],
362
+ "env": {
363
+ "LLM_PROVIDER": "gemini",
364
+ "LLM_API_KEY": "your-api-key",
365
+ "GTHINKING_LOG_LEVEL": "info"
366
+ }
367
+ }
368
+ }
369
+ }
370
+ ```
371
+
372
+ ### Available Tools
373
+
374
+ #### think
375
+
376
+ Execute full thinking pipeline.
377
+
378
+ **Input:**
379
+ ```json
380
+ {
381
+ "query": "string",
382
+ "preferredStages": ["search", "analysis", "reasoning", "synthesis"],
383
+ "options": {
384
+ "depth": "deep",
385
+ "complexity": "complex"
386
+ }
387
+ }
388
+ ```
389
+
390
+ #### quick_search
391
+
392
+ Execute quick search.
393
+
394
+ **Input:**
395
+ ```json
396
+ {
397
+ "query": "string"
398
+ }
399
+ ```
400
+
401
+ #### creative_solve
402
+
403
+ Solve problem creatively.
404
+
405
+ **Input:**
406
+ ```json
407
+ {
408
+ "challenge": "string",
409
+ "techniques": ["brainstorming", "scamper"]
410
+ }
411
+ ```