@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/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-D2C1O9b4.cjs';
2
- export { A as AnalyticsHandlerConfig, c as AuthHandlersConfig, B as BlogBySlugConfig, d as ChangePasswordConfig, e as CmsApiHandlerConfig, f as CmsGetter, g as CrudHandlerOptions, D as DashboardStatsConfig, h as EcommerceAnalyticsConfig, F as ForgotPasswordConfig, i as FormBySlugConfig, G as GetPublicSettingsGroupConfig, j as GetPublicSettingsGroupDataSource, I as InviteAcceptConfig, k as SetPasswordConfig, l as SettingsApiConfig, m as SocialLinkItem, n as StorefrontApiConfig, o as StorefrontOtpFlags, U as UploadHandlerConfig, p as UserAuthApiConfig, q as UserAvatarConfig, r as UserProfileConfig, s as UsersApiConfig, t as createAnalyticsHandlers, u as createBlogBySlugHandler, v as createChangePasswordHandler, w as createCmsApiHandler, x as createCrudByIdHandler, y as createCrudHandler, z as createDashboardStatsHandler, H as createEcommerceAnalyticsHandler, J as createForgotPasswordHandler, K as createFormBySlugHandler, L as createInviteAcceptHandler, M as createMediaZipExtractHandler, N as createSetPasswordHandler, P as createSettingsApiHandlers, Q as createStorefrontApiHandler, R as createUploadHandler, V as createUserAuthApiRouter, W as createUserAvatarHandler, X as createUserProfileHandler, Y as createUsersApiHandlers, Z as getCompanyDetailsFromSettings, _ as getPublicSettingsGroup, $ as mergeEmailLayoutCompanyDetails } from './index-D2C1O9b4.cjs';
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-DGtM2Gsk.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-DGtM2Gsk.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,62 @@ interface LlmServiceInterface {
510
526
  content: string;
511
527
  }>;
512
528
  streamChat(messages: LlmMessage[], options?: LlmChatOptions): AsyncIterable<string>;
513
- /** OpenAI-compatible embeddings; returns [] if gateway does not support /v1/embeddings */
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 Inference `…/models/{model}`.
536
+ */
514
537
  embed?(text: string, options?: {
515
538
  model?: string;
516
539
  }): Promise<number[]>;
517
540
  }
