MCPcopy
hub / github.com/coder/mux / createMuxMessage

Function createMuxMessage

src/common/types/message.ts:889–915  ·  view source on GitHub ↗
(
  id: string,
  role: "user" | "assistant",
  content: string,
  metadata?: MuxMetadata,
  additionalParts?: MuxMessage["parts"]
)

Source from the content-addressed store, hash-verified

887
888// Helper to create a simple text message
889export function createMuxMessage(
890 id: string,
891 role: "user" | "assistant",
892 content: string,
893 metadata?: MuxMetadata,
894 additionalParts?: MuxMessage["parts"]
895): MuxMessage {
896 const textPart = content
897 ? [{ type: "text" as const, text: content, state: "done" as const }]
898 : [];
899 const parts = [...textPart, ...(additionalParts ?? [])];
900
901 // Validation: User messages must have at least one part with content
902 // This prevents empty user messages from being created (defense-in-depth)
903 if (role === "user" && parts.length === 0) {
904 throw new Error(
905 "Cannot create user message with no parts. Empty messages should be rejected upstream."
906 );
907 }
908
909 return {
910 id,
911 role,
912 metadata,
913 parts,
914 };
915}

Calls

no outgoing calls

Tested by 15

makeCompletedTurnHistoryFunction · 0.72
appendUserHistoryMessageFunction · 0.72
finalizeChildReportFunction · 0.72
createFixtureFunction · 0.72
seedCompactionEpochFunction · 0.72
seedImageMessageFunction · 0.72
startAdvisorStreamFunction · 0.72
streamOnceFunction · 0.72