Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(channels): Send message tool (#4387)
Eric Hayes001be5e3679a
diff --git a/js/app/packages/channel/Channel/message-grouping-meta.ts b/js/app/packages/channel/Channel/message-grouping-meta.tsindex 28db8af47d..feb586d73e 100644--- a/js/app/packages/channel/Channel/message-grouping-meta.ts+++ b/js/app/packages/channel/Channel/message-grouping-meta.ts@@ -2,7 +2,7 @@ import type { ApiChannelMessage } from '@service-storage/generated/schemas/apiChexport type GroupableMessage = Pick<ApiChannelMessage,- 'id' | 'sender_id' | 'created_at' | 'attachments' | 'deleted_at'+ 'id' | 'sender_id' | 'sender' | 'created_at' | 'attachments' | 'deleted_at'> & {thread?: Pick<ApiChannelMessage['thread'], 'reply_count'>;};@@ -23,6 +23,12 @@ export function shouldGroupWithPreviousMessage(): boolean {if (!previous) return false;if (current.sender_id !== previous.sender_id) return false;+ // Agent messages share the Macro bot's sender_id but carry the triggering+ // user in `sender.triggered_by`; messages prompted by different users must+ // not merge under a single "from" pill.+ if (current.sender?.triggered_by !== previous.sender?.triggered_by) {+ return false;+ }if (isDeleted(current) || isDeleted(previous)) return false;if (hasThreadReplies(previous)) return false;diff --git a/js/app/packages/channel/Channel/tests/message-list-meta.test.ts b/js/app/packages/channel/Channel/tests/message-list-meta.test.tsindex d643ef22a7..2741ff9553 100644--- a/js/app/packages/channel/Channel/tests/message-list-meta.test.ts+++ b/js/app/packages/channel/Channel/tests/message-list-meta.test.ts@@ -1,12 +1,14 @@import { senderFromStorageId } from '@queries/channel/message-sender';import type { ApiChannelMessage } from '@service-storage/generated/schemas/apiChannelMessage';+import type { ApiMessageSender } from '@service-storage/generated/schemas/apiMessageSender';import { describe, expect, it } from 'vitest';import { buildChannelMessageListMeta } from '../message-list-meta';function createMessage(id: string,createdAt: string,- senderId = 'user-1'+ senderId = 'user-1',+ sender: ApiMessageSender = senderFromStorageId(senderId)): ApiChannelMessage {return {id,@@ -14,7 +16,7 @@ function createMessage(content: '',created_at: createdAt,updated_at: createdAt,- sender: senderFromStorageId(senderId),+ sender,sender_id: senderId,attachments: [],reactions: [],@@ -79,4 +81,42 @@ describe('buildChannelMessageListMeta', () => {expect(meta.m2.isGroupedWithPrevious).toBe(true);expect(meta.m3.isGroupedWithPrevious).toBe(true);});++ it('does not group agent messages triggered by different users, despite a shared bot sender_id', () => {+ const botId = 'bot|00000000-0000-0000-0000-000000000000';+ const agentSender = (triggeredBy: string): ApiMessageSender => ({+ type: 'bot',+ id: '00000000-0000-0000-0000-000000000000',+ name: 'Macro',+ triggered_by: triggeredBy,+ });+ const messages = [+ // Two Macro-agent messages with the same bot sender_id but triggered by+ // different users must not merge under one "from" pill.+ createMessage(+ 'm1',+ '2026-02-20T09:00:00.000Z',+ botId,+ agentSender('user-a')+ ),+ createMessage(+ 'm2',+ '2026-02-20T09:01:00.000Z',+ botId,+ agentSender('user-b')+ ),+ // A third triggered by the same user as m2 groups with it.+ createMessage(+ 'm3',+ '2026-02-20T09:02:00.000Z',+ botId,+ agentSender('user-b')+ ),+ ];++ const meta = buildChannelMessageListMeta(messages, () => false);++ expect(meta.m2.isGroupedWithPrevious).toBe(false);+ expect(meta.m3.isGroupedWithPrevious).toBe(true);+ });});diff --git a/js/app/packages/channel/Message/ChannelMessage.tsx b/js/app/packages/channel/Message/ChannelMessage.tsxindex 1a4565ed3e..5d5931aaeb 100644--- a/js/app/packages/channel/Message/ChannelMessage.tsx+++ b/js/app/packages/channel/Message/ChannelMessage.tsx@@ -126,14 +126,17 @@ function RegularMessageLayout(props: {<Message.Slot placement="icon"><Message.SenderIcon /></Message.Slot>- <Message.Slot placement="header" class="flex items-center gap-1 min-w-0">- <Message.SenderName />- <Message.AgentBadge />- <Message.EditedIndicator />- {/* On message hover, timestamp floats above actions. */}- <div class="grow shrink-0 min-w-0 flex justify-end group-hover/message:absolute group-hover/message:right-1 group-hover/message:-top-9 group-hover/message:p-1 group-hover/message:bg-surface group-hover/message:rounded-md">- <Message.Timestamp class="ml-auto shrink-0" format="dateAndTime" />+ <Message.Slot placement="header" class="flex flex-col gap-0.5 min-w-0">+ <div class="flex items-center gap-1 min-w-0">+ <Message.SenderName />+ <Message.AgentBadge />+ <Message.EditedIndicator />+ {/* On message hover, timestamp floats above actions. */}+ <div class="grow shrink-0 min-w-0 flex justify-end group-hover/message:absolute group-hover/message:right-1 group-hover/message:-top-9 group-hover/message:p-1 group-hover/message:bg-surface group-hover/message:rounded-md">+ <Message.Timestamp class="ml-auto shrink-0" format="dateAndTime" />+ </div></div>+ <Message.FromPill /></Message.Slot><Message.Slot placement="content" class="ph-no-capture"><MessageContentSlotdiff --git a/js/app/packages/channel/Message/FromPill.tsx b/js/app/packages/channel/Message/FromPill.tsxnew file mode 100644index 0000000000..952d98c353--- /dev/null+++ b/js/app/packages/channel/Message/FromPill.tsx@@ -0,0 +1,64 @@+import { HoverCard } from '@core/component/HoverCard';+import { UserTooltip } from '@core/component/UserTooltip';+import { macroIdToEmail, tryMacroId, useDisplayName } from '@core/user';+import { cn } from '@ui';+import { createSignal, Show } from 'solid-js';+import { useMessage } from './context';++type FromPillProps = {+ class?: string;+};++/**+ * Shows who triggered an agent (bot) message, e.g. `from Eric Hayes`, where the+ * name is a hoverable user reference (same hover card as an `@mention`).+ * Rendered only when the message's sender carries a `triggered_by` user id.+ */+export function FromPill(props: FromPillProps) {+ const message = useMessage();+ const triggeredBy = () => message().sender?.triggered_by ?? undefined;+ const macroId = () => {+ const id = triggeredBy();+ return id ? tryMacroId(id) : undefined;+ };+ const [displayName] = useDisplayName(macroId());+ const email = () => {+ const id = macroId();+ return id ? macroIdToEmail(id) : (triggeredBy() ?? '');+ };+ const label = () => displayName() || email() || (triggeredBy() ?? '');++ const [open, setOpen] = createSignal(false);++ return (+ <Show when={triggeredBy()}>+ <span+ class={cn(+ 'inline-flex items-center gap-1 text-xs text-ink-muted',+ props.class+ )}+ >+ from+ <HoverCard+ placement="top"+ open={open()}+ onOpenChange={setOpen}+ triggerAs="span"+ trigger={+ <span class="cursor-default rounded-md p-0.5 font-medium text-accent hover:bg-accent/20 focus:bg-accent/20">+ {label()}+ </span>+ }+ content={+ <UserTooltip+ displayName={label()}+ email={email()}+ id={triggeredBy()}+ onClose={() => setOpen(false)}+ />+ }+ />+ </span>+ </Show>+ );+}diff --git a/js/app/packages/channel/Message/Message.ts b/js/app/packages/channel/Message/Message.tsindex 6bab286a1d..3093acf81f 100644--- a/js/app/packages/channel/Message/Message.ts+++ b/js/app/packages/channel/Message/Message.ts@@ -4,6 +4,7 @@ import { Attachments } from './Attachments';import { Content } from './Content';import { DateDivider } from './DateDivider';import { EditedIndicator } from './EditedIndicator';+import { FromPill } from './FromPill';import { HoverActions } from './HoverActions';import { Layout } from './Layout';import { MediaPreview } from './MediaPreview';@@ -22,6 +23,7 @@ export const Message = {Slot,SenderName,AgentBadge,+ FromPill,SenderIcon,Timestamp,Content,diff --git a/js/app/packages/channel/StandaloneThread/ParentMessage.tsx b/js/app/packages/channel/StandaloneThread/ParentMessage.tsxindex 59a4118512..7dad7e6ff4 100644--- a/js/app/packages/channel/StandaloneThread/ParentMessage.tsx+++ b/js/app/packages/channel/StandaloneThread/ParentMessage.tsx@@ -30,15 +30,18 @@ export function ParentMessage(props: ParentMessageProps) {</Message.Slot><Message.Slotplacement="header"- class="flex items-center gap-1 min-w-0"+ class="flex flex-col gap-0.5 min-w-0">- <Message.SenderName />- <Message.AgentBadge />- <Message.EditedIndicator />- <Message.Timestamp- class="ml-auto shrink-0"- format="dateAndTime"- />+ <div class="flex items-center gap-1 min-w-0">+ <Message.SenderName />+ <Message.AgentBadge />+ <Message.EditedIndicator />+ <Message.Timestamp+ class="ml-auto shrink-0"+ format="dateAndTime"+ />+ </div>+ <Message.FromPill /></Message.Slot><Message.Slot placement="content"><Message.Content />diff --git a/js/app/packages/channel/StandaloneThread/Replies.tsx b/js/app/packages/channel/StandaloneThread/Replies.tsxindex 8301023f3e..c5a34139aa 100644--- a/js/app/packages/channel/StandaloneThread/Replies.tsx+++ b/js/app/packages/channel/StandaloneThread/Replies.tsx@@ -96,15 +96,18 @@ export function Replies(props: RepliesProps) {<Show when={!meta()?.isGroupedWithPrevious}><Message.Slotplacement="header"- class="flex items-center gap-1 min-w-0"+ class="flex flex-col gap-0.5 min-w-0">- <Message.SenderName />- <Message.AgentBadge />- <Message.EditedIndicator />- <Message.Timestamp- class="ml-auto shrink-0"- format="dateAndTime"- />+ <div class="flex items-center gap-1 min-w-0">+ <Message.SenderName />+ <Message.AgentBadge />+ <Message.EditedIndicator />+ <Message.Timestamp+ class="ml-auto shrink-0"+ format="dateAndTime"+ />+ </div>+ <Message.FromPill /></Message.Slot></Show><Message.Slot placement="content">diff --git a/js/app/packages/core/component/AI/component/tool/SendChannelMessage.tsx b/js/app/packages/core/component/AI/component/tool/SendChannelMessage.tsxnew file mode 100644index 0000000000..300d844594--- /dev/null+++ b/js/app/packages/core/component/AI/component/tool/SendChannelMessage.tsx@@ -0,0 +1,27 @@+import { useChannelName } from '@core/context/channels';+import PaperPlaneTilt from '@phosphor-icons/core/regular/paper-plane-tilt.svg';+import { BaseTool } from './BaseTool';+import { createToolRenderer } from './ToolRenderer';++export const sendChannelMessageHandler = createToolRenderer({+ name: 'SendChannelMessage',+ render: (ctx) => {+ const channelName = useChannelName(ctx.tool.data.channel_id, 'Channel');++ return (+ <BaseTool+ type={ctx.response ? 'response' : 'call'}+ icon={PaperPlaneTilt}+ renderContext={ctx.renderContext}+ >+ <div class="flex min-w-0 flex-1 items-center justify-between gap-3 overflow-hidden">+ <span class="min-w-0 truncate">+ {ctx.response ? 'Sent message to' : 'Send message to'}{' '}+ <span class="text-ink">{channelName()}</span>+ {ctx.tool.data.thread_id ? ' thread' : ''}+ </span>+ </div>+ </BaseTool>+ );+ },+});diff --git a/js/app/packages/core/component/AI/component/tool/handler.tsx b/js/app/packages/core/component/AI/component/tool/handler.tsxindex b8b5f9b8ea..abbceabc14 100644--- a/js/app/packages/core/component/AI/component/tool/handler.tsx+++ b/js/app/packages/core/component/AI/component/tool/handler.tsx@@ -36,6 +36,7 @@ import { readThreadHandler } from './ReadThread';import { renameDocumentHandler } from './RenameDocument';import { contentSearchHandler, nameSearchHandler } from './Search';import { searchToolsHandler } from './SearchTools';+import { sendChannelMessageHandler } from './SendChannelMessage';import { sendEmailHandler } from './SendEmail';import { subagentHandler } from './Subagent';import { textEditorCodeExecutionHandler } from './TextEditorCodeExecution';@@ -77,6 +78,7 @@ const toolHandlers: ToolHandlerMap<RenderContext> = {ReadMetadata: readMetadataHandler,RenameDocument: renameDocumentHandler,SearchTools: searchToolsHandler,+ SendChannelMessage: sendChannelMessageHandler,SendEmail: sendEmailHandler,SetEntityProperty: setEntityPropertyHandler,Subagent: subagentHandler,diff --git a/js/app/packages/service-clients/service-cognition/generated/tools/schemas.ts b/js/app/packages/service-clients/service-cognition/generated/tools/schemas.tsindex adda1e7ee5..70895560cf 100644--- a/js/app/packages/service-clients/service-cognition/generated/tools/schemas.ts+++ b/js/app/packages/service-clients/service-cognition/generated/tools/schemas.ts@@ -1978,6 +1978,17 @@ export const SearchToolsResponse = z.object({results: z.array(z.object({ description: z.string(), name: z.string() })),});+export const SendChannelMessage = z.object({+ channel_id: z.string().uuid(),+ content: z.string(),+ thread_id: z.union([z.string().uuid(), z.null()]).optional(),+});++export const SendChannelMessageResponse = z.object({+ channel_id: z.string().uuid(),+ message_id: z.string(),+});+export const SendEmail = z.object({bcc: z.array(diff --git a/js/app/packages/service-clients/service-cognition/generated/tools/tool.ts b/js/app/packages/service-clients/service-cognition/generated/tools/tool.tsindex 29d0e7ac16..697caec0e3 100644--- a/js/app/packages/service-clients/service-cognition/generated/tools/tool.ts+++ b/js/app/packages/service-clients/service-cognition/generated/tools/tool.ts@@ -85,6 +85,10 @@ type ToolParserMap = {response: types.RenameDocumentResponse;};SearchTools: { call: types.SearchTools; response: types.SearchToolsResponse };+ SendChannelMessage: {+ call: types.SendChannelMessage;+ response: types.SendChannelMessageResponse;+ };SendEmail: { call: types.SendEmail; response: types.UserToolResponse };SetEntityProperty: {call: types.SetEntityProperty;@@ -196,6 +200,10 @@ const toolParserMap = {call: schemas.SearchTools,response: schemas.SearchToolsResponse,},+ SendChannelMessage: {+ call: schemas.SendChannelMessage,+ response: schemas.SendChannelMessageResponse,+ },SendEmail: { call: schemas.SendEmail, response: schemas.UserToolResponse },SetEntityProperty: {call: schemas.SetEntityProperty,@@ -300,6 +308,10 @@ type ToolDataMap = {response: types.RenameDocumentResponse;};SearchTools: { call: types.SearchTools; response: types.SearchToolsResponse };+ SendChannelMessage: {+ call: types.SendChannelMessage;+ response: types.SendChannelMessageResponse;+ };SendEmail: { call: types.SendEmail; response: types.UserToolResponse };SetEntityProperty: {call: types.SetEntityProperty;diff --git a/js/app/packages/service-clients/service-cognition/generated/tools/types.ts b/js/app/packages/service-clients/service-cognition/generated/tools/types.tsindex 83b75581b2..ccc6d5e060 100644--- a/js/app/packages/service-clients/service-cognition/generated/tools/types.ts+++ b/js/app/packages/service-clients/service-cognition/generated/tools/types.ts@@ -2609,6 +2609,27 @@ export interface SearchToolsResponse {*/results: ToolMatch[];}+/**+ * Send or reply to a channel on behalf of the user. Only use this when explicitly asked to send a message+ */+export interface SendChannelMessage {+ /**+ * The channel id to send the message to+ */+ channel_id: string;+ /**+ * Message content in macro markdown format. This uses the same syntax as markdown documents+ */+ content: string;+ /**+ * An optional thread id to reply too+ */+ thread_id?: string | null;+}+export interface SendChannelMessageResponse {+ channel_id: string;+ message_id: string;+}/*** Draft, compose, and send an email. ALWAYS use this tool whenever the user asks you to draft, write, compose, or send an email (or reply to one) — never write the email as plain text in the chat. This tool opens the email draft in the composer for the user to review, edit, and confirm before it is sent, so it is the correct tool even when the user only wants a draft. To reply to an existing message, provide the replying_to_id. Write the body in Markdown — use **bold**, *italics*, lists, links, and other standard Markdown formatting. The draft composer renders the Markdown for the user to review and edit; the composer produces HTML that is sent as the actual email body.*/diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/apiMessageSender.ts b/js/app/packages/service-clients/service-storage/generated/schemas/apiMessageSender.tsindex b2817c0a4f..22bcb8f790 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/apiMessageSender.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/apiMessageSender.ts@@ -6,6 +6,7 @@*/import type { ApiMessageSenderAvatarUrl } from './apiMessageSenderAvatarUrl';import type { ApiMessageSenderName } from './apiMessageSenderName';+import type { ApiMessageSenderTriggeredBy } from './apiMessageSenderTriggeredBy';import type { ApiMessageSenderType } from './apiMessageSenderType';/**@@ -18,6 +19,8 @@ export interface ApiMessageSender {id: string;/** Display name for bot senders. */name?: ApiMessageSenderName;+ /** For an agent (bot) message, the id of the user who triggered it. */+ triggered_by?: ApiMessageSenderTriggeredBy;/** Sender type. */type: ApiMessageSenderType;}diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/apiMessageSenderTriggeredBy.ts b/js/app/packages/service-clients/service-storage/generated/schemas/apiMessageSenderTriggeredBy.tsnew file mode 100644index 0000000000..0a02695b02--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/apiMessageSenderTriggeredBy.ts@@ -0,0 +1,11 @@+/**+ * Generated by orval v7.21.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * For an agent (bot) message, the id of the user who triggered it.+ */+export type ApiMessageSenderTriggeredBy = string | null;diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts b/js/app/packages/service-clients/service-storage/generated/schemas/index.tsindex 051d7e70a2..59593d6854 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts@@ -89,6 +89,7 @@ export * from './apiMessageAttachmentWidth';export * from './apiMessageSender';export * from './apiMessageSenderAvatarUrl';export * from './apiMessageSenderName';+export * from './apiMessageSenderTriggeredBy';export * from './apiMessageSenderType';export * from './apiParticipantRole';export * from './apiPropertyEntityType';diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.tsindex d8842c4af6..c8f9f5e1e2 100644--- a/js/app/packages/service-clients/service-storage/generated/zod.ts+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts@@ -1720,6 +1720,12 @@ export const getChannelResponse = zod.string().nullish().describe('Display name for bot senders.'),+ triggered_by: zod+ .string()+ .nullish()+ .describe(+ 'For an agent (bot) message, the id of the user who triggered it.'+ ),type: zod.enum(['user', 'bot']).describe('Public sender type.'),}).describe('Public sender identity for channel messages.'),@@ -1798,6 +1804,12 @@ export const getChannelResponse = zod.string().nullish().describe('Display name for bot senders.'),+ triggered_by: zod+ .string()+ .nullish()+ .describe(+ 'For an agent (bot) message, the id of the user who triggered it.'+ ),type: zod.enum(['user', 'bot']).describe('Public sender type.'),@@ -2163,6 +2175,12 @@ export const getChannelMessagesResponse = zod.string().nullish().describe('Display name for bot senders.'),+ triggered_by: zod+ .string()+ .nullish()+ .describe(+ 'For an agent (bot) message, the id of the user who triggered it.'+ ),type: zod.enum(['user', 'bot']).describe('Public sender type.'),}).describe('Public sender identity for channel messages.'),@@ -2241,6 +2259,12 @@ export const getChannelMessagesResponse = zod.string().nullish().describe('Display name for bot senders.'),+ triggered_by: zod+ .string()+ .nullish()+ .describe(+ 'For an agent (bot) message, the id of the user who triggered it.'+ ),type: zod.enum(['user', 'bot']).describe('Public sender type.'),@@ -2423,6 +2447,12 @@ export const postChannelMessagesResponse = zod.string().nullish().describe('Display name for bot senders.'),+ triggered_by: zod+ .string()+ .nullish()+ .describe(+ 'For an agent (bot) message, the id of the user who triggered it.'+ ),type: zod.enum(['user', 'bot']).describe('Public sender type.'),}).describe('Public sender identity for channel messages.'),@@ -2501,6 +2531,12 @@ export const postChannelMessagesResponse = zod.string().nullish().describe('Display name for bot senders.'),+ triggered_by: zod+ .string()+ .nullish()+ .describe(+ 'For an agent (bot) message, the id of the user who triggered it.'+ ),type: zod.enum(['user', 'bot']).describe('Public sender type.'),@@ -2589,6 +2625,12 @@ export const getMessageWithContextResponse = zod.string().nullish().describe('Display name for bot senders.'),+ triggered_by: zod+ .string()+ .nullish()+ .describe(+ 'For an agent (bot) message, the id of the user who triggered it.'+ ),type: zod.enum(['user', 'bot']).describe('Public sender type.'),}).describe('Public sender identity for channel messages.'),@@ -2666,6 +2708,12 @@ export const getThreadRepliesResponseItem = zod.string().describe('Sender id without the storage namespace prefix.'),name: zod.string().nullish().describe('Display name for bot senders.'),+ triggered_by: zod+ .string()+ .nullish()+ .describe(+ 'For an agent (bot) message, the id of the user who triggered it.'+ ),type: zod.enum(['user', 'bot']).describe('Public sender type.'),}).describe('Public sender identity for channel messages.'),diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.jsonindex 89c92c7566..9dccef8f90 100644--- a/js/app/packages/service-clients/service-storage/openapi.json+++ b/js/app/packages/service-clients/service-storage/openapi.json@@ -10210,6 +10210,10 @@"type": ["string", "null"],"description": "Display name for bot senders."},+ "triggered_by": {+ "type": ["string", "null"],+ "description": "For an agent (bot) message, the id of the user who triggered it."+ },"type": {"$ref": "#/components/schemas/ApiMessageSenderType","description": "Sender type."diff --git a/rust/cloud-storage/.sqlx/query-109fd3ea2a92055d4f0d2e27727aee16a03bc33c37c4cdf2a1a80b5f2d8e5f00.json b/rust/cloud-storage/.sqlx/query-109fd3ea2a92055d4f0d2e27727aee16a03bc33c37c4cdf2a1a80b5f2d8e5f00.jsonnew file mode 100644index 0000000000..ac5596a2bd--- /dev/null+++ b/rust/cloud-storage/.sqlx/query-109fd3ea2a92055d4f0d2e27727aee16a03bc33c37c4cdf2a1a80b5f2d8e5f00.json@@ -0,0 +1,77 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT\n id AS \"id!\", thread_id AS \"thread_id!\", sender_id AS \"sender_id!\",\n triggered_by_user_id,\n content AS \"content!\", created_at AS \"created_at!\", updated_at AS \"updated_at!\",\n edited_at::timestamptz AS \"edited_at?\",\n reply_count AS \"reply_count!\", latest_reply_at AS \"latest_reply_at?\"\n FROM (\n SELECT\n r.id,\n r.thread_id,\n r.sender_id,\n r.triggered_by_user_id,\n r.content,\n r.created_at,\n r.updated_at,\n r.edited_at,\n COUNT(*) OVER (PARTITION BY r.thread_id) AS reply_count,\n MAX(r.created_at) OVER (PARTITION BY r.thread_id)::timestamptz AS latest_reply_at,\n ROW_NUMBER() OVER (\n PARTITION BY r.thread_id\n ORDER BY r.created_at ASC, r.id ASC\n ) AS rn\n FROM comms_messages r\n WHERE r.thread_id = ANY($1) AND r.deleted_at IS NULL\n ) sub\n WHERE rn <= $2\n ORDER BY thread_id, created_at ASC, id ASC\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id!",+ "type_info": "Uuid"+ },+ {+ "ordinal": 1,+ "name": "thread_id!",+ "type_info": "Uuid"+ },+ {+ "ordinal": 2,+ "name": "sender_id!",+ "type_info": "Text"+ },+ {+ "ordinal": 3,+ "name": "triggered_by_user_id",+ "type_info": "Text"+ },+ {+ "ordinal": 4,+ "name": "content!",+ "type_info": "Text"+ },+ {+ "ordinal": 5,+ "name": "created_at!",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 6,+ "name": "updated_at!",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 7,+ "name": "edited_at?",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 8,+ "name": "reply_count!",+ "type_info": "Int8"+ },+ {+ "ordinal": 9,+ "name": "latest_reply_at?",+ "type_info": "Timestamptz"+ }+ ],+ "parameters": {+ "Left": [+ "UuidArray",+ "Int8"+ ]+ },+ "nullable": [+ false,+ true,+ false,+ true,+ false,+ false,+ false,+ null,+ null,+ null+ ]+ },+ "hash": "109fd3ea2a92055d4f0d2e27727aee16a03bc33c37c4cdf2a1a80b5f2d8e5f00"+}diff --git a/rust/cloud-storage/.sqlx/query-046aa54b375545002a615891a34147d0d4f2c1e409bf1aa2263b84c88e2deda9.json b/rust/cloud-storage/.sqlx/query-11fa9f8cff223ea598b05cb8d734dd3a6200562694046817cbfadef2f6d67082.jsonsimilarity index 64%rename from rust/cloud-storage/.sqlx/query-046aa54b375545002a615891a34147d0d4f2c1e409bf1aa2263b84c88e2deda9.jsonrename to rust/cloud-storage/.sqlx/query-11fa9f8cff223ea598b05cb8d734dd3a6200562694046817cbfadef2f6d67082.jsonindex 33eecf6bc8..873e1e0706 100644--- a/rust/cloud-storage/.sqlx/query-046aa54b375545002a615891a34147d0d4f2c1e409bf1aa2263b84c88e2deda9.json+++ b/rust/cloud-storage/.sqlx/query-11fa9f8cff223ea598b05cb8d734dd3a6200562694046817cbfadef2f6d67082.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n INSERT INTO comms_messages (id, channel_id, sender_id, content, thread_id)\n VALUES ($1, $2, $3, $4, $5)\n RETURNING\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n ",+ "query": "\n INSERT INTO comms_messages (id, channel_id, sender_id, triggered_by_user_id, content, thread_id)\n VALUES ($1, $2, $3, $4, $5, $6)\n RETURNING\n id,\n channel_id,\n sender_id,\n triggered_by_user_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n ","describe": {"columns": [{@@ -20,31 +20,36 @@},{"ordinal": 3,- "name": "content",+ "name": "triggered_by_user_id","type_info": "Text"},{"ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 5,+ "ordinal": 6,"name": "updated_at","type_info": "Timestamptz"},{- "ordinal": 6,+ "ordinal": 7,"name": "thread_id","type_info": "Uuid"},{- "ordinal": 7,+ "ordinal": 8,"name": "edited_at?","type_info": "Timestamptz"},{- "ordinal": 8,+ "ordinal": 9,"name": "deleted_at?","type_info": "Timestamptz"}@@ -55,6 +60,7 @@"Uuid","Text","Text",+ "Text","Uuid"]},@@ -62,6 +68,7 @@false,false,false,+ true,false,false,false,@@ -70,5 +77,5 @@null]},- "hash": "046aa54b375545002a615891a34147d0d4f2c1e409bf1aa2263b84c88e2deda9"+ "hash": "11fa9f8cff223ea598b05cb8d734dd3a6200562694046817cbfadef2f6d67082"}diff --git a/rust/cloud-storage/.sqlx/query-1df49f5d478dcee269a9bded7fdcc34060d1c9dd6f964f3d6444b55830af299a.json b/rust/cloud-storage/.sqlx/query-17c240f6a460b4c63a40f0ab96f8d756f2001fb03c1e389dabb596d95359ed94.jsonsimilarity index 74%rename from rust/cloud-storage/.sqlx/query-1df49f5d478dcee269a9bded7fdcc34060d1c9dd6f964f3d6444b55830af299a.jsonrename to rust/cloud-storage/.sqlx/query-17c240f6a460b4c63a40f0ab96f8d756f2001fb03c1e389dabb596d95359ed94.jsonindex 9826ea2bab..3c25cdad6e 100644--- a/rust/cloud-storage/.sqlx/query-1df49f5d478dcee269a9bded7fdcc34060d1c9dd6f964f3d6444b55830af299a.json+++ b/rust/cloud-storage/.sqlx/query-17c240f6a460b4c63a40f0ab96f8d756f2001fb03c1e389dabb596d95359ed94.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n UPDATE comms_messages\n SET content = $1, updated_at = NOW(), edited_at = NOW()\n WHERE id = $2 AND channel_id = $3\n RETURNING\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n ",+ "query": "\n UPDATE comms_messages\n SET content = $1, updated_at = NOW(), edited_at = NOW()\n WHERE id = $2 AND channel_id = $3\n RETURNING\n id,\n channel_id,\n sender_id,\n triggered_by_user_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n ","describe": {"columns": [{@@ -20,31 +20,36 @@},{"ordinal": 3,- "name": "content",+ "name": "triggered_by_user_id","type_info": "Text"},{"ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 5,+ "ordinal": 6,"name": "updated_at","type_info": "Timestamptz"},{- "ordinal": 6,+ "ordinal": 7,"name": "thread_id","type_info": "Uuid"},{- "ordinal": 7,+ "ordinal": 8,"name": "edited_at?","type_info": "Timestamptz"},{- "ordinal": 8,+ "ordinal": 9,"name": "deleted_at?","type_info": "Timestamptz"}@@ -60,6 +65,7 @@false,false,false,+ true,false,false,false,@@ -68,5 +74,5 @@null]},- "hash": "1df49f5d478dcee269a9bded7fdcc34060d1c9dd6f964f3d6444b55830af299a"+ "hash": "17c240f6a460b4c63a40f0ab96f8d756f2001fb03c1e389dabb596d95359ed94"}diff --git a/rust/cloud-storage/.sqlx/query-da0e4cfc27ca84e3cad6ed3d7b58d20ea15ba8756bc54a8d518ea82a39a27ec4.json b/rust/cloud-storage/.sqlx/query-246d88f16e6bac8064be41148528e0545be33e3c43a3dc5193ab12220f8d8a7c.jsonsimilarity index 66%rename from rust/cloud-storage/.sqlx/query-da0e4cfc27ca84e3cad6ed3d7b58d20ea15ba8756bc54a8d518ea82a39a27ec4.jsonrename to rust/cloud-storage/.sqlx/query-246d88f16e6bac8064be41148528e0545be33e3c43a3dc5193ab12220f8d8a7c.jsonindex 12f733e69c..5d095581d7 100644--- a/rust/cloud-storage/.sqlx/query-da0e4cfc27ca84e3cad6ed3d7b58d20ea15ba8756bc54a8d518ea82a39a27ec4.json+++ b/rust/cloud-storage/.sqlx/query-246d88f16e6bac8064be41148528e0545be33e3c43a3dc5193ab12220f8d8a7c.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n id,\n thread_id AS \"thread_id!\",\n sender_id,\n content,\n created_at,\n updated_at,\n edited_at::timestamptz AS \"edited_at?\"\n FROM comms_messages\n WHERE thread_id = $1\n AND deleted_at IS NULL\n ORDER BY created_at ASC, id ASC\n ",+ "query": "\n SELECT\n id,\n thread_id AS \"thread_id!\",\n sender_id,\n triggered_by_user_id,\n content,\n created_at,\n updated_at,\n edited_at::timestamptz AS \"edited_at?\"\n FROM comms_messages\n WHERE thread_id = $1\n AND deleted_at IS NULL\n ORDER BY created_at ASC, id ASC\n ","describe": {"columns": [{@@ -20,21 +20,26 @@},{"ordinal": 3,- "name": "content",+ "name": "triggered_by_user_id","type_info": "Text"},{"ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 5,+ "ordinal": 6,"name": "updated_at","type_info": "Timestamptz"},{- "ordinal": 6,+ "ordinal": 7,"name": "edited_at?","type_info": "Timestamptz"}@@ -48,11 +53,12 @@false,true,false,+ true,false,false,false,null]},- "hash": "da0e4cfc27ca84e3cad6ed3d7b58d20ea15ba8756bc54a8d518ea82a39a27ec4"+ "hash": "246d88f16e6bac8064be41148528e0545be33e3c43a3dc5193ab12220f8d8a7c"}diff --git a/rust/cloud-storage/.sqlx/query-2b2674801d90fb7b89f286300e8a03ec10c34ab1f8a6ecc6a9ecac5b964669a2.json b/rust/cloud-storage/.sqlx/query-256ccfc280aaca7d1eff2bd993b29d29e94abe7ec9ad2574d53e138413e049cd.jsonsimilarity index 77%rename from rust/cloud-storage/.sqlx/query-2b2674801d90fb7b89f286300e8a03ec10c34ab1f8a6ecc6a9ecac5b964669a2.jsonrename to rust/cloud-storage/.sqlx/query-256ccfc280aaca7d1eff2bd993b29d29e94abe7ec9ad2574d53e138413e049cd.jsonindex be3b1e901c..17701131fd 100644--- a/rust/cloud-storage/.sqlx/query-2b2674801d90fb7b89f286300e8a03ec10c34ab1f8a6ecc6a9ecac5b964669a2.json+++ b/rust/cloud-storage/.sqlx/query-256ccfc280aaca7d1eff2bd993b29d29e94abe7ec9ad2574d53e138413e049cd.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n UPDATE comms_messages\n SET\n updated_at = NOW(),\n edited_at = NOW(),\n deleted_at = CASE\n WHEN $2 = false AND (content IS NULL OR content ~ '^[\\s]*$') THEN NOW()\n ELSE deleted_at\n END\n WHERE id = $1\n RETURNING\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n ",+ "query": "\n UPDATE comms_messages\n SET\n updated_at = NOW(),\n edited_at = NOW(),\n deleted_at = CASE\n WHEN $2 = false AND (content IS NULL OR content ~ '^[\\s]*$') THEN NOW()\n ELSE deleted_at\n END\n WHERE id = $1\n RETURNING\n id,\n channel_id,\n sender_id,\n triggered_by_user_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n ","describe": {"columns": [{@@ -20,31 +20,36 @@},{"ordinal": 3,- "name": "content",+ "name": "triggered_by_user_id","type_info": "Text"},{"ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 5,+ "ordinal": 6,"name": "updated_at","type_info": "Timestamptz"},{- "ordinal": 6,+ "ordinal": 7,"name": "thread_id","type_info": "Uuid"},{- "ordinal": 7,+ "ordinal": 8,"name": "edited_at?","type_info": "Timestamptz"},{- "ordinal": 8,+ "ordinal": 9,"name": "deleted_at?","type_info": "Timestamptz"}@@ -59,6 +64,7 @@false,false,false,+ true,false,false,false,@@ -67,5 +73,5 @@null]},- "hash": "2b2674801d90fb7b89f286300e8a03ec10c34ab1f8a6ecc6a9ecac5b964669a2"+ "hash": "256ccfc280aaca7d1eff2bd993b29d29e94abe7ec9ad2574d53e138413e049cd"}diff --git a/rust/cloud-storage/.sqlx/query-f9dd839c0eeb6b25a432136def701390348a6d4e33feefb4c3d33974e15fcf83.json b/rust/cloud-storage/.sqlx/query-6220297009a6be311ae935bd69ad9a2235af5d38bf380330fa1b2d40777a3b53.jsonsimilarity index 58%rename from rust/cloud-storage/.sqlx/query-f9dd839c0eeb6b25a432136def701390348a6d4e33feefb4c3d33974e15fcf83.jsonrename to rust/cloud-storage/.sqlx/query-6220297009a6be311ae935bd69ad9a2235af5d38bf380330fa1b2d40777a3b53.jsonindex ac492d99f7..1626fcf87d 100644--- a/rust/cloud-storage/.sqlx/query-f9dd839c0eeb6b25a432136def701390348a6d4e33feefb4c3d33974e15fcf83.json+++ b/rust/cloud-storage/.sqlx/query-6220297009a6be311ae935bd69ad9a2235af5d38bf380330fa1b2d40777a3b53.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n m.id,\n m.channel_id,\n m.sender_id,\n m.content,\n m.created_at,\n m.updated_at,\n m.edited_at::timestamptz AS \"edited_at?\",\n m.deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages m\n WHERE m.channel_id = $1\n AND m.thread_id IS NULL\n AND (m.deleted_at IS NULL OR EXISTS (\n SELECT 1 FROM comms_messages r\n WHERE r.thread_id = m.id AND r.deleted_at IS NULL\n ))\n AND (m.created_at, m.id) < ($2, $3)\n ORDER BY m.created_at DESC, m.id DESC\n LIMIT $4\n ",+ "query": "\n SELECT\n m.id,\n m.channel_id,\n m.sender_id,\n m.triggered_by_user_id,\n m.content,\n m.created_at,\n m.updated_at,\n m.edited_at::timestamptz AS \"edited_at?\",\n m.deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages m\n WHERE m.channel_id = $1\n AND m.thread_id IS NULL\n AND (m.deleted_at IS NULL OR EXISTS (\n SELECT 1 FROM comms_messages r\n WHERE r.thread_id = m.id AND r.deleted_at IS NULL\n ))\n AND (m.created_at, m.id) > ($2, $3)\n ORDER BY m.created_at ASC, m.id ASC\n LIMIT $4\n ","describe": {"columns": [{@@ -20,26 +20,31 @@},{"ordinal": 3,- "name": "content",+ "name": "triggered_by_user_id","type_info": "Text"},{"ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 5,+ "ordinal": 6,"name": "updated_at","type_info": "Timestamptz"},{- "ordinal": 6,+ "ordinal": 7,"name": "edited_at?","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "deleted_at?","type_info": "Timestamptz"}@@ -56,6 +61,7 @@false,false,false,+ true,false,false,false,@@ -63,5 +69,5 @@null]},- "hash": "f9dd839c0eeb6b25a432136def701390348a6d4e33feefb4c3d33974e15fcf83"+ "hash": "6220297009a6be311ae935bd69ad9a2235af5d38bf380330fa1b2d40777a3b53"}diff --git a/rust/cloud-storage/.sqlx/query-6656045ae486ab93f763edc9734b18f0867a279705c7f5a91775754f3cfbe83c.json b/rust/cloud-storage/.sqlx/query-6656045ae486ab93f763edc9734b18f0867a279705c7f5a91775754f3cfbe83c.jsondeleted file mode 100644index 1537df5b97..0000000000--- a/rust/cloud-storage/.sqlx/query-6656045ae486ab93f763edc9734b18f0867a279705c7f5a91775754f3cfbe83c.json+++ /dev/null@@ -1,71 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT\n id AS \"id!\", thread_id AS \"thread_id!\", sender_id AS \"sender_id!\",\n content AS \"content!\", created_at AS \"created_at!\", updated_at AS \"updated_at!\",\n edited_at::timestamptz AS \"edited_at?\",\n reply_count AS \"reply_count!\", latest_reply_at AS \"latest_reply_at?\"\n FROM (\n SELECT\n r.id,\n r.thread_id,\n r.sender_id,\n r.content,\n r.created_at,\n r.updated_at,\n r.edited_at,\n COUNT(*) OVER (PARTITION BY r.thread_id) AS reply_count,\n MAX(r.created_at) OVER (PARTITION BY r.thread_id)::timestamptz AS latest_reply_at,\n ROW_NUMBER() OVER (\n PARTITION BY r.thread_id\n ORDER BY r.created_at ASC, r.id ASC\n ) AS rn\n FROM comms_messages r\n WHERE r.thread_id = ANY($1) AND r.deleted_at IS NULL\n ) sub\n WHERE rn <= $2\n ORDER BY thread_id, created_at ASC, id ASC\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "id!",- "type_info": "Uuid"- },- {- "ordinal": 1,- "name": "thread_id!",- "type_info": "Uuid"- },- {- "ordinal": 2,- "name": "sender_id!",- "type_info": "Text"- },- {- "ordinal": 3,- "name": "content!",- "type_info": "Text"- },- {- "ordinal": 4,- "name": "created_at!",- "type_info": "Timestamptz"- },- {- "ordinal": 5,- "name": "updated_at!",- "type_info": "Timestamptz"- },- {- "ordinal": 6,- "name": "edited_at?",- "type_info": "Timestamptz"- },- {- "ordinal": 7,- "name": "reply_count!",- "type_info": "Int8"- },- {- "ordinal": 8,- "name": "latest_reply_at?",- "type_info": "Timestamptz"- }- ],- "parameters": {- "Left": [- "UuidArray",- "Int8"- ]- },- "nullable": [- false,- true,- false,- false,- false,- false,- null,- null,- null- ]- },- "hash": "6656045ae486ab93f763edc9734b18f0867a279705c7f5a91775754f3cfbe83c"-}diff --git a/rust/cloud-storage/.sqlx/query-f0c307220a9a497860462656f53da3e5786501c7b07a41983acb8459df610b8b.json b/rust/cloud-storage/.sqlx/query-725e8efb816dd4f03c34db74c141dc0929de9df06ec14e4c7eb93409a0bd0de8.jsonsimilarity index 67%rename from rust/cloud-storage/.sqlx/query-f0c307220a9a497860462656f53da3e5786501c7b07a41983acb8459df610b8b.jsonrename to rust/cloud-storage/.sqlx/query-725e8efb816dd4f03c34db74c141dc0929de9df06ec14e4c7eb93409a0bd0de8.jsonindex 87007e2972..ec2418ff4f 100644--- a/rust/cloud-storage/.sqlx/query-f0c307220a9a497860462656f53da3e5786501c7b07a41983acb8459df610b8b.json+++ b/rust/cloud-storage/.sqlx/query-725e8efb816dd4f03c34db74c141dc0929de9df06ec14e4c7eb93409a0bd0de8.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n id,\n channel_id,\n thread_id,\n sender_id,\n content,\n created_at,\n updated_at,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages\n WHERE channel_id = $1\n AND (created_at, id) < ($2, $3)\n ORDER BY created_at DESC, id DESC\n LIMIT $4\n ",+ "query": "\n SELECT\n id,\n channel_id,\n thread_id,\n sender_id,\n triggered_by_user_id,\n content,\n created_at,\n updated_at,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages\n WHERE channel_id = $1\n AND (created_at, id) < ($2, $3)\n ORDER BY created_at DESC, id DESC\n LIMIT $4\n ","describe": {"columns": [{@@ -25,26 +25,31 @@},{"ordinal": 4,- "name": "content",+ "name": "triggered_by_user_id","type_info": "Text"},{"ordinal": 5,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 6,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 6,+ "ordinal": 7,"name": "updated_at","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "edited_at?","type_info": "Timestamptz"},{- "ordinal": 8,+ "ordinal": 9,"name": "deleted_at?","type_info": "Timestamptz"}@@ -62,6 +67,7 @@false,true,false,+ true,false,false,false,@@ -69,5 +75,5 @@null]},- "hash": "f0c307220a9a497860462656f53da3e5786501c7b07a41983acb8459df610b8b"+ "hash": "725e8efb816dd4f03c34db74c141dc0929de9df06ec14e4c7eb93409a0bd0de8"}diff --git a/rust/cloud-storage/.sqlx/query-7a04573d80958eb5b841e520136db80173119aacbab82f50a4a1ae468aaada65.json b/rust/cloud-storage/.sqlx/query-811160740482a042237f6ffc433290e0e89ba9521fbba575634fd92a39433271.jsonsimilarity index 74%rename from rust/cloud-storage/.sqlx/query-7a04573d80958eb5b841e520136db80173119aacbab82f50a4a1ae468aaada65.jsonrename to rust/cloud-storage/.sqlx/query-811160740482a042237f6ffc433290e0e89ba9521fbba575634fd92a39433271.jsonindex d692f301d5..90d232e808 100644--- a/rust/cloud-storage/.sqlx/query-7a04573d80958eb5b841e520136db80173119aacbab82f50a4a1ae468aaada65.json+++ b/rust/cloud-storage/.sqlx/query-811160740482a042237f6ffc433290e0e89ba9521fbba575634fd92a39433271.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n UPDATE comms_messages\n SET content = '', updated_at = NOW(), deleted_at = NOW()\n WHERE id = $1 AND channel_id = $2\n RETURNING\n id,\n channel_id,\n sender_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n ",+ "query": "\n UPDATE comms_messages\n SET content = '', updated_at = NOW(), deleted_at = NOW()\n WHERE id = $1 AND channel_id = $2\n RETURNING\n id,\n channel_id,\n sender_id,\n triggered_by_user_id,\n content,\n created_at,\n updated_at,\n thread_id,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n ","describe": {"columns": [{@@ -20,31 +20,36 @@},{"ordinal": 3,- "name": "content",+ "name": "triggered_by_user_id","type_info": "Text"},{"ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 5,+ "ordinal": 6,"name": "updated_at","type_info": "Timestamptz"},{- "ordinal": 6,+ "ordinal": 7,"name": "thread_id","type_info": "Uuid"},{- "ordinal": 7,+ "ordinal": 8,"name": "edited_at?","type_info": "Timestamptz"},{- "ordinal": 8,+ "ordinal": 9,"name": "deleted_at?","type_info": "Timestamptz"}@@ -59,6 +64,7 @@false,false,false,+ true,false,false,false,@@ -67,5 +73,5 @@null]},- "hash": "7a04573d80958eb5b841e520136db80173119aacbab82f50a4a1ae468aaada65"+ "hash": "811160740482a042237f6ffc433290e0e89ba9521fbba575634fd92a39433271"}diff --git a/rust/cloud-storage/.sqlx/query-96f2482e829992f905137782aa37d8559171dacf2675417c2318cd4dd468ce94.json b/rust/cloud-storage/.sqlx/query-96f2482e829992f905137782aa37d8559171dacf2675417c2318cd4dd468ce94.jsonnew file mode 100644index 0000000000..9a07b1debb--- /dev/null+++ b/rust/cloud-storage/.sqlx/query-96f2482e829992f905137782aa37d8559171dacf2675417c2318cd4dd468ce94.json@@ -0,0 +1,82 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT\n m.id,\n m.channel_id,\n m.sender_id,\n m.triggered_by_user_id,\n m.content,\n m.created_at,\n m.updated_at,\n m.edited_at::timestamptz AS \"edited_at?\",\n m.deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages m\n WHERE m.channel_id = $1\n AND m.thread_id IS NULL\n AND (m.deleted_at IS NULL OR EXISTS (\n SELECT 1 FROM comms_messages r\n WHERE r.thread_id = m.id AND r.deleted_at IS NULL\n ))\n AND ($2::timestamptz IS NOT NULL AND (m.created_at, m.id) > ($2, $3))\n AND ($5::uuid[] IS NULL OR m.id = ANY($5))\n AND ($6::timestamptz IS NULL OR m.created_at >= $6)\n AND ($7::timestamptz IS NULL OR m.created_at < $7)\n AND (\n ($8::timestamptz IS NULL AND $9::timestamptz IS NULL)\n OR (\n ($8::timestamptz IS NULL OR m.created_at >= $8)\n AND ($9::timestamptz IS NULL OR m.created_at < $9)\n )\n OR EXISTS (\n SELECT 1 FROM comms_messages r\n WHERE r.thread_id = m.id\n AND r.deleted_at IS NULL\n AND ($8::timestamptz IS NULL OR r.created_at >= $8)\n AND ($9::timestamptz IS NULL OR r.created_at < $9)\n )\n )\n AND ($10::bool = FALSE OR (\n ($11::bool IS NULL OR EXISTS (\n SELECT 1\n FROM notification n\n JOIN user_notification un ON un.notification_id = n.id\n JOIN comms_messages msg ON msg.id = (n.metadata->>'messageId')::uuid\n WHERE un.user_id = $13::text\n AND un.deleted_at IS NULL\n AND un.done = $11\n AND n.event_item_type = 'channel'\n AND n.event_item_id = $1::uuid::text\n AND n.metadata->>'messageId' IS NOT NULL\n AND msg.channel_id = $1\n AND msg.deleted_at IS NULL\n AND COALESCE(msg.thread_id, msg.id) = m.id\n ))\n AND ($12::bool IS NULL OR EXISTS (\n SELECT 1\n FROM notification n\n JOIN user_notification un ON un.notification_id = n.id\n JOIN comms_messages msg ON msg.id = (n.metadata->>'messageId')::uuid\n WHERE un.user_id = $13::text\n AND un.deleted_at IS NULL\n AND (un.seen_at IS NOT NULL) = $12\n AND n.event_item_type = 'channel'\n AND n.event_item_id = $1::uuid::text\n AND n.metadata->>'messageId' IS NOT NULL\n AND msg.channel_id = $1\n AND msg.deleted_at IS NULL\n AND COALESCE(msg.thread_id, msg.id) = m.id\n ))\n ))\n ORDER BY m.created_at ASC, m.id ASC\n LIMIT $4\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 1,+ "name": "channel_id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 2,+ "name": "sender_id",+ "type_info": "Text"+ },+ {+ "ordinal": 3,+ "name": "triggered_by_user_id",+ "type_info": "Text"+ },+ {+ "ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,+ "name": "created_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 6,+ "name": "updated_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 7,+ "name": "edited_at?",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 8,+ "name": "deleted_at?",+ "type_info": "Timestamptz"+ }+ ],+ "parameters": {+ "Left": [+ "Uuid",+ "Timestamptz",+ "Uuid",+ "Int8",+ "UuidArray",+ "Timestamptz",+ "Timestamptz",+ "Timestamptz",+ "Timestamptz",+ "Bool",+ "Bool",+ "Bool",+ "Text"+ ]+ },+ "nullable": [+ false,+ false,+ false,+ true,+ false,+ false,+ false,+ null,+ null+ ]+ },+ "hash": "96f2482e829992f905137782aa37d8559171dacf2675417c2318cd4dd468ce94"+}diff --git a/rust/cloud-storage/.sqlx/query-244c5d4b6165e48a376b1a33583bcc6cbe5e22bd559419180a6c2f2855ff607e.json b/rust/cloud-storage/.sqlx/query-b002a549f1a74fd65b2a24564ef8e35fa56a985e1f8eef8265139dd4a2777440.jsonsimilarity index 67%rename from rust/cloud-storage/.sqlx/query-244c5d4b6165e48a376b1a33583bcc6cbe5e22bd559419180a6c2f2855ff607e.jsonrename to rust/cloud-storage/.sqlx/query-b002a549f1a74fd65b2a24564ef8e35fa56a985e1f8eef8265139dd4a2777440.jsonindex 7303f3cfa9..58ebd52eaf 100644--- a/rust/cloud-storage/.sqlx/query-244c5d4b6165e48a376b1a33583bcc6cbe5e22bd559419180a6c2f2855ff607e.json+++ b/rust/cloud-storage/.sqlx/query-b002a549f1a74fd65b2a24564ef8e35fa56a985e1f8eef8265139dd4a2777440.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n id,\n channel_id,\n thread_id,\n sender_id,\n content,\n created_at,\n updated_at,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages\n WHERE channel_id = $1\n AND (created_at, id) > ($2, $3)\n ORDER BY created_at ASC, id ASC\n LIMIT $4\n ",+ "query": "\n SELECT\n id,\n channel_id,\n thread_id,\n sender_id,\n triggered_by_user_id,\n content,\n created_at,\n updated_at,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages\n WHERE channel_id = $1\n AND (created_at, id) > ($2, $3)\n ORDER BY created_at ASC, id ASC\n LIMIT $4\n ","describe": {"columns": [{@@ -25,26 +25,31 @@},{"ordinal": 4,- "name": "content",+ "name": "triggered_by_user_id","type_info": "Text"},{"ordinal": 5,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 6,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 6,+ "ordinal": 7,"name": "updated_at","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "edited_at?","type_info": "Timestamptz"},{- "ordinal": 8,+ "ordinal": 9,"name": "deleted_at?","type_info": "Timestamptz"}@@ -62,6 +67,7 @@false,true,false,+ true,false,false,false,@@ -69,5 +75,5 @@null]},- "hash": "244c5d4b6165e48a376b1a33583bcc6cbe5e22bd559419180a6c2f2855ff607e"+ "hash": "b002a549f1a74fd65b2a24564ef8e35fa56a985e1f8eef8265139dd4a2777440"}diff --git a/rust/cloud-storage/.sqlx/query-bdc2a74951d6efbce08d469970b29610352e02441283f12a67b0da0c44771522.json b/rust/cloud-storage/.sqlx/query-bdc2a74951d6efbce08d469970b29610352e02441283f12a67b0da0c44771522.jsondeleted file mode 100644index 5e8933ecc4..0000000000--- a/rust/cloud-storage/.sqlx/query-bdc2a74951d6efbce08d469970b29610352e02441283f12a67b0da0c44771522.json+++ /dev/null@@ -1,76 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT\n m.id,\n m.channel_id,\n m.sender_id,\n m.content,\n m.created_at,\n m.updated_at,\n m.edited_at::timestamptz AS \"edited_at?\",\n m.deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages m\n WHERE m.channel_id = $1\n AND m.thread_id IS NULL\n AND (m.deleted_at IS NULL OR EXISTS (\n SELECT 1 FROM comms_messages r\n WHERE r.thread_id = m.id AND r.deleted_at IS NULL\n ))\n AND ($2::timestamptz IS NOT NULL AND (m.created_at, m.id) > ($2, $3))\n AND ($5::uuid[] IS NULL OR m.id = ANY($5))\n AND ($6::timestamptz IS NULL OR m.created_at >= $6)\n AND ($7::timestamptz IS NULL OR m.created_at < $7)\n AND (\n ($8::timestamptz IS NULL AND $9::timestamptz IS NULL)\n OR (\n ($8::timestamptz IS NULL OR m.created_at >= $8)\n AND ($9::timestamptz IS NULL OR m.created_at < $9)\n )\n OR EXISTS (\n SELECT 1 FROM comms_messages r\n WHERE r.thread_id = m.id\n AND r.deleted_at IS NULL\n AND ($8::timestamptz IS NULL OR r.created_at >= $8)\n AND ($9::timestamptz IS NULL OR r.created_at < $9)\n )\n )\n AND ($10::bool = FALSE OR (\n ($11::bool IS NULL OR EXISTS (\n SELECT 1\n FROM notification n\n JOIN user_notification un ON un.notification_id = n.id\n JOIN comms_messages msg ON msg.id = (n.metadata->>'messageId')::uuid\n WHERE un.user_id = $13::text\n AND un.deleted_at IS NULL\n AND un.done = $11\n AND n.event_item_type = 'channel'\n AND n.event_item_id = $1::uuid::text\n AND n.metadata->>'messageId' IS NOT NULL\n AND msg.channel_id = $1\n AND msg.deleted_at IS NULL\n AND COALESCE(msg.thread_id, msg.id) = m.id\n ))\n AND ($12::bool IS NULL OR EXISTS (\n SELECT 1\n FROM notification n\n JOIN user_notification un ON un.notification_id = n.id\n JOIN comms_messages msg ON msg.id = (n.metadata->>'messageId')::uuid\n WHERE un.user_id = $13::text\n AND un.deleted_at IS NULL\n AND (un.seen_at IS NOT NULL) = $12\n AND n.event_item_type = 'channel'\n AND n.event_item_id = $1::uuid::text\n AND n.metadata->>'messageId' IS NOT NULL\n AND msg.channel_id = $1\n AND msg.deleted_at IS NULL\n AND COALESCE(msg.thread_id, msg.id) = m.id\n ))\n ))\n ORDER BY m.created_at ASC, m.id ASC\n LIMIT $4\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "id",- "type_info": "Uuid"- },- {- "ordinal": 1,- "name": "channel_id",- "type_info": "Uuid"- },- {- "ordinal": 2,- "name": "sender_id",- "type_info": "Text"- },- {- "ordinal": 3,- "name": "content",- "type_info": "Text"- },- {- "ordinal": 4,- "name": "created_at",- "type_info": "Timestamptz"- },- {- "ordinal": 5,- "name": "updated_at",- "type_info": "Timestamptz"- },- {- "ordinal": 6,- "name": "edited_at?",- "type_info": "Timestamptz"- },- {- "ordinal": 7,- "name": "deleted_at?",- "type_info": "Timestamptz"- }- ],- "parameters": {- "Left": [- "Uuid",- "Timestamptz",- "Uuid",- "Int8",- "UuidArray",- "Timestamptz",- "Timestamptz",- "Timestamptz",- "Timestamptz",- "Bool",- "Bool",- "Bool",- "Text"- ]- },- "nullable": [- false,- false,- false,- false,- false,- false,- null,- null- ]- },- "hash": "bdc2a74951d6efbce08d469970b29610352e02441283f12a67b0da0c44771522"-}diff --git a/rust/cloud-storage/.sqlx/query-c3a21ba551a400f7dbdd9f80f7f3a857d2ea88043f3557137fb2718e64661ce0.json b/rust/cloud-storage/.sqlx/query-c3a21ba551a400f7dbdd9f80f7f3a857d2ea88043f3557137fb2718e64661ce0.jsonnew file mode 100644index 0000000000..93b2477aa8--- /dev/null+++ b/rust/cloud-storage/.sqlx/query-c3a21ba551a400f7dbdd9f80f7f3a857d2ea88043f3557137fb2718e64661ce0.json@@ -0,0 +1,82 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT\n m.id,\n m.channel_id,\n m.sender_id,\n m.triggered_by_user_id,\n m.content,\n m.created_at,\n m.updated_at,\n m.edited_at::timestamptz AS \"edited_at?\",\n m.deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages m\n WHERE m.channel_id = $1\n AND m.thread_id IS NULL\n AND (m.deleted_at IS NULL OR EXISTS (\n SELECT 1 FROM comms_messages r\n WHERE r.thread_id = m.id AND r.deleted_at IS NULL\n ))\n AND ($2::timestamptz IS NULL OR (m.created_at, m.id) < ($2, $3))\n AND ($5::uuid[] IS NULL OR m.id = ANY($5))\n AND ($6::timestamptz IS NULL OR m.created_at >= $6)\n AND ($7::timestamptz IS NULL OR m.created_at < $7)\n AND (\n ($8::timestamptz IS NULL AND $9::timestamptz IS NULL)\n OR (\n ($8::timestamptz IS NULL OR m.created_at >= $8)\n AND ($9::timestamptz IS NULL OR m.created_at < $9)\n )\n OR EXISTS (\n SELECT 1 FROM comms_messages r\n WHERE r.thread_id = m.id\n AND r.deleted_at IS NULL\n AND ($8::timestamptz IS NULL OR r.created_at >= $8)\n AND ($9::timestamptz IS NULL OR r.created_at < $9)\n )\n )\n AND ($10::bool = FALSE OR (\n ($11::bool IS NULL OR EXISTS (\n SELECT 1\n FROM notification n\n JOIN user_notification un ON un.notification_id = n.id\n JOIN comms_messages msg ON msg.id = (n.metadata->>'messageId')::uuid\n WHERE un.user_id = $13::text\n AND un.deleted_at IS NULL\n AND un.done = $11\n AND n.event_item_type = 'channel'\n AND n.event_item_id = $1::uuid::text\n AND n.metadata->>'messageId' IS NOT NULL\n AND msg.channel_id = $1\n AND msg.deleted_at IS NULL\n AND COALESCE(msg.thread_id, msg.id) = m.id\n ))\n AND ($12::bool IS NULL OR EXISTS (\n SELECT 1\n FROM notification n\n JOIN user_notification un ON un.notification_id = n.id\n JOIN comms_messages msg ON msg.id = (n.metadata->>'messageId')::uuid\n WHERE un.user_id = $13::text\n AND un.deleted_at IS NULL\n AND (un.seen_at IS NOT NULL) = $12\n AND n.event_item_type = 'channel'\n AND n.event_item_id = $1::uuid::text\n AND n.metadata->>'messageId' IS NOT NULL\n AND msg.channel_id = $1\n AND msg.deleted_at IS NULL\n AND COALESCE(msg.thread_id, msg.id) = m.id\n ))\n ))\n ORDER BY m.created_at DESC, m.id DESC\n LIMIT $4\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 1,+ "name": "channel_id",+ "type_info": "Uuid"+ },+ {+ "ordinal": 2,+ "name": "sender_id",+ "type_info": "Text"+ },+ {+ "ordinal": 3,+ "name": "triggered_by_user_id",+ "type_info": "Text"+ },+ {+ "ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,+ "name": "created_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 6,+ "name": "updated_at",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 7,+ "name": "edited_at?",+ "type_info": "Timestamptz"+ },+ {+ "ordinal": 8,+ "name": "deleted_at?",+ "type_info": "Timestamptz"+ }+ ],+ "parameters": {+ "Left": [+ "Uuid",+ "Timestamptz",+ "Uuid",+ "Int8",+ "UuidArray",+ "Timestamptz",+ "Timestamptz",+ "Timestamptz",+ "Timestamptz",+ "Bool",+ "Bool",+ "Bool",+ "Text"+ ]+ },+ "nullable": [+ false,+ false,+ false,+ true,+ false,+ false,+ false,+ null,+ null+ ]+ },+ "hash": "c3a21ba551a400f7dbdd9f80f7f3a857d2ea88043f3557137fb2718e64661ce0"+}diff --git a/rust/cloud-storage/.sqlx/query-5dc0e1bcbf170bd9bbf24c739411500b574a43db370a9c995599ae8aaca20f23.json b/rust/cloud-storage/.sqlx/query-d82d977779927364228d9652cd1958df1fa31ba45ef06790f540139098e3d10f.jsonsimilarity index 70%rename from rust/cloud-storage/.sqlx/query-5dc0e1bcbf170bd9bbf24c739411500b574a43db370a9c995599ae8aaca20f23.jsonrename to rust/cloud-storage/.sqlx/query-d82d977779927364228d9652cd1958df1fa31ba45ef06790f540139098e3d10f.jsonindex 5301e22ea0..2a7f8ba1fa 100644--- a/rust/cloud-storage/.sqlx/query-5dc0e1bcbf170bd9bbf24c739411500b574a43db370a9c995599ae8aaca20f23.json+++ b/rust/cloud-storage/.sqlx/query-d82d977779927364228d9652cd1958df1fa31ba45ef06790f540139098e3d10f.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n id,\n channel_id,\n thread_id,\n sender_id,\n content,\n created_at,\n updated_at,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages\n WHERE id = $1 AND channel_id = $2\n ",+ "query": "\n SELECT\n id,\n channel_id,\n thread_id,\n sender_id,\n triggered_by_user_id,\n content,\n created_at,\n updated_at,\n edited_at::timestamptz AS \"edited_at?\",\n deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages\n WHERE id = $1 AND channel_id = $2\n ","describe": {"columns": [{@@ -25,26 +25,31 @@},{"ordinal": 4,- "name": "content",+ "name": "triggered_by_user_id","type_info": "Text"},{"ordinal": 5,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 6,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 6,+ "ordinal": 7,"name": "updated_at","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "edited_at?","type_info": "Timestamptz"},{- "ordinal": 8,+ "ordinal": 9,"name": "deleted_at?","type_info": "Timestamptz"}@@ -60,6 +65,7 @@false,true,false,+ true,false,false,false,@@ -67,5 +73,5 @@null]},- "hash": "5dc0e1bcbf170bd9bbf24c739411500b574a43db370a9c995599ae8aaca20f23"+ "hash": "d82d977779927364228d9652cd1958df1fa31ba45ef06790f540139098e3d10f"}diff --git a/rust/cloud-storage/.sqlx/query-d7a3be325f304ca9642f1ae4f18a3b22e871c61feff6dbc1fe793cedd2cf403c.json b/rust/cloud-storage/.sqlx/query-ec3636e62ff865a5c6808e8f87d65730837b043b9cb69ce7075c431cee32b58b.jsonsimilarity index 58%rename from rust/cloud-storage/.sqlx/query-d7a3be325f304ca9642f1ae4f18a3b22e871c61feff6dbc1fe793cedd2cf403c.jsonrename to rust/cloud-storage/.sqlx/query-ec3636e62ff865a5c6808e8f87d65730837b043b9cb69ce7075c431cee32b58b.jsonindex 59be5b6504..72ef23f4f8 100644--- a/rust/cloud-storage/.sqlx/query-d7a3be325f304ca9642f1ae4f18a3b22e871c61feff6dbc1fe793cedd2cf403c.json+++ b/rust/cloud-storage/.sqlx/query-ec3636e62ff865a5c6808e8f87d65730837b043b9cb69ce7075c431cee32b58b.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n m.id,\n m.channel_id,\n m.sender_id,\n m.content,\n m.created_at,\n m.updated_at,\n m.edited_at::timestamptz AS \"edited_at?\",\n m.deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages m\n WHERE m.channel_id = $1\n AND m.thread_id IS NULL\n AND (m.deleted_at IS NULL OR EXISTS (\n SELECT 1 FROM comms_messages r\n WHERE r.thread_id = m.id AND r.deleted_at IS NULL\n ))\n AND (m.created_at, m.id) > ($2, $3)\n ORDER BY m.created_at ASC, m.id ASC\n LIMIT $4\n ",+ "query": "\n SELECT\n m.id,\n m.channel_id,\n m.sender_id,\n m.triggered_by_user_id,\n m.content,\n m.created_at,\n m.updated_at,\n m.edited_at::timestamptz AS \"edited_at?\",\n m.deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages m\n WHERE m.channel_id = $1\n AND m.thread_id IS NULL\n AND (m.deleted_at IS NULL OR EXISTS (\n SELECT 1 FROM comms_messages r\n WHERE r.thread_id = m.id AND r.deleted_at IS NULL\n ))\n AND (m.created_at, m.id) < ($2, $3)\n ORDER BY m.created_at DESC, m.id DESC\n LIMIT $4\n ","describe": {"columns": [{@@ -20,26 +20,31 @@},{"ordinal": 3,- "name": "content",+ "name": "triggered_by_user_id","type_info": "Text"},{"ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 5,+ "ordinal": 6,"name": "updated_at","type_info": "Timestamptz"},{- "ordinal": 6,+ "ordinal": 7,"name": "edited_at?","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "deleted_at?","type_info": "Timestamptz"}@@ -56,6 +61,7 @@false,false,false,+ true,false,false,false,@@ -63,5 +69,5 @@null]},- "hash": "d7a3be325f304ca9642f1ae4f18a3b22e871c61feff6dbc1fe793cedd2cf403c"+ "hash": "ec3636e62ff865a5c6808e8f87d65730837b043b9cb69ce7075c431cee32b58b"}diff --git a/rust/cloud-storage/.sqlx/query-ec9e817e0985ec4f58c8c6bc5817016f366e31f1ac3a8cf8696ed61434472afb.json b/rust/cloud-storage/.sqlx/query-ec9e817e0985ec4f58c8c6bc5817016f366e31f1ac3a8cf8696ed61434472afb.jsondeleted file mode 100644index 579bd20b2e..0000000000--- a/rust/cloud-storage/.sqlx/query-ec9e817e0985ec4f58c8c6bc5817016f366e31f1ac3a8cf8696ed61434472afb.json+++ /dev/null@@ -1,76 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT\n m.id,\n m.channel_id,\n m.sender_id,\n m.content,\n m.created_at,\n m.updated_at,\n m.edited_at::timestamptz AS \"edited_at?\",\n m.deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages m\n WHERE m.channel_id = $1\n AND m.thread_id IS NULL\n AND (m.deleted_at IS NULL OR EXISTS (\n SELECT 1 FROM comms_messages r\n WHERE r.thread_id = m.id AND r.deleted_at IS NULL\n ))\n AND ($2::timestamptz IS NULL OR (m.created_at, m.id) < ($2, $3))\n AND ($5::uuid[] IS NULL OR m.id = ANY($5))\n AND ($6::timestamptz IS NULL OR m.created_at >= $6)\n AND ($7::timestamptz IS NULL OR m.created_at < $7)\n AND (\n ($8::timestamptz IS NULL AND $9::timestamptz IS NULL)\n OR (\n ($8::timestamptz IS NULL OR m.created_at >= $8)\n AND ($9::timestamptz IS NULL OR m.created_at < $9)\n )\n OR EXISTS (\n SELECT 1 FROM comms_messages r\n WHERE r.thread_id = m.id\n AND r.deleted_at IS NULL\n AND ($8::timestamptz IS NULL OR r.created_at >= $8)\n AND ($9::timestamptz IS NULL OR r.created_at < $9)\n )\n )\n AND ($10::bool = FALSE OR (\n ($11::bool IS NULL OR EXISTS (\n SELECT 1\n FROM notification n\n JOIN user_notification un ON un.notification_id = n.id\n JOIN comms_messages msg ON msg.id = (n.metadata->>'messageId')::uuid\n WHERE un.user_id = $13::text\n AND un.deleted_at IS NULL\n AND un.done = $11\n AND n.event_item_type = 'channel'\n AND n.event_item_id = $1::uuid::text\n AND n.metadata->>'messageId' IS NOT NULL\n AND msg.channel_id = $1\n AND msg.deleted_at IS NULL\n AND COALESCE(msg.thread_id, msg.id) = m.id\n ))\n AND ($12::bool IS NULL OR EXISTS (\n SELECT 1\n FROM notification n\n JOIN user_notification un ON un.notification_id = n.id\n JOIN comms_messages msg ON msg.id = (n.metadata->>'messageId')::uuid\n WHERE un.user_id = $13::text\n AND un.deleted_at IS NULL\n AND (un.seen_at IS NOT NULL) = $12\n AND n.event_item_type = 'channel'\n AND n.event_item_id = $1::uuid::text\n AND n.metadata->>'messageId' IS NOT NULL\n AND msg.channel_id = $1\n AND msg.deleted_at IS NULL\n AND COALESCE(msg.thread_id, msg.id) = m.id\n ))\n ))\n ORDER BY m.created_at DESC, m.id DESC\n LIMIT $4\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "id",- "type_info": "Uuid"- },- {- "ordinal": 1,- "name": "channel_id",- "type_info": "Uuid"- },- {- "ordinal": 2,- "name": "sender_id",- "type_info": "Text"- },- {- "ordinal": 3,- "name": "content",- "type_info": "Text"- },- {- "ordinal": 4,- "name": "created_at",- "type_info": "Timestamptz"- },- {- "ordinal": 5,- "name": "updated_at",- "type_info": "Timestamptz"- },- {- "ordinal": 6,- "name": "edited_at?",- "type_info": "Timestamptz"- },- {- "ordinal": 7,- "name": "deleted_at?",- "type_info": "Timestamptz"- }- ],- "parameters": {- "Left": [- "Uuid",- "Timestamptz",- "Uuid",- "Int8",- "UuidArray",- "Timestamptz",- "Timestamptz",- "Timestamptz",- "Timestamptz",- "Bool",- "Bool",- "Bool",- "Text"- ]- },- "nullable": [- false,- false,- false,- false,- false,- false,- null,- null- ]- },- "hash": "ec9e817e0985ec4f58c8c6bc5817016f366e31f1ac3a8cf8696ed61434472afb"-}diff --git a/rust/cloud-storage/.sqlx/query-ab3aa320a07e9885f1de7995533b75dfc995ac18e421ca940dd0828aa32b47a6.json b/rust/cloud-storage/.sqlx/query-fbee16f91442381c51b85d5e77042ba3787eec094e62746727249f3055ec2dbb.jsonsimilarity index 62%rename from rust/cloud-storage/.sqlx/query-ab3aa320a07e9885f1de7995533b75dfc995ac18e421ca940dd0828aa32b47a6.jsonrename to rust/cloud-storage/.sqlx/query-fbee16f91442381c51b85d5e77042ba3787eec094e62746727249f3055ec2dbb.jsonindex 026107a6ab..b1688e3f54 100644--- a/rust/cloud-storage/.sqlx/query-ab3aa320a07e9885f1de7995533b75dfc995ac18e421ca940dd0828aa32b47a6.json+++ b/rust/cloud-storage/.sqlx/query-fbee16f91442381c51b85d5e77042ba3787eec094e62746727249f3055ec2dbb.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT\n m.id,\n m.channel_id,\n m.sender_id,\n m.content,\n m.created_at,\n m.updated_at,\n m.edited_at::timestamptz AS \"edited_at?\",\n m.deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages m\n WHERE m.id = COALESCE(\n (SELECT thread_id FROM comms_messages WHERE id = $1 AND channel_id = $2),\n $1\n )\n AND m.channel_id = $2\n AND m.thread_id IS NULL\n ",+ "query": "\n SELECT\n m.id,\n m.channel_id,\n m.sender_id,\n m.triggered_by_user_id,\n m.content,\n m.created_at,\n m.updated_at,\n m.edited_at::timestamptz AS \"edited_at?\",\n m.deleted_at::timestamptz AS \"deleted_at?\"\n FROM comms_messages m\n WHERE m.id = COALESCE(\n (SELECT thread_id FROM comms_messages WHERE id = $1 AND channel_id = $2),\n $1\n )\n AND m.channel_id = $2\n AND m.thread_id IS NULL\n ","describe": {"columns": [{@@ -20,26 +20,31 @@},{"ordinal": 3,- "name": "content",+ "name": "triggered_by_user_id","type_info": "Text"},{"ordinal": 4,+ "name": "content",+ "type_info": "Text"+ },+ {+ "ordinal": 5,"name": "created_at","type_info": "Timestamptz"},{- "ordinal": 5,+ "ordinal": 6,"name": "updated_at","type_info": "Timestamptz"},{- "ordinal": 6,+ "ordinal": 7,"name": "edited_at?","type_info": "Timestamptz"},{- "ordinal": 7,+ "ordinal": 8,"name": "deleted_at?","type_info": "Timestamptz"}@@ -54,6 +59,7 @@false,false,false,+ true,false,false,false,@@ -61,5 +67,5 @@null]},- "hash": "ab3aa320a07e9885f1de7995533b75dfc995ac18e421ca940dd0828aa32b47a6"+ "hash": "fbee16f91442381c51b85d5e77042ba3787eec094e62746727249f3055ec2dbb"}diff --git a/rust/cloud-storage/ai_tools/src/lib.rs b/rust/cloud-storage/ai_tools/src/lib.rsindex 14635e469c..8c653f0c56 100644--- a/rust/cloud-storage/ai_tools/src/lib.rs+++ b/rust/cloud-storage/ai_tools/src/lib.rs@@ -42,15 +42,16 @@ pub use tool_context::{NoOpCallRtcClient, NoOpConnectionService, NoOpNotificationIngress, NoOpNotificationService,NoOpScheduleContext, NoOpSnsEndpointManager, NoOpTaskProperties, RequestContext,TaskPropertiesAdapter, ToolCallRecordQueryService, ToolCallService, ToolCallToolContext,- ToolChannelMessagesService, ToolChannelToolContext, ToolChatService, ToolChatToolContext,- ToolCommsService, ToolDocumentService, ToolDocumentToolContext, ToolEmailService,- ToolEmailToolContext, ToolEntityAccessManagementService, ToolEntityAccessService,- ToolForeignEntityService, ToolFrecencyService, ToolNotificationQueue, ToolNotificationService,+ ToolChannelEventDispatcher, ToolChannelMessagesService, ToolChannelToolContext,+ ToolChatService, ToolChatToolContext, ToolCommsService, ToolDocumentService,+ ToolDocumentToolContext, ToolEmailService, ToolEmailToolContext,+ ToolEntityAccessManagementService, ToolEntityAccessService, ToolForeignEntityService,+ ToolFrecencyService, ToolNotificationQueue, ToolNotificationService,ToolNotificationToolContext, ToolPropertiesService, ToolPropertiesToolContext,ToolServiceContext, ToolSoupService, ToolSystemPropertiesService, ToolTeamService,ToolTeamToolContext, ToolUserEmailService, build_channel_tool_context,- build_properties_service, build_properties_tool_context, build_task_properties_adapter,- build_team_tool_context,+ build_channel_tool_context_with_dispatcher, build_properties_service,+ build_properties_tool_context, build_task_properties_adapter, build_team_tool_context,};pub type AiToolSet = AsyncToolCollection<ToolServiceContext>;diff --git a/rust/cloud-storage/ai_tools/src/tool_context.rs b/rust/cloud-storage/ai_tools/src/tool_context.rsindex e30190fdbe..8f0f41ea23 100644--- a/rust/cloud-storage/ai_tools/src/tool_context.rs+++ b/rust/cloud-storage/ai_tools/src/tool_context.rs@@ -6,6 +6,8 @@ use call::domain::service::{CallRecordQueryServiceImpl, CallServiceImpl};use call::inbound::toolset::CallToolContext;use call::outbound::pg_call_repo::PgCallRepo;use call::outbound::s3_recording_storage::S3RecordingStorage;+use channels::domain::ports::ChannelEventDispatcher;+use channels::domain::service::{NoopChannelEventDispatcher, NoopChannelReferenceSharePermissions};use channels::domain::{list_service::ChannelListServiceImpl, service::ChannelServiceImpl};use channels::inbound::toolset::ChannelToolContext;use channels::outbound::pg_channels_repo::PgChannelsRepo;@@ -69,17 +71,42 @@ pub type ToolCommsService = ChannelListServiceImpl<frecency::outbound::postgres::FrecencyPgStorage,>;+/// A channel event dispatcher injected into the tool service. Defaults to a+/// no-op; hosts that own the realtime/notification clients (e.g. the+/// document-storage service running the Macro agent) inject a real+/// side-effect-wired dispatcher so agent-sent messages notify and broadcast.+pub type ToolChannelEventDispatcher = std::sync::Arc<dyn ChannelEventDispatcher>;+/// Type alias for the channel messages service implementation used by AI tools.-pub type ToolChannelMessagesService = ChannelServiceImpl<PgChannelsRepo>;+pub type ToolChannelMessagesService =+ ChannelServiceImpl<PgChannelsRepo, ToolChannelEventDispatcher>;/// Type alias for the channel AI tool context.pub type ToolChannelToolContext =ChannelToolContext<ToolChannelMessagesService, ToolEntityAccessService>;-/// Build the channel AI tool context from a Postgres pool.+/// Build the channel AI tool context from a Postgres pool, with no side+/// effects (no notifications/realtime) for hosts that lack those clients.pub fn build_channel_tool_context(pool: sqlx::PgPool) -> ToolChannelToolContext {+ build_channel_tool_context_with_dispatcher(+ pool,+ std::sync::Arc::new(NoopChannelEventDispatcher),+ )+}++/// Build the channel AI tool context wired to `dispatcher`, so messages sent by+/// agent tools fire the host's channel side effects (notifications, realtime,+/// search indexing).+pub fn build_channel_tool_context_with_dispatcher(+ pool: sqlx::PgPool,+ dispatcher: ToolChannelEventDispatcher,+) -> ToolChannelToolContext {ChannelToolContext::new(- ChannelServiceImpl::new(PgChannelsRepo::new(pool.clone())),+ ChannelServiceImpl::with_dependencies(+ PgChannelsRepo::new(pool.clone()),+ dispatcher,+ NoopChannelReferenceSharePermissions,+ ),entity_access::domain::service::EntityAccessServiceImpl::new(entity_access::outbound::PgAccessRepository::new(pool),),diff --git a/rust/cloud-storage/bots/src/inbound/channel_webhook_router.rs b/rust/cloud-storage/bots/src/inbound/channel_webhook_router.rsindex 738eda4307..14e560f01e 100644--- a/rust/cloud-storage/bots/src/inbound/channel_webhook_router.rs+++ b/rust/cloud-storage/bots/src/inbound/channel_webhook_router.rs@@ -252,6 +252,8 @@ whereattachments: Vec::new(),nonce: None,notification_policy: Default::default(),+ // External webhook bot posting on its own; no triggering user.+ triggered_by: None,},).await?;diff --git a/rust/cloud-storage/channel_bots/src/domain/service.rs b/rust/cloud-storage/channel_bots/src/domain/service.rsindex 4ccd531dfb..aab864fb5b 100644--- a/rust/cloud-storage/channel_bots/src/domain/service.rs+++ b/rust/cloud-storage/channel_bots/src/domain/service.rs@@ -272,6 +272,7 @@ whereattachments: Vec::new(),nonce: None,notification_policy: PostMessageNotificationPolicy::Silent,+ triggered_by: Some(event.requesting_user.as_ref().to_string()),},).await?;diff --git a/rust/cloud-storage/channel_bots/src/domain/service/tests.rs b/rust/cloud-storage/channel_bots/src/domain/service/tests.rsindex 878a038433..d7cfb27197 100644--- a/rust/cloud-storage/channel_bots/src/domain/service/tests.rs+++ b/rust/cloud-storage/channel_bots/src/domain/service/tests.rs@@ -294,6 +294,7 @@ fn context_message(edited_at: None,deleted_at: None,bot_profile: None,+ triggered_by: None,}}@@ -307,6 +308,7 @@ fn thread_reply(id: Uuid, sender_id: &str, content: &str) -> ThreadReply {created_at: now,updated_at: now,edited_at: None,+ triggered_by: None,reactions: Vec::new(),attachments: Vec::new(),}@@ -332,6 +334,7 @@ fn mention_event(updated_at: Utc::now(),edited_at: None,deleted_at: None,+ triggered_by: None,},reply_thread_id: thread_id.unwrap_or(trigger_id),requesting_user: user_id(sender_email),diff --git a/rust/cloud-storage/channels/src/domain/models.rs b/rust/cloud-storage/channels/src/domain/models.rsindex 4d23bf0ca0..7c8a19f2e0 100644--- a/rust/cloud-storage/channels/src/domain/models.rs+++ b/rust/cloud-storage/channels/src/domain/models.rs@@ -225,6 +225,8 @@ pub struct ChannelMessage {pub channel_id: Uuid,/// User who sent the message.pub sender_id: String,+ /// For an agent (bot) message, the id of the user who triggered it.+ pub triggered_by: Option<String>,/// Bot profile when the sender is a bot.pub bot_profile: Option<BotSenderProfile>,/// Message body.@@ -301,6 +303,8 @@ pub struct ThreadReply {pub id: Uuid,/// User who sent the reply.pub sender_id: String,+ /// For an agent (bot) reply, the id of the user who triggered it.+ pub triggered_by: Option<String>,/// Bot profile when the sender is a bot.pub bot_profile: Option<BotSenderProfile>,/// Reply body.@@ -440,6 +444,8 @@ pub struct ChannelContextMessage {pub thread_id: Option<Uuid>,/// User who sent the message.pub sender_id: String,+ /// For an agent (bot) message, the id of the user who triggered it.+ pub triggered_by: Option<String>,/// Bot profile when the sender is a bot.pub bot_profile: Option<BotSenderProfile>,/// Message content.@@ -510,6 +516,8 @@ pub struct TopLevelMessageRow {pub channel_id: Uuid,/// Sender user id.pub sender_id: String,+ /// For an agent (bot) message, the id of the user who triggered it.+ pub triggered_by: Option<String>,/// Message content.pub content: String,/// Created timestamp.@@ -542,6 +550,8 @@ pub struct ThreadReplyRow {pub thread_id: Uuid,/// Sender user id.pub sender_id: String,+ /// For an agent (bot) reply, the id of the user who triggered it.+ pub triggered_by: Option<String>,/// Reply content.pub content: String,/// Created timestamp.@@ -954,6 +964,11 @@ pub struct PostMessageRequest {#[serde(skip)]#[cfg_attr(feature = "inbound", schema(ignore))]pub notification_policy: PostMessageNotificationPolicy,+ /// For an agent (bot) post, the id of the user who triggered it. `None`+ /// for ordinary human posts. Set internally, never from the wire.+ #[serde(skip)]+ #[cfg_attr(feature = "inbound", schema(ignore))]+ pub triggered_by: Option<String>,}/// Response returned after sending a message.@@ -1056,6 +1071,8 @@ pub struct MutatedMessage {pub thread_id: Option<Uuid>,/// Sender actor id.pub sender_id: Sender,+ /// For an agent (bot) message, the id of the user who triggered it.+ pub triggered_by: Option<String>,/// Message body.pub content: String,/// Created timestamp.diff --git a/rust/cloud-storage/channels/src/domain/ports.rs b/rust/cloud-storage/channels/src/domain/ports.rsindex 41432159c6..f3eb2b1ade 100644--- a/rust/cloud-storage/channels/src/domain/ports.rs+++ b/rust/cloud-storage/channels/src/domain/ports.rs@@ -304,10 +304,15 @@ pub trait ChannelRepo: Send + Sync + 'static {) -> impl Future<Output = Result<(), Self::Err>> + Send;/// Create a message.+ ///+ /// `triggered_by_user_id` is the id of the user who triggered an agent+ /// (bot) message, persisted to the nullable `triggered_by_user_id` column;+ /// `None` for ordinary human messages.fn create_message(&self,channel_id: Uuid,sender_id: String,+ triggered_by_user_id: Option<String>,content: String,thread_id: Option<Uuid>,) -> impl Future<Output = Result<MutatedMessage, Self::Err>> + Send;@@ -958,6 +963,15 @@ pub trait ChannelEventDispatcher: Send + Sync + 'static {fn dispatch(&self, event: ChannelEvent);}+/// Allows a boxed dispatcher to be used wherever a `ChannelEventDispatcher` is+/// expected, so callers (e.g. the AI toolset) can inject a side-effect-wired+/// dispatcher behind a uniform type.+impl ChannelEventDispatcher for std::sync::Arc<dyn ChannelEventDispatcher> {+ fn dispatch(&self, event: ChannelEvent) {+ (**self).dispatch(event);+ }+}+/// Dispatcher for contact graph updates.pub trait ChannelContactsDispatcher: Send + Sync + 'static {/// Error type for contacts operations.diff --git a/rust/cloud-storage/channels/src/domain/service.rs b/rust/cloud-storage/channels/src/domain/service.rsindex fcc3c7cf21..cb57502e71 100644--- a/rust/cloud-storage/channels/src/domain/service.rs+++ b/rust/cloud-storage/channels/src/domain/service.rs@@ -141,6 +141,7 @@ whereid: r.id,bot_profile: bot_profile_for(&bot_profiles, &r.sender_id),sender_id: r.sender_id.clone(),+ triggered_by: r.triggered_by.clone(),content: r.content.clone(),created_at: r.created_at,updated_at: r.updated_at,@@ -157,6 +158,7 @@ wherechannel_id: row.channel_id,bot_profile: bot_profile_for(&bot_profiles, &row.sender_id),sender_id: row.sender_id,+ triggered_by: row.triggered_by,content: row.content,created_at: row.created_at,updated_at: row.updated_at,@@ -202,6 +204,7 @@ whereid: row.id,bot_profile: bot_profile_for(&bot_profiles, &row.sender_id),sender_id: row.sender_id,+ triggered_by: row.triggered_by,content: row.content,created_at: row.created_at,updated_at: row.updated_at,@@ -513,6 +516,7 @@ where.create_message(channel_id,actor_storage_id.clone(),+ req.triggered_by.clone(),req.content.clone(),req.thread_id,)diff --git a/rust/cloud-storage/channels/src/domain/service/test.rs b/rust/cloud-storage/channels/src/domain/service/test.rsindex f803893d7d..8a25d3b609 100644--- a/rust/cloud-storage/channels/src/domain/service/test.rs+++ b/rust/cloud-storage/channels/src/domain/service/test.rs@@ -29,6 +29,7 @@ fn make_row(id: Uuid, minutes_ago: i64) -> TopLevelMessageRow {id,channel_id: Uuid::nil(),sender_id: "user_1".into(),+ triggered_by: None,content: format!("msg {minutes_ago}"),created_at: now - chrono::Duration::minutes(minutes_ago),updated_at: now - chrono::Duration::minutes(minutes_ago),@@ -98,6 +99,7 @@ async fn returns_messages_with_thread_info() {id: reply_id,thread_id: parent_id,sender_id: "user_2".into(),+ triggered_by: None,content: "reply".into(),created_at: Utc::now(),updated_at: Utc::now(),@@ -197,6 +199,7 @@ async fn attaches_bot_profiles_to_bot_authored_messages() {id: Uuid::new_v4(),thread_id: parent_id,sender_id: seeded_bot.to_storage_string(),+ triggered_by: None,content: "reply".into(),created_at: Utc::now(),updated_at: Utc::now(),@@ -296,6 +299,7 @@ impl FakeMutationRepo {channel_id,thread_id: None,sender_id: Sender::parse_storage_str(sender).unwrap(),+ triggered_by: None,content: "hello".to_string(),created_at: now,updated_at: now,@@ -540,12 +544,14 @@ impl ChannelRepo for FakeMutationRepo {&self,channel_id: Uuid,sender_id: String,+ triggered_by_user_id: Option<String>,content: String,thread_id: Option<Uuid>,) -> Result<MutatedMessage, Self::Err> {let mut state = self.state.lock().unwrap();state.message.channel_id = channel_id;state.message.sender_id = Sender::parse_storage_str(&sender_id).unwrap();+ state.message.triggered_by = triggered_by_user_id;state.message.content = content;state.message.thread_id = thread_id;Ok(state.message.clone())@@ -827,6 +833,7 @@ async fn post_message_emits_message_posted_event_and_updates_share_permissions()}],nonce: Some("nonce-1".to_string()),notification_policy: Default::default(),+ triggered_by: None,},).await@@ -897,6 +904,7 @@ async fn bot_post_message_persists_bot_sender_and_skips_user_only_effects() {}],nonce: None,notification_policy: Default::default(),+ triggered_by: None,},).await@@ -1449,6 +1457,7 @@ async fn thread_replies_resolve_and_hydrate() {id: Uuid::new_v4(),thread_id: parent.id,sender_id: "macro|[email protected]".into(),+ triggered_by: None,content: "reply 1".into(),created_at: Utc::now(),updated_at: Utc::now(),@@ -1458,6 +1467,7 @@ async fn thread_replies_resolve_and_hydrate() {id: Uuid::new_v4(),thread_id: parent.id,sender_id: "macro|[email protected]".into(),+ triggered_by: None,content: "reply 2".into(),created_at: Utc::now(),updated_at: Utc::now(),diff --git a/rust/cloud-storage/channels/src/domain/side_effects.rs b/rust/cloud-storage/channels/src/domain/side_effects.rsindex 2b0b8a73e3..de38341bd6 100644--- a/rust/cloud-storage/channels/src/domain/side_effects.rs+++ b/rust/cloud-storage/channels/src/domain/side_effects.rs@@ -71,7 +71,7 @@ pub enum ChannelRealtimeEffect {/// Recipients that should receive the update.recipients: Vec<MacroUserIdStr<'static>>,/// Persisted message payload.- message: MutatedMessage,+ message: Box<MutatedMessage>,/// Public bot profile when the sender is a bot.bot_profile: Option<BotSenderProfile>,/// Client mutation nonce echoed to listeners.@@ -455,7 +455,7 @@ wherelet bot_profile = self.bot_profile_for_message(&message).await;self.publish_realtime(ChannelRealtimeEffect::Message {recipients,- message: message.clone(),+ message: Box::new(message.clone()),bot_profile: bot_profile.clone(),nonce,})@@ -486,7 +486,7 @@ wherelet bot_profile = self.bot_profile_for_message(&message).await;self.publish_realtime(ChannelRealtimeEffect::Message {recipients,- message,+ message: Box::new(message),bot_profile,nonce,})@@ -585,7 +585,7 @@ wherelet bot_profile = self.bot_profile_for_message(&message).await;self.publish_realtime(ChannelRealtimeEffect::Message {recipients: recipients.clone(),- message: message.clone(),+ message: Box::new(message.clone()),bot_profile: bot_profile.clone(),nonce: nonce.clone(),})diff --git a/rust/cloud-storage/channels/src/domain/side_effects/test.rs b/rust/cloud-storage/channels/src/domain/side_effects/test.rsindex 416511352c..aeca9808b2 100644--- a/rust/cloud-storage/channels/src/domain/side_effects/test.rs+++ b/rust/cloud-storage/channels/src/domain/side_effects/test.rs@@ -170,6 +170,7 @@ async fn macro_ai_bot_profile_is_builtin_without_context_lookup() {channel_id: Uuid::new_v4(),thread_id: None,sender_id: Sender::Bot(bot_id::MACRO_AI_BOT_ID),+ triggered_by: None,content: "hello".to_string(),created_at: now,updated_at: now,@@ -206,6 +207,7 @@ async fn non_macro_bot_profile_uses_context_lookup() {channel_id: Uuid::new_v4(),thread_id: None,sender_id: Sender::Bot(BotId::from_uuid(Uuid::new_v4())),+ triggered_by: None,content: "hello".to_string(),created_at: now,updated_at: now,@@ -269,6 +271,7 @@ async fn message_posted_derives_realtime_search_and_notification_effects() {channel_id,thread_id: None,sender_id: Sender::User(sender.clone()),+ triggered_by: None,content: "hello".to_string(),created_at: now,updated_at: now,@@ -352,6 +355,7 @@ fn bot_message_posted_event(channel_id,thread_id,sender_id: Sender::Bot(BotId::from_uuid(Uuid::new_v4())),+ triggered_by: None,content: "hello".to_string(),created_at: now,updated_at: now,@@ -412,6 +416,7 @@ async fn silent_message_posted_skips_notifications_only() {channel_id,thread_id: None,sender_id: Sender::User(sender),+ triggered_by: None,content: "transient".to_string(),created_at: now,updated_at: now,@@ -466,6 +471,7 @@ async fn message_changed_with_posted_notification_context_sends_notification() {channel_id,thread_id: Some(thread_id),sender_id: Sender::Bot(bot_id::MACRO_AI_BOT_ID),+ triggered_by: None,content: "final answer".to_string(),created_at: now,updated_at: now,@@ -762,6 +768,7 @@ async fn user_message_with_bot_mention_enqueues_bot_trigger() {channel_id,thread_id: None,sender_id: Sender::User(sender),+ triggered_by: None,content: "@macro help".to_string(),created_at: now,updated_at: now,@@ -848,6 +855,7 @@ async fn document_mentions_notify_participants_except_sender() {channel_id,thread_id: None,sender_id: Sender::User(sender.clone()),+ triggered_by: None,content: "hello".to_string(),created_at: now,updated_at: now,diff --git a/rust/cloud-storage/channels/src/inbound/axum_router.rs b/rust/cloud-storage/channels/src/inbound/axum_router.rsindex 63a6d81d87..af929d883d 100644--- a/rust/cloud-storage/channels/src/inbound/axum_router.rs+++ b/rust/cloud-storage/channels/src/inbound/axum_router.rs@@ -1609,6 +1609,9 @@ pub struct ApiMessageSender {/// Avatar URL for bot senders.#[serde(skip_serializing_if = "Option::is_none")]avatar_url: Option<String>,+ /// For an agent (bot) message, the id of the user who triggered it.+ #[serde(skip_serializing_if = "Option::is_none")]+ triggered_by: Option<String>,}/// Public sender type.@@ -1629,30 +1632,39 @@ impl ApiMessageSender {id: bot_id.as_uuid().to_string(),name: None,avatar_url: None,+ triggered_by: None,},Ok(Sender::User(user_id)) => Self {sender_type: ApiMessageSenderType::User,id: user_id.to_string(),name: None,avatar_url: None,+ triggered_by: None,},Err(_) => Self {sender_type: ApiMessageSenderType::User,id: sender_id.to_string(),name: None,avatar_url: None,+ triggered_by: None,},}}- /// Build a sender identity, attaching the bot profile for bot senders.- fn from_message_sender(sender_id: &str, bot_profile: Option<BotSenderProfile>) -> Self {+ /// Build a sender identity, attaching the bot profile and the triggering+ /// user (for agent messages) to bot senders.+ fn from_message_sender(+ sender_id: &str,+ triggered_by: Option<String>,+ bot_profile: Option<BotSenderProfile>,+ ) -> Self {let mut sender = Self::from_storage_string(sender_id);- if matches!(sender.sender_type, ApiMessageSenderType::Bot)- && let Some(profile) = bot_profile- {- sender.name = Some(profile.name);- sender.avatar_url = profile.avatar_url;+ if matches!(sender.sender_type, ApiMessageSenderType::Bot) {+ if let Some(profile) = bot_profile {+ sender.name = Some(profile.name);+ sender.avatar_url = profile.avatar_url;+ }+ sender.triggered_by = triggered_by;}sender}@@ -1692,7 +1704,11 @@ impl From<ChannelMessage> for ApiChannelMessage {Self {id: m.id,channel_id: m.channel_id,- sender: ApiMessageSender::from_message_sender(&m.sender_id, m.bot_profile),+ sender: ApiMessageSender::from_message_sender(+ &m.sender_id,+ m.triggered_by,+ m.bot_profile,+ ),sender_id: m.sender_id,content: m.content,created_at: m.created_at,@@ -1752,7 +1768,11 @@ impl From<ChannelContextMessage> for ApiChannelContextMessage {id: message.id,channel_id: message.channel_id,thread_id: message.thread_id,- sender: ApiMessageSender::from_message_sender(&message.sender_id, message.bot_profile),+ sender: ApiMessageSender::from_message_sender(+ &message.sender_id,+ message.triggered_by,+ message.bot_profile,+ ),sender_id: message.sender_id,content: message.content,created_at: message.created_at,@@ -1907,7 +1927,11 @@ impl From<ThreadReply> for ApiThreadReply {fn from(r: ThreadReply) -> Self {Self {id: r.id,- sender: ApiMessageSender::from_message_sender(&r.sender_id, r.bot_profile),+ sender: ApiMessageSender::from_message_sender(+ &r.sender_id,+ r.triggered_by,+ r.bot_profile,+ ),sender_id: r.sender_id,content: r.content,created_at: r.created_at,diff --git a/rust/cloud-storage/channels/src/inbound/axum_router/test.rs b/rust/cloud-storage/channels/src/inbound/axum_router/test.rsindex f92fdfaa16..b6ce5d645c 100644--- a/rust/cloud-storage/channels/src/inbound/axum_router/test.rs+++ b/rust/cloud-storage/channels/src/inbound/axum_router/test.rs@@ -264,6 +264,7 @@ impl ChannelService for MockService {channel_id,thread_id: None,sender_id: "macro|[email protected]".to_string(),+ triggered_by: None,bot_profile: None,content: "message context".to_string(),created_at: now,@@ -1055,6 +1056,7 @@ impl ChannelService for AroundHasItemsService {id: Uuid::new_v4(),channel_id,sender_id: "macro|[email protected]".to_string(),+ triggered_by: None,bot_profile: None,content: "hello".to_string(),created_at: now,diff --git a/rust/cloud-storage/channels/src/inbound/toolset/mod.rs b/rust/cloud-storage/channels/src/inbound/toolset/mod.rsindex 146c732af6..a0c4d6910b 100644--- a/rust/cloud-storage/channels/src/inbound/toolset/mod.rs+++ b/rust/cloud-storage/channels/src/inbound/toolset/mod.rs@@ -3,12 +3,15 @@mod read_channel_message_context;mod read_channel_messages;mod read_channel_thread;+mod send_channel_message;mod types;#[cfg(test)]mod test;-use crate::domain::ports::ChannelService;+use crate::{+ domain::ports::ChannelService, inbound::toolset::send_channel_message::SendChannelMessage,+};use ai_toolset::{AsyncToolCollection, RequestContext, ToolCallError};use entity_access::domain::{models::{AccessError, AccessLevel, EntityType},@@ -108,4 +111,5 @@ where.add_tool::<ReadChannelMessages, ChannelToolContext<Svc, AccessSvc>>().add_tool::<ReadChannelMessageContext, ChannelToolContext<Svc, AccessSvc>>().add_tool::<ReadChannelThread, ChannelToolContext<Svc, AccessSvc>>()+ .add_tool::<SendChannelMessage, ChannelToolContext<Svc, AccessSvc>>()}diff --git a/rust/cloud-storage/channels/src/inbound/toolset/send_channel_message.rs b/rust/cloud-storage/channels/src/inbound/toolset/send_channel_message.rsnew file mode 100644index 0000000000..9ff86ddce0--- /dev/null+++ b/rust/cloud-storage/channels/src/inbound/toolset/send_channel_message.rs@@ -0,0 +1,89 @@+use ai_toolset::{AsyncTool, RequestContext, ServiceContext, ToolCallError, ToolResult};+use async_trait::async_trait;+use schemars::JsonSchema;+use serde::{Deserialize, Serialize};+use uuid::Uuid;++use crate::domain::models::{PostMessageNotificationPolicy, PostMessageRequest, Sender};+use crate::domain::ports::ChannelService;+use crate::inbound::toolset::ChannelToolContext;+use entity_access::domain::ports::EntityAccessService;++#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]+#[schemars(+ title = "SendChannelMessage",+ description = "Send or reply to a channel on behalf of the user. Only use this when explicitly asked to send a message"+)]+pub struct SendChannelMessage {+ /// macro markdown+ #[schemars(+ description = "Message content in macro markdown format. This uses the same syntax as markdown documents"+ )]+ pub content: String,+ /// the channel to send to+ #[schemars(description = "The channel id to send the message to")]+ pub channel_id: Uuid,+ /// an optional thread being replied too+ #[schemars(description = "An optional thread id to reply too")]+ pub thread_id: Option<Uuid>,+}++#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]+pub struct SendChannelMessageResponse {+ pub channel_id: Uuid,+ pub message_id: String,+}++#[async_trait]+impl<Svc, AccessSvc> AsyncTool<ChannelToolContext<Svc, AccessSvc>> for SendChannelMessage+where+ Svc: ChannelService,+ AccessSvc: EntityAccessService,+{+ type Output = SendChannelMessageResponse;++ #[tracing::instrument(skip_all, fields(user_id=?request_context.user_id), err)]+ async fn call(+ &self,+ service_context: ServiceContext<ChannelToolContext<Svc, AccessSvc>>,+ request_context: RequestContext,+ ) -> ToolResult<Self::Output> {+ service_context+ .require_channel_member(&request_context, self.channel_id)+ .await?;++ // AI sends as the Macro agent bot; the triggering user is recorded+ // separately so the client can render a "from <user>" pill.+ let actor = Sender::Bot(bot_id::MACRO_AI_BOT_ID);+ let triggered_by = Some(request_context.user_id.as_ref().to_string());++ let req = PostMessageRequest {+ content: self.content.clone(),+ mentions: vec![],+ attachments: vec![],+ nonce: None,+ notification_policy: PostMessageNotificationPolicy::Default,+ thread_id: self.thread_id,+ triggered_by,+ };++ service_context+ .service+ .post_message(actor, self.channel_id, req)+ .await+ .map_err(tool_err("failed to send message"))+ .map(|response| SendChannelMessageResponse {+ channel_id: self.channel_id,+ message_id: response.id,+ })+ }+}++fn tool_err(+ description: &'static str,+) -> impl FnOnce(crate::domain::ports::ChannelMutationErr) -> ToolCallError {+ move |err| ToolCallError {+ description: description.to_string(),+ internal_error: anyhow::Error::new(err),+ }+}diff --git a/rust/cloud-storage/channels/src/inbound/toolset/types.rs b/rust/cloud-storage/channels/src/inbound/toolset/types.rsindex 1d944b1272..f1baff9dd4 100644--- a/rust/cloud-storage/channels/src/inbound/toolset/types.rs+++ b/rust/cloud-storage/channels/src/inbound/toolset/types.rs@@ -403,6 +403,7 @@ mod tests {ThreadReply {id: Uuid::new_v4(),sender_id: "macro|[email protected]".to_string(),+ triggered_by: None,bot_profile: None,content: "reply".to_string(),created_at: dt(seconds),@@ -419,6 +420,7 @@ mod tests {id,channel_id: Uuid::new_v4(),sender_id: "macro|[email protected]".to_string(),+ triggered_by: None,bot_profile: None,content: "parent".to_string(),created_at: dt(1),diff --git a/rust/cloud-storage/channels/src/outbound/connection_gateway_realtime.rs b/rust/cloud-storage/channels/src/outbound/connection_gateway_realtime.rsindex 1709e933c9..0b34d77204 100644--- a/rust/cloud-storage/channels/src/outbound/connection_gateway_realtime.rs+++ b/rust/cloud-storage/channels/src/outbound/connection_gateway_realtime.rs@@ -63,11 +63,18 @@ impl ChannelRealtimePublisher for ConnectionGatewayChannelRealtimePublisher {bot_profile,nonce,} => {- let sender = MessageRealtimeSender::new(&message.sender_id, bot_profile);+ let sender = MessageRealtimeSender::new(+ &message.sender_id,+ message.triggered_by.clone(),+ bot_profile,+ );self.send_update("comms_message",WithNonce {- data: MessageRealtimeData { message, sender },+ data: MessageRealtimeData {+ message: *message,+ sender,+ },nonce,},recipients,@@ -168,22 +175,30 @@ struct MessageRealtimeSender {name: Option<String>,#[serde(skip_serializing_if = "Option::is_none")]avatar_url: Option<String>,+ #[serde(skip_serializing_if = "Option::is_none")]+ triggered_by: Option<String>,}impl MessageRealtimeSender {- fn new(sender: &Sender, bot_profile: Option<BotSenderProfile>) -> Self {+ fn new(+ sender: &Sender,+ triggered_by: Option<String>,+ bot_profile: Option<BotSenderProfile>,+ ) -> Self {match sender {Sender::Bot(bot_id) => Self {sender_type: "bot",id: bot_id.as_uuid().to_string(),name: bot_profile.as_ref().map(|profile| profile.name.clone()),avatar_url: bot_profile.and_then(|profile| profile.avatar_url),+ triggered_by,},Sender::User(user_id) => Self {sender_type: "user",id: user_id.as_ref().to_string(),name: None,avatar_url: None,+ triggered_by: None,},}}diff --git a/rust/cloud-storage/channels/src/outbound/connection_gateway_realtime/test.rs b/rust/cloud-storage/channels/src/outbound/connection_gateway_realtime/test.rsindex 9201151237..e2a8c2d643 100644--- a/rust/cloud-storage/channels/src/outbound/connection_gateway_realtime/test.rs+++ b/rust/cloud-storage/channels/src/outbound/connection_gateway_realtime/test.rs@@ -10,6 +10,7 @@ fn message(sender_id: Sender) -> MutatedMessage {channel_id: Uuid::new_v4(),thread_id: None,sender_id,+ triggered_by: None,content: "hello".to_string(),created_at: now,updated_at: now,@@ -24,6 +25,7 @@ fn bot_message_payload_includes_enriched_sender() {let message = message(Sender::Bot(bot_id));let sender = MessageRealtimeSender::new(&message.sender_id,+ None,Some(BotSenderProfile {name: "Deploy Bot".to_string(),avatar_url: Some("https://example.com/bot.png".to_string()),@@ -49,12 +51,36 @@ fn bot_message_payload_includes_enriched_sender() {);}+#[test]+fn agent_message_payload_includes_triggering_user() {+ let bot_id = BotId::from_uuid(Uuid::new_v4());+ let message = message(Sender::Bot(bot_id));+ let sender = MessageRealtimeSender::new(+ &message.sender_id,+ Some("macro|[email protected]".to_string()),+ Some(BotSenderProfile {+ name: "Macro".to_string(),+ avatar_url: None,+ }),+ );++ let payload = serde_json::to_value(WithNonce {+ data: MessageRealtimeData { message, sender },+ nonce: None,+ })+ .unwrap();++ assert_eq!(payload["sender"]["type"], "bot");+ assert_eq!(payload["sender"]["name"], "Macro");+ assert_eq!(payload["sender"]["triggered_by"], "macro|[email protected]");+}+#[test]fn user_message_payload_omits_bot_fields() {let user = macro_user_id::user_id::MacroUserIdStr::try_from_email("[email protected]").expect("valid email");let message = message(Sender::User(user.clone()));- let sender = MessageRealtimeSender::new(&message.sender_id, None);+ let sender = MessageRealtimeSender::new(&message.sender_id, None, None);let payload = serde_json::to_value(WithNonce {data: MessageRealtimeData { message, sender },diff --git a/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs b/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rsindex 84be1b5055..245962fdda 100644--- a/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs+++ b/rust/cloud-storage/channels/src/outbound/pg_channels_repo.rs@@ -68,6 +68,7 @@ struct TopLevelRow {id: Uuid,channel_id: Uuid,sender_id: String,+ triggered_by_user_id: Option<String>,content: String,created_at: chrono::DateTime<chrono::Utc>,updated_at: chrono::DateTime<chrono::Utc>,@@ -90,6 +91,7 @@ struct ThreadDataRow {id: Uuid,thread_id: Uuid,sender_id: String,+ triggered_by_user_id: Option<String>,content: String,created_at: chrono::DateTime<chrono::Utc>,updated_at: chrono::DateTime<chrono::Utc>,@@ -104,6 +106,7 @@ struct ThreadReplyOnlyRow {id: Uuid,thread_id: Uuid,sender_id: String,+ triggered_by_user_id: Option<String>,content: String,created_at: chrono::DateTime<chrono::Utc>,updated_at: chrono::DateTime<chrono::Utc>,@@ -159,6 +162,7 @@ struct ContextMessageRow {channel_id: Uuid,thread_id: Option<Uuid>,sender_id: String,+ triggered_by_user_id: Option<String>,content: String,created_at: chrono::DateTime<chrono::Utc>,updated_at: chrono::DateTime<chrono::Utc>,@@ -173,6 +177,7 @@ impl From<ContextMessageRow> for ChannelContextMessage {channel_id: row.channel_id,thread_id: row.thread_id,sender_id: row.sender_id,+ triggered_by: row.triggered_by_user_id,// Bot profiles are joined in the service layer.bot_profile: None,content: row.content,@@ -201,6 +206,7 @@ struct MutatedMessageRow {channel_id: Uuid,thread_id: Option<Uuid>,sender_id: String,+ triggered_by_user_id: Option<String>,content: String,created_at: chrono::DateTime<chrono::Utc>,updated_at: chrono::DateTime<chrono::Utc>,@@ -283,6 +289,7 @@ fn mutated_message_from_row(row: MutatedMessageRow) -> anyhow::Result<MutatedMeschannel_id: row.channel_id,thread_id: row.thread_id,sender_id,+ triggered_by: row.triggered_by_user_id,content: row.content,created_at: row.created_at,updated_at: row.updated_at,@@ -928,6 +935,7 @@ fn build_channel_thread_rows_query(m.id AS id,m.channel_id AS channel_id,m.sender_id AS sender_id,+ m.triggered_by_user_id AS triggered_by_user_id,m.content AS content,m.created_at AS created_at,m.updated_at AS updated_at,@@ -1255,6 +1263,7 @@ impl ChannelListRepo for PgChannelsRepo {id: row.try_get("id")?,channel_id: row.try_get("channel_id")?,sender_id: row.try_get("sender_id")?,+ triggered_by: row.try_get::<Option<String>, _>("triggered_by_user_id")?,content: row.try_get("content")?,created_at: row.try_get("created_at")?,updated_at: row.try_get("updated_at")?,@@ -1315,6 +1324,7 @@ impl ChannelListRepo for PgChannelsRepo {.map(|reply| ThreadReply {id: reply.id,sender_id: reply.sender_id.clone(),+ triggered_by: reply.triggered_by.clone(),bot_profile: bot_profile_for_sender(&bot_profiles,&reply.sender_id,@@ -1337,6 +1347,7 @@ impl ChannelListRepo for PgChannelsRepo {id: parent.id,channel_id: parent.channel_id,sender_id: parent.sender_id.clone(),+ triggered_by: parent.triggered_by.clone(),bot_profile: bot_profile_for_sender(&bot_profiles, &parent.sender_id),content: parent.content,created_at: parent.created_at,@@ -1504,6 +1515,7 @@ impl ChannelRepo for PgChannelsRepo {m.id,m.channel_id,m.sender_id,+ m.triggered_by_user_id,m.content,m.created_at,m.updated_at,@@ -1596,6 +1608,7 @@ impl ChannelRepo for PgChannelsRepo {m.id,m.channel_id,m.sender_id,+ m.triggered_by_user_id,m.content,m.created_at,m.updated_at,@@ -1694,6 +1707,7 @@ impl ChannelRepo for PgChannelsRepo {id: r.id,channel_id: r.channel_id,sender_id: r.sender_id,+ triggered_by: r.triggered_by_user_id,content: r.content,created_at: r.created_at,updated_at: r.updated_at,@@ -1723,6 +1737,7 @@ impl ChannelRepo for PgChannelsRepo {r#"SELECTid AS "id!", thread_id AS "thread_id!", sender_id AS "sender_id!",+ triggered_by_user_id,content AS "content!", created_at AS "created_at!", updated_at AS "updated_at!",edited_at::timestamptz AS "edited_at?",reply_count AS "reply_count!", latest_reply_at AS "latest_reply_at?"@@ -1731,6 +1746,7 @@ impl ChannelRepo for PgChannelsRepo {r.id,r.thread_id,r.sender_id,+ r.triggered_by_user_id,r.content,r.created_at,r.updated_at,@@ -1764,6 +1780,7 @@ impl ChannelRepo for PgChannelsRepo {id: r.id,thread_id: r.thread_id,sender_id: r.sender_id,+ triggered_by: r.triggered_by_user_id,content: r.content,created_at: r.created_at,updated_at: r.updated_at,@@ -1783,6 +1800,7 @@ impl ChannelRepo for PgChannelsRepo {id,thread_id AS "thread_id!",sender_id,+ triggered_by_user_id,content,created_at,updated_at,@@ -1803,6 +1821,7 @@ impl ChannelRepo for PgChannelsRepo {id: r.id,thread_id: r.thread_id,sender_id: r.sender_id,+ triggered_by: r.triggered_by_user_id,content: r.content,created_at: r.created_at,updated_at: r.updated_at,@@ -2009,6 +2028,7 @@ impl ChannelRepo for PgChannelsRepo {channel_id,thread_id,sender_id,+ triggered_by_user_id,content,created_at,updated_at,@@ -2035,6 +2055,7 @@ impl ChannelRepo for PgChannelsRepo {channel_id,thread_id,sender_id,+ triggered_by_user_id,content,created_at,updated_at,@@ -2063,6 +2084,7 @@ impl ChannelRepo for PgChannelsRepo {channel_id,thread_id,sender_id,+ triggered_by_user_id,content,created_at,updated_at,@@ -2251,6 +2273,7 @@ impl ChannelRepo for PgChannelsRepo {m.id,m.channel_id,m.sender_id,+ m.triggered_by_user_id,m.content,m.created_at,m.updated_at,@@ -2274,6 +2297,7 @@ impl ChannelRepo for PgChannelsRepo {id: r.id,channel_id: r.channel_id,sender_id: r.sender_id,+ triggered_by: r.triggered_by_user_id,content: r.content,created_at: r.created_at,updated_at: r.updated_at,@@ -2335,6 +2359,7 @@ impl ChannelRepo for PgChannelsRepo {m.id,m.channel_id,m.sender_id,+ m.triggered_by_user_id,m.content,m.created_at,m.updated_at,@@ -2365,6 +2390,7 @@ impl ChannelRepo for PgChannelsRepo {m.id,m.channel_id,m.sender_id,+ m.triggered_by_user_id,m.content,m.created_at,m.updated_at,@@ -2395,6 +2421,7 @@ impl ChannelRepo for PgChannelsRepo {id: r.id,channel_id: r.channel_id,sender_id: r.sender_id,+ triggered_by: r.triggered_by_user_id,content: r.content,created_at: r.created_at,updated_at: r.updated_at,@@ -2765,6 +2792,7 @@ impl ChannelRepo for PgChannelsRepo {&self,channel_id: Uuid,sender_id: String,+ triggered_by_user_id: Option<String>,content: String,thread_id: Option<Uuid>,) -> Result<MutatedMessage, Self::Err> {@@ -2772,12 +2800,13 @@ impl ChannelRepo for PgChannelsRepo {let row = sqlx::query_as!(MutatedMessageRow,r#"- INSERT INTO comms_messages (id, channel_id, sender_id, content, thread_id)- VALUES ($1, $2, $3, $4, $5)+ INSERT INTO comms_messages (id, channel_id, sender_id, triggered_by_user_id, content, thread_id)+ VALUES ($1, $2, $3, $4, $5, $6)RETURNINGid,channel_id,sender_id,+ triggered_by_user_id,content,created_at,updated_at,@@ -2788,6 +2817,7 @@ impl ChannelRepo for PgChannelsRepo {message_id,channel_id,sender_id,+ triggered_by_user_id,content,thread_id,)@@ -3013,6 +3043,7 @@ impl ChannelRepo for PgChannelsRepo {id,channel_id,sender_id,+ triggered_by_user_id,content,created_at,updated_at,@@ -3045,6 +3076,7 @@ impl ChannelRepo for PgChannelsRepo {id,channel_id,sender_id,+ triggered_by_user_id,content,created_at,updated_at,@@ -3076,6 +3108,7 @@ impl ChannelRepo for PgChannelsRepo {id,channel_id,sender_id,+ triggered_by_user_id,content,created_at,updated_at,diff --git a/rust/cloud-storage/document_storage_service/src/main.rs b/rust/cloud-storage/document_storage_service/src/main.rsindex 9ac261f7e6..c0e2d44735 100644--- a/rust/cloud-storage/document_storage_service/src/main.rs+++ b/rust/cloud-storage/document_storage_service/src/main.rs@@ -623,16 +623,24 @@ async fn main() -> anyhow::Result<()> {let channels_service = Arc::new(ChannelServiceImpl::with_dependencies(channels_repo,- SpawnedChannelEventDispatcher::new(channel_side_effects),+ SpawnedChannelEventDispatcher::new(channel_side_effects.clone()),PgChannelReferenceSharePermissions::new(db.clone(), entity_access_service.clone()),));// Wire Macro AI to react to mentions. The router posts replies through the// channel service we just built and runs the agent loop in-process with the// same pre-configured toolset used by other AI hosts.- let macro_agent_tool_context = ai_tools::build_tool_service_context_from_env(db.clone())+ let mut macro_agent_tool_context = ai_tools::build_tool_service_context_from_env(db.clone()).await.context("failed to build Macro agent tool context")?;+ // Wire the agent's SendChannelMessage tool to the same side-effect pipeline+ // as the HTTP API, so messages it posts fire notifications and realtime+ // updates (the generic env builder uses a no-op dispatcher otherwise).+ macro_agent_tool_context.channel_tool_context =+ ai_tools::build_channel_tool_context_with_dispatcher(+ db.clone(),+ std::sync::Arc::new(SpawnedChannelEventDispatcher::new(channel_side_effects)),+ );let macro_agent_tools = ai_tools::all_tools();let bot_trigger_router = channel_bots::inbound::BotTriggerRouter::new(channels_service.clone(),diff --git a/rust/cloud-storage/macro_db_client/migrations/20260629171949_add_comms_messages_triggered_by.sql b/rust/cloud-storage/macro_db_client/migrations/20260629171949_add_comms_messages_triggered_by.sqlnew file mode 100644index 0000000000..ff976ea4c3--- /dev/null+++ b/rust/cloud-storage/macro_db_client/migrations/20260629171949_add_comms_messages_triggered_by.sql@@ -0,0 +1,11 @@+-- Record which user triggered an agent-authored channel message.+--+-- AI/agent messages are sent as the Macro agent bot (`Sender::Bot`), so the+-- `sender_id` identifies the bot, not the person who prompted it. This column+-- persists the triggering user's id so clients can render a "from <user>" pill+-- on the agent's message.+--+-- Nullable with no default: human messages and channel/system bots leave it+-- NULL, and the column adds without a table rewrite or backfill.+ALTER TABLE public.comms_messages+ ADD COLUMN IF NOT EXISTS triggered_by_user_id text;diff --git a/rust/cloud-storage/soup/src/domain/service/tests.rs b/rust/cloud-storage/soup/src/domain/service/tests.rsindex 8f4cf83734..14d0e18b79 100644--- a/rust/cloud-storage/soup/src/domain/service/tests.rs+++ b/rust/cloud-storage/soup/src/domain/service/tests.rs@@ -506,6 +506,7 @@ fn channel_thread_message(updated_at,edited_at: None,deleted_at: None,+ triggered_by: None,thread: ThreadInfo {reply_count: 1,latest_reply_at: Some(DateTime::default() + Days::new(1)),@@ -517,6 +518,7 @@ fn channel_thread_message(created_at: DateTime::default() + Days::new(1),updated_at: DateTime::default() + Days::new(1),edited_at: None,+ triggered_by: None,reactions: Vec::new(),attachments: Vec::new(),}],