@providerprotocol/ai 0.0.39 → 0.0.40

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.
Files changed (130) hide show
  1. package/README.md +269 -34
  2. package/dist/anthropic/index.d.ts +3 -3
  3. package/dist/anthropic/index.js +7 -5
  4. package/dist/anthropic/index.js.map +1 -1
  5. package/dist/cerebras/index.d.ts +3 -3
  6. package/dist/cerebras/index.js +7 -5
  7. package/dist/cerebras/index.js.map +1 -1
  8. package/dist/{chunk-WU4U6IHF.js → chunk-6QCV4WXF.js} +4 -13
  9. package/dist/chunk-6QCV4WXF.js.map +1 -0
  10. package/dist/{chunk-5XPRVUOK.js → chunk-AC3VHSZJ.js} +2 -2
  11. package/dist/{chunk-5XPRVUOK.js.map → chunk-AC3VHSZJ.js.map} +1 -1
  12. package/dist/{chunk-ZDYEDI2A.js → chunk-CWGTARDE.js} +2 -2
  13. package/dist/{chunk-KNBODIQU.js → chunk-DI47UY2H.js} +2 -2
  14. package/dist/{chunk-KNBODIQU.js.map → chunk-DI47UY2H.js.map} +1 -1
  15. package/dist/{chunk-IDZR4ROP.js → chunk-EHR3LIPS.js} +2 -2
  16. package/dist/{chunk-IDZR4ROP.js.map → chunk-EHR3LIPS.js.map} +1 -1
  17. package/dist/chunk-EY2LLDGY.js +94 -0
  18. package/dist/chunk-EY2LLDGY.js.map +1 -0
  19. package/dist/{chunk-MJI74VEJ.js → chunk-F5ENANMJ.js} +18 -2
  20. package/dist/chunk-F5ENANMJ.js.map +1 -0
  21. package/dist/chunk-IKJH5ZSJ.js +1 -0
  22. package/dist/chunk-IKJH5ZSJ.js.map +1 -0
  23. package/dist/{chunk-IIMTP3XC.js → chunk-KBI45OXI.js} +2 -2
  24. package/dist/{chunk-SAMIK4WZ.js → chunk-KVUOTFYZ.js} +2 -2
  25. package/dist/{chunk-U6M3MXNI.js → chunk-L6QWKFGE.js} +3 -2
  26. package/dist/chunk-L6QWKFGE.js.map +1 -0
  27. package/dist/{chunk-RDC5GYST.js → chunk-N4LAFGLX.js} +7 -7
  28. package/dist/{chunk-ZKNPQBIE.js → chunk-R3T2IYOU.js} +5 -3
  29. package/dist/{chunk-ZKNPQBIE.js.map → chunk-R3T2IYOU.js.map} +1 -1
  30. package/dist/chunk-U2G5PHHL.js +25 -0
  31. package/dist/chunk-U2G5PHHL.js.map +1 -0
  32. package/dist/{chunk-SBGZJVTJ.js → chunk-VQZPADW6.js} +100 -33
  33. package/dist/chunk-VQZPADW6.js.map +1 -0
  34. package/dist/{chunk-O32SBS6S.js → chunk-XTWBAL42.js} +2 -2
  35. package/dist/{chunk-O32SBS6S.js.map → chunk-XTWBAL42.js.map} +1 -1
  36. package/dist/{chunk-WNB5PSY6.js → chunk-ZMESKGUY.js} +2 -2
  37. package/dist/{chunk-7ULSRWDH.js → chunk-ZSZVWLGE.js} +2 -2
  38. package/dist/{embedding-iNQCeXfk.d.ts → embedding-ts1npsDg.d.ts} +1 -1
  39. package/dist/google/index.d.ts +38 -4
  40. package/dist/google/index.js +5 -4
  41. package/dist/google/index.js.map +1 -1
  42. package/dist/groq/index.d.ts +3 -3
  43. package/dist/groq/index.js +7 -5
  44. package/dist/groq/index.js.map +1 -1
  45. package/dist/http/index.d.ts +5 -5
  46. package/dist/http/index.js +19 -22
  47. package/dist/{image-stream-ARno6XlS.d.ts → image-stream-BPml2YZZ.d.ts} +1 -1
  48. package/dist/index.d.ts +8 -8
  49. package/dist/index.js +306 -112
  50. package/dist/index.js.map +1 -1
  51. package/dist/{llm-CZqlijjK.d.ts → llm-BWLaTzzY.d.ts} +75 -29
  52. package/dist/middleware/logging/index.d.ts +3 -3
  53. package/dist/middleware/logging/index.js +3 -0
  54. package/dist/middleware/logging/index.js.map +1 -1
  55. package/dist/middleware/parsed-object/index.d.ts +3 -3
  56. package/dist/middleware/parsed-object/index.js +5 -1
  57. package/dist/middleware/parsed-object/index.js.map +1 -1
  58. package/dist/middleware/persistence/index.d.ts +3 -3
  59. package/dist/middleware/persistence/index.js +3 -2
  60. package/dist/middleware/persistence/index.js.map +1 -1
  61. package/dist/middleware/pipeline/index.d.ts +195 -0
  62. package/dist/middleware/pipeline/index.js +61 -0
  63. package/dist/middleware/pipeline/index.js.map +1 -0
  64. package/dist/middleware/pubsub/index.d.ts +13 -11
  65. package/dist/middleware/pubsub/index.js +31 -5
  66. package/dist/middleware/pubsub/index.js.map +1 -1
  67. package/dist/middleware/pubsub/server/express/index.d.ts +3 -3
  68. package/dist/middleware/pubsub/server/express/index.js +2 -2
  69. package/dist/middleware/pubsub/server/fastify/index.d.ts +3 -3
  70. package/dist/middleware/pubsub/server/fastify/index.js +2 -2
  71. package/dist/middleware/pubsub/server/h3/index.d.ts +3 -3
  72. package/dist/middleware/pubsub/server/h3/index.js +2 -2
  73. package/dist/middleware/pubsub/server/index.d.ts +50 -9
  74. package/dist/middleware/pubsub/server/index.js +5 -5
  75. package/dist/middleware/pubsub/server/index.js.map +1 -1
  76. package/dist/middleware/pubsub/server/webapi/index.d.ts +3 -3
  77. package/dist/middleware/pubsub/server/webapi/index.js +2 -2
  78. package/dist/moonshot/index.d.ts +3 -3
  79. package/dist/moonshot/index.js +7 -5
  80. package/dist/moonshot/index.js.map +1 -1
  81. package/dist/ollama/index.d.ts +24 -4
  82. package/dist/ollama/index.js +5 -4
  83. package/dist/ollama/index.js.map +1 -1
  84. package/dist/openai/index.d.ts +65 -4
  85. package/dist/openai/index.js +7 -5
  86. package/dist/openai/index.js.map +1 -1
  87. package/dist/openrouter/index.d.ts +4 -4
  88. package/dist/openrouter/index.js +7 -5
  89. package/dist/openrouter/index.js.map +1 -1
  90. package/dist/proxy/index.d.ts +5 -5
  91. package/dist/proxy/index.js +16 -15
  92. package/dist/proxy/index.js.map +1 -1
  93. package/dist/proxy/server/express/index.d.ts +8 -9
  94. package/dist/proxy/server/express/index.js +4 -3
  95. package/dist/proxy/server/fastify/index.d.ts +8 -9
  96. package/dist/proxy/server/fastify/index.js +4 -3
  97. package/dist/proxy/server/h3/index.d.ts +8 -9
  98. package/dist/proxy/server/h3/index.js +4 -3
  99. package/dist/proxy/server/index.d.ts +5 -5
  100. package/dist/proxy/server/index.js +14 -13
  101. package/dist/proxy/server/webapi/index.d.ts +8 -9
  102. package/dist/proxy/server/webapi/index.js +4 -3
  103. package/dist/responses/index.d.ts +3 -3
  104. package/dist/responses/index.js +7 -5
  105. package/dist/responses/index.js.map +1 -1
  106. package/dist/retry-DVfdPLIB.d.ts +322 -0
  107. package/dist/{stream-DVVUIKpz.d.ts → stream-bBd_4Ipu.d.ts} +27 -4
  108. package/dist/{tool-D22EhP5F.d.ts → tool-BmAfKNBq.d.ts} +1 -1
  109. package/dist/{types-CyXF0J7C.d.ts → types-nTwlpyJE.d.ts} +13 -1
  110. package/dist/utils/index.d.ts +66 -2
  111. package/dist/utils/index.js +13 -0
  112. package/dist/xai/index.d.ts +3 -3
  113. package/dist/xai/index.js +7 -5
  114. package/dist/xai/index.js.map +1 -1
  115. package/package.json +6 -1
  116. package/dist/chunk-ARVM24K2.js +0 -128
  117. package/dist/chunk-ARVM24K2.js.map +0 -1
  118. package/dist/chunk-MJI74VEJ.js.map +0 -1
  119. package/dist/chunk-SBGZJVTJ.js.map +0 -1
  120. package/dist/chunk-U6M3MXNI.js.map +0 -1
  121. package/dist/chunk-WU4U6IHF.js.map +0 -1
  122. package/dist/chunk-Y5H7C5J4.js +0 -263
  123. package/dist/chunk-Y5H7C5J4.js.map +0 -1
  124. package/dist/retry-C1eJbEMV.d.ts +0 -531
  125. /package/dist/{chunk-ZDYEDI2A.js.map → chunk-CWGTARDE.js.map} +0 -0
  126. /package/dist/{chunk-IIMTP3XC.js.map → chunk-KBI45OXI.js.map} +0 -0
  127. /package/dist/{chunk-SAMIK4WZ.js.map → chunk-KVUOTFYZ.js.map} +0 -0
  128. /package/dist/{chunk-RDC5GYST.js.map → chunk-N4LAFGLX.js.map} +0 -0
  129. /package/dist/{chunk-WNB5PSY6.js.map → chunk-ZMESKGUY.js.map} +0 -0
  130. /package/dist/{chunk-7ULSRWDH.js.map → chunk-ZSZVWLGE.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/http/retry.ts","../src/http/errors.ts","../src/http/fetch.ts"],"sourcesContent":["/**\n * Retry strategy factories for handling transient failures in HTTP requests.\n *\n * All strategies use the factory pattern to ensure each request gets an\n * isolated instance, preventing state sharing between concurrent requests.\n *\n * @module http/retry\n */\n\nimport type { RetryStrategy, RetryStrategyFactory } from '../types/provider.ts';\nimport { ErrorCode, type UPPError } from '../types/errors.ts';\n\n/**\n * Checks if an error is eligible for retry.\n */\nfunction isRetryable(error: UPPError): boolean {\n return (\n error.code === ErrorCode.RateLimited ||\n error.code === ErrorCode.NetworkError ||\n error.code === ErrorCode.Timeout ||\n error.code === ErrorCode.ProviderError\n );\n}\n\n/**\n * Options for exponential backoff retry strategy.\n */\nexport interface ExponentialBackoffOptions {\n /** Maximum number of retry attempts (default: 3) */\n maxAttempts?: number;\n /** Initial delay in milliseconds (default: 1000) */\n baseDelay?: number;\n /** Maximum delay cap in milliseconds (default: 30000) */\n maxDelay?: number;\n /** Whether to add random jitter to delays (default: true) */\n jitter?: boolean;\n}\n\n/**\n * Creates an exponential backoff retry strategy.\n *\n * The delay between retries doubles with each attempt, helping to:\n * - Avoid overwhelming servers during outages\n * - Reduce thundering herd effects when many clients retry simultaneously\n * - Give transient issues time to resolve\n *\n * Delay formula: min(baseDelay * 2^(attempt-1), maxDelay)\n * With jitter: delay * random(0.5, 1.0)\n *\n * Only retries on transient errors: RATE_LIMITED, NETWORK_ERROR, TIMEOUT, PROVIDER_ERROR\n *\n * @param options - Configuration options\n * @returns A factory that creates fresh strategy instances per request\n *\n * @example\n * ```typescript\n * // Default configuration (3 retries, 1s base, 30s max, jitter enabled)\n * const retry = exponentialBackoff();\n *\n * // Custom configuration\n * const customRetry = exponentialBackoff({\n * maxAttempts: 5, // Up to 5 retry attempts\n * baseDelay: 500, // Start with 500ms delay\n * maxDelay: 60000, // Cap at 60 seconds\n * jitter: false // Disable random jitter\n * });\n *\n * // Use with provider\n * const provider = createOpenAI({\n * retryStrategy: customRetry\n * });\n * ```\n */\nexport function exponentialBackoff(options: ExponentialBackoffOptions = {}): RetryStrategyFactory {\n const maxAttempts = options.maxAttempts ?? 3;\n const baseDelay = options.baseDelay ?? 1000;\n const maxDelay = options.maxDelay ?? 30000;\n const jitter = options.jitter ?? true;\n\n return (): RetryStrategy => ({\n maxAttempts,\n\n onRetry(error: UPPError, attempt: number): number | null {\n if (attempt > maxAttempts) {\n return null;\n }\n\n if (!isRetryable(error)) {\n return null;\n }\n\n let delay = baseDelay * Math.pow(2, attempt - 1);\n delay = Math.min(delay, maxDelay);\n\n if (jitter) {\n delay = delay * (0.5 + Math.random());\n }\n\n return Math.floor(delay);\n },\n });\n}\n\n/**\n * Options for linear backoff retry strategy.\n */\nexport interface LinearBackoffOptions {\n /** Maximum number of retry attempts (default: 3) */\n maxAttempts?: number;\n /** Base delay multiplier in milliseconds (default: 1000) */\n delay?: number;\n}\n\n/**\n * Creates a linear backoff retry strategy.\n *\n * Unlike exponential backoff, linear backoff increases delays at a constant rate:\n * - Attempt 1: delay * 1 (e.g., 1000ms)\n * - Attempt 2: delay * 2 (e.g., 2000ms)\n * - Attempt 3: delay * 3 (e.g., 3000ms)\n *\n * This strategy is simpler and more predictable than exponential backoff,\n * suitable for scenarios where gradual delay increase is preferred over\n * aggressive backoff.\n *\n * Only retries on transient errors: RATE_LIMITED, NETWORK_ERROR, TIMEOUT, PROVIDER_ERROR\n *\n * @param options - Configuration options\n * @returns A factory that creates fresh strategy instances per request\n *\n * @example\n * ```typescript\n * // Default configuration (3 retries, 1s delay increment)\n * const retry = linearBackoff();\n *\n * // Custom configuration\n * const customRetry = linearBackoff({\n * maxAttempts: 4, // Up to 4 retry attempts\n * delay: 2000 // 2s, 4s, 6s, 8s delays\n * });\n *\n * // Use with provider\n * const provider = createAnthropic({\n * retryStrategy: customRetry\n * });\n * ```\n */\nexport function linearBackoff(options: LinearBackoffOptions = {}): RetryStrategyFactory {\n const maxAttempts = options.maxAttempts ?? 3;\n const delay = options.delay ?? 1000;\n\n return (): RetryStrategy => ({\n maxAttempts,\n\n onRetry(error: UPPError, attempt: number): number | null {\n if (attempt > maxAttempts) {\n return null;\n }\n\n if (!isRetryable(error)) {\n return null;\n }\n\n return delay * attempt;\n },\n });\n}\n\n/**\n * Creates a no-retry strategy that fails immediately on any error.\n *\n * Use this strategy when:\n * - Retries are handled at a higher level in your application\n * - You want immediate failure feedback\n * - The operation is not idempotent\n * - Time sensitivity requires fast failure\n *\n * @returns A factory that creates no-retry strategy instances\n *\n * @example\n * ```typescript\n * // Disable retries for time-sensitive operations\n * const provider = createOpenAI({\n * retryStrategy: noRetry()\n * });\n * ```\n */\nexport function noRetry(): RetryStrategyFactory {\n return (): RetryStrategy => ({\n maxAttempts: 0,\n\n onRetry(): null {\n return null;\n },\n });\n}\n\n/**\n * Options for retry-after strategy.\n */\nexport interface RetryAfterStrategyOptions {\n /** Maximum number of retry attempts (default: 3) */\n maxAttempts?: number;\n /** Delay in ms when no Retry-After header is present (default: 5000) */\n fallbackDelay?: number;\n}\n\n/**\n * Creates a retry strategy that respects server-provided Retry-After headers.\n *\n * When servers return a 429 (Too Many Requests) response, they often include\n * a Retry-After header indicating when the client should retry. This strategy\n * uses that information for precise retry timing.\n *\n * Benefits over fixed backoff strategies:\n * - Follows server recommendations for optimal retry timing\n * - Avoids retrying too early and wasting requests\n * - Adapts to dynamic rate limit windows\n *\n * If no Retry-After header is provided, falls back to a configurable delay.\n * Only retries on RATE_LIMITED errors.\n *\n * @param options - Configuration options\n * @returns A factory that creates fresh strategy instances per request\n *\n * @example\n * ```typescript\n * // Use server-recommended retry timing\n * const retryAfter = retryAfterStrategy({\n * maxAttempts: 5, // Retry up to 5 times\n * fallbackDelay: 10000 // 10s fallback if no header\n * });\n *\n * const provider = createOpenAI({\n * retryStrategy: retryAfter\n * });\n * ```\n */\nexport function retryAfterStrategy(options: RetryAfterStrategyOptions = {}): RetryStrategyFactory {\n const maxAttempts = options.maxAttempts ?? 3;\n const fallbackDelay = options.fallbackDelay ?? 5000;\n\n return (): RetryStrategy => {\n let lastRetryAfter: number | undefined;\n\n return {\n maxAttempts,\n\n setRetryAfter(seconds: number): void {\n lastRetryAfter = seconds * 1000;\n },\n\n onRetry(error: UPPError, attempt: number): number | null {\n if (attempt > maxAttempts) {\n return null;\n }\n\n if (error.code !== ErrorCode.RateLimited) {\n return null;\n }\n\n const delay = lastRetryAfter ?? fallbackDelay;\n lastRetryAfter = undefined;\n return delay;\n },\n };\n };\n}\n","/**\n * HTTP error handling and normalization utilities.\n * @module http/errors\n */\n\nimport {\n UPPError,\n ErrorCode,\n type Modality,\n} from '../types/errors.ts';\nimport { toError } from '../utils/error.ts';\n\n/**\n * Maps HTTP status codes to standardized UPP error codes.\n *\n * This function provides consistent error categorization across all providers:\n * - 400 -> INVALID_REQUEST (bad request format or parameters)\n * - 401, 403 -> AUTHENTICATION_FAILED (invalid or missing credentials)\n * - 404 -> MODEL_NOT_FOUND (requested model does not exist)\n * - 408 -> TIMEOUT (request timed out)\n * - 413 -> CONTEXT_LENGTH_EXCEEDED (input too long)\n * - 429 -> RATE_LIMITED (too many requests)\n * - 5xx -> PROVIDER_ERROR (server-side issues)\n *\n * @param status - HTTP status code from the response\n * @returns The corresponding UPP ErrorCode\n *\n * @example\n * ```typescript\n * const errorCode = statusToErrorCode(429);\n * // Returns 'RATE_LIMITED'\n *\n * const serverError = statusToErrorCode(503);\n * // Returns 'PROVIDER_ERROR'\n * ```\n */\nexport function statusToErrorCode(status: number): ErrorCode {\n switch (status) {\n case 400:\n return ErrorCode.InvalidRequest;\n case 402:\n return ErrorCode.QuotaExceeded;\n case 401:\n case 403:\n return ErrorCode.AuthenticationFailed;\n case 404:\n return ErrorCode.ModelNotFound;\n case 408:\n return ErrorCode.Timeout;\n case 409:\n return ErrorCode.InvalidRequest;\n case 422:\n return ErrorCode.InvalidRequest;\n case 413:\n return ErrorCode.ContextLengthExceeded;\n case 451:\n return ErrorCode.ContentFiltered;\n case 429:\n return ErrorCode.RateLimited;\n case 500:\n case 502:\n case 503:\n case 504:\n return ErrorCode.ProviderError;\n default:\n return ErrorCode.ProviderError;\n }\n}\n\n/**\n * Normalizes HTTP error responses into standardized UPPError objects.\n *\n * This function performs several operations:\n * 1. Maps the HTTP status code to an appropriate ErrorCode\n * 2. Attempts to extract a meaningful error message from the response body\n * 3. Handles various provider-specific error response formats\n *\n * Supported error message formats:\n * - `{ error: { message: \"...\" } }` (OpenAI, Anthropic)\n * - `{ message: \"...\" }` (simple format)\n * - `{ error: { error: { message: \"...\" } } }` (nested format)\n * - `{ detail: \"...\" }` (FastAPI style)\n * - Plain text body (if under 200 characters)\n *\n * @param response - The HTTP Response object with non-2xx status\n * @param provider - Provider identifier for error context\n * @param modality - Request modality for error context\n * @returns A UPPError with normalized code and message\n *\n * @example\n * ```typescript\n * if (!response.ok) {\n * const error = await normalizeHttpError(response, 'openai', 'llm');\n * // error.code might be 'RATE_LIMITED' for 429\n * // error.message contains provider's error message\n * throw error;\n * }\n * ```\n */\nexport async function normalizeHttpError(\n response: Response,\n provider: string,\n modality: Modality\n): Promise<UPPError> {\n const code = statusToErrorCode(response.status);\n let message = `HTTP ${response.status}: ${response.statusText}`;\n let bodyReadError: Error | undefined;\n\n try {\n const body = await response.text();\n if (body) {\n try {\n const json = JSON.parse(body);\n const extractedMessage =\n json.error?.message ||\n json.message ||\n json.error?.error?.message ||\n json.detail;\n\n if (extractedMessage) {\n message = extractedMessage;\n }\n } catch {\n if (body.length < 200) {\n message = body;\n }\n }\n }\n } catch (error) {\n bodyReadError = toError(error);\n }\n\n return new UPPError(message, code, provider, modality, response.status, bodyReadError);\n}\n\n/**\n * Creates a UPPError for network failures (DNS, connection, etc.).\n *\n * Use this when the request fails before receiving any HTTP response,\n * such as DNS resolution failures, connection refused, or network unreachable.\n *\n * @param error - The underlying Error that caused the failure\n * @param provider - Provider identifier for error context\n * @param modality - Request modality for error context\n * @returns A UPPError with NETWORK_ERROR code and the original error attached\n */\nexport function networkError(\n error: Error,\n provider: string,\n modality: Modality\n): UPPError {\n return new UPPError(\n `Network error: ${error.message}`,\n ErrorCode.NetworkError,\n provider,\n modality,\n undefined,\n error\n );\n}\n\n/**\n * Creates a UPPError for request timeout.\n *\n * Use this when the request exceeds the configured timeout duration\n * and is aborted by the AbortController.\n *\n * @param timeout - The timeout duration in milliseconds that was exceeded\n * @param provider - Provider identifier for error context\n * @param modality - Request modality for error context\n * @returns A UPPError with TIMEOUT code\n */\nexport function timeoutError(\n timeout: number,\n provider: string,\n modality: Modality\n): UPPError {\n return new UPPError(\n `Request timed out after ${timeout}ms`,\n ErrorCode.Timeout,\n provider,\n modality\n );\n}\n\n/**\n * Creates a UPPError for user-initiated request cancellation.\n *\n * Use this when the request is aborted via a user-provided AbortSignal,\n * distinct from timeout-based cancellation.\n *\n * @param provider - Provider identifier for error context\n * @param modality - Request modality for error context\n * @returns A UPPError with CANCELLED code\n */\nexport function cancelledError(provider: string, modality: Modality): UPPError {\n return new UPPError(\n 'Request was cancelled',\n ErrorCode.Cancelled,\n provider,\n modality\n );\n}\n","/**\n * HTTP fetch utilities with retry, timeout, and error normalization.\n * @module http/fetch\n */\n\nimport type { ProviderConfig } from '../types/provider.ts';\nimport type { Modality } from '../types/errors.ts';\nimport { UPPError } from '../types/errors.ts';\nimport {\n normalizeHttpError,\n networkError,\n timeoutError,\n cancelledError,\n} from './errors.ts';\nimport { noRetry } from './retry.ts';\nimport { toError } from '../utils/error.ts';\n\n/** Default request timeout in milliseconds (2 minutes). */\nconst DEFAULT_TIMEOUT = 120000;\nconst MAX_RETRY_AFTER_SECONDS = 3600;\n\n/**\n * Warns when a non-TLS URL is used with a provider.\n * Only warns in non-production, excludes localhost for local development.\n */\nexport function warnInsecureUrl(url: string, provider: string): void {\n if (\n process.env.NODE_ENV !== 'production' &&\n url.startsWith('http://') &&\n !url.includes('localhost') &&\n !url.includes('127.0.0.1') &&\n !url.includes('[::1]')\n ) {\n console.warn(\n `[UPP] Provider \"${provider}\" using non-TLS URL: ${url}. ` +\n 'API keys may be exposed to network interception.'\n );\n }\n}\n\n/**\n * Delays execution for a specified duration.\n *\n * @param ms - Duration to sleep in milliseconds\n * @returns Promise that resolves after the specified delay\n */\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Parses Retry-After header values into seconds.\n *\n * Supports both delta-seconds and HTTP-date formats.\n */\nfunction parseRetryAfter(headerValue: string | null, maxSeconds: number): number | null {\n if (!headerValue) {\n return null;\n }\n\n const seconds = parseInt(headerValue, 10);\n if (!Number.isNaN(seconds)) {\n return Math.min(maxSeconds, Math.max(0, seconds));\n }\n\n const dateMillis = Date.parse(headerValue);\n if (Number.isNaN(dateMillis)) {\n return null;\n }\n\n const deltaMs = dateMillis - Date.now();\n if (deltaMs <= 0) {\n return 0;\n }\n\n const deltaSeconds = Math.ceil(deltaMs / 1000);\n return Math.min(maxSeconds, Math.max(0, deltaSeconds));\n}\n\n/**\n * Executes a fetch request with configurable timeout.\n *\n * Creates an AbortController to cancel the request if it exceeds the timeout.\n * Properly handles both user-provided abort signals and timeout-based cancellation,\n * throwing appropriate error types for each case.\n *\n * @param fetchFn - The fetch function to use (allows custom implementations)\n * @param url - The URL to fetch\n * @param init - Standard fetch RequestInit options\n * @param timeout - Maximum time in milliseconds before aborting\n * @param provider - Provider identifier for error context\n * @param modality - Request modality for error context\n * @returns The Response from the fetch call\n *\n * @throws {UPPError} TIMEOUT - When the timeout is exceeded\n * @throws {UPPError} CANCELLED - When cancelled via user-provided signal\n * @throws {Error} Network errors are passed through unchanged\n */\nasync function fetchWithTimeout(\n fetchFn: typeof fetch,\n url: string,\n init: RequestInit,\n timeout: number,\n provider: string,\n modality: Modality\n): Promise<Response> {\n const existingSignal = init.signal;\n\n // Check if already aborted before starting\n if (existingSignal?.aborted) {\n throw cancelledError(provider, modality);\n }\n\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n\n const onAbort = () => controller.abort();\n if (existingSignal) {\n existingSignal.addEventListener('abort', onAbort, { once: true });\n }\n\n try {\n const response = await fetchFn(url, {\n ...init,\n signal: controller.signal,\n });\n return response;\n } catch (error) {\n if (toError(error).name === 'AbortError') {\n if (existingSignal?.aborted) {\n throw cancelledError(provider, modality);\n }\n throw timeoutError(timeout, provider, modality);\n }\n throw error;\n } finally {\n clearTimeout(timeoutId);\n if (existingSignal) {\n existingSignal.removeEventListener('abort', onAbort);\n }\n }\n}\n\n/**\n * Executes an HTTP fetch request with automatic retry, timeout handling, and error normalization.\n *\n * This function wraps the standard fetch API with additional capabilities:\n * - Configurable timeout with automatic request cancellation (per attempt)\n * - Retry strategy support (exponential backoff, linear, token bucket, etc.)\n * - Pre-request delay support for rate limiting strategies\n * - Automatic Retry-After header parsing and handling\n * - Error normalization to UPPError format\n *\n * @param url - The URL to fetch\n * @param init - Standard fetch RequestInit options (method, headers, body, etc.)\n * @param config - Provider configuration containing fetch customization, timeout, and retry strategy\n * @param provider - Provider identifier for error context (e.g., 'openai', 'anthropic')\n * @param modality - Request modality for error context (e.g., 'llm', 'embedding', 'image')\n * @returns The successful Response object\n *\n * @throws {UPPError} RATE_LIMITED - When rate limited and retries exhausted\n * @throws {UPPError} NETWORK_ERROR - When a network failure occurs\n * @throws {UPPError} TIMEOUT - When the request times out\n * @throws {UPPError} CANCELLED - When the request is aborted via signal\n * @throws {UPPError} Various codes based on HTTP status (see statusToErrorCode)\n *\n * @example\n * ```typescript\n * const response = await doFetch(\n * 'https://api.openai.com/v1/chat/completions',\n * {\n * method: 'POST',\n * headers: { 'Authorization': 'Bearer sk-...' },\n * body: JSON.stringify({ model: 'gpt-4', messages: [] })\n * },\n * { timeout: 30000, retryStrategy: exponentialBackoff() },\n * 'openai',\n * 'llm'\n * );\n * ```\n */\nexport async function doFetch(\n url: string,\n init: RequestInit,\n config: ProviderConfig,\n provider: string,\n modality: Modality\n): Promise<Response> {\n const fetchFn = config.fetch ?? fetch;\n const timeout = config.timeout ?? DEFAULT_TIMEOUT;\n const strategy = (config.retryStrategy ?? noRetry())();\n\n // Warn about potential security issue with non-TLS URLs\n warnInsecureUrl(url, provider);\n\n let attempt = 0;\n\n while (true) {\n attempt++;\n\n if (strategy.beforeRequest) {\n const delay = await strategy.beforeRequest();\n if (delay > 0) {\n await sleep(delay);\n }\n }\n\n let response: Response;\n try {\n response = await fetchWithTimeout(\n fetchFn,\n url,\n init,\n timeout,\n provider,\n modality\n );\n } catch (error) {\n if (error instanceof UPPError) {\n const delay = await strategy.onRetry(error, attempt);\n if (delay !== null) {\n await sleep(delay);\n continue;\n }\n throw error;\n }\n\n const uppError = networkError(toError(error), provider, modality);\n\n const delay = await strategy.onRetry(uppError, attempt);\n if (delay !== null) {\n await sleep(delay);\n continue;\n }\n\n throw uppError;\n }\n\n if (!response.ok) {\n const error = await normalizeHttpError(response, provider, modality);\n\n const retryAfterSeconds = parseRetryAfter(\n response.headers.get('Retry-After'),\n config.retryAfterMaxSeconds ?? MAX_RETRY_AFTER_SECONDS\n );\n if (retryAfterSeconds !== null && strategy.setRetryAfter) {\n strategy.setRetryAfter(retryAfterSeconds);\n }\n\n const delay = await strategy.onRetry(error, attempt);\n if (delay !== null) {\n await sleep(delay);\n continue;\n }\n\n throw error;\n }\n\n strategy.reset?.();\n\n return response;\n }\n}\n\n/**\n * Executes an HTTP fetch request for streaming responses.\n *\n * Unlike {@link doFetch}, this function returns the response immediately without\n * checking the HTTP status. This is necessary for Server-Sent Events (SSE) and\n * other streaming protocols where error information may be embedded in the stream.\n *\n * The caller is responsible for:\n * - Checking response.ok and handling HTTP errors\n * - Parsing the response stream (e.g., using parseSSEStream)\n * - Handling stream-specific error conditions\n *\n * Retries are not performed for streaming requests since partial data may have\n * already been consumed by the caller.\n *\n * @param url - The URL to fetch\n * @param init - Standard fetch RequestInit options\n * @param config - Provider configuration containing fetch customization and timeout\n * @param provider - Provider identifier for error context\n * @param modality - Request modality for error context\n * @returns The Response object (may have non-2xx status)\n *\n * @throws {UPPError} NETWORK_ERROR - When a network failure occurs\n * @throws {UPPError} TIMEOUT - When the request times out\n * @throws {UPPError} CANCELLED - When the request is aborted via signal\n *\n * @example\n * ```typescript\n * const response = await doStreamFetch(\n * 'https://api.openai.com/v1/chat/completions',\n * {\n * method: 'POST',\n * headers: { 'Authorization': 'Bearer sk-...' },\n * body: JSON.stringify({ model: 'gpt-4', messages: [], stream: true })\n * },\n * { timeout: 120000 },\n * 'openai',\n * 'llm'\n * );\n *\n * if (!response.ok) {\n * throw await normalizeHttpError(response, 'openai', 'llm');\n * }\n *\n * for await (const event of parseSSEStream(response.body!)) {\n * console.log(event);\n * }\n * ```\n */\nexport async function doStreamFetch(\n url: string,\n init: RequestInit,\n config: ProviderConfig,\n provider: string,\n modality: Modality\n): Promise<Response> {\n const fetchFn = config.fetch ?? fetch;\n const timeout = config.timeout ?? DEFAULT_TIMEOUT;\n const strategy = (config.retryStrategy ?? noRetry())();\n\n if (strategy.beforeRequest) {\n const delay = await strategy.beforeRequest();\n if (delay > 0) {\n await sleep(delay);\n }\n }\n\n try {\n const response = await fetchWithTimeout(\n fetchFn,\n url,\n init,\n timeout,\n provider,\n modality\n );\n return response;\n } catch (error) {\n if (error instanceof UPPError) {\n throw error;\n }\n throw networkError(toError(error), provider, modality);\n }\n}\n"],"mappings":";;;;;;;;;AAeA,SAAS,YAAY,OAA0B;AAC7C,SACE,MAAM,SAAS,UAAU,eACzB,MAAM,SAAS,UAAU,gBACzB,MAAM,SAAS,UAAU,WACzB,MAAM,SAAS,UAAU;AAE7B;AAmDO,SAAS,mBAAmB,UAAqC,CAAC,GAAyB;AAChG,QAAM,cAAc,QAAQ,eAAe;AAC3C,QAAM,YAAY,QAAQ,aAAa;AACvC,QAAM,WAAW,QAAQ,YAAY;AACrC,QAAM,SAAS,QAAQ,UAAU;AAEjC,SAAO,OAAsB;AAAA,IAC3B;AAAA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,WAAW,MAAM;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,iBAAiB,UAAU;AAC7B,YAAM;AAAA,IACR;AACA,UAAM,aAAa,QAAQ,KAAK,GAAG,UAAU,QAAQ;AAAA,EACvD;AACF;","names":["delay"]}
@@ -6,7 +6,7 @@ import {
6
6
  import {
7
7
  serializeStreamEvent,
8
8
  serializeTurn
9
- } from "./chunk-7ULSRWDH.js";
9
+ } from "./chunk-ZSZVWLGE.js";
10
10
 
11
11
  // src/providers/proxy/server/express.ts
12
12
  function sendJSON(turn, res) {
@@ -96,4 +96,4 @@ export {
96
96
  sendError,
97
97
  express
98
98
  };
99
- //# sourceMappingURL=chunk-O32SBS6S.js.map
99
+ //# sourceMappingURL=chunk-XTWBAL42.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/providers/proxy/server/express.ts"],"sourcesContent":["/**\n * @fileoverview Express/Connect adapter for proxy server.\n *\n * Provides utilities for using PP proxy with Express.js or Connect-based servers.\n * These adapters convert PP types to Express-compatible responses.\n *\n * @module providers/proxy/server/express\n */\n\nimport type { Turn } from '../../../types/turn.ts';\nimport type { StreamResult } from '../../../types/stream.ts';\nimport type { EmbeddingResult } from '../../../types/embedding.ts';\nimport type { ImageResult } from '../../../types/image.ts';\nimport { serializeTurn, serializeStreamEvent } from '../serialization.ts';\nimport { serializeImageResult, serializeImageStreamEvent } from '../serialization.media.ts';\nimport { resolveImageResult, type ImageStreamLike } from './image-stream.ts';\n\n/**\n * Express Response interface (minimal type to avoid dependency).\n */\ninterface ExpressResponse {\n setHeader(name: string, value: string): void;\n status(code: number): ExpressResponse;\n write(chunk: string): boolean;\n end(): void;\n json(body: unknown): void;\n}\n\n/**\n * Send a Turn as JSON response.\n *\n * @param turn - The completed inference turn\n * @param res - Express response object\n *\n * @example\n * ```typescript\n * const turn = await instance.generate(messages);\n * expressAdapter.sendJSON(turn, res);\n * ```\n */\nexport function sendJSON(turn: Turn, res: ExpressResponse): void {\n res.setHeader('Content-Type', 'application/json');\n res.json(serializeTurn(turn));\n}\n\n/**\n * Send an EmbeddingResult as JSON response.\n *\n * @param result - The embedding result\n * @param res - Express response object\n */\nexport function sendEmbeddingJSON(result: EmbeddingResult, res: ExpressResponse): void {\n res.setHeader('Content-Type', 'application/json');\n res.json(result);\n}\n\n/**\n * Send an ImageResult as JSON response.\n *\n * @param result - The image result\n * @param res - Express response object\n */\nexport function sendImageJSON(result: ImageResult, res: ExpressResponse): void {\n res.setHeader('Content-Type', 'application/json');\n res.json(serializeImageResult(result));\n}\n\n/**\n * Stream a StreamResult as Server-Sent Events.\n *\n * @param stream - The StreamResult from instance.stream()\n * @param res - Express response object\n *\n * @example\n * ```typescript\n * const stream = instance.stream(messages);\n * expressAdapter.streamSSE(stream, res);\n * ```\n */\nexport function streamSSE(stream: StreamResult, res: ExpressResponse): void {\n res.setHeader('Content-Type', 'text/event-stream');\n res.setHeader('Cache-Control', 'no-cache');\n res.setHeader('Connection', 'keep-alive');\n\n (async () => {\n try {\n for await (const event of stream) {\n const serialized = serializeStreamEvent(event);\n res.write(`data: ${JSON.stringify(serialized)}\\n\\n`);\n }\n\n const turn = await stream.turn;\n res.write(`data: ${JSON.stringify(serializeTurn(turn))}\\n\\n`);\n res.write('data: [DONE]\\n\\n');\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n res.write(`data: ${JSON.stringify({ error: message })}\\n\\n`);\n } finally {\n res.end();\n }\n })();\n}\n\n/**\n * Stream an ImageStreamResult as Server-Sent Events.\n *\n * @param stream - The ImageStreamResult or ImageProviderStreamResult from image().stream()\n * @param res - Express response object\n */\nexport function streamImageSSE(stream: ImageStreamLike, res: ExpressResponse): void {\n res.setHeader('Content-Type', 'text/event-stream');\n res.setHeader('Cache-Control', 'no-cache');\n res.setHeader('Connection', 'keep-alive');\n\n (async () => {\n try {\n for await (const event of stream) {\n const serialized = serializeImageStreamEvent(event);\n res.write(`data: ${JSON.stringify(serialized)}\\n\\n`);\n }\n\n const result = await resolveImageResult(stream);\n res.write(`data: ${JSON.stringify(serializeImageResult(result))}\\n\\n`);\n res.write('data: [DONE]\\n\\n');\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n res.write(`data: ${JSON.stringify({ error: message })}\\n\\n`);\n } finally {\n res.end();\n }\n })();\n}\n\n/**\n * Send an error response.\n *\n * @param message - Error message\n * @param status - HTTP status code\n * @param res - Express response object\n */\nexport function sendError(message: string, status: number, res: ExpressResponse): void {\n res.status(status).json({ error: message });\n}\n\n/**\n * Express adapter utilities.\n *\n * @example Basic usage\n * ```typescript\n * import express from 'express';\n * import { llm } from '@providerprotocol/ai';\n * import { anthropic } from '@providerprotocol/ai/anthropic';\n * import { parseBody } from '@providerprotocol/ai/proxy';\n * import { express as expressAdapter } from '@providerprotocol/ai/proxy/server';\n *\n * const app = express();\n * app.use(express.json());\n *\n * app.post('/api/ai', async (req, res) => {\n * const { messages, system, params } = parseBody(req.body);\n * const instance = llm({ model: anthropic('claude-sonnet-4-20250514'), system });\n *\n * if (req.headers.accept?.includes('text/event-stream')) {\n * expressAdapter.streamSSE(instance.stream(messages), res);\n * } else {\n * const turn = await instance.generate(messages);\n * expressAdapter.sendJSON(turn, res);\n * }\n * });\n * ```\n *\n * @example API Gateway with authentication\n * ```typescript\n * import express from 'express';\n * import { llm } from '@providerprotocol/ai';\n * import { anthropic } from '@providerprotocol/ai/anthropic';\n * import { ExponentialBackoff, RoundRobinKeys } from '@providerprotocol/ai/http';\n * import { parseBody } from '@providerprotocol/ai/proxy';\n * import { express as expressAdapter } from '@providerprotocol/ai/proxy/server';\n *\n * const app = express();\n * app.use(express.json());\n *\n * // Your platform's auth middleware\n * async function authMiddleware(req, res, next) {\n * const token = req.headers.authorization?.replace('Bearer ', '');\n * const user = await validatePlatformToken(token);\n * if (!user) return res.status(401).json({ error: 'Unauthorized' });\n * req.user = user;\n * next();\n * }\n *\n * // Server manages AI provider keys - users never see them\n * const claude = llm({\n * model: anthropic('claude-sonnet-4-20250514'),\n * config: {\n * apiKey: new RoundRobinKeys([process.env.ANTHROPIC_KEY_1!, process.env.ANTHROPIC_KEY_2!]),\n * retryStrategy: new ExponentialBackoff({ maxAttempts: 3 }),\n * },\n * });\n *\n * app.post('/api/ai', authMiddleware, async (req, res) => {\n * // Track usage per user\n * // await trackUsage(req.user.id);\n *\n * const { messages, system, params } = parseBody(req.body);\n *\n * if (params?.stream) {\n * expressAdapter.streamSSE(claude.stream(messages, { system }), res);\n * } else {\n * const turn = await claude.generate(messages, { system });\n * expressAdapter.sendJSON(turn, res);\n * }\n * });\n * ```\n */\nexport const express = {\n sendJSON,\n sendEmbeddingJSON,\n sendImageJSON,\n streamSSE,\n streamImageSSE,\n sendError,\n};\n"],"mappings":";;;;;;;;;;;AAwCO,SAAS,SAAS,MAAY,KAA4B;AAC/D,MAAI,UAAU,gBAAgB,kBAAkB;AAChD,MAAI,KAAK,cAAc,IAAI,CAAC;AAC9B;AAQO,SAAS,kBAAkB,QAAyB,KAA4B;AACrF,MAAI,UAAU,gBAAgB,kBAAkB;AAChD,MAAI,KAAK,MAAM;AACjB;AAQO,SAAS,cAAc,QAAqB,KAA4B;AAC7E,MAAI,UAAU,gBAAgB,kBAAkB;AAChD,MAAI,KAAK,qBAAqB,MAAM,CAAC;AACvC;AAcO,SAAS,UAAU,QAAsB,KAA4B;AAC1E,MAAI,UAAU,gBAAgB,mBAAmB;AACjD,MAAI,UAAU,iBAAiB,UAAU;AACzC,MAAI,UAAU,cAAc,YAAY;AAExC,GAAC,YAAY;AACX,QAAI;AACF,uBAAiB,SAAS,QAAQ;AAChC,cAAM,aAAa,qBAAqB,KAAK;AAC7C,YAAI,MAAM,SAAS,KAAK,UAAU,UAAU,CAAC;AAAA;AAAA,CAAM;AAAA,MACrD;AAEA,YAAM,OAAO,MAAM,OAAO;AAC1B,UAAI,MAAM,SAAS,KAAK,UAAU,cAAc,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":["/**\n * @fileoverview Express/Connect adapter for proxy server.\n *\n * Provides utilities for using PP proxy with Express.js or Connect-based servers.\n * These adapters convert PP types to Express-compatible responses.\n *\n * @module providers/proxy/server/express\n */\n\nimport type { Turn } from '../../../types/turn.ts';\nimport type { StreamResult } from '../../../types/stream.ts';\nimport type { EmbeddingResult } from '../../../types/embedding.ts';\nimport type { ImageResult } from '../../../types/image.ts';\nimport { serializeTurn, serializeStreamEvent } from '../serialization.ts';\nimport { serializeImageResult, serializeImageStreamEvent } from '../serialization.media.ts';\nimport { resolveImageResult, type ImageStreamLike } from './image-stream.ts';\n\n/**\n * Express Response interface (minimal type to avoid dependency).\n */\ninterface ExpressResponse {\n setHeader(name: string, value: string): void;\n status(code: number): ExpressResponse;\n write(chunk: string): boolean;\n end(): void;\n json(body: unknown): void;\n}\n\n/**\n * Send a Turn as JSON response.\n *\n * @param turn - The completed inference turn\n * @param res - Express response object\n *\n * @example\n * ```typescript\n * const turn = await instance.generate(messages);\n * expressAdapter.sendJSON(turn, res);\n * ```\n */\nexport function sendJSON(turn: Turn, res: ExpressResponse): void {\n res.setHeader('Content-Type', 'application/json');\n res.json(serializeTurn(turn));\n}\n\n/**\n * Send an EmbeddingResult as JSON response.\n *\n * @param result - The embedding result\n * @param res - Express response object\n */\nexport function sendEmbeddingJSON(result: EmbeddingResult, res: ExpressResponse): void {\n res.setHeader('Content-Type', 'application/json');\n res.json(result);\n}\n\n/**\n * Send an ImageResult as JSON response.\n *\n * @param result - The image result\n * @param res - Express response object\n */\nexport function sendImageJSON(result: ImageResult, res: ExpressResponse): void {\n res.setHeader('Content-Type', 'application/json');\n res.json(serializeImageResult(result));\n}\n\n/**\n * Stream a StreamResult as Server-Sent Events.\n *\n * @param stream - The StreamResult from instance.stream()\n * @param res - Express response object\n *\n * @example\n * ```typescript\n * const stream = instance.stream(messages);\n * expressAdapter.streamSSE(stream, res);\n * ```\n */\nexport function streamSSE(stream: StreamResult, res: ExpressResponse): void {\n res.setHeader('Content-Type', 'text/event-stream');\n res.setHeader('Cache-Control', 'no-cache');\n res.setHeader('Connection', 'keep-alive');\n\n (async () => {\n try {\n for await (const event of stream) {\n const serialized = serializeStreamEvent(event);\n res.write(`data: ${JSON.stringify(serialized)}\\n\\n`);\n }\n\n const turn = await stream.turn;\n res.write(`data: ${JSON.stringify(serializeTurn(turn))}\\n\\n`);\n res.write('data: [DONE]\\n\\n');\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n res.write(`data: ${JSON.stringify({ error: message })}\\n\\n`);\n } finally {\n res.end();\n }\n })();\n}\n\n/**\n * Stream an ImageStreamResult as Server-Sent Events.\n *\n * @param stream - The ImageStreamResult or ImageProviderStreamResult from image().stream()\n * @param res - Express response object\n */\nexport function streamImageSSE(stream: ImageStreamLike, res: ExpressResponse): void {\n res.setHeader('Content-Type', 'text/event-stream');\n res.setHeader('Cache-Control', 'no-cache');\n res.setHeader('Connection', 'keep-alive');\n\n (async () => {\n try {\n for await (const event of stream) {\n const serialized = serializeImageStreamEvent(event);\n res.write(`data: ${JSON.stringify(serialized)}\\n\\n`);\n }\n\n const result = await resolveImageResult(stream);\n res.write(`data: ${JSON.stringify(serializeImageResult(result))}\\n\\n`);\n res.write('data: [DONE]\\n\\n');\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n res.write(`data: ${JSON.stringify({ error: message })}\\n\\n`);\n } finally {\n res.end();\n }\n })();\n}\n\n/**\n * Send an error response.\n *\n * @param message - Error message\n * @param status - HTTP status code\n * @param res - Express response object\n */\nexport function sendError(message: string, status: number, res: ExpressResponse): void {\n res.status(status).json({ error: message });\n}\n\n/**\n * Express adapter utilities.\n *\n * @example Basic usage\n * ```typescript\n * import express from 'express';\n * import { llm } from '@providerprotocol/ai';\n * import { anthropic } from '@providerprotocol/ai/anthropic';\n * import { parseBody } from '@providerprotocol/ai/proxy';\n * import { express as expressAdapter } from '@providerprotocol/ai/proxy/server';\n *\n * const app = express();\n * app.use(express.json());\n *\n * app.post('/api/ai', async (req, res) => {\n * const { messages, system, params } = parseBody(req.body);\n * const instance = llm({ model: anthropic('claude-sonnet-4-20250514'), system });\n *\n * if (req.headers.accept?.includes('text/event-stream')) {\n * expressAdapter.streamSSE(instance.stream(messages), res);\n * } else {\n * const turn = await instance.generate(messages);\n * expressAdapter.sendJSON(turn, res);\n * }\n * });\n * ```\n *\n * @example API Gateway with authentication\n * ```typescript\n * import express from 'express';\n * import { llm, exponentialBackoff, roundRobinKeys } from '@providerprotocol/ai';\n * import { anthropic } from '@providerprotocol/ai/anthropic';\n * import { parseBody } from '@providerprotocol/ai/proxy';\n * import { express as expressAdapter } from '@providerprotocol/ai/proxy/server';\n *\n * const app = express();\n * app.use(express.json());\n *\n * // Your platform's auth middleware\n * async function authMiddleware(req, res, next) {\n * const token = req.headers.authorization?.replace('Bearer ', '');\n * const user = await validatePlatformToken(token);\n * if (!user) return res.status(401).json({ error: 'Unauthorized' });\n * req.user = user;\n * next();\n * }\n *\n * // Server manages AI provider keys - users never see them\n * const claude = llm({\n * model: anthropic('claude-sonnet-4-20250514'),\n * config: {\n * apiKey: roundRobinKeys([process.env.ANTHROPIC_KEY_1!, process.env.ANTHROPIC_KEY_2!]),\n * retryStrategy: exponentialBackoff({ maxAttempts: 3 }),\n * },\n * });\n *\n * app.post('/api/ai', authMiddleware, async (req, res) => {\n * // Track usage per user\n * // await trackUsage(req.user.id);\n *\n * const { messages, system, params } = parseBody(req.body);\n *\n * if (params?.stream) {\n * expressAdapter.streamSSE(claude.stream(messages, { system }), res);\n * } else {\n * const turn = await claude.generate(messages, { system });\n * expressAdapter.sendJSON(turn, res);\n * }\n * });\n * ```\n */\nexport const express = {\n sendJSON,\n sendEmbeddingJSON,\n sendImageJSON,\n streamSSE,\n streamImageSSE,\n sendError,\n};\n"],"mappings":";;;;;;;;;;;AAwCO,SAAS,SAAS,MAAY,KAA4B;AAC/D,MAAI,UAAU,gBAAgB,kBAAkB;AAChD,MAAI,KAAK,cAAc,IAAI,CAAC;AAC9B;AA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AM,SAAS,KAAK,UAAU,qBAAqB,MAAM,CAAC,CAAC;AAAA;AAAA,CAAM;AACrE,UAAI,MAAM,kBAAkB;AAAA,IAC9B,SAAS,OAAO;AACd,YAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,UAAI,MAAM,SAAS,KAAK,UAAU,EAAE,OAAO,QAAQ,CAAC,CAAC;AAAA;AAAA,CAAM;AAAA,IAC7D,UAAE;AACA,UAAI,IAAI;AAAA,IACV;AAAA,EACF,GAAG;AACL;AASO,SAAS,UAAU,SAAiB,QAAgB,KAA4B;AACrF,MAAI,OAAO,MAAM,EAAE,KAAK,EAAE,OAAO,QAAQ,CAAC;AAC5C;AAyEO,IAAM,UAAU;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  runSubscriberStream
3
- } from "./chunk-U6M3MXNI.js";
3
+ } from "./chunk-L6QWKFGE.js";
4
4
 
5
5
  // src/middleware/pubsub/server/webapi.ts
6
6
  function createSubscriberStream(streamId, adapter) {
@@ -46,4 +46,4 @@ export {
46
46
  createSubscriberStream,
47
47
  webapi
48
48
  };
49
- //# sourceMappingURL=chunk-WNB5PSY6.js.map
49
+ //# sourceMappingURL=chunk-ZMESKGUY.js.map
@@ -6,7 +6,7 @@ import {
6
6
  AssistantMessage,
7
7
  ToolResultMessage,
8
8
  UserMessage
9
- } from "./chunk-WU4U6IHF.js";
9
+ } from "./chunk-6QCV4WXF.js";
10
10
  import {
11
11
  ErrorCode,
12
12
  ModalityType,
@@ -80,4 +80,4 @@ export {
80
80
  serializeStreamEvent2 as serializeStreamEvent,
81
81
  deserializeStreamEvent2 as deserializeStreamEvent
82
82
  };
83
- //# sourceMappingURL=chunk-7ULSRWDH.js.map
83
+ //# sourceMappingURL=chunk-ZSZVWLGE.js.map
@@ -1,4 +1,4 @@
1
- import { P as ProviderIdentity, c as ProviderConfig, M as Middleware, E as EmbeddingInput, d as EmbeddingUsage, B as BoundEmbeddingModel } from './llm-CZqlijjK.js';
1
+ import { P as ProviderIdentity, c as ProviderConfig, M as Middleware, E as EmbeddingInput, d as EmbeddingUsage, B as BoundEmbeddingModel } from './llm-BWLaTzzY.js';
2
2
 
3
3
  /**
4
4
  * @fileoverview Embedding types for vector embedding generation.
@@ -1,6 +1,6 @@
1
- import { c as ProviderConfig, e as Provider } from '../llm-CZqlijjK.js';
2
- import '../stream-DVVUIKpz.js';
3
- import '../tool-D22EhP5F.js';
1
+ import { c as ProviderConfig, e as Provider } from '../llm-BWLaTzzY.js';
2
+ import '../stream-bBd_4Ipu.js';
3
+ import '../tool-BmAfKNBq.js';
4
4
 
5
5
  /**
6
6
  * Provider-specific parameters for Google Gemini API requests.
@@ -952,6 +952,40 @@ interface GoogleEmbedParams {
952
952
  autoTruncate?: boolean;
953
953
  }
954
954
 
955
+ /**
956
+ * @fileoverview Google Imagen Image Generation API Handler
957
+ *
958
+ * This module implements the image handler for Google's Imagen API via Google AI.
959
+ * Supports Imagen 3 and 4 models through the Gemini API.
960
+ *
961
+ * @see {@link https://ai.google.dev/gemini-api/docs/imagen Imagen API Reference}
962
+ * @module providers/google/image
963
+ */
964
+
965
+ /**
966
+ * Google Imagen generation parameters.
967
+ * Passed through unchanged to the API.
968
+ */
969
+ interface GoogleImagenParams {
970
+ /** Number of images to generate (1-4) */
971
+ sampleCount?: number;
972
+ /** Image size: '1K' (1024px) or '2K' (2048px) */
973
+ imageSize?: '1K' | '2K';
974
+ /** Aspect ratio */
975
+ aspectRatio?: '1:1' | '3:4' | '4:3' | '9:16' | '16:9';
976
+ /** Person generation setting */
977
+ personGeneration?: 'dont_allow' | 'allow_adult' | 'allow_all';
978
+ /** Safety filter level */
979
+ safetyFilterLevel?: 'block_low_and_above' | 'block_medium_and_above' | 'block_only_high' | 'block_none';
980
+ /** Add invisible SynthID watermark (default: true) */
981
+ addWatermark?: boolean;
982
+ /**
983
+ * Negative prompt to exclude concepts.
984
+ * @deprecated Not supported on Imagen 3.0-002+ and Imagen 4 models. Will be ignored.
985
+ */
986
+ negativePrompt?: string;
987
+ }
988
+
955
989
  /**
956
990
  * Google Gemini provider for the Unified Provider Protocol (UPP).
957
991
  *
@@ -1019,4 +1053,4 @@ declare const google: Provider<unknown> & {
1019
1053
  };
1020
1054
  };
1021
1055
 
1022
- export { type CacheCreateOptions, type CacheListOptions, type GoogleBuiltInTool, type GoogleCacheCreateRequest, type GoogleCacheListResponse, type GoogleCacheResponse, type GoogleCacheUpdateRequest, type GoogleCodeExecutionResult, type GoogleCodeExecutionTool, type GoogleEmbedParams, type GoogleFileSearchTool, type GoogleGroundingMetadata, type GoogleHeaders, type GoogleImageConfig, type GoogleLLMParams, type GoogleMapsTool, type GoogleResponseModality, type GoogleSearchTool, type GoogleTaskType, type GoogleToolConfig, type GoogleUrlContextTool, cache, google, tools };
1056
+ export { type CacheCreateOptions, type CacheListOptions, type GoogleBuiltInTool, type GoogleCacheCreateRequest, type GoogleCacheListResponse, type GoogleCacheResponse, type GoogleCacheUpdateRequest, type GoogleCodeExecutionResult, type GoogleCodeExecutionTool, type GoogleEmbedParams, type GoogleFileSearchTool, type GoogleGroundingMetadata, type GoogleHeaders, type GoogleImageConfig, type GoogleImagenParams, type GoogleLLMParams, type GoogleMapsTool, type GoogleResponseModality, type GoogleSearchTool, type GoogleTaskType, type GoogleToolConfig, type GoogleUrlContextTool, cache, google, tools };
@@ -9,7 +9,7 @@ import {
9
9
  } from "../chunk-TUTYMOBL.js";
10
10
  import {
11
11
  resolveApiKey
12
- } from "../chunk-ARVM24K2.js";
12
+ } from "../chunk-EY2LLDGY.js";
13
13
  import {
14
14
  createProvider
15
15
  } from "../chunk-JA3UZALR.js";
@@ -17,17 +17,18 @@ import {
17
17
  doFetch,
18
18
  doStreamFetch,
19
19
  normalizeHttpError
20
- } from "../chunk-SBGZJVTJ.js";
20
+ } from "../chunk-VQZPADW6.js";
21
21
  import {
22
22
  StreamEventType,
23
23
  objectDelta
24
- } from "../chunk-MJI74VEJ.js";
24
+ } from "../chunk-F5ENANMJ.js";
25
25
  import {
26
26
  AssistantMessage,
27
27
  isAssistantMessage,
28
28
  isToolResultMessage,
29
29
  isUserMessage
30
- } from "../chunk-WU4U6IHF.js";
30
+ } from "../chunk-6QCV4WXF.js";
31
+ import "../chunk-U2G5PHHL.js";
31
32
  import {
32
33
  toError
33
34
  } from "../chunk-GIDT7C6I.js";