@microsoft/agents-hosting-storage-blob 0.5.19-gc1e2ea1096 → 0.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -4,10 +4,23 @@
|
|
|
4
4
|
|
|
5
5
|
This package allows to configure Azure Blob Storage as the backend for Agents conversation State
|
|
6
6
|
|
|
7
|
-
## Usage
|
|
7
|
+
## Usage with connectionStrings
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
const blobStorage = new
|
|
10
|
+
const blobStorage = new BlobStorage(process.env.BLOB_STORAGE_CONNECTION_STRING!, process.env.BLOB_CONTAINER_ID!)
|
|
11
11
|
const conversationState = new ConversationState(blobStorage)
|
|
12
12
|
const userState = new UserState(blobStorage)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Usage with EntraID authentication
|
|
17
|
+
|
|
18
|
+
>note: you must assign RBAC permissions to your storage account
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
const echo = new AgentApplication<TurnState>({
|
|
22
|
+
storage: new BlobsStorage('', undefined, undefined,
|
|
23
|
+
'https://agentsstate.blob.core.windows.net/nodejs-conversations',
|
|
24
|
+
new MsalTokenCredential(loadAuthConfigFromEnv()))
|
|
25
|
+
})
|
|
13
26
|
```
|
|
@@ -1,7 +1,60 @@
|
|
|
1
1
|
import { Activity } from '@microsoft/agents-activity';
|
|
2
|
+
import { TokenCredential } from '@azure/core-auth';
|
|
2
3
|
import { AnonymousCredential, StoragePipelineOptions, StorageSharedKeyCredential } from '@azure/storage-blob';
|
|
3
4
|
import { TranscriptStore, PagedResult, TranscriptInfo } from '@microsoft/agents-hosting';
|
|
5
|
+
/**
|
|
6
|
+
* Sanitizes a blob key for use with Azure Blob Storage.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This function performs the following operations:
|
|
10
|
+
* 1. Validates that the key is not empty
|
|
11
|
+
* 2. Removes empty path segments by splitting on '/' and filtering out empty parts
|
|
12
|
+
* 3. Truncates the sanitized key to 1024 characters maximum
|
|
13
|
+
* 4. URL encodes the key to ensure it's safe for use as a blob name
|
|
14
|
+
* 5. Optionally decodes the key if the decodeTranscriptKey option is set
|
|
15
|
+
*
|
|
16
|
+
* @param key - The blob key string to sanitize. Must be non-empty.
|
|
17
|
+
* @param options - Optional configuration options.
|
|
18
|
+
* @param options.decodeTranscriptKey - If true, returns the URL-decoded version of the sanitized key.
|
|
19
|
+
* @returns A sanitized blob key that is safe for use with Azure Blob Storage, truncated to 1024 characters.
|
|
20
|
+
*
|
|
21
|
+
* @throws {Error} When the provided key is null, undefined, or an empty string.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // Basic sanitization with encoding
|
|
26
|
+
* const sanitized = sanitizeBlobKey('channel1/conversation2/activity.json');
|
|
27
|
+
* // Returns: 'channel1%2Fconversation2%2Factivity.json'
|
|
28
|
+
*
|
|
29
|
+
* // Sanitization with decoding option
|
|
30
|
+
* const decoded = sanitizeBlobKey('channel1/conversation2/activity.json', { decodeTranscriptKey: true });
|
|
31
|
+
* // Returns: 'channel1/conversation2/activity.json'
|
|
32
|
+
*
|
|
33
|
+
* // Handles empty path segments
|
|
34
|
+
* const withEmptySegments = sanitizeBlobKey('channel1//conversation2///activity.json');
|
|
35
|
+
* // Returns: 'channel1%2Fconversation2%2Factivity.json'
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
4
38
|
export declare function sanitizeBlobKey(key: string, options?: BlobsTranscriptStoreOptions): string;
|
|
39
|
+
/**
|
|
40
|
+
* Performs type casting with optional constructor validation.
|
|
41
|
+
* If a constructor is provided, validates that the value is an instance of that constructor.
|
|
42
|
+
* Otherwise, performs a direct type assertion.
|
|
43
|
+
*
|
|
44
|
+
* @template T - The target type to cast to.
|
|
45
|
+
* @param value - The value to cast.
|
|
46
|
+
* @param ctor - Optional constructor function to validate the value against.
|
|
47
|
+
* @returns The value cast to type T.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* // With constructor validation
|
|
52
|
+
* const dateValue = maybeCast(someValue, Date);
|
|
53
|
+
*
|
|
54
|
+
* // Direct type assertion
|
|
55
|
+
* const stringValue = maybeCast<string>(someValue);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
5
58
|
export declare function maybeCast<T>(value: unknown, ctor?: {
|
|
6
59
|
new (...args: any[]): T;
|
|
7
60
|
}): T;
|
|
@@ -34,7 +87,7 @@ export declare class BlobsTranscriptStore implements TranscriptStore {
|
|
|
34
87
|
* @param blobServiceUri - Optional URI for the blob service.
|
|
35
88
|
* @param tokenCredential - Optional credentials for authenticating with the blob service.
|
|
36
89
|
*/
|
|
37
|
-
constructor(connectionString: string, containerName: string, options?: BlobsTranscriptStoreOptions, blobServiceUri?: string, tokenCredential?: StorageSharedKeyCredential | AnonymousCredential);
|
|
90
|
+
constructor(connectionString: string, containerName: string, options?: BlobsTranscriptStoreOptions, blobServiceUri?: string, tokenCredential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential);
|
|
38
91
|
private _initialize;
|
|
39
92
|
/**
|
|
40
93
|
* Retrieves transcript activities for a specific conversation.
|
|
@@ -82,6 +82,39 @@ function getBlobKey(activity, options) {
|
|
|
82
82
|
.parse(activity);
|
|
83
83
|
return sanitizeBlobKey([activity.channelId, (_a = activity.conversation) === null || _a === void 0 ? void 0 : _a.id, `${formatTicks(timestamp)}-${activity.id}.json`].join('/'), options);
|
|
84
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Sanitizes a blob key for use with Azure Blob Storage.
|
|
87
|
+
*
|
|
88
|
+
* @remarks
|
|
89
|
+
* This function performs the following operations:
|
|
90
|
+
* 1. Validates that the key is not empty
|
|
91
|
+
* 2. Removes empty path segments by splitting on '/' and filtering out empty parts
|
|
92
|
+
* 3. Truncates the sanitized key to 1024 characters maximum
|
|
93
|
+
* 4. URL encodes the key to ensure it's safe for use as a blob name
|
|
94
|
+
* 5. Optionally decodes the key if the decodeTranscriptKey option is set
|
|
95
|
+
*
|
|
96
|
+
* @param key - The blob key string to sanitize. Must be non-empty.
|
|
97
|
+
* @param options - Optional configuration options.
|
|
98
|
+
* @param options.decodeTranscriptKey - If true, returns the URL-decoded version of the sanitized key.
|
|
99
|
+
* @returns A sanitized blob key that is safe for use with Azure Blob Storage, truncated to 1024 characters.
|
|
100
|
+
*
|
|
101
|
+
* @throws {Error} When the provided key is null, undefined, or an empty string.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* // Basic sanitization with encoding
|
|
106
|
+
* const sanitized = sanitizeBlobKey('channel1/conversation2/activity.json');
|
|
107
|
+
* // Returns: 'channel1%2Fconversation2%2Factivity.json'
|
|
108
|
+
*
|
|
109
|
+
* // Sanitization with decoding option
|
|
110
|
+
* const decoded = sanitizeBlobKey('channel1/conversation2/activity.json', { decodeTranscriptKey: true });
|
|
111
|
+
* // Returns: 'channel1/conversation2/activity.json'
|
|
112
|
+
*
|
|
113
|
+
* // Handles empty path segments
|
|
114
|
+
* const withEmptySegments = sanitizeBlobKey('channel1//conversation2///activity.json');
|
|
115
|
+
* // Returns: 'channel1%2Fconversation2%2Factivity.json'
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
85
118
|
function sanitizeBlobKey(key, options) {
|
|
86
119
|
if (!key || key.length === 0) {
|
|
87
120
|
throw new Error('Please provide a non-empty key');
|
|
@@ -95,6 +128,25 @@ function sanitizeBlobKey(key, options) {
|
|
|
95
128
|
}
|
|
96
129
|
return encodedKey;
|
|
97
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Performs type casting with optional constructor validation.
|
|
133
|
+
* If a constructor is provided, validates that the value is an instance of that constructor.
|
|
134
|
+
* Otherwise, performs a direct type assertion.
|
|
135
|
+
*
|
|
136
|
+
* @template T - The target type to cast to.
|
|
137
|
+
* @param value - The value to cast.
|
|
138
|
+
* @param ctor - Optional constructor function to validate the value against.
|
|
139
|
+
* @returns The value cast to type T.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* // With constructor validation
|
|
144
|
+
* const dateValue = maybeCast(someValue, Date);
|
|
145
|
+
*
|
|
146
|
+
* // Direct type assertion
|
|
147
|
+
* const stringValue = maybeCast<string>(someValue);
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
98
150
|
function maybeCast(value, ctor) {
|
|
99
151
|
if (ctor != null && value instanceof ctor) {
|
|
100
152
|
return value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blobsTranscriptStore.js","sourceRoot":"","sources":["../../src/blobsTranscriptStore.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"blobsTranscriptStore.js","sourceRoot":"","sources":["../../src/blobsTranscriptStore.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,0CAeC;AAqBD,8BAMC;AAvID,uCAAwB;AACxB,iEAA8C;AAC9C,gEAAqD;AAErD,sDAO4B;AAG5B;;;;GAIG;AACH,SAAS,WAAW,CAAE,SAAe;IACnC,MAAM,UAAU,GAAG,kBAAkB,CAAA;IACrC,MAAM,mBAAmB,GAAG,KAAK,CAAA;IACjC,MAAM,KAAK,GAAG,UAAU,GAAG,SAAS,CAAC,OAAO,EAAE,GAAG,mBAAmB,CAAA;IACpE,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;AAC3B,CAAC;AAED;;;;GAIG;AACH,SAAS,gBAAgB,CAAE,SAAiB;IAC1C,OAAO,eAAe,CAAC,GAAG,SAAS,GAAG,CAAC,CAAA;AACzC,CAAC;AAED;;;;;GAKG;AACH,SAAS,qBAAqB,CAAE,SAAiB,EAAE,cAAsB;IACvE,OAAO,eAAe,CAAC,GAAG,SAAS,IA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,QAAQ,CAAC,SAAS,EAAE,CAAC;YACvB,QAAQ,CAAC,SAAS,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,CAAA;QAC5D,CAAC;QAED,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;IAChE,CAAC;CACF;AAzPD,oDAyPC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@microsoft/agents-hosting-storage-blob",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.11",
|
|
5
5
|
"homepage": "https://github.com/microsoft/Agents-for-js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"types": "dist/src/index.d.ts",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@azure/storage-blob": "^12.27.0",
|
|
20
|
-
"@microsoft/agents-hosting": "0.
|
|
20
|
+
"@microsoft/agents-hosting": "0.6.11"
|
|
21
21
|
},
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"files": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as z from 'zod'
|
|
2
2
|
import StreamConsumers from 'stream/consumers'
|
|
3
3
|
import { Activity } from '@microsoft/agents-activity'
|
|
4
|
-
|
|
4
|
+
import { TokenCredential } from '@azure/core-auth'
|
|
5
5
|
import {
|
|
6
6
|
AnonymousCredential,
|
|
7
7
|
BlobItem,
|
|
@@ -58,6 +58,39 @@ function getBlobKey (activity: Activity, options?: BlobsTranscriptStoreOptions):
|
|
|
58
58
|
)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Sanitizes a blob key for use with Azure Blob Storage.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* This function performs the following operations:
|
|
66
|
+
* 1. Validates that the key is not empty
|
|
67
|
+
* 2. Removes empty path segments by splitting on '/' and filtering out empty parts
|
|
68
|
+
* 3. Truncates the sanitized key to 1024 characters maximum
|
|
69
|
+
* 4. URL encodes the key to ensure it's safe for use as a blob name
|
|
70
|
+
* 5. Optionally decodes the key if the decodeTranscriptKey option is set
|
|
71
|
+
*
|
|
72
|
+
* @param key - The blob key string to sanitize. Must be non-empty.
|
|
73
|
+
* @param options - Optional configuration options.
|
|
74
|
+
* @param options.decodeTranscriptKey - If true, returns the URL-decoded version of the sanitized key.
|
|
75
|
+
* @returns A sanitized blob key that is safe for use with Azure Blob Storage, truncated to 1024 characters.
|
|
76
|
+
*
|
|
77
|
+
* @throws {Error} When the provided key is null, undefined, or an empty string.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // Basic sanitization with encoding
|
|
82
|
+
* const sanitized = sanitizeBlobKey('channel1/conversation2/activity.json');
|
|
83
|
+
* // Returns: 'channel1%2Fconversation2%2Factivity.json'
|
|
84
|
+
*
|
|
85
|
+
* // Sanitization with decoding option
|
|
86
|
+
* const decoded = sanitizeBlobKey('channel1/conversation2/activity.json', { decodeTranscriptKey: true });
|
|
87
|
+
* // Returns: 'channel1/conversation2/activity.json'
|
|
88
|
+
*
|
|
89
|
+
* // Handles empty path segments
|
|
90
|
+
* const withEmptySegments = sanitizeBlobKey('channel1//conversation2///activity.json');
|
|
91
|
+
* // Returns: 'channel1%2Fconversation2%2Factivity.json'
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
61
94
|
export function sanitizeBlobKey (key: string, options?: BlobsTranscriptStoreOptions): string {
|
|
62
95
|
if (!key || key.length === 0) {
|
|
63
96
|
throw new Error('Please provide a non-empty key')
|
|
@@ -75,6 +108,25 @@ export function sanitizeBlobKey (key: string, options?: BlobsTranscriptStoreOpti
|
|
|
75
108
|
return encodedKey
|
|
76
109
|
}
|
|
77
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Performs type casting with optional constructor validation.
|
|
113
|
+
* If a constructor is provided, validates that the value is an instance of that constructor.
|
|
114
|
+
* Otherwise, performs a direct type assertion.
|
|
115
|
+
*
|
|
116
|
+
* @template T - The target type to cast to.
|
|
117
|
+
* @param value - The value to cast.
|
|
118
|
+
* @param ctor - Optional constructor function to validate the value against.
|
|
119
|
+
* @returns The value cast to type T.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* // With constructor validation
|
|
124
|
+
* const dateValue = maybeCast(someValue, Date);
|
|
125
|
+
*
|
|
126
|
+
* // Direct type assertion
|
|
127
|
+
* const stringValue = maybeCast<string>(someValue);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
78
130
|
export function maybeCast<T> (value: unknown, ctor?: { new (...args: any[]): T }): T {
|
|
79
131
|
if (ctor != null && value instanceof ctor) {
|
|
80
132
|
return value
|
|
@@ -122,7 +174,7 @@ export class BlobsTranscriptStore implements TranscriptStore {
|
|
|
122
174
|
containerName: string,
|
|
123
175
|
options?: BlobsTranscriptStoreOptions,
|
|
124
176
|
blobServiceUri = '',
|
|
125
|
-
tokenCredential?: StorageSharedKeyCredential | AnonymousCredential
|
|
177
|
+
tokenCredential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential
|
|
126
178
|
) {
|
|
127
179
|
if (blobServiceUri !== '' && tokenCredential !== null) {
|
|
128
180
|
z.object({ blobServiceUri: z.string() }).parse({
|