import { NdiClient, UnknownAnswer } from "ndi-sdk";
const client = new NdiClient();
const result = await client.systemone.evaluate({
state: { vendor: "Acme Freight", amount: 1200, purchase_order: "PO-4411" },
questions: {
approve: {
type: "noul",
criteria: { true: "The invoice matches an open purchase order", false: "No purchase order covers it" },
},
risk: {
type: "choice",
instructions: "How risky is paying this invoice?",
criteria: { low: null, high: "Unusual vendor, amount, or terms" },
},
urgency: { type: "score", criteria: ["not urgent", "this week", "today"] },
},
});
for (const [name, answer] of Object.entries(result.answers)) {
if (answer instanceof UnknownAnswer) {
console.log(name, answer.type, answer.data);
} else if (answer.type === "noul") {
console.log(name, answer.noul);
} else if (answer.type === "choice") {
console.log(name, answer.choice, answer.probabilities);
} else {
console.log(name, answer.legend[Math.round(answer.score)], answer.probabilities);
}
}