Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

700 B
Raw Blame
import {
  type CanvasFile,
  canvasVersion,
  readCanvasFile,
} from './document-format';
import { type LegacyTextCodec, migrateLegacyCanvas } from './migrate-legacy';

export type CanvasLoadResult =
  | { kind: 'next'; file: CanvasFile }
  | { kind: 'error'; message: string };

export function loadCanvasFile(
  value: unknown,
  text: LegacyTextCodec
): CanvasLoadResult {
  try {
    return {
      kind: 'next',
      file:
        canvasVersion(value) === 2
          ? readCanvasFile(value)
          : migrateLegacyCanvas(value, text),
    };
  } catch (error) {
    return {
      kind: 'error',
      message: error instanceof Error ? error.message : 'Could not open canvas',
    };
  }
}