@@ -22,7 +22,7 @@ import { ChatContext, ChatRequest } from './chat-model';
2222import { expect } from 'chai' ;
2323import { AIVariable , DefaultAIVariableService , ResolvedAIVariable , ToolInvocationRegistryImpl , ToolRequest } from '@theia/ai-core' ;
2424import { ILogger , Logger } from '@theia/core' ;
25- import { ParsedChatRequestTextPart , ParsedChatRequestVariablePart } from './parsed-chat-request' ;
25+ import { ParsedChatRequestAgentPart , ParsedChatRequestFunctionPart , ParsedChatRequestTextPart , ParsedChatRequestVariablePart } from './parsed-chat-request' ;
2626
2727describe ( 'ChatRequestParserImpl' , ( ) => {
2828 const chatAgentService = sinon . createStubInstance ( ChatAgentServiceImpl ) ;
@@ -42,10 +42,11 @@ describe('ChatRequestParserImpl', () => {
4242 } ;
4343 const context : ChatContext = { variables : [ ] } ;
4444 const result = await parser . parseChatRequest ( req , ChatAgentLocation . Panel , context ) ;
45- expect ( result . parts ) . to . deep . contain ( {
46- text : 'What is the best pizza topping?' ,
47- range : { start : 0 , endExclusive : 31 }
48- } ) ;
45+ expect ( result . parts . length ) . to . equal ( 1 ) ;
46+ const part = result . parts [ 0 ] as ParsedChatRequestTextPart ;
47+ expect ( part . kind ) . to . equal ( 'text' ) ;
48+ expect ( part . text ) . to . equal ( 'What is the best pizza topping?' ) ;
49+ expect ( part . range ) . to . deep . equal ( { start : 0 , endExclusive : 31 } ) ;
4950 } ) ;
5051
5152 it ( 'parses text with variable name' , async ( ) => {
@@ -54,19 +55,23 @@ describe('ChatRequestParserImpl', () => {
5455 } ;
5556 const context : ChatContext = { variables : [ ] } ;
5657 const result = await parser . parseChatRequest ( req , ChatAgentLocation . Panel , context ) ;
57- expect ( result ) . to . deep . contain ( {
58- parts : [ {
59- text : 'What is the ' ,
60- range : { start : 0 , endExclusive : 12 }
61- } , {
62- variableName : 'best' ,
63- variableArg : undefined ,
64- range : { start : 12 , endExclusive : 17 }
65- } , {
66- text : ' pizza topping?' ,
67- range : { start : 17 , endExclusive : 32 }
68- } ]
69- } ) ;
58+ expect ( result . parts . length ) . to . equal ( 3 ) ;
59+
60+ const textPart1 = result . parts [ 0 ] as ParsedChatRequestTextPart ;
61+ expect ( textPart1 . kind ) . to . equal ( 'text' ) ;
62+ expect ( textPart1 . text ) . to . equal ( 'What is the ' ) ;
63+ expect ( textPart1 . range ) . to . deep . equal ( { start : 0 , endExclusive : 12 } ) ;
64+
65+ const varPart = result . parts [ 1 ] as ParsedChatRequestVariablePart ;
66+ expect ( varPart . kind ) . to . equal ( 'var' ) ;
67+ expect ( varPart . variableName ) . to . equal ( 'best' ) ;
68+ expect ( varPart . variableArg ) . to . be . undefined ;
69+ expect ( varPart . range ) . to . deep . equal ( { start : 12 , endExclusive : 17 } ) ;
70+
71+ const textPart2 = result . parts [ 2 ] as ParsedChatRequestTextPart ;
72+ expect ( textPart2 . kind ) . to . equal ( 'text' ) ;
73+ expect ( textPart2 . text ) . to . equal ( ' pizza topping?' ) ;
74+ expect ( textPart2 . range ) . to . deep . equal ( { start : 17 , endExclusive : 32 } ) ;
7075 } ) ;
7176
7277 it ( 'parses text with variable name with argument' , async ( ) => {
@@ -75,19 +80,23 @@ describe('ChatRequestParserImpl', () => {
7580 } ;
7681 const context : ChatContext = { variables : [ ] } ;
7782 const result = await parser . parseChatRequest ( req , ChatAgentLocation . Panel , context ) ;
78- expect ( result ) . to . deep . contain ( {
79- parts : [ {
80- text : 'What is the ' ,
81- range : { start : 0 , endExclusive : 12 }
82- } , {
83- variableName : 'best' ,
84- variableArg : 'by-poll' ,
85- range : { start : 12 , endExclusive : 25 }
86- } , {
87- text : ' pizza topping?' ,
88- range : { start : 25 , endExclusive : 40 }
89- } ]
90- } ) ;
83+ expect ( result . parts . length ) . to . equal ( 3 ) ;
84+
85+ const textPart1 = result . parts [ 0 ] as ParsedChatRequestTextPart ;
86+ expect ( textPart1 . kind ) . to . equal ( 'text' ) ;
87+ expect ( textPart1 . text ) . to . equal ( 'What is the ' ) ;
88+ expect ( textPart1 . range ) . to . deep . equal ( { start : 0 , endExclusive : 12 } ) ;
89+
90+ const varPart = result . parts [ 1 ] as ParsedChatRequestVariablePart ;
91+ expect ( varPart . kind ) . to . equal ( 'var' ) ;
92+ expect ( varPart . variableName ) . to . equal ( 'best' ) ;
93+ expect ( varPart . variableArg ) . to . equal ( 'by-poll' ) ;
94+ expect ( varPart . range ) . to . deep . equal ( { start : 12 , endExclusive : 25 } ) ;
95+
96+ const textPart2 = result . parts [ 2 ] as ParsedChatRequestTextPart ;
97+ expect ( textPart2 . kind ) . to . equal ( 'text' ) ;
98+ expect ( textPart2 . text ) . to . equal ( ' pizza topping?' ) ;
99+ expect ( textPart2 . range ) . to . deep . equal ( { start : 25 , endExclusive : 40 } ) ;
91100 } ) ;
92101
93102 it ( 'parses text with variable name with numeric argument' , async ( ) => {
@@ -265,4 +274,32 @@ describe('ChatRequestParserImpl', () => {
265274 const varPart = result . parts [ 0 ] as ParsedChatRequestVariablePart ;
266275 expect ( varPart . variableArg ) . to . equal ( 'cmd|"arg with \\"quote\\"" other' ) ;
267276 } ) ;
277+
278+ describe ( 'parsed chat request part kind assignments' , ( ) => {
279+ it ( 'ParsedChatRequestTextPart has kind assigned at runtime' , ( ) => {
280+ const part = new ParsedChatRequestTextPart ( { start : 0 , endExclusive : 5 } , 'hello' ) ;
281+ expect ( part . kind ) . to . equal ( 'text' ) ;
282+ } ) ;
283+
284+ it ( 'ParsedChatRequestVariablePart has kind assigned at runtime' , ( ) => {
285+ const part = new ParsedChatRequestVariablePart ( { start : 0 , endExclusive : 5 } , 'varName' , undefined ) ;
286+ expect ( part . kind ) . to . equal ( 'var' ) ;
287+ } ) ;
288+
289+ it ( 'ParsedChatRequestFunctionPart has kind assigned at runtime' , ( ) => {
290+ const toolRequest : ToolRequest = {
291+ id : 'testTool' ,
292+ name : 'Test Tool' ,
293+ handler : async ( ) => undefined ,
294+ parameters : { type : 'object' , properties : { } }
295+ } ;
296+ const part = new ParsedChatRequestFunctionPart ( { start : 0 , endExclusive : 5 } , toolRequest ) ;
297+ expect ( part . kind ) . to . equal ( 'function' ) ;
298+ } ) ;
299+
300+ it ( 'ParsedChatRequestAgentPart has kind assigned at runtime' , ( ) => {
301+ const part = new ParsedChatRequestAgentPart ( { start : 0 , endExclusive : 5 } , 'agentId' , 'agentName' ) ;
302+ expect ( part . kind ) . to . equal ( 'agent' ) ;
303+ } ) ;
304+ } ) ;
268305} ) ;
0 commit comments