Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/client/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const endpointNames = {
"desk.revoke": "deskRevoke",
"desk.machine.get": "deskMachine",
"desk.machine.update": "deskMachineUpdate",
"desk.browser": "deskBrowser",
} as const

export const omitEndpoints = new Set(["fs.read", "pty.connect", "pty.connectToken"])
13 changes: 13 additions & 0 deletions packages/client/src/generated-effect/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ const Endpoint2_12 = (raw: RawClient["server.channels"]) => (input?: Endpoint2_1
payload: { name: input?.["name"], kind: input?.["kind"], access: input?.["access"] },
}).pipe(Effect.mapError(mapClientError))

type Endpoint2_13Request = Parameters<RawClient["server.channels"]["desk.browser"]>[0]
type Endpoint2_13Input = {
readonly method: Endpoint2_13Request["payload"]["method"]
readonly path: Endpoint2_13Request["payload"]["path"]
readonly body?: Endpoint2_13Request["payload"]["body"]
readonly pairMs?: Endpoint2_13Request["payload"]["pairMs"]
}
const Endpoint2_13 = (raw: RawClient["server.channels"]) => (input: Endpoint2_13Input) =>
raw["desk.browser"]({
payload: { method: input["method"], path: input["path"], body: input["body"], pairMs: input["pairMs"] },
}).pipe(Effect.mapError(mapClientError))

const adaptGroup2 = (raw: RawClient["server.channels"]) => ({
status: Endpoint2_0(raw),
reload: Endpoint2_1(raw),
Expand All @@ -123,6 +135,7 @@ const adaptGroup2 = (raw: RawClient["server.channels"]) => ({
deskRevoke: Endpoint2_10(raw),
deskMachine: Endpoint2_11(raw),
deskMachineUpdate: Endpoint2_12(raw),
deskBrowser: Endpoint2_13(raw),
})

const Endpoint3_0 = (raw: RawClient["server.apps"]) => () => raw["apps.list"]({}).pipe(Effect.mapError(mapClientError))
Expand Down
14 changes: 14 additions & 0 deletions packages/client/src/generated/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import type {
ServerChannelsDeskMachineOutput,
ServerChannelsDeskMachineUpdateInput,
ServerChannelsDeskMachineUpdateOutput,
ServerChannelsDeskBrowserInput,
ServerChannelsDeskBrowserOutput,
ServerAppsListOutput,
ServerAppsRegisterInput,
ServerAppsRegisterOutput,
Expand Down Expand Up @@ -465,6 +467,18 @@ export function make(options: ClientOptions) {
},
requestOptions,
),
deskBrowser: (input: ServerChannelsDeskBrowserInput, requestOptions?: RequestOptions) =>
request<ServerChannelsDeskBrowserOutput>(
{
method: "POST",
path: `/desk/browser`,
body: { method: input["method"], path: input["path"], body: input["body"], pairMs: input["pairMs"] },
successStatus: 200,
declaredStatuses: [503, 401, 400],
empty: false,
},
requestOptions,
),
},
"server.apps": {
list: (requestOptions?: RequestOptions) =>
Expand Down
79 changes: 79 additions & 0 deletions packages/client/src/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ export type ServerChannelsDeskStatusOutput = {
readonly addedAt: number
readonly online: boolean
}>
readonly browser?:
| {
readonly state: "off" | "none" | "found" | "pairing" | "ready" | "denied"
readonly name?: string | undefined
readonly code?: string | undefined
readonly reason?: string | undefined
}
| undefined
}

export type ServerChannelsDeskEnableInput = { readonly enabled: { readonly enabled: boolean }["enabled"] }
Expand All @@ -229,6 +237,14 @@ export type ServerChannelsDeskEnableOutput = {
readonly addedAt: number
readonly online: boolean
}>
readonly browser?:
| {
readonly state: "off" | "none" | "found" | "pairing" | "ready" | "denied"
readonly name?: string | undefined
readonly code?: string | undefined
readonly reason?: string | undefined
}
| undefined
}

export type ServerChannelsDeskLoginOutput = {
Expand Down Expand Up @@ -259,6 +275,14 @@ export type ServerChannelsDeskLogoutOutput = {
readonly addedAt: number
readonly online: boolean
}>
readonly browser?:
| {
readonly state: "off" | "none" | "found" | "pairing" | "ready" | "denied"
readonly name?: string | undefined
readonly code?: string | undefined
readonly reason?: string | undefined
}
| undefined
}

export type ServerChannelsDeskTokenSetInput = {
Expand Down Expand Up @@ -301,6 +325,14 @@ export type ServerChannelsDeskTokenSetOutput = {
readonly addedAt: number
readonly online: boolean
}>
readonly browser?:
| {
readonly state: "off" | "none" | "found" | "pairing" | "ready" | "denied"
readonly name?: string | undefined
readonly code?: string | undefined
readonly reason?: string | undefined
}
| undefined
}

