@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.
- package/dist/src/app/streaming/AIEntity.d.ts +36 -0
- package/dist/src/app/streaming/AIEntity.js +7 -0
- package/dist/src/app/streaming/AIEntity.js.map +1 -0
- package/dist/src/app/streaming/actionCall.d.ts +33 -0
- package/dist/src/app/streaming/actionCall.js +7 -0
- package/dist/src/app/streaming/actionCall.js.map +1 -0
- package/dist/src/app/streaming/clientCitation.d.ts +68 -0
- package/dist/src/app/streaming/clientCitation.js +10 -0
- package/dist/src/app/streaming/clientCitation.js.map +1 -0
- package/dist/src/app/streaming/message.d.ts +106 -0
- package/dist/src/app/streaming/message.js +7 -0
- package/dist/src/app/streaming/message.js.map +1 -0
- package/dist/src/app/streaming/sensitivityUsageInfo.d.ts +40 -0
- package/dist/src/app/streaming/sensitivityUsageInfo.js +3 -0
- package/dist/src/app/streaming/sensitivityUsageInfo.js.map +1 -0
- package/dist/src/app/streaming/streamingResponse.d.ts +141 -0
- package/dist/src/app/streaming/streamingResponse.js +331 -0
- package/dist/src/app/streaming/streamingResponse.js.map +1 -0
- package/dist/src/app/streaming/utilities.d.ts +31 -0
- package/dist/src/app/streaming/utilities.js +101 -0
- package/dist/src/app/streaming/utilities.js.map +1 -0
- package/dist/src/turnContext.d.ts +3 -0
- package/dist/src/turnContext.js +5 -0
- package/dist/src/turnContext.js.map +1 -1
- package/package.json +2 -2
- package/src/app/streaming/AIEntity.ts +44 -0
- package/src/app/streaming/actionCall.ts +37 -0
- package/src/app/streaming/clientCitation.ts +102 -0
- package/src/app/streaming/message.ts +125 -0
- package/src/app/streaming/sensitivityUsageInfo.ts +48 -0
- package/src/app/streaming/streamingResponse.ts +406 -0
- package/src/app/streaming/utilities.ts +108 -0
- package/src/turnContext.ts +7 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ClientCitation } from './clientCitation'
|
|
7
|
+
|
|
8
|
+
// import { stringify } from 'yaml'
|
|
9
|
+
|
|
10
|
+
// import { Tokenizer } from './tokenizers'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Utility functions for manipulating .
|
|
14
|
+
*/
|
|
15
|
+
export class Utilities {
|
|
16
|
+
// /**
|
|
17
|
+
// * Converts a value to a string.
|
|
18
|
+
// * @remarks
|
|
19
|
+
// * Dates are converted to ISO strings and Objects are converted to JSON or YAML, whichever is shorter.
|
|
20
|
+
// * @param {Tokenizer} tokenizer Tokenizer to use for encoding.
|
|
21
|
+
// * @param {any} value Value to convert.
|
|
22
|
+
// * @param {boolean} asJSON Optional. If true objects will always be converted to JSON instead of YAML. Defaults to false.
|
|
23
|
+
// * @returns {string} Converted value.
|
|
24
|
+
// */
|
|
25
|
+
// public static toString (tokenizer: Tokenizer, value: any, asJSON: boolean = false): string {
|
|
26
|
+
// if (value === undefined || value === null) {
|
|
27
|
+
// return ''
|
|
28
|
+
// } else if (typeof value === 'object') {
|
|
29
|
+
// if (typeof value.toISOString === 'function') {
|
|
30
|
+
// return value.toISOString()
|
|
31
|
+
// } else if (asJSON) {
|
|
32
|
+
// return JSON.stringify(value)
|
|
33
|
+
// } else {
|
|
34
|
+
// // Return shorter version of object
|
|
35
|
+
// const asYaml = stringify(value)
|
|
36
|
+
// const asJSON = JSON.stringify(value)
|
|
37
|
+
// if (tokenizer.encode(asYaml).length <= tokenizer.encode(asJSON).length) {
|
|
38
|
+
// return asYaml
|
|
39
|
+
// } else {
|
|
40
|
+
// return asJSON
|
|
41
|
+
// }
|
|
42
|
+
// }
|
|
43
|
+
// } else {
|
|
44
|
+
// return value.toString()
|
|
45
|
+
// }
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* Clips the text to a maximum length in case it exceeds the limit.
|
|
51
|
+
* @param {string} text The text to clip.
|
|
52
|
+
* @param {number} maxLength The maximum length of the text to return, cutting off the last whole word.
|
|
53
|
+
* @returns {string} The modified text
|
|
54
|
+
*/
|
|
55
|
+
public static snippet (text: string, maxLength: number): string {
|
|
56
|
+
if (text.length <= maxLength) {
|
|
57
|
+
return text
|
|
58
|
+
}
|
|
59
|
+
let snippet = text.slice(0, maxLength)
|
|
60
|
+
snippet = snippet.slice(0, Math.min(snippet.length, snippet.lastIndexOf(' ')))
|
|
61
|
+
snippet += '...'
|
|
62
|
+
return snippet
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Convert citation tags `[doc(s)n]` to `[n]` where n is a number.
|
|
67
|
+
* @param {string} text The text to format.
|
|
68
|
+
* @returns {string} The formatted text.
|
|
69
|
+
*/
|
|
70
|
+
public static formatCitationsResponse (text: string): string {
|
|
71
|
+
return text.replace(/\[docs?(\d+)\]/gi, '[$1]')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get the citations used in the text. This will remove any citations that are included in the citations array from the response but not referenced in the text.
|
|
76
|
+
* @param {string} text - The text to search for citation references, i.e. [1], [2], etc.
|
|
77
|
+
* @param {ClientCitation[]} citations - The list of citations to search for.
|
|
78
|
+
* @returns {ClientCitation[] | undefined} The list of citations used in the text.
|
|
79
|
+
*/
|
|
80
|
+
public static getUsedCitations (text: string, citations: ClientCitation[]): ClientCitation[] | undefined {
|
|
81
|
+
const regex = /\[(\d+)\]/gi
|
|
82
|
+
const matches = text.match(regex)
|
|
83
|
+
|
|
84
|
+
if (!matches) {
|
|
85
|
+
return undefined
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Remove duplicates
|
|
89
|
+
const filteredMatches = new Set()
|
|
90
|
+
matches.forEach((match) => {
|
|
91
|
+
if (filteredMatches.has(match)) {
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
filteredMatches.add(match)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
// Add citations
|
|
99
|
+
const usedCitations: ClientCitation[] = []
|
|
100
|
+
filteredMatches.forEach((match) => {
|
|
101
|
+
const found = citations.find((citation) => `[${citation.position}]` === match)
|
|
102
|
+
if (found) {
|
|
103
|
+
usedCitations.push(found)
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
return usedCitations
|
|
107
|
+
}
|
|
108
|
+
}
|
package/src/turnContext.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { ResourceResponse } from './connector-client/resourceResponse'
|
|
|
6
6
|
import { TurnContextStateCollection } from './turnContextStateCollection'
|
|
7
7
|
import { AttachmentInfo } from './connector-client/attachmentInfo'
|
|
8
8
|
import { AttachmentData } from './connector-client/attachmentData'
|
|
9
|
+
import { StreamingResponse } from './app/streaming/streamingResponse'
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Defines a handler for processing and sending activities.
|
|
@@ -73,7 +74,7 @@ export class TurnContext {
|
|
|
73
74
|
private readonly _onDeleteActivity: DeleteActivityHandler[] = []
|
|
74
75
|
private readonly _turn = 'turn'
|
|
75
76
|
private readonly _locale = 'locale'
|
|
76
|
-
|
|
77
|
+
private readonly _streamingResponse: StreamingResponse
|
|
77
78
|
/**
|
|
78
79
|
* Initializes a new instance of the TurnContext class.
|
|
79
80
|
*
|
|
@@ -89,6 +90,7 @@ export class TurnContext {
|
|
|
89
90
|
this._adapter = adapterOrContext
|
|
90
91
|
this._activity = request as Activity
|
|
91
92
|
}
|
|
93
|
+
this._streamingResponse = new StreamingResponse(this)
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
/**
|
|
@@ -395,6 +397,10 @@ export class TurnContext {
|
|
|
395
397
|
return this._turnState
|
|
396
398
|
}
|
|
397
399
|
|
|
400
|
+
get streamingResponse (): StreamingResponse {
|
|
401
|
+
return this._streamingResponse
|
|
402
|
+
}
|
|
403
|
+
|
|
398
404
|
/**
|
|
399
405
|
* Emits events to registered middleware handlers.
|
|
400
406
|
*
|