MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / replacePlanDraftWithPlan

Function replacePlanDraftWithPlan

src/services/ai/planBlocks.ts:63–81  ·  view source on GitHub ↗
(
  blocks: readonly T[],
  plan: PlanContentBlock
)

Source from the content-addressed store, hash-verified

61}
62
63export function replacePlanDraftWithPlan<T extends BlockWithType>(
64 blocks: readonly T[],
65 plan: PlanContentBlock
66): Array<T | PlanContentBlock> {
67 const nextBlocks = blocks.map(cloneBlock) as Array<T | PlanContentBlock>
68 for (let index = nextBlocks.length - 1; index >= 0; index--) {
69 const block = nextBlocks[index]
70 if (isPlanDraftBlock(block)) {
71 const displayText = block.text.trim()
72 nextBlocks[index] = {
73 ...toPlanContentBlock(plan),
74 ...(displayText ? { displayText } : {}),
75 }
76 return nextBlocks
77 }
78 }
79 nextBlocks.push(toPlanContentBlock(plan))
80 return nextBlocks
81}
82
83export function removePlanDraftBlocks<T extends BlockWithType>(blocks: readonly T[]): T[] {
84 return blocks.filter((block) => block.type !== 'plan_draft').map(cloneBlock)

Callers 2

appendPlanToBlocksFunction · 0.90
planBlocks.test.tsFile · 0.90

Calls 2

isPlanDraftBlockFunction · 0.85
toPlanContentBlockFunction · 0.85

Tested by

no test coverage detected