GRIETENS
Menu

Live updates: show the buyer the quote being made

For engine builders. The same document as plain Markdown, for an AI or a script: /kit/live-updates.md

A buyer who asks for a quote on Grietens waits on a page. While your engine works on the request it can show him the work: a line of what it is doing, a progress bar, and a live feed of text, pictures and files (a sketch of the roof, the truss layout, a draft offer). Send as many updates as you like, as often as you like, until the answer. They never change your price or anything final: the answer still comes as before (your answer to the call, or a callback with a status).

This document is public at https://grietens.cloud/kit/live-updates.md (also https://app.grietens.cloud/kit/live-updates.md). How to connect an engine at all: https://grietens.cloud/guides/en/connect-a-quote-engine-to-grietens.

The one call

Node kit (grietens-engine.mjs):

await engine.progress(request.request_id, { label: 'Reading the drawings', step: 1, of: 4,
  items: [{ text: 'Roof: gable, 30 degrees' }, { picture: './sketch.png' }] });

Python kit (grietens_engine.py):

engine.progress(request["request_id"], {"label": "Reading the drawings", "step": 1, "of": 4,
    "items": [{"text": "Roof: gable, 30 degrees"}, {"picture": "./sketch.png"}]})

A picture or a file may be a local path or bytes (the kit serves it at an unguessable address on your engine for Grietens to fetch) or an https address on your engine's own host: the same host name as your engine's address, at any path on it (see "Where a picture or a file may be" below). The call never throws for a network failure; it returns { ok, status, body, error }.

Write the labels and texts in the buyer's language. The request Grietens sends carries language, "lv" or "en", the language of the buyer's page or request, whenever Grietens knows it (it is absent when it does not: then pick your own default). Your labels, your text items and your answer's message read best in it.

Your quote function also gets a second argument with the same calls bound to its request:

quote: async (request, live) => { await live.step('Reading the drawings'); await live.show({ text: 'Span 9.2 m' }); /* … */ return answer; }

In Python, a quote function with two parameters gets it: def quote(request, live): live.step("Reading the drawings").

The wrapper: one line per step

import { createEngine, withSteps } from './grietens-engine.mjs';
const engine = createEngine({ url, keyFile, card, quote: withSteps(async (request, step, show) => {
  await step('Reading the drawings');
  await show({ text: 'Roof: gable, 30 degrees' }, { id: 'layout', picture: './layout.png' });
  await step('Placing the trusses');
  await step('Pricing');
  return { status: 'needs_review', kind: 'estimate', price: 18400, currency: 'EUR', scope: ['trusses'] };
}, { of: 3 }) });

Each await step('…') sends one update with the next step number (1 of 3, 2 of 3, …). Python: quote=with_steps(fn, of=3) where fn(request, step, show).

The raw HTTP shape (without a kit)

POST to the request's callback_url (the one in the request Grietens sent you), with a JSON body that has progress and no status:

{
  "progress": {
    "label": "Placing the trusses",
    "step": 2,
    "of": 4,
    "percent": 50,
    "eta_seconds": 90,
    "state": "working",
    "items": [
      { "text": "Roof: gable, 30 degrees, span 9.2 m" },
      { "id": "layout", "picture": "https://quotes.example.com/files/plan-2.png" },
      { "file": { "url": "https://quotes.example.com/files/offer-draft.pdf", "name": "Offer draft.pdf" } }
    ]
  }
}

Sign it with your engine's own key, like a callback, with the purpose progress. The signed text is these lines joined by a newline (\n), signed with Ed25519, the signature in base64url:

grietens-sig/3
engine-answer
progress
<your engine's address, as on your card>
<the origin of callback_url, e.g. https://app.grietens.cloud>
<the request_id>
<unix seconds, the same as X-Engine-Timestamp>
<the SHA-256 of the exact body bytes, lower-case hex>

