MCPcopy Index your code
hub / github.com/AI45Lab/Code / parse_js_step_spec

Function parse_js_step_spec

sdk/node/src/lib.rs:5101–5139  ·  view source on GitHub ↗

Parse a JS pipeline-stage return value into an `AgentStepSpec`, or `None` for `null`/`undefined`/unreadable input (which stops the chain). Accepts camelCase (the SDK convention) and snake_case keys.

(val: napi::JsUnknown)

Source from the content-addressed store, hash-verified

5099/// for `null`/`undefined`/unreadable input (which stops the chain). Accepts
5100/// camelCase (the SDK convention) and snake_case keys.
5101fn parse_js_step_spec(val: napi::JsUnknown) -> Option<RustAgentStepSpec> {
5102 use napi::{JsObject, ValueType};
5103 if !matches!(val.get_type().ok()?, ValueType::Object) {
5104 return None;
5105 }
5106 let obj = unsafe { val.cast::<JsObject>() };
5107 let get_str = |keys: &[&str]| -> Option<String> {
5108 for k in keys {
5109 if let Ok(s) = obj.get_named_property::<napi::JsString>(k) {
5110 if let Some(v) = s.into_utf8().ok().and_then(|s| s.into_owned().ok()) {
5111 return Some(v);
5112 }
5113 }
5114 }
5115 None
5116 };
5117 let task_id = get_str(&["taskId", "task_id"])?;
5118 let agent = get_str(&["agent"])?;
5119 let prompt = get_str(&["prompt"])?;
5120 let description = get_str(&["description"]).unwrap_or_default();
5121 let max_steps = ["maxSteps", "max_steps"]
5122 .iter()
5123 .find_map(|k| obj.get_named_property::<napi::JsNumber>(k).ok())
5124 .and_then(|n| n.get_uint32().ok())
5125 .map(|n| n as usize);
5126 let parent_session_id = get_str(&["parentSessionId", "parent_session_id"]);
5127 Some(RustAgentStepSpec {
5128 task_id,
5129 agent,
5130 description,
5131 prompt,
5132 max_steps,
5133 parent_session_id,
5134 // Per-stage `outputSchema` is not yet supported on pipeline stages
5135 // (the lenient JsUnknown parse here can't read an arbitrary JSON-schema
5136 // property safely). Use `parallel` for schema-validated steps.
5137 output_schema: None,
5138 })
5139}
5140
5141impl NodeBudgetGuard {
5142 fn call_decision(

Callers 1

invokeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected