Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit b78b336

Browse files
anastasiya1155calyptobai
authored andcommitted
Add fields to list studios (projects) (#1205)
* return token counter, doc_context and full context in list studios route
1 parent f2a6cf8 commit b78b336

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

server/bleep/sqlx-data.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@
14921492
},
14931493
"query": "UPDATE project_repos\n SET branch = ?\n WHERE project_id = ? AND repo_ref = ?\n RETURNING id"
14941494
},
1495-
"ebdb202965998c4e29727dca19a60c82b2a4574530858e29bf6584c8b6e1f32b": {
1495+
"e72d027c61c96b02889751f6817129ea73d23383be3dae5fc1bffdc6e7b2c46d": {
14961496
"describe": {
14971497
"columns": [
14981498
{
@@ -1514,19 +1514,31 @@
15141514
"name": "context",
15151515
"ordinal": 3,
15161516
"type_info": "Text"
1517+
},
1518+
{
1519+
"name": "doc_context",
1520+
"ordinal": 4,
1521+
"type_info": "Text"
1522+
},
1523+
{
1524+
"name": "messages",
1525+
"ordinal": 5,
1526+
"type_info": "Text"
15171527
}
15181528
],
15191529
"nullable": [
15201530
false,
15211531
true,
15221532
false,
1533+
false,
1534+
false,
15231535
false
15241536
],
15251537
"parameters": {
15261538
"Right": 2
15271539
}
15281540
},
1529-
"query": "SELECT\n s.id,\n s.name,\n ss.modified_at as \"modified_at!\",\n ss.context\n FROM studios s\n INNER JOIN studio_snapshots ss ON s.id = ss.studio_id\n INNER JOIN projects p ON p.id = s.project_id\n WHERE s.project_id = ? AND p.user_id = ? AND (ss.studio_id, ss.modified_at) IN (\n SELECT studio_id, MAX(modified_at)\n FROM studio_snapshots\n GROUP BY studio_id\n )"
1541+
"query": "SELECT\n s.id,\n s.name,\n ss.modified_at as \"modified_at!\",\n ss.context,\n ss.doc_context,\n ss.messages\n FROM studios s\n INNER JOIN studio_snapshots ss ON s.id = ss.studio_id\n INNER JOIN projects p ON p.id = s.project_id\n WHERE s.project_id = ? AND p.user_id = ? AND (ss.studio_id, ss.modified_at) IN (\n SELECT studio_id, MAX(modified_at)\n FROM studio_snapshots\n GROUP BY studio_id\n )"
15301542
},
15311543
"ec193a038eb7fc3aaca3c3adebcc4dbde01b47ae34ac2df2227c5e5459617182": {
15321544
"describe": {

server/bleep/src/webserver/autocomplete.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ pub(super) async fn handle(
125125
.restrict_repo_queries(queries.clone(), &app)
126126
.await?;
127127

128-
let restricted_queries = api_params
129-
.restrict_queries(queries.clone(), &app)
130-
.await?;
128+
let restricted_queries = api_params.restrict_queries(queries.clone(), &app).await?;
131129

132130
let mut engines = vec![];
133131
if ac_params.content {

server/bleep/src/webserver/studio.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,9 @@ pub struct ListItem {
357357
modified_at: NaiveDateTime,
358358
repos: Vec<String>,
359359
most_common_ext: String,
360-
context: Vec<ListItemContextFile>,
361-
}
362-
363-
#[derive(serde::Serialize)]
364-
struct ListItemContextFile {
365-
path: String,
366-
hidden: bool,
367-
ranges: Vec<Range<usize>>,
360+
context: Vec<ContextFile>,
361+
doc_context: Vec<DocContextFile>,
362+
token_counts: TokenCounts,
368363
}
369364

370365
pub async fn list(
@@ -379,7 +374,9 @@ pub async fn list(
379374
s.id,
380375
s.name,
381376
ss.modified_at as \"modified_at!\",
382-
ss.context
377+
ss.context,
378+
ss.doc_context,
379+
ss.messages
383380
FROM studios s
384381
INNER JOIN studio_snapshots ss ON s.id = ss.studio_id
385382
INNER JOIN projects p ON p.id = s.project_id
@@ -399,6 +396,10 @@ pub async fn list(
399396
for studio in studios {
400397
let context: Vec<ContextFile> =
401398
serde_json::from_str(&studio.context).map_err(Error::internal)?;
399+
let doc_context: Vec<DocContextFile> =
400+
serde_json::from_str(&studio.doc_context).map_err(Error::internal)?;
401+
let messages: Vec<Message> =
402+
serde_json::from_str(&studio.messages).map_err(Error::internal)?;
402403

403404
let repos: HashSet<String> = context.iter().map(|file| file.repo.name.clone()).collect();
404405

@@ -423,20 +424,17 @@ pub async fn list(
423424
.unwrap_or_default()
424425
.to_owned();
425426

427+
let token_counts = token_counts((*app).clone(), &messages, &context, &doc_context).await?;
428+
426429
let list_item = ListItem {
427430
id: studio.id,
428431
name: studio.name.unwrap_or_else(default_studio_name),
429432
modified_at: studio.modified_at,
430433
repos: repos.into_iter().collect::<Vec<_>>(),
431434
most_common_ext,
432-
context: context
433-
.iter()
434-
.map(|c| ListItemContextFile {
435-
path: c.path.clone(),
436-
hidden: c.hidden,
437-
ranges: c.ranges.clone(),
438-
})
439-
.collect(),
435+
context,
436+
doc_context,
437+
token_counts,
440438
};
441439

442440
list_items.push(list_item);

0 commit comments

Comments
 (0)