Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add support for coder inbox#444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
DanielleMaywood merged 15 commits intomainfromdm-coder-inbox-oom-ood
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
15 commits
Select commitHold shift + click to select a range
f73eaee
feat: begin impl of coder inbox
DanielleMaywoodMar 3, 2025
2de7f12
chore: take inspiration from existing websocket
DanielleMaywoodMar 3, 2025
88b31a2
chore: apply feedback
DanielleMaywoodMar 4, 2025
1809fb8
chore: update websocket url
DanielleMaywoodMar 17, 2025
eae596e
chore: replace showWarningMessage with showInformationMessage
DanielleMaywoodMar 17, 2025
5f4d8e8
Merge branch 'main' into dm-coder-inbox-oom-ood
DanielleMaywoodMar 17, 2025
be3f0a4
chore: upgrade dependencies
DanielleMaywoodMar 19, 2025
455ba73
Merge branch 'main' into dm-coder-inbox-oom-ood
DanielleMaywoodMar 19, 2025
f4f99b2
chore: only upgrade coder dependency
DanielleMaywoodMar 19, 2025
57acbff
chore: socketUrlRaw -> socketUrl
DanielleMaywoodMar 20, 2025
48d1c6b
chore: private -> #
DanielleMaywoodMar 20, 2025
7f7d9c0
chore: cleanup on websocket error
DanielleMaywoodMar 20, 2025
cf5ebea
chore: add comment
DanielleMaywoodMar 20, 2025
474b906
chore: appease the linter
DanielleMaywoodMar 20, 2025
d695588
chore: request plaintext format from api
DanielleMaywoodMar 21, 2025
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
2 changes: 1 addition & 1 deletionsrc/api.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,7 @@ export function needToken(): boolean {
/**
* Create a new agent based off the current settings.
*/
async function createHttpAgent(): Promise<ProxyAgent> {
exportasync function createHttpAgent(): Promise<ProxyAgent> {
const cfg = vscode.workspace.getConfiguration()
const insecure = Boolean(cfg.get("coder.insecure"))
const certFile = expandPath(String(cfg.get("coder.tlsCertFile") ?? "").trim())
Expand Down
83 changes: 83 additions & 0 deletionssrc/inbox.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
import { Api } from "coder/site/src/api/api"
import { Workspace, GetInboxNotificationResponse } from "coder/site/src/api/typesGenerated"
import { ProxyAgent } from "proxy-agent"
import * as vscode from "vscode"
import { WebSocket } from "ws"
import { errToStr } from "./api-helper"
import { type Storage } from "./storage"

// These are the template IDs of our notifications.
// Maybe in the future we should avoid hardcoding
// these in both coderd and here.
const TEMPLATE_WORKSPACE_OUT_OF_MEMORY = "a9d027b4-ac49-4fb1-9f6d-45af15f64e7a"
const TEMPLATE_WORKSPACE_OUT_OF_DISK = "f047f6a3-5713-40f7-85aa-0394cce9fa3a"

export class Inbox implements vscode.Disposable {
readonly #storage: Storage
#disposed = false
#socket: WebSocket

constructor(workspace: Workspace, httpAgent: ProxyAgent, restClient: Api, storage: Storage) {
this.#storage = storage

const baseUrlRaw = restClient.getAxiosInstance().defaults.baseURL
if (!baseUrlRaw) {
throw new Error("No base URL set on REST client")
}

const watchTemplates = [TEMPLATE_WORKSPACE_OUT_OF_DISK, TEMPLATE_WORKSPACE_OUT_OF_MEMORY]
const watchTemplatesParam = encodeURIComponent(watchTemplates.join(","))

const watchTargets = [workspace.id]
const watchTargetsParam = encodeURIComponent(watchTargets.join(","))

// We shouldn't need to worry about this throwing. Whilst `baseURL` could
// be an invalid URL, that would've caused issues before we got to here.
const baseUrl = new URL(baseUrlRaw)
const socketProto = baseUrl.protocol === "https:" ? "wss:" : "ws:"
const socketUrl = `${socketProto}//${baseUrl.host}/api/v2/notifications/inbox/watch?format=plaintext&templates=${watchTemplatesParam}&targets=${watchTargetsParam}`

const coderSessionTokenHeader = "Coder-Session-Token"
this.#socket = new WebSocket(new URL(socketUrl), {
followRedirects: true,
agent: httpAgent,
headers: {
[coderSessionTokenHeader]: restClient.getAxiosInstance().defaults.headers.common[coderSessionTokenHeader] as
| string
| undefined,
},
})

this.#socket.on("open", () => {
this.#storage.writeToCoderOutputChannel("Listening to Coder Inbox")
})

this.#socket.on("error", (error) => {
this.notifyError(error)
this.dispose()
})

this.#socket.on("message", (data) => {
try {
const inboxMessage = JSON.parse(data.toString()) as GetInboxNotificationResponse

vscode.window.showInformationMessage(inboxMessage.notification.title)
} catch (error) {
this.notifyError(error)
}
})
}

dispose() {
if (!this.#disposed) {
this.#storage.writeToCoderOutputChannel("No longer listening to Coder Inbox")
this.#socket.close()
this.#disposed = true
}
}

private notifyError(error: unknown) {
const message = errToStr(error, "Got empty error while monitoring Coder Inbox")
this.#storage.writeToCoderOutputChannel(message)
}
}
8 changes: 7 additions & 1 deletionsrc/remote.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,12 +9,13 @@ import * as path from "path"
import prettyBytes from "pretty-bytes"
import * as semver from "semver"
import * as vscode from "vscode"
import { makeCoderSdk, needToken, startWorkspaceIfStoppedOrFailed, waitForBuild } from "./api"
import {createHttpAgent,makeCoderSdk, needToken, startWorkspaceIfStoppedOrFailed, waitForBuild } from "./api"
import { extractAgents } from "./api-helper"
import * as cli from "./cliManager"
import { Commands } from "./commands"
import { featureSetForVersion, FeatureSet } from "./featureSet"
import { getHeaderCommand } from "./headers"
import { Inbox } from "./inbox"
import { SSHConfig, SSHValues, mergeSSHConfigValues } from "./sshConfig"
import { computeSSHProperties, sshSupportsSetEnv } from "./sshSupport"
import { Storage } from "./storage"
Expand DownExpand Up@@ -403,6 +404,11 @@ export class Remote {
disposables.push(monitor)
disposables.push(monitor.onChange.event((w) => (this.commands.workspace = w)))

// Watch coder inbox for messages
const httpAgent = await createHttpAgent()
const inbox = new Inbox(workspace, httpAgent, workspaceRestClient, this.storage)
disposables.push(inbox)

// Wait for the agent to connect.
if (agent.status === "connecting") {
this.storage.writeToCoderOutputChannel(`Waiting for ${workspaceName}/${agent.name}...`)
Expand Down
2 changes: 1 addition & 1 deletionyarn.lock
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1594,7 +1594,7 @@ co@3.1.0:

"coder@https://github.com/coder/coder#main":
version "0.0.0"
resolved "https://github.com/coder/coder#975ea23d6f49a4043131f79036d1bf5166eb9140"
resolved "https://github.com/coder/coder#3ac844ad3d341d2910542b83d4f33df7bd0be85e"

collapse-white-space@^1.0.2:
version "1.0.6"
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp