Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/added-inbox-transcribe-then-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Sharing from the Inbox 🔗 Share → Hive menu is open to read-write users as well as owners (read users still only get Link), and RFC… / Knowledge on an audio-only item now transcribe it first and share when the transcript completes, with a "Transcribing, then → RFC" progress label; DIBS still sends straight away.
18 changes: 17 additions & 1 deletion dashboard/test/inbox-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function makeContext(role) {
window: { _hiveRole: role },
INBOX_SOURCE_ICONS: { plaud: '🎙️' },
INBOX_DEST_LABELS: { spek_rfc: 'RFC', dibs: 'dibs' },
INBOX_INTENT_LABELS: { spek_rfc: 'RFC', dismiss: 'Knowledge', spek: 'spek' },
INBOX_SUMMARY_COLLAPSE_CHARS: 280,
_inboxSelected: new Set(),
_inboxExpanded: new Set(),
Expand All @@ -48,7 +49,7 @@ function makeContext(role) {
Array,
};
vm.createContext(ctx);
for (const fn of ['inboxSourceIcon', 'inboxItemKey', 'inboxViewerCanPlay', 'inboxApiPath', 'inboxFmtDuration', 'inboxStatePill', 'inboxSummaryHtml', 'inboxTranscriptHtml', 'inboxTxUnavailableText', 'inboxTxEtaText', 'inboxTxElapsedText', 'inboxTxProgressHtml', 'inboxTranscriptionHtml', 'inboxItemHtml']) {
for (const fn of ['inboxCanShare', 'inboxIntentLabel', 'inboxIntentThen', 'inboxSourceIcon', 'inboxItemKey', 'inboxViewerCanPlay', 'inboxApiPath', 'inboxFmtDuration', 'inboxStatePill', 'inboxSummaryHtml', 'inboxTranscriptHtml', 'inboxTxUnavailableText', 'inboxTxEtaText', 'inboxTxElapsedText', 'inboxTxProgressHtml', 'inboxTranscriptionHtml', 'inboxItemHtml']) {
vm.runInContext(extractFunction(fn), ctx);
}
return ctx;
Expand Down Expand Up @@ -140,3 +141,18 @@ test('File RFC route state: a failed hand-off shows its error inline, delegated
assert.match(html, /muted-xs">handed to agent builder to draft with spek and publish to o\/r</);
assert.doesNotMatch(html, /role="alert"/);
});

test('transcribe-then-share: the progress bar names the share, a failed intent shows its reason', () => {
const ctx = makeContext('read-write');
const running = Object.assign({}, pendingItem, {
transcription: { status: 'running', phase: 'transcribing', progress: 0.4, started_at: '2026-11-16T10:00:00Z', eta_seconds: 240 },
share_intents: { spek_rfc: { status: 'waiting', actor: 'rw@example.com' } },
});
let html = vm.runInContext('inboxItemHtml(' + JSON.stringify(running) + ')', ctx);
assert.match(html, /Transcribing, then → RFC · 40%/);
const failed = Object.assign({}, pendingItem, { share_intents: { dismiss: { status: 'failed', error: 'transcription failed: provider down' } } });
html = vm.runInContext('inboxItemHtml(' + JSON.stringify(failed) + ')', ctx);
assert.match(html, /data-status="error"[^>]*>→ Knowledge failed</);
assert.match(html, /role="alert">transcription failed: provider down</);
assert.match(html, /inbox-check/, 'read-write can select items for the bulk Hive menu');
});
4 changes: 4 additions & 0 deletions src/docs/inbox-transcription.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,7 @@ speed for the estimate.
| `GET` | `/api/inbox/{source}/{id}/content` | Dashboard auth | Falls back to the machine transcript, with `transcript_label` |

See also [api-reference/knowledge.md](api-reference/knowledge.md).

## Transcribe first, then share

Choosing RFC… or Knowledge from 🔗 Share → Hive on an item that has audio but no text starts a transcription for it (the Transcribe path above, with the same consent, budget and daily caps) and keeps the choice as a pending share. The share runs when the transcript completes; the item's progress bar reads "Transcribing, then → RFC". The pending share holds only the dialog choices (destination, who chose it, repository), never item text, and is stored with the item state, so a restart resumes it. If the transcription fails or is skipped, nothing is sent and the item shows the reason with a Retry in the Share menu.
29 changes: 22 additions & 7 deletions src/docs/inbox-voice-sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,31 @@ Each Inbox item shows what the source has for the recording:
whether a sync also writes a link into the fact.
- **🔗 Share ▾** — the only per-item menu besides ▶ Play and Transcript
(arrow keys move, Esc closes and returns focus). It has two labelled groups.
**Hive** (owners only): **RFC…** (**Retry RFC…** after a failure), **Knowledge**
(**Back to inbox** on a kept item) and **DIBS**. RFC… is disabled with a
hint when the item has no text yet (use 🎧 Transcribe) or no RFC repository is
set; DIBS is disabled until `inbox.dibs.url` (Settings → Inbox → dibs URL)
and the token variable named by `inbox.dibs.token_env` are set. Other
features add their own entry to this group. **Link** (everyone who can see
**Hive** (owners and read-write users; read users see only Link):
**RFC…** (**Retry RFC…** after a failure), **Knowledge** (**Back to inbox**
on a kept item) and **DIBS**. An item that has audio but no text yet is
**transcribed first** (the same path as 🎧 Transcribe, with its consent,
budget and caps): RFC… and Knowledge queue the share with the dialog
choices, the progress bar reads "Transcribing, then → RFC", and the share
runs when the transcript completes; the choice survives a restart. If
transcription fails, nothing is sent: the item shows "→ RFC failed" with the
reason and the menu offers Retry. If transcription is unavailable
(disabled, no consent, budget used, no provider) these entries are disabled
with the reason and, for owners, a **⚙ Transcription settings…** entry.
Items that already have text share immediately. RFC… is also disabled when
no RFC repository is set. **DIBS** always sends straight away, audio-only
items included; it is disabled until `inbox.dibs.url` (Settings → Inbox →
dibs URL) and the token variable named by `inbox.dibs.token_env` are set.
Every share is audited with the acting user; the settings (auto-routing,
dibs URL and token, RFC repository) stay owner-only. Other
features add their own entry to this group (`inboxShareHiveActions`; a
destination that needs the transcript-first path registers with
`Service.RegisterIntentRunner`). **Link** (everyone who can see
the Inbox): **Copy link** copies a deep link to the item
(`<dashboard URL>#section-inbox-section?item=<source>%2F<id>`); **Share…**
opens the browser's share sheet and appears only where the browser has one.
The selection bar has the same kind of **Hive ▾** menu for bulk Knowledge.
The selection bar has a **Hive ▾** menu for bulk Knowledge, which waits for
transcripts the same way.
Sharing never shares
the media URL: the recipient signs in to this hive and needs owner or
read-write access to play. Opening the link opens the Inbox, shows
Expand Down
76 changes: 66 additions & 10 deletions src/pkg/dashboard/api_inbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func (s *Server) handleInboxContent(w http.ResponseWriter, r *http.Request) {

// requireInboxPlaybackRole admits owners (verified) and read-write sessions:
// playing a recording is a read of private audio, not an operator mutation.
//
// Sharing an item (route, Knowledge-only) takes the same owner or read-write
// admission (requireInboxShareRole); settings stay owner-only.
func requireInboxPlaybackRole(w http.ResponseWriter, r *http.Request) bool {
role := r.Header.Get("X-Hive-Role")
if isOwnerRole(role) && r.Header.Get(ownerRoleVerifiedHeader) != "true" {
Expand Down Expand Up @@ -404,6 +407,14 @@ type inboxRouteRequest struct {
ItemID string `json:"item_id"`
Destination string `json:"destination"`
Repo string `json:"repo,omitempty"`
// Params are short dialog choices kept with a transcribe-first share.
Params map[string]string `json:"params,omitempty"`
}

// requireInboxShareRole admits owners (verified) and read-write sessions to
// share an inbox item; read is denied. Every share is audited with the user.
func requireInboxShareRole(w http.ResponseWriter, r *http.Request) bool {
return requireInboxPlaybackRole(w, r)
}

// InboxRouteResponse is POST /api/inbox/route.
Expand All @@ -412,12 +423,15 @@ type InboxRouteResponse struct {
ItemID string `json:"item_id"`
Destination string `json:"destination"`
State inbox.RouteState `json:"state"`
// WaitingTranscript is true when the item has audio but no text: the hive
// transcribes it first and shares when the transcript completes.
WaitingTranscript bool `json:"waiting_transcript,omitempty"`
}

// handleInboxRoute (owner) queues one item for one destination; progress is
// handleInboxRoute (owner or read-write) queues one item for one destination; progress is
// read back from GET /api/inbox.
func (s *Server) handleInboxRoute(w http.ResponseWriter, r *http.Request) {
if !requireOwnerRole(w, r) {
if !requireInboxShareRole(w, r) {
return
}
svc, ok := s.inboxService(w)
Expand Down Expand Up @@ -449,20 +463,43 @@ func (s *Server) handleInboxRoute(w http.ResponseWriter, r *http.Request) {
jsonError(w, msg, http.StatusNotFound)
return
}
st, err := svc.Route(ctx, it, inbox.Request{Destination: req.Destination, Repo: req.Repo})
actor := requestUser(r)
var st inbox.RouteState
waiting := false
if req.Destination == inbox.DestDibs {
// DIBS sends straight away, audio-only items included.
st, err = svc.Route(ctx, it, inbox.Request{Destination: req.Destination, Repo: req.Repo})
} else {
var out inbox.ShareOutcome
out, err = svc.ShareWhenReady(ctx, it, inbox.ShareIntent{Destination: req.Destination, Actor: actor, Repo: req.Repo, Params: req.Params}, s.inboxTranscribeOptions(actor))
st, waiting = out.State, out.Waiting
}
switch {
case errors.Is(err, inbox.ErrRouteBusy):
jsonError(w, "that route is already queued or running", http.StatusConflict)
return
case errors.Is(err, inbox.ErrUnknownDestination):
jsonError(w, err.Error(), http.StatusBadRequest)
return
case errors.Is(err, inbox.ErrTranscribeUnavailable):
jsonError(w, "this item has audio but no text yet, and "+err.Error(), http.StatusPreconditionFailed)
return
case err != nil:
jsonError(w, "route failed: "+err.Error(), http.StatusInternalServerError)
return
}
s.auditFromRequest(r, "inbox_route", auditDetail("source", req.Source, "item", req.ItemID, "destination", req.Destination, "repo", req.Repo), "")
jsonStatusResponse(w, http.StatusAccepted, InboxRouteResponse{Source: req.Source, ItemID: req.ItemID, Destination: req.Destination, State: st})
s.auditFromRequest(r, "inbox_route", auditDetail("source", req.Source, "item", req.ItemID, "destination", req.Destination, "repo", req.Repo, "actor", actor, "transcribe_first", strconv.FormatBool(waiting)), "")
jsonStatusResponse(w, http.StatusAccepted, InboxRouteResponse{Source: req.Source, ItemID: req.ItemID, Destination: req.Destination, State: st, WaitingTranscript: waiting})
}

// inboxTranscribeOptions builds the audited options for a transcription the
// request caused.
func (s *Server) inboxTranscribeOptions(actor string) inbox.TranscribeOptions {
return inbox.TranscribeOptions{Actor: actor, Audit: func(a inbox.TranscribeAudit) {
if s.audit != nil {
s.audit.Log(a.Actor, "inbox_transcribe", auditDetail(a.Fields()...), "")
}
}}
}

func inboxRepoOK(repo string) bool {
Expand All @@ -481,11 +518,15 @@ type inboxDismissRequest struct {
// InboxDismissResponse is POST /api/inbox/dismiss.
type InboxDismissResponse struct {
Dismissed int `json:"dismissed"`
// WaitingTranscript counts items that will be kept once transcribed.
WaitingTranscript int `json:"waiting_transcript,omitempty"`
}

// handleInboxDismiss (owner) marks items "knowledge only" (bulk).
// handleInboxDismiss (owner or read-write) marks items "knowledge only"
// (bulk). Audio-only items are transcribed first when transcription is
// available (the dismissal runs when the transcript completes).
func (s *Server) handleInboxDismiss(w http.ResponseWriter, r *http.Request) {
if !requireOwnerRole(w, r) {
if !requireInboxShareRole(w, r) {
return
}
svc, ok := s.inboxService(w)
Expand All @@ -497,19 +538,34 @@ func (s *Server) handleInboxDismiss(w http.ResponseWriter, r *http.Request) {
jsonError(w, "items[] is required", http.StatusBadRequest)
return
}
n := 0
n, waiting := 0, 0
actor := requestUser(r)
for _, it := range req.Items {
if it.Source == "" || it.ItemID == "" {
continue
}
if !req.Undo {
if item, found, _ := svc.Find(r.Context(), it.Source, it.ItemID); found {
if out, err := svc.ShareWhenReady(r.Context(), item, inbox.ShareIntent{Destination: inbox.DestDismiss, Actor: actor}, s.inboxTranscribeOptions(actor)); err == nil {
if out.Waiting {
waiting++
}
n++
continue
} else if !errors.Is(err, inbox.ErrTranscribeUnavailable) {
jsonError(w, "dismiss failed: "+err.Error(), http.StatusInternalServerError)
return
}
}
}
if err := svc.Dismiss(it.Source, it.ItemID, !req.Undo); err != nil {
jsonError(w, "dismiss failed: "+err.Error(), http.StatusInternalServerError)
return
}
n++
}
s.auditFromRequest(r, "inbox_dismiss", auditDetail("count", strconv.Itoa(n)), "")
jsonResponse(w, InboxDismissResponse{Dismissed: n})
s.auditFromRequest(r, "inbox_dismiss", auditDetail("count", strconv.Itoa(n), "actor", actor, "waiting_transcript", strconv.Itoa(waiting)), "")
jsonResponse(w, InboxDismissResponse{Dismissed: n, WaitingTranscript: waiting})
}

func (s *Server) handleInboxSettingsGet(w http.ResponseWriter, r *http.Request) {
Expand Down
57 changes: 57 additions & 0 deletions src/pkg/dashboard/api_inbox_share_role_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package dashboard

import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"

"github.com/hivecommons/hive/pkg/config"
)

func doShareRolePost(s *Server, path, role string, body any) *httptest.ResponseRecorder {
var b bytes.Buffer
_ = json.NewEncoder(&b).Encode(body)
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodPost, path, &b)
req.Header.Set("Content-Type", "application/json")
if role != "" {
req.Header.Set("X-Hive-Role", role)
}
if role == "owner" {
req.Header.Set(ownerRoleVerifiedHeader, "true")
}
s.mux.ServeHTTP(rec, req)
return rec
}

// Sharing an item (route, Knowledge-only) is open to owner and read-write;
// read and anonymous callers get 403. Settings stay owner-only.
func TestInboxShareRoleMatrix(t *testing.T) {
s, deps := apiServer(t)
spek := &inboxTestDest{name: "spek_rfc"}
deps.Config.Inbox = config.InboxConfig{Spek: config.InboxSpek{Repo: "myorg/rfcs"}}
deps.Inbox = newInboxTestService(t, deps.Config.Inbox, spek)
route := map[string]string{"source": "plaud", "item_id": "rec-1", "destination": "spek_rfc"}
for _, role := range []string{"", "read-only", "read"} {
if rec := doShareRolePost(s, "/api/inbox/route", role, route); rec.Code != http.StatusForbidden {
t.Fatalf("role %q route = %d, want 403", role, rec.Code)
}
if rec := doShareRolePost(s, "/api/inbox/dismiss", role, map[string]any{"items": []map[string]string{{"source": "plaud", "item_id": "rec-1"}}}); rec.Code != http.StatusForbidden {
t.Fatalf("role %q dismiss = %d, want 403", role, rec.Code)
}
}
if rec := doShareRolePost(s, "/api/inbox/route", "read-write", route); rec.Code != http.StatusAccepted {
t.Fatalf("read-write route = %d: %s", rec.Code, rec.Body.String())
}
if rec := doShareRolePost(s, "/api/inbox/dismiss", "read-write", map[string]any{"items": []map[string]string{{"source": "plaud", "item_id": "rec-1"}}}); rec.Code != http.StatusOK {
t.Fatalf("read-write dismiss = %d: %s", rec.Code, rec.Body.String())
}
if rec := doShareRolePost(s, "/api/inbox/route", "owner", route); rec.Code != http.StatusAccepted {
t.Fatalf("owner route = %d: %s", rec.Code, rec.Body.String())
}
if rec := doShareRolePost(s, "/api/inbox/settings", "read-write", map[string]any{"spek_repo": "o/r"}); rec.Code != http.StatusForbidden {
t.Fatalf("read-write settings = %d, want 403 (settings stay owner-only)", rec.Code)
}
}
Loading
Loading