MCPcopy Create free account
hub / github.com/AI45Lab/Code / session_for_agent

Method session_for_agent

sdk/node/src/lib.rs:2899–2929  ·  view source on GitHub ↗
(
        &self,
        workspace: String,
        agent_name: String,
        agent_dirs: Option<Vec<String>>,
        options: Option<SessionOptions>,
    )

Source from the content-addressed store, hash-verified

2897 /// @param options - Optional session overrides layered on top of the agent definition
2898 #[napi]
2899 pub fn session_for_agent(
2900 &self,
2901 workspace: String,
2902 agent_name: String,
2903 agent_dirs: Option<Vec<String>>,
2904 options: Option<SessionOptions>,
2905 ) -> napi::Result<Session> {
2906 let registry = a3s_code_core::subagent::AgentRegistry::new();
2907 for dir in agent_dirs.unwrap_or_default() {
2908 let agents = a3s_code_core::subagent::load_agents_from_dir(std::path::Path::new(&dir));
2909 for agent in agents {
2910 registry.register(agent);
2911 }
2912 }
2913 let def = registry
2914 .get(&agent_name)
2915 .ok_or_else(|| napi::Error::from_reason(format!("agent '{}' not found", agent_name)))?;
2916 let session = self
2917 .inner
2918 .session_for_agent(
2919 workspace,
2920 &def,
2921 options
2922 .map(|o| js_session_options_to_rust(Some(o)))
2923 .transpose()?,
2924 )
2925 .map_err(|e| napi::Error::from_reason(format!("{e}")))?;
2926 Ok(Session {
2927 inner: Arc::new(session),
2928 })
2929 }
2930
2931 /// Create a session pre-configured from a disposable worker spec.
2932 ///

Callers

nothing calls this directly

Calls 4

load_agents_from_dirFunction · 0.85
registerMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected