@musdrop/ds-harness-remote 0.6.14 → 0.6.17

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 CHANGED
@@ -2224,7 +2224,8 @@ If a code was sent, recover the original submission without changing it.`,
2224
2224
  modelShareRuleAnyDeviceHint: "A rule without any selected device applies to every authorized peer.",
2225
2225
  modelShareEdit: "Edit",
2226
2226
  modelShareSaveEdit: "Save rule",
2227
- modelShareSelectModelsHint: "No models selected yet"
2227
+ modelShareSelectModelsHint: "No models selected yet",
2228
+ modelShareClearDraft: "Clear form"
2228
2229
  }, zh = {
2229
2230
  uploadTooLarge: "\u6587\u4EF6\u8D85\u8FC7\u5F53\u524D\u8FDE\u63A5\u7684\u5355\u6587\u4EF6\u4E0A\u4F20\u4E0A\u9650\uFF08{size}\uFF09\u3002",
2230
2231
  relayUploadTooLarge: "\u6587\u4EF6\u8D85\u8FC7\u5F53\u524D\u8FDE\u63A5\u7684\u5355\u6587\u4EF6\u4E0A\u4F20\u4E0A\u9650\uFF08{size}\uFF09\u3002Relay \u548C TURN \u4E0A\u4F20\u65F6\uFF0C\u666E\u901A\u7528\u6237\u6BCF\u4E2A\u6587\u4EF6\u6700\u591A 20 MiB\uFF0C\u652F\u6301\u4F1A\u5458\u989D\u5EA6\u7684\u8FDE\u63A5\u6700\u591A 100 MiB\u3002",
@@ -2671,7 +2672,8 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
2671
2672
  modelShareRuleAnyDeviceHint: "\u672A\u9009\u62E9\u4EFB\u4F55\u8BBE\u5907\u7684\u89C4\u5219\u5BF9\u6240\u6709\u5DF2\u6388\u6743\u7684\u8BBE\u5907\u751F\u6548\u3002",
2672
2673
  modelShareEdit: "\u7F16\u8F91",
2673
2674
  modelShareSaveEdit: "\u4FDD\u5B58\u89C4\u5219",
2674
- modelShareSelectModelsHint: "\u5C1A\u672A\u9009\u62E9\u6A21\u578B"
2675
+ modelShareSelectModelsHint: "\u5C1A\u672A\u9009\u62E9\u6A21\u578B",
2676
+ modelShareClearDraft: "\u6E05\u7A7A\u8868\u5355"
2675
2677
  }, ru = {
2676
2678
  uploadTooLarge: "\u0424\u0430\u0439\u043B \u043F\u0440\u0435\u0432\u044B\u0448\u0430\u0435\u0442 \u0442\u0435\u043A\u0443\u0449\u0438\u0439 \u043B\u0438\u043C\u0438\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0438 ({size}).",
2677
2679
  relayUploadTooLarge: "\u0424\u0430\u0439\u043B \u043F\u0440\u0435\u0432\u044B\u0448\u0430\u0435\u0442 \u0442\u0435\u043A\u0443\u0449\u0438\u0439 \u043B\u0438\u043C\u0438\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0438 ({size}). \u0427\u0435\u0440\u0435\u0437 Relay \u0438 TURN \u043B\u0438\u043C\u0438\u0442 \u0441\u043E\u0441\u0442\u0430\u0432\u043B\u044F\u0435\u0442 20 \u041C\u0438\u0411 \u043D\u0430 \u0444\u0430\u0439\u043B \u0438\u043B\u0438 100 \u041C\u0438\u0411, \u0435\u0441\u043B\u0438 \u0441\u043E\u0435\u0434\u0438\u043D\u0435\u043D\u0438\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043B\u0438\u043C\u0438\u0442 \u043F\u043E\u0434\u043F\u0438\u0441\u043A\u0438.",
@@ -3118,7 +3120,8 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
3118
3120
  modelShareRuleAnyDeviceHint: "\u041F\u0440\u0430\u0432\u0438\u043B\u043E \u0431\u0435\u0437 \u0432\u044B\u0431\u0440\u0430\u043D\u043D\u044B\u0445 \u0443\u0441\u0442\u0440\u043E\u0439\u0441\u0442\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u043B\u044F \u0432\u0441\u0435\u0445 \u0430\u0432\u0442\u043E\u0440\u0438\u0437\u043E\u0432\u0430\u043D\u043D\u044B\u0445 \u0443\u0441\u0442\u0440\u043E\u0439\u0441\u0442\u0432.",
3119
3121
  modelShareEdit: "\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C",
3120
3122
  modelShareSaveEdit: "\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C \u043F\u0440\u0430\u0432\u0438\u043B\u043E",
3121
- modelShareSelectModelsHint: "\u041C\u043E\u0434\u0435\u043B\u0438 \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D\u044B"
3123
+ modelShareSelectModelsHint: "\u041C\u043E\u0434\u0435\u043B\u0438 \u043D\u0435 \u0432\u044B\u0431\u0440\u0430\u043D\u044B",
3124
+ modelShareClearDraft: "\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C \u0444\u043E\u0440\u043C\u0443"
3122
3125
  }, uk = {
3123
3126
  uploadTooLarge: "\u0424\u0430\u0439\u043B \u043F\u0435\u0440\u0435\u0432\u0438\u0449\u0443\u0454 \u043F\u043E\u0442\u043E\u0447\u043D\u0438\u0439 \u043B\u0456\u043C\u0456\u0442 \u0437\u0430\u0432\u0430\u043D\u0442\u0430\u0436\u0435\u043D\u043D\u044F ({size}).",
3124
3127
  relayUploadTooLarge: "\u0424\u0430\u0439\u043B \u043F\u0435\u0440\u0435\u0432\u0438\u0449\u0443\u0454 \u043F\u043E\u0442\u043E\u0447\u043D\u0438\u0439 \u043B\u0456\u043C\u0456\u0442 \u0437\u0430\u0432\u0430\u043D\u0442\u0430\u0436\u0435\u043D\u043D\u044F ({size}). \u0427\u0435\u0440\u0435\u0437 Relay \u0456 TURN \u043B\u0456\u043C\u0456\u0442 \u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u044C 20 \u041C\u0456\u0411 \u043D\u0430 \u0444\u0430\u0439\u043B \u0430\u0431\u043E 100 \u041C\u0456\u0411, \u044F\u043A\u0449\u043E \u0437\u2019\u0454\u0434\u043D\u0430\u043D\u043D\u044F \u043F\u0456\u0434\u0442\u0440\u0438\u043C\u0443\u0454 \u043B\u0456\u043C\u0456\u0442 \u043F\u0435\u0440\u0435\u0434\u043F\u043B\u0430\u0442\u0438.",
@@ -3565,7 +3568,8 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
3565
3568
  modelShareRuleAnyDeviceHint: "\u041F\u0440\u0430\u0432\u0438\u043B\u043E \u0431\u0435\u0437 \u0432\u0438\u0431\u0440\u0430\u043D\u0438\u0445 \u043F\u0440\u0438\u0441\u0442\u0440\u043E\u0457\u0432 \u0434\u0456\u0454 \u0434\u043B\u044F \u0432\u0441\u0456\u0445 \u0430\u0432\u0442\u043E\u0440\u0438\u0437\u043E\u0432\u0430\u043D\u0438\u0445 \u043F\u0440\u0438\u0441\u0442\u0440\u043E\u0457\u0432.",
3566
3569
  modelShareEdit: "\u0420\u0435\u0434\u0430\u0433\u0443\u0432\u0430\u0442\u0438",
3567
3570
  modelShareSaveEdit: "\u0417\u0431\u0435\u0440\u0435\u0433\u0442\u0438 \u043F\u0440\u0430\u0432\u0438\u043B\u043E",
3568
- modelShareSelectModelsHint: "\u041C\u043E\u0434\u0435\u043B\u0456 \u043D\u0435 \u0432\u0438\u0431\u0440\u0430\u043D\u043E"
3571
+ modelShareSelectModelsHint: "\u041C\u043E\u0434\u0435\u043B\u0456 \u043D\u0435 \u0432\u0438\u0431\u0440\u0430\u043D\u043E",
3572
+ modelShareClearDraft: "\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u0438 \u0444\u043E\u0440\u043C\u0443"
3569
3573
  };
3570
3574
 
3571
3575
  // packages/plugin/src/client/header.ts
@@ -4355,6 +4359,7 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4355
4359
 
4356
4360
  // packages/plugin/src/client/model-sharing.ts
4357
4361
  init_page_globals();
4362
+ var ROUTE_SEPARATOR = "::";
4358
4363
  function Chevron(React) {
4359
4364
  return React.createElement("svg", {
4360
4365
  width: 12,
@@ -4373,7 +4378,7 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4373
4378
  }
4374
4379
  function createModelSharingSection(React) {
4375
4380
  return function(props) {
4376
- let { control, t, available = !0 } = props, [view, setView] = React.useState(void 0), [busy, setBusy] = React.useState(!1), [error, setError] = React.useState(void 0), [notice, setNotice] = React.useState(void 0), [grantSelectedModels, setGrantSelectedModels] = React.useState([]), [grantAllOfProvider, setGrantAllOfProvider] = React.useState([]), [grantAnyDevice, setGrantAnyDevice] = React.useState(!0), [grantDevices, setGrantDevices] = React.useState([]), [editingGrant, setEditingGrant] = React.useState(!1), [concurrencyDraft, setConcurrencyDraft] = React.useState(void 0), viewRef = React.useRef(void 0), queueRef = React.useRef(Promise.resolve()), busyRef = React.useRef(!1), applyView = (next) => {
4381
+ let { control, t, available = !0 } = props, [view, setView] = React.useState(void 0), [busy, setBusy] = React.useState(!1), [error, setError] = React.useState(void 0), [notice, setNotice] = React.useState(void 0), [draftModels, setDraftModels] = React.useState([]), [draftDevices, setDraftDevices] = React.useState([]), [draftAnyDevice, setDraftAnyDevice] = React.useState(!0), [editingIndex, setEditingIndex] = React.useState(void 0), [concurrencyDraft, setConcurrencyDraft] = React.useState(void 0), viewRef = React.useRef(void 0), queueRef = React.useRef(Promise.resolve()), busyRef = React.useRef(!1), applyView = (next) => {
4377
4382
  viewRef.current = next, setView(next), setConcurrencyDraft(void 0);
4378
4383
  }, load = React.useCallback(async () => {
4379
4384
  setError(void 0);
@@ -4382,7 +4387,7 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4382
4387
  } catch (reason) {
4383
4388
  setError(messageOf(reason, t));
4384
4389
  }
4385
- }, [control]);
4390
+ }, [control, t]);
4386
4391
  React.useEffect(() => {
4387
4392
  load();
4388
4393
  }, [load]);
@@ -4402,59 +4407,51 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4402
4407
  enqueue((current) => ({ ...current, host: { ...current.host, ...changes } }));
4403
4408
  }, patchSources = (sources) => {
4404
4409
  enqueue((current) => ({ ...current, borrower: { ...current.borrower, sources } }));
4405
- }, toggleSource = (deviceId, hostName) => {
4406
- if (view === void 0) return;
4407
- let sources = { ...view.store.borrower.sources }, current = sources[deviceId];
4408
- sources[deviceId] = {
4409
- enabled: !(current?.enabled ?? !1),
4410
- models: current?.models ?? [],
4411
- hostName: current?.hostName ?? hostName
4412
- }, patchSources(sources);
4413
- }, removeGrant = (index) => {
4414
- view !== void 0 && patchHost({ grants: view.store.host.grants.filter((_, i) => i !== index) });
4415
- }, toggleGrantModel = (routeKey) => {
4416
- setGrantSelectedModels((current) => current.includes(routeKey) ? current.filter((id) => id !== routeKey) : [...current, routeKey]);
4417
- }, toggleGrantAllOfProvider = (provider) => {
4418
- setGrantAllOfProvider((current) => current.includes(provider) ? current.filter((id) => id !== provider) : [...current, provider]);
4419
- }, toggleGrantDevice = (deviceId) => {
4420
- setGrantDevices((current) => current.includes(deviceId) ? current.filter((id) => id !== deviceId) : [...current, deviceId]);
4421
- }, addGrant = () => {
4422
- if (view === void 0) return;
4423
- let anyDevice = grantAnyDevice || grantDevices.length === 0, replaced = new Set(anyDevice ? ["*"] : grantDevices), selected = new Set(grantSelectedModels), allProviders = new Set(grantAllOfProvider), grants = view.store.host.grants.filter((grant) => allProviders.has(grant.provider) ? !1 : grant.models.length === 0 ? !0 : !grant.models.some((model) => selected.has(`${grant.provider}::${model}`)));
4424
- for (let deviceId of anyDevice ? [void 0] : grantDevices) {
4425
- for (let provider of grantAllOfProvider)
4426
- grants.push({ ...deviceId === void 0 ? {} : { deviceId }, provider, models: [] });
4427
- for (let route of grantSelectedModels) {
4428
- let separator = route.indexOf("::");
4429
- if (separator <= 0) continue;
4430
- let provider = route.slice(0, separator);
4431
- allProviders.has(provider) || grants.push({
4432
- ...deviceId === void 0 ? {} : { deviceId },
4433
- provider,
4434
- models: [.../* @__PURE__ */ new Set([
4435
- ...grants.filter((grant) => grant.provider === provider && grant.deviceId === deviceId).flatMap((grant) => grant.models),
4436
- route.slice(separator + 2)
4437
- ])]
4438
- });
4439
- }
4440
- }
4441
- patchHost({ grants, enabled: !0 }), setGrantSelectedModels([]), setGrantAllOfProvider([]), setGrantAnyDevice(!0), setGrantDevices([]), setEditingGrant(!1);
4442
- }, resetGrantForm = () => {
4443
- setGrantSelectedModels([]), setGrantAllOfProvider([]), setGrantAnyDevice(!0), setGrantDevices([]), setEditingGrant(!1);
4444
- }, label = (device) => `${device.name}${device.online ? ` \xB7 ${t("modelShareOnline")}` : device.known ? ` \xB7 ${t("modelShareOffline")}` : ""}`, peerName = (deviceId) => view?.peers.find((device) => device.deviceId === deviceId)?.name ?? deviceId, grantModelsSummary = (models) => models.length === 0 ? t("modelShareAllModels") : models.join(", "), borrowStatus = (deviceId, source) => {
4410
+ }, toggleDraftModel = (route) => {
4411
+ setDraftModels((current) => current.includes(route) ? current.filter((id) => id !== route) : [...current, route]);
4412
+ }, toggleDraftDevice = (deviceId) => {
4413
+ setDraftDevices((current) => current.includes(deviceId) ? current.filter((id) => id !== deviceId) : [...current, deviceId]);
4414
+ }, resetDraft = () => {
4415
+ setDraftModels([]), setDraftDevices([]), setDraftAnyDevice(!0), setEditingIndex(void 0);
4416
+ }, saveRule = () => {
4417
+ view === void 0 || draftModels.length === 0 || (enqueue((current) => {
4418
+ let rules = [...current.host.rules], rule = {
4419
+ models: [...draftModels],
4420
+ devices: draftAnyDevice || draftDevices.length === 0 ? [] : [...draftDevices]
4421
+ };
4422
+ return editingIndex !== void 0 && editingIndex < rules.length ? rules[editingIndex] = rule : rules.push(rule), { ...current, host: { ...current.host, rules, enabled: !0 } };
4423
+ }), resetDraft());
4424
+ }, startEdit = (index) => {
4425
+ let rule = view?.store.host.rules[index];
4426
+ rule !== void 0 && (setDraftModels([...rule.models]), setDraftDevices([...rule.devices]), setDraftAnyDevice(rule.devices.length === 0), setEditingIndex(index));
4427
+ }, removeRule = (index) => {
4428
+ view !== void 0 && (editingIndex === index && resetDraft(), patchHost({ rules: view.store.host.rules.filter((_, i) => i !== index) }));
4429
+ }, label = (device) => `${device.name}${device.online ? ` \xB7 ${t("modelShareOnline")}` : device.known ? ` \xB7 ${t("modelShareOffline")}` : ""}`, peerName = (deviceId) => view?.peers.find((device) => device.deviceId === deviceId)?.name ?? deviceId, ruleSummary = (rule) => [
4430
+ rule.models.map((route) => {
4431
+ let separator = route.indexOf(ROUTE_SEPARATOR), provider = route.slice(0, separator), model = route.slice(separator + ROUTE_SEPARATOR.length), providerName = view?.localProviders.find((candidate) => candidate.id === provider)?.name ?? provider;
4432
+ if (model === "*") return `${providerName}: ${t("modelShareAllModels")}`;
4433
+ let modelName = view?.localProviders.find((candidate) => candidate.id === provider)?.models.find((candidate) => candidate.id === model)?.name;
4434
+ return `${providerName} / ${modelName ?? model}`;
4435
+ }).join(", "),
4436
+ rule.devices.length === 0 ? t("modelShareAnyDevice") : rule.devices.map(peerName).join(", ")
4437
+ ], borrowStatus = (deviceId, source) => {
4445
4438
  if (view === void 0 || source?.enabled !== !0) return;
4446
4439
  let diagnostics = view.borrowerDiagnostics;
4447
4440
  if (diagnostics.syncAvailable !== !0)
4448
4441
  return { cls: " isFailed", text: t("modelShareBorrowStatusDisconnected") };
4449
4442
  let entry = diagnostics.sources.find((item) => item.hostId === deviceId);
4450
- if (entry !== void 0) {
4451
- if (entry.outcome === "registered")
4452
- return { cls: " isPassed", text: t("modelShareBorrowStatusOk", { count: entry.modelCount }) };
4453
- if (entry.outcome === "failed")
4454
- return { cls: " isFailed", text: t("modelShareBorrowStatusFailed", { reason: entry.error ?? "" }) };
4455
- if (entry.outcome === "host-disabled" || entry.outcome === "no-models")
4456
- return { cls: " isFailed", text: t("modelShareBorrowStatusPeerEmpty") };
4457
- }
4443
+ if (entry !== void 0)
4444
+ switch (entry.outcome) {
4445
+ case "registered":
4446
+ return { cls: "", text: t("modelShareBorrowStatusOk", { count: entry.modelCount }) };
4447
+ case "host-disabled":
4448
+ case "no-models":
4449
+ return { cls: " isFailed", text: t("modelShareBorrowStatusPeerEmpty") };
4450
+ case "failed":
4451
+ return { cls: " isFailed", text: t("modelShareBorrowStatusFailed", { reason: entry.error ?? "" }) };
4452
+ default:
4453
+ return;
4454
+ }
4458
4455
  };
4459
4456
  if (view === void 0)
4460
4457
  return React.createElement(
@@ -4467,12 +4464,7 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4467
4464
  React.createElement("p", null, error ?? t("modelShareNotLoaded"))
4468
4465
  )
4469
4466
  );
4470
- let { host, borrower } = view.store, disabled = busy || !view.writable || !available, draftModels = view.localProviders.flatMap((provider) => provider.models.map((model) => ({ provider, model }))), selectedCount = grantSelectedModels.length + grantAllOfProvider.length, modelsSummary = selectedCount === 0 ? t("modelShareSelectModelsHint") : t("modelShareSelectedCount", { count: selectedCount }), devicesSummary = grantAnyDevice || grantDevices.length === 0 ? t("modelShareAnyDevice") : t("modelShareSelectedCount", { count: grantDevices.length }), deviceSummaryLine = `${t("modelShareDevice")}: ${devicesSummary}`, modelSummaryLine = `${t("modelShareModels")}: ${modelsSummary}`, grantGroups = [];
4471
- host.grants.forEach((grant, index) => {
4472
- let group = grantGroups.find((candidate) => candidate.provider === grant.provider);
4473
- group === void 0 && (group = { provider: grant.provider, entries: [] }, grantGroups.push(group)), group.entries.push({ index, grant });
4474
- });
4475
- let lendingRows = React.createElement(
4467
+ let { host, borrower } = view.store, disabled = busy || !view.writable || !available, selectedCount = draftModels.length, modelsSummary = selectedCount === 0 ? t("modelShareSelectModelsHint") : t("modelShareSelectedCount", { count: selectedCount }), devicesSummary = draftAnyDevice || draftDevices.length === 0 ? t("modelShareAnyDevice") : t("modelShareSelectedCount", { count: draftDevices.length }), deviceSummaryLine = `${t("modelShareDevice")}: ${devicesSummary}`, modelSummaryLine = `${t("modelShareModels")}: ${modelsSummary}`, lendingRows = React.createElement(
4476
4468
  "div",
4477
4469
  { className: "dshRemoteAcpList" },
4478
4470
  React.createElement(
@@ -4484,11 +4476,7 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4484
4476
  React.createElement(
4485
4477
  "div",
4486
4478
  { className: "dshRemoteAcpRowInfo" },
4487
- React.createElement(
4488
- "div",
4489
- { className: "dshRemoteAcpRowInfo" },
4490
- React.createElement("strong", { className: "dshRemoteAcpName" }, t("modelShareMaxConcurrent"))
4491
- )
4479
+ React.createElement("strong", { className: "dshRemoteAcpName" }, t("modelShareMaxConcurrent"))
4492
4480
  ),
4493
4481
  React.createElement(
4494
4482
  "div",
@@ -4511,61 +4499,33 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4511
4499
  ),
4512
4500
  React.createElement("p", { className: "dshRemoteAcpDiag" }, t("modelShareRuleAnyDeviceHint"))
4513
4501
  ),
4514
- ...grantGroups.map((group) => React.createElement(
4502
+ ...host.rules.map((rule, index) => React.createElement(
4515
4503
  "div",
4516
4504
  {
4517
- key: `grant-group-${group.provider}`,
4518
- className: "dshRemoteAcpRow"
4505
+ key: `rule-${index}`,
4506
+ className: "dshRemoteModelShareGrantEntry"
4519
4507
  },
4508
+ React.createElement("span", null, ruleSummary(rule).join(" \xB7 ")),
4520
4509
  React.createElement(
4521
4510
  "div",
4522
- { className: "dshRemoteAcpRowMain" },
4523
- React.createElement(
4524
- "div",
4525
- { className: "dshRemoteAcpRowInfo" },
4526
- React.createElement("strong", { className: "dshRemoteAcpName" }, group.provider)
4527
- )
4528
- ),
4529
- React.createElement(
4530
- "p",
4531
- { className: "dshRemoteAcpDiag" },
4532
- grantModelsSummary([...new Set(group.entries.map((entry) => entry.grant.models).flat())])
4533
- ),
4534
- ...group.entries.map((entry) => React.createElement(
4535
- "div",
4536
- {
4537
- key: `grant-${entry.index}`,
4538
- className: "dshRemoteModelShareGrantEntry"
4539
- },
4540
- React.createElement("span", null, [
4541
- entry.grant.deviceId === void 0 ? t("modelShareAnyDevice") : peerName(entry.grant.deviceId),
4542
- grantModelsSummary(entry.grant.models)
4543
- ].join(" \xB7 ")),
4544
- React.createElement(
4545
- "div",
4546
- { className: "dshRemoteAcpRowActions" },
4547
- React.createElement("button", {
4548
- type: "button",
4549
- className: "dshRemoteAcpActionBtn",
4550
- disabled,
4551
- "aria-label": `${t("modelShareEdit")}: ${group.provider}${entry.grant.deviceId === void 0 ? "" : ` \u2192 ${peerName(entry.grant.deviceId)}`}`,
4552
- // Edit = prefill the form from this grant and drop the saved
4553
- // entry; saving the form writes the edited rule back.
4554
- onClick: () => {
4555
- setGrantAnyDevice(entry.grant.deviceId === void 0), setGrantDevices(entry.grant.deviceId === void 0 ? [] : [entry.grant.deviceId]), entry.grant.models.length === 0 ? (setGrantAllOfProvider([group.provider]), setGrantSelectedModels([])) : (setGrantAllOfProvider([]), setGrantSelectedModels(entry.grant.models.map((model) => `${group.provider}::${model}`))), removeGrant(entry.index), setEditingGrant(!0);
4556
- }
4557
- }, t("modelShareEdit")),
4558
- React.createElement("button", {
4559
- type: "button",
4560
- className: "dshRemoteAcpRemoveBtn",
4561
- disabled,
4562
- "aria-label": `${t("modelShareRemove")}: ${group.provider}${entry.grant.deviceId === void 0 ? "" : ` \u2192 ${peerName(entry.grant.deviceId)}`}`,
4563
- onClick: () => removeGrant(entry.index)
4564
- }, t("modelShareRemove"))
4565
- )
4566
- ))
4511
+ { className: "dshRemoteAcpRowActions" },
4512
+ React.createElement("button", {
4513
+ type: "button",
4514
+ className: "dshRemoteAcpActionBtn",
4515
+ disabled,
4516
+ "aria-label": `${t("modelShareEdit")} #${index + 1}`,
4517
+ onClick: () => startEdit(index)
4518
+ }, t("modelShareEdit")),
4519
+ React.createElement("button", {
4520
+ type: "button",
4521
+ className: "dshRemoteAcpRemoveBtn",
4522
+ disabled,
4523
+ "aria-label": `${t("modelShareRemove")} #${index + 1}`,
4524
+ onClick: () => removeRule(index)
4525
+ }, t("modelShareRemove"))
4526
+ )
4567
4527
  )),
