@infuro/cms-core 1.0.19 → 1.0.21

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,59 @@ 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
+ * Pipeline logs (grep `[llm-agent-knowledge] pipeline`):
374
+ * - 01_request — incoming POST, content-type preview
375
+ * - 02_agent_loaded — agent id for slug
376
+ * - 03_body_parsed — JSON vs multipart, sizes / documentId
377
+ * - 04_* — file decode or PDF extract (multipart)
378
+ * - 05_branch — link_existing_document | new_upload_ingest
379
+ * - 06_* — KB row + junction (link create / exists)
380
+ * - 06b_chunks_existing_count — link path: existing chunk rows
381
+ * - 06_knowledge_document_saved — new ingest: document row id
382
+ * - 07_chunk_split — split stats
383
+ * - 07b_chunks_persisted — chunk rows saved
384
+ * - 07_query_chunks_missing_embedding — link path: rows with NULL embedding
385
+ * - 08_* — resolve LLM plugin, embed availability or skip
386
+ * - 09_embedding_workers_start / 10_embedding_workers_finished — concurrent embed+DB update
387
+ * - 11_response — final outcome summary
388
+ * - 99_pipeline_error — uncaught exception
389
+ */
390
+
391
+ interface LlmAgentKnowledgeApiConfig {
392
+ dataSource: DataSource;
393
+ entityMap: EntityMap;
394
+ getCms: () => Promise<{
395
+ getPlugin: (name: string) => unknown;
396
+ }>;
397
+ json: (body: unknown, init?: {
398
+ status?: number;
399
+ }) => Response;
400
+ requireAuth: (req: Request) => Promise<Response | null>;
401
+ requireEntityPermission?: RequireEntityPermissionFn;
402
+ }
403
+ declare function createLlmAgentKnowledgeHandlers(config: LlmAgentKnowledgeApiConfig): {
404
+ list(req: Request, slug: string): Promise<Response>;
405
+ post(req: Request, slug: string): Promise<Response>;
406
+ unlink(req: Request, slug: string, documentIdStr: string): Promise<Response>;
407
+ } | null;
314
408
 
315
409
  /**
316
410
  * 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 +456,13 @@ interface CmsApiHandlerConfig {
362
456
  userProfile?: UserProfileConfig;
363
457
  /** GET/PUT /api/settings/:group */
364
458
  settings?: SettingsApiConfig;
365
- /** POST /api/chat/identify, GET /api/chat/conversations/:id/messages, POST /api/chat/messages */
459
+ /** GET /api/chat/config (public); POST /api/chat/identify; GET /api/chat/conversations/:id/messages; POST /api/chat/messages */
366
460
  chat?: ChatApiConfig;
