Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: '24.x'
node-version: '25.9.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: '24.x'
node-version: '25.9.x'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
Expand Down
1 change: 1 addition & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[tools]
node = "25.9.0"
ruby = "latest"
2 changes: 1 addition & 1 deletion ts/.tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node 24.8.0
nodejs 25.9.0
4 changes: 2 additions & 2 deletions ts/examples/simple-example-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
} from "@code0-tech/hercules";

const sdk = createSdk({
authToken: "someToken",
authToken: "token",
aquilaUrl: "127.0.0.1:50051",
actionId: "action_123",
actionId: "service",
version: "0.0.0",
}, [
{
Expand Down
298 changes: 142 additions & 156 deletions ts/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"license": "ISC",
"type": "module",
"dependencies": {
"@code0-tech/tucana": "^0.0.65",
"@code0-tech/tucana": "^0.0.66",
"@grpc/grpc-js": "^1.14.3",
"@protobuf-ts/grpc-backend": "^2.11.1",
"@protobuf-ts/grpc-transport": "^2.11.1",
Expand Down
60 changes: 55 additions & 5 deletions ts/src/action_sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
DataTypeServiceClient,
DataTypeUpdateRequest, ExecutionRequest,
FlowTypeServiceClient,
FlowTypeUpdateRequest, RuntimeFunctionDefinitionServiceClient, RuntimeFunctionDefinitionUpdateRequest,
FlowTypeUpdateRequest,
FunctionDefinitionServiceClient,
FunctionDefinitionUpdateRequest, RuntimeFunctionDefinitionServiceClient, RuntimeFunctionDefinitionUpdateRequest,
TransferRequest, TransferResponse
} from "@code0-tech/tucana/aquila";
import {
Expand All @@ -30,6 +32,7 @@ const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActi

const state: SdkState = {
functions: [],
runtimeFunctions: [],
dataTypes: [],
flowTypes: [],
configurationDefinitions: configDefinitions?.map(value => {
Expand Down Expand Up @@ -137,11 +140,11 @@ const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActi
})
return Promise.resolve()
},
registerFunctionDefinitions: async (...functionDefinitions) => {
for (const registeredFunction of functionDefinitions) {
registerRuntimeFunctionDefinitions: async (...runtimeFunctionDefinitions) => {
for (const registeredFunction of runtimeFunctionDefinitions) {
const handler = registeredFunction.handler;
const functionDefinition = registeredFunction.definition;
state.functions.push({
state.runtimeFunctions.push({
identifier: functionDefinition.runtimeName,
definition: {
displayMessage: functionDefinition.displayMessage || [],
Expand Down Expand Up @@ -170,6 +173,36 @@ const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActi
}
return Promise.resolve()
},
registerFunctionDefinitions: async (...functionDefinitions) => {
for (const functionDefinition of functionDefinitions) {
state.functions.push({
identifier: functionDefinition.runtimeName,
definition: {
displayMessage: functionDefinition.displayMessage || [],
name: functionDefinition.name || [],
documentation: functionDefinition.documentation || [],
description: functionDefinition.description || [],
deprecationMessage: functionDefinition.deprecationMessage || [],
displayIcon: functionDefinition.displayIcon || "",
alias: functionDefinition.alias || [],
linkedDataTypeIdentifiers: functionDefinition.linkedDataTypes || [],
definitionSource: "action",
version: functionDefinition.version || config.version,
runtimeName: functionDefinition.runtimeName,
parameterDefinitions: (functionDefinition.parameters || []).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,
}
});
}
return Promise.resolve()
},
dispatchEvent: async (eventType, projectId, payload) => {
if (!state.stream) {
return Promise.reject("SDK is not connected. Call connect() before dispatching events.");
Expand Down Expand Up @@ -242,6 +275,23 @@ async function connect(state: SdkState, config: ActionSdk["config"], options?: R
RuntimeFunctionDefinitionUpdateRequest.create(
{
runtimeFunctions: [
...state.runtimeFunctions.map(func => ({
...func.definition,
}))
]
}
), builtOptions
).then(value => {
if (!value.response.success) {
return Promise.reject(value.response);
}
})

const FunctionDefinitionClient = new FunctionDefinitionServiceClient(state.transport)
await FunctionDefinitionClient.update(
FunctionDefinitionUpdateRequest.create(
{
functions: [
...state.functions.map(func => ({
...func.definition,
}))
Expand Down Expand Up @@ -309,7 +359,7 @@ function handleExecutionRequest(state: SdkState, message: TransferResponse) {
return
}
const execution = message.data.execution as ExecutionRequest;
const func = state.functions.find(value => value.identifier == execution.functionIdentifier);
const func = state.runtimeFunctions.find(value => value.identifier == execution.functionIdentifier);
if (func) {
const params = Object.entries(execution.parameters!.fields!).map(([key, value]) => {
const param = func.definition.runtimeParameterDefinitions
Expand Down
16 changes: 13 additions & 3 deletions ts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ActionConfigurationDefinition, ActionProjectConfiguration,
DefinitionDataType,
DefinitionDataTypeRule, FlowType,
FlowTypeSetting_UniquenessScope,
FlowTypeSetting_UniquenessScope, FunctionDefinition,
RuntimeFunctionDefinition,
Translation
} from "@code0-tech/tucana/shared";
Expand Down Expand Up @@ -56,6 +56,7 @@ export interface HerculesFlowType {
displayIcon?: string,
}


export interface HerculesRuntimeFunctionDefinition {
runtimeName: string,
parameters?: {
Expand All @@ -78,6 +79,8 @@ export interface HerculesRuntimeFunctionDefinition {
displayIcon?: string,
}

export type HerculesRegisterFunctionDefinition = HerculesRuntimeFunctionDefinition

export interface HerculesActionProjectConfiguration {
projectId: number | bigint,
configValues: {
Expand All @@ -96,7 +99,7 @@ export interface HerculesActionConfigurationDefinition {
identifier: string,
}

export type HerculesRegisterFunctionParameter = {
export type HerculesRegisterRuntimeFunctionParameter = {
definition: HerculesRuntimeFunctionDefinition,
handler: (...args: any[]) => Promise<PlainValue> | PlainValue,
}
Expand All @@ -117,7 +120,8 @@ export interface ActionSdk {
registerConfigDefinitions: (...actionConfigurations: Array<HerculesActionConfigurationDefinition>) => Promise<void>,
registerDataTypes: (...dataType: Array<HerculesDataType>) => Promise<void>,
registerFlowTypes: (...flowTypes: Array<HerculesFlowType>) => Promise<void>,
registerFunctionDefinitions: (...functionDefinitions: Array<HerculesRegisterFunctionParameter>) => Promise<void>,
registerFunctionDefinitions: (...functionDefinitions: Array<HerculesRegisterFunctionDefinition>) => Promise<void>,
registerRuntimeFunctionDefinitions: (...runtimeFunctionDefinitions: Array<HerculesRegisterRuntimeFunctionParameter>) => Promise<void>,
dispatchEvent: (eventType: string, projectId: number | bigint, payload: PlainValue) => Promise<void>,
}

Expand All @@ -134,13 +138,19 @@ export class RuntimeErrorException extends Error {
}

export interface RegisteredFunction {
identifier: string,
definition: FunctionDefinition
}

export interface RegisteredRuntimeFunction {
identifier: string,
definition: RuntimeFunctionDefinition,
handler: (...args: any[]) => Promise<PlainValue> | PlainValue,
}

export interface SdkState {
functions: RegisteredFunction[],
runtimeFunctions: RegisteredRuntimeFunction[],
dataTypes: DefinitionDataType[],
flowTypes: FlowType[],
configurationDefinitions: ActionConfigurationDefinition[],
Expand Down