@microsoft/agents-hosting 0.4.3 → 0.5.4-ga4d0401645

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 (107) hide show
  1. package/dist/src/activityWireCompat.js +1 -1
  2. package/dist/src/activityWireCompat.js.map +1 -1
  3. package/dist/src/app/adaptiveCards/activityValueParsers.d.ts +115 -0
  4. package/dist/src/app/adaptiveCards/activityValueParsers.js +224 -0
  5. package/dist/src/app/adaptiveCards/activityValueParsers.js.map +1 -0
  6. package/dist/src/app/adaptiveCards/adaptiveCardActionExecuteResponseType.d.ts +21 -0
  7. package/dist/src/app/adaptiveCards/adaptiveCardActionExecuteResponseType.js +26 -0
  8. package/dist/src/app/adaptiveCards/adaptiveCardActionExecuteResponseType.js.map +1 -0
  9. package/dist/src/app/adaptiveCards/adaptiveCardsActions.d.ts +57 -0
  10. package/dist/src/app/adaptiveCards/adaptiveCardsActions.js +272 -0
  11. package/dist/src/app/adaptiveCards/adaptiveCardsActions.js.map +1 -0
  12. package/dist/src/app/adaptiveCards/adaptiveCardsOptions.d.ts +20 -0
  13. package/dist/src/app/adaptiveCards/adaptiveCardsOptions.js +7 -0
  14. package/dist/src/app/adaptiveCards/adaptiveCardsOptions.js.map +1 -0
  15. package/dist/src/app/adaptiveCards/adaptiveCardsSearchParams.d.ts +31 -0
  16. package/dist/src/app/adaptiveCards/adaptiveCardsSearchParams.js +16 -0
  17. package/dist/src/app/adaptiveCards/adaptiveCardsSearchParams.js.map +1 -0
  18. package/dist/src/app/adaptiveCards/index.d.ts +3 -0
  19. package/dist/src/app/adaptiveCards/index.js +20 -0
  20. package/dist/src/app/adaptiveCards/index.js.map +1 -0
  21. package/dist/src/app/adaptiveCards/query.d.ts +22 -0
  22. package/dist/src/app/adaptiveCards/query.js +7 -0
  23. package/dist/src/app/adaptiveCards/query.js.map +1 -0
  24. package/dist/src/app/agentApplication.d.ts +56 -8
  25. package/dist/src/app/agentApplication.js +88 -11
  26. package/dist/src/app/agentApplication.js.map +1 -1
  27. package/dist/src/app/agentApplicationBuilder.d.ts +2 -2
  28. package/dist/src/app/agentApplicationBuilder.js.map +1 -1
  29. package/dist/src/app/agentApplicationOptions.d.ts +17 -2
  30. package/dist/src/app/appRoute.d.ts +5 -0
  31. package/dist/src/app/attachmentDownloader.js +1 -0
  32. package/dist/src/app/attachmentDownloader.js.map +1 -1
  33. package/dist/src/app/extensions.d.ts +9 -0
  34. package/dist/src/app/extensions.js +16 -0
  35. package/dist/src/app/extensions.js.map +1 -0
  36. package/dist/src/app/index.d.ts +2 -0
  37. package/dist/src/app/index.js +2 -0
  38. package/dist/src/app/index.js.map +1 -1
  39. package/dist/src/app/streaming/AIEntity.d.ts +36 -0
  40. package/dist/src/app/streaming/AIEntity.js +7 -0
  41. package/dist/src/app/streaming/AIEntity.js.map +1 -0
  42. package/dist/src/app/streaming/actionCall.d.ts +33 -0
  43. package/dist/src/app/streaming/actionCall.js +7 -0
  44. package/dist/src/app/streaming/actionCall.js.map +1 -0
  45. package/dist/src/app/streaming/clientCitation.d.ts +68 -0
  46. package/dist/src/app/streaming/clientCitation.js +10 -0
  47. package/dist/src/app/streaming/clientCitation.js.map +1 -0
  48. package/dist/src/app/streaming/message.d.ts +106 -0
  49. package/dist/src/app/streaming/message.js +7 -0
  50. package/dist/src/app/streaming/message.js.map +1 -0
  51. package/dist/src/app/streaming/sensitivityUsageInfo.d.ts +40 -0
  52. package/dist/src/app/streaming/sensitivityUsageInfo.js +3 -0
  53. package/dist/src/app/streaming/sensitivityUsageInfo.js.map +1 -0
  54. package/dist/src/app/streaming/streamingResponse.d.ts +141 -0
  55. package/dist/src/app/streaming/streamingResponse.js +331 -0
  56. package/dist/src/app/streaming/streamingResponse.js.map +1 -0
  57. package/dist/src/app/streaming/utilities.d.ts +31 -0
  58. package/dist/src/app/streaming/utilities.js +101 -0
  59. package/dist/src/app/streaming/utilities.js.map +1 -0
  60. package/dist/src/auth/jwt-middleware.js +1 -0
  61. package/dist/src/auth/jwt-middleware.js.map +1 -1
  62. package/dist/src/baseAdapter.js +1 -1
  63. package/dist/src/baseAdapter.js.map +1 -1
  64. package/dist/src/cards/adaptiveCard.d.ts +15 -0
  65. package/dist/src/cards/adaptiveCard.js +7 -0
  66. package/dist/src/cards/adaptiveCard.js.map +1 -0
  67. package/dist/src/cards/index.d.ts +1 -0
  68. package/dist/src/cards/index.js +1 -0
  69. package/dist/src/cards/index.js.map +1 -1
  70. package/dist/src/cloudAdapter.js +6 -7
  71. package/dist/src/cloudAdapter.js.map +1 -1
  72. package/dist/src/connector-client/connectorClient.d.ts +6 -4
  73. package/dist/src/connector-client/connectorClient.js +34 -17
  74. package/dist/src/connector-client/connectorClient.js.map +1 -1
  75. package/dist/src/turnContext.d.ts +3 -0
  76. package/dist/src/turnContext.js +5 -0
  77. package/dist/src/turnContext.js.map +1 -1
  78. package/package.json +2 -2
  79. package/src/activityWireCompat.ts +1 -1
  80. package/src/app/adaptiveCards/activityValueParsers.ts +249 -0
  81. package/src/app/adaptiveCards/adaptiveCardActionExecuteResponseType.ts +24 -0
  82. package/src/app/adaptiveCards/adaptiveCardsActions.ts +320 -0
  83. package/src/app/adaptiveCards/adaptiveCardsOptions.ts +23 -0
  84. package/src/app/adaptiveCards/adaptiveCardsSearchParams.ts +28 -0
  85. package/src/app/adaptiveCards/index.ts +3 -0
  86. package/src/app/adaptiveCards/query.ts +25 -0
  87. package/src/app/agentApplication.ts +109 -29
  88. package/src/app/agentApplicationBuilder.ts +2 -2
  89. package/src/app/agentApplicationOptions.ts +20 -2
  90. package/src/app/appRoute.ts +6 -0
  91. package/src/app/attachmentDownloader.ts +1 -0
  92. package/src/app/extensions.ts +19 -0
  93. package/src/app/index.ts +2 -0
  94. package/src/app/streaming/AIEntity.ts +44 -0
  95. package/src/app/streaming/actionCall.ts +37 -0
  96. package/src/app/streaming/clientCitation.ts +102 -0
  97. package/src/app/streaming/message.ts +125 -0
  98. package/src/app/streaming/sensitivityUsageInfo.ts +48 -0
  99. package/src/app/streaming/streamingResponse.ts +406 -0
  100. package/src/app/streaming/utilities.ts +108 -0
  101. package/src/auth/jwt-middleware.ts +1 -1
  102. package/src/baseAdapter.ts +2 -2
  103. package/src/cards/adaptiveCard.ts +16 -0
  104. package/src/cards/index.ts +1 -0
  105. package/src/cloudAdapter.ts +5 -7
  106. package/src/connector-client/connectorClient.ts +38 -19
  107. package/src/turnContext.ts +7 -1
@@ -4,18 +4,20 @@
4
4
  */
5
5
 
6
6
  import { Activity, ActivityTypes, ConversationReference } from '@microsoft/agents-activity'
7
- import { TurnState } from './turnState'
8
7
  import { BaseAdapter } from '../baseAdapter'
9
- import { AgentApplicationOptions } from './agentApplicationOptions'
10
- import { RouteSelector } from './routeSelector'
11
- import { RouteHandler } from './routeHandler'
12
- import { ConversationUpdateEvents } from './conversationUpdateEvents'
13
- import { TurnEvents } from './turnEvents'
14
- import { AppRoute } from './appRoute'
15
- import { TurnContext } from '../turnContext'
16
8
  import { ResourceResponse } from '../connector-client'
17
9
  import { debug } from '../logger'
10
+ import { TurnContext } from '../turnContext'
11
+ import { AdaptiveCardsActions } from './adaptiveCards'
12
+ import { AgentApplicationOptions } from './agentApplicationOptions'
13
+ import { AppRoute } from './appRoute'
14
+ import { ConversationUpdateEvents } from './conversationUpdateEvents'
15
+ import { AgentExtension } from './extensions'
18
16
  import { Authorization } from './oauth/authorization'
17
+ import { RouteHandler } from './routeHandler'
18
+ import { RouteSelector } from './routeSelector'
19
+ import { TurnEvents } from './turnEvents'
20
+ import { TurnState } from './turnState'
19
21
 