4568
- host.grants.length === 0 ? React.createElement("p", { className: "dshRemoteAcpDiag" }, t("modelShareNoGrants")) : null,
4528
+ host.rules.length === 0 ? React.createElement("p", { className: "dshRemoteAcpDiag" }, t("modelShareNoGrants")) : null,
4569
4529
  React.createElement(
4570
4530
  "div",
4571
4531
  { className: "dshRemoteAcpAddForm" },
@@ -4575,19 +4535,19 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4575
4535
  React.createElement("button", {
4576
4536
  type: "button",
4577
4537
  className: "dshRemoteAcpAddTrigger",
4578
- disabled: disabled || grantSelectedModels.length === 0 && grantAllOfProvider.length === 0,
4579
- onClick: addGrant
4580
- }, t(editingGrant ? "modelShareSaveEdit" : "modelShareAddGrant")),
4581
- editingGrant ? React.createElement("button", {
4538
+ disabled: disabled || draftModels.length === 0,
4539
+ onClick: saveRule
4540
+ }, t(editingIndex !== void 0 ? "modelShareSaveEdit" : "modelShareAddGrant")),
4541
+ draftModels.length > 0 || draftDevices.length > 0 || editingIndex !== void 0 ? React.createElement("button", {
4582
4542
  type: "button",
4583
4543
  className: "dshRemoteAcpAddTrigger",
4584
4544
  disabled,
4585
- onClick: resetGrantForm
4586
- }, t("cancelServiceAddressEdit")) : null
4545
+ onClick: resetDraft
4546
+ }, t("modelShareClearDraft")) : null
4587
4547
  ),
