provider

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package provider 定义 provider adapter 的稳定内部接口和数据契约。 本包不执行 lark-cli 命令;实际 CLI 调用在 internal/app 的 adapter 实现中完成。 把契约类型独立出来,便于在不依赖 app Service 的情况下测试 adapter 行为和 provider 选择。

Index

Constants

View Source
const CapabilityErrorCode = "provider_capability_missing"

CapabilityErrorCode 返回 capability missing 的稳定 error code。

Variables

View Source
var ErrCapabilityMissing = errors.New("provider_capability_missing")

CapabilityMissingError 表示 provider 暂不支持原生文档写入。 app 层不得静默降级到 markdown-file,必须把该错误透传给用户。

Functions

func AppendAs added in v0.2.0

func AppendAs(args []string, as string) []string

AppendAs appends the profile's --as identity argument when it is set and not "auto". Shared with the app-layer lark argument builder.

func ExtractJSON added in v0.2.0

func ExtractJSON(body []byte) []byte

ExtractJSON returns the first JSON object found in CLI output, tolerating leading non-JSON noise. Shared with the app-layer provider call sites.

func FirstString added in v0.2.0

func FirstString(payload map[string]any, keys ...string) string

FirstString resolves the first non-empty string among keys, looking in both the payload root and its nested "data" object. Shared with the app-layer provider result parsing.

func ResolveExternalObjectType

func ResolveExternalObjectType(renderer domain.PublishDocRenderer, providerType string) string

ResolveExternalObjectType 根据 renderer 和 provider 返回类型决定 external_object.type。 native-docx 应得到 docx/doc;markdown-file 得到 file。

Types

type LarkNativeCLICommand

type LarkNativeCLICommand struct {
	Dir   string
	Name  string
	Args  []string
	Stdin string
}

LarkNativeCLICommand 是 adapter 交给外部 CLI runner 的完整命令描述。

type LarkNativeCLIRunner

type LarkNativeCLIRunner interface {
	Run(ctx context.Context, cmd LarkNativeCLICommand) ([]byte, error)
}

LarkNativeCLIRunner 执行 provider CLI。测试可注入 fake runner,避免依赖真实 lark-cli。

type LarkNativeDocAdapter

type LarkNativeDocAdapter interface {
	// CheckCapability 探测 lark-cli 是否支持原生文档写入。
	CheckCapability(ctx context.Context) error
	// CreateNativeDoc 创建原生文档,返回 docx/doc 对象。
	CreateNativeDoc(ctx context.Context, input NativeDocCreateInput) (NativeDocResult, error)
	// UpdateNativeDoc 更新已有原生文档正文。
	UpdateNativeDoc(ctx context.Context, input NativeDocUpdateInput) (NativeDocResult, error)
	// UploadMedia 上传图片/渲染资产,返回 provider media token。
	UploadMedia(ctx context.Context, input MediaUploadInput) (string, error)
	// InspectObjectType 查询远端对象类型(docx/doc/file)。
	InspectObjectType(ctx context.Context, docToken string) (string, error)
}

LarkNativeDocAdapter 定义 lark-cli 原生文档能力的稳定内部接口。 app 层的 adapter 实现封装实际 lark-cli 命令名,保证调用方只依赖此接口。

type LarkNativeDocCLIAdapter

type LarkNativeDocCLIAdapter struct {
	// contains filtered or unexported fields
}

LarkNativeDocCLIAdapter 封装 lark-cli native-docx 命令参数和 JSON 结果解析。

func NewLarkNativeDocCLIAdapter

func NewLarkNativeDocCLIAdapter(profile domain.PublishDocProfile, runner LarkNativeCLIRunner) *LarkNativeDocCLIAdapter

NewLarkNativeDocCLIAdapter 创建 lark-cli 原生文档 adapter。

func (*LarkNativeDocCLIAdapter) CheckCapability

func (a *LarkNativeDocCLIAdapter) CheckCapability(ctx context.Context) error

func (*LarkNativeDocCLIAdapter) CreateNativeDoc

func (*LarkNativeDocCLIAdapter) InspectObjectType

func (a *LarkNativeDocCLIAdapter) InspectObjectType(ctx context.Context, docToken string) (string, error)

func (*LarkNativeDocCLIAdapter) UpdateNativeDoc

func (*LarkNativeDocCLIAdapter) UploadMedia

func (a *LarkNativeDocCLIAdapter) UploadMedia(ctx context.Context, input MediaUploadInput) (string, error)

type MediaUploadInput

type MediaUploadInput struct {
	Root      string
	DocToken  string
	Path      string // vault-relative artifact 路径
	MediaType string
	Caption   string
	Width     int
}

MediaUploadInput 描述一次资产上传。

type NativeDocCreateInput

type NativeDocCreateInput struct {
	Title       string
	FolderToken string
	PlanJSON    []byte
	ContentPath string
}

NativeDocCreateInput 是创建飞书原生文档的 provider-neutral 输入。 PlanJSON 是序列化后的 publishdocast.NativePlan;adapter 负责翻译成 provider 命令。

type NativeDocResult

type NativeDocResult struct {
	Token string // doc token / file token
	URL   string
	Type  string // docx / doc / file
}

NativeDocResult 是 create/update 的归一化结果。

type NativeDocUpdateInput

type NativeDocUpdateInput struct {
	Title       string
	DocToken    string
	PlanJSON    []byte
	ContentPath string
	ExistingURL string
}

NativeDocUpdateInput 是更新飞书原生文档的输入。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL