chore(server): publish api package
This commit is contained in:
parent
140224b0fc
commit
6272c77912
8 changed files with 94 additions and 16 deletions
|
|
@ -5,10 +5,19 @@
|
|||
"private": true,
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/anomalyco/opencode.git",
|
||||
"directory": "packages/server"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"exports": {
|
||||
"./*": "./src/*.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"build:publish": "bun tsc -p tsconfig.publish.json",
|
||||
"typecheck": "tsgo --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
|||
52
packages/server/script/publish.ts
Normal file
52
packages/server/script/publish.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env bun
|
||||
|
||||
import { Script } from "@opencode-ai/script"
|
||||
import { $ } from "bun"
|
||||
import { rm } from "node:fs/promises"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
process.chdir(fileURLToPath(new URL("..", import.meta.url)))
|
||||
|
||||
const originalText = await Bun.file("package.json").text()
|
||||
const pkg = JSON.parse(originalText) as {
|
||||
name: string
|
||||
version: string
|
||||
private?: boolean
|
||||
files?: Array<string>
|
||||
scripts?: Record<string, string>
|
||||
dependencies: Record<string, string>
|
||||
devDependencies?: Record<string, string>
|
||||
exports: Record<string, unknown>
|
||||
}
|
||||
const tarball = `${pkg.name.replace("@", "").replace("/", "-")}-${pkg.version}.tgz`
|
||||
|
||||
if ((await $`npm view ${pkg.name}@${pkg.version} version`.nothrow()).exitCode === 0) {
|
||||
console.log(`already published ${pkg.name}@${pkg.version}`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
try {
|
||||
await $`rm -rf dist`
|
||||
await $`bun run build:publish`
|
||||
delete pkg.private
|
||||
delete pkg.scripts
|
||||
delete pkg.devDependencies
|
||||
pkg.files = ["dist"]
|
||||
pkg.exports = {
|
||||
"./api": {
|
||||
import: "./dist/api.js",
|
||||
types: "./dist/api.d.ts",
|
||||
},
|
||||
}
|
||||
pkg.dependencies = {
|
||||
"@opencode-ai/protocol": pkg.dependencies["@opencode-ai/protocol"],
|
||||
effect: pkg.dependencies.effect,
|
||||
}
|
||||
await Bun.write("package.json", JSON.stringify(pkg, null, 2) + "\n")
|
||||
await rm(tarball, { force: true })
|
||||
await $`bun pm pack`
|
||||
await $`npm publish ${tarball} --tag ${Script.channel} --access public`
|
||||
} finally {
|
||||
await Bun.write("package.json", originalText)
|
||||
await rm(tarball, { force: true })
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
import { makeDefaultApi } from "@opencode-ai/protocol/api"
|
||||
import { LocationMiddleware } from "./location"
|
||||
import { SessionLocationMiddleware } from "./middleware/session-location"
|
||||
import { LocationMiddleware, SessionLocationMiddleware } from "./middleware/location.js"
|
||||
|
||||
export const Api = makeDefaultApi({
|
||||
locationMiddleware: LocationMiddleware,
|
||||
|
|
|
|||
|
|
@ -4,14 +4,10 @@ import { AbsolutePath } from "@opencode-ai/core/schema"
|
|||
import { WorkspaceV2 } from "@opencode-ai/core/workspace"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { HttpServerRequest } from "effect/unstable/http"
|
||||
import { HttpApiMiddleware } from "effect/unstable/httpapi"
|
||||
import { LocationMiddleware } from "./middleware/location.js"
|
||||
|
||||
export type LocationServices = Layer.Success<ReturnType<(typeof LocationServiceMap.Service)["get"]>>
|
||||
|
||||
export class LocationMiddleware extends HttpApiMiddleware.Service<LocationMiddleware, { provides: LocationServices }>()(
|
||||
"@opencode/HttpApiLocation",
|
||||
) {}
|
||||
|
||||
export function response<A, E, R>(data: Effect.Effect<A, E, R>) {
|
||||
return Effect.gen(function* () {
|
||||
const location = yield* Location.Service
|
||||
|
|
|
|||
13
packages/server/src/middleware/location.ts
Normal file
13
packages/server/src/middleware/location.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { InvalidRequestError, SessionNotFoundError } from "@opencode-ai/protocol/errors"
|
||||
import { HttpApiMiddleware } from "effect/unstable/httpapi"
|
||||
|
||||
export class LocationMiddleware extends HttpApiMiddleware.Service<LocationMiddleware>()(
|
||||
"@opencode/HttpApiLocation",
|
||||
) {}
|
||||
|
||||
export class SessionLocationMiddleware extends HttpApiMiddleware.Service<SessionLocationMiddleware>()(
|
||||
"@opencode/HttpApiSessionLocation",
|
||||
{
|
||||
error: [InvalidRequestError, SessionNotFoundError],
|
||||
},
|
||||
) {}
|
||||
|
|
@ -8,16 +8,8 @@ import { WorkspaceV2 } from "@opencode-ai/core/workspace"
|
|||
import { eq } from "drizzle-orm"
|
||||
import { Effect, Layer, Schema } from "effect"
|
||||
import { HttpRouter } from "effect/unstable/http"
|
||||
import { HttpApiMiddleware } from "effect/unstable/httpapi"
|
||||
import { InvalidRequestError, SessionNotFoundError } from "@opencode-ai/protocol/errors"
|
||||
import type { LocationServices } from "../location"
|
||||
|
||||
export class SessionLocationMiddleware extends HttpApiMiddleware.Service<
|
||||
SessionLocationMiddleware,
|
||||
{ provides: LocationServices }
|
||||
>()("@opencode/HttpApiSessionLocation", {
|
||||
error: [InvalidRequestError, SessionNotFoundError],
|
||||
}) {}
|
||||
import { SessionLocationMiddleware } from "./location.js"
|
||||
|
||||
const decodeSessionID = Schema.decodeUnknownEffect(SessionV2.ID)
|
||||
|
||||
|
|
|
|||
14
packages/server/tsconfig.publish.json
Normal file
14
packages/server/tsconfig.publish.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"noEmit": false,
|
||||
"declaration": true,
|
||||
"allowImportingTsExtensions": false
|
||||
},
|
||||
"include": ["src/api.ts", "src/middleware/location.ts"]
|
||||
}
|
||||
|
|
@ -41,6 +41,9 @@ await $`bun ./packages/schema/script/publish.ts`
|
|||
console.log("\n=== protocol ===\n")
|
||||
await $`bun ./packages/protocol/script/publish.ts`
|
||||
|
||||
console.log("\n=== server ===\n")
|
||||
await $`bun ./packages/server/script/publish.ts`
|
||||
|
||||
console.log("\n=== cli ===\n")
|
||||
await $`bun ./packages/cli/script/publish.ts`
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue