MCPcopy Index your code
hub / github.com/codeaashu/claude-code / assistantMessageToMessageParam

Function assistantMessageToMessageParam

src/services/api/claude.ts:633–674  ·  view source on GitHub ↗
(
  message: AssistantMessage,
  addCache = false,
  enablePromptCaching: boolean,
  querySource?: QuerySource,
)

Source from the content-addressed store, hash-verified

631}
632
633export function assistantMessageToMessageParam(
634 message: AssistantMessage,
635 addCache = false,
636 enablePromptCaching: boolean,
637 querySource?: QuerySource,
638): MessageParam {
639 if (addCache) {
640 if (typeof message.message.content === 'string') {
641 return {
642 role: 'assistant',
643 content: [
644 {
645 type: 'text',
646 text: message.message.content,
647 ...(enablePromptCaching && {
648 cache_control: getCacheControl({ querySource }),
649 }),
650 },
651 ],
652 }
653 } else {
654 return {
655 role: 'assistant',
656 content: message.message.content.map((_, i) => ({
657 ..._,
658 ...(i === message.message.content.length - 1 &&
659 _.type !== 'thinking' &&
660 _.type !== 'redacted_thinking' &&
661 (feature('CONNECTOR_TEXT') ? !isConnectorTextBlock(_) : true)
662 ? enablePromptCaching
663 ? { cache_control: getCacheControl({ querySource }) }
664 : {}
665 : {}),
666 })),
667 }
668 }
669 }
670 return {
671 role: 'assistant',
672 content: message.message.content,
673 }
674}
675
676export type Options = {
677 getToolPermissionContext: () => Promise<ToolPermissionContext>

Callers 1

addCacheBreakpointsFunction · 0.85

Calls 2

getCacheControlFunction · 0.85
featureFunction · 0.85

Tested by

no test coverage detected