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
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
# PreProcessor
|
|
2
|
+
|
|
3
|
+
The `PreProcessor` class allows you to filter, modify, or block user messages before they reach your AI agent. Use preprocessors for content filtering, message enrichment, spam detection, and access control.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { PreProcessor } from 'lua-cli';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
PreProcessors enable:
|
|
14
|
+
- Filter and block inappropriate content
|
|
15
|
+
- Modify messages before agent processing
|
|
16
|
+
- Add context and enrichment to messages
|
|
17
|
+
- Implement access control and permissions
|
|
18
|
+
- Detect spam and malicious content
|
|
19
|
+
- Route messages based on content
|
|
20
|
+
- Execute in sync or async mode
|
|
21
|
+
- Control execution order with priorities
|
|
22
|
+
|
|
23
|
+
## Class Definition
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
class PreProcessor {
|
|
27
|
+
constructor(config: PreProcessorConfig);
|
|
28
|
+
getName(): string;
|
|
29
|
+
getDescription(): string;
|
|
30
|
+
getAsync(): boolean;
|
|
31
|
+
getPriority(): number;
|
|
32
|
+
execute(user: UserDataInstance, messages: ChatMessage[], channel: string): Promise<PreProcessorResult>;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
interface PreProcessorConfig {
|
|
40
|
+
/** PreProcessor name (optional, defaults to 'unnamed-preprocessor') */
|
|
41
|
+
name?: string;
|
|
42
|
+
|
|
43
|
+
/** Short description of the preprocessor */
|
|
44
|
+
description: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Async flag - indicates if processor should run in background:
|
|
48
|
+
* - true: Run asynchronously (non-blocking, for slow operations)
|
|
49
|
+
* - false: Run synchronously (blocking, for fast operations)
|
|
50
|
+
* Default: false (synchronous)
|
|
51
|
+
*/
|
|
52
|
+
async?: boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Execution priority (lower runs first).
|
|
56
|
+
* Default: 100
|
|
57
|
+
*/
|
|
58
|
+
priority?: number;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Function that processes messages before sending to agent.
|
|
62
|
+
*/
|
|
63
|
+
execute: (
|
|
64
|
+
user: UserDataInstance,
|
|
65
|
+
messages: ChatMessage[],
|
|
66
|
+
channel: string
|
|
67
|
+
) => Promise<PreProcessorResult>;
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Result Types
|
|
72
|
+
|
|
73
|
+
### Block Response
|
|
74
|
+
|
|
75
|
+
Stop processing and send a response to the user:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
{
|
|
79
|
+
action: 'block',
|
|
80
|
+
response: string, // Message to show to user
|
|
81
|
+
metadata?: Record<string, any> // Optional metadata
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Proceed Response
|
|
86
|
+
|
|
87
|
+
Continue to the next preprocessor or agent:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
{
|
|
91
|
+
action: 'proceed',
|
|
92
|
+
modifiedMessage?: ChatMessage[], // Optional modified messages
|
|
93
|
+
metadata?: Record<string, any> // Optional metadata
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Message Types
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
type ChatMessage =
|
|
101
|
+
| { type: 'text'; text: string }
|
|
102
|
+
| { type: 'image'; url: string }
|
|
103
|
+
| { type: 'file'; url: string; mimeType?: string };
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Complete Examples
|
|
107
|
+
|
|
108
|
+
### Content Filter
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { PreProcessor } from 'lua-cli';
|
|
112
|
+
|
|
113
|
+
export const contentFilter = new PreProcessor({
|
|
114
|
+
name: 'content-filter',
|
|
115
|
+
description: 'Filters inappropriate content',
|
|
116
|
+
priority: 10, // Run early
|
|
117
|
+
|
|
118
|
+
execute: async (user, messages, channel) => {
|
|
119
|
+
const blockedWords = ['spam', 'scam', 'phishing'];
|
|
120
|
+
|
|
121
|
+
// Check text messages for blocked words
|
|
122
|
+
for (const message of messages) {
|
|
123
|
+
if (message.type === 'text') {
|
|
124
|
+
const lowerText = message.text.toLowerCase();
|
|
125
|
+
|
|
126
|
+
for (const word of blockedWords) {
|
|
127
|
+
if (lowerText.includes(word)) {
|
|
128
|
+
return {
|
|
129
|
+
action: 'block',
|
|
130
|
+
response: 'Your message contains inappropriate content and cannot be processed.',
|
|
131
|
+
metadata: {
|
|
132
|
+
reason: 'blocked_word',
|
|
133
|
+
word
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return { action: 'proceed' };
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### User Verification
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { PreProcessor } from 'lua-cli';
|
|
150
|
+
|
|
151
|
+
export const userVerification = new PreProcessor({
|
|
152
|
+
name: 'user-verification',
|
|
153
|
+
description: 'Verifies user has completed onboarding',
|
|
154
|
+
priority: 5, // Run very early
|
|
155
|
+
|
|
156
|
+
execute: async (user, messages, channel) => {
|
|
157
|
+
const userData = await user.get();
|
|
158
|
+
|
|
159
|
+
// Check if user has completed onboarding
|
|
160
|
+
if (!userData.data?.onboardingCompleted) {
|
|
161
|
+
return {
|
|
162
|
+
action: 'block',
|
|
163
|
+
response: 'Please complete your profile setup before using the assistant. Type "/start" to begin.',
|
|
164
|
+
metadata: {
|
|
165
|
+
reason: 'onboarding_incomplete'
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Check if user is suspended
|
|
171
|
+
if (userData.data?.status === 'suspended') {
|
|
172
|
+
return {
|
|
173
|
+
action: 'block',
|
|
174
|
+
response: 'Your account has been suspended. Please contact support.',
|
|
175
|
+
metadata: {
|
|
176
|
+
reason: 'account_suspended'
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return { action: 'proceed' };
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Message Enrichment
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import { PreProcessor } from 'lua-cli';
|
|
190
|
+
|
|
191
|
+
export const messageEnrichment = new PreProcessor({
|
|
192
|
+
name: 'message-enrichment',
|
|
193
|
+
description: 'Adds user context to messages',
|
|
194
|
+
priority: 50,
|
|
195
|
+
|
|
196
|
+
execute: async (user, messages, channel) => {
|
|
197
|
+
const userData = await user.get();
|
|
198
|
+
|
|
199
|
+
// Add context message with user info
|
|
200
|
+
const contextMessage = {
|
|
201
|
+
type: 'text' as const,
|
|
202
|
+
text: `[User Context: Name: ${userData.data?.name || 'Unknown'}, Plan: ${userData.data?.plan || 'free'}, Location: ${userData.data?.location || 'Unknown'}]`
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// Prepend context to messages
|
|
206
|
+
const enrichedMessages = [contextMessage, ...messages];
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
action: 'proceed',
|
|
210
|
+
modifiedMessage: enrichedMessages,
|
|
211
|
+
metadata: {
|
|
212
|
+
enriched: true,
|
|
213
|
+
userPlan: userData.data?.plan
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Rate Limiter
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import { PreProcessor, Data } from 'lua-cli';
|
|
224
|
+
|
|
225
|
+
export const rateLimiter = new PreProcessor({
|
|
226
|
+
name: 'rate-limiter',
|
|
227
|
+
description: 'Limits message rate per user',
|
|
228
|
+
priority: 15,
|
|
229
|
+
|
|
230
|
+
execute: async (user, messages, channel) => {
|
|
231
|
+
const userId = user.id;
|
|
232
|
+
const now = Date.now();
|
|
233
|
+
const windowMs = 60 * 1000; // 1 minute
|
|
234
|
+
const maxMessages = 10;
|
|
235
|
+
|
|
236
|
+
// Get user's recent messages
|
|
237
|
+
const rateLimitKey = `rate_limit_${userId}`;
|
|
238
|
+
const records = await Data.get('rate_limits');
|
|
239
|
+
let userRecord = records.find(r => r.data.key === rateLimitKey);
|
|
240
|
+
|
|
241
|
+
if (!userRecord) {
|
|
242
|
+
// Create new record
|
|
243
|
+
await Data.create('rate_limits', {
|
|
244
|
+
key: rateLimitKey,
|
|
245
|
+
messages: [now],
|
|
246
|
+
windowStart: now
|
|
247
|
+
});
|
|
248
|
+
return { action: 'proceed' };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Filter messages within window
|
|
252
|
+
const recentMessages = userRecord.data.messages
|
|
253
|
+
.filter((timestamp: number) => now - timestamp < windowMs);
|
|
254
|
+
|
|
255
|
+
// Check if limit exceeded
|
|
256
|
+
if (recentMessages.length >= maxMessages) {
|
|
257
|
+
return {
|
|
258
|
+
action: 'block',
|
|
259
|
+
response: 'You are sending messages too quickly. Please wait a moment and try again.',
|
|
260
|
+
metadata: {
|
|
261
|
+
reason: 'rate_limit_exceeded',
|
|
262
|
+
retryAfter: windowMs - (now - recentMessages[0])
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Update record
|
|
268
|
+
await Data.update('rate_limits', userRecord.id, {
|
|
269
|
+
...userRecord.data,
|
|
270
|
+
messages: [...recentMessages, now]
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
return { action: 'proceed' };
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Spam Detector
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
import { PreProcessor, AI } from 'lua-cli';
|
|
282
|
+
|
|
283
|
+
export const spamDetector = new PreProcessor({
|
|
284
|
+
name: 'spam-detector',
|
|
285
|
+
description: 'AI-powered spam detection',
|
|
286
|
+
priority: 20,
|
|
287
|
+
async: true, // Can run in background
|
|
288
|
+
|
|
289
|
+
execute: async (user, messages, channel) => {
|
|
290
|
+
// Only check text messages
|
|
291
|
+
const textMessages = messages.filter(m => m.type === 'text');
|
|
292
|
+
|
|
293
|
+
if (textMessages.length === 0) {
|
|
294
|
+
return { action: 'proceed' };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const messageText = textMessages.map(m => m.text).join(' ');
|
|
298
|
+
|
|
299
|
+
// Use AI to detect spam
|
|
300
|
+
const analysis = await AI.generate(
|
|
301
|
+
'You are a spam detector. Analyze the message and respond with JSON: { "isSpam": true/false, "confidence": 0-1, "reason": "explanation" }',
|
|
302
|
+
[{ type: 'text', text: messageText }]
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
try {
|
|
306
|
+
const result = JSON.parse(analysis);
|
|
307
|
+
|
|
308
|
+
if (result.isSpam && result.confidence > 0.8) {
|
|
309
|
+
return {
|
|
310
|
+
action: 'block',
|
|
311
|
+
response: 'Your message appears to be spam and cannot be processed.',
|
|
312
|
+
metadata: {
|
|
313
|
+
reason: 'spam_detected',
|
|
314
|
+
confidence: result.confidence,
|
|
315
|
+
analysis: result.reason
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
} catch (error) {
|
|
320
|
+
// If AI response is not valid JSON, proceed anyway
|
|
321
|
+
console.error('Spam detection parsing error:', error);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return { action: 'proceed' };
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Business Hours Checker
|
|
330
|
+
|
|
331
|
+
```typescript
|
|
332
|
+
import { PreProcessor } from 'lua-cli';
|
|
333
|
+
|
|
334
|
+
export const businessHoursChecker = new PreProcessor({
|
|
335
|
+
name: 'business-hours',
|
|
336
|
+
description: 'Checks if within business hours',
|
|
337
|
+
priority: 30,
|
|
338
|
+
|
|
339
|
+
execute: async (user, messages, channel) => {
|
|
340
|
+
const now = new Date();
|
|
341
|
+
const hour = now.getHours();
|
|
342
|
+
const day = now.getDay();
|
|
343
|
+
|
|
344
|
+
// Business hours: Monday-Friday, 9 AM - 5 PM
|
|
345
|
+
const isWeekday = day >= 1 && day <= 5;
|
|
346
|
+
const isBusinessHours = hour >= 9 && hour < 17;
|
|
347
|
+
|
|
348
|
+
if (!isWeekday || !isBusinessHours) {
|
|
349
|
+
// Add notice to message
|
|
350
|
+
const noticeMessage = {
|
|
351
|
+
type: 'text' as const,
|
|
352
|
+
text: '[Note: You are contacting us outside business hours. Our team will respond when we return (Monday-Friday, 9 AM - 5 PM).]'
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
return {
|
|
356
|
+
action: 'proceed',
|
|
357
|
+
modifiedMessage: [noticeMessage, ...messages],
|
|
358
|
+
metadata: {
|
|
359
|
+
outsideBusinessHours: true,
|
|
360
|
+
timestamp: now.toISOString()
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return { action: 'proceed' };
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Language Translator
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
import { PreProcessor, AI } from 'lua-cli';
|
|
374
|
+
|
|
375
|
+
export const languageTranslator = new PreProcessor({
|
|
376
|
+
name: 'language-translator',
|
|
377
|
+
description: 'Translates non-English messages to English',
|
|
378
|
+
priority: 40,
|
|
379
|
+
async: true,
|
|
380
|
+
|
|
381
|
+
execute: async (user, messages, channel) => {
|
|
382
|
+
const textMessages = messages.filter(m => m.type === 'text');
|
|
383
|
+
|
|
384
|
+
if (textMessages.length === 0) {
|
|
385
|
+
return { action: 'proceed' };
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const messageText = textMessages[0].text;
|
|
389
|
+
|
|
390
|
+
// Detect language
|
|
391
|
+
const detection = await AI.generate(
|
|
392
|
+
'Detect the language of this text. Respond with just the language code (e.g., "en", "es", "fr") or "en" if already English.',
|
|
393
|
+
[{ type: 'text', text: messageText }]
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
const language = detection.trim().toLowerCase();
|
|
397
|
+
|
|
398
|
+
// If not English, translate
|
|
399
|
+
if (language !== 'en' && language !== 'english') {
|
|
400
|
+
const translation = await AI.generate(
|
|
401
|
+
'Translate this text to English. Return only the translation, no explanations.',
|
|
402
|
+
[{ type: 'text', text: messageText }]
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
// Replace with translated text
|
|
406
|
+
const translatedMessages = messages.map(msg => {
|
|
407
|
+
if (msg.type === 'text') {
|
|
408
|
+
return { type: 'text' as const, text: translation };
|
|
409
|
+
}
|
|
410
|
+
return msg;
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
return {
|
|
414
|
+
action: 'proceed',
|
|
415
|
+
modifiedMessage: translatedMessages,
|
|
416
|
+
metadata: {
|
|
417
|
+
originalLanguage: language,
|
|
418
|
+
translated: true
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return { action: 'proceed' };
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### Priority Routing
|
|
429
|
+
|
|
430
|
+
```typescript
|
|
431
|
+
import { PreProcessor } from 'lua-cli';
|
|
432
|
+
|
|
433
|
+
export const priorityRouter = new PreProcessor({
|
|
434
|
+
name: 'priority-router',
|
|
435
|
+
description: 'Routes urgent messages to priority queue',
|
|
436
|
+
priority: 25,
|
|
437
|
+
|
|
438
|
+
execute: async (user, messages, channel) => {
|
|
439
|
+
const urgentKeywords = ['urgent', 'emergency', 'critical', 'asap', 'help'];
|
|
440
|
+
|
|
441
|
+
// Check for urgent keywords
|
|
442
|
+
for (const message of messages) {
|
|
443
|
+
if (message.type === 'text') {
|
|
444
|
+
const lowerText = message.text.toLowerCase();
|
|
445
|
+
|
|
446
|
+
for (const keyword of urgentKeywords) {
|
|
447
|
+
if (lowerText.includes(keyword)) {
|
|
448
|
+
// Mark as high priority
|
|
449
|
+
const priorityMessage = {
|
|
450
|
+
type: 'text' as const,
|
|
451
|
+
text: `[HIGH PRIORITY] ${message.text}`
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
return {
|
|
455
|
+
action: 'proceed',
|
|
456
|
+
modifiedMessage: [priorityMessage, ...messages.slice(1)],
|
|
457
|
+
metadata: {
|
|
458
|
+
priority: 'high',
|
|
459
|
+
keyword,
|
|
460
|
+
flagged: true
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return {
|
|
469
|
+
action: 'proceed',
|
|
470
|
+
metadata: {
|
|
471
|
+
priority: 'normal'
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
## Execution Order
|
|
479
|
+
|
|
480
|
+
PreProcessors execute in priority order (lowest first):
|
|
481
|
+
|
|
482
|
+
```typescript
|
|
483
|
+
// Priority 5 - User verification (runs first)
|
|
484
|
+
new PreProcessor({ priority: 5, ... });
|
|
485
|
+
|
|
486
|
+
// Priority 10 - Content filter
|
|
487
|
+
new PreProcessor({ priority: 10, ... });
|
|
488
|
+
|
|
489
|
+
// Priority 50 - Message enrichment (runs last)
|
|
490
|
+
new PreProcessor({ priority: 50, ... });
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
## Async vs Sync
|
|
494
|
+
|
|
495
|
+
### Synchronous (default)
|
|
496
|
+
- Blocks message processing until complete
|
|
497
|
+
- Best for fast operations (< 100ms)
|
|
498
|
+
- Use for filtering, validation, simple transforms
|
|
499
|
+
|
|
500
|
+
### Asynchronous
|
|
501
|
+
- Runs in background, doesn't block
|
|
502
|
+
- Best for slow operations (API calls, AI)
|
|
503
|
+
- Set `async: true` in config
|
|
504
|
+
|
|
505
|
+
```typescript
|
|
506
|
+
// Fast operation - synchronous
|
|
507
|
+
new PreProcessor({
|
|
508
|
+
name: 'quick-filter',
|
|
509
|
+
async: false, // Default
|
|
510
|
+
execute: async (user, messages, channel) => {
|
|
511
|
+
// Fast check
|
|
512
|
+
return { action: 'proceed' };
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
// Slow operation - asynchronous
|
|
517
|
+
new PreProcessor({
|
|
518
|
+
name: 'ai-analyzer',
|
|
519
|
+
async: true, // Non-blocking
|
|
520
|
+
execute: async (user, messages, channel) => {
|
|
521
|
+
// Slow AI call
|
|
522
|
+
await AI.generate(...);
|
|
523
|
+
return { action: 'proceed' };
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
## Best Practices
|
|
529
|
+
|
|
530
|
+
### ✅ DO
|
|
531
|
+
|
|
532
|
+
- Use low priorities for critical checks (run early)
|
|
533
|
+
- Set `async: true` for slow operations
|
|
534
|
+
- Return clear block messages to users
|
|
535
|
+
- Log blocked messages for review
|
|
536
|
+
- Use metadata to pass data between preprocessors
|
|
537
|
+
- Handle errors gracefully
|
|
538
|
+
- Keep preprocessing logic fast
|
|
539
|
+
- Test with edge cases
|
|
540
|
+
|
|
541
|
+
### ❌ DON'T
|
|
542
|
+
|
|
543
|
+
- Don't block valid messages unnecessarily
|
|
544
|
+
- Don't perform heavy computation synchronously
|
|
545
|
+
- Don't skip error handling
|
|
546
|
+
- Don't forget to return a result
|
|
547
|
+
- Don't modify messages unless necessary
|
|
548
|
+
- Don't create circular logic
|
|
549
|
+
- Don't use very high priorities (use low numbers instead)
|
|
550
|
+
|
|
551
|
+
## Error Handling
|
|
552
|
+
|
|
553
|
+
```typescript
|
|
554
|
+
export const safePreProcessor = new PreProcessor({
|
|
555
|
+
name: 'safe-preprocessor',
|
|
556
|
+
description: 'Preprocessor with error handling',
|
|
557
|
+
|
|
558
|
+
execute: async (user, messages, channel) => {
|
|
559
|
+
try {
|
|
560
|
+
// Your preprocessing logic
|
|
561
|
+
const result = await processMessages(messages);
|
|
562
|
+
|
|
563
|
+
return { action: 'proceed' };
|
|
564
|
+
} catch (error) {
|
|
565
|
+
console.error('PreProcessor error:', error);
|
|
566
|
+
|
|
567
|
+
// Log error but don't block message
|
|
568
|
+
await Data.create('preprocessor_errors', {
|
|
569
|
+
error: error.message,
|
|
570
|
+
userId: user.id,
|
|
571
|
+
timestamp: new Date().toISOString()
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
// Proceed anyway (fail open)
|
|
575
|
+
return { action: 'proceed' };
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
## Common Patterns
|
|
582
|
+
|
|
583
|
+
### Conditional Blocking
|
|
584
|
+
|
|
585
|
+
```typescript
|
|
586
|
+
if (shouldBlock) {
|
|
587
|
+
return {
|
|
588
|
+
action: 'block',
|
|
589
|
+
response: 'Message blocked'
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
return { action: 'proceed' };
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
### Message Modification
|
|
596
|
+
|
|
597
|
+
```typescript
|
|
598
|
+
const modifiedMessages = messages.map(msg => {
|
|
599
|
+
if (msg.type === 'text') {
|
|
600
|
+
return { type: 'text', text: msg.text.toUpperCase() };
|
|
601
|
+
}
|
|
602
|
+
return msg;
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
return {
|
|
606
|
+
action: 'proceed',
|
|
607
|
+
modifiedMessage: modifiedMessages
|
|
608
|
+
};
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
### Adding Context
|
|
612
|
+
|
|
613
|
+
```typescript
|
|
614
|
+
const contextMsg = { type: 'text' as const, text: '[Context info]' };
|
|
615
|
+
return {
|
|
616
|
+
action: 'proceed',
|
|
617
|
+
modifiedMessage: [contextMsg, ...messages]
|
|
618
|
+
};
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
## Related APIs
|
|
622
|
+
|
|
623
|
+
- [PostProcessor](./PostProcessor.md) - Process agent responses
|
|
624
|
+
- [User API](./User.md) - Access user data
|
|
625
|
+
- [Data API](./Data.md) - Store filtering logs
|
|
626
|
+
|
|
627
|
+
## See Also
|
|
628
|
+
|
|
629
|
+
- [Message Filtering Guide](../guides/MessageFiltering.md)
|
|
630
|
+
- [Content Moderation](../guides/ContentModeration.md)
|