@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
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { AddAttachmentBodySchema, AttachmentAddedDataSchema, AttachmentDetailDataSchema, GetAttachmentQuerySchema } from "../../shared/schemas/agent-tools.schema.js";
|
|
2
|
+
import { attachmentImageMarkdown } from "../../shared/logic/attachments.js";
|
|
3
|
+
import { actFor, actingRequest, ago, byteSize, directSpace, resolveTask, taskData, taskKey, taskUpdateSummary, userLabel } from "../core/agent.js";
|
|
4
|
+
import { NotFoundError, OrganizerError } from "../core/errors.js";
|
|
5
|
+
import { newId } from "../core/ids.js";
|
|
6
|
+
import { readFile, readingOf } from "./files.js";
|
|
7
|
+
import { parseInput, respond } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Pièces jointes des tâches de l'espace du jeton : lecture (image montrée à
|
|
10
|
+
* l'agent, texte d'un PDF, d'un fichier texte ou Word) et envoi d'un fichier
|
|
11
|
+
* que le mode MCP lit sur sa machine.
|
|
12
|
+
*/
|
|
13
|
+
/** Référence d'une pièce jointe dans un texte : miniature pour une image, nom du fichier sinon. */
|
|
14
|
+
function attachmentReference(filename, mime, id) {
|
|
15
|
+
return mime.toLowerCase().startsWith("image/") ? attachmentImageMarkdown(filename, id) : `\`${filename.replace(/`/g, "'")}\``;
|
|
16
|
+
}
|
|
17
|
+
export const attachmentRoutes = [
|
|
18
|
+
{
|
|
19
|
+
method: "GET",
|
|
20
|
+
path: "/attachments/:id",
|
|
21
|
+
handle: async ({ store, attachments }, { agent, params, query }) => {
|
|
22
|
+
const input = parseInput(GetAttachmentQuerySchema, query);
|
|
23
|
+
const space = agent.space;
|
|
24
|
+
const id = params.id.trim();
|
|
25
|
+
const attachment = store.findAttachment(id);
|
|
26
|
+
const task = attachment ? store.findTask(attachment.taskId) : null;
|
|
27
|
+
if (!attachment || !task || task.spaceId !== space.id) {
|
|
28
|
+
throw new NotFoundError(`Attachment ${id} not found in "${space.name}". Take the id of an attachment from get_task, or from a reference attachment:<id> in a text of a task.`);
|
|
29
|
+
}
|
|
30
|
+
const uploader = store.findUser(attachment.uploaderId);
|
|
31
|
+
const uploadedBy = uploader ? userLabel(uploader) : "a former member";
|
|
32
|
+
const key = taskKey(store, task);
|
|
33
|
+
const header = `Attachment ${attachment.id} "${attachment.filename}" (${attachment.mime}, ${byteSize(attachment.size)}) of task ${key} "${task.title}", uploaded by ${uploadedBy} ${ago(attachment.createdAt)}.`;
|
|
34
|
+
const reading = readingOf(attachment.filename, attachment.mime);
|
|
35
|
+
if (!reading) {
|
|
36
|
+
throw new OrganizerError(`Attachment ${attachment.id} "${attachment.filename}" is a ${attachment.mime} file: get_attachment opens images, PDF files, text files (txt, md, csv, json, yaml, xml…) and Word files (.docx). Rely on its name and on the surrounding text, or ask its author what it contains.`);
|
|
37
|
+
}
|
|
38
|
+
const what = `attachment ${attachment.id} "${attachment.filename}"`;
|
|
39
|
+
const read = await readFile(reading, attachment.filename, attachments.read(attachment), input.part, what, (part) => `get_attachment with part ${part}`);
|
|
40
|
+
const data = {
|
|
41
|
+
attachment: { id: attachment.id, filename: attachment.filename, mime: attachment.mime, size: attachment.size, taskKey: key, uploadedBy, createdAt: attachment.createdAt },
|
|
42
|
+
...read.fields,
|
|
43
|
+
};
|
|
44
|
+
return { ...respond(AttachmentDetailDataSchema, [header, "", ...read.lines].join("\n"), data), images: read.images };
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
method: "POST",
|
|
49
|
+
path: "/tasks/:ref/attachments",
|
|
50
|
+
handle: ({ store, attachments }, { agent, params, body }) => {
|
|
51
|
+
const input = parseInput(AddAttachmentBodySchema, body);
|
|
52
|
+
const comment = input.comment?.trim();
|
|
53
|
+
const content = Buffer.from(input.file.content);
|
|
54
|
+
const { filename, mime } = input.file;
|
|
55
|
+
// Refus avant l'écriture du fichier : demande invalide ou tâche hors de l'espace.
|
|
56
|
+
check(store, agent, input.request_id, params.ref);
|
|
57
|
+
const id = newId();
|
|
58
|
+
const storagePath = attachments.write(id, content);
|
|
59
|
+
try {
|
|
60
|
+
const { task, commentId } = actFor(store, agent, input.request_id, (tx, space) => {
|
|
61
|
+
const task = resolveTask(tx.store, space, params.ref);
|
|
62
|
+
const attachment = tx.createAttachment({ id, taskId: task.id, filename, mime, size: content.length, storagePath });
|
|
63
|
+
tx.recordAgentAction({ entityType: "attachment", entityId: id, operation: "create", before: null, after: attachment, summary: `Pièce jointe ajoutée : ${filename}`, taskId: task.id });
|
|
64
|
+
const reference = attachmentReference(filename, mime, id);
|
|
65
|
+
if (input.append_to_description) {
|
|
66
|
+
const before = tx.store.taskSnapshot(task.id);
|
|
67
|
+
const current = before.description.replace(/\s+$/, "");
|
|
68
|
+
tx.updateTask(task.id, { description: current === "" ? reference : `${current}\n\n${reference}` });
|
|
69
|
+
const after = tx.store.taskSnapshot(task.id);
|
|
70
|
+
tx.recordAgentAction({ entityType: "task", entityId: task.id, operation: "update", before, after, summary: taskUpdateSummary(tx.store, before, after).summary, taskId: task.id });
|
|
71
|
+
}
|
|
72
|
+
let commentId = null;
|
|
73
|
+
if (comment !== undefined && comment !== "") {
|
|
74
|
+
const added = tx.addComment(task.id, `${comment}\n\n${reference}`);
|
|
75
|
+
tx.recordAgentAction({ entityType: "comment", entityId: added.id, operation: "create", before: null, after: added, summary: "Commentaire ajouté", taskId: task.id });
|
|
76
|
+
commentId = added.id;
|
|
77
|
+
}
|
|
78
|
+
return { task, commentId };
|
|
79
|
+
});
|
|
80
|
+
const where = [commentId ? `shown in comment ${commentId}` : null, input.append_to_description ? "referenced at the end of the description" : null].filter((part) => part !== null);
|
|
81
|
+
return respond(AttachmentAddedDataSchema, `Attached "${filename}" (${mime}, ${byteSize(content.length)}) to ${taskKey(store, task)} (attachment id ${id})${where.length > 0 ? `, ${where.join(" and ")}` : ""}.`, { task: taskData(store, store.getTask(task.id)), attachment: { id, filename, mime, size: content.length }, commentId, inDescription: input.append_to_description });
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
attachments.remove([storagePath]);
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
/** Vérifie, sans rien écrire, que l'agent peut écrire pour la demande et que la tâche est dans l'espace du jeton. */
|
|
91
|
+
function check(store, agent, requestId, ref) {
|
|
92
|
+
if (requestId === undefined)
|
|
93
|
+
resolveTask(store, directSpace(store, agent), ref);
|
|
94
|
+
else
|
|
95
|
+
resolveTask(store, actingRequest(store, agent, requestId).space, ref);
|
|
96
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DocumentDetailDataSchema, GetDocumentQuerySchema, ListDocumentsDataSchema, NoQuerySchema } from "../../shared/schemas/agent-tools.schema.js";
|
|
2
|
+
import { documentFormatOf } from "../../shared/logic/documents.js";
|
|
3
|
+
import { ago, byteSize, documentData, documentLine, resolveDocument } from "../core/agent.js";
|
|
4
|
+
import { readFile } from "./files.js";
|
|
5
|
+
import { parseInput, respond } from "./types.js";
|
|
6
|
+
/** Documents de référence de l'espace du jeton, en lecture seule : liste, lecture du texte par parties, image montrée à l'agent. */
|
|
7
|
+
export const documentRoutes = [
|
|
8
|
+
{
|
|
9
|
+
method: "GET",
|
|
10
|
+
path: "/documents",
|
|
11
|
+
handle: ({ store }, { agent, query }) => {
|
|
12
|
+
parseInput(NoQuerySchema, query);
|
|
13
|
+
const space = agent.space;
|
|
14
|
+
const documents = store.listDocuments(space.id);
|
|
15
|
+
if (documents.length === 0)
|
|
16
|
+
return respond(ListDocumentsDataSchema, `No reference document in "${space.name}".`, { documents: [] });
|
|
17
|
+
const lines = documents.map((document) => documentLine(store, document));
|
|
18
|
+
return respond(ListDocumentsDataSchema, `${documents.length} reference document(s) in "${space.name}", most recently updated first:\n${lines.join("\n")}\nRead one with get_document.`, {
|
|
19
|
+
documents: documents.map((document) => documentData(store, document)),
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
method: "GET",
|
|
25
|
+
path: "/documents/:ref",
|
|
26
|
+
handle: async ({ store, attachments }, { agent, params, query }) => {
|
|
27
|
+
const input = parseInput(GetDocumentQuerySchema, query);
|
|
28
|
+
const document = resolveDocument(store, agent.space, params.ref);
|
|
29
|
+
const data = documentData(store, document);
|
|
30
|
+
const format = documentFormatOf(document.filename);
|
|
31
|
+
if (!format)
|
|
32
|
+
throw new Error(`Document ${document.id} has an unsupported file name: ${document.filename}.`);
|
|
33
|
+
const replaced = document.version > 1 ? `, version ${document.version} uploaded by ${data.updatedBy} ${ago(document.updatedAt)}` : `, version 1`;
|
|
34
|
+
const header = [
|
|
35
|
+
`Document ${document.id} "${document.filename}" (${data.format}, ${byteSize(document.size)}), uploaded by ${data.uploadedBy} ${ago(document.createdAt)}${replaced}.`,
|
|
36
|
+
`Description: ${document.description.trim() === "" ? "(none)" : document.description}`,
|
|
37
|
+
];
|
|
38
|
+
const read = await readFile(format.reading, document.filename, attachments.readPath(document.storagePath), input.part, `document ${document.id} "${document.filename}"`, (part) => `get_document with part ${part}`);
|
|
39
|
+
return { ...respond(DocumentDetailDataSchema, [...header, "", ...read.lines].join("\n"), { document: data, ...read.fields }), images: read.images };
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AgentImageContent } from "../../shared/schemas/agent-tools.schema.js";
|
|
2
|
+
import { type DocumentReading } from "../../shared/logic/documents.js";
|
|
3
|
+
/**
|
|
4
|
+
* Lecture d'un fichier par l'agent, commune à get_document et get_attachment :
|
|
5
|
+
* une image jointe à la réponse, le texte d'un PDF, d'un fichier texte ou
|
|
6
|
+
* d'un fichier Word, découpé en parties.
|
|
7
|
+
*/
|
|
8
|
+
/** Contenu lu : texte de la réponse (sans en-tête), données et images à montrer. */
|
|
9
|
+
export interface FileReading {
|
|
10
|
+
lines: string[];
|
|
11
|
+
fields: {
|
|
12
|
+
kind: DocumentReading;
|
|
13
|
+
part: number;
|
|
14
|
+
partCount: number;
|
|
15
|
+
text: string | null;
|
|
16
|
+
image: {
|
|
17
|
+
mimeType: string;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
converted: boolean;
|
|
21
|
+
} | null;
|
|
22
|
+
pdf: {
|
|
23
|
+
pages: number;
|
|
24
|
+
hasText: boolean;
|
|
25
|
+
} | null;
|
|
26
|
+
};
|
|
27
|
+
images: AgentImageContent[];
|
|
28
|
+
}
|
|
29
|
+
/** Façon de lire un fichier d'après son type MIME et son nom ; null pour un format que l'agent n'ouvre pas. */
|
|
30
|
+
export declare function readingOf(filename: string, mime: string): DocumentReading | null;
|
|
31
|
+
/**
|
|
32
|
+
* Lit un fichier : `what` le désigne dans les messages (`document X "nom"`),
|
|
33
|
+
* `next` est l'appel qui lit la partie suivante.
|
|
34
|
+
*/
|
|
35
|
+
export declare function readFile(reading: DocumentReading, filename: string, content: Buffer, part: number, what: string, next: (part: number) => string): Promise<FileReading>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { documentFormatOf } from "../../shared/logic/documents.js";
|
|
2
|
+
import { pdfPagesText, pdfText, prepareImage } from "../core/agent-files.js";
|
|
3
|
+
import { DocumentTextError, documentText, splitParts } from "../core/document-text.js";
|
|
4
|
+
import { OrganizerError } from "../core/errors.js";
|
|
5
|
+
/** Façon de lire un fichier d'après son type MIME et son nom ; null pour un format que l'agent n'ouvre pas. */
|
|
6
|
+
export function readingOf(filename, mime) {
|
|
7
|
+
const normalized = mime.toLowerCase().split(";")[0].trim();
|
|
8
|
+
if (normalized.startsWith("image/"))
|
|
9
|
+
return "image";
|
|
10
|
+
if (normalized === "application/pdf")
|
|
11
|
+
return "pdf";
|
|
12
|
+
return documentFormatOf(filename)?.reading ?? null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Lit un fichier : `what` le désigne dans les messages (`document X "nom"`),
|
|
16
|
+
* `next` est l'appel qui lit la partie suivante.
|
|
17
|
+
*/
|
|
18
|
+
export async function readFile(reading, filename, content, part, what, next) {
|
|
19
|
+
if (reading === "image") {
|
|
20
|
+
if (part !== 1)
|
|
21
|
+
throw new OrganizerError(`${capitalize(what)} is an image: it has a single part, pass part 1.`);
|
|
22
|
+
let image;
|
|
23
|
+
try {
|
|
24
|
+
image = await prepareImage(content);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
if (err instanceof OrganizerError)
|
|
28
|
+
throw new OrganizerError(`The image of ${what} cannot be shown: ${err.message}`);
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
const note = image.converted ? ` It was converted to ${image.width}×${image.height} px (${image.mimeType}) to fit the limits of the Claude API.` : "";
|
|
32
|
+
return {
|
|
33
|
+
lines: [`The image follows (${image.width}×${image.height} px).${note}`],
|
|
34
|
+
fields: { kind: "image", part: 1, partCount: 1, text: null, image: { mimeType: image.mimeType, width: image.width, height: image.height, converted: image.converted }, pdf: null },
|
|
35
|
+
images: [{ data: image.data, mimeType: image.mimeType }],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
let text;
|
|
39
|
+
let pdf = null;
|
|
40
|
+
if (reading === "pdf") {
|
|
41
|
+
let extracted;
|
|
42
|
+
try {
|
|
43
|
+
extracted = await pdfText(content);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
if (err instanceof OrganizerError)
|
|
47
|
+
throw new OrganizerError(`${capitalize(what)}: ${err.message} Ask a member to upload it again.`);
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
pdf = { pages: extracted.pages.length, hasText: extracted.hasText };
|
|
51
|
+
if (!extracted.hasText) {
|
|
52
|
+
if (part !== 1)
|
|
53
|
+
throw new OrganizerError(`${capitalize(what)} has no text: pass part 1.`);
|
|
54
|
+
return {
|
|
55
|
+
lines: [
|
|
56
|
+
`This PDF has ${extracted.pages.length} page(s) but no text layer: it contains only images (a scan or a photo, for instance), so no text can be extracted. Ask a member for a text version, or for screenshots of the relevant pages pasted into a task.`,
|
|
57
|
+
],
|
|
58
|
+
fields: { kind: "pdf", part: 1, partCount: 1, text: null, image: null, pdf },
|
|
59
|
+
images: [],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
text = pdfPagesText(extracted);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
try {
|
|
66
|
+
text = documentText(filename, content) ?? "";
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
if (err instanceof DocumentTextError)
|
|
70
|
+
throw new OrganizerError(`The text of ${what} cannot be read (invalid UTF-8 text or damaged Word file). Ask a member to upload it again.`);
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const parts = splitParts(text);
|
|
75
|
+
if (part > parts.length)
|
|
76
|
+
throw new OrganizerError(`${capitalize(what)} has ${parts.length} part(s): pass a part between 1 and ${parts.length}.`);
|
|
77
|
+
const position = parts.length > 1 ? `Part ${part} of ${parts.length}:` : "Content:";
|
|
78
|
+
const body = text.trim() === "" ? "(empty)" : parts[part - 1];
|
|
79
|
+
const lines = [pdf ? `PDF of ${pdf.pages} page(s), extracted text.` : null, position, body].filter((line) => line !== null);
|
|
80
|
+
if (part < parts.length)
|
|
81
|
+
lines.push("", `(Next: ${next(part + 1)}.)`);
|
|
82
|
+
return { lines, fields: { kind: reading, part, partCount: parts.length, text: parts[part - 1], image: null, pdf }, images: [] };
|
|
83
|
+
}
|
|
84
|
+
function capitalize(text) {
|
|
85
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
86
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { GetHistoryQuerySchema, HistoryDataSchema } from "../../shared/schemas/agent-tools.schema.js";
|
|
2
|
+
import { resolveMembers, resolveTask } from "../core/agent.js";
|
|
3
|
+
import { HistoryContext, historyEvent } from "../core/history-events.js";
|
|
4
|
+
import { historyFilters } from "../core/space-history.js";
|
|
5
|
+
import { parseInput, respond } from "./types.js";
|
|
6
|
+
/** Historique de l'espace du jeton, en lecture seule : qui a changé quoi, et quand. */
|
|
7
|
+
export const historyRoutes = [
|
|
8
|
+
{
|
|
9
|
+
method: "GET",
|
|
10
|
+
path: "/history",
|
|
11
|
+
handle: ({ store }, { agent, query }) => {
|
|
12
|
+
const input = parseInput(GetHistoryQuerySchema, query);
|
|
13
|
+
const space = agent.space;
|
|
14
|
+
const author = input.author === undefined ? undefined : input.author.trim().toLowerCase() === "agent" ? "agent" : resolveMembers(store, space, [input.author])[0].id;
|
|
15
|
+
const filters = historyFilters({ actor: author, categories: input.category === undefined ? undefined : [input.category], since: undefined });
|
|
16
|
+
const ctx = new HistoryContext(store);
|
|
17
|
+
const task = input.task === undefined ? null : resolveTask(store, space, input.task);
|
|
18
|
+
const byAuthor = (row) => {
|
|
19
|
+
const { actor } = filters;
|
|
20
|
+
if (actor === null)
|
|
21
|
+
return true;
|
|
22
|
+
return actor.type === "agent" ? row.version.actorType === "agent" : row.version.actorType === "user" && row.version.actorId === actor.userId;
|
|
23
|
+
};
|
|
24
|
+
const rows = task
|
|
25
|
+
? store
|
|
26
|
+
.listTaskHistory(task.id)
|
|
27
|
+
.filter((row) => input.before === undefined || row.version.seq < input.before)
|
|
28
|
+
.filter(byAuthor)
|
|
29
|
+
: store.listSpaceHistory(space.id, filters, input.before ?? null, input.limit + 1);
|
|
30
|
+
const page = rows.slice(0, input.limit);
|
|
31
|
+
const events = page.map((row) => historyEvent(ctx, row, false)).filter((event) => event !== null);
|
|
32
|
+
const total = task ? rows.length : store.countSpaceHistory(space.id, filters);
|
|
33
|
+
const nextBefore = rows.length > input.limit ? page[page.length - 1].version.seq : null;
|
|
34
|
+
const scope = task ? `task ${ctx.task(task.id).key}` : `"${space.name}"`;
|
|
35
|
+
if (events.length === 0)
|
|
36
|
+
return respond(HistoryDataSchema, `No event in the history of ${scope} matches.`, { events: [], total: 0, nextBefore: null });
|
|
37
|
+
const lines = events.map(eventLine);
|
|
38
|
+
const more = nextBefore === null ? "" : `\n(older events: call get_history again with before ${nextBefore})`;
|
|
39
|
+
return respond(HistoryDataSchema, `History of ${scope}, most recent first (${total} event(s)):\n${lines.join("\n")}${more}`, { events, total, nextBefore });
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
/** Ligne d'un événement : date, auteur, changements, tâche concernée. */
|
|
44
|
+
function eventLine(event) {
|
|
45
|
+
const who = event.actor.type === "agent" ? `agent for ${event.actor.name}${event.request ? ` (request ${event.request.id})` : ""}` : event.actor.name;
|
|
46
|
+
const on = event.task && event.category === "task" ? ` — ${taskLabel(event.task)}` : "";
|
|
47
|
+
return `- ${event.at.slice(0, 16).replace("T", " ")} UTC · ${who}: ${event.changes.map(changeText).join("; ")}${on}`;
|
|
48
|
+
}
|
|
49
|
+
function taskLabel(task) {
|
|
50
|
+
return `${task.key} "${task.title}"${task.deleted ? " (deleted)" : ""}`;
|
|
51
|
+
}
|
|
52
|
+
function quote(text) {
|
|
53
|
+
const line = text.trim().split(/\r?\n/)[0];
|
|
54
|
+
return `"${line.length > 80 ? `${line.slice(0, 79)}…` : line}"`;
|
|
55
|
+
}
|
|
56
|
+
/** Changement en anglais. */
|
|
57
|
+
function changeText(change) {
|
|
58
|
+
switch (change.kind) {
|
|
59
|
+
case "created":
|
|
60
|
+
return "created the task";
|
|
61
|
+
case "deleted":
|
|
62
|
+
return "deleted the task";
|
|
63
|
+
case "restored":
|
|
64
|
+
return "restored the task";
|
|
65
|
+
case "title":
|
|
66
|
+
return `renamed ${quote(change.from)} → ${quote(change.to)}`;
|
|
67
|
+
case "status":
|
|
68
|
+
case "priority":
|
|
69
|
+
case "type":
|
|
70
|
+
return `${change.kind} ${change.from} → ${change.to}`;
|
|
71
|
+
case "description":
|
|
72
|
+
return `edited the description (+${change.added} −${change.removed} lines)`;
|
|
73
|
+
case "assignees":
|
|
74
|
+
return `assignees ${[...change.added.map((person) => `+${person.name}`), ...change.removed.map((person) => `−${person.name}`)].join(" ")}`;
|
|
75
|
+
case "tags":
|
|
76
|
+
return `tags ${[...change.added.map((tag) => `+${tag}`), ...change.removed.map((tag) => `−${tag}`)].join(" ")}`;
|
|
77
|
+
case "parent":
|
|
78
|
+
return `parent ${change.from ? change.from.key : "none"} → ${change.to ? change.to.key : "none"}`;
|
|
79
|
+
case "tested":
|
|
80
|
+
return `tested task ${change.from ? change.from.key : "none"} → ${change.to ? change.to.key : "none"}`;
|
|
81
|
+
case "checklist":
|
|
82
|
+
return change.action === "edited" ? `checklist item ${quote(change.previous ?? "")} reworded ${quote(change.text)}` : `checklist item ${quote(change.text)} ${change.action}`;
|
|
83
|
+
case "checkpoint":
|
|
84
|
+
return change.action === "edited" ? `checkpoint ${quote(change.previous ?? "")} reworded ${quote(change.text)}` : `checkpoint ${quote(change.text)} ${change.action}`;
|
|
85
|
+
case "idea":
|
|
86
|
+
return `idea ${quote(change.text)} ${change.action}${change.task ? ` into ${change.task.key}` : ""}`;
|
|
87
|
+
case "member":
|
|
88
|
+
return {
|
|
89
|
+
created_space: "created the space",
|
|
90
|
+
joined: "joined the space",
|
|
91
|
+
added: `added ${change.person.name} to the space`,
|
|
92
|
+
left: "left the space",
|
|
93
|
+
removed: `removed ${change.person.name} from the space`,
|
|
94
|
+
role: `made ${change.person.name} ${change.role}`,
|
|
95
|
+
}[change.action];
|
|
96
|
+
case "invitation":
|
|
97
|
+
return { invited: `invited ${change.person.name}`, revoked: `revoked the invitation of ${change.person.name}`, declined: "declined the invitation" }[change.action];
|
|
98
|
+
case "note":
|
|
99
|
+
return change.action === "renamed" ? `renamed note ${quote(change.previous ?? "")} → ${quote(change.title)}` : `note ${quote(change.title)} ${change.action}`;
|
|
100
|
+
case "document":
|
|
101
|
+
return `document "${change.filename}" ${change.action}`;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { NoQuerySchema, NoteDetailDataSchema, SearchNotesDataSchema, SearchNotesQuerySchema } from "../../shared/schemas/agent-tools.schema.js";
|
|
2
|
+
import { ago, noteData, resolveNote } from "../core/agent.js";
|
|
3
|
+
import { parseInput, respond } from "./types.js";
|
|
4
|
+
/** Notes de l'espace du jeton, en lecture seule : recherche et lecture d'une note. */
|
|
5
|
+
export const noteRoutes = [
|
|
6
|
+
{
|
|
7
|
+
method: "GET",
|
|
8
|
+
path: "/notes",
|
|
9
|
+
handle: ({ store }, { agent, query }) => {
|
|
10
|
+
const input = parseInput(SearchNotesQuerySchema, query);
|
|
11
|
+
const space = agent.space;
|
|
12
|
+
const words = (input.query ?? "").toLowerCase().split(/\s+/).filter((word) => word !== "");
|
|
13
|
+
const matches = store.listNotes(space.id).filter((note) => {
|
|
14
|
+
const haystack = `${note.title} ${note.body}`.toLowerCase();
|
|
15
|
+
return words.every((word) => haystack.includes(word));
|
|
16
|
+
});
|
|
17
|
+
if (matches.length === 0)
|
|
18
|
+
return respond(SearchNotesDataSchema, `No note of "${space.name}" matches.`, { notes: [], total: 0 });
|
|
19
|
+
const shown = matches.slice(0, input.limit);
|
|
20
|
+
const lines = shown.map((note) => `- ${note.id} "${note.title}" (updated ${ago(note.updatedAt)})`);
|
|
21
|
+
const more = matches.length > shown.length ? `\n(${matches.length - shown.length} more: narrow the query or raise limit)` : "";
|
|
22
|
+
return respond(SearchNotesDataSchema, `${matches.length} note(s) in "${space.name}", most recently updated first:\n${lines.join("\n")}${more}\nRead one with get_note.`, {
|
|
23
|
+
notes: shown.map((note) => noteData(store, note)),
|
|
24
|
+
total: matches.length,
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
method: "GET",
|
|
30
|
+
path: "/notes/:ref",
|
|
31
|
+
handle: ({ store }, { agent, params, query }) => {
|
|
32
|
+
parseInput(NoQuerySchema, query);
|
|
33
|
+
const note = resolveNote(store, agent.space, params.ref);
|
|
34
|
+
const data = noteData(store, note);
|
|
35
|
+
const header = `Note ${note.id} "${note.title}" by ${data.authorName}, created ${ago(note.createdAt)}, updated ${ago(note.updatedAt)}. Link it in a text as ${data.link}.`;
|
|
36
|
+
return respond(NoteDetailDataSchema, [header, "", note.body.trim() === "" ? "(empty)" : note.body].join("\n"), { note: data, body: note.body });
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CheckFollowUpsBodySchema, CheckFollowUpsDataSchema, ClaimRequestBodySchema, ClaimRequestDataSchema, CompleteRequestBodySchema, FailRequestBodySchema, FinishRequestDataSchema, ListRequestsDataSchema, ListRequestsQuerySchema, ReportDirectBodySchema, } from "../../shared/schemas/agent-tools.schema.js";
|
|
2
|
-
import { actFor, agentActor, directSpace, ideaData, memberData, previousSuites, quote, recentIdeas, requestContext, requestData, requestHistory, requestLine, requestOfSpace, requestThread, spaceData, userLabel, treeData, } from "../core/agent.js";
|
|
2
|
+
import { actFor, agentActor, directSpace, ideaData, documentData, memberData, previousSuites, quote, recentIdeas, requestContext, requestData, requestHistory, requestLine, requestOfSpace, requestThread, spaceData, userLabel, treeData, } from "../core/agent.js";
|
|
3
3
|
import { InvariantError, NotFoundError } from "../core/errors.js";
|
|
4
4
|
import { parseInput, respond } from "./types.js";
|
|
5
5
|
/** Demandes de l'espace du jeton : liste, compte rendu d'un travail direct, prise, fin (réussie ou en échec), points de la demande d'origine qu'une suite règle. */
|
|
@@ -62,6 +62,7 @@ export const requestRoutes = [
|
|
|
62
62
|
members: memberData(store, agent.space),
|
|
63
63
|
tasks: treeData(store, agent.space),
|
|
64
64
|
ideas: recentIdeas(store, agent.space).map((idea) => ideaData(store, idea)),
|
|
65
|
+
documents: store.listDocuments(agent.space.id).map((document) => documentData(store, document)),
|
|
65
66
|
});
|
|
66
67
|
},
|
|
67
68
|
},
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { AgentApiContext, AgentApiRequest, AgentApiResponse } from "./types.js";
|
|
2
|
-
/** Traite une requête de l'API agent ; une erreur est
|
|
3
|
-
export declare function handleAgentRequest(ctx: AgentApiContext, request: AgentApiRequest): AgentApiResponse
|
|
2
|
+
/** Traite une requête de l'API agent ; une erreur est rejetée telle quelle, avec la nature qui fixe son code HTTP. */
|
|
3
|
+
export declare function handleAgentRequest(ctx: AgentApiContext, request: AgentApiRequest): Promise<AgentApiResponse>;
|
|
@@ -3,10 +3,15 @@ import { NotFoundError, OrganizerError } from "../core/errors.js";
|
|
|
3
3
|
import { checklistRoutes } from "./checklist.js";
|
|
4
4
|
import { questionRoutes } from "./questions.js";
|
|
5
5
|
import { ideaRoutes } from "./ideas.js";
|
|
6
|
+
import { noteRoutes } from "./notes.js";
|
|
7
|
+
import { documentRoutes } from "./documents.js";
|
|
8
|
+
import { attachmentRoutes } from "./attachments.js";
|
|
9
|
+
import { historyRoutes } from "./history.js";
|
|
6
10
|
import { notificationRoutes } from "./notifications.js";
|
|
7
11
|
import { requestRoutes } from "./requests.js";
|
|
8
12
|
import { taskRoutes } from "./tasks.js";
|
|
9
13
|
import { viewRoutes } from "./views.js";
|
|
14
|
+
import { timerRoutes } from "./timers.js";
|
|
10
15
|
function compile(route) {
|
|
11
16
|
const keys = [];
|
|
12
17
|
const source = route.path.replace(/:([A-Za-z]+)/g, (_, key) => {
|
|
@@ -15,7 +20,7 @@ function compile(route) {
|
|
|
15
20
|
});
|
|
16
21
|
return { route, pattern: new RegExp(`^${source}$`), keys };
|
|
17
22
|
}
|
|
18
|
-
const ROUTES = [...requestRoutes, ...taskRoutes, ...checklistRoutes, ...questionRoutes, ...ideaRoutes, ...viewRoutes, ...notificationRoutes].map(compile);
|
|
23
|
+
const ROUTES = [...requestRoutes, ...taskRoutes, ...checklistRoutes, ...questionRoutes, ...ideaRoutes, ...noteRoutes, ...documentRoutes, ...attachmentRoutes, ...historyRoutes, ...viewRoutes, ...timerRoutes, ...notificationRoutes].map(compile);
|
|
19
24
|
/** Segment de chemin décodé ; un encodage `%` invalide est une erreur 400. */
|
|
20
25
|
function decodeSegment(raw) {
|
|
21
26
|
try {
|
|
@@ -25,8 +30,8 @@ function decodeSegment(raw) {
|
|
|
25
30
|
throw new OrganizerError(`Invalid URL: a path segment is badly encoded (${raw}).`);
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
|
-
/** Traite une requête de l'API agent ; une erreur est
|
|
29
|
-
export function handleAgentRequest(ctx, request) {
|
|
33
|
+
/** Traite une requête de l'API agent ; une erreur est rejetée telle quelle, avec la nature qui fixe son code HTTP. */
|
|
34
|
+
export async function handleAgentRequest(ctx, request) {
|
|
30
35
|
const now = ctx.now?.() ?? new Date();
|
|
31
36
|
const agent = resolveAgentToken(ctx.store, request.bearer, now);
|
|
32
37
|
for (const candidate of ROUTES) {
|
|
@@ -37,7 +42,7 @@ export function handleAgentRequest(ctx, request) {
|
|
|
37
42
|
continue;
|
|
38
43
|
const params = {};
|
|
39
44
|
candidate.keys.forEach((key, index) => (params[key] = decodeSegment(match[index + 1])));
|
|
40
|
-
return candidate.route.handle(ctx, { agent, params, query: request.query, body: request.body });
|
|
45
|
+
return await candidate.route.handle(ctx, { agent, params, query: request.query, body: request.body });
|
|
41
46
|
}
|
|
42
47
|
throw new NotFoundError(`Unknown agent API route: ${request.method} /api/agent${request.path}. Update @imenam/mcp-organizer so that the MCP mode and the site agree.`);
|
|
43
48
|
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { AddCommentBodySchema, CommentDataSchema, ContextDataSchema, CreateTaskBodySchema, NoQuerySchema, SearchTasksDataSchema, SearchTasksQuerySchema, SetAssigneesBodySchema, SetTagsBodySchema, TaskDataSchema, TaskDetailDataSchema, UpdateTaskBodySchema, } from "../../shared/schemas/agent-tools.schema.js";
|
|
2
|
+
import { attachmentImages } from "../../shared/logic/attachments.js";
|
|
2
3
|
import { combinedResult } from "../../shared/logic/test-summary.js";
|
|
3
|
-
import { actFor, ago, assigneesSummary, createdTaskSummary, ideaData, memberData, recentIdeas, requireText, resolveMembers, resolveTask, spaceContextLines, spaceData, taskData, taskKey, taskUpdateSummary, treeData, userLabel, } from "../core/agent.js";
|
|
4
|
+
import { actFor, ago, attachmentLines, assigneesSummary, createdTaskSummary, ideaData, documentData, memberData, recentIdeas, requireText, resolveMembers, resolveTask, spaceContextLines, spaceData, taskData, taskKey, taskUpdateSummary, treeData, userLabel, } from "../core/agent.js";
|
|
4
5
|
import { OrganizerError } from "../core/errors.js";
|
|
5
6
|
import { questionData, questionLines, questionsOf } from "./questions.js";
|
|
6
7
|
import { parseInput, respond } from "./types.js";
|
|
8
|
+
/** Mention des images jointes qu'un texte référence, ajoutée à sa ligne : ` [images: nom (attachment id), …; open with get_attachment]`. */
|
|
9
|
+
function imageNote(text) {
|
|
10
|
+
const images = attachmentImages(text);
|
|
11
|
+
return images.length === 0 ? "" : ` [images: ${images.map((image) => `${image.name} (attachment ${image.id})`).join(", ")}; open with get_attachment]`;
|
|
12
|
+
}
|
|
7
13
|
/** Espace du jeton et ses tâches : contexte, lecture, recherche, création, modification, assignés, tags, commentaires. */
|
|
8
14
|
/** Nombre de commentaires récents affichés par get_task. */
|
|
9
15
|
const RECENT_COMMENTS = 15;
|
|
@@ -20,6 +26,7 @@ export const taskRoutes = [
|
|
|
20
26
|
members: memberData(store, space),
|
|
21
27
|
tasks: treeData(store, space),
|
|
22
28
|
ideas: recentIdeas(store, space).map((idea) => ideaData(store, idea)),
|
|
29
|
+
documents: store.listDocuments(space.id).map((document) => documentData(store, document)),
|
|
23
30
|
});
|
|
24
31
|
},
|
|
25
32
|
},
|
|
@@ -73,7 +80,7 @@ export const taskRoutes = [
|
|
|
73
80
|
const own = results.filter((result) => result.checkpointId === checkpoint.id);
|
|
74
81
|
const combined = combinedResult(own.map((result) => result.result));
|
|
75
82
|
checkpoints.push({ id: checkpoint.id, text: checkpoint.text, result: combined });
|
|
76
|
-
const comments = own.filter((result) => result.comment.trim() !== "").map((result) => `${name(result.testerId)}: ${result.comment}`);
|
|
83
|
+
const comments = own.filter((result) => result.comment.trim() !== "").map((result) => `${name(result.testerId)}: ${result.comment}${imageNote(result.comment)}`);
|
|
77
84
|
lines.push(`- [${combined}] ${checkpoint.text} (id ${checkpoint.id})${comments.length > 0 ? ` — ${comments.join(" | ")}` : ""}`);
|
|
78
85
|
}
|
|
79
86
|
if (points.length === 0)
|
|
@@ -95,11 +102,11 @@ export const taskRoutes = [
|
|
|
95
102
|
if (comments.length > 0) {
|
|
96
103
|
lines.push("", "Recent comments:");
|
|
97
104
|
for (const comment of comments)
|
|
98
|
-
lines.push(`- ${comment.requestId ? "agent" : name(comment.authorId)}, ${ago(comment.createdAt)}: ${comment.body}`);
|
|
105
|
+
lines.push(`- ${comment.requestId ? "agent" : name(comment.authorId)}, ${ago(comment.createdAt)}: ${comment.body}${imageNote(comment.body)}`);
|
|
99
106
|
}
|
|
100
107
|
const attachments = store.listAttachments(task.id);
|
|
101
108
|
if (attachments.length > 0)
|
|
102
|
-
lines.push("",
|
|
109
|
+
lines.push("", ...attachmentLines(store, task));
|
|
103
110
|
return respond(TaskDetailDataSchema, lines.join("\n"), {
|
|
104
111
|
task: summary,
|
|
105
112
|
description: task.description,
|
|
@@ -114,8 +121,9 @@ export const taskRoutes = [
|
|
|
114
121
|
byAgent: comment.requestId !== null,
|
|
115
122
|
body: comment.body,
|
|
116
123
|
createdAt: comment.createdAt,
|
|
124
|
+
images: attachmentImages(comment.body),
|
|
117
125
|
})),
|
|
118
|
-
attachments: attachments.map((attachment) => attachment.filename),
|
|
126
|
+
attachments: attachments.map((attachment) => ({ id: attachment.id, filename: attachment.filename, mime: attachment.mime, size: attachment.size })),
|
|
119
127
|
});
|
|
120
128
|
},
|
|
121
129
|
},
|