dsh-mo-image 0.6.0 → 1.0.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/CHANGELOG.md +39 -0
- package/README.md +328 -55
- package/icon.png +0 -0
- package/lib/adapter-kit.js +289 -40
- package/lib/adapters/async.js +354 -140
- package/lib/adapters/cn.js +133 -68
- package/lib/adapters/openai.js +193 -143
- package/lib/adapters.js +3579 -695
- package/lib/client.js +6742 -828
- package/lib/comfy-workflow.js +100 -10
- package/lib/config-store.js +1628 -0
- package/lib/field-templates.js +385 -0
- package/lib/image-execution.js +58 -0
- package/lib/image-jobs.js +344 -0
- package/lib/image-queue.js +195 -0
- package/lib/image-request.js +830 -0
- package/lib/image-service.js +189 -0
- package/lib/image-worker.js +208 -0
- package/lib/index.js +1054 -967
- package/lib/localized-error.js +4 -0
- package/lib/model-rules.js +1034 -0
- package/lib/net.js +60 -25
- package/lib/output-profiles.js +1225 -0
- package/lib/png-scale.js +150 -68
- package/lib/prompt-profiles.js +196 -80
- package/lib/provider-operations.js +291 -0
- package/lib/proxy-dispatcher.js +11 -5
- package/lib/proxy.js +10 -8
- package/lib/request-auth.js +198 -0
- package/lib/retry.js +162 -0
- package/lib/settings-memory.js +117 -0
- package/lib/status.js +190 -0
- package/locale/messages.csv +206 -24
- package/package.json +3 -1
- package/scripts/release.mjs +79 -64
- package/skills/mo-image-editing/SKILL.md +36 -80
- package/skills/mo-image-generation/SKILL.md +62 -154
package/lib/net.js
CHANGED
|
@@ -33,7 +33,15 @@ function dispatcherFor(proxyUrl) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
function hostOf(url) {
|
|
36
|
-
try { return new URL(String(url)).host ||
|
|
36
|
+
try { return new URL(String(url)).host || '未知主机'; } catch (_error) { return '未知主机'; }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function proxyEndpointOf(proxyUrl) {
|
|
40
|
+
try {
|
|
41
|
+
const url = new URL(proxyUrl);
|
|
42
|
+
if (url.host) return url.protocol + '//' + url.host;
|
|
43
|
+
} catch (_error) { /* malformed input can contain credentials */ }
|
|
44
|
+
return '代理地址不可用';
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
export async function resolveRequestProxy(url, options = {}) {
|
|
@@ -54,6 +62,21 @@ function causeCode(error) {
|
|
|
54
62
|
return '';
|
|
55
63
|
}
|
|
56
64
|
|
|
65
|
+
const PROXY_ERROR_NAMES = new Set(['Error', 'TypeError', 'RangeError', 'URIError', 'AbortError', 'TimeoutError']);
|
|
66
|
+
|
|
67
|
+
// Preserve metadata used for retry and timeout decisions. A proxy/transport can
|
|
68
|
+
// echo credentials in arbitrary messages or extra properties on the original error.
|
|
69
|
+
function safeProxyCause(error, depth = 0) {
|
|
70
|
+
if (!error || depth >= 5) return undefined;
|
|
71
|
+
const name = PROXY_ERROR_NAMES.has(error.name) ? error.name : 'Error';
|
|
72
|
+
const code = error.code;
|
|
73
|
+
const validCode = (typeof code === 'string' || typeof code === 'number') && /^[A-Z0-9_]{1,80}$/.test(String(code));
|
|
74
|
+
const safe = new Error(validCode ? String(code) : name, { cause: safeProxyCause(error.cause, depth + 1) });
|
|
75
|
+
safe.name = name;
|
|
76
|
+
if (validCode) safe.code = code;
|
|
77
|
+
return safe;
|
|
78
|
+
}
|
|
79
|
+
|
|
57
80
|
const HINTS = {
|
|
58
81
|
UND_ERR_CONNECT_TIMEOUT: 'TCP 连接超时',
|
|
59
82
|
UND_ERR_HEADERS_TIMEOUT: '等待响应头超时',
|
|
@@ -85,13 +108,23 @@ const HINT_KINDS = {
|
|
|
85
108
|
DEPTH_ZERO_SELF_SIGNED_CERT: 'tls'
|
|
86
109
|
};
|
|
87
110
|
|
|
88
|
-
|
|
111
|
+
function networkDiagnostic(error, url, decision) {
|
|
89
112
|
const host = hostOf(url);
|
|
90
|
-
const
|
|
113
|
+
const proxied = Boolean(decision?.proxyUrl);
|
|
114
|
+
const cause = proxied ? safeProxyCause(error) : error;
|
|
115
|
+
const code = causeCode(cause);
|
|
116
|
+
const detail = code || (proxied ? '代理请求失败' : cause?.message || '');
|
|
117
|
+
return { host, proxied, cause, code, detail };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function describeDiagnostic({ host, proxied, code, detail }) {
|
|
91
121
|
const hint = HINTS[code] || '';
|
|
92
|
-
const via =
|
|
93
|
-
|
|
94
|
-
|
|
122
|
+
const via = proxied ? '经系统网络配置' : '直连';
|
|
123
|
+
return '网络请求失败:' + host + ' ' + (detail || '未知错误') + ',' + via + '。' + (hint ? hint + '。' : '');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function describeNetworkError(error, url, decision) {
|
|
127
|
+
return describeDiagnostic(networkDiagnostic(error, url, decision));
|
|
95
128
|
}
|
|
96
129
|
|
|
97
130
|
/**
|
|
@@ -99,14 +132,13 @@ export function describeNetworkError(error, url, decision) {
|
|
|
99
132
|
* code/params 让设置页按当前语言重写整句。
|
|
100
133
|
*/
|
|
101
134
|
export function networkFailure(error, url, decision) {
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
const wrapped = new Error(describeNetworkError(error, url, decision), { cause: error });
|
|
135
|
+
const diagnostic = networkDiagnostic(error, url, decision);
|
|
136
|
+
const wrapped = new Error(describeDiagnostic(diagnostic), { cause: diagnostic.cause });
|
|
105
137
|
return localizedError(wrapped, 'network.failed', {
|
|
106
|
-
host: host,
|
|
107
|
-
cause:
|
|
108
|
-
via:
|
|
109
|
-
hint: HINT_KINDS[code] || ''
|
|
138
|
+
host: diagnostic.host,
|
|
139
|
+
cause: diagnostic.detail,
|
|
140
|
+
via: diagnostic.proxied ? 'proxy' : 'direct',
|
|
141
|
+
hint: HINT_KINDS[diagnostic.code] || ''
|
|
110
142
|
});
|
|
111
143
|
}
|
|
112
144
|
|
|
@@ -128,26 +160,29 @@ export async function request(url, init = {}, options = {}) {
|
|
|
128
160
|
}
|
|
129
161
|
}
|
|
130
162
|
|
|
131
|
-
const dispatcher = (() => {
|
|
132
|
-
try {
|
|
133
|
-
return dispatcherFor(decision.proxyUrl);
|
|
134
|
-
} catch (error) {
|
|
135
|
-
throw localizedError(new Error('网络连接配置无效:' + (error && error.message ? error.message : error)), 'network.routeInvalid');
|
|
136
|
-
}
|
|
137
|
-
})();
|
|
138
163
|
const host = hostOf(url);
|
|
139
|
-
const
|
|
164
|
+
const endpoint = proxyEndpointOf(decision.proxyUrl);
|
|
165
|
+
const source = '(来源 ' + decision.source + ')';
|
|
166
|
+
let dispatcher;
|
|
167
|
+
try {
|
|
168
|
+
dispatcher = dispatcherFor(decision.proxyUrl);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
logLine('network: ' + host + ' 的代理配置无效 ' + endpoint + source);
|
|
171
|
+
throw localizedError(new Error('网络连接配置无效:' + error.message), 'network.routeInvalid');
|
|
172
|
+
}
|
|
173
|
+
const key = endpoint + '|' + decision.source + '|' + host;
|
|
140
174
|
if (!loggedHosts.has(key)) {
|
|
141
175
|
loggedHosts.add(key);
|
|
142
|
-
logLine('network: ' + host + ' 走代理 ' +
|
|
176
|
+
logLine('network: ' + host + ' 走代理 ' + endpoint + source);
|
|
143
177
|
}
|
|
144
178
|
|
|
145
179
|
try {
|
|
146
180
|
return await fetch(url, Object.assign({}, fetchInit, { dispatcher: dispatcher }));
|
|
147
181
|
} catch (error) {
|
|
148
|
-
if (error
|
|
149
|
-
|
|
150
|
-
|
|
182
|
+
if (error?.name === 'AbortError') throw localizedError(safeProxyCause(error), 'network.timeout', { host });
|
|
183
|
+
const failure = networkFailure(error, url, decision);
|
|
184
|
+
logLine('network: ' + host + ' 经代理 ' + endpoint + source + ' 失败:' + failure.localized.params.cause);
|
|
185
|
+
throw failure;
|
|
151
186
|
}
|
|
152
187
|
}
|
|
153
188
|
|