4588
- // One flat picker: every provider's models, grouped under provider
4589
- // headings, all selectable in a single pass. A provider heading row
4590
- // checks all of that provider's models at once.
4548
+ // One flat picker: every provider's models under provider headings,
4549
+ // all selectable in a single pass. The heading checkbox adds that
4550
+ // provider's wildcard route (all current models).
4591
4551
  React.createElement(
4592
4552
  "details",
4593
4553
  { className: "dshRemoteModelSharePicker" },
@@ -4596,7 +4556,7 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4596
4556
  "div",
4597
4557
  { className: "dshRemoteModelSharePickerList", role: "group", "aria-label": t("modelShareModels") },
4598
4558
  ...view.localProviders.map((provider) => {
4599
- let allChecked = grantAllOfProvider.includes(provider.id);
4559
+ let wildcard = `${provider.id}${ROUTE_SEPARATOR}*`;
4600
4560
  return React.createElement(
4601
4561
  "div",
4602
4562
  { key: `prov-${provider.id}`, className: "dshRemoteModelShareProviderGroup" },
@@ -4605,26 +4565,25 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4605
4565
  { className: "dshRemoteModelShareProviderHeading" },
4606
4566
  React.createElement("input", {
4607
4567
  type: "checkbox",
4608
- checked: allChecked,
4568
+ checked: draftModels.includes(wildcard),
4609
4569
  disabled,
4610
4570
  "aria-label": `${t("modelShareAllModels")}: ${provider.name ?? provider.id}`,
4611
- onChange: () => toggleGrantAllOfProvider(provider.id)
4571
+ onChange: () => toggleDraftModel(wildcard)
4612
4572
  }),
4613
4573
  React.createElement("strong", null, provider.name ?? provider.id)
4614
4574
  ),
4615
4575
  ...provider.models.map((model) => {
4616
- let route = `${provider.id}::${model.id}`;
4576
+ let route = `${provider.id}${ROUTE_SEPARATOR}${model.id}`;
4617
4577
  return React.createElement(
4618
4578
  "label",
4619
4579
  { key: `model-${route}` },
4620
4580
  React.createElement("input", {
4621
4581
  type: "checkbox",
4622
- checked: allChecked || grantSelectedModels.includes(route),
4623
- // An "all of this provider" heading supersedes the
4624
- // individual boxes of that provider.
4625
- disabled: disabled || allChecked,
4582
+ checked: draftModels.includes(route) || draftModels.includes(wildcard),
4583
+ // The provider wildcard supersedes its individual boxes.
4584
+ disabled: disabled || draftModels.includes(wildcard),
4626
4585
  "aria-label": `${provider.name ?? provider.id} / ${model.name ?? model.id}`,
4627
- onChange: () => toggleGrantModel(route)
4586
+ onChange: () => toggleDraftModel(route)
4628
4587
  }),
4629
4588
  model.name ?? model.id
4630
4589
  );
@@ -4646,10 +4605,10 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4646
4605
  null,
4647
4606
  React.createElement("input", {
4648
4607
  type: "checkbox",
4649
- checked: grantAnyDevice,
4608
+ checked: draftAnyDevice,
4650
4609
  disabled,
4651
4610
  "aria-label": t("modelShareAnyDevice"),
4652
- onChange: (event) => setGrantAnyDevice(event.target.checked)
4611
+ onChange: (event) => setDraftAnyDevice(event.target.checked)
4653
4612
  }),
4654
4613
  t("modelShareAnyDevice")
4655
4614
  ),
@@ -4658,10 +4617,10 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4658
4617
  { key: `device-${device.deviceId}` },
4659
4618
  React.createElement("input", {
4660
4619
  type: "checkbox",
4661
- checked: grantDevices.includes(device.deviceId),
4662
- disabled: disabled || grantAnyDevice,
4620
+ checked: draftDevices.includes(device.deviceId),
4621
+ disabled: disabled || draftAnyDevice,
4663
4622
  "aria-label": label(device),
4664
- onChange: () => toggleGrantDevice(device.deviceId)
4623
+ onChange: () => toggleDraftDevice(device.deviceId)
4665
4624
  }),
4666
4625
  label(device)
4667
4626
  ))
@@ -4685,7 +4644,12 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4685
4644
  React.createElement(
4686
4645
  "div",
4687
4646
  { className: "dshRemoteAcpRowInfo" },
4688
- React.createElement("strong", { className: "dshRemoteAcpName" }, label(device))
4647
+ React.createElement("strong", { className: "dshRemoteAcpName" }, label(device)),
4648
+ React.createElement(
4649
+ "p",
4650
+ null,
4651
+ `${t("modelShareBorrowFrom")} ${device.name}`
4652
+ )
4689
4653
  ),
4690
4654
  React.createElement("input", {
4691
4655
  type: "checkbox",
@@ -4695,14 +4659,20 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4695
4659
  "aria-checked": source?.enabled ?? !1,
4696
4660
  disabled,
4697
4661
  "aria-label": `${t("modelShareBorrowFrom")}: ${label(device)}`,
4698
- onChange: () => toggleSource(device.deviceId, device.name)
4662
+ onChange: () => {
4663
+ let sources = { ...borrower.sources };
4664
+ sources[device.deviceId] = {
4665
+ enabled: !(source?.enabled ?? !1),
4666
+ models: source?.models ?? [],
4667
+ hostName: source?.hostName ?? device.name
4668
+ }, patchSources(sources);
4669
+ }
4699
4670
  })
4700
4671
  ),
4701
- status === void 0 ? null : React.createElement(
4702
- "p",
4703
- { className: "dshRemoteAcpDiag" },
4704
- React.createElement("span", { className: `dshRemoteAcpStatus${status.cls}` }, status.text)
4705
- )
4672
+ status !== void 0 ? React.createElement("p", {
4673
+ className: `dshRemoteAcpDiag${status.cls}`,
4674
+ role: status.cls === "" ? "status" : "alert"
4675
+ }, status.text) : null
4706
4676
  );
