Remove Lua scripting tool (#27388)
We decided to take this out for now. It doesn't seem necessary, and it complicates the code a lot. We can always put it back later if desired. Release Notes: - N/A
This commit is contained in:
parent
5465198d0d
commit
5d05c4aa70
14 changed files with 52 additions and 2059 deletions
|
@ -23,7 +23,6 @@ use project::{Project, Worktree};
|
|||
use prompt_store::{
|
||||
AssistantSystemPromptContext, PromptBuilder, RulesFile, WorktreeInfoForSystemPrompt,
|
||||
};
|
||||
use scripting_tool::{ScriptingSession, ScriptingTool};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use settings::Settings;
|
||||
use util::{maybe, post_inc, ResultExt as _, TryFutureExt as _};
|
||||
|
@ -34,7 +33,7 @@ use crate::thread_store::{
|
|||
SerializedMessage, SerializedMessageSegment, SerializedThread, SerializedToolResult,
|
||||
SerializedToolUse,
|
||||
};
|
||||
use crate::tool_use::{PendingToolUse, PendingToolUseStatus, ToolType, ToolUse, ToolUseState};
|
||||
use crate::tool_use::{PendingToolUse, ToolUse, ToolUseState};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum RequestKind {
|
||||
|
@ -188,8 +187,6 @@ pub struct Thread {
|
|||
action_log: Entity<ActionLog>,
|
||||
last_restore_checkpoint: Option<LastRestoreCheckpoint>,
|
||||
pending_checkpoint: Option<ThreadCheckpoint>,
|
||||
scripting_session: Entity<ScriptingSession>,
|
||||
scripting_tool_use: ToolUseState,
|
||||
initial_project_snapshot: Shared<Task<Option<Arc<ProjectSnapshot>>>>,
|
||||
cumulative_token_usage: TokenUsage,
|
||||
feedback: Option<ThreadFeedback>,
|
||||
|
@ -221,8 +218,6 @@ impl Thread {
|
|||
last_restore_checkpoint: None,
|
||||
pending_checkpoint: None,
|
||||
tool_use: ToolUseState::new(tools.clone()),
|
||||
scripting_session: cx.new(|cx| ScriptingSession::new(project.clone(), cx)),
|
||||
scripting_tool_use: ToolUseState::new(tools),
|
||||
action_log: cx.new(|_| ActionLog::new()),
|
||||
initial_project_snapshot: {
|
||||
let project_snapshot = Self::project_snapshot(project, cx);
|
||||
|
@ -251,14 +246,7 @@ impl Thread {
|
|||
.unwrap_or(0),
|
||||
);
|
||||
let tool_use =
|
||||
ToolUseState::from_serialized_messages(tools.clone(), &serialized.messages, |name| {
|
||||
name != ScriptingTool::NAME
|
||||
});
|
||||
let scripting_tool_use =
|
||||
ToolUseState::from_serialized_messages(tools.clone(), &serialized.messages, |name| {
|
||||
name == ScriptingTool::NAME
|
||||
});
|
||||
let scripting_session = cx.new(|cx| ScriptingSession::new(project.clone(), cx));
|
||||
ToolUseState::from_serialized_messages(tools.clone(), &serialized.messages, |_| true);
|
||||
|
||||
Self {
|
||||
id,
|
||||
|
@ -297,8 +285,6 @@ impl Thread {
|
|||
tools,
|
||||
tool_use,
|
||||
action_log: cx.new(|_| ActionLog::new()),
|
||||
scripting_session,
|
||||
scripting_tool_use,
|
||||
initial_project_snapshot: Task::ready(serialized.initial_project_snapshot).shared(),
|
||||
// TODO: persist token usage?
|
||||
cumulative_token_usage: TokenUsage::default(),
|
||||
|
@ -357,37 +343,13 @@ impl Thread {
|
|||
.pending_tool_uses()
|
||||
.into_iter()
|
||||
.find(|tool_use| &tool_use.id == id)
|
||||
.or_else(|| {
|
||||
self.scripting_tool_use
|
||||
.pending_tool_uses()
|
||||
.into_iter()
|
||||
.find(|tool_use| &tool_use.id == id)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn tools_needing_confirmation(&self) -> impl Iterator<Item = (ToolType, &PendingToolUse)> {
|
||||
pub fn tools_needing_confirmation(&self) -> impl Iterator<Item = &PendingToolUse> {
|
||||
self.tool_use
|
||||
.pending_tool_uses()
|
||||
.into_iter()
|
||||
.filter_map(|tool_use| {
|
||||
if let PendingToolUseStatus::NeedsConfirmation(confirmation) = &tool_use.status {
|
||||
Some((confirmation.tool_type.clone(), tool_use))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.chain(
|
||||
self.scripting_tool_use
|
||||
.pending_tool_uses()
|
||||
.into_iter()
|
||||
.filter_map(|tool_use| {
|
||||
if tool_use.status.needs_confirmation() {
|
||||
Some((ToolType::ScriptingTool, tool_use))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}),
|
||||
)
|
||||
.filter(|tool_use| tool_use.status.needs_confirmation())
|
||||
}
|
||||
|
||||
pub fn checkpoint_for_message(&self, id: MessageId) -> Option<ThreadCheckpoint> {
|
||||
|
@ -520,25 +482,18 @@ impl Thread {
|
|||
|
||||
/// Returns whether all of the tool uses have finished running.
|
||||
pub fn all_tools_finished(&self) -> bool {
|
||||
let mut all_pending_tool_uses = self
|
||||
.tool_use
|
||||
.pending_tool_uses()
|
||||
.into_iter()
|
||||
.chain(self.scripting_tool_use.pending_tool_uses());
|
||||
|
||||
// If the only pending tool uses left are the ones with errors, then
|
||||
// that means that we've finished running all of the pending tools.
|
||||
all_pending_tool_uses.all(|tool_use| tool_use.status.is_error())
|
||||
self.tool_use
|
||||
.pending_tool_uses()
|
||||
.iter()
|
||||
.all(|tool_use| tool_use.status.is_error())
|
||||
}
|
||||
|
||||
pub fn tool_uses_for_message(&self, id: MessageId, cx: &App) -> Vec<ToolUse> {
|
||||
self.tool_use.tool_uses_for_message(id, cx)
|
||||
}
|
||||
|
||||
pub fn scripting_tool_uses_for_message(&self, id: MessageId, cx: &App) -> Vec<ToolUse> {
|
||||
self.scripting_tool_use.tool_uses_for_message(id, cx)
|
||||
}
|
||||
|
||||
pub fn tool_results_for_message(&self, id: MessageId) -> Vec<&LanguageModelToolResult> {
|
||||
self.tool_use.tool_results_for_message(id)
|
||||
}
|
||||
|
@ -547,21 +502,10 @@ impl Thread {
|
|||
self.tool_use.tool_result(id)
|
||||
}
|
||||
|
||||
pub fn scripting_tool_results_for_message(
|
||||
&self,
|
||||
id: MessageId,
|
||||
) -> Vec<&LanguageModelToolResult> {
|
||||
self.scripting_tool_use.tool_results_for_message(id)
|
||||
}
|
||||
|
||||
pub fn message_has_tool_results(&self, message_id: MessageId) -> bool {
|
||||
self.tool_use.message_has_tool_results(message_id)
|
||||
}
|
||||
|
||||
pub fn message_has_scripting_tool_results(&self, message_id: MessageId) -> bool {
|
||||
self.scripting_tool_use.message_has_tool_results(message_id)
|
||||
}
|
||||
|
||||
pub fn insert_user_message(
|
||||
&mut self,
|
||||
text: impl Into<String>,
|
||||
|
@ -682,7 +626,6 @@ impl Thread {
|
|||
tool_uses: this
|
||||
.tool_uses_for_message(message.id, cx)
|
||||
.into_iter()
|
||||
.chain(this.scripting_tool_uses_for_message(message.id, cx))
|
||||
.map(|tool_use| SerializedToolUse {
|
||||
id: tool_use.id,
|
||||
name: tool_use.name,
|
||||
|
@ -692,7 +635,6 @@ impl Thread {
|
|||
tool_results: this
|
||||
.tool_results_for_message(message.id)
|
||||
.into_iter()
|
||||
.chain(this.scripting_tool_results_for_message(message.id))
|
||||
.map(|tool_result| SerializedToolResult {
|
||||
tool_use_id: tool_result.tool_use_id.clone(),
|
||||
is_error: tool_result.is_error,
|
||||
|
@ -825,15 +767,6 @@ impl Thread {
|
|||
let mut request = self.to_completion_request(request_kind, cx);
|
||||
request.tools = {
|
||||
let mut tools = Vec::new();
|
||||
|
||||
if self.tools.is_scripting_tool_enabled() {
|
||||
tools.push(LanguageModelRequestTool {
|
||||
name: ScriptingTool::NAME.into(),
|
||||
description: ScriptingTool::DESCRIPTION.into(),
|
||||
input_schema: ScriptingTool::input_schema(),
|
||||
});
|
||||
}
|
||||
|
||||
tools.extend(self.tools().enabled_tools(cx).into_iter().map(|tool| {
|
||||
LanguageModelRequestTool {
|
||||
name: tool.name(),
|
||||
|
@ -894,8 +827,6 @@ impl Thread {
|
|||
RequestKind::Chat => {
|
||||
self.tool_use
|
||||
.attach_tool_results(message.id, &mut request_message);
|
||||
self.scripting_tool_use
|
||||
.attach_tool_results(message.id, &mut request_message);
|
||||
}
|
||||
RequestKind::Summarize => {
|
||||
// We don't care about tool use during summarization.
|
||||
|
@ -912,8 +843,6 @@ impl Thread {
|
|||
RequestKind::Chat => {
|
||||
self.tool_use
|
||||
.attach_tool_uses(message.id, &mut request_message);
|
||||
self.scripting_tool_use
|
||||
.attach_tool_uses(message.id, &mut request_message);
|
||||
}
|
||||
RequestKind::Summarize => {
|
||||
// We don't care about tool use during summarization.
|
||||
|
@ -1060,19 +989,11 @@ impl Thread {
|
|||
.iter()
|
||||
.rfind(|message| message.role == Role::Assistant)
|
||||
{
|
||||
if tool_use.name.as_ref() == ScriptingTool::NAME {
|
||||
thread.scripting_tool_use.request_tool_use(
|
||||
last_assistant_message.id,
|
||||
tool_use,
|
||||
cx,
|
||||
);
|
||||
} else {
|
||||
thread.tool_use.request_tool_use(
|
||||
last_assistant_message.id,
|
||||
tool_use,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
thread.tool_use.request_tool_use(
|
||||
last_assistant_message.id,
|
||||
tool_use,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1237,7 +1158,7 @@ impl Thread {
|
|||
tool_use.ui_text.clone(),
|
||||
tool_use.input.clone(),
|
||||
messages.clone(),
|
||||
ToolType::NonScriptingTool(tool),
|
||||
tool,
|
||||
);
|
||||
} else {
|
||||
self.run_tool(
|
||||
|
@ -1245,7 +1166,7 @@ impl Thread {
|
|||
tool_use.ui_text.clone(),
|
||||
tool_use.input.clone(),
|
||||
&messages,
|
||||
ToolType::NonScriptingTool(tool),
|
||||
tool,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
|
@ -1255,33 +1176,13 @@ impl Thread {
|
|||
tool_use.ui_text.clone(),
|
||||
tool_use.input.clone(),
|
||||
&messages,
|
||||
ToolType::NonScriptingTool(tool),
|
||||
tool,
|
||||
cx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let pending_scripting_tool_uses = self
|
||||
.scripting_tool_use
|
||||
.pending_tool_uses()
|
||||
.into_iter()
|
||||
.filter(|tool_use| tool_use.status.is_idle())
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for scripting_tool_use in pending_scripting_tool_uses.iter() {
|
||||
self.scripting_tool_use.confirm_tool_use(
|
||||
scripting_tool_use.id.clone(),
|
||||
scripting_tool_use.ui_text.clone(),
|
||||
scripting_tool_use.input.clone(),
|
||||
messages.clone(),
|
||||
ToolType::ScriptingTool,
|
||||
);
|
||||
}
|
||||
|
||||
pending_tool_uses
|
||||
.into_iter()
|
||||
.chain(pending_scripting_tool_uses)
|
||||
}
|
||||
|
||||
pub fn run_tool(
|
||||
|
@ -1290,21 +1191,12 @@ impl Thread {
|
|||
ui_text: impl Into<SharedString>,
|
||||
input: serde_json::Value,
|
||||
messages: &[LanguageModelRequestMessage],
|
||||
tool_type: ToolType,
|
||||
tool: Arc<dyn Tool>,
|
||||
cx: &mut Context<'_, Thread>,
|
||||
) {
|
||||
match tool_type {
|
||||
ToolType::ScriptingTool => {
|
||||
let task = self.spawn_scripting_tool_use(tool_use_id.clone(), input, cx);
|
||||
self.scripting_tool_use
|
||||
.run_pending_tool(tool_use_id, ui_text.into(), task);
|
||||
}
|
||||
ToolType::NonScriptingTool(tool) => {
|
||||
let task = self.spawn_tool_use(tool_use_id.clone(), messages, input, tool, cx);
|
||||
self.tool_use
|
||||
.run_pending_tool(tool_use_id, ui_text.into(), task);
|
||||
}
|
||||
}
|
||||
let task = self.spawn_tool_use(tool_use_id.clone(), messages, input, tool, cx);
|
||||
self.tool_use
|
||||
.run_pending_tool(tool_use_id, ui_text.into(), task);
|
||||
}
|
||||
|
||||
fn spawn_tool_use(
|
||||
|
@ -1344,60 +1236,6 @@ impl Thread {
|
|||
})
|
||||
}
|
||||
|
||||
fn spawn_scripting_tool_use(
|
||||
&mut self,
|
||||
tool_use_id: LanguageModelToolUseId,
|
||||
input: serde_json::Value,
|
||||
cx: &mut Context<Thread>,
|
||||
) -> Task<()> {
|
||||
let task = match ScriptingTool::deserialize_input(input) {
|
||||
Err(err) => Task::ready(Err(err.into())),
|
||||
Ok(input) => {
|
||||
let (script_id, script_task) =
|
||||
self.scripting_session.update(cx, move |session, cx| {
|
||||
session.run_script(input.lua_script, cx)
|
||||
});
|
||||
|
||||
let session = self.scripting_session.clone();
|
||||
cx.spawn(async move |_, cx| {
|
||||
script_task.await;
|
||||
|
||||
let message = session.read_with(cx, |session, _cx| {
|
||||
// Using a id to get the script output seems impractical.
|
||||
// Why not just include it in the Task result?
|
||||
// This is because we'll later report the script state as it runs,
|
||||
session
|
||||
.get(script_id)
|
||||
.output_message_for_llm()
|
||||
.expect("Script shouldn't still be running")
|
||||
})?;
|
||||
|
||||
Ok(message)
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
cx.spawn({
|
||||
let tool_use_id = tool_use_id.clone();
|
||||
async move |thread, cx| {
|
||||
let output = task.await;
|
||||
thread
|
||||
.update(cx, |thread, cx| {
|
||||
let pending_tool_use = thread
|
||||
.scripting_tool_use
|
||||
.insert_tool_output(tool_use_id.clone(), output);
|
||||
|
||||
cx.emit(ThreadEvent::ToolFinished {
|
||||
tool_use_id,
|
||||
pending_tool_use,
|
||||
canceled: false,
|
||||
});
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn attach_tool_results(
|
||||
&mut self,
|
||||
updated_context: Vec<ContextSnapshot>,
|
||||
|
@ -1654,22 +1492,12 @@ impl Thread {
|
|||
self.cumulative_token_usage.clone()
|
||||
}
|
||||
|
||||
pub fn deny_tool_use(
|
||||
&mut self,
|
||||
tool_use_id: LanguageModelToolUseId,
|
||||
tool_type: ToolType,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
pub fn deny_tool_use(&mut self, tool_use_id: LanguageModelToolUseId, cx: &mut Context<Self>) {
|
||||
let err = Err(anyhow::anyhow!(
|
||||
"Permission to run tool action denied by user"
|
||||
));
|
||||
|
||||
if let ToolType::ScriptingTool = tool_type {
|
||||
self.scripting_tool_use
|
||||
.insert_tool_output(tool_use_id.clone(), err);
|
||||
} else {
|
||||
self.tool_use.insert_tool_output(tool_use_id.clone(), err);
|
||||
}
|
||||
self.tool_use.insert_tool_output(tool_use_id.clone(), err);
|
||||
|
||||
cx.emit(ThreadEvent::ToolFinished {
|
||||
tool_use_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue