anna-app-runtime-local 0.2.0a30__tar.gz → 0.2.0a33__tar.gz

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.
Files changed (19) hide show
  1. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/PKG-INFO +2 -2
  2. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/pyproject.toml +2 -2
  3. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/src/anna_app_runtime_local/__init__.py +1 -1
  4. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/src/anna_app_runtime_local/bridge.py +15 -1
  5. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/src/anna_app_runtime_local/jobs.py +1 -1
  6. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/src/anna_app_runtime_local/session.py +22 -27
  7. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/src/anna_app_runtime_local/store.py +2 -3
  8. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/tests/test_local_dispatch.py +55 -7
  9. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/tests/test_reverse_rpc.py +3 -3
  10. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/tests/test_tool_jobs.py +14 -2
  11. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/.gitignore +0 -0
  12. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/README.md +0 -0
  13. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/src/anna_app_runtime_local/executa.py +0 -0
  14. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/src/anna_app_runtime_local/token.py +0 -0
  15. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/src/anna_app_runtime_local/web_local.py +0 -0
  16. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/tests/__init__.py +0 -0
  17. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/tests/conftest.py +0 -0
  18. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/tests/test_frame_limits.py +0 -0
  19. {anna_app_runtime_local-0.2.0a30 → anna_app_runtime_local-0.2.0a33}/tests/test_web_local_images.py +0 -0
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: anna-app-runtime-local
3
- Version: 0.2.0a30
3
+ Version: 0.2.0a33
4
4
  Summary: Local-dev in-memory runtime for Anna Apps. Wraps anna-app-core's dispatcher with an InMemoryWindowStore + WebSocket bridge.
5
5
  Author: Talent AI
6
6
  License: Proprietary
7
7
  Keywords: anna,anna-app,dev,executa,harness
8
8
  Requires-Python: >=3.10
9
- Requires-Dist: anna-app-core<0.27,>=0.26.0
9
+ Requires-Dist: anna-app-core<0.29,>=0.28.0
10
10
  Requires-Dist: ddgs<10,>=9.13
11
11
  Description-Content-Type: text/markdown
12
12
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "anna-app-runtime-local"
3
- version = "0.2.0a30"
3
+ version = "0.2.0a33"
4
4
  description = "Local-dev in-memory runtime for Anna Apps. Wraps anna-app-core's dispatcher with an InMemoryWindowStore + WebSocket bridge."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -36,7 +36,7 @@ keywords = ["anna", "anna-app", "executa", "dev", "harness"]
36
36
  # (platform-media-generation-music §7) — same bridge-forward / not_implemented
37
37
  # contract as video.*.
38
38
  dependencies = [
39
- "anna-app-core>=0.26.0,<0.27",
39
+ "anna-app-core>=0.28.0,<0.29",
40
40
  "ddgs>=9.13,<10",
41
41
  ]
42
42
 
@@ -29,4 +29,4 @@ __all__ = [
29
29
  "DevTokenError",
30
30
  ]
31
31
 
32
- __version__ = "0.2.0a30"
32
+ __version__ = "0.2.0a33"
@@ -7,7 +7,14 @@ Protocol: one JSON envelope per line on stdin / stdout.
7
7
  Methods (request → response):
8
8
 
9
9
  session.create { user_id, manifest, view?, entry_payload?, app_slug? }
