@codebolt/codeboltjs 2.0.2 → 2.0.4

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 (414) hide show
  1. package/Readme.md +47 -0
  2. package/{modules → dist}/agentlib/agent.js +63 -54
  3. package/{modules → dist}/agentlib/usermessage.js +3 -3
  4. package/{index.d.ts → dist/index.d.ts} +3 -0
  5. package/{index.js → dist/index.js} +2 -0
  6. package/dist/utils/editFile.d.ts +4 -0
  7. package/dist/utils/editFile.js +30 -0
  8. package/dist/utils.d.ts +5 -0
  9. package/{utils.js → dist/utils.js} +4 -4
  10. package/package.json +17 -8
  11. package/.codebolt/chat.json +0 -1
  12. package/.codebolt/debug.json +0 -1
  13. package/.codebolt/projectState.json +0 -127
  14. package/.codebolt/tasks.json +0 -1
  15. package/.codeboltconfig.yaml +0 -0
  16. package/.github/workflows/publish-to-npm.yml +0 -20
  17. package/bkp/toolBox.bkp.ts +0 -1162
  18. package/docs/.nojekyll +0 -1
  19. package/docs/assets/highlight.css +0 -127
  20. package/docs/assets/icons.js +0 -15
  21. package/docs/assets/icons.svg +0 -1
  22. package/docs/assets/main.js +0 -59
  23. package/docs/assets/navigation.js +0 -1
  24. package/docs/assets/search.js +0 -1
  25. package/docs/assets/style.css +0 -1412
  26. package/docs/classes/_internal_.Agent.html +0 -318
  27. package/docs/classes/_internal_.AsyncResource.html +0 -44
  28. package/docs/classes/_internal_.Blob.html +0 -33
  29. package/docs/classes/_internal_.ClientRequest.html +0 -506
  30. package/docs/classes/_internal_.Codebolt.html +0 -315
  31. package/docs/classes/_internal_.CustomEventEmitter-1.html +0 -248
  32. package/docs/classes/_internal_.CustomEventEmitter.html +0 -248
  33. package/docs/classes/_internal_.Duplex.html +0 -690
  34. package/docs/classes/_internal_.EventEmitter-1.html +0 -254
  35. package/docs/classes/_internal_.EventEmitter.EventEmitterAsyncResource.html +0 -268
  36. package/docs/classes/_internal_.IncomingMessage.html +0 -661
  37. package/docs/classes/_internal_.KeyObject.html +0 -76
  38. package/docs/classes/_internal_.OutgoingMessage.html +0 -491
  39. package/docs/classes/_internal_.Readable.html +0 -551
  40. package/docs/classes/_internal_.ReadableBase.html +0 -551
  41. package/docs/classes/_internal_.Server-1.html +0 -416
  42. package/docs/classes/_internal_.Server-2.html +0 -326
  43. package/docs/classes/_internal_.Server-3.html +0 -353
  44. package/docs/classes/_internal_.Server.html +0 -390
  45. package/docs/classes/_internal_.ServerResponse.html +0 -569
  46. package/docs/classes/_internal_.Socket.html +0 -791
  47. package/docs/classes/_internal_.Stream.html +0 -256
  48. package/docs/classes/_internal_.TLSSocket.html +0 -947
  49. package/docs/classes/_internal_.URL.html +0 -140
  50. package/docs/classes/_internal_.URLSearchParams.html +0 -68
  51. package/docs/classes/_internal_.WebSocket-1.html +0 -297
  52. package/docs/classes/_internal_.WebSocket.Server.html +0 -261
  53. package/docs/classes/_internal_.Writable.html +0 -394
  54. package/docs/classes/_internal_.WritableBase.html +0 -394
  55. package/docs/classes/_internal_.X509Certificate.html +0 -144
  56. package/docs/classes/_internal_.internal-1.html +0 -256
  57. package/docs/classes/_internal_.internal.PassThrough.html +0 -686
  58. package/docs/classes/_internal_.internal.Transform.html +0 -693
  59. package/docs/enums/_internal_.logType.html +0 -4
  60. package/docs/functions/_internal_.WebSocket.createWebSocketStream.html +0 -1
  61. package/docs/functions/_internal_._node_stream_consumers_.arrayBuffer.html +0 -1
  62. package/docs/functions/_internal_._node_stream_consumers_.blob.html +0 -1
  63. package/docs/functions/_internal_._node_stream_consumers_.buffer.html +0 -1
  64. package/docs/functions/_internal_._node_stream_consumers_.json.html +0 -1
  65. package/docs/functions/_internal_._node_stream_consumers_.text.html +0 -1
  66. package/docs/functions/_internal_._node_stream_promises_.finished.html +0 -1
  67. package/docs/functions/_internal_._node_stream_promises_.pipeline.html +0 -1
  68. package/docs/functions/_internal_.internal.addAbortSignal.html +0 -17
  69. package/docs/functions/_internal_.internal.finished-1.html +0 -20
  70. package/docs/functions/_internal_.internal.finished.__promisify__.html +0 -1
  71. package/docs/functions/_internal_.internal.getDefaultHighWaterMark.html +0 -4
  72. package/docs/functions/_internal_.internal.isErrored.html +0 -3
  73. package/docs/functions/_internal_.internal.isReadable.html +0 -3
  74. package/docs/functions/_internal_.internal.pipeline-1.html +0 -24
  75. package/docs/functions/_internal_.internal.pipeline.__promisify__.html +0 -1
  76. package/docs/functions/_internal_.internal.setDefaultHighWaterMark.html +0 -4
  77. package/docs/hierarchy.html +0 -1
  78. package/docs/index.html +0 -12
  79. package/docs/interfaces/_internal_.AddToAgentStateResponse.html +0 -3
  80. package/docs/interfaces/_internal_.AddTokenResponse.html +0 -3
  81. package/docs/interfaces/_internal_.AddVectorItemResponse.html +0 -3
  82. package/docs/interfaces/_internal_.AddressInfo.html +0 -4
  83. package/docs/interfaces/_internal_.AgentOptions.html +0 -35
  84. package/docs/interfaces/_internal_.ApplicationState.html +0 -4
  85. package/docs/interfaces/_internal_.ArrayBufferView.html +0 -7
  86. package/docs/interfaces/_internal_.ArrayLike.html +0 -2
  87. package/docs/interfaces/_internal_.ArrayOptions.html +0 -7
  88. package/docs/interfaces/_internal_.AsymmetricKeyDetails.html +0 -15
  89. package/docs/interfaces/_internal_.AsyncGenerator.html +0 -5
  90. package/docs/interfaces/_internal_.AsyncGeneratorFunction.html +0 -12
  91. package/docs/interfaces/_internal_.AsyncIterable.html +0 -2
  92. package/docs/interfaces/_internal_.AsyncIterableIterator.html +0 -5
  93. package/docs/interfaces/_internal_.AsyncIterator.html +0 -4
  94. package/docs/interfaces/_internal_.AsyncResourceOptions.html +0 -12
  95. package/docs/interfaces/_internal_.BlobOptions.html +0 -8
  96. package/docs/interfaces/_internal_.Buffer.html +0 -760
  97. package/docs/interfaces/_internal_.BufferConstructor.html +0 -165
  98. package/docs/interfaces/_internal_.Certificate.html +0 -13
  99. package/docs/interfaces/_internal_.ChatMessage.html +0 -3
  100. package/docs/interfaces/_internal_.Choice.html +0 -5
  101. package/docs/interfaces/_internal_.CipherNameAndProtocol.html +0 -7
  102. package/docs/interfaces/_internal_.ClientRequestArgs.html +0 -28
  103. package/docs/interfaces/_internal_.CommandError.html +0 -3
  104. package/docs/interfaces/_internal_.CommonConnectionOptions.html +0 -29
  105. package/docs/interfaces/_internal_.ConnectOpts.html +0 -5
  106. package/docs/interfaces/_internal_.CreateFileResponse.html +0 -6
  107. package/docs/interfaces/_internal_.CreateFolderResponse.html +0 -6
  108. package/docs/interfaces/_internal_.CryptoKey.html +0 -26
  109. package/docs/interfaces/_internal_.DebugAddLogResponse.html +0 -4
  110. package/docs/interfaces/_internal_.DeleteFileResponse.html +0 -6
  111. package/docs/interfaces/_internal_.DeleteFolderResponse.html +0 -6
  112. package/docs/interfaces/_internal_.DetailedPeerCertificate.html +0 -53
  113. package/docs/interfaces/_internal_.Dict.html +0 -1
  114. package/docs/interfaces/_internal_.Disposable.html +0 -2
  115. package/docs/interfaces/_internal_.DropArgument.html +0 -7
  116. package/docs/interfaces/_internal_.DuplexOptions.html +0 -22
  117. package/docs/interfaces/_internal_.EphemeralKeyInfo.html +0 -7
  118. package/docs/interfaces/_internal_.ErrnoException.html +0 -8
  119. package/docs/interfaces/_internal_.Error.html +0 -4
  120. package/docs/interfaces/_internal_.EventEmitter-2.html +0 -130
  121. package/docs/interfaces/_internal_.EventEmitter.Abortable.html +0 -3
  122. package/docs/interfaces/_internal_.EventEmitter.EventEmitterAsyncResourceOptions.html +0 -19
  123. package/docs/interfaces/_internal_.EventEmitter.EventEmitterReferencingAsyncResource.html +0 -32
  124. package/docs/interfaces/_internal_.EventEmitterOptions.html +0 -3
  125. package/docs/interfaces/_internal_.ExtractTextResponse.html +0 -3
  126. package/docs/interfaces/_internal_.GetAgentStateResponse.html +0 -3
  127. package/docs/interfaces/_internal_.GetContentResponse.html +0 -3
  128. package/docs/interfaces/_internal_.GetMarkdownResponse.html +0 -3
  129. package/docs/interfaces/_internal_.GetMatcherListTreeResponse.html +0 -3
  130. package/docs/interfaces/_internal_.GetProjectPathResponse.html +0 -5
  131. package/docs/interfaces/_internal_.GetTokenResponse.html +0 -3
  132. package/docs/interfaces/_internal_.GetVectorResponse.html +0 -3
  133. package/docs/interfaces/_internal_.GoToPageResponse.html +0 -3
  134. package/docs/interfaces/_internal_.HtmlReceived.html +0 -3
  135. package/docs/interfaces/_internal_.IncomingHttpHeaders.html +0 -64
  136. package/docs/interfaces/_internal_.InformationEvent.html +0 -8
  137. package/docs/interfaces/_internal_.IpcSocketConnectOpts.html +0 -6
  138. package/docs/interfaces/_internal_.Iterable.html +0 -2
  139. package/docs/interfaces/_internal_.IterableIterator.html +0 -5
  140. package/docs/interfaces/_internal_.Iterator.html +0 -4
  141. package/docs/interfaces/_internal_.IteratorReturnResult.html +0 -3
  142. package/docs/interfaces/_internal_.IteratorYieldResult.html +0 -3
  143. package/docs/interfaces/_internal_.JsonWebKey.html +0 -14
  144. package/docs/interfaces/_internal_.JwkKeyExportOptions.html +0 -2
  145. package/docs/interfaces/_internal_.KeyAlgorithm.html +0 -2
  146. package/docs/interfaces/_internal_.KeyExportOptions.html +0 -5
  147. package/docs/interfaces/_internal_.KeyObject-1.html +0 -5
  148. package/docs/interfaces/_internal_.LLMResponse.html +0 -4
  149. package/docs/interfaces/_internal_.ListenOptions.html +0 -13
  150. package/docs/interfaces/_internal_.LookupAddress.html +0 -6
  151. package/docs/interfaces/_internal_.LookupOptions.html +0 -27
  152. package/docs/interfaces/_internal_.MatchProblemResponse.html +0 -3
  153. package/docs/interfaces/_internal_.MemoryGetResponse.html +0 -5
  154. package/docs/interfaces/_internal_.MemorySetResponse.html +0 -5
  155. package/docs/interfaces/_internal_.Message.html +0 -8
  156. package/docs/interfaces/_internal_.MessageContent.html +0 -3
  157. package/docs/interfaces/_internal_.Object.html +0 -18
  158. package/docs/interfaces/_internal_.OnReadOpts.html +0 -6
  159. package/docs/interfaces/_internal_.OpenDebugBrowserResponse.html +0 -4
  160. package/docs/interfaces/_internal_.OutgoingHttpHeaders.html +0 -80
  161. package/docs/interfaces/_internal_.PeerCertificate.html +0 -50
  162. package/docs/interfaces/_internal_.PromiseLike.html +0 -6
  163. package/docs/interfaces/_internal_.PxfObject.html +0 -5
  164. package/docs/interfaces/_internal_.QueryVectorItemResponse.html +0 -3
  165. package/docs/interfaces/_internal_.QueuingStrategy.html +0 -3
  166. package/docs/interfaces/_internal_.QueuingStrategySize.html +0 -1
  167. package/docs/interfaces/_internal_.ReadFileResponse.html +0 -7
  168. package/docs/interfaces/_internal_.ReadOnlyDict.html +0 -1
  169. package/docs/interfaces/_internal_.ReadWriteStream.html +0 -144
  170. package/docs/interfaces/_internal_.ReadableByteStreamController.html +0 -6
  171. package/docs/interfaces/_internal_.ReadableByteStreamControllerCallback.html +0 -1
  172. package/docs/interfaces/_internal_.ReadableOptions.html +0 -11
  173. package/docs/interfaces/_internal_.ReadableStream-1.html +0 -141
  174. package/docs/interfaces/_internal_.ReadableStream.html +0 -10
  175. package/docs/interfaces/_internal_.ReadableStreamBYOBReader.html +0 -5
  176. package/docs/interfaces/_internal_.ReadableStreamDefaultController.html +0 -5
  177. package/docs/interfaces/_internal_.ReadableStreamDefaultReadDoneResult.html +0 -3
  178. package/docs/interfaces/_internal_.ReadableStreamDefaultReadValueResult.html +0 -3
  179. package/docs/interfaces/_internal_.ReadableStreamDefaultReader.html +0 -5
  180. package/docs/interfaces/_internal_.ReadableStreamErrorCallback.html +0 -1
  181. package/docs/interfaces/_internal_.ReadableStreamGenericReader.html +0 -3
  182. package/docs/interfaces/_internal_.ReadableStreamReadDoneResult.html +0 -3
  183. package/docs/interfaces/_internal_.ReadableStreamReadValueResult.html +0 -3
  184. package/docs/interfaces/_internal_.ReadableWritablePair.html +0 -9
  185. package/docs/interfaces/_internal_.SecureContext.html +0 -2
  186. package/docs/interfaces/_internal_.SecureContextOptions.html +0 -121
  187. package/docs/interfaces/_internal_.Selection.html +0 -6
  188. package/docs/interfaces/_internal_.ServerOptions.html +0 -64
  189. package/docs/interfaces/_internal_.ServerOpts.html +0 -25
  190. package/docs/interfaces/_internal_.SharedArrayBuffer.html +0 -7
  191. package/docs/interfaces/_internal_.SharedArrayBufferConstructor.html +0 -3
  192. package/docs/interfaces/_internal_.SocketConstructorOpts.html +0 -6
  193. package/docs/interfaces/_internal_.StaticEventEmitterOptions.html +0 -15
  194. package/docs/interfaces/_internal_.StreamOptions.html +0 -9
  195. package/docs/interfaces/_internal_.StreamPipeOptions.html +0 -37
  196. package/docs/interfaces/_internal_.TLSSocketOptions.html +0 -160
  197. package/docs/interfaces/_internal_.TcpSocketConnectOpts.html +0 -19
  198. package/docs/interfaces/_internal_.TerminalInterruptResponse.html +0 -3
  199. package/docs/interfaces/_internal_.TlsOptions.html +0 -197
  200. package/docs/interfaces/_internal_.UnderlyingByteSource.html +0 -6
  201. package/docs/interfaces/_internal_.UnderlyingSink.html +0 -6
  202. package/docs/interfaces/_internal_.UnderlyingSinkAbortCallback.html +0 -1
  203. package/docs/interfaces/_internal_.UnderlyingSinkCloseCallback.html +0 -1
  204. package/docs/interfaces/_internal_.UnderlyingSinkStartCallback.html +0 -1
  205. package/docs/interfaces/_internal_.UnderlyingSinkWriteCallback.html +0 -1
  206. package/docs/interfaces/_internal_.UnderlyingSource.html +0 -5
  207. package/docs/interfaces/_internal_.UnderlyingSourceCancelCallback.html +0 -1
  208. package/docs/interfaces/_internal_.UnderlyingSourcePullCallback.html +0 -1
  209. package/docs/interfaces/_internal_.UnderlyingSourceStartCallback.html +0 -1
  210. package/docs/interfaces/_internal_.UpdateFileResponse.html +0 -6
  211. package/docs/interfaces/_internal_.UrlResponse.html +0 -3
  212. package/docs/interfaces/_internal_.Usage-1.html +0 -4
  213. package/docs/interfaces/_internal_.Usage.html +0 -4
  214. package/docs/interfaces/_internal_.UserMessage.html +0 -3
  215. package/docs/interfaces/_internal_.UserRequest.html +0 -7
  216. package/docs/interfaces/_internal_.WebSocket.AddressInfo.html +0 -4
  217. package/docs/interfaces/_internal_.WebSocket.ClientOptions.html +0 -138
  218. package/docs/interfaces/_internal_.WebSocket.CloseEvent.html +0 -6
  219. package/docs/interfaces/_internal_.WebSocket.ErrorEvent.html +0 -5
  220. package/docs/interfaces/_internal_.WebSocket.Event.html +0 -3
  221. package/docs/interfaces/_internal_.WebSocket.EventListenerOptions.html +0 -2
  222. package/docs/interfaces/_internal_.WebSocket.MessageEvent.html +0 -4
  223. package/docs/interfaces/_internal_.WebSocket.PerMessageDeflateOptions.html +0 -9
  224. package/docs/interfaces/_internal_.WebSocket.ServerOptions.html +0 -14
  225. package/docs/interfaces/_internal_.WebSocket.WebSocket.html +0 -172
  226. package/docs/interfaces/_internal_.WebSocket.WebSocketServer.html +0 -144
  227. package/docs/interfaces/_internal_.WebSocketAlias.html +0 -172
  228. package/docs/interfaces/_internal_.WritableOptions.html +0 -14
  229. package/docs/interfaces/_internal_.WritableStream-1.html +0 -8
  230. package/docs/interfaces/_internal_.WritableStream.html +0 -133
  231. package/docs/interfaces/_internal_.WritableStreamDefaultController.html +0 -6
  232. package/docs/interfaces/_internal_.WritableStreamDefaultWriter.html +0 -12
  233. package/docs/interfaces/_internal_.X509CheckOptions.html +0 -16
  234. package/docs/interfaces/_internal_.ZlibOptions.html +0 -21
  235. package/docs/interfaces/_internal_.getMatchDetail.html +0 -3
  236. package/docs/interfaces/_internal_.internal.FinishedOptions.html +0 -6
  237. package/docs/interfaces/_internal_.internal.Pipe.html +0 -5
  238. package/docs/interfaces/_internal_.internal.PipelineOptions.html +0 -3
  239. package/docs/interfaces/_internal_.internal.TransformOptions.html +0 -24
  240. package/docs/modules/_internal_.EventEmitter.html +0 -6
  241. package/docs/modules/_internal_.WebSocket.html +0 -21
  242. package/docs/modules/_internal_._node_stream_consumers_.html +0 -6
  243. package/docs/modules/_internal_._node_stream_promises_.html +0 -3
  244. package/docs/modules/_internal_.html +0 -228
  245. package/docs/modules/_internal_.internal.finished.html +0 -2
  246. package/docs/modules/_internal_.internal.html +0 -36
  247. package/docs/modules/_internal_.internal.pipeline.html +0 -2
  248. package/docs/modules.html +0 -3
  249. package/docs/types/_internal_.AnyRest.html +0 -1
  250. package/docs/types/_internal_.Args.html +0 -1
  251. package/docs/types/_internal_.ArrayBufferLike.html +0 -1
  252. package/docs/types/_internal_.ArrayBufferView-1.html +0 -1
  253. package/docs/types/_internal_.BinaryLike.html +0 -1
  254. package/docs/types/_internal_.BufferEncoding.html +0 -1
  255. package/docs/types/_internal_.BufferLike.html +0 -1
  256. package/docs/types/_internal_.ComposeFnParam.html +0 -1
  257. package/docs/types/_internal_.DefaultEventMap.html +0 -1
  258. package/docs/types/_internal_.EventMap.html +0 -1
  259. package/docs/types/_internal_.InstanceType.html +0 -2
  260. package/docs/types/_internal_.IteratorResult.html +0 -1
  261. package/docs/types/_internal_.Key.html +0 -1
  262. package/docs/types/_internal_.Key2.html +0 -1
  263. package/docs/types/_internal_.KeyFormat.html +0 -1
  264. package/docs/types/_internal_.KeyObjectType.html +0 -1
  265. package/docs/types/_internal_.KeyType-1.html +0 -1
  266. package/docs/types/_internal_.KeyType.html +0 -1
  267. package/docs/types/_internal_.KeyUsage.html +0 -1
  268. package/docs/types/_internal_.Listener.html +0 -1
  269. package/docs/types/_internal_.LookupFunction.html +0 -1
  270. package/docs/types/_internal_.OutgoingHttpHeader.html +0 -1
  271. package/docs/types/_internal_.Partial.html +0 -2
  272. package/docs/types/_internal_.Pick.html +0 -2
  273. package/docs/types/_internal_.PropertyKey.html +0 -1
  274. package/docs/types/_internal_.ReadableStreamController.html +0 -1
  275. package/docs/types/_internal_.ReadableStreamDefaultReadResult.html +0 -1
  276. package/docs/types/_internal_.ReadableStreamReadResult.html +0 -1
  277. package/docs/types/_internal_.Record.html +0 -2
  278. package/docs/types/_internal_.RequestListener.html +0 -1
  279. package/docs/types/_internal_.SecureVersion.html +0 -1
  280. package/docs/types/_internal_.ServerOptions-1.html +0 -1
  281. package/docs/types/_internal_.SocketConnectOpts.html +0 -1
  282. package/docs/types/_internal_.SocketReadyState.html +0 -1
  283. package/docs/types/_internal_.TypedArray.html +0 -1
  284. package/docs/types/_internal_.WebSocket.CertMeta.html +0 -2
  285. package/docs/types/_internal_.WebSocket.Data.html +0 -2
  286. package/docs/types/_internal_.WebSocket.RawData.html +0 -2
  287. package/docs/types/_internal_.WebSocket.VerifyClientCallbackAsync.html +0 -4
  288. package/docs/types/_internal_.WebSocket.VerifyClientCallbackSync.html +0 -4
  289. package/docs/types/_internal_.WithImplicitCoercion.html +0 -1
  290. package/docs/types/_internal_.internal.PipelineCallback.html +0 -1
  291. package/docs/types/_internal_.internal.PipelineDestination.html +0 -1
  292. package/docs/types/_internal_.internal.PipelineDestinationIterableFunction.html +0 -1
  293. package/docs/types/_internal_.internal.PipelineDestinationPromiseFunction.html +0 -1
  294. package/docs/types/_internal_.internal.PipelinePromise.html +0 -1
  295. package/docs/types/_internal_.internal.PipelineSource.html +0 -1
  296. package/docs/types/_internal_.internal.PipelineSourceFunction.html +0 -1
  297. package/docs/types/_internal_.internal.PipelineTransform.html +0 -1
  298. package/docs/types/_internal_.internal.PipelineTransformSource.html +0 -1
  299. package/docs/types/_internal_.internal.TransformCallback.html +0 -1
  300. package/docs/variables/_internal_.Buffer-1.html +0 -1
  301. package/docs/variables/_internal_.Error-1.html +0 -1
  302. package/docs/variables/_internal_.Object-1.html +0 -2
  303. package/docs/variables/_internal_.ReadableByteStreamController-1.html +0 -1
  304. package/docs/variables/_internal_.ReadableStream-2.html +0 -1
  305. package/docs/variables/_internal_.ReadableStreamBYOBReader-1.html +0 -1
  306. package/docs/variables/_internal_.ReadableStreamDefaultController-1.html +0 -1
  307. package/docs/variables/_internal_.ReadableStreamDefaultReader-1.html +0 -1
  308. package/docs/variables/_internal_.SharedArrayBuffer-1.html +0 -1
  309. package/docs/variables/_internal_.WebSocket.WebSocket-1.html +0 -1
  310. package/docs/variables/_internal_.WebSocket.WebSocketServer-1.html +0 -1
  311. package/docs/variables/_internal_.WebSocketAlias-1.html +0 -1
  312. package/docs/variables/_internal_.WritableStream-2.html +0 -1
  313. package/docs/variables/_internal_.WritableStreamDefaultController-1.html +0 -1
  314. package/docs/variables/_internal_.WritableStreamDefaultWriter-1.html +0 -1
  315. package/docs/variables/_internal_.internal.consumers.html +0 -1
  316. package/docs/variables/_internal_.internal.promises.html +0 -1
  317. package/docs/variables/default.html +0 -1
  318. package/script/gen.js +0 -27
  319. package/src/index.ts +0 -107
  320. package/src/modules/agent.ts +0 -120
  321. package/src/modules/agentlib/agent.ts +0 -406
  322. package/src/modules/agentlib/systemprompt.ts +0 -55
  323. package/src/modules/agentlib/taskInstruction.ts +0 -105
  324. package/src/modules/agentlib/usermessage.ts +0 -188
  325. package/src/modules/browser.ts +0 -352
  326. package/src/modules/chat.ts +0 -229
  327. package/src/modules/codeparsers.ts +0 -28
  328. package/src/modules/codeutils.ts +0 -182
  329. package/src/modules/crawler.ts +0 -121
  330. package/src/modules/dbmemory.ts +0 -52
  331. package/src/modules/debug.ts +0 -68
  332. package/src/modules/docutils.ts +0 -18
  333. package/src/modules/fs.ts +0 -263
  334. package/src/modules/git.ts +0 -237
  335. package/src/modules/history.ts +0 -82
  336. package/src/modules/knowledge.ts +0 -5
  337. package/src/modules/llm.ts +0 -36
  338. package/src/modules/outputparsers.ts +0 -30
  339. package/src/modules/project.ts +0 -68
  340. package/src/modules/rag.ts +0 -27
  341. package/src/modules/search.ts +0 -32
  342. package/src/modules/state.ts +0 -115
  343. package/src/modules/task.ts +0 -73
  344. package/src/modules/terminal.ts +0 -113
  345. package/src/modules/tokenizer.ts +0 -56
  346. package/src/modules/toolBox.ts +0 -1384
  347. package/src/modules/tools.ts +0 -254
  348. package/src/modules/vectordb.ts +0 -102
  349. package/src/modules/websocket.ts +0 -97
  350. package/src/utils.ts +0 -5
  351. package/tests/chat.test.js +0 -0
  352. package/tests/fs.test.js +0 -89
  353. package/tests/index.test.js +0 -4
  354. package/tsconfig.json +0 -122
  355. package/utils.d.ts +0 -5
  356. package/webpack.config.js +0 -25
  357. /package/{modules → dist}/agentlib/agent.d.ts +0 -0
  358. /package/{modules → dist}/agentlib/systemprompt.d.ts +0 -0
  359. /package/{modules → dist}/agentlib/systemprompt.js +0 -0
  360. /package/{modules → dist}/agentlib/taskInstruction.d.ts +0 -0
  361. /package/{modules → dist}/agentlib/taskInstruction.js +0 -0
  362. /package/{modules → dist}/agentlib/usermessage.d.ts +0 -0
  363. /package/{modules → dist/modules}/agent.d.ts +0 -0
  364. /package/{modules → dist/modules}/agent.js +0 -0
  365. /package/{modules → dist/modules}/browser.d.ts +0 -0
  366. /package/{modules → dist/modules}/browser.js +0 -0
  367. /package/{modules → dist/modules}/chat.d.ts +0 -0
  368. /package/{modules → dist/modules}/chat.js +0 -0
  369. /package/{modules → dist/modules}/codeparsers.d.ts +0 -0
  370. /package/{modules → dist/modules}/codeparsers.js +0 -0
  371. /package/{modules → dist/modules}/codeutils.d.ts +0 -0
  372. /package/{modules → dist/modules}/codeutils.js +0 -0
  373. /package/{modules → dist/modules}/crawler.d.ts +0 -0
  374. /package/{modules → dist/modules}/crawler.js +0 -0
  375. /package/{modules → dist/modules}/dbmemory.d.ts +0 -0
  376. /package/{modules → dist/modules}/dbmemory.js +0 -0
  377. /package/{modules → dist/modules}/debug.d.ts +0 -0
  378. /package/{modules → dist/modules}/debug.js +0 -0
  379. /package/{modules → dist/modules}/docutils.d.ts +0 -0
  380. /package/{modules → dist/modules}/docutils.js +0 -0
  381. /package/{modules → dist/modules}/fs.d.ts +0 -0
  382. /package/{modules → dist/modules}/fs.js +0 -0
  383. /package/{modules → dist/modules}/git.d.ts +0 -0
  384. /package/{modules → dist/modules}/git.js +0 -0
  385. /package/{modules → dist/modules}/history.d.ts +0 -0
  386. /package/{modules → dist/modules}/history.js +0 -0
  387. /package/{modules → dist/modules}/knowledge.d.ts +0 -0
  388. /package/{modules → dist/modules}/knowledge.js +0 -0
  389. /package/{modules → dist/modules}/llm.d.ts +0 -0
  390. /package/{modules → dist/modules}/llm.js +0 -0
  391. /package/{modules → dist/modules}/outputparsers.d.ts +0 -0
  392. /package/{modules → dist/modules}/outputparsers.js +0 -0
  393. /package/{modules → dist/modules}/project.d.ts +0 -0
  394. /package/{modules → dist/modules}/project.js +0 -0
  395. /package/{modules → dist/modules}/rag.d.ts +0 -0
  396. /package/{modules → dist/modules}/rag.js +0 -0
  397. /package/{modules → dist/modules}/search.d.ts +0 -0
  398. /package/{modules → dist/modules}/search.js +0 -0
  399. /package/{modules → dist/modules}/state.d.ts +0 -0
  400. /package/{modules → dist/modules}/state.js +0 -0
  401. /package/{modules → dist/modules}/task.d.ts +0 -0
  402. /package/{modules → dist/modules}/task.js +0 -0
  403. /package/{modules → dist/modules}/terminal.d.ts +0 -0
  404. /package/{modules → dist/modules}/terminal.js +0 -0
  405. /package/{modules → dist/modules}/tokenizer.d.ts +0 -0
  406. /package/{modules → dist/modules}/tokenizer.js +0 -0
  407. /package/{modules → dist/modules}/toolBox.d.ts +0 -0
  408. /package/{modules → dist/modules}/toolBox.js +0 -0
  409. /package/{modules → dist/modules}/tools.d.ts +0 -0
  410. /package/{modules → dist/modules}/tools.js +0 -0
  411. /package/{modules → dist/modules}/vectordb.d.ts +0 -0
  412. /package/{modules → dist/modules}/vectordb.js +0 -0
  413. /package/{modules → dist/modules}/websocket.d.ts +0 -0
  414. /package/{modules → dist/modules}/websocket.js +0 -0
@@ -1,1162 +0,0 @@
1
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
- import {
4
- CallToolRequestSchema,
5
- ClientCapabilities,
6
- CompleteRequestSchema,
7
- CreateMessageRequestSchema,
8
- ErrorCode,
9
- GetPromptRequestSchema,
10
- ListPromptsRequestSchema,
11
- ListResourcesRequestSchema,
12
- ListResourceTemplatesRequestSchema,
13
- ListToolsRequestSchema,
14
- McpError,
15
- ReadResourceRequestSchema,
16
- Root,
17
- RootsListChangedNotificationSchema,
18
- ServerCapabilities,
19
- SetLevelRequestSchema,
20
- } from "@modelcontextprotocol/sdk/types.js";
21
- import { zodToJsonSchema } from "zod-to-json-schema";
22
- import { z } from "zod";
23
- import { setTimeout as delay } from "timers/promises";
24
- import { readFile } from "fs/promises";
25
- // import { fileTypeFromBuffer } from "file-type";
26
- // type FileTypeModule = typeof import('file-type');
27
- import { StrictEventEmitter } from "strict-event-emitter-types";
28
- import { EventEmitter } from "events";
29
- import Fuse from "fuse.js";
30
- // import { startSSEServer } from "mcp-proxy";
31
- import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
32
- import parseURITemplate from "uri-templates";
33
- import { loadEsm } from "load-esm";
34
-
35
- export type SSEServer = {
36
- close: () => Promise<void>;
37
- };
38
-
39
- type FastMCPEvents = {
40
- connect: (event: { session: FastMCPSession }) => void;
41
- disconnect: (event: { session: FastMCPSession }) => void;
42
- };
43
-
44
- type FastMCPSessionEvents = {
45
- rootsChanged: (event: { roots: Root[] }) => void;
46
- error: (event: { error: Error }) => void;
47
- };
48
-
49
- /**
50
- * Generates an image content object from a URL, file path, or buffer.
51
- */
52
- export const imageContent = async (
53
- input: { url: string } | { path: string } | { buffer: Buffer },
54
- ): Promise<ImageContent> => {
55
- let rawData: Buffer;
56
-
57
- if ("url" in input) {
58
- const response = await fetch(input.url);
59
-
60
- if (!response.ok) {
61
- throw new Error(`Failed to fetch image from URL: ${response.statusText}`);
62
- }
63
-
64
- rawData = Buffer.from(await response.arrayBuffer());
65
- } else if ("path" in input) {
66
- rawData = await readFile(input.path);
67
- } else if ("buffer" in input) {
68
- rawData = input.buffer;
69
- } else {
70
- throw new Error(
71
- "Invalid input: Provide a valid 'url', 'path', or 'buffer'",
72
- );
73
- }
74
- const { fileTypeFromBuffer } = await loadEsm('file-type');
75
- const mimeType = await fileTypeFromBuffer(rawData);
76
-
77
- const base64Data = rawData.toString("base64");
78
-
79
- return {
80
- type: "image",
81
- data: base64Data,
82
- mimeType: mimeType?.mime ?? "image/png",
83
- } as const;
84
- };
85
-
86
- abstract class FastMCPError extends Error {
87
- public constructor(message?: string) {
88
- super(message);
89
- this.name = new.target.name;
90
- }
91
- }
92
-
93
- type Extra = unknown;
94
-
95
- type Extras = Record<string, Extra>;
96
-
97
- export class UnexpectedStateError extends FastMCPError {
98
- public extras?: Extras;
99
-
100
- public constructor(message: string, extras?: Extras) {
101
- super(message);
102
- this.name = new.target.name;
103
- this.extras = extras;
104
- }
105
- }
106
-
107
- /**
108
- * An error that is meant to be surfaced to the user.
109
- */
110
- export class UserError extends UnexpectedStateError { }
111
-
112
- type ToolParameters = z.ZodTypeAny;
113
-
114
- type Literal = boolean | null | number | string | undefined;
115
-
116
- type SerializableValue =
117
- | Literal
118
- | SerializableValue[]
119
- | { [key: string]: SerializableValue };
120
-
121
- type Progress = {
122
- /**
123
- * The progress thus far. This should increase every time progress is made, even if the total is unknown.
124
- */
125
- progress: number;
126
- /**
127
- * Total number of items to process (or total progress required), if known.
128
- */
129
- total?: number;
130
- };
131
-
132
- type Context = {
133
- reportProgress: (progress: Progress) => Promise<void>;
134
- log: {
135
- debug: (message: string, data?: SerializableValue) => void;
136
- error: (message: string, data?: SerializableValue) => void;
137
- info: (message: string, data?: SerializableValue) => void;
138
- warn: (message: string, data?: SerializableValue) => void;
139
- };
140
- };
141
-
142
- type TextContent = {
143
- type: "text";
144
- text: string;
145
- };
146
-
147
- const TextContentZodSchema = z
148
- .object({
149
- type: z.literal("text"),
150
- /**
151
- * The text content of the message.
152
- */
153
- text: z.string(),
154
- })
155
- .strict() satisfies z.ZodType<TextContent>;
156
-
157
- type ImageContent = {
158
- type: "image";
159
- data: string;
160
- mimeType: string;
161
- };
162
-
163
- const ImageContentZodSchema = z
164
- .object({
165
- type: z.literal("image"),
166
- /**
167
- * The base64-encoded image data.
168
- */
169
- data: z.string().base64(),
170
- /**
171
- * The MIME type of the image. Different providers may support different image types.
172
- */
173
- mimeType: z.string(),
174
- })
175
- .strict() satisfies z.ZodType<ImageContent>;
176
-
177
- type Content = TextContent | ImageContent;
178
-
179
- const ContentZodSchema = z.discriminatedUnion("type", [
180
- TextContentZodSchema,
181
- ImageContentZodSchema,
182
- ]) satisfies z.ZodType<Content>;
183
-
184
- type ContentResult = {
185
- content: Content[];
186
- isError?: boolean;
187
- };
188
-
189
- const ContentResultZodSchema = z
190
- .object({
191
- content: ContentZodSchema.array(),
192
- isError: z.boolean().optional(),
193
- })
194
- .strict() satisfies z.ZodType<ContentResult>;
195
-
196
- type Completion = {
197
- values: string[];
198
- total?: number;
199
- hasMore?: boolean;
200
- };
201
-
202
- /**
203
- * https://github.com/modelcontextprotocol/typescript-sdk/blob/3164da64d085ec4e022ae881329eee7b72f208d4/src/types.ts#L983-L1003
204
- */
205
- const CompletionZodSchema = z.object({
206
- /**
207
- * An array of completion values. Must not exceed 100 items.
208
- */
209
- values: z.array(z.string()).max(100),
210
- /**
211
- * The total number of completion options available. This can exceed the number of values actually sent in the response.
212
- */
213
- total: z.optional(z.number().int()),
214
- /**
215
- * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
216
- */
217
- hasMore: z.optional(z.boolean()),
218
- }) satisfies z.ZodType<Completion>;
219
-
220
- type Tool<Params extends ToolParameters = ToolParameters> = {
221
- name: string;
222
- description?: string;
223
- parameters?: Params;
224
- execute: (
225
- args: z.infer<Params>,
226
- context: Context,
227
- ) => Promise<string | ContentResult | TextContent | ImageContent>;
228
- };
229
-
230
- type ResourceResult =
231
- | {
232
- text: string;
233
- }
234
- | {
235
- blob: string;
236
- };
237
-
238
- type InputResourceTemplateArgument = Readonly<{
239
- name: string;
240
- description?: string;
241
- complete?: ArgumentValueCompleter;
242
- }>;
243
-
244
- type ResourceTemplateArgument = Readonly<{
245
- name: string;
246
- description?: string;
247
- complete?: ArgumentValueCompleter;
248
- }>;
249
-
250
- type ResourceTemplate<
251
- Arguments extends ResourceTemplateArgument[] = ResourceTemplateArgument[],
252
- > = {
253
- uriTemplate: string;
254
- name: string;
255
- description?: string;
256
- mimeType?: string;
257
- arguments: Arguments;
258
- complete?: (name: string, value: string) => Promise<Completion>;
259
- load: (
260
- args: ResourceTemplateArgumentsToObject<Arguments>,
261
- ) => Promise<ResourceResult>;
262
- };
263
-
264
- type ResourceTemplateArgumentsToObject<T extends { name: string }[]> = {
265
- [K in T[number]["name"]]: string;
266
- };
267
-
268
- type InputResourceTemplate<
269
- Arguments extends ResourceTemplateArgument[] = ResourceTemplateArgument[],
270
- > = {
271
- uriTemplate: string;
272
- name: string;
273
- description?: string;
274
- mimeType?: string;
275
- arguments: Arguments;
276
- load: (
277
- args: ResourceTemplateArgumentsToObject<Arguments>,
278
- ) => Promise<ResourceResult>;
279
- };
280
-
281
- type Resource = {
282
- uri: string;
283
- name: string;
284
- description?: string;
285
- mimeType?: string;
286
- load: () => Promise<ResourceResult | ResourceResult[]>;
287
- complete?: (name: string, value: string) => Promise<Completion>;
288
- };
289
-
290
- type ArgumentValueCompleter = (value: string) => Promise<Completion>;
291
-
292
- type InputPromptArgument = Readonly<{
293
- name: string;
294
- description?: string;
295
- required?: boolean;
296
- complete?: ArgumentValueCompleter;
297
- enum?: string[];
298
- }>;
299
-
300
- type PromptArgumentsToObject<T extends { name: string; required?: boolean }[]> =
301
- {
302
- [K in T[number]["name"]]: Extract<
303
- T[number],
304
- { name: K }
305
- >["required"] extends true
306
- ? string
307
- : string | undefined;
308
- };
309
-
310
- type InputPrompt<
311
- Arguments extends InputPromptArgument[] = InputPromptArgument[],
312
- Args = PromptArgumentsToObject<Arguments>,
313
- > = {
314
- name: string;
315
- description?: string;
316
- arguments?: InputPromptArgument[];
317
- load: (args: Args) => Promise<string>;
318
- };
319
-
320
- type PromptArgument = Readonly<{
321
- name: string;
322
- description?: string;
323
- required?: boolean;
324
- complete?: ArgumentValueCompleter;
325
- enum?: string[];
326
- }>;
327
-
328
- type Prompt<
329
- Arguments extends PromptArgument[] = PromptArgument[],
330
- Args = PromptArgumentsToObject<Arguments>,
331
- > = {
332
- arguments?: PromptArgument[];
333
- complete?: (name: string, value: string) => Promise<Completion>;
334
- description?: string;
335
- load: (args: Args) => Promise<string>;
336
- name: string;
337
- };
338
-
339
- type ServerOptions = {
340
- name: string;
341
- version: `${number}.${number}.${number}`;
342
- };
343
-
344
- type LoggingLevel =
345
- | "debug"
346
- | "info"
347
- | "notice"
348
- | "warning"
349
- | "error"
350
- | "critical"
351
- | "alert"
352
- | "emergency";
353
-
354
- const FastMCPSessionEventEmitterBase: {
355
- new(): StrictEventEmitter<EventEmitter, FastMCPSessionEvents>;
356
- } = EventEmitter;
357
-
358
- class FastMCPSessionEventEmitter extends FastMCPSessionEventEmitterBase { }
359
-
360
- type SamplingResponse = {
361
- model: string;
362
- stopReason?: "endTurn" | "stopSequence" | "maxTokens" | string;
363
- role: "user" | "assistant";
364
- content: TextContent | ImageContent;
365
- };
366
-
367
- export class FastMCPSession extends FastMCPSessionEventEmitter {
368
- #capabilities: ServerCapabilities = {};
369
- #clientCapabilities?: ClientCapabilities;
370
- #loggingLevel: LoggingLevel = "info";
371
- #prompts: Prompt[] = [];
372
- #resources: Resource[] = [];
373
- #resourceTemplates: ResourceTemplate[] = [];
374
- #roots: Root[] = [];
375
- #server: Server;
376
-
377
- constructor({
378
- name,
379
- version,
380
- tools,
381
- resources,
382
- resourcesTemplates,
383
- prompts,
384
- }: {
385
- name: string;
386
- version: string;
387
- tools: Tool[];
388
- resources: Resource[];
389
- resourcesTemplates: InputResourceTemplate[];
390
- prompts: Prompt[];
391
- }) {
392
- super();
393
-
394
- if (tools.length) {
395
- this.#capabilities.tools = {};
396
- }
397
-
398
- if (resources.length || resourcesTemplates.length) {
399
- this.#capabilities.resources = {};
400
- }
401
-
402
- if (prompts.length) {
403
- for (const prompt of prompts) {
404
- this.addPrompt(prompt);
405
- }
406
-
407
- this.#capabilities.prompts = {};
408
- }
409
-
410
- this.#capabilities.logging = {};
411
-
412
- this.#server = new Server(
413
- { name: name, version: version },
414
- { capabilities: this.#capabilities },
415
- );
416
-
417
- this.setupErrorHandling();
418
- this.setupLoggingHandlers();
419
- this.setupRootsHandlers();
420
- this.setupCompleteHandlers();
421
-
422
- if (tools.length) {
423
- this.setupToolHandlers(tools);
424
- }
425
-
426
- if (resources.length || resourcesTemplates.length) {
427
- for (const resource of resources) {
428
- this.addResource(resource);
429
- }
430
-
431
- this.setupResourceHandlers(resources);
432
-
433
- if (resourcesTemplates.length) {
434
- for (const resourceTemplate of resourcesTemplates) {
435
- this.addResourceTemplate(resourceTemplate);
436
- }
437
-
438
- this.setupResourceTemplateHandlers(resourcesTemplates);
439
- }
440
- }
441
-
442
- if (prompts.length) {
443
- this.setupPromptHandlers(prompts);
444
- }
445
- }
446
-
447
- private addResource(inputResource: Resource) {
448
- this.#resources.push(inputResource);
449
- }
450
-
451
- private addResourceTemplate(inputResourceTemplate: InputResourceTemplate) {
452
- const completers: Record<string, ArgumentValueCompleter> = {};
453
-
454
- for (const argument of inputResourceTemplate.arguments ?? []) {
455
- if (argument.complete) {
456
- completers[argument.name] = argument.complete;
457
- }
458
- }
459
-
460
- const resourceTemplate = {
461
- ...inputResourceTemplate,
462
- complete: async (name: string, value: string) => {
463
- if (completers[name]) {
464
- return await completers[name](value);
465
- }
466
-
467
- return {
468
- values: [],
469
- };
470
- },
471
- };
472
-
473
- this.#resourceTemplates.push(resourceTemplate);
474
- }
475
-
476
- private addPrompt(inputPrompt: InputPrompt) {
477
- const completers: Record<string, ArgumentValueCompleter> = {};
478
- const enums: Record<string, string[]> = {};
479
-
480
- for (const argument of inputPrompt.arguments ?? []) {
481
- if (argument.complete) {
482
- completers[argument.name] = argument.complete;
483
- }
484
-
485
- if (argument.enum) {
486
- enums[argument.name] = argument.enum;
487
- }
488
- }
489
-
490
- const prompt = {
491
- ...inputPrompt,
492
- complete: async (name: string, value: string) => {
493
- if (completers[name]) {
494
- return await completers[name](value);
495
- }
496
-
497
- if (enums[name]) {
498
- const fuse = new Fuse(enums[name], {
499
- keys: ["value"],
500
- });
501
-
502
- const result = fuse.search(value);
503
-
504
- return {
505
- values: result.map((item) => item.item),
506
- total: result.length,
507
- };
508
- }
509
-
510
- return {
511
- values: [],
512
- };
513
- },
514
- };
515
-
516
- this.#prompts.push(prompt);
517
- }
518
-
519
- public get clientCapabilities(): ClientCapabilities | null {
520
- return this.#clientCapabilities ?? null;
521
- }
522
-
523
- public get server(): Server {
524
- return this.#server;
525
- }
526
-
527
- #pingInterval: ReturnType<typeof setInterval> | null = null;
528
-
529
- public async requestSampling(
530
- message: z.infer<typeof CreateMessageRequestSchema>["params"],
531
- ): Promise<SamplingResponse> {
532
- return this.#server.createMessage(message);
533
- }
534
-
535
- public async connect(transport: Transport) {
536
- if (this.#server.transport) {
537
- throw new UnexpectedStateError("Server is already connected");
538
- }
539
-
540
- await this.#server.connect(transport);
541
-
542
- let attempt = 0;
543
-
544
- while (attempt++ < 10) {
545
- const capabilities = await this.#server.getClientCapabilities();
546
-
547
- if (capabilities) {
548
- this.#clientCapabilities = capabilities;
549
-
550
- break;
551
- }
552
-
553
- await delay(100);
554
- }
555
-
556
- if (!this.#clientCapabilities) {
557
- throw new UnexpectedStateError("Server did not connect");
558
- }
559
-
560
- if (this.#clientCapabilities?.roots) {
561
- const roots = await this.#server.listRoots();
562
-
563
- this.#roots = roots.roots;
564
- }
565
-
566
- this.#pingInterval = setInterval(async () => {
567
- try {
568
- await this.#server.ping();
569
- } catch (error) {
570
- this.emit("error", {
571
- error: error as Error,
572
- });
573
- }
574
- }, 1000);
575
- }
576
-
577
- public get roots(): Root[] {
578
- return this.#roots;
579
- }
580
-
581
- public async close() {
582
- if (this.#pingInterval) {
583
- clearInterval(this.#pingInterval);
584
- }
585
-
586
- await this.#server.close();
587
- }
588
-
589
- private setupErrorHandling() {
590
- this.#server.onerror = (error) => {
591
- console.error("[MCP Error]", error);
592
- };
593
- }
594
-
595
- public get loggingLevel(): LoggingLevel {
596
- return this.#loggingLevel;
597
- }
598
-
599
- private setupCompleteHandlers() {
600
- this.#server.setRequestHandler(CompleteRequestSchema, async (request) => {
601
- if (request.params.ref.type === "ref/prompt") {
602
- const prompt = this.#prompts.find(
603
- (prompt) => prompt.name === request.params.ref.name,
604
- );
605
-
606
- if (!prompt) {
607
- throw new UnexpectedStateError("Unknown prompt", {
608
- request,
609
- });
610
- }
611
-
612
- if (!prompt.complete) {
613
- throw new UnexpectedStateError("Prompt does not support completion", {
614
- request,
615
- });
616
- }
617
-
618
- const completion = CompletionZodSchema.parse(
619
- await prompt.complete(
620
- request.params.argument.name,
621
- request.params.argument.value,
622
- ),
623
- );
624
-
625
- return {
626
- completion,
627
- };
628
- }
629
-
630
- if (request.params.ref.type === "ref/resource") {
631
- const resource = this.#resourceTemplates.find(
632
- (resource) => resource.uriTemplate === request.params.ref.uri,
633
- );
634
-
635
- if (!resource) {
636
- throw new UnexpectedStateError("Unknown resource", {
637
- request,
638
- });
639
- }
640
-
641
- if (!("uriTemplate" in resource)) {
642
- throw new UnexpectedStateError("Unexpected resource");
643
- }
644
-
645
- if (!resource.complete) {
646
- throw new UnexpectedStateError(
647
- "Resource does not support completion",
648
- {
649
- request,
650
- },
651
- );
652
- }
653
-
654
- const completion = CompletionZodSchema.parse(
655
- await resource.complete(
656
- request.params.argument.name,
657
- request.params.argument.value,
658
- ),
659
- );
660
-
661
- return {
662
- completion,
663
- };
664
- }
665
-
666
- throw new UnexpectedStateError("Unexpected completion request", {
667
- request,
668
- });
669
- });
670
- }
671
-
672
- private setupRootsHandlers() {
673
- this.#server.setNotificationHandler(
674
- RootsListChangedNotificationSchema,
675
- () => {
676
- this.#server.listRoots().then((roots) => {
677
- this.#roots = roots.roots;
678
-
679
- this.emit("rootsChanged", {
680
- roots: roots.roots,
681
- });
682
- });
683
- },
684
- );
685
- }
686
-
687
- private setupLoggingHandlers() {
688
- this.#server.setRequestHandler(SetLevelRequestSchema, (request) => {
689
- this.#loggingLevel = request.params.level;
690
-
691
- return {};
692
- });
693
- }
694
-
695
- private setupToolHandlers(tools: Tool[]) {
696
- this.#server.setRequestHandler(ListToolsRequestSchema, async () => {
697
- return {
698
- tools: tools.map((tool) => {
699
- return {
700
- name: tool.name,
701
- description: tool.description,
702
- inputSchema: tool.parameters
703
- ? zodToJsonSchema(tool.parameters)
704
- : undefined,
705
- };
706
- }),
707
- };
708
- });
709
-
710
- this.#server.setRequestHandler(CallToolRequestSchema, async (request) => {
711
- const tool = tools.find((tool) => tool.name === request.params.name);
712
-
713
- if (!tool) {
714
- throw new McpError(
715
- ErrorCode.MethodNotFound,
716
- `Unknown tool: ${request.params.name}`,
717
- );
718
- }
719
-
720
- let args: any = undefined;
721
-
722
- if (tool.parameters) {
723
- const parsed = tool.parameters.safeParse(request.params.arguments);
724
-
725
- if (!parsed.success) {
726
- throw new McpError(
727
- ErrorCode.InvalidParams,
728
- `Invalid ${request.params.name} parameters`,
729
- );
730
- }
731
-
732
- args = parsed.data;
733
- }
734
-
735
- const progressToken = request.params?._meta?.progressToken;
736
-
737
- let result: ContentResult;
738
-
739
- try {
740
- const reportProgress = async (progress: Progress) => {
741
- await this.#server.notification({
742
- method: "notifications/progress",
743
- params: {
744
- ...progress,
745
- progressToken,
746
- },
747
- });
748
- };
749
-
750
- const log = {
751
- debug: (message: string, context?: SerializableValue) => {
752
- this.#server.sendLoggingMessage({
753
- level: "debug",
754
- data: {
755
- message,
756
- context,
757
- },
758
- });
759
- },
760
- error: (message: string, context?: SerializableValue) => {
761
- this.#server.sendLoggingMessage({
762
- level: "error",
763
- data: {
764
- message,
765
- context,
766
- },
767
- });
768
- },
769
- info: (message: string, context?: SerializableValue) => {
770
- this.#server.sendLoggingMessage({
771
- level: "info",
772
- data: {
773
- message,
774
- context,
775
- },
776
- });
777
- },
778
- warn: (message: string, context?: SerializableValue) => {
779
- this.#server.sendLoggingMessage({
780
- level: "warning",
781
- data: {
782
- message,
783
- context,
784
- },
785
- });
786
- },
787
- };
788
-
789
- const maybeStringResult = await tool.execute(args, {
790
- reportProgress,
791
- log,
792
- });
793
-
794
- if (typeof maybeStringResult === "string") {
795
- result = ContentResultZodSchema.parse({
796
- content: [{ type: "text", text: maybeStringResult }],
797
- });
798
- } else if ("type" in maybeStringResult) {
799
- result = ContentResultZodSchema.parse({
800
- content: [maybeStringResult],
801
- });
802
- } else {
803
- result = ContentResultZodSchema.parse(maybeStringResult);
804
- }
805
- } catch (error) {
806
- if (error instanceof UserError) {
807
- return {
808
- content: [{ type: "text", text: error.message }],
809
- isError: true,
810
- };
811
- }
812
-
813
- return {
814
- content: [{ type: "text", text: `Error: ${error}` }],
815
- isError: true,
816
- };
817
- }
818
-
819
- return result;
820
- });
821
- }
822
-
823
- private setupResourceHandlers(resources: Resource[]) {
824
- this.#server.setRequestHandler(ListResourcesRequestSchema, async () => {
825
- return {
826
- resources: resources.map((resource) => {
827
- return {
828
- uri: resource.uri,
829
- name: resource.name,
830
- mimeType: resource.mimeType,
831
- };
832
- }),
833
- };
834
- });
835
-
836
- this.#server.setRequestHandler(
837
- ReadResourceRequestSchema,
838
- async (request) => {
839
- if ("uri" in request.params) {
840
- const resource = resources.find(
841
- (resource) =>
842
- "uri" in resource && resource.uri === request.params.uri,
843
- );
844
-
845
- if (!resource) {
846
- for (const resourceTemplate of this.#resourceTemplates) {
847
- const uriTemplate = parseURITemplate(
848
- resourceTemplate.uriTemplate,
849
- );
850
-
851
- const match = uriTemplate.fromUri(request.params.uri);
852
-
853
- if (!match) {
854
- continue;
855
- }
856
-
857
- const uri = uriTemplate.fill(match);
858
-
859
- const result = await resourceTemplate.load(match);
860
-
861
- return {
862
- contents: [
863
- {
864
- uri: uri,
865
- mimeType: resourceTemplate.mimeType,
866
- name: resourceTemplate.name,
867
- ...result,
868
- },
869
- ],
870
- };
871
- }
872
-
873
- throw new McpError(
874
- ErrorCode.MethodNotFound,
875
- `Unknown resource: ${request.params.uri}`,
876
- );
877
- }
878
-
879
- if (!("uri" in resource)) {
880
- throw new UnexpectedStateError("Resource does not support reading");
881
- }
882
-
883
- let maybeArrayResult: Awaited<ReturnType<Resource["load"]>>;
884
-
885
- try {
886
- maybeArrayResult = await resource.load();
887
- } catch (error) {
888
- throw new McpError(
889
- ErrorCode.InternalError,
890
- `Error reading resource: ${error}`,
891
- {
892
- uri: resource.uri,
893
- },
894
- );
895
- }
896
-
897
- if (Array.isArray(maybeArrayResult)) {
898
- return {
899
- contents: maybeArrayResult.map((result) => ({
900
- uri: resource.uri,
901
- mimeType: resource.mimeType,
902
- name: resource.name,
903
- ...result,
904
- })),
905
- };
906
- } else {
907
- return {
908
- contents: [
909
- {
910
- uri: resource.uri,
911
- mimeType: resource.mimeType,
912
- name: resource.name,
913
- ...maybeArrayResult,
914
- },
915
- ],
916
- };
917
- }
918
- }
919
-
920
- throw new UnexpectedStateError("Unknown resource request", {
921
- request,
922
- });
923
- },
924
- );
925
- }
926
-
927
- private setupResourceTemplateHandlers(resourceTemplates: ResourceTemplate[]) {
928
- this.#server.setRequestHandler(
929
- ListResourceTemplatesRequestSchema,
930
- async () => {
931
- return {
932
- resourceTemplates: resourceTemplates.map((resourceTemplate) => {
933
- return {
934
- name: resourceTemplate.name,
935
- uriTemplate: resourceTemplate.uriTemplate,
936
- };
937
- }),
938
- };
939
- },
940
- );
941
- }
942
-
943
- private setupPromptHandlers(prompts: Prompt[]) {
944
- this.#server.setRequestHandler(ListPromptsRequestSchema, async () => {
945
- return {
946
- prompts: prompts.map((prompt) => {
947
- return {
948
- name: prompt.name,
949
- description: prompt.description,
950
- arguments: prompt.arguments,
951
- complete: prompt.complete,
952
- };
953
- }),
954
- };
955
- });
956
-
957
- this.#server.setRequestHandler(GetPromptRequestSchema, async (request) => {
958
- const prompt = prompts.find(
959
- (prompt) => prompt.name === request.params.name,
960
- );
961
-
962
- if (!prompt) {
963
- throw new McpError(
964
- ErrorCode.MethodNotFound,
965
- `Unknown prompt: ${request.params.name}`,
966
- );
967
- }
968
-
969
- const args = request.params.arguments;
970
-
971
- for (const arg of prompt.arguments ?? []) {
972
- if (arg.required && !(args && arg.name in args)) {
973
- throw new McpError(
974
- ErrorCode.InvalidRequest,
975
- `Missing required argument: ${arg.name}`,
976
- );
977
- }
978
- }
979
-
980
- let result: Awaited<ReturnType<Prompt["load"]>>;
981
-
982
- try {
983
- result = await prompt.load(args as Record<string, string | undefined>);
984
- } catch (error) {
985
- throw new McpError(
986
- ErrorCode.InternalError,
987
- `Error loading prompt: ${error}`,
988
- );
989
- }
990
-
991
- return {
992
- description: prompt.description,
993
- messages: [
994
- {
995
- role: "user",
996
- content: { type: "text", text: result },
997
- },
998
- ],
999
- };
1000
- });
1001
- }
1002
- }
1003
-
1004
- const FastMCPEventEmitterBase: {
1005
- new(): StrictEventEmitter<EventEmitter, FastMCPEvents>;
1006
- } = EventEmitter;
1007
-
1008
- class FastMCPEventEmitter extends FastMCPEventEmitterBase { }
1009
-
1010
- export class ToolBox extends FastMCPEventEmitter {
1011
- #options: ServerOptions;
1012
- #prompts: InputPrompt[] = [];
1013
- #resources: Resource[] = [];
1014
- #resourcesTemplates: InputResourceTemplate[] = [];
1015
- #sessions: FastMCPSession[] = [];
1016
- #sseServer: SSEServer | null = null;
1017
- #tools: Tool[] = [];
1018
-
1019
- constructor(public options: ServerOptions) {
1020
- super();
1021
-
1022
- this.#options = options;
1023
- }
1024
-
1025
- public get sessions(): FastMCPSession[] {
1026
- return this.#sessions;
1027
- }
1028
-
1029
- /**
1030
- * Adds a tool to the server.
1031
- */
1032
- public addTool<Params extends ToolParameters>(tool: Tool<Params>) {
1033
- this.#tools.push(tool as unknown as Tool);
1034
- }
1035
-
1036
- /**
1037
- * Adds a resource to the server.
1038
- */
1039
- public addResource(resource: Resource) {
1040
- this.#resources.push(resource);
1041
- }
1042
-
1043
- /**
1044
- * Adds a resource template to the server.
1045
- */
1046
- public addResourceTemplate<
1047
- const Args extends InputResourceTemplateArgument[],
1048
- >(resource: InputResourceTemplate<Args>) {
1049
- this.#resourcesTemplates.push(resource);
1050
- }
1051
-
1052
- /**
1053
- * Adds a prompt to the server.
1054
- */
1055
- public addPrompt<const Args extends InputPromptArgument[]>(
1056
- prompt: InputPrompt<Args>,
1057
- ) {
1058
- this.#prompts.push(prompt);
1059
- }
1060
-
1061
- /**
1062
- * Starts the server.
1063
- */
1064
- public async activate(
1065
- options:
1066
- | { transportType: "stdio" }
1067
- | {
1068
- transportType: "sse";
1069
- sse: { endpoint: `/${string}`; port: number };
1070
- } = {
1071
- transportType: "stdio",
1072
- },
1073
- ) {
1074
- if (options.transportType === "stdio") {
1075
- const transport = new StdioServerTransport();
1076
-
1077
- const session = new FastMCPSession({
1078
- name: this.#options.name,
1079
- version: this.#options.version,
1080
- tools: this.#tools,
1081
- resources: this.#resources,
1082
- resourcesTemplates: this.#resourcesTemplates,
1083
- prompts: this.#prompts,
1084
- });
1085
- await session.connect(transport);
1086
-
1087
- this.#sessions.push(session);
1088
-
1089
- this.emit("connect", {
1090
- session,
1091
- });
1092
-
1093
- console.info(`server is running on stdio`);
1094
- } else if (options.transportType === "sse") {
1095
- // this.#sseServer = await startSSEServer<FastMCPSession>({
1096
- // endpoint: options.sse.endpoint as `/${string}`,
1097
- // port: options.sse.port,
1098
- // createServer: async () => {
1099
- // return new FastMCPSession({
1100
- // name: this.#options.name,
1101
- // version: this.#options.version,
1102
- // tools: this.#tools,
1103
- // resources: this.#resources,
1104
- // resourcesTemplates: this.#resourcesTemplates,
1105
- // prompts: this.#prompts,
1106
- // });
1107
- // },
1108
- // onClose: (session) => {
1109
- // this.emit("disconnect", {
1110
- // session,
1111
- // });
1112
- // },
1113
- // onConnect: async (session) => {
1114
- // this.#sessions.push(session);
1115
-
1116
- // this.emit("connect", {
1117
- // session,
1118
- // });
1119
- // },
1120
- // });
1121
-
1122
- // console.error(
1123
- // `server is running on SSE at http://localhost:${options.sse.port}${options.sse.endpoint}`,
1124
- // );
1125
- } else {
1126
- throw new Error("Invalid transport type");
1127
- }
1128
- }
1129
-
1130
- /**
1131
- * Stops the server.
1132
- */
1133
- public async stop() {
1134
- if (this.#sseServer) {
1135
- this.#sseServer.close();
1136
- }
1137
- }
1138
-
1139
- // public async activate() {
1140
-
1141
- // const transport = new StdioServerTransport();
1142
-
1143
- // const session = new FastMCPSession({
1144
- // name: this.#options.name,
1145
- // version: this.#options.version,
1146
- // tools: this.#tools,
1147
- // resources: this.#resources,
1148
- // resourcesTemplates: this.#resourcesTemplates,
1149
- // prompts: this.#prompts,
1150
- // });
1151
-
1152
- // await session.connect(transport);
1153
-
1154
- // this.#sessions.push(session);
1155
-
1156
- // this.emit("connect", {
1157
- // session,
1158
- // });
1159
-
1160
- // console.info(`server is running on stdio`);
1161
- // }
1162
- }