Headers: Content-Type: application/json, X-Engine-Timestamp: <unix seconds>, X-Engine-Sig-Version: 3, X-Engine-Signature-Ed25519: <signature>. (The older version 2 text, without the first line's 3 and without the origin line, grietens-sig/2, is accepted too.) An unsigned update, or one whose signature does not verify, is ignored.

The answer: 200 {"ok": true, "applied": true, "items": <items kept>, "bytes_left": <bytes>, "text_bytes_left": <bytes>, "warnings": [...]}. After your final answer an update is answered {"applied": false, "event": "finished"} and changes nothing.

Every field

Field What it is
label One line of what you are doing now ("Reading the drawings"). Up to 300 characters.
step, of Step 2 of 4: the page draws a bar.
percent 0 to 100: the page draws a bar (without step or percent it shows a moving bar).
eta_seconds About how long is left, in seconds ("about 2 min left").
state working (the default) or waiting_for_person: a person at the factory releases the answer; the page says it waits for the factory's engineer.
items Things to add to the buyer's live feed, in order. Each is one of:
text A short note or fact (up to 4000 characters; line breaks are kept).
picture An https address on your engine's host, any path (or { "url", "name" }): a PNG, JPEG or WebP picture, shown as a thumbnail that opens large.
file An https address on your engine's host, any path (or { "url", "name" }): a PDF, or a drawing (DXF, DWG, IFC, STEP), shown as a file the buyer downloads.
id Optional, on any item: send an item with the same id again and it REPLACES that item where it is (a drawing you redraw every few seconds).

For the bar the newest wins, field by field: each of label, step, of, percent, eta_seconds and state you send replaces the one before, and one you leave out keeps its value (an update with only items leaves the bar as it is). Items are added, never removed by you.

The bounds (only safety, set generously)

Bound Value When you pass it
Updates per engine 1200 a minute (any burst within it) 429, "bound": "updates_per_minute": that update is not kept; the next minute's are.
Items in one update 100 400, "bound": "items_per_update": send them in more updates.
Items kept per request 1000 The oldest leave the buyer's view first; a warning says how many.
One picture or file 10 MB, and the kinds above (the bytes decide, not the name) That item shows as "not kept"; the rest goes on.
Pictures and files per request 100 MB in all Further pictures and files are listed as "not kept"; bytes_left says what is left.
Pictures and files per shop a day (UTC) 5 GB once a person at Grietens verified the company; 200 MB before Further pictures and files wait for the next day (the item says so).
Text of one item 4000 characters Cut, with a warning.
Text kept per request 256 KB in all (UTF-8): every text item, every picture's and file's name and address, the label and its history The oldest items leave the buyer's view first; a warning names text_bytes_per_request and says how many; text_bytes_left says what is left. Six lines of a few words use about 1 KB.

Where a picture or a file may be

Grietens fetches each picture and file once, right when the update arrives, and keeps its own copy: the buyer sees them when your engine is offline. It fetches only an address that

The bytes decide what it is, never the name: a picture must be a PNG, JPEG or WebP picture; a file may be a PDF, a picture or a drawing. Web pages, SVG, programs and archives are never kept, whatever the name says. The checker (below) fetches each of your pictures and files the same way and tells you, item by item, whether Grietens would keep it.

What the buyer sees

The factory's row on the buyer's page opens into a live panel: your label and the bar on top, a small "live" mark while updates come, then the feed: text as short lines, pictures as a grid of thumbnails that open large (left and right between them), files as chips with their name, kind and size. New items ease in; the feed scrolls inside its own box and never moves the page. When your answer arrives, the price shows, and the feed stays under it, folded, as "How this quote was made". The shop's own Quotes tab shows the same feed on the request. (See the screenshots live-row-*.png, live-viewer-*.png and live-made-*.png.)

What we recommend

When a person releases the quote

Some engines do not answer at once: the engine reads the request, and a person at the factory checks the work and releases the price hours later. Answer the call with status: "pending", and while the person checks, send live updates with state: "waiting_for_person" (the buyer's page then says it waits for the factory's engineer).

Draw the line before the release. Grietens shows the buyer whatever you send, the moment it arrives, and cannot take a shown item back (sending an item with the same id replaces it, but the buyer may have seen it). So before the person releases the answer:

The answer itself comes after the release, by callback, with its price. Nothing is sent after the answer: Grietens answers any later update with "applied": false and shows nothing of it.

A worked example on the lower layer (createProtocol), where your own storage keeps the facts and any later process may send:

// an engine whose quote a person releases, on the lower layer (createProtocol)
import { createProtocol } from './grietens-engine.mjs';
const g = createProtocol({ url, keyFile, store: nonceStore, fetch: guardedFetch });   // fetch: your own sender for every call (optional)

// 1. Grietens' call (after g.verify, purpose 'quote-request'): keep what you will need later, answer "pending" at once
async function onRequest(v) {
  const lv = v.request.language === 'lv';
  await db.save(v.requestId, { callbackUrl: v.request.callback_url, lv, roof: await readDrawings(v.request), released: false });
  return g.reply('answer', v.requestId, { contract: '1', request_id: v.requestId, status: 'pending',
    message: lv ? 'Mūsu inženieris pārbauda aprēķinu' : 'Our engineer checks the quote' });
}

// 2. at any later time, from stored facts only (another process, after a restart): what the engine understood, never a price
async function showWhatWeUnderstood(requestId) {
  const job = await db.load(requestId);
  if (!job || job.released) return null;   // nothing after the answer
  const { lv, roof } = job;
  return g.sendProgress({ requestId, callbackUrl: job.callbackUrl, progress: {
    state: 'waiting_for_person', label: lv ? 'Gaida mūsu inženieri' : 'Waiting for our engineer',
    items: [
      { id: 'roof', text: lv ? `Divslīpju jumts, laidums ${roof.span_m} m, ${roof.trusses} kopnes` : `Gable roof, span ${roof.span_m} m, ${roof.trusses} trusses` },
      { id: 'model', picture: { url: roof.pictureUrl, name: 'roof.png' } },   // on your engine's host, any path
    ] } });
}

// 3. when the person releases it: the answer by callback (signed for the request), then nothing more
async function release(requestId, answer) {
  const job = await db.load(requestId);
  const out = await g.sendCallback({ requestId, callbackUrl: job.callbackUrl, answer });
  if (out.ok) await db.save(requestId, { ...job, released: true });
  return out;
}

In Python the same calls are g.verify(...), g.reply("answer", rid, {...}), g.send_progress(rid, callback_url, {...}) and g.send_callback(rid, callback_url, answer) on a Protocol(url=..., key_file=..., transport=...). On the easy path (createEngine) the same shape is quote() answering { status: 'pending' }, engine.progress(requestId, update) at any time, and engine.complete(requestId, answer) after the release.

A shop Grietens has not checked yet

The open Grietens page asks only factories whose company Grietens checked in the company register. A shop that is not checked yet gets requests through its own link only, and its live updates show on that link only, like everything else of it.

Try it

Run the checker next to your engine: node grietens-engine-check.mjs --url http://localhost:8787/quote. It plays Grietens, sends one request, prints every live update as it arrives (live update 3: "Pricing" · step 3 of 3 · 1 text, 1 picture) and checks each is signed for the request. It fetches every picture and file an update names, as Grietens would, and prints for each whether Grietens keeps it (its kind and size) or why not and what to fix; one that would not be kept fails the check. Against a local engine (http://localhost:…) it allows your engine's own scheme and port on the same host name; Grietens itself needs https on 443. It sends the request's language (--language lv, en or none). Grietens can also run its request page locally against your engine and show you how your updates look.

The smallest useful version

quote: async (request, live) => {
  await live.step('Reading your drawings', { of: 2 });
  await live.step('Pricing');
  return answer;
}