From 0f39850aae04e12fca8bd08fd528d5100c7f6d53 Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Mon, 9 Mar 2026 22:39:54 +0100 Subject: [PATCH 1/6] Cleanup sdk --- README.md | 2 + bin/Gemfile | 5 +- bin/Gemfile.lock | 10 +- bin/test_server.rb | 22 +++- ts/examples/simple_example.ts | 57 ++-------- ts/src/action_sdk.ts | 193 ++++++++++++++++++++++------------ ts/src/types.ts | 122 +++++++++++++++++++++ 7 files changed, 284 insertions(+), 127 deletions(-) create mode 100644 ts/src/types.ts diff --git a/README.md b/README.md index 8222b23..92c18ff 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ sequenceDiagram Hercules->>Aquila: Register datatypes Aquila-->>Hercules: Validation result + + Hercules->>Stream: ActionConfiguration Request
with (registered) datatypes Hercules->>Aquila: Register function definitions Aquila-->>Hercules: Validation result diff --git a/bin/Gemfile b/bin/Gemfile index 22c8cd7..7bc0494 100644 --- a/bin/Gemfile +++ b/bin/Gemfile @@ -1,7 +1,8 @@ +# frozen_string_literal: true + source 'https://rubygems.org' ruby '3.4.7' - -gem 'tucana', '0.0.56' gem 'grpc', '~> 1.67' +gem 'tucana', '0.0.56' diff --git a/bin/Gemfile.lock b/bin/Gemfile.lock index 77057d1..7efaa01 100644 --- a/bin/Gemfile.lock +++ b/bin/Gemfile.lock @@ -1,3 +1,9 @@ +PATH + remote: ../../tucana/build/ruby + specs: + tucana (0.0.0) + grpc (~> 1.64) + GEM remote: https://rubygems.org/ specs: @@ -17,8 +23,6 @@ GEM google-protobuf (>= 3.25, < 5.0) googleapis-common-protos-types (~> 1.0) rake (13.3.1) - tucana (0.0.56) - grpc (~> 1.64) PLATFORMS ruby @@ -26,7 +30,7 @@ PLATFORMS DEPENDENCIES grpc (~> 1.67) - tucana (= 0.0.56) + tucana (= 0.0.0)! RUBY VERSION ruby 3.4.7p58 diff --git a/bin/test_server.rb b/bin/test_server.rb index f870f9e..9f2b9d3 100755 --- a/bin/test_server.rb +++ b/bin/test_server.rb @@ -31,6 +31,16 @@ def add_runtime_functions(functions) def add_action_config_definition(config) @action_config_definitions << config end + + def register_config_definitions(token, config_definitions) + @action_config_definitions.each do |config| + next unless config[:auth_token] == token + + config[:config_definitions] = config_definitions + puts "Registered config definitions for action: #{config[:action_identifier]} (v#{config[:version]})" + break + end + end end class FlowTypeTransferService < Tucana::Aquila::FlowTypeService::Service @@ -93,7 +103,8 @@ def construct_parameters(func) end def transfer(requests, call) - puts "Got Auth token: #{call.metadata['authorization']}" + token = call.metadata['authorization'] + puts "Got Auth token: #{token}" Enumerator.new do |yielder| Thread.new do loop do @@ -144,6 +155,7 @@ def transfer(requests, call) end requests.each do |req| + p req unless req.result.nil? puts "Received execution result for: #{req.result.execution_identifier}" puts "Result value: #{req.result.result}" @@ -157,14 +169,20 @@ def transfer(requests, call) next end + unless req.action_configuration.nil? + @state.register_config_definitions(token, + req.action_configuration.action_configurations) + end + next if req.logon.nil? logon = req.logon @state.add_action_config_definition({ + auth_token: token, action_identifier: logon.action_identifier, version: logon.version, - config_definitions: logon.action_configurations, + config_definitions: [], }) puts "Action logon received: #{logon.action_identifier} (v#{logon.version})" diff --git a/ts/examples/simple_example.ts b/ts/examples/simple_example.ts index b8f62f6..09d247e 100644 --- a/ts/examples/simple_example.ts +++ b/ts/examples/simple_example.ts @@ -2,49 +2,29 @@ import { createSdk } from "../src/action_sdk.js"; import { Struct, Value } from "@code0-tech/tucana/pb/shared.struct_pb.js"; import { constructValue } from "@code0-tech/tucana/helpers/shared.struct_helper.js"; import { ActionProjectConfiguration } from "@code0-tech/tucana/pb/shared.action_configuration_pb.js"; +import {randomUUID} from "node:crypto"; const sdk = createSdk({ - token: "your_token_here", + token: randomUUID(), actionUrl: "127.0.0.1:50051", actionId: "action_123", version: "0.0.0", }) sdk.registerConfigDefinitions({ - type: { - signature: "string", - identifier: "STRING", - version: "0.0.0", - rules: [], - name: [], - genericKeys: [], - alias: [], - displayMessage: [], - linkedDataTypeIdentifiers: [], - definitionSource: "" - }, - name: [], - description: [], + type: "LIST", + linkedDataTypeIdentifiers: ["STRING", "LIST"], identifier: "config_discord_bot_token", }) sdk.registerDataType({ identifier: "SOME_DATATYPE", signature: "any", - name: [], - alias: [], - rules: [], - genericKeys: [], - displayMessage: [], - definitionSource: "", - linkedDataTypeIdentifiers: [], - version: "0.0.0", }) sdk.registerFunctionDefinition( { signature: "(n: NUMBER) => NUMBER", - definitionSource: "", linkedDataTypeIdentifiers: ["NUMBER"], runtimeParameterDefinitions: [ { @@ -55,46 +35,23 @@ sdk.registerFunctionDefinition( defaultValue: constructValue(20), } ], - alias: [], - deprecationMessage: [], - description: [], - displayIcon: "", - displayMessage: [], - documentation: [], - name: [], - throwsError: false, version: "0.0.0", runtimeName: "fib", }, - async (params: Struct): Promise => { - console.log("Received parameters:", params); - let n = params.fields["n"]; - + (n: number): number => { function fibonacci(num: number): number { if (num <= 1) return num; return fibonacci(num - 1) + fibonacci(num - 2); } - - if (n && n.kind.oneofKind === "numberValue") { - return constructValue(fibonacci(n.kind.numberValue)); - } - - return constructValue(fibonacci(1)); + return fibonacci(n) } ) sdk.registerFlowType( { - documentation: [], - description: [], - displayIcon: "", - displayMessage: [], editable: false, inputTypeIdentifier: "STRING", - name: [], - alias: [], identifier: "test_flow", - settings: [], version: "0.0.0", } ) @@ -119,4 +76,4 @@ function connectToSdk() { connectToSdk(); }, 5000) }) -} \ No newline at end of file +} diff --git a/ts/src/action_sdk.ts b/ts/src/action_sdk.ts index f86db14..e170053 100644 --- a/ts/src/action_sdk.ts +++ b/ts/src/action_sdk.ts @@ -1,15 +1,17 @@ -import {FlowType} from "@code0-tech/tucana/pb/shared.flow_definition_pb.js"; -import {DefinitionDataType} from "@code0-tech/tucana/pb/shared.data_type_pb.js"; -import {RuntimeFunctionDefinition} from "@code0-tech/tucana/pb/shared.runtime_function_pb.js"; -import {Struct, Value} from "@code0-tech/tucana/pb/shared.struct_pb.js"; -import {GrpcOptions, GrpcTransport} from "@protobuf-ts/grpc-transport"; +import {GrpcTransport} from "@protobuf-ts/grpc-transport"; import {ChannelCredentials} from "@grpc/grpc-js"; import {ActionTransferServiceClient} from "@code0-tech/tucana/pb/aquila.action_pb.client.js"; -import {DuplexStreamingCall, RpcOptions} from "@protobuf-ts/runtime-rpc"; -import {ExecutionRequest, TransferRequest, TransferResponse} from "@code0-tech/tucana/pb/aquila.action_pb.js"; -import {constructValue} from "@code0-tech/tucana/helpers/shared.struct_helper.js"; +import {RpcOptions} from "@protobuf-ts/runtime-rpc"; import { - ActionConfigurationDefinition, ActionConfigurations, + ActionConfiguration, + ExecutionRequest, + TransferRequest, + TransferResponse +} from "@code0-tech/tucana/pb/aquila.action_pb.js"; +import {constructValue, toAllowedValue} from "@code0-tech/tucana/helpers/shared.struct_helper.js"; +import { + ActionConfigurationDefinition, + ActionConfigurations, ActionProjectConfiguration } from "@code0-tech/tucana/pb/shared.action_configuration_pb"; import {DataTypeServiceClient} from "@code0-tech/tucana/pb/aquila.data_type_pb.client"; @@ -18,42 +20,9 @@ import {RuntimeFunctionDefinitionServiceClient} from "@code0-tech/tucana/pb/aqui import {RuntimeFunctionDefinitionUpdateRequest} from "@code0-tech/tucana/pb/aquila.runtime_function_pb"; import {FlowTypeServiceClient} from "@code0-tech/tucana/pb/aquila.flow_type_pb.client"; import {FlowTypeUpdateRequest} from "@code0-tech/tucana/pb/aquila.flow_type_pb"; +import {ActionSdk, SdkState} from "./types"; +import {FlowTypeSetting_UniquenessScope} from "@code0-tech/tucana/pb/shared.flow_definition_pb"; -type ActionSdk = { - config: { - token: string, - actionUrl: string, - actionId: string, - version: string, - }, - fullyConnected: () => boolean, // indicates whether the SDK is fully connected and ready to send/receive messages. Becomes true after connect() resolves successfully - connect: (options?: GrpcOptions) => Promise, // after registering the functions and events - onError: (handler: (error: Error) => void) => void, - getProjectActionConfigurations(): ActionProjectConfiguration[], - registerConfigDefinitions: (...actionConfigurations: ActionConfigurationDefinition[]) => Promise, - registerDataType: (dataType: Omit) => Promise, - registerFlowType: (flowType: Omit) => Promise, - registerFunctionDefinition: (functionDefinition: Omit, handler: (parameters: Struct) => Promise) => Promise, - dispatchEvent: (eventType: string, projectId: number | bigint, payload: Value) => Promise, -} - -type RegisteredFunction = { - identifier: string, - definition: Omit, - handler: (parameters: Struct) => Promise, -} - -type SdkState = { - functions: RegisteredFunction[], - dataTypes: DefinitionDataType[], - flowTypes: FlowType[], - configurationDefinitions: ActionConfigurationDefinition[], - projectConfigurations: ActionProjectConfiguration[], - transport: GrpcTransport, - client: ActionTransferServiceClient, - stream: DuplexStreamingCall | undefined, - fullyConnected: boolean, -} export const createSdk = (config: ActionSdk["config"]): ActionSdk => { const transport = new GrpcTransport( @@ -90,22 +59,87 @@ export const createSdk = (config: ActionSdk["config"]): ActionSdk => { getProjectActionConfigurations: () => { return state.projectConfigurations; }, - registerConfigDefinitions: async (actionConfigurations) => { - state.configurationDefinitions = state.configurationDefinitions.concat(actionConfigurations); + registerConfigDefinitions: async (...actionConfigurations) => { + state.configurationDefinitions.push(...(actionConfigurations?.map(value => { + return { + identifier: value.identifier, + name: value.name || [], + description: value.description || [], + type: value.type, + linkedDataTypeIdentifiers: value.linkedDataTypeIdentifiers || [], + defaultValue: constructValue(value.defaultValue || null), + } + }) || [])) + return Promise.resolve() }, registerDataType: async (dataType) => { - state.dataTypes.push(dataType); + state.dataTypes.push({ + identifier: dataType.identifier, + name: dataType.name || [], + alias: dataType.alias || [], + rules: dataType.rules || [], + genericKeys: dataType.genericKeys || [], + signature: dataType.signature, + linkedDataTypeIdentifiers: dataType.linkedDataTypeIdentifiers || [], + displayMessage: dataType.displayMessage || [], + definitionSource: "", + version: dataType.version || config.version, + }); + + return Promise.resolve() }, registerFlowType: async (flowType) => { - state.flowTypes.push(flowType); + state.flowTypes.push({ + identifier: flowType.identifier, + name: flowType.name || [], + alias: flowType.alias || [], + description: flowType.description || [], + displayIcon: flowType.displayIcon || "", + displayMessage: flowType.displayMessage || [], + documentation: flowType.documentation || [], + definitionSource: "", + version: flowType.version || config.version, + inputTypeIdentifier: flowType.inputTypeIdentifier, + returnTypeIdentifier: flowType.returnTypeIdentifier, + settings: (flowType.settings || []).map(setting => ({ + name: setting.name || [], + defaultValue: constructValue(setting.defaultValue || null), + identifier: setting.identifier, + description: setting.description || [], + unique: setting.unique || FlowTypeSetting_UniquenessScope.NONE, + dataTypeIdentifier: setting.dataTypeIdentifier + })), + editable: flowType.editable || false, + }); return Promise.resolve() }, registerFunctionDefinition: async (functionDefinition, handler) => { state.functions.push({ identifier: functionDefinition.runtimeName, - definition: functionDefinition, + definition: { + displayMessage: functionDefinition.displayMessage || [], + name: functionDefinition.name || [], + documentation: functionDefinition.documentation || [], + description: functionDefinition.description || [], + deprecationMessage: functionDefinition.deprecationMessage || [], + displayIcon: functionDefinition.displayIcon || "", + alias: functionDefinition.alias || [], + linkedDataTypeIdentifiers: functionDefinition.linkedDataTypeIdentifiers || [], + definitionSource: "", + version: functionDefinition.version || config.version, + runtimeName: functionDefinition.runtimeName, + runtimeParameterDefinitions: (functionDefinition.runtimeParameterDefinitions || []).map(param => ({ + runtimeName: param.runtimeName, + name: param.name || [], + description: param.description || [], + documentation: param.documentation || [], + defaultValue: constructValue(param.defaultValue || null), + })), + signature: functionDefinition.signature, + throwsError: functionDefinition.throwsError || false, + }, handler: handler, }); return Promise.resolve() @@ -125,7 +159,7 @@ export const createSdk = (config: ActionSdk["config"]): ActionSdk => { event: { projectId: projectIdBigInt, eventType: eventType, - payload: payload || constructValue(null), + payload: constructValue(payload) || constructValue(null), } } }) @@ -138,7 +172,7 @@ export const createSdk = (config: ActionSdk["config"]): ActionSdk => { } } -async function connect(state: SdkState, config: ActionSdk["config"], options?: RpcOptions): Promise { +async function connect(state: SdkState, config: ActionSdk["config"], options?: RpcOptions): Promise { const builtOptions: RpcOptions = { meta: { "Authorization": config.token, @@ -153,8 +187,7 @@ async function connect(state: SdkState, config: ActionSdk["config"], options?: oneofKind: "logon", logon: { actionIdentifier: config.actionId, - version: config.version, - actionConfigurations: state.configurationDefinitions + version: config.version } } } @@ -175,6 +208,24 @@ async function connect(state: SdkState, config: ActionSdk["config"], options?: }).catch(reason => { return Promise.reject(reason); }) + + + await state.stream.requests.send( + TransferRequest.create({ + data: { + oneofKind: "actionConfiguration", + actionConfiguration: ActionConfiguration.create( + { + actionConfigurations: state.configurationDefinitions + } + ) + } + } + ), + ).catch(reason => { + return Promise.reject(reason); + }) + const runtimeFunctionDefinitionClient = new RuntimeFunctionDefinitionServiceClient(state.transport) await runtimeFunctionDefinitionClient.update( RuntimeFunctionDefinitionUpdateRequest.create( @@ -239,24 +290,26 @@ function handleExecutionRequest(state: SdkState, message: TransferResponse): Pro const execution = message.data.execution as ExecutionRequest; const func = state.functions.find(value => value.identifier == execution.functionIdentifier); if (func) { - func.handler(execution.parameters!).then(async value => { - try { - console.log("Execution result:", value); - return await state.stream!.requests.send( - TransferRequest.create({ - data: { - oneofKind: "result", - result: { - executionIdentifier: execution.executionIdentifier, - result: value || constructValue(null), - } - } - }) - ); - } catch (reason) { - return reject(reason); - } + const params = Object.values(execution!.parameters!.fields!).map(value => { + return toAllowedValue(value) }) + + const result = func.handler(params) + try { + return await state.stream!.requests.send( + TransferRequest.create({ + data: { + oneofKind: "result", + result: { + executionIdentifier: execution.executionIdentifier, + result: constructValue(result), + } + } + }) + ); + } catch (reason) { + return reject(reason); + } } resolve(); }) diff --git a/ts/src/types.ts b/ts/src/types.ts new file mode 100644 index 0000000..cc8a965 --- /dev/null +++ b/ts/src/types.ts @@ -0,0 +1,122 @@ +import {FlowType, FlowTypeSetting_UniquenessScope} from "@code0-tech/tucana/pb/shared.flow_definition_pb.js"; +import { DefinitionDataType, DefinitionDataTypeRule } from "@code0-tech/tucana/pb/shared.data_type_pb.js"; +import { RuntimeFunctionDefinition } from "@code0-tech/tucana/pb/shared.runtime_function_pb.js"; +import { Value } from "@code0-tech/tucana/pb/shared.struct_pb.js"; +import { GrpcOptions, GrpcTransport } from "@protobuf-ts/grpc-transport"; +import { ActionTransferServiceClient } from "@code0-tech/tucana/pb/aquila.action_pb.client.js"; +import { DuplexStreamingCall } from "@protobuf-ts/runtime-rpc"; +import { + TransferRequest, + TransferResponse +} from "@code0-tech/tucana/pb/aquila.action_pb.js"; +import { AllowedValue } from "@code0-tech/tucana/helpers/shared.struct_helper.js"; +import { + ActionConfigurationDefinition, ActionProjectConfiguration +} from "@code0-tech/tucana/pb/shared.action_configuration_pb"; +import {Translation} from "@code0-tech/tucana/pb/shared.translation_pb"; + +export interface HerculesDefinitionDataType { + identifier: string, + name?: Translation[], + displayMessage?: Translation[], + alias?: Translation[], + rules?: DefinitionDataTypeRule[], + genericKeys?: string[], + signature: string, + linkedDataTypeIdentifiers?: string[], + // Will default to sdk version + version?: string +} + +export interface HerculesFlowTypeSetting { + identifier: string, + unique?: FlowTypeSetting_UniquenessScope, + dataTypeIdentifier: string, + defaultValue?: Value, + name?: Translation[], + description?: Translation[], +} + +export interface HerculesFlowType { + identifier: string, + settings?: HerculesFlowTypeSetting[] + inputTypeIdentifier?: string, + returnTypeIdentifier?: string, + editable: boolean, + name?: Translation[], + description?: Translation[], + documentation?: Translation[], + displayMessage?: Translation[], + alias?: Translation[], + version?: string, + displayIcon?: string, +} + +export interface HerculesRuntimeFunctionDefinition { + runtimeName: string, + runtimeParameterDefinitions?: { + runtimeName: string, + defaultValue?: AllowedValue, + name?: Translation[], + description?: Translation[], + documentation?: Translation[], + }[], + signature: string, + throwsError?: boolean, + name?: Translation[], + description?: Translation[], + documentation?: Translation[], + deprecationMessage?: Translation[], + displayMessage?: Translation[], + alias?: Translation[], + linkedDataTypeIdentifiers?: string[], + version?: string, + displayIcon?: string, +} + +export interface HerculesActionConfigurationDefinition { + name?: Translation[], + description?: Translation[], + type: string, + linkedDataTypeIdentifiers?: string[], + defaultValue?: AllowedValue, + identifier: string, +} + +export interface ActionSdk { + config: { + token: string, + actionUrl: string, + actionId: string, + version: string, + }, + fullyConnected: () => boolean, // indicates whether the SDK is fully connected and ready to send/receive messages. Becomes true after connect() resolves successfully + connect: (options?: GrpcOptions) => Promise, // after registering the functions and events + onError: (handler: (error: Error) => void) => void, + + getProjectActionConfigurations(): ActionProjectConfiguration[], + + registerConfigDefinitions: (...actionConfigurations: Array) => Promise, + registerDataType: (dataType: HerculesDefinitionDataType) => Promise, + registerFlowType: (flowType: HerculesFlowType) => Promise, + registerFunctionDefinition: (functionDefinition: HerculesRuntimeFunctionDefinition, handler: Function) => Promise, + dispatchEvent: (eventType: string, projectId: number | bigint, payload: AllowedValue) => Promise, +} + +export interface RegisteredFunction { + identifier: string, + definition: RuntimeFunctionDefinition, + handler: Function +} + +export interface SdkState { + functions: RegisteredFunction[], + dataTypes: DefinitionDataType[], + flowTypes: FlowType[], + configurationDefinitions: ActionConfigurationDefinition[], + projectConfigurations: ActionProjectConfiguration[], + transport: GrpcTransport, + client: ActionTransferServiceClient, + stream: DuplexStreamingCall | undefined, + fullyConnected: boolean, +} From a25fe5bb6f62b9ea7f5ae919c2e7cb1231ce898c Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Mon, 9 Mar 2026 22:53:28 +0100 Subject: [PATCH 2/6] Remove unused reports --- ts/examples/simple_example.ts | 1 - ts/src/action_sdk.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/ts/examples/simple_example.ts b/ts/examples/simple_example.ts index 09d247e..3daf2cc 100644 --- a/ts/examples/simple_example.ts +++ b/ts/examples/simple_example.ts @@ -1,5 +1,4 @@ import { createSdk } from "../src/action_sdk.js"; -import { Struct, Value } from "@code0-tech/tucana/pb/shared.struct_pb.js"; import { constructValue } from "@code0-tech/tucana/helpers/shared.struct_helper.js"; import { ActionProjectConfiguration } from "@code0-tech/tucana/pb/shared.action_configuration_pb.js"; import {randomUUID} from "node:crypto"; diff --git a/ts/src/action_sdk.ts b/ts/src/action_sdk.ts index e170053..d50cbdf 100644 --- a/ts/src/action_sdk.ts +++ b/ts/src/action_sdk.ts @@ -10,7 +10,6 @@ import { } from "@code0-tech/tucana/pb/aquila.action_pb.js"; import {constructValue, toAllowedValue} from "@code0-tech/tucana/helpers/shared.struct_helper.js"; import { - ActionConfigurationDefinition, ActionConfigurations, ActionProjectConfiguration } from "@code0-tech/tucana/pb/shared.action_configuration_pb"; From 404a39c64bd7105f7f51ba9f23ffc6b6cec97a45 Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Tue, 10 Mar 2026 15:34:59 +0100 Subject: [PATCH 3/6] Rename some stuff --- README.md | 12 ++--- ts/examples/simple_example.ts | 19 ++++---- ts/src/action_sdk.ts | 84 ++++++++++++++++++----------------- ts/src/types.ts | 10 ++++- 4 files changed, 66 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 92c18ff..c39e6fa 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,14 @@ sequenceDiagram participant Aquila as Aquila (Server) participant Stream as Stream (gRPC) + Hercules->>Aquila: Register datatypes
because maybe they are needed in the config definitions + Aquila-->>Hercules: Validation result + + Hercules->>Stream: Open bi-directional stream Hercules->>Stream: ActionLogon request - Hercules->>Aquila: Register datatypes - Aquila-->>Hercules: Validation result - - Hercules->>Stream: ActionConfiguration Request
with (registered) datatypes - + Hercules->>Aquila: Register function definitions Aquila-->>Hercules: Validation result @@ -61,4 +61,4 @@ To use a simple test server use the following command: ```bash ./bin/test_server.rb ``` -This will start a test server on `localhost:50051` that you can connect to with the action sdk. \ No newline at end of file +This will start a test server on `localhost:50051` that you can connect to with the action sdk. diff --git a/ts/examples/simple_example.ts b/ts/examples/simple_example.ts index 3daf2cc..cd1d999 100644 --- a/ts/examples/simple_example.ts +++ b/ts/examples/simple_example.ts @@ -1,11 +1,11 @@ import { createSdk } from "../src/action_sdk.js"; import { constructValue } from "@code0-tech/tucana/helpers/shared.struct_helper.js"; import { ActionProjectConfiguration } from "@code0-tech/tucana/pb/shared.action_configuration_pb.js"; -import {randomUUID} from "node:crypto"; +import { HerculesFunctionContext } from "../src/types.js"; const sdk = createSdk({ - token: randomUUID(), - actionUrl: "127.0.0.1:50051", + authToken: "someToken", + aquilaUrl: "127.0.0.1:50051", actionId: "action_123", version: "0.0.0", }) @@ -28,16 +28,16 @@ sdk.registerFunctionDefinition( runtimeParameterDefinitions: [ { runtimeName: "n", - description: [], - name: [], - documentation: [], - defaultValue: constructValue(20), + defaultValue: 20, } ], - version: "0.0.0", runtimeName: "fib", }, - (n: number): number => { + (n: number, context: HerculesFunctionContext): number => { + console.log("Project id:", context.projectId); + console.log("Execution id:", context.executionId); + console.log("Matched configs:", context.matchedConfigs); // matched configs for the current execution + function fibonacci(num: number): number { if (num <= 1) return num; return fibonacci(num - 1) + fibonacci(num - 2); @@ -51,7 +51,6 @@ sdk.registerFlowType( editable: false, inputTypeIdentifier: "STRING", identifier: "test_flow", - version: "0.0.0", } ) diff --git a/ts/src/action_sdk.ts b/ts/src/action_sdk.ts index d50cbdf..912ae26 100644 --- a/ts/src/action_sdk.ts +++ b/ts/src/action_sdk.ts @@ -1,32 +1,32 @@ -import {GrpcTransport} from "@protobuf-ts/grpc-transport"; -import {ChannelCredentials} from "@grpc/grpc-js"; -import {ActionTransferServiceClient} from "@code0-tech/tucana/pb/aquila.action_pb.client.js"; -import {RpcOptions} from "@protobuf-ts/runtime-rpc"; +import { GrpcTransport } from "@protobuf-ts/grpc-transport"; +import { ChannelCredentials } from "@grpc/grpc-js"; +import { ActionTransferServiceClient } from "@code0-tech/tucana/pb/aquila.action_pb.client.js"; +import { RpcOptions } from "@protobuf-ts/runtime-rpc"; import { ActionConfiguration, ExecutionRequest, TransferRequest, TransferResponse } from "@code0-tech/tucana/pb/aquila.action_pb.js"; -import {constructValue, toAllowedValue} from "@code0-tech/tucana/helpers/shared.struct_helper.js"; +import { constructValue, toAllowedValue } from "@code0-tech/tucana/helpers/shared.struct_helper.js"; import { ActionConfigurations, ActionProjectConfiguration } from "@code0-tech/tucana/pb/shared.action_configuration_pb"; -import {DataTypeServiceClient} from "@code0-tech/tucana/pb/aquila.data_type_pb.client"; -import {DataTypeUpdateRequest} from "@code0-tech/tucana/pb/aquila.data_type_pb"; -import {RuntimeFunctionDefinitionServiceClient} from "@code0-tech/tucana/pb/aquila.runtime_function_pb.client"; -import {RuntimeFunctionDefinitionUpdateRequest} from "@code0-tech/tucana/pb/aquila.runtime_function_pb"; -import {FlowTypeServiceClient} from "@code0-tech/tucana/pb/aquila.flow_type_pb.client"; -import {FlowTypeUpdateRequest} from "@code0-tech/tucana/pb/aquila.flow_type_pb"; -import {ActionSdk, SdkState} from "./types"; -import {FlowTypeSetting_UniquenessScope} from "@code0-tech/tucana/pb/shared.flow_definition_pb"; +import { DataTypeServiceClient } from "@code0-tech/tucana/pb/aquila.data_type_pb.client"; +import { DataTypeUpdateRequest } from "@code0-tech/tucana/pb/aquila.data_type_pb"; +import { RuntimeFunctionDefinitionServiceClient } from "@code0-tech/tucana/pb/aquila.runtime_function_pb.client"; +import { RuntimeFunctionDefinitionUpdateRequest } from "@code0-tech/tucana/pb/aquila.runtime_function_pb"; +import { FlowTypeServiceClient } from "@code0-tech/tucana/pb/aquila.flow_type_pb.client"; +import { FlowTypeUpdateRequest } from "@code0-tech/tucana/pb/aquila.flow_type_pb"; +import { ActionSdk, HerculesFunctionContext, SdkState } from "./types"; +import { FlowTypeSetting_UniquenessScope } from "@code0-tech/tucana/pb/shared.flow_definition_pb"; export const createSdk = (config: ActionSdk["config"]): ActionSdk => { const transport = new GrpcTransport( { - host: config.actionUrl, + host: config.aquilaUrl, channelCredentials: ChannelCredentials.createInsecure() } ) @@ -82,7 +82,7 @@ export const createSdk = (config: ActionSdk["config"]): ActionSdk => { signature: dataType.signature, linkedDataTypeIdentifiers: dataType.linkedDataTypeIdentifiers || [], displayMessage: dataType.displayMessage || [], - definitionSource: "", + definitionSource: "action", version: dataType.version || config.version, }); @@ -98,7 +98,7 @@ export const createSdk = (config: ActionSdk["config"]): ActionSdk => { displayIcon: flowType.displayIcon || "", displayMessage: flowType.displayMessage || [], documentation: flowType.documentation || [], - definitionSource: "", + definitionSource: "action", version: flowType.version || config.version, inputTypeIdentifier: flowType.inputTypeIdentifier, returnTypeIdentifier: flowType.returnTypeIdentifier, @@ -126,7 +126,7 @@ export const createSdk = (config: ActionSdk["config"]): ActionSdk => { displayIcon: functionDefinition.displayIcon || "", alias: functionDefinition.alias || [], linkedDataTypeIdentifiers: functionDefinition.linkedDataTypeIdentifiers || [], - definitionSource: "", + definitionSource: "action", version: functionDefinition.version || config.version, runtimeName: functionDefinition.runtimeName, runtimeParameterDefinitions: (functionDefinition.runtimeParameterDefinitions || []).map(param => ({ @@ -174,27 +174,12 @@ export const createSdk = (config: ActionSdk["config"]): ActionSdk => { async function connect(state: SdkState, config: ActionSdk["config"], options?: RpcOptions): Promise { const builtOptions: RpcOptions = { meta: { - "Authorization": config.token, + "Authorization": config.authToken, }, ...options } state.stream = state.client.transfer(builtOptions); - await state.stream.requests.send( - TransferRequest.create({ - data: { - oneofKind: "logon", - logon: { - actionIdentifier: config.actionId, - version: config.version - } - } - } - ), - ).catch(reason => { - return Promise.reject(reason); - }) - const dataTypeClient = new DataTypeServiceClient(state.transport) await dataTypeClient.update(DataTypeUpdateRequest.create({ dataTypes: [ @@ -209,17 +194,18 @@ async function connect(state: SdkState, config: ActionSdk["config"], options?: R }) + await state.stream.requests.send( TransferRequest.create({ - data: { - oneofKind: "actionConfiguration", - actionConfiguration: ActionConfiguration.create( - { - actionConfigurations: state.configurationDefinitions - } - ) + data: { + oneofKind: "logon", + logon: { + actionIdentifier: config.actionId, + version: config.version, + actionConfigurations: state.configurationDefinitions } } + } ), ).catch(reason => { return Promise.reject(reason); @@ -293,7 +279,23 @@ function handleExecutionRequest(state: SdkState, message: TransferResponse): Pro return toAllowedValue(value) }) - const result = func.handler(params) + const context: HerculesFunctionContext = { + projectId: execution.projectId, + executionId: execution.executionIdentifier, + matchedConfigs: state.projectConfigurations.filter(config => { + config.projectId === execution.projectId + }) || [], + } + + if (func.handler.arguments.length == params.length + 1) { + // handler has context parameter + params.push(context) + } else if (func.handler.arguments.length > params.length + 1) { + reject(new Error("Handler has more parameters than provided arguments")) + return + } + + const result = func.handler(params.push(context)) try { return await state.stream!.requests.send( TransferRequest.create({ diff --git a/ts/src/types.ts b/ts/src/types.ts index cc8a965..960686f 100644 --- a/ts/src/types.ts +++ b/ts/src/types.ts @@ -15,6 +15,12 @@ import { } from "@code0-tech/tucana/pb/shared.action_configuration_pb"; import {Translation} from "@code0-tech/tucana/pb/shared.translation_pb"; +export interface HerculesFunctionContext { + projectId: number | bigint, + executionId: string, + matchedConfigs: ActionProjectConfiguration[] +} + export interface HerculesDefinitionDataType { identifier: string, name?: Translation[], @@ -85,8 +91,8 @@ export interface HerculesActionConfigurationDefinition { export interface ActionSdk { config: { - token: string, - actionUrl: string, + authToken: string, + aquilaUrl: string, actionId: string, version: string, }, From 5b25b3c9f0b9db18369a4b2d89e00079d307636c Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Tue, 10 Mar 2026 15:49:10 +0100 Subject: [PATCH 4/6] Add comment --- ts/examples/simple_example.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ts/examples/simple_example.ts b/ts/examples/simple_example.ts index cd1d999..9ce3ed8 100644 --- a/ts/examples/simple_example.ts +++ b/ts/examples/simple_example.ts @@ -33,6 +33,7 @@ sdk.registerFunctionDefinition( ], runtimeName: "fib", }, + // This param is optional and can be omitted (n: number, context: HerculesFunctionContext): number => { console.log("Project id:", context.projectId); console.log("Execution id:", context.executionId); From cd7de0d1752e3533fcfd72f9a1721dcb541fd994 Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Tue, 10 Mar 2026 16:41:17 +0100 Subject: [PATCH 5/6] Update tucana --- bin/Gemfile | 2 +- bin/Gemfile.lock | 10 +++------- bin/test_server.rb | 20 ++------------------ ts/bun.lock | 4 ++-- ts/examples/simple_example.ts | 1 + ts/package.json | 2 +- ts/src/action_sdk.ts | 6 +++--- 7 files changed, 13 insertions(+), 32 deletions(-) diff --git a/bin/Gemfile b/bin/Gemfile index 7bc0494..23c96af 100644 --- a/bin/Gemfile +++ b/bin/Gemfile @@ -5,4 +5,4 @@ source 'https://rubygems.org' ruby '3.4.7' gem 'grpc', '~> 1.67' -gem 'tucana', '0.0.56' +gem 'tucana', '0.0.57' diff --git a/bin/Gemfile.lock b/bin/Gemfile.lock index 7efaa01..a0fe082 100644 --- a/bin/Gemfile.lock +++ b/bin/Gemfile.lock @@ -1,9 +1,3 @@ -PATH - remote: ../../tucana/build/ruby - specs: - tucana (0.0.0) - grpc (~> 1.64) - GEM remote: https://rubygems.org/ specs: @@ -23,6 +17,8 @@ GEM google-protobuf (>= 3.25, < 5.0) googleapis-common-protos-types (~> 1.0) rake (13.3.1) + tucana (0.0.57) + grpc (~> 1.64) PLATFORMS ruby @@ -30,7 +26,7 @@ PLATFORMS DEPENDENCIES grpc (~> 1.67) - tucana (= 0.0.0)! + tucana (= 0.0.57) RUBY VERSION ruby 3.4.7p58 diff --git a/bin/test_server.rb b/bin/test_server.rb index 9f2b9d3..cd4d80e 100755 --- a/bin/test_server.rb +++ b/bin/test_server.rb @@ -31,16 +31,6 @@ def add_runtime_functions(functions) def add_action_config_definition(config) @action_config_definitions << config end - - def register_config_definitions(token, config_definitions) - @action_config_definitions.each do |config| - next unless config[:auth_token] == token - - config[:config_definitions] = config_definitions - puts "Registered config definitions for action: #{config[:action_identifier]} (v#{config[:version]})" - break - end - end end class FlowTypeTransferService < Tucana::Aquila::FlowTypeService::Service @@ -144,6 +134,7 @@ def transfer(requests, call) yielder << Tucana::Aquila::TransferResponse.new( { execution: Tucana::Aquila::ExecutionRequest.new( + project_id: Random.rand(1..1000), execution_identifier: exec_identifier, function_identifier: func.runtime_name, parameters: construct_parameters(func) @@ -155,7 +146,6 @@ def transfer(requests, call) end requests.each do |req| - p req unless req.result.nil? puts "Received execution result for: #{req.result.execution_identifier}" puts "Result value: #{req.result.result}" @@ -168,12 +158,6 @@ def transfer(requests, call) puts "Project id: #{req.event.project_id}" next end - - unless req.action_configuration.nil? - @state.register_config_definitions(token, - req.action_configuration.action_configurations) - end - next if req.logon.nil? logon = req.logon @@ -182,7 +166,7 @@ def transfer(requests, call) auth_token: token, action_identifier: logon.action_identifier, version: logon.version, - config_definitions: [], + config_definitions: logon.action_configurations, }) puts "Action logon received: #{logon.action_identifier} (v#{logon.version})" diff --git a/ts/bun.lock b/ts/bun.lock index b7857f9..6480e61 100644 --- a/ts/bun.lock +++ b/ts/bun.lock @@ -5,7 +5,7 @@ "": { "name": "ts", "dependencies": { - "@code0-tech/tucana": "^0.0.56", + "@code0-tech/tucana": "^0.0.57", "@grpc/grpc-js": "^1.14.3", "@protobuf-ts/grpc-transport": "^2.11.1", "@protobuf-ts/runtime": "^2.11.1", @@ -21,7 +21,7 @@ }, }, "packages": { - "@code0-tech/tucana": ["@code0-tech/tucana@0.0.56", "", {}, "sha512-tU/5HaqdKBIMIvJFbMJfPMDhqGIS48oyRis2M2ykrrzkEa9DjLjXDKmh4NmCaDQddP3IXPZp/4PJUC+SDWCV/g=="], + "@code0-tech/tucana": ["@code0-tech/tucana@0.0.57", "", {}, "sha512-E83SjcAWotN2uvQAmbIet4tsvSGOgwGeVOg9mTQ0KaU0R1VAKPp2or7mNsccEyo3KYnOMRoOt1bcAC4OMba8Sw=="], "@cspotcode/source-map-support": ["@cspotcode/source-map-support@0.8.1", "", { "dependencies": { "@jridgewell/trace-mapping": "0.3.9" } }, "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw=="], diff --git a/ts/examples/simple_example.ts b/ts/examples/simple_example.ts index 9ce3ed8..9288ff2 100644 --- a/ts/examples/simple_example.ts +++ b/ts/examples/simple_example.ts @@ -35,6 +35,7 @@ sdk.registerFunctionDefinition( }, // This param is optional and can be omitted (n: number, context: HerculesFunctionContext): number => { + console.log(context) console.log("Project id:", context.projectId); console.log("Execution id:", context.executionId); console.log("Matched configs:", context.matchedConfigs); // matched configs for the current execution diff --git a/ts/package.json b/ts/package.json index a195a3c..e6caa38 100644 --- a/ts/package.json +++ b/ts/package.json @@ -21,7 +21,7 @@ "license": "ISC", "type": "module", "dependencies": { - "@code0-tech/tucana": "^0.0.56", + "@code0-tech/tucana": "^0.0.57", "@grpc/grpc-js": "^1.14.3", "@protobuf-ts/grpc-transport": "^2.11.1", "@protobuf-ts/runtime": "^2.11.1", diff --git a/ts/src/action_sdk.ts b/ts/src/action_sdk.ts index 912ae26..60fa0d7 100644 --- a/ts/src/action_sdk.ts +++ b/ts/src/action_sdk.ts @@ -287,15 +287,15 @@ function handleExecutionRequest(state: SdkState, message: TransferResponse): Pro }) || [], } - if (func.handler.arguments.length == params.length + 1) { + if (func.handler.length == params.length + 1) { // handler has context parameter params.push(context) - } else if (func.handler.arguments.length > params.length + 1) { + } else if (func.handler.length > params.length + 1) { reject(new Error("Handler has more parameters than provided arguments")) return } - const result = func.handler(params.push(context)) + const result = func.handler(...params) try { return await state.stream!.requests.send( TransferRequest.create({ From 0ae683b97f8869d047bc8bcd34600cd9f4471abd Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Tue, 10 Mar 2026 21:14:32 +0100 Subject: [PATCH 6/6] Apply review --- ts/bun.lock | 4 +- ts/examples/simple_example.ts | 29 +++++++------- ts/package-lock.json | 8 ++-- ts/package.json | 2 +- ts/src/action_sdk.ts | 73 ++++++++++++++++++++--------------- ts/src/types.ts | 20 +++++----- 6 files changed, 74 insertions(+), 62 deletions(-) diff --git a/ts/bun.lock b/ts/bun.lock index 6480e61..a46996d 100644 --- a/ts/bun.lock +++ b/ts/bun.lock @@ -5,7 +5,7 @@ "": { "name": "ts", "dependencies": { - "@code0-tech/tucana": "^0.0.57", + "@code0-tech/tucana": "^0.0.58", "@grpc/grpc-js": "^1.14.3", "@protobuf-ts/grpc-transport": "^2.11.1", "@protobuf-ts/runtime": "^2.11.1", @@ -21,7 +21,7 @@ }, }, "packages": { - "@code0-tech/tucana": ["@code0-tech/tucana@0.0.57", "", {}, "sha512-E83SjcAWotN2uvQAmbIet4tsvSGOgwGeVOg9mTQ0KaU0R1VAKPp2or7mNsccEyo3KYnOMRoOt1bcAC4OMba8Sw=="], + "@code0-tech/tucana": ["@code0-tech/tucana@0.0.58", "", {}, "sha512-0kLzp/2y4aGiAW3SEwPnJXLhRIafuMEPa3f+sR7y/hb4JsSAn3/hMHAbtUee7axW8u4BCek7SX+Hyn68GP1CNQ=="], "@cspotcode/source-map-support": ["@cspotcode/source-map-support@0.8.1", "", { "dependencies": { "@jridgewell/trace-mapping": "0.3.9" } }, "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw=="], diff --git a/ts/examples/simple_example.ts b/ts/examples/simple_example.ts index 9288ff2..7da9da5 100644 --- a/ts/examples/simple_example.ts +++ b/ts/examples/simple_example.ts @@ -1,31 +1,31 @@ -import { createSdk } from "../src/action_sdk.js"; -import { constructValue } from "@code0-tech/tucana/helpers/shared.struct_helper.js"; -import { ActionProjectConfiguration } from "@code0-tech/tucana/pb/shared.action_configuration_pb.js"; -import { HerculesFunctionContext } from "../src/types.js"; +import {createSdk} from "../src/action_sdk.js"; +import {constructValue} from "@code0-tech/tucana/helpers/shared.struct_helper.js"; +import {ActionProjectConfiguration} from "@code0-tech/tucana/pb/shared.action_configuration_pb.js"; +import {HerculesFunctionContext} from "../src/types.js"; const sdk = createSdk({ authToken: "someToken", aquilaUrl: "127.0.0.1:50051", actionId: "action_123", version: "0.0.0", -}) - -sdk.registerConfigDefinitions({ - type: "LIST", - linkedDataTypeIdentifiers: ["STRING", "LIST"], - identifier: "config_discord_bot_token", -}) +}, [ + { + type: "LIST", + linkedDataTypeIdentifiers: ["STRING", "LIST"], + identifier: "config_discord_bot_token", + } +]) sdk.registerDataType({ identifier: "SOME_DATATYPE", - signature: "any", + type: "any", }) sdk.registerFunctionDefinition( { signature: "(n: NUMBER) => NUMBER", linkedDataTypeIdentifiers: ["NUMBER"], - runtimeParameterDefinitions: [ + parameters: [ { runtimeName: "n", defaultValue: 20, @@ -44,6 +44,7 @@ sdk.registerFunctionDefinition( if (num <= 1) return num; return fibonacci(num - 1) + fibonacci(num - 2); } + return fibonacci(n) } ) @@ -51,7 +52,7 @@ sdk.registerFunctionDefinition( sdk.registerFlowType( { editable: false, - inputTypeIdentifier: "STRING", + inputType: "STRING", identifier: "test_flow", } ) diff --git a/ts/package-lock.json b/ts/package-lock.json index b9c60fd..49ac935 100644 --- a/ts/package-lock.json +++ b/ts/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@code0-tech/tucana": "^0.0.52", + "@code0-tech/tucana": "^0.0.58", "@grpc/grpc-js": "^1.14.3", "@protobuf-ts/grpc-transport": "^2.11.1", "@protobuf-ts/runtime": "^2.11.1", @@ -24,9 +24,9 @@ } }, "node_modules/@code0-tech/tucana": { - "version": "0.0.52", - "resolved": "https://registry.npmjs.org/@code0-tech/tucana/-/tucana-0.0.52.tgz", - "integrity": "sha512-Pk78QdH6Ino4crHzhjhzYoRQSfCTGdc8W7u9SQc/vBJxO2TiVL2rVJ/KKgzlSQU/2r8Ijn/Zl3GYRlSgiPRnJQ==", + "version": "0.0.58", + "resolved": "https://registry.npmjs.org/@code0-tech/tucana/-/tucana-0.0.58.tgz", + "integrity": "sha512-0kLzp/2y4aGiAW3SEwPnJXLhRIafuMEPa3f+sR7y/hb4JsSAn3/hMHAbtUee7axW8u4BCek7SX+Hyn68GP1CNQ==", "license": "Apache-2.0" }, "node_modules/@cspotcode/source-map-support": { diff --git a/ts/package.json b/ts/package.json index e6caa38..2a9381f 100644 --- a/ts/package.json +++ b/ts/package.json @@ -21,7 +21,7 @@ "license": "ISC", "type": "module", "dependencies": { - "@code0-tech/tucana": "^0.0.57", + "@code0-tech/tucana": "^0.0.58", "@grpc/grpc-js": "^1.14.3", "@protobuf-ts/grpc-transport": "^2.11.1", "@protobuf-ts/runtime": "^2.11.1", diff --git a/ts/src/action_sdk.ts b/ts/src/action_sdk.ts index 60fa0d7..47f52ed 100644 --- a/ts/src/action_sdk.ts +++ b/ts/src/action_sdk.ts @@ -1,29 +1,28 @@ -import { GrpcTransport } from "@protobuf-ts/grpc-transport"; -import { ChannelCredentials } from "@grpc/grpc-js"; -import { ActionTransferServiceClient } from "@code0-tech/tucana/pb/aquila.action_pb.client.js"; -import { RpcOptions } from "@protobuf-ts/runtime-rpc"; +import {GrpcTransport} from "@protobuf-ts/grpc-transport"; +import {ChannelCredentials} from "@grpc/grpc-js"; +import {ActionTransferServiceClient} from "@code0-tech/tucana/pb/aquila.action_pb.client.js"; +import {RpcOptions} from "@protobuf-ts/runtime-rpc"; import { - ActionConfiguration, ExecutionRequest, TransferRequest, TransferResponse } from "@code0-tech/tucana/pb/aquila.action_pb.js"; -import { constructValue, toAllowedValue } from "@code0-tech/tucana/helpers/shared.struct_helper.js"; +import {constructValue, toAllowedValue} from "@code0-tech/tucana/helpers/shared.struct_helper.js"; import { ActionConfigurations, ActionProjectConfiguration } from "@code0-tech/tucana/pb/shared.action_configuration_pb"; -import { DataTypeServiceClient } from "@code0-tech/tucana/pb/aquila.data_type_pb.client"; -import { DataTypeUpdateRequest } from "@code0-tech/tucana/pb/aquila.data_type_pb"; -import { RuntimeFunctionDefinitionServiceClient } from "@code0-tech/tucana/pb/aquila.runtime_function_pb.client"; -import { RuntimeFunctionDefinitionUpdateRequest } from "@code0-tech/tucana/pb/aquila.runtime_function_pb"; -import { FlowTypeServiceClient } from "@code0-tech/tucana/pb/aquila.flow_type_pb.client"; -import { FlowTypeUpdateRequest } from "@code0-tech/tucana/pb/aquila.flow_type_pb"; -import { ActionSdk, HerculesFunctionContext, SdkState } from "./types"; -import { FlowTypeSetting_UniquenessScope } from "@code0-tech/tucana/pb/shared.flow_definition_pb"; +import {DataTypeServiceClient} from "@code0-tech/tucana/pb/aquila.data_type_pb.client"; +import {DataTypeUpdateRequest} from "@code0-tech/tucana/pb/aquila.data_type_pb"; +import {RuntimeFunctionDefinitionServiceClient} from "@code0-tech/tucana/pb/aquila.runtime_function_pb.client"; +import {RuntimeFunctionDefinitionUpdateRequest} from "@code0-tech/tucana/pb/aquila.runtime_function_pb"; +import {FlowTypeServiceClient} from "@code0-tech/tucana/pb/aquila.flow_type_pb.client"; +import {FlowTypeUpdateRequest} from "@code0-tech/tucana/pb/aquila.flow_type_pb"; +import {ActionSdk, HerculesActionConfigurationDefinition, HerculesFunctionContext, SdkState} from "./types"; +import {FlowTypeSetting, FlowTypeSetting_UniquenessScope} from "@code0-tech/tucana/pb/shared.flow_definition_pb"; -export const createSdk = (config: ActionSdk["config"]): ActionSdk => { +export const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActionConfigurationDefinition[]): ActionSdk => { const transport = new GrpcTransport( { host: config.aquilaUrl, @@ -36,7 +35,16 @@ export const createSdk = (config: ActionSdk["config"]): ActionSdk => { functions: [], dataTypes: [], flowTypes: [], - configurationDefinitions: [], + configurationDefinitions: configDefinitions?.map(value => { + return { + identifier: value.identifier, + name: value.name || [], + description: value.description || [], + type: value.type, + linkedDataTypeIdentifiers: value.linkedDataTypeIdentifiers || [], + defaultValue: constructValue(value.defaultValue || null), + } + }) || [], projectConfigurations: [], transport: transport, client: client, @@ -79,7 +87,7 @@ export const createSdk = (config: ActionSdk["config"]): ActionSdk => { alias: dataType.alias || [], rules: dataType.rules || [], genericKeys: dataType.genericKeys || [], - signature: dataType.signature, + type: dataType.type, linkedDataTypeIdentifiers: dataType.linkedDataTypeIdentifiers || [], displayMessage: dataType.displayMessage || [], definitionSource: "action", @@ -100,17 +108,19 @@ export const createSdk = (config: ActionSdk["config"]): ActionSdk => { documentation: flowType.documentation || [], definitionSource: "action", version: flowType.version || config.version, - inputTypeIdentifier: flowType.inputTypeIdentifier, - returnTypeIdentifier: flowType.returnTypeIdentifier, + inputType: flowType.inputType || "", + returnType: flowType.returnType || "", + linkedDataTypeIdentifiers: flowType.linkedDataTypeIdentifiers || [], settings: (flowType.settings || []).map(setting => ({ name: setting.name || [], defaultValue: constructValue(setting.defaultValue || null), identifier: setting.identifier, description: setting.description || [], unique: setting.unique || FlowTypeSetting_UniquenessScope.NONE, - dataTypeIdentifier: setting.dataTypeIdentifier - })), - editable: flowType.editable || false, + type: setting.dataTypeIdentifier, + linkedDataTypeIdentifiers: setting.linkedDataTypeIdentifiers || [], + } as FlowTypeSetting)), + editable: flowType.editable || false }); return Promise.resolve() }, @@ -129,7 +139,7 @@ export const createSdk = (config: ActionSdk["config"]): ActionSdk => { definitionSource: "action", version: functionDefinition.version || config.version, runtimeName: functionDefinition.runtimeName, - runtimeParameterDefinitions: (functionDefinition.runtimeParameterDefinitions || []).map(param => ({ + runtimeParameterDefinitions: (functionDefinition.parameters || []).map(param => ({ runtimeName: param.runtimeName, name: param.name || [], description: param.description || [], @@ -194,18 +204,17 @@ async function connect(state: SdkState, config: ActionSdk["config"], options?: R }) - await state.stream.requests.send( TransferRequest.create({ - data: { - oneofKind: "logon", - logon: { - actionIdentifier: config.actionId, - version: config.version, - actionConfigurations: state.configurationDefinitions + data: { + oneofKind: "logon", + logon: { + actionIdentifier: config.actionId, + version: config.version, + actionConfigurations: state.configurationDefinitions + } } } - } ), ).catch(reason => { return Promise.reject(reason); @@ -283,7 +292,7 @@ function handleExecutionRequest(state: SdkState, message: TransferResponse): Pro projectId: execution.projectId, executionId: execution.executionIdentifier, matchedConfigs: state.projectConfigurations.filter(config => { - config.projectId === execution.projectId + return config.projectId === execution.projectId }) || [], } diff --git a/ts/src/types.ts b/ts/src/types.ts index 960686f..32a4fd4 100644 --- a/ts/src/types.ts +++ b/ts/src/types.ts @@ -9,11 +9,11 @@ import { TransferRequest, TransferResponse } from "@code0-tech/tucana/pb/aquila.action_pb.js"; -import { AllowedValue } from "@code0-tech/tucana/helpers/shared.struct_helper.js"; import { ActionConfigurationDefinition, ActionProjectConfiguration } from "@code0-tech/tucana/pb/shared.action_configuration_pb"; import {Translation} from "@code0-tech/tucana/pb/shared.translation_pb"; +import {PlainValue} from "@code0-tech/tucana/helpers/shared.struct_helper"; export interface HerculesFunctionContext { projectId: number | bigint, @@ -28,7 +28,7 @@ export interface HerculesDefinitionDataType { alias?: Translation[], rules?: DefinitionDataTypeRule[], genericKeys?: string[], - signature: string, + type: string, linkedDataTypeIdentifiers?: string[], // Will default to sdk version version?: string @@ -38,7 +38,8 @@ export interface HerculesFlowTypeSetting { identifier: string, unique?: FlowTypeSetting_UniquenessScope, dataTypeIdentifier: string, - defaultValue?: Value, + linkedDataTypeIdentifiers?: string[], + defaultValue?: PlainValue, name?: Translation[], description?: Translation[], } @@ -46,8 +47,9 @@ export interface HerculesFlowTypeSetting { export interface HerculesFlowType { identifier: string, settings?: HerculesFlowTypeSetting[] - inputTypeIdentifier?: string, - returnTypeIdentifier?: string, + inputType?: string, + returnType?: string, + linkedDataTypeIdentifiers?: string[], editable: boolean, name?: Translation[], description?: Translation[], @@ -60,9 +62,9 @@ export interface HerculesFlowType { export interface HerculesRuntimeFunctionDefinition { runtimeName: string, - runtimeParameterDefinitions?: { + parameters?: { runtimeName: string, - defaultValue?: AllowedValue, + defaultValue?: PlainValue, name?: Translation[], description?: Translation[], documentation?: Translation[], @@ -85,7 +87,7 @@ export interface HerculesActionConfigurationDefinition { description?: Translation[], type: string, linkedDataTypeIdentifiers?: string[], - defaultValue?: AllowedValue, + defaultValue?: PlainValue, identifier: string, } @@ -106,7 +108,7 @@ export interface ActionSdk { registerDataType: (dataType: HerculesDefinitionDataType) => Promise, registerFlowType: (flowType: HerculesFlowType) => Promise, registerFunctionDefinition: (functionDefinition: HerculesRuntimeFunctionDefinition, handler: Function) => Promise, - dispatchEvent: (eventType: string, projectId: number | bigint, payload: AllowedValue) => Promise, + dispatchEvent: (eventType: string, projectId: number | bigint, payload: PlainValue) => Promise, } export interface RegisteredFunction {