|
| 1 | +package coze |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net/http" |
| 6 | +) |
| 7 | + |
| 8 | +func (r *storesPlugins) List(ctx context.Context, req *ListStoresPluginsReq, options ...CozeAPIOption) (NumberPaged[ProductPlugin], error) { |
| 9 | + if req.PageSize == 0 { |
| 10 | + req.PageSize = 20 |
| 11 | + } |
| 12 | + if req.PageNum == 0 { |
| 13 | + req.PageNum = 1 |
| 14 | + } |
| 15 | + return NewNumberPaged( |
| 16 | + func(request *pageRequest) (*pageResponse[ProductPlugin], error) { |
| 17 | + response := new(listStoresPluginsResp) |
| 18 | + if err := r.core.rawRequest(ctx, &RawRequestReq{ |
| 19 | + Method: http.MethodGet, |
| 20 | + URL: "/v1/stores/plugins", |
| 21 | + Body: req.toReq(request), |
| 22 | + options: options, |
| 23 | + }, response); err != nil { |
| 24 | + return nil, err |
| 25 | + } |
| 26 | + return &pageResponse[ProductPlugin]{ |
| 27 | + response: response.HTTPResponse, |
| 28 | + HasMore: response.Data.HasMore, |
| 29 | + Data: response.Data.Items, |
| 30 | + LogID: response.HTTPResponse.LogID(), |
| 31 | + }, nil |
| 32 | + }, req.PageSize, req.PageNum) |
| 33 | +} |
| 34 | + |
| 35 | +type ProductPlugin struct { |
| 36 | + baseModel |
| 37 | + Metainfo *ProductMetaInfo `json:"metainfo,omitempty"` |
| 38 | + PluginInfo *ProductPluginInfo `json:"plugin_info,omitempty"` |
| 39 | +} |
| 40 | + |
| 41 | +type ProductMetaInfo struct { |
| 42 | + Name string `json:"name,omitempty"` // 插件的名称。 |
| 43 | + Description string `json:"description,omitempty"` // 插件的描述信息,用于说明插件的功能、用途和特点。 |
| 44 | + Category *ProductCategory `json:"category,omitempty"` // 插件所属的分类信息,包含分类 ID 和分类名称。 |
| 45 | + IconURL string `json:"icon_url,omitempty"` // 插件的图标 URL。 |
| 46 | + EntityType string `json:"entity_type,omitempty"` // 实体类型,当前仅支持 plugin,表示插件。 |
| 47 | + EntityID string `json:"entity_id,omitempty"` // 插件 ID。 |
| 48 | + ListedAt int64 `json:"listed_at,omitempty"` // 插件上架时间,以 Unix 时间戳格式表示,单位为秒。 |
| 49 | + PaidType string `json:"paid_type,omitempty"` // 插件的付费类型,固定为 paid,即付费插件。 |
| 50 | + ProductID string `json:"product_id,omitempty"` // 商品的 ID,用于在插件商店中唯一标识该插件商品。 |
| 51 | + IsOfficial bool `json:"is_official,omitempty"` // 标识插件是否为官方发布。 |
| 52 | +} |
| 53 | + |
| 54 | +type ProductCategory struct { |
| 55 | + ID string `json:"id,omitempty"` // 插件分类 ID。 |
| 56 | + Name string `json:"name,omitempty"` // 插件分类名称。 |
| 57 | +} |
| 58 | + |
| 59 | +type ProductPluginInfo struct { |
| 60 | + Heat int64 `json:"heat,omitempty"` // 插件的热度值,用于表示该插件的受欢迎程度或使用频率。数值越大表示热度越高。 |
| 61 | + CallCount int64 `json:"call_count,omitempty"` // 插件的调用量,表示该插件的累计调用次数。 |
| 62 | + Description string `json:"description,omitempty"` // 插件的描述信息,用于说明插件的功能、用途和特点。 |
| 63 | + SuccessRate float64 `json:"success_rate,omitempty"` // 插件的调用成功率,以小数形式表示,数值范围为 0 到 1。 |
| 64 | + BotsUseCount int64 `json:"bots_use_count,omitempty"` // 该插件在智能体或工作流中的累计关联次数。 |
| 65 | + FavoriteCount int64 `json:"favorite_count,omitempty"` // 插件的收藏量,表示该插件被用户收藏的总次数。 |
| 66 | + IsCallAvailable bool `json:"is_call_available,omitempty"` // 标识该插件当前是否可被调用。 |
| 67 | + TotalToolsCount int64 `json:"total_tools_count,omitempty"` // 插件包含的工具总数。 |
| 68 | + AvgExecDurationMs float64 `json:"avg_exec_duration_ms,omitempty"` // 插件执行的平均耗时,单位为毫秒。 |
| 69 | + AssociatedBotsUseCount int64 `json:"associated_bots_use_count,omitempty"` // 当前扣子商店中关联了该插件的智能体数量。 |
| 70 | +} |
| 71 | + |
| 72 | +type ListStoresPluginsReq struct { |
| 73 | + Keyword *string `query:"keyword" json:"-"` // 插件搜索的关键词,支持模糊匹配。 |
| 74 | + IsOfficial *bool `query:"is_official" json:"-"` // 是否为扣子官方插件。默认返回官方插件和三方插件。 |
| 75 | + CategoryIDs []string `query:"category_ids" json:"-"` // 插件分类 ID 列表,用于筛选指定多个分类下的插件。默认为空,即返回所有分类下的插件。可以通过查询插件分类API 获取对应的插件分类 ID。 |
| 76 | + SortType *string `query:"sort_type" json:"-"` // 排序类型,用于指定返回插件的排序方式。支持的排序方式如下所示: |
| 77 | + PageNum int `query:"page_num" json:"-"` |
| 78 | + PageSize int `query:"page_size" json:"-"` |
| 79 | +} |
| 80 | + |
| 81 | +type ListStoresPluginsResp struct { |
| 82 | + Items []*ProductPlugin `json:"items"` |
| 83 | + HasMore bool `json:"has_more"` |
| 84 | +} |
| 85 | + |
| 86 | +func (r ListStoresPluginsReq) toReq(page *pageRequest) *ListStoresPluginsReq { |
| 87 | + return &ListStoresPluginsReq{ |
| 88 | + Keyword: r.Keyword, |
| 89 | + IsOfficial: r.IsOfficial, |
| 90 | + CategoryIDs: r.CategoryIDs, |
| 91 | + SortType: r.SortType, |
| 92 | + PageNum: page.PageNum, |
| 93 | + PageSize: page.PageSize, |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +type listStoresPluginsResp struct { |
| 98 | + baseResponse |
| 99 | + Data *ListStoresPluginsResp `json:"data"` |
| 100 | +} |
| 101 | + |
| 102 | +type storesPlugins struct { |
| 103 | + core *core |
| 104 | +} |
| 105 | + |
| 106 | +func newStoresPlugins(core *core) *storesPlugins { |
| 107 | + return &storesPlugins{core: core} |
| 108 | +} |
0 commit comments