@thatopen/services 0.35.1 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -66
- package/dist/built-in/index.d.ts +13 -13
- package/dist/cli/lib/browser-session.d.ts +17 -0
- package/dist/cli/lib/config.d.ts +6 -0
- package/dist/cli.js +334 -38
- package/dist/cli.js.map +1 -1
- package/dist/core/browser-sign-in.d.ts +50 -0
- package/dist/core/browser-sign-in.test.d.ts +1 -0
- package/dist/core/builtin-recipes/index.d.ts +2 -2
- package/dist/core/builtin-recipes/layer-to-native.d.ts +19 -0
- package/dist/core/builtin-recipes/records-to-native.d.ts +43 -0
- package/dist/core/builtin-recipes/shapes-to-families.d.ts +9 -4
- package/dist/core/builtin-recipes/shared.d.ts +8 -11
- package/dist/core/channel.d.ts +1 -1
- package/dist/core/client.d.ts +46 -2
- package/dist/core/frag-items.d.ts +1 -1
- package/dist/core/history.d.ts +9 -9
- package/dist/core/op-builder.d.ts +2 -2
- package/dist/core/platform-client.d.ts +6 -3
- package/dist/core/project-recipes.d.ts +1 -1
- package/dist/core/recipes.d.ts +31 -5
- package/dist/index.cjs.js +23 -20
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +4284 -3455
- package/dist/index.es.js.map +1 -1
- package/dist/vite-env.d.ts +1 -1
- package/docs/ai-quickstart.md +548 -548
- package/docs/builtin/paths.json +130 -130
- package/docs/cli/create.md +29 -29
- package/docs/cli/local-server.md +38 -38
- package/docs/cli/login.md +35 -32
- package/docs/cli/mcp.md +46 -46
- package/docs/cli/publish.md +31 -31
- package/docs/cli/run.md +26 -26
- package/docs/cli/serve.md +43 -43
- package/docs/cli/swap.md +30 -30
- package/docs/client/paths.json +2 -2
- package/docs/cloud/GaussianSplatConverter.md +43 -43
- package/docs/cloud/PointCloudConverter.md +53 -53
- package/docs/flow-architecture.md +393 -393
- package/docs/flow-plugin-guide.md +354 -354
- package/docs/platform-token.md +81 -81
- package/docs/rate-limits.md +133 -133
- package/docs/recipes-guide.md +243 -243
- package/docs/revit-collab-quickstart.md +445 -445
- package/docs/rhino-interop-quickstart.md +387 -387
- package/docs/sheet-sets-guide.md +69 -69
- package/package.json +1 -1
- package/resources/AGENTS.md +57 -57
- package/src/built-in/CDEManager/example.ts +214 -214
- package/src/built-in/CDEManager/examples/FileEditing/example.ts +226 -226
- package/src/built-in/CDEManager/examples/FileMoves/example.ts +186 -186
- package/src/built-in/CDEManager/examples/FileOperations/example.ts +295 -295
- package/src/built-in/CDEManager/examples/FileTransfers/example.ts +210 -210
- package/src/built-in/CDEManager/examples/FolderManagement/example.ts +230 -230
- package/src/built-in/CDEManager/examples/MetadataSchema/example.ts +230 -230
- package/src/built-in/CDEManager/examples/MetadataViews/example.ts +166 -166
- package/src/built-in/CDEManager/examples/ProjectConfig/example.ts +177 -177
- package/src/built-in/ClashesManager/example.ts +283 -283
- package/src/built-in/GISManager/example.ts +355 -355
- package/src/built-in/ProjectManager/example.ts +124 -124
- package/src/built-in/UIManager/src/app/example.ts +97 -97
- package/src/built-in/UIManager/src/app/examples/AppState/example.ts +140 -140
- package/src/built-in/UIManager/src/app/examples/Banner/example.ts +159 -159
- package/src/built-in/UIManager/src/app/examples/Contexts/example.ts +123 -123
- package/src/built-in/UIManager/src/app/examples/FileDrop/example.ts +124 -124
- package/src/built-in/UIManager/src/app/examples/FloatingLayout/example.ts +90 -90
- package/src/built-in/UIManager/src/app/examples/Modal/example.ts +163 -163
- package/src/built-in/UIManager/src/app/examples/Notifications/example.ts +133 -133
- package/src/built-in/UIManager/src/app/examples/ProjectFileStorage/example.ts +150 -150
- package/src/built-in/UIManager/src/app/examples/Sidebar/example.ts +105 -105
- package/src/built-in/UIManager/src/clashes-panel/example.ts +183 -183
- package/src/built-in/UIManager/src/gis-panel/example.ts +163 -163
- package/src/built-in/UIManager/src/gis-properties-panel/example.ts +168 -168
- package/src/built-in/UIManager/src/git-history-panel/example.ts +70 -70
- package/src/built-in/UIManager/src/map-panel/example.ts +189 -189
- package/src/built-in/UIManager/src/models-list/example.ts +181 -181
- package/src/built-in/UIManager/src/settings-panel/example.ts +303 -303
- package/src/built-in/UIManager/src/topics-panel/example.ts +170 -170
- package/src/built-in/UIManager/src/viewer/example.ts +182 -182
- package/src/built-in/UIManager/src/viewer-toolbar/example.ts +376 -376
- package/src/built-in/index.ts +2995 -2995
- package/src/cli/templates/app/README.md +250 -250
- package/src/cli/templates/app/index.html +35 -35
- package/src/cli/templates/app/package.json +32 -32
- package/src/cli/templates/app/src/app.ts +37 -37
- package/src/cli/templates/app/src/assets/tool-placeholder.ts +50 -50
- package/src/cli/templates/app/src/bim-components/CloudRunner/index.ts +95 -95
- package/src/cli/templates/app/src/bim-components/CloudRunner/src/index.ts +1 -1
- package/src/cli/templates/app/src/bim-components/CloudRunner/src/types.ts +5 -5
- package/src/cli/templates/app/src/bim-components/index.ts +1 -1
- package/src/cli/templates/app/src/globals.ts +1 -1
- package/src/cli/templates/app/src/main.history.ts +191 -191
- package/src/cli/templates/app/src/main.ts +226 -226
- package/src/cli/templates/app/src/setups/channel.ts +76 -76
- package/src/cli/templates/app/src/setups/reality-capture/lib/hidden-tiles-plugin.ts +88 -88
- package/src/cli/templates/app/src/setups/reality-capture/lib/point-tile-plugin.ts +166 -166
- package/src/cli/templates/app/src/setups/reality-capture/lib/render-frame.ts +31 -31
- package/src/cli/templates/app/src/setups/reality-capture/lib/splat-tile-plugin.ts +51 -51
- package/src/cli/templates/app/src/setups/reality-capture-viewer.ts +1383 -1383
- package/src/cli/templates/app/src/ui-components/app-info-section/index.ts +26 -26
- package/src/cli/templates/app/src/ui-components/app-info-section/src/index.ts +1 -1
- package/src/cli/templates/app/src/ui-components/app-info-section/src/types.ts +15 -15
- package/src/cli/templates/app/src/ui-components/cloud-runner-section/index.ts +37 -37
- package/src/cli/templates/app/src/ui-components/cloud-runner-section/src/index.ts +1 -1
- package/src/cli/templates/app/src/ui-components/cloud-runner-section/src/types.ts +14 -14
- package/src/cli/templates/app/src/ui-components/index.ts +2 -2
- package/src/cli/templates/app/tsconfig.json +16 -16
- package/src/cli/templates/app/vite.config.js +57 -57
- package/src/cli/templates/cloud-component/README.md +205 -205
- package/src/cli/templates/cloud-component/_thatopen +5 -5
- package/src/cli/templates/cloud-component/declarations.json +4 -4
- package/src/cli/templates/cloud-component/package.json +21 -21
- package/src/cli/templates/cloud-component/src/main.ts +70 -70
- package/src/cli/templates/cloud-component/tsconfig.json +16 -16
- package/src/cli/templates/cloud-component/vite.config.js +46 -46
- package/src/cli/templates/shared/AGENTS.md +8 -8
- package/src/cli/templates/shared/CLAUDE.md +1 -1
- package/src/cli/templates/shared/_gitignore +5 -5
- package/src/core/examples/.env.example +7 -7
- package/src/core/examples/apps.ts +67 -67
- package/src/core/examples/batch-reads.ts +99 -99
- package/src/core/examples/channel.ts +65 -65
- package/src/core/examples/components.ts +91 -91
- package/src/core/examples/execution.ts +75 -75
- package/src/core/examples/file-metadata.ts +94 -94
- package/src/core/examples/files.ts +81 -81
- package/src/core/examples/folders.ts +82 -82
- package/src/core/examples/hidden-files.ts +88 -88
- package/src/core/examples/history.ts +103 -103
- package/src/core/examples/icons.ts +68 -68
- package/src/core/examples/permissions.ts +87 -87
- package/dist/core/builtin-recipes/records-to-revit.d.ts +0 -28
- package/dist/core/builtin-recipes/rhino-to-revit.d.ts +0 -16
|
@@ -1,354 +1,354 @@
|
|
|
1
|
-
# Writing a flow plugin
|
|
2
|
-
|
|
3
|
-
The concrete contract. [The architecture notes](https://raw.githubusercontent.com/ThatOpen/platform_services/main/docs/flow-architecture.md) say why any of this is
|
|
4
|
-
shaped the way it is; this says what the bytes look like.
|
|
5
|
-
|
|
6
|
-
> **Plug-ins only.** Since `@thatopen/services` 0.20, apps and scripts do not write this layout by
|
|
7
|
-
> hand: `client.history(projectId)` reads and writes documents and version timelines, and
|
|
8
|
-
> `client.recipes` lists and runs the recipes that bring project data into a native application —
|
|
9
|
-
> see `src/core/examples/history.ts` in the package, and
|
|
10
|
-
> [Writing a recipe](https://raw.githubusercontent.com/ThatOpen/platform_services/main/docs/recipes-guide.md)
|
|
11
|
-
> for the recipes themselves. The bytes below are the contract for NATIVE PLUG-INS (which carry their own client),
|
|
12
|
-
> and the reference for what the API does underneath. Anything else touching these files directly
|
|
13
|
-
> will break when the layout moves behind the API, which is the plan.
|
|
14
|
-
|
|
15
|
-
Nothing here is aspirational. Every rule below is what the
|
|
16
|
-
was written from their implementation rather than ahead of it — which is why the awkward parts are
|
|
17
|
-
stated as plainly as the tidy ones. Where a rule exists because something broke, it says so.
|
|
18
|
-
|
|
19
|
-
The most reliable way to check any of it is the same one available to you: publish something and
|
|
20
|
-
read it back. The formats are open and the platform's file API is the whole transport.
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## 0. Which of these do you actually need?
|
|
25
|
-
|
|
26
|
-
Three different jobs, three different amounts of work. Pick yours before reading further.
|
|
27
|
-
|
|
28
|
-
| You want to | Implement | Sections |
|
|
29
|
-
|---|---|---|
|
|
30
|
-
| Let people bring project data into YOUR application | Run a recipe, apply the changes it returns | 1, 2, 5 |
|
|
31
|
-
| Show a model your application did not author | Read a `.frag` | 1, 3 |
|
|
32
|
-
| Let people collaborate in YOUR application | A history, plus whatever arbitration it needs | 1, 3, 4, 6 |
|
|
33
|
-
|
|
34
|
-
Applying a recipe needs no ownership registry and no collaboration layer of your own: the changes
|
|
35
|
-
are an ordinary edit in your application, made by the person working there. Writing a recipe needs
|
|
36
|
-
no plugin at all — that is
|
|
37
|
-
[Writing a recipe](https://raw.githubusercontent.com/ThatOpen/platform_services/main/docs/recipes-guide.md).
|
|
38
|
-
|
|
39
|
-
---
|
|
40
|
-
|
|
41
|
-
## 1. Where things live
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
The platform's file API is the whole transport. There is no flow server.
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
project
|
|
48
|
-
└── bimterop/ a folder, created on demand
|
|
49
|
-
└── revit-<documentId>/ one per model
|
|
50
|
-
├── <modelname>.frag the model, as of the last full export
|
|
51
|
-
│ └── (hidden children) per-commit delta .frag, addressed by id
|
|
52
|
-
├── revitflow_history.json the commit log
|
|
53
|
-
├── revitflow_recipes.json the recipes this model was given, and what each made
|
|
54
|
-
├── revitflow_btree.json file -> blocks, current state
|
|
55
|
-
├── revitflow_btree_<n>.json file -> blocks, as of version n
|
|
56
|
-
├── revitflow_bindex.json block -> which pack holds it
|
|
57
|
-
├── revitflow_bpack_<n>.zip the blocks first seen at version n
|
|
58
|
-
├── revitflow_version.txt the current version number
|
|
59
|
-
├── revitflow_manifest.json version, who, when
|
|
60
|
-
├── bimterop-locks-anchor a file whose hidden children are claims
|
|
61
|
-
└── revitflow-queue-anchor a file whose hidden children are queue tickets
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
**Visible files are named; hidden files are not.** The platform's hidden-file API has no queryable
|
|
65
|
-
name: listing by parent and fetching by id both return ids and sizes only. So every hidden file's id
|
|
66
|
-
has to be written down somewhere visible when it is created, or it is orphaned for good. That single
|
|
67
|
-
fact explains several shapes below — `deltaId` on a commit, and the use of an ordinary file as an
|
|
68
|
-
"anchor" whose only job is to be a parent.
|
|
69
|
-
|
|
70
|
-
**Two things come free with a listing, and they matter.** A hidden file's `_id` is a Mongo ObjectId
|
|
71
|
-
whose first four bytes are its creation time, so a set of hidden files is ordered by arrival without
|
|
72
|
-
downloading any of them. `owningEntity` is the platform user who created it. The sync queue and the
|
|
73
|
-
ownership registry are both built entirely out of those two facts.
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
## 2. The changes a recipe returns
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
A recipe's `run` answers `{ title, verb, payload, targets, ruleTallies }`, or throws `UpToDate` when
|
|
81
|
-
there is nothing to write. `payload` is the changes; the plugin applies them directly, in its own
|
|
82
|
-
application. They are never uploaded and never queued: they exist between the run and the apply,
|
|
83
|
-
in memory.
|
|
84
|
-
|
|
85
|
-
`verb` is a label — `add`, `set`, `remove` or `mixed` — and is never read to decide anything,
|
|
86
|
-
because one run may add, change and remove at once. `title` is what the history row will say.
|
|
87
|
-
`ruleTallies` has one `{ read, written }` per row of the manifest's `rules`.
|
|
88
|
-
|
|
89
|
-
Recipes build the payload with `OperationBuilder` (`add`, `set`, `remove`, then `build(opId)`), so
|
|
90
|
-
nobody writes these bytes by hand; `describeChanges(payload)` reads them back as a list. What
|
|
91
|
-
follows is what that payload IS, for a plugin that has to apply it.
|
|
92
|
-
|
|
93
|
-
### The payload
|
|
94
|
-
|
|
95
|
-
A `.frag` with **no geometry at all**.
|
|
96
|
-
|
|
97
|
-
- one geometry-less item per change
|
|
98
|
-
- the target's native id in the item's `guid` — the slot the format already has for a global id
|
|
99
|
-
- the envelope, as JSON, in `Model.metadata`
|
|
100
|
-
|
|
101
|
-
A geometry-less item is a real thing the format supports, but writers get it wrong in a way that is
|
|
102
|
-
worth stating: only items that actually have vertices and indices may appear in the mesh table, and
|
|
103
|
-
an item's bounding box must not be all zeros (a zero-size box reads as absent and the reader stops
|
|
104
|
-
with "Dimension not found").
|
|
105
|
-
|
|
106
|
-
### The envelope
|
|
107
|
-
|
|
108
|
-
```json
|
|
109
|
-
{
|
|
110
|
-
"schema": "revitflow/op@2",
|
|
111
|
-
"opId": "op-9a68aceffc4e",
|
|
112
|
-
"batchId": "batch-...",
|
|
113
|
-
"targetProject": "<project id>",
|
|
114
|
-
"targetDocument": "<document id>",
|
|
115
|
-
"baseCommitGuid": "<commit guid this was authored against>",
|
|
116
|
-
"baseCommit": 18,
|
|
117
|
-
"author": "recipe:columns-from-points",
|
|
118
|
-
"title": "Columns from points: 4 change(s)",
|
|
119
|
-
"summary": "add",
|
|
120
|
-
"transform": { "translate": [0,0,0], "rotate": {"origin":[0,0,0],"axis":[0,0,1],"degrees":90} }
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
`schema` is checked exactly. An applier that reads `@1` the `@2` way would not fail, it would
|
|
125
|
-
quietly do the wrong thing, so an unknown schema is refused and the recipe has to be updated.
|
|
126
|
-
|
|
127
|
-
`baseCommitGuid` / `baseCommit` name the commit of the target the changes were computed against.
|
|
128
|
-
The plugin applies them right after the run, so that is normally the model as it is; an element a
|
|
129
|
-
`set` or `remove` names that is gone all the same is reported rather than skipped quietly.
|
|
130
|
-
|
|
131
|
-
`transform` is optional and applies to every `set` item, on top of whatever its attributes change.
|
|
132
|
-
It exists alongside the per-item transform because the two answer different questions: an item's own
|
|
133
|
-
transform says "put it HERE", which is what an `add` needs; this says "move it BY this", which needs
|
|
134
|
-
no knowledge of where anything currently is.
|
|
135
|
-
|
|
136
|
-
**There is no `units` field, deliberately.** The changes edit the data an application published, so
|
|
137
|
-
its numbers are in the terms of that data — exactly as a patch over a JSON document writes the
|
|
138
|
-
fields as the document holds them. Read a position out of a published model, write it back
|
|
139
|
-
unchanged, and nothing moves. Converting from whatever the author's document uses is the
|
|
140
|
-
recipe's job, because the recipe is the only thing that knows both sides. An earlier version
|
|
141
|
-
made every change set declare its units, which looked careful and was a bug waiting to happen: it let
|
|
142
|
-
an author state a unit while writing coordinates in an axis convention the target does not use, a
|
|
143
|
-
mistake no declared unit can catch.
|
|
144
|
-
|
|
145
|
-
### Who wrote it
|
|
146
|
-
|
|
147
|
-
The envelope's `author` is free text: a recipe writes `recipe:<name>`. It is not who made the
|
|
148
|
-
change. The person who applied the recipe is, and they appear where every change of theirs appears:
|
|
149
|
-
on the commit their sync writes (section 3), whose `userId` is what the platform's own member
|
|
150
|
-
component resolves into a real name and face. Get that wrong and the commit shows up under
|
|
151
|
-
somebody else's avatar, which is worse than showing none.
|
|
152
|
-
|
|
153
|
-
**In a native plug-in there is no call that answers it**, so read the `u` claim out of the API
|
|
154
|
-
key's JWT payload (base64url, no signature check, since this only decides which name to display).
|
|
155
|
-
That is what the
|
|
156
|
-
|
|
157
|
-
### The verbs
|
|
158
|
-
|
|
159
|
-
One per item, in the attribute `flow:op`:
|
|
160
|
-
|
|
161
|
-
```
|
|
162
|
-
add no guid (it does not exist yet), attributes describe it, transform says where it goes
|
|
163
|
-
set names an item by its guid; an attribute present is written, absent is left alone,
|
|
164
|
-
and an EMPTY value clears it
|
|
165
|
-
remove names an item by its guid
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
### The reserved namespace
|
|
169
|
-
|
|
170
|
-
`flow:` is reserved. An applier skips **the whole namespace**, not the names it happens to know, so
|
|
171
|
-
an author can record something for its own later use without the applier being taught what it means
|
|
172
|
-
and without it being mistaken for a parameter of the thing being changed.
|
|
173
|
-
|
|
174
|
-
- `flow:op` — the verb above
|
|
175
|
-
- `flow:source` — where this change came from, in the RECIPE's own terms: a stable key, the source
|
|
176
|
-
file's id plus the thing's own id there
|
|
177
|
-
- `flow:print` — a fingerprint of what the change asks for; the same print next time means nothing
|
|
178
|
-
to write
|
|
179
|
-
|
|
180
|
-
`flow:source` is not a link between elements. Nothing is written into the source, and no element
|
|
181
|
-
of the target carries it. The plugin keeps it in the target model's record of what that recipe made
|
|
182
|
-
(`revitflow_recipes.json`), which is the recipe's own bookkeeping and nobody else's.
|
|
183
|
-
|
|
184
|
-
**Every other attribute name belongs to the target application.** `Family`, `Type`, `CategoryId`,
|
|
185
|
-
`Level`, `Position` are what
|
|
186
|
-
them without needing to know what any of them mean; the plugin receiving them is the only thing that
|
|
187
|
-
does. Anything not in the receiving plugin's list of structural fields is treated as a parameter of
|
|
188
|
-
the element, which is what keeps the change vocabulary and the export vocabulary the same thing
|
|
189
|
-
rather than two things that have to be kept in step.
|
|
190
|
-
|
|
191
|
-
### What the plugin keeps
|
|
192
|
-
|
|
193
|
-
When it has applied a run, the plugin records in `revitflow_recipes.json`, for that recipe in that
|
|
194
|
-
model, which source key became which native id and with which print — the i-th result is what the
|
|
195
|
-
i-th change produced. A `remove` forgets the element it took out. On the next run that record goes
|
|
196
|
-
back to the recipe as `made` (source key → `{ id, print }`), filtered to what still exists in the
|
|
197
|
-
model, and is how an apply writes only what changed in the source.
|
|
198
|
-
|
|
199
|
-
The applier runs its verbs in passes — adds first, so a `set` can address something the same run
|
|
200
|
-
just made — but each change records its own result, so the pass order never reaches the answer.
|
|
201
|
-
|
|
202
|
-
---
|
|
203
|
-
|
|
204
|
-
## 3. The history
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
`revitflow_history.json`, a visible file.
|
|
208
|
-
|
|
209
|
-
```json
|
|
210
|
-
{
|
|
211
|
-
"model": "<stable model guid>",
|
|
212
|
-
"commits": [{
|
|
213
|
-
"guid": "36095fba-1931-4ae2-963a-fed88f26b9b2",
|
|
214
|
-
"parents": ["<guid>", "<guid>"],
|
|
215
|
-
"version": 19,
|
|
216
|
-
"message": "Moved the grid, everything follows",
|
|
217
|
-
"author": "anton",
|
|
218
|
-
"source": "revit",
|
|
219
|
-
"timestamp": "2026-07-31T12:00:00.000Z",
|
|
220
|
-
"changes": [{ "type": "create", "uniqueId": "..." }],
|
|
221
|
-
"counts": { "added": 1, "modified": 0, "removed": 0 },
|
|
222
|
-
"deltaId": "<hidden file id of this commit's delta .frag>",
|
|
223
|
-
"userId": "<platform user id>",
|
|
224
|
-
"full": false,
|
|
225
|
-
"kind": "recipe",
|
|
226
|
-
"origin": {
|
|
227
|
-
"recipe": "ifc-to-revit",
|
|
228
|
-
"title": "IFC to Revit: 6 level(s), 47 wall(s)…",
|
|
229
|
-
"source": { "folderId": "<id>", "fileId": "<id>", "name": "racbasicsampleproject.ifc", "version": "v1" }
|
|
230
|
-
}
|
|
231
|
-
}]
|
|
232
|
-
}
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
Rules, restated here because they are the part an implementer gets wrong:
|
|
236
|
-
|
|
237
|
-
- **`guid` is identity.** Minted by whoever writes the commit, never reused, meaningful outside the
|
|
238
|
-
file it lives in.
|
|
239
|
-
- **`parents` is the structure.** Absent on a root. First entry is the line this commit continues;
|
|
240
|
-
more than one means a merge. Order by walking it, breaking ties on `timestamp`.
|
|
241
|
-
- **`version` is data, never a name, and nothing may sort by it.** It is where the commit landed in
|
|
242
|
-
the CDE. An application with no such number omits it entirely.
|
|
243
|
-
- **`message` is the author's own words, and is optional.** Free text, never parsed, absent when
|
|
244
|
-
nobody said anything. Take it from wherever the application already asks:
|
|
245
|
-
with Central dialog has had a Comment box forever, so the add-in passes that through rather than
|
|
246
|
-
generating a sentence about element counts, which `changes` already says better.
|
|
247
|
-
- **`full`** means this commit re-exported the whole model, so the visible `.frag` shows the model
|
|
248
|
-
as of here. Otherwise the commit ships only its delta, in a hidden child named by `deltaId`.
|
|
249
|
-
- **`kind`** says what sort of step it was when it was not a plain sync: `upload` (a file brought
|
|
250
|
-
to the platform) or `recipe` (a sync whose changes include a recipe applied in the native
|
|
251
|
-
application). Absent means a sync.
|
|
252
|
-
- **`origin`** says, on a `recipe` commit, where the change came from: `{ recipe, recipeVersion?,
|
|
253
|
-
title, source: { folderId, fileId, name, version } }` — the recipe, the version of a project
|
|
254
|
-
recipe (absent for a built-in), what it wrote in a line, and the exact source document and
|
|
255
|
-
version it read. When several recipes were applied since the previous commit, `origins` lists
|
|
256
|
-
them all and the first is `origin`. The platform's history panel shows these commits with a recipe
|
|
257
|
-
mark and their title.
|
|
258
|
-
|
|
259
|
-
---
|
|
260
|
-
|
|
261
|
-
## 4. Collaboration in
|
|
262
|
-
|
|
263
|
-
None of this is required by the contract. It is what a file needs when its application works the way
|
|
264
|
-
|
|
265
|
-
your application must take.
|
|
266
|
-
|
|
267
|
-
### The native model
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
The `.rvt` central and its local are stored as content-addressed 64K blocks. A push walks the folder,
|
|
271
|
-
uploads only blocks nobody has seen, and writes the file-to-blocks map. Blocks are only ever added,
|
|
272
|
-
so every state the model has been in is still there, and each version's map is kept under its own
|
|
273
|
-
name so a past state can be rebuilt.
|
|
274
|
-
|
|
275
|
-
### Ownership
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
central here is a snapshot that syncs rather than a live shared file, two people on two machines can
|
|
280
|
-
both borrow the same wall and both succeed, and neither finds out until one syncs. So arbitration
|
|
281
|
-
has to happen where both machines can see it.
|
|
282
|
-
|
|
283
|
-
A claim is **state, not an event**: one file per client, holding the keys it currently holds.
|
|
284
|
-
Releasing rewrites or deletes it. Reads cost one download per live claim set, roughly per person
|
|
285
|
-
working, rather than one per edit anybody has ever made.
|
|
286
|
-
|
|
287
|
-
The race is arbitrated by **the earliest claim**, and the order comes from the file's own `_id` —
|
|
288
|
-
read from the listing, needing no download. Two clients that both find a key free and both write
|
|
289
|
-
will therefore agree, on re-reading, about which of them has it.
|
|
290
|
-
|
|
291
|
-
The two failure orders are opposite on purpose. Acquiring writes the corrected claim before deleting
|
|
292
|
-
the old one, so a crash between the two leaves you holding too much (released at the next sync).
|
|
293
|
-
Releasing deletes before writing, so a crash leaves you holding too little. Never the reverse: too
|
|
294
|
-
little is recoverable, too much locks a colleague out of an element nobody is editing.
|
|
295
|
-
|
|
296
|
-
### Turn-taking
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
One sync at a time, first come first served. A ticket **is** a hidden file, and leaving the queue
|
|
300
|
-
deletes it, so asking whose turn it is costs one listing and never grows.
|
|
301
|
-
|
|
302
|
-
It was not always. The first version was an append-only log of enqueue and dequeue documents, so
|
|
303
|
-
every reader downloaded every event ever written and paired them up. Measured on one dev document:
|
|
304
|
-
100 hidden files, refetched every 800ms while polling, which is where seven and a half seconds of a
|
|
305
|
-
sync went with nobody else in the queue. It grew with every sync anybody had ever done, forever.
|
|
306
|
-
|
|
307
|
-
A ticket older than 180 seconds is stepped over, so a client that dies mid-sync cannot hold the queue
|
|
308
|
-
for good.
|
|
309
|
-
|
|
310
|
-
---
|
|
311
|
-
|
|
312
|
-
## 5. Applying a recipe in your plugin, end to end
|
|
313
|
-
|
|
314
|
-
The recipe code is the platform's own, in `@thatopen/services`; a plugin hosts it rather than
|
|
315
|
-
reimplementing it. (The
|
|
316
|
-
C#.) The whole job, for the common case:
|
|
317
|
-
|
|
318
|
-
1. **Offer the recipes.** `client.recipes.catalog(projectId, { to: '<your app>' })` lists the
|
|
319
|
-
built-ins and the project's own; `client.recipes.choices(name, projectId)` lists the documents
|
|
320
|
-
it can read, each with its current version; the manifest's `settingsSchema` says what to ask.
|
|
321
|
-
In
|
|
322
|
-
2. **Run it.** `client.recipes.run(name, { projectId, target, input, settings, made, opId,
|
|
323
|
-
recipeVersion, progress })`, with `made` read from your model's record of what that recipe made
|
|
324
|
-
before. It answers `{ title, verb, payload, targets, ruleTallies }`, or throws `UpToDate`: say
|
|
325
|
-
so ("Nothing imported") and stop.
|
|
326
|
-
3. **Apply the payload in ONE transaction** of your application, so one undo takes it all back.
|
|
327
|
-
Refuse what you cannot build, with a reason; never approximate.
|
|
328
|
-
4. **Record what it made** (source key → native id and print) next to the model's history, and
|
|
329
|
-
which recipe, version and source version this was.
|
|
330
|
-
5. **On the next sync, say where it came from**: the commit carries `kind: "recipe"` and `origin`
|
|
331
|
-
(section 3).
|
|
332
|
-
|
|
333
|
-
That is all. No lock beyond what your application already takes for an edit, no queue, nobody else
|
|
334
|
-
to wait for. In
|
|
335
|
-
|
|
336
|
-
---
|
|
337
|
-
|
|
338
|
-
## 6. Building a collaboration layer for a new application
|
|
339
|
-
|
|
340
|
-
The contract is section 3, and nothing else. What you decide for yourself:
|
|
341
|
-
|
|
342
|
-
- **What a commit contains.** Whatever your application can honestly report as changed.
|
|
343
|
-
- **Whether ownership exists at all.**
|
|
344
|
-
For an application where teams already divide work by file, no locking may be the right answer.
|
|
345
|
-
- **How concurrent edits reconcile.**
|
|
346
|
-
is the expensive half. A central that is *reconstructed* from per-object deltas rather than
|
|
347
|
-
overwritten is buildable on stable object ids and per-commit deltas, but that is rebuilding
|
|
348
|
-
worksharing rather than configuring it.
|
|
349
|
-
- **Whether history branches.** The format allows it. Whether your application does is yours to
|
|
350
|
-
decide, and
|
|
351
|
-
|
|
352
|
-
The one thing not up for grabs: **order comes from the graph, never from a counter.** Write commits
|
|
353
|
-
with guids and parents, and every reader on the platform can already show your history alongside
|
|
354
|
-
everybody else's.
|
|
1
|
+
# Writing a flow plugin
|
|
2
|
+
|
|
3
|
+
The concrete contract. [The architecture notes](https://raw.githubusercontent.com/ThatOpen/platform_services/main/docs/flow-architecture.md) say why any of this is
|
|
4
|
+
shaped the way it is; this says what the bytes look like.
|
|
5
|
+
|
|
6
|
+
> **Plug-ins only.** Since `@thatopen/services` 0.20, apps and scripts do not write this layout by
|
|
7
|
+
> hand: `client.history(projectId)` reads and writes documents and version timelines, and
|
|
8
|
+
> `client.recipes` lists and runs the recipes that bring project data into a native application —
|
|
9
|
+
> see `src/core/examples/history.ts` in the package, and
|
|
10
|
+
> [Writing a recipe](https://raw.githubusercontent.com/ThatOpen/platform_services/main/docs/recipes-guide.md)
|
|
11
|
+
> for the recipes themselves. The bytes below are the contract for NATIVE PLUG-INS (which carry their own client),
|
|
12
|
+
> and the reference for what the API does underneath. Anything else touching these files directly
|
|
13
|
+
> will break when the layout moves behind the API, which is the plan.
|
|
14
|
+
|
|
15
|
+
Nothing here is aspirational. Every rule below is what the native tools plugins already do, and
|
|
16
|
+
was written from their implementation rather than ahead of it — which is why the awkward parts are
|
|
17
|
+
stated as plainly as the tidy ones. Where a rule exists because something broke, it says so.
|
|
18
|
+
|
|
19
|
+
The most reliable way to check any of it is the same one available to you: publish something and
|
|
20
|
+
read it back. The formats are open and the platform's file API is the whole transport.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 0. Which of these do you actually need?
|
|
25
|
+
|
|
26
|
+
Three different jobs, three different amounts of work. Pick yours before reading further.
|
|
27
|
+
|
|
28
|
+
| You want to | Implement | Sections |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| Let people bring project data into YOUR application | Run a recipe, apply the changes it returns | 1, 2, 5 |
|
|
31
|
+
| Show a model your application did not author | Read a `.frag` | 1, 3 |
|
|
32
|
+
| Let people collaborate in YOUR application | A history, plus whatever arbitration it needs | 1, 3, 4, 6 |
|
|
33
|
+
|
|
34
|
+
Applying a recipe needs no ownership registry and no collaboration layer of your own: the changes
|
|
35
|
+
are an ordinary edit in your application, made by the person working there. Writing a recipe needs
|
|
36
|
+
no plugin at all — that is
|
|
37
|
+
[Writing a recipe](https://raw.githubusercontent.com/ThatOpen/platform_services/main/docs/recipes-guide.md).
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 1. Where things live
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
The platform's file API is the whole transport. There is no flow server.
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
project
|
|
48
|
+
└── bimterop/ a folder, created on demand
|
|
49
|
+
└── revit-<documentId>/ one per model
|
|
50
|
+
├── <modelname>.frag the model, as of the last full export
|
|
51
|
+
│ └── (hidden children) per-commit delta .frag, addressed by id
|
|
52
|
+
├── revitflow_history.json the commit log
|
|
53
|
+
├── revitflow_recipes.json the recipes this model was given, and what each made
|
|
54
|
+
├── revitflow_btree.json file -> blocks, current state
|
|
55
|
+
├── revitflow_btree_<n>.json file -> blocks, as of version n
|
|
56
|
+
├── revitflow_bindex.json block -> which pack holds it
|
|
57
|
+
├── revitflow_bpack_<n>.zip the blocks first seen at version n
|
|
58
|
+
├── revitflow_version.txt the current version number
|
|
59
|
+
├── revitflow_manifest.json version, who, when
|
|
60
|
+
├── bimterop-locks-anchor a file whose hidden children are claims
|
|
61
|
+
└── revitflow-queue-anchor a file whose hidden children are queue tickets
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Visible files are named; hidden files are not.** The platform's hidden-file API has no queryable
|
|
65
|
+
name: listing by parent and fetching by id both return ids and sizes only. So every hidden file's id
|
|
66
|
+
has to be written down somewhere visible when it is created, or it is orphaned for good. That single
|
|
67
|
+
fact explains several shapes below — `deltaId` on a commit, and the use of an ordinary file as an
|
|
68
|
+
"anchor" whose only job is to be a parent.
|
|
69
|
+
|
|
70
|
+
**Two things come free with a listing, and they matter.** A hidden file's `_id` is a Mongo ObjectId
|
|
71
|
+
whose first four bytes are its creation time, so a set of hidden files is ordered by arrival without
|
|
72
|
+
downloading any of them. `owningEntity` is the platform user who created it. The sync queue and the
|
|
73
|
+
ownership registry are both built entirely out of those two facts.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 2. The changes a recipe returns
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
A recipe's `run` answers `{ title, verb, payload, targets, ruleTallies }`, or throws `UpToDate` when
|
|
81
|
+
there is nothing to write. `payload` is the changes; the plugin applies them directly, in its own
|
|
82
|
+
application. They are never uploaded and never queued: they exist between the run and the apply,
|
|
83
|
+
in memory.
|
|
84
|
+
|
|
85
|
+
`verb` is a label — `add`, `set`, `remove` or `mixed` — and is never read to decide anything,
|
|
86
|
+
because one run may add, change and remove at once. `title` is what the history row will say.
|
|
87
|
+
`ruleTallies` has one `{ read, written }` per row of the manifest's `rules`.
|
|
88
|
+
|
|
89
|
+
Recipes build the payload with `OperationBuilder` (`add`, `set`, `remove`, then `build(opId)`), so
|
|
90
|
+
nobody writes these bytes by hand; `describeChanges(payload)` reads them back as a list. What
|
|
91
|
+
follows is what that payload IS, for a plugin that has to apply it.
|
|
92
|
+
|
|
93
|
+
### The payload
|
|
94
|
+
|
|
95
|
+
A `.frag` with **no geometry at all**.
|
|
96
|
+
|
|
97
|
+
- one geometry-less item per change
|
|
98
|
+
- the target's native id in the item's `guid` — the slot the format already has for a global id
|
|
99
|
+
- the envelope, as JSON, in `Model.metadata`
|
|
100
|
+
|
|
101
|
+
A geometry-less item is a real thing the format supports, but writers get it wrong in a way that is
|
|
102
|
+
worth stating: only items that actually have vertices and indices may appear in the mesh table, and
|
|
103
|
+
an item's bounding box must not be all zeros (a zero-size box reads as absent and the reader stops
|
|
104
|
+
with "Dimension not found").
|
|
105
|
+
|
|
106
|
+
### The envelope
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"schema": "revitflow/op@2",
|
|
111
|
+
"opId": "op-9a68aceffc4e",
|
|
112
|
+
"batchId": "batch-...",
|
|
113
|
+
"targetProject": "<project id>",
|
|
114
|
+
"targetDocument": "<document id>",
|
|
115
|
+
"baseCommitGuid": "<commit guid this was authored against>",
|
|
116
|
+
"baseCommit": 18,
|
|
117
|
+
"author": "recipe:columns-from-points",
|
|
118
|
+
"title": "Columns from points: 4 change(s)",
|
|
119
|
+
"summary": "add",
|
|
120
|
+
"transform": { "translate": [0,0,0], "rotate": {"origin":[0,0,0],"axis":[0,0,1],"degrees":90} }
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`schema` is checked exactly. An applier that reads `@1` the `@2` way would not fail, it would
|
|
125
|
+
quietly do the wrong thing, so an unknown schema is refused and the recipe has to be updated.
|
|
126
|
+
|
|
127
|
+
`baseCommitGuid` / `baseCommit` name the commit of the target the changes were computed against.
|
|
128
|
+
The plugin applies them right after the run, so that is normally the model as it is; an element a
|
|
129
|
+
`set` or `remove` names that is gone all the same is reported rather than skipped quietly.
|
|
130
|
+
|
|
131
|
+
`transform` is optional and applies to every `set` item, on top of whatever its attributes change.
|
|
132
|
+
It exists alongside the per-item transform because the two answer different questions: an item's own
|
|
133
|
+
transform says "put it HERE", which is what an `add` needs; this says "move it BY this", which needs
|
|
134
|
+
no knowledge of where anything currently is.
|
|
135
|
+
|
|
136
|
+
**There is no `units` field, deliberately.** The changes edit the data an application published, so
|
|
137
|
+
its numbers are in the terms of that data — exactly as a patch over a JSON document writes the
|
|
138
|
+
fields as the document holds them. Read a position out of a published model, write it back
|
|
139
|
+
unchanged, and nothing moves. Converting from whatever the author's document uses is the
|
|
140
|
+
recipe's job, because the recipe is the only thing that knows both sides. An earlier version
|
|
141
|
+
made every change set declare its units, which looked careful and was a bug waiting to happen: it let
|
|
142
|
+
an author state a unit while writing coordinates in an axis convention the target does not use, a
|
|
143
|
+
mistake no declared unit can catch.
|
|
144
|
+
|
|
145
|
+
### Who wrote it
|
|
146
|
+
|
|
147
|
+
The envelope's `author` is free text: a recipe writes `recipe:<name>`. It is not who made the
|
|
148
|
+
change. The person who applied the recipe is, and they appear where every change of theirs appears:
|
|
149
|
+
on the commit their sync writes (section 3), whose `userId` is what the platform's own member
|
|
150
|
+
component resolves into a real name and face. Get that wrong and the commit shows up under
|
|
151
|
+
somebody else's avatar, which is worse than showing none.
|
|
152
|
+
|
|
153
|
+
**In a native plug-in there is no call that answers it**, so read the `u` claim out of the API
|
|
154
|
+
key's JWT payload (base64url, no signature check, since this only decides which name to display).
|
|
155
|
+
That is what the plugin does.
|
|
156
|
+
|
|
157
|
+
### The verbs
|
|
158
|
+
|
|
159
|
+
One per item, in the attribute `flow:op`:
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
add no guid (it does not exist yet), attributes describe it, transform says where it goes
|
|
163
|
+
set names an item by its guid; an attribute present is written, absent is left alone,
|
|
164
|
+
and an EMPTY value clears it
|
|
165
|
+
remove names an item by its guid
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### The reserved namespace
|
|
169
|
+
|
|
170
|
+
`flow:` is reserved. An applier skips **the whole namespace**, not the names it happens to know, so
|
|
171
|
+
an author can record something for its own later use without the applier being taught what it means
|
|
172
|
+
and without it being mistaken for a parameter of the thing being changed.
|
|
173
|
+
|
|
174
|
+
- `flow:op` — the verb above
|
|
175
|
+
- `flow:source` — where this change came from, in the RECIPE's own terms: a stable key, the source
|
|
176
|
+
file's id plus the thing's own id there
|
|
177
|
+
- `flow:print` — a fingerprint of what the change asks for; the same print next time means nothing
|
|
178
|
+
to write
|
|
179
|
+
|
|
180
|
+
`flow:source` is not a link between elements. Nothing is written into the source, and no element
|
|
181
|
+
of the target carries it. The plugin keeps it in the target model's record of what that recipe made
|
|
182
|
+
(`revitflow_recipes.json`), which is the recipe's own bookkeeping and nobody else's.
|
|
183
|
+
|
|
184
|
+
**Every other attribute name belongs to the target application.** `Family`, `Type`, `CategoryId`,
|
|
185
|
+
`Level`, `Position` are what the modelling tool calls its own fields in what the modelling tool publishes. A recipe copies
|
|
186
|
+
them without needing to know what any of them mean; the plugin receiving them is the only thing that
|
|
187
|
+
does. Anything not in the receiving plugin's list of structural fields is treated as a parameter of
|
|
188
|
+
the element, which is what keeps the change vocabulary and the export vocabulary the same thing
|
|
189
|
+
rather than two things that have to be kept in step.
|
|
190
|
+
|
|
191
|
+
### What the plugin keeps
|
|
192
|
+
|
|
193
|
+
When it has applied a run, the plugin records in `revitflow_recipes.json`, for that recipe in that
|
|
194
|
+
model, which source key became which native id and with which print — the i-th result is what the
|
|
195
|
+
i-th change produced. A `remove` forgets the element it took out. On the next run that record goes
|
|
196
|
+
back to the recipe as `made` (source key → `{ id, print }`), filtered to what still exists in the
|
|
197
|
+
model, and is how an apply writes only what changed in the source.
|
|
198
|
+
|
|
199
|
+
The applier runs its verbs in passes — adds first, so a `set` can address something the same run
|
|
200
|
+
just made — but each change records its own result, so the pass order never reaches the answer.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 3. The history
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
`revitflow_history.json`, a visible file.
|
|
208
|
+
|
|
209
|
+
```json
|
|
210
|
+
{
|
|
211
|
+
"model": "<stable model guid>",
|
|
212
|
+
"commits": [{
|
|
213
|
+
"guid": "36095fba-1931-4ae2-963a-fed88f26b9b2",
|
|
214
|
+
"parents": ["<guid>", "<guid>"],
|
|
215
|
+
"version": 19,
|
|
216
|
+
"message": "Moved the grid, everything follows",
|
|
217
|
+
"author": "anton",
|
|
218
|
+
"source": "revit",
|
|
219
|
+
"timestamp": "2026-07-31T12:00:00.000Z",
|
|
220
|
+
"changes": [{ "type": "create", "uniqueId": "..." }],
|
|
221
|
+
"counts": { "added": 1, "modified": 0, "removed": 0 },
|
|
222
|
+
"deltaId": "<hidden file id of this commit's delta .frag>",
|
|
223
|
+
"userId": "<platform user id>",
|
|
224
|
+
"full": false,
|
|
225
|
+
"kind": "recipe",
|
|
226
|
+
"origin": {
|
|
227
|
+
"recipe": "ifc-to-revit",
|
|
228
|
+
"title": "IFC to Revit: 6 level(s), 47 wall(s)…",
|
|
229
|
+
"source": { "folderId": "<id>", "fileId": "<id>", "name": "racbasicsampleproject.ifc", "version": "v1" }
|
|
230
|
+
}
|
|
231
|
+
}]
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Rules, restated here because they are the part an implementer gets wrong:
|
|
236
|
+
|
|
237
|
+
- **`guid` is identity.** Minted by whoever writes the commit, never reused, meaningful outside the
|
|
238
|
+
file it lives in.
|
|
239
|
+
- **`parents` is the structure.** Absent on a root. First entry is the line this commit continues;
|
|
240
|
+
more than one means a merge. Order by walking it, breaking ties on `timestamp`.
|
|
241
|
+
- **`version` is data, never a name, and nothing may sort by it.** It is where the commit landed in
|
|
242
|
+
the CDE. An application with no such number omits it entirely.
|
|
243
|
+
- **`message` is the author's own words, and is optional.** Free text, never parsed, absent when
|
|
244
|
+
nobody said anything. Take it from wherever the application already asks: the modelling tool's Synchronize
|
|
245
|
+
with Central dialog has had a Comment box forever, so the add-in passes that through rather than
|
|
246
|
+
generating a sentence about element counts, which `changes` already says better.
|
|
247
|
+
- **`full`** means this commit re-exported the whole model, so the visible `.frag` shows the model
|
|
248
|
+
as of here. Otherwise the commit ships only its delta, in a hidden child named by `deltaId`.
|
|
249
|
+
- **`kind`** says what sort of step it was when it was not a plain sync: `upload` (a file brought
|
|
250
|
+
to the platform) or `recipe` (a sync whose changes include a recipe applied in the native
|
|
251
|
+
application). Absent means a sync.
|
|
252
|
+
- **`origin`** says, on a `recipe` commit, where the change came from: `{ recipe, recipeVersion?,
|
|
253
|
+
title, source: { folderId, fileId, name, version } }` — the recipe, the version of a project
|
|
254
|
+
recipe (absent for a built-in), what it wrote in a line, and the exact source document and
|
|
255
|
+
version it read. When several recipes were applied since the previous commit, `origins` lists
|
|
256
|
+
them all and the first is `origin`. The platform's history panel shows these commits with a recipe
|
|
257
|
+
mark and their title.
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## 4. Collaboration in the modelling tool, as one worked example
|
|
262
|
+
|
|
263
|
+
None of this is required by the contract. It is what a file needs when its application works the way
|
|
264
|
+
the modelling tool does, and it is here because it is the hardest case: read it as an example, not as the shape
|
|
265
|
+
your application must take.
|
|
266
|
+
|
|
267
|
+
### The native model
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
The `.rvt` central and its local are stored as content-addressed 64K blocks. A push walks the folder,
|
|
271
|
+
uploads only blocks nobody has seen, and writes the file-to-blocks map. Blocks are only ever added,
|
|
272
|
+
so every state the model has been in is still there, and each version's map is kept under its own
|
|
273
|
+
name so a past state can be rebuilt.
|
|
274
|
+
|
|
275
|
+
### Ownership
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
the modelling tool already arbitrates ownership — against **that machine's copy of the central**. Since the
|
|
279
|
+
central here is a snapshot that syncs rather than a live shared file, two people on two machines can
|
|
280
|
+
both borrow the same wall and both succeed, and neither finds out until one syncs. So arbitration
|
|
281
|
+
has to happen where both machines can see it.
|
|
282
|
+
|
|
283
|
+
A claim is **state, not an event**: one file per client, holding the keys it currently holds.
|
|
284
|
+
Releasing rewrites or deletes it. Reads cost one download per live claim set, roughly per person
|
|
285
|
+
working, rather than one per edit anybody has ever made.
|
|
286
|
+
|
|
287
|
+
The race is arbitrated by **the earliest claim**, and the order comes from the file's own `_id` —
|
|
288
|
+
read from the listing, needing no download. Two clients that both find a key free and both write
|
|
289
|
+
will therefore agree, on re-reading, about which of them has it.
|
|
290
|
+
|
|
291
|
+
The two failure orders are opposite on purpose. Acquiring writes the corrected claim before deleting
|
|
292
|
+
the old one, so a crash between the two leaves you holding too much (released at the next sync).
|
|
293
|
+
Releasing deletes before writing, so a crash leaves you holding too little. Never the reverse: too
|
|
294
|
+
little is recoverable, too much locks a colleague out of an element nobody is editing.
|
|
295
|
+
|
|
296
|
+
### Turn-taking
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
One sync at a time, first come first served. A ticket **is** a hidden file, and leaving the queue
|
|
300
|
+
deletes it, so asking whose turn it is costs one listing and never grows.
|
|
301
|
+
|
|
302
|
+
It was not always. The first version was an append-only log of enqueue and dequeue documents, so
|
|
303
|
+
every reader downloaded every event ever written and paired them up. Measured on one dev document:
|
|
304
|
+
100 hidden files, refetched every 800ms while polling, which is where seven and a half seconds of a
|
|
305
|
+
sync went with nobody else in the queue. It grew with every sync anybody had ever done, forever.
|
|
306
|
+
|
|
307
|
+
A ticket older than 180 seconds is stepped over, so a client that dies mid-sync cannot hold the queue
|
|
308
|
+
for good.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## 5. Applying a recipe in your plugin, end to end
|
|
313
|
+
|
|
314
|
+
The recipe code is the platform's own, in `@thatopen/services`; a plugin hosts it rather than
|
|
315
|
+
reimplementing it. (The plugin runs it in a hidden WebView2 page and applies the result in
|
|
316
|
+
C#.) The whole job, for the common case:
|
|
317
|
+
|
|
318
|
+
1. **Offer the recipes.** `client.recipes.catalog(projectId, { to: '<your app>' })` lists the
|
|
319
|
+
built-ins and the project's own; `client.recipes.choices(name, projectId)` lists the documents
|
|
320
|
+
it can read, each with its current version; the manifest's `settingsSchema` says what to ask.
|
|
321
|
+
In the modelling tool this is **That Open > Select recipe**.
|
|
322
|
+
2. **Run it.** `client.recipes.run(name, { projectId, target, input, settings, made, opId,
|
|
323
|
+
recipeVersion, progress })`, with `made` read from your model's record of what that recipe made
|
|
324
|
+
before. It answers `{ title, verb, payload, targets, ruleTallies }`, or throws `UpToDate`: say
|
|
325
|
+
so ("Nothing imported") and stop.
|
|
326
|
+
3. **Apply the payload in ONE transaction** of your application, so one undo takes it all back.
|
|
327
|
+
Refuse what you cannot build, with a reason; never approximate.
|
|
328
|
+
4. **Record what it made** (source key → native id and print) next to the model's history, and
|
|
329
|
+
which recipe, version and source version this was.
|
|
330
|
+
5. **On the next sync, say where it came from**: the commit carries `kind: "recipe"` and `origin`
|
|
331
|
+
(section 3).
|
|
332
|
+
|
|
333
|
+
That is all. No lock beyond what your application already takes for an edit, no queue, nobody else
|
|
334
|
+
to wait for. In the modelling tool, steps 2 to 4 are **That Open > Update**.
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
## 6. Building a collaboration layer for a new application
|
|
339
|
+
|
|
340
|
+
The contract is section 3, and nothing else. What you decide for yourself:
|
|
341
|
+
|
|
342
|
+
- **What a commit contains.** Whatever your application can honestly report as changed.
|
|
343
|
+
- **Whether ownership exists at all.** the modelling tool's model is claimed-before-editing arbitrated centrally.
|
|
344
|
+
For an application where teams already divide work by file, no locking may be the right answer.
|
|
345
|
+
- **How concurrent edits reconcile.** the modelling tool has a merge engine; most applications do not, and this
|
|
346
|
+
is the expensive half. A central that is *reconstructed* from per-object deltas rather than
|
|
347
|
+
overwritten is buildable on stable object ids and per-commit deltas, but that is rebuilding
|
|
348
|
+
worksharing rather than configuring it.
|
|
349
|
+
- **Whether history branches.** The format allows it. Whether your application does is yours to
|
|
350
|
+
decide, and the modelling tool's cannot: its central is a single line.
|
|
351
|
+
|
|
352
|
+
The one thing not up for grabs: **order comes from the graph, never from a counter.** Write commits
|
|
353
|
+
with guids and parents, and every reader on the platform can already show your history alongside
|
|
354
|
+
everybody else's.
|