@microsoft/agents-hosting 0.2.14 → 0.4.1
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 +17 -1
- package/dist/src/app/agentApplication.d.ts +27 -15
- package/dist/src/app/agentApplication.js +36 -31
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationBuilder.d.ts +3 -4
- package/dist/src/app/agentApplicationBuilder.js +7 -7
- package/dist/src/app/agentApplicationBuilder.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +26 -2
- package/dist/src/app/appRoute.d.ts +6 -0
- package/dist/src/app/attachmentDownloader.d.ts +18 -0
- package/dist/src/app/attachmentDownloader.js +18 -0
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/conversationUpdateEvents.d.ts +6 -0
- package/dist/src/app/index.d.ts +1 -1
- package/dist/src/app/index.js +1 -1
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/app/inputFileDownloader.d.ts +22 -0
- package/dist/src/app/oauth/authorization.d.ts +87 -0
- package/dist/src/app/oauth/authorization.js +135 -0
- package/dist/src/app/oauth/authorization.js.map +1 -0
- package/dist/src/app/routeHandler.d.ts +8 -0
- package/dist/src/app/routeSelector.d.ts +9 -0
- package/dist/src/app/turnState.d.ts +128 -15
- package/dist/src/app/turnState.js +114 -16
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +24 -0
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/request.d.ts +12 -0
- package/dist/src/baseAdapter.d.ts +17 -0
- package/dist/src/baseAdapter.js +17 -0
- package/dist/src/baseAdapter.js.map +1 -1
- package/dist/src/cards/cardFactory.d.ts +3 -0
- package/dist/src/cards/cardFactory.js +3 -0
- package/dist/src/cards/cardFactory.js.map +1 -1
- package/dist/src/cards/o365ConnectorCardActionBase.d.ts +8 -0
- package/dist/src/oauth/oAuthFlow.d.ts +32 -3
- package/dist/src/oauth/oAuthFlow.js +38 -14
- package/dist/src/oauth/oAuthFlow.js.map +1 -1
- package/dist/src/oauth/userTokenClient.d.ts +2 -2
- package/dist/src/oauth/userTokenClient.js +3 -3
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/state/agentStatePropertyAccesor.d.ts +1 -1
- package/dist/src/state/agentStatePropertyAccesor.js +1 -1
- package/dist/src/statusCodes.d.ts +39 -0
- package/dist/src/statusCodes.js +39 -0
- package/dist/src/statusCodes.js.map +1 -1
- package/dist/src/storage/fileStorage.d.ts +9 -0
- package/dist/src/storage/fileStorage.js +62 -0
- package/dist/src/storage/fileStorage.js.map +1 -0
- package/dist/src/storage/index.d.ts +1 -0
- package/dist/src/storage/index.js +1 -0
- package/dist/src/storage/index.js.map +1 -1
- package/dist/src/tokenResponseEventName.d.ts +3 -0
- package/dist/src/tokenResponseEventName.js +3 -0
- package/dist/src/tokenResponseEventName.js.map +1 -1
- package/package.json +4 -4
- package/src/app/agentApplication.ts +36 -32
- package/src/app/agentApplicationBuilder.ts +8 -8
- package/src/app/agentApplicationOptions.ts +33 -2
- package/src/app/appRoute.ts +7 -0
- package/src/app/attachmentDownloader.ts +18 -0
- package/src/app/conversationUpdateEvents.ts +6 -0
- package/src/app/index.ts +1 -1
- package/src/app/inputFileDownloader.ts +24 -0
- package/src/app/oauth/authorization.ts +162 -0
- package/src/app/routeHandler.ts +8 -0
- package/src/app/routeSelector.ts +9 -0
- package/src/app/turnState.ts +129 -33
- package/src/auth/authConfiguration.ts +32 -1
- package/src/auth/request.ts +15 -0
- package/src/baseAdapter.ts +18 -0
- package/src/cards/cardFactory.ts +3 -0
- package/src/cards/o365ConnectorCardActionBase.ts +8 -0
- package/src/oauth/oAuthFlow.ts +59 -18
- package/src/oauth/userTokenClient.ts +4 -4
- package/src/state/agentStatePropertyAccesor.ts +1 -1
- package/src/statusCodes.ts +51 -0
- package/src/storage/fileStorage.ts +59 -0
- package/src/storage/index.ts +1 -0
- package/src/tokenResponseEventName.ts +3 -0
- package/dist/src/app/oauth/userIdentity.d.ts +0 -43
- package/dist/src/app/oauth/userIdentity.js +0 -54
- package/dist/src/app/oauth/userIdentity.js.map +0 -1
- package/src/app/oauth/userIdentity.ts +0 -78
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import { Storage, StoreItem } from './storage'
|
|
4
|
+
|
|
5
|
+
export class FileStorage implements Storage {
|
|
6
|
+
private _folder: string
|
|
7
|
+
private _stateFile: Record<string, string>
|
|
8
|
+
constructor (folder: string) {
|
|
9
|
+
this._folder = folder
|
|
10
|
+
if (!fs.existsSync(folder)) {
|
|
11
|
+
fs.mkdirSync(folder, { recursive: true })
|
|
12
|
+
}
|
|
13
|
+
if (!fs.existsSync(path.join(folder, 'state.json'))) {
|
|
14
|
+
fs.writeFileSync(path.join(folder, 'state.json'), '{}')
|
|
15
|
+
}
|
|
16
|
+
const data = fs.readFileSync(path.join(folder, 'state.json'), 'utf8')
|
|
17
|
+
this._stateFile = JSON.parse(data)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
read (keys: string[]) : Promise<StoreItem> {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
if (!keys || keys.length === 0) {
|
|
23
|
+
reject(new ReferenceError('Keys are required when reading.'))
|
|
24
|
+
} else {
|
|
25
|
+
const data: StoreItem = {}
|
|
26
|
+
for (const key of keys) {
|
|
27
|
+
const item = this._stateFile[key]
|
|
28
|
+
if (item) {
|
|
29
|
+
data[key] = item
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
resolve(data)
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
write (changes: StoreItem) : Promise<void> {
|
|
38
|
+
const keys = Object.keys(changes)
|
|
39
|
+
for (const key of keys) {
|
|
40
|
+
this._stateFile[key] = changes[key]
|
|
41
|
+
}
|
|
42
|
+
fs.writeFileSync(this._folder + '/state.json', JSON.stringify(this._stateFile, null, 2))
|
|
43
|
+
return Promise.resolve()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
delete (keys: string[]) : Promise<void> {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
if (!keys || keys.length === 0) {
|
|
49
|
+
reject(new ReferenceError('Keys are required when deleting.'))
|
|
50
|
+
} else {
|
|
51
|
+
for (const key of keys) {
|
|
52
|
+
delete this._stateFile[key]
|
|
53
|
+
}
|
|
54
|
+
fs.writeFileSync(this._folder + '/state.json', JSON.stringify(this._stateFile, null, 2))
|
|
55
|
+
}
|
|
56
|
+
resolve()
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/storage/index.ts
CHANGED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { TurnContext } from '../../turnContext';
|
|
6
|
-
import { TurnState } from '../turnState';
|
|
7
|
-
import { Storage } from '../../storage';
|
|
8
|
-
import { OAuthFlow, TokenResponse } from '../../oauth';
|
|
9
|
-
/**
|
|
10
|
-
* Options for configuring user identity.
|
|
11
|
-
* Contains settings related to Single Sign-On (SSO) authentication.
|
|
12
|
-
*/
|
|
13
|
-
export interface UserIdentityOptions {
|
|
14
|
-
/**
|
|
15
|
-
* Determines whether Single Sign-On (SSO) is enabled for user authentication.
|
|
16
|
-
*/
|
|
17
|
-
enableSSO: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* The name of the SSO connection to use when SSO is enabled.
|
|
20
|
-
* Only applicable when enableSSO is set to true.
|
|
21
|
-
*/
|
|
22
|
-
ssoConnectionName?: string;
|
|
23
|
-
}
|
|
24
|
-
export declare class UserIdentity {
|
|
25
|
-
oAuthFlow: OAuthFlow;
|
|
26
|
-
/**
|
|
27
|
-
* Creates a new instance of UserAuthorization.
|
|
28
|
-
* @param {Storage} storage - The storage system to use for state management.
|
|
29
|
-
*/
|
|
30
|
-
constructor(storage: Storage, connectionName: string);
|
|
31
|
-
getToken(context: TurnContext): Promise<TokenResponse>;
|
|
32
|
-
authenticate(context: TurnContext, state: TurnState): Promise<TokenResponse>;
|
|
33
|
-
/**
|
|
34
|
-
* Signs out the current user.
|
|
35
|
-
* This method clears the user's token and resets the SSO state.
|
|
36
|
-
*
|
|
37
|
-
* @param {TurnContext} context - The context object for the current turn.
|
|
38
|
-
* @param {TurnState} state - The state object for the current turn.
|
|
39
|
-
*/
|
|
40
|
-
signOut(context: TurnContext, state: TurnState): Promise<void>;
|
|
41
|
-
_signInHandler: ((context: TurnContext, state: TurnState) => void) | null;
|
|
42
|
-
onSignInSuccess(handler: (context: TurnContext, state: TurnState) => void): void;
|
|
43
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.UserIdentity = void 0;
|
|
8
|
-
const oauth_1 = require("../../oauth");
|
|
9
|
-
const state_1 = require("../../state");
|
|
10
|
-
class UserIdentity {
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new instance of UserAuthorization.
|
|
13
|
-
* @param {Storage} storage - The storage system to use for state management.
|
|
14
|
-
*/
|
|
15
|
-
constructor(storage, connectionName) {
|
|
16
|
-
this._signInHandler = null;
|
|
17
|
-
const userState = new state_1.UserState(storage);
|
|
18
|
-
this.oAuthFlow = new oauth_1.OAuthFlow(userState, connectionName);
|
|
19
|
-
}
|
|
20
|
-
async getToken(context) {
|
|
21
|
-
return await this.oAuthFlow.getUserToken(context);
|
|
22
|
-
}
|
|
23
|
-
async authenticate(context, state) {
|
|
24
|
-
var _a;
|
|
25
|
-
let tokenResponse;
|
|
26
|
-
if (((_a = this.oAuthFlow.state) === null || _a === void 0 ? void 0 : _a.flowStarted) === false) {
|
|
27
|
-
tokenResponse = await this.oAuthFlow.beginFlow(context);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
tokenResponse = await this.oAuthFlow.continueFlow(context);
|
|
31
|
-
if (tokenResponse.status === oauth_1.TokenRequestStatus.Success) {
|
|
32
|
-
if (this._signInHandler) {
|
|
33
|
-
await this._signInHandler(context, state);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return tokenResponse;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Signs out the current user.
|
|
41
|
-
* This method clears the user's token and resets the SSO state.
|
|
42
|
-
*
|
|
43
|
-
* @param {TurnContext} context - The context object for the current turn.
|
|
44
|
-
* @param {TurnState} state - The state object for the current turn.
|
|
45
|
-
*/
|
|
46
|
-
async signOut(context, state) {
|
|
47
|
-
await this.oAuthFlow.signOut(context);
|
|
48
|
-
}
|
|
49
|
-
onSignInSuccess(handler) {
|
|
50
|
-
this._signInHandler = handler;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.UserIdentity = UserIdentity;
|
|
54
|
-
//# sourceMappingURL=userIdentity.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"userIdentity.js","sourceRoot":"","sources":["../../../../src/app/oauth/userIdentity.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAMH,uCAA0E;AAC1E,uCAAuC;AAqBvC,MAAa,YAAY;IAGvB;;;OAGG;IACH,YAAa,OAAgB,EAAE,cAAsB;QAmCrD,mBAAc,GAA8D,IAAI,CAAA;QAlC9E,MAAM,SAAS,GAAG,IAAI,iBAAS,CAAC,OAAO,CAAC,CAAA;QACxC,IAAI,CAAC,SAAS,GAAG,IAAI,iBAAS,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;IAC3D,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAE,OAAoB;QACzC,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;IACnD,CAAC;IAEM,KAAK,CAAC,YAAY,CAAE,OAAoB,EAAE,KAAgB;;QAC/D,IAAI,aAA4B,CAAA;QAChC,IAAI,CAAA,MAAA,IAAI,CAAC,SAAS,CAAC,KAAK,0CAAE,WAAW,MAAK,KAAK,EAAE,CAAC;YAChD,aAAa,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;QACzD,CAAC;aAAM,CAAC;YACN,aAAa,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;YAC1D,IAAI,aAAa,CAAC,MAAM,KAAK,0BAAkB,CAAC,OAAO,EAAE,CAAC;gBACxD,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;oBACxB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;gBAC3C,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,aAAa,CAAA;IACtB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,CAAE,OAAoB,EAAE,KAAgB;QACnD,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;IAGM,eAAe,CAAE,OAAyD;QAC/E,IAAI,CAAC,cAAc,GAAG,OAAO,CAAA;IAC/B,CAAC;CACF;AA9CD,oCA8CC"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { TurnContext } from '../../turnContext'
|
|
7
|
-
// import { debug } from '../../logger'
|
|
8
|
-
import { TurnState } from '../turnState'
|
|
9
|
-
import { Storage } from '../../storage'
|
|
10
|
-
import { OAuthFlow, TokenRequestStatus, TokenResponse } from '../../oauth'
|
|
11
|
-
import { UserState } from '../../state'
|
|
12
|
-
|
|
13
|
-
// const logger = debug('agents:user-identity')
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Options for configuring user identity.
|
|
17
|
-
* Contains settings related to Single Sign-On (SSO) authentication.
|
|
18
|
-
*/
|
|
19
|
-
export interface UserIdentityOptions {
|
|
20
|
-
/**
|
|
21
|
-
* Determines whether Single Sign-On (SSO) is enabled for user authentication.
|
|
22
|
-
*/
|
|
23
|
-
enableSSO: boolean;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The name of the SSO connection to use when SSO is enabled.
|
|
27
|
-
* Only applicable when enableSSO is set to true.
|
|
28
|
-
*/
|
|
29
|
-
ssoConnectionName?: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export class UserIdentity {
|
|
33
|
-
oAuthFlow: OAuthFlow
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Creates a new instance of UserAuthorization.
|
|
37
|
-
* @param {Storage} storage - The storage system to use for state management.
|
|
38
|
-
*/
|
|
39
|
-
constructor (storage: Storage, connectionName: string) {
|
|
40
|
-
const userState = new UserState(storage)
|
|
41
|
-
this.oAuthFlow = new OAuthFlow(userState, connectionName)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public async getToken (context: TurnContext): Promise<TokenResponse> {
|
|
45
|
-
return await this.oAuthFlow.getUserToken(context)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public async authenticate (context: TurnContext, state: TurnState) : Promise<TokenResponse> {
|
|
49
|
-
let tokenResponse: TokenResponse
|
|
50
|
-
if (this.oAuthFlow.state?.flowStarted === false) {
|
|
51
|
-
tokenResponse = await this.oAuthFlow.beginFlow(context)
|
|
52
|
-
} else {
|
|
53
|
-
tokenResponse = await this.oAuthFlow.continueFlow(context)
|
|
54
|
-
if (tokenResponse.status === TokenRequestStatus.Success) {
|
|
55
|
-
if (this._signInHandler) {
|
|
56
|
-
await this._signInHandler(context, state)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return tokenResponse
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Signs out the current user.
|
|
65
|
-
* This method clears the user's token and resets the SSO state.
|
|
66
|
-
*
|
|
67
|
-
* @param {TurnContext} context - The context object for the current turn.
|
|
68
|
-
* @param {TurnState} state - The state object for the current turn.
|
|
69
|
-
*/
|
|
70
|
-
async signOut (context: TurnContext, state: TurnState) {
|
|
71
|
-
await this.oAuthFlow.signOut(context)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
_signInHandler: ((context: TurnContext, state: TurnState) => void) | null = null
|
|
75
|
-
public onSignInSuccess (handler: (context: TurnContext, state: TurnState) => void) {
|
|
76
|
-
this._signInHandler = handler
|
|
77
|
-
}
|
|
78
|
-
}
|