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.

1.4 KB
Raw Blame
import { itemToSafeName } from '@core/constant/allBlocks';
import type { Item } from '@service-storage/generated/schemas/item';
import { formatDocumentName } from '@service-storage/util/filename';
import type { HistoryItem, HistoryQueryResponse } from './types';

export function transformHistoryItem(item: Item): HistoryItem {
  const safeName = itemToSafeName(item);
  const name =
    item.type === 'document'
      ? formatDocumentName(safeName, item.fileType, {
          fullyQualifiedBlockName: true,
        })
      : safeName;
  const base = {
    id: item.id,
    name,
    createdAt: item.createdAt,
    updatedAt: item.updatedAt,
    deletedAt: item.deletedAt,
    rawName: item.name,
  };

  switch (item.type) {
    case 'document':
      return {
        ...base,
        type: 'document',
        fileType: item.fileType,
        subType: item.subType,
        ownerId: item.owner,
      };

    case 'chat':
      return {
        ...base,
        type: 'chat',
        isPersistent: item.isPersistent,
        ownerId: item.userId,
      };

    case 'project':
      return {
        ...base,
        type: 'project',
        ownerId: item.userId,
      };
  }
}

export function transformHistoryResponse(
  response: HistoryQueryResponse
): HistoryItem[] {
  return response.data
    .filter(
      (item) =>
        item.type !== 'document' ||
        item.subType?.type !== 'initiative_description'
    )
    .map(transformHistoryItem);
}