Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
model_store.hpp
Go to the documentation of this file.
1#pragma once
2
3// Generic model store/state primitive. Owns the on-disk
4// layout under PULP_HOME (`<home>/<subsystem>/model-state.json` for the active model,
5// `<home>/<subsystem>/models/<id>.json` for per-model install metadata), the
6// installed/active queries, list (over a caller-supplied registry), and activate.
7// Parameterized by `subsystem` (e.g. "audio", "magenta") so multiple consumers share
8// one mechanism. Install/remove stream checkpoints through the runtime downloader.
9
10#include <filesystem>
11#include <functional>
12#include <string>
13#include <string_view>
14#include <utility>
15#include <vector>
16
18
19namespace pulp::runtime {
20class CancelToken; // cancel.hpp
21}
22
23namespace pulp::runtime {
24
26 std::filesystem::path metadata_path;
27 bool metadata_found = false;
28 std::string model_id;
29 std::string backend;
30 std::string checkpoint_ref;
31 std::filesystem::path resolved_checkpoint_path;
32 bool checkpoint_exists = false;
33
34 [[nodiscard]] bool loadable() const { return metadata_found && checkpoint_exists; }
35};
36
39 std::string status = "not_installed"; // installed | missing_checkpoint | partial | not_installed
40 bool active = false;
41 std::filesystem::path resolved_checkpoint_path;
42 float partial_fraction = -1.0f; // >= 0 when a resumable .part exists (downloaded/total)
43};
44
46 std::filesystem::path pulp_home;
47 std::string active_model_id;
48 std::vector<ListedModel> models;
49 std::string error;
50};
51
53 bool ok = false;
54 std::filesystem::path state_path;
55 std::string active_model_id;
56 std::string backend;
57 std::string checkpoint_ref;
58 std::filesystem::path resolved_checkpoint_path;
59 std::string error;
60};
61
62// PULP_HOME resolution: explicit override → $PULP_HOME → $HOME/.pulp (USERPROFILE on
63// Windows). NOTE (path policy): a sandboxed AUv3/iOS host may not have HOME
64// access — callers in those contexts should pass an explicit container path.
65std::filesystem::path resolve_pulp_home(const std::filesystem::path& override_path = {});
66
67std::filesystem::path model_state_path(std::string_view subsystem,
68 const std::filesystem::path& pulp_home_override = {});
69std::filesystem::path model_install_path(std::string_view subsystem, std::string_view model_id,
70 const std::filesystem::path& pulp_home_override = {});
71InstalledModelRecord read_installed_model(std::string_view subsystem, std::string_view model_id,
72 const std::filesystem::path& pulp_home_override = {});
73std::string read_active_model_id(std::string_view subsystem,
74 const std::filesystem::path& pulp_home_override = {});
75ModelListResult list_models(const std::vector<ModelEntry>& registry, std::string_view subsystem,
76 const std::filesystem::path& pulp_home_override = {});
77ActivateModelResult activate_model(const std::vector<ModelEntry>& registry, std::string_view subsystem,
78 std::string_view model_id,
79 const std::filesystem::path& pulp_home_override = {});
80
81std::string to_json(const ModelListResult& result);
82std::string to_json(const ActivateModelResult& result);
83
84// ---- install / remove (streaming, resumable, sha256-verified downloader) -----------
85
87 bool ok = false;
88 std::string error;
89 bool cancelled = false;
90 std::filesystem::path checkpoint_path; // downloaded file
91 std::filesystem::path metadata_path; // <home>/<subsystem>/models/<id>.json
92 std::string sha256;
93};
94
102install_model(const ModelEntry& model, std::string_view subsystem,
103 const std::function<bool(const struct DownloadProgress&)>& on_progress = {},
104 const CancelToken* cancel = nullptr,
105 const std::vector<std::pair<std::string, std::string>>& headers = {},
106 const std::filesystem::path& pulp_home_override = {}, bool allow_unverified = false);
107
111bool remove_model(std::string_view subsystem, std::string_view model_id, std::string& error,
112 const std::filesystem::path& pulp_home_override = {});
113
114} // namespace pulp::runtime
Definition cancel.hpp:77
Definition generated_event_source.hpp:33
std::string to_json(const ModelListResult &result)
bool remove_model(std::string_view subsystem, std::string_view model_id, std::string &error, const std::filesystem::path &pulp_home_override={})
Delete an installed model's files + metadata.
ActivateModelResult activate_model(const std::vector< ModelEntry > &registry, std::string_view subsystem, std::string_view model_id, const std::filesystem::path &pulp_home_override={})
ModelListResult list_models(const std::vector< ModelEntry > &registry, std::string_view subsystem, const std::filesystem::path &pulp_home_override={})
std::filesystem::path model_install_path(std::string_view subsystem, std::string_view model_id, const std::filesystem::path &pulp_home_override={})
std::filesystem::path model_state_path(std::string_view subsystem, const std::filesystem::path &pulp_home_override={})
std::string read_active_model_id(std::string_view subsystem, const std::filesystem::path &pulp_home_override={})
InstallModelResult install_model(const ModelEntry &model, std::string_view subsystem, const std::function< bool(const struct DownloadProgress &)> &on_progress={}, const CancelToken *cancel=nullptr, const std::vector< std::pair< std::string, std::string > > &headers={}, const std::filesystem::path &pulp_home_override={}, bool allow_unverified=false)
Download model's checkpoint into <home>/<subsystem>/models/<id>/ (streaming, resumable,...
std::filesystem::path resolve_pulp_home(const std::filesystem::path &override_path={})
InstalledModelRecord read_installed_model(std::string_view subsystem, std::string_view model_id, const std::filesystem::path &pulp_home_override={})
Definition model_store.hpp:52
bool ok
Definition model_store.hpp:53
std::filesystem::path state_path
Definition model_store.hpp:54
std::string checkpoint_ref
Definition model_store.hpp:57
std::string error
Definition model_store.hpp:59
std::filesystem::path resolved_checkpoint_path
Definition model_store.hpp:58
std::string backend
Definition model_store.hpp:56
std::string active_model_id
Definition model_store.hpp:55
Definition model_download.hpp:21
Definition model_store.hpp:86
std::string error
Definition model_store.hpp:88
std::filesystem::path metadata_path
Definition model_store.hpp:91
std::string sha256
Definition model_store.hpp:92
bool ok
Definition model_store.hpp:87
bool cancelled
Definition model_store.hpp:89
std::filesystem::path checkpoint_path
Definition model_store.hpp:90
Definition model_store.hpp:25
bool checkpoint_exists
Definition model_store.hpp:32
std::string checkpoint_ref
Definition model_store.hpp:30
std::string backend
Definition model_store.hpp:29
bool loadable() const
Definition model_store.hpp:34
bool metadata_found
Definition model_store.hpp:27
std::filesystem::path metadata_path
Definition model_store.hpp:26
std::string model_id
Definition model_store.hpp:28
std::filesystem::path resolved_checkpoint_path
Definition model_store.hpp:31
Definition model_store.hpp:37
float partial_fraction
Definition model_store.hpp:42
ModelEntry model
Definition model_store.hpp:38
std::filesystem::path resolved_checkpoint_path
Definition model_store.hpp:41
std::string status
Definition model_store.hpp:39
bool active
Definition model_store.hpp:40
Definition model_registry.hpp:25
Definition model_store.hpp:45
std::vector< ListedModel > models
Definition model_store.hpp:48
std::filesystem::path pulp_home
Definition model_store.hpp:46
std::string error
Definition model_store.hpp:49
std::string active_model_id
Definition model_store.hpp:47