@microsoft/agents-hosting 1.5.0-beta.6.ga236d9a19c → 1.5.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/dist/package.json +10 -9
- package/dist/src/activityHandler.js +2 -2
- package/dist/src/activityHandler.js.map +1 -1
- package/dist/src/agent-client/agentClient.js +49 -40
- package/dist/src/agent-client/agentClient.js.map +1 -1
- package/dist/src/agent-client/agentResponseHandler.js +2 -2
- package/dist/src/agent-client/agentResponseHandler.js.map +1 -1
- package/dist/src/app/agentApplication.d.ts +36 -10
- package/dist/src/app/agentApplication.js +169 -99
- package/dist/src/app/agentApplication.js.map +1 -1
- package/dist/src/app/agentApplicationBuilder.d.ts +15 -0
- package/dist/src/app/agentApplicationBuilder.js +22 -4
- package/dist/src/app/agentApplicationBuilder.js.map +1 -1
- package/dist/src/app/agentApplicationOptions.d.ts +38 -0
- package/dist/src/app/attachmentDownloader.js +2 -2
- package/dist/src/app/attachmentDownloader.js.map +1 -1
- package/dist/src/app/auth/authorization.js +12 -9
- package/dist/src/app/auth/authorization.js.map +1 -1
- package/dist/src/app/auth/authorizationManager.d.ts +18 -5
- package/dist/src/app/auth/authorizationManager.js +258 -45
- package/dist/src/app/auth/authorizationManager.js.map +1 -1
- package/dist/src/app/auth/handlerStorage.js +3 -1
- package/dist/src/app/auth/handlerStorage.js.map +1 -1
- package/dist/src/app/auth/handlers/agenticAuthorization.d.ts +19 -16
- package/dist/src/app/auth/handlers/agenticAuthorization.js +46 -52
- package/dist/src/app/auth/handlers/agenticAuthorization.js.map +1 -1
- package/dist/src/app/auth/handlers/azureBotAuthorization.d.ts +51 -75
- package/dist/src/app/auth/handlers/azureBotAuthorization.js +217 -192
- package/dist/src/app/auth/handlers/azureBotAuthorization.js.map +1 -1
- package/dist/src/app/auth/types.d.ts +100 -1
- package/dist/src/app/auth/utils.d.ts +10 -0
- package/dist/src/app/auth/utils.js +21 -0
- package/dist/src/app/auth/utils.js.map +1 -0
- package/dist/src/app/index.d.ts +1 -0
- package/dist/src/app/index.js +1 -0
- package/dist/src/app/index.js.map +1 -1
- package/dist/src/app/proactive/conversation.d.ts +43 -0
- package/dist/src/app/proactive/conversation.js +67 -0
- package/dist/src/app/proactive/conversation.js.map +1 -0
- package/dist/src/app/proactive/conversationBuilder.d.ts +54 -0
- package/dist/src/app/proactive/conversationBuilder.js +110 -0
- package/dist/src/app/proactive/conversationBuilder.js.map +1 -0
- package/dist/src/app/proactive/conversationReferenceBuilder.d.ts +68 -0
- package/dist/src/app/proactive/conversationReferenceBuilder.js +125 -0
- package/dist/src/app/proactive/conversationReferenceBuilder.js.map +1 -0
- package/dist/src/app/proactive/createConversationOptions.d.ts +30 -0
- package/dist/src/app/proactive/createConversationOptions.js +10 -0
- package/dist/src/app/proactive/createConversationOptions.js.map +1 -0
- package/dist/src/app/proactive/createConversationOptionsBuilder.d.ts +69 -0
- package/dist/src/app/proactive/createConversationOptionsBuilder.js +141 -0
- package/dist/src/app/proactive/createConversationOptionsBuilder.js.map +1 -0
- package/dist/src/app/proactive/index.d.ts +7 -0
- package/dist/src/app/proactive/index.js +26 -0
- package/dist/src/app/proactive/index.js.map +1 -0
- package/dist/src/app/proactive/proactive.d.ts +248 -0
- package/dist/src/app/proactive/proactive.js +310 -0
- package/dist/src/app/proactive/proactive.js.map +1 -0
- package/dist/src/app/proactive/proactiveOptions.d.ts +19 -0
- package/dist/src/app/proactive/proactiveOptions.js +5 -0
- package/dist/src/app/proactive/proactiveOptions.js.map +1 -0
- package/dist/src/app/streaming/streamingResponse.js +2 -2
- package/dist/src/app/streaming/streamingResponse.js.map +1 -1
- package/dist/src/app/teamsAttachmentDownloader.js +2 -2
- package/dist/src/app/teamsAttachmentDownloader.js.map +1 -1
- package/dist/src/app/turnState.js +2 -2
- package/dist/src/app/turnState.js.map +1 -1
- package/dist/src/auth/authConfiguration.d.ts +61 -0
- package/dist/src/auth/authConfiguration.js +52 -3
- package/dist/src/auth/authConfiguration.js.map +1 -1
- package/dist/src/auth/jwt-middleware.js +2 -2
- package/dist/src/auth/jwt-middleware.js.map +1 -1
- package/dist/src/auth/msalConnectionManager.js +20 -0
- package/dist/src/auth/msalConnectionManager.js.map +1 -1
- package/dist/src/auth/msalTokenCredential.js +3 -0
- package/dist/src/auth/msalTokenCredential.js.map +1 -1
- package/dist/src/auth/msalTokenProvider.js +136 -110
- package/dist/src/auth/msalTokenProvider.js.map +1 -1
- package/dist/src/baseAdapter.js +2 -2
- package/dist/src/baseAdapter.js.map +1 -1
- package/dist/src/cloudAdapter.js +201 -154
- package/dist/src/cloudAdapter.js.map +1 -1
- package/dist/src/connector-client/connectorClient.js +176 -127
- package/dist/src/connector-client/connectorClient.js.map +1 -1
- package/dist/src/errorHelper.js +108 -0
- package/dist/src/errorHelper.js.map +1 -1
- package/dist/src/middlewareSet.js +2 -2
- package/dist/src/middlewareSet.js.map +1 -1
- package/dist/src/oauth/userTokenClient.js +78 -48
- package/dist/src/oauth/userTokenClient.js.map +1 -1
- package/dist/src/observability/index.d.ts +2 -0
- package/dist/src/observability/index.js +21 -0
- package/dist/src/observability/index.js.map +1 -0
- package/dist/src/observability/metrics.d.ts +21 -0
- package/dist/src/observability/metrics.js +87 -0
- package/dist/src/observability/metrics.js.map +1 -0
- package/dist/src/observability/traces.d.ts +234 -0
- package/dist/src/observability/traces.js +962 -0
- package/dist/src/observability/traces.js.map +1 -0
- package/dist/src/state/agentState.js +2 -2
- package/dist/src/state/agentState.js.map +1 -1
- package/dist/src/storage/fileStorage.js +38 -28
- package/dist/src/storage/fileStorage.js.map +1 -1
- package/dist/src/storage/memoryStorage.js +41 -30
- package/dist/src/storage/memoryStorage.js.map +1 -1
- package/dist/src/transcript/fileTranscriptLogger.js +2 -2
- package/dist/src/transcript/fileTranscriptLogger.js.map +1 -1
- package/dist/src/transcript/transcriptLoggerMiddleware.js +2 -2
- package/dist/src/transcript/transcriptLoggerMiddleware.js.map +1 -1
- package/dist/src/turnContext.js +48 -42
- package/dist/src/turnContext.js.map +1 -1
- package/package.json +10 -9
- package/src/activityHandler.ts +1 -1
- package/src/agent-client/agentClient.ts +53 -42
- package/src/agent-client/agentResponseHandler.ts +1 -1
- package/src/app/agentApplication.ts +212 -86
- package/src/app/agentApplicationBuilder.ts +26 -4
- package/src/app/agentApplicationOptions.ts +43 -0
- package/src/app/attachmentDownloader.ts +1 -1
- package/src/app/auth/authorization.ts +11 -8
- package/src/app/auth/authorizationManager.ts +297 -45
- package/src/app/auth/handlerStorage.ts +3 -1
- package/src/app/auth/handlers/agenticAuthorization.ts +68 -72
- package/src/app/auth/handlers/azureBotAuthorization.ts +260 -264
- package/src/app/auth/types.ts +102 -1
- package/src/app/auth/utils.ts +22 -0
- package/src/app/index.ts +1 -0
- package/src/app/proactive/conversation.ts +87 -0
- package/src/app/proactive/conversationBuilder.ts +139 -0
- package/src/app/proactive/conversationReferenceBuilder.ts +161 -0
- package/src/app/proactive/createConversationOptions.ts +35 -0
- package/src/app/proactive/createConversationOptionsBuilder.ts +181 -0
- package/src/app/proactive/index.ts +10 -0
- package/src/app/proactive/proactive.ts +524 -0
- package/src/app/proactive/proactiveOptions.ts +24 -0
- package/src/app/streaming/streamingResponse.ts +1 -1
- package/src/app/teamsAttachmentDownloader.ts +1 -1
- package/src/app/turnState.ts +1 -1
- package/src/auth/authConfiguration.ts +58 -1
- package/src/auth/jwt-middleware.ts +1 -1
- package/src/auth/msalConnectionManager.ts +22 -0
- package/src/auth/msalTokenCredential.ts +4 -0
- package/src/auth/msalTokenProvider.ts +138 -107
- package/src/baseAdapter.ts +1 -1
- package/src/cloudAdapter.ts +239 -184
- package/src/connector-client/connectorClient.ts +169 -126
- package/src/errorHelper.ts +124 -0
- package/src/middlewareSet.ts +1 -1
- package/src/oauth/userTokenClient.ts +70 -46
- package/src/observability/index.ts +5 -0
- package/src/observability/metrics.ts +103 -0
- package/src/observability/traces.ts +988 -0
- package/src/state/agentState.ts +1 -1
- package/src/storage/fileStorage.ts +36 -26
- package/src/storage/memoryStorage.ts +40 -29
- package/src/transcript/fileTranscriptLogger.ts +1 -1
- package/src/transcript/transcriptLoggerMiddleware.ts +1 -1
- package/src/turnContext.ts +47 -41
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import type { Activity, ChannelAccount, ConversationParameters } from '@microsoft/agents-activity'
|
|
5
|
+
import { Channels, ExceptionHelper, RoleTypes } from '@microsoft/agents-activity'
|
|
6
|
+
import { Errors } from '../../errorHelper'
|
|
7
|
+
import { AzureBotScope, type CreateConversationOptions } from './createConversationOptions'
|
|
8
|
+
import type { ConversationClaims } from './conversation'
|
|
9
|
+
import { ConversationReferenceBuilder } from './conversationReferenceBuilder'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Fluent builder for `CreateConversationOptions`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const opts = CreateConversationOptionsBuilder
|
|
17
|
+
* .create('my-client-id', 'msteams')
|
|
18
|
+
* .withUser('user-aad-id')
|
|
19
|
+
* .withTenantId('tenant-id')
|
|
20
|
+
* .build()
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export class CreateConversationOptionsBuilder {
|
|
24
|
+
private readonly _claims: ConversationClaims
|
|
25
|
+
private readonly _channelId: string
|
|
26
|
+
private readonly _serviceUrl: string
|
|
27
|
+
private _scope: string = AzureBotScope
|
|
28
|
+
private _storeConversation: boolean = false
|
|
29
|
+
private _parameters: Partial<ConversationParameters> = {
|
|
30
|
+
channelData: {},
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private _activity: Partial<Activity> | undefined
|
|
34
|
+
|
|
35
|
+
private constructor (claims: ConversationClaims, channelId: string, serviceUrl?: string) {
|
|
36
|
+
this._claims = claims
|
|
37
|
+
this._channelId = channelId
|
|
38
|
+
this._serviceUrl =
|
|
39
|
+
serviceUrl ?? ConversationReferenceBuilder.serviceUrlForChannel(channelId)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new builder from an agent client ID string.
|
|
44
|
+
* @param agentClientId The agent's client (app) ID.
|
|
45
|
+
* @param channelId The target channel (e.g. `'msteams'`).
|
|
46
|
+
* @param serviceUrl Optional service URL override.
|
|
47
|
+
*/
|
|
48
|
+
static create (agentClientId: string, channelId: string, serviceUrl?: string, parameters?: Partial<ConversationParameters>): CreateConversationOptionsBuilder
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new builder from an existing claims object (e.g. from a stored `Conversation`).
|
|
51
|
+
* @param claims JWT claims — `aud` must be the agent's client ID.
|
|
52
|
+
* @param channelId The target channel (e.g. `'msteams'`).
|
|
53
|
+
* @param serviceUrl Optional service URL override.
|
|
54
|
+
*/
|
|
55
|
+
static create (claims: ConversationClaims, channelId: string, serviceUrl?: string, parameters?: Partial<ConversationParameters>): CreateConversationOptionsBuilder
|
|
56
|
+
static create (
|
|
57
|
+
agentClientIdOrClaims: string | ConversationClaims,
|
|
58
|
+
channelId: string,
|
|
59
|
+
serviceUrl?: string,
|
|
60
|
+
parameters?: Partial<ConversationParameters>
|
|
61
|
+
): CreateConversationOptionsBuilder {
|
|
62
|
+
const claims: ConversationClaims = typeof agentClientIdOrClaims === 'string'
|
|
63
|
+
? { aud: agentClientIdOrClaims }
|
|
64
|
+
: agentClientIdOrClaims
|
|
65
|
+
|
|
66
|
+
const builder = new CreateConversationOptionsBuilder(claims, channelId, serviceUrl)
|
|
67
|
+
if (parameters) {
|
|
68
|
+
builder._parameters = { ...builder._parameters, ...parameters }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Set parameters.agent if not already provided — matches C# behavior
|
|
72
|
+
if (!builder._parameters.agent) {
|
|
73
|
+
builder._parameters.agent = { id: claims.aud, role: RoleTypes.Agent }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return builder
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Adds a member (the target user) to `parameters.members`. */
|
|
80
|
+
withUser (userId: string, userName?: string): this
|
|
81
|
+
withUser (account: ChannelAccount): this
|
|
82
|
+
withUser (userIdOrAccount: string | ChannelAccount, userName?: string): this {
|
|
83
|
+
const account: ChannelAccount =
|
|
84
|
+
typeof userIdOrAccount === 'string'
|
|
85
|
+
? { id: userIdOrAccount, name: userName }
|
|
86
|
+
: userIdOrAccount
|
|
87
|
+
const members = this._parameters.members ?? []
|
|
88
|
+
members.push(account)
|
|
89
|
+
this._parameters = { ...this._parameters, members }
|
|
90
|
+
return this
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Sets `parameters.activity`. Defaults `activity.type` to `'message'` if not provided. */
|
|
94
|
+
withActivity (activity: Partial<Activity>): this {
|
|
95
|
+
this._activity = activity
|
|
96
|
+
return this
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Merges additional channel-specific data into `parameters.channelData`. */
|
|
100
|
+
withChannelData (data: object): this {
|
|
101
|
+
this._parameters = {
|
|
102
|
+
...this._parameters,
|
|
103
|
+
channelData: { ...(this._parameters.channelData as object ?? {}), ...data },
|
|
104
|
+
}
|
|
105
|
+
return this
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Sets `parameters.tenantId`.
|
|
110
|
+
* On `msteams` channels, also sets `channelData.tenant.id`.
|
|
111
|
+
*/
|
|
112
|
+
withTenantId (tenantId: string): this {
|
|
113
|
+
this._parameters = { ...this._parameters, tenantId }
|
|
114
|
+
if (this._channelId === Channels.Msteams) {
|
|
115
|
+
this.withChannelData({ tenant: { id: tenantId } })
|
|
116
|
+
}
|
|
117
|
+
return this
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Sets `parameters.isGroup = true` and `channelData.channel.id`.
|
|
122
|
+
* Only has effect on `msteams` channels.
|
|
123
|
+
*/
|
|
124
|
+
withTeamsChannelId (teamsChannelId: string): this {
|
|
125
|
+
if (this._channelId !== Channels.Msteams) return this
|
|
126
|
+
this._parameters = { ...this._parameters, isGroup: true }
|
|
127
|
+
this.withChannelData({ channel: { id: teamsChannelId } })
|
|
128
|
+
return this
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Sets `parameters.topicName`. */
|
|
132
|
+
withTopicName (name: string): this {
|
|
133
|
+
this._parameters = { ...this._parameters, topicName: name }
|
|
134
|
+
return this
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Sets `parameters.isGroup`. */
|
|
138
|
+
isGroup (value: boolean): this {
|
|
139
|
+
this._parameters = { ...this._parameters, isGroup: value }
|
|
140
|
+
return this
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Overrides the default `AzureBotScope` OAuth scope. */
|
|
144
|
+
withScope (scope: string): this {
|
|
145
|
+
this._scope = scope
|
|
146
|
+
return this
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Controls whether the resulting conversation is stored after creation. */
|
|
150
|
+
storeConversation (value: boolean): this {
|
|
151
|
+
this._storeConversation = value
|
|
152
|
+
return this
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Builds and returns `CreateConversationOptions`.
|
|
157
|
+
* @throws if no members were added via `withUser()`.
|
|
158
|
+
*/
|
|
159
|
+
build (): CreateConversationOptions {
|
|
160
|
+
if (!this._parameters.members?.length) {
|
|
161
|
+
throw ExceptionHelper.generateException(Error, Errors.CreateConversationBuilderMembersRequired)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const activity: Partial<Activity> = {
|
|
165
|
+
type: 'message',
|
|
166
|
+
...this._activity,
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
identity: this._claims,
|
|
171
|
+
channelId: this._channelId,
|
|
172
|
+
serviceUrl: this._serviceUrl,
|
|
173
|
+
scope: this._scope,
|
|
174
|
+
storeConversation: this._storeConversation,
|
|
175
|
+
parameters: {
|
|
176
|
+
...this._parameters,
|
|
177
|
+
activity: activity as Activity,
|
|
178
|
+
},
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
export * from './conversation'
|
|
5
|
+
export * from './conversationBuilder'
|
|
6
|
+
export * from './conversationReferenceBuilder'
|
|
7
|
+
export * from './createConversationOptions'
|
|
8
|
+
export * from './createConversationOptionsBuilder'
|
|
9
|
+
export * from './proactiveOptions'
|
|
10
|
+
export * from './proactive'
|