Przeglądaj źródła

Merge remote-tracking branch 'origin/feature/compapi_v1.02' into develop/apikey_and_agent_v1

liwei 2 tygodni temu
rodzic
commit
752c0b1d5b
40 zmienionych plików z 9297 dodań i 183 usunięć
  1. 480 0
      crontask/compapi_callback.go
  2. 7 4
      crontask/init.go
  3. 28 8
      desc/openapi/chat.api
  4. 165 22
      ent/client.go
  5. 271 0
      ent/compapiasynctask.go
  6. 198 0
      ent/compapiasynctask/compapiasynctask.go
  7. 1135 0
      ent/compapiasynctask/where.go
  8. 1561 0
      ent/compapiasynctask_create.go
  9. 88 0
      ent/compapiasynctask_delete.go
  10. 526 0
      ent/compapiasynctask_query.go
  11. 910 0
      ent/compapiasynctask_update.go
  12. 2 0
      ent/ent.go
  13. 12 0
      ent/hook/hook.go
  14. 30 0
      ent/intercept/intercept.go
  15. 37 0
      ent/migrate/schema.go
  16. 1384 0
      ent/mutation.go
  17. 82 0
      ent/pagination.go
  18. 3 0
      ent/predicate/predicate.go
  19. 56 0
      ent/runtime/runtime.go
  20. 61 0
      ent/schema/compapi_asynctask.go
  21. 360 0
      ent/set_not_nil.go
  22. 3 0
      ent/tx.go
  23. 15 7
      go.mod
  24. 22 14
      go.sum
  25. 10 16
      internal/handler/chat/chat_completions_handler.go
  26. 262 81
      internal/logic/chat/chat_completions_logic.go
  27. 27 10
      internal/middleware/openauthority_middleware.go
  28. 19 0
      internal/types/compapi.go
  29. 29 6
      internal/types/types.go
  30. 197 0
      internal/utils/compapi/base.go
  31. 1 1
      internal/utils/compapi/config.go
  32. 5 0
      internal/utils/compapi/fastgpt.go
  33. 46 14
      internal/utils/compapi/func.go
  34. 91 0
      internal/utils/compapi/mismatch.go
  35. 160 0
      internal/utils/compapi/result.go
  36. 80 0
      internal/utils/compapi/std.go
  37. 321 0
      internal/utils/typekit/print.go
  38. 217 0
      internal/utils/typekit/print.go.1
  39. 345 0
      internal/utils/typekit/print.go.3
  40. 51 0
      sql/wechat/compapi_asynctask.sql

+ 480 - 0
crontask/compapi_callback.go

@@ -0,0 +1,480 @@
+package crontask
+
+import (
+	"bytes"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"hash/fnv"
+	"runtime"
+	"strconv"
+	"strings"
+	"sync"
+	"sync/atomic"
+	"time"
+	"wechat-api/ent"
+	"wechat-api/ent/compapiasynctask"
+	"wechat-api/ent/predicate"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/compapi"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+const (
+	Task_Ready    = 10 //任务就绪
+	ReqApi_Done   = 20 //请求API完成
+	Callback_Done = 30 //请求回调完成
+	All_Done      = 30 //全部完成
+	Task_Suspend  = 60 //任务暂停
+	Task_Fail     = 70 //任务失败
+
+	//MaxWorker   = 5    //最大并发worker数量
+	MaxLoadTask = 1000 //一次最大获取任务数量
+
+	LoopTryCount    = 3 //循环体内重试次数
+	ErrTaskTryCount = 3 //最大允许错误任务重试次数
+
+	DefaultDisId = "DIS0001"
+)
+
+type Task struct {
+	Data *ent.CompapiAsynctask
+	Idx  int
+	Code int
+}
+
+// 带会话管理的任务通道组
+type TaskDispatcher struct {
+	mu        sync.Mutex
+	workerChs []chan Task // 每个worker独立通道
+}
+
+func NewTaskDispatcher(channelCount int) *TaskDispatcher {
+	td := &TaskDispatcher{
+		workerChs: make([]chan Task, channelCount),
+	}
+
+	// 初始化worker通道
+	for i := range td.workerChs {
+		td.workerChs[i] = make(chan Task, 100) // 每个worker带缓冲
+		//fmt.Printf("make worker chan:%d\n", i+1)
+	}
+	return td
+}
+
+// 按woker下标索引选择workerChs
+func (td *TaskDispatcher) getWorkerChanByIdx(idx int) (int, chan Task) {
+	nidx := idx % len(td.workerChs)
+	return nidx, td.workerChs[nidx]
+}
+
+// 按哈希分片选择workerChs
+func (td *TaskDispatcher) getWorkerChanByHash(disID string) (int, chan Task) {
+	if len(disID) == 0 {
+		disID = DefaultDisId
+	}
+	idx := 0
+	if len(td.workerChs) > 1 {
+		h := fnv.New32a()
+		h.Write([]byte(disID))
+		idx = int(h.Sum32()) % len(td.workerChs)
+	}
+	outStr := fmt.Sprintf("getWorkerChannel by disId Hash:'%s',from workerChs{", disID)
+	for i := range len(td.workerChs) {
+		outStr += fmt.Sprintf("#%d", i+1)
+		if i < len(td.workerChs)-1 {
+			outStr += ","
+		}
+	}
+	outStr += fmt.Sprintf("} choice chs:'#%d' by '%s'", idx+1, disID)
+	logx.Debug(outStr)
+
+	return idx, td.workerChs[idx]
+}
+
+// 分配任务到对应的消费channel
+func (td *TaskDispatcher) Dispatch(task Task) {
+	td.mu.Lock()
+	defer td.mu.Unlock()
+
+	// 根据chatId哈希获得其对应的workerChan
+	workerChIdx, workerCh := td.getWorkerChanByHash(task.Data.EventType)
+	// 将任务送入该chatid的workerChan
+	workerCh <- task
+	logx.Debugf("Producer:EventType:[%s] Task Push to WorkerChan:#%d", task.Data.EventType, workerChIdx+1)
+}
+
+func getGoroutineId() (int64, error) {
+	// 堆栈结果中需要消除的前缀符
+	var goroutineSpace = []byte("goroutine ")
+
+	bs := make([]byte, 128)
+	bs = bs[:runtime.Stack(bs, false)]
+	bs = bytes.TrimPrefix(bs, goroutineSpace)
+	i := bytes.IndexByte(bs, ' ')
+	if i < 0 {
+		return -1, errors.New("get current goroutine id failed")
+	}
+	return strconv.ParseInt(string(bs[:i]), 10, 64)
+}
+
+func (l *CronTask) CliTest(MaxWorker int, MaxChannel int) {
+	l.compApiCallback(MaxWorker, MaxChannel)
+}
+
+func (l *CronTask) compApiCallback(MaxWorker int, MaxChannel int) {
+
+	var (
+		wg       sync.WaitGroup
+		produced int64 //生产数量(原子计数器)
+		consumed int64 //消费数量(原子计数器)
+	)
+	//创建任务分发器
+	if MaxWorker <= 0 {
+		MaxWorker = 2
+	}
+	if MaxChannel <= 0 || MaxChannel > MaxWorker {
+		MaxChannel = MaxWorker
+	}
+	dispatcher := NewTaskDispatcher(MaxChannel)
+
+	//启动消费者
+	for widx := range MaxWorker {
+		cidx, ch := dispatcher.getWorkerChanByIdx(widx)
+		wg.Add(1)
+		go func(workerID int, channelID int, taskCh chan Task) {
+			defer wg.Done()
+			gid, _ := getGoroutineId()
+			logx.Infof("Consumer %d(Goroutine:%d) bind WorkerChan:#%d start......\n",
+				workerID, gid, channelID)
+			for task := range taskCh {
+				l.processTask(workerID, task)
+				atomic.AddInt64(&consumed, 1)
+			}
+		}(widx+1, cidx+1, ch)
+	}
+
+	// 生产者
+	wg.Add(1)
+	go func() {
+		defer wg.Done()
+		gid, _ := getGoroutineId()
+		logx.Infof("Producer 1(Goroutine:%d) start......\n", gid)
+		//获得待处理异步任务列表
+		tasks, err := l.getAsyncReqTaskList()
+		if err != nil {
+			logx.Errorf("getAsyncReqTaskList err:%s", err)
+			return
+		}
+
+		// 分发任务
+		for _, task := range tasks {
+			dispatcher.Dispatch(task)
+			atomic.AddInt64(&produced, 1)
+		}
+
+		logx.Infof("📦Producer 1 此批次共创建任务%d件", len(tasks))
+
+		// 关闭所有会话通道
+		dispatcher.mu.Lock()
+		for _, ch := range dispatcher.workerChs {
+			_ = ch
+			close(ch)
+		}
+		dispatcher.mu.Unlock()
+	}()
+
+	wg.Wait()
+	if atomic.LoadInt64(&produced) > 0 {
+		logx.Infof("🏁本次任务完成度统计: Producer:1,Consumer:%d (%d/%d)*100=%d%%", MaxWorker, atomic.LoadInt64(&consumed), atomic.LoadInt64(&produced),
+			(atomic.LoadInt64(&consumed)/atomic.LoadInt64(&produced))*100)
+	}
+}
+
+func (l *CronTask) getAsyncReqTaskList() ([]Task, error) {
+	var predicates []predicate.CompapiAsynctask
+	predicates = append(predicates, compapiasynctask.TaskStatusLT(All_Done))
+
+	var tasks []Task
+	res, err := l.svcCtx.DB.CompapiAsynctask.Query().Where(predicates...).
+		Order(ent.Asc(compapiasynctask.FieldID)).
+		Limit(MaxLoadTask).
+		All(l.ctx)
+	if err == nil {
+		for idx, val := range res {
+			tasks = append(tasks, Task{Data: val, Idx: idx})
+		}
+	}
+	return tasks, err
+}
+
+func (l *CronTask) processTask(workerID int, task Task) {
+	/*
+		fmt.Printf("In processTask,Consumer(%d) dealing Task Detail: User(%s/%s/%s) Async Call %s(%s) on Status:%d\n",
+			workerID, task.Data.EventType, task.Data.ChatID, task.Data.AuthToken,
+			task.Data.OpenaiBase, task.Data.OpenaiKey, task.Data.TaskStatus)*/
+	_ = workerID
+	var err error
+	rt := 0
+	for {
+		if task.Data.TaskStatus >= All_Done {
+			break
+		}
+		switch task.Data.TaskStatus {
+		case Task_Ready:
+			//请求API平台
+			//	succ: taskStatus Task_Ready => ReqApi_Done
+			//  fail: taskStatus保持当前不变或Task_Fail
+			rt, err = l.requestAPI(task.Data)
+		case ReqApi_Done:
+			//结果回调
+			// succ: taskStatus ReqApi_Done => Callback_Done(All_Done)
+			// fail: taskStatus保持当前不变或Task_Fail
+			rt, err = l.requestCallback(task.Data)
+		}
+		if err != nil {
+			//收集错误
+			if rt == 0 {
+				//不可恢复错误处理....
+			}
+			logx.Debugf("Task ignore by '%s'", err)
+			return //先暂时忽略处理,也许应按错误类型分别对待
+		}
+	}
+}
+
+func (l *CronTask) requestCallback(taskData *ent.CompapiAsynctask) (int, error) {
+	workerId, _ := getGoroutineId()
+	logx.Debugf("Worker:%d INTO requestCallback for task status:%d", workerId, taskData.TaskStatus)
+
+	if needStop, _ := l.checkErrRetry(taskData); needStop { //重试次数检测,如果超过直接标为永久失败而不再处理
+		return 1, errors.New("too many err retry")
+	}
+	if taskData.TaskStatus != ReqApi_Done {
+		return 0, fmt.Errorf("invalid task run order for status:%d", taskData.TaskStatus)
+	}
+
+	if len(taskData.CallbackURL) == 0 {
+		return 0, errors.New("callback url empty")
+	}
+	if len(taskData.ResponseRaw) == 0 {
+		return 0, errors.New("call api response empty")
+	}
+
+	fstr := "mytest-svc:"
+	if taskData.RetryCount > 0 && strings.Contains(taskData.CallbackURL, fstr) {
+		taskData.CallbackURL = strings.Replace(taskData.CallbackURL, fstr, "0.0.0.0:", 1)
+	}
+
+	//先开启事务更新任务状态 => Callback_Done(回调完成)
+	tx, err := l.updateTaskStatusByTx(taskData.ID, Callback_Done)
+	if err != nil {
+		return 0, err
+	}
+
+	//请求预先给定的callback_url
+	var res map[string]any
+	//初始化client
+	client := compapi.NewClient(l.ctx)
+	for i := range LoopTryCount { //重试机制
+
+		res, err = client.Callback(taskData.EventType, taskData.CallbackURL, taskData.ResponseRaw)
+		//_, err = client.Chat.Completions.New(l.ctx, emptyParams, opts...)
+		if err == nil {
+			//call succ
+			//fmt.Println("callback succ..........")
+			//fmt.Println(typekit.PrettyPrint(res))
+			logx.Infof("callback:'%s' succ", taskData.CallbackURL)
+			break
+		}
+		logx.Infof("Worker:%d call '%s' fail: '%s',sleep %d Second for next(%d/%d/%d)", workerId,
+			taskData.CallbackURL, err, 1+i*5, i+1, LoopTryCount, taskData.RetryCount)
+		time.Sleep(time.Duration(1+i*5) * time.Second)
+	}
+
+	//多次循环之后依然失败,进入错误任务处理环节
+	if err != nil {
+		_ = tx.Rollback() //回滚之前更新状态
+		//fmt.Printf("Worker:%d client.Chat.Completions.New Fail,Rollback......\n", workerId)
+		err1 := l.dealErrorTask(taskData, err) //错误任务处理
+		et := 1
+		if err1 != nil {
+			et = 0
+		}
+		return et, err
+	}
+	//成功后处理环节
+	err = tx.Commit() //事务提交
+	if err != nil {
+		return 0, err
+	}
+
+	//更新taskData.CallbackResponseRaw
+	l.updateCallbackResponse(taskData.ID, res)
+
+	taskData.TaskStatus = Callback_Done //状态迁移
+	return 1, nil
+}
+
+func (l *CronTask) requestAPI(taskData *ent.CompapiAsynctask) (int, error) {
+	workerId, _ := getGoroutineId()
+	logx.Debugf("Worker:%d INTO requestAPI for task status:%d", workerId, taskData.TaskStatus)
+
+	if needStop, _ := l.checkErrRetry(taskData); needStop { //重试次数检测,如果超过直接标为永久失败而不再处理
+		return 1, errors.New("too many err retry")
+	}
+
+	if taskData.TaskStatus != Task_Ready {
+		return 0, fmt.Errorf("invalid task run order for status:%d", taskData.TaskStatus)
+	}
+	var (
+		err     error
+		apiResp *types.CompOpenApiResp
+		tx      *ent.Tx
+	)
+	req := types.CompApiReq{}
+	if err = json.Unmarshal([]byte(taskData.RequestRaw), &req); err != nil {
+		return 0, err
+	}
+	//先开启事务更新任务状态 => ReqApi_Done(请求API完成)
+	tx, err = l.updateTaskStatusByTx(taskData.ID, ReqApi_Done)
+	if err != nil {
+		return 0, err
+	}
+
+	//初始化client
+	client := compapi.NewClient(l.ctx, compapi.WithApiBase(taskData.OpenaiBase),
+		compapi.WithApiKey(taskData.OpenaiKey))
+
+	for i := range LoopTryCount { //重试机制
+
+		apiResp, err = client.Chat(&req)
+
+		if err == nil && apiResp != nil && len(apiResp.Choices) > 0 {
+			//call succ
+			break
+		} else if apiResp != nil && len(apiResp.Choices) == 0 {
+			err = errors.New("返回结果缺失,请检查访问权限")
+		}
+
+		logx.Infof("Worker:%d call '%s' fail: '%s',sleep %d Second for next(%d/%d/%d)", workerId,
+			taskData.CallbackURL, err, 1+i*5, i+1, LoopTryCount, taskData.RetryCount)
+		time.Sleep(time.Duration(1+i*5) * time.Second)
+	}
+
+	//多次循环之后依然失败,进入错误任务处理环节
+	if err != nil || apiResp == nil {
+		if apiResp == nil && err == nil {
+			err = errors.New("resp is null")
+		}
+		_ = tx.Rollback()                      //回滚之前更新状态
+		err1 := l.dealErrorTask(taskData, err) //错误任务处理
+		et := 1
+		if err1 != nil {
+			et = 0
+		}
+		return et, err
+	}
+	//成功后处理环节
+
+	//更新taskData.ResponseRaw
+	taskData.ResponseRaw, err = (*apiResp).ToString()
+	if err != nil {
+		_ = tx.Rollback() //回滚之前更新状态
+		return 0, err
+	}
+	err = l.updateApiResponseByTx(tx, taskData.ID, taskData.ResponseRaw)
+	if err != nil {
+		return 0, err
+	}
+	err = tx.Commit() //事务提交
+	//fmt.Printf("Worker:%d requestAPI事务提交\n", workerId)
+	if err != nil {
+		return 0, err
+	}
+	taskData.TaskStatus = ReqApi_Done //状态迁移
+
+	return 1, nil
+}
+
+// 更新任务状态事务版
+func (l *CronTask) updateTaskStatusByTx(Id uint64, status int) (*ent.Tx, error) {
+	//开启Mysql事务
+	tx, _ := l.svcCtx.DB.Tx(l.ctx)
+	_, err := tx.CompapiAsynctask.UpdateOneID(Id).
+		SetTaskStatus(int8(status)).
+		SetUpdatedAt(time.Now()).
+		Save(l.ctx)
+	if err != nil {
+		return nil, err
+	}
+	return tx, nil
+}
+
+// 更新请求大模型后结果事务版
+func (l *CronTask) updateApiResponseByTx(tx *ent.Tx, taskId uint64, apiResponse string) error {
+	_, err := tx.CompapiAsynctask.UpdateOneID(taskId).
+		SetUpdatedAt(time.Now()).
+		SetResponseRaw(apiResponse).
+		SetLastError("").
+		SetRetryCount(0).
+		Save(l.ctx)
+	if err != nil {
+		_ = tx.Rollback() //回滚之前更新状态
+	}
+	return err
+}
+
+func (l *CronTask) updateCallbackResponse(taskId uint64, callRes any) error {
+	callResStr := ""
+	switch v := callRes.(type) {
+	case []byte:
+		callResStr = string(v)
+	default:
+		if bs, err := json.Marshal(v); err == nil {
+			callResStr = string(bs)
+		} else {
+			return err
+		}
+	}
+	_, err := l.svcCtx.DB.CompapiAsynctask.UpdateOneID(taskId).
+		SetUpdatedAt(time.Now()).
+		SetCallbackResponseRaw(callResStr).
+		SetLastError("").
+		SetRetryCount(0).
+		Save(l.ctx)
+	return err
+}
+
+func (l *CronTask) checkErrRetry(taskData *ent.CompapiAsynctask) (bool, error) {
+	var err error
+	var needStop = false
+	if taskData.RetryCount >= ErrTaskTryCount { //错误任务尝试次数超过约定则将任务状态永久设为失败
+		_, err = l.svcCtx.DB.CompapiAsynctask.UpdateOneID(taskData.ID).
+			SetUpdatedAt(time.Now()).
+			SetTaskStatus(int8(Task_Fail)).
+			Save(l.ctx)
+		if err == nil {
+			needStop = true
+			taskData.TaskStatus = Task_Fail
+		}
+	}
+	return needStop, err
+}
+
+// 错误任务处理
+func (l *CronTask) dealErrorTask(taskData *ent.CompapiAsynctask, lasterr error) error {
+	logx.Debug("多次循环之后依然失败,进入错误任务处理环节")
+	cauo := l.svcCtx.DB.CompapiAsynctask.UpdateOneID(taskData.ID).
+		SetUpdatedAt(time.Now())
+	if taskData.RetryCount >= ErrTaskTryCount { //错误任务尝试次数超过约定则将任务状态永久设为失败
+		taskData.TaskStatus = Task_Fail
+		cauo = cauo.SetTaskStatus(int8(Task_Fail))
+	} else {
+		cauo = cauo.SetRetryCount(taskData.RetryCount + 1).
+			SetLastError(lasterr.Error())
+	}
+	_, err := cauo.Save(l.ctx)
+	return err
+}

+ 7 - 4
crontask/init.go

@@ -23,13 +23,14 @@ func NewCronTask(ctx context.Context, svcCtx *svc.ServiceContext) *CronTask {
 }
 
 func ScheduleRun(c *cron.Cron, serverCtx *svc.ServiceContext) {
+
 	l := NewCronTask(context.Background(), serverCtx)
 	c.AddFunc("* * * * *", func() {
 		l.sendMsg()
 	})
 
 	sendWx := NewCronTask(context.Background(), serverCtx)
-	c.AddFunc("* * * * *", func() {
+	c.AddFunc("*/30 * * * *", func() {
 		sendWx.sendWx()
 	})
 
@@ -43,8 +44,10 @@ func ScheduleRun(c *cron.Cron, serverCtx *svc.ServiceContext) {
 		computeStatistic.computeStatistic()
 	})
 
-	syncWx := NewCronTask(context.Background(), serverCtx)
-	c.AddFunc("*/30 * * * *", func() {
-		syncWx.syncWx()
+	l = NewCronTask(context.Background(), serverCtx)
+	c.AddFunc("* * * * *", func() {
+		MaxWorker := 10
+		MaxChannel := 3
+		l.compApiCallback(MaxWorker, MaxChannel)
 	})
 }

+ 28 - 8
desc/openapi/chat.api

@@ -24,6 +24,8 @@ type (
         Messages []StdCompMessage `json:"messages"`
         //Stream 是否流式输出
         Stream bool `json:"stream,default=false"`
+		//格式化输出定义
+		ResponseFormat interface{} `json:"response_format,omitempty"`
     }
 
 	//关于工作流配置的请求信息
@@ -31,36 +33,38 @@ type (
 		//EventType事件类型
         EventType string `json:"event_type,default=fastgpt"`
         //WorkId工作流ID
-        WorkId string `json:"work_id"`
+        WorkId string `json:"work_id,optional,omitempty"`
 		//IsBatch 是同步还是异步,默认及取值false表明同步
         IsBatch bool `json:"is_batch,default=false"`
         //异步回调地址
-        Callback string `json:"callback,optional"`
+        Callback string `json:"callback,optional,omitempty"`
 	}
 
 	FastGptSpecReq {
         //ChatId
-        ChatId string `json:"chat_id,optional"`
+        ChatId string `json:"chat_id,optional,omitempty"`
 		//FastgptChatId
-		FastgptChatId string `json:"chatId,optional"`
+		FastgptChatId string `json:"chatId,optional,omitempty"`
         //ResponseChatItemId
-        ResponseChatItemId string `json:"response_chat_item_id,optional"`
+        ResponseChatItemId string `json:"response_chat_item_id,optional,omitempty"`
         //Detail 详情开关
         Detail bool `json:"detail,default=false"`
         //Variables
-        Variables map[string]string `json:"variables,optional"`
+        Variables map[string]string `json:"variables,optional,omitempty"`
 	}
 	
 	StdCompMessage {
         Role string `json:"role"`
-        Content interface{} `json:"content"`
+		Content interface{} `json:"content"`
+        //Content string `json:"content"`
     }
 
     //以下是API响应类型
 	CompOpenApiResp {
         StdCompApiResp
 		FastgptSpecResp
-    }
+		FastgptErrResp
+	}
 
 	StdCompApiResp {
         // A unique identifier for the chat completion.
@@ -89,6 +93,22 @@ type (
 		ResponseData []map[string]interface{} `json:"responseData,omitempty"`
 		NewVariables map[string]interface{} `json:"newVariables,omitempty"`
 	}
+
+	FastgptErrResp {
+		FgtErrCode *int `json:"code,omitempty"`
+		FgtErrStatusTxt *string `json:"statusText,omitempty"`
+		FgtErrMessage *string `json:"message,omitempty"`
+	}
+	
+	DeepseekErrResp {
+		DSErr DeepseekErrInfo `json:"error,omitempty"`
+	}
+	DeepseekErrInfo {
+		Message string `json:"message,omitempty"`
+		Type string `json:"type,omitempty"`
+		Code string `json:"code,omitempty"`
+		Param interface{} `json:"param,omitempty"`
+	}
 	
 	ChatCompletionAudio {
 	    // Unique identifier for this audio response.

+ 165 - 22
ent/client.go

@@ -20,6 +20,7 @@ import (
 	"wechat-api/ent/category"
 	"wechat-api/ent/chatrecords"
 	"wechat-api/ent/chatsession"
+	"wechat-api/ent/compapiasynctask"
 	"wechat-api/ent/contact"
 	"wechat-api/ent/creditbalance"
 	"wechat-api/ent/creditusage"
@@ -84,6 +85,8 @@ type Client struct {
 	ChatRecords *ChatRecordsClient
 	// ChatSession is the client for interacting with the ChatSession builders.
 	ChatSession *ChatSessionClient
+	// CompapiAsynctask is the client for interacting with the CompapiAsynctask builders.
+	CompapiAsynctask *CompapiAsynctaskClient
 	// Contact is the client for interacting with the Contact builders.
 	Contact *ContactClient
 	// CreditBalance is the client for interacting with the CreditBalance builders.
@@ -168,6 +171,7 @@ func (c *Client) init() {
 	c.Category = NewCategoryClient(c.config)
 	c.ChatRecords = NewChatRecordsClient(c.config)
 	c.ChatSession = NewChatSessionClient(c.config)
+	c.CompapiAsynctask = NewCompapiAsynctaskClient(c.config)
 	c.Contact = NewContactClient(c.config)
 	c.CreditBalance = NewCreditBalanceClient(c.config)
 	c.CreditUsage = NewCreditUsageClient(c.config)
@@ -301,6 +305,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
 		Category:            NewCategoryClient(cfg),
 		ChatRecords:         NewChatRecordsClient(cfg),
 		ChatSession:         NewChatSessionClient(cfg),
+		CompapiAsynctask:    NewCompapiAsynctaskClient(cfg),
 		Contact:             NewContactClient(cfg),
 		CreditBalance:       NewCreditBalanceClient(cfg),
 		CreditUsage:         NewCreditUsageClient(cfg),
@@ -361,6 +366,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
 		Category:            NewCategoryClient(cfg),
 		ChatRecords:         NewChatRecordsClient(cfg),
 		ChatSession:         NewChatSessionClient(cfg),
+		CompapiAsynctask:    NewCompapiAsynctaskClient(cfg),
 		Contact:             NewContactClient(cfg),
 		CreditBalance:       NewCreditBalanceClient(cfg),
 		CreditUsage:         NewCreditUsageClient(cfg),
@@ -423,13 +429,14 @@ func (c *Client) Close() error {
 func (c *Client) Use(hooks ...Hook) {
 	for _, n := range []interface{ Use(...Hook) }{
 		c.Agent, c.AgentBase, c.AliyunAvatar, c.AllocAgent, c.ApiKey, c.BatchMsg,
-		c.Category, c.ChatRecords, c.ChatSession, c.Contact, c.CreditBalance,
-		c.CreditUsage, c.Employee, c.EmployeeConfig, c.Label, c.LabelRelationship,
-		c.LabelTagging, c.Message, c.MessageRecords, c.Msg, c.PayRecharge, c.Server,
-		c.SopNode, c.SopStage, c.SopTask, c.Token, c.Tutorial, c.UsageDetail,
-		c.UsageStatisticDay, c.UsageStatisticHour, c.UsageStatisticMonth, c.UsageTotal,
-		c.Whatsapp, c.WhatsappChannel, c.WorkExperience, c.WpChatroom,
-		c.WpChatroomMember, c.Wx, c.WxCard, c.WxCardUser, c.WxCardVisit,
+		c.Category, c.ChatRecords, c.ChatSession, c.CompapiAsynctask, c.Contact,
+		c.CreditBalance, c.CreditUsage, c.Employee, c.EmployeeConfig, c.Label,
+		c.LabelRelationship, c.LabelTagging, c.Message, c.MessageRecords, c.Msg,
+		c.PayRecharge, c.Server, c.SopNode, c.SopStage, c.SopTask, c.Token, c.Tutorial,
+		c.UsageDetail, c.UsageStatisticDay, c.UsageStatisticHour,
+		c.UsageStatisticMonth, c.UsageTotal, c.Whatsapp, c.WhatsappChannel,
+		c.WorkExperience, c.WpChatroom, c.WpChatroomMember, c.Wx, c.WxCard,
+		c.WxCardUser, c.WxCardVisit,
 	} {
 		n.Use(hooks...)
 	}
@@ -440,13 +447,14 @@ func (c *Client) Use(hooks ...Hook) {
 func (c *Client) Intercept(interceptors ...Interceptor) {
 	for _, n := range []interface{ Intercept(...Interceptor) }{
 		c.Agent, c.AgentBase, c.AliyunAvatar, c.AllocAgent, c.ApiKey, c.BatchMsg,
-		c.Category, c.ChatRecords, c.ChatSession, c.Contact, c.CreditBalance,
-		c.CreditUsage, c.Employee, c.EmployeeConfig, c.Label, c.LabelRelationship,
-		c.LabelTagging, c.Message, c.MessageRecords, c.Msg, c.PayRecharge, c.Server,
-		c.SopNode, c.SopStage, c.SopTask, c.Token, c.Tutorial, c.UsageDetail,
-		c.UsageStatisticDay, c.UsageStatisticHour, c.UsageStatisticMonth, c.UsageTotal,
-		c.Whatsapp, c.WhatsappChannel, c.WorkExperience, c.WpChatroom,
-		c.WpChatroomMember, c.Wx, c.WxCard, c.WxCardUser, c.WxCardVisit,
+		c.Category, c.ChatRecords, c.ChatSession, c.CompapiAsynctask, c.Contact,
+		c.CreditBalance, c.CreditUsage, c.Employee, c.EmployeeConfig, c.Label,
+		c.LabelRelationship, c.LabelTagging, c.Message, c.MessageRecords, c.Msg,
+		c.PayRecharge, c.Server, c.SopNode, c.SopStage, c.SopTask, c.Token, c.Tutorial,
+		c.UsageDetail, c.UsageStatisticDay, c.UsageStatisticHour,
+		c.UsageStatisticMonth, c.UsageTotal, c.Whatsapp, c.WhatsappChannel,
+		c.WorkExperience, c.WpChatroom, c.WpChatroomMember, c.Wx, c.WxCard,
+		c.WxCardUser, c.WxCardVisit,
 	} {
 		n.Intercept(interceptors...)
 	}
@@ -473,6 +481,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
 		return c.ChatRecords.mutate(ctx, m)
 	case *ChatSessionMutation:
 		return c.ChatSession.mutate(ctx, m)
+	case *CompapiAsynctaskMutation:
+		return c.CompapiAsynctask.mutate(ctx, m)
 	case *ContactMutation:
 		return c.Contact.mutate(ctx, m)
 	case *CreditBalanceMutation:
@@ -1851,6 +1861,139 @@ func (c *ChatSessionClient) mutate(ctx context.Context, m *ChatSessionMutation)
 	}
 }
 
+// CompapiAsynctaskClient is a client for the CompapiAsynctask schema.
+type CompapiAsynctaskClient struct {
+	config
+}
+
+// NewCompapiAsynctaskClient returns a client for the CompapiAsynctask from the given config.
+func NewCompapiAsynctaskClient(c config) *CompapiAsynctaskClient {
+	return &CompapiAsynctaskClient{config: c}
+}
+
+// Use adds a list of mutation hooks to the hooks stack.
+// A call to `Use(f, g, h)` equals to `compapiasynctask.Hooks(f(g(h())))`.
+func (c *CompapiAsynctaskClient) Use(hooks ...Hook) {
+	c.hooks.CompapiAsynctask = append(c.hooks.CompapiAsynctask, hooks...)
+}
+
+// Intercept adds a list of query interceptors to the interceptors stack.
+// A call to `Intercept(f, g, h)` equals to `compapiasynctask.Intercept(f(g(h())))`.
+func (c *CompapiAsynctaskClient) Intercept(interceptors ...Interceptor) {
+	c.inters.CompapiAsynctask = append(c.inters.CompapiAsynctask, interceptors...)
+}
+
+// Create returns a builder for creating a CompapiAsynctask entity.
+func (c *CompapiAsynctaskClient) Create() *CompapiAsynctaskCreate {
+	mutation := newCompapiAsynctaskMutation(c.config, OpCreate)
+	return &CompapiAsynctaskCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
+}
+
+// CreateBulk returns a builder for creating a bulk of CompapiAsynctask entities.
+func (c *CompapiAsynctaskClient) CreateBulk(builders ...*CompapiAsynctaskCreate) *CompapiAsynctaskCreateBulk {
+	return &CompapiAsynctaskCreateBulk{config: c.config, builders: builders}
+}
+
+// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
+// a builder and applies setFunc on it.
+func (c *CompapiAsynctaskClient) MapCreateBulk(slice any, setFunc func(*CompapiAsynctaskCreate, int)) *CompapiAsynctaskCreateBulk {
+	rv := reflect.ValueOf(slice)
+	if rv.Kind() != reflect.Slice {
+		return &CompapiAsynctaskCreateBulk{err: fmt.Errorf("calling to CompapiAsynctaskClient.MapCreateBulk with wrong type %T, need slice", slice)}
+	}
+	builders := make([]*CompapiAsynctaskCreate, rv.Len())
+	for i := 0; i < rv.Len(); i++ {
+		builders[i] = c.Create()
+		setFunc(builders[i], i)
+	}
+	return &CompapiAsynctaskCreateBulk{config: c.config, builders: builders}
+}
+
+// Update returns an update builder for CompapiAsynctask.
+func (c *CompapiAsynctaskClient) Update() *CompapiAsynctaskUpdate {
+	mutation := newCompapiAsynctaskMutation(c.config, OpUpdate)
+	return &CompapiAsynctaskUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
+}
+
+// UpdateOne returns an update builder for the given entity.
+func (c *CompapiAsynctaskClient) UpdateOne(ca *CompapiAsynctask) *CompapiAsynctaskUpdateOne {
+	mutation := newCompapiAsynctaskMutation(c.config, OpUpdateOne, withCompapiAsynctask(ca))
+	return &CompapiAsynctaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
+}
+
+// UpdateOneID returns an update builder for the given id.
+func (c *CompapiAsynctaskClient) UpdateOneID(id uint64) *CompapiAsynctaskUpdateOne {
+	mutation := newCompapiAsynctaskMutation(c.config, OpUpdateOne, withCompapiAsynctaskID(id))
+	return &CompapiAsynctaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
+}
+
+// Delete returns a delete builder for CompapiAsynctask.
+func (c *CompapiAsynctaskClient) Delete() *CompapiAsynctaskDelete {
+	mutation := newCompapiAsynctaskMutation(c.config, OpDelete)
+	return &CompapiAsynctaskDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
+}
+
+// DeleteOne returns a builder for deleting the given entity.
+func (c *CompapiAsynctaskClient) DeleteOne(ca *CompapiAsynctask) *CompapiAsynctaskDeleteOne {
+	return c.DeleteOneID(ca.ID)
+}
+
+// DeleteOneID returns a builder for deleting the given entity by its id.
+func (c *CompapiAsynctaskClient) DeleteOneID(id uint64) *CompapiAsynctaskDeleteOne {
+	builder := c.Delete().Where(compapiasynctask.ID(id))
+	builder.mutation.id = &id
+	builder.mutation.op = OpDeleteOne
+	return &CompapiAsynctaskDeleteOne{builder}
+}
+
+// Query returns a query builder for CompapiAsynctask.
+func (c *CompapiAsynctaskClient) Query() *CompapiAsynctaskQuery {
+	return &CompapiAsynctaskQuery{
+		config: c.config,
+		ctx:    &QueryContext{Type: TypeCompapiAsynctask},
+		inters: c.Interceptors(),
+	}
+}
+
+// Get returns a CompapiAsynctask entity by its id.
+func (c *CompapiAsynctaskClient) Get(ctx context.Context, id uint64) (*CompapiAsynctask, error) {
+	return c.Query().Where(compapiasynctask.ID(id)).Only(ctx)
+}
+
+// GetX is like Get, but panics if an error occurs.
+func (c *CompapiAsynctaskClient) GetX(ctx context.Context, id uint64) *CompapiAsynctask {
+	obj, err := c.Get(ctx, id)
+	if err != nil {
+		panic(err)
+	}
+	return obj
+}
+
+// Hooks returns the client hooks.
+func (c *CompapiAsynctaskClient) Hooks() []Hook {
+	return c.hooks.CompapiAsynctask
+}
+
+// Interceptors returns the client interceptors.
+func (c *CompapiAsynctaskClient) Interceptors() []Interceptor {
+	return c.inters.CompapiAsynctask
+}
+
+func (c *CompapiAsynctaskClient) mutate(ctx context.Context, m *CompapiAsynctaskMutation) (Value, error) {
+	switch m.Op() {
+	case OpCreate:
+		return (&CompapiAsynctaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
+	case OpUpdate:
+		return (&CompapiAsynctaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
+	case OpUpdateOne:
+		return (&CompapiAsynctaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
+	case OpDelete, OpDeleteOne:
+		return (&CompapiAsynctaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
+	default:
+		return nil, fmt.Errorf("ent: unknown CompapiAsynctask mutation op: %q", m.Op())
+	}
+}
+
 // ContactClient is a client for the Contact schema.
 type ContactClient struct {
 	config
@@ -6527,19 +6670,19 @@ func (c *WxCardVisitClient) mutate(ctx context.Context, m *WxCardVisitMutation)
 type (
 	hooks struct {
 		Agent, AgentBase, AliyunAvatar, AllocAgent, ApiKey, BatchMsg, Category,
-		ChatRecords, ChatSession, Contact, CreditBalance, CreditUsage, Employee,
-		EmployeeConfig, Label, LabelRelationship, LabelTagging, Message,
-		MessageRecords, Msg, PayRecharge, Server, SopNode, SopStage, SopTask, Token,
-		Tutorial, UsageDetail, UsageStatisticDay, UsageStatisticHour,
+		ChatRecords, ChatSession, CompapiAsynctask, Contact, CreditBalance,
+		CreditUsage, Employee, EmployeeConfig, Label, LabelRelationship, LabelTagging,
+		Message, MessageRecords, Msg, PayRecharge, Server, SopNode, SopStage, SopTask,
+		Token, Tutorial, UsageDetail, UsageStatisticDay, UsageStatisticHour,
 		UsageStatisticMonth, UsageTotal, Whatsapp, WhatsappChannel, WorkExperience,
 		WpChatroom, WpChatroomMember, Wx, WxCard, WxCardUser, WxCardVisit []ent.Hook
 	}
 	inters struct {
 		Agent, AgentBase, AliyunAvatar, AllocAgent, ApiKey, BatchMsg, Category,
-		ChatRecords, ChatSession, Contact, CreditBalance, CreditUsage, Employee,
-		EmployeeConfig, Label, LabelRelationship, LabelTagging, Message,
-		MessageRecords, Msg, PayRecharge, Server, SopNode, SopStage, SopTask, Token,
-		Tutorial, UsageDetail, UsageStatisticDay, UsageStatisticHour,
+		ChatRecords, ChatSession, CompapiAsynctask, Contact, CreditBalance,
+		CreditUsage, Employee, EmployeeConfig, Label, LabelRelationship, LabelTagging,
+		Message, MessageRecords, Msg, PayRecharge, Server, SopNode, SopStage, SopTask,
+		Token, Tutorial, UsageDetail, UsageStatisticDay, UsageStatisticHour,
 		UsageStatisticMonth, UsageTotal, Whatsapp, WhatsappChannel, WorkExperience,
 		WpChatroom, WpChatroomMember, Wx, WxCard, WxCardUser,
 		WxCardVisit []ent.Interceptor

+ 271 - 0
ent/compapiasynctask.go

@@ -0,0 +1,271 @@
+// Code generated by ent, DO NOT EDIT.
+
+package ent
+
+import (
+	"fmt"
+	"strings"
+	"time"
+	"wechat-api/ent/compapiasynctask"
+
+	"entgo.io/ent"
+	"entgo.io/ent/dialect/sql"
+)
+
+// CompapiAsynctask is the model entity for the CompapiAsynctask schema.
+type CompapiAsynctask struct {
+	config `json:"-"`
+	// ID of the ent.
+	ID uint64 `json:"id,omitempty"`
+	// Create Time | 创建日期
+	CreatedAt time.Time `json:"created_at,omitempty"`
+	// Update Time | 修改日期
+	UpdatedAt time.Time `json:"updated_at,omitempty"`
+	// 发起请求者的授权token
+	AuthToken string `json:"auth_token,omitempty"`
+	// 请求目标类型
+	EventType string `json:"event_type,omitempty"`
+	// 会话ID
+	ChatID string `json:"chat_id,omitempty"`
+	// organization_id | 租户ID
+	OrganizationID uint64 `json:"organization_id,omitempty"`
+	// 待请求的大模型服务地址
+	OpenaiBase string `json:"openai_base,omitempty"`
+	// 待请求的大模型服务密钥授权token
+	OpenaiKey string `json:"openai_key,omitempty"`
+	// 请求参数结构字符串
+	RequestRaw string `json:"request_raw,omitempty"`
+	// 请求响应结构字符串
+	ResponseRaw string `json:"response_raw,omitempty"`
+	// callback_url | 异步执行回调地址
+	CallbackURL string `json:"callback_url,omitempty"`
+	// callback返回结构字符串
+	CallbackResponseRaw string `json:"callback_response_raw,omitempty"`
+	// 所用大模型
+	Model string `json:"model,omitempty"`
+	// callback_status | 任务完成状态 10 任务就绪 20 请求API完成 30 请求回调完成 60 任务暂停 70 任务失败
+	TaskStatus int8 `json:"task_status,omitempty"`
+	// retry count | 重试次数
+	RetryCount int8 `json:"retry_count,omitempty"`
+	// 最后一次出错信息
+	LastError    string `json:"last_error,omitempty"`
+	selectValues sql.SelectValues
+}
+
+// scanValues returns the types for scanning values from sql.Rows.
+func (*CompapiAsynctask) scanValues(columns []string) ([]any, error) {
+	values := make([]any, len(columns))
+	for i := range columns {
+		switch columns[i] {
+		case compapiasynctask.FieldID, compapiasynctask.FieldOrganizationID, compapiasynctask.FieldTaskStatus, compapiasynctask.FieldRetryCount:
+			values[i] = new(sql.NullInt64)
+		case compapiasynctask.FieldAuthToken, compapiasynctask.FieldEventType, compapiasynctask.FieldChatID, compapiasynctask.FieldOpenaiBase, compapiasynctask.FieldOpenaiKey, compapiasynctask.FieldRequestRaw, compapiasynctask.FieldResponseRaw, compapiasynctask.FieldCallbackURL, compapiasynctask.FieldCallbackResponseRaw, compapiasynctask.FieldModel, compapiasynctask.FieldLastError:
+			values[i] = new(sql.NullString)
+		case compapiasynctask.FieldCreatedAt, compapiasynctask.FieldUpdatedAt:
+			values[i] = new(sql.NullTime)
+		default:
+			values[i] = new(sql.UnknownType)
+		}
+	}
+	return values, nil
+}
+
+// assignValues assigns the values that were returned from sql.Rows (after scanning)
+// to the CompapiAsynctask fields.
+func (ca *CompapiAsynctask) assignValues(columns []string, values []any) error {
+	if m, n := len(values), len(columns); m < n {
+		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
+	}
+	for i := range columns {
+		switch columns[i] {
+		case compapiasynctask.FieldID:
+			value, ok := values[i].(*sql.NullInt64)
+			if !ok {
+				return fmt.Errorf("unexpected type %T for field id", value)
+			}
+			ca.ID = uint64(value.Int64)
+		case compapiasynctask.FieldCreatedAt:
+			if value, ok := values[i].(*sql.NullTime); !ok {
+				return fmt.Errorf("unexpected type %T for field created_at", values[i])
+			} else if value.Valid {
+				ca.CreatedAt = value.Time
+			}
+		case compapiasynctask.FieldUpdatedAt:
+			if value, ok := values[i].(*sql.NullTime); !ok {
+				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
+			} else if value.Valid {
+				ca.UpdatedAt = value.Time
+			}
+		case compapiasynctask.FieldAuthToken:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field auth_token", values[i])
+			} else if value.Valid {
+				ca.AuthToken = value.String
+			}
+		case compapiasynctask.FieldEventType:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field event_type", values[i])
+			} else if value.Valid {
+				ca.EventType = value.String
+			}
+		case compapiasynctask.FieldChatID:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field chat_id", values[i])
+			} else if value.Valid {
+				ca.ChatID = value.String
+			}
+		case compapiasynctask.FieldOrganizationID:
+			if value, ok := values[i].(*sql.NullInt64); !ok {
+				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
+			} else if value.Valid {
+				ca.OrganizationID = uint64(value.Int64)
+			}
+		case compapiasynctask.FieldOpenaiBase:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field openai_base", values[i])
+			} else if value.Valid {
+				ca.OpenaiBase = value.String
+			}
+		case compapiasynctask.FieldOpenaiKey:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field openai_key", values[i])
+			} else if value.Valid {
+				ca.OpenaiKey = value.String
+			}
+		case compapiasynctask.FieldRequestRaw:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field request_raw", values[i])
+			} else if value.Valid {
+				ca.RequestRaw = value.String
+			}
+		case compapiasynctask.FieldResponseRaw:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field response_raw", values[i])
+			} else if value.Valid {
+				ca.ResponseRaw = value.String
+			}
+		case compapiasynctask.FieldCallbackURL:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field callback_url", values[i])
+			} else if value.Valid {
+				ca.CallbackURL = value.String
+			}
+		case compapiasynctask.FieldCallbackResponseRaw:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field callback_response_raw", values[i])
+			} else if value.Valid {
+				ca.CallbackResponseRaw = value.String
+			}
+		case compapiasynctask.FieldModel:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field model", values[i])
+			} else if value.Valid {
+				ca.Model = value.String
+			}
+		case compapiasynctask.FieldTaskStatus:
+			if value, ok := values[i].(*sql.NullInt64); !ok {
+				return fmt.Errorf("unexpected type %T for field task_status", values[i])
+			} else if value.Valid {
+				ca.TaskStatus = int8(value.Int64)
+			}
+		case compapiasynctask.FieldRetryCount:
+			if value, ok := values[i].(*sql.NullInt64); !ok {
+				return fmt.Errorf("unexpected type %T for field retry_count", values[i])
+			} else if value.Valid {
+				ca.RetryCount = int8(value.Int64)
+			}
+		case compapiasynctask.FieldLastError:
+			if value, ok := values[i].(*sql.NullString); !ok {
+				return fmt.Errorf("unexpected type %T for field last_error", values[i])
+			} else if value.Valid {
+				ca.LastError = value.String
+			}
+		default:
+			ca.selectValues.Set(columns[i], values[i])
+		}
+	}
+	return nil
+}
+
+// Value returns the ent.Value that was dynamically selected and assigned to the CompapiAsynctask.
+// This includes values selected through modifiers, order, etc.
+func (ca *CompapiAsynctask) Value(name string) (ent.Value, error) {
+	return ca.selectValues.Get(name)
+}
+
+// Update returns a builder for updating this CompapiAsynctask.
+// Note that you need to call CompapiAsynctask.Unwrap() before calling this method if this CompapiAsynctask
+// was returned from a transaction, and the transaction was committed or rolled back.
+func (ca *CompapiAsynctask) Update() *CompapiAsynctaskUpdateOne {
+	return NewCompapiAsynctaskClient(ca.config).UpdateOne(ca)
+}
+
+// Unwrap unwraps the CompapiAsynctask entity that was returned from a transaction after it was closed,
+// so that all future queries will be executed through the driver which created the transaction.
+func (ca *CompapiAsynctask) Unwrap() *CompapiAsynctask {
+	_tx, ok := ca.config.driver.(*txDriver)
+	if !ok {
+		panic("ent: CompapiAsynctask is not a transactional entity")
+	}
+	ca.config.driver = _tx.drv
+	return ca
+}
+
+// String implements the fmt.Stringer.
+func (ca *CompapiAsynctask) String() string {
+	var builder strings.Builder
+	builder.WriteString("CompapiAsynctask(")
+	builder.WriteString(fmt.Sprintf("id=%v, ", ca.ID))
+	builder.WriteString("created_at=")
+	builder.WriteString(ca.CreatedAt.Format(time.ANSIC))
+	builder.WriteString(", ")
+	builder.WriteString("updated_at=")
+	builder.WriteString(ca.UpdatedAt.Format(time.ANSIC))
+	builder.WriteString(", ")
+	builder.WriteString("auth_token=")
+	builder.WriteString(ca.AuthToken)
+	builder.WriteString(", ")
+	builder.WriteString("event_type=")
+	builder.WriteString(ca.EventType)
+	builder.WriteString(", ")
+	builder.WriteString("chat_id=")
+	builder.WriteString(ca.ChatID)
+	builder.WriteString(", ")
+	builder.WriteString("organization_id=")
+	builder.WriteString(fmt.Sprintf("%v", ca.OrganizationID))
+	builder.WriteString(", ")
+	builder.WriteString("openai_base=")
+	builder.WriteString(ca.OpenaiBase)
+	builder.WriteString(", ")
+	builder.WriteString("openai_key=")
+	builder.WriteString(ca.OpenaiKey)
+	builder.WriteString(", ")
+	builder.WriteString("request_raw=")
+	builder.WriteString(ca.RequestRaw)
+	builder.WriteString(", ")
+	builder.WriteString("response_raw=")
+	builder.WriteString(ca.ResponseRaw)
+	builder.WriteString(", ")
+	builder.WriteString("callback_url=")
+	builder.WriteString(ca.CallbackURL)
+	builder.WriteString(", ")
+	builder.WriteString("callback_response_raw=")
+	builder.WriteString(ca.CallbackResponseRaw)
+	builder.WriteString(", ")
+	builder.WriteString("model=")
+	builder.WriteString(ca.Model)
+	builder.WriteString(", ")
+	builder.WriteString("task_status=")
+	builder.WriteString(fmt.Sprintf("%v", ca.TaskStatus))
+	builder.WriteString(", ")
+	builder.WriteString("retry_count=")
+	builder.WriteString(fmt.Sprintf("%v", ca.RetryCount))
+	builder.WriteString(", ")
+	builder.WriteString("last_error=")
+	builder.WriteString(ca.LastError)
+	builder.WriteByte(')')
+	return builder.String()
+}
+
+// CompapiAsynctasks is a parsable slice of CompapiAsynctask.
+type CompapiAsynctasks []*CompapiAsynctask

+ 198 - 0
ent/compapiasynctask/compapiasynctask.go

@@ -0,0 +1,198 @@
+// Code generated by ent, DO NOT EDIT.
+
+package compapiasynctask
+
+import (
+	"time"
+
+	"entgo.io/ent/dialect/sql"
+)
+
+const (
+	// Label holds the string label denoting the compapiasynctask type in the database.
+	Label = "compapi_asynctask"
+	// FieldID holds the string denoting the id field in the database.
+	FieldID = "id"
+	// FieldCreatedAt holds the string denoting the created_at field in the database.
+	FieldCreatedAt = "created_at"
+	// FieldUpdatedAt holds the string denoting the updated_at field in the database.
+	FieldUpdatedAt = "updated_at"
+	// FieldAuthToken holds the string denoting the auth_token field in the database.
+	FieldAuthToken = "auth_token"
+	// FieldEventType holds the string denoting the event_type field in the database.
+	FieldEventType = "event_type"
+	// FieldChatID holds the string denoting the chat_id field in the database.
+	FieldChatID = "chat_id"
+	// FieldOrganizationID holds the string denoting the organization_id field in the database.
+	FieldOrganizationID = "organization_id"
+	// FieldOpenaiBase holds the string denoting the openai_base field in the database.
+	FieldOpenaiBase = "openai_base"
+	// FieldOpenaiKey holds the string denoting the openai_key field in the database.
+	FieldOpenaiKey = "openai_key"
+	// FieldRequestRaw holds the string denoting the request_raw field in the database.
+	FieldRequestRaw = "request_raw"
+	// FieldResponseRaw holds the string denoting the response_raw field in the database.
+	FieldResponseRaw = "response_raw"
+	// FieldCallbackURL holds the string denoting the callback_url field in the database.
+	FieldCallbackURL = "callback_url"
+	// FieldCallbackResponseRaw holds the string denoting the callback_response_raw field in the database.
+	FieldCallbackResponseRaw = "callback_response_raw"
+	// FieldModel holds the string denoting the model field in the database.
+	FieldModel = "model"
+	// FieldTaskStatus holds the string denoting the task_status field in the database.
+	FieldTaskStatus = "task_status"
+	// FieldRetryCount holds the string denoting the retry_count field in the database.
+	FieldRetryCount = "retry_count"
+	// FieldLastError holds the string denoting the last_error field in the database.
+	FieldLastError = "last_error"
+	// Table holds the table name of the compapiasynctask in the database.
+	Table = "compapi_asynctask"
+)
+
+// Columns holds all SQL columns for compapiasynctask fields.
+var Columns = []string{
+	FieldID,
+	FieldCreatedAt,
+	FieldUpdatedAt,
+	FieldAuthToken,
+	FieldEventType,
+	FieldChatID,
+	FieldOrganizationID,
+	FieldOpenaiBase,
+	FieldOpenaiKey,
+	FieldRequestRaw,
+	FieldResponseRaw,
+	FieldCallbackURL,
+	FieldCallbackResponseRaw,
+	FieldModel,
+	FieldTaskStatus,
+	FieldRetryCount,
+	FieldLastError,
+}
+
+// ValidColumn reports if the column name is valid (part of the table columns).
+func ValidColumn(column string) bool {
+	for i := range Columns {
+		if column == Columns[i] {
+			return true
+		}
+	}
+	return false
+}
+
+var (
+	// DefaultCreatedAt holds the default value on creation for the "created_at" field.
+	DefaultCreatedAt func() time.Time
+	// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
+	DefaultUpdatedAt func() time.Time
+	// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
+	UpdateDefaultUpdatedAt func() time.Time
+	// DefaultEventType holds the default value on creation for the "event_type" field.
+	DefaultEventType string
+	// DefaultChatID holds the default value on creation for the "chat_id" field.
+	DefaultChatID string
+	// OrganizationIDValidator is a validator for the "organization_id" field. It is called by the builders before save.
+	OrganizationIDValidator func(uint64) error
+	// DefaultResponseRaw holds the default value on creation for the "response_raw" field.
+	DefaultResponseRaw string
+	// CallbackURLValidator is a validator for the "callback_url" field. It is called by the builders before save.
+	CallbackURLValidator func(string) error
+	// DefaultCallbackResponseRaw holds the default value on creation for the "callback_response_raw" field.
+	DefaultCallbackResponseRaw string
+	// DefaultModel holds the default value on creation for the "model" field.
+	DefaultModel string
+	// DefaultTaskStatus holds the default value on creation for the "task_status" field.
+	DefaultTaskStatus int8
+	// DefaultRetryCount holds the default value on creation for the "retry_count" field.
+	DefaultRetryCount int8
+	// DefaultLastError holds the default value on creation for the "last_error" field.
+	DefaultLastError string
+)
+
+// OrderOption defines the ordering options for the CompapiAsynctask queries.
+type OrderOption func(*sql.Selector)
+
+// ByID orders the results by the id field.
+func ByID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldID, opts...).ToFunc()
+}
+
+// ByCreatedAt orders the results by the created_at field.
+func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
+}
+
+// ByUpdatedAt orders the results by the updated_at field.
+func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
+}
+
+// ByAuthToken orders the results by the auth_token field.
+func ByAuthToken(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldAuthToken, opts...).ToFunc()
+}
+
+// ByEventType orders the results by the event_type field.
+func ByEventType(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldEventType, opts...).ToFunc()
+}
+
+// ByChatID orders the results by the chat_id field.
+func ByChatID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldChatID, opts...).ToFunc()
+}
+
+// ByOrganizationID orders the results by the organization_id field.
+func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()
+}
+
+// ByOpenaiBase orders the results by the openai_base field.
+func ByOpenaiBase(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldOpenaiBase, opts...).ToFunc()
+}
+
+// ByOpenaiKey orders the results by the openai_key field.
+func ByOpenaiKey(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldOpenaiKey, opts...).ToFunc()
+}
+
+// ByRequestRaw orders the results by the request_raw field.
+func ByRequestRaw(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldRequestRaw, opts...).ToFunc()
+}
+
+// ByResponseRaw orders the results by the response_raw field.
+func ByResponseRaw(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldResponseRaw, opts...).ToFunc()
+}
+
+// ByCallbackURL orders the results by the callback_url field.
+func ByCallbackURL(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldCallbackURL, opts...).ToFunc()
+}
+
+// ByCallbackResponseRaw orders the results by the callback_response_raw field.
+func ByCallbackResponseRaw(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldCallbackResponseRaw, opts...).ToFunc()
+}
+
+// ByModel orders the results by the model field.
+func ByModel(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldModel, opts...).ToFunc()
+}
+
+// ByTaskStatus orders the results by the task_status field.
+func ByTaskStatus(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldTaskStatus, opts...).ToFunc()
+}
+
+// ByRetryCount orders the results by the retry_count field.
+func ByRetryCount(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldRetryCount, opts...).ToFunc()
+}
+
+// ByLastError orders the results by the last_error field.
+func ByLastError(opts ...sql.OrderTermOption) OrderOption {
+	return sql.OrderByField(FieldLastError, opts...).ToFunc()
+}

+ 1135 - 0
ent/compapiasynctask/where.go

@@ -0,0 +1,1135 @@
+// Code generated by ent, DO NOT EDIT.
+
+package compapiasynctask
+
+import (
+	"time"
+	"wechat-api/ent/predicate"
+
+	"entgo.io/ent/dialect/sql"
+)
+
+// ID filters vertices based on their ID field.
+func ID(id uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldID, id))
+}
+
+// IDEQ applies the EQ predicate on the ID field.
+func IDEQ(id uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldID, id))
+}
+
+// IDNEQ applies the NEQ predicate on the ID field.
+func IDNEQ(id uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldID, id))
+}
+
+// IDIn applies the In predicate on the ID field.
+func IDIn(ids ...uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldID, ids...))
+}
+
+// IDNotIn applies the NotIn predicate on the ID field.
+func IDNotIn(ids ...uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldID, ids...))
+}
+
+// IDGT applies the GT predicate on the ID field.
+func IDGT(id uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldID, id))
+}
+
+// IDGTE applies the GTE predicate on the ID field.
+func IDGTE(id uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldID, id))
+}
+
+// IDLT applies the LT predicate on the ID field.
+func IDLT(id uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldID, id))
+}
+
+// IDLTE applies the LTE predicate on the ID field.
+func IDLTE(id uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldID, id))
+}
+
+// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
+func CreatedAt(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldCreatedAt, v))
+}
+
+// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
+func UpdatedAt(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldUpdatedAt, v))
+}
+
+// AuthToken applies equality check predicate on the "auth_token" field. It's identical to AuthTokenEQ.
+func AuthToken(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldAuthToken, v))
+}
+
+// EventType applies equality check predicate on the "event_type" field. It's identical to EventTypeEQ.
+func EventType(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldEventType, v))
+}
+
+// ChatID applies equality check predicate on the "chat_id" field. It's identical to ChatIDEQ.
+func ChatID(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldChatID, v))
+}
+
+// OrganizationID applies equality check predicate on the "organization_id" field. It's identical to OrganizationIDEQ.
+func OrganizationID(v uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldOrganizationID, v))
+}
+
+// OpenaiBase applies equality check predicate on the "openai_base" field. It's identical to OpenaiBaseEQ.
+func OpenaiBase(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldOpenaiBase, v))
+}
+
+// OpenaiKey applies equality check predicate on the "openai_key" field. It's identical to OpenaiKeyEQ.
+func OpenaiKey(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldOpenaiKey, v))
+}
+
+// RequestRaw applies equality check predicate on the "request_raw" field. It's identical to RequestRawEQ.
+func RequestRaw(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldRequestRaw, v))
+}
+
+// ResponseRaw applies equality check predicate on the "response_raw" field. It's identical to ResponseRawEQ.
+func ResponseRaw(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldResponseRaw, v))
+}
+
+// CallbackURL applies equality check predicate on the "callback_url" field. It's identical to CallbackURLEQ.
+func CallbackURL(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldCallbackURL, v))
+}
+
+// CallbackResponseRaw applies equality check predicate on the "callback_response_raw" field. It's identical to CallbackResponseRawEQ.
+func CallbackResponseRaw(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldCallbackResponseRaw, v))
+}
+
+// Model applies equality check predicate on the "model" field. It's identical to ModelEQ.
+func Model(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldModel, v))
+}
+
+// TaskStatus applies equality check predicate on the "task_status" field. It's identical to TaskStatusEQ.
+func TaskStatus(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldTaskStatus, v))
+}
+
+// RetryCount applies equality check predicate on the "retry_count" field. It's identical to RetryCountEQ.
+func RetryCount(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldRetryCount, v))
+}
+
+// LastError applies equality check predicate on the "last_error" field. It's identical to LastErrorEQ.
+func LastError(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldLastError, v))
+}
+
+// CreatedAtEQ applies the EQ predicate on the "created_at" field.
+func CreatedAtEQ(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldCreatedAt, v))
+}
+
+// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
+func CreatedAtNEQ(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldCreatedAt, v))
+}
+
+// CreatedAtIn applies the In predicate on the "created_at" field.
+func CreatedAtIn(vs ...time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldCreatedAt, vs...))
+}
+
+// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
+func CreatedAtNotIn(vs ...time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldCreatedAt, vs...))
+}
+
+// CreatedAtGT applies the GT predicate on the "created_at" field.
+func CreatedAtGT(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldCreatedAt, v))
+}
+
+// CreatedAtGTE applies the GTE predicate on the "created_at" field.
+func CreatedAtGTE(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldCreatedAt, v))
+}
+
+// CreatedAtLT applies the LT predicate on the "created_at" field.
+func CreatedAtLT(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldCreatedAt, v))
+}
+
+// CreatedAtLTE applies the LTE predicate on the "created_at" field.
+func CreatedAtLTE(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldCreatedAt, v))
+}
+
+// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
+func UpdatedAtEQ(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldUpdatedAt, v))
+}
+
+// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
+func UpdatedAtNEQ(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldUpdatedAt, v))
+}
+
+// UpdatedAtIn applies the In predicate on the "updated_at" field.
+func UpdatedAtIn(vs ...time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldUpdatedAt, vs...))
+}
+
+// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
+func UpdatedAtNotIn(vs ...time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldUpdatedAt, vs...))
+}
+
+// UpdatedAtGT applies the GT predicate on the "updated_at" field.
+func UpdatedAtGT(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldUpdatedAt, v))
+}
+
+// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
+func UpdatedAtGTE(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldUpdatedAt, v))
+}
+
+// UpdatedAtLT applies the LT predicate on the "updated_at" field.
+func UpdatedAtLT(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldUpdatedAt, v))
+}
+
+// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
+func UpdatedAtLTE(v time.Time) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldUpdatedAt, v))
+}
+
+// AuthTokenEQ applies the EQ predicate on the "auth_token" field.
+func AuthTokenEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldAuthToken, v))
+}
+
+// AuthTokenNEQ applies the NEQ predicate on the "auth_token" field.
+func AuthTokenNEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldAuthToken, v))
+}
+
+// AuthTokenIn applies the In predicate on the "auth_token" field.
+func AuthTokenIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldAuthToken, vs...))
+}
+
+// AuthTokenNotIn applies the NotIn predicate on the "auth_token" field.
+func AuthTokenNotIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldAuthToken, vs...))
+}
+
+// AuthTokenGT applies the GT predicate on the "auth_token" field.
+func AuthTokenGT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldAuthToken, v))
+}
+
+// AuthTokenGTE applies the GTE predicate on the "auth_token" field.
+func AuthTokenGTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldAuthToken, v))
+}
+
+// AuthTokenLT applies the LT predicate on the "auth_token" field.
+func AuthTokenLT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldAuthToken, v))
+}
+
+// AuthTokenLTE applies the LTE predicate on the "auth_token" field.
+func AuthTokenLTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldAuthToken, v))
+}
+
+// AuthTokenContains applies the Contains predicate on the "auth_token" field.
+func AuthTokenContains(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContains(FieldAuthToken, v))
+}
+
+// AuthTokenHasPrefix applies the HasPrefix predicate on the "auth_token" field.
+func AuthTokenHasPrefix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasPrefix(FieldAuthToken, v))
+}
+
+// AuthTokenHasSuffix applies the HasSuffix predicate on the "auth_token" field.
+func AuthTokenHasSuffix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasSuffix(FieldAuthToken, v))
+}
+
+// AuthTokenEqualFold applies the EqualFold predicate on the "auth_token" field.
+func AuthTokenEqualFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEqualFold(FieldAuthToken, v))
+}
+
+// AuthTokenContainsFold applies the ContainsFold predicate on the "auth_token" field.
+func AuthTokenContainsFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContainsFold(FieldAuthToken, v))
+}
+
+// EventTypeEQ applies the EQ predicate on the "event_type" field.
+func EventTypeEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldEventType, v))
+}
+
+// EventTypeNEQ applies the NEQ predicate on the "event_type" field.
+func EventTypeNEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldEventType, v))
+}
+
+// EventTypeIn applies the In predicate on the "event_type" field.
+func EventTypeIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldEventType, vs...))
+}
+
+// EventTypeNotIn applies the NotIn predicate on the "event_type" field.
+func EventTypeNotIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldEventType, vs...))
+}
+
+// EventTypeGT applies the GT predicate on the "event_type" field.
+func EventTypeGT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldEventType, v))
+}
+
+// EventTypeGTE applies the GTE predicate on the "event_type" field.
+func EventTypeGTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldEventType, v))
+}
+
+// EventTypeLT applies the LT predicate on the "event_type" field.
+func EventTypeLT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldEventType, v))
+}
+
+// EventTypeLTE applies the LTE predicate on the "event_type" field.
+func EventTypeLTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldEventType, v))
+}
+
+// EventTypeContains applies the Contains predicate on the "event_type" field.
+func EventTypeContains(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContains(FieldEventType, v))
+}
+
+// EventTypeHasPrefix applies the HasPrefix predicate on the "event_type" field.
+func EventTypeHasPrefix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasPrefix(FieldEventType, v))
+}
+
+// EventTypeHasSuffix applies the HasSuffix predicate on the "event_type" field.
+func EventTypeHasSuffix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasSuffix(FieldEventType, v))
+}
+
+// EventTypeEqualFold applies the EqualFold predicate on the "event_type" field.
+func EventTypeEqualFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEqualFold(FieldEventType, v))
+}
+
+// EventTypeContainsFold applies the ContainsFold predicate on the "event_type" field.
+func EventTypeContainsFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContainsFold(FieldEventType, v))
+}
+
+// ChatIDEQ applies the EQ predicate on the "chat_id" field.
+func ChatIDEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldChatID, v))
+}
+
+// ChatIDNEQ applies the NEQ predicate on the "chat_id" field.
+func ChatIDNEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldChatID, v))
+}
+
+// ChatIDIn applies the In predicate on the "chat_id" field.
+func ChatIDIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldChatID, vs...))
+}
+
+// ChatIDNotIn applies the NotIn predicate on the "chat_id" field.
+func ChatIDNotIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldChatID, vs...))
+}
+
+// ChatIDGT applies the GT predicate on the "chat_id" field.
+func ChatIDGT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldChatID, v))
+}
+
+// ChatIDGTE applies the GTE predicate on the "chat_id" field.
+func ChatIDGTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldChatID, v))
+}
+
+// ChatIDLT applies the LT predicate on the "chat_id" field.
+func ChatIDLT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldChatID, v))
+}
+
+// ChatIDLTE applies the LTE predicate on the "chat_id" field.
+func ChatIDLTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldChatID, v))
+}
+
+// ChatIDContains applies the Contains predicate on the "chat_id" field.
+func ChatIDContains(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContains(FieldChatID, v))
+}
+
+// ChatIDHasPrefix applies the HasPrefix predicate on the "chat_id" field.
+func ChatIDHasPrefix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasPrefix(FieldChatID, v))
+}
+
+// ChatIDHasSuffix applies the HasSuffix predicate on the "chat_id" field.
+func ChatIDHasSuffix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasSuffix(FieldChatID, v))
+}
+
+// ChatIDIsNil applies the IsNil predicate on the "chat_id" field.
+func ChatIDIsNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIsNull(FieldChatID))
+}
+
+// ChatIDNotNil applies the NotNil predicate on the "chat_id" field.
+func ChatIDNotNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotNull(FieldChatID))
+}
+
+// ChatIDEqualFold applies the EqualFold predicate on the "chat_id" field.
+func ChatIDEqualFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEqualFold(FieldChatID, v))
+}
+
+// ChatIDContainsFold applies the ContainsFold predicate on the "chat_id" field.
+func ChatIDContainsFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContainsFold(FieldChatID, v))
+}
+
+// OrganizationIDEQ applies the EQ predicate on the "organization_id" field.
+func OrganizationIDEQ(v uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDNEQ applies the NEQ predicate on the "organization_id" field.
+func OrganizationIDNEQ(v uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldOrganizationID, v))
+}
+
+// OrganizationIDIn applies the In predicate on the "organization_id" field.
+func OrganizationIDIn(vs ...uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDNotIn applies the NotIn predicate on the "organization_id" field.
+func OrganizationIDNotIn(vs ...uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldOrganizationID, vs...))
+}
+
+// OrganizationIDGT applies the GT predicate on the "organization_id" field.
+func OrganizationIDGT(v uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldOrganizationID, v))
+}
+
+// OrganizationIDGTE applies the GTE predicate on the "organization_id" field.
+func OrganizationIDGTE(v uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldOrganizationID, v))
+}
+
+// OrganizationIDLT applies the LT predicate on the "organization_id" field.
+func OrganizationIDLT(v uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldOrganizationID, v))
+}
+
+// OrganizationIDLTE applies the LTE predicate on the "organization_id" field.
+func OrganizationIDLTE(v uint64) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldOrganizationID, v))
+}
+
+// OpenaiBaseEQ applies the EQ predicate on the "openai_base" field.
+func OpenaiBaseEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldOpenaiBase, v))
+}
+
+// OpenaiBaseNEQ applies the NEQ predicate on the "openai_base" field.
+func OpenaiBaseNEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldOpenaiBase, v))
+}
+
+// OpenaiBaseIn applies the In predicate on the "openai_base" field.
+func OpenaiBaseIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldOpenaiBase, vs...))
+}
+
+// OpenaiBaseNotIn applies the NotIn predicate on the "openai_base" field.
+func OpenaiBaseNotIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldOpenaiBase, vs...))
+}
+
+// OpenaiBaseGT applies the GT predicate on the "openai_base" field.
+func OpenaiBaseGT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldOpenaiBase, v))
+}
+
+// OpenaiBaseGTE applies the GTE predicate on the "openai_base" field.
+func OpenaiBaseGTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldOpenaiBase, v))
+}
+
+// OpenaiBaseLT applies the LT predicate on the "openai_base" field.
+func OpenaiBaseLT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldOpenaiBase, v))
+}
+
+// OpenaiBaseLTE applies the LTE predicate on the "openai_base" field.
+func OpenaiBaseLTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldOpenaiBase, v))
+}
+
+// OpenaiBaseContains applies the Contains predicate on the "openai_base" field.
+func OpenaiBaseContains(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContains(FieldOpenaiBase, v))
+}
+
+// OpenaiBaseHasPrefix applies the HasPrefix predicate on the "openai_base" field.
+func OpenaiBaseHasPrefix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasPrefix(FieldOpenaiBase, v))
+}
+
+// OpenaiBaseHasSuffix applies the HasSuffix predicate on the "openai_base" field.
+func OpenaiBaseHasSuffix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasSuffix(FieldOpenaiBase, v))
+}
+
+// OpenaiBaseEqualFold applies the EqualFold predicate on the "openai_base" field.
+func OpenaiBaseEqualFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEqualFold(FieldOpenaiBase, v))
+}
+
+// OpenaiBaseContainsFold applies the ContainsFold predicate on the "openai_base" field.
+func OpenaiBaseContainsFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContainsFold(FieldOpenaiBase, v))
+}
+
+// OpenaiKeyEQ applies the EQ predicate on the "openai_key" field.
+func OpenaiKeyEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldOpenaiKey, v))
+}
+
+// OpenaiKeyNEQ applies the NEQ predicate on the "openai_key" field.
+func OpenaiKeyNEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldOpenaiKey, v))
+}
+
+// OpenaiKeyIn applies the In predicate on the "openai_key" field.
+func OpenaiKeyIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldOpenaiKey, vs...))
+}
+
+// OpenaiKeyNotIn applies the NotIn predicate on the "openai_key" field.
+func OpenaiKeyNotIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldOpenaiKey, vs...))
+}
+
+// OpenaiKeyGT applies the GT predicate on the "openai_key" field.
+func OpenaiKeyGT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldOpenaiKey, v))
+}
+
+// OpenaiKeyGTE applies the GTE predicate on the "openai_key" field.
+func OpenaiKeyGTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldOpenaiKey, v))
+}
+
+// OpenaiKeyLT applies the LT predicate on the "openai_key" field.
+func OpenaiKeyLT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldOpenaiKey, v))
+}
+
+// OpenaiKeyLTE applies the LTE predicate on the "openai_key" field.
+func OpenaiKeyLTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldOpenaiKey, v))
+}
+
+// OpenaiKeyContains applies the Contains predicate on the "openai_key" field.
+func OpenaiKeyContains(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContains(FieldOpenaiKey, v))
+}
+
+// OpenaiKeyHasPrefix applies the HasPrefix predicate on the "openai_key" field.
+func OpenaiKeyHasPrefix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasPrefix(FieldOpenaiKey, v))
+}
+
+// OpenaiKeyHasSuffix applies the HasSuffix predicate on the "openai_key" field.
+func OpenaiKeyHasSuffix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasSuffix(FieldOpenaiKey, v))
+}
+
+// OpenaiKeyEqualFold applies the EqualFold predicate on the "openai_key" field.
+func OpenaiKeyEqualFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEqualFold(FieldOpenaiKey, v))
+}
+
+// OpenaiKeyContainsFold applies the ContainsFold predicate on the "openai_key" field.
+func OpenaiKeyContainsFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContainsFold(FieldOpenaiKey, v))
+}
+
+// RequestRawEQ applies the EQ predicate on the "request_raw" field.
+func RequestRawEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldRequestRaw, v))
+}
+
+// RequestRawNEQ applies the NEQ predicate on the "request_raw" field.
+func RequestRawNEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldRequestRaw, v))
+}
+
+// RequestRawIn applies the In predicate on the "request_raw" field.
+func RequestRawIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldRequestRaw, vs...))
+}
+
+// RequestRawNotIn applies the NotIn predicate on the "request_raw" field.
+func RequestRawNotIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldRequestRaw, vs...))
+}
+
+// RequestRawGT applies the GT predicate on the "request_raw" field.
+func RequestRawGT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldRequestRaw, v))
+}
+
+// RequestRawGTE applies the GTE predicate on the "request_raw" field.
+func RequestRawGTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldRequestRaw, v))
+}
+
+// RequestRawLT applies the LT predicate on the "request_raw" field.
+func RequestRawLT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldRequestRaw, v))
+}
+
+// RequestRawLTE applies the LTE predicate on the "request_raw" field.
+func RequestRawLTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldRequestRaw, v))
+}
+
+// RequestRawContains applies the Contains predicate on the "request_raw" field.
+func RequestRawContains(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContains(FieldRequestRaw, v))
+}
+
+// RequestRawHasPrefix applies the HasPrefix predicate on the "request_raw" field.
+func RequestRawHasPrefix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasPrefix(FieldRequestRaw, v))
+}
+
+// RequestRawHasSuffix applies the HasSuffix predicate on the "request_raw" field.
+func RequestRawHasSuffix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasSuffix(FieldRequestRaw, v))
+}
+
+// RequestRawEqualFold applies the EqualFold predicate on the "request_raw" field.
+func RequestRawEqualFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEqualFold(FieldRequestRaw, v))
+}
+
+// RequestRawContainsFold applies the ContainsFold predicate on the "request_raw" field.
+func RequestRawContainsFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContainsFold(FieldRequestRaw, v))
+}
+
+// ResponseRawEQ applies the EQ predicate on the "response_raw" field.
+func ResponseRawEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldResponseRaw, v))
+}
+
+// ResponseRawNEQ applies the NEQ predicate on the "response_raw" field.
+func ResponseRawNEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldResponseRaw, v))
+}
+
+// ResponseRawIn applies the In predicate on the "response_raw" field.
+func ResponseRawIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldResponseRaw, vs...))
+}
+
+// ResponseRawNotIn applies the NotIn predicate on the "response_raw" field.
+func ResponseRawNotIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldResponseRaw, vs...))
+}
+
+// ResponseRawGT applies the GT predicate on the "response_raw" field.
+func ResponseRawGT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldResponseRaw, v))
+}
+
+// ResponseRawGTE applies the GTE predicate on the "response_raw" field.
+func ResponseRawGTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldResponseRaw, v))
+}
+
+// ResponseRawLT applies the LT predicate on the "response_raw" field.
+func ResponseRawLT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldResponseRaw, v))
+}
+
+// ResponseRawLTE applies the LTE predicate on the "response_raw" field.
+func ResponseRawLTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldResponseRaw, v))
+}
+
+// ResponseRawContains applies the Contains predicate on the "response_raw" field.
+func ResponseRawContains(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContains(FieldResponseRaw, v))
+}
+
+// ResponseRawHasPrefix applies the HasPrefix predicate on the "response_raw" field.
+func ResponseRawHasPrefix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasPrefix(FieldResponseRaw, v))
+}
+
+// ResponseRawHasSuffix applies the HasSuffix predicate on the "response_raw" field.
+func ResponseRawHasSuffix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasSuffix(FieldResponseRaw, v))
+}
+
+// ResponseRawIsNil applies the IsNil predicate on the "response_raw" field.
+func ResponseRawIsNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIsNull(FieldResponseRaw))
+}
+
+// ResponseRawNotNil applies the NotNil predicate on the "response_raw" field.
+func ResponseRawNotNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotNull(FieldResponseRaw))
+}
+
+// ResponseRawEqualFold applies the EqualFold predicate on the "response_raw" field.
+func ResponseRawEqualFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEqualFold(FieldResponseRaw, v))
+}
+
+// ResponseRawContainsFold applies the ContainsFold predicate on the "response_raw" field.
+func ResponseRawContainsFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContainsFold(FieldResponseRaw, v))
+}
+
+// CallbackURLEQ applies the EQ predicate on the "callback_url" field.
+func CallbackURLEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldCallbackURL, v))
+}
+
+// CallbackURLNEQ applies the NEQ predicate on the "callback_url" field.
+func CallbackURLNEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldCallbackURL, v))
+}
+
+// CallbackURLIn applies the In predicate on the "callback_url" field.
+func CallbackURLIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldCallbackURL, vs...))
+}
+
+// CallbackURLNotIn applies the NotIn predicate on the "callback_url" field.
+func CallbackURLNotIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldCallbackURL, vs...))
+}
+
+// CallbackURLGT applies the GT predicate on the "callback_url" field.
+func CallbackURLGT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldCallbackURL, v))
+}
+
+// CallbackURLGTE applies the GTE predicate on the "callback_url" field.
+func CallbackURLGTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldCallbackURL, v))
+}
+
+// CallbackURLLT applies the LT predicate on the "callback_url" field.
+func CallbackURLLT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldCallbackURL, v))
+}
+
+// CallbackURLLTE applies the LTE predicate on the "callback_url" field.
+func CallbackURLLTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldCallbackURL, v))
+}
+
+// CallbackURLContains applies the Contains predicate on the "callback_url" field.
+func CallbackURLContains(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContains(FieldCallbackURL, v))
+}
+
+// CallbackURLHasPrefix applies the HasPrefix predicate on the "callback_url" field.
+func CallbackURLHasPrefix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasPrefix(FieldCallbackURL, v))
+}
+
+// CallbackURLHasSuffix applies the HasSuffix predicate on the "callback_url" field.
+func CallbackURLHasSuffix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasSuffix(FieldCallbackURL, v))
+}
+
+// CallbackURLEqualFold applies the EqualFold predicate on the "callback_url" field.
+func CallbackURLEqualFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEqualFold(FieldCallbackURL, v))
+}
+
+// CallbackURLContainsFold applies the ContainsFold predicate on the "callback_url" field.
+func CallbackURLContainsFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContainsFold(FieldCallbackURL, v))
+}
+
+// CallbackResponseRawEQ applies the EQ predicate on the "callback_response_raw" field.
+func CallbackResponseRawEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldCallbackResponseRaw, v))
+}
+
+// CallbackResponseRawNEQ applies the NEQ predicate on the "callback_response_raw" field.
+func CallbackResponseRawNEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldCallbackResponseRaw, v))
+}
+
+// CallbackResponseRawIn applies the In predicate on the "callback_response_raw" field.
+func CallbackResponseRawIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldCallbackResponseRaw, vs...))
+}
+
+// CallbackResponseRawNotIn applies the NotIn predicate on the "callback_response_raw" field.
+func CallbackResponseRawNotIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldCallbackResponseRaw, vs...))
+}
+
+// CallbackResponseRawGT applies the GT predicate on the "callback_response_raw" field.
+func CallbackResponseRawGT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldCallbackResponseRaw, v))
+}
+
+// CallbackResponseRawGTE applies the GTE predicate on the "callback_response_raw" field.
+func CallbackResponseRawGTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldCallbackResponseRaw, v))
+}
+
+// CallbackResponseRawLT applies the LT predicate on the "callback_response_raw" field.
+func CallbackResponseRawLT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldCallbackResponseRaw, v))
+}
+
+// CallbackResponseRawLTE applies the LTE predicate on the "callback_response_raw" field.
+func CallbackResponseRawLTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldCallbackResponseRaw, v))
+}
+
+// CallbackResponseRawContains applies the Contains predicate on the "callback_response_raw" field.
+func CallbackResponseRawContains(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContains(FieldCallbackResponseRaw, v))
+}
+
+// CallbackResponseRawHasPrefix applies the HasPrefix predicate on the "callback_response_raw" field.
+func CallbackResponseRawHasPrefix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasPrefix(FieldCallbackResponseRaw, v))
+}
+
+// CallbackResponseRawHasSuffix applies the HasSuffix predicate on the "callback_response_raw" field.
+func CallbackResponseRawHasSuffix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasSuffix(FieldCallbackResponseRaw, v))
+}
+
+// CallbackResponseRawIsNil applies the IsNil predicate on the "callback_response_raw" field.
+func CallbackResponseRawIsNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIsNull(FieldCallbackResponseRaw))
+}
+
+// CallbackResponseRawNotNil applies the NotNil predicate on the "callback_response_raw" field.
+func CallbackResponseRawNotNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotNull(FieldCallbackResponseRaw))
+}
+
+// CallbackResponseRawEqualFold applies the EqualFold predicate on the "callback_response_raw" field.
+func CallbackResponseRawEqualFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEqualFold(FieldCallbackResponseRaw, v))
+}
+
+// CallbackResponseRawContainsFold applies the ContainsFold predicate on the "callback_response_raw" field.
+func CallbackResponseRawContainsFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContainsFold(FieldCallbackResponseRaw, v))
+}
+
+// ModelEQ applies the EQ predicate on the "model" field.
+func ModelEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldModel, v))
+}
+
+// ModelNEQ applies the NEQ predicate on the "model" field.
+func ModelNEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldModel, v))
+}
+
+// ModelIn applies the In predicate on the "model" field.
+func ModelIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldModel, vs...))
+}
+
+// ModelNotIn applies the NotIn predicate on the "model" field.
+func ModelNotIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldModel, vs...))
+}
+
+// ModelGT applies the GT predicate on the "model" field.
+func ModelGT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldModel, v))
+}
+
+// ModelGTE applies the GTE predicate on the "model" field.
+func ModelGTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldModel, v))
+}
+
+// ModelLT applies the LT predicate on the "model" field.
+func ModelLT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldModel, v))
+}
+
+// ModelLTE applies the LTE predicate on the "model" field.
+func ModelLTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldModel, v))
+}
+
+// ModelContains applies the Contains predicate on the "model" field.
+func ModelContains(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContains(FieldModel, v))
+}
+
+// ModelHasPrefix applies the HasPrefix predicate on the "model" field.
+func ModelHasPrefix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasPrefix(FieldModel, v))
+}
+
+// ModelHasSuffix applies the HasSuffix predicate on the "model" field.
+func ModelHasSuffix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasSuffix(FieldModel, v))
+}
+
+// ModelIsNil applies the IsNil predicate on the "model" field.
+func ModelIsNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIsNull(FieldModel))
+}
+
+// ModelNotNil applies the NotNil predicate on the "model" field.
+func ModelNotNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotNull(FieldModel))
+}
+
+// ModelEqualFold applies the EqualFold predicate on the "model" field.
+func ModelEqualFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEqualFold(FieldModel, v))
+}
+
+// ModelContainsFold applies the ContainsFold predicate on the "model" field.
+func ModelContainsFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContainsFold(FieldModel, v))
+}
+
+// TaskStatusEQ applies the EQ predicate on the "task_status" field.
+func TaskStatusEQ(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldTaskStatus, v))
+}
+
+// TaskStatusNEQ applies the NEQ predicate on the "task_status" field.
+func TaskStatusNEQ(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldTaskStatus, v))
+}
+
+// TaskStatusIn applies the In predicate on the "task_status" field.
+func TaskStatusIn(vs ...int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldTaskStatus, vs...))
+}
+
+// TaskStatusNotIn applies the NotIn predicate on the "task_status" field.
+func TaskStatusNotIn(vs ...int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldTaskStatus, vs...))
+}
+
+// TaskStatusGT applies the GT predicate on the "task_status" field.
+func TaskStatusGT(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldTaskStatus, v))
+}
+
+// TaskStatusGTE applies the GTE predicate on the "task_status" field.
+func TaskStatusGTE(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldTaskStatus, v))
+}
+
+// TaskStatusLT applies the LT predicate on the "task_status" field.
+func TaskStatusLT(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldTaskStatus, v))
+}
+
+// TaskStatusLTE applies the LTE predicate on the "task_status" field.
+func TaskStatusLTE(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldTaskStatus, v))
+}
+
+// TaskStatusIsNil applies the IsNil predicate on the "task_status" field.
+func TaskStatusIsNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIsNull(FieldTaskStatus))
+}
+
+// TaskStatusNotNil applies the NotNil predicate on the "task_status" field.
+func TaskStatusNotNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotNull(FieldTaskStatus))
+}
+
+// RetryCountEQ applies the EQ predicate on the "retry_count" field.
+func RetryCountEQ(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldRetryCount, v))
+}
+
+// RetryCountNEQ applies the NEQ predicate on the "retry_count" field.
+func RetryCountNEQ(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldRetryCount, v))
+}
+
+// RetryCountIn applies the In predicate on the "retry_count" field.
+func RetryCountIn(vs ...int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldRetryCount, vs...))
+}
+
+// RetryCountNotIn applies the NotIn predicate on the "retry_count" field.
+func RetryCountNotIn(vs ...int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldRetryCount, vs...))
+}
+
+// RetryCountGT applies the GT predicate on the "retry_count" field.
+func RetryCountGT(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldRetryCount, v))
+}
+
+// RetryCountGTE applies the GTE predicate on the "retry_count" field.
+func RetryCountGTE(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldRetryCount, v))
+}
+
+// RetryCountLT applies the LT predicate on the "retry_count" field.
+func RetryCountLT(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldRetryCount, v))
+}
+
+// RetryCountLTE applies the LTE predicate on the "retry_count" field.
+func RetryCountLTE(v int8) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldRetryCount, v))
+}
+
+// RetryCountIsNil applies the IsNil predicate on the "retry_count" field.
+func RetryCountIsNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIsNull(FieldRetryCount))
+}
+
+// RetryCountNotNil applies the NotNil predicate on the "retry_count" field.
+func RetryCountNotNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotNull(FieldRetryCount))
+}
+
+// LastErrorEQ applies the EQ predicate on the "last_error" field.
+func LastErrorEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEQ(FieldLastError, v))
+}
+
+// LastErrorNEQ applies the NEQ predicate on the "last_error" field.
+func LastErrorNEQ(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNEQ(FieldLastError, v))
+}
+
+// LastErrorIn applies the In predicate on the "last_error" field.
+func LastErrorIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIn(FieldLastError, vs...))
+}
+
+// LastErrorNotIn applies the NotIn predicate on the "last_error" field.
+func LastErrorNotIn(vs ...string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotIn(FieldLastError, vs...))
+}
+
+// LastErrorGT applies the GT predicate on the "last_error" field.
+func LastErrorGT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGT(FieldLastError, v))
+}
+
+// LastErrorGTE applies the GTE predicate on the "last_error" field.
+func LastErrorGTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldGTE(FieldLastError, v))
+}
+
+// LastErrorLT applies the LT predicate on the "last_error" field.
+func LastErrorLT(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLT(FieldLastError, v))
+}
+
+// LastErrorLTE applies the LTE predicate on the "last_error" field.
+func LastErrorLTE(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldLTE(FieldLastError, v))
+}
+
+// LastErrorContains applies the Contains predicate on the "last_error" field.
+func LastErrorContains(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContains(FieldLastError, v))
+}
+
+// LastErrorHasPrefix applies the HasPrefix predicate on the "last_error" field.
+func LastErrorHasPrefix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasPrefix(FieldLastError, v))
+}
+
+// LastErrorHasSuffix applies the HasSuffix predicate on the "last_error" field.
+func LastErrorHasSuffix(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldHasSuffix(FieldLastError, v))
+}
+
+// LastErrorIsNil applies the IsNil predicate on the "last_error" field.
+func LastErrorIsNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldIsNull(FieldLastError))
+}
+
+// LastErrorNotNil applies the NotNil predicate on the "last_error" field.
+func LastErrorNotNil() predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldNotNull(FieldLastError))
+}
+
+// LastErrorEqualFold applies the EqualFold predicate on the "last_error" field.
+func LastErrorEqualFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldEqualFold(FieldLastError, v))
+}
+
+// LastErrorContainsFold applies the ContainsFold predicate on the "last_error" field.
+func LastErrorContainsFold(v string) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.FieldContainsFold(FieldLastError, v))
+}
+
+// And groups predicates with the AND operator between them.
+func And(predicates ...predicate.CompapiAsynctask) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.AndPredicates(predicates...))
+}
+
+// Or groups predicates with the OR operator between them.
+func Or(predicates ...predicate.CompapiAsynctask) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.OrPredicates(predicates...))
+}
+
+// Not applies the not operator on the given predicate.
+func Not(p predicate.CompapiAsynctask) predicate.CompapiAsynctask {
+	return predicate.CompapiAsynctask(sql.NotPredicates(p))
+}

+ 1561 - 0
ent/compapiasynctask_create.go

@@ -0,0 +1,1561 @@
+// Code generated by ent, DO NOT EDIT.
+
+package ent
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"time"
+	"wechat-api/ent/compapiasynctask"
+
+	"entgo.io/ent/dialect/sql"
+	"entgo.io/ent/dialect/sql/sqlgraph"
+	"entgo.io/ent/schema/field"
+)
+
+// CompapiAsynctaskCreate is the builder for creating a CompapiAsynctask entity.
+type CompapiAsynctaskCreate struct {
+	config
+	mutation *CompapiAsynctaskMutation
+	hooks    []Hook
+	conflict []sql.ConflictOption
+}
+
+// SetCreatedAt sets the "created_at" field.
+func (cac *CompapiAsynctaskCreate) SetCreatedAt(t time.Time) *CompapiAsynctaskCreate {
+	cac.mutation.SetCreatedAt(t)
+	return cac
+}
+
+// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
+func (cac *CompapiAsynctaskCreate) SetNillableCreatedAt(t *time.Time) *CompapiAsynctaskCreate {
+	if t != nil {
+		cac.SetCreatedAt(*t)
+	}
+	return cac
+}
+
+// SetUpdatedAt sets the "updated_at" field.
+func (cac *CompapiAsynctaskCreate) SetUpdatedAt(t time.Time) *CompapiAsynctaskCreate {
+	cac.mutation.SetUpdatedAt(t)
+	return cac
+}
+
+// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
+func (cac *CompapiAsynctaskCreate) SetNillableUpdatedAt(t *time.Time) *CompapiAsynctaskCreate {
+	if t != nil {
+		cac.SetUpdatedAt(*t)
+	}
+	return cac
+}
+
+// SetAuthToken sets the "auth_token" field.
+func (cac *CompapiAsynctaskCreate) SetAuthToken(s string) *CompapiAsynctaskCreate {
+	cac.mutation.SetAuthToken(s)
+	return cac
+}
+
+// SetEventType sets the "event_type" field.
+func (cac *CompapiAsynctaskCreate) SetEventType(s string) *CompapiAsynctaskCreate {
+	cac.mutation.SetEventType(s)
+	return cac
+}
+
+// SetNillableEventType sets the "event_type" field if the given value is not nil.
+func (cac *CompapiAsynctaskCreate) SetNillableEventType(s *string) *CompapiAsynctaskCreate {
+	if s != nil {
+		cac.SetEventType(*s)
+	}
+	return cac
+}
+
+// SetChatID sets the "chat_id" field.
+func (cac *CompapiAsynctaskCreate) SetChatID(s string) *CompapiAsynctaskCreate {
+	cac.mutation.SetChatID(s)
+	return cac
+}
+
+// SetNillableChatID sets the "chat_id" field if the given value is not nil.
+func (cac *CompapiAsynctaskCreate) SetNillableChatID(s *string) *CompapiAsynctaskCreate {
+	if s != nil {
+		cac.SetChatID(*s)
+	}
+	return cac
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (cac *CompapiAsynctaskCreate) SetOrganizationID(u uint64) *CompapiAsynctaskCreate {
+	cac.mutation.SetOrganizationID(u)
+	return cac
+}
+
+// SetOpenaiBase sets the "openai_base" field.
+func (cac *CompapiAsynctaskCreate) SetOpenaiBase(s string) *CompapiAsynctaskCreate {
+	cac.mutation.SetOpenaiBase(s)
+	return cac
+}
+
+// SetOpenaiKey sets the "openai_key" field.
+func (cac *CompapiAsynctaskCreate) SetOpenaiKey(s string) *CompapiAsynctaskCreate {
+	cac.mutation.SetOpenaiKey(s)
+	return cac
+}
+
+// SetRequestRaw sets the "request_raw" field.
+func (cac *CompapiAsynctaskCreate) SetRequestRaw(s string) *CompapiAsynctaskCreate {
+	cac.mutation.SetRequestRaw(s)
+	return cac
+}
+
+// SetResponseRaw sets the "response_raw" field.
+func (cac *CompapiAsynctaskCreate) SetResponseRaw(s string) *CompapiAsynctaskCreate {
+	cac.mutation.SetResponseRaw(s)
+	return cac
+}
+
+// SetNillableResponseRaw sets the "response_raw" field if the given value is not nil.
+func (cac *CompapiAsynctaskCreate) SetNillableResponseRaw(s *string) *CompapiAsynctaskCreate {
+	if s != nil {
+		cac.SetResponseRaw(*s)
+	}
+	return cac
+}
+
+// SetCallbackURL sets the "callback_url" field.
+func (cac *CompapiAsynctaskCreate) SetCallbackURL(s string) *CompapiAsynctaskCreate {
+	cac.mutation.SetCallbackURL(s)
+	return cac
+}
+
+// SetCallbackResponseRaw sets the "callback_response_raw" field.
+func (cac *CompapiAsynctaskCreate) SetCallbackResponseRaw(s string) *CompapiAsynctaskCreate {
+	cac.mutation.SetCallbackResponseRaw(s)
+	return cac
+}
+
+// SetNillableCallbackResponseRaw sets the "callback_response_raw" field if the given value is not nil.
+func (cac *CompapiAsynctaskCreate) SetNillableCallbackResponseRaw(s *string) *CompapiAsynctaskCreate {
+	if s != nil {
+		cac.SetCallbackResponseRaw(*s)
+	}
+	return cac
+}
+
+// SetModel sets the "model" field.
+func (cac *CompapiAsynctaskCreate) SetModel(s string) *CompapiAsynctaskCreate {
+	cac.mutation.SetModel(s)
+	return cac
+}
+
+// SetNillableModel sets the "model" field if the given value is not nil.
+func (cac *CompapiAsynctaskCreate) SetNillableModel(s *string) *CompapiAsynctaskCreate {
+	if s != nil {
+		cac.SetModel(*s)
+	}
+	return cac
+}
+
+// SetTaskStatus sets the "task_status" field.
+func (cac *CompapiAsynctaskCreate) SetTaskStatus(i int8) *CompapiAsynctaskCreate {
+	cac.mutation.SetTaskStatus(i)
+	return cac
+}
+
+// SetNillableTaskStatus sets the "task_status" field if the given value is not nil.
+func (cac *CompapiAsynctaskCreate) SetNillableTaskStatus(i *int8) *CompapiAsynctaskCreate {
+	if i != nil {
+		cac.SetTaskStatus(*i)
+	}
+	return cac
+}
+
+// SetRetryCount sets the "retry_count" field.
+func (cac *CompapiAsynctaskCreate) SetRetryCount(i int8) *CompapiAsynctaskCreate {
+	cac.mutation.SetRetryCount(i)
+	return cac
+}
+
+// SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
+func (cac *CompapiAsynctaskCreate) SetNillableRetryCount(i *int8) *CompapiAsynctaskCreate {
+	if i != nil {
+		cac.SetRetryCount(*i)
+	}
+	return cac
+}
+
+// SetLastError sets the "last_error" field.
+func (cac *CompapiAsynctaskCreate) SetLastError(s string) *CompapiAsynctaskCreate {
+	cac.mutation.SetLastError(s)
+	return cac
+}
+
+// SetNillableLastError sets the "last_error" field if the given value is not nil.
+func (cac *CompapiAsynctaskCreate) SetNillableLastError(s *string) *CompapiAsynctaskCreate {
+	if s != nil {
+		cac.SetLastError(*s)
+	}
+	return cac
+}
+
+// SetID sets the "id" field.
+func (cac *CompapiAsynctaskCreate) SetID(u uint64) *CompapiAsynctaskCreate {
+	cac.mutation.SetID(u)
+	return cac
+}
+
+// Mutation returns the CompapiAsynctaskMutation object of the builder.
+func (cac *CompapiAsynctaskCreate) Mutation() *CompapiAsynctaskMutation {
+	return cac.mutation
+}
+
+// Save creates the CompapiAsynctask in the database.
+func (cac *CompapiAsynctaskCreate) Save(ctx context.Context) (*CompapiAsynctask, error) {
+	cac.defaults()
+	return withHooks(ctx, cac.sqlSave, cac.mutation, cac.hooks)
+}
+
+// SaveX calls Save and panics if Save returns an error.
+func (cac *CompapiAsynctaskCreate) SaveX(ctx context.Context) *CompapiAsynctask {
+	v, err := cac.Save(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return v
+}
+
+// Exec executes the query.
+func (cac *CompapiAsynctaskCreate) Exec(ctx context.Context) error {
+	_, err := cac.Save(ctx)
+	return err
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (cac *CompapiAsynctaskCreate) ExecX(ctx context.Context) {
+	if err := cac.Exec(ctx); err != nil {
+		panic(err)
+	}
+}
+
+// defaults sets the default values of the builder before save.
+func (cac *CompapiAsynctaskCreate) defaults() {
+	if _, ok := cac.mutation.CreatedAt(); !ok {
+		v := compapiasynctask.DefaultCreatedAt()
+		cac.mutation.SetCreatedAt(v)
+	}
+	if _, ok := cac.mutation.UpdatedAt(); !ok {
+		v := compapiasynctask.DefaultUpdatedAt()
+		cac.mutation.SetUpdatedAt(v)
+	}
+	if _, ok := cac.mutation.EventType(); !ok {
+		v := compapiasynctask.DefaultEventType
+		cac.mutation.SetEventType(v)
+	}
+	if _, ok := cac.mutation.ChatID(); !ok {
+		v := compapiasynctask.DefaultChatID
+		cac.mutation.SetChatID(v)
+	}
+	if _, ok := cac.mutation.ResponseRaw(); !ok {
+		v := compapiasynctask.DefaultResponseRaw
+		cac.mutation.SetResponseRaw(v)
+	}
+	if _, ok := cac.mutation.CallbackResponseRaw(); !ok {
+		v := compapiasynctask.DefaultCallbackResponseRaw
+		cac.mutation.SetCallbackResponseRaw(v)
+	}
+	if _, ok := cac.mutation.Model(); !ok {
+		v := compapiasynctask.DefaultModel
+		cac.mutation.SetModel(v)
+	}
+	if _, ok := cac.mutation.TaskStatus(); !ok {
+		v := compapiasynctask.DefaultTaskStatus
+		cac.mutation.SetTaskStatus(v)
+	}
+	if _, ok := cac.mutation.RetryCount(); !ok {
+		v := compapiasynctask.DefaultRetryCount
+		cac.mutation.SetRetryCount(v)
+	}
+	if _, ok := cac.mutation.LastError(); !ok {
+		v := compapiasynctask.DefaultLastError
+		cac.mutation.SetLastError(v)
+	}
+}
+
+// check runs all checks and user-defined validators on the builder.
+func (cac *CompapiAsynctaskCreate) check() error {
+	if _, ok := cac.mutation.CreatedAt(); !ok {
+		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "CompapiAsynctask.created_at"`)}
+	}
+	if _, ok := cac.mutation.UpdatedAt(); !ok {
+		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "CompapiAsynctask.updated_at"`)}
+	}
+	if _, ok := cac.mutation.AuthToken(); !ok {
+		return &ValidationError{Name: "auth_token", err: errors.New(`ent: missing required field "CompapiAsynctask.auth_token"`)}
+	}
+	if _, ok := cac.mutation.EventType(); !ok {
+		return &ValidationError{Name: "event_type", err: errors.New(`ent: missing required field "CompapiAsynctask.event_type"`)}
+	}
+	if _, ok := cac.mutation.OrganizationID(); !ok {
+		return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "CompapiAsynctask.organization_id"`)}
+	}
+	if v, ok := cac.mutation.OrganizationID(); ok {
+		if err := compapiasynctask.OrganizationIDValidator(v); err != nil {
+			return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.organization_id": %w`, err)}
+		}
+	}
+	if _, ok := cac.mutation.OpenaiBase(); !ok {
+		return &ValidationError{Name: "openai_base", err: errors.New(`ent: missing required field "CompapiAsynctask.openai_base"`)}
+	}
+	if _, ok := cac.mutation.OpenaiKey(); !ok {
+		return &ValidationError{Name: "openai_key", err: errors.New(`ent: missing required field "CompapiAsynctask.openai_key"`)}
+	}
+	if _, ok := cac.mutation.RequestRaw(); !ok {
+		return &ValidationError{Name: "request_raw", err: errors.New(`ent: missing required field "CompapiAsynctask.request_raw"`)}
+	}
+	if _, ok := cac.mutation.CallbackURL(); !ok {
+		return &ValidationError{Name: "callback_url", err: errors.New(`ent: missing required field "CompapiAsynctask.callback_url"`)}
+	}
+	if v, ok := cac.mutation.CallbackURL(); ok {
+		if err := compapiasynctask.CallbackURLValidator(v); err != nil {
+			return &ValidationError{Name: "callback_url", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.callback_url": %w`, err)}
+		}
+	}
+	return nil
+}
+
+func (cac *CompapiAsynctaskCreate) sqlSave(ctx context.Context) (*CompapiAsynctask, error) {
+	if err := cac.check(); err != nil {
+		return nil, err
+	}
+	_node, _spec := cac.createSpec()
+	if err := sqlgraph.CreateNode(ctx, cac.driver, _spec); err != nil {
+		if sqlgraph.IsConstraintError(err) {
+			err = &ConstraintError{msg: err.Error(), wrap: err}
+		}
+		return nil, err
+	}
+	if _spec.ID.Value != _node.ID {
+		id := _spec.ID.Value.(int64)
+		_node.ID = uint64(id)
+	}
+	cac.mutation.id = &_node.ID
+	cac.mutation.done = true
+	return _node, nil
+}
+
+func (cac *CompapiAsynctaskCreate) createSpec() (*CompapiAsynctask, *sqlgraph.CreateSpec) {
+	var (
+		_node = &CompapiAsynctask{config: cac.config}
+		_spec = sqlgraph.NewCreateSpec(compapiasynctask.Table, sqlgraph.NewFieldSpec(compapiasynctask.FieldID, field.TypeUint64))
+	)
+	_spec.OnConflict = cac.conflict
+	if id, ok := cac.mutation.ID(); ok {
+		_node.ID = id
+		_spec.ID.Value = id
+	}
+	if value, ok := cac.mutation.CreatedAt(); ok {
+		_spec.SetField(compapiasynctask.FieldCreatedAt, field.TypeTime, value)
+		_node.CreatedAt = value
+	}
+	if value, ok := cac.mutation.UpdatedAt(); ok {
+		_spec.SetField(compapiasynctask.FieldUpdatedAt, field.TypeTime, value)
+		_node.UpdatedAt = value
+	}
+	if value, ok := cac.mutation.AuthToken(); ok {
+		_spec.SetField(compapiasynctask.FieldAuthToken, field.TypeString, value)
+		_node.AuthToken = value
+	}
+	if value, ok := cac.mutation.EventType(); ok {
+		_spec.SetField(compapiasynctask.FieldEventType, field.TypeString, value)
+		_node.EventType = value
+	}
+	if value, ok := cac.mutation.ChatID(); ok {
+		_spec.SetField(compapiasynctask.FieldChatID, field.TypeString, value)
+		_node.ChatID = value
+	}
+	if value, ok := cac.mutation.OrganizationID(); ok {
+		_spec.SetField(compapiasynctask.FieldOrganizationID, field.TypeUint64, value)
+		_node.OrganizationID = value
+	}
+	if value, ok := cac.mutation.OpenaiBase(); ok {
+		_spec.SetField(compapiasynctask.FieldOpenaiBase, field.TypeString, value)
+		_node.OpenaiBase = value
+	}
+	if value, ok := cac.mutation.OpenaiKey(); ok {
+		_spec.SetField(compapiasynctask.FieldOpenaiKey, field.TypeString, value)
+		_node.OpenaiKey = value
+	}
+	if value, ok := cac.mutation.RequestRaw(); ok {
+		_spec.SetField(compapiasynctask.FieldRequestRaw, field.TypeString, value)
+		_node.RequestRaw = value
+	}
+	if value, ok := cac.mutation.ResponseRaw(); ok {
+		_spec.SetField(compapiasynctask.FieldResponseRaw, field.TypeString, value)
+		_node.ResponseRaw = value
+	}
+	if value, ok := cac.mutation.CallbackURL(); ok {
+		_spec.SetField(compapiasynctask.FieldCallbackURL, field.TypeString, value)
+		_node.CallbackURL = value
+	}
+	if value, ok := cac.mutation.CallbackResponseRaw(); ok {
+		_spec.SetField(compapiasynctask.FieldCallbackResponseRaw, field.TypeString, value)
+		_node.CallbackResponseRaw = value
+	}
+	if value, ok := cac.mutation.Model(); ok {
+		_spec.SetField(compapiasynctask.FieldModel, field.TypeString, value)
+		_node.Model = value
+	}
+	if value, ok := cac.mutation.TaskStatus(); ok {
+		_spec.SetField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
+		_node.TaskStatus = value
+	}
+	if value, ok := cac.mutation.RetryCount(); ok {
+		_spec.SetField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
+		_node.RetryCount = value
+	}
+	if value, ok := cac.mutation.LastError(); ok {
+		_spec.SetField(compapiasynctask.FieldLastError, field.TypeString, value)
+		_node.LastError = value
+	}
+	return _node, _spec
+}
+
+// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
+// of the `INSERT` statement. For example:
+//
+//	client.CompapiAsynctask.Create().
+//		SetCreatedAt(v).
+//		OnConflict(
+//			// Update the row with the new values
+//			// the was proposed for insertion.
+//			sql.ResolveWithNewValues(),
+//		).
+//		// Override some of the fields with custom
+//		// update values.
+//		Update(func(u *ent.CompapiAsynctaskUpsert) {
+//			SetCreatedAt(v+v).
+//		}).
+//		Exec(ctx)
+func (cac *CompapiAsynctaskCreate) OnConflict(opts ...sql.ConflictOption) *CompapiAsynctaskUpsertOne {
+	cac.conflict = opts
+	return &CompapiAsynctaskUpsertOne{
+		create: cac,
+	}
+}
+
+// OnConflictColumns calls `OnConflict` and configures the columns
+// as conflict target. Using this option is equivalent to using:
+//
+//	client.CompapiAsynctask.Create().
+//		OnConflict(sql.ConflictColumns(columns...)).
+//		Exec(ctx)
+func (cac *CompapiAsynctaskCreate) OnConflictColumns(columns ...string) *CompapiAsynctaskUpsertOne {
+	cac.conflict = append(cac.conflict, sql.ConflictColumns(columns...))
+	return &CompapiAsynctaskUpsertOne{
+		create: cac,
+	}
+}
+
+type (
+	// CompapiAsynctaskUpsertOne is the builder for "upsert"-ing
+	//  one CompapiAsynctask node.
+	CompapiAsynctaskUpsertOne struct {
+		create *CompapiAsynctaskCreate
+	}
+
+	// CompapiAsynctaskUpsert is the "OnConflict" setter.
+	CompapiAsynctaskUpsert struct {
+		*sql.UpdateSet
+	}
+)
+
+// SetUpdatedAt sets the "updated_at" field.
+func (u *CompapiAsynctaskUpsert) SetUpdatedAt(v time.Time) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldUpdatedAt, v)
+	return u
+}
+
+// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateUpdatedAt() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldUpdatedAt)
+	return u
+}
+
+// SetAuthToken sets the "auth_token" field.
+func (u *CompapiAsynctaskUpsert) SetAuthToken(v string) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldAuthToken, v)
+	return u
+}
+
+// UpdateAuthToken sets the "auth_token" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateAuthToken() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldAuthToken)
+	return u
+}
+
+// SetEventType sets the "event_type" field.
+func (u *CompapiAsynctaskUpsert) SetEventType(v string) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldEventType, v)
+	return u
+}
+
+// UpdateEventType sets the "event_type" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateEventType() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldEventType)
+	return u
+}
+
+// SetChatID sets the "chat_id" field.
+func (u *CompapiAsynctaskUpsert) SetChatID(v string) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldChatID, v)
+	return u
+}
+
+// UpdateChatID sets the "chat_id" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateChatID() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldChatID)
+	return u
+}
+
+// ClearChatID clears the value of the "chat_id" field.
+func (u *CompapiAsynctaskUpsert) ClearChatID() *CompapiAsynctaskUpsert {
+	u.SetNull(compapiasynctask.FieldChatID)
+	return u
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (u *CompapiAsynctaskUpsert) SetOrganizationID(v uint64) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldOrganizationID, v)
+	return u
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateOrganizationID() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldOrganizationID)
+	return u
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *CompapiAsynctaskUpsert) AddOrganizationID(v uint64) *CompapiAsynctaskUpsert {
+	u.Add(compapiasynctask.FieldOrganizationID, v)
+	return u
+}
+
+// SetOpenaiBase sets the "openai_base" field.
+func (u *CompapiAsynctaskUpsert) SetOpenaiBase(v string) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldOpenaiBase, v)
+	return u
+}
+
+// UpdateOpenaiBase sets the "openai_base" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateOpenaiBase() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldOpenaiBase)
+	return u
+}
+
+// SetOpenaiKey sets the "openai_key" field.
+func (u *CompapiAsynctaskUpsert) SetOpenaiKey(v string) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldOpenaiKey, v)
+	return u
+}
+
+// UpdateOpenaiKey sets the "openai_key" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateOpenaiKey() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldOpenaiKey)
+	return u
+}
+
+// SetRequestRaw sets the "request_raw" field.
+func (u *CompapiAsynctaskUpsert) SetRequestRaw(v string) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldRequestRaw, v)
+	return u
+}
+
+// UpdateRequestRaw sets the "request_raw" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateRequestRaw() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldRequestRaw)
+	return u
+}
+
+// SetResponseRaw sets the "response_raw" field.
+func (u *CompapiAsynctaskUpsert) SetResponseRaw(v string) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldResponseRaw, v)
+	return u
+}
+
+// UpdateResponseRaw sets the "response_raw" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateResponseRaw() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldResponseRaw)
+	return u
+}
+
+// ClearResponseRaw clears the value of the "response_raw" field.
+func (u *CompapiAsynctaskUpsert) ClearResponseRaw() *CompapiAsynctaskUpsert {
+	u.SetNull(compapiasynctask.FieldResponseRaw)
+	return u
+}
+
+// SetCallbackURL sets the "callback_url" field.
+func (u *CompapiAsynctaskUpsert) SetCallbackURL(v string) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldCallbackURL, v)
+	return u
+}
+
+// UpdateCallbackURL sets the "callback_url" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateCallbackURL() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldCallbackURL)
+	return u
+}
+
+// SetCallbackResponseRaw sets the "callback_response_raw" field.
+func (u *CompapiAsynctaskUpsert) SetCallbackResponseRaw(v string) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldCallbackResponseRaw, v)
+	return u
+}
+
+// UpdateCallbackResponseRaw sets the "callback_response_raw" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateCallbackResponseRaw() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldCallbackResponseRaw)
+	return u
+}
+
+// ClearCallbackResponseRaw clears the value of the "callback_response_raw" field.
+func (u *CompapiAsynctaskUpsert) ClearCallbackResponseRaw() *CompapiAsynctaskUpsert {
+	u.SetNull(compapiasynctask.FieldCallbackResponseRaw)
+	return u
+}
+
+// SetModel sets the "model" field.
+func (u *CompapiAsynctaskUpsert) SetModel(v string) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldModel, v)
+	return u
+}
+
+// UpdateModel sets the "model" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateModel() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldModel)
+	return u
+}
+
+// ClearModel clears the value of the "model" field.
+func (u *CompapiAsynctaskUpsert) ClearModel() *CompapiAsynctaskUpsert {
+	u.SetNull(compapiasynctask.FieldModel)
+	return u
+}
+
+// SetTaskStatus sets the "task_status" field.
+func (u *CompapiAsynctaskUpsert) SetTaskStatus(v int8) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldTaskStatus, v)
+	return u
+}
+
+// UpdateTaskStatus sets the "task_status" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateTaskStatus() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldTaskStatus)
+	return u
+}
+
+// AddTaskStatus adds v to the "task_status" field.
+func (u *CompapiAsynctaskUpsert) AddTaskStatus(v int8) *CompapiAsynctaskUpsert {
+	u.Add(compapiasynctask.FieldTaskStatus, v)
+	return u
+}
+
+// ClearTaskStatus clears the value of the "task_status" field.
+func (u *CompapiAsynctaskUpsert) ClearTaskStatus() *CompapiAsynctaskUpsert {
+	u.SetNull(compapiasynctask.FieldTaskStatus)
+	return u
+}
+
+// SetRetryCount sets the "retry_count" field.
+func (u *CompapiAsynctaskUpsert) SetRetryCount(v int8) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldRetryCount, v)
+	return u
+}
+
+// UpdateRetryCount sets the "retry_count" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateRetryCount() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldRetryCount)
+	return u
+}
+
+// AddRetryCount adds v to the "retry_count" field.
+func (u *CompapiAsynctaskUpsert) AddRetryCount(v int8) *CompapiAsynctaskUpsert {
+	u.Add(compapiasynctask.FieldRetryCount, v)
+	return u
+}
+
+// ClearRetryCount clears the value of the "retry_count" field.
+func (u *CompapiAsynctaskUpsert) ClearRetryCount() *CompapiAsynctaskUpsert {
+	u.SetNull(compapiasynctask.FieldRetryCount)
+	return u
+}
+
+// SetLastError sets the "last_error" field.
+func (u *CompapiAsynctaskUpsert) SetLastError(v string) *CompapiAsynctaskUpsert {
+	u.Set(compapiasynctask.FieldLastError, v)
+	return u
+}
+
+// UpdateLastError sets the "last_error" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsert) UpdateLastError() *CompapiAsynctaskUpsert {
+	u.SetExcluded(compapiasynctask.FieldLastError)
+	return u
+}
+
+// ClearLastError clears the value of the "last_error" field.
+func (u *CompapiAsynctaskUpsert) ClearLastError() *CompapiAsynctaskUpsert {
+	u.SetNull(compapiasynctask.FieldLastError)
+	return u
+}
+
+// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
+// Using this option is equivalent to using:
+//
+//	client.CompapiAsynctask.Create().
+//		OnConflict(
+//			sql.ResolveWithNewValues(),
+//			sql.ResolveWith(func(u *sql.UpdateSet) {
+//				u.SetIgnore(compapiasynctask.FieldID)
+//			}),
+//		).
+//		Exec(ctx)
+func (u *CompapiAsynctaskUpsertOne) UpdateNewValues() *CompapiAsynctaskUpsertOne {
+	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
+	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
+		if _, exists := u.create.mutation.ID(); exists {
+			s.SetIgnore(compapiasynctask.FieldID)
+		}
+		if _, exists := u.create.mutation.CreatedAt(); exists {
+			s.SetIgnore(compapiasynctask.FieldCreatedAt)
+		}
+	}))
+	return u
+}
+
+// Ignore sets each column to itself in case of conflict.
+// Using this option is equivalent to using:
+//
+//	client.CompapiAsynctask.Create().
+//	    OnConflict(sql.ResolveWithIgnore()).
+//	    Exec(ctx)
+func (u *CompapiAsynctaskUpsertOne) Ignore() *CompapiAsynctaskUpsertOne {
+	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
+	return u
+}
+
+// DoNothing configures the conflict_action to `DO NOTHING`.
+// Supported only by SQLite and PostgreSQL.
+func (u *CompapiAsynctaskUpsertOne) DoNothing() *CompapiAsynctaskUpsertOne {
+	u.create.conflict = append(u.create.conflict, sql.DoNothing())
+	return u
+}
+
+// Update allows overriding fields `UPDATE` values. See the CompapiAsynctaskCreate.OnConflict
+// documentation for more info.
+func (u *CompapiAsynctaskUpsertOne) Update(set func(*CompapiAsynctaskUpsert)) *CompapiAsynctaskUpsertOne {
+	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
+		set(&CompapiAsynctaskUpsert{UpdateSet: update})
+	}))
+	return u
+}
+
+// SetUpdatedAt sets the "updated_at" field.
+func (u *CompapiAsynctaskUpsertOne) SetUpdatedAt(v time.Time) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetUpdatedAt(v)
+	})
+}
+
+// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateUpdatedAt() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateUpdatedAt()
+	})
+}
+
+// SetAuthToken sets the "auth_token" field.
+func (u *CompapiAsynctaskUpsertOne) SetAuthToken(v string) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetAuthToken(v)
+	})
+}
+
+// UpdateAuthToken sets the "auth_token" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateAuthToken() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateAuthToken()
+	})
+}
+
+// SetEventType sets the "event_type" field.
+func (u *CompapiAsynctaskUpsertOne) SetEventType(v string) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetEventType(v)
+	})
+}
+
+// UpdateEventType sets the "event_type" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateEventType() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateEventType()
+	})
+}
+
+// SetChatID sets the "chat_id" field.
+func (u *CompapiAsynctaskUpsertOne) SetChatID(v string) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetChatID(v)
+	})
+}
+
+// UpdateChatID sets the "chat_id" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateChatID() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateChatID()
+	})
+}
+
+// ClearChatID clears the value of the "chat_id" field.
+func (u *CompapiAsynctaskUpsertOne) ClearChatID() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearChatID()
+	})
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (u *CompapiAsynctaskUpsertOne) SetOrganizationID(v uint64) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *CompapiAsynctaskUpsertOne) AddOrganizationID(v uint64) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateOrganizationID() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// SetOpenaiBase sets the "openai_base" field.
+func (u *CompapiAsynctaskUpsertOne) SetOpenaiBase(v string) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetOpenaiBase(v)
+	})
+}
+
+// UpdateOpenaiBase sets the "openai_base" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateOpenaiBase() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateOpenaiBase()
+	})
+}
+
+// SetOpenaiKey sets the "openai_key" field.
+func (u *CompapiAsynctaskUpsertOne) SetOpenaiKey(v string) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetOpenaiKey(v)
+	})
+}
+
+// UpdateOpenaiKey sets the "openai_key" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateOpenaiKey() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateOpenaiKey()
+	})
+}
+
+// SetRequestRaw sets the "request_raw" field.
+func (u *CompapiAsynctaskUpsertOne) SetRequestRaw(v string) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetRequestRaw(v)
+	})
+}
+
+// UpdateRequestRaw sets the "request_raw" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateRequestRaw() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateRequestRaw()
+	})
+}
+
+// SetResponseRaw sets the "response_raw" field.
+func (u *CompapiAsynctaskUpsertOne) SetResponseRaw(v string) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetResponseRaw(v)
+	})
+}
+
+// UpdateResponseRaw sets the "response_raw" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateResponseRaw() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateResponseRaw()
+	})
+}
+
+// ClearResponseRaw clears the value of the "response_raw" field.
+func (u *CompapiAsynctaskUpsertOne) ClearResponseRaw() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearResponseRaw()
+	})
+}
+
+// SetCallbackURL sets the "callback_url" field.
+func (u *CompapiAsynctaskUpsertOne) SetCallbackURL(v string) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetCallbackURL(v)
+	})
+}
+
+// UpdateCallbackURL sets the "callback_url" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateCallbackURL() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateCallbackURL()
+	})
+}
+
+// SetCallbackResponseRaw sets the "callback_response_raw" field.
+func (u *CompapiAsynctaskUpsertOne) SetCallbackResponseRaw(v string) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetCallbackResponseRaw(v)
+	})
+}
+
+// UpdateCallbackResponseRaw sets the "callback_response_raw" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateCallbackResponseRaw() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateCallbackResponseRaw()
+	})
+}
+
+// ClearCallbackResponseRaw clears the value of the "callback_response_raw" field.
+func (u *CompapiAsynctaskUpsertOne) ClearCallbackResponseRaw() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearCallbackResponseRaw()
+	})
+}
+
+// SetModel sets the "model" field.
+func (u *CompapiAsynctaskUpsertOne) SetModel(v string) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetModel(v)
+	})
+}
+
+// UpdateModel sets the "model" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateModel() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateModel()
+	})
+}
+
+// ClearModel clears the value of the "model" field.
+func (u *CompapiAsynctaskUpsertOne) ClearModel() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearModel()
+	})
+}
+
+// SetTaskStatus sets the "task_status" field.
+func (u *CompapiAsynctaskUpsertOne) SetTaskStatus(v int8) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetTaskStatus(v)
+	})
+}
+
+// AddTaskStatus adds v to the "task_status" field.
+func (u *CompapiAsynctaskUpsertOne) AddTaskStatus(v int8) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.AddTaskStatus(v)
+	})
+}
+
+// UpdateTaskStatus sets the "task_status" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateTaskStatus() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateTaskStatus()
+	})
+}
+
+// ClearTaskStatus clears the value of the "task_status" field.
+func (u *CompapiAsynctaskUpsertOne) ClearTaskStatus() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearTaskStatus()
+	})
+}
+
+// SetRetryCount sets the "retry_count" field.
+func (u *CompapiAsynctaskUpsertOne) SetRetryCount(v int8) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetRetryCount(v)
+	})
+}
+
+// AddRetryCount adds v to the "retry_count" field.
+func (u *CompapiAsynctaskUpsertOne) AddRetryCount(v int8) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.AddRetryCount(v)
+	})
+}
+
+// UpdateRetryCount sets the "retry_count" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateRetryCount() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateRetryCount()
+	})
+}
+
+// ClearRetryCount clears the value of the "retry_count" field.
+func (u *CompapiAsynctaskUpsertOne) ClearRetryCount() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearRetryCount()
+	})
+}
+
+// SetLastError sets the "last_error" field.
+func (u *CompapiAsynctaskUpsertOne) SetLastError(v string) *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetLastError(v)
+	})
+}
+
+// UpdateLastError sets the "last_error" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertOne) UpdateLastError() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateLastError()
+	})
+}
+
+// ClearLastError clears the value of the "last_error" field.
+func (u *CompapiAsynctaskUpsertOne) ClearLastError() *CompapiAsynctaskUpsertOne {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearLastError()
+	})
+}
+
+// Exec executes the query.
+func (u *CompapiAsynctaskUpsertOne) Exec(ctx context.Context) error {
+	if len(u.create.conflict) == 0 {
+		return errors.New("ent: missing options for CompapiAsynctaskCreate.OnConflict")
+	}
+	return u.create.Exec(ctx)
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (u *CompapiAsynctaskUpsertOne) ExecX(ctx context.Context) {
+	if err := u.create.Exec(ctx); err != nil {
+		panic(err)
+	}
+}
+
+// Exec executes the UPSERT query and returns the inserted/updated ID.
+func (u *CompapiAsynctaskUpsertOne) ID(ctx context.Context) (id uint64, err error) {
+	node, err := u.create.Save(ctx)
+	if err != nil {
+		return id, err
+	}
+	return node.ID, nil
+}
+
+// IDX is like ID, but panics if an error occurs.
+func (u *CompapiAsynctaskUpsertOne) IDX(ctx context.Context) uint64 {
+	id, err := u.ID(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return id
+}
+
+// CompapiAsynctaskCreateBulk is the builder for creating many CompapiAsynctask entities in bulk.
+type CompapiAsynctaskCreateBulk struct {
+	config
+	err      error
+	builders []*CompapiAsynctaskCreate
+	conflict []sql.ConflictOption
+}
+
+// Save creates the CompapiAsynctask entities in the database.
+func (cacb *CompapiAsynctaskCreateBulk) Save(ctx context.Context) ([]*CompapiAsynctask, error) {
+	if cacb.err != nil {
+		return nil, cacb.err
+	}
+	specs := make([]*sqlgraph.CreateSpec, len(cacb.builders))
+	nodes := make([]*CompapiAsynctask, len(cacb.builders))
+	mutators := make([]Mutator, len(cacb.builders))
+	for i := range cacb.builders {
+		func(i int, root context.Context) {
+			builder := cacb.builders[i]
+			builder.defaults()
+			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
+				mutation, ok := m.(*CompapiAsynctaskMutation)
+				if !ok {
+					return nil, fmt.Errorf("unexpected mutation type %T", m)
+				}
+				if err := builder.check(); err != nil {
+					return nil, err
+				}
+				builder.mutation = mutation
+				var err error
+				nodes[i], specs[i] = builder.createSpec()
+				if i < len(mutators)-1 {
+					_, err = mutators[i+1].Mutate(root, cacb.builders[i+1].mutation)
+				} else {
+					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
+					spec.OnConflict = cacb.conflict
+					// Invoke the actual operation on the latest mutation in the chain.
+					if err = sqlgraph.BatchCreate(ctx, cacb.driver, spec); err != nil {
+						if sqlgraph.IsConstraintError(err) {
+							err = &ConstraintError{msg: err.Error(), wrap: err}
+						}
+					}
+				}
+				if err != nil {
+					return nil, err
+				}
+				mutation.id = &nodes[i].ID
+				if specs[i].ID.Value != nil && nodes[i].ID == 0 {
+					id := specs[i].ID.Value.(int64)
+					nodes[i].ID = uint64(id)
+				}
+				mutation.done = true
+				return nodes[i], nil
+			})
+			for i := len(builder.hooks) - 1; i >= 0; i-- {
+				mut = builder.hooks[i](mut)
+			}
+			mutators[i] = mut
+		}(i, ctx)
+	}
+	if len(mutators) > 0 {
+		if _, err := mutators[0].Mutate(ctx, cacb.builders[0].mutation); err != nil {
+			return nil, err
+		}
+	}
+	return nodes, nil
+}
+
+// SaveX is like Save, but panics if an error occurs.
+func (cacb *CompapiAsynctaskCreateBulk) SaveX(ctx context.Context) []*CompapiAsynctask {
+	v, err := cacb.Save(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return v
+}
+
+// Exec executes the query.
+func (cacb *CompapiAsynctaskCreateBulk) Exec(ctx context.Context) error {
+	_, err := cacb.Save(ctx)
+	return err
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (cacb *CompapiAsynctaskCreateBulk) ExecX(ctx context.Context) {
+	if err := cacb.Exec(ctx); err != nil {
+		panic(err)
+	}
+}
+
+// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
+// of the `INSERT` statement. For example:
+//
+//	client.CompapiAsynctask.CreateBulk(builders...).
+//		OnConflict(
+//			// Update the row with the new values
+//			// the was proposed for insertion.
+//			sql.ResolveWithNewValues(),
+//		).
+//		// Override some of the fields with custom
+//		// update values.
+//		Update(func(u *ent.CompapiAsynctaskUpsert) {
+//			SetCreatedAt(v+v).
+//		}).
+//		Exec(ctx)
+func (cacb *CompapiAsynctaskCreateBulk) OnConflict(opts ...sql.ConflictOption) *CompapiAsynctaskUpsertBulk {
+	cacb.conflict = opts
+	return &CompapiAsynctaskUpsertBulk{
+		create: cacb,
+	}
+}
+
+// OnConflictColumns calls `OnConflict` and configures the columns
+// as conflict target. Using this option is equivalent to using:
+//
+//	client.CompapiAsynctask.Create().
+//		OnConflict(sql.ConflictColumns(columns...)).
+//		Exec(ctx)
+func (cacb *CompapiAsynctaskCreateBulk) OnConflictColumns(columns ...string) *CompapiAsynctaskUpsertBulk {
+	cacb.conflict = append(cacb.conflict, sql.ConflictColumns(columns...))
+	return &CompapiAsynctaskUpsertBulk{
+		create: cacb,
+	}
+}
+
+// CompapiAsynctaskUpsertBulk is the builder for "upsert"-ing
+// a bulk of CompapiAsynctask nodes.
+type CompapiAsynctaskUpsertBulk struct {
+	create *CompapiAsynctaskCreateBulk
+}
+
+// UpdateNewValues updates the mutable fields using the new values that
+// were set on create. Using this option is equivalent to using:
+//
+//	client.CompapiAsynctask.Create().
+//		OnConflict(
+//			sql.ResolveWithNewValues(),
+//			sql.ResolveWith(func(u *sql.UpdateSet) {
+//				u.SetIgnore(compapiasynctask.FieldID)
+//			}),
+//		).
+//		Exec(ctx)
+func (u *CompapiAsynctaskUpsertBulk) UpdateNewValues() *CompapiAsynctaskUpsertBulk {
+	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
+	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
+		for _, b := range u.create.builders {
+			if _, exists := b.mutation.ID(); exists {
+				s.SetIgnore(compapiasynctask.FieldID)
+			}
+			if _, exists := b.mutation.CreatedAt(); exists {
+				s.SetIgnore(compapiasynctask.FieldCreatedAt)
+			}
+		}
+	}))
+	return u
+}
+
+// Ignore sets each column to itself in case of conflict.
+// Using this option is equivalent to using:
+//
+//	client.CompapiAsynctask.Create().
+//		OnConflict(sql.ResolveWithIgnore()).
+//		Exec(ctx)
+func (u *CompapiAsynctaskUpsertBulk) Ignore() *CompapiAsynctaskUpsertBulk {
+	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
+	return u
+}
+
+// DoNothing configures the conflict_action to `DO NOTHING`.
+// Supported only by SQLite and PostgreSQL.
+func (u *CompapiAsynctaskUpsertBulk) DoNothing() *CompapiAsynctaskUpsertBulk {
+	u.create.conflict = append(u.create.conflict, sql.DoNothing())
+	return u
+}
+
+// Update allows overriding fields `UPDATE` values. See the CompapiAsynctaskCreateBulk.OnConflict
+// documentation for more info.
+func (u *CompapiAsynctaskUpsertBulk) Update(set func(*CompapiAsynctaskUpsert)) *CompapiAsynctaskUpsertBulk {
+	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
+		set(&CompapiAsynctaskUpsert{UpdateSet: update})
+	}))
+	return u
+}
+
+// SetUpdatedAt sets the "updated_at" field.
+func (u *CompapiAsynctaskUpsertBulk) SetUpdatedAt(v time.Time) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetUpdatedAt(v)
+	})
+}
+
+// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateUpdatedAt() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateUpdatedAt()
+	})
+}
+
+// SetAuthToken sets the "auth_token" field.
+func (u *CompapiAsynctaskUpsertBulk) SetAuthToken(v string) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetAuthToken(v)
+	})
+}
+
+// UpdateAuthToken sets the "auth_token" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateAuthToken() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateAuthToken()
+	})
+}
+
+// SetEventType sets the "event_type" field.
+func (u *CompapiAsynctaskUpsertBulk) SetEventType(v string) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetEventType(v)
+	})
+}
+
+// UpdateEventType sets the "event_type" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateEventType() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateEventType()
+	})
+}
+
+// SetChatID sets the "chat_id" field.
+func (u *CompapiAsynctaskUpsertBulk) SetChatID(v string) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetChatID(v)
+	})
+}
+
+// UpdateChatID sets the "chat_id" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateChatID() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateChatID()
+	})
+}
+
+// ClearChatID clears the value of the "chat_id" field.
+func (u *CompapiAsynctaskUpsertBulk) ClearChatID() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearChatID()
+	})
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (u *CompapiAsynctaskUpsertBulk) SetOrganizationID(v uint64) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetOrganizationID(v)
+	})
+}
+
+// AddOrganizationID adds v to the "organization_id" field.
+func (u *CompapiAsynctaskUpsertBulk) AddOrganizationID(v uint64) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.AddOrganizationID(v)
+	})
+}
+
+// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateOrganizationID() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateOrganizationID()
+	})
+}
+
+// SetOpenaiBase sets the "openai_base" field.
+func (u *CompapiAsynctaskUpsertBulk) SetOpenaiBase(v string) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetOpenaiBase(v)
+	})
+}
+
+// UpdateOpenaiBase sets the "openai_base" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateOpenaiBase() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateOpenaiBase()
+	})
+}
+
+// SetOpenaiKey sets the "openai_key" field.
+func (u *CompapiAsynctaskUpsertBulk) SetOpenaiKey(v string) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetOpenaiKey(v)
+	})
+}
+
+// UpdateOpenaiKey sets the "openai_key" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateOpenaiKey() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateOpenaiKey()
+	})
+}
+
+// SetRequestRaw sets the "request_raw" field.
+func (u *CompapiAsynctaskUpsertBulk) SetRequestRaw(v string) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetRequestRaw(v)
+	})
+}
+
+// UpdateRequestRaw sets the "request_raw" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateRequestRaw() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateRequestRaw()
+	})
+}
+
+// SetResponseRaw sets the "response_raw" field.
+func (u *CompapiAsynctaskUpsertBulk) SetResponseRaw(v string) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetResponseRaw(v)
+	})
+}
+
+// UpdateResponseRaw sets the "response_raw" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateResponseRaw() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateResponseRaw()
+	})
+}
+
+// ClearResponseRaw clears the value of the "response_raw" field.
+func (u *CompapiAsynctaskUpsertBulk) ClearResponseRaw() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearResponseRaw()
+	})
+}
+
+// SetCallbackURL sets the "callback_url" field.
+func (u *CompapiAsynctaskUpsertBulk) SetCallbackURL(v string) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetCallbackURL(v)
+	})
+}
+
+// UpdateCallbackURL sets the "callback_url" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateCallbackURL() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateCallbackURL()
+	})
+}
+
+// SetCallbackResponseRaw sets the "callback_response_raw" field.
+func (u *CompapiAsynctaskUpsertBulk) SetCallbackResponseRaw(v string) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetCallbackResponseRaw(v)
+	})
+}
+
+// UpdateCallbackResponseRaw sets the "callback_response_raw" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateCallbackResponseRaw() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateCallbackResponseRaw()
+	})
+}
+
+// ClearCallbackResponseRaw clears the value of the "callback_response_raw" field.
+func (u *CompapiAsynctaskUpsertBulk) ClearCallbackResponseRaw() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearCallbackResponseRaw()
+	})
+}
+
+// SetModel sets the "model" field.
+func (u *CompapiAsynctaskUpsertBulk) SetModel(v string) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetModel(v)
+	})
+}
+
+// UpdateModel sets the "model" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateModel() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateModel()
+	})
+}
+
+// ClearModel clears the value of the "model" field.
+func (u *CompapiAsynctaskUpsertBulk) ClearModel() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearModel()
+	})
+}
+
+// SetTaskStatus sets the "task_status" field.
+func (u *CompapiAsynctaskUpsertBulk) SetTaskStatus(v int8) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetTaskStatus(v)
+	})
+}
+
+// AddTaskStatus adds v to the "task_status" field.
+func (u *CompapiAsynctaskUpsertBulk) AddTaskStatus(v int8) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.AddTaskStatus(v)
+	})
+}
+
+// UpdateTaskStatus sets the "task_status" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateTaskStatus() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateTaskStatus()
+	})
+}
+
+// ClearTaskStatus clears the value of the "task_status" field.
+func (u *CompapiAsynctaskUpsertBulk) ClearTaskStatus() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearTaskStatus()
+	})
+}
+
+// SetRetryCount sets the "retry_count" field.
+func (u *CompapiAsynctaskUpsertBulk) SetRetryCount(v int8) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetRetryCount(v)
+	})
+}
+
+// AddRetryCount adds v to the "retry_count" field.
+func (u *CompapiAsynctaskUpsertBulk) AddRetryCount(v int8) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.AddRetryCount(v)
+	})
+}
+
+// UpdateRetryCount sets the "retry_count" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateRetryCount() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateRetryCount()
+	})
+}
+
+// ClearRetryCount clears the value of the "retry_count" field.
+func (u *CompapiAsynctaskUpsertBulk) ClearRetryCount() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearRetryCount()
+	})
+}
+
+// SetLastError sets the "last_error" field.
+func (u *CompapiAsynctaskUpsertBulk) SetLastError(v string) *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.SetLastError(v)
+	})
+}
+
+// UpdateLastError sets the "last_error" field to the value that was provided on create.
+func (u *CompapiAsynctaskUpsertBulk) UpdateLastError() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.UpdateLastError()
+	})
+}
+
+// ClearLastError clears the value of the "last_error" field.
+func (u *CompapiAsynctaskUpsertBulk) ClearLastError() *CompapiAsynctaskUpsertBulk {
+	return u.Update(func(s *CompapiAsynctaskUpsert) {
+		s.ClearLastError()
+	})
+}
+
+// Exec executes the query.
+func (u *CompapiAsynctaskUpsertBulk) Exec(ctx context.Context) error {
+	if u.create.err != nil {
+		return u.create.err
+	}
+	for i, b := range u.create.builders {
+		if len(b.conflict) != 0 {
+			return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the CompapiAsynctaskCreateBulk instead", i)
+		}
+	}
+	if len(u.create.conflict) == 0 {
+		return errors.New("ent: missing options for CompapiAsynctaskCreateBulk.OnConflict")
+	}
+	return u.create.Exec(ctx)
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (u *CompapiAsynctaskUpsertBulk) ExecX(ctx context.Context) {
+	if err := u.create.Exec(ctx); err != nil {
+		panic(err)
+	}
+}

+ 88 - 0
ent/compapiasynctask_delete.go

@@ -0,0 +1,88 @@
+// Code generated by ent, DO NOT EDIT.
+
+package ent
+
+import (
+	"context"
+	"wechat-api/ent/compapiasynctask"
+	"wechat-api/ent/predicate"
+
+	"entgo.io/ent/dialect/sql"
+	"entgo.io/ent/dialect/sql/sqlgraph"
+	"entgo.io/ent/schema/field"
+)
+
+// CompapiAsynctaskDelete is the builder for deleting a CompapiAsynctask entity.
+type CompapiAsynctaskDelete struct {
+	config
+	hooks    []Hook
+	mutation *CompapiAsynctaskMutation
+}
+
+// Where appends a list predicates to the CompapiAsynctaskDelete builder.
+func (cad *CompapiAsynctaskDelete) Where(ps ...predicate.CompapiAsynctask) *CompapiAsynctaskDelete {
+	cad.mutation.Where(ps...)
+	return cad
+}
+
+// Exec executes the deletion query and returns how many vertices were deleted.
+func (cad *CompapiAsynctaskDelete) Exec(ctx context.Context) (int, error) {
+	return withHooks(ctx, cad.sqlExec, cad.mutation, cad.hooks)
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (cad *CompapiAsynctaskDelete) ExecX(ctx context.Context) int {
+	n, err := cad.Exec(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return n
+}
+
+func (cad *CompapiAsynctaskDelete) sqlExec(ctx context.Context) (int, error) {
+	_spec := sqlgraph.NewDeleteSpec(compapiasynctask.Table, sqlgraph.NewFieldSpec(compapiasynctask.FieldID, field.TypeUint64))
+	if ps := cad.mutation.predicates; len(ps) > 0 {
+		_spec.Predicate = func(selector *sql.Selector) {
+			for i := range ps {
+				ps[i](selector)
+			}
+		}
+	}
+	affected, err := sqlgraph.DeleteNodes(ctx, cad.driver, _spec)
+	if err != nil && sqlgraph.IsConstraintError(err) {
+		err = &ConstraintError{msg: err.Error(), wrap: err}
+	}
+	cad.mutation.done = true
+	return affected, err
+}
+
+// CompapiAsynctaskDeleteOne is the builder for deleting a single CompapiAsynctask entity.
+type CompapiAsynctaskDeleteOne struct {
+	cad *CompapiAsynctaskDelete
+}
+
+// Where appends a list predicates to the CompapiAsynctaskDelete builder.
+func (cado *CompapiAsynctaskDeleteOne) Where(ps ...predicate.CompapiAsynctask) *CompapiAsynctaskDeleteOne {
+	cado.cad.mutation.Where(ps...)
+	return cado
+}
+
+// Exec executes the deletion query.
+func (cado *CompapiAsynctaskDeleteOne) Exec(ctx context.Context) error {
+	n, err := cado.cad.Exec(ctx)
+	switch {
+	case err != nil:
+		return err
+	case n == 0:
+		return &NotFoundError{compapiasynctask.Label}
+	default:
+		return nil
+	}
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (cado *CompapiAsynctaskDeleteOne) ExecX(ctx context.Context) {
+	if err := cado.Exec(ctx); err != nil {
+		panic(err)
+	}
+}

+ 526 - 0
ent/compapiasynctask_query.go

@@ -0,0 +1,526 @@
+// Code generated by ent, DO NOT EDIT.
+
+package ent
+
+import (
+	"context"
+	"fmt"
+	"math"
+	"wechat-api/ent/compapiasynctask"
+	"wechat-api/ent/predicate"
+
+	"entgo.io/ent/dialect/sql"
+	"entgo.io/ent/dialect/sql/sqlgraph"
+	"entgo.io/ent/schema/field"
+)
+
+// CompapiAsynctaskQuery is the builder for querying CompapiAsynctask entities.
+type CompapiAsynctaskQuery struct {
+	config
+	ctx        *QueryContext
+	order      []compapiasynctask.OrderOption
+	inters     []Interceptor
+	predicates []predicate.CompapiAsynctask
+	// intermediate query (i.e. traversal path).
+	sql  *sql.Selector
+	path func(context.Context) (*sql.Selector, error)
+}
+
+// Where adds a new predicate for the CompapiAsynctaskQuery builder.
+func (caq *CompapiAsynctaskQuery) Where(ps ...predicate.CompapiAsynctask) *CompapiAsynctaskQuery {
+	caq.predicates = append(caq.predicates, ps...)
+	return caq
+}
+
+// Limit the number of records to be returned by this query.
+func (caq *CompapiAsynctaskQuery) Limit(limit int) *CompapiAsynctaskQuery {
+	caq.ctx.Limit = &limit
+	return caq
+}
+
+// Offset to start from.
+func (caq *CompapiAsynctaskQuery) Offset(offset int) *CompapiAsynctaskQuery {
+	caq.ctx.Offset = &offset
+	return caq
+}
+
+// Unique configures the query builder to filter duplicate records on query.
+// By default, unique is set to true, and can be disabled using this method.
+func (caq *CompapiAsynctaskQuery) Unique(unique bool) *CompapiAsynctaskQuery {
+	caq.ctx.Unique = &unique
+	return caq
+}
+
+// Order specifies how the records should be ordered.
+func (caq *CompapiAsynctaskQuery) Order(o ...compapiasynctask.OrderOption) *CompapiAsynctaskQuery {
+	caq.order = append(caq.order, o...)
+	return caq
+}
+
+// First returns the first CompapiAsynctask entity from the query.
+// Returns a *NotFoundError when no CompapiAsynctask was found.
+func (caq *CompapiAsynctaskQuery) First(ctx context.Context) (*CompapiAsynctask, error) {
+	nodes, err := caq.Limit(1).All(setContextOp(ctx, caq.ctx, "First"))
+	if err != nil {
+		return nil, err
+	}
+	if len(nodes) == 0 {
+		return nil, &NotFoundError{compapiasynctask.Label}
+	}
+	return nodes[0], nil
+}
+
+// FirstX is like First, but panics if an error occurs.
+func (caq *CompapiAsynctaskQuery) FirstX(ctx context.Context) *CompapiAsynctask {
+	node, err := caq.First(ctx)
+	if err != nil && !IsNotFound(err) {
+		panic(err)
+	}
+	return node
+}
+
+// FirstID returns the first CompapiAsynctask ID from the query.
+// Returns a *NotFoundError when no CompapiAsynctask ID was found.
+func (caq *CompapiAsynctaskQuery) FirstID(ctx context.Context) (id uint64, err error) {
+	var ids []uint64
+	if ids, err = caq.Limit(1).IDs(setContextOp(ctx, caq.ctx, "FirstID")); err != nil {
+		return
+	}
+	if len(ids) == 0 {
+		err = &NotFoundError{compapiasynctask.Label}
+		return
+	}
+	return ids[0], nil
+}
+
+// FirstIDX is like FirstID, but panics if an error occurs.
+func (caq *CompapiAsynctaskQuery) FirstIDX(ctx context.Context) uint64 {
+	id, err := caq.FirstID(ctx)
+	if err != nil && !IsNotFound(err) {
+		panic(err)
+	}
+	return id
+}
+
+// Only returns a single CompapiAsynctask entity found by the query, ensuring it only returns one.
+// Returns a *NotSingularError when more than one CompapiAsynctask entity is found.
+// Returns a *NotFoundError when no CompapiAsynctask entities are found.
+func (caq *CompapiAsynctaskQuery) Only(ctx context.Context) (*CompapiAsynctask, error) {
+	nodes, err := caq.Limit(2).All(setContextOp(ctx, caq.ctx, "Only"))
+	if err != nil {
+		return nil, err
+	}
+	switch len(nodes) {
+	case 1:
+		return nodes[0], nil
+	case 0:
+		return nil, &NotFoundError{compapiasynctask.Label}
+	default:
+		return nil, &NotSingularError{compapiasynctask.Label}
+	}
+}
+
+// OnlyX is like Only, but panics if an error occurs.
+func (caq *CompapiAsynctaskQuery) OnlyX(ctx context.Context) *CompapiAsynctask {
+	node, err := caq.Only(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return node
+}
+
+// OnlyID is like Only, but returns the only CompapiAsynctask ID in the query.
+// Returns a *NotSingularError when more than one CompapiAsynctask ID is found.
+// Returns a *NotFoundError when no entities are found.
+func (caq *CompapiAsynctaskQuery) OnlyID(ctx context.Context) (id uint64, err error) {
+	var ids []uint64
+	if ids, err = caq.Limit(2).IDs(setContextOp(ctx, caq.ctx, "OnlyID")); err != nil {
+		return
+	}
+	switch len(ids) {
+	case 1:
+		id = ids[0]
+	case 0:
+		err = &NotFoundError{compapiasynctask.Label}
+	default:
+		err = &NotSingularError{compapiasynctask.Label}
+	}
+	return
+}
+
+// OnlyIDX is like OnlyID, but panics if an error occurs.
+func (caq *CompapiAsynctaskQuery) OnlyIDX(ctx context.Context) uint64 {
+	id, err := caq.OnlyID(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return id
+}
+
+// All executes the query and returns a list of CompapiAsynctasks.
+func (caq *CompapiAsynctaskQuery) All(ctx context.Context) ([]*CompapiAsynctask, error) {
+	ctx = setContextOp(ctx, caq.ctx, "All")
+	if err := caq.prepareQuery(ctx); err != nil {
+		return nil, err
+	}
+	qr := querierAll[[]*CompapiAsynctask, *CompapiAsynctaskQuery]()
+	return withInterceptors[[]*CompapiAsynctask](ctx, caq, qr, caq.inters)
+}
+
+// AllX is like All, but panics if an error occurs.
+func (caq *CompapiAsynctaskQuery) AllX(ctx context.Context) []*CompapiAsynctask {
+	nodes, err := caq.All(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return nodes
+}
+
+// IDs executes the query and returns a list of CompapiAsynctask IDs.
+func (caq *CompapiAsynctaskQuery) IDs(ctx context.Context) (ids []uint64, err error) {
+	if caq.ctx.Unique == nil && caq.path != nil {
+		caq.Unique(true)
+	}
+	ctx = setContextOp(ctx, caq.ctx, "IDs")
+	if err = caq.Select(compapiasynctask.FieldID).Scan(ctx, &ids); err != nil {
+		return nil, err
+	}
+	return ids, nil
+}
+
+// IDsX is like IDs, but panics if an error occurs.
+func (caq *CompapiAsynctaskQuery) IDsX(ctx context.Context) []uint64 {
+	ids, err := caq.IDs(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return ids
+}
+
+// Count returns the count of the given query.
+func (caq *CompapiAsynctaskQuery) Count(ctx context.Context) (int, error) {
+	ctx = setContextOp(ctx, caq.ctx, "Count")
+	if err := caq.prepareQuery(ctx); err != nil {
+		return 0, err
+	}
+	return withInterceptors[int](ctx, caq, querierCount[*CompapiAsynctaskQuery](), caq.inters)
+}
+
+// CountX is like Count, but panics if an error occurs.
+func (caq *CompapiAsynctaskQuery) CountX(ctx context.Context) int {
+	count, err := caq.Count(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return count
+}
+
+// Exist returns true if the query has elements in the graph.
+func (caq *CompapiAsynctaskQuery) Exist(ctx context.Context) (bool, error) {
+	ctx = setContextOp(ctx, caq.ctx, "Exist")
+	switch _, err := caq.FirstID(ctx); {
+	case IsNotFound(err):
+		return false, nil
+	case err != nil:
+		return false, fmt.Errorf("ent: check existence: %w", err)
+	default:
+		return true, nil
+	}
+}
+
+// ExistX is like Exist, but panics if an error occurs.
+func (caq *CompapiAsynctaskQuery) ExistX(ctx context.Context) bool {
+	exist, err := caq.Exist(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return exist
+}
+
+// Clone returns a duplicate of the CompapiAsynctaskQuery builder, including all associated steps. It can be
+// used to prepare common query builders and use them differently after the clone is made.
+func (caq *CompapiAsynctaskQuery) Clone() *CompapiAsynctaskQuery {
+	if caq == nil {
+		return nil
+	}
+	return &CompapiAsynctaskQuery{
+		config:     caq.config,
+		ctx:        caq.ctx.Clone(),
+		order:      append([]compapiasynctask.OrderOption{}, caq.order...),
+		inters:     append([]Interceptor{}, caq.inters...),
+		predicates: append([]predicate.CompapiAsynctask{}, caq.predicates...),
+		// clone intermediate query.
+		sql:  caq.sql.Clone(),
+		path: caq.path,
+	}
+}
+
+// GroupBy is used to group vertices by one or more fields/columns.
+// It is often used with aggregate functions, like: count, max, mean, min, sum.
+//
+// Example:
+//
+//	var v []struct {
+//		CreatedAt time.Time `json:"created_at,omitempty"`
+//		Count int `json:"count,omitempty"`
+//	}
+//
+//	client.CompapiAsynctask.Query().
+//		GroupBy(compapiasynctask.FieldCreatedAt).
+//		Aggregate(ent.Count()).
+//		Scan(ctx, &v)
+func (caq *CompapiAsynctaskQuery) GroupBy(field string, fields ...string) *CompapiAsynctaskGroupBy {
+	caq.ctx.Fields = append([]string{field}, fields...)
+	grbuild := &CompapiAsynctaskGroupBy{build: caq}
+	grbuild.flds = &caq.ctx.Fields
+	grbuild.label = compapiasynctask.Label
+	grbuild.scan = grbuild.Scan
+	return grbuild
+}
+
+// Select allows the selection one or more fields/columns for the given query,
+// instead of selecting all fields in the entity.
+//
+// Example:
+//
+//	var v []struct {
+//		CreatedAt time.Time `json:"created_at,omitempty"`
+//	}
+//
+//	client.CompapiAsynctask.Query().
+//		Select(compapiasynctask.FieldCreatedAt).
+//		Scan(ctx, &v)
+func (caq *CompapiAsynctaskQuery) Select(fields ...string) *CompapiAsynctaskSelect {
+	caq.ctx.Fields = append(caq.ctx.Fields, fields...)
+	sbuild := &CompapiAsynctaskSelect{CompapiAsynctaskQuery: caq}
+	sbuild.label = compapiasynctask.Label
+	sbuild.flds, sbuild.scan = &caq.ctx.Fields, sbuild.Scan
+	return sbuild
+}
+
+// Aggregate returns a CompapiAsynctaskSelect configured with the given aggregations.
+func (caq *CompapiAsynctaskQuery) Aggregate(fns ...AggregateFunc) *CompapiAsynctaskSelect {
+	return caq.Select().Aggregate(fns...)
+}
+
+func (caq *CompapiAsynctaskQuery) prepareQuery(ctx context.Context) error {
+	for _, inter := range caq.inters {
+		if inter == nil {
+			return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
+		}
+		if trv, ok := inter.(Traverser); ok {
+			if err := trv.Traverse(ctx, caq); err != nil {
+				return err
+			}
+		}
+	}
+	for _, f := range caq.ctx.Fields {
+		if !compapiasynctask.ValidColumn(f) {
+			return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
+		}
+	}
+	if caq.path != nil {
+		prev, err := caq.path(ctx)
+		if err != nil {
+			return err
+		}
+		caq.sql = prev
+	}
+	return nil
+}
+
+func (caq *CompapiAsynctaskQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CompapiAsynctask, error) {
+	var (
+		nodes = []*CompapiAsynctask{}
+		_spec = caq.querySpec()
+	)
+	_spec.ScanValues = func(columns []string) ([]any, error) {
+		return (*CompapiAsynctask).scanValues(nil, columns)
+	}
+	_spec.Assign = func(columns []string, values []any) error {
+		node := &CompapiAsynctask{config: caq.config}
+		nodes = append(nodes, node)
+		return node.assignValues(columns, values)
+	}
+	for i := range hooks {
+		hooks[i](ctx, _spec)
+	}
+	if err := sqlgraph.QueryNodes(ctx, caq.driver, _spec); err != nil {
+		return nil, err
+	}
+	if len(nodes) == 0 {
+		return nodes, nil
+	}
+	return nodes, nil
+}
+
+func (caq *CompapiAsynctaskQuery) sqlCount(ctx context.Context) (int, error) {
+	_spec := caq.querySpec()
+	_spec.Node.Columns = caq.ctx.Fields
+	if len(caq.ctx.Fields) > 0 {
+		_spec.Unique = caq.ctx.Unique != nil && *caq.ctx.Unique
+	}
+	return sqlgraph.CountNodes(ctx, caq.driver, _spec)
+}
+
+func (caq *CompapiAsynctaskQuery) querySpec() *sqlgraph.QuerySpec {
+	_spec := sqlgraph.NewQuerySpec(compapiasynctask.Table, compapiasynctask.Columns, sqlgraph.NewFieldSpec(compapiasynctask.FieldID, field.TypeUint64))
+	_spec.From = caq.sql
+	if unique := caq.ctx.Unique; unique != nil {
+		_spec.Unique = *unique
+	} else if caq.path != nil {
+		_spec.Unique = true
+	}
+	if fields := caq.ctx.Fields; len(fields) > 0 {
+		_spec.Node.Columns = make([]string, 0, len(fields))
+		_spec.Node.Columns = append(_spec.Node.Columns, compapiasynctask.FieldID)
+		for i := range fields {
+			if fields[i] != compapiasynctask.FieldID {
+				_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
+			}
+		}
+	}
+	if ps := caq.predicates; len(ps) > 0 {
+		_spec.Predicate = func(selector *sql.Selector) {
+			for i := range ps {
+				ps[i](selector)
+			}
+		}
+	}
+	if limit := caq.ctx.Limit; limit != nil {
+		_spec.Limit = *limit
+	}
+	if offset := caq.ctx.Offset; offset != nil {
+		_spec.Offset = *offset
+	}
+	if ps := caq.order; len(ps) > 0 {
+		_spec.Order = func(selector *sql.Selector) {
+			for i := range ps {
+				ps[i](selector)
+			}
+		}
+	}
+	return _spec
+}
+
+func (caq *CompapiAsynctaskQuery) sqlQuery(ctx context.Context) *sql.Selector {
+	builder := sql.Dialect(caq.driver.Dialect())
+	t1 := builder.Table(compapiasynctask.Table)
+	columns := caq.ctx.Fields
+	if len(columns) == 0 {
+		columns = compapiasynctask.Columns
+	}
+	selector := builder.Select(t1.Columns(columns...)...).From(t1)
+	if caq.sql != nil {
+		selector = caq.sql
+		selector.Select(selector.Columns(columns...)...)
+	}
+	if caq.ctx.Unique != nil && *caq.ctx.Unique {
+		selector.Distinct()
+	}
+	for _, p := range caq.predicates {
+		p(selector)
+	}
+	for _, p := range caq.order {
+		p(selector)
+	}
+	if offset := caq.ctx.Offset; offset != nil {
+		// limit is mandatory for offset clause. We start
+		// with default value, and override it below if needed.
+		selector.Offset(*offset).Limit(math.MaxInt32)
+	}
+	if limit := caq.ctx.Limit; limit != nil {
+		selector.Limit(*limit)
+	}
+	return selector
+}
+
+// CompapiAsynctaskGroupBy is the group-by builder for CompapiAsynctask entities.
+type CompapiAsynctaskGroupBy struct {
+	selector
+	build *CompapiAsynctaskQuery
+}
+
+// Aggregate adds the given aggregation functions to the group-by query.
+func (cagb *CompapiAsynctaskGroupBy) Aggregate(fns ...AggregateFunc) *CompapiAsynctaskGroupBy {
+	cagb.fns = append(cagb.fns, fns...)
+	return cagb
+}
+
+// Scan applies the selector query and scans the result into the given value.
+func (cagb *CompapiAsynctaskGroupBy) Scan(ctx context.Context, v any) error {
+	ctx = setContextOp(ctx, cagb.build.ctx, "GroupBy")
+	if err := cagb.build.prepareQuery(ctx); err != nil {
+		return err
+	}
+	return scanWithInterceptors[*CompapiAsynctaskQuery, *CompapiAsynctaskGroupBy](ctx, cagb.build, cagb, cagb.build.inters, v)
+}
+
+func (cagb *CompapiAsynctaskGroupBy) sqlScan(ctx context.Context, root *CompapiAsynctaskQuery, v any) error {
+	selector := root.sqlQuery(ctx).Select()
+	aggregation := make([]string, 0, len(cagb.fns))
+	for _, fn := range cagb.fns {
+		aggregation = append(aggregation, fn(selector))
+	}
+	if len(selector.SelectedColumns()) == 0 {
+		columns := make([]string, 0, len(*cagb.flds)+len(cagb.fns))
+		for _, f := range *cagb.flds {
+			columns = append(columns, selector.C(f))
+		}
+		columns = append(columns, aggregation...)
+		selector.Select(columns...)
+	}
+	selector.GroupBy(selector.Columns(*cagb.flds...)...)
+	if err := selector.Err(); err != nil {
+		return err
+	}
+	rows := &sql.Rows{}
+	query, args := selector.Query()
+	if err := cagb.build.driver.Query(ctx, query, args, rows); err != nil {
+		return err
+	}
+	defer rows.Close()
+	return sql.ScanSlice(rows, v)
+}
+
+// CompapiAsynctaskSelect is the builder for selecting fields of CompapiAsynctask entities.
+type CompapiAsynctaskSelect struct {
+	*CompapiAsynctaskQuery
+	selector
+}
+
+// Aggregate adds the given aggregation functions to the selector query.
+func (cas *CompapiAsynctaskSelect) Aggregate(fns ...AggregateFunc) *CompapiAsynctaskSelect {
+	cas.fns = append(cas.fns, fns...)
+	return cas
+}
+
+// Scan applies the selector query and scans the result into the given value.
+func (cas *CompapiAsynctaskSelect) Scan(ctx context.Context, v any) error {
+	ctx = setContextOp(ctx, cas.ctx, "Select")
+	if err := cas.prepareQuery(ctx); err != nil {
+		return err
+	}
+	return scanWithInterceptors[*CompapiAsynctaskQuery, *CompapiAsynctaskSelect](ctx, cas.CompapiAsynctaskQuery, cas, cas.inters, v)
+}
+
+func (cas *CompapiAsynctaskSelect) sqlScan(ctx context.Context, root *CompapiAsynctaskQuery, v any) error {
+	selector := root.sqlQuery(ctx)
+	aggregation := make([]string, 0, len(cas.fns))
+	for _, fn := range cas.fns {
+		aggregation = append(aggregation, fn(selector))
+	}
+	switch n := len(*cas.selector.flds); {
+	case n == 0 && len(aggregation) > 0:
+		selector.Select(aggregation...)
+	case n != 0 && len(aggregation) > 0:
+		selector.AppendSelect(aggregation...)
+	}
+	rows := &sql.Rows{}
+	query, args := selector.Query()
+	if err := cas.driver.Query(ctx, query, args, rows); err != nil {
+		return err
+	}
+	defer rows.Close()
+	return sql.ScanSlice(rows, v)
+}

+ 910 - 0
ent/compapiasynctask_update.go

@@ -0,0 +1,910 @@
+// Code generated by ent, DO NOT EDIT.
+
+package ent
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"time"
+	"wechat-api/ent/compapiasynctask"
+	"wechat-api/ent/predicate"
+
+	"entgo.io/ent/dialect/sql"
+	"entgo.io/ent/dialect/sql/sqlgraph"
+	"entgo.io/ent/schema/field"
+)
+
+// CompapiAsynctaskUpdate is the builder for updating CompapiAsynctask entities.
+type CompapiAsynctaskUpdate struct {
+	config
+	hooks    []Hook
+	mutation *CompapiAsynctaskMutation
+}
+
+// Where appends a list predicates to the CompapiAsynctaskUpdate builder.
+func (cau *CompapiAsynctaskUpdate) Where(ps ...predicate.CompapiAsynctask) *CompapiAsynctaskUpdate {
+	cau.mutation.Where(ps...)
+	return cau
+}
+
+// SetUpdatedAt sets the "updated_at" field.
+func (cau *CompapiAsynctaskUpdate) SetUpdatedAt(t time.Time) *CompapiAsynctaskUpdate {
+	cau.mutation.SetUpdatedAt(t)
+	return cau
+}
+
+// SetAuthToken sets the "auth_token" field.
+func (cau *CompapiAsynctaskUpdate) SetAuthToken(s string) *CompapiAsynctaskUpdate {
+	cau.mutation.SetAuthToken(s)
+	return cau
+}
+
+// SetNillableAuthToken sets the "auth_token" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableAuthToken(s *string) *CompapiAsynctaskUpdate {
+	if s != nil {
+		cau.SetAuthToken(*s)
+	}
+	return cau
+}
+
+// SetEventType sets the "event_type" field.
+func (cau *CompapiAsynctaskUpdate) SetEventType(s string) *CompapiAsynctaskUpdate {
+	cau.mutation.SetEventType(s)
+	return cau
+}
+
+// SetNillableEventType sets the "event_type" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableEventType(s *string) *CompapiAsynctaskUpdate {
+	if s != nil {
+		cau.SetEventType(*s)
+	}
+	return cau
+}
+
+// SetChatID sets the "chat_id" field.
+func (cau *CompapiAsynctaskUpdate) SetChatID(s string) *CompapiAsynctaskUpdate {
+	cau.mutation.SetChatID(s)
+	return cau
+}
+
+// SetNillableChatID sets the "chat_id" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableChatID(s *string) *CompapiAsynctaskUpdate {
+	if s != nil {
+		cau.SetChatID(*s)
+	}
+	return cau
+}
+
+// ClearChatID clears the value of the "chat_id" field.
+func (cau *CompapiAsynctaskUpdate) ClearChatID() *CompapiAsynctaskUpdate {
+	cau.mutation.ClearChatID()
+	return cau
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (cau *CompapiAsynctaskUpdate) SetOrganizationID(u uint64) *CompapiAsynctaskUpdate {
+	cau.mutation.ResetOrganizationID()
+	cau.mutation.SetOrganizationID(u)
+	return cau
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableOrganizationID(u *uint64) *CompapiAsynctaskUpdate {
+	if u != nil {
+		cau.SetOrganizationID(*u)
+	}
+	return cau
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (cau *CompapiAsynctaskUpdate) AddOrganizationID(u int64) *CompapiAsynctaskUpdate {
+	cau.mutation.AddOrganizationID(u)
+	return cau
+}
+
+// SetOpenaiBase sets the "openai_base" field.
+func (cau *CompapiAsynctaskUpdate) SetOpenaiBase(s string) *CompapiAsynctaskUpdate {
+	cau.mutation.SetOpenaiBase(s)
+	return cau
+}
+
+// SetNillableOpenaiBase sets the "openai_base" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableOpenaiBase(s *string) *CompapiAsynctaskUpdate {
+	if s != nil {
+		cau.SetOpenaiBase(*s)
+	}
+	return cau
+}
+
+// SetOpenaiKey sets the "openai_key" field.
+func (cau *CompapiAsynctaskUpdate) SetOpenaiKey(s string) *CompapiAsynctaskUpdate {
+	cau.mutation.SetOpenaiKey(s)
+	return cau
+}
+
+// SetNillableOpenaiKey sets the "openai_key" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableOpenaiKey(s *string) *CompapiAsynctaskUpdate {
+	if s != nil {
+		cau.SetOpenaiKey(*s)
+	}
+	return cau
+}
+
+// SetRequestRaw sets the "request_raw" field.
+func (cau *CompapiAsynctaskUpdate) SetRequestRaw(s string) *CompapiAsynctaskUpdate {
+	cau.mutation.SetRequestRaw(s)
+	return cau
+}
+
+// SetNillableRequestRaw sets the "request_raw" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableRequestRaw(s *string) *CompapiAsynctaskUpdate {
+	if s != nil {
+		cau.SetRequestRaw(*s)
+	}
+	return cau
+}
+
+// SetResponseRaw sets the "response_raw" field.
+func (cau *CompapiAsynctaskUpdate) SetResponseRaw(s string) *CompapiAsynctaskUpdate {
+	cau.mutation.SetResponseRaw(s)
+	return cau
+}
+
+// SetNillableResponseRaw sets the "response_raw" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableResponseRaw(s *string) *CompapiAsynctaskUpdate {
+	if s != nil {
+		cau.SetResponseRaw(*s)
+	}
+	return cau
+}
+
+// ClearResponseRaw clears the value of the "response_raw" field.
+func (cau *CompapiAsynctaskUpdate) ClearResponseRaw() *CompapiAsynctaskUpdate {
+	cau.mutation.ClearResponseRaw()
+	return cau
+}
+
+// SetCallbackURL sets the "callback_url" field.
+func (cau *CompapiAsynctaskUpdate) SetCallbackURL(s string) *CompapiAsynctaskUpdate {
+	cau.mutation.SetCallbackURL(s)
+	return cau
+}
+
+// SetNillableCallbackURL sets the "callback_url" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableCallbackURL(s *string) *CompapiAsynctaskUpdate {
+	if s != nil {
+		cau.SetCallbackURL(*s)
+	}
+	return cau
+}
+
+// SetCallbackResponseRaw sets the "callback_response_raw" field.
+func (cau *CompapiAsynctaskUpdate) SetCallbackResponseRaw(s string) *CompapiAsynctaskUpdate {
+	cau.mutation.SetCallbackResponseRaw(s)
+	return cau
+}
+
+// SetNillableCallbackResponseRaw sets the "callback_response_raw" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableCallbackResponseRaw(s *string) *CompapiAsynctaskUpdate {
+	if s != nil {
+		cau.SetCallbackResponseRaw(*s)
+	}
+	return cau
+}
+
+// ClearCallbackResponseRaw clears the value of the "callback_response_raw" field.
+func (cau *CompapiAsynctaskUpdate) ClearCallbackResponseRaw() *CompapiAsynctaskUpdate {
+	cau.mutation.ClearCallbackResponseRaw()
+	return cau
+}
+
+// SetModel sets the "model" field.
+func (cau *CompapiAsynctaskUpdate) SetModel(s string) *CompapiAsynctaskUpdate {
+	cau.mutation.SetModel(s)
+	return cau
+}
+
+// SetNillableModel sets the "model" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableModel(s *string) *CompapiAsynctaskUpdate {
+	if s != nil {
+		cau.SetModel(*s)
+	}
+	return cau
+}
+
+// ClearModel clears the value of the "model" field.
+func (cau *CompapiAsynctaskUpdate) ClearModel() *CompapiAsynctaskUpdate {
+	cau.mutation.ClearModel()
+	return cau
+}
+
+// SetTaskStatus sets the "task_status" field.
+func (cau *CompapiAsynctaskUpdate) SetTaskStatus(i int8) *CompapiAsynctaskUpdate {
+	cau.mutation.ResetTaskStatus()
+	cau.mutation.SetTaskStatus(i)
+	return cau
+}
+
+// SetNillableTaskStatus sets the "task_status" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableTaskStatus(i *int8) *CompapiAsynctaskUpdate {
+	if i != nil {
+		cau.SetTaskStatus(*i)
+	}
+	return cau
+}
+
+// AddTaskStatus adds i to the "task_status" field.
+func (cau *CompapiAsynctaskUpdate) AddTaskStatus(i int8) *CompapiAsynctaskUpdate {
+	cau.mutation.AddTaskStatus(i)
+	return cau
+}
+
+// ClearTaskStatus clears the value of the "task_status" field.
+func (cau *CompapiAsynctaskUpdate) ClearTaskStatus() *CompapiAsynctaskUpdate {
+	cau.mutation.ClearTaskStatus()
+	return cau
+}
+
+// SetRetryCount sets the "retry_count" field.
+func (cau *CompapiAsynctaskUpdate) SetRetryCount(i int8) *CompapiAsynctaskUpdate {
+	cau.mutation.ResetRetryCount()
+	cau.mutation.SetRetryCount(i)
+	return cau
+}
+
+// SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableRetryCount(i *int8) *CompapiAsynctaskUpdate {
+	if i != nil {
+		cau.SetRetryCount(*i)
+	}
+	return cau
+}
+
+// AddRetryCount adds i to the "retry_count" field.
+func (cau *CompapiAsynctaskUpdate) AddRetryCount(i int8) *CompapiAsynctaskUpdate {
+	cau.mutation.AddRetryCount(i)
+	return cau
+}
+
+// ClearRetryCount clears the value of the "retry_count" field.
+func (cau *CompapiAsynctaskUpdate) ClearRetryCount() *CompapiAsynctaskUpdate {
+	cau.mutation.ClearRetryCount()
+	return cau
+}
+
+// SetLastError sets the "last_error" field.
+func (cau *CompapiAsynctaskUpdate) SetLastError(s string) *CompapiAsynctaskUpdate {
+	cau.mutation.SetLastError(s)
+	return cau
+}
+
+// SetNillableLastError sets the "last_error" field if the given value is not nil.
+func (cau *CompapiAsynctaskUpdate) SetNillableLastError(s *string) *CompapiAsynctaskUpdate {
+	if s != nil {
+		cau.SetLastError(*s)
+	}
+	return cau
+}
+
+// ClearLastError clears the value of the "last_error" field.
+func (cau *CompapiAsynctaskUpdate) ClearLastError() *CompapiAsynctaskUpdate {
+	cau.mutation.ClearLastError()
+	return cau
+}
+
+// Mutation returns the CompapiAsynctaskMutation object of the builder.
+func (cau *CompapiAsynctaskUpdate) Mutation() *CompapiAsynctaskMutation {
+	return cau.mutation
+}
+
+// Save executes the query and returns the number of nodes affected by the update operation.
+func (cau *CompapiAsynctaskUpdate) Save(ctx context.Context) (int, error) {
+	cau.defaults()
+	return withHooks(ctx, cau.sqlSave, cau.mutation, cau.hooks)
+}
+
+// SaveX is like Save, but panics if an error occurs.
+func (cau *CompapiAsynctaskUpdate) SaveX(ctx context.Context) int {
+	affected, err := cau.Save(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return affected
+}
+
+// Exec executes the query.
+func (cau *CompapiAsynctaskUpdate) Exec(ctx context.Context) error {
+	_, err := cau.Save(ctx)
+	return err
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (cau *CompapiAsynctaskUpdate) ExecX(ctx context.Context) {
+	if err := cau.Exec(ctx); err != nil {
+		panic(err)
+	}
+}
+
+// defaults sets the default values of the builder before save.
+func (cau *CompapiAsynctaskUpdate) defaults() {
+	if _, ok := cau.mutation.UpdatedAt(); !ok {
+		v := compapiasynctask.UpdateDefaultUpdatedAt()
+		cau.mutation.SetUpdatedAt(v)
+	}
+}
+
+// check runs all checks and user-defined validators on the builder.
+func (cau *CompapiAsynctaskUpdate) check() error {
+	if v, ok := cau.mutation.OrganizationID(); ok {
+		if err := compapiasynctask.OrganizationIDValidator(v); err != nil {
+			return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.organization_id": %w`, err)}
+		}
+	}
+	if v, ok := cau.mutation.CallbackURL(); ok {
+		if err := compapiasynctask.CallbackURLValidator(v); err != nil {
+			return &ValidationError{Name: "callback_url", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.callback_url": %w`, err)}
+		}
+	}
+	return nil
+}
+
+func (cau *CompapiAsynctaskUpdate) sqlSave(ctx context.Context) (n int, err error) {
+	if err := cau.check(); err != nil {
+		return n, err
+	}
+	_spec := sqlgraph.NewUpdateSpec(compapiasynctask.Table, compapiasynctask.Columns, sqlgraph.NewFieldSpec(compapiasynctask.FieldID, field.TypeUint64))
+	if ps := cau.mutation.predicates; len(ps) > 0 {
+		_spec.Predicate = func(selector *sql.Selector) {
+			for i := range ps {
+				ps[i](selector)
+			}
+		}
+	}
+	if value, ok := cau.mutation.UpdatedAt(); ok {
+		_spec.SetField(compapiasynctask.FieldUpdatedAt, field.TypeTime, value)
+	}
+	if value, ok := cau.mutation.AuthToken(); ok {
+		_spec.SetField(compapiasynctask.FieldAuthToken, field.TypeString, value)
+	}
+	if value, ok := cau.mutation.EventType(); ok {
+		_spec.SetField(compapiasynctask.FieldEventType, field.TypeString, value)
+	}
+	if value, ok := cau.mutation.ChatID(); ok {
+		_spec.SetField(compapiasynctask.FieldChatID, field.TypeString, value)
+	}
+	if cau.mutation.ChatIDCleared() {
+		_spec.ClearField(compapiasynctask.FieldChatID, field.TypeString)
+	}
+	if value, ok := cau.mutation.OrganizationID(); ok {
+		_spec.SetField(compapiasynctask.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := cau.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(compapiasynctask.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := cau.mutation.OpenaiBase(); ok {
+		_spec.SetField(compapiasynctask.FieldOpenaiBase, field.TypeString, value)
+	}
+	if value, ok := cau.mutation.OpenaiKey(); ok {
+		_spec.SetField(compapiasynctask.FieldOpenaiKey, field.TypeString, value)
+	}
+	if value, ok := cau.mutation.RequestRaw(); ok {
+		_spec.SetField(compapiasynctask.FieldRequestRaw, field.TypeString, value)
+	}
+	if value, ok := cau.mutation.ResponseRaw(); ok {
+		_spec.SetField(compapiasynctask.FieldResponseRaw, field.TypeString, value)
+	}
+	if cau.mutation.ResponseRawCleared() {
+		_spec.ClearField(compapiasynctask.FieldResponseRaw, field.TypeString)
+	}
+	if value, ok := cau.mutation.CallbackURL(); ok {
+		_spec.SetField(compapiasynctask.FieldCallbackURL, field.TypeString, value)
+	}
+	if value, ok := cau.mutation.CallbackResponseRaw(); ok {
+		_spec.SetField(compapiasynctask.FieldCallbackResponseRaw, field.TypeString, value)
+	}
+	if cau.mutation.CallbackResponseRawCleared() {
+		_spec.ClearField(compapiasynctask.FieldCallbackResponseRaw, field.TypeString)
+	}
+	if value, ok := cau.mutation.Model(); ok {
+		_spec.SetField(compapiasynctask.FieldModel, field.TypeString, value)
+	}
+	if cau.mutation.ModelCleared() {
+		_spec.ClearField(compapiasynctask.FieldModel, field.TypeString)
+	}
+	if value, ok := cau.mutation.TaskStatus(); ok {
+		_spec.SetField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
+	}
+	if value, ok := cau.mutation.AddedTaskStatus(); ok {
+		_spec.AddField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
+	}
+	if cau.mutation.TaskStatusCleared() {
+		_spec.ClearField(compapiasynctask.FieldTaskStatus, field.TypeInt8)
+	}
+	if value, ok := cau.mutation.RetryCount(); ok {
+		_spec.SetField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
+	}
+	if value, ok := cau.mutation.AddedRetryCount(); ok {
+		_spec.AddField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
+	}
+	if cau.mutation.RetryCountCleared() {
+		_spec.ClearField(compapiasynctask.FieldRetryCount, field.TypeInt8)
+	}
+	if value, ok := cau.mutation.LastError(); ok {
+		_spec.SetField(compapiasynctask.FieldLastError, field.TypeString, value)
+	}
+	if cau.mutation.LastErrorCleared() {
+		_spec.ClearField(compapiasynctask.FieldLastError, field.TypeString)
+	}
+	if n, err = sqlgraph.UpdateNodes(ctx, cau.driver, _spec); err != nil {
+		if _, ok := err.(*sqlgraph.NotFoundError); ok {
+			err = &NotFoundError{compapiasynctask.Label}
+		} else if sqlgraph.IsConstraintError(err) {
+			err = &ConstraintError{msg: err.Error(), wrap: err}
+		}
+		return 0, err
+	}
+	cau.mutation.done = true
+	return n, nil
+}
+
+// CompapiAsynctaskUpdateOne is the builder for updating a single CompapiAsynctask entity.
+type CompapiAsynctaskUpdateOne struct {
+	config
+	fields   []string
+	hooks    []Hook
+	mutation *CompapiAsynctaskMutation
+}
+
+// SetUpdatedAt sets the "updated_at" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetUpdatedAt(t time.Time) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.SetUpdatedAt(t)
+	return cauo
+}
+
+// SetAuthToken sets the "auth_token" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetAuthToken(s string) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.SetAuthToken(s)
+	return cauo
+}
+
+// SetNillableAuthToken sets the "auth_token" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableAuthToken(s *string) *CompapiAsynctaskUpdateOne {
+	if s != nil {
+		cauo.SetAuthToken(*s)
+	}
+	return cauo
+}
+
+// SetEventType sets the "event_type" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetEventType(s string) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.SetEventType(s)
+	return cauo
+}
+
+// SetNillableEventType sets the "event_type" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableEventType(s *string) *CompapiAsynctaskUpdateOne {
+	if s != nil {
+		cauo.SetEventType(*s)
+	}
+	return cauo
+}
+
+// SetChatID sets the "chat_id" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetChatID(s string) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.SetChatID(s)
+	return cauo
+}
+
+// SetNillableChatID sets the "chat_id" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableChatID(s *string) *CompapiAsynctaskUpdateOne {
+	if s != nil {
+		cauo.SetChatID(*s)
+	}
+	return cauo
+}
+
+// ClearChatID clears the value of the "chat_id" field.
+func (cauo *CompapiAsynctaskUpdateOne) ClearChatID() *CompapiAsynctaskUpdateOne {
+	cauo.mutation.ClearChatID()
+	return cauo
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetOrganizationID(u uint64) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.ResetOrganizationID()
+	cauo.mutation.SetOrganizationID(u)
+	return cauo
+}
+
+// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableOrganizationID(u *uint64) *CompapiAsynctaskUpdateOne {
+	if u != nil {
+		cauo.SetOrganizationID(*u)
+	}
+	return cauo
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (cauo *CompapiAsynctaskUpdateOne) AddOrganizationID(u int64) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.AddOrganizationID(u)
+	return cauo
+}
+
+// SetOpenaiBase sets the "openai_base" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetOpenaiBase(s string) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.SetOpenaiBase(s)
+	return cauo
+}
+
+// SetNillableOpenaiBase sets the "openai_base" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableOpenaiBase(s *string) *CompapiAsynctaskUpdateOne {
+	if s != nil {
+		cauo.SetOpenaiBase(*s)
+	}
+	return cauo
+}
+
+// SetOpenaiKey sets the "openai_key" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetOpenaiKey(s string) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.SetOpenaiKey(s)
+	return cauo
+}
+
+// SetNillableOpenaiKey sets the "openai_key" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableOpenaiKey(s *string) *CompapiAsynctaskUpdateOne {
+	if s != nil {
+		cauo.SetOpenaiKey(*s)
+	}
+	return cauo
+}
+
+// SetRequestRaw sets the "request_raw" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetRequestRaw(s string) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.SetRequestRaw(s)
+	return cauo
+}
+
+// SetNillableRequestRaw sets the "request_raw" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableRequestRaw(s *string) *CompapiAsynctaskUpdateOne {
+	if s != nil {
+		cauo.SetRequestRaw(*s)
+	}
+	return cauo
+}
+
+// SetResponseRaw sets the "response_raw" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetResponseRaw(s string) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.SetResponseRaw(s)
+	return cauo
+}
+
+// SetNillableResponseRaw sets the "response_raw" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableResponseRaw(s *string) *CompapiAsynctaskUpdateOne {
+	if s != nil {
+		cauo.SetResponseRaw(*s)
+	}
+	return cauo
+}
+
+// ClearResponseRaw clears the value of the "response_raw" field.
+func (cauo *CompapiAsynctaskUpdateOne) ClearResponseRaw() *CompapiAsynctaskUpdateOne {
+	cauo.mutation.ClearResponseRaw()
+	return cauo
+}
+
+// SetCallbackURL sets the "callback_url" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetCallbackURL(s string) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.SetCallbackURL(s)
+	return cauo
+}
+
+// SetNillableCallbackURL sets the "callback_url" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableCallbackURL(s *string) *CompapiAsynctaskUpdateOne {
+	if s != nil {
+		cauo.SetCallbackURL(*s)
+	}
+	return cauo
+}
+
+// SetCallbackResponseRaw sets the "callback_response_raw" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetCallbackResponseRaw(s string) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.SetCallbackResponseRaw(s)
+	return cauo
+}
+
+// SetNillableCallbackResponseRaw sets the "callback_response_raw" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableCallbackResponseRaw(s *string) *CompapiAsynctaskUpdateOne {
+	if s != nil {
+		cauo.SetCallbackResponseRaw(*s)
+	}
+	return cauo
+}
+
+// ClearCallbackResponseRaw clears the value of the "callback_response_raw" field.
+func (cauo *CompapiAsynctaskUpdateOne) ClearCallbackResponseRaw() *CompapiAsynctaskUpdateOne {
+	cauo.mutation.ClearCallbackResponseRaw()
+	return cauo
+}
+
+// SetModel sets the "model" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetModel(s string) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.SetModel(s)
+	return cauo
+}
+
+// SetNillableModel sets the "model" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableModel(s *string) *CompapiAsynctaskUpdateOne {
+	if s != nil {
+		cauo.SetModel(*s)
+	}
+	return cauo
+}
+
+// ClearModel clears the value of the "model" field.
+func (cauo *CompapiAsynctaskUpdateOne) ClearModel() *CompapiAsynctaskUpdateOne {
+	cauo.mutation.ClearModel()
+	return cauo
+}
+
+// SetTaskStatus sets the "task_status" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetTaskStatus(i int8) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.ResetTaskStatus()
+	cauo.mutation.SetTaskStatus(i)
+	return cauo
+}
+
+// SetNillableTaskStatus sets the "task_status" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableTaskStatus(i *int8) *CompapiAsynctaskUpdateOne {
+	if i != nil {
+		cauo.SetTaskStatus(*i)
+	}
+	return cauo
+}
+
+// AddTaskStatus adds i to the "task_status" field.
+func (cauo *CompapiAsynctaskUpdateOne) AddTaskStatus(i int8) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.AddTaskStatus(i)
+	return cauo
+}
+
+// ClearTaskStatus clears the value of the "task_status" field.
+func (cauo *CompapiAsynctaskUpdateOne) ClearTaskStatus() *CompapiAsynctaskUpdateOne {
+	cauo.mutation.ClearTaskStatus()
+	return cauo
+}
+
+// SetRetryCount sets the "retry_count" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetRetryCount(i int8) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.ResetRetryCount()
+	cauo.mutation.SetRetryCount(i)
+	return cauo
+}
+
+// SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableRetryCount(i *int8) *CompapiAsynctaskUpdateOne {
+	if i != nil {
+		cauo.SetRetryCount(*i)
+	}
+	return cauo
+}
+
+// AddRetryCount adds i to the "retry_count" field.
+func (cauo *CompapiAsynctaskUpdateOne) AddRetryCount(i int8) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.AddRetryCount(i)
+	return cauo
+}
+
+// ClearRetryCount clears the value of the "retry_count" field.
+func (cauo *CompapiAsynctaskUpdateOne) ClearRetryCount() *CompapiAsynctaskUpdateOne {
+	cauo.mutation.ClearRetryCount()
+	return cauo
+}
+
+// SetLastError sets the "last_error" field.
+func (cauo *CompapiAsynctaskUpdateOne) SetLastError(s string) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.SetLastError(s)
+	return cauo
+}
+
+// SetNillableLastError sets the "last_error" field if the given value is not nil.
+func (cauo *CompapiAsynctaskUpdateOne) SetNillableLastError(s *string) *CompapiAsynctaskUpdateOne {
+	if s != nil {
+		cauo.SetLastError(*s)
+	}
+	return cauo
+}
+
+// ClearLastError clears the value of the "last_error" field.
+func (cauo *CompapiAsynctaskUpdateOne) ClearLastError() *CompapiAsynctaskUpdateOne {
+	cauo.mutation.ClearLastError()
+	return cauo
+}
+
+// Mutation returns the CompapiAsynctaskMutation object of the builder.
+func (cauo *CompapiAsynctaskUpdateOne) Mutation() *CompapiAsynctaskMutation {
+	return cauo.mutation
+}
+
+// Where appends a list predicates to the CompapiAsynctaskUpdate builder.
+func (cauo *CompapiAsynctaskUpdateOne) Where(ps ...predicate.CompapiAsynctask) *CompapiAsynctaskUpdateOne {
+	cauo.mutation.Where(ps...)
+	return cauo
+}
+
+// Select allows selecting one or more fields (columns) of the returned entity.
+// The default is selecting all fields defined in the entity schema.
+func (cauo *CompapiAsynctaskUpdateOne) Select(field string, fields ...string) *CompapiAsynctaskUpdateOne {
+	cauo.fields = append([]string{field}, fields...)
+	return cauo
+}
+
+// Save executes the query and returns the updated CompapiAsynctask entity.
+func (cauo *CompapiAsynctaskUpdateOne) Save(ctx context.Context) (*CompapiAsynctask, error) {
+	cauo.defaults()
+	return withHooks(ctx, cauo.sqlSave, cauo.mutation, cauo.hooks)
+}
+
+// SaveX is like Save, but panics if an error occurs.
+func (cauo *CompapiAsynctaskUpdateOne) SaveX(ctx context.Context) *CompapiAsynctask {
+	node, err := cauo.Save(ctx)
+	if err != nil {
+		panic(err)
+	}
+	return node
+}
+
+// Exec executes the query on the entity.
+func (cauo *CompapiAsynctaskUpdateOne) Exec(ctx context.Context) error {
+	_, err := cauo.Save(ctx)
+	return err
+}
+
+// ExecX is like Exec, but panics if an error occurs.
+func (cauo *CompapiAsynctaskUpdateOne) ExecX(ctx context.Context) {
+	if err := cauo.Exec(ctx); err != nil {
+		panic(err)
+	}
+}
+
+// defaults sets the default values of the builder before save.
+func (cauo *CompapiAsynctaskUpdateOne) defaults() {
+	if _, ok := cauo.mutation.UpdatedAt(); !ok {
+		v := compapiasynctask.UpdateDefaultUpdatedAt()
+		cauo.mutation.SetUpdatedAt(v)
+	}
+}
+
+// check runs all checks and user-defined validators on the builder.
+func (cauo *CompapiAsynctaskUpdateOne) check() error {
+	if v, ok := cauo.mutation.OrganizationID(); ok {
+		if err := compapiasynctask.OrganizationIDValidator(v); err != nil {
+			return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.organization_id": %w`, err)}
+		}
+	}
+	if v, ok := cauo.mutation.CallbackURL(); ok {
+		if err := compapiasynctask.CallbackURLValidator(v); err != nil {
+			return &ValidationError{Name: "callback_url", err: fmt.Errorf(`ent: validator failed for field "CompapiAsynctask.callback_url": %w`, err)}
+		}
+	}
+	return nil
+}
+
+func (cauo *CompapiAsynctaskUpdateOne) sqlSave(ctx context.Context) (_node *CompapiAsynctask, err error) {
+	if err := cauo.check(); err != nil {
+		return _node, err
+	}
+	_spec := sqlgraph.NewUpdateSpec(compapiasynctask.Table, compapiasynctask.Columns, sqlgraph.NewFieldSpec(compapiasynctask.FieldID, field.TypeUint64))
+	id, ok := cauo.mutation.ID()
+	if !ok {
+		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "CompapiAsynctask.id" for update`)}
+	}
+	_spec.Node.ID.Value = id
+	if fields := cauo.fields; len(fields) > 0 {
+		_spec.Node.Columns = make([]string, 0, len(fields))
+		_spec.Node.Columns = append(_spec.Node.Columns, compapiasynctask.FieldID)
+		for _, f := range fields {
+			if !compapiasynctask.ValidColumn(f) {
+				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
+			}
+			if f != compapiasynctask.FieldID {
+				_spec.Node.Columns = append(_spec.Node.Columns, f)
+			}
+		}
+	}
+	if ps := cauo.mutation.predicates; len(ps) > 0 {
+		_spec.Predicate = func(selector *sql.Selector) {
+			for i := range ps {
+				ps[i](selector)
+			}
+		}
+	}
+	if value, ok := cauo.mutation.UpdatedAt(); ok {
+		_spec.SetField(compapiasynctask.FieldUpdatedAt, field.TypeTime, value)
+	}
+	if value, ok := cauo.mutation.AuthToken(); ok {
+		_spec.SetField(compapiasynctask.FieldAuthToken, field.TypeString, value)
+	}
+	if value, ok := cauo.mutation.EventType(); ok {
+		_spec.SetField(compapiasynctask.FieldEventType, field.TypeString, value)
+	}
+	if value, ok := cauo.mutation.ChatID(); ok {
+		_spec.SetField(compapiasynctask.FieldChatID, field.TypeString, value)
+	}
+	if cauo.mutation.ChatIDCleared() {
+		_spec.ClearField(compapiasynctask.FieldChatID, field.TypeString)
+	}
+	if value, ok := cauo.mutation.OrganizationID(); ok {
+		_spec.SetField(compapiasynctask.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := cauo.mutation.AddedOrganizationID(); ok {
+		_spec.AddField(compapiasynctask.FieldOrganizationID, field.TypeUint64, value)
+	}
+	if value, ok := cauo.mutation.OpenaiBase(); ok {
+		_spec.SetField(compapiasynctask.FieldOpenaiBase, field.TypeString, value)
+	}
+	if value, ok := cauo.mutation.OpenaiKey(); ok {
+		_spec.SetField(compapiasynctask.FieldOpenaiKey, field.TypeString, value)
+	}
+	if value, ok := cauo.mutation.RequestRaw(); ok {
+		_spec.SetField(compapiasynctask.FieldRequestRaw, field.TypeString, value)
+	}
+	if value, ok := cauo.mutation.ResponseRaw(); ok {
+		_spec.SetField(compapiasynctask.FieldResponseRaw, field.TypeString, value)
+	}
+	if cauo.mutation.ResponseRawCleared() {
+		_spec.ClearField(compapiasynctask.FieldResponseRaw, field.TypeString)
+	}
+	if value, ok := cauo.mutation.CallbackURL(); ok {
+		_spec.SetField(compapiasynctask.FieldCallbackURL, field.TypeString, value)
+	}
+	if value, ok := cauo.mutation.CallbackResponseRaw(); ok {
+		_spec.SetField(compapiasynctask.FieldCallbackResponseRaw, field.TypeString, value)
+	}
+	if cauo.mutation.CallbackResponseRawCleared() {
+		_spec.ClearField(compapiasynctask.FieldCallbackResponseRaw, field.TypeString)
+	}
+	if value, ok := cauo.mutation.Model(); ok {
+		_spec.SetField(compapiasynctask.FieldModel, field.TypeString, value)
+	}
+	if cauo.mutation.ModelCleared() {
+		_spec.ClearField(compapiasynctask.FieldModel, field.TypeString)
+	}
+	if value, ok := cauo.mutation.TaskStatus(); ok {
+		_spec.SetField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
+	}
+	if value, ok := cauo.mutation.AddedTaskStatus(); ok {
+		_spec.AddField(compapiasynctask.FieldTaskStatus, field.TypeInt8, value)
+	}
+	if cauo.mutation.TaskStatusCleared() {
+		_spec.ClearField(compapiasynctask.FieldTaskStatus, field.TypeInt8)
+	}
+	if value, ok := cauo.mutation.RetryCount(); ok {
+		_spec.SetField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
+	}
+	if value, ok := cauo.mutation.AddedRetryCount(); ok {
+		_spec.AddField(compapiasynctask.FieldRetryCount, field.TypeInt8, value)
+	}
+	if cauo.mutation.RetryCountCleared() {
+		_spec.ClearField(compapiasynctask.FieldRetryCount, field.TypeInt8)
+	}
+	if value, ok := cauo.mutation.LastError(); ok {
+		_spec.SetField(compapiasynctask.FieldLastError, field.TypeString, value)
+	}
+	if cauo.mutation.LastErrorCleared() {
+		_spec.ClearField(compapiasynctask.FieldLastError, field.TypeString)
+	}
+	_node = &CompapiAsynctask{config: cauo.config}
+	_spec.Assign = _node.assignValues
+	_spec.ScanValues = _node.scanValues
+	if err = sqlgraph.UpdateNode(ctx, cauo.driver, _spec); err != nil {
+		if _, ok := err.(*sqlgraph.NotFoundError); ok {
+			err = &NotFoundError{compapiasynctask.Label}
+		} else if sqlgraph.IsConstraintError(err) {
+			err = &ConstraintError{msg: err.Error(), wrap: err}
+		}
+		return nil, err
+	}
+	cauo.mutation.done = true
+	return _node, nil
+}

+ 2 - 0
ent/ent.go

@@ -17,6 +17,7 @@ import (
 	"wechat-api/ent/category"
 	"wechat-api/ent/chatrecords"
 	"wechat-api/ent/chatsession"
+	"wechat-api/ent/compapiasynctask"
 	"wechat-api/ent/contact"
 	"wechat-api/ent/creditbalance"
 	"wechat-api/ent/creditusage"
@@ -122,6 +123,7 @@ func checkColumn(table, column string) error {
 			category.Table:            category.ValidColumn,
 			chatrecords.Table:         chatrecords.ValidColumn,
 			chatsession.Table:         chatsession.ValidColumn,
+			compapiasynctask.Table:    compapiasynctask.ValidColumn,
 			contact.Table:             contact.ValidColumn,
 			creditbalance.Table:       creditbalance.ValidColumn,
 			creditusage.Table:         creditusage.ValidColumn,

+ 12 - 0
ent/hook/hook.go

@@ -116,6 +116,18 @@ func (f ChatSessionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value,
 	return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ChatSessionMutation", m)
 }
 
+// The CompapiAsynctaskFunc type is an adapter to allow the use of ordinary
+// function as CompapiAsynctask mutator.
+type CompapiAsynctaskFunc func(context.Context, *ent.CompapiAsynctaskMutation) (ent.Value, error)
+
+// Mutate calls f(ctx, m).
+func (f CompapiAsynctaskFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
+	if mv, ok := m.(*ent.CompapiAsynctaskMutation); ok {
+		return f(ctx, mv)
+	}
+	return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CompapiAsynctaskMutation", m)
+}
+
 // The ContactFunc type is an adapter to allow the use of ordinary
 // function as Contact mutator.
 type ContactFunc func(context.Context, *ent.ContactMutation) (ent.Value, error)

+ 30 - 0
ent/intercept/intercept.go

@@ -15,6 +15,7 @@ import (
 	"wechat-api/ent/category"
 	"wechat-api/ent/chatrecords"
 	"wechat-api/ent/chatsession"
+	"wechat-api/ent/compapiasynctask"
 	"wechat-api/ent/contact"
 	"wechat-api/ent/creditbalance"
 	"wechat-api/ent/creditusage"
@@ -351,6 +352,33 @@ func (f TraverseChatSession) Traverse(ctx context.Context, q ent.Query) error {
 	return fmt.Errorf("unexpected query type %T. expect *ent.ChatSessionQuery", q)
 }
 
+// The CompapiAsynctaskFunc type is an adapter to allow the use of ordinary function as a Querier.
+type CompapiAsynctaskFunc func(context.Context, *ent.CompapiAsynctaskQuery) (ent.Value, error)
+
+// Query calls f(ctx, q).
+func (f CompapiAsynctaskFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
+	if q, ok := q.(*ent.CompapiAsynctaskQuery); ok {
+		return f(ctx, q)
+	}
+	return nil, fmt.Errorf("unexpected query type %T. expect *ent.CompapiAsynctaskQuery", q)
+}
+
+// The TraverseCompapiAsynctask type is an adapter to allow the use of ordinary function as Traverser.
+type TraverseCompapiAsynctask func(context.Context, *ent.CompapiAsynctaskQuery) error
+
+// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
+func (f TraverseCompapiAsynctask) Intercept(next ent.Querier) ent.Querier {
+	return next
+}
+
+// Traverse calls f(ctx, q).
+func (f TraverseCompapiAsynctask) Traverse(ctx context.Context, q ent.Query) error {
+	if q, ok := q.(*ent.CompapiAsynctaskQuery); ok {
+		return f(ctx, q)
+	}
+	return fmt.Errorf("unexpected query type %T. expect *ent.CompapiAsynctaskQuery", q)
+}
+
 // The ContactFunc type is an adapter to allow the use of ordinary function as a Querier.
 type ContactFunc func(context.Context, *ent.ContactQuery) (ent.Value, error)
 
@@ -1236,6 +1264,8 @@ func NewQuery(q ent.Query) (Query, error) {
 		return &query[*ent.ChatRecordsQuery, predicate.ChatRecords, chatrecords.OrderOption]{typ: ent.TypeChatRecords, tq: q}, nil
 	case *ent.ChatSessionQuery:
 		return &query[*ent.ChatSessionQuery, predicate.ChatSession, chatsession.OrderOption]{typ: ent.TypeChatSession, tq: q}, nil
+	case *ent.CompapiAsynctaskQuery:
+		return &query[*ent.CompapiAsynctaskQuery, predicate.CompapiAsynctask, compapiasynctask.OrderOption]{typ: ent.TypeCompapiAsynctask, tq: q}, nil
 	case *ent.ContactQuery:
 		return &query[*ent.ContactQuery, predicate.Contact, contact.OrderOption]{typ: ent.TypeContact, tq: q}, nil
 	case *ent.CreditBalanceQuery:

+ 37 - 0
ent/migrate/schema.go

@@ -277,6 +277,39 @@ var (
 			},
 		},
 	}
+	// CompapiAsynctaskColumns holds the columns for the "compapi_asynctask" table.
+	CompapiAsynctaskColumns = []*schema.Column{
+		{Name: "id", Type: field.TypeUint64, Increment: true},
+		{Name: "created_at", Type: field.TypeTime, Comment: "Create Time | 创建日期"},
+		{Name: "updated_at", Type: field.TypeTime, Comment: "Update Time | 修改日期"},
+		{Name: "auth_token", Type: field.TypeString, Comment: "发起请求者的授权token"},
+		{Name: "event_type", Type: field.TypeString, Comment: "请求目标类型", Default: "fastgpt"},
+		{Name: "chat_id", Type: field.TypeString, Nullable: true, Comment: "会话ID", Default: ""},
+		{Name: "organization_id", Type: field.TypeUint64, Comment: "organization_id | 租户ID"},
+		{Name: "openai_base", Type: field.TypeString, Comment: "待请求的大模型服务地址"},
+		{Name: "openai_key", Type: field.TypeString, Comment: "待请求的大模型服务密钥授权token"},
+		{Name: "request_raw", Type: field.TypeString, Comment: "请求参数结构字符串"},
+		{Name: "response_raw", Type: field.TypeString, Nullable: true, Comment: "请求响应结构字符串", Default: ""},
+		{Name: "callback_url", Type: field.TypeString, Size: 255, Comment: "callback_url | 异步执行回调地址"},
+		{Name: "callback_response_raw", Type: field.TypeString, Nullable: true, Comment: "callback返回结构字符串", Default: ""},
+		{Name: "model", Type: field.TypeString, Nullable: true, Comment: "所用大模型", Default: ""},
+		{Name: "task_status", Type: field.TypeInt8, Nullable: true, Comment: "callback_status | 任务完成状态 10 任务就绪 20 请求API完成 30 请求回调完成 60 任务暂停 70 任务失败", Default: 10},
+		{Name: "retry_count", Type: field.TypeInt8, Nullable: true, Comment: "retry count | 重试次数", Default: 0},
+		{Name: "last_error", Type: field.TypeString, Nullable: true, Comment: "最后一次出错信息", Default: ""},
+	}
+	// CompapiAsynctaskTable holds the schema information for the "compapi_asynctask" table.
+	CompapiAsynctaskTable = &schema.Table{
+		Name:       "compapi_asynctask",
+		Columns:    CompapiAsynctaskColumns,
+		PrimaryKey: []*schema.Column{CompapiAsynctaskColumns[0]},
+		Indexes: []*schema.Index{
+			{
+				Name:    "compapiasynctask_task_status",
+				Unique:  false,
+				Columns: []*schema.Column{CompapiAsynctaskColumns[14]},
+			},
+		},
+	}
 	// ContactColumns holds the columns for the "contact" table.
 	ContactColumns = []*schema.Column{
 		{Name: "id", Type: field.TypeUint64, Increment: true},
@@ -1427,6 +1460,7 @@ var (
 		CategoryTable,
 		ChatRecordsTable,
 		ChatSessionTable,
+		CompapiAsynctaskTable,
 		ContactTable,
 		CreditBalanceTable,
 		CreditUsageTable,
@@ -1491,6 +1525,9 @@ func init() {
 	ChatSessionTable.Annotation = &entsql.Annotation{
 		Table: "chat_session",
 	}
+	CompapiAsynctaskTable.Annotation = &entsql.Annotation{
+		Table: "compapi_asynctask",
+	}
 	ContactTable.Annotation = &entsql.Annotation{
 		Table: "contact",
 	}

+ 1384 - 0
ent/mutation.go

@@ -17,6 +17,7 @@ import (
 	"wechat-api/ent/category"
 	"wechat-api/ent/chatrecords"
 	"wechat-api/ent/chatsession"
+	"wechat-api/ent/compapiasynctask"
 	"wechat-api/ent/contact"
 	"wechat-api/ent/creditbalance"
 	"wechat-api/ent/creditusage"
@@ -74,6 +75,7 @@ const (
 	TypeCategory            = "Category"
 	TypeChatRecords         = "ChatRecords"
 	TypeChatSession         = "ChatSession"
+	TypeCompapiAsynctask    = "CompapiAsynctask"
 	TypeContact             = "Contact"
 	TypeCreditBalance       = "CreditBalance"
 	TypeCreditUsage         = "CreditUsage"
@@ -10407,6 +10409,1388 @@ func (m *ChatSessionMutation) ResetEdge(name string) error {
 	return fmt.Errorf("unknown ChatSession edge %s", name)
 }
 
+// CompapiAsynctaskMutation represents an operation that mutates the CompapiAsynctask nodes in the graph.
+type CompapiAsynctaskMutation struct {
+	config
+	op                    Op
+	typ                   string
+	id                    *uint64
+	created_at            *time.Time
+	updated_at            *time.Time
+	auth_token            *string
+	event_type            *string
+	chat_id               *string
+	organization_id       *uint64
+	addorganization_id    *int64
+	openai_base           *string
+	openai_key            *string
+	request_raw           *string
+	response_raw          *string
+	callback_url          *string
+	callback_response_raw *string
+	model                 *string
+	task_status           *int8
+	addtask_status        *int8
+	retry_count           *int8
+	addretry_count        *int8
+	last_error            *string
+	clearedFields         map[string]struct{}
+	done                  bool
+	oldValue              func(context.Context) (*CompapiAsynctask, error)
+	predicates            []predicate.CompapiAsynctask
+}
+
+var _ ent.Mutation = (*CompapiAsynctaskMutation)(nil)
+
+// compapiasynctaskOption allows management of the mutation configuration using functional options.
+type compapiasynctaskOption func(*CompapiAsynctaskMutation)
+
+// newCompapiAsynctaskMutation creates new mutation for the CompapiAsynctask entity.
+func newCompapiAsynctaskMutation(c config, op Op, opts ...compapiasynctaskOption) *CompapiAsynctaskMutation {
+	m := &CompapiAsynctaskMutation{
+		config:        c,
+		op:            op,
+		typ:           TypeCompapiAsynctask,
+		clearedFields: make(map[string]struct{}),
+	}
+	for _, opt := range opts {
+		opt(m)
+	}
+	return m
+}
+
+// withCompapiAsynctaskID sets the ID field of the mutation.
+func withCompapiAsynctaskID(id uint64) compapiasynctaskOption {
+	return func(m *CompapiAsynctaskMutation) {
+		var (
+			err   error
+			once  sync.Once
+			value *CompapiAsynctask
+		)
+		m.oldValue = func(ctx context.Context) (*CompapiAsynctask, error) {
+			once.Do(func() {
+				if m.done {
+					err = errors.New("querying old values post mutation is not allowed")
+				} else {
+					value, err = m.Client().CompapiAsynctask.Get(ctx, id)
+				}
+			})
+			return value, err
+		}
+		m.id = &id
+	}
+}
+
+// withCompapiAsynctask sets the old CompapiAsynctask of the mutation.
+func withCompapiAsynctask(node *CompapiAsynctask) compapiasynctaskOption {
+	return func(m *CompapiAsynctaskMutation) {
+		m.oldValue = func(context.Context) (*CompapiAsynctask, error) {
+			return node, nil
+		}
+		m.id = &node.ID
+	}
+}
+
+// Client returns a new `ent.Client` from the mutation. If the mutation was
+// executed in a transaction (ent.Tx), a transactional client is returned.
+func (m CompapiAsynctaskMutation) Client() *Client {
+	client := &Client{config: m.config}
+	client.init()
+	return client
+}
+
+// Tx returns an `ent.Tx` for mutations that were executed in transactions;
+// it returns an error otherwise.
+func (m CompapiAsynctaskMutation) Tx() (*Tx, error) {
+	if _, ok := m.driver.(*txDriver); !ok {
+		return nil, errors.New("ent: mutation is not running in a transaction")
+	}
+	tx := &Tx{config: m.config}
+	tx.init()
+	return tx, nil
+}
+
+// SetID sets the value of the id field. Note that this
+// operation is only accepted on creation of CompapiAsynctask entities.
+func (m *CompapiAsynctaskMutation) SetID(id uint64) {
+	m.id = &id
+}
+
+// ID returns the ID value in the mutation. Note that the ID is only available
+// if it was provided to the builder or after it was returned from the database.
+func (m *CompapiAsynctaskMutation) ID() (id uint64, exists bool) {
+	if m.id == nil {
+		return
+	}
+	return *m.id, true
+}
+
+// IDs queries the database and returns the entity ids that match the mutation's predicate.
+// That means, if the mutation is applied within a transaction with an isolation level such
+// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
+// or updated by the mutation.
+func (m *CompapiAsynctaskMutation) IDs(ctx context.Context) ([]uint64, error) {
+	switch {
+	case m.op.Is(OpUpdateOne | OpDeleteOne):
+		id, exists := m.ID()
+		if exists {
+			return []uint64{id}, nil
+		}
+		fallthrough
+	case m.op.Is(OpUpdate | OpDelete):
+		return m.Client().CompapiAsynctask.Query().Where(m.predicates...).IDs(ctx)
+	default:
+		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
+	}
+}
+
+// SetCreatedAt sets the "created_at" field.
+func (m *CompapiAsynctaskMutation) SetCreatedAt(t time.Time) {
+	m.created_at = &t
+}
+
+// CreatedAt returns the value of the "created_at" field in the mutation.
+func (m *CompapiAsynctaskMutation) CreatedAt() (r time.Time, exists bool) {
+	v := m.created_at
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldCreatedAt returns the old "created_at" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
+	}
+	return oldValue.CreatedAt, nil
+}
+
+// ResetCreatedAt resets all changes to the "created_at" field.
+func (m *CompapiAsynctaskMutation) ResetCreatedAt() {
+	m.created_at = nil
+}
+
+// SetUpdatedAt sets the "updated_at" field.
+func (m *CompapiAsynctaskMutation) SetUpdatedAt(t time.Time) {
+	m.updated_at = &t
+}
+
+// UpdatedAt returns the value of the "updated_at" field in the mutation.
+func (m *CompapiAsynctaskMutation) UpdatedAt() (r time.Time, exists bool) {
+	v := m.updated_at
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldUpdatedAt returns the old "updated_at" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
+	}
+	return oldValue.UpdatedAt, nil
+}
+
+// ResetUpdatedAt resets all changes to the "updated_at" field.
+func (m *CompapiAsynctaskMutation) ResetUpdatedAt() {
+	m.updated_at = nil
+}
+
+// SetAuthToken sets the "auth_token" field.
+func (m *CompapiAsynctaskMutation) SetAuthToken(s string) {
+	m.auth_token = &s
+}
+
+// AuthToken returns the value of the "auth_token" field in the mutation.
+func (m *CompapiAsynctaskMutation) AuthToken() (r string, exists bool) {
+	v := m.auth_token
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldAuthToken returns the old "auth_token" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldAuthToken(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldAuthToken is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldAuthToken requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldAuthToken: %w", err)
+	}
+	return oldValue.AuthToken, nil
+}
+
+// ResetAuthToken resets all changes to the "auth_token" field.
+func (m *CompapiAsynctaskMutation) ResetAuthToken() {
+	m.auth_token = nil
+}
+
+// SetEventType sets the "event_type" field.
+func (m *CompapiAsynctaskMutation) SetEventType(s string) {
+	m.event_type = &s
+}
+
+// EventType returns the value of the "event_type" field in the mutation.
+func (m *CompapiAsynctaskMutation) EventType() (r string, exists bool) {
+	v := m.event_type
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldEventType returns the old "event_type" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldEventType(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldEventType is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldEventType requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldEventType: %w", err)
+	}
+	return oldValue.EventType, nil
+}
+
+// ResetEventType resets all changes to the "event_type" field.
+func (m *CompapiAsynctaskMutation) ResetEventType() {
+	m.event_type = nil
+}
+
+// SetChatID sets the "chat_id" field.
+func (m *CompapiAsynctaskMutation) SetChatID(s string) {
+	m.chat_id = &s
+}
+
+// ChatID returns the value of the "chat_id" field in the mutation.
+func (m *CompapiAsynctaskMutation) ChatID() (r string, exists bool) {
+	v := m.chat_id
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldChatID returns the old "chat_id" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldChatID(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldChatID is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldChatID requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldChatID: %w", err)
+	}
+	return oldValue.ChatID, nil
+}
+
+// ClearChatID clears the value of the "chat_id" field.
+func (m *CompapiAsynctaskMutation) ClearChatID() {
+	m.chat_id = nil
+	m.clearedFields[compapiasynctask.FieldChatID] = struct{}{}
+}
+
+// ChatIDCleared returns if the "chat_id" field was cleared in this mutation.
+func (m *CompapiAsynctaskMutation) ChatIDCleared() bool {
+	_, ok := m.clearedFields[compapiasynctask.FieldChatID]
+	return ok
+}
+
+// ResetChatID resets all changes to the "chat_id" field.
+func (m *CompapiAsynctaskMutation) ResetChatID() {
+	m.chat_id = nil
+	delete(m.clearedFields, compapiasynctask.FieldChatID)
+}
+
+// SetOrganizationID sets the "organization_id" field.
+func (m *CompapiAsynctaskMutation) SetOrganizationID(u uint64) {
+	m.organization_id = &u
+	m.addorganization_id = nil
+}
+
+// OrganizationID returns the value of the "organization_id" field in the mutation.
+func (m *CompapiAsynctaskMutation) OrganizationID() (r uint64, exists bool) {
+	v := m.organization_id
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldOrganizationID returns the old "organization_id" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldOrganizationID(ctx context.Context) (v uint64, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldOrganizationID is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldOrganizationID requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldOrganizationID: %w", err)
+	}
+	return oldValue.OrganizationID, nil
+}
+
+// AddOrganizationID adds u to the "organization_id" field.
+func (m *CompapiAsynctaskMutation) AddOrganizationID(u int64) {
+	if m.addorganization_id != nil {
+		*m.addorganization_id += u
+	} else {
+		m.addorganization_id = &u
+	}
+}
+
+// AddedOrganizationID returns the value that was added to the "organization_id" field in this mutation.
+func (m *CompapiAsynctaskMutation) AddedOrganizationID() (r int64, exists bool) {
+	v := m.addorganization_id
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// ResetOrganizationID resets all changes to the "organization_id" field.
+func (m *CompapiAsynctaskMutation) ResetOrganizationID() {
+	m.organization_id = nil
+	m.addorganization_id = nil
+}
+
+// SetOpenaiBase sets the "openai_base" field.
+func (m *CompapiAsynctaskMutation) SetOpenaiBase(s string) {
+	m.openai_base = &s
+}
+
+// OpenaiBase returns the value of the "openai_base" field in the mutation.
+func (m *CompapiAsynctaskMutation) OpenaiBase() (r string, exists bool) {
+	v := m.openai_base
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldOpenaiBase returns the old "openai_base" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldOpenaiBase(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldOpenaiBase is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldOpenaiBase requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldOpenaiBase: %w", err)
+	}
+	return oldValue.OpenaiBase, nil
+}
+
+// ResetOpenaiBase resets all changes to the "openai_base" field.
+func (m *CompapiAsynctaskMutation) ResetOpenaiBase() {
+	m.openai_base = nil
+}
+
+// SetOpenaiKey sets the "openai_key" field.
+func (m *CompapiAsynctaskMutation) SetOpenaiKey(s string) {
+	m.openai_key = &s
+}
+
+// OpenaiKey returns the value of the "openai_key" field in the mutation.
+func (m *CompapiAsynctaskMutation) OpenaiKey() (r string, exists bool) {
+	v := m.openai_key
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldOpenaiKey returns the old "openai_key" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldOpenaiKey(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldOpenaiKey is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldOpenaiKey requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldOpenaiKey: %w", err)
+	}
+	return oldValue.OpenaiKey, nil
+}
+
+// ResetOpenaiKey resets all changes to the "openai_key" field.
+func (m *CompapiAsynctaskMutation) ResetOpenaiKey() {
+	m.openai_key = nil
+}
+
+// SetRequestRaw sets the "request_raw" field.
+func (m *CompapiAsynctaskMutation) SetRequestRaw(s string) {
+	m.request_raw = &s
+}
+
+// RequestRaw returns the value of the "request_raw" field in the mutation.
+func (m *CompapiAsynctaskMutation) RequestRaw() (r string, exists bool) {
+	v := m.request_raw
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldRequestRaw returns the old "request_raw" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldRequestRaw(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldRequestRaw is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldRequestRaw requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldRequestRaw: %w", err)
+	}
+	return oldValue.RequestRaw, nil
+}
+
+// ResetRequestRaw resets all changes to the "request_raw" field.
+func (m *CompapiAsynctaskMutation) ResetRequestRaw() {
+	m.request_raw = nil
+}
+
+// SetResponseRaw sets the "response_raw" field.
+func (m *CompapiAsynctaskMutation) SetResponseRaw(s string) {
+	m.response_raw = &s
+}
+
+// ResponseRaw returns the value of the "response_raw" field in the mutation.
+func (m *CompapiAsynctaskMutation) ResponseRaw() (r string, exists bool) {
+	v := m.response_raw
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldResponseRaw returns the old "response_raw" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldResponseRaw(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldResponseRaw is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldResponseRaw requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldResponseRaw: %w", err)
+	}
+	return oldValue.ResponseRaw, nil
+}
+
+// ClearResponseRaw clears the value of the "response_raw" field.
+func (m *CompapiAsynctaskMutation) ClearResponseRaw() {
+	m.response_raw = nil
+	m.clearedFields[compapiasynctask.FieldResponseRaw] = struct{}{}
+}
+
+// ResponseRawCleared returns if the "response_raw" field was cleared in this mutation.
+func (m *CompapiAsynctaskMutation) ResponseRawCleared() bool {
+	_, ok := m.clearedFields[compapiasynctask.FieldResponseRaw]
+	return ok
+}
+
+// ResetResponseRaw resets all changes to the "response_raw" field.
+func (m *CompapiAsynctaskMutation) ResetResponseRaw() {
+	m.response_raw = nil
+	delete(m.clearedFields, compapiasynctask.FieldResponseRaw)
+}
+
+// SetCallbackURL sets the "callback_url" field.
+func (m *CompapiAsynctaskMutation) SetCallbackURL(s string) {
+	m.callback_url = &s
+}
+
+// CallbackURL returns the value of the "callback_url" field in the mutation.
+func (m *CompapiAsynctaskMutation) CallbackURL() (r string, exists bool) {
+	v := m.callback_url
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldCallbackURL returns the old "callback_url" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldCallbackURL(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldCallbackURL is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldCallbackURL requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldCallbackURL: %w", err)
+	}
+	return oldValue.CallbackURL, nil
+}
+
+// ResetCallbackURL resets all changes to the "callback_url" field.
+func (m *CompapiAsynctaskMutation) ResetCallbackURL() {
+	m.callback_url = nil
+}
+
+// SetCallbackResponseRaw sets the "callback_response_raw" field.
+func (m *CompapiAsynctaskMutation) SetCallbackResponseRaw(s string) {
+	m.callback_response_raw = &s
+}
+
+// CallbackResponseRaw returns the value of the "callback_response_raw" field in the mutation.
+func (m *CompapiAsynctaskMutation) CallbackResponseRaw() (r string, exists bool) {
+	v := m.callback_response_raw
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldCallbackResponseRaw returns the old "callback_response_raw" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldCallbackResponseRaw(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldCallbackResponseRaw is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldCallbackResponseRaw requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldCallbackResponseRaw: %w", err)
+	}
+	return oldValue.CallbackResponseRaw, nil
+}
+
+// ClearCallbackResponseRaw clears the value of the "callback_response_raw" field.
+func (m *CompapiAsynctaskMutation) ClearCallbackResponseRaw() {
+	m.callback_response_raw = nil
+	m.clearedFields[compapiasynctask.FieldCallbackResponseRaw] = struct{}{}
+}
+
+// CallbackResponseRawCleared returns if the "callback_response_raw" field was cleared in this mutation.
+func (m *CompapiAsynctaskMutation) CallbackResponseRawCleared() bool {
+	_, ok := m.clearedFields[compapiasynctask.FieldCallbackResponseRaw]
+	return ok
+}
+
+// ResetCallbackResponseRaw resets all changes to the "callback_response_raw" field.
+func (m *CompapiAsynctaskMutation) ResetCallbackResponseRaw() {
+	m.callback_response_raw = nil
+	delete(m.clearedFields, compapiasynctask.FieldCallbackResponseRaw)
+}
+
+// SetModel sets the "model" field.
+func (m *CompapiAsynctaskMutation) SetModel(s string) {
+	m.model = &s
+}
+
+// Model returns the value of the "model" field in the mutation.
+func (m *CompapiAsynctaskMutation) Model() (r string, exists bool) {
+	v := m.model
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldModel returns the old "model" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldModel(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldModel is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldModel requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldModel: %w", err)
+	}
+	return oldValue.Model, nil
+}
+
+// ClearModel clears the value of the "model" field.
+func (m *CompapiAsynctaskMutation) ClearModel() {
+	m.model = nil
+	m.clearedFields[compapiasynctask.FieldModel] = struct{}{}
+}
+
+// ModelCleared returns if the "model" field was cleared in this mutation.
+func (m *CompapiAsynctaskMutation) ModelCleared() bool {
+	_, ok := m.clearedFields[compapiasynctask.FieldModel]
+	return ok
+}
+
+// ResetModel resets all changes to the "model" field.
+func (m *CompapiAsynctaskMutation) ResetModel() {
+	m.model = nil
+	delete(m.clearedFields, compapiasynctask.FieldModel)
+}
+
+// SetTaskStatus sets the "task_status" field.
+func (m *CompapiAsynctaskMutation) SetTaskStatus(i int8) {
+	m.task_status = &i
+	m.addtask_status = nil
+}
+
+// TaskStatus returns the value of the "task_status" field in the mutation.
+func (m *CompapiAsynctaskMutation) TaskStatus() (r int8, exists bool) {
+	v := m.task_status
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldTaskStatus returns the old "task_status" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldTaskStatus(ctx context.Context) (v int8, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldTaskStatus is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldTaskStatus requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldTaskStatus: %w", err)
+	}
+	return oldValue.TaskStatus, nil
+}
+
+// AddTaskStatus adds i to the "task_status" field.
+func (m *CompapiAsynctaskMutation) AddTaskStatus(i int8) {
+	if m.addtask_status != nil {
+		*m.addtask_status += i
+	} else {
+		m.addtask_status = &i
+	}
+}
+
+// AddedTaskStatus returns the value that was added to the "task_status" field in this mutation.
+func (m *CompapiAsynctaskMutation) AddedTaskStatus() (r int8, exists bool) {
+	v := m.addtask_status
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// ClearTaskStatus clears the value of the "task_status" field.
+func (m *CompapiAsynctaskMutation) ClearTaskStatus() {
+	m.task_status = nil
+	m.addtask_status = nil
+	m.clearedFields[compapiasynctask.FieldTaskStatus] = struct{}{}
+}
+
+// TaskStatusCleared returns if the "task_status" field was cleared in this mutation.
+func (m *CompapiAsynctaskMutation) TaskStatusCleared() bool {
+	_, ok := m.clearedFields[compapiasynctask.FieldTaskStatus]
+	return ok
+}
+
+// ResetTaskStatus resets all changes to the "task_status" field.
+func (m *CompapiAsynctaskMutation) ResetTaskStatus() {
+	m.task_status = nil
+	m.addtask_status = nil
+	delete(m.clearedFields, compapiasynctask.FieldTaskStatus)
+}
+
+// SetRetryCount sets the "retry_count" field.
+func (m *CompapiAsynctaskMutation) SetRetryCount(i int8) {
+	m.retry_count = &i
+	m.addretry_count = nil
+}
+
+// RetryCount returns the value of the "retry_count" field in the mutation.
+func (m *CompapiAsynctaskMutation) RetryCount() (r int8, exists bool) {
+	v := m.retry_count
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldRetryCount returns the old "retry_count" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldRetryCount(ctx context.Context) (v int8, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldRetryCount is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldRetryCount requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldRetryCount: %w", err)
+	}
+	return oldValue.RetryCount, nil
+}
+
+// AddRetryCount adds i to the "retry_count" field.
+func (m *CompapiAsynctaskMutation) AddRetryCount(i int8) {
+	if m.addretry_count != nil {
+		*m.addretry_count += i
+	} else {
+		m.addretry_count = &i
+	}
+}
+
+// AddedRetryCount returns the value that was added to the "retry_count" field in this mutation.
+func (m *CompapiAsynctaskMutation) AddedRetryCount() (r int8, exists bool) {
+	v := m.addretry_count
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// ClearRetryCount clears the value of the "retry_count" field.
+func (m *CompapiAsynctaskMutation) ClearRetryCount() {
+	m.retry_count = nil
+	m.addretry_count = nil
+	m.clearedFields[compapiasynctask.FieldRetryCount] = struct{}{}
+}
+
+// RetryCountCleared returns if the "retry_count" field was cleared in this mutation.
+func (m *CompapiAsynctaskMutation) RetryCountCleared() bool {
+	_, ok := m.clearedFields[compapiasynctask.FieldRetryCount]
+	return ok
+}
+
+// ResetRetryCount resets all changes to the "retry_count" field.
+func (m *CompapiAsynctaskMutation) ResetRetryCount() {
+	m.retry_count = nil
+	m.addretry_count = nil
+	delete(m.clearedFields, compapiasynctask.FieldRetryCount)
+}
+
+// SetLastError sets the "last_error" field.
+func (m *CompapiAsynctaskMutation) SetLastError(s string) {
+	m.last_error = &s
+}
+
+// LastError returns the value of the "last_error" field in the mutation.
+func (m *CompapiAsynctaskMutation) LastError() (r string, exists bool) {
+	v := m.last_error
+	if v == nil {
+		return
+	}
+	return *v, true
+}
+
+// OldLastError returns the old "last_error" field's value of the CompapiAsynctask entity.
+// If the CompapiAsynctask object wasn't provided to the builder, the object is fetched from the database.
+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
+func (m *CompapiAsynctaskMutation) OldLastError(ctx context.Context) (v string, err error) {
+	if !m.op.Is(OpUpdateOne) {
+		return v, errors.New("OldLastError is only allowed on UpdateOne operations")
+	}
+	if m.id == nil || m.oldValue == nil {
+		return v, errors.New("OldLastError requires an ID field in the mutation")
+	}
+	oldValue, err := m.oldValue(ctx)
+	if err != nil {
+		return v, fmt.Errorf("querying old value for OldLastError: %w", err)
+	}
+	return oldValue.LastError, nil
+}
+
+// ClearLastError clears the value of the "last_error" field.
+func (m *CompapiAsynctaskMutation) ClearLastError() {
+	m.last_error = nil
+	m.clearedFields[compapiasynctask.FieldLastError] = struct{}{}
+}
+
+// LastErrorCleared returns if the "last_error" field was cleared in this mutation.
+func (m *CompapiAsynctaskMutation) LastErrorCleared() bool {
+	_, ok := m.clearedFields[compapiasynctask.FieldLastError]
+	return ok
+}
+
+// ResetLastError resets all changes to the "last_error" field.
+func (m *CompapiAsynctaskMutation) ResetLastError() {
+	m.last_error = nil
+	delete(m.clearedFields, compapiasynctask.FieldLastError)
+}
+
+// Where appends a list predicates to the CompapiAsynctaskMutation builder.
+func (m *CompapiAsynctaskMutation) Where(ps ...predicate.CompapiAsynctask) {
+	m.predicates = append(m.predicates, ps...)
+}
+
+// WhereP appends storage-level predicates to the CompapiAsynctaskMutation builder. Using this method,
+// users can use type-assertion to append predicates that do not depend on any generated package.
+func (m *CompapiAsynctaskMutation) WhereP(ps ...func(*sql.Selector)) {
+	p := make([]predicate.CompapiAsynctask, len(ps))
+	for i := range ps {
+		p[i] = ps[i]
+	}
+	m.Where(p...)
+}
+
+// Op returns the operation name.
+func (m *CompapiAsynctaskMutation) Op() Op {
+	return m.op
+}
+
+// SetOp allows setting the mutation operation.
+func (m *CompapiAsynctaskMutation) SetOp(op Op) {
+	m.op = op
+}
+
+// Type returns the node type of this mutation (CompapiAsynctask).
+func (m *CompapiAsynctaskMutation) Type() string {
+	return m.typ
+}
+
+// Fields returns all fields that were changed during this mutation. Note that in
+// order to get all numeric fields that were incremented/decremented, call
+// AddedFields().
+func (m *CompapiAsynctaskMutation) Fields() []string {
+	fields := make([]string, 0, 16)
+	if m.created_at != nil {
+		fields = append(fields, compapiasynctask.FieldCreatedAt)
+	}
+	if m.updated_at != nil {
+		fields = append(fields, compapiasynctask.FieldUpdatedAt)
+	}
+	if m.auth_token != nil {
+		fields = append(fields, compapiasynctask.FieldAuthToken)
+	}
+	if m.event_type != nil {
+		fields = append(fields, compapiasynctask.FieldEventType)
+	}
+	if m.chat_id != nil {
+		fields = append(fields, compapiasynctask.FieldChatID)
+	}
+	if m.organization_id != nil {
+		fields = append(fields, compapiasynctask.FieldOrganizationID)
+	}
+	if m.openai_base != nil {
+		fields = append(fields, compapiasynctask.FieldOpenaiBase)
+	}
+	if m.openai_key != nil {
+		fields = append(fields, compapiasynctask.FieldOpenaiKey)
+	}
+	if m.request_raw != nil {
+		fields = append(fields, compapiasynctask.FieldRequestRaw)
+	}
+	if m.response_raw != nil {
+		fields = append(fields, compapiasynctask.FieldResponseRaw)
+	}
+	if m.callback_url != nil {
+		fields = append(fields, compapiasynctask.FieldCallbackURL)
+	}
+	if m.callback_response_raw != nil {
+		fields = append(fields, compapiasynctask.FieldCallbackResponseRaw)
+	}
+	if m.model != nil {
+		fields = append(fields, compapiasynctask.FieldModel)
+	}
+	if m.task_status != nil {
+		fields = append(fields, compapiasynctask.FieldTaskStatus)
+	}
+	if m.retry_count != nil {
+		fields = append(fields, compapiasynctask.FieldRetryCount)
+	}
+	if m.last_error != nil {
+		fields = append(fields, compapiasynctask.FieldLastError)
+	}
+	return fields
+}
+
+// Field returns the value of a field with the given name. The second boolean
+// return value indicates that this field was not set, or was not defined in the
+// schema.
+func (m *CompapiAsynctaskMutation) Field(name string) (ent.Value, bool) {
+	switch name {
+	case compapiasynctask.FieldCreatedAt:
+		return m.CreatedAt()
+	case compapiasynctask.FieldUpdatedAt:
+		return m.UpdatedAt()
+	case compapiasynctask.FieldAuthToken:
+		return m.AuthToken()
+	case compapiasynctask.FieldEventType:
+		return m.EventType()
+	case compapiasynctask.FieldChatID:
+		return m.ChatID()
+	case compapiasynctask.FieldOrganizationID:
+		return m.OrganizationID()
+	case compapiasynctask.FieldOpenaiBase:
+		return m.OpenaiBase()
+	case compapiasynctask.FieldOpenaiKey:
+		return m.OpenaiKey()
+	case compapiasynctask.FieldRequestRaw:
+		return m.RequestRaw()
+	case compapiasynctask.FieldResponseRaw:
+		return m.ResponseRaw()
+	case compapiasynctask.FieldCallbackURL:
+		return m.CallbackURL()
+	case compapiasynctask.FieldCallbackResponseRaw:
+		return m.CallbackResponseRaw()
+	case compapiasynctask.FieldModel:
+		return m.Model()
+	case compapiasynctask.FieldTaskStatus:
+		return m.TaskStatus()
+	case compapiasynctask.FieldRetryCount:
+		return m.RetryCount()
+	case compapiasynctask.FieldLastError:
+		return m.LastError()
+	}
+	return nil, false
+}
+
+// OldField returns the old value of the field from the database. An error is
+// returned if the mutation operation is not UpdateOne, or the query to the
+// database failed.
+func (m *CompapiAsynctaskMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
+	switch name {
+	case compapiasynctask.FieldCreatedAt:
+		return m.OldCreatedAt(ctx)
+	case compapiasynctask.FieldUpdatedAt:
+		return m.OldUpdatedAt(ctx)
+	case compapiasynctask.FieldAuthToken:
+		return m.OldAuthToken(ctx)
+	case compapiasynctask.FieldEventType:
+		return m.OldEventType(ctx)
+	case compapiasynctask.FieldChatID:
+		return m.OldChatID(ctx)
+	case compapiasynctask.FieldOrganizationID:
+		return m.OldOrganizationID(ctx)
+	case compapiasynctask.FieldOpenaiBase:
+		return m.OldOpenaiBase(ctx)
+	case compapiasynctask.FieldOpenaiKey:
+		return m.OldOpenaiKey(ctx)
+	case compapiasynctask.FieldRequestRaw:
+		return m.OldRequestRaw(ctx)
+	case compapiasynctask.FieldResponseRaw:
+		return m.OldResponseRaw(ctx)
+	case compapiasynctask.FieldCallbackURL:
+		return m.OldCallbackURL(ctx)
+	case compapiasynctask.FieldCallbackResponseRaw:
+		return m.OldCallbackResponseRaw(ctx)
+	case compapiasynctask.FieldModel:
+		return m.OldModel(ctx)
+	case compapiasynctask.FieldTaskStatus:
+		return m.OldTaskStatus(ctx)
+	case compapiasynctask.FieldRetryCount:
+		return m.OldRetryCount(ctx)
+	case compapiasynctask.FieldLastError:
+		return m.OldLastError(ctx)
+	}
+	return nil, fmt.Errorf("unknown CompapiAsynctask field %s", name)
+}
+
+// SetField sets the value of a field with the given name. It returns an error if
+// the field is not defined in the schema, or if the type mismatched the field
+// type.
+func (m *CompapiAsynctaskMutation) SetField(name string, value ent.Value) error {
+	switch name {
+	case compapiasynctask.FieldCreatedAt:
+		v, ok := value.(time.Time)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetCreatedAt(v)
+		return nil
+	case compapiasynctask.FieldUpdatedAt:
+		v, ok := value.(time.Time)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetUpdatedAt(v)
+		return nil
+	case compapiasynctask.FieldAuthToken:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetAuthToken(v)
+		return nil
+	case compapiasynctask.FieldEventType:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetEventType(v)
+		return nil
+	case compapiasynctask.FieldChatID:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetChatID(v)
+		return nil
+	case compapiasynctask.FieldOrganizationID:
+		v, ok := value.(uint64)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetOrganizationID(v)
+		return nil
+	case compapiasynctask.FieldOpenaiBase:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetOpenaiBase(v)
+		return nil
+	case compapiasynctask.FieldOpenaiKey:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetOpenaiKey(v)
+		return nil
+	case compapiasynctask.FieldRequestRaw:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetRequestRaw(v)
+		return nil
+	case compapiasynctask.FieldResponseRaw:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetResponseRaw(v)
+		return nil
+	case compapiasynctask.FieldCallbackURL:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetCallbackURL(v)
+		return nil
+	case compapiasynctask.FieldCallbackResponseRaw:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetCallbackResponseRaw(v)
+		return nil
+	case compapiasynctask.FieldModel:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetModel(v)
+		return nil
+	case compapiasynctask.FieldTaskStatus:
+		v, ok := value.(int8)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetTaskStatus(v)
+		return nil
+	case compapiasynctask.FieldRetryCount:
+		v, ok := value.(int8)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetRetryCount(v)
+		return nil
+	case compapiasynctask.FieldLastError:
+		v, ok := value.(string)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.SetLastError(v)
+		return nil
+	}
+	return fmt.Errorf("unknown CompapiAsynctask field %s", name)
+}
+
+// AddedFields returns all numeric fields that were incremented/decremented during
+// this mutation.
+func (m *CompapiAsynctaskMutation) AddedFields() []string {
+	var fields []string
+	if m.addorganization_id != nil {
+		fields = append(fields, compapiasynctask.FieldOrganizationID)
+	}
+	if m.addtask_status != nil {
+		fields = append(fields, compapiasynctask.FieldTaskStatus)
+	}
+	if m.addretry_count != nil {
+		fields = append(fields, compapiasynctask.FieldRetryCount)
+	}
+	return fields
+}
+
+// AddedField returns the numeric value that was incremented/decremented on a field
+// with the given name. The second boolean return value indicates that this field
+// was not set, or was not defined in the schema.
+func (m *CompapiAsynctaskMutation) AddedField(name string) (ent.Value, bool) {
+	switch name {
+	case compapiasynctask.FieldOrganizationID:
+		return m.AddedOrganizationID()
+	case compapiasynctask.FieldTaskStatus:
+		return m.AddedTaskStatus()
+	case compapiasynctask.FieldRetryCount:
+		return m.AddedRetryCount()
+	}
+	return nil, false
+}
+
+// AddField adds the value to the field with the given name. It returns an error if
+// the field is not defined in the schema, or if the type mismatched the field
+// type.
+func (m *CompapiAsynctaskMutation) AddField(name string, value ent.Value) error {
+	switch name {
+	case compapiasynctask.FieldOrganizationID:
+		v, ok := value.(int64)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.AddOrganizationID(v)
+		return nil
+	case compapiasynctask.FieldTaskStatus:
+		v, ok := value.(int8)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.AddTaskStatus(v)
+		return nil
+	case compapiasynctask.FieldRetryCount:
+		v, ok := value.(int8)
+		if !ok {
+			return fmt.Errorf("unexpected type %T for field %s", value, name)
+		}
+		m.AddRetryCount(v)
+		return nil
+	}
+	return fmt.Errorf("unknown CompapiAsynctask numeric field %s", name)
+}
+
+// ClearedFields returns all nullable fields that were cleared during this
+// mutation.
+func (m *CompapiAsynctaskMutation) ClearedFields() []string {
+	var fields []string
+	if m.FieldCleared(compapiasynctask.FieldChatID) {
+		fields = append(fields, compapiasynctask.FieldChatID)
+	}
+	if m.FieldCleared(compapiasynctask.FieldResponseRaw) {
+		fields = append(fields, compapiasynctask.FieldResponseRaw)
+	}
+	if m.FieldCleared(compapiasynctask.FieldCallbackResponseRaw) {
+		fields = append(fields, compapiasynctask.FieldCallbackResponseRaw)
+	}
+	if m.FieldCleared(compapiasynctask.FieldModel) {
+		fields = append(fields, compapiasynctask.FieldModel)
+	}
+	if m.FieldCleared(compapiasynctask.FieldTaskStatus) {
+		fields = append(fields, compapiasynctask.FieldTaskStatus)
+	}
+	if m.FieldCleared(compapiasynctask.FieldRetryCount) {
+		fields = append(fields, compapiasynctask.FieldRetryCount)
+	}
+	if m.FieldCleared(compapiasynctask.FieldLastError) {
+		fields = append(fields, compapiasynctask.FieldLastError)
+	}
+	return fields
+}
+
+// FieldCleared returns a boolean indicating if a field with the given name was
+// cleared in this mutation.
+func (m *CompapiAsynctaskMutation) FieldCleared(name string) bool {
+	_, ok := m.clearedFields[name]
+	return ok
+}
+
+// ClearField clears the value of the field with the given name. It returns an
+// error if the field is not defined in the schema.
+func (m *CompapiAsynctaskMutation) ClearField(name string) error {
+	switch name {
+	case compapiasynctask.FieldChatID:
+		m.ClearChatID()
+		return nil
+	case compapiasynctask.FieldResponseRaw:
+		m.ClearResponseRaw()
+		return nil
+	case compapiasynctask.FieldCallbackResponseRaw:
+		m.ClearCallbackResponseRaw()
+		return nil
+	case compapiasynctask.FieldModel:
+		m.ClearModel()
+		return nil
+	case compapiasynctask.FieldTaskStatus:
+		m.ClearTaskStatus()
+		return nil
+	case compapiasynctask.FieldRetryCount:
+		m.ClearRetryCount()
+		return nil
+	case compapiasynctask.FieldLastError:
+		m.ClearLastError()
+		return nil
+	}
+	return fmt.Errorf("unknown CompapiAsynctask nullable field %s", name)
+}
+
+// ResetField resets all changes in the mutation for the field with the given name.
+// It returns an error if the field is not defined in the schema.
+func (m *CompapiAsynctaskMutation) ResetField(name string) error {
+	switch name {
+	case compapiasynctask.FieldCreatedAt:
+		m.ResetCreatedAt()
+		return nil
+	case compapiasynctask.FieldUpdatedAt:
+		m.ResetUpdatedAt()
+		return nil
+	case compapiasynctask.FieldAuthToken:
+		m.ResetAuthToken()
+		return nil
+	case compapiasynctask.FieldEventType:
+		m.ResetEventType()
+		return nil
+	case compapiasynctask.FieldChatID:
+		m.ResetChatID()
+		return nil
+	case compapiasynctask.FieldOrganizationID:
+		m.ResetOrganizationID()
+		return nil
+	case compapiasynctask.FieldOpenaiBase:
+		m.ResetOpenaiBase()
+		return nil
+	case compapiasynctask.FieldOpenaiKey:
+		m.ResetOpenaiKey()
+		return nil
+	case compapiasynctask.FieldRequestRaw:
+		m.ResetRequestRaw()
+		return nil
+	case compapiasynctask.FieldResponseRaw:
+		m.ResetResponseRaw()
+		return nil
+	case compapiasynctask.FieldCallbackURL:
+		m.ResetCallbackURL()
+		return nil
+	case compapiasynctask.FieldCallbackResponseRaw:
+		m.ResetCallbackResponseRaw()
+		return nil
+	case compapiasynctask.FieldModel:
+		m.ResetModel()
+		return nil
+	case compapiasynctask.FieldTaskStatus:
+		m.ResetTaskStatus()
+		return nil
+	case compapiasynctask.FieldRetryCount:
+		m.ResetRetryCount()
+		return nil
+	case compapiasynctask.FieldLastError:
+		m.ResetLastError()
+		return nil
+	}
+	return fmt.Errorf("unknown CompapiAsynctask field %s", name)
+}
+
+// AddedEdges returns all edge names that were set/added in this mutation.
+func (m *CompapiAsynctaskMutation) AddedEdges() []string {
+	edges := make([]string, 0, 0)
+	return edges
+}
+
+// AddedIDs returns all IDs (to other nodes) that were added for the given edge
+// name in this mutation.
+func (m *CompapiAsynctaskMutation) AddedIDs(name string) []ent.Value {
+	return nil
+}
+
+// RemovedEdges returns all edge names that were removed in this mutation.
+func (m *CompapiAsynctaskMutation) RemovedEdges() []string {
+	edges := make([]string, 0, 0)
+	return edges
+}
+
+// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
+// the given name in this mutation.
+func (m *CompapiAsynctaskMutation) RemovedIDs(name string) []ent.Value {
+	return nil
+}
+
+// ClearedEdges returns all edge names that were cleared in this mutation.
+func (m *CompapiAsynctaskMutation) ClearedEdges() []string {
+	edges := make([]string, 0, 0)
+	return edges
+}
+
+// EdgeCleared returns a boolean which indicates if the edge with the given name
+// was cleared in this mutation.
+func (m *CompapiAsynctaskMutation) EdgeCleared(name string) bool {
+	return false
+}
+
+// ClearEdge clears the value of the edge with the given name. It returns an error
+// if that edge is not defined in the schema.
+func (m *CompapiAsynctaskMutation) ClearEdge(name string) error {
+	return fmt.Errorf("unknown CompapiAsynctask unique edge %s", name)
+}
+
+// ResetEdge resets all changes to the edge with the given name in this mutation.
+// It returns an error if the edge is not defined in the schema.
+func (m *CompapiAsynctaskMutation) ResetEdge(name string) error {
+	return fmt.Errorf("unknown CompapiAsynctask edge %s", name)
+}
+
 // ContactMutation represents an operation that mutates the Contact nodes in the graph.
 type ContactMutation struct {
 	config

+ 82 - 0
ent/pagination.go

@@ -14,6 +14,7 @@ import (
 	"wechat-api/ent/category"
 	"wechat-api/ent/chatrecords"
 	"wechat-api/ent/chatsession"
+	"wechat-api/ent/compapiasynctask"
 	"wechat-api/ent/contact"
 	"wechat-api/ent/creditbalance"
 	"wechat-api/ent/creditusage"
@@ -823,6 +824,87 @@ func (cs *ChatSessionQuery) Page(
 	return ret, nil
 }
 
+type CompapiAsynctaskPager struct {
+	Order  compapiasynctask.OrderOption
+	Filter func(*CompapiAsynctaskQuery) (*CompapiAsynctaskQuery, error)
+}
+
+// CompapiAsynctaskPaginateOption enables pagination customization.
+type CompapiAsynctaskPaginateOption func(*CompapiAsynctaskPager)
+
+// DefaultCompapiAsynctaskOrder is the default ordering of CompapiAsynctask.
+var DefaultCompapiAsynctaskOrder = Desc(compapiasynctask.FieldID)
+
+func newCompapiAsynctaskPager(opts []CompapiAsynctaskPaginateOption) (*CompapiAsynctaskPager, error) {
+	pager := &CompapiAsynctaskPager{}
+	for _, opt := range opts {
+		opt(pager)
+	}
+	if pager.Order == nil {
+		pager.Order = DefaultCompapiAsynctaskOrder
+	}
+	return pager, nil
+}
+
+func (p *CompapiAsynctaskPager) ApplyFilter(query *CompapiAsynctaskQuery) (*CompapiAsynctaskQuery, error) {
+	if p.Filter != nil {
+		return p.Filter(query)
+	}
+	return query, nil
+}
+
+// CompapiAsynctaskPageList is CompapiAsynctask PageList result.
+type CompapiAsynctaskPageList struct {
+	List        []*CompapiAsynctask `json:"list"`
+	PageDetails *PageDetails        `json:"pageDetails"`
+}
+
+func (ca *CompapiAsynctaskQuery) Page(
+	ctx context.Context, pageNum uint64, pageSize uint64, opts ...CompapiAsynctaskPaginateOption,
+) (*CompapiAsynctaskPageList, error) {
+
+	pager, err := newCompapiAsynctaskPager(opts)
+	if err != nil {
+		return nil, err
+	}
+
+	if ca, err = pager.ApplyFilter(ca); err != nil {
+		return nil, err
+	}
+
+	ret := &CompapiAsynctaskPageList{}
+
+	ret.PageDetails = &PageDetails{
+		Page: pageNum,
+		Size: pageSize,
+	}
+
+	query := ca.Clone()
+	query.ctx.Fields = nil
+	count, err := query.Count(ctx)
+
+	if err != nil {
+		return nil, err
+	}
+
+	ret.PageDetails.Total = uint64(count)
+
+	if pager.Order != nil {
+		ca = ca.Order(pager.Order)
+	} else {
+		ca = ca.Order(DefaultCompapiAsynctaskOrder)
+	}
+
+	ca = ca.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
+	list, err := ca.All(ctx)
+	if err != nil {
+		return nil, err
+	}
+	ret.List = list
+
+	return ret, nil
+}
+
 type ContactPager struct {
 	Order  contact.OrderOption
 	Filter func(*ContactQuery) (*ContactQuery, error)

+ 3 - 0
ent/predicate/predicate.go

@@ -33,6 +33,9 @@ type ChatRecords func(*sql.Selector)
 // ChatSession is the predicate function for chatsession builders.
 type ChatSession func(*sql.Selector)
 
+// CompapiAsynctask is the predicate function for compapiasynctask builders.
+type CompapiAsynctask func(*sql.Selector)
+
 // Contact is the predicate function for contact builders.
 type Contact func(*sql.Selector)
 

+ 56 - 0
ent/runtime/runtime.go

@@ -13,6 +13,7 @@ import (
 	"wechat-api/ent/category"
 	"wechat-api/ent/chatrecords"
 	"wechat-api/ent/chatsession"
+	"wechat-api/ent/compapiasynctask"
 	"wechat-api/ent/contact"
 	"wechat-api/ent/creditbalance"
 	"wechat-api/ent/creditusage"
@@ -400,6 +401,61 @@ func init() {
 	chatsessionDescBotType := chatsessionFields[3].Descriptor()
 	// chatsession.DefaultBotType holds the default value on creation for the bot_type field.
 	chatsession.DefaultBotType = chatsessionDescBotType.Default.(uint8)
+	compapiasynctaskMixin := schema.CompapiAsynctask{}.Mixin()
+	compapiasynctaskMixinFields0 := compapiasynctaskMixin[0].Fields()
+	_ = compapiasynctaskMixinFields0
+	compapiasynctaskFields := schema.CompapiAsynctask{}.Fields()
+	_ = compapiasynctaskFields
+	// compapiasynctaskDescCreatedAt is the schema descriptor for created_at field.
+	compapiasynctaskDescCreatedAt := compapiasynctaskMixinFields0[1].Descriptor()
+	// compapiasynctask.DefaultCreatedAt holds the default value on creation for the created_at field.
+	compapiasynctask.DefaultCreatedAt = compapiasynctaskDescCreatedAt.Default.(func() time.Time)
+	// compapiasynctaskDescUpdatedAt is the schema descriptor for updated_at field.
+	compapiasynctaskDescUpdatedAt := compapiasynctaskMixinFields0[2].Descriptor()
+	// compapiasynctask.DefaultUpdatedAt holds the default value on creation for the updated_at field.
+	compapiasynctask.DefaultUpdatedAt = compapiasynctaskDescUpdatedAt.Default.(func() time.Time)
+	// compapiasynctask.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
+	compapiasynctask.UpdateDefaultUpdatedAt = compapiasynctaskDescUpdatedAt.UpdateDefault.(func() time.Time)
+	// compapiasynctaskDescEventType is the schema descriptor for event_type field.
+	compapiasynctaskDescEventType := compapiasynctaskFields[1].Descriptor()
+	// compapiasynctask.DefaultEventType holds the default value on creation for the event_type field.
+	compapiasynctask.DefaultEventType = compapiasynctaskDescEventType.Default.(string)
+	// compapiasynctaskDescChatID is the schema descriptor for chat_id field.
+	compapiasynctaskDescChatID := compapiasynctaskFields[2].Descriptor()
+	// compapiasynctask.DefaultChatID holds the default value on creation for the chat_id field.
+	compapiasynctask.DefaultChatID = compapiasynctaskDescChatID.Default.(string)
+	// compapiasynctaskDescOrganizationID is the schema descriptor for organization_id field.
+	compapiasynctaskDescOrganizationID := compapiasynctaskFields[3].Descriptor()
+	// compapiasynctask.OrganizationIDValidator is a validator for the "organization_id" field. It is called by the builders before save.
+	compapiasynctask.OrganizationIDValidator = compapiasynctaskDescOrganizationID.Validators[0].(func(uint64) error)
+	// compapiasynctaskDescResponseRaw is the schema descriptor for response_raw field.
+	compapiasynctaskDescResponseRaw := compapiasynctaskFields[7].Descriptor()
+	// compapiasynctask.DefaultResponseRaw holds the default value on creation for the response_raw field.
+	compapiasynctask.DefaultResponseRaw = compapiasynctaskDescResponseRaw.Default.(string)
+	// compapiasynctaskDescCallbackURL is the schema descriptor for callback_url field.
+	compapiasynctaskDescCallbackURL := compapiasynctaskFields[8].Descriptor()
+	// compapiasynctask.CallbackURLValidator is a validator for the "callback_url" field. It is called by the builders before save.
+	compapiasynctask.CallbackURLValidator = compapiasynctaskDescCallbackURL.Validators[0].(func(string) error)
+	// compapiasynctaskDescCallbackResponseRaw is the schema descriptor for callback_response_raw field.
+	compapiasynctaskDescCallbackResponseRaw := compapiasynctaskFields[9].Descriptor()
+	// compapiasynctask.DefaultCallbackResponseRaw holds the default value on creation for the callback_response_raw field.
+	compapiasynctask.DefaultCallbackResponseRaw = compapiasynctaskDescCallbackResponseRaw.Default.(string)
+	// compapiasynctaskDescModel is the schema descriptor for model field.
+	compapiasynctaskDescModel := compapiasynctaskFields[10].Descriptor()
+	// compapiasynctask.DefaultModel holds the default value on creation for the model field.
+	compapiasynctask.DefaultModel = compapiasynctaskDescModel.Default.(string)
+	// compapiasynctaskDescTaskStatus is the schema descriptor for task_status field.
+	compapiasynctaskDescTaskStatus := compapiasynctaskFields[11].Descriptor()
+	// compapiasynctask.DefaultTaskStatus holds the default value on creation for the task_status field.
+	compapiasynctask.DefaultTaskStatus = compapiasynctaskDescTaskStatus.Default.(int8)
+	// compapiasynctaskDescRetryCount is the schema descriptor for retry_count field.
+	compapiasynctaskDescRetryCount := compapiasynctaskFields[12].Descriptor()
+	// compapiasynctask.DefaultRetryCount holds the default value on creation for the retry_count field.
+	compapiasynctask.DefaultRetryCount = compapiasynctaskDescRetryCount.Default.(int8)
+	// compapiasynctaskDescLastError is the schema descriptor for last_error field.
+	compapiasynctaskDescLastError := compapiasynctaskFields[13].Descriptor()
+	// compapiasynctask.DefaultLastError holds the default value on creation for the last_error field.
+	compapiasynctask.DefaultLastError = compapiasynctaskDescLastError.Default.(string)
 	contactMixin := schema.Contact{}.Mixin()
 	contactMixinHooks2 := contactMixin[2].Hooks()
 	contact.Hooks[0] = contactMixinHooks2[0]

+ 61 - 0
ent/schema/compapi_asynctask.go

@@ -0,0 +1,61 @@
+package schema
+
+import (
+	"entgo.io/ent"
+	"entgo.io/ent/dialect/entsql"
+	"entgo.io/ent/schema"
+	"entgo.io/ent/schema/field"
+	"entgo.io/ent/schema/index"
+	"github.com/suyuan32/simple-admin-common/orm/ent/mixins"
+)
+
+// CompapiJob holds the schema definition for the CompapiJob entity.
+type CompapiAsynctask struct {
+	ent.Schema
+}
+
+// Fields of the CompapiJob.
+func (CompapiAsynctask) Fields() []ent.Field {
+
+	return []ent.Field{
+		field.String("auth_token").Annotations(entsql.WithComments(true)).Comment("发起请求者的授权token"),
+		field.String("event_type").Default("fastgpt").Annotations(entsql.WithComments(true)).Comment("请求目标类型"),
+		field.String("chat_id").Optional().Default("").Annotations(entsql.WithComments(true)).Comment("会话ID"),
+		field.Uint64("organization_id").Positive().Comment("organization_id | 租户ID"),
+		field.String("openai_base").Annotations(entsql.WithComments(true)).Comment("待请求的大模型服务地址"),
+		field.String("openai_key").Annotations(entsql.WithComments(true)).Comment("待请求的大模型服务密钥授权token"),
+		field.String("request_raw").Annotations(entsql.WithComments(true)).Comment("请求参数结构字符串"),
+		field.String("response_raw").Optional().Default("").Annotations(entsql.WithComments(true)).Comment("请求响应结构字符串"),
+		field.String("callback_url").MaxLen(255).Annotations(entsql.WithComments(true)).Comment("callback_url | 异步执行回调地址"),
+		//field.Uint64("callback_response_code").Positive().Comment("callback返回状态码"),
+		field.String("callback_response_raw").Optional().Default("").Annotations(entsql.WithComments(true)).Comment("callback返回结构字符串"),
+		//field.Int8("dist_status").Optional().Default(0).Annotations(entsql.WithComments(true)).Comment("dist status | 分发状态 0 未 1 已"),
+		//field.Time("dist_at").Optional().Annotations(entsql.WithComments(true)).Comment("Dist Time | 分发时间"),
+		field.String("model").Optional().Default("").Annotations(entsql.WithComments(true)).Comment("所用大模型"),
+		field.Int8("task_status").Optional().Default(10).Annotations(entsql.WithComments(true)).Comment("callback_status | 任务完成状态 10 任务就绪 20 请求API完成 30 请求回调完成 60 任务暂停 70 任务失败"),
+		field.Int8("retry_count").Optional().Default(0).Annotations(entsql.WithComments(true)).Comment("retry count | 重试次数"),
+		field.String("last_error").Optional().Default("").Annotations(entsql.WithComments(true)).Comment("最后一次出错信息"),
+	}
+}
+
+func (CompapiAsynctask) Mixin() []ent.Mixin {
+	return []ent.Mixin{
+		mixins.IDMixin{},
+	}
+}
+
+func (CompapiAsynctask) Indexes() []ent.Index {
+	return []ent.Index{
+		//index.Fields("dist_status"),
+		index.Fields("task_status"),
+	}
+}
+
+func (CompapiAsynctask) Edges() []ent.Edge { return []ent.Edge{} }
+
+func (CompapiAsynctask) Annotations() []schema.Annotation {
+	return []schema.Annotation{
+		entsql.WithComments(true),
+		entsql.Annotation{Table: "compapi_asynctask"},
+	}
+}

+ 360 - 0
ent/set_not_nil.go

@@ -2192,6 +2192,366 @@ func (cs *ChatSessionCreate) SetNotNilBotType(value *uint8) *ChatSessionCreate {
 }
 
 // set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilUpdatedAt(value *time.Time) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetUpdatedAt(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilUpdatedAt(value *time.Time) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetUpdatedAt(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilUpdatedAt(value *time.Time) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetUpdatedAt(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilAuthToken(value *string) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetAuthToken(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilAuthToken(value *string) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetAuthToken(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilAuthToken(value *string) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetAuthToken(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilEventType(value *string) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetEventType(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilEventType(value *string) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetEventType(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilEventType(value *string) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetEventType(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilChatID(value *string) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetChatID(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilChatID(value *string) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetChatID(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilChatID(value *string) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetChatID(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilOrganizationID(value *uint64) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetOrganizationID(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilOrganizationID(value *uint64) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetOrganizationID(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilOrganizationID(value *uint64) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetOrganizationID(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilOpenaiBase(value *string) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetOpenaiBase(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilOpenaiBase(value *string) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetOpenaiBase(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilOpenaiBase(value *string) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetOpenaiBase(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilOpenaiKey(value *string) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetOpenaiKey(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilOpenaiKey(value *string) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetOpenaiKey(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilOpenaiKey(value *string) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetOpenaiKey(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilRequestRaw(value *string) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetRequestRaw(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilRequestRaw(value *string) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetRequestRaw(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilRequestRaw(value *string) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetRequestRaw(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilResponseRaw(value *string) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetResponseRaw(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilResponseRaw(value *string) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetResponseRaw(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilResponseRaw(value *string) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetResponseRaw(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilCallbackURL(value *string) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetCallbackURL(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilCallbackURL(value *string) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetCallbackURL(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilCallbackURL(value *string) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetCallbackURL(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilCallbackResponseRaw(value *string) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetCallbackResponseRaw(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilCallbackResponseRaw(value *string) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetCallbackResponseRaw(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilCallbackResponseRaw(value *string) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetCallbackResponseRaw(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilModel(value *string) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetModel(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilModel(value *string) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetModel(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilModel(value *string) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetModel(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilTaskStatus(value *int8) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetTaskStatus(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilTaskStatus(value *int8) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetTaskStatus(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilTaskStatus(value *int8) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetTaskStatus(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilRetryCount(value *int8) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetRetryCount(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilRetryCount(value *int8) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetRetryCount(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilRetryCount(value *int8) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetRetryCount(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdate) SetNotNilLastError(value *string) *CompapiAsynctaskUpdate {
+	if value != nil {
+		return ca.SetLastError(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskUpdateOne) SetNotNilLastError(value *string) *CompapiAsynctaskUpdateOne {
+	if value != nil {
+		return ca.SetLastError(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
+func (ca *CompapiAsynctaskCreate) SetNotNilLastError(value *string) *CompapiAsynctaskCreate {
+	if value != nil {
+		return ca.SetLastError(*value)
+	}
+	return ca
+}
+
+// set field if value's pointer is not nil.
 func (c *ContactUpdate) SetNotNilUpdatedAt(value *time.Time) *ContactUpdate {
 	if value != nil {
 		return c.SetUpdatedAt(*value)

+ 3 - 0
ent/tx.go

@@ -32,6 +32,8 @@ type Tx struct {
 	ChatRecords *ChatRecordsClient
 	// ChatSession is the client for interacting with the ChatSession builders.
 	ChatSession *ChatSessionClient
+	// CompapiAsynctask is the client for interacting with the CompapiAsynctask builders.
+	CompapiAsynctask *CompapiAsynctaskClient
 	// Contact is the client for interacting with the Contact builders.
 	Contact *ContactClient
 	// CreditBalance is the client for interacting with the CreditBalance builders.
@@ -236,6 +238,7 @@ func (tx *Tx) init() {
 	tx.Category = NewCategoryClient(tx.config)
 	tx.ChatRecords = NewChatRecordsClient(tx.config)
 	tx.ChatSession = NewChatSessionClient(tx.config)
+	tx.CompapiAsynctask = NewCompapiAsynctaskClient(tx.config)
 	tx.Contact = NewContactClient(tx.config)
 	tx.CreditBalance = NewCreditBalanceClient(tx.config)
 	tx.CreditUsage = NewCreditUsageClient(tx.config)

+ 15 - 7
go.mod

@@ -20,7 +20,6 @@ require (
 	github.com/golang-jwt/jwt/v5 v5.2.1
 	github.com/gorilla/websocket v1.5.0
 	github.com/imroc/req/v3 v3.43.1
-	github.com/openai/openai-go v0.1.0-alpha.62
 	github.com/redis/go-redis/v9 v9.6.1
 	github.com/robfig/cron/v3 v3.0.1
 	github.com/russross/blackfriday v1.6.0
@@ -33,8 +32,8 @@ require (
 	github.com/suyuan32/simple-admin-core v1.3.11
 	github.com/zeromicro/go-zero v1.6.3
 	go.mongodb.org/mongo-driver v1.14.0
-	golang.org/x/crypto v0.27.0
-	golang.org/x/text v0.18.0
+	golang.org/x/crypto v0.32.0
+	golang.org/x/text v0.21.0
 	google.golang.org/protobuf v1.35.2
 	gorm.io/driver/mysql v1.5.5
 	gorm.io/gen v0.3.26
@@ -43,6 +42,12 @@ require (
 )
 
 require (
+	github.com/invopop/jsonschema v0.13.0
+	github.com/openai/openai-go v0.1.0-beta.9
+//github.com/openai/openai-go v0.1.0-alpha.62
+)
+
+require (
 	ariga.io/atlas v0.19.2 // indirect
 	filippo.io/edwards25519 v1.1.0 // indirect
 	github.com/ArtisanCloud/PowerLibs/v2 v2.0.49 // indirect
@@ -55,7 +60,9 @@ require (
 	github.com/aliyun/credentials-go v1.3.10 // indirect
 	github.com/andybalholm/brotli v1.1.0 // indirect
 	github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
+	github.com/bahlo/generic-list-go v0.2.0 // indirect
 	github.com/beorn7/perks v1.0.1 // indirect
+	github.com/buger/jsonparser v1.1.1 // indirect
 	github.com/casbin/ent-adapter v0.3.0 // indirect
 	github.com/casbin/govaluate v1.1.1 // indirect
 	github.com/casbin/redis-watcher/v2 v2.5.0 // indirect
@@ -139,6 +146,7 @@ require (
 	github.com/tidwall/pretty v1.2.1 // indirect
 	github.com/tidwall/sjson v1.2.5 // indirect
 	github.com/tjfoc/gmsm v1.4.1 // indirect
+	github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
 	github.com/xdg-go/pbkdf2 v1.0.0 // indirect
 	github.com/xdg-go/scram v1.1.2 // indirect
 	github.com/xdg-go/stringprep v1.0.4 // indirect
@@ -163,11 +171,11 @@ require (
 	go.uber.org/zap v1.27.0 // indirect
 	golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
 	golang.org/x/mod v0.17.0 // indirect
-	golang.org/x/net v0.29.0 // indirect
+	golang.org/x/net v0.34.0 // indirect
 	golang.org/x/oauth2 v0.18.0 // indirect
-	golang.org/x/sync v0.8.0 // indirect
-	golang.org/x/sys v0.25.0 // indirect
-	golang.org/x/term v0.24.0 // indirect
+	golang.org/x/sync v0.10.0 // indirect
+	golang.org/x/sys v0.29.0 // indirect
+	golang.org/x/term v0.28.0 // indirect
 	golang.org/x/time v0.6.0 // indirect
 	golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
 	google.golang.org/appengine v1.6.8 // indirect

+ 22 - 14
go.sum

@@ -108,6 +108,8 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmms
 github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
 github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
 github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
+github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
+github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
 github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
 github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -118,6 +120,8 @@ github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
 github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
 github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
 github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
+github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
+github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
 github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
 github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
 github.com/casbin/casbin/v2 v2.29.2/go.mod h1:vByNa/Fchek0KZUgG5wEsl7iFsiviAYKRtgrQfcJqHg=
@@ -353,6 +357,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
 github.com/imroc/req/v3 v3.43.1 h1:tsWAhvxik4egtHAvMlxcjaWJtHlJL8EpBqJMOm5rmyQ=
 github.com/imroc/req/v3 v3.43.1/go.mod h1:SQIz5iYop16MJxbo8ib+4LnostGCok8NQf8ToyQc2xA=
 github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
+github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
+github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
 github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
 github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
 github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
@@ -524,8 +530,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
 github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
 github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
 github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
-github.com/openai/openai-go v0.1.0-alpha.62 h1:wf1Z+ZZAlqaUBlxhE5rhXxc9hQylcDRgMU2fg+jME+E=
-github.com/openai/openai-go v0.1.0-alpha.62/go.mod h1:3SdE6BffOX9HPEQv8IL/fi3LYZ5TUpRYaqGQZbyk11A=
+github.com/openai/openai-go v0.1.0-beta.9 h1:ABpubc5yU/3ejee2GgRrbFta81SG/d7bQbB8mIdP0Xo=
+github.com/openai/openai-go v0.1.0-beta.9/go.mod h1:g461MYGXEXBVdV5SaR/5tNzNbSfwTBBefwc+LlDCK0Y=
 github.com/openzipkin/zipkin-go v0.4.2 h1:zjqfqHjUpPmB3c1GlCvvgsM1G4LkvqQbBDueDOCg/jA=
 github.com/openzipkin/zipkin-go v0.4.2/go.mod h1:ZeVkFjuuBiSy13y8vpSDCjMi9GoI3hPpCJSBx/EYFhY=
 github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
@@ -661,6 +667,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1
 github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
 github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
 github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
+github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
+github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
 github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
 github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
 github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
@@ -759,8 +767,8 @@ golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDf
 golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
 golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
 golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
-golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
-golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
+golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
+golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
 golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -828,8 +836,8 @@ golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
 golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
 golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
 golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
-golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
-golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
+golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
+golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -849,8 +857,8 @@ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
 golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
 golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
-golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
-golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
+golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
+golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
 golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -899,8 +907,8 @@ golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
-golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
-golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
+golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
 golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
@@ -915,8 +923,8 @@ golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
 golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
 golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
 golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
-golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
-golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
+golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
+golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
@@ -932,8 +940,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
 golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
 golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
-golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
-golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
+golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
+golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
 golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
 golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=

+ 10 - 16
internal/handler/chat/chat_completions_handler.go

@@ -3,7 +3,6 @@ package chat
 import (
 	"bytes"
 	"encoding/json"
-	"fmt"
 	"io"
 	"net/http"
 
@@ -33,21 +32,14 @@ import (
 
 func ChatCompletionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.CompApiReq
 		/*
-			var req types.CompApiReq
 			if err := httpx.Parse(r, &req, true); err != nil {
 				httpx.ErrorCtx(r.Context(), w, err)
 				return
 			}
-
-			l := chat.NewChatCompletionsLogic(r.Context(), svcCtx)
-			resp, err := l.ChatCompletions(&req)
-			if err != nil {
-				httpx.ErrorCtx(r.Context(), w, err)
-			} else {
-				httpx.OkJsonCtx(r.Context(), w, resp)
-			}
 		*/
+
 		// 读取请求体
 		body, err := io.ReadAll(r.Body)
 		if err != nil {
@@ -56,23 +48,25 @@ func ChatCompletionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 		}
 		// 将请求体还原,以便后续处理
 		r.Body = io.NopCloser(bytes.NewBuffer(body))
-
-		// 打印请求体
 		logx.Info(string(body))
-		var req types.CompApiReq
 		err = json.Unmarshal([]byte(string(body)), &req)
 		if err != nil {
-			fmt.Println("Error:", err)
+			httpx.ErrorCtx(r.Context(), w, err)
 			return
 		}
 		// 打印请求体
 		logx.Info(req)
+
 		l := chat.NewChatCompletionsLogic(r.Context(), svcCtx)
-		resp, err := l.ChatCompletions(&req)
+		am, resp, err := l.ChatCompletions(&req)
 		if err != nil {
 			httpx.ErrorCtx(r.Context(), w, err)
 		} else {
-			httpx.OkJsonCtx(r.Context(), w, resp)
+			if !am {
+				httpx.OkJsonCtx(r.Context(), w, resp)
+			} else {
+				httpx.OkJsonCtx(r.Context(), w, types.BaseDataInfo{Code: 0, Msg: "请求已经受理"})
+			}
 		}
 	}
 }

+ 262 - 81
internal/logic/chat/chat_completions_logic.go

@@ -2,8 +2,14 @@ package chat
 
 import (
 	"context"
+	"encoding/json"
 	"errors"
+	"fmt"
+	"net"
+	"net/url"
+	"regexp"
 	"strconv"
+	"strings"
 
 	"wechat-api/ent"
 	"wechat-api/internal/svc"
@@ -25,6 +31,21 @@ type ChatCompletionsLogic struct {
 	svcCtx *svc.ServiceContext
 }
 
+type FastgptChatLogic struct {
+	ChatCompletionsLogic
+}
+
+type MismatchChatLogic struct {
+	ChatCompletionsLogic
+}
+
+type baseLogicWorkflow interface {
+	AppendAsyncRequest(apiKeyObj *ent.ApiKey, req *types.CompApiReq) error
+	DoSyncRequest(apiKeyObj *ent.ApiKey, req *types.CompApiReq) (*types.CompOpenApiResp, error)
+	AppendUsageDetailLog(authToken string, req *types.CompApiReq, resp *types.CompOpenApiResp) error
+	AdjustRequest(req *types.CompApiReq, apiKeyObj *ent.ApiKey)
+}
+
 func NewChatCompletionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChatCompletionsLogic {
 	return &ChatCompletionsLogic{
 		Logger: logx.WithContext(ctx),
@@ -32,57 +53,184 @@ func NewChatCompletionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *C
 		svcCtx: svcCtx}
 }
 
-func (l *ChatCompletionsLogic) ChatCompletions(req *types.CompApiReq) (resp *types.CompOpenApiResp, err error) {
+func (l *FastgptChatLogic) AdjustRequest(req *types.CompApiReq, apiKeyObj *ent.ApiKey) {
+
+	l.ChatCompletionsLogic.AdjustRequest(req, apiKeyObj) //先父类的参数调整
+
+	if req.EventType != "fastgpt" {
+		return
+	}
+	if len(req.Model) > 0 {
+		if req.Variables == nil {
+			req.Variables = make(map[string]string)
+		}
+		req.Variables["model"] = req.Model
+	}
+
+	if len(req.ChatId) > 0 && len(req.FastgptChatId) == 0 {
+		req.FastgptChatId = req.ChatId
+	} else if len(req.ChatId) == 0 && len(req.FastgptChatId) > 0 {
+		req.ChatId = req.FastgptChatId
+	}
+}
+
+func (l *ChatCompletionsLogic) ChatCompletions(req *types.CompApiReq) (asyncMode bool, resp *types.CompOpenApiResp, err error) {
 	// todo: add your logic here and delete this line
 
-	/*
-	   1.鉴权获得token
-	   2.必要参数检测及转换
-	   3. 根据event_type选择不同处理路由
-	*/
 	var (
 		apiKeyObj *ent.ApiKey
 		ok        bool
 	)
-	workToken := compapi.GetWorkTokenByID(req.EventType, req.WorkId)
+	asyncMode = false
+
+	//从上下文中获取鉴权中间件埋下的apiAuthInfo
 	apiKeyObj, ok = contextkey.AuthTokenInfoKey.GetValue(l.ctx)
 	if !ok {
-		return nil, errors.New("content get token err")
+		return asyncMode, nil, errors.New("content get auth info err")
 	}
-	if req.WorkId == "TEST_DOUYIN" || req.WorkId == "travel" { //临时加
-		apiKeyObj.OpenaiBase = "http://cn-agent.gkscrm.com/api/v1/"
-		workToken = "fastgpt-jsMmQKEM5uX7tDimT1zHlZHkBhMHRT2k61YaxyDJRZTUHehID7sG8BKXADNIU"
-	}
-
+	//微调apiKeyObj的openaikey
+	//apiKeyObjAdjust(req.EventType, req.WorkId, apiKeyObj)
 	/*
 		fmt.Println("=========================================")
 		fmt.Printf("In ChatCompletion Get Token Info:\nKey:'%s'\n", apiKeyObj.Key)
-		fmt.Printf("Title:'%s'\n", apiKeyObj.Title)
-		fmt.Printf("OpenaiBase:'%s'\n", apiKeyObj.OpenaiBase)
-		fmt.Printf("OpenaiKey:'%s'\n", apiKeyObj.OpenaiKey)
-		fmt.Printf("workToken:'%s' because %s/%s\n", workToken, req.EventType, req.WorkId)
+		fmt.Printf("Auth Token:'%s'\n", apiKeyObj.Key)
+		fmt.Printf("ApiKey AgentID:%d\n", apiKeyObj.AgentID)
+		fmt.Printf("ApiKey APIBase:'%s'\n", apiKeyObj.Edges.Agent.APIBase)
+		fmt.Printf("ApiKey APIKey:'%s'\n", apiKeyObj.Edges.Agent.APIKey)
+		fmt.Printf("ApiKey Type:%d\n", apiKeyObj.Edges.Agent.Type)
+		fmt.Printf("ApiKey Model:'%s'\n", apiKeyObj.Edges.Agent.Model)
+		fmt.Printf("EventType:'%s'\n", req.EventType)
+		fmt.Printf("req.ChatId:'%s VS req.FastgptChatId:'%s'\n", req.ChatId, req.FastgptChatId)
 		fmt.Println("=========================================")
 	*/
 
-	if len(apiKeyObj.OpenaiBase) == 0 || len(workToken) == 0 {
-		return nil, errors.New("not auth info")
+	//根据请求产生相关的工作流接口集
+	wf, err := l.getLogicWorkflow(apiKeyObj, req)
+	if err != nil {
+		return false, nil, err
+	}
+	//微调部分请求参数
+	wf.AdjustRequest(req, apiKeyObj)
+
+	if isAsyncReqest(req) { //异步请求处理模式
+		asyncMode = true
+		err = wf.AppendAsyncRequest(apiKeyObj, req)
+	} else { //同步请求处理模式
+		resp, err = wf.DoSyncRequest(apiKeyObj, req)
+		if err == nil && resp != nil && len(resp.Choices) > 0 {
+			wf.AppendUsageDetailLog(apiKeyObj.Key, req, resp) //请求记录
+		} else if resp != nil && len(resp.Choices) == 0 {
+			err = errors.New("返回结果缺失,请检查访问地址及权限")
+		}
+	}
+	return asyncMode, resp, err
+}
+
+func (l *ChatCompletionsLogic) getLogicWorkflow(apiKeyObj *ent.ApiKey, req *types.CompApiReq) (baseLogicWorkflow, error) {
+	var (
+		err error
+		wf  baseLogicWorkflow
+	)
+
+	if apiKeyObj.Edges.Agent.Type != 2 {
+		err = fmt.Errorf("api agent type not support(%d)", apiKeyObj.Edges.Agent.Type)
+	} else if req.EventType == "mismatch" {
+		wf = &MismatchChatLogic{ChatCompletionsLogic: *l}
+	} else {
+		wf = &FastgptChatLogic{ChatCompletionsLogic: *l}
+	}
+	return wf, err
+}
+
+func (l *ChatCompletionsLogic) AdjustRequest(req *types.CompApiReq, apiKeyObj *ent.ApiKey) {
+
+	if len(req.EventType) == 0 {
+		req.EventType = "fastgpt"
 	}
 
-	apiResp, err := l.workForFastgpt(req, workToken, apiKeyObj.OpenaiBase)
-	if err == nil && apiResp != nil {
-		l.doRequestLog(req, apiResp) //请求记录
+	if len(req.Model) == 0 && len(apiKeyObj.Edges.Agent.Model) > 0 {
+		req.Model = apiKeyObj.Edges.Agent.Model
 	}
 
-	return apiResp, err
+	//异步任务相关参数调整
+	if req.IsBatch {
+		//流模式暂时不支持异步模式
+		//Callback格式非法则取消批量模式
+		if req.Stream || !IsValidURL(&req.Callback, true) {
+			req.IsBatch = false
+		}
+	}
 }
 
-func (l *ChatCompletionsLogic) doRequestLog(req *types.CompApiReq, resp *types.CompOpenApiResp) error {
-	authToken, ok := contextkey.OpenapiTokenKey.GetValue(l.ctx)
-	if !ok {
-		return errors.New("content get auth token err")
+func (l *ChatCompletionsLogic) DoSyncRequest(apiKeyObj *ent.ApiKey, req *types.CompApiReq) (*types.CompOpenApiResp, error) {
+	//return compapi.NewFastgptChatCompletions(l.ctx, apiKeyObj.Edges.Agent.APIKey, apiKeyObj.Edges.Agent.APIBase, req)
+	return compapi.NewClient(l.ctx, compapi.WithApiBase(apiKeyObj.Edges.Agent.APIBase),
+		compapi.WithApiKey(apiKeyObj.Edges.Agent.APIKey)).
+		Chat(req)
+}
+
+func (l *ChatCompletionsLogic) AppendAsyncRequest(apiKeyObj *ent.ApiKey, req *types.CompApiReq) error {
+
+	rawReqBs, err := json.Marshal(*req)
+	if err != nil {
+		return err
 	}
+	rawReqStr := string(rawReqBs)
+	res, err := l.svcCtx.DB.CompapiAsynctask.Create().
+		SetNotNilAuthToken(&apiKeyObj.Key).
+		SetNotNilOpenaiBase(&apiKeyObj.Edges.Agent.APIBase).
+		SetNotNilOpenaiKey(&apiKeyObj.Edges.Agent.APIKey).
+		SetNotNilOrganizationID(&apiKeyObj.OrganizationID).
+		SetNotNilEventType(&req.EventType).
+		SetNillableModel(&req.Model).
+		SetNillableChatID(&req.ChatId).
+		SetNotNilRequestRaw(&rawReqStr).
+		SetNotNilCallbackURL(&req.Callback).
+		Save(l.ctx)
 
-	return l.appendUsageDetailLog(authToken, req, resp)
+	if err == nil {
+		logx.Infof("appendAsyncRequest succ,get id:%d", res.ID)
+	}
+	return err
+}
+
+func (l *ChatCompletionsLogic) AppendUsageDetailLog(authToken string, req *types.CompApiReq, resp *types.CompOpenApiResp) error {
+
+	logType := 5
+	rawReqResp := custom_types.OriginalData{Request: req, Response: resp}
+	tmpId := 0
+	tmpId, _ = strconv.Atoi(resp.ID)
+	sessionId := uint64(tmpId)
+	orgId := uint64(0)
+	apiKeyObj, ok := contextkey.AuthTokenInfoKey.GetValue(l.ctx)
+	if ok {
+		orgId = apiKeyObj.OrganizationID
+	}
+	promptTokens := uint64(resp.Usage.PromptTokens)
+	completionToken := uint64(resp.Usage.CompletionTokens)
+	totalTokens := promptTokens + completionToken
+
+	msgContent := getMessageContentStr(req.Messages[0].Content)
+
+	_, _, _ = logType, sessionId, totalTokens
+	res, err := l.svcCtx.DB.UsageDetail.Create().
+		SetNotNilType(&logType).
+		SetNotNilBotID(&authToken).
+		SetNotNilReceiverID(&req.EventType).
+		SetNotNilSessionID(&sessionId).
+		SetNillableRequest(&msgContent).
+		SetNillableResponse(&resp.Choices[0].Message.Content).
+		SetNillableOrganizationID(&orgId).
+		SetOriginalData(rawReqResp).
+		SetNillablePromptTokens(&promptTokens).
+		SetNillableCompletionTokens(&completionToken).
+		SetNillableTotalTokens(&totalTokens).
+		Save(l.ctx)
+
+	if err == nil { //插入UsageDetai之后再统计UsageTotal
+		l.updateUsageTotal(authToken, res.ID, orgId)
+	}
+	return err
 }
 
 func (l *ChatCompletionsLogic) getUsagetotalIdByToken(authToken string) (uint64, error) {
@@ -150,72 +298,105 @@ func (l *ChatCompletionsLogic) sumTotalTokensByAuthToken(authToken string) (uint
 	return totalTokens, err
 }
 
-func (l *ChatCompletionsLogic) appendUsageDetailLog(authToken string, req *types.CompApiReq, resp *types.CompOpenApiResp) error {
+func apiKeyObjAdjust(eventType string, workId string, obj *ent.ApiKey) {
+	if eventType != "fastgpt" {
+		return
+	}
+	obj.OpenaiKey, _ = compapi.GetWorkInfoByID(eventType, workId)
+}
 
-	logType := 5
-	workIdx := compapi.GetWorkIdxByID(req.EventType, req.WorkId)
-	rawReqResp := custom_types.OriginalData{Request: req, Response: resp}
+// 合法域名正则(支持通配符、中文域名等场景按需调整)
+var domainRegex = regexp.MustCompile(
+	// 多级域名(如 example.com)
+	`^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,63}$` +
+		`|` +
+		// 单级域名(如 localhost 或 mytest-svc)
+		`^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$`,
+)
 
-	tmpId := 0
-	tmpId, _ = strconv.Atoi(resp.ID)
-	sessionId := uint64(tmpId)
-	orgId := uint64(0)
-	apiKeyObj, ok := contextkey.AuthTokenInfoKey.GetValue(l.ctx)
-	if ok {
-		orgId = apiKeyObj.OrganizationID
+func IsValidURL(input *string, adjust bool) bool {
+	// 空值直接返回
+	if *input == "" {
+		return false
+	}
+	inputStr := *input
+
+	// --- 预处理输入:自动补全协议 ---
+	// 若输入不包含协议头,默认添加 http://
+	if !strings.Contains(*input, "://") {
+		inputStr = "http://" + *input
+	}
+
+	// --- 解析 URL ---
+	u, err := url.Parse(inputStr)
+	if err != nil {
+		return false
+	}
+
+	// --- 校验协议 ---
+	// 只允许常见协议(按需扩展)
+	switch u.Scheme {
+	case "http", "https", "ftp", "ftps":
+	default:
+		return false
+	}
+
+	// --- 拆分 Host 和 Port ---
+	host, port, err := net.SplitHostPort(u.Host)
+	if err != nil {
+		// 无端口时,整个 Host 作为主机名
+		host = u.Host
+		port = ""
+	}
+
+	// --- 校验主机名 ---
+	// 场景1:IPv4 或 IPv6
+	if ip := net.ParseIP(host); ip != nil {
+		// 允许私有或保留 IP(按需调整)
+		// 示例中允许所有合法 IP
+	} else {
+		// 场景2:域名(包括 localhost)
+		if !domainRegex.MatchString(host) {
+			return false
+		}
 	}
-	promptTokens := uint64(resp.Usage.PromptTokens)
-	completionToken := uint64(resp.Usage.CompletionTokens)
-	totalTokens := promptTokens + completionToken
 
-	msgContent := ""
-	switch val := req.Messages[0].Content.(type) {
+	// --- 校验端口 ---
+	if port != "" {
+		p, err := net.LookupPort("tcp", port) // 动态获取端口(如 "http" 对应 80)
+		if err != nil {
+			// 直接尝试解析为数字端口
+			numPort, err := strconv.Atoi(port)
+			if err != nil || numPort < 1 || numPort > 65535 {
+				return false
+			}
+		} else if p == 0 { // 动态端口为 0 时无效
+			return false
+		}
+	}
+	if adjust {
+		*input = inputStr
+	}
+	return true
+}
+
+func getMessageContentStr(input any) string {
+	str := ""
+	switch val := input.(type) {
 	case string:
-		msgContent = val
+		str = val
 	case []interface{}:
 		if len(val) > 0 {
 			if valc, ok := val[0].(map[string]interface{}); ok {
 				if valcc, ok := valc["text"]; ok {
-					msgContent, _ = valcc.(string)
+					str, _ = valcc.(string)
 				}
 			}
 		}
 	}
-
-	res, err := l.svcCtx.DB.UsageDetail.Create().
-		SetNotNilType(&logType).
-		SetNotNilBotID(&authToken).
-		SetNotNilReceiverID(&req.EventType).
-		SetNotNilSessionID(&sessionId).
-		SetNillableApp(&workIdx).
-		//SetNillableRequest(&req.Messages[0].Content).
-		SetNillableRequest(&msgContent).
-		SetNillableResponse(&resp.Choices[0].Message.Content).
-		SetNillableOrganizationID(&orgId).
-		SetOriginalData(rawReqResp).
-		SetNillablePromptTokens(&promptTokens).
-		SetNillableCompletionTokens(&completionToken).
-		SetNillableTotalTokens(&totalTokens).
-		Save(l.ctx)
-
-	if err == nil { //插入UsageDetai之后再统计UsageTotal
-		l.updateUsageTotal(authToken, res.ID, orgId)
-	}
-	return err
+	return str
 }
 
-func (l *ChatCompletionsLogic) workForFastgpt(req *types.CompApiReq, apiKey string, apiBase string) (resp *types.CompOpenApiResp, err error) {
-
-	//apiKey := "fastgpt-d2uehCb2T40h9chNGjf4bpFrVKmMkCFPbrjfVLZ6DAL2zzqzOFJWP"
-	if len(req.ChatId) > 0 && len(req.FastgptChatId) == 0 {
-		req.FastgptChatId = req.ChatId
-	}
-	if len(req.Model) > 0 {
-		if req.Variables == nil {
-			req.Variables = make(map[string]string)
-		}
-		req.Variables["model"] = req.Model
-	}
-	return compapi.NewFastgptChatCompletions(l.ctx, apiKey, apiBase, req)
-
+func isAsyncReqest(req *types.CompApiReq) bool {
+	return req.IsBatch
 }

+ 27 - 10
internal/middleware/openauthority_middleware.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"encoding/json"
 	"errors"
+	"fmt"
 	"net/http"
 
 	"wechat-api/ent"
@@ -50,7 +51,7 @@ func (m *OpenAuthorityMiddleware) checkTokenUserInfo(ctx context.Context, authTo
 
 	//首先从redis取数据
 	apiKeyObj, rc, err = m.getTokenUserInfoByRds(ctx, authToken)
-	if rc <= 0 || err != nil { //无法获得后再从数据库获得	{
+	if rc <= 0 || err != nil { //无法获得后再从数据库获得
 
 		rc = 0
 		err = nil
@@ -64,9 +65,9 @@ func (m *OpenAuthorityMiddleware) checkTokenUserInfo(ctx context.Context, authTo
 		fromId = 2
 	}
 
-	/*
-		if err == nil {
+	if err == nil {
 
+		/*
 			fromStr := ""
 			switch fromId {
 			case 1:
@@ -74,15 +75,22 @@ func (m *OpenAuthorityMiddleware) checkTokenUserInfo(ctx context.Context, authTo
 			case 2:
 				fromStr = "RDS"
 			}
+
 			fmt.Println("=========================================>>>")
 			fmt.Printf("In checkTokenUserInfo Get Token Info From %s\n", fromStr)
-			fmt.Printf("Key:'%s'\n", apiKeyObj.Key)
-			fmt.Printf("Title:'%s'\n", apiKeyObj.Title)
-			fmt.Printf("OpenaiBase:'%s'\n", apiKeyObj.OpenaiBase)
-			fmt.Printf("OpenaiKey:'%s'\n", apiKeyObj.OpenaiKey)
+			fmt.Printf("Auth Token:'%s'\n", apiKeyObj.Key)
+			fmt.Printf("AgentID:%d\n", apiKeyObj.AgentID)
+			fmt.Printf("APIBase:'%s'\n", apiKeyObj.Edges.Agent.APIBase)
+			fmt.Printf("APIKey:'%s'\n", apiKeyObj.Edges.Agent.APIKey)
+			fmt.Printf("Type:%d\n", apiKeyObj.Edges.Agent.Type)
+			fmt.Printf("Model:'%s'\n", apiKeyObj.Edges.Agent.Model)
+			//fmt.Println(typekit.PrettyPrint(apiKeyObj))
+			//fmt.Printf("OpenaiBase:'%s'\n", apiKeyObj.OpenaiBase)
+			//fmt.Printf("OpenaiKey:'%s'\n", apiKeyObj.OpenaiKey)
 			fmt.Println("<<<=========================================")
-		}
-	*/
+		*/
+
+	}
 	return apiKeyObj, rc, err
 }
 
@@ -98,6 +106,7 @@ func (m *OpenAuthorityMiddleware) getTokenUserInfoByRds(ctx context.Context, aut
 
 	rcode := -1
 	result := ent.ApiKey{}
+	m.Rds.Del(ctx, compapi.APIAuthInfoKey) //for debug
 	jsonStr, err := m.Rds.HGet(ctx, compapi.APIAuthInfoKey, authToken).Result()
 	if errors.Is(err, redis.Nil) {
 		rcode = 0 //key not exist
@@ -117,9 +126,13 @@ func (m *OpenAuthorityMiddleware) getTokenUserInfoByDb(ctx context.Context, logi
 	var predicates []predicate.ApiKey
 	predicates = append(predicates, apikey.KeyEQ(loginToken))
 	val, err := m.DB.ApiKey.Query().Where(predicates...).WithAgent().Only(ctx)
+	//val, err := m.DB.ApiKey.Query().Where(predicates...).First(ctx)
 	if err != nil {
 		return nil, rcode, err
 	}
+	if val.Edges.Agent == nil {
+		return nil, rcode, fmt.Errorf("edge get agent info is nil by agentid:%d", val.AgentID)
+	}
 	return val, 1, nil
 }
 
@@ -138,8 +151,12 @@ func (m *OpenAuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc
 			httpx.Error(w, errorx.NewApiError(http.StatusForbidden, "无法获取合适的授权信息"))
 			return
 		}
+		if len(apiKeyObj.OpenaiBase) == 0 {
+			httpx.Error(w, errorx.NewApiError(http.StatusForbidden, "缺失OpenaiBase"))
+			return
+		}
+
 		ctx = contextkey.AuthTokenInfoKey.WithValue(ctx, apiKeyObj)
-		ctx = contextkey.OpenapiTokenKey.WithValue(ctx, authToken)
 
 		newReq := r.WithContext(ctx)
 		// Passthrough to next handler if need

+ 19 - 0
internal/types/compapi.go

@@ -0,0 +1,19 @@
+package types
+
+import "encoding/json"
+
+func (me *CompApiReq) ToBytes() ([]byte, error) {
+	return json.Marshal(me)
+}
+
+func (me *CompOpenApiResp) ToBytes() ([]byte, error) {
+	return json.Marshal(me)
+}
+
+func (me *CompOpenApiResp) ToString() (string, error) {
+	bs, err := me.ToBytes()
+	if err != nil {
+		return "", err
+	}
+	return string(bs), nil
+}

+ 29 - 6
internal/types/types.go

@@ -1956,6 +1956,8 @@ type StdCompApiReq struct {
 	Messages []StdCompMessage `json:"messages"`
 	//Stream 是否流式输出
 	Stream bool `json:"stream,default=false"`
+	//格式化输出定义
+	ResponseFormat interface{} `json:"response_format,omitempty"`
 }
 
 // 关于工作流配置的请求信息
@@ -1964,25 +1966,25 @@ type CompCtlReq struct {
 	//EventType事件类型
 	EventType string `json:"event_type,default=fastgpt"`
 	//WorkId工作流ID
-	WorkId string `json:"work_id"`
+	WorkId string `json:"work_id,optional,omitempty"`
 	//IsBatch 是同步还是异步,默认及取值false表明同步
 	IsBatch bool `json:"is_batch,default=false"`
 	//异步回调地址
-	Callback string `json:"callback,optional"`
+	Callback string `json:"callback,optional,omitempty"`
 }
 
 // swagger:model FastGptSpecReq
 type FastGptSpecReq struct {
 	//ChatId
-	ChatId string `json:"chat_id,optional"`
+	ChatId string `json:"chat_id,optional,omitempty"`
 	//FastgptChatId
-	FastgptChatId string `json:"chatId,optional"`
+	FastgptChatId string `json:"chatId,optional,omitempty"`
 	//ResponseChatItemId
-	ResponseChatItemId string `json:"response_chat_item_id,optional"`
+	ResponseChatItemId string `json:"response_chat_item_id,optional,omitempty"`
 	//Detail 详情开关
 	Detail bool `json:"detail,default=false"`
 	//Variables
-	Variables map[string]string `json:"variables,optional"`
+	Variables map[string]string `json:"variables,optional,omitempty"`
 }
 
 type StdCompMessage struct {
@@ -1995,6 +1997,7 @@ type StdCompMessage struct {
 type CompOpenApiResp struct {
 	StdCompApiResp
 	FastgptSpecResp
+	FastgptErrResp
 }
 
 // swagger:model StdCompApiResp
@@ -2027,6 +2030,26 @@ type FastgptSpecResp struct {
 	NewVariables map[string]interface{}   `json:"newVariables,omitempty"`
 }
 
+// swagger:model FastgptErrResp
+type FastgptErrResp struct {
+	FgtErrCode      *int    `json:"code,omitempty"`
+	FgtErrStatusTxt *string `json:"statusText,omitempty"`
+	FgtErrMessage   *string `json:"message,omitempty"`
+}
+
+// swagger:model DeepseekErrResp
+type DeepseekErrResp struct {
+	DSErr DeepseekErrInfo `json:"error,omitempty"`
+}
+
+// swagger:model DeepseekErrInfo
+type DeepseekErrInfo struct {
+	Message string      `json:"message,omitempty"`
+	Type    string      `json:"type,omitempty"`
+	Code    string      `json:"code,omitempty"`
+	Param   interface{} `json:"param,omitempty"`
+}
+
 type ChatCompletionAudio struct {
 	// Unique identifier for this audio response.
 	ID string `json:"id"`

+ 197 - 0
internal/utils/compapi/base.go

@@ -0,0 +1,197 @@
+package compapi
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"net/http"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/contextkey"
+
+	"github.com/invopop/jsonschema"
+	"github.com/openai/openai-go"
+	"github.com/openai/openai-go/option"
+	"github.com/openai/openai-go/packages/ssestream"
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+type ClientConfig struct {
+	ApiKey  string
+	ApiBase string
+}
+type ClientOption func(*ClientConfig)
+
+func WithApiKey(ApiKey string) ClientOption {
+	return func(cfg *ClientConfig) {
+		cfg.ApiKey = ApiKey
+	}
+}
+func WithApiBase(ApiBase string) ClientOption {
+	return func(cfg *ClientConfig) {
+		cfg.ApiBase = ApiBase
+	}
+}
+
+type clientActionFace interface {
+	DoRequest(req *types.CompApiReq) (*types.CompOpenApiResp, error)
+	DoRequestStream(req *types.CompApiReq) (*types.CompOpenApiResp, error)
+	BuildRequest(req *types.CompApiReq) error
+	CallbackPrepare(params any) ([]byte, error)
+}
+
+type Client struct {
+	OAC    *openai.Client
+	Config ClientConfig
+	ctx    context.Context
+}
+
+func NewClient(ctx context.Context, opts ...ClientOption) *Client {
+
+	client := Client{}
+	for _, opt := range opts {
+		opt(&client.Config)
+	}
+	client.NewOAC() //初始化openai client
+	client.ctx = ctx
+	return &client
+}
+
+func (me *Client) getClientActFace(clientType string) (clientActionFace, error) {
+	var (
+		err     error
+		actFace clientActionFace
+	)
+
+	switch clientType {
+	case "mismatch":
+		actFace = &MismatchClient{StdClient: StdClient{Client: me}}
+	default:
+		actFace = &FastgptClient{StdClient: StdClient{Client: me}}
+	}
+	return actFace, err
+}
+
+func (me *Client) NewOAC() {
+	opts := []option.RequestOption{}
+	if len(me.Config.ApiKey) > 0 {
+		opts = append(opts, option.WithAPIKey(me.Config.ApiKey))
+	}
+	if len(me.Config.ApiBase) > 0 {
+		opts = append(opts, option.WithBaseURL(me.Config.ApiBase))
+	}
+	oac := openai.NewClient(opts...)
+	me.OAC = &oac
+}
+
+func (me *Client) Callback(clientType string, callbackUrl string, params any) (map[string]any, error) {
+	actFace, err := me.getClientActFace(clientType)
+	if err != nil {
+		return nil, err
+	}
+	/*
+		switch actFace.(type) {
+		case *MismatchClient:
+			fmt.Printf("MismatchClient.Callback() for EventType:'%s'\n", clientType)
+		case *FastgptClient:
+			fmt.Printf("FastgptClient.Callback() for EventType:'%s'\n", clientType)
+		default:
+			fmt.Printf("maybe StdClient.Callback() for EventType:'%s'\n", clientType)
+		}
+	*/
+	var newParams []byte
+	if newParams, err = actFace.CallbackPrepare(params); err != nil {
+		return nil, err
+	}
+	//Post(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption)
+	resp := map[string]any{}
+	err = me.OAC.Post(me.ctx, callbackUrl, newParams, &resp)
+	if err != nil {
+		return nil, err
+	}
+	return resp, nil
+}
+
+func (me *Client) Chat(chatInfo *types.CompApiReq) (*types.CompOpenApiResp, error) {
+	var (
+		err     error
+		actFace clientActionFace
+		apiResp *types.CompOpenApiResp
+	)
+	actFace, err = me.getClientActFace(chatInfo.EventType)
+	if err != nil {
+		return nil, err
+	}
+	/*
+		switch actFace.(type) {
+		case *MismatchClient:
+			fmt.Printf("MismatchClient.Chat() for EventType:'%s'\n", chatInfo.EventType)
+		case *FastgptClient:
+			fmt.Printf("FastgptClient.Chat() for EventType:'%s'\n", chatInfo.EventType)
+		default:
+			fmt.Printf("maybe StdClient.Chat() for EventType:'%s'\n", chatInfo.EventType)
+		}
+	*/
+
+	err = actFace.BuildRequest(chatInfo)
+	if err != nil {
+		return nil, err
+	}
+	if chatInfo.Stream {
+		apiResp, err = actFace.DoRequestStream(chatInfo)
+	} else {
+		apiResp, err = actFace.DoRequest(chatInfo)
+	}
+	return apiResp, err
+}
+
+func GenerateSchema[T any]() interface{} {
+	// Structured Outputs uses a subset of JSON schema
+	// These flags are necessary to comply with the subset
+	reflector := jsonschema.Reflector{
+		AllowAdditionalProperties: false,
+		DoNotReference:            true,
+	}
+	var v T
+	schema := reflector.Reflect(v)
+	return schema
+}
+
+func getHttpResponseTools(ctx context.Context) (*http.ResponseWriter, *http.Flusher, error) {
+	hw, ok := contextkey.HttpResponseWriterKey.GetValue(ctx) //context取出http.ResponseWriter
+	if !ok {
+		return nil, nil, errors.New("content get http writer err")
+	}
+	flusher, ok := (hw).(http.Flusher)
+	if !ok {
+		return nil, nil, errors.New("streaming unsupported")
+	}
+	return &hw, &flusher, nil
+}
+
+func streamOut(ctx context.Context, res *http.Response) {
+	var ehw http.ResponseWriter
+	hw, flusher, err := getHttpResponseTools(ctx)
+	if err != nil {
+		http.Error(ehw, "Streaming unsupported!", http.StatusInternalServerError)
+	}
+
+	//获取API返回结果流
+	chatStream := ssestream.NewStream[ApiRespStreamChunk](ApiRespStreamDecoder(res), err)
+	defer chatStream.Close()
+
+	//设置流式输出头 http1.1
+	(*hw).Header().Set("Content-Type", "text/event-stream;charset=utf-8")
+	(*hw).Header().Set("Connection", "keep-alive")
+	(*hw).Header().Set("Cache-Control", "no-cache")
+
+	for chatStream.Next() {
+		chunk := chatStream.Current()
+		fmt.Fprintf((*hw), "data:%s\n\n", chunk.Data.RAW)
+		(*flusher).Flush()
+		//time.Sleep(1 * time.Millisecond)
+	}
+	fmt.Fprintf((*hw), "data:%s\n\n", "[DONE]")
+	(*flusher).Flush()
+
+	httpx.Ok((*hw))
+}

+ 1 - 1
internal/utils/compapi/config.go

@@ -13,7 +13,7 @@ const (
 
 type workIdInfo struct {
 	Id  string
-	Idx int
+	Idx uint
 }
 
 var fastgptWorkIdMap = map[string]workIdInfo{

+ 5 - 0
internal/utils/compapi/fastgpt.go

@@ -0,0 +1,5 @@
+package compapi
+
+type FastgptClient struct {
+	StdClient
+}

+ 46 - 14
internal/utils/compapi/func.go

@@ -16,20 +16,41 @@ import (
 	"github.com/zeromicro/go-zero/rest/httpx"
 )
 
+type StdChatClient struct {
+	*openai.Client
+}
+
+func NewStdChatClient(apiKey string, apiBase string) *StdChatClient {
+	opts := []option.RequestOption{}
+	if len(apiKey) > 0 {
+		opts = append(opts, option.WithAPIKey(apiKey))
+	}
+	opts = append(opts, option.WithBaseURL(apiBase))
+	client := openai.NewClient(opts...)
+	return &StdChatClient{&client}
+}
+
 func NewAiClient(apiKey string, apiBase string) *openai.Client {
-	return openai.NewClient(option.WithAPIKey(apiKey),
-		option.WithBaseURL(apiBase))
+	opts := []option.RequestOption{}
+	if len(apiKey) > 0 {
+		opts = append(opts, option.WithAPIKey(apiKey))
+	}
+	opts = append(opts, option.WithBaseURL(apiBase))
+	client := openai.NewClient(opts...)
+	return &client
 }
 
 func NewFastgptClient(apiKey string) *openai.Client {
 	//http://fastgpt.ascrm.cn/api/v1/
-	return openai.NewClient(option.WithAPIKey(apiKey),
+	client := openai.NewClient(option.WithAPIKey(apiKey),
 		option.WithBaseURL("http://fastgpt.ascrm.cn/api/v1/"))
+	return &client
 }
 
 func NewDeepSeekClient(apiKey string) *openai.Client {
-	return openai.NewClient(option.WithAPIKey(apiKey),
+	client := openai.NewClient(option.WithAPIKey(apiKey),
 		option.WithBaseURL("https://api.deepseek.com"))
+	return &client
 }
 
 func DoChatCompletions(ctx context.Context, client *openai.Client, chatInfo *types.CompApiReq) (*types.CompOpenApiResp, error) {
@@ -43,14 +64,17 @@ func DoChatCompletions(ctx context.Context, client *openai.Client, chatInfo *typ
 		return nil, err
 	}
 	//fmt.Printf("In DoChatCompletions, req: '%s'\n", string(jsonBytes))
+	//也许应该对请求体不规范成员名进行检查
 	customResp := types.CompOpenApiResp{}
 	reqBodyOps := option.WithRequestBody("application/json", jsonBytes)
 	respBodyOps := option.WithResponseBodyInto(&customResp)
 	if _, err = client.Chat.Completions.New(ctx, emptyParams, reqBodyOps, respBodyOps); err != nil {
 		return nil, err
 	}
+	if customResp.FgtErrCode != nil && customResp.FgtErrStatusTxt != nil { //针对fastgpt出错但New()不返回错误的情况
+		return nil, fmt.Errorf("%s(%d)", *customResp.FgtErrStatusTxt, *customResp.FgtErrCode)
+	}
 	return &customResp, nil
-
 }
 
 func DoChatCompletionsStream(ctx context.Context, client *openai.Client, chatInfo *types.CompApiReq) (res *types.CompOpenApiResp, err error) {
@@ -110,6 +134,12 @@ func NewChatCompletions(ctx context.Context, client *openai.Client, chatInfo *ty
 	}
 }
 
+func NewMismatchChatCompletions(ctx context.Context, apiKey string, apiBase string, chatInfo *types.CompApiReq) (*types.CompOpenApiResp, error) {
+
+	client := NewAiClient(apiKey, apiBase)
+	return NewChatCompletions(ctx, client, chatInfo)
+}
+
 func NewFastgptChatCompletions(ctx context.Context, apiKey string, apiBase string, chatInfo *types.CompApiReq) (*types.CompOpenApiResp, error) {
 
 	client := NewAiClient(apiKey, apiBase)
@@ -190,20 +220,22 @@ func DoChatCompletionsStreamOld(ctx context.Context, client *openai.Client, chat
 	return nil, nil
 }
 
-// 获取workToken
-func GetWorkTokenByID(eventType string, workId string) string {
+func GetWorkInfoByID(eventType string, workId string) (string, uint) {
 	val, exist := fastgptWorkIdMap[workId]
 	if !exist {
 		val = fastgptWorkIdMap["default"]
 	}
-	return val.Id
+	return val.Id, val.Idx
+}
+
+// 获取workToken
+func GetWorkTokenByID(eventType string, workId string) string {
+	id, _ := GetWorkInfoByID(eventType, workId)
+	return id
 }
 
 // 获取workIdx
-func GetWorkIdxByID(eventType string, workId string) int {
-	val, exist := fastgptWorkIdMap[workId]
-	if !exist {
-		val = fastgptWorkIdMap["default"]
-	}
-	return val.Idx
+func GetWorkIdxByID(eventType string, workId string) uint {
+	_, idx := GetWorkInfoByID(eventType, workId)
+	return idx
 }

+ 91 - 0
internal/utils/compapi/mismatch.go

@@ -0,0 +1,91 @@
+package compapi
+
+import (
+	"wechat-api/internal/types"
+
+	"github.com/openai/openai-go"
+)
+
+type MismatchClient struct {
+	StdClient
+}
+
+// Generate the JSON schema at initialization time
+var MismatchResponseSchema = GenerateSchema[MismatchResponse]()
+
+type MismatchResponse struct {
+	UserIntent   string   `json:"user_intent" jsonschema_description:"用户意图"`
+	SimilarReply []string `json:"similar_reply" jsonschema_description:"类似回复"`
+	Keywords     []string `json:"keywords" jsonschema_description:"关键词库"`
+	Regular      []string `json:"regular" jsonschema_description:"正则表达式"`
+}
+
+/*
+
+"response_format":{"type":"json_object"}}
+
+{"type":"json_schema",
+	"json_schema":{
+		"description":"从通话记录中提取表单","name":"keyword_schema","schema":{
+			"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":false,"properties":{
+			"keywords":{
+				"description":"关键词库","items":{"type":"string"},"type":"array"},"regular":{"description":"正则表达式","items":{"type":"string"},"type":"array"},"similar_reply":{"description":"类似回复","items":{"type":"string"},"type":"array"},"swear_words":{"description":"脏话列表","items":{"type":"string"},"type":"array"},"user_intent":{"description":"用户意图","type":"string"},"user_mood":{"description":"用户情绪","type":"string"}},"required":["user_intent","similar_reply","keywords","regular","user_mood","swear_words"],"type":"object"},"strict":true}}
+*/
+
+func (me *MismatchClient) BuildRequest(req *types.CompApiReq) error {
+
+	//先重构message
+	newMessSlice := make([]types.StdCompMessage, 2)
+	newMessSlice[0] = types.StdCompMessage{Role: "system", Content: ` # 任务介绍
+		公司在用程序巡检电话通话记录时,有些用户的回复内容没有被关键词库识别到,请根据以下通话记录,给出一些类似的回复,以及对关键词库的具体建议,非常感谢!
+
+		# 输出要求
+		1. 用户意图:结合上下文,首先考虑可能的语音识别错误并纠错,然后分析未识别内容的根本意图,用户说这句话的背后真实目的是什么,结合上下文挖掘用户最深的意图,请不要停留在表面的意思。
+		2. 类似回复:首先应包含未识别的内容原文:` + req.Variables["missed"] + `。其次生成尽可能多的类似意图的回复。
+		2. 关键词库:从类似回复中抽取特征词,要求有两点:一是特征词应尽可能的准确,即要覆盖住此类问题,又要尽可能避免和其他语境相冲突。二是需要注重通用性,一些专有名词、人名、地名、产品名、公司名等需要排除在外。
+		3. 正则表达式:对关键词词进行解耦,用正则表达式进行表示,专注于主要内容,排除次要内容
+
+		# 注意事项
+		1. 应贴近真实的外呼场景,用户的素质参差不齐,请避免使用任何浮夸的用词,避免使用高级词汇,避免使用任何的礼貌用语或敬语,适当的低素质些,请至少给出20条结果
+		2. 通话记录为录音转译,因此可能有错别字或音同字不同的情况(例如:借和接),请根据上下文分析后就成可能的错字错误
+		3. 正则关键词库和正则表达式中也应该考虑到音同字不同的情况,且避免使用匹配次数相关的语法如{0,2}`}
+
+	newMessSlice[1] = types.StdCompMessage{Role: "user", Content: `
+	# 通话记录` + req.Variables["chat_history"] + `
+
+	# 可能识别有误的内容:` + req.Variables["missed"]}
+
+	//oldModel := req.Model
+	//req.Model = "deepseek-v3"
+	//再构造ResponseFormat
+	if req.Model == "deepseek-v3" || req.Model == "deepseek-chat" {
+		newMessSlice[1].Content = newMessSlice[1].Content.(string) + `json:{
+    "user_intent": str, #用户意图
+    "similar_reply": list[str], #类似回复
+    "keywords": list[str], #关键词库
+    "regular": list[str], #正则表达式
+}`
+		req.ResponseFormat = openai.ResponseFormatJSONObjectParam{Type: "json_object"}
+	} else {
+		schemaParam := openai.ResponseFormatJSONSchemaJSONSchemaParam{
+			Name:        "keyword_schema",
+			Description: openai.String("从通话记录中提取表单"),
+			Schema:      MismatchResponseSchema,
+			Strict:      openai.Bool(true),
+		}
+		req.ResponseFormat = openai.ResponseFormatJSONSchemaParam{JSONSchema: schemaParam}
+	}
+	//req.Model = oldModel
+	req.Messages = newMessSlice
+
+	return nil
+}
+
+func (me *MismatchClient) CallbackPrepare(params any) ([]byte, error) {
+	res := MismatchResponse{}
+	err := NewChatResult(params).ParseContentAs(&res)
+	if err != nil {
+		return nil, err
+	}
+	return WrapJSON(res, "data", true)
+}

+ 160 - 0
internal/utils/compapi/result.go

@@ -0,0 +1,160 @@
+package compapi
+
+import (
+	"bytes"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"strings"
+	"wechat-api/internal/types"
+)
+
+// 包装了原始的 API 响应,并提供了解析助手方法
+type ChatResult struct {
+	*types.CompOpenApiResp
+	err error
+}
+
+// NewChatResult 是 ChatResult 的构造函数
+func NewChatResult(resp any) *ChatResult {
+	nresp, err := AnyToCompOpenApiResp(resp)
+	res := ChatResult{nresp, err}
+	if nresp == nil {
+		res.err = errors.New("CompOpenApiRes is nil")
+	}
+	return &res
+}
+
+// 以下是ChatResul助手方法
+
+// GetContentString 返回第一个 Choice 的 Message Content (标准方式)
+func (r *ChatResult) GetContentString() (string, error) {
+	var (
+		content string = ""
+		err     error
+	)
+	if r.err == nil && len(r.Choices) > 0 {
+		content = r.Choices[0].Message.Content
+	} else if r.err == nil && len(r.Choices) == 0 {
+		err = errors.New("choices empty")
+	}
+	return content, err
+}
+
+// ParseContentAs 解析 Message Content 中的 JSON 到指定的 Go 结构体
+// target 必须是一个指向目标结构体实例的指针 (e.g., &MyStruct{})
+func (r *ChatResult) ParseContentAs(target any) error {
+	content, err := r.GetContentString()
+	if err != nil {
+		return fmt.Errorf("parseContent err: %s", err)
+	} else if content == "" {
+		return errors.New("parseContent err: content is empty or unavailable")
+	}
+
+	// (可选)清理可能的 Markdown ```json ``` 包装
+	if strings.HasPrefix(content, "```json") && strings.HasSuffix(content, "```") {
+		content = strings.TrimSuffix(strings.TrimPrefix(content, "```json"), "```")
+		content = strings.TrimSpace(content)
+	}
+
+	err = json.Unmarshal([]byte(content), target)
+	if err != nil {
+		return fmt.Errorf("parseContent err: failed to unmarshal content JSON into target type '%w'", err)
+	}
+	return nil
+}
+
+func AnyToBytes(in any) ([]byte, error) {
+	switch v := in.(type) {
+	case string:
+		return []byte(v), nil
+	case []byte:
+		return v, nil
+	default:
+		return json.Marshal(v)
+	}
+}
+
+func AnyToCompOpenApiResp(in any) (*types.CompOpenApiResp, error) {
+	if resp, ok := in.(*types.CompOpenApiResp); ok {
+		return resp, nil
+	}
+	if resp, ok := in.(types.CompOpenApiResp); ok {
+		return &resp, nil
+	}
+	bs, err := AnyToBytes(in)
+	if err != nil {
+		return nil, err
+	}
+	nresp := &types.CompOpenApiResp{}
+	err = json.Unmarshal(bs, nresp)
+	if err != nil {
+		return nil, err
+	}
+	return nresp, nil
+}
+
+func AnyToCompApiReq(in any) (*types.CompApiReq, error) {
+	if req, ok := in.(*types.CompApiReq); ok {
+		return req, nil
+	}
+	if req, ok := in.(types.CompApiReq); ok {
+		return &req, nil
+	}
+	bs, err := AnyToBytes(in)
+	if err != nil {
+		return nil, err
+	}
+	nreq := &types.CompApiReq{}
+	err = json.Unmarshal(bs, nreq)
+	if err != nil {
+		return nil, err
+	}
+	return nreq, nil
+}
+
+func CheckJSON(input any, checkEmpty bool) (bool, error) {
+	inputBytes, err := AnyToBytes(input)
+	if err != nil {
+		return false, err
+	}
+	var raw json.RawMessage
+	err = json.Unmarshal(inputBytes, &raw)
+	if err != nil {
+		return false, fmt.Errorf("input is not valid JSON: %w", err)
+	}
+	if checkEmpty {
+		trimmed := bytes.TrimSpace(inputBytes)
+		if len(trimmed) == 0 {
+			return false, fmt.Errorf("input is empty")
+		}
+	}
+	return true, nil
+}
+
+func WrapJSON(input any, warpKey string, checkValid bool) ([]byte, error) {
+	var (
+		inputBytes  []byte
+		outputBytes []byte
+		err         error
+	)
+	if inputBytes, err = AnyToBytes(input); err != nil {
+		return nil, err
+	}
+
+	if checkValid {
+		if _, err = CheckJSON(inputBytes, true); err != nil {
+			return nil, err
+		}
+	}
+	if len(warpKey) == 0 {
+		return inputBytes, nil
+	}
+	wrapper := map[string]json.RawMessage{
+		warpKey: json.RawMessage(inputBytes),
+	}
+	if outputBytes, err = json.Marshal(wrapper); err != nil {
+		return nil, fmt.Errorf("failed to marshal wrapper structure: %w", err)
+	}
+	return outputBytes, nil
+}

+ 80 - 0
internal/utils/compapi/std.go

@@ -0,0 +1,80 @@
+package compapi
+
+import (
+	"errors"
+	"fmt"
+	"net/http"
+	"wechat-api/internal/types"
+
+	"github.com/openai/openai-go"
+	"github.com/openai/openai-go/option"
+)
+
+type StdClient struct {
+	*Client
+}
+
+func (me *StdClient) CallbackPrepare(params any) ([]byte, error) {
+	return AnyToBytes(params)
+}
+
+func (me *StdClient) DoRequestBS(req []byte,
+	customResp any, isSteam bool) (*openai.ChatCompletion, error) {
+
+	opts := []option.RequestOption{}
+	if len(req) > 0 {
+		opts = append(opts, option.WithRequestBody("application/json", req))
+	} else {
+		return nil, errors.New("request body empty")
+	}
+	if customResp != nil {
+		opts = append(opts, option.WithResponseBodyInto(customResp))
+	}
+	if isSteam {
+		opts = append(opts, option.WithJSONSet("stream", true))
+	}
+	emptyParams := openai.ChatCompletionNewParams{}
+
+	return me.OAC.Chat.Completions.New(me.ctx, emptyParams, opts...)
+}
+func (me *StdClient) DoRequest(req *types.CompApiReq) (*types.CompOpenApiResp, error) {
+
+	//fmt.Println(typekit.PrettyPrint(req))
+	jsonBytes, err := req.ToBytes()
+	if err != nil {
+		return nil, err
+	}
+	customResp := types.CompOpenApiResp{}
+	if _, err = me.DoRequestBS(jsonBytes, &customResp, req.Stream); err != nil {
+		return nil, err
+	}
+
+	if customResp.FgtErrCode != nil && customResp.FgtErrStatusTxt != nil { //针对fastgpt出错但New()不返回错误的情况
+		return nil, fmt.Errorf("%s(%d)", *customResp.FgtErrStatusTxt, *customResp.FgtErrCode)
+	}
+	return &customResp, nil
+}
+
+func (me *StdClient) DoRequestStream(req *types.CompApiReq) (*types.CompOpenApiResp, error) {
+	var (
+		//raw []byte
+		raw       *http.Response
+		jsonBytes []byte
+		err       error
+	)
+
+	jsonBytes, err = req.ToBytes()
+	if err != nil {
+		return nil, err
+	}
+	if _, err = me.DoRequestBS(jsonBytes, &raw, req.Stream); err != nil {
+		return nil, err
+	}
+	streamOut(me.ctx, raw)
+
+	return nil, nil
+}
+
+func (me *StdClient) BuildRequest(req *types.CompApiReq) error {
+	return nil
+}

+ 321 - 0
internal/utils/typekit/print.go

@@ -0,0 +1,321 @@
+package typekit
+
+//package main
+
+import (
+	"fmt"
+	"reflect"
+	"sort"
+	"strconv"
+	"strings"
+	"unsafe"
+)
+
+const (
+	colorReset  = "\033[0m"
+	colorStruct = "\033[34m\033[7m"
+	colorField  = "\033[32m"
+	colorMap    = "\033[33m\033[7m"
+	colorSlice  = "\033[35m\033[7m"
+	colorValue  = "\033[31m"
+	colorKey    = "\033[36m"
+	symbolVert  = "│  "
+	symbolLast  = "└─ "
+	symbolMid   = "├─ "
+	symbolEmpty = "   "
+)
+
+type PrintOptions struct {
+	ShowTypes bool
+}
+
+func PrettyPrint(v interface{}, opts ...PrintOptions) string {
+	option := PrintOptions{ShowTypes: true}
+	if len(opts) > 0 {
+		option = opts[0]
+	}
+	return prettyPrint(reflect.ValueOf(v), 0, make(map[uintptr]bool), option, []bool{}).String()
+}
+
+type lines []string
+
+func (l lines) String() string {
+	return strings.Join(l, "\n")
+}
+
+func buildPrefix(indent int, isLasts []bool) string {
+	var prefix strings.Builder
+	for i := 0; i < indent; i++ {
+		if i < len(isLasts) {
+			if isLasts[i] {
+				prefix.WriteString(symbolEmpty)
+			} else {
+				prefix.WriteString(symbolVert)
+			}
+		}
+	}
+	return prefix.String()
+}
+
+func prettyPrint(v reflect.Value, indentLevel int, visited map[uintptr]bool, opts PrintOptions, isLasts []bool) lines {
+	original := v
+	for {
+		switch v.Kind() {
+		case reflect.Ptr:
+			if v.IsNil() {
+				return lines{colorValue + "nil" + colorReset}
+			}
+			ptr := v.Pointer()
+			if visited[ptr] {
+				return lines{fmt.Sprintf("%s&%p%s", colorValue, v.Interface(), colorReset)}
+			}
+			visited[ptr] = true
+			original = v
+			v = v.Elem()
+		case reflect.Interface:
+			if v.IsNil() {
+				return lines{colorValue + "nil" + colorReset}
+			}
+			v = v.Elem()
+		default:
+			goto END_DEREF
+		}
+	}
+END_DEREF:
+
+	switch v.Kind() {
+	case reflect.Struct:
+		return printStruct(v, indentLevel, visited, opts, isLasts)
+	case reflect.Map:
+		return printMap(v, indentLevel, visited, opts, isLasts)
+	case reflect.Slice, reflect.Array:
+		return printSlice(v, indentLevel, visited, opts, isLasts)
+	case reflect.String:
+		return lines{fmt.Sprintf("%s%q%s", colorValue, v.String(), colorReset)}
+	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
+		return lines{fmt.Sprintf("%s%d%s", colorValue, v.Int(), colorReset)}
+	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
+		return lines{fmt.Sprintf("%s%d%s", colorValue, v.Uint(), colorReset)}
+	case reflect.Float32, reflect.Float64:
+		// 使用精确的字符串表示,保留必要精度
+		str := strconv.FormatFloat(v.Float(), 'f', -1, 64)
+		// 移除多余的末尾零和小数点
+		if strings.Contains(str, ".") {
+			str = strings.TrimRight(str, "0")
+			str = strings.TrimRight(str, ".")
+		}
+		return lines{fmt.Sprintf("%s%s%s", colorValue, str, colorReset)}
+	case reflect.Bool:
+		return lines{fmt.Sprintf("%s%t%s", colorValue, v.Bool(), colorReset)}
+	default:
+		if original.Kind() == reflect.Ptr {
+			return lines{fmt.Sprintf("%s%v%s", colorValue, original.Interface(), colorReset)}
+		}
+		//return lines{fmt.Sprintf("%s%v%s", colorValue, v.Interface(), colorReset)}
+		return lines{formatUnexported(v, original)}
+	}
+}
+
+// 新增辅助函数处理未导出字段
+func formatUnexported(v, original reflect.Value) string {
+	var value interface{}
+	var canShow bool
+
+	// 尝试通过不同方式安全获取值
+	switch {
+	case v.CanInterface():
+		value = v.Interface()
+		canShow = true
+	case original.Kind() == reflect.Ptr && original.CanInterface():
+		value = original.Interface()
+		canShow = true
+	default:
+		canShow = false
+	}
+
+	// 特殊处理指针类型
+	if v.Kind() == reflect.Ptr && !v.IsNil() {
+		return fmt.Sprintf("%s&%p%s", colorValue, unsafe.Pointer(v.Pointer()), colorReset)
+	}
+
+	// 构造显示字符串
+	if canShow {
+		return fmt.Sprintf("%s%v%s", colorValue, value, colorReset)
+	}
+	return fmt.Sprintf("%s<unexported>%s", colorValue, colorReset)
+}
+
+func printStruct(v reflect.Value, indentLevel int, visited map[uintptr]bool, opts PrintOptions, parentLasts []bool) lines {
+	var header string
+	if opts.ShowTypes {
+		header = fmt.Sprintf("%s%s%s", colorStruct, v.Type().String(), colorReset)
+	} else {
+		header = " ---"
+	}
+
+	result := lines{header}
+	fieldCount := v.NumField()
+
+	for i := 0; i < fieldCount; i++ {
+		field := v.Type().Field(i)
+		// 跳过未导出字段
+		if !field.IsExported() {
+			continue
+		}
+		fieldValue := v.Field(i)
+		isLast := i == fieldCount-1
+
+		prefix := buildPrefix(indentLevel, parentLasts)
+		currentLasts := append(parentLasts, isLast)
+
+		var symbol string
+		if isLast {
+			symbol = symbolLast
+		} else {
+			symbol = symbolMid
+		}
+
+		fieldLines := prettyPrint(fieldValue, indentLevel+1, visited, opts, currentLasts)
+		fieldHeader := fmt.Sprintf("%s%s%s%s: ",
+			prefix,
+			symbol,
+			colorField,
+			field.Name,
+		)
+
+		if len(fieldLines) == 0 {
+			result = append(result, fieldHeader+colorValue+"<invalid>"+colorReset)
+			continue
+		}
+
+		result = append(result, fieldHeader+fieldLines[0])
+		for _, line := range fieldLines[1:] {
+			result = append(result, prefix+symbolEmpty+line)
+		}
+	}
+	return result
+}
+
+func printMap(v reflect.Value, indentLevel int, visited map[uintptr]bool, opts PrintOptions, parentLasts []bool) lines {
+	var header string
+	if opts.ShowTypes {
+		header = fmt.Sprintf("%s%s%s", colorMap, v.Type().String(), colorReset)
+	} else {
+		header = " ---"
+	}
+
+	result := lines{header}
+	keys := v.MapKeys()
+	sort.Slice(keys, func(i, j int) bool {
+		return fmt.Sprintf("%v", keys[i]) < fmt.Sprintf("%v", keys[j])
+	})
+	keyCount := len(keys)
+
+	for i, key := range keys {
+		prefix := buildPrefix(indentLevel, parentLasts)
+		isLast := i == keyCount-1
+		currentLasts := append(parentLasts, isLast)
+
+		var symbol string
+		if isLast {
+			symbol = symbolLast
+		} else {
+			symbol = symbolMid
+		}
+
+		keyLines := prettyPrint(key, 0, visited, opts, currentLasts)
+		valueLines := prettyPrint(v.MapIndex(key), indentLevel+1, visited, opts, currentLasts)
+
+		keyHeader := fmt.Sprintf("%s%s%s%s: ",
+			prefix,
+			symbol,
+			colorKey,
+			strings.Join(keyLines, ""),
+		)
+
+		if len(valueLines) == 0 {
+			result = append(result, keyHeader+colorValue+"<invalid>"+colorReset)
+			continue
+		}
+
+		result = append(result, keyHeader+valueLines[0])
+		for _, line := range valueLines[1:] {
+			result = append(result, prefix+symbolEmpty+line)
+		}
+	}
+	return result
+}
+
+func printSlice(v reflect.Value, indentLevel int, visited map[uintptr]bool, opts PrintOptions, parentLasts []bool) lines {
+	var header string
+	if opts.ShowTypes {
+		header = fmt.Sprintf("%s%s%s", colorSlice, v.Type().String(), colorReset)
+	} else {
+		header = " ---"
+	}
+
+	result := lines{header}
+	elemCount := v.Len()
+
+	for i := 0; i < elemCount; i++ {
+		prefix := buildPrefix(indentLevel, parentLasts)
+		isLast := i == elemCount-1
+		currentLasts := append(parentLasts, isLast)
+
+		var symbol string
+		if isLast {
+			symbol = symbolLast
+		} else {
+			symbol = symbolMid
+		}
+
+		elemLines := prettyPrint(v.Index(i), indentLevel+1, visited, opts, currentLasts)
+		bullet := fmt.Sprintf("%s%s", prefix, symbol)
+
+		if len(elemLines) == 0 {
+			result = append(result, bullet+colorValue+"<invalid>"+colorReset)
+			continue
+		}
+
+		result = append(result, bullet+elemLines[0])
+		for _, line := range elemLines[1:] {
+			result = append(result, prefix+symbolEmpty+line)
+		}
+	}
+	return result
+}
+
+/*
+type Person struct {
+	Name    string
+	Age     int
+	Hobbies []string
+	Address struct {
+		City  string
+		State string
+	}
+	Metadata map[string]interface{}
+}
+
+func main() {
+	p := Person{
+		Name:    "Alice",
+		Age:     30,
+		Hobbies: []string{"Reading", "Hiking"},
+		Metadata: map[string]interface{}{
+			"id":     123,
+			"scores": []float64{98.5, 87.2},
+			"nested": map[string]interface{}{"a": 1, "b": 2},
+		},
+	}
+	p.Address.City = "New York"
+	p.Address.State = "NY"
+	p.Metadata["self_ref"] = &p
+
+	fmt.Println("With types:")
+	fmt.Println(PrettyPrint(p, PrintOptions{ShowTypes: false}))
+
+	fmt.Println("\nWithout types:\n")
+	fmt.Println(PrettyPrint(p))
+}
+*/

+ 217 - 0
internal/utils/typekit/print.go.1

@@ -0,0 +1,217 @@
+package typekit
+
+import (
+	"fmt"
+	"reflect"
+	"sort"
+	"strings"
+)
+
+const (
+	colorReset  = "\033[0m"
+	colorStruct = "\033[34m"
+	colorField  = "\033[32m"
+	colorMap    = "\033[33m"
+	colorSlice  = "\033[35m"
+	colorValue  = "\033[31m"
+	colorKey    = "\033[36m"
+)
+
+func PrettyPrint(v interface{}) string {
+	return prettyPrint(reflect.ValueOf(v), 0, make(map[uintptr]bool)).String()
+}
+
+type lines []string
+
+func (l lines) String() string {
+	return strings.Join(l, "\n")
+}
+
+func prettyPrint(v reflect.Value, indentLevel int, visited map[uintptr]bool) lines {
+	original := v
+	// 改进的指针/接口处理逻辑
+	for {
+		switch v.Kind() {
+		case reflect.Ptr:
+			if v.IsNil() {
+				return lines{colorValue + "nil" + colorReset}
+			}
+			ptr := v.Pointer() // 使用正确获取指针值的方法
+			if visited[ptr] {
+				// 正确格式化指针地址
+				return lines{fmt.Sprintf("%s&%p%s", colorValue, v.Interface(), colorReset)}
+			}
+			visited[ptr] = true
+			original = v
+			v = v.Elem()
+		case reflect.Interface:
+			if v.IsNil() {
+				return lines{colorValue + "nil" + colorReset}
+			}
+			v = v.Elem()
+		default:
+			goto END_DEREF
+		}
+	}
+END_DEREF:
+
+	switch v.Kind() {
+	case reflect.Struct:
+		return printStruct(v, indentLevel, visited)
+	case reflect.Map:
+		return printMap(v, indentLevel, visited)
+	case reflect.Slice, reflect.Array:
+		return printSlice(v, indentLevel, visited)
+	case reflect.String:
+		return lines{fmt.Sprintf("%s%q%s", colorValue, v.String(), colorReset)}
+	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
+		return lines{fmt.Sprintf("%s%d%s", colorValue, v.Int(), colorReset)}
+	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
+		return lines{fmt.Sprintf("%s%d%s", colorValue, v.Uint(), colorReset)}
+	case reflect.Float32, reflect.Float64:
+		return lines{fmt.Sprintf("%s%.2f%s", colorValue, v.Float(), colorReset)}
+	case reflect.Bool:
+		return lines{fmt.Sprintf("%s%t%s", colorValue, v.Bool(), colorReset)}
+	default:
+		if original.Kind() == reflect.Ptr {
+			return lines{fmt.Sprintf("%s%v%s", colorValue, original.Interface(), colorReset)}
+		}
+		return lines{fmt.Sprintf("%s%v%s", colorValue, v.Interface(), colorReset)}
+	}
+}
+
+// 完整实现结构体打印
+func printStruct(v reflect.Value, indentLevel int, visited map[uintptr]bool) lines {
+	header := fmt.Sprintf("%s%s%s%s:",
+		strings.Repeat("  ", indentLevel),
+		colorStruct,
+		v.Type().String(),
+		colorReset,
+	)
+	result := lines{header}
+
+	for i := 0; i < v.NumField(); i++ {
+		field := v.Type().Field(i)
+		fieldValue := v.Field(i)
+
+		fieldLines := prettyPrint(fieldValue, indentLevel+1, visited)
+		fieldHeader := fmt.Sprintf("%s%s%s: ",
+			strings.Repeat("  ", indentLevel+1),
+			colorField,
+			field.Name,
+		)
+
+		if len(fieldLines) == 0 {
+			result = append(result, fieldHeader+colorValue+"<invalid>"+colorReset)
+			continue
+		}
+
+		result = append(result, fieldHeader+fieldLines[0])
+		for _, line := range fieldLines[1:] {
+			result = append(result,
+				strings.Repeat("  ", indentLevel+1)+"  "+line)
+		}
+	}
+	return result
+}
+
+// 完整实现map打印
+func printMap(v reflect.Value, indentLevel int, visited map[uintptr]bool) lines {
+	header := fmt.Sprintf("%s%s%s%s:",
+		strings.Repeat("  ", indentLevel),
+		colorMap,
+		v.Type().String(),
+		colorReset,
+	)
+	result := lines{header}
+
+	keys := v.MapKeys()
+	sort.Slice(keys, func(i, j int) bool {
+		return fmt.Sprintf("%v", keys[i]) < fmt.Sprintf("%v", keys[j])
+	})
+
+	for _, key := range keys {
+		keyLines := prettyPrint(key, 0, visited)
+		valueLines := prettyPrint(v.MapIndex(key), indentLevel+1, visited)
+
+		keyHeader := fmt.Sprintf("%s%s%s: ",
+			strings.Repeat("  ", indentLevel+1),
+			colorKey,
+			strings.Join(keyLines, ""),
+		)
+
+		if len(valueLines) == 0 {
+			result = append(result, keyHeader+colorValue+"<invalid>"+colorReset)
+			continue
+		}
+
+		result = append(result, keyHeader+valueLines[0])
+		for _, line := range valueLines[1:] {
+			result = append(result,
+				strings.Repeat("  ", indentLevel+1)+"  "+line)
+		}
+	}
+	return result
+}
+
+// 完整实现slice/array打印
+func printSlice(v reflect.Value, indentLevel int, visited map[uintptr]bool) lines {
+	header := fmt.Sprintf("%s%s%s%s:",
+		strings.Repeat("  ", indentLevel),
+		colorSlice,
+		v.Type().String(),
+		colorReset,
+	)
+	result := lines{header}
+
+	for i := 0; i < v.Len(); i++ {
+		elemLines := prettyPrint(v.Index(i), indentLevel+1, visited)
+		bullet := fmt.Sprintf("%s- ",
+			strings.Repeat("  ", indentLevel+1),
+		)
+
+		if len(elemLines) == 0 {
+			result = append(result, bullet+colorValue+"<invalid>"+colorReset)
+			continue
+		}
+
+		result = append(result, bullet+elemLines[0])
+		for _, line := range elemLines[1:] {
+			result = append(result,
+				strings.Repeat("  ", indentLevel+1)+"  "+line)
+		}
+	}
+	return result
+}
+
+/*
+// 修正后的测试用例
+type Person struct {
+	Name    string
+	Age     int
+	Hobbies []string
+	Address struct {
+		City  string
+		State string
+	}
+	Metadata map[string]interface{}
+}
+
+func main() {
+	p := Person{
+		Name:    "Alice",
+		Age:     30,
+		Hobbies: []string{"Reading", "Hiking"},
+		Metadata: map[string]interface{}{
+			"id":     123,
+			"scores": []float64{98.5, 87.2},
+			"nested": map[string]interface{}{"a": 1, "b": 2},
+		},
+	}
+	p.Address.City = "New York"
+	p.Address.State = "NY"
+	p.Metadata["self_ref"] = &p // 正确设置循环引用
+
+	fmt.Println(PrettyPrint(p))
+}
+*/

+ 345 - 0
internal/utils/typekit/print.go.3

@@ -0,0 +1,345 @@
+package main
+
+import (
+	"fmt"
+	"os"
+	"reflect"
+	"sort"
+	"strconv"
+	"strings"
+
+	"github.com/muesli/termenv"
+)
+
+// 颜色配置枚举
+type ColorProfile int
+
+const (
+	Auto ColorProfile = iota
+	Dark
+	Light
+	NoColor
+)
+
+// 打印选项结构
+type PrintOptions struct {
+	ShowTypes      bool         // 是否显示类型信息
+	ColorProfile   ColorProfile // 颜色配置方案
+	FloatPrecision int          // 浮点数精度(-1表示自动)
+}
+
+// 颜色缓存变量
+var (
+	colorType  string
+	colorField string
+	colorKey   string
+	colorValue string
+	resetColor string
+)
+
+// 初始化颜色配置
+func initColors(profile ColorProfile) {
+	output := termenv.NewOutput(os.Stdout)
+	style := output.String()
+	resetColor = style.Reset().String()
+
+	switch profile {
+	case Auto:
+		if output.HasDarkBackground() {
+			setDarkThemeColors(output)
+		} else {
+			setLightThemeColors(output)
+		}
+	case Dark:
+		setDarkThemeColors(output)
+	case Light:
+		setLightThemeColors(output)
+	case NoColor:
+		colorType = ""
+		colorField = ""
+		colorKey = ""
+		colorValue = ""
+		resetColor = ""
+	}
+}
+
+// 暗色主题配色
+func setDarkThemeColors(output *termenv.Output) {
+	colorType = output.String().Foreground(output.Color("#5FAFFF")).String()
+	colorField = output.String().Foreground(output.Color("#AFF080")).String()
+	colorKey = output.String().Foreground(output.Color("#FFD700")).String()
+	colorValue = output.String().Foreground(output.Color("#E0E0E0")).String()
+}
+
+// 亮色主题配色
+func setLightThemeColors(output *termenv.Output) {
+	colorType = output.String().Foreground(output.Color("#005FAF")).String()
+	colorField = output.String().Foreground(output.Color("#008000")).String()
+	colorKey = output.String().Foreground(output.Color("#AF5F00")).String()
+	colorValue = output.String().Foreground(output.Color("#404040")).String()
+}
+
+// 美观打印入口函数
+func PrettyPrint(v interface{}, opts ...PrintOptions) string {
+	// 设置默认选项
+	option := PrintOptions{
+		ShowTypes:      true,
+		ColorProfile:   Auto,
+		FloatPrecision: -1,
+	}
+	if len(opts) > 0 {
+		option = opts[0]
+	}
+
+	// 初始化颜色
+	initColors(option.ColorProfile)
+
+	// 开始递归打印
+	return prettyPrint(reflect.ValueOf(v), 0, make(map[uintptr]bool), option, []bool{}).String()
+}
+
+// 行集合类型
+type lines []string
+
+func (l lines) String() string {
+	return strings.Join(l, "\n")
+}
+
+// 核心打印逻辑
+func prettyPrint(v reflect.Value, depth int, visited map[uintptr]bool, opts PrintOptions, lastMarkers []bool) lines {
+	original := v
+	// 处理指针和接口
+	for {
+		switch v.Kind() {
+		case reflect.Ptr:
+			if v.IsNil() {
+				return lines{colorValue + "nil" + resetColor}
+			}
+			ptr := v.Pointer()
+			if visited[ptr] {
+				return lines{fmt.Sprintf("%s&%p%s", colorValue, v.Interface(), resetColor)}
+			}
+			visited[ptr] = true
+			original = v
+			v = v.Elem()
+		case reflect.Interface:
+			if v.IsNil() {
+				return lines{colorValue + "nil" + resetColor}
+			}
+			v = v.Elem()
+		default:
+			goto END_DEREF
+		}
+	}
+END_DEREF:
+
+	var result lines
+	prefix := buildPrefix(depth, lastMarkers)
+
+	// 添加类型行
+	if opts.ShowTypes && depth == 0 {
+		typeLine := fmt.Sprintf("%s%s%s", colorType, getTypeName(original, v), resetColor)
+		result = append(result, typeLine)
+	}
+
+	switch v.Kind() {
+	case reflect.Struct:
+		result = append(result, printStruct(v, depth, visited, opts, lastMarkers)...)
+	case reflect.Map:
+		result = append(result, printMap(v, depth, visited, opts, lastMarkers)...)
+	case reflect.Slice, reflect.Array:
+		result = append(result, printSlice(v, depth, visited, opts, lastMarkers)...)
+	default:
+		result = append(result, formatValue(v, prefix, opts))
+	}
+
+	return result
+}
+
+// 构建前缀字符串
+func buildPrefix(depth int, lastMarkers []bool) string {
+	if depth == 0 {
+		return ""
+	}
+
+	var prefix strings.Builder
+	for i := 0; i < depth-1; i++ {
+		if i < len(lastMarkers) && lastMarkers[i] {
+			prefix.WriteString("    ")
+		} else {
+			prefix.WriteString("│   ")
+		}
+	}
+
+	if depth > 0 {
+		if len(lastMarkers) > 0 && lastMarkers[len(lastMarkers)-1] {
+			prefix.WriteString("└── ")
+		} else {
+			prefix.WriteString("├── ")
+		}
+	}
+	return prefix.String()
+}
+
+// 获取类型名称
+func getTypeName(original, v reflect.Value) string {
+	if original.Kind() == reflect.Ptr {
+		return original.Type().String()
+	}
+	return v.Type().String()
+}
+
+// 格式化值
+func formatValue(v reflect.Value, prefix string, opts PrintOptions) string {
+	switch v.Kind() {
+	case reflect.String:
+		return fmt.Sprintf("%s%s%q%s", prefix, colorValue, v.String(), resetColor)
+	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
+		return fmt.Sprintf("%s%s%d%s", prefix, colorValue, v.Int(), resetColor)
+	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
+		return fmt.Sprintf("%s%s%d%s", prefix, colorValue, v.Uint(), resetColor)
+	case reflect.Float32, reflect.Float64:
+		return formatFloat(v.Float(), opts.FloatPrecision, prefix)
+	case reflect.Bool:
+		return fmt.Sprintf("%s%s%t%s", prefix, colorValue, v.Bool(), resetColor)
+	default:
+		return fmt.Sprintf("%s%s%v%s", prefix, colorValue, v.Interface(), resetColor)
+	}
+}
+
+// 格式化浮点数(改进精度处理)
+func formatFloat(f float64, precision int, prefix string) string {
+	var str string
+	if precision >= 0 {
+		str = strconv.FormatFloat(f, 'f', precision, 64)
+	} else {
+		// 自动处理精度
+		str = strconv.FormatFloat(f, 'f', -1, 64)
+		if strings.Contains(str, ".") {
+			str = strings.TrimRight(str, "0")
+			str = strings.TrimRight(str, ".")
+		}
+	}
+	return fmt.Sprintf("%s%s%s%s", prefix, colorValue, str, resetColor)
+}
+
+// 打印结构体
+func printStruct(v reflect.Value, depth int, visited map[uintptr]bool, opts PrintOptions, lastMarkers []bool) lines {
+	var result lines
+	fieldCount := v.NumField()
+
+	for i := 0; i < fieldCount; i++ {
+		field := v.Type().Field(i)
+		fieldValue := v.Field(i)
+		isLast := i == fieldCount-1
+
+		newMarkers := append(lastMarkers, isLast)
+		subLines := prettyPrint(fieldValue, depth+1, visited, opts, newMarkers)
+
+		// 字段头
+		fieldHeader := fmt.Sprintf("%s%s%s:",
+			buildPrefix(depth+1, newMarkers[:len(newMarkers)-1]),
+			colorField,
+			field.Name,
+		)
+
+		if len(subLines) == 0 {
+			result = append(result, fieldHeader+colorValue+"<invalid>"+resetColor)
+			continue
+		}
+
+		// 合并字段头和数据
+		result = append(result, fieldHeader+strings.TrimPrefix(subLines[0], buildPrefix(depth+1, newMarkers)))
+		result = append(result, subLines[1:]...)
+	}
+	return result
+}
+
+// 打印Map
+func printMap(v reflect.Value, depth int, visited map[uintptr]bool, opts PrintOptions, lastMarkers []bool) lines {
+	var result lines
+	keys := v.MapKeys()
+	sort.Slice(keys, func(i, j int) bool {
+		return fmt.Sprintf("%v", keys[i]) < fmt.Sprintf("%v", keys[j])
+	})
+
+	for i, key := range keys {
+		isLast := i == len(keys)-1
+		newMarkers := append(lastMarkers, isLast)
+
+		keyLines := prettyPrint(key, depth+1, visited, opts, newMarkers)
+		valueLines := prettyPrint(v.MapIndex(key), depth+1, visited, opts, newMarkers)
+
+		// Key头
+		keyHeader := fmt.Sprintf("%s%s%s:",
+			buildPrefix(depth+1, newMarkers[:len(newMarkers)-1]),
+			colorKey,
+			strings.Join(keyLines, ""),
+		)
+
+		// 合并Key和Value
+		if len(valueLines) > 0 {
+			result = append(result, keyHeader+strings.TrimPrefix(valueLines[0], buildPrefix(depth+1, newMarkers)))
+			result = append(result, valueLines[1:]...)
+		} else {
+			result = append(result, keyHeader+"<invalid>")
+		}
+	}
+	return result
+}
+
+// 打印Slice/Array
+func printSlice(v reflect.Value, depth int, visited map[uintptr]bool, opts PrintOptions, lastMarkers []bool) lines {
+	var result lines
+	for i := 0; i < v.Len(); i++ {
+		isLast := i == v.Len()-1
+		newMarkers := append(lastMarkers, isLast)
+		elemLines := prettyPrint(v.Index(i), depth+1, visited, opts, newMarkers)
+		result = append(result, elemLines...)
+	}
+	return result
+}
+
+// 测试结构体
+type Person struct {
+	Name    string
+	Age     int
+	Hobbies []string
+	Address struct {
+		City  string
+		State string
+	}
+	Metadata map[string]interface{}
+}
+
+func main() {
+	p := Person{
+		Name:    "Alice",
+		Age:     30,
+		Hobbies: []string{"Reading", "Hiking"},
+		Metadata: map[string]interface{}{
+			"id":     123,
+			"scores": []float64{98.5, 87.2000, 100.0},
+			"nested": map[string]interface{}{"a": 1, "b": 2},
+		},
+	}
+	p.Address.City = "New York"
+	p.Address.State = "NY"
+	p.Metadata["self_ref"] = &p
+
+	fmt.Println("=== 默认输出(自动颜色适配)===")
+	fmt.Println(PrettyPrint(p))
+
+	fmt.Println("\n=== 显示类型+亮色主题+浮点精度2位 ===")
+	fmt.Println(PrettyPrint(p, PrintOptions{
+		ShowTypes:      true,
+		ColorProfile:   Light,
+		FloatPrecision: 2,
+	}))
+
+	fmt.Println("\n=== 不显示类型+暗色主题 ===")
+	fmt.Println(PrettyPrint(p, PrintOptions{
+		ShowTypes:    false,
+		ColorProfile: Dark,
+	}))
+}

+ 51 - 0
sql/wechat/compapi_asynctask.sql

@@ -0,0 +1,51 @@
+-- -------------------------------------------------------------
+-- TablePlus 6.4.4(604)
+--
+-- https://tableplus.com/
+--
+-- Database: wechat
+-- Generation Time: 2025-04-13 16:07:49.8430
+-- -------------------------------------------------------------
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
+/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
+/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
+/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
+
+
+CREATE TABLE `compapi_asynctask` (
+  `id` int NOT NULL AUTO_INCREMENT,
+  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Create Time | 任务创建日期',
+  `auth_token` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '发起请求者的授权token',
+  `event_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'fastgpt' COMMENT '请求目标类型',
+  `chat_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '会话ID',
+  `organization_id` bigint unsigned DEFAULT '1' COMMENT '机构 ID',
+  `openai_base` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '' COMMENT '大模型服务地址',
+  `openai_key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT '' COMMENT '大模型服务密钥',
+  `request_raw` text NOT NULL COMMENT '请求结构JSON',
+  `response_raw` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '请求大模型返回原始数据',
+  `callback_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '异步执行回调地址',
+  `callback_response_raw` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'callback返回原始数据',
+  `model` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
+  `task_status` tinyint NOT NULL DEFAULT '10' COMMENT 'callback status |任务完成状态 10 任务就绪 20 请求API完成 30 请求回调完成 50 任务全部完成 60 任务暂停 70 任务失败 ',
+  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'updated Time | 状态更新时间',
+  `retry_count` tinyint DEFAULT '0' COMMENT 'retry count | 重试次数',
+  `last_error` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '最后一次错误信息',
+  PRIMARY KEY (`id`),
+  KEY `task_status` (`task_status`) USING BTREE
+) ENGINE=InnoDB AUTO_INCREMENT=816 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+
+
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;