Usage examples
Pick one complete file for your task. Prepare installation and model configuration. JSON downloads are for inspecting structure, not calling models in the browser.
Install with npm install @devcodex/intent-runtime; required dependencies are automatic. The first three examples are complete ESM files, each creating and disposing its own Intent. They call your configured real model API and require INTENT_API_KEY and INTENT_MODEL.
Model wording, IDs, and organization may vary. Verify observable behavior below. Fixed full JSON is not a promise of verbatim output. Failures print a safe IntentError summary; see Recovery.
Basic intent recognition
Save as basic-en.mjs and run node basic-en.mjs. No business Schema is needed. fields defaults to [], so no structured orderId is newly extracted.
Read effective.intents plus global/per-intent constraints. Resolve issues before assuming a specific interpretation. This example does not query an order.
Extract an order ID
Save as parse-en.mjs and run node parse-en.mjs. The Schema declares a string. After selection, use fieldResults.intentId to locate the owning inputs.
A successful selected field is present with value "000123", retaining leading zeros. If no definite value is available, inspect issues and fieldResults rather than filling a default ID. Multiple orders retain separate owners; do not put two IDs into one scalar field.
Multi-turn changes and invalidation
Save as multi-turn-en.mjs and run node multi-turn-en.mjs. The complete Schema allows a discount up to 20 for VIP and 10 for non-VIP. Each continuation supplies baseline; turn three also carries relevant issues.
If the model fails to link goals correctly, inspect issues and sources rather than assuming three arbitrary first nodes are the same order. Unknown VIP does not default to false: discount 6 is legal in either branch, while 18 depends on VIP and remains unknown. See Fields.
More scenarios
The following explain behavior or provide configuration fragments; they are not standalone programs.
Complete structural examples
The response catalog includes full config/request/result, with baseline/context when needed.
Fixed language candidates go through the actual core, with real Validator checks for business fields. No-Schema scenarios do not artificially add one. Technical failures are tested at their own stage. Run the complete API programs with your actual model configuration to assess language understanding.
Requirement changes and clarification
“User module with sign-in and registration; do not modify the database; deliver instructions” → “withdraw registration and change instructions to English” retains surviving identity, parent constraints, and deliverables. “Use the second method” needs its candidates. “Email verification; do not modify code yet” resolves only the relevant ambiguity. See Multi-turn material.
Terms and actions
Pass semantics to new Intent. An explicit match can retain ORDER_HOLD regardless of language. Definitions describe meaning; they do not assert that your application has a tool to execute it.
Extensions and output switches
Explicit semantic labels go into the owning intent's extensions; business parameters remain in inputs. Do not invent a goal solely to hold extension labels. output overrides defaults per key. Disabling evidence retains necessary issue/inference sources. suggestions remains independent advice rather than a new formal goal. Enabling extensions without extensionSchema produces SCHEMA_NOT_CONFIGURED.
Conditions, logic, and scope
“Publish only when review passes AND the owner confirms, OR staging passes” retains the AND/OR grouping. “Do not publish without approval” retains negation without querying actual approval. global constraints apply to the relevant tree; intent constraints apply to the goal and explicit descendants; phase means a user-expressed phase; target uses stable referenceId in that goal's references. Automatically derived implementation steps are not user phases.
before means from precedes to; depends_on means from depends on to; parallel/exclusive are symmetric. Independence does not imply parallelism or remove explicit order. Opposite ordering requirements may produce normal partial/RELATION_CONFLICT; do not erase one to claim success.
Quotes, repetition, and corrections
Time and descriptive rules
Normalize “tomorrow” reliably only with referenceTime. Without a reference, preserve relative time and uncertainty rather than inserting the local date. Retain offsets, units, totals, and per-item quantities.
A field description such as “end time must be after start time” is interpreted by the same model call, followed by format/declarative validation. A known wrong ordering is not a definite usable value. Missing dependencies remain unknown without external lookup. Passing a type check does not establish satisfaction of natural-language constraints.