2
2
// Licensed under the MIT License.
3
3
4
4
import { CommandHandlerContext } from "../../commandHandlerContext.js" ;
5
- import { ActionContext , ParsedCommandParams } from "@typeagent/agent-sdk" ;
5
+ import {
6
+ ActionContext ,
7
+ CompletionGroup ,
8
+ ParsedCommandParams ,
9
+ SessionContext ,
10
+ } from "@typeagent/agent-sdk" ;
6
11
import { CommandHandler } from "@typeagent/agent-sdk/helpers/command" ;
7
12
import { displayResult } from "@typeagent/agent-sdk/helpers/display" ;
8
13
import { getColorElapsedString } from "common-utils" ;
9
14
import { translateRequest } from "../../../translation/translateRequest.js" ;
15
+ import { requestCompletion } from "../../../translation/requestCompletion.js" ;
10
16
11
17
export class TranslateCommandHandler implements CommandHandler {
12
18
public readonly description = "Translate a request" ;
@@ -26,21 +32,37 @@ export class TranslateCommandHandler implements CommandHandler {
26
32
params . args . request ,
27
33
context ,
28
34
) ;
29
- if ( translationResult ) {
30
- const elapsedStr = getColorElapsedString (
31
- translationResult . elapsedMs ,
32
- ) ;
33
- const usageStr = translationResult . tokenUsage
34
- ? `(Tokens: ${ translationResult . tokenUsage . prompt_tokens } + ${ translationResult . tokenUsage . completion_tokens } = ${ translationResult . tokenUsage . total_tokens } )`
35
- : "" ;
36
- displayResult (
37
- `${ translationResult . requestAction } ${ elapsedStr } ${ usageStr } \n\nJSON:\n${ JSON . stringify (
38
- translationResult . requestAction . actions ,
39
- undefined ,
40
- 2 ,
41
- ) } `,
42
- context ,
43
- ) ;
35
+
36
+ const elapsedStr = getColorElapsedString ( translationResult . elapsedMs ) ;
37
+ const usageStr = translationResult . tokenUsage
38
+ ? `(Tokens: ${ translationResult . tokenUsage . prompt_tokens } + ${ translationResult . tokenUsage . completion_tokens } = ${ translationResult . tokenUsage . total_tokens } )`
39
+ : "" ;
40
+ displayResult (
41
+ `${ translationResult . requestAction } ${ elapsedStr } ${ usageStr } \n\nJSON:\n${ JSON . stringify (
42
+ translationResult . requestAction . actions ,
43
+ undefined ,
44
+ 2 ,
45
+ ) } `,
46
+ context ,
47
+ ) ;
48
+ }
49
+ public async getCompletion (
50
+ context : SessionContext < CommandHandlerContext > ,
51
+ params : ParsedCommandParams < typeof this . parameters > ,
52
+ names : string [ ] ,
53
+ ) : Promise < CompletionGroup [ ] > {
54
+ const completions : CompletionGroup [ ] = [ ] ;
55
+ for ( const name of names ) {
56
+ if ( name === "request" ) {
57
+ const requestPrefix = params . args . request ;
58
+ completions . push (
59
+ ...( await requestCompletion (
60
+ requestPrefix ,
61
+ context . agentContext ,
62
+ ) ) ,
63
+ ) ;
64
+ }
44
65
}
66
+ return completions ;
45
67
}
46
68
}
0 commit comments