# Artifacts and projects

The five artifact kinds, their API, their routes, and how PINTER Space projects moved to the server.

Artifacts replace the old dashboard-only store. One table holds five kinds, and
every kind has the same metadata shape, so a list page, a share link, and a
desktop deep link work the same way for all of them.

## Artifact kinds

| `kind` | Content | Opened by |
| --- | --- | --- |
| `dashboard` | Panels and saved queries in `spec` | Dashboard renderer on `/artefacts/{id}` |
| `note` | Markdown in `spec.markdown` | PINTER Desktop editor |
| `visual` | HTML in `spec.html` | PINTER Desktop editor |
| `image` | Bytes in object storage, `mime` and `size_bytes` set | Download |
| `file` | Bytes in object storage, `mime` and `size_bytes` set | Download |

`image` and `file` never go through `POST /api/artifacts`; they are created by
the upload endpoint and are rejected elsewhere with `kind_requires_upload`.
The API path uses `artifact` in code. Only user-facing Indonesian text says
"Artefak".

## Routes

| Route | Contents |
| --- | --- |
| `/artefacts` | Artifact list. |
| `/artefacts/{artifactId}` | Artifact detail. |
| `/share/a/{artifactId}` | Artifact detail through a share link. |
| `/dashboards` | Redirects to `/artefacts`. |
| `/dashboards/{dashboardId}` | Redirects to `/artefacts/{dashboardId}`. |
| `/share/dash/{dashboardId}` | Redirects to `/share/a/{dashboardId}`. |
| `/space` | Project hub. Desktop renders `SpacePage`, web renders `ProjectsHubPage`. |

Redirects run in `beforeLoad` with `throw redirect({ to: ... })`, never in a
`useEffect`.

## Desktop deep link

`pinter://artifact/{id}` opens PINTER Desktop on `/artefacts/{id}`. The id must
be a UUID; anything else is ignored instead of crashing the app.

The web detail page shows **Buka di PINTER** for `dashboard`, `note`, and
`visual`. `image` and `file` only offer a download.

## Projects

Projects moved from the desktop file `projects.json` to `projects` rows owned by
the API.

- `GET /api/projects`, `POST /api/projects`, `GET|PATCH|DELETE /api/projects/{id}`.
- `GET|POST /api/projects/{id}/files` and `DELETE /api/projects/{id}/files/{document_id}`
  link Knowledge Hub documents. A project file is a document link, not a copy.
- `PATCH /api/projects/{id}/share` sets internal grants only. Projects have no
  public link in this release.

Project files feed the chat through three things: a manifest in the system
prompt, the `search_project_files` tool, and `@` mentions. Mentions must be
resolved from the file slug, because composer mention tokens stop at a space.

## Moving desktop projects

`POST /api/projects/import` takes archived desktop projects and is idempotent on
`(owner_id, legacy_id)`:

```json
{
  "projects": [
    {
      "legacy_id": "p-1730",
      "name": "Proyek Pupuk",
      "description": "",
      "instructions": "",
      "conversation_ids": ["c-1", "c-2"]
    }
  ]
}
```

The response is `{"created": 1, "skipped": 0, "id_map": {"p-1730": "uuid"}}`.
Conversations whose `project_id` still holds a legacy id are moved to the new
UUID, which is why `conversations.project_id` stays `TEXT`.

What moves and what does not:

| Moves | Stays behind |
| --- | --- |
| Name, description, instructions | Attached local files |
| Conversation ids | Everything under the old Space folder |

After a successful import the API is the only writer. PINTER Desktop keeps
`projects.json` as a read-only archive and stores the returned `id_map` in
`projects.imported.json`, so a rollback needs no file surgery. When the network
fails the import writes nothing.

The project **Files** tab then starts empty, with a **Tautkan dari Knowledge Hub**
action. Old project files are not uploaded and are not reachable from the
project until they are linked as Knowledge Hub documents.

## Errors

Errors arrive as `detail: {"code": "...", "message": "..."}`.

| Case | Status | `code` |
| --- | --- | --- |
| Note or visual above 262144 bytes | 413 | `artifact_too_large` |
| File above 26214400 bytes | 413 | `file_too_large` |
| User artifact bytes above 1073741824 | 409 | `artifact_quota_exceeded` |
| Extension or mime outside the allowlist | 415 | `file_type_not_allowed` |
| `spec` does not match the kind | 422 | `kind_content_mismatch` |
| `POST /api/artifacts` with kind `image` or `file` | 422 | `kind_requires_upload` |
| `spec` change on `image` or `file` | 409 | `kind_immutable` |
| `/query` or `/export` on a non-dashboard kind | 422 | `kind_mismatch` |
| `project_id` not owned by the caller | 403 | `project_forbidden` |
| More than 50 project files | 409 | `project_files_limit` |
| More than 3 mentions or 32768 bytes | 413 | `mention_too_large` |
