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 { FoldedMessage } from '@service-agent-fold/generated/types';
import { describe, expect, it } from 'vitest';
import { isLiveTurn, liveTurnMessage } from './live-turn';
const agent = (turn: number, stop: FoldedMessage['stop']): FoldedMessage => ({
agentSessionId: 'session',
key: `${turn}:agent`,
pending: false,
segments: [],
phase: null,
postedAt: null,
requestId: null,
turn,
author: { kind: 'agent' },
parts: [{ kind: 'thought', text: 'hm' }],
stop,
});
const user = (turn: number): FoldedMessage => ({
agentSessionId: 'session',
key: `${turn}:user`,
pending: false,
segments: [],
phase: null,
postedAt: null,
requestId: null,
turn,
author: { kind: 'user', userId: 'u' },
parts: [{ kind: 'text', text: 'do it' }],
stop: null,
});
const control = (turn: number): FoldedMessage => ({
agentSessionId: 'session',
key: `${turn}:user`,
pending: false,
segments: [],
phase: null,
postedAt: null,
requestId: 'r',
turn,
author: { kind: 'user', userId: 'u' },
parts: [
{
kind: 'control',
control: { kind: 'set_model', model: 'x' },
outcome: { kind: 'accepted' },
},
],
stop: null,
});
describe('liveTurnMessage', () => {
it('names the newest agent message while the session is working', () => {
const tail = agent(1, null);
expect(
liveTurnMessage([user(0), agent(0, null), user(1), tail], true)
).toBe(tail);
});
it('names nothing once the session has stopped working, whatever stop says', () => {
// A superseded turn keeps `stop: null`; a dead runtime never stamps one.
expect(liveTurnMessage([user(0), agent(0, null)], false)).toBeUndefined();
});
it('names nothing while a prompt is still awaiting its reply', () => {
expect(
liveTurnMessage([user(0), agent(0, { kind: 'end_turn' }), user(1)], true)
).toBeUndefined();
});
it('does not keep a turn live across a trailing model change', () => {
expect(
liveTurnMessage([user(0), agent(0, null), control(1)], true)
).toBeUndefined();
});
it('names the agent message that follows a model change', () => {
const next = agent(2, null);
expect(
liveTurnMessage([user(0), agent(0, null), control(1), next], true)
).toBe(next);
});
it('is empty for an empty transcript', () => {
expect(liveTurnMessage([], true)).toBeUndefined();
});
});
describe('isLiveTurn', () => {
it('matches by turn and author, not identity', () => {
const live = agent(3, null);
expect(isLiveTurn({ ...live }, live)).toBe(true);
expect(isLiveTurn(agent(2, null), live)).toBe(false);
expect(isLiveTurn(user(3), live)).toBe(false);
});
it('is false when nothing is live', () => {
expect(isLiveTurn(agent(0, null), undefined)).toBe(false);
});
});