541
+ /**
542
+ * Normalize Hugging Face Inference feature-extraction response to a single `number[]`.
543
+ */
544
+ declare function parseHfInferenceEmbeddingBody(data: unknown): number[] | null;
545
+ type LlmEmbeddingProvider = 'openai' | 'huggingface';
546
+ interface LlmServiceEmbedOptions {
547
+ embeddingProvider?: LlmEmbeddingProvider;
548
+ /** Default `https://api-inference.huggingface.co` when using Hugging Face Inference. */
549
+ hfInferenceBaseUrl?: string;
550
+ /** Token for embedding calls; defaults to chat `apiKey`. */
551
+ embeddingApiKey?: string;
552
+ }
553
+ /**
554
+ * Set `LLM_DEBUG=1` (or `true` / `yes`) to log composed chat payloads.
555
+ * Set `LLM_EMBED_DEBUG=1` for per-request embedding logs (verbose with many chunks).
556
+ */
518
557
  declare class LlmService implements LlmServiceInterface {
558
+ private static embedHttpErrorLogged;
559
+ private static embedShapeErrorLogged;
560
+ private static embedSuccessLogged;
561
+ private static hfDimensionMismatchWarned;
519
562
  private readonly baseURL;
520
563
  private readonly apiKey;
521
564
  private readonly defaultEmbeddingModel?;
522
- private static embedWarned;
523
- constructor(baseURL: string, apiKey: string, defaultEmbeddingModel?: string | undefined);
565
+ private readonly embeddingProvider;
566
+ private readonly hfInferenceBaseURL;
567
+ private readonly embeddingApiKey;
568
+ constructor(baseURL: string, apiKey: string, defaultEmbeddingModel?: string, embedOpts?: LlmServiceEmbedOptions);
524
569
  private get base();
525
570
  private get url();
526
- /**
527
- * OpenAI-compatible embeddings. Returns [] if endpoint not available or unexpected response.
528
- * Server must implement: POST /v1/embeddings
529
- * Body: { model: string, input: string }
530
- * Response: { data: [ { embedding: number[] } ] } or { embedding: number[] }
531
- */
571
+ private llmDebugEnabled;
572
+ /** Per-request embedding logs (noisy with many chunks). Set `LLM_EMBED_DEBUG=1`. */
573
+ private embedDebugEnabled;
574
+ private logAgentComposition;
575
+ private logChatCompletionsRequest;
532
576
  embed(text: string, options?: {
533
577
  model?: string;
534
578
  }): Promise<number[]>;
579
+ private embedHuggingFaceInference;
580
+ private buildAgentMessages;
581
+ chatAgent(options: LlmAgentOptions): Promise<{
582
+ content: string;
583
+ }>;
584
+ streamChatAgent(options: LlmAgentOptions): AsyncIterable<string>;
535
585
  chat(messages: LlmMessage[], options?: LlmChatOptions): Promise<{
536
586
  content: string;
537
587
  }>;
@@ -541,8 +591,17 @@ declare class LlmService implements LlmServiceInterface {
541
591
  interface LlmPluginConfig {
542
592
  baseURL?: string;
543
593
  apiKey?: string;
544
- /** Default model for embed(); also from env EMBEDDING_MODEL (e.g. for Qwen use your server's embedding model name). */
594
+ /** Default model for embed(); also from env EMBEDDING_MODEL. */
545
595
  embeddingModel?: string;
596
+ /**
597
+ * `openai` (default): `POST {LLM_GATEWAY_URL}/v1/embeddings`.
598
+ * `huggingface`: `POST {HF_INFERENCE_URL}/models/{EMBEDDING_MODEL}` (Inference API). Env: `EMBEDDING_PROVIDER=huggingface`.
599
+ */
600
+ embeddingProvider?: LlmEmbeddingProvider;
601
+ /** Hugging Face Inference API base; default `https://api-inference.huggingface.co`. Env: `HF_INFERENCE_URL`. */
602
+ hfInferenceBaseUrl?: string;
603
+ /** Optional; defaults to `apiKey`. Env: `EMBEDDING_API_KEY`. */
604
+ embeddingApiKey?: string;
546
605
  }
547
606
  declare function llmPlugin(config?: LlmPluginConfig): CmsPlugin<LlmService | undefined>;
548
607
 
@@ -1415,7 +1474,34 @@ declare class Wishlist {
1415
1474
  items: WishlistItem[];
1416
1475
  }
1417
1476
 
1477
+ declare class LlmAgent {
1478
+ id: number;
1479
+ name: string;
1480
+ /** Stable key for API / widgets (e.g. `support`, `sales`). */
1481
+ slug: string;
1482
+ /** Passed as `systemPrompt` to `LlmService.chatAgent`. */
1483
+ systemInstruction: string;
1484
+ model: string | null;
1485
+ temperature: number | null;
1486
+ maxTokens: number | null;
1487
+ /**
1488
+ * Rules string: plain prose → appended to system prompt as output guardrails; JSON → see `parseLlmAgentValidationRules` in cms-handlers
1489
+ * (structural checks + optional `guardrails` / `outputRules` / `outputInstructions` for the model).
1490
+ */
1491
+ validationRules: string | null;
1492
+ enabled: boolean;
1493
+ createdAt: Date;
1494
+ updatedAt: Date;
1495
+ deletedAt: Date | null;
1496
+ deleted: boolean;
1497
+ createdBy: number | null;
1498
+ updatedBy: number | null;
1499
+ deletedBy: number | null;
1500
+ }
1501
+ /** Partial {@link LlmAgentOptions} for merging with `userPrompt` / `history` / `context`. */
1502
+ declare function llmAgentToChatAgentOptions(agent: LlmAgent): Pick<LlmAgentOptions, 'systemPrompt' | 'model' | 'temperature' | 'max_tokens'>;
1503
+
1418
1504
  /** Map API resource segment (e.g. "blogs", "form_submissions") to entity. Used by CRUD handler. */
1419
1505
  declare const CMS_ENTITY_MAP: Record<string, EntityTarget<typeorm.ObjectLiteral>>;
1420
1506
 
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 };
1507
+ 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-GMn7-9PX.js';
2
- export { A as AnalyticsHandlerConfig, c as AuthHandlersConfig, B as BlogBySlugConfig, d as ChangePasswordConfig, e as CmsApiHandlerConfig, f as CmsGetter, g as CrudHandlerOptions, D as DashboardStatsConfig, h as EcommerceAnalyticsConfig, F as ForgotPasswordConfig, i as FormBySlugConfig, G as GetPublicSettingsGroupConfig, j as GetPublicSettingsGroupDataSource, I as InviteAcceptConfig, k as SetPasswordConfig, l as SettingsApiConfig, m as SocialLinkItem, n as StorefrontApiConfig, o as StorefrontOtpFlags, U as UploadHandlerConfig, p as UserAuthApiConfig, q as UserAvatarConfig, r as UserProfileConfig, s as UsersApiConfig, t as createAnalyticsHandlers, u as createBlogBySlugHandler, v as createChangePasswordHandler, w as createCmsApiHandler, x as createCrudByIdHandler, y as createCrudHandler, z as createDashboardStatsHandler, H as createEcommerceAnalyticsHandler, J as createForgotPasswordHandler, K as createFormBySlugHandler, L as createInviteAcceptHandler, M as createMediaZipExtractHandler, N as createSetPasswordHandler, P as createSettingsApiHandlers, Q as createStorefrontApiHandler, R as createUploadHandler, V as createUserAuthApiRouter, W as createUserAvatarHandler, X as createUserProfileHandler, Y as createUsersApiHandlers, Z as getCompanyDetailsFromSettings, _ as getPublicSettingsGroup, $ as mergeEmailLayoutCompanyDetails } from './index-GMn7-9PX.js';
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--GBYw5JE.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--GBYw5JE.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,62 @@ interface LlmServiceInterface {
510
526
  content: string;
511
527
  }>;
512
528
  streamChat(messages: LlmMessage[], options?: LlmChatOptions): AsyncIterable<string>;
513
- /** OpenAI-compatible embeddings; returns [] if gateway does not support /v1/embeddings */
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 Inference `…/models/{model}`.
536
+ */
514
537
  embed?(text: string, options?: {
515
538
  model?: string;
516
539
  }): Promise<number[]>;
517
540
  }
