Compare commits
10 Commits
58a10c3217
...
5f287a06f2
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f287a06f2 | |||
| ff391c31c1 | |||
| 9fde44f11d | |||
| ec69ea88e3 | |||
| 63dec1d8f1 | |||
| c5d0317bb6 | |||
| fa9f64752b | |||
| be91feea63 | |||
| 6c0944d6f2 | |||
| 3c39e3b7e1 |
+1
-1
@@ -12,4 +12,4 @@ node_modules/
|
|||||||
.next/
|
.next/
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
|
|
||||||
.superpowers
|
.superpowersserver
|
||||||
|
|||||||
Vendored
+17
File diff suppressed because one or more lines are too long
@@ -38,9 +38,9 @@ const knowledgeCollectionName = "knowledge_chunks"
|
|||||||
var Index = &index{
|
var Index = &index{
|
||||||
chunkConfig: ChunkingConfig{
|
chunkConfig: ChunkingConfig{
|
||||||
Provider: string(enums.KnowledgeChunkProviderStructured),
|
Provider: string(enums.KnowledgeChunkProviderStructured),
|
||||||
TargetTokens: 300,
|
TargetTokens: 100,
|
||||||
MaxTokens: 400,
|
MaxTokens: 150,
|
||||||
OverlapTokens: 40,
|
OverlapTokens: 20,
|
||||||
EnableFallback: true,
|
EnableFallback: true,
|
||||||
},
|
},
|
||||||
registry: ragchunk.NewDefaultRegistry(),
|
registry: ragchunk.NewDefaultRegistry(),
|
||||||
|
|||||||
@@ -185,6 +185,22 @@ func (c *ConversationController) PostTransfer() *web.JsonResult {
|
|||||||
return web.JsonSuccess()
|
return web.JsonSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ConversationController) PostHandoff() *web.JsonResult {
|
||||||
|
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionConversationAssign)
|
||||||
|
if err != nil {
|
||||||
|
return web.JsonError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req := request.RequestHumanConversationRequest{}
|
||||||
|
if err := params.ReadJSON(c.Ctx, &req); err != nil {
|
||||||
|
return web.JsonError(err)
|
||||||
|
}
|
||||||
|
if err := services.ConversationService.RequestHuman(req.ConversationID, operator); err != nil {
|
||||||
|
return web.JsonError(err)
|
||||||
|
}
|
||||||
|
return web.JsonSuccess()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ConversationController) PostClose() *web.JsonResult {
|
func (c *ConversationController) PostClose() *web.JsonResult {
|
||||||
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionConversationClose)
|
operator, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionConversationClose)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ type TransferConversationRequest struct {
|
|||||||
Reason string `json:"reason"`
|
Reason string `json:"reason"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RequestHumanConversationRequest struct {
|
||||||
|
ConversationID int64 `json:"conversationId"`
|
||||||
|
}
|
||||||
|
|
||||||
type CloseConversationRequest struct {
|
type CloseConversationRequest struct {
|
||||||
ConversationID int64 `json:"conversationId"`
|
ConversationID int64 `json:"conversationId"`
|
||||||
CloseReason string `json:"closeReason"`
|
CloseReason string `json:"closeReason"`
|
||||||
|
|||||||
@@ -374,6 +374,38 @@ func (s *conversationService) TryOffHoursHandoffByAI(conversationID int64, aiAge
|
|||||||
return handled, err
|
return handled, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *conversationService) RequestHuman(conversationID int64, operator *dto.AuthPrincipal) error {
|
||||||
|
if operator == nil {
|
||||||
|
return errorsx.Unauthorized("未登录或登录已过期")
|
||||||
|
}
|
||||||
|
conversation := s.Get(conversationID)
|
||||||
|
if conversation == nil {
|
||||||
|
return errorsx.InvalidParam("会话不存在")
|
||||||
|
}
|
||||||
|
if conversation.Status != enums.IMConversationStatusAIServing {
|
||||||
|
return errorsx.InvalidParam("当前会话状态不允许转人工")
|
||||||
|
}
|
||||||
|
now := time.Now()
|
||||||
|
return sqls.WithTransaction(func(ctx *sqls.TxContext) error {
|
||||||
|
if err := repositories.ConversationRepository.Updates(ctx.Tx, conversationID, map[string]any{
|
||||||
|
"status": enums.IMConversationStatusPending,
|
||||||
|
"update_user_id": operator.UserID,
|
||||||
|
"update_user_name": operator.Username,
|
||||||
|
"updated_at": now,
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return ConversationEventLogService.CreateEvent(ctx, conversationID,
|
||||||
|
enums.IMEventTypeTransfer, enums.IMSenderTypeSystem, 0,
|
||||||
|
"管理员手动转人工",
|
||||||
|
s.buildEventPayload(map[string]any{
|
||||||
|
"operator": operator.Username,
|
||||||
|
"fromStatus": enums.IMConversationStatusAIServing,
|
||||||
|
"toStatus": enums.IMConversationStatusPending,
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (s *conversationService) CloseConversation(conversationID int64, closeReason string, operator *dto.AuthPrincipal) error {
|
func (s *conversationService) CloseConversation(conversationID int64, closeReason string, operator *dto.AuthPrincipal) error {
|
||||||
if operator == nil {
|
if operator == nil {
|
||||||
return errorsx.Unauthorized("未登录或登录已过期")
|
return errorsx.Unauthorized("未登录或登录已过期")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -111,7 +112,7 @@ func (s *knowledgeDocumentService) CreateKnowledgeDocument(req request.CreateKno
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := rag.Index.IndexDocumentByID(context.Background(), item.ID); err != nil {
|
if err := rag.Index.IndexDocumentByID(context.Background(), item.ID); err != nil {
|
||||||
slog.Error("failed to index created knowledge document", "document_id", item.ID, "error", err)
|
return nil, fmt.Errorf("文档索引失败: %w", err)
|
||||||
}
|
}
|
||||||
item = s.Get(item.ID)
|
item = s.Get(item.ID)
|
||||||
return item, nil
|
return item, nil
|
||||||
@@ -160,7 +161,7 @@ func (s *knowledgeDocumentService) UpdateKnowledgeDocument(req request.UpdateKno
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := rag.Index.IndexDocumentByID(context.Background(), req.ID); err != nil {
|
if err := rag.Index.IndexDocumentByID(context.Background(), req.ID); err != nil {
|
||||||
slog.Error("failed to reindex updated knowledge document", "document_id", req.ID, "error", err)
|
return fmt.Errorf("文档重新索引失败: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,6 +266,15 @@ function AgentEditDialogBody({
|
|||||||
await onSubmit(buildPayload(values));
|
await onSubmit(buildPayload(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onFormError(errors: object) {
|
||||||
|
const firstError = Object.values(errors).find(
|
||||||
|
(e: unknown) => (e as { message?: string })?.message
|
||||||
|
) as { message?: string } | undefined
|
||||||
|
if (firstError?.message) {
|
||||||
|
toast.error(firstError.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ProjectDialog
|
<ProjectDialog
|
||||||
open={open}
|
open={open}
|
||||||
@@ -284,7 +293,7 @@ function AgentEditDialogBody({
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => formRef.current?.requestSubmit()}
|
onClick={() => handleSubmit(onFormSubmit, onFormError)()}
|
||||||
disabled={saving || loading}
|
disabled={saving || loading}
|
||||||
>
|
>
|
||||||
{saving ? "保存中..." : "保存"}
|
{saving ? "保存中..." : "保存"}
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ type ConversationDetailDialogProps = {
|
|||||||
onLoadMoreMessages?: () => void | Promise<void>;
|
onLoadMoreMessages?: () => void | Promise<void>;
|
||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
onOpenAssign: () => void;
|
onOpenAssign: () => void;
|
||||||
onDispatch: () => Promise<void>;
|
onDispatch: () => Promise<void>
|
||||||
|
onRequestHuman?: () => Promise<void>;
|
||||||
onOpenTransfer: () => void;
|
onOpenTransfer: () => void;
|
||||||
onRead: () => Promise<void>;
|
onRead: () => Promise<void>;
|
||||||
onOpenClose: () => void;
|
onOpenClose: () => void;
|
||||||
@@ -272,6 +273,14 @@ export function ConversationDetailDialog({
|
|||||||
: "暂无会话信息"}
|
: "暂无会话信息"}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-wrap gap-2">
|
<div className="flex flex-wrap gap-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => void onRequestHuman?.()}
|
||||||
|
disabled={saving || !currentConversation || currentConversation.status !== 1}
|
||||||
|
>
|
||||||
|
<MessageCircleMoreIcon />
|
||||||
|
{saving ? "处理中..." : "转人工"}
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={onOpenAssign}
|
onClick={onOpenAssign}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import {
|
|||||||
fetchConversations,
|
fetchConversations,
|
||||||
fetchTagsAll,
|
fetchTagsAll,
|
||||||
markConversationRead,
|
markConversationRead,
|
||||||
|
requestHumanConversation,
|
||||||
type AdminAgentProfile,
|
type AdminAgentProfile,
|
||||||
type AdminAgentTeam,
|
type AdminAgentTeam,
|
||||||
type AdminConversation,
|
type AdminConversation,
|
||||||
@@ -610,6 +611,22 @@ export default function DashboardConversationsPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleRequestHuman(item: AdminConversation) {
|
||||||
|
setActionLoadingId(item.id)
|
||||||
|
try {
|
||||||
|
await requestHumanConversation(item.id)
|
||||||
|
toast.success(`已转人工:${item.customerName || `#${item.id}`}`)
|
||||||
|
await loadConversations()
|
||||||
|
if (detailItem?.id === item.id) {
|
||||||
|
await refreshDetail()
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(error instanceof Error ? error.message : "转人工失败")
|
||||||
|
} finally {
|
||||||
|
setActionLoadingId(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleDispatch(item: AdminConversation) {
|
async function handleDispatch(item: AdminConversation) {
|
||||||
setActionLoadingId(item.id)
|
setActionLoadingId(item.id)
|
||||||
try {
|
try {
|
||||||
@@ -761,6 +778,13 @@ export default function DashboardConversationsPage() {
|
|||||||
<MoreHorizontalIcon />
|
<MoreHorizontalIcon />
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end" className="w-44 min-w-44">
|
<DropdownMenuContent align="end" className="w-44 min-w-44">
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => void handleRequestHuman(item)}
|
||||||
|
disabled={actionLoadingId === item.id || item.status !== 1}
|
||||||
|
>
|
||||||
|
<MessageCircleMoreIcon />
|
||||||
|
{actionLoadingId === item.id ? "处理中..." : "转人工"}
|
||||||
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => openAssign(item)}
|
onClick={() => openAssign(item)}
|
||||||
disabled={actionLoadingId === item.id || item.status !== 2}
|
disabled={actionLoadingId === item.id || item.status !== 2}
|
||||||
@@ -838,6 +862,12 @@ export default function DashboardConversationsPage() {
|
|||||||
loadingMoreMessages={detailMessagesLoadingMore}
|
loadingMoreMessages={detailMessagesLoadingMore}
|
||||||
onLoadMoreMessages={loadMoreDetailMessages}
|
onLoadMoreMessages={loadMoreDetailMessages}
|
||||||
onOpenChange={handleDetailOpenChange}
|
onOpenChange={handleDetailOpenChange}
|
||||||
|
onRequestHuman={async () => {
|
||||||
|
if (!detailItem) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await handleRequestHuman(detailItem)
|
||||||
|
}}
|
||||||
onOpenAssign={() => {
|
onOpenAssign={() => {
|
||||||
if (!detailItem) {
|
if (!detailItem) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -833,6 +833,13 @@ export function assignConversation(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function requestHumanConversation(conversationId: number) {
|
||||||
|
return request<void>("/api/dashboard/conversation/handoff", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ conversationId }),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function dispatchConversation(conversationId: number) {
|
export function dispatchConversation(conversationId: number) {
|
||||||
return request<void>("/api/dashboard/conversation/dispatch", {
|
return request<void>("/api/dashboard/conversation/dispatch", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
Reference in New Issue
Block a user