@hed-hog/core 0.0.387 → 0.0.390
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 +12 -11
- package/dist/access-log/access-log.interceptor.d.ts.map +1 -1
- package/dist/access-log/access-log.interceptor.js +4 -2
- package/dist/access-log/access-log.interceptor.js.map +1 -1
- package/dist/ai/ai-attachment.fragments.d.ts +23 -0
- package/dist/ai/ai-attachment.fragments.d.ts.map +1 -0
- package/dist/ai/ai-attachment.fragments.js +34 -0
- package/dist/ai/ai-attachment.fragments.js.map +1 -0
- package/dist/ai/ai.controller.d.ts +7 -16
- package/dist/ai/ai.controller.d.ts.map +1 -1
- package/dist/ai/ai.prompts.d.ts +16 -0
- package/dist/ai/ai.prompts.d.ts.map +1 -0
- package/dist/ai/ai.prompts.js +37 -0
- package/dist/ai/ai.prompts.js.map +1 -0
- package/dist/ai/ai.service.d.ts +63 -12
- package/dist/ai/ai.service.d.ts.map +1 -1
- package/dist/ai/ai.service.js +215 -88
- package/dist/ai/ai.service.js.map +1 -1
- package/dist/ai/dto/chat.dto.d.ts +4 -1
- package/dist/ai/dto/chat.dto.d.ts.map +1 -1
- package/dist/ai/dto/chat.dto.js +23 -1
- package/dist/ai/dto/chat.dto.js.map +1 -1
- package/dist/ai/dto/create-agent.dto.d.ts +1 -1
- package/dist/ai/dto/create-agent.dto.d.ts.map +1 -1
- package/dist/ai/dto/create-agent.dto.js +1 -1
- package/dist/ai/dto/create-agent.dto.js.map +1 -1
- package/dist/ai/dto/update-agent.dto.d.ts +1 -1
- package/dist/ai/dto/update-agent.dto.d.ts.map +1 -1
- package/dist/ai/dto/update-agent.dto.js +1 -1
- package/dist/ai/dto/update-agent.dto.js.map +1 -1
- package/dist/ai-instruction/ai-instruction.controller.d.ts +61 -7
- package/dist/ai-instruction/ai-instruction.controller.d.ts.map +1 -1
- package/dist/ai-instruction/ai-instruction.controller.js +63 -20
- package/dist/ai-instruction/ai-instruction.controller.js.map +1 -1
- package/dist/ai-instruction/ai-instruction.module.d.ts.map +1 -1
- package/dist/ai-instruction/ai-instruction.module.js +13 -2
- package/dist/ai-instruction/ai-instruction.module.js.map +1 -1
- package/dist/ai-instruction/ai-instruction.service.d.ts +131 -6
- package/dist/ai-instruction/ai-instruction.service.d.ts.map +1 -1
- package/dist/ai-instruction/ai-instruction.service.js +533 -60
- package/dist/ai-instruction/ai-instruction.service.js.map +1 -1
- package/dist/ai-instruction/ai-prompt-builder.service.d.ts +8 -0
- package/dist/ai-instruction/ai-prompt-builder.service.d.ts.map +1 -1
- package/dist/ai-instruction/ai-prompt-builder.service.js +10 -1
- package/dist/ai-instruction/ai-prompt-builder.service.js.map +1 -1
- package/dist/ai-instruction/ai-prompt-registry.d.ts +45 -0
- package/dist/ai-instruction/ai-prompt-registry.d.ts.map +1 -0
- package/dist/ai-instruction/ai-prompt-registry.js +49 -0
- package/dist/ai-instruction/ai-prompt-registry.js.map +1 -0
- package/dist/ai-instruction/ai-prompt-resolver.service.d.ts +89 -0
- package/dist/ai-instruction/ai-prompt-resolver.service.d.ts.map +1 -0
- package/dist/ai-instruction/ai-prompt-resolver.service.js +222 -0
- package/dist/ai-instruction/ai-prompt-resolver.service.js.map +1 -0
- package/dist/ai-instruction/ai-prompt-template.util.d.ts +70 -0
- package/dist/ai-instruction/ai-prompt-template.util.d.ts.map +1 -0
- package/dist/ai-instruction/ai-prompt-template.util.js +154 -0
- package/dist/ai-instruction/ai-prompt-template.util.js.map +1 -0
- package/dist/ai-instruction/dto/create-ai-instruction.dto.d.ts +5 -0
- package/dist/ai-instruction/dto/create-ai-instruction.dto.d.ts.map +1 -1
- package/dist/ai-instruction/dto/create-ai-instruction.dto.js +27 -1
- package/dist/ai-instruction/dto/create-ai-instruction.dto.js.map +1 -1
- package/dist/ai-instruction/dto/preview-ai-instruction.dto.d.ts +14 -0
- package/dist/ai-instruction/dto/preview-ai-instruction.dto.d.ts.map +1 -0
- package/dist/ai-instruction/dto/preview-ai-instruction.dto.js +42 -0
- package/dist/ai-instruction/dto/preview-ai-instruction.dto.js.map +1 -0
- package/dist/ai-instruction/dto/update-ai-instruction.dto.d.ts +11 -0
- package/dist/ai-instruction/dto/update-ai-instruction.dto.d.ts.map +1 -1
- package/dist/ai-instruction/dto/update-ai-instruction.dto.js +34 -0
- package/dist/ai-instruction/dto/update-ai-instruction.dto.js.map +1 -1
- package/dist/ai-instruction/types/ai-instruction.types.d.ts +13 -1
- package/dist/ai-instruction/types/ai-instruction.types.d.ts.map +1 -1
- package/dist/ai-instruction/types/ai-instruction.types.js +10 -0
- package/dist/ai-instruction/types/ai-instruction.types.js.map +1 -1
- package/dist/auth/auth.controller.d.ts +24 -9
- package/dist/auth/auth.controller.d.ts.map +1 -1
- package/dist/auth/auth.controller.js +49 -21
- package/dist/auth/auth.controller.js.map +1 -1
- package/dist/auth/auth.service.d.ts +33 -8
- package/dist/auth/auth.service.d.ts.map +1 -1
- package/dist/auth/auth.service.js +78 -29
- package/dist/auth/auth.service.js.map +1 -1
- package/dist/captcha/captcha.module.d.ts +3 -0
- package/dist/captcha/captcha.module.d.ts.map +1 -0
- package/dist/captcha/captcha.module.js +23 -0
- package/dist/captcha/captcha.module.js.map +1 -0
- package/dist/captcha/captcha.service.d.ts +38 -0
- package/dist/captcha/captcha.service.d.ts.map +1 -0
- package/dist/captcha/captcha.service.js +144 -0
- package/dist/captcha/captcha.service.js.map +1 -0
- package/dist/challenge/challenge.service.d.ts +16 -7
- package/dist/challenge/challenge.service.d.ts.map +1 -1
- package/dist/challenge/challenge.service.js +64 -16
- package/dist/challenge/challenge.service.js.map +1 -1
- package/dist/core.module.d.ts +3 -1
- package/dist/core.module.d.ts.map +1 -1
- package/dist/core.module.js +29 -2
- package/dist/core.module.js.map +1 -1
- package/dist/dashboard/dashboard/dashboard.controller.d.ts +15 -15
- package/dist/dashboard/dashboard/dashboard.service.d.ts +15 -15
- package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts +6 -6
- package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts +6 -6
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.d.ts +20 -20
- package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.d.ts +20 -20
- package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts +1 -1
- package/dist/dashboard/dashboard-role/dashboard-role.controller.d.ts +13 -13
- package/dist/dashboard/dashboard-role/dashboard-role.service.d.ts +13 -13
- package/dist/file/file.service.d.ts +6 -0
- package/dist/file/file.service.d.ts.map +1 -1
- package/dist/file/file.service.js +44 -4
- package/dist/file/file.service.js.map +1 -1
- package/dist/incident/incident-notifier.service.d.ts +36 -0
- package/dist/incident/incident-notifier.service.d.ts.map +1 -0
- package/dist/incident/incident-notifier.service.js +208 -0
- package/dist/incident/incident-notifier.service.js.map +1 -0
- package/dist/incident/incident.controller.d.ts +23 -0
- package/dist/incident/incident.controller.d.ts.map +1 -0
- package/dist/incident/incident.controller.js +75 -0
- package/dist/incident/incident.controller.js.map +1 -0
- package/dist/incident/incident.module.d.ts +7 -0
- package/dist/incident/incident.module.d.ts.map +1 -0
- package/dist/incident/incident.module.js +32 -0
- package/dist/incident/incident.module.js.map +1 -0
- package/dist/incident/incident.service.d.ts +72 -0
- package/dist/incident/incident.service.d.ts.map +1 -0
- package/dist/incident/incident.service.js +184 -0
- package/dist/incident/incident.service.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -1
- package/dist/integration-profile/dto/test.dto.d.ts +13 -0
- package/dist/integration-profile/dto/test.dto.d.ts.map +1 -0
- package/dist/integration-profile/dto/test.dto.js +26 -0
- package/dist/integration-profile/dto/test.dto.js.map +1 -0
- package/dist/integration-profile/integration-profile.controller.d.ts +12 -1
- package/dist/integration-profile/integration-profile.controller.d.ts.map +1 -1
- package/dist/integration-profile/integration-profile.controller.js +9 -1
- package/dist/integration-profile/integration-profile.controller.js.map +1 -1
- package/dist/integration-profile/integration-profile.module.d.ts +6 -1
- package/dist/integration-profile/integration-profile.module.d.ts.map +1 -1
- package/dist/integration-profile/integration-profile.module.js +26 -3
- package/dist/integration-profile/integration-profile.module.js.map +1 -1
- package/dist/integration-profile/integration-profile.secrets.d.ts.map +1 -1
- package/dist/integration-profile/integration-profile.secrets.js +9 -1
- package/dist/integration-profile/integration-profile.secrets.js.map +1 -1
- package/dist/integration-profile/integration-profile.service.d.ts +26 -7
- package/dist/integration-profile/integration-profile.service.d.ts.map +1 -1
- package/dist/integration-profile/integration-profile.service.js +94 -91
- package/dist/integration-profile/integration-profile.service.js.map +1 -1
- package/dist/integration-profile/integration-profile.utils.d.ts +13 -1
- package/dist/integration-profile/integration-profile.utils.d.ts.map +1 -1
- package/dist/integration-profile/integration-profile.utils.js +20 -5
- package/dist/integration-profile/integration-profile.utils.js.map +1 -1
- package/dist/integration-profile/testers/ai.testers.d.ts +3 -0
- package/dist/integration-profile/testers/ai.testers.d.ts.map +1 -0
- package/dist/integration-profile/testers/ai.testers.js +125 -0
- package/dist/integration-profile/testers/ai.testers.js.map +1 -0
- package/dist/integration-profile/testers/captcha.testers.d.ts +3 -0
- package/dist/integration-profile/testers/captcha.testers.d.ts.map +1 -0
- package/dist/integration-profile/testers/captcha.testers.js +121 -0
- package/dist/integration-profile/testers/captcha.testers.js.map +1 -0
- package/dist/integration-profile/testers/email.testers.d.ts +3 -0
- package/dist/integration-profile/testers/email.testers.d.ts.map +1 -0
- package/dist/integration-profile/testers/email.testers.js +128 -0
- package/dist/integration-profile/testers/email.testers.js.map +1 -0
- package/dist/integration-profile/testers/http-probe.d.ts +57 -0
- package/dist/integration-profile/testers/http-probe.d.ts.map +1 -0
- package/dist/integration-profile/testers/http-probe.js +140 -0
- package/dist/integration-profile/testers/http-probe.js.map +1 -0
- package/dist/integration-profile/testers/index.d.ts +12 -0
- package/dist/integration-profile/testers/index.d.ts.map +1 -0
- package/dist/integration-profile/testers/index.js +45 -0
- package/dist/integration-profile/testers/index.js.map +1 -0
- package/dist/integration-profile/testers/infrastructure.testers.d.ts +3 -0
- package/dist/integration-profile/testers/infrastructure.testers.d.ts.map +1 -0
- package/dist/integration-profile/testers/infrastructure.testers.js +105 -0
- package/dist/integration-profile/testers/infrastructure.testers.js.map +1 -0
- package/dist/integration-profile/testers/integration-tester.registry.d.ts +17 -0
- package/dist/integration-profile/testers/integration-tester.registry.d.ts.map +1 -0
- package/dist/integration-profile/testers/integration-tester.registry.js +52 -0
- package/dist/integration-profile/testers/integration-tester.registry.js.map +1 -0
- package/dist/integration-profile/testers/integration-tester.types.d.ts +55 -0
- package/dist/integration-profile/testers/integration-tester.types.d.ts.map +1 -0
- package/dist/integration-profile/testers/integration-tester.types.js +16 -0
- package/dist/integration-profile/testers/integration-tester.types.js.map +1 -0
- package/dist/integration-profile/testers/messaging.testers.d.ts +3 -0
- package/dist/integration-profile/testers/messaging.testers.d.ts.map +1 -0
- package/dist/integration-profile/testers/messaging.testers.js +70 -0
- package/dist/integration-profile/testers/messaging.testers.js.map +1 -0
- package/dist/integration-profile/testers/oauth.testers.d.ts +3 -0
- package/dist/integration-profile/testers/oauth.testers.d.ts.map +1 -0
- package/dist/integration-profile/testers/oauth.testers.js +285 -0
- package/dist/integration-profile/testers/oauth.testers.js.map +1 -0
- package/dist/integration-profile/testers/payment.testers.d.ts +3 -0
- package/dist/integration-profile/testers/payment.testers.d.ts.map +1 -0
- package/dist/integration-profile/testers/payment.testers.js +169 -0
- package/dist/integration-profile/testers/payment.testers.js.map +1 -0
- package/dist/integration-profile/testers/storage.testers.d.ts +3 -0
- package/dist/integration-profile/testers/storage.testers.d.ts.map +1 -0
- package/dist/integration-profile/testers/storage.testers.js +208 -0
- package/dist/integration-profile/testers/storage.testers.js.map +1 -0
- package/dist/language/en.json +4 -2
- package/dist/language/pt.json +4 -2
- package/dist/leaked-password/leaked-password.controller.d.ts +24 -0
- package/dist/leaked-password/leaked-password.controller.d.ts.map +1 -0
- package/dist/leaked-password/leaked-password.controller.js +78 -0
- package/dist/leaked-password/leaked-password.controller.js.map +1 -0
- package/dist/leaked-password/leaked-password.module.d.ts +8 -0
- package/dist/leaked-password/leaked-password.module.d.ts.map +1 -0
- package/dist/leaked-password/leaked-password.module.js +31 -0
- package/dist/leaked-password/leaked-password.module.js.map +1 -0
- package/dist/leaked-password/leaked-password.service.d.ts +64 -0
- package/dist/leaked-password/leaked-password.service.d.ts.map +1 -0
- package/dist/leaked-password/leaked-password.service.js +218 -0
- package/dist/leaked-password/leaked-password.service.js.map +1 -0
- package/dist/locale/locale.controller.d.ts +1 -1
- package/dist/locale/locale.service.d.ts +1 -1
- package/dist/mail/dto/preview.dto.d.ts +18 -0
- package/dist/mail/dto/preview.dto.d.ts.map +1 -0
- package/dist/mail/dto/preview.dto.js +66 -0
- package/dist/mail/dto/preview.dto.js.map +1 -0
- package/dist/mail/dto/send.dto.d.ts +7 -0
- package/dist/mail/dto/send.dto.d.ts.map +1 -1
- package/dist/mail/dto/send.dto.js +10 -0
- package/dist/mail/dto/send.dto.js.map +1 -1
- package/dist/mail/mail.controller.d.ts +4 -0
- package/dist/mail/mail.controller.d.ts.map +1 -1
- package/dist/mail/mail.controller.js +16 -2
- package/dist/mail/mail.controller.js.map +1 -1
- package/dist/mail/mail.service.d.ts +23 -2
- package/dist/mail/mail.service.d.ts.map +1 -1
- package/dist/mail/mail.service.js +102 -13
- package/dist/mail/mail.service.js.map +1 -1
- package/dist/mail-layout/dto/update.dto.d.ts +17 -0
- package/dist/mail-layout/dto/update.dto.d.ts.map +1 -0
- package/dist/mail-layout/dto/update.dto.js +27 -0
- package/dist/mail-layout/dto/update.dto.js.map +1 -0
- package/dist/mail-layout/mail-layout.controller.d.ts +15 -0
- package/dist/mail-layout/mail-layout.controller.d.ts.map +1 -0
- package/dist/mail-layout/mail-layout.controller.js +71 -0
- package/dist/mail-layout/mail-layout.controller.js.map +1 -0
- package/dist/mail-layout/mail-layout.module.d.ts +3 -0
- package/dist/mail-layout/mail-layout.module.d.ts.map +1 -0
- package/dist/mail-layout/mail-layout.module.js +35 -0
- package/dist/mail-layout/mail-layout.module.js.map +1 -0
- package/dist/mail-layout/mail-layout.service.d.ts +27 -0
- package/dist/mail-layout/mail-layout.service.d.ts.map +1 -0
- package/dist/mail-layout/mail-layout.service.js +80 -0
- package/dist/mail-layout/mail-layout.service.js.map +1 -0
- package/dist/mcp-chat/mcp-chat.controller.d.ts +2 -2
- package/dist/mcp-chat/mcp-chat.service.d.ts +24 -2
- package/dist/mcp-chat/mcp-chat.service.d.ts.map +1 -1
- package/dist/mcp-chat/mcp-chat.service.js +80 -24
- package/dist/mcp-chat/mcp-chat.service.js.map +1 -1
- package/dist/menu/menu.controller.d.ts +3 -3
- package/dist/menu/menu.service.d.ts +3 -3
- package/dist/notification/notification.controller.d.ts +12 -12
- package/dist/notification/notification.service.d.ts +12 -12
- package/dist/oauth/oauth-token-broker.service.d.ts +72 -0
- package/dist/oauth/oauth-token-broker.service.d.ts.map +1 -0
- package/dist/oauth/oauth-token-broker.service.js +258 -0
- package/dist/oauth/oauth-token-broker.service.js.map +1 -0
- package/dist/oauth/oauth.module.d.ts.map +1 -1
- package/dist/oauth/oauth.module.js +3 -1
- package/dist/oauth/oauth.module.js.map +1 -1
- package/dist/oauth/oauth.service.d.ts +2 -0
- package/dist/oauth/oauth.service.d.ts.map +1 -1
- package/dist/oauth/oauth.service.js +6 -3
- package/dist/oauth/oauth.service.js.map +1 -1
- package/dist/pdf/pdf.service.d.ts +8 -0
- package/dist/pdf/pdf.service.d.ts.map +1 -1
- package/dist/pdf/pdf.service.js +52 -0
- package/dist/pdf/pdf.service.js.map +1 -1
- package/dist/presence/presence.controller.d.ts +16 -0
- package/dist/presence/presence.controller.d.ts.map +1 -0
- package/dist/presence/presence.controller.js +60 -0
- package/dist/presence/presence.controller.js.map +1 -0
- package/dist/presence/presence.listener.d.ts +29 -0
- package/dist/presence/presence.listener.d.ts.map +1 -0
- package/dist/presence/presence.listener.js +82 -0
- package/dist/presence/presence.listener.js.map +1 -0
- package/dist/presence/presence.module.d.ts +3 -0
- package/dist/presence/presence.module.d.ts.map +1 -0
- package/dist/presence/presence.module.js +32 -0
- package/dist/presence/presence.module.js.map +1 -0
- package/dist/presence/presence.service.d.ts +42 -0
- package/dist/presence/presence.service.d.ts.map +1 -0
- package/dist/presence/presence.service.js +147 -0
- package/dist/presence/presence.service.js.map +1 -0
- package/dist/profile/dto/delete-account.dto.d.ts +8 -0
- package/dist/profile/dto/delete-account.dto.d.ts.map +1 -0
- package/dist/profile/dto/delete-account.dto.js +22 -0
- package/dist/profile/dto/delete-account.dto.js.map +1 -0
- package/dist/profile/events/profile-account-deleted.event.d.ts +12 -0
- package/dist/profile/events/profile-account-deleted.event.d.ts.map +1 -0
- package/dist/profile/events/profile-account-deleted.event.js +17 -0
- package/dist/profile/events/profile-account-deleted.event.js.map +1 -0
- package/dist/profile/profile.controller.d.ts +21 -15
- package/dist/profile/profile.controller.d.ts.map +1 -1
- package/dist/profile/profile.controller.js +75 -46
- package/dist/profile/profile.controller.js.map +1 -1
- package/dist/profile/profile.service.d.ts +30 -18
- package/dist/profile/profile.service.d.ts.map +1 -1
- package/dist/profile/profile.service.js +113 -37
- package/dist/profile/profile.service.js.map +1 -1
- package/dist/realtime/realtime.gateway.d.ts +48 -0
- package/dist/realtime/realtime.gateway.d.ts.map +1 -0
- package/dist/realtime/realtime.gateway.js +156 -0
- package/dist/realtime/realtime.gateway.js.map +1 -0
- package/dist/realtime/realtime.module.d.ts +8 -0
- package/dist/realtime/realtime.module.d.ts.map +1 -0
- package/dist/realtime/realtime.module.js +29 -0
- package/dist/realtime/realtime.module.js.map +1 -0
- package/dist/realtime/realtime.service.d.ts +51 -0
- package/dist/realtime/realtime.service.d.ts.map +1 -0
- package/dist/realtime/realtime.service.js +177 -0
- package/dist/realtime/realtime.service.js.map +1 -0
- package/dist/redis/redis-pubsub.d.ts +27 -0
- package/dist/redis/redis-pubsub.d.ts.map +1 -0
- package/dist/redis/redis-pubsub.js +140 -0
- package/dist/redis/redis-pubsub.js.map +1 -0
- package/dist/role/role.controller.d.ts +3 -3
- package/dist/role/role.service.d.ts +3 -3
- package/dist/setting/dto/create.dto.d.ts.map +1 -1
- package/dist/setting/dto/create.dto.js +9 -2
- package/dist/setting/dto/create.dto.js.map +1 -1
- package/dist/setting/setting.controller.d.ts +5 -5
- package/dist/setting/setting.service.d.ts +8 -5
- package/dist/setting/setting.service.d.ts.map +1 -1
- package/dist/setting/setting.service.js +25 -1
- package/dist/setting/setting.service.js.map +1 -1
- package/dist/user/dto/create-with-email-and-password.dto.d.ts +2 -0
- package/dist/user/dto/create-with-email-and-password.dto.d.ts.map +1 -1
- package/dist/user/dto/create-with-email-and-password.dto.js +5 -0
- package/dist/user/dto/create-with-email-and-password.dto.js.map +1 -1
- package/dist/user/dto/query-user-mail-list.dto.d.ts +5 -0
- package/dist/user/dto/query-user-mail-list.dto.d.ts.map +1 -0
- package/dist/user/dto/query-user-mail-list.dto.js +25 -0
- package/dist/user/dto/query-user-mail-list.dto.js.map +1 -0
- package/dist/user/user-credential.util.d.ts +19 -0
- package/dist/user/user-credential.util.d.ts.map +1 -0
- package/dist/user/user-credential.util.js +32 -0
- package/dist/user/user-credential.util.js.map +1 -0
- package/dist/user/user.controller.d.ts +17 -5
- package/dist/user/user.controller.d.ts.map +1 -1
- package/dist/user/user.controller.js +18 -3
- package/dist/user/user.controller.js.map +1 -1
- package/dist/user/user.service.d.ts +28 -6
- package/dist/user/user.service.d.ts.map +1 -1
- package/dist/user/user.service.js +204 -13
- package/dist/user/user.service.js.map +1 -1
- package/dist/validators/is-strong-password-with-settings.validator.d.ts.map +1 -1
- package/dist/validators/is-strong-password-with-settings.validator.js +11 -0
- package/dist/validators/is-strong-password-with-settings.validator.js.map +1 -1
- package/dist/validators/service-locator.d.ts +9 -0
- package/dist/validators/service-locator.d.ts.map +1 -1
- package/dist/validators/service-locator.js +12 -0
- package/dist/validators/service-locator.js.map +1 -1
- package/dist/whatsapp-sender/whatsapp-sender.module.d.ts +3 -0
- package/dist/whatsapp-sender/whatsapp-sender.module.d.ts.map +1 -0
- package/dist/whatsapp-sender/whatsapp-sender.module.js +23 -0
- package/dist/whatsapp-sender/whatsapp-sender.module.js.map +1 -0
- package/dist/whatsapp-sender/whatsapp-sender.service.d.ts +50 -0
- package/dist/whatsapp-sender/whatsapp-sender.service.d.ts.map +1 -0
- package/dist/whatsapp-sender/whatsapp-sender.service.js +224 -0
- package/dist/whatsapp-sender/whatsapp-sender.service.js.map +1 -0
- package/hedhog/data/integration_provider.yaml +16 -0
- package/hedhog/data/mail.yaml +88 -61
- package/hedhog/data/mail_layout.yaml +188 -0
- package/hedhog/data/menu.yaml +67 -3
- package/hedhog/data/route.yaml +135 -0
- package/hedhog/data/setting_group.yaml +139 -1
- package/hedhog/frontend/app/account/components/mfa-setup-dialog.tsx.ejs +36 -0
- package/hedhog/frontend/app/account/components/two-factor-auth.tsx.ejs +2 -0
- package/hedhog/frontend/app/account/hooks/use-mfa-setup.ts.ejs +10 -7
- package/hedhog/frontend/app/ai_agent/page.tsx.ejs +7 -4
- package/hedhog/frontend/app/ai_instruction/_components/ai-instruction-form.tsx.ejs +580 -0
- package/hedhog/frontend/app/ai_instruction/_components/ai-instruction-preview.tsx.ejs +150 -0
- package/hedhog/frontend/app/ai_instruction/_components/ai-instruction-versions.tsx.ejs +199 -0
- package/hedhog/frontend/app/ai_instruction/_components/prompt-diff.tsx.ejs +63 -0
- package/hedhog/frontend/app/ai_instruction/_lib/line-diff.spec.ts.ejs +59 -0
- package/hedhog/frontend/app/ai_instruction/_lib/line-diff.ts.ejs +72 -0
- package/hedhog/frontend/app/ai_instruction/_lib/prompt-template.spec.ts.ejs +170 -0
- package/hedhog/frontend/app/ai_instruction/_lib/prompt-template.ts.ejs +167 -0
- package/hedhog/frontend/app/ai_instruction/_lib/types.ts.ejs +99 -0
- package/hedhog/frontend/app/ai_instruction/page.tsx.ejs +422 -0
- package/hedhog/frontend/app/configurations/[slug]/components/setting-field.tsx.ejs +51 -4
- package/hedhog/frontend/app/incidents/page.tsx.ejs +400 -0
- package/hedhog/frontend/app/integration/profiles/page.tsx.ejs +153 -84
- package/hedhog/frontend/app/mail/layout/page.tsx.ejs +344 -0
- package/hedhog/frontend/app/mail/template/page.tsx.ejs +155 -121
- package/hedhog/frontend/app/mcp_chat/page.tsx.ejs +129 -17
- package/hedhog/frontend/app/pages/_components/page-delete-dialog.tsx.ejs +343 -0
- package/hedhog/frontend/app/pages/_components/page-detail-sheet.tsx.ejs +438 -0
- package/hedhog/frontend/app/pages/_components/page-wizard-sheet.tsx.ejs +1009 -0
- package/hedhog/frontend/app/pages/_components/system-page-types.ts.ejs +56 -0
- package/hedhog/frontend/app/pages/_components/use-system-pages.ts.ejs +171 -0
- package/hedhog/frontend/app/pages/page.tsx.ejs +514 -0
- package/hedhog/frontend/app/users/page.tsx.ejs +119 -13
- package/hedhog/frontend/app/users/user-activity-timeline.tsx.ejs +231 -0
- package/hedhog/frontend/app/users/user-mails.tsx.ejs +399 -0
- package/hedhog/frontend/app/users/user-sheet.tsx.ejs +60 -75
- package/hedhog/frontend/messages/en.json +499 -3
- package/hedhog/frontend/messages/pt.json +499 -3
- package/hedhog/table/ai_agent.yaml +1 -0
- package/hedhog/table/ai_instruction.yaml +15 -0
- package/hedhog/table/leaked_password.yaml +18 -0
- package/hedhog/table/mail_layout.yaml +35 -0
- package/hedhog/table/mail_var.yaml +4 -0
- package/hedhog/table/setting.yaml +1 -0
- package/hedhog/table/system_incident.yaml +59 -0
- package/hedhog/table/user_presence.yaml +36 -0
- package/package.json +8 -4
- package/src/access-log/access-log.interceptor.ts +4 -2
- package/src/ai/ai-attachment.fragments.spec.ts +319 -0
- package/src/ai/ai-attachment.fragments.ts +35 -0
- package/src/ai/ai.prompts.ts +38 -0
- package/src/ai/ai.service.spec.ts +280 -0
- package/src/ai/ai.service.ts +338 -82
- package/src/ai/dto/chat.dto.ts +33 -3
- package/src/ai/dto/create-agent.dto.ts +2 -2
- package/src/ai/dto/update-agent.dto.ts +2 -2
- package/src/ai-instruction/ai-instruction.controller.ts +40 -9
- package/src/ai-instruction/ai-instruction.module.ts +13 -2
- package/src/ai-instruction/ai-instruction.service.spec.ts +658 -0
- package/src/ai-instruction/ai-instruction.service.ts +661 -62
- package/src/ai-instruction/ai-prompt-builder.service.ts +10 -1
- package/src/ai-instruction/ai-prompt-registry.ts +87 -0
- package/src/ai-instruction/ai-prompt-resolver.service.spec.ts +375 -0
- package/src/ai-instruction/ai-prompt-resolver.service.ts +295 -0
- package/src/ai-instruction/ai-prompt-template.util.spec.ts +162 -0
- package/src/ai-instruction/ai-prompt-template.util.ts +199 -0
- package/src/ai-instruction/dto/create-ai-instruction.dto.ts +39 -3
- package/src/ai-instruction/dto/preview-ai-instruction.dto.ts +26 -0
- package/src/ai-instruction/dto/update-ai-instruction.dto.ts +42 -1
- package/src/ai-instruction/types/ai-instruction.types.ts +24 -1
- package/src/auth/auth.controller.ts +31 -5
- package/src/auth/auth.service.spec.ts +3 -1
- package/src/auth/auth.service.ts +101 -36
- package/src/captcha/captcha.module.ts +10 -0
- package/src/captcha/captcha.service.spec.ts +210 -0
- package/src/captcha/captcha.service.ts +191 -0
- package/src/challenge/challenge.service.spec.ts +39 -4
- package/src/challenge/challenge.service.ts +72 -17
- package/src/core.module.ts +27 -1
- package/src/file/file.service.spec.ts +105 -0
- package/src/file/file.service.ts +60 -3
- package/src/incident/incident-notifier.service.spec.ts +205 -0
- package/src/incident/incident-notifier.service.ts +241 -0
- package/src/incident/incident.controller.ts +38 -0
- package/src/incident/incident.module.ts +19 -0
- package/src/incident/incident.service.spec.ts +150 -0
- package/src/incident/incident.service.ts +209 -0
- package/src/index.ts +37 -0
- package/src/integration-profile/dto/test.dto.ts +19 -0
- package/src/integration-profile/integration-profile.controller.ts +10 -1
- package/src/integration-profile/integration-profile.module.spec.ts +51 -0
- package/src/integration-profile/integration-profile.module.ts +23 -4
- package/src/integration-profile/integration-profile.secrets.ts +9 -1
- package/src/integration-profile/integration-profile.service.spec.ts +279 -0
- package/src/integration-profile/integration-profile.service.ts +120 -124
- package/src/integration-profile/integration-profile.utils.spec.ts +22 -0
- package/src/integration-profile/integration-profile.utils.ts +40 -3
- package/src/integration-profile/testers/ai.testers.ts +165 -0
- package/src/integration-profile/testers/captcha.testers.spec.ts +92 -0
- package/src/integration-profile/testers/captcha.testers.ts +139 -0
- package/src/integration-profile/testers/email.testers.ts +161 -0
- package/src/integration-profile/testers/http-probe.spec.ts +153 -0
- package/src/integration-profile/testers/http-probe.ts +171 -0
- package/src/integration-profile/testers/index.ts +30 -0
- package/src/integration-profile/testers/infrastructure.testers.ts +122 -0
- package/src/integration-profile/testers/integration-tester.registry.spec.ts +75 -0
- package/src/integration-profile/testers/integration-tester.registry.ts +43 -0
- package/src/integration-profile/testers/integration-tester.types.ts +61 -0
- package/src/integration-profile/testers/messaging.testers.ts +102 -0
- package/src/integration-profile/testers/oauth.testers.spec.ts +220 -0
- package/src/integration-profile/testers/oauth.testers.ts +305 -0
- package/src/integration-profile/testers/payment.testers.ts +185 -0
- package/src/integration-profile/testers/remaining.testers.spec.ts +401 -0
- package/src/integration-profile/testers/storage.testers.spec.ts +185 -0
- package/src/integration-profile/testers/storage.testers.ts +226 -0
- package/src/integration-profile/testers/tester-coverage.spec.ts +58 -0
- package/src/language/en.json +4 -2
- package/src/language/pt.json +4 -2
- package/src/leaked-password/README.md +83 -0
- package/src/leaked-password/leaked-password.controller.ts +52 -0
- package/src/leaked-password/leaked-password.module.ts +18 -0
- package/src/leaked-password/leaked-password.service.ts +242 -0
- package/src/leaked-password/seed/build-seed-sql.mjs +180 -0
- package/src/leaked-password/seed/common-passwords.txt +335 -0
- package/src/mail/dto/preview.dto.ts +50 -0
- package/src/mail/dto/send.dto.ts +14 -1
- package/src/mail/mail-template.spec.ts +197 -0
- package/src/mail/mail.controller.ts +9 -2
- package/src/mail/mail.service.spec.ts +116 -1
- package/src/mail/mail.service.ts +118 -12
- package/src/mail-layout/dto/update.dto.ts +19 -0
- package/src/mail-layout/mail-layout.controller.ts +47 -0
- package/src/mail-layout/mail-layout.module.ts +22 -0
- package/src/mail-layout/mail-layout.service.ts +94 -0
- package/src/mcp-chat/mcp-chat.service.spec.ts +236 -0
- package/src/mcp-chat/mcp-chat.service.ts +122 -26
- package/src/oauth/oauth-token-broker.service.spec.ts +172 -0
- package/src/oauth/oauth-token-broker.service.ts +363 -0
- package/src/oauth/oauth.module.ts +3 -1
- package/src/oauth/oauth.service.ts +8 -2
- package/src/pdf/pdf.service.ts +75 -0
- package/src/presence/presence.controller.ts +29 -0
- package/src/presence/presence.listener.ts +53 -0
- package/src/presence/presence.module.ts +19 -0
- package/src/presence/presence.service.spec.ts +97 -0
- package/src/presence/presence.service.ts +160 -0
- package/src/profile/dto/delete-account.dto.ts +11 -0
- package/src/profile/events/profile-account-deleted.event.ts +13 -0
- package/src/profile/profile.controller.ts +46 -34
- package/src/profile/profile.service.ts +138 -38
- package/src/realtime/realtime.gateway.ts +138 -0
- package/src/realtime/realtime.module.ts +16 -0
- package/src/realtime/realtime.service.spec.ts +50 -0
- package/src/realtime/realtime.service.ts +187 -0
- package/src/redis/redis-pubsub.ts +179 -0
- package/src/setting/dto/create.dto.ts +13 -2
- package/src/setting/setting.service.spec.ts +56 -0
- package/src/setting/setting.service.ts +29 -1
- package/src/user/dto/create-with-email-and-password.dto.ts +6 -1
- package/src/user/dto/query-user-mail-list.dto.ts +10 -0
- package/src/user/user-credential.util.ts +35 -0
- package/src/user/user.controller.ts +17 -2
- package/src/user/user.service.spec.ts +153 -0
- package/src/user/user.service.ts +255 -12
- package/src/validators/is-strong-password-with-settings.validator.ts +12 -0
- package/src/validators/service-locator.ts +15 -0
- package/src/whatsapp-sender/whatsapp-sender.module.ts +10 -0
- package/src/whatsapp-sender/whatsapp-sender.service.ts +313 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mirrors `libraries/core/src/ai-instruction/ai-prompt-template.util.spec.ts`.
|
|
3
|
+
* The implementation is duplicated between the backend and the admin (see the
|
|
4
|
+
* header of `prompt-template.ts`); these shared cases are what keeps the two
|
|
5
|
+
* copies from drifting apart.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, it } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
PromptTemplateError,
|
|
11
|
+
estimateTokens,
|
|
12
|
+
extractPlaceholders,
|
|
13
|
+
renderTemplate,
|
|
14
|
+
validateTemplate,
|
|
15
|
+
} from './prompt-template';
|
|
16
|
+
|
|
17
|
+
describe('renderTemplate', () => {
|
|
18
|
+
it('substitui {{var}} pelo valor', () => {
|
|
19
|
+
expect(renderTemplate('Olá {{nome}}!', { nome: 'Ana' })).toBe('Olá Ana!');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('mantém o placeholder literal quando a variável não foi informada', () => {
|
|
23
|
+
expect(renderTemplate('Olá {{nome}}!', {})).toBe('Olá {{nome}}!');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('trata null e undefined como string vazia quando a chave existe', () => {
|
|
27
|
+
expect(renderTemplate('[{{a}}][{{b}}]', { a: null, b: undefined })).toBe('[][{{b}}]');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('converte números e booleanos', () => {
|
|
31
|
+
expect(renderTemplate('{{n}} / {{b}}', { n: 42, b: true })).toBe('42 / true');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('renderiza bloco {{#var}} quando a variável é truthy', () => {
|
|
35
|
+
expect(renderTemplate('a{{#x}}SIM{{/x}}b', { x: true })).toBe('aSIMb');
|
|
36
|
+
expect(renderTemplate('a{{#x}}SIM{{/x}}b', { x: false })).toBe('ab');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('renderiza bloco {{^var}} quando a variável é falsy', () => {
|
|
40
|
+
expect(renderTemplate('a{{^x}}NAO{{/x}}b', { x: false })).toBe('aNAOb');
|
|
41
|
+
expect(renderTemplate('a{{^x}}NAO{{/x}}b', { x: true })).toBe('ab');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('trata as strings "false" e "0" como falsy', () => {
|
|
45
|
+
expect(renderTemplate('{{#x}}SIM{{/x}}', { x: 'false' })).toBe('');
|
|
46
|
+
expect(renderTemplate('{{#x}}SIM{{/x}}', { x: '0' })).toBe('');
|
|
47
|
+
expect(renderTemplate('{{#x}}SIM{{/x}}', { x: ' ' })).toBe('');
|
|
48
|
+
expect(renderTemplate('{{#x}}SIM{{/x}}', { x: 0 })).toBe('');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('substitui variáveis dentro de um bloco mantido', () => {
|
|
52
|
+
expect(renderTemplate('{{#tem}}Tom: {{tom}}{{/tem}}', { tem: true, tom: 'formal' })).toBe(
|
|
53
|
+
'Tom: formal',
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('não substitui variáveis dentro de um bloco descartado', () => {
|
|
58
|
+
expect(renderTemplate('{{#tem}}Tom: {{tom}}{{/tem}}fim', { tem: false, tom: 'formal' })).toBe(
|
|
59
|
+
'fim',
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('resolve blocos irmãos independentes', () => {
|
|
64
|
+
const template = '{{#a}}A{{/a}}{{^a}}nao-A{{/a}}|{{#b}}B{{/b}}';
|
|
65
|
+
expect(renderTemplate(template, { a: true, b: false })).toBe('A|');
|
|
66
|
+
expect(renderTemplate(template, { a: false, b: true })).toBe('nao-A|B');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('lança quando um bloco não é fechado', () => {
|
|
70
|
+
expect(() => renderTemplate('inicio {{#x}}corpo sem fim', { x: true })).toThrow(
|
|
71
|
+
PromptTemplateError,
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('preserva chaves de JSON no corpo do prompt', () => {
|
|
76
|
+
const template = 'Retorne {"isCorrect": boolean, "score": number} para {{aluno}}';
|
|
77
|
+
expect(renderTemplate(template, { aluno: 'Ana' })).toBe(
|
|
78
|
+
'Retorne {"isCorrect": boolean, "score": number} para Ana',
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('preserva chaves triplas e chaves soltas', () => {
|
|
83
|
+
expect(renderTemplate('{{{x}}}', { x: 'v' })).toBe('{v}');
|
|
84
|
+
expect(renderTemplate('{ nao é placeholder }', {})).toBe('{ nao é placeholder }');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('não interpreta placeholders com hífen ou ponto', () => {
|
|
88
|
+
expect(renderTemplate('{{a-b}} {{a.b}}', { 'a-b': 'x' })).toBe('{{a-b}} {{a.b}}');
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('extractPlaceholders', () => {
|
|
93
|
+
it('separa substituições de blocos', () => {
|
|
94
|
+
const result = extractPlaceholders('{{a}} {{#b}}{{c}}{{/b}} {{^d}}{{/d}}');
|
|
95
|
+
expect(result.substitutions.sort()).toEqual(['a', 'c']);
|
|
96
|
+
expect(result.blocks.sort()).toEqual(['b', 'd']);
|
|
97
|
+
expect(result.unbalanced).toEqual([]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('detecta bloco aberto sem fechamento', () => {
|
|
101
|
+
expect(extractPlaceholders('{{#a}}texto').unbalanced).toEqual(['a']);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('detecta fechamento sem abertura', () => {
|
|
105
|
+
expect(extractPlaceholders('texto{{/a}}').unbalanced).toEqual(['a']);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('não duplica nomes repetidos', () => {
|
|
109
|
+
expect(extractPlaceholders('{{a}} {{a}}').substitutions).toEqual(['a']);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('validateTemplate', () => {
|
|
114
|
+
const schema = {
|
|
115
|
+
version: 1 as const,
|
|
116
|
+
variables: {
|
|
117
|
+
obrigatoria: { type: 'string' as const, required: true },
|
|
118
|
+
opcional: { type: 'string' as const },
|
|
119
|
+
condicional: { type: 'boolean' as const, required: true, conditional: true },
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
it('aceita um template que usa todas as obrigatórias', () => {
|
|
124
|
+
const result = validateTemplate('{{obrigatoria}} {{#condicional}}x{{/condicional}}', schema);
|
|
125
|
+
expect(result.missingRequired).toEqual([]);
|
|
126
|
+
expect(result.unknownPlaceholders).toEqual([]);
|
|
127
|
+
expect(result.unbalancedBlocks).toEqual([]);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('reporta obrigatória removida', () => {
|
|
131
|
+
const result = validateTemplate('{{#condicional}}x{{/condicional}}', schema);
|
|
132
|
+
expect(result.missingRequired).toEqual(['obrigatoria']);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('aceita a condicional usada apenas como bloco', () => {
|
|
136
|
+
const result = validateTemplate('{{obrigatoria}}{{^condicional}}y{{/condicional}}', schema);
|
|
137
|
+
expect(result.missingRequired).toEqual([]);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('reporta placeholder desconhecido', () => {
|
|
141
|
+
const result = validateTemplate(
|
|
142
|
+
'{{obrigatoria}} {{#condicional}}{{/condicional}} {{typo}}',
|
|
143
|
+
schema,
|
|
144
|
+
);
|
|
145
|
+
expect(result.unknownPlaceholders).toEqual(['typo']);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('reporta bloco não balanceado', () => {
|
|
149
|
+
const result = validateTemplate('{{obrigatoria}} {{#condicional}}sem fim', schema);
|
|
150
|
+
expect(result.unbalancedBlocks).toEqual(['condicional']);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('não reporta desconhecidos quando não há schema declarado', () => {
|
|
154
|
+
const result = validateTemplate('{{qualquer}}', null);
|
|
155
|
+
expect(result.unknownPlaceholders).toEqual([]);
|
|
156
|
+
expect(result.missingRequired).toEqual([]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('aceita um mapa de variáveis sem o envelope version/variables', () => {
|
|
160
|
+
const result = validateTemplate('{{a}}', { a: { type: 'string', required: true } });
|
|
161
|
+
expect(result.missingRequired).toEqual([]);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe('estimateTokens', () => {
|
|
166
|
+
it('estima aproximadamente 4 caracteres por token', () => {
|
|
167
|
+
expect(estimateTokens('12345678')).toBe(2);
|
|
168
|
+
expect(estimateTokens('')).toBe(0);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side copy of the prompt template engine from
|
|
3
|
+
* `libraries/core/src/ai-instruction/ai-prompt-template.util.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Duplicated on purpose: the editor validates on every keystroke, and a
|
|
6
|
+
* round-trip per character is not acceptable. The alternative — moving this into
|
|
7
|
+
* `packages/api-types` — would put logic into a package that is types-only today
|
|
8
|
+
* and is consumed by everything.
|
|
9
|
+
*
|
|
10
|
+
* Kept honest by `prompt-template.spec.ts` on both sides sharing the same case
|
|
11
|
+
* list. If you change one, change the other.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type VariableSpec = {
|
|
15
|
+
type: 'string' | 'number' | 'boolean';
|
|
16
|
+
required?: boolean;
|
|
17
|
+
conditional?: boolean;
|
|
18
|
+
description?: string;
|
|
19
|
+
sample?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type VariablesSchema = {
|
|
23
|
+
version: 1;
|
|
24
|
+
variables: Record<string, VariableSpec>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type TemplateVars = Record<string, string | number | boolean | null | undefined>;
|
|
28
|
+
|
|
29
|
+
export type TemplatePlaceholders = {
|
|
30
|
+
substitutions: string[];
|
|
31
|
+
blocks: string[];
|
|
32
|
+
unbalanced: string[];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type TemplateValidation = {
|
|
36
|
+
missingRequired: string[];
|
|
37
|
+
unknownPlaceholders: string[];
|
|
38
|
+
unbalancedBlocks: string[];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const SUBSTITUTION_RE = /\{\{(\w+)\}\}/g;
|
|
42
|
+
const BLOCK_OPEN_RE = /\{\{([#^])(\w+)\}\}/g;
|
|
43
|
+
const BLOCK_CLOSE_RE = /\{\{\/(\w+)\}\}/g;
|
|
44
|
+
|
|
45
|
+
export class PromptTemplateError extends Error {
|
|
46
|
+
constructor(message: string) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.name = 'PromptTemplateError';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isTruthy(value: TemplateVars[string]): boolean {
|
|
53
|
+
if (value === undefined || value === null) return false;
|
|
54
|
+
if (typeof value === 'boolean') return value;
|
|
55
|
+
if (typeof value === 'number') return value !== 0;
|
|
56
|
+
|
|
57
|
+
const trimmed = value.trim();
|
|
58
|
+
if (!trimmed) return false;
|
|
59
|
+
return trimmed !== 'false' && trimmed !== '0';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function stringify(value: TemplateVars[string]): string {
|
|
63
|
+
if (value === undefined || value === null) return '';
|
|
64
|
+
return String(value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function renderTemplate(template: string, vars: TemplateVars = {}): string {
|
|
68
|
+
const rendered = renderBlocks(template, vars);
|
|
69
|
+
|
|
70
|
+
return rendered.replace(SUBSTITUTION_RE, (match, key: string) => {
|
|
71
|
+
const value = vars[key];
|
|
72
|
+
return value === undefined ? match : stringify(value);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function renderBlocks(template: string, vars: TemplateVars): string {
|
|
77
|
+
let result = '';
|
|
78
|
+
let cursor = 0;
|
|
79
|
+
|
|
80
|
+
const openRe = new RegExp(BLOCK_OPEN_RE.source, 'g');
|
|
81
|
+
let open: RegExpExecArray | null;
|
|
82
|
+
|
|
83
|
+
while ((open = openRe.exec(template)) !== null) {
|
|
84
|
+
const openTag = open[0];
|
|
85
|
+
const kind = open[1] ?? '#';
|
|
86
|
+
const name = open[2] ?? '';
|
|
87
|
+
const bodyStart = open.index + openTag.length;
|
|
88
|
+
const closeTag = `{{/${name}}}`;
|
|
89
|
+
const closeIndex = template.indexOf(closeTag, bodyStart);
|
|
90
|
+
|
|
91
|
+
if (closeIndex === -1) {
|
|
92
|
+
throw new PromptTemplateError(`Unclosed template block "{{${kind}${name}}}".`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
result += template.slice(cursor, open.index);
|
|
96
|
+
|
|
97
|
+
const body = template.slice(bodyStart, closeIndex);
|
|
98
|
+
const keep = kind === '#' ? isTruthy(vars[name]) : !isTruthy(vars[name]);
|
|
99
|
+
if (keep) result += body;
|
|
100
|
+
|
|
101
|
+
cursor = closeIndex + closeTag.length;
|
|
102
|
+
openRe.lastIndex = cursor;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return result + template.slice(cursor);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function extractPlaceholders(template: string): TemplatePlaceholders {
|
|
109
|
+
const substitutions = new Set<string>();
|
|
110
|
+
const blocks = new Set<string>();
|
|
111
|
+
const closes = new Set<string>();
|
|
112
|
+
|
|
113
|
+
for (const match of template.matchAll(new RegExp(BLOCK_OPEN_RE.source, 'g'))) {
|
|
114
|
+
if (match[2]) blocks.add(match[2]);
|
|
115
|
+
}
|
|
116
|
+
for (const match of template.matchAll(new RegExp(BLOCK_CLOSE_RE.source, 'g'))) {
|
|
117
|
+
if (match[1]) closes.add(match[1]);
|
|
118
|
+
}
|
|
119
|
+
for (const match of template.matchAll(new RegExp(SUBSTITUTION_RE.source, 'g'))) {
|
|
120
|
+
if (match[1]) substitutions.add(match[1]);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const unbalanced = [
|
|
124
|
+
...[...blocks].filter((name) => !closes.has(name)),
|
|
125
|
+
...[...closes].filter((name) => !blocks.has(name)),
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
substitutions: [...substitutions],
|
|
130
|
+
blocks: [...blocks],
|
|
131
|
+
unbalanced: [...new Set(unbalanced)],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function normalizeVariables(
|
|
136
|
+
schema?: VariablesSchema | Record<string, VariableSpec> | null,
|
|
137
|
+
): Record<string, VariableSpec> {
|
|
138
|
+
if (!schema) return {};
|
|
139
|
+
if ('variables' in schema && schema.variables && typeof schema.variables === 'object') {
|
|
140
|
+
return (schema as VariablesSchema).variables;
|
|
141
|
+
}
|
|
142
|
+
return schema as Record<string, VariableSpec>;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function validateTemplate(
|
|
146
|
+
content: string,
|
|
147
|
+
schema?: VariablesSchema | Record<string, VariableSpec> | null,
|
|
148
|
+
): TemplateValidation {
|
|
149
|
+
const { substitutions, blocks, unbalanced } = extractPlaceholders(content);
|
|
150
|
+
const variables = normalizeVariables(schema);
|
|
151
|
+
const declared = new Set(Object.keys(variables));
|
|
152
|
+
const used = new Set([...substitutions, ...blocks]);
|
|
153
|
+
|
|
154
|
+
const missingRequired = Object.entries(variables)
|
|
155
|
+
.filter(([name, spec]) => spec.required && !used.has(name))
|
|
156
|
+
.map(([name]) => name);
|
|
157
|
+
|
|
158
|
+
const unknownPlaceholders = declared.size
|
|
159
|
+
? [...used].filter((name) => !declared.has(name))
|
|
160
|
+
: [];
|
|
161
|
+
|
|
162
|
+
return { missingRequired, unknownPlaceholders, unbalancedBlocks: unbalanced };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function estimateTokens(text: string): number {
|
|
166
|
+
return Math.ceil(text.length / 4);
|
|
167
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { VariableSpec, VariablesSchema } from './prompt-template';
|
|
2
|
+
|
|
3
|
+
export type AiInstructionLayer =
|
|
4
|
+
| 'system'
|
|
5
|
+
| 'product'
|
|
6
|
+
| 'module'
|
|
7
|
+
| 'agent'
|
|
8
|
+
| 'tool'
|
|
9
|
+
| 'output'
|
|
10
|
+
| 'task';
|
|
11
|
+
|
|
12
|
+
export const AI_INSTRUCTION_LAYERS: AiInstructionLayer[] = [
|
|
13
|
+
'task',
|
|
14
|
+
'system',
|
|
15
|
+
'product',
|
|
16
|
+
'module',
|
|
17
|
+
'agent',
|
|
18
|
+
'tool',
|
|
19
|
+
'output',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export type AiInstruction = {
|
|
23
|
+
id: number;
|
|
24
|
+
slug: string;
|
|
25
|
+
layer: AiInstructionLayer;
|
|
26
|
+
name: string;
|
|
27
|
+
content: string;
|
|
28
|
+
variables_schema: VariablesSchema | Record<string, VariableSpec> | null;
|
|
29
|
+
locale: string;
|
|
30
|
+
module_slug: string | null;
|
|
31
|
+
is_active: boolean;
|
|
32
|
+
version: number;
|
|
33
|
+
model: string | null;
|
|
34
|
+
temperature: number | null;
|
|
35
|
+
max_tokens: number | null;
|
|
36
|
+
/** Security-sensitive prompt: editing requires an explicit acknowledgement. */
|
|
37
|
+
is_locked: boolean;
|
|
38
|
+
created_at: string;
|
|
39
|
+
updated_at: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type AiInstructionVersion = {
|
|
43
|
+
id: number;
|
|
44
|
+
version: number;
|
|
45
|
+
content: string;
|
|
46
|
+
change_note: string | null;
|
|
47
|
+
created_at: string;
|
|
48
|
+
created_by_name: string | null;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** A prompt as declared in code, paired with what the database holds. */
|
|
52
|
+
export type AiPromptRegistryEntry = {
|
|
53
|
+
slug: string;
|
|
54
|
+
name: string;
|
|
55
|
+
module_slug: string;
|
|
56
|
+
locale: string;
|
|
57
|
+
fallback: string;
|
|
58
|
+
variables: Record<string, VariableSpec>;
|
|
59
|
+
security_sensitive: boolean;
|
|
60
|
+
required_phrases: string[];
|
|
61
|
+
defaults: { model?: string; temperature?: number; maxTokens?: number };
|
|
62
|
+
exists_in_db: boolean;
|
|
63
|
+
db_matches_fallback: boolean;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type AiInstructionPreview = {
|
|
67
|
+
rendered: string;
|
|
68
|
+
render_error: string | null;
|
|
69
|
+
char_count: number;
|
|
70
|
+
estimated_tokens: number;
|
|
71
|
+
missing_required: string[];
|
|
72
|
+
unknown_placeholders: string[];
|
|
73
|
+
unbalanced_blocks: string[];
|
|
74
|
+
warnings: string[];
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type PaginatedResponse<T> = {
|
|
78
|
+
data: T[];
|
|
79
|
+
total: number;
|
|
80
|
+
page: number;
|
|
81
|
+
pageSize: number;
|
|
82
|
+
totalPages: number;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export function getErrorMessage(error: unknown, fallback: string) {
|
|
86
|
+
if (error && typeof error === 'object') {
|
|
87
|
+
const record = error as {
|
|
88
|
+
message?: string;
|
|
89
|
+
response?: { data?: { message?: string | string[]; error?: string } };
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const message = record.response?.data?.message;
|
|
93
|
+
if (Array.isArray(message)) return message.join(' ');
|
|
94
|
+
|
|
95
|
+
return message || record.response?.data?.error || record.message || fallback;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return fallback;
|
|
99
|
+
}
|