@@ -10,7 +10,9 @@ import {
1010 DataTypeServiceClient ,
1111 DataTypeUpdateRequest , ExecutionRequest ,
1212 FlowTypeServiceClient ,
13- FlowTypeUpdateRequest , RuntimeFunctionDefinitionServiceClient , RuntimeFunctionDefinitionUpdateRequest ,
13+ FlowTypeUpdateRequest ,
14+ FunctionDefinitionServiceClient ,
15+ FunctionDefinitionUpdateRequest , RuntimeFunctionDefinitionServiceClient , RuntimeFunctionDefinitionUpdateRequest ,
1416 TransferRequest , TransferResponse
1517} from "@code0-tech/tucana/aquila" ;
1618import {
@@ -30,6 +32,7 @@ const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActi
3032
3133 const state : SdkState = {
3234 functions : [ ] ,
35+ runtimeFunctions : [ ] ,
3336 dataTypes : [ ] ,
3437 flowTypes : [ ] ,
3538 configurationDefinitions : configDefinitions ?. map ( value => {
@@ -137,11 +140,11 @@ const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActi
137140 } )
138141 return Promise . resolve ( )
139142 } ,
140- registerFunctionDefinitions : async ( ...functionDefinitions ) => {
141- for ( const registeredFunction of functionDefinitions ) {
143+ registerRuntimeFunctionDefinitions : async ( ...runtimeFunctionDefinitions ) => {
144+ for ( const registeredFunction of runtimeFunctionDefinitions ) {
142145 const handler = registeredFunction . handler ;
143146 const functionDefinition = registeredFunction . definition ;
144- state . functions . push ( {
147+ state . runtimeFunctions . push ( {
145148 identifier : functionDefinition . runtimeName ,
146149 definition : {
147150 displayMessage : functionDefinition . displayMessage || [ ] ,
@@ -170,6 +173,36 @@ const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActi
170173 }
171174 return Promise . resolve ( )
172175 } ,
176+ registerFunctionDefinitions : async ( ...functionDefinitions ) => {
177+ for ( const functionDefinition of functionDefinitions ) {
178+ state . functions . push ( {
179+ identifier : functionDefinition . runtimeName ,
180+ definition : {
181+ displayMessage : functionDefinition . displayMessage || [ ] ,
182+ name : functionDefinition . name || [ ] ,
183+ documentation : functionDefinition . documentation || [ ] ,
184+ description : functionDefinition . description || [ ] ,
185+ deprecationMessage : functionDefinition . deprecationMessage || [ ] ,
186+ displayIcon : functionDefinition . displayIcon || "" ,
187+ alias : functionDefinition . alias || [ ] ,
188+ linkedDataTypeIdentifiers : functionDefinition . linkedDataTypes || [ ] ,
189+ definitionSource : "action" ,
190+ version : functionDefinition . version || config . version ,
191+ runtimeName : functionDefinition . runtimeName ,
192+ parameterDefinitions : ( functionDefinition . parameters || [ ] ) . map ( param => ( {
193+ runtimeName : param . runtimeName ,
194+ name : param . name || [ ] ,
195+ description : param . description || [ ] ,
196+ documentation : param . documentation || [ ] ,
197+ defaultValue : constructValue ( param . defaultValue || null ) ,
198+ } ) ) ,
199+ signature : functionDefinition . signature ,
200+ throwsError : functionDefinition . throwsError || false ,
201+ }
202+ } ) ;
203+ }
204+ return Promise . resolve ( )
205+ } ,
173206 dispatchEvent : async ( eventType , projectId , payload ) => {
174207 if ( ! state . stream ) {
175208 return Promise . reject ( "SDK is not connected. Call connect() before dispatching events." ) ;
@@ -242,6 +275,23 @@ async function connect(state: SdkState, config: ActionSdk["config"], options?: R
242275 RuntimeFunctionDefinitionUpdateRequest . create (
243276 {
244277 runtimeFunctions : [
278+ ...state . runtimeFunctions . map ( func => ( {
279+ ...func . definition ,
280+ } ) )
281+ ]
282+ }
283+ ) , builtOptions
284+ ) . then ( value => {
285+ if ( ! value . response . success ) {
286+ return Promise . reject ( value . response ) ;
287+ }
288+ } )
289+
290+ const FunctionDefinitionClient = new FunctionDefinitionServiceClient ( state . transport )
291+ await FunctionDefinitionClient . update (
292+ FunctionDefinitionUpdateRequest . create (
293+ {
294+ functions : [
245295 ...state . functions . map ( func => ( {
246296 ...func . definition ,
247297 } ) )
@@ -309,7 +359,7 @@ function handleExecutionRequest(state: SdkState, message: TransferResponse) {
309359 return
310360 }
311361 const execution = message . data . execution as ExecutionRequest ;
312- const func = state . functions . find ( value => value . identifier == execution . functionIdentifier ) ;
362+ const func = state . runtimeFunctions . find ( value => value . identifier == execution . functionIdentifier ) ;
313363 if ( func ) {
314364 const params = Object . entries ( execution . parameters ! . fields ! ) . map ( ( [ key , value ] ) => {
315365 const param = func . definition . runtimeParameterDefinitions
0 commit comments