Quickstart: coding agents
claude mcp add formancy -- npx -y @formancy/mcpThat is the whole installation. Seven tools appear in the agent, and four of them work immediately with no server, no API key and no account — so you can have an agent write and check a complete form before deciding whether to run anything.
Why this is not just the API with a prompt in front of it
Section titled “Why this is not just the API with a prompt in front of it”An agent writing a form is writing logic, and logic is where a model is least reliable and, more importantly, least correctable. A wrong expression does not throw. It shows the wrong field to the wrong person, or quietly computes nothing into a box somebody needed a number in, and it does that until a human notices months later.
formancy can catch that before the form exists, because the document format has a published JSON Schema and the expression language type-checks. So the tools check first and act second.
Ask an agent for a total that is four times the number of seats and it will
reach for seats * 4. Here is what it is told:
The document is structurally valid, but 1 expression(s) will never do anything.These compile and then fail at evaluation, so nothing would report them atruntime: a computed field would stay empty and a visible rule would show thefield it was meant to hide.
monthly (computed): no such overload: double * int. This evaluates to nothing for every value anybody enters, so the rule never does anything. A number field holds a double and CEL will not widen a whole number to meet it, so write the literals with a decimal point — 4 becomes 4.0.The agent fixes it in the next turn. Without this it would publish a form that looks right and computes nothing.
The same goes for the mistakes the engine refuses outright — a misspelled field
name, a cycle between two computed fields, or a checkbox written as a condition
on its own. validate_form builds the same engine the server’s publish gate and
every renderer build, so it does not call a form valid whose logic the server
would then refuse, and it says what to write instead:
Rule on "phone" (visible): A visible expression must produce bool, but this oneproduces dyn. A checkbox nobody has touched is null rather than false, so itcannot be a condition on its own: write callback == true.The tools
Section titled “The tools”| Tool | Needs a server | What it is for |
|---|---|---|
describe_spec |
no | Every field type, layout kind, rule kind and format. Call it before writing anything. |
validate_form |
no | The server’s publish checks, without publishing: schema, the engine’s compile, expressions that never evaluate. |
diff_forms |
no | What a change would do to submissions already collected: compatible, lossy or breaking. |
check_scenarios |
no | Run a form against examples with their answers written down, and report which stopped holding. The only check that catches a condition written backwards. |
propose_form_edit |
yes | Hold an edit up against the published form without publishing it: what it would cost submissions already collected, plus the basedOn hash to publish with. |
publish_form |
yes | Publish — after validating locally and refusing to send a document that would not work. Takes basedOn, and refuses when the form has changed since. |
list_forms |
yes | The forms on the server, with their current version. |
get_form |
yes | One document, with its version and schema hash. |
list_submissions |
yes | Submissions for one form. |
describe_spec earns its place
Section titled “describe_spec earns its place”Asked for an email field, a model writes type: "email" — because that is what
every other form builder calls it. formancy has no such type; an email field is
text with format: "email". Told the list up front, the agent gets it right
the first time instead of spending a turn discovering it.
The same tool carries the handful of things about this format that are
counter-intuitive enough to catch people out: that a version 1 document may not
contain a version 2 construct, that an empty list answer is [] and never
null, that a JSON number is a double, and that a field key is identity rather
than a label.
diff_forms answers the question that cannot be un-answered
Section titled “diff_forms answers the question that cannot be un-answered”Publishing over an existing form is the one edit with permanent consequences.
diff_forms grades it against the data already collected, so “will this break
anything?” is a tool call rather than a judgement:
- compatible — existing drafts and submissions rebind silently.
- lossy — they rebind, but some answers no longer have a field to live in.
They are kept under
data.__orphaned, never deleted. - breaking — existing drafts cannot rebind and open read-only against the version that produced them.
check_scenarios catches the rule written backwards
Section titled “check_scenarios catches the rule written backwards”validate_form says a document works. It cannot say the condition is the opposite of
the one you were asked for, because
visible: leaveType == 'other'visible: leaveType != 'other'are both valid CEL. Both compile, both type-check, both satisfy the schema and the engine. One of them asks a question nobody should be asked, and the difference is not in the document — it is between the document and what somebody meant.
An example with its answer written down is the only thing that can see it:
{ "name": "other shows the reason", "changes": { "leaveType": "other" }, "valid": true, "visible": { "reason": true }}A scenario can pin whether the form validates, which error codes each field carries, which fields are visible, what each holds, and which paths the submission does not carry — the last one because validity alone cannot tell a cleared branch from one that was never filled. Write one for every rule you add. The tool refuses an empty set rather than reporting that all nought scenarios hold.
Every key names one answer, by its path. A field inside a group is named through the
group, home.street; a page is left out, since it scopes nothing; and a field in a
repeater’s row is named by the row’s position from 0, colleagues[0].fee. That is also how a
list is filled: one answer at a time, and naming a row the list does not have yet adds it. For
a form whose count is worked out as size(colleagues),
{ "name": "two colleagues are both counted", "changes": { "colleagues[0].who": "Ada", "colleagues[0].fee": 100, "colleagues[1].who": "Grace", "colleagues[1].fee": 120 }, "valid": true, "values": { "count": 2 }}starts from an empty list and ends with two rows. A scenario does not set a list whole, and
cannot remove a row the answers it starts from already have. A list, a group, one row or a
page named as though it were one answer is a failure that says which it is and offers a path
to name instead, and so is colleagues[].fee, the spelling a rule uses for every row. A
field in a row the list does not have is neither visible nor hidden, and an example that says
it is one or the other fails
(0182).
What the engine says at a list itself is the exception: errors and visible may name it,
"errors": { "colleagues": ["maxItems"] } for a fourth colleague on a list of three, because a
list’s bounds and the rules aimed at it are reported at the list, and a rule hides it whole
(0184).
A deployment can keep them, and its publish runs them. The server keeps each form’s
examples and the sample they start from beside the form — GET and PUT /f/:path/examples,
with the permission publishing takes — and every publish runs them against the version the
form has and the new one. Each example that stops holding is a sentence in the 201’s
warnings, and the form is published all the same
(0166).
publish_form hands back the server’s answer as its data, so the warnings are there — beside a
summary that says only Done., so read the data. There is no tool to read or keep a form’s
examples; check_scenarios still runs the ones you pass it, before anything is published.
Changing a form that exists is a two-step tool call
Section titled “Changing a form that exists is a two-step tool call”validate_form says a document works. It does not say that your rewrite
dropped an option somebody has already chosen, and an agent reading only its
own two documents cannot tell either — it has not seen what is published.
So propose_form_edit fetches the live form, diffs against it and answers with
the change list and a basedOn hash. Put the change list in front of the
person; publish with the hash when they agree.
The hash is not ceremony. A formancy document is the whole form, so
publishing an edit based on an older version silently reverts whatever somebody
published in between — and the publish succeeds, so nothing reports it.
publish_form with basedOn refuses that; without it, the older behaviour is
still there, because a form being created for the first time has nothing to be
based on. The two builders hold the same rule against a session rather than a
server (0109).
What a tool says about itself
Section titled “What a tool says about itself”Every tool carries annotations, which is the only thing a client has to decide
whether a call needs your agreement before it happens. The five that need no server
— describe_spec, validate_form, diff_forms, check_scenarios and the checking
half of publishing — declare themselves read-only and closed-world, so a host can run
them freely. publish_form declares that it writes, that it is not destructive
(a published version is immutable, so a publish adds rather than overwrites) and that
it is not idempotent (publishing twice makes two versions).
Each answers with a structured result beside the prose — the same envelope every time: whether it worked, a sentence to read, and the part to act on. Refusals too, which is the answer you most need to act on.
Three prompts, for the three things you ask
Section titled “Three prompts, for the three things you ask”build_a_form, change_a_form and embed_a_form. They ship with the server, so
they arrive with the connection rather than being documentation somebody has to find
and paste, and they give the order rather than the tool names:
- Building calls
describe_specfirst. A model that writes the document first has already inventedtype: "email", and the correction costs a turn. Scenarios come last and are written from the description rather than from the rules just written — otherwise they agree with whatever the rules happen to say. - Changing goes
get_form→ edit →propose_form_edit→ show the person →publish_formwith the hash. Never straight to publish. - Embedding answers for one framework, not both.
Connecting it to a server
Section titled “Connecting it to a server”FORMANCY_URL=http://localhost:4380 \FORMANCY_API_KEY=fk_… \ npx -y @formancy/mcpSet both or neither. Half-configured is refused at startup: a URL with no key returns 401 on every call and a key with no URL does nothing, and both look like a broken tool rather than an unconfigured one.
See self-hosting for how to mint an API key.
Other clients
Section titled “Other clients”Anything that speaks the Model Context Protocol. The server runs over stdio, so the client launches the process and talks down its pipes — nothing listens on a port:
{ "mcpServers": { "formancy": { "command": "npx", "args": ["-y", "@formancy/mcp"], "env": { "FORMANCY_URL": "http://localhost:4380", "FORMANCY_API_KEY": "fk_…" } } }}In the builder, for people who are not using an agent
Section titled “In the builder, for people who are not using an agent”The same loop is available with a person in front of it. PromptPane from
@formancy/builder-react — and FormancyPromptPane from
@formancy/builder-angular — takes an instruction, and the answer is parsed,
validated, compiled by the engine and type-checked before anything reaches the
editor. If it fails, the model is told what was wrong and asked again.
And then it is shown rather than applied. Valid is not the same as wanted:
a document passes every one of those checks with the condition inverted that
you asked to loosen. The pane lists what the answer would change — the same
list diff_forms gives, marking what costs answers already collected — and
applies nothing until you press the button. A proposal written against a form
that has since changed is refused rather than applied over the change, because
a document is the whole form.
The model is yours. ask is a prop, the way an uploader is a provider: no
vendor, no key and no network call inside any formancy package, so you can
point it at something on your own hardware and nothing about a form’s contents
leaves your network.
<PromptPane session={session} ask={askModel} />Without the prop the pane renders nothing, rather than a button that cannot work.
Give it the form’s examples, and it runs them before you decide. A rule turned
the wrong way round passes every check above, and the change list says only that
the rule changed. An example with its answer written down tells the two apart. Pass
the pane the examples your ScenarioPane runs, with the same scenarios,
initialValue and mode:
<PromptPane session={session} ask={askModel} scenarios={scenarios} initialValue={sample} />The pane then runs them against the form as it is and as the answer would leave it.
The review’s heading names each example that would stop holding, and the status
names those and any that would hold again. Apply stays enabled: a rule you asked to
change stops its old example holding, and the decision is yours. A rule no example
pins gets no warning. Without scenarios, the review says nothing about examples
(0159).
Give the scenario pane the same model, and it drafts examples where a form has none.
The person says what the form should do; the model is asked for examples of it and shown the
form’s fields, the engine’s error codes and those words, and never a rule, a pattern, a bound
or which fields are required. A model shown the rule writes the example the rule passes,
which agrees with the rule whether it is right or wrong. draftScenarios(ask, document, intent, { initialValue, existing, stop }) is the run on its own: it reads each item of the
answer by itself, lists the ones that are not examples with why, and asks again only when
none is. draftVerdict runs a draft as the scenario pane runs its list, and keepDraft
refuses a name already taken and a field the form does not have, and keeps a draft that
fails — whether the example or the rule is wrong is the person’s call
(0162).
Writing askModel
Section titled “Writing askModel”An AskModel is one turn: a prompt in, the model’s text out. Point it at an
endpoint on your own server, and keep the model’s key there. A key in the
browser is a key anybody who opens the page can read.
import type { AskModel } from '@formancy/builder-core'
export const askModel: AskModel = async ({ system, user }, turn) => { // The person can stop the run while this waits. Abort the request when they // do, so your server stops too rather than paying for an answer nobody reads. const controller = new AbortController() turn.onCancel(() => controller.abort())
const response = await fetch('/api/form-model', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ system, user }), signal: controller.signal, }) if (!response.ok) throw new Error(`The model service answered ${response.status}.`) const { text } = (await response.json()) as { text: string } return text}/api/form-model is yours to write: it adds the key, calls whichever model you
use with system as the system prompt and user as the message, and answers
with the text. Abort that call when the browser’s request closes, and a stop in
the browser ends the call to the model as well. If you run formancy’s own server, it is
already written — see through formancy’s server.
While a run waits, the pane shows Stop. Pressing it — or taking the pane off
the screen, when the pane holds its own run — ends the run at once, calls what you
gave turn.onCancel, and discards whatever the model answers afterwards. To keep a
run going while the pane is away, hold it yourself; see below. A function written without the
second argument is stopped all the same: the pane stops waiting for it, though
its request runs on. A function that wraps another AskModel hands turn on
with the prompt; the types require it, so a wrapper cannot drop the stop.
When your function throws or rejects, the pane says the model could not be
reached, followed by your error’s message, rather than that the document did not
work. Write the message for the person reading it. Something thrown without one —
undefined, an event, an empty string — is said without a reason.
When the format cannot do what was asked, the model may say so. “Email me every
submission” is one such request: a form document says what a form asks and checks,
not where an answer goes. The briefing tells the model not to write a document that
does part of the request, and to answer {"declined": "<why>"} instead. The run
ends on that answer rather than asking again. A decline with no reason in it does not
end the run: the next turn asks the model for one. The pane says the model declined, and
shows its reason, as text, where the problems would be. Nothing is applied. The
reason is the model’s own claim, and nothing checks it: if it declined something a
form can do, reword the instruction and ask again.
If your model service refuses a request itself, in its response rather than in its text, return a decline for it, with a sentence for the person reading it:
import { declinedAnswer } from '@formancy/builder-core'
// Inside your AskModel, where the service's answer is read:if (refused) return declinedAnswer('The model service would not answer this request.')The run then ends the same way, rather than reporting a model that could not be reached. A blank reason throws, because it would not read as a decline.
Each turn also says which it is: attempt and limit, and from the second turn
followUp, which is the complaint alone. user always carries the whole
instruction with the latest complaint, so a function that keeps no conversation
sends user every time. One that keeps a conversation, whose history already
holds the model’s last answer, can send followUp instead.
And each says which request it is: kind is authoring for a form written or changed,
translation for a language’s missing messages, and scenarios for drafted examples — the
three in MODEL_REQUEST_KINDS. The run that builds the prompt sets it, and the relay pane
below says what leaves by it. It is required, as attempt and limit are, so a prompt you
build by hand — calling your own function in a test, say — has to name one; a function that
only receives prompts is unaffected.
Called directly, authorForm(askModel, instruction, { current, stop }) resolves
however the run ends. A working document is ok: true. Otherwise ended says why
there is none: gave-up, stopped, unreachable with your error’s message as
reason, absent when it had none, busy, or declined with the model’s reason as
reason. stop comes from createStop(); calling its stop() is the button.
busy is for a model that takes one request at a time. Reject with ModelBusyError
from @formancy/builder-core while yours is answering another, and the run ends at once,
with no reason, and the pane says another request is waiting for the model — in the
person’s language, rather than your error’s message under “could not be reached”. The
relay below does exactly that.
Through formancy’s server: the deployment path
Section titled “Through formancy’s server: the deployment path”If you run formancy’s server, it can hold the model and its key for you. Name the provider —
anthropic for Claude, openai, or xai for Grok — its key and the model, and the server
asks it (self-hosting). The admin then
draws the prompt pane and gives its Translations tab the same ask. A builder page of your own
asks the same route:
import { declinedAnswer, modelRequestKind } from '@formancy/builder-core'import type { AskModel } from '@formancy/builder-core'
/** A session from POST /auth/login, for somebody who may edit forms. */declare const session: string
export const askModel: AskModel = async ({ system, user }, turn) => { // The server writes the briefing itself, so say only which request this is. const kind = modelRequestKind(system) if (kind === undefined) throw new Error('This is not a request formancy makes.')
const controller = new AbortController() turn.onCancel(() => controller.abort()) const response = await fetch('/api/model/complete', { method: 'POST', headers: { 'content-type': 'application/json', authorization: `Bearer ${session}` }, body: JSON.stringify({ kind, user }), signal: controller.signal, }) const body = (await response.json()) as { text?: string; declined?: string; message?: string } if (response.ok && body.declined !== undefined) return declinedAnswer(body.declined) if (response.ok && body.text !== undefined) return body.text throw new Error(body.message ?? `The server answered ${response.status}.`)}The route answers the three requests the builders make — writing a form, translating it,
drafting its examples — each under the briefing the server writes for it, and never under a
system part from the request, and a briefing your page wrote itself is refused before it
leaves. That narrows what the key can be spent on; it does not close it. The user part is the
person’s text, so somebody with a session can still ask the model for something else under
formancy’s briefing and read the answer — bounded by the permission, the limit, the body cap
and the audit row, not prevented. modelRequestKind finds the request from the briefing the
run handed your function, so one function serves the prompt pane, the translations pane and
the scenario pane. It needs
a session that may edit forms and allows ten requests a minute per session. A refusal by the
provider comes back as declined, which ends the run on that turn as the model’s own decline
would. When the request goes away — the person pressed Stop — the server abandons the call to
the provider.
The form leaves, from the server. Each request carries what its kind carries to the provider the operator chose: writing or changing a form, the whole document; translating, the messages a language is missing, where each is used and the translations it has; drafting examples, the form’s title, fields, labels and options, the codes it can report, the starting answers, the names of its examples and what the author said — neither of the last two carries the rules. The admin says which provider and model before anybody asks. A page that may not call a model at all, formancy.ai’s among them, uses the relay below instead: no server, and a person carries each turn.
No model on the page: a relay
Section titled “No model on the page: a relay”Some pages may not call a model at all — formancy.ai’s own playground asks no other site
for anything. For those, @formancy/builder-core has a relay: an AskModel whose
turn a person carries. The page shows the exact request, the person copies it into a chat
of their own, and pastes the answer back. Every check after the paste runs in the page, and
the answer is held for review like any model’s.
import { useState } from 'react'import { createRelay } from '@formancy/builder-core'import type { BuilderSession } from '@formancy/builder-core'import { PromptPane, RelayPane } from '@formancy/builder-react'
const CHAT = { name: 'Your chat', href: 'https://chat.example/' }
export function Describe({ session }: { session: BuilderSession }) { // One relay for the pane's life, so the turn it is waiting on is not lost on a render. const [relay] = useState(() => createRelay()) return ( <> <RelayPane session={session} relay={relay} chat={CHAT} /> <PromptPane session={session} ask={relay.ask} /> </> )}In Angular it is <formancy-relay-pane [session]="session" [relay]="relay" [chat]="chat" />
beside <formancy-prompt-pane [session]="session" [ask]="relay.ask" />.
The relay pane draws nothing until a turn waits. Then it shows the briefing, folded away, and the request in a box that cannot be edited, with Copy. On a retry, Copy writes only what was wrong, for the chat that already holds the last answer, and a second button copies the whole request for a new one. If the browser will not let the page write the clipboard, the text is selected in the box instead, and the pane says so.
Each turn that arrives while it is drawn takes the focus to Copy, whose description is the turn and what to do with it. The page is waiting on the person from that moment, and the prompt pane says only that the form is being written; an answer that failed takes the pane, and the focus in it, away before the retry draws it again. A turn already waiting when the pane is drawn — with a run you hold, as below, the pane drawn again after the person changed a view or a builder — leaves the focus where it is: they were using another control, and nothing new is waiting on them. Each turn also starts with an empty answer box, so nothing pasted for one is offered to the next.
chat is yours to name, and optional. With it, the pane links to that chat in a new tab;
without it, there is no link and the request is copied all the same. Neither builder names
a service. The request is never put in a URL.
What the relay decides, it decides once, for both builders:
- One turn at a time. A second request while one waits is refused with
ModelBusyError, and that run endsbusy: its pane says another request is waiting for the model’s answer. Give each pane its own relay if two must be able to run at once. - A paste with no JSON object in it is held back and costs no attempt. The pane says so and offers Use it anyway, which sends it as it is. A decline is an answer.
- A stop clears the turn. An answer pasted after it is refused, never kept for the next request.
The same relay can be the scenario pane’s ask, for drafting examples, and the
translations pane’s, for a language’s missing messages, as the playground’s is. One turn at
a time holds across all of them, whichever asks first: a draft asked for while a model’s edit
waits is refused, and so is an edit asked for while a draft or a translation waits. Each
ends busy, and its pane says so. No pane knows its ask is a relay, so the button that
will be refused stays enabled while the other turn waits.
What leaves, and who carries it. The relay and its pane send the request nowhere: what
the person copies goes on the clipboard, and pasting it into a chat gives it to that service
under their own account. What the request carries depends on its kind. A form’s edit carries
the briefing, the instruction and the whole form, its rules included. A translation carries
the messages the language is missing, where the form uses each and the translations it
already has, but not its rules. A request for examples carries the form’s title, its fields,
labels and options, the codes it can report, the sample examples start from, the names of
those already kept and what the author said, but not its rules. The pane says which, for the
turn it shows — relayLeaves(turn.prompt.kind, text) is the sentence, in the person’s
language — and says it of itself: what the rest of your page sends is yours, and the pane
cannot know it. A pasted answer is not tied to the request it answers: the review’s list
of changes, against the form the run was asked about, is what shows an answer to something
else.
A relay is for a page that cannot call a model. Where yours can, write an askModel that
calls your own server, as above: it takes no copying, and the request goes where you
decide.
Keeping a turn when the pane goes
Section titled “Keeping a turn when the pane goes”By default the prompt pane’s run is the pane’s: take the pane off the screen and the run stops. Through a relay that loses the turn whenever the person looks at anything else while their chat answers — another tab, another view — and the answer they paste back finds nothing waiting. If your page draws the prompt pane under a tab, hold the run where the relay is, and give it to the pane:
import { useState } from 'react'import { createPromptRun, createRelay } from '@formancy/builder-core'import type { BuilderSession } from '@formancy/builder-core'import { PromptPane, RelayPane } from '@formancy/builder-react'
export function Builder({ session, tab }: { session: BuilderSession; tab: 'fields' | 'other' }) { // Above the tabs, so both live as long as the page rather than the Fields tab. const [relay] = useState(() => createRelay()) const [run] = useState(() => createPromptRun()) return ( <> <RelayPane session={session} relay={relay} /> {tab === 'fields' ? <PromptPane session={session} ask={relay.ask} run={run} /> : null} </> )}In Angular, <formancy-prompt-pane [session]="session" [ask]="relay.ask" [run]="run" />.
A pane given run draws it and leaves it running when it goes. The pane drawn next shows
the run as it is: still waiting, with Stop, or with its answer held for review. Once a run
has answered, the instruction box is the person’s again, so the review names the words the
run was asked with — In answer to “…” — whatever the box says by then. Two panes given
one run, one in each builder say, show one instruction, one Stop and one proposal, so a
proposal reviewed in one can be applied in the other. The run belongs to the form it was asked about. When you open another form, call
run.discard(), which stops a run still waiting and forgets what it came to. A proposal
held while the form changed is refused at Apply, as always.
Holding the run makes ending it your job. Nothing stops it because a pane went, so with your
own model behind ask the request keeps running until it answers, Stop is pressed, or you
call run.stop() or run.discard(). Leave run out, and the pane stops its own run when
it goes, as before
(0163).
The translations pane and the scenario pane’s drafting take a held run the same way, each held for what it is about (0164):
import { useState } from 'react'import { createDraftRun, createRelay, createTranslationRun } from '@formancy/builder-core'import type { BuilderSession } from '@formancy/builder-core'import type { Scenario } from '@formancy/core/authoring'import { RelayPane, ScenarioPane, TranslationsPane } from '@formancy/builder-react'
export function Tabs({ session, tab }: { session: BuilderSession; tab: 'fields' | 'translations' }) { const [relay] = useState(() => createRelay()) const [translation] = useState(() => createTranslationRun()) const [drafting] = useState(() => createDraftRun()) const [scenarios, setScenarios] = useState<readonly Scenario[]>([]) return ( <> <RelayPane session={session} relay={relay} /> {tab === 'translations' ? ( <TranslationsPane session={session} ask={relay.ask} run={translation} /> ) : ( <ScenarioPane session={session} scenarios={scenarios} onChange={setScenarios} ask={relay.ask} drafting={drafting} /> )} </> )}In Angular, [run]="translation" on <formancy-translations-pane> and
[drafting]="drafting" on <formancy-scenario-pane>.
- A translation is held for its language. The run keeps the language it was asked for,
with its proposal and what Translate the rest builds on. A translations pane given it opens
on that language, waiting or with its review. Under any other language — the default too — the
pane says where the run is and draws nothing of it: no review, no Stop, no Ask, so a French
proposal is never reviewed or applied as German. Once the run’s language has left the form —
the person undid adding it — no pane can be drawn under it, so every language says so and
offers the run’s Stop, or its Discard once it has answered.
translationOn(run.state(), locale, session.document())is that decision, if you draw your own. - Drafts are held for their form, by its id. A scenario pane over any session of the same
form — a new one, opened over the same document — shows the drafts, judged against the form
as it is now. Over a form with another id it shows none of them, and Keep is refused there.
draftsOn(run.state(), session)is that decision. The words typed into the box are the run’s, so two panes over one run share them.
Call discard() on each when you open another form. Given no run or drafting, each part
holds its own as before: the translation’s ends when the part goes or another language is
chosen, and the drafting’s when the part goes or is handed another session.
Asking a model for a language’s missing messages
Section titled “Asking a model for a language’s missing messages”The translations pane takes the same ask. Given one, a language other than the default
offers to ask a model for every message that language is missing, and holds the answer for
review message by message before it lands:
<TranslationsPane session={session} ask={askModel} />In Angular it is <formancy-translations-pane [session]="session" [ask]="askModel" />. A
relay’s ask works too, and the turn is drawn by the relay pane as the prompt pane’s is.
Without ask the pane is the translator’s table it always was.
What is sent. The request is built from the form alone, by translationPrompt(form, locale): every message the form refers to with no target in that language — never one
nothing refers to any more — each with its source and where it is used, and the
translations the language already has, for the register. The form’s rules are not sent,
and neither is the document. The model answers with the catalogue file the pane already
downloads and uploads: locale, defaultLocale, and messages with id, source and
target.
What is checked. An answer that is not JSON, not a catalogue file, or a catalogue for
another language is asked for again, with that problem alone. A decline ends the run, as for
a form, and so does a model answering another request, which ends it busy. Anything else
is kept: an id it was not asked for is dropped and listed, and a message it left empty — or
wrote as nothing but spaces — is listed as still missing, with Translate the rest to ask
for those.
What lands. The answer goes through the catalogue import into a copy of the form, so the
import’s rules apply: an empty target erases nothing, and a translation made from a source
that has changed since the model was asked is marked. That is judged by the source the
request sent, not the one the model wrote back, which it may have translated or left out. A
translation equal to its source is marked as well, and kept. Only messages still missing
when the answer arrives are written, so a translation a person made is never replaced. The
review shows each message’s source, what was there, what is proposed and its marks, and the
form as it would read in that language. Apply is applyProposal: refused if the form has
changed since, one undo step otherwise. An answer that writes nothing is not held for
review: the pane says whether the model left everything empty or a person translated what it
wrote first, lists what was dropped, and offers to ask again.
Called directly, translateCatalogue(askModel, form, locale, { stop }) resolves however the
run ends, as authorForm does, and proposeTranslation(session, result.answer) holds a
successful answer as a proposal: an EditProposal with rows, dropped and
stillMissing. translationToReview(proposal) returns it only when it writes something.
The review is only as good as its reader’s command of that language. A fluent translation that asks a different question passes every check here, and once applied a model’s message cannot be told from a person’s: where each message came from is not recorded (0161).