@elastics-ai/host-kit
v0.6.0
Published
Elastics design tokens and custom elements for pages that Claude or ChatGPT publish.
Readme
@elastics-ai/host-kit
Elastics design tokens and eleven custom elements for a page that a host builds and publishes, such as a Claude artifact or a ChatGPT Site. The Elastics MCP tool get_style_kit tells the model which published version to load.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@elastics-ai/[email protected]/host-kit.css" integrity="sha384-…" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/@elastics-ai/[email protected]/host-kit.js" integrity="sha384-…" crossorigin="anonymous"></script>
<ex-card heading="Will BTC close above $100k?" state="live">
<ex-stat label="Yes price" value="62¢" change="+3¢" trend="up"></ex-stat>
<ex-book></ex-book>
</ex-card>
<script>
document.querySelector('ex-book').bids = [['0.62', '150'], ['0.61', '90']];
</script>This example documents version 0.3.1. Take its full tags, with their integrity values, from HOST_KIT_TAGS in src/index.ts at this version. get_style_kit sends the tags of the version that it serves. The browser then refuses a file whose bytes differ from the ones this repository built.
| Element | Input |
|---|---|
| ex-card | heading, state, label; children go in the card |
| ex-stat | label, value, format, change, trend (up or down) |
| ex-badge | state (live, stale, failed, off), label |
| ex-table | .columns = [{key, label, numeric, format, side}], .rows = [{...}] |
| ex-book | .asks, .bids as [[price, size]] or [{price, size}]; price="quote" for an instrument |
| ex-news-row | headline, url (linked only when https), source, time |
| ex-notification-row | headline, body, time, read |
| ex-run-row | status (running, failed, other), action, time |
| ex-chart | .points = [[time, price]] or [{time, price}], time in Unix seconds, price 0 to 1; label, height (200) |
| ex-tabs | children with data-label (and data-disabled) are the panels; label, value; fires change |
| ex-markets | .markets = [{title, price, volume, url, image}] |
| ex-outcomes | .event (the get_event answer), .feed (an await_feed_update answer); market; fires change with {market_id} |
| ex-holders | .holders (the get_market_holders answer) |
| ex-resolution | .market (the get_market answer) |
ex-book takes prediction-market prices from 0 to 1 and prints them in cents, with Price, Size and Total columns and the spread between the asks and the bids. With price="quote", it prints an instrument's prices in its quote currency in an 80px column, and the spread as a percentage of the best bid. A side with no levels says No Asks or No Bids. A level whose price is not a number shows at the far end of its side, outside the spread and the depth bars.
ex-chart draws a price line as the web app's line chart: cents on the price axis, dotted rules at its ticks, dates or the web app's 12h clock on the time axis, a dot on the last reading, and the moment and price under the pointer. ex-tabs draws pill tabs over its panels: the arrow keys move between tabs, Home and End jump, and Enter, Space or a click picks one. ex-markets lists markets as the web app's search rows: the title, then the Yes price in cents and the volume in compact dollars ($1.4M). A row links out only to an https url, and its tile shows an https image over the title's first two letters.
format prints a number as the web app does: cents for a 0 to 1 price (0.004 prints 0.4¢), usd for dollars ($3,113.68), amount for two decimals (169,439.48) and number for at most two (1,250). A numeric column without a format groups its thousands and keeps every decimal (0.0000123). A value that is not a number prints as it came. A column with side: true tints Buy and Sell, and side: "<key>" tints the cell by the row's side under that key, as the web app's tape tints its price.
Every element writes values with textContent, so markup in a feed value shows as text. The colours follow prefers-color-scheme, and a .light or .dark class on any ancestor pins one scheme.
Use class="ex-btn" for pill buttons and add data-variant="secondary" for a raised fill and border. <ex-tabs> uses a subtle track with an accent fill under the selected tab.
The script inserts the rules of host-kit.css itself, once per document, first in the head, so the page's own rules win. The rules come inside the script's bytes, which its integrity value covers, and the script fetches no stylesheet. So a Claude artifact, which loads stylesheets only from Google Fonts, needs only the script. A page can still link host-kit.css (HOST_KIT_TAGS.link): its rules equal the inserted ones. Released versions up to 0.4.0 insert only the rules of ex-chart, ex-tabs and ex-markets, so a page on one of them still needs the CSS.
Charts
host-kit-charts.js draws the web app's own line chart, candles, market chart, order book and trade tape, from packages/ui, in a shadow root. It is a separate script, so a page that draws no chart loads none of its weight. Load it after host-kit.js, which sets the tokens that the chart reads, with its own tag from HOST_KIT_TAGS.charts.
ex-market-chart draws its studies with host-kit-charts-studies.js, from the same folder as host-kit-charts.js. The chart adds that script, with its hash, the first time a study is on, so serve both files side by side.
| Element | Input |
|---|---|
| ex-price-chart | unit (probability or price, required with .points), .history, .points; label, height (200) |
| ex-candles | unit (probability or price, required with .points), .history, .points; label, height (260) |
| ex-market-chart | unit, .history, .points, .trades; label, height (320 for the price, each study pane adds its own), type (candles or line), volume (on or off), studies (sma ema bb vwap rsi macd), resolution, market, outcome; events interval and change |
| ex-orderbook | .book (a get_orderbook or get_instrument_orderbook answer, or an await_feed_update answer, one of its feeds, or its book); unit, outcome, market, label, height (420) |
| ex-trades | .trades (an await_feed_update answer or one of its feeds, each one added to the tape); market, outcome, binary, price="quote", height (360) |
| ex-market-header | .market (the get_market or get_instrument answer), .event (the get_event answer), .feed (an await_feed_update answer); side; fires change with {side} |
ex-market-header draws a market's two sides with host-kit.js's ex-tabs, so load host-kit.js before the charts file.
.history is the answer of get_price_history (a prediction market) or of get_instrument_history (a Hyperliquid instrument). Pass the tool answer as is: the chart knows each answer by its own fields and converts it. .points takes live readings or trades as ex-chart does: [time, price, size?] or {time, price, size}, time in Unix seconds. .points needs unit: probability for a prediction market, from 0 to 1, or price for a Hyperliquid instrument, in its quote asset. ex-price-chart draws the readings after the history's last bar, and ex-candles folds each trade into the last bar or a new bar after it. A reading before the last bar is already in the history, and neither element draws it. An input that the chart cannot read is said in the chart's place: .points with no unit, any other unit, a unit that the history's answer contradicts, a probability reading above 1, or a time in milliseconds.
ex-market-chart is the web app's market chart whole: a toolbar with the intervals 1m to 1W, candles or a line, the volume, and the indicators SMA, EMA, Bollinger Bands and VWAP over the price and RSI and MACD in panes under it. The toolbar sets the element's own attributes. A new interval needs new candles, which the page reads: on an interval event, call the same history tool with resolution: event.detail.resolution and set .history to its answer. The element never fetches. Each chart also takes .trades, an await_feed_update answer or one of its trades entries as it comes. A prediction market's chart then needs outcome, the get_market outcomes[].id of the side its history reads, and market where the answer holds several markets.
<ex-market-chart unit="probability" label="Yes" outcome="1234" studies="ema rsi"></ex-market-chart>
<script>
const chart = document.querySelector('ex-market-chart');
chart.history = priceHistoryAnswer; // get_price_history, as it came
chart.addEventListener('interval', async (e) => {
chart.history = await callTool(server, 'get_price_history', {
market_id: '7452089',
resolution: e.detail.resolution,
});
});
chart.trades = feedAnswer; // await_feed_update, as it came
</script><ex-candles unit="probability" label="Yes"></ex-candles>
<script>
const chart = document.querySelector('ex-candles');
chart.history = priceHistoryAnswer; // get_price_history, as it came
chart.points = [[1795979300, 0.72, 150]]; // a trade from the live feed
</script>ex-orderbook is the web app's order book: asks down to the spread, bids under it, a depth bar on each level and a flash on each level that changes. Set .book to the get_orderbook answer (a prediction market, in cents with dollar totals) or the get_instrument_orderbook answer (a Hyperliquid instrument, in its quote asset with cumulative size), as it came. Then set it to each await_feed_update answer as it comes: a live book replaces the levels up to its last price and keeps the farther ones. A tool answer replaces the whole book. Set market (a market or instrument id) before .book when an answer streams several books, and outcome (an outcome id or name) to show an outcome other than the first. A book alone, with no answer around it, names no unit, so it needs unit. The header says Offline when the feed is unavailable and Stale when its publisher last confirmed it longer ago than its stale_after_ms. A click on a level fires a price event, with { side, price, outcome } in its detail: side is buy on an ask and sell on a bid. The book places no order.
<ex-orderbook></ex-orderbook>
<script>
const book = document.querySelector('ex-orderbook');
book.book = orderbookAnswer; // get_orderbook, as it came
book.addEventListener('price', (e) => console.log(e.detail.price));
let cursor;
for (;;) {
const answer = await awaitFeedUpdate({ markets: [{ market_id: '2695678', feeds: ['orderbook'] }], cursor });
book.book = answer; // merged over the snapshot
cursor = answer.cursor;
}
</script>ex-trades is the web app's trade tape. Set .trades to each await_feed_update answer as it comes, or to one of its feeds: the element keeps the newest 100 prints, newest first, and flashes each print that arrives after the first answer, which is the feed's replay. On a binary market, give outcome (the outcome on screen) and binary, and a print on the other outcome reads mirrored, as on the web app. For a Hyperliquid instrument, set price="quote". Give market when one answer carries the trades of several markets. The tape says in its place a price that is not in its unit, such as a Polymarket price in cents, and a price that the feed contradicts: Polymarket's trades are probabilities from 0 to 1, and hl.trades are in the instrument's quote asset.
<ex-trades market="2695678" outcome="2293…5363" binary></ex-trades>
<script>
const tape = document.querySelector('ex-trades');
let cursor;
for (;;) {
const answer = await awaitFeedUpdate({ markets: [{ market_id: '2695678', feeds: ['trades'] }], cursor });
tape.trades = answer; // as it came
cursor = answer.cursor;
}
</script>TradingView chart
host-kit-tv.js defines ex-tv-chart, TradingView Advanced Charts with the web app's own settings and theme. Load it after host-kit.js, with its tag from HOST_KIT_TAGS.tv. It takes the inputs of ex-candles: unit, .history, .points, label, and height (360). It draws at the bar width of the history, and starts when the history arrives. A prediction market prints in cents with ¢ on the price scale, the last-price badge and the legend (0.4¢, 47¢), as the web chart does. A page can set .history before the script runs. A history with no bars shows No price history, as ex-candles does. An input the chart cannot read, or a library that does not load (The chart cannot load: …), is said in its place with role="alert".
The library ships in charting_library/, beside the script, and loads only on a page that draws an ex-tv-chart. The script loads it from the folder beside its own URL, so load the script with a <script src> tag. The library asks for its CSS with <link> elements, which a Claude artifact refuses, so the script fetches each sheet and inserts its text in a <style> instead.
Orders
host-kit-trade.js defines ex-trade: a self-contained prediction, perps or spot ticket in Shadow DOM. Load it after host-kit.js, which supplies tokens, with its tag from HOST_KIT_TAGS.trade. The card owns its draft and confirm state; the page supplies the market feed and the existing app-only tool bridge.
market: the market'sid, or the instrument'sidwithkind="perp"orkind="spot"(the defaultkindisprediction).side:buyorsell.outcome: a prediction market's outcome index (get_marketoutcomes).outcome-namelabels the outcome until Elastics returns its name.price: a limit price. Use a probability from 0 to 1 for a prediction market (0.62) or a price in USD for an instrument.price="auto"follows the current quote for the side and outcome. Omitpricefor a market order.sizein contracts or coins, oramountin dollars for a prediction market's market buy.size-unit="shares"keeps a prediction market buy's share count insize. The card prices whole shares against current ask depth and includes the fee when it previews the spend.size-unit="quote"keeps an instrument draft's quote amount insize. The card converts it to base size on the venue grid for review. Copysize-unitwith the other attributes when you replace the element.
The page can keep the existing attributes and set .market, .book and .feed to the market, order-book and live-feed answers as they arrive. .applyBookLevel({ outcome, side, price }) prefills a limit draft. A root price event from a same-market ex-orderbook or ex-book also prefills it. A prediction book price is a probability from 0 to 1; an instrument price is in its quote asset.
Keep the card mounted during feed updates so it can retain prices and freshness by outcome. A replacement card with only a tape update waits for a matching confirmed book before it enables market Review.
The page gives the element its host's tool bridge in .bridge, an object with call(tool, args). Keep the same bridge object during a session. Set it to null on disconnect and supply a new object for a new session. If the bridge exposes a sessionId, reassign the bridge when that value changes. Reapply market and book data after the session changes.
When the bridge and target are ready, the card reads open_market_ticket with { target, preview?, capacity? }. The optional preview contains the order fields and selected wallet_id. On an instrument, the card requests wallet-scoped capacity for its size presets. Max reads capacity again for the selected wallet. Review waits for that read. If it returns no capacity, Max can try again. The answer also provides the title, venue rules, outcomes, server-signable wallets, positions, and doubt. A draft or wallet change refreshes the preview.
The card keeps edits in page memory. A replacement with the same authored order attributes and bridge session resumes the draft. The card restores the authored order and uses the new default if a ticket removes the draft's wallet. A reload starts with the authored order. If an order uses live book data to derive its terms, Confirm checks that the same book still supports them. In a Claude artifact:
const mcp = await claude.use('mcp');
document.querySelector('ex-trade').bridge = mcp && {
call: (tool, args) => mcp.callTool(SERVER, tool, args, { cache: false }),
};The artifact lists open_market_ticket, place_market_order and open_trade_ticket among its connector's tools. The element calls no tool before it has both a bridge and a market target. The card provides buy/sell, Market/Limit, outcome, USD/Shares or USDC/coin, live conversion, balance presets, wallet selection, limit steppers, and order facts. The confirmation shows the server's market title, outcome, wallet and Terms, plus size, limit, notional, and fee. The venue sets the fee at fill. Confirm sends place_market_order with the draft fields, wallet_id, request_id, terms, and grant in one object, as defined by the tool. Elastics requires the exact preview terms.
The terms identify the market or instrument, the prediction outcome, the token when available, and the wallet ID. If Elastics refuses the grant of a confirmation or a retry, the element reads the ticket again before any order goes to the OMS. If the terms or the wallet change before the first send, the user confirms again. A retry keeps its wallet. A ticket read again shows an order that Elastics found, or tells the user to wait while an earlier order on the market has no known outcome.
A press whose outcome is not known keeps its request ID: after a lost or unclear reply, or after a refusal that arrives when another element has taken the same ID. Retry sends the order again under that ID, so the OMS places it at most once. The element keeps these IDs in session storage, where every ex-trade of the same origin in the browser tab reads them when it decides: on the page, in other frames, and after a reload. A new confirmation of an order whose ID is kept takes that ID when the user confirms, not when the ticket opens, and sends it. The order's figures compare by value, so 0.62 and 0.620 name the same price.
Session storage has limits. If the host refuses it, only the elements on one page share the IDs. If it refuses one write, the page keeps that ID, and other frames see it only after a later write from the page succeeds. If another script clears or corrupts the list, the elements on the page keep the IDs that the page last read, and other frames and a reload see them only after the page writes the list again. In these cases, a press in another frame or after a reload can send a new order. A clear can also make a Retry on the page send a new order: Elastics refuses the grant of the element's first send while another frame has a lost press of the same order. The element cannot tell a cleared list from an ID that another press took and then settled, so it keeps its ID for Retry.
The element releases a request ID when Elastics answers that the order was placed, or that the OMS ended the order under that ID with zero fills. If the page removed the element before the placed answer arrived, nobody saw that answer, so the element keeps the ID and the next press of the order shows that order. A refusal of a first send releases its ID too, unless another element took the ID before the refusal arrived. Every other refusal keeps the ID for Retry. After a release, the next confirmation can send a new order.
If Elastics cannot sign for the wallet, the element shows "Place in Elastics" from open_trade_ticket. The element reports invalid drafts with role="alert". change fires with { state, outcome } on each state change. All card styles live in the trade script's shadow root.
host-kit.js has no import or export, so it loads as a classic script or as a module, and from a file:// page. Open demo.html to see every element in both schemes.
License
Proprietary. Copyright Elastics, all rights reserved. See LICENSE. host-kit-charts.js also bundles third-party packages under their own licences, and charting_library/ holds TradingView Advanced Charts under Elastics' licence agreement with TradingView, Inc.; see THIRD_PARTY_NOTICES.txt.
