UNPKG

acp-sdk

Version:

Agent Communication Protocol SDK

38 lines (36 loc) 1.04 kB
import { isMessage, Message, isMessagePart, MessagePart } from '../models/models.js'; function inputToMessages(input) { if (Array.isArray(input)) { if (!input.length) { return []; } if (input.every((i) => isMessage(i))) { return input.map((i) => Message.parse(i)); } if (input.every((i) => isMessagePart(i))) { return [Message.parse({ parts: input })]; } if (input.every((i) => typeof i === "string")) { return [ Message.parse({ parts: input.map((content) => MessagePart.parse({ content })) }) ]; } throw new TypeError("List with mixed types is not supported"); } else { if (typeof input === "string") { input = MessagePart.parse({ content: input }); } if (isMessagePart(input)) { input = Message.parse({ parts: [input] }); } if (isMessage(input)) { input = [Message.parse(input)]; } return input; } } export { inputToMessages }; //# sourceMappingURL=utils.js.map //# sourceMappingURL=utils.js.map