@microsoft/agents-hosting 0.5.1-g2e246ff274 → 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 (33) hide show
  1. package/dist/src/app/streaming/AIEntity.d.ts +36 -0
  2. package/dist/src/app/streaming/AIEntity.js +7 -0
  3. package/dist/src/app/streaming/AIEntity.js.map +1 -0
  4. package/dist/src/app/streaming/actionCall.d.ts +33 -0
  5. package/dist/src/app/streaming/actionCall.js +7 -0
  6. package/dist/src/app/streaming/actionCall.js.map +1 -0
  7. package/dist/src/app/streaming/clientCitation.d.ts +68 -0
  8. package/dist/src/app/streaming/clientCitation.js +10 -0
  9. package/dist/src/app/streaming/clientCitation.js.map +1 -0
  10. package/dist/src/app/streaming/message.d.ts +106 -0
  11. package/dist/src/app/streaming/message.js +7 -0
  12. package/dist/src/app/streaming/message.js.map +1 -0
  13. package/dist/src/app/streaming/sensitivityUsageInfo.d.ts +40 -0
  14. package/dist/src/app/streaming/sensitivityUsageInfo.js +3 -0
  15. package/dist/src/app/streaming/sensitivityUsageInfo.js.map +1 -0
  16. package/dist/src/app/streaming/streamingResponse.d.ts +141 -0
  17. package/dist/src/app/streaming/streamingResponse.js +331 -0
  18. package/dist/src/app/streaming/streamingResponse.js.map +1 -0
  19. package/dist/src/app/streaming/utilities.d.ts +31 -0
  20. package/dist/src/app/streaming/utilities.js +101 -0
  21. package/dist/src/app/streaming/utilities.js.map +1 -0
  22. package/dist/src/turnContext.d.ts +3 -0
  23. package/dist/src/turnContext.js +5 -0
  24. package/dist/src/turnContext.js.map +1 -1
  25. package/package.json +2 -2
  26. package/src/app/streaming/AIEntity.ts +44 -0
  27. package/src/app/streaming/actionCall.ts +37 -0
  28. package/src/app/streaming/clientCitation.ts +102 -0
  29. package/src/app/streaming/message.ts +125 -0
  30. package/src/app/streaming/sensitivityUsageInfo.ts +48 -0
  31. package/src/app/streaming/streamingResponse.ts +406 -0
  32. package/src/app/streaming/utilities.ts +108 -0
  33. package/src/turnContext.ts +7 -1
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { ClientCitation } from './clientCitation';
6
+ import { SensitivityUsageInfo } from './sensitivityUsageInfo';
7
+ export interface AIEntity {
8
+ /**
9
+ * Required as 'https://schema.org/Message'
10
+ */
11
+ type: 'https://schema.org/Message';
12
+ /**
13
+ * Required as 'Message
14
+ */
15
+ '@type': 'Message';
16
+ /**
17
+ * Required as 'https://schema.org
18
+ */
19
+ '@context': 'https://schema.org';
20
+ /**
21
+ * Must be left blank. This is for Bot Framework schema.
22
+ */
23
+ '@id': '';
24
+ /**
25
+ * Indicate that the content was generated by AI.
26
+ */
27
+ additionalType: ['AIGeneratedContent'];
28
+ /**
29
+ * Optional; if citations object is included, the sent activity will include the citations, referenced in the activity text.
30
+ */
31
+ citation?: ClientCitation[];
32
+ /**
33
+ * Optional; if usage_info object is included, the sent activity will include the sensitivity usage information.
34
+ */
35
+ usageInfo?: SensitivityUsageInfo;
36
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=AIEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AIEntity.js","sourceRoot":"","sources":["../../../../src/app/streaming/AIEntity.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * 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.
7
+ */
8
+ export interface ActionCall {
9
+ /**
10
+ * The ID of the tool call.
11
+ */
12
+ id: string;
13
+ /**
14
+ * The function that the model called.
15
+ */
16
+ function: {
17
+ /**
18
+ * The name of the function.
19
+ */
20
+ name: string;
21
+ /**
22
+ * The arguments to call the function with, as generated by the model in JSON
23
+ * format. Note that the model does not always generate valid JSON, and may
24
+ * hallucinate parameters not defined by your function schema. Validate the
25
+ * arguments in your code before calling your function.
26
+ */
27
+ arguments: string;
28
+ };
29
+ /**
30
+ * The type of the tool. Currently, only `function` is supported.
31
+ */
32
+ type: 'function';
33
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=actionCall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionCall.js","sourceRoot":"","sources":["../../../../src/app/streaming/actionCall.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @module teams-ai
3
+ */
4
+ /**
5
+ * Copyright (c) Microsoft Corporation. All rights reserved.
6
+ * Licensed under the MIT License.
7
+ */
8
+ import { SensitivityUsageInfo } from './sensitivityUsageInfo';
9
+ export type ClientCitationIconName = 'Microsoft Word' | 'Microsoft Excel' | 'Microsoft PowerPoint' | 'Microsoft OneNote' | 'Microsoft SharePoint' | 'Microsoft Visio' | 'Microsoft Loop' | 'Microsoft Whiteboard' | 'Adobe Illustrator' | 'Adobe Photoshop' | 'Adobe InDesign' | 'Adobe Flash' | 'Sketch' | 'Source Code' | 'Image' | 'GIF' | 'Video' | 'Sound' | 'ZIP' | 'Text' | 'PDF';
10
+ /**
11
+ * Represents a Teams client citation to be included in a message. See Bot messages with AI-generated content for more details.
12
+ * https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/bot-messages-ai-generated-content?tabs=before%2Cbotmessage
13
+ */
14
+ export interface ClientCitation {
15
+ /**
16
+ * Required; must be "Claim"
17
+ */
18
+ '@type': 'Claim';
19
+ /**
20
+ * Required. Number and position of the citation.
21
+ */
22
+ position: number;
23
+ appearance: {
24
+ /**
25
+ * Required; Must be 'DigitalDocument'
26
+ */
27
+ '@type': 'DigitalDocument';
28
+ /**
29
+ * Name of the document. (max length 80)
30
+ */
31
+ name: string;
32
+ /**
33
+ * Stringified adaptive card with additional information about the citation.
34
+ * It is rendered within the modal.
35
+ */
36
+ text?: string;
37
+ /**
38
+ * URL of the document. This will make the name of the citation clickable and direct the user to the specified URL.
39
+ */
40
+ url?: string;
41
+ /**
42
+ * Extract of the referenced content. (max length 160)
43
+ */
44
+ abstract: string;
45
+ /**
46
+ * Encoding format of the `citation.appearance.text` field.
47
+ */
48
+ encodingFormat?: 'application/vnd.microsoft.card.adaptive';
49
+ /**
50
+ * Information about the citation’s icon.
51
+ */
52
+ image?: {
53
+ '@type': 'ImageObject';
54
+ /**
55
+ * The image/icon name
56
+ */
57
+ name: ClientCitationIconName;
58
+ };
59
+ /**
60
+ * Optional; set by developer. (max length 3) (max keyword length 28)
61
+ */
62
+ keywords?: string[];
63
+ /**
64
+ * Optional sensitivity content information.
65
+ */
66
+ usageInfo?: SensitivityUsageInfo;
67
+ };
68
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /**
3
+ * @module teams-ai
4
+ */
5
+ /**
6
+ * Copyright (c) Microsoft Corporation. All rights reserved.
7
+ * Licensed under the MIT License.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ //# sourceMappingURL=clientCitation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientCitation.js","sourceRoot":"","sources":["../../../../src/app/streaming/clientCitation.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH;;;GAGG"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { ActionCall } from './actionCall';
6
+ /**
7
+ * A message object sent to or received from an LLM.
8
+ * @param TContent Optional. Type of the message content. Defaults to `string`
9
+ */
10
+ export interface Message<TContent = string> {
11
+ /**
12
+ * The messages role. Typically 'system', 'user', 'assistant', 'tool', 'function'.
13
+ */
14
+ role: string;
15
+ /**
16
+ * Text of the message.
17
+ */
18
+ content: TContent | undefined;
19
+ /**
20
+ * Optional. A named function to call.
21
+ */
22
+ function_call?: FunctionCall;
23
+ /**
24
+ * The context used for the message.
25
+ */
26
+ context?: MessageContext;
27
+ /**
28
+ * Optional. Name of the function that was called.
29
+ */
30
+ name?: string;
31
+ /**
32
+ * 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.
33
+ */
34
+ action_calls?: ActionCall[];
35
+ /**
36
+ * Optional. The id of the action called.
37
+ */
38
+ action_call_id?: string | undefined;
39
+ }
40
+ /**
41
+ * A named function to call.
42
+ */
43
+ export interface FunctionCall {
44
+ /**
45
+ * Name of the function to call.
46
+ */
47
+ name?: string;
48
+ /**
49
+ * Optional. Arguments to pass to the function. Must be deserialized.
50
+ */
51
+ arguments?: string;
52
+ }
53
+ export type MessageContentParts = TextContentPart | ImageContentPart;
54
+ export interface TextContentPart {
55
+ /**
56
+ * Type of the message content. Should always be 'text'.
57
+ */
58
+ type: 'text';
59
+ /**
60
+ * The text of the message.
61
+ */
62
+ text: string;
63
+ }
64
+ export interface ImageContentPart {
65
+ /**
66
+ * Type of the message content. Should always be 'image_url'.
67
+ */
68
+ type: 'image_url';
69
+ /**
70
+ * The URL of the image.
71
+ */
72
+ image_url: string | {
73
+ url: string;
74
+ };
75
+ }
76
+ /**
77
+ * Citations returned by the model.
78
+ */
79
+ export interface Citation {
80
+ /**
81
+ * The content of the citation.
82
+ */
83
+ content: string;
84
+ /**
85
+ * The title of the citation.
86
+ */
87
+ title: string | null;
88
+ /**
89
+ * The URL of the citation.
90
+ */
91
+ url: string | null;
92
+ /**
93
+ * The filepath of the document.
94
+ */
95
+ filepath: string | null;
96
+ }
97
+ export interface MessageContext {
98
+ /**
99
+ * Citations used in the message.
100
+ */
101
+ citations: Citation[];
102
+ /**
103
+ * The intent of the message (what the user wrote).
104
+ */
105
+ intent: string;
106
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../src/app/streaming/message.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
@@ -0,0 +1,40 @@
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
+ * Required; Set to CreativeWork;
11
+ */
12
+ '@type': 'CreativeWork';
13
+ /**
14
+ * Sensitivity description of the content
15
+ */
16
+ description?: string;
17
+ /**
18
+ * Sensitivity title of the content
19
+ */
20
+ name: string;
21
+ /**
22
+ * Optional; ignored in Teams.
23
+ */
24
+ position?: number;
25
+ pattern?: {
26
+ /**
27
+ * Set to DefinedTerm
28
+ */
29
+ '@type': 'DefinedTerm';
30
+ inDefinedTermSet: string;
31
+ /**
32
+ * Color
33
+ */
34
+ name: string;
35
+ /**
36
+ * e.g. #454545
37
+ */
38
+ termCode: string;
39
+ };
40
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=sensitivityUsageInfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sensitivityUsageInfo.js","sourceRoot":"","sources":["../../../../src/app/streaming/sensitivityUsageInfo.ts"],"names":[],"mappings":""}
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { Attachment } from '@microsoft/agents-activity';
6
+ import { TurnContext } from '../../turnContext';
7
+ import { ClientCitation } from './clientCitation';
8
+ import { SensitivityUsageInfo } from './sensitivityUsageInfo';
9
+ import { Citation } from './message';
10
+ /**
11
+ * A helper class for streaming responses to the client.
12
+ * @remarks
13
+ * This class is used to send a series of updates to the client in a single response. The expected
14
+ * sequence of calls is:
15
+ *
16
+ * `sendInformativeUpdate()`, `sendTextChunk()`, `sendTextChunk()`, ..., `endStream()`.
17
+ *
18
+ * Once `endStream()` is called, the stream is considered ended and no further updates can be sent.
19
+ */
20
+ export declare class StreamingResponse {
21
+ private readonly _context;
22
+ private _nextSequence;
23
+ private _streamId?;
24
+ private _message;
25
+ private _attachments?;
26
+ private _ended;
27
+ private _queue;
28
+ private _queueSync;
29
+ private _chunkQueued;
30
+ private _enableFeedbackLoop;
31
+ private _feedbackLoopType?;
32
+ private _enableGeneratedByAILabel;
33
+ private _citations?;
34
+ private _sensitivityLabel?;
35
+ /**
36
+ * Creates a new StreamingResponse instance.
37
+ * @param {TurnContext} context - Context for the current turn of conversation with the user.
38
+ * @returns {TurnContext} - The context for the current turn of conversation with the user.
39
+ */
40
+ constructor(context: TurnContext);
41
+ /**
42
+ * Gets the stream ID of the current response.
43
+ * @returns {string | undefined} - The stream ID of the current response.
44
+ * @remarks
45
+ * Assigned after the initial update is sent.
46
+ */
47
+ get streamId(): string | undefined;
48
+ /**
49
+ * Gets the citations of the current response.
50
+ */
51
+ get citations(): ClientCitation[] | undefined;
52
+ /**
53
+ * Gets the number of updates sent for the stream.
54
+ * @returns {number} - The number of updates sent for the stream.
55
+ */
56
+ get updatesSent(): number;
57
+ /**
58
+ * Queues an informative update to be sent to the client.
59
+ * @param {string} text Text of the update to send.
60
+ */
61
+ queueInformativeUpdate(text: string): void;
62
+ /**
63
+ * Queues a chunk of partial message text to be sent to the client
64
+ * @remarks
65
+ * The text we be sent as quickly as possible to the client. Chunks may be combined before
66
+ * delivery to the client.
67
+ * @param {string} text Partial text of the message to send.
68
+ * @param {Citation[]} citations Citations to be included in the message.
69
+ */
70
+ queueTextChunk(text: string, citations?: Citation[]): void;
71
+ /**
72
+ * Ends the stream by sending the final message to the client.
73
+ * @returns {Promise<void>} - A promise representing the async operation
74
+ */
75
+ endStream(): Promise<void>;
76
+ /**
77
+ * Sets the attachments to attach to the final chunk.
78
+ * @param attachments List of attachments.
79
+ */
80
+ setAttachments(attachments: Attachment[]): void;
81
+ /**
82
+ * Sets the sensitivity label to attach to the final chunk.
83
+ * @param sensitivityLabel The sensitivty label.
84
+ */
85
+ setSensitivityLabel(sensitivityLabel: SensitivityUsageInfo): void;
86
+ /**
87
+ * Sets the citations for the full message.
88
+ * @param {Citation[]} citations Citations to be included in the message.
89
+ */
90
+ setCitations(citations: Citation[]): void;
91
+ /**
92
+ * Sets the Feedback Loop in Teams that allows a user to
93
+ * give thumbs up or down to a response.
94
+ * Default is `false`.
95
+ * @param enableFeedbackLoop If true, the feedback loop is enabled.
96
+ */
97
+ setFeedbackLoop(enableFeedbackLoop: boolean): void;
98
+ /**
99
+ * Sets the type of UI to use for the feedback loop.
100
+ * @param feedbackLoopType The type of the feedback loop.
101
+ */
102
+ setFeedbackLoopType(feedbackLoopType: 'default' | 'custom'): void;
103
+ /**
104
+ * Sets the the Generated by AI label in Teams
105
+ * Default is `false`.
106
+ * @param enableGeneratedByAILabel If true, the label is added.
107
+ */
108
+ setGeneratedByAILabel(enableGeneratedByAILabel: boolean): void;
109
+ /**
110
+ * Returns the most recently streamed message.
111
+ * @returns The streamed message.
112
+ */
113
+ getMessage(): string;
114
+ /**
115
+ * Waits for the outgoing activity queue to be empty.
116
+ * @returns {Promise<void>} - A promise representing the async operation.
117
+ */
118
+ waitForQueue(): Promise<void>;
119
+ /**
120
+ * Queues the next chunk of text to be sent to the client.
121
+ * @private
122
+ */
123
+ private queueNextChunk;
124
+ /**
125
+ * Queues an activity to be sent to the client.
126
+ */
127
+ private queueActivity;
128
+ /**
129
+ * Sends any queued activities to the client until the queue is empty.
130
+ * @returns {Promise<void>} - A promise that will be resolved once the queue is empty.
131
+ * @private
132
+ */
133
+ private drainQueue;
134
+ /**
135
+ * Sends an activity to the client and saves the stream ID returned.
136
+ * @param {Activity} activity - The activity to send.
137
+ * @returns {Promise<void>} - A promise representing the async operation.
138
+ * @private
139
+ */
140
+ private sendActivity;
141
+ }