@microsoft/agents-hosting 1.5.0-beta.1.g77c44097fe → 1.5.0-beta.12.ga9a2b23c19

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.
Files changed (61) hide show
  1. package/dist/package.json +2 -2
  2. package/dist/src/app/agentApplication.d.ts +31 -9
  3. package/dist/src/app/agentApplication.js +125 -82
  4. package/dist/src/app/agentApplication.js.map +1 -1
  5. package/dist/src/app/agentApplicationBuilder.d.ts +7 -0
  6. package/dist/src/app/agentApplicationBuilder.js +9 -0
  7. package/dist/src/app/agentApplicationBuilder.js.map +1 -1
  8. package/dist/src/app/agentApplicationOptions.d.ts +6 -0
  9. package/dist/src/app/auth/authorizationManager.d.ts +4 -0
  10. package/dist/src/app/auth/authorizationManager.js +10 -9
  11. package/dist/src/app/auth/authorizationManager.js.map +1 -1
  12. package/dist/src/app/auth/handlers/azureBotAuthorization.js +3 -3
  13. package/dist/src/app/auth/handlers/azureBotAuthorization.js.map +1 -1
  14. package/dist/src/app/index.d.ts +1 -0
  15. package/dist/src/app/index.js +1 -0
  16. package/dist/src/app/index.js.map +1 -1
  17. package/dist/src/app/proactive/conversation.d.ts +43 -0
  18. package/dist/src/app/proactive/conversation.js +67 -0
  19. package/dist/src/app/proactive/conversation.js.map +1 -0
  20. package/dist/src/app/proactive/conversationBuilder.d.ts +54 -0
  21. package/dist/src/app/proactive/conversationBuilder.js +110 -0
  22. package/dist/src/app/proactive/conversationBuilder.js.map +1 -0
  23. package/dist/src/app/proactive/conversationReferenceBuilder.d.ts +68 -0
  24. package/dist/src/app/proactive/conversationReferenceBuilder.js +125 -0
  25. package/dist/src/app/proactive/conversationReferenceBuilder.js.map +1 -0
  26. package/dist/src/app/proactive/createConversationOptions.d.ts +30 -0
  27. package/dist/src/app/proactive/createConversationOptions.js +10 -0
  28. package/dist/src/app/proactive/createConversationOptions.js.map +1 -0
  29. package/dist/src/app/proactive/createConversationOptionsBuilder.d.ts +69 -0
  30. package/dist/src/app/proactive/createConversationOptionsBuilder.js +141 -0
  31. package/dist/src/app/proactive/createConversationOptionsBuilder.js.map +1 -0
  32. package/dist/src/app/proactive/index.d.ts +7 -0
  33. package/dist/src/app/proactive/index.js +26 -0
  34. package/dist/src/app/proactive/index.js.map +1 -0
  35. package/dist/src/app/proactive/proactive.d.ts +248 -0
  36. package/dist/src/app/proactive/proactive.js +271 -0
  37. package/dist/src/app/proactive/proactive.js.map +1 -0
  38. package/dist/src/app/proactive/proactiveOptions.d.ts +19 -0
  39. package/dist/src/app/proactive/proactiveOptions.js +5 -0
  40. package/dist/src/app/proactive/proactiveOptions.js.map +1 -0
  41. package/dist/src/errorHelper.js +94 -0
  42. package/dist/src/errorHelper.js.map +1 -1
  43. package/dist/src/turnContext.js +7 -1
  44. package/dist/src/turnContext.js.map +1 -1
  45. package/package.json +2 -2
  46. package/src/app/agentApplication.ts +130 -79
  47. package/src/app/agentApplicationBuilder.ts +11 -0
  48. package/src/app/agentApplicationOptions.ts +7 -0
  49. package/src/app/auth/authorizationManager.ts +14 -9
  50. package/src/app/auth/handlers/azureBotAuthorization.ts +3 -3
  51. package/src/app/index.ts +1 -0
  52. package/src/app/proactive/conversation.ts +87 -0
  53. package/src/app/proactive/conversationBuilder.ts +139 -0
  54. package/src/app/proactive/conversationReferenceBuilder.ts +161 -0
  55. package/src/app/proactive/createConversationOptions.ts +35 -0
  56. package/src/app/proactive/createConversationOptionsBuilder.ts +181 -0
  57. package/src/app/proactive/index.ts +10 -0
  58. package/src/app/proactive/proactive.ts +481 -0
  59. package/src/app/proactive/proactiveOptions.ts +24 -0
  60. package/src/errorHelper.ts +108 -0
  61. package/src/turnContext.ts +6 -1
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.AzureBotScope = void 0;
6
+ /**
7
+ * Default OAuth scope for Azure Bot Service authentication.
8
+ */
9
+ exports.AzureBotScope = 'https://api.botframework.com';
10
+ //# sourceMappingURL=createConversationOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createConversationOptions.js","sourceRoot":"","sources":["../../../../src/app/proactive/createConversationOptions.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAKlC;;GAEG;AACU,QAAA,aAAa,GAAG,8BAA8B,CAAA"}
@@ -0,0 +1,69 @@
1
+ import type { Activity, ChannelAccount, ConversationParameters } from '@microsoft/agents-activity';
2
+ import { type CreateConversationOptions } from './createConversationOptions';
3
+ import type { ConversationClaims } from './conversation';
4
+ /**
5
+ * Fluent builder for `CreateConversationOptions`.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const opts = CreateConversationOptionsBuilder
10
+ * .create('my-client-id', 'msteams')
11
+ * .withUser('user-aad-id')
12
+ * .withTenantId('tenant-id')
13
+ * .build()
14
+ * ```
15
+ */
16
+ export declare class CreateConversationOptionsBuilder {
17
+ private readonly _claims;
18
+ private readonly _channelId;
19
+ private readonly _serviceUrl;
20
+ private _scope;
21
+ private _storeConversation;
22
+ private _parameters;
23
+ private _activity;
24
+ private constructor();
25
+ /**
26
+ * Creates a new builder from an agent client ID string.
27
+ * @param agentClientId The agent's client (app) ID.
28
+ * @param channelId The target channel (e.g. `'msteams'`).
29
+ * @param serviceUrl Optional service URL override.
30
+ */
31
+ static create(agentClientId: string, channelId: string, serviceUrl?: string, parameters?: Partial<ConversationParameters>): CreateConversationOptionsBuilder;
32
+ /**
33
+ * Creates a new builder from an existing claims object (e.g. from a stored `Conversation`).
34
+ * @param claims JWT claims — `aud` must be the agent's client ID.
35
+ * @param channelId The target channel (e.g. `'msteams'`).
36
+ * @param serviceUrl Optional service URL override.
37
+ */
38
+ static create(claims: ConversationClaims, channelId: string, serviceUrl?: string, parameters?: Partial<ConversationParameters>): CreateConversationOptionsBuilder;
39
+ /** Adds a member (the target user) to `parameters.members`. */
40
+ withUser(userId: string, userName?: string): this;
41
+ withUser(account: ChannelAccount): this;
42
+ /** Sets `parameters.activity`. Defaults `activity.type` to `'message'` if not provided. */
43
+ withActivity(activity: Partial<Activity>): this;
44
+ /** Merges additional channel-specific data into `parameters.channelData`. */
45
+ withChannelData(data: object): this;
46
+ /**
47
+ * Sets `parameters.tenantId`.
48
+ * On `msteams` channels, also sets `channelData.tenant.id`.
49
+ */
50
+ withTenantId(tenantId: string): this;
51
+ /**
52
+ * Sets `parameters.isGroup = true` and `channelData.channel.id`.
53
+ * Only has effect on `msteams` channels.
54
+ */
55
+ withTeamsChannelId(teamsChannelId: string): this;
56
+ /** Sets `parameters.topicName`. */
57
+ withTopicName(name: string): this;
58
+ /** Sets `parameters.isGroup`. */
59
+ isGroup(value: boolean): this;
60
+ /** Overrides the default `AzureBotScope` OAuth scope. */
61
+ withScope(scope: string): this;
62
+ /** Controls whether the resulting conversation is stored after creation. */
63
+ storeConversation(value: boolean): this;
64
+ /**
65
+ * Builds and returns `CreateConversationOptions`.
66
+ * @throws if no members were added via `withUser()`.
67
+ */
68
+ build(): CreateConversationOptions;
69
+ }
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.CreateConversationOptionsBuilder = void 0;
6
+ const agents_activity_1 = require("@microsoft/agents-activity");
7
+ const errorHelper_1 = require("../../errorHelper");
8
+ const createConversationOptions_1 = require("./createConversationOptions");
9
+ const conversationReferenceBuilder_1 = require("./conversationReferenceBuilder");
10
+ /**
11
+ * Fluent builder for `CreateConversationOptions`.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const opts = CreateConversationOptionsBuilder
16
+ * .create('my-client-id', 'msteams')
17
+ * .withUser('user-aad-id')
18
+ * .withTenantId('tenant-id')
19
+ * .build()
20
+ * ```
21
+ */
22
+ class CreateConversationOptionsBuilder {
23
+ constructor(claims, channelId, serviceUrl) {
24
+ this._scope = createConversationOptions_1.AzureBotScope;
25
+ this._storeConversation = false;
26
+ this._parameters = {
27
+ channelData: {},
28
+ };
29
+ this._claims = claims;
30
+ this._channelId = channelId;
31
+ this._serviceUrl =
32
+ serviceUrl !== null && serviceUrl !== void 0 ? serviceUrl : conversationReferenceBuilder_1.ConversationReferenceBuilder.serviceUrlForChannel(channelId);
33
+ }
34
+ static create(agentClientIdOrClaims, channelId, serviceUrl, parameters) {
35
+ const claims = typeof agentClientIdOrClaims === 'string'
36
+ ? { aud: agentClientIdOrClaims }
37
+ : agentClientIdOrClaims;
38
+ const builder = new CreateConversationOptionsBuilder(claims, channelId, serviceUrl);
39
+ if (parameters) {
40
+ builder._parameters = { ...builder._parameters, ...parameters };
41
+ }
42
+ // Set parameters.agent if not already provided — matches C# behavior
43
+ if (!builder._parameters.agent) {
44
+ builder._parameters.agent = { id: claims.aud, role: agents_activity_1.RoleTypes.Agent };
45
+ }
46
+ return builder;
47
+ }
48
+ withUser(userIdOrAccount, userName) {
49
+ var _a;
50
+ const account = typeof userIdOrAccount === 'string'
51
+ ? { id: userIdOrAccount, name: userName }
52
+ : userIdOrAccount;
53
+ const members = (_a = this._parameters.members) !== null && _a !== void 0 ? _a : [];
54
+ members.push(account);
55
+ this._parameters = { ...this._parameters, members };
56
+ return this;
57
+ }
58
+ /** Sets `parameters.activity`. Defaults `activity.type` to `'message'` if not provided. */
59
+ withActivity(activity) {
60
+ this._activity = activity;
61
+ return this;
62
+ }
63
+ /** Merges additional channel-specific data into `parameters.channelData`. */
64
+ withChannelData(data) {
65
+ var _a;
66
+ this._parameters = {
67
+ ...this._parameters,
68
+ channelData: { ...((_a = this._parameters.channelData) !== null && _a !== void 0 ? _a : {}), ...data },
69
+ };
70
+ return this;
71
+ }
72
+ /**
73
+ * Sets `parameters.tenantId`.
74
+ * On `msteams` channels, also sets `channelData.tenant.id`.
75
+ */
76
+ withTenantId(tenantId) {
77
+ this._parameters = { ...this._parameters, tenantId };
78
+ if (this._channelId === agents_activity_1.Channels.Msteams) {
79
+ this.withChannelData({ tenant: { id: tenantId } });
80
+ }
81
+ return this;
82
+ }
83
+ /**
84
+ * Sets `parameters.isGroup = true` and `channelData.channel.id`.
85
+ * Only has effect on `msteams` channels.
86
+ */
87
+ withTeamsChannelId(teamsChannelId) {
88
+ if (this._channelId !== agents_activity_1.Channels.Msteams)
89
+ return this;
90
+ this._parameters = { ...this._parameters, isGroup: true };
91
+ this.withChannelData({ channel: { id: teamsChannelId } });
92
+ return this;
93
+ }
94
+ /** Sets `parameters.topicName`. */
95
+ withTopicName(name) {
96
+ this._parameters = { ...this._parameters, topicName: name };
97
+ return this;
98
+ }
99
+ /** Sets `parameters.isGroup`. */
100
+ isGroup(value) {
101
+ this._parameters = { ...this._parameters, isGroup: value };
102
+ return this;
103
+ }
104
+ /** Overrides the default `AzureBotScope` OAuth scope. */
105
+ withScope(scope) {
106
+ this._scope = scope;
107
+ return this;
108
+ }
109
+ /** Controls whether the resulting conversation is stored after creation. */
110
+ storeConversation(value) {
111
+ this._storeConversation = value;
112
+ return this;
113
+ }
114
+ /**
115
+ * Builds and returns `CreateConversationOptions`.
116
+ * @throws if no members were added via `withUser()`.
117
+ */
118
+ build() {
119
+ var _a;
120
+ if (!((_a = this._parameters.members) === null || _a === void 0 ? void 0 : _a.length)) {
121
+ throw agents_activity_1.ExceptionHelper.generateException(Error, errorHelper_1.Errors.CreateConversationBuilderMembersRequired);
122
+ }
123
+ const activity = {
124
+ type: 'message',
125
+ ...this._activity,
126
+ };
127
+ return {
128
+ identity: this._claims,
129
+ channelId: this._channelId,
130
+ serviceUrl: this._serviceUrl,
131
+ scope: this._scope,
132
+ storeConversation: this._storeConversation,
133
+ parameters: {
134
+ ...this._parameters,
135
+ activity: activity,
136
+ },
137
+ };
138
+ }
139
+ }
140
+ exports.CreateConversationOptionsBuilder = CreateConversationOptionsBuilder;
141
+ //# sourceMappingURL=createConversationOptionsBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createConversationOptionsBuilder.js","sourceRoot":"","sources":["../../../../src/app/proactive/createConversationOptionsBuilder.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAGlC,gEAAiF;AACjF,mDAA0C;AAC1C,2EAA2F;AAE3F,iFAA6E;AAE7E;;;;;;;;;;;GAWG;AACH,MAAa,gCAAgC;IAY3C,YAAqB,MAA0B,EAAE,SAAiB,EAAE,UAAmB;QAR/E,WAAM,GAAW,yCAAa,CAAA;QAC9B,uBAAkB,GAAY,KAAK,CAAA;QACnC,gBAAW,GAAoC;YACrD,WAAW,EAAE,EAAE;SAChB,CAAA;QAKC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;QAC3B,IAAI,CAAC,WAAW;YACd,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,2DAA4B,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAA;IAC9E,CAAC;IAgBD,MAAM,CAAC,MAAM,CACX,qBAAkD,EAClD,SAAiB,EACjB,UAAmB,EACnB,UAA4C;QAE5C,MAAM,MAAM,GAAuB,OAAO,qBAAqB,KAAK,QAAQ;YAC1E,CAAC,CAAC,EAAE,GAAG,EAAE,qBAAqB,EAAE;YAChC,CAAC,CAAC,qBAAqB,CAAA;QAEzB,MAAM,OAAO,GAAG,IAAI,gCAAgC,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;QACnF,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC,WAAW,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,EAAE,GAAG,UAAU,EAAE,CAAA;QACjE,CAAC;QAED,qEAAqE;QACrE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;YAC/B,OAAO,CAAC,WAAW,CAAC,KAAK,GAAG,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,2BAAS,CAAC,KAAK,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Q,EAAE,IAAI,CAAC,OAAO;YACtB,SAAS,EAAE,IAAI,CAAC,UAAU;YAC1B,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,iBAAiB,EAAE,IAAI,CAAC,kBAAkB;YAC1C,UAAU,EAAE;gBACV,GAAG,IAAI,CAAC,WAAW;gBACnB,QAAQ,EAAE,QAAoB;aAC/B;SACF,CAAA;IACH,CAAC;CACF;AA9JD,4EA8JC"}
@@ -0,0 +1,7 @@
1
+ export * from './conversation';
2
+ export * from './conversationBuilder';
3
+ export * from './conversationReferenceBuilder';
4
+ export * from './createConversationOptions';
5
+ export * from './createConversationOptionsBuilder';
6
+ export * from './proactiveOptions';
7
+ export * from './proactive';
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved.
3
+ // Licensed under the MIT License.
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ __exportStar(require("./conversation"), exports);
20
+ __exportStar(require("./conversationBuilder"), exports);
21
+ __exportStar(require("./conversationReferenceBuilder"), exports);
22
+ __exportStar(require("./createConversationOptions"), exports);
23
+ __exportStar(require("./createConversationOptionsBuilder"), exports);
24
+ __exportStar(require("./proactiveOptions"), exports);
25
+ __exportStar(require("./proactive"), exports);
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/app/proactive/index.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;;;;;;;;;;;;;AAElC,iDAA8B;AAC9B,wDAAqC;AACrC,iEAA8C;AAC9C,8DAA2C;AAC3C,qEAAkD;AAClD,qDAAkC;AAClC,8CAA2B"}
@@ -0,0 +1,248 @@
1
+ import type { Activity } from '@microsoft/agents-activity';
2
+ import type { ResourceResponse } from '../../connector-client';
3
+ import type { BaseAdapter } from '../../baseAdapter';
4
+ import type { TurnContext } from '../../turnContext';
5
+ import type { TurnState } from '../turnState';
6
+ import type { RouteHandler } from '../routeHandler';
7
+ import type { AgentApplication } from '../agentApplication';
8
+ import type { ProactiveOptions } from './proactiveOptions';
9
+ import type { CreateConversationOptions } from './createConversationOptions';
10
+ import { Conversation } from './conversation';
11
+ /**
12
+ * Provides methods for storing, retrieving, and managing conversation references to enable
13
+ * proactive messaging scenarios. Supports sending activities and continuing conversations outside
14
+ * the standard request/response flow using stored conversation references.
15
+ *
16
+ * @remarks
17
+ * Use the `Proactive` class to implement scenarios where an agent needs to initiate conversations
18
+ * or send messages to users without an incoming activity, such as notifications or scheduled alerts.
19
+ * Some operations require that conversation references be stored using {@link storeConversation}
20
+ * before they can be used.
21
+ *
22
+ * Access via `app.proactive` after configuring `proactive` in {@link AgentApplicationOptions}.
23
+ */
24
+ export declare class Proactive<TState extends TurnState> {
25
+ /**
26
+ * `activity.valueType` that indicates additional key/values for the ContinueConversation event.
27
+ */
28
+ static readonly ContinueConversationValueType = "application/vnd.microsoft.activity.continueconversation+json";
29
+ private readonly _app;
30
+ private readonly _options;
31
+ private readonly _storage?;
32
+ constructor(app: AgentApplication<TState>, options: ProactiveOptions);
33
+ private requireStorage;
34
+ private requireAppStorage;
35
+ /**
36
+ * Stores the current conversation reference from a live {@link TurnContext} in proactive storage.
37
+ *
38
+ * @param context - The context object for the current turn, containing activity and conversation
39
+ * information.
40
+ * @returns The conversation ID that can be used to retrieve the reference in future operations.
41
+ * @example
42
+ * ```typescript
43
+ * // Inside an onMessage handler — save the conversation so we can message later
44
+ * app.onActivity('message', async (ctx, state) => {
45
+ * const convId = await app.proactive.storeConversation(ctx)
46
+ * await ctx.sendActivity(`Conversation stored. ID: ${convId}`)
47
+ * })
48
+ * ```
49
+ */
50
+ storeConversation(context: TurnContext): Promise<string>;
51
+ /**
52
+ * Stores an explicit {@link Conversation} object in proactive storage.
53
+ *
54
+ * @param conversation - The conversation reference record to store.
55
+ * @returns The conversation ID that can be used to retrieve the reference in future operations.
56
+ * @throws If the conversation fails validation (missing `conversation.id`, `serviceUrl`, or
57
+ * `claims.aud`).
58
+ * @example
59
+ * ```typescript
60
+ * // Build a Conversation manually and store it
61
+ * const conv = ConversationBuilder
62
+ * .create('my-app-id', 'msteams')
63
+ * .withUser('user-aad-id')
64
+ * .withConversationId('19:existing-thread-id@thread.tacv2')
65
+ * .build()
66
+ * const convId = await app.proactive.storeConversation(conv)
67
+ * ```
68
+ */
69
+ storeConversation(conversation: Conversation): Promise<string>;
70
+ /**
71
+ * Retrieves the stored {@link Conversation} associated with the given conversation ID.
72
+ *
73
+ * @param conversationId - The unique identifier of the conversation to retrieve.
74
+ * @returns The stored `Conversation`, or `undefined` if no record exists for that ID.
75
+ * @example
76
+ * ```typescript
77
+ * const conv = await app.proactive.getConversation(convId)
78
+ * if (conv) {
79
+ * await app.proactive.sendActivity(adapter, conv, { text: 'Hello!' })
80
+ * }
81
+ * ```
82
+ */
83
+ getConversation(conversationId: string): Promise<Conversation | undefined>;
84
+ /**
85
+ * Retrieves the stored {@link Conversation} for the given ID, throwing if no record is found.
86
+ *
87
+ * @param conversationId - The unique identifier of the conversation to retrieve.
88
+ * @returns The stored `Conversation`.
89
+ * @throws `Error` if no conversation reference is found for the specified ID.
90
+ * @example
91
+ * ```typescript
92
+ * // Use when absence of the conversation should be treated as an error
93
+ * const conv = await app.proactive.getConversationOrThrow(convId)
94
+ * await app.proactive.sendActivity(adapter, conv, { text: 'Alert: your report is ready.' })
95
+ * ```
96
+ */
97
+ getConversationOrThrow(conversationId: string): Promise<Conversation>;
98
+ /**
99
+ * Deletes the stored conversation reference for the given conversation ID.
100
+ *
101
+ * @param conversationId - The unique identifier of the conversation whose reference should be
102
+ * deleted.
103
+ * @remarks If no record exists for the given ID, no action is taken.
104
+ * @example
105
+ * ```typescript
106
+ * // Clean up after a conversation has ended
107
+ * app.onActivity('endOfConversation', async (ctx, state) => {
108
+ * await app.proactive.deleteConversation(ctx.activity.conversation.id)
109
+ * })
110
+ * ```
111
+ */
112
+ deleteConversation(conversationId: string): Promise<void>;
113
+ /**
114
+ * Sends an activity to a stored conversation, looking it up by ID.
115
+ *
116
+ * @param adapter - The channel adapter used to send the activity.
117
+ * @param conversationId - The ID of a conversation previously stored via {@link storeConversation}.
118
+ * @param activity - The activity to send. If `type` is not set it defaults to `'message'`.
119
+ * @returns A {@link ResourceResponse} with the ID of the sent activity.
120
+ * @throws `Error` if no conversation reference is found for the specified ID.
121
+ * @example
122
+ * ```typescript
123
+ * // Send a notification using a previously stored conversation ID
124
+ * await app.proactive.sendActivity(adapter, storedConvId, { text: 'Your order has shipped!' })
125
+ * ```
126
+ */
127
+ sendActivity(adapter: BaseAdapter, conversationId: string, activity: Partial<Activity>): Promise<ResourceResponse>;
128
+ /**
129
+ * Sends an activity to an existing conversation using the provided {@link Conversation} reference.
130
+ *
131
+ * @param adapter - The channel adapter used to send the activity.
132
+ * @param conversation - A `Conversation` instance created via its constructor or
133
+ * {@link ConversationBuilder}.
134
+ * @param activity - The activity to send. If `type` is not set it defaults to `'message'`.
135
+ * @returns A {@link ResourceResponse} with the ID of the sent activity.
136
+ * @example
137
+ * ```typescript
138
+ * // Build a Conversation from a stored reference and send a message
139
+ * const conv = await app.proactive.getConversationOrThrow(convId)
140
+ * const response = await app.proactive.sendActivity(adapter, conv, { text: 'Hello from the agent!' })
141
+ * console.log('Sent activity ID:', response.id)
142
+ * ```
143
+ */
144
+ sendActivity(adapter: BaseAdapter, conversation: Conversation, activity: Partial<Activity>): Promise<ResourceResponse>;
145
+ /**
146
+ * Continues a stored conversation by executing the given handler within the context of that
147
+ * conversation, looking it up by ID.
148
+ *
149
+ * See the {@link Conversation} overload for full details.
150
+ *
151
+ * @param adapter - The channel adapter used to continue the conversation.
152
+ * @param conversationId - The ID of a conversation previously stored via {@link storeConversation}.
153
+ * @param handler - The route handler to execute within the continued conversation context.
154
+ * @param autoSignInHandlers - Optional list of OAuth connection names whose tokens should be
155
+ * acquired before invoking the handler.
156
+ * @param continuationActivity - Optional activity fields merged into the continuation activity,
157
+ * making them available on `ctx.activity` inside the handler (e.g. `value`, `valueType`).
158
+ * @throws `Error` if no conversation reference is found for the specified ID.
159
+ * @example
160
+ * ```typescript
161
+ * // Scheduled job: send a daily digest to all stored conversations
162
+ * for (const convId of storedIds) {
163
+ * await app.proactive.continueConversation(adapter, convId, async (ctx, state) => {
164
+ * await ctx.sendActivity('Here is your daily digest...')
165
+ * })
166
+ * }
167
+ * ```
168
+ */
169
+ continueConversation(adapter: BaseAdapter, conversationId: string, handler: RouteHandler<TState>, autoSignInHandlers?: string[], continuationActivity?: Partial<Activity>): Promise<void>;
170
+ /**
171
+ * Continues an existing conversation by executing the given handler within the context of the
172
+ * provided {@link Conversation} reference. The handler receives a {@link TurnContext} and a
173
+ * freshly loaded {@link TurnState} scoped to the original conversation, enabling the agent to
174
+ * respond as if replying to an incoming activity.
175
+ *
176
+ * @remarks
177
+ * Exceptions thrown inside the handler are captured and re-thrown after the adapter callback
178
+ * completes, since the adapter would otherwise silently swallow them.
179
+ *
180
+ * If `autoSignInHandlers` are supplied and the application has user authorization configured,
181
+ * tokens are acquired before the handler is called. If not all tokens are available and
182
+ * `proactiveOptions.failOnUnsignedInConnections` is not `false`, an error is thrown.
183
+ *
184
+ * @param adapter - The channel adapter used to continue the conversation.
185
+ * @param conversation - A `Conversation` instance created via its constructor or
186
+ * {@link ConversationBuilder}.
187
+ * @param handler - The route handler to execute within the continued conversation context.
188
+ * @param autoSignInHandlers - Optional list of OAuth connection names whose tokens should be
189
+ * acquired before invoking the handler.
190
+ * @param continuationActivity - Optional activity fields merged into the continuation activity,
191
+ * making them available on `ctx.activity` inside the handler (e.g. `value`, `valueType`).
192
+ * @example
193
+ * ```typescript
194
+ * // Continue a conversation with a custom value payload
195
+ * const conv = await app.proactive.getConversationOrThrow(convId)
196
+ * await app.proactive.continueConversation(
197
+ * adapter,
198
+ * conv,
199
+ * async (ctx, state) => {
200
+ * const payload = ctx.activity.value as { alertType: string }
201
+ * await ctx.sendActivity(`Alert triggered: ${payload.alertType}`)
202
+ * },
203
+ * undefined,
204
+ * { value: { alertType: 'threshold-exceeded' }, valueType: Proactive.ContinueConversationValueType }
205
+ * )
206
+ * ```
207
+ */
208
+ continueConversation(adapter: BaseAdapter, conversation: Conversation, handler: RouteHandler<TState>, autoSignInHandlers?: string[], continuationActivity?: Partial<Activity>): Promise<void>;
209
+ /**
210
+ * Creates a new conversation using the specified channel adapter and conversation options.
211
+ *
212
+ * @remarks
213
+ * This wraps `CloudAdapter.createConversationAsync()`, which requires real network connectivity
214
+ * and authentication. The provided adapter must implement
215
+ * `createConversationAsync()`; a `TypeError` is thrown if it does not.
216
+ *
217
+ * If `createOptions.storeConversation` is `true`, the resulting {@link Conversation} is
218
+ * automatically stored via {@link storeConversation} so it can be retrieved by ID later.
219
+ *
220
+ * If a `handler` is provided it is executed within the newly created conversation, giving the
221
+ * agent a chance to send an initial message or load state.
222
+ *
223
+ * @param adapter - The channel adapter used to create the conversation. Must implement
224
+ * `createConversationAsync()` (i.e. a `CloudAdapter` instance).
225
+ * @param createOptions - Details required to create the conversation, including identity, channel,
226
+ * service URL, OAuth scope, and `ConversationParameters`. Build with
227
+ * {@link CreateConversationOptionsBuilder}.
228
+ * @param handler - Optional route handler executed immediately after the conversation is created.
229
+ * @returns The newly created {@link Conversation}.
230
+ * @throws `TypeError` if the adapter does not implement `createConversationAsync()`.
231
+ * @example
232
+ * ```typescript
233
+ * // Initiate a new 1:1 conversation with a Teams user and send a welcome message
234
+ * const opts = CreateConversationOptionsBuilder
235
+ * .create(process.env.APP_ID!, 'msteams')
236
+ * .withUser('user-aad-object-id')
237
+ * .withTenantId('tenant-id')
238
+ * .storeConversation(true)
239
+ * .build()
240
+ *
241
+ * const conv = await app.proactive.createConversation(adapter, opts, async (ctx, state) => {
242
+ * await ctx.sendActivity('Hi! I have an update for you.')
243
+ * })
244
+ * console.log('New conversation ID:', conv.reference.conversation.id)
245
+ * ```
246
+ */
247
+ createConversation(adapter: BaseAdapter, createOptions: CreateConversationOptions, handler?: RouteHandler<TState>): Promise<Conversation>;
248
+ }