lua-cli 3.5.0-alpha.3 → 3.5.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -689
- package/dist/api/agent.api.service.d.ts +1 -8
- package/dist/api/agent.api.service.js +1 -11
- package/dist/api/agent.api.service.js.map +1 -1
- package/dist/api/auth.api.service.d.ts +1 -1
- package/dist/api/auth.api.service.js +1 -1
- package/dist/api/auth.api.service.js.map +1 -1
- package/dist/api/backup.api.service.d.ts +80 -0
- package/dist/api/backup.api.service.js +101 -0
- package/dist/api/backup.api.service.js.map +1 -0
- package/dist/api/basket.api.service.d.ts +4 -5
- package/dist/api/basket.api.service.js +13 -18
- package/dist/api/basket.api.service.js.map +1 -1
- package/dist/api/cdn.api.service.d.ts +2 -0
- package/dist/api/cdn.api.service.js +2 -0
- package/dist/api/cdn.api.service.js.map +1 -1
- package/dist/api/chat.api.service.d.ts +10 -2
- package/dist/api/chat.api.service.js +21 -2
- package/dist/api/chat.api.service.js.map +1 -1
- package/dist/api/credentials.js +5 -8
- package/dist/api/credentials.js.map +1 -1
- package/dist/api/custom.data.api.service.d.ts +3 -3
- package/dist/api/custom.data.api.service.js +9 -10
- package/dist/api/custom.data.api.service.js.map +1 -1
- package/dist/api/developer.api.service.d.ts +1 -1
- package/dist/api/developer.api.service.js +1 -1
- package/dist/api/developer.api.service.js.map +1 -1
- package/dist/api/http.client.js.map +1 -0
- package/dist/api/job.api.service.d.ts +2 -2
- package/dist/api/job.api.service.js +2 -2
- package/dist/api/job.api.service.js.map +1 -1
- package/dist/api/logs.api.service.d.ts +1 -1
- package/dist/api/logs.api.service.js +1 -1
- package/dist/api/logs.api.service.js.map +1 -1
- package/dist/api/marketplace.api.service.d.ts +6 -6
- package/dist/api/marketplace.api.service.js.map +1 -1
- package/dist/api/order.api.service.d.ts +3 -4
- package/dist/api/order.api.service.js +8 -10
- package/dist/api/order.api.service.js.map +1 -1
- package/dist/api/persona.api.service.d.ts +1 -1
- package/dist/api/persona.api.service.js +1 -1
- package/dist/api/persona.api.service.js.map +1 -1
- package/dist/api/postprocessor.api.service.d.ts +1 -1
- package/dist/api/postprocessor.api.service.js +1 -1
- package/dist/api/postprocessor.api.service.js.map +1 -1
- package/dist/api/preprocessor.api.service.d.ts +1 -1
- package/dist/api/preprocessor.api.service.js +1 -1
- package/dist/api/preprocessor.api.service.js.map +1 -1
- package/dist/api/products.api.service.d.ts +4 -4
- package/dist/api/products.api.service.js +6 -6
- package/dist/api/products.api.service.js.map +1 -1
- package/dist/api/resource.api.service.d.ts +76 -0
- package/dist/api/resource.api.service.js +74 -0
- package/dist/api/resource.api.service.js.map +1 -0
- package/dist/api/skills.api.service.d.ts +7 -15
- package/dist/api/skills.api.service.js +1 -1
- package/dist/api/skills.api.service.js.map +1 -1
- package/dist/api/tool.api.service.d.ts +1 -1
- package/dist/api/tool.api.service.js +1 -1
- package/dist/api/tool.api.service.js.map +1 -1
- package/dist/api/unifiedto.api.service.d.ts +1 -1
- package/dist/api/unifiedto.api.service.js +1 -1
- package/dist/api/unifiedto.api.service.js.map +1 -1
- package/dist/api/user.data.api.service.d.ts +7 -8
- package/dist/api/user.data.api.service.js +2 -3
- package/dist/api/user.data.api.service.js.map +1 -1
- package/dist/api/webhook.api.service.d.ts +1 -1
- package/dist/api/webhook.api.service.js +1 -1
- package/dist/api/webhook.api.service.js.map +1 -1
- package/dist/api/whatsapp-templates.api.service.d.ts +1 -1
- package/dist/api/whatsapp-templates.api.service.js +1 -1
- package/dist/api/whatsapp-templates.api.service.js.map +1 -1
- package/dist/api-exports.d.ts +14 -12
- package/dist/api-exports.js +8 -8
- package/dist/api-exports.js.map +1 -1
- package/dist/cli/command-definitions.js +32 -17
- package/dist/cli/command-definitions.js.map +1 -1
- package/dist/commands/admin.js +3 -24
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/agents.d.ts +8 -7
- package/dist/commands/agents.js +63 -21
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/channels.js +11 -23
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/chat.js +33 -47
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/chatClear.js +11 -41
- package/dist/commands/chatClear.js.map +1 -1
- package/dist/commands/compile.d.ts +26 -23
- package/dist/commands/compile.js +98 -403
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/completion.js +1 -1
- package/dist/commands/completion.js.map +1 -1
- package/dist/commands/deploy.js +55 -25
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.js +29 -45
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/env.js +12 -25
- package/dist/commands/env.js.map +1 -1
- package/dist/commands/evals.js +3 -20
- package/dist/commands/evals.js.map +1 -1
- package/dist/commands/features.js +10 -23
- package/dist/commands/features.js.map +1 -1
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.js +1 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +135 -19
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/integrations.js +26 -37
- package/dist/commands/integrations.js.map +1 -1
- package/dist/commands/jobs.js +32 -56
- package/dist/commands/jobs.js.map +1 -1
- package/dist/commands/logs.js +9 -20
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/marketplace.js +34 -52
- package/dist/commands/marketplace.js.map +1 -1
- package/dist/commands/mcp.js +10 -23
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/persona.js +43 -74
- package/dist/commands/persona.js.map +1 -1
- package/dist/commands/postprocessors.js +15 -28
- package/dist/commands/postprocessors.js.map +1 -1
- package/dist/commands/preprocessors.js +15 -28
- package/dist/commands/preprocessors.js.map +1 -1
- package/dist/commands/production.js +30 -63
- package/dist/commands/production.js.map +1 -1
- package/dist/commands/push.js +294 -1241
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/pushBackup.d.ts +22 -0
- package/dist/commands/pushBackup.js +133 -0
- package/dist/commands/pushBackup.js.map +1 -0
- package/dist/commands/resources.js +29 -72
- package/dist/commands/resources.js.map +1 -1
- package/dist/commands/skills.d.ts +1 -1
- package/dist/commands/skills.js +58 -70
- package/dist/commands/skills.js.map +1 -1
- package/dist/commands/sync.d.ts +1 -3
- package/dist/commands/sync.js +12 -24
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/test.js +135 -104
- package/dist/commands/test.js.map +1 -1
- package/dist/commands/webhooks.js +15 -28
- package/dist/commands/webhooks.js.map +1 -1
- package/dist/compiler/agent-traverser.d.ts +104 -0
- package/dist/compiler/agent-traverser.js +311 -0
- package/dist/compiler/agent-traverser.js.map +1 -0
- package/dist/compiler/bundler.d.ts +42 -0
- package/dist/compiler/bundler.js +187 -0
- package/dist/compiler/bundler.js.map +1 -0
- package/dist/compiler/compiler.d.ts +177 -0
- package/dist/compiler/compiler.js +580 -0
- package/dist/compiler/compiler.js.map +1 -0
- package/dist/compiler/index.d.ts +36 -0
- package/dist/compiler/index.js +42 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/plugins/base.d.ts +264 -0
- package/dist/compiler/plugins/base.js +307 -0
- package/dist/compiler/plugins/base.js.map +1 -0
- package/dist/compiler/plugins/job.plugin.d.ts +33 -0
- package/dist/compiler/plugins/job.plugin.js +143 -0
- package/dist/compiler/plugins/job.plugin.js.map +1 -0
- package/dist/compiler/plugins/mcp-server.plugin.d.ts +50 -0
- package/dist/compiler/plugins/mcp-server.plugin.js +186 -0
- package/dist/compiler/plugins/mcp-server.plugin.js.map +1 -0
- package/dist/compiler/plugins/postprocessor.plugin.d.ts +20 -0
- package/dist/compiler/plugins/postprocessor.plugin.js +39 -0
- package/dist/compiler/plugins/postprocessor.plugin.js.map +1 -0
- package/dist/compiler/plugins/preprocessor.plugin.d.ts +20 -0
- package/dist/compiler/plugins/preprocessor.plugin.js +48 -0
- package/dist/compiler/plugins/preprocessor.plugin.js.map +1 -0
- package/dist/compiler/plugins/processor-base.d.ts +16 -0
- package/dist/compiler/plugins/processor-base.js +34 -0
- package/dist/compiler/plugins/processor-base.js.map +1 -0
- package/dist/compiler/plugins/registry.d.ts +61 -0
- package/dist/compiler/plugins/registry.js +107 -0
- package/dist/compiler/plugins/registry.js.map +1 -0
- package/dist/compiler/plugins/skill.plugin.d.ts +71 -0
- package/dist/compiler/plugins/skill.plugin.js +243 -0
- package/dist/compiler/plugins/skill.plugin.js.map +1 -0
- package/dist/compiler/plugins/tool.plugin.d.ts +67 -0
- package/dist/compiler/plugins/tool.plugin.js +279 -0
- package/dist/compiler/plugins/tool.plugin.js.map +1 -0
- package/dist/compiler/plugins/webhook.plugin.d.ts +37 -0
- package/dist/compiler/plugins/webhook.plugin.js +127 -0
- package/dist/compiler/plugins/webhook.plugin.js.map +1 -0
- package/dist/compiler/source-writer.d.ts +98 -0
- package/dist/compiler/source-writer.js +223 -0
- package/dist/compiler/source-writer.js.map +1 -0
- package/dist/compiler/types.d.ts +289 -0
- package/dist/compiler/types.js +20 -0
- package/dist/compiler/types.js.map +1 -0
- package/dist/compiler/utils/ast-helpers.d.ts +57 -0
- package/dist/compiler/utils/ast-helpers.js +164 -0
- package/dist/compiler/utils/ast-helpers.js.map +1 -0
- package/dist/compiler/utils/common.d.ts +23 -0
- package/dist/compiler/utils/common.js +66 -0
- package/dist/compiler/utils/common.js.map +1 -0
- package/dist/compiler/utils/file-discovery.d.ts +34 -0
- package/dist/compiler/utils/file-discovery.js +68 -0
- package/dist/compiler/utils/file-discovery.js.map +1 -0
- package/dist/compiler/utils/path-resolver.d.ts +25 -0
- package/dist/compiler/utils/path-resolver.js +66 -0
- package/dist/compiler/utils/path-resolver.js.map +1 -0
- package/dist/compiler/utils/schema-converter.d.ts +26 -0
- package/dist/compiler/utils/schema-converter.js +94 -0
- package/dist/compiler/utils/schema-converter.js.map +1 -0
- package/dist/config/compile.constants.d.ts +2 -22
- package/dist/config/compile.constants.js +2 -49
- package/dist/config/compile.constants.js.map +1 -1
- package/dist/config/constants.d.ts +18 -2
- package/dist/config/constants.js +28 -8
- package/dist/config/constants.js.map +1 -1
- package/dist/config/dev.constants.d.ts +0 -10
- package/dist/config/dev.constants.js +0 -10
- package/dist/config/dev.constants.js.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/instances/basket.instance.js.map +1 -0
- package/dist/instances/data.entry.instance.js.map +1 -0
- package/dist/instances/job.instance.js.map +1 -0
- package/dist/instances/order.instance.js.map +1 -0
- package/dist/instances/product.instance.js.map +1 -0
- package/dist/instances/product.pagination.instance.js.map +1 -0
- package/dist/instances/product.search.instance.js.map +1 -0
- package/dist/instances/user.instance.js.map +1 -0
- package/dist/interfaces/admin.d.ts +0 -38
- package/dist/interfaces/backup.d.ts +125 -0
- package/dist/interfaces/backup.js +8 -0
- package/dist/interfaces/backup.js.map +1 -0
- package/dist/interfaces/baskets.d.ts +0 -56
- package/dist/interfaces/common.d.ts +1 -0
- package/dist/interfaces/deploy.d.ts +0 -15
- package/dist/interfaces/index.d.ts +1 -1
- package/dist/interfaces/marketplace.d.ts +51 -0
- package/dist/interfaces/marketplace.js +1 -1
- package/dist/interfaces/marketplace.js.map +1 -1
- package/dist/interfaces/message.d.ts +0 -3
- package/dist/interfaces/orders.d.ts +0 -24
- package/dist/interfaces/postprocessors.d.ts +0 -18
- package/dist/interfaces/preprocessors.d.ts +0 -18
- package/dist/interfaces/skills.d.ts +61 -0
- package/dist/interfaces/user.d.ts +25 -0
- package/dist/interfaces/webhooks.d.ts +0 -9
- package/dist/primitives/base.handler.d.ts +106 -0
- package/dist/primitives/base.handler.js +370 -0
- package/dist/primitives/base.handler.js.map +1 -0
- package/dist/primitives/index.d.ts +47 -0
- package/dist/primitives/index.js +78 -0
- package/dist/primitives/index.js.map +1 -0
- package/dist/primitives/job.handler.d.ts +52 -0
- package/dist/primitives/job.handler.js +118 -0
- package/dist/primitives/job.handler.js.map +1 -0
- package/dist/primitives/mcp-server.handler.d.ts +54 -0
- package/dist/primitives/mcp-server.handler.js +91 -0
- package/dist/primitives/mcp-server.handler.js.map +1 -0
- package/dist/primitives/postprocessor.handler.d.ts +49 -0
- package/dist/primitives/postprocessor.handler.js +81 -0
- package/dist/primitives/postprocessor.handler.js.map +1 -0
- package/dist/primitives/preprocessor.handler.d.ts +54 -0
- package/dist/primitives/preprocessor.handler.js +95 -0
- package/dist/primitives/preprocessor.handler.js.map +1 -0
- package/dist/primitives/skill.handler.d.ts +44 -0
- package/dist/primitives/skill.handler.js +192 -0
- package/dist/primitives/skill.handler.js.map +1 -0
- package/dist/primitives/types.d.ts +72 -0
- package/dist/primitives/types.js +17 -0
- package/dist/primitives/types.js.map +1 -0
- package/dist/primitives/webhook.handler.d.ts +50 -0
- package/dist/primitives/webhook.handler.js +96 -0
- package/dist/primitives/webhook.handler.js.map +1 -0
- package/dist/services/auth.js +1 -2
- package/dist/services/auth.js.map +1 -1
- package/dist/services/sandbox.service.d.ts +103 -0
- package/dist/services/sandbox.service.js +479 -0
- package/dist/services/sandbox.service.js.map +1 -0
- package/dist/types/api-contracts.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/skill.d.ts +8 -2
- package/dist/types/skill.js +8 -0
- package/dist/types/skill.js.map +1 -1
- package/dist/types/yaml.types.d.ts +69 -0
- package/dist/types/yaml.types.js +6 -0
- package/dist/types/yaml.types.js.map +1 -0
- package/dist/utils/artifact-loader.d.ts +108 -0
- package/dist/utils/artifact-loader.js +188 -0
- package/dist/utils/artifact-loader.js.map +1 -0
- package/dist/utils/backup-helpers.d.ts +122 -0
- package/dist/utils/backup-helpers.js +274 -0
- package/dist/utils/backup-helpers.js.map +1 -0
- package/dist/utils/cli.d.ts +8 -0
- package/dist/utils/cli.js +19 -2
- package/dist/utils/cli.js.map +1 -1
- package/dist/utils/command-utils.d.ts +42 -0
- package/dist/utils/command-utils.js +83 -0
- package/dist/utils/command-utils.js.map +1 -0
- package/dist/utils/deploy-helpers.d.ts +0 -29
- package/dist/utils/deploy-helpers.js +0 -70
- package/dist/utils/deploy-helpers.js.map +1 -1
- package/dist/utils/dev-api.d.ts +3 -99
- package/dist/utils/dev-api.js +3 -430
- package/dist/utils/dev-api.js.map +1 -1
- package/dist/utils/dev-server.d.ts +3 -1
- package/dist/utils/dev-server.js +69 -145
- package/dist/utils/dev-server.js.map +1 -1
- package/dist/utils/dev-watcher.d.ts +0 -1
- package/dist/utils/dev-watcher.js +23 -8
- package/dist/utils/dev-watcher.js.map +1 -1
- package/dist/utils/env-loader.utils.d.ts +10 -1
- package/dist/utils/env-loader.utils.js +39 -31
- package/dist/utils/env-loader.utils.js.map +1 -1
- package/dist/utils/files.d.ts +47 -3
- package/dist/utils/files.js +98 -40
- package/dist/utils/files.js.map +1 -1
- package/dist/utils/init-agent.js +1 -2
- package/dist/utils/init-agent.js.map +1 -1
- package/dist/utils/init-helpers.d.ts +2 -10
- package/dist/utils/init-helpers.js +9 -17
- package/dist/utils/init-helpers.js.map +1 -1
- package/dist/utils/init-prompts.d.ts +0 -8
- package/dist/utils/init-prompts.js +0 -22
- package/dist/utils/init-prompts.js.map +1 -1
- package/dist/utils/prompt-handler.d.ts +3 -0
- package/dist/utils/prompt-handler.js +13 -0
- package/dist/utils/prompt-handler.js.map +1 -1
- package/dist/utils/sandbox-storage.d.ts +6 -5
- package/dist/utils/sandbox-storage.js +12 -12
- package/dist/utils/sandbox-storage.js.map +1 -1
- package/dist/utils/sandbox.d.ts +7 -30
- package/dist/utils/sandbox.js +247 -223
- package/dist/utils/sandbox.js.map +1 -1
- package/dist/utils/semver.d.ts +12 -0
- package/dist/utils/semver.js +23 -0
- package/dist/utils/semver.js.map +1 -1
- package/dist/utils/sync-display.d.ts +9 -0
- package/dist/utils/sync-display.js +67 -0
- package/dist/utils/sync-display.js.map +1 -0
- package/dist/utils/sync-fetch.d.ts +23 -0
- package/dist/utils/sync-fetch.js +64 -0
- package/dist/utils/sync-fetch.js.map +1 -0
- package/dist/utils/sync-helpers.d.ts +4 -59
- package/dist/utils/sync-helpers.js +4 -206
- package/dist/utils/sync-helpers.js.map +1 -1
- package/dist/web/app.css +912 -186
- package/dist/web/app.js +46 -46
- package/docs/API_INDEX.md +100 -0
- package/docs/API_REFERENCE.md +773 -0
- package/docs/CLI_REFERENCE.md +924 -0
- package/docs/GETTING_STARTED.md +862 -0
- package/docs/README.md +270 -0
- package/docs/api/AI.md +882 -0
- package/docs/api/Baskets.md +511 -0
- package/docs/api/CDN.md +524 -0
- package/docs/api/Data.md +446 -0
- package/docs/api/Jobs.md +524 -0
- package/docs/api/LuaAgent.md +454 -0
- package/docs/api/LuaJob.md +604 -0
- package/docs/api/LuaSkill.md +396 -0
- package/docs/api/LuaTool.md +521 -0
- package/docs/api/LuaWebhook.md +601 -0
- package/docs/api/Orders.md +514 -0
- package/docs/api/PostProcessor.md +565 -0
- package/docs/api/PreProcessor.md +630 -0
- package/docs/api/Products.md +507 -0
- package/docs/api/Templates.md +662 -0
- package/docs/api/User.md +567 -0
- package/docs/archive/DEVELOPMENT_GUIDE_V1.md +1294 -0
- package/docs/compiler-v2/ASSESSMENT.md +205 -0
- package/docs/compiler-v2/TEST_PLAN.md +306 -0
- package/package.json +3 -7
- package/template/tsconfig.json +1 -1
- package/dist/common/basket.instance.js.map +0 -1
- package/dist/common/data.entry.instance.js.map +0 -1
- package/dist/common/http.client.js.map +0 -1
- package/dist/common/job.instance.js.map +0 -1
- package/dist/common/order.instance.js.map +0 -1
- package/dist/common/product.instance.js.map +0 -1
- package/dist/common/product.pagination.instance.js.map +0 -1
- package/dist/common/product.search.instance.js.map +0 -1
- package/dist/common/user.instance.js.map +0 -1
- package/dist/config/auth.constants.d.ts +0 -11
- package/dist/config/auth.constants.js +0 -12
- package/dist/config/auth.constants.js.map +0 -1
- package/dist/config/init.constants.d.ts +0 -15
- package/dist/config/init.constants.js +0 -20
- package/dist/config/init.constants.js.map +0 -1
- package/dist/interfaces/compile.d.ts +0 -12
- package/dist/interfaces/compile.js +0 -5
- package/dist/interfaces/compile.js.map +0 -1
- package/dist/types/compile.types.d.ts +0 -131
- package/dist/types/compile.types.js +0 -6
- package/dist/types/compile.types.js.map +0 -1
- package/dist/utils/agent-code-utils.d.ts +0 -25
- package/dist/utils/agent-code-utils.js +0 -107
- package/dist/utils/agent-code-utils.js.map +0 -1
- package/dist/utils/bundling.d.ts +0 -89
- package/dist/utils/bundling.js +0 -1068
- package/dist/utils/bundling.js.map +0 -1
- package/dist/utils/compile.d.ts +0 -116
- package/dist/utils/compile.js +0 -1062
- package/dist/utils/compile.js.map +0 -1
- package/dist/utils/deploy-api.d.ts +0 -26
- package/dist/utils/deploy-api.js +0 -54
- package/dist/utils/deploy-api.js.map +0 -1
- package/dist/utils/deployment.d.ts +0 -26
- package/dist/utils/deployment.js +0 -218
- package/dist/utils/deployment.js.map +0 -1
- package/dist/utils/dev-helpers.d.ts +0 -47
- package/dist/utils/dev-helpers.js +0 -82
- package/dist/utils/dev-helpers.js.map +0 -1
- package/dist/utils/job-management.d.ts +0 -27
- package/dist/utils/job-management.js +0 -248
- package/dist/utils/job-management.js.map +0 -1
- package/dist/utils/mcp-server-management.d.ts +0 -26
- package/dist/utils/mcp-server-management.js +0 -197
- package/dist/utils/mcp-server-management.js.map +0 -1
- package/dist/utils/postprocessor-management.d.ts +0 -9
- package/dist/utils/postprocessor-management.js +0 -117
- package/dist/utils/postprocessor-management.js.map +0 -1
- package/dist/utils/pre-bundle-jobs.d.ts +0 -27
- package/dist/utils/pre-bundle-jobs.js +0 -189
- package/dist/utils/pre-bundle-jobs.js.map +0 -1
- package/dist/utils/preprocessor-management.d.ts +0 -9
- package/dist/utils/preprocessor-management.js +0 -117
- package/dist/utils/preprocessor-management.js.map +0 -1
- package/dist/utils/push-api.d.ts +0 -15
- package/dist/utils/push-api.js +0 -49
- package/dist/utils/push-api.js.map +0 -1
- package/dist/utils/push-helpers.d.ts +0 -82
- package/dist/utils/push-helpers.js +0 -246
- package/dist/utils/push-helpers.js.map +0 -1
- package/dist/utils/skill-management.d.ts +0 -39
- package/dist/utils/skill-management.js +0 -299
- package/dist/utils/skill-management.js.map +0 -1
- package/dist/utils/test-helpers.d.ts +0 -33
- package/dist/utils/test-helpers.js +0 -84
- package/dist/utils/test-helpers.js.map +0 -1
- package/dist/utils/test-prompts.d.ts +0 -23
- package/dist/utils/test-prompts.js +0 -187
- package/dist/utils/test-prompts.js.map +0 -1
- package/dist/utils/tool-detection.d.ts +0 -19
- package/dist/utils/tool-detection.js +0 -125
- package/dist/utils/tool-detection.js.map +0 -1
- package/dist/utils/webhook-management.d.ts +0 -27
- package/dist/utils/webhook-management.js +0 -241
- package/dist/utils/webhook-management.js.map +0 -1
- /package/dist/{common → api}/http.client.d.ts +0 -0
- /package/dist/{common → api}/http.client.js +0 -0
- /package/dist/{common → instances}/basket.instance.d.ts +0 -0
- /package/dist/{common → instances}/basket.instance.js +0 -0
- /package/dist/{common → instances}/data.entry.instance.d.ts +0 -0
- /package/dist/{common → instances}/data.entry.instance.js +0 -0
- /package/dist/{common → instances}/job.instance.d.ts +0 -0
- /package/dist/{common → instances}/job.instance.js +0 -0
- /package/dist/{common → instances}/order.instance.d.ts +0 -0
- /package/dist/{common → instances}/order.instance.js +0 -0
- /package/dist/{common → instances}/product.instance.d.ts +0 -0
- /package/dist/{common → instances}/product.instance.js +0 -0
- /package/dist/{common → instances}/product.pagination.instance.d.ts +0 -0
- /package/dist/{common → instances}/product.pagination.instance.js +0 -0
- /package/dist/{common → instances}/product.search.instance.d.ts +0 -0
- /package/dist/{common → instances}/product.search.instance.js +0 -0
- /package/dist/{common → instances}/user.instance.d.ts +0 -0
- /package/dist/{common → instances}/user.instance.js +0 -0
package/dist/utils/bundling.js
DELETED
|
@@ -1,1068 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bundling Utilities
|
|
3
|
-
* Handles esbuild bundling of tools and main index
|
|
4
|
-
*/
|
|
5
|
-
import fs from "fs";
|
|
6
|
-
import path from "path";
|
|
7
|
-
import { build } from "esbuild";
|
|
8
|
-
import { Project, Node } from "ts-morph";
|
|
9
|
-
import { writeProgress } from "./cli.js";
|
|
10
|
-
import { COMPILE_DIRS, COMPILE_FILES, ESBUILD_TOOL_CONFIG, ESBUILD_INDEX_CONFIG, DEFAULT_INPUT_SCHEMA, EXTERNAL_PACKAGES, } from '../config/compile.constants.js';
|
|
11
|
-
import { wrapExecuteForVM, wrapConditionForVM, evaluateZodSchemaToJsonSchema } from './compile.js';
|
|
12
|
-
import { evaluate } from 'ts-evaluator';
|
|
13
|
-
import ts from 'typescript';
|
|
14
|
-
/**
|
|
15
|
-
* Helper function to remove lua-cli and api-exports imports from source code.
|
|
16
|
-
* Used when bundling via stdin or temp files where the plugin can't process them.
|
|
17
|
-
*/
|
|
18
|
-
function stripLuaCliImports(sourceCode) {
|
|
19
|
-
return sourceCode
|
|
20
|
-
// Remove api-exports imports
|
|
21
|
-
.replace(/import\s+{([^}]+)}\s+from\s+["'][^"']*api-exports["'];?/g, '// api-exports imports removed - using sandbox globals')
|
|
22
|
-
// Remove lua-cli imports
|
|
23
|
-
.replace(/import\s+{([^}]+)}\s+from\s+["']lua-cli["'];?/g, '// lua-cli imports removed - using sandbox globals')
|
|
24
|
-
// Remove lua-cli/skill imports (but keep LuaTool, etc. for type checking in temp files)
|
|
25
|
-
.replace(/import\s+{([^}]+)}\s+from\s+["']lua-cli\/skill["'];?/g, (match, imports) => {
|
|
26
|
-
// Keep only LuaTool, LuaWebhook, LuaJob types for temp files
|
|
27
|
-
const typeImports = imports.split(',')
|
|
28
|
-
.map((imp) => imp.trim())
|
|
29
|
-
.filter((imp) => /^(LuaTool|LuaWebhook|LuaJob|LuaPreProcessor|LuaPostProcessor)$/.test(imp));
|
|
30
|
-
return typeImports.length > 0
|
|
31
|
-
? `// lua-cli/skill imports removed - using sandbox globals (types kept for compilation)`
|
|
32
|
-
: '// lua-cli/skill imports removed - using sandbox globals';
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Extracts and filters relevant imports from source code.
|
|
37
|
-
* Removes lua-cli internal classes and API imports that are available in the sandbox.
|
|
38
|
-
*
|
|
39
|
-
* @param sourceFilePath - Path to the source file
|
|
40
|
-
* @returns Array of relevant import statements
|
|
41
|
-
*/
|
|
42
|
-
function extractRelevantImports(sourceFilePath) {
|
|
43
|
-
const sourceContent = fs.readFileSync(sourceFilePath, 'utf8');
|
|
44
|
-
// Extract all import statements from the source
|
|
45
|
-
const importPattern = /^import\s+.+\s+from\s+['"][^'"]+['"];?$/gm;
|
|
46
|
-
const imports = sourceContent.match(importPattern) || [];
|
|
47
|
-
// Filter to only imports that might be used (exclude lua-cli internal classes and APIs)
|
|
48
|
-
return imports.filter(imp => !imp.includes('LuaTool') &&
|
|
49
|
-
!imp.includes('LuaWebhook') &&
|
|
50
|
-
!imp.includes('LuaJob') &&
|
|
51
|
-
!imp.includes('PreProcessor') &&
|
|
52
|
-
!imp.includes('PostProcessor') &&
|
|
53
|
-
!imp.includes('LuaAgent') &&
|
|
54
|
-
!imp.includes('lua-cli') && // Exclude all lua-cli imports (they're available in sandbox)
|
|
55
|
-
!imp.includes('api-exports') && // Exclude api-exports
|
|
56
|
-
!imp.includes('../../../dist/api-exports') // Exclude direct api-exports imports
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Generic function to bundle and compress execute function code with dependencies.
|
|
61
|
-
*
|
|
62
|
-
* @param executeFunction - Raw execute function code
|
|
63
|
-
* @param componentName - Name of the component (webhook/job/processor)
|
|
64
|
-
* @param componentType - Type identifier for temp files
|
|
65
|
-
* @param vmWrapperGenerator - Function that generates the VM wrapper code
|
|
66
|
-
* @param distDir - Distribution directory
|
|
67
|
-
* @param sourceFilePath - Path to source file containing the component
|
|
68
|
-
* @param debugMode - Enable verbose logging and preserve temp files
|
|
69
|
-
* @returns Compressed base64-encoded bundled code
|
|
70
|
-
*/
|
|
71
|
-
async function bundleAndCompressExecuteFunction(executeFunction, componentName, componentType, vmWrapperGenerator, distDir, sourceFilePath, debugMode) {
|
|
72
|
-
const { compressCode } = await import('./compile.js');
|
|
73
|
-
// Create temporary file with the execute function wrapped as a module
|
|
74
|
-
const tempDir = path.join(distDir, '.temp');
|
|
75
|
-
if (!fs.existsSync(tempDir)) {
|
|
76
|
-
fs.mkdirSync(tempDir, { recursive: true });
|
|
77
|
-
}
|
|
78
|
-
const tempFile = path.join(tempDir, `${componentName}-${componentType}.ts`);
|
|
79
|
-
const tempOutput = path.join(tempDir, `${componentName}-${componentType}.js`);
|
|
80
|
-
let moduleCode = ''; // Declare outside try block for debug mode access
|
|
81
|
-
try {
|
|
82
|
-
// Extract relevant imports from source file
|
|
83
|
-
const relevantImports = extractRelevantImports(sourceFilePath);
|
|
84
|
-
if (debugMode) {
|
|
85
|
-
console.log(` → Found ${relevantImports.length} import(s) to bundle`);
|
|
86
|
-
if (relevantImports.length > 0 && debugMode) {
|
|
87
|
-
relevantImports.forEach(imp => console.log(` - ${imp}`));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Write execute function as a module export with all relevant imports
|
|
91
|
-
moduleCode = `
|
|
92
|
-
// ${componentType} execute function for ${componentName}
|
|
93
|
-
${relevantImports.join('\n')}
|
|
94
|
-
|
|
95
|
-
// The execute function with all dependencies available
|
|
96
|
-
const executeFunc = ${executeFunction};
|
|
97
|
-
|
|
98
|
-
export default executeFunc;
|
|
99
|
-
`;
|
|
100
|
-
if (debugMode) {
|
|
101
|
-
console.log(` → Using stdin bundling to preserve import resolution`);
|
|
102
|
-
}
|
|
103
|
-
// Bundle with esbuild using stdin to preserve import resolution
|
|
104
|
-
// This ensures relative imports resolve correctly from the original source file location
|
|
105
|
-
await build({
|
|
106
|
-
stdin: {
|
|
107
|
-
contents: moduleCode,
|
|
108
|
-
resolveDir: path.dirname(sourceFilePath), // Resolve imports from source file's directory
|
|
109
|
-
sourcefile: sourceFilePath, // Pretend we're the source file for better error messages
|
|
110
|
-
loader: 'ts',
|
|
111
|
-
},
|
|
112
|
-
bundle: true,
|
|
113
|
-
platform: 'node',
|
|
114
|
-
target: 'node16',
|
|
115
|
-
format: 'cjs',
|
|
116
|
-
minify: true,
|
|
117
|
-
outfile: tempOutput,
|
|
118
|
-
external: [...EXTERNAL_PACKAGES], // Use same external packages as tools
|
|
119
|
-
plugins: [sandboxGlobalsPlugin],
|
|
120
|
-
});
|
|
121
|
-
// Read bundled code and validate it exists and has content
|
|
122
|
-
if (!fs.existsSync(tempOutput)) {
|
|
123
|
-
throw new Error(`esbuild failed to create output file for ${componentName}`);
|
|
124
|
-
}
|
|
125
|
-
const bundledCode = fs.readFileSync(tempOutput, 'utf8');
|
|
126
|
-
if (bundledCode.length === 0) {
|
|
127
|
-
throw new Error(`esbuild created empty bundle for ${componentName}`);
|
|
128
|
-
}
|
|
129
|
-
// Wrap for VM execution using provided generator
|
|
130
|
-
const wrappedCode = vmWrapperGenerator(bundledCode);
|
|
131
|
-
// Compress the wrapped code
|
|
132
|
-
const compressed = compressCode(wrappedCode);
|
|
133
|
-
if (debugMode) {
|
|
134
|
-
console.log(` → Bundle size: ${(bundledCode.length / 1024).toFixed(2)}KB (uncompressed)`);
|
|
135
|
-
console.log(` → Compressed: ${(compressed.length / 1024).toFixed(2)}KB (base64 gzip)`);
|
|
136
|
-
}
|
|
137
|
-
// Clean up temp files (unless in debug mode)
|
|
138
|
-
if (!debugMode) {
|
|
139
|
-
try {
|
|
140
|
-
fs.unlinkSync(tempOutput);
|
|
141
|
-
}
|
|
142
|
-
catch (cleanupError) {
|
|
143
|
-
// Ignore cleanup errors
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
// In debug mode, write the moduleCode to tempFile for inspection
|
|
148
|
-
fs.writeFileSync(tempFile, moduleCode);
|
|
149
|
-
console.log(` ℹ️ Preserved temp files for debugging:`);
|
|
150
|
-
console.log(` - ${tempFile} (source with imports)`);
|
|
151
|
-
console.log(` - ${tempOutput} (bundled output)`);
|
|
152
|
-
}
|
|
153
|
-
return compressed;
|
|
154
|
-
}
|
|
155
|
-
catch (error) {
|
|
156
|
-
// Provide helpful error messages based on error type
|
|
157
|
-
let errorMessage = `Warning: Could not bundle ${componentType} ${componentName}`;
|
|
158
|
-
if (error.message && error.message.includes('Could not resolve')) {
|
|
159
|
-
errorMessage += `\n Dependency resolution failed: ${error.message}`;
|
|
160
|
-
// Check if it's a relative import issue
|
|
161
|
-
if (error.message.includes('"../') || error.message.includes('"./')) {
|
|
162
|
-
errorMessage += `\n Hint: Relative imports detected. Consider using TypeScript path aliases (e.g., @/services/...)`;
|
|
163
|
-
errorMessage += `\n Or ensure the import path is correct relative to: ${path.dirname(sourceFilePath)}`;
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
errorMessage += `\n Hint: Ensure all imported packages are in package.json and run 'npm install'`;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else if (error.message && error.message.includes('Transform failed')) {
|
|
170
|
-
errorMessage += `\n TypeScript compilation failed: ${error.message}`;
|
|
171
|
-
errorMessage += `\n Hint: Check syntax in ${path.basename(sourceFilePath)}`;
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
errorMessage += `: ${error.message || error}`;
|
|
175
|
-
}
|
|
176
|
-
console.warn(errorMessage);
|
|
177
|
-
if (debugMode && error.stack) {
|
|
178
|
-
console.error(' Full stack trace:', error.stack);
|
|
179
|
-
}
|
|
180
|
-
// Clean up on error (unless in debug mode)
|
|
181
|
-
if (!debugMode) {
|
|
182
|
-
try {
|
|
183
|
-
if (fs.existsSync(tempOutput))
|
|
184
|
-
fs.unlinkSync(tempOutput);
|
|
185
|
-
}
|
|
186
|
-
catch (cleanupError) {
|
|
187
|
-
// Ignore cleanup errors
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
// In debug mode, write the moduleCode for inspection
|
|
192
|
-
try {
|
|
193
|
-
fs.writeFileSync(tempFile, moduleCode);
|
|
194
|
-
console.log(` ℹ️ Temp files preserved for debugging (check dist/.temp/)`);
|
|
195
|
-
}
|
|
196
|
-
catch (writeError) {
|
|
197
|
-
// Ignore write errors
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return '';
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* esbuild plugin to inject sandbox globals instead of requiring lua-cli
|
|
205
|
-
* This removes require("lua-cli") statements and injects the global API objects
|
|
206
|
-
* that are available in the sandbox (Products, User, Data, Baskets, Orders, Webhooks, Jobs)
|
|
207
|
-
*/
|
|
208
|
-
export const sandboxGlobalsPlugin = {
|
|
209
|
-
name: 'sandbox-globals',
|
|
210
|
-
setup(build) {
|
|
211
|
-
// Only process user files, not node_modules
|
|
212
|
-
build.onLoad({ filter: /\.([jt]sx?)$/, namespace: 'file' }, async (args) => {
|
|
213
|
-
// Skip node_modules
|
|
214
|
-
if (args.path.includes('node_modules')) {
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
const contents = await fs.promises.readFile(args.path, 'utf8');
|
|
218
|
-
// Only transform files that import from lua-cli or api-exports
|
|
219
|
-
if (!contents.includes('lua-cli') && !contents.includes('api-exports')) {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
// Replace lua-cli imports with global references
|
|
223
|
-
let transformedContents = contents;
|
|
224
|
-
// Replace named imports from api-exports (e.g., ../../../dist/api-exports)
|
|
225
|
-
// Match: import { Jobs, Products, etc. } from "../../../dist/api-exports"
|
|
226
|
-
transformedContents = transformedContents.replace(/import\s+{([^}]+)}\s+from\s+["'][^"']*api-exports["'];?/g, (match, imports) => {
|
|
227
|
-
// Just remove the import, globals will be available in sandbox
|
|
228
|
-
return '// api-exports imports removed - using sandbox globals';
|
|
229
|
-
});
|
|
230
|
-
// Replace named imports from lua-cli
|
|
231
|
-
// Match: import { Products, User, Data, etc. } from "lua-cli"
|
|
232
|
-
transformedContents = transformedContents.replace(/import\s+{([^}]+)}\s+from\s+["']lua-cli["'];?/g, (match, imports) => {
|
|
233
|
-
// Just remove the import, globals will be available in sandbox
|
|
234
|
-
return '// lua-cli imports removed - using sandbox globals';
|
|
235
|
-
});
|
|
236
|
-
// Replace lua-cli/skill imports - keep env and LuaTool as they might be needed
|
|
237
|
-
transformedContents = transformedContents.replace(/import\s+{([^}]+)}\s+from\s+["']lua-cli\/skill["'];?/g, (match, imports) => {
|
|
238
|
-
// Check if env is imported, if so we need to keep a reference
|
|
239
|
-
if (imports.includes('env')) {
|
|
240
|
-
return '// lua-cli/skill imports removed - env available in sandbox';
|
|
241
|
-
}
|
|
242
|
-
return '// lua-cli/skill imports removed - using sandbox globals';
|
|
243
|
-
});
|
|
244
|
-
// Map import names to sandbox global names
|
|
245
|
-
// Products -> Product, Orders -> Order, etc.
|
|
246
|
-
const globalMappings = {
|
|
247
|
-
'Products': 'Products',
|
|
248
|
-
'User': 'User',
|
|
249
|
-
'Data': 'Data',
|
|
250
|
-
'Baskets': 'Baskets',
|
|
251
|
-
'Orders': 'Orders',
|
|
252
|
-
'Webhooks': 'Webhooks',
|
|
253
|
-
'Jobs': 'Jobs',
|
|
254
|
-
'Templates': 'Templates'
|
|
255
|
-
};
|
|
256
|
-
// Replace usage of imported names with globals
|
|
257
|
-
for (const [importName, globalName] of Object.entries(globalMappings)) {
|
|
258
|
-
// Replace standalone usage (e.g., Products.method() -> Product.method())
|
|
259
|
-
const regex = new RegExp(`\\b${importName}\\.`, 'g');
|
|
260
|
-
transformedContents = transformedContents.replace(regex, `${globalName}.`);
|
|
261
|
-
}
|
|
262
|
-
// Note: env function and LuaTool interface are already available in sandbox
|
|
263
|
-
// env is a function in the sandbox context (see sandbox.ts line 333)
|
|
264
|
-
return {
|
|
265
|
-
contents: transformedContents,
|
|
266
|
-
loader: args.path.endsWith('.ts') ? 'ts' :
|
|
267
|
-
args.path.endsWith('.tsx') ? 'tsx' : 'js'
|
|
268
|
-
};
|
|
269
|
-
});
|
|
270
|
-
},
|
|
271
|
-
};
|
|
272
|
-
/**
|
|
273
|
-
* Bundles a tool's TypeScript code into a standalone JavaScript file.
|
|
274
|
-
* Uses esbuild to:
|
|
275
|
-
* - Bundle all dependencies (except external packages)
|
|
276
|
-
* - Minify code for production
|
|
277
|
-
* - Wrap for VM execution
|
|
278
|
-
*
|
|
279
|
-
* For inline tools (defined in index.ts), creates a temporary export file first.
|
|
280
|
-
*
|
|
281
|
-
* @param tool - The tool to bundle
|
|
282
|
-
* @param distDir - The distribution directory for output
|
|
283
|
-
* @param modifiedSource - Optional modified source (for pre-bundled jobs)
|
|
284
|
-
* @param debugMode - Enable verbose logging and preserve temp files
|
|
285
|
-
*/
|
|
286
|
-
export async function bundleTool(tool, distDir, modifiedSource, debugMode) {
|
|
287
|
-
if (!debugMode)
|
|
288
|
-
writeProgress(`📦 Bundling ${tool.className}...`);
|
|
289
|
-
if (debugMode)
|
|
290
|
-
console.log(` → Bundling ${tool.className}...`);
|
|
291
|
-
try {
|
|
292
|
-
const outputPath = path.join(distDir, COMPILE_DIRS.TOOLS, `${tool.className}.js`);
|
|
293
|
-
let entryPoint = tool.filePath;
|
|
294
|
-
let tempFile = null;
|
|
295
|
-
// Note: modifiedSource is handled via stdin below, no temp file needed
|
|
296
|
-
// Check if tool is inline (in index.ts or src/index.ts)
|
|
297
|
-
const isInlineInIndex = tool.filePath.endsWith('index.ts') || tool.filePath.endsWith('index.tsx');
|
|
298
|
-
if (isInlineInIndex) {
|
|
299
|
-
// Create a temporary file that exports just this tool class
|
|
300
|
-
const tempDir = path.join(distDir, '.temp');
|
|
301
|
-
if (!fs.existsSync(tempDir)) {
|
|
302
|
-
fs.mkdirSync(tempDir, { recursive: true });
|
|
303
|
-
}
|
|
304
|
-
tempFile = path.join(tempDir, `${tool.className}.ts`);
|
|
305
|
-
// Read the source file and extract just the tool class
|
|
306
|
-
const sourceContent = fs.readFileSync(tool.filePath, 'utf8');
|
|
307
|
-
const project = new Project();
|
|
308
|
-
const sourceFile = project.addSourceFileAtPath(tool.filePath);
|
|
309
|
-
const classDecl = sourceFile.getClass(tool.className);
|
|
310
|
-
if (classDecl) {
|
|
311
|
-
// Get all imports from the original file that this class might need
|
|
312
|
-
const imports = sourceFile.getImportDeclarations();
|
|
313
|
-
let importsText = '';
|
|
314
|
-
// Include imports from lua-cli and zod (tools commonly need these)
|
|
315
|
-
imports.forEach(importDecl => {
|
|
316
|
-
const moduleSpec = importDecl.getModuleSpecifierValue();
|
|
317
|
-
if (moduleSpec === 'lua-cli' || moduleSpec === 'zod' || moduleSpec.startsWith('./')) {
|
|
318
|
-
importsText += importDecl.getText() + '\n';
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
// Create temporary file with imports and the tool class
|
|
322
|
-
const toolClassText = classDecl.getText();
|
|
323
|
-
const tempContent = `${importsText}\n${toolClassText}\n\nexport default ${tool.className};\n`;
|
|
324
|
-
fs.writeFileSync(tempFile, tempContent);
|
|
325
|
-
entryPoint = tempFile;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
// Use stdin for modified source to preserve import resolution
|
|
329
|
-
if (modifiedSource && !isInlineInIndex) {
|
|
330
|
-
// Remove api-exports and lua-cli imports (they're available in sandbox)
|
|
331
|
-
const transformedSource = stripLuaCliImports(modifiedSource);
|
|
332
|
-
await build({
|
|
333
|
-
...ESBUILD_TOOL_CONFIG,
|
|
334
|
-
stdin: {
|
|
335
|
-
contents: transformedSource,
|
|
336
|
-
resolveDir: path.dirname(tool.filePath),
|
|
337
|
-
sourcefile: tool.filePath,
|
|
338
|
-
loader: 'ts',
|
|
339
|
-
},
|
|
340
|
-
outfile: outputPath,
|
|
341
|
-
plugins: [sandboxGlobalsPlugin],
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
await build({
|
|
346
|
-
...ESBUILD_TOOL_CONFIG,
|
|
347
|
-
entryPoints: [entryPoint],
|
|
348
|
-
outfile: outputPath,
|
|
349
|
-
plugins: [sandboxGlobalsPlugin],
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
// Clean up temp file if created (unless in debug mode)
|
|
353
|
-
if (tempFile && fs.existsSync(tempFile) && !debugMode) {
|
|
354
|
-
try {
|
|
355
|
-
fs.unlinkSync(tempFile);
|
|
356
|
-
}
|
|
357
|
-
catch (cleanupError) {
|
|
358
|
-
// Ignore cleanup errors
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
else if (tempFile && debugMode) {
|
|
362
|
-
if (debugMode)
|
|
363
|
-
console.log(` ℹ️ Preserved temp file: ${tempFile}`);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
catch (error) {
|
|
367
|
-
console.warn(`Warning: Failed to bundle ${tool.className}:`, error);
|
|
368
|
-
if (debugMode && error instanceof Error) {
|
|
369
|
-
console.error(' Stack trace:', error.stack);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
/**
|
|
374
|
-
* Bundles the main index.ts file into a standalone JavaScript file.
|
|
375
|
-
* This creates the entry point for the skill.
|
|
376
|
-
*
|
|
377
|
-
* @param indexPath - Path to the index.ts file
|
|
378
|
-
* @param distDir - The distribution directory for output
|
|
379
|
-
*/
|
|
380
|
-
export async function bundleMainIndex(indexPath, distDir) {
|
|
381
|
-
writeProgress("📦 Bundling main index...");
|
|
382
|
-
try {
|
|
383
|
-
await build({
|
|
384
|
-
...ESBUILD_INDEX_CONFIG,
|
|
385
|
-
entryPoints: [indexPath],
|
|
386
|
-
outfile: path.join(distDir, COMPILE_FILES.INDEX_JS),
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
catch (error) {
|
|
390
|
-
console.warn("Warning: Failed to bundle main index:", error);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Extracts and bundles webhook execute function and schemas.
|
|
395
|
-
*
|
|
396
|
-
* @param webhook - Webhook metadata with name and version
|
|
397
|
-
* @param indexFile - The TypeScript source file containing the webhook
|
|
398
|
-
* @param distDir - Distribution directory for output
|
|
399
|
-
* @param project - Optional ts-morph Project for resolving imports
|
|
400
|
-
* @param debugMode - Enable verbose logging and preserve temp files
|
|
401
|
-
* @returns Webhook with bundled code and schemas
|
|
402
|
-
*/
|
|
403
|
-
export async function bundleWebhook(webhook, indexFile, distDir, project, debugMode) {
|
|
404
|
-
if (!debugMode)
|
|
405
|
-
writeProgress(`📦 Bundling webhook ${webhook.name}...`);
|
|
406
|
-
try {
|
|
407
|
-
// Find the LuaWebhook constructor in the AST
|
|
408
|
-
let executeFunction = '';
|
|
409
|
-
let querySchema = undefined;
|
|
410
|
-
let headerSchema = undefined;
|
|
411
|
-
let bodySchema = undefined;
|
|
412
|
-
let sourceFilePath = indexFile.getFilePath();
|
|
413
|
-
// Helper function to search for webhook in a file
|
|
414
|
-
const searchFileForWebhook = (file) => {
|
|
415
|
-
file.forEachDescendant((node) => {
|
|
416
|
-
if (Node.isNewExpression(node)) {
|
|
417
|
-
const expression = node.getExpression();
|
|
418
|
-
if (expression.getText() === 'LuaWebhook') {
|
|
419
|
-
const args = node.getArguments();
|
|
420
|
-
if (args.length > 0 && Node.isObjectLiteralExpression(args[0])) {
|
|
421
|
-
const configObj = args[0];
|
|
422
|
-
// First pass: check if this is the webhook we're looking for
|
|
423
|
-
let isMatchingWebhook = false;
|
|
424
|
-
let foundExecute = '';
|
|
425
|
-
let foundQuerySchema = undefined;
|
|
426
|
-
let foundHeaderSchema = undefined;
|
|
427
|
-
let foundBodySchema = undefined;
|
|
428
|
-
configObj.getProperties().forEach((prop) => {
|
|
429
|
-
if (Node.isPropertyAssignment(prop)) {
|
|
430
|
-
const name = prop.getName();
|
|
431
|
-
const value = prop.getInitializer();
|
|
432
|
-
if (name === 'name' && value) {
|
|
433
|
-
const nameValue = value.getText().replace(/['"]/g, '');
|
|
434
|
-
if (nameValue === webhook.name) {
|
|
435
|
-
isMatchingWebhook = true;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
if (name === 'execute' && value) {
|
|
439
|
-
foundExecute = value.getText();
|
|
440
|
-
}
|
|
441
|
-
else if (name === 'querySchema' && value) {
|
|
442
|
-
foundQuerySchema = value.getText();
|
|
443
|
-
}
|
|
444
|
-
else if (name === 'headerSchema' && value) {
|
|
445
|
-
foundHeaderSchema = value.getText();
|
|
446
|
-
}
|
|
447
|
-
else if (name === 'bodySchema' && value) {
|
|
448
|
-
foundBodySchema = value.getText();
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
});
|
|
452
|
-
// Only set values if this is the matching webhook
|
|
453
|
-
if (isMatchingWebhook) {
|
|
454
|
-
executeFunction = foundExecute;
|
|
455
|
-
querySchema = foundQuerySchema;
|
|
456
|
-
headerSchema = foundHeaderSchema;
|
|
457
|
-
bodySchema = foundBodySchema;
|
|
458
|
-
// Update source file path to the file where webhook was found
|
|
459
|
-
sourceFilePath = file.getFilePath();
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
};
|
|
466
|
-
// Search in index file first
|
|
467
|
-
searchFileForWebhook(indexFile);
|
|
468
|
-
// If not found and project is available, search in imported files
|
|
469
|
-
if (!executeFunction && project) {
|
|
470
|
-
const imports = indexFile.getImportDeclarations();
|
|
471
|
-
for (const importDecl of imports) {
|
|
472
|
-
try {
|
|
473
|
-
const moduleSpecifier = importDecl.getModuleSpecifierValue();
|
|
474
|
-
const { resolveImportPath } = await import('./compile.js');
|
|
475
|
-
const importPath = resolveImportPath(moduleSpecifier, indexFile.getFilePath());
|
|
476
|
-
if (fs.existsSync(importPath)) {
|
|
477
|
-
const importedFile = project.addSourceFileAtPath(importPath);
|
|
478
|
-
searchFileForWebhook(importedFile);
|
|
479
|
-
// If found, stop searching
|
|
480
|
-
if (executeFunction) {
|
|
481
|
-
break;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
catch (error) {
|
|
486
|
-
// Continue searching other imports
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
// Convert Zod schemas to JSON Schema
|
|
491
|
-
const convertedSchemas = {};
|
|
492
|
-
if (querySchema) {
|
|
493
|
-
convertedSchemas.querySchema = await evaluateZodSchemaToJsonSchema(querySchema);
|
|
494
|
-
}
|
|
495
|
-
if (headerSchema) {
|
|
496
|
-
convertedSchemas.headerSchema = await evaluateZodSchemaToJsonSchema(headerSchema);
|
|
497
|
-
}
|
|
498
|
-
if (bodySchema) {
|
|
499
|
-
convertedSchemas.bodySchema = await evaluateZodSchemaToJsonSchema(bodySchema);
|
|
500
|
-
}
|
|
501
|
-
// Bundle and compress the execute function (like tools)
|
|
502
|
-
let compressedCode = '';
|
|
503
|
-
if (executeFunction) {
|
|
504
|
-
compressedCode = await bundleAndCompressWebhookCode(executeFunction, webhook.name, distDir, sourceFilePath, debugMode);
|
|
505
|
-
}
|
|
506
|
-
return {
|
|
507
|
-
...webhook,
|
|
508
|
-
executeFunction,
|
|
509
|
-
code: compressedCode, // Add compressed bundled code
|
|
510
|
-
...convertedSchemas
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
catch (error) {
|
|
514
|
-
console.warn(`Warning: Could not bundle webhook ${webhook.name}:`, error);
|
|
515
|
-
return webhook;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
/**
|
|
519
|
-
* Bundles and compresses webhook execute function code.
|
|
520
|
-
* Creates a temporary file, bundles with esbuild, compresses with gzip.
|
|
521
|
-
* Includes all imports from the source file to ensure dependencies are bundled.
|
|
522
|
-
*
|
|
523
|
-
* @param executeFunction - Raw execute function code
|
|
524
|
-
* @param webhookName - Name of the webhook
|
|
525
|
-
* @param distDir - Distribution directory
|
|
526
|
-
* @param sourceFilePath - Path to the source file containing the webhook
|
|
527
|
-
* @param debugMode - Enable verbose logging and preserve temp files
|
|
528
|
-
* @returns Compressed base64-encoded bundled code
|
|
529
|
-
*/
|
|
530
|
-
async function bundleAndCompressWebhookCode(executeFunction, webhookName, distDir, sourceFilePath, debugMode) {
|
|
531
|
-
return bundleAndCompressExecuteFunction(executeFunction, webhookName, 'webhook', (bundledCode) => `(async (event) => {
|
|
532
|
-
|
|
533
|
-
// Execute the bundled webhook code
|
|
534
|
-
${bundledCode}
|
|
535
|
-
|
|
536
|
-
// Get the execute function from exports
|
|
537
|
-
const executeFunction = module.exports.default || module.exports;
|
|
538
|
-
|
|
539
|
-
// Execute with the unified event object
|
|
540
|
-
return await executeFunction(event);
|
|
541
|
-
})`, distDir, sourceFilePath, debugMode);
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Extracts and bundles job execute function.
|
|
545
|
-
*
|
|
546
|
-
* @param job - Job metadata with name and version
|
|
547
|
-
* @param indexFile - The TypeScript source file containing the job
|
|
548
|
-
* @param distDir - Distribution directory for output
|
|
549
|
-
* @param project - Optional ts-morph Project for resolving imports
|
|
550
|
-
* @param debugMode - Enable verbose logging and preserve temp files
|
|
551
|
-
* @returns Job with bundled code
|
|
552
|
-
*/
|
|
553
|
-
export async function bundleJob(job, indexFile, distDir, project, debugMode) {
|
|
554
|
-
if (!debugMode)
|
|
555
|
-
writeProgress(`📦 Bundling job ${job.name}...`);
|
|
556
|
-
try {
|
|
557
|
-
// Find the LuaJob constructor in the AST
|
|
558
|
-
let executeFunction = '';
|
|
559
|
-
let sourceFilePath = indexFile.getFilePath();
|
|
560
|
-
// Helper function to search for job in a file
|
|
561
|
-
const searchFileForJob = (file) => {
|
|
562
|
-
file.forEachDescendant((node) => {
|
|
563
|
-
if (Node.isNewExpression(node)) {
|
|
564
|
-
const expression = node.getExpression();
|
|
565
|
-
if (expression.getText() === 'LuaJob') {
|
|
566
|
-
const args = node.getArguments();
|
|
567
|
-
if (args.length > 0 && Node.isObjectLiteralExpression(args[0])) {
|
|
568
|
-
const configObj = args[0];
|
|
569
|
-
// First pass: check if this is the job we're looking for
|
|
570
|
-
let isMatchingJob = false;
|
|
571
|
-
let foundExecute = '';
|
|
572
|
-
configObj.getProperties().forEach((prop) => {
|
|
573
|
-
if (Node.isPropertyAssignment(prop)) {
|
|
574
|
-
const name = prop.getName();
|
|
575
|
-
const value = prop.getInitializer();
|
|
576
|
-
if (name === 'name' && value) {
|
|
577
|
-
const nameValue = value.getText().replace(/['"]/g, '');
|
|
578
|
-
if (nameValue === job.name) {
|
|
579
|
-
isMatchingJob = true;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
if (name === 'execute' && value) {
|
|
583
|
-
foundExecute = value.getText();
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
// Only set executeFunction if this is the matching job
|
|
588
|
-
if (isMatchingJob && foundExecute) {
|
|
589
|
-
executeFunction = foundExecute;
|
|
590
|
-
// Update source file path to the file where job was found
|
|
591
|
-
sourceFilePath = file.getFilePath();
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
});
|
|
597
|
-
};
|
|
598
|
-
// Search in index file first
|
|
599
|
-
searchFileForJob(indexFile);
|
|
600
|
-
// If not found and project is available, search in imported files
|
|
601
|
-
if (!executeFunction && project) {
|
|
602
|
-
const imports = indexFile.getImportDeclarations();
|
|
603
|
-
for (const importDecl of imports) {
|
|
604
|
-
try {
|
|
605
|
-
const moduleSpecifier = importDecl.getModuleSpecifierValue();
|
|
606
|
-
const { resolveImportPath } = await import('./compile.js');
|
|
607
|
-
const importPath = resolveImportPath(moduleSpecifier, indexFile.getFilePath());
|
|
608
|
-
if (fs.existsSync(importPath)) {
|
|
609
|
-
const importedFile = project.addSourceFileAtPath(importPath);
|
|
610
|
-
searchFileForJob(importedFile);
|
|
611
|
-
// If found, stop searching
|
|
612
|
-
if (executeFunction) {
|
|
613
|
-
break;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
catch (error) {
|
|
618
|
-
// Continue searching other imports
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
// Bundle and compress the execute function (like tools)
|
|
623
|
-
let compressedCode = '';
|
|
624
|
-
if (executeFunction) {
|
|
625
|
-
compressedCode = await bundleAndCompressJobCode(executeFunction, job.name, distDir, sourceFilePath, debugMode);
|
|
626
|
-
}
|
|
627
|
-
return {
|
|
628
|
-
...job,
|
|
629
|
-
executeFunction,
|
|
630
|
-
code: compressedCode // Add compressed bundled code
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
catch (error) {
|
|
634
|
-
console.warn(`Warning: Could not bundle job ${job.name}:`, error);
|
|
635
|
-
return job;
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Bundles and compresses job execute function code.
|
|
640
|
-
* Creates a temporary file, bundles with esbuild, compresses with gzip.
|
|
641
|
-
* Includes all imports from the source file to ensure dependencies are bundled.
|
|
642
|
-
*
|
|
643
|
-
* @param executeFunction - Raw execute function code
|
|
644
|
-
* @param jobName - Name of the job
|
|
645
|
-
* @param distDir - Distribution directory
|
|
646
|
-
* @param sourceFilePath - Path to the source file containing the job
|
|
647
|
-
* @param debugMode - Enable verbose logging and preserve temp files
|
|
648
|
-
* @returns Compressed base64-encoded bundled code
|
|
649
|
-
*/
|
|
650
|
-
async function bundleAndCompressJobCode(executeFunction, jobName, distDir, sourceFilePath, debugMode) {
|
|
651
|
-
return bundleAndCompressExecuteFunction(executeFunction, jobName, 'job', (bundledCode) => `(async (job) => {
|
|
652
|
-
// Execute the bundled job code
|
|
653
|
-
${bundledCode}
|
|
654
|
-
|
|
655
|
-
// Get the execute function from exports
|
|
656
|
-
const executeFunction = module.exports.default || module.exports;
|
|
657
|
-
|
|
658
|
-
// Execute job with job instance parameter
|
|
659
|
-
return await executeFunction(job);
|
|
660
|
-
})`, distDir, sourceFilePath, debugMode);
|
|
661
|
-
}
|
|
662
|
-
/**
|
|
663
|
-
* Bundles and compresses preprocessor execute function code.
|
|
664
|
-
*/
|
|
665
|
-
export async function bundlePreProcessor(preprocessor, indexFile, distDir, project, debugMode) {
|
|
666
|
-
if (!debugMode)
|
|
667
|
-
writeProgress(`📦 Bundling preprocessor ${preprocessor.name}...`);
|
|
668
|
-
try {
|
|
669
|
-
let executeFunction = '';
|
|
670
|
-
let sourceFilePath = indexFile.getFilePath();
|
|
671
|
-
const searchFileForPreProcessor = (file) => {
|
|
672
|
-
file.forEachDescendant((node) => {
|
|
673
|
-
if (Node.isNewExpression(node)) {
|
|
674
|
-
const expression = node.getExpression();
|
|
675
|
-
if (expression.getText() === 'PreProcessor') {
|
|
676
|
-
const args = node.getArguments();
|
|
677
|
-
if (args.length > 0 && Node.isObjectLiteralExpression(args[0])) {
|
|
678
|
-
const configObj = args[0];
|
|
679
|
-
let isMatching = false;
|
|
680
|
-
let foundExecute = '';
|
|
681
|
-
configObj.getProperties().forEach((prop) => {
|
|
682
|
-
if (Node.isPropertyAssignment(prop)) {
|
|
683
|
-
const name = prop.getName();
|
|
684
|
-
const value = prop.getInitializer();
|
|
685
|
-
if (name === 'name' && value) {
|
|
686
|
-
const nameValue = value.getText().replace(/['"]/g, '');
|
|
687
|
-
if (nameValue === preprocessor.name) {
|
|
688
|
-
isMatching = true;
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
if (name === 'execute' && value) {
|
|
692
|
-
foundExecute = value.getText();
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
});
|
|
696
|
-
if (isMatching && foundExecute) {
|
|
697
|
-
executeFunction = foundExecute;
|
|
698
|
-
// Update source file path to the file where preprocessor was found
|
|
699
|
-
sourceFilePath = file.getFilePath();
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
});
|
|
705
|
-
};
|
|
706
|
-
// Search in index file first
|
|
707
|
-
searchFileForPreProcessor(indexFile);
|
|
708
|
-
// If not found and project is available, search in imported files
|
|
709
|
-
if (!executeFunction && project) {
|
|
710
|
-
const imports = indexFile.getImportDeclarations();
|
|
711
|
-
for (const importDecl of imports) {
|
|
712
|
-
try {
|
|
713
|
-
const moduleSpecifier = importDecl.getModuleSpecifierValue();
|
|
714
|
-
const { resolveImportPath } = await import('./compile.js');
|
|
715
|
-
const importPath = resolveImportPath(moduleSpecifier, indexFile.getFilePath());
|
|
716
|
-
if (fs.existsSync(importPath)) {
|
|
717
|
-
const importedFile = project.addSourceFileAtPath(importPath);
|
|
718
|
-
searchFileForPreProcessor(importedFile);
|
|
719
|
-
if (executeFunction) {
|
|
720
|
-
break;
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
catch (error) {
|
|
725
|
-
// Continue searching
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
let compressedCode = '';
|
|
730
|
-
if (executeFunction) {
|
|
731
|
-
compressedCode = await bundleAndCompressProcessorCode(executeFunction, preprocessor.name, 'pre', distDir, sourceFilePath, debugMode);
|
|
732
|
-
}
|
|
733
|
-
return {
|
|
734
|
-
name: preprocessor.name,
|
|
735
|
-
version: preprocessor.version,
|
|
736
|
-
description: preprocessor.description,
|
|
737
|
-
async: preprocessor.async === true ? true : false, // Explicitly set boolean
|
|
738
|
-
executeFunction,
|
|
739
|
-
code: compressedCode
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
catch (error) {
|
|
743
|
-
console.warn(`Warning: Could not bundle preprocessor ${preprocessor.name}:`, error);
|
|
744
|
-
return preprocessor;
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* Bundles and compresses postprocessor execute function code.
|
|
749
|
-
*/
|
|
750
|
-
export async function bundlePostProcessor(postprocessor, indexFile, distDir, project, debugMode) {
|
|
751
|
-
if (!debugMode)
|
|
752
|
-
writeProgress(`📦 Bundling postprocessor ${postprocessor.name}...`);
|
|
753
|
-
try {
|
|
754
|
-
let executeFunction = '';
|
|
755
|
-
let sourceFilePath = indexFile.getFilePath();
|
|
756
|
-
const searchFileForPostProcessor = (file) => {
|
|
757
|
-
file.forEachDescendant((node) => {
|
|
758
|
-
if (Node.isNewExpression(node)) {
|
|
759
|
-
const expression = node.getExpression();
|
|
760
|
-
if (expression.getText() === 'PostProcessor') {
|
|
761
|
-
const args = node.getArguments();
|
|
762
|
-
if (args.length > 0 && Node.isObjectLiteralExpression(args[0])) {
|
|
763
|
-
const configObj = args[0];
|
|
764
|
-
let isMatching = false;
|
|
765
|
-
let foundExecute = '';
|
|
766
|
-
configObj.getProperties().forEach((prop) => {
|
|
767
|
-
if (Node.isPropertyAssignment(prop)) {
|
|
768
|
-
const name = prop.getName();
|
|
769
|
-
const value = prop.getInitializer();
|
|
770
|
-
if (name === 'name' && value) {
|
|
771
|
-
const nameValue = value.getText().replace(/['"]/g, '');
|
|
772
|
-
if (nameValue === postprocessor.name) {
|
|
773
|
-
isMatching = true;
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
if (name === 'execute' && value) {
|
|
777
|
-
foundExecute = value.getText();
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
});
|
|
781
|
-
if (isMatching && foundExecute) {
|
|
782
|
-
executeFunction = foundExecute;
|
|
783
|
-
// Update source file path to the file where postprocessor was found
|
|
784
|
-
sourceFilePath = file.getFilePath();
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
};
|
|
791
|
-
// Search in index file first
|
|
792
|
-
searchFileForPostProcessor(indexFile);
|
|
793
|
-
// If not found and project is available, search in imported files
|
|
794
|
-
if (!executeFunction && project) {
|
|
795
|
-
const imports = indexFile.getImportDeclarations();
|
|
796
|
-
for (const importDecl of imports) {
|
|
797
|
-
try {
|
|
798
|
-
const moduleSpecifier = importDecl.getModuleSpecifierValue();
|
|
799
|
-
const { resolveImportPath } = await import('./compile.js');
|
|
800
|
-
const importPath = resolveImportPath(moduleSpecifier, indexFile.getFilePath());
|
|
801
|
-
if (fs.existsSync(importPath)) {
|
|
802
|
-
const importedFile = project.addSourceFileAtPath(importPath);
|
|
803
|
-
searchFileForPostProcessor(importedFile);
|
|
804
|
-
if (executeFunction) {
|
|
805
|
-
break;
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
catch (error) {
|
|
810
|
-
// Continue searching
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
let compressedCode = '';
|
|
815
|
-
if (executeFunction) {
|
|
816
|
-
compressedCode = await bundleAndCompressProcessorCode(executeFunction, postprocessor.name, 'post', distDir, sourceFilePath, debugMode);
|
|
817
|
-
}
|
|
818
|
-
return {
|
|
819
|
-
name: postprocessor.name,
|
|
820
|
-
version: postprocessor.version,
|
|
821
|
-
description: postprocessor.description,
|
|
822
|
-
executeFunction,
|
|
823
|
-
code: compressedCode
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
catch (error) {
|
|
827
|
-
console.warn(`Warning: Could not bundle postprocessor ${postprocessor.name}:`, error);
|
|
828
|
-
return postprocessor;
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
/**
|
|
832
|
-
* Bundles and compresses processor execute function code.
|
|
833
|
-
* Includes all imports from the source file to ensure dependencies are bundled.
|
|
834
|
-
*/
|
|
835
|
-
async function bundleAndCompressProcessorCode(executeFunction, processorName, type, distDir, sourceFilePath, debugMode) {
|
|
836
|
-
// Processor execute functions receive: (user, message, [response], channel)
|
|
837
|
-
const paramList = type === 'pre' ? 'user, message, channel' : 'user, message, response, channel';
|
|
838
|
-
return bundleAndCompressExecuteFunction(executeFunction, processorName, `${type}processor`, (bundledCode) => `(async (${paramList}) => {
|
|
839
|
-
// Execute the bundled processor code
|
|
840
|
-
${bundledCode}
|
|
841
|
-
|
|
842
|
-
const executeFunction = module.exports.default || module.exports;
|
|
843
|
-
return await executeFunction(${paramList});
|
|
844
|
-
})`, distDir, sourceFilePath, debugMode);
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* Extracts tool code from a bundled tool.
|
|
848
|
-
* Reads the bundled code, wraps it for VM execution (execute and condition),
|
|
849
|
-
* and converts the Zod schema to JSON Schema format.
|
|
850
|
-
*/
|
|
851
|
-
export async function extractToolCode(tool, project) {
|
|
852
|
-
try {
|
|
853
|
-
const toolSourceFile = project.getSourceFile(tool.filePath);
|
|
854
|
-
if (!toolSourceFile) {
|
|
855
|
-
console.warn(`Warning: Could not find source file for ${tool.className}`);
|
|
856
|
-
return;
|
|
857
|
-
}
|
|
858
|
-
const classDecl = toolSourceFile.getClass(tool.className);
|
|
859
|
-
if (!classDecl) {
|
|
860
|
-
console.warn(`Warning: Could not find class ${tool.className} in ${tool.filePath}`);
|
|
861
|
-
return;
|
|
862
|
-
}
|
|
863
|
-
// Verify execute method or property exists
|
|
864
|
-
const executeMethod = classDecl.getMethod('execute');
|
|
865
|
-
const executeProperty = classDecl.getProperty('execute');
|
|
866
|
-
if (!executeMethod && !executeProperty) {
|
|
867
|
-
console.warn(`Warning: Could not find execute method or property in ${tool.className}`);
|
|
868
|
-
return;
|
|
869
|
-
}
|
|
870
|
-
// Validate execute has a body (for methods) or initializer (for arrow function properties)
|
|
871
|
-
if (executeMethod) {
|
|
872
|
-
const executeBody = executeMethod.getBodyText();
|
|
873
|
-
if (!executeBody) {
|
|
874
|
-
console.warn(`Warning: Execute method has no body in ${tool.className}`);
|
|
875
|
-
return;
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
else if (executeProperty) {
|
|
879
|
-
const initializer = executeProperty.getInitializer();
|
|
880
|
-
if (!initializer) {
|
|
881
|
-
console.warn(`Warning: Execute property has no initializer in ${tool.className}`);
|
|
882
|
-
return;
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
// Read bundled code and wrap for VM execution
|
|
886
|
-
const rawBundledCode = readBundledToolCode(tool);
|
|
887
|
-
if (rawBundledCode) {
|
|
888
|
-
tool.executeCode = wrapExecuteForVM(rawBundledCode, tool.className);
|
|
889
|
-
// Check if tool has condition and wrap it
|
|
890
|
-
const hasCondition = classDecl.getMethod('condition') || classDecl.getProperty('condition');
|
|
891
|
-
if (hasCondition) {
|
|
892
|
-
tool.conditionCode = wrapConditionForVM(rawBundledCode, tool.className);
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
// Extract input schema using ts-evaluator (resolves all imports/expressions automatically)
|
|
896
|
-
tool.inputSchema = await extractInputSchema(classDecl, tool);
|
|
897
|
-
}
|
|
898
|
-
catch (error) {
|
|
899
|
-
console.warn(`Warning: Could not extract tool metadata for ${tool.className}:`, error);
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
/**
|
|
903
|
-
* Reads the raw bundled tool code from the dist directory.
|
|
904
|
-
*/
|
|
905
|
-
function readBundledToolCode(tool) {
|
|
906
|
-
const bundledPath = path.join(process.cwd(), COMPILE_DIRS.DIST, COMPILE_DIRS.TOOLS, `${tool.className}.js`);
|
|
907
|
-
if (fs.existsSync(bundledPath)) {
|
|
908
|
-
return fs.readFileSync(bundledPath, 'utf8');
|
|
909
|
-
}
|
|
910
|
-
return undefined;
|
|
911
|
-
}
|
|
912
|
-
/**
|
|
913
|
-
* Extracts and converts the input schema from a tool class using ts-evaluator.
|
|
914
|
-
* This evaluates the actual TypeScript AST node, resolving all imports and expressions.
|
|
915
|
-
*
|
|
916
|
-
* @param classDecl - The tool class declaration from ts-morph
|
|
917
|
-
* @param tool - The tool being analyzed
|
|
918
|
-
* @returns The JSON Schema object or default schema
|
|
919
|
-
*/
|
|
920
|
-
async function extractInputSchema(classDecl, tool) {
|
|
921
|
-
const inputSchemaProperty = classDecl.getProperty('inputSchema');
|
|
922
|
-
if (!inputSchemaProperty?.getInitializer()) {
|
|
923
|
-
return DEFAULT_INPUT_SCHEMA;
|
|
924
|
-
}
|
|
925
|
-
try {
|
|
926
|
-
const initializer = inputSchemaProperty.getInitializer();
|
|
927
|
-
const sourceFile = initializer.getSourceFile();
|
|
928
|
-
const project = sourceFile.getProject();
|
|
929
|
-
// Get the underlying TypeScript compiler objects for ts-evaluator
|
|
930
|
-
const tsNode = initializer.compilerNode;
|
|
931
|
-
const typeChecker = project.getTypeChecker().compilerObject;
|
|
932
|
-
const compilerOptions = project.getCompilerOptions();
|
|
933
|
-
// Get zod from node_modules to provide as extra global
|
|
934
|
-
const { z } = await import('zod');
|
|
935
|
-
// Evaluate the AST node using ts-evaluator
|
|
936
|
-
// This resolves all imports, variables, and expressions automatically
|
|
937
|
-
const result = evaluate({
|
|
938
|
-
node: tsNode,
|
|
939
|
-
typeChecker,
|
|
940
|
-
typescript: ts,
|
|
941
|
-
environment: {
|
|
942
|
-
preset: 'NODE',
|
|
943
|
-
extra: { z } // Provide zod as a global to avoid import resolution issues
|
|
944
|
-
},
|
|
945
|
-
policy: {
|
|
946
|
-
deterministic: false,
|
|
947
|
-
network: false,
|
|
948
|
-
console: false,
|
|
949
|
-
io: { read: true, write: false },
|
|
950
|
-
process: { exit: false, spawnChild: false }
|
|
951
|
-
}
|
|
952
|
-
});
|
|
953
|
-
if (!result.success) {
|
|
954
|
-
throw new Error(result.reason?.message || 'Failed to evaluate schema');
|
|
955
|
-
}
|
|
956
|
-
const zodSchema = result.value;
|
|
957
|
-
if (!zodSchema || typeof zodSchema !== 'object') {
|
|
958
|
-
return DEFAULT_INPUT_SCHEMA;
|
|
959
|
-
}
|
|
960
|
-
// Convert Zod schema to JSON Schema
|
|
961
|
-
const { zodToJsonSchema } = await import('zod-to-json-schema');
|
|
962
|
-
const jsonSchema = zodToJsonSchema(zodSchema, { target: 'jsonSchema7' });
|
|
963
|
-
// Clean up the JSON schema (remove $schema, title, etc.)
|
|
964
|
-
const { $schema, title, definitions, $ref, ...cleanSchema } = jsonSchema;
|
|
965
|
-
return cleanSchema;
|
|
966
|
-
}
|
|
967
|
-
catch (error) {
|
|
968
|
-
console.warn(`Warning: Could not evaluate schema for ${tool.className}:`, error?.message || error);
|
|
969
|
-
return DEFAULT_INPUT_SCHEMA;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
/**
|
|
973
|
-
* Bundles and compresses an MCP resolver function using esbuild.
|
|
974
|
-
*
|
|
975
|
-
* MCP resolver functions are simple arrow functions like:
|
|
976
|
-
* () => ({ KEY: env("KEY") })
|
|
977
|
-
*
|
|
978
|
-
* They don't have imports (env is runtime-provided), but may have TypeScript
|
|
979
|
-
* type annotations that need transpilation. Uses esbuild for TypeScript support.
|
|
980
|
-
*
|
|
981
|
-
* @param functionCode - Raw function code (e.g., "() => ({ KEY: env('KEY') })")
|
|
982
|
-
* @param resolverType - Type of resolver ('env', 'headers', 'url') for temp file naming
|
|
983
|
-
* @param serverName - MCP server name for temp file naming
|
|
984
|
-
* @param distDir - Distribution directory for temp files
|
|
985
|
-
* @param debugMode - Enable verbose logging and preserve temp files
|
|
986
|
-
* @returns Compressed base64-encoded bundled code, or null if bundling fails
|
|
987
|
-
*/
|
|
988
|
-
export async function bundleMCPResolverFunction(functionCode, resolverType, serverName, distDir, debugMode) {
|
|
989
|
-
const { compressCode } = await import('./compile.js');
|
|
990
|
-
// Create temporary file with the function wrapped as a module
|
|
991
|
-
const tempDir = path.join(distDir, '.temp');
|
|
992
|
-
if (!fs.existsSync(tempDir)) {
|
|
993
|
-
fs.mkdirSync(tempDir, { recursive: true });
|
|
994
|
-
}
|
|
995
|
-
const safeName = serverName.replace(/[^a-zA-Z0-9]/g, '_');
|
|
996
|
-
const tempFile = path.join(tempDir, `mcp-${safeName}-${resolverType}.ts`);
|
|
997
|
-
const tempOutput = path.join(tempDir, `mcp-${safeName}-${resolverType}.js`);
|
|
998
|
-
try {
|
|
999
|
-
// Write function as a module export
|
|
1000
|
-
// The function references `env` which will be provided by the runtime sandbox
|
|
1001
|
-
const moduleCode = `
|
|
1002
|
-
// MCP ${resolverType} resolver for ${serverName}
|
|
1003
|
-
// Note: env() is provided by the runtime sandbox, not imported
|
|
1004
|
-
const resolverFunc = ${functionCode};
|
|
1005
|
-
export default resolverFunc;
|
|
1006
|
-
`;
|
|
1007
|
-
fs.writeFileSync(tempFile, moduleCode);
|
|
1008
|
-
if (debugMode) {
|
|
1009
|
-
console.log(` → Bundling MCP ${resolverType} resolver for ${serverName}...`);
|
|
1010
|
-
}
|
|
1011
|
-
// Bundle with esbuild - minimal config since there are no imports to resolve
|
|
1012
|
-
await build({
|
|
1013
|
-
entryPoints: [tempFile],
|
|
1014
|
-
bundle: true,
|
|
1015
|
-
platform: 'node',
|
|
1016
|
-
target: 'node16',
|
|
1017
|
-
format: 'cjs',
|
|
1018
|
-
minify: true,
|
|
1019
|
-
outfile: tempOutput,
|
|
1020
|
-
external: [...EXTERNAL_PACKAGES],
|
|
1021
|
-
plugins: [sandboxGlobalsPlugin],
|
|
1022
|
-
});
|
|
1023
|
-
// Read bundled code
|
|
1024
|
-
if (!fs.existsSync(tempOutput)) {
|
|
1025
|
-
throw new Error(`esbuild failed to create output file for MCP ${resolverType} resolver`);
|
|
1026
|
-
}
|
|
1027
|
-
const bundledCode = fs.readFileSync(tempOutput, 'utf8');
|
|
1028
|
-
if (bundledCode.length === 0) {
|
|
1029
|
-
throw new Error(`esbuild created empty bundle for MCP ${resolverType} resolver`);
|
|
1030
|
-
}
|
|
1031
|
-
// Wrap for VM execution - the resolver function returns a value directly
|
|
1032
|
-
const wrappedCode = `(async () => {
|
|
1033
|
-
${bundledCode}
|
|
1034
|
-
|
|
1035
|
-
const resolverFunc = module.exports.default || module.exports;
|
|
1036
|
-
return resolverFunc();
|
|
1037
|
-
})()`;
|
|
1038
|
-
// Compress the wrapped code
|
|
1039
|
-
const compressed = compressCode(wrappedCode);
|
|
1040
|
-
if (debugMode) {
|
|
1041
|
-
console.log(` → MCP ${resolverType} resolver bundled: ${(compressed.length / 1024).toFixed(2)}KB`);
|
|
1042
|
-
}
|
|
1043
|
-
// Clean up temp files (unless in debug mode)
|
|
1044
|
-
if (!debugMode) {
|
|
1045
|
-
try {
|
|
1046
|
-
fs.unlinkSync(tempFile);
|
|
1047
|
-
fs.unlinkSync(tempOutput);
|
|
1048
|
-
}
|
|
1049
|
-
catch (cleanupError) {
|
|
1050
|
-
// Ignore cleanup errors
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
return compressed;
|
|
1054
|
-
}
|
|
1055
|
-
catch (error) {
|
|
1056
|
-
console.warn(`Warning: Could not bundle MCP ${resolverType} resolver for ${serverName}: ${error.message}`);
|
|
1057
|
-
// Fallback: compress the raw function with simple wrapper (may fail at runtime if TS syntax)
|
|
1058
|
-
try {
|
|
1059
|
-
const fallbackCode = `(${functionCode})()`;
|
|
1060
|
-
return compressCode(fallbackCode);
|
|
1061
|
-
}
|
|
1062
|
-
catch (fallbackError) {
|
|
1063
|
-
console.warn(`Warning: Fallback compression also failed for MCP ${resolverType} resolver`);
|
|
1064
|
-
return null;
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
//# sourceMappingURL=bundling.js.map
|