@jochenyang/opencode-vision 1.0.1 → 1.0.2

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/bin/install.js +66 -19
  2. package/package.json +10 -3
package/bin/install.js CHANGED
@@ -5,12 +5,19 @@ const os = require("os")
5
5
 
6
6
  const SRC = path.join(__dirname, "..")
7
7
  const DST = path.join(os.homedir(), ".config", "opencode")
8
+ const isWin = process.platform === "win32"
8
9
 
9
10
  const FILES = [
10
11
  ["tools/vision.ts", "tools/vision.ts"],
11
12
  ["plugins/vision-helper.ts", "plugins/vision-helper.ts"],
12
13
  ]
13
14
 
15
+ const ENV_VARS = [
16
+ { name: "VISION_API_KEY", desc: "视觉 API 密钥 / Vision API key", example: "sk-your-api-key" },
17
+ { name: "VISION_API_URL", desc: "视觉 API 地址 / Vision API base URL", example: "https://your-api-endpoint/v1" },
18
+ { name: "VISION_MODEL", desc: "视觉模型名称 / Vision model name", example: "your-vision-model" },
19
+ ]
20
+
14
21
  function log(msg, ok = true) {
15
22
  const prefix = ok ? "\x1b[32m ✓\x1b[0m" : "\x1b[31m ✗\x1b[0m"
16
23
  console.log(`${prefix} ${msg}`)
@@ -20,45 +27,82 @@ function title(msg) {
20
27
  console.log(`\n\x1b[36m═══ ${msg} \x1b[0m\n`)
21
28
  }
22
29
 
30
+ function printEnvGuide() {
31
+ console.log("\n 你需要设置以下环境变量才能使用视觉识别功能:")
32
+ console.log()
33
+
34
+ for (const v of ENV_VARS) {
35
+ console.log(` \x1b[33m${v.name}\x1b[0m`)
36
+ console.log(` → ${v.desc}`)
37
+ console.log(` → 示例: ${v.example}`)
38
+ console.log()
39
+ }
40
+
41
+ if (isWin) {
42
+ console.log(" \x1b[36mWindows 系统级配置(管理员 PowerShell):\x1b[0m")
43
+ console.log()
44
+ for (const v of ENV_VARS) {
45
+ console.log(` [System.Environment]::SetEnvironmentVariable('${v.name}', '${v.example}', 'User')`)
46
+ }
47
+ console.log()
48
+ console.log(" 设置后重启终端生效。")
49
+ } else {
50
+ console.log(" \x1b[36mmacOS / Linux 配置(添加到 ~/.zshrc 或 ~/.bashrc):\x1b[0m")
51
+ console.log()
52
+ for (const v of ENV_VARS) {
53
+ console.log(` export ${v.name}="${v.example}"`)
54
+ }
55
+ console.log()
56
+ console.log(" 然后执行 source ~/.zshrc 或重启终端。")
57
+ }
58
+ }
59
+
60
+ async function checkVars() {
61
+ let missing = 0
62
+ for (const v of ENV_VARS) {
63
+ const val = process.env[v.name]
64
+ if (val) {
65
+ const masked = v.name === "VISION_API_KEY" ? val.slice(0, 6) + "****" : val
66
+ log(`${v.name} = ${masked}`)
67
+ } else {
68
+ log(`${v.name} 未设置`, false)
69
+ missing++
70
+ }
71
+ }
72
+ return missing
73
+ }
74
+
23
75
  async function doInstall() {
24
76
  title("opencode-vision 安装")
25
77
 
78
+ // ── 文件复制 ──
26
79
  for (const [, rel] of FILES) {
27
80
  const dir = path.join(DST, path.dirname(rel))
28
81
  if (!fs.existsSync(dir)) {
29
82
  fs.mkdirSync(dir, { recursive: true })
30
83
  }
31
84
  }
32
-
33
85
  for (const [srcRel, dstRel] of FILES) {
34
86
  const src = path.join(SRC, srcRel)
35
87
  const dst = path.join(DST, dstRel)
36
-
37
88
  if (!fs.existsSync(src)) {
38
89
  log(`源文件不存在: ${srcRel}`, false)
39
90
  continue
40
91
  }
41
-
42
92
  fs.copyFileSync(src, dst)
43
93
  log(`安装 ${dstRel}`)
44
94
  }
45
95
 
96
+ // ── 环境变量检查 ──
46
97
  title("环境变量检查")
47
- const vars = {
48
- VISION_API_KEY: process.env.VISION_API_KEY,
49
- VISION_API_URL: process.env.VISION_API_URL,
50
- VISION_MODEL: process.env.VISION_MODEL,
51
- }
98
+ const missing = await checkVars()
52
99
 
53
- for (const [name, val] of Object.entries(vars)) {
54
- if (val) {
55
- const masked = name === "VISION_API_KEY" ? val.slice(0, 6) + "****" : val
56
- log(`${name} = ${masked}`)
57
- } else {
58
- log(`${name} 未设置 — 请配置后再使用`, false)
59
- }
100
+ if (missing > 0) {
101
+ console.log(`\n \x1b[33m⚠ 有 ${missing} 个环境变量未设置。\x1b[0m`)
102
+ printEnvGuide()
60
103
  }
61
104
 
105
+ // ── OpenCode 检测 ──
62
106
  title("OpenCode 检测")
63
107
  try {
64
108
  const { execSync } = require("child_process")
@@ -73,9 +117,13 @@ async function doInstall() {
73
117
  }
74
118
 
75
119
  title("安装完成")
76
- console.log(" 重启 OpenCode 后即可使用。")
77
- console.log(" 粘贴一张图片试试看:")
78
- console.log(' [图片] "这是什么?"')
120
+ console.log(" 文件已就位,重启 OpenCode 后即可使用。")
121
+ if (missing > 0) {
122
+ console.log(" ⚠ 环境变量未配置完整,视觉识别功能无法正常工作。")
123
+ console.log(" 请按上面指引设置后再重启 OpenCode。")
124
+ }
125
+ console.log(" 📝 使用方式:粘贴一张图片并提问")
126
+ console.log(' "[图片] 这是什么?"')
79
127
  }
80
128
 
81
129
  async function doUninstall() {
@@ -92,7 +140,6 @@ async function doUninstall() {
92
140
  log(`已删除 ${rel}`)
93
141
  removed++
94
142
 
95
- // 如果目录空了就一并清理
96
143
  const dir = path.dirname(dst)
97
144
  if (fs.existsSync(dir) && fs.readdirSync(dir).length === 0) {
98
145
  fs.rmdirSync(dir)
package/package.json CHANGED
@@ -1,13 +1,20 @@
1
1
  {
2
2
  "name": "@jochenyang/opencode-vision",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Vision plugin + tool for OpenCode — automatically handles pasted images for non-vision models",
5
- "keywords": ["opencode", "vision", "image", "ai", "plugin", "tool"],
5
+ "keywords": [
6
+ "opencode",
7
+ "vision",
8
+ "image",
9
+ "ai",
10
+ "plugin",
11
+ "tool"
12
+ ],
6
13
  "homepage": "https://github.com/jochenyang/opencode-vision",
7
14
  "license": "MIT",
8
15
  "author": "Jochen Yang",
9
16
  "bin": {
10
- "opencode-vision": "./bin/install.js"
17
+ "opencode-vision": "bin/install.js"
11
18
  },
12
19
  "files": [
13
20
  "bin/",