461
+ /**
462
+ * GET/POST /api/llm_agents/:slug/knowledge; DELETE …/knowledge/:documentId — agent KB ingest + links.
463
+ * When omitted but `chat` is set, the same dataSource / entityMap / getCms / json / requireAuth are reused automatically.
464
+ */
465
+ llmAgentKnowledge?: LlmAgentKnowledgeApiConfig;
367
466
  /**
368
467
  * Entity-level RBAC (session `entityPerms` / Administrator). When omitted, admin routes that need it respond with 403
369
468
  * (`entity_rbac_required`) so CRUD cannot run as auth-only. Pass `createAuthHelpers(...).requireEntityPermission` from the app.
@@ -373,7 +472,7 @@ interface CmsApiHandlerConfig {
373
472
  getSessionUser?: () => Promise<SessionUser | null>;
374
473
  }
375
474
  declare function createCmsApiHandler(config: CmsApiHandlerConfig): {
376
- handle(method: string, path: string[], req: Request): Promise<Response>;
475
+ handle(method: string, pathInput: string[], req: Request): Promise<Response>;
377
476
  };
378
477
 
379
478
  interface StorefrontOtpFlags {
@@ -411,4 +510,4 @@ declare function createStorefrontApiHandler(config: StorefrontApiConfig): {
411
510
  handle(method: string, path: string[], req: Request): Promise<Response>;
412
511
  };
413
512
 
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 };
513
+ 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,59 @@ 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
+ * Pipeline logs (grep `[llm-agent-knowledge] pipeline`):
374
+ * - 01_request — incoming POST, content-type preview
375
+ * - 02_agent_loaded — agent id for slug
376
+ * - 03_body_parsed — JSON vs multipart, sizes / documentId
377
+ * - 04_* — file decode or PDF extract (multipart)
378
+ * - 05_branch — link_existing_document | new_upload_ingest
379
+ * - 06_* — KB row + junction (link create / exists)
380
+ * - 06b_chunks_existing_count — link path: existing chunk rows
381
+ * - 06_knowledge_document_saved — new ingest: document row id
382
+ * - 07_chunk_split — split stats
383
+ * - 07b_chunks_persisted — chunk rows saved
384
+ * - 07_query_chunks_missing_embedding — link path: rows with NULL embedding
385
+ * - 08_* — resolve LLM plugin, embed availability or skip
386
+ * - 09_embedding_workers_start / 10_embedding_workers_finished — concurrent embed+DB update
387
+ * - 11_response — final outcome summary
388
+ * - 99_pipeline_error — uncaught exception
389
+ */
390
+
391
+ interface LlmAgentKnowledgeApiConfig {
392
+ dataSource: DataSource;
393
+ entityMap: EntityMap;
394
+ getCms: () => Promise<{
395
+ getPlugin: (name: string) => unknown;
396
+ }>;
397
+ json: (body: unknown, init?: {
398
+ status?: number;
399
+ }) => Response;
400
+ requireAuth: (req: Request) => Promise<Response | null>;
401
+ requireEntityPermission?: RequireEntityPermissionFn;
402
+ }
403
+ declare function createLlmAgentKnowledgeHandlers(config: LlmAgentKnowledgeApiConfig): {
404
+ list(req: Request, slug: string): Promise<Response>;
405
+ post(req: Request, slug: string): Promise<Response>;
406
+ unlink(req: Request, slug: string, documentIdStr: string): Promise<Response>;
407
+ } | null;
314
408
 
315
409
  /**
316
410
  * 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 +456,13 @@ interface CmsApiHandlerConfig {
362
456
  userProfile?: UserProfileConfig;
363
457
  /** GET/PUT /api/settings/:group */
364
458
  settings?: SettingsApiConfig;
365
- /** POST /api/chat/identify, GET /api/chat/conversations/:id/messages, POST /api/chat/messages */
459
+ /** GET /api/chat/config (public); POST /api/chat/identify; GET /api/chat/conversations/:id/messages; POST /api/chat/messages */
366
460
  chat?: ChatApiConfig;
461
+ /**
462
+ * GET/POST /api/llm_agents/:slug/knowledge; DELETE …/knowledge/:documentId — agent KB ingest + links.
463
+ * When omitted but `chat` is set, the same dataSource / entityMap / getCms / json / requireAuth are reused automatically.
464
+ */
465
+ llmAgentKnowledge?: LlmAgentKnowledgeApiConfig;
367
466
  /**
368
467
  * Entity-level RBAC (session `entityPerms` / Administrator). When omitted, admin routes that need it respond with 403
369
468
  * (`entity_rbac_required`) so CRUD cannot run as auth-only. Pass `createAuthHelpers(...).requireEntityPermission` from the app.
@@ -373,7 +472,7 @@ interface CmsApiHandlerConfig {
373
472
  getSessionUser?: () => Promise<SessionUser | null>;
374
473
  }
375
474
  declare function createCmsApiHandler(config: CmsApiHandlerConfig): {
376
- handle(method: string, path: string[], req: Request): Promise<Response>;
475
+ handle(method: string, pathInput: string[], req: Request): Promise<Response>;
377
476
  };
378
477
 
379
478
  interface StorefrontOtpFlags {
@@ -411,4 +510,4 @@ declare function createStorefrontApiHandler(config: StorefrontApiConfig): {
411
510
  handle(method: string, path: string[], req: Request): Promise<Response>;
412
511
  };
413
512
 
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 };
513
+ 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 };