dsh-apk-vm 0.10.0 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.2
4
+
5
+ Panel administrator mode and owner-header compatibility.
6
+
7
+ ### Added
8
+
9
+ - The human Web panel is now an **administrator** owner: it may operate any VM even when an
10
+ Agent conversation holds the lease. Admin requests bypass the `409 vm-busy` guard but do not
11
+ steal or refresh the agent lease.
12
+ - `x-apk-vm-role: admin` is accepted only from loopback requests; non-loopback callers are
13
+ downgraded to `user`. `ownerStatus`, `ownerLabel` and the panel usage card expose the role.
14
+
15
+ ### Fixed
16
+
17
+ - Browser `fetch` no longer rejects the panel owner label with `String contains non
18
+ ISO-8859-1 code point`; labels and workspace paths are percent-encoded and decoded on Host.
19
+ - Panel **Claim** / **Release** actions force ownership for the local admin, so the human can
20
+ recover control of a VM held by an Agent.
21
+
22
+ ## 0.10.1
23
+
24
+ Fix panel requests failing with non-ISO-8859-1 header values.
25
+
26
+ ### Fixed
27
+
28
+ - Percent-encode the panel owner label before sending it as `x-apk-vm-label`, so Chromium
29
+ `fetch` no longer rejects requests with `String contains non ISO-8859-1 code point`.
30
+ - Decode percent-encoded owner HTTP headers/query values on the Host, including Chinese
31
+ workspace paths and labels.
32
+
3
33
  ## 0.10.0
4
34
 
5
35
  VM ownership and dedicated conversation/project VMs.
package/README.md CHANGED
@@ -45,7 +45,7 @@ same-origin, loopback-only debug HTTP API and an `apk_vm` Agent tool.
45
45
  > 当前 **Windows x64 与 Linux x86_64(headless)为端到端已验证平台**;macOS 仅做探测/CI
46
46
  > 覆盖,详见 `docs/LINUX-E2E.md`。
47
47
 
48
- **Status:** `0.10.0` · Apache-2.0 · no npm runtime dependencies · no build step.
48
+ **Status:** `0.10.2` · Apache-2.0 · no npm runtime dependencies · no build step.
49
49
 
50
50
  This is an open-source DSH plugin published on npm as **`dsh-apk-vm`**. Repository:
51
51
  [github.com/yuxiaole-bili/dsh-apk-vm](https://github.com/yuxiaole-bili/dsh-apk-vm).
@@ -345,12 +345,18 @@ or `project`), session id, workspace, and `since` / `lastSeenAt` timestamps; lea
345
345
  - The VM instances card shows the current owner/scope. The **VM usage** card in the panel
346
346
  shows a readable owner label and provides **Claim**, **Release** and a `shared` /
347
347
  `conversation` / `project` scope control for the human user.
348
+ - The Web panel is an administrator: it can operate a VM held by an Agent conversation and may
349
+ force **Claim** / **Release**, while ordinary Agent calls still get `409 vm-busy`. The panel
350
+ sends `x-apk-vm-role: admin`; the Host accepts that role only from loopback requests and
351
+ downgrades non-local callers to `user`.
348
352
  - `owner_status` lists default/extra VM leases; `claim_vm` and `release_vm` manage them.
349
353
  HTTP: `GET|POST /apk-vm/ownership` (`status`, `claim`, `release`, `touch`), while
350
354
  `GET /apk-vm/state` and `GET /apk-vm/instances` include owner metadata.
351
355
  - When the panel makes a mutating HTTP request it sends
352
356
  `x-apk-vm-owner`, `x-apk-vm-scope`, `x-apk-vm-session`, `x-apk-vm-workspace` and
353
- `x-apk-vm-label`. A request that supplies an owner header auto-claims a free VM; on a leased VM
357
+ `x-apk-vm-label`. Header values may be percent-encoded (UTF-8); the Host decodes them, so
358
+ non-ASCII labels and workspace paths remain valid for browser `fetch`. A request that
359
+ supplies an owner header auto-claims a free VM; on a leased VM
354
360
  it must match the current owner key. `POST /apk-vm/*` control routes return `409 vm-busy` with
