2026-04-12 23:37:52 +08:00
|
|
|
package runtime
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
|
2026-05-31 18:43:48 +08:00
|
|
|
applicationruntime "agent-desk/internal/ai/application/runtime"
|
|
|
|
|
"agent-desk/internal/ai/runtime/graphs"
|
|
|
|
|
"agent-desk/internal/models"
|
2026-04-12 23:37:52 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type runtimeReplyExecutor struct{}
|
|
|
|
|
|
2026-04-19 11:19:51 +08:00
|
|
|
type runtimeReplyRunInput struct {
|
|
|
|
|
Conversation models.Conversation
|
|
|
|
|
Message models.Message
|
|
|
|
|
AIAgent models.AIAgent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type runtimeReplyResumeInput struct {
|
|
|
|
|
Conversation models.Conversation
|
|
|
|
|
Message models.Message
|
|
|
|
|
AIAgent models.AIAgent
|
|
|
|
|
PendingInterrupt *models.ConversationInterrupt
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-12 23:37:52 +08:00
|
|
|
func newRuntimeReplyExecutor() *runtimeReplyExecutor {
|
|
|
|
|
return &runtimeReplyExecutor{}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-27 23:29:02 +08:00
|
|
|
func (e *runtimeReplyExecutor) Run(ctx context.Context, input runtimeReplyRunInput) (*applicationruntime.RunResult, error) {
|
2026-07-25 12:04:06 +08:00
|
|
|
summary, err := applicationruntime.DefaultAgentApplicationService.Run(ctx, applicationruntime.ApplicationRunInput{
|
|
|
|
|
ConversationID: input.Conversation.ID,
|
|
|
|
|
MessageID: input.Message.ID,
|
|
|
|
|
AIAgentID: input.AIAgent.ID,
|
2026-04-12 23:37:52 +08:00
|
|
|
})
|
|
|
|
|
return summary, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-27 23:29:02 +08:00
|
|
|
func (e *runtimeReplyExecutor) ResumePendingInterrupt(ctx context.Context, input runtimeReplyResumeInput) (*applicationruntime.RunResult, error) {
|
2026-04-19 11:19:51 +08:00
|
|
|
if input.PendingInterrupt == nil {
|
2026-04-19 11:40:17 +08:00
|
|
|
return nil, fmt.Errorf("pending interrupt is required")
|
2026-04-12 23:37:52 +08:00
|
|
|
}
|
2026-07-25 12:04:06 +08:00
|
|
|
summary, err := applicationruntime.DefaultAgentApplicationService.Resume(ctx, applicationruntime.ApplicationResumeInput{
|
|
|
|
|
ApplicationRunInput: applicationruntime.ApplicationRunInput{
|
|
|
|
|
ConversationID: input.Conversation.ID,
|
|
|
|
|
MessageID: input.Message.ID,
|
|
|
|
|
AIAgentID: input.AIAgent.ID,
|
|
|
|
|
},
|
2026-04-19 11:19:51 +08:00
|
|
|
CheckPointID: strings.TrimSpace(input.PendingInterrupt.CheckPointID),
|
2026-04-14 11:47:13 +08:00
|
|
|
ResumeData: map[string]string{
|
2026-04-19 11:19:51 +08:00
|
|
|
strings.TrimSpace(input.PendingInterrupt.InterruptID): strings.TrimSpace(input.Message.Content),
|
2026-04-12 23:37:52 +08:00
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
return summary, err
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-27 23:29:02 +08:00
|
|
|
func expiredInterruptSummary() *applicationruntime.RunResult {
|
|
|
|
|
return &applicationruntime.RunResult{
|
2026-04-12 23:37:52 +08:00
|
|
|
Status: "expired",
|
|
|
|
|
ReplyText: graphs.ConfirmationExpiredReply,
|
|
|
|
|
}
|
|
|
|
|
}
|