Skip to content

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

1.5 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { azureBlobStorageAuth } from '../auth';
import { BlobServiceClient } from '@azure/storage-blob';
import { containerProp } from '../common';

export const findBlobs = createAction({
  auth: azureBlobStorageAuth,
  name: 'findBlobs',
  classification: 'SEARCH',
  displayName: 'Find Blobs',
  description: 'Finds Blobs based on their tags',
  audience: 'both',
  aiMetadata: { description: 'Searches a container for blobs matching the supplied tag key-value pairs, returning the names of blobs whose tags satisfy all conditions (combined with AND). Use to locate blobs by tag rather than by name or prefix. Read-only and idempotent.', idempotent: true },
  props: {
    container: containerProp,
    tags: Property.Object({
      displayName: 'Tags',
      description: 'The tags to filter blobs by',
      required: true,
    }),
  },
  async run(context) {
    const { container, tags } = context.propsValue;
    const auth = context.auth.props;
    
    const blobServiceClient = BlobServiceClient.fromConnectionString(auth.connectionString);
    const containerClient = blobServiceClient.getContainerClient(container);

    const tagExpressions = Object.entries(tags).map(([key, value]) => `${key}='${value}'`);
    const tagQuery = tagExpressions.join(' AND ');

    const blobs = [];
    for await (const blob of containerClient.findBlobsByTags(tagQuery)) {
      blobs.push({
        name: blob.name
      });
    };

    return blobs;
  },
});