a6ee31f55a
* feat(wisdom): add trusted publish and install foundation
* feat(wisdom): add private contribution loop
* feat(wisdom): add managed consumption workflows
* fix(wisdom): close cross-repository safety gaps
* fix(wisdom): align local package and lifecycle policy
* fix(wisdom): require explicit profile setup
* docs(wisdom): repin reconciled gateway head
* fix(wisdom): fence content downloads and approval receipts
* docs(wisdom): record generation-fenced downloads
* docs(wisdom): record unified delivery PR
* fix(ci): stop passing invalid classifier inputs
* docs(wisdom): remove internal requirements ledger
* feat(wisdom): localize dashboard and desktop copy
* feat(wisdom): complete local contribution and consumption UX
* style(wisdom): satisfy desktop lint
* chore(wisdom): refresh requirements pin
* test(dashboard): allow formatted profile copy
* test(wisdom): stabilize desktop interaction coverage
* fix(wisdom): surface dashboard action failures
* fix(wisdom): add repeatable Portal demo login
* feat(wisdom): add actionable skill notifications
* feat(wisdom): add notification install and update actions
* fix(wisdom): make Telegram skill alerts actionable
* fix(wisdom): always refresh demo Agent login
* feat(wisdom): embed Telegram notification actions
* fix(wisdom): preserve Telegram notifications after actions
* fix(wisdom): keep Telegram notification cards readable
* feat(wisdom): add Telegram candidate approval flow
* feat(wisdom): explain Telegram qualification reasons
* fix(wisdom): reconcile cross-surface candidate actions
* feat(telegram): add Collective Wisdom management command
* chore(wisdom): refresh Gateway contract pin
* chore(wisdom): advance Gateway contract pin
* feat(wisdom): align command UX across clients
* feat(slack): add Collective Wisdom management parity
* feat(wisdom): add security and professionalism reviews
* feat(wisdom): add first-time qualification guidance
* feat(wisdom): simplify qualification sharing choices
* feat(skills): add optional editorial metadata
* feat(wisdom): enrich legacy skill presentation
* fix(wisdom): harden review and update boundaries
* fix(wisdom): emit canonical review timestamps
* fix(wisdom): align with merged gateway and main
* wisdom: add agent-led sharing core (policy, evidence, schemas, templates, delivery, weekly job, share/install flows)
- hermes_wisdom/agent_led/: policy resolution (server > local > defaults),
7-day evidence builder that excludes bundled/hub/managed skills and
dismissed/handled/recently-suggested content hashes, strict pydantic
schemas for agent output with repair-or-reject, fixed copy templates
(Share / Teammate / Published / Update / Mute), idempotent retried
delivery ledger with stale-action resolution, weekly review job,
resumable Share and Install flows.
- prompts/: candidate review, recipient recommendation, share packaging.
- tests/wisdom/test_agent_led.py: 30 tests.
* wisdom: agent-led renderers and button action dispatcher
- render.py: Telegram HTML, Slack blocks, Desktop payload; editorial name
is the emphasized line, product label stays separate.
- actions.py: resolve opaque wa:<action>:<dedup> targets via the delivery
ledger; Not now -> dismissal, Mute -> fixed options, Share -> resumable
packaging flow, Install/Update -> plan command. Never publishes/installs.
* wisdom: CLI verbs, agent_led config default, conversational catalog skill
- hermes wisdom browse/review-week/act/share/dismiss/mute (all --json).
- wisdom.agent_led config block, default enabled.
- SKILL.md rewritten so natural-language catalog questions map to the CLI
verbs, share/install flows and fixed notification templates.
* wisdom: wire agent-led weekly review into gateway tick and Telegram buttons
- gateway housekeeping tick calls maybe_run_weekly_review with a home
channel sender when a Telegram adapter is available.
- Telegram: wa: callbacks resolved through the ledger (stale-safe), mute
duration keyboard, send_wisdom_agent_recommendation rich card + fallback.
* fix(wisdom): integrate local mediation and harden model and setup boundaries
* fix(wisdom): honor authoritative recommendation policy and defer on failure
* fix(wisdom): synchronize opaque suppression and recheck delivery preferences
* feat(wisdom): route weekly selection through the session-owned assessment queue
* fix(wisdom): prepare and submit the reviewed generated share package
* feat(wisdom): separate native Share preparation from publication consent
* feat(wisdom): sync native mute choices through a leased preference outbox
* feat(wisdom): bind native mute controls to durable preference choices
* feat(wisdom): add scoped desktop and dashboard notification settings
* fix(wisdom): revalidate feed recommendations before assessment and delivery
* fix(wisdom): persist validated delivery receipts before completing notices
* feat(wisdom): add private notification claim and receipt client
* Persist Wisdom send reservations and recover delivery acknowledgements
* Route legacy Wisdom controls through current native review
* Add typed private Wisdom operation outcome client
* fix(wisdom): make agent-led advice usable in the local demo
* fix(wisdom): keep requested consent outside proactive limits
* fix(wisdom): distinguish unavailable assessments and preserve digest text
* fix(wisdom): assess ongoing usefulness beyond the current task
* fix(wisdom): restore immediate qualification sharing controls
* fix(wisdom): separate qualification review from installation advice
* fix(wisdom): collapse review checklists and simplify sharing copy
* fix(wisdom): show compact sharing progress and publication receipts
* fix(wisdom): require credential prefixes rather than matching skill names
* fix(wisdom): finish package checks before presenting sharing consent
* fix(wisdom): scan local skills before qualification cards
* fix(wisdom): update moderation results on existing sharing cards
* fix(wisdom): keep sharing review accessible from receipt cards
* fix(wisdom): align mediated review cards and collapsible checks
* fix(wisdom): clarify clean security summary wording
* fix(wisdom): normalize consent plans and add explicit recheck
* fix(wisdom): keep install and update receipts concise
* fix(wisdom): collapse assessments and deduplicate operation cards
* fix(wisdom): restore private Portal review from native cards
* fix(wisdom): sync Portal publication to original consent card
* fix(wisdom): show local skill version on sharing cards
* fix(wisdom): skip agent recommendations for self-published versions
* fix(wisdom): simplify candidate notices and local-edit recovery copy
* feat(wisdom): submit locally reviewed packages with one confirmation
* feat(wisdom): expose safe receipt and outcome sync recovery
* wisdom: onboarding notice says detect and share, names the user's own skill
Copy review from the product owner on the first and returning
qualification notices (fixed delivery mode):
- the feature blurb now says the org enabled detection *and sharing*
- both notices say the detected skill is one the user created
- both close with an exclamation mark
Applied identically to hermes_wisdom.notice, the desktop and web i18n
strings, and the tests that assert the sentences.
* wisdom: one opener, no approval line, ask to share after the skill is shown
Product owner review of the candidate card.
- The Hermes written card now opens with the same sentence as the fixed card
("Your organisation has enabled Collective Wisdom, a feature designed to
automatically detect and share useful skills across all team members.")
instead of its own blurb, so there is one first time message.
- "Nothing is shared without your approval." removed from Telegram, Slack
and Desktop. The buttons already make the permission explicit.
- "Would you like to share?" no longer appears before the skill is named.
It is now the last line, after the skill name, description, why suggested
and the checks, and reads "Would you like to share it?" (matching the
agent led template wording).
Tests updated for the new order; proposalNotice removed from all desktop locales.
* wisdom: American spelling, organization
Product owner decision: user facing copy uses American spelling.
Changes "Your organisation" to "Your organization" in the chat notice,
the Hermes written card opener, the desktop and web strings, and the
tests that assert them. Identifiers such as nas_organisation:* and the
German and French locales are untouched.
* wisdom: candidate card copy round 4 (owner review)
Apply the product owner's round 4 copy decisions to the Hermes Collective
Wisdom candidate card on Telegram, Slack, Desktop and the shared views:
1. Hermes-written cards are titled "Hermes Collective Wisdom" instead of
the bare "Collective Wisdom".
2. The "Reusable skill ready to review" line is gone from the candidate
card (Telegram rich card and plain fallback, legacy agent-led share
template).
3. The skill name and description are labelled: "Skill name: <name>" and
"What it does: <description>" (Telegram, Slack, Desktop).
4. "Why suggested:" is now "Why others might benefit:".
5. A passing professionalism review reads "Safe to share at work ✓ (no
inappropriate content found)" with no per-check bullets and no "Pass";
a failed review reads "Needs a look before sharing at work (possible
inappropriate content)" and lists only the checks that flagged
something. Pending/unavailable wording is unchanged.
6. Telegram button toasts: "Will ask later...", "Preparing more
details...", "Sharing...".
7. Qualification reasons: "You used this skill consistently across many
days." and "You've really refined this skill."
8. prompts/wisdom_candidate_review.md asks for a compelling
editorial_name, a simple one_line_description and a compelling
why_coworkers_benefit under 300 characters; "Be concise and
convincing." becomes "Be concise and compelling: the goal is that the
user wants to share it."
Tests updated for the new strings; review_text() gains direct coverage.
* wisdom: re-apply owner copy after rebase
- Native share cards (advice_view/interaction_view): drop the approval line, ask "Would you like to share it?" as the last line after the checks
- Hermes-written completion card titled "Hermes Collective Wisdom"
- Qualification reasons use the owner wording (consistently across many days / really refined)
- American spelling (organization) in remaining English copy
- Desktop test asserts the current Share button; web test matches the returning notice
* fix(wisdom): pin reconciled Gateway and verify Unicode hash vectors
Pin Gateway 60cd2d6b613ae3cd4a6e65155d1142006d907e78 and byte-identical producer artifacts. Verify every content-order case and package-manifest binding. Validation: 186 focused Python tests, Ruff and contract verifier.
* fix(wisdom): reconcile optional SDK tests and frontend lint
* fix(wisdom): default to agent-written notification summaries
* fix(wisdom): restore deferred install review and browse controls
* feat(wisdom): inspect installed setup with exact package provenance
* feat(wisdom): run native-approved installed setup steps with durable evidence
* fix(wisdom): recover interrupted setup with explicit native consent
* feat(wisdom): hand native installs into guided setup review
* fix(wisdom): continue requested setup with fixed notification copy
* fix(wisdom): preserve setup while waiting for a session model
* fix(wisdom): expose canonical setup review controls on desktop
* fix(wisdom): resume setup after recorded automatic updates
* fix(wisdom): make missing setup prerequisites recheckable
* chore(wisdom): align Agent with verified Gateway contract
* fix(wisdom): stop guessing team slugs in portal links
* fix(wisdom): retire pending advice on account sign-out
* fix(wisdom): cancel advice after terminal account revocation
* fix(wisdom): fence feed responses across account sign-out
* fix(wisdom): checkpoint signed-out feed before reactivation
* fix(wisdom): link proactive advice to scoped notification settings
* fix(wisdom): coalesce queued publication recommendations by version
* fix(wisdom): keep package review navigation local and deferable
* fix(wisdom): reflect installed state in discovery controls
* fix(wisdom): show exact checks before command confirmation
* chore(wisdom): pin bounded analytics privacy contract
* chore(wisdom): pin retired legacy notification contract
* feat(wisdom): review publisher usage with exact sharing copy
* fix(wisdom): align discovery and review check summaries
* fix(wisdom): show expired consent before confirmation
* fix(wisdom): require fresh review for legacy install controls
* fix(wisdom): preserve review expiry across check toggles
* fix(wisdom): retain update policy in native install reviews
* fix(wisdom): surface failed native card edits
* fix(wisdom): persist local command approval reviews
* fix(wisdom): use saved approvals for messaging commands
* test(wisdom): provide scan result in setup handoff fixture
* test(wisdom): exercise Telegram approvals with saved review state
* fix(wisdom): retain suppression policy for offline deferral
* fix(wisdom): reconsider candidates after deferred suppression expires
* fix(wisdom): bind review checks and report verified readiness separately
* fix(wisdom): persist accepted publication intent and recover exact outcomes
* fix(sync): pin UTF-8 tree ordering across writers
* chore(wisdom): pin organisation-scoped Gateway authorization
* fix(wisdom): restrict consent delivery to user-facing sessions
* chore(wisdom): refresh reviewed Gateway contract pin
* fix(wisdom): preserve kept tools in Blank Slate exclusions
* test(auth): reset anonymous fixture with a profile-scoped cache
* fix(wisdom): gate local surfaces and work on current profile entitlement
* fix(wisdom): invalidate quiet tool cache on entitlement changes
* test(wisdom): authorize local consent gateway fixtures
* fix(wisdom): keep entitlement decoding free of native crypto imports
* test(wisdom): provide local entitlement to demo CLI subprocess
* ci: leave upstream workflow unchanged in Wisdom PR
* fix(wisdom): ship package and contracts in Nix wheels
---------
Co-authored-by: hbizi <36184542+hbizi@users.noreply.github.com>
543 lines
19 KiB
Python
543 lines
19 KiB
Python
"""Profile-scoped Collective Wisdom API for Dashboard and Desktop.
|
|
|
|
Gateway credentials and endpoints remain inside this process.
|
|
"""
|
|
|
|
import asyncio
|
|
import hashlib
|
|
import re
|
|
from typing import Any, List, Optional
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
from hermes_cli.web_models import (
|
|
WisdomSuggestRequest,
|
|
WisdomReviewRequest,
|
|
WisdomPublicationRequest,
|
|
WisdomPreparedSaveRequest,
|
|
WisdomCandidateDismissRequest,
|
|
WisdomCandidateEventRequest,
|
|
WisdomReviseRequest,
|
|
WisdomDecisionRequest,
|
|
WisdomSetupRequest,
|
|
WisdomScanRequest,
|
|
WisdomInstallPlanRequest,
|
|
WisdomInstallApplyRequest,
|
|
WisdomCheckRequest,
|
|
WisdomUpdatePlanRequest,
|
|
WisdomUpdateApplyRequest,
|
|
WisdomUninstallRequest,
|
|
WisdomNotificationRequest,
|
|
WisdomConsentRequest,
|
|
WisdomMutePrepareRequest,
|
|
WisdomSyncRetryRequest,
|
|
WisdomMuteChooseRequest,
|
|
)
|
|
from hermes_cli.web_routers._common import (
|
|
_profile_scope,
|
|
_spawn_hermes_action,
|
|
log as _log,
|
|
)
|
|
from hermes_cli.web_server_profiles import _profile_cli_args
|
|
from hermes_cli.web_server_gateway import _ACTION_LOG_FILES, _ACTION_PROCS
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
def _wisdom_http_error(exc: Exception) -> HTTPException:
|
|
from hermes_wisdom.client import WisdomError
|
|
from hermes_wisdom.package import PackagePolicyError
|
|
|
|
if isinstance(exc, WisdomError):
|
|
status = {
|
|
3: 403,
|
|
4: 404,
|
|
5: 409,
|
|
6: 422,
|
|
7: 409,
|
|
8: 503,
|
|
}.get(exc.exit_code, 500)
|
|
return HTTPException(status_code=status, detail=str(exc))
|
|
if isinstance(exc, PackagePolicyError):
|
|
return HTTPException(status_code=422, detail=str(exc))
|
|
_log.exception("Collective Wisdom request failed")
|
|
return HTTPException(status_code=500, detail="Collective Wisdom request failed")
|
|
|
|
|
|
async def _run_wisdom(profile: Optional[str], fn, *, require_setup: bool = True):
|
|
def run():
|
|
with _profile_scope(profile):
|
|
from hermes_wisdom.service import WisdomService
|
|
from hermes_wisdom.entitlement import require_entitlement
|
|
|
|
require_entitlement()
|
|
service = WisdomService()
|
|
if require_setup:
|
|
service.require_setup()
|
|
return fn(service)
|
|
|
|
try:
|
|
return await asyncio.to_thread(run)
|
|
except Exception as exc:
|
|
raise _wisdom_http_error(exc) from exc
|
|
|
|
|
|
def _schedule_wisdom_professionalism_reviews(profile: Optional[str]) -> None:
|
|
"""Wake the local review worker after Dashboard/Desktop creates new work."""
|
|
|
|
async def run() -> None:
|
|
try:
|
|
await _run_wisdom(
|
|
profile,
|
|
lambda service: service.process_professionalism_reviews(max_jobs=4),
|
|
)
|
|
except Exception:
|
|
_log.debug("Collective Wisdom professionalism worker failed", exc_info=True)
|
|
|
|
asyncio.create_task(run())
|
|
|
|
|
|
|
|
|
|
@router.get("/api/wisdom/entitlement")
|
|
async def get_wisdom_entitlement(profile: Optional[str] = None):
|
|
"""Expose refresh-free local JWT entitlement metadata for UI gating."""
|
|
def run():
|
|
with _profile_scope(profile):
|
|
from hermes_wisdom.entitlement import current_entitlement
|
|
|
|
# Derive the boolean and metadata from one auth/token snapshot so a
|
|
# concurrent token replacement cannot produce a mismatched response.
|
|
metadata = current_entitlement()
|
|
scopes = tuple(metadata.get("scopes", ()))
|
|
return {
|
|
"entitled": "wisdom:read" in scopes,
|
|
"org_id": metadata.get("org_id"),
|
|
"scopes": list(scopes),
|
|
"expires_at": metadata.get("expires_at"),
|
|
}
|
|
|
|
try:
|
|
return await asyncio.to_thread(run)
|
|
except Exception:
|
|
# This presentation gate must fail closed and must never trigger auth refresh.
|
|
_log.debug("Collective Wisdom entitlement probe failed", exc_info=True)
|
|
return {"entitled": False, "org_id": None, "scopes": [], "expires_at": None}
|
|
|
|
|
|
@router.get("/api/wisdom/status")
|
|
async def get_wisdom_status(profile: Optional[str] = None):
|
|
return await _run_wisdom(
|
|
profile, lambda service: service.status(), require_setup=False
|
|
)
|
|
|
|
|
|
@router.get("/api/wisdom/sync")
|
|
async def get_wisdom_sync(profile: Optional[str] = None):
|
|
return await _run_wisdom(profile, lambda service: service.sync_status())
|
|
|
|
|
|
@router.post("/api/wisdom/sync/retry")
|
|
async def post_wisdom_sync_retry(body: WisdomSyncRetryRequest):
|
|
return await _run_wisdom(body.profile, lambda service: service.retry_sync())
|
|
|
|
|
|
def _wisdom_action_name(verb: str, profile: Optional[str]) -> str:
|
|
scope = (profile or "current").strip().lower() or "current"
|
|
slug = re.sub(r"[^a-z0-9]+", "-", scope).strip("-")[:32] or "current"
|
|
digest = hashlib.sha1(scope.encode()).hexdigest()[:8]
|
|
name = f"wisdom-{verb}-{slug}-{digest}"
|
|
_ACTION_LOG_FILES.setdefault(name, f"action-{name}.log")
|
|
return name
|
|
|
|
|
|
def _spawn_wisdom_action(
|
|
verb: str, profile: Optional[str], command: List[str]
|
|
) -> dict[str, Any]:
|
|
name = _wisdom_action_name(verb, profile)
|
|
existing = _ACTION_PROCS.get(name)
|
|
if existing is not None and existing.poll() is None:
|
|
return {"ok": True, "pid": existing.pid, "name": name, "reused": True}
|
|
args = [*_profile_cli_args(profile), "wisdom", *command, "--json"]
|
|
proc = _spawn_hermes_action(args, name)
|
|
return {"ok": True, "pid": proc.pid, "name": name, "reused": False}
|
|
|
|
|
|
@router.post("/api/wisdom/setup")
|
|
async def post_wisdom_setup(body: WisdomSetupRequest):
|
|
if not body.accept_disclosure:
|
|
raise HTTPException(
|
|
status_code=422,
|
|
detail="Collective Wisdom setup requires explicit disclosure acceptance",
|
|
)
|
|
try:
|
|
return _spawn_wisdom_action(
|
|
"setup", body.profile, ["setup", "--accept-disclosure"]
|
|
)
|
|
except HTTPException:
|
|
raise
|
|
except Exception as exc:
|
|
_log.exception("Failed to start Collective Wisdom setup")
|
|
raise HTTPException(status_code=500, detail=f"Failed to start setup: {exc}")
|
|
|
|
|
|
@router.post("/api/wisdom/scan")
|
|
async def post_wisdom_scan(body: WisdomScanRequest):
|
|
command = ["scan", *([body.skill] if body.skill else [])]
|
|
try:
|
|
return _spawn_wisdom_action("scan", body.profile, command)
|
|
except HTTPException:
|
|
raise
|
|
except Exception as exc:
|
|
_log.exception("Failed to start Collective Wisdom scan")
|
|
raise HTTPException(status_code=500, detail=f"Failed to start scan: {exc}")
|
|
|
|
|
|
@router.get("/api/wisdom/candidates")
|
|
async def get_wisdom_candidates(profile: Optional[str] = None):
|
|
return await _run_wisdom(
|
|
profile, lambda service: {"candidates": service.scan_candidates()}
|
|
)
|
|
|
|
|
|
@router.get("/api/wisdom/events")
|
|
async def get_wisdom_events(
|
|
profile: Optional[str] = None, session_id: Optional[str] = None
|
|
):
|
|
def read(service):
|
|
from hermes_wisdom.mediation import delivery_mode
|
|
|
|
if delivery_mode() == "agent":
|
|
return {"events": [], "delivery_mode": "agent"}
|
|
return {
|
|
"events": service.pending_candidate_events(
|
|
session_id=session_id or "", surface="desktop"
|
|
)
|
|
}
|
|
|
|
return await _run_wisdom(profile, read)
|
|
|
|
|
|
@router.get("/api/wisdom/drafts")
|
|
async def get_wisdom_drafts(profile: Optional[str] = None):
|
|
return await _run_wisdom(
|
|
profile,
|
|
lambda service: {
|
|
"drafts": [
|
|
draft.model_dump(mode="json") for draft in service.client.list_drafts()
|
|
]
|
|
},
|
|
)
|
|
|
|
|
|
@router.get("/api/wisdom/discovery")
|
|
async def get_wisdom_discovery(profile: Optional[str] = None):
|
|
return await _run_wisdom(profile, lambda service: service.list_skills())
|
|
|
|
|
|
@router.get("/api/wisdom/skills/{skill_id}")
|
|
async def get_wisdom_skill(skill_id: str, profile: Optional[str] = None):
|
|
# Command views intentionally show human-readable slugs. Accept the same
|
|
# opaque-ID-or-exact-slug references as `/wisdom show` so Desktop preview
|
|
# actions can consume command output without leaking registry IDs into it.
|
|
return await _run_wisdom(profile, lambda service: service.resolve_skill(skill_id))
|
|
|
|
|
|
@router.get("/api/wisdom/skills/{skill_id}/versions/{version}")
|
|
async def get_wisdom_version(
|
|
skill_id: str, version: int, profile: Optional[str] = None
|
|
):
|
|
return await _run_wisdom(
|
|
profile, lambda service: service.version_detail(skill_id, version)
|
|
)
|
|
|
|
|
|
@router.get("/api/wisdom/skills/{skill_id}/versions/{version}/content")
|
|
async def get_wisdom_version_content(
|
|
skill_id: str, version: int, profile: Optional[str] = None
|
|
):
|
|
return await _run_wisdom(
|
|
profile, lambda service: service.version_content(skill_id, version)
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/suggest")
|
|
async def post_wisdom_suggest(body: WisdomSuggestRequest):
|
|
result = await _run_wisdom(
|
|
body.profile,
|
|
lambda service: service.suggest(
|
|
body.skill,
|
|
description=body.description,
|
|
system_specification=body.system_specification,
|
|
allow_private_secret_review=body.send_for_owner_only_server_review,
|
|
local_skill_id=body.local_skill_id,
|
|
),
|
|
)
|
|
if result.get("network_submission") is False and result.get("local_draft_id"):
|
|
_schedule_wisdom_professionalism_reviews(body.profile)
|
|
return result
|
|
|
|
|
|
@router.post("/api/wisdom/review")
|
|
async def post_wisdom_review(body: WisdomReviewRequest):
|
|
return await _run_wisdom(
|
|
body.profile,
|
|
lambda service: service.review(
|
|
body.draft_id, acknowledge=body.acknowledge, portal=False,
|
|
expected_hashes=body.expected_hashes,
|
|
),
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/publication/review")
|
|
async def post_wisdom_publication_review(body: WisdomDecisionRequest):
|
|
return await _run_wisdom(body.profile, lambda service: service.publication_review(body.draft_id))
|
|
|
|
|
|
@router.post("/api/wisdom/publication/submit")
|
|
async def post_wisdom_publication_submit(body: WisdomPublicationRequest):
|
|
if set(body.expected_hashes) != {"content", "author_description", "package_manifest"}:
|
|
raise HTTPException(status_code=422, detail="Confirmation requires all three displayed package hashes")
|
|
if body.interaction_id or body.session_id:
|
|
if not body.interaction_id or not body.session_id:
|
|
raise HTTPException(status_code=422, detail="Both interaction and session are required")
|
|
def submit(service):
|
|
from hermes_wisdom.consent import ConsentActor, WisdomConsent
|
|
actor = ConsentActor(body.session_id, "local", "local-user", f"local:{body.session_id}")
|
|
return WisdomConsent(service).submit_local_publication(
|
|
service.store.active_org_id(), body.interaction_id, actor,
|
|
draft_id=body.draft_id, expected_hashes=body.expected_hashes, publication_mode=body.publication_mode,
|
|
)
|
|
return await _run_wisdom(body.profile, submit)
|
|
return await _run_wisdom(
|
|
body.profile,
|
|
lambda service: service.submit_reviewed_package(
|
|
body.draft_id, expected_hashes=body.expected_hashes,
|
|
publication_mode=body.publication_mode,
|
|
),
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/prepared/save")
|
|
async def post_wisdom_prepared_save(body: WisdomPreparedSaveRequest):
|
|
result = await _run_wisdom(
|
|
body.profile,
|
|
lambda service: service.save_prepared(
|
|
body.draft_id,
|
|
author_description=body.author_description,
|
|
files=[item.model_dump() for item in body.files],
|
|
),
|
|
)
|
|
_schedule_wisdom_professionalism_reviews(body.profile)
|
|
return result
|
|
|
|
|
|
@router.post("/api/wisdom/candidates/dismiss")
|
|
async def post_wisdom_candidate_dismiss(body: WisdomCandidateDismissRequest):
|
|
return await _run_wisdom(
|
|
body.profile,
|
|
lambda service: service.dismiss_local_candidate(
|
|
body.local_skill_id, body.content_hash
|
|
),
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/candidates/defer")
|
|
async def post_wisdom_candidate_defer(body: WisdomCandidateEventRequest):
|
|
return await _run_wisdom(
|
|
body.profile,
|
|
lambda service: service.defer_candidate_prompt(
|
|
body.event_id, surface="desktop"
|
|
),
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/candidates/prepare")
|
|
async def post_wisdom_candidate_prepare(body: WisdomCandidateEventRequest):
|
|
result = await _run_wisdom(
|
|
body.profile, lambda service: service.prepare_candidate(body.event_id)
|
|
)
|
|
if result.get("stage") == "prepared":
|
|
_schedule_wisdom_professionalism_reviews(body.profile)
|
|
return result
|
|
|
|
|
|
@router.post("/api/wisdom/candidates/approve")
|
|
async def post_wisdom_candidate_approve(body: WisdomCandidateEventRequest):
|
|
return await _run_wisdom(
|
|
body.profile, lambda service: service.approve_candidate(body.event_id)
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/revise")
|
|
async def post_wisdom_revise(body: WisdomReviseRequest):
|
|
return await _run_wisdom(
|
|
body.profile,
|
|
lambda service: service.revise(
|
|
body.draft_id,
|
|
author_description=body.author_description,
|
|
files=[item.model_dump() for item in body.files],
|
|
expected_content_hash=body.expected_content_hash,
|
|
expected_description_hash=body.expected_author_description_hash,
|
|
expected_manifest_hash=body.expected_package_manifest_hash,
|
|
allow_private_secret_review=body.send_for_owner_only_server_review,
|
|
),
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/approve")
|
|
async def post_wisdom_approve(body: WisdomDecisionRequest):
|
|
return await _run_wisdom(
|
|
body.profile, lambda service: service.approve(body.draft_id)
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/decline")
|
|
async def post_wisdom_decline(body: WisdomDecisionRequest):
|
|
return await _run_wisdom(
|
|
body.profile, lambda service: service.decline(body.draft_id)
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/install/plan")
|
|
async def post_wisdom_install_plan(body: WisdomInstallPlanRequest):
|
|
return await _run_wisdom(
|
|
body.profile,
|
|
lambda service: service.install_plan(
|
|
body.reference, update_mode=body.update_mode
|
|
),
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/install/apply")
|
|
async def post_wisdom_install_apply(body: WisdomInstallApplyRequest):
|
|
return await _run_wisdom(
|
|
body.profile,
|
|
lambda service: service.install_apply(
|
|
body.receipt, accept_partial=body.accept_partial
|
|
),
|
|
)
|
|
|
|
|
|
@router.get("/api/wisdom/installations")
|
|
async def get_wisdom_installations(profile: Optional[str] = None):
|
|
def read(service):
|
|
from hermes_wisdom.mediation import delivery_mode
|
|
|
|
return {
|
|
"delivery_mode": delivery_mode(),
|
|
"installations": service.store.installations(),
|
|
"notifications": service.notifications(mark_seen=False)["events"],
|
|
}
|
|
|
|
return await _run_wisdom(profile, read)
|
|
|
|
|
|
@router.post("/api/wisdom/check")
|
|
async def post_wisdom_check(body: WisdomCheckRequest):
|
|
return await _run_wisdom(
|
|
body.profile,
|
|
lambda service: service.check(apply_automatic=body.apply_automatic),
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/update/plan")
|
|
async def post_wisdom_update_plan(body: WisdomUpdatePlanRequest):
|
|
return await _run_wisdom(
|
|
body.profile, lambda service: service.update_plan(body.skill_id)
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/update/apply")
|
|
async def post_wisdom_update_apply(body: WisdomUpdateApplyRequest):
|
|
return await _run_wisdom(
|
|
body.profile,
|
|
lambda service: service.update_apply(
|
|
body.receipt,
|
|
accept_sensitive=body.accept_sensitive,
|
|
accept_partial=body.accept_partial,
|
|
preserve_modified=body.preserve_modified,
|
|
),
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/uninstall")
|
|
async def post_wisdom_uninstall(body: WisdomUninstallRequest):
|
|
return await _run_wisdom(
|
|
body.profile, lambda service: service.uninstall(body.skill_id)
|
|
)
|
|
|
|
|
|
@router.post("/api/wisdom/notifications")
|
|
async def post_wisdom_notifications(body: WisdomNotificationRequest):
|
|
return await _run_wisdom(
|
|
body.profile,
|
|
lambda service: service.notifications(mark_seen=body.mark_seen),
|
|
)
|
|
|
|
|
|
@router.get("/api/wisdom/mediation")
|
|
async def get_wisdom_mediation(profile: Optional[str] = None):
|
|
from hermes_wisdom.mediation import WisdomMediation
|
|
from hermes_wisdom.mediation_view import desktop_interaction
|
|
|
|
def activity(service):
|
|
value = WisdomMediation(service).activity()
|
|
return {**value, "interactions": [desktop_interaction(item) for item in value["interactions"]]}
|
|
|
|
return await _run_wisdom(profile, activity)
|
|
|
|
|
|
@router.get("/api/wisdom/mute")
|
|
async def get_wisdom_mute(profile: Optional[str] = None):
|
|
from hermes_wisdom.preferences import WisdomPreferences
|
|
|
|
return await _run_wisdom(profile, lambda service: WisdomPreferences(service).native_mute_command())
|
|
|
|
|
|
@router.post("/api/wisdom/mute/prepare")
|
|
async def post_wisdom_mute_prepare(body: WisdomMutePrepareRequest):
|
|
def prepare(service):
|
|
from hermes_wisdom.preferences import WisdomPreferences
|
|
|
|
preferences = WisdomPreferences(service)
|
|
org = service.store.active_org_id()
|
|
control = preferences.prepare_mute_control(org)
|
|
return {**control, "organization_id": org, "sync": preferences.mute_status(org)}
|
|
|
|
return await _run_wisdom(body.profile, prepare)
|
|
|
|
|
|
@router.post("/api/wisdom/mute/choose")
|
|
async def post_wisdom_mute_choose(body: WisdomMuteChooseRequest):
|
|
def choose(service):
|
|
from hermes_wisdom.preferences import WisdomPreferences
|
|
|
|
preferences = WisdomPreferences(service)
|
|
preferences.choose_mute_control(service.store.active_org_id(), body.control_id, body.duration)
|
|
return preferences.native_mute_command()
|
|
|
|
return await _run_wisdom(body.profile, choose)
|
|
|
|
|
|
@router.post("/api/wisdom/consent")
|
|
async def post_wisdom_consent(body: WisdomConsentRequest):
|
|
def resolve(service):
|
|
from hermes_wisdom.consent import ConsentActor, WisdomConsent
|
|
from hermes_wisdom.mediation_view import desktop_interaction
|
|
|
|
actor = ConsentActor(body.session_id, "local", "local-user", f"local:{body.session_id}")
|
|
return desktop_interaction(WisdomConsent(service).resolve(
|
|
service.store.active_org_id(), body.interaction_id, actor, body.action
|
|
))
|
|
return await _run_wisdom(body.profile, resolve)
|
|
|
|
|
|
@router.post("/api/wisdom/consent/publication-review")
|
|
async def post_wisdom_consent_publication_review(body: WisdomConsentRequest):
|
|
def prepare(service):
|
|
from hermes_wisdom.consent import ConsentActor, WisdomConsent
|
|
actor = ConsentActor(body.session_id, "local", "local-user", f"local:{body.session_id}")
|
|
return WisdomConsent(service).prepare_local_publication(service.store.active_org_id(), body.interaction_id, actor)
|
|
return await _run_wisdom(body.profile, prepare)
|