@opencode/protocol 0.0.0-dev-20114 → 0.0.0-dev-20115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import { Schema } from "effect";
2
2
  import { HttpApiEndpoint, HttpApiGroup } from "effect/unstable/httpapi";
3
+ import { UnauthorizedError } from "../errors.js";
3
4
  export declare const ServerInfo: Schema.Struct<{
4
5
  readonly version: Schema.String;
5
6
  readonly pid: Schema.Int;
@@ -9,6 +10,16 @@ export declare const ServerInfo: Schema.Struct<{
9
10
  }>;
10
11
  }>;
11
12
  export type ServerInfo = typeof ServerInfo.Type;
13
+ export declare const PairingCode: Schema.Struct<{
14
+ readonly code: Schema.String;
15
+ readonly expires_in: Schema.Int;
16
+ }>;
17
+ export type PairingCode = typeof PairingCode.Type;
18
+ export declare const PairingSession: Schema.Struct<{
19
+ readonly token: Schema.String;
20
+ }>;
21
+ export type PairingSession = typeof PairingSession.Type;
22
+ export declare function isPairingConnectURL(url: URL): boolean;
12
23
  export declare const ServerGroup: HttpApiGroup.HttpApiGroup<"server.server", HttpApiEndpoint.HttpApiEndpoint<"server.info", "GET", "/api/info", never, never, never, never, Schema.toCodecJson<Schema.Struct<{
13
24
  readonly version: Schema.String;
14
25
  readonly pid: Schema.Int;
@@ -16,4 +27,11 @@ export declare const ServerGroup: HttpApiGroup.HttpApiGroup<"server.server", Htt
16
27
  readonly paths: Schema.Struct<{
17
28
  readonly tmp: Schema.String;
18
29
  }>;
19
- }>>, never, never, never>, false>;
30
+ }>>, never, never, never> | HttpApiEndpoint.HttpApiEndpoint<"server.pair", "POST", "/api/pair", never, never, never, never, Schema.toCodecJson<Schema.Struct<{
31
+ readonly code: Schema.String;
32
+ readonly expires_in: Schema.Int;
33
+ }>>, never, never, never> | HttpApiEndpoint.HttpApiEndpoint<"server.connect", "GET", "/auth/connect/:code", Schema.toCodecStringTree<Schema.Struct<{
34
+ code: Schema.String;
35
+ }>>, never, never, never, Schema.toCodecJson<Schema.Struct<{
36
+ readonly token: Schema.String;
37
+ }>>, Schema.toCodecJson<typeof UnauthorizedError>, never, never>, false>;
@@ -1,5 +1,6 @@
1
1
  import { Schema } from "effect";
2
2
  import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi";
3
+ import { UnauthorizedError } from "../errors.js";
3
4
  export const ServerInfo = Schema.Struct({
4
5
  version: Schema.String,
5
6
  // 0 means the runtime has no OS process identity (e.g. workerd).
@@ -9,6 +10,18 @@ export const ServerInfo = Schema.Struct({
9
10
  tmp: Schema.String,
10
11
  }),
11
12
  }).annotate({ identifier: "ServerInfo" });
13
+ export const PairingCode = Schema.Struct({
14
+ code: Schema.String,
15
+ expires_in: Schema.Int,
16
+ }).annotate({ identifier: "PairingCode" });
17
+ export const PairingSession = Schema.Struct({
18
+ token: Schema.String,
19
+ }).annotate({ identifier: "PairingSession" });
20
+ const PAIRING_CONNECT_PATH = /^\/auth\/connect\/[^/]+$/;
21
+ // Authorization middleware skips credential checks for pairing links; the connect handler consumes the code instead.
22
+ export function isPairingConnectURL(url) {
23
+ return PAIRING_CONNECT_PATH.test(url.pathname);
24
+ }
12
25
  export const ServerGroup = HttpApiGroup.make("server.server")
13
26
  .add(HttpApiEndpoint.get("server.info", "/api/info", {
14
27
  success: ServerInfo,
@@ -16,5 +29,21 @@ export const ServerGroup = HttpApiGroup.make("server.server")
16
29
  identifier: "server.info",
17
30
  summary: "Get server info",
18
31
  description: "Return the server identity, connection URLs, paths, and readiness status.",
32
+ })))
33
+ .add(HttpApiEndpoint.post("server.pair", "/api/pair", {
34
+ success: PairingCode,
35
+ }).annotateMerge(OpenApi.annotations({
36
+ identifier: "server.pair",
37
+ summary: "Create pairing code",
38
+ description: "Create a short-lived, single-use code for a /auth/connect/:code pairing link.",
39
+ })))
40
+ .add(HttpApiEndpoint.get("server.connect", "/auth/connect/:code", {
41
+ params: { code: Schema.String },
42
+ success: PairingSession,
43
+ error: UnauthorizedError,
44
+ }).annotateMerge(OpenApi.annotations({
45
+ identifier: "server.connect",
46
+ summary: "Redeem pairing code",
47
+ description: "Redeem a pairing code. Browsers receive a session cookie and a redirect to the web app; requests that accept JSON receive a session token to use as the password.",
19
48
  })))
20
49
  .annotateMerge(OpenApi.annotations({ title: "server" }));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/protocol",
4
- "version": "0.0.0-dev-20114",
4
+ "version": "0.0.0-dev-20115",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -32,7 +32,7 @@
32
32
  "typecheck": "tsgo --noEmit"
33
33
  },
34
34
  "dependencies": {
35
- "@opencode/schema": "0.0.0-dev-20114",
35
+ "@opencode/schema": "0.0.0-dev-20115",
36
36
  "effect": "4.0.0-rc.112"
37
37
  },
38
38
  "devDependencies": {