@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.
- package/dist/admin.cjs +661 -19
- package/dist/admin.cjs.map +1 -1
- package/dist/admin.js +681 -22
- package/dist/admin.js.map +1 -1
- package/dist/api.cjs +3745 -101
- 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 +3732 -83
- package/dist/api.js.map +1 -1
- package/dist/{index-D2C1O9b4.d.cts → index-BGAh4fPQ.d.cts} +102 -3
- package/dist/{index-GMn7-9PX.d.ts → index-Cnwh7B3r.d.ts} +102 -3
- package/dist/index.cjs +2301 -787
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +124 -13
- package/dist/index.d.ts +124 -13
- package/dist/index.js +2154 -648
- 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 +9 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CompanyDetails, T as TemplateContext, E as EmailTemplateResult, a as EmailTemplateName, O as OrderPlacedLineItem, S as StorageService, b as EntityMap$2 } from './index-
|
|
2
|
-
export { A as AnalyticsHandlerConfig, c as AuthHandlersConfig, B as BlogBySlugConfig, d as ChangePasswordConfig, e as
|
|
1
|
+
import { C as CompanyDetails, T as TemplateContext, E as EmailTemplateResult, a as EmailTemplateName, O as OrderPlacedLineItem, S as StorageService, b as EntityMap$2 } from './index-BGAh4fPQ.cjs';
|
|
2
|
+
export { A as AnalyticsHandlerConfig, c as AuthHandlersConfig, B as BlogBySlugConfig, d as ChangePasswordConfig, e as ChatPublicConfig, f as CmsApiHandlerConfig, g as CmsGetter, h as CrudHandlerOptions, D as DashboardStatsConfig, i as EcommerceAnalyticsConfig, F as ForgotPasswordConfig, j as FormBySlugConfig, G as GetPublicSettingsGroupConfig, k as GetPublicSettingsGroupDataSource, I as InviteAcceptConfig, L as LlmAgentKnowledgeApiConfig, l as LlmAgentValidationRulesJson, P as ParsedLlmAgentValidation, m as SetPasswordConfig, n as SettingsApiConfig, o as SocialLinkItem, p as StorefrontApiConfig, q as StorefrontOtpFlags, U as UploadHandlerConfig, r as UserAuthApiConfig, s as UserAvatarConfig, t as UserProfileConfig, u as UsersApiConfig, v as createAnalyticsHandlers, w as createBlogBySlugHandler, x as createChangePasswordHandler, y as createCmsApiHandler, z as createCrudByIdHandler, H as createCrudHandler, J as createDashboardStatsHandler, K as createEcommerceAnalyticsHandler, M as createForgotPasswordHandler, N as createFormBySlugHandler, Q as createInviteAcceptHandler, R as createLlmAgentKnowledgeHandlers, V as createMediaZipExtractHandler, W as createSetPasswordHandler, X as createSettingsApiHandlers, Y as createStorefrontApiHandler, Z as createUploadHandler, _ as createUserAuthApiRouter, $ as createUserAvatarHandler, a0 as createUserProfileHandler, a1 as createUsersApiHandlers, a2 as getCompanyDetailsFromSettings, a3 as getPublicSettingsGroup, a4 as mergeEmailLayoutCompanyDetails, a5 as mergeGuardrailsIntoSystemPrompt, a6 as parseLlmAgentValidationRules, a7 as validateUserMessageAgainstAgentRules, a8 as validateUserMessageAgainstStructuredRules } from './index-BGAh4fPQ.cjs';
|
|
3
3
|
import { ClassValue } from 'clsx';
|
|
4
4
|
import * as typeorm from 'typeorm';
|
|
5
5
|
import { DataSource, EntityTarget, ObjectLiteral } from 'typeorm';
|
|
@@ -500,7 +500,23 @@ interface LlmMessage {
|
|
|
500
500
|
role: 'user' | 'assistant' | 'system';
|
|
501
501
|
content: string;
|
|
502
502
|
}
|
|
503
|
+
/** Passed to {@link LlmService.chat} / {@link LlmService.streamChat}; only `model`, `temperature`, and `max_tokens` are sent to the gateway. */
|
|
503
504
|
interface LlmChatOptions {
|
|
505
|
+
systemPrompt?: string;
|
|
506
|
+
userPrompt?: string;
|
|
507
|
+
history?: LlmMessage[];
|
|
508
|
+
context?: string;
|
|
509
|
+
model?: string;
|
|
510
|
+
temperature?: number;
|
|
511
|
+
max_tokens?: number;
|
|
512
|
+
}
|
|
513
|
+
/** Options for {@link LlmService.chatAgent} / {@link LlmService.streamChatAgent}: composes system + context + history + user into chat messages. */
|
|
514
|
+
interface LlmAgentOptions {
|
|
515
|
+
systemPrompt?: string;
|
|
516
|
+
userPrompt: string;
|
|
517
|
+
history?: LlmMessage[];
|
|
518
|
+
/** RAG or other material; merged into the system message when set. */
|
|
519
|
+
context?: string;
|
|
504
520
|
model?: string;
|
|
505
521
|
temperature?: number;
|
|
506
522
|
max_tokens?: number;
|
|
@@ -510,28 +526,85 @@ interface LlmServiceInterface {
|
|
|
510
526
|
content: string;
|
|
511
527
|
}>;
|
|
512
528
|
streamChat(messages: LlmMessage[], options?: LlmChatOptions): AsyncIterable<string>;
|
|
513
|
-
|
|
529
|
+
chatAgent(options: LlmAgentOptions): Promise<{
|
|
530
|
+
content: string;
|
|
531
|
+
}>;
|
|
532
|
+
streamChatAgent(options: LlmAgentOptions): AsyncIterable<string>;
|
|
533
|
+
/**
|
|
534
|
+
* Embeddings for RAG / knowledge base. Wire format depends on {@link LlmServiceEmbedOptions}:
|
|
535
|
+
* OpenAI `{base}/v1/embeddings`, or Hugging Face via `@huggingface/inference` (Hub-routed feature extraction) with legacy HTTP fallback.
|
|
536
|
+
*/
|
|
514
537
|
embed?(text: string, options?: {
|
|
515
538
|
model?: string;
|
|
516
539
|
}): Promise<number[]>;
|
|
517
540
|
}
|
|
541
|
+
declare function parseHfInferenceEmbeddingBody(data: unknown): number[] | null;
|
|
542
|
+
type LlmEmbeddingProvider = 'openai' | 'huggingface';
|
|
543
|
+
interface LlmServiceEmbedOptions {
|
|
544
|
+
embeddingProvider?: LlmEmbeddingProvider;
|
|
545
|
+
/** Legacy manual HTTP base when the Inference SDK path fails; default `https://router.huggingface.co/v1` (router host is normalized to `…/hf-inference`). */
|
|
546
|
+
hfInferenceBaseUrl?: string;
|
|
547
|
+
/** Token for embedding calls; defaults to chat `apiKey`. */
|
|
548
|
+
embeddingApiKey?: string;
|
|
549
|
+
/**
|
|
550
|
+
* Default `model` for `POST …/v1/chat/completions` when the caller omits `model`.
|
|
551
|
+
* Set via plugin / CMS `LLM_CHAT_MODEL` or env `LLM_CHAT_MODEL`.
|
|
552
|
+
* If unset, the library picks a fallback from `LLM_GATEWAY_URL` (HF router vs OpenRouter-style).
|
|
553
|
+
*/
|
|
554
|
+
defaultChatModel?: string;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Set `LLM_DEBUG=1` (or `true` / `yes`) to log composed chat payloads.
|
|
558
|
+
* Set `LLM_EMBED_DEBUG=1` for per-request embedding logs (verbose with many chunks).
|
|
559
|
+
* Set `LLM_CHAT_MODEL` for the default chat model when agents/requests omit `model` (gateway-specific id).
|
|
560
|
+
* If unset, fallback is chosen from `LLM_GATEWAY_URL` (HF vs other).
|
|
561
|
+
*/
|
|
518
562
|
declare class LlmService implements LlmServiceInterface {
|
|
563
|
+
private static embedHttpErrorLogged;
|
|
564
|
+
private static embedShapeErrorLogged;
|
|
565
|
+
private static embedSuccessLogged;
|
|
566
|
+
private static hfDimensionMismatchWarned;
|
|
567
|
+
private static hfInferenceSdkErrorLogged;
|
|
519
568
|
private readonly baseURL;
|
|
520
569
|
private readonly apiKey;
|
|
521
570
|
private readonly defaultEmbeddingModel?;
|
|
522
|
-
private
|
|
523
|
-
|
|
571
|
+
private readonly embeddingProvider;
|
|
572
|
+
private readonly hfInferenceBaseURL;
|
|
573
|
+
private readonly embeddingApiKey;
|
|
574
|
+
private readonly defaultChatModel;
|
|
575
|
+
constructor(baseURL: string, apiKey: string, defaultEmbeddingModel?: string, embedOpts?: LlmServiceEmbedOptions);
|
|
576
|
+
private resolveChatModel;
|
|
524
577
|
private get base();
|
|
525
578
|
private get url();
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
*/
|
|
579
|
+
private llmDebugEnabled;
|
|
580
|
+
/** Per-request embedding logs (noisy with many chunks). Set `LLM_EMBED_DEBUG=1`. */
|
|
581
|
+
private embedDebugEnabled;
|
|
582
|
+
private logAgentComposition;
|
|
583
|
+
private logChatCompletionsRequest;
|
|
532
584
|
embed(text: string, options?: {
|
|
533
585
|
model?: string;
|
|
534
586
|
}): Promise<number[]>;
|
|
587
|
+
/**
|
|
588
|
+
* POST `{ url }` with OpenAI-style `{ model, input }` and Bearer token; parses `{ data:[{embedding}] }`.
|
|
589
|
+
*/
|
|
590
|
+
private fetchOpenAiShapeEmbeddings;
|
|
591
|
+
/**
|
|
592
|
+
* Hugging Face–recommended path: Hub resolves a provider that supports `feature-extraction` for the model.
|
|
593
|
+
*/
|
|
594
|
+
private embedViaHuggingfaceInferenceSdk;
|
|
595
|
+
/** Base URL for legacy `…/pipeline/…` and `…/models/{model}` tries (HF router only). */
|
|
596
|
+
private hfLegacyInferenceBase;
|
|
597
|
+
/**
|
|
598
|
+
* Hugging Face embeddings: `@huggingface/inference` (Hub-routed feature extraction), then
|
|
599
|
+
* legacy direct `hf-inference` HTTP tries. Note: `https://router.huggingface.co/v1/embeddings` is not
|
|
600
|
+
* offered for embeddings (OpenAI-compatible `/v1` on HF is chat-only).
|
|
601
|
+
*/
|
|
602
|
+
private embedHuggingFaceInference;
|
|
603
|
+
private buildAgentMessages;
|
|
604
|
+
chatAgent(options: LlmAgentOptions): Promise<{
|
|
605
|
+
content: string;
|
|
606
|
+
}>;
|
|
607
|
+
streamChatAgent(options: LlmAgentOptions): AsyncIterable<string>;
|
|
535
608
|
chat(messages: LlmMessage[], options?: LlmChatOptions): Promise<{
|
|
536
609
|
content: string;
|
|
537
610
|
}>;
|
|
@@ -541,8 +614,19 @@ declare class LlmService implements LlmServiceInterface {
|
|
|
541
614
|
interface LlmPluginConfig {
|
|
542
615
|
baseURL?: string;
|
|
543
616
|
apiKey?: string;
|
|
544
|
-
/** Default model
|
|
617
|
+
/** Default chat model when agents omit `model` (`POST /v1/chat/completions`). Env: `LLM_CHAT_MODEL`. If unset, inferred from `LLM_GATEWAY_URL` (HF vs OpenRouter-style default). */
|
|
618
|
+
defaultChatModel?: string;
|
|
619
|
+
/** Default model for embed(); also from env EMBEDDING_MODEL. */
|
|
545
620
|
embeddingModel?: string;
|
|
621
|
+
/**
|
|
622
|
+
* `openai` (default): `POST {LLM_GATEWAY_URL}/v1/embeddings`.
|
|
623
|
+
* `huggingface`: `@huggingface/inference` feature extraction (Hub-routed), with legacy `…/hf-inference/…` HTTP fallback. Env: `EMBEDDING_PROVIDER=huggingface`.
|
|
624
|
+
*/
|
|
625
|
+
embeddingProvider?: LlmEmbeddingProvider;
|
|
626
|
+
/** Legacy HTTP base if the SDK path fails; default `https://router.huggingface.co/v1` (router hosts map to `…/hf-inference`). Env: `HF_INFERENCE_URL`. */
|
|
627
|
+
hfInferenceBaseUrl?: string;
|
|
628
|
+
/** Optional; defaults to `apiKey`. Env: `EMBEDDING_API_KEY`. */
|
|
629
|
+
embeddingApiKey?: string;
|
|
546
630
|
}
|
|
547
631
|
declare function llmPlugin(config?: LlmPluginConfig): CmsPlugin<LlmService | undefined>;
|
|
548
632
|
|
|
@@ -1415,7 +1499,34 @@ declare class Wishlist {
|
|
|
1415
1499
|
items: WishlistItem[];
|
|
1416
1500
|
}
|
|
1417
1501
|
|
|
1502
|
+
declare class LlmAgent {
|
|
1503
|
+
id: number;
|
|
1504
|
+
name: string;
|
|
1505
|
+
/** Stable key for API / widgets (e.g. `support`, `sales`). */
|
|
1506
|
+
slug: string;
|
|
1507
|
+
/** Passed as `systemPrompt` to `LlmService.chatAgent`. */
|
|
1508
|
+
systemInstruction: string;
|
|
1509
|
+
model: string | null;
|
|
1510
|
+
temperature: number | null;
|
|
1511
|
+
maxTokens: number | null;
|
|
1512
|
+
/**
|
|
1513
|
+
* Rules string: plain prose → appended to system prompt as output guardrails; JSON → see `parseLlmAgentValidationRules` in cms-handlers
|
|
1514
|
+
* (structural checks + optional `guardrails` / `outputRules` / `outputInstructions` for the model).
|
|
1515
|
+
*/
|
|
1516
|
+
validationRules: string | null;
|
|
1517
|
+
enabled: boolean;
|
|
1518
|
+
createdAt: Date;
|
|
1519
|
+
updatedAt: Date;
|
|
1520
|
+
deletedAt: Date | null;
|
|
1521
|
+
deleted: boolean;
|
|
1522
|
+
createdBy: number | null;
|
|
1523
|
+
updatedBy: number | null;
|
|
1524
|
+
deletedBy: number | null;
|
|
1525
|
+
}
|
|
1526
|
+
/** Partial {@link LlmAgentOptions} for merging with `userPrompt` / `history` / `context`. */
|
|
1527
|
+
declare function llmAgentToChatAgentOptions(agent: LlmAgent): Pick<LlmAgentOptions, 'systemPrompt' | 'model' | 'temperature' | 'max_tokens'>;
|
|
1528
|
+
|
|
1418
1529
|
/** Map API resource segment (e.g. "blogs", "form_submissions") to entity. Used by CRUD handler. */
|
|
1419
1530
|
declare const CMS_ENTITY_MAP: Record<string, EntityTarget<typeorm.ObjectLiteral>>;
|
|
1420
1531
|
|
|
1421
|
-
export { Address, type AnalyticsPluginConfig, Attribute, Blog, Brand, CMS_ENTITY_MAP, type CachePluginConfig, type CacheService, type CaptchaProviderId, type CaptchaPublicConfig, CaptchaService, type CaptchaVerifyResult, Cart, CartItem, Category, ChatConversation, ChatMessage, type CmsApp, type CmsPlugin, Collection, Comment, CompanyDetails, Config, Contact, type CreateCmsAppOptions, type DataSourceManager, type ERPPluginConfig, type ERPPluginInstance, ERPSubmissionService, type EmailData, type EmailJobPayload, type EmailPluginConfig, EmailService, type EmailServiceInterface, EmailTemplateName, EmailTemplateResult, EntityMap$2 as EntityMap, type ErpContactSyncInput, type ErpCreateContactPayload, type ErpJobPayload, type ErpPaidOrderDataSource, type ErpPaidOrderEntityMap, type ExtraPublicWriteRule, Form, FormField, FormSubmission, KnowledgeBaseChunk, KnowledgeBaseDocument, type LlmChatOptions, type LlmMessage, type LlmPluginConfig, LlmService, type LlmServiceInterface, type LocalStoragePluginConfig, type Logger, Media, MessageTemplate, Order, OrderItem, type OrderPlacedEmailPayload, OrderPlacedLineItem, OtpChallenge, type OtpChannel, type OtpPurpose, Page, PasswordResetToken, Payment, type PaymentIntent, type PaymentPluginConfig, type PaymentServiceInterface, Permission, type PipelineNames, type PluginContext, Product, ProductAttribute, ProductCategory, ProductTax, type PublicThemeSettingsPayload, type QueuePluginConfig, type QueueService, type RenderEmailOptions, type RenderedEmail, type S3StoragePluginConfig, Seo, type SeoLike, type SeoMetadataOverrides, type SmsJobPayload, type SmsPluginConfig, type SmsProviderChoice, type SmsProviderId, type SmsServiceConfig, type SmsServiceInterface, StorageService, Tag, Tax, TemplateContext, User, UserGroup, Wishlist, WishlistItem, ZIP_MIME_TYPES, allowRateLimit, analyticsPlugin, assertCaptchaOk, buildCaptchaPublicConfig, cachePlugin, captchaPlugin, cn, countRecentOtpSends, createCmsApp, createDataSourceManager, createOtpChallenge, emailPlugin, emailTemplates, erpPlugin, fetchSeoBySlug, formatDate, formatDateOnly, formatDateTime, generateNumericOtp, generateSlug, hashOtpCode, isZipMedia, joinRecipientsForSend, linkUnclaimedContactToUser, llmPlugin, loadPublicThemeSettings, localStoragePlugin, mergeSeoBySlug, normalizePhoneE164, parseEmailRecipientsFromConfig, paymentPlugin, queueEmail, queueErp, queueErpCreateContactIfEnabled, queueErpPaidOrderForOrderId, queueOrderPlacedEmails, queuePlugin, queueSms, rateLimitCheckoutPost, rateLimitKeyForApiRequest, rateLimitPublicApiIfNeeded, registerEmailQueueProcessor, registerErpQueueProcessor, registerSmsQueueProcessor, relativePathFromMediaParentId, renderEmail, renderLayout, resolvePublicMetadata, s3StoragePlugin, sanitizeMediaFolderPath, sanitizeStorageSegment, seedDefaultAdmin, sendOrderPlacedEmailsAfterConfirmation, serializeEmailRecipients, shouldRateLimitPublicWrite, smsPlugin, truncateText, validateSlug, verifyAndConsumeOtpChallenge, verifyOtpCodeHash };
|
|
1532
|
+
export { Address, type AnalyticsPluginConfig, Attribute, Blog, Brand, CMS_ENTITY_MAP, type CachePluginConfig, type CacheService, type CaptchaProviderId, type CaptchaPublicConfig, CaptchaService, type CaptchaVerifyResult, Cart, CartItem, Category, ChatConversation, ChatMessage, type CmsApp, type CmsPlugin, Collection, Comment, CompanyDetails, Config, Contact, type CreateCmsAppOptions, type DataSourceManager, type ERPPluginConfig, type ERPPluginInstance, ERPSubmissionService, type EmailData, type EmailJobPayload, type EmailPluginConfig, EmailService, type EmailServiceInterface, EmailTemplateName, EmailTemplateResult, EntityMap$2 as EntityMap, type ErpContactSyncInput, type ErpCreateContactPayload, type ErpJobPayload, type ErpPaidOrderDataSource, type ErpPaidOrderEntityMap, type ExtraPublicWriteRule, Form, FormField, FormSubmission, KnowledgeBaseChunk, KnowledgeBaseDocument, LlmAgent, type LlmAgentOptions, type LlmChatOptions, type LlmEmbeddingProvider, type LlmMessage, type LlmPluginConfig, LlmService, type LlmServiceEmbedOptions, type LlmServiceInterface, type LocalStoragePluginConfig, type Logger, Media, MessageTemplate, Order, OrderItem, type OrderPlacedEmailPayload, OrderPlacedLineItem, OtpChallenge, type OtpChannel, type OtpPurpose, Page, PasswordResetToken, Payment, type PaymentIntent, type PaymentPluginConfig, type PaymentServiceInterface, Permission, type PipelineNames, type PluginContext, Product, ProductAttribute, ProductCategory, ProductTax, type PublicThemeSettingsPayload, type QueuePluginConfig, type QueueService, type RenderEmailOptions, type RenderedEmail, type S3StoragePluginConfig, Seo, type SeoLike, type SeoMetadataOverrides, type SmsJobPayload, type SmsPluginConfig, type SmsProviderChoice, type SmsProviderId, type SmsServiceConfig, type SmsServiceInterface, StorageService, Tag, Tax, TemplateContext, User, UserGroup, Wishlist, WishlistItem, ZIP_MIME_TYPES, allowRateLimit, analyticsPlugin, assertCaptchaOk, buildCaptchaPublicConfig, cachePlugin, captchaPlugin, cn, countRecentOtpSends, createCmsApp, createDataSourceManager, createOtpChallenge, emailPlugin, emailTemplates, erpPlugin, fetchSeoBySlug, formatDate, formatDateOnly, formatDateTime, generateNumericOtp, generateSlug, hashOtpCode, isZipMedia, joinRecipientsForSend, linkUnclaimedContactToUser, llmAgentToChatAgentOptions, llmPlugin, loadPublicThemeSettings, localStoragePlugin, mergeSeoBySlug, normalizePhoneE164, parseEmailRecipientsFromConfig, parseHfInferenceEmbeddingBody, paymentPlugin, queueEmail, queueErp, queueErpCreateContactIfEnabled, queueErpPaidOrderForOrderId, queueOrderPlacedEmails, queuePlugin, queueSms, rateLimitCheckoutPost, rateLimitKeyForApiRequest, rateLimitPublicApiIfNeeded, registerEmailQueueProcessor, registerErpQueueProcessor, registerSmsQueueProcessor, relativePathFromMediaParentId, renderEmail, renderLayout, resolvePublicMetadata, s3StoragePlugin, sanitizeMediaFolderPath, sanitizeStorageSegment, seedDefaultAdmin, sendOrderPlacedEmailsAfterConfirmation, serializeEmailRecipients, shouldRateLimitPublicWrite, smsPlugin, truncateText, validateSlug, verifyAndConsumeOtpChallenge, verifyOtpCodeHash };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CompanyDetails, T as TemplateContext, E as EmailTemplateResult, a as EmailTemplateName, O as OrderPlacedLineItem, S as StorageService, b as EntityMap$2 } from './index-
|
|
2
|
-
export { A as AnalyticsHandlerConfig, c as AuthHandlersConfig, B as BlogBySlugConfig, d as ChangePasswordConfig, e as
|
|
1
|
+
import { C as CompanyDetails, T as TemplateContext, E as EmailTemplateResult, a as EmailTemplateName, O as OrderPlacedLineItem, S as StorageService, b as EntityMap$2 } from './index-Cnwh7B3r.js';
|
|
2
|
+
export { A as AnalyticsHandlerConfig, c as AuthHandlersConfig, B as BlogBySlugConfig, d as ChangePasswordConfig, e as ChatPublicConfig, f as CmsApiHandlerConfig, g as CmsGetter, h as CrudHandlerOptions, D as DashboardStatsConfig, i as EcommerceAnalyticsConfig, F as ForgotPasswordConfig, j as FormBySlugConfig, G as GetPublicSettingsGroupConfig, k as GetPublicSettingsGroupDataSource, I as InviteAcceptConfig, L as LlmAgentKnowledgeApiConfig, l as LlmAgentValidationRulesJson, P as ParsedLlmAgentValidation, m as SetPasswordConfig, n as SettingsApiConfig, o as SocialLinkItem, p as StorefrontApiConfig, q as StorefrontOtpFlags, U as UploadHandlerConfig, r as UserAuthApiConfig, s as UserAvatarConfig, t as UserProfileConfig, u as UsersApiConfig, v as createAnalyticsHandlers, w as createBlogBySlugHandler, x as createChangePasswordHandler, y as createCmsApiHandler, z as createCrudByIdHandler, H as createCrudHandler, J as createDashboardStatsHandler, K as createEcommerceAnalyticsHandler, M as createForgotPasswordHandler, N as createFormBySlugHandler, Q as createInviteAcceptHandler, R as createLlmAgentKnowledgeHandlers, V as createMediaZipExtractHandler, W as createSetPasswordHandler, X as createSettingsApiHandlers, Y as createStorefrontApiHandler, Z as createUploadHandler, _ as createUserAuthApiRouter, $ as createUserAvatarHandler, a0 as createUserProfileHandler, a1 as createUsersApiHandlers, a2 as getCompanyDetailsFromSettings, a3 as getPublicSettingsGroup, a4 as mergeEmailLayoutCompanyDetails, a5 as mergeGuardrailsIntoSystemPrompt, a6 as parseLlmAgentValidationRules, a7 as validateUserMessageAgainstAgentRules, a8 as validateUserMessageAgainstStructuredRules } from './index-Cnwh7B3r.js';
|
|
3
3
|
import { ClassValue } from 'clsx';
|
|
4
4
|
import * as typeorm from 'typeorm';
|
|
5
5
|
import { DataSource, EntityTarget, ObjectLiteral } from 'typeorm';
|
|
@@ -500,7 +500,23 @@ interface LlmMessage {
|
|
|
500
500
|
role: 'user' | 'assistant' | 'system';
|
|
501
501
|
content: string;
|
|
502
502
|
}
|
|
503
|
+
/** Passed to {@link LlmService.chat} / {@link LlmService.streamChat}; only `model`, `temperature`, and `max_tokens` are sent to the gateway. */
|
|
503
504
|
interface LlmChatOptions {
|
|
505
|
+
systemPrompt?: string;
|
|
506
|
+
userPrompt?: string;
|
|
507
|
+
history?: LlmMessage[];
|
|
508
|
+
context?: string;
|
|
509
|
+
model?: string;
|
|
510
|
+
temperature?: number;
|
|
511
|
+
max_tokens?: number;
|
|
512
|
+
}
|
|
513
|
+
/** Options for {@link LlmService.chatAgent} / {@link LlmService.streamChatAgent}: composes system + context + history + user into chat messages. */
|
|
514
|
+
interface LlmAgentOptions {
|
|
515
|
+
systemPrompt?: string;
|
|
516
|
+
userPrompt: string;
|
|
517
|
+
history?: LlmMessage[];
|
|
518
|
+
/** RAG or other material; merged into the system message when set. */
|
|
519
|
+
context?: string;
|
|
504
520
|
model?: string;
|
|
505
521
|
temperature?: number;
|
|
506
522
|
max_tokens?: number;
|
|
@@ -510,28 +526,85 @@ interface LlmServiceInterface {
|
|
|
510
526
|
content: string;
|
|
511
527
|
}>;
|
|
512
528
|
streamChat(messages: LlmMessage[], options?: LlmChatOptions): AsyncIterable<string>;
|
|
513
|
-
|
|
529
|
+
chatAgent(options: LlmAgentOptions): Promise<{
|
|
530
|
+
content: string;
|
|
531
|
+
}>;
|
|
532
|
+
streamChatAgent(options: LlmAgentOptions): AsyncIterable<string>;
|
|
533
|
+
/**
|
|
534
|
+
* Embeddings for RAG / knowledge base. Wire format depends on {@link LlmServiceEmbedOptions}:
|
|
535
|
+
* OpenAI `{base}/v1/embeddings`, or Hugging Face via `@huggingface/inference` (Hub-routed feature extraction) with legacy HTTP fallback.
|
|
536
|
+
*/
|
|
514
537
|
embed?(text: string, options?: {
|
|
515
538
|
model?: string;
|
|
516
539
|
}): Promise<number[]>;
|
|
517
540
|
}
|
|
541
|
+
declare function parseHfInferenceEmbeddingBody(data: unknown): number[] | null;
|
|
542
|
+
type LlmEmbeddingProvider = 'openai' | 'huggingface';
|
|
543
|
+
interface LlmServiceEmbedOptions {
|
|
544
|
+
embeddingProvider?: LlmEmbeddingProvider;
|
|
545
|
+
/** Legacy manual HTTP base when the Inference SDK path fails; default `https://router.huggingface.co/v1` (router host is normalized to `…/hf-inference`). */
|
|
546
|
+
hfInferenceBaseUrl?: string;
|
|
547
|
+
/** Token for embedding calls; defaults to chat `apiKey`. */
|
|
548
|
+
embeddingApiKey?: string;
|
|
549
|
+
/**
|
|
550
|
+
* Default `model` for `POST …/v1/chat/completions` when the caller omits `model`.
|
|
551
|
+
* Set via plugin / CMS `LLM_CHAT_MODEL` or env `LLM_CHAT_MODEL`.
|
|
552
|
+
* If unset, the library picks a fallback from `LLM_GATEWAY_URL` (HF router vs OpenRouter-style).
|
|
553
|
+
*/
|
|
554
|
+
defaultChatModel?: string;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Set `LLM_DEBUG=1` (or `true` / `yes`) to log composed chat payloads.
|
|
558
|
+
* Set `LLM_EMBED_DEBUG=1` for per-request embedding logs (verbose with many chunks).
|
|
559
|
+
* Set `LLM_CHAT_MODEL` for the default chat model when agents/requests omit `model` (gateway-specific id).
|
|
560
|
+
* If unset, fallback is chosen from `LLM_GATEWAY_URL` (HF vs other).
|
|
561
|
+
*/
|
|
518
562
|
declare class LlmService implements LlmServiceInterface {
|
|
563
|
+
private static embedHttpErrorLogged;
|
|
564
|
+
private static embedShapeErrorLogged;
|
|
565
|
+
private static embedSuccessLogged;
|
|
566
|
+
private static hfDimensionMismatchWarned;
|
|
567
|
+
private static hfInferenceSdkErrorLogged;
|
|
519
568
|
private readonly baseURL;
|
|
520
569
|
private readonly apiKey;
|
|
521
570
|
private readonly defaultEmbeddingModel?;
|
|
522
|
-
private
|
|
523
|
-
|
|
571
|
+
private readonly embeddingProvider;
|
|
572
|
+
private readonly hfInferenceBaseURL;
|
|
573
|
+
private readonly embeddingApiKey;
|
|
574
|
+
private readonly defaultChatModel;
|
|
575
|
+
constructor(baseURL: string, apiKey: string, defaultEmbeddingModel?: string, embedOpts?: LlmServiceEmbedOptions);
|
|
576
|
+
private resolveChatModel;
|
|
524
577
|
private get base();
|
|
525
578
|
private get url();
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
*/
|
|
579
|
+
private llmDebugEnabled;
|
|
580
|
+
/** Per-request embedding logs (noisy with many chunks). Set `LLM_EMBED_DEBUG=1`. */
|
|
581
|
+
private embedDebugEnabled;
|
|
582
|
+
private logAgentComposition;
|
|
583
|
+
private logChatCompletionsRequest;
|
|
532
584
|
embed(text: string, options?: {
|
|
533
585
|
model?: string;
|
|
534
586
|
}): Promise<number[]>;
|
|
587
|
+
/**
|
|
588
|
+
* POST `{ url }` with OpenAI-style `{ model, input }` and Bearer token; parses `{ data:[{embedding}] }`.
|
|
589
|
+
*/
|
|
590
|
+
private fetchOpenAiShapeEmbeddings;
|
|
591
|
+
/**
|
|
592
|
+
* Hugging Face–recommended path: Hub resolves a provider that supports `feature-extraction` for the model.
|
|
593
|
+
*/
|
|
594
|
+
private embedViaHuggingfaceInferenceSdk;
|
|
595
|
+
/** Base URL for legacy `…/pipeline/…` and `…/models/{model}` tries (HF router only). */
|
|
596
|
+
private hfLegacyInferenceBase;
|
|
597
|
+
/**
|
|
598
|
+
* Hugging Face embeddings: `@huggingface/inference` (Hub-routed feature extraction), then
|
|
599
|
+
* legacy direct `hf-inference` HTTP tries. Note: `https://router.huggingface.co/v1/embeddings` is not
|
|
600
|
+
* offered for embeddings (OpenAI-compatible `/v1` on HF is chat-only).
|
|
601
|
+
*/
|
|
602
|
+
private embedHuggingFaceInference;
|
|
603
|
+
private buildAgentMessages;
|
|
604
|
+
chatAgent(options: LlmAgentOptions): Promise<{
|
|
605
|
+
content: string;
|
|
606
|
+
}>;
|
|
607
|
+
streamChatAgent(options: LlmAgentOptions): AsyncIterable<string>;
|
|
535
608
|
chat(messages: LlmMessage[], options?: LlmChatOptions): Promise<{
|
|
536
609
|
content: string;
|
|
537
610
|
}>;
|
|
@@ -541,8 +614,19 @@ declare class LlmService implements LlmServiceInterface {
|
|
|
541
614
|
interface LlmPluginConfig {
|
|
542
615
|
baseURL?: string;
|
|
543
616
|
apiKey?: string;
|
|
544
|
-
/** Default model
|
|
617
|
+
/** Default chat model when agents omit `model` (`POST /v1/chat/completions`). Env: `LLM_CHAT_MODEL`. If unset, inferred from `LLM_GATEWAY_URL` (HF vs OpenRouter-style default). */
|
|
618
|
+
defaultChatModel?: string;
|
|
619
|
+
/** Default model for embed(); also from env EMBEDDING_MODEL. */
|
|
545
620
|
embeddingModel?: string;
|
|
621
|
+
/**
|
|
622
|
+
* `openai` (default): `POST {LLM_GATEWAY_URL}/v1/embeddings`.
|
|
623
|
+
* `huggingface`: `@huggingface/inference` feature extraction (Hub-routed), with legacy `…/hf-inference/…` HTTP fallback. Env: `EMBEDDING_PROVIDER=huggingface`.
|
|
624
|
+
*/
|
|
625
|
+
embeddingProvider?: LlmEmbeddingProvider;
|
|
626
|
+
/** Legacy HTTP base if the SDK path fails; default `https://router.huggingface.co/v1` (router hosts map to `…/hf-inference`). Env: `HF_INFERENCE_URL`. */
|
|
627
|
+
hfInferenceBaseUrl?: string;
|
|
628
|
+
/** Optional; defaults to `apiKey`. Env: `EMBEDDING_API_KEY`. */
|
|
629
|
+
embeddingApiKey?: string;
|
|
546
630
|
}
|
|
547
631
|
declare function llmPlugin(config?: LlmPluginConfig): CmsPlugin<LlmService | undefined>;
|
|
548
632
|
|
|
@@ -1415,7 +1499,34 @@ declare class Wishlist {
|
|
|
1415
1499
|
items: WishlistItem[];
|
|
1416
1500
|
}
|
|
1417
1501
|
|
|
1502
|
+
declare class LlmAgent {
|
|
1503
|
+
id: number;
|
|
1504
|
+
name: string;
|
|
1505
|
+
/** Stable key for API / widgets (e.g. `support`, `sales`). */
|
|
1506
|
+
slug: string;
|
|
1507
|
+
/** Passed as `systemPrompt` to `LlmService.chatAgent`. */
|
|
1508
|
+
systemInstruction: string;
|
|
1509
|
+
model: string | null;
|
|
1510
|
+
temperature: number | null;
|
|
1511
|
+
maxTokens: number | null;
|
|
1512
|
+
/**
|
|
1513
|
+
* Rules string: plain prose → appended to system prompt as output guardrails; JSON → see `parseLlmAgentValidationRules` in cms-handlers
|
|
1514
|
+
* (structural checks + optional `guardrails` / `outputRules` / `outputInstructions` for the model).
|
|
1515
|
+
*/
|
|
1516
|
+
validationRules: string | null;
|
|
1517
|
+
enabled: boolean;
|
|
1518
|
+
createdAt: Date;
|
|
1519
|
+
updatedAt: Date;
|
|
1520
|
+
deletedAt: Date | null;
|
|
1521
|
+
deleted: boolean;
|
|
1522
|
+
createdBy: number | null;
|
|
1523
|
+
updatedBy: number | null;
|
|
1524
|
+
deletedBy: number | null;
|
|
1525
|
+
}
|
|
1526
|
+
/** Partial {@link LlmAgentOptions} for merging with `userPrompt` / `history` / `context`. */
|
|
1527
|
+
declare function llmAgentToChatAgentOptions(agent: LlmAgent): Pick<LlmAgentOptions, 'systemPrompt' | 'model' | 'temperature' | 'max_tokens'>;
|
|
1528
|
+
|
|
1418
1529
|
/** Map API resource segment (e.g. "blogs", "form_submissions") to entity. Used by CRUD handler. */
|
|
1419
1530
|
declare const CMS_ENTITY_MAP: Record<string, EntityTarget<typeorm.ObjectLiteral>>;
|
|
1420
1531
|
|
|
1421
|
-
export { Address, type AnalyticsPluginConfig, Attribute, Blog, Brand, CMS_ENTITY_MAP, type CachePluginConfig, type CacheService, type CaptchaProviderId, type CaptchaPublicConfig, CaptchaService, type CaptchaVerifyResult, Cart, CartItem, Category, ChatConversation, ChatMessage, type CmsApp, type CmsPlugin, Collection, Comment, CompanyDetails, Config, Contact, type CreateCmsAppOptions, type DataSourceManager, type ERPPluginConfig, type ERPPluginInstance, ERPSubmissionService, type EmailData, type EmailJobPayload, type EmailPluginConfig, EmailService, type EmailServiceInterface, EmailTemplateName, EmailTemplateResult, EntityMap$2 as EntityMap, type ErpContactSyncInput, type ErpCreateContactPayload, type ErpJobPayload, type ErpPaidOrderDataSource, type ErpPaidOrderEntityMap, type ExtraPublicWriteRule, Form, FormField, FormSubmission, KnowledgeBaseChunk, KnowledgeBaseDocument, type LlmChatOptions, type LlmMessage, type LlmPluginConfig, LlmService, type LlmServiceInterface, type LocalStoragePluginConfig, type Logger, Media, MessageTemplate, Order, OrderItem, type OrderPlacedEmailPayload, OrderPlacedLineItem, OtpChallenge, type OtpChannel, type OtpPurpose, Page, PasswordResetToken, Payment, type PaymentIntent, type PaymentPluginConfig, type PaymentServiceInterface, Permission, type PipelineNames, type PluginContext, Product, ProductAttribute, ProductCategory, ProductTax, type PublicThemeSettingsPayload, type QueuePluginConfig, type QueueService, type RenderEmailOptions, type RenderedEmail, type S3StoragePluginConfig, Seo, type SeoLike, type SeoMetadataOverrides, type SmsJobPayload, type SmsPluginConfig, type SmsProviderChoice, type SmsProviderId, type SmsServiceConfig, type SmsServiceInterface, StorageService, Tag, Tax, TemplateContext, User, UserGroup, Wishlist, WishlistItem, ZIP_MIME_TYPES, allowRateLimit, analyticsPlugin, assertCaptchaOk, buildCaptchaPublicConfig, cachePlugin, captchaPlugin, cn, countRecentOtpSends, createCmsApp, createDataSourceManager, createOtpChallenge, emailPlugin, emailTemplates, erpPlugin, fetchSeoBySlug, formatDate, formatDateOnly, formatDateTime, generateNumericOtp, generateSlug, hashOtpCode, isZipMedia, joinRecipientsForSend, linkUnclaimedContactToUser, llmPlugin, loadPublicThemeSettings, localStoragePlugin, mergeSeoBySlug, normalizePhoneE164, parseEmailRecipientsFromConfig, paymentPlugin, queueEmail, queueErp, queueErpCreateContactIfEnabled, queueErpPaidOrderForOrderId, queueOrderPlacedEmails, queuePlugin, queueSms, rateLimitCheckoutPost, rateLimitKeyForApiRequest, rateLimitPublicApiIfNeeded, registerEmailQueueProcessor, registerErpQueueProcessor, registerSmsQueueProcessor, relativePathFromMediaParentId, renderEmail, renderLayout, resolvePublicMetadata, s3StoragePlugin, sanitizeMediaFolderPath, sanitizeStorageSegment, seedDefaultAdmin, sendOrderPlacedEmailsAfterConfirmation, serializeEmailRecipients, shouldRateLimitPublicWrite, smsPlugin, truncateText, validateSlug, verifyAndConsumeOtpChallenge, verifyOtpCodeHash };
|
|
1532
|
+
export { Address, type AnalyticsPluginConfig, Attribute, Blog, Brand, CMS_ENTITY_MAP, type CachePluginConfig, type CacheService, type CaptchaProviderId, type CaptchaPublicConfig, CaptchaService, type CaptchaVerifyResult, Cart, CartItem, Category, ChatConversation, ChatMessage, type CmsApp, type CmsPlugin, Collection, Comment, CompanyDetails, Config, Contact, type CreateCmsAppOptions, type DataSourceManager, type ERPPluginConfig, type ERPPluginInstance, ERPSubmissionService, type EmailData, type EmailJobPayload, type EmailPluginConfig, EmailService, type EmailServiceInterface, EmailTemplateName, EmailTemplateResult, EntityMap$2 as EntityMap, type ErpContactSyncInput, type ErpCreateContactPayload, type ErpJobPayload, type ErpPaidOrderDataSource, type ErpPaidOrderEntityMap, type ExtraPublicWriteRule, Form, FormField, FormSubmission, KnowledgeBaseChunk, KnowledgeBaseDocument, LlmAgent, type LlmAgentOptions, type LlmChatOptions, type LlmEmbeddingProvider, type LlmMessage, type LlmPluginConfig, LlmService, type LlmServiceEmbedOptions, type LlmServiceInterface, type LocalStoragePluginConfig, type Logger, Media, MessageTemplate, Order, OrderItem, type OrderPlacedEmailPayload, OrderPlacedLineItem, OtpChallenge, type OtpChannel, type OtpPurpose, Page, PasswordResetToken, Payment, type PaymentIntent, type PaymentPluginConfig, type PaymentServiceInterface, Permission, type PipelineNames, type PluginContext, Product, ProductAttribute, ProductCategory, ProductTax, type PublicThemeSettingsPayload, type QueuePluginConfig, type QueueService, type RenderEmailOptions, type RenderedEmail, type S3StoragePluginConfig, Seo, type SeoLike, type SeoMetadataOverrides, type SmsJobPayload, type SmsPluginConfig, type SmsProviderChoice, type SmsProviderId, type SmsServiceConfig, type SmsServiceInterface, StorageService, Tag, Tax, TemplateContext, User, UserGroup, Wishlist, WishlistItem, ZIP_MIME_TYPES, allowRateLimit, analyticsPlugin, assertCaptchaOk, buildCaptchaPublicConfig, cachePlugin, captchaPlugin, cn, countRecentOtpSends, createCmsApp, createDataSourceManager, createOtpChallenge, emailPlugin, emailTemplates, erpPlugin, fetchSeoBySlug, formatDate, formatDateOnly, formatDateTime, generateNumericOtp, generateSlug, hashOtpCode, isZipMedia, joinRecipientsForSend, linkUnclaimedContactToUser, llmAgentToChatAgentOptions, llmPlugin, loadPublicThemeSettings, localStoragePlugin, mergeSeoBySlug, normalizePhoneE164, parseEmailRecipientsFromConfig, parseHfInferenceEmbeddingBody, paymentPlugin, queueEmail, queueErp, queueErpCreateContactIfEnabled, queueErpPaidOrderForOrderId, queueOrderPlacedEmails, queuePlugin, queueSms, rateLimitCheckoutPost, rateLimitKeyForApiRequest, rateLimitPublicApiIfNeeded, registerEmailQueueProcessor, registerErpQueueProcessor, registerSmsQueueProcessor, relativePathFromMediaParentId, renderEmail, renderLayout, resolvePublicMetadata, s3StoragePlugin, sanitizeMediaFolderPath, sanitizeStorageSegment, seedDefaultAdmin, sendOrderPlacedEmailsAfterConfirmation, serializeEmailRecipients, shouldRateLimitPublicWrite, smsPlugin, truncateText, validateSlug, verifyAndConsumeOtpChallenge, verifyOtpCodeHash };
|