2026-04-12 13:32:07 +08:00
package tools
import (
"context"
2026-05-31 18:43:48 +08:00
"agent-desk/internal/ai/runtime/graphs"
"agent-desk/internal/ai/runtime/registry"
"agent-desk/internal/models"
"agent-desk/internal/pkg/toolx"
2026-04-12 13:32:07 +08:00
einotool "github.com/cloudwego/eino/components/tool"
"github.com/cloudwego/eino/schema"
einojsonschema "github.com/eino-contrib/jsonschema"
orderedmap "github.com/wk8/go-ordered-map/v2"
)
type PrepareTicketDraftTool struct {
2026-04-17 18:48:45 +08:00
conversation models . Conversation
2026-04-12 13:32:07 +08:00
}
func NewPrepareTicketDraftTool () * PrepareTicketDraftTool {
return & PrepareTicketDraftTool {}
}
2026-04-14 09:56:37 +08:00
func ( t * PrepareTicketDraftTool ) Spec () toolx . ToolSpec {
return toolx . GraphPrepareTicketDraft
}
2026-04-12 13:32:07 +08:00
func ( t * PrepareTicketDraftTool ) Name () string {
2026-04-14 09:51:25 +08:00
return toolx . GraphPrepareTicketDraft . Name
2026-04-12 13:32:07 +08:00
}
func ( t * PrepareTicketDraftTool ) Code () string {
2026-04-14 09:51:25 +08:00
return toolx . GraphPrepareTicketDraft . Code
2026-04-12 13:32:07 +08:00
}
func ( t * PrepareTicketDraftTool ) Enabled ( ctx registry . Context ) bool {
2026-04-17 18:48:45 +08:00
return true
2026-04-12 13:32:07 +08:00
}
func ( t * PrepareTicketDraftTool ) Build ( ctx registry . Context ) ( einotool . BaseTool , error ) {
if ! t . Enabled ( ctx ) {
return nil , nil
}
return & PrepareTicketDraftTool { conversation : ctx . Conversation }, nil
}
func ( t * PrepareTicketDraftTool ) Info ( ctx context . Context ) ( * schema . ToolInfo , error ) {
return & schema . ToolInfo {
2026-04-14 09:51:25 +08:00
Name : toolx . GraphPrepareTicketDraft . Name ,
2026-05-31 20:06:44 +08:00
Desc : "Graph Tool. Prepares a ticket draft from the current conversation and collected information. Use it before create_ticket_with_confirmation when the ticket content needs to be organized." ,
2026-04-12 13:32:07 +08:00
ParamsOneOf : schema . NewParamsOneOfByJSONSchema ( & einojsonschema . Schema {
Version : einojsonschema . Version ,
Type : "object" ,
Properties : orderedmap . New [ string , * einojsonschema . Schema ]( orderedmap . WithInitialData (
orderedmap . Pair [ string , * einojsonschema . Schema ]{
Key : "title" ,
Value : & einojsonschema . Schema {
Type : "string" ,
2026-05-31 20:06:44 +08:00
Description : "Prepared ticket title. Optional." ,
2026-04-12 13:32:07 +08:00
},
},
orderedmap . Pair [ string , * einojsonschema . Schema ]{
Key : "description" ,
Value : & einojsonschema . Schema {
Type : "string" ,
2026-05-31 20:06:44 +08:00
Description : "Prepared ticket description. Optional." ,
2026-04-12 13:32:07 +08:00
},
},
orderedmap . Pair [ string , * einojsonschema . Schema ]{
Key : "issue" ,
Value : & einojsonschema . Schema {
Type : "string" ,
2026-05-31 20:06:44 +08:00
Description : "The issue or error message the user is experiencing." ,
2026-04-12 13:32:07 +08:00
},
},
orderedmap . Pair [ string , * einojsonschema . Schema ]{
Key : "impact" ,
Value : & einojsonschema . Schema {
Type : "string" ,
2026-05-31 20:06:44 +08:00
Description : "Impact scope, such as unable to sign in, unable to place an order, or business interruption." ,
2026-04-12 13:32:07 +08:00
},
},
orderedmap . Pair [ string , * einojsonschema . Schema ]{
Key : "expectedOutcome" ,
Value : & einojsonschema . Schema {
Type : "string" ,
2026-05-31 20:06:44 +08:00
Description : "The user's expected outcome or request." ,
2026-04-12 13:32:07 +08:00
},
},
orderedmap . Pair [ string , * einojsonschema . Schema ]{
Key : "currentAttempt" ,
Value : & einojsonschema . Schema {
Type : "string" ,
Description : "当前已尝试过的处理步骤,可选。" ,
},
},
)),
}),
Extra : map [ string ] any {
2026-04-14 09:51:25 +08:00
"toolCode" : toolx . GraphPrepareTicketDraft . Code ,
2026-04-12 13:32:07 +08:00
"sourceType" : "graph" ,
},
}, nil
}
func ( t * PrepareTicketDraftTool ) InvokableRun ( ctx context . Context , argumentsInJSON string , opts ... einotool . Option ) ( string , error ) {
return graphs . NewPrepareTicketDraftGraph ( t . conversation ). Run ( ctx , argumentsInJSON )
}