Skip to content

feat(sdk)!: Provider.Test、模型探测和失败的视频任务返回 error - #66

Merged
HoneyBBQ merged 1 commit into
feat/errors-direct-httpfrom
feat/errors-probe
Sep 30, 2026
Merged

HoneyBBQ merged 1 commit into
feat/errors-direct-httpfrom
feat/errors-probe

Conversation

@HoneyBBQ

@HoneyBBQ HoneyBBQ commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

问题

Provider.Test 返回的 ProviderTestResult 只有一个状态枚举和一段 message,底层错误被丢掉了。调用方要区分 key 无效和主机不可达,只能匹配 Message,Memoh 目前就是匹配 "authentication failed"。TestModel 的探测用 ProbeStatus,只保留了状态码。

GenerateVideo 把失败的任务返回成格式化字符串。轮询被 context 提前中断时,context 的错误也会丢失。

改动

  • Provider.Test(ctx) 改为返回 error。provider 可达且接受凭据时返回 nil,provider 拒绝检查时返回 *sdk.APIError,其他情况返回包装后的传输错误。OpenCode Go 的检查请求公开的模型列表端点,nil 只说明端点可达,凭据要用 TestModel 验证。删除 ProviderTestResult、ProviderStatus 及其常量。
  • ClassifyProbeStatus(int) 改为 ClassifyProbe(err)。错误为 nil 或状态码为 400、422、429 时,判定模型受支持;404 判定为模型不存在。其他错误原样返回,所以 401 会保留它的 Kind。
  • utils.ProbeStatus 改为 utils.Probe,非 2xx 响应返回 *sdk.APIError。
  • GenerateVideo 把失败的任务返回成 *sdk.APIError,StatusCode 为 0,带上任务的 code、message 和 Kind。轮询提前结束时包装 ctx.Err()。方舟任务失败时保留错误码,下载失败返回 *sdk.APIError。
  • VideoProvider 新增必须实现的 Name(),VideoError 新增 Kind 字段。

验证

  • go build ./...、go vet ./...、go test ./... -short -count=1 -race 和 golangci-lint run ./... 均通过,go mod tidy 无 diff。
  • conformance 套件对每个聊天 provider 的 Test 检查三种情况:主机可达、key 被拒(*sdk.APIError,Kind 为 KindAuthentication)、主机不可达。模型探测用 400、422、429、404 和 key 被拒几种响应检查。
  • OpenCode Go 的 Test 有 httptest 用例,公开模型列表可达时返回 nil。
  • ClassifyProbe 有表格测试,覆盖 nil、每个判定为受支持的状态码、404、其他 API 错误和非 API 错误。
  • GenerateVideo 有任务失败、超时和 context 取消的测试。每个视频包都测试了任务失败和下载返回非 2xx。

⚠️ No human QA

@HoneyBBQ
HoneyBBQ added this pull request to stack #67 September 28, 2026 13:17
@HoneyBBQ HoneyBBQ changed the title feat(sdk)!: return errors from Provider.Test, model probes and failed video jobs feat(sdk)!: Provider.Test、模型探测和失败的视频任务返回 error Sep 28, 2026
@HoneyBBQ
HoneyBBQ force-pushed the feat/errors-probe branch 2 times, most recently from 73f0ca7 to 0a288a2 Compare September 29, 2026 11:45
Provider.Test now returns error: nil when the provider is reachable and
accepts the credentials, a *APIError when it rejected the check, and the
wrapped transport error otherwise. ProviderTestResult, ProviderStatus and
its constants are removed; callers read KindOf(err) instead of matching
the message text.

ClassifyProbeStatus(int) becomes ClassifyProbe(err). utils.ProbeStatus
becomes utils.Probe, which returns *APIError for non-2xx responses, so a
401 from the TestModel probe keeps its Kind.

GenerateVideo returns a failed job as a *APIError with StatusCode 0 and
the job's Code, Message and Kind, and wraps the context error when
polling ends early. VideoProvider gains Name(), VideoError gains Kind,
Ark task failures keep their code, and download failures are *APIError.

BREAKING CHANGE: Provider.Test returns error; ProviderTestResult,
ProviderStatus and ClassifyProbeStatus are removed; VideoProvider
requires Name().
@HoneyBBQ
HoneyBBQ marked this pull request as ready for review September 30, 2026 06:54
@HoneyBBQ
HoneyBBQ merged commit d0ae284 into main Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant