MCPcopy
hub / github.com/srcbookdev/srcbook / createNewCell

Function createNewCell

packages/web/src/routes/session.tsx:240–262  ·  view source on GitHub ↗
(type: 'code' | 'markdown' | 'generate-ai', index: number)

Source from the content-addressed store, hash-verified

238 }
239
240 async function createNewCell(type: 'code' | 'markdown' | 'generate-ai', index: number) {
241 if (!channel) {
242 return;
243 }
244
245 // First, create the cell on client.
246 // Then, push state to server, _only_ for code or markdown cells. AI generation is a client side only cell.
247 // TODO: Handle potential errors (eg, rollback optimistic client creation if there are errors)
248 let cell;
249 switch (type) {
250 case 'code':
251 cell = createCodeCell(index, session.language);
252 channel.push('cell:create', { index, cell });
253 break;
254 case 'markdown':
255 cell = createMarkdownCell(index);
256 channel.push('cell:create', { index, cell });
257 break;
258 case 'generate-ai':
259 cell = createGenerateAiCell(index);
260 break;
261 }
262 }
263
264 async function insertGeneratedCells(idx: number, cells: Array<CodeCellType | MarkdownCellType>) {
265 if (!channel) {

Callers 1

SessionFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected