dsh-plugin-core-demo 0.35.12 → 0.35.14
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/client.js +124 -28
- package/dist/index.js +33 -7
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -1324,6 +1324,26 @@ function groupOf(groups, value) {
|
|
|
1324
1324
|
return void 0;
|
|
1325
1325
|
return groups.find((g) => g.options.some((o) => o.value === value));
|
|
1326
1326
|
}
|
|
1327
|
+
function retainSelectedValue(groups, value) {
|
|
1328
|
+
if (value === void 0 || value === "")
|
|
1329
|
+
return { groups, retained: false };
|
|
1330
|
+
if (flattenOptions(groups).some((o) => o.value === value))
|
|
1331
|
+
return { groups, retained: false };
|
|
1332
|
+
const slash3 = value.indexOf("/");
|
|
1333
|
+
const provider = slash3 > 0 ? value.slice(0, slash3) : "";
|
|
1334
|
+
const option = { value, label: value };
|
|
1335
|
+
const group = groups.find((g) => g.value === provider && g.value !== "");
|
|
1336
|
+
if (group !== void 0) {
|
|
1337
|
+
return {
|
|
1338
|
+
groups: groups.map((g) => g === group ? { value: g.value, label: g.label, options: [option, ...g.options] } : g),
|
|
1339
|
+
retained: true
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
return {
|
|
1343
|
+
groups: [...groups, { value: provider, label: provider, options: [option] }],
|
|
1344
|
+
retained: true
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1327
1347
|
function resolveTriggerSizing(opts) {
|
|
1328
1348
|
const px = (v) => typeof v === "number" ? `${v}px` : v;
|
|
1329
1349
|
if (opts.width !== void 0) {
|
|
@@ -5624,6 +5644,24 @@ var WorkspaceListStore = class {
|
|
|
5624
5644
|
};
|
|
5625
5645
|
var workspaceList = new WorkspaceListStore();
|
|
5626
5646
|
var workspaceFiles;
|
|
5647
|
+
var boundModelsPath;
|
|
5648
|
+
var catalogInFlight;
|
|
5649
|
+
function loadModelCatalog(path) {
|
|
5650
|
+
if (catalogInFlight !== void 0)
|
|
5651
|
+
return catalogInFlight;
|
|
5652
|
+
const job = fetch(path, { cache: "no-store" }).then((response) => response.ok ? response.json() : Promise.reject(new Error(`HTTP ${response.status}`))).then((data2) => {
|
|
5653
|
+
const routes = data2?.routes;
|
|
5654
|
+
if (!Array.isArray(routes))
|
|
5655
|
+
throw new Error("\u6A21\u578B\u76EE\u5F55\u54CD\u5E94\u7F3A\u5C11 routes");
|
|
5656
|
+
modelCatalog.setRoutes(routes);
|
|
5657
|
+
}).catch((error) => {
|
|
5658
|
+
modelCatalog.setUnavailable(String(error));
|
|
5659
|
+
}).finally(() => {
|
|
5660
|
+
catalogInFlight = void 0;
|
|
5661
|
+
});
|
|
5662
|
+
catalogInFlight = job;
|
|
5663
|
+
return job;
|
|
5664
|
+
}
|
|
5627
5665
|
function isWorkspaceSource(value) {
|
|
5628
5666
|
if (value === null || typeof value !== "object")
|
|
5629
5667
|
return false;
|
|
@@ -5646,14 +5684,8 @@ function connectHost(ctx, options = {}) {
|
|
|
5646
5684
|
const modelsPath = options.modelsPath;
|
|
5647
5685
|
if (modelsPath === void 0)
|
|
5648
5686
|
return;
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
if (!Array.isArray(routes))
|
|
5652
|
-
throw new Error("\u6A21\u578B\u76EE\u5F55\u54CD\u5E94\u7F3A\u5C11 routes");
|
|
5653
|
-
modelCatalog.setRoutes(routes);
|
|
5654
|
-
}).catch((error) => {
|
|
5655
|
-
modelCatalog.setUnavailable(String(error));
|
|
5656
|
-
});
|
|
5687
|
+
boundModelsPath = modelsPath;
|
|
5688
|
+
void loadModelCatalog(modelsPath);
|
|
5657
5689
|
}
|
|
5658
5690
|
|
|
5659
5691
|
// dist/ui/inputs/picker-icons.js
|
|
@@ -5687,7 +5719,7 @@ function ModelPicker(props) {
|
|
|
5687
5719
|
const searchable = props.searchable ?? true;
|
|
5688
5720
|
const defaultOption = props.allowDefault === false ? void 0 : { value: "", label: props.defaultLabel ?? tt("modelDefault") };
|
|
5689
5721
|
const catalog = (0, import_react16.useSyncExternalStore)(modelCatalog.subscribe, modelCatalog.getSnapshot, modelCatalog.getSnapshot);
|
|
5690
|
-
const
|
|
5722
|
+
const catalogGroups = props.groups ?? (catalog.status === "ready" ? catalog.routes.map((route) => ({
|
|
5691
5723
|
value: route.provider,
|
|
5692
5724
|
label: route.displayName,
|
|
5693
5725
|
options: route.models.map((model) => ({
|
|
@@ -5695,7 +5727,9 @@ function ModelPicker(props) {
|
|
|
5695
5727
|
label: model.name ?? model.id
|
|
5696
5728
|
}))
|
|
5697
5729
|
})) : []);
|
|
5698
|
-
const
|
|
5730
|
+
const retained = retainSelectedValue(catalogGroups, props.value);
|
|
5731
|
+
const groups = retained.groups;
|
|
5732
|
+
const degraded = props.degraded ?? (catalog.status === "unavailable" || catalog.status === "ready" && catalogGroups.length === 0 || retained.retained);
|
|
5699
5733
|
const icon2 = props.icon === void 0 ? sparkleIcon() : props.icon ?? void 0;
|
|
5700
5734
|
const emitModel = (v) => {
|
|
5701
5735
|
props.onChange?.(typeof v === "string" ? v : v[0] ?? "");
|
|
@@ -5754,7 +5788,8 @@ function ModelPicker(props) {
|
|
|
5754
5788
|
}
|
|
5755
5789
|
const group = groups.find((g) => g.value === provider);
|
|
5756
5790
|
const options = group === void 0 ? [] : flattenOptions([group]);
|
|
5757
|
-
|
|
5791
|
+
const rowClass = ["dshpc-picker__row", props.className, props.rowClassName].filter((part) => part !== void 0 && part !== "").join(" ");
|
|
5792
|
+
return (0, import_react16.createElement)("div", { className: rowClass }, (0, import_react16.createElement)(Picker, {
|
|
5758
5793
|
options: groups.map((g) => ({ value: g.value, label: g.label })),
|
|
5759
5794
|
value: provider === "" ? void 0 : provider,
|
|
5760
5795
|
placeholder: tt("modelProvider"),
|
|
@@ -5764,6 +5799,8 @@ function ModelPicker(props) {
|
|
|
5764
5799
|
searchSizing: props.searchSizing,
|
|
5765
5800
|
searchable,
|
|
5766
5801
|
size: props.size,
|
|
5802
|
+
placement: props.placement,
|
|
5803
|
+
className: props.providerClassName,
|
|
5767
5804
|
translate: props.translate,
|
|
5768
5805
|
onChange: (v) => {
|
|
5769
5806
|
setPickedProvider(typeof v === "string" ? v : v[0] ?? "");
|
|
@@ -5784,7 +5821,7 @@ function ModelPicker(props) {
|
|
|
5784
5821
|
hint: props.hint,
|
|
5785
5822
|
size: props.size,
|
|
5786
5823
|
placement: props.placement,
|
|
5787
|
-
className: props.
|
|
5824
|
+
className: props.modelClassName,
|
|
5788
5825
|
translate: props.translate,
|
|
5789
5826
|
onChange: emitModel
|
|
5790
5827
|
}));
|
|
@@ -63864,8 +63901,12 @@ var docData = {
|
|
|
63864
63901
|
"en": "\xA71 Initialize styles (once at entry): `id` must be unique within the plugin so co-mounted plugins don\u2019t clobber; vars and classes use the fixed `dshpc` prefix, no parameter."
|
|
63865
63902
|
},
|
|
63866
63903
|
{
|
|
63867
|
-
"zh": "\xA72 \u7528\u4E00\u4E2A\u63A7\u4EF6",
|
|
63868
|
-
"en": "\xA72 Use a control"
|
|
63904
|
+
"zh": "\xA72 \u7528\u4E00\u4E2A\u63A7\u4EF6\uFF1A\u901A\u7528 `Picker` \u7684\u9009\u9879\u7531\u8C03\u7528\u65B9\u7ED9\uFF08\u793A\u4F8B\u91CC\u662F `priorities`\uFF0C\u4E0D\u662F\u6A21\u578B\u76EE\u5F55\uFF09\u3002",
|
|
63905
|
+
"en": "\xA72 Use a control: a generic `Picker` takes its options from the caller (`priorities` in the example, not a model catalog)."
|
|
63906
|
+
},
|
|
63907
|
+
{
|
|
63908
|
+
"zh": "\xA72 \u9644\uFF1A\u9009\u6A21\u578B\u4E0D\u8981\u624B\u6413\u6570\u7EC4 \u2014\u2014 \u5BBF\u4E3B `serveModelCatalog(ctx, { path })` \u6CE8\u518C\u53EA\u8BFB\u76EE\u5F55\u8DEF\u7531\uFF0Cclient `connectHost(ctx, { modelsPath: path })` \u7528\u540C\u4E00\u4E2A path \u5E38\u91CF\u63A5\u4E0A\uFF0C\u518D\u6E32\u67D3 `ModelPicker`\uFF1B\u4F9B\u5E94\u5546 / \u6A21\u578B\u6709\u589E\u51CF\u8C03 `await refreshModelCatalog()` \u91CD\u62C9\u3002\u6F0F\u4E86 `modelsPath` \u5C31\u662F\u7A7A\u76EE\u5F55\uFF0C\u4E14\u4E0D\u4F1A\u6709\u62A5\u9519\u3002",
|
|
63909
|
+
"en": "\xA72a Model selection: never hand-roll a models array. Register `serveModelCatalog(ctx, { path })` on the host, call `connectHost(ctx, { modelsPath: path })` on the client with the same path constant, then render `ModelPicker`. `await refreshModelCatalog()` re-pulls the catalog when providers change. Omitting `modelsPath` leaves the catalog empty, silently."
|
|
63869
63910
|
},
|
|
63870
63911
|
{
|
|
63871
63912
|
"zh": "\xA73 \u7528\u901A\u7528\u65B9\u6CD5",
|
|
@@ -63898,7 +63939,12 @@ var docData = {
|
|
|
63898
63939
|
{
|
|
63899
63940
|
"id": "integration-use-control",
|
|
63900
63941
|
"lang": "tsx",
|
|
63901
|
-
"src": "import { Button, Input, Picker, showToast } from 'dsh-plugin-core/ui'\n\nh(Input, { value: name, onChange: setName, placeholder: '\u4EFB\u52A1\u540D', error: nameError })\nh(Button, { variant: 'primary', onClick: save }, '\u4FDD\u5B58')\nh(Picker, {\n options:
|
|
63942
|
+
"src": "import { Button, Input, Picker, showToast } from 'dsh-plugin-core/ui'\n\nh(Input, { value: name, onChange: setName, placeholder: '\u4EFB\u52A1\u540D', error: nameError })\nh(Button, { variant: 'primary', onClick: save }, '\u4FDD\u5B58')\nh(Picker, {\n options: priorities, // [{ value, label }]\uFF1A\u901A\u7528 Picker \u7684\u9009\u9879\u7531\u8C03\u7528\u65B9\u7ED9\n value: current,\n onChange: (v) => setCurrent(v as string),\n searchable: true,\n clearable: true,\n})\nshowToast('\u5DF2\u4FDD\u5B58', { variant: 'success' })"
|
|
63943
|
+
},
|
|
63944
|
+
{
|
|
63945
|
+
"id": "integration-use-model-catalog",
|
|
63946
|
+
"lang": "tsx",
|
|
63947
|
+
"src": "// paths.ts \u2014\u2014 \u5BBF\u4E3B\u4E0E client \u5171\u7528\u540C\u4E00\u4E2A\u5E38\u91CF\nexport const MODELS_PATH = '/api/dsh-task-reminder/models'\n\n// \u5BBF\u4E3B apply\uFF1A\u6CE8\u518C\u53EA\u8BFB\u6A21\u578B\u76EE\u5F55\u8DEF\u7531\nimport { serveModelCatalog } from 'dsh-plugin-core/host'\nserveModelCatalog(ctx, { path: MODELS_PATH })\n\n// client apply\uFF1A\u63A5\u540C\u4E00\u4E2A path\nimport { connectHost, refreshModelCatalog, ModelPicker } from 'dsh-plugin-core/ui'\nconnectHost(ctx, { modelsPath: MODELS_PATH })\n\n// \u4E09\u79CD\u5F62\u6001\u5171\u7528\u540C\u4E00\u4EFD\u76EE\u5F55\uFF0ConChange \u4E00\u5F8B\u53D1 provider/id\nh(ModelPicker, { variant: 'cascade', value: current, onChange: setCurrent })\nawait refreshModelCatalog() // \u4F9B\u5E94\u5546 / \u6A21\u578B\u6709\u589E\u51CF\u65F6\u91CD\u62C9\uFF08Promise\uFF09"
|
|
63902
63948
|
},
|
|
63903
63949
|
{
|
|
63904
63950
|
"id": "integration-use-utils",
|
|
@@ -63975,12 +64021,21 @@ var docData = {
|
|
|
63975
64021
|
}
|
|
63976
64022
|
},
|
|
63977
64023
|
{
|
|
63978
|
-
"name": "\
|
|
63979
|
-
"type": "\u73B0\u8C61\uFF1A\
|
|
64024
|
+
"name": "\u7ED9\u901A\u7528 Picker \u624B\u6413 models \u6570\u7EC4",
|
|
64025
|
+
"type": "\u73B0\u8C61\uFF1A\u5019\u9009\u5199\u6B7B / \u7A7A\u76EE\u5F55",
|
|
64026
|
+
"def": "\u2014",
|
|
64027
|
+
"desc": {
|
|
64028
|
+
"zh": "\u9009\u6A21\u578B\u8D70 ModelPicker + \u5BBF\u4E3B serveModelCatalog / client connectHost(ctx, { modelsPath }) \u4E24\u6BB5\u5F0F\u63A5\u7EBF",
|
|
64029
|
+
"en": "Use ModelPicker with the two-sided serveModelCatalog / connectHost(ctx, { modelsPath }) wiring"
|
|
64030
|
+
}
|
|
64031
|
+
},
|
|
64032
|
+
{
|
|
64033
|
+
"name": "connectHost(ctx) \u4E0D\u5E26 modelsPath",
|
|
64034
|
+
"type": "\u73B0\u8C61\uFF1A\u6A21\u578B\u76EE\u5F55\u6C38\u8FDC\u505C\u5728 loading\uFF0C\u4E0D\u62A5\u9519",
|
|
63980
64035
|
"def": "\u2014",
|
|
63981
64036
|
"desc": {
|
|
63982
|
-
"zh": "\
|
|
63983
|
-
"en": "
|
|
64037
|
+
"zh": "\u6A21\u578B\u76EE\u5F55\u4E0D\u662F\u5FEB\u7167\uFF0C\u5FC5\u987B\u4F20\u5BBF\u4E3B\u6CE8\u518C\u7684\u540C\u4E00\u4E2A path",
|
|
64038
|
+
"en": "The model catalog is an HTTP route, not a snapshot: pass the same path registered on the host"
|
|
63984
64039
|
}
|
|
63985
64040
|
},
|
|
63986
64041
|
{
|
|
@@ -64300,8 +64355,8 @@ var docData = {
|
|
|
64300
64355
|
"en": "WorkspacePicker: a domain picker that brings its own data. Call `connectHost(ctx)` once in the plugin apply and it subscribes to the official `workspaces` snapshot. Unwired = empty state, never fabricated data. Trigger and search-box sizing (`width` / `minWidth` / `maxWidth` / `searchSizing`) matches Picker; `translate` overrides all built-in copy in the component and its dropdown."
|
|
64301
64356
|
},
|
|
64302
64357
|
{
|
|
64303
|
-
"zh": "ModelPicker\uFF1A\u9009\u62E9\u6A21\u578B\u7684\u5B8C\u6574\u5C01\u88C5\uFF0C\u4E09\u79CD\u5F62\u6001\u5171\u7528\u540C\u4E00\u4EFD\u5BBF\u4E3B\u76EE\u5F55\
|
|
64304
|
-
"en":
|
|
64358
|
+
"zh": "ModelPicker\uFF1A\u9009\u62E9\u6A21\u578B\u7684\u5B8C\u6574\u5C01\u88C5\uFF0C\u4E09\u79CD\u5F62\u6001\u5171\u7528\u540C\u4E00\u4EFD\u5BBF\u4E3B\u76EE\u5F55\uFF0C`onChange` \u4E00\u5F8B\u53D1 `provider/id`\uFF1A`grouped`\uFF08\u9ED8\u8BA4\uFF09= \u4E00\u4E2A\u4E0B\u62C9\u3001\u4F9B\u5E94\u5546\u505A\u7EC4\u5934\uFF1B`flat` = \u4E00\u4E2A\u4E0B\u62C9\u3001\u5168\u90E8\u6A21\u578B\u5E73\u94FA\u6210\u300C\u5382\u5546-\u6A21\u578B\u300D\u5E76\u5E26\u641C\u7D22\uFF0C\u641C\u5382\u5546\u540D\u5373\u53EF\u7B5B\uFF1B`cascade` = \u4E24\u4E2A\u4E0B\u62C9\u8054\u52A8\uFF0C\u5382\u5546\u6846\u4E0E\u6A21\u578B\u6846\u90FD\u5E26\u641C\u7D22\uFF0C\u6362\u5382\u5546\u6E05\u7A7A\u6A21\u578B\u3002**\u63A5\u7EBF\u662F\u4E24\u6BB5\u5F0F**\uFF1A\u5BBF\u4E3B `serveModelCatalog(ctx, { path })` + client `connectHost(ctx, { modelsPath: path })` \u7528\u540C\u4E00\u4E2A path \u5E38\u91CF\uFF0C\u6F0F\u4E86 `modelsPath` \u76EE\u5F55\u6C38\u8FDC\u505C\u5728 loading\uFF1B\u4F9B\u5E94\u5546 / \u6A21\u578B\u6709\u589E\u51CF\u65F6 `await refreshModelCatalog()` \u91CD\u62C9\u3002`width` / `minWidth` / `maxWidth` \u7BA1\u89E6\u53D1\u5668\uFF0C`searchSizing` \u7BA1\u6240\u6709\u641C\u7D22\u6846\uFF0C`providerSizing` / `modelSizing` \u8BA9\u8054\u52A8\u6001\u4E24\u4E2A\u6846\u5206\u522B\u8BBE\u5BBD\u3002\u65E7\u503C\u5DF2\u4E0D\u5728\u76EE\u5F55\u91CC\u65F6\u6309\u771F\u5B9E\u503C\u4FDD\u7559\u4E00\u9879\u5E76\u5982\u5B9E\u63D0\u793A\u300C\u5019\u9009\u53EF\u80FD\u4E0D\u5B8C\u6574\u300D\uFF0C\u4E0D\u9759\u9ED8\u4E22\u5F03\u3002\u5BBF\u4E3B\u4FA7 `serveModelCatalog` \u7684 `getLlm` \u53EA\u662F\u53EF\u9009\u53D6\u503C\u8986\u76D6\uFF0C\u4E0D\u4F20\u65F6\u6838\u5FC3\u81EA\u884C\u6536\u53E3\uFF08ctx \u5931\u6D3B\u6309\u4E0D\u53EF\u7528\u56DE 503\uFF09\uFF0C\u6D88\u8D39\u65B9\u4E0D\u5FC5\u5404\u81EA\u9632\u3002",
|
|
64359
|
+
"en": 'ModelPicker: the complete model selector. Three variants share one host catalog and always emit `provider/id`: `grouped` (default) groups models under provider headers in one dropdown; `flat` lists every model as `vendor-model` in one searchable dropdown; `cascade` links two searchable dropdowns (provider then model). **Wiring is two-sided**: `serveModelCatalog(ctx, { path })` on the host and `connectHost(ctx, { modelsPath: path })` on the client with the same path constant \u2014 without `modelsPath` the catalog stays `loading` forever; `await refreshModelCatalog()` re-pulls it when providers change. `width`/`minWidth`/`maxWidth` size triggers, `searchSizing` sizes every search box, and `providerSizing`/`modelSizing` size the two cascade boxes separately. A controlled value no longer present in the catalog is retained as-is with an honest "candidates may be incomplete" hint instead of being silently dropped. The host-side `getLlm` on `serveModelCatalog` is only an optional override \u2014 the core handles a disposed ctx itself and answers 503, so consumers need not guard it.'
|
|
64305
64360
|
}
|
|
64306
64361
|
],
|
|
64307
64362
|
"api": [
|
|
@@ -64669,9 +64724,45 @@ var docData = {
|
|
|
64669
64724
|
"en": "icon: omitted = default star; null = hidden; element = custom"
|
|
64670
64725
|
}
|
|
64671
64726
|
},
|
|
64727
|
+
{
|
|
64728
|
+
"name": "className",
|
|
64729
|
+
"type": "string",
|
|
64730
|
+
"def": "\u2014",
|
|
64731
|
+
"desc": {
|
|
64732
|
+
"zh": "\u7EC4\u4EF6\u6839\u5143\u7D20\uFF1Agrouped / flat \u843D\u5728 Picker \u6839\uFF0Ccascade \u843D\u5728\u4E24\u6846\u5916\u5C42 row",
|
|
64733
|
+
"en": "Root element: the Picker root for grouped/flat, the outer row for cascade"
|
|
64734
|
+
}
|
|
64735
|
+
},
|
|
64736
|
+
{
|
|
64737
|
+
"name": "rowClassName",
|
|
64738
|
+
"type": "string",
|
|
64739
|
+
"def": "\u2014",
|
|
64740
|
+
"desc": {
|
|
64741
|
+
"zh": "cascade \u5916\u5C42 row \u7684\u9644\u52A0\u7C7B\u540D\uFF08\u63A7\u5236\u4E24\u6846\u95F4\u8DDD / \u5E03\u5C40\uFF09",
|
|
64742
|
+
"en": "Extra class for the cascade outer row (gap / layout)"
|
|
64743
|
+
}
|
|
64744
|
+
},
|
|
64745
|
+
{
|
|
64746
|
+
"name": "providerClassName / modelClassName",
|
|
64747
|
+
"type": "string",
|
|
64748
|
+
"def": "\u2014",
|
|
64749
|
+
"desc": {
|
|
64750
|
+
"zh": "cascade \u5382\u5546\u6846 / \u6A21\u578B\u6846\u5404\u81EA\u7684\u7C7B\u540D",
|
|
64751
|
+
"en": "Class for the cascade provider / model box"
|
|
64752
|
+
}
|
|
64753
|
+
},
|
|
64754
|
+
{
|
|
64755
|
+
"name": "refreshModelCatalog()",
|
|
64756
|
+
"type": "(path?: string) => Promise<ModelCatalogState>",
|
|
64757
|
+
"def": "\u2014",
|
|
64758
|
+
"desc": {
|
|
64759
|
+
"zh": "\u4F9B\u5E94\u5546 / \u6A21\u578B\u6709\u589E\u51CF\u65F6\u91CD\u62C9\u76EE\u5F55\uFF1B\u4E0D\u4F20 path \u7528 connectHost \u8BB0\u4E0B\u7684\u90A3\u4E2A\uFF1B\u672A\u63A5\u7EBF\u5219 reject",
|
|
64760
|
+
"en": "Re-pull the catalog when providers change; omit path to reuse the wired one; rejects if unwired"
|
|
64761
|
+
}
|
|
64762
|
+
},
|
|
64672
64763
|
{
|
|
64673
64764
|
"name": "\u900F\u4F20 Picker",
|
|
64674
|
-
"type": "value / defaultValue / onChange / clearable / searchable / hint / size / placement /
|
|
64765
|
+
"type": "value / defaultValue / onChange / clearable / searchable / hint / size / placement / disabled / degraded / translate",
|
|
64675
64766
|
"def": "\u2014",
|
|
64676
64767
|
"desc": {
|
|
64677
64768
|
"zh": "\u540C Picker \u540C\u540D\u53C2\u6570",
|
|
@@ -64686,6 +64777,11 @@ var docData = {
|
|
|
64686
64777
|
"id": "ui-workspacepicker-example",
|
|
64687
64778
|
"lang": "tsx",
|
|
64688
64779
|
"src": "import { WorkspacePicker, connectHost } from 'dsh-plugin-core/ui'\n\n// apply(ctx) \u91CC\uFF1AconnectHost(ctx)\nh(WorkspacePicker, { value: cur, onChange: setCur, clearable: true })"
|
|
64780
|
+
},
|
|
64781
|
+
{
|
|
64782
|
+
"id": "ui-modelpicker-example",
|
|
64783
|
+
"lang": "tsx",
|
|
64784
|
+
"src": "// paths.ts \u2014\u2014 \u5BBF\u4E3B\u4E0E client \u5171\u7528\u540C\u4E00\u4E2A\u5E38\u91CF\nexport const MODELS_PATH = '/api/dsh-task-reminder/models'\n\n// \u5BBF\u4E3B apply\uFF1A\u6CE8\u518C\u53EA\u8BFB\u6A21\u578B\u76EE\u5F55\u8DEF\u7531\nimport { serveModelCatalog } from 'dsh-plugin-core/host'\nserveModelCatalog(ctx, { path: MODELS_PATH })\n\n// client apply\uFF1A\u63A5\u540C\u4E00\u4E2A path\nimport { connectHost, refreshModelCatalog, ModelPicker } from 'dsh-plugin-core/ui'\nconnectHost(ctx, { modelsPath: MODELS_PATH })\n\n// \u4E09\u79CD\u5F62\u6001\u5171\u7528\u540C\u4E00\u4EFD\u76EE\u5F55\uFF0ConChange \u4E00\u5F8B\u53D1 provider/id\nh(ModelPicker, { variant: 'cascade', value: current, onChange: setCurrent })\nawait refreshModelCatalog() // \u4F9B\u5E94\u5546 / \u6A21\u578B\u6709\u589E\u51CF\u65F6\u91CD\u62C9\uFF08Promise\uFF09"
|
|
64689
64785
|
}
|
|
64690
64786
|
]
|
|
64691
64787
|
},
|
|
@@ -71248,9 +71344,9 @@ function ReferencePage() {
|
|
|
71248
71344
|
"tbody",
|
|
71249
71345
|
null,
|
|
71250
71346
|
[
|
|
71251
|
-
[t3("buildCore"), `v${"0.35.
|
|
71252
|
-
[t3("buildDemo"), `v${"0.35.
|
|
71253
|
-
[t3("buildStamp"), "261110-
|
|
71347
|
+
[t3("buildCore"), `v${"0.35.14"}`],
|
|
71348
|
+
[t3("buildDemo"), `v${"0.35.14"}`],
|
|
71349
|
+
[t3("buildStamp"), "261110-084237-247"]
|
|
71254
71350
|
].map(
|
|
71255
71351
|
([label, value]) => (0, import_react98.createElement)(
|
|
71256
71352
|
"tr",
|
|
@@ -71566,9 +71662,9 @@ function DemoPage() {
|
|
|
71566
71662
|
lineHeight: "14px"
|
|
71567
71663
|
}
|
|
71568
71664
|
},
|
|
71569
|
-
(0, import_react100.createElement)("span", null, `core v${"0.35.
|
|
71570
|
-
(0, import_react100.createElement)("span", null, `demo v${"0.35.
|
|
71571
|
-
(0, import_react100.createElement)("span", { style: { marginTop: "4px", fontSize: "9px" } }, "261110-
|
|
71665
|
+
(0, import_react100.createElement)("span", null, `core v${"0.35.14"}`),
|
|
71666
|
+
(0, import_react100.createElement)("span", null, `demo v${"0.35.14"}`),
|
|
71667
|
+
(0, import_react100.createElement)("span", { style: { marginTop: "4px", fontSize: "9px" } }, "261110-084237-247")
|
|
71572
71668
|
)
|
|
71573
71669
|
)
|
|
71574
71670
|
),
|
package/dist/index.js
CHANGED
|
@@ -1107,19 +1107,45 @@ async function buildModelRoutes(llm) {
|
|
|
1107
1107
|
routes.sort((left, right) => left.displayName.localeCompare(right.displayName));
|
|
1108
1108
|
return routes;
|
|
1109
1109
|
}
|
|
1110
|
+
var JSON_HEADERS = { "content-type": "application/json; charset=utf-8" };
|
|
1111
|
+
function resolveLlm(ctx, options) {
|
|
1112
|
+
const fromHook = options.getLlm?.();
|
|
1113
|
+
if (fromHook !== void 0)
|
|
1114
|
+
return fromHook;
|
|
1115
|
+
try {
|
|
1116
|
+
return ctx.get?.("llm");
|
|
1117
|
+
} catch {
|
|
1118
|
+
return void 0;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1110
1121
|
function serveModelCatalog(ctx, options) {
|
|
1111
|
-
ctx.inject(["
|
|
1112
|
-
const llm = services.llm;
|
|
1122
|
+
ctx.inject(["webServer"], (services) => {
|
|
1113
1123
|
const webServer = services.webServer;
|
|
1114
|
-
if (
|
|
1124
|
+
if (webServer === void 0)
|
|
1115
1125
|
return;
|
|
1116
1126
|
webServer.register({
|
|
1117
1127
|
kind: "exact",
|
|
1118
1128
|
path: options.path,
|
|
1119
|
-
handler: async (
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1129
|
+
handler: async (req, res) => {
|
|
1130
|
+
if (options.authorize !== void 0 && !await options.authorize(req)) {
|
|
1131
|
+
res.writeHead(403, JSON_HEADERS);
|
|
1132
|
+
res.end(JSON.stringify({ error: "forbidden" }));
|
|
1133
|
+
return;
|
|
1134
|
+
}
|
|
1135
|
+
const llm = resolveLlm(ctx, options);
|
|
1136
|
+
if (llm === void 0) {
|
|
1137
|
+
res.writeHead(503, JSON_HEADERS);
|
|
1138
|
+
res.end(JSON.stringify({ routes: [], error: "llm-unavailable" }));
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
try {
|
|
1142
|
+
const routes = await buildModelRoutes(llm);
|
|
1143
|
+
res.writeHead(200, JSON_HEADERS);
|
|
1144
|
+
res.end(JSON.stringify({ routes }));
|
|
1145
|
+
} catch (error) {
|
|
1146
|
+
res.writeHead(500, JSON_HEADERS);
|
|
1147
|
+
res.end(JSON.stringify({ routes: [], error: String(error) }));
|
|
1148
|
+
}
|
|
1123
1149
|
}
|
|
1124
1150
|
});
|
|
1125
1151
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-core-demo",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.14",
|
|
4
4
|
"description": "The shared UI foundation for DSH plugins, with a live component preview: design tokens, common controls, workspace browsing and notifications maintained in one place — install it to preview every component in a real host.",
|
|
5
5
|
"icon": "./assets/icon-components.svg",
|
|
6
6
|
"keywords": [
|