-
-
Notifications
You must be signed in to change notification settings - Fork 41
Orb P0 S3: GET /api/device/v1/events SSE (name-keyed upserts, resume, revoke closes, demo stops on switch-off) #3521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jaylfc
wants to merge
8
commits into
dev
Choose a base branch
from
exec/tsk-3nh2c4
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ad0f452
tsk-aa5qck: extract avatar slug + dir into agent_avatars module
jaylfc 4477ec5
feat(device): add GET /api/device/v1/state (agents:read)
jaylfc 5904ce8
fix: address review blockers on /api/device/v1/state
jaylfc 19283a7
fix: keep lock-widgets assembler pure and align demo flag helper
jaylfc b1799c6
fix: filter pending decisions by device owner in assemble_lock_agents
jaylfc a0682cf
# RED-PROOF
jaylfc 9c42821
fix: device SSE stream, per-connection IDs, snapshot logic, docs, tests
jaylfc c24b839
Merge exec/tsk-22jk4c into exec/tsk-3nh2c4: carry the device-owner de…
jaylfc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Fixed | ||
|
|
||
| - `GET /api/device/v1/state` now filters pending decisions by device owner, preventing a device paired to one owner from seeing another owner's pending decisions through a shared (no `user_id`) agent. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| ### Added | ||
|
|
||
| - `GET /api/device/v1/events` (scope `agents:read`, device bearer) emits | ||
| Server-Sent Events of owner-filtered agent state changes: `agent.upsert` | ||
| (name-keyed, full object including `avatar: {hue, hash}`), `agent.remove`, | ||
| `decision.open`, `decision.close`, `agent.recap`, and a `snapshot` event | ||
| when the client's `Last-Event-ID` is older than stream history. Heartbeat | ||
| is a comment line `: ping` every 15 seconds. | ||
|
|
||
| ### Security | ||
|
|
||
| - Revoking the device or losing the `agents:read` scope closes open SSE | ||
| streams immediately (re-checked on every loop tick). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ### Fixed | ||
|
|
||
| - `/auth/lock-widgets` now returns an empty string for an agent's status when no live container is present, instead of falling back to the configured `status` value. This keeps the pre-auth console endpoint pure and prevents config-derived status leakage before sign-in. | ||
| - `GET /api/device/v1/state` `demo` flag now uses the existing `_demo_enabled` helper instead of reading the env flag directly, matching the rest of the lock-screen demo paths. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Changed | ||
|
|
||
| - Extracted avatar slug and avatar directory logic from `tinyagentos/routes/auth.py` into a new `tinyagentos/agent_avatars.py` module, and added `avatar_source_path` and `avatar_hash` helpers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ### Added | ||
|
|
||
| - GET `/api/device/v1/state` (device bearer, scope `agents:read`): returns the owner-filtered agent list for the paired device, plus `server.version`, `time`, and `demo` flag. Server-side string caps (name 48, status 120, `last_recap` 180, question 280, option 40) with trailing ellipsis. `avatar.hash` is the first 16 hex chars of the avatar image SHA-256, or null when no image is installed. | ||
|
|
||
| ### Security | ||
|
|
||
| - `/api/device/v1/state` is registered in the device-bearer allowlist (`_DEVICE_BEARER_PATHS`) and is CSRF-exempt like the other device-bearer routes. Only a `taosdev_...` bearer with the `agents:read` scope may reach it; missing scope returns 403 with `device_scope_missing`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """Tests for tinyagentos.agent_avatars module (avatar_source_path + avatar_hash).""" | ||
| from __future__ import annotations | ||
|
|
||
| import hashlib | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from tinyagentos import agent_avatars as aa | ||
| from tinyagentos.agent_avatars import avatar_hash, avatar_source_path | ||
| from tinyagentos.routes.auth import _avatar_slug | ||
|
|
||
|
|
||
| class TestAvatarSourcePathAndHash: | ||
|
|
||
| def test_no_jpg_returns_none(self, tmp_path, monkeypatch): | ||
| monkeypatch.setattr(aa, "LOCK_AVATAR_DIR", str(tmp_path)) | ||
| assert avatar_source_path("Some Agent") is None | ||
| assert avatar_hash("Some Agent") is None | ||
|
|
||
| def test_existing_jpg_returns_path_and_hash(self, tmp_path, monkeypatch): | ||
| monkeypatch.setattr(aa, "LOCK_AVATAR_DIR", str(tmp_path)) | ||
| name = "Some Agent" | ||
| slug = _avatar_slug(name) | ||
| (tmp_path / f"{slug}.jpg").write_bytes(b"one") | ||
| assert avatar_source_path(name) == tmp_path / f"{slug}.jpg" | ||
| h = avatar_hash(name) | ||
| assert isinstance(h, str) | ||
| assert len(h) == 16 | ||
| assert h == hashlib.sha256(b"one").hexdigest()[:16] | ||
|
|
||
| def test_hash_changes_when_file_changes(self, tmp_path, monkeypatch): | ||
| monkeypatch.setattr(aa, "LOCK_AVATAR_DIR", str(tmp_path)) | ||
| name = "Some Agent" | ||
| slug = _avatar_slug(name) | ||
| p = tmp_path / f"{slug}.jpg" | ||
| p.write_bytes(b"one") | ||
| first = avatar_hash(name) | ||
| p.write_bytes(b"two") | ||
| second = avatar_hash(name) | ||
| assert first != second | ||
|
|
||
| def test_imported_slug_matches_module_slug(self): | ||
| name = "Some Agent" | ||
| assert _avatar_slug(name) == aa._avatar_slug(name) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add the events route to the allowlist doc.
This PR adds
GET /api/device/v1/eventsto_DEVICE_BEARER_PATHS. The documented allowlist stops at/state.- `GET /api/device/v1/state` — scope `agents:read` (owner-filtered agent list) +- `GET /api/device/v1/events` — scope `agents:read` (SSE agent state changes)📝 Committable suggestion
🤖 Prompt for AI Agents