pomljs
Version:
Prompt Orchestration Markup Language
1 lines • 8.13 kB
Source Map (JSON)
{"version":3,"file":"message.cjs","sources":["../../.build/components/message.js"],"sourcesContent":["import { component } from \"../base\";\nimport { Text, Image, ToolRequest, ToolResponse } from \"../essentials\";\nimport * as React from 'react';\nimport { parsePythonStyleSlice } from './utils';\n/**\n * Wrap the contents in a system message.\n *\n * @see {@link Text} for other props available.\n *\n * @example\n * ```xml\n * <system-msg>Answer concisely.</system-msg>\n * ```\n */\nexport const SystemMessage = component('SystemMessage', ['system-msg'])((props) => {\n const { children, ...others } = props;\n return (React.createElement(Text, { speaker: \"system\", ...others }, children));\n});\n/**\n * Wrap the contents in a user message.\n *\n * @see {@link Text} for other props available.\n *\n * @example\n * ```xml\n * <user-msg>What is the capital of France?</user-msg>\n * ```\n */\nexport const HumanMessage = component('HumanMessage', ['human-msg'])((props) => {\n const { children, ...others } = props;\n return (React.createElement(Text, { speaker: \"human\", ...others }, children));\n});\n/**\n * Wrap the contents in a AI message.\n *\n * @see {@link Text} for other props available.\n *\n * @example\n * ```xml\n * <ai-msg>Paris</ai-msg>\n * ```\n */\nexport const AiMessage = component('AiMessage', ['ai-msg'])((props) => {\n const { children, ...others } = props;\n return (React.createElement(Text, { speaker: \"ai\", ...others }, children));\n});\n/**\n * Display a message content.\n *\n * @param {object|string} content - The content of the message. It can be a string, or an array of strings and multimedia content.\n *\n * @example\n * ```xml\n * <msg-content content=\"What is the capital of France?\" />\n * ```\n */\nexport const MessageContent = component('MessageContent', ['msg-content'])((props) => {\n const { children, content, ...others } = props;\n const displayStringOrMultimedia = (media, key) => {\n if (typeof media === 'string') {\n return (React.createElement(Text, { key: key, ...others }, media));\n }\n else if (media.type.startsWith('image/')) {\n const image = media;\n return (React.createElement(Image, { key: key, base64: image.base64, alt: image.alt, type: image.type, ...others }));\n }\n else if (media.type === 'application/vnd.poml.toolrequest') {\n const toolRequest = media;\n return (React.createElement(ToolRequest, { key: key, id: toolRequest.id, name: toolRequest.name, parameters: toolRequest.content, ...others }));\n }\n else if (media.type === 'application/vnd.poml.toolresponse') {\n const toolResponse = media;\n return (React.createElement(ToolResponse, { key: key, id: toolResponse.id, name: toolResponse.name, ...others },\n React.createElement(MessageContent, { content: toolResponse.content, ...others })));\n }\n else {\n throw new Error(`Unsupported media type: ${media.type}`);\n }\n };\n if (typeof content === 'string') {\n return displayStringOrMultimedia(content);\n }\n else if (Array.isArray(content)) {\n return React.createElement(Text, null, content.map((item, index) => displayStringOrMultimedia(item, `content-${index}`)));\n }\n});\n/**\n * Display a conversation between system, human and AI.\n *\n * @param {object} messages - A list of message. Each message should have a `speaker` and a `content` field.\n * @param {string} selectedMessages - The messages to be selected. If not provided, all messages will be selected.\n * You can use a string like `2` to specify a single message, or slice like `2:4` to specify a range of messages (2 inclusive, 4 exclusive).\n * Or use `-6:` to select the last 6 messages.\n *\n * @example\n * ```xml\n * <conversation messages=\"{{[{ speaker: 'human', content: 'What is the capital of France?' }, { speaker: 'ai', content: 'Paris' }]}}\" />\n * ```\n */\nexport const Conversation = component('Conversation', ['conversation'])((props) => {\n let { children, messages, selectedMessages, ...others } = props;\n if (selectedMessages) {\n const [start, end] = parsePythonStyleSlice(selectedMessages, messages.length);\n messages = messages.slice(start, end);\n }\n return (React.createElement(Text, null, messages.map((message, index) => (React.createElement(Text, { key: `message-${index}`, speaker: message.speaker, ...others },\n React.createElement(MessageContent, { content: message.content, ...others }))))));\n});\n//# sourceMappingURL=message.js.map"],"names":["component","React","Text","Image","ToolRequest","ToolResponse","parsePythonStyleSlice"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC6BA,cAAS,CAAC,eAAe,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK;AACnF,IAAI,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,EAAE,GAAG,KAAK;AACzC,IAAI,QAAQC,gBAAK,CAAC,aAAa,CAACC,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