feat(agent): enhance agent sharing and selection features
- Updated the AgentSelector component to improve agent selection logic, ensuring accurate representation of selected agents. - Introduced new AgentShareSettings component for managing agent sharing with organizations, including UI for selecting organizations and displaying shared agents. - Enhanced API interactions for sharing agents, including new methods for listing and managing agent shares. - Improved localization support for agent sharing features across multiple languages. - Updated various components to reflect changes in agent capabilities and sharing status, enhancing user experience and clarity. This update strengthens the agent management features, providing users with better tools for sharing and selecting agents within organizations.
This commit is contained in:
@@ -89,7 +89,7 @@ export function useStream() {
|
||||
if (params.knowledge_ids !== undefined && params.knowledge_ids.length > 0) {
|
||||
postBody.knowledge_ids = params.knowledge_ids;
|
||||
}
|
||||
// Include agent_id if provided (for custom agent configuration)
|
||||
// Include agent_id if provided (backend resolves shared agent and tenant from share relation)
|
||||
if (params.agent_id) {
|
||||
postBody.agent_id = params.agent_id;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { get, post, put, del, postUpload, getDown } from "../../utils/request";
|
||||
|
||||
// 知识库管理 API(列表、创建、获取、更新、删除、复制)
|
||||
export function listKnowledgeBases() {
|
||||
return get(`/api/v1/knowledge-bases`);
|
||||
export function listKnowledgeBases(params?: { agent_id?: string }) {
|
||||
const query = new URLSearchParams();
|
||||
if (params?.agent_id) query.set('agent_id', params.agent_id);
|
||||
const qs = query.toString();
|
||||
return get(qs ? `/api/v1/knowledge-bases?${qs}` : '/api/v1/knowledge-bases');
|
||||
}
|
||||
|
||||
export function createKnowledgeBase(data: {
|
||||
@@ -23,8 +26,11 @@ export function createKnowledgeBase(data: {
|
||||
return post(`/api/v1/knowledge-bases`, data);
|
||||
}
|
||||
|
||||
export function getKnowledgeBaseById(id: string) {
|
||||
return get(`/api/v1/knowledge-bases/${id}`);
|
||||
export function getKnowledgeBaseById(id: string, options?: { agent_id?: string }) {
|
||||
const query = new URLSearchParams();
|
||||
if (options?.agent_id) query.set('agent_id', options.agent_id);
|
||||
const qs = query.toString();
|
||||
return get(qs ? `/api/v1/knowledge-bases/${id}?${qs}` : `/api/v1/knowledge-bases/${id}`);
|
||||
}
|
||||
|
||||
export function updateKnowledgeBase(id: string, data: { name: string; description?: string; config: any }) {
|
||||
@@ -81,8 +87,11 @@ export function listKnowledgeFiles(
|
||||
return get(`/api/v1/knowledge-bases/${kbId}/knowledge?${qs}`);
|
||||
}
|
||||
|
||||
export function getKnowledgeDetails(id: string) {
|
||||
return get(`/api/v1/knowledge/${id}`);
|
||||
export function getKnowledgeDetails(id: string, options?: { agent_id?: string }) {
|
||||
const query = new URLSearchParams();
|
||||
if (options?.agent_id) query.set('agent_id', options.agent_id);
|
||||
const qs = query.toString();
|
||||
return get(qs ? `/api/v1/knowledge/${id}?${qs}` : `/api/v1/knowledge/${id}`);
|
||||
}
|
||||
|
||||
export function updateManualKnowledge(id: string, data: { title: string; content: string; status: string }) {
|
||||
@@ -98,8 +107,10 @@ export function downKnowledgeDetails(id: string) {
|
||||
}
|
||||
|
||||
/** @param idsQueryString - query string with ids (e.g. ids=xxx&ids=yyy) */
|
||||
export function batchQueryKnowledge(idsQueryString: string, kbId?: string) {
|
||||
const qs = kbId ? `${idsQueryString}&kb_id=${encodeURIComponent(kbId)}` : idsQueryString;
|
||||
export function batchQueryKnowledge(idsQueryString: string, kbId?: string, agentId?: string) {
|
||||
let qs = idsQueryString;
|
||||
if (kbId) qs += `&kb_id=${encodeURIComponent(kbId)}`;
|
||||
if (agentId) qs += `&agent_id=${encodeURIComponent(agentId)}`;
|
||||
return get(`/api/v1/knowledge/batch?${qs}`);
|
||||
}
|
||||
|
||||
@@ -267,10 +278,20 @@ export function updateFAQImportResultDisplayStatus(knowledgeBaseId: string, disp
|
||||
});
|
||||
}
|
||||
|
||||
export function searchKnowledge(keyword: string, offset = 0, limit = 20, fileTypes?: string[]) {
|
||||
let url = `/api/v1/knowledge/search?keyword=${encodeURIComponent(keyword)}&offset=${offset}&limit=${limit}`;
|
||||
export function searchKnowledge(
|
||||
keyword: string,
|
||||
offset = 0,
|
||||
limit = 20,
|
||||
fileTypes?: string[],
|
||||
options?: { agent_id?: string }
|
||||
) {
|
||||
const query = new URLSearchParams();
|
||||
query.set('keyword', keyword);
|
||||
query.set('offset', String(offset));
|
||||
query.set('limit', String(limit));
|
||||
if (fileTypes && fileTypes.length > 0) {
|
||||
url += `&file_types=${encodeURIComponent(fileTypes.join(','))}`;
|
||||
query.set('file_types', fileTypes.join(','));
|
||||
}
|
||||
return get(url);
|
||||
if (options?.agent_id) query.set('agent_id', options.agent_id);
|
||||
return get(`/api/v1/knowledge/search?${query.toString()}`);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ export interface Organization {
|
||||
member_limit?: number
|
||||
member_count?: number
|
||||
share_count?: number
|
||||
agent_share_count?: number
|
||||
pending_join_request_count?: number
|
||||
is_owner?: boolean
|
||||
my_role?: string
|
||||
@@ -80,6 +81,7 @@ export interface OrganizationPreview {
|
||||
avatar?: string
|
||||
member_count: number
|
||||
share_count: number
|
||||
agent_share_count?: number
|
||||
is_already_member: boolean
|
||||
require_approval: boolean
|
||||
created_at: string
|
||||
@@ -94,6 +96,7 @@ export interface SearchableOrganizationItem {
|
||||
member_count: number
|
||||
member_limit: number // 0 = unlimited
|
||||
share_count: number
|
||||
agent_share_count?: number
|
||||
is_already_member: boolean
|
||||
require_approval: boolean
|
||||
}
|
||||
@@ -204,6 +207,47 @@ export interface ListSharesResponse {
|
||||
total: number
|
||||
}
|
||||
|
||||
// Agent share types
|
||||
export interface AgentShareResponse {
|
||||
id: string
|
||||
agent_id: string
|
||||
agent_name?: string
|
||||
organization_id: string
|
||||
organization_name?: string
|
||||
shared_by_user_id: string
|
||||
shared_by_username?: string
|
||||
source_tenant_id: number
|
||||
permission: string
|
||||
my_role_in_org?: string
|
||||
my_permission?: string
|
||||
created_at: string
|
||||
/** Agent scope summary for list display */
|
||||
scope_kb?: string
|
||||
scope_kb_count?: number
|
||||
scope_web_search?: boolean
|
||||
scope_mcp?: string
|
||||
scope_mcp_count?: number
|
||||
/** Agent avatar (emoji) for list display */
|
||||
agent_avatar?: string
|
||||
}
|
||||
|
||||
export interface SharedAgentInfo {
|
||||
agent: { id: string; name: string; description?: string; [key: string]: any }
|
||||
share_id: string
|
||||
organization_id: string
|
||||
org_name: string
|
||||
permission: string
|
||||
source_tenant_id: number
|
||||
shared_at: string
|
||||
shared_by_user_id?: string
|
||||
shared_by_username?: string
|
||||
}
|
||||
|
||||
export interface ListAgentSharesResponse {
|
||||
shares: AgentShareResponse[]
|
||||
total: number
|
||||
}
|
||||
|
||||
// Organization API functions
|
||||
|
||||
/**
|
||||
@@ -520,6 +564,61 @@ export async function listOrgShares(orgId: string): Promise<ApiResponse<ListShar
|
||||
}
|
||||
}
|
||||
|
||||
// Agent sharing
|
||||
export async function shareAgent(agentId: string, req: ShareKnowledgeBaseRequest): Promise<ApiResponse<AgentShareResponse>> {
|
||||
try {
|
||||
const response = await post(`/api/v1/agents/${agentId}/shares`, req)
|
||||
return response as unknown as ApiResponse<AgentShareResponse>
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error.message || 'Failed to share agent' }
|
||||
}
|
||||
}
|
||||
|
||||
export async function listAgentShares(agentId: string): Promise<ApiResponse<ListAgentSharesResponse>> {
|
||||
try {
|
||||
const response = await get(`/api/v1/agents/${agentId}/shares`)
|
||||
return response as unknown as ApiResponse<ListAgentSharesResponse>
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error.message || 'Failed to list agent shares' }
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateAgentSharePermission(agentId: string, shareId: string, req: UpdateSharePermissionRequest): Promise<ApiResponse<void>> {
|
||||
try {
|
||||
const response = await put(`/api/v1/agents/${agentId}/shares/${shareId}`, req)
|
||||
return response as unknown as ApiResponse<void>
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error.message || 'Failed to update share permission' }
|
||||
}
|
||||
}
|
||||
|
||||
export async function removeAgentShare(agentId: string, shareId: string): Promise<ApiResponse<void>> {
|
||||
try {
|
||||
const response = await del(`/api/v1/agents/${agentId}/shares/${shareId}`)
|
||||
return response as unknown as ApiResponse<void>
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error.message || 'Failed to remove share' }
|
||||
}
|
||||
}
|
||||
|
||||
export async function listSharedAgents(): Promise<ApiResponse<SharedAgentInfo[]>> {
|
||||
try {
|
||||
const response = await get('/api/v1/shared-agents')
|
||||
return response as unknown as ApiResponse<SharedAgentInfo[]>
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error.message || 'Failed to list shared agents' }
|
||||
}
|
||||
}
|
||||
|
||||
export async function listOrgAgentShares(orgId: string): Promise<ApiResponse<ListAgentSharesResponse>> {
|
||||
try {
|
||||
const response = await get(`/api/v1/organizations/${orgId}/agent-shares`)
|
||||
return response as unknown as ApiResponse<ListAgentSharesResponse>
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error.message || 'Failed to list organization agent shares' }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search users for inviting to organization (excludes existing members)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user