import { GatewayErrorCode, ApprovalContext } from '@vess-id/ai-identity'; /** * Gateway API client for agentd (spec §10). * * All requests use X-Device-Session-Token header for authentication. * * Endpoints: * - POST /api/v1/agentd/nonce (nonce for VP replay prevention) * - POST /api/v1/agentd/vc/auto-issue (auto-issue VC) * - GET /api/v1/agentd/vc/approved (find approved requests) * - GET /api/v1/agentd/vc/status/:jti (VC revocation status) * - POST /api/v1/agentd/vp/verify-authorize (VP verify + authorize) * - POST /api/v1/agentd/approval/request (OOB approval request create) * - GET /api/v1/agentd/approval/:id/status (OOB approval status poll) * - POST /api/v1/grant/quick-approve (inline Grant + VC issuance) * - POST /api/v1/grant/consume (one-time grant consumption) * - POST /api/v1/tool/invoke (SaaS tool execution) * - POST /api/v1/audit/batch (batch audit event sync) * - GET /api/v1/grant/policy/:projectId (org policy sync) * - POST /api/v1/agentd/resource/resolve (resolve human-readable resource to canonical ID) */ /** Resource constraint describing a scoped resource (e.g., Slack channel, GitHub repo). */ export interface ResourceConstraint { provider: string; type: string; id?: string; pattern?: string; } export interface AutoIssueVCParams { subjectDid: string; projectId: string; actions: string[]; sessionId?: string; /** * Optional approval context carried on the retry path after the user * clicked 承認 in the approval UI (Cedar 一元化 Step 3.5 client side). * * When present, the API server's `/api/v1/agentd/vc/auto-issue` endpoint * consumes the single-use `token` against the approval-token ledger and * injects `{ granted: true, request_id, outcome_id }` into the Cedar * `context.approval` so a policy that previously returned `auth_required` * now returns `permit`. * * Field names use snake_case to match the server DTO * (`ApprovalContextDto` in `packages/api/src/grant/dto/remote-vc.dto.ts` / * `AutoIssueVCApprovalContextInternalDto` in the internal controller). * * Spec ref: docs/specs/2026-05-24-cedar-unification-design.md §6 / §11.1. */ approval_context?: ApprovalContext; /** * 動作確認 fix-forward (Cedar 一元化 spec rev 5) — raw tool-invocation * parameters (e.g. `{to: 'kantaro@vess.id'}` for `gmail.message.send`, * `{channel: 'C123'}` for `slack.message.post`). The server uses these * to bind `context.recipient.address` on the Cedar pre-check so policies * like `recipient.address like "*@vess.id"` evaluate cleanly at the * autoIssueVC layer (rather than failing indeterminate → 500). * * Optional for backward compat: pre-rev-5 servers accept-and-ignore the * field; pre-rev-5 clients omit it and continue to work for actions whose * policies don't reference `context.recipient`. */ parameters?: Record; } export interface AutoIssueVCResult { autoIssued: boolean; credential: { jwt: string; expiresAt: number; }; actions: string[]; resources?: ResourceConstraint[]; metadata?: Record; } export interface ApprovedRequest { id: string; actions: string[]; approvalExpiresAt?: string; resources?: ResourceConstraint[]; } export interface VerifyAuthorizeResult { authorized: boolean; reason?: string; projectId?: string; issuerDid?: string; grantId?: string; approvalMode?: 'one_time' | 'persistent'; } export interface CreateApprovalRequestParams { subjectDid: string; projectId: string; actions: string[]; resources?: ResourceConstraint[]; expiresInHours?: number; actionParams?: Record; } export interface CreateApprovalRequestResult { requestId: string; approvalUrl: string; status: string; expiresAt: string; } export interface ApprovalStatusResult { status: 'pending' | 'approved' | 'denied' | 'expired' | 'consumed'; actions?: string[]; resources?: ResourceConstraint[]; grant?: any; approvalExpiresAt?: string; approvalUrl?: string; requestExpiresAt?: string; } export interface QuickApproveParams { actions: string[]; resources: Array<{ type: string; pattern?: string; id?: string; }>; normalizedResource?: string; resourceFingerprint?: string; subjectDid: string; projectId: string; issueVC: boolean; approvalMode: 'one_time' | 'persistent'; approvalNonce: string; expiresInHours?: number; } export interface QuickApproveResult { grant: { id: string; actions: string[]; resources: Array<{ type: string; id?: string; pattern?: string; }>; status: string; }; /** The VC credential JWT string (raw JWT, not wrapped in an object) */ credential: string; vcId: string; issuerDid: string; subjectDid: string; actions: string[]; issuedAt: string; /** ISO 8601 expiration timestamp */ expiresAt: string; /** Resources with provider enrichment, ready for wallet storage */ resources?: ResourceConstraint[]; } export interface ResolveResourceResult { canonicalId: string; displayName: string; provider: string; type: string; resolved: boolean; } export interface ReauthRequiredInfo { provider: string; reason: string; message: string; authUrl: string; projectId?: string; metadata?: Record; } export interface InvokeToolResult { success: boolean; data?: any; error?: string; errorCode?: GatewayErrorCode; allowedResources?: string[]; requestedResource?: string; reauthRequired?: ReauthRequiredInfo; } export interface ConsumeGrantResult { consumed: boolean; reason?: string; } export interface RegisterAgentParams { agentDid: string; name: string; type: string; publicKey: { kty: string; crv: string; x: string; y: string; }; projectId: string; deviceInfo?: { platform?: string; hostname?: string; runtime?: string; }; } export interface RegisterAgentResult { id: string; did: string; name: string; type: string; status: string; } export interface InvokeToolParams { action: string; parameters: Record; holderDid: string; vpJwt: string; vpChallenge: string; vpDomain: string; } /** * Custom error for network-level failures (connection refused, DNS, timeout). * Used by ExecutionEngine to distinguish network issues from code bugs. */ export declare class GatewayNetworkError extends Error { readonly cause?: unknown | undefined; constructor(message: string, cause?: unknown | undefined); } /** * Custom error for HTTP-level failures from the gateway (non-2xx, non-network). * * Exposes `status` (numeric HTTP status code) so callers can distinguish * 409 (idempotent conflict) from 5xx (transient) without string-matching * the error message. This makes the agentd-side retry logic robust against * any future change in the message format produced by gateway-client. */ export declare class GatewayHttpError extends Error { readonly status: number; readonly body?: string | undefined; constructor(message: string, status: number, body?: string | undefined); } export declare class AgentdGatewayClient { private readonly baseUrl; private readonly getSessionToken; private readonly onTokenRefreshed?; /** Shared promise for deduplicating concurrent token refresh attempts */ private refreshPromise; constructor(baseUrl: string, getSessionToken: () => string, onTokenRefreshed?: ((newToken: string) => void) | undefined); private buildHeaders; /** * Wrap fetch calls to convert network errors into GatewayNetworkError. */ private fetchWithNetworkError; /** * Wrap fetch calls with automatic retry on 401 (token expired). * On 401, attempts to refresh the token and retry the original request. * Does NOT apply to refreshToken itself (to avoid infinite loops). */ private fetchWithAuthRetry; /** * Refresh the device session token. * POST /api/v1/device/refresh * NOTE: Uses fetchWithNetworkError (not fetchWithAuthRetry) to avoid infinite loops. */ refreshToken(): Promise<{ deviceSessionToken: string; expiresAt: string; }>; /** * Issue nonce for VP replay prevention. * POST /api/v1/agentd/nonce */ issueNonce(agentDid: string): Promise<{ nonce: string; }>; /** * Auto-issue VC when grant has autoApprove enabled. * POST /api/v1/agentd/vc/auto-issue */ autoIssueVC(params: AutoIssueVCParams): Promise; /** * Find approved requests by subjectDid. * GET /api/v1/agentd/vc/approved?subjectDid=... */ findApprovedRequests(subjectDid: string): Promise; /** * Claim a VC from an approved request (atomic, one-time). * POST /api/v1/agentd/vc/claim */ claimVC(requestId: string, subjectDid: string): Promise<{ credential: { jwt: string; expiresAt: number; }; vcId: string; actions: string[]; resources?: ResourceConstraint[]; actionParams?: Record; }>; /** * Check VC revocation status by jti. * GET /api/v1/agentd/vc/status/:jti */ checkVCStatus(jti: string): Promise<{ valid: boolean; reason?: string; }>; /** * VP verify + grant authorization check (gateway_verified_local). * POST /api/v1/agentd/vp/verify-authorize */ verifyAndAuthorize(vpJwt: string, challenge: string, domain: string, action: string, holderDid: string): Promise; /** * Register an agent in the API Agent table so it appears in agents.html / timeline.html. * POST /api/v1/agents/create * * Requires X-Project-Id header for ProjectRoleGuard. * Treats 409 Conflict as success (idempotent — agent already exists). */ registerAgent(params: RegisterAgentParams): Promise; /** * Inline Grant + VC issuance (spec §6.2). * POST /api/v1/grant/quick-approve */ quickApprove(params: QuickApproveParams): Promise; /** * Create an OOB approval request for high-risk actions. * POST /api/v1/agentd/approval/request */ createApprovalRequest(params: CreateApprovalRequestParams): Promise; /** * Poll the status of an OOB approval request. * GET /api/v1/agentd/approval/:requestId/status */ getApprovalStatus(requestId: string): Promise; /** * One-time grant atomic consumption (spec §6.2). * POST /api/v1/grant/consume */ consumeGrant(grantId: string): Promise; /** * SaaS tool execution via Gateway (VP in Authorization header). * POST /api/v1/tool/invoke */ invokeTool(params: InvokeToolParams): Promise; /** * Resolve a human-readable resource identifier to its canonical ID. * POST /api/v1/agentd/resource/resolve */ resolveResource(params: { provider: string; resourceType: string; input: string; projectId: string; }): Promise; /** * Fetch org-level policy for a project (spec §7.6). */ fetchOrgPolicy(projectId: string): Promise; /** * Verify a VP with the Gateway (spec §7.4 gateway_verified_local). * @deprecated Use verifyAndAuthorize instead for full VP+grant check. */ verifyVP(vpJwt: string, nonce: string, domain: string): Promise<{ valid: boolean; reason?: string; }>; /** * Check if Gateway is reachable. */ isReachable(): Promise; } //# sourceMappingURL=gateway-client.d.ts.map