@nogataka/imgen 0.2.0 → 0.3.0

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/dist/index.js CHANGED
@@ -2,256 +2,25 @@
2
2
  import {
3
3
  AzureChatClient,
4
4
  AzureImageClient,
5
- DEFAULT_CONFIG,
6
5
  LANGUAGE_DESCRIPTIONS,
7
- Logger,
8
- deletePreset,
9
6
  fileExists,
10
7
  getAzureConfig,
11
- getConfigPath,
12
8
  getPreset,
13
- getPresetsPath,
14
- listAllPresets,
15
- loadConfig,
16
9
  loadContextFile,
17
10
  readImageFile,
18
- saveConfig,
19
- saveFileWithUniqueNameIfExists,
20
- savePreset
21
- } from "./chunk-HQT7ZTCY.js";
11
+ saveFileWithUniqueNameIfExists
12
+ } from "./chunk-UZXMJEHL.js";
22
13
 
23
14
  // src/commands/index.ts
24
- import { Command as Command8 } from "commander";
25
-
26
- // src/commands/configure.ts
27
- import { Command } from "commander";
28
- import inquirer from "inquirer";
29
- function configureCommand() {
30
- return new Command("configure").description("API\u8A2D\u5B9A\u3092\u884C\u3044\u307E\u3059").option("--show", "\u73FE\u5728\u306E\u8A2D\u5B9A\u3092\u8868\u793A").option("--reset", "\u8A2D\u5B9A\u3092\u30EA\u30BB\u30C3\u30C8").action(async (options) => {
31
- try {
32
- if (options.show) {
33
- await showConfig();
34
- return;
35
- }
36
- if (options.reset) {
37
- await resetConfig();
38
- return;
39
- }
40
- await interactiveConfig();
41
- } catch (error) {
42
- if (error instanceof Error) {
43
- console.error("\u30A8\u30E9\u30FC:", error.message);
44
- } else {
45
- console.error("\u4E0D\u660E\u306A\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F");
46
- }
47
- process.exit(1);
48
- }
49
- });
50
- }
51
- async function showConfig() {
52
- const config = await loadConfig();
53
- const configPath = getConfigPath();
54
- console.log(`
55
- \u8A2D\u5B9A\u30D5\u30A1\u30A4\u30EB: ${configPath}
56
- `);
57
- if (!config) {
58
- console.log("\u8A2D\u5B9A\u30D5\u30A1\u30A4\u30EB\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002");
59
- console.log("\n\u30C7\u30D5\u30A9\u30EB\u30C8\u5024:");
60
- console.log(JSON.stringify(DEFAULT_CONFIG, null, 2));
61
- return;
62
- }
63
- const displayConfig = { ...config };
64
- if (displayConfig.azureApiKey) {
65
- displayConfig.azureApiKey = "****" + displayConfig.azureApiKey.slice(-4);
66
- }
67
- console.log("\u73FE\u5728\u306E\u8A2D\u5B9A:");
68
- console.log(JSON.stringify(displayConfig, null, 2));
69
- }
70
- async function resetConfig() {
71
- const { confirm } = await inquirer.prompt([
72
- {
73
- type: "confirm",
74
- name: "confirm",
75
- message: "\u8A2D\u5B9A\u3092\u30EA\u30BB\u30C3\u30C8\u3057\u307E\u3059\u304B\uFF1F\uFF08API\u8A2D\u5B9A\u3082\u524A\u9664\u3055\u308C\u307E\u3059\uFF09",
76
- default: false
77
- }
78
- ]);
79
- if (confirm) {
80
- await saveConfig({});
81
- console.log("\u8A2D\u5B9A\u3092\u30EA\u30BB\u30C3\u30C8\u3057\u307E\u3057\u305F\u3002");
82
- } else {
83
- console.log("\u30AD\u30E3\u30F3\u30BB\u30EB\u3057\u307E\u3057\u305F\u3002");
84
- }
85
- }
86
- async function interactiveConfig() {
87
- const { action } = await inquirer.prompt([
88
- {
89
- type: "list",
90
- name: "action",
91
- message: "\u8A2D\u5B9A\u9805\u76EE\u3092\u9078\u629E\u3057\u3066\u304F\u3060\u3055\u3044",
92
- choices: [
93
- { name: "Azure OpenAI\u63A5\u7D9A\u8A2D\u5B9A", value: "azure" },
94
- { name: "\u30C7\u30D5\u30A9\u30EB\u30C8\u5024\u3092\u8A2D\u5B9A", value: "defaults" },
95
- { name: "\u73FE\u5728\u306E\u8A2D\u5B9A\u3092\u8868\u793A", value: "show" },
96
- { name: "\u8A2D\u5B9A\u3092\u30EA\u30BB\u30C3\u30C8", value: "reset" },
97
- { name: "\u7D42\u4E86", value: "exit" }
98
- ]
99
- }
100
- ]);
101
- switch (action) {
102
- case "azure":
103
- await configureAzure();
104
- break;
105
- case "defaults":
106
- await configureDefaults();
107
- break;
108
- case "show":
109
- await showConfig();
110
- break;
111
- case "reset":
112
- await resetConfig();
113
- break;
114
- case "exit":
115
- return;
116
- }
117
- }
118
- async function configureAzure() {
119
- const config = await loadConfig() || {};
120
- const envEndpoint = process.env.AZURE_OPENAI_ENDPOINT;
121
- const envKey = process.env.AZURE_OPENAI_API_KEY;
122
- if (envEndpoint && envKey) {
123
- console.log("\n\u74B0\u5883\u5909\u6570\u3067Azure OpenAI\u8A2D\u5B9A\u304C\u691C\u51FA\u3055\u308C\u307E\u3057\u305F\u3002");
124
- const { useEnv } = await inquirer.prompt([
125
- {
126
- type: "confirm",
127
- name: "useEnv",
128
- message: "\u74B0\u5883\u5909\u6570\u306E\u5024\u3092\u8A2D\u5B9A\u30D5\u30A1\u30A4\u30EB\u306B\u4FDD\u5B58\u3057\u307E\u3059\u304B\uFF1F",
129
- default: true
130
- }
131
- ]);
132
- if (useEnv) {
133
- config.azureEndpoint = envEndpoint;
134
- config.azureApiKey = envKey;
135
- config.azureDeploymentName = process.env.AZURE_OPENAI_DEPLOYMENT_NAME || "gpt-5.1";
136
- config.azureImageDeploymentName = process.env.AZURE_OPENAI_DEPLOYMENT_NAME_IMAGE || "gpt-image-1.5";
137
- config.azureApiVersion = process.env.AZURE_OPENAI_API_VERSION || "2024-02-15-preview";
138
- config.azureImageApiVersion = process.env.AZURE_OPENAI_IMAGE_API_VERSION || "2025-04-01-preview";
139
- await saveConfig(config);
140
- console.log("\u8A2D\u5B9A\u3092\u4FDD\u5B58\u3057\u307E\u3057\u305F\u3002");
141
- return;
142
- }
143
- }
144
- const answers = await inquirer.prompt([
145
- {
146
- type: "input",
147
- name: "endpoint",
148
- message: "Azure OpenAI \u30A8\u30F3\u30C9\u30DD\u30A4\u30F3\u30C8:",
149
- default: config.azureEndpoint || "",
150
- validate: (input) => input.startsWith("https://") || "https:// \u3067\u59CB\u307E\u308BURL\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"
151
- },
152
- {
153
- type: "password",
154
- name: "apiKey",
155
- message: "Azure OpenAI API\u30AD\u30FC:",
156
- mask: "*",
157
- validate: (input) => input.length > 0 || "API\u30AD\u30FC\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044"
158
- },
159
- {
160
- type: "input",
161
- name: "deploymentName",
162
- message: "\u30C1\u30E3\u30C3\u30C8\u30E2\u30C7\u30EB\u30C7\u30D7\u30ED\u30A4\u540D:",
163
- default: config.azureDeploymentName || "gpt-5.1"
164
- },
165
- {
166
- type: "input",
167
- name: "imageDeploymentName",
168
- message: "\u753B\u50CF\u30E2\u30C7\u30EB\u30C7\u30D7\u30ED\u30A4\u540D:",
169
- default: config.azureImageDeploymentName || "gpt-image-1.5"
170
- },
171
- {
172
- type: "input",
173
- name: "apiVersion",
174
- message: "\u30C1\u30E3\u30C3\u30C8 API \u30D0\u30FC\u30B8\u30E7\u30F3:",
175
- default: config.azureApiVersion || "2024-02-15-preview"
176
- },
177
- {
178
- type: "input",
179
- name: "imageApiVersion",
180
- message: "\u753B\u50CF API \u30D0\u30FC\u30B8\u30E7\u30F3:",
181
- default: config.azureImageApiVersion || "2025-04-01-preview"
182
- }
183
- ]);
184
- config.azureEndpoint = answers.endpoint;
185
- config.azureApiKey = answers.apiKey;
186
- config.azureDeploymentName = answers.deploymentName;
187
- config.azureImageDeploymentName = answers.imageDeploymentName;
188
- config.azureApiVersion = answers.apiVersion;
189
- config.azureImageApiVersion = answers.imageApiVersion;
190
- await saveConfig(config);
191
- console.log("\nAzure OpenAI\u8A2D\u5B9A\u3092\u4FDD\u5B58\u3057\u307E\u3057\u305F\u3002");
192
- }
193
- async function configureDefaults() {
194
- const config = await loadConfig() || {};
195
- const answers = await inquirer.prompt([
196
- {
197
- type: "list",
198
- name: "language",
199
- message: "\u30C7\u30D5\u30A9\u30EB\u30C8\u8A00\u8A9E",
200
- choices: Object.entries(LANGUAGE_DESCRIPTIONS).map(([key, value]) => ({
201
- name: `${key}: ${value}`,
202
- value: key
203
- })),
204
- default: config.defaultLanguage || DEFAULT_CONFIG.defaultLanguage
205
- },
206
- {
207
- type: "list",
208
- name: "imageSize",
209
- message: "\u30C7\u30D5\u30A9\u30EB\u30C8\u753B\u50CF\u30B5\u30A4\u30BA",
210
- choices: [
211
- { name: "1024x1024 (\u6B63\u65B9\u5F62)", value: "1024x1024" },
212
- { name: "1536x1024 (\u6A2A\u9577)", value: "1536x1024" },
213
- { name: "1024x1536 (\u7E26\u9577)", value: "1024x1536" }
214
- ],
215
- default: config.defaultImageSize || DEFAULT_CONFIG.defaultImageSize
216
- },
217
- {
218
- type: "list",
219
- name: "imageQuality",
220
- message: "\u30C7\u30D5\u30A9\u30EB\u30C8\u753B\u50CF\u54C1\u8CEA",
221
- choices: [
222
- { name: "high (\u9AD8\u54C1\u8CEA)", value: "high" },
223
- { name: "medium (\u6A19\u6E96)", value: "medium" },
224
- { name: "low (\u9AD8\u901F)", value: "low" }
225
- ],
226
- default: config.defaultImageQuality || DEFAULT_CONFIG.defaultImageQuality
227
- },
228
- {
229
- type: "list",
230
- name: "imageFormat",
231
- message: "\u30C7\u30D5\u30A9\u30EB\u30C8\u753B\u50CF\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8",
232
- choices: [
233
- { name: "PNG", value: "png" },
234
- { name: "JPG", value: "jpg" },
235
- { name: "WebP", value: "webp" }
236
- ],
237
- default: config.defaultImageFormat || DEFAULT_CONFIG.defaultImageFormat
238
- }
239
- ]);
240
- config.defaultLanguage = answers.language;
241
- config.defaultImageSize = answers.imageSize;
242
- config.defaultImageQuality = answers.imageQuality;
243
- config.defaultImageFormat = answers.imageFormat;
244
- await saveConfig(config);
245
- console.log("\n\u30C7\u30D5\u30A9\u30EB\u30C8\u8A2D\u5B9A\u3092\u4FDD\u5B58\u3057\u307E\u3057\u305F\u3002");
246
- }
15
+ import { Command as Command5 } from "commander";
247
16
 
248
17
  // src/commands/image/index.ts
249
- import { Command as Command5 } from "commander";
18
+ import { Command as Command4 } from "commander";
250
19
 
251
20
  // src/commands/image/edit.ts
252
21
  import * as fs from "fs/promises";
253
22
  import * as path from "path";
254
- import { Command as Command2, Option } from "commander";
23
+ import { Command, Option } from "commander";
255
24
 
256
25
  // src/utils/output.ts
257
26
  function createSuccessOutput(command, result) {
@@ -271,7 +40,7 @@ function printJson(output) {
271
40
  // src/commands/image/edit.ts
272
41
  var SUPPORTED_EXTENSIONS = [".jpg", ".jpeg", ".png", ".gif", ".webp"];
273
42
  function imageEditCommand() {
274
- return new Command2("edit").description("\u753B\u50CF\u3092AI\u7DE8\u96C6").argument("<file>", "\u7DE8\u96C6\u3059\u308B\u753B\u50CF\u30D5\u30A1\u30A4\u30EB\u306E\u30D1\u30B9").argument("<prompt>", "\u7DE8\u96C6\u306E\u6307\u793A").option("-o, --output <path>", "\u51FA\u529B\u30D1\u30B9").addOption(
43
+ return new Command("edit").description("\u753B\u50CF\u3092AI\u7DE8\u96C6").argument("<file>", "\u7DE8\u96C6\u3059\u308B\u753B\u50CF\u30D5\u30A1\u30A4\u30EB\u306E\u30D1\u30B9").argument("<prompt>", "\u7DE8\u96C6\u306E\u6307\u793A").option("-o, --output <path>", "\u51FA\u529B\u30D1\u30B9").addOption(
275
44
  new Option("-f, --format <format>", "\u51FA\u529B\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8").choices(["png", "jpg", "webp"]).default("png")
276
45
  ).addOption(
277
46
  new Option("-s, --size <size>", "\u51FA\u529B\u30B5\u30A4\u30BA").choices(["1024x1024", "1536x1024", "1024x1536"]).default("1024x1024")
@@ -295,11 +64,8 @@ function imageEditCommand() {
295
64
  }
296
65
  process.exit(1);
297
66
  }
298
- const config = await loadConfig();
299
- const effectiveSize = options.size !== "1024x1024" ? options.size : config?.defaultImageSize || options.size;
300
- const effectiveFormat = options.format !== "png" ? options.format : config?.defaultImageFormat || options.format;
301
- Logger.setGlobalConfig({ destination: "BOTH" /* BOTH */, minLevel: "INFO" /* INFO */ });
302
- const logger = Logger.getInstance({ name: "image-edit" });
67
+ const effectiveSize = options.size;
68
+ const effectiveFormat = options.format;
303
69
  if (options.dryRun) {
304
70
  const info = {
305
71
  file: filePath,
@@ -347,11 +113,6 @@ function imageEditCommand() {
347
113
  outputPath = `${fileName}.${effectiveFormat}`;
348
114
  }
349
115
  const finalPath = await saveFileWithUniqueNameIfExists(outputPath, editedData);
350
- await logger.info("\u753B\u50CF\u3092\u7DE8\u96C6\u3057\u307E\u3057\u305F", {
351
- input: filePath,
352
- output: finalPath,
353
- size: effectiveSize
354
- });
355
116
  if (options.json) {
356
117
  printJson(
357
118
  createSuccessOutput("image edit", {
@@ -366,14 +127,12 @@ function imageEditCommand() {
366
127
  }
367
128
  } catch (error) {
368
129
  if (error instanceof Error) {
369
- await logger.error("\u753B\u50CF\u7DE8\u96C6\u306B\u5931\u6557\u3057\u307E\u3057\u305F", { error: error.message });
370
130
  if (options.json) {
371
131
  printJson(createErrorOutput("image edit", error.message));
372
132
  } else {
373
133
  console.error("\u30A8\u30E9\u30FC:", error.message);
374
134
  }
375
135
  } else {
376
- await logger.error("\u4E0D\u660E\u306A\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F");
377
136
  if (options.json) {
378
137
  printJson(createErrorOutput("image edit", "\u4E0D\u660E\u306A\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F"));
379
138
  } else {
@@ -387,16 +146,15 @@ function imageEditCommand() {
387
146
 
388
147
  // src/commands/image/explain.ts
389
148
  import * as fs2 from "fs/promises";
390
- import { Command as Command3 } from "commander";
149
+ import { Command as Command2 } from "commander";
391
150
  function imageExplainCommand() {
392
- return new Command3("explain").description("\u753B\u50CF\u306E\u5185\u5BB9\u3092\u8AAC\u660E").argument("<file>", "\u753B\u50CF\u30D5\u30A1\u30A4\u30EB\u306E\u30D1\u30B9").option(
151
+ return new Command2("explain").description("\u753B\u50CF\u306E\u5185\u5BB9\u3092\u8AAC\u660E").argument("<file>", "\u753B\u50CF\u30D5\u30A1\u30A4\u30EB\u306E\u30D1\u30B9").option(
393
152
  "-l, --lang <lang>",
394
153
  `\u51FA\u529B\u8A00\u8A9E (${Object.keys(LANGUAGE_DESCRIPTIONS).join(", ")})`,
395
154
  "ja"
396
155
  ).option("-f, --format <format>", "\u51FA\u529B\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8 (markdown | json)", "markdown").option("-c, --context <context>", "\u30B3\u30F3\u30C6\u30AD\u30B9\u30C8\u60C5\u5831").option("-o, --output <path>", "\u51FA\u529B\u30D5\u30A1\u30A4\u30EB\u30D1\u30B9").action(async (filePath, options) => {
397
156
  try {
398
- const config = await loadConfig();
399
- const lang = options.lang === "ja" && config?.defaultLanguage ? config.defaultLanguage : options.lang;
157
+ const lang = options.lang;
400
158
  const validLangs = Object.keys(LANGUAGE_DESCRIPTIONS);
401
159
  const effectiveLang = validLangs.includes(lang) ? lang : "ja";
402
160
  const azureConfig = await getAzureConfig();
@@ -437,7 +195,7 @@ ${explanation}`;
437
195
  // src/commands/image/gen.ts
438
196
  import * as fs3 from "fs/promises";
439
197
  import * as path2 from "path";
440
- import { Command as Command4, Option as Option2 } from "commander";
198
+ import { Command as Command3, Option as Option2 } from "commander";
441
199
  var VALID_FORMATS = ["png", "jpg", "webp"];
442
200
  function validateImageFormat(ext, specifiedFormat) {
443
201
  if (!VALID_FORMATS.includes(ext)) {
@@ -474,7 +232,7 @@ async function resolveOutputPath(outputPath, defaultFormat, fileName) {
474
232
  return { path: outputPath, format };
475
233
  }
476
234
  function imageGenCommand() {
477
- return new Command4("gen").description("\u30C6\u30AD\u30B9\u30C8\u304B\u3089\u753B\u50CF\u3092\u751F\u6210").argument("<theme>", "\u753B\u50CF\u751F\u6210\u306E\u30C6\u30FC\u30DE").option("-c, --context <file>", "\u30B3\u30F3\u30C6\u30AD\u30B9\u30C8\u30D5\u30A1\u30A4\u30EB\u306E\u30D1\u30B9").option("-o, --output <path>", "\u51FA\u529B\u30D1\u30B9\uFF08\u30D5\u30A1\u30A4\u30EB\u307E\u305F\u306F\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\uFF09").addOption(
235
+ return new Command3("gen").description("\u30C6\u30AD\u30B9\u30C8\u304B\u3089\u753B\u50CF\u3092\u751F\u6210").argument("<theme>", "\u753B\u50CF\u751F\u6210\u306E\u30C6\u30FC\u30DE").option("-c, --context <file>", "\u30B3\u30F3\u30C6\u30AD\u30B9\u30C8\u30D5\u30A1\u30A4\u30EB\u306E\u30D1\u30B9").option("-o, --output <path>", "\u51FA\u529B\u30D1\u30B9\uFF08\u30D5\u30A1\u30A4\u30EB\u307E\u305F\u306F\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\uFF09").addOption(
478
236
  new Option2("-s, --size <size>", "\u753B\u50CF\u30B5\u30A4\u30BA").choices(["1024x1024", "1536x1024", "1024x1536"]).default("1024x1024")
479
237
  ).addOption(
480
238
  new Option2("-q, --quality <quality>", "\u753B\u50CF\u54C1\u8CEA").choices(["low", "medium", "high"]).default("high")
@@ -489,7 +247,7 @@ function imageGenCommand() {
489
247
  let presetQuality;
490
248
  let presetFormat;
491
249
  if (options.preset) {
492
- const preset = await getPreset(options.preset);
250
+ const preset = getPreset(options.preset);
493
251
  if (!preset) {
494
252
  const errorMsg = `\u30D7\u30EA\u30BB\u30C3\u30C8 '${options.preset}' \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002
495
253
  imgen preset list \u3067\u4E00\u89A7\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`;
@@ -504,15 +262,9 @@ imgen preset list \u3067\u4E00\u89A7\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u
504
262
  presetQuality = preset.quality;
505
263
  presetFormat = preset.format;
506
264
  }
507
- const config = await loadConfig();
508
- const effectiveSize = options.size !== "1024x1024" ? options.size : presetSize || config?.defaultImageSize || options.size;
509
- const effectiveQuality = options.quality !== "high" ? options.quality : presetQuality || config?.defaultImageQuality || options.quality;
510
- const effectiveFormat = options.format !== "png" ? options.format : presetFormat || config?.defaultImageFormat || options.format;
511
- Logger.setGlobalConfig({
512
- destination: "BOTH" /* BOTH */,
513
- minLevel: options.debug ? "DEBUG" /* DEBUG */ : "INFO" /* INFO */
514
- });
515
- const logger = Logger.getInstance({ name: "image-gen" });
265
+ const effectiveSize = options.size !== "1024x1024" ? options.size : presetSize || options.size;
266
+ const effectiveQuality = options.quality !== "high" ? options.quality : presetQuality || options.quality;
267
+ const effectiveFormat = options.format !== "png" ? options.format : presetFormat || options.format;
516
268
  if (options.dryRun) {
517
269
  const dryRunInfo = {
518
270
  theme,
@@ -545,7 +297,7 @@ imgen preset list \u3067\u4E00\u89A7\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u
545
297
  const context = await loadContextFile(options.context);
546
298
  const prompt = await chatClient.generatePrompt(theme, context);
547
299
  if (options.debug) {
548
- await logger.debug("\u751F\u6210\u3055\u308C\u305F\u30D7\u30ED\u30F3\u30D7\u30C8", { prompt, theme });
300
+ console.error("[DEBUG] \u751F\u6210\u3055\u308C\u305F\u30D7\u30ED\u30F3\u30D7\u30C8:", JSON.stringify({ prompt, theme }));
549
301
  }
550
302
  const imageData = await imageClient.generateImage(prompt, {
551
303
  size: effectiveSize,
@@ -558,13 +310,6 @@ imgen preset list \u3067\u4E00\u89A7\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u
558
310
  fileName
559
311
  );
560
312
  const finalOutputPath = await saveFileWithUniqueNameIfExists(outputPath, imageData);
561
- await logger.info("\u753B\u50CF\u3092\u751F\u6210\u3057\u307E\u3057\u305F", {
562
- path: finalOutputPath,
563
- format,
564
- size: effectiveSize,
565
- quality: effectiveQuality,
566
- ...options.preset ? { preset: options.preset } : {}
567
- });
568
313
  if (options.json) {
569
314
  printJson(
570
315
  createSuccessOutput("image gen", {
@@ -580,14 +325,12 @@ imgen preset list \u3067\u4E00\u89A7\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u
580
325
  }
581
326
  } catch (error) {
582
327
  if (error instanceof Error) {
583
- await logger.error("\u753B\u50CF\u751F\u6210\u306B\u5931\u6557\u3057\u307E\u3057\u305F", { error: error.message });
584
328
  if (options.json) {
585
329
  printJson(createErrorOutput("image gen", error.message));
586
330
  } else {
587
331
  console.error("\u30A8\u30E9\u30FC:", error.message);
588
332
  }
589
333
  } else {
590
- await logger.error("\u4E0D\u660E\u306A\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F");
591
334
  if (options.json) {
592
335
  printJson(createErrorOutput("image gen", "\u4E0D\u660E\u306A\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F"));
593
336
  } else {
@@ -601,174 +344,16 @@ imgen preset list \u3067\u4E00\u89A7\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u
601
344
 
602
345
  // src/commands/image/index.ts
603
346
  function imageCommand() {
604
- const image = new Command5("image").description("\u753B\u50CF\u751F\u6210\u30FB\u7DE8\u96C6\u30FB\u8AAC\u660E (gpt-image-1.5 / gpt-5.1)");
347
+ const image = new Command4("image").description("\u753B\u50CF\u751F\u6210\u30FB\u7DE8\u96C6\u30FB\u8AAC\u660E (gpt-image-1.5 / gpt-5.1)");
605
348
  image.addCommand(imageGenCommand());
606
349
  image.addCommand(imageEditCommand());
607
350
  image.addCommand(imageExplainCommand());
608
351
  return image;
609
352
  }
610
353
 
611
- // src/commands/log.ts
612
- import chalk from "chalk";
613
- import { Command as Command6 } from "commander";
614
- function parseLogLevel(level) {
615
- switch (level.toLowerCase()) {
616
- case "debug":
617
- return "DEBUG" /* DEBUG */;
618
- case "info":
619
- return "INFO" /* INFO */;
620
- case "warn":
621
- return "WARN" /* WARN */;
622
- case "error":
623
- return "ERROR" /* ERROR */;
624
- default:
625
- return "INFO" /* INFO */;
626
- }
627
- }
628
- function displayLogs(entries) {
629
- for (const entry of entries) {
630
- const timestamp = entry.timestamp.replace("T", " ").replace(/\.\d+Z$/, "");
631
- let levelColor;
632
- switch (entry.level) {
633
- case "DEBUG" /* DEBUG */:
634
- levelColor = chalk.gray;
635
- break;
636
- case "INFO" /* INFO */:
637
- levelColor = chalk.blue;
638
- break;
639
- case "WARN" /* WARN */:
640
- levelColor = chalk.yellow;
641
- break;
642
- case "ERROR" /* ERROR */:
643
- levelColor = chalk.red;
644
- break;
645
- default:
646
- levelColor = chalk.white;
647
- }
648
- const levelText = levelColor(entry.level);
649
- const dataText = entry.data ? ` ${JSON.stringify(entry.data)}` : "";
650
- console.log(`[${timestamp}] ${levelText} ${entry.message}${dataText}`);
651
- }
652
- }
653
- function logCommand() {
654
- return new Command6("log").description("\u30ED\u30B0\u3092\u8868\u793A\u3057\u307E\u3059").option("-n, --lines <lines>", "\u8868\u793A\u3059\u308B\u884C\u6570", "20").option("-l, --level <level>", "\u8868\u793A\u3059\u308B\u30ED\u30B0\u30EC\u30D9\u30EB (debug, info, warn, error)", "info").action(async (options) => {
655
- const lines = parseInt(options.lines, 10) || 20;
656
- const logLevel = parseLogLevel(options.level);
657
- const logger = Logger.getInstance({
658
- name: "imgen",
659
- config: { destination: "CONSOLE" /* CONSOLE */ }
660
- });
661
- try {
662
- const entries = await logger.getLogEntries(logLevel, lines);
663
- if (entries.length === 0) {
664
- console.log("\u30ED\u30B0\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3067\u3057\u305F");
665
- return;
666
- }
667
- displayLogs(entries);
668
- } catch (error) {
669
- console.error(
670
- `\u30ED\u30B0\u306E\u53D6\u5F97\u306B\u5931\u6557\u3057\u307E\u3057\u305F: ${error instanceof Error ? error.message : String(error)}`
671
- );
672
- }
673
- });
674
- }
675
-
676
- // src/commands/preset.ts
677
- import { Command as Command7 } from "commander";
678
- function presetCommand() {
679
- const preset = new Command7("preset").description("\u753B\u50CF\u751F\u6210\u30D7\u30EA\u30BB\u30C3\u30C8\u3092\u7BA1\u7406\u3057\u307E\u3059");
680
- preset.command("list").description("\u30D7\u30EA\u30BB\u30C3\u30C8\u4E00\u89A7\u3092\u8868\u793A").option("--json", "JSON\u5F62\u5F0F\u3067\u51FA\u529B").action(async (options) => {
681
- try {
682
- const presets = await listAllPresets();
683
- if (options.json) {
684
- console.log(JSON.stringify(presets, null, 2));
685
- return;
686
- }
687
- console.log(`
688
- \u30D7\u30EA\u30BB\u30C3\u30C8\u4E00\u89A7 (${getPresetsPath()})
689
- `);
690
- if (presets.length === 0) {
691
- console.log("\u30D7\u30EA\u30BB\u30C3\u30C8\u304C\u3042\u308A\u307E\u305B\u3093\u3002");
692
- return;
693
- }
694
- const builtins = presets.filter((p) => p.builtin);
695
- if (builtins.length > 0) {
696
- console.log("\u30D3\u30EB\u30C8\u30A4\u30F3\u30D7\u30EA\u30BB\u30C3\u30C8:");
697
- for (const { name, preset: preset2 } of builtins) {
698
- console.log(` ${name}`);
699
- formatPreset(preset2, " ");
700
- }
701
- console.log();
702
- }
703
- const userDefined = presets.filter((p) => !p.builtin);
704
- if (userDefined.length > 0) {
705
- console.log("\u30E6\u30FC\u30B6\u30FC\u5B9A\u7FA9\u30D7\u30EA\u30BB\u30C3\u30C8:");
706
- for (const { name, preset: preset2 } of userDefined) {
707
- console.log(` ${name}`);
708
- formatPreset(preset2, " ");
709
- }
710
- }
711
- } catch (error) {
712
- if (error instanceof Error) {
713
- console.error("\u30A8\u30E9\u30FC:", error.message);
714
- } else {
715
- console.error("\u4E0D\u660E\u306A\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F");
716
- }
717
- process.exit(1);
718
- }
719
- });
720
- preset.command("save <name>").description("\u65B0\u3057\u3044\u30D7\u30EA\u30BB\u30C3\u30C8\u3092\u4FDD\u5B58").option("-s, --size <size>", "\u753B\u50CF\u30B5\u30A4\u30BA (1024x1024, 1536x1024, 1024x1536)").option("-q, --quality <quality>", "\u753B\u50CF\u54C1\u8CEA (low, medium, high)").option("-f, --format <format>", "\u753B\u50CF\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8 (png, jpg, webp)").action(
721
- async (name, options) => {
722
- try {
723
- const preset2 = {};
724
- if (options.size) preset2.size = options.size;
725
- if (options.quality) preset2.quality = options.quality;
726
- if (options.format) preset2.format = options.format;
727
- if (Object.keys(preset2).length === 0) {
728
- console.error("\u30A8\u30E9\u30FC: \u5C11\u306A\u304F\u3068\u30821\u3064\u306E\u30AA\u30D7\u30B7\u30E7\u30F3\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044");
729
- process.exit(1);
730
- }
731
- await savePreset(name, preset2);
732
- console.log(`\u30D7\u30EA\u30BB\u30C3\u30C8 '${name}' \u3092\u4FDD\u5B58\u3057\u307E\u3057\u305F\u3002`);
733
- } catch (error) {
734
- if (error instanceof Error) {
735
- console.error("\u30A8\u30E9\u30FC:", error.message);
736
- } else {
737
- console.error("\u4E0D\u660E\u306A\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F");
738
- }
739
- process.exit(1);
740
- }
741
- }
742
- );
743
- preset.command("delete <name>").description("\u30D7\u30EA\u30BB\u30C3\u30C8\u3092\u524A\u9664").action(async (name) => {
744
- try {
745
- const deleted = await deletePreset(name);
746
- if (deleted) {
747
- console.log(`\u30D7\u30EA\u30BB\u30C3\u30C8 '${name}' \u3092\u524A\u9664\u3057\u307E\u3057\u305F\u3002`);
748
- } else {
749
- console.error(`\u30D7\u30EA\u30BB\u30C3\u30C8 '${name}' \u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002`);
750
- process.exit(1);
751
- }
752
- } catch (error) {
753
- if (error instanceof Error) {
754
- console.error("\u30A8\u30E9\u30FC:", error.message);
755
- } else {
756
- console.error("\u4E0D\u660E\u306A\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F");
757
- }
758
- process.exit(1);
759
- }
760
- });
761
- return preset;
762
- }
763
- function formatPreset(preset, indent) {
764
- if (preset.size) console.log(`${indent}\u30B5\u30A4\u30BA: ${preset.size}`);
765
- if (preset.quality) console.log(`${indent}\u54C1\u8CEA: ${preset.quality}`);
766
- if (preset.format) console.log(`${indent}\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8: ${preset.format}`);
767
- }
768
-
769
354
  // src/commands/index.ts
770
355
  function createMainCommand() {
771
- const program = new Command8().name("imgen").version("0.1.0").description("Azure OpenAI \u753B\u50CF\u751F\u6210\u30FB\u7DE8\u96C6\u30FB\u8AAC\u660E\u30C4\u30FC\u30EB - gpt-image-1.5 / gpt-5.1").addHelpText(
356
+ const program = new Command5().name("imgen").version("0.3.0").description("Azure OpenAI \u753B\u50CF\u751F\u6210\u30FB\u7DE8\u96C6\u30FB\u8AAC\u660E\u30C4\u30FC\u30EB - gpt-image-1.5 / gpt-5.1").addHelpText(
772
357
  "before",
773
358
  `
774
359
  \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557
@@ -784,22 +369,19 @@ function createMainCommand() {
784
369
  "after",
785
370
  `
786
371
  \u4F7F\u7528\u4F8B:
787
- $ imgen image gen "\u5915\u65E5\u306E\u6D77\u8FBA" -q high -t vivid
372
+ $ imgen image gen "\u5915\u65E5\u306E\u6D77\u8FBA" -q high -s 1536x1024
788
373
  $ imgen image gen "\u53EF\u611B\u3044\u732B" -s 1024x1024 -p builtin:square
789
374
  $ imgen image edit photo.png "\u80CC\u666F\u3092\u9752\u7A7A\u306B"
790
375
  $ imgen image explain screenshot.png -l en
791
376
 
792
377
  \u30AF\u30A4\u30C3\u30AF\u30B9\u30BF\u30FC\u30C8:
793
- 1. \u8A2D\u5B9A: imgen configure
378
+ 1. API\u30AD\u30FC\u3092\u8A2D\u5B9A: export AZURE_OPENAI_API_KEY="..."
794
379
  2. \u753B\u50CF\u751F\u6210: imgen image gen "\u30C6\u30FC\u30DE"
795
380
  `
796
381
  ).action(() => {
797
382
  program.help();
798
383
  });
799
384
  program.addCommand(imageCommand());
800
- program.addCommand(presetCommand());
801
- program.addCommand(configureCommand());
802
- program.addCommand(logCommand());
803
385
  return program;
804
386
  }
805
387