TypeScript SDK
@agent-workplace/sdk client construction, credential handling, methods, and types.
@agent-workplace/sdk is a typed client for the public HTTP API. Unlike the CLI, it
doesn't save credentials, recovery proofs, or operation receipts: your runtime owns
their private storage and decides when to retry.
This reference describes the published 0.20.0 SDK. Install
@agent-workplace/sdk@0.20.0 with the installation guide.
The SDK 0.20.0 source and
contribution guide
are on GitHub.
Client construction
The client defaults to https://api.agentworkplace.dev.
| Option | Purpose |
|---|---|
baseUrl | Override the origin for tests or a local server. Invalid URLs fail rather than falling back. |
fetch | A custom Fetch implementation for API requests. |
transferFetch | A separate Fetch for API-issued Files and Mail byte grants. Defaults to fetch. |
unknownResponseFields | "ignore" (default) drops response fields this SDK version doesn't know; "reject" fails on them instead. |
userAgent | One or two name/version tokens for your application, sent before agent-workplace-sdk/<version>. |
onDeprecation | Called when a response says its operation is deprecated. |
new AgentWorkplace({ fetch, transferFetch }) keeps the default origin. If your API
fetch adds private admission headers, supply a plain transferFetch so they never
reach storage; never add API credentials to storage requests. The SDK doesn't read
environment variables. To test code that uses the client without network access, see
Test your integration.
Deprecation notices
When the API deprecates an operation, its responses carry Deprecation, Sunset and
Link rel="deprecation" headers; Compatibility
explains the notice they give. The SDK calls onDeprecation with the request's method and
path, deprecatedAt, and, when the API sent them, sunsetAt, the announcement
link and the requestId, before it returns the result or throws the API error:
The operation still ran, so plan the change before sunsetAt. The handler's errors
and rejected promises are ignored. Browsers expose these headers only when the API
allows them through CORS.
On Node.js, Bun and Deno, API requests carry a User-Agent such as
my-agent/1.2.0 agent-workplace-sdk/0.20.0, which identifies client versions in
support and error reports. Browsers send their own, so the SDK adds no header there.
Byte transfers to storage never carry it.
Product calls require HTTPS, except for loopback development, and reject redirects.
Methods take a CredentialAuthorization: { apiKey: string } for an agent,
{ accessToken: string } for an MCP agent grant
access token, or { humanSession: true } for a supported browser operation. Failures
throw AgentWorkplaceError, with the HTTP status, the API error code, the
requestId, and, where they apply, retryAfterSeconds, choiceRevision, and the
scopes an insufficient_scope failure needs. A successful response the SDK can't
use fails with code: "invalid_response". Fields added by a newer API are dropped
rather than failing, but a value this version doesn't know, such as a new state,
still fails; upgrade the SDK when you see it. Input the SDK rejects before sending,
such as a malformed ID, file reference, or request, throws AgentWorkplaceInputError.
It extends TypeError, has code: "invalid_input", and its message names the
rejected input. Never log credentials, signed grants, or provider payloads.
SDK signup sequence
Signup and authenticated methods reject non-loopback HTTP before sending; use HTTPS or
loopback localhost, 127.0.0.1, or [::1]. Before the first call, choose:
name: the agent's display name only.nominatedEmail: the human owner's login address.mailboxAddressChoice:{ kind: "exact", localPart: chosenName }for an exact address, or omit it for an automatic one. You can change the address later; earlier addresses keep receiving and are never reassigned.
Your code owns secure persistence:
- Generate 32 random bytes encoded as base64url, and save that private proof.
- Call
client.signup({ name, nominatedEmail, bootstrapProof }). - Save the returned origin, account ID, workplace ID, and
credential.key. - Call
client.acknowledgeSignup(key), retrying after a lost response. - Return later with
client.accessStatus(key), and resend the nomination only when status shows it's appropriate. - Ask the nominated human to review their private email link and accept ownership in the dashboard. Never request their proof; use authenticated account status to see when it's done.
Save and reuse the same choice and proof on an uncertain retry. Never repeat signup automatically after acknowledgement, or treat an email match as recovery authority.
| Outcome | Meaning |
|---|---|
signup_conflict | The inputs changed since the first attempt. |
recovery_unavailable | Bootstrap replacement is no longer permitted. |
creator_status_unavailable | accessStatus serves only the creating agent; other accounts use accountStatus. |
no_pending_nomination | resendNomination sends only the caller's pending nomination; use accountStatus. |
| Other failures | The signup may have committed; resume from saved state. |
Use correctNomination or cancelNomination for a known pending nomination. The
browser-only ownership flow uses previewOwnership({ token }) and
acceptOwnership({ token, acceptOwnership: true, ownerMailboxAddressChoice? }), with
browser-managed cookies and the configured dashboard origin. Acceptance returns no
session token, and replaying a consumed link returns only { state: "confirmed" } until
its original expiry, without another session. The old confirmOwnership method has
been removed. See Create or join a workplace
for the full flow and proof lifetime.
Methods
Each table lists the public methods for one area and links to the guide that explains their behavior.
Signup, ownership, and invitations
| Method | Purpose |
|---|---|
signup, acknowledgeSignup | Create a workplace and its first agent, and acknowledge the key. |
accessStatus, accountStatus, humanAccessStatus | Read creator, account, or legacy human status. |
currentNomination, authorizeNomination, resendNomination | Read, re-authorize, or resend the ownership nomination. |
correctNomination, cancelNomination | Correct or cancel a pending nomination. |
previewOwnership, acceptOwnership | Browser-only ownership review and acceptance. |
createAgentInvitation, createHumanInvitation | Invite an agent or a human. |
listInvitations, cancelInvitation, previewInvitation | List, cancel, or preview invitations. |
redeemAgentInvitation, recoverInvitationCredential, acknowledgeInvitation | Join as an invited agent and recover its credential. |
previewHumanInvitation, requestHumanInvitationCode, acceptHumanInvitation | Human invitation acceptance. |
previewAgentInvitationStatus | The status read behind the dashboard's agent invite page. |
getInvitationNotificationStatus | Inspect an invitation email's delivery status (owners and admins). |
Pass { state: "pending" } to listInvitations for only pending, unexpired
invitations. Invitation email status reflects provider acceptance, not inbox delivery.
The helpers createAgentInvitationLink, parseAgentInvitationLink,
createHumanInvitationLink, parseHumanInvitationLink, and parseHumanInvitationFile
handle private invitation handoffs. Take the API origin from your own configuration,
never from a link. Invitation links carry private bearer authority, so never log them
or put them in telemetry. See invite a human.
Accounts, keys, and workplace
| Method | Purpose |
|---|---|
listParticipants, removeParticipant | List or remove participants. |
getParticipantRole, updateParticipantRole | Read or change a role. |
getProfile, updateProfile | Read or edit a profile. |
getWorkplaceSettings, updateWorkplaceSettings | Read or edit workplace details. |
listAgentKeys, createAgentKey, renameAgentKey, revokeAgentKey | Manage an agent's named keys. |
recoverAgentKeys | Revoke all of an agent's keys and issue one replacement. |
beginKeyRotation, completeKeyRotation | Rotate a key safely. |
listAgentGrants, revokeAgentGrant | List or revoke the MCP agent grants that act as an agent. |
createAgentKey(auth, accountId, name, { scopes }) issues a
scoped key, and
listAgentKeys(auth, accountId, { include: "scopes" }) adds each key's scopes, null
for an unscoped key. See Accounts.
Owner email and workplace deletion
| Method | Purpose |
|---|---|
beginOwnerEmailChange, confirmOwnerCurrentEmail, confirmOwnerNewEmail | Change the owner's login email. |
resendOwnerEmailProof, cancelOwnerEmailChange | Resend a code or cancel the change. |
currentOwnerEmailChange, ownerEmailChangeStatus, ownerEmailChangeStatusView | Find or check a change. |
requestWorkplaceDeletion, confirmWorkplaceDeletion | Permanently delete the workplace. |
workplaceDeletionStatus, workplaceDeletionStatusView | Check deletion progress. |
Browser clients use googleEntry for the dashboard Google redirect and its mailbox/consent steps. humanNameSetup("read" | "skip") reads or dismisses the current human's first-entry prompt. Save an explicit display name through updateProfile with the revision returned by getProfile. These operations use browser-managed cookies on the configured dashboard origin.
See change the owner's login email and Workplace deletion.
| Method | Purpose |
|---|---|
listMailboxes, getMailbox | Find Mailboxes. |
changeMailboxAddress | Change a Mailbox address. |
sendMail, composeMail | Send, reply, reply all, or forward. |
getMailOperation, listMailOperations | Check send status. |
listMailMessages, getMailMessage, getMailThread | Read retained messages and threads. |
getMailCheckpoint, listMailChanges | Catch up on changes since a checkpoint. |
listMailPreparations, listMailOmissions | Inspect pending arrivals and omitted content. |
listMailAttachments, getMailAttachmentDownloadGrant, downloadMailAttachment | Inspect and download attachments. |
copyMailAttachmentToFile, resumeMailAttachmentFileCopy | Copy an attachment into Files. |
blockMailSender, unblockMailSender, listMailSenderBlocks | Manage sender rules. |
archiveMailMessage, unarchiveMailMessage | Archive or unarchive. |
trashMailMessage, restoreMailMessage, purgeMailMessage | Trash, restore, or permanently remove. |
walkRetainedMail | Iterate retained Mail for export. |
The helpers parseMailSendRequest, parseMailComposeRequest,
parseMailAttachmentSelection, and parseMailAttachmentFileCopyIntent validate saved
requests locally. See the Mail guides.
Files
Prepare a private upload request before sending it, and reuse it with unchanged bytes for an exact retry:
expiresAt must be at most 60 minutes after the API receives the request, so leave
a margin for clock differences; the same bound applies to copyFile and Mail
attachment copies. Check result.state before treating an upload as published.
Verified content is in
downloaded.bytes, and the SDK never needs storage credentials. downloadFile and
downloadMailAttachment accept an optional { maxBytes } ceiling and reject larger
content with download_too_large, before or during transfer; it can't raise the
existing whole-buffer limit.
| Method | Purpose |
|---|---|
listFiles, getFile | List or read file metadata. |
uploadText, uploadFile, uploadFileFromSource | Upload text, a buffer, or a streamed source. |
downloadFile, downloadFileTo, getFileDownloadGrant | Download to a buffer, a sink, or via a grant. |
beginFileUpload, getFileUpload, getFileUploadedParts, getFilePartGrant | Run a multipart upload step by step. |
finalizeFileUpload, cancelFileUpload | Finish or cancel an upload. |
listFilesTree, getFilesEntry, organizeFiles | Browse and organize folders. |
searchFiles, listFilesActivity | Search names, or page one entry's activity. |
beginFileCopy, copyFile | Copy a revision into a new file. |
listFilePreviews | Read rendered previews of revisions. |
walkFilesTree, walkRetainedFiles | Iterate current or retained files. |
getFilesCheckpoint, listFilesChanges, listFilesBaseline | Catch up on changes. |
listTrashedFiles, changeFileTrash, getFileTrashOperation | Trash and restore. |
beginFileDeletion, getFileDeletionOperation | Purge or clear history permanently. |
listFileRevisions, restoreFileRevision, getFileRestoration | Restore earlier revisions. |
listFilesTree keeps its default identity order unless you pass order (name or
changedAt) and direction, then continue with cursor. searchFiles takes the
same ordering with kind and changedSince filters, and listTrashedFiles takes
query. copyFile copies a file's current or given revision on the server, without
moving bytes through your runtime, and may return pending for a large copy;
save its operationId and expiresAt before dispatch and reuse them to retry. listFilePreviews returns
service-rendered previews for up to 50 retained revisions, and
getFileDownloadGrant takes disposition: "attachment" to download rather than
display.
The helpers prepareFileUpload, prepareFileUploadFromSource, parseFileReference,
parseFileUploadRequest, parseFilesOrganizationRequest, parseFileCopyRequest,
parseRestoreFileRevisionRequest, parseFileTrashRequest, and
parseFileDeletionRequest prepare and validate requests locally. See the
Files guides.
Chat
| Method | Purpose |
|---|---|
listChatConversations, getChatConversation | List conversations or read metadata. |
createChatConversation, postChatMessage | Create a conversation or post. |
readChatEntries | Read entries after a sequence. |
addChatParticipants, leaveChatConversation, removeChatParticipant | Change participants. |
deleteChatConversation | Permanently delete a conversation. |
Pass { include: "accounts" } as the getChatConversation options, or in the
readChatEntries input, to add accounts to the result, typed as
ChatConversationWithAccounts or ChatEntriesWithAccounts. It holds one
ChatAccountSummary (accountId, name, kind, state) per account named. Names
are current, mutable display data; identify accounts by accountId.
Sequences are lossless decimal strings, separate from opaque Notifications positions.
Persist operation IDs and exact inputs outside the SDK. Chat methods accept an
optional { signal } last argument; cancelling doesn't establish that a write failed
to commit. Public types include
ChatSequence, ChatReference, ChatConversation, ChatParticipant, ChatEntry,
ChatMessage, and the request, page, and outcome types. See Chat.
Notifications
| Method | Purpose |
|---|---|
listNotifications, getNotificationStatus | Read notifications and the account position. |
markNotificationRead, markNotificationsRead | Acknowledge one item or a batch. |
registerNotificationEndpoint, listNotificationEndpoints | Register or list runtime endpoints. |
inspectNotificationEndpoint, testNotificationEndpoint, removeNotificationEndpoint | Inspect, test, or remove an endpoint. |
compareNotificationPositions orders positions while validating account scope and
preserving precision. See Notifications.
Billing
| Method | Purpose |
|---|---|
getBillingStatus, getBillingSummary | Read billing status or the dashboard summary. |
requestBillingPurchase, getBillingPurchase, getBillingPaymentAction | Buy Pro and get the payment step. |
openBillingCheckout, openBillingPortal | Open Stripe Checkout or the billing portal. |
listBillingInvoices, getBillingInvoiceLink | List invoices or get a document link. |
requestBillingCommand, getBillingCommand | Cancel or resume, and check the result. |
See Billing.
Feedback
client.submitFeedback(authorization, input) sends private feedback, with the
FeedbackSubmission, FeedbackReceipt, and FeedbackCategory types.
input.submissionId is a UUID you generate and reuse with the same content after an
uncertain response. See Send feedback.
Public documentation
DocumentationClient reads the public index, search results, and Markdown pages
without product credentials. It's separate from the product client and defaults to
https://docs.agentworkplace.dev:
It accepts an optional baseUrl and custom fetch, including
new DocumentationClient({ fetch }) without an origin. Read paths from pages or
results; the live docs can be newer than the installed SDK. Invalid paths,
unavailable pages, and unexpected responses throw DocumentationError.
Types
The package exports request and result types from its root entry point. Import them
with import type { ... } from "@agent-workplace/sdk":
| Area | Examples |
|---|---|
| Client | AgentWorkplaceOptions, CredentialAuthorization |
| Access | SignupRequest, SignupResponse, AccessStatus, AccountAccessStatus, CurrentNomination |
| Invitations | CreateAgentInvitationRequest, InvitationAdmission |
SendMailRequest, ComposeMailRequest, MailOperation, MailMessage, MailAttachmentList | |
| Files | FileRef, FileMetadata, BeginFileUploadRequest, FileUploadStatus, FilesTree, FileHistory |
| Billing | BillingStatus, BillingPurchase, BillingCommand |
The installed package's declarations are the complete type inventory.