dsh-mo-image 1.0.3 → 1.0.5
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 +10 -0
- package/README.md +3 -3
- package/lib/client.js +103 -34
- package/lib/config-store.js +2 -4
- package/lib/index.js +42 -8
- package/locale/messages.csv +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## v1.0.5
|
|
4
|
+
|
|
5
|
+
- **选择协议更方便。** 点击「更多协议…」会直接展开完整列表。选择「自定义」后,文生图、图生图和获取模型列表的地址都紧跟在协议下方。
|
|
6
|
+
- **文生图和图生图的返回格式可以分别设置。** 自定义协议下,填写了地址的操作需要选择返回格式才能保存。只用文生图时,图生图的地址和返回格式可以留空。
|
|
7
|
+
- **自定义 JSON 更容易填写。** 两个输入框各有自己的标签,并提供 OpenAI Images 示例,说明如何从接口返回中取出图片。
|
|
8
|
+
|
|
9
|
+
## v1.0.4
|
|
10
|
+
|
|
11
|
+
- **加强设置、更新和图片预览的访问保护。** 这些功能现在会先验证 DSH 登录状态。登录后,旧聊天里的预览图片仍可打开。
|
|
12
|
+
|
|
3
13
|
## v1.0.3
|
|
4
14
|
|
|
5
15
|
- **更新优化:** 设置页中的自动更新按钮UI优化,自动更新时默认使用国内源。
|
package/README.md
CHANGED
|
@@ -92,7 +92,7 @@ npm run release -- minor --dry-run # 只看会做什么
|
|
|
92
92
|
|
|
93
93
|
「模型目录」沿用 DSH 对话模型设置页的模型行:拖动手柄(或聚焦手柄后按上下方向键)调整顺序,顺序就是选择器里的顺序;「获取可用模型」会把上游列出的模型连同显示名一起带回来,已加入列表的模型默认勾选,勾选结果就是新的模型列表。
|
|
94
94
|
|
|
95
|
-
**编辑已有提供商**与**新建**用的是同一套表单布局(同一段代码,差异用参数表达)。新建的三条入口保持各自的样子:「第三方模型提供商」是预设选择器 + API 密钥常显;「本地模型」是部署器 + 显示名称 + API 密钥常显;「自定义模型 API」把全部字段一次平铺(显示名称 → API 地址 → 密钥 →
|
|
95
|
+
**编辑已有提供商**与**新建**用的是同一套表单布局(同一段代码,差异用参数表达)。新建的三条入口保持各自的样子:「第三方模型提供商」是预设选择器 + API 密钥常显;「本地模型」是部署器 + 显示名称 + API 密钥常显;「自定义模型 API」把全部字段一次平铺(显示名称 → API 地址 → 密钥 → 协议设置 → 模型目录与调度模型)。**编辑已有提供商**只常显 **API 密钥**,其余字段收进默认关闭的「自定义设置」折叠区。API 协议选择「自定义」时,文生图、图生图和获取模型列表的端点紧跟在协议下方。
|
|
96
96
|
|
|
97
97
|
**从内置预设建的提供商不显示协议相关字段**:协议、鉴权与返回格式预设里已经写好了,零配置就能用,不需要人去改一个已经正确的配置。自己填地址的(「自定义模型 API」、中转站、老配置)形状未知,这一块照旧出现。判据只看来源(`presetId`),不看地址;手改 API 地址不动它——同一家提供商换个地址(反向代理、私有化部署)仍是那份预设。老配置没记来源时先按协议分组:组内只有一份就是它(本地部署器就是这样,换端口、换机器仍认得出),共用协议的那一组(`openai-images` 那 14 份)再按地址、按名称消歧;没记协议(`adapter` 为空)的则在全部预设里按地址认,地址认不出再按名称认,都唯一不了就不补。补不上时,只有「地址是预设的、协议却不是预设里的那一条」这种本该有来源的配置会在表单顶部看到红字;「自定义模型 API」入口、自定义端点和自定义协议都不提醒——它们本来就没有预设来源。以前手动改过的协议 / 鉴权 / 返回格式只是不显示,保存时原样带回。
|
|
98
98
|
|
|
@@ -217,7 +217,7 @@ $DSH_HOME/mo-image/out/
|
|
|
217
217
|
|
|
218
218
|
聊天里新生成的图片使用本地文件绝对路径,支持本地图片菜单的 DSH 客户端可以通过宿主读取原图、复制图片并在桌面文件夹中定位。找不到会话目录,或图片超过宿主的本地预览上限时,使用签名预览。
|
|
219
219
|
|
|
220
|
-
|
|
220
|
+
登录 DSH 后,旧聊天中的 `/api/mo-image/preview/<basename>` 和签名预览链接都可用。HMAC 签名 key 保存在 `$DSH_HOME/mo-image/preview.key`,因此签名链接在宿主重启后仍然有效。
|
|
221
221
|
|
|
222
222
|
建议把 `generated-images/` 加进项目的 `.gitignore`,避免把生成图误提交。
|
|
223
223
|
|
|
@@ -592,7 +592,7 @@ $DSH_HOME/.credentials.yaml
|
|
|
592
592
|
|
|
593
593
|
云端预设由协议解析返回值。本地预设沿用部署器的解析方式,模型级「输出设置」默认锁定,可解锁为自定义工作流或部署修改返回格式。「输入设置」仍用于自配来源及 ComfyUI、A1111、SwarmUI 等由部署端决定的输入参数。
|
|
594
594
|
|
|
595
|
-
「自定义模型 API
|
|
595
|
+
「自定义模型 API」提供协议和返回格式控件。API 协议为「自定义」时,填写了端点的文生图或图生图操作须选择返回预设,或选「自定义 JSON」并参考 OpenAI Images 示例填写输出描述符。模型默认继承提供商的返回格式,也可单独覆盖。请求体里的 `output_format` 一类字段控制上游图片编码,操作的 `output` 描述插件如何从响应里取图。
|
|
596
596
|
|
|
597
597
|
```json
|
|
598
598
|
{
|
package/lib/client.js
CHANGED
|
@@ -997,6 +997,16 @@ window.__ModuleLoader__.load({
|
|
|
997
997
|
|
|
998
998
|
/** 「更多协议…」的哨兵值:选中它只展开列表,绝不写进配置——它也不是一条协议。 */
|
|
999
999
|
const PROTOCOL_MORE = '__more__';
|
|
1000
|
+
// Matches the OpenAI Images response preset, including URL-based responses.
|
|
1001
|
+
const OPENAI_OUTPUT_EXAMPLE = [
|
|
1002
|
+
'{',
|
|
1003
|
+
' "kind": "json",',
|
|
1004
|
+
' "pick": [',
|
|
1005
|
+
' {"path": "data.0.b64_json", "as": "base64"},',
|
|
1006
|
+
' {"path": "data.0.url", "as": "url"}',
|
|
1007
|
+
' ]',
|
|
1008
|
+
'}'
|
|
1009
|
+
].join('\n');
|
|
1000
1010
|
|
|
1001
1011
|
/**
|
|
1002
1012
|
* 「自定义」协议的 id。
|
|
@@ -1930,7 +1940,7 @@ window.__ModuleLoader__.load({
|
|
|
1930
1940
|
* - 新建:目录 / 本地两条入口各自带一段 body(预设选择器 / 部署器 + 常显字段);
|
|
1931
1941
|
* 「自定义模型 API」没有 body,协议与接入细节两组字段按 fieldOrder 平铺(不套折叠区)。
|
|
1932
1942
|
* - 编辑(compact):常显只剩 API 密钥;显示名称 → API 地址 → 协议设置(内容平铺,
|
|
1933
|
-
* 不再套第二层 details)→ 模型目录
|
|
1943
|
+
* 不再套第二层 details)→ 模型目录 → 调度模型,全收进同一个
|
|
1934
1944
|
* 「自定义设置」折叠区,默认收起。
|
|
1935
1945
|
*
|
|
1936
1946
|
* 参数:
|
|
@@ -1940,8 +1950,8 @@ window.__ModuleLoader__.load({
|
|
|
1940
1950
|
* - fields 各字段块;某一侧没有的(比如新建没有的已存密钥回显)传 null
|
|
1941
1951
|
* - fieldOrder 平铺时的常显字段顺序;默认「密钥 → 名称 → 地址」。新建「自定义模型 API」
|
|
1942
1952
|
* 改成「名称 → 地址 → 密钥」:密钥和地址 / 协议是同一组信息(连哪个服务)。
|
|
1943
|
-
* - protocolFields 协议相关的一组控件:协议 → 鉴权 →
|
|
1944
|
-
* - advancedFields 接入细节的一组控件:模型目录 →
|
|
1953
|
+
* - protocolFields 协议相关的一组控件:协议 → 自定义端点 → 鉴权 → 协议选项 → 返回格式
|
|
1954
|
+
* - advancedFields 接入细节的一组控件:模型目录 → 调度模型
|
|
1945
1955
|
* - presetSourced 预设来源整块不渲染协议相关字段:判据只在这一处
|
|
1946
1956
|
* - compact true = 常显只留密钥,其余(名称 → 地址 → 协议 → 接入细节)收进同一个
|
|
1947
1957
|
* 「自定义设置」(编辑页)
|
|
@@ -1976,7 +1986,7 @@ window.__ModuleLoader__.load({
|
|
|
1976
1986
|
const protocolFields = options.presetSourced ? null : options.protocolFields;
|
|
1977
1987
|
/**
|
|
1978
1988
|
* 编辑页的形态:常显只有 API 密钥,其余全住同一个「自定义设置」折叠区。
|
|
1979
|
-
* 顺序固定为「名称 → 地址 → 协议设置 → 接入细节(模型目录 /
|
|
1989
|
+
* 顺序固定为「名称 → 地址 → 协议设置 → 接入细节(模型目录 / 调度模型)」。
|
|
1980
1990
|
*/
|
|
1981
1991
|
const compactBody = options.compact ? h(React.Fragment, null,
|
|
1982
1992
|
options.notice || null,
|
|
@@ -2045,7 +2055,8 @@ window.__ModuleLoader__.load({
|
|
|
2045
2055
|
// 编辑页「自定义设置」折叠区的展开状态:默认收起(平时只是改某一项,别把整张表铺开)。
|
|
2046
2056
|
// 新建的目录 / 本地两条入口也用这个状态,它们的折叠区同样是「自定义设置」。
|
|
2047
2057
|
// 协议下拉是否展开了长尾协议:只活在这一次面板里,不进配置(面板重开就是收起的)。
|
|
2048
|
-
const [
|
|
2058
|
+
const [protocolExpansion, setProtocolExpansion] = React.useState('');
|
|
2059
|
+
const protocolExpanded = Boolean(protocolExpansion);
|
|
2049
2060
|
// 「自动识别」的结果提示(busy / ok / warn):同样只是这一屏的话,不落盘。
|
|
2050
2061
|
const [protocolNote, setProtocolNote] = React.useState({ busy: false, tone: '', text: '' });
|
|
2051
2062
|
const [mode, setMode] = React.useState('catalog');
|
|
@@ -2172,7 +2183,8 @@ window.__ModuleLoader__.load({
|
|
|
2172
2183
|
key: draft.key.trim()
|
|
2173
2184
|
};
|
|
2174
2185
|
};
|
|
2175
|
-
const
|
|
2186
|
+
const customRouteValue = (kind) => String(providerOperations?.[kind]?.path ?? draft.customEndpoints?.[kind] ?? '');
|
|
2187
|
+
const customPathOf = (kind) => customRouteValue(kind).trim();
|
|
2176
2188
|
const [ruleProvider, ruleSignature] = React.useMemo(() => {
|
|
2177
2189
|
const provider = ruleProviderOf(draft, providerOperations);
|
|
2178
2190
|
return [provider, JSON.stringify(provider)];
|
|
@@ -2572,7 +2584,7 @@ window.__ModuleLoader__.load({
|
|
|
2572
2584
|
}
|
|
2573
2585
|
return next;
|
|
2574
2586
|
});
|
|
2575
|
-
|
|
2587
|
+
setProtocolExpansion('');
|
|
2576
2588
|
// 连不上/超时的文案自带句号;接「;已切到自定义…」前把句号收掉,别出现「。;」。
|
|
2577
2589
|
const issueWithSuffix = issue
|
|
2578
2590
|
? issue.replace(/[。..]$/, '') + t('form.detectProtocolSwitchedToCustom')
|
|
@@ -2707,6 +2719,18 @@ window.__ModuleLoader__.load({
|
|
|
2707
2719
|
}, protocolNote.busy
|
|
2708
2720
|
? h(React.Fragment, null, detectSpinner(), t('form.detectProtocolBusy'))
|
|
2709
2721
|
: t('form.detectProtocol'));
|
|
2722
|
+
const expandProtocols = (select) => {
|
|
2723
|
+
if (typeof select?.showPicker === 'function' && typeof ReactDOM?.flushSync === 'function') {
|
|
2724
|
+
// Commit the optgroups before reopening the native picker in the same user gesture.
|
|
2725
|
+
ReactDOM.flushSync(() => setProtocolExpansion('picker'));
|
|
2726
|
+
try {
|
|
2727
|
+
select.showPicker();
|
|
2728
|
+
return;
|
|
2729
|
+
} catch (_error) { /* older or embedded webviews may reject opening the picker */ }
|
|
2730
|
+
}
|
|
2731
|
+
setProtocolExpansion('list');
|
|
2732
|
+
};
|
|
2733
|
+
const showProtocolList = protocolExpansion === 'list';
|
|
2710
2734
|
return h('div', { className: MC.field },
|
|
2711
2735
|
// label 与问号一行:问号在 label 自己的容器里,hover 互不影响。
|
|
2712
2736
|
h('div', {
|
|
@@ -2719,24 +2743,27 @@ window.__ModuleLoader__.load({
|
|
|
2719
2743
|
// 识别按钮紧贴下拉框右侧,和它同处一行;不要塞进 label 里。
|
|
2720
2744
|
h('div', {
|
|
2721
2745
|
'data-mo-image-protocol-row': '',
|
|
2722
|
-
style: { display: 'flex', alignItems: 'center', gap: 8, minWidth: 0 }
|
|
2746
|
+
style: { display: 'flex', alignItems: showProtocolList ? 'flex-start' : 'center', gap: 8, minWidth: 0 }
|
|
2723
2747
|
},
|
|
2724
2748
|
h('select', {
|
|
2725
2749
|
className: MC.input + ' ' + MC.selectInput,
|
|
2726
2750
|
'data-mo-image-protocol': '',
|
|
2727
|
-
style: { flex: '1 1 auto', minWidth: 0 },
|
|
2751
|
+
style: { flex: '1 1 auto', minWidth: 0, ...(showProtocolList ? { height: 'auto' } : {}) },
|
|
2752
|
+
size: showProtocolList ? 8 : undefined,
|
|
2728
2753
|
value: draft.adapter || '',
|
|
2754
|
+
onBlur: showProtocolList ? () => setProtocolExpansion('') : undefined,
|
|
2755
|
+
onKeyDown: showProtocolList ? (event) => {
|
|
2756
|
+
if (event.key === 'Escape') setProtocolExpansion('');
|
|
2757
|
+
} : undefined,
|
|
2729
2758
|
onChange: (e) => {
|
|
2730
2759
|
const picked = String(e.target.value || '');
|
|
2731
2760
|
// 「更多协议…」只展开列表,不改配置:它不是一个能存下来的协议。
|
|
2732
|
-
if (picked === PROTOCOL_MORE) {
|
|
2733
|
-
|
|
2761
|
+
if (picked === PROTOCOL_MORE) { expandProtocols(e.currentTarget); return; }
|
|
2762
|
+
setProtocolExpansion('');
|
|
2734
2763
|
// 换协议 = 换一套选项:旧协议的选项对新协议没有意义,一律回到新协议的默认值;
|
|
2735
2764
|
// 上一次识别的提示也一并作废,免得「已识别为 X」挂在另一个协议下面。
|
|
2736
2765
|
setProtocolNote({ busy: false, tone: '', text: '' });
|
|
2737
|
-
//
|
|
2738
|
-
// 本身就是「没写」,所以清掉显式值 = 切到跟随协议;模型级的返回格式覆盖
|
|
2739
|
-
// 继承的是上面这一层,一并清掉(它们说的是旧协议的响应形状)。
|
|
2766
|
+
// 清除旧协议的鉴权和两级返回格式覆盖。自定义协议的返回格式需要重新选择。
|
|
2740
2767
|
setOperationOverrides({});
|
|
2741
2768
|
setOutputJsonDrafts({});
|
|
2742
2769
|
setDraft((prev) => {
|
|
@@ -2914,12 +2941,20 @@ window.__ModuleLoader__.load({
|
|
|
2914
2941
|
h('input', {
|
|
2915
2942
|
className: MC.input,
|
|
2916
2943
|
name: 'route-' + kind,
|
|
2917
|
-
value:
|
|
2944
|
+
value: customRouteValue(kind),
|
|
2918
2945
|
placeholder: ROUTE_PLACEHOLDER[kind] || '',
|
|
2919
|
-
onChange: (e) =>
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2946
|
+
onChange: (e) => {
|
|
2947
|
+
const value = e.target.value;
|
|
2948
|
+
if (providerOperations?.[kind]?.path !== undefined) {
|
|
2949
|
+
setOperationOverrides((prev) => {
|
|
2950
|
+
const config = hasOwn(prev, '') ? prev[''] : providerOperations;
|
|
2951
|
+
return { ...prev, '': { ...config, [kind]: { ...config[kind], path: value } } };
|
|
2952
|
+
});
|
|
2953
|
+
}
|
|
2954
|
+
setDraft((prev) => ({
|
|
2955
|
+
...prev, customEndpoints: { ...prev.customEndpoints, [kind]: value }
|
|
2956
|
+
}));
|
|
2957
|
+
}
|
|
2923
2958
|
})
|
|
2924
2959
|
);
|
|
2925
2960
|
/** 某个作用域(提供商 / 某个模型)当前的操作配置。 */
|
|
@@ -2934,7 +2969,9 @@ window.__ModuleLoader__.load({
|
|
|
2934
2969
|
?? (value && typeof value === 'object' ? JSON.stringify(value, null, 2) : undefined);
|
|
2935
2970
|
const explicit = presets.includes(value);
|
|
2936
2971
|
const legacy = json === undefined && !explicit && Boolean(value) && value !== 'auto';
|
|
2937
|
-
const
|
|
2972
|
+
const requiresExplicitFormat = !model && isCustomProtocol(draft.adapter);
|
|
2973
|
+
const defaultOption = requiresExplicitFormat ? '' : 'inherit';
|
|
2974
|
+
const selected = json !== undefined ? 'custom-json' : legacy ? 'custom' : explicit ? value : defaultOption;
|
|
2938
2975
|
const operationLabel = 'form.route.' + kind;
|
|
2939
2976
|
const label = t('form.operationOutput', { operation: t(operationLabel) });
|
|
2940
2977
|
const select = h('label', { className: MC.field, key: kind },
|
|
@@ -2962,20 +2999,22 @@ window.__ModuleLoader__.load({
|
|
|
2962
2999
|
});
|
|
2963
3000
|
}
|
|
2964
3001
|
},
|
|
2965
|
-
h('option', { value:
|
|
3002
|
+
h('option', { value: defaultOption, disabled: requiresExplicitFormat }, requiresExplicitFormat
|
|
3003
|
+
? t('form.protocolUnset')
|
|
3004
|
+
: t(model ? 'form.outputPreset.inherit' : 'form.outputPreset.protocol')),
|
|
2966
3005
|
presets.map((preset) => h('option', { key: preset, value: preset }, translatedOr(t, 'form.outputPreset.' + preset, preset))),
|
|
2967
3006
|
h('option', { value: 'custom-json' }, t('form.outputPreset.customJson')),
|
|
2968
3007
|
legacy ? h('option', { value: 'custom', disabled: true, 'data-mo-image-output-legacy': '' }, t('form.outputPreset.customLegacy')) : null));
|
|
2969
|
-
const editor = json === undefined ? null : h('
|
|
2970
|
-
|
|
3008
|
+
const editor = json === undefined ? null : h('label', { className: MC.field, key: kind },
|
|
3009
|
+
h('span', { className: MC.fieldLabel }, label + ' · JSON'),
|
|
3010
|
+
h('textarea', {
|
|
2971
3011
|
className: MC.input,
|
|
2972
3012
|
'data-mo-image-output-json': kind,
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
rows: 5, maxLength: 64 * 1024, spellCheck: false, disabled: !!locked,
|
|
3013
|
+
placeholder: OPENAI_OUTPUT_EXAMPLE,
|
|
3014
|
+
rows: 7, maxLength: 64 * 1024, spellCheck: false, disabled: !!locked,
|
|
2976
3015
|
value: json,
|
|
2977
3016
|
onChange: (event) => updateOutputJson(scope, kind, event.target.value)
|
|
2978
|
-
|
|
3017
|
+
}));
|
|
2979
3018
|
return { select, editor };
|
|
2980
3019
|
};
|
|
2981
3020
|
/** 这里存着用户以前手写、匹配不到预设的 output(保留原值,不静默丢弃)。 */
|
|
@@ -2989,10 +3028,10 @@ window.__ModuleLoader__.load({
|
|
|
2989
3028
|
// 提供商与模型共用同一套预设和描述符控件。描述符默认折叠在下拉项内。
|
|
2990
3029
|
const outputPresetPanel = (model, locked) => {
|
|
2991
3030
|
const declaration = imageCatalog.adapters.find((entry) => entry.id === draft.adapter);
|
|
2992
|
-
const noEditRoute = draft.adapter
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
3031
|
+
const noEditRoute = !isCustomProtocol(draft.adapter) && (
|
|
3032
|
+
(presetSourced && isLocalDeployment(draft) && declaration?.routes && !routesOf(draft.adapter).edit)
|
|
3033
|
+
|| draft.protocolOptions?.edit === 'none'
|
|
3034
|
+
);
|
|
2996
3035
|
const fields = ['generate', 'edit'].map((kind) => operationOutputSelect(kind, model,
|
|
2997
3036
|
locked || (kind === 'edit' && noEditRoute && operationConfigOf(model).edit?.output === undefined)));
|
|
2998
3037
|
return h('div', {
|
|
@@ -3003,6 +3042,9 @@ window.__ModuleLoader__.load({
|
|
|
3003
3042
|
},
|
|
3004
3043
|
// 两个下拉各占半宽、并排一行:它们本来就短,不占两行。
|
|
3005
3044
|
h('div', { style: { display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) minmax(0, 1fr)', gap: 8 } }, fields.map((field) => field.select)),
|
|
3045
|
+
fields.some((field) => field.editor)
|
|
3046
|
+
? h('p', { className: MC.advancedHint, style: FLUSH_TEXT_STYLE }, t('form.outputPreset.jsonExample'))
|
|
3047
|
+
: null,
|
|
3006
3048
|
...fields.map((field) => field.editor),
|
|
3007
3049
|
hasLegacyOutput(model)
|
|
3008
3050
|
? h('p', {
|
|
@@ -5261,6 +5303,16 @@ window.__ModuleLoader__.load({
|
|
|
5261
5303
|
if (hasOwn(operationOverrides, '') || jsonOutputDraftOf('') || draft.operations) {
|
|
5262
5304
|
next.operations = operationsForSave('');
|
|
5263
5305
|
}
|
|
5306
|
+
if (!presetSourced && isCustomProtocol(next.adapter)) {
|
|
5307
|
+
for (const kind of ['generate', 'edit']) {
|
|
5308
|
+
const output = next.operations?.[kind]?.output;
|
|
5309
|
+
if (customPathOf(kind) && (!output || output === 'auto')) {
|
|
5310
|
+
setAdvanced(true);
|
|
5311
|
+
const operationLabel = 'form.route.' + kind;
|
|
5312
|
+
throw new Error(t('form.outputPreset.required', { operation: t(operationLabel) }));
|
|
5313
|
+
}
|
|
5314
|
+
}
|
|
5315
|
+
}
|
|
5264
5316
|
next.modelOptions = { ...draft.modelOptions };
|
|
5265
5317
|
for (const model of draft.models.filter(Boolean)) {
|
|
5266
5318
|
if (!hasOwn(operationOverrides, model) && !jsonOutputDraftOf(model)) continue;
|
|
@@ -5288,7 +5340,7 @@ window.__ModuleLoader__.load({
|
|
|
5288
5340
|
);
|
|
5289
5341
|
/**
|
|
5290
5342
|
* 两组字段的内容:新建(自定义模型 API)与编辑传的是同一组,顺序也一样。
|
|
5291
|
-
*
|
|
5343
|
+
* 自定义端点紧跟协议;接入细节那一组里模型目录在调度模型之前。
|
|
5292
5344
|
* 删掉或挪动这里的任意一项,新建与编辑会同时变——这正是要的效果。区别只在壳:
|
|
5293
5345
|
* 新建那条入口平铺(flat),编辑页把它们全收进一个「自定义设置」(compact)。
|
|
5294
5346
|
*
|
|
@@ -5296,11 +5348,12 @@ window.__ModuleLoader__.load({
|
|
|
5296
5348
|
*/
|
|
5297
5349
|
const protocolSettingsFields = [
|
|
5298
5350
|
protocolField,
|
|
5351
|
+
routePanel,
|
|
5299
5352
|
!protocolLocked || a1111AuthConfigurable ? authField : null,
|
|
5300
5353
|
protocolOptionsField,
|
|
5301
5354
|
!protocolLocked || draft.presetId === '' || (isNew && mode === 'custom') ? operationEditor() : null
|
|
5302
5355
|
];
|
|
5303
|
-
const advancedSettingsFields = [presetSourced && a1111AuthConfigurable ? authField : null, modelDirectory,
|
|
5356
|
+
const advancedSettingsFields = [presetSourced && a1111AuthConfigurable ? authField : null, modelDirectory, hostModelField];
|
|
5304
5357
|
/**
|
|
5305
5358
|
* 「切换为自定义API」:把预设来源的提供商变成自己配的那种(丢掉 `presetId`)。
|
|
5306
5359
|
*
|
|
@@ -5483,7 +5536,7 @@ window.__ModuleLoader__.load({
|
|
|
5483
5536
|
});
|
|
5484
5537
|
}
|
|
5485
5538
|
// 编辑页:同一份布局换一种壳(compact)—— 常显只有密钥,显示名称 → API 地址 →
|
|
5486
|
-
// 协议设置 → 模型目录 →
|
|
5539
|
+
// 协议设置 → 模型目录 → 调度模型全住一个「自定义设置」。字段本身与新建那份相同。
|
|
5487
5540
|
return ProviderFormLayout({ ...sharedFormLayout, compact: true });
|
|
5488
5541
|
}
|
|
5489
5542
|
|
|
@@ -7824,6 +7877,8 @@ window.__ModuleLoader__.load({
|
|
|
7824
7877
|
"form.outputPreset.inherit": "继承提供商设置",
|
|
7825
7878
|
"form.outputPreset.protocol": "跟随协议",
|
|
7826
7879
|
"form.outputPreset.customJson": "自定义 JSON",
|
|
7880
|
+
"form.outputPreset.jsonExample": "以 OpenAI Images 为例。请按接口实际响应填写图片字段的路径(path)和类型(as)。",
|
|
7881
|
+
"form.outputPreset.required": "请选择{operation}返回格式。",
|
|
7827
7882
|
"form.outputPreset.invalidJson": "{operation}的返回配置需要一个有效的 JSON 对象或非空数组。",
|
|
7828
7883
|
"form.outputPreset.openai": "OpenAI Images",
|
|
7829
7884
|
"form.outputPreset.binary": "二进制图片",
|
|
@@ -8219,6 +8274,8 @@ window.__ModuleLoader__.load({
|
|
|
8219
8274
|
"form.outputPreset.inherit": "Inherit provider setting",
|
|
8220
8275
|
"form.outputPreset.protocol": "Protocol default",
|
|
8221
8276
|
"form.outputPreset.customJson": "Custom JSON",
|
|
8277
|
+
"form.outputPreset.jsonExample": "The example uses OpenAI Images. Set path and as to match the image field and its type in your API response.",
|
|
8278
|
+
"form.outputPreset.required": "Choose a response format for {operation}.",
|
|
8222
8279
|
"form.outputPreset.invalidJson": "Enter a valid JSON object or nonempty array for the {operation} response.",
|
|
8223
8280
|
"form.outputPreset.openai": "OpenAI Images",
|
|
8224
8281
|
"form.outputPreset.binary": "Binary image",
|
|
@@ -8614,6 +8671,8 @@ window.__ModuleLoader__.load({
|
|
|
8614
8671
|
"form.outputPreset.inherit": "プロバイダー設定を継承",
|
|
8615
8672
|
"form.outputPreset.protocol": "プロトコルの既定値",
|
|
8616
8673
|
"form.outputPreset.customJson": "カスタム JSON",
|
|
8674
|
+
"form.outputPreset.jsonExample": "OpenAI Images の例です。API レスポンスの画像フィールドのパス(path)と種類(as)に合わせてください。",
|
|
8675
|
+
"form.outputPreset.required": "{operation}のレスポンス形式を選択してください。",
|
|
8617
8676
|
"form.outputPreset.invalidJson": "{operation}のレスポンスに有効な JSON オブジェクトか空でない配列を入力してください。",
|
|
8618
8677
|
"form.outputPreset.openai": "OpenAI Images",
|
|
8619
8678
|
"form.outputPreset.binary": "バイナリ画像",
|
|
@@ -9009,6 +9068,8 @@ window.__ModuleLoader__.load({
|
|
|
9009
9068
|
"form.outputPreset.inherit": "Heredar del proveedor",
|
|
9010
9069
|
"form.outputPreset.protocol": "Predeterminado del protocolo",
|
|
9011
9070
|
"form.outputPreset.customJson": "JSON personalizado",
|
|
9071
|
+
"form.outputPreset.jsonExample": "El ejemplo usa OpenAI Images. Ajusta path y as al campo de imagen y a su tipo en la respuesta de tu API.",
|
|
9072
|
+
"form.outputPreset.required": "Elige un formato de respuesta para {operation}.",
|
|
9012
9073
|
"form.outputPreset.invalidJson": "Introduce un objeto JSON válido o una lista no vacía para la respuesta de {operation}.",
|
|
9013
9074
|
"form.outputPreset.openai": "OpenAI Images",
|
|
9014
9075
|
"form.outputPreset.binary": "Imagen binaria",
|
|
@@ -9404,6 +9465,8 @@ window.__ModuleLoader__.load({
|
|
|
9404
9465
|
"form.outputPreset.inherit": "Hériter du fournisseur",
|
|
9405
9466
|
"form.outputPreset.protocol": "Par défaut du protocole",
|
|
9406
9467
|
"form.outputPreset.customJson": "JSON personnalisé",
|
|
9468
|
+
"form.outputPreset.jsonExample": "L’exemple utilise OpenAI Images. Adaptez path et as au champ d’image et à son type dans la réponse de votre API.",
|
|
9469
|
+
"form.outputPreset.required": "Choisissez un format de réponse pour {operation}.",
|
|
9407
9470
|
"form.outputPreset.invalidJson": "Saisissez un objet JSON valide ou un tableau non vide pour la réponse de {operation}.",
|
|
9408
9471
|
"form.outputPreset.openai": "OpenAI Images",
|
|
9409
9472
|
"form.outputPreset.binary": "Image binaire",
|
|
@@ -9799,6 +9862,8 @@ window.__ModuleLoader__.load({
|
|
|
9799
9862
|
"form.outputPreset.inherit": "Vom Anbieter übernehmen",
|
|
9800
9863
|
"form.outputPreset.protocol": "Protokollstandard",
|
|
9801
9864
|
"form.outputPreset.customJson": "Eigenes JSON",
|
|
9865
|
+
"form.outputPreset.jsonExample": "Das Beispiel verwendet OpenAI Images. Passe path und as an das Bildfeld und seinen Typ in der API-Antwort an.",
|
|
9866
|
+
"form.outputPreset.required": "Wähle ein Antwortformat für {operation}.",
|
|
9802
9867
|
"form.outputPreset.invalidJson": "Geben Sie für die Antwort von {operation} ein gültiges JSON-Objekt oder ein nicht leeres Array ein.",
|
|
9803
9868
|
"form.outputPreset.openai": "OpenAI Images",
|
|
9804
9869
|
"form.outputPreset.binary": "Binärbild",
|
|
@@ -10194,6 +10259,8 @@ window.__ModuleLoader__.load({
|
|
|
10194
10259
|
"form.outputPreset.inherit": "Настройка поставщика",
|
|
10195
10260
|
"form.outputPreset.protocol": "По умолчанию протокола",
|
|
10196
10261
|
"form.outputPreset.customJson": "Свой JSON",
|
|
10262
|
+
"form.outputPreset.jsonExample": "В примере используется OpenAI Images. Укажите в path и as путь и тип поля с изображением в ответе вашего API.",
|
|
10263
|
+
"form.outputPreset.required": "Выберите формат ответа для операции «{operation}».",
|
|
10197
10264
|
"form.outputPreset.invalidJson": "Для ответа {operation} укажите допустимый объект JSON или непустой массив.",
|
|
10198
10265
|
"form.outputPreset.openai": "OpenAI Images",
|
|
10199
10266
|
"form.outputPreset.binary": "Двоичное изображение",
|
|
@@ -10589,6 +10656,8 @@ window.__ModuleLoader__.load({
|
|
|
10589
10656
|
"form.outputPreset.inherit": "Herdar do provedor",
|
|
10590
10657
|
"form.outputPreset.protocol": "Padrão do protocolo",
|
|
10591
10658
|
"form.outputPreset.customJson": "JSON personalizado",
|
|
10659
|
+
"form.outputPreset.jsonExample": "O exemplo usa OpenAI Images. Ajuste path e as ao campo de imagem e ao tipo dele na resposta da sua API.",
|
|
10660
|
+
"form.outputPreset.required": "Escolha um formato de resposta para {operation}.",
|
|
10592
10661
|
"form.outputPreset.invalidJson": "Insira um objeto JSON válido ou uma lista não vazia para a resposta de {operation}.",
|
|
10593
10662
|
"form.outputPreset.openai": "OpenAI Images",
|
|
10594
10663
|
"form.outputPreset.binary": "Imagem binária",
|
package/lib/config-store.js
CHANGED
|
@@ -1033,10 +1033,8 @@ function requestHostName(req) {
|
|
|
1033
1033
|
return withoutPort;
|
|
1034
1034
|
}
|
|
1035
1035
|
/**
|
|
1036
|
-
*
|
|
1037
|
-
*
|
|
1038
|
-
* DSH_WEB_URL 公布的域名;Origin 必须同源;POST 必须是 application/json。
|
|
1039
|
-
* 同一 OS 用户的进程本来就能读凭据文件,这里不是对抗同 UID 进程的边界。
|
|
1036
|
+
* DSH 完成访问校验后,设置相关接口仍要求同源浏览器请求。
|
|
1037
|
+
* Host 支持回环、IP 字面量及 DSH 公布的域名,写请求必须使用 application/json。
|
|
1040
1038
|
*/
|
|
1041
1039
|
export function assertLocalRequest(store, req, write) {
|
|
1042
1040
|
const hostName = requestHostName(req);
|
package/lib/index.js
CHANGED
|
@@ -175,6 +175,40 @@ function sendJson(res, status, value) {
|
|
|
175
175
|
res.writeHead(status, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store' });
|
|
176
176
|
res.end(JSON.stringify(value));
|
|
177
177
|
}
|
|
178
|
+
|
|
179
|
+
function routeAccessRejection(ctx, req, peer) {
|
|
180
|
+
// New hosts admit requests before dispatch and pass the authenticated Peer.
|
|
181
|
+
if (peer !== undefined) {
|
|
182
|
+
if (peer?.signal?.aborted) return 401;
|
|
183
|
+
return peer?.principal?.kind === 'owner' ? undefined : 403;
|
|
184
|
+
}
|
|
185
|
+
// On older hosts the handler itself must apply Connection's access check.
|
|
186
|
+
try {
|
|
187
|
+
const connection = ctx.get?.('connection');
|
|
188
|
+
if (typeof connection?.requestRejection === 'function') {
|
|
189
|
+
const rejection = connection.requestRejection(req);
|
|
190
|
+
if (rejection === undefined || rejection === 401 || rejection === 403) return rejection;
|
|
191
|
+
}
|
|
192
|
+
} catch (_error) {
|
|
193
|
+
// A missing or unavailable authentication service cannot grant access.
|
|
194
|
+
}
|
|
195
|
+
return 503;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function registerPrivateRoute(ctx, route) {
|
|
199
|
+
return ctx.webServer.register({
|
|
200
|
+
...route,
|
|
201
|
+
auth: 'required',
|
|
202
|
+
async handler(req, res, peer) {
|
|
203
|
+
const rejection = routeAccessRejection(ctx, req, peer);
|
|
204
|
+
if (rejection === undefined) return route.handler(req, res);
|
|
205
|
+
const error = rejection === 401 ? 'unauthorized'
|
|
206
|
+
: rejection === 403 ? 'forbidden' : 'DSH authentication unavailable';
|
|
207
|
+
return sendJson(res, rejection, { ok: false, error });
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
178
212
|
async function readBody(req) {
|
|
179
213
|
const chunks = [];
|
|
180
214
|
let total = 0;
|
|
@@ -1164,7 +1198,7 @@ export function apply(ctx, options = {}) {
|
|
|
1164
1198
|
|
|
1165
1199
|
ctx.effect(() => {
|
|
1166
1200
|
try {
|
|
1167
|
-
return ctx
|
|
1201
|
+
return registerPrivateRoute(ctx, {
|
|
1168
1202
|
kind: 'exact', path: '/api/mo-image/config',
|
|
1169
1203
|
handler: async (req, res) => {
|
|
1170
1204
|
try {
|
|
@@ -1189,7 +1223,7 @@ export function apply(ctx, options = {}) {
|
|
|
1189
1223
|
|
|
1190
1224
|
ctx.effect(() => {
|
|
1191
1225
|
try {
|
|
1192
|
-
return ctx
|
|
1226
|
+
return registerPrivateRoute(ctx, {
|
|
1193
1227
|
kind: 'exact', path: '/api/mo-image/models',
|
|
1194
1228
|
handler: async (req, res) => {
|
|
1195
1229
|
try {
|
|
@@ -1216,7 +1250,7 @@ export function apply(ctx, options = {}) {
|
|
|
1216
1250
|
|
|
1217
1251
|
ctx.effect(() => {
|
|
1218
1252
|
try {
|
|
1219
|
-
return ctx
|
|
1253
|
+
return registerPrivateRoute(ctx, {
|
|
1220
1254
|
kind: 'exact', path: '/api/mo-image/detect-protocol',
|
|
1221
1255
|
handler: async (req, res) => {
|
|
1222
1256
|
try {
|
|
@@ -1276,7 +1310,7 @@ export function apply(ctx, options = {}) {
|
|
|
1276
1310
|
|
|
1277
1311
|
ctx.effect(() => {
|
|
1278
1312
|
try {
|
|
1279
|
-
return ctx
|
|
1313
|
+
return registerPrivateRoute(ctx, {
|
|
1280
1314
|
kind: 'exact', path: '/api/mo-image/detect-model-rule',
|
|
1281
1315
|
handler: async (req, res) => {
|
|
1282
1316
|
try {
|
|
@@ -1333,7 +1367,7 @@ export function apply(ctx, options = {}) {
|
|
|
1333
1367
|
|
|
1334
1368
|
ctx.effect(() => {
|
|
1335
1369
|
try {
|
|
1336
|
-
return ctx
|
|
1370
|
+
return registerPrivateRoute(ctx, {
|
|
1337
1371
|
kind: 'exact', path: '/api/mo-image/comfy/analyze',
|
|
1338
1372
|
handler: async (req, res) => {
|
|
1339
1373
|
try {
|
|
@@ -1361,7 +1395,7 @@ export function apply(ctx, options = {}) {
|
|
|
1361
1395
|
*/
|
|
1362
1396
|
ctx.effect(() => {
|
|
1363
1397
|
try {
|
|
1364
|
-
return ctx
|
|
1398
|
+
return registerPrivateRoute(ctx, {
|
|
1365
1399
|
kind: 'exact', path: '/api/mo-image/comfy/params',
|
|
1366
1400
|
handler: async (req, res) => {
|
|
1367
1401
|
try {
|
|
@@ -1386,7 +1420,7 @@ export function apply(ctx, options = {}) {
|
|
|
1386
1420
|
|
|
1387
1421
|
ctx.effect(() => {
|
|
1388
1422
|
try {
|
|
1389
|
-
return ctx
|
|
1423
|
+
return registerPrivateRoute(ctx, {
|
|
1390
1424
|
kind: 'prefix', path: '/api/mo-image/preview',
|
|
1391
1425
|
handler: async (req, res) => {
|
|
1392
1426
|
let handle;
|
|
@@ -1431,7 +1465,7 @@ export function apply(ctx, options = {}) {
|
|
|
1431
1465
|
|
|
1432
1466
|
ctx.effect(() => {
|
|
1433
1467
|
try {
|
|
1434
|
-
return ctx
|
|
1468
|
+
return registerPrivateRoute(ctx, {
|
|
1435
1469
|
kind: 'exact', path: '/api/mo-image/update',
|
|
1436
1470
|
handler: async (req, res) => {
|
|
1437
1471
|
try {
|
package/locale/messages.csv
CHANGED
|
@@ -47,6 +47,8 @@ form.operationOutput,"{operation}返回格式","Response format for {operation}"
|
|
|
47
47
|
form.outputPreset.inherit,"继承提供商设置","Inherit provider setting","プロバイダー設定を継承","Heredar del proveedor","Hériter du fournisseur","Vom Anbieter übernehmen","Настройка поставщика","Herdar do provedor"
|
|
48
48
|
form.outputPreset.protocol,"跟随协议","Protocol default","プロトコルの既定値","Predeterminado del protocolo","Par défaut du protocole","Protokollstandard","По умолчанию протокола","Padrão do protocolo"
|
|
49
49
|
form.outputPreset.customJson,"自定义 JSON","Custom JSON","カスタム JSON","JSON personalizado","JSON personnalisé","Eigenes JSON","Свой JSON","JSON personalizado"
|
|
50
|
+
form.outputPreset.jsonExample,"以 OpenAI Images 为例。请按接口实际响应填写图片字段的路径(path)和类型(as)。","The example uses OpenAI Images. Set path and as to match the image field and its type in your API response.","OpenAI Images の例です。API レスポンスの画像フィールドのパス(path)と種類(as)に合わせてください。","El ejemplo usa OpenAI Images. Ajusta path y as al campo de imagen y a su tipo en la respuesta de tu API.","L’exemple utilise OpenAI Images. Adaptez path et as au champ d’image et à son type dans la réponse de votre API.","Das Beispiel verwendet OpenAI Images. Passe path und as an das Bildfeld und seinen Typ in der API-Antwort an.","В примере используется OpenAI Images. Укажите в path и as путь и тип поля с изображением в ответе вашего API.","O exemplo usa OpenAI Images. Ajuste path e as ao campo de imagem e ao tipo dele na resposta da sua API."
|
|
51
|
+
form.outputPreset.required,"请选择{operation}返回格式。","Choose a response format for {operation}.","{operation}のレスポンス形式を選択してください。","Elige un formato de respuesta para {operation}.","Choisissez un format de réponse pour {operation}.","Wähle ein Antwortformat für {operation}.","Выберите формат ответа для операции «{operation}».","Escolha um formato de resposta para {operation}."
|
|
50
52
|
form.outputPreset.invalidJson,"{operation}的返回配置需要一个有效的 JSON 对象或非空数组。","Enter a valid JSON object or nonempty array for the {operation} response.","{operation}のレスポンスに有効な JSON オブジェクトか空でない配列を入力してください。","Introduce un objeto JSON válido o una lista no vacía para la respuesta de {operation}.","Saisissez un objet JSON valide ou un tableau non vide pour la réponse de {operation}.","Geben Sie für die Antwort von {operation} ein gültiges JSON-Objekt oder ein nicht leeres Array ein.","Для ответа {operation} укажите допустимый объект JSON или непустой массив.","Insira um objeto JSON válido ou uma lista não vazia para a resposta de {operation}."
|
|
51
53
|
form.outputPreset.openai,"OpenAI Images","OpenAI Images","OpenAI Images","OpenAI Images","OpenAI Images","OpenAI Images","OpenAI Images","OpenAI Images"
|
|
52
54
|
form.outputPreset.binary,"二进制图片","Binary image","バイナリ画像","Imagen binaria","Image binaire","Binärbild","Двоичное изображение","Imagem binária"
|
package/package.json
CHANGED