4707
4677
  }),
4708
4678
  Object.keys(borrower.sources).length === 0 ? React.createElement("p", { className: "dshRemoteAcpDiag" }, t("modelShareNoSources")) : null
@@ -4720,12 +4690,12 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4720
4690
  "div",
4721
4691
  { className: "dshRemoteAcpSummaryText" },
4722
4692
  React.createElement("strong", null, t("modelShareLending")),
4723
- React.createElement("p", null, t("modelShareLendingHint"))
4693
+ React.createElement("p", null, t("modelSharingHint"))
4724
4694
  ),
4725
4695
  React.createElement(
4726
4696
  "span",
4727
4697
  { className: "dshRemoteAcpSummaryMeta" },
4728
- React.createElement("span", { className: "dshRemoteAcpCountText" }, String(host.grants.length)),
4698
+ React.createElement("span", { className: "dshRemoteAcpCountText" }, String(host.rules.length)),
4729
4699
  Chevron(React)
4730
4700
  )
4731
4701
  ),
package/dist/index.js CHANGED
@@ -75383,7 +75383,7 @@ function parseIpv6(value) {
75383
75383
  }
75384
75384
 
75385
75385
  // packages/plugin/src/version.ts
75386
- var PLUGIN_VERSION = "0.6.14";
75386
+ var PLUGIN_VERSION = "0.6.17";
75387
75387
 
