comfy_builder_core/attributes.rs
1use pyo3::types::PyAnyMethods;
2use pyo3::{Bound, FromPyObject, PyAny, PyResult};
3use std::ops::Deref;
4
5/// UNIQUE_ID is the unique identifier of the node, and matches the id property of the node on the client side.
6/// It is commonly used in client-server communications.
7/// see https://docs.comfy.org/development/comfyui-server/comms_messages#getting-node-id
8#[derive(Debug)]
9pub struct UniqueId(pub String);
10
11/// PROMPT is the complete prompt sent by the client to the server.
12/// See [the prompt object](https://docs.comfy.org/custom-nodes/js/javascript_objects_and_hijacking#prompt) for a full description.
13#[derive(Debug)]
14pub struct Prompt(pub String);
15
16/// EXTRA_PNGINFO is a dictionary that will be copied into the metadata of any .png files saved.
17/// Custom nodes can store additional information in this dictionary for saving (or as a way to communicate with a downstream node).
18#[derive(Debug)]
19pub struct ExtraPngInfo(pub String);
20
21/// DYNPROMPT is an instance of comfy_execution.graph.DynamicPrompt.
22/// It differs from PROMPT in that it may mutate during the course of execution in response to [Node Expansion](https://docs.comfy.org/custom-nodes/backend/expansion).
23#[derive(Debug)]
24pub struct DynPrompt(pub String);
25
26impl Deref for UniqueId {
27 type Target = String;
28
29 fn deref(&self) -> &Self::Target {
30 &self.0
31 }
32}
33
34impl<'py> FromPyObject<'py> for UniqueId {
35 fn extract_bound(object: &Bound<'py, PyAny>) -> PyResult<Self> {
36 object
37 .extract::<String>()
38 .map(UniqueId)
39 }
40}
41
42impl<'py> FromPyObject<'py> for Prompt {
43 fn extract_bound(object: &Bound<'py, PyAny>) -> PyResult<Self> {
44 // @todo convert from dict to json string
45 Ok(Prompt(object.to_string()))
46 }
47}
48
49impl<'py> FromPyObject<'py> for ExtraPngInfo {
50 fn extract_bound(object: &Bound<'py, PyAny>) -> PyResult<Self> {
51 // @todo convert from dict to json string
52 Ok(ExtraPngInfo(object.to_string()))
53 }
54}
55
56impl<'py> FromPyObject<'py> for DynPrompt {
57 fn extract_bound(object: &Bound<'py, PyAny>) -> PyResult<Self> {
58 // @todo convert from comfy_execution.graph.DynamicPrompt to a better format
59 Ok(DynPrompt(object.to_string()))
60 }
61}