(
spec: { type: string; content?: string; metadata?: Record<string, unknown> },
index: number
)
| 404 | ] |
| 405 | |
| 406 | function createBlock( |
| 407 | spec: { type: string; content?: string; metadata?: Record<string, unknown> }, |
| 408 | index: number |
| 409 | ): DeepnoteBlock { |
| 410 | const base = { |
| 411 | id: randomUUID(), |
| 412 | blockGroup: randomUUID(), |
| 413 | sortingKey: generateSortingKey(index), |
| 414 | type: spec.type, |
| 415 | content: spec.content !== undefined ? spec.content : '', |
| 416 | metadata: spec.metadata !== undefined ? spec.metadata : {}, |
| 417 | } |
| 418 | |
| 419 | // Add execution fields for executable blocks |
| 420 | const candidate = executableBlockTypeSet.has(spec.type) |
| 421 | ? { |
| 422 | ...base, |
| 423 | executionCount: null, |
| 424 | outputs: [], |
| 425 | } |
| 426 | : base |
| 427 | |
| 428 | const parsed = deepnoteBlockSchema.safeParse(candidate) |
| 429 | if (!parsed.success) { |
| 430 | throw new Error( |
| 431 | `Invalid block spec for type "${spec.type}": ${parsed.error.issues[0]?.message ?? 'schema validation failed'}` |
| 432 | ) |
| 433 | } |
| 434 | |
| 435 | return parsed.data |
| 436 | } |
| 437 | |
| 438 | async function handleCreate(args: Record<string, unknown>) { |
| 439 | const parsedArgs = createArgsSchema.safeParse(args) |
no test coverage detected