75388
75388
  // packages/plugin/src/server-api.ts
75389
75389
  var TERMINAL_CONTROL_CHARACTERS = /[\u0000-\u001f\u007f-\u009f]/u;
@@ -93834,11 +93834,40 @@ var ClientModeRuntime = class {
93834
93834
  if (this.closed) throw new ClientModeError("CANCELLED", "The Remote runtime is closed.");
93835
93835
  return this.sessionTools.run(operation, args, signal);
93836
93836
  }
93837
- // [model-sharing] BEGIN — a transport bound to one lending Host. It reuses
93838
- // the same warm connection that the Remote UI uses (`withToolRemote`), so
93839
- // borrowed model calls never open a second Control connection.
93837
+ /**
93838
+ * [model-sharing] A transport bound to one lending Host that **holds its
93839
+ * connection across the whole borrowed stream**. `withToolRemote` would
93840
+ * open and close a fresh background connection per RPC, and the Host keeps
93841
+ * stream state per connection — drain on a new connection cannot find the
93842
+ * stream opened on the previous one. The first call connects, the held
93843
+ * connection serves open/drain/close for that stream, and `release()`
93844
+ * closes it when the borrower's adapter is done.
93845
+ */
93840
93846
  createModelShareTransport(hostId, hostName) {
93841
- const rpc = (method, params, signal) => this.withToolRemote(hostId, signal ?? this.remoteLifetime.signal, async (remote, activeSignal) => await remote.client.rpc(method, params, activeSignal));
93847
+ let held;
93848
+ let holding;
93849
+ const acquire = async () => {
93850
+ if (this.connected?.target.deviceId === hostId) {
93851
+ return { remote: this.connected, signal: this.remoteLifetime.signal };
93852
+ }
93853
+ if (held !== void 0) return held;
93854
+ holding ??= (async () => {
93855
+ if (this.identity === void 0) await this.ensureIdentity();
93856
+ const signal = this.remoteLifetime.signal;
93857
+ const remote = await this.connection.connect(hostId, signal, { background: true });
93858
+ held = { remote, signal };
93859
+ remote.client.onClose(() => {
93860
+ if (held?.remote === remote) held = void 0;
93861
+ });
93862
+ return held;
93863
+ })();
93864
+ return holding;
93865
+ };
93866
+ const rpc = async (method, params, signal) => {
93867
+ const { remote, signal: activeSignal } = await acquire();
93868
+ const scoped = signal === void 0 ? activeSignal : AbortSignal.any([activeSignal, signal]);
93869
+ return await remote.client.rpc(method, params, scoped);
93870
+ };
93842
93871
  return {
93843
93872
  hostId,
93844
93873
  hostName,
@@ -93850,6 +93879,13 @@ var ClientModeRuntime = class {
93850
93879
  ),
93851
93880
  close: async (streamId) => {
93852
93881
  await rpc("model.share.close", { streamId }).catch(() => void 0);
93882
+ },
93883
+ /** Drop the held connection when the borrowing runtime withdraws. */
93884
+ release: () => {
93885
+ const current = held;
93886
+ held = void 0;
93887
+ holding = void 0;
93888
+ void current?.remote.client.close().catch(() => void 0);
93853
93889
  }
93854
93890
  };
93855
93891
  }
@@ -113917,26 +113953,31 @@ var DEFAULT_STORE = {
113917
113953
  host: {
113918
113954
  enabled: false,
113919
113955
  allowedDevices: [],
113920
- grants: [],
113956
+ rules: [],
113921
113957
  maxConcurrent: 2
113922
113958
  },
113923
113959
  borrower: {
113924
113960
  sources: {}
113925
113961
  }
113926
113962
  };
113963
+ var ROUTE_PATTERN = /^[a-z0-9][a-z0-9._-]*::(\*|[a-z0-9][a-z0-9._-]*)$/i;
113964
+ function normalizeRoute(value) {
113965
+ if (typeof value !== "string") return void 0;
113966
+ const route = value.trim();
113967
+ return ROUTE_PATTERN.test(route) ? route : void 0;
113968
+ }
113927
113969
  function normalizeStore2(input4) {
113928
113970
  const raw = typeof input4 === "object" && input4 !== null ? input4 : {};
113929
113971
  const hostRaw = typeof raw.host === "object" && raw.host !== null ? raw.host : {};
113930
113972
  const borrowerRaw = typeof raw.borrower === "object" && raw.borrower !== null ? raw.borrower : {};
113931
- const grants = Array.isArray(hostRaw.grants) ? hostRaw.grants.flatMap((entry) => {
113973
+ const rules = Array.isArray(hostRaw.rules) ? hostRaw.rules.flatMap((entry) => {
113932
113974
  if (typeof entry !== "object" || entry === null) return [];
113933
- const grant = entry;
113934
- const provider = typeof grant.provider === "string" ? grant.provider.trim() : "";
113935
- if (provider === "") return [];
113975
+ const rule = entry;
113976
+ const models = Array.isArray(rule.models) ? [...new Set(rule.models.map(normalizeRoute).filter((route) => route !== void 0))] : [];
113977
+ if (models.length === 0) return [];
113936
113978
  return [{
113937
- ...typeof grant.deviceId === "string" && grant.deviceId.trim() !== "" ? { deviceId: grant.deviceId.trim() } : {},
113938
- provider,
113939
- models: Array.isArray(grant.models) ? grant.models.filter((model) => typeof model === "string" && model.trim() !== "").map((model) => model.trim()) : []
113979
+ models,
113980
+ devices: Array.isArray(rule.devices) ? [...new Set(rule.devices.filter((id7) => typeof id7 === "string" && id7.trim() !== "").map((id7) => id7.trim()))] : []
113940
113981
  }];
113941
113982
  }) : [];
113942
113983
  const sourcesRaw = typeof borrowerRaw.sources === "object" && borrowerRaw.sources !== null ? borrowerRaw.sources : {};
@@ -113956,7 +113997,7 @@ function normalizeStore2(input4) {
113956
113997
  host: {
113957
113998
  enabled: hostRaw.enabled === true,
113958
113999
  allowedDevices: Array.isArray(hostRaw.allowedDevices) ? hostRaw.allowedDevices.filter((id7) => typeof id7 === "string" && id7.trim() !== "").map((id7) => id7.trim()) : [],
113959
- grants,
114000
+ rules,
113960
114001
  maxConcurrent: Number.isFinite(maxConcurrentRaw) ? Math.min(Math.max(maxConcurrentRaw, 1), 16) : DEFAULT_STORE.host.maxConcurrent
113961
114002
  },
113962
114003
  borrower: { sources }
@@ -114758,8 +114799,8 @@ var PluginControlRuntime = class {
114758
114799
  }
114759
114800
  const lending = store.host;
114760
114801
  for (const id7 of lending.allowedDevices) remember(id7, id7);
114761
- for (const grant of lending.grants) {
114762
- if (grant.deviceId !== void 0) remember(grant.deviceId, grant.deviceId);
114802
+ for (const rule of lending.rules) {
114803
+ for (const deviceId of rule.devices) remember(deviceId, deviceId);
114763
114804
  }
114764
114805
  for (const [hostId, source] of Object.entries(store.borrower.sources)) {
114765
114806
  remember(hostId, source.hostName ?? hostId);
@@ -122667,12 +122708,23 @@ function parseRouteKey(key) {
122667
122708
  function grantAllows(policy, deviceId, provider, model) {
122668
122709
  if (!policy.enabled) return false;
122669
122710
  if (policy.allowedDevices.length > 0 && !policy.allowedDevices.includes(deviceId)) return false;
122670
- return policy.grants.some((grant) => {
122671
- if (grant.provider !== provider) return false;
122672
- if (grant.deviceId !== void 0 && grant.deviceId !== deviceId) return false;
122673
- return grant.models.length === 0 || grant.models.includes(model);
122711
+ const route = `${provider}::${model}`;
122712
+ const wildcard = `${provider}::*`;
122713
+ return policy.rules.some((rule) => {
122714
+ if (rule.devices.length > 0 && !rule.devices.includes(deviceId)) return false;
122715
+ return rule.models.includes(route) || rule.models.includes(wildcard);
122674
122716
  });
122675
122717
  }
122718
+ function allowedRoutes(policy, deviceId) {
122719
+ const routes = /* @__PURE__ */ new Set();
122720
+ if (!policy.enabled) return routes;
122721
+ if (policy.allowedDevices.length > 0 && !policy.allowedDevices.includes(deviceId)) return routes;
122722
+ for (const rule of policy.rules) {
122723
+ if (rule.devices.length > 0 && !rule.devices.includes(deviceId)) continue;
122724
+ for (const route of rule.models) routes.add(route);
122725
+ }
122726
+ return routes;
122727
+ }
122676
122728
  var ModelShareHost = class {
122677
122729
  constructor(llm, store, logger2, deviceId = "") {
122678
122730
  this.llm = llm;
@@ -122693,40 +122745,62 @@ var ModelShareHost = class {
122693
122745
  if (host.allowedDevices.length > 0 && !host.allowedDevices.includes(deviceId)) {
122694
122746
  return { enabled: false, models: [], accepting: false };
122695
122747
  }
122748
+ const allowed = allowedRoutes(host, deviceId);
122749
+ const wildcardProviders = /* @__PURE__ */ new Set();
122750
+ const exactRoutes = /* @__PURE__ */ new Set();
122751
+ for (const route of allowed) {
122752
+ const separator = route.indexOf(ROUTE_SEPARATOR);
122753
+ if (separator <= 0) continue;
122754
+ const provider = route.slice(0, separator);
122755
+ const model = route.slice(separator + ROUTE_SEPARATOR.length);
122756
+ if (model === "*") wildcardProviders.add(provider);
122757
+ else exactRoutes.add(route);
122758
+ }
122696
122759
  const models = [];
122697
122760
  const seen = /* @__PURE__ */ new Set();
122698
- for (const grant of host.grants) {
122699
- if (grant.deviceId !== void 0 && grant.deviceId !== deviceId) continue;
122700
- let catalog;
122761
+ const emit2 = async (provider, entry) => {
122762
+ const resolved = await this.safeResolve(provider, entry);
122763
+ const id7 = routeKey(provider, resolved.id);
122764
+ if (seen.has(id7)) return;
122765
+ seen.add(id7);
122766
+ const contextWindow = resolved.context?.contextWindow ?? resolved.contextWindow;
122767
+ const maxTokens = resolved.defaultMaxTokens ?? resolved.maxTokens;
122768
+ const parsed = sharedModelSchema.safeParse({
122769
+ id: id7,
122770
+ provider,
122771
+ model: resolved.id,
122772
+ name: resolved.name ?? resolved.id,
122773
+ ...contextWindow === void 0 ? {} : { contextWindow },
122774
+ ...maxTokens === void 0 ? {} : { maxTokens },
122775
+ ...resolved.reasoning?.efforts === void 0 ? {} : { reasoningEfforts: resolved.reasoning.efforts.map((effort) => effort.id) },
122776
+ ...resolved.inputModalities === void 0 ? {} : { inputModalities: [...resolved.inputModalities] }
122777
+ });
122778
+ if (parsed.success) models.push(parsed.data);
122779
+ };
122780
+ const providers = [.../* @__PURE__ */ new Set([
122781
+ ...wildcardProviders,
122782
+ ...Array.from(exactRoutes).map((route) => route.slice(0, route.indexOf(ROUTE_SEPARATOR)))
122783
+ ])];
122784
+ const catalogs = /* @__PURE__ */ new Map();
122785
+ await Promise.all(providers.map(async (provider) => {
122701
122786
  try {
122702
- catalog = await this.llm.listModels(grant.provider);
122787
+ catalogs.set(provider, await this.llm.listModels(provider));
122703
122788
  } catch (error62) {
122704
122789
  this.logger?.warn("model-share: catalog lookup failed", {
122705
- provider: grant.provider,
122790
+ provider,
122706
122791
  reason: error62 instanceof Error ? error62.name : "unknown"
122707
122792
  });
122708
- continue;
122709
- }
122710
- for (const entry of catalog) {
122711
- if (grant.models.length > 0 && !grant.models.includes(entry.id)) continue;
122712
- const resolved = await this.safeResolve(grant.provider, entry);
122713
- const id7 = routeKey(grant.provider, resolved.id);
122714
- if (seen.has(id7)) continue;
122715
- seen.add(id7);
122716
- const contextWindow = resolved.context?.contextWindow ?? resolved.contextWindow;
122717
- const maxTokens = resolved.defaultMaxTokens ?? resolved.maxTokens;
122718
- const parsed = sharedModelSchema.safeParse({
122719
- id: id7,
122720
- provider: grant.provider,
122721
- model: resolved.id,
122722
- name: resolved.name ?? resolved.id,
122723
- ...contextWindow === void 0 ? {} : { contextWindow },
122724
- ...maxTokens === void 0 ? {} : { maxTokens },
122725
- ...resolved.reasoning?.efforts === void 0 ? {} : { reasoningEfforts: resolved.reasoning.efforts.map((effort) => effort.id) },
122726
- ...resolved.inputModalities === void 0 ? {} : { inputModalities: [...resolved.inputModalities] }
122727
- });
122728
- if (parsed.success) models.push(parsed.data);
122729
122793
  }
122794
+ }));
122795
+ for (const provider of wildcardProviders) {
122796
+ for (const entry of catalogs.get(provider) ?? []) await emit2(provider, entry);
122797
+ }
122798
+ for (const route of exactRoutes) {
122799
+ const separator = route.indexOf(ROUTE_SEPARATOR);
122800
+ const provider = route.slice(0, separator);
122801
+ const model = route.slice(separator + ROUTE_SEPARATOR.length);
122802
+ const entry = (catalogs.get(provider) ?? []).find((candidate) => candidate.id === model);
122803
+ if (entry !== void 0) await emit2(provider, entry);
122730
122804
  }
122731
122805
  return { enabled: true, models, accepting: this.activeCount < host.maxConcurrent };
122732
122806
  }
@@ -126856,7 +126930,7 @@ var RemoteModelAdapter = class extends LlmAdapter {
126856
126930
  };
126857
126931
  }
126858
126932
  async listModels(provider) {
126859
- return this.transport.models().map((entry) => this.toModelInfo(provider, entry));
126933
+ return this.deduplicated().map((entry) => this.toModelInfo(provider, entry));
126860
126934
  }
126861
126935
  async resolveModel(provider, model, _signal) {
126862
126936
  const entry = this.findModel(model);
@@ -126869,19 +126943,34 @@ var RemoteModelAdapter = class extends LlmAdapter {
126869
126943
  stream: (options) => this.stream(options)
126870
126944
  };
126871
126945
  }
126946
+ /**
126947
+ * The Host may lend the same bare model name from several providers. DSH
126948
+ * requires unique ids within one provider's catalog, so drop later entries
126949
+ * whose route key (and therefore stable id) repeats.
126950
+ */
126951
+ deduplicated() {
126952
+ const seen = /* @__PURE__ */ new Set();
126953
+ return this.transport.models().filter((entry) => {
126954
+ if (seen.has(entry.id)) return false;
126955
+ seen.add(entry.id);
126956
+ return true;
126957
+ });
126958
+ }
126872
126959
  /** Resolve a borrower-facing model id back to a lent model entry. */
126873
126960
  findModel(modelId) {
126874
126961
  const models = this.transport.models();
126875
- const direct = models.find((entry) => entry.id === modelId || entry.model === modelId);
126876
- if (direct !== void 0) return direct;
126877
- const matches = models.filter((entry) => entry.model === modelId);
126878
- return matches.length === 1 ? matches[0] : void 0;
126962
+ const exact = models.find((entry) => entry.id === modelId);
126963
+ if (exact !== void 0) return exact;
126964
+ const bare = models.filter((entry) => entry.model === modelId);
126965
+ return bare.length === 1 ? bare[0] : void 0;
126879
126966
  }
126880
126967
  toModelInfo(provider, entry) {
126968
+ const sourceProvider = entry.provider || provider;
126881
126969
  return {
126882
126970
  provider,
126883
- id: entry.model,
126884
- name: entry.name,
126971
+ // Route key, unique across providers; entry.id is provider::model.
126972
+ id: entry.id,
126973
+ name: `${sourceProvider} / ${entry.name}`,
126885
126974
  ...entry.inputModalities === void 0 ? {} : { inputModalities: [...entry.inputModalities] },
126886
126975
  ...entry.contextWindow === void 0 ? {} : { context: { contextWindow: entry.contextWindow } },
126887
126976
  ...entry.maxTokens === void 0 ? {} : { defaultMaxTokens: entry.maxTokens },
@@ -127055,6 +127144,13 @@ var BorrowerRuntime = class {
127055
127144
  if (existing !== void 0) {
127056
127145
  existing.holder.models = [...selected];
127057
127146
  existing.models = existing.holder.models;
127147
+ if (existing.transport !== transport) {
127148
+ try {
127149
+ existing.transport?.release?.();
127150
+ } catch {
127151
+ }
127152
+ existing.transport = transport;
127153
+ }
127058
127154
  this.states.set(hostId, { outcome: "registered" });
127059
127155
  return;
127060
127156
  }
@@ -127072,7 +127168,7 @@ var BorrowerRuntime = class {
127072
127168
  }, this.logger);
127073
127169
  try {
127074
127170
  const handle = this.llm.registerAdapter([providerId], adapter);
127075
- this.registered.set(hostId, { handle, models: holder.models, holder });
127171
+ this.registered.set(hostId, { handle, models: holder.models, holder, transport });
127076
127172
  this.states.set(hostId, { outcome: "registered" });
127077
127173
  this.logger?.info("model-share: borrower provider registered", {
127078
127174
  hostId,
@@ -127099,6 +127195,10 @@ var BorrowerRuntime = class {
127099
127195
  existing.handle();
127100
127196
  } catch {
127101
127197
  }
127198
+ try {
127199
+ existing.transport?.release?.();
127200
+ } catch {
127201
+ }
127102
127202
  this.registered.delete(hostId);
127103
127203
  this.logger?.info("model-share: borrower provider withdrawn", { hostId });
127104
127204
  }
@@ -127152,17 +127252,15 @@ async function setHostGrant(store, provider, models, deviceId) {
127152
127252
  if (trimmedProvider === "") return { ok: false, message: "A provider id is required." };
127153
127253
  const trimmedModels = models.map((model) => model.trim()).filter((model) => model !== "");
127154
127254
  const next = await store.update((current) => {
127155
- const grants = current.host.grants.filter((grant) => !(grant.provider === trimmedProvider && grant.deviceId === deviceId));
127156
- grants.push({
127157
- provider: trimmedProvider,
127158
- models: trimmedModels,
127159
- ...deviceId === void 0 ? {} : { deviceId }
127160
- });
127161
- return { ...current, host: { ...current.host, grants } };
127255
+ const rule = {
127256
+ models: trimmedModels.length === 0 ? [`${trimmedProvider}::*`] : trimmedModels.map((model) => `${trimmedProvider}::${model}`),
127257
+ devices: deviceId === void 0 || deviceId.trim() === "" ? [] : [deviceId.trim()]
127258
+ };
127259
+ return { ...current, host: { ...current.host, rules: [...current.host.rules, rule] } };
127162
127260
  });
127163
127261
  return {
127164
127262
  ok: true,
127165
- message: `Grant recorded for ${trimmedProvider}: ${trimmedModels.length === 0 ? "all models" : trimmedModels.join(", ")}.`,
127263
+ message: `Rule recorded for ${trimmedProvider}: ${trimmedModels.length === 0 ? "all models" : trimmedModels.join(", ")}.`,
127166
127264
  store: next
127167
127265
  };
127168
127266
  }
@@ -127228,11 +127326,15 @@ function describeStore(store) {
127228
127326
  const lines = [];
127229
127327
  lines.push(`lending: ${store.host.enabled ? "enabled" : "disabled"} (maxConcurrent=${store.host.maxConcurrent})`);
127230
127328
  lines.push(` allowlist: ${store.host.allowedDevices.length === 0 ? "any authorized peer" : store.host.allowedDevices.join(", ")}`);
127231
- if (store.host.grants.length === 0) {
127232
- lines.push(" grants: none");
127329
+ if (store.host.rules.length === 0) {
127330
+ lines.push(" rules: none");
127233
127331
  } else {
127234
- for (const grant of store.host.grants) {
127235
- lines.push(` grant: ${grant.provider} -> ${grant.models.length === 0 ? "all models" : grant.models.join(", ")}${grant.deviceId === void 0 ? "" : ` (only ${grant.deviceId})`}`);
127332
+ for (const [index, rule] of store.host.rules.entries()) {
127333
+ const models = rule.models.map((route) => {
127334
+ const separator = route.indexOf("::");
127335
+ return separator <= 0 ? route : `${route.slice(0, separator)}/${route.slice(separator + 2)}`;
127336
+ });
127337
+ lines.push(` rule #${index + 1}: ${models.join(", ")} -> ${rule.devices.length === 0 ? "any authorized peer" : rule.devices.join(", ")}`);
127236
127338
  }
127237
127339
  }
127238
127340
  const sources = Object.entries(store.borrower.sources);
@@ -128609,6 +128711,7 @@ async function activate(ctx, readConfig, entryId, requireRemoteEvents = false) {
128609
128711
  const borrower = new BorrowerRuntime(llmRegistry, activeStore, logger2);
128610
128712
  modelShareBorrowers.push(borrower);
128611
128713
  const clientRuntimeForSync = nextClientRuntime;
128714
+ const syncTransports = /* @__PURE__ */ new Map();
128612
128715
  const SYNC_OK_MS = 6e4;
128613
128716
  const SYNC_RETRY_MS = 15e3;
128614
128717
  const lastSyncAt = /* @__PURE__ */ new Map();
@@ -128630,7 +128733,12 @@ async function activate(ctx, readConfig, entryId, requireRemoteEvents = false) {
128630
128733
  if (elapsed < (lastSyncOk.get(hostId) === false ? SYNC_RETRY_MS : SYNC_OK_MS)) continue;
128631
128734
  lastSyncAt.set(hostId, now);
128632
128735
  const deviceName = source.hostName ?? hostId;
128633
- const transport = clientRuntimeForSync.createModelShareTransport(hostId, deviceName);
128736
+ let transport = syncTransports.get(hostId);
128737
+ if (transport === void 0 || transport.hostName !== deviceName) {
128738
+ transport?.release?.();
128739
+ transport = clientRuntimeForSync.createModelShareTransport(hostId, deviceName);
128740
+ syncTransports.set(hostId, transport);
128741
+ }
128634
128742
  const before = borrower.activeHosts().includes(hostId);
128635
128743
  await borrower.refresh(hostId, deviceName, {
128636
128744
  ...transport,
@@ -128658,6 +128766,8 @@ async function activate(ctx, readConfig, entryId, requireRemoteEvents = false) {
128658
128766
  const previousDispose = borrower.close.bind(borrower);
128659
128767
  borrower.close = () => {
128660
128768
  clearInterval(syncTimer);
128769
+ for (const transport of syncTransports.values()) transport.release?.();
128770
+ syncTransports.clear();
128661
128771
  previousDispose();
128662
128772
  };
128663
128773
  const staleHosts = /* @__PURE__ */ new Set();
package/dsh-plugin.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://dsh.community/schemas/dsh-plugin-0.15.json",
3
3
  "id": "com.r2049.ds-harness-remote",
4
4
  "name": "@musdrop/ds-harness-remote",
5
- "version": "0.6.14",
5
+ "version": "0.6.17",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@musdrop/ds-harness-remote",
3
- "version": "0.6.14",
3
+ "version": "0.6.17",
4
4
  "description": "P2P-based, end-to-end encrypted remote access to DeepSeek Harness, CodeX, Claude Code, Pi, and other workspaces from web and mobile clients. Fork adding cross-device model lending/borrowing.",
5
5
  "keywords": [
6
6
  "deepseek",