@imenam/mcp-organizer 1.0.30 → 1.0.32
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/README.md +7 -6
- package/dist/shared/schemas/admin-api.schema.d.ts +43 -1
- package/dist/shared/schemas/admin-api.schema.js +10 -1
- package/dist/shared/schemas/entities.schema.d.ts +6 -0
- package/dist/shared/schemas/entities.schema.js +6 -0
- package/dist/shared/schemas/notifications-api.schema.d.ts +2 -0
- package/dist/shared/schemas/notifications-api.schema.js +4 -1
- package/dist/src/core/migrations.js +12 -0
- package/dist/src/core/notifications.d.ts +19 -4
- package/dist/src/core/notifications.js +139 -29
- package/dist/src/core/store.d.ts +11 -4
- package/dist/src/core/store.js +37 -9
- package/gui/dist/assets/index-B-B-jasM.css +1 -0
- package/gui/dist/assets/index-D4QIxUSt.js +104 -0
- package/gui/dist/index.html +2 -2
- package/package.json +1 -1
- package/gui/dist/assets/index-BqkvnOJy.js +0 -104
- package/gui/dist/assets/index-rbLhuRHl.css +0 -1
|
@@ -53,13 +53,22 @@ function userName(store, userId) {
|
|
|
53
53
|
function batched(notification) {
|
|
54
54
|
return notification.actorType === "agent" && notification.requestId !== null;
|
|
55
55
|
}
|
|
56
|
+
/** Fin de la période de `minutes` minutes, alignée sur l'heure, qui contient l'instant `at`. */
|
|
57
|
+
export function digestPeriodEnd(at, minutes) {
|
|
58
|
+
const period = minutes * 60_000;
|
|
59
|
+
return (Math.floor(at / period) + 1) * period;
|
|
60
|
+
}
|
|
56
61
|
/**
|
|
57
62
|
* Envoi des e-mails de notification. Le store marque en base les
|
|
58
63
|
* notifications à envoyer par e-mail ; après chaque mutation qui peut en
|
|
59
|
-
* rendre prêtes, au démarrage et à l'échéance du prochain
|
|
60
|
-
* parcourt celles en attente
|
|
64
|
+
* rendre prêtes, au démarrage et à l'échéance du prochain envoi, l'envoi
|
|
65
|
+
* parcourt celles en attente. Pour un destinataire qui reçoit un résumé
|
|
66
|
+
* périodique (`emailDigestMinutes`), toutes ses notifications en attente
|
|
67
|
+
* partent dans un seul e-mail à la fin de la période, alignée sur l'heure, qui
|
|
68
|
+
* contient la plus ancienne. Pour les autres :
|
|
61
69
|
*
|
|
62
|
-
* -
|
|
70
|
+
* - celles des actions des utilisateurs partent aussitôt, dans un seul e-mail
|
|
71
|
+
* quand plusieurs sont prêtes en même temps ;
|
|
63
72
|
* - celles de l'agent sont regroupées par destinataire et par lot (la demande
|
|
64
73
|
* pour laquelle il agit) : un seul e-mail part quand la demande quitte
|
|
65
74
|
* `processing` (traitée, échouée, libérée), ou au plus tard `maxDelayMs`
|
|
@@ -115,24 +124,20 @@ export class NotificationMailer {
|
|
|
115
124
|
this.deps.logError(`Listing the pending notification e-mails failed: ${err?.stack ?? err}`);
|
|
116
125
|
return;
|
|
117
126
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
group.push(notification);
|
|
126
|
-
else
|
|
127
|
-
groups.set(key, [notification]);
|
|
127
|
+
let groups;
|
|
128
|
+
try {
|
|
129
|
+
groups = this.group(pending.filter((notification) => !this.sending.has(notification.id) && !this.abandoned.has(notification.id)));
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
this.deps.logError(`Grouping the pending notification e-mails failed: ${err?.stack ?? err}`);
|
|
133
|
+
return;
|
|
128
134
|
}
|
|
129
135
|
let next = Infinity;
|
|
130
|
-
for (const group of groups
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.enqueue(group.map((notification) => notification.id));
|
|
136
|
+
for (const group of groups) {
|
|
137
|
+
if (this.ready(group))
|
|
138
|
+
this.enqueue(group.kind, group.notifications.map((notification) => notification.id));
|
|
134
139
|
else
|
|
135
|
-
next = Math.min(next, deadline);
|
|
140
|
+
next = Math.min(next, group.deadline);
|
|
136
141
|
}
|
|
137
142
|
if (next < Infinity) {
|
|
138
143
|
this.timer = setTimeout(() => this.sweep(), Math.max(0, next - this.now()));
|
|
@@ -144,17 +149,42 @@ export class NotificationMailer {
|
|
|
144
149
|
clearTimeout(this.timer);
|
|
145
150
|
this.timer = null;
|
|
146
151
|
}
|
|
147
|
-
/**
|
|
148
|
-
|
|
149
|
-
|
|
152
|
+
/** Répartit les notifications en attente, les plus anciennes d'abord, en e-mails. */
|
|
153
|
+
group(pending) {
|
|
154
|
+
const periods = new Map();
|
|
155
|
+
const groups = new Map();
|
|
156
|
+
for (const notification of pending) {
|
|
157
|
+
const { userId } = notification;
|
|
158
|
+
if (!periods.has(userId))
|
|
159
|
+
periods.set(userId, this.store.getUserSettings(userId).emailDigestMinutes);
|
|
160
|
+
const period = periods.get(userId);
|
|
161
|
+
const createdAt = Date.parse(notification.createdAt);
|
|
162
|
+
const [key, kind, deadline] = period !== null
|
|
163
|
+
? [`digest ${userId}`, "summary", digestPeriodEnd(createdAt, period)]
|
|
164
|
+
: batched(notification)
|
|
165
|
+
? [`batch ${userId} ${notification.requestId}`, "batch", createdAt + this.maxDelayMs]
|
|
166
|
+
: [`now ${userId}`, "summary", createdAt];
|
|
167
|
+
const group = groups.get(key);
|
|
168
|
+
if (group)
|
|
169
|
+
group.notifications.push(notification);
|
|
170
|
+
else
|
|
171
|
+
groups.set(key, { kind, notifications: [notification], deadline });
|
|
172
|
+
}
|
|
173
|
+
return [...groups.values()];
|
|
174
|
+
}
|
|
175
|
+
/** Vrai si le groupe peut partir : échéance atteinte, ou lot de l'agent dont la demande est close. */
|
|
176
|
+
ready(group) {
|
|
177
|
+
if (this.now() >= group.deadline)
|
|
150
178
|
return true;
|
|
151
|
-
|
|
179
|
+
if (group.kind !== "batch")
|
|
180
|
+
return false;
|
|
181
|
+
const request = this.store.findAgentRequest(group.notifications[0].requestId);
|
|
152
182
|
return request === null || request.status !== "processing";
|
|
153
183
|
}
|
|
154
|
-
enqueue(ids) {
|
|
184
|
+
enqueue(kind, ids) {
|
|
155
185
|
for (const id of ids)
|
|
156
186
|
this.sending.add(id);
|
|
157
|
-
const delivery = this.deliver(ids).finally(() => {
|
|
187
|
+
const delivery = this.deliver(kind, ids).finally(() => {
|
|
158
188
|
for (const id of ids)
|
|
159
189
|
this.sending.delete(id);
|
|
160
190
|
this.inFlight.delete(delivery);
|
|
@@ -162,12 +192,12 @@ export class NotificationMailer {
|
|
|
162
192
|
this.inFlight.add(delivery);
|
|
163
193
|
}
|
|
164
194
|
/** Envoie un e-mail pour les notifications `ids`, d'un même destinataire, et enregistre son issue sur chacune. */
|
|
165
|
-
async deliver(ids) {
|
|
195
|
+
async deliver(kind, ids) {
|
|
166
196
|
try {
|
|
167
197
|
const notifications = this.existing(ids);
|
|
168
198
|
if (notifications.length === 0)
|
|
169
199
|
return;
|
|
170
|
-
const outcome = await this.send(notifications);
|
|
200
|
+
const outcome = await this.send(kind, notifications);
|
|
171
201
|
// Une notification disparaît avec sa tâche ou son commentaire, éventuellement supprimés pendant l'envoi.
|
|
172
202
|
this.record(this.existing(ids), outcome);
|
|
173
203
|
}
|
|
@@ -194,12 +224,16 @@ export class NotificationMailer {
|
|
|
194
224
|
tx.recordNotificationEmail(notification.id, outcome);
|
|
195
225
|
});
|
|
196
226
|
}
|
|
197
|
-
async send(notifications) {
|
|
227
|
+
async send(kind, notifications) {
|
|
198
228
|
const blocker = notificationEmailBlocker(this.deps);
|
|
199
229
|
if (blocker)
|
|
200
230
|
return { sent: false, reason: blocker };
|
|
201
231
|
const recipient = this.store.getUser(notifications[0].userId);
|
|
202
|
-
const message = notifications.length === 1
|
|
232
|
+
const message = notifications.length === 1
|
|
233
|
+
? this.message(notifications[0], recipient.email)
|
|
234
|
+
: kind === "batch"
|
|
235
|
+
? this.digest(notifications, recipient.email)
|
|
236
|
+
: this.summary(notifications, recipient.email);
|
|
203
237
|
const outcome = await this.deps.mailer.send(message);
|
|
204
238
|
return outcome.sent ? { sent: true } : { sent: false, reason: outcome.reason };
|
|
205
239
|
}
|
|
@@ -307,6 +341,77 @@ export class NotificationMailer {
|
|
|
307
341
|
action: request ? { label: "Voir la demande", url: this.requestUrl(request.id) } : undefined,
|
|
308
342
|
});
|
|
309
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* E-mail qui regroupe des notifications quelconques d'un destinataire, d'un
|
|
346
|
+
* ou de plusieurs espaces : chaque tâche concernée avec ce qui la touche,
|
|
347
|
+
* qui l'a fait et son lien, puis chaque demande traitée avec les points
|
|
348
|
+
* laissés à son auteur.
|
|
349
|
+
*/
|
|
350
|
+
summary(notifications, to) {
|
|
351
|
+
const byTask = new Map();
|
|
352
|
+
const requestIds = new Set();
|
|
353
|
+
for (const notification of notifications) {
|
|
354
|
+
if (notification.taskId === null) {
|
|
355
|
+
requestIds.add(notification.requestId);
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
const list = byTask.get(notification.taskId);
|
|
359
|
+
if (list)
|
|
360
|
+
list.push(notification);
|
|
361
|
+
else
|
|
362
|
+
byTask.set(notification.taskId, [notification]);
|
|
363
|
+
}
|
|
364
|
+
const tasks = [...byTask.keys()].map((taskId) => this.store.getTask(taskId));
|
|
365
|
+
const requests = [...requestIds].map((requestId) => this.store.getAgentRequest(requestId));
|
|
366
|
+
const spaces = new Map();
|
|
367
|
+
for (const spaceId of [...tasks.map((task) => task.spaceId), ...requests.map((request) => request.targetSpaceId)]) {
|
|
368
|
+
if (!spaces.has(spaceId))
|
|
369
|
+
spaces.set(spaceId, this.store.getSpace(spaceId));
|
|
370
|
+
}
|
|
371
|
+
const single = spaces.size === 1 ? [...spaces.values()][0] : null;
|
|
372
|
+
const where = single ? `dans l'espace « ${single.name} »` : `dans ${spaces.size} espaces`;
|
|
373
|
+
const blocks = [{ type: "paragraph", content: [`${capitalize(notificationsLabel(notifications.length))} ${where}.`] }];
|
|
374
|
+
for (const task of tasks) {
|
|
375
|
+
const space = spaces.get(task.spaceId);
|
|
376
|
+
const taskUrl = this.taskUrl(task.id);
|
|
377
|
+
const items = byTask.get(task.id).map((notification) => {
|
|
378
|
+
const who = actorName(this.store, notification) ?? AGENT_NAME;
|
|
379
|
+
if (notification.type === "assigned")
|
|
380
|
+
return { label: `${who} vous a assigné cette tâche` };
|
|
381
|
+
const comment = notification.commentId === null ? null : this.store.findComment(notification.commentId);
|
|
382
|
+
const body = (comment?.body ?? "").trim();
|
|
383
|
+
return body ? { label: `${who} a commenté`, markdown: body } : { label: `${who} a commenté` };
|
|
384
|
+
});
|
|
385
|
+
blocks.push({
|
|
386
|
+
type: "section",
|
|
387
|
+
title: [{ strong: `${space.keyPrefix}-${task.number} « ${task.title} »` }, ...(single ? [] : [` · ${space.name}`])],
|
|
388
|
+
items,
|
|
389
|
+
link: { label: "Ouvrir la tâche", url: taskUrl },
|
|
390
|
+
links: { attachmentUrl: taskUrl, keyPrefixes: [space.keyPrefix], spaceId: space.id },
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
for (const request of requests) {
|
|
394
|
+
const space = spaces.get(request.targetSpaceId);
|
|
395
|
+
const requestUrl = this.requestUrl(request.id);
|
|
396
|
+
blocks.push({
|
|
397
|
+
type: "section",
|
|
398
|
+
title: [`${AGENT_NAME} a traité ta demande « ${requestExcerpt(request.text)} »${single ? "" : ` · ${space.name}`} : ${POINTS_TITLE.toLowerCase()}`],
|
|
399
|
+
items: this.openPoints(request.id).map((point) => ({ markdown: point })),
|
|
400
|
+
link: { label: "Voir la demande", url: requestUrl },
|
|
401
|
+
links: { attachmentUrl: requestUrl, keyPrefixes: [space.keyPrefix], spaceId: space.id },
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
const baseUrl = publicBase(this.deps.publicUrl);
|
|
405
|
+
const rendered = renderEmail({
|
|
406
|
+
subject: `Résumé : ${notificationsLabel(notifications.length)} ${where}`,
|
|
407
|
+
space: single?.name ?? null,
|
|
408
|
+
blocks,
|
|
409
|
+
footnote: UNSUBSCRIBE,
|
|
410
|
+
preferencesUrl: `${baseUrl}/#/parametres`,
|
|
411
|
+
links: { baseUrl, keyPrefixes: [...spaces.values()].map((space) => space.keyPrefix), spaceId: single?.id ?? null },
|
|
412
|
+
});
|
|
413
|
+
return { to, ...rendered };
|
|
414
|
+
}
|
|
310
415
|
/** E-mail de notification rendu dans le gabarit, avec les liens de l'espace et celui des préférences. */
|
|
311
416
|
mail(to, space, content) {
|
|
312
417
|
const baseUrl = publicBase(this.deps.publicUrl);
|
|
@@ -337,6 +442,10 @@ export class NotificationMailer {
|
|
|
337
442
|
function notificationsLabel(count) {
|
|
338
443
|
return `${count} notification${count > 1 ? "s" : ""}`;
|
|
339
444
|
}
|
|
445
|
+
/** Texte avec une majuscule initiale. */
|
|
446
|
+
function capitalize(text) {
|
|
447
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
448
|
+
}
|
|
340
449
|
/** « 1 point », « 3 points ». */
|
|
341
450
|
function pointsLabel(count) {
|
|
342
451
|
return `${count} point${count > 1 ? "s" : ""}`;
|
|
@@ -392,7 +501,7 @@ export function markAllNotificationsRead(store, userId) {
|
|
|
392
501
|
return unreadCount(store, userId);
|
|
393
502
|
}
|
|
394
503
|
function settingsView(store, deps, userId) {
|
|
395
|
-
const { notifyAssignApp, notifyAssignEmail, notifyCommentApp, notifyCommentEmail, notifyFollowUpApp, notifyFollowUpEmail, assistantHistory, pomodoro } = store.getUserSettings(userId);
|
|
504
|
+
const { notifyAssignApp, notifyAssignEmail, notifyCommentApp, notifyCommentEmail, notifyFollowUpApp, notifyFollowUpEmail, assistantHistory, pomodoro, emailDigestMinutes, } = store.getUserSettings(userId);
|
|
396
505
|
const reason = notificationEmailBlocker(deps);
|
|
397
506
|
return {
|
|
398
507
|
notifyAssignApp,
|
|
@@ -403,6 +512,7 @@ function settingsView(store, deps, userId) {
|
|
|
403
512
|
notifyFollowUpEmail,
|
|
404
513
|
assistantHistory,
|
|
405
514
|
pomodoro,
|
|
515
|
+
emailDigestMinutes,
|
|
406
516
|
email: { enabled: reason === null, reason },
|
|
407
517
|
transcription: { enabled: deps.transcriber.enabled, reason: deps.transcriber.disabledReason },
|
|
408
518
|
};
|
package/dist/src/core/store.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type Database from "better-sqlite3";
|
|
2
2
|
import { WatcherRegistry } from "./watchers.js";
|
|
3
3
|
import { type BoardGrouping, type BoardLayout, type EntityType, type MemberRole, type RequestKind, type RequestStatus, type SpaceKind, type TaskPriority, type TaskStatus, type TaskType, type TestResultValue, type AccessLinkPurpose, type AgentOperation, type UserStatus, type VersionedEntityType } from "../../shared/schemas/enums.schema.js";
|
|
4
|
-
import { type AccessLink, type AgentAction, type AgentInstructions, type AgentRequest, type AgentToken, type Attachment, type BoardView, type Change, type ChecklistItem, type Comment, type QuestionOption, type QuestionSnapshot, type TaskQuestion, type EntityVersion, type FollowUp, type Idea, type Invitation, type Note, type SpaceDocument, type Membership, type Notification, type Session, type Space, type Tag, type Task, type TaskSnapshot, type TestCheckpoint, type TestResult, type TestReview, type TimeSession, type PomodoroSettings, type User, type UserSettings, type NotificationPreferences, type SpaceNotificationSettings } from "../../shared/schemas/entities.schema.js";
|
|
5
|
-
import { type ClaudeConnection, type RunnerSessionRecord, type RunnerSettings } from "../../shared/schemas/admin-api.schema.js";
|
|
4
|
+
import { type AccessLink, type AgentAction, type AgentInstructions, type AgentRequest, type AgentToken, type Attachment, type BoardView, type Change, type ChecklistItem, type Comment, type QuestionOption, type QuestionSnapshot, type TaskQuestion, type EntityVersion, type FollowUp, type Idea, type Invitation, type Note, type SpaceDocument, type Membership, type Notification, type Session, type Space, type Tag, type Task, type TaskSnapshot, type TestCheckpoint, type TestResult, type TestReview, type TimeSession, type PomodoroSettings, type EmailDigestMinutes, type User, type UserSettings, type NotificationPreferences, type SpaceNotificationSettings } from "../../shared/schemas/entities.schema.js";
|
|
5
|
+
import { type ClaudeConnection, type NewRunnerSession, type RunnerSessionRecord, type RunnerSettings } from "../../shared/schemas/admin-api.schema.js";
|
|
6
6
|
/**
|
|
7
7
|
* Auteur d'une mutation : un utilisateur de la GUI, ou un agent qui agit avec
|
|
8
8
|
* son jeton, avec les droits du propriétaire du jeton, pour une demande que ce
|
|
@@ -377,6 +377,7 @@ export interface UpdateUserSettingsInput {
|
|
|
377
377
|
notifyFollowUpEmail?: boolean;
|
|
378
378
|
assistantHistory?: number;
|
|
379
379
|
pomodoro?: PomodoroSettings;
|
|
380
|
+
emailDigestMinutes?: EmailDigestMinutes | null;
|
|
380
381
|
}
|
|
381
382
|
/** Issue de l'envoi de l'e-mail d'une notification. */
|
|
382
383
|
export type NotificationEmailOutcome = {
|
|
@@ -480,6 +481,8 @@ export declare class Mutation {
|
|
|
480
481
|
readonly emailNotificationIds: string[];
|
|
481
482
|
/** Demandes de l'agent touchées par la mutation. */
|
|
482
483
|
readonly touchedRequestIds: Set<string>;
|
|
484
|
+
/** Vrai si la mutation change la période du résumé des e-mails d'un utilisateur. */
|
|
485
|
+
emailScheduleChanged: boolean;
|
|
483
486
|
/** Demandes passées en attente par la mutation : créées, ou libérées. */
|
|
484
487
|
readonly pendingRequestIds: string[];
|
|
485
488
|
/** Espaces où la mutation a autorisé le runner. */
|
|
@@ -889,8 +892,12 @@ export declare class Mutation {
|
|
|
889
892
|
setClaudeConnection(tokenCipher: string, tokenHint: string): ClaudeConnection;
|
|
890
893
|
/** Marque le token de Claude comme refusé par Claude, avec le message de Claude Code. */
|
|
891
894
|
markClaudeTokenRefused(reason: string): void;
|
|
892
|
-
/**
|
|
893
|
-
|
|
895
|
+
/**
|
|
896
|
+
* Enregistre le relevé d'une session du runner terminée, avec les auteurs des
|
|
897
|
+
* demandes de son espace que le runner a prises entre son début et sa fin
|
|
898
|
+
* (hors actions directes).
|
|
899
|
+
*/
|
|
900
|
+
recordRunnerSession(record: NewRunnerSession): void;
|
|
894
901
|
/** Vérifie les invariants sur l'état final, puis écrit les versions et le journal. */
|
|
895
902
|
finish(): void;
|
|
896
903
|
private checkInvariants;
|
package/dist/src/core/store.js
CHANGED
|
@@ -6,7 +6,7 @@ import { WatcherRegistry } from "./watchers.js";
|
|
|
6
6
|
import { isVisibleVersion, VERSION_SNAPSHOT_SCHEMAS, versionSnapshot } from "./versions.js";
|
|
7
7
|
import { MAX_TASK_DEPTH, TASK_PRIORITIES, TASK_STATUSES, TASK_TYPES, VERSIONED_ENTITY_TYPES, } from "../../shared/schemas/enums.schema.js";
|
|
8
8
|
import { AccessLinkSchema, AgentActionSchema, AgentInstructionsSchema, AgentTokenSchema, AgentRequestSchema, AttachmentSchema, BoardViewSchema, ChangeSchema, ChecklistItemSchema, CommentSchema, MAX_QUESTION_OPTIONS, QuestionOptionSchema, TaskQuestionSchema, EntityVersionSchema, FollowUpSchema, IdeaSchema, InvitationSchema, NoteSchema, SpaceDocumentSchema, MembershipSchema, NotificationSchema, SessionSchema, SpaceSchema, TagSchema, TaskSchema, TaskSnapshotSchema, TestCheckpointSchema, TestResultSchema, TestReviewSchema, TimeSessionSchema, UserSchema, UserSettingsSchema, SpaceNotificationSettingsSchema, } from "../../shared/schemas/entities.schema.js";
|
|
9
|
-
import { ClaudeConnectionSchema, RunnerSessionRecordSchema, RunnerSettingsSchema, } from "../../shared/schemas/admin-api.schema.js";
|
|
9
|
+
import { ClaudeConnectionSchema, NewRunnerSessionSchema, RunnerSessionRecordSchema, RunnerSettingsSchema, } from "../../shared/schemas/admin-api.schema.js";
|
|
10
10
|
/** Valide `value` avec `schema` ; une donnée invalide est une erreur métier qui liste les champs fautifs. */
|
|
11
11
|
function validate(schema, value, what) {
|
|
12
12
|
const parsed = schema.safeParse(value);
|
|
@@ -45,7 +45,7 @@ function spaceNotificationSettingsFromRow(row) {
|
|
|
45
45
|
function agentInstructionsFromRow(row) {
|
|
46
46
|
return AgentInstructionsSchema.parse({ spaceId: row.space_id, text: row.text, updatedAt: row.updated_at, updatedBy: row.updated_by });
|
|
47
47
|
}
|
|
48
|
-
function runnerSessionFromRow(row) {
|
|
48
|
+
function runnerSessionFromRow(row, authors) {
|
|
49
49
|
return RunnerSessionRecordSchema.parse({
|
|
50
50
|
id: row.id,
|
|
51
51
|
spaceId: row.space_id,
|
|
@@ -60,6 +60,7 @@ function runnerSessionFromRow(row) {
|
|
|
60
60
|
outputTokens: row.output_tokens,
|
|
61
61
|
cacheReadTokens: row.cache_read_tokens,
|
|
62
62
|
cacheCreationTokens: row.cache_creation_tokens,
|
|
63
|
+
authors,
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
66
|
/** Les préférences de notification d'un objet qui les porte. */
|
|
@@ -83,6 +84,7 @@ function settingsFromRow(row) {
|
|
|
83
84
|
longBreakMinutes: row.pomodoro_long_break_minutes,
|
|
84
85
|
cycles: row.pomodoro_cycles,
|
|
85
86
|
},
|
|
87
|
+
emailDigestMinutes: row.email_digest_minutes,
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
90
|
function timeSessionFromRow(row) {
|
|
@@ -531,7 +533,19 @@ export class Store {
|
|
|
531
533
|
}
|
|
532
534
|
/** Sessions du runner commencées depuis `since`, de la plus récente à la plus ancienne. */
|
|
533
535
|
listRunnerSessionsSince(since) {
|
|
534
|
-
|
|
536
|
+
const rows = this.db.prepare("SELECT * FROM runner_sessions WHERE started_at >= ? ORDER BY started_at DESC, id").all(since);
|
|
537
|
+
const authors = new Map();
|
|
538
|
+
const authorRows = this.db
|
|
539
|
+
.prepare(`SELECT a.session_id, u.id, COALESCE(u.display_name, u.email) AS name
|
|
540
|
+
FROM runner_session_authors a JOIN runner_sessions s ON s.id = a.session_id JOIN users u ON u.id = a.user_id
|
|
541
|
+
WHERE s.started_at >= ? ORDER BY name COLLATE NOCASE, u.id`)
|
|
542
|
+
.all(since);
|
|
543
|
+
for (const row of authorRows) {
|
|
544
|
+
const list = authors.get(row.session_id) ?? [];
|
|
545
|
+
list.push({ id: row.id, name: row.name });
|
|
546
|
+
authors.set(row.session_id, list);
|
|
547
|
+
}
|
|
548
|
+
return rows.map((row) => runnerSessionFromRow(row, authors.get(row.id) ?? []));
|
|
535
549
|
}
|
|
536
550
|
/** Instructions de l'agent propres à un espace, ou celles du site quand `spaceId` est null ; null s'il n'y en a pas. */
|
|
537
551
|
findAgentInstructions(spaceId) {
|
|
@@ -1304,7 +1318,7 @@ export class Store {
|
|
|
1304
1318
|
try {
|
|
1305
1319
|
const result = fn(tx);
|
|
1306
1320
|
tx.finish();
|
|
1307
|
-
emails = tx.emailNotificationIds.length > 0 || tx.touchedRequestIds.size > 0;
|
|
1321
|
+
emails = tx.emailNotificationIds.length > 0 || tx.touchedRequestIds.size > 0 || tx.emailScheduleChanged;
|
|
1308
1322
|
pending = tx.pendingRequestIds;
|
|
1309
1323
|
allowed = tx.runnerAllowedSpaceIds;
|
|
1310
1324
|
return result;
|
|
@@ -1350,6 +1364,8 @@ export class Mutation {
|
|
|
1350
1364
|
emailNotificationIds = [];
|
|
1351
1365
|
/** Demandes de l'agent touchées par la mutation. */
|
|
1352
1366
|
touchedRequestIds = new Set();
|
|
1367
|
+
/** Vrai si la mutation change la période du résumé des e-mails d'un utilisateur. */
|
|
1368
|
+
emailScheduleChanged = false;
|
|
1353
1369
|
/** Demandes passées en attente par la mutation : créées, ou libérées. */
|
|
1354
1370
|
pendingRequestIds = [];
|
|
1355
1371
|
/** Espaces où la mutation a autorisé le runner. */
|
|
@@ -3071,12 +3087,15 @@ export class Mutation {
|
|
|
3071
3087
|
}
|
|
3072
3088
|
/** Modifie les préférences d'un utilisateur. */
|
|
3073
3089
|
updateUserSettings(userId, patch) {
|
|
3074
|
-
const
|
|
3090
|
+
const previous = this.store.getUserSettings(userId);
|
|
3091
|
+
const settings = validate(UserSettingsSchema, { ...previous, ...definedFields(patch) }, "settings");
|
|
3092
|
+
if (settings.emailDigestMinutes !== previous.emailDigestMinutes)
|
|
3093
|
+
this.emailScheduleChanged = true;
|
|
3075
3094
|
this.db
|
|
3076
3095
|
.prepare(`UPDATE user_settings SET notify_assign_app = ?, notify_assign_email = ?, notify_comment_app = ?, notify_comment_email = ?,
|
|
3077
3096
|
notify_follow_up_app = ?, notify_follow_up_email = ?, assistant_history = ?, pomodoro_work_minutes = ?,
|
|
3078
|
-
pomodoro_short_break_minutes = ?, pomodoro_long_break_minutes = ?, pomodoro_cycles = ? WHERE user_id = ?`)
|
|
3079
|
-
.run(settings.notifyAssignApp ? 1 : 0, settings.notifyAssignEmail ? 1 : 0, settings.notifyCommentApp ? 1 : 0, settings.notifyCommentEmail ? 1 : 0, settings.notifyFollowUpApp ? 1 : 0, settings.notifyFollowUpEmail ? 1 : 0, settings.assistantHistory, settings.pomodoro.workMinutes, settings.pomodoro.shortBreakMinutes, settings.pomodoro.longBreakMinutes, settings.pomodoro.cycles, userId);
|
|
3097
|
+
pomodoro_short_break_minutes = ?, pomodoro_long_break_minutes = ?, pomodoro_cycles = ?, email_digest_minutes = ? WHERE user_id = ?`)
|
|
3098
|
+
.run(settings.notifyAssignApp ? 1 : 0, settings.notifyAssignEmail ? 1 : 0, settings.notifyCommentApp ? 1 : 0, settings.notifyCommentEmail ? 1 : 0, settings.notifyFollowUpApp ? 1 : 0, settings.notifyFollowUpEmail ? 1 : 0, settings.assistantHistory, settings.pomodoro.workMinutes, settings.pomodoro.shortBreakMinutes, settings.pomodoro.longBreakMinutes, settings.pomodoro.cycles, settings.emailDigestMinutes, userId);
|
|
3080
3099
|
this.touch("user_settings", userId, null, userId);
|
|
3081
3100
|
return settings;
|
|
3082
3101
|
}
|
|
@@ -3146,13 +3165,22 @@ export class Mutation {
|
|
|
3146
3165
|
markClaudeTokenRefused(reason) {
|
|
3147
3166
|
this.db.prepare("UPDATE claude_connection SET refused_at = ?, refused_reason = ? WHERE id = 1").run(this.now, reason);
|
|
3148
3167
|
}
|
|
3149
|
-
/**
|
|
3168
|
+
/**
|
|
3169
|
+
* Enregistre le relevé d'une session du runner terminée, avec les auteurs des
|
|
3170
|
+
* demandes de son espace que le runner a prises entre son début et sa fin
|
|
3171
|
+
* (hors actions directes).
|
|
3172
|
+
*/
|
|
3150
3173
|
recordRunnerSession(record) {
|
|
3151
|
-
const valid = validate(
|
|
3174
|
+
const valid = validate(NewRunnerSessionSchema, record, "runner session");
|
|
3152
3175
|
this.db
|
|
3153
3176
|
.prepare(`INSERT INTO runner_sessions (id, space_id, space_name, started_at, ended_at, outcome, model, turns, cost_usd, input_tokens, output_tokens, cache_read_tokens, cache_creation_tokens)
|
|
3154
3177
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
3155
3178
|
.run(valid.id, valid.spaceId, valid.spaceName, valid.startedAt, valid.endedAt, valid.outcome, valid.model, valid.turns, valid.costUsd, valid.inputTokens, valid.outputTokens, valid.cacheReadTokens, valid.cacheCreationTokens);
|
|
3179
|
+
this.db
|
|
3180
|
+
.prepare(`INSERT INTO runner_session_authors (session_id, user_id)
|
|
3181
|
+
SELECT DISTINCT ?, r.author_id FROM agent_requests r JOIN agent_tokens t ON t.id = r.claimed_by_token_id
|
|
3182
|
+
WHERE r.target_space_id = ? AND t.is_runner = 1 AND r.kind <> 'direct' AND r.claimed_at >= ? AND r.claimed_at <= ?`)
|
|
3183
|
+
.run(valid.id, valid.spaceId, valid.startedAt, valid.endedAt);
|
|
3156
3184
|
}
|
|
3157
3185
|
// --- Fin de mutation ---
|
|
3158
3186
|
/** Vérifie les invariants sur l'état final, puis écrit les versions et le journal. */
|