dsh-pictor 0.1.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/LICENSE +21 -0
- package/README.md +81 -0
- package/agents/00.renderer.md +117 -0
- package/agents/10.orchestrator.md +191 -0
- package/agents/11.extractor.md +132 -0
- package/agents/12.advisor.md +151 -0
- package/assets/empty-state.png +0 -0
- package/assets/previews/layouts/bento-grid.webp +0 -0
- package/assets/previews/layouts/binary-comparison.webp +0 -0
- package/assets/previews/layouts/bridge.webp +0 -0
- package/assets/previews/layouts/circular-flow.webp +0 -0
- package/assets/previews/layouts/comic-strip.webp +0 -0
- package/assets/previews/layouts/comparison-matrix.webp +0 -0
- package/assets/previews/layouts/dashboard.webp +0 -0
- package/assets/previews/layouts/funnel.webp +0 -0
- package/assets/previews/layouts/geo-map.webp +0 -0
- package/assets/previews/layouts/hierarchical-layers.webp +0 -0
- package/assets/previews/layouts/hub-spoke.webp +0 -0
- package/assets/previews/layouts/iceberg.webp +0 -0
- package/assets/previews/layouts/isometric-map.webp +0 -0
- package/assets/previews/layouts/jigsaw.webp +0 -0
- package/assets/previews/layouts/linear-progression.webp +0 -0
- package/assets/previews/layouts/network-graph.webp +0 -0
- package/assets/previews/layouts/parallel-tracks.webp +0 -0
- package/assets/previews/layouts/periodic-table.webp +0 -0
- package/assets/previews/layouts/quadrant-matrix.webp +0 -0
- package/assets/previews/layouts/sankey-flow.webp +0 -0
- package/assets/previews/layouts/story-mountain.webp +0 -0
- package/assets/previews/layouts/structural-breakdown.webp +0 -0
- package/assets/previews/layouts/toulmin-argument.webp +0 -0
- package/assets/previews/layouts/tree-branching.webp +0 -0
- package/assets/previews/layouts/venn-diagram.webp +0 -0
- package/assets/previews/layouts/winding-roadmap.webp +0 -0
- package/assets/previews/styles/aged-academia.webp +0 -0
- package/assets/previews/styles/bandung-circuit.webp +0 -0
- package/assets/previews/styles/bold-graphic.webp +0 -0
- package/assets/previews/styles/chalkboard.webp +0 -0
- package/assets/previews/styles/claymation.webp +0 -0
- package/assets/previews/styles/clean-analytics.webp +0 -0
- package/assets/previews/styles/corporate-memphis.webp +0 -0
- package/assets/previews/styles/craft-handmade.webp +0 -0
- package/assets/previews/styles/cyberpunk-neon.webp +0 -0
- package/assets/previews/styles/ikea-manual.webp +0 -0
- package/assets/previews/styles/kawaii.webp +0 -0
- package/assets/previews/styles/knolling.webp +0 -0
- package/assets/previews/styles/lego-brick.webp +0 -0
- package/assets/previews/styles/mckinsey-report.webp +0 -0
- package/assets/previews/styles/origami.webp +0 -0
- package/assets/previews/styles/pixel-art.webp +0 -0
- package/assets/previews/styles/storybook-watercolor.webp +0 -0
- package/assets/previews/styles/subway-map.webp +0 -0
- package/assets/previews/styles/technical-schematic.webp +0 -0
- package/assets/previews/styles/tricon-infographic.webp +0 -0
- package/assets/previews/styles/ui-wireframe.webp +0 -0
- package/cordis.patch.yml +8 -0
- package/docs/DESIGN.zh.md +278 -0
- package/docs/verification-checklist.zh.md +64 -0
- package/lib/client.js +1724 -0
- package/lib/image-providers.js +195 -0
- package/lib/index.js +739 -0
- package/lib/render.js +28 -0
- package/package.json +80 -0
- package/references/domain/base-prompt.md +44 -0
- package/references/domain/diagram-types/_catalog.yaml +78 -0
- package/references/domain/diagram-types/debate-map.md +33 -0
- package/references/domain/diagram-types/evidence-radar.md +33 -0
- package/references/domain/diagram-types/geographic-map.md +33 -0
- package/references/domain/diagram-types/greimas-square.md +33 -0
- package/references/domain/diagram-types/landscape.md +33 -0
- package/references/domain/diagram-types/network-graph.md +35 -0
- package/references/domain/diagram-types/parallel-timeline.md +33 -0
- package/references/domain/diagram-types/quadrant.md +33 -0
- package/references/domain/diagram-types/sankey-flow.md +33 -0
- package/references/domain/diagram-types/stakeholder-matrix.md +31 -0
- package/references/domain/diagram-types/toulmin-diagram.md +35 -0
- package/references/domain/layouts/bento-grid.md +41 -0
- package/references/domain/layouts/binary-comparison.md +48 -0
- package/references/domain/layouts/bridge.md +41 -0
- package/references/domain/layouts/circular-flow.md +41 -0
- package/references/domain/layouts/comic-strip.md +41 -0
- package/references/domain/layouts/comparison-matrix.md +41 -0
- package/references/domain/layouts/dashboard.md +41 -0
- package/references/domain/layouts/funnel.md +41 -0
- package/references/domain/layouts/geo-map.md +82 -0
- package/references/domain/layouts/hierarchical-layers.md +48 -0
- package/references/domain/layouts/hub-spoke.md +41 -0
- package/references/domain/layouts/iceberg.md +41 -0
- package/references/domain/layouts/isometric-map.md +41 -0
- package/references/domain/layouts/jigsaw.md +41 -0
- package/references/domain/layouts/linear-progression.md +48 -0
- package/references/domain/layouts/network-graph.md +42 -0
- package/references/domain/layouts/parallel-tracks.md +49 -0
- package/references/domain/layouts/periodic-table.md +41 -0
- package/references/domain/layouts/quadrant-matrix.md +93 -0
- package/references/domain/layouts/sankey-flow.md +97 -0
- package/references/domain/layouts/story-mountain.md +41 -0
- package/references/domain/layouts/structural-breakdown.md +48 -0
- package/references/domain/layouts/toulmin-argument.md +113 -0
- package/references/domain/layouts/tree-branching.md +41 -0
- package/references/domain/layouts/venn-diagram.md +41 -0
- package/references/domain/layouts/winding-roadmap.md +41 -0
- package/references/domain/styles/aged-academia.md +36 -0
- package/references/domain/styles/bandung-circuit.md +82 -0
- package/references/domain/styles/bold-graphic.md +36 -0
- package/references/domain/styles/chalkboard.md +61 -0
- package/references/domain/styles/claymation.md +29 -0
- package/references/domain/styles/clean-analytics.md +78 -0
- package/references/domain/styles/corporate-memphis.md +29 -0
- package/references/domain/styles/craft-handmade.md +44 -0
- package/references/domain/styles/cyberpunk-neon.md +29 -0
- package/references/domain/styles/ikea-manual.md +29 -0
- package/references/domain/styles/kawaii.md +29 -0
- package/references/domain/styles/knolling.md +29 -0
- package/references/domain/styles/lego-brick.md +29 -0
- package/references/domain/styles/mckinsey-report.md +83 -0
- package/references/domain/styles/origami.md +29 -0
- package/references/domain/styles/pixel-art.md +29 -0
- package/references/domain/styles/storybook-watercolor.md +29 -0
- package/references/domain/styles/subway-map.md +29 -0
- package/references/domain/styles/technical-schematic.md +36 -0
- package/references/domain/styles/tricon-infographic.md +54 -0
- package/references/domain/styles/ui-wireframe.md +29 -0
- package/references/domain/visual-principles.md +63 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
function isPlainObject(v) {
|
|
2
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
3
|
+
}
|
|
4
|
+
function deepMerge(target, patch) {
|
|
5
|
+
for (const k of Object.keys(patch || {})) {
|
|
6
|
+
if (isPlainObject(patch[k]) && isPlainObject(target[k])) deepMerge(target[k], patch[k]);
|
|
7
|
+
else target[k] = patch[k];
|
|
8
|
+
}
|
|
9
|
+
return target;
|
|
10
|
+
}
|
|
11
|
+
class GeminiProvider {
|
|
12
|
+
constructor(cfg = {}) {
|
|
13
|
+
this.cfg = cfg;
|
|
14
|
+
}
|
|
15
|
+
cfg;
|
|
16
|
+
name = "gemini";
|
|
17
|
+
async generateImage(prompt) {
|
|
18
|
+
if (!this.cfg.apiKey) throw new Error("\u751F\u56FE\u914D\u7F6E\u7F3A\u5C11 apiKey");
|
|
19
|
+
const model = this.cfg.model || "gemini-3-pro-image-preview";
|
|
20
|
+
const baseUrl = this.cfg.baseUrl || "https://generativelanguage.googleapis.com";
|
|
21
|
+
const url = `${baseUrl}/v1beta/models/${model}:generateContent`;
|
|
22
|
+
const body = {
|
|
23
|
+
contents: [{ role: "user", parts: [{ text: prompt }] }],
|
|
24
|
+
generationConfig: { responseModalities: ["IMAGE"], imageConfig: { imageSize: "1K" } }
|
|
25
|
+
};
|
|
26
|
+
deepMerge(body, this.cfg.extra);
|
|
27
|
+
const res = await fetch(url, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: { "Content-Type": "application/json", "x-goog-api-key": this.cfg.apiKey },
|
|
30
|
+
body: JSON.stringify(body)
|
|
31
|
+
});
|
|
32
|
+
if (!res.ok) throw new Error(`Gemini API error (${res.status}): ${await res.text()}`);
|
|
33
|
+
const json = await res.json();
|
|
34
|
+
for (const candidate of json.candidates || []) {
|
|
35
|
+
for (const part of candidate.content?.parts || []) {
|
|
36
|
+
if (part.inlineData?.data) {
|
|
37
|
+
return { data: part.inlineData.data, mimeType: part.inlineData.mimeType || "image/png" };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const SEEDREAM_SIZE_MAP = {
|
|
45
|
+
"16:9": "2560x1440",
|
|
46
|
+
"4:3": "2304x1728",
|
|
47
|
+
"3:4": "1728x2304",
|
|
48
|
+
"9:16": "1440x2560",
|
|
49
|
+
"1:1": "2K"
|
|
50
|
+
};
|
|
51
|
+
class SeedreamProvider {
|
|
52
|
+
constructor(cfg = {}) {
|
|
53
|
+
this.cfg = cfg;
|
|
54
|
+
}
|
|
55
|
+
cfg;
|
|
56
|
+
name = "seedream";
|
|
57
|
+
async generateImage(prompt, aspectRatio = "16:9") {
|
|
58
|
+
if (!this.cfg.apiKey) throw new Error("\u751F\u56FE\u914D\u7F6E\u7F3A\u5C11 apiKey");
|
|
59
|
+
const model = this.cfg.model || "doubao-seedream-4-5-251128";
|
|
60
|
+
const baseUrl = this.cfg.baseUrl || "https://ark.cn-beijing.volces.com/api/v3";
|
|
61
|
+
const size = SEEDREAM_SIZE_MAP[aspectRatio] || "2K";
|
|
62
|
+
const body = { model, prompt, size, response_format: "b64_json", watermark: false };
|
|
63
|
+
deepMerge(body, this.cfg.extra);
|
|
64
|
+
const res = await fetch(`${baseUrl}/images/generations`, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.cfg.apiKey}` },
|
|
67
|
+
body: JSON.stringify(body)
|
|
68
|
+
});
|
|
69
|
+
if (!res.ok) throw new Error(`Seedream API error (${res.status}): ${await res.text()}`);
|
|
70
|
+
const json = await res.json();
|
|
71
|
+
const first = json.data?.[0];
|
|
72
|
+
if (!first?.b64_json) return null;
|
|
73
|
+
return { data: first.b64_json, mimeType: "image/png" };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const OPENAI_SIZE_MAP = {
|
|
77
|
+
"16:9": "1792x1024",
|
|
78
|
+
"4:3": "1536x1152",
|
|
79
|
+
"3:4": "1152x1536",
|
|
80
|
+
"9:16": "1024x1792",
|
|
81
|
+
"1:1": "1024x1024"
|
|
82
|
+
};
|
|
83
|
+
class OpenAICompatibleProvider {
|
|
84
|
+
constructor(cfg = {}) {
|
|
85
|
+
this.cfg = cfg;
|
|
86
|
+
}
|
|
87
|
+
cfg;
|
|
88
|
+
name = "openai-compatible";
|
|
89
|
+
async generateImage(prompt, aspectRatio = "16:9") {
|
|
90
|
+
if (!this.cfg.apiKey) throw new Error("\u751F\u56FE\u914D\u7F6E\u7F3A\u5C11 apiKey");
|
|
91
|
+
if (!this.cfg.baseUrl || !this.cfg.model) throw new Error("openai-compatible \u914D\u7F6E\u9700\u8981 baseUrl \u4E0E model");
|
|
92
|
+
const size = OPENAI_SIZE_MAP[aspectRatio] || "1024x1024";
|
|
93
|
+
const url = this.cfg.baseUrl.replace(/\/$/, "") + "/images/generations";
|
|
94
|
+
const body = { model: this.cfg.model, prompt, size, response_format: "b64_json" };
|
|
95
|
+
deepMerge(body, this.cfg.extra);
|
|
96
|
+
const res = await fetch(url, {
|
|
97
|
+
method: "POST",
|
|
98
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.cfg.apiKey}` },
|
|
99
|
+
body: JSON.stringify(body)
|
|
100
|
+
});
|
|
101
|
+
if (!res.ok) throw new Error(`Image API error (${res.status}): ${await res.text()}`);
|
|
102
|
+
const json = await res.json();
|
|
103
|
+
const first = json.data?.[0];
|
|
104
|
+
if (!first?.b64_json) return null;
|
|
105
|
+
return { data: first.b64_json, mimeType: "image/png" };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const DASHSCOPE_SIZE_MAP = {
|
|
109
|
+
"16:9": "1440*810",
|
|
110
|
+
"4:3": "1280*960",
|
|
111
|
+
"3:4": "960*1280",
|
|
112
|
+
"9:16": "810*1440",
|
|
113
|
+
"1:1": "1024*1024"
|
|
114
|
+
};
|
|
115
|
+
class DashScopeProvider {
|
|
116
|
+
constructor(cfg = {}) {
|
|
117
|
+
this.cfg = cfg;
|
|
118
|
+
}
|
|
119
|
+
cfg;
|
|
120
|
+
name = "dashscope";
|
|
121
|
+
async generateImage(prompt, aspectRatio = "16:9") {
|
|
122
|
+
if (!this.cfg.apiKey) throw new Error("\u751F\u56FE\u914D\u7F6E\u7F3A\u5C11 apiKey");
|
|
123
|
+
const model = this.cfg.model || "qwen-image-3.0-pro";
|
|
124
|
+
const base = this.cfg.baseUrl || "https://dashscope.aliyuncs.com/api/v1";
|
|
125
|
+
const size = DASHSCOPE_SIZE_MAP[aspectRatio] || "1024*1024";
|
|
126
|
+
const url = base.replace(/\/$/, "") + "/services/aigc/multimodal-generation/generation";
|
|
127
|
+
const parameters = { size, prompt_extend: true, watermark: false };
|
|
128
|
+
const body = {
|
|
129
|
+
model,
|
|
130
|
+
input: { messages: [{ role: "user", content: [{ type: "text", text: prompt }] }] },
|
|
131
|
+
parameters
|
|
132
|
+
};
|
|
133
|
+
deepMerge(body, this.cfg.extra);
|
|
134
|
+
const res = await fetch(url, {
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers: {
|
|
137
|
+
"content-type": "application/json",
|
|
138
|
+
authorization: `Bearer ${this.cfg.apiKey}`,
|
|
139
|
+
"x-dashscope-async": "disable"
|
|
140
|
+
// 同步返回结果,免轮询
|
|
141
|
+
},
|
|
142
|
+
body: JSON.stringify(body)
|
|
143
|
+
});
|
|
144
|
+
if (!res.ok) throw new Error(`DashScope API error (${res.status}): ${await res.text()}`);
|
|
145
|
+
const json = await res.json();
|
|
146
|
+
const choices = json?.output?.choices;
|
|
147
|
+
if (!Array.isArray(choices) || !choices.length) return null;
|
|
148
|
+
for (const ch of choices) {
|
|
149
|
+
const content = ch?.message?.content;
|
|
150
|
+
if (!Array.isArray(content)) continue;
|
|
151
|
+
for (const block of content) {
|
|
152
|
+
if (!block) continue;
|
|
153
|
+
if (block.b64_image) return { data: String(block.b64_image), mimeType: "image/png" };
|
|
154
|
+
if (block.image) {
|
|
155
|
+
const img = await fetch(String(block.image));
|
|
156
|
+
if (!img.ok) throw new Error("DashScope image download failed");
|
|
157
|
+
const buf = Buffer.from(await img.arrayBuffer());
|
|
158
|
+
return { data: buf.toString("base64"), mimeType: "image/png" };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const MOCK_1PX_PNG = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==";
|
|
166
|
+
class MockProvider {
|
|
167
|
+
name = "mock";
|
|
168
|
+
async generateImage() {
|
|
169
|
+
return { data: MOCK_1PX_PNG, mimeType: "image/png" };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function createImageProvider(name, cfg) {
|
|
173
|
+
switch (name) {
|
|
174
|
+
case "gemini":
|
|
175
|
+
return new GeminiProvider(cfg);
|
|
176
|
+
case "seedream":
|
|
177
|
+
return new SeedreamProvider(cfg);
|
|
178
|
+
case "openai-compatible":
|
|
179
|
+
return new OpenAICompatibleProvider(cfg);
|
|
180
|
+
case "dashscope":
|
|
181
|
+
return new DashScopeProvider(cfg);
|
|
182
|
+
case "mock":
|
|
183
|
+
return new MockProvider();
|
|
184
|
+
default:
|
|
185
|
+
throw new Error(`\u672A\u77E5\u751F\u56FE provider: ${name}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
export {
|
|
189
|
+
DashScopeProvider,
|
|
190
|
+
GeminiProvider,
|
|
191
|
+
MockProvider,
|
|
192
|
+
OpenAICompatibleProvider,
|
|
193
|
+
SeedreamProvider,
|
|
194
|
+
createImageProvider
|
|
195
|
+
};
|