Skip to content

feat(ask): handle PAI stream events (session/result/cost/done) - #29

Open
Priyanshu (priyanshu-plivo) wants to merge 3 commits into
mainfrom
feat/buddy-pai-stream-events
Open

feat(ask): handle PAI stream events (session/result/cost/done)#29
Priyanshu (priyanshu-plivo) wants to merge 3 commits into
mainfrom
feat/buddy-pai-stream-events

Conversation

@priyanshu-plivo

Copy link
Copy Markdown
Contributor

What

Prep the plivo ask Buddy client for the PAI streaming contract, backward-compatible with today's token/final events.

Contract (verified live against prod pai-voice customer endpoint)

Raw SSE — data: is the bare object (NOT the {type,data} wrapper):

  • session {session_id} · result {text} (complete answer, no deltas) · cost {total_cost_usd} · done {} · heartbeats = :-comment lines (already skipped by the SSE reader).

Changes

  • internal/api/types.go: add session_id to BuddyChatRequest.
  • cmd/buddy.go buddyRenderer: handle result (render as block), session (capture for continuation), cost (verbose/-o json only — hidden in normal output), done (terminate; also ends -o json). buddyInner already falls back to the raw payload, so unwrapped frames parse with no envelope change.
  • buddySession (-i): capture session_id and replay it on the next turn; cleared on /reset.

Testing

  • Unit: 3 new table tests + full cmd/api suites, -race clean.
  • E2E: real plivo binary vs a mock emitting the exact prod frames → JSON passthrough ✓, human-mode block render ✓, cost hidden (shown in --verbose) ✓, clean done termination ✓.

Open questions (for the PAI/aiassist owner)

  1. When Buddy's own endpoint adopts this: raw payloads (like pai-voice) or the {type,data} wrapper? (Coded for both.)
  2. Continuation request field — is it session_id?
  3. cost confirmed internal-only / never shown to customers?
  4. During transition, does customer scope emit only result (no token)?

Pairs with contacto-console PR (same contract in the web Buddy chat).

Prep the CLI Buddy client for the PAI streaming contract, alongside the
legacy token/final events (backward-compatible):
- result: complete sanitized answer (no deltas) — rendered as a block
- session: capture session_id; buddySession replays it on the next -i turn
- cost: total_cost_usd shown only in --verbose (passes through in -o json)
- done: ends the stream (also terminates -o json mode)
buddyInner already falls back to the raw payload, so unwrapped PAI frames
parse without an envelope change. Adds table tests.
The ubuntu-latest-m-plivo managed runner pool has been unavailable since
Jul 7 — smoke/lint/codeql jobs sat queued and GitHub auto-cancelled them
at the 24h timeout, blocking every PR. These jobs only run gofmt/vet/
go test/build + dry-run smoke checks on public deps (no internal network),
and pages.yml already uses ubuntu-latest in this repo, so GitHub-hosted
runners are sufficient. Revert to -m-plivo once that pool is healthy if the
team prefers it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant