@dsh-plus/image-studio 0.1.5 → 0.1.6
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/lib/index.d.ts +1 -0
- package/lib/index.js +7 -2
- package/package.json +2 -2
- package/src/client/client.ts +2 -1
- package/src/dto.ts +4 -0
- package/src/provider/openai-images.ts +9 -5
- package/src/provider/registry.ts +1 -1
- package/src/service.ts +3 -0
package/lib/index.d.ts
CHANGED
|
@@ -165,6 +165,7 @@ declare class ImageStudioService extends Service {
|
|
|
165
165
|
private current;
|
|
166
166
|
private readonly runner;
|
|
167
167
|
private readonly log;
|
|
168
|
+
private settingsRef;
|
|
168
169
|
constructor(ctx: Context, config: ImageStudioConfig);
|
|
169
170
|
/** 配置热更:并发上限即时生效(进行中任务不受影响)。 */
|
|
170
171
|
private applyConfig;
|
package/lib/index.js
CHANGED
|
@@ -355,7 +355,9 @@ function buildGenerationBody(request) {
|
|
|
355
355
|
/** 构造 edits multipart 请求体(纯函数;image 官方上限 ≤16 张由边界校验)。 */
|
|
356
356
|
function buildEditBody(request) {
|
|
357
357
|
const chunks = [];
|
|
358
|
-
const pushText = (text) =>
|
|
358
|
+
const pushText = (text) => {
|
|
359
|
+
chunks.push(Buffer.from(text, "utf8"));
|
|
360
|
+
};
|
|
359
361
|
pushText(formField("model", request.target.model));
|
|
360
362
|
pushText(formField("prompt", request.prompt));
|
|
361
363
|
pushText(formField("n", String(request.n)));
|
|
@@ -478,7 +480,10 @@ function upstreamErrorMessage(raw) {
|
|
|
478
480
|
try {
|
|
479
481
|
const doc = JSON.parse(trimmed);
|
|
480
482
|
if (typeof doc.error === "string" && doc.error.length > 0) return doc.error;
|
|
481
|
-
if (typeof doc.error
|
|
483
|
+
if (typeof doc.error === "object" && doc.error !== null) {
|
|
484
|
+
const message = doc.error.message;
|
|
485
|
+
if (typeof message === "string" && message.length > 0) return message;
|
|
486
|
+
}
|
|
482
487
|
if (typeof doc.message === "string" && doc.message.length > 0) return doc.message;
|
|
483
488
|
} catch {}
|
|
484
489
|
return trimmed.slice(0, 300);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-plus/image-studio",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "dsh-plus service+ui plugin: 图像工作室——OpenAI Images 协议文生图/图生图,全参数开关化,双预设体系,并发生图任务与可二次编辑画廊",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"https-proxy-agent": "^9.1.0",
|
|
23
|
-
"@dsh-plus/shared": "0.1.
|
|
23
|
+
"@dsh-plus/shared": "0.1.15"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@deepseek-ai/cordis": "^4.0.2",
|
package/src/client/client.ts
CHANGED
|
@@ -32,7 +32,8 @@ export const inject = ['slots', 'locale', 'remote', 'remote.settings'] as const
|
|
|
32
32
|
const PLUGIN_ID = '@dsh-plus/image-studio'
|
|
33
33
|
|
|
34
34
|
interface SlotsLike {
|
|
35
|
-
inject
|
|
35
|
+
/** 官方 slots 服务:回调返回 disposer;inject 返回等待/生效 effect 的幂等 disposer。 */
|
|
36
|
+
inject(key: string, callback: () => unknown): () => void
|
|
36
37
|
register(options: Record<string, unknown>, component: unknown): () => void
|
|
37
38
|
}
|
|
38
39
|
|
package/src/dto.ts
CHANGED
|
@@ -9,6 +9,10 @@ import type { GalleryItem } from './gallery/store.ts'
|
|
|
9
9
|
import type { ImageEndpoint } from './provider/types.ts'
|
|
10
10
|
import type { TaskState } from './task/runner.ts'
|
|
11
11
|
|
|
12
|
+
// GalleryItem 由 gallery/store 定义,但属 wire 视图的一部分(GalleryListWire 及
|
|
13
|
+
// 客户端半 fetchGalleryItem 都用它);在此转出,dto 保持「前后端共享类型单一门面」。
|
|
14
|
+
export type { GalleryItem }
|
|
15
|
+
|
|
12
16
|
/** 任务提交请求体。 */
|
|
13
17
|
export interface GenerateRequest {
|
|
14
18
|
/** 提供商预设 id 与 inline 二选一(都传时 inline 优先)。 */
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* 开发测试指向本地 mock,严禁真实调用产生费用。
|
|
7
7
|
* @module image-studio/provider/openai-images
|
|
8
8
|
*/
|
|
9
|
-
import { request as httpRequest } from 'node:http'
|
|
10
|
-
import { request as httpsRequest
|
|
9
|
+
import { request as httpRequest, type IncomingMessage } from 'node:http'
|
|
10
|
+
import { request as httpsRequest } from 'node:https'
|
|
11
11
|
import { HttpsProxyAgent } from 'https-proxy-agent'
|
|
12
12
|
import type { GeneratedImage, InputImage, NormalizedRequest, ProviderResult } from './types.ts'
|
|
13
13
|
import { ProviderError } from './types.ts'
|
|
@@ -74,7 +74,9 @@ export function buildEditBody(request: NormalizedRequest): {
|
|
|
74
74
|
body: Buffer
|
|
75
75
|
} {
|
|
76
76
|
const chunks: Buffer[] = []
|
|
77
|
-
const pushText = (text: string): void =>
|
|
77
|
+
const pushText = (text: string): void => {
|
|
78
|
+
chunks.push(Buffer.from(text, 'utf8'))
|
|
79
|
+
}
|
|
78
80
|
pushText(formField('model', request.target.model))
|
|
79
81
|
pushText(formField('prompt', request.prompt))
|
|
80
82
|
pushText(formField('n', String(request.n)))
|
|
@@ -246,8 +248,10 @@ function upstreamErrorMessage(raw: string): string {
|
|
|
246
248
|
message?: string
|
|
247
249
|
}
|
|
248
250
|
if (typeof doc.error === 'string' && doc.error.length > 0) return doc.error
|
|
249
|
-
|
|
250
|
-
|
|
251
|
+
// error 是 string | { message? } 联合:先收窄到对象再读 message(直接访问不合法)。
|
|
252
|
+
if (typeof doc.error === 'object' && doc.error !== null) {
|
|
253
|
+
const message = doc.error.message
|
|
254
|
+
if (typeof message === 'string' && message.length > 0) return message
|
|
251
255
|
}
|
|
252
256
|
if (typeof doc.message === 'string' && doc.message.length > 0) return doc.message
|
|
253
257
|
} catch {
|
package/src/provider/registry.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { ImageStudioError } from '../errors.ts'
|
|
7
7
|
import { generateViaOpenAIImages } from './openai-images.ts'
|
|
8
|
-
import type { ImageEndpoint, ImageProvider, NormalizedRequest } from './types.ts'
|
|
8
|
+
import type { ImageEndpoint, ImageProvider, NormalizedRequest, ProviderResult } from './types.ts'
|
|
9
9
|
|
|
10
10
|
type GenerateFn = (request: NormalizedRequest, signal: AbortSignal) => Promise<ProviderResult>
|
|
11
11
|
|
package/src/service.ts
CHANGED
|
@@ -74,6 +74,9 @@ export class ImageStudioService extends Service {
|
|
|
74
74
|
private current: () => ImageStudioConfig
|
|
75
75
|
private readonly runner: TaskRunner<TaskSnapshot>
|
|
76
76
|
private readonly log: (message: string) => void
|
|
77
|
+
// settings 服务窄面(settingsCtx.inject 回调内落存)。declare:不参与类字段
|
|
78
|
+
// 初始化 emit,保持实例运行期形状与既有产物一致(不因声明而多出 undefined 字段)。
|
|
79
|
+
private declare settingsRef: SettingsLike | undefined
|
|
77
80
|
|
|
78
81
|
constructor(ctx: ContextT, config: ImageStudioConfig) {
|
|
79
82
|
super(ctx, 'imageStudio')
|