@imenam/mcp-organizer 1.0.20 → 1.0.22
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 +110 -32
- package/dist/shared/logic/attachments.d.ts +28 -0
- package/dist/shared/logic/attachments.js +52 -0
- package/dist/shared/logic/documents.d.ts +20 -0
- package/dist/shared/logic/documents.js +33 -0
- package/dist/shared/logic/line-diff.d.ts +13 -0
- package/dist/shared/logic/line-diff.js +66 -0
- package/dist/shared/logic/notes.d.ts +12 -0
- package/dist/shared/logic/notes.js +23 -0
- package/dist/shared/logic/timer.d.ts +69 -0
- package/dist/shared/logic/timer.js +87 -0
- package/dist/shared/schemas/agent-api.schema.d.ts +10 -29
- package/dist/shared/schemas/agent-api.schema.js +4 -15
- package/dist/shared/schemas/agent-tools.schema.d.ts +648 -2
- package/dist/shared/schemas/agent-tools.schema.js +158 -8
- package/dist/shared/schemas/api.schema.d.ts +7 -0
- package/dist/shared/schemas/api.schema.js +6 -0
- package/dist/shared/schemas/documents-api.schema.d.ts +47 -0
- package/dist/shared/schemas/documents-api.schema.js +36 -0
- package/dist/shared/schemas/entities.schema.d.ts +107 -54
- package/dist/shared/schemas/entities.schema.js +81 -10
- package/dist/shared/schemas/enums.schema.d.ts +19 -3
- package/dist/shared/schemas/enums.schema.js +8 -2
- package/dist/shared/schemas/gui-api.schema.d.ts +1 -0
- package/dist/shared/schemas/gui-api.schema.js +2 -0
- package/dist/shared/schemas/history-api.schema.d.ts +961 -0
- package/dist/shared/schemas/history-api.schema.js +104 -0
- package/dist/shared/schemas/notes-api.schema.d.ts +54 -0
- package/dist/shared/schemas/notes-api.schema.js +38 -0
- package/dist/shared/schemas/notifications-api.schema.d.ts +12 -0
- package/dist/shared/schemas/notifications-api.schema.js +4 -1
- package/dist/shared/schemas/tasks-api.schema.d.ts +39 -0
- package/dist/shared/schemas/tasks-api.schema.js +5 -0
- package/dist/shared/schemas/timers-api.schema.d.ts +119 -0
- package/dist/shared/schemas/timers-api.schema.js +44 -0
- package/dist/shared/schemas/views-api.schema.d.ts +16 -0
- package/dist/shared/schemas/views-api.schema.js +4 -2
- package/dist/src/agent-api/attachments.d.ts +2 -0
- package/dist/src/agent-api/attachments.js +96 -0
- package/dist/src/agent-api/documents.d.ts +3 -0
- package/dist/src/agent-api/documents.js +42 -0
- package/dist/src/agent-api/files.d.ts +35 -0
- package/dist/src/agent-api/files.js +86 -0
- package/dist/src/agent-api/history.d.ts +3 -0
- package/dist/src/agent-api/history.js +103 -0
- package/dist/src/agent-api/notes.d.ts +3 -0
- package/dist/src/agent-api/notes.js +39 -0
- package/dist/src/agent-api/requests.js +2 -1
- package/dist/src/agent-api/router.d.ts +2 -2
- package/dist/src/agent-api/router.js +9 -4
- package/dist/src/agent-api/tasks.js +13 -5
- package/dist/src/agent-api/timers.d.ts +2 -0
- package/dist/src/agent-api/timers.js +170 -0
- package/dist/src/agent-api/types.d.ts +7 -2
- package/dist/src/agent-api/views.js +15 -30
- package/dist/src/cli/backup.js +3 -3
- package/dist/src/core/accounts.d.ts +12 -5
- package/dist/src/core/accounts.js +28 -10
- package/dist/src/core/agent-files.d.ts +41 -0
- package/dist/src/core/agent-files.js +102 -0
- package/dist/src/core/agent.d.ts +29 -3
- package/dist/src/core/agent.js +129 -1
- package/dist/src/core/attachments.d.ts +6 -3
- package/dist/src/core/attachments.js +9 -4
- package/dist/src/core/board-views.js +4 -4
- package/dist/src/core/document-text.d.ts +18 -0
- package/dist/src/core/document-text.js +119 -0
- package/dist/src/core/documents.d.ts +22 -0
- package/dist/src/core/documents.js +167 -0
- package/dist/src/core/history-events.d.ts +34 -0
- package/dist/src/core/history-events.js +236 -0
- package/dist/src/core/history.d.ts +3 -1
- package/dist/src/core/history.js +59 -12
- package/dist/src/core/migrations.js +153 -0
- package/dist/src/core/notes.d.ts +23 -0
- package/dist/src/core/notes.js +78 -0
- package/dist/src/core/notifications.d.ts +48 -5
- package/dist/src/core/notifications.js +209 -33
- package/dist/src/core/password-reset.d.ts +37 -0
- package/dist/src/core/password-reset.js +56 -0
- package/dist/src/core/requests.d.ts +13 -7
- package/dist/src/core/requests.js +26 -14
- package/dist/src/core/snapshots.d.ts +3 -3
- package/dist/src/core/snapshots.js +5 -1
- package/dist/src/core/space-history.d.ts +18 -0
- package/dist/src/core/space-history.js +86 -0
- package/dist/src/core/spaces.d.ts +1 -1
- package/dist/src/core/spaces.js +4 -4
- package/dist/src/core/store.d.ts +154 -11
- package/dist/src/core/store.js +479 -52
- package/dist/src/core/task-history.d.ts +9 -5
- package/dist/src/core/task-history.js +17 -25
- package/dist/src/core/tasks.d.ts +2 -2
- package/dist/src/core/tasks.js +13 -2
- package/dist/src/core/timers.d.ts +33 -0
- package/dist/src/core/timers.js +101 -0
- package/dist/src/core/versions.d.ts +22 -0
- package/dist/src/core/versions.js +106 -0
- package/dist/src/gui-api.d.ts +4 -1
- package/dist/src/gui-api.js +87 -8
- package/dist/src/mcp/client.d.ts +7 -4
- package/dist/src/mcp/client.js +31 -4
- package/dist/src/mcp/start.d.ts +1 -1
- package/dist/src/mcp/start.js +14 -9
- package/dist/src/mcp/tools.d.ts +11 -0
- package/dist/src/mcp/tools.js +182 -5
- package/dist/src/mcp/upload.d.ts +22 -0
- package/dist/src/mcp/upload.js +79 -0
- package/dist/src/server/app.d.ts +4 -2
- package/dist/src/server/app.js +58 -8
- package/dist/src/server/login-limiter.d.ts +27 -1
- package/dist/src/server/login-limiter.js +31 -1
- package/dist/src/server/start.js +1 -0
- package/gui/dist/assets/index-C1f7hOcM.js +104 -0
- package/gui/dist/assets/index-CfMiwPSL.css +1 -0
- package/gui/dist/index.html +2 -2
- package/package.json +3 -1
- package/gui/dist/assets/index-9c9BlfUi.js +0 -99
- package/gui/dist/assets/index-DH23A5aa.css +0 -1
package/dist/src/core/agent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Actor, Mutation, Store } from "./store.js";
|
|
2
|
-
import type { AgentAction, AgentRequest, Comment, Idea, Space, Task, TaskSnapshot, User } from "../../shared/schemas/entities.schema.js";
|
|
3
|
-
import type { AgentIdea, AgentMember, AgentRequestSummary, AgentSpace, AgentTaskSummary } from "../../shared/schemas/agent-tools.schema.js";
|
|
2
|
+
import type { AgentAction, AgentRequest, Comment, Idea, Note, Space, SpaceDocument, Task, TaskSnapshot, User } from "../../shared/schemas/entities.schema.js";
|
|
3
|
+
import type { AgentDocument, AgentIdea, AgentMember, AgentNote, AgentRequestSummary, AgentSpace, AgentTaskSummary } from "../../shared/schemas/agent-tools.schema.js";
|
|
4
4
|
import type { ResolvedAgentToken } from "./agent-tokens.js";
|
|
5
5
|
/**
|
|
6
6
|
* Logique de l'API agent : agent appelant (jeton résolu), demande pour
|
|
@@ -32,6 +32,16 @@ export declare function actingRequest(store: Store, agent: AgentCaller, requestI
|
|
|
32
32
|
request: AgentRequest;
|
|
33
33
|
space: Space;
|
|
34
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Auteur de la demande, membre de l'espace : celui dont l'agent règle les
|
|
37
|
+
* éléments personnels (`what` : ses vues, ses chronos). Seuls le runner du
|
|
38
|
+
* site et un jeton de l'auteur lui-même y ont accès. Sans demande, c'est le
|
|
39
|
+
* propriétaire du jeton ; le runner n'agit pas sans demande.
|
|
40
|
+
*/
|
|
41
|
+
export declare function requestAuthor(store: Store, agent: AgentCaller, requestId: string | undefined, what: "views" | "timers"): {
|
|
42
|
+
author: User;
|
|
43
|
+
space: Space;
|
|
44
|
+
};
|
|
35
45
|
export declare function userLabel(user: User): string;
|
|
36
46
|
export declare function taskKey(store: Store, task: Task): string;
|
|
37
47
|
/**
|
|
@@ -44,6 +54,10 @@ export declare function actionTaskKey(store: Store, action: AgentAction): string
|
|
|
44
54
|
export declare function resolveTask(store: Store, space: Space, ref: string): Task;
|
|
45
55
|
/** Idée de l'espace. */
|
|
46
56
|
export declare function resolveIdea(store: Store, space: Space, ideaId: string): Idea;
|
|
57
|
+
/** Note de l'espace désignée par son identifiant, son lien `#/notes/<id>` ou une adresse qui le contient. */
|
|
58
|
+
export declare function resolveNote(store: Store, space: Space, ref: string): Note;
|
|
59
|
+
/** Document de l'espace désigné par son identifiant ou son nom de fichier (sans tenir compte de la casse). */
|
|
60
|
+
export declare function resolveDocument(store: Store, space: Space, ref: string): SpaceDocument;
|
|
47
61
|
/** Membres de l'espace désignés par leur identifiant ou leur adresse e-mail. */
|
|
48
62
|
export declare function resolveMembers(store: Store, space: Space, refs: readonly string[]): User[];
|
|
49
63
|
/** Arborescence de l'espace : chaque tâche puis ses sous-tâches, par colonne et rang. */
|
|
@@ -65,17 +79,29 @@ export declare function requestThread(store: Store, request: AgentRequest): Comm
|
|
|
65
79
|
export declare function previousSuites(store: Store, origin: AgentRequest, request: AgentRequest): AgentRequest[];
|
|
66
80
|
/** Contexte complet d'une demande, renvoyé par claim_request. */
|
|
67
81
|
export declare function requestContext(store: Store, agent: AgentCaller, request: AgentRequest): string;
|
|
82
|
+
/** Pièces jointes d'une tâche, avec la façon de les ouvrir ; aucune ligne pour une tâche sans pièce jointe. */
|
|
83
|
+
export declare function attachmentLines(store: Store, task: Task): string[];
|
|
68
84
|
/** Instructions personnalisées de l'agent pour une demande de l'espace : celles du site, puis celles de l'espace. */
|
|
69
85
|
export declare function instructionLines(store: Store, space: Space): string[];
|
|
70
86
|
/** Idées actives récentes de la boîte à idées d'un espace. */
|
|
71
87
|
export declare function recentIdeas(store: Store, space: Space): Idea[];
|
|
72
|
-
/**
|
|
88
|
+
/** Taille lisible d'un nombre d'octets, pour l'agent. */
|
|
89
|
+
export declare function byteSize(bytes: number): string;
|
|
90
|
+
/** Ligne d'un document : identifiant, nom, format, taille, version et description. */
|
|
91
|
+
export declare function documentLine(store: Store, document: SpaceDocument): string;
|
|
92
|
+
/** Documents de référence d'un espace, pour claim_request et get_context. */
|
|
93
|
+
export declare function documentContextLines(store: Store, space: Space): string[];
|
|
94
|
+
/** Arbre des tâches, membres, idées récentes et documents d'un espace, pour claim_request et get_context. */
|
|
73
95
|
export declare function spaceContextLines(store: Store, space: Space): string[];
|
|
74
96
|
export declare function spaceData(space: Space): AgentSpace;
|
|
75
97
|
export declare function memberData(store: Store, space: Space): AgentMember[];
|
|
76
98
|
export declare function taskData(store: Store, task: Task): AgentTaskSummary;
|
|
77
99
|
/** Tâches d'un espace dans l'ordre de l'arbre : chaque tâche puis ses sous-tâches, par colonne et rang. */
|
|
78
100
|
export declare function treeData(store: Store, space: Space): AgentTaskSummary[];
|
|
101
|
+
/** Notes de l'espace référencées par le texte d'une demande, en entier ; une référence hors de l'espace ou introuvable est signalée. */
|
|
102
|
+
export declare function referencedNoteLines(store: Store, space: Space, text: string): string[];
|
|
103
|
+
export declare function noteData(store: Store, note: Note): AgentNote;
|
|
104
|
+
export declare function documentData(store: Store, document: SpaceDocument): AgentDocument;
|
|
79
105
|
export declare function ideaData(store: Store, idea: Idea): AgentIdea;
|
|
80
106
|
export declare function requestData(store: Store, agent: AgentCaller, request: AgentRequest): AgentRequestSummary;
|
|
81
107
|
export declare function quote(text: string, max?: number): string;
|
package/dist/src/core/agent.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ForbiddenError, InvariantError, NotFoundError, OrganizerError } from "./errors.js";
|
|
2
2
|
import { taskIdOfAction } from "./snapshots.js";
|
|
3
|
+
import { noteHash, noteIdOf, noteIdsIn } from "../../shared/logic/notes.js";
|
|
4
|
+
import { documentFormatOf } from "../../shared/logic/documents.js";
|
|
3
5
|
import { PRIORITY_LABELS, STATUS_LABELS, TYPE_LABELS } from "../../shared/logic/labels.js";
|
|
4
6
|
import { summarizeTest } from "../../shared/logic/test-summary.js";
|
|
5
7
|
export function agentActor(agent, requestId) {
|
|
@@ -65,6 +67,28 @@ export function actingRequest(store, agent, requestId) {
|
|
|
65
67
|
}
|
|
66
68
|
return { request, space };
|
|
67
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Auteur de la demande, membre de l'espace : celui dont l'agent règle les
|
|
72
|
+
* éléments personnels (`what` : ses vues, ses chronos). Seuls le runner du
|
|
73
|
+
* site et un jeton de l'auteur lui-même y ont accès. Sans demande, c'est le
|
|
74
|
+
* propriétaire du jeton ; le runner n'agit pas sans demande.
|
|
75
|
+
*/
|
|
76
|
+
export function requestAuthor(store, agent, requestId, what) {
|
|
77
|
+
if (requestId === undefined) {
|
|
78
|
+
if (agent.token.isRunner)
|
|
79
|
+
throw new ForbiddenError("The site runner acts only for the requests it claims: pass the request_id of the request you process.");
|
|
80
|
+
return { author: agent.user, space: directSpace(store, agent) };
|
|
81
|
+
}
|
|
82
|
+
const { request, space } = actingRequest(store, agent, requestId);
|
|
83
|
+
const author = store.getUser(request.authorId);
|
|
84
|
+
if (!agent.token.isRunner && agent.token.userId !== author.id) {
|
|
85
|
+
throw new ForbiddenError(`Request ${requestId} was written by ${userLabel(author)}, not by the owner of your token: only their own agent or the site runner can read or change their ${what}. Tell them so in your reply.`);
|
|
86
|
+
}
|
|
87
|
+
if (!store.isMember(space.id, author.id)) {
|
|
88
|
+
throw new ForbiddenError(`${userLabel(author)}, the author of request ${requestId}, is no longer a member of "${space.name}": their ${what} cannot be changed.`);
|
|
89
|
+
}
|
|
90
|
+
return { author, space };
|
|
91
|
+
}
|
|
68
92
|
// --- Noms et identifiants ---------------------------------------------------------
|
|
69
93
|
export function userLabel(user) {
|
|
70
94
|
return user.displayName ?? user.email;
|
|
@@ -119,6 +143,30 @@ export function resolveIdea(store, space, ideaId) {
|
|
|
119
143
|
throw new ForbiddenError(`Idea ${ideaId} is not in your space "${space.name}". You can only act in this space.`);
|
|
120
144
|
return idea;
|
|
121
145
|
}
|
|
146
|
+
/** Note de l'espace désignée par son identifiant, son lien `#/notes/<id>` ou une adresse qui le contient. */
|
|
147
|
+
export function resolveNote(store, space, ref) {
|
|
148
|
+
const id = noteIdOf(ref);
|
|
149
|
+
const note = store.findNote(id);
|
|
150
|
+
if (!note)
|
|
151
|
+
throw new NotFoundError(`Note ${ref.trim()} not found in "${space.name}". Call search_notes to find it.`);
|
|
152
|
+
if (note.spaceId !== space.id)
|
|
153
|
+
throw new ForbiddenError(`Note ${id} is not in your space "${space.name}". You can only read the notes of this space.`);
|
|
154
|
+
return note;
|
|
155
|
+
}
|
|
156
|
+
/** Document de l'espace désigné par son identifiant ou son nom de fichier (sans tenir compte de la casse). */
|
|
157
|
+
export function resolveDocument(store, space, ref) {
|
|
158
|
+
const trimmed = ref.trim();
|
|
159
|
+
const byId = store.findDocument(trimmed);
|
|
160
|
+
if (byId) {
|
|
161
|
+
if (byId.spaceId !== space.id)
|
|
162
|
+
throw new ForbiddenError(`Document ${trimmed} is not in your space "${space.name}". You can only read the documents of this space.`);
|
|
163
|
+
return byId;
|
|
164
|
+
}
|
|
165
|
+
const byName = store.listDocuments(space.id).find((document) => document.filename.toLowerCase() === trimmed.toLowerCase());
|
|
166
|
+
if (!byName)
|
|
167
|
+
throw new NotFoundError(`Document ${trimmed} not found in "${space.name}". Call list_documents to find it.`);
|
|
168
|
+
return byName;
|
|
169
|
+
}
|
|
122
170
|
/** Membres de l'espace désignés par leur identifiant ou leur adresse e-mail. */
|
|
123
171
|
export function resolveMembers(store, space, refs) {
|
|
124
172
|
return refs.map((ref) => {
|
|
@@ -296,6 +344,8 @@ export function requestContext(store, agent, request) {
|
|
|
296
344
|
if (task) {
|
|
297
345
|
const space = store.getSpace(task.spaceId);
|
|
298
346
|
lines.push(`Context task: ${space.keyPrefix}-${task.number} "${task.title}" [${task.status}, ${task.priority}${task.type === "test" ? ", test" : ""}] (id ${task.id})${space.id !== target.id ? ` in space "${space.name}" (out of your reach)` : ""}.`);
|
|
347
|
+
if (space.id === target.id)
|
|
348
|
+
lines.push(...attachmentLines(store, task));
|
|
299
349
|
if (task.type === "test" && request.kind === "test_review") {
|
|
300
350
|
const checkpoints = store.listCheckpoints(task.id);
|
|
301
351
|
const results = store.listTestResults(task.id).filter((result) => result.testerId === request.authorId);
|
|
@@ -313,6 +363,7 @@ export function requestContext(store, agent, request) {
|
|
|
313
363
|
if (idea)
|
|
314
364
|
lines.push(`Context idea: ${idea.id} "${idea.text}".`);
|
|
315
365
|
}
|
|
366
|
+
lines.push(...referencedNoteLines(store, target, request.text));
|
|
316
367
|
const origin = request.parentRequestId === null ? null : store.findAgentRequest(request.parentRequestId);
|
|
317
368
|
if (origin)
|
|
318
369
|
lines.push(...originLines(store, origin, request));
|
|
@@ -330,6 +381,16 @@ export function requestContext(store, agent, request) {
|
|
|
330
381
|
lines.push("", "Next: read with get_task / search_tasks, act with the write tools (pass this request_id), then call complete_request with a short reply in the author's language, and follow_ups for what the author still has to do.");
|
|
331
382
|
return lines.join("\n");
|
|
332
383
|
}
|
|
384
|
+
/** Pièces jointes d'une tâche, avec la façon de les ouvrir ; aucune ligne pour une tâche sans pièce jointe. */
|
|
385
|
+
export function attachmentLines(store, task) {
|
|
386
|
+
const attachments = store.listAttachments(task.id);
|
|
387
|
+
if (attachments.length === 0)
|
|
388
|
+
return [];
|
|
389
|
+
return [
|
|
390
|
+
`Attachments of ${taskKey(store, task)} — open one with get_attachment (images are shown to you, PDF files come as text) when it helps, for example a screenshot of a failed checkpoint or one cited in a comment:`,
|
|
391
|
+
...attachments.map((attachment) => `- ${attachment.filename} (${attachment.mime}, ${byteSize(attachment.size)}, id ${attachment.id})`),
|
|
392
|
+
];
|
|
393
|
+
}
|
|
333
394
|
/** Instructions personnalisées de l'agent pour une demande de l'espace : celles du site, puis celles de l'espace. */
|
|
334
395
|
export function instructionLines(store, space) {
|
|
335
396
|
const site = store.findAgentInstructions(null);
|
|
@@ -348,7 +409,35 @@ export function recentIdeas(store, space) {
|
|
|
348
409
|
.filter((idea) => idea.archivedAt === null && idea.promotedTaskId === null)
|
|
349
410
|
.slice(0, CONTEXT_IDEAS);
|
|
350
411
|
}
|
|
351
|
-
/**
|
|
412
|
+
/** Nombre maximal de documents cités dans le contexte d'une demande. */
|
|
413
|
+
const CONTEXT_DOCUMENTS = 30;
|
|
414
|
+
/** Taille lisible d'un nombre d'octets, pour l'agent. */
|
|
415
|
+
export function byteSize(bytes) {
|
|
416
|
+
if (bytes < 1024)
|
|
417
|
+
return `${bytes} B`;
|
|
418
|
+
if (bytes < 1024 * 1024)
|
|
419
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
420
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
421
|
+
}
|
|
422
|
+
/** Ligne d'un document : identifiant, nom, format, taille, version et description. */
|
|
423
|
+
export function documentLine(store, document) {
|
|
424
|
+
const data = documentData(store, document);
|
|
425
|
+
const description = data.description.trim().replace(/\s+/g, " ");
|
|
426
|
+
const shown = description.length > 200 ? `${description.slice(0, 200)}…` : description;
|
|
427
|
+
return `- ${data.id} "${data.filename}" (${data.format}, ${byteSize(data.size)}, version ${data.version}, updated ${ago(data.updatedAt)})${shown ? ` — ${shown}` : ""}`;
|
|
428
|
+
}
|
|
429
|
+
/** Documents de référence d'un espace, pour claim_request et get_context. */
|
|
430
|
+
export function documentContextLines(store, space) {
|
|
431
|
+
const documents = store.listDocuments(space.id);
|
|
432
|
+
const lines = ["", "Reference documents of the space (read one with get_document when it helps the request):"];
|
|
433
|
+
if (documents.length === 0)
|
|
434
|
+
return [...lines, "(none)"];
|
|
435
|
+
lines.push(...documents.slice(0, CONTEXT_DOCUMENTS).map((document) => documentLine(store, document)));
|
|
436
|
+
if (documents.length > CONTEXT_DOCUMENTS)
|
|
437
|
+
lines.push(`(${documents.length - CONTEXT_DOCUMENTS} more: call list_documents)`);
|
|
438
|
+
return lines;
|
|
439
|
+
}
|
|
440
|
+
/** Arbre des tâches, membres, idées récentes et documents d'un espace, pour claim_request et get_context. */
|
|
352
441
|
export function spaceContextLines(store, space) {
|
|
353
442
|
const lines = [];
|
|
354
443
|
const tree = spaceTree(store, space);
|
|
@@ -358,6 +447,7 @@ export function spaceContextLines(store, space) {
|
|
|
358
447
|
const ideas = recentIdeas(store, space);
|
|
359
448
|
lines.push("", "Recent ideas in the idea box:");
|
|
360
449
|
lines.push(...(ideas.length > 0 ? ideas.map((idea) => `- ${idea.id}: "${idea.text.trim().replace(/\s+/g, " ")}" (${ago(idea.createdAt)})`) : ["(none)"]));
|
|
450
|
+
lines.push(...documentContextLines(store, space));
|
|
361
451
|
return lines;
|
|
362
452
|
}
|
|
363
453
|
// --- Données structurées des réponses -----------------------------------------------
|
|
@@ -406,6 +496,44 @@ export function treeData(store, space) {
|
|
|
406
496
|
walk(null);
|
|
407
497
|
return ordered;
|
|
408
498
|
}
|
|
499
|
+
/** Notes de l'espace référencées par le texte d'une demande, en entier ; une référence hors de l'espace ou introuvable est signalée. */
|
|
500
|
+
export function referencedNoteLines(store, space, text) {
|
|
501
|
+
const lines = [];
|
|
502
|
+
for (const id of noteIdsIn(text)) {
|
|
503
|
+
const note = store.findNote(id);
|
|
504
|
+
if (!note || note.spaceId !== space.id) {
|
|
505
|
+
lines.push("", `Referenced note ${id}: not found in "${space.name}".`);
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
lines.push("", `Referenced note ${note.id} "${note.title}" (by ${userNameOf(store, note.authorId)}, updated ${ago(note.updatedAt)}):`, note.body.trim() === "" ? "(empty)" : note.body);
|
|
509
|
+
}
|
|
510
|
+
return lines;
|
|
511
|
+
}
|
|
512
|
+
function userNameOf(store, userId) {
|
|
513
|
+
const user = store.findUser(userId);
|
|
514
|
+
return user ? userLabel(user) : "a former member";
|
|
515
|
+
}
|
|
516
|
+
export function noteData(store, note) {
|
|
517
|
+
return { id: note.id, title: note.title, link: noteHash(note.id), authorName: userNameOf(store, note.authorId), createdAt: note.createdAt, updatedAt: note.updatedAt };
|
|
518
|
+
}
|
|
519
|
+
export function documentData(store, document) {
|
|
520
|
+
const format = documentFormatOf(document.filename);
|
|
521
|
+
if (!format)
|
|
522
|
+
throw new Error(`Document ${document.id} has an unsupported file name: ${document.filename}.`);
|
|
523
|
+
return {
|
|
524
|
+
id: document.id,
|
|
525
|
+
filename: document.filename,
|
|
526
|
+
description: document.description,
|
|
527
|
+
format: format.label,
|
|
528
|
+
mime: document.mime,
|
|
529
|
+
size: document.size,
|
|
530
|
+
version: document.version,
|
|
531
|
+
uploadedBy: userNameOf(store, document.uploaderId),
|
|
532
|
+
updatedBy: userNameOf(store, document.updatedBy),
|
|
533
|
+
createdAt: document.createdAt,
|
|
534
|
+
updatedAt: document.updatedAt,
|
|
535
|
+
};
|
|
536
|
+
}
|
|
409
537
|
export function ideaData(store, idea) {
|
|
410
538
|
const promoted = idea.promotedTaskId === null ? null : store.findTask(idea.promotedTaskId);
|
|
411
539
|
return { id: idea.id, text: idea.text, archived: idea.archivedAt !== null, promotedTaskKey: promoted ? taskKey(store, promoted) : null, createdAt: idea.createdAt };
|
|
@@ -2,8 +2,9 @@ import type { Attachment } from "../../shared/schemas/entities.schema.js";
|
|
|
2
2
|
/** Sous-répertoire des pièces jointes dans le répertoire de données. */
|
|
3
3
|
export declare const ATTACHMENTS_DIRNAME = "attachments";
|
|
4
4
|
/**
|
|
5
|
-
* Fichiers des pièces jointes, rangés sous
|
|
6
|
-
* base enregistre le chemin relatif au
|
|
5
|
+
* Fichiers des pièces jointes et des documents d'espace, rangés sous
|
|
6
|
+
* `<dataDir>/attachments/<id>`. La base enregistre le chemin relatif au
|
|
7
|
+
* répertoire de données.
|
|
7
8
|
*/
|
|
8
9
|
export declare class AttachmentStorage {
|
|
9
10
|
readonly dataDir: string;
|
|
@@ -14,8 +15,10 @@ export declare class AttachmentStorage {
|
|
|
14
15
|
/** Écrit le contenu d'une pièce jointe et renvoie son chemin relatif. */
|
|
15
16
|
write(id: string, content: Buffer): string;
|
|
16
17
|
read(attachment: Attachment): Buffer;
|
|
18
|
+
/** Contenu du fichier rangé au chemin relatif `storagePath`. */
|
|
19
|
+
readPath(storagePath: string): Buffer;
|
|
17
20
|
/** Vrai si le fichier d'une pièce jointe existe. */
|
|
18
21
|
exists(storagePath: string): boolean;
|
|
19
|
-
/** Efface les fichiers
|
|
22
|
+
/** Efface les fichiers supprimés de la base ; un fichier déjà absent est ignoré. */
|
|
20
23
|
remove(storagePaths: readonly string[]): void;
|
|
21
24
|
}
|
|
@@ -3,8 +3,9 @@ import path from "node:path";
|
|
|
3
3
|
/** Sous-répertoire des pièces jointes dans le répertoire de données. */
|
|
4
4
|
export const ATTACHMENTS_DIRNAME = "attachments";
|
|
5
5
|
/**
|
|
6
|
-
* Fichiers des pièces jointes, rangés sous
|
|
7
|
-
* base enregistre le chemin relatif au
|
|
6
|
+
* Fichiers des pièces jointes et des documents d'espace, rangés sous
|
|
7
|
+
* `<dataDir>/attachments/<id>`. La base enregistre le chemin relatif au
|
|
8
|
+
* répertoire de données.
|
|
8
9
|
*/
|
|
9
10
|
export class AttachmentStorage {
|
|
10
11
|
dataDir;
|
|
@@ -30,13 +31,17 @@ export class AttachmentStorage {
|
|
|
30
31
|
return storagePath;
|
|
31
32
|
}
|
|
32
33
|
read(attachment) {
|
|
33
|
-
return
|
|
34
|
+
return this.readPath(attachment.storagePath);
|
|
35
|
+
}
|
|
36
|
+
/** Contenu du fichier rangé au chemin relatif `storagePath`. */
|
|
37
|
+
readPath(storagePath) {
|
|
38
|
+
return fs.readFileSync(this.absolute(storagePath));
|
|
34
39
|
}
|
|
35
40
|
/** Vrai si le fichier d'une pièce jointe existe. */
|
|
36
41
|
exists(storagePath) {
|
|
37
42
|
return fs.existsSync(this.absolute(storagePath));
|
|
38
43
|
}
|
|
39
|
-
/** Efface les fichiers
|
|
44
|
+
/** Efface les fichiers supprimés de la base ; un fichier déjà absent est ignoré. */
|
|
40
45
|
remove(storagePaths) {
|
|
41
46
|
for (const storagePath of storagePaths)
|
|
42
47
|
fs.rmSync(this.absolute(storagePath), { force: true });
|
|
@@ -8,12 +8,12 @@ import { requireMember } from "./spaces.js";
|
|
|
8
8
|
const asUser = (userId) => ({ type: "user", userId });
|
|
9
9
|
/** Vues créées pour un membre qui n'en a aucune : le Kanban et la liste par statut, sans filtre. */
|
|
10
10
|
export const DEFAULT_BOARD_VIEWS = [
|
|
11
|
-
{ name: "Tableau", layout: "kanban", groupBy: "status", thenBy: "none", showEmptyGroups: true, statuses: [], priorities: [], assigneeIds: [], unassigned: false, tagIds: [] },
|
|
12
|
-
{ name: "Liste", layout: "list", groupBy: "status", thenBy: "none", showEmptyGroups: false, statuses: [], priorities: [], assigneeIds: [], unassigned: false, tagIds: [] },
|
|
11
|
+
{ name: "Tableau", layout: "kanban", groupBy: "status", thenBy: "none", showEmptyGroups: true, statuses: [], priorities: [], assigneeIds: [], unassigned: false, tagIds: [], types: [] },
|
|
12
|
+
{ name: "Liste", layout: "list", groupBy: "status", thenBy: "none", showEmptyGroups: false, statuses: [], priorities: [], assigneeIds: [], unassigned: false, tagIds: [], types: [] },
|
|
13
13
|
];
|
|
14
14
|
function viewOf(view) {
|
|
15
|
-
const { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds } = view;
|
|
16
|
-
return { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds };
|
|
15
|
+
const { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds, types } = view;
|
|
16
|
+
return { id, name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds, types };
|
|
17
17
|
}
|
|
18
18
|
/** Assignés d'une vue : des membres de l'espace. */
|
|
19
19
|
function requireAssignees(store, spaceId, assigneeIds) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OrganizerError } from "./errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Texte d'un document pour l'agent : le contenu d'un fichier texte décodé en
|
|
4
|
+
* UTF-8, ou le texte des paragraphes d'un fichier Word (.docx), lu dans
|
|
5
|
+
* l'archive sans dépendance. Le texte d'un PDF et les images se lisent de
|
|
6
|
+
* façon asynchrone (voir `agent-files.ts`).
|
|
7
|
+
*/
|
|
8
|
+
/** Longueur d'une partie d'un document lu par morceaux, en caractères. */
|
|
9
|
+
export declare const DOCUMENT_PART_LENGTH = 20000;
|
|
10
|
+
/** Erreur d'un fichier dont le texte ne se lit pas ; `message` est en français, pour le membre qui dépose le fichier. */
|
|
11
|
+
export declare class DocumentTextError extends OrganizerError {
|
|
12
|
+
}
|
|
13
|
+
/** Contenu décompressé d'une entrée d'une archive zip, ou null si l'archive ne la contient pas. */
|
|
14
|
+
export declare function readZipEntry(archive: Buffer, entryName: string): Buffer | null;
|
|
15
|
+
/** Texte d'un fichier texte ou Word ; null pour un PDF ou une image. */
|
|
16
|
+
export declare function documentText(filename: string, content: Buffer): string | null;
|
|
17
|
+
/** Découpe un texte en parties d'au plus `size` caractères, coupées de préférence en fin de ligne. */
|
|
18
|
+
export declare function splitParts(text: string, size?: number): string[];
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { inflateRawSync } from "node:zlib";
|
|
2
|
+
import { documentFormatOf } from "../../shared/logic/documents.js";
|
|
3
|
+
import { OrganizerError } from "./errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* Texte d'un document pour l'agent : le contenu d'un fichier texte décodé en
|
|
6
|
+
* UTF-8, ou le texte des paragraphes d'un fichier Word (.docx), lu dans
|
|
7
|
+
* l'archive sans dépendance. Le texte d'un PDF et les images se lisent de
|
|
8
|
+
* façon asynchrone (voir `agent-files.ts`).
|
|
9
|
+
*/
|
|
10
|
+
/** Longueur d'une partie d'un document lu par morceaux, en caractères. */
|
|
11
|
+
export const DOCUMENT_PART_LENGTH = 20_000;
|
|
12
|
+
/** Erreur d'un fichier dont le texte ne se lit pas ; `message` est en français, pour le membre qui dépose le fichier. */
|
|
13
|
+
export class DocumentTextError extends OrganizerError {
|
|
14
|
+
}
|
|
15
|
+
/** Texte d'un fichier texte encodé en UTF-8, sans marque d'ordre des octets. */
|
|
16
|
+
function decodeUtf8(content) {
|
|
17
|
+
try {
|
|
18
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(content);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw new DocumentTextError("Le fichier n'est pas un texte encodé en UTF-8 : réenregistrez-le en UTF-8, puis déposez-le de nouveau.");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Contenu décompressé d'une entrée d'une archive zip, ou null si l'archive ne la contient pas. */
|
|
25
|
+
export function readZipEntry(archive, entryName) {
|
|
26
|
+
const invalid = () => new DocumentTextError("Le fichier Word est illisible (archive invalide) : ouvrez-le dans Word, enregistrez-le de nouveau en .docx, puis déposez-le.");
|
|
27
|
+
const END_SIGNATURE = 0x06054b50;
|
|
28
|
+
let end = -1;
|
|
29
|
+
for (let at = archive.length - 22; at >= Math.max(0, archive.length - 22 - 0xffff); at--) {
|
|
30
|
+
if (archive.readUInt32LE(at) === END_SIGNATURE) {
|
|
31
|
+
end = at;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (end < 0)
|
|
36
|
+
throw invalid();
|
|
37
|
+
const count = archive.readUInt16LE(end + 10);
|
|
38
|
+
let at = archive.readUInt32LE(end + 16);
|
|
39
|
+
for (let index = 0; index < count; index++) {
|
|
40
|
+
if (at + 46 > archive.length || archive.readUInt32LE(at) !== 0x02014b50)
|
|
41
|
+
throw invalid();
|
|
42
|
+
const method = archive.readUInt16LE(at + 10);
|
|
43
|
+
const compressedSize = archive.readUInt32LE(at + 20);
|
|
44
|
+
const nameLength = archive.readUInt16LE(at + 28);
|
|
45
|
+
const extraLength = archive.readUInt16LE(at + 30);
|
|
46
|
+
const commentLength = archive.readUInt16LE(at + 32);
|
|
47
|
+
const localOffset = archive.readUInt32LE(at + 42);
|
|
48
|
+
const name = archive.toString("utf8", at + 46, at + 46 + nameLength);
|
|
49
|
+
at += 46 + nameLength + extraLength + commentLength;
|
|
50
|
+
if (name !== entryName)
|
|
51
|
+
continue;
|
|
52
|
+
if (localOffset + 30 > archive.length || archive.readUInt32LE(localOffset) !== 0x04034b50)
|
|
53
|
+
throw invalid();
|
|
54
|
+
const dataStart = localOffset + 30 + archive.readUInt16LE(localOffset + 26) + archive.readUInt16LE(localOffset + 28);
|
|
55
|
+
const data = archive.subarray(dataStart, dataStart + compressedSize);
|
|
56
|
+
if (method === 0)
|
|
57
|
+
return data;
|
|
58
|
+
if (method !== 8)
|
|
59
|
+
throw invalid();
|
|
60
|
+
try {
|
|
61
|
+
return inflateRawSync(data);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
throw invalid();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const XML_ENTITIES = { lt: "<", gt: ">", amp: "&", quot: '"', apos: "'" };
|
|
70
|
+
function decodeXml(text) {
|
|
71
|
+
return text.replace(/&(#x[0-9a-fA-F]+|#\d+|lt|gt|amp|quot|apos);/g, (_, entity) => {
|
|
72
|
+
if (entity.startsWith("#x"))
|
|
73
|
+
return String.fromCodePoint(parseInt(entity.slice(2), 16));
|
|
74
|
+
if (entity.startsWith("#"))
|
|
75
|
+
return String.fromCodePoint(parseInt(entity.slice(1), 10));
|
|
76
|
+
return XML_ENTITIES[entity];
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** Texte du corps d'un fichier Word : un paragraphe par ligne, tabulations et sauts de ligne conservés. */
|
|
80
|
+
function docxText(content) {
|
|
81
|
+
const xml = readZipEntry(content, "word/document.xml");
|
|
82
|
+
if (!xml)
|
|
83
|
+
throw new DocumentTextError("Le fichier n'est pas un document Word (.docx) : il ne contient pas de texte Word.");
|
|
84
|
+
const parts = [];
|
|
85
|
+
for (const match of xml.toString("utf8").matchAll(/<w:t(?:\s[^>]*)?>([^<]*)<\/w:t>|<w:tab\/>|<w:(?:br|cr)(?:\s[^>]*)?\/>|<\/w:p>/g)) {
|
|
86
|
+
if (match[1] !== undefined)
|
|
87
|
+
parts.push(decodeXml(match[1]));
|
|
88
|
+
else if (match[0] === "<w:tab/>")
|
|
89
|
+
parts.push("\t");
|
|
90
|
+
else
|
|
91
|
+
parts.push("\n");
|
|
92
|
+
}
|
|
93
|
+
return parts.join("").replace(/\n{3,}/g, "\n\n").trim();
|
|
94
|
+
}
|
|
95
|
+
/** Texte d'un fichier texte ou Word ; null pour un PDF ou une image. */
|
|
96
|
+
export function documentText(filename, content) {
|
|
97
|
+
const format = documentFormatOf(filename);
|
|
98
|
+
if (!format)
|
|
99
|
+
throw new DocumentTextError(`Format de fichier non pris en charge : ${filename}.`);
|
|
100
|
+
if (format.reading === "text")
|
|
101
|
+
return decodeUtf8(content);
|
|
102
|
+
if (format.reading === "docx")
|
|
103
|
+
return docxText(content);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
/** Découpe un texte en parties d'au plus `size` caractères, coupées de préférence en fin de ligne. */
|
|
107
|
+
export function splitParts(text, size = DOCUMENT_PART_LENGTH) {
|
|
108
|
+
const parts = [];
|
|
109
|
+
let start = 0;
|
|
110
|
+
while (text.length - start > size) {
|
|
111
|
+
const window = text.slice(start, start + size);
|
|
112
|
+
const newline = window.lastIndexOf("\n");
|
|
113
|
+
const cut = newline > size / 2 ? newline + 1 : size;
|
|
114
|
+
parts.push(text.slice(start, start + cut));
|
|
115
|
+
start += cut;
|
|
116
|
+
}
|
|
117
|
+
parts.push(text.slice(start));
|
|
118
|
+
return parts;
|
|
119
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AttachmentStorage } from "./attachments.js";
|
|
2
|
+
import type { Store } from "./store.js";
|
|
3
|
+
import { type DocumentListResponse, type DocumentView, type UpdateDocumentRequest } from "../../shared/schemas/documents-api.schema.js";
|
|
4
|
+
import type { UploadAttachmentRequest } from "../../shared/schemas/tasks-api.schema.js";
|
|
5
|
+
import type { ApiFile } from "../../shared/schemas/gui-api.schema.js";
|
|
6
|
+
/** Documents de l'espace, du plus récemment modifié au plus ancien, avec le volume occupé. */
|
|
7
|
+
export declare function listDocuments(store: Store, userId: string, spaceId: string): DocumentListResponse;
|
|
8
|
+
/**
|
|
9
|
+
* Dépose un document : le fichier est écrit, puis le document est créé en
|
|
10
|
+
* base après vérification des droits, du nom et du quota dans la même
|
|
11
|
+
* transaction. Un refus efface le fichier écrit.
|
|
12
|
+
*/
|
|
13
|
+
export declare function uploadDocument(store: Store, storage: AttachmentStorage, userId: string, spaceId: string, input: UploadAttachmentRequest): DocumentView;
|
|
14
|
+
/**
|
|
15
|
+
* Remplace le fichier d'un document par une nouvelle version : sa description
|
|
16
|
+
* est gardée, sa version incrémentée, l'ancien fichier effacé.
|
|
17
|
+
*/
|
|
18
|
+
export declare function replaceDocument(store: Store, storage: AttachmentStorage, userId: string, documentId: string, input: UploadAttachmentRequest): DocumentView;
|
|
19
|
+
export declare function updateDocument(store: Store, userId: string, documentId: string, patch: UpdateDocumentRequest): DocumentView;
|
|
20
|
+
/** Contenu d'un document, avec son type et son nom. */
|
|
21
|
+
export declare function downloadDocument(store: Store, storage: AttachmentStorage, userId: string, documentId: string): ApiFile;
|
|
22
|
+
export declare function deleteDocument(store: Store, storage: AttachmentStorage, userId: string, documentId: string): void;
|