агенты: добавить поиск инструментов по каталогу

This commit is contained in:
bsodfather committed 2026-07-21 13:12:46 +03:00
1 parent 63f8ee333f
commit 99bd05c145
35 files changed
+2088 -155

No files matched your search

@@ -1,6 +1,42 @@
use super::*;
impl PostgresRegistry {
pub async fn get_published_agent_catalog_by_slug(
&self,
workspace_slug: &str,
agent_slug: &str,
) -> Result<PublishedAgentCatalog, RegistryError> {
let row = sqlx::query(
"select
pa.version,
av.tool_selection_policy_json
from workspaces w
join agents a on a.workspace_id = w.id
join published_agents pa on pa.agent_id = a.id
join agent_versions av on av.agent_id = a.id and av.version = pa.version
where w.slug = $1 and a.slug = $2",
)
.bind(workspace_slug)
.bind(agent_slug)
.fetch_optional(&self.pool)
.await?
.ok_or_else(|| RegistryError::PublishedAgentNotFound {
workspace_slug: workspace_slug.to_owned(),
agent_slug: agent_slug.to_owned(),
})?;
let tools = self
.get_published_agent_tools_by_slug(workspace_slug, agent_slug)
.await?;
Ok(PublishedAgentCatalog {
agent_version: from_db_version(row.try_get("version")?, "agent_version")?,
tool_selection_policy: deserialize_json_value(
row.try_get("tool_selection_policy_json")?,
)?,
tools,
})
}
pub async fn list_agents(
&self,
workspace_id: &WorkspaceId,
@@ -254,6 +290,48 @@ impl PostgresRegistry {
Ok(())
}
pub async fn save_agent_catalog_config(
&self,
request: SaveAgentCatalogConfigRequest<'_>,
) -> Result<(), RegistryError> {
if self
.get_agent_summary(request.workspace_id, request.agent_id)
.await?
.is_none()
{
return Err(RegistryError::AgentNotFound {
agent_id: request.agent_id.as_str().to_owned(),
});
}
let mut tx = self.pool.begin().await?;
let updated = sqlx::query(
"update agent_versions
set tool_selection_policy_json = $3
where agent_id = $1 and version = $2",
)
.bind(request.agent_id.as_str())
.bind(to_db_version(request.agent_version))
.bind(Json(serialize_json_value(request.tool_selection_policy)?))
.execute(&mut *tx)
.await?
.rows_affected();
if updated == 0 {
return Err(RegistryError::AgentNotFound {
agent_id: request.agent_id.as_str().to_owned(),
});
}
replace_agent_bindings_rows(
&mut tx,
request.agent_id,
request.agent_version,
request.bindings,
)
.await?;
tx.commit().await?;
Ok(())
}
pub async fn update_agent_summary(
&self,
workspace_id: &WorkspaceId,
+10 -9
View File
@@ -39,13 +39,14 @@ use crate::{
ImportJob, ImportJobId, InvitationRecord, InvocationLogRecord, ListApprovalRequestsQuery,
ListInvocationLogsQuery, MembershipRecord, OperationAgentRef, OperationSampleMetadata,
OperationSummary, OperationUsageSummary, OperationVersionRecord, PlatformApiKeyRecord,
PublishAgentRequest, PublishRequest, PublishedAgentTool, RegistryOperation,
RotateSecretRequest, SaveAgentBindingsRequest, SaveAuthProfileRequest,
SaveDescriptorMetadataRequest, SaveSampleMetadataRequest, SaveWorkspaceUpstreamRequest,
SecretRecord, SecretVersionRecord, SessionRecord, UpdateWorkspaceRequest,
UsageAgentBreakdown, UsageOperationBreakdown, UsageQuery, UsageRollupRecord, UsageSummary,
UsageTimelinePoint, WorkspaceMembershipRecord, WorkspaceRecord, WorkspaceUpstream,
YamlImportJob, YamlImportJobCompletion, YamlImportJobId, YamlImportJobStatus,
PublishAgentRequest, PublishRequest, PublishedAgentCatalog, PublishedAgentTool,
RegistryOperation, RotateSecretRequest, SaveAgentBindingsRequest,
SaveAgentCatalogConfigRequest, SaveAuthProfileRequest, SaveDescriptorMetadataRequest,
SaveSampleMetadataRequest, SaveWorkspaceUpstreamRequest, SecretRecord, SecretVersionRecord,
SessionRecord, UpdateWorkspaceRequest, UsageAgentBreakdown, UsageOperationBreakdown,
UsageQuery, UsageRollupRecord, UsageSummary, UsageTimelinePoint, WorkspaceMembershipRecord,
WorkspaceRecord, WorkspaceUpstream, YamlImportJob, YamlImportJobCompletion,
YamlImportJobId, YamlImportJobStatus,
},
};
@@ -154,7 +155,7 @@ async fn insert_agent_version_row(
.bind(to_db_version(version.version))
.bind(serialize_enum_text(&version.status, "status")?)
.bind(Json(version.instructions.clone()))
.bind(Json(version.tool_selection_policy.clone()))
.bind(Json(serialize_json_value(&version.tool_selection_policy)?))
.bind(version.created_at)
.execute(&mut **tx)
.await?;
@@ -498,7 +499,7 @@ fn build_agent_version_record(
version,
status,
instructions: instructions_json,
tool_selection_policy: tool_selection_policy_json,
tool_selection_policy: deserialize_json_value(tool_selection_policy_json)?,
created_at,
},
})