export type ServerChannelsDeskTokenClearOutput = {
Expand All @@ -325,6 +357,14 @@ export type ServerChannelsDeskTokenClearOutput = {
readonly addedAt: number
readonly online: boolean
}>
readonly browser?:
| {
readonly state: "off" | "none" | "found" | "pairing" | "ready" | "denied"
readonly name?: string | undefined
readonly code?: string | undefined
readonly reason?: string | undefined
}
| undefined
}

export type ServerChannelsDeskApproveInput = { readonly code: { readonly code: string }["code"] }
Expand Down Expand Up @@ -385,6 +425,45 @@ export type ServerChannelsDeskMachineUpdateOutput = {
readonly access: "read_only" | "ask" | "trusted"
}

export type ServerChannelsDeskBrowserInput = {
readonly method: {
readonly method: "GET" | "POST"
readonly path: string
readonly body?: unknown | undefined
readonly pairMs?: number | undefined
}["method"]
readonly path: {
readonly method: "GET" | "POST"
readonly path: string
readonly body?: unknown | undefined
readonly pairMs?: number | undefined
}["path"]
readonly body?: {
readonly method: "GET" | "POST"
readonly path: string
readonly body?: unknown | undefined
readonly pairMs?: number | undefined
}["body"]
readonly pairMs?: {
readonly method: "GET" | "POST"
readonly path: string
readonly body?: unknown | undefined
readonly pairMs?: number | undefined
}["pairMs"]
}

export type ServerChannelsDeskBrowserOutput = {
readonly status: number
readonly body?: unknown | undefined
readonly browser: {
readonly state: "off" | "none" | "found" | "pairing" | "ready" | "denied"
readonly name?: string | undefined
readonly code?: string | undefined
readonly reason?: string | undefined
}
readonly error?: string | undefined
}

export type ServerAppsListOutput = {
readonly apps: ReadonlyArray<{
readonly id: string
Expand Down
45 changes: 45 additions & 0 deletions packages/protocol/src/groups/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ export const DeskLogin = Schema.Struct({
expiresAt: Schema.Number,
}).annotate({ identifier: "DeskLogin" })

/**
* Where this engine stands with the person's browser extension (redrob-extension, docs/remote-control.md):
* `off` no relay connection, `none` no browser with the extension in this account, `found` one is
* online, `pairing` waiting for Allow in that browser (`code`), `ready`, `denied` (`reason`).
*/
export const DeskBrowserState = Schema.Struct({
state: Schema.Literals(["off", "none", "found", "pairing", "ready", "denied"]),
name: Schema.optional(Schema.String),
code: Schema.optional(Schema.String),
reason: Schema.optional(Schema.String),
}).annotate({ identifier: "DeskBrowserState" })

export const DeskStatus = Schema.Struct({
/** The switch (`channels.json` entry `desk`); on unless turned off. */
enabled: Schema.Boolean,
Expand All @@ -66,8 +78,27 @@ export const DeskStatus = Schema.Struct({
online: Schema.Boolean,
}),
),
/** The person's Chrome with the Redrob extension, as the `browser` tool reaches it over the relay. */
browser: Schema.optional(DeskBrowserState),
}).annotate({ identifier: "DeskStatus" })

/** One request of the extension's route set (its `src/remote/forward.ts`); anything else it answers 403. */
export const DeskBrowserRequest = Schema.Struct({
method: Schema.Literals(["GET", "POST"]),
path: Schema.String,
body: Schema.optional(Schema.Unknown),
/** How long to wait for Allow in the browser the first time, in ms (default two minutes). */
pairMs: Schema.optional(Schema.Number),
}).annotate({ identifier: "DeskBrowserRequest" })

export const DeskBrowserResponse = Schema.Struct({
/** The extension's status; 0 when the request did not reach it (`error` says why). */
status: Schema.Number,
body: Schema.optional(Schema.Unknown),
browser: DeskBrowserState,
error: Schema.optional(Schema.String),
}).annotate({ identifier: "DeskBrowserResponse" })

/** Redrob Desktop's own redrob-auth access token (client `redrob-desktop`), for `PUT /desk/token`. */
export const DeskToken = Schema.Struct({
accessToken: Schema.String,
Expand Down Expand Up @@ -267,3 +298,17 @@ export const ChannelsGroup = HttpApiGroup.make("server.channels")
}),
),
)
.add(
HttpApiEndpoint.post("desk.browser", "/desk/browser", {
payload: DeskBrowserRequest,
success: DeskBrowserResponse,
error: ServiceUnavailableError,
}).annotateMerge(
OpenApi.annotations({
identifier: "v2.desk.browser",
summary: "Ask the person's browser extension",
description:
"Sends one request of the Redrob extension's route set to the person's Chrome over the desk relay, as a paired device (the first time the person allows this engine in Chrome). Used by the browser tool of every engine on this machine. status 0 when it did not reach the extension. 503 on a server that is not the registered daemon.",
}),
),
)
Loading
Loading