Вышел Модуль интеграций 2.0 для MedusaЧитать анонс
A

Ai chat

AI shopping assistant for Medusa v2 storefronts: answers from real catalog, stock, prices and policies (never invented), streams, and hands over to a human on WhatsApp — by Haus Kayu

npm install medusa-ai-chat
Категория
Создано
Версия
0.1.2
Последнее обновление
2 дня назад
Ежемесячные загрузки
Загрузка данных

Haus Kayu

medusa-ai-chat

An AI shopping assistant for Medusa v2 storefronts that only says what your store data says. It searches the catalog, reads prices, stock, variants and shipping rates through tools, quotes your own policy pages, streams the answer, and hands the visitor over to a human on WhatsApp (pre-filled message with a summary) whenever the question is a complaint, a refund, a negotiation, a custom order, or something it cannot answer. A sentence-level guard drops any amount the tools did not return, so an invented price never reaches the visitor.
Asisten AI untuk storefront Medusa v2 yang hanya menjawab dari data toko: cari produk, harga, stok, ongkir, kebijakan, streaming, dan oper ke WhatsApp CS dengan ringkasan obrolan. Angka yang tidak berasal dari tools tidak pernah tampil.

npm CI Medusa license: MIT

Screenshots

Admin → AI Assistant (demo store, example conversations) and the chat panel of a storefront (Kiln, the theme of hauskayu.com).

Overview: today's spend against the daily budget, 30-day countsConversations: filters, cost, handover and thumbs per chat
Admin overviewAdmin conversations
A conversation: tools called, tokens, cost, WhatsApp handoverSettings: switch, budget, greeting per language, extra instructions, FAQ
Admin conversationAdmin settings
Storefront, phone (Indonesian): answer with a product cardStorefront, desktop (English): handover to WhatsApp
Storefront phoneStorefront desktop

Compatibility

PluginMedusaNodeTested in CI on
0.1.x2.19.0 or newer 2.x ()20.19+ or 22.12+Medusa 2.19.0 and 2.22.2

Model providers: Anthropic (default, ), any OpenAI-compatible chat-completions API, and a deterministic mock for tests. Optional integrations it detects at runtime: the Meilisearch store route of (better search), the public rate card of (shipping estimates), the Local Notification Provider on channel (Admin bell on handover).

Quick start

Open AI Assistant in the Admin sidebar: switch, greeting, FAQ, daily budget, conversations, statistics. Storefront integration: , , then stream (server-sent events). Types and an SSE reader ship in . The Kiln theme has a ready-made glass chat panel for this plugin.

What the assistant can and cannot do

It doesIt never does
Searches products and quotes price, stock and variants per region/currency, in the visitor's language (Translation Module)States an amount, discount, stock level or delivery date no tool returned (the guard removes the sentence and offers CS)
Gives shipping services, per-kg rates and delivery estimates from the real rate cardPromises anything: discounts, reservations, refunds, custom work
Answers policy questions from your own pages (markdown, text or HTML) and the Admin FAQAsks for or accepts payment details (card numbers are blocked before the model and masked in storage)
Hands over to WhatsApp with greeting, summary, product links and a chat id; posts to the Admin feedFollows instructions found in customer text or catalog data (both are wrapped as data)
Streams the answer sentence by sentenceSends a prompt larger than (older turns are summarised first)

Store API

RoutePurpose
, , name, greeting, CS hours, WhatsApp number, privacy path, limits
→
→ SSE: , , , , , , or
→ the WhatsApp link for the "Chat with CS" button (summary of the conversation)

Every call carries the storefront's publishable key; the tools call your own Store API with the same key, so the assistant sees exactly the products, prices and stock that storefront sees. The session token is random and only its hash is stored; the IP address is stored as a salted hash for rate limiting only.

Admin API

, , , (filters , , , , ), .

Options

OptionDefaultNotes
for any OpenAI-compatible API (, required), for tests
Name of the environment variable holding the key
Anthropic effort level
known for Anthropic modelsUSD per million tokens ; needed for cost tracking of other models
/ / Facts for the model and the WhatsApp greeting
Base of product links; default ; (made-to-order page) ; default ; accepted market prefixes
/ Per locale; the Admin greeting overrides
Locales the storefront may request; the first is the fallback
Developer text appended to the system prompt (tone etc.)
International number without ; without it there is no handoff tool
Per locale; shown next to the CS button and told to the model
topic → locale → URL of a page the tool may read (cached , cut at )
Products with such metadata set to true are never shown
first localeLanguage the catalog is written in; the model retries a failed search with words in it
derivedMedusa translation locale per assistant locale (); default of the market
When a search finds nothing, this many products are listed and matched by words (title, description, categories, metadata); disables
tool; switches itself off when the zone-rate route is missing
see below 1000, 20, 12, 8000, 30000, 700, 4, 30, 100, 6
Spend cap per calendar day in (default UTC); the Admin setting overrides. Over the cap, visitors get the WhatsApp button only
Conversations are deleted by a nightly job
Admin bell on handover; for the link
Where the tools reach this server's Store API
Small plugin credit under the Admin page

Cost

With Claude Haiku 5.5 the stable prompt (rules + tools, ≈2,500 tokens) is read from the prompt cache after the first call of a 5-minute window; a typical turn with one tool call costs about $0.0005–0.001, a six-turn conversation $0.003–0.006. Cache writes, cache reads, input and output are all counted against the daily budget.

Other model calls on the same budget

Other features of the store that call a model with the same key (a search rewrite, a description helper) can share the assistant's daily budget, Admin statistics, rate limiter and price list through , the only public server API of the package (everything else is internal):

Export
Today's cap, total spend, the feature's spend and cap, (total reached the cap, or the feature its of it)
Adds a call to today's usage row and the feature counter; returns the cost in USD
/ USD per million tokens (the option for the assistant's model, else published prices) and the cost of one call
/ The assistant's per-IP limits and a fixed-window counter through the Cache Module, namespaced apart from the assistant's own
/ The visitor's address (Cloudflare header first) and its salted hash for rate-limit keys

Feature counters live in the Cache Module (Redis when the store has it) for two days; the daily total is the persistent usage row the assistant itself reads.

Privacy

Tell your visitors that chat messages are processed by the model provider (Anthropic, or the API you configured) and kept for . The storefront must show a consent notice before the first message and send ; the plugin refuses sessions without it. Card numbers are blocked and masked; IPs are hashed; the Admin can delete any conversation.

Development

See CONTRIBUTING.md. sends a red-team prompt set to a running store and prints the answers and guard notices (needs the real provider; costs a few cents).

MIT © Haus Kayu