Official
chat
Built-in chat UI (JavaScript UI plugin).
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/chat@0.2.8
Permissions in 0.2.8
Files
question-fields.ts2.3 KB
// What a question card shows and answers: each field's answer is what the
// user gave, else the field's default; a field whose `when` conditions do
// not hold is hidden and answers nothing.
import type { QuestionCondition, QuestionField } from "divergence";
export type AnswerValue = string | number | boolean | string[];
export type Answers = Record<string, unknown>;
/// The field's answer: the user's, else its default.
export function answerOf(field: QuestionField, answers: Answers): unknown {
const given = answers[field.id];
return given === undefined || given === null || given === "" ? field.default : given;
}
function holds(condition: QuestionCondition, value: unknown) {
if (value === undefined || value === null || value === "") return false;
const hit = Array.isArray(value) ? value.includes(condition.value) : value === condition.value;
return condition.op === "eq" ? hit : !hit;
}
/// The fields that show, in order. A condition on a hidden field does not
/// hold, so hiding one field hides every field that depends on it.
export function visibleFields(fields: readonly QuestionField[], answers: Answers): QuestionField[] {
const shown = new Map<string, QuestionField>();
for (const field of fields) {
const visible = (field.when ?? []).every((condition) => {
const on = shown.get(condition.field);
return on !== undefined && holds(condition, answerOf(on, answers));
});
if (visible) shown.set(field.id, field);
}
return [...shown.values()];
}
/// The answer sent for a card: every shown field that has an answer or a
/// default, and nothing for a hidden one.
export function submittedValues(fields: readonly QuestionField[], answers: Answers): Record<string, unknown> {
const values: Record<string, unknown> = {};
for (const field of visibleFields(fields, answers)) {
const value = answerOf(field, answers);
if (value !== undefined && value !== null && value !== "") values[field.id] = value;
}
return values;
}
/// The answers worth keeping across a reload: never a secret one.
export function storableAnswers(fields: readonly QuestionField[], answers: Answers): Answers {
const secret = new Set(fields.filter((field) => field.secret).map((field) => field.id));
return Object.fromEntries(Object.entries(answers).filter(([id]) => !secret.has(id)));
}Versions
| Version | Published | Plugin API | Size | Permissions | Status |
|---|---|---|---|---|---|
| 0.2.9latest | Nov 21, 2026 | >=5 <6 | 349 KB | 5 permissions | Listed |
| 0.2.8 | Nov 16, 2026 | >=5 <6 | 348.6 KB | 5 permissions | Listed |
| 0.2.7 | Nov 11, 2026 | >=5 <6 | 314.3 KB | 5 permissions | Listed |
| 0.2.6 | Nov 9, 2026 | >=5 <6 | 306.2 KB | 5 permissions | Listed |
| 0.2.5 | Oct 27, 2026 | >=2 <4 | 178.6 KB | 5 permissions | Listed |
No comments yet.