11import OpenAI from 'openai' ;
22import { ACI } from '../../src/client' ;
3- import {
4- ACISearchFunctions ,
5- ACIExecuteFunction
6- } from '../../src/meta_functions' ;
3+ import { ACISearchFunctions , ACIExecuteFunction } from '../../src/meta_functions' ;
74import { FunctionDefinitionFormat } from '../../src/types/functions' ;
85// load .env.local
96import dotenv from 'dotenv' ;
@@ -13,123 +10,121 @@ dotenv.config();
1310describe ( 'AI Integration Tests' , ( ) => {
1411 let aciClient : ACI ;
1512 let openaiClient : OpenAI ;
16-
13+
1714 beforeAll ( ( ) => {
1815 // Create a real API clients using environment variables
19- aciClient = new ACI ( {
20- apiKey : process . env . TEST_ACI_API_KEY as string
16+ aciClient = new ACI ( {
17+ apiKey : process . env . TEST_ACI_API_KEY as string ,
2118 } ) ;
22-
19+
2320 openaiClient = new OpenAI ( {
2421 apiKey : process . env . TEST_OPENAI_API_KEY as string ,
2522 } ) ;
2623 } ) ;
27-
24+
2825 // Helper to extract the first function_call from OpenAI output
2926 function getFirstFunctionCall ( output : any [ ] ) {
3027 return output . find ( item => item . type === 'function_call' ) ;
3128 }
32-
29+
3330 it ( 'completes a full AI workflow: search and execute GitHub star repo' , async ( ) => {
3431 // Get the function schemas in OpenAI format
3532 const aciSearchFunctionsSchema = ACISearchFunctions . toJsonSchema (
3633 FunctionDefinitionFormat . OPENAI_RESPONSES
3734 ) ;
38-
35+
3936 const aciExecuteFunctionSchema = ACIExecuteFunction . toJsonSchema (
4037 FunctionDefinitionFormat . OPENAI_RESPONSES
4138 ) ;
42-
39+
4340 // Step 1: Initial user query and function search
4441 const userMessage = 'Can you star aipotheosis-labs/aci github repo?' ;
45-
42+
4643 // Using as any to bypass TypeScript errors for the test
4744 const searchResponse = await openaiClient . responses . create ( {
4845 model : 'gpt-4o' ,
4946 input : userMessage ,
50- tools : [ aciSearchFunctionsSchema , aciExecuteFunctionSchema ] as any
47+ tools : [ aciSearchFunctionsSchema , aciExecuteFunctionSchema ] as any ,
5148 } ) ;
52-
49+
5350 const searchToolCall = getFirstFunctionCall ( searchResponse . output ) ;
5451 expect ( searchToolCall ) . toBeDefined ( ) ;
55-
52+
5653 if ( ! searchToolCall || searchToolCall . type !== 'function_call' ) {
5754 throw new Error ( 'No tool call returned from OpenAI' ) ;
5855 }
59-
56+
6057 // Verify it's calling the search function
6158 expect ( searchToolCall . name ) . toBe ( 'ACI_SEARCH_FUNCTIONS' ) ;
62-
59+
6360 // Step 2: Handle the ACI search function call
6461 const searchArguments = JSON . parse ( searchToolCall . arguments ) ;
6562 const searchResults = await aciClient . handleFunctionCall ( {
6663 functionName : searchToolCall . name ,
6764 functionArguments : searchArguments ,
6865 linkedAccountOwnerId : 'test-user-id' ,
6966 allowedAppsOnly : false ,
70- format : FunctionDefinitionFormat . OPENAI_RESPONSES
67+ format : FunctionDefinitionFormat . OPENAI_RESPONSES ,
7168 } ) ;
72-
69+
7370 // Verify we found the GitHub star repository function
7471 expect ( Array . isArray ( searchResults ) ) . toBe ( true ) ;
7572 expect ( searchResults . length ) . toBeGreaterThan ( 0 ) ;
76-
73+
7774 // Find the GitHub star repository function
7875 const githubStarFunction = searchResults . find (
79- ( func : any ) => func . function ?. name === 'GITHUB__STAR_REPOSITORY' ||
80- func . name === 'GITHUB__STAR_REPOSITORY'
76+ ( func : any ) =>
77+ func . function ?. name === 'GITHUB__STAR_REPOSITORY' || func . name === 'GITHUB__STAR_REPOSITORY'
8178 ) ;
8279 expect ( githubStarFunction ) . toBeDefined ( ) ;
83-
84-
80+
8581 // Second OpenAI call to trigger execution
8682 const executeResponse = await openaiClient . responses . create ( {
8783 model : 'gpt-4o' ,
8884 input : [
8985 {
9086 role : 'system' ,
9187 content :
92- " You are a helpful assistant with access to an unlimited number of tools via some meta functions: " +
93- " ACI_SEARCH_FUNCTIONS, and ACI_EXECUTE_FUNCTION. " +
94- " You can use ACI_SEARCH_FUNCTIONS to find relevant functions across all apps. Try to limit the number of results per request to 1. " +
95- " Once you have identified the function you need to use, you can use ACI_EXECUTE_FUNCTION to execute the function provided you have the correct input arguments." +
96- " When you useing ACI_SEARCH_FUNCTIONS, the limit parameter is 10 typically"
88+ ' You are a helpful assistant with access to an unlimited number of tools via some meta functions: ' +
89+ ' ACI_SEARCH_FUNCTIONS, and ACI_EXECUTE_FUNCTION. ' +
90+ ' You can use ACI_SEARCH_FUNCTIONS to find relevant functions across all apps. Try to limit the number of results per request to 1. ' +
91+ ' Once you have identified the function you need to use, you can use ACI_EXECUTE_FUNCTION to execute the function provided you have the correct input arguments.' +
92+ ' When you useing ACI_SEARCH_FUNCTIONS, the limit parameter is 10 typically' ,
9793 } ,
9894 {
9995 role : 'user' ,
100- content : userMessage
96+ content : userMessage ,
10197 } ,
10298 {
103- ...searchToolCall
99+ ...searchToolCall ,
104100 } ,
105101 {
106- type : " function_call_output" ,
102+ type : ' function_call_output' ,
107103 call_id : searchToolCall . call_id ,
108- "output" : JSON . stringify ( searchResults )
109-
104+ output : JSON . stringify ( searchResults ) ,
110105 } ,
111106 ] ,
112- tools : [ aciSearchFunctionsSchema , aciExecuteFunctionSchema ] as any
107+ tools : [ aciSearchFunctionsSchema , aciExecuteFunctionSchema ] as any ,
113108 } as any ) ;
114-
109+
115110 // Extract the execution tool call
116111 const executeToolCall = getFirstFunctionCall ( executeResponse . output ) ;
117112 expect ( executeToolCall ) . toBeDefined ( ) ;
118-
113+
119114 if ( ! executeToolCall || executeToolCall . type !== 'function_call' ) {
120115 throw new Error ( 'No execution tool call returned from OpenAI' ) ;
121116 }
122-
117+
123118 // Verify it's calling the execute function
124119 expect ( executeToolCall . name ) . toBe ( 'ACI_EXECUTE_FUNCTION' ) ;
125-
120+
126121 // Step 4: Check the execution parameters
127122 const executeArguments = JSON . parse ( executeToolCall . arguments ) ;
128123 expect ( executeArguments . function_name ) . toBe ( 'GITHUB__STAR_REPOSITORY' ) ;
129124 expect ( executeArguments . function_arguments . path . owner ) . toBe ( 'aipotheosis-labs' ) ;
130125 expect ( executeArguments . function_arguments . path . repo ) . toBe ( 'aci' ) ;
131-
126+
132127 // Note: We're not actually executing the function as it would require
133128 // real GitHub credentials, but we've verified the LLM generates the correct parameters
134129 } , 60000 ) ; // Longer timeout for this complex test
135- } ) ;
130+ } ) ;
0 commit comments