2026-04-09 10:01:23 +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-09 10:01:23 +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"
)
2026-04-10 15:45:51 +08:00
type CreateTicketGraphTool struct {
2026-04-17 18:48:45 +08:00
conversation models . Conversation
2026-04-17 17:57:01 +08:00
aiAgent models . AIAgent
2026-04-09 10:01:23 +08:00
}
2026-04-10 15:45:51 +08:00
func NewCreateTicketGraphTool () * CreateTicketGraphTool {
return & CreateTicketGraphTool {}
2026-04-09 10:01:23 +08:00
}
2026-04-14 09:56:37 +08:00
func ( t * CreateTicketGraphTool ) Spec () toolx . ToolSpec {
return toolx . GraphCreateTicketConfirm
}
2026-04-10 15:45:51 +08:00
func ( t * CreateTicketGraphTool ) Name () string {
2026-04-14 09:51:25 +08:00
return toolx . GraphCreateTicketConfirm . Name
2026-04-09 10:01:23 +08:00
}
2026-04-10 15:45:51 +08:00
func ( t * CreateTicketGraphTool ) Code () string {
2026-04-14 09:51:25 +08:00
return toolx . GraphCreateTicketConfirm . Code
2026-04-09 10:01:23 +08:00
}
2026-04-10 15:45:51 +08:00
func ( t * CreateTicketGraphTool ) Enabled ( ctx registry . Context ) bool {
2026-04-17 17:57:01 +08:00
return true
2026-04-09 10:01:23 +08:00
}
2026-04-10 15:45:51 +08:00
func ( t * CreateTicketGraphTool ) Build ( ctx registry . Context ) ( einotool . BaseTool , error ) {
2026-04-09 10:01:23 +08:00
if ! t . Enabled ( ctx ) {
return nil , nil
}
2026-04-10 15:45:51 +08:00
return & CreateTicketGraphTool {
2026-04-09 10:01:23 +08:00
conversation : ctx . Conversation ,
aiAgent : ctx . AIAgent ,
}, nil
}
2026-04-10 15:45:51 +08:00
func ( t * CreateTicketGraphTool ) Info ( ctx context . Context ) ( * schema . ToolInfo , error ) {
2026-04-09 10:01:23 +08:00
return & schema . ToolInfo {
2026-04-14 09:51:25 +08:00
Name : toolx . GraphCreateTicketConfirm . Name ,
2026-05-31 20:06:44 +08:00
Desc : "Graph Tool. Handles ticket parameter preparation, user confirmation, actual ticket creation, and result return. Use only when the user explicitly asks to create a ticket and the title and description are clear." ,
2026-04-09 10:01:23 +08:00
ParamsOneOf : schema . NewParamsOneOfByJSONSchema ( & einojsonschema . Schema {
Version : einojsonschema . Version ,
Type : "object" ,
Required : [] string {
"title" ,
"description" ,
},
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 : "Ticket title. Concisely summarizes the issue." ,
2026-04-09 10:01:23 +08:00
},
},
orderedmap . Pair [ string , * einojsonschema . Schema ]{
Key : "description" ,
Value : & einojsonschema . Schema {
Type : "string" ,
2026-05-31 20:06:44 +08:00
Description : "Ticket description. Clearly captures the user's issue, symptoms, and request." ,
2026-04-09 10:01:23 +08:00
},
},
)),
}),
Extra : map [ string ] any {
2026-04-14 09:51:25 +08:00
"toolCode" : toolx . GraphCreateTicketConfirm . Code ,
2026-04-10 15:45:51 +08:00
"sourceType" : "graph" ,
2026-04-09 10:01:23 +08:00
},
}, nil
}
2026-04-10 15:45:51 +08:00
func ( t * CreateTicketGraphTool ) InvokableRun ( ctx context . Context , argumentsInJSON string , opts ... einotool . Option ) ( string , error ) {
return graphs . NewCreateTicketGraph ( t . conversation , t . aiAgent ). Run ( ctx , argumentsInJSON )
2026-04-09 10:01:23 +08:00
}