Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit 97c052f

Browse files
committed
feat(chat): refactor and bump dstack
1 parent 3d9e3f8 commit 97c052f

File tree

6 files changed

+23
-16
lines changed

6 files changed

+23
-16
lines changed

.eslintrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"rules": {
99
"node/no-missing-import": "off",
1010
"unicorn/no-process-exit": "off",
11-
"no-process-exit": "off"
11+
"no-process-exit": "off",
12+
"space-before-function-paren": "off"
1213
}
13-
}
14+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"bugs": "https://github.com/dstack-js/chat/issues",
1111
"dependencies": {
1212
"@dstack-js/ipfs": "^0.2.22",
13-
"@dstack-js/lib": "^0.2.23",
13+
"@dstack-js/lib": "^0.2.25",
1414
"@oclif/command": "^1",
1515
"@oclif/config": "^1",
1616
"blessed": "^0.1.81",

src/commands/discord/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class DiscordRelay extends Command {
2525
throw new Error('DISCORD_KEY env is missing')
2626
}
2727

28-
const { pubsub } = await getStack()
28+
const { stack } = await getStack()
29+
const { pubsub } = stack
30+
2931
const client = new Discord.Client({ intents: [Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILDS, Intents.FLAGS.DIRECT_MESSAGES] })
3032
await client.login(process.env.DISCORD_KEY)
3133

src/services/chat.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as blessed from 'blessed'
22
import { getStack } from './stack'
33

44
export const run = async (room: string, nickname?: string) => {
5-
const { ipfs, stack, pubsub } = await getStack()
5+
const { ipfs, stack } = await getStack()
6+
const { id, pubsub } = stack
67

78
const screen = blessed.screen({
89
smartCSR: true,
@@ -20,7 +21,7 @@ export const run = async (room: string, nickname?: string) => {
2021
left: 0,
2122
items: [
2223
'dstack: connected',
23-
`dstack: your id is ${stack.id.slice(-5)}`,
24+
`dstack: your id is ${id.slice(-5)}`,
2425
'dstack: use /help to see commands'
2526
]
2627
})
@@ -31,7 +32,7 @@ export const run = async (room: string, nickname?: string) => {
3132
height: '10%',
3233
inputOnFocus: true,
3334
clickable: true,
34-
label: ` ID: ${stack.id.slice(-5)} `,
35+
label: ` ID: ${id.slice(-5)} `,
3536
padding: {
3637
top: 1,
3738
left: 2
@@ -101,8 +102,12 @@ export const run = async (room: string, nickname?: string) => {
101102
}
102103
})
103104

104-
screen.key(['escape', 'q', 'C-c'], function () {
105-
return process.exit(0)
105+
screen.key(['escape', 'q', 'C-c'], () => {
106+
process.exit(0)
107+
})
108+
109+
input.key(['C-c'], () => {
110+
process.exit(0)
106111
})
107112

108113
screen.append(messageList)

src/services/stack.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { create } from '@dstack-js/ipfs'
22
import { Stack } from '@dstack-js/lib'
3-
import type { PubSub } from '@dstack-js/lib/src/pubsub'
3+
44
const wrtc = require('wrtc')
55

66
interface Message {
@@ -38,7 +38,6 @@ export const getStack = async () => {
3838
}, wrtc)
3939

4040
const stack = await Stack.create('dstack-chat', ipfs)
41-
const pubsub = stack.pubsub as PubSub<Message>
4241

43-
return { pubsub, stack, ipfs }
42+
return { stack: stack as Stack<Message>, ipfs }
4443
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@
252252
libp2p-webrtc-star "^0.25.0"
253253
tslib "^2.3.1"
254254

255-
"@dstack-js/lib@^0.2.23":
256-
version "0.2.23"
257-
resolved "https://registry.yarnpkg.com/@dstack-js/lib/-/lib-0.2.23.tgz#3b41188edc7a74210ad51af2787aec53b68da602"
258-
integrity sha512-+Vocbvhmh7GU+WR9MnSvUD2Kr0e0pX90DmKqEq1oSXMnp8TiblQfBaTBVyBVf66ygWyKGwi9VGQzLA5BBqLAbQ==
255+
"@dstack-js/lib@^0.2.25":
256+
version "0.2.25"
257+
resolved "https://registry.yarnpkg.com/@dstack-js/lib/-/lib-0.2.25.tgz#9e0d53e96fe1e81d450678c04d21bea19bbb67d1"
258+
integrity sha512-FPdAG8+nl5PENpUR3sUQv79WCTC37atCOIK3kvPFxql2AhkCvAUYqoGMYdZuvGr44P+PSSL2MPwftZZYEml0AQ==
259259
dependencies:
260260
buffer "^6.0.3"
261261
it-drain "^1.0.5"

0 commit comments

Comments
 (0)