@agentscope-ai/agentscope 0.0.2

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 (136) hide show
  1. package/dist/agent/index.d.mts +234 -0
  2. package/dist/agent/index.d.ts +234 -0
  3. package/dist/agent/index.js +1412 -0
  4. package/dist/agent/index.js.map +1 -0
  5. package/dist/agent/index.mjs +1375 -0
  6. package/dist/agent/index.mjs.map +1 -0
  7. package/dist/base-BOx3UzOl.d.mts +41 -0
  8. package/dist/base-BoIps2RL.d.ts +41 -0
  9. package/dist/base-C7jwyH4Z.d.mts +52 -0
  10. package/dist/base-Cwi4bjze.d.ts +127 -0
  11. package/dist/base-DYlBMCy_.d.mts +127 -0
  12. package/dist/base-NX-knWOv.d.ts +52 -0
  13. package/dist/block-VsnHrllL.d.mts +48 -0
  14. package/dist/block-VsnHrllL.d.ts +48 -0
  15. package/dist/event/index.d.mts +181 -0
  16. package/dist/event/index.d.ts +181 -0
  17. package/dist/event/index.js +58 -0
  18. package/dist/event/index.js.map +1 -0
  19. package/dist/event/index.mjs +33 -0
  20. package/dist/event/index.mjs.map +1 -0
  21. package/dist/formatter/index.d.mts +187 -0
  22. package/dist/formatter/index.d.ts +187 -0
  23. package/dist/formatter/index.js +647 -0
  24. package/dist/formatter/index.js.map +1 -0
  25. package/dist/formatter/index.mjs +616 -0
  26. package/dist/formatter/index.mjs.map +1 -0
  27. package/dist/index-BTJDlKvQ.d.mts +195 -0
  28. package/dist/index-BcatlwXQ.d.ts +195 -0
  29. package/dist/index-CAxQAkiP.d.mts +21 -0
  30. package/dist/index-CAxQAkiP.d.ts +21 -0
  31. package/dist/mcp/index.d.mts +9 -0
  32. package/dist/mcp/index.d.ts +9 -0
  33. package/dist/mcp/index.js +432 -0
  34. package/dist/mcp/index.js.map +1 -0
  35. package/dist/mcp/index.mjs +408 -0
  36. package/dist/mcp/index.mjs.map +1 -0
  37. package/dist/message/index.d.mts +10 -0
  38. package/dist/message/index.d.ts +10 -0
  39. package/dist/message/index.js +67 -0
  40. package/dist/message/index.js.map +1 -0
  41. package/dist/message/index.mjs +37 -0
  42. package/dist/message/index.mjs.map +1 -0
  43. package/dist/message-CkN21KaY.d.mts +99 -0
  44. package/dist/message-CzLeTlua.d.ts +99 -0
  45. package/dist/model/index.d.mts +377 -0
  46. package/dist/model/index.d.ts +377 -0
  47. package/dist/model/index.js +1880 -0
  48. package/dist/model/index.js.map +1 -0
  49. package/dist/model/index.mjs +1849 -0
  50. package/dist/model/index.mjs.map +1 -0
  51. package/dist/storage/index.d.mts +68 -0
  52. package/dist/storage/index.d.ts +68 -0
  53. package/dist/storage/index.js +250 -0
  54. package/dist/storage/index.js.map +1 -0
  55. package/dist/storage/index.mjs +212 -0
  56. package/dist/storage/index.mjs.map +1 -0
  57. package/dist/tool/index.d.mts +311 -0
  58. package/dist/tool/index.d.ts +311 -0
  59. package/dist/tool/index.js +1494 -0
  60. package/dist/tool/index.js.map +1 -0
  61. package/dist/tool/index.mjs +1447 -0
  62. package/dist/tool/index.mjs.map +1 -0
  63. package/dist/toolkit-CEpulFi0.d.ts +99 -0
  64. package/dist/toolkit-CGEZSZPa.d.mts +99 -0
  65. package/jest.config.js +11 -0
  66. package/package.json +92 -0
  67. package/src/_utils/common.ts +104 -0
  68. package/src/_utils/index.ts +1 -0
  69. package/src/agent/agent-base.ts +0 -0
  70. package/src/agent/agent.test.ts +1028 -0
  71. package/src/agent/agent.ts +1032 -0
  72. package/src/agent/index.ts +2 -0
  73. package/src/agent/interfaces.ts +23 -0
  74. package/src/agent/test-compression.ts +72 -0
  75. package/src/event/index.ts +250 -0
  76. package/src/formatter/base.ts +133 -0
  77. package/src/formatter/dashscope-chat-formatter.test.ts +372 -0
  78. package/src/formatter/dashscope-chat-formatter.ts +163 -0
  79. package/src/formatter/deepseek-chat-formatter.ts +130 -0
  80. package/src/formatter/index.ts +5 -0
  81. package/src/formatter/ollama-chat-formatter.ts +67 -0
  82. package/src/formatter/openai-chat-formatter.test.ts +263 -0
  83. package/src/formatter/openai-chat-formatter.ts +301 -0
  84. package/src/formatter/openai.md +767 -0
  85. package/src/mcp/base.ts +114 -0
  86. package/src/mcp/http.test.ts +303 -0
  87. package/src/mcp/http.ts +224 -0
  88. package/src/mcp/index.ts +2 -0
  89. package/src/mcp/stdio.test.ts +91 -0
  90. package/src/mcp/stdio.ts +119 -0
  91. package/src/message/block.ts +60 -0
  92. package/src/message/enums.ts +4 -0
  93. package/src/message/index.ts +12 -0
  94. package/src/message/message.test.ts +80 -0
  95. package/src/message/message.ts +131 -0
  96. package/src/model/base.ts +226 -0
  97. package/src/model/dashscope-model.test.ts +335 -0
  98. package/src/model/dashscope-model.ts +441 -0
  99. package/src/model/deepseek-model.test.ts +279 -0
  100. package/src/model/deepseek-model.ts +401 -0
  101. package/src/model/index.ts +7 -0
  102. package/src/model/ollama-model.test.ts +307 -0
  103. package/src/model/ollama-model.ts +356 -0
  104. package/src/model/openai-model.ts +327 -0
  105. package/src/model/response.ts +22 -0
  106. package/src/model/usage.ts +12 -0
  107. package/src/storage/base.ts +52 -0
  108. package/src/storage/file-system.test.ts +587 -0
  109. package/src/storage/file-system.ts +269 -0
  110. package/src/storage/index.ts +2 -0
  111. package/src/tool/base.ts +23 -0
  112. package/src/tool/bash.test.ts +174 -0
  113. package/src/tool/bash.ts +152 -0
  114. package/src/tool/edit.test.ts +83 -0
  115. package/src/tool/edit.ts +95 -0
  116. package/src/tool/glob.test.ts +63 -0
  117. package/src/tool/glob.ts +166 -0
  118. package/src/tool/grep.test.ts +74 -0
  119. package/src/tool/grep.ts +256 -0
  120. package/src/tool/index.ts +10 -0
  121. package/src/tool/read.test.ts +77 -0
  122. package/src/tool/read.ts +117 -0
  123. package/src/tool/response.ts +82 -0
  124. package/src/tool/task.test.ts +299 -0
  125. package/src/tool/task.ts +399 -0
  126. package/src/tool/toolkit.test.ts +636 -0
  127. package/src/tool/toolkit.ts +601 -0
  128. package/src/tool/write.test.ts +52 -0
  129. package/src/tool/write.ts +57 -0
  130. package/src/type/index.ts +52 -0
  131. package/tsconfig.build.json +4 -0
  132. package/tsconfig.cjs.json +11 -0
  133. package/tsconfig.esm.json +10 -0
  134. package/tsconfig.json +14 -0
  135. package/tsup.config.ts +20 -0
  136. package/typedoc.json +52 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/message/message.ts","../../src/formatter/base.ts","../../src/formatter/dashscope-chat-formatter.ts","../../src/formatter/deepseek-chat-formatter.ts","../../src/formatter/ollama-chat-formatter.ts","../../src/formatter/openai-chat-formatter.ts"],"sourcesContent":["import { JSONSerializableObject } from '../type';\nimport {\n ContentBlock,\n TextBlock,\n ThinkingBlock,\n ToolResultBlock,\n ToolCallBlock,\n DataBlock,\n} from './block';\n\n/** A chat message exchanged between agents or between an agent and a model. */\nexport interface Msg {\n /** Unique identifier for the message. */\n id: string;\n /** Display name of the message sender. */\n name: string;\n /** Conversation role of the sender. */\n role: 'user' | 'assistant' | 'system';\n /** Message body. */\n content: ContentBlock[];\n /** Arbitrary key-value metadata attached to the message. */\n metadata: Record<string, JSONSerializableObject>;\n /** ISO-8601 creation timestamp. */\n timestamp: string;\n /** Usage information for the message, such as token counts. */\n usage?: {\n inputTokens: number;\n outputTokens: number;\n };\n}\n\n/**\n * Create a new {@link Msg} object, filling in `id` and `timestamp` when omitted.\n *\n * @param root0\n * @param root0.name\n * @param root0.content\n * @param root0.role\n * @param root0.metadata\n * @param root0.id\n * @param root0.timestamp\n * @param root0.usage\n * @returns A fully-populated {@link Msg} object.\n */\nexport function createMsg({\n name,\n content,\n role,\n metadata = {},\n id = crypto.randomUUID(),\n timestamp = new Date().toISOString(),\n usage,\n}: Omit<Msg, 'id' | 'timestamp' | 'metadata'> &\n Partial<Pick<Msg, 'id' | 'timestamp' | 'metadata'>>): Msg {\n return { id, name, role, content, metadata, timestamp, usage } as Msg;\n}\n\n/**\n * Extract the plain-text content from a message.\n *\n * When `content` is a string it is returned as-is. When it is an array of\n * content blocks, all {@link TextBlock} texts are joined with `separator`.\n *\n * @param msg - The message to read.\n * @param separator - String inserted between consecutive text blocks. Defaults to `'\\n'`.\n * @returns The concatenated text, or `null` when no text blocks are present.\n */\nexport function getTextContent(msg: Msg, separator: string = '\\n'): string | null {\n const textBlocks = msg.content.filter(block => block.type === 'text');\n if (textBlocks.length === 0) {\n return null;\n }\n return textBlocks.map(block => (block as TextBlock).text).join(separator);\n}\n\n/**\n * Return all content blocks from a message, regardless of type.\n *\n * When `content` is a plain string it is wrapped in a single {@link TextBlock}.\n *\n * @param msg - The message to read.\n * @returns An array of all {@link ContentBlock} objects.\n */\nexport function getContentBlocks(msg: Msg): ContentBlock[];\n/**\n * Return all {@link TextBlock} objects from a message.\n *\n * @param msg - The message to read.\n * @param blockType - `'text'`\n * @returns An array of {@link TextBlock} objects.\n */\nexport function getContentBlocks(msg: Msg, blockType: 'text'): TextBlock[];\n/**\n * Return all {@link ThinkingBlock} objects from a message.\n *\n * @param msg - The message to read.\n * @param blockType - `'thinking'`\n * @returns An array of {@link ThinkingBlock} objects.\n */\nexport function getContentBlocks(msg: Msg, blockType: 'thinking'): ThinkingBlock[];\n/**\n * Return all {@link DataBlock} objects from a message.\n *\n * @param msg - The message to read.\n * @param blockType - `'video'`\n * @returns An array of {@link DataBlock} objects.\n */\nexport function getContentBlocks(msg: Msg, blockType: 'data'): DataBlock[];\n/**\n * Return all {@link ToolCallBlock} objects from a message.\n *\n * @param msg - The message to read.\n * @param blockType - `'tool_call'`\n * @returns An array of {@link ToolCallBlock} objects.\n */\nexport function getContentBlocks(msg: Msg, blockType: 'tool_call'): ToolCallBlock[];\n/**\n * Return all {@link ToolResultBlock} objects from a message.\n *\n * @param msg - The message to read.\n * @param blockType - `'tool_result'`\n * @returns An array of {@link ToolResultBlock} objects.\n */\nexport function getContentBlocks(msg: Msg, blockType: 'tool_result'): ToolResultBlock[];\nexport function getContentBlocks(\n msg: Msg,\n blockType?: 'text' | 'thinking' | 'data' | 'tool_call' | 'tool_result'\n): ContentBlock[] {\n if (!blockType) return msg.content;\n return msg.content.filter(block => block.type === blockType);\n}\n","import { Msg, TextBlock, DataBlock, createMsg } from '../message';\n\n/**\n * Base class for message formatters.\n */\nexport abstract class FormatterBase {\n /**\n * Format the input message objects into the required format by the API.\n *\n * @param root0\n * @param root0.msgs - An array of message objects to be formatted.\n * @returns A promise that resolves to an array of formatted message objects.\n */\n abstract format({ msgs }: { msgs: Array<Msg> }): Promise<Record<string, unknown>[]>;\n\n /**\n * Convert the tool output to string format for the LLM APIs that only accept text input. If\n * `promoteMultimodalToolResult` is true, the multimodal content will be promoted to be a user message with\n * \"<system-info></system-info>\" tags. Otherwise, the multimodal content will be saved to a storage and a URL link\n * will be provided in the text output.\n *\n * @param output - The tool output, which can be a string or an array of content blocks.\n * @param promoteMultimodalToolResult - Whether to promote the multimodal content to the prompt messages.\n * @returns An object containing the text output and an optional promoted message.\n */\n convertToolOutputToString(\n output: string | (TextBlock | DataBlock)[],\n promoteMultimodalToolResult: boolean | { image?: boolean; audio?: boolean; video?: boolean }\n ) {\n if (typeof output === 'string') return { text: output, promotedMsg: null };\n\n let textualOutput = [];\n\n const promotedData: { id: string; block: DataBlock }[] = [];\n\n for (const block of output) {\n switch (block.type) {\n case 'text':\n textualOutput.push(block.text);\n break;\n default:\n const type = block.source.mediaType.split('/')[0];\n if (type !== 'image' && type !== 'audio' && type !== 'video') {\n console.log(\n `Unsupported media type '${block.source.mediaType}' in tool output. Only image, audio and video are supported.`\n );\n break;\n }\n if (block.source.type === 'url') {\n textualOutput.push(\n `<system-info>One returned ${type} can be found at: ${block.source.url}</system-info>`\n );\n } else {\n // If we should promote the multimodal content to the prompt messages\n const shouldPromote =\n promoteMultimodalToolResult === true ||\n (typeof promoteMultimodalToolResult === 'object' &&\n promoteMultimodalToolResult[type]);\n\n if (shouldPromote) {\n // Create an ID for the multimodal content first, which should less than 10 characters\n const dataID = Math.random().toString(36).substring(2, 10);\n textualOutput.push(\n `<system-info>One returned ${type} is embedded with ID '${dataID}' and will be attached within '<system-info></system-info>' tags later.</system-info>`\n );\n\n // Record the promoted data\n promotedData.push({ id: dataID, block });\n } else {\n // TODO: save locally\n\n // Save to storage and provide URL link\n textualOutput.push(`The returned ${block.type} is stored locally.`);\n }\n }\n }\n }\n\n // Attach prefix and suffix system-info tags if there are promoted blocks\n const promotedBlocks: (TextBlock | DataBlock)[] = [];\n promotedData.forEach(({ id, block }) => {\n const type = block.source.mediaType.split('/')[0];\n promotedBlocks.push({\n id: crypto.randomUUID(),\n type: 'text',\n text: `<${type}_data id='${id}'>`,\n });\n promotedBlocks.push(block);\n promotedBlocks.push({\n id: crypto.randomUUID(),\n type: 'text',\n text: `</${type}_data>\\n`,\n });\n });\n\n if (promotedBlocks.length > 0) {\n // The prefix\n const prefix =\n '<system-info>The multimodal contents returned from the tool call are as follows:\\n';\n\n if (promotedBlocks[0].type === 'text') {\n promotedBlocks[0].text = `${prefix}${promotedBlocks[0].text}`;\n } else {\n promotedBlocks.unshift({\n id: crypto.randomUUID(),\n type: 'text',\n text: `${prefix}`,\n });\n }\n\n // The suffix\n const lastBlock = promotedBlocks[promotedBlocks.length - 1];\n if (lastBlock.type === 'text') {\n promotedBlocks[promotedBlocks.length - 1] = {\n id: crypto.randomUUID(),\n type: 'text',\n text: `${lastBlock.text}</system-info>`,\n };\n } else {\n promotedBlocks.push({\n id: crypto.randomUUID(),\n type: 'text',\n text: `</system-info>`,\n });\n }\n }\n\n return {\n text: textualOutput.join('\\n'),\n promotedMsg: createMsg({ name: 'user', content: promotedBlocks, role: 'user' }),\n };\n }\n}\n","import { FormatterBase } from './base';\nimport { Msg, TextBlock, getContentBlocks } from '../message';\nimport { DataBlock } from '../message';\n\ninterface DashScopeFormatterOptions {\n /**\n * Since DashScope API doesn't support multimodal tool outputs, this option indicates whether to\n * promote the multimodal tool results to the prompt messages, so that LLMs can see them.\n * Note you should ensure your model supports the corresponding modalities.\n */\n promoteMultimodalToolResult?:\n | {\n image?: boolean;\n audio?: boolean;\n video?: boolean;\n }\n | boolean;\n}\n\n/**\n *\n */\nexport class DashScopeChatFormatter extends FormatterBase {\n private promoteMultimodalToolResult:\n | { image?: boolean; audio?: boolean; video?: boolean }\n | boolean;\n\n /**\n * Initialize a DashScopeChatFormatter instance.\n *\n * @param promoteMultimodalToolResult - Since DashScope API doesn't support multimodal tool outputs, this option\n * indicates whether to promote the multimodal tool results to the prompt messages, so that LLMs can see them.\n * Note you should ensure your model supports the corresponding modalities.\n * @param promoteMultimodalToolResult.promoteMultimodalToolResult\n */\n constructor({ promoteMultimodalToolResult = false }: DashScopeFormatterOptions = {}) {\n super();\n this.promoteMultimodalToolResult = promoteMultimodalToolResult;\n }\n\n /**\n * Format the input message objects into the required format by DashScope API.\n *\n * @param msgs - An array of Msg instances to be formatted.\n * @param msgs.msgs\n * @returns A promise that resolves to an array of formatted message objects.\n */\n async format({ msgs }: { msgs: Array<Msg> }): Promise<Record<string, unknown>[]> {\n const formattedMsgs: Array<Record<string, unknown>> = [];\n let index = 0;\n while (index < msgs.length) {\n const msg = msgs[index];\n const formattedMsg: {\n role: string;\n content: Record<string, unknown>[];\n tool_calls?: {\n id: string;\n type: 'function';\n function: {\n name: string;\n arguments: string;\n };\n }[];\n } = {\n role: msg.role,\n content: [],\n };\n\n // The cached messages that should be pushed after the current message, to keep the order of messages correct.\n const cachedMsgs = [];\n for (const block of getContentBlocks(msg)) {\n switch (block.type) {\n case 'text':\n formattedMsg.content.push(this._formatTextBlock(block));\n break;\n case 'thinking':\n break;\n case 'tool_call':\n if (!formattedMsg.tool_calls) {\n formattedMsg.tool_calls = [];\n }\n formattedMsg.tool_calls.push({\n id: block.id,\n type: 'function',\n function: {\n name: block.name,\n arguments: block.input,\n },\n });\n break;\n case 'tool_result':\n const formattedToolResult = this.convertToolOutputToString(\n block.output,\n this.promoteMultimodalToolResult\n );\n\n cachedMsgs.push({\n role: 'tool',\n tool_call_id: block.id,\n name: block.name,\n content: formattedToolResult.text,\n });\n if (formattedToolResult.promotedMsg) {\n // Insert the promoted message into the array as the next message to be processed\n msgs.splice(index + 1, 0, formattedToolResult.promotedMsg);\n }\n break;\n case 'data':\n formattedMsg.content.push(...this._formatMultimodalBlock(block));\n break;\n }\n }\n if (formattedMsg.content.length > 0 || formattedMsg.tool_calls) {\n formattedMsgs.push(formattedMsg);\n }\n if (cachedMsgs.length > 0) {\n formattedMsgs.push(...cachedMsgs);\n }\n\n // Process next message\n index++;\n }\n return formattedMsgs;\n }\n\n /**\n * Format a text content block into the required format.\n *\n * @param block - The text content block to format.\n * @returns An object representing the formatted text content.\n */\n _formatTextBlock(block: TextBlock) {\n return { text: block.text };\n }\n\n /**\n * Format a multimodal data block into the required format.\n * In DashScope API, the local file paths should be prefixed with \"file://\". URLs are kept unchanged.\n *\n * @param block - The multimodal content block to format.\n * @returns An object representing the formatted multimodal content.\n */\n _formatMultimodalBlock(block: DataBlock) {\n const type = block.source.mediaType.split('/')[0];\n\n if (!['image', 'audio', 'video'].includes(type)) {\n console.log(\n `Skip unsupported media type ${block.source.mediaType} in DashScopeChatFormatter. Only image, audio and video are supported.`\n );\n return [];\n }\n\n if (block.source.type === 'url') {\n return [{ [type]: block.source.url }];\n }\n\n return [\n {\n [type]: `data:${block.source.mediaType};base64,${block.source.data}`,\n },\n ];\n }\n}\n","import { FormatterBase } from './base';\nimport { Msg, getContentBlocks } from '../message';\n\ninterface DeepSeekFormatterOptions {\n /**\n * Most LLM APIs don't support multimodal tool outputs, this option controls whether to\n * promote multimodal tool results to follow-up user messages.\n */\n promoteMultimodalToolResult?:\n | {\n image?: boolean;\n audio?: boolean;\n video?: boolean;\n }\n | boolean;\n}\n\n/**\n * Format AgentScope message objects into DeepSeek Chat Completions message format.\n */\nexport class DeepSeekChatFormatter extends FormatterBase {\n private promoteMultimodalToolResult:\n | { image?: boolean; audio?: boolean; video?: boolean }\n | boolean;\n\n /**\n * Initializes a new instance of the DeepSeekChatFormatter class.\n * @param root0\n * @param root0.promoteMultimodalToolResult\n */\n constructor({ promoteMultimodalToolResult = false }: DeepSeekFormatterOptions = {}) {\n super();\n this.promoteMultimodalToolResult = promoteMultimodalToolResult;\n }\n\n /**\n * Format the input messages into the structure expected by DeepSeek Chat Completions API.\n * @param root0\n * @param root0.msgs\n * @returns An array of formatted message objects ready to be sent to the DeepSeek API.\n */\n async format({ msgs }: { msgs: Array<Msg> }): Promise<Record<string, unknown>[]> {\n const formattedMsgs: Array<Record<string, unknown>> = [];\n let index = 0;\n\n while (index < msgs.length) {\n const msg = msgs[index];\n const formattedMsg: {\n role: string;\n name: string;\n content: Record<string, unknown>[] | null;\n tool_calls?: {\n id: string;\n type: 'function';\n function: {\n name: string;\n arguments: string;\n };\n }[];\n } = {\n role: msg.role,\n name: msg.name,\n content: null,\n };\n const content: Record<string, unknown>[] = [];\n\n // Cache tool-result messages to keep the sequence right after current message.\n const cachedMsgs: Record<string, unknown>[] = [];\n for (const block of getContentBlocks(msg)) {\n switch (block.type) {\n case 'text':\n content.push({\n type: 'text',\n text: block.text,\n });\n break;\n case 'thinking':\n break;\n case 'tool_call':\n if (!formattedMsg.tool_calls) {\n formattedMsg.tool_calls = [];\n }\n formattedMsg.tool_calls.push({\n id: block.id,\n type: 'function',\n function: {\n name: block.name,\n arguments: block.input,\n },\n });\n break;\n case 'tool_result':\n const formattedToolResult = this.convertToolOutputToString(\n block.output,\n this.promoteMultimodalToolResult\n );\n cachedMsgs.push({\n role: 'tool',\n tool_call_id: block.id,\n name: block.name,\n content: formattedToolResult.text,\n });\n if (formattedToolResult.promotedMsg?.content.length) {\n msgs.splice(index + 1, 0, formattedToolResult.promotedMsg);\n }\n break;\n case 'data':\n console.warn(\n `DeepSeek models don't support multimodal data for now (2026-03), skip the data block in message content.`\n );\n break;\n }\n }\n\n if (content.length > 0) {\n formattedMsg.content = content;\n }\n if (formattedMsg.content || formattedMsg.tool_calls) {\n formattedMsgs.push(formattedMsg);\n }\n if (cachedMsgs.length > 0) {\n formattedMsgs.push(...cachedMsgs);\n }\n\n index++;\n }\n\n return formattedMsgs;\n }\n}\n","import { FormatterBase } from './base';\nimport { Msg, getContentBlocks, getTextContent } from '../message';\n\n/**\n * Format AgentScope message objects into Ollama Chat message format.\n * Ollama expects simple string content, not the multimodal array format.\n */\nexport class OllamaChatFormatter extends FormatterBase {\n // eslint-disable-next-line jsdoc/require-returns\n /**\n * Format messages for Ollama API\n * @param root0\n * @param root0.msgs\n */\n async format({ msgs }: { msgs: Array<Msg> }): Promise<Record<string, unknown>[]> {\n const formattedMsgs: Array<Record<string, unknown>> = [];\n\n for (const msg of msgs) {\n const formattedMsg: {\n role: string;\n content: string;\n tool_calls?: {\n function: {\n name: string;\n arguments: Record<string, unknown>;\n };\n }[];\n } = {\n role: msg.role,\n content: '',\n };\n\n // Extract text content\n const textContent = getTextContent(msg);\n if (textContent) {\n formattedMsg.content = textContent;\n }\n\n // Handle tool calls\n const toolCalls = getContentBlocks(msg, 'tool_call');\n if (toolCalls.length > 0) {\n formattedMsg.tool_calls = toolCalls.map(toolCall => ({\n function: {\n name: toolCall.name,\n arguments: JSON.parse(toolCall.input),\n },\n }));\n }\n\n // Handle tool results\n const toolResults = getContentBlocks(msg, 'tool_result');\n for (const toolResult of toolResults) {\n const resultText = this.convertToolOutputToString(toolResult.output, false);\n formattedMsgs.push({\n role: 'tool',\n content: resultText.text,\n });\n }\n\n if (formattedMsg.content || formattedMsg.tool_calls) {\n formattedMsgs.push(formattedMsg);\n }\n }\n\n return formattedMsgs;\n }\n}\n","import { existsSync } from 'fs';\nimport { readFile } from 'fs/promises';\nimport { extname } from 'path';\nimport { fileURLToPath } from 'url';\n\nimport { FormatterBase } from './base';\nimport { DataBlock, Msg, TextBlock, getContentBlocks } from '../message';\n\ninterface OpenAIFormatterOptions {\n /**\n * Most LLM APIs don't support multimodal tool outputs, this option controls whether to\n * promote multimodal tool results to follow-up user messages.\n */\n promoteMultimodalToolResult?:\n | {\n image?: boolean;\n audio?: boolean;\n video?: boolean;\n }\n | boolean;\n}\n\n/**\n * Format AgentScope message objects into OpenAI Chat Completions message format.\n */\nexport class OpenAIChatFormatter extends FormatterBase {\n private promoteMultimodalToolResult:\n | { image?: boolean; audio?: boolean; video?: boolean }\n | boolean;\n\n /**\n * Initializes a new instance of the OpenAIChatFormatter class.\n * @param root0\n * @param root0.promoteMultimodalToolResult\n */\n constructor({ promoteMultimodalToolResult = false }: OpenAIFormatterOptions = {}) {\n super();\n this.promoteMultimodalToolResult = promoteMultimodalToolResult;\n }\n\n /**\n * Format the input messages into OpenAI Chat Completions message format.\n * @param root0\n * @param root0.msgs\n * @returns An array of formatted messages compatible with OpenAI Chat Completions API.\n */\n async format({ msgs }: { msgs: Array<Msg> }): Promise<Record<string, unknown>[]> {\n const formattedMsgs: Array<Record<string, unknown>> = [];\n let index = 0;\n\n while (index < msgs.length) {\n const msg = msgs[index];\n const formattedMsg: {\n role: string;\n name: string;\n content: Record<string, unknown>[] | null;\n tool_calls?: {\n id: string;\n type: 'function';\n function: {\n name: string;\n arguments: string;\n };\n }[];\n } = {\n role: msg.role,\n name: msg.name,\n content: null,\n };\n const content: Record<string, unknown>[] = [];\n\n // Cache tool-result messages to keep the sequence right after current message.\n const cachedMsgs: Record<string, unknown>[] = [];\n for (const block of getContentBlocks(msg)) {\n switch (block.type) {\n case 'text':\n content.push(this._formatTextBlock(block));\n break;\n case 'thinking':\n break;\n case 'tool_call':\n if (!formattedMsg.tool_calls) {\n formattedMsg.tool_calls = [];\n }\n formattedMsg.tool_calls.push({\n id: block.id,\n type: 'function',\n function: {\n name: block.name,\n arguments: block.input,\n },\n });\n break;\n case 'tool_result':\n const formattedToolResult = this.convertToolOutputToString(\n block.output,\n this.promoteMultimodalToolResult\n );\n cachedMsgs.push({\n role: 'tool',\n tool_call_id: block.id,\n name: block.name,\n content: formattedToolResult.text,\n });\n if (formattedToolResult.promotedMsg?.content.length) {\n msgs.splice(index + 1, 0, formattedToolResult.promotedMsg);\n }\n break;\n case 'data':\n content.push(\n ...(await this._formatMultimodalBlock({ block, role: msg.role }))\n );\n break;\n }\n }\n\n if (content.length > 0) {\n formattedMsg.content = content;\n }\n if (formattedMsg.content || formattedMsg.tool_calls) {\n formattedMsgs.push(formattedMsg);\n }\n if (cachedMsgs.length > 0) {\n formattedMsgs.push(...cachedMsgs);\n }\n\n index++;\n }\n\n return formattedMsgs;\n }\n\n /**\n * Format a text block into OpenAI Chat Completions message content format.\n * @param block\n * @returns An object representing the formatted text block.\n */\n _formatTextBlock(block: TextBlock) {\n return {\n type: 'text',\n text: block.text,\n };\n }\n\n /**\n * Format a multimodal data block into OpenAI Chat Completions message content format.\n * @param root0\n * @param root0.block\n * @param root0.role\n * @returns The formatted content blocks\n */\n async _formatMultimodalBlock({\n block,\n role,\n }: {\n block: DataBlock;\n role: Msg['role'];\n }): Promise<Record<string, unknown>[]> {\n const type = block.source.mediaType.split('/')[0];\n if (type === 'image') {\n return [\n {\n type: 'image_url',\n image_url: {\n url: await this._toOpenAIImageURL(block),\n },\n },\n ];\n }\n\n if (type === 'audio') {\n // Skip assistant output audio to avoid carrying generated audio back into next request.\n if (role === 'assistant') {\n return [];\n }\n return [\n {\n type: 'input_audio',\n input_audio: await this._toOpenAIAudioData(block),\n },\n ];\n }\n\n console.log(\n `Skip unsupported media type ${block.source.mediaType} in OpenAIChatFormatter. Only image and audio are supported.`\n );\n return [];\n }\n\n /**\n * Convert the data block to an OpenAI compatible image URL.\n * @param block\n * @returns A promise that resolves to a string representing the image URL in a format compatible with OpenAI Chat Completions API.\n */\n protected async _toOpenAIImageURL(block: DataBlock): Promise<string> {\n if (block.source.type === 'base64') {\n return `data:${block.source.mediaType};base64,${block.source.data}`;\n }\n\n const sourceUrl = block.source.url;\n if (sourceUrl.startsWith('http://') || sourceUrl.startsWith('https://')) {\n return sourceUrl;\n }\n if (sourceUrl.startsWith('data:')) {\n return sourceUrl;\n }\n\n const localPath = this._toLocalPath(sourceUrl);\n if (!localPath || !existsSync(localPath)) {\n throw new Error(`Image path not found: ${sourceUrl}`);\n }\n\n const ext = extname(localPath).toLowerCase();\n const supportedImageExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.webp'];\n if (!supportedImageExtensions.includes(ext)) {\n throw new TypeError(\n `Unsupported image extension: ${ext}. Supported: ${supportedImageExtensions.join(', ')}`\n );\n }\n\n const file = await readFile(localPath);\n const mime = block.source.mediaType || `image/${ext.slice(1)}`;\n return `data:${mime};base64,${file.toString('base64')}`;\n }\n\n /**\n * Converts a data block to OpenAI compatible audio data format.\n *\n * @param block - The data block containing audio information.\n * @returns A promise that resolves to an object with audio data and format.\n */\n protected async _toOpenAIAudioData(\n block: DataBlock\n ): Promise<{ data: string; format: 'wav' | 'mp3' }> {\n const supportedMediaTypes = new Map<string, 'wav' | 'mp3'>([\n ['audio/wav', 'wav'],\n ['audio/mp3', 'mp3'],\n ['audio/mpeg', 'mp3'],\n ]);\n\n if (block.source.type === 'base64') {\n const format = supportedMediaTypes.get(block.source.mediaType);\n if (!format) {\n throw new TypeError(\n `Unsupported audio media type: ${block.source.mediaType}, only audio/wav and audio/mp3 are supported.`\n );\n }\n return { data: block.source.data, format };\n }\n\n const sourceUrl = block.source.url;\n const localPath = this._toLocalPath(sourceUrl);\n let data: string;\n\n if (localPath && existsSync(localPath)) {\n const file = await readFile(localPath);\n data = file.toString('base64');\n } else if (sourceUrl.startsWith('http://') || sourceUrl.startsWith('https://')) {\n const response = await fetch(sourceUrl);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch audio from URL: ${sourceUrl} (${response.status})`\n );\n }\n const arr = await response.arrayBuffer();\n data = Buffer.from(arr).toString('base64');\n } else {\n throw new Error(\n `Unsupported audio source: ${sourceUrl}, it should be a local file path, file URL, or an HTTP URL.`\n );\n }\n\n const ext = extname(localPath || sourceUrl).toLowerCase();\n const extToFormat = new Map<string, 'wav' | 'mp3'>([\n ['.wav', 'wav'],\n ['.mp3', 'mp3'],\n ]);\n const format = extToFormat.get(ext);\n if (!format) {\n throw new TypeError(`Unsupported audio extension: ${ext}, wav and mp3 are supported.`);\n }\n\n return { data, format };\n }\n\n /**\n * Converts a URL or path to a local file path.\n *\n * @param urlOrPath - The URL or path to convert.\n * @returns The local file path, or null if not a local path.\n */\n protected _toLocalPath(urlOrPath: string) {\n if (urlOrPath.startsWith('file://')) {\n return fileURLToPath(urlOrPath);\n }\n if (!urlOrPath.includes('://')) {\n return urlOrPath;\n }\n return null;\n }\n}\n"],"mappings":";AA4CO,SAAS,UAAU;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,KAAK,OAAO,WAAW;AAAA,EACvB,aAAY,oBAAI,KAAK,GAAE,YAAY;AAAA,EACnC;AACJ,GAC8D;AAC1D,SAAO,EAAE,IAAI,MAAM,MAAM,SAAS,UAAU,WAAW,MAAM;AACjE;AAYO,SAAS,eAAe,KAAU,YAAoB,MAAqB;AAC9E,QAAM,aAAa,IAAI,QAAQ,OAAO,WAAS,MAAM,SAAS,MAAM;AACpE,MAAI,WAAW,WAAW,GAAG;AACzB,WAAO;AAAA,EACX;AACA,SAAO,WAAW,IAAI,WAAU,MAAoB,IAAI,EAAE,KAAK,SAAS;AAC5E;AAmDO,SAAS,iBACZ,KACA,WACc;AACd,MAAI,CAAC,UAAW,QAAO,IAAI;AAC3B,SAAO,IAAI,QAAQ,OAAO,WAAS,MAAM,SAAS,SAAS;AAC/D;;;AC7HO,IAAe,gBAAf,MAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBhC,0BACI,QACA,6BACF;AACE,QAAI,OAAO,WAAW,SAAU,QAAO,EAAE,MAAM,QAAQ,aAAa,KAAK;AAEzE,QAAI,gBAAgB,CAAC;AAErB,UAAM,eAAmD,CAAC;AAE1D,eAAW,SAAS,QAAQ;AACxB,cAAQ,MAAM,MAAM;AAAA,QAChB,KAAK;AACD,wBAAc,KAAK,MAAM,IAAI;AAC7B;AAAA,QACJ;AACI,gBAAM,OAAO,MAAM,OAAO,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QAAQ,aAAa,SAAS,EAAE,YAAY;AACxD,UAAM,cAAc,oBAAI,IAA2B;AAAA,MAC/C,CAAC,QAAQ,KAAK;AAAA,MACd,CAAC,QAAQ,KAAK;AAAA,IAClB,CAAC;AACD,UAAM,SAAS,YAAY,IAAI,GAAG;AAClC,QAAI,CAAC,QAAQ;AACT,YAAM,IAAI,UAAU,gCAAgC,GAAG,8BAA8B;AAAA,IACzF;AAEA,WAAO,EAAE,MAAM,OAAO;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQU,aAAa,WAAmB;AACtC,QAAI,UAAU,WAAW,SAAS,GAAG;AACjC,aAAO,cAAc,SAAS;AAAA,IAClC;AACA,QAAI,CAAC,UAAU,SAAS,KAAK,GAAG;AAC5B,aAAO;AAAA,IACX;AACA,WAAO;AAAA,EACX;AACJ;","names":["format"]}
@@ -0,0 +1,195 @@
1
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
+ import { SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js';
3
+ import { StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
4
+ import { RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';
5
+ import z$1, { z } from 'zod';
6
+ import { J as JSONSerializableObject, b as ToolInputSchema } from './index-CAxQAkiP.mjs';
7
+ import { T as TextBlock, D as DataBlock } from './block-VsnHrllL.mjs';
8
+ import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
9
+
10
+ /**
11
+ * The tool response structure.
12
+ */
13
+ interface ToolResponse {
14
+ content: Array<TextBlock | DataBlock>;
15
+ id: string;
16
+ createdAt: string;
17
+ metadata: Record<string, JSONSerializableObject>;
18
+ state: 'success' | 'error' | 'interrupted' | 'running';
19
+ isLast: boolean;
20
+ isInterrupted: boolean;
21
+ }
22
+
23
+ interface Tool {
24
+ name: string;
25
+ description: string;
26
+ inputSchema: z.ZodObject | ToolInputSchema;
27
+ call?: (input: any) => string | Promise<string> | Generator<string> | AsyncGenerator<string> | ToolResponse | Promise<ToolResponse> | Generator<ToolResponse> | AsyncGenerator<ToolResponse>;
28
+ requireUserConfirm?: boolean;
29
+ }
30
+
31
+ /**
32
+ * Type definition for getting a client instance
33
+ */
34
+ type GetClient = () => Promise<Client>;
35
+ /**
36
+ * Type definition for releasing a client instance
37
+ */
38
+ type ReleaseClient = (client: Client) => Promise<void>;
39
+ /**
40
+ * MCPTool class that wraps an MCP tool and provides a callable interface
41
+ */
42
+ declare class MCPTool implements Tool {
43
+ name: string;
44
+ description: string;
45
+ inputSchema: z$1.ZodObject | ToolInputSchema;
46
+ requireUserConfirm: boolean;
47
+ call: (input: Record<string, unknown>) => Promise<ToolResponse>;
48
+ private getClient;
49
+ private releaseClient;
50
+ /**
51
+ * Initialize an MCPTool instance
52
+ * @param root0
53
+ * @param root0.name
54
+ * @param root0.description
55
+ * @param root0.inputSchema
56
+ * @param root0.getClient
57
+ * @param root0.releaseClient
58
+ */
59
+ constructor({ name, description, inputSchema, getClient, releaseClient, }: {
60
+ name: string;
61
+ description: string;
62
+ inputSchema: z$1.ZodObject | ToolInputSchema;
63
+ getClient: GetClient;
64
+ releaseClient: ReleaseClient;
65
+ });
66
+ /**
67
+ * Call the MCP tool with the specified input arguments. This method sends a request to the MCP server to execute
68
+ * the tool and returns the result as a ToolResponse.
69
+ *
70
+ * @param arguments
71
+ * @param input
72
+ * @returns A ToolResponse object containing the result of the tool execution, or an error message if the call fails.
73
+ */
74
+ _call(input: Record<string, unknown>): Promise<ToolResponse>;
75
+ }
76
+
77
+ /**
78
+ * The HTTP MCP client class that connects to an MCP server using either Streamable HTTP or Server-Sent Events (SSE)
79
+ * transport.
80
+ * Note the client is stateful, meaning that developers should manually call the `connect()` and `close()` methods to
81
+ * manage the connection lifecycle.
82
+ */
83
+ declare class HTTPMCPClient {
84
+ name: string;
85
+ private requestOptions?;
86
+ private client?;
87
+ private transport?;
88
+ private transportType;
89
+ private url;
90
+ private transportOpts?;
91
+ private stateful;
92
+ /**
93
+ * Initialize the HTTPStatefulMCPClient with the specified transport type, URL, and options.
94
+ *
95
+ * @param root0
96
+ * @param root0.name
97
+ * @param root0.transportType
98
+ * @param root0.url
99
+ * @param root0.stateful
100
+ * @param root0.transportOpts
101
+ * @param root0.requestOptions
102
+ */
103
+ constructor({ name, transportType, url, stateful, transportOpts, requestOptions, }: {
104
+ name: string;
105
+ transportType: 'streamable-http' | 'sse';
106
+ url: string;
107
+ stateful?: boolean;
108
+ transportOpts?: StreamableHTTPClientTransportOptions | SSEClientTransportOptions;
109
+ requestOptions?: RequestOptions;
110
+ });
111
+ /**
112
+ * Connect to the MCP server with the specified transport and URL. This method must be called before making any
113
+ * requests to the server.
114
+ */
115
+ connect(): Promise<void>;
116
+ /**
117
+ * The internal method to establish the connection to the MCP server. It initializes the appropriate transport
118
+ * based on the specified transport type and creates a new Client instance to manage the connection and requests.
119
+ */
120
+ protected _connect(): Promise<void>;
121
+ /**
122
+ * List all tools available on the MCP server.
123
+ *
124
+ * @returns An array of MCPTool instances representing the tools available on the server.
125
+ */
126
+ listTools(): Promise<MCPTool[]>;
127
+ /**
128
+ * Close the connection to the MCP server and clean up any resources used by the client.
129
+ */
130
+ close(): Promise<void>;
131
+ /**
132
+ * The internal method to close the connection to the MCP server.
133
+ */
134
+ protected _close(): Promise<void>;
135
+ /**
136
+ * Create a new client instance without storing it in this.client.
137
+ * Used for stateless operations where each request needs its own client.
138
+ * @returns A new connected Client instance
139
+ */
140
+ protected _createClient(): Promise<Client>;
141
+ /**
142
+ * Get a callable function for a specific tool by its name.
143
+ * @param root0
144
+ * @param root0.name
145
+ * @returns An instance of MCPTool that can be called to execute the tool's functionality.
146
+ */
147
+ getCallableFunction({ name }: {
148
+ name: string;
149
+ }): Promise<MCPTool>;
150
+ }
151
+
152
+ /**
153
+ * The STDIO MCP client class.
154
+ */
155
+ declare class StdioMCPClient {
156
+ name: string;
157
+ private stdioServerParameters;
158
+ private transport?;
159
+ private client?;
160
+ /**
161
+ * Initialize the StdioMCPClient with the given Stdio parameters.
162
+ *
163
+ * @param root0
164
+ * @param root0.name
165
+ */
166
+ constructor({ name, ...rest }: {
167
+ name: string;
168
+ } & StdioServerParameters);
169
+ /**
170
+ * Connect to the MCP server using Stdio transport. Note the Stdio client will start an
171
+ * MCP server process under the hood.
172
+ */
173
+ connect(): Promise<void>;
174
+ /**
175
+ * Close the connection and stop the MCP server process.
176
+ */
177
+ close(): Promise<void>;
178
+ /**
179
+ * List all tools available on the MCP server.
180
+ *
181
+ * @returns An array of MCPTool instances representing the tools available on the server.
182
+ */
183
+ listTools(): Promise<MCPTool[]>;
184
+ /**
185
+ * Get a callable function for a specific tool by its name.
186
+ * @param root0
187
+ * @param root0.name
188
+ * @returns An instance of MCPTool that can be called to execute the tool's functionality.
189
+ */
190
+ getCallableFunction({ name }: {
191
+ name: string;
192
+ }): Promise<MCPTool>;
193
+ }
194
+
195
+ export { HTTPMCPClient as H, StdioMCPClient as S, type Tool as T, type ToolResponse as a };
@@ -0,0 +1,195 @@
1
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
+ import { SSEClientTransportOptions } from '@modelcontextprotocol/sdk/client/sse.js';
3
+ import { StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
4
+ import { RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';
5
+ import z$1, { z } from 'zod';
6
+ import { J as JSONSerializableObject, b as ToolInputSchema } from './index-CAxQAkiP.js';
7
+ import { T as TextBlock, D as DataBlock } from './block-VsnHrllL.js';
8
+ import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
9
+
10
+ /**
11
+ * The tool response structure.
12
+ */
13
+ interface ToolResponse {
14
+ content: Array<TextBlock | DataBlock>;
15
+ id: string;
16
+ createdAt: string;
17
+ metadata: Record<string, JSONSerializableObject>;
18
+ state: 'success' | 'error' | 'interrupted' | 'running';
19
+ isLast: boolean;
20
+ isInterrupted: boolean;
21
+ }
22
+
23
+ interface Tool {
24
+ name: string;
25
+ description: string;
26
+ inputSchema: z.ZodObject | ToolInputSchema;
27
+ call?: (input: any) => string | Promise<string> | Generator<string> | AsyncGenerator<string> | ToolResponse | Promise<ToolResponse> | Generator<ToolResponse> | AsyncGenerator<ToolResponse>;
28
+ requireUserConfirm?: boolean;
29
+ }
30
+
31
+ /**
32
+ * Type definition for getting a client instance
33
+ */
34
+ type GetClient = () => Promise<Client>;
35
+ /**
36
+ * Type definition for releasing a client instance
37
+ */
38
+ type ReleaseClient = (client: Client) => Promise<void>;
39
+ /**
40
+ * MCPTool class that wraps an MCP tool and provides a callable interface
41
+ */
42
+ declare class MCPTool implements Tool {
43
+ name: string;
44
+ description: string;
45
+ inputSchema: z$1.ZodObject | ToolInputSchema;
46
+ requireUserConfirm: boolean;
47
+ call: (input: Record<string, unknown>) => Promise<ToolResponse>;
48
+ private getClient;
49
+ private releaseClient;
50
+ /**
51
+ * Initialize an MCPTool instance
52
+ * @param root0
53
+ * @param root0.name
54
+ * @param root0.description
55
+ * @param root0.inputSchema
56
+ * @param root0.getClient
57
+ * @param root0.releaseClient
58
+ */
59
+ constructor({ name, description, inputSchema, getClient, releaseClient, }: {
60
+ name: string;
61
+ description: string;
62
+ inputSchema: z$1.ZodObject | ToolInputSchema;
63
+ getClient: GetClient;
64
+ releaseClient: ReleaseClient;
65
+ });
66
+ /**
67
+ * Call the MCP tool with the specified input arguments. This method sends a request to the MCP server to execute
68
+ * the tool and returns the result as a ToolResponse.
69
+ *
70
+ * @param arguments
71
+ * @param input
72
+ * @returns A ToolResponse object containing the result of the tool execution, or an error message if the call fails.
73
+ */
74
+ _call(input: Record<string, unknown>): Promise<ToolResponse>;
75
+ }
76
+
77
+ /**
78
+ * The HTTP MCP client class that connects to an MCP server using either Streamable HTTP or Server-Sent Events (SSE)
79
+ * transport.
80
+ * Note the client is stateful, meaning that developers should manually call the `connect()` and `close()` methods to
81
+ * manage the connection lifecycle.
82
+ */
83
+ declare class HTTPMCPClient {
84
+ name: string;
85
+ private requestOptions?;
86
+ private client?;
87
+ private transport?;
88
+ private transportType;
89
+ private url;
90
+ private transportOpts?;
91
+ private stateful;
92
+ /**
93
+ * Initialize the HTTPStatefulMCPClient with the specified transport type, URL, and options.
94
+ *
95
+ * @param root0
96
+ * @param root0.name
97
+ * @param root0.transportType
98
+ * @param root0.url
99
+ * @param root0.stateful
100
+ * @param root0.transportOpts
101
+ * @param root0.requestOptions
102
+ */
103
+ constructor({ name, transportType, url, stateful, transportOpts, requestOptions, }: {
104
+ name: string;
105
+ transportType: 'streamable-http' | 'sse';
106
+ url: string;
107
+ stateful?: boolean;
108
+ transportOpts?: StreamableHTTPClientTransportOptions | SSEClientTransportOptions;
109
+ requestOptions?: RequestOptions;
110
+ });
111
+ /**
112
+ * Connect to the MCP server with the specified transport and URL. This method must be called before making any
113
+ * requests to the server.
114
+ */
115
+ connect(): Promise<void>;
116
+ /**
117
+ * The internal method to establish the connection to the MCP server. It initializes the appropriate transport
118
+ * based on the specified transport type and creates a new Client instance to manage the connection and requests.
119
+ */
120
+ protected _connect(): Promise<void>;
121
+ /**
122
+ * List all tools available on the MCP server.
123
+ *
124
+ * @returns An array of MCPTool instances representing the tools available on the server.
125
+ */
126
+ listTools(): Promise<MCPTool[]>;
127
+ /**
128
+ * Close the connection to the MCP server and clean up any resources used by the client.
129
+ */
130
+ close(): Promise<void>;
131
+ /**
132
+ * The internal method to close the connection to the MCP server.
133
+ */
134
+ protected _close(): Promise<void>;
135
+ /**
136
+ * Create a new client instance without storing it in this.client.
137
+ * Used for stateless operations where each request needs its own client.
138
+ * @returns A new connected Client instance
139
+ */
140
+ protected _createClient(): Promise<Client>;
141
+ /**
142
+ * Get a callable function for a specific tool by its name.
143
+ * @param root0
144
+ * @param root0.name
145
+ * @returns An instance of MCPTool that can be called to execute the tool's functionality.
146
+ */
147
+ getCallableFunction({ name }: {
148
+ name: string;
149
+ }): Promise<MCPTool>;
150
+ }
151
+
152
+ /**
153
+ * The STDIO MCP client class.
154
+ */
155
+ declare class StdioMCPClient {
156
+ name: string;
157
+ private stdioServerParameters;
158
+ private transport?;
159
+ private client?;
160
+ /**
161
+ * Initialize the StdioMCPClient with the given Stdio parameters.
162
+ *
163
+ * @param root0
164
+ * @param root0.name
165
+ */
166
+ constructor({ name, ...rest }: {
167
+ name: string;
168
+ } & StdioServerParameters);
169
+ /**
170
+ * Connect to the MCP server using Stdio transport. Note the Stdio client will start an
171
+ * MCP server process under the hood.
172
+ */
173
+ connect(): Promise<void>;
174
+ /**
175
+ * Close the connection and stop the MCP server process.
176
+ */
177
+ close(): Promise<void>;
178
+ /**
179
+ * List all tools available on the MCP server.
180
+ *
181
+ * @returns An array of MCPTool instances representing the tools available on the server.
182
+ */
183
+ listTools(): Promise<MCPTool[]>;
184
+ /**
185
+ * Get a callable function for a specific tool by its name.
186
+ * @param root0
187
+ * @param root0.name
188
+ * @returns An instance of MCPTool that can be called to execute the tool's functionality.
189
+ */
190
+ getCallableFunction({ name }: {
191
+ name: string;
192
+ }): Promise<MCPTool>;
193
+ }
194
+
195
+ export { HTTPMCPClient as H, StdioMCPClient as S, type Tool as T, type ToolResponse as a };
@@ -0,0 +1,21 @@
1
+ type JSONSerializableObject = string | number | boolean | null | JSONSerializableObject[] | {
2
+ [key: string]: JSONSerializableObject;
3
+ };
4
+ type ToolName = string;
5
+ type ToolChoice = 'auto' | 'none' | 'required' | ToolName;
6
+ interface ToolInputSchema {
7
+ type: 'object';
8
+ properties?: Record<string, object>;
9
+ required?: string[];
10
+ [key: string]: unknown;
11
+ }
12
+ interface ToolSchema {
13
+ type: 'function';
14
+ function: {
15
+ name: string;
16
+ description: string;
17
+ parameters: ToolInputSchema;
18
+ };
19
+ }
20
+
21
+ export type { JSONSerializableObject as J, ToolSchema as T, ToolChoice as a, ToolInputSchema as b };
@@ -0,0 +1,21 @@
1
+ type JSONSerializableObject = string | number | boolean | null | JSONSerializableObject[] | {
2
+ [key: string]: JSONSerializableObject;
3
+ };
4
+ type ToolName = string;
5
+ type ToolChoice = 'auto' | 'none' | 'required' | ToolName;
6
+ interface ToolInputSchema {
7
+ type: 'object';
8
+ properties?: Record<string, object>;
9
+ required?: string[];
10
+ [key: string]: unknown;
11
+ }
12
+ interface ToolSchema {
13
+ type: 'function';
14
+ function: {
15
+ name: string;
16
+ description: string;
17
+ parameters: ToolInputSchema;
18
+ };
19
+ }
20
+
21
+ export type { JSONSerializableObject as J, ToolSchema as T, ToolChoice as a, ToolInputSchema as b };
@@ -0,0 +1,9 @@
1
+ export { H as HTTPMCPClient, S as StdioMCPClient } from '../index-BTJDlKvQ.mjs';
2
+ import '@modelcontextprotocol/sdk/client/index.js';
3
+ import '@modelcontextprotocol/sdk/client/sse.js';
4
+ import '@modelcontextprotocol/sdk/client/streamableHttp.js';
5
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
6
+ import 'zod';
7
+ import '../index-CAxQAkiP.mjs';
8
+ import '../block-VsnHrllL.mjs';
9
+ import '@modelcontextprotocol/sdk/client/stdio.js';
@@ -0,0 +1,9 @@
1
+ export { H as HTTPMCPClient, S as StdioMCPClient } from '../index-BcatlwXQ.js';
2
+ import '@modelcontextprotocol/sdk/client/index.js';
3
+ import '@modelcontextprotocol/sdk/client/sse.js';
4
+ import '@modelcontextprotocol/sdk/client/streamableHttp.js';
5
+ import '@modelcontextprotocol/sdk/shared/protocol.js';
6
+ import 'zod';
7
+ import '../index-CAxQAkiP.js';
8
+ import '../block-VsnHrllL.js';
9
+ import '@modelcontextprotocol/sdk/client/stdio.js';