Просмотр исходного кода

fix(sdk): preserve generated event contracts

Dax Raad 3 месяцев назад
Родитель
Сommit
25edeaf473

+ 3 - 3
packages/core/src/permission.ts

@@ -14,17 +14,17 @@ export class PermissionID extends Newtype<PermissionID>()(
   }
 }
 
-export const Action = Schema.Literals(["allow", "deny", "ask"]).annotate({ identifier: "PermissionV2.Action" })
+export const Action = Schema.Literals(["allow", "deny", "ask"]).annotate({ identifier: "Permission.Action" })
 export type Action = typeof Action.Type
 
 export const Rule = Schema.Struct({
   permission: Schema.String,
   pattern: Schema.String,
   action: Action,
-}).annotate({ identifier: "PermissionV2.Rule" })
+}).annotate({ identifier: "Permission.Rule" })
 export type Rule = typeof Rule.Type
 
-export const Ruleset = Schema.Array(Rule).annotate({ identifier: "PermissionV2.Ruleset" })
+export const Ruleset = Schema.Array(Rule).annotate({ identifier: "Permission.Ruleset" })
 export type Ruleset = typeof Ruleset.Type
 
 const EDIT_TOOLS = ["edit", "write", "apply_patch"]

+ 2 - 2
packages/opencode/src/question/index.ts

@@ -75,13 +75,13 @@ export const Reply = Schema.Struct({
 }).annotate({ identifier: "QuestionReply" })
 export type Reply = Schema.Schema.Type<typeof Reply>
 
-const Replied = Schema.Struct({
+export const Replied = Schema.Struct({
   sessionID: SessionID,
   requestID: QuestionID,
   answers: Schema.Array(Answer),
 }).annotate({ identifier: "QuestionReplied" })
 
-const Rejected = Schema.Struct({
+export const Rejected = Schema.Struct({
   sessionID: SessionID,
   requestID: QuestionID,
 }).annotate({ identifier: "QuestionRejected" })

+ 7 - 0
packages/opencode/src/server/event.ts

@@ -1,6 +1,13 @@
 import { EventV2 } from "@opencode-ai/core/event"
+import { Schema } from "effect"
 
 export const Event = {
   Connected: EventV2.define({ type: "server.connected", schema: {} }),
   Disposed: EventV2.define({ type: "global.disposed", schema: {} }),
 }
+
+export const InstanceDisposed = Schema.Struct({
+  id: Schema.String,
+  type: Schema.Literal("server.instance.disposed"),
+  properties: Schema.Struct({ directory: Schema.String }),
+}).annotate({ identifier: "Event.server.instance.disposed" })

+ 9 - 5
packages/opencode/src/server/routes/instance/httpapi/api.ts

@@ -1,12 +1,13 @@
 import { Schema } from "effect"
 import { HttpApi } from "effect/unstable/httpapi"
 import { EventV2 } from "@opencode-ai/core/event"
+import { InstanceDisposed } from "@/server/event"
+import { Question } from "@/question"
 import { ConfigApi } from "./groups/config"
 import { ControlApi } from "./groups/control"
 import { EventApi } from "./groups/event"
 import { ExperimentalApi } from "./groups/experimental"
 import { FileApi } from "./groups/file"
-import { GlobalApi } from "./groups/global"
 import { InstanceApi } from "./groups/instance"
 import { McpApi } from "./groups/mcp"
 import { PermissionApi } from "./groups/permission"
@@ -19,11 +20,13 @@ import { SyncApi } from "./groups/sync"
 import { TuiApi } from "./groups/tui"
 import { WorkspaceApi } from "./groups/workspace"
 import { V2Api } from "./groups/v2"
+// GlobalEventSchema snapshots the registry after event-producing groups register their variants.
+import { GlobalApi } from "./groups/global"
 import { Authorization } from "./middleware/authorization"
 import { SchemaErrorMiddleware } from "./middleware/schema-error"
 
-const EventSchema = Schema.Union(
-  EventV2.registry
+const EventSchema = Schema.Union([
+  ...EventV2.registry
     .values()
     .map((definition) =>
       Schema.Struct({
@@ -33,7 +36,8 @@ const EventSchema = Schema.Union(
       }).annotate({ identifier: `Event.${definition.type}` }),
     )
     .toArray(),
-).annotate({ identifier: "Event" })
+  InstanceDisposed,
+]).annotate({ identifier: "Event" })
 
 export const RootHttpApi = HttpApi.make("opencode-root")
   .addHttpApi(ControlApi)
@@ -64,7 +68,7 @@ export const OpenCodeHttpApi = HttpApi.make("opencode")
   .addHttpApi(EventApi)
   .addHttpApi(InstanceHttpApi)
   .addHttpApi(PtyConnectApi)
-  .annotate(HttpApi.AdditionalSchemas, [EventSchema])
+  .annotate(HttpApi.AdditionalSchemas, [EventSchema, Question.Replied, Question.Rejected])
 
 export type RootHttpApiType = typeof RootHttpApi
 export type InstanceHttpApiType = typeof InstanceHttpApi

+ 23 - 4
packages/opencode/src/server/routes/instance/httpapi/groups/global.ts

@@ -1,6 +1,6 @@
 import { Config } from "@/config/config"
 import { EventV2 } from "@opencode-ai/core/event"
-import "@/server/event"
+import { InstanceDisposed } from "@/server/event"
 import { Schema } from "effect"
 import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi"
 import { described } from "./metadata"
@@ -10,18 +10,37 @@ const GlobalHealth = Schema.Struct({
   version: Schema.String,
 })
 
+const SyncEventSchemas = EventV2.registry
+  .values()
+  .flatMap((definition) => {
+    if (!definition.sync) return []
+    return [
+      Schema.Struct({
+        type: Schema.Literal("sync"),
+        name: Schema.Literal(EventV2.versionedType(definition.type, definition.sync.version)),
+        id: Schema.String,
+        seq: Schema.Finite,
+        aggregateID: Schema.Literal(definition.sync.aggregate),
+        data: definition.data,
+      }).annotate({ identifier: `SyncEvent.${definition.type}` }),
+    ]
+  })
+  .toArray()
+
 const GlobalEventSchema = Schema.Struct({
   directory: Schema.String,
   project: Schema.optional(Schema.String),
   workspace: Schema.optional(Schema.String),
-  payload: Schema.Union(
-    EventV2.registry
+  payload: Schema.Union([
+    ...EventV2.registry
       .values()
       .map((definition) =>
         Schema.Struct({ id: Schema.String, type: Schema.Literal(definition.type), properties: definition.data }),
       )
       .toArray(),
-  ),
+    InstanceDisposed,
+    ...SyncEventSchemas,
+  ]),
 }).annotate({ identifier: "GlobalEvent" })
 
 export const GlobalUpgradeInput = Schema.Struct({

Разница между файлами не показана из-за своего большого размера
+ 822 - 724
packages/sdk/js/src/v2/gen/types.gen.ts


Разница между файлами не показана из-за своего большого размера
+ 2244 - 1932
packages/sdk/openapi.json


Некоторые файлы не были показаны из-за большого количества измененных файлов