Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(forms): share forms an agent presents in a channel reply (#9565)

Wolf Mermelstein55b6b2f414b4
diff --git a/apps/docs/AI/mcp/tools/set-form-access.mdx b/apps/docs/AI/mcp/tools/set-form-access.mdx
index 751ef73c6e..50bc674cbe 100644
--- a/apps/docs/AI/mcp/tools/set-form-access.mdx
+++ b/apps/docs/AI/mcp/tools/set-form-access.mdx
@@ -6,7 +6,7 @@ description: >-
# SetFormAccess
-Open, close or share a saved form immediately. Requires Form Owner. Supply complete audience/status/deadline/tally settings and explicit channel grant deltas; empty deltas change no grants. Optional responsesVisible lets View holders read response rows; optional anonymous makes the form anonymous to everyone, its owner included (who responded is kept apart from the responses), and is refused once anyone has responded. Public allows anonymous responses. View allows responding without database access unless responses are shared; channel Edit grants editing of the entire backing database. Uses the existing Forms settings and sharing services without a review step. This never posts a message or sends invitations. Settings and channel grants are separate writes; inspect partial results before retrying. Returns actual access, canonical links and acceptingResponses; a URL alone does not mean the form is open.
+Open, close or share a saved form immediately. Requires Form Owner. Supply complete audience/status/deadline/tally settings and explicit channel grant deltas; empty deltas change no grants. Optional responsesVisible lets View holders read response rows; optional anonymous makes the form anonymous to everyone, its owner included (who responded is kept apart from the responses), and is refused once anyone has responded. Public allows anonymous responses and is needed only for people without a Macro account; members-only already admits everyone in the channels the form is shared with, people outside the team included. View allows responding without database access unless responses are shared; channel Edit grants editing of the entire backing database. Uses the existing Forms settings and sharing services without a review step. This never posts a message or sends invitations. Settings and channel grants are separate writes; inspect partial results before retrying. Returns actual access, canonical links and acceptingResponses; a URL alone does not mean the form is open.
## Parameters
diff --git a/apps/web/src/lib/service-clients/service-cognition/generated/tools/types.ts b/apps/web/src/lib/service-clients/service-cognition/generated/tools/types.ts
index c013367545..279310f03a 100644
--- a/apps/web/src/lib/service-clients/service-cognition/generated/tools/types.ts
+++ b/apps/web/src/lib/service-clients/service-cognition/generated/tools/types.ts
@@ -15632,7 +15632,7 @@ export interface SetFavoriteResponse {
favorite: boolean;
}
/**
- * Open, close or share a saved form immediately. Requires Form Owner. Supply complete audience/status/deadline/tally settings and explicit channel grant deltas; empty deltas change no grants. Optional responsesVisible lets View holders read response rows; optional anonymous makes the form anonymous to everyone, its owner included (who responded is kept apart from the responses), and is refused once anyone has responded. Public allows anonymous responses. View allows responding without database access unless responses are shared; channel Edit grants editing of the entire backing database. Uses the existing Forms settings and sharing services without a review step. This never posts a message or sends invitations. Settings and channel grants are separate writes; inspect partial results before retrying. Returns actual access, canonical links and acceptingResponses; a URL alone does not mean the form is open.
+ * Open, close or share a saved form immediately. Requires Form Owner. Supply complete audience/status/deadline/tally settings and explicit channel grant deltas; empty deltas change no grants. Optional responsesVisible lets View holders read response rows; optional anonymous makes the form anonymous to everyone, its owner included (who responded is kept apart from the responses), and is refused once anyone has responded. Public allows anonymous responses and is needed only for people without a Macro account; members-only already admits everyone in the channels the form is shared with, people outside the team included. View allows responding without database access unless responses are shared; channel Edit grants editing of the entire backing database. Uses the existing Forms settings and sharing services without a review step. This never posts a message or sends invitations. Settings and channel grants are separate writes; inspect partial results before retrying. Returns actual access, canonical links and acceptingResponses; a URL alone does not mean the form is open.
*/
export interface SetFormAccess {
formId: FormId;
diff --git a/crates/forms/src/inbound/toolset/set_form_access.rs b/crates/forms/src/inbound/toolset/set_form_access.rs
index 9ee3899860..3d0c7e636f 100644
--- a/crates/forms/src/inbound/toolset/set_form_access.rs
+++ b/crates/forms/src/inbound/toolset/set_form_access.rs
@@ -11,7 +11,7 @@ use serde::Deserialize;
#[derive(Debug, Clone, Deserialize, JsonSchema)]
#[schemars(
title = "SetFormAccess",
- description = "Open, close or share a saved form immediately. Requires Form Owner. Supply complete audience/status/deadline/tally settings and explicit channel grant deltas; empty deltas change no grants. Optional responsesVisible lets View holders read response rows; optional anonymous makes the form anonymous to everyone, its owner included (who responded is kept apart from the responses), and is refused once anyone has responded. Public allows anonymous responses. View allows responding without database access unless responses are shared; channel Edit grants editing of the entire backing database. Uses the existing Forms settings and sharing services without a review step. This never posts a message or sends invitations. Settings and channel grants are separate writes; inspect partial results before retrying. Returns actual access, canonical links and acceptingResponses; a URL alone does not mean the form is open."
+ description = "Open, close or share a saved form immediately. Requires Form Owner. Supply complete audience/status/deadline/tally settings and explicit channel grant deltas; empty deltas change no grants. Optional responsesVisible lets View holders read response rows; optional anonymous makes the form anonymous to everyone, its owner included (who responded is kept apart from the responses), and is refused once anyone has responded. Public allows anonymous responses and is needed only for people without a Macro account; members-only already admits everyone in the channels the form is shared with, people outside the team included. View allows responding without database access unless responses are shared; channel Edit grants editing of the entire backing database. Uses the existing Forms settings and sharing services without a review step. This never posts a message or sends invitations. Settings and channel grants are separate writes; inspect partial results before retrying. Returns actual access, canonical links and acceptingResponses; a URL alone does not mean the form is open."
)]
pub struct SetFormAccess {
/// Flat workflow arguments shared with the domain service.
diff --git a/crates/models_forms/src/form.rs b/crates/models_forms/src/form.rs
index 15b4398d78..c4a6626dd1 100644
--- a/crates/models_forms/src/form.rs
+++ b/crates/models_forms/src/form.rs
@@ -26,11 +26,14 @@ use crate::ids::FormId;
#[serde(rename_all = "camelCase")]
#[strum(serialize_all = "snake_case")]
pub enum Audience {
- /// Signed-in Macro users the form is shared with; one response each,
- /// editable while the form is open.
+ /// Signed-in Macro users the form is shared with, directly or through a
+ /// channel: everyone in a channel it is shared with can respond, people
+ /// outside the owner's team included. One response each, editable while
+ /// the form is open.
Members,
/// Anyone with the link. Anonymous visitors respond anonymously and
- /// without a limit; a signed-in visitor responds as themselves.
+ /// without a limit; a signed-in visitor responds as themselves. Needed
+ /// only for people without a Macro account or the form's channels.
Public,
}
diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.md
index 94607eecaf..279db850e7 100644
--- a/docs/agent-guide/channels.md
+++ b/docs/agent-guide/channels.md
@@ -567,7 +567,7 @@ for the user to confirm a composer card). For an event with attendees the bot is
ask for confirmation in the thread first, since Google sends the invitations the moment the
event is created — no invitation goes out from the initial request. It cannot draft or send
email at all. A bot or agent reply posted for a person shares, as that person, the linked items
-(chips or attachments) that the replying bot created for them while answering: those with a
+(chips, attachments, or forms presented as cards in the reply's steps) that the replying bot created for them while answering: those with a
`created` activity row by that bot on the person's behalf since the person's latest message in
the thread before the reply, or, for a bot message that starts its own thread (a poll card
posted top-level), their latest message in the channel. Forms and databases an agent creates
diff --git a/docs/agent-guide/forms.md b/docs/agent-guide/forms.md
index bb19e88425..a087fb72fa 100644
--- a/docs/agent-guide/forms.md
+++ b/docs/agent-guide/forms.md
@@ -37,7 +37,10 @@ decides who may respond.
vote times keep only the day, and a vote can't be changed.
- Asked for a poll, or for a form for a channel, the Macro agent makes a poll
and posts it as its card in one message (its channel reply), the same card
- `/poll` posts.
+ `/poll` posts. A form the agent made for the request and presented as a card
+ in its reply's steps is shared with the channel the same way, so everyone in
+ the channel, people outside the team included, can respond to a
+ members-only form.
## The form page
diff --git a/packages/lexical-core/tests/channel-mentions.test.ts b/packages/lexical-core/tests/channel-mentions.test.ts
index 15281c0a81..198d5df942 100644
--- a/packages/lexical-core/tests/channel-mentions.test.ts
+++ b/packages/lexical-core/tests/channel-mentions.test.ts
@@ -116,3 +116,51 @@ it('preserves authored groups for server-side recipient expansion', () => {
)
).toEqual([{ entityType: 'group', entityId: 'here' }]);
});
+
+it('references the forms an agent reply presents in its activity cards', () => {
+ // An agent that presents a form it made posts it only as a card in the
+ // reply's steps; without a reference, channel delivery never shares the
+ // form and channel members are denied it.
+ const activity = {
+ agentSessionId: 'session-1',
+ turn: 0,
+ segment: 0,
+ sealed: true,
+ rows: [
+ { id: 'create', label: 'Create Form', status: 'completed' },
+ {
+ id: 'view-1',
+ label: 'Present view',
+ status: 'completed',
+ card: {
+ kind: 'view',
+ view: {
+ widgets: [
+ { type: 'cards', items: [{ type: 'form', id: 'form-1' }] },
+ {
+ type: 'container',
+ children: [
+ {
+ type: 'cards',
+ items: [
+ { type: 'form', id: 'form-2' },
+ { type: 'document', id: 'doc-1' },
+ ],
+ },
+ ],
+ },
+ ],
+ },
+ },
+ },
+ ],
+ };
+ expect(
+ extractChannelMentionsFromMarkdown(
+ `<m-agent-activity>${JSON.stringify(activity)}</m-agent-activity>\n\nI built the form.`
+ )
+ ).toEqual([
+ { entityType: 'form', entityId: 'form-1' },
+ { entityType: 'form', entityId: 'form-2' },
+ ]);
+});
diff --git a/packages/lexical-core/utils/mentions.ts b/packages/lexical-core/utils/mentions.ts
index e9ba8f6dbe..28beef3a69 100644
--- a/packages/lexical-core/utils/mentions.ts
+++ b/packages/lexical-core/utils/mentions.ts
@@ -1,6 +1,11 @@
import { $dfsIterator } from '@lexical/utils';
import { $getRoot, type LexicalNode } from 'lexical';
import { match, P } from 'ts-pattern';
+import type { Widget_Serialize as Widget } from '../generated/dynamic-ui';
+import {
+ $isAgentActivityNode,
+ isAgentActivityCard,
+} from '../nodes/AgentActivityNode';
import {
$isAgentSessionMentionNode,
type AgentSessionMentionInfo,
@@ -124,6 +129,18 @@ function documentMentionEntityType(blockName: string): string {
);
}
+/** The forms in a presented view's cards, nested containers included. */
+function viewFormIds(widgets: readonly Widget[]): string[] {
+ return widgets.flatMap((widget) =>
+ match(widget)
+ .with({ type: 'cards' }, ({ items }) =>
+ items.filter((item) => item.type === 'form').map((item) => item.id)
+ )
+ .with({ type: 'container' }, ({ children }) => viewFormIds(children))
+ .otherwise(() => [])
+ );
+}
+
/**
* Extracts the mentions in the current editor state as `ChannelMention`s,
* the way the web editor tracks them while composing a channel message.
@@ -132,7 +149,9 @@ function documentMentionEntityType(blockName: string): string {
* carry no referencable entity and are skipped. Project (initiative) and CRM
* pipeline mentions are skipped too: channel references auto-share their
* target with members.
- * Authored group mentions are preserved. Duplicates are dropped.
+ * Authored group mentions are preserved. Forms an agent reply presents as
+ * cards in its steps count as references, like a posted form card, so
+ * channel delivery can share them. Duplicates are dropped.
*/
export function $extractChannelMentions(): ChannelMention[] {
const out: ChannelMention[] = [];
@@ -156,6 +175,13 @@ export function $extractChannelMentions(): ChannelMention[] {
entityType: documentMentionEntityType(node.getBlockName()),
entityId: node.getDocumentId(),
});
+ } else if ($isAgentActivityNode(node)) {
+ for (const row of node.exportComponentProps().rows) {
+ if (!isAgentActivityCard(row.card)) continue;
+ for (const formId of viewFormIds(row.card.view.widgets)) {
+ push({ entityType: 'form', entityId: formId });
+ }
+ }
} else if ($isAgentSessionMentionNode(node)) {
push({ entityType: 'agent_session', entityId: node.getId() });
} else if ($isGroupMentionNode(node)) {