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.

9.1 KB
Raw Blame
{
  "db_name": "PostgreSQL",
  "query": "\n        WITH user_source_ids AS (\n            SELECT cp.channel_id::text as source_id FROM comms_channel_participants cp\n                WHERE cp.user_id = $1 AND cp.left_at IS NULL\n            UNION ALL\n            SELECT t.team_id::text FROM team_user t\n                WHERE t.user_id = $1\n            UNION ALL\n            SELECT $1\n        ),\n        Combined AS (\n            SELECT\n                'document' as \"item_type!\",\n                d.id as \"id!\",\n                CAST(COALESCE(di.id, db.id) as TEXT) as \"document_version_id\",\n                d.owner as \"user_id!\",\n                d.name as \"name!\",\n                d.\"branchedFromId\" as \"branched_from_id\",\n                d.\"branchedFromVersionId\" as \"branched_from_version_id\",\n                d.\"documentFamilyId\" as \"document_family_id\",\n                d.\"fileType\" as \"file_type\",\n                d.\"createdAt\"::timestamptz as \"created_at!\",\n                d.\"updatedAt\"::timestamptz as \"updated_at!\",\n                d.\"projectId\" as \"project_id\",\n                NULL as \"is_persistent\",\n                NULL::text as \"model\",\n                di.sha as \"sha\",\n                dt.sub_type as \"sub_type?: DocumentSubType\",\n                EXISTS (\n                    SELECT 1\n                    FROM document_email de\n                    WHERE de.document_id = d.id\n                ) as \"is_email_attachment!\",\n                (\n                    dt.sub_type IS DISTINCT FROM 'task'\n                    OR EXISTS (\n                        SELECT 1\n                        FROM entity_properties ep_assignees\n                        WHERE ep_assignees.entity_id = d.id\n                            AND ep_assignees.entity_type = 'TASK'\n                            AND ep_assignees.property_definition_id = $6\n                            AND ep_assignees.values->'value' @> jsonb_build_array(\n                                jsonb_build_object('entity_id', $1)\n                            )\n                    )\n                ) as \"is_important!\",\n                ARRAY(\n                    SELECT status_option_id::uuid\n                    FROM jsonb_array_elements_text(\n                        CASE\n                            WHEN jsonb_typeof(ep_status.values->'value') = 'array'\n                            THEN ep_status.values->'value'\n                            ELSE '[]'::jsonb\n                        END\n                    ) AS status_option_id\n                ) as \"status_option_ids!: Vec<Uuid>\",\n                uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n                CASE\n                    WHEN dt.sub_type = 'task'\n                        AND ep_status.values->'value' ? $4\n                    THEN true\n                    WHEN dt.sub_type = 'task'\n                    THEN false\n                    ELSE NULL\n                END as \"is_completed\",\n                d.\"deletedAt\"::timestamptz as \"deleted_at\"\n            FROM \"Document\" d\n            LEFT JOIN document_sub_type dt ON dt.document_id = d.id\n            LEFT JOIN entity_properties ep_status \n                ON dt.sub_type = 'task'\n                AND ep_status.entity_id = d.id \n                AND ep_status.entity_type = 'TASK'\n                AND ep_status.property_definition_id = $5\n            LEFT JOIN \"UserHistory\" uh \n                ON uh.\"itemId\" = d.id \n                AND uh.\"itemType\" = 'document' \n                AND uh.\"userId\" = $1\n            LEFT JOIN LATERAL (\n                SELECT b.id \n                FROM \"DocumentBom\" b \n                WHERE b.\"documentId\" = d.id \n                ORDER BY b.\"createdAt\" DESC \n                LIMIT 1\n            ) db ON true\n            LEFT JOIN LATERAL (\n                SELECT i.id, i.sha \n                FROM \"DocumentInstance\" i \n                WHERE i.\"documentId\" = d.id \n                ORDER BY i.\"updatedAt\" DESC \n                LIMIT 1\n            ) di ON true\n            WHERE d.\"deletedAt\" IS NULL\n            AND d.id = ANY($2::text[])\n            AND EXISTS (\n                SELECT 1 FROM entity_access ea\n                WHERE ea.entity_id::text = d.id\n                    AND ea.entity_type = 'document'\n                    AND ea.source_id = ANY(ARRAY(SELECT source_id FROM user_source_ids))\n            )\n\n            UNION ALL\n        \n            SELECT\n                'chat' as \"item_type!\",\n                c.id as \"id!\",\n                NULL as \"document_version_id\",\n                c.\"userId\" as \"user_id!\",\n                c.name as \"name!\",\n                NULL as \"branched_from_id\",\n                NULL as \"branched_from_version_id\",\n                NULL as \"document_family_id\",\n                NULL as \"file_type\",\n                c.\"createdAt\"::timestamptz as \"created_at!\",\n                c.\"updatedAt\"::timestamptz as \"updated_at!\",\n                c.\"projectId\" as \"project_id\",\n                c.\"isPersistent\" as \"is_persistent\",\n                c.model as \"model\",\n                NULL as \"sha\",\n                NULL as \"sub_type\",\n                false as \"is_email_attachment!\",\n                true as \"is_important!\",\n                ARRAY[]::uuid[] as \"status_option_ids!: Vec<Uuid>\",\n                uh.\"updatedAt\"::timestamptz as \"viewed_at\",\n                NULL as \"is_completed\",\n                c.\"deletedAt\"::timestamptz as \"deleted_at\"\n            FROM \"Chat\" c\n            LEFT JOIN \"UserHistory\" uh\n                ON uh.\"itemId\" = c.id\n                AND uh.\"itemType\" = 'chat'\n                AND uh.\"userId\" = $1\n            WHERE c.\"deletedAt\" IS NULL\n            AND c.id = ANY($3::text[])\n            AND EXISTS (\n                SELECT 1 FROM entity_access ea\n                WHERE ea.entity_id::text = c.id\n                    AND ea.entity_type = 'chat'\n                    AND ea.source_id = ANY(ARRAY(SELECT source_id FROM user_source_ids))\n            )\n        )\n        SELECT * \n        FROM Combined\n        ",
  "describe": {
    "columns": [
      {
        "ordinal": 0,
        "name": "item_type!",
        "type_info": "Text"
      },
      {
        "ordinal": 1,
        "name": "id!",
        "type_info": "Text"
      },
      {
        "ordinal": 2,
        "name": "document_version_id",
        "type_info": "Text"
      },
      {
        "ordinal": 3,
        "name": "user_id!",
        "type_info": "Text"
      },
      {
        "ordinal": 4,
        "name": "name!",
        "type_info": "Text"
      },
      {
        "ordinal": 5,
        "name": "branched_from_id",
        "type_info": "Text"
      },
      {
        "ordinal": 6,
        "name": "branched_from_version_id",
        "type_info": "Int8"
      },
      {
        "ordinal": 7,
        "name": "document_family_id",
        "type_info": "Int8"
      },
      {
        "ordinal": 8,
        "name": "file_type",
        "type_info": "Text"
      },
      {
        "ordinal": 9,
        "name": "created_at!",
        "type_info": "Timestamptz"
      },
      {
        "ordinal": 10,
        "name": "updated_at!",
        "type_info": "Timestamptz"
      },
      {
        "ordinal": 11,
        "name": "project_id",
        "type_info": "Text"
      },
      {
        "ordinal": 12,
        "name": "is_persistent",
        "type_info": "Bool"
      },
      {
        "ordinal": 13,
        "name": "model",
        "type_info": "Text"
      },
      {
        "ordinal": 14,
        "name": "sha",
        "type_info": "Text"
      },
      {
        "ordinal": 15,
        "name": "sub_type?: DocumentSubType",
        "type_info": {
          "Custom": {
            "name": "document_sub_type_value",
            "kind": {
              "Enum": [
                "task",
                "snippet",
                "skill",
                "initiative_description"
              ]
            }
          }
        }
      },
      {
        "ordinal": 16,
        "name": "is_email_attachment!",
        "type_info": "Bool"
      },
      {
        "ordinal": 17,
        "name": "is_important!",
        "type_info": "Bool"
      },
      {
        "ordinal": 18,
        "name": "status_option_ids!: Vec<Uuid>",
        "type_info": "UuidArray"
      },
      {
        "ordinal": 19,
        "name": "viewed_at",
        "type_info": "Timestamptz"
      },
      {
        "ordinal": 20,
        "name": "is_completed",
        "type_info": "Bool"
      },
      {
        "ordinal": 21,
        "name": "deleted_at",
        "type_info": "Timestamptz"
      }
    ],
    "parameters": {
      "Left": [
        "Text",
        "TextArray",
        "TextArray",
        "Text",
        "Uuid",
        "Uuid"
      ]
    },
    "nullable": [
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null
    ]
  },
  "hash": "16dca24944ad6d29aa1011d5b2b18d964fe1d31ffaef2982499c24f04c2a9c03"
}