@microsoft/agents-hosting-express 1.9.0-beta.8.gf58e66b2ee → 1.9.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 +5 -1
- package/dist/package.json +3 -3
- package/dist/src/createAgentRequestHandler.d.ts +6 -1
- package/dist/src/createAgentRequestHandler.js +9 -3
- package/dist/src/createAgentRequestHandler.js.map +1 -1
- package/dist/src/createCloudAdapter.d.ts +1 -1
- package/dist/src/createCloudAdapter.js.map +1 -1
- package/dist/src/startServer.d.ts +2 -1
- package/dist/src/startServer.js +10 -6
- package/dist/src/startServer.js.map +1 -1
- package/package.json +3 -3
- package/src/createAgentRequestHandler.ts +21 -5
- package/src/createCloudAdapter.ts +1 -1
- package/src/startServer.ts +20 -7
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @microsoft/agents-hosting-express
|
|
1
|
+
# @microsoft/agents-hosting-express
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
@@ -50,6 +50,10 @@ startServer(agent, {
|
|
|
50
50
|
|
|
51
51
|
If you manage your own Express app (or another framework with an adapter that exposes Express-compatible request/response objects), use `createAgentRequestHandler` to get a handler that includes JWT authorization and activity processing:
|
|
52
52
|
|
|
53
|
+
The handler resolves its explicit or environment authentication independently
|
|
54
|
+
from activity processing. An `AgentApplication`'s existing adapter is reused,
|
|
55
|
+
preserving its middleware, connection state, runtime policies, and identity.
|
|
56
|
+
|
|
53
57
|
```ts
|
|
54
58
|
import express from 'express';
|
|
55
59
|
import { AgentApplication, TurnState } from '@microsoft/agents-hosting';
|
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@microsoft/agents-hosting-express",
|
|
4
|
-
"version": "1.9.
|
|
4
|
+
"version": "1.9.1",
|
|
5
5
|
"homepage": "https://github.com/microsoft/Agents-for-js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"main": "dist/src/index.js",
|
|
20
20
|
"types": "dist/src/index.d.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@microsoft/agents-hosting": "1.9.
|
|
23
|
-
"@microsoft/agents-telemetry": "1.9.
|
|
22
|
+
"@microsoft/agents-hosting": "1.9.1",
|
|
23
|
+
"@microsoft/agents-telemetry": "1.9.1",
|
|
24
24
|
"express": "5.2.1",
|
|
25
25
|
"express-rate-limit": "8.6.2"
|
|
26
26
|
},
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { ActivityHandler, AgentApplication, AuthConfiguration, WebResponse, Request, TurnState } from '@microsoft/agents-hosting';
|
|
6
|
+
import { type CreateCloudAdapterOptions } from './createCloudAdapter';
|
|
6
7
|
/**
|
|
7
8
|
* Re-export of `WebResponse` from `@microsoft/agents-hosting` for backward compatibility.
|
|
8
9
|
* New code should import `WebResponse` directly from `@microsoft/agents-hosting`.
|
|
@@ -29,6 +30,10 @@ export type AgentRequestHandler = (req: Request, res: WebResponse) => Promise<vo
|
|
|
29
30
|
* @param agent - The AgentApplication or ActivityHandler instance to process incoming activities.
|
|
30
31
|
* @param authConfiguration - Optional custom authentication configuration. If not provided,
|
|
31
32
|
* configuration will be loaded from environment variables using loadAuthConfigFromEnv().
|
|
33
|
+
* @param options - Optional additional settings, such as a host-scoped `ConfigurationContext`.
|
|
34
|
+
* For an `AgentApplication`, this defaults to its own `configurationContext` option when omitted;
|
|
35
|
+
* a plain `ActivityHandler` has no built-in context and must be supplied here to participate in
|
|
36
|
+
* host-scoped configuration.
|
|
32
37
|
* @returns A request handler function `(req, res) => Promise<void>`.
|
|
33
38
|
*
|
|
34
39
|
* @example
|
|
@@ -47,4 +52,4 @@ export type AgentRequestHandler = (req: Request, res: WebResponse) => Promise<vo
|
|
|
47
52
|
* app.listen(3978);
|
|
48
53
|
* ```
|
|
49
54
|
*/
|
|
50
|
-
export declare const createAgentRequestHandler: (agent: AgentApplication<TurnState<any, any>> | ActivityHandler, authConfiguration?: AuthConfiguration) => AgentRequestHandler;
|
|
55
|
+
export declare const createAgentRequestHandler: (agent: AgentApplication<TurnState<any, any>> | ActivityHandler, authConfiguration?: AuthConfiguration, options?: CreateCloudAdapterOptions) => AgentRequestHandler;
|
|
@@ -20,6 +20,10 @@ const createCloudAdapter_1 = require("./createCloudAdapter");
|
|
|
20
20
|
* @param agent - The AgentApplication or ActivityHandler instance to process incoming activities.
|
|
21
21
|
* @param authConfiguration - Optional custom authentication configuration. If not provided,
|
|
22
22
|
* configuration will be loaded from environment variables using loadAuthConfigFromEnv().
|
|
23
|
+
* @param options - Optional additional settings, such as a host-scoped `ConfigurationContext`.
|
|
24
|
+
* For an `AgentApplication`, this defaults to its own `configurationContext` option when omitted;
|
|
25
|
+
* a plain `ActivityHandler` has no built-in context and must be supplied here to participate in
|
|
26
|
+
* host-scoped configuration.
|
|
23
27
|
* @returns A request handler function `(req, res) => Promise<void>`.
|
|
24
28
|
*
|
|
25
29
|
* @example
|
|
@@ -38,10 +42,12 @@ const createCloudAdapter_1 = require("./createCloudAdapter");
|
|
|
38
42
|
* app.listen(3978);
|
|
39
43
|
* ```
|
|
40
44
|
*/
|
|
41
|
-
const createAgentRequestHandler = (agent, authConfiguration) => {
|
|
42
|
-
|
|
43
|
-
const
|
|
45
|
+
const createAgentRequestHandler = (agent, authConfiguration, options) => {
|
|
46
|
+
var _a;
|
|
47
|
+
const configurationContext = (_a = options === null || options === void 0 ? void 0 : options.configurationContext) !== null && _a !== void 0 ? _a : (agent instanceof agents_hosting_1.AgentApplication ? agent.options.configurationContext : undefined);
|
|
48
|
+
const authConfig = (0, agents_hosting_1.getAuthConfigWithDefaults)(authConfiguration, { configurationContext });
|
|
44
49
|
const jwtMiddleware = (0, agents_hosting_1.authorizeJWT)(authConfig);
|
|
50
|
+
const { adapter, headerPropagation } = (0, createCloudAdapter_1.createCloudAdapter)(agent, authConfig, options);
|
|
45
51
|
return async (req, res) => {
|
|
46
52
|
let middlewareError;
|
|
47
53
|
let nextCalled = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAgentRequestHandler.js","sourceRoot":"","sources":["../../src/createAgentRequestHandler.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,
|
|
1
|
+
{"version":3,"file":"createAgentRequestHandler.js","sourceRoot":"","sources":["../../src/createAgentRequestHandler.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,8DASkC;AAClC,6DAAyF;AA8BzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACI,MAAM,yBAAyB,GAAG,CACvC,KAA8D,EAC9D,iBAAqC,EACrC,OAAmC,EACd,EAAE;;IACvB,MAAM,oBAAoB,SAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,mCACxD,CAAC,KAAK,YAAY,iCAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACtF,MAAM,UAAU,GAAG,IAAA,0CAAyB,EAAC,iBAAiB,EAAE,EAAE,oBAAoB,EAAE,CAAC,CAAA;IACzF,MAAM,aAAa,GAAG,IAAA,6BAAY,EAAC,UAAU,CAAC,CAAA;IAC9C,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,GAAG,IAAA,uCAAkB,EAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;IAErF,OAAO,KAAK,EAAE,GAAY,EAAE,GAAgB,EAAiB,EAAE;QAC7D,IAAI,eAAoB,CAAA;QACxB,IAAI,UAAU,GAAG,KAAK,CAAA;QAEtB,MAAM,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAS,EAAE,EAAE;YAC1C,UAAU,GAAG,IAAI,CAAA;YACjB,eAAe,GAAG,GAAG,CAAA;QACvB,CAAC,CAAC,CAAA;QAEF,IAAI,eAAe,EAAE,CAAC;YACpB,MAAM,eAAe,CAAA;QACvB,CAAC;QAED,uGAAuG;QACvG,IAAI,CAAC,UAAU,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC;YACnC,OAAM;QACR,CAAC;QAED,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAA;IACrF,CAAC,CAAA;AACH,CAAC,CAAA;AA/BY,QAAA,yBAAyB,GAAzB,yBAAyB,CA+BrC"}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* `createCloudAdapter` was moved into core so it can be reused by Fastify and
|
|
7
7
|
* other hosting integrations without dragging the Express runtime along.
|
|
8
8
|
*/
|
|
9
|
-
export { createCloudAdapter, type CloudAdapterResult } from '@microsoft/agents-hosting';
|
|
9
|
+
export { createCloudAdapter, type CloudAdapterResult, type CreateCloudAdapterOptions } from '@microsoft/agents-hosting';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCloudAdapter.js","sourceRoot":"","sources":["../../src/createCloudAdapter.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,
|
|
1
|
+
{"version":3,"file":"createCloudAdapter.js","sourceRoot":"","sources":["../../src/createCloudAdapter.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,4DAAuH;AAA9G,oHAAA,kBAAkB,OAAA"}
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import express from 'express';
|
|
6
6
|
import { ActivityHandler, AgentApplication, AuthConfiguration, TurnState } from '@microsoft/agents-hosting';
|
|
7
|
+
import { type CreateCloudAdapterOptions } from './createCloudAdapter';
|
|
7
8
|
/**
|
|
8
9
|
* Options for configuring the Express server started by `startServer`.
|
|
9
10
|
*/
|
|
10
|
-
export interface StartServerOptions {
|
|
11
|
+
export interface StartServerOptions extends CreateCloudAdapterOptions {
|
|
11
12
|
/**
|
|
12
13
|
* Optional custom authentication configuration.
|
|
13
14
|
* If not provided, configuration will be loaded from environment variables using loadAuthConfigFromEnv().
|
package/dist/src/startServer.js
CHANGED
|
@@ -16,24 +16,28 @@ const agents_telemetry_1 = require("@microsoft/agents-telemetry");
|
|
|
16
16
|
const createCloudAdapter_1 = require("./createCloudAdapter");
|
|
17
17
|
const logger = (0, agents_telemetry_1.debug)('agents:hosting-express');
|
|
18
18
|
function startServer(agent, optionsOrAuth) {
|
|
19
|
-
var _a, _b, _c;
|
|
19
|
+
var _a, _b, _c, _d;
|
|
20
20
|
const isOptions = typeof optionsOrAuth === 'object' && optionsOrAuth !== null &&
|
|
21
|
-
('authConfig' in optionsOrAuth || 'port' in optionsOrAuth || 'routePath' in optionsOrAuth ||
|
|
21
|
+
('authConfig' in optionsOrAuth || 'port' in optionsOrAuth || 'routePath' in optionsOrAuth ||
|
|
22
|
+
'rateLimitOptions' in optionsOrAuth || 'beforeListen' in optionsOrAuth || 'configurationContext' in optionsOrAuth);
|
|
22
23
|
// Legacy overload: the second argument is a raw AuthConfiguration. An empty object carries no auth
|
|
23
24
|
// settings, so treat it like no argument and load defaults from the environment (matching startServer(agent)).
|
|
24
25
|
const hasAuthSettings = !isOptions && optionsOrAuth != null && Object.keys(optionsOrAuth).length > 0;
|
|
25
26
|
const opts = isOptions
|
|
26
27
|
? optionsOrAuth
|
|
27
28
|
: { authConfig: hasAuthSettings ? optionsOrAuth : undefined };
|
|
28
|
-
const authConfig = (0, agents_hosting_1.getAuthConfigWithDefaults)(opts.authConfig);
|
|
29
29
|
const routePath = (_a = opts.routePath) !== null && _a !== void 0 ? _a : '/api/messages';
|
|
30
|
-
const
|
|
30
|
+
const configurationContext = (_b = opts.configurationContext) !== null && _b !== void 0 ? _b : (agent instanceof agents_hosting_1.AgentApplication ? agent.options.configurationContext : undefined);
|
|
31
|
+
const authConfig = (0, agents_hosting_1.getAuthConfigWithDefaults)(opts.authConfig, { configurationContext });
|
|
32
|
+
const { adapter, headerPropagation } = (0, createCloudAdapter_1.createCloudAdapter)(agent, authConfig, { configurationContext: opts.configurationContext });
|
|
31
33
|
const server = (0, express_1.default)();
|
|
32
34
|
server.use(express_1.default.json());
|
|
33
35
|
if (opts.beforeListen && typeof opts.beforeListen === 'function') {
|
|
34
36
|
opts.beforeListen(server);
|
|
35
37
|
}
|
|
36
|
-
const middlewares = [
|
|
38
|
+
const middlewares = [
|
|
39
|
+
(0, agents_hosting_1.authorizeJWT)(authConfig)
|
|
40
|
+
];
|
|
37
41
|
if (opts.rateLimitOptions) {
|
|
38
42
|
const messagesRateLimiter = (0, express_rate_limit_1.default)({
|
|
39
43
|
windowMs: opts.rateLimitOptions.windowMs,
|
|
@@ -44,7 +48,7 @@ function startServer(agent, optionsOrAuth) {
|
|
|
44
48
|
middlewares.unshift(messagesRateLimiter);
|
|
45
49
|
}
|
|
46
50
|
server.post(routePath, ...middlewares, (req, res) => adapter.process(req, res, (context) => agent.run(context), headerPropagation));
|
|
47
|
-
const port = (
|
|
51
|
+
const port = (_d = (_c = opts.port) !== null && _c !== void 0 ? _c : process.env.PORT) !== null && _d !== void 0 ? _d : 3978;
|
|
48
52
|
const className = (obj) => { var _a; var _b; return (_b = (_a = obj === null || obj === void 0 ? void 0 : obj.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : (obj ? 'custom' : undefined); };
|
|
49
53
|
logger.info('Express server settings loaded', {
|
|
50
54
|
messageEndpoint: `POST ${routePath}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"startServer.js","sourceRoot":"","sources":["../../src/startServer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,sDAA2C;AAC3C,4EAA0C;AAC1C,
|
|
1
|
+
{"version":3,"file":"startServer.js","sourceRoot":"","sources":["../../src/startServer.ts"],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C,SAAS,CAAC,GAAA,CAAA;IACtF,MAAM,CAAC,IAAI,CAAC,gCAAgC,EAAE;QAC5C,eAAe,EAAE,QAAQ,SAAS,EAAE;QACpC,IAAI,EAAE;YACJ,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SACrE;QACD,WAAW,EAAE,CAAC,cAAc,EAAE,cAAc,CAAC;QAC7C,OAAO,EAAE;YACP,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC;YAC7B,MAAM,EAAE,KAAK,YAAY,gCAAe,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe;SACzF;QACD,iBAAiB,EAAE,iBAAiB,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU;KAC5E,CAAC,CAAA;IACF,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;QAC7B,OAAO,CAAC,GAAG,CAAC,8BAA8B,IAAI,WAAW,sBAAO,cAAc,UAAU,CAAC,QAAQ,UAAU,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAA;IACjI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IAC7B,OAAO,MAAM,CAAA;AACf,CAAC"}
|
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-express",
|
|
4
|
-
"version": "1.9.
|
|
4
|
+
"version": "1.9.1",
|
|
5
5
|
"homepage": "https://github.com/microsoft/Agents-for-js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"main": "dist/src/index.js",
|
|
20
20
|
"types": "dist/src/index.d.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@microsoft/agents-hosting": "1.9.
|
|
23
|
-
"@microsoft/agents-telemetry": "1.9.
|
|
22
|
+
"@microsoft/agents-hosting": "1.9.1",
|
|
23
|
+
"@microsoft/agents-telemetry": "1.9.1",
|
|
24
24
|
"express": "5.2.1",
|
|
25
25
|
"express-rate-limit": "8.6.2"
|
|
26
26
|
},
|
|
@@ -4,8 +4,17 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { type Response as ExpressResponse } from 'express'
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
ActivityHandler,
|
|
9
|
+
AgentApplication,
|
|
10
|
+
AuthConfiguration,
|
|
11
|
+
authorizeJWT,
|
|
12
|
+
getAuthConfigWithDefaults,
|
|
13
|
+
WebResponse,
|
|
14
|
+
Request,
|
|
15
|
+
TurnState
|
|
16
|
+
} from '@microsoft/agents-hosting'
|
|
17
|
+
import { createCloudAdapter, type CreateCloudAdapterOptions } from './createCloudAdapter'
|
|
9
18
|
|
|
10
19
|
/**
|
|
11
20
|
* Compile-time contract guard — no runtime effect; type-checked by `npm run build`.
|
|
@@ -48,6 +57,10 @@ export type AgentRequestHandler = (req: Request, res: WebResponse) => Promise<vo
|
|
|
48
57
|
* @param agent - The AgentApplication or ActivityHandler instance to process incoming activities.
|
|
49
58
|
* @param authConfiguration - Optional custom authentication configuration. If not provided,
|
|
50
59
|
* configuration will be loaded from environment variables using loadAuthConfigFromEnv().
|
|
60
|
+
* @param options - Optional additional settings, such as a host-scoped `ConfigurationContext`.
|
|
61
|
+
* For an `AgentApplication`, this defaults to its own `configurationContext` option when omitted;
|
|
62
|
+
* a plain `ActivityHandler` has no built-in context and must be supplied here to participate in
|
|
63
|
+
* host-scoped configuration.
|
|
51
64
|
* @returns A request handler function `(req, res) => Promise<void>`.
|
|
52
65
|
*
|
|
53
66
|
* @example
|
|
@@ -68,11 +81,14 @@ export type AgentRequestHandler = (req: Request, res: WebResponse) => Promise<vo
|
|
|
68
81
|
*/
|
|
69
82
|
export const createAgentRequestHandler = (
|
|
70
83
|
agent: AgentApplication<TurnState<any, any>> | ActivityHandler,
|
|
71
|
-
authConfiguration?: AuthConfiguration
|
|
84
|
+
authConfiguration?: AuthConfiguration,
|
|
85
|
+
options?: CreateCloudAdapterOptions
|
|
72
86
|
): AgentRequestHandler => {
|
|
73
|
-
const
|
|
74
|
-
|
|
87
|
+
const configurationContext = options?.configurationContext ??
|
|
88
|
+
(agent instanceof AgentApplication ? agent.options.configurationContext : undefined)
|
|
89
|
+
const authConfig = getAuthConfigWithDefaults(authConfiguration, { configurationContext })
|
|
75
90
|
const jwtMiddleware = authorizeJWT(authConfig)
|
|
91
|
+
const { adapter, headerPropagation } = createCloudAdapter(agent, authConfig, options)
|
|
76
92
|
|
|
77
93
|
return async (req: Request, res: WebResponse): Promise<void> => {
|
|
78
94
|
let middlewareError: any
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* other hosting integrations without dragging the Express runtime along.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
export { createCloudAdapter, type CloudAdapterResult } from '@microsoft/agents-hosting'
|
|
10
|
+
export { createCloudAdapter, type CloudAdapterResult, type CreateCloudAdapterOptions } from '@microsoft/agents-hosting'
|
package/src/startServer.ts
CHANGED
|
@@ -5,17 +5,25 @@
|
|
|
5
5
|
|
|
6
6
|
import express, { Response } from 'express'
|
|
7
7
|
import rateLimit from 'express-rate-limit'
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
ActivityHandler,
|
|
10
|
+
AgentApplication,
|
|
11
|
+
AuthConfiguration,
|
|
12
|
+
authorizeJWT,
|
|
13
|
+
getAuthConfigWithDefaults,
|
|
14
|
+
Request,
|
|
15
|
+
TurnState
|
|
16
|
+
} from '@microsoft/agents-hosting'
|
|
9
17
|
import { version } from '@microsoft/agents-hosting/package.json'
|
|
10
18
|
import { debug } from '@microsoft/agents-telemetry'
|
|
11
|
-
import { createCloudAdapter } from './createCloudAdapter'
|
|
19
|
+
import { createCloudAdapter, type CreateCloudAdapterOptions } from './createCloudAdapter'
|
|
12
20
|
|
|
13
21
|
const logger = debug('agents:hosting-express')
|
|
14
22
|
|
|
15
23
|
/**
|
|
16
24
|
* Options for configuring the Express server started by `startServer`.
|
|
17
25
|
*/
|
|
18
|
-
export interface StartServerOptions {
|
|
26
|
+
export interface StartServerOptions extends CreateCloudAdapterOptions {
|
|
19
27
|
/**
|
|
20
28
|
* Optional custom authentication configuration.
|
|
21
29
|
* If not provided, configuration will be loaded from environment variables using loadAuthConfigFromEnv().
|
|
@@ -111,7 +119,8 @@ export function startServer (agent: AgentApplication<TurnState<any, any>> | Acti
|
|
|
111
119
|
export function startServer (agent: AgentApplication<TurnState<any, any>> | ActivityHandler, authConfiguration?: AuthConfiguration): express.Express
|
|
112
120
|
export function startServer (agent: AgentApplication<TurnState<any, any>> | ActivityHandler, optionsOrAuth?: StartServerOptions | AuthConfiguration): express.Express {
|
|
113
121
|
const isOptions = typeof optionsOrAuth === 'object' && optionsOrAuth !== null &&
|
|
114
|
-
('authConfig' in optionsOrAuth || 'port' in optionsOrAuth || 'routePath' in optionsOrAuth ||
|
|
122
|
+
('authConfig' in optionsOrAuth || 'port' in optionsOrAuth || 'routePath' in optionsOrAuth ||
|
|
123
|
+
'rateLimitOptions' in optionsOrAuth || 'beforeListen' in optionsOrAuth || 'configurationContext' in optionsOrAuth)
|
|
115
124
|
|
|
116
125
|
// Legacy overload: the second argument is a raw AuthConfiguration. An empty object carries no auth
|
|
117
126
|
// settings, so treat it like no argument and load defaults from the environment (matching startServer(agent)).
|
|
@@ -119,9 +128,11 @@ export function startServer (agent: AgentApplication<TurnState<any, any>> | Acti
|
|
|
119
128
|
const opts: StartServerOptions = isOptions
|
|
120
129
|
? optionsOrAuth as StartServerOptions
|
|
121
130
|
: { authConfig: hasAuthSettings ? optionsOrAuth as AuthConfiguration : undefined }
|
|
122
|
-
const authConfig: AuthConfiguration = getAuthConfigWithDefaults(opts.authConfig)
|
|
123
131
|
const routePath = opts.routePath ?? '/api/messages'
|
|
124
|
-
const
|
|
132
|
+
const configurationContext = opts.configurationContext ??
|
|
133
|
+
(agent instanceof AgentApplication ? agent.options.configurationContext : undefined)
|
|
134
|
+
const authConfig = getAuthConfigWithDefaults(opts.authConfig, { configurationContext })
|
|
135
|
+
const { adapter, headerPropagation } = createCloudAdapter(agent, authConfig, { configurationContext: opts.configurationContext })
|
|
125
136
|
|
|
126
137
|
const server = express()
|
|
127
138
|
server.use(express.json())
|
|
@@ -130,7 +141,9 @@ export function startServer (agent: AgentApplication<TurnState<any, any>> | Acti
|
|
|
130
141
|
opts.beforeListen(server)
|
|
131
142
|
}
|
|
132
143
|
|
|
133
|
-
const middlewares: express.RequestHandler[] = [
|
|
144
|
+
const middlewares: express.RequestHandler[] = [
|
|
145
|
+
authorizeJWT(authConfig)
|
|
146
|
+
]
|
|
134
147
|
if (opts.rateLimitOptions) {
|
|
135
148
|
const messagesRateLimiter = rateLimit({
|
|
136
149
|
windowMs: opts.rateLimitOptions.windowMs,
|