mirror of
https://github.com/vegu-ai/talemate.git
synced 2026-09-03 04:30:14 +02:00
405 lines
11 KiB
Markdown
405 lines
11 KiB
Markdown
|
|
# Dict And List Nodes
|
||
|
|
|
||
|
|
Build and manipulate dictionaries and lists. The **Dict Collector** and **List Collector** aggregate any number of inputs through dynamic sockets — see [Collector Nodes](../../core-concepts/collector_nodes.md) for how key inference works with **Make Key-Value Pair**.
|
||
|
|
|
||
|
|
<!-- glossary:generated - everything below this line is generated by `python -m talemate.game.engine.nodes.tools glossary --write` - do not edit -->
|
||
|
|
|
||
|
|
|
||
|
|
_14 nodes._
|
||
|
|
|
||
|
|
| Node | Registry path |
|
||
|
|
| --- | --- |
|
||
|
|
| [Combine Lists](#combine-lists) | `data/CombineLists` |
|
||
|
|
| [Dict Collector](#dict-collector) | `data/DictCollector` |
|
||
|
|
| [Dict Get](#dict-get) | `data/DictGet` |
|
||
|
|
| [Dict Get (Path)](#dict-get-path) | `data/DictGetPath` |
|
||
|
|
| [Dict To Key-Value Pairs](#dict-to-key-value-pairs) | `data/DictKeyValuePairs` |
|
||
|
|
| [Dict Pop](#dict-pop) | `data/DictPop` |
|
||
|
|
| [Dict Set](#dict-set) | `data/DictSet` |
|
||
|
|
| [Dict Update](#dict-update) | `data/DictUpdate` |
|
||
|
|
| [List Append](#list-append) | `data/ListAppend` |
|
||
|
|
| [List Collector](#list-collector) | `data/ListCollector` |
|
||
|
|
| [List Remove](#list-remove) | `data/ListRemove` |
|
||
|
|
| [Make Dict](#make-dict) | `data/MakeDict` |
|
||
|
|
| [Make Key-Value Pair](#make-key-value-pair) | `data/MakeKeyValuePair` |
|
||
|
|
| [Make List](#make-list) | `data/MakeList` |
|
||
|
|
|
||
|
|
## Combine Lists
|
||
|
|
|
||
|
|
`data/CombineLists`
|
||
|
|
|
||
|
|
Combines multiple lists into a single list
|
||
|
|
|
||
|
|
Each connected dynamic input must be a list; their items are appended
|
||
|
|
to the result in socket order.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `list` | `list` | (optional) Base list to extend (optional - a new list is created if not provided) |
|
||
|
|
|
||
|
|
This node supports **dynamic inputs** - additional input sockets can be added in the editor as needed, and connected values are collected with key inference (see [Collector Nodes](../../core-concepts/collector_nodes.md)).
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `list` | `list` | The combined list |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `create_copy` | `bool` | `True` | Create a copy of the list |
|
||
|
|
|
||
|
|
## Dict Collector
|
||
|
|
|
||
|
|
`data/DictCollector`
|
||
|
|
|
||
|
|
Collects key-value pairs into a dictionary with dynamic inputs.
|
||
|
|
New item sockets appear as connections are made.
|
||
|
|
|
||
|
|
For each connected item the key is inferred: if the value is a
|
||
|
|
(key, value) tuple (e.g., from Make Key-Value Pair) that key is used;
|
||
|
|
otherwise the key is derived from the source socket - for sockets named
|
||
|
|
`value`, the source node's `name`, `key` or `attribute` input is used,
|
||
|
|
falling back to the source socket name.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `dict` | `dict` | (optional) Base dictionary to collect into (optional - a new dictionary is created if not provided) |
|
||
|
|
|
||
|
|
This node supports **dynamic inputs** - additional input sockets can be added in the editor as needed, and connected values are collected with key inference (see [Collector Nodes](../../core-concepts/collector_nodes.md)).
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `dict` | `dict` | The collected dictionary |
|
||
|
|
|
||
|
|
## Dict Get
|
||
|
|
|
||
|
|
`data/DictGet`
|
||
|
|
|
||
|
|
Retrieves a value from a dictionary
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `dict` | `dict` | Dictionary |
|
||
|
|
| `key` | `str` | Key |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `value` | `any` | The value for the key, or None if the key is not present |
|
||
|
|
| `key` | `str` | The key input, passed through |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `key` | `str` | `unset` | Key |
|
||
|
|
|
||
|
|
## Dict Get (Path)
|
||
|
|
|
||
|
|
`data/DictGetPath`
|
||
|
|
|
||
|
|
Retrieves a value from a nested dict (or list-of-dicts) using a dotted path.
|
||
|
|
|
||
|
|
Supports:
|
||
|
|
- Nested dict keys: "modes.generate_arc.close_arc"
|
||
|
|
- List indices: "items.0.name"
|
||
|
|
- Missing paths return the `default` input (or None if unset)
|
||
|
|
- Any non-traversable segment short-circuits to `default`
|
||
|
|
|
||
|
|
Downstream DynamicSocketNodeBase collectors (DictCollector, UpdateObject)
|
||
|
|
auto-infer the collector key from the last segment of `path` via the
|
||
|
|
`key` property set during run(). E.g. `modes.generate_arc.close_arc`
|
||
|
|
yields a collector key of `close_arc`.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `dict` | `dict` | Dictionary (or any traversable structure) |
|
||
|
|
| `path` | `str` | (optional) Dotted path string |
|
||
|
|
| `default` | `any` | Fallback value when the path does not fully resolve (optional) |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `value` | `any` | The resolved value, or `default` if the path does not resolve |
|
||
|
|
| `found` | `bool` | True if the full path was resolved, False if default was used |
|
||
|
|
| `path` | `str` | The path that was attempted (echoed for graph readability) |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `path` | `str` | `""` | Dotted path to the value (e.g. 'modes.generate_arc.close_arc') |
|
||
|
|
|
||
|
|
## Dict To Key-Value Pairs
|
||
|
|
|
||
|
|
`data/DictKeyValuePairs`
|
||
|
|
|
||
|
|
Creates a list of key-value pairs from a dictionary
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `dict` | `dict` | Dictionary to convert |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `dict` | `dict` | The dict input, passed through |
|
||
|
|
| `kvs` | `list` | List of (key, value) tuples |
|
||
|
|
|
||
|
|
## Dict Pop
|
||
|
|
|
||
|
|
`data/DictPop`
|
||
|
|
|
||
|
|
Pops a value from a dictionary
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `dict` | `dict` | Dictionary |
|
||
|
|
| `key` | `str` | Key |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `dict` | `dict` | The dictionary with the key removed |
|
||
|
|
| `value` | `any` | The popped value, or None if the key was not present |
|
||
|
|
| `key` | `str` | The key input, passed through |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `key` | `str` | `unset` | Key |
|
||
|
|
|
||
|
|
## Dict Set
|
||
|
|
|
||
|
|
`data/DictSet`
|
||
|
|
|
||
|
|
Set a value in a dictionary
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `dict` | `dict` | (optional) Dictionary - if not provided, a new dictionary will be created |
|
||
|
|
| `key` | `str` | (optional) Key |
|
||
|
|
| `value` | `any` | Value |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `dict` | `dict` | Dictionary |
|
||
|
|
| `key` | `str` | Key |
|
||
|
|
| `value` | `any` | Value |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `key` | `str` | `unset` | Key |
|
||
|
|
|
||
|
|
## Dict Update
|
||
|
|
|
||
|
|
`data/DictUpdate`
|
||
|
|
|
||
|
|
Updates a dictionary from a list of other dictionaries
|
||
|
|
|
||
|
|
Each dictionary in the list is applied in order. By default this is a
|
||
|
|
shallow dict.update(); enable merge to deep-merge nested dictionaries
|
||
|
|
instead of replacing them. By default the target dictionary is modified
|
||
|
|
in place; enable create_copy to leave the input untouched.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `state` | `any` | The graph state |
|
||
|
|
| `dict` | `dict` | The target dictionary to update |
|
||
|
|
| `dicts` | `list` | List of dictionaries to apply to the target |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `state` | `any` | The state input, passed through |
|
||
|
|
| `dict` | `dict` | The updated dictionary |
|
||
|
|
| `dicts` | `list` | The dicts input, passed through |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `create_copy` | `bool` | `False` | Create a copy of the dictionary |
|
||
|
|
| `merge` | `bool` | `False` | Perform a deep merge |
|
||
|
|
|
||
|
|
## List Append
|
||
|
|
|
||
|
|
`data/ListAppend`
|
||
|
|
|
||
|
|
Appends an item to a list
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `list` | `list` | (optional) List to append to (optional - a new list is created if not provided) |
|
||
|
|
| `item` | `any` | Item to append |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `list` | `list` | The list with the item appended |
|
||
|
|
| `item` | `any` | The item input, passed through |
|
||
|
|
|
||
|
|
## List Collector
|
||
|
|
|
||
|
|
`data/ListCollector`
|
||
|
|
|
||
|
|
Collects items into a list with dynamic inputs.
|
||
|
|
New item sockets appear as connections are made, and each connected
|
||
|
|
value is appended to the list in socket order.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `list` | `list` | (optional) Base list to append to (optional - a new list is created if not provided) |
|
||
|
|
|
||
|
|
This node supports **dynamic inputs** - additional input sockets can be added in the editor as needed, and connected values are collected with key inference (see [Collector Nodes](../../core-concepts/collector_nodes.md)).
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `list` | `list` | The collected list |
|
||
|
|
|
||
|
|
## List Remove
|
||
|
|
|
||
|
|
`data/ListRemove`
|
||
|
|
|
||
|
|
Removes an item from a list
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `list` | `list` | List |
|
||
|
|
| `item` | `any` | Item |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `list` | `list` | List |
|
||
|
|
| `item` | `any` | Item |
|
||
|
|
| `removed` | `bool` | True if item was removed, False if not |
|
||
|
|
|
||
|
|
## Make Dict
|
||
|
|
|
||
|
|
`data/MakeDict`
|
||
|
|
|
||
|
|
Creates a new dictionary, optionally initialized from the data property
|
||
|
|
|
||
|
|
The data property is deep-copied on every execution, so downstream
|
||
|
|
mutation of the dictionary does not alter the property.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `state` | `any` | (optional) Graph state |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `state` | `any` | The state input, passed through |
|
||
|
|
| `dict` | `dict` | The new dictionary |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `data` | `dict` | `{}` | Data |
|
||
|
|
|
||
|
|
## Make Key-Value Pair
|
||
|
|
|
||
|
|
`data/MakeKeyValuePair`
|
||
|
|
|
||
|
|
Creates a key-value pair tuple from separate key and value inputs.
|
||
|
|
Outputs a tuple (key, value) that can be connected to DictCollector.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `key` | `str` | The key (optional) |
|
||
|
|
| `value` | `any` | The value (optional) |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `kv` | `key/value` | The (key, value) tuple |
|
||
|
|
| `key` | `str` | The key input, passed through |
|
||
|
|
| `value` | `any` | The value input, passed through |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `key` | `str` | `""` | Key |
|
||
|
|
| `value` | `any` | `""` | Value |
|
||
|
|
|
||
|
|
## Make List
|
||
|
|
|
||
|
|
`data/MakeList`
|
||
|
|
|
||
|
|
Creates a new list, optionally initialized from the items property
|
||
|
|
|
||
|
|
The items property is deep-copied on every execution, so downstream
|
||
|
|
mutation of the list does not alter the property.
|
||
|
|
|
||
|
|
**Inputs**
|
||
|
|
|
||
|
|
| Input | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `state` | `any` | (optional) Graph state |
|
||
|
|
| `item_type` | `str` | Declared type of the items in the list (optional) |
|
||
|
|
|
||
|
|
**Outputs**
|
||
|
|
|
||
|
|
| Output | Type | Description |
|
||
|
|
| --- | --- | --- |
|
||
|
|
| `state` | `any` | The state input, passed through |
|
||
|
|
| `list` | `list` | The new list |
|
||
|
|
|
||
|
|
**Properties**
|
||
|
|
|
||
|
|
| Property | Type | Default | Description |
|
||
|
|
| --- | --- | --- | --- |
|
||
|
|
| `item_type` | `str` | `"any"` | Type of items in the list. Choices are generated at runtime. |
|
||
|
|
| `items` | `list` | `[]` | Initial items in the list |
|