355
361
  the current owner when the header is missing or does not match. Read-only `GET` routes are
356
362
  never blocked.
package/client.js CHANGED
@@ -30,7 +30,7 @@ window.__ModuleLoader__.load({
30
30
  var SWIPE_THRESHOLD_PX = 24;
31
31
  var FRAME_INTERVAL_MS = 500;
32
32
  var STATE_INTERVAL_MS = 2000;
33
- var CLIENT_VERSION = '0.10.0';
33
+ var CLIENT_VERSION = '0.10.2';
34
34
 
35
35
  /* ------------------------------------------------------------------ *
36
36
  * Optional dsh-better-sidebar integration.
@@ -126,6 +126,7 @@ window.__ModuleLoader__.load({
126
126
  'owner.busy': 'in use by {label}',
127
127
  'owner.scope': 'Scope',
128
128
  'owner.forceHint': 'Another owner holds this VM; release it first.',
129
+ 'owner.admin': 'Administrator — can operate every VM',
129
130
  'action.start': 'Start VM',
130
131
  'action.starting': 'Starting…',
131
132
  'action.stop': 'Stop',
@@ -443,6 +444,7 @@ window.__ModuleLoader__.load({
443
444
  'owner.busy': '被 {label} 占用',
444
445
  'owner.scope': '范围',
445
446
  'owner.forceHint': '其他使用者正在占用,请先释放。',
447
+ 'owner.admin': '管理员 · 可操作所有虚拟机',
446
448
  'action.start': '启动虚拟机',
447
449
  'action.starting': '正在启动…',
448
450
  'action.stop': '停止',
@@ -850,7 +852,8 @@ window.__ModuleLoader__.load({
850
852
  return {
851
853
  'x-apk-vm-owner': panelOwnerKey(),
852
854
  'x-apk-vm-scope': panelOwnerScope(),
853
- 'x-apk-vm-label': '桌面面板',
855
+ 'x-apk-vm-role': 'admin',
856
+ 'x-apk-vm-label': encodeURIComponent('桌面管理员'),
854
857
  };
855
858
  }
856
859
 
@@ -4692,6 +4695,7 @@ window.__ModuleLoader__.load({
4692
4695
  h(
4693
4696
  'div',
4694
4697
  { className: 'apkvm-ownerbody' },
4698
+ h('div', { className: 'apkvm-owneradmin' }, T('owner.admin')),
4695
4699
  h(
4696
4700
  'div',
4697
4701
  { className: 'apkvm-ownerrow' },
package/index.js CHANGED
@@ -951,9 +951,19 @@ export function apply(ctx, config = {}) {
951
951
  }
952
952
  }
953
953
 
954
+ function isLoopbackRequest(req) {
955
+ const address = String((req && req.socket && req.socket.remoteAddress) || '');
956
+ return address === '127.0.0.1' || address === '::1' || address.startsWith('::ffff:127.');
957
+ }
958
+
954
959
  function httpOwnerFromRequest(req) {
955
960
  const values = ownerFromHttp(req.headers || {}, requestQuery(req));
956
- return values ? instanceManager.ownerFor(values) : null;
961
+ if (!values) return null;
962
+ const owner = instanceManager.ownerFor(values);
963
+ // Admin is a local-panel privilege only. A remote/forwarded request may
964
+ // still identify itself, but it is downgraded to a normal owner.
965
+ if (owner.role === 'admin' && !isLoopbackRequest(req)) owner.role = 'user';
966
+ return owner;
957
967
  }
958
968
 
959
969
  function assertHttpOwner(req, res, instanceId = 'default') {
@@ -1559,16 +1569,18 @@ export function apply(ctx, config = {}) {
1559
1569
  sessionId: body.sessionId || (body.owner && body.owner.sessionId) || null,
1560
1570
  workspace: body.workspace || (body.owner && body.owner.workspace) || null,
1561
1571
  label: body.ownerLabel || body.label || (body.owner && body.owner.label) || '桌面面板',
1572
+ role: body.role || body.ownerRole || (body.owner && body.owner.role) || 'user',
1562
1573
  source: 'panel',
1563
1574
  });
1564
1575
  try {
1576
+ const admin = owner.role === 'admin';
1565
1577
  if (action === 'claim') {
1566
- const result = instanceManager.claimOwner(instanceId, owner, { force: body.force === true });
1578
+ const result = instanceManager.claimOwner(instanceId, owner, { force: body.force === true || admin });
1567
1579
  sendJson(res, 200, { ok: true, instanceId, ...result });
1568
1580
  return;
1569
1581
  }
1570
1582
  if (action === 'release') {
1571
- const released = instanceManager.releaseOwner(instanceId, owner, { force: body.force === true });
1583
+ const released = instanceManager.releaseOwner(instanceId, owner, { force: body.force === true || admin });
1572
1584
  sendJson(res, 200, { ok: true, instanceId, released });
1573
1585
  return;
1574
1586
  }
package/lib/http-owner.js CHANGED
@@ -4,24 +4,37 @@
4
4
  * the InstanceManager lease book.
5
5
  */
6
6
 
7
+ import { OWNER_ROLE, normalizeRole } from './vm-ownership.js';
8
+
7
9
  const HEADER_NAMES = [
8
10
  ['key', 'x-apk-vm-owner'],
9
11
  ['scope', 'x-apk-vm-scope'],
10
12
  ['sessionId', 'x-apk-vm-session'],
11
13
  ['workspace', 'x-apk-vm-workspace'],
12
14
  ['label', 'x-apk-vm-label'],
15
+ ['role', 'x-apk-vm-role'],
13
16
  ];
14
17
 
18
+ function decodeHeaderValue(value) {
19
+ const text = String(value);
20
+ if (!/%[0-9A-Fa-f]{2}/.test(text)) return text;
21
+ try {
22
+ return decodeURIComponent(text);
23
+ } catch (error) {
24
+ return text;
25
+ }
26
+ }
27
+
15
28
  function firstValue(headers, query, header) {
16
29
  const source = headers || {};
17
30
  const direct = source[header];
18
31
  if (direct !== undefined && direct !== null) {
19
- if (Array.isArray(direct)) return String(direct[0] || '').trim();
20
- return String(direct).trim();
32
+ if (Array.isArray(direct)) return decodeHeaderValue(String(direct[0] || '').trim());
33
+ return decodeHeaderValue(String(direct).trim());
21
34
  }
22
35
  if (query && typeof query.get === 'function') {
23
36
  const fromQuery = query.get(header.replace(/^x-apk-vm-/, ''));
24
- if (fromQuery !== undefined && fromQuery !== null) return String(fromQuery).trim();
37
+ if (fromQuery !== undefined && fromQuery !== null) return decodeHeaderValue(String(fromQuery).trim());
25
38
  }
26
39
  return '';
27
40
  }
@@ -36,6 +49,7 @@ export function ownerFromHttp(headers, query) {
36
49
  sessionId: firstValue(headers, query, 'x-apk-vm-session') || null,
37
50
  workspace: firstValue(headers, query, 'x-apk-vm-workspace') || null,
38
51
  label: firstValue(headers, query, 'x-apk-vm-label') || key,
52
+ role: normalizeRole(firstValue(headers, query, 'x-apk-vm-role')),
39
53
  source: 'http',
40
54
  };
41
55
  }
@@ -43,6 +57,12 @@ export function ownerFromHttp(headers, query) {
43
57
  /** Compare an incoming owner with the current lease; never mutate state. */
44
58
  export function checkOwnerAccess(lease, incoming, instanceId = 'default') {
45
59
  const id = String(instanceId || 'default');
60
+ // The local panel is the human administrator: it may operate every VM even
61
+ // when an Agent conversation owns the lease. It does not silently steal the
62
+ // lease; ownership metadata remains intact for the Agent's next turn.
63
+ if (incoming && normalizeRole(incoming.role) === OWNER_ROLE.ADMIN) {
64
+ return { ok: true, admin: true, autoClaim: false, touch: false };
65
+ }
46
66
  if (!lease) {
47
67
  return { ok: true, autoClaim: Boolean(incoming), touch: false };
48
68
  }
package/lib/instances.js CHANGED
@@ -17,6 +17,7 @@ import { createAvd, DEFAULT_SYSTEM_IMAGE } from './setup.js';
17
17
  import { ScrcpyStream } from './video-stream.js';
18
18
  import {
19
19
  DEFAULT_LEASE_TTL_MS,
20
+ OWNER_ROLE,
20
21
  OWNER_SCOPE,
21
22
  VmLeaseBook,
22
23
  createOwner,
@@ -451,13 +452,14 @@ export class InstanceManager {
451
452
  }
452
453
 
453
454
  /** Return a public owner descriptor from loose tool/route arguments. */
454
- ownerFor({ key, scope, sessionId, workspace, label, source = 'tool' } = {}) {
455
+ ownerFor({ key, scope, sessionId, workspace, label, role = OWNER_ROLE.USER, source = 'tool' } = {}) {
455
456
  return createOwner({
456
457
  key,
457
458
  scope: normalizeScope(scope || OWNER_SCOPE.SHARED),
458
459
  sessionId,
459
460
  workspace,
460
461
  label,
462
+ role,
461
463
  source,
462
464
  });
463
465
  }
@@ -20,6 +20,27 @@ export const OWNER_SCOPE = Object.freeze({
20
20
  export const OWNER_SCOPES = Object.values(OWNER_SCOPE);
21
21
  export const DEFAULT_LEASE_TTL_MS = 30 * 60 * 1000;
22
22
 
23
+ /**
24
+ * Roles are intentionally separate from scopes: a human panel user may be an
25
+ * administrator while still choosing a shared/conversation/project scope.
26
+ * Only the local panel should be allowed to send the admin role.
27
+ */
28
+ export const OWNER_ROLE = Object.freeze({
29
+ ADMIN: 'admin',
30
+ USER: 'user',
31
+ });
32
+ export const OWNER_ROLES = Object.values(OWNER_ROLE);
33
+
34
+ export function normalizeRole(value, fallback = OWNER_ROLE.USER) {
35
+ const text = String(value || '').trim().toLowerCase();
36
+ if (OWNER_ROLES.includes(text)) return text;
37
+ return fallback;
38
+ }
39
+
40
+ export function isAdminOwner(owner) {
41
+ return Boolean(owner && normalizeRole(owner.role) === OWNER_ROLE.ADMIN);
42
+ }
43
+
23
44
  export function normalizeScope(value, fallback = OWNER_SCOPE.SHARED) {
24
45
  const text = String(value || '').trim().toLowerCase();
25
46
  if (OWNER_SCOPES.includes(text)) return text;
@@ -94,6 +115,7 @@ export function createOwner({
94
115
  sessionId = null,
95
116
  workspace = null,
96
117
  label = '',
118
+ role = OWNER_ROLE.USER,
97
119
  source = 'tool',
98
120
  since = null,
99
121
  lastSeenAt = null,
@@ -111,6 +133,7 @@ export function createOwner({
111
133
  sessionId: cleanText(sessionId, 200) || null,
112
134
  workspace: cleanText(workspace, 400) || null,
113
135
  label: cleanText(label, 80) || ownerLabelFor({ key: resolvedKey, scope: normalizedScope, sessionId, workspace }),
136
+ role: normalizeRole(role),
114
137
  source: cleanText(source, 40) || 'tool',
115
138
  since: Number.isFinite(since) ? Number(since) : null,
116
139
  lastSeenAt: Number.isFinite(lastSeenAt) ? Number(lastSeenAt) : null,
@@ -127,6 +150,7 @@ export function publicOwner(owner) {
127
150
  sessionId: owner.sessionId || null,
128
151
  workspace: owner.workspace || null,
129
152
  label: ownerLabelFor(owner),
153
+ role: normalizeRole(owner.role),
130
154
  source: owner.source || 'tool',
131
155
  since: owner.since ?? null,
132
156
  lastSeenAt: owner.lastSeenAt ?? null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-apk-vm",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "type": "module",
5
5
  "description": "Local AOSP Android VM for DeepSeek Harness: preview rooted APKs at up to 60 fps, automate UIAutomator flows, and give each Agent an isolated VM.",
6
6
  "license": "Apache-2.0",