Share via


@microsoft/agents-hosting-storage-blob package

Classes

BlobsStorage

A class that implements the Storage interface using Azure Blob Storage. Provides persistence for bot state data using Azure's Blob Storage service.

BlobsTranscriptStore

A class that implements the TranscriptStore interface using Azure Blob Storage.

Interfaces

BlobsStorageOptions

Options for configuring the BlobsStorage.

BlobsTranscriptStoreOptions

Options for configuring the BlobsTranscriptStore.

Functions

maybeCast<T>(unknown, (args: any[]) => T)

Performs type casting with optional constructor validation.

Example

// With constructor validation
const dateValue = maybeCast(someValue, Date);

// Direct type assertion
const stringValue = maybeCast<string>(someValue);
sanitizeBlobKey(string, BlobsTranscriptStoreOptions)

Sanitizes a blob key for use with Azure Blob Storage.

Example

// Basic sanitization with encoding
const sanitized = sanitizeBlobKey('channel1/conversation2/activity.json');
// Returns: 'channel1%2Fconversation2%2Factivity.json'

// Sanitization with decoding option
const decoded = sanitizeBlobKey('channel1/conversation2/activity.json', { decodeTranscriptKey: true });
// Returns: 'channel1/conversation2/activity.json'

// Handles empty path segments
const withEmptySegments = sanitizeBlobKey('channel1//conversation2///activity.json');
// Returns: 'channel1%2Fconversation2%2Factivity.json'

Function Details

maybeCast<T>(unknown, (args: any[]) => T)

Performs type casting with optional constructor validation.

Example

// With constructor validation
const dateValue = maybeCast(someValue, Date);

// Direct type assertion
const stringValue = maybeCast<string>(someValue);
function maybeCast<T>(value: unknown, ctor?: (args: any[]) => T): T

Parameters

value

unknown

The value to cast.

ctor

(args: any[]) => T

Optional constructor function to validate the value against.

Returns

T

The value cast to type T.

Remarks

If a constructor is provided, validates that the value is an instance of that constructor. Otherwise, performs a direct type assertion.

sanitizeBlobKey(string, BlobsTranscriptStoreOptions)

Sanitizes a blob key for use with Azure Blob Storage.

Example

// Basic sanitization with encoding
const sanitized = sanitizeBlobKey('channel1/conversation2/activity.json');
// Returns: 'channel1%2Fconversation2%2Factivity.json'

// Sanitization with decoding option
const decoded = sanitizeBlobKey('channel1/conversation2/activity.json', { decodeTranscriptKey: true });
// Returns: 'channel1/conversation2/activity.json'

// Handles empty path segments
const withEmptySegments = sanitizeBlobKey('channel1//conversation2///activity.json');
// Returns: 'channel1%2Fconversation2%2Factivity.json'
function sanitizeBlobKey(key: string, options?: BlobsTranscriptStoreOptions): string

Parameters

key

string

The blob key string to sanitize. Must be non-empty.

options
BlobsTranscriptStoreOptions

Optional configuration options.

Returns

string

A sanitized blob key that is safe for use with Azure Blob Storage, truncated to 1024 characters.

Remarks

This function performs the following operations:

  1. Validates that the key is not empty
  2. Removes empty path segments by splitting on '/' and filtering out empty parts
  3. Truncates the sanitized key to 1024 characters maximum
  4. URL encodes the key to ensure it's safe for use as a blob name
  5. Optionally decodes the key if the decodeTranscriptKey option is set