location.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Location } from "@opencode-ai/schema/location"
  2. import { Schema } from "effect"
  3. import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
  4. export const LocationQuery = Schema.Struct({
  5. location: Schema.optional(
  6. Schema.Struct({
  7. directory: Schema.optional(Schema.String),
  8. workspace: Schema.optional(Schema.String),
  9. }),
  10. ),
  11. }).annotate({ identifier: "LocationQuery" })
  12. export const locationQueryOpenApi = OpenApi.annotations({
  13. transform: (operation) => {
  14. const parameters = operation.parameters
  15. if (!Array.isArray(parameters)) return operation
  16. return {
  17. ...operation,
  18. parameters: parameters.map((parameter) =>
  19. parameter?.name === "location" && parameter?.in === "query"
  20. ? { ...parameter, style: "deepObject", explode: true }
  21. : parameter,
  22. ),
  23. }
  24. },
  25. })
  26. export const LocationGroup = HttpApiGroup.make("server.location").add(
  27. HttpApiEndpoint.get("location.get", "/api/location", {
  28. query: LocationQuery,
  29. success: Location.Info,
  30. })
  31. .annotateMerge(locationQueryOpenApi)
  32. .annotateMerge(
  33. OpenApi.annotations({
  34. identifier: "v2.location.get",
  35. summary: "Get location",
  36. description: "Resolve the requested location or the server default location.",
  37. }),
  38. ),
  39. )