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 from1 commit
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
NextNext commit
feat: begin impl of coder inbox
Connect to Coder Inbox on /api/v2/notifications/watch to listen fornotifications. Currently limit this to only show notifications forOOM/OOD notifications.
  • Loading branch information
@DanielleMaywood
DanielleMaywood committedMar 3, 2025
commitf73eaeeadbdc47ebb5cdeb8bcf2f8e55218bf8f0
89 changes: 89 additions & 0 deletionssrc/inbox.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
import { Api } from "coder/site/src/api/api"
import * as vscode from "vscode"
import { WebSocket } from "ws"
import { errToStr } from "./api-helper"
import { Storage } from "./storage"

type InboxMessage = {
unread_count: number
notification: {
id: string
user_id: string
template_id: string
targets: string[]
title: string
content: string
actions: {
[key: string]: string
}
read_at: string
created_at: string
}
}

const TemplateWorkspaceOutOfMemory = "a9d027b4-ac49-4fb1-9f6d-45af15f64e7a"
const TemplateWorkspaceOutOfDisk = "f047f6a3-5713-40f7-85aa-0394cce9fa3a"

export class Inbox implements vscode.Disposable {
private disposed = false
private socket: WebSocket

constructor(
private readonly restClient: Api,
private readonly storage: Storage,
) {
// const url = this.restClient.getAxiosInstance().defaults.baseURL
const token = this.restClient.getAxiosInstance().defaults.headers.common["Coder-Session-Token"] as
| string
| undefined
// const inboxUrl = new URL(`${url}/api/v2/notifications/watch`);
const inboxUrl = new URL(`ws://localhost:8080`)

this.storage.writeToCoderOutputChannel("Listening to Coder Inbox")

// We're gonna connect over WebSocket so replace the scheme.
if (inboxUrl.protocol === "https") {
inboxUrl.protocol = "wss"
} else if (inboxUrl.protocol === "http") {
inboxUrl.protocol = "ws"
}

this.socket = new WebSocket(inboxUrl, {
headers: {
"Coder-Session-Token": token,
},
})

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

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

if (
inboxMessage.notification.template_id === TemplateWorkspaceOutOfDisk ||
inboxMessage.notification.template_id === TemplateWorkspaceOutOfMemory
) {
vscode.window.showWarningMessage(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)
}
}
5 changes: 5 additions & 0 deletionssrc/remote.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,7 @@ 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,10 @@ export class Remote {
disposables.push(monitor)
disposables.push(monitor.onChange.event((w) => (this.commands.workspace = w)))

// Watch coder inbox for messages
const inbox = new Inbox(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

[8]ページ先頭

©2009-2025 Movatter.jp