feat(cli): adopt generated oRPC contract for unary endpoints (#37090)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-06-08 08:09:44 +00:00
1 parent d0b376d31a
commit a15ecf6bec
27 files changed
+798 -184

No files matched your search

+9 -4
View File
@@ -1,15 +1,20 @@
import type { WorkspaceDetailResponse, WorkspaceListResponse } from '@dify/contracts/api/openapi/types.gen'
import type { OpenApiClient } from '@/http/orpc'
import type { HttpClient } from '@/http/types'
import { createOpenApiClient } from '@/http/orpc'
export class WorkspacesClient {
private readonly http: HttpClient
private readonly orpc: OpenApiClient
constructor(http: HttpClient) {
this.http = http
// oRPC client over the same transport (UA+bearer / retry / timeout / error-map) — SPEC §4.4:
// one transport, a contract facade. Both methods are standard unary JSON, so both go through
// the generated contract.
this.orpc = createOpenApiClient(http)
}
async list(): Promise<WorkspaceListResponse> {
return this.http.get<WorkspaceListResponse>('workspaces')
return this.orpc.workspaces.get()
}
/**
@@ -22,6 +27,6 @@ export class WorkspacesClient {
* server's state.
*/
async switch(workspaceId: string): Promise<WorkspaceDetailResponse> {
return this.http.post<WorkspaceDetailResponse>(`workspaces/${encodeURIComponent(workspaceId)}/switch`)
return this.orpc.workspaces.byWorkspaceId.switch.post({ params: { workspace_id: workspaceId } })
}
}