fix(sdk): preserve generated event contracts
This commit is contained in:
parent
1afa9e32c9
commit
25edeaf473
7 changed files with 3120 additions and 2774 deletions
|
|
@ -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 type Action = typeof Action.Type
|
||||||
|
|
||||||
export const Rule = Schema.Struct({
|
export const Rule = Schema.Struct({
|
||||||
permission: Schema.String,
|
permission: Schema.String,
|
||||||
pattern: Schema.String,
|
pattern: Schema.String,
|
||||||
action: Action,
|
action: Action,
|
||||||
}).annotate({ identifier: "PermissionV2.Rule" })
|
}).annotate({ identifier: "Permission.Rule" })
|
||||||
export type Rule = typeof Rule.Type
|
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
|
export type Ruleset = typeof Ruleset.Type
|
||||||
|
|
||||||
const EDIT_TOOLS = ["edit", "write", "apply_patch"]
|
const EDIT_TOOLS = ["edit", "write", "apply_patch"]
|
||||||
|
|
|
||||||
|
|
@ -75,13 +75,13 @@ export const Reply = Schema.Struct({
|
||||||
}).annotate({ identifier: "QuestionReply" })
|
}).annotate({ identifier: "QuestionReply" })
|
||||||
export type Reply = Schema.Schema.Type<typeof Reply>
|
export type Reply = Schema.Schema.Type<typeof Reply>
|
||||||
|
|
||||||
const Replied = Schema.Struct({
|
export const Replied = Schema.Struct({
|
||||||
sessionID: SessionID,
|
sessionID: SessionID,
|
||||||
requestID: QuestionID,
|
requestID: QuestionID,
|
||||||
answers: Schema.Array(Answer),
|
answers: Schema.Array(Answer),
|
||||||
}).annotate({ identifier: "QuestionReplied" })
|
}).annotate({ identifier: "QuestionReplied" })
|
||||||
|
|
||||||
const Rejected = Schema.Struct({
|
export const Rejected = Schema.Struct({
|
||||||
sessionID: SessionID,
|
sessionID: SessionID,
|
||||||
requestID: QuestionID,
|
requestID: QuestionID,
|
||||||
}).annotate({ identifier: "QuestionRejected" })
|
}).annotate({ identifier: "QuestionRejected" })
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
import { EventV2 } from "@opencode-ai/core/event"
|
import { EventV2 } from "@opencode-ai/core/event"
|
||||||
|
import { Schema } from "effect"
|
||||||
|
|
||||||
export const Event = {
|
export const Event = {
|
||||||
Connected: EventV2.define({ type: "server.connected", schema: {} }),
|
Connected: EventV2.define({ type: "server.connected", schema: {} }),
|
||||||
Disposed: EventV2.define({ type: "global.disposed", 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" })
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
import { HttpApi } from "effect/unstable/httpapi"
|
import { HttpApi } from "effect/unstable/httpapi"
|
||||||
import { EventV2 } from "@opencode-ai/core/event"
|
import { EventV2 } from "@opencode-ai/core/event"
|
||||||
|
import { InstanceDisposed } from "@/server/event"
|
||||||
|
import { Question } from "@/question"
|
||||||
import { ConfigApi } from "./groups/config"
|
import { ConfigApi } from "./groups/config"
|
||||||
import { ControlApi } from "./groups/control"
|
import { ControlApi } from "./groups/control"
|
||||||
import { EventApi } from "./groups/event"
|
import { EventApi } from "./groups/event"
|
||||||
import { ExperimentalApi } from "./groups/experimental"
|
import { ExperimentalApi } from "./groups/experimental"
|
||||||
import { FileApi } from "./groups/file"
|
import { FileApi } from "./groups/file"
|
||||||
import { GlobalApi } from "./groups/global"
|
|
||||||
import { InstanceApi } from "./groups/instance"
|
import { InstanceApi } from "./groups/instance"
|
||||||
import { McpApi } from "./groups/mcp"
|
import { McpApi } from "./groups/mcp"
|
||||||
import { PermissionApi } from "./groups/permission"
|
import { PermissionApi } from "./groups/permission"
|
||||||
|
|
@ -19,11 +20,13 @@ import { SyncApi } from "./groups/sync"
|
||||||
import { TuiApi } from "./groups/tui"
|
import { TuiApi } from "./groups/tui"
|
||||||
import { WorkspaceApi } from "./groups/workspace"
|
import { WorkspaceApi } from "./groups/workspace"
|
||||||
import { V2Api } from "./groups/v2"
|
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 { Authorization } from "./middleware/authorization"
|
||||||
import { SchemaErrorMiddleware } from "./middleware/schema-error"
|
import { SchemaErrorMiddleware } from "./middleware/schema-error"
|
||||||
|
|
||||||
const EventSchema = Schema.Union(
|
const EventSchema = Schema.Union([
|
||||||
EventV2.registry
|
...EventV2.registry
|
||||||
.values()
|
.values()
|
||||||
.map((definition) =>
|
.map((definition) =>
|
||||||
Schema.Struct({
|
Schema.Struct({
|
||||||
|
|
@ -33,7 +36,8 @@ const EventSchema = Schema.Union(
|
||||||
}).annotate({ identifier: `Event.${definition.type}` }),
|
}).annotate({ identifier: `Event.${definition.type}` }),
|
||||||
)
|
)
|
||||||
.toArray(),
|
.toArray(),
|
||||||
).annotate({ identifier: "Event" })
|
InstanceDisposed,
|
||||||
|
]).annotate({ identifier: "Event" })
|
||||||
|
|
||||||
export const RootHttpApi = HttpApi.make("opencode-root")
|
export const RootHttpApi = HttpApi.make("opencode-root")
|
||||||
.addHttpApi(ControlApi)
|
.addHttpApi(ControlApi)
|
||||||
|
|
@ -64,7 +68,7 @@ export const OpenCodeHttpApi = HttpApi.make("opencode")
|
||||||
.addHttpApi(EventApi)
|
.addHttpApi(EventApi)
|
||||||
.addHttpApi(InstanceHttpApi)
|
.addHttpApi(InstanceHttpApi)
|
||||||
.addHttpApi(PtyConnectApi)
|
.addHttpApi(PtyConnectApi)
|
||||||
.annotate(HttpApi.AdditionalSchemas, [EventSchema])
|
.annotate(HttpApi.AdditionalSchemas, [EventSchema, Question.Replied, Question.Rejected])
|
||||||
|
|
||||||
export type RootHttpApiType = typeof RootHttpApi
|
export type RootHttpApiType = typeof RootHttpApi
|
||||||
export type InstanceHttpApiType = typeof InstanceHttpApi
|
export type InstanceHttpApiType = typeof InstanceHttpApi
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { Config } from "@/config/config"
|
import { Config } from "@/config/config"
|
||||||
import { EventV2 } from "@opencode-ai/core/event"
|
import { EventV2 } from "@opencode-ai/core/event"
|
||||||
import "@/server/event"
|
import { InstanceDisposed } from "@/server/event"
|
||||||
import { Schema } from "effect"
|
import { Schema } from "effect"
|
||||||
import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi"
|
import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi"
|
||||||
import { described } from "./metadata"
|
import { described } from "./metadata"
|
||||||
|
|
@ -10,18 +10,37 @@ const GlobalHealth = Schema.Struct({
|
||||||
version: Schema.String,
|
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({
|
const GlobalEventSchema = Schema.Struct({
|
||||||
directory: Schema.String,
|
directory: Schema.String,
|
||||||
project: Schema.optional(Schema.String),
|
project: Schema.optional(Schema.String),
|
||||||
workspace: Schema.optional(Schema.String),
|
workspace: Schema.optional(Schema.String),
|
||||||
payload: Schema.Union(
|
payload: Schema.Union([
|
||||||
EventV2.registry
|
...EventV2.registry
|
||||||
.values()
|
.values()
|
||||||
.map((definition) =>
|
.map((definition) =>
|
||||||
Schema.Struct({ id: Schema.String, type: Schema.Literal(definition.type), properties: definition.data }),
|
Schema.Struct({ id: Schema.String, type: Schema.Literal(definition.type), properties: definition.data }),
|
||||||
)
|
)
|
||||||
.toArray(),
|
.toArray(),
|
||||||
),
|
InstanceDisposed,
|
||||||
|
...SyncEventSchemas,
|
||||||
|
]),
|
||||||
}).annotate({ identifier: "GlobalEvent" })
|
}).annotate({ identifier: "GlobalEvent" })
|
||||||
|
|
||||||
export const GlobalUpgradeInput = Schema.Struct({
|
export const GlobalUpgradeInput = Schema.Struct({
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue