refactor: unify AI capabilities and workspace integration
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
"""Domain-owned AI capabilities; caller owns authorization and transactions."""
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from ..ai.capabilities import Capability, EmptyArgs
|
||||
from ..schemas import Contract
|
||||
from .contracts import CatalogFilters, Scope
|
||||
from .platform import platform_options
|
||||
|
||||
|
||||
class CatalogSearchArgs(Contract):
|
||||
filters: CatalogFilters
|
||||
dataset_id: str | None = Field(default=None, min_length=1, max_length=200)
|
||||
|
||||
|
||||
class CatalogDetailArgs(Contract):
|
||||
scope: Scope
|
||||
dataset_id: str = Field(min_length=1, max_length=200)
|
||||
field_id: str = Field(default="", max_length=200)
|
||||
|
||||
|
||||
async def search(ctx, args):
|
||||
data = await ctx.business.catalog.search(args.filters, args.dataset_id)
|
||||
return {
|
||||
**data,
|
||||
"scope": args.filters.model_dump(include=set(Scope.model_fields)),
|
||||
"dataset_id": args.dataset_id,
|
||||
}
|
||||
|
||||
|
||||
async def detail(ctx, args):
|
||||
data = await ctx.business.catalog.detail(args.scope, args.dataset_id, args.field_id)
|
||||
# Saved notes are unnecessary for selection; unsaved drafts never enter this interface.
|
||||
data.pop("research", None)
|
||||
return data
|
||||
|
||||
|
||||
INSTRUCTIONS = ""
|
||||
|
||||
|
||||
CAPABILITIES = (
|
||||
Capability(
|
||||
name="get_catalog_scopes",
|
||||
schema=EmptyArgs,
|
||||
description="从平台读取当前账户可用的研究范围组合。",
|
||||
label="读取研究范围",
|
||||
renderer="catalog",
|
||||
effect="query",
|
||||
handler=lambda ctx, args: platform_options(ctx.platform_client),
|
||||
source="worldquant_platform",
|
||||
),
|
||||
Capability(
|
||||
name="search_catalog",
|
||||
schema=CatalogSearchArgs,
|
||||
description="分页查询本地目录。省略 dataset_id 查询数据集;提供 dataset_id 查询其字段、类型和完整集合版本。无缓存时说明需在数据集页同步,不编造字段。",
|
||||
label="查询数据集与字段",
|
||||
renderer="catalog",
|
||||
effect="query",
|
||||
handler=search,
|
||||
),
|
||||
Capability(
|
||||
name="get_catalog_detail",
|
||||
schema=CatalogDetailArgs,
|
||||
description="读取指定范围的数据集或字段详情;field_id 为空表示数据集。",
|
||||
label="读取数据详情",
|
||||
renderer="catalog",
|
||||
effect="query",
|
||||
handler=detail,
|
||||
),
|
||||
)
|
||||
Reference in New Issue
Block a user