Dax Raad 4 недель назад
Родитель
Сommit
f80343b875

+ 1 - 1
packages/opencode/src/auth/index.ts

@@ -32,7 +32,7 @@ export namespace Auth {
     token: Schema.String,
   }) {}
 
-  const _Info = Schema.Union([Oauth, Api, WellKnown])
+  const _Info = Schema.Union([Oauth, Api, WellKnown]).annotate({ discriminator: "type", identifier: "Auth" })
   export const Info = Object.assign(_Info, { zod: zod(_Info) })
   export type Info = Schema.Schema.Type<typeof _Info>
 

+ 6 - 0
packages/opencode/src/util/effect-zod.ts

@@ -60,6 +60,12 @@ function union(ast: SchemaAST.Union): z.ZodTypeAny {
   const items = ast.types.map(walk)
   if (items.length === 1) return items[0]
   if (items.length < 2) return fail(ast)
+
+  const discriminator = (ast as any).annotations?.discriminator
+  if (discriminator) {
+    return z.discriminatedUnion(discriminator, items as [z.ZodObject<any>, z.ZodObject<any>, ...z.ZodObject<any>[]])
+  }
+
   return z.union(items as [z.ZodTypeAny, z.ZodTypeAny, ...Array<z.ZodTypeAny>])
 }
 

+ 3 - 5
packages/sdk/js/src/v2/gen/sdk.gen.ts

@@ -4,11 +4,11 @@ import { client } from "./client.gen.js"
 import { buildClientParams, type Client, type Options as Options2, type TDataShape } from "./client/index.js"
 import type {
   AgentPartInput,
-  ApiAuth,
   AppAgentsResponses,
   AppLogErrors,
   AppLogResponses,
   AppSkillsResponses,
+  Auth as Auth3,
   AuthRemoveErrors,
   AuthRemoveResponses,
   AuthSetErrors,
@@ -63,7 +63,6 @@ import type {
   McpLocalConfig,
   McpRemoteConfig,
   McpStatusResponses,
-  OAuth,
   OutputFormat,
   Part as Part2,
   PartDeleteErrors,
@@ -174,7 +173,6 @@ import type {
   TuiShowToastResponses,
   TuiSubmitPromptResponses,
   VcsGetResponses,
-  WellKnownAuth,
   WorktreeCreateErrors,
   WorktreeCreateInput,
   WorktreeCreateResponses,
@@ -339,7 +337,7 @@ export class Auth extends HeyApiClient {
   public set<ThrowOnError extends boolean = false>(
     parameters: {
       providerID: string
-      body?: OAuth | ApiAuth | WellKnownAuth
+      auth?: Auth3
     },
     options?: Options<never, ThrowOnError>,
   ) {
@@ -349,7 +347,7 @@ export class Auth extends HeyApiClient {
         {
           args: [
             { in: "path", key: "providerID" },
-            { key: "body", map: "body" },
+            { key: "auth", map: "body" },
           ],
         },
       ],

+ 3 - 1
packages/sdk/js/src/v2/gen/types.gen.ts

@@ -1534,6 +1534,8 @@ export type WellKnownAuth = {
   token: string
 }
 
+export type Auth = OAuth | ApiAuth | WellKnownAuth
+
 export type NotFoundError = {
   name: "NotFoundError"
   data: {
@@ -2056,7 +2058,7 @@ export type AuthRemoveResponses = {
 export type AuthRemoveResponse = AuthRemoveResponses[keyof AuthRemoveResponses]
 
 export type AuthSetData = {
-  body?: OAuth | ApiAuth | WellKnownAuth
+  body?: Auth
   path: {
     providerID: string
   }