meshy-dsh 0.3.0 → 0.3.1

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.
Files changed (2) hide show
  1. package/lib/index.js +34 -2
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -6,8 +6,9 @@
6
6
  // Web and Desktop, four authenticated routes under /api for the settings page. Every CLI call
7
7
  // uses fixed arguments.
8
8
  import { spawn } from 'node:child_process'
9
+ import { watch } from 'node:fs'
9
10
  import { createRequire } from 'node:module'
10
- import { join } from 'node:path'
11
+ import { basename, dirname, join } from 'node:path'
11
12
 
12
13
  export const name = 'meshy-dsh'
13
14
 
@@ -75,6 +76,33 @@ const regionOf = (baseUrl) => typeof baseUrl === 'string' && baseUrl.includes('m
75
76
  /** The signed-in session handed to shells, or null while signed out. Never sent to a page. */
76
77
  let session = null
77
78
  let reading = null
79
+ let watcher = null
80
+ let watchedFile = null
81
+
82
+ /**
83
+ * Re-read the session as soon as the credentials file changes. A refresh by any other process (a
84
+ * terminal, another agent) ends the access token this host holds, so waiting for the next timer
85
+ * tick would hand shells a rejected token in the meantime.
86
+ */
87
+ function watchStore(file) {
88
+ if (typeof file !== 'string' || !file || file === watchedFile) return
89
+ stopWatching()
90
+ try {
91
+ watcher = watch(dirname(file), { persistent: false }, (_event, name) => {
92
+ if (name === null || String(name) === basename(file)) void refreshSession()
93
+ })
94
+ watcher.on('error', stopWatching)
95
+ watchedFile = file
96
+ } catch {
97
+ // The directory does not exist yet (never signed in); the next read tries again.
98
+ }
99
+ }
100
+
101
+ function stopWatching() {
102
+ watcher?.close()
103
+ watcher = null
104
+ watchedFile = null
105
+ }
78
106
 
79
107
  /**
80
108
  * Re-read the session. `auth status --offline` refreshes the token here, where the store is
@@ -84,6 +112,7 @@ export function refreshSession() {
84
112
  reading ??= meshy(['auth', 'status', '--offline', '--show-token'])
85
113
  .then((out) => {
86
114
  const r = out.result ?? {}
115
+ watchStore(r.credentials_file)
87
116
  session = out.ok && r.authenticated === true && typeof r.token === 'string' && r.token
88
117
  ? {
89
118
  token: r.token,
@@ -264,7 +293,10 @@ export function apply(ctx) {
264
293
  void refreshSession()
265
294
  const timer = setInterval(refreshSession, SESSION_REFRESH_MS)
266
295
  timer.unref?.()
267
- return () => clearInterval(timer)
296
+ return () => {
297
+ clearInterval(timer)
298
+ stopWatching()
299
+ }
268
300
  }, 'meshy-dsh: session refresh')
269
301
  ctx.inject(['shellEnv'], (ctx) => {
270
302
  ctx.shellEnv.register({ name: 'meshy', variables: SHELL_VARIABLES, resolve: shellFacts })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meshy-dsh",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Meshy skills for DeepSeek Harness: textured, rigged and animated 3D models or print-ready files from text or images, through meshy-cli, with a Meshy settings page and a 3D preview for GLB files.",
5
5
  "keywords": [
6
6
  "dsh-plugin",
@@ -65,6 +65,6 @@
65
65
  "tsdown": "^0.23.4"
66
66
  },
67
67
  "dependencies": {
68
- "meshy-cli": "0.8.0"
68
+ "meshy-cli": "0.8.1"
69
69
  }
70
70
  }