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.

15.4 KB
Raw Blame
{
  "db_name": "PostgreSQL",
  "query": "\n            WITH user_source_ids AS (\n                SELECT cp.channel_id::text AS source_id\n                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 AS source_id\n                FROM team_user t\n                WHERE t.user_id = $1\n                UNION ALL\n                SELECT $1 AS source_id\n            ),\n            visible_calls AS (\n                SELECT\n                    c.id AS call_id,\n                    c.channel_id,\n                    c.room_name,\n                    c.created_by,\n                    c.created_at AS started_at,\n                    NULL::timestamptz AS ended_at,\n                    NULL::bigint AS duration_ms,\n                    c.egress_id,\n                    c.recording_key,\n                    c.preview_url,\n                    c.recording_started_at,\n                    (SELECT title FROM call_meetings WHERE id = c.meeting_id) AS custom_name,\n                    NULL::text AS summary,\n                    c.share_with_team,\n                    sp.team_share_access_level,\n                    true AS is_active,\n                    false AS is_imported,\n                    CASE\n                        WHEN EXISTS (\n                            SELECT 1 FROM call_participants cp\n                            WHERE cp.call_id = c.id AND cp.user_id = $1\n                        ) THEN 'ATTENDED'::text\n                        WHEN EXISTS (\n                            SELECT 1 FROM comms_channel_participants ccp\n                            WHERE ccp.channel_id = c.channel_id\n                              AND ccp.user_id = $1\n                              AND ccp.left_at IS NULL\n                        ) THEN 'MISSED'::text\n                        ELSE 'UNATTENDED'::text\n                    END AS status\n                FROM calls c\n                JOIN \"SharePermission\" sp ON sp.id = c.share_permission_id\n                WHERE EXISTS (\n                    SELECT 1 FROM entity_access ea\n                    JOIN user_source_ids u ON u.source_id = ea.source_id\n                    WHERE ea.entity_id = c.id\n                      AND ea.entity_type = 'call'\n                      AND (c.channel_id IS NOT NULL OR (ea.source_type = 'user' AND ea.source_id = $1))\n                )\n                AND ($3::bool IS FALSE OR c.channel_id = ANY($4))\n                AND ($5::bool IS FALSE OR c.id = ANY($6))\n                -- Property conditions in conjunctive normal form: every\n                -- clause needs a term the call satisfies. Tags (no\n                -- definition) match any property value; entity references\n                -- match their definition's value.\n                AND NOT EXISTS (\n                    SELECT 1\n                    FROM generate_series(0, $9::int - 1) AS clause(idx)\n                    WHERE NOT EXISTS (\n                        SELECT 1\n                        FROM UNNEST($10::int[], $11::bool[], $12::uuid[], $13::text[])\n                            AS term(clause_idx, negated, definition_id, value)\n                        WHERE term.clause_idx = clause.idx\n                          AND term.negated <> EXISTS (\n                              SELECT 1 FROM entity_properties ep\n                              WHERE ep.entity_id = c.id::text\n                                AND ep.entity_type = 'CALL_RECORD'\n                                AND jsonb_typeof(ep.values -> 'value') = 'array'\n                                AND CASE\n                                    WHEN term.definition_id IS NULL\n                                        THEN jsonb_exists(ep.values -> 'value', term.value)\n                                    ELSE ep.property_definition_id = term.definition_id\n                                        AND ep.values -> 'value' @> jsonb_build_array(\n                                            jsonb_build_object('entity_id', term.value)\n                                        )\n                                END\n                          )\n                    )\n                )\n                UNION ALL\n                SELECT\n                    cr.id AS call_id,\n                    cr.channel_id,\n                    cr.room_name,\n                    cr.created_by,\n                    cr.started_at,\n                    cr.ended_at,\n                    cr.duration_ms,\n                    cr.egress_id,\n                    cr.recording_key,\n                    cr.preview_url,\n                    cr.recording_started_at,\n                    cr.custom_name,\n                    cr.summary,\n                    (sp.team_share_access_level IS NOT NULL) AS share_with_team,\n                    sp.team_share_access_level,\n                    false AS is_active,\n                    false AS is_imported,\n                    CASE\n                        WHEN EXISTS (\n                            SELECT 1 FROM call_record_participants crp\n                            WHERE crp.call_record_id = cr.id AND crp.user_id = $1\n                        ) THEN 'ATTENDED'::text\n                        WHEN EXISTS (\n                            SELECT 1 FROM comms_channel_participants ccp\n                            WHERE ccp.channel_id = cr.channel_id\n                              AND ccp.user_id = $1\n                              AND ccp.left_at IS NULL\n                        ) THEN 'MISSED'::text\n                        ELSE 'UNATTENDED'::text\n                    END AS status\n                FROM call_records cr\n                JOIN \"SharePermission\" sp ON sp.id = cr.share_permission_id\n                WHERE EXISTS (\n                    SELECT 1 FROM entity_access ea\n                    JOIN user_source_ids u ON u.source_id = ea.source_id\n                    WHERE ea.entity_id = cr.id\n                      AND ea.entity_type = 'call'\n                      AND (cr.channel_id IS NOT NULL OR (ea.source_type = 'user' AND ea.source_id = $1))\n                )\n                AND ($3::bool IS FALSE OR cr.channel_id = ANY($4))\n                AND ($5::bool IS FALSE OR cr.id = ANY($6))\n                -- Property conditions in conjunctive normal form: every\n                -- clause needs a term the call satisfies. Tags (no\n                -- definition) match any property value; entity references\n                -- match their definition's value.\n                AND NOT EXISTS (\n                    SELECT 1\n                    FROM generate_series(0, $9::int - 1) AS clause(idx)\n                    WHERE NOT EXISTS (\n                        SELECT 1\n                        FROM UNNEST($10::int[], $11::bool[], $12::uuid[], $13::text[])\n                            AS term(clause_idx, negated, definition_id, value)\n                        WHERE term.clause_idx = clause.idx\n                          AND term.negated <> EXISTS (\n                              SELECT 1 FROM entity_properties ep\n                              WHERE ep.entity_id = cr.id::text\n                                AND ep.entity_type = 'CALL_RECORD'\n                                AND jsonb_typeof(ep.values -> 'value') = 'array'\n                                AND CASE\n                                    WHEN term.definition_id IS NULL\n                                        THEN jsonb_exists(ep.values -> 'value', term.value)\n                                    ELSE ep.property_definition_id = term.definition_id\n                                        AND ep.values -> 'value' @> jsonb_build_array(\n                                            jsonb_build_object('entity_id', term.value)\n                                        )\n                                END\n                          )\n                    )\n                )\n                UNION ALL\n                -- Imported calls (e.g. Granola) exist only as call entities;\n                -- native calls are mirrored there too, so exclude them.\n                SELECT\n                    ce.id AS call_id,\n                    ce.channel_id,\n                    NULL::text AS room_name,\n                    ce.user_id AS created_by,\n                    COALESCE(ce.started_at, ce.created_at) AS started_at,\n                    ce.ended_at,\n                    ce.duration_ms,\n                    NULL::text AS egress_id,\n                    NULL::text AS recording_key,\n                    NULL::text AS preview_url,\n                    NULL::timestamptz AS recording_started_at,\n                    ce.title AS custom_name,\n                    (\n                        SELECT s.metadata ->> 'summary' FROM call_entity_sources s\n                        WHERE s.call_id = ce.id\n                        ORDER BY s.synced_at DESC NULLS LAST\n                        LIMIT 1\n                    ) AS summary,\n                    (sp.team_share_access_level IS NOT NULL) AS share_with_team,\n                    sp.team_share_access_level,\n                    false AS is_active,\n                    true AS is_imported,\n                    -- The importer was in the meeting; everyone else only\n                    -- sees it when shared, so it is not theirs to attend.\n                    CASE WHEN ce.user_id = $1 THEN 'ATTENDED'::text ELSE 'UNATTENDED'::text END AS status\n                FROM call_entities ce\n                JOIN \"SharePermission\" sp ON sp.id = ce.share_permission_id\n                WHERE ce.created_via <> 'native'\n                AND EXISTS (\n                    SELECT 1 FROM entity_access ea\n                    JOIN user_source_ids u ON u.source_id = ea.source_id\n                    WHERE ea.entity_id = ce.id\n                      AND ea.entity_type = 'call'\n                      AND (ce.channel_id IS NOT NULL OR (ea.source_type = 'user' AND ea.source_id = $1))\n                )\n                AND ($3::bool IS FALSE OR ce.channel_id = ANY($4))\n                AND ($5::bool IS FALSE OR ce.id = ANY($6))\n                AND NOT EXISTS (\n                    SELECT 1\n                    FROM generate_series(0, $9::int - 1) AS clause(idx)\n                    WHERE NOT EXISTS (\n                        SELECT 1\n                        FROM UNNEST($10::int[], $11::bool[], $12::uuid[], $13::text[])\n                            AS term(clause_idx, negated, definition_id, value)\n                        WHERE term.clause_idx = clause.idx\n                          AND term.negated <> EXISTS (\n                              SELECT 1 FROM entity_properties ep\n                              WHERE ep.entity_id = ce.id::text\n                                AND ep.entity_type = 'CALL_RECORD'\n                                AND jsonb_typeof(ep.values -> 'value') = 'array'\n                                AND CASE\n                                    WHEN term.definition_id IS NULL\n                                        THEN jsonb_exists(ep.values -> 'value', term.value)\n                                    ELSE ep.property_definition_id = term.definition_id\n                                        AND ep.values -> 'value' @> jsonb_build_array(\n                                            jsonb_build_object('entity_id', term.value)\n                                        )\n                                END\n                          )\n                    )\n                )\n            )\n            SELECT\n                call_id as \"call_id!\",\n                channel_id as \"channel_id?\",\n                room_name,\n                created_by as \"created_by!\",\n                started_at as \"started_at!\",\n                ended_at,\n                duration_ms,\n                egress_id,\n                recording_key,\n                preview_url,\n                recording_started_at,\n                custom_name,\n                summary,\n                share_with_team as \"share_with_team!\",\n                team_share_access_level as \"team_share_access_level?: AccessLevel\",\n                is_active as \"is_active!\",\n                is_imported as \"is_imported!\",\n                status as \"status!\"\n            FROM visible_calls\n            WHERE ($7::bool IS FALSE OR status = ANY($8::text[]))\n              -- Soup's keyset: calls sort by start, or by last activity.\n              AND (\n                  $15::timestamptz IS NULL\n                  OR (\n                      CASE WHEN $14 THEN started_at ELSE COALESCE(ended_at, started_at) END,\n                      call_id::text\n                  ) < ($15, $16::text)\n              )\n            ORDER BY\n                CASE WHEN $14 THEN started_at ELSE COALESCE(ended_at, started_at) END DESC,\n                call_id::text DESC\n            LIMIT $2\n            ",
  "describe": {
    "columns": [
      {
        "ordinal": 0,
        "name": "call_id!",
        "type_info": "Uuid"
      },
      {
        "ordinal": 1,
        "name": "channel_id?",
        "type_info": "Uuid"
      },
      {
        "ordinal": 2,
        "name": "room_name",
        "type_info": "Text"
      },
      {
        "ordinal": 3,
        "name": "created_by!",
        "type_info": "Text"
      },
      {
        "ordinal": 4,
        "name": "started_at!",
        "type_info": "Timestamptz"
      },
      {
        "ordinal": 5,
        "name": "ended_at",
        "type_info": "Timestamptz"
      },
      {
        "ordinal": 6,
        "name": "duration_ms",
        "type_info": "Int8"
      },
      {
        "ordinal": 7,
        "name": "egress_id",
        "type_info": "Text"
      },
      {
        "ordinal": 8,
        "name": "recording_key",
        "type_info": "Text"
      },
      {
        "ordinal": 9,
        "name": "preview_url",
        "type_info": "Text"
      },
      {
        "ordinal": 10,
        "name": "recording_started_at",
        "type_info": "Timestamptz"
      },
      {
        "ordinal": 11,
        "name": "custom_name",
        "type_info": "Text"
      },
      {
        "ordinal": 12,
        "name": "summary",
        "type_info": "Text"
      },
      {
        "ordinal": 13,
        "name": "share_with_team!",
        "type_info": "Bool"
      },
      {
        "ordinal": 14,
        "name": "team_share_access_level?: AccessLevel",
        "type_info": {
          "Custom": {
            "name": "\"AccessLevel\"",
            "kind": {
              "Enum": [
                "view",
                "comment",
                "edit",
                "owner"
              ]
            }
          }
        }
      },
      {
        "ordinal": 15,
        "name": "is_active!",
        "type_info": "Bool"
      },
      {
        "ordinal": 16,
        "name": "is_imported!",
        "type_info": "Bool"
      },
      {
        "ordinal": 17,
        "name": "status!",
        "type_info": "Text"
      }
    ],
    "parameters": {
      "Left": [
        "Text",
        "Int8",
        "Bool",
        "UuidArray",
        "Bool",
        "UuidArray",
        "Bool",
        "TextArray",
        "Int4",
        "Int4Array",
        "BoolArray",
        "UuidArray",
        "TextArray",
        "Bool",
        "Timestamptz",
        "Text"
      ]
    },
    "nullable": [
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null
    ]
  },
  "hash": "17472756d69dc95d7b01ac5ef8bab432a38de912d4f346e4827df8b2887462fa"
}