opencode-dashscope-imagegen 0.1.0 → 0.1.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.
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "opencode-dashscope-imagegen",
3
- "version": "0.1.0",
4
- "description": "OpenCode plugin: text-to-image generation via Alibaba DashScope (qwen-image / wan models). Adds an image_generate tool.",
3
+ "version": "0.1.2",
4
+ "description": "OpenCode plugin that adds an image_generate tool for text-to-image generation with Alibaba DashScope models (qwen-image-2.0, qwen-image-3.0, wan2.7-image)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "exports": {
8
- ".": "./dist/index.js"
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
9
12
  },
10
13
  "files": [
11
14
  "dist",
@@ -13,22 +16,50 @@
13
16
  ],
14
17
  "scripts": {
15
18
  "typecheck": "tsc --noEmit",
16
- "build": "bun build src/index.ts --target node --format esm --outdir dist"
19
+ "build": "tsc"
17
20
  },
18
21
  "keywords": [
19
22
  "opencode",
23
+ "opencode-plugin",
24
+ "opencode-ai",
20
25
  "plugin",
21
26
  "dashscope",
27
+ "alibaba",
28
+ "aliyun",
29
+ "bailian",
22
30
  "qwen",
31
+ "qwen-image",
32
+ "wan",
23
33
  "image-generation",
24
- "text-to-image"
34
+ "text-to-image",
35
+ "image",
36
+ "imagegen",
37
+ "ai",
38
+ "ai-image",
39
+ "typescript"
25
40
  ],
26
41
  "license": "MIT",
42
+ "author": "WhiteBite",
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/WhiteBite/opencode-dashscope-imagegen.git"
46
+ },
47
+ "homepage": "https://github.com/WhiteBite/opencode-dashscope-imagegen#readme",
48
+ "bugs": {
49
+ "url": "https://github.com/WhiteBite/opencode-dashscope-imagegen/issues"
50
+ },
51
+ "engines": {
52
+ "node": ">=18"
53
+ },
54
+ "publishConfig": {
55
+ "access": "public",
56
+ "provenance": true
57
+ },
27
58
  "dependencies": {
28
- "@opencode-ai/plugin": "latest"
59
+ "@opencode-ai/plugin": "^1.18.19"
29
60
  },
30
61
  "devDependencies": {
31
- "typescript": "^5.5.0",
32
- "@types/node": "^22.0.0"
62
+ "@types/node": "^22.0.0",
63
+ "typescript": "^5.5.0"
33
64
  }
34
65
  }
package/src/index.ts CHANGED
@@ -1,14 +1,25 @@
1
- import type { Plugin } from "@opencode-ai/plugin";
1
+ import type { Plugin, PluginInput } from "@opencode-ai/plugin";
2
2
  import { tool } from "@opencode-ai/plugin";
3
3
  import { writeFileSync, mkdirSync, existsSync, readFileSync } from "node:fs";
4
4
  import { join, isAbsolute, dirname } from "node:path";
5
5
 
6
- const LOG = "[dashscope-imagegen]";
6
+ const SERVICE = "dashscope-imagegen";
7
7
  const ENDPOINT =
8
8
  "https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation";
9
9
  const DEFAULT_MODEL = "qwen-image-2.0";
10
10
 
11
- console.log(`${LOG} plugin module loaded (pid=${process.pid}, platform=${process.platform})`);
11
+ /** Structured logger via the OpenCode SDK; never throws. */
12
+ function makeLog(client: PluginInput["client"]) {
13
+ return (level: "info" | "error", message: string, extra?: Record<string, unknown>) => {
14
+ try {
15
+ void client.app
16
+ .log({ body: { service: SERVICE, level, message, extra } })
17
+ .catch(() => {});
18
+ } catch {
19
+ // logging must never break generation
20
+ }
21
+ };
22
+ }
12
23
 
13
24
  function configDir(): string {
14
25
  return (
@@ -130,8 +141,9 @@ async function runGenerate(args: GenArgs) {
130
141
  };
131
142
  }
132
143
 
133
- const DashscopeImagegenPlugin: Plugin = async () => {
134
- console.log(`${LOG} plugin() invoked, registering image_generate tool`);
144
+ export const DashscopeImagegenPlugin: Plugin = async ({ client }) => {
145
+ const log = makeLog(client);
146
+ log("info", "plugin initialized, registering image_generate tool");
135
147
  return {
136
148
  tool: {
137
149
  image_generate: tool({
@@ -153,13 +165,17 @@ const DashscopeImagegenPlugin: Plugin = async () => {
153
165
  .describe("Absolute output file path (default: auto-named in gen-images dir)"),
154
166
  },
155
167
  async execute(args) {
156
- console.log(
157
- `${LOG} execute: prompt="${args.prompt.slice(0, 80)}" model=${args.model ?? DEFAULT_MODEL} size=${args.size ?? "1024*1024"}`,
158
- );
168
+ log("info", "image_generate called", {
169
+ prompt: args.prompt.slice(0, 80),
170
+ model: args.model ?? DEFAULT_MODEL,
171
+ size: args.size ?? "1024*1024",
172
+ });
159
173
  try {
160
174
  return await runGenerate(args);
161
175
  } catch (e) {
162
- console.error(`${LOG} execute failed:`, e);
176
+ log("error", "image_generate failed", {
177
+ error: e instanceof Error ? e.message : String(e),
178
+ });
163
179
  throw e;
164
180
  }
165
181
  },
@@ -167,5 +183,3 @@ const DashscopeImagegenPlugin: Plugin = async () => {
167
183
  },
168
184
  };
169
185
  };
170
-
171
- export default DashscopeImagegenPlugin;