@agentscope-ai/agentscope 0.0.2 → 0.0.3

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 (77) hide show
  1. package/LICENSE +202 -0
  2. package/dist/agent/index.d.mts +10 -10
  3. package/dist/agent/index.d.ts +10 -10
  4. package/dist/agent/index.js +94 -90
  5. package/dist/agent/index.js.map +1 -1
  6. package/dist/agent/index.mjs +94 -90
  7. package/dist/agent/index.mjs.map +1 -1
  8. package/dist/{base-BOx3UzOl.d.mts → base-Bo8TzBQq.d.mts} +2 -2
  9. package/dist/{base-NX-knWOv.d.ts → base-Co-MzdN5.d.ts} +1 -1
  10. package/dist/{base-DYlBMCy_.d.mts → base-D9uCcDjZ.d.mts} +3 -3
  11. package/dist/{base-C7jwyH4Z.d.mts → base-Dh5vEBQD.d.mts} +1 -1
  12. package/dist/{base-Cwi4bjze.d.ts → base-TYjCCv7T.d.ts} +3 -3
  13. package/dist/{base-BoIps2RL.d.ts → base-t7G4uaR_.d.ts} +2 -2
  14. package/dist/{block-VsnHrllL.d.mts → block-7fd6byyN.d.mts} +2 -2
  15. package/dist/{block-VsnHrllL.d.ts → block-7fd6byyN.d.ts} +2 -2
  16. package/dist/event/index.d.mts +105 -89
  17. package/dist/event/index.d.ts +105 -89
  18. package/dist/event/index.js +8 -8
  19. package/dist/event/index.js.map +1 -1
  20. package/dist/event/index.mjs +8 -8
  21. package/dist/event/index.mjs.map +1 -1
  22. package/dist/formatter/index.d.mts +3 -3
  23. package/dist/formatter/index.d.ts +3 -3
  24. package/dist/formatter/index.js +17 -17
  25. package/dist/formatter/index.js.map +1 -1
  26. package/dist/formatter/index.mjs +17 -17
  27. package/dist/formatter/index.mjs.map +1 -1
  28. package/dist/{index-BTJDlKvQ.d.mts → index-BVNbIN62.d.mts} +1 -1
  29. package/dist/{index-BcatlwXQ.d.ts → index-DaopL-Vp.d.ts} +1 -1
  30. package/dist/mcp/index.d.mts +2 -2
  31. package/dist/mcp/index.d.ts +2 -2
  32. package/dist/mcp/index.js +1 -1
  33. package/dist/mcp/index.js.map +1 -1
  34. package/dist/mcp/index.mjs +1 -1
  35. package/dist/mcp/index.mjs.map +1 -1
  36. package/dist/message/index.d.mts +2 -2
  37. package/dist/message/index.d.ts +2 -2
  38. package/dist/message/index.js +39 -5
  39. package/dist/message/index.js.map +1 -1
  40. package/dist/message/index.mjs +36 -5
  41. package/dist/message/index.mjs.map +1 -1
  42. package/dist/{message-CkN21KaY.d.mts → message-CYnHiEVt.d.mts} +66 -43
  43. package/dist/{message-CzLeTlua.d.ts → message-DZN7LetB.d.ts} +66 -43
  44. package/dist/model/index.d.mts +5 -5
  45. package/dist/model/index.d.ts +5 -5
  46. package/dist/model/index.js +17 -17
  47. package/dist/model/index.js.map +1 -1
  48. package/dist/model/index.mjs +17 -17
  49. package/dist/model/index.mjs.map +1 -1
  50. package/dist/storage/index.d.mts +3 -3
  51. package/dist/storage/index.d.ts +3 -3
  52. package/dist/storage/index.js +4 -4
  53. package/dist/storage/index.js.map +1 -1
  54. package/dist/storage/index.mjs +4 -4
  55. package/dist/storage/index.mjs.map +1 -1
  56. package/dist/tool/index.d.mts +4 -4
  57. package/dist/tool/index.d.ts +4 -4
  58. package/dist/{toolkit-CEpulFi0.d.ts → toolkit-BuMTkbGg.d.ts} +2 -2
  59. package/dist/{toolkit-CGEZSZPa.d.mts → toolkit-CH9qKAy9.d.mts} +2 -2
  60. package/package.json +87 -87
  61. package/src/agent/agent.test.ts +63 -63
  62. package/src/agent/agent.ts +101 -99
  63. package/src/agent/test-compression.ts +1 -1
  64. package/src/event/index.ts +96 -98
  65. package/src/formatter/base.ts +3 -3
  66. package/src/formatter/dashscope-chat-formatter.test.ts +8 -8
  67. package/src/formatter/dashscope-chat-formatter.ts +3 -3
  68. package/src/formatter/openai-chat-formatter.test.ts +4 -4
  69. package/src/formatter/openai-chat-formatter.ts +6 -6
  70. package/src/mcp/base.ts +1 -1
  71. package/src/message/block.ts +2 -2
  72. package/src/message/index.ts +9 -1
  73. package/src/message/message.test.ts +1 -1
  74. package/src/message/message.ts +101 -47
  75. package/src/permission/index.ts +13 -0
  76. package/src/storage/file-system.test.ts +3 -3
  77. package/src/storage/file-system.ts +4 -4
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mcp/http.ts","../../src/mcp/base.ts","../../src/tool/response.ts","../../src/mcp/stdio.ts"],"sourcesContent":["import { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport {\n SSEClientTransport,\n SSEClientTransportOptions,\n} from '@modelcontextprotocol/sdk/client/sse.js';\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport { StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport type { RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { ListToolsRequest, ListToolsResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';\n\nimport { MCPTool } from './base';\n\n/**\n * The HTTP MCP client class that connects to an MCP server using either Streamable HTTP or Server-Sent Events (SSE)\n * transport.\n * Note the client is stateful, meaning that developers should manually call the `connect()` and `close()` methods to\n * manage the connection lifecycle.\n */\nexport class HTTPMCPClient {\n name: string;\n private requestOptions?: RequestOptions;\n private client?: Client;\n private transport?: StreamableHTTPClientTransport | SSEClientTransport;\n private transportType: 'streamable-http' | 'sse';\n private url: string;\n private transportOpts?: StreamableHTTPClientTransportOptions | SSEClientTransportOptions;\n private stateful: boolean;\n\n /**\n * Initialize the HTTPStatefulMCPClient with the specified transport type, URL, and options.\n *\n * @param root0\n * @param root0.name\n * @param root0.transportType\n * @param root0.url\n * @param root0.stateful\n * @param root0.transportOpts\n * @param root0.requestOptions\n */\n constructor({\n name,\n transportType,\n url,\n stateful = true,\n transportOpts,\n requestOptions,\n }: {\n name: string;\n transportType: 'streamable-http' | 'sse';\n url: string;\n stateful?: boolean;\n transportOpts?: StreamableHTTPClientTransportOptions | SSEClientTransportOptions;\n requestOptions?: RequestOptions;\n }) {\n this.name = name;\n this.transportType = transportType;\n this.transportOpts = transportOpts;\n this.requestOptions = requestOptions;\n this.url = url;\n this.stateful = stateful;\n }\n\n /**\n * Connect to the MCP server with the specified transport and URL. This method must be called before making any\n * requests to the server.\n */\n async connect() {\n if (!this.stateful) {\n console.log(\n `MCP client '${this.name}' initialized with stateful=false will connect and close the connection automatically for each request, no need to call 'connect()' method explicitly.`\n );\n } else {\n await this._connect();\n }\n }\n\n /**\n * The internal method to establish the connection to the MCP server. It initializes the appropriate transport\n * based on the specified transport type and creates a new Client instance to manage the connection and requests.\n */\n protected async _connect() {\n const baseUrl = new URL(this.url);\n if (this.transportType === 'streamable-http') {\n this.transport = new StreamableHTTPClientTransport(baseUrl, this.transportOpts);\n } else {\n this.transport = new SSEClientTransport(baseUrl, this.transportOpts);\n }\n this.client = new Client({\n name: this.name,\n version: '1.0.0',\n });\n await this.client.connect(this.transport, this.requestOptions);\n console.log(`MCP client '${this.name}' is connected`);\n }\n\n /**\n * List all tools available on the MCP server.\n *\n * @returns An array of MCPTool instances representing the tools available on the server.\n */\n async listTools(): Promise<MCPTool[]> {\n let listClient: Client;\n\n if (this.stateful) {\n if (!this.client) {\n throw new Error(\n `Client not initialized, call 'connect()' method first for the MCP client named '${this.name}'`\n );\n }\n listClient = this.client;\n } else {\n listClient = await this._createClient();\n }\n\n try {\n const toolsRequest: ListToolsRequest = {\n method: 'tools/list',\n params: {},\n };\n\n const toolsResult = await listClient.request(toolsRequest, ListToolsResultSchema);\n if (toolsResult.tools === undefined) {\n return [];\n }\n\n return toolsResult.tools.map((tool: Tool) => {\n if (this.stateful) {\n return new MCPTool({\n name: tool.name,\n description: tool.description || '',\n inputSchema: tool.inputSchema,\n getClient: async () => this.client!,\n releaseClient: async () => {},\n });\n } else {\n return new MCPTool({\n name: tool.name,\n description: tool.description || '',\n inputSchema: tool.inputSchema,\n getClient: () => this._createClient(),\n releaseClient: async (c: Client) => {\n await c.close();\n },\n });\n }\n });\n } finally {\n if (!this.stateful) {\n await listClient.close();\n }\n }\n }\n\n /**\n * Close the connection to the MCP server and clean up any resources used by the client.\n */\n async close() {\n if (!this.stateful) {\n console.log(\n `MCP client '${this.name}' initialized with stateful=false will connect and close the connection automatically for each request, no need to call 'close()' method explicitly.`\n );\n } else {\n await this._close();\n }\n }\n\n /**\n * The internal method to close the connection to the MCP server.\n */\n protected async _close() {\n try {\n await this.client?.close();\n } finally {\n console.log(`MCP client '${this.name} is closed.'`);\n this.client = undefined;\n this.transport = undefined;\n }\n }\n\n /**\n * Create a new client instance without storing it in this.client.\n * Used for stateless operations where each request needs its own client.\n * @returns A new connected Client instance\n */\n protected async _createClient(): Promise<Client> {\n const baseUrl = new URL(this.url);\n const transport =\n this.transportType === 'streamable-http'\n ? new StreamableHTTPClientTransport(baseUrl, this.transportOpts)\n : new SSEClientTransport(baseUrl, this.transportOpts);\n\n const client = new Client({\n name: this.name,\n version: '1.0.0',\n });\n await client.connect(transport, this.requestOptions);\n return client;\n }\n\n /**\n * Get a callable function for a specific tool by its name.\n * @param root0\n * @param root0.name\n * @returns An instance of MCPTool that can be called to execute the tool's functionality.\n */\n async getCallableFunction({ name }: { name: string }) {\n if (this.stateful && !this.client) {\n throw new Error(\n `Client not initialized, call 'connect()' method first for the MCP client named '${this.name}'`\n );\n }\n\n const tools = await this.listTools();\n const targetTool = tools.find(tool => tool.name === name);\n\n if (!targetTool) {\n throw new Error(\n `Tool '${name}' not found in MCP server '${this.name}'. Available tools: ${tools.map(t => t.name).join(', ')}`\n );\n }\n\n return targetTool;\n }\n}\n","import { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { CallToolRequest, CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport z from 'zod';\n\nimport { Tool, ToolResponse } from '../tool';\nimport { createToolResponse } from '../tool/response';\nimport { ToolInputSchema } from '../type';\n\n/**\n * Type definition for getting a client instance\n */\ntype GetClient = () => Promise<Client>;\n\n/**\n * Type definition for releasing a client instance\n */\ntype ReleaseClient = (client: Client) => Promise<void>;\n\n/**\n * MCPTool class that wraps an MCP tool and provides a callable interface\n */\nexport class MCPTool implements Tool {\n name: string;\n description: string;\n inputSchema: z.ZodObject | ToolInputSchema;\n requireUserConfirm = false;\n call: (input: Record<string, unknown>) => Promise<ToolResponse>;\n\n private getClient: GetClient;\n private releaseClient: ReleaseClient;\n\n /**\n * Initialize an MCPTool instance\n * @param root0\n * @param root0.name\n * @param root0.description\n * @param root0.inputSchema\n * @param root0.getClient\n * @param root0.releaseClient\n */\n constructor({\n name,\n description,\n inputSchema,\n getClient,\n releaseClient,\n }: {\n name: string;\n description: string;\n inputSchema: z.ZodObject | ToolInputSchema;\n getClient: GetClient;\n releaseClient: ReleaseClient;\n }) {\n this.name = name;\n this.description = description;\n this.inputSchema = inputSchema;\n this.getClient = getClient;\n this.releaseClient = releaseClient;\n this.call = this._call.bind(this);\n }\n\n /**\n * Call the MCP tool with the specified input arguments. This method sends a request to the MCP server to execute\n * the tool and returns the result as a ToolResponse.\n *\n * @param arguments\n * @param input\n * @returns A ToolResponse object containing the result of the tool execution, or an error message if the call fails.\n */\n async _call(input: Record<string, unknown>) {\n const client = await this.getClient();\n try {\n const request: CallToolRequest = {\n method: 'tools/call',\n params: {\n name: this.name,\n arguments: input,\n },\n };\n const result = await client.request(request, CallToolResultSchema);\n\n const content: ToolResponse['content'] = [];\n result.content.forEach(item => {\n if (item.type === 'text') {\n content.push({ type: 'text', text: item.text, id: crypto.randomUUID() });\n } else if (item.type === 'image' || item.type === 'audio') {\n content.push({\n id: crypto.randomUUID(),\n type: 'data',\n source: { type: 'base64', mediaType: item.mimeType, data: item.data },\n });\n } else {\n console.warn(\n `Unsupported content type '${item.type}' in tool result, skipping...`\n );\n }\n });\n return createToolResponse({ content, state: 'success' });\n } catch (error) {\n return createToolResponse({\n content: [\n {\n id: crypto.randomUUID(),\n type: 'text',\n text: `Error calling tool '${this.name}': ${error}`,\n },\n ],\n state: 'error',\n });\n } finally {\n await this.releaseClient(client);\n }\n }\n}\n","import { DataBlock, TextBlock } from '../message';\nimport { JSONSerializableObject } from '../type';\n\n/**\n * The tool response structure.\n */\nexport interface ToolResponse {\n content: Array<TextBlock | DataBlock>;\n id: string;\n createdAt: string;\n metadata: Record<string, JSONSerializableObject>;\n state: 'success' | 'error' | 'interrupted' | 'running';\n isLast: boolean;\n isInterrupted: boolean;\n}\n\n/**\n * Create a tool response object with the given parameters.\n *\n * @param root0\n * @param root0.content\n * @param root0.state\n * @param root0.id\n * @param root0.createdAt\n * @param root0.metadata\n * @param root0.stream\n * @param root0.isLast\n * @param root0.isInterrupted\n * @returns A ToolResponse object\n */\nexport function createToolResponse({\n content,\n state,\n id = crypto.randomUUID(),\n createdAt = new Date().toISOString(),\n metadata = {},\n stream = false,\n isLast = true,\n isInterrupted = false,\n}: {\n content: Array<TextBlock | DataBlock>;\n state: 'success' | 'error' | 'interrupted' | 'running';\n id?: string;\n createdAt?: string;\n metadata?: Record<string, JSONSerializableObject>;\n stream?: boolean;\n isLast?: boolean;\n isInterrupted?: boolean;\n}) {\n return {\n content,\n id,\n createdAt,\n metadata,\n state,\n stream,\n isLast,\n isInterrupted,\n } as ToolResponse;\n}\n\n/**\n * If the given object conforms to the ToolResponse structure.\n *\n * @param obj\n * @returns True if the object is a ToolResponse, false otherwise\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isToolResponse(obj: any): boolean {\n return (\n obj &&\n typeof obj === 'object' &&\n typeof obj.id === 'string' &&\n typeof obj.createdAt === 'string' &&\n Array.isArray(obj.content) &&\n typeof obj.metadata === 'object' &&\n typeof obj.stream === 'boolean' &&\n typeof obj.isLast === 'boolean' &&\n typeof obj.isInterrupted === 'boolean' &&\n ['success', 'error', 'interrupted', 'running'].includes(obj.state)\n );\n}\n","import { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport {\n StdioClientTransport,\n StdioServerParameters,\n} from '@modelcontextprotocol/sdk/client/stdio.js';\nimport { ListToolsRequest, ListToolsResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';\n\nimport { MCPTool } from './base';\n\n/**\n * The STDIO MCP client class.\n */\nexport class StdioMCPClient {\n name: string;\n private stdioServerParameters: StdioServerParameters;\n private transport?: StdioClientTransport;\n private client?: Client;\n\n /**\n * Initialize the StdioMCPClient with the given Stdio parameters.\n *\n * @param root0\n * @param root0.name\n */\n constructor({\n name,\n ...rest\n }: {\n name: string;\n } & StdioServerParameters) {\n this.name = name;\n this.stdioServerParameters = rest;\n }\n\n /**\n * Connect to the MCP server using Stdio transport. Note the Stdio client will start an\n * MCP server process under the hood.\n */\n async connect() {\n this.transport = new StdioClientTransport(this.stdioServerParameters);\n this.client = new Client({\n name: this.name,\n version: '1.0.0',\n });\n await this.client.connect(this.transport);\n }\n\n /**\n * Close the connection and stop the MCP server process.\n */\n async close() {\n try {\n if (this.client) {\n await this.client.close();\n }\n } finally {\n this.client = undefined;\n this.transport = undefined;\n }\n }\n\n /**\n * List all tools available on the MCP server.\n *\n * @returns An array of MCPTool instances representing the tools available on the server.\n */\n async listTools(): Promise<MCPTool[]> {\n if (!this.client) {\n throw new Error(\n `Client not initialized, call 'connect()' method first for the MCP client named '${this.name}'`\n );\n }\n\n const toolsRequest: ListToolsRequest = {\n method: 'tools/list',\n params: {},\n };\n\n const toolsResult = await this.client.request(toolsRequest, ListToolsResultSchema);\n if (toolsResult.tools === undefined) {\n return [];\n }\n\n return toolsResult.tools.map((tool: Tool) => {\n return new MCPTool({\n name: tool.name,\n description: tool.description || '',\n inputSchema: tool.inputSchema,\n getClient: async () => this.client!,\n releaseClient: async () => {},\n });\n });\n }\n\n /**\n * Get a callable function for a specific tool by its name.\n * @param root0\n * @param root0.name\n * @returns An instance of MCPTool that can be called to execute the tool's functionality.\n */\n async getCallableFunction({ name }: { name: string }) {\n if (!this.client) {\n throw new Error(\n `Client not initialized, call 'connect()' method first for the MCP client named '${this.name}'`\n );\n }\n\n const tools = await this.listTools();\n const targetTool = tools.find(tool => tool.name === name);\n\n if (!targetTool) {\n throw new Error(\n `Tool '${name}' not found in MCP server '${this.name}'. Available tools: ${tools.map(t => t.name).join(', ')}`\n );\n }\n\n return targetTool;\n }\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB;AAAA,EACI;AAAA,OAEG;AACP,SAAS,qCAAqC;AAG9C,SAA2B,6BAAmC;;;ACP9D,SAA0B,4BAA4B;;;AC6B/C,SAAS,mBAAmB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA,KAAK,OAAO,WAAW;AAAA,EACvB,aAAY,oBAAI,KAAK,GAAE,YAAY;AAAA,EACnC,WAAW,CAAC;AAAA,EACZ,SAAS;AAAA,EACT,SAAS;AAAA,EACT,gBAAgB;AACpB,GASG;AACC,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;;;ADtCO,IAAM,UAAN,MAA8B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA,qBAAqB;AAAA,EACrB;AAAA,EAEQ;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWR,YAAY;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,GAMG;AACC,SAAK,OAAO;AACZ,SAAK,cAAc;AACnB,SAAK,cAAc;AACnB,SAAK,YAAY;AACjB,SAAK,gBAAgB;AACrB,SAAK,OAAO,KAAK,MAAM,KAAK,IAAI;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,MAAM,OAAgC;AACxC,UAAM,SAAS,MAAM,KAAK,UAAU;AACpC,QAAI;AACA,YAAM,UAA2B;AAAA,QAC7B,QAAQ;AAAA,QACR,QAAQ;AAAA,UACJ,MAAM,KAAK;AAAA,UACX,WAAW;AAAA,QACf;AAAA,MACJ;AACA,Y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","names":["Client","ListToolsResultSchema","Client","ListToolsResultSchema"]}
1
+ {"version":3,"sources":["../../src/mcp/http.ts","../../src/mcp/base.ts","../../src/tool/response.ts","../../src/mcp/stdio.ts"],"sourcesContent":["import { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport {\n SSEClientTransport,\n SSEClientTransportOptions,\n} from '@modelcontextprotocol/sdk/client/sse.js';\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport { StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport type { RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport { ListToolsRequest, ListToolsResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';\n\nimport { MCPTool } from './base';\n\n/**\n * The HTTP MCP client class that connects to an MCP server using either Streamable HTTP or Server-Sent Events (SSE)\n * transport.\n * Note the client is stateful, meaning that developers should manually call the `connect()` and `close()` methods to\n * manage the connection lifecycle.\n */\nexport class HTTPMCPClient {\n name: string;\n private requestOptions?: RequestOptions;\n private client?: Client;\n private transport?: StreamableHTTPClientTransport | SSEClientTransport;\n private transportType: 'streamable-http' | 'sse';\n private url: string;\n private transportOpts?: StreamableHTTPClientTransportOptions | SSEClientTransportOptions;\n private stateful: boolean;\n\n /**\n * Initialize the HTTPStatefulMCPClient with the specified transport type, URL, and options.\n *\n * @param root0\n * @param root0.name\n * @param root0.transportType\n * @param root0.url\n * @param root0.stateful\n * @param root0.transportOpts\n * @param root0.requestOptions\n */\n constructor({\n name,\n transportType,\n url,\n stateful = true,\n transportOpts,\n requestOptions,\n }: {\n name: string;\n transportType: 'streamable-http' | 'sse';\n url: string;\n stateful?: boolean;\n transportOpts?: StreamableHTTPClientTransportOptions | SSEClientTransportOptions;\n requestOptions?: RequestOptions;\n }) {\n this.name = name;\n this.transportType = transportType;\n this.transportOpts = transportOpts;\n this.requestOptions = requestOptions;\n this.url = url;\n this.stateful = stateful;\n }\n\n /**\n * Connect to the MCP server with the specified transport and URL. This method must be called before making any\n * requests to the server.\n */\n async connect() {\n if (!this.stateful) {\n console.log(\n `MCP client '${this.name}' initialized with stateful=false will connect and close the connection automatically for each request, no need to call 'connect()' method explicitly.`\n );\n } else {\n await this._connect();\n }\n }\n\n /**\n * The internal method to establish the connection to the MCP server. It initializes the appropriate transport\n * based on the specified transport type and creates a new Client instance to manage the connection and requests.\n */\n protected async _connect() {\n const baseUrl = new URL(this.url);\n if (this.transportType === 'streamable-http') {\n this.transport = new StreamableHTTPClientTransport(baseUrl, this.transportOpts);\n } else {\n this.transport = new SSEClientTransport(baseUrl, this.transportOpts);\n }\n this.client = new Client({\n name: this.name,\n version: '1.0.0',\n });\n await this.client.connect(this.transport, this.requestOptions);\n console.log(`MCP client '${this.name}' is connected`);\n }\n\n /**\n * List all tools available on the MCP server.\n *\n * @returns An array of MCPTool instances representing the tools available on the server.\n */\n async listTools(): Promise<MCPTool[]> {\n let listClient: Client;\n\n if (this.stateful) {\n if (!this.client) {\n throw new Error(\n `Client not initialized, call 'connect()' method first for the MCP client named '${this.name}'`\n );\n }\n listClient = this.client;\n } else {\n listClient = await this._createClient();\n }\n\n try {\n const toolsRequest: ListToolsRequest = {\n method: 'tools/list',\n params: {},\n };\n\n const toolsResult = await listClient.request(toolsRequest, ListToolsResultSchema);\n if (toolsResult.tools === undefined) {\n return [];\n }\n\n return toolsResult.tools.map((tool: Tool) => {\n if (this.stateful) {\n return new MCPTool({\n name: tool.name,\n description: tool.description || '',\n inputSchema: tool.inputSchema,\n getClient: async () => this.client!,\n releaseClient: async () => {},\n });\n } else {\n return new MCPTool({\n name: tool.name,\n description: tool.description || '',\n inputSchema: tool.inputSchema,\n getClient: () => this._createClient(),\n releaseClient: async (c: Client) => {\n await c.close();\n },\n });\n }\n });\n } finally {\n if (!this.stateful) {\n await listClient.close();\n }\n }\n }\n\n /**\n * Close the connection to the MCP server and clean up any resources used by the client.\n */\n async close() {\n if (!this.stateful) {\n console.log(\n `MCP client '${this.name}' initialized with stateful=false will connect and close the connection automatically for each request, no need to call 'close()' method explicitly.`\n );\n } else {\n await this._close();\n }\n }\n\n /**\n * The internal method to close the connection to the MCP server.\n */\n protected async _close() {\n try {\n await this.client?.close();\n } finally {\n console.log(`MCP client '${this.name} is closed.'`);\n this.client = undefined;\n this.transport = undefined;\n }\n }\n\n /**\n * Create a new client instance without storing it in this.client.\n * Used for stateless operations where each request needs its own client.\n * @returns A new connected Client instance\n */\n protected async _createClient(): Promise<Client> {\n const baseUrl = new URL(this.url);\n const transport =\n this.transportType === 'streamable-http'\n ? new StreamableHTTPClientTransport(baseUrl, this.transportOpts)\n : new SSEClientTransport(baseUrl, this.transportOpts);\n\n const client = new Client({\n name: this.name,\n version: '1.0.0',\n });\n await client.connect(transport, this.requestOptions);\n return client;\n }\n\n /**\n * Get a callable function for a specific tool by its name.\n * @param root0\n * @param root0.name\n * @returns An instance of MCPTool that can be called to execute the tool's functionality.\n */\n async getCallableFunction({ name }: { name: string }) {\n if (this.stateful && !this.client) {\n throw new Error(\n `Client not initialized, call 'connect()' method first for the MCP client named '${this.name}'`\n );\n }\n\n const tools = await this.listTools();\n const targetTool = tools.find(tool => tool.name === name);\n\n if (!targetTool) {\n throw new Error(\n `Tool '${name}' not found in MCP server '${this.name}'. Available tools: ${tools.map(t => t.name).join(', ')}`\n );\n }\n\n return targetTool;\n }\n}\n","import { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { CallToolRequest, CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport z from 'zod';\n\nimport { Tool, ToolResponse } from '../tool';\nimport { createToolResponse } from '../tool/response';\nimport { ToolInputSchema } from '../type';\n\n/**\n * Type definition for getting a client instance\n */\ntype GetClient = () => Promise<Client>;\n\n/**\n * Type definition for releasing a client instance\n */\ntype ReleaseClient = (client: Client) => Promise<void>;\n\n/**\n * MCPTool class that wraps an MCP tool and provides a callable interface\n */\nexport class MCPTool implements Tool {\n name: string;\n description: string;\n inputSchema: z.ZodObject | ToolInputSchema;\n requireUserConfirm = false;\n call: (input: Record<string, unknown>) => Promise<ToolResponse>;\n\n private getClient: GetClient;\n private releaseClient: ReleaseClient;\n\n /**\n * Initialize an MCPTool instance\n * @param root0\n * @param root0.name\n * @param root0.description\n * @param root0.inputSchema\n * @param root0.getClient\n * @param root0.releaseClient\n */\n constructor({\n name,\n description,\n inputSchema,\n getClient,\n releaseClient,\n }: {\n name: string;\n description: string;\n inputSchema: z.ZodObject | ToolInputSchema;\n getClient: GetClient;\n releaseClient: ReleaseClient;\n }) {\n this.name = name;\n this.description = description;\n this.inputSchema = inputSchema;\n this.getClient = getClient;\n this.releaseClient = releaseClient;\n this.call = this._call.bind(this);\n }\n\n /**\n * Call the MCP tool with the specified input arguments. This method sends a request to the MCP server to execute\n * the tool and returns the result as a ToolResponse.\n *\n * @param arguments\n * @param input\n * @returns A ToolResponse object containing the result of the tool execution, or an error message if the call fails.\n */\n async _call(input: Record<string, unknown>) {\n const client = await this.getClient();\n try {\n const request: CallToolRequest = {\n method: 'tools/call',\n params: {\n name: this.name,\n arguments: input,\n },\n };\n const result = await client.request(request, CallToolResultSchema);\n\n const content: ToolResponse['content'] = [];\n result.content.forEach(item => {\n if (item.type === 'text') {\n content.push({ type: 'text', text: item.text, id: crypto.randomUUID() });\n } else if (item.type === 'image' || item.type === 'audio') {\n content.push({\n id: crypto.randomUUID(),\n type: 'data',\n source: { type: 'base64', media_type: item.mimeType, data: item.data },\n });\n } else {\n console.warn(\n `Unsupported content type '${item.type}' in tool result, skipping...`\n );\n }\n });\n return createToolResponse({ content, state: 'success' });\n } catch (error) {\n return createToolResponse({\n content: [\n {\n id: crypto.randomUUID(),\n type: 'text',\n text: `Error calling tool '${this.name}': ${error}`,\n },\n ],\n state: 'error',\n });\n } finally {\n await this.releaseClient(client);\n }\n }\n}\n","import { DataBlock, TextBlock } from '../message';\nimport { JSONSerializableObject } from '../type';\n\n/**\n * The tool response structure.\n */\nexport interface ToolResponse {\n content: Array<TextBlock | DataBlock>;\n id: string;\n createdAt: string;\n metadata: Record<string, JSONSerializableObject>;\n state: 'success' | 'error' | 'interrupted' | 'running';\n isLast: boolean;\n isInterrupted: boolean;\n}\n\n/**\n * Create a tool response object with the given parameters.\n *\n * @param root0\n * @param root0.content\n * @param root0.state\n * @param root0.id\n * @param root0.createdAt\n * @param root0.metadata\n * @param root0.stream\n * @param root0.isLast\n * @param root0.isInterrupted\n * @returns A ToolResponse object\n */\nexport function createToolResponse({\n content,\n state,\n id = crypto.randomUUID(),\n createdAt = new Date().toISOString(),\n metadata = {},\n stream = false,\n isLast = true,\n isInterrupted = false,\n}: {\n content: Array<TextBlock | DataBlock>;\n state: 'success' | 'error' | 'interrupted' | 'running';\n id?: string;\n createdAt?: string;\n metadata?: Record<string, JSONSerializableObject>;\n stream?: boolean;\n isLast?: boolean;\n isInterrupted?: boolean;\n}) {\n return {\n content,\n id,\n createdAt,\n metadata,\n state,\n stream,\n isLast,\n isInterrupted,\n } as ToolResponse;\n}\n\n/**\n * If the given object conforms to the ToolResponse structure.\n *\n * @param obj\n * @returns True if the object is a ToolResponse, false otherwise\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function isToolResponse(obj: any): boolean {\n return (\n obj &&\n typeof obj === 'object' &&\n typeof obj.id === 'string' &&\n typeof obj.createdAt === 'string' &&\n Array.isArray(obj.content) &&\n typeof obj.metadata === 'object' &&\n typeof obj.stream === 'boolean' &&\n typeof obj.isLast === 'boolean' &&\n typeof obj.isInterrupted === 'boolean' &&\n ['success', 'error', 'interrupted', 'running'].includes(obj.state)\n );\n}\n","import { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport {\n StdioClientTransport,\n StdioServerParameters,\n} from '@modelcontextprotocol/sdk/client/stdio.js';\nimport { ListToolsRequest, ListToolsResultSchema, Tool } from '@modelcontextprotocol/sdk/types.js';\n\nimport { MCPTool } from './base';\n\n/**\n * The STDIO MCP client class.\n */\nexport class StdioMCPClient {\n name: string;\n private stdioServerParameters: StdioServerParameters;\n private transport?: StdioClientTransport;\n private client?: Client;\n\n /**\n * Initialize the StdioMCPClient with the given Stdio parameters.\n *\n * @param root0\n * @param root0.name\n */\n constructor({\n name,\n ...rest\n }: {\n name: string;\n } & StdioServerParameters) {\n this.name = name;\n this.stdioServerParameters = rest;\n }\n\n /**\n * Connect to the MCP server using Stdio transport. Note the Stdio client will start an\n * MCP server process under the hood.\n */\n async connect() {\n this.transport = new StdioClientTransport(this.stdioServerParameters);\n this.client = new Client({\n name: this.name,\n version: '1.0.0',\n });\n await this.client.connect(this.transport);\n }\n\n /**\n * Close the connection and stop the MCP server process.\n */\n async close() {\n try {\n if (this.client) {\n await this.client.close();\n }\n } finally {\n this.client = undefined;\n this.transport = undefined;\n }\n }\n\n /**\n * List all tools available on the MCP server.\n *\n * @returns An array of MCPTool instances representing the tools available on the server.\n */\n async listTools(): Promise<MCPTool[]> {\n if (!this.client) {\n throw new Error(\n `Client not initialized, call 'connect()' method first for the MCP client named '${this.name}'`\n );\n }\n\n const toolsRequest: ListToolsRequest = {\n method: 'tools/list',\n params: {},\n };\n\n const toolsResult = await this.client.request(toolsRequest, ListToolsResultSchema);\n if (toolsResult.tools === undefined) {\n return [];\n }\n\n return toolsResult.tools.map((tool: Tool) => {\n return new MCPTool({\n name: tool.name,\n description: tool.description || '',\n inputSchema: tool.inputSchema,\n getClient: async () => this.client!,\n releaseClient: async () => {},\n });\n });\n }\n\n /**\n * Get a callable function for a specific tool by its name.\n * @param root0\n * @param root0.name\n * @returns An instance of MCPTool that can be called to execute the tool's functionality.\n */\n async getCallableFunction({ name }: { name: string }) {\n if (!this.client) {\n throw new Error(\n `Client not initialized, call 'connect()' method first for the MCP client named '${this.name}'`\n );\n }\n\n const tools = await this.listTools();\n const targetTool = tools.find(tool => tool.name === name);\n\n if (!targetTool) {\n throw new Error(\n `Tool '${name}' not found in MCP server '${this.name}'. Available tools: ${tools.map(t => t.name).join(', ')}`\n );\n }\n\n return targetTool;\n }\n}\n"],"mapp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A,IACrB;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,YAAgC;AAClC,QAAI,CAAC,KAAK,QAAQ;AACd,YAAM,IAAI;AAAA,QACN,mFAAmF,KAAK,IAAI;AAAA,MAChG;AAAA,IACJ;AAEA,UAAM,eAAiC;AAAA,MACnC,QAAQ;AAAA,MACR,QAAQ,CAAC;AAAA,IACb;AAEA,UAAM,cAAc,MAAM,KAAK,OAAO,QAAQ,cAAcC,sBAAqB;AACjF,QAAI,YAAY,UAAU,QAAW;AACjC,aAAO,CAAC;AAAA,IACZ;AAEA,WAAO,YAAY,MAAM,IAAI,CAAC,SAAe;AACzC,aAAO,IAAI,QAAQ;AAAA,QACf,MAAM,KAAK;AAAA,QACX,aAAa,KAAK,eAAe;AAAA,QACjC,aAAa,KAAK;AAAA,QAClB,WAAW,YAAY,KAAK;AAAA,QAC5B,eAAe,YAAY;AAAA,QAAC;AAAA,MAChC,CAAC;AAAA,IACL,CAAC;AAAA,EACL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,oBAAoB,EAAE,KAAK,GAAqB;AAClD,QAAI,CAAC,KAAK,QAAQ;AACd,YAAM,IAAI;AAAA,QACN,mFAAmF,KAAK,IAAI;AAAA,MAChG;AAAA,IACJ;AAEA,UAAM,QAAQ,MAAM,KAAK,UAAU;AACnC,UAAM,aAAa,MAAM,KAAK,UAAQ,KAAK,SAAS,IAAI;AAExD,QAAI,CAAC,YAAY;AACb,YAAM,IAAI;AAAA,QACN,SAAS,IAAI,8BAA8B,KAAK,IAAI,uBAAuB,MAAM,IAAI,OAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;AAAA,MAChH;AAAA,IACJ;AAEA,WAAO;AAAA,EACX;AACJ;","names":["Client","ListToolsResultSchema","Client","ListToolsResultSchema"]}
@@ -1,5 +1,5 @@
1
- export { M as Msg, c as createMsg, g as getContentBlocks, a as getTextContent } from '../message-CkN21KaY.mjs';
2
- export { B as Base64Source, C as ContentBlock, D as DataBlock, T as TextBlock, a as ThinkingBlock, b as ToolCallBlock, c as ToolResultBlock, U as URLSource } from '../block-VsnHrllL.mjs';
1
+ export { A as AssistantMsg, M as Msg, S as SystemMsg, U as UserMsg, c as createMsg, g as getContentBlocks, a as getTextContent } from '../message-CYnHiEVt.mjs';
2
+ export { B as Base64Source, C as ContentBlock, D as DataBlock, T as TextBlock, a as ThinkingBlock, b as ToolCallBlock, c as ToolResultBlock, U as URLSource } from '../block-7fd6byyN.mjs';
3
3
  import '../index-CAxQAkiP.mjs';
4
4
 
5
5
  declare enum GenerateReason {
@@ -1,5 +1,5 @@
1
- export { M as Msg, c as createMsg, g as getContentBlocks, a as getTextContent } from '../message-CzLeTlua.js';
2
- export { B as Base64Source, C as ContentBlock, D as DataBlock, T as TextBlock, a as ThinkingBlock, b as ToolCallBlock, c as ToolResultBlock, U as URLSource } from '../block-VsnHrllL.js';
1
+ export { A as AssistantMsg, M as Msg, S as SystemMsg, U as UserMsg, c as createMsg, g as getContentBlocks, a as getTextContent } from '../message-DZN7LetB.js';
2
+ export { B as Base64Source, C as ContentBlock, D as DataBlock, T as TextBlock, a as ThinkingBlock, b as ToolCallBlock, c as ToolResultBlock, U as URLSource } from '../block-7fd6byyN.js';
3
3
  import '../index-CAxQAkiP.js';
4
4
 
5
5
  declare enum GenerateReason {
@@ -20,7 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/message/index.ts
21
21
  var message_exports = {};
22
22
  __export(message_exports, {
23
+ AssistantMsg: () => AssistantMsg,
23
24
  GenerateReason: () => GenerateReason,
25
+ SystemMsg: () => SystemMsg,
26
+ UserMsg: () => UserMsg,
24
27
  createMsg: () => createMsg,
25
28
  getContentBlocks: () => getContentBlocks,
26
29
  getTextContent: () => getTextContent
@@ -34,16 +37,44 @@ function createMsg({
34
37
  role,
35
38
  metadata = {},
36
39
  id = crypto.randomUUID(),
37
- timestamp = (/* @__PURE__ */ new Date()).toISOString(),
40
+ created_at = (/* @__PURE__ */ new Date()).toISOString(),
41
+ finished_at,
38
42
  usage
39
43
  }) {
40
- return { id, name, role, content, metadata, timestamp, usage };
44
+ const contentBlocks = typeof content === "string" ? [{ id: crypto.randomUUID(), type: "text", text: content }] : content;
45
+ return { id, name, role, content: contentBlocks, metadata, created_at, finished_at, usage };
46
+ }
47
+ function UserMsg({
48
+ name,
49
+ content,
50
+ metadata = {},
51
+ id = crypto.randomUUID(),
52
+ created_at = (/* @__PURE__ */ new Date()).toISOString()
53
+ }) {
54
+ return createMsg({ name, content, role: "user", metadata, id, created_at });
55
+ }
56
+ function AssistantMsg({
57
+ name,
58
+ content,
59
+ metadata = {},
60
+ id = crypto.randomUUID(),
61
+ created_at = (/* @__PURE__ */ new Date()).toISOString(),
62
+ usage
63
+ }) {
64
+ return createMsg({ name, content, role: "assistant", metadata, id, created_at, usage });
65
+ }
66
+ function SystemMsg({
67
+ name,
68
+ content,
69
+ metadata = {},
70
+ id = crypto.randomUUID(),
71
+ created_at = (/* @__PURE__ */ new Date()).toISOString()
72
+ }) {
73
+ return createMsg({ name, content, role: "system", metadata, id, created_at });
41
74
  }
42
75
  function getTextContent(msg, separator = "\n") {
43
76
  const textBlocks = msg.content.filter((block) => block.type === "text");
44
- if (textBlocks.length === 0) {
45
- return null;
46
- }
77
+ if (textBlocks.length === 0) return null;
47
78
  return textBlocks.map((block) => block.text).join(separator);
48
79
  }
49
80
  function getContentBlocks(msg, blockType) {
@@ -59,7 +90,10 @@ var GenerateReason = /* @__PURE__ */ ((GenerateReason2) => {
59
90
  })(GenerateReason || {});
60
91
  // Annotate the CommonJS export names for ESM import in node:
61
92
  0 && (module.exports = {
93
+ AssistantMsg,
62
94
  GenerateReason,
95
+ SystemMsg,
96
+ UserMsg,
63
97
  createMsg,
64
98
  getContentBlocks,
65
99
  getTextContent
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/message/index.ts","../../src/message/message.ts","../../src/message/enums.ts"],"sourcesContent":["export { Msg, createMsg, getTextContent, getContentBlocks } from './message';\nexport {\n TextBlock,\n ThinkingBlock,\n ToolCallBlock,\n ToolResultBlock,\n ContentBlock,\n Base64Source,\n URLSource,\n DataBlock,\n} from './block';\nexport { GenerateReason } from './enums';\n","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","export enum GenerateReason {\n AWAITING_TOOL_RESULT = 'AWAITING_TOOL_RESULT',\n AWAITING_USER_CONFIRMATION = 'AWAITING_USER_CONFIRMATION',\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4CO,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;;;AClIO,IAAK,iBAAL,kBAAKA,oBAAL;AACH,EAAAA,gBAAA,0BAAuB;AACvB,EAAAA,gBAAA,gCAA6B;AAFrB,SAAAA;AAAA,GAAA;","names":["GenerateReason"]}
1
+ {"version":3,"sources":["../../src/message/index.ts","../../src/message/message.ts","../../src/message/enums.ts"],"sourcesContent":["export {\n Msg,\n createMsg,\n UserMsg,\n AssistantMsg,\n SystemMsg,\n getTextContent,\n getContentBlocks,\n} from './message';\nexport {\n TextBlock,\n ThinkingBlock,\n ToolCallBlock,\n ToolResultBlock,\n ContentBlock,\n Base64Source,\n URLSource,\n DataBlock,\n} from './block';\nexport { GenerateReason } from './enums';\n","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 created_at: string;\n /** ISO-8601 finished timestamp. */\n finished_at?: string | null;\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 `created_at` when omitted.\n * A plain string `content` is automatically wrapped in a single {@link TextBlock}.\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.created_at\n * @param root0.finished_at\n * @param root0.usage\n * @returns A Msg object.\n */\nexport function createMsg({\n name,\n content,\n role,\n metadata = {},\n id = crypto.randomUUID(),\n created_at = new Date().toISOString(),\n finished_at,\n usage,\n}: Omit<Msg, 'id' | 'created_at' | 'metadata' | 'content'> &\n Partial<Pick<Msg, 'id' | 'created_at' | 'metadata'>> & {\n content: string | ContentBlock[];\n }): Msg {\n const contentBlocks: ContentBlock[] =\n typeof content === 'string'\n ? [{ id: crypto.randomUUID(), type: 'text', text: content } as TextBlock]\n : content;\n return { id, name, role, content: contentBlocks, metadata, created_at, finished_at, usage };\n}\n\n/**\n * Create a user {@link Msg}.\n * @param root0\n * @param root0.name\n * @param root0.content\n * @param root0.metadata\n * @param root0.id\n * @param root0.created_at\n * @returns A Msg object with role 'user'.\n */\nexport function UserMsg({\n name,\n content,\n metadata = {},\n id = crypto.randomUUID(),\n created_at = new Date().toISOString(),\n}: {\n name: string;\n content: string | ContentBlock[];\n metadata?: Record<string, JSONSerializableObject>;\n id?: string;\n created_at?: string;\n}): Msg {\n return createMsg({ name, content, role: 'user', metadata, id, created_at });\n}\n\n/**\n * Create an assistant {@link Msg}.\n * @param root0\n * @param root0.name\n * @param root0.content\n * @param root0.metadata\n * @param root0.id\n * @param root0.created_at\n * @param root0.usage\n * @returns A Msg object with role 'assistant'.\n */\nexport function AssistantMsg({\n name,\n content,\n metadata = {},\n id = crypto.randomUUID(),\n created_at = new Date().toISOString(),\n usage,\n}: {\n name: string;\n content: string | ContentBlock[];\n metadata?: Record<string, JSONSerializableObject>;\n id?: string;\n created_at?: string;\n usage?: Msg['usage'];\n}): Msg {\n return createMsg({ name, content, role: 'assistant', metadata, id, created_at, usage });\n}\n\n/**\n * Create a system {@link Msg}.\n * @param root0\n * @param root0.name\n * @param root0.content\n * @param root0.metadata\n * @param root0.id\n * @param root0.created_at\n * @returns A Msg object with role 'system'.\n */\nexport function SystemMsg({\n name,\n content,\n metadata = {},\n id = crypto.randomUUID(),\n created_at = new Date().toISOString(),\n}: {\n name: string;\n content: string | ContentBlock[];\n metadata?: Record<string, JSONSerializableObject>;\n id?: string;\n created_at?: string;\n}): Msg {\n return createMsg({ name, content, role: 'system', metadata, id, created_at });\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) return null;\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[];\nexport function getContentBlocks(msg: Msg, blockType: 'text'): TextBlock[];\nexport function getContentBlocks(msg: Msg, blockType: 'thinking'): ThinkingBlock[];\nexport function getContentBlocks(msg: Msg, blockType: 'data'): DataBlock[];\nexport function getContentBlocks(msg: Msg, blockType: 'tool_call'): ToolCallBlock[];\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","export enum GenerateReason {\n AWAITING_TOOL_RESULT = 'AWAITING_TOOL_RESULT',\n AWAITING_USER_CONFIRMATION = 'AWAITING_USER_CONFIRMATION',\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC+CO,SAAS,UAAU;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,KAAK,OAAO,WAAW;AAAA,EACvB,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA,EACpC;AAAA,EACA;AACJ,GAGY;AACR,QAAM,gBACF,OAAO,YAAY,WACb,CAAC,EAAE,IAAI,OAAO,WAAW,GAAG,MAAM,QAAQ,MAAM,QAAQ,CAAc,IACtE;AACV,SAAO,EAAE,IAAI,MAAM,MAAM,SAAS,eAAe,UAAU,YAAY,aAAa,MAAM;AAC9F;AAYO,SAAS,QAAQ;AAAA,EACpB;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,KAAK,OAAO,WAAW;AAAA,EACvB,cAAa,oBAAI,KAAK,GAAE,YAAY;AACxC,GAMQ;AACJ,SAAO,UAAU,EAAE,MAAM,SAAS,MAAM,QAAQ,UAAU,IAAI,WAAW,CAAC;AAC9E;AAaO,SAAS,aAAa;AAAA,EACzB;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,KAAK,OAAO,WAAW;AAAA,EACvB,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA,EACpC;AACJ,GAOQ;AACJ,SAAO,UAAU,EAAE,MAAM,SAAS,MAAM,aAAa,UAAU,IAAI,YAAY,MAAM,CAAC;AAC1F;AAYO,SAAS,UAAU;AAAA,EACtB;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,KAAK,OAAO,WAAW;AAAA,EACvB,cAAa,oBAAI,KAAK,GAAE,YAAY;AACxC,GAMQ;AACJ,SAAO,UAAU,EAAE,MAAM,SAAS,MAAM,UAAU,UAAU,IAAI,WAAW,CAAC;AAChF;AAYO,SAAS,eAAe,KAAU,YAAoB,MAAqB;AAC9E,QAAM,aAAa,IAAI,QAAQ,OAAO,WAAS,MAAM,SAAS,MAAM;AACpE,MAAI,WAAW,WAAW,EAAG,QAAO;AACpC,SAAO,WAAW,IAAI,WAAU,MAAoB,IAAI,EAAE,KAAK,SAAS;AAC5E;AAgBO,SAAS,iBACZ,KACA,WACc;AACd,MAAI,CAAC,UAAW,QAAO,IAAI;AAC3B,SAAO,IAAI,QAAQ,OAAO,WAAS,MAAM,SAAS,SAAS;AAC/D;;;ACxLO,IAAK,iBAAL,kBAAKA,oBAAL;AACH,EAAAA,gBAAA,0BAAuB;AACvB,EAAAA,gBAAA,gCAA6B;AAFrB,SAAAA;AAAA,GAAA;","names":["GenerateReason"]}
@@ -5,16 +5,44 @@ function createMsg({
5
5
  role,
6
6
  metadata = {},
7
7
  id = crypto.randomUUID(),
8
- timestamp = (/* @__PURE__ */ new Date()).toISOString(),
8
+ created_at = (/* @__PURE__ */ new Date()).toISOString(),
9
+ finished_at,
9
10
  usage
10
11
  }) {
11
- return { id, name, role, content, metadata, timestamp, usage };
12
+ const contentBlocks = typeof content === "string" ? [{ id: crypto.randomUUID(), type: "text", text: content }] : content;
13
+ return { id, name, role, content: contentBlocks, metadata, created_at, finished_at, usage };
14
+ }
15
+ function UserMsg({
16
+ name,
17
+ content,
18
+ metadata = {},
19
+ id = crypto.randomUUID(),
20
+ created_at = (/* @__PURE__ */ new Date()).toISOString()
21
+ }) {
22
+ return createMsg({ name, content, role: "user", metadata, id, created_at });
23
+ }
24
+ function AssistantMsg({
25
+ name,
26
+ content,
27
+ metadata = {},
28
+ id = crypto.randomUUID(),
29
+ created_at = (/* @__PURE__ */ new Date()).toISOString(),
30
+ usage
31
+ }) {
32
+ return createMsg({ name, content, role: "assistant", metadata, id, created_at, usage });
33
+ }
34
+ function SystemMsg({
35
+ name,
36
+ content,
37
+ metadata = {},
38
+ id = crypto.randomUUID(),
39
+ created_at = (/* @__PURE__ */ new Date()).toISOString()
40
+ }) {
41
+ return createMsg({ name, content, role: "system", metadata, id, created_at });
12
42
  }
13
43
  function getTextContent(msg, separator = "\n") {
14
44
  const textBlocks = msg.content.filter((block) => block.type === "text");
15
- if (textBlocks.length === 0) {
16
- return null;
17
- }
45
+ if (textBlocks.length === 0) return null;
18
46
  return textBlocks.map((block) => block.text).join(separator);
19
47
  }
20
48
  function getContentBlocks(msg, blockType) {
@@ -29,7 +57,10 @@ var GenerateReason = /* @__PURE__ */ ((GenerateReason2) => {
29
57
  return GenerateReason2;
30
58
  })(GenerateReason || {});
31
59
  export {
60
+ AssistantMsg,
32
61
  GenerateReason,
62
+ SystemMsg,
63
+ UserMsg,
33
64
  createMsg,
34
65
  getContentBlocks,
35
66
  getTextContent
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/message/message.ts","../../src/message/enums.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","export enum GenerateReason {\n AWAITING_TOOL_RESULT = 'AWAITING_TOOL_RESULT',\n AWAITING_USER_CONFIRMATION = 'AWAITING_USER_CONFIRMATION',\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;;;AClIO,IAAK,iBAAL,kBAAKA,oBAAL;AACH,EAAAA,gBAAA,0BAAuB;AACvB,EAAAA,gBAAA,gCAA6B;AAFrB,SAAAA;AAAA,GAAA;","names":["GenerateReason"]}
1
+ {"version":3,"sources":["../../src/message/message.ts","../../src/message/enums.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 created_at: string;\n /** ISO-8601 finished timestamp. */\n finished_at?: string | null;\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 `created_at` when omitted.\n * A plain string `content` is automatically wrapped in a single {@link TextBlock}.\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.created_at\n * @param root0.finished_at\n * @param root0.usage\n * @returns A Msg object.\n */\nexport function createMsg({\n name,\n content,\n role,\n metadata = {},\n id = crypto.randomUUID(),\n created_at = new Date().toISOString(),\n finished_at,\n usage,\n}: Omit<Msg, 'id' | 'created_at' | 'metadata' | 'content'> &\n Partial<Pick<Msg, 'id' | 'created_at' | 'metadata'>> & {\n content: string | ContentBlock[];\n }): Msg {\n const contentBlocks: ContentBlock[] =\n typeof content === 'string'\n ? [{ id: crypto.randomUUID(), type: 'text', text: content } as TextBlock]\n : content;\n return { id, name, role, content: contentBlocks, metadata, created_at, finished_at, usage };\n}\n\n/**\n * Create a user {@link Msg}.\n * @param root0\n * @param root0.name\n * @param root0.content\n * @param root0.metadata\n * @param root0.id\n * @param root0.created_at\n * @returns A Msg object with role 'user'.\n */\nexport function UserMsg({\n name,\n content,\n metadata = {},\n id = crypto.randomUUID(),\n created_at = new Date().toISOString(),\n}: {\n name: string;\n content: string | ContentBlock[];\n metadata?: Record<string, JSONSerializableObject>;\n id?: string;\n created_at?: string;\n}): Msg {\n return createMsg({ name, content, role: 'user', metadata, id, created_at });\n}\n\n/**\n * Create an assistant {@link Msg}.\n * @param root0\n * @param root0.name\n * @param root0.content\n * @param root0.metadata\n * @param root0.id\n * @param root0.created_at\n * @param root0.usage\n * @returns A Msg object with role 'assistant'.\n */\nexport function AssistantMsg({\n name,\n content,\n metadata = {},\n id = crypto.randomUUID(),\n created_at = new Date().toISOString(),\n usage,\n}: {\n name: string;\n content: string | ContentBlock[];\n metadata?: Record<string, JSONSerializableObject>;\n id?: string;\n created_at?: string;\n usage?: Msg['usage'];\n}): Msg {\n return createMsg({ name, content, role: 'assistant', metadata, id, created_at, usage });\n}\n\n/**\n * Create a system {@link Msg}.\n * @param root0\n * @param root0.name\n * @param root0.content\n * @param root0.metadata\n * @param root0.id\n * @param root0.created_at\n * @returns A Msg object with role 'system'.\n */\nexport function SystemMsg({\n name,\n content,\n metadata = {},\n id = crypto.randomUUID(),\n created_at = new Date().toISOString(),\n}: {\n name: string;\n content: string | ContentBlock[];\n metadata?: Record<string, JSONSerializableObject>;\n id?: string;\n created_at?: string;\n}): Msg {\n return createMsg({ name, content, role: 'system', metadata, id, created_at });\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) return null;\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[];\nexport function getContentBlocks(msg: Msg, blockType: 'text'): TextBlock[];\nexport function getContentBlocks(msg: Msg, blockType: 'thinking'): ThinkingBlock[];\nexport function getContentBlocks(msg: Msg, blockType: 'data'): DataBlock[];\nexport function getContentBlocks(msg: Msg, blockType: 'tool_call'): ToolCallBlock[];\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","export enum GenerateReason {\n AWAITING_TOOL_RESULT = 'AWAITING_TOOL_RESULT',\n AWAITING_USER_CONFIRMATION = 'AWAITING_USER_CONFIRMATION',\n}\n"],"mappings":";AA+CO,SAAS,UAAU;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,KAAK,OAAO,WAAW;AAAA,EACvB,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA,EACpC;AAAA,EACA;AACJ,GAGY;AACR,QAAM,gBACF,OAAO,YAAY,WACb,CAAC,EAAE,IAAI,OAAO,WAAW,GAAG,MAAM,QAAQ,MAAM,QAAQ,CAAc,IACtE;AACV,SAAO,EAAE,IAAI,MAAM,MAAM,SAAS,eAAe,UAAU,YAAY,aAAa,MAAM;AAC9F;AAYO,SAAS,QAAQ;AAAA,EACpB;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,KAAK,OAAO,WAAW;AAAA,EACvB,cAAa,oBAAI,KAAK,GAAE,YAAY;AACxC,GAMQ;AACJ,SAAO,UAAU,EAAE,MAAM,SAAS,MAAM,QAAQ,UAAU,IAAI,WAAW,CAAC;AAC9E;AAaO,SAAS,aAAa;AAAA,EACzB;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,KAAK,OAAO,WAAW;AAAA,EACvB,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA,EACpC;AACJ,GAOQ;AACJ,SAAO,UAAU,EAAE,MAAM,SAAS,MAAM,aAAa,UAAU,IAAI,YAAY,MAAM,CAAC;AAC1F;AAYO,SAAS,UAAU;AAAA,EACtB;AAAA,EACA;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,KAAK,OAAO,WAAW;AAAA,EACvB,cAAa,oBAAI,KAAK,GAAE,YAAY;AACxC,GAMQ;AACJ,SAAO,UAAU,EAAE,MAAM,SAAS,MAAM,UAAU,UAAU,IAAI,WAAW,CAAC;AAChF;AAYO,SAAS,eAAe,KAAU,YAAoB,MAAqB;AAC9E,QAAM,aAAa,IAAI,QAAQ,OAAO,WAAS,MAAM,SAAS,MAAM;AACpE,MAAI,WAAW,WAAW,EAAG,QAAO;AACpC,SAAO,WAAW,IAAI,WAAU,MAAoB,IAAI,EAAE,KAAK,SAAS;AAC5E;AAgBO,SAAS,iBACZ,KACA,WACc;AACd,MAAI,CAAC,UAAW,QAAO,IAAI;AAC3B,SAAO,IAAI,QAAQ,OAAO,WAAS,MAAM,SAAS,SAAS;AAC/D;;;ACxLO,IAAK,iBAAL,kBAAKA,oBAAL;AACH,EAAAA,gBAAA,0BAAuB;AACvB,EAAAA,gBAAA,gCAA6B;AAFrB,SAAAA;AAAA,GAAA;","names":["GenerateReason"]}
@@ -1,5 +1,5 @@
1
1
  import { J as JSONSerializableObject } from './index-CAxQAkiP.mjs';
2
- import { C as ContentBlock, T as TextBlock, a as ThinkingBlock, D as DataBlock, b as ToolCallBlock, c as ToolResultBlock } from './block-VsnHrllL.mjs';
2
+ import { C as ContentBlock, T as TextBlock, a as ThinkingBlock, D as DataBlock, b as ToolCallBlock, c as ToolResultBlock } from './block-7fd6byyN.mjs';
3
3
 
4
4
  /** A chat message exchanged between agents or between an agent and a model. */
5
5
  interface Msg {
@@ -14,7 +14,9 @@ interface Msg {
14
14
  /** Arbitrary key-value metadata attached to the message. */
15
15
  metadata: Record<string, JSONSerializableObject>;
16
16
  /** ISO-8601 creation timestamp. */
17
- timestamp: string;
17
+ created_at: string;
18
+ /** ISO-8601 finished timestamp. */
19
+ finished_at?: string | null;
18
20
  /** Usage information for the message, such as token counts. */
19
21
  usage?: {
20
22
  inputTokens: number;
@@ -22,19 +24,75 @@ interface Msg {
22
24
  };
23
25
  }
24
26
  /**
25
- * Create a new {@link Msg} object, filling in `id` and `timestamp` when omitted.
26
- *
27
+ * Create a new {@link Msg} object, filling in `id` and `created_at` when omitted.
28
+ * A plain string `content` is automatically wrapped in a single {@link TextBlock}.
27
29
  * @param root0
28
30
  * @param root0.name
29
31
  * @param root0.content
30
32
  * @param root0.role
31
33
  * @param root0.metadata
32
34
  * @param root0.id
33
- * @param root0.timestamp
35
+ * @param root0.created_at
36
+ * @param root0.finished_at
34
37
  * @param root0.usage
35
- * @returns A fully-populated {@link Msg} object.
38
+ * @returns A Msg object.
39
+ */
40
+ declare function createMsg({ name, content, role, metadata, id, created_at, finished_at, usage, }: Omit<Msg, 'id' | 'created_at' | 'metadata' | 'content'> & Partial<Pick<Msg, 'id' | 'created_at' | 'metadata'>> & {
41
+ content: string | ContentBlock[];
42
+ }): Msg;
43
+ /**
44
+ * Create a user {@link Msg}.
45
+ * @param root0
46
+ * @param root0.name
47
+ * @param root0.content
48
+ * @param root0.metadata
49
+ * @param root0.id
50
+ * @param root0.created_at
51
+ * @returns A Msg object with role 'user'.
52
+ */
53
+ declare function UserMsg({ name, content, metadata, id, created_at, }: {
54
+ name: string;
55
+ content: string | ContentBlock[];
56
+ metadata?: Record<string, JSONSerializableObject>;
57
+ id?: string;
58
+ created_at?: string;
59
+ }): Msg;
60
+ /**
61
+ * Create an assistant {@link Msg}.
62
+ * @param root0
63
+ * @param root0.name
64
+ * @param root0.content
65
+ * @param root0.metadata
66
+ * @param root0.id
67
+ * @param root0.created_at
68
+ * @param root0.usage
69
+ * @returns A Msg object with role 'assistant'.
70
+ */
71
+ declare function AssistantMsg({ name, content, metadata, id, created_at, usage, }: {
72
+ name: string;
73
+ content: string | ContentBlock[];
74
+ metadata?: Record<string, JSONSerializableObject>;
75
+ id?: string;
76
+ created_at?: string;
77
+ usage?: Msg['usage'];
78
+ }): Msg;
79
+ /**
80
+ * Create a system {@link Msg}.
81
+ * @param root0
82
+ * @param root0.name
83
+ * @param root0.content
84
+ * @param root0.metadata
85
+ * @param root0.id
86
+ * @param root0.created_at
87
+ * @returns A Msg object with role 'system'.
36
88
  */
37
- declare function createMsg({ name, content, role, metadata, id, timestamp, usage, }: Omit<Msg, 'id' | 'timestamp' | 'metadata'> & Partial<Pick<Msg, 'id' | 'timestamp' | 'metadata'>>): Msg;
89
+ declare function SystemMsg({ name, content, metadata, id, created_at, }: {
90
+ name: string;
91
+ content: string | ContentBlock[];
92
+ metadata?: Record<string, JSONSerializableObject>;
93
+ id?: string;
94
+ created_at?: string;
95
+ }): Msg;
38
96
  /**
39
97
  * Extract the plain-text content from a message.
40
98
  *
@@ -55,45 +113,10 @@ declare function getTextContent(msg: Msg, separator?: string): string | null;
55
113
  * @returns An array of all {@link ContentBlock} objects.
56
114
  */
57
115
  declare function getContentBlocks(msg: Msg): ContentBlock[];
58
- /**
59
- * Return all {@link TextBlock} objects from a message.
60
- *
61
- * @param msg - The message to read.
62
- * @param blockType - `'text'`
63
- * @returns An array of {@link TextBlock} objects.
64
- */
65
116
  declare function getContentBlocks(msg: Msg, blockType: 'text'): TextBlock[];
66
- /**
67
- * Return all {@link ThinkingBlock} objects from a message.
68
- *
69
- * @param msg - The message to read.
70
- * @param blockType - `'thinking'`
71
- * @returns An array of {@link ThinkingBlock} objects.
72
- */
73
117
  declare function getContentBlocks(msg: Msg, blockType: 'thinking'): ThinkingBlock[];
74
- /**
75
- * Return all {@link DataBlock} objects from a message.
76
- *
77
- * @param msg - The message to read.
78
- * @param blockType - `'video'`
79
- * @returns An array of {@link DataBlock} objects.
80
- */
81
118
  declare function getContentBlocks(msg: Msg, blockType: 'data'): DataBlock[];
82
- /**
83
- * Return all {@link ToolCallBlock} objects from a message.
84
- *
85
- * @param msg - The message to read.
86
- * @param blockType - `'tool_call'`
87
- * @returns An array of {@link ToolCallBlock} objects.
88
- */
89
119
  declare function getContentBlocks(msg: Msg, blockType: 'tool_call'): ToolCallBlock[];
90
- /**
91
- * Return all {@link ToolResultBlock} objects from a message.
92
- *
93
- * @param msg - The message to read.
94
- * @param blockType - `'tool_result'`
95
- * @returns An array of {@link ToolResultBlock} objects.
96
- */
97
120
  declare function getContentBlocks(msg: Msg, blockType: 'tool_result'): ToolResultBlock[];
98
121
 
99
- export { type Msg as M, getTextContent as a, createMsg as c, getContentBlocks as g };
122
+ export { AssistantMsg as A, type Msg as M, SystemMsg as S, UserMsg as U, getTextContent as a, createMsg as c, getContentBlocks as g };
@@ -1,5 +1,5 @@
1
1
  import { J as JSONSerializableObject } from './index-CAxQAkiP.js';
2
- import { C as ContentBlock, T as TextBlock, a as ThinkingBlock, D as DataBlock, b as ToolCallBlock, c as ToolResultBlock } from './block-VsnHrllL.js';
2
+ import { C as ContentBlock, T as TextBlock, a as ThinkingBlock, D as DataBlock, b as ToolCallBlock, c as ToolResultBlock } from './block-7fd6byyN.js';
3
3
 
4
4
  /** A chat message exchanged between agents or between an agent and a model. */
5
5
  interface Msg {
@@ -14,7 +14,9 @@ interface Msg {
14
14
  /** Arbitrary key-value metadata attached to the message. */
15
15
  metadata: Record<string, JSONSerializableObject>;
16
16
  /** ISO-8601 creation timestamp. */
17
- timestamp: string;
17
+ created_at: string;
18
+ /** ISO-8601 finished timestamp. */
19
+ finished_at?: string | null;
18
20
  /** Usage information for the message, such as token counts. */
19
21
  usage?: {
20
22
  inputTokens: number;
@@ -22,19 +24,75 @@ interface Msg {
22
24
  };
23
25
  }
24
26
  /**
25
- * Create a new {@link Msg} object, filling in `id` and `timestamp` when omitted.
26
- *
27
+ * Create a new {@link Msg} object, filling in `id` and `created_at` when omitted.
28
+ * A plain string `content` is automatically wrapped in a single {@link TextBlock}.
27
29
  * @param root0
28
30
  * @param root0.name
29
31
  * @param root0.content
30
32
  * @param root0.role
31
33
  * @param root0.metadata
32
34
  * @param root0.id
33
- * @param root0.timestamp
35
+ * @param root0.created_at
36
+ * @param root0.finished_at
34
37
  * @param root0.usage
35
- * @returns A fully-populated {@link Msg} object.
38
+ * @returns A Msg object.
39
+ */
40
+ declare function createMsg({ name, content, role, metadata, id, created_at, finished_at, usage, }: Omit<Msg, 'id' | 'created_at' | 'metadata' | 'content'> & Partial<Pick<Msg, 'id' | 'created_at' | 'metadata'>> & {
41
+ content: string | ContentBlock[];
42
+ }): Msg;
43
+ /**
44
+ * Create a user {@link Msg}.
45
+ * @param root0
46
+ * @param root0.name
47
+ * @param root0.content
48
+ * @param root0.metadata
49
+ * @param root0.id
50
+ * @param root0.created_at
51
+ * @returns A Msg object with role 'user'.
52
+ */
53
+ declare function UserMsg({ name, content, metadata, id, created_at, }: {
54
+ name: string;
55
+ content: string | ContentBlock[];
56
+ metadata?: Record<string, JSONSerializableObject>;
57
+ id?: string;
58
+ created_at?: string;
59
+ }): Msg;
60
+ /**
61
+ * Create an assistant {@link Msg}.
62
+ * @param root0
63
+ * @param root0.name
64
+ * @param root0.content
65
+ * @param root0.metadata
66
+ * @param root0.id
67
+ * @param root0.created_at
68
+ * @param root0.usage
69
+ * @returns A Msg object with role 'assistant'.
70
+ */
71
+ declare function AssistantMsg({ name, content, metadata, id, created_at, usage, }: {
72
+ name: string;
73
+ content: string | ContentBlock[];
74
+ metadata?: Record<string, JSONSerializableObject>;
75
+ id?: string;
76
+ created_at?: string;
77
+ usage?: Msg['usage'];
78
+ }): Msg;
79
+ /**
80
+ * Create a system {@link Msg}.
81
+ * @param root0
82
+ * @param root0.name
83
+ * @param root0.content
84
+ * @param root0.metadata
85
+ * @param root0.id
86
+ * @param root0.created_at
87
+ * @returns A Msg object with role 'system'.
36
88
  */
37
- declare function createMsg({ name, content, role, metadata, id, timestamp, usage, }: Omit<Msg, 'id' | 'timestamp' | 'metadata'> & Partial<Pick<Msg, 'id' | 'timestamp' | 'metadata'>>): Msg;
89
+ declare function SystemMsg({ name, content, metadata, id, created_at, }: {
90
+ name: string;
91
+ content: string | ContentBlock[];
92
+ metadata?: Record<string, JSONSerializableObject>;
93
+ id?: string;
94
+ created_at?: string;
95
+ }): Msg;
38
96
  /**
39
97
  * Extract the plain-text content from a message.
40
98
  *
@@ -55,45 +113,10 @@ declare function getTextContent(msg: Msg, separator?: string): string | null;
55
113
  * @returns An array of all {@link ContentBlock} objects.
56
114
  */
57
115
  declare function getContentBlocks(msg: Msg): ContentBlock[];
58
- /**
59
- * Return all {@link TextBlock} objects from a message.
60
- *
61
- * @param msg - The message to read.
62
- * @param blockType - `'text'`
63
- * @returns An array of {@link TextBlock} objects.
64
- */
65
116
  declare function getContentBlocks(msg: Msg, blockType: 'text'): TextBlock[];
66
- /**
67
- * Return all {@link ThinkingBlock} objects from a message.
68
- *
69
- * @param msg - The message to read.
70
- * @param blockType - `'thinking'`
71
- * @returns An array of {@link ThinkingBlock} objects.
72
- */
73
117
  declare function getContentBlocks(msg: Msg, blockType: 'thinking'): ThinkingBlock[];
74
- /**
75
- * Return all {@link DataBlock} objects from a message.
76
- *
77
- * @param msg - The message to read.
78
- * @param blockType - `'video'`
79
- * @returns An array of {@link DataBlock} objects.
80
- */
81
118
  declare function getContentBlocks(msg: Msg, blockType: 'data'): DataBlock[];
82
- /**
83
- * Return all {@link ToolCallBlock} objects from a message.
84
- *
85
- * @param msg - The message to read.
86
- * @param blockType - `'tool_call'`
87
- * @returns An array of {@link ToolCallBlock} objects.
88
- */
89
119
  declare function getContentBlocks(msg: Msg, blockType: 'tool_call'): ToolCallBlock[];
90
- /**
91
- * Return all {@link ToolResultBlock} objects from a message.
92
- *
93
- * @param msg - The message to read.
94
- * @param blockType - `'tool_result'`
95
- * @returns An array of {@link ToolResultBlock} objects.
96
- */
97
120
  declare function getContentBlocks(msg: Msg, blockType: 'tool_result'): ToolResultBlock[];
98
121
 
99
- export { type Msg as M, getTextContent as a, createMsg as c, getContentBlocks as g };
122
+ export { AssistantMsg as A, type Msg as M, SystemMsg as S, UserMsg as U, getTextContent as a, createMsg as c, getContentBlocks as g };