From 85852d0e0ac3188f9a8d5490762cde980e576c5a Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Sat, 4 Apr 2026 20:56:47 +0200 Subject: [PATCH 1/6] Update hercules version and abstract docs more --- actions/ai-action/.example.env | 4 + actions/ai-action/Dockerfile | 18 + actions/ai-action/package.json | 24 + actions/ai-action/scripts/generateDocs.ts | 45 + .../ai-action/src/config/authTokenConfig.ts | 45 + .../models/anthropic/anthropicSettings.ts | 14 + .../src/functions/models/anthropic/common.ts | 8 + .../functions/models/createModelFunction.ts | 66 ++ .../src/functions/models/google/common.ts | 8 + .../functions/models/google/googleSettings.ts | 18 + .../src/functions/models/ollama/common.ts | 9 + .../functions/models/ollama/ollamaSettings.ts | 14 + .../src/functions/models/openai/common.ts | 8 + .../functions/models/openai/openAiSettings.ts | 14 + actions/ai-action/src/helpers.ts | 207 ++++ actions/ai-action/src/index.ts | 42 + actions/ai-action/src/types/aiModel.ts | 41 + actions/ai-action/tsconfig.json | 7 + actions/ai-action/vite.config.ts | 31 + actions/ai-action/vitest.config.ts | 8 + actions/gls-action/scripts/generateDocs.ts | 17 +- .../src/functions/cancelShipment.ts | 2 +- .../src/functions/getAllowedServices.ts | 2 +- .../src/functions/getEndOfDayReport.ts | 2 +- .../gls-action/src/functions/reprintParcel.ts | 2 +- .../services/createAddresseeOnlyShipment.ts | 2 +- .../services/createDeliveryAtWorkShipment.ts | 2 +- .../createDeliveryNextWorkingDayShipment.ts | 2 +- .../createDeliverySaturdayShipment.ts | 2 +- .../services/createDepositShipment.ts | 2 +- .../services/createExchangeShipment.ts | 2 +- .../services/createFlexDeliveryShipment.ts | 2 +- .../services/createGuaranteed24Shipment.ts | 2 +- .../services/createIdentPinShipment.ts | 2 +- .../functions/services/createIdentShipment.ts | 2 +- .../services/createPickAndShipShipment.ts | 2 +- .../services/createShopDeliveryShipment.ts | 2 +- .../services/createShopReturnShipment.ts | 2 +- .../services/createSignatureShipment.ts | 2 +- .../functions/services/createTyreShipment.ts | 2 +- .../src/functions/updateParcelWeight.ts | 2 +- .../src/functions/utils/createAddress.ts | 2 +- .../src/functions/utils/createConsignee.ts | 2 +- .../functions/utils/createCustomContent.ts | 2 +- .../functions/utils/createPrintingOptions.ts | 2 +- .../src/functions/utils/createShipmentUnit.ts | 2 +- .../src/functions/validateShipment.ts | 2 +- actions/gls-action/src/helpers.ts | 37 - actions/gls-action/src/types/glsAddress.ts | 2 +- .../src/types/glsAllowedServices.ts | 2 +- .../gls-action/src/types/glsCancelShipment.ts | 2 +- actions/gls-action/src/types/glsConsignee.ts | 2 +- .../src/types/glsCreateParcelsResponse.ts | 2 +- .../gls-action/src/types/glsCustomContent.ts | 2 +- .../src/types/glsEndOfDayRequest.ts | 2 +- .../src/types/glsPrintingOptions.ts | 2 +- .../gls-action/src/types/glsReprintParcel.ts | 2 +- .../gls-action/src/types/glsReturnOptions.ts | 2 +- actions/gls-action/src/types/glsShipment.ts | 2 +- .../gls-action/src/types/glsShipmentUnit.ts | 2 +- actions/gls-action/src/types/glsShipper.ts | 2 +- .../gls-action/src/types/glsUnitService.ts | 2 +- .../src/types/glsUpdateParcelWeight.ts | 2 +- .../src/types/glsValidateShipment.ts | 2 +- .../test/functions/reprintParcel.test.ts | 2 +- .../gls-action/test/helpers/withSdkMock.ts | 38 +- actions/gls-action/test/index.test.ts | 9 +- code0-tech-hercules-0.0.0.tgz | Bin 0 -> 5323 bytes docker-compose.yml | 7 +- docs/Actions/AI/functions.mdx | 998 ++++++++++++++++++ docs/Actions/AI/types.mdx | 256 +++++ package-lock.json | 238 ++++- package.json | 2 +- scripts/create-action.mjs | 133 ++- src/helpers.ts | 42 + src/standardActionDocs.ts | 82 +- 76 files changed, 2392 insertions(+), 184 deletions(-) create mode 100644 actions/ai-action/.example.env create mode 100644 actions/ai-action/Dockerfile create mode 100644 actions/ai-action/package.json create mode 100644 actions/ai-action/scripts/generateDocs.ts create mode 100644 actions/ai-action/src/config/authTokenConfig.ts create mode 100644 actions/ai-action/src/functions/models/anthropic/anthropicSettings.ts create mode 100644 actions/ai-action/src/functions/models/anthropic/common.ts create mode 100644 actions/ai-action/src/functions/models/createModelFunction.ts create mode 100644 actions/ai-action/src/functions/models/google/common.ts create mode 100644 actions/ai-action/src/functions/models/google/googleSettings.ts create mode 100644 actions/ai-action/src/functions/models/ollama/common.ts create mode 100644 actions/ai-action/src/functions/models/ollama/ollamaSettings.ts create mode 100644 actions/ai-action/src/functions/models/openai/common.ts create mode 100644 actions/ai-action/src/functions/models/openai/openAiSettings.ts create mode 100644 actions/ai-action/src/helpers.ts create mode 100644 actions/ai-action/src/index.ts create mode 100644 actions/ai-action/src/types/aiModel.ts create mode 100644 actions/ai-action/tsconfig.json create mode 100644 actions/ai-action/vite.config.ts create mode 100644 actions/ai-action/vitest.config.ts create mode 100644 code0-tech-hercules-0.0.0.tgz create mode 100644 docs/Actions/AI/functions.mdx create mode 100644 docs/Actions/AI/types.mdx create mode 100644 src/helpers.ts diff --git a/actions/ai-action/.example.env b/actions/ai-action/.example.env new file mode 100644 index 0000000..c6c7c80 --- /dev/null +++ b/actions/ai-action/.example.env @@ -0,0 +1,4 @@ +HERCULES_AUTH_TOKEN=your_hercules_auth_token_here +HERCULES_AQUILA_URL=https://aquila.hercules-ci.com +HERCULES_ACTION_ID=gls-action +HERCULES_SDK_VERSION=0.0.0 \ No newline at end of file diff --git a/actions/ai-action/Dockerfile b/actions/ai-action/Dockerfile new file mode 100644 index 0000000..3fb2319 --- /dev/null +++ b/actions/ai-action/Dockerfile @@ -0,0 +1,18 @@ +FROM node:24-alpine + +WORKDIR /app + +COPY code0-tech-* ./ + +COPY package.json package-lock.json tsconfig.base.json turbo.json ./ + +COPY actions/ai ./actions/ai-action + +RUN npm ci + +WORKDIR /app/actions/ai-action + +RUN npm run build + + +CMD ["npm", "run", "start", "-w", "@code0-tech/ai-action"] \ No newline at end of file diff --git a/actions/ai-action/package.json b/actions/ai-action/package.json new file mode 100644 index 0000000..e736426 --- /dev/null +++ b/actions/ai-action/package.json @@ -0,0 +1,24 @@ +{ + "name": "@code0-tech/ai-action", + "version": "0.0.0", + "private": true, + "type": "module", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "scripts": { + "build": "vite build", + "lint": "eslint .", + "test": "vitest run", + "start": "node dist/main.js", + "generate:docs": "npm run build && node dist/generateDocs.js" + }, + "dependencies": { + "@ai-sdk/anthropic": "^3.0.66", + "@ai-sdk/google": "^3.0.57", + "@ai-sdk/openai": "^3.0.50", + "ai": "^6.0.145", + "ai-sdk-ollama": "^3.8.2", + "ollama-ai-provider-v2": "^3.5.0", + "ts-morph": "^27.0.2" + } +} diff --git a/actions/ai-action/scripts/generateDocs.ts b/actions/ai-action/scripts/generateDocs.ts new file mode 100644 index 0000000..48b36d1 --- /dev/null +++ b/actions/ai-action/scripts/generateDocs.ts @@ -0,0 +1,45 @@ +import {RegistryState, runStandardActionDocs, StandardActionDocsConfig} from "../../../src/standardActionDocs" +import {loadAllDefinitions, loadAllDefinitionsByModules} from "../src/helpers"; +import {ActionSdk} from "@code0-tech/hercules"; + +export function generateAIConfig(): StandardActionDocsConfig { + return { + actionName: "AI", + typePrefix: "AI_", + typesOutputPath: "../../docs/Actions/AI/types.mdx", + functionsOutputPath: "../../docs/Actions/AI/functions.mdx", + loadAllDefinitions: loadAllDefinitions, + typeLinkOverrides: {}, + typesCopy: { + title: "Datatypes", + description: "All data types registered by the AI Action.", + heading: "AI Action Types", + intro: `The AI Action registers the following data types with the Hercules platform.`, + }, + functionsCopy: { + title: "Functions", + description: "All functions registered by the AI Action.", + intro: "" + }, + functionGroups: [ + { + heading: "OpenAI Models", + loadFunctions: async (sdk) => await loadAllDefinitionsByModules(sdk, import.meta.glob("../src/functions/models/openai/common.ts")), + }, + { + heading: "Google Models", + loadFunctions: async (sdk) => await loadAllDefinitionsByModules(sdk, import.meta.glob("../src/functions/models/google/common.ts")), + }, + { + heading: "Anthropic Models", + loadFunctions: async (sdk) => await loadAllDefinitionsByModules(sdk, import.meta.glob("../src/functions/models/anthropic/common.ts")), + }, + { + heading: "Ollama", + loadFunctions: async (sdk) => await loadAllDefinitionsByModules(sdk, import.meta.glob("../src/functions/models/ollama/common.ts")), + }, + ], + } +} + +await runStandardActionDocs(generateAIConfig()) diff --git a/actions/ai-action/src/config/authTokenConfig.ts b/actions/ai-action/src/config/authTokenConfig.ts new file mode 100644 index 0000000..df5bcee --- /dev/null +++ b/actions/ai-action/src/config/authTokenConfig.ts @@ -0,0 +1,45 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {z} from "zod"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers" +import {ModelSchema} from "../types/aiModel"; + +const providers = ModelSchema.shape.provider.options; + +export const AuthTokensConfigSchema = z.object( + Object.fromEntries( + providers.map((option) => [ + option, + z.object({ + defaultToken: z.string(), + overrides: z.record(z.string(), z.string()) + }) + ]) + ) +); + +export type AuthTokensConfig = z.infer + +export default (sdk: ActionSdk) => { + sdk.registerDataTypes({ + type: singleZodSchemaToTypescriptDef("AI_CONFIG_AUTH_TOKENS_TYPE", AuthTokensConfigSchema), + identifier: "AI_CONFIG_AUTH_TOKENS_TYPE" + }) + + return sdk.registerConfigDefinitions({ + type: "AI_CONFIG_AUTH_TOKENS_TYPE", + identifier: "AUTH_TOKENS", + linkedDataTypes: ["AI_CONFIG_AUTH_TOKENS_TYPE"], + name: [ + { + code: "en-US", + content: "Auth tokens" + } + ], + description: [ + { + code: "en-US", + content: "Every configured " + } + ] + }) +} \ No newline at end of file diff --git a/actions/ai-action/src/functions/models/anthropic/anthropicSettings.ts b/actions/ai-action/src/functions/models/anthropic/anthropicSettings.ts new file mode 100644 index 0000000..62dbe26 --- /dev/null +++ b/actions/ai-action/src/functions/models/anthropic/anthropicSettings.ts @@ -0,0 +1,14 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {singleZodSchemaToTypescriptDef} from "../../../../../../src/helpers"; +import z from "zod"; + +export const AnthropicSettingsSchema = z.looseObject({ + +}) + +export default (sdk: ActionSdk) => { + return sdk.registerDataTypes({ + type: singleZodSchemaToTypescriptDef("ANTHROPIC_SETTINGS", AnthropicSettingsSchema), + identifier: "ANTHROPIC_SETTINGS" + }) +} \ No newline at end of file diff --git a/actions/ai-action/src/functions/models/anthropic/common.ts b/actions/ai-action/src/functions/models/anthropic/common.ts new file mode 100644 index 0000000..3fb9fff --- /dev/null +++ b/actions/ai-action/src/functions/models/anthropic/common.ts @@ -0,0 +1,8 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {Model} from "../../../types/aiModel"; +import {registerDefaultCommonAiModelFunction} from "../../../helpers"; + +export default (sdk: ActionSdk, provider: Model["provider"], model: Model["model"]) => { + if (!provider || !model) return Promise.resolve() + return registerDefaultCommonAiModelFunction(sdk, "AI_ANTHROPIC_SETTINGS", provider, model) +} diff --git a/actions/ai-action/src/functions/models/createModelFunction.ts b/actions/ai-action/src/functions/models/createModelFunction.ts new file mode 100644 index 0000000..57fa8fb --- /dev/null +++ b/actions/ai-action/src/functions/models/createModelFunction.ts @@ -0,0 +1,66 @@ +import {ActionSdk, HerculesFunctionContext} from "@code0-tech/hercules"; +import {Model} from "../../types/aiModel"; + + +export default (sdk: ActionSdk) => { + return sdk.registerRuntimeFunctionDefinitions({ + definition: { + runtimeName: "createModel", + signature: "(settings: object, maxOutputTokens?: number, temperature?: number, maxRetries?: number, stopSequences?: string[], presencePenalty?: number, frequencyPenalty?: number, seed?: number) => AI_MODEL", + parameters: [ + { + runtimeName: "provider", + }, + { + runtimeName: "model", + }, + { + runtimeName: "settings", + }, + { + runtimeName: "maxOutputTokens" + }, + { + runtimeName: "temperature" + }, + { + runtimeName: "maxRetries" + }, + { + runtimeName: "stopSequences" + }, + { + runtimeName: "presencePenalty" + }, + { + runtimeName: "frequencyPenalty" + }, + { + runtimeName: "seed" + } + ], + }, + handler: (provider: Model["provider"], + model: Model["model"], + maxOutputTokens?: Model["maxOutputTokens"], + temperature?: Model["temperature"], + maxRetries?: Model["maxRetries"], + stopSequences?: Model["stopSequences"], + presencePenalty?: Model["presencePenalty"], + frequencyPenalty?: Model["frequencyPenalty"], + seed?: Model["seed"] + ): Model => { + return { + provider: provider, + model: model, + maxOutputTokens: maxOutputTokens, + frequencyPenalty: frequencyPenalty, + presencePenalty: presencePenalty, + stopSequences: stopSequences, + temperature: temperature, + maxRetries: maxRetries, + seed: seed + } + } + }) +} \ No newline at end of file diff --git a/actions/ai-action/src/functions/models/google/common.ts b/actions/ai-action/src/functions/models/google/common.ts new file mode 100644 index 0000000..f6fb4bd --- /dev/null +++ b/actions/ai-action/src/functions/models/google/common.ts @@ -0,0 +1,8 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {Model} from "../../../types/aiModel"; +import {registerDefaultCommonAiModelFunction} from "../../../helpers"; + +export default (sdk: ActionSdk, provider: Model["provider"], model: Model["model"]) => { + if (!provider || !model) return Promise.resolve() + return registerDefaultCommonAiModelFunction(sdk, "AI_GOOGLE_SETTINGS", provider, model) +} \ No newline at end of file diff --git a/actions/ai-action/src/functions/models/google/googleSettings.ts b/actions/ai-action/src/functions/models/google/googleSettings.ts new file mode 100644 index 0000000..b27963f --- /dev/null +++ b/actions/ai-action/src/functions/models/google/googleSettings.ts @@ -0,0 +1,18 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {singleZodSchemaToTypescriptDef} from "../../../../../../src/helpers"; +import z from "zod"; + +export const GoogleSettingsSchema = z.looseObject({ + thinkingConfig: z.object({ + thinkingBudget: z.number().optional(), + includeThoughts: z.boolean().optional(), + thinkingLevel: z.enum(["minimal", "low", "medium", "high"]).optional() + }).optional() +}) + +export default (sdk: ActionSdk) => { + return sdk.registerDataTypes({ + type: singleZodSchemaToTypescriptDef("AI_GOOGLE_SETTINGS", GoogleSettingsSchema), + identifier: "AI_GOOGLE_SETTINGS" + }) +} \ No newline at end of file diff --git a/actions/ai-action/src/functions/models/ollama/common.ts b/actions/ai-action/src/functions/models/ollama/common.ts new file mode 100644 index 0000000..c4b1450 --- /dev/null +++ b/actions/ai-action/src/functions/models/ollama/common.ts @@ -0,0 +1,9 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {Model} from "../../../types/aiModel"; +import {registerDefaultCommonAiModelFunction} from "../../../helpers"; + +export default (sdk: ActionSdk, provider: Model["provider"], model: Model["model"]) => { + if (!provider || !model) return Promise.resolve() + return registerDefaultCommonAiModelFunction(sdk, "AI_OLLAMA_SETTINGS", provider, model) +} + diff --git a/actions/ai-action/src/functions/models/ollama/ollamaSettings.ts b/actions/ai-action/src/functions/models/ollama/ollamaSettings.ts new file mode 100644 index 0000000..4e67ab9 --- /dev/null +++ b/actions/ai-action/src/functions/models/ollama/ollamaSettings.ts @@ -0,0 +1,14 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {singleZodSchemaToTypescriptDef} from "../../../../../../src/helpers"; +import z from "zod"; + +export const OllamaSettingsSchema = z.looseObject({ + baseURL: z.string() +}) + +export default (sdk: ActionSdk) => { + return sdk.registerDataTypes({ + type: singleZodSchemaToTypescriptDef("AI_OLLAMA_SETTINGS", OllamaSettingsSchema), + identifier: "AI_OLLAMA_SETTINGS" + }) +} \ No newline at end of file diff --git a/actions/ai-action/src/functions/models/openai/common.ts b/actions/ai-action/src/functions/models/openai/common.ts new file mode 100644 index 0000000..0d1e096 --- /dev/null +++ b/actions/ai-action/src/functions/models/openai/common.ts @@ -0,0 +1,8 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {Model} from "../../../types/aiModel"; +import {registerDefaultCommonAiModelFunction} from "../../../helpers"; + +export default (sdk: ActionSdk, provider: Model["provider"], model: Model["model"]) => { + if (!provider || !model) return Promise.resolve() + return registerDefaultCommonAiModelFunction(sdk, "AI_OPENAI_SETTINGS", provider, model) +} diff --git a/actions/ai-action/src/functions/models/openai/openAiSettings.ts b/actions/ai-action/src/functions/models/openai/openAiSettings.ts new file mode 100644 index 0000000..ab2aaa1 --- /dev/null +++ b/actions/ai-action/src/functions/models/openai/openAiSettings.ts @@ -0,0 +1,14 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {singleZodSchemaToTypescriptDef} from "../../../../../../src/helpers"; +import z from "zod"; + +export const OpenAiSettingsSchema = z.looseObject({ + +}) + +export default (sdk: ActionSdk) => { + return sdk.registerDataTypes({ + type: singleZodSchemaToTypescriptDef("AI_OPENAI_SETTINGS", OpenAiSettingsSchema), + identifier: "AI_OPENAI_SETTINGS" + }) +} \ No newline at end of file diff --git a/actions/ai-action/src/helpers.ts b/actions/ai-action/src/helpers.ts new file mode 100644 index 0000000..2ad321a --- /dev/null +++ b/actions/ai-action/src/helpers.ts @@ -0,0 +1,207 @@ +import {ActionSdk, HerculesFunctionContext, RuntimeErrorException} from "@code0-tech/hercules"; +import {AuthTokensConfigSchema} from "./config/authTokenConfig"; +import {Model, MODEL_REGISTRY} from "./types/aiModel"; + +export function registerDefaultCommonAiModelFunction(sdk: ActionSdk, settingsTypeName: string, provider: Model["provider"], model: Model["model"]) { + return sdk.registerFunctionDefinitions( + { + name: [ + { + code: "en-US", + content: `Create ${provider} - ${model}` + } + ], + documentation: [ + { + code: "en-US", + content: "Auto generated wrapper function to create this model" + } + ], + runtimeDefinitionName: "createModel", + runtimeName: `${provider}/${model}`, + signature: `(settings: ${settingsTypeName}, maxOutputTokens?: number, temperature?: number, maxRetries?: number, stopSequences?: string[], presencePenalty?: number, frequencyPenalty?: number, seed?: number): AI_MODEL`, + parameters: [ + { + runtimeName: "provider", + defaultValue: provider, + hidden: true + }, + { + runtimeName: "model", + defaultValue: model, + hidden: true, + }, + { + runtimeName: "settings", + name: [ + { + code: "en-US", + content: "Settings" + } + ], + description: [ + { + code: "en-US", + content: "The settings for this provider, for more information see the type" + } + ] + }, + { + runtimeName: "maxOutputTokens", + name: [ + { + code: "en-US", + content: "Max Output Tokens" + } + ], + description: [ + { + code: "en-US", + content: "Maximum number of tokens to generate" + } + ] + }, + { + description: [ + { + code: "en-US", + content: "temperature is a parameter that controls the randomness of the model’s outputs during text generation. Normally between 0 and 1" + } + ], + name: [ + { + code: "en-US", + content: "Temperature" + } + ], + runtimeName: "temperature" + }, + { + runtimeName: "maxRetries", + name: [ + { + code: "en-US", + content: "Maximum Retries" + } + ], + description: [ + { + code: "en-US", + content: "Maximum number of retries. Set to 0 to disable retries. Default value is 2" + } + ], + }, + { + runtimeName: "stopSequences", + name: [ + { + code: "en-US", + content: "Stop sequences" + } + ], + description: [ + { + code: "en-US", + content: "Stop sequences are specific strings (words, characters, or patterns) that tell an AI model when to stop generating text." + } + ] + }, + { + runtimeName: "presencePenalty", + name: [ + { + code: "en-US", + content: "Presence Penalty" + } + ], + description: [ + { + code: "en-US", + content: "Presence penalty pushes the model to talk about new things instead of repeating existing ones. Typical range of 0-2" + } + ] + }, + { + runtimeName: "frequencyPenalty", + name: [ + { + code: "en-US", + content: "Frequency Penalty" + } + ], + description: [ + { + code: "en-US", + content: "Frequency penalty is a parameter that reduces the likelihood of the model repeating the same words or phrases multiple times. Typical range of 0-2" + } + ] + }, + { + runtimeName: "seed", + name: [ + { + code: "en-US", + content: "Seed" + } + ], + description: [ + { + code: "en-US", + content: "Seed is a parameter used to make AI model outputs reproducible." + } + ] + } + ], + } + ); +} + +export async function loadAllDefinitions(sdk: ActionSdk) { + const modules = import.meta.glob([ + './{types,functions,config}/**/*.ts' + ]); + + await loadAllDefinitionsByModules(sdk, modules) +} + +export async function loadAllDefinitionsByModules(sdk: ActionSdk, modules: { [x: string]: () => any; }) { + for (const path in modules) { + const mod: any = await modules[path](); + + if (typeof mod.default !== 'function') continue + + if (mod.default.length === 1) { + try { + await mod.default(sdk); + } catch (error) { + console.log(`Error registering functions from ${path}:`, error); + } + } else if (mod.default.length === 3) { + const parts = path.split("/") + const provider = parts.at(-2) as Model["provider"] + + for (const model of MODEL_REGISTRY[provider]) { + try { + await mod.default(sdk, provider, model); + } catch (error) { + console.log(`Error registering functions from ${path}:`, error); + } + } + } + } +} + +export function extractToken(context: HerculesFunctionContext, provider: Model["provider"], model: Model["model"]): string { + const config = AuthTokensConfigSchema.safeParse(context.matchedConfig.findConfig("AUTH_TOKENS")); + + if (!config.success) { + throw new RuntimeErrorException("Invalid Auth config") + } + + const override = config.data[provider].overrides[model]; + if (override) { + return override + } + + return config.data[provider].defaultToken +} \ No newline at end of file diff --git a/actions/ai-action/src/index.ts b/actions/ai-action/src/index.ts new file mode 100644 index 0000000..da4584d --- /dev/null +++ b/actions/ai-action/src/index.ts @@ -0,0 +1,42 @@ +import {createSdk} from "@code0-tech/hercules" +import { + loadAllDefinitions +} from "./helpers"; + +export const sdk = createSdk({ + authToken: process.env.HERCULES_AUTH_TOKEN || "", + aquilaUrl: process.env.HERCULES_AQUILA_URL || "127.0.0.1:50051", + actionId: process.env.HERCULES_ACTION_ID || "ai-action", + version: process.env.HERCULES_SDK_VERSION || "0.0.0", +}) + +async function main() { + try { + await loadAllDefinitions(sdk) + connectToSdk() + } catch (error) { + console.error(error) + } +} + +main().catch(err => { + console.error(err) + process.exit(1) +}) + + +function connectToSdk() { + sdk.connect().then(() => { + console.log("SDK connected successfully"); + }).catch(() => { + console.error("Error connecting SDK:"); + }) + + sdk.onError((error) => { + console.error("SDK Error occurred:", error.message); + console.log("Attempting to reconnect in 5s..."); + setTimeout(() => { + connectToSdk(); + }, 5000) + }) +} \ No newline at end of file diff --git a/actions/ai-action/src/types/aiModel.ts b/actions/ai-action/src/types/aiModel.ts new file mode 100644 index 0000000..005c8ce --- /dev/null +++ b/actions/ai-action/src/types/aiModel.ts @@ -0,0 +1,41 @@ +import {z} from "zod"; +import {ActionSdk} from "@code0-tech/hercules"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; + +export const MODEL_REGISTRY = { + openai: ['gpt-5.1'], + google: ['gemini-2.5-flash'], + anthropic: ['claude-haiku-4-5', 'claude-sonnet-4-6', 'claude-opus-4-6'], + ollama: ['selfhosted'] +} as const + + +type Provider = keyof typeof MODEL_REGISTRY +export const ProviderEnum = z.enum(Object.keys(MODEL_REGISTRY) as [Provider, ...Provider[]]) + +export const ModelSchema = z.object({ + provider: ProviderEnum.describe(` + @description The provider, either pass in the raw provider you want to use, or use the appropriate functions to create this object + `), + model: z.string().describe(` + @description The model of the provider, either pass in the raw model you want to use, or use the appropriate functions to create this object + `), + settings: z.looseObject({}).optional(), + seed: z.number().optional(), + maxOutputTokens: z.number().optional(), + temperature: z.number().min(0).max(1).optional(), + maxRetries: z.number().optional(), + stopSequences: z.array(z.string()).optional(), + presencePenalty: z.number().min(-1).max(1).optional(), + frequencyPenalty: z.number().min(-1).max(1).optional() +}) + + +export type Model = z.infer + +export default (sdk: ActionSdk) => { + return sdk.registerDataTypes({ + type: singleZodSchemaToTypescriptDef("AI_MODEL", ModelSchema), + identifier: "AI_MODEL" + }) +} \ No newline at end of file diff --git a/actions/ai-action/tsconfig.json b/actions/ai-action/tsconfig.json new file mode 100644 index 0000000..d3ec800 --- /dev/null +++ b/actions/ai-action/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": ["src", "scripts"] +} \ No newline at end of file diff --git a/actions/ai-action/vite.config.ts b/actions/ai-action/vite.config.ts new file mode 100644 index 0000000..7ab94be --- /dev/null +++ b/actions/ai-action/vite.config.ts @@ -0,0 +1,31 @@ +import {defineConfig} from 'vite'; +import {resolve} from 'path'; + +export default defineConfig({ + build: { + target: 'node18', + ssr: true, + outDir: 'dist', + emptyOutDir: true, + rollupOptions: { + input: { + main: resolve(__dirname, 'src/index.ts'), + generateDocs: resolve(__dirname, 'scripts/generateDocs.ts') + }, + external: [ + 'fs', + 'path', + 'os', + 'crypto', + 'stream', + 'util', + 'events', + 'buffer', + 'url', + 'zlib', + 'node:fs', + 'node:path' + ] + } + } +}); \ No newline at end of file diff --git a/actions/ai-action/vitest.config.ts b/actions/ai-action/vitest.config.ts new file mode 100644 index 0000000..918a608 --- /dev/null +++ b/actions/ai-action/vitest.config.ts @@ -0,0 +1,8 @@ +import baseConfig from "../../vitest.config"; +import { defineConfig, mergeConfig } from "vitest/config"; + +export default mergeConfig(baseConfig, defineConfig({ + test: { + include: ["**/*.{test,spec}.{ts,tsx}"] + } +})); \ No newline at end of file diff --git a/actions/gls-action/scripts/generateDocs.ts b/actions/gls-action/scripts/generateDocs.ts index 27f8ffb..d8886ef 100644 --- a/actions/gls-action/scripts/generateDocs.ts +++ b/actions/gls-action/scripts/generateDocs.ts @@ -1,6 +1,11 @@ -import {runStandardActionDocs, StandardActionDocsConfig} from "../../../src/standardActionDocs" +import { + loadFunctions, + runStandardActionDocs, + StandardActionDocsConfig +} from "../../../src/standardActionDocs" import {loadAllDefinitions} from "../src/helpers"; + export function createGlsDocsConfig(): StandardActionDocsConfig { return { actionName: "GLS", @@ -29,7 +34,8 @@ export function createGlsDocsConfig(): StandardActionDocsConfig { functionGroups: [ { heading: "Builder functions", - modules: import.meta.glob("../src/functions/utils/*.ts"), + loadFunctions: (sdk) => + loadFunctions(sdk, import.meta.glob("../src/functions/utils/*.ts")), }, { heading: "Shipment functions", @@ -45,11 +51,14 @@ export function createGlsDocsConfig(): StandardActionDocsConfig { | \`customContent\` | GLS_CUSTOM_CONTENT | No | Custom logo and barcode settings | ---`, - modules: import.meta.glob("../src/functions/services/*.ts"), + + loadFunctions: (sdk) => + loadFunctions(sdk, import.meta.glob("../src/functions/services/*.ts")), }, { heading: "API functions", - modules: import.meta.glob("../src/functions/*.ts"), + loadFunctions: (sdk) => + loadFunctions(sdk, import.meta.glob("../src/functions/*.ts")), }, ], } diff --git a/actions/gls-action/src/functions/cancelShipment.ts b/actions/gls-action/src/functions/cancelShipment.ts index a032f4a..26d9b1a 100644 --- a/actions/gls-action/src/functions/cancelShipment.ts +++ b/actions/gls-action/src/functions/cancelShipment.ts @@ -3,7 +3,7 @@ import {cancelShipment} from "../helpers"; import {CancelShipmentRequestData, CancelShipmentResponseData} from "../types/glsCancelShipment"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "cancelShipment", diff --git a/actions/gls-action/src/functions/getAllowedServices.ts b/actions/gls-action/src/functions/getAllowedServices.ts index 545242a..5a2ab7c 100644 --- a/actions/gls-action/src/functions/getAllowedServices.ts +++ b/actions/gls-action/src/functions/getAllowedServices.ts @@ -8,7 +8,7 @@ import { } from "../types/glsAllowedServices"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "getAllowedServices", diff --git a/actions/gls-action/src/functions/getEndOfDayReport.ts b/actions/gls-action/src/functions/getEndOfDayReport.ts index 9fe77b9..5a19fcb 100644 --- a/actions/gls-action/src/functions/getEndOfDayReport.ts +++ b/actions/gls-action/src/functions/getEndOfDayReport.ts @@ -4,7 +4,7 @@ import axios from "axios"; import {EndOfDayRequestData, EndOfDayResponseData, EndOfDayResponseDataSchema} from "../types/glsEndOfDayRequest"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "getEndOfDayReport", diff --git a/actions/gls-action/src/functions/reprintParcel.ts b/actions/gls-action/src/functions/reprintParcel.ts index ea9fc86..d42c596 100644 --- a/actions/gls-action/src/functions/reprintParcel.ts +++ b/actions/gls-action/src/functions/reprintParcel.ts @@ -8,7 +8,7 @@ import { } from "../types/glsReprintParcel"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "reprintParcel", diff --git a/actions/gls-action/src/functions/services/createAddresseeOnlyShipment.ts b/actions/gls-action/src/functions/services/createAddresseeOnlyShipment.ts index 6b9f5cb..3a6fdbc 100644 --- a/actions/gls-action/src/functions/services/createAddresseeOnlyShipment.ts +++ b/actions/gls-action/src/functions/services/createAddresseeOnlyShipment.ts @@ -11,7 +11,7 @@ import {CustomContent} from "../../types/glsCustomContent"; import {ReturnOptions} from "../../types/glsReturnOptions"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createAddresseeOnlyShipment", diff --git a/actions/gls-action/src/functions/services/createDeliveryAtWorkShipment.ts b/actions/gls-action/src/functions/services/createDeliveryAtWorkShipment.ts index 75be85b..d834d53 100644 --- a/actions/gls-action/src/functions/services/createDeliveryAtWorkShipment.ts +++ b/actions/gls-action/src/functions/services/createDeliveryAtWorkShipment.ts @@ -11,7 +11,7 @@ import {ReturnOptions} from "../../types/glsReturnOptions"; import {CreateParcelsResponse} from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createDeliveryAtWorkShipment", diff --git a/actions/gls-action/src/functions/services/createDeliveryNextWorkingDayShipment.ts b/actions/gls-action/src/functions/services/createDeliveryNextWorkingDayShipment.ts index 845ddaa..e2abc19 100644 --- a/actions/gls-action/src/functions/services/createDeliveryNextWorkingDayShipment.ts +++ b/actions/gls-action/src/functions/services/createDeliveryNextWorkingDayShipment.ts @@ -11,7 +11,7 @@ import {ReturnOptions} from "../../types/glsReturnOptions"; import {CreateParcelsResponse} from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createDeliveryNextWorkingDayShipment", diff --git a/actions/gls-action/src/functions/services/createDeliverySaturdayShipment.ts b/actions/gls-action/src/functions/services/createDeliverySaturdayShipment.ts index ba00235..e0b7398 100644 --- a/actions/gls-action/src/functions/services/createDeliverySaturdayShipment.ts +++ b/actions/gls-action/src/functions/services/createDeliverySaturdayShipment.ts @@ -12,7 +12,7 @@ import {CreateParcelsResponse} from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createDeliverySaturdayShipment", diff --git a/actions/gls-action/src/functions/services/createDepositShipment.ts b/actions/gls-action/src/functions/services/createDepositShipment.ts index 2307cbf..2054132 100644 --- a/actions/gls-action/src/functions/services/createDepositShipment.ts +++ b/actions/gls-action/src/functions/services/createDepositShipment.ts @@ -12,7 +12,7 @@ import {ReturnOptions} from "../../types/glsReturnOptions"; import {CreateParcelsResponse} from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createDepositShipment", diff --git a/actions/gls-action/src/functions/services/createExchangeShipment.ts b/actions/gls-action/src/functions/services/createExchangeShipment.ts index e9060e5..729028a 100644 --- a/actions/gls-action/src/functions/services/createExchangeShipment.ts +++ b/actions/gls-action/src/functions/services/createExchangeShipment.ts @@ -12,7 +12,7 @@ import {ReturnOptions} from "../../types/glsReturnOptions"; import {CreateParcelsResponse} from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createExchangeShipment", diff --git a/actions/gls-action/src/functions/services/createFlexDeliveryShipment.ts b/actions/gls-action/src/functions/services/createFlexDeliveryShipment.ts index 9be4468..50d6a24 100644 --- a/actions/gls-action/src/functions/services/createFlexDeliveryShipment.ts +++ b/actions/gls-action/src/functions/services/createFlexDeliveryShipment.ts @@ -11,7 +11,7 @@ import {CustomContent} from "../../types/glsCustomContent"; import {PrintingOptions} from "../../types/glsPrintingOptions"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createFlexDeliveryShipment", diff --git a/actions/gls-action/src/functions/services/createGuaranteed24Shipment.ts b/actions/gls-action/src/functions/services/createGuaranteed24Shipment.ts index f4ce626..980e070 100644 --- a/actions/gls-action/src/functions/services/createGuaranteed24Shipment.ts +++ b/actions/gls-action/src/functions/services/createGuaranteed24Shipment.ts @@ -11,7 +11,7 @@ import {ReturnOptions} from "../../types/glsReturnOptions"; import {CreateParcelsResponse} from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createGuaranteed24Shipment", diff --git a/actions/gls-action/src/functions/services/createIdentPinShipment.ts b/actions/gls-action/src/functions/services/createIdentPinShipment.ts index 881fe57..aea5583 100644 --- a/actions/gls-action/src/functions/services/createIdentPinShipment.ts +++ b/actions/gls-action/src/functions/services/createIdentPinShipment.ts @@ -12,7 +12,7 @@ import {CreateParcelsResponse} from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createIdentPinShipment", diff --git a/actions/gls-action/src/functions/services/createIdentShipment.ts b/actions/gls-action/src/functions/services/createIdentShipment.ts index f1b99c1..a7fb416 100644 --- a/actions/gls-action/src/functions/services/createIdentShipment.ts +++ b/actions/gls-action/src/functions/services/createIdentShipment.ts @@ -12,7 +12,7 @@ import {CreateParcelsResponse} from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createIdentShipment", diff --git a/actions/gls-action/src/functions/services/createPickAndShipShipment.ts b/actions/gls-action/src/functions/services/createPickAndShipShipment.ts index 0836c80..84dd64b 100644 --- a/actions/gls-action/src/functions/services/createPickAndShipShipment.ts +++ b/actions/gls-action/src/functions/services/createPickAndShipShipment.ts @@ -11,7 +11,7 @@ import {ReturnOptions} from "../../types/glsReturnOptions"; import {CreateParcelsResponse} from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createPickAndShipShipment", diff --git a/actions/gls-action/src/functions/services/createShopDeliveryShipment.ts b/actions/gls-action/src/functions/services/createShopDeliveryShipment.ts index 5e241e6..5b82a63 100644 --- a/actions/gls-action/src/functions/services/createShopDeliveryShipment.ts +++ b/actions/gls-action/src/functions/services/createShopDeliveryShipment.ts @@ -10,7 +10,7 @@ import {ReturnOptions} from "../../types/glsReturnOptions"; import { CreateParcelsResponse } from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createShopDeliveryShipment", diff --git a/actions/gls-action/src/functions/services/createShopReturnShipment.ts b/actions/gls-action/src/functions/services/createShopReturnShipment.ts index dd86205..49c7283 100644 --- a/actions/gls-action/src/functions/services/createShopReturnShipment.ts +++ b/actions/gls-action/src/functions/services/createShopReturnShipment.ts @@ -11,7 +11,7 @@ import {ReturnOptions} from "../../types/glsReturnOptions"; import {CreateParcelsResponse} from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createShopReturnShipment", diff --git a/actions/gls-action/src/functions/services/createSignatureShipment.ts b/actions/gls-action/src/functions/services/createSignatureShipment.ts index 396bb9a..e3bab1a 100644 --- a/actions/gls-action/src/functions/services/createSignatureShipment.ts +++ b/actions/gls-action/src/functions/services/createSignatureShipment.ts @@ -11,7 +11,7 @@ import {ReturnOptions} from "../../types/glsReturnOptions"; import {CreateParcelsResponse} from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - sdk.registerFunctionDefinitions( + sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createSignatureShipment", diff --git a/actions/gls-action/src/functions/services/createTyreShipment.ts b/actions/gls-action/src/functions/services/createTyreShipment.ts index faf6837..a02d028 100644 --- a/actions/gls-action/src/functions/services/createTyreShipment.ts +++ b/actions/gls-action/src/functions/services/createTyreShipment.ts @@ -11,7 +11,7 @@ import {ReturnOptions} from "../../types/glsReturnOptions"; import {CreateParcelsResponse} from "../../types/glsCreateParcelsResponse"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createTyreShipment", diff --git a/actions/gls-action/src/functions/updateParcelWeight.ts b/actions/gls-action/src/functions/updateParcelWeight.ts index f1cb59b..6f7d829 100644 --- a/actions/gls-action/src/functions/updateParcelWeight.ts +++ b/actions/gls-action/src/functions/updateParcelWeight.ts @@ -8,7 +8,7 @@ import { } from "../types/glsUpdateParcelWeight"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "updateParcelWeight", diff --git a/actions/gls-action/src/functions/utils/createAddress.ts b/actions/gls-action/src/functions/utils/createAddress.ts index 10d3f7d..a6fd439 100644 --- a/actions/gls-action/src/functions/utils/createAddress.ts +++ b/actions/gls-action/src/functions/utils/createAddress.ts @@ -2,7 +2,7 @@ import {ActionSdk} from "@code0-tech/hercules"; import {AddressSchema} from "../../types/glsAddress"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createAddress", diff --git a/actions/gls-action/src/functions/utils/createConsignee.ts b/actions/gls-action/src/functions/utils/createConsignee.ts index 6f5f166..17e95e3 100644 --- a/actions/gls-action/src/functions/utils/createConsignee.ts +++ b/actions/gls-action/src/functions/utils/createConsignee.ts @@ -3,7 +3,7 @@ import {AddressSchema} from "../../types/glsAddress"; import {ConsigneeSchema} from "../../types/glsConsignee"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createConsignee", diff --git a/actions/gls-action/src/functions/utils/createCustomContent.ts b/actions/gls-action/src/functions/utils/createCustomContent.ts index 23d597b..5eb75ef 100644 --- a/actions/gls-action/src/functions/utils/createCustomContent.ts +++ b/actions/gls-action/src/functions/utils/createCustomContent.ts @@ -2,7 +2,7 @@ import {ActionSdk} from "@code0-tech/hercules"; import {CustomContent} from "../../types/glsCustomContent"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createCustomContent", diff --git a/actions/gls-action/src/functions/utils/createPrintingOptions.ts b/actions/gls-action/src/functions/utils/createPrintingOptions.ts index d4a1170..e788a2c 100644 --- a/actions/gls-action/src/functions/utils/createPrintingOptions.ts +++ b/actions/gls-action/src/functions/utils/createPrintingOptions.ts @@ -2,7 +2,7 @@ import {ActionSdk} from "@code0-tech/hercules"; import {PrintingOptions, ReturnLabels} from "../../types/glsPrintingOptions"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createPrintingOptions", diff --git a/actions/gls-action/src/functions/utils/createShipmentUnit.ts b/actions/gls-action/src/functions/utils/createShipmentUnit.ts index 75c0368..09fbab0 100644 --- a/actions/gls-action/src/functions/utils/createShipmentUnit.ts +++ b/actions/gls-action/src/functions/utils/createShipmentUnit.ts @@ -3,7 +3,7 @@ import { UnitService } from "../../types/glsUnitService"; import {ShipmentUnit} from "../../types/glsShipmentUnit"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "createShipmentUnit", diff --git a/actions/gls-action/src/functions/validateShipment.ts b/actions/gls-action/src/functions/validateShipment.ts index 153d48c..c96d200 100644 --- a/actions/gls-action/src/functions/validateShipment.ts +++ b/actions/gls-action/src/functions/validateShipment.ts @@ -8,7 +8,7 @@ import { } from "../types/glsValidateShipment"; export default (sdk: ActionSdk) => { - return sdk.registerFunctionDefinitions( + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { definition: { runtimeName: "validateShipment", diff --git a/actions/gls-action/src/helpers.ts b/actions/gls-action/src/helpers.ts index b5a3101..772e59a 100644 --- a/actions/gls-action/src/helpers.ts +++ b/actions/gls-action/src/helpers.ts @@ -108,44 +108,7 @@ export const DEFAULT_DATA_TYPES_FOR_SERVICES = [ "GLS_CREATE_PARCELS_RESPONSE" ] -export function singleZodSchemaToTypescriptDef( - typeName: string, - zodSchema: ZodObject -) { - return zodSchemaToTypescriptDefs(typeName, zodSchema).get(typeName)!; -} - -export function zodSchemaToTypescriptDefs( - typeName: string, - zodSchema: ZodObject, - extraSchemas: Record = {} -): Map { - const store = createAuxiliaryTypeStore(); - const result = new Map(); - - for (const [name, schema] of Object.entries(extraSchemas)) { - const {node} = zodToTs(schema, {auxiliaryTypeStore: store}); - - const alias = ts.factory.createTypeAliasDeclaration( - undefined, - ts.factory.createIdentifier(name), - undefined, - node - ); - - store.definitions.set(schema, { - identifier: ts.factory.createIdentifier(name), - node: alias - }); - result.set(name, printNode(alias).replace(`type ${name} =`, ``)); - } - - const {node} = zodToTs(zodSchema, {auxiliaryTypeStore: store}); - result.set(typeName, printNode(node)); - - return result; -} let cachedToken = { token: "", diff --git a/actions/gls-action/src/types/glsAddress.ts b/actions/gls-action/src/types/glsAddress.ts index 05f5a86..a71eb8e 100644 --- a/actions/gls-action/src/types/glsAddress.ts +++ b/actions/gls-action/src/types/glsAddress.ts @@ -1,6 +1,6 @@ import {ActionSdk} from "@code0-tech/hercules"; import z from "zod" -import {singleZodSchemaToTypescriptDef} from "../helpers"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; export const AddressSchema = z.object({ Name1: z.string().max(40).describe(` diff --git a/actions/gls-action/src/types/glsAllowedServices.ts b/actions/gls-action/src/types/glsAllowedServices.ts index 8d4bd31..c2ca23f 100644 --- a/actions/gls-action/src/types/glsAllowedServices.ts +++ b/actions/gls-action/src/types/glsAllowedServices.ts @@ -1,5 +1,5 @@ import {ActionSdk} from "@code0-tech/hercules"; -import {singleZodSchemaToTypescriptDef} from "../helpers"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; import z from "zod"; export const AllowedServicesRequestDataSchema = z.object({ diff --git a/actions/gls-action/src/types/glsCancelShipment.ts b/actions/gls-action/src/types/glsCancelShipment.ts index e2be4ca..95c1190 100644 --- a/actions/gls-action/src/types/glsCancelShipment.ts +++ b/actions/gls-action/src/types/glsCancelShipment.ts @@ -1,5 +1,5 @@ import {ActionSdk} from "@code0-tech/hercules"; -import {singleZodSchemaToTypescriptDef} from "../helpers"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; import z from "zod"; export const CancelShipmentRequestDataSchema = z.object({ diff --git a/actions/gls-action/src/types/glsConsignee.ts b/actions/gls-action/src/types/glsConsignee.ts index b125b15..994c99c 100644 --- a/actions/gls-action/src/types/glsConsignee.ts +++ b/actions/gls-action/src/types/glsConsignee.ts @@ -1,5 +1,5 @@ import {ActionSdk} from "@code0-tech/hercules"; -import {zodSchemaToTypescriptDefs} from "../helpers"; +import {zodSchemaToTypescriptDefs} from "../../../../src/helpers"; import {AddressSchema} from "./glsAddress"; import {z} from "zod"; diff --git a/actions/gls-action/src/types/glsCreateParcelsResponse.ts b/actions/gls-action/src/types/glsCreateParcelsResponse.ts index 6d510bc..a2a7d98 100644 --- a/actions/gls-action/src/types/glsCreateParcelsResponse.ts +++ b/actions/gls-action/src/types/glsCreateParcelsResponse.ts @@ -1,5 +1,5 @@ import {ActionSdk} from "@code0-tech/hercules"; -import {singleZodSchemaToTypescriptDef} from "../helpers"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; import {z} from "zod"; export const CreateParcelsResponseSchema = z.object({ diff --git a/actions/gls-action/src/types/glsCustomContent.ts b/actions/gls-action/src/types/glsCustomContent.ts index df751ab..61a459b 100644 --- a/actions/gls-action/src/types/glsCustomContent.ts +++ b/actions/gls-action/src/types/glsCustomContent.ts @@ -1,5 +1,5 @@ import {ActionSdk} from "@code0-tech/hercules"; -import {singleZodSchemaToTypescriptDef} from "../helpers"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; import {z} from "zod"; export const CustomContentSchema = z.object({ diff --git a/actions/gls-action/src/types/glsEndOfDayRequest.ts b/actions/gls-action/src/types/glsEndOfDayRequest.ts index 81b62bb..9d0a2c3 100644 --- a/actions/gls-action/src/types/glsEndOfDayRequest.ts +++ b/actions/gls-action/src/types/glsEndOfDayRequest.ts @@ -1,5 +1,5 @@ import {ActionSdk} from "@code0-tech/hercules"; -import {singleZodSchemaToTypescriptDef, zodSchemaToTypescriptDefs} from "../helpers"; +import {singleZodSchemaToTypescriptDef, zodSchemaToTypescriptDefs} from "../../../../src/helpers"; import z from "zod"; import {AddressSchema} from "./glsAddress"; diff --git a/actions/gls-action/src/types/glsPrintingOptions.ts b/actions/gls-action/src/types/glsPrintingOptions.ts index 9d59be3..b2c643d 100644 --- a/actions/gls-action/src/types/glsPrintingOptions.ts +++ b/actions/gls-action/src/types/glsPrintingOptions.ts @@ -1,5 +1,5 @@ import {ActionSdk} from "@code0-tech/hercules"; -import {singleZodSchemaToTypescriptDef, zodSchemaToTypescriptDefs} from "../helpers"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; import {z} from "zod"; export const ReturnLabelsSchema = z.object({ diff --git a/actions/gls-action/src/types/glsReprintParcel.ts b/actions/gls-action/src/types/glsReprintParcel.ts index 34d639d..e2ab096 100644 --- a/actions/gls-action/src/types/glsReprintParcel.ts +++ b/actions/gls-action/src/types/glsReprintParcel.ts @@ -1,5 +1,5 @@ import {ActionSdk} from "@code0-tech/hercules"; -import {singleZodSchemaToTypescriptDef} from "../helpers"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; import z from "zod"; export const ReprintParcelRequestDataSchema = z.object({ diff --git a/actions/gls-action/src/types/glsReturnOptions.ts b/actions/gls-action/src/types/glsReturnOptions.ts index b94efc5..82a2b05 100644 --- a/actions/gls-action/src/types/glsReturnOptions.ts +++ b/actions/gls-action/src/types/glsReturnOptions.ts @@ -1,4 +1,4 @@ -import {singleZodSchemaToTypescriptDef} from "../helpers"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; import {z} from "zod"; import {ActionSdk} from "@code0-tech/hercules"; diff --git a/actions/gls-action/src/types/glsShipment.ts b/actions/gls-action/src/types/glsShipment.ts index e245db9..c1558ae 100644 --- a/actions/gls-action/src/types/glsShipment.ts +++ b/actions/gls-action/src/types/glsShipment.ts @@ -1,4 +1,4 @@ -import {zodSchemaToTypescriptDefs} from "../helpers"; +import {zodSchemaToTypescriptDefs} from "../../../../src/helpers"; import {z} from "zod"; import {ConsigneeSchema} from "./glsConsignee"; import {AddressSchema} from "./glsAddress"; diff --git a/actions/gls-action/src/types/glsShipmentUnit.ts b/actions/gls-action/src/types/glsShipmentUnit.ts index baceb6b..21e9cc5 100644 --- a/actions/gls-action/src/types/glsShipmentUnit.ts +++ b/actions/gls-action/src/types/glsShipmentUnit.ts @@ -1,5 +1,5 @@ import {z} from "zod"; -import {zodSchemaToTypescriptDefs} from "../helpers"; +import {zodSchemaToTypescriptDefs} from "../../../../src/helpers"; import {ShipmentSchema} from "./glsShipment"; import {InternalUnitServiceSchema, UnitServiceSchema} from "./glsUnitService"; import {ActionSdk} from "@code0-tech/hercules"; diff --git a/actions/gls-action/src/types/glsShipper.ts b/actions/gls-action/src/types/glsShipper.ts index 2887d09..2435eb2 100644 --- a/actions/gls-action/src/types/glsShipper.ts +++ b/actions/gls-action/src/types/glsShipper.ts @@ -1,6 +1,6 @@ import {z} from "zod"; import {AddressSchema} from "./glsAddress"; -import {zodSchemaToTypescriptDefs} from "../helpers"; +import {zodSchemaToTypescriptDefs} from "../../../../src/helpers"; import {ActionSdk} from "@code0-tech/hercules"; export const ShipperSchema = z.object({ diff --git a/actions/gls-action/src/types/glsUnitService.ts b/actions/gls-action/src/types/glsUnitService.ts index 050fe26..dd3adc7 100644 --- a/actions/gls-action/src/types/glsUnitService.ts +++ b/actions/gls-action/src/types/glsUnitService.ts @@ -1,5 +1,5 @@ import z from "zod" -import {zodSchemaToTypescriptDefs} from "../helpers"; +import {zodSchemaToTypescriptDefs} from "../../../../src/helpers"; import {ShipmentSchema} from "./glsShipment"; import {ActionSdk} from "@code0-tech/hercules"; diff --git a/actions/gls-action/src/types/glsUpdateParcelWeight.ts b/actions/gls-action/src/types/glsUpdateParcelWeight.ts index 5a907c3..5b914cc 100644 --- a/actions/gls-action/src/types/glsUpdateParcelWeight.ts +++ b/actions/gls-action/src/types/glsUpdateParcelWeight.ts @@ -1,5 +1,5 @@ import z from "zod"; -import {singleZodSchemaToTypescriptDef} from "../helpers"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; import {ActionSdk} from "@code0-tech/hercules"; export const UpdateParcelWeightRequestDataSchema = z.object({ diff --git a/actions/gls-action/src/types/glsValidateShipment.ts b/actions/gls-action/src/types/glsValidateShipment.ts index e22874f..c199920 100644 --- a/actions/gls-action/src/types/glsValidateShipment.ts +++ b/actions/gls-action/src/types/glsValidateShipment.ts @@ -1,7 +1,7 @@ import {ActionSdk} from "@code0-tech/hercules"; import z from "zod"; import {InternalShipmentSchma, ShipmentSchema} from "./glsShipment"; -import {singleZodSchemaToTypescriptDef, zodSchemaToTypescriptDefs} from "../helpers"; +import {singleZodSchemaToTypescriptDef, zodSchemaToTypescriptDefs} from "../../../../src/helpers"; export const ValidateShipmentRequestDataSchema = z.object({ diff --git a/actions/gls-action/test/functions/reprintParcel.test.ts b/actions/gls-action/test/functions/reprintParcel.test.ts index 3f408a2..e6115e0 100644 --- a/actions/gls-action/test/functions/reprintParcel.test.ts +++ b/actions/gls-action/test/functions/reprintParcel.test.ts @@ -82,7 +82,7 @@ describe("reprintParcel.ts", () => { await withBaseFunctionMock(register.default, async (state) => { expect(state.registeredFunctionDefinitions).toHaveLength(1); - const [reprintParcel] = state.registeredFunctionDefinitions; + const [reprintParcel] = state.registeredRuntimeFunctionDefinitions; expect(reprintParcel.definition.runtimeName).toBe("reprintParcel"); diff --git a/actions/gls-action/test/helpers/withSdkMock.ts b/actions/gls-action/test/helpers/withSdkMock.ts index 6648559..306b3af 100644 --- a/actions/gls-action/test/helpers/withSdkMock.ts +++ b/actions/gls-action/test/helpers/withSdkMock.ts @@ -3,15 +3,16 @@ import { ActionSdk, HerculesActionConfigurationDefinition, HerculesDataType, - HerculesFlowType, - HerculesRegisterFunctionParameter + HerculesFlowType, HerculesRegisterFunctionDefinition, + HerculesRegisterRuntimeFunctionParameter } from "@code0-tech/hercules"; import {SdkMockState} from "../index.test"; export const withSdkMock = async (tests: (state: SdkMockState) => void) => { const state = vi.hoisted(() => { const state: SdkMockState = { - registeredFunctionDefinitions: [] as HerculesRegisterFunctionParameter[], + registeredFunctionDefinitions: [] as HerculesRegisterFunctionDefinition[], + registeredRuntimeFunctionDefinitions: [] as HerculesRegisterRuntimeFunctionParameter[], dataTypes: [] as HerculesDataType[], flowTypes: [] as HerculesFlowType[], configDefinitions: [] as HerculesActionConfigurationDefinition[], @@ -28,9 +29,36 @@ export const withSdkMock = async (tests: (state: SdkMockState) => void) => { state.configDefinitions = configDefinitions || null const mockedActionSdk: ActionSdk = { + registerFunctionDefinitions(...functionDefinitions: HerculesRegisterFunctionDefinition[]): Promise { + functionDefinitions.forEach(value => { + state.registeredFunctionDefinitions.push(value) + }) + return Promise.resolve(undefined); + }, + registerRuntimeFunctionDefinitionsAndFunctionDefinitions(...runtimeFunctionDefinitions: HerculesRegisterRuntimeFunctionParameter[]): Promise { + runtimeFunctionDefinitions.forEach(value => { + state.registeredRuntimeFunctionDefinitions.push(value) + }) + + runtimeFunctionDefinitions.forEach(value => { + state.registeredFunctionDefinitions.push({ + ...value.definition, + runtimeDefinitionName: value.definition.runtimeName, + parameters: value.definition.parameters.map(param =>{ + return { + ...param, + runtimeDefinitionName: param.runtimeName + } + }) + }) + }) + return Promise.resolve(undefined); + }, config: config, - registerFunctionDefinitions: (...defs: HerculesRegisterFunctionParameter[]) => { - state.registeredFunctionDefinitions = defs; + registerRuntimeFunctionDefinitions: (...defs: HerculesRegisterRuntimeFunctionParameter[]) => { + defs.forEach(value => { + state.registeredRuntimeFunctionDefinitions.push(value) + }) return Promise.resolve(); }, diff --git a/actions/gls-action/test/index.test.ts b/actions/gls-action/test/index.test.ts index f11dcc9..94b67b0 100644 --- a/actions/gls-action/test/index.test.ts +++ b/actions/gls-action/test/index.test.ts @@ -2,13 +2,14 @@ import {describe, expect, it, vi} from "vitest"; import { HerculesActionConfigurationDefinition, HerculesDataType, - HerculesFlowType, - HerculesRegisterFunctionParameter + HerculesFlowType, HerculesRegisterFunctionDefinition, + HerculesRegisterRuntimeFunctionParameter } from "@code0-tech/hercules"; import {withSdkMock} from "./helpers/withSdkMock"; export type SdkMockState = { - registeredFunctionDefinitions: HerculesRegisterFunctionParameter[] | null; + registeredFunctionDefinitions: HerculesRegisterFunctionDefinition[] | null; + registeredRuntimeFunctionDefinitions: HerculesRegisterRuntimeFunctionParameter[] | null; dataTypes: HerculesDataType[] | null; flowTypes: HerculesFlowType[] | null; configDefinitions: HerculesActionConfigurationDefinition[] | null; @@ -92,7 +93,7 @@ describe("withSdkMock", () => { expect(value.documentation || [], `${value.identifier}: Documentation should be set`).not.toHaveLength(0) }) - state.registeredFunctionDefinitions?.forEach(value => { + state.registeredRuntimeFunctionDefinitions?.forEach(value => { expect(value.definition.name || [], `${value.definition.runtimeName}: Name should be set`).not.toHaveLength(0) expect(value.definition.description || [], `${value.definition.runtimeName}: Description should be set`).not.toHaveLength(0) expect(value.definition.documentation || [], `${value.definition.runtimeName}: Documentation should be set`).not.toHaveLength(0) diff --git a/code0-tech-hercules-0.0.0.tgz b/code0-tech-hercules-0.0.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..158ff589c58afb0dbd6d65d950f4696383eeee7f GIT binary patch literal 5323 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 + +--- + +## Google Models + + +### `google/gemini-2.5-flash` (`createModel`) + +| Parameter | Name | Type | Required | Description | +| --- | --- | --- | --- | --- | +| settings | Settings | [AI_GOOGLE_SETTINGS](./types.mdx#ai_google_settings) | Yes | The settings for this provider, for more information see the type | +| maxOutputTokens | Max Output Tokens | number | No | Maximum number of tokens to generate | +| temperature | Temperature | number | No | temperature is a parameter that controls the randomness of the model’s outputs during text generation. Normally between 0 and 1 | +| maxRetries | Maximum Retries | number | No | Maximum number of retries. Set to 0 to disable retries. Default value is 2 | +| stopSequences | Stop sequences | string[] | No | Stop sequences are specific strings (words, characters, or patterns) that tell an AI model when to stop generating text. | +| presencePenalty | Presence Penalty | number | No | Presence penalty pushes the model to talk about new things instead of repeating existing ones. Typical range of 0-2 | +| frequencyPenalty | Frequency Penalty | number | No | Frequency penalty is a parameter that reduces the likelihood of the model repeating the same words or phrases multiple times. Typical range of 0-2 | +| seed | Seed | number | No | Seed is a parameter used to make AI model outputs reproducible. | + +Return Type: [AI_MODEL](./types.mdx#ai_model) + +# + +Auto generated wrapper function to create this model + + + +--- + +## Anthropic Models + + +### `anthropic/claude-opus-4-6` (`createModel`) + +| Parameter | Name | Type | Required | Description | +| --- | --- | --- | --- | --- | +| settings | Settings | [AI_ANTHROPIC_SETTINGS](./types.mdx#ai_anthropic_settings) | Yes | The settings for this provider, for more information see the type | +| maxOutputTokens | Max Output Tokens | number | No | Maximum number of tokens to generate | +| temperature | Temperature | number | No | temperature is a parameter that controls the randomness of the model’s outputs during text generation. Normally between 0 and 1 | +| maxRetries | Maximum Retries | number | No | Maximum number of retries. Set to 0 to disable retries. Default value is 2 | +| stopSequences | Stop sequences | string[] | No | Stop sequences are specific strings (words, characters, or patterns) that tell an AI model when to stop generating text. | +| presencePenalty | Presence Penalty | number | No | Presence penalty pushes the model to talk about new things instead of repeating existing ones. Typical range of 0-2 | +| frequencyPenalty | Frequency Penalty | number | No | Frequency penalty is a parameter that reduces the likelihood of the model repeating the same words or phrases multiple times. Typical range of 0-2 | +| seed | Seed | number | No | Seed is a parameter used to make AI model outputs reproducible. | + +Return Type: [AI_MODEL](./types.mdx#ai_model) + +# + +Auto generated wrapper function to create this model + + + +--- + +### `anthropic/claude-sonnet-4-6` (`createModel`) + +| Parameter | Name | Type | Required | Description | +| --- | --- | --- | --- | --- | +| settings | Settings | [AI_ANTHROPIC_SETTINGS](./types.mdx#ai_anthropic_settings) | Yes | The settings for this provider, for more information see the type | +| maxOutputTokens | Max Output Tokens | number | No | Maximum number of tokens to generate | +| temperature | Temperature | number | No | temperature is a parameter that controls the randomness of the model’s outputs during text generation. Normally between 0 and 1 | +| maxRetries | Maximum Retries | number | No | Maximum number of retries. Set to 0 to disable retries. Default value is 2 | +| stopSequences | Stop sequences | string[] | No | Stop sequences are specific strings (words, characters, or patterns) that tell an AI model when to stop generating text. | +| presencePenalty | Presence Penalty | number | No | Presence penalty pushes the model to talk about new things instead of repeating existing ones. Typical range of 0-2 | +| frequencyPenalty | Frequency Penalty | number | No | Frequency penalty is a parameter that reduces the likelihood of the model repeating the same words or phrases multiple times. Typical range of 0-2 | +| seed | Seed | number | No | Seed is a parameter used to make AI model outputs reproducible. | + +Return Type: [AI_MODEL](./types.mdx#ai_model) + +# + +Auto generated wrapper function to create this model + + + +--- + +### `anthropic/claude-haiku-4-5` (`createModel`) + +| Parameter | Name | Type | Required | Description | +| --- | --- | --- | --- | --- | +| settings | Settings | [AI_ANTHROPIC_SETTINGS](./types.mdx#ai_anthropic_settings) | Yes | The settings for this provider, for more information see the type | +| maxOutputTokens | Max Output Tokens | number | No | Maximum number of tokens to generate | +| temperature | Temperature | number | No | temperature is a parameter that controls the randomness of the model’s outputs during text generation. Normally between 0 and 1 | +| maxRetries | Maximum Retries | number | No | Maximum number of retries. Set to 0 to disable retries. Default value is 2 | +| stopSequences | Stop sequences | string[] | No | Stop sequences are specific strings (words, characters, or patterns) that tell an AI model when to stop generating text. | +| presencePenalty | Presence Penalty | number | No | Presence penalty pushes the model to talk about new things instead of repeating existing ones. Typical range of 0-2 | +| frequencyPenalty | Frequency Penalty | number | No | Frequency penalty is a parameter that reduces the likelihood of the model repeating the same words or phrases multiple times. Typical range of 0-2 | +| seed | Seed | number | No | Seed is a parameter used to make AI model outputs reproducible. | + +Return Type: [AI_MODEL](./types.mdx#ai_model) + +# + +Auto generated wrapper function to create this model + + + +--- + +## Ollama + + +### `ollama/selfhosted` (`createModel`) + +| Parameter | Name | Type | Required | Description | +| --- | --- | --- | --- | --- | +| settings | Settings | [AI_OLLAMA_SETTINGS](./types.mdx#ai_ollama_settings) | Yes | The settings for this provider, for more information see the type | +| maxOutputTokens | Max Output Tokens | number | No | Maximum number of tokens to generate | +| temperature | Temperature | number | No | temperature is a parameter that controls the randomness of the model’s outputs during text generation. Normally between 0 and 1 | +| maxRetries | Maximum Retries | number | No | Maximum number of retries. Set to 0 to disable retries. Default value is 2 | +| stopSequences | Stop sequences | string[] | No | Stop sequences are specific strings (words, characters, or patterns) that tell an AI model when to stop generating text. | +| presencePenalty | Presence Penalty | number | No | Presence penalty pushes the model to talk about new things instead of repeating existing ones. Typical range of 0-2 | +| frequencyPenalty | Frequency Penalty | number | No | Frequency penalty is a parameter that reduces the likelihood of the model repeating the same words or phrases multiple times. Typical range of 0-2 | +| seed | Seed | number | No | Seed is a parameter used to make AI model outputs reproducible. | + +Return Type: [AI_MODEL](./types.mdx#ai_model) + +# + +Auto generated wrapper function to create this model + + + +--- diff --git a/docs/Actions/AI/types.mdx b/docs/Actions/AI/types.mdx new file mode 100644 index 0000000..2d371b7 --- /dev/null +++ b/docs/Actions/AI/types.mdx @@ -0,0 +1,256 @@ +--- +title: Datatypes +description: All data types registered by the AI Action. +--- +import {TypeTable} from "fumadocs-ui/components/type-table"; + +# AI Action Types + +The AI Action registers the following data types with the Hercules platform. + +--- + +# AI_MODEL +No documentation provided for this type. + + + +# AI_OPENAI_SETTINGS +No documentation provided for this type. + + + +# AI_OLLAMA_SETTINGS +No documentation provided for this type. + + + +# AI_GOOGLE_SETTINGS +No documentation provided for this type. + + + +# AI_GOOGLE_SETTINGS$thinkingConfig +No documentation provided for this type. + + + +# ANTHROPIC_SETTINGS +No documentation provided for this type. + + + +# AI_CONFIG_AUTH_TOKENS_TYPE +No documentation provided for this type. + + + +# AI_CONFIG_AUTH_TOKENS_TYPE$ollama +No documentation provided for this type. + + + +# AI_CONFIG_AUTH_TOKENS_TYPE$anthropic +No documentation provided for this type. + + + +# AI_CONFIG_AUTH_TOKENS_TYPE$google +No documentation provided for this type. + + + +# AI_CONFIG_AUTH_TOKENS_TYPE$openai +No documentation provided for this type. + + + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 273360b..3352c2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "actions/*" ], "dependencies": { - "@code0-tech/hercules": "^0.0.2", + "@code0-tech/hercules": "file:code0-tech-hercules-0.0.0.tgz", "axios": "^1.13.6", "vite": "^7.3.1", "zod": "^4.3.6", @@ -27,6 +27,19 @@ "vitest": "^4.0.0" } }, + "actions/ai-action": { + "name": "@code0-tech/ai-action", + "version": "0.0.0", + "dependencies": { + "@ai-sdk/anthropic": "^3.0.66", + "@ai-sdk/google": "^3.0.57", + "@ai-sdk/openai": "^3.0.50", + "ai": "^6.0.145", + "ai-sdk-ollama": "^3.8.2", + "ollama-ai-provider-v2": "^3.5.0", + "ts-morph": "^27.0.2" + } + }, "actions/gls-action": { "name": "@code0-tech/gls-action", "version": "0.0.0", @@ -39,17 +52,115 @@ "version": "0.0.0", "extraneous": true }, + "node_modules/@ai-sdk/anthropic": { + "version": "3.0.66", + "resolved": "https://registry.npmjs.org/@ai-sdk/anthropic/-/anthropic-3.0.66.tgz", + "integrity": "sha512-yJpQ2x6ACwbXo5D6HsVWd2FFnnWcetfGx4oxkG66P8FawusvrY2vL2qMiiNTruWrxEYDy+YHc3ctv8C769MMJA==", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "3.0.8", + "@ai-sdk/provider-utils": "4.0.22" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.25.76 || ^4.1.8" + } + }, + "node_modules/@ai-sdk/gateway": { + "version": "3.0.87", + "resolved": "https://registry.npmjs.org/@ai-sdk/gateway/-/gateway-3.0.87.tgz", + "integrity": "sha512-knLx/VY0u5KAZGgrTorWCTbEnwK3oCCdm8yjxVQm3s14erqVo60SP08dsFWm+xNULPTusftQGVD/l0/hx5QOHg==", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "3.0.8", + "@ai-sdk/provider-utils": "4.0.22", + "@vercel/oidc": "3.1.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.25.76 || ^4.1.8" + } + }, + "node_modules/@ai-sdk/google": { + "version": "3.0.57", + "resolved": "https://registry.npmjs.org/@ai-sdk/google/-/google-3.0.57.tgz", + "integrity": "sha512-ojbYWB1loG8EGdfOWCbbtasoSwfjsGbOt2I1uPBLmoIBOa7EtUuYP4SujxHADZJFg2h08oUt4Dcw+1hJsjlF6A==", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "3.0.8", + "@ai-sdk/provider-utils": "4.0.22" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.25.76 || ^4.1.8" + } + }, + "node_modules/@ai-sdk/openai": { + "version": "3.0.50", + "resolved": "https://registry.npmjs.org/@ai-sdk/openai/-/openai-3.0.50.tgz", + "integrity": "sha512-7M7bklrS+gckzPdpQpC3iG5aN5aQPRJdAJQ5jt7sEgYCqDgUuef9x4Nd570+ghIfKTZvV6tSqeeTuD6De/bZig==", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "3.0.8", + "@ai-sdk/provider-utils": "4.0.22" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.25.76 || ^4.1.8" + } + }, + "node_modules/@ai-sdk/provider": { + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/@ai-sdk/provider/-/provider-3.0.8.tgz", + "integrity": "sha512-oGMAgGoQdBXbZqNG0Ze56CHjDZ1IDYOwGYxYjO5KLSlz5HiNQ9udIXsPZ61VWaHGZ5XW/jyjmr6t2xz2jGVwbQ==", + "license": "Apache-2.0", + "dependencies": { + "json-schema": "^0.4.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@ai-sdk/provider-utils": { + "version": "4.0.22", + "resolved": "https://registry.npmjs.org/@ai-sdk/provider-utils/-/provider-utils-4.0.22.tgz", + "integrity": "sha512-B2OTFcRw/Pdka9ZTjpXv6T6qZ6RruRuLokyb8HwW+aoW9ndJ3YasA3/mVswyJw7VMBF8ofXgqvcrCt9KYvFifg==", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "3.0.8", + "@standard-schema/spec": "^1.1.0", + "eventsource-parser": "^3.0.6" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.25.76 || ^4.1.8" + } + }, + "node_modules/@code0-tech/ai-action": { + "resolved": "actions/ai-action", + "link": true + }, "node_modules/@code0-tech/gls-action": { "resolved": "actions/gls-action", "link": true }, "node_modules/@code0-tech/hercules": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/@code0-tech/hercules/-/hercules-0.0.2.tgz", - "integrity": "sha512-oG0N8zRNX8WJmYORhbNnAj75HXi6pzL+xclO3vOxHQiOBjb4hjqnRYIBtCTuR9xAJSXeOEqPu5rgK2hHKTsdzA==", + "version": "0.0.0", + "resolved": "file:code0-tech-hercules-0.0.0.tgz", + "integrity": "sha512-F8xqDI8GnrNmjdwNgMcXQyy2N7ELFZZHu4IHJS74zHLGcGQ4bMINlxAcLE+pLEg23ezI/rhklGsDaB8mTeULNQ==", "license": "ISC", "dependencies": { - "@code0-tech/tucana": "^0.0.65", + "@code0-tech/tucana": "^0.0.67", "@grpc/grpc-js": "^1.14.3", "@protobuf-ts/grpc-backend": "^2.11.1", "@protobuf-ts/grpc-transport": "^2.11.1", @@ -58,9 +169,9 @@ } }, "node_modules/@code0-tech/tucana": { - "version": "0.0.65", - "resolved": "https://registry.npmjs.org/@code0-tech/tucana/-/tucana-0.0.65.tgz", - "integrity": "sha512-XTNAZ+iqTEf1yLU0uqNc2+ICg6tRF0w41C6da9DePoV4qDa2aRmZwA4jJyr/1i+hohZVKRrhkY7Qaf/blsyx0g==", + "version": "0.0.67", + "resolved": "https://registry.npmjs.org/@code0-tech/tucana/-/tucana-0.0.67.tgz", + "integrity": "sha512-3V1h3LB+iWeXnt80nsIQo+TeMgVTgbDxvDsAArbffHyU37ii1tsAAV6Ty7wAdkrCSsObyFRpdiIZgzgYVVKfzw==", "license": "Apache-2.0" }, "node_modules/@esbuild/aix-ppc64": { @@ -707,6 +818,15 @@ "url": "https://opencollective.com/js-sdsl" } }, + "node_modules/@opentelemetry/api": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz", + "integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==", + "license": "Apache-2.0", + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/@protobuf-ts/grpc-backend": { "version": "2.11.1", "resolved": "https://registry.npmjs.org/@protobuf-ts/grpc-backend/-/grpc-backend-2.11.1.tgz", @@ -1141,7 +1261,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz", "integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==", - "dev": true, "license": "MIT" }, "node_modules/@ts-morph/common": { @@ -1516,6 +1635,15 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@vercel/oidc": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@vercel/oidc/-/oidc-3.1.0.tgz", + "integrity": "sha512-Fw28YZpRnA3cAHHDlkt7xQHiJ0fcL+NRcIqsocZQUSmbzeIKRpwttJjik5ZGanXP+vlA4SbTg+AbA3bP363l+w==", + "license": "Apache-2.0", + "engines": { + "node": ">= 20" + } + }, "node_modules/@vitest/expect": { "version": "4.0.18", "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.0.18.tgz", @@ -1650,6 +1778,42 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/ai": { + "version": "6.0.145", + "resolved": "https://registry.npmjs.org/ai/-/ai-6.0.145.tgz", + "integrity": "sha512-RbMiFsPZxE4uf5Hhs8rscp5bIwvjQOrqS5dQGWNVRHGM947QZgkKX7Ih5hto8MK/7xkbtneoOZruZ8oSLO828A==", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/gateway": "3.0.87", + "@ai-sdk/provider": "3.0.8", + "@ai-sdk/provider-utils": "4.0.22", + "@opentelemetry/api": "1.9.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.25.76 || ^4.1.8" + } + }, + "node_modules/ai-sdk-ollama": { + "version": "3.8.2", + "resolved": "https://registry.npmjs.org/ai-sdk-ollama/-/ai-sdk-ollama-3.8.2.tgz", + "integrity": "sha512-0k9tLeXLhGahsjNOOBZ07KccffeZNx4gIeutuccjRT8YxxEtnIoVF/ECdgoyaPm8be6WCLDkVnmtSJmkdWHHZA==", + "license": "MIT", + "dependencies": { + "@ai-sdk/provider": "^3.0.8", + "@ai-sdk/provider-utils": "^4.0.21", + "jsonrepair": "^3.13.3", + "ollama": "^0.6.3" + }, + "engines": { + "node": ">=22" + }, + "peerDependencies": { + "ai": "^6.0.137" + } + }, "node_modules/ajv": { "version": "6.14.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.14.0.tgz", @@ -2158,6 +2322,15 @@ "node": ">=0.10.0" } }, + "node_modules/eventsource-parser": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.0.6.tgz", + "integrity": "sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg==", + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/expect-type": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz", @@ -2505,6 +2678,12 @@ "dev": true, "license": "MIT" }, + "node_modules/json-schema": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", + "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", + "license": "(AFL-2.1 OR BSD-3-Clause)" + }, "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -2519,6 +2698,15 @@ "dev": true, "license": "MIT" }, + "node_modules/jsonrepair": { + "version": "3.13.3", + "resolved": "https://registry.npmjs.org/jsonrepair/-/jsonrepair-3.13.3.tgz", + "integrity": "sha512-BTznj0owIt2CBAH/LTo7+1I5pMvl1e1033LRl/HUowlZmJOIhzC0zbX5bxMngLkfT4WnzPP26QnW5wMr2g9tsQ==", + "license": "ISC", + "bin": { + "jsonrepair": "bin/cli.js" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -2669,6 +2857,32 @@ ], "license": "MIT" }, + "node_modules/ollama": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/ollama/-/ollama-0.6.3.tgz", + "integrity": "sha512-KEWEhIqE5wtfzEIZbDCLH51VFZ6Z3ZSa6sIOg/E/tBV8S51flyqBOXi+bRxlOYKDf8i327zG9eSTb8IJxvm3Zg==", + "license": "MIT", + "dependencies": { + "whatwg-fetch": "^3.6.20" + } + }, + "node_modules/ollama-ai-provider-v2": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/ollama-ai-provider-v2/-/ollama-ai-provider-v2-3.5.0.tgz", + "integrity": "sha512-+s/aYIYa91z2Vk3AkGAz3BaPAQ0flS2eFZD3BN2mD/N6W6YQbcookyu6pc2cbc8SP5VGpNB857WJ0eHDjKXsXw==", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "^3.0.8", + "@ai-sdk/provider-utils": "^4.0.19" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "ai": "^5.0.0 || ^6.0.0", + "zod": "^4.0.16" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -3298,6 +3512,12 @@ } } }, + "node_modules/whatwg-fetch": { + "version": "3.6.20", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz", + "integrity": "sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==", + "license": "MIT" + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 4eb0488..4db9de9 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "vitest": "^4.0.0" }, "dependencies": { - "@code0-tech/hercules": "^0.0.2", + "@code0-tech/hercules": "file:code0-tech-hercules-0.0.0.tgz", "axios": "^1.13.6", "vite": "^7.3.1", "zod": "^4.3.6", diff --git a/scripts/create-action.mjs b/scripts/create-action.mjs index 4dc142b..dfe605f 100644 --- a/scripts/create-action.mjs +++ b/scripts/create-action.mjs @@ -2,10 +2,10 @@ // Creates a new package inside the packages/ workspace. // Usage: npm run create-package -- -import { mkdir, writeFile, readFile } from "fs/promises"; -import { join, dirname } from "path"; -import { fileURLToPath } from "url"; -import { existsSync } from "fs"; +import {mkdir, writeFile, readFile} from "fs/promises"; +import {join, dirname} from "path"; +import {fileURLToPath} from "url"; +import {existsSync} from "fs"; const __dirname = dirname(fileURLToPath(import.meta.url)); const rootDir = join(__dirname, ".."); @@ -13,82 +13,117 @@ const rootDir = join(__dirname, ".."); const actionName = process.argv[2]; if (!actionName) { - console.error("Usage: npm run create-package -- "); - process.exit(1); + console.error("Usage: npm run create-package -- "); + process.exit(1); } if (!/^[a-z][a-z0-9-]*$/.test(actionName)) { - console.error( - "Action name must start with a lowercase letter and contain only lowercase letters, digits, and hyphens." - ); - process.exit(1); + console.error( + "Action name must start with a lowercase letter and contain only lowercase letters, digits, and hyphens." + ); + process.exit(1); } const packageDir = join(rootDir, "actions", actionName); if (existsSync(packageDir)) { - console.error( - `Action "${actionName}" already exists at actions/${actionName}` - ); - process.exit(1); + console.error( + `Action "${actionName}" already exists at actions/${actionName}` + ); + process.exit(1); } console.log(`Creating action "${actionName}"...`); // Create directory structure -await mkdir(join(packageDir, "src"), { recursive: true }); +await mkdir(join(packageDir, "src"), {recursive: true}); // package.json const packageJson = { - name: `@code0-tech/${actionName}`, - version: "0.0.0", - private: true, - type: "module", - main: "./dist/index.js", - types: "./dist/index.d.ts", - scripts: { - build: "tsc --build", - lint: "eslint .", - }, + name: `@code0-tech/${actionName}`, + version: "0.0.0", + private: true, + type: "module", + main: "./dist/index.js", + types: "./dist/index.d.ts", + scripts: { + build: "vite build", + lint: "eslint .", + test: "vitest run", + start: "node dist/main.js", + "generate:docs": "npm run build && node dist/generateDocs.js" + }, }; await writeFile( - join(packageDir, "package.json"), - JSON.stringify(packageJson, null, 2) + "\n" + join(packageDir, "package.json"), + JSON.stringify(packageJson, null, 2) + "\n" ); +await writeFile(join(packageDir, "vite.config.ts"), ` +import {defineConfig} from 'vite'; +import {resolve} from 'path'; + +export default defineConfig({ + build: { + target: 'node18', + ssr: true, + outDir: 'dist', + emptyOutDir: true, + rollupOptions: { + input: { + main: resolve(__dirname, 'src/index.ts'), + generateDocs: resolve(__dirname, 'scripts/generateDocs.ts') + }, + external: [ + 'fs', + 'path', + 'os', + 'crypto', + 'stream', + 'util', + 'events', + 'buffer', + 'url', + 'zlib', + 'node:fs', + 'node:path' + ] + } + } +}); +`); + +await writeFile(join(packageDir, "vitetest.config.ts"), ` +import baseConfig from "../../vitest.config"; +import { defineConfig, mergeConfig } from "vitest/config"; + +export default mergeConfig(baseConfig, defineConfig({ + test: { + include: ["**/*.{test,spec}.{ts,tsx}"] + } +})); +`); + + // tsconfig.json const tsconfig = { - extends: "../../tsconfig.base.json", - compilerOptions: { - rootDir: "./src", - outDir: "./dist", - composite: true, - }, - include: ["src"], - exclude: ["src/**/*.test.ts", "src/**/*.spec.ts"], + extends: "../../tsconfig.base.json", + compilerOptions: { + outDir: "dist", + }, + include: ["src"], + exclude: ["src/**/*.test.ts", "src/**/*.spec.ts"], }; await writeFile( - join(packageDir, "tsconfig.json"), - JSON.stringify(tsconfig, null, 2) + "\n" + join(packageDir, "tsconfig.json"), + JSON.stringify(tsconfig, null, 2) + "\n" ); // src/index.ts await writeFile(join(packageDir, "src", "index.ts"), `// ${actionName}\n`); -// Update root tsconfig.json references -const rootTsconfigPath = join(rootDir, "tsconfig.json"); -const rootTsconfig = JSON.parse(await readFile(rootTsconfigPath, "utf-8")); - -rootTsconfig.references = rootTsconfig.references ?? []; -rootTsconfig.references.push({ path: `actions/${actionName}` }); - -await writeFile( - rootTsconfigPath, - JSON.stringify(rootTsconfig, null, 2) + "\n" -); - console.log(`\n✅ Action "${actionName}" created successfully!`); console.log(` Location : actions/${actionName}`); console.log(` Run "npm install" to link the new workspace.`); diff --git a/src/helpers.ts b/src/helpers.ts new file mode 100644 index 0000000..96175e3 --- /dev/null +++ b/src/helpers.ts @@ -0,0 +1,42 @@ +import {ZodObject} from "zod"; +import {createAuxiliaryTypeStore, printNode, zodToTs} from "zod-to-ts"; +import * as ts from "typescript"; + +export function singleZodSchemaToTypescriptDef( + typeName: string, + zodSchema: ZodObject +) { + return zodSchemaToTypescriptDefs(typeName, zodSchema).get(typeName)!; +} + +export function zodSchemaToTypescriptDefs( + typeName: string, + zodSchema: ZodObject, + extraSchemas: Record = {} +): Map { + const store = createAuxiliaryTypeStore(); + const result = new Map(); + + for (const [name, schema] of Object.entries(extraSchemas)) { + const {node} = zodToTs(schema, {auxiliaryTypeStore: store}); + + const alias = ts.factory.createTypeAliasDeclaration( + undefined, + ts.factory.createIdentifier(name), + undefined, + node + ); + + store.definitions.set(schema, { + identifier: ts.factory.createIdentifier(name), + node: alias + }); + + result.set(name, printNode(alias).replace(`type ${name} =`, ``)); + } + + const {node} = zodToTs(zodSchema, {auxiliaryTypeStore: store}); + result.set(typeName, printNode(node)); + + return result; +} diff --git a/src/standardActionDocs.ts b/src/standardActionDocs.ts index 5d3b9ab..9403008 100644 --- a/src/standardActionDocs.ts +++ b/src/standardActionDocs.ts @@ -3,8 +3,8 @@ import { ActionSdk, HerculesActionConfigurationDefinition, HerculesDataType, - HerculesFlowType, - HerculesRegisterFunctionParameter, + HerculesFlowType, HerculesRegisterFunctionDefinition, + HerculesRegisterRuntimeFunctionParameter, RegisteredFunction, } from "@code0-tech/hercules" import {Project, SymbolFlags, Type} from "ts-morph" @@ -27,16 +27,16 @@ interface FunctionDefinitionCard { } } -interface RegistryState { +export interface RegistryState { dataTypes: HerculesDataType[] actionConfigurationDefinitions: HerculesActionConfigurationDefinition[] - runtimeFunctions: HerculesRegisterFunctionParameter[] + functions: HerculesRegisterFunctionDefinition[] flowTypes: HerculesFlowType[] } interface FunctionGroup { heading: string - modules: Record Promise> + loadFunctions: (sdk: ActionSdk) => Promise, intro?: string } @@ -69,14 +69,24 @@ function createRegistry(): RegistryState { return { dataTypes: [], actionConfigurationDefinitions: [], - runtimeFunctions: [], + functions: [], flowTypes: [], } } function createMockSdk(registry: RegistryState): ActionSdk { + const registerFunctionDefinitions = (...functionDefinitions) => { + registry.functions = [...functionDefinitions.map(value => { + return { + ...value, + isFunctionDefinition: true + } + }), ...registry.functions] + return Promise.resolve() + }; return { - onError: () => {}, + onError: () => { + }, connect: () => Promise.resolve([]), dispatchEvent: () => Promise.resolve(), getProjectActionConfigurations: () => [], @@ -98,10 +108,24 @@ function createMockSdk(registry: RegistryState): ActionSdk { ] return Promise.resolve() }, - registerFunctionDefinitions: (...functionDefinitions) => { - registry.runtimeFunctions = [...functionDefinitions, ...registry.runtimeFunctions] - return Promise.resolve() + registerRuntimeFunctionDefinitionsAndFunctionDefinitions: async (...runtimeFunctionDefinitions) => { + for (const value of runtimeFunctionDefinitions) { + await registerFunctionDefinitions({ + ...value.definition, + runtimeDefinitionName: value.definition.runtimeName, + parameters: value.definition.parameters.map(parameter => { + return { + ...parameter, + runtimeDefinitionName: parameter.runtimeName + } + }) + } as HerculesRegisterFunctionDefinition) + } + }, + registerRuntimeFunctionDefinitions: () => { + return Promise.resolve() }, + registerFunctionDefinitions: registerFunctionDefinitions, registerFlowTypes: (...flowTypes) => { registry.flowTypes = [...registry.flowTypes, ...flowTypes] return Promise.resolve() @@ -139,7 +163,7 @@ function breakDownType(typeName: string, code: string): Record { } let typeText: string - if (propType.getText().startsWith("{")) { + if (propType.getText().startsWith("{") && !(propType.getText() === "{ [key: string]: string; }" || propType.getText() === "{ [x: string]: unknown; }")) { const nestedName = `${currentName}$${name}` const nestedType = buildType(propType, nestedName) map[nestedName] = `export type ${nestedName} = ${nestedType};` @@ -262,7 +286,7 @@ ${config.typesCopy.intro} } function getParamInfo(signature: string, paramName: string): { optional: boolean; type: string | null } { - const paramsMatch = signature.match(/\((.*)\)/s) + const paramsMatch = signature.match(/\((.*)\)/) if (!paramsMatch) { return {optional: false, type: null} } @@ -289,11 +313,7 @@ function generateMarkdownTable(headers: string[], rows: string[][]): string { return [headerRow, separator, ...bodyRows].join("\n") } -async function loadFunctions( - modules: Record Promise>, - sdk: ActionSdk, - registry: RegistryState, -): Promise { +export const loadFunctions = async (sdk: ActionSdk, modules: { [x: string]: () => any; }) => { for (const path in modules) { const mod: any = await modules[path]() if (typeof mod.default !== "function") { @@ -306,8 +326,6 @@ async function loadFunctions( console.log(`Error registering functions from ${path}:`, error) } } - - registry.runtimeFunctions = [...registry.runtimeFunctions] } async function generateFunctions(config: StandardActionDocsConfig, sdk: ActionSdk, registry: RegistryState): Promise { @@ -322,16 +340,15 @@ ${config.functionsCopy.intro} ` for (const group of config.functionGroups) { - registry.runtimeFunctions = [] - await loadFunctions(group.modules, sdk, registry) + registry.functions = [] + await group.loadFunctions(sdk) generatedDoc += ` ## ${group.heading} ${group.intro ? `\n${group.intro}\n` : ""} ` - registry.runtimeFunctions.forEach(value => { - const definition = value.definition + registry.functions.forEach(definition => { const card: FunctionDefinitionCard = { descriptions: definition.description, names: definition.name, @@ -347,30 +364,33 @@ ${group.intro ? `\n${group.intro}\n` : ""} } const headers = ["Parameter", "Name", "Type", "Required", "Description"] - const rows: string[][] = definition.parameters.map(parameter => { + const rows: string[][] = definition.parameters.filter(value => !value.hidden).map(parameter => { const paramInfo = getParamInfo(definition.signature, parameter.runtimeName) const linkedType = getTypeLink(paramInfo.type, config) return [ parameter.runtimeName, - parameter.name[0].content, + parameter.name?.[0]?.content, linkedType?.replace(/\|/g, "\\|") || "Unknown", paramInfo.optional ? "No" : "Yes", - parameter.description[0].content, + parameter.description?.[0]?.content, ] }) + const formattedName = definition.runtimeName === definition.runtimeDefinitionName ? + `\`${definition.runtimeName}\`` : + `\`${definition.runtimeName}\` (\`${definition.runtimeDefinitionName}\`)` const returnType = definition.signature.split("):")[1]?.trim() generatedDoc += ` -### \`${definition.runtimeName}\` - -${generateMarkdownTable(headers, rows)} +### ${formattedName} -Return Type: ${getTypeLink(returnType || null, config) || "Unknown"} +${definition.documentation?.[0]?.content || ""} # -${definition.documentation?.at(0)?.content || ""} +${generateMarkdownTable(headers, rows)} + +Return Type: ${getTypeLink(returnType || null, config) || "Unknown"} Date: Sat, 4 Apr 2026 21:00:37 +0200 Subject: [PATCH 2/6] Linting --- actions/ai-action/scripts/generateDocs.ts | 3 +-- actions/ai-action/src/functions/models/createModelFunction.ts | 2 +- actions/gls-action/src/helpers.ts | 4 +--- scripts/create-action.mjs | 2 +- src/standardActionDocs.ts | 1 - 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/actions/ai-action/scripts/generateDocs.ts b/actions/ai-action/scripts/generateDocs.ts index 48b36d1..0af61b1 100644 --- a/actions/ai-action/scripts/generateDocs.ts +++ b/actions/ai-action/scripts/generateDocs.ts @@ -1,6 +1,5 @@ -import {RegistryState, runStandardActionDocs, StandardActionDocsConfig} from "../../../src/standardActionDocs" +import {runStandardActionDocs, StandardActionDocsConfig} from "../../../src/standardActionDocs" import {loadAllDefinitions, loadAllDefinitionsByModules} from "../src/helpers"; -import {ActionSdk} from "@code0-tech/hercules"; export function generateAIConfig(): StandardActionDocsConfig { return { diff --git a/actions/ai-action/src/functions/models/createModelFunction.ts b/actions/ai-action/src/functions/models/createModelFunction.ts index 57fa8fb..c2da9b7 100644 --- a/actions/ai-action/src/functions/models/createModelFunction.ts +++ b/actions/ai-action/src/functions/models/createModelFunction.ts @@ -1,4 +1,4 @@ -import {ActionSdk, HerculesFunctionContext} from "@code0-tech/hercules"; +import {ActionSdk} from "@code0-tech/hercules"; import {Model} from "../../types/aiModel"; diff --git a/actions/gls-action/src/helpers.ts b/actions/gls-action/src/helpers.ts index 772e59a..604cd71 100644 --- a/actions/gls-action/src/helpers.ts +++ b/actions/gls-action/src/helpers.ts @@ -1,6 +1,4 @@ -import {ZodError, ZodObject} from "zod"; -import {createAuxiliaryTypeStore, printNode, zodToTs} from "zod-to-ts"; -import ts from "typescript"; +import {ZodError} from "zod"; import axios from "axios"; import { HerculesRuntimeFunctionDefinition, diff --git a/scripts/create-action.mjs b/scripts/create-action.mjs index dfe605f..12d2a30 100644 --- a/scripts/create-action.mjs +++ b/scripts/create-action.mjs @@ -2,7 +2,7 @@ // Creates a new package inside the packages/ workspace. // Usage: npm run create-package -- -import {mkdir, writeFile, readFile} from "fs/promises"; +import {mkdir, writeFile} from "fs/promises"; import {join, dirname} from "path"; import {fileURLToPath} from "url"; import {existsSync} from "fs"; diff --git a/src/standardActionDocs.ts b/src/standardActionDocs.ts index 9403008..507255c 100644 --- a/src/standardActionDocs.ts +++ b/src/standardActionDocs.ts @@ -4,7 +4,6 @@ import { HerculesActionConfigurationDefinition, HerculesDataType, HerculesFlowType, HerculesRegisterFunctionDefinition, - HerculesRegisterRuntimeFunctionParameter, RegisteredFunction, } from "@code0-tech/hercules" import {Project, SymbolFlags, Type} from "ts-morph" From 8a11315d1c567bcf93f506ca8dc0e16acc005b62 Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Sat, 4 Apr 2026 21:01:56 +0200 Subject: [PATCH 3/6] Generate docs --- docs/Actions/AI/functions.mdx | 48 ++++---- docs/Actions/GLS/functions.mdx | 208 ++++++++++++++++----------------- 2 files changed, 128 insertions(+), 128 deletions(-) diff --git a/docs/Actions/AI/functions.mdx b/docs/Actions/AI/functions.mdx index f88ce2c..b5567b1 100644 --- a/docs/Actions/AI/functions.mdx +++ b/docs/Actions/AI/functions.mdx @@ -12,6 +12,10 @@ description: All functions registered by the AI Action. ### `openai/gpt-5.1` (`createModel`) +Auto generated wrapper function to create this model + +# + | Parameter | Name | Type | Required | Description | | --- | --- | --- | --- | --- | | settings | Settings | [AI_OPENAI_SETTINGS](./types.mdx#ai_openai_settings) | Yes | The settings for this provider, for more information see the type | @@ -25,10 +29,6 @@ description: All functions registered by the AI Action. Return Type: [AI_MODEL](./types.mdx#ai_model) -# - -Auto generated wrapper function to create this model - Date: Sat, 4 Apr 2026 21:04:07 +0200 Subject: [PATCH 4/6] fix naming --- .../src/functions/models/anthropic/anthropicSettings.ts | 4 ++-- docs/Actions/AI/types.mdx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/actions/ai-action/src/functions/models/anthropic/anthropicSettings.ts b/actions/ai-action/src/functions/models/anthropic/anthropicSettings.ts index 62dbe26..042cca1 100644 --- a/actions/ai-action/src/functions/models/anthropic/anthropicSettings.ts +++ b/actions/ai-action/src/functions/models/anthropic/anthropicSettings.ts @@ -8,7 +8,7 @@ export const AnthropicSettingsSchema = z.looseObject({ export default (sdk: ActionSdk) => { return sdk.registerDataTypes({ - type: singleZodSchemaToTypescriptDef("ANTHROPIC_SETTINGS", AnthropicSettingsSchema), - identifier: "ANTHROPIC_SETTINGS" + type: singleZodSchemaToTypescriptDef("AI_ANTHROPIC_SETTINGS", AnthropicSettingsSchema), + identifier: "AI_ANTHROPIC_SETTINGS" }) } \ No newline at end of file diff --git a/docs/Actions/AI/types.mdx b/docs/Actions/AI/types.mdx index 2d371b7..6f31944 100644 --- a/docs/Actions/AI/types.mdx +++ b/docs/Actions/AI/types.mdx @@ -136,7 +136,7 @@ thinkingBudget: { }} /> -# ANTHROPIC_SETTINGS +# AI_ANTHROPIC_SETTINGS No documentation provided for this type. Date: Mon, 6 Apr 2026 01:56:20 +0200 Subject: [PATCH 5/6] Add AI tool registration and authentication configuration --- actions/ai-action/package.json | 3 +- actions/ai-action/scripts/generateDocs.ts | 4 + .../ai-action/src/config/authTokenConfig.ts | 45 --- .../ai-action/src/config/modelAuthConfig.ts | 36 ++ .../ai-action/src/config/toolsAuthConfig.ts | 36 ++ .../ai-action/src/functions/generateText.ts | 112 ++++++ .../functions/models/createModelFunction.ts | 2 +- .../functions/models/ollama/ollamaSettings.ts | 2 + .../ai-action/src/functions/tools/common.ts | 31 ++ .../src/functions/tools/createTool.ts | 36 ++ actions/ai-action/src/helpers.ts | 35 +- actions/ai-action/src/types/aiTool.ts | 72 ++++ .../src/types/glsPrintingOptions.ts | 2 +- code0-tech-hercules-0.0.0.tgz | Bin 5323 -> 0 bytes docs/Actions/AI/functions.mdx | 36 ++ docs/Actions/AI/types.mdx | 110 +++--- package-lock.json | 325 +++++++++++++++++- package.json | 2 +- src/standardActionDocs.ts | 2 +- 19 files changed, 777 insertions(+), 114 deletions(-) delete mode 100644 actions/ai-action/src/config/authTokenConfig.ts create mode 100644 actions/ai-action/src/config/modelAuthConfig.ts create mode 100644 actions/ai-action/src/config/toolsAuthConfig.ts create mode 100644 actions/ai-action/src/functions/generateText.ts create mode 100644 actions/ai-action/src/functions/tools/common.ts create mode 100644 actions/ai-action/src/functions/tools/createTool.ts create mode 100644 actions/ai-action/src/types/aiTool.ts delete mode 100644 code0-tech-hercules-0.0.0.tgz diff --git a/actions/ai-action/package.json b/actions/ai-action/package.json index e736426..2bc6493 100644 --- a/actions/ai-action/package.json +++ b/actions/ai-action/package.json @@ -15,8 +15,9 @@ "dependencies": { "@ai-sdk/anthropic": "^3.0.66", "@ai-sdk/google": "^3.0.57", + "@ai-sdk/mcp": "^1.0.32", "@ai-sdk/openai": "^3.0.50", - "ai": "^6.0.145", + "ai": "^6.0.146", "ai-sdk-ollama": "^3.8.2", "ollama-ai-provider-v2": "^3.5.0", "ts-morph": "^27.0.2" diff --git a/actions/ai-action/scripts/generateDocs.ts b/actions/ai-action/scripts/generateDocs.ts index 0af61b1..94cea5a 100644 --- a/actions/ai-action/scripts/generateDocs.ts +++ b/actions/ai-action/scripts/generateDocs.ts @@ -37,6 +37,10 @@ export function generateAIConfig(): StandardActionDocsConfig { heading: "Ollama", loadFunctions: async (sdk) => await loadAllDefinitionsByModules(sdk, import.meta.glob("../src/functions/models/ollama/common.ts")), }, + { + heading: "Tools", + loadFunctions: async (sdk) => await loadAllDefinitionsByModules(sdk, import.meta.glob("../src/functions/tools/**/*.ts")), + } ], } } diff --git a/actions/ai-action/src/config/authTokenConfig.ts b/actions/ai-action/src/config/authTokenConfig.ts deleted file mode 100644 index df5bcee..0000000 --- a/actions/ai-action/src/config/authTokenConfig.ts +++ /dev/null @@ -1,45 +0,0 @@ -import {ActionSdk} from "@code0-tech/hercules"; -import {z} from "zod"; -import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers" -import {ModelSchema} from "../types/aiModel"; - -const providers = ModelSchema.shape.provider.options; - -export const AuthTokensConfigSchema = z.object( - Object.fromEntries( - providers.map((option) => [ - option, - z.object({ - defaultToken: z.string(), - overrides: z.record(z.string(), z.string()) - }) - ]) - ) -); - -export type AuthTokensConfig = z.infer - -export default (sdk: ActionSdk) => { - sdk.registerDataTypes({ - type: singleZodSchemaToTypescriptDef("AI_CONFIG_AUTH_TOKENS_TYPE", AuthTokensConfigSchema), - identifier: "AI_CONFIG_AUTH_TOKENS_TYPE" - }) - - return sdk.registerConfigDefinitions({ - type: "AI_CONFIG_AUTH_TOKENS_TYPE", - identifier: "AUTH_TOKENS", - linkedDataTypes: ["AI_CONFIG_AUTH_TOKENS_TYPE"], - name: [ - { - code: "en-US", - content: "Auth tokens" - } - ], - description: [ - { - code: "en-US", - content: "Every configured " - } - ] - }) -} \ No newline at end of file diff --git a/actions/ai-action/src/config/modelAuthConfig.ts b/actions/ai-action/src/config/modelAuthConfig.ts new file mode 100644 index 0000000..cff6c29 --- /dev/null +++ b/actions/ai-action/src/config/modelAuthConfig.ts @@ -0,0 +1,36 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {z} from "zod"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers" +import {ModelSchema} from "../types/aiModel"; + +const providers = ModelSchema.shape.provider.options; + +export const ModelAuthConfigSchema = z.object( + Object.fromEntries( + providers.map((option) => [ + option, + z.object({ + authToken: z.string(), + }) + ]) + ) +); + +export default (sdk: ActionSdk) => { + sdk.registerDataTypes({ + type: singleZodSchemaToTypescriptDef("AI_MODEL_AUTH_CONFIG", ModelAuthConfigSchema), + identifier: "AI_MODEL_AUTH_CONFIG" + }) + + return sdk.registerConfigDefinitions({ + type: "AI_MODEL_AUTH_CONFIG", + identifier: "MODEL_AUTH", + linkedDataTypes: ["AI_MODEL_AUTH_CONFIG"], + name: [ + { + code: "en-US", + content: "Model auth" + } + ] + }) +} \ No newline at end of file diff --git a/actions/ai-action/src/config/toolsAuthConfig.ts b/actions/ai-action/src/config/toolsAuthConfig.ts new file mode 100644 index 0000000..c6e5140 --- /dev/null +++ b/actions/ai-action/src/config/toolsAuthConfig.ts @@ -0,0 +1,36 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; +import {z} from "zod"; +import {ToolProviderEnum} from "../types/aiTool"; + +const providers = ToolProviderEnum.options; + +export const ToolsAuthConfigSchema = z.object( + Object.fromEntries( + providers.map((option) => [ + option, + z.object({ + authToken: z.string(), + }) + ]) + ) +); + +export default (sdk: ActionSdk) => { + sdk.registerDataTypes({ + type: singleZodSchemaToTypescriptDef("AI_TOOLS_AUTH_CONFIG", ToolsAuthConfigSchema), + identifier: "AI_TOOLS_AUTH_CONFIG" + }) + + return sdk.registerConfigDefinitions({ + type: "AI_TOOLS_AUTH_CONFIG", + identifier: "TOOLS_AUTH", + linkedDataTypes: ["AI_TOOLS_AUTH_CONFIG"], + name: [ + { + code: "en-US", + content: "Model auth" + } + ] + }) +} \ No newline at end of file diff --git a/actions/ai-action/src/functions/generateText.ts b/actions/ai-action/src/functions/generateText.ts new file mode 100644 index 0000000..eefbf7d --- /dev/null +++ b/actions/ai-action/src/functions/generateText.ts @@ -0,0 +1,112 @@ +import {ActionSdk, HerculesFunctionContext} from "@code0-tech/hercules"; +import {Model} from "../types/aiModel"; +import {extractToken, extractToolToken} from "../helpers"; +import {generateText, isLoopFinished, ToolSet} from "ai"; +import {createGoogleGenerativeAI} from "@ai-sdk/google"; +import {ProviderV3} from "@ai-sdk/provider"; +import {createOpenAI} from "@ai-sdk/openai"; +import {createAnthropic} from "@ai-sdk/anthropic"; +import {createOllama} from "ollama-ai-provider-v2"; +import {OllamaSettings, OllamaSettingsSchema} from "./models/ollama/ollamaSettings"; +import {createMCPClient} from "@ai-sdk/mcp"; +import {Tool} from "../types/aiTool"; + + +export const handler = async (context: HerculesFunctionContext, model: Model, system: string, prompt: string, tools: Tool[]): Promise => { + const apiKey = extractToken(context, model.provider) + + let provider: ProviderV3 + + switch (model.provider) { + case "google": { + provider = createGoogleGenerativeAI({apiKey: apiKey}); + break + } + case "openai": { + provider = createOpenAI({ + apiKey: apiKey + }) + break + } + case "anthropic": { + provider = createAnthropic({ + apiKey: apiKey + }) + break + } + case "ollama": { + const settings: OllamaSettings = OllamaSettingsSchema.parse(model.settings) + provider = createOllama({ + baseURL: settings.baseURL + }) + break + } + + } + let modelTools: ToolSet = {} + + for (const tool of tools) { + const mcpClient = await createMCPClient({ + transport: { + type: 'http', + url: tool.url, + headers: {Authorization: `Bearer ${extractToolToken(context, tool.providerName)}`}, + redirect: 'error', + }, + }); + const tools = await mcpClient.tools() + + if (!tool.tools) { + modelTools = { + ...modelTools, + ...tools + } + continue + } + + const filteredTools: ToolSet = {} + + Object.entries(tools) + .filter(([toolName]) => tool.tools.includes(toolName)) + .forEach(([toolName, toolValue]) => { + filteredTools[toolName] = toolValue + }) + + + modelTools = { + ...modelTools, + ...filteredTools + } + } + + const generated = await generateText({ + model: provider.languageModel(model.model), + prompt: prompt, + system: system, + tools: modelTools, + stopWhen: isLoopFinished(), + }) + + + if (generated.output) { + return generated.output + } + generated.content.forEach((value: any) => { + if (value.type === "tool-result" && value.output.content) { + return value.output.content[0].text + } + }) + +}; +export default (sdk: ActionSdk) => { + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( + { + definition: { + runtimeName: "generateText", + signature: "(model: AI_MODEL, system: string, prompt: string, tools: AI_TOOL[]): string", + linkedDataTypes: ["AI_MODEL", "AI_TOOL"] + }, + handler: handler + } + ) +} \ No newline at end of file diff --git a/actions/ai-action/src/functions/models/createModelFunction.ts b/actions/ai-action/src/functions/models/createModelFunction.ts index c2da9b7..f699402 100644 --- a/actions/ai-action/src/functions/models/createModelFunction.ts +++ b/actions/ai-action/src/functions/models/createModelFunction.ts @@ -6,7 +6,7 @@ export default (sdk: ActionSdk) => { return sdk.registerRuntimeFunctionDefinitions({ definition: { runtimeName: "createModel", - signature: "(settings: object, maxOutputTokens?: number, temperature?: number, maxRetries?: number, stopSequences?: string[], presencePenalty?: number, frequencyPenalty?: number, seed?: number) => AI_MODEL", + signature: "(provider: string, model: string, settings: object, maxOutputTokens?: number, temperature?: number, maxRetries?: number, stopSequences?: string[], presencePenalty?: number, frequencyPenalty?: number, seed?: number) => AI_MODEL", parameters: [ { runtimeName: "provider", diff --git a/actions/ai-action/src/functions/models/ollama/ollamaSettings.ts b/actions/ai-action/src/functions/models/ollama/ollamaSettings.ts index 4e67ab9..0d31ab6 100644 --- a/actions/ai-action/src/functions/models/ollama/ollamaSettings.ts +++ b/actions/ai-action/src/functions/models/ollama/ollamaSettings.ts @@ -6,6 +6,8 @@ export const OllamaSettingsSchema = z.looseObject({ baseURL: z.string() }) +export type OllamaSettings = z.infer + export default (sdk: ActionSdk) => { return sdk.registerDataTypes({ type: singleZodSchemaToTypescriptDef("AI_OLLAMA_SETTINGS", OllamaSettingsSchema), diff --git a/actions/ai-action/src/functions/tools/common.ts b/actions/ai-action/src/functions/tools/common.ts new file mode 100644 index 0000000..478e464 --- /dev/null +++ b/actions/ai-action/src/functions/tools/common.ts @@ -0,0 +1,31 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {TOOL_REGISTRY, ToolProvider} from "../../types/aiTool"; + + +export default (sdk: ActionSdk, tool: ToolProvider) => { + return sdk.registerFunctionDefinitions({ + runtimeName: tool, + runtimeDefinitionName: "createTool", + linkedDataTypes: ["AI_TOOL"], + signature: `(name: string, url: string, tools?: ${TOOL_REGISTRY[tool].tools.map(toolName => `"${toolName}"`).join(" | ")}): AI_TOOL`, + parameters: [ + { + runtimeName: "name", + hidden: true, + defaultValue: tool + }, + { + runtimeName: "url", + hidden: true, + defaultValue: TOOL_REGISTRY[tool].url + }, + { + runtimeName: "tools", + hidden: false, + optional: false, + defaultValue: TOOL_REGISTRY[tool].tools + } + ] + + }) +} \ No newline at end of file diff --git a/actions/ai-action/src/functions/tools/createTool.ts b/actions/ai-action/src/functions/tools/createTool.ts new file mode 100644 index 0000000..20256d5 --- /dev/null +++ b/actions/ai-action/src/functions/tools/createTool.ts @@ -0,0 +1,36 @@ +import {ActionSdk} from "@code0-tech/hercules"; +import {Tool, ToolProvider} from "../../types/aiTool"; + + +export default (sdk: ActionSdk) => { + return sdk.registerRuntimeFunctionDefinitions({ + definition: { + runtimeName: "createTool", + linkedDataTypes: ["AI_TOOL"], + signature: "(providerName: string, url: string, tools?: string[]): AI_TOOL", + parameters: [ + { + runtimeName: "providerName" + }, + { + runtimeName: "url", + }, + { + runtimeName: "tools", + optional: true + }, + ], + }, + handler: ( + providerName: string, + url: string, + tools?: string[] + ): Tool => { + return { + providerName: providerName as ToolProvider, + url: url, + tools: tools || undefined + } + } + }) +} \ No newline at end of file diff --git a/actions/ai-action/src/helpers.ts b/actions/ai-action/src/helpers.ts index 2ad321a..f9f0323 100644 --- a/actions/ai-action/src/helpers.ts +++ b/actions/ai-action/src/helpers.ts @@ -1,6 +1,8 @@ import {ActionSdk, HerculesFunctionContext, RuntimeErrorException} from "@code0-tech/hercules"; -import {AuthTokensConfigSchema} from "./config/authTokenConfig"; import {Model, MODEL_REGISTRY} from "./types/aiModel"; +import {ToolsAuthConfigSchema} from "./config/toolsAuthConfig"; +import {ToolProvider, ToolProviderEnum} from "./types/aiTool"; +import {ModelAuthConfigSchema} from "./config/modelAuthConfig"; export function registerDefaultCommonAiModelFunction(sdk: ActionSdk, settingsTypeName: string, provider: Model["provider"], model: Model["model"]) { return sdk.registerFunctionDefinitions( @@ -17,9 +19,10 @@ export function registerDefaultCommonAiModelFunction(sdk: ActionSdk, settingsTyp content: "Auto generated wrapper function to create this model" } ], + linkedDataTypes: [settingsTypeName, "AI_MODEL"], runtimeDefinitionName: "createModel", runtimeName: `${provider}/${model}`, - signature: `(settings: ${settingsTypeName}, maxOutputTokens?: number, temperature?: number, maxRetries?: number, stopSequences?: string[], presencePenalty?: number, frequencyPenalty?: number, seed?: number): AI_MODEL`, + signature: `(provider: string, model: string, settings: ${settingsTypeName}, maxOutputTokens?: number, temperature?: number, maxRetries?: number, stopSequences?: string[], presencePenalty?: number, frequencyPenalty?: number, seed?: number): AI_MODEL`, parameters: [ { runtimeName: "provider", @@ -187,21 +190,35 @@ export async function loadAllDefinitionsByModules(sdk: ActionSdk, modules: { [x: console.log(`Error registering functions from ${path}:`, error); } } + } else if (mod.default.length === 2) { + for (const toolProvider of ToolProviderEnum.options) { + try { + await mod.default(sdk, toolProvider); + } catch (error) { + console.log(`Error registering functions from ${path}:`, error); + } + } } } } -export function extractToken(context: HerculesFunctionContext, provider: Model["provider"], model: Model["model"]): string { - const config = AuthTokensConfigSchema.safeParse(context.matchedConfig.findConfig("AUTH_TOKENS")); +export function extractToolToken(context: HerculesFunctionContext, providerName: ToolProvider) { + const config = ToolsAuthConfigSchema.safeParse(context.matchedConfig.findConfig("TOOLS_AUTH")) if (!config.success) { - throw new RuntimeErrorException("Invalid Auth config") + throw new RuntimeErrorException("Invalid tools auth") } - const override = config.data[provider].overrides[model]; - if (override) { - return override + return config.data[providerName].authToken +} + +export function extractToken(context: HerculesFunctionContext, provider: Model["provider"]): string { + const config = ModelAuthConfigSchema.safeParse(context.matchedConfig.findConfig("MODEL_AUTH")); + + if (!config.success) { + throw new RuntimeErrorException("Invalid Auth config") } - return config.data[provider].defaultToken + + return config.data[provider].authToken } \ No newline at end of file diff --git a/actions/ai-action/src/types/aiTool.ts b/actions/ai-action/src/types/aiTool.ts new file mode 100644 index 0000000..05839f7 --- /dev/null +++ b/actions/ai-action/src/types/aiTool.ts @@ -0,0 +1,72 @@ +import {z} from "zod"; +import {ActionSdk} from "@code0-tech/hercules"; +import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; + +export const TOOL_REGISTRY = { + github: { + url: "https://api.githubcopilot.com/mcp/", + tools: ["add_comment_to_pending_review", + "add_issue_comment", + "add_reply_to_pull_request_comment", + "assign_copilot_to_issue", + "create_branch", + "create_or_update_file", + "create_pull_request", + "create_pull_request_with_copilot", + "create_repository", + "delete_file", + "fork_repository", + "get_commit", + "get_copilot_job_status", + "get_file_contents", + "get_label", + "get_latest_release", + "get_release_by_tag", + "get_tag", + "get_team_members", + "get_teams", + "issue_read", + "issue_write", + "list_branches", + "list_commits", + "list_issue_types", + "list_issues", + "list_pull_requests", + "list_releases", + "list_tags", + "merge_pull_request", + "pull_request_read", + "pull_request_review_write", + "push_files", + "request_copilot_review", + "run_secret_scanning", + "search_code", + "search_issues", + "search_pull_requests", + "search_repositories", + "search_users", + "sub_issue_write", + "update_pull_request", + "update_pull_request_branch" + ] + } +} as const + + +export type ToolProvider = keyof typeof TOOL_REGISTRY +export const ToolProviderEnum = z.enum(Object.keys(TOOL_REGISTRY) as [ToolProvider, ...ToolProvider[]]) + +export const ToolSchema = z.object({ + providerName: ToolProviderEnum, + url: z.string(), + tools: z.array(z.string()).optional() +}) + +export type Tool = z.infer + +export default (sdk: ActionSdk) => { + return sdk.registerDataTypes({ + type: singleZodSchemaToTypescriptDef("AI_TOOL", ToolSchema), + identifier: "AI_TOOL" + }) +} \ No newline at end of file diff --git a/actions/gls-action/src/types/glsPrintingOptions.ts b/actions/gls-action/src/types/glsPrintingOptions.ts index b2c643d..bcdb27c 100644 --- a/actions/gls-action/src/types/glsPrintingOptions.ts +++ b/actions/gls-action/src/types/glsPrintingOptions.ts @@ -1,5 +1,5 @@ import {ActionSdk} from "@code0-tech/hercules"; -import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; +import {singleZodSchemaToTypescriptDef, zodSchemaToTypescriptDefs} from "../../../../src/helpers"; import {z} from "zod"; export const ReturnLabelsSchema = z.object({ diff --git a/code0-tech-hercules-0.0.0.tgz b/code0-tech-hercules-0.0.0.tgz deleted file mode 100644 index 158ff589c58afb0dbd6d65d950f4696383eeee7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5323 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 --- + +## Tools + + +### `github` (`createTool`) + + + +# + +| Parameter | Name | Type | Required | Description | +|-----------|------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|-------------| +| tools | | "add_comment_to_pending_review" \| "add_issue_comment" \| "add_reply_to_pull_request_comment" \| "assign_copilot_to_issue" \| "create_branch" \| "create_or_update_file" \| "create_pull_request" \| "create_pull_request_with_copilot" \| "create_repository" \| "delete_file" \| "fork_repository" \| "get_commit" \| "get_copilot_job_status" \| "get_file_contents" \| "get_label" \| "get_latest_release" \| "get_release_by_tag" \| "get_tag" \| "get_team_members" \| "get_teams" \| "issue_read" \| "issue_write" \| "list_branches" \| "list_commits" \| "list_issue_types" \| "list_issues" \| "list_pull_requests" \| "list_releases" \| "list_tags" \| "merge_pull_request" \| "pull_request_read" \| "pull_request_review_write" \| "push_files" \| "request_copilot_review" \| "run_secret_scanning" \| "search_code" \| "search_issues" \| "search_pull_requests" \| "search_repositories" \| "search_users" \| "sub_issue_write" \| "update_pull_request" \| "update_pull_request_branch" | No | | + +Return Type: [AI_TOOL](./types.mdx#ai_tool) + + + +--- diff --git a/docs/Actions/AI/types.mdx b/docs/Actions/AI/types.mdx index 6f31944..9d44675 100644 --- a/docs/Actions/AI/types.mdx +++ b/docs/Actions/AI/types.mdx @@ -10,6 +10,31 @@ The AI Action registers the following data types with the Hercules platform. --- +# AI_TOOL +No documentation provided for this type. + + + # AI_MODEL No documentation provided for this type. @@ -143,7 +168,34 @@ No documentation provided for this type. }} /> -# AI_CONFIG_AUTH_TOKENS_TYPE +# AI_TOOLS_AUTH_CONFIG +No documentation provided for this type. + + + +# AI_TOOLS_AUTH_CONFIG$github +No documentation provided for this type. + + + +# AI_MODEL_AUTH_CONFIG No documentation provided for this type. -# AI_CONFIG_AUTH_TOKENS_TYPE$ollama +# AI_MODEL_AUTH_CONFIG$ollama No documentation provided for this type. -# AI_CONFIG_AUTH_TOKENS_TYPE$anthropic +# AI_MODEL_AUTH_CONFIG$anthropic No documentation provided for this type. -# AI_CONFIG_AUTH_TOKENS_TYPE$google +# AI_MODEL_AUTH_CONFIG$google No documentation provided for this type. -# AI_CONFIG_AUTH_TOKENS_TYPE$openai +# AI_MODEL_AUTH_CONFIG$openai No documentation provided for this type. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3352c2e..3c7c57c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "actions/*" ], "dependencies": { - "@code0-tech/hercules": "file:code0-tech-hercules-0.0.0.tgz", + "@code0-tech/hercules": "^0.0.3", "axios": "^1.13.6", "vite": "^7.3.1", "zod": "^4.3.6", @@ -33,8 +33,9 @@ "dependencies": { "@ai-sdk/anthropic": "^3.0.66", "@ai-sdk/google": "^3.0.57", + "@ai-sdk/mcp": "^1.0.32", "@ai-sdk/openai": "^3.0.50", - "ai": "^6.0.145", + "ai": "^6.0.146", "ai-sdk-ollama": "^3.8.2", "ollama-ai-provider-v2": "^3.5.0", "ts-morph": "^27.0.2" @@ -69,9 +70,9 @@ } }, "node_modules/@ai-sdk/gateway": { - "version": "3.0.87", - "resolved": "https://registry.npmjs.org/@ai-sdk/gateway/-/gateway-3.0.87.tgz", - "integrity": "sha512-knLx/VY0u5KAZGgrTorWCTbEnwK3oCCdm8yjxVQm3s14erqVo60SP08dsFWm+xNULPTusftQGVD/l0/hx5QOHg==", + "version": "3.0.88", + "resolved": "https://registry.npmjs.org/@ai-sdk/gateway/-/gateway-3.0.88.tgz", + "integrity": "sha512-AFoj7xdWAtCQcy0jJ235ENSakYM8D28qBX+rB+/rX4r8qe/LXgl0e5UivOqxAlIM5E9jnQdYxIPuj3XFtGk/yg==", "license": "Apache-2.0", "dependencies": { "@ai-sdk/provider": "3.0.8", @@ -101,6 +102,23 @@ "zod": "^3.25.76 || ^4.1.8" } }, + "node_modules/@ai-sdk/mcp": { + "version": "1.0.32", + "resolved": "https://registry.npmjs.org/@ai-sdk/mcp/-/mcp-1.0.32.tgz", + "integrity": "sha512-WkZquZ+bPAwG1mH9yrjGVPKLycaxnUQhJkkYAAZTSAuIgENcO4k/V38+rI28AneoE995mpWn40sFiZ96fHTPgw==", + "license": "Apache-2.0", + "dependencies": { + "@ai-sdk/provider": "3.0.8", + "@ai-sdk/provider-utils": "4.0.22", + "pkce-challenge": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "zod": "^3.25.76 || ^4.1.8" + } + }, "node_modules/@ai-sdk/openai": { "version": "3.0.50", "resolved": "https://registry.npmjs.org/@ai-sdk/openai/-/openai-3.0.50.tgz", @@ -155,17 +173,19 @@ "link": true }, "node_modules/@code0-tech/hercules": { - "version": "0.0.0", - "resolved": "file:code0-tech-hercules-0.0.0.tgz", - "integrity": "sha512-F8xqDI8GnrNmjdwNgMcXQyy2N7ELFZZHu4IHJS74zHLGcGQ4bMINlxAcLE+pLEg23ezI/rhklGsDaB8mTeULNQ==", + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/@code0-tech/hercules/-/hercules-0.0.3.tgz", + "integrity": "sha512-Hg/OEGvzjRBf5uQMyfQkcMZiqHdnlis8gbwC2QXm3X02N1YK2t+2QjQvAmaXG5wwxkF9OC0WJ9LSWwJU9Ro+LA==", "license": "ISC", "dependencies": { - "@code0-tech/tucana": "^0.0.67", + "@code0-tech/tucana": "0.0.67", "@grpc/grpc-js": "^1.14.3", "@protobuf-ts/grpc-backend": "^2.11.1", "@protobuf-ts/grpc-transport": "^2.11.1", "@protobuf-ts/runtime": "^2.11.1", - "@protobuf-ts/runtime-rpc": "^2.11.1" + "@protobuf-ts/runtime-rpc": "^2.11.1", + "pino": "^10.3.1", + "pino-pretty": "^13.1.3" } }, "node_modules/@code0-tech/tucana": { @@ -827,6 +847,12 @@ "node": ">=8.0.0" } }, + "node_modules/@pinojs/redact": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@pinojs/redact/-/redact-0.4.0.tgz", + "integrity": "sha512-k2ENnmBugE/rzQfEcdWHcCY+/FM3VLzH9cYEsbdsoqrvzAKRhUZeRNhAZvB8OitQJ1TBed3yqWtdjzS6wJKBwg==", + "license": "MIT" + }, "node_modules/@protobuf-ts/grpc-backend": { "version": "2.11.1", "resolved": "https://registry.npmjs.org/@protobuf-ts/grpc-backend/-/grpc-backend-2.11.1.tgz", @@ -1779,12 +1805,12 @@ } }, "node_modules/ai": { - "version": "6.0.145", - "resolved": "https://registry.npmjs.org/ai/-/ai-6.0.145.tgz", - "integrity": "sha512-RbMiFsPZxE4uf5Hhs8rscp5bIwvjQOrqS5dQGWNVRHGM947QZgkKX7Ih5hto8MK/7xkbtneoOZruZ8oSLO828A==", + "version": "6.0.146", + "resolved": "https://registry.npmjs.org/ai/-/ai-6.0.146.tgz", + "integrity": "sha512-70DE8k1rR0N3mXxyyfjYAx/FxRln/kQ5ym18lt1ys1eUklcPuoIXGbUBwdfCbmkt6YF3jCDZ5+OgkWieP/NGDw==", "license": "Apache-2.0", "dependencies": { - "@ai-sdk/gateway": "3.0.87", + "@ai-sdk/gateway": "3.0.88", "@ai-sdk/provider": "3.0.8", "@ai-sdk/provider-utils": "4.0.22", "@opentelemetry/api": "1.9.0" @@ -1871,6 +1897,15 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", "license": "MIT" }, + "node_modules/atomic-sleep": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", + "integrity": "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==", + "license": "MIT", + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/axios": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/axios/-/axios-1.15.0.tgz", @@ -1964,6 +1999,12 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "license": "MIT" }, + "node_modules/colorette": { + "version": "2.0.20", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz", + "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==", + "license": "MIT" + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -1991,6 +2032,15 @@ "node": ">= 8" } }, + "node_modules/dateformat": { + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-4.6.3.tgz", + "integrity": "sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==", + "license": "MIT", + "engines": { + "node": "*" + } + }, "node_modules/debug": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", @@ -2045,6 +2095,15 @@ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "license": "MIT" }, + "node_modules/end-of-stream": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz", + "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==", + "license": "MIT", + "dependencies": { + "once": "^1.4.0" + } + }, "node_modules/es-define-property": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", @@ -2341,6 +2400,12 @@ "node": ">=12.0.0" } }, + "node_modules/fast-copy": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/fast-copy/-/fast-copy-4.0.2.tgz", + "integrity": "sha512-ybA6PDXIXOXivLJK/z9e+Otk7ve13I4ckBvGO5I2RRmBU1gMHLVDJYEuJYhGwez7YNlYji2M2DvVU+a9mSFDlw==", + "license": "MIT" + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -2362,6 +2427,12 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-safe-stringify": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", + "license": "MIT" + }, "node_modules/fdir": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", @@ -2612,6 +2683,12 @@ "node": ">= 0.4" } }, + "node_modules/help-me": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/help-me/-/help-me-5.0.0.tgz", + "integrity": "sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==", + "license": "MIT" + }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", @@ -2671,6 +2748,15 @@ "dev": true, "license": "ISC" }, + "node_modules/joycon": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/joycon/-/joycon-3.1.1.tgz", + "integrity": "sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, "node_modules/json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", @@ -2814,6 +2900,15 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -2883,6 +2978,24 @@ "zod": "^4.0.16" } }, + "node_modules/on-exit-leak-free": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/on-exit-leak-free/-/on-exit-leak-free-2.1.2.tgz", + "integrity": "sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA==", + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -2984,6 +3097,76 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/pino": { + "version": "10.3.1", + "resolved": "https://registry.npmjs.org/pino/-/pino-10.3.1.tgz", + "integrity": "sha512-r34yH/GlQpKZbU1BvFFqOjhISRo1MNx1tWYsYvmj6KIRHSPMT2+yHOEb1SG6NMvRoHRF0a07kCOox/9yakl1vg==", + "license": "MIT", + "dependencies": { + "@pinojs/redact": "^0.4.0", + "atomic-sleep": "^1.0.0", + "on-exit-leak-free": "^2.1.0", + "pino-abstract-transport": "^3.0.0", + "pino-std-serializers": "^7.0.0", + "process-warning": "^5.0.0", + "quick-format-unescaped": "^4.0.3", + "real-require": "^0.2.0", + "safe-stable-stringify": "^2.3.1", + "sonic-boom": "^4.0.1", + "thread-stream": "^4.0.0" + }, + "bin": { + "pino": "bin.js" + } + }, + "node_modules/pino-abstract-transport": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-3.0.0.tgz", + "integrity": "sha512-wlfUczU+n7Hy/Ha5j9a/gZNy7We5+cXp8YL+X+PG8S0KXxw7n/JXA3c46Y0zQznIJ83URJiwy7Lh56WLokNuxg==", + "license": "MIT", + "dependencies": { + "split2": "^4.0.0" + } + }, + "node_modules/pino-pretty": { + "version": "13.1.3", + "resolved": "https://registry.npmjs.org/pino-pretty/-/pino-pretty-13.1.3.tgz", + "integrity": "sha512-ttXRkkOz6WWC95KeY9+xxWL6AtImwbyMHrL1mSwqwW9u+vLp/WIElvHvCSDg0xO/Dzrggz1zv3rN5ovTRVowKg==", + "license": "MIT", + "dependencies": { + "colorette": "^2.0.7", + "dateformat": "^4.6.3", + "fast-copy": "^4.0.0", + "fast-safe-stringify": "^2.1.1", + "help-me": "^5.0.0", + "joycon": "^3.1.1", + "minimist": "^1.2.6", + "on-exit-leak-free": "^2.1.0", + "pino-abstract-transport": "^3.0.0", + "pump": "^3.0.0", + "secure-json-parse": "^4.0.0", + "sonic-boom": "^4.0.1", + "strip-json-comments": "^5.0.2" + }, + "bin": { + "pino-pretty": "bin.js" + } + }, + "node_modules/pino-std-serializers": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-7.1.0.tgz", + "integrity": "sha512-BndPH67/JxGExRgiX1dX0w1FvZck5Wa4aal9198SrRhZjH3GxKQUKIBnYJTdj2HDN3UQAS06HlfcSbQj2OHmaw==", + "license": "MIT" + }, + "node_modules/pkce-challenge": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-5.0.1.tgz", + "integrity": "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ==", + "license": "MIT", + "engines": { + "node": ">=16.20.0" + } + }, "node_modules/postcss": { "version": "8.5.8", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.8.tgz", @@ -3022,6 +3205,22 @@ "node": ">= 0.8.0" } }, + "node_modules/process-warning": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-5.0.0.tgz", + "integrity": "sha512-a39t9ApHNx2L4+HBnQKqxxHNs1r7KF+Intd8Q/g1bUh6q0WIp9voPXJ/x0j+ZL45KF1pJd9+q2jLIRMfvEshkA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT" + }, "node_modules/protobufjs": { "version": "7.5.4", "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.5.4.tgz", @@ -3055,6 +3254,16 @@ "node": ">=10" } }, + "node_modules/pump": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz", + "integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==", + "license": "MIT", + "dependencies": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -3065,6 +3274,21 @@ "node": ">=6" } }, + "node_modules/quick-format-unescaped": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz", + "integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==", + "license": "MIT" + }, + "node_modules/real-require": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/real-require/-/real-require-0.2.0.tgz", + "integrity": "sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==", + "license": "MIT", + "engines": { + "node": ">= 12.13.0" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -3118,6 +3342,31 @@ "fsevents": "~2.3.2" } }, + "node_modules/safe-stable-stringify": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.5.0.tgz", + "integrity": "sha512-b3rppTKm9T+PsVCBEOUR46GWI7fdOs00VKZ1+9c1EWDaDMvjQc6tUwuFyIprgGgTcWoVHSKrU8H31ZHA2e0RHA==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/secure-json-parse": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-4.1.0.tgz", + "integrity": "sha512-l4KnYfEyqYJxDwlNVyRfO2E4NTHfMKAWdUuA8J0yve2Dz/E/PdBepY03RvyJpssIpRFwJoCD55wA+mEDs6ByWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, "node_modules/semver": { "version": "7.7.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", @@ -3161,6 +3410,15 @@ "dev": true, "license": "ISC" }, + "node_modules/sonic-boom": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-4.2.1.tgz", + "integrity": "sha512-w6AxtubXa2wTXAUsZMMWERrsIRAdrK0Sc+FUytWvYAhBJLyuI4llrMIC1DtlNSdI99EI86KZum2MMq3EAZlF9Q==", + "license": "MIT", + "dependencies": { + "atomic-sleep": "^1.0.0" + } + }, "node_modules/source-map-js": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", @@ -3170,6 +3428,15 @@ "node": ">=0.10.0" } }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "license": "ISC", + "engines": { + "node": ">= 10.x" + } + }, "node_modules/stackback": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", @@ -3210,6 +3477,30 @@ "node": ">=8" } }, + "node_modules/strip-json-comments": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-5.0.3.tgz", + "integrity": "sha512-1tB5mhVo7U+ETBKNf92xT4hrQa3pm0MZ0PQvuDnWgAAGHDsfp4lPSpiS6psrSiet87wyGPh9ft6wmhOMQ0hDiw==", + "license": "MIT", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/thread-stream": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/thread-stream/-/thread-stream-4.0.0.tgz", + "integrity": "sha512-4iMVL6HAINXWf1ZKZjIPcz5wYaOdPhtO8ATvZ+Xqp3BTdaqtAwQkNmKORqcIo5YkQqGXq5cwfswDwMqqQNrpJA==", + "license": "MIT", + "dependencies": { + "real-require": "^0.2.0" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/tinybench": { "version": "2.9.0", "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", @@ -3578,6 +3869,12 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/package.json b/package.json index 4db9de9..d40e567 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "vitest": "^4.0.0" }, "dependencies": { - "@code0-tech/hercules": "file:code0-tech-hercules-0.0.0.tgz", + "@code0-tech/hercules": "^0.0.3", "axios": "^1.13.6", "vite": "^7.3.1", "zod": "^4.3.6", diff --git a/src/standardActionDocs.ts b/src/standardActionDocs.ts index 507255c..366b77b 100644 --- a/src/standardActionDocs.ts +++ b/src/standardActionDocs.ts @@ -112,7 +112,7 @@ function createMockSdk(registry: RegistryState): ActionSdk { await registerFunctionDefinitions({ ...value.definition, runtimeDefinitionName: value.definition.runtimeName, - parameters: value.definition.parameters.map(parameter => { + parameters: value.definition.parameters?.map(parameter => { return { ...parameter, runtimeDefinitionName: parameter.runtimeName From c259f41148f32ccbda0f14f4e085fe0b07423574 Mon Sep 17 00:00:00 2001 From: Dario Pranjic Date: Thu, 9 Apr 2026 21:42:50 +0200 Subject: [PATCH 6/6] Implement structured data generation and refactor tool handling --- .../src/functions/generateStructuredData.ts | 139 ++++++++++++++++++ .../ai-action/src/functions/generateText.ts | 88 +---------- actions/ai-action/src/functions/helpers.ts | 79 ++++++++++ actions/ai-action/src/types/aiTool.ts | 3 +- docs/Actions/AI/functions.mdx | 6 +- package-lock.json | 9 +- package.json | 1 + src/standardActionDocs.ts | 2 +- 8 files changed, 240 insertions(+), 87 deletions(-) create mode 100644 actions/ai-action/src/functions/generateStructuredData.ts create mode 100644 actions/ai-action/src/functions/helpers.ts diff --git a/actions/ai-action/src/functions/generateStructuredData.ts b/actions/ai-action/src/functions/generateStructuredData.ts new file mode 100644 index 0000000..8a32b75 --- /dev/null +++ b/actions/ai-action/src/functions/generateStructuredData.ts @@ -0,0 +1,139 @@ +import {ActionSdk, HerculesFunctionContext} from "@code0-tech/hercules"; +import {Model} from "../types/aiModel"; +import {Tool} from "../types/aiTool"; +import {extractToken} from "../helpers"; +import {generateText, isLoopFinished, Output} from "ai"; +import {PlainValue} from "@code0-tech/tucana/helpers"; +import {buildProvider, buildTools} from "./helpers"; +import z from "zod"; + + +function generateZodSchema(value: PlainValue): z.ZodTypeAny { + if (value === null) { + return z.null(); + } + + if (Array.isArray(value)) { + if (value.length === 0) { + return z.array(z.unknown()); + } + + const itemSchemas = value.map((item) => generateZodSchema(item)); + const itemSchema = + itemSchemas.length === 1 + ? itemSchemas[0] + : itemSchemas.slice(1).reduce((acc, current) => z.union([acc, current]), itemSchemas[0]); + + return z.array(itemSchema); + } + + switch (typeof value) { + case "string": + return z.string(); + case "number": + return z.number(); + case "boolean": + return z.boolean(); + case "object": { + const shape: Record = {}; + for (const [key, nestedValue] of Object.entries(value as Record)) { + shape[key] = generateZodSchema(nestedValue); + } + return z.object(shape); + } + default: + return z.unknown(); + } +} + +export const handler = async (context: HerculesFunctionContext, model: Model, system: string, prompt: string, tools: Tool[], type: PlainValue): Promise => { + const apiKey = extractToken(context, model.provider) + + const provider = buildProvider(model, apiKey); + + const modelTools = await buildTools(tools, context); + + const generated = await generateText({ + model: provider.languageModel(model.model), + prompt: prompt, + system: system, + tools: modelTools, + stopWhen: isLoopFinished(), + output: Output.object({ + schema: generateZodSchema(type) + }) + }) + + return generated.output as any +}; +export default (sdk: ActionSdk) => { + return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( + { + definition: { + runtimeName: "generateStructuredData", + signature: "(model: AI_MODEL, system: string, prompt: string, tools: AI_TOOL[], type: TYPE): TYPE", + linkedDataTypes: ["AI_MODEL", "AI_TOOL", "TYPE"], + name: [ + { + code: "en-US", + content: "Generate structured Data" + } + ], + displayMessage: [ + { + code: "en-US", + content: "generate structured Data" + } + ], + parameters: [ + { + runtimeName: "model", + name: [ + { + code: "en-US", + content: "Model" + } + ], + }, + { + runtimeName: "system", + name: [ + { + code: "en-US", + content: "System prompt" + } + ] + }, + { + runtimeName: "prompt", + name: [ + { + code: "en-US", + content: "Prompt" + } + ] + }, + { + runtimeName: "tools", + name: [ + { + code: "en-US", + content: "Tools" + } + ] + }, + { + runtimeName: "type", + name: [ + { + code: "en-US", + content: "Output Type" + } + ] + } + ] + }, + handler: handler + } + ) +} diff --git a/actions/ai-action/src/functions/generateText.ts b/actions/ai-action/src/functions/generateText.ts index eefbf7d..4ddb1e1 100644 --- a/actions/ai-action/src/functions/generateText.ts +++ b/actions/ai-action/src/functions/generateText.ts @@ -1,83 +1,17 @@ import {ActionSdk, HerculesFunctionContext} from "@code0-tech/hercules"; import {Model} from "../types/aiModel"; -import {extractToken, extractToolToken} from "../helpers"; -import {generateText, isLoopFinished, ToolSet} from "ai"; -import {createGoogleGenerativeAI} from "@ai-sdk/google"; -import {ProviderV3} from "@ai-sdk/provider"; -import {createOpenAI} from "@ai-sdk/openai"; -import {createAnthropic} from "@ai-sdk/anthropic"; -import {createOllama} from "ollama-ai-provider-v2"; -import {OllamaSettings, OllamaSettingsSchema} from "./models/ollama/ollamaSettings"; -import {createMCPClient} from "@ai-sdk/mcp"; +import {extractToken} from "../helpers"; +import {generateText, isLoopFinished} from "ai"; import {Tool} from "../types/aiTool"; +import {buildProvider, buildTools} from "./helpers"; export const handler = async (context: HerculesFunctionContext, model: Model, system: string, prompt: string, tools: Tool[]): Promise => { const apiKey = extractToken(context, model.provider) - let provider: ProviderV3 + const provider = buildProvider(model, apiKey); - switch (model.provider) { - case "google": { - provider = createGoogleGenerativeAI({apiKey: apiKey}); - break - } - case "openai": { - provider = createOpenAI({ - apiKey: apiKey - }) - break - } - case "anthropic": { - provider = createAnthropic({ - apiKey: apiKey - }) - break - } - case "ollama": { - const settings: OllamaSettings = OllamaSettingsSchema.parse(model.settings) - provider = createOllama({ - baseURL: settings.baseURL - }) - break - } - - } - let modelTools: ToolSet = {} - - for (const tool of tools) { - const mcpClient = await createMCPClient({ - transport: { - type: 'http', - url: tool.url, - headers: {Authorization: `Bearer ${extractToolToken(context, tool.providerName)}`}, - redirect: 'error', - }, - }); - const tools = await mcpClient.tools() - - if (!tool.tools) { - modelTools = { - ...modelTools, - ...tools - } - continue - } - - const filteredTools: ToolSet = {} - - Object.entries(tools) - .filter(([toolName]) => tool.tools.includes(toolName)) - .forEach(([toolName, toolValue]) => { - filteredTools[toolName] = toolValue - }) - - - modelTools = { - ...modelTools, - ...filteredTools - } - } + const modelTools = await buildTools(tools, context); const generated = await generateText({ model: provider.languageModel(model.model), @@ -87,17 +21,9 @@ export const handler = async (context: HerculesFunctionContext, model: Model, sy stopWhen: isLoopFinished(), }) - - if (generated.output) { - return generated.output - } - generated.content.forEach((value: any) => { - if (value.type === "tool-result" && value.output.content) { - return value.output.content[0].text - } - }) - + return generated.output }; + export default (sdk: ActionSdk) => { return sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions( { diff --git a/actions/ai-action/src/functions/helpers.ts b/actions/ai-action/src/functions/helpers.ts new file mode 100644 index 0000000..4015ff4 --- /dev/null +++ b/actions/ai-action/src/functions/helpers.ts @@ -0,0 +1,79 @@ +import {HerculesFunctionContext} from "@code0-tech/hercules"; +import {Model} from "../types/aiModel"; +import {Tool} from "../types/aiTool"; +import {extractToolToken} from "../helpers"; +import {ToolSet} from "ai"; +import {ProviderV3} from "@ai-sdk/provider"; +import {createGoogleGenerativeAI} from "@ai-sdk/google"; +import {createOpenAI} from "@ai-sdk/openai"; +import {createAnthropic} from "@ai-sdk/anthropic"; +import {OllamaSettings, OllamaSettingsSchema} from "./models/ollama/ollamaSettings"; +import {createOllama} from "ollama-ai-provider-v2"; +import {createMCPClient} from "@ai-sdk/mcp"; + +export function buildProvider(model: Model, apiKey: string): ProviderV3 { + switch (model.provider) { + case "google": { + return createGoogleGenerativeAI({ + apiKey: apiKey + }); + } + case "openai": { + return createOpenAI({ + apiKey: apiKey + }) + break + } + case "anthropic": { + return createAnthropic({ + apiKey: apiKey + }) + } + case "ollama": { + const settings: OllamaSettings = OllamaSettingsSchema.parse(model.settings) + return createOllama({ + baseURL: settings.baseURL + }) + } + + } +} + +export async function buildTools(tools: Tool[], context: HerculesFunctionContext) { + let modelTools: ToolSet = {} + + for (const tool of tools) { + const mcpClient = await createMCPClient({ + transport: { + type: 'http', + url: tool.url, + headers: {Authorization: `Bearer ${extractToolToken(context, tool.providerName)}`}, + redirect: 'error', + }, + }); + const tools = await mcpClient.tools() + + if (!tool.tools) { + modelTools = { + ...modelTools, + ...tools + } + continue + } + + const filteredTools: ToolSet = {} + + Object.entries(tools) + .filter(([toolName]) => tool.tools.includes(toolName)) + .forEach(([toolName, toolValue]) => { + filteredTools[toolName] = toolValue + }) + + + modelTools = { + ...modelTools, + ...filteredTools + } + } + return modelTools; +} diff --git a/actions/ai-action/src/types/aiTool.ts b/actions/ai-action/src/types/aiTool.ts index 05839f7..1921415 100644 --- a/actions/ai-action/src/types/aiTool.ts +++ b/actions/ai-action/src/types/aiTool.ts @@ -5,7 +5,8 @@ import {singleZodSchemaToTypescriptDef} from "../../../../src/helpers"; export const TOOL_REGISTRY = { github: { url: "https://api.githubcopilot.com/mcp/", - tools: ["add_comment_to_pending_review", + tools: [ + "add_comment_to_pending_review", "add_issue_comment", "add_reply_to_pull_request_comment", "assign_copilot_to_issue", diff --git a/docs/Actions/AI/functions.mdx b/docs/Actions/AI/functions.mdx index 493acb4..c0365da 100644 --- a/docs/Actions/AI/functions.mdx +++ b/docs/Actions/AI/functions.mdx @@ -1006,9 +1006,9 @@ Return Type: [AI_MODEL](./types.mdx#ai_model) # -| Parameter | Name | Type | Required | Description | -|-----------|------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|-------------| -| tools | | "add_comment_to_pending_review" \| "add_issue_comment" \| "add_reply_to_pull_request_comment" \| "assign_copilot_to_issue" \| "create_branch" \| "create_or_update_file" \| "create_pull_request" \| "create_pull_request_with_copilot" \| "create_repository" \| "delete_file" \| "fork_repository" \| "get_commit" \| "get_copilot_job_status" \| "get_file_contents" \| "get_label" \| "get_latest_release" \| "get_release_by_tag" \| "get_tag" \| "get_team_members" \| "get_teams" \| "issue_read" \| "issue_write" \| "list_branches" \| "list_commits" \| "list_issue_types" \| "list_issues" \| "list_pull_requests" \| "list_releases" \| "list_tags" \| "merge_pull_request" \| "pull_request_read" \| "pull_request_review_write" \| "push_files" \| "request_copilot_review" \| "run_secret_scanning" \| "search_code" \| "search_issues" \| "search_pull_requests" \| "search_repositories" \| "search_users" \| "sub_issue_write" \| "update_pull_request" \| "update_pull_request_branch" | No | | +| Parameter | Name | Type | Required | Description | +| --- | --- | --- | --- | --- | +| tools | | "add_comment_to_pending_review" \| "add_issue_comment" \| "add_reply_to_pull_request_comment" \| "assign_copilot_to_issue" \| "create_branch" \| "create_or_update_file" \| "create_pull_request" \| "create_pull_request_with_copilot" \| "create_repository" \| "delete_file" \| "fork_repository" \| "get_commit" \| "get_copilot_job_status" \| "get_file_contents" \| "get_label" \| "get_latest_release" \| "get_release_by_tag" \| "get_tag" \| "get_team_members" \| "get_teams" \| "issue_read" \| "issue_write" \| "list_branches" \| "list_commits" \| "list_issue_types" \| "list_issues" \| "list_pull_requests" \| "list_releases" \| "list_tags" \| "merge_pull_request" \| "pull_request_read" \| "pull_request_review_write" \| "push_files" \| "request_copilot_review" \| "run_secret_scanning" \| "search_code" \| "search_issues" \| "search_pull_requests" \| "search_repositories" \| "search_users" \| "sub_issue_write" \| "update_pull_request" \| "update_pull_request_branch" | No | | Return Type: [AI_TOOL](./types.mdx#ai_tool) diff --git a/package-lock.json b/package-lock.json index 3c7c57c..da6387a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ ], "dependencies": { "@code0-tech/hercules": "^0.0.3", + "@code0-tech/tucana": "^0.0.68", "axios": "^1.13.6", "vite": "^7.3.1", "zod": "^4.3.6", @@ -188,12 +189,18 @@ "pino-pretty": "^13.1.3" } }, - "node_modules/@code0-tech/tucana": { + "node_modules/@code0-tech/hercules/node_modules/@code0-tech/tucana": { "version": "0.0.67", "resolved": "https://registry.npmjs.org/@code0-tech/tucana/-/tucana-0.0.67.tgz", "integrity": "sha512-3V1h3LB+iWeXnt80nsIQo+TeMgVTgbDxvDsAArbffHyU37ii1tsAAV6Ty7wAdkrCSsObyFRpdiIZgzgYVVKfzw==", "license": "Apache-2.0" }, + "node_modules/@code0-tech/tucana": { + "version": "0.0.68", + "resolved": "https://registry.npmjs.org/@code0-tech/tucana/-/tucana-0.0.68.tgz", + "integrity": "sha512-kbjLiKjJyZLnPmNi5JabWRNZcWZyXnfnld8jCFrUkvKbGj77CAwggR0uH8SqaxwWNWqQZlavYzCZWO/ob3+uKA==", + "license": "Apache-2.0" + }, "node_modules/@esbuild/aix-ppc64": { "version": "0.27.3", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.3.tgz", diff --git a/package.json b/package.json index d40e567..fa95bcc 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ }, "dependencies": { "@code0-tech/hercules": "^0.0.3", + "@code0-tech/tucana": "^0.0.68", "axios": "^1.13.6", "vite": "^7.3.1", "zod": "^4.3.6", diff --git a/src/standardActionDocs.ts b/src/standardActionDocs.ts index 366b77b..7734788 100644 --- a/src/standardActionDocs.ts +++ b/src/standardActionDocs.ts @@ -8,7 +8,7 @@ import { import {Project, SymbolFlags, Type} from "ts-morph" interface Translation { - code?: string + code?: "en-US" | "de-DE" | string content?: string }