@paradigma-inc/flywheel 0.1.16 → 0.1.19

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.
@@ -1,218 +1,49 @@
1
1
  # Flywheel Artifacts
2
2
 
3
- Canonical reference for node artifact publishing in Flywheel MCP 0.9.
4
-
5
- Legacy note:
6
-
7
- - historical `run_artifacts` rows are retained for backward reads.
8
- - new artifact writes must use the MCP batch upload workflow:
9
- `flywheel_prepare_artifact_uploads` -> raw file upload(s) ->
10
- `flywheel_finalize_artifact_uploads`.
11
-
12
- ## Node MCP Contract
13
-
14
- Artifacts are managed through node MCP tools:
15
-
16
- - `flywheel_prepare_artifact_uploads` prepares one or more signed raw-file
17
- upload requests for a node.
18
- - The caller executes each returned upload request with raw bytes.
19
- - `flywheel_finalize_artifact_uploads` appends all staged uploads in that batch
20
- to the node and bumps node revision once.
21
- - `flywheel_list_artifacts` and `flywheel_get_artifact` return artifact
22
- metadata.
23
- - `flywheel_get_artifact_preview` reads persisted preview payload content by
24
- artifact id.
25
- - `flywheel_commit_node` commits/finalizes node state after terminal fields are
26
- already staged.
27
-
28
- Contract rules:
29
-
30
- - `flywheel_prepare_artifact_uploads` requires `expected_revision` and enforces
31
- optimistic locking before issuing upload tickets.
32
- - Upload uses the signed one-time ticket in each returned `upload_url`;
33
- client-supplied path/reference fields are not part of this contract.
34
- - Raw upload only stages payloads. It does not mutate node state or bump node
35
- revision.
36
- - `flywheel_finalize_artifact_uploads` is the single node mutation point for an
37
- artifact batch.
38
- - `flywheel_commit_node` is finalize-only:
39
- - request shape is `expected_revision` with optional `summary` override.
40
- - node kind/outcome/hypothesis/insights/no_artifacts_reason must already be
41
- staged.
42
- - commit transitions lifecycle to `committed`.
43
- - committed node contract rules remain strict:
44
- - `kind=empirical` + `outcome=completed` requires artifacts or
45
- `no_artifacts_reason`.
46
- - `kind=insight` requires non-empty `insights`.
47
- - `kind=empirical` requires empty `insights`.
48
- - MCP mutating calls require idempotency:
49
- - tool transport auto-manages idempotency keys for tool calls.
50
- - direct HTTP callers must provide `Idempotency-Key` on mutating MCP
51
- endpoints.
52
-
53
- `artifact_type=banner` is supported for campaign root visuals. It follows the
54
- same raw image upload validation path as `artifact_type=image` and is intended
55
- for zoomed-out canvas visibility.
56
-
57
- ## Prepare Request Shape
58
-
59
- `POST /mcp/nodes/{node_id}/artifacts/uploads/prepare`
60
-
61
- ```json
62
- {
63
- "expected_revision": 7,
64
- "items": [
65
- {
66
- "artifact_type": "image",
67
- "title": "Loss curve",
68
- "execution_id": "optional-execution-id",
69
- "metadata": {
70
- "source": "training-run"
71
- },
72
- "filename": "loss_curve.png",
73
- "media_type": "image/png"
74
- }
75
- ]
76
- }
77
- ```
78
-
79
- Notes:
80
-
81
- - `items` must contain at least one structured object item.
82
- - String or JSON-encoded item payloads are invalid at the tool boundary.
83
- - `filename` and `media_type` are required for each item.
84
- - `metadata` is caller-defined JSON.
85
-
86
- ## Prepare Response Shape
87
-
88
- ```json
89
- {
90
- "batch": {
91
- "batch_token": "uuid",
92
- "expires_at": "2026-03-09T16:00:00+00:00",
93
- "max_upload_bytes": 10485760,
94
- "items": [
95
- {
96
- "upload_id": "uuid",
97
- "upload_url": "https://.../mcp/artifacts/uploads/{upload_id}?ticket=...",
98
- "method": "PUT",
99
- "headers": {
100
- "Content-Type": "image/png",
101
- "X-Flywheel-Artifact-Filename": "loss_curve.png"
102
- },
103
- "curl_command": "curl -sS -X PUT '...' -H 'Content-Type: image/png' -H 'X-Flywheel-Artifact-Filename: loss_curve.png' --data-binary @/absolute/path/to/file"
104
- }
105
- ]
106
- }
107
- }
108
- ```
109
-
110
- ## Raw Upload Step
111
-
112
- Execute each returned request exactly:
113
-
114
- - Method: `PUT`
115
- - URL: `batch.items[i].upload_url`
116
- - Body: raw file bytes
117
- - Headers:
118
- - `Content-Type` (media type)
119
- - `X-Flywheel-Artifact-Filename` (filename hint)
120
-
121
- A successful upload:
122
-
123
- - validates the uploaded bytes against the requested artifact type
124
- - stages canonical payload JSON in blob storage
125
- - returns `202 Accepted`
126
- - does not yet append an artifact record to the node
127
-
128
- ## Finalize Request and Response
129
-
130
- `POST /mcp/nodes/{node_id}/artifacts/uploads/finalize`
131
-
132
- ```json
133
- {
134
- "batch_token": "uuid"
135
- }
136
- ```
137
-
138
- Successful finalize:
139
-
140
- - validates the batch is complete and still revision-compatible
141
- - appends all staged artifacts to the node
142
- - persists canonical payload JSON to `artifacts/nodes/{node_id}/{artifact_id}.json`
143
- - bumps node revision once
144
- - returns `{ "node": ..., "artifacts": [...] }`
145
-
146
- ## Artifact Preview Behavior
147
-
148
- Artifact preview endpoint:
149
- `GET /mcp/nodes/{node_id}/artifacts/{artifact_id}/preview`.
150
- MCP tool: `flywheel_get_artifact_preview`.
151
-
152
- - Preview reads canonical persisted payload blob (`storage_path`) only.
153
- - No workspace dependency or local-file fallback is required.
154
- - `data_url` in preview responses is render output only; never upload JSON
155
- metadata wrappers.
156
- - Preview-normalized types:
157
- - `image` -> image payload with `data_url`
158
- - `html` / `plotly_html` -> HTML payload
159
- - `json` -> JSON payload
160
- - `text` / `diff_carousel` and common text/code extensions -> text payload
161
-
162
- ## WebUI Artifact Payload Reads
163
-
164
- When artifacts are projected through node responses, the server returns
165
- normalized storage references for each artifact payload:
166
-
167
- - `storage_path`: canonical blob path (for example
168
- `artifacts/nodes/{node_id}/{artifact_id}.json`).
169
- - `storage_url`: the single client/host read URL for that payload.
170
- - All blob backends: `/blobs/{storage_path}` authenticated byte-serving
171
- proxy after access checks.
172
-
173
- Clients should read artifact bytes from `storage_url` only. `storage_path`
174
- remains metadata/debug context and must not be reconstructed into fetch URLs by
175
- clients. Payload loads are coordinated through a shared loader with in-flight
176
- deduplication, cache reuse, and bounded fetch concurrency to avoid bursty
177
- request storms and `429` backpressure under artifact-heavy nodes.
178
-
179
- The node overview panel additionally avoids eager load spikes by defaulting to
180
- collapsed mode for artifact-heavy nodes and deferring artifact rendering until
181
- cards approach the viewport.
182
-
183
- ## Artifact Load Telemetry
184
-
185
- The WebUI emits a batched first-party product analytics event,
186
- `web_artifact_payload_batch`, through `POST /analytics/events`.
187
-
188
- This event is intended for aggregate artifact read-path observability and
189
- includes fields such as:
190
-
191
- - load volume (`loads_started`, `loads_completed`, `loads_failed`)
192
- - rate-limit incidence (`loads_429`)
193
- - queue/load latency aggregates
194
- - source mix (`/blobs/*` authenticated proxy)
195
- - top per-node load/failure summaries in the batch window
196
-
197
- ## File Inventory Surfaces
198
-
199
- Artifacts and attachments are exposed through two HTTP inventory endpoints:
200
-
201
- - `GET /users/me/files` for account-wide browsing in Settings.
202
- - `GET /nodes/{node_id}/files` for node lineage-scoped browsing in the node
203
- details panel.
204
-
205
- Inventory entries include source context (`node_id`, `execution_id`) so the UI
206
- can jump directly to the originating node or execution.
207
-
208
- ## Common Invalid Payload Causes
209
-
210
- - stale `expected_revision` at prepare or finalize time
211
- - missing/invalid upload ticket
212
- - expired upload ticket or batch
213
- - upload body exceeds configured size limit
214
- - uploaded bytes do not match requested artifact format (for example invalid
215
- JSON)
216
- - finalize called before every prepared upload is staged
217
- - commit contract violations (for example empirical `completed` without
218
- artifacts or `no_artifacts_reason`)
3
+ Canonical artifact upload/finalize contract derived from `mcp_contract.py`.
4
+
5
+ ## Upload Contract
6
+
7
+ - Prepare tool: `flywheel_prepare_artifact_uploads`.
8
+ - Finalize tool: `flywheel_finalize_artifact_uploads`.
9
+ - Raw file upload required between prepare/finalize: `True`.
10
+ - Upload transport step: `PUT` to `prepare.items[].upload_url`.
11
+ - Required headers source: `prepare.items[].upload_headers`.
12
+ - Upload body contract: `raw_file_bytes`.
13
+ - Prepare item required fields: `artifact_type`, `filename`, `media_type`.
14
+ - Prepare item optional fields: `title`, `execution_id`, `metadata`, `note`.
15
+ - Prepare item note: prepare.items[] is structured object input at the tool boundary; stringified JSON payloads are invalid.
16
+ - Raw upload stage success code: `202`.
17
+ - Stage semantics: `accepted_and_staged`.
18
+ - Finalize appends the batch with a single revision bump: `True`.
19
+ - Forbidden upload payload kinds: `json_metadata_wrapper`.
20
+ - Optional note field `note` applies to `artifact_metadata_record` (markdown allowed: `True`).
21
+
22
+ ## Supported Artifact Types
23
+
24
+ - `text`, `table`, `json`, `image`, `banner`, `html`, `plotly_html`, `vega`, `checkpoint`, `binary`, `diff_carousel`
25
+
26
+ ## Metadata Contract
27
+
28
+ - `title` required non-empty: `True`.
29
+ - Display label field: `title`.
30
+ - Title normalization priority: `explicit_title` -> `payload.title` -> `payload.name` -> `basename(payload.path|payload.filename|payload.file)` -> `basename(filename)` -> `basename(storage_path)` -> `artifact_type` -> `artifact`.
31
+ - Title must not derive from: `storage_url`.
32
+ - `storage_url` purpose: `raw_artifact_byte_read_url`.
33
+ - `storage_url` cannot be used as display label: `True`.
34
+
35
+ ## Preview and Read Contract
36
+
37
+ - `flywheel_list_artifacts`: List node artifacts.
38
+ - `flywheel_get_artifact`: Get one artifact by id.
39
+ - No dedicated artifact preview tool exists in the current MCP operation catalog.
40
+ - Guidance: use flywheel_prepare_artifact_uploads, raw-file upload, and flywheel_finalize_artifact_uploads to publish experiment evidence before empirical completed commits
41
+
42
+ ## Failure Causes to Handle Explicitly
43
+
44
+ - Stale `expected_revision` on mutating calls returns `409` and requires explicit reconciliation.
45
+ - Reusing an idempotency key with a different payload hash causes `409_conflict`.
46
+ - Empirical `completed` commits must satisfy one of: `artifacts_non_empty`, `no_artifacts_reason_non_empty`.
47
+ - Prepare item payloads must be structured objects; stringified JSON item payloads are invalid.
48
+ - Uploading metadata wrappers instead of raw file bytes violates the upload contract.
49
+ - Finalize requires a valid prepared batch token and staged uploads from that batch.