@infuro/cms-core 1.0.19 → 1.0.20

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.
@@ -153,6 +153,47 @@ declare function createUserAuthApiRouter(config: UserAuthApiConfig): {
153
153
  */
154
154
 
155
155
  type RequireEntityPermissionFn = (req: Request, entity: string, action: EntityCrudAction) => Promise<Response | null>;
156
+ /**
157
+ * Optional JSON in `LlmAgent.validationRules`. Used for programmatic checks before the LLM call.
158
+ * For natural-language output rules, use `guardrails` / `outputRules` / `outputInstructions` (merged into system prompt).
159
+ */
160
+ type LlmAgentValidationRulesJson = {
161
+ maxUserChars?: number;
162
+ maxMessageLength?: number;
163
+ minUserChars?: number;
164
+ minMessageLength?: number;
165
+ blockedSubstrings?: string[];
166
+ /** Shown to the model as output guardrails (first non-empty of guardrails | outputRules | outputInstructions wins). */
167
+ guardrails?: string;
168
+ outputRules?: string;
169
+ outputInstructions?: string;
170
+ };
171
+ type ParsedLlmAgentValidation = {
172
+ /** Subset used for length / substring checks only. */
173
+ structured: Pick<LlmAgentValidationRulesJson, 'maxUserChars' | 'maxMessageLength' | 'minUserChars' | 'minMessageLength' | 'blockedSubstrings'>;
174
+ /** Appended to system prompt so the model follows output guardrails. */
175
+ guardrailsForPrompt: string | null;
176
+ };
177
+ /**
178
+ * - Valid JSON object: structural keys → validation; `guardrails` / `outputRules` / `outputInstructions` → prompt suffix.
179
+ * - Not JSON: entire string is treated as prose guardrails for the prompt (no programmatic rules unless you use JSON).
180
+ */
181
+ declare function parseLlmAgentValidationRules(validationRulesText: string | null | undefined): ParsedLlmAgentValidation;
182
+ declare function validateUserMessageAgainstStructuredRules(message: string, structured: ParsedLlmAgentValidation['structured']): {
183
+ ok: true;
184
+ } | {
185
+ ok: false;
186
+ error: string;
187
+ };
188
+ /** Parses `validationRules` then runs programmatic checks only. */
189
+ declare function validateUserMessageAgainstAgentRules(message: string, validationRulesText: string | null | undefined): {
190
+ ok: true;
191
+ } | {
192
+ ok: false;
193
+ error: string;
194
+ };
195
+ /** Merges guardrails prose into the system instruction sent to the model. */
196
+ declare function mergeGuardrailsIntoSystemPrompt(baseSystem: string | undefined, guardrailsForPrompt: string | null): string;
156
197
  interface CmsHandlersBase {
157
198
  json: (body: unknown, init?: {
158
199
  status?: number;
@@ -311,6 +352,42 @@ interface ChatApiConfig extends CmsHandlersBase {
311
352
  getPlugin: (name: string) => unknown;
312
353
  }>;
313
354
  }
355
+ /** Safe subset of `llm` settings for the storefront chat widget (`GET /api/chat/config`). */
356
+ interface ChatPublicConfig {
357
+ enabled: boolean;
358
+ chatMode: 'whatsapp' | 'external' | 'llm';
359
+ /** When `chatMode === 'llm'`, slug of the attached agent (from `attachedAgentSlug` setting). */
360
+ agentSlug: string;
361
+ botName: string;
362
+ icon: string;
363
+ iconImageUrl: string;
364
+ iconBackgroundColor: string;
365
+ headerColor: string;
366
+ whatsappPhone: string;
367
+ }
368
+
369
+ /**
370
+ * Admin API: attach knowledge base documents to an LLM agent, ingest text into chunks + embeddings.
371
+ * Routes: GET/POST /api/llm_agents/:slug/knowledge, DELETE /api/llm_agents/:slug/knowledge/:documentId
372
+ */
373
+
374
+ interface LlmAgentKnowledgeApiConfig {
375
+ dataSource: DataSource;
376
+ entityMap: EntityMap;
377
+ getCms: () => Promise<{
378
+ getPlugin: (name: string) => unknown;
379
+ }>;
380
+ json: (body: unknown, init?: {
381
+ status?: number;
382
+ }) => Response;
383
+ requireAuth: (req: Request) => Promise<Response | null>;
384
+ requireEntityPermission?: RequireEntityPermissionFn;
385
+ }
386
+ declare function createLlmAgentKnowledgeHandlers(config: LlmAgentKnowledgeApiConfig): {
387
+ list(req: Request, slug: string): Promise<Response>;
388
+ post(req: Request, slug: string): Promise<Response>;
389
+ unlink(req: Request, slug: string, documentIdStr: string): Promise<Response>;
390
+ } | null;
314
391
 
315
392
  /**
316
393
  * Single CMS API handler: dashboard, analytics, upload, media zip extract, blog/form by slug, users API, user auth, CRUD. Mount once (e.g. app/api/[[...path]]/route.ts).
@@ -362,8 +439,13 @@ interface CmsApiHandlerConfig {
362
439
  userProfile?: UserProfileConfig;
363
440
  /** GET/PUT /api/settings/:group */
364
441
  settings?: SettingsApiConfig;
365
- /** POST /api/chat/identify, GET /api/chat/conversations/:id/messages, POST /api/chat/messages */
442
+ /** GET /api/chat/config (public); POST /api/chat/identify; GET /api/chat/conversations/:id/messages; POST /api/chat/messages */
366
443
  chat?: ChatApiConfig;
444
+ /**
445
+ * GET/POST /api/llm_agents/:slug/knowledge; DELETE …/knowledge/:documentId — agent KB ingest + links.
446
+ * When omitted but `chat` is set, the same dataSource / entityMap / getCms / json / requireAuth are reused automatically.
447
+ */
448
+ llmAgentKnowledge?: LlmAgentKnowledgeApiConfig;
367
449
  /**
368
450
  * Entity-level RBAC (session `entityPerms` / Administrator). When omitted, admin routes that need it respond with 403
369
451
  * (`entity_rbac_required`) so CRUD cannot run as auth-only. Pass `createAuthHelpers(...).requireEntityPermission` from the app.
@@ -411,4 +493,4 @@ declare function createStorefrontApiHandler(config: StorefrontApiConfig): {
411
493
  handle(method: string, path: string[], req: Request): Promise<Response>;
412
494
  };
413
495
 
414
- export { mergeEmailLayoutCompanyDetails as $, type AnalyticsHandlerConfig as A, type BlogBySlugConfig as B, type CompanyDetails as C, type DashboardStatsConfig as D, type EmailTemplateResult as E, type ForgotPasswordConfig as F, type GetPublicSettingsGroupConfig as G, createEcommerceAnalyticsHandler as H, type InviteAcceptConfig as I, createForgotPasswordHandler as J, createFormBySlugHandler as K, createInviteAcceptHandler as L, createMediaZipExtractHandler as M, createSetPasswordHandler as N, type OrderPlacedLineItem as O, createSettingsApiHandlers as P, createStorefrontApiHandler as Q, createUploadHandler as R, type StorageService as S, type TemplateContext as T, type UploadHandlerConfig as U, createUserAuthApiRouter as V, createUserAvatarHandler as W, createUserProfileHandler as X, createUsersApiHandlers as Y, getCompanyDetailsFromSettings as Z, getPublicSettingsGroup as _, type EmailTemplateName as a, type EntityMap as b, type AuthHandlersConfig as c, type ChangePasswordConfig as d, type CmsApiHandlerConfig as e, type CmsGetter as f, type CrudHandlerOptions as g, type EcommerceAnalyticsConfig as h, type FormBySlugConfig as i, type GetPublicSettingsGroupDataSource as j, type SetPasswordConfig as k, type SettingsApiConfig as l, type SocialLinkItem as m, type StorefrontApiConfig as n, type StorefrontOtpFlags as o, type UserAuthApiConfig as p, type UserAvatarConfig as q, type UserProfileConfig as r, type UsersApiConfig as s, createAnalyticsHandlers as t, createBlogBySlugHandler as u, createChangePasswordHandler as v, createCmsApiHandler as w, createCrudByIdHandler as x, createCrudHandler as y, createDashboardStatsHandler as z };
496
+ export { createUserAvatarHandler as $, type AnalyticsHandlerConfig as A, type BlogBySlugConfig as B, type CompanyDetails as C, type DashboardStatsConfig as D, type EmailTemplateResult as E, type ForgotPasswordConfig as F, type GetPublicSettingsGroupConfig as G, createCrudHandler as H, type InviteAcceptConfig as I, createDashboardStatsHandler as J, createEcommerceAnalyticsHandler as K, type LlmAgentKnowledgeApiConfig as L, createForgotPasswordHandler as M, createFormBySlugHandler as N, type OrderPlacedLineItem as O, type ParsedLlmAgentValidation as P, createInviteAcceptHandler as Q, createLlmAgentKnowledgeHandlers as R, type StorageService as S, type TemplateContext as T, type UploadHandlerConfig as U, createMediaZipExtractHandler as V, createSetPasswordHandler as W, createSettingsApiHandlers as X, createStorefrontApiHandler as Y, createUploadHandler as Z, createUserAuthApiRouter as _, type EmailTemplateName as a, createUserProfileHandler as a0, createUsersApiHandlers as a1, getCompanyDetailsFromSettings as a2, getPublicSettingsGroup as a3, mergeEmailLayoutCompanyDetails as a4, mergeGuardrailsIntoSystemPrompt as a5, parseLlmAgentValidationRules as a6, validateUserMessageAgainstAgentRules as a7, validateUserMessageAgainstStructuredRules as a8, type EntityMap as b, type AuthHandlersConfig as c, type ChangePasswordConfig as d, type ChatPublicConfig as e, type CmsApiHandlerConfig as f, type CmsGetter as g, type CrudHandlerOptions as h, type EcommerceAnalyticsConfig as i, type FormBySlugConfig as j, type GetPublicSettingsGroupDataSource as k, type LlmAgentValidationRulesJson as l, type SetPasswordConfig as m, type SettingsApiConfig as n, type SocialLinkItem as o, type StorefrontApiConfig as p, type StorefrontOtpFlags as q, type UserAuthApiConfig as r, type UserAvatarConfig as s, type UserProfileConfig as t, type UsersApiConfig as u, createAnalyticsHandlers as v, createBlogBySlugHandler as w, createChangePasswordHandler as x, createCmsApiHandler as y, createCrudByIdHandler as z };
@@ -153,6 +153,47 @@ declare function createUserAuthApiRouter(config: UserAuthApiConfig): {
153
153
  */
154
154
 
155
155
  type RequireEntityPermissionFn = (req: Request, entity: string, action: EntityCrudAction) => Promise<Response | null>;
156
+ /**
157
+ * Optional JSON in `LlmAgent.validationRules`. Used for programmatic checks before the LLM call.
158
+ * For natural-language output rules, use `guardrails` / `outputRules` / `outputInstructions` (merged into system prompt).
159
+ */
160
+ type LlmAgentValidationRulesJson = {
161
+ maxUserChars?: number;
162
+ maxMessageLength?: number;
163
+ minUserChars?: number;
164
+ minMessageLength?: number;
165
+ blockedSubstrings?: string[];
166
+ /** Shown to the model as output guardrails (first non-empty of guardrails | outputRules | outputInstructions wins). */
167
+ guardrails?: string;
168
+ outputRules?: string;
169
+ outputInstructions?: string;
170
+ };
171
+ type ParsedLlmAgentValidation = {
172
+ /** Subset used for length / substring checks only. */
173
+ structured: Pick<LlmAgentValidationRulesJson, 'maxUserChars' | 'maxMessageLength' | 'minUserChars' | 'minMessageLength' | 'blockedSubstrings'>;
174
+ /** Appended to system prompt so the model follows output guardrails. */
175
+ guardrailsForPrompt: string | null;
176
+ };
177
+ /**
178
+ * - Valid JSON object: structural keys → validation; `guardrails` / `outputRules` / `outputInstructions` → prompt suffix.
179
+ * - Not JSON: entire string is treated as prose guardrails for the prompt (no programmatic rules unless you use JSON).
180
+ */
181
+ declare function parseLlmAgentValidationRules(validationRulesText: string | null | undefined): ParsedLlmAgentValidation;
182
+ declare function validateUserMessageAgainstStructuredRules(message: string, structured: ParsedLlmAgentValidation['structured']): {
183
+ ok: true;
184
+ } | {
185
+ ok: false;
186
+ error: string;
187
+ };
188
+ /** Parses `validationRules` then runs programmatic checks only. */
189
+ declare function validateUserMessageAgainstAgentRules(message: string, validationRulesText: string | null | undefined): {
190
+ ok: true;
191
+ } | {
192
+ ok: false;
193
+ error: string;
194
+ };
195
+ /** Merges guardrails prose into the system instruction sent to the model. */
196
+ declare function mergeGuardrailsIntoSystemPrompt(baseSystem: string | undefined, guardrailsForPrompt: string | null): string;
156
197
  interface CmsHandlersBase {
157
198
  json: (body: unknown, init?: {
158
199
  status?: number;
@@ -311,6 +352,42 @@ interface ChatApiConfig extends CmsHandlersBase {
311
352
  getPlugin: (name: string) => unknown;
312
353
  }>;
313
354
  }
355
+ /** Safe subset of `llm` settings for the storefront chat widget (`GET /api/chat/config`). */
356
+ interface ChatPublicConfig {
357
+ enabled: boolean;
358
+ chatMode: 'whatsapp' | 'external' | 'llm';
359
+ /** When `chatMode === 'llm'`, slug of the attached agent (from `attachedAgentSlug` setting). */
360
+ agentSlug: string;
361
+ botName: string;
362
+ icon: string;
363
+ iconImageUrl: string;
364
+ iconBackgroundColor: string;
365
+ headerColor: string;
366
+ whatsappPhone: string;
367
+ }
368
+
369
+ /**
370
+ * Admin API: attach knowledge base documents to an LLM agent, ingest text into chunks + embeddings.
371
+ * Routes: GET/POST /api/llm_agents/:slug/knowledge, DELETE /api/llm_agents/:slug/knowledge/:documentId
372
+ */
373
+
374
+ interface LlmAgentKnowledgeApiConfig {
375
+ dataSource: DataSource;
376
+ entityMap: EntityMap;
377
+ getCms: () => Promise<{
378
+ getPlugin: (name: string) => unknown;
379
+ }>;
380
+ json: (body: unknown, init?: {
381
+ status?: number;
382
+ }) => Response;
383
+ requireAuth: (req: Request) => Promise<Response | null>;
384
+ requireEntityPermission?: RequireEntityPermissionFn;
385
+ }
386
+ declare function createLlmAgentKnowledgeHandlers(config: LlmAgentKnowledgeApiConfig): {
387
+ list(req: Request, slug: string): Promise<Response>;
388
+ post(req: Request, slug: string): Promise<Response>;
389
+ unlink(req: Request, slug: string, documentIdStr: string): Promise<Response>;
390
+ } | null;
314
391
 
315
392
  /**
316
393
  * Single CMS API handler: dashboard, analytics, upload, media zip extract, blog/form by slug, users API, user auth, CRUD. Mount once (e.g. app/api/[[...path]]/route.ts).
@@ -362,8 +439,13 @@ interface CmsApiHandlerConfig {
362
439
  userProfile?: UserProfileConfig;
363
440
  /** GET/PUT /api/settings/:group */
364
441
  settings?: SettingsApiConfig;
365
- /** POST /api/chat/identify, GET /api/chat/conversations/:id/messages, POST /api/chat/messages */
442
+ /** GET /api/chat/config (public); POST /api/chat/identify; GET /api/chat/conversations/:id/messages; POST /api/chat/messages */
366
443
  chat?: ChatApiConfig;
444
+ /**
445
+ * GET/POST /api/llm_agents/:slug/knowledge; DELETE …/knowledge/:documentId — agent KB ingest + links.
446
+ * When omitted but `chat` is set, the same dataSource / entityMap / getCms / json / requireAuth are reused automatically.
447
+ */
448
+ llmAgentKnowledge?: LlmAgentKnowledgeApiConfig;
367
449
  /**
368
450
  * Entity-level RBAC (session `entityPerms` / Administrator). When omitted, admin routes that need it respond with 403
369
451
  * (`entity_rbac_required`) so CRUD cannot run as auth-only. Pass `createAuthHelpers(...).requireEntityPermission` from the app.
@@ -411,4 +493,4 @@ declare function createStorefrontApiHandler(config: StorefrontApiConfig): {
411
493
  handle(method: string, path: string[], req: Request): Promise<Response>;
412
494
  };
413
495
 
414
- export { mergeEmailLayoutCompanyDetails as $, type AnalyticsHandlerConfig as A, type BlogBySlugConfig as B, type CompanyDetails as C, type DashboardStatsConfig as D, type EmailTemplateResult as E, type ForgotPasswordConfig as F, type GetPublicSettingsGroupConfig as G, createEcommerceAnalyticsHandler as H, type InviteAcceptConfig as I, createForgotPasswordHandler as J, createFormBySlugHandler as K, createInviteAcceptHandler as L, createMediaZipExtractHandler as M, createSetPasswordHandler as N, type OrderPlacedLineItem as O, createSettingsApiHandlers as P, createStorefrontApiHandler as Q, createUploadHandler as R, type StorageService as S, type TemplateContext as T, type UploadHandlerConfig as U, createUserAuthApiRouter as V, createUserAvatarHandler as W, createUserProfileHandler as X, createUsersApiHandlers as Y, getCompanyDetailsFromSettings as Z, getPublicSettingsGroup as _, type EmailTemplateName as a, type EntityMap as b, type AuthHandlersConfig as c, type ChangePasswordConfig as d, type CmsApiHandlerConfig as e, type CmsGetter as f, type CrudHandlerOptions as g, type EcommerceAnalyticsConfig as h, type FormBySlugConfig as i, type GetPublicSettingsGroupDataSource as j, type SetPasswordConfig as k, type SettingsApiConfig as l, type SocialLinkItem as m, type StorefrontApiConfig as n, type StorefrontOtpFlags as o, type UserAuthApiConfig as p, type UserAvatarConfig as q, type UserProfileConfig as r, type UsersApiConfig as s, createAnalyticsHandlers as t, createBlogBySlugHandler as u, createChangePasswordHandler as v, createCmsApiHandler as w, createCrudByIdHandler as x, createCrudHandler as y, createDashboardStatsHandler as z };
496
+ export { createUserAvatarHandler as $, type AnalyticsHandlerConfig as A, type BlogBySlugConfig as B, type CompanyDetails as C, type DashboardStatsConfig as D, type EmailTemplateResult as E, type ForgotPasswordConfig as F, type GetPublicSettingsGroupConfig as G, createCrudHandler as H, type InviteAcceptConfig as I, createDashboardStatsHandler as J, createEcommerceAnalyticsHandler as K, type LlmAgentKnowledgeApiConfig as L, createForgotPasswordHandler as M, createFormBySlugHandler as N, type OrderPlacedLineItem as O, type ParsedLlmAgentValidation as P, createInviteAcceptHandler as Q, createLlmAgentKnowledgeHandlers as R, type StorageService as S, type TemplateContext as T, type UploadHandlerConfig as U, createMediaZipExtractHandler as V, createSetPasswordHandler as W, createSettingsApiHandlers as X, createStorefrontApiHandler as Y, createUploadHandler as Z, createUserAuthApiRouter as _, type EmailTemplateName as a, createUserProfileHandler as a0, createUsersApiHandlers as a1, getCompanyDetailsFromSettings as a2, getPublicSettingsGroup as a3, mergeEmailLayoutCompanyDetails as a4, mergeGuardrailsIntoSystemPrompt as a5, parseLlmAgentValidationRules as a6, validateUserMessageAgainstAgentRules as a7, validateUserMessageAgainstStructuredRules as a8, type EntityMap as b, type AuthHandlersConfig as c, type ChangePasswordConfig as d, type ChatPublicConfig as e, type CmsApiHandlerConfig as f, type CmsGetter as g, type CrudHandlerOptions as h, type EcommerceAnalyticsConfig as i, type FormBySlugConfig as j, type GetPublicSettingsGroupDataSource as k, type LlmAgentValidationRulesJson as l, type SetPasswordConfig as m, type SettingsApiConfig as n, type SocialLinkItem as o, type StorefrontApiConfig as p, type StorefrontOtpFlags as q, type UserAuthApiConfig as r, type UserAvatarConfig as s, type UserProfileConfig as t, type UsersApiConfig as u, createAnalyticsHandlers as v, createBlogBySlugHandler as w, createChangePasswordHandler as x, createCmsApiHandler as y, createCrudByIdHandler as z };