← Back to Pull requests

feat!: move the SDK and CLI to the /api/v2 platform API (Toolkit 1.0.0) #215

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 19, 2026 22:36 UTC
Author

Summary


  • Toolkit 1.0.0 (M20 of the agent API permissions and /api/v2 platform API program): the SDK and CLI move from /api/v1 REST and GraphQL to the gateway's /api/v2 platform API, one resource at a time, in a major release whose main breaking change is the ID format (human decision).

  • New transport client._v2Request / client._v2Pages beside _request, sharing its headers, credential, timeout and network-error path: camelCase JSON, {items, nextPageToken} pages, repeated query parameters for lists, JSON Merge Patch on PATCH, and an Idempotency-Key on every write (the caller's request ID when a method takes one, else a new UUID per call).

  • Errors: RFC 9457 problems become AlvaError with code, status, message, and, when present, requiredPermission, invalidParams and retryAfter; the CLI prints them with the error. The v1 envelope is still read on /api/v2, because the gateway's authentication middleware writes it there.

  • IDs are opaque platform strings (AlvaId, task_0...). Public method signatures, CLI commands and output otherwise keep their shape (R16). Theses also return number, author_version_number and publication.thesisNumber, so agents can still link alva.ai/thesis/<number> and the App's Thesis cards.

  • Moved: Theses, Thesis reads, For You, Playbooks, release, feeds, comments, remix, Skillhub, SDK docs; watchlist, people and Playbook follows, alerts; cronjobs, automations, agent schedules; files and screenshots; user, notification preferences, secrets, service accounts, feedback; markets, trading pairs, company news, X; wallet and credit entries; Playbook functions and allowances; runs and the data-skills token; portfolios, copy trading and the broker CLI.

  • Still on /api/v1 (no /api/v2 route yet, 0.x transport and IDs): steward (GraphQL), trading.execute and subscribe({executeLatest: true}), notifications.listFeed, subscriptions.subscribeFeed/unsubscribeFeed, secrets.get, channelGroupSubscriptions, and fs plus Playbook/Skillhub discovery for clients without an API key (browser Playbooks with a PBSV or viewer token), the browser UDF runtime and auth login.
  • Architecture and Key Decisions


  • Design record: alva-gateway docs/changelogs/2026-11-19-agent-api-permissions.md (D10 conventions, D16 IDs, R16, 4.2 and 4.6 M20) and doc/api-v2-conventions.md. Local changelogs: docs/changelogs/2026-11-19-agent-api-v2.md (transport and integration) and the three slices 2026-11-19-content-resources-v2.md, 2026-11-19-agent-api-v2-social-automation-files-account.md, 2026-11-19-agent-api-v2-market-trading-runtime.md.

  • One transport method beside _request; _request is split into _headers, _send and decodeResponse without a behavior change, so both doors keep one credential and error path.

  • No new automatic retries. The Idempotency-Key makes the retries that exist safe; retryAfter is exposed for the one retrying caller (steward) when it moves.

  • New AlvaError members are declared fields assigned only when present, so other errors and the CLI output of v1 errors keep their shape.

  • One caller-username read (client.user._username(), cached per client) for release, own-Playbook lookups and copy trading.

  • One API-key door (AlvaClient._sendsApiKey()): a client without an API key, or one whose requests carry a PBSV or viewer token, keeps /api/v1 for fs and discovery, because /api/v2 accepts only API keys and sends no CORS headers.

  • package.json stays 0.36.0: scripts/release.sh major bumps it to 1.0.0 at release (a pre-bumped version would release as 2.0.0). CHANGELOG.md is new and holds the complete 1.0.0 notes; the README has a "Migrating from 0.x to 1.0" section.
  • Risks and Remaining Work


  • The release (npm, then the Toolkit submodule and Dispatch pin in sdk-monorepo) follows the gateway deploy (record 4.6 step 7) and is not part of this PR.

  • The skills references (trading and broker flags, numeric-ID examples, Thesis links by thesisNumber) ship with this version in the skills agent-api-v2 PR.

  • The App still writes numeric <reply_to> Thesis and version IDs, which thesis version get sends to /api/v2 and the gateway refuses; the quote then stays an ordinary quote. Fix in the App (write platform IDs) or the gateway (a version lookup by number).

  • The Thesis preview card's ticker entity-id is a platform Asset ID; the App's share sheet reads it as an entity ID (frontend follow-up).

  • Agents see an ID mix while some calls stay on /api/v1: trading.execute, subscribe({executeLatest}), broker --account and the embedded trading accounts use trex numeric IDs; alert group uses numeric feed IDs.

  • The caller username is cached for a client's life; a rename during a long-lived client keeps the old name.
  • Breaking Changes


    Major version (1.0.0). Details in CHANGELOG.md and the README migration section:
  • IDs are opaque platform strings; numeric IDs are no longer returned or accepted (except the calls still on /api/v1).

  • /api/v2 problem codes replace v1 and GraphQL codes (for example a failed precondition is CONFLICT 409, a malformed response INVALID_RESPONSE 502); details is undefined for problems.

  • Every /api/v2 route requires one credential permission and refuses with INSUFFICIENT_PERMISSION; calls that need the caller's username read GET /api/v2/me (social:read); every broker command needs trading:write.

  • Removed CLI flags: for-you list --newer-than, trading orders --source (use --origin), functions register --clear-run-as, and service-account revoke --path --permission (use --grant-id). --run-as-service-account refuses empty values and 0.

  • Installed 0.x CLIs and SDKs keep working against /api/v1.
  • Database Migrations


    None

    Verification


  • npm run lint, npm run format:check, npm run typecheck, npm test (75 files, 1,499 tests) and npm run build pass on the PR head (2026-11-19); git status is clean after the build. The tracked pre-push hook is not installed in the shared hooks directory, so the same five checks were run by hand.

  • Transport: test/platformApi.test.ts covers query encoding, v2Path, headers, Merge Patch with null, 204, idempotency keys, problem parsing, CLI error JSON and pagination. Mutations of each rule (repeated query parameters, Merge Patch, the caller's key, requiredPermission, retryAfter precedence, invalidParams, page parameters, the repeated-token guard, ./.. segments, declared fields) each failed a test and were restored.

  • Contract check: every /api/v2 request the suite sends (620 calls on 145 routes; every _v2Request call site in src/ ran at least once) was matched against the gateway's route snapshot pkg/v2/api/testdata/v2_snapshot.golden at alva-gateway b34005a9: method and path, every query parameter and body field with its type and enum value, and every ID's prefix. Fake responses were checked against the routes' response fields the same way. The only mismatches were the synthetic routes of the transport test.

  • Integration mutations (caller read once per client, the API-key door ignoring a PBSV token, functions register --run-as-service-account 0) and the Thesis number fields (version number source, Thesis number, summary number, number validation) each failed a test and were restored.

  • E2E: pending; runs once on the nightly VM after all PRs exist (human decision).

  • Not run: an STG smoke against a gateway serving /api/v2.
  • Merge Order


    1. alva-backend https://github.com/alva-ai/alva-backend/pull/3835 (platform permissions in pkg/authctx).
    2. alva-gateway P1 (branch agent-api-permissions), then alva-gateway P2 (branch agent-api-v2, the /api/v2 routes), merged and deployed to STG and PRD.
    3. This PR. Every release cut from main after this merge is 1.0.0, so merge it only when the /api/v2 routes are live in the environments the release targets.
    4. Release 1.0.0 with scripts/release.sh major, then the Toolkit submodule and Dispatch pin in sdk-monorepo (main publishes STG, the release tag PRD), together with the skills agent-api-v2 PR.

    Related PRs


  • alva-backend: https://github.com/alva-ai/alva-backend/pull/3835

  • alva-gateway P1 and P2, trex, jagent, jagent-deno, sandbox-agent-ts, the alva-backend steward scripts and skills: opened in the same program (branches agent-api-permissions and agent-api-v2).
  • Changelog: docs/changelogs/2026-11-19-agent-api-v2.md

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: chatgpt-codex-connector[bot] Review duration: 4m
    All Vouch review confidence checks passed
    Residual risk 0.42 = Change Risk (0.52) × (1 − Review Confidence (0.20)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 28% · Reviewer familiarity: 35%
    20%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #215"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 20.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 20.1% · Lower = rushed or shallow review
    20.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 41.5% · Moderate risk
    41.5%