Skip to content

Commit

Permalink
Support rich output types (#74)
Browse files Browse the repository at this point in the history
* Bump rust deps

* Support data field in API

* Support data field in JS and Python SDKs

* Address comments
  • Loading branch information
jakelazaroff authored Jan 29, 2025
1 parent 0bacdab commit 7f1a7b2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions javascript/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface ApiExecResponse {

export interface ExecResponse {
value?: string | null
data?: { [key: string]: unknown }
error?: string
runtime_ms: number
}
Expand Down
3 changes: 2 additions & 1 deletion python/sdk/forevervm_sdk/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Literal, Optional, TypedDict
from typing import Any, Dict, List, Literal, Optional, TypedDict


class WhoamiResponse(TypedDict):
Expand Down Expand Up @@ -27,6 +27,7 @@ class ExecResultBase(TypedDict):

class ExecResultValue(ExecResultBase):
value: Optional[str]
data: Optional[Dict[str, Any]]


class ExecResultError(ExecResultBase):
Expand Down
4 changes: 2 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions rust/forevervm-sdk/src/api/api_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ impl Instruction {
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(untagged, rename_all = "snake_case")]
pub enum ExecResultType {
#[serde(rename = "value")]
Value(Option<String>),
Value {
value: Option<String>,
data: Option<serde_json::Value>,
},

#[serde(rename = "error")]
Error(String),
}

Expand Down
5 changes: 4 additions & 1 deletion rust/forevervm-sdk/tests/basic_sdk_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ async fn test_exec() {

assert_eq!(
exec_result.result.result,
ExecResultType::Value(Some("567".to_string()))
ExecResultType::Value {
value: Some("567".to_string()),
data: None
}
);
}

Expand Down
12 changes: 9 additions & 3 deletions rust/forevervm/src/commands/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ pub async fn machine_repl(machine_name: Option<MachineName>) -> anyhow::Result<(
ExecResultType::Error(err) => {
eprintln!("Error: {}", err);
}
ExecResultType::Value(Some(data)) => {
println!("{}", data);
ExecResultType::Value {
value: Some(value),
data: _,
} => {
println!("{}", value);
}
ExecResultType::Value(None) => {}
ExecResultType::Value {
value: None,
data: _,
} => {}
},
Err(err) => {
eprintln!("Error: {}", err);
Expand Down

0 comments on commit 7f1a7b2

Please sign in to comment.