Declaring AI tasks
Tasks are declared in the template, so adding a task only requires editing the template; MN itself does not change.mnaddon.json needs no extra fields for this.
template.json
id: the identifier used to invoke the task.title: the task name shown to the user.trigger: how the task is started. Defaults to"user"."user"means the task only runs after the user triggers it."auto"allows the add-on to start the task on its own, after obtaining consent once.
scope: the scope of the material that is sent.word_sentencelets the add-on provide one word and the sentence containing it. The word is limited to 80 characters and the sentence to 600 characters.card_textmakes MN take the title and body from the card. Whatever the add-on passes is ignored.attempt_inkis for reading handwritten content on a card. Handwriting, text boxes, and formula boxes are merged into one image and sent to a handwriting recognition model. If the card has no handwritten content, the call is rejected.
prompt: the prompt text.output: a JSON Schema for the return value. Values may only be"string","number", and"bool".required: the fields inoutputthat must be present.tier: the model tier.0is the fastest,2the most capable. Defaults to0.
Running AI
Call a declared task withmn.ai(cardId, taskId, params).
params depends on scope:
- For
word_sentence, the add-on supplies the material inparamsand must providewordandsentence. - For
card_text, MN takes the material from the card;paramsis not sent and its contents are ignored. - For
attempt_ink, MN builds the image from the card, and the add-on supplies everything else inparams, such as the question and the reference answer.
index.html
- On success,
{ ok: true, text, json }.json: the object parsed according to the task’soutput.text: the raw text returned by the model.
- On failure,
{ ok: false, error }, whereerroris one of:bad_args: the material does not meet the requirements, or the task declaration is invalid.bad_output: the model returned the wrong field structure, and nothing was written to the card.task_used: MN sends each task on a given card only once; repeated requests are rejected.declined: the user chose to decline in the prompt.consent_required: an auto-started task has not obtained consent yet.max_required: the task requires a MAX subscription.no_service: no AI service is configured in the app.rate_limited: too many requests.no_ticket: the card was not assigned to this add-on’s AI.not_owner: the AI on this card was assigned to a different add-on.network: the request did not reach the service.no_ink: there is nothing usable in the answer area.
MN asks for the user’s consent before deducting quota. A second request sent while that prompt is still open is treated as a decline. Disable the button while a request is in flight to avoid double clicks.
Assigning AI to an add-on
Excerpt tools and highlight shortcuts in a template each carry anai_addon field holding an add-on id. It states that cards excerpted with that tool are handed to that add-on for processing. Highlight shortcuts are the row of quick buttons that appears on the menu bar when you select text in a document.
In Edit scene template → Card and excerpt menus, you can set AI assigned to: … when adding a highlight shortcut.
template.json
ai_addon may call AI on them. Once a card has been assigned to another add-on, this add-on’s task calls on that card are rejected with not_owner; if the tool has AI disabled, the calls fail with no_ticket.
Reading the task list from the template
The page can read the tasks declared by the current template and build buttons from them, so adding a task to the template requires no add-on change:index.html