@nogataka/imgen 0.1.0 → 0.2.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/sdk.d.ts ADDED
@@ -0,0 +1,154 @@
1
+ type SupportedLanguage = "ja" | "en" | "zh" | "ko" | "es" | "fr" | "de" | "it" | "ru" | "vi";
2
+ declare const LANGUAGE_DESCRIPTIONS: Record<SupportedLanguage, string>;
3
+
4
+ type ImageSizeConfig = "1024x1024" | "1536x1024" | "1024x1536";
5
+ type ImageQualityConfig = "low" | "medium" | "high";
6
+ type ImageFormatConfig = "png" | "jpg" | "webp";
7
+ type LogLevelConfig = "debug" | "info" | "warn" | "error";
8
+ interface Config {
9
+ azureEndpoint?: string;
10
+ azureApiKey?: string;
11
+ azureDeploymentName?: string;
12
+ azureImageDeploymentName?: string;
13
+ azureApiVersion?: string;
14
+ azureImageApiVersion?: string;
15
+ defaultOutputDir?: string;
16
+ defaultLanguage?: SupportedLanguage;
17
+ defaultImageSize?: ImageSizeConfig;
18
+ defaultImageQuality?: ImageQualityConfig;
19
+ defaultImageFormat?: ImageFormatConfig;
20
+ logLevel?: LogLevelConfig;
21
+ }
22
+ declare const DEFAULT_CONFIG: {
23
+ defaultLanguage: SupportedLanguage;
24
+ defaultImageSize: ImageSizeConfig;
25
+ defaultImageQuality: ImageQualityConfig;
26
+ defaultImageFormat: ImageFormatConfig;
27
+ logLevel: LogLevelConfig;
28
+ };
29
+ interface AzureConfig {
30
+ endpoint: string;
31
+ apiKey: string;
32
+ deploymentName: string;
33
+ imageDeploymentName: string;
34
+ apiVersion: string;
35
+ imageApiVersion: string;
36
+ }
37
+ /**
38
+ * Loads the configuration from disk. Returns null if no config file exists.
39
+ */
40
+ declare function loadConfig(): Promise<Config | null>;
41
+ /**
42
+ * Saves the configuration to disk, creating the config directory if needed.
43
+ */
44
+ declare function saveConfig(config: Config): Promise<void>;
45
+ /**
46
+ * Resolves the full Azure OpenAI configuration from environment variables and
47
+ * the config file. Environment variables take precedence over file-based config.
48
+ * Throws if required fields (endpoint, apiKey, deploymentName, imageDeploymentName)
49
+ * are missing.
50
+ */
51
+ declare function getAzureConfig(): Promise<AzureConfig>;
52
+
53
+ type ImageSize = "1024x1024" | "1536x1024" | "1024x1536";
54
+ type ImageQuality = "low" | "medium" | "high";
55
+ interface GenerateImageOptions {
56
+ size?: ImageSize;
57
+ quality?: ImageQuality;
58
+ }
59
+ interface EditImageOptions {
60
+ size?: ImageSize;
61
+ }
62
+ /**
63
+ * Client for Azure OpenAI Image generation and editing.
64
+ * Uses the SDK (`AzureOpenAI`) for `generateImage` and the REST API directly
65
+ * for `editImage`, because the Azure SDK's img2img support is unreliable.
66
+ */
67
+ declare class AzureImageClient {
68
+ private client;
69
+ private config;
70
+ private logger;
71
+ constructor(config: AzureConfig);
72
+ /**
73
+ * Generates an image from a text prompt using the Azure OpenAI SDK.
74
+ * Returns raw image bytes as a Uint8Array.
75
+ */
76
+ generateImage(prompt: string, options: GenerateImageOptions): Promise<Uint8Array>;
77
+ /**
78
+ * Edits an existing image using the Azure OpenAI REST API.
79
+ * Uses fetch + FormData because the SDK's image editing support is unreliable.
80
+ * Returns raw image bytes as a Uint8Array.
81
+ */
82
+ editImage(imageBuffer: Buffer, prompt: string, options?: EditImageOptions): Promise<Uint8Array>;
83
+ }
84
+
85
+ interface ImageData {
86
+ data: string;
87
+ mimeType: string;
88
+ }
89
+ declare function readImageFile(filePath: string): Promise<ImageData>;
90
+ declare function getMimeType(filePath: string): string;
91
+
92
+ /**
93
+ * Client for Azure OpenAI Chat Completions API.
94
+ * Provides methods to generate image prompts, file names, and image explanations
95
+ * using a chat model (e.g. gpt-5.1).
96
+ */
97
+ declare class AzureChatClient {
98
+ private client;
99
+ private deploymentName;
100
+ private logger;
101
+ constructor(config: AzureConfig);
102
+ /**
103
+ * Generates a detailed image-generation prompt from a short theme description.
104
+ * Optionally accepts additional context to guide prompt generation.
105
+ */
106
+ generatePrompt(theme: string, context?: string): Promise<string>;
107
+ /**
108
+ * Generates a sanitized file name (lowercase alphanumeric + hyphens only) from a theme.
109
+ */
110
+ generateFileName(theme: string, maxLength?: number): Promise<string>;
111
+ /**
112
+ * Generates a detailed explanation of an image using multimodal (vision) input.
113
+ * The explanation language is controlled by the `lang` parameter.
114
+ */
115
+ generateExplanation(imageData: ImageData, lang?: string, context?: string): Promise<string>;
116
+ }
117
+
118
+ /**
119
+ * Represents a preset configuration for image generation.
120
+ */
121
+ interface ImagePreset {
122
+ size?: ImageSizeConfig;
123
+ quality?: ImageQualityConfig;
124
+ format?: ImageFormatConfig;
125
+ }
126
+ /**
127
+ * A dictionary of named presets.
128
+ */
129
+ interface Presets {
130
+ [name: string]: ImagePreset;
131
+ }
132
+ /**
133
+ * Built-in presets that ship with imgen.
134
+ */
135
+ declare const BUILTIN_PRESETS: Presets;
136
+ /**
137
+ * Retrieves a preset by name. Checks builtin presets first, then user-defined
138
+ * presets. Returns null if no preset with the given name is found.
139
+ */
140
+ declare function getPreset(name: string): Promise<ImagePreset | null>;
141
+ /**
142
+ * Lists all presets (builtin and user-defined), returning each with its name,
143
+ * preset configuration, and a flag indicating whether it is builtin.
144
+ */
145
+ declare function listAllPresets(): Promise<{
146
+ name: string;
147
+ preset: ImagePreset;
148
+ builtin: boolean;
149
+ }[]>;
150
+
151
+ declare function saveFileWithUniqueNameIfExists(outputPath: string, data: Uint8Array, maxRetries?: number): Promise<string>;
152
+ declare function fileExists(filePath: string): Promise<boolean>;
153
+
154
+ export { AzureChatClient, type AzureConfig, AzureImageClient, BUILTIN_PRESETS, type Config, DEFAULT_CONFIG, type EditImageOptions, type GenerateImageOptions, type ImageData, type ImageFormatConfig, type ImagePreset, type ImageQuality, type ImageQualityConfig, type ImageSize, type ImageSizeConfig, LANGUAGE_DESCRIPTIONS, type LogLevelConfig, type Presets, type SupportedLanguage, fileExists, getAzureConfig, getMimeType, getPreset, listAllPresets, loadConfig, readImageFile, saveConfig, saveFileWithUniqueNameIfExists };
package/dist/sdk.js ADDED
@@ -0,0 +1,32 @@
1
+ import {
2
+ AzureChatClient,
3
+ AzureImageClient,
4
+ BUILTIN_PRESETS,
5
+ DEFAULT_CONFIG,
6
+ LANGUAGE_DESCRIPTIONS,
7
+ fileExists,
8
+ getAzureConfig,
9
+ getMimeType,
10
+ getPreset,
11
+ listAllPresets,
12
+ loadConfig,
13
+ readImageFile,
14
+ saveConfig,
15
+ saveFileWithUniqueNameIfExists
16
+ } from "./chunk-HQT7ZTCY.js";
17
+ export {
18
+ AzureChatClient,
19
+ AzureImageClient,
20
+ BUILTIN_PRESETS,
21
+ DEFAULT_CONFIG,
22
+ LANGUAGE_DESCRIPTIONS,
23
+ fileExists,
24
+ getAzureConfig,
25
+ getMimeType,
26
+ getPreset,
27
+ listAllPresets,
28
+ loadConfig,
29
+ readImageFile,
30
+ saveConfig,
31
+ saveFileWithUniqueNameIfExists
32
+ };
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "@nogataka/imgen",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Azure OpenAI画像生成・編集・説明CLIツール - gpt-image-1.5 / gpt-5.1",
5
5
  "type": "module",
6
6
  "bin": { "imgen": "dist/index.js" },
7
7
  "main": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
9
- "exports": { ".": { "import": "./dist/index.js", "types": "./dist/index.d.ts" } },
9
+ "exports": {
10
+ ".": { "import": "./dist/index.js", "types": "./dist/index.d.ts" },
11
+ "./sdk": { "import": "./dist/sdk.js", "types": "./dist/sdk.d.ts" }
12
+ },
10
13
  "files": ["dist"],
11
14
  "publishConfig": { "access": "public" },
12
15
  "scripts": {
13
16
  "dev": "node --env-file=.env --import tsx src/index.ts",
14
- "build": "tsup src/index.ts --format esm --dts --clean",
17
+ "build": "tsup src/index.ts src/sdk.ts --format esm --dts --clean",
15
18
  "test": "vitest run",
16
19
  "test:watch": "vitest",
17
20
  "check": "tsc --noEmit",