|
|
@@ -1,31 +1,97 @@
|
|
|
import { Context } from "effect"
|
|
|
import { HttpApi, HttpApiGroup, HttpApiMiddleware, OpenApi } from "effect/unstable/httpapi"
|
|
|
-import { SchemaErrorMiddleware } from "./middleware/schema-error"
|
|
|
-import { GenerateGroup } from "./groups/generate"
|
|
|
-import { MessageGroup } from "./groups/message"
|
|
|
-import { ModelGroup } from "./groups/model"
|
|
|
-import { ProviderGroup } from "./groups/provider"
|
|
|
-import { makeSessionGroup } from "./groups/session"
|
|
|
-import { makePermissionGroup } from "./groups/permission"
|
|
|
-import { FileSystemGroup } from "./groups/fs"
|
|
|
-import { CommandGroup } from "./groups/command"
|
|
|
-import { SkillGroup } from "./groups/skill"
|
|
|
-import { EventGroup, makeEventGroup } from "./groups/event"
|
|
|
+import { SchemaErrorMiddleware } from "./middleware/schema-error.js"
|
|
|
+import { GenerateGroup } from "./groups/generate.js"
|
|
|
+import { MessageGroup } from "./groups/message.js"
|
|
|
+import { ModelGroup } from "./groups/model.js"
|
|
|
+import { ProviderGroup } from "./groups/provider.js"
|
|
|
+import { makeSessionGroup } from "./groups/session.js"
|
|
|
+import { makePermissionGroup } from "./groups/permission.js"
|
|
|
+import { FileSystemGroup } from "./groups/fs.js"
|
|
|
+import { CommandGroup } from "./groups/command.js"
|
|
|
+import { SkillGroup } from "./groups/skill.js"
|
|
|
+import { EventGroup, makeEventGroup } from "./groups/event.js"
|
|
|
import type { Definition } from "@opencode-ai/schema/event"
|
|
|
-import { AgentGroup } from "./groups/agent"
|
|
|
-import { PluginGroup } from "./groups/plugin"
|
|
|
-import { HealthGroup } from "./groups/health"
|
|
|
-import { PtyGroup } from "./groups/pty"
|
|
|
-import { ShellGroup } from "./groups/shell"
|
|
|
-import { makeQuestionGroup } from "./groups/question"
|
|
|
-import { ReferenceGroup } from "./groups/reference"
|
|
|
-import { Authorization } from "./middleware/authorization"
|
|
|
-import { LocationGroup } from "./groups/location"
|
|
|
-import { IntegrationGroup } from "./groups/integration"
|
|
|
-import { McpGroup } from "./groups/mcp"
|
|
|
-import { CredentialGroup } from "./groups/credential"
|
|
|
-import { ProjectGroup } from "./groups/project"
|
|
|
-import { ProjectCopyGroup } from "./groups/project-copy"
|
|
|
+import { AgentGroup } from "./groups/agent.js"
|
|
|
+import { PluginGroup } from "./groups/plugin.js"
|
|
|
+import { HealthGroup } from "./groups/health.js"
|
|
|
+import { PtyGroup } from "./groups/pty.js"
|
|
|
+import { ShellGroup } from "./groups/shell.js"
|
|
|
+import { makeQuestionGroup } from "./groups/question.js"
|
|
|
+import { ReferenceGroup } from "./groups/reference.js"
|
|
|
+import { Authorization } from "./middleware/authorization.js"
|
|
|
+import { LocationGroup } from "./groups/location.js"
|
|
|
+import { IntegrationGroup } from "./groups/integration.js"
|
|
|
+import { McpGroup } from "./groups/mcp.js"
|
|
|
+import { CredentialGroup } from "./groups/credential.js"
|
|
|
+import { ProjectGroup } from "./groups/project.js"
|
|
|
+import { ProjectCopyGroup } from "./groups/project-copy.js"
|
|
|
+
|
|
|
+type LocationGroups<LocationId extends HttpApiMiddleware.AnyId> =
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof LocationGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof AgentGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof PluginGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof ModelGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof GenerateGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof ProviderGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof IntegrationGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof McpGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof CredentialGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof ProjectGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof FileSystemGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof CommandGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof SkillGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof PtyGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof ShellGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof ReferenceGroup, LocationId>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof ProjectCopyGroup, LocationId>
|
|
|
+
|
|
|
+type SessionGroups<SessionLocationId extends HttpApiMiddleware.AnyId, SessionLocationService> =
|
|
|
+ | ReturnType<typeof makeSessionGroup<SessionLocationId, SessionLocationService>>
|
|
|
+ | HttpApiGroup.AddMiddleware<typeof MessageGroup, SessionLocationId>
|
|
|
+
|
|
|
+type MixedMiddlewareGroups<
|
|
|
+ LocationId extends HttpApiMiddleware.AnyId,
|
|
|
+ LocationService,
|
|
|
+ SessionLocationId extends HttpApiMiddleware.AnyId,
|
|
|
+ SessionLocationService,
|
|
|
+> =
|
|
|
+ | ReturnType<
|
|
|
+ typeof makePermissionGroup<LocationId, LocationService, SessionLocationId, SessionLocationService>
|
|
|
+ >
|
|
|
+ | ReturnType<typeof makeQuestionGroup<LocationId, LocationService, SessionLocationId, SessionLocationService>>
|
|
|
+
|
|
|
+type ApiGroups<
|
|
|
+ LocationId extends HttpApiMiddleware.AnyId,
|
|
|
+ LocationService,
|
|
|
+ SessionLocationId extends HttpApiMiddleware.AnyId,
|
|
|
+ SessionLocationService,
|
|
|
+ Event extends HttpApiGroup.Any,
|
|
|
+> =
|
|
|
+ | typeof HealthGroup
|
|
|
+ | LocationGroups<LocationId>
|
|
|
+ | SessionGroups<SessionLocationId, SessionLocationService>
|
|
|
+ | MixedMiddlewareGroups<LocationId, LocationService, SessionLocationId, SessionLocationService>
|
|
|
+ | Event
|
|
|
+
|
|
|
+type EventGroupFor<Definitions extends ReadonlyArray<Definition>> = ReturnType<typeof makeEventGroup<Definitions>>
|
|
|
+
|
|
|
+export type Api<
|
|
|
+ LocationId extends HttpApiMiddleware.AnyId,
|
|
|
+ LocationService,
|
|
|
+ SessionLocationId extends HttpApiMiddleware.AnyId,
|
|
|
+ SessionLocationService,
|
|
|
+ Event extends HttpApiGroup.Any,
|
|
|
+> = HttpApi.HttpApi<
|
|
|
+ "server",
|
|
|
+ HttpApiGroup.AddMiddleware<
|
|
|
+ HttpApiGroup.AddMiddleware<
|
|
|
+ ApiGroups<LocationId, LocationService, SessionLocationId, SessionLocationService, Event>,
|
|
|
+ Authorization
|
|
|
+ >,
|
|
|
+ SchemaErrorMiddleware
|
|
|
+ >
|
|
|
+>
|
|
|
|
|
|
// Protocol owns middleware placement, while Server injects concrete keys so Core service identities stay downstream.
|
|
|
const makeApiFromGroup = <
|
|
|
@@ -38,7 +104,7 @@ const makeApiFromGroup = <
|
|
|
eventGroup: Group,
|
|
|
locationMiddleware: Context.Key<LocationId, LocationService>,
|
|
|
sessionLocationMiddleware: Context.Key<SessionLocationId, SessionLocationService>,
|
|
|
-) =>
|
|
|
+): Api<LocationId, LocationService, SessionLocationId, SessionLocationService, Group> =>
|
|
|
HttpApi.make("server")
|
|
|
.add(HealthGroup)
|
|
|
.add(LocationGroup.middleware(locationMiddleware))
|
|
|
@@ -74,15 +140,16 @@ const makeApiFromGroup = <
|
|
|
.middleware(SchemaErrorMiddleware)
|
|
|
|
|
|
export const makeApi = <
|
|
|
+ const Definitions extends ReadonlyArray<Definition>,
|
|
|
LocationId extends HttpApiMiddleware.AnyId,
|
|
|
LocationService,
|
|
|
SessionLocationId extends HttpApiMiddleware.AnyId,
|
|
|
SessionLocationService,
|
|
|
>(options: {
|
|
|
- readonly definitions: ReadonlyArray<Definition>
|
|
|
+ readonly definitions: Definitions
|
|
|
readonly locationMiddleware: Context.Key<LocationId, LocationService>
|
|
|
readonly sessionLocationMiddleware: Context.Key<SessionLocationId, SessionLocationService>
|
|
|
-}) =>
|
|
|
+}): Api<LocationId, LocationService, SessionLocationId, SessionLocationService, EventGroupFor<Definitions>> =>
|
|
|
makeApiFromGroup(makeEventGroup(options.definitions), options.locationMiddleware, options.sessionLocationMiddleware)
|
|
|
|
|
|
export const makeDefaultApi = <
|
|
|
@@ -93,4 +160,5 @@ export const makeDefaultApi = <
|
|
|
>(options: {
|
|
|
readonly locationMiddleware: Context.Key<LocationId, LocationService>
|
|
|
readonly sessionLocationMiddleware: Context.Key<SessionLocationId, SessionLocationService>
|
|
|
-}) => makeApiFromGroup(EventGroup, options.locationMiddleware, options.sessionLocationMiddleware)
|
|
|
+}): Api<LocationId, LocationService, SessionLocationId, SessionLocationService, typeof EventGroup> =>
|
|
|
+ makeApiFromGroup(EventGroup, options.locationMiddleware, options.sessionLocationMiddleware)
|