@dxv-systems/mail-graph 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/app-integration.md +62 -22
- package/package.json +1 -1
package/docs/app-integration.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Microsoft 365 helpdesk: app integration recipe
|
|
2
2
|
|
|
3
|
-
For a coding agent adding the Microsoft 365 helpdesk to an app built on `company-app-template`. Apply it exactly. All logic lives in `@dxv-systems/mail-graph` (Graph client, guided setup) and `@dxv-systems/helpdesk` (tickets, drafting, sending, staff inbox); the app adds a thin, fixed layer: tables, adapters, two catch-all routes, three pages,
|
|
3
|
+
For a coding agent adding the Microsoft 365 helpdesk to an app built on `company-app-template`. Apply it exactly. All logic lives in `@dxv-systems/mail-graph` (Graph client, guided setup) and `@dxv-systems/helpdesk` (tickets, drafting, sending, staff inbox); the app adds a thin, fixed layer: tables, adapters, two catch-all routes, three pages, the crons. Read the package READMEs ("Guided Microsoft 365 setup", "Pilot controls", "Inbox UI") once; this recipe does not repeat them.
|
|
4
4
|
|
|
5
5
|
This recipe ships inside the package: after step 1 it is at `node_modules/@dxv-systems/mail-graph/docs/app-integration.md` (from 0.1.2 on), so an agent working in the app's repository can read it without access to dxv-packages.
|
|
6
6
|
|
|
@@ -11,20 +11,20 @@ The code below was compiled, linted, knip-checked, built and tested against a fr
|
|
|
11
11
|
- **Production only.** Microsoft 365 is off unless `VERCEL_ENV=production` and `M365_CLIENT_ID` and `APP_URL` are set (`readM365Env()`). While off, every page renders a "not enabled" card and the routes answer `503 not_configured`; nothing crashes and no Graph call is made. Previews and staging never reach a client tenant.
|
|
12
12
|
- **Admin only for setup:** permission `m365:manage` (admins). **Staff only for the inbox:** permission `helpdesk:use` (managers and admins). Code checks permissions, never roles.
|
|
13
13
|
- **The helpdesk runs only while the connection is `connected`** (`getHelpdeskDeps()` returns null otherwise). The scope is exactly the connected mailboxes.
|
|
14
|
-
- **One way of working:** a person approves each reply in the helpdesk, and the helpdesk then sends it from the mailbox (`writeMode: "approve_and_send"`). Nothing reaches Outlook before that approval. The
|
|
14
|
+
- **One way of working:** a person approves each reply in the helpdesk, and the helpdesk then sends it from the mailbox (`writeMode: "approve_and_send"`). Nothing reaches Outlook before that approval. The switches are `paused` (kill switch, default off) and `draft_mode` (when the AI writes a reply proposal: `on_request`, the default, or `auto`) in `helpdesk_settings`, edited on the admin page; they apply on the next call, no redeploy.
|
|
15
15
|
- Never call Graph or the helpdesk functions anywhere else than the files below. UI never imports `@/lib/db` (ESLint).
|
|
16
16
|
|
|
17
17
|
## 1. Install
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
npm install --save-exact @dxv-systems/mail-graph@0.7.
|
|
20
|
+
npm install --save-exact @dxv-systems/mail-graph@0.7.1 @dxv-systems/helpdesk@0.17.0 @vercel/oidc@4.0.1
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
Use the published versions (exact, never a range; upgrading is a deliberate change). **Vendored variant** (before publication, e.g. the rehearsal): `npm pack` each package into `vendor/` and install `file:vendor/dxv-systems-mail-graph-<version>.tgz file:vendor/dxv-systems-helpdesk-<version>.tgz` instead; commit the tarballs with `package.json` and the lockfile.
|
|
24
24
|
|
|
25
25
|
`@vercel/oidc` is already in the lockfile through `@dxv-systems/ai`; pin the same version so it is not duplicated.
|
|
26
26
|
|
|
27
|
-
The FAQ distiller in `deps.ts`
|
|
27
|
+
The FAQ distiller and the drafter in `deps.ts` start runs by gateway feature, which needs `@dxv-systems/ai` 0.3 or later. The company app template still ships `^0.2`, so raise it: `npm install @dxv-systems/ai@^0.3.2`. Its 0.3.0 dropped the agent UUID from `createRuns().fireRun`; an app that calls it elsewhere passes the feature to `createRuns` instead.
|
|
28
28
|
|
|
29
29
|
## 2. Environment
|
|
30
30
|
|
|
@@ -79,6 +79,7 @@ Extend the `drizzle-orm/pg-core` import with `boolean, doublePrecision, primaryK
|
|
|
79
79
|
import type { M365Connection } from "@dxv-systems/mail-graph/setup";
|
|
80
80
|
import type {
|
|
81
81
|
DistillState,
|
|
82
|
+
DraftMode,
|
|
82
83
|
DraftRunStatus,
|
|
83
84
|
HistoryState,
|
|
84
85
|
LastVerb,
|
|
@@ -115,6 +116,8 @@ export const helpdeskSettings = pgTable(
|
|
|
115
116
|
id: integer("id").primaryKey().default(1),
|
|
116
117
|
/** Kill switch: no sync, drafting, sending or Graph call at all. */
|
|
117
118
|
paused: boolean("paused").notNull().default(false),
|
|
119
|
+
/** When the AI writes a reply proposal: only when staff ask (`on_request`) or for every new mail (`auto`). */
|
|
120
|
+
draftMode: varchar("draft_mode", { length: 20 }).$type<DraftMode>().notNull().default("on_request"),
|
|
118
121
|
/** Lease of the sync cron: a run starts only when this is null or past. */
|
|
119
122
|
syncLeaseUntil: timestamp("sync_lease_until", { withTimezone: true }),
|
|
120
123
|
/** Lease of the history cron, apart from the sync's, so neither waits for the other. */
|
|
@@ -305,7 +308,7 @@ export const helpdeskReplyAttachments = pgTable(
|
|
|
305
308
|
);
|
|
306
309
|
```
|
|
307
310
|
|
|
308
|
-
Every column maps one field of the package types (`M365Connection`, `SyncState`, `Thread` incl. `dismissedBy`, `StoredMessage`, `DraftRun`, `SendIntent`, `ReplyAttachment`); `assignee_id`, `assignment_note` and `assigned_by` are the inbox's assignment, `seq` orders draft runs, `sync_lease_until` guards cron overlap. Then run `npm run db:generate`, review the SQL (ten `CREATE TABLE`s, foreign keys, nine indexes, no `DROP`) and commit it with its snapshot and journal entry. An app on helpdesk 0.2 upgrades with one generated migration: `direction` on `helpdesk_messages` (default `inbound`) and `sent_link`, `sent_last_received_at` on `helpdesk_sync_states` (see the helpdesk README, Upgrading from 0.2). An app on helpdesk 0.4 upgrades with one generated migration too: `assignment_note` and `assigned_by` on `helpdesk_threads`, both nullable (see the helpdesk README, Upgrading from 0.4). An app on helpdesk 0.5 upgrades with one generated migration: `from_name`, `preview`, `has_attachments`, `is_read` and `location` on `helpdesk_messages`, all nullable, and its store's `markMessageRemoved` becomes `updateMessageState`. Add `update helpdesk_sync_states set link = null, sent_link = null;` to the end of that generated migration, so the next sync fills the new fields of mail already stored (see the helpdesk README, Upgrading from 0.5). An app on helpdesk 0.11 upgrades with one generated migration: the table `helpdesk_history_states` and `history_lease_until` on `helpdesk_settings`, nothing dropped (see the helpdesk README, Upgrading from 0.11). An app on helpdesk 0.13 upgrades with one generated migration: the table `helpdesk_distill_states` and `distill_lease_until` on `helpdesk_settings`, nothing dropped; then add the store methods, `claimDistillLease`, the distiller in `deps.ts`, the distill cron and the settings card below (see the helpdesk README, Upgrading from 0.13.0). An app on helpdesk 0.14 upgrades with one generated migration: `to_recipients` and `cc_recipients` (jsonb, nullable) on `helpdesk_messages`, and two lines in `toMessage` (see the helpdesk README, Upgrading from 0.14.0). An app on helpdesk 0.15 upgrades with one generated migration: `last_verb` (jsonb, nullable) on `helpdesk_messages`, and one line in `toMessage` (see the helpdesk README, Upgrading from 0.15.0).
|
|
311
|
+
Every column maps one field of the package types (`M365Connection`, `SyncState`, `Thread` incl. `dismissedBy`, `StoredMessage`, `DraftRun`, `SendIntent`, `ReplyAttachment`); `assignee_id`, `assignment_note` and `assigned_by` are the inbox's assignment, `seq` orders draft runs, `sync_lease_until` guards cron overlap. Then run `npm run db:generate`, review the SQL (ten `CREATE TABLE`s, foreign keys, nine indexes, no `DROP`) and commit it with its snapshot and journal entry. An app on helpdesk 0.2 upgrades with one generated migration: `direction` on `helpdesk_messages` (default `inbound`) and `sent_link`, `sent_last_received_at` on `helpdesk_sync_states` (see the helpdesk README, Upgrading from 0.2). An app on helpdesk 0.4 upgrades with one generated migration too: `assignment_note` and `assigned_by` on `helpdesk_threads`, both nullable (see the helpdesk README, Upgrading from 0.4). An app on helpdesk 0.5 upgrades with one generated migration: `from_name`, `preview`, `has_attachments`, `is_read` and `location` on `helpdesk_messages`, all nullable, and its store's `markMessageRemoved` becomes `updateMessageState`. Add `update helpdesk_sync_states set link = null, sent_link = null;` to the end of that generated migration, so the next sync fills the new fields of mail already stored (see the helpdesk README, Upgrading from 0.5). An app on helpdesk 0.11 upgrades with one generated migration: the table `helpdesk_history_states` and `history_lease_until` on `helpdesk_settings`, nothing dropped (see the helpdesk README, Upgrading from 0.11). An app on helpdesk 0.13 upgrades with one generated migration: the table `helpdesk_distill_states` and `distill_lease_until` on `helpdesk_settings`, nothing dropped; then add the store methods, `claimDistillLease`, the distiller in `deps.ts`, the distill cron and the settings card below (see the helpdesk README, Upgrading from 0.13.0). An app on helpdesk 0.14 upgrades with one generated migration: `to_recipients` and `cc_recipients` (jsonb, nullable) on `helpdesk_messages`, and two lines in `toMessage` (see the helpdesk README, Upgrading from 0.14.0). An app on helpdesk 0.15 upgrades with one generated migration: `last_verb` (jsonb, nullable) on `helpdesk_messages`, and one line in `toMessage` (see the helpdesk README, Upgrading from 0.15.0). An app on helpdesk 0.16 upgrades with one generated migration: `draft_mode` (varchar, not null, default `on_request`) on `helpdesk_settings`, nothing dropped; then add the draft mode to `settings.ts`, the actions, the settings form and page, the drafter in `deps.ts`, and `collectDrafts` in the sync cron below (see the helpdesk README, Upgrading from 0.16.0). The store, the crons and `vercel.json` do not change.
|
|
309
312
|
|
|
310
313
|
## 5. `src/lib/m365/` (Graph sign-in and the guided setup)
|
|
311
314
|
|
|
@@ -1110,20 +1113,22 @@ export const helpdeskInbox: HelpdeskInboxQueries = {
|
|
|
1110
1113
|
```ts
|
|
1111
1114
|
import "server-only";
|
|
1112
1115
|
import { and, eq, isNull, lt, or } from "drizzle-orm";
|
|
1113
|
-
import type { HelpdeskControls } from "@dxv-systems/helpdesk";
|
|
1116
|
+
import type { DraftMode, HelpdeskControls } from "@dxv-systems/helpdesk";
|
|
1114
1117
|
import { db } from "@/lib/db";
|
|
1115
1118
|
import { helpdeskSettings } from "@/lib/db/schema";
|
|
1116
1119
|
|
|
1117
1120
|
export interface HelpdeskSettingsView {
|
|
1118
1121
|
paused: boolean;
|
|
1122
|
+
draftMode: DraftMode;
|
|
1119
1123
|
}
|
|
1120
1124
|
|
|
1121
|
-
|
|
1125
|
+
// A new app starts on request: the AI writes a proposal only when staff press "Voorstel schrijven".
|
|
1126
|
+
const DEFAULTS: HelpdeskSettingsView = { paused: false, draftMode: "on_request" };
|
|
1122
1127
|
|
|
1123
1128
|
/** The switches as stored (no row: the defaults). Not user-scoped. */
|
|
1124
1129
|
export async function readHelpdeskSettings(): Promise<HelpdeskSettingsView> {
|
|
1125
1130
|
const [row] = await db
|
|
1126
|
-
.select({ paused: helpdeskSettings.paused })
|
|
1131
|
+
.select({ paused: helpdeskSettings.paused, draftMode: helpdeskSettings.draftMode })
|
|
1127
1132
|
.from(helpdeskSettings)
|
|
1128
1133
|
.where(eq(helpdeskSettings.id, 1))
|
|
1129
1134
|
.limit(1);
|
|
@@ -1132,11 +1137,11 @@ export async function readHelpdeskSettings(): Promise<HelpdeskSettingsView> {
|
|
|
1132
1137
|
|
|
1133
1138
|
/**
|
|
1134
1139
|
* `HelpdeskDeps.controls`: called at the start of every helpdesk call. One way of working: a
|
|
1135
|
-
* person approves each reply in the helpdesk, which then sends it.
|
|
1140
|
+
* person approves each reply in the helpdesk, which then sends it. Switches: pause, draft mode.
|
|
1136
1141
|
*/
|
|
1137
1142
|
export async function loadHelpdeskControls(): Promise<HelpdeskControls> {
|
|
1138
|
-
const { paused } = await readHelpdeskSettings();
|
|
1139
|
-
return { paused, writeMode: "approve_and_send" };
|
|
1143
|
+
const { paused, draftMode } = await readHelpdeskSettings();
|
|
1144
|
+
return { paused, writeMode: "approve_and_send", draftMode };
|
|
1140
1145
|
}
|
|
1141
1146
|
|
|
1142
1147
|
export async function saveHelpdeskSettings(settings: HelpdeskSettingsView, userId: number): Promise<void> {
|
|
@@ -1211,16 +1216,18 @@ export async function releaseDistillLease(): Promise<void> {
|
|
|
1211
1216
|
}
|
|
1212
1217
|
```
|
|
1213
1218
|
|
|
1214
|
-
**
|
|
1219
|
+
**The drafter.** The AI reply proposal is a run of the platform agent `helpdesk-drafter`, started through the gateway feature `helpdesk.draft` (`createRuns` from the template's `@/lib/ai`). The platform never calls the app, so the sync cron below polls the runs with `collectDrafts` for each mailbox right after its sync (every 5 minutes); a finished run puts its text in "Jouw antwoord" and the ticket in review. DXV creates `helpdesk-drafter` in the client's tenant and links it to `helpdesk.draft` in the Portal, as it does `klantenservice-faq` for `helpdesk.faq-distill`. The agent reads the client's FAQ in `klantenservice/faq/` itself through its docstore tools; the run input is only the conversation (helpdesk README, Drafting). Until the feature is linked, a run start fails and the ticket shows "Het voorstel kon niet worden gemaakt" with an empty box; staff write the reply themselves, as without a drafter.
|
|
1220
|
+
|
|
1221
|
+
**On request by default.** A new app stores `draft_mode = on_request`: every new customer mail opens its ticket in review (`reviewReason: "no_draft"`, label "Zelf antwoorden") with an empty "Jouw antwoord" box and the button "Voorstel schrijven" (the package's inbox shows it). Pressing it starts one run; the text arrives with the first sync after the run finishes, within about 5 minutes ("Er wordt een voorstel geschreven…" until then). Staff can also write the reply themselves: saving it creates a staff run (an ordinary draft run with `text: null`, `reason: "staff"`), and "Goedkeuren en versturen" saves and sends it. A blank reply is refused (422 `empty_reply`). The admin switches to `auto` (a proposal for every new mail) on the settings page; it applies from the next sync on.
|
|
1215
1222
|
|
|
1216
1223
|
`src/lib/helpdesk/deps.ts`: one `HelpdeskDeps` per call, built from the stored connection. The notifier sends in-app notifications (template `notifyUsers`) to everyone with `helpdesk:use`, linking to the ticket. That matches this recipe's `getStaff`, where every helpdesk user has access to every connected mailbox; an app with access per person sends each event only to the people with access to `event.mailbox` (helpdesk README, Access per mailbox). `assigned` goes to the assignee only, with the internal note.
|
|
1217
1224
|
|
|
1218
|
-
The distiller starts and reads runs of the gateway feature `helpdesk.faq-distill` (`createRuns` from the template's `@/lib/ai`). DXV registers that feature for the app in the Portal, pointing to the platform agent `klantenservice-faq`. Until then a run start fails, the card shows the error and the pairs wait; nothing else is affected.
|
|
1225
|
+
The drafter starts and reads runs of `helpdesk.draft` (see The drafter above). The distiller starts and reads runs of the gateway feature `helpdesk.faq-distill` (`createRuns` from the template's `@/lib/ai`). DXV registers that feature for the app in the Portal, pointing to the platform agent `klantenservice-faq`. Until then a run start fails, the card shows the error and the pairs wait; nothing else is affected.
|
|
1219
1226
|
|
|
1220
1227
|
```ts
|
|
1221
1228
|
import "server-only";
|
|
1222
1229
|
import { inArray } from "drizzle-orm";
|
|
1223
|
-
import type { Distiller, HelpdeskDeps, Notifier } from "@dxv-systems/helpdesk";
|
|
1230
|
+
import type { Distiller, Drafter, HelpdeskDeps, Notifier } from "@dxv-systems/helpdesk";
|
|
1224
1231
|
import { activeScope } from "@dxv-systems/mail-graph/setup";
|
|
1225
1232
|
import { createRuns } from "@/lib/ai";
|
|
1226
1233
|
import { rolesWithPermission } from "@/lib/auth/permissions";
|
|
@@ -1297,6 +1304,18 @@ const distiller: Distiller = {
|
|
|
1297
1304
|
},
|
|
1298
1305
|
};
|
|
1299
1306
|
|
|
1307
|
+
/** Reply proposals (agent `helpdesk-drafter`). The package builds the input and the event key; the sync cron reads. */
|
|
1308
|
+
const drafter: Drafter = {
|
|
1309
|
+
async start(request) {
|
|
1310
|
+
const { id } = await createRuns({ feature: "helpdesk.draft" }).fireRun({ ...request.input }, { eventKey: request.eventKey });
|
|
1311
|
+
return { runId: String(id) };
|
|
1312
|
+
},
|
|
1313
|
+
async read(runId) {
|
|
1314
|
+
const run = await createRuns({ feature: "helpdesk.draft" }).getRun(runId);
|
|
1315
|
+
return { status: run.status, result: run.result, ...(run.error ? { error: run.error } : {}) };
|
|
1316
|
+
},
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1300
1319
|
/** The app's own sender (EMAIL_FROM): its mail is never a ticket. */
|
|
1301
1320
|
function ownAddresses(): string[] {
|
|
1302
1321
|
const from = process.env.EMAIL_FROM?.trim();
|
|
@@ -1321,6 +1340,7 @@ export async function getHelpdeskDeps(): Promise<HelpdeskDeps | null> {
|
|
|
1321
1340
|
notifier,
|
|
1322
1341
|
attachments: helpdeskReplyFiles,
|
|
1323
1342
|
distiller,
|
|
1343
|
+
drafter,
|
|
1324
1344
|
};
|
|
1325
1345
|
}
|
|
1326
1346
|
```
|
|
@@ -1401,11 +1421,12 @@ export const helpdeskReplyFiles: ReplyAttachmentsDeps = {
|
|
|
1401
1421
|
|
|
1402
1422
|
A `FileServiceError` from `createUploadTarget` or `completeUpload` (too large for `FILE_MAX_SIZE_MB`, a file that was not uploaded) reaches the inbox route as an unexpected error (500, "Er ging iets mis"); the package's own limits (20 MB together, 10 files) are checked first and give a clear message. `deleteFile` removes the `files` row only; the object stays in the bucket under the template's retention model.
|
|
1403
1423
|
|
|
1404
|
-
`src/lib/helpdesk/service.ts`: setup hooks and the
|
|
1424
|
+
`src/lib/helpdesk/service.ts`: setup hooks and the crons (each one run at a time; the sync per mailbox: `connectMailbox` (idempotent), `syncMailbox`, `collectDrafts`, `sweepStuckDrafts`).
|
|
1405
1425
|
|
|
1406
1426
|
```ts
|
|
1407
1427
|
import "server-only";
|
|
1408
1428
|
import {
|
|
1429
|
+
collectDrafts,
|
|
1409
1430
|
connectMailbox,
|
|
1410
1431
|
isPaused,
|
|
1411
1432
|
isSyncFailing,
|
|
@@ -1455,7 +1476,7 @@ export async function onHelpdeskReset(adminId: number | null): Promise<void> {
|
|
|
1455
1476
|
|
|
1456
1477
|
export type HelpdeskSyncOutcome = "not_connected" | "busy" | "paused" | "done";
|
|
1457
1478
|
|
|
1458
|
-
/** Cron: one run at a time (lease). Per mailbox: sync,
|
|
1479
|
+
/** Cron: one run at a time (lease). Per mailbox: sync, bring in finished reply proposals, fail draft runs that never reported. */
|
|
1459
1480
|
export async function runHelpdeskSync(): Promise<HelpdeskSyncOutcome> {
|
|
1460
1481
|
const deps = await getHelpdeskDeps();
|
|
1461
1482
|
if (!deps) return "not_connected";
|
|
@@ -1466,6 +1487,13 @@ export async function runHelpdeskSync(): Promise<HelpdeskSyncOutcome> {
|
|
|
1466
1487
|
// connectMailbox is idempotent; it covers a mailbox added after onConnected.
|
|
1467
1488
|
await connectMailbox(deps, mailbox);
|
|
1468
1489
|
const result = await syncMailbox(deps, mailbox);
|
|
1490
|
+
// The platform never calls the app: poll the reply-proposal runs. A failure here never stops the other mailboxes.
|
|
1491
|
+
try {
|
|
1492
|
+
const drafts = await collectDrafts(deps, mailbox);
|
|
1493
|
+
if (!isPaused(drafts) && drafts.lastError) console.warn("helpdesk drafts: run not readable", { mailbox, error: drafts.lastError });
|
|
1494
|
+
} catch (err) {
|
|
1495
|
+
console.error("helpdesk drafts: collecting failed", { mailbox, error: err instanceof Error ? err.message : String(err) });
|
|
1496
|
+
}
|
|
1469
1497
|
if (isPaused(result)) {
|
|
1470
1498
|
paused = true;
|
|
1471
1499
|
continue;
|
|
@@ -1567,14 +1595,15 @@ import { saveHelpdeskSettings } from "./settings";
|
|
|
1567
1595
|
|
|
1568
1596
|
const settingsSchema = z.object({
|
|
1569
1597
|
paused: z.enum(["on", "off"], { message: "Kies aan of uit." }),
|
|
1598
|
+
draftMode: z.enum(["on_request", "auto"], { message: "Kies wanneer de AI een voorstel schrijft." }),
|
|
1570
1599
|
});
|
|
1571
1600
|
|
|
1572
|
-
/** The pause switch;
|
|
1601
|
+
/** The pause switch and the draft mode; they apply on the next helpdesk call, no redeploy. */
|
|
1573
1602
|
export async function updateHelpdeskSettings(_prev: FormState, formData: FormData): Promise<FormState> {
|
|
1574
1603
|
const user = await requirePermission("m365:manage");
|
|
1575
|
-
const parsed = settingsSchema.safeParse({ paused: formData.get("paused") });
|
|
1604
|
+
const parsed = settingsSchema.safeParse({ paused: formData.get("paused"), draftMode: formData.get("draftMode") });
|
|
1576
1605
|
if (!parsed.success) return { errors: parsed.error.flatten().fieldErrors };
|
|
1577
|
-
await saveHelpdeskSettings({ paused: parsed.data.paused === "on" }, user.id);
|
|
1606
|
+
await saveHelpdeskSettings({ paused: parsed.data.paused === "on", draftMode: parsed.data.draftMode }, user.id);
|
|
1578
1607
|
revalidatePath("/dashboard/helpdesk/instellingen");
|
|
1579
1608
|
return { success: true, message: "Helpdesk-instellingen opgeslagen." };
|
|
1580
1609
|
}
|
|
@@ -1754,12 +1783,13 @@ export function M365NotEnabled({ title, description }: { title: string; descript
|
|
|
1754
1783
|
|
|
1755
1784
|
import { useActionState, useEffect } from "react";
|
|
1756
1785
|
import { toast } from "sonner";
|
|
1786
|
+
import type { DraftMode } from "@dxv-systems/helpdesk";
|
|
1757
1787
|
import { updateHelpdeskSettings } from "@/lib/helpdesk/actions";
|
|
1758
1788
|
import type { FormState } from "@/lib/forms";
|
|
1759
1789
|
import { SubmitButton } from "@/components/submit-button";
|
|
1760
1790
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
|
|
1761
1791
|
|
|
1762
|
-
export function HelpdeskSettingsForm({ paused }: { paused: boolean }) {
|
|
1792
|
+
export function HelpdeskSettingsForm({ paused, draftMode }: { paused: boolean; draftMode: DraftMode }) {
|
|
1763
1793
|
const [state, formAction] = useActionState<FormState, FormData>(updateHelpdeskSettings, {});
|
|
1764
1794
|
|
|
1765
1795
|
useEffect(() => {
|
|
@@ -1787,6 +1817,15 @@ export function HelpdeskSettingsForm({ paused }: { paused: boolean }) {
|
|
|
1787
1817
|
</label>
|
|
1788
1818
|
))}
|
|
1789
1819
|
</fieldset>
|
|
1820
|
+
<fieldset className="space-y-2">
|
|
1821
|
+
<legend className="text-sm font-semibold">Voorstel van de AI</legend>
|
|
1822
|
+
{(["on_request", "auto"] as const).map((value) => (
|
|
1823
|
+
<label key={value} className="flex min-h-11 items-center gap-3">
|
|
1824
|
+
<input type="radio" name="draftMode" value={value} defaultChecked={draftMode === value} className="size-4 accent-primary" />
|
|
1825
|
+
{value === "on_request" ? "Op verzoek, met de knop “Voorstel schrijven”" : "Automatisch bij elke nieuwe mail"}
|
|
1826
|
+
</label>
|
|
1827
|
+
))}
|
|
1828
|
+
</fieldset>
|
|
1790
1829
|
</CardContent>
|
|
1791
1830
|
<CardFooter className="justify-end">
|
|
1792
1831
|
<SubmitButton pendingText="Opslaan…">Opslaan</SubmitButton>
|
|
@@ -2203,7 +2242,7 @@ export default async function HelpdeskSettingsPage() {
|
|
|
2203
2242
|
return (
|
|
2204
2243
|
<div className="space-y-6">
|
|
2205
2244
|
<PageHeader title="Helpdesk-instellingen" />
|
|
2206
|
-
<HelpdeskSettingsForm paused={settings.paused} />
|
|
2245
|
+
<HelpdeskSettingsForm paused={settings.paused} draftMode={settings.draftMode} />
|
|
2207
2246
|
<MailHistorySettings mailboxes={historyMailboxes} />
|
|
2208
2247
|
<MailDistillSettings mailboxes={historyMailboxes} />
|
|
2209
2248
|
</div>
|
|
@@ -2575,4 +2614,5 @@ describe("helpdesk store on Postgres", () => {
|
|
|
2575
2614
|
3. Production, manual flow (test tenant): Beheer → Microsoft 365 → enter mailbox(es) and a check mailbox → "Koppelen met Microsoft" (a Global Administrator signs in and consents for the organisation) → back on the page the setup is already at the access check, with no script; wait for "Gekoppeld" (up to ~2 h; the 10-minute cron keeps checking with the page closed). Also try "Liever met een PowerShell-script" once: consent, Object ID filled, run the downloaded script, "Script is uitgevoerd". Also open the IT link in a private window: it works without an account and the response has `Referrer-Policy: no-referrer`.
|
|
2576
2615
|
4. Send a mail to the connected mailbox. Within 5 minutes it appears under Helpdesk as "Te beoordelen" ("Zelf antwoorden") with an empty "Jouw antwoord" box and a notification. Type a reply, "Goedkeuren en versturen" → the reply is in the mailbox's Sent Items, threaded under the customer's mail with the quote kept.
|
|
2577
2616
|
5. Pause on the admin page → the inbox shows the pause banner and the next cron returns `paused`. Unpause.
|
|
2578
|
-
6.
|
|
2617
|
+
6. Reply proposal (once DXV has linked `helpdesk-drafter` to `helpdesk.draft`): on a ticket in review press "Voorstel schrijven" → "Er wordt een voorstel geschreven…", and after the next sync cron (within about 5 minutes of the run finishing) the AI's text is in "Jouw antwoord". Nothing is sent until "Goedkeuren en versturen".
|
|
2618
|
+
7. Files on a reply (production): open a ticket, "Bijlage toevoegen" with a PDF of a few MB and one over 4.5 MB, then "Goedkeuren en versturen". The reply in Outlook's Sent Items carries both files; the ticket shows them on the sent reply in the conversation. A file above 20 MB is refused with the limit message before any upload.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxv-systems/mail-graph",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Microsoft Graph mail for DXV apps — app-only auth via a caller-supplied client assertion (federated or certificate), per-mailbox delta sync, messages, attachments, threaded replies, folders, forward and send. Never deletes. Guided Microsoft 365 setup (route handlers and a React page) under ./setup. Zero runtime dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dxv",
|