UNPKG

@automattic/agenttic-client

Version:

A TypeScript client library for A2A (Agent2Agent) protocol communication

77 lines 2.47 kB
/** * Jetpack Authentication Provider for Agenttic Client * * Provides authentication for WordPress sites using Jetpack connection. */ /** * Internal dependencies */ import type { AuthProvider } from '../client/types/index'; export declare const JWT_TOKEN_ID = "jetpack-ai-jwt-token"; export declare const JWT_TOKEN_EXPIRATION_TIME: number; declare global { interface Window { JP_CONNECTION_INITIAL_STATE?: { apiNonce: string; siteSuffix: string; connectionStatus: { isActive: boolean; }; }; Jetpack_Editor_Initial_State?: { wpcomBlogId: string; }; } } interface TokenData { token: string; blogId: string; expire: number; } export interface JetpackApiError { code?: string; status?: number; message?: string; } /** * Error handler function type for Jetpack authentication errors */ export type JetpackErrorHandler = (error: JetpackApiError) => string; /** * Request a JWT token from Jetpack for API authentication * @param errorHandler - Function to handle and format error messages * @param useCachedToken - Whether to use cached token if available and valid * @return Token data with JWT token and blog ID, or null on failure */ export declare function requestJetpackToken(errorHandler: JetpackErrorHandler, useCachedToken?: boolean): Promise<TokenData | null>; /** * Create a Jetpack authentication provider for use with Agenttic client. * * This factory function creates an authentication provider that handles * authentication for WordPress sites with Jetpack, automatically managing * token caching and refresh. * * @example * ```typescript * import { createJetpackAuthProvider } from '@automattic/agenttic-client'; * import { useAgent } from '@automattic/agenttic-client'; * * const errorHandler = (error) => { * if (error.code === 'rest_forbidden') { * return 'Permission denied'; * } * return 'Authentication failed'; * }; * * const { state, sendMessage } = useAgent({ * agentId: 'my-agent', * authProvider: createJetpackAuthProvider(errorHandler), * }); * ``` * * @param errorHandler - Function to handle and format error messages * @return Authentication provider function that returns headers with JWT token */ export declare const createJetpackAuthProvider: (errorHandler: JetpackErrorHandler) => AuthProvider; export {}; //# sourceMappingURL=jetpack.d.ts.map