541
+ /**
542
+ * Normalize Hugging Face Inference feature-extraction response to a single `number[]`.
543
+ */
544
+ declare function parseHfInferenceEmbeddingBody(data: unknown): number[] | null;
545
+ type LlmEmbeddingProvider = 'openai' | 'huggingface';
546
+ interface LlmServiceEmbedOptions {
547
+ embeddingProvider?: LlmEmbeddingProvider;
548
+ /** Default `https://api-inference.huggingface.co` when using Hugging Face Inference. */
549
+ hfInferenceBaseUrl?: string;
550
+ /** Token for embedding calls; defaults to chat `apiKey`. */
551
+ embeddingApiKey?: string;
552
+ }
553
+ /**
554
+ * Set `LLM_DEBUG=1` (or `true` / `yes`) to log composed chat payloads.
555
+ * Set `LLM_EMBED_DEBUG=1` for per-request embedding logs (verbose with many chunks).
556
+ */
518
557
  declare class LlmService implements LlmServiceInterface {
558
+ private static embedHttpErrorLogged;
559
+ private static embedShapeErrorLogged;
560
+ private static embedSuccessLogged;
561
+ private static hfDimensionMismatchWarned;
519
562
  private readonly baseURL;
520
563
  private readonly apiKey;
521
564
  private readonly defaultEmbeddingModel?;
522
- private static embedWarned;
523
- constructor(baseURL: string, apiKey: string, defaultEmbeddingModel?: string | undefined);
565
+ private readonly embeddingProvider;
566
+ private readonly hfInferenceBaseURL;
567
+ private readonly embeddingApiKey;
568
+ constructor(baseURL: string, apiKey: string, defaultEmbeddingModel?: string, embedOpts?: LlmServiceEmbedOptions);
524
569
  private get base();
525
570
  private get url();
526
- /**
527
- * OpenAI-compatible embeddings. Returns [] if endpoint not available or unexpected response.
528
- * Server must implement: POST /v1/embeddings
529
- * Body: { model: string, input: string }
530
- * Response: { data: [ { embedding: number[] } ] } or { embedding: number[] }
531
- */
571
+ private llmDebugEnabled;
572
+ /** Per-request embedding logs (noisy with many chunks). Set `LLM_EMBED_DEBUG=1`. */
573
+ private embedDebugEnabled;
574
+ private logAgentComposition;
575
+ private logChatCompletionsRequest;
532
576
  embed(text: string, options?: {
533
577
  model?: string;
534
578
  }): Promise<number[]>;
579
+ private embedHuggingFaceInference;
580
+ private buildAgentMessages;
581
+ chatAgent(options: LlmAgentOptions): Promise<{
582
+ content: string;
583
+ }>;
584
+ streamChatAgent(options: LlmAgentOptions): AsyncIterable<string>;
535
585
  chat(messages: LlmMessage[], options?: LlmChatOptions): Promise<{
536
586
  content: string;
537
587
  }>;
@@ -541,8 +591,17 @@ declare class LlmService implements LlmServiceInterface {
541
591
  interface LlmPluginConfig {
542
592
  baseURL?: string;
543
593
  apiKey?: string;
544
- /** Default model for embed(); also from env EMBEDDING_MODEL (e.g. for Qwen use your server's embedding model name). */
594
+ /** Default model for embed(); also from env EMBEDDING_MODEL. */
545
595
  embeddingModel?: string;
596
+ /**
597
+ * `openai` (default): `POST {LLM_GATEWAY_URL}/v1/embeddings`.
598
+ * `huggingface`: `POST {HF_INFERENCE_URL}/models/{EMBEDDING_MODEL}` (Inference API). Env: `EMBEDDING_PROVIDER=huggingface`.
599
+ */
600
+ embeddingProvider?: LlmEmbeddingProvider;
601
+ /** Hugging Face Inference API base; default `https://api-inference.huggingface.co`. Env: `HF_INFERENCE_URL`. */
602
+ hfInferenceBaseUrl?: string;
603
+ /** Optional; defaults to `apiKey`. Env: `EMBEDDING_API_KEY`. */
604
+ embeddingApiKey?: string;
546
605
  }
547
606
  declare function llmPlugin(config?: LlmPluginConfig): CmsPlugin<LlmService | undefined>;
548
607
 
@@ -1415,7 +1474,34 @@ declare class Wishlist {
1415
1474
  items: WishlistItem[];
1416
1475
  }
1417
1476
 
1477
+ declare class LlmAgent {
1478
+ id: number;
1479
+ name: string;
1480
+ /** Stable key for API / widgets (e.g. `support`, `sales`). */
1481
+ slug: string;
1482
+ /** Passed as `systemPrompt` to `LlmService.chatAgent`. */
1483
+ systemInstruction: string;
1484
+ model: string | null;
1485
+ temperature: number | null;
1486
+ maxTokens: number | null;
1487
+ /**
1488
+ * Rules string: plain prose → appended to system prompt as output guardrails; JSON → see `parseLlmAgentValidationRules` in cms-handlers
1489
+ * (structural checks + optional `guardrails` / `outputRules` / `outputInstructions` for the model).
1490
+ */
1491
+ validationRules: string | null;
1492
+ enabled: boolean;
1493
+ createdAt: Date;
1494
+ updatedAt: Date;
1495
+ deletedAt: Date | null;
1496
+ deleted: boolean;
1497
+ createdBy: number | null;
1498
+ updatedBy: number | null;
1499
+ deletedBy: number | null;
1500
+ }
1501
+ /** Partial {@link LlmAgentOptions} for merging with `userPrompt` / `history` / `context`. */
1502
+ declare function llmAgentToChatAgentOptions(agent: LlmAgent): Pick<LlmAgentOptions, 'systemPrompt' | 'model' | 'temperature' | 'max_tokens'>;
1503
+
1418
1504
  /** Map API resource segment (e.g. "blogs", "form_submissions") to entity. Used by CRUD handler. */
1419
1505
  declare const CMS_ENTITY_MAP: Record<string, EntityTarget<typeorm.ObjectLiteral>>;
1420
1506
 
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 };
1507
+ 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 };