@syfthub/sdk 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +494 -178
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +495 -146
- package/dist/index.d.ts +495 -146
- package/dist/index.js +494 -179
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/utils.ts","../src/client.ts","../src/resources/api-tokens.ts","../src/resources/auth.ts","../src/resources/aggregators.ts","../src/resources/users.ts","../src/pagination.ts","../src/resources/my-endpoints.ts","../src/resources/hub.ts","../src/resources/accounting.ts","../src/resources/agent.ts","../src/resources/chat.ts","../src/models/common.ts","../src/models/endpoint.ts","../src/resources/syftai.ts","../src/index.ts"],"names":["NotFoundError","data"],"mappings":";;;;;;;;;;;AAAA,IAAA,cAAA,GAAA,EAAA;AAAA,QAAA,CAAA,cAAA,EAAA;AAAA,EAAA,QAAA,EAAA,MAAA,QAAA;AAAA,EAAA,4BAAA,EAAA,MAAA,4BAAA;AAAA,EAAA,iCAAA,EAAA,MAAA,iCAAA;AAAA,EAAA,mBAAA,EAAA,MAAA,mBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA,kBAAA;AAAA,EAAA,kBAAA,EAAA,MAAA,kBAAA;AAAA,EAAA,8BAAA,EAAA,MAAA,8BAAA;AAAA,EAAA,YAAA,EAAA,MAAA,YAAA;AAAA,EAAA,aAAA,EAAA,MAAA,aAAA;AAAA,EAAA,YAAA,EAAA,MAAA,YAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,eAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AAAA,IAGa,YAAA,CAAA,CAcA,QAAA,CAAA,CAeA,mBAAA,CAAA,CAWA,kBAAA,CAAA,CAUA,aAAA,CAAA,CAWA,iBAa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AAA;AAAA;AAAA;AAAA,EAeA,IAAI,uBAAA,GAAmC;AACrC,IAAA,OAAO,IAAA,CAAK,WAAA,KAAgB,MAAA,IAAa,IAAA,CAAK,WAAA,KAAgB,IAAA;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,KAAA,GAAc;AAAA,EAGd;AACF;;;ActaA,WAAA,EAAA","file":"index.js","sourcesContent":["/**\n * Base error class for all SyftHub SDK errors.\n */\nexport class SyftHubError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SyftHubError';\n // Maintains proper stack trace for where error was thrown (V8 engines)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n}\n\n/**\n * Error thrown when an API request fails with an error status code.\n */\nexport class APIError extends SyftHubError {\n constructor(\n message: string,\n public readonly status: number,\n public readonly data?: unknown\n ) {\n super(message);\n this.name = 'APIError';\n }\n}\n\n/**\n * Error thrown when authentication is required but not provided,\n * or when credentials are invalid (HTTP 401).\n */\nexport class AuthenticationError extends SyftHubError {\n constructor(message: string = 'Authentication required') {\n super(message);\n this.name = 'AuthenticationError';\n }\n}\n\n/**\n * Error thrown when the user doesn't have permission to access\n * a resource (HTTP 403).\n */\nexport class AuthorizationError extends SyftHubError {\n constructor(message: string = 'Permission denied') {\n super(message);\n this.name = 'AuthorizationError';\n }\n}\n\n/**\n * Error thrown when a requested resource is not found (HTTP 404).\n */\nexport class NotFoundError extends SyftHubError {\n constructor(message: string = 'Resource not found') {\n super(message);\n this.name = 'NotFoundError';\n }\n}\n\n/**\n * Error thrown when request validation fails (HTTP 422).\n * Contains field-level error details when available.\n */\nexport class ValidationError extends SyftHubError {\n constructor(\n message: string,\n public readonly errors?: Record<string, string[]>\n ) {\n super(message);\n this.name = 'ValidationError';\n }\n}\n\n/**\n * Error thrown when a network request fails (connection errors, timeouts).\n */\nexport class NetworkError extends SyftHubError {\n constructor(\n message: string = 'Network request failed',\n public readonly cause?: Error\n ) {\n super(message);\n this.name = 'NetworkError';\n }\n}\n\n/**\n * Error thrown when SDK configuration is invalid.\n */\nexport class ConfigurationError extends SyftHubError {\n constructor(message: string = 'Invalid SDK configuration') {\n super(message);\n this.name = 'ConfigurationError';\n }\n}\n\n// =============================================================================\n// User Registration Errors\n// =============================================================================\n\n/**\n * Error thrown when username or email already exists in SyftHub (HTTP 409).\n *\n * This error indicates a duplicate user registration attempt.\n * The `field` property indicates which field caused the conflict.\n *\n * @example\n * ```typescript\n * try {\n * await client.auth.register({ username: \"john\", email: \"john@example.com\", ... });\n * } catch (error) {\n * if (error instanceof UserAlreadyExistsError) {\n * console.log(`${error.field} is already taken`);\n * }\n * }\n * ```\n */\nexport class UserAlreadyExistsError extends SyftHubError {\n /** The field that caused the conflict (\"username\" or \"email\") */\n public readonly field?: string;\n\n constructor(\n message: string = 'Username or email already exists',\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'UserAlreadyExistsError';\n // Extract field from detail if available\n if (detail && typeof detail === 'object' && 'field' in detail) {\n this.field = (detail as { field?: string }).field;\n }\n }\n}\n\n// =============================================================================\n// Accounting-related Errors\n// =============================================================================\n\n/**\n * Error thrown when email already exists in the accounting service during registration.\n *\n * This error indicates that the user needs to provide their existing\n * accounting password to link their SyftHub account with their existing\n * accounting account.\n *\n * @example\n * ```typescript\n * try {\n * await client.auth.register({ username: \"john\", email: \"john@example.com\", ... });\n * } catch (error) {\n * if (error instanceof AccountingAccountExistsError) {\n * // Prompt user for their existing accounting password\n * const accountingPassword = prompt(\"Enter your existing accounting password:\");\n * // Retry registration with the password\n * await client.auth.register({\n * username: \"john\",\n * email: \"john@example.com\",\n * ...,\n * accountingPassword\n * });\n * }\n * }\n * ```\n */\nexport class AccountingAccountExistsError extends SyftHubError {\n /** Indicates that the user needs to provide their existing accounting password */\n public readonly requiresAccountingPassword = true;\n\n constructor(\n message: string = 'This email already has an account in the accounting service',\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'AccountingAccountExistsError';\n }\n}\n\n/**\n * Error thrown when the provided accounting password is invalid.\n */\nexport class InvalidAccountingPasswordError extends SyftHubError {\n constructor(\n message: string = 'The provided accounting password is invalid',\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'InvalidAccountingPasswordError';\n }\n}\n\n/**\n * Error thrown when the accounting service is unavailable or returns an error.\n */\nexport class AccountingServiceUnavailableError extends SyftHubError {\n constructor(\n message: string = 'Accounting service is unavailable',\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'AccountingServiceUnavailableError';\n }\n}\n","import {\n AccountingAccountExistsError,\n AccountingServiceUnavailableError,\n APIError,\n AuthenticationError,\n AuthorizationError,\n InvalidAccountingPasswordError,\n NetworkError,\n NotFoundError,\n SyftHubError,\n UserAlreadyExistsError,\n ValidationError,\n} from './errors.js';\nimport { toCamelCase, toSnakeCase, buildSearchParams } from './utils.js';\n\n/**\n * Options for HTTP requests.\n */\nexport interface RequestOptions {\n /** Whether to include the Authorization header (default: true) */\n includeAuth?: boolean;\n /** Whether to send body as form-urlencoded instead of JSON */\n isFormData?: boolean;\n /** Request-specific timeout in milliseconds */\n timeout?: number;\n}\n\n/**\n * Internal request options including body and params.\n */\ninterface InternalRequestOptions extends RequestOptions {\n body?: unknown;\n params?: Record<string, unknown>;\n}\n\n/**\n * Auth tokens returned from login/refresh.\n */\nexport interface AuthTokens {\n accessToken: string;\n refreshToken: string;\n tokenType: string;\n}\n\n/**\n * Internal HTTP client for making API requests.\n *\n * Handles:\n * - Bearer token authentication (JWT or API token)\n * - Automatic token refresh on 401 responses (JWT only)\n * - JSON serialization/deserialization\n * - snake_case <-> camelCase conversion\n * - Error handling and exception mapping\n */\nexport class HTTPClient {\n private accessToken: string | null = null;\n private refreshToken: string | null = null;\n private apiToken: string | null = null;\n private isRefreshing = false;\n private refreshPromise: Promise<void> | null = null;\n\n /**\n * Create a new HTTP client.\n *\n * @param baseUrl - Base URL for all API requests (without trailing slash)\n * @param timeout - Default timeout in milliseconds (default: 30000)\n */\n constructor(\n private readonly baseUrl: string,\n private readonly timeout: number = 30000\n ) {}\n\n /**\n * Set JWT authentication tokens.\n * Clears any API token if set.\n */\n setTokens(access: string, refresh: string): void {\n this.accessToken = access;\n this.refreshToken = refresh;\n this.apiToken = null; // Clear API token when using JWT\n }\n\n /**\n * Set API token for authentication.\n * Clears any JWT tokens if set.\n *\n * @param token - The API token (starts with \"syft_\")\n */\n setApiToken(token: string): void {\n this.apiToken = token;\n this.accessToken = null; // Clear JWT tokens when using API token\n this.refreshToken = null;\n }\n\n /**\n * Get current JWT authentication tokens.\n * Returns null if using API token authentication.\n */\n getTokens(): AuthTokens | null {\n if (!this.accessToken || !this.refreshToken) {\n return null;\n }\n return {\n accessToken: this.accessToken,\n refreshToken: this.refreshToken,\n tokenType: 'bearer',\n };\n }\n\n /**\n * Check if using API token authentication.\n */\n isUsingApiToken(): boolean {\n return this.apiToken !== null;\n }\n\n /**\n * Clear all authentication (JWT and API tokens).\n */\n clearTokens(): void {\n this.accessToken = null;\n this.refreshToken = null;\n this.apiToken = null;\n }\n\n /**\n * Check if the client has valid authentication (JWT or API token).\n */\n hasTokens(): boolean {\n return this.accessToken !== null || this.apiToken !== null;\n }\n\n /**\n * Get the current bearer token (API token or JWT access token).\n */\n private getBearerToken(): string | null {\n return this.apiToken ?? this.accessToken;\n }\n\n /**\n * Make a GET request.\n */\n async get<T>(\n path: string,\n params?: Record<string, unknown>,\n options?: RequestOptions\n ): Promise<T> {\n return this.request<T>('GET', path, { ...options, params });\n }\n\n /**\n * Make a POST request.\n */\n async post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {\n return this.request<T>('POST', path, { ...options, body });\n }\n\n /**\n * Make a PUT request.\n */\n async put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {\n return this.request<T>('PUT', path, { ...options, body });\n }\n\n /**\n * Make a PATCH request.\n */\n async patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {\n return this.request<T>('PATCH', path, { ...options, body });\n }\n\n /**\n * Make a DELETE request.\n */\n async delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('DELETE', path, options);\n }\n\n /**\n * Make an HTTP request with automatic retry on 401.\n */\n private async request<T>(\n method: string,\n path: string,\n options: InternalRequestOptions = {}\n ): Promise<T> {\n const { includeAuth = true, isFormData = false, timeout, body, params } = options;\n\n // Build URL with query params\n let url = `${this.baseUrl}${path}`;\n if (params) {\n const searchParams = buildSearchParams(params);\n const queryString = searchParams.toString();\n if (queryString) {\n url += `?${queryString}`;\n }\n }\n\n // Build headers\n const headers: Record<string, string> = {};\n\n const bearerToken = this.getBearerToken();\n if (includeAuth && bearerToken) {\n headers['Authorization'] = `Bearer ${bearerToken}`;\n }\n\n // Build body\n let requestBody: string | undefined;\n if (body !== undefined) {\n if (isFormData) {\n headers['Content-Type'] = 'application/x-www-form-urlencoded';\n // For form data, convert to URLSearchParams\n const formData = new URLSearchParams();\n for (const [key, value] of Object.entries(body as Record<string, unknown>)) {\n if (value !== undefined && value !== null) {\n formData.append(key, String(value));\n }\n }\n requestBody = formData.toString();\n } else {\n headers['Content-Type'] = 'application/json';\n // Convert camelCase to snake_case for JSON bodies\n requestBody = JSON.stringify(toSnakeCase(body));\n }\n }\n\n // Create abort controller for timeout\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout ?? this.timeout);\n\n try {\n const response = await fetch(url, {\n method,\n headers,\n body: requestBody,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n // Handle 401 with automatic token refresh (JWT only, not API tokens)\n // API tokens don't have refresh capability - they just fail\n if (response.status === 401 && includeAuth && this.refreshToken && !this.apiToken) {\n // Attempt to refresh the token\n await this.attemptTokenRefresh();\n\n // Retry the original request with new token\n return this.request<T>(method, path, {\n ...options,\n // Mark that we shouldn't retry again to prevent infinite loops\n includeAuth: true,\n });\n }\n\n return await this.handleResponse<T>(response);\n } catch (error) {\n clearTimeout(timeoutId);\n\n if (error instanceof SyftHubError) {\n throw error;\n }\n\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new NetworkError('Request timed out', error);\n }\n throw new NetworkError(error.message, error);\n }\n\n throw new NetworkError('Unknown network error');\n }\n }\n\n /**\n * Handle the HTTP response and convert to the expected type.\n */\n private async handleResponse<T>(response: Response): Promise<T> {\n // Try to parse response as JSON\n let data: unknown;\n const contentType = response.headers.get('content-type');\n\n if (contentType?.includes('application/json')) {\n try {\n data = await response.json();\n } catch {\n data = null;\n }\n } else {\n // For non-JSON responses, use text\n const text = await response.text();\n data = text || null;\n }\n\n // Handle error responses\n if (!response.ok) {\n this.handleErrorResponse(response.status, data);\n }\n\n // Convert snake_case to camelCase and parse dates\n return toCamelCase<T>(data);\n }\n\n /**\n * Handle error responses by throwing appropriate exceptions.\n */\n private handleErrorResponse(status: number, data: unknown): never {\n const message = this.extractErrorMessage(data);\n const { code, detail } = this.extractErrorCodeAndDetail(data);\n\n // Check for domain-specific errors based on error code first\n if (code) {\n switch (code) {\n // User registration errors\n case 'USER_ALREADY_EXISTS':\n throw new UserAlreadyExistsError(message, detail);\n // Accounting-related errors\n case 'ACCOUNTING_ACCOUNT_EXISTS':\n throw new AccountingAccountExistsError(message, detail);\n case 'INVALID_ACCOUNTING_PASSWORD':\n throw new InvalidAccountingPasswordError(message, detail);\n case 'ACCOUNTING_SERVICE_UNAVAILABLE':\n throw new AccountingServiceUnavailableError(message, detail);\n }\n }\n\n // Standard status code handling\n switch (status) {\n case 401:\n throw new AuthenticationError(message);\n case 403:\n throw new AuthorizationError(message);\n case 404:\n throw new NotFoundError(message);\n case 422:\n throw new ValidationError(message, this.extractValidationErrors(data));\n default:\n throw new APIError(message, status, data);\n }\n }\n\n /**\n * Extract error code and detail from API response.\n * Used for accounting-specific error handling.\n */\n private extractErrorCodeAndDetail(data: unknown): { code?: string; detail?: unknown } {\n if (!data || typeof data !== 'object') {\n return {};\n }\n\n // FastAPI returns { detail: { code: \"...\", message: \"...\", ... } }\n if ('detail' in data) {\n const detail = (data as { detail: unknown }).detail;\n if (detail && typeof detail === 'object' && 'code' in detail) {\n const innerDetail = detail as { code?: string };\n return {\n code: innerDetail.code,\n detail: detail,\n };\n }\n }\n\n return {};\n }\n\n /**\n * Extract error message from API response.\n */\n private extractErrorMessage(data: unknown): string {\n if (typeof data === 'string') {\n return data;\n }\n\n if (data && typeof data === 'object') {\n // FastAPI style: { detail: \"message\" }\n if ('detail' in data) {\n const detail = (data as { detail: unknown }).detail;\n if (typeof detail === 'string') {\n return detail;\n }\n // FastAPI validation errors: { detail: [{ msg: \"...\", loc: [...] }] }\n if (Array.isArray(detail) && detail.length > 0) {\n const firstError = detail[0] as { msg?: string };\n if (firstError?.msg) {\n return firstError.msg;\n }\n }\n }\n\n // Generic: { message: \"...\" } or { error: \"...\" }\n if ('message' in data && typeof (data as { message: unknown }).message === 'string') {\n return (data as { message: string }).message;\n }\n if ('error' in data && typeof (data as { error: unknown }).error === 'string') {\n return (data as { error: string }).error;\n }\n }\n\n return 'An error occurred';\n }\n\n /**\n * Extract field-level validation errors from API response.\n */\n private extractValidationErrors(data: unknown): Record<string, string[]> | undefined {\n if (!data || typeof data !== 'object' || !('detail' in data)) {\n return undefined;\n }\n\n const detail = (data as { detail: unknown }).detail;\n if (!Array.isArray(detail)) {\n return undefined;\n }\n\n const errors: Record<string, string[]> = {};\n\n for (const error of detail) {\n if (typeof error === 'object' && error !== null && 'loc' in error && 'msg' in error) {\n const { loc, msg } = error as { loc: unknown[]; msg: string };\n // loc is typically ['body', 'field_name']\n const field = String(loc[loc.length - 1] ?? 'unknown');\n if (!errors[field]) {\n errors[field] = [];\n }\n errors[field].push(msg);\n }\n }\n\n return Object.keys(errors).length > 0 ? errors : undefined;\n }\n\n /**\n * Attempt to refresh the access token using the refresh token.\n */\n private async attemptTokenRefresh(): Promise<void> {\n // If already refreshing, wait for the existing refresh to complete\n if (this.isRefreshing && this.refreshPromise) {\n await this.refreshPromise;\n return;\n }\n\n this.isRefreshing = true;\n\n this.refreshPromise = (async () => {\n try {\n const response = await fetch(`${this.baseUrl}/api/v1/auth/refresh`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ refresh_token: this.refreshToken }),\n });\n\n if (!response.ok) {\n // Refresh failed, clear tokens\n this.clearTokens();\n throw new AuthenticationError('Token refresh failed');\n }\n\n const data = (await response.json()) as {\n access_token: string;\n refresh_token: string;\n };\n\n this.accessToken = data.access_token;\n this.refreshToken = data.refresh_token;\n } finally {\n this.isRefreshing = false;\n this.refreshPromise = null;\n }\n })();\n\n await this.refreshPromise;\n }\n}\n","// Per-key caches. Every request runs these over every key; the key-set is\n// small (tens to low hundreds across a process lifetime) so an unbounded Map\n// is fine and saves repeated regex work on hot paths.\nconst snakeToCamelCache = new Map<string, string>();\nconst camelToSnakeCache = new Map<string, string>();\n\n/**\n * Convert a snake_case string to camelCase.\n *\n * @example\n * snakeToCamel('created_at') // 'createdAt'\n * snakeToCamel('full_name') // 'fullName'\n */\nexport function snakeToCamel(str: string): string {\n const cached = snakeToCamelCache.get(str);\n if (cached !== undefined) return cached;\n const result = str.replace(/_([a-z])/g, (_, letter: string) => letter.toUpperCase());\n snakeToCamelCache.set(str, result);\n return result;\n}\n\n/**\n * Convert a camelCase string to snake_case.\n *\n * @example\n * camelToSnake('createdAt') // 'created_at'\n * camelToSnake('fullName') // 'full_name'\n */\nexport function camelToSnake(str: string): string {\n const cached = camelToSnakeCache.get(str);\n if (cached !== undefined) return cached;\n const result = str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);\n camelToSnakeCache.set(str, result);\n return result;\n}\n\n/**\n * Regular expression to match ISO 8601 date strings.\n */\nconst ISO_DATE_REGEX = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/;\n\n/**\n * Check if a value looks like an ISO date string.\n */\nfunction isISODateString(value: unknown): value is string {\n return typeof value === 'string' && ISO_DATE_REGEX.test(value);\n}\n\n/**\n * Recursively transform object keys using the provided transformer function.\n * Optionally parses ISO date strings to Date objects.\n *\n * @param obj - The object to transform\n * @param keyTransformer - Function to transform each key\n * @param parseDates - Whether to parse ISO date strings to Date objects\n */\nexport function transformKeys<T>(\n obj: unknown,\n keyTransformer: (key: string) => string,\n parseDates = true\n): T {\n // Handle null and undefined\n if (obj === null || obj === undefined) {\n return obj as T;\n }\n\n // Handle arrays\n if (Array.isArray(obj)) {\n return obj.map((item) => transformKeys(item, keyTransformer, parseDates)) as T;\n }\n\n // Serialize Date objects to ISO strings. Must come before the object branch,\n // which would otherwise enumerate a Date's (empty) own properties.\n if (obj instanceof Date) {\n return obj.toISOString() as T;\n }\n\n // Handle date strings\n if (parseDates && isISODateString(obj)) {\n return new Date(obj) as T;\n }\n\n // Handle objects\n if (typeof obj === 'object') {\n const transformed: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n transformed[keyTransformer(key)] = transformKeys(value, keyTransformer, parseDates);\n }\n return transformed as T;\n }\n\n // Return primitives as-is\n return obj as T;\n}\n\n/**\n * Convert all keys in an object from camelCase to snake_case.\n * Does not parse dates (for request bodies).\n */\nexport function toSnakeCase<T>(obj: unknown): T {\n return transformKeys<T>(obj, camelToSnake, false);\n}\n\n/**\n * Convert all keys in an object from snake_case to camelCase.\n * Parses ISO date strings to Date objects (for response bodies).\n */\nexport function toCamelCase<T>(obj: unknown): T {\n return transformKeys<T>(obj, snakeToCamel, true);\n}\n\n/**\n * Build URL search params from an object, filtering out undefined values.\n */\nexport function buildSearchParams(params: Record<string, unknown>): URLSearchParams {\n const searchParams = new URLSearchParams();\n\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined && value !== null) {\n searchParams.append(camelToSnake(key), String(value));\n }\n }\n\n return searchParams;\n}\n\n/**\n * Parse a Server-Sent Events stream into event/data pairs.\n *\n * - Yields `{event, data}` on blank-line boundaries (SSE framing) OR after any\n * `data:` line when no preceding `event:` has been seen (tolerates servers\n * that emit only `data:` lines — fall back to `\"message\"`).\n * - Does NOT JSON.parse; callers parse their own schema.\n * - Flushes any pending event when the stream ends.\n */\nexport async function* readSSEEvents(\n response: Response\n): AsyncGenerator<{ event: string; data: string }> {\n if (!response.body) return;\n\n const reader = response.body.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n let currentEvent: string | null = null;\n let currentData = '';\n\n const flush = function* (): Generator<{ event: string; data: string }> {\n if (currentData) {\n yield { event: currentEvent ?? 'message', data: currentData };\n }\n currentEvent = null;\n currentData = '';\n };\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n const trimmed = line.trim();\n\n if (!trimmed) {\n yield* flush();\n continue;\n }\n\n if (trimmed.startsWith('event:')) {\n currentEvent = trimmed.slice(6).trim();\n } else if (trimmed.startsWith('data:')) {\n // If we already have buffered data without a blank-line terminator,\n // emit it now so data-only streams (no event: header) still flow.\n if (currentData && currentEvent === null) {\n yield* flush();\n }\n currentData = trimmed.slice(5).trim();\n }\n }\n }\n\n // Process any trailing line still in the buffer.\n const trailing = buffer.trim();\n if (trailing) {\n if (trailing.startsWith('event:')) {\n currentEvent = trailing.slice(6).trim();\n } else if (trailing.startsWith('data:')) {\n if (currentData && currentEvent === null) {\n yield* flush();\n }\n currentData = trailing.slice(5).trim();\n }\n }\n yield* flush();\n } finally {\n reader.releaseLock();\n }\n}\n","import { HTTPClient, type AuthTokens } from './http.js';\nimport { AuthenticationError, SyftHubError } from './errors.js';\nimport { APITokensResource } from './resources/api-tokens.js';\nimport { AuthResource } from './resources/auth.js';\nimport { UsersResource } from './resources/users.js';\nimport { MyEndpointsResource } from './resources/my-endpoints.js';\nimport { HubResource } from './resources/hub.js';\nimport { AccountingResource } from './resources/accounting.js';\nimport { AgentResource } from './resources/agent.js';\nimport { ChatResource } from './resources/chat.js';\nimport { SyftAIResource } from './resources/syftai.js';\n\n/**\n * Configuration options for SyftHubClient.\n */\nexport interface SyftHubClientOptions {\n /**\n * Base URL for the SyftHub API.\n * Falls back to SYFTHUB_URL environment variable.\n * @example 'https://hub.syft.com'\n */\n baseUrl?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 30000\n */\n timeout?: number;\n\n /**\n * Base URL for the aggregator service (optional).\n * Falls back to SYFTHUB_AGGREGATOR_URL environment variable.\n * Defaults to {baseUrl}/aggregator/api/v1\n */\n aggregatorUrl?: string;\n\n /**\n * API token for authentication (alternative to username/password login).\n * If provided, the client will be authenticated immediately without needing to call login().\n * Falls back to SYFTHUB_API_TOKEN environment variable.\n * @example 'syft_pat_xxxxx...'\n */\n apiToken?: string;\n}\n\n/**\n * Get environment variable, handling both Node.js and browser environments.\n */\nfunction getEnv(key: string): string | undefined {\n if (typeof process !== 'undefined' && process.env) {\n return process.env[key];\n }\n return undefined;\n}\n\n/**\n * Check if running in a browser environment.\n */\nfunction isBrowser(): boolean {\n return (\n typeof globalThis !== 'undefined' &&\n typeof (globalThis as { window?: unknown }).window !== 'undefined' &&\n typeof (globalThis as { document?: unknown }).document !== 'undefined'\n );\n}\n\n/**\n * SyftHub SDK client for interacting with the SyftHub API.\n *\n * @example\n * // Basic usage\n * import { SyftHubClient } from '@syfthub/sdk';\n *\n * const client = new SyftHubClient({ baseUrl: 'https://hub.syft.com' });\n *\n * // Or use environment variable\n * // Set SYFTHUB_URL=https://hub.syft.com\n * const client = new SyftHubClient();\n *\n * @example\n * // Authentication\n * const user = await client.auth.login('alice', 'password123');\n * console.log(`Logged in as ${user.username}`);\n *\n * // Get current user\n * const me = await client.auth.me();\n *\n * @example\n * // Browse endpoints\n * for await (const endpoint of client.hub.browse()) {\n * console.log(endpoint.name);\n * }\n *\n * @example\n * // Manage your endpoints\n * const endpoint = await client.myEndpoints.create({\n * name: 'My Model',\n * type: 'model',\n * visibility: 'public',\n * });\n *\n * @example\n * // Token persistence\n * const tokens = client.getTokens();\n * // Save tokens to storage...\n *\n * // Later, restore tokens\n * client.setTokens(savedTokens);\n */\nexport class SyftHubClient {\n private readonly http: HTTPClient;\n private readonly aggregatorUrl: string;\n\n // Lazy-initialized resources\n private _auth?: AuthResource;\n private _users?: UsersResource;\n private _myEndpoints?: MyEndpointsResource;\n private _hub?: HubResource;\n private _accounting?: AccountingResource;\n private _agent?: AgentResource;\n private _chat?: ChatResource;\n private _syftai?: SyftAIResource;\n private _apiTokens?: APITokensResource;\n\n /**\n * Create a new SyftHub client.\n *\n * @param options - Configuration options\n * @throws {SyftHubError} If baseUrl is not provided and SYFTHUB_URL is not set (in non-browser environments)\n */\n constructor(options: SyftHubClientOptions = {}) {\n let baseUrl = options.baseUrl ?? getEnv('SYFTHUB_URL');\n\n // In browser environments, empty baseUrl means same-origin requests\n // This is valid and commonly used when the API is served from the same domain\n if (!baseUrl && !isBrowser()) {\n throw new SyftHubError(\n 'baseUrl is required. Provide it in options or set the SYFTHUB_URL environment variable.'\n );\n }\n\n // Default to empty string for same-origin browser requests\n baseUrl = baseUrl ?? '';\n\n // Remove trailing slash from base URL (only if not empty)\n const normalizedUrl = baseUrl ? baseUrl.replace(/\\/+$/, '') : '';\n\n this.http = new HTTPClient(normalizedUrl, options.timeout ?? 30000);\n\n // Resolve aggregator URL (default to {baseUrl}/aggregator/api/v1)\n this.aggregatorUrl =\n options.aggregatorUrl ??\n getEnv('SYFTHUB_AGGREGATOR_URL') ??\n `${normalizedUrl}/aggregator/api/v1`;\n\n // Initialize with API token if provided\n const apiToken = options.apiToken ?? getEnv('SYFTHUB_API_TOKEN');\n if (apiToken) {\n this.http.setApiToken(apiToken);\n }\n }\n\n /**\n * Authentication resource for login, register, and session management.\n *\n * @example\n * const user = await client.auth.login('alice', 'password');\n * await client.auth.logout();\n */\n get auth(): AuthResource {\n if (!this._auth) {\n this._auth = new AuthResource(this.http);\n }\n return this._auth;\n }\n\n /**\n * Users resource for profile management.\n *\n * @example\n * const user = await client.users.update({ fullName: 'Alice Smith' });\n * const available = await client.users.checkUsername('newname');\n */\n get users(): UsersResource {\n if (!this._users) {\n this._users = new UsersResource(this.http);\n }\n return this._users;\n }\n\n /**\n * My Endpoints resource for managing your own endpoints.\n *\n * @example\n * const endpoints = await client.myEndpoints.list().all();\n * const endpoint = await client.myEndpoints.create({ name: 'My API', type: 'model' });\n */\n get myEndpoints(): MyEndpointsResource {\n if (!this._myEndpoints) {\n this._myEndpoints = new MyEndpointsResource(this.http);\n }\n return this._myEndpoints;\n }\n\n /**\n * Hub resource for browsing public endpoints.\n *\n * @example\n * for await (const endpoint of client.hub.browse()) {\n * console.log(endpoint.name);\n * }\n */\n get hub(): HubResource {\n if (!this._hub) {\n this._hub = new HubResource(this.http);\n }\n return this._hub;\n }\n\n /**\n * Agent resource for bidirectional agent sessions via WebSocket.\n *\n * @example\n * const session = await client.agent.startSession({\n * prompt: 'Help me refactor this code',\n * endpoint: 'alice/code-assistant',\n * });\n *\n * for await (const event of session.events()) {\n * console.log(event.type, event.payload);\n * }\n */\n get agent(): AgentResource {\n if (!this._agent) {\n this._agent = new AgentResource(this.auth, this.aggregatorUrl);\n }\n return this._agent;\n }\n\n /**\n * Accounting resource for wallet and payment operations.\n *\n * Provides access to MPP wallet management (balance, transactions,\n * wallet creation/import). Uses the same SyftHub JWT authentication\n * as other resources.\n *\n * You must call `initAccounting()` after login to initialize this resource,\n * or access it directly if already initialized.\n *\n * @throws {AuthenticationError} If not initialized\n *\n * @example\n * // Login first, then initialize accounting\n * await client.auth.login('alice', 'password');\n * await client.initAccounting();\n *\n * // Now accounting is available\n * const wallet = await client.accounting.getWallet();\n * const balance = await client.accounting.getBalance();\n */\n get accounting(): AccountingResource {\n if (this._accounting) {\n return this._accounting;\n }\n\n throw new AuthenticationError(\n 'Accounting not initialized. ' + 'Call `await client.initAccounting()` after login.'\n );\n }\n\n /**\n * Initialize the accounting (wallet) resource.\n *\n * The wallet API uses the same SyftHub authentication as other resources.\n * This method simply verifies authentication and creates the resource.\n *\n * @returns The initialized AccountingResource\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * // Login first, then initialize accounting\n * await client.auth.login('alice', 'password');\n * await client.initAccounting();\n *\n * // Now accounting is available\n * const wallet = await client.accounting.getWallet();\n * const balance = await client.accounting.getBalance();\n */\n async initAccounting(): Promise<AccountingResource> {\n // Return cached instance\n if (this._accounting) {\n return this._accounting;\n }\n\n if (!this.isAuthenticated) {\n throw new AuthenticationError(\n 'Must be logged in to use accounting. ' + 'Call client.auth.login() first.'\n );\n }\n\n this._accounting = new AccountingResource(this.http);\n return this._accounting;\n }\n\n /**\n * Chat resource for RAG-augmented conversations via the Aggregator.\n *\n * This resource provides high-level chat functionality that integrates\n * with the SyftHub Aggregator service for RAG workflows.\n *\n * @example\n * // Simple chat completion\n * const response = await client.chat.complete({\n * prompt: 'What is machine learning?',\n * model: 'alice/gpt-model',\n * dataSources: ['bob/ml-docs'],\n * });\n * console.log(response.response);\n *\n * // Streaming chat\n * for await (const event of client.chat.stream(options)) {\n * if (event.type === 'token') {\n * process.stdout.write(event.content);\n * }\n * }\n *\n * // Get available endpoints\n * const models = await client.chat.getAvailableModels();\n * const sources = await client.chat.getAvailableDataSources();\n */\n get chat(): ChatResource {\n if (!this._chat) {\n this._chat = new ChatResource(this.hub, this.auth, this.aggregatorUrl);\n }\n return this._chat;\n }\n\n /**\n * SyftAI-Space resource for direct endpoint queries (low-level API).\n *\n * This resource provides direct access to SyftAI-Space endpoints without\n * going through the aggregator. Use this when you need custom RAG pipelines\n * or fine-grained control over queries.\n *\n * For most use cases, prefer the higher-level `client.chat` API instead.\n *\n * @example\n * // Query a data source directly\n * const docs = await client.syftai.queryDataSource({\n * endpoint: { url: 'http://syftai:8080', slug: 'docs' },\n * query: 'What is Python?',\n * userEmail: 'alice@example.com',\n * });\n *\n * // Query a model directly\n * const response = await client.syftai.queryModel({\n * endpoint: { url: 'http://syftai:8080', slug: 'gpt-model' },\n * messages: [{ role: 'user', content: 'Hello!' }],\n * userEmail: 'alice@example.com',\n * });\n */\n get syftai(): SyftAIResource {\n if (!this._syftai) {\n this._syftai = new SyftAIResource();\n }\n return this._syftai;\n }\n\n /**\n * API Tokens resource for managing personal access tokens.\n *\n * API tokens provide an alternative to username/password authentication.\n * They are ideal for CI/CD pipelines, scripts, and programmatic access.\n *\n * @example\n * // Create a new token\n * const result = await client.apiTokens.create({\n * name: 'CI/CD Pipeline',\n * scopes: ['write'],\n * });\n * console.log('Save this token:', result.token);\n *\n * // List all tokens\n * const { tokens } = await client.apiTokens.list();\n *\n * // Revoke a token\n * await client.apiTokens.revoke(tokenId);\n */\n get apiTokens(): APITokensResource {\n if (!this._apiTokens) {\n this._apiTokens = new APITokensResource(this.http);\n }\n return this._apiTokens;\n }\n\n /**\n * Check if the client is using API token authentication.\n *\n * @returns True if authenticated with an API token (vs JWT)\n */\n get isUsingApiToken(): boolean {\n return this.http.isUsingApiToken();\n }\n\n /**\n * Get current authentication tokens.\n *\n * Use this to persist tokens for later sessions.\n *\n * @returns Current tokens or null if not authenticated\n *\n * @example\n * const tokens = client.getTokens();\n * if (tokens) {\n * localStorage.setItem('tokens', JSON.stringify(tokens));\n * }\n */\n getTokens(): AuthTokens | null {\n return this.http.getTokens();\n }\n\n /**\n * Set authentication tokens.\n *\n * Use this to restore a session from previously saved tokens.\n *\n * @param tokens - Tokens to set\n *\n * @example\n * const saved = JSON.parse(localStorage.getItem('tokens'));\n * if (saved) {\n * client.setTokens(saved);\n * }\n */\n setTokens(tokens: AuthTokens): void {\n this.http.setTokens(tokens.accessToken, tokens.refreshToken);\n }\n\n /**\n * Check if the client is currently authenticated.\n *\n * @returns True if tokens are present\n */\n get isAuthenticated(): boolean {\n return this.http.hasTokens();\n }\n\n /**\n * Check if the accounting (wallet) resource has been initialized.\n *\n * Use this to check if accounting is available before accessing\n * the `accounting` property, which will throw if not initialized.\n *\n * @returns True if accounting has been initialized via `initAccounting()`\n *\n * @example\n * if (client.isAccountingInitialized) {\n * const wallet = await client.accounting.getWallet();\n * }\n */\n get isAccountingInitialized(): boolean {\n return this._accounting !== undefined && this._accounting !== null;\n }\n\n /**\n * Close the client and clean up resources.\n *\n * Currently a no-op, but may be used in future for connection pooling.\n */\n close(): void {\n // Currently a no-op\n // Could be used for cleanup in future (e.g., connection pools)\n }\n}\n","/**\n * Resource for managing API tokens.\n */\n\nimport type { HTTPClient } from '../http.js';\nimport type {\n APIToken,\n APITokenCreateResponse,\n APITokenListResponse,\n CreateAPITokenInput,\n UpdateAPITokenInput,\n} from '../models/api-token.js';\n\n/**\n * Resource for managing API tokens.\n *\n * API tokens provide an alternative to username/password authentication.\n * They are ideal for CI/CD pipelines, scripts, and programmatic access.\n *\n * @example\n * // Create a new token\n * const result = await client.apiTokens.create({\n * name: 'CI/CD Pipeline',\n * scopes: ['write'],\n * });\n * console.log('Save this token:', result.token);\n *\n * // List all tokens\n * const { tokens } = await client.apiTokens.list();\n *\n * // Revoke a token\n * await client.apiTokens.revoke(tokenId);\n */\nexport class APITokensResource {\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * Create a new API token.\n *\n * IMPORTANT: The returned token is only shown ONCE!\n * Make sure to save it immediately - it cannot be retrieved later.\n *\n * @param input - Token creation options\n * @returns The created token with the full token value\n *\n * @example\n * const result = await client.apiTokens.create({\n * name: 'CI/CD Pipeline',\n * scopes: ['write'],\n * expiresAt: new Date('2025-12-31'),\n * });\n *\n * // SAVE THIS TOKEN - it will not be shown again!\n * console.log(result.token);\n */\n async create(input: CreateAPITokenInput): Promise<APITokenCreateResponse> {\n return this.http.post<APITokenCreateResponse>('/api/v1/auth/tokens', input);\n }\n\n /**\n * List all API tokens for the current user.\n *\n * By default, only active tokens are returned.\n * Note: The full token value is never returned - only the prefix.\n *\n * @param options - List options\n * @returns List of tokens and total count\n *\n * @example\n * // List active tokens\n * const { tokens, total } = await client.apiTokens.list();\n *\n * // Include revoked tokens\n * const all = await client.apiTokens.list({ includeInactive: true });\n */\n async list(\n options: {\n includeInactive?: boolean;\n skip?: number;\n limit?: number;\n } = {}\n ): Promise<APITokenListResponse> {\n const params: Record<string, unknown> = {};\n if (options.includeInactive !== undefined) {\n params.include_inactive = options.includeInactive;\n }\n if (options.skip !== undefined) {\n params.skip = options.skip;\n }\n if (options.limit !== undefined) {\n params.limit = options.limit;\n }\n return this.http.get<APITokenListResponse>('/api/v1/auth/tokens', params);\n }\n\n /**\n * Get a single API token by ID.\n *\n * Note: The full token value is never returned - only the prefix.\n *\n * @param tokenId - The token ID\n * @returns The token details\n *\n * @example\n * const token = await client.apiTokens.get(123);\n * console.log(token.name, token.lastUsedAt);\n */\n async get(tokenId: number): Promise<APIToken> {\n return this.http.get<APIToken>(`/api/v1/auth/tokens/${tokenId}`);\n }\n\n /**\n * Update an API token's name.\n *\n * Only the name can be updated. Scopes and expiration cannot be\n * changed after creation.\n *\n * @param tokenId - The token ID\n * @param input - Update options\n * @returns The updated token\n *\n * @example\n * const updated = await client.apiTokens.update(123, {\n * name: 'New Name',\n * });\n */\n async update(tokenId: number, input: UpdateAPITokenInput): Promise<APIToken> {\n return this.http.patch<APIToken>(`/api/v1/auth/tokens/${tokenId}`, input);\n }\n\n /**\n * Revoke an API token.\n *\n * The token becomes immediately unusable. This action cannot be undone.\n *\n * @param tokenId - The token ID to revoke\n *\n * @example\n * await client.apiTokens.revoke(123);\n */\n async revoke(tokenId: number): Promise<void> {\n await this.http.delete<void>(`/api/v1/auth/tokens/${tokenId}`);\n }\n}\n","import type { HTTPClient } from '../http.js';\nimport type {\n AuthConfig,\n PasswordResetConfirmInput,\n PasswordResetRequestInput,\n RegisterResult,\n User,\n UserRegisterInput,\n VerifyOTPInput,\n} from '../models/index.js';\nimport type { TransactionTokensResponse } from '../models/accounting.js';\nimport { AuthenticationError } from '../errors.js';\n\n/**\n * Response from login/register endpoints.\n */\ninterface AuthResponse {\n user: User;\n accessToken: string;\n refreshToken: string;\n tokenType: string;\n}\n\n/**\n * Response from registration endpoint (may have null tokens).\n */\ninterface RegistrationResponse {\n user: User;\n accessToken: string | null;\n refreshToken: string | null;\n tokenType: string;\n requiresEmailVerification: boolean;\n}\n\n/**\n * Authentication resource for login, register, and session management.\n *\n * @example\n * // Register a new user\n * const user = await client.auth.register({\n * username: 'alice',\n * email: 'alice@example.com',\n * password: 'SecurePass123!',\n * fullName: 'Alice'\n * });\n *\n * @example\n * // Login\n * const user = await client.auth.login('alice', 'SecurePass123!');\n *\n * @example\n * // Get current user\n * const me = await client.auth.me();\n *\n * @example\n * // Logout\n * await client.auth.logout();\n */\nexport class AuthResource {\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * Register a new user account.\n *\n * If an accounting service URL is configured (via `accountingServiceUrl` or server default),\n * the backend will handle accounting integration using a \"try-create-first\" approach:\n *\n * **Accounting Password Behavior:**\n * - **Not provided**: A secure password is auto-generated and a new accounting account is created.\n * - **Provided (new user)**: The account is created with your chosen password.\n * - **Provided (existing user)**: Your password is validated and accounts are linked.\n *\n * This means you can set your own accounting password during registration even if you're\n * a new user - you don't need an existing accounting account first.\n *\n * @param input - Registration details (username, email, password, fullName)\n * @returns The created User\n * @throws {ValidationError} If input validation fails\n * @throws {UserAlreadyExistsError} If username or email already exists in SyftHub\n * @throws {AccountingAccountExistsError} If email already exists in accounting service\n * and no `accountingPassword` was provided. Retry with the password.\n * @throws {InvalidAccountingPasswordError} If the provided accounting password doesn't\n * match an existing accounting account\n * @throws {AccountingServiceUnavailableError} If the accounting service is unreachable\n *\n * @example\n * // Basic registration (auto-generated accounting password)\n * const user = await client.auth.register({\n * username: 'alice',\n * email: 'alice@example.com',\n * password: 'SecurePass123!',\n * fullName: 'Alice'\n * });\n *\n * @example\n * // Registration with custom accounting password (NEW user)\n * const user = await client.auth.register({\n * username: 'bob',\n * email: 'bob@example.com',\n * password: 'SecurePass123!',\n * fullName: 'Bob',\n * accountingPassword: 'MyChosenAccountingPass!' // Creates account with this password\n * });\n *\n * @example\n * // Handle existing accounting account\n * try {\n * await client.auth.register({ username, email, password, fullName });\n * } catch (error) {\n * if (error instanceof AccountingAccountExistsError) {\n * // Prompt user for their existing accounting password\n * const accountingPassword = await promptUser('Enter your existing accounting password:');\n * await client.auth.register({ username, email, password, fullName, accountingPassword });\n * } else {\n * throw error;\n * }\n * }\n */\n async register(input: UserRegisterInput): Promise<RegisterResult> {\n const response = await this.http.post<RegistrationResponse>('/api/v1/auth/register', input, {\n includeAuth: false,\n });\n\n // Store tokens if present (not withheld for email verification)\n if (response.accessToken && response.refreshToken) {\n this.http.setTokens(response.accessToken, response.refreshToken);\n }\n\n return {\n user: response.user,\n requiresEmailVerification: response.requiresEmailVerification,\n };\n }\n\n /**\n * Login with username/email and password.\n *\n * Uses OAuth2 password flow (form-urlencoded body).\n *\n * @param username - Username or email\n * @param password - Password\n * @returns The authenticated User\n * @throws {AuthenticationError} If credentials are invalid\n */\n async login(username: string, password: string): Promise<User> {\n const response = await this.http.post<AuthResponse>(\n '/api/v1/auth/login',\n { username, password },\n {\n includeAuth: false,\n isFormData: true,\n }\n );\n\n // Store tokens in HTTP client\n this.http.setTokens(response.accessToken, response.refreshToken);\n\n return response.user;\n }\n\n /**\n * Logout the current user.\n *\n * Invalidates tokens on the server and clears local token storage.\n */\n async logout(): Promise<void> {\n try {\n await this.http.post<void>('/api/v1/auth/logout');\n } finally {\n // Always clear tokens, even if the API call fails\n this.http.clearTokens();\n }\n }\n\n /**\n * Get the current authenticated user.\n *\n * @returns The current User\n * @throws {AuthenticationError} If not authenticated\n */\n async me(): Promise<User> {\n return this.http.get<User>('/api/v1/auth/me');\n }\n\n /**\n * Manually refresh the access token.\n *\n * This is normally handled automatically when a request returns 401.\n *\n * @throws {AuthenticationError} If refresh token is invalid or expired\n */\n async refresh(): Promise<void> {\n const tokens = this.http.getTokens();\n if (!tokens) {\n throw new AuthenticationError('No refresh token available');\n }\n\n const response = await this.http.post<{\n accessToken: string;\n refreshToken: string;\n }>('/api/v1/auth/refresh', { refreshToken: tokens.refreshToken }, { includeAuth: false });\n\n this.http.setTokens(response.accessToken, response.refreshToken);\n }\n\n /**\n * Change the current user's password.\n *\n * @param currentPassword - Current password for verification\n * @param newPassword - New password to set\n * @throws {AuthenticationError} If current password is incorrect\n * @throws {ValidationError} If new password doesn't meet requirements\n */\n async changePassword(currentPassword: string, newPassword: string): Promise<void> {\n await this.http.put<void>('/api/v1/auth/me/password', {\n currentPassword,\n newPassword,\n });\n }\n\n /**\n * Get the platform's authentication configuration.\n *\n * No authentication required. Use this to determine whether email\n * verification or password reset is available.\n *\n * @returns AuthConfig with feature flags\n */\n async getAuthConfig(): Promise<AuthConfig> {\n return this.http.get<AuthConfig>('/api/v1/auth/config', undefined, { includeAuth: false });\n }\n\n /**\n * Verify a registration OTP and receive auth tokens.\n *\n * After registering when email verification is required, call this with\n * the 6-digit code sent to the user's email.\n *\n * Idempotent: if the user is already verified, tokens are issued immediately.\n *\n * @param input - Email and 6-digit code\n * @returns The authenticated User\n * @throws {APIError} If the code is invalid or max attempts exceeded\n */\n async verifyOtp(input: VerifyOTPInput): Promise<User> {\n const response = await this.http.post<AuthResponse>('/api/v1/auth/register/verify-otp', input, {\n includeAuth: false,\n });\n\n this.http.setTokens(response.accessToken, response.refreshToken);\n return response.user;\n }\n\n /**\n * Resend the registration OTP code.\n *\n * Rate-limited. Always returns successfully to prevent email enumeration.\n *\n * @param email - Email address to resend the OTP to\n */\n async resendOtp(email: string): Promise<void> {\n await this.http.post<void>(\n '/api/v1/auth/register/resend-otp',\n { email },\n {\n includeAuth: false,\n }\n );\n }\n\n /**\n * Request a password reset OTP.\n *\n * Always returns successfully to prevent email enumeration.\n * If SMTP is not configured on the server, this is a no-op.\n *\n * @param input - Email address for password reset\n */\n async requestPasswordReset(input: PasswordResetRequestInput): Promise<void> {\n await this.http.post<void>('/api/v1/auth/password-reset/request', input, {\n includeAuth: false,\n });\n }\n\n /**\n * Confirm a password reset with OTP and set a new password.\n *\n * @param input - Email, 6-digit code, and new password\n * @throws {APIError} If the code is invalid or max attempts exceeded\n */\n async confirmPasswordReset(input: PasswordResetConfirmInput): Promise<void> {\n await this.http.post<void>('/api/v1/auth/password-reset/confirm', input, {\n includeAuth: false,\n });\n }\n\n /**\n * Get a peer token for NATS communication with tunneling spaces.\n *\n * Peer tokens are short-lived credentials that allow the aggregator to\n * communicate with tunneling SyftAI Spaces via NATS pub/sub.\n *\n * @param targetUsernames - Usernames of the tunneling spaces to communicate with\n * @returns PeerTokenResponse with token, channel, expiry, and NATS URL\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * const peer = await client.auth.getPeerToken(['alice', 'bob']);\n * console.log(`Peer channel: ${peer.peerChannel}, expires in ${peer.expiresIn}s`);\n */\n async getPeerToken(targetUsernames: string[]): Promise<PeerTokenResponse> {\n return this.http.post<PeerTokenResponse>('/api/v1/peer-token', {\n target_usernames: targetUsernames,\n });\n }\n\n /**\n * Get a guest peer token for NATS communication without authentication.\n *\n * Guest peer tokens are rate-limited by IP address. They use the same\n * response format as authenticated peer tokens.\n *\n * @param targetUsernames - Usernames of the tunneling spaces to communicate with\n * @returns PeerTokenResponse with token, channel, expiry, and NATS URL\n *\n * @example\n * const peer = await client.auth.getGuestPeerToken(['alice']);\n * console.log(`Guest peer channel: ${peer.peerChannel}`);\n */\n async getGuestPeerToken(targetUsernames: string[]): Promise<PeerTokenResponse> {\n return this.http.post<PeerTokenResponse>(\n '/api/v1/nats/guest-peer-token',\n { target_usernames: targetUsernames },\n { includeAuth: false }\n );\n }\n\n /**\n * Get a satellite token for a specific audience (target service).\n *\n * Satellite tokens are short-lived, RS256-signed JWTs that allow satellite\n * services (like SyftAI-Space) to verify user identity without calling\n * SyftHub for every request.\n *\n * @param audience - Target service identifier (username of the service owner)\n * @returns Satellite token response with token and expiry\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If audience is invalid or inactive\n *\n * @example\n * // Get a token for querying alice's SyftAI-Space endpoints\n * const tokenResponse = await client.auth.getSatelliteToken('alice');\n * console.log(`Token expires in ${tokenResponse.expiresIn} seconds`);\n */\n async getSatelliteToken(audience: string): Promise<SatelliteTokenResponse> {\n return this.http.get<SatelliteTokenResponse>('/api/v1/token', { aud: audience });\n }\n\n /**\n * Get satellite tokens for multiple audiences in parallel.\n *\n * This is useful when making requests to endpoints owned by different users.\n * Tokens are cached and reused where possible.\n *\n * @param audiences - Array of unique audience identifiers (usernames)\n * @returns Map of audience to satellite token\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * // Get tokens for multiple endpoint owners\n * const tokens = await client.auth.getSatelliteTokens(['alice', 'bob']);\n * console.log(`Got ${tokens.size} tokens`);\n */\n async getSatelliteTokens(audiences: string[]): Promise<Map<string, string>> {\n const uniqueAudiences = [...new Set(audiences)];\n const tokenMap = new Map<string, string>();\n\n // Fetch tokens in parallel\n const results = await Promise.allSettled(\n uniqueAudiences.map(async (aud) => {\n const response = await this.getSatelliteToken(aud);\n return { audience: aud, token: response.targetToken };\n })\n );\n\n // Collect successful results; warn on failures so misconfigured IDPs are visible\n for (const [i, result] of results.entries()) {\n if (result.status === 'fulfilled') {\n tokenMap.set(result.value.audience, result.value.token);\n } else {\n console.warn(\n `[SyftHub] Failed to fetch satellite token for \"${uniqueAudiences[i]}\":`,\n result.reason\n );\n }\n }\n\n return tokenMap;\n }\n\n /**\n * Get a guest satellite token for a specific audience (target service).\n *\n * Guest tokens allow unauthenticated users to access policy-free endpoints.\n * No authentication is required to call this method.\n *\n * @param audience - Target service identifier (username of the service owner)\n * @returns Satellite token response with token and expiry\n * @throws {ValidationError} If audience is invalid or inactive\n *\n * @example\n * // Get a guest token for querying alice's policy-free endpoints\n * const tokenResponse = await client.auth.getGuestSatelliteToken('alice');\n */\n async getGuestSatelliteToken(audience: string): Promise<SatelliteTokenResponse> {\n return this.http.get<SatelliteTokenResponse>(\n '/api/v1/token/guest',\n { aud: audience },\n { includeAuth: false }\n );\n }\n\n /**\n * Get guest satellite tokens for multiple audiences in parallel.\n *\n * No authentication is required to call this method.\n *\n * @param audiences - Array of unique audience identifiers (usernames)\n * @returns Map of audience to satellite token\n *\n * @example\n * const tokens = await client.auth.getGuestSatelliteTokens(['alice', 'bob']);\n */\n async getGuestSatelliteTokens(audiences: string[]): Promise<Map<string, string>> {\n const uniqueAudiences = [...new Set(audiences)];\n const tokenMap = new Map<string, string>();\n\n const results = await Promise.allSettled(\n uniqueAudiences.map(async (aud) => {\n const response = await this.getGuestSatelliteToken(aud);\n return { audience: aud, token: response.targetToken };\n })\n );\n\n for (const result of results) {\n if (result.status === 'fulfilled') {\n tokenMap.set(result.value.audience, result.value.token);\n }\n }\n\n return tokenMap;\n }\n\n /**\n * Get transaction tokens for multiple endpoint owners.\n *\n * @deprecated Transaction tokens are no longer needed. Payments are handled\n * via the MPP 402 flow. This method is kept for backward compatibility and\n * always returns empty tokens/errors.\n *\n * @param ownerUsernames - Array of endpoint owner usernames (ignored)\n * @returns TransactionTokensResponse with empty tokens and errors\n */\n async getTransactionTokens(ownerUsernames: string[]): Promise<TransactionTokensResponse> {\n // Transaction tokens are no longer needed - payments are handled via MPP 402 flow\n void ownerUsernames;\n return { tokens: {}, errors: {} };\n }\n\n /**\n * Get the current access token (JWT or API token).\n *\n * This is used by the chat flow to pass the user's Hub token to the\n * aggregator for the MPP payment callback.\n *\n * @returns The current access token, or null if not authenticated\n */\n getAccessToken(): string | null {\n const tokens = this.http.getTokens();\n return tokens?.accessToken ?? null;\n }\n}\n\n/**\n * Response from peer token endpoint.\n */\nexport interface PeerTokenResponse {\n /** Short-lived token for NATS authentication */\n peerToken: string;\n /** Unique reply channel for receiving responses */\n peerChannel: string;\n /** Seconds until the token expires */\n expiresIn: number;\n /** NATS server URL for WebSocket connections */\n natsUrl: string;\n}\n\n/**\n * Response from satellite token endpoint.\n */\nexport interface SatelliteTokenResponse {\n /** RS256-signed JWT for the target service */\n targetToken: string;\n /** Seconds until the token expires */\n expiresIn: number;\n}\n\n// TransactionTokensResponse is imported from models/accounting.ts\nexport type { TransactionTokensResponse } from '../models/accounting.js';\n","import type { HTTPClient } from '../http.js';\nimport type {\n UserAggregator,\n UserAggregatorCreateInput,\n UserAggregatorUpdateInput,\n} from '../models/index.js';\n\n/**\n * Resource for managing user's aggregator configurations.\n *\n * Aggregators are custom RAG orchestration service endpoints that users can\n * configure to use for chat operations. Each user can have multiple aggregator\n * configurations, with one set as the default.\n *\n * The first aggregator created is automatically set as the default. Only one\n * aggregator can be the default at a time; setting a new default automatically\n * unsets the previous one.\n *\n * @example\n * // List all aggregators\n * const aggregators = await client.users.aggregators.list();\n * for (const agg of aggregators) {\n * console.log(`${agg.name}: ${agg.url}`);\n * }\n *\n * @example\n * // Create a new aggregator\n * const agg = await client.users.aggregators.create({\n * name: 'My Custom Aggregator',\n * url: 'https://my-aggregator.example.com'\n * });\n *\n * @example\n * // Set as default\n * const defaultAgg = await client.users.aggregators.setDefault(agg.id);\n */\nexport class AggregatorsResource {\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * List all aggregator configurations for the current user.\n *\n * @returns Array of UserAggregator objects\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * const aggregators = await client.users.aggregators.list();\n * for (const agg of aggregators) {\n * if (agg.isDefault) {\n * console.log(`Default: ${agg.name}`);\n * }\n * }\n */\n async list(): Promise<UserAggregator[]> {\n return this.http.get<UserAggregator[]>('/api/v1/users/me/aggregators');\n }\n\n /**\n * Get a specific aggregator configuration by ID.\n *\n * @param aggregatorId - The aggregator ID\n * @returns The UserAggregator object\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If aggregator not found\n *\n * @example\n * const agg = await client.users.aggregators.get(1);\n * console.log(`${agg.name}: ${agg.url}`);\n */\n async get(aggregatorId: number): Promise<UserAggregator> {\n return this.http.get<UserAggregator>(`/api/v1/users/me/aggregators/${aggregatorId}`);\n }\n\n /**\n * Create a new aggregator configuration.\n *\n * The first aggregator created is automatically set as the default.\n *\n * @param input - Aggregator creation input\n * @returns The created UserAggregator object\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If input is invalid\n *\n * @example\n * const agg = await client.users.aggregators.create({\n * name: 'My Custom Aggregator',\n * url: 'https://my-aggregator.example.com'\n * });\n * console.log(`Created: ${agg.id}`);\n */\n async create(input: UserAggregatorCreateInput): Promise<UserAggregator> {\n return this.http.post<UserAggregator>('/api/v1/users/me/aggregators', input);\n }\n\n /**\n * Update an aggregator configuration.\n *\n * Only provided fields will be updated.\n *\n * @param aggregatorId - The aggregator ID to update\n * @param input - Fields to update\n * @returns The updated UserAggregator object\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If aggregator not found\n * @throws {ValidationError} If input is invalid\n *\n * @example\n * const agg = await client.users.aggregators.update(1, {\n * name: 'Updated Name'\n * });\n */\n async update(aggregatorId: number, input: UserAggregatorUpdateInput): Promise<UserAggregator> {\n return this.http.put<UserAggregator>(`/api/v1/users/me/aggregators/${aggregatorId}`, input);\n }\n\n /**\n * Delete an aggregator configuration.\n *\n * @param aggregatorId - The aggregator ID to delete\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If aggregator not found\n *\n * @example\n * await client.users.aggregators.delete(1);\n */\n async delete(aggregatorId: number): Promise<void> {\n await this.http.delete<void>(`/api/v1/users/me/aggregators/${aggregatorId}`);\n }\n\n /**\n * Set an aggregator as the default.\n *\n * Only one aggregator can be the default at a time. Setting a new default\n * automatically unsets the previous one.\n *\n * @param aggregatorId - The aggregator ID to set as default\n * @returns The updated UserAggregator object with isDefault=true\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If aggregator not found\n *\n * @example\n * const agg = await client.users.aggregators.setDefault(2);\n * console.log(`${agg.name} is now the default`);\n */\n async setDefault(aggregatorId: number): Promise<UserAggregator> {\n return this.http.patch<UserAggregator>(`/api/v1/users/me/aggregators/${aggregatorId}/default`);\n }\n}\n","import type { HTTPClient } from '../http.js';\nimport type {\n AccountingCredentials,\n HeartbeatInput,\n HeartbeatResponse,\n User,\n UserUpdateInput,\n} from '../models/index.js';\nimport { AggregatorsResource } from './aggregators.js';\n\n/**\n * Users resource for profile management and availability checks.\n *\n * @example\n * // Update your profile\n * const user = await client.users.update({\n * fullName: 'Alice Smith',\n * avatarUrl: 'https://example.com/avatar.jpg'\n * });\n *\n * @example\n * // Check if username is available\n * const available = await client.users.checkUsername('newusername');\n *\n * @example\n * // Check if email is available\n * const available = await client.users.checkEmail('new@example.com');\n *\n * @example\n * // Manage aggregators\n * const aggregators = await client.users.aggregators.list();\n * const newAgg = await client.users.aggregators.create({\n * name: 'My Aggregator',\n * url: 'https://my-aggregator.example.com'\n * });\n */\nexport class UsersResource {\n private _aggregators?: AggregatorsResource;\n\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * Access aggregator management operations.\n *\n * @returns AggregatorsResource for managing user's aggregator configurations\n *\n * @example\n * // List aggregators\n * const aggregators = await client.users.aggregators.list();\n * for (const agg of aggregators) {\n * console.log(`${agg.name}: ${agg.url}`);\n * }\n *\n * // Create aggregator\n * const agg = await client.users.aggregators.create({\n * name: 'My Aggregator',\n * url: 'https://my-aggregator.example.com'\n * });\n *\n * // Set as default\n * await client.users.aggregators.setDefault(agg.id);\n */\n get aggregators(): AggregatorsResource {\n if (!this._aggregators) {\n this._aggregators = new AggregatorsResource(this.http);\n }\n return this._aggregators;\n }\n\n /**\n * Update the current user's profile.\n *\n * Only provided fields will be updated.\n *\n * @param input - Fields to update\n * @returns The updated User\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If input validation fails\n */\n async update(input: UserUpdateInput): Promise<User> {\n return this.http.put<User>('/api/v1/users/me', input);\n }\n\n /**\n * Check if a username is available.\n *\n * @param username - Username to check\n * @returns True if the username is available\n */\n async checkUsername(username: string): Promise<boolean> {\n const response = await this.http.get<{ available: boolean }>(\n `/api/v1/users/check-username/${encodeURIComponent(username)}`,\n undefined,\n { includeAuth: false }\n );\n return response.available;\n }\n\n /**\n * Check if an email is available.\n *\n * @param email - Email to check\n * @returns True if the email is available\n */\n async checkEmail(email: string): Promise<boolean> {\n const response = await this.http.get<{ available: boolean }>(\n `/api/v1/users/check-email/${encodeURIComponent(email)}`,\n undefined,\n { includeAuth: false }\n );\n return response.available;\n }\n\n /**\n * Get the current user's accounting service credentials.\n *\n * Returns credentials stored in SyftHub for connecting to an external\n * accounting service. The email is always the same as the user's SyftHub email.\n *\n * @returns Accounting credentials (url and password may be null if not configured)\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * const credentials = await client.users.getAccountingCredentials();\n * if (credentials.url && credentials.password) {\n * // Use credentials to connect to accounting service\n * }\n */\n async getAccountingCredentials(): Promise<AccountingCredentials> {\n return this.http.get<AccountingCredentials>('/api/v1/users/me/accounting');\n }\n\n /**\n * Send a heartbeat to indicate this SyftAI Space is alive.\n *\n * The heartbeat mechanism allows SyftAI Spaces to signal their availability\n * to SyftHub. This should be called periodically (before the TTL expires)\n * to maintain the \"active\" status.\n *\n * @param input - Heartbeat parameters\n * @param input.url - Full URL of this space (e.g., \"https://myspace.example.com\").\n * The server extracts the domain from this URL.\n * @param input.ttlSeconds - Time-to-live in seconds (1-3600). The server caps this\n * at a maximum of 600 seconds (10 minutes). Default is 300\n * seconds (5 minutes).\n * @returns HeartbeatResponse containing status, expiry time, domain, and effective TTL\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If URL or TTL is invalid\n *\n * @example\n * // Send heartbeat with default TTL (300 seconds)\n * const response = await client.users.sendHeartbeat({\n * url: 'https://myspace.example.com'\n * });\n * console.log(`Next heartbeat before: ${response.expiresAt}`);\n *\n * @example\n * // Send heartbeat with custom TTL\n * const response = await client.users.sendHeartbeat({\n * url: 'https://myspace.example.com',\n * ttlSeconds: 600 // Maximum allowed\n * });\n */\n async sendHeartbeat(input: HeartbeatInput): Promise<HeartbeatResponse> {\n const response = await this.http.post<{\n status: string;\n received_at: string;\n expires_at: string;\n domain: string;\n ttl_seconds: number;\n }>('/api/v1/users/me/heartbeat', {\n url: input.url,\n ttl_seconds: input.ttlSeconds ?? 300,\n });\n\n return {\n status: response.status,\n receivedAt: new Date(response.received_at),\n expiresAt: new Date(response.expires_at),\n domain: response.domain,\n ttlSeconds: response.ttl_seconds,\n };\n }\n}\n","/**\n * Function type for fetching a page of items.\n */\nexport type PageFetcher<T> = (skip: number, limit: number) => Promise<T[]>;\n\n/**\n * Lazy async iterator for paginated API responses.\n *\n * Fetches pages on demand as you iterate, minimizing API calls\n * and memory usage for large datasets.\n *\n * @example\n * // Iterate through all items\n * for await (const endpoint of client.hub.browse()) {\n * console.log(endpoint.name);\n * }\n *\n * @example\n * // Get just the first page\n * const firstPage = await client.hub.browse().firstPage();\n *\n * @example\n * // Get first 10 items\n * const top10 = await client.hub.browse().take(10);\n */\nexport class PageIterator<T> implements AsyncIterable<T> {\n private items: T[] = [];\n private index = 0;\n private skip = 0;\n private exhausted = false;\n private initialized = false;\n\n /**\n * Create a new PageIterator.\n *\n * @param fetcher - Function that fetches a page of items given skip and limit\n * @param pageSize - Number of items to fetch per page (default: 20)\n */\n constructor(\n private readonly fetcher: PageFetcher<T>,\n private readonly pageSize: number = 20\n ) {}\n\n /**\n * Async iterator implementation for `for await...of` loops.\n */\n async *[Symbol.asyncIterator](): AsyncIterator<T> {\n while (true) {\n // If we've consumed all items in the current page\n if (this.index >= this.items.length) {\n if (this.exhausted) break;\n await this.fetchNextPage();\n if (this.items.length === 0) break;\n }\n\n const item = this.items[this.index];\n if (item === undefined) break;\n\n this.index++;\n yield item;\n }\n }\n\n /**\n * Get just the first page of results.\n *\n * @returns Promise resolving to the first page of items\n */\n async firstPage(): Promise<T[]> {\n if (!this.initialized) {\n await this.fetchNextPage();\n }\n return [...this.items];\n }\n\n /**\n * Get all items across all pages.\n *\n * Warning: This loads all items into memory. For large datasets,\n * consider iterating with `for await...of` instead.\n *\n * @returns Promise resolving to all items\n */\n async all(): Promise<T[]> {\n const results: T[] = [];\n for await (const item of this) {\n results.push(item);\n }\n return results;\n }\n\n /**\n * Get the first N items.\n *\n * @param n - Maximum number of items to return\n * @returns Promise resolving to up to N items\n */\n async take(n: number): Promise<T[]> {\n const results: T[] = [];\n for await (const item of this) {\n results.push(item);\n if (results.length >= n) break;\n }\n return results;\n }\n\n /**\n * Fetch the next page of items from the API.\n */\n private async fetchNextPage(): Promise<void> {\n const page = await this.fetcher(this.skip, this.pageSize);\n this.items = page;\n this.index = 0;\n this.skip += this.pageSize;\n this.exhausted = page.length < this.pageSize;\n this.initialized = true;\n }\n}\n","import type { HTTPClient } from '../http.js';\nimport type {\n Endpoint,\n EndpointCreateInput,\n EndpointUpdateInput,\n SyncEndpointsResponse,\n Visibility,\n} from '../models/index.js';\nimport { PageIterator } from '../pagination.js';\n\n/**\n * Options for listing endpoints.\n */\nexport interface ListEndpointsOptions {\n /** Filter by visibility level */\n visibility?: Visibility;\n /** Number of items per page (default: 20) */\n pageSize?: number;\n}\n\n/**\n * My Endpoints resource for CRUD operations on user's own endpoints.\n *\n * For browsing public endpoints from other users, see the Hub resource.\n *\n * @example\n * // List your endpoints\n * for await (const endpoint of client.myEndpoints.list()) {\n * console.log(endpoint.name);\n * }\n *\n * @example\n * // Create a new endpoint\n * const endpoint = await client.myEndpoints.create({\n * name: 'My API',\n * type: 'model',\n * visibility: 'public',\n * description: 'A cool API'\n * });\n *\n * @example\n * // Get a specific endpoint\n * const endpoint = await client.myEndpoints.get('alice/my-api');\n *\n * @example\n * // Update an endpoint\n * const updated = await client.myEndpoints.update('alice/my-api', {\n * description: 'Updated description'\n * });\n *\n * @example\n * // Delete an endpoint\n * await client.myEndpoints.delete('alice/my-api');\n */\nexport class MyEndpointsResource {\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * Parse an endpoint path into owner and slug.\n *\n * @param path - Path in \"owner/slug\" format\n * @returns Tuple of [owner, slug]\n * @throws {Error} If path format is invalid\n */\n private parsePath(path: string): [string, string] {\n const parts = path.replace(/^\\/|\\/$/g, '').split('/');\n if (parts.length !== 2 || !parts[0] || !parts[1]) {\n throw new Error(`Invalid endpoint path: '${path}'. Expected format: 'owner/slug'`);\n }\n return [parts[0], parts[1]];\n }\n\n /**\n * List the current user's endpoints.\n *\n * @param options - Filtering and pagination options\n * @returns PageIterator that lazily fetches endpoints\n * @throws {AuthenticationError} If not authenticated\n */\n list(options?: ListEndpointsOptions): PageIterator<Endpoint> {\n const pageSize = options?.pageSize ?? 20;\n\n return new PageIterator<Endpoint>(async (skip, limit) => {\n const params: Record<string, unknown> = { skip, limit };\n if (options?.visibility) {\n params['visibility'] = options.visibility;\n }\n return this.http.get<Endpoint[]>('/api/v1/endpoints', params);\n }, pageSize);\n }\n\n /**\n * Create a new endpoint.\n *\n * @param input - Endpoint creation details\n * @returns The created Endpoint\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If input validation fails\n */\n async create(input: EndpointCreateInput): Promise<Endpoint> {\n return this.http.post<Endpoint>('/api/v1/endpoints', input);\n }\n\n /**\n * Get a specific endpoint by path.\n *\n * @param path - Endpoint path in \"owner/slug\" format (e.g., \"alice/my-api\")\n * @returns The Endpoint\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If endpoint not found\n * @throws {AuthorizationError} If not authorized to view\n */\n async get(path: string): Promise<Endpoint> {\n const [, slug] = this.parsePath(path);\n\n // Search user's own endpoints by slug\n // /api/v1/endpoints returns EndpointResponse with full details including id\n const endpoints = await this.http.get<Endpoint[]>('/api/v1/endpoints', { limit: 100 });\n\n for (const ep of endpoints) {\n if (ep.slug === slug) {\n return ep;\n }\n }\n\n // Import NotFoundError here to avoid circular dependency\n const { NotFoundError } = await import('../errors.js');\n throw new NotFoundError(\n `Endpoint not found: '${path}'. No endpoint found with slug '${slug}' in your endpoints.`\n );\n }\n\n /**\n * Update an endpoint.\n *\n * Only provided fields will be updated.\n *\n * @param path - Endpoint path in \"owner/slug\" format\n * @param input - Fields to update\n * @returns The updated Endpoint\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If endpoint not found\n * @throws {AuthorizationError} If not owner/admin\n */\n async update(path: string, input: EndpointUpdateInput): Promise<Endpoint> {\n const [, slug] = this.parsePath(path);\n // Use slug-based endpoint directly instead of resolving ID\n return this.http.patch<Endpoint>(`/api/v1/endpoints/slug/${slug}`, input);\n }\n\n /**\n * Delete an endpoint.\n *\n * @param path - Endpoint path in \"owner/slug\" format\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If endpoint not found\n * @throws {AuthorizationError} If not owner/admin\n */\n async delete(path: string): Promise<void> {\n const [, slug] = this.parsePath(path);\n // Use slug-based endpoint directly instead of resolving ID\n await this.http.delete<void>(`/api/v1/endpoints/slug/${slug}`);\n }\n\n /**\n * Synchronize user's endpoints with provided list.\n *\n * This is a DESTRUCTIVE operation that:\n * 1. Deletes ALL existing endpoints owned by the current user\n * 2. Creates ALL endpoints from the provided list\n * 3. Is ATOMIC: either all endpoints sync successfully, or none do\n *\n * Important Notes:\n * - Stars on existing endpoints will be lost (reset to 0)\n * - Endpoint IDs will change (new IDs assigned)\n * - Maximum 100 endpoints per sync request\n *\n * @param endpoints - List of endpoint specifications to sync.\n * Pass an empty array to delete ALL user endpoints.\n * @returns SyncEndpointsResponse with synced count, deleted count, and created endpoints\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If any endpoint fails validation (entire batch rejected)\n *\n * @example\n * // Sync with new endpoints\n * const result = await client.myEndpoints.sync([\n * { name: 'Model A', type: 'model', visibility: 'public' },\n * { name: 'Data Source B', type: 'data_source', visibility: 'private' },\n * ]);\n * console.log(`Deleted ${result.deleted}, created ${result.synced} endpoints`);\n *\n * @example\n * // Clear all endpoints\n * const result = await client.myEndpoints.sync([]);\n * console.log(`Deleted ${result.deleted} endpoints`);\n */\n async sync(endpoints: EndpointCreateInput[] = []): Promise<SyncEndpointsResponse> {\n return this.http.post<SyncEndpointsResponse>('/api/v1/endpoints/sync', { endpoints });\n }\n}\n","import type { HTTPClient } from '../http.js';\nimport type {\n EndpointPublic,\n EndpointSearchResult,\n EndpointSearchResponse,\n SearchOptions,\n} from '../models/index.js';\nimport { PageIterator } from '../pagination.js';\n\n/**\n * Options for browsing endpoints.\n */\nexport interface BrowseOptions {\n /** Filter by endpoint type ('model' or 'data_source') */\n endpointType?: string;\n /** Number of items per page (default: 20) */\n pageSize?: number;\n}\n\n/**\n * Options for trending endpoints.\n */\nexport interface TrendingOptions {\n /** Filter by endpoint type ('model' or 'data_source') */\n endpointType?: string;\n /** Minimum number of stars */\n minStars?: number;\n /** Number of items per page (default: 20) */\n pageSize?: number;\n}\n\n/**\n * Options for listing guest-accessible endpoints.\n */\nexport interface GuestAccessibleOptions {\n /** Filter by endpoint type ('model' or 'data_source') */\n endpointType?: string;\n /** Number of items per page (default: 20) */\n pageSize?: number;\n}\n\n/**\n * Hub resource for browsing and discovering public endpoints.\n *\n * For managing your own endpoints, see the MyEndpoints resource.\n *\n * @example\n * // Browse all public endpoints\n * for await (const endpoint of client.hub.browse()) {\n * console.log(`${endpoint.ownerUsername}/${endpoint.slug}: ${endpoint.name}`);\n * }\n *\n * @example\n * // Get trending endpoints\n * for await (const endpoint of client.hub.trending({ minStars: 10 })) {\n * console.log(`${endpoint.name} - ${endpoint.starsCount} stars`);\n * }\n *\n * @example\n * // Semantic search for endpoints\n * const results = await client.hub.search('machine learning for images');\n * for (const result of results) {\n * console.log(`${result.ownerUsername}/${result.slug}: ${result.relevanceScore.toFixed(2)}`);\n * }\n *\n * @example\n * // Get a specific endpoint\n * const endpoint = await client.hub.get('alice/cool-api');\n * console.log(endpoint.readme);\n *\n * @example\n * // Star an endpoint (requires auth)\n * await client.hub.star('alice/cool-api');\n *\n * @example\n * // Check if you've starred an endpoint\n * const starred = await client.hub.isStarred('alice/cool-api');\n */\nexport class HubResource {\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * Parse an endpoint path into owner and slug.\n *\n * @param path - Path in \"owner/slug\" format\n * @returns Tuple of [owner, slug]\n */\n private parsePath(path: string): [string, string] {\n const parts = path.replace(/^\\/|\\/$/g, '').split('/');\n if (parts.length !== 2 || !parts[0] || !parts[1]) {\n throw new Error(`Invalid endpoint path: '${path}'. Expected format: 'owner/slug'`);\n }\n return [parts[0], parts[1]];\n }\n\n /**\n * Resolve an endpoint path to its ID.\n *\n * This searches the user's own endpoints to find the ID.\n *\n * @param path - Endpoint path in \"owner/slug\" format\n * @returns The endpoint ID\n */\n private async resolveEndpointId(path: string): Promise<number> {\n const [, slug] = this.parsePath(path);\n\n // Search the user's endpoints to find the ID\n // This uses /api/v1/endpoints which returns full details including ID\n const endpoints = await this.http.get<Array<{ id?: number; slug?: string }>>(\n '/api/v1/endpoints',\n { limit: 100 }\n );\n\n for (const ep of endpoints) {\n if (ep.slug === slug && ep.id !== undefined) {\n return ep.id;\n }\n }\n\n // Import NotFoundError here to avoid circular dependency\n const { NotFoundError } = await import('../errors.js');\n throw new NotFoundError(\n `Could not resolve endpoint ID for '${path}'. ` +\n \"Endpoint not found or you don't have access to get its ID.\"\n );\n }\n\n /**\n * Browse all public endpoints.\n *\n * @param options - Filter and pagination options\n * @returns PageIterator that lazily fetches endpoints\n *\n * @example\n * // Browse only model endpoints\n * const models = await client.hub.browse({ endpointType: 'model' }).firstPage();\n */\n browse(options?: BrowseOptions): PageIterator<EndpointPublic> {\n const pageSize = options?.pageSize ?? 20;\n\n return new PageIterator<EndpointPublic>(async (skip, limit) => {\n const params: Record<string, unknown> = { skip, limit };\n if (options?.endpointType !== undefined) {\n params['endpoint_type'] = options.endpointType;\n }\n return this.http.get<EndpointPublic[]>('/api/v1/endpoints/public', params, {\n includeAuth: false,\n });\n }, pageSize);\n }\n\n /**\n * Get trending endpoints sorted by stars.\n *\n * @param options - Filter and pagination options\n * @returns PageIterator that lazily fetches endpoints\n *\n * @example\n * // Get trending models only\n * const models = await client.hub.trending({ endpointType: 'model' }).firstPage();\n */\n trending(options?: TrendingOptions): PageIterator<EndpointPublic> {\n const pageSize = options?.pageSize ?? 20;\n\n return new PageIterator<EndpointPublic>(async (skip, limit) => {\n const params: Record<string, unknown> = { skip, limit };\n if (options?.endpointType !== undefined) {\n params['endpoint_type'] = options.endpointType;\n }\n if (options?.minStars !== undefined) {\n params['min_stars'] = options.minStars;\n }\n return this.http.get<EndpointPublic[]>('/api/v1/endpoints/trending', params, {\n includeAuth: false,\n });\n }, pageSize);\n }\n\n /**\n * List endpoints accessible to unauthenticated (guest) users.\n *\n * Guest-accessible endpoints are public, active, and have no policies attached.\n * No authentication is required to call this method.\n *\n * @param options - Filter and pagination options\n * @returns PageIterator that lazily fetches guest-accessible endpoints\n *\n * @example\n * // List all guest-accessible endpoints\n * for await (const endpoint of client.hub.guestAccessible()) {\n * console.log(`${endpoint.ownerUsername}/${endpoint.slug}: ${endpoint.name}`);\n * }\n *\n * @example\n * // List only guest-accessible models\n * const models = await client.hub.guestAccessible({ endpointType: 'model' }).firstPage();\n */\n guestAccessible(options?: GuestAccessibleOptions): PageIterator<EndpointPublic> {\n const pageSize = options?.pageSize ?? 20;\n\n return new PageIterator<EndpointPublic>(async (skip, limit) => {\n const params: Record<string, unknown> = { skip, limit };\n if (options?.endpointType !== undefined) {\n params['endpoint_type'] = options.endpointType;\n }\n return this.http.get<EndpointPublic[]>('/api/v1/endpoints/guest-accessible', params, {\n includeAuth: false,\n });\n }, pageSize);\n }\n\n /**\n * Search for endpoints using semantic search.\n *\n * Uses RAG-powered semantic search to find endpoints that match the\n * natural language query. Returns results sorted by relevance score.\n *\n * Note: If RAG is not configured on the server (no OpenAI API key),\n * this method returns an empty array.\n *\n * @param query - Natural language search query (e.g., \"machine learning models for image classification\")\n * @param options - Search options (topK, type filter, minScore)\n * @returns Promise resolving to array of EndpointSearchResult with relevance scores.\n * Returns empty array if query is too short (<3 chars) or no matches found.\n *\n * @example\n * // Search for machine learning models\n * const results = await client.hub.search('image classification models');\n * for (const result of results) {\n * console.log(`${result.ownerUsername}/${result.slug}: ${result.relevanceScore.toFixed(2)}`);\n * }\n *\n * @example\n * // Filter by type and minimum score\n * const dataSources = await client.hub.search('customer data', {\n * type: EndpointType.DATA_SOURCE,\n * minScore: 0.5,\n * });\n */\n async search(query: string, options: SearchOptions = {}): Promise<EndpointSearchResult[]> {\n const { topK = 10, type, minScore = 0 } = options;\n\n // Skip search for very short queries\n if (!query || query.trim().length < 3) {\n return [];\n }\n\n const body: Record<string, unknown> = {\n query: query.trim(),\n top_k: topK,\n };\n\n if (type !== undefined) {\n body['type'] = type;\n }\n\n try {\n const response = await this.http.post<EndpointSearchResponse>(\n '/api/v1/endpoints/search',\n body,\n { includeAuth: false }\n );\n\n // Filter by minScore and return results\n return (response.results ?? []).filter((result) => result.relevanceScore >= minScore);\n } catch {\n // Return empty array on any error (e.g., RAG not configured)\n return [];\n }\n }\n\n /**\n * Get an endpoint by its path.\n *\n * This method searches the public endpoints API to find the endpoint,\n * which works reliably across all deployment configurations.\n *\n * @param path - Endpoint path in \"owner/slug\" format (e.g., \"alice/cool-api\")\n * @returns The EndpointPublic\n * @throws {NotFoundError} If endpoint not found\n */\n async get(path: string): Promise<EndpointPublic> {\n const [owner, slug] = this.parsePath(path);\n\n // Search public endpoints to find the matching one\n // This approach works because /api/v1/endpoints/public is reliably\n // served by the backend API, unlike /{owner}/{slug} which may be\n // intercepted by frontend routing in some deployments.\n for await (const endpoint of this.browse({ pageSize: 100 })) {\n if (endpoint.ownerUsername === owner && endpoint.slug === slug) {\n return endpoint;\n }\n }\n\n // Import NotFoundError here to avoid circular dependency\n const { NotFoundError } = await import('../errors.js');\n throw new NotFoundError(\n `Endpoint not found: '${path}'. No public endpoint found with owner '${owner}' and slug '${slug}'.`\n );\n }\n\n /**\n * Star an endpoint.\n *\n * @param path - Endpoint path in \"owner/slug\" format\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If endpoint not found\n */\n async star(path: string): Promise<void> {\n const endpointId = await this.resolveEndpointId(path);\n // Use POST method for starring (not PATCH)\n await this.http.post<void>(`/api/v1/endpoints/${endpointId}/star`);\n }\n\n /**\n * Unstar an endpoint.\n *\n * @param path - Endpoint path in \"owner/slug\" format\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If endpoint not found\n */\n async unstar(path: string): Promise<void> {\n const endpointId = await this.resolveEndpointId(path);\n // Use DELETE method to /star endpoint (not PATCH to /unstar)\n await this.http.delete<void>(`/api/v1/endpoints/${endpointId}/star`);\n }\n\n /**\n * Get the owner/slug paths of a collective's approved member endpoints,\n * optionally narrowed to a single shared-endpoint subset.\n *\n * Used by the chat resource to expand both `collective/<slug>` and\n * `collective/<slug>/<shared-slug>` data-source references into the\n * individual endpoint paths before building the aggregator request.\n *\n * @param slug - The collective slug (e.g. \"genomics-research\")\n * @param sharedSlug - Optional curated-subset slug. When provided, only the\n * intersection of the subset's configured endpoints with the collective's\n * currently approved members is returned. Omit for \"all approved members\".\n * @returns Array of \"owner/slug\" path strings\n * @throws {NotFoundError} If the collective (or shared endpoint) does not exist\n */\n async getCollectiveEndpointPaths(slug: string, sharedSlug?: string): Promise<string[]> {\n const base = `/api/v1/collectives/by-slug/${encodeURIComponent(slug)}`;\n const path = sharedSlug\n ? `${base}/shared-endpoints/${encodeURIComponent(sharedSlug)}/endpoint-paths`\n : `${base}/endpoint-paths`;\n return this.http.get<string[]>(path, {}, { includeAuth: false });\n }\n\n /**\n * Check if you have starred an endpoint.\n *\n * @param path - Endpoint path in \"owner/slug\" format\n * @returns True if starred, False otherwise\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If endpoint not found\n */\n async isStarred(path: string): Promise<boolean> {\n const endpointId = await this.resolveEndpointId(path);\n const response = await this.http.get<{ starred: boolean }>(\n `/api/v1/endpoints/${endpointId}/starred`\n );\n return response.starred ?? false;\n }\n}\n","/**\n * Accounting Resource for SyftHub SDK (MPP Wallet)\n *\n * This module provides wallet management operations via the SyftHub API.\n * Payments are handled through the MPP (Micropayment Protocol) 402 flow,\n * replacing the previous external accounting service with direct wallet support.\n *\n * @example\n * ```typescript\n * // Initialize via client (after login)\n * await client.auth.login('alice', 'password');\n * await client.initAccounting();\n *\n * // Get wallet info\n * const wallet = await client.accounting.getWallet();\n * console.log(`Wallet address: ${wallet.address}`);\n *\n * // Get balance\n * const balance = await client.accounting.getBalance();\n * console.log(`Balance: ${balance.balance} ${balance.currency}`);\n *\n * // Get transactions\n * const transactions = await client.accounting.getTransactions();\n * for (const tx of transactions) {\n * console.log(`${tx.created_at}: ${tx.amount} from ${tx.sender_email}`);\n * }\n * ```\n */\n\nimport type { HTTPClient } from '../http.js';\nimport type { WalletInfo, WalletBalance, WalletTransaction } from '../models/accounting.js';\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * Options for creating an AccountingResource.\n *\n * @deprecated The old AccountingResourceOptions with external service credentials\n * are no longer needed. Use the HTTPClient-based constructor instead.\n */\nexport interface AccountingResourceOptions {\n /** @deprecated No longer used - wallet API is accessed via SyftHub */\n url: string;\n /** @deprecated No longer used */\n email: string;\n /** @deprecated No longer used */\n password: string;\n /** @deprecated No longer used */\n timeout?: number;\n}\n\n/**\n * Options for listing transactions.\n *\n * @deprecated Use getTransactions() which returns all transactions directly.\n */\nexport interface TransactionsOptions {\n /** Number of items per page (default: 20) */\n pageSize?: number;\n}\n\n// =============================================================================\n// AccountingResource\n// =============================================================================\n\n/**\n * Wallet and payment operations via the SyftHub API.\n *\n * Manages MPP (Micropayment Protocol) wallets for users. Payments for\n * endpoint usage are handled automatically via the 402 payment flow\n * between the aggregator and SyftAI-Space instances.\n *\n * @example\n * ```typescript\n * // Get wallet info\n * const wallet = await client.accounting.getWallet();\n * if (!wallet.exists) {\n * // Create a new wallet\n * const result = await client.accounting.createWallet();\n * console.log(`Created wallet: ${result.address}`);\n * }\n *\n * // Check balance\n * const balance = await client.accounting.getBalance();\n * console.log(`Balance: ${balance.balance} ${balance.currency}`);\n * ```\n */\nexport class AccountingResource {\n constructor(private readonly http: HTTPClient) {}\n\n // ===========================================================================\n // Wallet Operations\n // ===========================================================================\n\n /**\n * Get the current user's wallet information.\n *\n * @returns WalletInfo with address and existence status\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * ```typescript\n * const wallet = await client.accounting.getWallet();\n * if (wallet.exists) {\n * console.log(`Wallet address: ${wallet.address}`);\n * } else {\n * console.log('No wallet configured');\n * }\n * ```\n */\n async getWallet(): Promise<WalletInfo> {\n return this.http.get<WalletInfo>('/api/v1/wallet/');\n }\n\n /**\n * Get the current user's wallet balance and recent transactions.\n *\n * @returns WalletBalance with balance, currency, and recent transactions\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * ```typescript\n * const balance = await client.accounting.getBalance();\n * console.log(`Balance: ${balance.balance} ${balance.currency}`);\n * console.log(`Wallet configured: ${balance.wallet_configured}`);\n * ```\n */\n async getBalance(): Promise<WalletBalance> {\n return this.http.get<WalletBalance>('/api/v1/wallet/balance');\n }\n\n /**\n * Get the current user's wallet transactions.\n *\n * @returns Array of WalletTransaction objects\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * ```typescript\n * const transactions = await client.accounting.getTransactions();\n * for (const tx of transactions) {\n * console.log(`${tx.created_at}: ${tx.amount} ${tx.status}`);\n * }\n * ```\n */\n async getTransactions(): Promise<WalletTransaction[]> {\n return this.http.get<WalletTransaction[]>('/api/v1/wallet/transactions');\n }\n\n /**\n * Create a new wallet for the current user.\n *\n * Generates a new wallet with a fresh keypair. The wallet address\n * is returned and stored on the server.\n *\n * @returns Object with the new wallet address\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If user already has a wallet\n *\n * @example\n * ```typescript\n * const result = await client.accounting.createWallet();\n * console.log(`New wallet address: ${result.address}`);\n * ```\n */\n async createWallet(): Promise<{ address: string }> {\n return this.http.post<{ address: string }>('/api/v1/wallet/create', {});\n }\n\n /**\n * Import an existing wallet using a private key.\n *\n * @param privateKey - The private key to import\n * @returns Object with the imported wallet address\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If the private key is invalid\n *\n * @example\n * ```typescript\n * const result = await client.accounting.importWallet('0x...');\n * console.log(`Imported wallet address: ${result.address}`);\n * ```\n */\n async importWallet(privateKey: string): Promise<{ address: string }> {\n return this.http.post<{ address: string }>('/api/v1/wallet/import', {\n private_key: privateKey,\n });\n }\n}\n\n// =============================================================================\n// Factory Function\n// =============================================================================\n\n/**\n * Create a new AccountingResource instance.\n *\n * @deprecated Use the SyftHubClient's built-in accounting resource instead.\n * The wallet API is now accessed through the SyftHub HTTP client, not\n * a separate external service.\n *\n * @param options - Configuration options (ignored, kept for backward compatibility)\n * @returns AccountingResource instance\n */\nexport function createAccountingResource(options: AccountingResourceOptions): AccountingResource {\n void options;\n throw new Error(\n 'createAccountingResource() is deprecated. ' +\n 'The wallet API is now accessed through the SyftHubClient. ' +\n 'Use client.initAccounting() after login instead.'\n );\n}\n","/**\n * Agent resource for bidirectional agent sessions via WebSocket.\n *\n * @example\n * const session = await client.agent.startSession({\n * prompt: 'Help me refactor this code',\n * endpoint: 'alice/code-assistant',\n * });\n *\n * for await (const event of session.events()) {\n * switch (event.type) {\n * case 'agent.message':\n * console.log(event.payload.content);\n * break;\n * case 'agent.tool_call':\n * if (event.payload.requires_confirmation) {\n * await session.confirm(event.payload.tool_call_id);\n * }\n * break;\n * }\n * }\n */\n\nimport { SyftHubError } from '../errors.js';\nimport type { AgentEvent, AgentSessionOptions, AgentSessionState } from '../models/agent.js';\nimport type { AuthResource } from './auth.js';\n\n/**\n * Error thrown during agent session operations.\n */\nexport class AgentSessionError extends SyftHubError {\n constructor(\n message: string,\n public readonly code?: string\n ) {\n super(message);\n this.name = 'AgentSessionError';\n }\n}\n\n/**\n * AgentResource manages agent session lifecycle.\n */\nexport class AgentResource {\n constructor(\n private readonly auth: AuthResource,\n private readonly aggregatorUrl: string\n ) {}\n\n /**\n * Start a new agent session.\n *\n * @param options - Session options including prompt, endpoint, and config\n * @returns An AgentSessionClient for interacting with the session\n */\n async startSession(options: AgentSessionOptions): Promise<AgentSessionClient> {\n // Parse endpoint\n let owner: string;\n let slug: string;\n if (typeof options.endpoint === 'string') {\n const parts = options.endpoint.split('/');\n if (parts.length !== 2) {\n throw new AgentSessionError(\n `Endpoint must be in 'owner/slug' format, got: ${options.endpoint}`\n );\n }\n owner = parts[0]!;\n slug = parts[1]!;\n } else {\n owner = options.endpoint.owner;\n slug = options.endpoint.slug;\n }\n\n // Fetch satellite token\n const satResponse = await this.auth.getSatelliteToken(owner);\n\n // Fetch peer token for tunneling\n const peerResponse = await this.auth.getPeerToken([owner]);\n\n // Build WebSocket URL\n const wsUrl = this.aggregatorUrl.replace(/^http/, 'ws') + '/agent/session';\n\n // Create WebSocket\n const ws = new WebSocket(wsUrl);\n\n // Wait for connection\n await new Promise<void>((resolve, reject) => {\n const onOpen = () => {\n ws.removeEventListener('error', onError);\n resolve();\n };\n const onError = (_e: Event) => {\n ws.removeEventListener('open', onOpen);\n reject(new AgentSessionError('Failed to connect to agent WebSocket'));\n };\n ws.addEventListener('open', onOpen, { once: true });\n ws.addEventListener('error', onError, { once: true });\n\n // Handle abort signal\n if (options.signal) {\n options.signal.addEventListener(\n 'abort',\n () => {\n ws.close();\n reject(new AgentSessionError('Session start aborted'));\n },\n { once: true }\n );\n }\n });\n\n // Send session.start\n const startPayload: Record<string, unknown> = {\n prompt: options.prompt,\n endpoint: { owner, slug },\n satellite_token: satResponse.targetToken,\n peer_token: peerResponse.peerToken,\n peer_channel: peerResponse.peerChannel,\n };\n if (options.config) {\n startPayload.config = options.config;\n }\n if (options.messages) {\n startPayload.messages = options.messages;\n }\n\n ws.send(\n JSON.stringify({\n type: 'session.start',\n payload: startPayload,\n })\n );\n\n // Wait for session.created response\n const response = await new Promise<{ session_id: string }>((resolve, reject) => {\n const onMessage = (event: MessageEvent) => {\n try {\n const data = JSON.parse(event.data as string);\n if (data.type === 'session.created') {\n ws.removeEventListener('message', onMessage);\n resolve({\n session_id: data.session_id || data.payload?.session_id,\n });\n } else if (data.type === 'agent.error') {\n ws.removeEventListener('message', onMessage);\n reject(\n new AgentSessionError(\n data.payload?.message || 'Session start failed',\n data.payload?.code\n )\n );\n }\n } catch {\n reject(new AgentSessionError('Failed to parse session response'));\n }\n };\n ws.addEventListener('message', onMessage);\n });\n\n return new AgentSessionClient(ws, response.session_id);\n }\n}\n\n/**\n * Client for an active agent session.\n * Provides both async iterable and callback-based APIs for receiving events.\n */\nexport class AgentSessionClient {\n private _state: AgentSessionState = 'running';\n private _sequenceCounter = 0;\n private _messageQueue: AgentEvent[] = [];\n private _messageResolvers: Array<(value: AgentEvent | null) => void> = [];\n private _closed = false;\n\n constructor(\n private readonly ws: WebSocket,\n public readonly sessionId: string\n ) {\n this.ws.addEventListener('message', (event: MessageEvent) => {\n this._handleMessage(event);\n });\n this.ws.addEventListener('close', () => {\n this._handleClose();\n });\n this.ws.addEventListener('error', () => {\n this._state = 'error';\n this._handleClose();\n });\n }\n\n /** Current session state */\n get state(): AgentSessionState {\n return this._state;\n }\n\n /**\n * Async generator yielding agent events.\n *\n * @example\n * for await (const event of session.events()) {\n * console.log(event.type, event.payload);\n * }\n */\n async *events(): AsyncGenerator<AgentEvent> {\n while (!this._closed) {\n const event = await this._nextEvent();\n if (event === null) break;\n yield event;\n }\n }\n\n /**\n * Register an event handler.\n *\n * @param eventType - The event type to listen for, or '*' for all events\n * @param handler - Callback function\n */\n on(eventType: string, handler: (event: AgentEvent) => void): void {\n this.ws.addEventListener('message', (msgEvent: MessageEvent) => {\n try {\n const data = JSON.parse(msgEvent.data as string) as AgentEvent;\n if (eventType === '*' || data.type === eventType) {\n handler(data);\n }\n } catch {\n // Ignore parse errors\n }\n });\n }\n\n /** Send a user message to the agent */\n sendMessage(content: string): void {\n this._send({\n type: 'user.message',\n payload: { content },\n });\n }\n\n /** Confirm a tool call */\n confirm(toolCallId: string): void {\n this._send({\n type: 'user.confirm',\n payload: { tool_call_id: toolCallId },\n });\n }\n\n /** Deny a tool call */\n deny(toolCallId: string, reason?: string): void {\n this._send({\n type: 'user.deny',\n payload: { tool_call_id: toolCallId, reason },\n });\n }\n\n /** Cancel the session */\n cancel(): void {\n this._state = 'cancelled';\n this._send({ type: 'user.cancel' });\n }\n\n /** Close the session and WebSocket */\n close(): void {\n if (this._closed) return;\n this._send({ type: 'session.close' });\n this.ws.close();\n this._handleClose();\n }\n\n // ---- Internal ----\n\n private _send(msg: Record<string, unknown>): void {\n if (this.ws.readyState === WebSocket.OPEN) {\n this.ws.send(JSON.stringify(msg));\n }\n }\n\n private _handleMessage(event: MessageEvent): void {\n try {\n const data = JSON.parse(event.data as string) as AgentEvent & {\n session_id?: string;\n sequence?: number;\n };\n this._sequenceCounter++;\n\n // Update state based on event type\n switch (data.type) {\n case 'agent.request_input':\n this._state = 'awaiting_input';\n break;\n case 'session.completed':\n this._state = 'completed';\n break;\n case 'session.failed':\n this._state = 'failed';\n break;\n case 'agent.error':\n if (!(data as { payload: { recoverable: boolean } }).payload.recoverable) {\n this._state = 'error';\n }\n break;\n default:\n if (this._state === 'awaiting_input' || this._state === 'connecting') {\n this._state = 'running';\n }\n }\n\n // Deliver to async generator or queue\n if (this._messageResolvers.length > 0) {\n const resolve = this._messageResolvers.shift()!;\n resolve(data);\n } else {\n this._messageQueue.push(data);\n }\n\n // Handle terminal states\n if (data.type === 'session.completed' || data.type === 'session.failed') {\n this._handleClose();\n }\n } catch {\n // Ignore parse errors\n }\n }\n\n private _handleClose(): void {\n if (this._closed) return;\n this._closed = true;\n\n // Resolve all pending waiters with null\n for (const resolve of this._messageResolvers) {\n resolve(null);\n }\n this._messageResolvers = [];\n }\n\n private _nextEvent(): Promise<AgentEvent | null> {\n // Return queued event if available\n if (this._messageQueue.length > 0) {\n return Promise.resolve(this._messageQueue.shift()!);\n }\n\n // If closed, return null\n if (this._closed) {\n return Promise.resolve(null);\n }\n\n // Wait for next event\n return new Promise<AgentEvent | null>((resolve) => {\n this._messageResolvers.push(resolve);\n });\n }\n}\n","/**\n * Chat resource for RAG-augmented conversations via the Aggregator service.\n *\n * This resource handles satellite token authentication automatically:\n * - Resolves endpoints and extracts owner information\n * - Exchanges Hub access tokens for satellite tokens (one per unique owner)\n * - Sends tokens to the aggregator for forwarding to SyftAI-Space\n *\n * @example\n * // Simple chat completion\n * const response = await client.chat.complete({\n * prompt: 'What is machine learning?',\n * model: 'alice/gpt-model',\n * dataSources: ['bob/ml-docs'],\n * });\n * console.log(response.response);\n *\n * // Streaming chat\n * for await (const event of client.chat.stream(options)) {\n * if (event.type === 'token') {\n * process.stdout.write(event.content);\n * }\n * }\n */\n\nimport type { EndpointPublic } from '../models/index.js';\nimport type {\n ChatMetadata,\n ChatOptions,\n ChatResponse,\n ChatStreamEvent,\n DocumentSource,\n EndpointRef,\n Message,\n SourceInfo,\n SourceStatus,\n TokenUsage,\n} from '../models/chat.js';\nimport { SyftHubError } from '../errors.js';\nimport { readSSEEvents } from '../utils.js';\nimport type { HubResource } from './hub.js';\nimport type { AuthResource } from './auth.js';\nimport { EndpointType } from '../models/index.js';\n\n/**\n * Error thrown when the aggregator service is unavailable or returns an error.\n */\nexport class AggregatorError extends SyftHubError {\n constructor(\n message: string,\n public readonly status?: number,\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'AggregatorError';\n }\n}\n\n/**\n * Error thrown when an endpoint cannot be resolved.\n */\nexport class EndpointResolutionError extends SyftHubError {\n constructor(\n message: string,\n public readonly endpointPath?: string\n ) {\n super(message);\n this.name = 'EndpointResolutionError';\n }\n}\n\n/**\n * Chat resource for RAG-augmented conversations via the Aggregator.\n *\n * This resource provides high-level chat functionality that:\n * - Queries data sources for relevant context (retrieval)\n * - Sends prompts with context to model endpoints (generation)\n * - Supports both synchronous and streaming responses\n */\nexport class ChatResource {\n constructor(\n private readonly hub: HubResource,\n private readonly auth: AuthResource,\n private readonly aggregatorUrl: string\n ) {}\n\n /**\n * Check if an endpoint type matches the expected type.\n * A model_data_source endpoint matches both 'model' and 'data_source'.\n */\n private static typeMatches(actualType: string, expectedType: string): boolean {\n if (actualType === expectedType) return true;\n if (actualType === EndpointType.MODEL_DATA_SOURCE) {\n return expectedType === EndpointType.MODEL || expectedType === EndpointType.DATA_SOURCE;\n }\n // Agent endpoints can be used where model endpoints are expected\n if (actualType === EndpointType.AGENT && expectedType === EndpointType.MODEL) {\n return true;\n }\n return false;\n }\n\n /**\n * Convert any endpoint format to EndpointRef with URL and owner info.\n * The ownerUsername is critical for satellite token authentication.\n */\n private async resolveEndpointRef(\n endpoint: string | EndpointRef | EndpointPublic,\n expectedType?: 'model' | 'data_source'\n ): Promise<EndpointRef> {\n // Already an EndpointRef\n if (this.isEndpointRef(endpoint)) {\n return endpoint;\n }\n\n // EndpointPublic object\n if (this.isEndpointPublic(endpoint)) {\n // Validate type if expected (model_data_source matches both model and data_source)\n if (expectedType && !ChatResource.typeMatches(endpoint.type, expectedType)) {\n throw new Error(\n `Expected endpoint type '${expectedType}', got '${endpoint.type}' for '${endpoint.slug}'`\n );\n }\n\n // Find first enabled connection with URL\n for (const conn of endpoint.connect) {\n if (conn.enabled && conn.config['url']) {\n return {\n url: String(conn.config['url']),\n slug: endpoint.slug,\n name: endpoint.name,\n tenantName: conn.config['tenant_name'] as string | undefined,\n ownerUsername: endpoint.ownerUsername, // Capture owner for satellite token\n };\n }\n }\n\n throw new EndpointResolutionError(\n `Endpoint '${endpoint.slug}' has no connection with URL configured`,\n `${endpoint.ownerUsername}/${endpoint.slug}`\n );\n }\n\n // String path format \"owner/slug\"\n if (typeof endpoint === 'string') {\n let ep: EndpointPublic;\n try {\n ep = await this.hub.get(endpoint);\n } catch (error) {\n throw new EndpointResolutionError(\n `Failed to fetch endpoint '${endpoint}': ${error instanceof Error ? error.message : String(error)}`,\n endpoint\n );\n }\n return this.resolveEndpointRef(ep, expectedType);\n }\n\n throw new TypeError(`Cannot resolve endpoint from type: ${typeof endpoint}`);\n }\n\n /**\n * Collect unique owner usernames from all endpoints.\n * Used to determine which satellite tokens need to be fetched.\n */\n private collectUniqueOwners(modelRef: EndpointRef, dataSourceRefs: EndpointRef[]): string[] {\n const owners = new Set<string>();\n\n if (modelRef.ownerUsername) {\n owners.add(modelRef.ownerUsername);\n }\n\n for (const ds of dataSourceRefs) {\n if (ds.ownerUsername) {\n owners.add(ds.ownerUsername);\n }\n }\n\n return [...owners];\n }\n\n /**\n * Get satellite tokens for all unique endpoint owners.\n * Returns a map of owner username to satellite token.\n *\n * @param owners - Array of unique owner usernames\n * @param guestMode - If true, fetch guest tokens (no auth required)\n */\n private async getSatelliteTokensForOwners(\n owners: string[],\n guestMode = false\n ): Promise<Record<string, string>> {\n if (owners.length === 0) {\n return {};\n }\n\n const tokenMap = guestMode\n ? await this.auth.getGuestSatelliteTokens(owners)\n : await this.auth.getSatelliteTokens(owners);\n const result: Record<string, string> = {};\n\n for (const [owner, token] of tokenMap) {\n result[owner] = token;\n }\n\n return result;\n }\n\n /**\n * Get the user's Hub access token for MPP payment flow.\n * Returns null if in guest mode or not authenticated.\n */\n private getUserToken(): string | null {\n return this.auth.getAccessToken();\n }\n\n /**\n * Type guard for EndpointRef.\n */\n private isEndpointRef(value: unknown): value is EndpointRef {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'url' in value &&\n 'slug' in value &&\n typeof (value as EndpointRef).url === 'string' &&\n typeof (value as EndpointRef).slug === 'string'\n );\n }\n\n /**\n * Type guard for EndpointPublic.\n */\n private isEndpointPublic(value: unknown): value is EndpointPublic {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'connect' in value &&\n 'ownerUsername' in value &&\n Array.isArray((value as EndpointPublic).connect)\n );\n }\n\n private static readonly COLLECTIVE_PREFIX = 'collective/';\n private static readonly TUNNELING_PREFIX = 'tunneling:';\n\n /**\n * Expand any `collective/<slug>` (or `collective/<slug>/<shared-slug>`)\n * entries in the data-sources list into the individual `owner/slug` paths\n * of the collective's approved members.\n *\n * Path forms recognised:\n * - `collective/<slug>` → every approved member (backward-compatible)\n * - `collective/<slug>/all` → equivalent alias of the above\n * - `collective/<slug>/<shared-slug>` → the named subset, intersected with\n * the collective's currently approved members\n *\n * Non-collective entries pass through unchanged. String paths are\n * deduplicated so a regular endpoint that also belongs to a selected\n * collective is not queried twice.\n */\n private async expandCollectivePaths(\n dataSources: (string | EndpointRef | EndpointPublic)[]\n ): Promise<(string | EndpointRef | EndpointPublic)[]> {\n const expanded: (string | EndpointRef | EndpointPublic)[] = [];\n const seenPaths = new Set<string>();\n\n for (const ds of dataSources) {\n if (typeof ds === 'string' && ds.startsWith(ChatResource.COLLECTIVE_PREFIX)) {\n const rest = ds.slice(ChatResource.COLLECTIVE_PREFIX.length);\n const slashAt = rest.indexOf('/');\n const collectiveSlug = slashAt < 0 ? rest : rest.slice(0, slashAt);\n // `all` is the implicit alias of \"every approved member\" and maps to\n // the same hub route as the no-subset form, so the SDK normalises it\n // away rather than round-tripping a degenerate identifier.\n const rawShared = slashAt < 0 ? undefined : rest.slice(slashAt + 1);\n const sharedSlug = rawShared && rawShared !== 'all' ? rawShared : undefined;\n\n if (!collectiveSlug) {\n throw new EndpointResolutionError(`Malformed collective path: ${ds}`, ds);\n }\n\n let memberPaths: string[];\n try {\n memberPaths = await this.hub.getCollectiveEndpointPaths(collectiveSlug, sharedSlug);\n } catch (error) {\n const target = sharedSlug ? `${collectiveSlug}/${sharedSlug}` : collectiveSlug;\n throw new EndpointResolutionError(\n `Failed to resolve collective '${target}': ${error instanceof Error ? error.message : String(error)}`,\n ds\n );\n }\n for (const path of memberPaths) {\n if (!seenPaths.has(path)) {\n seenPaths.add(path);\n expanded.push(path);\n }\n }\n } else if (typeof ds === 'string') {\n if (!seenPaths.has(ds)) {\n seenPaths.add(ds);\n expanded.push(ds);\n }\n } else {\n // EndpointRef or EndpointPublic — pass through without dedup\n expanded.push(ds);\n }\n }\n\n return expanded;\n }\n\n /**\n * Check if any endpoints use tunneling URLs and extract target usernames.\n */\n private collectTunnelingUsernames(\n modelRef: EndpointRef,\n dataSourceRefs: EndpointRef[]\n ): string[] {\n const usernames = new Set<string>();\n\n if (modelRef.url.startsWith(ChatResource.TUNNELING_PREFIX)) {\n usernames.add(modelRef.url.slice(ChatResource.TUNNELING_PREFIX.length));\n }\n\n for (const ds of dataSourceRefs) {\n if (ds.url.startsWith(ChatResource.TUNNELING_PREFIX)) {\n usernames.add(ds.url.slice(ChatResource.TUNNELING_PREFIX.length));\n }\n }\n\n return [...usernames];\n }\n\n /**\n * Shared request preparation for complete() and stream().\n * Resolves endpoints, fetches tokens, and builds the aggregator request body.\n * Returns the request body and the resolved aggregator URL.\n */\n private async prepareRequest(\n options: ChatOptions,\n stream: boolean\n ): Promise<{ requestBody: Record<string, unknown>; effectiveAggregatorUrl: string }> {\n const modelRef = await this.resolveEndpointRef(options.model, 'model');\n\n // Expand any collective/<slug> paths into their approved member endpoint paths.\n const expandedDataSources = await this.expandCollectivePaths(options.dataSources ?? []);\n\n const dsRefs: EndpointRef[] = [];\n for (const ds of expandedDataSources) {\n dsRefs.push(await this.resolveEndpointRef(ds, 'data_source'));\n }\n\n const uniqueOwners = this.collectUniqueOwners(modelRef, dsRefs);\n const guestMode = options.guestMode ?? false;\n const endpointTokens = await this.getSatelliteTokensForOwners(uniqueOwners, guestMode);\n const userToken = guestMode ? null : this.getUserToken();\n\n let peerToken = options.peerToken;\n let peerChannel = options.peerChannel;\n if (!peerToken) {\n const tunnelingUsernames = this.collectTunnelingUsernames(modelRef, dsRefs);\n if (tunnelingUsernames.length > 0) {\n const peerResponse = guestMode\n ? await this.auth.getGuestPeerToken(tunnelingUsernames)\n : await this.auth.getPeerToken(tunnelingUsernames);\n peerToken = peerResponse.peerToken;\n peerChannel = peerResponse.peerChannel;\n }\n }\n\n const requestBody = this.buildRequestBody(\n options.prompt,\n modelRef,\n dsRefs,\n endpointTokens,\n userToken,\n {\n topK: options.topK,\n maxTokens: options.maxTokens,\n temperature: options.temperature,\n similarityThreshold: options.similarityThreshold,\n stream,\n messages: options.messages,\n peerToken,\n peerChannel,\n }\n );\n\n const effectiveAggregatorUrl = (options.aggregatorUrl ?? this.aggregatorUrl).replace(\n /\\/+$/,\n ''\n );\n\n return { requestBody, effectiveAggregatorUrl };\n }\n\n /**\n * Parse an error response from the aggregator into an AggregatorError.\n */\n private async handleAggregatorErrorResponse(response: Response): Promise<never> {\n let message = `HTTP ${response.status}`;\n try {\n const data = (await response.json()) as Record<string, unknown>;\n message = String(data['message'] ?? data['error'] ?? message);\n } catch {\n // Use default message\n }\n throw new AggregatorError(`Aggregator error: ${message}`, response.status);\n }\n\n /**\n * Build the request body for the aggregator.\n * Includes endpoint_tokens mapping for satellite token authentication.\n * Includes user_token for MPP payment callback authorization.\n * User identity is derived from satellite tokens, not passed in request body.\n */\n private buildRequestBody(\n prompt: string,\n modelRef: EndpointRef,\n dataSourceRefs: EndpointRef[],\n endpointTokens: Record<string, string>,\n userToken: string | null,\n options: {\n topK?: number;\n maxTokens?: number;\n temperature?: number;\n similarityThreshold?: number;\n stream?: boolean;\n messages?: Message[];\n peerToken?: string;\n peerChannel?: string;\n }\n ): Record<string, unknown> {\n const body: Record<string, unknown> = {\n prompt,\n model: {\n url: modelRef.url,\n slug: modelRef.slug,\n name: modelRef.name ?? '',\n tenant_name: modelRef.tenantName ?? null,\n owner_username: modelRef.ownerUsername ?? null,\n },\n data_sources: dataSourceRefs.map((ds) => ({\n url: ds.url,\n slug: ds.slug,\n name: ds.name ?? '',\n tenant_name: ds.tenantName ?? null,\n owner_username: ds.ownerUsername ?? null,\n })),\n endpoint_tokens: endpointTokens,\n top_k: options.topK ?? 5,\n max_tokens: options.maxTokens ?? 1024,\n temperature: options.temperature ?? 0.7,\n similarity_threshold: options.similarityThreshold ?? 0.5,\n stream: options.stream ?? false,\n };\n\n // Include user token for MPP payment flow\n if (userToken) {\n body['user_token'] = userToken;\n }\n\n if (options.messages && options.messages.length > 0) {\n body.messages = options.messages.map((m) => ({ role: m.role, content: m.content }));\n }\n\n // Include peer token fields for NATS tunneling\n if (options.peerToken) {\n body['peer_token'] = options.peerToken;\n }\n if (options.peerChannel) {\n body['peer_channel'] = options.peerChannel;\n }\n\n return body;\n }\n\n /**\n * Parse a SourceInfo from raw data.\n */\n private parseSourceInfo(data: Record<string, unknown>): SourceInfo {\n return {\n path: String(data['path'] ?? ''),\n documentsRetrieved: Number(data['documents_retrieved'] ?? 0),\n status: (data['status'] as SourceStatus) ?? 'success',\n errorMessage: data['error_message'] as string | undefined,\n };\n }\n\n /**\n * Parse ChatMetadata from raw data.\n */\n private parseMetadata(data: Record<string, unknown>): ChatMetadata {\n return {\n retrievalTimeMs: Number(data['retrieval_time_ms'] ?? 0),\n generationTimeMs: Number(data['generation_time_ms'] ?? 0),\n totalTimeMs: Number(data['total_time_ms'] ?? 0),\n };\n }\n\n /**\n * Parse TokenUsage from raw data.\n */\n private parseUsage(data: Record<string, unknown>): TokenUsage {\n return {\n promptTokens: Number(data['prompt_tokens'] ?? 0),\n completionTokens: Number(data['completion_tokens'] ?? 0),\n totalTokens: Number(data['total_tokens'] ?? 0),\n };\n }\n\n /**\n * Parse document sources from raw data.\n * The new format is a dict mapping document title to {slug, content}.\n */\n private parseDocumentSources(\n data: Record<string, unknown> | undefined\n ): Record<string, DocumentSource> {\n const sources: Record<string, DocumentSource> = {};\n if (!data || typeof data !== 'object') {\n return sources;\n }\n\n for (const [title, value] of Object.entries(data)) {\n if (value && typeof value === 'object') {\n const source = value as Record<string, unknown>;\n sources[title] = {\n slug: String(source['slug'] ?? ''),\n content: String(source['content'] ?? ''),\n };\n }\n }\n return sources;\n }\n\n /**\n * Parse retrieval info (SourceInfo array) from raw data.\n */\n private parseRetrievalInfo(data: Record<string, unknown>[] | undefined): SourceInfo[] {\n const retrievalInfo: SourceInfo[] = [];\n if (!Array.isArray(data)) {\n return retrievalInfo;\n }\n\n for (const item of data) {\n retrievalInfo.push(this.parseSourceInfo(item));\n }\n return retrievalInfo;\n }\n\n /**\n * Send a chat request and get the complete response.\n *\n * This method automatically:\n * 1. Resolves endpoints and extracts owner information\n * 2. Exchanges Hub tokens for satellite tokens (one per unique owner)\n * 3. Passes the user's Hub access token for MPP payment authorization\n * 4. Sends tokens to the aggregator for forwarding to SyftAI-Space\n *\n * @param options - Chat completion options\n * @returns ChatResponse with response text, sources, and metadata\n * @throws {EndpointResolutionError} If endpoint cannot be resolved\n * @throws {AggregatorError} If aggregator service fails\n */\n async complete(options: ChatOptions): Promise<ChatResponse> {\n const { requestBody, effectiveAggregatorUrl } = await this.prepareRequest(options, false);\n\n const response = await fetch(`${effectiveAggregatorUrl}/chat`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(requestBody),\n });\n\n if (!response.ok) {\n return this.handleAggregatorErrorResponse(response);\n }\n\n const data = (await response.json()) as Record<string, unknown>;\n\n // Parse document sources (new format: dict of title -> {slug, content})\n const sourcesData = data['sources'] as Record<string, unknown> | undefined;\n const sources = this.parseDocumentSources(sourcesData);\n\n // Parse retrieval info (metadata about each data source retrieval)\n const retrievalInfoData = data['retrieval_info'] as Record<string, unknown>[] | undefined;\n const retrievalInfo = this.parseRetrievalInfo(retrievalInfoData);\n\n const metadataData = data['metadata'] as Record<string, unknown> | undefined;\n const metadata = this.parseMetadata(metadataData ?? {});\n\n // Parse usage if available\n const usageData = data['usage'] as Record<string, unknown> | undefined;\n const usage = usageData ? this.parseUsage(usageData) : undefined;\n\n // Parse profit share if available\n const profitShare = data['profit_share'] as Record<string, number> | undefined;\n\n return {\n response: String(data['response'] ?? ''),\n sources,\n retrievalInfo,\n metadata,\n usage,\n profitShare,\n };\n }\n\n /**\n * Send a chat request and stream response events.\n *\n * This method automatically:\n * 1. Resolves endpoints and extracts owner information\n * 2. Exchanges Hub tokens for satellite tokens (one per unique owner)\n * 3. Passes the user's Hub access token for MPP payment authorization\n * 4. Sends tokens to the aggregator for forwarding to SyftAI-Space\n *\n * @param options - Chat completion options\n * @yields ChatStreamEvent objects as they arrive\n */\n async *stream(options: ChatOptions): AsyncGenerator<ChatStreamEvent, void, unknown> {\n const { requestBody, effectiveAggregatorUrl } = await this.prepareRequest(options, true);\n\n const response = await fetch(`${effectiveAggregatorUrl}/chat/stream`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Accept: 'text/event-stream',\n },\n body: JSON.stringify(requestBody),\n signal: options.signal,\n });\n\n if (!response.ok) {\n return this.handleAggregatorErrorResponse(response);\n }\n\n if (!response.body) {\n throw new AggregatorError('No response body from aggregator');\n }\n\n for await (const { event: eventName, data: dataStr } of readSSEEvents(response)) {\n if (eventName === 'message') continue; // chat protocol always names events\n try {\n const data = JSON.parse(dataStr) as Record<string, unknown>;\n const event = this.parseSSEEvent(eventName, data);\n if (event) {\n yield event;\n }\n } catch {\n yield { type: 'error', message: `Failed to parse SSE data: ${dataStr}` };\n }\n }\n }\n\n /**\n * Parse an SSE event into a typed event object.\n */\n private parseSSEEvent(eventType: string, data: Record<string, unknown>): ChatStreamEvent | null {\n switch (eventType) {\n case 'retrieval_start':\n return {\n type: 'retrieval_start',\n sourceCount: Number(data['sources'] ?? 0),\n };\n\n case 'source_complete':\n return {\n type: 'source_complete',\n path: String(data['path'] ?? ''),\n status: String(data['status'] ?? ''),\n documentsRetrieved: Number(data['documents'] ?? 0),\n };\n\n case 'retrieval_complete':\n return {\n type: 'retrieval_complete',\n totalDocuments: Number(data['total_documents'] ?? 0),\n timeMs: Number(data['time_ms'] ?? 0),\n };\n\n case 'reranking_start':\n return {\n type: 'reranking_start',\n documents: Number(data['documents'] ?? 0),\n };\n\n case 'reranking_complete':\n return {\n type: 'reranking_complete',\n documents: Number(data['documents'] ?? 0),\n timeMs: Number(data['time_ms'] ?? 0),\n };\n\n case 'generation_start':\n return { type: 'generation_start' };\n\n case 'generation_heartbeat':\n return {\n type: 'generation_heartbeat',\n elapsedMs: Number(data['elapsed_ms'] ?? 0),\n };\n\n case 'token':\n return {\n type: 'token',\n content: String(data['content'] ?? ''),\n };\n\n case 'done': {\n // Parse document sources (new format: dict of title -> {slug, content})\n const sourcesData = data['sources'] as Record<string, unknown> | undefined;\n const sources = this.parseDocumentSources(sourcesData);\n\n // Parse retrieval info (metadata about each data source retrieval)\n const retrievalInfoData = data['retrieval_info'] as Record<string, unknown>[] | undefined;\n const retrievalInfo = this.parseRetrievalInfo(retrievalInfoData);\n\n const metadataData = data['metadata'] as Record<string, unknown> | undefined;\n const metadata = this.parseMetadata(metadataData ?? {});\n\n // Parse usage if available (only from non-streaming mode)\n const usageData = data['usage'] as Record<string, unknown> | undefined;\n const usage = usageData ? this.parseUsage(usageData) : undefined;\n\n // Parse profit share if available\n const profitShare = data['profit_share'] as Record<string, number> | undefined;\n\n // Parse clean response (cite-tag-stripped) if attribution ran\n const response = data['response'] as string | undefined;\n\n return { type: 'done', sources, retrievalInfo, metadata, usage, profitShare, response };\n }\n\n case 'error':\n return {\n type: 'error',\n message: String(data['message'] ?? 'Unknown error'),\n };\n\n default:\n console.warn(`[SyftHub] Unknown SSE event type received from aggregator: ${eventType}`);\n return {\n type: 'error',\n message: `Unknown event type: ${eventType}`,\n };\n }\n }\n\n private async getAvailableEndpoints(\n endpointType: EndpointType,\n limit: number\n ): Promise<EndpointPublic[]> {\n const results: EndpointPublic[] = [];\n\n for await (const endpoint of this.hub.browse()) {\n if (results.length >= limit) break;\n if (endpoint.type !== endpointType) continue;\n if (endpoint.connect.some((conn) => conn.enabled && conn.config['url'])) {\n results.push(endpoint);\n }\n }\n\n return results;\n }\n\n /**\n * Get model endpoints that have connection URLs configured.\n *\n * @param limit - Maximum number of results (default: 20)\n * @returns Array of EndpointPublic objects for models with URLs\n */\n async getAvailableModels(limit = 20): Promise<EndpointPublic[]> {\n return this.getAvailableEndpoints(EndpointType.MODEL, limit);\n }\n\n /**\n * Get data source endpoints that have connection URLs configured.\n *\n * @param limit - Maximum number of results (default: 20)\n * @returns Array of EndpointPublic objects for data sources with URLs\n */\n async getAvailableDataSources(limit = 20): Promise<EndpointPublic[]> {\n return this.getAvailableEndpoints(EndpointType.DATA_SOURCE, limit);\n }\n}\n","/**\n * Visibility levels for endpoints.\n */\nexport const Visibility = {\n /** Visible to everyone, no authentication required */\n PUBLIC: 'public',\n /** Only visible to the owner and collaborators */\n PRIVATE: 'private',\n /** Behaves like private — only visible to the owner */\n INTERNAL: 'internal',\n} as const;\n\nexport type Visibility = (typeof Visibility)[keyof typeof Visibility];\n\n/**\n * Types of endpoints.\n */\nexport const EndpointType = {\n /** Machine learning model endpoint */\n MODEL: 'model',\n /** Data source endpoint */\n DATA_SOURCE: 'data_source',\n /** Both model and data source endpoint */\n MODEL_DATA_SOURCE: 'model_data_source',\n /** Agent endpoint with session-based interaction */\n AGENT: 'agent',\n} as const;\n\nexport type EndpointType = (typeof EndpointType)[keyof typeof EndpointType];\n\n/**\n * User roles in the system.\n */\nexport const UserRole = {\n /** Administrator with full access */\n ADMIN: 'admin',\n /** Regular user */\n USER: 'user',\n /** Guest user with limited access */\n GUEST: 'guest',\n} as const;\n\nexport type UserRole = (typeof UserRole)[keyof typeof UserRole];\n","import type { EndpointType, Visibility } from './common.js';\n\n/**\n * Policy configuration for an endpoint.\n */\nexport interface Policy {\n readonly type: string;\n readonly version: string;\n readonly enabled: boolean;\n readonly description: string;\n readonly config: Record<string, unknown>;\n}\n\n/**\n * Connection configuration for an endpoint.\n */\nexport interface Connection {\n readonly type: string;\n readonly enabled: boolean;\n readonly description: string;\n readonly config: Record<string, unknown>;\n}\n\n/**\n * Full endpoint model (for authenticated users viewing their own endpoints).\n */\nexport interface Endpoint {\n readonly id: number;\n readonly userId: number;\n readonly name: string;\n readonly slug: string;\n readonly description: string;\n readonly type: EndpointType;\n readonly visibility: Visibility;\n readonly isActive: boolean;\n readonly contributors: readonly number[];\n readonly version: string;\n readonly readme: string;\n readonly tags: readonly string[];\n readonly starsCount: number;\n readonly policies: readonly Policy[];\n readonly connect: readonly Connection[];\n readonly createdAt: Date;\n readonly updatedAt: Date;\n}\n\n/**\n * Public endpoint model (for browsing the hub).\n */\nexport interface EndpointPublic {\n readonly name: string;\n readonly slug: string;\n readonly description: string;\n readonly type: EndpointType;\n readonly ownerUsername: string;\n /** Number of contributors (user IDs not exposed for privacy) */\n readonly contributorsCount: number;\n readonly version: string;\n readonly readme: string;\n readonly tags: readonly string[];\n readonly starsCount: number;\n readonly policies: readonly Policy[];\n readonly connect: readonly Connection[];\n readonly createdAt: Date;\n readonly updatedAt: Date;\n}\n\n/**\n * Search result with relevance score from semantic search.\n *\n * Extends the public endpoint fields with a relevance score indicating\n * how well the endpoint matches the search query.\n */\nexport interface EndpointSearchResult {\n readonly name: string;\n readonly slug: string;\n readonly description: string;\n readonly type: EndpointType;\n readonly ownerUsername: string;\n /** Number of contributors (user IDs not exposed for privacy) */\n readonly contributorsCount: number;\n readonly version: string;\n readonly readme: string;\n readonly tags: readonly string[];\n readonly starsCount: number;\n readonly policies: readonly Policy[];\n readonly connect: readonly Connection[];\n readonly createdAt: Date;\n readonly updatedAt: Date;\n /** Relevance score from semantic search (0.0-1.0) */\n readonly relevanceScore: number;\n}\n\n/**\n * Response from the endpoint search API.\n */\nexport interface EndpointSearchResponse {\n readonly results: readonly EndpointSearchResult[];\n readonly total: number;\n readonly query: string;\n}\n\n/**\n * Options for semantic search.\n */\nexport interface SearchOptions {\n /** Maximum number of results to return (default: 10) */\n topK?: number;\n /** Filter by endpoint type */\n type?: EndpointType;\n /** Minimum relevance score threshold (0.0-1.0, default: 0.0) */\n minScore?: number;\n}\n\n/**\n * Get the full path for a search result (owner/slug format).\n *\n * @param result - The search result\n * @returns The path in \"owner/slug\" format\n */\nexport function getSearchResultPath(result: EndpointSearchResult): string {\n return `${result.ownerUsername}/${result.slug}`;\n}\n\n/**\n * Input for creating a new endpoint.\n */\nexport interface EndpointCreateInput {\n name: string;\n type: EndpointType;\n visibility?: Visibility;\n description?: string;\n slug?: string;\n version?: string;\n readme?: string;\n tags?: string[];\n policies?: Policy[];\n connect?: Connection[];\n contributors?: number[];\n}\n\n/**\n * Input for updating an existing endpoint.\n */\nexport interface EndpointUpdateInput {\n name?: string;\n description?: string;\n visibility?: Visibility;\n version?: string;\n readme?: string;\n tags?: string[];\n policies?: Policy[];\n connect?: Connection[];\n contributors?: number[];\n}\n\n/**\n * Get the full path for a public endpoint (owner/slug format).\n *\n * @param endpoint - The public endpoint\n * @returns The path in \"owner/slug\" format\n */\nexport function getEndpointPublicPath(endpoint: EndpointPublic): string {\n return `${endpoint.ownerUsername}/${endpoint.slug}`;\n}\n\n/**\n * Response from the sync endpoints operation.\n *\n * Contains details about the sync operation including how many endpoints\n * were deleted, how many were created, and the full list of created endpoints.\n */\nexport interface SyncEndpointsResponse {\n /** Number of endpoints created */\n readonly synced: number;\n /** Number of endpoints deleted */\n readonly deleted: number;\n /** List of created endpoints with full details */\n readonly endpoints: readonly Endpoint[];\n}\n","/**\n * SyftAI-Space resource for direct endpoint queries.\n *\n * This module provides low-level access to SyftAI-Space endpoints, allowing\n * users to build custom RAG pipelines or bypass the aggregator service.\n *\n * @example\n * // Query a data source directly\n * const docs = await client.syftai.queryDataSource({\n * endpoint: { url: 'http://syftai:8080', slug: 'docs' },\n * query: 'What is machine learning?',\n * userEmail: 'alice@example.com',\n * });\n *\n * // Query a model directly\n * const response = await client.syftai.queryModel({\n * endpoint: { url: 'http://syftai:8080', slug: 'gpt-model' },\n * messages: [\n * { role: 'system', content: 'You are a helpful assistant.' },\n * { role: 'user', content: 'Hello!' },\n * ],\n * userEmail: 'alice@example.com',\n * });\n */\n\nimport type { Document, QueryDataSourceOptions, QueryModelOptions } from '../models/chat.js';\nimport { SyftHubError } from '../errors.js';\nimport { readSSEEvents } from '../utils.js';\n\n/**\n * Error thrown when data source retrieval fails.\n */\nexport class RetrievalError extends SyftHubError {\n constructor(\n message: string,\n public readonly sourcePath?: string,\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'RetrievalError';\n }\n}\n\n/**\n * Error thrown when model generation fails.\n */\nexport class GenerationError extends SyftHubError {\n constructor(\n message: string,\n public readonly modelSlug?: string,\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'GenerationError';\n }\n}\n\n/**\n * Low-level resource for direct SyftAI-Space endpoint queries.\n *\n * This resource provides direct access to SyftAI-Space endpoints without\n * going through the aggregator. Use this when you need:\n * - Custom RAG pipelines with specific retrieval strategies\n * - Direct model queries without data source context\n * - Fine-grained control over the query process\n *\n * For most use cases, prefer the higher-level `client.chat` API instead.\n */\nexport class SyftAIResource {\n // No dependencies - uses direct fetch to SyftAI-Space endpoints\n\n /**\n * Build headers for SyftAI-Space request.\n */\n private buildHeaders(tenantName?: string): Record<string, string> {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n if (tenantName) {\n headers['X-Tenant-Name'] = tenantName;\n }\n return headers;\n }\n\n /**\n * Query a data source endpoint directly.\n *\n * @param options - Query options\n * @returns Array of Document objects\n * @throws {RetrievalError} If the query fails\n */\n async queryDataSource(options: QueryDataSourceOptions): Promise<Document[]> {\n const { endpoint, query, userEmail, topK = 5, similarityThreshold = 0.5 } = options;\n\n const url = `${endpoint.url.replace(/\\/$/, '')}/api/v1/endpoints/${endpoint.slug}/query`;\n\n const requestBody = {\n user_email: userEmail,\n messages: query, // SyftAI-Space expects \"messages\" for query text\n limit: topK,\n similarity_threshold: similarityThreshold,\n };\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: 'POST',\n headers: this.buildHeaders(endpoint.tenantName),\n body: JSON.stringify(requestBody),\n });\n } catch (error) {\n throw new RetrievalError(\n `Failed to connect to data source '${endpoint.slug}': ${error instanceof Error ? error.message : String(error)}`,\n endpoint.slug,\n error\n );\n }\n\n if (!response.ok) {\n let message = `HTTP ${response.status}`;\n try {\n const data = (await response.json()) as Record<string, unknown>;\n message = String(data['detail'] ?? data['message'] ?? message);\n } catch {\n // Use default message\n }\n throw new RetrievalError(`Data source query failed: ${message}`, endpoint.slug);\n }\n\n const data = (await response.json()) as Record<string, unknown>;\n const documents: Document[] = [];\n\n const docsData = data['documents'] as Record<string, unknown>[] | undefined;\n if (Array.isArray(docsData)) {\n for (const doc of docsData) {\n documents.push({\n content: String(doc['content'] ?? ''),\n score: Number(doc['score'] ?? 0),\n metadata: (doc['metadata'] as Record<string, unknown>) ?? {},\n });\n }\n }\n\n return documents;\n }\n\n /**\n * Query a model endpoint directly.\n *\n * @param options - Query options\n * @returns Generated response text\n * @throws {GenerationError} If generation fails\n */\n async queryModel(options: QueryModelOptions): Promise<string> {\n const { endpoint, messages, userEmail, maxTokens = 1024, temperature = 0.7 } = options;\n\n const url = `${endpoint.url.replace(/\\/$/, '')}/api/v1/endpoints/${endpoint.slug}/query`;\n\n const requestBody = {\n user_email: userEmail,\n messages: messages.map((msg) => ({\n role: msg.role,\n content: msg.content,\n })),\n max_tokens: maxTokens,\n temperature,\n stream: false,\n };\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: 'POST',\n headers: this.buildHeaders(endpoint.tenantName),\n body: JSON.stringify(requestBody),\n });\n } catch (error) {\n throw new GenerationError(\n `Failed to connect to model '${endpoint.slug}': ${error instanceof Error ? error.message : String(error)}`,\n endpoint.slug,\n error\n );\n }\n\n if (!response.ok) {\n let message = `HTTP ${response.status}`;\n try {\n const data = (await response.json()) as Record<string, unknown>;\n message = String(data['detail'] ?? data['message'] ?? message);\n } catch {\n // Use default message\n }\n throw new GenerationError(`Model query failed: ${message}`, endpoint.slug);\n }\n\n const data = (await response.json()) as Record<string, unknown>;\n const messageData = data['message'] as Record<string, unknown> | undefined;\n return String(messageData?.['content'] ?? '');\n }\n\n /**\n * Stream a model response directly.\n *\n * @param options - Query options\n * @yields Response text chunks as they arrive\n * @throws {GenerationError} If generation fails\n */\n async *queryModelStream(options: QueryModelOptions): AsyncGenerator<string, void, unknown> {\n const { endpoint, messages, userEmail, maxTokens = 1024, temperature = 0.7 } = options;\n\n const url = `${endpoint.url.replace(/\\/$/, '')}/api/v1/endpoints/${endpoint.slug}/query`;\n\n const requestBody = {\n user_email: userEmail,\n messages: messages.map((msg) => ({\n role: msg.role,\n content: msg.content,\n })),\n max_tokens: maxTokens,\n temperature,\n stream: true,\n };\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: 'POST',\n headers: {\n ...this.buildHeaders(endpoint.tenantName),\n Accept: 'text/event-stream',\n },\n body: JSON.stringify(requestBody),\n });\n } catch (error) {\n throw new GenerationError(\n `Failed to connect to model '${endpoint.slug}': ${error instanceof Error ? error.message : String(error)}`,\n endpoint.slug,\n error\n );\n }\n\n if (!response.ok) {\n let message = `HTTP ${response.status}`;\n try {\n const data = (await response.json()) as Record<string, unknown>;\n message = String(data['detail'] ?? data['message'] ?? message);\n } catch {\n // Use default message\n }\n throw new GenerationError(`Model stream failed: ${message}`, endpoint.slug);\n }\n\n if (!response.body) {\n throw new GenerationError('No response body from model', endpoint.slug);\n }\n\n for await (const { data: dataStr } of readSSEEvents(response)) {\n if (dataStr === '[DONE]') return;\n\n try {\n const data = JSON.parse(dataStr) as Record<string, unknown>;\n\n // Extract content from various response formats\n if (typeof data['content'] === 'string') {\n yield data['content'];\n } else if (Array.isArray(data['choices'])) {\n // OpenAI-style response\n for (const choice of data['choices'] as Record<string, unknown>[]) {\n const delta = choice['delta'] as Record<string, unknown> | undefined;\n if (delta && typeof delta['content'] === 'string') {\n yield delta['content'];\n }\n }\n }\n } catch {\n // Skip malformed data\n }\n }\n }\n}\n","/**\n * SyftHub TypeScript SDK\n *\n * A TypeScript client library for the SyftHub API.\n *\n * @example\n * import { SyftHubClient, EndpointType, Visibility } from '@syfthub/sdk';\n *\n * const client = new SyftHubClient({ baseUrl: 'https://hub.syft.com' });\n *\n * // Login\n * const user = await client.auth.login('alice', 'password');\n *\n * // Create an endpoint\n * const endpoint = await client.myEndpoints.create({\n * name: 'My Model',\n * type: EndpointType.MODEL,\n * visibility: Visibility.PUBLIC,\n * });\n *\n * // Browse the hub\n * for await (const ep of client.hub.browse()) {\n * console.log(ep.name);\n * }\n *\n * // Chat with RAG via aggregator\n * const response = await client.chat.complete({\n * prompt: 'What is machine learning?',\n * model: 'alice/gpt-model',\n * dataSources: ['bob/ml-docs'],\n * });\n * console.log(response.response);\n *\n * // Streaming chat\n * for await (const event of client.chat.stream(options)) {\n * if (event.type === 'token') {\n * process.stdout.write(event.content);\n * }\n * }\n *\n * @packageDocumentation\n */\n\n// Main client\nexport { SyftHubClient } from './client.js';\nexport type { SyftHubClientOptions } from './client.js';\n\n// HTTP types (for advanced usage)\nexport type { AuthTokens } from './http.js';\n\n// Errors\nexport {\n SyftHubError,\n APIError,\n AuthenticationError,\n AuthorizationError,\n NotFoundError,\n ValidationError,\n NetworkError,\n ConfigurationError,\n // User registration errors\n UserAlreadyExistsError,\n // Accounting-related errors\n AccountingAccountExistsError,\n InvalidAccountingPasswordError,\n AccountingServiceUnavailableError,\n} from './errors.js';\n\n// Chat-specific errors\nexport { AggregatorError, EndpointResolutionError } from './resources/chat.js';\nexport { RetrievalError, GenerationError } from './resources/syftai.js';\n\n// Pagination\nexport { PageIterator } from './pagination.js';\nexport type { PageFetcher } from './pagination.js';\n\n// Models - Enums and constants\nexport { Visibility, EndpointType, UserRole } from './models/index.js';\n\n// Models - Types\nexport type {\n // User types\n User,\n UserRegisterInput,\n UserUpdateInput,\n PasswordChangeInput,\n RegisterResult,\n VerifyOTPInput,\n PasswordResetRequestInput,\n PasswordResetConfirmInput,\n AuthConfig,\n AccountingCredentials,\n HeartbeatInput,\n HeartbeatResponse,\n UserAggregator,\n UserAggregatorCreateInput,\n UserAggregatorUpdateInput,\n // Endpoint types\n Policy,\n Connection,\n Endpoint,\n EndpointPublic,\n EndpointCreateInput,\n EndpointUpdateInput,\n SyncEndpointsResponse,\n // API Token types\n APIToken,\n APITokenScope,\n APITokenCreateResponse,\n CreateAPITokenInput,\n UpdateAPITokenInput,\n APITokenListResponse,\n // Wallet types\n WalletInfo,\n WalletBalance,\n WalletTransaction,\n TransactionTokensResponse,\n // Chat types\n EndpointRef,\n Document,\n DocumentSource,\n SourceStatus,\n SourceInfo,\n ChatMetadata,\n ChatResponse,\n Message,\n ChatOptions,\n QueryDataSourceOptions,\n QueryModelOptions,\n // Chat streaming events\n ChatStreamEvent,\n RetrievalStartEvent,\n SourceCompleteEvent,\n RetrievalCompleteEvent,\n GenerationStartEvent,\n TokenEvent,\n DoneEvent,\n ErrorEvent,\n} from './models/index.js';\n\n// Model helpers\nexport { getEndpointPublicPath } from './models/index.js';\n\n// Accounting Resource (MPP wallet operations)\nexport { AccountingResource, createAccountingResource } from './resources/accounting.js';\nexport type { AccountingResourceOptions, TransactionsOptions } from './resources/accounting.js';\n\n// Agent Resource and types\nexport { AgentResource, AgentSessionClient, AgentSessionError } from './resources/agent.js';\nexport type {\n AgentEvent,\n AgentSessionState,\n AgentSessionOptions,\n AgentConfig,\n AgentHistoryMessage,\n ThinkingEvent as AgentThinkingEvent,\n ToolCallEvent as AgentToolCallEvent,\n ToolResultEvent as AgentToolResultEvent,\n AgentMessageEvent,\n TokenEvent as AgentTokenEvent,\n StatusEvent as AgentStatusEvent,\n RequestInputEvent as AgentRequestInputEvent,\n SessionCreatedEvent as AgentSessionCreatedEvent,\n SessionCompletedEvent as AgentSessionCompletedEvent,\n SessionFailedEvent as AgentSessionFailedEvent,\n AgentErrorEvent,\n} from './models/agent.js';\n\n// Chat Resource (for type hints)\nexport { ChatResource } from './resources/chat.js';\n\n// SyftAI Resource (for type hints)\nexport { SyftAIResource } from './resources/syftai.js';\n\n// API Tokens Resource (for type hints)\nexport { APITokensResource } from './resources/api-tokens.js';\n\n// Aggregators Resource (for type hints)\nexport { AggregatorsResource } from './resources/aggregators.js';\n\n// Resource option types (for type-safe usage)\nexport type { ListEndpointsOptions } from './resources/my-endpoints.js';\nexport type { BrowseOptions, TrendingOptions } from './resources/hub.js';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/utils.ts","../src/client.ts","../src/resources/api-tokens.ts","../src/resources/aggregators.ts","../src/resources/auth.ts","../src/resources/users.ts","../src/pagination.ts","../src/resources/my-endpoints.ts","../src/resources/hub.ts","../src/resources/accounting.ts","../src/resources/agent.ts","../src/resources/chat.ts","../src/models/common.ts","../src/models/endpoint.ts","../src/resources/search.ts","../src/resources/syftai.ts","../src/index.ts"],"names":["NotFoundError","data"],"mappings":";;;;;;;;;;;AAAA,IAAA,cAAA,GAAA,EAAA;AAAA,QAAA,CAAA,cAAA,EAAA;AAAA,EAAA,QAAA,EAAA,MAAA,QAAA;AAAA,EAAA,4BAAA,EAAA,MAAA,4BAAA;AAAA,EAA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;AAC7B,IAAA,OAAO,IAAA,CAAK,KAAK,eAAA,EAAgB;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,SAAA,GAA+B;AAC7B,IAAA,OAAO,IAAA,CAAK,KAAK,SAAA,EAAU;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,UAAU,MAAA,EAA0B;AAClC,IAAA,IAAA,CAAK,IAAA,CAAK,SAAA,CAAU,MAAA,CAAO,WAAA,EAAa,OAAO,YAAY,CAAA;AAAA,EAC7D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,eAAA,GAA2B;AAC7B,IAAA,OAAO,IAAA,CAAK,KAAK,SAAA,EAAU;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,IAAI,uBAAA,GAAmC;AACrC,IAAA,OAAO,IAAA,CAAK,WAAA,KAAgB,MAAA,IAAa,IAAA,CAAK,WAAA,KAAgB,IAAA;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,KAAA,GAAc;AAAA,EAGd;AACF;;;AehbA,WAAA,EAAA","file":"index.js","sourcesContent":["/**\n * Base error class for all SyftHub SDK errors.\n */\nexport class SyftHubError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SyftHubError';\n // Maintains proper stack trace for where error was thrown (V8 engines)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n}\n\n/**\n * Error thrown when an API request fails with an error status code.\n */\nexport class APIError extends SyftHubError {\n constructor(\n message: string,\n public readonly status: number,\n public readonly data?: unknown\n ) {\n super(message);\n this.name = 'APIError';\n }\n}\n\n/**\n * Error thrown when authentication is required but not provided,\n * or when credentials are invalid (HTTP 401).\n */\nexport class AuthenticationError extends SyftHubError {\n constructor(message: string = 'Authentication required') {\n super(message);\n this.name = 'AuthenticationError';\n }\n}\n\n/**\n * Error thrown when the user doesn't have permission to access\n * a resource (HTTP 403).\n */\nexport class AuthorizationError extends SyftHubError {\n constructor(message: string = 'Permission denied') {\n super(message);\n this.name = 'AuthorizationError';\n }\n}\n\n/**\n * Error thrown when a requested resource is not found (HTTP 404).\n */\nexport class NotFoundError extends SyftHubError {\n constructor(message: string = 'Resource not found') {\n super(message);\n this.name = 'NotFoundError';\n }\n}\n\n/**\n * Error thrown when request validation fails (HTTP 422).\n * Contains field-level error details when available.\n */\nexport class ValidationError extends SyftHubError {\n constructor(\n message: string,\n public readonly errors?: Record<string, string[]>\n ) {\n super(message);\n this.name = 'ValidationError';\n }\n}\n\n/**\n * Error thrown when a network request fails (connection errors, timeouts).\n */\nexport class NetworkError extends SyftHubError {\n constructor(\n message: string = 'Network request failed',\n public readonly cause?: Error\n ) {\n super(message);\n this.name = 'NetworkError';\n }\n}\n\n/**\n * Error thrown when SDK configuration is invalid.\n */\nexport class ConfigurationError extends SyftHubError {\n constructor(message: string = 'Invalid SDK configuration') {\n super(message);\n this.name = 'ConfigurationError';\n }\n}\n\n// =============================================================================\n// User Registration Errors\n// =============================================================================\n\n/**\n * Error thrown when username or email already exists in SyftHub (HTTP 409).\n *\n * This error indicates a duplicate user registration attempt.\n * The `field` property indicates which field caused the conflict.\n *\n * @example\n * ```typescript\n * try {\n * await client.auth.register({ username: \"john\", email: \"john@example.com\", ... });\n * } catch (error) {\n * if (error instanceof UserAlreadyExistsError) {\n * console.log(`${error.field} is already taken`);\n * }\n * }\n * ```\n */\nexport class UserAlreadyExistsError extends SyftHubError {\n /** The field that caused the conflict (\"username\" or \"email\") */\n public readonly field?: string;\n\n constructor(\n message: string = 'Username or email already exists',\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'UserAlreadyExistsError';\n // Extract field from detail if available\n if (detail && typeof detail === 'object' && 'field' in detail) {\n this.field = (detail as { field?: string }).field;\n }\n }\n}\n\n// =============================================================================\n// Accounting-related Errors\n// =============================================================================\n\n/**\n * Error thrown when email already exists in the accounting service during registration.\n *\n * This error indicates that the user needs to provide their existing\n * accounting password to link their SyftHub account with their existing\n * accounting account.\n *\n * @example\n * ```typescript\n * try {\n * await client.auth.register({ username: \"john\", email: \"john@example.com\", ... });\n * } catch (error) {\n * if (error instanceof AccountingAccountExistsError) {\n * // Prompt user for their existing accounting password\n * const accountingPassword = prompt(\"Enter your existing accounting password:\");\n * // Retry registration with the password\n * await client.auth.register({\n * username: \"john\",\n * email: \"john@example.com\",\n * ...,\n * accountingPassword\n * });\n * }\n * }\n * ```\n */\nexport class AccountingAccountExistsError extends SyftHubError {\n /** Indicates that the user needs to provide their existing accounting password */\n public readonly requiresAccountingPassword = true;\n\n constructor(\n message: string = 'This email already has an account in the accounting service',\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'AccountingAccountExistsError';\n }\n}\n\n/**\n * Error thrown when the provided accounting password is invalid.\n */\nexport class InvalidAccountingPasswordError extends SyftHubError {\n constructor(\n message: string = 'The provided accounting password is invalid',\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'InvalidAccountingPasswordError';\n }\n}\n\n/**\n * Error thrown when the accounting service is unavailable or returns an error.\n */\nexport class AccountingServiceUnavailableError extends SyftHubError {\n constructor(\n message: string = 'Accounting service is unavailable',\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'AccountingServiceUnavailableError';\n }\n}\n","import {\n AccountingAccountExistsError,\n AccountingServiceUnavailableError,\n APIError,\n AuthenticationError,\n AuthorizationError,\n InvalidAccountingPasswordError,\n NetworkError,\n NotFoundError,\n SyftHubError,\n UserAlreadyExistsError,\n ValidationError,\n} from './errors.js';\nimport { toCamelCase, toSnakeCase, buildSearchParams } from './utils.js';\n\n/**\n * Options for HTTP requests.\n */\nexport interface RequestOptions {\n /** Whether to include the Authorization header (default: true) */\n includeAuth?: boolean;\n /** Whether to send body as form-urlencoded instead of JSON */\n isFormData?: boolean;\n /** Request-specific timeout in milliseconds */\n timeout?: number;\n}\n\n/**\n * Internal request options including body and params.\n */\ninterface InternalRequestOptions extends RequestOptions {\n body?: unknown;\n params?: Record<string, unknown>;\n}\n\n/**\n * Auth tokens returned from login/refresh.\n */\nexport interface AuthTokens {\n accessToken: string;\n refreshToken: string;\n tokenType: string;\n}\n\n/**\n * Internal HTTP client for making API requests.\n *\n * Handles:\n * - Bearer token authentication (JWT or API token)\n * - Automatic token refresh on 401 responses (JWT only)\n * - JSON serialization/deserialization\n * - snake_case <-> camelCase conversion\n * - Error handling and exception mapping\n */\nexport class HTTPClient {\n private accessToken: string | null = null;\n private refreshToken: string | null = null;\n private apiToken: string | null = null;\n private isRefreshing = false;\n private refreshPromise: Promise<void> | null = null;\n\n /**\n * Create a new HTTP client.\n *\n * @param baseUrl - Base URL for all API requests (without trailing slash)\n * @param timeout - Default timeout in milliseconds (default: 30000)\n */\n constructor(\n private readonly baseUrl: string,\n private readonly timeout: number = 30000\n ) {}\n\n /**\n * Set JWT authentication tokens.\n * Clears any API token if set.\n */\n setTokens(access: string, refresh: string): void {\n this.accessToken = access;\n this.refreshToken = refresh;\n this.apiToken = null; // Clear API token when using JWT\n }\n\n /**\n * Set API token for authentication.\n * Clears any JWT tokens if set.\n *\n * @param token - The API token (starts with \"syft_\")\n */\n setApiToken(token: string): void {\n this.apiToken = token;\n this.accessToken = null; // Clear JWT tokens when using API token\n this.refreshToken = null;\n }\n\n /**\n * Get current JWT authentication tokens.\n * Returns null if using API token authentication.\n */\n getTokens(): AuthTokens | null {\n if (!this.accessToken || !this.refreshToken) {\n return null;\n }\n return {\n accessToken: this.accessToken,\n refreshToken: this.refreshToken,\n tokenType: 'bearer',\n };\n }\n\n /**\n * Check if using API token authentication.\n */\n isUsingApiToken(): boolean {\n return this.apiToken !== null;\n }\n\n /**\n * Clear all authentication (JWT and API tokens).\n */\n clearTokens(): void {\n this.accessToken = null;\n this.refreshToken = null;\n this.apiToken = null;\n }\n\n /**\n * Check if the client has valid authentication (JWT or API token).\n */\n hasTokens(): boolean {\n return this.accessToken !== null || this.apiToken !== null;\n }\n\n /**\n * Get the current bearer token (API token or JWT access token).\n */\n private getBearerToken(): string | null {\n return this.apiToken ?? this.accessToken;\n }\n\n /**\n * Make a GET request.\n */\n async get<T>(\n path: string,\n params?: Record<string, unknown>,\n options?: RequestOptions\n ): Promise<T> {\n return this.request<T>('GET', path, { ...options, params });\n }\n\n /**\n * Make a POST request.\n */\n async post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {\n return this.request<T>('POST', path, { ...options, body });\n }\n\n /**\n * Make a PUT request.\n */\n async put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {\n return this.request<T>('PUT', path, { ...options, body });\n }\n\n /**\n * Make a PATCH request.\n */\n async patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T> {\n return this.request<T>('PATCH', path, { ...options, body });\n }\n\n /**\n * Make a DELETE request.\n */\n async delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('DELETE', path, options);\n }\n\n /**\n * Make an HTTP request with automatic retry on 401.\n */\n private async request<T>(\n method: string,\n path: string,\n options: InternalRequestOptions = {}\n ): Promise<T> {\n const { includeAuth = true, isFormData = false, timeout, body, params } = options;\n\n // Build URL with query params\n let url = `${this.baseUrl}${path}`;\n if (params) {\n const searchParams = buildSearchParams(params);\n const queryString = searchParams.toString();\n if (queryString) {\n url += `?${queryString}`;\n }\n }\n\n // Build headers\n const headers: Record<string, string> = {};\n\n const bearerToken = this.getBearerToken();\n if (includeAuth && bearerToken) {\n headers['Authorization'] = `Bearer ${bearerToken}`;\n }\n\n // Build body\n let requestBody: string | undefined;\n if (body !== undefined) {\n if (isFormData) {\n headers['Content-Type'] = 'application/x-www-form-urlencoded';\n // For form data, convert to URLSearchParams\n const formData = new URLSearchParams();\n for (const [key, value] of Object.entries(body as Record<string, unknown>)) {\n if (value !== undefined && value !== null) {\n formData.append(key, String(value));\n }\n }\n requestBody = formData.toString();\n } else {\n headers['Content-Type'] = 'application/json';\n // Convert camelCase to snake_case for JSON bodies\n requestBody = JSON.stringify(toSnakeCase(body));\n }\n }\n\n // Create abort controller for timeout\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout ?? this.timeout);\n\n try {\n const response = await fetch(url, {\n method,\n headers,\n body: requestBody,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n // Handle 401 with automatic token refresh (JWT only, not API tokens)\n // API tokens don't have refresh capability - they just fail\n if (response.status === 401 && includeAuth && this.refreshToken && !this.apiToken) {\n // Attempt to refresh the token\n await this.attemptTokenRefresh();\n\n // Retry the original request with new token\n return this.request<T>(method, path, {\n ...options,\n // Mark that we shouldn't retry again to prevent infinite loops\n includeAuth: true,\n });\n }\n\n return await this.handleResponse<T>(response);\n } catch (error) {\n clearTimeout(timeoutId);\n\n if (error instanceof SyftHubError) {\n throw error;\n }\n\n if (error instanceof Error) {\n if (error.name === 'AbortError') {\n throw new NetworkError('Request timed out', error);\n }\n throw new NetworkError(error.message, error);\n }\n\n throw new NetworkError('Unknown network error');\n }\n }\n\n /**\n * Handle the HTTP response and convert to the expected type.\n */\n private async handleResponse<T>(response: Response): Promise<T> {\n // Try to parse response as JSON\n let data: unknown;\n const contentType = response.headers.get('content-type');\n\n if (contentType?.includes('application/json')) {\n try {\n data = await response.json();\n } catch {\n data = null;\n }\n } else {\n // For non-JSON responses, use text\n const text = await response.text();\n data = text || null;\n }\n\n // Handle error responses\n if (!response.ok) {\n this.handleErrorResponse(response.status, data);\n }\n\n // Convert snake_case to camelCase and parse dates\n return toCamelCase<T>(data);\n }\n\n /**\n * Handle error responses by throwing appropriate exceptions.\n */\n private handleErrorResponse(status: number, data: unknown): never {\n const message = this.extractErrorMessage(data);\n const { code, detail } = this.extractErrorCodeAndDetail(data);\n\n // Check for domain-specific errors based on error code first\n if (code) {\n switch (code) {\n // User registration errors\n case 'USER_ALREADY_EXISTS':\n throw new UserAlreadyExistsError(message, detail);\n // Accounting-related errors\n case 'ACCOUNTING_ACCOUNT_EXISTS':\n throw new AccountingAccountExistsError(message, detail);\n case 'INVALID_ACCOUNTING_PASSWORD':\n throw new InvalidAccountingPasswordError(message, detail);\n case 'ACCOUNTING_SERVICE_UNAVAILABLE':\n throw new AccountingServiceUnavailableError(message, detail);\n }\n }\n\n // Standard status code handling\n switch (status) {\n case 401:\n throw new AuthenticationError(message);\n case 403:\n throw new AuthorizationError(message);\n case 404:\n throw new NotFoundError(message);\n case 422:\n throw new ValidationError(message, this.extractValidationErrors(data));\n default:\n throw new APIError(message, status, data);\n }\n }\n\n /**\n * Extract error code and detail from API response.\n * Used for accounting-specific error handling.\n */\n private extractErrorCodeAndDetail(data: unknown): { code?: string; detail?: unknown } {\n if (!data || typeof data !== 'object') {\n return {};\n }\n\n // FastAPI returns { detail: { code: \"...\", message: \"...\", ... } }\n if ('detail' in data) {\n const detail = (data as { detail: unknown }).detail;\n if (detail && typeof detail === 'object' && 'code' in detail) {\n const innerDetail = detail as { code?: string };\n return {\n code: innerDetail.code,\n detail: detail,\n };\n }\n }\n\n return {};\n }\n\n /**\n * Extract error message from API response.\n */\n private extractErrorMessage(data: unknown): string {\n if (typeof data === 'string') {\n return data;\n }\n\n if (data && typeof data === 'object') {\n // FastAPI style: { detail: \"message\" }\n if ('detail' in data) {\n const detail = (data as { detail: unknown }).detail;\n if (typeof detail === 'string') {\n return detail;\n }\n // FastAPI validation errors: { detail: [{ msg: \"...\", loc: [...] }] }\n if (Array.isArray(detail) && detail.length > 0) {\n const firstError = detail[0] as { msg?: string };\n if (firstError?.msg) {\n return firstError.msg;\n }\n }\n }\n\n // Generic: { message: \"...\" } or { error: \"...\" }\n if ('message' in data && typeof (data as { message: unknown }).message === 'string') {\n return (data as { message: string }).message;\n }\n if ('error' in data && typeof (data as { error: unknown }).error === 'string') {\n return (data as { error: string }).error;\n }\n }\n\n return 'An error occurred';\n }\n\n /**\n * Extract field-level validation errors from API response.\n */\n private extractValidationErrors(data: unknown): Record<string, string[]> | undefined {\n if (!data || typeof data !== 'object' || !('detail' in data)) {\n return undefined;\n }\n\n const detail = (data as { detail: unknown }).detail;\n if (!Array.isArray(detail)) {\n return undefined;\n }\n\n const errors: Record<string, string[]> = {};\n\n for (const error of detail) {\n if (typeof error === 'object' && error !== null && 'loc' in error && 'msg' in error) {\n const { loc, msg } = error as { loc: unknown[]; msg: string };\n // loc is typically ['body', 'field_name']\n const field = String(loc[loc.length - 1] ?? 'unknown');\n if (!errors[field]) {\n errors[field] = [];\n }\n errors[field].push(msg);\n }\n }\n\n return Object.keys(errors).length > 0 ? errors : undefined;\n }\n\n /**\n * Attempt to refresh the access token using the refresh token.\n */\n private async attemptTokenRefresh(): Promise<void> {\n // If already refreshing, wait for the existing refresh to complete\n if (this.isRefreshing && this.refreshPromise) {\n await this.refreshPromise;\n return;\n }\n\n this.isRefreshing = true;\n\n this.refreshPromise = (async () => {\n try {\n const response = await fetch(`${this.baseUrl}/api/v1/auth/refresh`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ refresh_token: this.refreshToken }),\n });\n\n if (!response.ok) {\n // Refresh failed, clear tokens\n this.clearTokens();\n throw new AuthenticationError('Token refresh failed');\n }\n\n const data = (await response.json()) as {\n access_token: string;\n refresh_token: string;\n };\n\n this.accessToken = data.access_token;\n this.refreshToken = data.refresh_token;\n } finally {\n this.isRefreshing = false;\n this.refreshPromise = null;\n }\n })();\n\n await this.refreshPromise;\n }\n}\n","// Per-key caches. Every request runs these over every key; the key-set is\n// small (tens to low hundreds across a process lifetime) so an unbounded Map\n// is fine and saves repeated regex work on hot paths.\nconst snakeToCamelCache = new Map<string, string>();\nconst camelToSnakeCache = new Map<string, string>();\n\n/**\n * Convert a snake_case string to camelCase.\n *\n * @example\n * snakeToCamel('created_at') // 'createdAt'\n * snakeToCamel('full_name') // 'fullName'\n */\nexport function snakeToCamel(str: string): string {\n const cached = snakeToCamelCache.get(str);\n if (cached !== undefined) return cached;\n const result = str.replace(/_([a-z])/g, (_, letter: string) => letter.toUpperCase());\n snakeToCamelCache.set(str, result);\n return result;\n}\n\n/**\n * Convert a camelCase string to snake_case.\n *\n * @example\n * camelToSnake('createdAt') // 'created_at'\n * camelToSnake('fullName') // 'full_name'\n */\nexport function camelToSnake(str: string): string {\n const cached = camelToSnakeCache.get(str);\n if (cached !== undefined) return cached;\n const result = str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);\n camelToSnakeCache.set(str, result);\n return result;\n}\n\n/**\n * Regular expression to match ISO 8601 date strings.\n */\nconst ISO_DATE_REGEX = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}/;\n\n/**\n * Check if a value looks like an ISO date string.\n */\nfunction isISODateString(value: unknown): value is string {\n return typeof value === 'string' && ISO_DATE_REGEX.test(value);\n}\n\n/**\n * Recursively transform object keys using the provided transformer function.\n * Optionally parses ISO date strings to Date objects.\n *\n * @param obj - The object to transform\n * @param keyTransformer - Function to transform each key\n * @param parseDates - Whether to parse ISO date strings to Date objects\n */\nexport function transformKeys<T>(\n obj: unknown,\n keyTransformer: (key: string) => string,\n parseDates = true\n): T {\n // Handle null and undefined\n if (obj === null || obj === undefined) {\n return obj as T;\n }\n\n // Handle arrays\n if (Array.isArray(obj)) {\n return obj.map((item) => transformKeys(item, keyTransformer, parseDates)) as T;\n }\n\n // Serialize Date objects to ISO strings. Must come before the object branch,\n // which would otherwise enumerate a Date's (empty) own properties.\n if (obj instanceof Date) {\n return obj.toISOString() as T;\n }\n\n // Handle date strings\n if (parseDates && isISODateString(obj)) {\n return new Date(obj) as T;\n }\n\n // Handle objects\n if (typeof obj === 'object') {\n const transformed: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(obj)) {\n transformed[keyTransformer(key)] = transformKeys(value, keyTransformer, parseDates);\n }\n return transformed as T;\n }\n\n // Return primitives as-is\n return obj as T;\n}\n\n/**\n * Convert all keys in an object from camelCase to snake_case.\n * Does not parse dates (for request bodies).\n */\nexport function toSnakeCase<T>(obj: unknown): T {\n return transformKeys<T>(obj, camelToSnake, false);\n}\n\n/**\n * Convert all keys in an object from snake_case to camelCase.\n * Parses ISO date strings to Date objects (for response bodies).\n */\nexport function toCamelCase<T>(obj: unknown): T {\n return transformKeys<T>(obj, snakeToCamel, true);\n}\n\n/**\n * Build URL search params from an object, filtering out undefined values.\n */\nexport function buildSearchParams(params: Record<string, unknown>): URLSearchParams {\n const searchParams = new URLSearchParams();\n\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined && value !== null) {\n searchParams.append(camelToSnake(key), String(value));\n }\n }\n\n return searchParams;\n}\n\n/**\n * Parse a Server-Sent Events stream into event/data pairs.\n *\n * - Yields `{event, data}` on blank-line boundaries (SSE framing) OR after any\n * `data:` line when no preceding `event:` has been seen (tolerates servers\n * that emit only `data:` lines — fall back to `\"message\"`).\n * - Does NOT JSON.parse; callers parse their own schema.\n * - Flushes any pending event when the stream ends.\n */\nexport async function* readSSEEvents(\n response: Response\n): AsyncGenerator<{ event: string; data: string }> {\n if (!response.body) return;\n\n const reader = response.body.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n let currentEvent: string | null = null;\n let currentData = '';\n\n const flush = function* (): Generator<{ event: string; data: string }> {\n if (currentData) {\n yield { event: currentEvent ?? 'message', data: currentData };\n }\n currentEvent = null;\n currentData = '';\n };\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n const trimmed = line.trim();\n\n if (!trimmed) {\n yield* flush();\n continue;\n }\n\n if (trimmed.startsWith('event:')) {\n currentEvent = trimmed.slice(6).trim();\n } else if (trimmed.startsWith('data:')) {\n // If we already have buffered data without a blank-line terminator,\n // emit it now so data-only streams (no event: header) still flow.\n if (currentData && currentEvent === null) {\n yield* flush();\n }\n currentData = trimmed.slice(5).trim();\n }\n }\n }\n\n // Process any trailing line still in the buffer.\n const trailing = buffer.trim();\n if (trailing) {\n if (trailing.startsWith('event:')) {\n currentEvent = trailing.slice(6).trim();\n } else if (trailing.startsWith('data:')) {\n if (currentData && currentEvent === null) {\n yield* flush();\n }\n currentData = trailing.slice(5).trim();\n }\n }\n yield* flush();\n } finally {\n reader.releaseLock();\n }\n}\n","import { HTTPClient, type AuthTokens } from './http.js';\nimport { AuthenticationError, SyftHubError } from './errors.js';\nimport { APITokensResource } from './resources/api-tokens.js';\nimport { AggregatorsResource } from './resources/aggregators.js';\nimport { AuthResource } from './resources/auth.js';\nimport { UsersResource } from './resources/users.js';\nimport { MyEndpointsResource } from './resources/my-endpoints.js';\nimport { HubResource } from './resources/hub.js';\nimport { AccountingResource } from './resources/accounting.js';\nimport { AgentResource } from './resources/agent.js';\nimport { ChatResource } from './resources/chat.js';\nimport { SearchResource } from './resources/search.js';\nimport { SyftAIResource } from './resources/syftai.js';\n\n/**\n * Configuration options for SyftHubClient.\n */\nexport interface SyftHubClientOptions {\n /**\n * Base URL for the SyftHub API.\n * Falls back to SYFTHUB_URL environment variable.\n * @example 'https://hub.syft.com'\n */\n baseUrl?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 30000\n */\n timeout?: number;\n\n /**\n * Base URL for the aggregator service (optional).\n * Falls back to SYFTHUB_AGGREGATOR_URL environment variable.\n * Defaults to {baseUrl}/aggregator/api/v1\n */\n aggregatorUrl?: string;\n\n /**\n * API token for authentication (alternative to username/password login).\n * If provided, the client will be authenticated immediately without needing to call login().\n * Falls back to SYFTHUB_API_TOKEN environment variable.\n * @example 'syft_pat_xxxxx...'\n */\n apiToken?: string;\n}\n\n/**\n * Get environment variable, handling both Node.js and browser environments.\n */\nfunction getEnv(key: string): string | undefined {\n if (typeof process !== 'undefined' && process.env) {\n return process.env[key];\n }\n return undefined;\n}\n\n/**\n * Check if running in a browser environment.\n */\nfunction isBrowser(): boolean {\n return (\n typeof globalThis !== 'undefined' &&\n typeof (globalThis as { window?: unknown }).window !== 'undefined' &&\n typeof (globalThis as { document?: unknown }).document !== 'undefined'\n );\n}\n\n/**\n * SyftHub SDK client for interacting with the SyftHub API.\n *\n * @example\n * // Basic usage\n * import { SyftHubClient } from '@syfthub/sdk';\n *\n * const client = new SyftHubClient({ baseUrl: 'https://hub.syft.com' });\n *\n * // Or use environment variable\n * // Set SYFTHUB_URL=https://hub.syft.com\n * const client = new SyftHubClient();\n *\n * @example\n * // Authentication\n * const user = await client.auth.login('alice', 'password123');\n * console.log(`Logged in as ${user.username}`);\n *\n * // Get current user\n * const me = await client.auth.me();\n *\n * @example\n * // Browse endpoints\n * for await (const endpoint of client.hub.browse()) {\n * console.log(endpoint.name);\n * }\n *\n * @example\n * // Manage your endpoints\n * const endpoint = await client.myEndpoints.create({\n * name: 'My Model',\n * type: 'model',\n * visibility: 'public',\n * });\n *\n * @example\n * // Token persistence\n * const tokens = client.getTokens();\n * // Save tokens to storage...\n *\n * // Later, restore tokens\n * client.setTokens(savedTokens);\n */\nexport class SyftHubClient {\n private readonly http: HTTPClient;\n private readonly aggregatorUrl: string;\n\n // Lazy-initialized resources\n private _auth?: AuthResource;\n private _users?: UsersResource;\n private _myEndpoints?: MyEndpointsResource;\n private _hub?: HubResource;\n private _accounting?: AccountingResource;\n private _aggregators?: AggregatorsResource;\n private _agent?: AgentResource;\n private _chat?: ChatResource;\n private _search?: SearchResource;\n private _syftai?: SyftAIResource;\n private _apiTokens?: APITokensResource;\n\n /**\n * Create a new SyftHub client.\n *\n * @param options - Configuration options\n * @throws {SyftHubError} If baseUrl is not provided and SYFTHUB_URL is not set (in non-browser environments)\n */\n constructor(options: SyftHubClientOptions = {}) {\n let baseUrl = options.baseUrl ?? getEnv('SYFTHUB_URL');\n\n // In browser environments, empty baseUrl means same-origin requests\n // This is valid and commonly used when the API is served from the same domain\n if (!baseUrl && !isBrowser()) {\n throw new SyftHubError(\n 'baseUrl is required. Provide it in options or set the SYFTHUB_URL environment variable.'\n );\n }\n\n // Default to empty string for same-origin browser requests\n baseUrl = baseUrl ?? '';\n\n // Remove trailing slash from base URL (only if not empty)\n const normalizedUrl = baseUrl ? baseUrl.replace(/\\/+$/, '') : '';\n\n this.http = new HTTPClient(normalizedUrl, options.timeout ?? 30000);\n\n // Resolve aggregator URL (default to {baseUrl}/aggregator/api/v1)\n this.aggregatorUrl =\n options.aggregatorUrl ??\n getEnv('SYFTHUB_AGGREGATOR_URL') ??\n `${normalizedUrl}/aggregator/api/v1`;\n\n // Initialize with API token if provided\n const apiToken = options.apiToken ?? getEnv('SYFTHUB_API_TOKEN');\n if (apiToken) {\n this.http.setApiToken(apiToken);\n }\n }\n\n /**\n * Authentication resource for login, register, and session management.\n *\n * @example\n * const user = await client.auth.login('alice', 'password');\n * await client.auth.logout();\n */\n get auth(): AuthResource {\n if (!this._auth) {\n this._auth = new AuthResource(this.http);\n }\n return this._auth;\n }\n\n /**\n * Users resource for profile management.\n *\n * @example\n * const user = await client.users.update({ fullName: 'Alice Smith' });\n * const available = await client.users.checkUsername('newname');\n */\n get users(): UsersResource {\n if (!this._users) {\n this._users = new UsersResource(this.http);\n }\n return this._users;\n }\n\n /**\n * My Endpoints resource for managing your own endpoints.\n *\n * @example\n * const endpoints = await client.myEndpoints.list().all();\n * const endpoint = await client.myEndpoints.create({ name: 'My API', type: 'model' });\n */\n get myEndpoints(): MyEndpointsResource {\n if (!this._myEndpoints) {\n this._myEndpoints = new MyEndpointsResource(this.http);\n }\n return this._myEndpoints;\n }\n\n /**\n * Hub resource for browsing public endpoints.\n *\n * @example\n * for await (const endpoint of client.hub.browse()) {\n * console.log(endpoint.name);\n * }\n */\n get hub(): HubResource {\n if (!this._hub) {\n this._hub = new HubResource(this.http);\n }\n return this._hub;\n }\n\n /**\n * Agent resource for bidirectional agent sessions via WebSocket.\n *\n * @example\n * const session = await client.agent.startSession({\n * prompt: 'Help me refactor this code',\n * endpoint: 'alice/code-assistant',\n * });\n *\n * for await (const event of session.events()) {\n * console.log(event.type, event.payload);\n * }\n */\n get agent(): AgentResource {\n if (!this._agent) {\n this._agent = new AgentResource(this.auth, this.aggregatorUrl);\n }\n return this._agent;\n }\n\n /**\n * Accounting resource for wallet and payment operations.\n *\n * Provides access to MPP wallet management (balance, transactions,\n * wallet creation/import). Uses the same SyftHub JWT authentication\n * as other resources.\n *\n * You must call `initAccounting()` after login to initialize this resource,\n * or access it directly if already initialized.\n *\n * @throws {AuthenticationError} If not initialized\n *\n * @example\n * // Login first, then initialize accounting\n * await client.auth.login('alice', 'password');\n * await client.initAccounting();\n *\n * // Now accounting is available\n * const wallet = await client.accounting.getWallet();\n * const balance = await client.accounting.getBalance();\n */\n get accounting(): AccountingResource {\n if (!this.isAuthenticated) {\n throw new AuthenticationError(\n 'Must be logged in to use accounting. Call client.auth.login() first.'\n );\n }\n if (!this._accounting) {\n this._accounting = new AccountingResource(this.http);\n }\n return this._accounting;\n }\n\n /**\n * @deprecated Accounting is now initialized automatically on first access.\n * This method is kept for backward compatibility and is a no-op.\n */\n async initAccounting(): Promise<AccountingResource> {\n return this.accounting;\n }\n\n /**\n * Chat resource for RAG-augmented conversations via the Aggregator.\n *\n * This resource provides high-level chat functionality that integrates\n * with the SyftHub Aggregator service for RAG workflows.\n *\n * @example\n * // Simple chat completion\n * const response = await client.chat.complete({\n * prompt: 'What is machine learning?',\n * model: 'alice/gpt-model',\n * dataSources: ['bob/ml-docs'],\n * });\n * console.log(response.response);\n *\n * // Streaming chat\n * for await (const event of client.chat.stream(options)) {\n * if (event.type === 'token') {\n * process.stdout.write(event.content);\n * }\n * }\n *\n * // Get available endpoints\n * const models = await client.chat.getAvailableModels();\n * const sources = await client.chat.getAvailableDataSources();\n */\n get chat(): ChatResource {\n if (!this._chat) {\n this._chat = new ChatResource(this.hub, this.auth, this.aggregatorUrl);\n }\n return this._chat;\n }\n\n /**\n * Retrieval-only search via the Aggregator (no model generation).\n *\n * Symmetric counterpart to {@link chat}: queries data sources for relevant\n * documents without invoking a model. Satellite-token auth and MPP payment\n * are handled by the aggregator exactly as for chat.\n *\n * @example\n * const result = await client.search.query({\n * prompt: 'Hello, world!',\n * dataSources: ['epfl-news/epfl-news'],\n * });\n * for (const doc of result.documents) {\n * console.log(doc.title, doc.content.slice(0, 80));\n * }\n */\n get search(): SearchResource {\n if (!this._search) {\n this._search = new SearchResource(this.chat);\n }\n return this._search;\n }\n\n /**\n * SyftAI-Space resource for direct endpoint queries (low-level API).\n *\n * This resource provides direct access to SyftAI-Space endpoints without\n * going through the aggregator. Use this when you need custom RAG pipelines\n * or fine-grained control over queries.\n *\n * For most use cases, prefer the higher-level `client.chat` API instead.\n *\n * @example\n * // Query a data source directly\n * const docs = await client.syftai.queryDataSource({\n * endpoint: { url: 'http://syftai:8080', slug: 'docs' },\n * query: 'What is Python?',\n * userEmail: 'alice@example.com',\n * });\n *\n * // Query a model directly\n * const response = await client.syftai.queryModel({\n * endpoint: { url: 'http://syftai:8080', slug: 'gpt-model' },\n * messages: [{ role: 'user', content: 'Hello!' }],\n * userEmail: 'alice@example.com',\n * });\n */\n get syftai(): SyftAIResource {\n if (!this._syftai) {\n this._syftai = new SyftAIResource(this.http);\n }\n return this._syftai;\n }\n\n /**\n * API Tokens resource for managing personal access tokens.\n *\n * API tokens provide an alternative to username/password authentication.\n * They are ideal for CI/CD pipelines, scripts, and programmatic access.\n *\n * @example\n * // Create a new token\n * const result = await client.apiTokens.create({\n * name: 'CI/CD Pipeline',\n * scopes: ['write'],\n * });\n * console.log('Save this token:', result.token);\n *\n * // List all tokens\n * const { tokens } = await client.apiTokens.list();\n *\n * // Revoke a token\n * await client.apiTokens.revoke(tokenId);\n */\n get aggregators(): AggregatorsResource {\n if (!this._aggregators) {\n this._aggregators = new AggregatorsResource(this.http);\n }\n return this._aggregators;\n }\n\n get apiTokens(): APITokensResource {\n if (!this._apiTokens) {\n this._apiTokens = new APITokensResource(this.http);\n }\n return this._apiTokens;\n }\n\n /**\n * Check if the client is using API token authentication.\n *\n * @returns True if authenticated with an API token (vs JWT)\n */\n get isUsingApiToken(): boolean {\n return this.http.isUsingApiToken();\n }\n\n /**\n * Get current authentication tokens.\n *\n * Use this to persist tokens for later sessions.\n *\n * @returns Current tokens or null if not authenticated\n *\n * @example\n * const tokens = client.getTokens();\n * if (tokens) {\n * localStorage.setItem('tokens', JSON.stringify(tokens));\n * }\n */\n getTokens(): AuthTokens | null {\n return this.http.getTokens();\n }\n\n /**\n * Set authentication tokens.\n *\n * Use this to restore a session from previously saved tokens.\n *\n * @param tokens - Tokens to set\n *\n * @example\n * const saved = JSON.parse(localStorage.getItem('tokens'));\n * if (saved) {\n * client.setTokens(saved);\n * }\n */\n setTokens(tokens: AuthTokens): void {\n this.http.setTokens(tokens.accessToken, tokens.refreshToken);\n }\n\n /**\n * Check if the client is currently authenticated.\n *\n * @returns True if tokens are present\n */\n get isAuthenticated(): boolean {\n return this.http.hasTokens();\n }\n\n /**\n * Check if the accounting (wallet) resource has been initialized.\n *\n * Use this to check if accounting is available before accessing\n * the `accounting` property, which will throw if not initialized.\n *\n * @returns True if accounting has been initialized via `initAccounting()`\n *\n * @example\n * if (client.isAccountingInitialized) {\n * const wallet = await client.accounting.getWallet();\n * }\n */\n get isAccountingInitialized(): boolean {\n return this._accounting !== undefined && this._accounting !== null;\n }\n\n /**\n * Close the client and clean up resources.\n *\n * Currently a no-op, but may be used in future for connection pooling.\n */\n close(): void {\n // Currently a no-op\n // Could be used for cleanup in future (e.g., connection pools)\n }\n}\n","/**\n * Resource for managing API tokens.\n */\n\nimport type { HTTPClient } from '../http.js';\nimport type {\n APIToken,\n APITokenCreateResponse,\n APITokenListResponse,\n CreateAPITokenInput,\n UpdateAPITokenInput,\n} from '../models/api-token.js';\n\n/**\n * Resource for managing API tokens.\n *\n * API tokens provide an alternative to username/password authentication.\n * They are ideal for CI/CD pipelines, scripts, and programmatic access.\n *\n * @example\n * // Create a new token\n * const result = await client.apiTokens.create({\n * name: 'CI/CD Pipeline',\n * scopes: ['write'],\n * });\n * console.log('Save this token:', result.token);\n *\n * // List all tokens\n * const { tokens } = await client.apiTokens.list();\n *\n * // Revoke a token\n * await client.apiTokens.revoke(tokenId);\n */\nexport class APITokensResource {\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * Create a new API token.\n *\n * IMPORTANT: The returned token is only shown ONCE!\n * Make sure to save it immediately - it cannot be retrieved later.\n *\n * @param input - Token creation options\n * @returns The created token with the full token value\n *\n * @example\n * const result = await client.apiTokens.create({\n * name: 'CI/CD Pipeline',\n * scopes: ['write'],\n * expiresAt: new Date('2025-12-31'),\n * });\n *\n * // SAVE THIS TOKEN - it will not be shown again!\n * console.log(result.token);\n */\n async create(input: CreateAPITokenInput): Promise<APITokenCreateResponse> {\n return this.http.post<APITokenCreateResponse>('/api/v1/auth/tokens', input);\n }\n\n /**\n * List all API tokens for the current user.\n *\n * By default, only active tokens are returned.\n * Note: The full token value is never returned - only the prefix.\n *\n * @param options - List options\n * @returns List of tokens and total count\n *\n * @example\n * // List active tokens\n * const { tokens, total } = await client.apiTokens.list();\n *\n * // Include revoked tokens\n * const all = await client.apiTokens.list({ includeInactive: true });\n */\n async list(\n options: {\n includeInactive?: boolean;\n skip?: number;\n limit?: number;\n } = {}\n ): Promise<APITokenListResponse> {\n const params: Record<string, unknown> = {};\n if (options.includeInactive !== undefined) {\n params.include_inactive = options.includeInactive;\n }\n if (options.skip !== undefined) {\n params.skip = options.skip;\n }\n if (options.limit !== undefined) {\n params.limit = options.limit;\n }\n return this.http.get<APITokenListResponse>('/api/v1/auth/tokens', params);\n }\n\n /**\n * Get a single API token by ID.\n *\n * Note: The full token value is never returned - only the prefix.\n *\n * @param tokenId - The token ID\n * @returns The token details\n *\n * @example\n * const token = await client.apiTokens.get(123);\n * console.log(token.name, token.lastUsedAt);\n */\n async get(tokenId: number): Promise<APIToken> {\n return this.http.get<APIToken>(`/api/v1/auth/tokens/${tokenId}`);\n }\n\n /**\n * Update an API token's name.\n *\n * Only the name can be updated. Scopes and expiration cannot be\n * changed after creation.\n *\n * @param tokenId - The token ID\n * @param input - Update options\n * @returns The updated token\n *\n * @example\n * const updated = await client.apiTokens.update(123, {\n * name: 'New Name',\n * });\n */\n async update(tokenId: number, input: UpdateAPITokenInput): Promise<APIToken> {\n return this.http.patch<APIToken>(`/api/v1/auth/tokens/${tokenId}`, input);\n }\n\n /**\n * Revoke an API token.\n *\n * The token becomes immediately unusable. This action cannot be undone.\n *\n * @param tokenId - The token ID to revoke\n *\n * @example\n * await client.apiTokens.revoke(123);\n */\n async revoke(tokenId: number): Promise<void> {\n await this.http.delete<void>(`/api/v1/auth/tokens/${tokenId}`);\n }\n}\n","import type { HTTPClient } from '../http.js';\nimport type {\n UserAggregator,\n UserAggregatorCreateInput,\n UserAggregatorUpdateInput,\n} from '../models/index.js';\n\n/**\n * Resource for managing user's aggregator configurations.\n *\n * Aggregators are custom RAG orchestration service endpoints that users can\n * configure to use for chat operations. Each user can have multiple aggregator\n * configurations, with one set as the default.\n *\n * The first aggregator created is automatically set as the default. Only one\n * aggregator can be the default at a time; setting a new default automatically\n * unsets the previous one.\n *\n * @example\n * // List all aggregators\n * const aggregators = await client.users.aggregators.list();\n * for (const agg of aggregators) {\n * console.log(`${agg.name}: ${agg.url}`);\n * }\n *\n * @example\n * // Create a new aggregator\n * const agg = await client.users.aggregators.create({\n * name: 'My Custom Aggregator',\n * url: 'https://my-aggregator.example.com'\n * });\n *\n * @example\n * // Set as default\n * const defaultAgg = await client.users.aggregators.setDefault(agg.id);\n */\nexport class AggregatorsResource {\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * List all aggregator configurations for the current user.\n *\n * @returns Array of UserAggregator objects\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * const aggregators = await client.users.aggregators.list();\n * for (const agg of aggregators) {\n * if (agg.isDefault) {\n * console.log(`Default: ${agg.name}`);\n * }\n * }\n */\n async list(): Promise<UserAggregator[]> {\n return this.http.get<UserAggregator[]>('/api/v1/users/me/aggregators');\n }\n\n /**\n * Get a specific aggregator configuration by ID.\n *\n * @param aggregatorId - The aggregator ID\n * @returns The UserAggregator object\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If aggregator not found\n *\n * @example\n * const agg = await client.users.aggregators.get(1);\n * console.log(`${agg.name}: ${agg.url}`);\n */\n async get(aggregatorId: number): Promise<UserAggregator> {\n return this.http.get<UserAggregator>(`/api/v1/users/me/aggregators/${aggregatorId}`);\n }\n\n /**\n * Create a new aggregator configuration.\n *\n * The first aggregator created is automatically set as the default.\n *\n * @param input - Aggregator creation input\n * @returns The created UserAggregator object\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If input is invalid\n *\n * @example\n * const agg = await client.users.aggregators.create({\n * name: 'My Custom Aggregator',\n * url: 'https://my-aggregator.example.com'\n * });\n * console.log(`Created: ${agg.id}`);\n */\n async create(input: UserAggregatorCreateInput): Promise<UserAggregator> {\n return this.http.post<UserAggregator>('/api/v1/users/me/aggregators', input);\n }\n\n /**\n * Update an aggregator configuration.\n *\n * Only provided fields will be updated.\n *\n * @param aggregatorId - The aggregator ID to update\n * @param input - Fields to update\n * @returns The updated UserAggregator object\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If aggregator not found\n * @throws {ValidationError} If input is invalid\n *\n * @example\n * const agg = await client.users.aggregators.update(1, {\n * name: 'Updated Name'\n * });\n */\n async update(aggregatorId: number, input: UserAggregatorUpdateInput): Promise<UserAggregator> {\n return this.http.put<UserAggregator>(`/api/v1/users/me/aggregators/${aggregatorId}`, input);\n }\n\n /**\n * Delete an aggregator configuration.\n *\n * @param aggregatorId - The aggregator ID to delete\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If aggregator not found\n *\n * @example\n * await client.users.aggregators.delete(1);\n */\n async delete(aggregatorId: number): Promise<void> {\n await this.http.delete<void>(`/api/v1/users/me/aggregators/${aggregatorId}`);\n }\n\n /**\n * Set an aggregator as the default.\n *\n * Only one aggregator can be the default at a time. Setting a new default\n * automatically unsets the previous one.\n *\n * @param aggregatorId - The aggregator ID to set as default\n * @returns The updated UserAggregator object with isDefault=true\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If aggregator not found\n *\n * @example\n * const agg = await client.users.aggregators.setDefault(2);\n * console.log(`${agg.name} is now the default`);\n */\n async setDefault(aggregatorId: number): Promise<UserAggregator> {\n return this.http.patch<UserAggregator>(`/api/v1/users/me/aggregators/${aggregatorId}/default`);\n }\n}\n","import type { HTTPClient } from '../http.js';\nimport type {\n AuthConfig,\n PasswordResetConfirmInput,\n PasswordResetRequestInput,\n RegisterResult,\n User,\n UserRegisterInput,\n VerifyOTPInput,\n} from '../models/index.js';\nimport type { TransactionTokensResponse } from '../models/accounting.js';\nimport { AuthenticationError } from '../errors.js';\n\n/**\n * Response from login/register endpoints.\n */\ninterface AuthResponse {\n user: User;\n accessToken: string;\n refreshToken: string;\n tokenType: string;\n}\n\n/**\n * Response from registration endpoint (may have null tokens).\n */\ninterface RegistrationResponse {\n user: User;\n accessToken: string | null;\n refreshToken: string | null;\n tokenType: string;\n requiresEmailVerification: boolean;\n}\n\n/**\n * Authentication resource for login, register, and session management.\n *\n * @example\n * // Register a new user\n * const user = await client.auth.register({\n * username: 'alice',\n * email: 'alice@example.com',\n * password: 'SecurePass123!',\n * fullName: 'Alice'\n * });\n *\n * @example\n * // Login\n * const user = await client.auth.login('alice', 'SecurePass123!');\n *\n * @example\n * // Get current user\n * const me = await client.auth.me();\n *\n * @example\n * // Logout\n * await client.auth.logout();\n */\nexport class AuthResource {\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * Register a new user account.\n *\n * If an accounting service URL is configured (via `accountingServiceUrl` or server default),\n * the backend will handle accounting integration using a \"try-create-first\" approach:\n *\n * **Accounting Password Behavior:**\n * - **Not provided**: A secure password is auto-generated and a new accounting account is created.\n * - **Provided (new user)**: The account is created with your chosen password.\n * - **Provided (existing user)**: Your password is validated and accounts are linked.\n *\n * This means you can set your own accounting password during registration even if you're\n * a new user - you don't need an existing accounting account first.\n *\n * @param input - Registration details (username, email, password, fullName)\n * @returns The created User\n * @throws {ValidationError} If input validation fails\n * @throws {UserAlreadyExistsError} If username or email already exists in SyftHub\n * @throws {AccountingAccountExistsError} If email already exists in accounting service\n * and no `accountingPassword` was provided. Retry with the password.\n * @throws {InvalidAccountingPasswordError} If the provided accounting password doesn't\n * match an existing accounting account\n * @throws {AccountingServiceUnavailableError} If the accounting service is unreachable\n *\n * @example\n * // Basic registration (auto-generated accounting password)\n * const user = await client.auth.register({\n * username: 'alice',\n * email: 'alice@example.com',\n * password: 'SecurePass123!',\n * fullName: 'Alice'\n * });\n *\n * @example\n * // Registration with custom accounting password (NEW user)\n * const user = await client.auth.register({\n * username: 'bob',\n * email: 'bob@example.com',\n * password: 'SecurePass123!',\n * fullName: 'Bob',\n * accountingPassword: 'MyChosenAccountingPass!' // Creates account with this password\n * });\n *\n * @example\n * // Handle existing accounting account\n * try {\n * await client.auth.register({ username, email, password, fullName });\n * } catch (error) {\n * if (error instanceof AccountingAccountExistsError) {\n * // Prompt user for their existing accounting password\n * const accountingPassword = await promptUser('Enter your existing accounting password:');\n * await client.auth.register({ username, email, password, fullName, accountingPassword });\n * } else {\n * throw error;\n * }\n * }\n */\n async register(input: UserRegisterInput): Promise<RegisterResult> {\n const response = await this.http.post<RegistrationResponse>('/api/v1/auth/register', input, {\n includeAuth: false,\n });\n\n // Store tokens if present (not withheld for email verification)\n if (response.accessToken && response.refreshToken) {\n this.http.setTokens(response.accessToken, response.refreshToken);\n }\n\n return {\n user: response.user,\n requiresEmailVerification: response.requiresEmailVerification,\n };\n }\n\n /**\n * Login with username/email and password.\n *\n * Uses OAuth2 password flow (form-urlencoded body).\n *\n * @param username - Username or email\n * @param password - Password\n * @returns The authenticated User\n * @throws {AuthenticationError} If credentials are invalid\n */\n async login(username: string, password: string): Promise<User> {\n const response = await this.http.post<AuthResponse>(\n '/api/v1/auth/login',\n { username, password },\n {\n includeAuth: false,\n isFormData: true,\n }\n );\n\n // Store tokens in HTTP client\n this.http.setTokens(response.accessToken, response.refreshToken);\n\n return response.user;\n }\n\n /**\n * Logout the current user.\n *\n * Invalidates tokens on the server and clears local token storage.\n */\n async logout(): Promise<void> {\n try {\n await this.http.post<void>('/api/v1/auth/logout');\n } finally {\n // Always clear tokens, even if the API call fails\n this.http.clearTokens();\n }\n }\n\n /**\n * Get the current authenticated user.\n *\n * @returns The current User\n * @throws {AuthenticationError} If not authenticated\n */\n async me(): Promise<User> {\n return this.http.get<User>('/api/v1/auth/me');\n }\n\n /**\n * Manually refresh the access token.\n *\n * This is normally handled automatically when a request returns 401.\n *\n * @throws {AuthenticationError} If refresh token is invalid or expired\n */\n async refresh(): Promise<void> {\n const tokens = this.http.getTokens();\n if (!tokens) {\n throw new AuthenticationError('No refresh token available');\n }\n\n const response = await this.http.post<{\n accessToken: string;\n refreshToken: string;\n }>('/api/v1/auth/refresh', { refreshToken: tokens.refreshToken }, { includeAuth: false });\n\n this.http.setTokens(response.accessToken, response.refreshToken);\n }\n\n /**\n * Change the current user's password.\n *\n * @param currentPassword - Current password for verification\n * @param newPassword - New password to set\n * @throws {AuthenticationError} If current password is incorrect\n * @throws {ValidationError} If new password doesn't meet requirements\n */\n async changePassword(currentPassword: string, newPassword: string): Promise<void> {\n await this.http.put<void>('/api/v1/auth/me/password', {\n currentPassword,\n newPassword,\n });\n }\n\n /**\n * Get the platform's authentication configuration.\n *\n * No authentication required. Use this to determine whether email\n * verification or password reset is available.\n *\n * @returns AuthConfig with feature flags\n */\n async getAuthConfig(): Promise<AuthConfig> {\n return this.http.get<AuthConfig>('/api/v1/auth/config', undefined, { includeAuth: false });\n }\n\n /**\n * Verify a registration OTP and receive auth tokens.\n *\n * After registering when email verification is required, call this with\n * the 6-digit code sent to the user's email.\n *\n * Idempotent: if the user is already verified, tokens are issued immediately.\n *\n * @param input - Email and 6-digit code\n * @returns The authenticated User\n * @throws {APIError} If the code is invalid or max attempts exceeded\n */\n async verifyOtp(input: VerifyOTPInput): Promise<User> {\n const response = await this.http.post<AuthResponse>('/api/v1/auth/register/verify-otp', input, {\n includeAuth: false,\n });\n\n this.http.setTokens(response.accessToken, response.refreshToken);\n return response.user;\n }\n\n /**\n * Resend the registration OTP code.\n *\n * Rate-limited. Always returns successfully to prevent email enumeration.\n *\n * @param email - Email address to resend the OTP to\n */\n async resendOtp(email: string): Promise<void> {\n await this.http.post<void>(\n '/api/v1/auth/register/resend-otp',\n { email },\n {\n includeAuth: false,\n }\n );\n }\n\n /**\n * Request a password reset OTP.\n *\n * Always returns successfully to prevent email enumeration.\n * If SMTP is not configured on the server, this is a no-op.\n *\n * @param input - Email address for password reset\n */\n async requestPasswordReset(input: PasswordResetRequestInput): Promise<void> {\n await this.http.post<void>('/api/v1/auth/password-reset/request', input, {\n includeAuth: false,\n });\n }\n\n /**\n * Confirm a password reset with OTP and set a new password.\n *\n * @param input - Email, 6-digit code, and new password\n * @throws {APIError} If the code is invalid or max attempts exceeded\n */\n async confirmPasswordReset(input: PasswordResetConfirmInput): Promise<void> {\n await this.http.post<void>('/api/v1/auth/password-reset/confirm', input, {\n includeAuth: false,\n });\n }\n\n /**\n * Get a peer token for NATS communication with tunneling spaces.\n *\n * Peer tokens are short-lived credentials that allow the aggregator to\n * communicate with tunneling SyftAI Spaces via NATS pub/sub.\n *\n * @param targetUsernames - Usernames of the tunneling spaces to communicate with\n * @returns PeerTokenResponse with token, channel, expiry, and NATS URL\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * const peer = await client.auth.getPeerToken(['alice', 'bob']);\n * console.log(`Peer channel: ${peer.peerChannel}, expires in ${peer.expiresIn}s`);\n */\n async getPeerToken(targetUsernames: string[]): Promise<PeerTokenResponse> {\n return this.http.post<PeerTokenResponse>('/api/v1/peer-token', {\n target_usernames: targetUsernames,\n });\n }\n\n /**\n * Get a guest peer token for NATS communication without authentication.\n *\n * Guest peer tokens are rate-limited by IP address. They use the same\n * response format as authenticated peer tokens.\n *\n * @param targetUsernames - Usernames of the tunneling spaces to communicate with\n * @returns PeerTokenResponse with token, channel, expiry, and NATS URL\n *\n * @example\n * const peer = await client.auth.getGuestPeerToken(['alice']);\n * console.log(`Guest peer channel: ${peer.peerChannel}`);\n */\n async getGuestPeerToken(targetUsernames: string[]): Promise<PeerTokenResponse> {\n return this.http.post<PeerTokenResponse>(\n '/api/v1/nats/guest-peer-token',\n { target_usernames: targetUsernames },\n { includeAuth: false }\n );\n }\n\n /**\n * Get a satellite token for a specific audience (target service).\n *\n * Satellite tokens are short-lived, RS256-signed JWTs that allow satellite\n * services (like SyftAI-Space) to verify user identity without calling\n * SyftHub for every request.\n *\n * @param audience - Target service identifier (username of the service owner)\n * @returns Satellite token response with token and expiry\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If audience is invalid or inactive\n *\n * @example\n * // Get a token for querying alice's SyftAI-Space endpoints\n * const tokenResponse = await client.auth.getSatelliteToken('alice');\n * console.log(`Token expires in ${tokenResponse.expiresIn} seconds`);\n */\n async getSatelliteToken(audience: string): Promise<SatelliteTokenResponse> {\n return this.http.get<SatelliteTokenResponse>('/api/v1/token', { aud: audience });\n }\n\n /**\n * Get satellite tokens for multiple audiences in parallel.\n *\n * This is useful when making requests to endpoints owned by different users.\n * Tokens are cached and reused where possible.\n *\n * @param audiences - Array of unique audience identifiers (usernames)\n * @returns Map of audience to satellite token\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * // Get tokens for multiple endpoint owners\n * const tokens = await client.auth.getSatelliteTokens(['alice', 'bob']);\n * console.log(`Got ${tokens.size} tokens`);\n */\n async getSatelliteTokens(audiences: string[]): Promise<Map<string, string>> {\n const uniqueAudiences = [...new Set(audiences)];\n const tokenMap = new Map<string, string>();\n\n // Fetch tokens in parallel\n const results = await Promise.allSettled(\n uniqueAudiences.map(async (aud) => {\n const response = await this.getSatelliteToken(aud);\n return { audience: aud, token: response.targetToken };\n })\n );\n\n // Collect successful results; warn on failures so misconfigured IDPs are visible\n for (const [i, result] of results.entries()) {\n if (result.status === 'fulfilled') {\n tokenMap.set(result.value.audience, result.value.token);\n } else {\n console.warn(\n `[SyftHub] Failed to fetch satellite token for \"${uniqueAudiences[i]}\":`,\n result.reason\n );\n }\n }\n\n return tokenMap;\n }\n\n /**\n * Get a guest satellite token for a specific audience (target service).\n *\n * Guest tokens allow unauthenticated users to access policy-free endpoints.\n * No authentication is required to call this method.\n *\n * @param audience - Target service identifier (username of the service owner)\n * @returns Satellite token response with token and expiry\n * @throws {ValidationError} If audience is invalid or inactive\n *\n * @example\n * // Get a guest token for querying alice's policy-free endpoints\n * const tokenResponse = await client.auth.getGuestSatelliteToken('alice');\n */\n async getGuestSatelliteToken(audience: string): Promise<SatelliteTokenResponse> {\n return this.http.get<SatelliteTokenResponse>(\n '/api/v1/token/guest',\n { aud: audience },\n { includeAuth: false }\n );\n }\n\n /**\n * Get guest satellite tokens for multiple audiences in parallel.\n *\n * No authentication is required to call this method.\n *\n * @param audiences - Array of unique audience identifiers (usernames)\n * @returns Map of audience to satellite token\n *\n * @example\n * const tokens = await client.auth.getGuestSatelliteTokens(['alice', 'bob']);\n */\n async getGuestSatelliteTokens(audiences: string[]): Promise<Map<string, string>> {\n const uniqueAudiences = [...new Set(audiences)];\n const tokenMap = new Map<string, string>();\n\n const results = await Promise.allSettled(\n uniqueAudiences.map(async (aud) => {\n const response = await this.getGuestSatelliteToken(aud);\n return { audience: aud, token: response.targetToken };\n })\n );\n\n for (const result of results) {\n if (result.status === 'fulfilled') {\n tokenMap.set(result.value.audience, result.value.token);\n }\n }\n\n return tokenMap;\n }\n\n /**\n * Get transaction tokens for multiple endpoint owners.\n *\n * @deprecated Transaction tokens are no longer needed. Payments are handled\n * via the MPP 402 flow. This method is kept for backward compatibility and\n * always returns empty tokens/errors.\n *\n * @param ownerUsernames - Array of endpoint owner usernames (ignored)\n * @returns TransactionTokensResponse with empty tokens and errors\n */\n async getTransactionTokens(ownerUsernames: string[]): Promise<TransactionTokensResponse> {\n // Transaction tokens are no longer needed - payments are handled via MPP 402 flow\n void ownerUsernames;\n return { tokens: {}, errors: {} };\n }\n\n /**\n * Get the current access token (JWT or API token).\n *\n * This is used by the chat flow to pass the user's Hub token to the\n * aggregator for the MPP payment callback.\n *\n * @returns The current access token, or null if not authenticated\n */\n getAccessToken(): string | null {\n const tokens = this.http.getTokens();\n return tokens?.accessToken ?? null;\n }\n}\n\n/**\n * Response from peer token endpoint.\n */\nexport interface PeerTokenResponse {\n /** Short-lived token for NATS authentication */\n peerToken: string;\n /** Unique reply channel for receiving responses */\n peerChannel: string;\n /** Seconds until the token expires */\n expiresIn: number;\n /** NATS server URL for WebSocket connections */\n natsUrl: string;\n}\n\n/**\n * Response from satellite token endpoint.\n */\nexport interface SatelliteTokenResponse {\n /** RS256-signed JWT for the target service */\n targetToken: string;\n /** Seconds until the token expires */\n expiresIn: number;\n}\n\n// TransactionTokensResponse is imported from models/accounting.ts\nexport type { TransactionTokensResponse } from '../models/accounting.js';\n","import type { HTTPClient } from '../http.js';\nimport type {\n AccountingCredentials,\n HeartbeatInput,\n HeartbeatResponse,\n User,\n UserUpdateInput,\n} from '../models/index.js';\nimport { AggregatorsResource } from './aggregators.js';\n\n/**\n * Users resource for profile management and availability checks.\n *\n * @example\n * // Update your profile\n * const user = await client.users.update({\n * fullName: 'Alice Smith',\n * avatarUrl: 'https://example.com/avatar.jpg'\n * });\n *\n * @example\n * // Check if username is available\n * const available = await client.users.checkUsername('newusername');\n *\n * @example\n * // Check if email is available\n * const available = await client.users.checkEmail('new@example.com');\n *\n * @example\n * // Manage aggregators\n * const aggregators = await client.users.aggregators.list();\n * const newAgg = await client.users.aggregators.create({\n * name: 'My Aggregator',\n * url: 'https://my-aggregator.example.com'\n * });\n */\nexport class UsersResource {\n private _aggregators?: AggregatorsResource;\n\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * Access aggregator management operations.\n *\n * @returns AggregatorsResource for managing user's aggregator configurations\n *\n * @example\n * // List aggregators\n * const aggregators = await client.users.aggregators.list();\n * for (const agg of aggregators) {\n * console.log(`${agg.name}: ${agg.url}`);\n * }\n *\n * // Create aggregator\n * const agg = await client.users.aggregators.create({\n * name: 'My Aggregator',\n * url: 'https://my-aggregator.example.com'\n * });\n *\n * // Set as default\n * await client.users.aggregators.setDefault(agg.id);\n */\n get aggregators(): AggregatorsResource {\n if (!this._aggregators) {\n this._aggregators = new AggregatorsResource(this.http);\n }\n return this._aggregators;\n }\n\n /**\n * Update the current user's profile.\n *\n * Only provided fields will be updated.\n *\n * @param input - Fields to update\n * @returns The updated User\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If input validation fails\n */\n async update(input: UserUpdateInput): Promise<User> {\n return this.http.put<User>('/api/v1/users/me', input);\n }\n\n /**\n * Check if a username is available.\n *\n * @param username - Username to check\n * @returns True if the username is available\n */\n async checkUsername(username: string): Promise<boolean> {\n const response = await this.http.get<{ available: boolean }>(\n `/api/v1/users/check-username/${encodeURIComponent(username)}`,\n undefined,\n { includeAuth: false }\n );\n return response.available;\n }\n\n /**\n * Check if an email is available.\n *\n * @param email - Email to check\n * @returns True if the email is available\n */\n async checkEmail(email: string): Promise<boolean> {\n const response = await this.http.get<{ available: boolean }>(\n `/api/v1/users/check-email/${encodeURIComponent(email)}`,\n undefined,\n { includeAuth: false }\n );\n return response.available;\n }\n\n /**\n * Get the current user's accounting service credentials.\n *\n * Returns credentials stored in SyftHub for connecting to an external\n * accounting service. The email is always the same as the user's SyftHub email.\n *\n * @returns Accounting credentials (url and password may be null if not configured)\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * const credentials = await client.users.getAccountingCredentials();\n * if (credentials.url && credentials.password) {\n * // Use credentials to connect to accounting service\n * }\n */\n async getAccountingCredentials(): Promise<AccountingCredentials> {\n return this.http.get<AccountingCredentials>('/api/v1/users/me/accounting');\n }\n\n /**\n * Send a heartbeat to indicate this SyftAI Space is alive.\n *\n * The heartbeat mechanism allows SyftAI Spaces to signal their availability\n * to SyftHub. This should be called periodically (before the TTL expires)\n * to maintain the \"active\" status.\n *\n * @param input - Heartbeat parameters\n * @param input.url - Full URL of this space (e.g., \"https://myspace.example.com\").\n * The server extracts the domain from this URL.\n * @param input.ttlSeconds - Time-to-live in seconds (1-3600). The server caps this\n * at a maximum of 600 seconds (10 minutes). Default is 300\n * seconds (5 minutes).\n * @returns HeartbeatResponse containing status, expiry time, domain, and effective TTL\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If URL or TTL is invalid\n *\n * @example\n * // Send heartbeat with default TTL (300 seconds)\n * const response = await client.users.sendHeartbeat({\n * url: 'https://myspace.example.com'\n * });\n * console.log(`Next heartbeat before: ${response.expiresAt}`);\n *\n * @example\n * // Send heartbeat with custom TTL\n * const response = await client.users.sendHeartbeat({\n * url: 'https://myspace.example.com',\n * ttlSeconds: 600 // Maximum allowed\n * });\n */\n async sendHeartbeat(input: HeartbeatInput): Promise<HeartbeatResponse> {\n const response = await this.http.post<{\n status: string;\n received_at: string;\n expires_at: string;\n domain: string;\n ttl_seconds: number;\n }>('/api/v1/users/me/heartbeat', {\n url: input.url,\n ttl_seconds: input.ttlSeconds ?? 300,\n });\n\n return {\n status: response.status,\n receivedAt: new Date(response.received_at),\n expiresAt: new Date(response.expires_at),\n domain: response.domain,\n ttlSeconds: response.ttl_seconds,\n };\n }\n}\n","/**\n * Function type for fetching a page of items.\n */\nexport type PageFetcher<T> = (skip: number, limit: number) => Promise<T[]>;\n\n/**\n * Lazy async iterator for paginated API responses.\n *\n * Fetches pages on demand as you iterate, minimizing API calls\n * and memory usage for large datasets.\n *\n * @example\n * // Iterate through all items\n * for await (const endpoint of client.hub.browse()) {\n * console.log(endpoint.name);\n * }\n *\n * @example\n * // Get just the first page\n * const firstPage = await client.hub.browse().firstPage();\n *\n * @example\n * // Get first 10 items\n * const top10 = await client.hub.browse().take(10);\n */\nexport class PageIterator<T> implements AsyncIterable<T> {\n private items: T[] = [];\n private index = 0;\n private skip = 0;\n private exhausted = false;\n private initialized = false;\n\n /**\n * Create a new PageIterator.\n *\n * @param fetcher - Function that fetches a page of items given skip and limit\n * @param pageSize - Number of items to fetch per page (default: 20)\n */\n constructor(\n private readonly fetcher: PageFetcher<T>,\n private readonly pageSize: number = 20\n ) {}\n\n /**\n * Async iterator implementation for `for await...of` loops.\n */\n async *[Symbol.asyncIterator](): AsyncIterator<T> {\n while (true) {\n // If we've consumed all items in the current page\n if (this.index >= this.items.length) {\n if (this.exhausted) break;\n await this.fetchNextPage();\n if (this.items.length === 0) break;\n }\n\n const item = this.items[this.index];\n if (item === undefined) break;\n\n this.index++;\n yield item;\n }\n }\n\n /**\n * Get just the first page of results.\n *\n * @returns Promise resolving to the first page of items\n */\n async firstPage(): Promise<T[]> {\n if (!this.initialized) {\n await this.fetchNextPage();\n }\n return [...this.items];\n }\n\n /**\n * Get all items across all pages.\n *\n * Warning: This loads all items into memory. For large datasets,\n * consider iterating with `for await...of` instead.\n *\n * @returns Promise resolving to all items\n */\n async all(): Promise<T[]> {\n const results: T[] = [];\n for await (const item of this) {\n results.push(item);\n }\n return results;\n }\n\n /**\n * Get the first N items.\n *\n * @param n - Maximum number of items to return\n * @returns Promise resolving to up to N items\n */\n async take(n: number): Promise<T[]> {\n const results: T[] = [];\n for await (const item of this) {\n results.push(item);\n if (results.length >= n) break;\n }\n return results;\n }\n\n /**\n * Fetch the next page of items from the API.\n */\n private async fetchNextPage(): Promise<void> {\n const page = await this.fetcher(this.skip, this.pageSize);\n this.items = page;\n this.index = 0;\n this.skip += this.pageSize;\n this.exhausted = page.length < this.pageSize;\n this.initialized = true;\n }\n}\n","import type { HTTPClient } from '../http.js';\nimport type {\n Endpoint,\n EndpointCreateInput,\n EndpointUpdateInput,\n SyncEndpointsResponse,\n Visibility,\n} from '../models/index.js';\nimport { PageIterator } from '../pagination.js';\n\n/**\n * Options for listing endpoints.\n */\nexport interface ListEndpointsOptions {\n /** Filter by visibility level */\n visibility?: Visibility;\n /** Number of items per page (default: 20) */\n pageSize?: number;\n}\n\n/**\n * My Endpoints resource for CRUD operations on user's own endpoints.\n *\n * For browsing public endpoints from other users, see the Hub resource.\n *\n * @example\n * // List your endpoints\n * for await (const endpoint of client.myEndpoints.list()) {\n * console.log(endpoint.name);\n * }\n *\n * @example\n * // Create a new endpoint\n * const endpoint = await client.myEndpoints.create({\n * name: 'My API',\n * type: 'model',\n * visibility: 'public',\n * description: 'A cool API'\n * });\n *\n * @example\n * // Get a specific endpoint\n * const endpoint = await client.myEndpoints.get('alice/my-api');\n *\n * @example\n * // Update an endpoint\n * const updated = await client.myEndpoints.update('alice/my-api', {\n * description: 'Updated description'\n * });\n *\n * @example\n * // Delete an endpoint\n * await client.myEndpoints.delete('alice/my-api');\n */\nexport class MyEndpointsResource {\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * Parse an endpoint path into owner and slug.\n *\n * @param path - Path in \"owner/slug\" format\n * @returns Tuple of [owner, slug]\n * @throws {Error} If path format is invalid\n */\n private parsePath(path: string): [string, string] {\n const parts = path.replace(/^\\/|\\/$/g, '').split('/');\n if (parts.length !== 2 || !parts[0] || !parts[1]) {\n throw new Error(`Invalid endpoint path: '${path}'. Expected format: 'owner/slug'`);\n }\n return [parts[0], parts[1]];\n }\n\n /**\n * List the current user's endpoints.\n *\n * @param options - Filtering and pagination options\n * @returns PageIterator that lazily fetches endpoints\n * @throws {AuthenticationError} If not authenticated\n */\n list(options?: ListEndpointsOptions): PageIterator<Endpoint> {\n const pageSize = options?.pageSize ?? 20;\n\n return new PageIterator<Endpoint>(async (skip, limit) => {\n const params: Record<string, unknown> = { skip, limit };\n if (options?.visibility) {\n params['visibility'] = options.visibility;\n }\n return this.http.get<Endpoint[]>('/api/v1/endpoints', params);\n }, pageSize);\n }\n\n /**\n * Create a new endpoint.\n *\n * @param input - Endpoint creation details\n * @returns The created Endpoint\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If input validation fails\n */\n async create(input: EndpointCreateInput): Promise<Endpoint> {\n return this.http.post<Endpoint>('/api/v1/endpoints', input);\n }\n\n /**\n * Get a specific endpoint by path.\n *\n * @param path - Endpoint path in \"owner/slug\" format (e.g., \"alice/my-api\")\n * @returns The Endpoint\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If endpoint not found\n * @throws {AuthorizationError} If not authorized to view\n */\n async get(path: string): Promise<Endpoint> {\n const [, slug] = this.parsePath(path);\n\n // Search user's own endpoints by slug\n // /api/v1/endpoints returns EndpointResponse with full details including id\n const endpoints = await this.http.get<Endpoint[]>('/api/v1/endpoints', { limit: 100 });\n\n for (const ep of endpoints) {\n if (ep.slug === slug) {\n return ep;\n }\n }\n\n // Import NotFoundError here to avoid circular dependency\n const { NotFoundError } = await import('../errors.js');\n throw new NotFoundError(\n `Endpoint not found: '${path}'. No endpoint found with slug '${slug}' in your endpoints.`\n );\n }\n\n /**\n * Update an endpoint.\n *\n * Only provided fields will be updated.\n *\n * @param path - Endpoint path in \"owner/slug\" format\n * @param input - Fields to update\n * @returns The updated Endpoint\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If endpoint not found\n * @throws {AuthorizationError} If not owner/admin\n */\n async update(path: string, input: EndpointUpdateInput): Promise<Endpoint> {\n const [, slug] = this.parsePath(path);\n // Use slug-based endpoint directly instead of resolving ID\n return this.http.patch<Endpoint>(`/api/v1/endpoints/slug/${slug}`, input);\n }\n\n /**\n * Delete an endpoint.\n *\n * @param path - Endpoint path in \"owner/slug\" format\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If endpoint not found\n * @throws {AuthorizationError} If not owner/admin\n */\n async delete(path: string): Promise<void> {\n const [, slug] = this.parsePath(path);\n // Use slug-based endpoint directly instead of resolving ID\n await this.http.delete<void>(`/api/v1/endpoints/slug/${slug}`);\n }\n\n /**\n * Synchronize user's endpoints with provided list.\n *\n * This is a DESTRUCTIVE operation that:\n * 1. Deletes ALL existing endpoints owned by the current user\n * 2. Creates ALL endpoints from the provided list\n * 3. Is ATOMIC: either all endpoints sync successfully, or none do\n *\n * Important Notes:\n * - Stars on existing endpoints will be lost (reset to 0)\n * - Endpoint IDs will change (new IDs assigned)\n * - Maximum 100 endpoints per sync request\n *\n * @param endpoints - List of endpoint specifications to sync.\n * Pass an empty array to delete ALL user endpoints.\n * @returns SyncEndpointsResponse with synced count, deleted count, and created endpoints\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If any endpoint fails validation (entire batch rejected)\n *\n * @example\n * // Sync with new endpoints\n * const result = await client.myEndpoints.sync([\n * { name: 'Model A', type: 'model', visibility: 'public' },\n * { name: 'Data Source B', type: 'data_source', visibility: 'private' },\n * ]);\n * console.log(`Deleted ${result.deleted}, created ${result.synced} endpoints`);\n *\n * @example\n * // Clear all endpoints\n * const result = await client.myEndpoints.sync([]);\n * console.log(`Deleted ${result.deleted} endpoints`);\n */\n async sync(endpoints: EndpointCreateInput[] = []): Promise<SyncEndpointsResponse> {\n return this.http.post<SyncEndpointsResponse>('/api/v1/endpoints/sync', { endpoints });\n }\n}\n","import type { HTTPClient } from '../http.js';\nimport type {\n EndpointPublic,\n EndpointSearchResult,\n EndpointSearchResponse,\n SearchOptions,\n} from '../models/index.js';\nimport { PageIterator } from '../pagination.js';\n\n/**\n * Options for browsing endpoints.\n */\nexport interface BrowseOptions {\n /** Filter by endpoint type ('model' or 'data_source') */\n endpointType?: string;\n /** Number of items per page (default: 20) */\n pageSize?: number;\n}\n\n/**\n * Options for trending endpoints.\n */\nexport interface TrendingOptions {\n /** Filter by endpoint type ('model' or 'data_source') */\n endpointType?: string;\n /** Minimum number of stars */\n minStars?: number;\n /** Number of items per page (default: 20) */\n pageSize?: number;\n}\n\n/**\n * Options for listing guest-accessible endpoints.\n */\nexport interface GuestAccessibleOptions {\n /** Filter by endpoint type ('model' or 'data_source') */\n endpointType?: string;\n /** Number of items per page (default: 20) */\n pageSize?: number;\n}\n\n/**\n * Hub resource for browsing and discovering public endpoints.\n *\n * For managing your own endpoints, see the MyEndpoints resource.\n *\n * @example\n * // Browse all public endpoints\n * for await (const endpoint of client.hub.browse()) {\n * console.log(`${endpoint.ownerUsername}/${endpoint.slug}: ${endpoint.name}`);\n * }\n *\n * @example\n * // Get trending endpoints\n * for await (const endpoint of client.hub.trending({ minStars: 10 })) {\n * console.log(`${endpoint.name} - ${endpoint.starsCount} stars`);\n * }\n *\n * @example\n * // Semantic search for endpoints\n * const results = await client.hub.search('machine learning for images');\n * for (const result of results) {\n * console.log(`${result.ownerUsername}/${result.slug}: ${result.relevanceScore.toFixed(2)}`);\n * }\n *\n * @example\n * // Get a specific endpoint\n * const endpoint = await client.hub.get('alice/cool-api');\n * console.log(endpoint.readme);\n *\n * @example\n * // Star an endpoint (requires auth)\n * await client.hub.star('alice/cool-api');\n *\n * @example\n * // Check if you've starred an endpoint\n * const starred = await client.hub.isStarred('alice/cool-api');\n */\nexport class HubResource {\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * Parse an endpoint path into owner and slug.\n *\n * @param path - Path in \"owner/slug\" format\n * @returns Tuple of [owner, slug]\n */\n private parsePath(path: string): [string, string] {\n const parts = path.replace(/^\\/|\\/$/g, '').split('/');\n if (parts.length !== 2 || !parts[0] || !parts[1]) {\n throw new Error(`Invalid endpoint path: '${path}'. Expected format: 'owner/slug'`);\n }\n return [parts[0], parts[1]];\n }\n\n /**\n * Resolve an endpoint path to its ID.\n *\n * This searches the user's own endpoints to find the ID.\n *\n * @param path - Endpoint path in \"owner/slug\" format\n * @returns The endpoint ID\n */\n private async resolveEndpointId(path: string): Promise<number> {\n const [, slug] = this.parsePath(path);\n\n // Search the user's endpoints to find the ID\n // This uses /api/v1/endpoints which returns full details including ID\n const endpoints = await this.http.get<Array<{ id?: number; slug?: string }>>(\n '/api/v1/endpoints',\n { limit: 100 }\n );\n\n for (const ep of endpoints) {\n if (ep.slug === slug && ep.id !== undefined) {\n return ep.id;\n }\n }\n\n // Import NotFoundError here to avoid circular dependency\n const { NotFoundError } = await import('../errors.js');\n throw new NotFoundError(\n `Could not resolve endpoint ID for '${path}'. ` +\n \"Endpoint not found or you don't have access to get its ID.\"\n );\n }\n\n /**\n * Browse all public endpoints.\n *\n * @param options - Filter and pagination options\n * @returns PageIterator that lazily fetches endpoints\n *\n * @example\n * // Browse only model endpoints\n * const models = await client.hub.browse({ endpointType: 'model' }).firstPage();\n */\n browse(options?: BrowseOptions): PageIterator<EndpointPublic> {\n const pageSize = options?.pageSize ?? 20;\n\n return new PageIterator<EndpointPublic>(async (skip, limit) => {\n const params: Record<string, unknown> = { skip, limit };\n if (options?.endpointType !== undefined) {\n params['endpoint_type'] = options.endpointType;\n }\n return this.http.get<EndpointPublic[]>('/api/v1/endpoints/public', params, {\n includeAuth: false,\n });\n }, pageSize);\n }\n\n /**\n * Get trending endpoints sorted by stars.\n *\n * @param options - Filter and pagination options\n * @returns PageIterator that lazily fetches endpoints\n *\n * @example\n * // Get trending models only\n * const models = await client.hub.trending({ endpointType: 'model' }).firstPage();\n */\n trending(options?: TrendingOptions): PageIterator<EndpointPublic> {\n const pageSize = options?.pageSize ?? 20;\n\n return new PageIterator<EndpointPublic>(async (skip, limit) => {\n const params: Record<string, unknown> = { skip, limit };\n if (options?.endpointType !== undefined) {\n params['endpoint_type'] = options.endpointType;\n }\n if (options?.minStars !== undefined) {\n params['min_stars'] = options.minStars;\n }\n return this.http.get<EndpointPublic[]>('/api/v1/endpoints/trending', params, {\n includeAuth: false,\n });\n }, pageSize);\n }\n\n /**\n * List endpoints accessible to unauthenticated (guest) users.\n *\n * Guest-accessible endpoints are public, active, and have no policies attached.\n * No authentication is required to call this method.\n *\n * @param options - Filter and pagination options\n * @returns PageIterator that lazily fetches guest-accessible endpoints\n *\n * @example\n * // List all guest-accessible endpoints\n * for await (const endpoint of client.hub.guestAccessible()) {\n * console.log(`${endpoint.ownerUsername}/${endpoint.slug}: ${endpoint.name}`);\n * }\n *\n * @example\n * // List only guest-accessible models\n * const models = await client.hub.guestAccessible({ endpointType: 'model' }).firstPage();\n */\n guestAccessible(options?: GuestAccessibleOptions): PageIterator<EndpointPublic> {\n const pageSize = options?.pageSize ?? 20;\n\n return new PageIterator<EndpointPublic>(async (skip, limit) => {\n const params: Record<string, unknown> = { skip, limit };\n if (options?.endpointType !== undefined) {\n params['endpoint_type'] = options.endpointType;\n }\n return this.http.get<EndpointPublic[]>('/api/v1/endpoints/guest-accessible', params, {\n includeAuth: false,\n });\n }, pageSize);\n }\n\n /**\n * Search for endpoints using semantic search.\n *\n * Uses RAG-powered semantic search to find endpoints that match the\n * natural language query. Returns results sorted by relevance score.\n *\n * Note: If RAG is not configured on the server (no OpenAI API key),\n * this method returns an empty array.\n *\n * @param query - Natural language search query (e.g., \"machine learning models for image classification\")\n * @param options - Search options (topK, type filter, minScore)\n * @returns Promise resolving to array of EndpointSearchResult with relevance scores.\n * Returns empty array if query is too short (<3 chars) or no matches found.\n *\n * @example\n * // Search for machine learning models\n * const results = await client.hub.search('image classification models');\n * for (const result of results) {\n * console.log(`${result.ownerUsername}/${result.slug}: ${result.relevanceScore.toFixed(2)}`);\n * }\n *\n * @example\n * // Filter by type and minimum score\n * const dataSources = await client.hub.search('customer data', {\n * type: EndpointType.DATA_SOURCE,\n * minScore: 0.5,\n * });\n */\n async search(query: string, options: SearchOptions = {}): Promise<EndpointSearchResult[]> {\n const { topK = 10, type, minScore = 0 } = options;\n\n // Skip search for very short queries\n if (!query || query.trim().length < 3) {\n return [];\n }\n\n const body: Record<string, unknown> = {\n query: query.trim(),\n top_k: topK,\n };\n\n if (type !== undefined) {\n body['type'] = type;\n }\n\n try {\n const response = await this.http.post<EndpointSearchResponse>(\n '/api/v1/endpoints/search',\n body,\n { includeAuth: false }\n );\n\n // Filter by minScore and return results\n return (response.results ?? []).filter((result) => result.relevanceScore >= minScore);\n } catch {\n // Return empty array on any error (e.g., RAG not configured)\n return [];\n }\n }\n\n /**\n * Get an endpoint by its path.\n *\n * This method searches the public endpoints API to find the endpoint,\n * which works reliably across all deployment configurations.\n *\n * @param path - Endpoint path in \"owner/slug\" format (e.g., \"alice/cool-api\")\n * @returns The EndpointPublic\n * @throws {NotFoundError} If endpoint not found\n */\n async get(path: string): Promise<EndpointPublic> {\n const [owner, slug] = this.parsePath(path);\n\n // Search public endpoints to find the matching one\n // This approach works because /api/v1/endpoints/public is reliably\n // served by the backend API, unlike /{owner}/{slug} which may be\n // intercepted by frontend routing in some deployments.\n for await (const endpoint of this.browse({ pageSize: 100 })) {\n if (endpoint.ownerUsername === owner && endpoint.slug === slug) {\n return endpoint;\n }\n }\n\n // Import NotFoundError here to avoid circular dependency\n const { NotFoundError } = await import('../errors.js');\n throw new NotFoundError(\n `Endpoint not found: '${path}'. No public endpoint found with owner '${owner}' and slug '${slug}'.`\n );\n }\n\n /**\n * Star an endpoint.\n *\n * @param path - Endpoint path in \"owner/slug\" format\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If endpoint not found\n */\n async star(path: string): Promise<void> {\n const endpointId = await this.resolveEndpointId(path);\n // Use POST method for starring (not PATCH)\n await this.http.post<void>(`/api/v1/endpoints/${endpointId}/star`);\n }\n\n /**\n * Unstar an endpoint.\n *\n * @param path - Endpoint path in \"owner/slug\" format\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If endpoint not found\n */\n async unstar(path: string): Promise<void> {\n const endpointId = await this.resolveEndpointId(path);\n // Use DELETE method to /star endpoint (not PATCH to /unstar)\n await this.http.delete<void>(`/api/v1/endpoints/${endpointId}/star`);\n }\n\n /**\n * Get the owner/slug paths of a collective's approved member endpoints,\n * optionally narrowed to a single shared-endpoint subset.\n *\n * Used by the chat resource to expand both `collective/<slug>` and\n * `collective/<slug>/<shared-slug>` data-source references into the\n * individual endpoint paths before building the aggregator request.\n *\n * @param slug - The collective slug (e.g. \"genomics-research\")\n * @param sharedSlug - Optional curated-subset slug. When provided, only the\n * intersection of the subset's configured endpoints with the collective's\n * currently approved members is returned. Omit for \"all approved members\".\n * @returns Array of \"owner/slug\" path strings\n * @throws {NotFoundError} If the collective (or shared endpoint) does not exist\n */\n async getCollectiveEndpointPaths(slug: string, sharedSlug?: string): Promise<string[]> {\n const base = `/api/v1/collectives/by-slug/${encodeURIComponent(slug)}`;\n const path = sharedSlug\n ? `${base}/shared-endpoints/${encodeURIComponent(sharedSlug)}/endpoint-paths`\n : `${base}/endpoint-paths`;\n return this.http.get<string[]>(path, {}, { includeAuth: false });\n }\n\n /**\n * Check if you have starred an endpoint.\n *\n * @param path - Endpoint path in \"owner/slug\" format\n * @returns True if starred, False otherwise\n * @throws {AuthenticationError} If not authenticated\n * @throws {NotFoundError} If endpoint not found\n */\n async isStarred(path: string): Promise<boolean> {\n const endpointId = await this.resolveEndpointId(path);\n const response = await this.http.get<{ starred: boolean }>(\n `/api/v1/endpoints/${endpointId}/starred`\n );\n return response.starred ?? false;\n }\n}\n","/**\n * Accounting Resource for SyftHub SDK (MPP Wallet)\n *\n * This module provides wallet management operations via the SyftHub API.\n * Payments are handled through the MPP (Micropayment Protocol) 402 flow,\n * replacing the previous external accounting service with direct wallet support.\n *\n * @example\n * ```typescript\n * // Initialize via client (after login)\n * await client.auth.login('alice', 'password');\n * await client.initAccounting();\n *\n * // Get wallet info\n * const wallet = await client.accounting.getWallet();\n * console.log(`Wallet address: ${wallet.address}`);\n *\n * // Get balance\n * const balance = await client.accounting.getBalance();\n * console.log(`Balance: ${balance.balance} ${balance.currency}`);\n *\n * // Get transactions\n * const transactions = await client.accounting.getTransactions();\n * for (const tx of transactions) {\n * console.log(`${tx.created_at}: ${tx.amount} from ${tx.sender_email}`);\n * }\n * ```\n */\n\nimport type { HTTPClient } from '../http.js';\nimport type { WalletInfo, WalletBalance, WalletTransaction } from '../models/accounting.js';\n\n// =============================================================================\n// Types\n// =============================================================================\n\n/**\n * Options for creating an AccountingResource.\n *\n * @deprecated The old AccountingResourceOptions with external service credentials\n * are no longer needed. Use the HTTPClient-based constructor instead.\n */\nexport interface AccountingResourceOptions {\n /** @deprecated No longer used - wallet API is accessed via SyftHub */\n url: string;\n /** @deprecated No longer used */\n email: string;\n /** @deprecated No longer used */\n password: string;\n /** @deprecated No longer used */\n timeout?: number;\n}\n\n/**\n * Options for listing transactions.\n *\n * @deprecated Use getTransactions() which returns all transactions directly.\n */\nexport interface TransactionsOptions {\n /** Number of items per page (default: 20) */\n pageSize?: number;\n}\n\n// =============================================================================\n// AccountingResource\n// =============================================================================\n\n/**\n * Wallet and payment operations via the SyftHub API.\n *\n * Manages MPP (Micropayment Protocol) wallets for users. Payments for\n * endpoint usage are handled automatically via the 402 payment flow\n * between the aggregator and SyftAI-Space instances.\n *\n * @example\n * ```typescript\n * // Get wallet info\n * const wallet = await client.accounting.getWallet();\n * if (!wallet.exists) {\n * // Create a new wallet\n * const result = await client.accounting.createWallet();\n * console.log(`Created wallet: ${result.address}`);\n * }\n *\n * // Check balance\n * const balance = await client.accounting.getBalance();\n * console.log(`Balance: ${balance.balance} ${balance.currency}`);\n * ```\n */\nexport class AccountingResource {\n constructor(private readonly http: HTTPClient) {}\n\n // ===========================================================================\n // Wallet Operations\n // ===========================================================================\n\n /**\n * Get the current user's wallet information.\n *\n * @returns WalletInfo with address and existence status\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * ```typescript\n * const wallet = await client.accounting.getWallet();\n * if (wallet.exists) {\n * console.log(`Wallet address: ${wallet.address}`);\n * } else {\n * console.log('No wallet configured');\n * }\n * ```\n */\n async getWallet(): Promise<WalletInfo> {\n return this.http.get<WalletInfo>('/api/v1/wallet/');\n }\n\n /**\n * Get the current user's wallet balance and recent transactions.\n *\n * @returns WalletBalance with balance, currency, and recent transactions\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * ```typescript\n * const balance = await client.accounting.getBalance();\n * console.log(`Balance: ${balance.balance} ${balance.currency}`);\n * console.log(`Wallet configured: ${balance.wallet_configured}`);\n * ```\n */\n async getBalance(): Promise<WalletBalance> {\n return this.http.get<WalletBalance>('/api/v1/wallet/balance');\n }\n\n /**\n * Get the current user's wallet transactions.\n *\n * @returns Array of WalletTransaction objects\n * @throws {AuthenticationError} If not authenticated\n *\n * @example\n * ```typescript\n * const transactions = await client.accounting.getTransactions();\n * for (const tx of transactions) {\n * console.log(`${tx.created_at}: ${tx.amount} ${tx.status}`);\n * }\n * ```\n */\n async getTransactions(): Promise<WalletTransaction[]> {\n return this.http.get<WalletTransaction[]>('/api/v1/wallet/transactions');\n }\n\n /**\n * Create a new wallet for the current user.\n *\n * Generates a new wallet with a fresh keypair. The wallet address\n * is returned and stored on the server.\n *\n * @returns Object with the new wallet address\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If user already has a wallet\n *\n * @example\n * ```typescript\n * const result = await client.accounting.createWallet();\n * console.log(`New wallet address: ${result.address}`);\n * ```\n */\n async createWallet(): Promise<{ address: string }> {\n return this.http.post<{ address: string }>('/api/v1/wallet/create', {});\n }\n\n /**\n * Import an existing wallet using a private key.\n *\n * @param privateKey - The private key to import\n * @returns Object with the imported wallet address\n * @throws {AuthenticationError} If not authenticated\n * @throws {ValidationError} If the private key is invalid\n *\n * @example\n * ```typescript\n * const result = await client.accounting.importWallet('0x...');\n * console.log(`Imported wallet address: ${result.address}`);\n * ```\n */\n async importWallet(privateKey: string): Promise<{ address: string }> {\n return this.http.post<{ address: string }>('/api/v1/wallet/import', {\n private_key: privateKey,\n });\n }\n}\n\n// =============================================================================\n// Factory Function\n// =============================================================================\n\n/**\n * Create a new AccountingResource instance.\n *\n * @deprecated Use the SyftHubClient's built-in accounting resource instead.\n * The wallet API is now accessed through the SyftHub HTTP client, not\n * a separate external service.\n *\n * @param options - Configuration options (ignored, kept for backward compatibility)\n * @returns AccountingResource instance\n */\nexport function createAccountingResource(options: AccountingResourceOptions): AccountingResource {\n void options;\n throw new Error(\n 'createAccountingResource() is deprecated. ' +\n 'The wallet API is now accessed through the SyftHubClient. ' +\n 'Use client.initAccounting() after login instead.'\n );\n}\n","/**\n * Agent resource for bidirectional agent sessions via WebSocket.\n *\n * @example\n * const session = await client.agent.startSession({\n * prompt: 'Help me refactor this code',\n * endpoint: 'alice/code-assistant',\n * });\n *\n * for await (const event of session.events()) {\n * switch (event.type) {\n * case 'agent.message':\n * console.log(event.payload.content);\n * break;\n * case 'agent.tool_call':\n * if (event.payload.requires_confirmation) {\n * await session.confirm(event.payload.tool_call_id);\n * }\n * break;\n * }\n * }\n */\n\nimport { SyftHubError } from '../errors.js';\nimport type { AgentEvent, AgentSessionOptions, AgentSessionState } from '../models/agent.js';\nimport type { AuthResource } from './auth.js';\n\n/**\n * Error thrown during agent session operations.\n */\nexport class AgentSessionError extends SyftHubError {\n constructor(\n message: string,\n public readonly code?: string\n ) {\n super(message);\n this.name = 'AgentSessionError';\n }\n}\n\n/**\n * AgentResource manages agent session lifecycle.\n */\nexport class AgentResource {\n constructor(\n private readonly auth: AuthResource,\n private readonly aggregatorUrl: string\n ) {}\n\n /**\n * Start a new agent session.\n *\n * @param options - Session options including prompt, endpoint, and config\n * @returns An AgentSessionClient for interacting with the session\n */\n async startSession(options: AgentSessionOptions): Promise<AgentSessionClient> {\n // Parse endpoint\n let owner: string;\n let slug: string;\n if (typeof options.endpoint === 'string') {\n const parts = options.endpoint.split('/');\n if (parts.length !== 2) {\n throw new AgentSessionError(\n `Endpoint must be in 'owner/slug' format, got: ${options.endpoint}`\n );\n }\n owner = parts[0]!;\n slug = parts[1]!;\n } else {\n owner = options.endpoint.owner;\n slug = options.endpoint.slug;\n }\n\n // Fetch satellite token\n const satResponse = await this.auth.getSatelliteToken(owner);\n\n // Fetch peer token for tunneling\n const peerResponse = await this.auth.getPeerToken([owner]);\n\n // Build WebSocket URL\n const wsUrl = this.aggregatorUrl.replace(/^http/, 'ws') + '/agent/session';\n\n // Create WebSocket\n const ws = new WebSocket(wsUrl);\n\n // Wait for connection\n await new Promise<void>((resolve, reject) => {\n const onOpen = () => {\n ws.removeEventListener('error', onError);\n resolve();\n };\n const onError = (_e: Event) => {\n ws.removeEventListener('open', onOpen);\n reject(new AgentSessionError('Failed to connect to agent WebSocket'));\n };\n ws.addEventListener('open', onOpen, { once: true });\n ws.addEventListener('error', onError, { once: true });\n\n // Handle abort signal\n if (options.signal) {\n options.signal.addEventListener(\n 'abort',\n () => {\n ws.close();\n reject(new AgentSessionError('Session start aborted'));\n },\n { once: true }\n );\n }\n });\n\n // Send session.start\n const startPayload: Record<string, unknown> = {\n prompt: options.prompt,\n endpoint: { owner, slug },\n satellite_token: satResponse.targetToken,\n peer_token: peerResponse.peerToken,\n peer_channel: peerResponse.peerChannel,\n };\n if (options.config) {\n startPayload.config = options.config;\n }\n if (options.messages) {\n startPayload.messages = options.messages;\n }\n\n ws.send(\n JSON.stringify({\n type: 'session.start',\n payload: startPayload,\n })\n );\n\n // Wait for session.created response\n const response = await new Promise<{ session_id: string }>((resolve, reject) => {\n const onMessage = (event: MessageEvent) => {\n try {\n const data = JSON.parse(event.data as string);\n if (data.type === 'session.created') {\n ws.removeEventListener('message', onMessage);\n resolve({\n session_id: data.session_id || data.payload?.session_id,\n });\n } else if (data.type === 'agent.error') {\n ws.removeEventListener('message', onMessage);\n reject(\n new AgentSessionError(\n data.payload?.message || 'Session start failed',\n data.payload?.code\n )\n );\n }\n } catch {\n reject(new AgentSessionError('Failed to parse session response'));\n }\n };\n ws.addEventListener('message', onMessage);\n });\n\n return new AgentSessionClient(ws, response.session_id);\n }\n}\n\n/**\n * Client for an active agent session.\n * Provides both async iterable and callback-based APIs for receiving events.\n */\nexport class AgentSessionClient {\n private _state: AgentSessionState = 'running';\n private _sequenceCounter = 0;\n private _messageQueue: AgentEvent[] = [];\n private _messageResolvers: Array<(value: AgentEvent | null) => void> = [];\n private _closed = false;\n\n constructor(\n private readonly ws: WebSocket,\n public readonly sessionId: string\n ) {\n this.ws.addEventListener('message', (event: MessageEvent) => {\n this._handleMessage(event);\n });\n this.ws.addEventListener('close', () => {\n this._handleClose();\n });\n this.ws.addEventListener('error', () => {\n this._state = 'error';\n this._handleClose();\n });\n }\n\n /** Current session state */\n get state(): AgentSessionState {\n return this._state;\n }\n\n /**\n * Async generator yielding agent events.\n *\n * @example\n * for await (const event of session.events()) {\n * console.log(event.type, event.payload);\n * }\n */\n async *events(): AsyncGenerator<AgentEvent> {\n while (!this._closed) {\n const event = await this._nextEvent();\n if (event === null) break;\n yield event;\n }\n }\n\n /**\n * Register an event handler.\n *\n * @param eventType - The event type to listen for, or '*' for all events\n * @param handler - Callback function\n */\n on(eventType: string, handler: (event: AgentEvent) => void): void {\n this.ws.addEventListener('message', (msgEvent: MessageEvent) => {\n try {\n const data = JSON.parse(msgEvent.data as string) as AgentEvent;\n if (eventType === '*' || data.type === eventType) {\n handler(data);\n }\n } catch {\n // Ignore parse errors\n }\n });\n }\n\n /** Send a user message to the agent */\n sendMessage(content: string): void {\n this._send({\n type: 'user.message',\n payload: { content },\n });\n }\n\n /** Confirm a tool call */\n confirm(toolCallId: string): void {\n this._send({\n type: 'user.confirm',\n payload: { tool_call_id: toolCallId },\n });\n }\n\n /** Deny a tool call */\n deny(toolCallId: string, reason?: string): void {\n this._send({\n type: 'user.deny',\n payload: { tool_call_id: toolCallId, reason },\n });\n }\n\n /** Cancel the session */\n cancel(): void {\n this._state = 'cancelled';\n this._send({ type: 'user.cancel' });\n }\n\n /** Close the session and WebSocket */\n close(): void {\n if (this._closed) return;\n this._send({ type: 'session.close' });\n this.ws.close();\n this._handleClose();\n }\n\n // ---- Internal ----\n\n private _send(msg: Record<string, unknown>): void {\n if (this.ws.readyState === WebSocket.OPEN) {\n this.ws.send(JSON.stringify(msg));\n }\n }\n\n private _handleMessage(event: MessageEvent): void {\n try {\n const data = JSON.parse(event.data as string) as AgentEvent & {\n session_id?: string;\n sequence?: number;\n };\n this._sequenceCounter++;\n\n // Update state based on event type\n switch (data.type) {\n case 'agent.request_input':\n this._state = 'awaiting_input';\n break;\n case 'session.completed':\n this._state = 'completed';\n break;\n case 'session.failed':\n this._state = 'failed';\n break;\n case 'agent.error':\n if (!(data as { payload: { recoverable: boolean } }).payload.recoverable) {\n this._state = 'error';\n }\n break;\n default:\n if (this._state === 'awaiting_input' || this._state === 'connecting') {\n this._state = 'running';\n }\n }\n\n // Deliver to async generator or queue\n if (this._messageResolvers.length > 0) {\n const resolve = this._messageResolvers.shift()!;\n resolve(data);\n } else {\n this._messageQueue.push(data);\n }\n\n // Handle terminal states\n if (data.type === 'session.completed' || data.type === 'session.failed') {\n this._handleClose();\n }\n } catch {\n // Ignore parse errors\n }\n }\n\n private _handleClose(): void {\n if (this._closed) return;\n this._closed = true;\n\n // Resolve all pending waiters with null\n for (const resolve of this._messageResolvers) {\n resolve(null);\n }\n this._messageResolvers = [];\n }\n\n private _nextEvent(): Promise<AgentEvent | null> {\n // Return queued event if available\n if (this._messageQueue.length > 0) {\n return Promise.resolve(this._messageQueue.shift()!);\n }\n\n // If closed, return null\n if (this._closed) {\n return Promise.resolve(null);\n }\n\n // Wait for next event\n return new Promise<AgentEvent | null>((resolve) => {\n this._messageResolvers.push(resolve);\n });\n }\n}\n","/**\n * Chat resource for RAG-augmented conversations via the Aggregator service.\n *\n * This resource handles satellite token authentication automatically:\n * - Resolves endpoints and extracts owner information\n * - Exchanges Hub access tokens for satellite tokens (one per unique owner)\n * - Sends tokens to the aggregator for forwarding to SyftAI-Space\n *\n * @example\n * // Simple chat completion\n * const response = await client.chat.complete({\n * prompt: 'What is machine learning?',\n * model: 'alice/gpt-model',\n * dataSources: ['bob/ml-docs'],\n * });\n * console.log(response.response);\n *\n * // Streaming chat\n * for await (const event of client.chat.stream(options)) {\n * if (event.type === 'token') {\n * process.stdout.write(event.content);\n * }\n * }\n */\n\nimport type { EndpointPublic } from '../models/index.js';\nimport type {\n Billing,\n BillingEntry,\n ChatMetadata,\n ChatOptions,\n ChatResponse,\n ChatStreamEvent,\n DocumentSource,\n EndpointRef,\n Message,\n Recipient,\n SearchDocument,\n SearchQueryOptions,\n SearchResponse,\n SourceInfo,\n SourceStatus,\n TokenUsage,\n Transaction,\n} from '../models/chat.js';\nimport { SyftHubError } from '../errors.js';\nimport { readSSEEvents } from '../utils.js';\nimport type { HubResource } from './hub.js';\nimport type { AuthResource } from './auth.js';\nimport { EndpointType } from '../models/index.js';\n\n/**\n * Error thrown when the aggregator service is unavailable or returns an error.\n */\nexport class AggregatorError extends SyftHubError {\n constructor(\n message: string,\n public readonly status?: number,\n public readonly detail?: unknown,\n /**\n * Billing/policy metadata the aggregator may attach even on an error\n * response — a paid query can be REJECTED yet still carry a charge that\n * must be surfaced (and possibly refunded).\n */\n public readonly billing?: Billing\n ) {\n super(message);\n this.name = 'AggregatorError';\n }\n}\n\n/**\n * Error thrown when an endpoint cannot be resolved.\n */\nexport class EndpointResolutionError extends SyftHubError {\n constructor(\n message: string,\n public readonly endpointPath?: string\n ) {\n super(message);\n this.name = 'EndpointResolutionError';\n }\n}\n\n/**\n * Chat resource for RAG-augmented conversations via the Aggregator.\n *\n * This resource provides high-level chat functionality that:\n * - Queries data sources for relevant context (retrieval)\n * - Sends prompts with context to model endpoints (generation)\n * - Supports both synchronous and streaming responses\n */\nexport class ChatResource {\n constructor(\n private readonly hub: HubResource,\n private readonly auth: AuthResource,\n private readonly aggregatorUrl: string\n ) {}\n\n /**\n * Check if an endpoint type matches the expected type.\n * A model_data_source endpoint matches both 'model' and 'data_source'.\n */\n private static typeMatches(actualType: string, expectedType: string): boolean {\n if (actualType === expectedType) return true;\n if (actualType === EndpointType.MODEL_DATA_SOURCE) {\n return expectedType === EndpointType.MODEL || expectedType === EndpointType.DATA_SOURCE;\n }\n // Agent endpoints can be used where model endpoints are expected\n if (actualType === EndpointType.AGENT && expectedType === EndpointType.MODEL) {\n return true;\n }\n return false;\n }\n\n /**\n * Convert any endpoint format to EndpointRef with URL and owner info.\n * The ownerUsername is critical for satellite token authentication.\n */\n private async resolveEndpointRef(\n endpoint: string | EndpointRef | EndpointPublic,\n expectedType?: 'model' | 'data_source'\n ): Promise<EndpointRef> {\n // Already an EndpointRef\n if (this.isEndpointRef(endpoint)) {\n return endpoint;\n }\n\n // EndpointPublic object\n if (this.isEndpointPublic(endpoint)) {\n // Validate type if expected (model_data_source matches both model and data_source)\n if (expectedType && !ChatResource.typeMatches(endpoint.type, expectedType)) {\n throw new Error(\n `Expected endpoint type '${expectedType}', got '${endpoint.type}' for '${endpoint.slug}'`\n );\n }\n\n // Find first enabled connection with URL\n for (const conn of endpoint.connect) {\n if (conn.enabled && conn.config['url']) {\n return {\n url: String(conn.config['url']),\n slug: endpoint.slug,\n name: endpoint.name,\n tenantName: conn.config['tenant_name'] as string | undefined,\n ownerUsername: endpoint.ownerUsername, // Capture owner for satellite token\n };\n }\n }\n\n throw new EndpointResolutionError(\n `Endpoint '${endpoint.slug}' has no connection with URL configured`,\n `${endpoint.ownerUsername}/${endpoint.slug}`\n );\n }\n\n // String path format \"owner/slug\"\n if (typeof endpoint === 'string') {\n let ep: EndpointPublic;\n try {\n ep = await this.hub.get(endpoint);\n } catch (error) {\n throw new EndpointResolutionError(\n `Failed to fetch endpoint '${endpoint}': ${error instanceof Error ? error.message : String(error)}`,\n endpoint\n );\n }\n return this.resolveEndpointRef(ep, expectedType);\n }\n\n throw new TypeError(`Cannot resolve endpoint from type: ${typeof endpoint}`);\n }\n\n /**\n * Collect unique owner usernames from all endpoints.\n * Used to determine which satellite tokens need to be fetched.\n */\n private collectUniqueOwners(modelRef: EndpointRef, dataSourceRefs: EndpointRef[]): string[] {\n const owners = new Set<string>();\n\n if (modelRef.ownerUsername) {\n owners.add(modelRef.ownerUsername);\n }\n\n for (const ds of dataSourceRefs) {\n if (ds.ownerUsername) {\n owners.add(ds.ownerUsername);\n }\n }\n\n return [...owners];\n }\n\n /**\n * Get satellite tokens for all unique endpoint owners.\n * Returns a map of owner username to satellite token.\n *\n * @param owners - Array of unique owner usernames\n * @param guestMode - If true, fetch guest tokens (no auth required)\n */\n private async getSatelliteTokensForOwners(\n owners: string[],\n guestMode = false\n ): Promise<Record<string, string>> {\n if (owners.length === 0) {\n return {};\n }\n\n const tokenMap = guestMode\n ? await this.auth.getGuestSatelliteTokens(owners)\n : await this.auth.getSatelliteTokens(owners);\n const result: Record<string, string> = {};\n\n for (const [owner, token] of tokenMap) {\n result[owner] = token;\n }\n\n return result;\n }\n\n /**\n * Get the user's Hub access token for MPP payment flow.\n * Returns null if in guest mode or not authenticated.\n */\n private getUserToken(): string | null {\n return this.auth.getAccessToken();\n }\n\n /**\n * Type guard for EndpointRef.\n */\n private isEndpointRef(value: unknown): value is EndpointRef {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'url' in value &&\n 'slug' in value &&\n typeof (value as EndpointRef).url === 'string' &&\n typeof (value as EndpointRef).slug === 'string'\n );\n }\n\n /**\n * Type guard for EndpointPublic.\n */\n private isEndpointPublic(value: unknown): value is EndpointPublic {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'connect' in value &&\n 'ownerUsername' in value &&\n Array.isArray((value as EndpointPublic).connect)\n );\n }\n\n private static readonly COLLECTIVE_PREFIX = 'collective/';\n private static readonly TUNNELING_PREFIX = 'tunneling:';\n\n /**\n * Expand any `collective/<slug>` (or `collective/<slug>/<shared-slug>`)\n * entries in the data-sources list into the individual `owner/slug` paths\n * of the collective's approved members.\n *\n * Path forms recognised:\n * - `collective/<slug>` → every approved member (backward-compatible)\n * - `collective/<slug>/all` → equivalent alias of the above\n * - `collective/<slug>/<shared-slug>` → the named subset, intersected with\n * the collective's currently approved members\n *\n * Non-collective entries pass through unchanged. String paths are\n * deduplicated so a regular endpoint that also belongs to a selected\n * collective is not queried twice.\n */\n private async expandCollectivePaths(\n dataSources: (string | EndpointRef | EndpointPublic)[]\n ): Promise<(string | EndpointRef | EndpointPublic)[]> {\n const expanded: (string | EndpointRef | EndpointPublic)[] = [];\n const seenPaths = new Set<string>();\n\n for (const ds of dataSources) {\n if (typeof ds === 'string' && ds.startsWith(ChatResource.COLLECTIVE_PREFIX)) {\n const rest = ds.slice(ChatResource.COLLECTIVE_PREFIX.length);\n const slashAt = rest.indexOf('/');\n const collectiveSlug = slashAt < 0 ? rest : rest.slice(0, slashAt);\n // `all` is the implicit alias of \"every approved member\" and maps to\n // the same hub route as the no-subset form, so the SDK normalises it\n // away rather than round-tripping a degenerate identifier.\n const rawShared = slashAt < 0 ? undefined : rest.slice(slashAt + 1);\n const sharedSlug = rawShared && rawShared !== 'all' ? rawShared : undefined;\n\n if (!collectiveSlug) {\n throw new EndpointResolutionError(`Malformed collective path: ${ds}`, ds);\n }\n\n let memberPaths: string[];\n try {\n memberPaths = await this.hub.getCollectiveEndpointPaths(collectiveSlug, sharedSlug);\n } catch (error) {\n const target = sharedSlug ? `${collectiveSlug}/${sharedSlug}` : collectiveSlug;\n throw new EndpointResolutionError(\n `Failed to resolve collective '${target}': ${error instanceof Error ? error.message : String(error)}`,\n ds\n );\n }\n for (const path of memberPaths) {\n if (!seenPaths.has(path)) {\n seenPaths.add(path);\n expanded.push(path);\n }\n }\n } else if (typeof ds === 'string') {\n if (!seenPaths.has(ds)) {\n seenPaths.add(ds);\n expanded.push(ds);\n }\n } else {\n // EndpointRef or EndpointPublic — pass through without dedup\n expanded.push(ds);\n }\n }\n\n return expanded;\n }\n\n /**\n * Check if any endpoints use tunneling URLs and extract target usernames.\n */\n private collectTunnelingUsernames(\n modelRef: EndpointRef,\n dataSourceRefs: EndpointRef[]\n ): string[] {\n const usernames = new Set<string>();\n\n if (modelRef.url.startsWith(ChatResource.TUNNELING_PREFIX)) {\n usernames.add(modelRef.url.slice(ChatResource.TUNNELING_PREFIX.length));\n }\n\n for (const ds of dataSourceRefs) {\n if (ds.url.startsWith(ChatResource.TUNNELING_PREFIX)) {\n usernames.add(ds.url.slice(ChatResource.TUNNELING_PREFIX.length));\n }\n }\n\n return [...usernames];\n }\n\n /**\n * Shared request preparation for complete() and stream().\n * Resolves endpoints, fetches tokens, and builds the aggregator request body.\n * Returns the request body and the resolved aggregator URL.\n */\n private async prepareRequest(\n options: ChatOptions,\n stream: boolean,\n retrievalOnly = false\n ): Promise<{ requestBody: Record<string, unknown>; effectiveAggregatorUrl: string }> {\n const modelRef = await this.resolveEndpointRef(options.model, 'model');\n\n // Expand any collective/<slug> paths into their approved member endpoint paths.\n const expandedDataSources = await this.expandCollectivePaths(options.dataSources ?? []);\n\n const dsRefs: EndpointRef[] = [];\n for (const ds of expandedDataSources) {\n dsRefs.push(await this.resolveEndpointRef(ds, 'data_source'));\n }\n\n const uniqueOwners = this.collectUniqueOwners(modelRef, dsRefs);\n const guestMode = options.guestMode ?? false;\n const endpointTokens = await this.getSatelliteTokensForOwners(uniqueOwners, guestMode);\n const userToken = guestMode ? null : this.getUserToken();\n\n let peerToken = options.peerToken;\n let peerChannel = options.peerChannel;\n if (!peerToken) {\n const tunnelingUsernames = this.collectTunnelingUsernames(modelRef, dsRefs);\n if (tunnelingUsernames.length > 0) {\n const peerResponse = guestMode\n ? await this.auth.getGuestPeerToken(tunnelingUsernames)\n : await this.auth.getPeerToken(tunnelingUsernames);\n peerToken = peerResponse.peerToken;\n peerChannel = peerResponse.peerChannel;\n }\n }\n\n const requestBody = this.buildRequestBody(\n options.prompt,\n modelRef,\n dsRefs,\n endpointTokens,\n userToken,\n {\n topK: options.topK,\n maxTokens: options.maxTokens,\n temperature: options.temperature,\n similarityThreshold: options.similarityThreshold,\n stream,\n messages: options.messages,\n peerToken,\n peerChannel,\n retrievalOnly,\n }\n );\n\n const effectiveAggregatorUrl = (options.aggregatorUrl ?? this.aggregatorUrl).replace(\n /\\/+$/,\n ''\n );\n\n return { requestBody, effectiveAggregatorUrl };\n }\n\n /**\n * Parse an error response from the aggregator into an AggregatorError.\n */\n private async handleAggregatorErrorResponse(response: Response): Promise<never> {\n let message = `HTTP ${response.status}`;\n let billing: Billing | undefined;\n try {\n const data = (await response.json()) as Record<string, unknown>;\n message = String(data['message'] ?? data['error'] ?? data['detail'] ?? message);\n // A paid query can be REJECTED yet still carry a billing block.\n billing = this.parseBilling(data);\n } catch {\n // Use default message\n }\n throw new AggregatorError(`Aggregator error: ${message}`, response.status, undefined, billing);\n }\n\n /**\n * Build the request body for the aggregator.\n * Includes endpoint_tokens mapping for satellite token authentication.\n * Includes user_token for MPP payment callback authorization.\n * User identity is derived from satellite tokens, not passed in request body.\n */\n private buildRequestBody(\n prompt: string,\n modelRef: EndpointRef,\n dataSourceRefs: EndpointRef[],\n endpointTokens: Record<string, string>,\n userToken: string | null,\n options: {\n topK?: number;\n maxTokens?: number;\n temperature?: number;\n similarityThreshold?: number;\n stream?: boolean;\n messages?: Message[];\n peerToken?: string;\n peerChannel?: string;\n retrievalOnly?: boolean;\n }\n ): Record<string, unknown> {\n const body: Record<string, unknown> = {\n prompt,\n model: {\n url: modelRef.url,\n slug: modelRef.slug,\n name: modelRef.name ?? '',\n tenant_name: modelRef.tenantName ?? null,\n owner_username: modelRef.ownerUsername ?? null,\n },\n data_sources: dataSourceRefs.map((ds) => ({\n url: ds.url,\n slug: ds.slug,\n name: ds.name ?? '',\n tenant_name: ds.tenantName ?? null,\n owner_username: ds.ownerUsername ?? null,\n })),\n endpoint_tokens: endpointTokens,\n top_k: options.topK ?? 5,\n max_tokens: options.maxTokens ?? 1024,\n temperature: options.temperature ?? 0.7,\n similarity_threshold: options.similarityThreshold ?? 0.5,\n stream: options.stream ?? false,\n };\n\n // Include user token for MPP payment flow\n if (userToken) {\n body['user_token'] = userToken;\n }\n\n if (options.messages && options.messages.length > 0) {\n body.messages = options.messages.map((m) => ({ role: m.role, content: m.content }));\n }\n\n // Include peer token fields for NATS tunneling\n if (options.peerToken) {\n body['peer_token'] = options.peerToken;\n }\n if (options.peerChannel) {\n body['peer_channel'] = options.peerChannel;\n }\n\n // Retrieval-only: aggregator skips reranking + generation.\n if (options.retrievalOnly) {\n body['retrieval_only'] = true;\n }\n\n return body;\n }\n\n /**\n * Parse a SourceInfo from raw data.\n */\n private parseSourceInfo(data: Record<string, unknown>): SourceInfo {\n return {\n path: String(data['path'] ?? ''),\n documentsRetrieved: Number(data['documents_retrieved'] ?? 0),\n status: (data['status'] as SourceStatus) ?? 'success',\n errorMessage: data['error_message'] as string | undefined,\n };\n }\n\n /**\n * Parse ChatMetadata from raw data.\n */\n private parseMetadata(data: Record<string, unknown>): ChatMetadata {\n return {\n retrievalTimeMs: Number(data['retrieval_time_ms'] ?? 0),\n generationTimeMs: Number(data['generation_time_ms'] ?? 0),\n totalTimeMs: Number(data['total_time_ms'] ?? 0),\n };\n }\n\n /**\n * Parse TokenUsage from raw data.\n */\n private parseUsage(data: Record<string, unknown>): TokenUsage {\n return {\n promptTokens: Number(data['prompt_tokens'] ?? 0),\n completionTokens: Number(data['completion_tokens'] ?? 0),\n totalTokens: Number(data['total_tokens'] ?? 0),\n };\n }\n\n /**\n * Parse a single billing/policy-metadata entry from a raw (snake_case) dict.\n *\n * Shared by {@link parseBilling} (aggregated, carries `source`) and the\n * direct-path `policy_metadata` parsing in {@link SyftAIResource}.\n */\n static parseBillingEntry(raw: Record<string, unknown>): BillingEntry {\n const recipientRaw = raw['recipient'] as Record<string, unknown> | null | undefined;\n const recipient: Recipient | undefined =\n recipientRaw && typeof recipientRaw === 'object'\n ? {\n username: recipientRaw['username'] as string | undefined,\n email: recipientRaw['email'] as string | undefined,\n walletAddress: recipientRaw['wallet_address'] as string | undefined,\n }\n : undefined;\n\n const transactionRaw = raw['transaction'] as Record<string, unknown> | null | undefined;\n const transaction: Transaction | undefined =\n transactionRaw && typeof transactionRaw === 'object'\n ? {\n rail: String(transactionRaw['rail'] ?? ''),\n id: String(transactionRaw['id'] ?? ''),\n reference: transactionRaw['reference'] as string | undefined,\n }\n : undefined;\n\n return {\n source: raw['source'] as string | undefined,\n policyType: String(raw['policy_type'] ?? ''),\n kind: String(raw['kind'] ?? ''),\n status: String(raw['status'] ?? ''),\n amount: raw['amount'] == null ? undefined : Number(raw['amount']),\n currency: raw['currency'] as string | undefined,\n recipient,\n transaction,\n reasonCode: raw['reason_code'] as string | undefined,\n reason: raw['reason'] as string | undefined,\n details: (raw['details'] as Record<string, unknown>) ?? {},\n };\n }\n\n /**\n * Parse the aggregated `billing` block from a raw aggregator response.\n *\n * Returns undefined when no `billing` object is present (e.g. an error body\n * with no policy metadata). The wire keys are snake_case.\n */\n private parseBilling(data: Record<string, unknown>): Billing | undefined {\n const b = data['billing'];\n if (!b || typeof b !== 'object') {\n return undefined;\n }\n const billing = b as Record<string, unknown>;\n const entriesRaw = Array.isArray(billing['entries']) ? billing['entries'] : [];\n return {\n totalCost: billing['total_cost'] == null ? null : Number(billing['total_cost']),\n currency: (billing['currency'] as string | null) ?? null,\n entries: (entriesRaw as Record<string, unknown>[]).map((e) =>\n ChatResource.parseBillingEntry(e)\n ),\n };\n }\n\n /**\n * Parse document sources from raw data.\n * The new format is a dict mapping document title to {slug, content}.\n */\n private parseDocumentSources(\n data: Record<string, unknown> | undefined\n ): Record<string, DocumentSource> {\n const sources: Record<string, DocumentSource> = {};\n if (!data || typeof data !== 'object') {\n return sources;\n }\n\n for (const [title, value] of Object.entries(data)) {\n if (value && typeof value === 'object') {\n const source = value as Record<string, unknown>;\n sources[title] = {\n slug: String(source['slug'] ?? ''),\n content: String(source['content'] ?? ''),\n };\n }\n }\n return sources;\n }\n\n /**\n * Parse retrieval info (SourceInfo array) from raw data.\n */\n private parseRetrievalInfo(data: Record<string, unknown>[] | undefined): SourceInfo[] {\n const retrievalInfo: SourceInfo[] = [];\n if (!Array.isArray(data)) {\n return retrievalInfo;\n }\n\n for (const item of data) {\n retrievalInfo.push(this.parseSourceInfo(item));\n }\n return retrievalInfo;\n }\n\n /**\n * Send a chat request and get the complete response.\n *\n * This method automatically:\n * 1. Resolves endpoints and extracts owner information\n * 2. Exchanges Hub tokens for satellite tokens (one per unique owner)\n * 3. Passes the user's Hub access token for MPP payment authorization\n * 4. Sends tokens to the aggregator for forwarding to SyftAI-Space\n *\n * @param options - Chat completion options\n * @returns ChatResponse with response text, sources, and metadata\n * @throws {EndpointResolutionError} If endpoint cannot be resolved\n * @throws {AggregatorError} If aggregator service fails\n */\n async complete(options: ChatOptions): Promise<ChatResponse> {\n const { requestBody, effectiveAggregatorUrl } = await this.prepareRequest(options, false);\n\n const response = await fetch(`${effectiveAggregatorUrl}/chat`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(requestBody),\n });\n\n if (!response.ok) {\n return this.handleAggregatorErrorResponse(response);\n }\n\n const data = (await response.json()) as Record<string, unknown>;\n\n // Parse document sources (new format: dict of title -> {slug, content})\n const sourcesData = data['sources'] as Record<string, unknown> | undefined;\n const sources = this.parseDocumentSources(sourcesData);\n\n // Parse retrieval info (metadata about each data source retrieval)\n const retrievalInfoData = data['retrieval_info'] as Record<string, unknown>[] | undefined;\n const retrievalInfo = this.parseRetrievalInfo(retrievalInfoData);\n\n const metadataData = data['metadata'] as Record<string, unknown> | undefined;\n const metadata = this.parseMetadata(metadataData ?? {});\n\n // Parse usage if available\n const usageData = data['usage'] as Record<string, unknown> | undefined;\n const usage = usageData ? this.parseUsage(usageData) : undefined;\n\n // Parse profit share if available\n const profitShare = data['profit_share'] as Record<string, number> | undefined;\n\n // Parse aggregated billing/policy metadata if available\n const billing = this.parseBilling(data);\n\n return {\n response: String(data['response'] ?? ''),\n sources,\n retrievalInfo,\n metadata,\n usage,\n profitShare,\n billing,\n };\n }\n\n /**\n * Placeholder model for retrieval-only requests. The aggregator requires a\n * `model` field on every request, but short-circuits before dereferencing it\n * when `retrieval_only` is set, so an empty ref is never contacted.\n */\n private static readonly RETRIEVAL_ONLY_MODEL: EndpointRef = {\n url: '',\n slug: '',\n name: 'retrieval-only',\n };\n\n /**\n * Retrieve documents from data sources without model generation.\n *\n * Drives the aggregator's retrieval-only path: data sources are queried in\n * parallel (with satellite-token auth and MPP payment handled server-side,\n * exactly like {@link complete}), but no model is invoked.\n *\n * Prefer the symmetric `client.search.query(...)` facade; this is the\n * underlying primitive.\n *\n * @param options - Search options\n * @returns SearchResponse with retrieved documents and per-source metadata\n * @throws {EndpointResolutionError} If a data source cannot be resolved\n * @throws {AggregatorError} If the aggregator service fails\n */\n async retrieve(options: SearchQueryOptions): Promise<SearchResponse> {\n const chatOptions: ChatOptions = {\n prompt: options.prompt,\n model: ChatResource.RETRIEVAL_ONLY_MODEL,\n dataSources: options.dataSources,\n topK: options.topK,\n similarityThreshold: options.similarityThreshold,\n aggregatorUrl: options.aggregatorUrl,\n guestMode: options.guestMode,\n };\n\n const { requestBody, effectiveAggregatorUrl } = await this.prepareRequest(\n chatOptions,\n false,\n true\n );\n\n const response = await fetch(`${effectiveAggregatorUrl}/chat`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(requestBody),\n signal: options.signal,\n });\n\n if (!response.ok) {\n return this.handleAggregatorErrorResponse(response);\n }\n\n const data = (await response.json()) as Record<string, unknown>;\n\n const sources = this.parseDocumentSources(\n data['sources'] as Record<string, unknown> | undefined\n );\n const documents: SearchDocument[] = Object.entries(sources).map(([title, source]) => ({\n title,\n slug: source.slug,\n content: source.content,\n }));\n\n const retrievalInfo = this.parseRetrievalInfo(\n data['retrieval_info'] as Record<string, unknown>[] | undefined\n );\n const metadata = this.parseMetadata((data['metadata'] as Record<string, unknown>) ?? {});\n\n const billing = this.parseBilling(data);\n\n return { documents, retrievalInfo, metadata, billing };\n }\n\n /**\n * Send a chat request and stream response events.\n *\n * This method automatically:\n * 1. Resolves endpoints and extracts owner information\n * 2. Exchanges Hub tokens for satellite tokens (one per unique owner)\n * 3. Passes the user's Hub access token for MPP payment authorization\n * 4. Sends tokens to the aggregator for forwarding to SyftAI-Space\n *\n * @param options - Chat completion options\n * @yields ChatStreamEvent objects as they arrive\n */\n async *stream(options: ChatOptions): AsyncGenerator<ChatStreamEvent, void, unknown> {\n const { requestBody, effectiveAggregatorUrl } = await this.prepareRequest(options, true);\n\n const response = await fetch(`${effectiveAggregatorUrl}/chat/stream`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Accept: 'text/event-stream',\n },\n body: JSON.stringify(requestBody),\n signal: options.signal,\n });\n\n if (!response.ok) {\n return this.handleAggregatorErrorResponse(response);\n }\n\n if (!response.body) {\n throw new AggregatorError('No response body from aggregator');\n }\n\n for await (const { event: eventName, data: dataStr } of readSSEEvents(response)) {\n if (eventName === 'message') continue; // chat protocol always names events\n try {\n const data = JSON.parse(dataStr) as Record<string, unknown>;\n const event = this.parseSSEEvent(eventName, data);\n if (event) {\n yield event;\n }\n } catch {\n yield { type: 'error', message: `Failed to parse SSE data: ${dataStr}` };\n }\n }\n }\n\n /**\n * Parse an SSE event into a typed event object.\n */\n private parseSSEEvent(eventType: string, data: Record<string, unknown>): ChatStreamEvent | null {\n switch (eventType) {\n case 'retrieval_start':\n return {\n type: 'retrieval_start',\n sourceCount: Number(data['sources'] ?? 0),\n };\n\n case 'source_complete':\n return {\n type: 'source_complete',\n path: String(data['path'] ?? ''),\n status: String(data['status'] ?? ''),\n documentsRetrieved: Number(data['documents'] ?? 0),\n };\n\n case 'retrieval_complete':\n return {\n type: 'retrieval_complete',\n totalDocuments: Number(data['total_documents'] ?? 0),\n timeMs: Number(data['time_ms'] ?? 0),\n };\n\n case 'reranking_start':\n return {\n type: 'reranking_start',\n documents: Number(data['documents'] ?? 0),\n };\n\n case 'reranking_complete':\n return {\n type: 'reranking_complete',\n documents: Number(data['documents'] ?? 0),\n timeMs: Number(data['time_ms'] ?? 0),\n };\n\n case 'generation_start':\n return { type: 'generation_start' };\n\n case 'generation_heartbeat':\n return {\n type: 'generation_heartbeat',\n elapsedMs: Number(data['elapsed_ms'] ?? 0),\n };\n\n case 'token':\n return {\n type: 'token',\n content: String(data['content'] ?? ''),\n };\n\n case 'done': {\n // Parse document sources (new format: dict of title -> {slug, content})\n const sourcesData = data['sources'] as Record<string, unknown> | undefined;\n const sources = this.parseDocumentSources(sourcesData);\n\n // Parse retrieval info (metadata about each data source retrieval)\n const retrievalInfoData = data['retrieval_info'] as Record<string, unknown>[] | undefined;\n const retrievalInfo = this.parseRetrievalInfo(retrievalInfoData);\n\n const metadataData = data['metadata'] as Record<string, unknown> | undefined;\n const metadata = this.parseMetadata(metadataData ?? {});\n\n // Parse usage if available (only from non-streaming mode)\n const usageData = data['usage'] as Record<string, unknown> | undefined;\n const usage = usageData ? this.parseUsage(usageData) : undefined;\n\n // Parse profit share if available\n const profitShare = data['profit_share'] as Record<string, number> | undefined;\n\n // Parse aggregated billing/policy metadata if available\n const billing = this.parseBilling(data);\n\n // Parse clean response (cite-tag-stripped) if attribution ran\n const response = data['response'] as string | undefined;\n\n return {\n type: 'done',\n sources,\n retrievalInfo,\n metadata,\n usage,\n profitShare,\n billing,\n response,\n };\n }\n\n case 'error':\n return {\n type: 'error',\n message: String(data['message'] ?? 'Unknown error'),\n billing: this.parseBilling(data),\n };\n\n default:\n console.warn(`[SyftHub] Unknown SSE event type received from aggregator: ${eventType}`);\n return {\n type: 'error',\n message: `Unknown event type: ${eventType}`,\n };\n }\n }\n\n private async getAvailableEndpoints(\n endpointType: EndpointType,\n limit: number\n ): Promise<EndpointPublic[]> {\n const results: EndpointPublic[] = [];\n\n for await (const endpoint of this.hub.browse()) {\n if (results.length >= limit) break;\n if (endpoint.type !== endpointType) continue;\n if (endpoint.connect.some((conn) => conn.enabled && conn.config['url'])) {\n results.push(endpoint);\n }\n }\n\n return results;\n }\n\n /**\n * Get model endpoints that have connection URLs configured.\n *\n * @param limit - Maximum number of results (default: 20)\n * @returns Array of EndpointPublic objects for models with URLs\n */\n async getAvailableModels(limit = 20): Promise<EndpointPublic[]> {\n return this.getAvailableEndpoints(EndpointType.MODEL, limit);\n }\n\n /**\n * Get data source endpoints that have connection URLs configured.\n *\n * @param limit - Maximum number of results (default: 20)\n * @returns Array of EndpointPublic objects for data sources with URLs\n */\n async getAvailableDataSources(limit = 20): Promise<EndpointPublic[]> {\n return this.getAvailableEndpoints(EndpointType.DATA_SOURCE, limit);\n }\n}\n","/**\n * Visibility levels for endpoints.\n */\nexport const Visibility = {\n /** Visible to everyone, no authentication required */\n PUBLIC: 'public',\n /** Only visible to the owner and collaborators */\n PRIVATE: 'private',\n /** Behaves like private — only visible to the owner */\n INTERNAL: 'internal',\n} as const;\n\nexport type Visibility = (typeof Visibility)[keyof typeof Visibility];\n\n/**\n * Types of endpoints.\n */\nexport const EndpointType = {\n /** Machine learning model endpoint */\n MODEL: 'model',\n /** Data source endpoint */\n DATA_SOURCE: 'data_source',\n /** Both model and data source endpoint */\n MODEL_DATA_SOURCE: 'model_data_source',\n /** Agent endpoint with session-based interaction */\n AGENT: 'agent',\n} as const;\n\nexport type EndpointType = (typeof EndpointType)[keyof typeof EndpointType];\n\n/**\n * User roles in the system.\n */\nexport const UserRole = {\n /** Administrator with full access */\n ADMIN: 'admin',\n /** Regular user */\n USER: 'user',\n /** Guest user with limited access */\n GUEST: 'guest',\n} as const;\n\nexport type UserRole = (typeof UserRole)[keyof typeof UserRole];\n","import type { EndpointType, Visibility } from './common.js';\n\n/**\n * Policy configuration for an endpoint.\n */\nexport interface Policy {\n readonly type: string;\n readonly version: string;\n readonly enabled: boolean;\n readonly description: string;\n readonly config: Record<string, unknown>;\n}\n\n/**\n * Connection configuration for an endpoint.\n */\nexport interface Connection {\n readonly type: string;\n readonly enabled: boolean;\n readonly description: string;\n readonly config: Record<string, unknown>;\n}\n\n/**\n * Full endpoint model (for authenticated users viewing their own endpoints).\n */\nexport interface Endpoint {\n readonly id: number;\n readonly userId: number;\n readonly name: string;\n readonly slug: string;\n readonly description: string;\n readonly type: EndpointType;\n readonly visibility: Visibility;\n readonly isActive: boolean;\n readonly contributors: readonly number[];\n readonly version: string;\n readonly readme: string;\n readonly tags: readonly string[];\n readonly starsCount: number;\n readonly policies: readonly Policy[];\n readonly connect: readonly Connection[];\n readonly createdAt: Date;\n readonly updatedAt: Date;\n}\n\n/**\n * Public endpoint model (for browsing the hub).\n */\nexport interface EndpointPublic {\n readonly name: string;\n readonly slug: string;\n readonly description: string;\n readonly type: EndpointType;\n readonly ownerUsername: string;\n /** Number of contributors (user IDs not exposed for privacy) */\n readonly contributorsCount: number;\n readonly version: string;\n readonly readme: string;\n readonly tags: readonly string[];\n readonly starsCount: number;\n readonly policies: readonly Policy[];\n readonly connect: readonly Connection[];\n readonly createdAt: Date;\n readonly updatedAt: Date;\n}\n\n/**\n * Search result with relevance score from semantic search.\n *\n * Extends the public endpoint fields with a relevance score indicating\n * how well the endpoint matches the search query.\n */\nexport interface EndpointSearchResult {\n readonly name: string;\n readonly slug: string;\n readonly description: string;\n readonly type: EndpointType;\n readonly ownerUsername: string;\n /** Number of contributors (user IDs not exposed for privacy) */\n readonly contributorsCount: number;\n readonly version: string;\n readonly readme: string;\n readonly tags: readonly string[];\n readonly starsCount: number;\n readonly policies: readonly Policy[];\n readonly connect: readonly Connection[];\n readonly createdAt: Date;\n readonly updatedAt: Date;\n /** Relevance score from semantic search (0.0-1.0) */\n readonly relevanceScore: number;\n}\n\n/**\n * Response from the endpoint search API.\n */\nexport interface EndpointSearchResponse {\n readonly results: readonly EndpointSearchResult[];\n readonly total: number;\n readonly query: string;\n}\n\n/**\n * Options for semantic search.\n */\nexport interface SearchOptions {\n /** Maximum number of results to return (default: 10) */\n topK?: number;\n /** Filter by endpoint type */\n type?: EndpointType;\n /** Minimum relevance score threshold (0.0-1.0, default: 0.0) */\n minScore?: number;\n}\n\n/**\n * Get the full path for a search result (owner/slug format).\n *\n * @param result - The search result\n * @returns The path in \"owner/slug\" format\n */\nexport function getSearchResultPath(result: EndpointSearchResult): string {\n return `${result.ownerUsername}/${result.slug}`;\n}\n\n/**\n * Input for creating a new endpoint.\n */\nexport interface EndpointCreateInput {\n name: string;\n type: EndpointType;\n visibility?: Visibility;\n description?: string;\n slug?: string;\n version?: string;\n readme?: string;\n tags?: string[];\n policies?: Policy[];\n connect?: Connection[];\n contributors?: number[];\n}\n\n/**\n * Input for updating an existing endpoint.\n */\nexport interface EndpointUpdateInput {\n name?: string;\n description?: string;\n visibility?: Visibility;\n version?: string;\n readme?: string;\n tags?: string[];\n policies?: Policy[];\n connect?: Connection[];\n contributors?: number[];\n}\n\n/**\n * Get the full path for a public endpoint (owner/slug format).\n *\n * @param endpoint - The public endpoint\n * @returns The path in \"owner/slug\" format\n */\nexport function getEndpointPublicPath(endpoint: EndpointPublic): string {\n return `${endpoint.ownerUsername}/${endpoint.slug}`;\n}\n\n/**\n * Response from the sync endpoints operation.\n *\n * Contains details about the sync operation including how many endpoints\n * were deleted, how many were created, and the full list of created endpoints.\n */\nexport interface SyncEndpointsResponse {\n /** Number of endpoints created */\n readonly synced: number;\n /** Number of endpoints deleted */\n readonly deleted: number;\n /** List of created endpoints with full details */\n readonly endpoints: readonly Endpoint[];\n}\n","/**\n * Search resource for retrieval-only queries via the Aggregator service.\n *\n * Symmetric counterpart to {@link ChatResource}: where `client.chat.complete()`\n * retrieves context *and* generates a model response, `client.search.query()`\n * retrieves documents from data sources without invoking any model.\n *\n * @example\n * // Symmetric to client.chat.complete(...)\n * const result = await client.search.query({\n * prompt: 'What happened at EPFL this week?',\n * dataSources: ['epfl-news/epfl-news'],\n * });\n * for (const doc of result.documents) {\n * console.log(doc.title, '->', doc.content.slice(0, 80));\n * }\n *\n * Authentication and billing are handled by the aggregator exactly as for chat:\n * satellite tokens are minted per data source owner, and metered endpoints that\n * respond with `402 Payment Required` are settled via the user's Hub wallet.\n */\n\nimport type { SearchQueryOptions, SearchResponse } from '../models/chat.js';\nimport type { ChatResource } from './chat.js';\n\n/**\n * Retrieval-only search via the Aggregator.\n *\n * Thin facade over {@link ChatResource.retrieve}, exposed as `client.search` to\n * mirror the shape of `client.chat`.\n */\nexport class SearchResource {\n /**\n * @param chat - The chat resource that owns aggregator communication and\n * request preparation (satellite tokens, MPP, collective expansion). Search\n * reuses it rather than duplicating that logic.\n */\n constructor(private readonly chat: ChatResource) {}\n\n /**\n * Retrieve documents from data sources without model generation.\n *\n * @param options - Search options (prompt, data sources, top-k, etc.)\n * @returns SearchResponse with retrieved documents and per-source metadata\n *\n * @example\n * const result = await client.search.query({\n * prompt: 'Hello, world!',\n * dataSources: ['epfl-news/epfl-news'],\n * });\n * console.log(result.documents.length, 'documents');\n */\n async query(options: SearchQueryOptions): Promise<SearchResponse> {\n return this.chat.retrieve(options);\n }\n}\n","/**\n * SyftAI-Space resource for direct endpoint queries.\n *\n * This module provides low-level access to SyftAI-Space endpoints, allowing\n * users to build custom RAG pipelines or bypass the aggregator service.\n *\n * @example\n * // Query a data source directly\n * const docs = await client.syftai.queryDataSource({\n * endpoint: { url: 'http://syftai:8080', slug: 'docs' },\n * query: 'What is machine learning?',\n * userEmail: 'alice@example.com',\n * });\n *\n * // Query a model directly\n * const response = await client.syftai.queryModel({\n * endpoint: { url: 'http://syftai:8080', slug: 'gpt-model' },\n * messages: [\n * { role: 'system', content: 'You are a helpful assistant.' },\n * { role: 'user', content: 'Hello!' },\n * ],\n * userEmail: 'alice@example.com',\n * });\n */\n\nimport type {\n DataSourceQueryResult,\n Document,\n PolicyMetadata,\n QueryDataSourceOptions,\n QueryModelOptions,\n} from '../models/chat.js';\nimport type { HTTPClient } from '../http.js';\nimport { SyftHubError } from '../errors.js';\nimport { readSSEEvents } from '../utils.js';\nimport { ChatResource } from './chat.js';\n\n/**\n * Error thrown when data source retrieval fails.\n */\nexport class RetrievalError extends SyftHubError {\n constructor(\n message: string,\n public readonly sourcePath?: string,\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'RetrievalError';\n }\n}\n\n/**\n * Error thrown when model generation fails.\n */\nexport class GenerationError extends SyftHubError {\n constructor(\n message: string,\n public readonly modelSlug?: string,\n public readonly detail?: unknown\n ) {\n super(message);\n this.name = 'GenerationError';\n }\n}\n\n/**\n * Low-level resource for direct SyftAI-Space endpoint queries.\n *\n * This resource provides direct access to SyftAI-Space endpoints without\n * going through the aggregator. Use this when you need:\n * - Custom RAG pipelines with specific retrieval strategies\n * - Direct model queries without data source context\n * - Fine-grained control over the query process\n *\n * For most use cases, prefer the higher-level `client.chat` API instead.\n */\nexport class SyftAIResource {\n /**\n * @param http - Hub HTTP client, used to mint satellite tokens and settle\n * MPP payments. Endpoint queries themselves use direct `fetch`, since the\n * SyftAI-Space URL is arbitrary and not the Hub base URL.\n */\n constructor(private readonly http: HTTPClient) {}\n\n /**\n * Mint a satellite token for `audience` (the endpoint owner's username).\n *\n * Mirrors the aggregator's token coordination layer: try an authenticated\n * token first, then fall back to a guest token. Returns `undefined` if both\n * fail, so the caller can still attempt an unauthenticated request.\n */\n private async mintSatelliteToken(audience: string): Promise<string | undefined> {\n if (this.http.hasTokens()) {\n try {\n const res = await this.http.get<{ targetToken?: string }>('/api/v1/token', {\n aud: audience,\n });\n if (res.targetToken) return res.targetToken;\n } catch {\n // fall through to guest\n }\n }\n try {\n const res = await this.http.get<{ targetToken?: string }>(\n '/api/v1/token/guest',\n { aud: audience },\n { includeAuth: false }\n );\n return res.targetToken;\n } catch {\n return undefined;\n }\n }\n\n /**\n * Pay an MPP `402` challenge via the Hub wallet, returning an X-Payment credential.\n *\n * Mirrors the aggregator's `handleMppPayment`: the `WWW-Authenticate`\n * challenge is forwarded verbatim to the Hub's `/api/v1/wallet/pay`, which\n * parses it and returns an `x_payment` string to attach to a retry.\n */\n private async payMpp(wwwAuthenticate: string, slug: string): Promise<string | undefined> {\n if (!wwwAuthenticate) return undefined;\n const res = await this.http.post<{ xPayment?: string }>('/api/v1/wallet/pay', {\n wwwAuthenticate,\n endpointSlug: slug,\n });\n return res.xPayment;\n }\n\n /**\n * Build headers for SyftAI-Space request.\n */\n private buildHeaders(tenantName?: string, authorizationToken?: string): Record<string, string> {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n if (tenantName) {\n headers['X-Tenant-Name'] = tenantName;\n }\n if (authorizationToken) {\n headers['Authorization'] = `Bearer ${authorizationToken}`;\n }\n return headers;\n }\n\n /**\n * Parse documents from a SyftAI-Space query response.\n *\n * Mirrors the aggregator's `DataSourceClient._parse_syftai_response`: the\n * canonical shape nests documents under `references.documents` and names the\n * score `similarity_score`. A legacy top-level `documents` list (with\n * `score`) is still honoured for backward compatibility.\n */\n private parseDocuments(data: Record<string, unknown>): Document[] {\n const references = data['references'] as Record<string, unknown> | undefined;\n let rawDocs: Record<string, unknown>[] | undefined;\n let scoreKey = 'score';\n if (references && typeof references === 'object') {\n rawDocs = references['documents'] as Record<string, unknown>[] | undefined;\n scoreKey = 'similarity_score';\n } else {\n rawDocs = data['documents'] as Record<string, unknown>[] | undefined;\n }\n\n const documents: Document[] = [];\n if (Array.isArray(rawDocs)) {\n for (const doc of rawDocs) {\n documents.push({\n content: String(doc['content'] ?? ''),\n score: Number(doc[scoreKey] ?? doc['score'] ?? 0),\n metadata: (doc['metadata'] as Record<string, unknown>) ?? {},\n });\n }\n }\n return documents;\n }\n\n /**\n * Parse the raw `policy_metadata` block from a syft-space response.\n *\n * The direct path (Boundary A) carries a top-level `policy_metadata` object\n * shaped `{ outcome, entries: [...] }`. Entries reuse the {@link BillingEntry}\n * shape (with `source` absent), so this delegates entry parsing to\n * {@link ChatResource.parseBillingEntry}. The wire keys are snake_case.\n */\n private parsePolicyMetadata(data: Record<string, unknown>): PolicyMetadata | undefined {\n const pm = data['policy_metadata'];\n if (!pm || typeof pm !== 'object') {\n return undefined;\n }\n const meta = pm as Record<string, unknown>;\n const entriesRaw = Array.isArray(meta['entries']) ? meta['entries'] : [];\n return {\n outcome: String(meta['outcome'] ?? ''),\n entries: (entriesRaw as Record<string, unknown>[]).map((e) =>\n ChatResource.parseBillingEntry(e)\n ),\n };\n }\n\n /**\n * Query a data source endpoint directly.\n *\n * Authentication mirrors the aggregator: SyftAI-Space endpoints expect a\n * satellite bearer token whose audience is the endpoint owner's username. If\n * `authorizationToken` is not supplied, one is minted automatically when an\n * owner is known (`ownerUsername` option or `endpoint.ownerUsername`).\n *\n * @param options - Query options\n * @returns DataSourceQueryResult — the retrieved documents plus the raw\n * `policyMetadata` block from the syft-space response (price, recipient,\n * transaction, status).\n * @throws {RetrievalError} If the query fails\n */\n async queryDataSource(options: QueryDataSourceOptions): Promise<DataSourceQueryResult> {\n const {\n endpoint,\n query,\n userEmail,\n topK = 5,\n similarityThreshold = 0.5,\n authorizationToken,\n ownerUsername,\n pay = false,\n } = options;\n\n const url = `${endpoint.url.replace(/\\/$/, '')}/api/v1/endpoints/${endpoint.slug}/query`;\n\n const requestBody = {\n user_email: userEmail,\n messages: query, // SyftAI-Space expects \"messages\" for query text\n limit: topK,\n similarity_threshold: similarityThreshold,\n };\n\n // Resolve a satellite token: caller-supplied, else mint from the owner.\n let token = authorizationToken;\n if (!token) {\n const audience = ownerUsername ?? endpoint.ownerUsername;\n if (audience) {\n token = await this.mintSatelliteToken(audience);\n }\n }\n const headers = this.buildHeaders(endpoint.tenantName, token);\n\n const postQuery = async (extraHeaders?: Record<string, string>): Promise<Response> => {\n try {\n return await fetch(url, {\n method: 'POST',\n headers: { ...headers, ...extraHeaders },\n body: JSON.stringify(requestBody),\n });\n } catch (error) {\n throw new RetrievalError(\n `Failed to connect to data source '${endpoint.slug}': ${error instanceof Error ? error.message : String(error)}`,\n endpoint.slug,\n error\n );\n }\n };\n\n let response = await postQuery();\n\n // MPP 402 payment flow: pay via the Hub wallet, then retry with X-Payment.\n if (response.status === 402 && pay) {\n let xPayment: string | undefined;\n try {\n xPayment = await this.payMpp(response.headers.get('www-authenticate') ?? '', endpoint.slug);\n } catch (error) {\n throw new RetrievalError(\n `Payment failed for data source '${endpoint.slug}': ${error instanceof Error ? error.message : String(error)}`,\n endpoint.slug,\n error\n );\n }\n if (xPayment) {\n response = await postQuery({ 'X-Payment': xPayment });\n }\n }\n\n if (!response.ok) {\n let message = `HTTP ${response.status}`;\n try {\n const data = (await response.json()) as Record<string, unknown>;\n message = String(data['detail'] ?? data['message'] ?? message);\n } catch {\n // Use default message\n }\n throw new RetrievalError(`Data source query failed: ${message}`, endpoint.slug);\n }\n\n const data = (await response.json()) as Record<string, unknown>;\n\n return {\n documents: this.parseDocuments(data),\n policyMetadata: this.parsePolicyMetadata(data),\n };\n }\n\n /**\n * Query a model endpoint directly.\n *\n * @param options - Query options\n * @returns Generated response text\n * @throws {GenerationError} If generation fails\n */\n async queryModel(options: QueryModelOptions): Promise<string> {\n const { endpoint, messages, userEmail, maxTokens = 1024, temperature = 0.7 } = options;\n\n const url = `${endpoint.url.replace(/\\/$/, '')}/api/v1/endpoints/${endpoint.slug}/query`;\n\n const requestBody = {\n user_email: userEmail,\n messages: messages.map((msg) => ({\n role: msg.role,\n content: msg.content,\n })),\n max_tokens: maxTokens,\n temperature,\n stream: false,\n };\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: 'POST',\n headers: this.buildHeaders(endpoint.tenantName),\n body: JSON.stringify(requestBody),\n });\n } catch (error) {\n throw new GenerationError(\n `Failed to connect to model '${endpoint.slug}': ${error instanceof Error ? error.message : String(error)}`,\n endpoint.slug,\n error\n );\n }\n\n if (!response.ok) {\n let message = `HTTP ${response.status}`;\n try {\n const data = (await response.json()) as Record<string, unknown>;\n message = String(data['detail'] ?? data['message'] ?? message);\n } catch {\n // Use default message\n }\n throw new GenerationError(`Model query failed: ${message}`, endpoint.slug);\n }\n\n const data = (await response.json()) as Record<string, unknown>;\n const messageData = data['message'] as Record<string, unknown> | undefined;\n return String(messageData?.['content'] ?? '');\n }\n\n /**\n * Stream a model response directly.\n *\n * @param options - Query options\n * @yields Response text chunks as they arrive\n * @throws {GenerationError} If generation fails\n */\n async *queryModelStream(options: QueryModelOptions): AsyncGenerator<string, void, unknown> {\n const { endpoint, messages, userEmail, maxTokens = 1024, temperature = 0.7 } = options;\n\n const url = `${endpoint.url.replace(/\\/$/, '')}/api/v1/endpoints/${endpoint.slug}/query`;\n\n const requestBody = {\n user_email: userEmail,\n messages: messages.map((msg) => ({\n role: msg.role,\n content: msg.content,\n })),\n max_tokens: maxTokens,\n temperature,\n stream: true,\n };\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: 'POST',\n headers: {\n ...this.buildHeaders(endpoint.tenantName),\n Accept: 'text/event-stream',\n },\n body: JSON.stringify(requestBody),\n });\n } catch (error) {\n throw new GenerationError(\n `Failed to connect to model '${endpoint.slug}': ${error instanceof Error ? error.message : String(error)}`,\n endpoint.slug,\n error\n );\n }\n\n if (!response.ok) {\n let message = `HTTP ${response.status}`;\n try {\n const data = (await response.json()) as Record<string, unknown>;\n message = String(data['detail'] ?? data['message'] ?? message);\n } catch {\n // Use default message\n }\n throw new GenerationError(`Model stream failed: ${message}`, endpoint.slug);\n }\n\n if (!response.body) {\n throw new GenerationError('No response body from model', endpoint.slug);\n }\n\n for await (const { data: dataStr } of readSSEEvents(response)) {\n if (dataStr === '[DONE]') return;\n\n try {\n const data = JSON.parse(dataStr) as Record<string, unknown>;\n\n // Extract content from various response formats\n if (typeof data['content'] === 'string') {\n yield data['content'];\n } else if (Array.isArray(data['choices'])) {\n // OpenAI-style response\n for (const choice of data['choices'] as Record<string, unknown>[]) {\n const delta = choice['delta'] as Record<string, unknown> | undefined;\n if (delta && typeof delta['content'] === 'string') {\n yield delta['content'];\n }\n }\n }\n } catch {\n // Skip malformed data\n }\n }\n }\n}\n","/**\n * SyftHub TypeScript SDK\n *\n * A TypeScript client library for the SyftHub API.\n *\n * @example\n * import { SyftHubClient, EndpointType, Visibility } from '@syfthub/sdk';\n *\n * const client = new SyftHubClient({ baseUrl: 'https://hub.syft.com' });\n *\n * // Login\n * const user = await client.auth.login('alice', 'password');\n *\n * // Create an endpoint\n * const endpoint = await client.myEndpoints.create({\n * name: 'My Model',\n * type: EndpointType.MODEL,\n * visibility: Visibility.PUBLIC,\n * });\n *\n * // Browse the hub\n * for await (const ep of client.hub.browse()) {\n * console.log(ep.name);\n * }\n *\n * // Chat with RAG via aggregator\n * const response = await client.chat.complete({\n * prompt: 'What is machine learning?',\n * model: 'alice/gpt-model',\n * dataSources: ['bob/ml-docs'],\n * });\n * console.log(response.response);\n *\n * // Streaming chat\n * for await (const event of client.chat.stream(options)) {\n * if (event.type === 'token') {\n * process.stdout.write(event.content);\n * }\n * }\n *\n * @packageDocumentation\n */\n\n// Main client\nexport { SyftHubClient } from './client.js';\nexport type { SyftHubClientOptions } from './client.js';\n\n// HTTP types (for advanced usage)\nexport type { AuthTokens } from './http.js';\n\n// Errors\nexport {\n SyftHubError,\n APIError,\n AuthenticationError,\n AuthorizationError,\n NotFoundError,\n ValidationError,\n NetworkError,\n ConfigurationError,\n // User registration errors\n UserAlreadyExistsError,\n // Accounting-related errors\n AccountingAccountExistsError,\n InvalidAccountingPasswordError,\n AccountingServiceUnavailableError,\n} from './errors.js';\n\n// Chat-specific errors\nexport { AggregatorError, EndpointResolutionError } from './resources/chat.js';\nexport { RetrievalError, GenerationError } from './resources/syftai.js';\n\n// Pagination\nexport { PageIterator } from './pagination.js';\nexport type { PageFetcher } from './pagination.js';\n\n// Models - Enums and constants\nexport { Visibility, EndpointType, UserRole } from './models/index.js';\n\n// Models - Types\nexport type {\n // User types\n User,\n UserRegisterInput,\n UserUpdateInput,\n PasswordChangeInput,\n RegisterResult,\n VerifyOTPInput,\n PasswordResetRequestInput,\n PasswordResetConfirmInput,\n AuthConfig,\n AccountingCredentials,\n HeartbeatInput,\n HeartbeatResponse,\n UserAggregator,\n UserAggregatorCreateInput,\n UserAggregatorUpdateInput,\n // Endpoint types\n Policy,\n Connection,\n Endpoint,\n EndpointPublic,\n EndpointCreateInput,\n EndpointUpdateInput,\n SyncEndpointsResponse,\n // API Token types\n APIToken,\n APITokenScope,\n APITokenCreateResponse,\n CreateAPITokenInput,\n UpdateAPITokenInput,\n APITokenListResponse,\n // Wallet types\n WalletInfo,\n WalletBalance,\n WalletTransaction,\n TransactionTokensResponse,\n // Chat types\n EndpointRef,\n Document,\n DocumentSource,\n SourceStatus,\n ReasonCode,\n SourceInfo,\n ChatMetadata,\n ChatResponse,\n Message,\n ChatOptions,\n SearchDocument,\n SearchQueryOptions,\n SearchResponse,\n DataSourceQueryResult,\n QueryDataSourceOptions,\n QueryModelOptions,\n // Billing / policy metadata\n Recipient,\n Transaction,\n BillingEntry,\n Billing,\n PolicyMetadata,\n // Chat streaming events\n ChatStreamEvent,\n RetrievalStartEvent,\n SourceCompleteEvent,\n RetrievalCompleteEvent,\n GenerationStartEvent,\n TokenEvent,\n DoneEvent,\n ErrorEvent,\n} from './models/index.js';\n\n// Model helpers\nexport { getEndpointPublicPath } from './models/index.js';\n\n// Accounting Resource (MPP wallet operations)\nexport { AccountingResource, createAccountingResource } from './resources/accounting.js';\nexport type { AccountingResourceOptions, TransactionsOptions } from './resources/accounting.js';\n\n// Agent Resource and types\nexport { AgentResource, AgentSessionClient, AgentSessionError } from './resources/agent.js';\nexport type {\n AgentEvent,\n AgentSessionState,\n AgentSessionOptions,\n AgentConfig,\n AgentHistoryMessage,\n ThinkingEvent as AgentThinkingEvent,\n ToolCallEvent as AgentToolCallEvent,\n ToolResultEvent as AgentToolResultEvent,\n AgentMessageEvent,\n TokenEvent as AgentTokenEvent,\n StatusEvent as AgentStatusEvent,\n RequestInputEvent as AgentRequestInputEvent,\n SessionCreatedEvent as AgentSessionCreatedEvent,\n SessionCompletedEvent as AgentSessionCompletedEvent,\n SessionFailedEvent as AgentSessionFailedEvent,\n AgentErrorEvent,\n} from './models/agent.js';\n\n// Chat Resource (for type hints)\nexport { ChatResource } from './resources/chat.js';\n\n// Search Resource (retrieval-only via the Aggregator)\nexport { SearchResource } from './resources/search.js';\n\n// SyftAI Resource (for type hints)\nexport { SyftAIResource } from './resources/syftai.js';\n\n// API Tokens Resource (for type hints)\nexport { APITokensResource } from './resources/api-tokens.js';\n\n// Aggregators Resource (for type hints)\nexport { AggregatorsResource } from './resources/aggregators.js';\n\n// Resource option types (for type-safe usage)\nexport type { ListEndpointsOptions } from './resources/my-endpoints.js';\nexport type { BrowseOptions, TrendingOptions } from './resources/hub.js';\n"]}
|