Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,11 @@
{
"key": "document-studio",
"name": "Document studio",
"version": "0.2.0",
"version": "0.3.0",
"subpath": "document-studio",
"manifest": "document-studio/module.yaml",
"manifest_sha256": "2e09f02654084161cdea77ebbdeb479e7da92034c5939b63cfb73402747cdecb",
"tree_sha256": "b1d2ddedab8e740cf8313da9a5fa6094b7b8da875035a5c9e98626c8454091d2",
"manifest_sha256": "f31b391b04ecf28700efb19584a020a2e72ddcb5c7ade5c5b6f6f3113f4562db",
"tree_sha256": "66f0b03609f2dfbb16859747646ae16fb778703f8544b36f318b8e94ae497fc0",
"description": {
"en": "Document studio: draft business documents from a brief, render them to PDF from templates and the company profile, review, approve and issue them with a number, and keep every revision in Storage.",
"fr": "Studio de documents : rédiger des documents professionnels depuis un brief, les rendre en PDF avec des gabarits et la fiche entreprise, les relire, les approuver et les émettre avec un numéro, en gardant chaque révision dans Storage."
Expand Down Expand Up @@ -693,6 +693,10 @@
"key": "document-studio-profile-save",
"name": "Save the company profile"
},
{
"key": "document-share",
"name": "Share an issued document"
},
{
"key": "document-studio-new-version",
"name": "Add a DOCX version"
Expand All @@ -705,7 +709,8 @@
"queries": [
"document-studio-list",
"document-studio-review-read",
"document-studio-template-read"
"document-studio-template-read",
"document-read"
],
"requires": {
"runtimes": [
Expand All @@ -720,7 +725,7 @@
"model": "free"
},
"maturity": "preview",
"workflows": 13,
"workflows": 15,
"miniapps": 1
},
{
Expand Down
39 changes: 34 additions & 5 deletions document-studio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ messages) is French; `fr` is the only locale in V0.
| `document-studio-list` | lists the documents (identifier, title, status, number, revision, latest hash) |
| `document-studio-review-read` | full record of a document and previews of its latest render, for the MiniApp |
| `document-studio-template-read` | lists the templates, or the manifest and data schemas of one template |
| `document-share` | publishes the reference of an **issued** document as a record of the native application data broker (`recipe--application_data_v1`, namespace `cib-documents`, key `doc_id`), then grants or removes `read` for one member. Requires `confirmation_manuelle`. The PDF stays in Storage |
| `document-read` | reads one shared reference through the broker (with the caller's permissions), or lists the references the caller may read when `doc_id` is empty or absent (`"doc_id": ""` is valid, so the form can be submitted blank) |

The `document-studio-review` MiniApp has no input component of its own (the
MiniApp vocabulary has none): the document identifier (`doc_id`) is typed in
Expand All @@ -37,6 +39,31 @@ table of renders (revision, mode, hash, path), refreshes it, and triggers a
new render. Approval and issue go through the
Workflow forms, with the manual confirmation.

## Sharing with the company

Sharing follows the `cib-contenu` pattern: the broker holds one record per document and enforces a per-member ACL; a
record is private to its owner until `document-share` grants `read` (`write` is refused on purpose: a member must not
be able to rewrite the reference). `expected_revision` is `0` for the first publication, then the revision returned by
the previous call (compare-and-set). The shared record (`document-studio.shared/v1`) holds `doc_id`, `title`,
`template_key`, `number`, `version` (the revision of the Storage record at issue), `path` (Storage path of the issued
PDF), `sha256` and `issued_at`. Removing access (`none`) does not need the Storage record, so it still works after a
cancellation; a cancelled document stays referenced until its owner removes the members. The PDF itself is read through the ACL of the
record, not through the Storage rights of the member: `document-read` with `doc_id` and `include_pdf: oui` (optional,
default `non`; a form field, `non` by default) reads the PDF at `data.path` from the Agent's Storage with `read_file`
(base64) only after the broker read succeeded, recomputes its SHA-256 and refuses `pdf_integrity_failed` when it differs
from the shared `sha256`, `pdf_too_large` above 5 MiB, and `invalid_path` when the path is not an issued document of
`/document-studio/docs/<doc_id>/issued/`. It returns `pdf_base64`, `pdf_sha256` and `pdf_bytes`. `include_pdf` without a
`doc_id` is refused.

## Optional service in the Company-in-a-Box template

`templates/company-in-a-box/compose.py --with-service documents` adds this Module as an optional fourth Agent
(`documents`, spec-init'ed in the consumer like the three roles; off by default). Besides the resources and the test
plan it writes `surface-drafts/cib-documents.surface-draft.json`, with `required_role` on every Workflow: `cib_documents`
for the owner of the service, `cib_admin` for `document-studio-profile-save`. Role grants and the ACL of each record are
cumulative; the Module never grants a role or a share. `document-read` has no `required_role` in the surface draft, like `contenu-read`: any member of the Application may call it and the ACL of each record decides what is returned. `document-share` republished without a member reports the real shares returned by the broker. The Administration select of `cib-admin-manage` does not list
`cib_documents` yet.

## Lifecycle

`draft` (successive renders) → `approved` → `issued`. `cancelled` is reachable
Expand All @@ -48,7 +75,7 @@ The Module never approves on a person's behalf.

## Storage

- `/document-studio/profile.json`: the brand, with the `{schema_version: 1, company, brand}` shape of the template contract. A fictitious example is in `examples/profile.example.json`.
- `/document-studio/profile.json`: the fallback brand (used when `cib-profile` is unavailable), with the `{schema_version: 1, company, brand}` shape of the template contract. A fictitious example is in `examples/profile.example.json`.
- `/document-studio/docs/<doc_id>/record.json`: the record (`document-studio.record/v1`): status, number, revision (+1 at every write), data, history, renders (path, SHA-256, previews, provenance), issue.
- `/document-studio/docs/<doc_id>/r<revision>-<sha12>/`: PDF and previews of one render attempt (12 first characters of the PDF SHA-256, so a losing attempt never overwrites another attempt's file).
- `/document-studio/docs/<doc_id>/issued/<number>-<sha12>.pdf`: the issued PDF.
Expand All @@ -60,8 +87,11 @@ The Module never approves on a person's behalf.
title with a short suffix. Number: `<PREFIX>-<year>-<seq>` (`DEV` for the
quote, `CR` for the minutes).

Without a company profile, `render` and `publish` fail with `profile_missing`:
store the brand with `document-studio-profile-save`.
The company profile is read from the `cib-profile` record of the `profile` Module through
`recipe--application_data_v1` (`operation: read`, `namespace: cib-profile`, `record_key: company-profile`, the call of
`cib-profile-read`); `render` and `publish` report the source in `profile_source`. Fallback: `/document-studio/profile.json`
in Storage. Without either, they fail with `profile_missing`. The fingerprints of the brand checked at issue
(`profile_changed`) are computed on the projected profile, whatever its source.

## DOCX versions

Expand Down Expand Up @@ -127,11 +157,10 @@ renderer, on synthetic data. They do not prove the behavior on a One.

## Known limits (V0)

- The brand is read from the `cib-profile` record (key `company-profile`) through the broker, by `render` and `publish`. If that record is absent, refused to the caller or unreadable, the Storage copy `/document-studio/profile.json` is used and the output says so (`profile_source`: `cib-profile` or `storage`). A broker refusal is therefore not distinguished from an absent record. `document-studio-profile-save` still writes only the Storage copy: save the profile in `cib-profile` (profile Module) to make it the source.
- Concurrent `mark-authoritative`: two calls on the same document at the same time are not safe. Both may pass the second read and the later write wins, which can leave the wrong version authoritative or bring a superseded one back while both calls report success. Serialise them (one writer per document). Moving the manifest to `application_data_v1`, which has compare-and-swap, lifts this limit (lot 4).
- Versions: Storage has no compare-and-swap. A manifest is read, the version file and redline are written, then the manifest is read again and written only if its text is unchanged (`concurrent_update` otherwise; a first manifest is written without overwrite). The window between the second read and the write is small, not null: allow one writer at a time per document. Files written before an abandoned manifest write stay orphaned in `versions/`. Pass `base_version` and `base_manifest_sha256` (returned as `manifest_sha256`) to make a stale caller fail.
- Versions are DOCX only (XLSX and PDF are out of this lot), the comparison and its 20 MiB input limit are those of `office_compare_v1`, and there is no review MiniApp for versions yet.

- The brand is read from Storage only. The `profile` Module keeps the profile in an application record whose broker is not wired in the One yet: calling the `cib-profile-read` Workflow would make every render fail until then.
- The logo is a reference (`storage://…`); this Module does not resolve it to a file before rendering.
- Number reservation is not atomic: it lists, writes without overwrite, reads back and checks the owner, at most 5 attempts (`number_conflict`). A number reserved then lost (failed render) stays reserved: it is taken again on the next attempt, never reused by another document. Atomic sequences are a platform follow-up.
- No sending (mail, SFTP), no DOCX rendering (DOCX files are only versioned), one locale (`fr`).
Expand Down
90 changes: 90 additions & 0 deletions document-studio/agents/main/workflows/document-read.json

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions document-studio/agents/main/workflows/document-share.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion document-studio/module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"schema_version": 2,
"key": "document-studio",
"name": "Document studio",
"version": "0.2.0",
"version": "0.3.0",
"provides": {
"actions": [
{
Expand Down Expand Up @@ -54,6 +54,12 @@
"workflow_id": "document-studio-profile-save",
"workflow_version": "1"
},
{
"key": "document-share",
"name": "Share an issued document",
"workflow_id": "document-share",
"workflow_version": "1"
},
{
"key": "document-studio-new-version",
"name": "Add a DOCX version",
Expand Down Expand Up @@ -85,6 +91,12 @@
"name": "Read the templates",
"workflow_id": "document-studio-template-read",
"workflow_version": "1"
},
{
"key": "document-read",
"name": "Read shared documents",
"workflow_id": "document-read",
"workflow_version": "1"
}
],
"apps": [
Expand Down
Loading
Loading