AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { HttpMethod } from '@activepieces/pieces-common';
import { createAction, Property } from '@activepieces/pieces-framework';
import { airtopAuth } from '../common/auth';
import { airtopApiCall, extractApiData, AirtopSession } from '../common/client';
import { fileId } from '../common/props';
import { propsValidation } from '@activepieces/pieces-common';
import * as z from 'zod/mini'
export const uploadFileToSessionAction = createAction({
auth: airtopAuth,
name: 'upload-file-to-session',
classification: 'WRITE',
displayName: 'Upload File to Sessions',
description: 'Push an existing file to one or more sessions, making it available for use in file inputs or downloads.',
audience: 'both',
aiMetadata: {
description: 'Pushes an already-uploaded Airtop file (by file id) to specific sessions, or to all active sessions when no session ids are given, making it available for file inputs or downloads in those sessions. Use this after a file exists in Airtop and you need it accessible inside a browsing session. Requires the file id; not idempotent since it performs a push to session state on each call.',
idempotent: false,
},
props: {
fileId: fileId,
sessionIds: Property.MultiSelectDropdown({
auth: airtopAuth,
displayName: 'Session IDs',
description: 'Select one or more sessions to make the file available on. Leave empty to make available to all sessions.',
required: false,
refreshers: [],
options: async ({ auth }) => {
if (!auth) {
return {
disabled: true,
options: [],
placeholder: 'Connect your account first',
};
}
try {
const response = await airtopApiCall<any>({
apiKey: auth.secret_text,
method: HttpMethod.GET,
resourceUri: '/sessions',
});
const sessions = extractApiData<AirtopSession>(response);
if (sessions.length === 0) {
return {
disabled: false,
options: [],
placeholder: 'No active sessions found. Create a session first.',
};
}
const sortedSessions = sessions.sort((a, b) => {
if (a.status === 'active' && b.status !== 'active') return -1;
if (a.status !== 'active' && b.status === 'active') return 1;
return 0;
});
const options = sortedSessions.map((session) => ({
label: `${session.id} (${session.status})`,
value: session.id,
}));
return {
disabled: false,
options,
placeholder: options.length === 0 ? 'No sessions available' : 'Select sessions or leave empty for all',
};
} catch (error: any) {
return {
disabled: true,
options: [],
placeholder: `Error loading sessions: ${error.message}`,
};
}
},
}),
},
async run({ propsValue, auth }) {
const { fileId, sessionIds } = propsValue;
if (sessionIds && sessionIds.length > 0) {
await propsValidation.validateZod({ sessionIds }, {
sessionIds: z.array(z.string().check(z.minLength(1, 'Session ID cannot be empty'))).check(z.minLength(1, 'At least one session ID is required when providing session IDs')),
});
}
const body: Record<string, any> = {};
if (sessionIds && sessionIds.length > 0) {
body['sessionIds'] = sessionIds;
}
const result = await airtopApiCall({
apiKey: auth.secret_text,
method: HttpMethod.POST,
resourceUri: `/files/${fileId}/push`,
body,
});
return {
fileId,
sessionIds: sessionIds && sessionIds.length > 0 ? sessionIds : 'all sessions',
sessionsCount: sessionIds?.length || 'all',
message: sessionIds && sessionIds.length > 0
? `File successfully pushed to ${sessionIds.length} session(s).`
: 'File successfully pushed to all sessions.',
result,
};
},
});