10
- → { session_id, window_uuid, token, expires_in }
10
+ → { session_id, window_uuid, token, expires_in, view,
11
+ view_meta, frame_permissions, permissions_policy }
12
+
13
+ ``frame_permissions`` / ``permissions_policy`` are the
14
+ production iframe ``allow`` fragments and bundle
15
+ ``Permissions-Policy`` header for this manifest
16
+ (anna_app_core.browser_permissions) — the harness
17
+ applies both so local == Dashboard (forum #395).
11
18
 
12
19
  session.call { session_id, ns, method, args? }
13
20
  → { ok: true, result: <dict> }
@@ -53,6 +60,11 @@ import traceback
53
60
  from collections.abc import AsyncIterator
54
61
  from typing import Any
55
62
 
63
+ from anna_app_core.browser_permissions import (
64
+ iframe_allow_parts,
65
+ permissions_policy_header,
66
+ )
67
+
56
68
  from .executa import (
57
69
  MAX_FRAME_BYTES,
58
70
  FRAME_HEAD_BYTES,
@@ -202,6 +214,8 @@ class _Bridge:
202
214
  "expires_in": expires_in,
203
215
  "view": session.window.view,
204
216
  "view_meta": _view_meta(session),
217
+ "frame_permissions": iframe_allow_parts(session.manifest),
218
+ "permissions_policy": permissions_policy_header(session.manifest),
205
219
  }
206
220
 
207
221
  elif method == "session.call":
@@ -35,7 +35,7 @@ ACTIVE_STATES = frozenset({"queued", "running"})
35
35
  PROGRESS_MAX = 500 # per-job ring buffer, mirrors ANNA_APP_TOOLS_JOB_PROGRESS_MAX
36
36
  HEARTBEAT_INTERVAL_S = 30.0
37
37
  RESULT_MAX_BYTES = 262_144 # mirrors ANNA_APP_TOOLS_JOB_RESULT_MAX_BYTES
38
- MAX_ACTIVE_PER_USER = 5 # mirrors ANNA_APP_TOOLS_JOB_MAX_ACTIVE_PER_USER
38
+ MAX_ACTIVE_PER_USER = 50 # mirrors ANNA_APP_TOOLS_JOB_MAX_ACTIVE_PER_USER (forum #474)
39
39
 
40
40
 
41
41
  def new_job_id() -> str:
@@ -86,9 +86,11 @@ class LocalDispatcherSession:
86
86
  app_slug: str | None = None,
87
87
  store: InMemoryWindowStore | None = None,
88
88
  ) -> "LocalDispatcherSession":
89
- from anna_app_core import AppManifest
89
+ from anna_app_core import AppManifest, normalize_legacy_manifest
90
90
 
91
- manifest = AppManifest.model_validate(manifest_dict)
91
+ # Harness ingest point (design app-permission-system-removal.md §5.2):
92
+ # schema ≤ 3 manifests are folded to schema 4 exactly like nexus does.
93
+ manifest = AppManifest.model_validate(normalize_legacy_manifest(manifest_dict))
92
94
 
93
95
  if store is None:
94
96
  store = InMemoryWindowStore()
@@ -196,20 +198,18 @@ _REVERSE_RPC_ROUTE: dict[str, tuple[str, str]] = {
196
198
  "image/generate": ("image", "generate"),
197
199
  "image/edit": ("image", "edit"),
198
200
  # NOTE: ``host/uploadFile`` is deliberately NOT in this table. It is an
199
- # executa-originated capability gated by the EXECUTA's own
200
- # ``upload_grant`` in production (matrix → nexus executa_upload_gate) —
201
- # the hosting app's ``ui.host_api`` ACL is never consulted. It is
202
- # handled by the dedicated ACL-bypass branch in
203
- # :class:`LocalServerRequestHandler` below (see ``_UPLOAD_MODE_TO_HOST``).
201
+ # executa-originated capability authorized by the EXECUTA's own
202
+ # ``upload_token`` in production (matrix → nexus executa_upload_gate). It
203
+ # is handled by the dedicated branch in :class:`LocalServerRequestHandler`
204
+ # below (see ``_UPLOAD_MODE_TO_HOST``).
204
205
  }
205
206
 
206
207
 
207
208
  # APS Files (object storage) reverse-RPC method → nexus storage REST method.
208
209
  #
209
- # These deliberately bypass the hosting app's ``ui.host_api`` ACL: in
210
- # production an executa's ``files/*`` calls travel on the executa's OWN
210
+ # In production an executa's ``files/*`` calls travel on the executa's OWN
211
211
  # ``storage_token`` (matrix Agent → ``/api/v1/storage/files/*``) and never
212
- # touch the app's grants. The local harness mirrors that by forwarding to
212
+ # touch the hosting app. The local harness mirrors that by forwarding to
213
213
  # ``host.storage.files_*`` over the python→node bridge, which the Node
214
214
  # ``LlmBridge`` turns into the matching ``/api/v1/storage/files/*`` request
215
215
  # using a minted ``storage_token`` — byte-for-byte the same path as
