diff --git a/memento-note/lib/ai/tools/excalidraw.tool.ts b/memento-note/lib/ai/tools/excalidraw.tool.ts index f07e066..0d032e6 100644 --- a/memento-note/lib/ai/tools/excalidraw.tool.ts +++ b/memento-note/lib/ai/tools/excalidraw.tool.ts @@ -4,7 +4,16 @@ import { tool } from 'ai' import { z } from 'zod' import { toolRegistry } from './registry' import { prisma } from '@/lib/prisma' -import dagre from 'dagre' +// import type is erased at build time — Turbopack won't try to resolve the module +import type dagreType from 'dagre' +let _dagre: typeof dagreType | null = null +async function getDagre(): Promise { + if (!_dagre) { + const mod = await import('dagre') + _dagre = (mod.default ?? mod) as typeof dagreType + } + return _dagre +} interface SimplifiedNode { id: string @@ -504,12 +513,13 @@ function getNodeRenderSpec(node: SimplifiedNode, isCenter: boolean): NodeRenderS return { text: wrapped, fontSize, width, height } } -function computeNodeLayoutForRankdir( +async function computeNodeLayoutForRankdir( nodes: SimplifiedNode[], edges: SimplifiedEdge[], rankdir: 'LR' | 'TB', renderSpecs: Map, -): Map { +): Promise> { + const dagre = await getDagre() const graph = new dagre.graphlib.Graph() graph.setGraph({ rankdir, @@ -738,11 +748,11 @@ async function computeNodeLayout( const firstRankdir: 'LR' | 'TB' = (diagramType === 'org-chart') ? 'TB' : 'LR' const secondRankdir: 'LR' | 'TB' = firstRankdir === 'LR' ? 'TB' : 'LR' - const lrLayout = computeNodeLayoutForRankdir(nodes, edges, firstRankdir, renderSpecs) + const lrLayout = await computeNodeLayoutForRankdir(nodes, edges, firstRankdir, renderSpecs) const lrQuality = computeLayoutQuality(nodes, edges, lrLayout) const lrBounds = getLayoutBounds(lrLayout) - const tbLayout = computeNodeLayoutForRankdir(nodes, edges, secondRankdir, renderSpecs) + const tbLayout = await computeNodeLayoutForRankdir(nodes, edges, secondRankdir, renderSpecs) const tbQuality = computeLayoutQuality(nodes, edges, tbLayout) const tbBounds = getLayoutBounds(tbLayout) diff --git a/memento-note/lib/ai/tools/pptx.tool.ts b/memento-note/lib/ai/tools/pptx.tool.ts index 32309e1..c584dbe 100644 --- a/memento-note/lib/ai/tools/pptx.tool.ts +++ b/memento-note/lib/ai/tools/pptx.tool.ts @@ -1,6 +1,16 @@ 'use server' -import PptxGenJS from 'pptxgenjs' +// import type is erased at build time — Turbopack won't try to resolve the module +import type PptxGenJSModule from 'pptxgenjs' +// Lazy singleton — actual module loaded at runtime only +let _PptxGenJS: (new () => PptxGenJSModule) | null = null +async function getPptxGenClass(): Promise PptxGenJSModule> { + if (!_PptxGenJS) { + const mod = await import('pptxgenjs') + _PptxGenJS = (mod.default ?? mod) as unknown as new () => PptxGenJSModule + } + return _PptxGenJS +} import { tool } from 'ai' import { z } from 'zod' import { toolRegistry } from './registry' @@ -960,10 +970,11 @@ function addClosingSlide(pres: PptxGenJS, spec: PresentationSpec, t: Theme, styl return s } -function buildPresentation(spec: PresentationSpec): PptxGenJS { +async function buildPresentation(spec: PresentationSpec): Promise { const { theme } = resolveTheme(spec) const style = STYLES[spec.style || 'soft'] || STYLES.soft! + const PptxGenJS = await getPptxGenClass() const pres = new PptxGenJS() pres.title = spec.title pres.author = 'Momento' @@ -1131,7 +1142,7 @@ RULES: } } - const pptx = buildPresentation(spec) + const pptx = await buildPresentation(spec) const base64 = await pptx.write({ outputType: 'base64' }) as string const canvas = await prisma.canvas.create({