@surph_ai/cli 0.0.5 → 0.0.7
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.
- package/cli.js +2 -1
- package/index.js +0 -0
- package/package.json +1 -1
- package/toolserver/ensure-chat.js +40 -17
package/cli.js
CHANGED
|
@@ -17,7 +17,7 @@ const AdmZip = require('adm-zip')
|
|
|
17
17
|
// const auth = require('./auth')
|
|
18
18
|
const deploy = require('./deploy')
|
|
19
19
|
const scaffold = require('./scaffold')
|
|
20
|
-
const { ensureChat } = require('./toolserver/ensure-chat')
|
|
20
|
+
const { ensureChat, chatNodePath } = require('./toolserver/ensure-chat')
|
|
21
21
|
const utils = require('./utils')
|
|
22
22
|
const packageJson = require('./package.json')
|
|
23
23
|
|
|
@@ -166,6 +166,7 @@ program.command('chatserver')
|
|
|
166
166
|
cliVersion: VERSION,
|
|
167
167
|
log: (msg) => console.log(colors.cyan(`\n${msg}\n`))
|
|
168
168
|
})
|
|
169
|
+
process.env.NODE_PATH = chatNodePath()
|
|
169
170
|
shell.exec(`nodemon --quiet "${chatPath}"`)
|
|
170
171
|
} catch (error) {
|
|
171
172
|
utils.printError(error)
|
package/index.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
const crypto = require('crypto')
|
|
2
2
|
const fs = require('fs')
|
|
3
|
-
const os = require('os')
|
|
4
3
|
const path = require('path')
|
|
5
4
|
|
|
6
5
|
const MANIFEST_URL = 'https://surph.s3.us-east-1.amazonaws.com/tools/cli/manifest.json'
|
|
7
6
|
const CHAT_URL = 'https://surph.s3.us-east-1.amazonaws.com/tools/cli/chat.js'
|
|
8
|
-
const
|
|
9
|
-
const CACHE_FILE = path.join(CACHE_DIR, 'chat.js')
|
|
10
|
-
const CACHE_META = path.join(CACHE_DIR, 'chat.meta.json')
|
|
7
|
+
const CLI_NODE_MODULES = path.join(__dirname, '..', 'node_modules')
|
|
11
8
|
const BUNDLED_FALLBACK = path.join(__dirname, 'chat.js')
|
|
12
9
|
|
|
10
|
+
const cachePaths = () => {
|
|
11
|
+
const cacheDir = path.join(process.cwd(), 'node_modules', '@surph_ai', 'cache')
|
|
12
|
+
return {
|
|
13
|
+
cacheDir,
|
|
14
|
+
cacheFile: path.join(cacheDir, 'chat.js'),
|
|
15
|
+
cacheMeta: path.join(cacheDir, 'manifest.json')
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const chatNodePath = () => {
|
|
20
|
+
const dirs = [
|
|
21
|
+
CLI_NODE_MODULES,
|
|
22
|
+
path.join(process.cwd(), 'node_modules')
|
|
23
|
+
].filter((dir) => fs.existsSync(dir))
|
|
24
|
+
return [...dirs, process.env.NODE_PATH].filter(Boolean).join(path.delimiter)
|
|
25
|
+
}
|
|
26
|
+
|
|
13
27
|
const parseVersion = (value) => String(value || '0').split('.').map((part) => {
|
|
14
28
|
const n = parseInt(part, 10)
|
|
15
29
|
return Number.isFinite(n) ? n : 0
|
|
@@ -39,11 +53,12 @@ const readJsonFile = (filepath) => {
|
|
|
39
53
|
}
|
|
40
54
|
|
|
41
55
|
const cacheMatches = (manifest) => {
|
|
42
|
-
const
|
|
56
|
+
const { cacheFile, cacheMeta } = cachePaths()
|
|
57
|
+
const meta = readJsonFile(cacheMeta)
|
|
43
58
|
if (!meta || meta.sha256 !== manifest.sha256) return false
|
|
44
|
-
if (!fs.existsSync(
|
|
59
|
+
if (!fs.existsSync(cacheFile)) return false
|
|
45
60
|
if (manifest.size) {
|
|
46
|
-
const { size } = fs.statSync(
|
|
61
|
+
const { size } = fs.statSync(cacheFile)
|
|
47
62
|
if (size !== manifest.size) return false
|
|
48
63
|
}
|
|
49
64
|
return true
|
|
@@ -80,15 +95,22 @@ const downloadChat = async (manifest) => {
|
|
|
80
95
|
throw new Error('Chat server checksum mismatch')
|
|
81
96
|
}
|
|
82
97
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
fs.writeFileSync(
|
|
86
|
-
|
|
87
|
-
|
|
98
|
+
const { cacheDir, cacheFile, cacheMeta } = cachePaths()
|
|
99
|
+
fs.mkdirSync(cacheDir, { recursive: true })
|
|
100
|
+
fs.writeFileSync(path.join(cacheDir, 'package.json'), JSON.stringify({
|
|
101
|
+
name: '@surph_ai/cache',
|
|
102
|
+
private: true,
|
|
103
|
+
type: 'commonjs'
|
|
104
|
+
}, null, 2) + '\n')
|
|
105
|
+
const tmp = `${cacheFile}.tmp`
|
|
106
|
+
fs.writeFileSync(tmp, buf)
|
|
107
|
+
fs.renameSync(tmp, cacheFile)
|
|
108
|
+
fs.writeFileSync(cacheMeta, JSON.stringify(manifest, null, 2) + '\n')
|
|
88
109
|
}
|
|
89
110
|
|
|
90
111
|
const fallbackPath = () => {
|
|
91
|
-
|
|
112
|
+
const { cacheFile } = cachePaths()
|
|
113
|
+
if (fs.existsSync(cacheFile)) return cacheFile
|
|
92
114
|
if (fs.existsSync(BUNDLED_FALLBACK)) return BUNDLED_FALLBACK
|
|
93
115
|
return null
|
|
94
116
|
}
|
|
@@ -112,14 +134,15 @@ const ensureChat = async ({ cliVersion, log } = {}) => {
|
|
|
112
134
|
)
|
|
113
135
|
}
|
|
114
136
|
|
|
137
|
+
const { cacheFile } = cachePaths()
|
|
115
138
|
if (cacheMatches(manifest)) {
|
|
116
|
-
return
|
|
139
|
+
return cacheFile
|
|
117
140
|
}
|
|
118
141
|
|
|
119
|
-
if (log) log('Downloading latest chat server...')
|
|
142
|
+
// if (log) log('Downloading latest chat server...')
|
|
120
143
|
try {
|
|
121
144
|
await downloadChat(manifest)
|
|
122
|
-
return
|
|
145
|
+
return cacheFile
|
|
123
146
|
} catch (error) {
|
|
124
147
|
const fallback = fallbackPath()
|
|
125
148
|
if (fallback) {
|
|
@@ -130,4 +153,4 @@ const ensureChat = async ({ cliVersion, log } = {}) => {
|
|
|
130
153
|
}
|
|
131
154
|
}
|
|
132
155
|
|
|
133
|
-
module.exports = { ensureChat }
|
|
156
|
+
module.exports = { ensureChat, chatNodePath }
|