Skip to content

Commit c3abd8d

Browse files
committed
defs need indexmap for insertion ordering
Signed-off-by: Nick Mitchell <[email protected]>
1 parent 04a42c7 commit c3abd8d

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

pdl-live-react/src-tauri/Cargo.lock

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pdl-live-react/src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ rustpython-vm = "0.4.0"
4141
async-recursion = "1.1.1"
4242
tokio-stream = "0.1.17"
4343
tokio = { version = "1.44.1", features = ["io-std"] }
44+
indexmap = { version = "2.9.0", features = ["serde"] }
4445

4546
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
4647
tauri-plugin-cli = "2"

pdl-live-react/src-tauri/src/compile/beeai.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ fn json_loads(
237237
outer_name: &str,
238238
inner_name: &str,
239239
value: &str,
240-
) -> Option<HashMap<String, PdlBlock>> {
241-
let mut m = HashMap::new();
240+
) -> Option<indexmap::IndexMap<String, PdlBlock>> {
241+
let mut m = indexmap::IndexMap::new();
242242
m.insert(
243243
outer_name.to_owned(),
244244
PdlBlock::Text(
@@ -505,7 +505,7 @@ asyncio.run(invoke())
505505
}
506506

507507
let closure_name = format!("agent_closure_{}", agent_name);
508-
let mut defs = HashMap::new();
508+
let mut defs = indexmap::IndexMap::new();
509509
defs.insert(
510510
closure_name.clone(),
511511
PdlBlock::Function(FunctionBlock {
@@ -544,7 +544,7 @@ asyncio.run(invoke())
544544
defs: if tool_declarations.len() == 0 {
545545
None
546546
} else {
547-
let mut m = HashMap::new();
547+
let mut m = indexmap::IndexMap::new();
548548
m.insert(
549549
"pdl__tools".to_string(),
550550
PdlBlock::Object(ObjectBlock {

pdl-live-react/src-tauri/src/pdl/ast.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use ::std::collections::HashMap;
2+
use indexmap::IndexMap;
23
use serde::{Deserialize, Serialize};
34
use serde_json::{to_string, Number, Value};
45

@@ -61,7 +62,7 @@ pub struct CallBlock {
6162
pub args: Option<Value>,
6263

6364
#[serde(skip_serializing_if = "Option::is_none")]
64-
pub defs: Option<HashMap<String, PdlBlock>>,
65+
pub defs: Option<IndexMap<String, PdlBlock>>,
6566
}
6667

6768
impl CallBlock {
@@ -79,7 +80,7 @@ pub trait SequencingBlock {
7980
fn description(&self) -> &Option<String>;
8081
fn role(&self) -> &Option<Role>;
8182
fn def(&self) -> &Option<String>;
82-
fn defs(&self) -> &Option<HashMap<String, PdlBlock>>;
83+
fn defs(&self) -> &Option<IndexMap<String, PdlBlock>>;
8384
fn items(&self) -> &Vec<PdlBlock>;
8485
fn with_items(&self, items: Vec<PdlBlock>) -> Self;
8586
fn parser(&self) -> &Option<PdlParser>;
@@ -102,7 +103,7 @@ pub struct LastOfBlock {
102103
pub role: Option<Role>,
103104

104105
#[serde(skip_serializing_if = "Option::is_none")]
105-
pub defs: Option<HashMap<String, PdlBlock>>,
106+
pub defs: Option<IndexMap<String, PdlBlock>>,
106107

107108
#[serde(skip_serializing_if = "Option::is_none")]
108109
pub parser: Option<PdlParser>,
@@ -123,7 +124,7 @@ impl SequencingBlock for LastOfBlock {
123124
fn def(&self) -> &Option<String> {
124125
return &self.def;
125126
}
126-
fn defs(&self) -> &Option<HashMap<String, PdlBlock>> {
127+
fn defs(&self) -> &Option<IndexMap<String, PdlBlock>> {
127128
&self.defs
128129
}
129130
fn items(&self) -> &Vec<PdlBlock> {
@@ -168,7 +169,7 @@ pub struct TextBlock {
168169
pub role: Option<Role>,
169170

170171
#[serde(skip_serializing_if = "Option::is_none")]
171-
pub defs: Option<HashMap<String, PdlBlock>>,
172+
pub defs: Option<IndexMap<String, PdlBlock>>,
172173

173174
#[serde(skip_serializing_if = "Option::is_none")]
174175
pub parser: Option<PdlParser>,
@@ -189,7 +190,7 @@ impl SequencingBlock for TextBlock {
189190
fn def(&self) -> &Option<String> {
190191
return &self.def;
191192
}
192-
fn defs(&self) -> &Option<HashMap<String, PdlBlock>> {
193+
fn defs(&self) -> &Option<IndexMap<String, PdlBlock>> {
193194
&self.defs
194195
}
195196
fn items(&self) -> &Vec<PdlBlock> {
@@ -506,7 +507,7 @@ pub struct IfBlock {
506507
pub else_: Option<Box<PdlBlock>>,
507508

508509
#[serde(skip_serializing_if = "Option::is_none")]
509-
pub defs: Option<HashMap<String, PdlBlock>>,
510+
pub defs: Option<IndexMap<String, PdlBlock>>,
510511
}
511512

512513
/// Return the array of values computed by each block of the list of blocks

pdl-live-react/src-tauri/src/pdl/interpreter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ impl<'a> Interpreter<'a> {
711711

712712
async fn process_defs(
713713
&mut self,
714-
defs: &Option<HashMap<String, PdlBlock>>,
714+
defs: &Option<indexmap::IndexMap<String, PdlBlock>>,
715715
) -> Result<(), PdlError> {
716716
let mut new_scope: Scope = HashMap::new();
717717
if let Some(cur_scope) = self.scope.last() {

0 commit comments

Comments
 (0)