Move LLM and agent into ext/ai with host tool catalog and call_fn.
Consolidate official AI extensions under ext/ai/, add agent history/context host APIs, dynamic call_fn, and a first-pass TOOL:name loop so runbooks can list zero-arg tools in a table. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
c4ffb9473f
commit
92d88fe761
29 files changed
+1019
-558
No files matched your search
+29
-6
@@ -166,13 +166,18 @@ impl Interpreter {
|
||||
}
|
||||
}
|
||||
|
||||
let mut ret = Value::None;
|
||||
for stmt in &fun.body {
|
||||
if let Some(v) = self.exec_stmt(module, fun, &mut env, stmt)? {
|
||||
ret = v;
|
||||
break;
|
||||
let ret = Value::None;
|
||||
self.host.push_call_frame(&fun.name);
|
||||
let body_result = (|| -> Result<Value> {
|
||||
for stmt in &fun.body {
|
||||
if let Some(v) = self.exec_stmt(module, fun, &mut env, stmt)? {
|
||||
return Ok(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(ret)
|
||||
})();
|
||||
self.host.pop_call_frame();
|
||||
let ret = body_result?;
|
||||
if self.trace {
|
||||
let display = ret.as_display();
|
||||
emit_trace(
|
||||
@@ -194,6 +199,7 @@ impl Interpreter {
|
||||
) -> Result<Option<Value>> {
|
||||
let span = stmt_span(stmt);
|
||||
self.current_span = span;
|
||||
self.host.current_line = span.line;
|
||||
if let Some(dbg) = &self.debug {
|
||||
dbg.on_stmt(span.line, &fun.name, &env.vars, &self.captured_stdout)
|
||||
.map_err(|m| self.err(m))?;
|
||||
@@ -557,6 +563,23 @@ impl Interpreter {
|
||||
.ok_or_else(|| self.err("at requires index"))?;
|
||||
return builtin_at(value, index).map_err(|m| self.err(m));
|
||||
}
|
||||
"call_fn" => {
|
||||
let bound = bind_args(&["name".into()], &ev_args, false)
|
||||
.map_err(|m| self.err(m))?;
|
||||
let name = match bound.get("name") {
|
||||
Some(Value::Text(s)) => s.as_str(),
|
||||
_ => return Err(self.err("call_fn requires text name")),
|
||||
};
|
||||
let target = lookup_function(module, fun, name).ok_or_else(|| {
|
||||
self.err(format!("call_fn: unknown function `{name}`"))
|
||||
})?;
|
||||
if !target.params.is_empty() {
|
||||
return Err(self.err(format!(
|
||||
"call_fn: `{name}` must have no parameters"
|
||||
)));
|
||||
}
|
||||
return self.run_function(module, target, Env::new(), &[]);
|
||||
}
|
||||
other if HostFn::from_name(other).is_some() => {
|
||||
let hf = HostFn::from_name(other).unwrap();
|
||||
let mut params: Vec<String> =
|
||||
|
||||
Reference in new issue
Block a user