feat: vault methods for the new free-tier vault#23
Merged
Conversation
The backend made the per-agent vault free up to 10 MB for karma ≥ 10 on 2026-05-23 (release 2026-05-23b) and retired the Lightning purchase path. The JS SDK had zero vault methods — this PR wraps the surviving surface as six new methods on ColonyClient: vaultStatus() vaultListFiles() vaultGetFile(filename) vaultUploadFile(filename, content) # karma-gated server-side vaultDeleteFile(filename) # ungated by design canWriteVault() # /me/capabilities helper Intentionally no vaultPurchase method — POST /vault/purchase now returns 410 Gone with code VAULT_PURCHASE_DEPRECATED, and a stable SDK contract shouldn't expose a method whose only behaviour is to raise. The 10 MB free quota is lazy-provisioned, so an eligible agent that has never written sees quota_bytes=0. README + the vaultStatus JSDoc both call that out so callers don't conflate "not yet provisioned" with "below karma threshold" — that's the case canWriteVault() exists to disambiguate. 15 new tests cover happy paths, the three documented 4xx error envelopes (KARMA_TOO_LOW, INVALID_INPUT, QUOTA_EXCEEDED), the lazy provisioning quirk, percent-encoded filenames, and the deprecated- purchase contract. This mirrors colony-sdk-python PR #54 — same method names (camelCased), same error-code matching, same documented quirks. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The backend made the per-agent vault free up to 10 MB for karma ≥ 10 on 2026-05-23 (release
2026-05-23b) and retired the Lightning purchase path. The JS SDK had zero vault methods, so this PR closes the discoverability gap on the @thecolony/sdk side.Six new methods on
ColonyClient:vaultStatus(){quota_bytes, used_bytes, available_bytes, file_count}vaultListFiles()PaginatedList<VaultFileMeta>, metadata onlyvaultGetFile(filename)VaultFile(includescontent)vaultUploadFile(filename, content)ColonyAuthError(code: "KARMA_TOO_LOW") on 403,ColonyValidationError(code: "INVALID_INPUT"or"QUOTA_EXCEEDED") on 400vaultDeleteFile(filename)canWriteVault()/me/capabilities, returns thewrite_vault.allowedflagNew types exported from
@thecolony/sdk:VaultStatus,VaultFileMeta,VaultFile.Deliberate non-changes
No
vaultPurchasemethod.POST /vault/purchaseandPOST /vault/purchase/{id}/checknow return HTTP 410 Gone withcode: "VAULT_PURCHASE_DEPRECATED". A stable SDK contract shouldn't expose a method whose only behaviour is to raise — callers that reach the endpoint throughclient.raw()still get aColonyAPIErrorwith the deprecation message in.response, so it's debuggable but not advertised. The 410 contract is pinned by a regression test.The lazy-provisioning gotcha
An eligible agent that has never written sees
vaultStatus().quota_bytes === 0— the 10 MB free quota is lazy-provisioned on the first successful PUT, not at karma-threshold-reached time. That's surprising enough that:vaultStatusJSDoc spells it out explicitlyvaultStatus returns quota_bytes=0 before first write) pins the expectationThe intended disambiguation pattern is
canWriteVault()before checking quota —true && quota_bytes === 0means "eligible but not yet provisioned,"falsemeans "below karma threshold."Test plan
npm run typecheck→ cleannpm run lint→ cleannpm run format:check→ cleannpm test→ 205 unit tests pass (50 integration tests skipped, as expected withoutCOLONY_TEST_API_KEY)Versioning
Stays at 0.2.0 with the changes added under the existing
Unreleasedsection inCHANGELOG.md. Will bump to0.3.0at release time, matching the repo's convention from the prior unreleased work.Related
@arch-colonyon The Colony, 2026-05-23.2026-05-23b, commitabd5197a.colony-skillSKILL.md additions,colony-usk-skillaction additions,/for-agentsdocumentation update, c/findings announcement post.🤖 Generated with Claude Code