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.

4.0 KB
Raw Blame
{
  "db_name": "PostgreSQL",
  "query": "\n        INSERT INTO email_mailbox_drafts (message_id,link_id,generation,actor_id,desired_content,base_version,provider_id)\n        SELECT m.id,m.link_id,l.sync_generation,$3,\n            jsonb_build_object('db_id',m.id,'provider_id',m.provider_id,'replying_to_id',m.replying_to_id,\n                'provider_thread_id',m.provider_thread_id,'thread_db_id',m.thread_id,'subject',COALESCE(m.subject,''),\n                'body_text',m.body_text,'body_html',m.body_html_sanitized,'body_macro',m.body_macro,'headers_json',m.headers_jsonb,\n                'actor_id',$3::text,'send_time',(SELECT send_time FROM email_scheduled_messages WHERE message_id = m.id),\n                'to',COALESCE(recipients.to_addresses,'[]'::jsonb),'cc',COALESCE(recipients.cc_addresses,'[]'::jsonb),'bcc',COALESCE(recipients.bcc_addresses,'[]'::jsonb),\n                '_attachments',jsonb_build_object(\n                    'uploads',COALESCE((SELECT jsonb_agg(to_jsonb(a) ORDER BY a.id) FROM email_attachments_drafts a WHERE a.draft_id = m.id AND NOT a.upload_pending),'[]'::jsonb),\n                    'forwarded',COALESCE((SELECT jsonb_agg(jsonb_build_object('id',a.id,'filename',a.filename,'mime_type',a.mime_type,'content_id',a.content_id,\n                        'provider_attachment_id',a.provider_attachment_id,'provider_id',source.provider_id,'link_id',source.link_id,'thread_id',source.thread_id,'grant_generation',sl.grant_generation) ORDER BY a.id)\n                        FROM email_attachments_fwd f JOIN email_attachments a ON a.id = f.attachment_id JOIN email_messages source ON source.id = a.message_id JOIN email_links sl ON sl.id = source.link_id\n                        WHERE f.message_id = m.id),'[]'::jsonb),\n                    'removals',COALESCE((SELECT jsonb_agg(CASE WHEN r.provider_id IS NOT NULL THEN jsonb_build_object('kind','provider_id','value',r.provider_id) ELSE jsonb_build_object('kind','content_id','value',r.content_id) END ORDER BY r.id)\n                        FROM email_draft_attachment_removals r WHERE r.message_id = m.id),'[]'::jsonb))),\n            COALESCE((SELECT versions[cardinality(versions)] FROM email_draft_organization_versions v\n                WHERE v.message_id=m.id AND m.provider_version=ANY(v.versions)),m.provider_version),m.provider_id\n        FROM email_messages m JOIN email_links l ON l.id = m.link_id\n        CROSS JOIN LATERAL (\n            SELECT jsonb_agg(jsonb_build_object('email',c.email_address,'name',COALESCE(r.name,c.name))) FILTER (WHERE r.recipient_type = 'TO') AS to_addresses,\n                jsonb_agg(jsonb_build_object('email',c.email_address,'name',COALESCE(r.name,c.name))) FILTER (WHERE r.recipient_type = 'CC') AS cc_addresses,\n                jsonb_agg(jsonb_build_object('email',c.email_address,'name',COALESCE(r.name,c.name))) FILTER (WHERE r.recipient_type = 'BCC') AS bcc_addresses\n            FROM email_message_recipients r JOIN email_contacts c ON c.id = r.contact_id WHERE r.message_id = m.id\n        ) recipients\n        WHERE m.id = $1 AND m.link_id = $2 AND l.provider = 'OUTLOOK'\n        ON CONFLICT (message_id) DO UPDATE SET\n            revision = email_mailbox_drafts.revision + 1,desired_content = EXCLUDED.desired_content,actor_id = EXCLUDED.actor_id,\n            checkpoint = CASE WHEN email_mailbox_drafts.state = 'synced' OR (email_mailbox_drafts.state='failed' AND email_mailbox_drafts.error_code='invalid_content') THEN NULL ELSE email_mailbox_drafts.checkpoint END,\n            error_code = CASE WHEN email_mailbox_drafts.state='failed' AND email_mailbox_drafts.error_code='invalid_content' THEN NULL ELSE email_mailbox_drafts.error_code END,\n            state = CASE WHEN email_mailbox_drafts.state IN ('synced','failed','cancelled') THEN 'pending' ELSE email_mailbox_drafts.state END,\n            available_at = now(),updated_at = now()\n    ",
  "describe": {
    "columns": [],
    "parameters": {
      "Left": [
        "Uuid",
        "Uuid",
        "Text"
      ]
    },
    "nullable": []
  },
  "hash": "f619002c0a005e47ae8c2674ed51e002e1a557de07b66060efd53df22aec58d7"
}