@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.
- package/dist/admin.cjs +534 -11
- package/dist/admin.cjs.map +1 -1
- package/dist/admin.js +564 -23
- package/dist/admin.js.map +1 -1
- package/dist/api.cjs +727 -36
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.js +705 -18
- package/dist/api.js.map +1 -1
- package/dist/{index-GMn7-9PX.d.ts → index--GBYw5JE.d.ts} +84 -2
- package/dist/{index-D2C1O9b4.d.cts → index-DGtM2Gsk.d.cts} +84 -2
- package/dist/index.cjs +1701 -713
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +99 -13
- package/dist/index.d.ts +99 -13
- package/dist/index.js +1554 -574
- package/dist/index.js.map +1 -1
- package/dist/migrations/1775300000000-LlmAgents.ts +57 -0
- package/dist/migrations/1775300000001-LlmAgentsValidationRulesText.ts +43 -0
- package/dist/migrations/1775300000002-SeedLlmAgentsPermissions.ts +33 -0
- package/dist/migrations/1775300000003-LlmAgentKnowledgeDocuments.ts +50 -0
- package/dist/migrations/1775400000000-KnowledgeBaseVectorDimension384.ts +32 -0
- package/package.json +8 -6
|
@@ -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
|
|
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 {
|
|
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
|
|
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 {
|
|
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 };
|