@providerprotocol/ai 0.0.34 → 0.0.35
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/README.md +542 -3
- package/dist/anthropic/index.d.ts +2 -1
- package/dist/anthropic/index.js +151 -145
- package/dist/anthropic/index.js.map +1 -1
- package/dist/cerebras/index.d.ts +392 -0
- package/dist/cerebras/index.js +648 -0
- package/dist/cerebras/index.js.map +1 -0
- package/dist/chunk-3GWM5GR3.js +153 -0
- package/dist/chunk-3GWM5GR3.js.map +1 -0
- package/dist/chunk-4OGB7JZA.js +157 -0
- package/dist/chunk-4OGB7JZA.js.map +1 -0
- package/dist/chunk-7DXVRILR.js +49 -0
- package/dist/chunk-7DXVRILR.js.map +1 -0
- package/dist/{chunk-3C7O2RNO.js → chunk-A2IM7PGT.js} +6 -4
- package/dist/{chunk-3C7O2RNO.js.map → chunk-A2IM7PGT.js.map} +1 -1
- package/dist/{chunk-3D6XGGVG.js → chunk-ARVM24K2.js} +2 -2
- package/dist/{chunk-4J6OFUKX.js → chunk-AY55T37A.js} +70 -162
- package/dist/chunk-AY55T37A.js.map +1 -0
- package/dist/{chunk-ILR2D5PN.js → chunk-BRP5XJ6Q.js} +2 -86
- package/dist/chunk-BRP5XJ6Q.js.map +1 -0
- package/dist/chunk-C4JP64VW.js +298 -0
- package/dist/chunk-C4JP64VW.js.map +1 -0
- package/dist/chunk-COS4ON4G.js +111 -0
- package/dist/chunk-COS4ON4G.js.map +1 -0
- package/dist/chunk-ETBFOLQN.js +34 -0
- package/dist/chunk-ETBFOLQN.js.map +1 -0
- package/dist/chunk-HB4ZIH3T.js +31 -0
- package/dist/chunk-HB4ZIH3T.js.map +1 -0
- package/dist/chunk-I53CI6ZZ.js +142 -0
- package/dist/chunk-I53CI6ZZ.js.map +1 -0
- package/dist/chunk-IDZOVWP3.js +29 -0
- package/dist/chunk-IDZOVWP3.js.map +1 -0
- package/dist/chunk-JA3UZALR.js +88 -0
- package/dist/chunk-JA3UZALR.js.map +1 -0
- package/dist/{chunk-WAKD3OO5.js → chunk-N5DX5JW3.js} +31 -31
- package/dist/chunk-N5DX5JW3.js.map +1 -0
- package/dist/chunk-OIEWDFQU.js +97 -0
- package/dist/chunk-OIEWDFQU.js.map +1 -0
- package/dist/{chunk-TOJCZMVU.js → chunk-PMK5LZ5Z.js} +40 -40
- package/dist/chunk-PMK5LZ5Z.js.map +1 -0
- package/dist/chunk-UFFJDYCE.js +94 -0
- package/dist/chunk-UFFJDYCE.js.map +1 -0
- package/dist/chunk-VGKZIGVI.js +222 -0
- package/dist/chunk-VGKZIGVI.js.map +1 -0
- package/dist/chunk-VOEWHQUB.js +31 -0
- package/dist/chunk-VOEWHQUB.js.map +1 -0
- package/dist/{chunk-KUPF5KHT.js → chunk-Y5H7C5J4.js} +2 -2
- package/dist/chunk-ZI67WIQS.js +30 -0
- package/dist/chunk-ZI67WIQS.js.map +1 -0
- package/dist/{embedding-D2BYIehX.d.ts → embedding-CW6SaOOz.d.ts} +1 -1
- package/dist/google/index.d.ts +2 -1
- package/dist/google/index.js +202 -199
- package/dist/google/index.js.map +1 -1
- package/dist/groq/index.d.ts +410 -0
- package/dist/groq/index.js +649 -0
- package/dist/groq/index.js.map +1 -0
- package/dist/http/index.d.ts +3 -2
- package/dist/http/index.js +5 -4
- package/dist/image-stream-C0ciACM2.d.ts +11 -0
- package/dist/index.d.ts +8 -118
- package/dist/index.js +518 -767
- package/dist/index.js.map +1 -1
- package/dist/{llm-BQJZj3cD.d.ts → llm-DwbUK7un.d.ts} +12 -1632
- package/dist/middleware/logging/index.d.ts +76 -0
- package/dist/middleware/logging/index.js +74 -0
- package/dist/middleware/logging/index.js.map +1 -0
- package/dist/middleware/parsed-object/index.d.ts +45 -0
- package/dist/middleware/parsed-object/index.js +73 -0
- package/dist/middleware/parsed-object/index.js.map +1 -0
- package/dist/middleware/pubsub/index.d.ts +104 -0
- package/dist/middleware/pubsub/index.js +230 -0
- package/dist/middleware/pubsub/index.js.map +1 -0
- package/dist/middleware/pubsub/server/express/index.d.ts +52 -0
- package/dist/middleware/pubsub/server/express/index.js +11 -0
- package/dist/middleware/pubsub/server/express/index.js.map +1 -0
- package/dist/middleware/pubsub/server/fastify/index.d.ts +53 -0
- package/dist/middleware/pubsub/server/fastify/index.js +11 -0
- package/dist/middleware/pubsub/server/fastify/index.js.map +1 -0
- package/dist/middleware/pubsub/server/h3/index.d.ts +56 -0
- package/dist/middleware/pubsub/server/h3/index.js +11 -0
- package/dist/middleware/pubsub/server/h3/index.js.map +1 -0
- package/dist/middleware/pubsub/server/index.d.ts +78 -0
- package/dist/middleware/pubsub/server/index.js +34 -0
- package/dist/middleware/pubsub/server/index.js.map +1 -0
- package/dist/middleware/pubsub/server/webapi/index.d.ts +53 -0
- package/dist/middleware/pubsub/server/webapi/index.js +11 -0
- package/dist/middleware/pubsub/server/webapi/index.js.map +1 -0
- package/dist/ollama/index.d.ts +2 -1
- package/dist/ollama/index.js +48 -45
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +2 -1
- package/dist/openai/index.js +319 -313
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +2 -1
- package/dist/openrouter/index.js +379 -383
- package/dist/openrouter/index.js.map +1 -1
- package/dist/proxy/index.d.ts +10 -914
- package/dist/proxy/index.js +275 -1007
- package/dist/proxy/index.js.map +1 -1
- package/dist/proxy/server/express/index.d.ts +161 -0
- package/dist/proxy/server/express/index.js +24 -0
- package/dist/proxy/server/express/index.js.map +1 -0
- package/dist/proxy/server/fastify/index.d.ts +162 -0
- package/dist/proxy/server/fastify/index.js +24 -0
- package/dist/proxy/server/fastify/index.js.map +1 -0
- package/dist/proxy/server/h3/index.d.ts +189 -0
- package/dist/proxy/server/h3/index.js +28 -0
- package/dist/proxy/server/h3/index.js.map +1 -0
- package/dist/proxy/server/index.d.ts +151 -0
- package/dist/proxy/server/index.js +48 -0
- package/dist/proxy/server/index.js.map +1 -0
- package/dist/proxy/server/webapi/index.d.ts +278 -0
- package/dist/proxy/server/webapi/index.js +32 -0
- package/dist/proxy/server/webapi/index.js.map +1 -0
- package/dist/responses/index.d.ts +650 -0
- package/dist/responses/index.js +930 -0
- package/dist/responses/index.js.map +1 -0
- package/dist/{retry-8Ch-WWgX.d.ts → retry-YayV42GV.d.ts} +1 -1
- package/dist/stream-CecfVCPO.d.ts +1632 -0
- package/dist/types-C8Gciizr.d.ts +168 -0
- package/dist/utils/index.d.ts +53 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/xai/index.d.ts +2 -1
- package/dist/xai/index.js +310 -310
- package/dist/xai/index.js.map +1 -1
- package/package.json +82 -4
- package/dist/chunk-4J6OFUKX.js.map +0 -1
- package/dist/chunk-ILR2D5PN.js.map +0 -1
- package/dist/chunk-TOJCZMVU.js.map +0 -1
- package/dist/chunk-WAKD3OO5.js.map +0 -1
- /package/dist/{chunk-3D6XGGVG.js.map → chunk-ARVM24K2.js.map} +0 -0
- /package/dist/{chunk-KUPF5KHT.js.map → chunk-Y5H7C5J4.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/providers/groq/transform.ts","../../src/providers/groq/llm.ts","../../src/providers/groq/index.ts"],"sourcesContent":["/**\n * @fileoverview Groq API Message Transformers\n *\n * This module provides transformation functions for converting between the\n * Universal Provider Protocol (UPP) message format and Groq's Chat Completions\n * API format (OpenAI-compatible). It handles both request transformation (UPP -> Groq)\n * and response transformation (Groq -> UPP), including streaming event transformation.\n *\n * @module providers/groq/transform\n */\n\nimport type { LLMRequest, LLMResponse } from '../../types/llm.ts';\nimport type { Message } from '../../types/messages.ts';\nimport type { StreamEvent } from '../../types/stream.ts';\nimport { StreamEventType } from '../../types/stream.ts';\nimport type { Tool, ToolCall } from '../../types/tool.ts';\nimport type { TokenUsage } from '../../types/turn.ts';\nimport type { ContentBlock, TextBlock, ImageBlock } from '../../types/content.ts';\nimport {\n AssistantMessage,\n isUserMessage,\n isAssistantMessage,\n isToolResultMessage,\n} from '../../types/messages.ts';\nimport { UPPError, ErrorCode, ModalityType } from '../../types/errors.ts';\nimport { generateId } from '../../utils/id.ts';\nimport type {\n GroqLLMParams,\n GroqRequest,\n GroqMessage,\n GroqUserContent,\n GroqTool,\n GroqResponse,\n GroqStreamChunk,\n GroqToolCall,\n} from './types.ts';\n\n/**\n * Normalizes system prompt to string.\n */\nfunction normalizeSystem(system: string | unknown[] | undefined): string | undefined {\n if (system === undefined || system === null) return undefined;\n if (typeof system === 'string') return system;\n if (!Array.isArray(system)) {\n throw new UPPError(\n 'System prompt must be a string or an array of text blocks',\n ErrorCode.InvalidRequest,\n 'groq',\n ModalityType.LLM\n );\n }\n\n const texts: string[] = [];\n for (const block of system) {\n if (!block || typeof block !== 'object' || !('text' in block)) {\n throw new UPPError(\n 'System prompt array must contain objects with a text field',\n ErrorCode.InvalidRequest,\n 'groq',\n ModalityType.LLM\n );\n }\n const textValue = (block as { text?: unknown }).text;\n if (typeof textValue !== 'string') {\n throw new UPPError(\n 'System prompt text must be a string',\n ErrorCode.InvalidRequest,\n 'groq',\n ModalityType.LLM\n );\n }\n if (textValue.length > 0) {\n texts.push(textValue);\n }\n }\n\n return texts.length > 0 ? texts.join('\\n\\n') : undefined;\n}\n\n/**\n * Filters content blocks to only include those with a valid type property.\n */\nfunction filterValidContent<T extends { type?: string }>(content: T[]): T[] {\n return content.filter((c) => c && typeof c.type === 'string');\n}\n\n/**\n * Transforms a UPP content block to Groq user content format.\n */\nfunction transformContentBlock(block: ContentBlock): GroqUserContent {\n switch (block.type) {\n case 'text':\n return { type: 'text', text: block.text };\n\n case 'image': {\n const imageBlock = block as ImageBlock;\n let url: string;\n\n if (imageBlock.source.type === 'base64') {\n url = `data:${imageBlock.mimeType};base64,${imageBlock.source.data}`;\n } else if (imageBlock.source.type === 'url') {\n url = imageBlock.source.url;\n } else if (imageBlock.source.type === 'bytes') {\n const base64 = Buffer.from(imageBlock.source.data).toString('base64');\n url = `data:${imageBlock.mimeType};base64,${base64}`;\n } else {\n throw new UPPError(\n 'Unknown image source type',\n ErrorCode.InvalidRequest,\n 'groq',\n ModalityType.LLM\n );\n }\n\n return {\n type: 'image_url',\n image_url: { url },\n };\n }\n\n case 'document':\n throw new UPPError(\n 'Groq does not support document input',\n ErrorCode.InvalidRequest,\n 'groq',\n ModalityType.LLM\n );\n\n default:\n throw new UPPError(\n `Unsupported content type: ${block.type}`,\n ErrorCode.InvalidRequest,\n 'groq',\n ModalityType.LLM\n );\n }\n}\n\n/**\n * Transforms a single UPP message to Groq format.\n */\nfunction transformMessage(message: Message): GroqMessage | null {\n if (isUserMessage(message)) {\n const validContent = filterValidContent(message.content);\n if (validContent.length === 1 && validContent[0]?.type === 'text') {\n return {\n role: 'user',\n content: (validContent[0] as TextBlock).text,\n };\n }\n return {\n role: 'user',\n content: validContent.map(transformContentBlock),\n };\n }\n\n if (isAssistantMessage(message)) {\n const validContent = filterValidContent(message.content);\n const textContent = validContent\n .filter((c): c is TextBlock => c.type === 'text')\n .map((c) => c.text)\n .join('');\n\n const assistantMessage: GroqMessage = {\n role: 'assistant',\n content: textContent || null,\n };\n\n if (message.toolCalls && message.toolCalls.length > 0) {\n (assistantMessage as { tool_calls?: GroqToolCall[] }).tool_calls =\n message.toolCalls.map((call) => ({\n id: call.toolCallId,\n type: 'function' as const,\n function: {\n name: call.toolName,\n arguments: JSON.stringify(call.arguments),\n },\n }));\n }\n\n return assistantMessage;\n }\n\n if (isToolResultMessage(message)) {\n const results = message.results.map((result) => ({\n role: 'tool' as const,\n tool_call_id: result.toolCallId,\n content:\n typeof result.result === 'string'\n ? result.result\n : JSON.stringify(result.result),\n }));\n\n return results[0] ?? null;\n }\n\n return null;\n}\n\n/**\n * Transforms tool result messages into multiple Groq tool messages.\n */\nexport function transformToolResults(message: Message): GroqMessage[] {\n if (!isToolResultMessage(message)) {\n const single = transformMessage(message);\n return single ? [single] : [];\n }\n\n return message.results.map((result) => ({\n role: 'tool' as const,\n tool_call_id: result.toolCallId,\n content:\n typeof result.result === 'string'\n ? result.result\n : JSON.stringify(result.result),\n }));\n}\n\n/**\n * Transforms UPP messages to Groq message format.\n *\n * @param messages - Array of UPP messages to transform\n * @param system - Optional system prompt\n * @returns Array of Groq-formatted messages\n */\nfunction transformMessages(\n messages: Message[],\n system?: string | unknown[]\n): GroqMessage[] {\n const result: GroqMessage[] = [];\n const normalizedSystem = normalizeSystem(system);\n\n if (normalizedSystem) {\n result.push({\n role: 'system',\n content: normalizedSystem,\n });\n }\n\n for (const message of messages) {\n if (isToolResultMessage(message)) {\n const toolMessages = transformToolResults(message);\n result.push(...toolMessages);\n } else {\n const transformed = transformMessage(message);\n if (transformed) {\n result.push(transformed);\n }\n }\n }\n\n return result;\n}\n\n/**\n * Extracts Groq-specific options from tool metadata.\n */\nfunction extractToolOptions(tool: Tool): { strict?: boolean } {\n const groqMeta = tool.metadata?.groq as { strict?: boolean } | undefined;\n return { strict: groqMeta?.strict };\n}\n\n/**\n * Transforms a UPP tool definition to Groq function tool format.\n */\nfunction transformTool(tool: Tool): GroqTool {\n const { strict } = extractToolOptions(tool);\n\n return {\n type: 'function',\n function: {\n name: tool.name,\n description: tool.description,\n parameters: {\n type: 'object',\n properties: tool.parameters.properties,\n required: tool.parameters.required,\n ...(tool.parameters.additionalProperties !== undefined\n ? { additionalProperties: tool.parameters.additionalProperties }\n : {}),\n },\n ...(strict !== undefined ? { strict } : {}),\n },\n };\n}\n\n/**\n * Transforms a UPP LLM request into Groq Chat Completions API format.\n *\n * @param request - The UPP LLM request containing messages, tools, and configuration\n * @param modelId - The Groq model identifier (e.g., 'llama-3.3-70b-versatile')\n * @returns A Groq Chat Completions API request body\n */\nexport function transformRequest(\n request: LLMRequest<GroqLLMParams>,\n modelId: string\n): GroqRequest {\n const params = request.params ?? ({} as GroqLLMParams);\n\n const groqRequest: GroqRequest = {\n ...params,\n model: modelId,\n messages: transformMessages(request.messages, request.system),\n };\n\n if (request.tools && request.tools.length > 0) {\n groqRequest.tools = request.tools.map(transformTool);\n }\n\n if (request.structure) {\n const schema: Record<string, unknown> = {\n type: 'object',\n properties: request.structure.properties,\n required: request.structure.required,\n ...(request.structure.additionalProperties !== undefined\n ? { additionalProperties: request.structure.additionalProperties }\n : { additionalProperties: false }),\n };\n if (request.structure.description) {\n schema.description = request.structure.description;\n }\n\n groqRequest.response_format = {\n type: 'json_schema',\n json_schema: {\n name: 'json_response',\n description: request.structure.description,\n schema,\n strict: true,\n },\n };\n }\n\n return groqRequest;\n}\n\n/**\n * Transforms a Groq response to UPP LLMResponse format.\n */\nexport function transformResponse(data: GroqResponse): LLMResponse {\n const choice = data.choices[0];\n if (!choice) {\n throw new UPPError(\n 'No choices in Groq response',\n ErrorCode.InvalidResponse,\n 'groq',\n ModalityType.LLM\n );\n }\n\n const textContent: TextBlock[] = [];\n let structuredData: unknown;\n if (choice.message.content) {\n textContent.push({ type: 'text', text: choice.message.content });\n try {\n structuredData = JSON.parse(choice.message.content);\n } catch {\n // Not JSON - expected for non-structured responses\n }\n }\n\n const toolCalls: ToolCall[] = [];\n if (choice.message.tool_calls) {\n for (const call of choice.message.tool_calls) {\n let args: Record<string, unknown> = {};\n try {\n args = JSON.parse(call.function.arguments);\n } catch {\n // Invalid JSON - use empty object\n }\n toolCalls.push({\n toolCallId: call.id,\n toolName: call.function.name,\n arguments: args,\n });\n }\n }\n\n const message = new AssistantMessage(\n textContent,\n toolCalls.length > 0 ? toolCalls : undefined,\n {\n id: data.id || generateId(),\n metadata: {\n groq: {\n model: data.model,\n finish_reason: choice.finish_reason,\n system_fingerprint: data.system_fingerprint,\n },\n },\n }\n );\n\n const usage: TokenUsage = {\n inputTokens: data.usage.prompt_tokens,\n outputTokens: data.usage.completion_tokens,\n totalTokens: data.usage.total_tokens,\n cacheReadTokens: data.usage.prompt_tokens_details?.cached_tokens ?? 0,\n cacheWriteTokens: 0,\n };\n\n let stopReason = 'end_turn';\n switch (choice.finish_reason) {\n case 'stop':\n stopReason = 'end_turn';\n break;\n case 'length':\n stopReason = 'max_tokens';\n break;\n case 'tool_calls':\n stopReason = 'tool_use';\n break;\n case 'content_filter':\n stopReason = 'content_filter';\n break;\n }\n\n return {\n message,\n usage,\n stopReason,\n data: structuredData,\n };\n}\n\n/**\n * Mutable state object for accumulating data during streaming responses.\n */\nexport interface GroqStreamState {\n /** Response ID from the first chunk */\n id: string;\n /** Model identifier */\n model: string;\n /** Accumulated text content */\n text: string;\n /** Map of tool call index to accumulated tool call data */\n toolCalls: Map<number, { id: string; name: string; arguments: string }>;\n /** The finish reason when streaming completes */\n finishReason: string | null;\n /** Input token count (from usage chunk) */\n inputTokens: number;\n /** Output token count (from usage chunk) */\n outputTokens: number;\n /** Number of tokens read from cache */\n cacheReadTokens: number;\n}\n\n/**\n * Creates a fresh stream state object for a new streaming session.\n */\nexport function createStreamState(): GroqStreamState {\n return {\n id: '',\n model: '',\n text: '',\n toolCalls: new Map(),\n finishReason: null,\n inputTokens: 0,\n outputTokens: 0,\n cacheReadTokens: 0,\n };\n}\n\n/**\n * Transforms a Groq streaming chunk into UPP stream events.\n */\nexport function transformStreamEvent(\n chunk: GroqStreamChunk,\n state: GroqStreamState\n): StreamEvent[] {\n const events: StreamEvent[] = [];\n\n if (chunk.id && !state.id) {\n state.id = chunk.id;\n events.push({ type: StreamEventType.MessageStart, index: 0, delta: {} });\n }\n if (chunk.model) {\n state.model = chunk.model;\n }\n\n const choice = chunk.choices[0];\n if (choice) {\n if (choice.delta.content) {\n state.text += choice.delta.content;\n events.push({\n type: StreamEventType.TextDelta,\n index: 0,\n delta: { text: choice.delta.content },\n });\n }\n\n if (choice.delta.tool_calls) {\n for (const toolCallDelta of choice.delta.tool_calls) {\n const index = toolCallDelta.index;\n let toolCall = state.toolCalls.get(index);\n\n if (!toolCall) {\n toolCall = { id: '', name: '', arguments: '' };\n state.toolCalls.set(index, toolCall);\n }\n\n if (toolCallDelta.id) {\n toolCall.id = toolCallDelta.id;\n }\n if (toolCallDelta.function?.name) {\n toolCall.name = toolCallDelta.function.name;\n }\n if (toolCallDelta.function?.arguments) {\n toolCall.arguments += toolCallDelta.function.arguments;\n events.push({\n type: StreamEventType.ToolCallDelta,\n index: index,\n delta: {\n toolCallId: toolCall.id,\n toolName: toolCall.name,\n argumentsJson: toolCallDelta.function.arguments,\n },\n });\n }\n }\n }\n\n if (choice.finish_reason) {\n state.finishReason = choice.finish_reason;\n events.push({ type: StreamEventType.MessageStop, index: 0, delta: {} });\n }\n }\n\n // Handle usage - can be in chunk.usage or chunk.x_groq.usage\n const usageData = chunk.usage ?? chunk.x_groq?.usage;\n if (usageData) {\n state.inputTokens = usageData.prompt_tokens;\n state.outputTokens = usageData.completion_tokens;\n state.cacheReadTokens = usageData.prompt_tokens_details?.cached_tokens ?? 0;\n }\n\n return events;\n}\n\n/**\n * Builds a complete LLMResponse from accumulated streaming state.\n */\nexport function buildResponseFromState(state: GroqStreamState): LLMResponse {\n const textContent: TextBlock[] = [];\n let structuredData: unknown;\n if (state.text) {\n textContent.push({ type: 'text', text: state.text });\n try {\n structuredData = JSON.parse(state.text);\n } catch {\n // Not JSON - expected for non-structured responses\n }\n }\n\n const toolCalls: ToolCall[] = [];\n for (const [, toolCall] of state.toolCalls) {\n let args: Record<string, unknown> = {};\n if (toolCall.arguments) {\n try {\n args = JSON.parse(toolCall.arguments);\n } catch {\n // Invalid JSON - use empty object\n }\n }\n toolCalls.push({\n toolCallId: toolCall.id,\n toolName: toolCall.name,\n arguments: args,\n });\n }\n\n const messageId = state.id || generateId();\n const message = new AssistantMessage(\n textContent,\n toolCalls.length > 0 ? toolCalls : undefined,\n {\n id: messageId,\n metadata: {\n groq: {\n model: state.model,\n finish_reason: state.finishReason,\n },\n },\n }\n );\n\n const usage: TokenUsage = {\n inputTokens: state.inputTokens,\n outputTokens: state.outputTokens,\n totalTokens: state.inputTokens + state.outputTokens,\n cacheReadTokens: state.cacheReadTokens,\n cacheWriteTokens: 0,\n };\n\n let stopReason = 'end_turn';\n switch (state.finishReason) {\n case 'stop':\n stopReason = 'end_turn';\n break;\n case 'length':\n stopReason = 'max_tokens';\n break;\n case 'tool_calls':\n stopReason = 'tool_use';\n break;\n case 'content_filter':\n stopReason = 'content_filter';\n break;\n }\n\n return {\n message,\n usage,\n stopReason,\n data: structuredData,\n };\n}\n","/**\n * @fileoverview Groq Chat Completions API Handler\n *\n * This module implements the LLM handler for Groq's Chat Completions API\n * (OpenAI-compatible at `/openai/v1/chat/completions`).\n *\n * @see {@link https://console.groq.com/docs/api-reference Groq API Reference}\n * @module providers/groq/llm\n */\n\nimport type { BoundLLMModel, LLMRequest, LLMResponse, LLMStreamResult, LLMCapabilities } from '../../types/llm.ts';\nimport type { LLMHandler } from '../../types/provider.ts';\nimport type { StreamEvent } from '../../types/stream.ts';\nimport { StreamEventType, objectDelta } from '../../types/stream.ts';\nimport type { LLMProvider } from '../../types/provider.ts';\nimport { UPPError, ErrorCode, ModalityType } from '../../types/errors.ts';\nimport { resolveApiKey } from '../../http/keys.ts';\nimport { doFetch, doStreamFetch } from '../../http/fetch.ts';\nimport { parseSSEStream } from '../../http/sse.ts';\nimport { normalizeHttpError } from '../../http/errors.ts';\nimport { parseJsonResponse } from '../../http/json.ts';\nimport { toError } from '../../utils/error.ts';\nimport type { GroqLLMParams, GroqResponse, GroqStreamChunk } from './types.ts';\nimport {\n transformRequest,\n transformResponse,\n transformStreamEvent,\n createStreamState,\n buildResponseFromState,\n} from './transform.ts';\n\n/** Base URL for Groq's Chat Completions API endpoint */\nconst GROQ_API_URL = 'https://api.groq.com/openai/v1/chat/completions';\n\n/**\n * Capability declaration for the Groq Chat Completions API.\n *\n * Defines what features are supported by this handler:\n * - Streaming: Real-time token-by-token response streaming via SSE\n * - Tools: Function calling for structured interactions\n * - Structured Output: JSON schema-based response formatting\n * - Image Input: Vision capabilities on select models (Llama 4 preview)\n */\nconst GROQ_CAPABILITIES: LLMCapabilities = {\n streaming: true,\n tools: true,\n structuredOutput: true,\n imageInput: true,\n documentInput: false,\n videoInput: false,\n audioInput: false,\n};\n\n/**\n * Creates an LLM handler for Groq's Chat Completions API.\n *\n * This factory function creates a handler that communicates with the\n * `/openai/v1/chat/completions` endpoint. The handler supports both synchronous\n * completion requests and streaming responses.\n *\n * @returns An LLM handler configured for the Groq API\n *\n * @example\n * ```typescript\n * const handler = createLLMHandler();\n * const model = handler.bind('llama-3.3-70b-versatile');\n *\n * // Synchronous completion\n * const response = await model.complete({\n * messages: [{ role: 'user', content: 'Hello!' }],\n * config: { apiKey: 'gsk_...' }\n * });\n *\n * // Streaming completion\n * const stream = model.stream({\n * messages: [{ role: 'user', content: 'Tell me a story' }],\n * config: { apiKey: 'gsk_...' }\n * });\n *\n * for await (const event of stream) {\n * if (event.type === StreamEventType.TextDelta) {\n * process.stdout.write(event.delta.text);\n * }\n * }\n * ```\n */\nexport function createLLMHandler(): LLMHandler<GroqLLMParams> {\n let providerRef: LLMProvider<GroqLLMParams> | null = null;\n\n return {\n _setProvider(provider: LLMProvider<GroqLLMParams>) {\n providerRef = provider;\n },\n\n bind(modelId: string): BoundLLMModel<GroqLLMParams> {\n if (!providerRef) {\n throw new UPPError(\n 'Provider reference not set. Handler must be used with createProvider() or have _setProvider called.',\n ErrorCode.InvalidRequest,\n 'groq',\n ModalityType.LLM\n );\n }\n\n const model: BoundLLMModel<GroqLLMParams> = {\n modelId,\n capabilities: GROQ_CAPABILITIES,\n\n get provider(): LLMProvider<GroqLLMParams> {\n return providerRef!;\n },\n\n async complete(request: LLMRequest<GroqLLMParams>): Promise<LLMResponse> {\n const apiKey = await resolveApiKey(\n request.config,\n 'GROQ_API_KEY',\n 'groq',\n 'llm'\n );\n\n const baseUrl = request.config.baseUrl ?? GROQ_API_URL;\n const body = transformRequest(request, modelId);\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n };\n\n if (request.config.headers) {\n for (const [key, value] of Object.entries(request.config.headers)) {\n if (value !== undefined) {\n headers[key] = value;\n }\n }\n }\n\n const response = await doFetch(\n baseUrl,\n {\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n signal: request.signal,\n },\n request.config,\n 'groq',\n 'llm'\n );\n\n const data = await parseJsonResponse<GroqResponse>(response, 'groq', 'llm');\n return transformResponse(data);\n },\n\n stream(request: LLMRequest<GroqLLMParams>): LLMStreamResult {\n const state = createStreamState();\n let responseResolve: (value: LLMResponse) => void;\n let responseReject: (error: Error) => void;\n\n const responsePromise = new Promise<LLMResponse>((resolve, reject) => {\n responseResolve = resolve;\n responseReject = reject;\n });\n\n async function* generateEvents(): AsyncGenerator<StreamEvent, void, unknown> {\n try {\n const apiKey = await resolveApiKey(\n request.config,\n 'GROQ_API_KEY',\n 'groq',\n 'llm'\n );\n\n const baseUrl = request.config.baseUrl ?? GROQ_API_URL;\n const body = transformRequest(request, modelId);\n body.stream = true;\n body.stream_options = { include_usage: true };\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${apiKey}`,\n Accept: 'text/event-stream',\n };\n\n if (request.config.headers) {\n for (const [key, value] of Object.entries(request.config.headers)) {\n if (value !== undefined) {\n headers[key] = value;\n }\n }\n }\n\n const response = await doStreamFetch(\n baseUrl,\n {\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n signal: request.signal,\n },\n request.config,\n 'groq',\n 'llm'\n );\n\n if (!response.ok) {\n const error = await normalizeHttpError(response, 'groq', 'llm');\n responseReject(error);\n throw error;\n }\n\n if (!response.body) {\n const error = new UPPError(\n 'No response body for streaming request',\n ErrorCode.ProviderError,\n 'groq',\n ModalityType.LLM\n );\n responseReject(error);\n throw error;\n }\n\n for await (const data of parseSSEStream(response.body)) {\n // Skip [DONE] marker\n if (data === '[DONE]') {\n continue;\n }\n\n // Check for Groq error event\n if (typeof data === 'object' && data !== null) {\n const chunk = data as GroqStreamChunk;\n\n // Check for error in chunk\n if ('error' in chunk && chunk.error) {\n const errorData = chunk.error as { message?: string; type?: string };\n const error = new UPPError(\n errorData.message ?? 'Unknown error',\n ErrorCode.ProviderError,\n 'groq',\n ModalityType.LLM\n );\n responseReject(error);\n throw error;\n }\n\n const uppEvents = transformStreamEvent(chunk, state);\n for (const event of uppEvents) {\n yield event;\n // Also emit ObjectDelta for structured output - gives developers explicit hook\n if (request.structure && event.type === StreamEventType.TextDelta) {\n yield objectDelta(event.delta.text ?? '', event.index);\n }\n }\n }\n }\n\n // Build final response\n responseResolve(buildResponseFromState(state));\n } catch (error) {\n const err = toError(error);\n responseReject(err);\n throw err;\n }\n }\n\n return {\n [Symbol.asyncIterator]() {\n return generateEvents();\n },\n response: responsePromise,\n };\n },\n };\n\n return model;\n },\n };\n}\n","/**\n * @fileoverview Groq Provider Factory\n *\n * This module provides the main Groq provider implementation for the\n * OpenAI-compatible Chat Completions API.\n *\n * @module providers/groq\n */\n\nimport { createProvider } from '../../core/provider.ts';\nimport { createLLMHandler } from './llm.ts';\n\n/**\n * Configuration options for the Groq provider.\n *\n * Currently Groq only supports one API endpoint (Chat Completions),\n * so no additional options are needed.\n */\nexport interface GroqProviderOptions {\n // Reserved for future use (e.g., if Groq adds multiple API modes)\n}\n\n/**\n * The Groq provider instance.\n *\n * Use this provider to create model references for Groq models like\n * Llama 3.3, Llama 3.1, Gemma 2, and other models available on Groq.\n *\n * @example Basic usage\n * ```typescript\n * import { groq } from './providers/groq';\n * import { llm } from './core/llm';\n *\n * const model = llm({\n * model: groq('llama-3.3-70b-versatile'),\n * params: { max_tokens: 1000 }\n * });\n *\n * const turn = await model.generate('Hello!');\n * console.log(turn.response.text);\n * ```\n *\n * @example With streaming\n * ```typescript\n * const stream = model.stream('Tell me a story');\n *\n * for await (const event of stream) {\n * if (event.type === StreamEventType.TextDelta) {\n * process.stdout.write(event.delta.text ?? '');\n * }\n * }\n *\n * const turn = await stream.turn;\n * console.log('Tokens used:', turn.usage.totalTokens);\n * ```\n *\n * @example With tools\n * ```typescript\n * const calculator = {\n * name: 'calculate',\n * description: 'Calculate a math expression',\n * parameters: {\n * type: 'object',\n * properties: {\n * expression: { type: 'string' }\n * },\n * required: ['expression']\n * },\n * run: async (params: { expression: string }) => {\n * return eval(params.expression);\n * }\n * };\n *\n * const model = llm({\n * model: groq('llama-3.3-70b-versatile'),\n * tools: [calculator]\n * });\n *\n * const turn = await model.generate('What is 15 + 27?');\n * ```\n *\n * @example Available models\n * Production models:\n * - `llama-3.3-70b-versatile` - Versatile model with tool use support\n * - `llama-3.1-8b-instant` - Fast, efficient model\n * - `llama-guard-4-12b` - Content moderation model\n * - `gemma2-9b-it` - Google's Gemma 2 model\n *\n * Preview models:\n * - `meta-llama/llama-4-scout-17b-16e-instruct` - Vision + tool use\n * - `qwen/qwen3-32b` - Qwen 3 model\n */\nexport const groq = createProvider<GroqProviderOptions>({\n name: 'groq',\n version: '1.0.0',\n handlers: {\n llm: createLLMHandler(),\n },\n});\n\nexport type {\n GroqLLMParams,\n GroqHeaders,\n GroqResponseFormat,\n GroqMessage,\n GroqRequest,\n GroqResponse,\n GroqStreamChunk,\n GroqTool,\n GroqToolCall,\n GroqToolChoice,\n GroqUsage,\n GroqSearchSettings,\n GroqDocument,\n GroqCitationOptions,\n} from './types.ts';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAS,gBAAgB,QAA4D;AACnF,MAAI,WAAW,UAAa,WAAW,KAAM,QAAO;AACpD,MAAI,OAAO,WAAW,SAAU,QAAO;AACvC,MAAI,CAAC,MAAM,QAAQ,MAAM,GAAG;AAC1B,UAAM,IAAI;AAAA,MACR;AAAA,MACA,UAAU;AAAA,MACV;AAAA,MACA,aAAa;AAAA,IACf;AAAA,EACF;AAEA,QAAM,QAAkB,CAAC;AACzB,aAAW,SAAS,QAAQ;AAC1B,QAAI,CAAC,SAAS,OAAO,UAAU,YAAY,EAAE,UAAU,QAAQ;AAC7D,YAAM,IAAI;AAAA,QACR;AAAA,QACA,UAAU;AAAA,QACV;AAAA,QACA,aAAa;AAAA,MACf;AAAA,I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AuB,KAAK,CAAC;AAAA,YAC/C,SAAS,OAAO;AACd,oBAAM,MAAM,QAAQ,KAAK;AACzB,6BAAe,GAAG;AAClB,oBAAM;AAAA,YACR;AAAA,UACF;AAEA,iBAAO;AAAA,YACL,CAAC,OAAO,aAAa,IAAI;AACvB,qBAAO,eAAe;AAAA,YACxB;AAAA,YACA,UAAU;AAAA,UACZ;AAAA,QACF;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;;;ACxLO,IAAM,OAAO,eAAoC;AAAA,EACtD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU;AAAA,IACR,KAAK,iBAAiB;AAAA,EACxB;AACF,CAAC;","names":[]}
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { D as DynamicKey, E as ExponentialBackoff, L as LinearBackoff, N as NoRetry, a as RetryAfterStrategy, R as RoundRobinKeys, T as TokenBucket, W as WeightedKeys, m as maskApiKey, r as resolveApiKey } from '../retry-
|
|
2
|
-
import {
|
|
1
|
+
export { D as DynamicKey, E as ExponentialBackoff, L as LinearBackoff, N as NoRetry, a as RetryAfterStrategy, R as RoundRobinKeys, T as TokenBucket, W as WeightedKeys, m as maskApiKey, r as resolveApiKey } from '../retry-YayV42GV.js';
|
|
2
|
+
import { b as ProviderConfig, e as Modality, U as UPPError, f as ErrorCode } from '../llm-DwbUK7un.js';
|
|
3
|
+
import '../stream-CecfVCPO.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* HTTP fetch utilities with retry, timeout, and error normalization.
|
package/dist/http/index.js
CHANGED
|
@@ -4,18 +4,18 @@ import {
|
|
|
4
4
|
NoRetry,
|
|
5
5
|
RetryAfterStrategy,
|
|
6
6
|
TokenBucket
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-Y5H7C5J4.js";
|
|
8
8
|
import {
|
|
9
9
|
parseSSEStream,
|
|
10
10
|
parseSimpleTextStream
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-PMK5LZ5Z.js";
|
|
12
12
|
import {
|
|
13
13
|
DynamicKey,
|
|
14
14
|
RoundRobinKeys,
|
|
15
15
|
WeightedKeys,
|
|
16
16
|
maskApiKey,
|
|
17
17
|
resolveApiKey
|
|
18
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-ARVM24K2.js";
|
|
19
19
|
import {
|
|
20
20
|
cancelledError,
|
|
21
21
|
doFetch,
|
|
@@ -25,7 +25,8 @@ import {
|
|
|
25
25
|
statusToErrorCode,
|
|
26
26
|
timeoutError,
|
|
27
27
|
warnInsecureUrl
|
|
28
|
-
} from "../chunk-
|
|
28
|
+
} from "../chunk-AY55T37A.js";
|
|
29
|
+
import "../chunk-COS4ON4G.js";
|
|
29
30
|
export {
|
|
30
31
|
DynamicKey,
|
|
31
32
|
ExponentialBackoff,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { I as ImageStreamResult, a as ImageProviderStreamResult } from './llm-DwbUK7un.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Image stream helpers for proxy server adapters.
|
|
5
|
+
*
|
|
6
|
+
* @module providers/proxy/server/image-stream
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
type ImageStreamLike = ImageStreamResult | ImageProviderStreamResult;
|
|
10
|
+
|
|
11
|
+
export type { ImageStreamLike as I };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { L as LLMOptions,
|
|
2
|
-
export {
|
|
3
|
-
import { E as EmbeddingOptions, a as EmbeddingInstance } from './embedding-
|
|
4
|
-
export { b as EmbedOptions, c as Embedding, h as EmbeddingInputType, g as EmbeddingModelInput, e as EmbeddingProgress, d as EmbeddingResult, f as EmbeddingStream } from './embedding-
|
|
5
|
-
|
|
1
|
+
import { L as LLMOptions, h as LLMInstance, i as ImageOptions, j as ImageInstance, k as LLMHandler, l as EmbeddingHandler, m as ImageHandler, d as Provider, g as ModelReference } from './llm-DwbUK7un.js';
|
|
2
|
+
export { a0 as AnyRequest, a1 as AnyResponse, B as BoundEmbeddingModel, X as BoundImageModel, A as BoundLLMModel, E as EmbeddingInput, r as EmbeddingProvider, t as EmbeddingRequest, u as EmbeddingResponse, c as EmbeddingUsage, v as EmbeddingVector, f as ErrorCode, H as GeneratedImage, n as Image, Q as ImageCapabilities, F as ImageEditInput, V as ImageEditRequest, G as ImageGenerateOptions, D as ImageInput, Y as ImageModelInput, s as ImageProvider, a as ImageProviderStreamResult, S as ImageRequest, W as ImageResponse, N as ImageResult, O as ImageStreamEvent, I as ImageStreamResult, J as ImageUsage, C as InferenceInput, K as KeyStrategy, w as LLMCapabilities, q as LLMProvider, x as LLMRequest, y as LLMResponse, z as LLMStreamResult, M as Middleware, Z as MiddlewareContext, $ as MiddlewareModality, e as Modality, o as ModalityType, b as ProviderConfig, P as ProviderIdentity, R as RetryStrategy, _ as StreamContext, T as Thread, p as ThreadJSON, U as UPPError } from './llm-DwbUK7un.js';
|
|
3
|
+
import { E as EmbeddingOptions, a as EmbeddingInstance } from './embedding-CW6SaOOz.js';
|
|
4
|
+
export { b as EmbedOptions, c as Embedding, h as EmbeddingInputType, g as EmbeddingModelInput, e as EmbeddingProgress, d as EmbeddingResult, f as EmbeddingStream } from './embedding-CW6SaOOz.js';
|
|
5
|
+
import { D as DocumentSource, j as DocumentBlock, k as AudioBlock, V as VideoBlock } from './stream-CecfVCPO.js';
|
|
6
|
+
export { L as AfterCallResult, A as AssistantContent, g as AssistantMessage, K as BeforeCallResult, B as BinaryBlock, C as ContentBlock, o as ContentBlockType, q as DocumentSourceType, E as EventDelta, c as ImageBlock, I as ImageSource, p as ImageSourceType, J as JSONSchema, l as JSONSchemaProperty, m as JSONSchemaPropertyType, M as Message, a as MessageJSON, Z as MessageMetadata, _ as MessageOptions, Q as MessageRole, e as MessageType, R as ReasoningBlock, S as StreamEvent, a2 as StreamEventType, i as StreamResult, n as TextBlock, h as TokenUsage, d as Tool, F as ToolCall, N as ToolExecution, H as ToolMetadata, G as ToolResult, P as ToolResultMessage, f as ToolUseStrategy, T as Turn, U as UserContent, O as UserMessage, a1 as aggregateUsage, a9 as contentBlockStart, aa as contentBlockStop, a3 as createStreamResult, $ as createTurn, a0 as emptyUsage, X as isAssistantMessage, x as isAudioBlock, z as isBinaryBlock, w as isDocumentBlock, v as isImageBlock, u as isReasoningBlock, s as isTextBlock, Y as isToolResultMessage, W as isUserMessage, y as isVideoBlock, a7 as messageStart, a8 as messageStop, a6 as objectDelta, r as reasoning, t as text, a4 as textDelta, a5 as toolCallDelta, ac as toolExecutionEnd, ab as toolExecutionStart } from './stream-CecfVCPO.js';
|
|
7
|
+
export { D as DynamicKey, E as ExponentialBackoff, L as LinearBackoff, N as NoRetry, a as RetryAfterStrategy, R as RoundRobinKeys, T as TokenBucket, W as WeightedKeys } from './retry-YayV42GV.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* @fileoverview LLM instance factory and streaming logic for the Universal Provider Protocol.
|
|
@@ -680,118 +682,6 @@ declare class Video {
|
|
|
680
682
|
static fromBlock(block: VideoBlock): Video;
|
|
681
683
|
}
|
|
682
684
|
|
|
683
|
-
/**
|
|
684
|
-
* @fileoverview Parsed object middleware for incremental JSON parsing.
|
|
685
|
-
*
|
|
686
|
-
* This middleware parses partial JSON from ObjectDelta and ToolCallDelta
|
|
687
|
-
* stream events, providing incremental structured data during streaming.
|
|
688
|
-
*
|
|
689
|
-
* @module middleware/parsed-object
|
|
690
|
-
*/
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* Event delta with parsed JSON data.
|
|
694
|
-
* Extended by parsedObjectMiddleware when parsing is enabled.
|
|
695
|
-
*/
|
|
696
|
-
interface ParsedEventDelta extends EventDelta {
|
|
697
|
-
/** Incrementally parsed JSON value */
|
|
698
|
-
parsed?: unknown;
|
|
699
|
-
}
|
|
700
|
-
/**
|
|
701
|
-
* Stream event with parsed JSON data.
|
|
702
|
-
* Returned by parsedObjectMiddleware for ObjectDelta and ToolCallDelta events.
|
|
703
|
-
*/
|
|
704
|
-
interface ParsedStreamEvent extends Omit<StreamEvent, 'delta'> {
|
|
705
|
-
delta: ParsedEventDelta;
|
|
706
|
-
}
|
|
707
|
-
/**
|
|
708
|
-
* Options for parsed object middleware.
|
|
709
|
-
*/
|
|
710
|
-
interface ParsedObjectOptions {
|
|
711
|
-
/**
|
|
712
|
-
* Parse ObjectDelta events (structured output responses).
|
|
713
|
-
* @default true
|
|
714
|
-
*/
|
|
715
|
-
parseObjects?: boolean;
|
|
716
|
-
/**
|
|
717
|
-
* Parse ToolCallDelta events (tool call arguments).
|
|
718
|
-
* @default true
|
|
719
|
-
*/
|
|
720
|
-
parseToolCalls?: boolean;
|
|
721
|
-
}
|
|
722
|
-
declare function parsedObjectMiddleware(options?: ParsedObjectOptions): Middleware;
|
|
723
|
-
|
|
724
|
-
/**
|
|
725
|
-
* @fileoverview Logging middleware for request/response visibility.
|
|
726
|
-
*
|
|
727
|
-
* Provides configurable logging for LLM, embedding, and image operations,
|
|
728
|
-
* including timing, error tracking, and optional event logging.
|
|
729
|
-
*
|
|
730
|
-
* @module middleware/logging
|
|
731
|
-
*/
|
|
732
|
-
|
|
733
|
-
/**
|
|
734
|
-
* Log levels for filtering output.
|
|
735
|
-
*/
|
|
736
|
-
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
737
|
-
/**
|
|
738
|
-
* Options for logging middleware.
|
|
739
|
-
*/
|
|
740
|
-
interface LoggingOptions {
|
|
741
|
-
/**
|
|
742
|
-
* Minimum log level to output.
|
|
743
|
-
* @default 'info'
|
|
744
|
-
*/
|
|
745
|
-
level?: LogLevel;
|
|
746
|
-
/**
|
|
747
|
-
* Log individual stream events.
|
|
748
|
-
* @default false
|
|
749
|
-
*/
|
|
750
|
-
logStreamEvents?: boolean;
|
|
751
|
-
/**
|
|
752
|
-
* Log tool calls and results.
|
|
753
|
-
* @default true
|
|
754
|
-
*/
|
|
755
|
-
logToolCalls?: boolean;
|
|
756
|
-
/**
|
|
757
|
-
* Custom logger function. If not provided, uses console.log.
|
|
758
|
-
* @param level - The log level
|
|
759
|
-
* @param message - The log message
|
|
760
|
-
* @param data - Optional additional data
|
|
761
|
-
*/
|
|
762
|
-
logger?(level: LogLevel, message: string, data?: Record<string, unknown>): void;
|
|
763
|
-
/**
|
|
764
|
-
* Prefix for all log messages.
|
|
765
|
-
* @default '[PP]'
|
|
766
|
-
*/
|
|
767
|
-
prefix?: string;
|
|
768
|
-
}
|
|
769
|
-
/**
|
|
770
|
-
* Creates a logging middleware for visibility into request lifecycle.
|
|
771
|
-
*
|
|
772
|
-
* This middleware logs the start, end, and errors of requests,
|
|
773
|
-
* with optional logging of stream events and tool calls.
|
|
774
|
-
*
|
|
775
|
-
* @param options - Configuration options
|
|
776
|
-
* @returns A middleware that logs request lifecycle events
|
|
777
|
-
*
|
|
778
|
-
* @example
|
|
779
|
-
* ```typescript
|
|
780
|
-
* import { llm, loggingMiddleware } from '@providerprotocol/ai';
|
|
781
|
-
* import { anthropic } from '@providerprotocol/ai/anthropic';
|
|
782
|
-
*
|
|
783
|
-
* const model = llm({
|
|
784
|
-
* model: anthropic('claude-sonnet-4-20250514'),
|
|
785
|
-
* middleware: [loggingMiddleware({ level: 'debug' })],
|
|
786
|
-
* });
|
|
787
|
-
*
|
|
788
|
-
* // Logs: [PP] [anthropic] Starting llm request (streaming)
|
|
789
|
-
* // Logs: [PP] [anthropic] Completed in 1234ms
|
|
790
|
-
* const result = await model.generate('Hello');
|
|
791
|
-
* ```
|
|
792
|
-
*/
|
|
793
|
-
declare function loggingMiddleware(options?: LoggingOptions): Middleware;
|
|
794
|
-
|
|
795
685
|
/**
|
|
796
686
|
* @fileoverview Unified Provider Protocol (UPP) - A unified interface for AI model inference
|
|
797
687
|
*
|
|
@@ -850,4 +740,4 @@ declare const ai: {
|
|
|
850
740
|
image: typeof image;
|
|
851
741
|
};
|
|
852
742
|
|
|
853
|
-
export { Audio, AudioBlock, Document, DocumentBlock, DocumentSource, EmbeddingHandler, EmbeddingInstance, EmbeddingOptions,
|
|
743
|
+
export { Audio, AudioBlock, Document, DocumentBlock, DocumentSource, EmbeddingHandler, EmbeddingInstance, EmbeddingOptions, ImageHandler, ImageInstance, ImageOptions, LLMHandler, LLMInstance, LLMOptions, ModelReference, Provider, Video, VideoBlock, ai, createProvider, embedding, image, llm };
|