Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions apps/api/src/handlers/custom-automations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import {
users,
} from '@roomote/db/server';
import {
CUSTOM_AUTOMATION_DESTINATION_CAPABILITIES,
listConnectedCommunicationProviders,
listAvailableAgentMailOutboundIdentities,
canStartAgentMailConversationWithUser,
resolveCustomAutomationSchedule,
resolveDefaultAutomationTarget,
runCustomAutomationNow,
} from '@roomote/sdk/server';
import {
Expand Down Expand Up @@ -400,16 +402,27 @@ customAutomationsRouter.get('/models', async (c) =>
customAutomationsRouter.get('/destinations', async (c) => {
const automationId = c.req.query('automationId');
let ownerUserId = actorId(c);
let existingTarget: OptionalAutomationTarget | null = null;
if (automationId) {
const automation = await getCustomAutomationById(automationId);
if (!automation || !canManage(c, automation)) {
return c.json({ error: 'Custom automation was not found.' }, 404);
}
ownerUserId = automation.createdByUserId ?? ownerUserId;
existingTarget = automation.target;
}
const [emailIdentities, defaultTarget] = await Promise.all([
listAvailableAgentMailOutboundIdentities(ownerUserId),
resolveDefaultAutomationTarget({
ownerUserId,
capabilities: CUSTOM_AUTOMATION_DESTINATION_CAPABILITIES,
existingTarget,
includeSharedChannels: c.get('customAutomationUser').role === 'admin',
}),
]);
return c.json({
emailIdentities:
await listAvailableAgentMailOutboundIdentities(ownerUserId),
emailIdentities,
defaultTarget,
});
});

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
AUTOMATION_RESULT_PRIORITIES,
type AutomationResultPriority,
type CustomAutomationScheduleMode,
type OptionalAutomationTarget,
type ReasoningEffort,
} from '@roomote/types';

Expand Down Expand Up @@ -292,12 +293,12 @@ function CustomAutomationRunButton({
);
}

function targetFromRow(row: CustomAutomationListItem): {
function targetFromAutomationTarget(target: OptionalAutomationTarget): {
provider: CustomAutomationFormState['targetProvider'];
mode: CustomAutomationFormState['targetMode'];
channelId: string;
} {
if (!row.target.provider || !row.target.externalRef) {
if (!target.provider || !target.externalRef) {
return {
provider: 'none',
mode: 'channel',
Expand All @@ -306,26 +307,30 @@ function targetFromRow(row: CustomAutomationListItem): {
}

const provider =
row.target.provider === 'discord' ||
row.target.provider === 'teams' ||
row.target.provider === 'telegram' ||
row.target.provider === 'email'
? row.target.provider
target.provider === 'discord' ||
target.provider === 'teams' ||
target.provider === 'telegram' ||
target.provider === 'email'
? target.provider
: 'slack';
return {
provider,
mode: isBackgroundAutomationUserTargetKind(row.target.targetKind)
mode: isBackgroundAutomationUserTargetKind(target.targetKind)
? 'direct_message'
: 'channel',
channelId:
row.target.provider === 'email'
? (getAutomationTargetEmailIdentityId(row.target) ?? '')
: isBackgroundAutomationUserTargetKind(row.target.targetKind)
target.provider === 'email'
? (getAutomationTargetEmailIdentityId(target) ?? '')
: isBackgroundAutomationUserTargetKind(target.targetKind)
? ''
: (row.target.externalRef ?? ''),
: (target.externalRef ?? ''),
};
}

function targetFromRow(row: CustomAutomationListItem) {
return targetFromAutomationTarget(row.target);
}

function formFromRow(
row: CustomAutomationListItem,
connectedProviders: readonly ConnectedDestinationProvider[] | null,
Expand Down Expand Up @@ -1199,29 +1204,16 @@ export function CustomAutomationsSection({
size="sm"
disabled={busy || atCap || !capabilitiesLoaded}
onClick={() => {
const managerProvider =
managerSlackChannelId && capabilities?.slackConnected
? 'slack'
: managerDiscordChannelId && capabilities?.discordConnected
? 'discord'
: null;
const targetProvider =
managerProvider ?? connectedDestinationOptions[0]?.value ?? 'none';
const target = targetFromAutomationTarget(
optionsQuery.data?.defaultTarget ?? {},
);
setIsCreating(true);
setEditingId(null);
setForm({
...EMPTY_FORM,
targetProvider,
targetMode:
targetProvider === 'email' ? 'direct_message' : 'channel',
targetChannelId:
targetProvider === 'slack'
? managerSlackChannelId
: targetProvider === 'discord'
? managerDiscordChannelId
: targetProvider === 'email'
? (emailOptions[0]?.id ?? '')
: '',
targetProvider: target.provider,
targetMode: target.mode,
targetChannelId: target.channelId,
});
setResolvedCron(null);
setScheduleSummary(null);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading