@musdrop/ds-harness-remote 0.6.13 → 0.6.16

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
@@ -2223,7 +2223,9 @@ If a code was sent, recover the original submission without changing it.`,
2223
2223
  modelShareBorrowStatusPeerEmpty: "This device lends nothing usable right now.",
2224
2224
  modelShareRuleAnyDeviceHint: "A rule without any selected device applies to every authorized peer.",
2225
2225
  modelShareEdit: "Edit",
2226
- modelShareSaveEdit: "Save rule"
2226
+ modelShareSaveEdit: "Save rule",
2227
+ modelShareSelectModelsHint: "No models selected yet",
2228
+ modelShareClearDraft: "Clear form"
2227
2229
  }, zh = {
2228
2230
  uploadTooLarge: "\u6587\u4EF6\u8D85\u8FC7\u5F53\u524D\u8FDE\u63A5\u7684\u5355\u6587\u4EF6\u4E0A\u4F20\u4E0A\u9650\uFF08{size}\uFF09\u3002",
2229
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",
@@ -2669,7 +2671,9 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
2669
2671
  modelShareBorrowStatusPeerEmpty: "\u8BE5\u8BBE\u5907\u5F53\u524D\u6CA1\u6709\u53EF\u501F\u7528\u7684\u6A21\u578B\u3002",
2670
2672
  modelShareRuleAnyDeviceHint: "\u672A\u9009\u62E9\u4EFB\u4F55\u8BBE\u5907\u7684\u89C4\u5219\u5BF9\u6240\u6709\u5DF2\u6388\u6743\u7684\u8BBE\u5907\u751F\u6548\u3002",
2671
2673
  modelShareEdit: "\u7F16\u8F91",
2672
- modelShareSaveEdit: "\u4FDD\u5B58\u89C4\u5219"
2674
+ modelShareSaveEdit: "\u4FDD\u5B58\u89C4\u5219",
2675
+ modelShareSelectModelsHint: "\u5C1A\u672A\u9009\u62E9\u6A21\u578B",
2676
+ modelShareClearDraft: "\u6E05\u7A7A\u8868\u5355"
2673
2677
  }, ru = {
2674
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}).",
2675
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.",
@@ -3115,7 +3119,9 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
3115
3119
  modelShareBorrowStatusPeerEmpty: "\u042D\u0442\u043E \u0443\u0441\u0442\u0440\u043E\u0439\u0441\u0442\u0432\u043E \u0441\u0435\u0439\u0447\u0430\u0441 \u043D\u0435 \u043F\u0440\u0435\u0434\u043E\u0441\u0442\u0430\u0432\u043B\u044F\u0435\u0442 \u043C\u043E\u0434\u0435\u043B\u0435\u0439.",
3116
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.",
3117
3121
  modelShareEdit: "\u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C",
3118
- modelShareSaveEdit: "\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C \u043F\u0440\u0430\u0432\u0438\u043B\u043E"
3122
+ modelShareSaveEdit: "\u0421\u043E\u0445\u0440\u0430\u043D\u0438\u0442\u044C \u043F\u0440\u0430\u0432\u0438\u043B\u043E",
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"
3119
3125
  }, uk = {
3120
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}).",
3121
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.",
@@ -3561,7 +3567,9 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
3561
3567
  modelShareBorrowStatusPeerEmpty: "\u0426\u0435\u0439 \u043F\u0440\u0438\u0441\u0442\u0440\u0456\u0439 \u0437\u0430\u0440\u0430\u0437 \u043D\u0435 \u043D\u0430\u0434\u0430\u0454 \u043C\u043E\u0434\u0435\u043B\u0435\u0439.",
3562
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.",
3563
3569
  modelShareEdit: "\u0420\u0435\u0434\u0430\u0433\u0443\u0432\u0430\u0442\u0438",
3564
- modelShareSaveEdit: "\u0417\u0431\u0435\u0440\u0435\u0433\u0442\u0438 \u043F\u0440\u0430\u0432\u0438\u043B\u043E"
3570
+ modelShareSaveEdit: "\u0417\u0431\u0435\u0440\u0435\u0433\u0442\u0438 \u043F\u0440\u0430\u0432\u0438\u043B\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"
3565
3573
  };
3566
3574
 
3567
3575
  // packages/plugin/src/client/header.ts
@@ -4351,6 +4359,7 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4351
4359
 
4352
4360
  // packages/plugin/src/client/model-sharing.ts
4353
4361
  init_page_globals();
4362
+ var ROUTE_SEPARATOR = "::";
4354
4363
  function Chevron(React) {
4355
4364
  return React.createElement("svg", {
4356
4365
  width: 12,
@@ -4369,7 +4378,7 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4369
4378
  }
4370
4379
  function createModelSharingSection(React) {
4371
4380
  return function(props) {
4372
- 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), [grantProvider, setGrantProvider] = React.useState(""), [grantAllModels, setGrantAllModels] = React.useState(!0), [grantModels, setGrantModels] = 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) => {
4373
4382
  viewRef.current = next, setView(next), setConcurrencyDraft(void 0);
4374
4383
  }, load = React.useCallback(async () => {
4375
4384
  setError(void 0);
@@ -4378,7 +4387,7 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4378
4387
  } catch (reason) {
4379
4388
  setError(messageOf(reason, t));
4380
4389
  }
4381
- }, [control]);
4390
+ }, [control, t]);
4382
4391
  React.useEffect(() => {
4383
4392
  load();
4384
4393
  }, [load]);
@@ -4398,42 +4407,51 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4398
4407
  enqueue((current) => ({ ...current, host: { ...current.host, ...changes } }));
4399
4408
  }, patchSources = (sources) => {
4400
4409
  enqueue((current) => ({ ...current, borrower: { ...current.borrower, sources } }));
4401
- }, toggleSource = (deviceId, hostName) => {
4402
- if (view === void 0) return;
4403
- let sources = { ...view.store.borrower.sources }, current = sources[deviceId];
4404
- sources[deviceId] = {
4405
- enabled: !(current?.enabled ?? !1),
4406
- models: current?.models ?? [],
4407
- hostName: current?.hostName ?? hostName
4408
- }, patchSources(sources);
4409
- }, removeGrant = (index) => {
4410
- view !== void 0 && patchHost({ grants: view.store.host.grants.filter((_, i) => i !== index) });
4411
- }, selectGrantProvider = (provider) => {
4412
- setGrantProvider(provider), setGrantAllModels(!0), setGrantModels([]);
4413
- }, toggleGrantModel = (modelId) => {
4414
- setGrantModels((current) => current.includes(modelId) ? current.filter((id) => id !== modelId) : [...current, modelId]);
4415
- }, toggleGrantDevice = (deviceId) => {
4416
- setGrantDevices((current) => current.includes(deviceId) ? current.filter((id) => id !== deviceId) : [...current, deviceId]);
4417
- }, addGrant = () => {
4418
- if (view === void 0 || grantProvider === "") return;
4419
- let provider = grantProvider, models = grantAllModels || grantModels.length === 0 ? [] : grantModels, anyDevice = grantAnyDevice || grantDevices.length === 0, replaced = new Set(anyDevice ? ["*"] : grantDevices), grants = view.store.host.grants.filter((grant) => grant.provider !== provider ? !0 : !replaced.has(grant.deviceId === void 0 ? "*" : grant.deviceId));
4420
- for (let deviceId of anyDevice ? [void 0] : grantDevices)
4421
- grants.push({ ...deviceId === void 0 ? {} : { deviceId }, provider, models });
4422
- patchHost({ grants, enabled: !0 }), setGrantProvider(""), setGrantAllModels(!0), setGrantModels([]), setGrantAnyDevice(!0), setGrantDevices([]), setEditingGrant(!1);
4423
- }, 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) => {
4424
4438
  if (view === void 0 || source?.enabled !== !0) return;
4425
4439
  let diagnostics = view.borrowerDiagnostics;
4426
4440
  if (diagnostics.syncAvailable !== !0)
4427
4441
  return { cls: " isFailed", text: t("modelShareBorrowStatusDisconnected") };
4428
4442
  let entry = diagnostics.sources.find((item) => item.hostId === deviceId);
4429
- if (entry !== void 0) {
4430
- if (entry.outcome === "registered")
4431
- return { cls: " isPassed", text: t("modelShareBorrowStatusOk", { count: entry.modelCount }) };
4432
- if (entry.outcome === "failed")
4433
- return { cls: " isFailed", text: t("modelShareBorrowStatusFailed", { reason: entry.error ?? "" }) };
4434
- if (entry.outcome === "host-disabled" || entry.outcome === "no-models")
4435
- return { cls: " isFailed", text: t("modelShareBorrowStatusPeerEmpty") };
4436
- }
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
+ }
4437
4455
  };
4438
4456
  if (view === void 0)
4439
4457
  return React.createElement(
@@ -4446,12 +4464,7 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4446
4464
  React.createElement("p", null, error ?? t("modelShareNotLoaded"))
4447
4465
  )
4448
4466
  );
4449
- let { host, borrower } = view.store, disabled = busy || !view.writable || !available, draftModels = view.localProviders.find((provider) => provider.id === grantProvider)?.models ?? [], modelsSummary = grantAllModels || grantModels.length === 0 ? t("modelShareAllModels") : t("modelShareSelectedCount", { count: grantModels.length }), devicesSummary = grantAnyDevice || grantDevices.length === 0 ? t("modelShareAnyDevice") : t("modelShareSelectedCount", { count: grantDevices.length }), deviceSummaryLine = `${t("modelShareDevice")}: ${devicesSummary}`, modelSummaryLine = `${t("modelShareModels")}: ${modelsSummary}`, grantGroups = [];
4450
- host.grants.forEach((grant, index) => {
4451
- let group = grantGroups.find((candidate) => candidate.provider === grant.provider);
4452
- group === void 0 && (group = { provider: grant.provider, entries: [] }, grantGroups.push(group)), group.entries.push({ index, grant });
4453
- });
4454
- 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(
4455
4468
  "div",
4456
4469
  { className: "dshRemoteAcpList" },
4457
4470
  React.createElement(
@@ -4463,11 +4476,7 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4463
4476
  React.createElement(
4464
4477
  "div",
4465
4478
  { className: "dshRemoteAcpRowInfo" },
4466
- React.createElement(
4467
- "div",
4468
- { className: "dshRemoteAcpRowInfo" },
4469
- React.createElement("strong", { className: "dshRemoteAcpName" }, t("modelShareMaxConcurrent"))
4470
- )
4479
+ React.createElement("strong", { className: "dshRemoteAcpName" }, t("modelShareMaxConcurrent"))
4471
4480
  ),
4472
4481
  React.createElement(
4473
4482
  "div",
@@ -4490,97 +4499,55 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4490
4499
  ),
4491
4500
  React.createElement("p", { className: "dshRemoteAcpDiag" }, t("modelShareRuleAnyDeviceHint"))
4492
4501
  ),
4493
- ...grantGroups.map((group) => React.createElement(
4502
+ ...host.rules.map((rule, index) => React.createElement(
4494
4503
  "div",
4495
4504
  {
4496
- key: `grant-group-${group.provider}`,
4497
- className: "dshRemoteAcpRow"
4505
+ key: `rule-${index}`,
4506
+ className: "dshRemoteModelShareGrantEntry"
4498
4507
  },
4508
+ React.createElement("span", null, ruleSummary(rule).join(" \xB7 ")),
4499
4509
  React.createElement(
4500
4510
  "div",
4501
- { className: "dshRemoteAcpRowMain" },
4502
- React.createElement(
4503
- "div",
4504
- { className: "dshRemoteAcpRowInfo" },
4505
- React.createElement("strong", { className: "dshRemoteAcpName" }, group.provider)
4506
- )
4507
- ),
4508
- React.createElement(
4509
- "p",
4510
- { className: "dshRemoteAcpDiag" },
4511
- grantModelsSummary([...new Set(group.entries.map((entry) => entry.grant.models).flat())])
4512
- ),
4513
- ...group.entries.map((entry) => React.createElement(
4514
- "div",
4515
- {
4516
- key: `grant-${entry.index}`,
4517
- className: "dshRemoteModelShareGrantEntry"
4518
- },
4519
- React.createElement("span", null, [
4520
- entry.grant.deviceId === void 0 ? t("modelShareAnyDevice") : peerName(entry.grant.deviceId),
4521
- grantModelsSummary(entry.grant.models)
4522
- ].join(" \xB7 ")),
4523
- React.createElement(
4524
- "div",
4525
- { className: "dshRemoteAcpRowActions" },
4526
- React.createElement("button", {
4527
- type: "button",
4528
- className: "dshRemoteAcpActionBtn",
4529
- disabled,
4530
- "aria-label": `${t("modelShareEdit")}: ${group.provider}${entry.grant.deviceId === void 0 ? "" : ` \u2192 ${peerName(entry.grant.deviceId)}`}`,
4531
- // Edit = prefill the form from this grant and drop the saved
4532
- // entry; saving the form writes the edited rule back.
4533
- onClick: () => {
4534
- setGrantProvider(group.provider), setGrantAllModels(entry.grant.models.length === 0), setGrantModels(entry.grant.models), setGrantAnyDevice(entry.grant.deviceId === void 0), setGrantDevices(entry.grant.deviceId === void 0 ? [] : [entry.grant.deviceId]), removeGrant(entry.index), setEditingGrant(!0);
4535
- }
4536
- }, t("modelShareEdit")),
4537
- React.createElement("button", {
4538
- type: "button",
4539
- className: "dshRemoteAcpRemoveBtn",
4540
- disabled,
4541
- "aria-label": `${t("modelShareRemove")}: ${group.provider}${entry.grant.deviceId === void 0 ? "" : ` \u2192 ${peerName(entry.grant.deviceId)}`}`,
4542
- onClick: () => removeGrant(entry.index)
4543
- }, t("modelShareRemove"))
4544
- )
4545
- ))
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
+ )
4546
4527
  )),
4547
- 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,
4548
4529
  React.createElement(
4549
4530
  "div",
4550
4531
  { className: "dshRemoteAcpAddForm" },
4551
4532
  React.createElement(
4552
4533
  "div",
4553
4534
  { className: "dshRemoteAcpAddInputs" },
4554
- React.createElement(
4555
- "select",
4556
- {
4557
- value: grantProvider,
4558
- disabled,
4559
- "aria-label": t("modelShareProvider"),
4560
- onChange: (event) => selectGrantProvider(event.target.value)
4561
- },
4562
- React.createElement("option", { value: "" }, t("modelShareSelectProvider")),
4563
- ...view.localProviders.map((provider) => React.createElement("option", {
4564
- key: provider.id,
4565
- value: provider.id
4566
- }, provider.name ?? provider.id))
4567
- ),
4568
4535
  React.createElement("button", {
4569
4536
  type: "button",
4570
4537
  className: "dshRemoteAcpAddTrigger",
4571
- disabled: disabled || grantProvider === "",
4572
- onClick: addGrant
4573
- }, t(editingGrant ? "modelShareSaveEdit" : "modelShareAddGrant")),
4574
- 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", {
4575
4542
  type: "button",
4576
4543
  className: "dshRemoteAcpAddTrigger",
4577
4544
  disabled,
4578
- onClick: () => {
4579
- setGrantProvider(""), setGrantAllModels(!0), setGrantModels([]), setGrantAnyDevice(!0), setGrantDevices([]), setEditingGrant(!1);
4580
- }
4581
- }, t("cancelServiceAddressEdit")) : null
4545
+ onClick: resetDraft
4546
+ }, t("modelShareClearDraft")) : null
4582
4547
  ),
4583
- // Collapsible model checkboxes for the selected provider.
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).
4584
4551
  React.createElement(
4585
4552
  "details",
4586
4553
  { className: "dshRemoteModelSharePicker" },
@@ -4588,31 +4555,41 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4588
4555
  React.createElement(
4589
4556
  "div",
4590
4557
  { className: "dshRemoteModelSharePickerList", role: "group", "aria-label": t("modelShareModels") },
4591
- React.createElement(
4592
- "label",
4593
- null,
4594
- React.createElement("input", {
4595
- type: "checkbox",
4596
- checked: grantAllModels,
4597
- disabled,
4598
- "aria-label": t("modelShareAllModels"),
4599
- onChange: (event) => setGrantAllModels(event.target.checked)
4600
- }),
4601
- t("modelShareAllModels")
4602
- ),
4603
- ...draftModels.map((model) => React.createElement(
4604
- "label",
4605
- { key: `model-${model.id}` },
4606
- React.createElement("input", {
4607
- type: "checkbox",
4608
- checked: grantModels.includes(model.id),
4609
- // The all-models checkbox disables individual selection.
4610
- disabled: disabled || grantAllModels,
4611
- "aria-label": model.name ?? model.id,
4612
- onChange: () => toggleGrantModel(model.id)
4613
- }),
4614
- model.name ?? model.id
4615
- ))
4558
+ ...view.localProviders.map((provider) => {
4559
+ let wildcard = `${provider.id}${ROUTE_SEPARATOR}*`;
4560
+ return React.createElement(
4561
+ "div",
4562
+ { key: `prov-${provider.id}`, className: "dshRemoteModelShareProviderGroup" },
4563
+ React.createElement(
4564
+ "label",
4565
+ { className: "dshRemoteModelShareProviderHeading" },
4566
+ React.createElement("input", {
4567
+ type: "checkbox",
4568
+ checked: draftModels.includes(wildcard),
4569
+ disabled,
4570
+ "aria-label": `${t("modelShareAllModels")}: ${provider.name ?? provider.id}`,
4571
+ onChange: () => toggleDraftModel(wildcard)
4572
+ }),
4573
+ React.createElement("strong", null, provider.name ?? provider.id)
4574
+ ),
4575
+ ...provider.models.map((model) => {
4576
+ let route = `${provider.id}${ROUTE_SEPARATOR}${model.id}`;
4577
+ return React.createElement(
4578
+ "label",
4579
+ { key: `model-${route}` },
4580
+ React.createElement("input", {
4581
+ type: "checkbox",
4582
+ checked: draftModels.includes(route) || draftModels.includes(wildcard),
4583
+ // The provider wildcard supersedes its individual boxes.
4584
+ disabled: disabled || draftModels.includes(wildcard),
4585
+ "aria-label": `${provider.name ?? provider.id} / ${model.name ?? model.id}`,
4586
+ onChange: () => toggleDraftModel(route)
4587
+ }),
4588
+ model.name ?? model.id
4589
+ );
4590
+ })
4591
+ );
4592
+ })
4616
4593
  )
4617
4594
  ),
4618
4595
  // Collapsible multi-device selection; empty means every peer.
@@ -4628,10 +4605,10 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4628
4605
  null,
4629
4606
  React.createElement("input", {
4630
4607
  type: "checkbox",
4631
- checked: grantAnyDevice,
4608
+ checked: draftAnyDevice,
4632
4609
  disabled,
4633
4610
  "aria-label": t("modelShareAnyDevice"),
4634
- onChange: (event) => setGrantAnyDevice(event.target.checked)
4611
+ onChange: (event) => setDraftAnyDevice(event.target.checked)
4635
4612
  }),
4636
4613
  t("modelShareAnyDevice")
4637
4614
  ),
@@ -4640,10 +4617,10 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4640
4617
  { key: `device-${device.deviceId}` },
4641
4618
  React.createElement("input", {
4642
4619
  type: "checkbox",
4643
- checked: grantDevices.includes(device.deviceId),
4644
- disabled: disabled || grantAnyDevice,
4620
+ checked: draftDevices.includes(device.deviceId),
4621
+ disabled: disabled || draftAnyDevice,
4645
4622
  "aria-label": label(device),
4646
- onChange: () => toggleGrantDevice(device.deviceId)
4623
+ onChange: () => toggleDraftDevice(device.deviceId)
4647
4624
  }),
4648
4625
  label(device)
4649
4626
  ))
@@ -4667,7 +4644,12 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4667
4644
  React.createElement(
4668
4645
  "div",
4669
4646
  { className: "dshRemoteAcpRowInfo" },
4670
- 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
+ )
4671
4653
  ),
4672
4654
  React.createElement("input", {
4673
4655
  type: "checkbox",
@@ -4677,14 +4659,20 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4677
4659
  "aria-checked": source?.enabled ?? !1,
4678
4660
  disabled,
4679
4661
  "aria-label": `${t("modelShareBorrowFrom")}: ${label(device)}`,
4680
- 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
+ }
4681
4670
  })
4682
4671
  ),
4683
- status === void 0 ? null : React.createElement(
4684
- "p",
4685
- { className: "dshRemoteAcpDiag" },
4686
- React.createElement("span", { className: `dshRemoteAcpStatus${status.cls}` }, status.text)
4687
- )
4672
+ status !== void 0 ? React.createElement("p", {
4673
+ className: `dshRemoteAcpDiag${status.cls}`,
4674
+ role: status.cls === "" ? "status" : "alert"
4675
+ }, status.text) : null
4688
4676
  );
4689
4677
  }),
4690
4678
  Object.keys(borrower.sources).length === 0 ? React.createElement("p", { className: "dshRemoteAcpDiag" }, t("modelShareNoSources")) : null
@@ -4702,12 +4690,12 @@ DSH Go \u626B\u7801\u6682\u4E0D\u652F\u6301\u591A\u53F0\u8BBE\u5907\u63A7\u5236\
4702
4690
  "div",
4703
4691
  { className: "dshRemoteAcpSummaryText" },
4704
4692
  React.createElement("strong", null, t("modelShareLending")),
4705
- React.createElement("p", null, t("modelShareLendingHint"))
4693
+ React.createElement("p", null, t("modelSharingHint"))
4706
4694
  ),
4707
4695
  React.createElement(
4708
4696
  "span",
4709
4697
  { className: "dshRemoteAcpSummaryMeta" },
4710
- React.createElement("span", { className: "dshRemoteAcpCountText" }, String(host.grants.length)),
4698
+ React.createElement("span", { className: "dshRemoteAcpCountText" }, String(host.rules.length)),
4711
4699
  Chevron(React)
4712
4700
  )
4713
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.13";
75386
+ var PLUGIN_VERSION = "0.6.16";
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,38 +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 parsed = sharedModelSchema.safeParse({
122717
- id: id7,
122718
- provider: grant.provider,
122719
- model: resolved.id,
122720
- name: resolved.name ?? resolved.id,
122721
- ...resolved.contextWindow === void 0 ? {} : { contextWindow: resolved.contextWindow },
122722
- ...resolved.maxTokens === void 0 ? {} : { maxTokens: resolved.maxTokens },
122723
- ...resolved.reasoning?.efforts === void 0 ? {} : { reasoningEfforts: resolved.reasoning.efforts.map((effort) => effort.id) },
122724
- ...resolved.inputModalities === void 0 ? {} : { inputModalities: [...resolved.inputModalities] }
122725
- });
122726
- if (parsed.success) models.push(parsed.data);
122727
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);
122728
122804
  }
122729
122805
  return { enabled: true, models, accepting: this.activeCount < host.maxConcurrent };
122730
122806
  }
@@ -127053,6 +127129,13 @@ var BorrowerRuntime = class {
127053
127129
  if (existing !== void 0) {
127054
127130
  existing.holder.models = [...selected];
127055
127131
  existing.models = existing.holder.models;
127132
+ if (existing.transport !== transport) {
127133
+ try {
127134
+ existing.transport?.release?.();
127135
+ } catch {
127136
+ }
127137
+ existing.transport = transport;
127138
+ }
127056
127139
  this.states.set(hostId, { outcome: "registered" });
127057
127140
  return;
127058
127141
  }
@@ -127070,7 +127153,7 @@ var BorrowerRuntime = class {
127070
127153
  }, this.logger);
127071
127154
  try {
127072
127155
  const handle = this.llm.registerAdapter([providerId], adapter);
127073
- this.registered.set(hostId, { handle, models: holder.models, holder });
127156
+ this.registered.set(hostId, { handle, models: holder.models, holder, transport });
127074
127157
  this.states.set(hostId, { outcome: "registered" });
127075
127158
  this.logger?.info("model-share: borrower provider registered", {
127076
127159
  hostId,
@@ -127097,6 +127180,10 @@ var BorrowerRuntime = class {
127097
127180
  existing.handle();
127098
127181
  } catch {
127099
127182
  }
127183
+ try {
127184
+ existing.transport?.release?.();
127185
+ } catch {
127186
+ }
127100
127187
  this.registered.delete(hostId);
127101
127188
  this.logger?.info("model-share: borrower provider withdrawn", { hostId });
127102
127189
  }
@@ -127150,17 +127237,15 @@ async function setHostGrant(store, provider, models, deviceId) {
127150
127237
  if (trimmedProvider === "") return { ok: false, message: "A provider id is required." };
127151
127238
  const trimmedModels = models.map((model) => model.trim()).filter((model) => model !== "");
127152
127239
  const next = await store.update((current) => {
127153
- const grants = current.host.grants.filter((grant) => !(grant.provider === trimmedProvider && grant.deviceId === deviceId));
127154
- grants.push({
127155
- provider: trimmedProvider,
127156
- models: trimmedModels,
127157
- ...deviceId === void 0 ? {} : { deviceId }
127158
- });
127159
- return { ...current, host: { ...current.host, grants } };
127240
+ const rule = {
127241
+ models: trimmedModels.length === 0 ? [`${trimmedProvider}::*`] : trimmedModels.map((model) => `${trimmedProvider}::${model}`),
127242
+ devices: deviceId === void 0 || deviceId.trim() === "" ? [] : [deviceId.trim()]
127243
+ };
127244
+ return { ...current, host: { ...current.host, rules: [...current.host.rules, rule] } };
127160
127245
  });
127161
127246
  return {
127162
127247
  ok: true,
127163
- message: `Grant recorded for ${trimmedProvider}: ${trimmedModels.length === 0 ? "all models" : trimmedModels.join(", ")}.`,
127248
+ message: `Rule recorded for ${trimmedProvider}: ${trimmedModels.length === 0 ? "all models" : trimmedModels.join(", ")}.`,
127164
127249
  store: next
127165
127250
  };
127166
127251
  }
@@ -127226,11 +127311,15 @@ function describeStore(store) {
127226
127311
  const lines = [];
127227
127312
  lines.push(`lending: ${store.host.enabled ? "enabled" : "disabled"} (maxConcurrent=${store.host.maxConcurrent})`);
127228
127313
  lines.push(` allowlist: ${store.host.allowedDevices.length === 0 ? "any authorized peer" : store.host.allowedDevices.join(", ")}`);
127229
- if (store.host.grants.length === 0) {
127230
- lines.push(" grants: none");
127314
+ if (store.host.rules.length === 0) {
127315
+ lines.push(" rules: none");
127231
127316
  } else {
127232
- for (const grant of store.host.grants) {
127233
- lines.push(` grant: ${grant.provider} -> ${grant.models.length === 0 ? "all models" : grant.models.join(", ")}${grant.deviceId === void 0 ? "" : ` (only ${grant.deviceId})`}`);
127317
+ for (const [index, rule] of store.host.rules.entries()) {
127318
+ const models = rule.models.map((route) => {
127319
+ const separator = route.indexOf("::");
127320
+ return separator <= 0 ? route : `${route.slice(0, separator)}/${route.slice(separator + 2)}`;
127321
+ });
127322
+ lines.push(` rule #${index + 1}: ${models.join(", ")} -> ${rule.devices.length === 0 ? "any authorized peer" : rule.devices.join(", ")}`);
127234
127323
  }
127235
127324
  }
127236
127325
  const sources = Object.entries(store.borrower.sources);
@@ -128607,6 +128696,7 @@ async function activate(ctx, readConfig, entryId, requireRemoteEvents = false) {
128607
128696
  const borrower = new BorrowerRuntime(llmRegistry, activeStore, logger2);
128608
128697
  modelShareBorrowers.push(borrower);
128609
128698
  const clientRuntimeForSync = nextClientRuntime;
128699
+ const syncTransports = /* @__PURE__ */ new Map();
128610
128700
  const SYNC_OK_MS = 6e4;
128611
128701
  const SYNC_RETRY_MS = 15e3;
128612
128702
  const lastSyncAt = /* @__PURE__ */ new Map();
@@ -128628,7 +128718,12 @@ async function activate(ctx, readConfig, entryId, requireRemoteEvents = false) {
128628
128718
  if (elapsed < (lastSyncOk.get(hostId) === false ? SYNC_RETRY_MS : SYNC_OK_MS)) continue;
128629
128719
  lastSyncAt.set(hostId, now);
128630
128720
  const deviceName = source.hostName ?? hostId;
128631
- const transport = clientRuntimeForSync.createModelShareTransport(hostId, deviceName);
128721
+ let transport = syncTransports.get(hostId);
128722
+ if (transport === void 0 || transport.hostName !== deviceName) {
128723
+ transport?.release?.();
128724
+ transport = clientRuntimeForSync.createModelShareTransport(hostId, deviceName);
128725
+ syncTransports.set(hostId, transport);
128726
+ }
128632
128727
  const before = borrower.activeHosts().includes(hostId);
128633
128728
  await borrower.refresh(hostId, deviceName, {
128634
128729
  ...transport,
@@ -128656,6 +128751,8 @@ async function activate(ctx, readConfig, entryId, requireRemoteEvents = false) {
128656
128751
  const previousDispose = borrower.close.bind(borrower);
128657
128752
  borrower.close = () => {
128658
128753
  clearInterval(syncTimer);
128754
+ for (const transport of syncTransports.values()) transport.release?.();
128755
+ syncTransports.clear();
128659
128756
  previousDispose();
128660
128757
  };
128661
128758
  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.13",
5
+ "version": "0.6.16",
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.13",
3
+ "version": "0.6.16",
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",