feat: let the ai session test-run hub scripts (#12170)

* feat: let the ai session run and test-run hub scripts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep hub scripts to test runs in the ai session

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-11-03 11:49:17 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 331aa51e22
commit 3125e6dac0
4 changed files with 34 additions and 8 deletions
@@ -1019,7 +1019,7 @@
"type": "object",
"properties": {
"path": {
"description": "Workspace path of the script to test.",
"description": "Workspace path of the script to test, or a hub/<version>/<app>/<name> path from search_hub_scripts to try a hub script.",
"type": "string"
},
"args": {
@@ -8,7 +8,7 @@ use serde_json::{json, Map, Value};
use super::chat::{Effect, RunPhase};
use super::workspace::{
api_message, get_draft, infer_script_schema, load_flow, load_script, path_enc,
api_message, get_draft, infer_script_schema, load_flow, load_script_to_run, path_enc,
};
use super::{enc, js_head, js_len, js_tail, opt_str_arg, pretty, str_arg, truthy, Ctx, ToolResult};
@@ -943,7 +943,7 @@ fn form_keys(schema: Option<&Value>) -> Vec<String> {
}
async fn resolve_test_script(ctx: &Ctx<'_>, path: &str) -> Result<Resolved, String> {
let script = load_script(ctx, path).await?;
let script = load_script_to_run(ctx, path).await?;
Ok(Resolved {
schema: script.schema,
code: Some(script.content.clone()),
@@ -1643,7 +1643,7 @@ async fn resolve_step(ctx: &Ctx<'_>, path: &str, step_id: &str) -> Result<Resolv
)
}
_ => {
let loaded = load_script(ctx, &target).await?;
let loaded = load_script_to_run(ctx, &target).await?;
(loaded.content, loaded.language, loaded.schema)
}
};
@@ -982,6 +982,30 @@ pub(super) struct LoadedScript {
pub schema: Option<Value>,
}
/// A hub script, by its `hub/<version>/<app>/<name>` path. Hub scripts live outside the
/// workspace: they have no draft and no workspace row.
pub(super) async fn get_hub_script(ctx: &Ctx<'_>, path: &str) -> Result<Value, String> {
ctx.get(&format!("/scripts/hub/get_full/{}", path_enc(path)))
.await
}
/// The script a test run executes: `load_script`, or a hub script as published. Only test
/// runs take a hub path: an edit would save a draft no run reads, and `run_script` stays
/// limited to deployed workspace scripts, which is all a read-and-run session may run.
pub(super) async fn load_script_to_run(ctx: &Ctx<'_>, path: &str) -> Result<LoadedScript, String> {
if !path.starts_with("hub/") {
return load_script(ctx, path).await;
}
let script = get_hub_script(ctx, path).await?;
let text = |key: &str| script.get(key).and_then(Value::as_str).map(String::from);
Ok(LoadedScript {
content: text("content").unwrap_or_default(),
language: text("language").unwrap_or_default(),
summary: text("summary"),
schema: non_null(script.get("schema")).cloned(),
})
}
pub(super) async fn load_script(ctx: &Ctx<'_>, path: &str) -> Result<LoadedScript, String> {
let text = |value: &Value, key: &str| value.get(key).and_then(Value::as_str).map(String::from);
if let Some((item, _)) = get_draft_item(ctx, "script", path, None).await? {
@@ -1664,9 +1688,7 @@ async fn read_workspace_item(ctx: &Ctx<'_>, args: &Value) -> ToolResult {
let item = match item_type {
"script" if hub => {
let script = ctx
.get(&format!("/scripts/hub/get_full/{}", path_enc(path)))
.await?;
let script = get_hub_script(ctx, path).await?;
let mut row = script.clone();
row["path"] = json!(path);
let mut item = with_value(
@@ -853,7 +853,11 @@ function waitSecondsToDetachMs(waitSeconds: number | undefined): number | undefi
}
const testRunScriptSchema = z.object({
path: z.string().describe('Workspace path of the script to test.'),
path: z
.string()
.describe(
'Workspace path of the script to test, or a hub/<version>/<app>/<name> path from search_hub_scripts to try a hub script.'
),
args: testRunArgsSchema,
background: backgroundArgSchema,
wait_seconds: waitSecondsArgSchema