From 98c09884bf9d70537237b5750c65e49ebc9e5b86 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Wed, 1 Jul 2026 13:53:09 -0400 Subject: [PATCH] feat(protocol): publish package --- bun.lock | 2 + packages/protocol/package.json | 17 ++- packages/protocol/script/build.ts | 9 ++ packages/protocol/script/publish.ts | 45 +++++++ packages/protocol/src/api.ts | 126 ++++++++++++++---- packages/protocol/src/client.ts | 17 ++- packages/protocol/src/groups/agent.ts | 2 +- packages/protocol/src/groups/command.ts | 2 +- packages/protocol/src/groups/credential.ts | 2 +- packages/protocol/src/groups/fs.ts | 2 +- packages/protocol/src/groups/generate.ts | 4 +- packages/protocol/src/groups/integration.ts | 4 +- packages/protocol/src/groups/mcp.ts | 2 +- packages/protocol/src/groups/message.ts | 2 +- packages/protocol/src/groups/model.ts | 4 +- packages/protocol/src/groups/permission.ts | 4 +- packages/protocol/src/groups/plugin.ts | 2 +- packages/protocol/src/groups/project-copy.ts | 2 +- packages/protocol/src/groups/project.ts | 2 +- packages/protocol/src/groups/provider.ts | 4 +- packages/protocol/src/groups/pty.ts | 4 +- packages/protocol/src/groups/question.ts | 4 +- packages/protocol/src/groups/reference.ts | 2 +- packages/protocol/src/groups/session.ts | 2 +- packages/protocol/src/groups/shell.ts | 4 +- packages/protocol/src/groups/skill.ts | 2 +- .../protocol/src/middleware/authorization.ts | 2 +- .../protocol/src/middleware/schema-error.ts | 2 +- packages/protocol/test/session-cursor.test.ts | 2 +- packages/protocol/tsconfig.build.json | 11 ++ packages/protocol/tsconfig.json | 4 + script/publish.ts | 3 + 32 files changed, 231 insertions(+), 65 deletions(-) create mode 100644 packages/protocol/script/build.ts create mode 100644 packages/protocol/script/publish.ts create mode 100644 packages/protocol/tsconfig.build.json diff --git a/bun.lock b/bun.lock index d817185ffe..5658133b84 100644 --- a/bun.lock +++ b/bun.lock @@ -710,6 +710,7 @@ }, "packages/protocol": { "name": "@opencode-ai/protocol", + "version": "1.17.11", "dependencies": { "@opencode-ai/schema": "workspace:*", "effect": "catalog:", @@ -718,6 +719,7 @@ "@tsconfig/bun": "catalog:", "@types/bun": "catalog:", "@typescript/native-preview": "catalog:", + "typescript": "catalog:", }, }, "packages/schema": { diff --git a/packages/protocol/package.json b/packages/protocol/package.json index 7d4c41dfc7..c79d9dbdf7 100644 --- a/packages/protocol/package.json +++ b/packages/protocol/package.json @@ -1,13 +1,25 @@ { "$schema": "https://json.schemastore.org/package.json", "name": "@opencode-ai/protocol", - "private": true, + "version": "1.17.11", "type": "module", "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/anomalyco/opencode.git", + "directory": "packages/protocol" + }, + "publishConfig": { + "access": "public" + }, + "files": [ + "dist" + ], "exports": { "./*": "./src/*.ts" }, "scripts": { + "build": "bun run script/build.ts", "typecheck": "tsgo --noEmit" }, "dependencies": { @@ -17,6 +29,7 @@ "devDependencies": { "@tsconfig/bun": "catalog:", "@types/bun": "catalog:", - "@typescript/native-preview": "catalog:" + "@typescript/native-preview": "catalog:", + "typescript": "catalog:" } } diff --git a/packages/protocol/script/build.ts b/packages/protocol/script/build.ts new file mode 100644 index 0000000000..323a63ddf9 --- /dev/null +++ b/packages/protocol/script/build.ts @@ -0,0 +1,9 @@ +#!/usr/bin/env bun + +import { $ } from "bun" +import { fileURLToPath } from "node:url" + +process.chdir(fileURLToPath(new URL("..", import.meta.url))) + +await $`rm -rf dist` +await $`bun tsc -p tsconfig.build.json` diff --git a/packages/protocol/script/publish.ts b/packages/protocol/script/publish.ts new file mode 100644 index 0000000000..8e37674b64 --- /dev/null +++ b/packages/protocol/script/publish.ts @@ -0,0 +1,45 @@ +#!/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 + exports: Record +} +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 $`bun run typecheck` + await $`bun run build` + pkg.exports = Object.fromEntries( + Object.entries(pkg.exports).map(([key, value]) => { + if (typeof value !== "string") return [key, value] + return [ + key, + { + import: value.replace("./src/", "./dist/").replace(/\.ts$/, ".js"), + types: value.replace("./src/", "./dist/").replace(/\.ts$/, ".d.ts"), + }, + ] + }), + ) + 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 }) +} diff --git a/packages/protocol/src/api.ts b/packages/protocol/src/api.ts index b8583c8520..886e81c602 100644 --- a/packages/protocol/src/api.ts +++ b/packages/protocol/src/api.ts @@ -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 = + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + | HttpApiGroup.AddMiddleware + +type SessionGroups = + | ReturnType> + | HttpApiGroup.AddMiddleware + +type MixedMiddlewareGroups< + LocationId extends HttpApiMiddleware.AnyId, + LocationService, + SessionLocationId extends HttpApiMiddleware.AnyId, + SessionLocationService, +> = + | ReturnType< + typeof makePermissionGroup + > + | ReturnType> + +type ApiGroups< + LocationId extends HttpApiMiddleware.AnyId, + LocationService, + SessionLocationId extends HttpApiMiddleware.AnyId, + SessionLocationService, + Event extends HttpApiGroup.Any, +> = + | typeof HealthGroup + | LocationGroups + | SessionGroups + | MixedMiddlewareGroups + | Event + +type EventGroupFor> = ReturnType> + +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, + 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, sessionLocationMiddleware: Context.Key, -) => +): Api => HttpApi.make("server") .add(HealthGroup) .add(LocationGroup.middleware(locationMiddleware)) @@ -74,15 +140,16 @@ const makeApiFromGroup = < .middleware(SchemaErrorMiddleware) export const makeApi = < + const Definitions extends ReadonlyArray, LocationId extends HttpApiMiddleware.AnyId, LocationService, SessionLocationId extends HttpApiMiddleware.AnyId, SessionLocationService, >(options: { - readonly definitions: ReadonlyArray + readonly definitions: Definitions readonly locationMiddleware: Context.Key readonly sessionLocationMiddleware: Context.Key -}) => +}): Api> => makeApiFromGroup(makeEventGroup(options.definitions), options.locationMiddleware, options.sessionLocationMiddleware) export const makeDefaultApi = < @@ -93,4 +160,5 @@ export const makeDefaultApi = < >(options: { readonly locationMiddleware: Context.Key readonly sessionLocationMiddleware: Context.Key -}) => makeApiFromGroup(EventGroup, options.locationMiddleware, options.sessionLocationMiddleware) +}): Api => + makeApiFromGroup(EventGroup, options.locationMiddleware, options.sessionLocationMiddleware) diff --git a/packages/protocol/src/client.ts b/packages/protocol/src/client.ts index aa7c45a0ae..30392887a3 100644 --- a/packages/protocol/src/client.ts +++ b/packages/protocol/src/client.ts @@ -1,6 +1,9 @@ -import { InvalidRequestError, SessionNotFoundError } from "./errors" -import { makeDefaultApi } from "./api" +import { InvalidRequestError, SessionNotFoundError } from "./errors.js" +import { makeDefaultApi } from "./api.js" +import type { Api } from "./api.js" +import type { Context } from "effect" import { HttpApiMiddleware } from "effect/unstable/httpapi" +import type { EventGroup } from "./groups/event.js" class LocationMiddleware extends HttpApiMiddleware.Service()( "@opencode-ai/client/LocationMiddleware", @@ -11,7 +14,15 @@ class SessionLocationMiddleware extends HttpApiMiddleware.Service, + Context.Service.Shape, + Context.Service.Identifier, + Context.Service.Shape, + typeof EventGroup +> + +export const ClientApi: ClientApiShape = makeDefaultApi({ locationMiddleware: LocationMiddleware, sessionLocationMiddleware: SessionLocationMiddleware, }) diff --git a/packages/protocol/src/groups/agent.ts b/packages/protocol/src/groups/agent.ts index 0d499e187f..1a9e958552 100644 --- a/packages/protocol/src/groups/agent.ts +++ b/packages/protocol/src/groups/agent.ts @@ -2,7 +2,7 @@ import { Agent } from "@opencode-ai/schema/agent" import { Location } from "@opencode-ai/schema/location" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const AgentGroup = HttpApiGroup.make("server.agent").add( HttpApiEndpoint.get("agent.list", "/api/agent", { diff --git a/packages/protocol/src/groups/command.ts b/packages/protocol/src/groups/command.ts index eac33cc292..6d463ae371 100644 --- a/packages/protocol/src/groups/command.ts +++ b/packages/protocol/src/groups/command.ts @@ -2,7 +2,7 @@ import { Command } from "@opencode-ai/schema/command" import { Location } from "@opencode-ai/schema/location" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const CommandGroup = HttpApiGroup.make("server.command") .add( diff --git a/packages/protocol/src/groups/credential.ts b/packages/protocol/src/groups/credential.ts index 4f6ce8461b..7ef7e2e7de 100644 --- a/packages/protocol/src/groups/credential.ts +++ b/packages/protocol/src/groups/credential.ts @@ -1,7 +1,7 @@ import { Credential } from "@opencode-ai/schema/credential" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const CredentialGroup = HttpApiGroup.make("server.credential") .add( diff --git a/packages/protocol/src/groups/fs.ts b/packages/protocol/src/groups/fs.ts index f5fc00e021..79dd045d32 100644 --- a/packages/protocol/src/groups/fs.ts +++ b/packages/protocol/src/groups/fs.ts @@ -3,7 +3,7 @@ import { Location } from "@opencode-ai/schema/location" import { PositiveInt, RelativePath } from "@opencode-ai/schema/schema" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { LocationQuery, locationQueryOpenApi } from "./location.js" const ListQuery = Schema.Struct({ ...LocationQuery.fields, diff --git a/packages/protocol/src/groups/generate.ts b/packages/protocol/src/groups/generate.ts index 7ea9e4ba25..fcf7e6f265 100644 --- a/packages/protocol/src/groups/generate.ts +++ b/packages/protocol/src/groups/generate.ts @@ -1,8 +1,8 @@ import { Model } from "@opencode-ai/schema/model" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" -import { InvalidRequestError, ServiceUnavailableError } from "../errors" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { InvalidRequestError, ServiceUnavailableError } from "../errors.js" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const GenerateGroup = HttpApiGroup.make("server.generate") .add( diff --git a/packages/protocol/src/groups/integration.ts b/packages/protocol/src/groups/integration.ts index 304681d330..6c1b08f316 100644 --- a/packages/protocol/src/groups/integration.ts +++ b/packages/protocol/src/groups/integration.ts @@ -2,8 +2,8 @@ import { Integration } from "@opencode-ai/schema/integration" import { Location } from "@opencode-ai/schema/location" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi" -import { InvalidRequestError } from "../errors" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { InvalidRequestError } from "../errors.js" +import { LocationQuery, locationQueryOpenApi } from "./location.js" const Inputs = Schema.Record(Schema.String, Schema.String) diff --git a/packages/protocol/src/groups/mcp.ts b/packages/protocol/src/groups/mcp.ts index 450a2a67c4..d29749ab15 100644 --- a/packages/protocol/src/groups/mcp.ts +++ b/packages/protocol/src/groups/mcp.ts @@ -2,7 +2,7 @@ import { Mcp } from "@opencode-ai/schema/mcp" import { Location } from "@opencode-ai/schema/location" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const McpGroup = HttpApiGroup.make("server.mcp") .add( diff --git a/packages/protocol/src/groups/message.ts b/packages/protocol/src/groups/message.ts index 7ace0ada99..3185381071 100644 --- a/packages/protocol/src/groups/message.ts +++ b/packages/protocol/src/groups/message.ts @@ -2,7 +2,7 @@ import { Session } from "@opencode-ai/schema/session" import { SessionMessage } from "@opencode-ai/schema/session-message" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" -import { InvalidCursorError, SessionNotFoundError, UnknownError } from "../errors" +import { InvalidCursorError, SessionNotFoundError, UnknownError } from "../errors.js" export const SessionMessagesQuery = Schema.Struct({ limit: Schema.optional( diff --git a/packages/protocol/src/groups/model.ts b/packages/protocol/src/groups/model.ts index 9125f95289..c8333eafb5 100644 --- a/packages/protocol/src/groups/model.ts +++ b/packages/protocol/src/groups/model.ts @@ -2,8 +2,8 @@ import { Model } from "@opencode-ai/schema/model" import { Location } from "@opencode-ai/schema/location" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" -import { ServiceUnavailableError } from "../errors" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { ServiceUnavailableError } from "../errors.js" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const ModelGroup = HttpApiGroup.make("server.model") .add( diff --git a/packages/protocol/src/groups/permission.ts b/packages/protocol/src/groups/permission.ts index 4370e18a71..cfd26c2c50 100644 --- a/packages/protocol/src/groups/permission.ts +++ b/packages/protocol/src/groups/permission.ts @@ -6,8 +6,8 @@ import { Project } from "@opencode-ai/schema/project" import { Session } from "@opencode-ai/schema/session" import { Context, Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenApi } from "effect/unstable/httpapi" -import { PermissionNotFoundError, SessionNotFoundError } from "../errors" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { PermissionNotFoundError, SessionNotFoundError } from "../errors.js" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const makePermissionGroup = < LocationId extends HttpApiMiddleware.AnyId, diff --git a/packages/protocol/src/groups/plugin.ts b/packages/protocol/src/groups/plugin.ts index 9522354f84..ee6d1ad7af 100644 --- a/packages/protocol/src/groups/plugin.ts +++ b/packages/protocol/src/groups/plugin.ts @@ -2,7 +2,7 @@ import { Location } from "@opencode-ai/schema/location" import { Plugin } from "@opencode-ai/schema/plugin" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const PluginGroup = HttpApiGroup.make("server.plugin") .add( diff --git a/packages/protocol/src/groups/project-copy.ts b/packages/protocol/src/groups/project-copy.ts index c4f0240fe3..995b8a47d3 100644 --- a/packages/protocol/src/groups/project-copy.ts +++ b/packages/protocol/src/groups/project-copy.ts @@ -2,7 +2,7 @@ import { ProjectCopy } from "@opencode-ai/schema/project-copy" import { Project } from "@opencode-ai/schema/project" import { Schema, Struct } from "effect" import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { LocationQuery, locationQueryOpenApi } from "./location.js" const root = "/experimental/project/:projectID/copy" diff --git a/packages/protocol/src/groups/project.ts b/packages/protocol/src/groups/project.ts index 7fbf7ac94d..53862fede4 100644 --- a/packages/protocol/src/groups/project.ts +++ b/packages/protocol/src/groups/project.ts @@ -1,6 +1,6 @@ import { Project } from "@opencode-ai/schema/project" import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { LocationQuery, locationQueryOpenApi } from "./location.js" const root = "/api/project" diff --git a/packages/protocol/src/groups/provider.ts b/packages/protocol/src/groups/provider.ts index 9089b1a09c..179d87092a 100644 --- a/packages/protocol/src/groups/provider.ts +++ b/packages/protocol/src/groups/provider.ts @@ -2,8 +2,8 @@ import { Provider } from "@opencode-ai/schema/provider" import { Location } from "@opencode-ai/schema/location" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" -import { ProviderNotFoundError, ServiceUnavailableError } from "../errors" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { ProviderNotFoundError, ServiceUnavailableError } from "../errors.js" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const ProviderGroup = HttpApiGroup.make("server.provider") .add( diff --git a/packages/protocol/src/groups/pty.ts b/packages/protocol/src/groups/pty.ts index a6ec1b66b6..4ac3c5519f 100644 --- a/packages/protocol/src/groups/pty.ts +++ b/packages/protocol/src/groups/pty.ts @@ -3,8 +3,8 @@ import { PtyTicket } from "@opencode-ai/schema/pty-ticket" import { Location } from "@opencode-ai/schema/location" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi" -import { ForbiddenError, PtyNotFoundError } from "../errors" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { ForbiddenError, PtyNotFoundError } from "../errors.js" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const PTY_CONNECT_TICKET_QUERY = "ticket" export const PTY_CONNECT_TOKEN_HEADER = "x-opencode-ticket" diff --git a/packages/protocol/src/groups/question.ts b/packages/protocol/src/groups/question.ts index e6d862334d..288d8724f3 100644 --- a/packages/protocol/src/groups/question.ts +++ b/packages/protocol/src/groups/question.ts @@ -3,8 +3,8 @@ import { Location } from "@opencode-ai/schema/location" import { Session } from "@opencode-ai/schema/session" import { Context, Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, HttpApiMiddleware, HttpApiSchema, OpenApi } from "effect/unstable/httpapi" -import { QuestionNotFoundError, SessionNotFoundError } from "../errors" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { QuestionNotFoundError, SessionNotFoundError } from "../errors.js" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const makeQuestionGroup = < LocationId extends HttpApiMiddleware.AnyId, diff --git a/packages/protocol/src/groups/reference.ts b/packages/protocol/src/groups/reference.ts index d953cd530a..0302f434b9 100644 --- a/packages/protocol/src/groups/reference.ts +++ b/packages/protocol/src/groups/reference.ts @@ -2,7 +2,7 @@ import { Location } from "@opencode-ai/schema/location" import { Reference } from "@opencode-ai/schema/reference" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const ReferenceGroup = HttpApiGroup.make("server.reference") .add( diff --git a/packages/protocol/src/groups/session.ts b/packages/protocol/src/groups/session.ts index fb812973de..7228596141 100644 --- a/packages/protocol/src/groups/session.ts +++ b/packages/protocol/src/groups/session.ts @@ -17,7 +17,7 @@ import { SessionNotFoundError, SkillNotFoundError, UnknownError, -} from "../errors" +} from "../errors.js" import { Agent } from "@opencode-ai/schema/agent" import { Model } from "@opencode-ai/schema/model" import { Location } from "@opencode-ai/schema/location" diff --git a/packages/protocol/src/groups/shell.ts b/packages/protocol/src/groups/shell.ts index 0ed1b91144..31fe35541e 100644 --- a/packages/protocol/src/groups/shell.ts +++ b/packages/protocol/src/groups/shell.ts @@ -2,8 +2,8 @@ import { Shell } from "@opencode-ai/schema/shell" import { Location } from "@opencode-ai/schema/location" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi" -import { ShellNotFoundError } from "../errors" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { ShellNotFoundError } from "../errors.js" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const ShellGroup = HttpApiGroup.make("server.shell") .add( diff --git a/packages/protocol/src/groups/skill.ts b/packages/protocol/src/groups/skill.ts index ab998a538e..805d0e441a 100644 --- a/packages/protocol/src/groups/skill.ts +++ b/packages/protocol/src/groups/skill.ts @@ -2,7 +2,7 @@ import { Skill } from "@opencode-ai/schema/skill" import { Location } from "@opencode-ai/schema/location" import { Schema } from "effect" import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi" -import { LocationQuery, locationQueryOpenApi } from "./location" +import { LocationQuery, locationQueryOpenApi } from "./location.js" export const SkillGroup = HttpApiGroup.make("server.skill") .add( diff --git a/packages/protocol/src/middleware/authorization.ts b/packages/protocol/src/middleware/authorization.ts index ed1c3caf66..54d33bc26e 100644 --- a/packages/protocol/src/middleware/authorization.ts +++ b/packages/protocol/src/middleware/authorization.ts @@ -1,5 +1,5 @@ import { HttpApiMiddleware } from "effect/unstable/httpapi" -import { UnauthorizedError } from "../errors" +import { UnauthorizedError } from "../errors.js" export class Authorization extends HttpApiMiddleware.Service()("@opencode/HttpApiAuthorization", { error: UnauthorizedError, diff --git a/packages/protocol/src/middleware/schema-error.ts b/packages/protocol/src/middleware/schema-error.ts index 635ecec197..a4c36d5b8c 100644 --- a/packages/protocol/src/middleware/schema-error.ts +++ b/packages/protocol/src/middleware/schema-error.ts @@ -1,5 +1,5 @@ import { HttpApiMiddleware } from "effect/unstable/httpapi" -import { InvalidRequestError } from "../errors" +import { InvalidRequestError } from "../errors.js" export class SchemaErrorMiddleware extends HttpApiMiddleware.Service()( "@opencode/HttpApiSchemaError", diff --git a/packages/protocol/test/session-cursor.test.ts b/packages/protocol/test/session-cursor.test.ts index 2680c962e1..2d44a11f5c 100644 --- a/packages/protocol/test/session-cursor.test.ts +++ b/packages/protocol/test/session-cursor.test.ts @@ -1,6 +1,6 @@ import { describe, expect, test } from "bun:test" import { Effect, Schema } from "effect" -import { SessionHistoryQuery, SessionsCursor } from "../src/groups/session" +import { SessionHistoryQuery, SessionsCursor } from "../src/groups/session.js" import { Session } from "@opencode-ai/schema/session" describe("SessionsCursor", () => { diff --git a/packages/protocol/tsconfig.build.json b/packages/protocol/tsconfig.build.json new file mode 100644 index 0000000000..e235ae78cf --- /dev/null +++ b/packages/protocol/tsconfig.build.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "./tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "dist", + "noEmit": false, + "declaration": true + }, + "include": ["src"] +} diff --git a/packages/protocol/tsconfig.json b/packages/protocol/tsconfig.json index 00ef125468..189db6f3e9 100644 --- a/packages/protocol/tsconfig.json +++ b/packages/protocol/tsconfig.json @@ -3,6 +3,10 @@ "extends": "@tsconfig/bun/tsconfig.json", "compilerOptions": { "lib": ["ESNext", "DOM", "DOM.Iterable"], + "module": "NodeNext", + "moduleResolution": "NodeNext", + "allowImportingTsExtensions": false, + "allowJs": false, "noUncheckedIndexedAccess": false } } diff --git a/script/publish.ts b/script/publish.ts index b1845a6023..5ee296a6cf 100755 --- a/script/publish.ts +++ b/script/publish.ts @@ -38,6 +38,9 @@ await prepareReleaseFiles() console.log("\n=== schema ===\n") await $`bun ./packages/schema/script/publish.ts` +console.log("\n=== protocol ===\n") +await $`bun ./packages/protocol/script/publish.ts` + console.log("\n=== cli ===\n") await $`bun ./packages/cli/script/publish.ts`