@@ -217,9 +217,8 @@ _REVERSE_RPC_ROUTE: dict[str, tuple[str, str]] = {
217
217
  #
218
218
  # Previously ``files/upload_begin`` / ``files/upload_complete`` were
219
219
  # misrouted onto the host-mediated ``upload.negotiate`` / ``upload.confirm``
220
- # facade, which (a) hit a different backend and (b) required a
221
- # ``ui.host_api.upload`` grant the App schema can't even express — so APS
222
- # Files via executa always failed under ``anna-app dev --storage aps``.
220
+ # facade, which hit a different backend — so APS Files via executa always
221
+ # failed under ``anna-app dev --storage aps``.
223
222
  _FILES_REVERSE_RPC: dict[str, str] = {
224
223
  "files/upload_begin": "files_init",
225
224
  "files/upload_complete": "files_finalize",
@@ -233,14 +232,11 @@ _FILES_REVERSE_RPC: dict[str, str] = {
233
232
  # Wire-identical to the matrix host handler (matrix
234
233
  # ``src/executa/host_upload.py``): a single JSON-RPC method whose
235
234
  # ``params.mode`` selects the sub-operation (default ``inline``). Like
236
- # ``files/*`` above, this is routed BEFORE the dispatcher route table so it
237
- # bypasses the app iframe ``ui.host_api`` ACL — in production an executa's
238
- # ``host/uploadFile`` is authorized by the executa's OWN ``upload_grant``
239
- # (nexus ``executa_upload_gate``) and never consults the hosting app's
240
- # manifest. Requiring ``ui.host_api.upload`` here broke the official
241
- # file-upload demo under `anna-app dev` (forum #159), and the old
242
- # ``("upload", "inline")`` route additionally ignored ``mode`` — silently
243
- # collapsing negotiate/confirm onto inline.
235
+ # ``files/*`` above, this is routed BEFORE the dispatcher route table — in
236
+ # production an executa's ``host/uploadFile`` is authorized by the executa's
237
+ # OWN ``upload_token`` (nexus ``executa_upload_gate``) and never consults the
238
+ # hosting app's manifest. The old ``("upload", "inline")`` route ignored
239
+ # ``mode`` — silently collapsing negotiate/confirm onto inline.
244
240
  _UPLOAD_MODE_TO_HOST: dict[str, str] = {
245
241
  "inline": "host.upload.inline",
246
242
  "negotiate": "host.upload.negotiate",
@@ -279,6 +275,7 @@ def _validate_sampling_text_only(args: dict) -> None:
279
275
  },
280
276
  )
281
277
 
278
+
282
279
  # Custom JSON-RPC code for "implemented in production but not in this
283
280
  # runtime" — matches the matrix host convention also used for the
284
281
  # dispatcher's ``not_implemented`` mapping below.
@@ -358,9 +355,8 @@ class LocalServerRequestHandler:
358
355
  args = {k: v for k, v in params.items() if k != "context"}
359
356
 
360
357
  # APS Files (object storage) reverse-RPC. Routed BEFORE the dispatcher
361
- # route table so it bypasses the app iframe ``ui.host_api`` ACL — in
362
- # production these go out on the executa's own ``storage_token`` and
363
- # never touch the hosting app's grants. Forward to the Node-side
358
+ # route table — in production these go out on the executa's own
359
+ # ``storage_token`` and never touch the hosting app. Forward to the Node-side
364
360
  # storage_token path when APS forwarding is wired; otherwise surface a
365
361
  # clean ``not_implemented`` (the in-memory harness has no object
366
362
  # storage backend, mirroring ``executa dev --storage memory``).
@@ -386,9 +382,8 @@ class LocalServerRequestHandler:
386
382
  # Host-mediated user-artifact upload. Routed BEFORE the dispatcher
387
383
  # route table so it bypasses the app iframe ``ui.host_api`` ACL —
388
384
  # see the ``_UPLOAD_MODE_TO_HOST`` comment for the production
389
- # semantics this mirrors. Grant enforcement happens server-side
390
- # (nexus rejects with APP_NOT_GRANTED when the dev app's
391
- # ``upload_grant`` is off).
385
+ # semantics this mirrors. Owner enforcement happens server-side
386
+ # (nexus rejects with APP_NOT_GRANTED when the dev app is disabled).
392
387
  if method == "host/uploadFile":
393
388
  mode = args.get("mode") or "inline"
394
389
  host_method = _UPLOAD_MODE_TO_HOST.get(mode)
@@ -437,8 +437,7 @@ class InMemoryWindowStore:
437
437
  async def agent_session_catalog(self, *, user_id, window, manifest, args):
438
438
  # Pre-create platform-tool discovery (dispatcher 0.18.0). The Node
439
439
  # LlmBridge answers locally (mock catalog derived from the manifest's
440
- # ``agent.tools`` declaration — the harness has no user-grant
441
- # concept, so ``user_granted`` is always true).
440
+ # ``agent.tools`` declaration).
442
441
  return await self._delegate(
443
442
  "host.agent.session.catalog", args, "agent.session.catalog"
444
443
  )
@@ -513,7 +512,7 @@ class InMemoryWindowStore:
513
512
  #
514
513
  # docs/design/platform-media-generation-video-audio.md §7 / §9 / §10.
515
514
  # Same host-mediated shape as image.*: production nexus delegates to
516
- # ``app_media_facade`` in-process (grant / quota / billing / job state
515
+ # ``app_media_facade`` in-process (owner check / quota / billing / job state
517
516
  # machine). With a bridge we forward ``host.video.*`` / ``host.audio.*`` /
518
517
  # ``host.llm.catalog`` so the Node LlmBridge mints and POSTs the matching
519
518
  # ``/api/v1/copilot/app/{video,audio,models}`` route; without one we
@@ -89,8 +89,7 @@ async def test_window_hello_returns_capabilities_and_view_meta():
89
89
  out = await sess.call("window", "hello", {})
90
90
  assert out["entry_payload"] == {"topic": "ECM"}
91
91
  assert out["view_meta"]["name"] == "main"
92
- assert "host_api_version" in out["capabilities"]
93
- assert "scopes" in out["capabilities"]
92
+ assert out["capabilities"] == {"host_api_version": "0.1.0"}
94
93
  assert out["is_resume"] is False
95
94
  # forum #376: app identity from the harness store (slug doubles as name).
96
95
  assert out["app"]["id"] == 1
@@ -191,14 +190,17 @@ async def test_tools_list_reflects_manifest_whitelist():
191
190
 
192
191
 
193
192
  @pytest.mark.asyncio
194
- async def test_unallowed_namespace_returns_permission_denied():
195
- # `chat` is missing from host_api below → dispatcher must reject.
193
+ async def test_undeclared_namespace_is_allowed():
194
+ # No method-level ACL (design app-permission-system-removal.md): an
195
+ # installed App may call every Host API method; legacy `host_api`
196
+ # method lists are folded away on ingest.
196
197
  sess = LocalDispatcherSession.create(
197
198
  user_id=1, manifest_dict=_manifest(host_api={"storage": ["*"]})
198
199
  )
199
- with pytest.raises(LocalSessionError) as exc:
200
- await sess.call("chat", "write_message", {"role": "assistant", "content": "hi"})
201
- assert exc.value.code == "permission_denied"
200
+ out = await sess.call(
201
+ "chat", "write_message", {"role": "assistant", "content": "hi"}
202
+ )
203
+ assert isinstance(out, dict)
202
204
 
203
205
 
204
206
  @pytest.mark.asyncio
@@ -357,6 +359,52 @@ async def test_bridge_handle_session_create_and_call():
357
359
  )
358
360
 
359
361
 
362
+ @pytest.mark.asyncio
363
+ async def test_bridge_session_create_returns_browser_permission_gates():
364
+ """design app-ui-browser-permissions.md §3.8 — harness == Dashboard.
365
+
366
+ ``session.create`` returns the production iframe ``allow`` fragments and
367
+ the bundle ``Permissions-Policy`` header for the manifest so the CLI
368
+ harness applies the same two gates (forum #395: mic worked locally only).
369
+ """
370
+ from anna_app_core.browser_permissions import PERMISSIONS_POLICY_FALLBACK
371
+ from anna_app_runtime_local.bridge import _Bridge
372
+
373
+ bridge = _Bridge()
374
+
375
+ async def create(manifest):
376
+ resp = await bridge.handle(
377
+ {
378
+ "jsonrpc": "2.0",
379
+ "id": 1,
380
+ "method": "session.create",
381
+ "params": {"user_id": 1, "manifest": manifest},
382
+ }
383
+ )
384
+ return resp["result"]
385
+
386
+ # Nothing declared → nothing delegated, every baseline feature denied.
387
+ plain = await create(_manifest())
388
+ assert plain["frame_permissions"] == []
389
+ assert plain["permissions_policy"] == PERMISSIONS_POLICY_FALLBACK
390
+
391
+ # transcribe alone does NOT imply the microphone (forum #395 root cause).
392
+ m = _manifest(host_api={"audio": ["speak", "transcribe"]})
393
+ stt = await create(m)
394
+ assert stt["frame_permissions"] == []
395
+ assert "microphone=()" in stt["permissions_policy"]
396
+
397
+ # Explicit declaration opens both gates.
398
+ m["ui"]["browser_permissions"] = ["microphone"]
399
+ explicit = await create(m)
400
+ assert explicit["frame_permissions"] == ["microphone 'src'"]
401
+ assert "microphone=(self)" in explicit["permissions_policy"]
402
+
403
+ # Implied by the realtime voice session grant.
404
+ implied = await create(_manifest(host_api={"audio": ["session"]}))
405
+ assert implied["frame_permissions"] == ["microphone 'src'"]
406
+
407
+
360
408
  @pytest.mark.asyncio
361
409
  async def test_bridge_unknown_method_returns_method_not_found():
362
410
  from anna_app_runtime_local.bridge import _Bridge
@@ -701,9 +701,9 @@ async def test_files_legacy_mode_returns_not_implemented() -> None:
701
701
 
702
702
  # ---------------------------------------------------------------------------
703
703
  # host/uploadFile (host-mediated user-artifact upload) via an executa's
704
- # reverse-RPC. Must (a) bypass the app iframe ``ui.host_api`` ACL — in
705
- # production the executa's OWN ``upload_grant`` authorizes it, never the
706
- # hosting app's manifest (forum #159) — and (b) dispatch on ``params.mode``
704
+ # reverse-RPC. Must (a) never consult the hosting app's manifest — in
705
+ # production the executa's OWN ``upload_token`` authorizes it (forum #159) —
706
+ # and (b) dispatch on ``params.mode``
707
707
  # exactly like the matrix host handler, instead of collapsing
708
708
  # negotiate/confirm onto inline.
709
709
  # ---------------------------------------------------------------------------
@@ -221,10 +221,15 @@ async def test_cross_user_get_is_job_not_found():
221
221
 
222
222
 
223
223
  @pytest.mark.asyncio
224
- async def test_quota_exceeded():
224
+ async def test_quota_exceeded(monkeypatch):
225
+ # 配额常量镜像生产 ANNA_APP_TOOLS_JOB_MAX_ACTIVE_PER_USER(forum #474:5→50);
226
+ # 用例显式设 2,不依赖默认值。
227
+ import anna_app_runtime_local.jobs as jobs_mod
228
+
229
+ monkeypatch.setattr(jobs_mod, "MAX_ACTIVE_PER_USER", 2)
225
230
  pool = FakePool(delay_s=10.0)
226
231
  sess, _ = _session(pool)
227
- for _ in range(5):
232
+ for _ in range(2):
228
233
  await sess.call(
229
234
  "tools", "invokeAsync", {"tool_id": TOOL_ID, "method": "run_steps"}
230
235
  )
@@ -233,6 +238,13 @@ async def test_quota_exceeded():
233
238
  "tools", "invokeAsync", {"tool_id": TOOL_ID, "method": "run_steps"}
234
239
  )
235
240
  assert ei.value.code == "job_quota_exceeded"
241
+ assert ei.value.details["max_active"] == 2
242
+
243
+
244
+ def test_quota_default_mirrors_production():
245
+ import anna_app_runtime_local.jobs as jobs_mod
246
+
247
+ assert jobs_mod.MAX_ACTIVE_PER_USER == 50
236
248
 
237
249
 
238
250
  @pytest.mark.asyncio