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
import type { RoutineTemplate } from '@service-scheduled-action/generated/schemas';
import { createRoot, createSignal } from 'solid-js';
import { describe, expect, it } from 'vitest';
import { createTemplateActivation } from './template-activation';
const DOC =
'<m-document-mention>{"documentId":"doc-1","documentName":"Acme account","blockName":"md"}</m-document-mention>';
const TEMPLATE: RoutineTemplate = {
id: 'template-1',
author: 'macro|[email protected]',
name: 'Weekly digest',
description: '',
active_count: 0,
created_at: '2026-10-20T00:00:00Z',
updated_at: '2026-10-20T00:00:00Z',
trigger: { type: 'cron', schedule: '0 0 9 * * 2', timezone: 'UTC' },
task: { model: 'model', prompt: '', user_prompt: `Read ${DOC}` },
variables: [
{
kind: 'item',
id: 'doc-1',
block_name: 'md',
label: 'Acme account',
fill: 'shared',
},
{ kind: 'time_zone', timezone: 'UTC', fill: 'activator' },
],
};
const ACTIVATOR = {
userId: 'macro|[email protected]',
email: '[email protected]',
timezone: 'America/New_York',
};
describe('createTemplateActivation', () => {
it('waits for a decision on an item the activator cannot open', () => {
createRoot((dispose) => {
const [access, setAccess] = createSignal<ReadonlyMap<string, boolean>>(
new Map([['doc-1', true]])
);
const activation = createTemplateActivation({
template: () => TEMPLATE,
activator: () => ACTIVATOR,
access,
});
expect(activation.request()).toEqual({
name: 'Weekly digest',
trigger: {
type: 'cron',
schedule: '0 0 9 * * 2',
timezone: 'America/New_York',
},
kind: 'Agent',
task: { model: 'model', prompt: '', user_prompt: `Read ${DOC}` },
enabled: true,
run_visibility: 'unlisted',
});
setAccess(new Map([['doc-1', false]]));
expect(activation.undecided().map((reference) => reference.key)).toEqual([
'doc-1',
]);
expect(activation.request()).toBeUndefined();
activation.choose('doc-1', 'leave_out');
expect(activation.request()?.task).toEqual({
model: 'model',
prompt: '',
user_prompt: 'Read Acme account',
});
dispose();
});
});
it('fills a routine with steps on its Ask AI step and keeps its code', () => {
createRoot((dispose) => {
const label = {
type: 'code',
title: 'Label invoices',
source: 'export async function main() {}',
};
const apps = [{ app_slug: 'linear', server_name: 'Linear' }];
const activation = createTemplateActivation({
template: () => ({
...TEMPLATE,
task: {
steps: [
label,
{ type: 'agent', model: 'model', instructions: `Read ${DOC}` },
],
mcp_servers: apps,
},
}),
activator: () => ACTIVATOR,
access: () => new Map([['doc-1', false]]),
});
expect(activation.prompt()).toBe(`Read ${DOC}`);
activation.choose('doc-1', 'leave_out');
expect(activation.request()?.task).toEqual({
steps: [
label,
{ type: 'agent', model: 'model', instructions: 'Read Acme account' },
],
mcp_servers: apps,
});
dispose();
});
});
it('fills the author in as the activator in the Ask AI step', () => {
createRoot((dispose) => {
const author =
'<m-user-mention>{"userId":"macro|[email protected]","email":"[email protected]"}</m-user-mention>';
const activation = createTemplateActivation({
template: () => ({
...TEMPLATE,
task: {
steps: [
{
type: 'agent',
model: 'model',
instructions: `Page ${author}, and tell ${author} tomorrow`,
},
],
},
variables: [
{
kind: 'user',
id: 'macro|[email protected]',
label: '[email protected]',
fill: 'activator',
},
],
}),
activator: () => ACTIVATOR,
access: () => new Map(),
});
const text = JSON.stringify(activation.request()?.task);
expect(text).not.toContain('[email protected]');
expect(text.match(/jun@macro\.com/g)).toHaveLength(4);
dispose();
});
});
});