20
22
  const logger = debug('agents:agent-application')
21
23
 
@@ -46,16 +48,21 @@ export class AgentApplication<TState extends TurnState> {
46
48
  protected readonly _afterTurn: ApplicationEventHandler<TState>[] = []
47
49
  private readonly _adapter?: BaseAdapter
48
50
  private readonly _authorization?: Authorization
49
- private _typingTimer: any
51
+ private _typingTimer: NodeJS.Timeout | undefined
52
+ protected readonly _extensions: AgentExtension<TState>[] = []
53
+ private readonly _adaptiveCards: AdaptiveCardsActions<TState>
50
54
 
51
55
  public constructor (options?: Partial<AgentApplicationOptions<TState>>) {
52
56
  this._options = {
53
57
  ...options,
54
58
  turnStateFactory: options?.turnStateFactory || (() => new TurnState() as TState),
55
59
  startTypingTimer: options?.startTypingTimer !== undefined ? options.startTypingTimer : false,
56
- longRunningMessages: options?.longRunningMessages !== undefined ? options.longRunningMessages : false
60
+ longRunningMessages: options?.longRunningMessages !== undefined ? options.longRunningMessages : false,
61
+ removeRecipientMention: options?.removeRecipientMention !== undefined ? options.removeRecipientMention : true,
57
62
  }
58
63
 
64
+ this._adaptiveCards = new AdaptiveCardsActions<TState>(this)
65
+
59
66
  if (this._options.adapter) {
60
67
  this._adapter = this._options.adapter
61
68
  }
@@ -65,9 +72,7 @@ export class AgentApplication<TState extends TurnState> {
65
72
  }
66
73
 
67
74
  if (this._options.longRunningMessages && !this._adapter && !this._options.agentAppId) {
68
- throw new Error(
69
- 'The Application.longRunningMessages property is unavailable because no adapter or agentAppId was configured.'
70
- )
75
+ throw new Error('The Application.longRunningMessages property is unavailable because no adapter was configured in the app.')
71
76
  }
72
77
  }
73
78
 
@@ -76,13 +81,7 @@ export class AgentApplication<TState extends TurnState> {
76
81
  * @throws Error if the adapter is not configured.
77
82
  */
78
83
  public get adapter (): BaseAdapter {
79
- if (!this._adapter) {
80
- throw new Error(
81
- 'The Application.adapter property is unavailable because it was not configured when creating the Application.'
82
- )
83
- }
84
-
85
- return this._adapter
84
+ return this._adapter!
86
85
  }
87
86
 
88
87
  /**
@@ -91,11 +90,8 @@ export class AgentApplication<TState extends TurnState> {
91
90
  */
92
91
  public get authorization (): Authorization {
93
92
  if (!this._authorization) {
94
- throw new Error(
95
- 'The Application.authorization property is unavailable because no authentication options were configured.'
96
- )
93
+ throw new Error('The Application.authorization property is unavailable because no authorization options were configured.')
97
94
  }
98
-
99
95
  return this._authorization
100
96
  }
101
97
 
@@ -107,6 +103,10 @@ export class AgentApplication<TState extends TurnState> {
107
103
  return this._options
108
104
  }
109
105
 
106
+ public get adaptiveCards (): AdaptiveCardsActions<TState> {
107
+ return this._adaptiveCards
108
+ }
109
+
110
110
  /**
111
111
  * Sets an error handler for the application.
112
112
  *
@@ -129,7 +129,6 @@ export class AgentApplication<TState extends TurnState> {
129
129
  if (this._adapter) {
130
130
  this._adapter.onTurnError = handler
131
131
  }
132
-
133
132
  return this
134
133
  }
135
134
 
@@ -153,8 +152,8 @@ export class AgentApplication<TState extends TurnState> {
153
152
  * );
154
153
  * ```
155
154
  */
156
- public addRoute (selector: RouteSelector, handler: RouteHandler<TState>): this {
157
- this._routes.push({ selector, handler })
155
+ public addRoute (selector: RouteSelector, handler: RouteHandler<TState>, isInvokeRoute: boolean = false): this {
156
+ this._routes.push({ selector, handler, isInvokeRoute })
158
157
  return this
159
158
  }
160
159
 
@@ -316,12 +315,74 @@ export class AgentApplication<TState extends TurnState> {
316
315
  this.authorization.onSignInSuccess(handler)
317
316
  } else {
318
317
  throw new Error(
319
- 'The Application.authentication property is unavailable because no authentication options were configured.'
318
+ 'The Application.authorization property is unavailable because no authorization options were configured.'
320
319
  )
321
320
  }
322
321
  return this
323
322
  }
324
323
 
324
+ /**
325
+ * Adds a handler for message reaction added events.
326
+ *
327
+ * @param handler - The handler function that will be called when a message reaction is added.
328
+ * @returns The current instance of the application.
329
+ *
330
+ * @remarks
331
+ * This method registers a handler that will be invoked when a user adds a reaction to a message,
332
+ * such as a like, heart, or other emoji reaction.
333
+ *
334
+ * Example usage:
335
+ * ```typescript
336
+ * app.onMessageReactionAdded(async (context, state) => {
337
+ * const reactionsAdded = context.activity.reactionsAdded;
338
+ * if (reactionsAdded && reactionsAdded.length > 0) {
339
+ * await context.sendActivity(`Thanks for your ${reactionsAdded[0].type} reaction!`);
340
+ * }
341
+ * });
342
+ * ```
343
+ */
344
+ public onMessageReactionAdded (handler: (context: TurnContext, state: TState) => Promise<void>): this {
345
+ const selector = async (context: TurnContext): Promise<boolean> => {
346
+ return context.activity.type === ActivityTypes.MessageReaction &&
347
+ Array.isArray(context.activity.reactionsAdded) &&
348
+ context.activity.reactionsAdded.length > 0
349
+ }
350
+
351
+ this.addRoute(selector, handler)
352
+ return this
353
+ }
354
+
355
+ /**
356
+ * Adds a handler for message reaction removed events.
357
+ *
358
+ * @param handler - The handler function that will be called when a message reaction is removed.
359
+ * @returns The current instance of the application.
360
+ *
361
+ * @remarks
362
+ * This method registers a handler that will be invoked when a user removes a reaction from a message,
363
+ * such as unliking or removing an emoji reaction.
364
+ *
365
+ * Example usage:
366
+ * ```typescript
367
+ * app.onMessageReactionRemoved(async (context, state) => {
368
+ * const reactionsRemoved = context.activity.reactionsRemoved;
369
+ * if (reactionsRemoved && reactionsRemoved.length > 0) {
370
+ * await context.sendActivity(`You removed your ${reactionsRemoved[0].type} reaction.`);
371
+ * }
372
+ * });
373
+ * ```
374
+ */
375
+ public onMessageReactionRemoved (handler: (context: TurnContext, state: TState) => Promise<void>): this {
376
+ const selector = async (context: TurnContext): Promise<boolean> => {
377
+ return context.activity.type === ActivityTypes.MessageReaction &&
378
+ Array.isArray(context.activity.reactionsRemoved) &&
379
+ context.activity.reactionsRemoved.length > 0
380
+ }
381
+
382
+ this.addRoute(selector, handler)
383
+ return this
384
+ }
385
+
325
386
  /**
326
387
  * Executes the application logic for a given turn context.
327
388
  *
@@ -355,8 +416,19 @@ export class AgentApplication<TState extends TurnState> {
355
416
  */
356
417
  public async runInternal (turnContext: TurnContext): Promise<boolean> {
357
418
  return await this.startLongRunningCall(turnContext, async (context) => {
358
- this.startTypingTimer(context)
359
419
  try {
420
+ if (this._options.startTypingTimer) {
421
+ this.startTypingTimer(context)
422
+ }
423
+
424
+ if (this._options.removeRecipientMention && context.activity.type === ActivityTypes.Message) {
425
+ context.activity.removeRecipientMention()
426
+ }
427
+
428
+ if (this._options.normalizeMentions && context.activity.type === ActivityTypes.Message) {
429
+ context.activity.normalizeMentions()
430
+ }
431
+
360
432
  const { storage, turnStateFactory } = this._options
361
433
  const state = turnStateFactory()
362
434
  await state.load(context, storage)
@@ -497,6 +569,14 @@ export class AgentApplication<TState extends TurnState> {
497
569
  }
498
570
  }
499
571
 
572
+ public registerExtension<T extends AgentExtension<TState>> (extension: T, regcb : (ext:T) => void): void {
573
+ if (this._extensions.includes(extension)) {
574
+ throw new Error('Extension already registered')
575
+ }
576
+ this._extensions.push(extension)
577
+ regcb(extension)
578
+ }
579
+
500
580
  /**
501
581
  * Stops the typing indicator timer if it's currently running.
502
582
  *
@@ -3,11 +3,11 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ import { Storage } from '../storage'
6
7
  import { AgentApplication } from './agentApplication'
7
8
  import { AgentApplicationOptions } from './agentApplicationOptions'
8
- import { TurnState } from './turnState'
9
- import { Storage } from '../storage'
10
9
  import { AuthorizationHandlers } from './oauth/authorization'
10
+ import { TurnState } from './turnState'
11
11
 
12
12
  /**
13
13
  * Builder class for creating and configuring AgentApplication instances.
@@ -4,10 +4,11 @@
4
4
  */
5
5
 
6
6
  import { CloudAdapter } from '../cloudAdapter'
7
- import { InputFileDownloader } from './inputFileDownloader'
8
- import { TurnState } from './turnState'
9
7
  import { Storage } from '../storage'
8
+ import { AdaptiveCardsOptions } from './adaptiveCards'
9
+ import { InputFileDownloader } from './inputFileDownloader'
10
10
  import { AuthorizationHandlers } from './oauth/authorization'
11
+ import { TurnState } from './turnState'
11
12
 
12
13
  export interface AgentApplicationOptions<TState extends TurnState> {
13
14
  /**
@@ -49,4 +50,21 @@ export interface AgentApplicationOptions<TState extends TurnState> {
49
50
  * Handlers for managing authorization.
50
51
  */
51
52
  authorization?: AuthorizationHandlers;
53
+
54
+ /**
55
+ * Options for AdaptiveCard actions.
56
+ */
57
+ adaptiveCardsOptions?: AdaptiveCardsOptions;
58
+
59
+ /**
60
+ * Optional. If true, the agent will automatically remove mentions of the bot's name from incoming
61
+ * messages. Defaults to true.
62
+ */
63
+ removeRecipientMention?: boolean;
64
+
65
+ /**
66
+ * Optional. If true, the agent will automatically normalize mentions in incoming messages. Defaults to
67
+ * true.
68
+ */
69
+ normalizeMentions?: boolean
52
70
  }
@@ -17,4 +17,10 @@ export interface AppRoute<TState extends TurnState> {
17
17
  * The handler function that processes the activity if the selector matches.
18
18
  */
19
19
  handler: RouteHandler<TState>;
20
+
21
+ /**
22
+ * Indicates whether this route is an invoke route.
23
+ * Invoke routes are used for specific types of activities, such as messaging extensions.
24
+ */
25
+ isInvokeRoute?: boolean;
20
26
  }
@@ -46,6 +46,7 @@ export class AttachmentDownloader<TState extends TurnState = TurnState> implemen
46
46
  return Promise.resolve([])
47
47
  }
48
48
 
49
+ // TODO: from adapter
49
50
  const authProvider: AuthProvider = new MsalTokenProvider()
50
51
 
51
52
  const accessToken = await authProvider.getAccessToken(loadAuthConfigFromEnv(), 'https://api.botframework.com')
@@ -0,0 +1,19 @@
1
+ import { TurnContext } from '../turnContext'
2
+ import { AgentApplication } from './agentApplication'
3
+ import { RouteHandler } from './routeHandler'
4
+ import { RouteSelector } from './routeSelector'
5
+ import { TurnState } from './turnState'
6
+
7
+ export class AgentExtension<TState extends TurnState> {
8
+ channelId: string
9
+ constructor (channelId: string) {
10
+ this.channelId = channelId
11
+ }
12
+
13
+ addRoute (app: AgentApplication<TState>, routeSelector: RouteSelector, routeHandler: RouteHandler<TurnState>, isInvokeRoute: boolean = false) {
14
+ const ensureChannelMatches = async (context: TurnContext) => {
15
+ return context.activity.channelId === this.channelId && routeSelector(context)
16
+ }
17
+ app.addRoute(ensureChannelMatches, routeHandler)
18
+ }
19
+ }
package/src/app/index.ts CHANGED
@@ -12,3 +12,5 @@ export * from './turnEvents'
12
12
  export * from './turnStateEntry'
13
13
  export * from './inputFileDownloader'
14
14
  export * from './appMemory'
15
+ export * from './extensions'
16
+ export * from './adaptiveCards'
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ClientCitation } from './clientCitation'
7
+ import { SensitivityUsageInfo } from './sensitivityUsageInfo'
8
+
9
+ export interface AIEntity {
10
+ /**
11
+ * Required as 'https://schema.org/Message'
12
+ */
13
+ type: 'https://schema.org/Message';
14
+
15
+ /**
16
+ * Required as 'Message
17
+ */
18
+ '@type': 'Message';
19
+
20
+ /**
21
+ * Required as 'https://schema.org
22
+ */
23
+ '@context': 'https://schema.org';
24
+
25
+ /**
26
+ * Must be left blank. This is for Bot Framework schema.
27
+ */
28
+ '@id': '';
29
+
30
+ /**
31
+ * Indicate that the content was generated by AI.
32
+ */
33
+ additionalType: ['AIGeneratedContent'];
34
+
35
+ /**
36
+ * Optional; if citations object is included, the sent activity will include the citations, referenced in the activity text.
37
+ */
38
+ citation?: ClientCitation[];
39
+
40
+ /**
41
+ * Optional; if usage_info object is included, the sent activity will include the sensitivity usage information.
42
+ */
43
+ usageInfo?: SensitivityUsageInfo;
44
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ /**
7
+ * An action call to be requested by the LLM model. This type is a generic meant to be the equivalent of OpenAI's [`ChatCompletionMessageToolCall`](https://github.com/openai/openai-node/blob/master/src/resources/chat/completions.ts#L477), but is not tied to OpenAI's implementation in order to allow for flexibility for other models in the future.
8
+ */
9
+ export interface ActionCall {
10
+ /**
11
+ * The ID of the tool call.
12
+ */
13
+ id: string;
14
+
15
+ /**
16
+ * The function that the model called.
17
+ */
18
+ function: {
19
+ /**
20
+ * The name of the function.
21
+ */
22
+ name: string;
23
+
24
+ /**
25
+ * The arguments to call the function with, as generated by the model in JSON
26
+ * format. Note that the model does not always generate valid JSON, and may
27
+ * hallucinate parameters not defined by your function schema. Validate the
28
+ * arguments in your code before calling your function.
29
+ */
30
+ arguments: string;
31
+ };
32
+
33
+ /**
34
+ * The type of the tool. Currently, only `function` is supported.
35
+ */
36
+ type: 'function';
37
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @module teams-ai
3
+ */
4
+ /**
5
+ * Copyright (c) Microsoft Corporation. All rights reserved.
6
+ * Licensed under the MIT License.
7
+ */
8
+
9
+ import { SensitivityUsageInfo } from './sensitivityUsageInfo'
10
+
11
+ export type ClientCitationIconName =
12
+ | 'Microsoft Word'
13
+ | 'Microsoft Excel'
14
+ | 'Microsoft PowerPoint'
15
+ | 'Microsoft OneNote'
16
+ | 'Microsoft SharePoint'
17
+ | 'Microsoft Visio'
18
+ | 'Microsoft Loop'
19
+ | 'Microsoft Whiteboard'
20
+ | 'Adobe Illustrator'
21
+ | 'Adobe Photoshop'
22
+ | 'Adobe InDesign'
23
+ | 'Adobe Flash'
24
+ | 'Sketch'
25
+ | 'Source Code'
26
+ | 'Image'
27
+ | 'GIF'
28
+ | 'Video'
29
+ | 'Sound'
30
+ | 'ZIP'
31
+ | 'Text'
32
+ | 'PDF'
33
+
34
+ /**
35
+ * Represents a Teams client citation to be included in a message. See Bot messages with AI-generated content for more details.
36
+ * https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/bot-messages-ai-generated-content?tabs=before%2Cbotmessage
37
+ */
38
+ export interface ClientCitation {
39
+ /**
40
+ * Required; must be "Claim"
41
+ */
42
+ '@type': 'Claim';
43
+
44
+ /**
45
+ * Required. Number and position of the citation.
46
+ */
47
+ position: number;
48
+ appearance: {
49
+ /**
50
+ * Required; Must be 'DigitalDocument'
51
+ */
52
+ '@type': 'DigitalDocument';
53
+
54
+ /**
55
+ * Name of the document. (max length 80)
56
+ */
57
+ name: string;
58
+
59
+ /**
60
+ * Stringified adaptive card with additional information about the citation.
61
+ * It is rendered within the modal.
62
+ */
63
+ text?: string;
64
+
65
+ /**
66
+ * URL of the document. This will make the name of the citation clickable and direct the user to the specified URL.
67
+ */
68
+ url?: string;
69
+
70
+ /**
71
+ * Extract of the referenced content. (max length 160)
72
+ */
73
+ abstract: string;
74
+
75
+ /**
76
+ * Encoding format of the `citation.appearance.text` field.
77
+ */
78
+ encodingFormat?: 'application/vnd.microsoft.card.adaptive';
79
+
80
+ /**
81
+ * Information about the citation’s icon.
82
+ */
83
+ image?: {
84
+ '@type': 'ImageObject';
85
+
86
+ /**
87
+ * The image/icon name
88
+ */
89
+ name: ClientCitationIconName;
90
+ };
91
+
92
+ /**
93
+ * Optional; set by developer. (max length 3) (max keyword length 28)
94
+ */
95
+ keywords?: string[];
96
+
97
+ /**
98
+ * Optional sensitivity content information.
99
+ */
100
+ usageInfo?: SensitivityUsageInfo;
101
+ };
102
+ }
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ActionCall } from './actionCall'
7
+
8
+ /**
9
+ * A message object sent to or received from an LLM.
10
+ * @param TContent Optional. Type of the message content. Defaults to `string`
11
+ */
12
+ export interface Message<TContent = string> {
13
+ /**
14
+ * The messages role. Typically 'system', 'user', 'assistant', 'tool', 'function'.
15
+ */
16
+ role: string;
17
+
18
+ /**
19
+ * Text of the message.
20
+ */
21
+ content: TContent | undefined;
22
+
23
+ /**
24
+ * Optional. A named function to call.
25
+ */
26
+ function_call?: FunctionCall;
27
+
28
+ /**
29
+ * The context used for the message.
30
+ */
31
+ context?: MessageContext;
32
+
33
+ /**
34
+ * Optional. Name of the function that was called.
35
+ */
36
+ name?: string;
37
+
38
+ /**
39
+ * Optional. The action or tool to be called by the model when using 'tools' augmentation. In OpenAI, this is the tool_calls property returned from the model.
40
+ */
41
+ action_calls?: ActionCall[];
42
+
43
+ /**
44
+ * Optional. The id of the action called.
45
+ */
46
+ action_call_id?: string | undefined;
47
+ }
48
+
49
+ /**
50
+ * A named function to call.
51
+ */
52
+ export interface FunctionCall {
53
+ /**
54
+ * Name of the function to call.
55
+ */
56
+ name?: string;
57
+
58
+ /**
59
+ * Optional. Arguments to pass to the function. Must be deserialized.
60
+ */
61
+ arguments?: string;
62
+ }
63
+
64
+ export type MessageContentParts = TextContentPart | ImageContentPart
65
+
66
+ export interface TextContentPart {
67
+ /**
68
+ * Type of the message content. Should always be 'text'.
69
+ */
70
+ type: 'text';
71
+
72
+ /**
73
+ * The text of the message.
74
+ */
75
+ text: string;
76
+ }
77
+
78
+ export interface ImageContentPart {
79
+ /**
80
+ * Type of the message content. Should always be 'image_url'.
81
+ */
82
+ type: 'image_url';
83
+
84
+ /**
85
+ * The URL of the image.
86
+ */
87
+ image_url: string | { url: string };
88
+ }
89
+
90
+ /**
91
+ * Citations returned by the model.
92
+ */
93
+ export interface Citation {
94
+ /**
95
+ * The content of the citation.
96
+ */
97
+ content: string;
98
+
99
+ /**
100
+ * The title of the citation.
101
+ */
102
+ title: string | null;
103
+
104
+ /**
105
+ * The URL of the citation.
106
+ */
107
+ url: string | null;
108
+
109
+ /**
110
+ * The filepath of the document.
111
+ */
112
+ filepath: string | null;
113
+ }
114
+
115
+ export interface MessageContext {
116
+ /**
117
+ * Citations used in the message.
118
+ */
119
+ citations: Citation[];
120
+
121
+ /**
122
+ * The intent of the message (what the user wrote).
123
+ */
124
+ intent: string;
125
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Sensitivity usage info for content sent to the user. This is used to provide information about the content to the user. See ClientCitation for more information.
3
+ */
4
+ export interface SensitivityUsageInfo {
5
+ /**
6
+ * Must be "https://schema.org/Message"
7
+ */
8
+ type: 'https://schema.org/Message';
9
+
10
+ /**
11
+ * Required; Set to CreativeWork;
12
+ */
13
+ '@type': 'CreativeWork';
14
+
15
+ /**
16
+ * Sensitivity description of the content
17
+ */
18
+ description?: string;
19
+
20
+ /**
21
+ * Sensitivity title of the content
22
+ */
23
+ name: string;
24
+
25
+ /**
26
+ * Optional; ignored in Teams.
27
+ */
28
+ position?: number;
29
+
30
+ pattern?: {
31
+ /**
32
+ * Set to DefinedTerm
33
+ */
34
+ '@type': 'DefinedTerm';
35
+
36
+ inDefinedTermSet: string;
37
+
38
+ /**
39
+ * Color
40
+ */
41
+ name: string;
42
+
43
+ /**
44
+ * e.g. #454545
45
+ */
46
+ termCode: string;
47
+ };
48
+ }