@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.
- package/README.md +269 -34
- package/dist/anthropic/index.d.ts +3 -3
- package/dist/anthropic/index.js +7 -5
- package/dist/anthropic/index.js.map +1 -1
- package/dist/cerebras/index.d.ts +3 -3
- package/dist/cerebras/index.js +7 -5
- package/dist/cerebras/index.js.map +1 -1
- package/dist/{chunk-WU4U6IHF.js → chunk-6QCV4WXF.js} +4 -13
- package/dist/chunk-6QCV4WXF.js.map +1 -0
- package/dist/{chunk-5XPRVUOK.js → chunk-AC3VHSZJ.js} +2 -2
- package/dist/{chunk-5XPRVUOK.js.map → chunk-AC3VHSZJ.js.map} +1 -1
- package/dist/{chunk-ZDYEDI2A.js → chunk-CWGTARDE.js} +2 -2
- package/dist/{chunk-KNBODIQU.js → chunk-DI47UY2H.js} +2 -2
- package/dist/{chunk-KNBODIQU.js.map → chunk-DI47UY2H.js.map} +1 -1
- package/dist/{chunk-IDZR4ROP.js → chunk-EHR3LIPS.js} +2 -2
- package/dist/{chunk-IDZR4ROP.js.map → chunk-EHR3LIPS.js.map} +1 -1
- package/dist/chunk-EY2LLDGY.js +94 -0
- package/dist/chunk-EY2LLDGY.js.map +1 -0
- package/dist/{chunk-MJI74VEJ.js → chunk-F5ENANMJ.js} +18 -2
- package/dist/chunk-F5ENANMJ.js.map +1 -0
- package/dist/chunk-IKJH5ZSJ.js +1 -0
- package/dist/chunk-IKJH5ZSJ.js.map +1 -0
- package/dist/{chunk-IIMTP3XC.js → chunk-KBI45OXI.js} +2 -2
- package/dist/{chunk-SAMIK4WZ.js → chunk-KVUOTFYZ.js} +2 -2
- package/dist/{chunk-U6M3MXNI.js → chunk-L6QWKFGE.js} +3 -2
- package/dist/chunk-L6QWKFGE.js.map +1 -0
- package/dist/{chunk-RDC5GYST.js → chunk-N4LAFGLX.js} +7 -7
- package/dist/{chunk-ZKNPQBIE.js → chunk-R3T2IYOU.js} +5 -3
- package/dist/{chunk-ZKNPQBIE.js.map → chunk-R3T2IYOU.js.map} +1 -1
- package/dist/chunk-U2G5PHHL.js +25 -0
- package/dist/chunk-U2G5PHHL.js.map +1 -0
- package/dist/{chunk-SBGZJVTJ.js → chunk-VQZPADW6.js} +100 -33
- package/dist/chunk-VQZPADW6.js.map +1 -0
- package/dist/{chunk-O32SBS6S.js → chunk-XTWBAL42.js} +2 -2
- package/dist/{chunk-O32SBS6S.js.map → chunk-XTWBAL42.js.map} +1 -1
- package/dist/{chunk-WNB5PSY6.js → chunk-ZMESKGUY.js} +2 -2
- package/dist/{chunk-7ULSRWDH.js → chunk-ZSZVWLGE.js} +2 -2
- package/dist/{embedding-iNQCeXfk.d.ts → embedding-ts1npsDg.d.ts} +1 -1
- package/dist/google/index.d.ts +38 -4
- package/dist/google/index.js +5 -4
- package/dist/google/index.js.map +1 -1
- package/dist/groq/index.d.ts +3 -3
- package/dist/groq/index.js +7 -5
- package/dist/groq/index.js.map +1 -1
- package/dist/http/index.d.ts +5 -5
- package/dist/http/index.js +19 -22
- package/dist/{image-stream-ARno6XlS.d.ts → image-stream-BPml2YZZ.d.ts} +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.js +306 -112
- package/dist/index.js.map +1 -1
- package/dist/{llm-CZqlijjK.d.ts → llm-BWLaTzzY.d.ts} +75 -29
- package/dist/middleware/logging/index.d.ts +3 -3
- package/dist/middleware/logging/index.js +3 -0
- package/dist/middleware/logging/index.js.map +1 -1
- package/dist/middleware/parsed-object/index.d.ts +3 -3
- package/dist/middleware/parsed-object/index.js +5 -1
- package/dist/middleware/parsed-object/index.js.map +1 -1
- package/dist/middleware/persistence/index.d.ts +3 -3
- package/dist/middleware/persistence/index.js +3 -2
- package/dist/middleware/persistence/index.js.map +1 -1
- package/dist/middleware/pipeline/index.d.ts +195 -0
- package/dist/middleware/pipeline/index.js +61 -0
- package/dist/middleware/pipeline/index.js.map +1 -0
- package/dist/middleware/pubsub/index.d.ts +13 -11
- package/dist/middleware/pubsub/index.js +31 -5
- package/dist/middleware/pubsub/index.js.map +1 -1
- package/dist/middleware/pubsub/server/express/index.d.ts +3 -3
- package/dist/middleware/pubsub/server/express/index.js +2 -2
- package/dist/middleware/pubsub/server/fastify/index.d.ts +3 -3
- package/dist/middleware/pubsub/server/fastify/index.js +2 -2
- package/dist/middleware/pubsub/server/h3/index.d.ts +3 -3
- package/dist/middleware/pubsub/server/h3/index.js +2 -2
- package/dist/middleware/pubsub/server/index.d.ts +50 -9
- package/dist/middleware/pubsub/server/index.js +5 -5
- package/dist/middleware/pubsub/server/index.js.map +1 -1
- package/dist/middleware/pubsub/server/webapi/index.d.ts +3 -3
- package/dist/middleware/pubsub/server/webapi/index.js +2 -2
- package/dist/moonshot/index.d.ts +3 -3
- package/dist/moonshot/index.js +7 -5
- package/dist/moonshot/index.js.map +1 -1
- package/dist/ollama/index.d.ts +24 -4
- package/dist/ollama/index.js +5 -4
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +65 -4
- package/dist/openai/index.js +7 -5
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +4 -4
- package/dist/openrouter/index.js +7 -5
- package/dist/openrouter/index.js.map +1 -1
- package/dist/proxy/index.d.ts +5 -5
- package/dist/proxy/index.js +16 -15
- package/dist/proxy/index.js.map +1 -1
- package/dist/proxy/server/express/index.d.ts +8 -9
- package/dist/proxy/server/express/index.js +4 -3
- package/dist/proxy/server/fastify/index.d.ts +8 -9
- package/dist/proxy/server/fastify/index.js +4 -3
- package/dist/proxy/server/h3/index.d.ts +8 -9
- package/dist/proxy/server/h3/index.js +4 -3
- package/dist/proxy/server/index.d.ts +5 -5
- package/dist/proxy/server/index.js +14 -13
- package/dist/proxy/server/webapi/index.d.ts +8 -9
- package/dist/proxy/server/webapi/index.js +4 -3
- package/dist/responses/index.d.ts +3 -3
- package/dist/responses/index.js +7 -5
- package/dist/responses/index.js.map +1 -1
- package/dist/retry-DVfdPLIB.d.ts +322 -0
- package/dist/{stream-DVVUIKpz.d.ts → stream-bBd_4Ipu.d.ts} +27 -4
- package/dist/{tool-D22EhP5F.d.ts → tool-BmAfKNBq.d.ts} +1 -1
- package/dist/{types-CyXF0J7C.d.ts → types-nTwlpyJE.d.ts} +13 -1
- package/dist/utils/index.d.ts +66 -2
- package/dist/utils/index.js +13 -0
- package/dist/xai/index.d.ts +3 -3
- package/dist/xai/index.js +7 -5
- package/dist/xai/index.js.map +1 -1
- package/package.json +6 -1
- package/dist/chunk-ARVM24K2.js +0 -128
- package/dist/chunk-ARVM24K2.js.map +0 -1
- package/dist/chunk-MJI74VEJ.js.map +0 -1
- package/dist/chunk-SBGZJVTJ.js.map +0 -1
- package/dist/chunk-U6M3MXNI.js.map +0 -1
- package/dist/chunk-WU4U6IHF.js.map +0 -1
- package/dist/chunk-Y5H7C5J4.js +0 -263
- package/dist/chunk-Y5H7C5J4.js.map +0 -1
- package/dist/retry-C1eJbEMV.d.ts +0 -531
- /package/dist/{chunk-ZDYEDI2A.js.map → chunk-CWGTARDE.js.map} +0 -0
- /package/dist/{chunk-IIMTP3XC.js.map → chunk-KBI45OXI.js.map} +0 -0
- /package/dist/{chunk-SAMIK4WZ.js.map → chunk-KVUOTFYZ.js.map} +0 -0
- /package/dist/{chunk-RDC5GYST.js.map → chunk-N4LAFGLX.js.map} +0 -0
- /package/dist/{chunk-WNB5PSY6.js.map → chunk-ZMESKGUY.js.map} +0 -0
- /package/dist/{chunk-7ULSRWDH.js.map → chunk-ZSZVWLGE.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/providers/moonshot/transform.ts","../../src/providers/moonshot/llm.ts","../../src/providers/moonshot/types.ts","../../src/providers/moonshot/index.ts"],"sourcesContent":["/**\n * @fileoverview Moonshot API Message Transformers\n *\n * This module provides transformation functions for converting between the\n * Universal Provider Protocol (UPP) message format and Moonshot's Chat Completions\n * API format (OpenAI-compatible). It handles both request transformation (UPP -> Moonshot)\n * and response transformation (Moonshot -> UPP), including streaming event transformation.\n *\n * @module providers/moonshot/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, VideoBlock, ReasoningBlock } 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 MoonshotLLMParams,\n MoonshotRequest,\n MoonshotMessage,\n MoonshotUserContent,\n MoonshotTool,\n MoonshotResponse,\n MoonshotStreamChunk,\n MoonshotToolCall,\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 'moonshot',\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 'moonshot',\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 'moonshot',\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 Moonshot user content format.\n */\nfunction transformContentBlock(block: ContentBlock): MoonshotUserContent {\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 'moonshot',\n ModalityType.LLM\n );\n }\n\n return {\n type: 'image_url',\n image_url: { url },\n };\n }\n\n case 'video': {\n const videoBlock = block as VideoBlock;\n const base64 = Buffer.from(videoBlock.data).toString('base64');\n const url = `data:${videoBlock.mimeType};base64,${base64}`;\n\n return {\n type: 'video_url',\n video_url: { url },\n };\n }\n\n case 'document':\n throw new UPPError(\n 'Moonshot does not support inline document blocks. Use the /v1/files API to upload documents first.',\n ErrorCode.InvalidRequest,\n 'moonshot',\n ModalityType.LLM\n );\n\n case 'audio':\n throw new UPPError(\n 'Moonshot does not support audio input',\n ErrorCode.InvalidRequest,\n 'moonshot',\n ModalityType.LLM\n );\n\n default:\n throw new UPPError(\n `Unsupported content type: ${block.type}`,\n ErrorCode.InvalidRequest,\n 'moonshot',\n ModalityType.LLM\n );\n }\n}\n\n/**\n * Transforms a single UPP message to Moonshot format.\n */\nfunction transformMessage(message: Message): MoonshotMessage | 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 // Extract reasoning content from metadata or content blocks\n const moonshotMeta = message.metadata?.moonshot as { reasoning_content?: string } | undefined;\n let reasoningContent = moonshotMeta?.reasoning_content;\n\n // Also check for ReasoningBlock in content if not in metadata\n if (!reasoningContent) {\n const reasoningBlocks = validContent.filter(\n (c): c is ReasoningBlock => c.type === 'reasoning'\n );\n if (reasoningBlocks.length > 0) {\n reasoningContent = reasoningBlocks.map((b) => b.text).join('\\n');\n }\n }\n\n const assistantMessage: MoonshotMessage = {\n role: 'assistant',\n content: textContent || null,\n };\n\n // Include reasoning_content if present (required for tool call messages)\n if (reasoningContent) {\n (assistantMessage as { reasoning_content?: string }).reasoning_content = reasoningContent;\n }\n\n if (message.toolCalls && message.toolCalls.length > 0) {\n (assistantMessage as { tool_calls?: MoonshotToolCall[] }).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 Moonshot tool messages.\n */\nexport function transformToolResults(message: Message): MoonshotMessage[] {\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 Moonshot message format.\n *\n * @param messages - Array of UPP messages to transform\n * @param system - Optional system prompt\n * @returns Array of Moonshot-formatted messages\n */\nfunction transformMessages(\n messages: Message[],\n system?: string | unknown[]\n): MoonshotMessage[] {\n const result: MoonshotMessage[] = [];\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 Moonshot-specific options from tool metadata.\n */\nfunction extractToolOptions(tool: Tool): { strict?: boolean } {\n const moonshotMeta = tool.metadata?.moonshot as { strict?: boolean } | undefined;\n return { strict: moonshotMeta?.strict };\n}\n\n/**\n * Transforms a UPP tool definition to Moonshot function tool format.\n */\nfunction transformTool(tool: Tool): MoonshotTool {\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 Moonshot Chat Completions API format.\n *\n * @param request - The UPP LLM request containing messages, tools, and configuration\n * @param modelId - The Moonshot model identifier (e.g., 'kimi-k2.5')\n * @returns A Moonshot Chat Completions API request body\n */\nexport function transformRequest(\n request: LLMRequest<MoonshotLLMParams>,\n modelId: string\n): MoonshotRequest {\n const params = request.params ?? ({} as MoonshotLLMParams);\n\n // Extract builtin tools from params before spreading\n const { tools: paramsTools, ...restParams } = params;\n\n const moonshotRequest: MoonshotRequest = {\n ...restParams,\n model: modelId,\n messages: transformMessages(request.messages, request.system),\n };\n\n // Combine builtin tools from params with transformed UPP tools\n const allTools: MoonshotTool[] = [];\n\n // Add builtin tools from params (already in Moonshot format)\n if (paramsTools && paramsTools.length > 0) {\n allTools.push(...paramsTools);\n }\n\n // Transform and add UPP tools from request.tools\n if (request.tools && request.tools.length > 0) {\n allTools.push(...request.tools.map(transformTool));\n }\n\n if (allTools.length > 0) {\n moonshotRequest.tools = allTools;\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 moonshotRequest.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 moonshotRequest;\n}\n\n/**\n * Transforms a Moonshot response to UPP LLMResponse format.\n */\nexport function transformResponse(data: MoonshotResponse): LLMResponse {\n const choice = data.choices[0];\n if (!choice) {\n throw new UPPError(\n 'No choices in Moonshot response',\n ErrorCode.InvalidResponse,\n 'moonshot',\n ModalityType.LLM\n );\n }\n\n const contentBlocks: (TextBlock | ReasoningBlock)[] = [];\n let structuredData: unknown;\n\n if (choice.message.reasoning_content) {\n contentBlocks.push({ type: 'reasoning', text: choice.message.reasoning_content });\n }\n\n if (choice.message.content) {\n contentBlocks.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 contentBlocks,\n toolCalls.length > 0 ? toolCalls : undefined,\n {\n id: data.id || generateId(),\n metadata: {\n moonshot: {\n model: data.model,\n finish_reason: choice.finish_reason,\n system_fingerprint: data.system_fingerprint,\n reasoning_content: choice.message.reasoning_content ?? undefined,\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 MoonshotStreamState {\n /** Response ID from the first chunk */\n id: string;\n /** Model identifier */\n model: string;\n /** Accumulated text content */\n text: string;\n /** Accumulated reasoning content (thinking traces) */\n reasoningText: 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(): MoonshotStreamState {\n return {\n id: '',\n model: '',\n text: '',\n reasoningText: '',\n toolCalls: new Map(),\n finishReason: null,\n inputTokens: 0,\n outputTokens: 0,\n cacheReadTokens: 0,\n };\n}\n\n/**\n * Transforms a Moonshot streaming chunk into UPP stream events.\n */\nexport function transformStreamEvent(\n chunk: MoonshotStreamChunk,\n state: MoonshotStreamState\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.reasoning_content) {\n state.reasoningText += choice.delta.reasoning_content;\n events.push({\n type: StreamEventType.ReasoningDelta,\n index: 0,\n delta: { text: choice.delta.reasoning_content },\n });\n }\n\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 if (chunk.usage) {\n state.inputTokens = chunk.usage.prompt_tokens;\n state.outputTokens = chunk.usage.completion_tokens;\n state.cacheReadTokens = chunk.usage.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: MoonshotStreamState): LLMResponse {\n const contentBlocks: (TextBlock | ReasoningBlock)[] = [];\n let structuredData: unknown;\n\n if (state.reasoningText) {\n contentBlocks.push({ type: 'reasoning', text: state.reasoningText });\n }\n\n if (state.text) {\n contentBlocks.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 contentBlocks,\n toolCalls.length > 0 ? toolCalls : undefined,\n {\n id: messageId,\n metadata: {\n moonshot: {\n model: state.model,\n finish_reason: state.finishReason,\n reasoning_content: state.reasoningText || undefined,\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 Moonshot Chat Completions API Handler\n *\n * This module implements the LLM handler for Moonshot's Chat Completions API\n * (OpenAI-compatible at `https://api.moonshot.ai/v1/chat/completions`).\n *\n * @see {@link https://platform.moonshot.ai/docs/api/chat Moonshot API Reference}\n * @module providers/moonshot/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, ProviderConfig } 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 { MoonshotLLMParams, MoonshotResponse, MoonshotStreamChunk } from './types.ts';\nimport {\n transformRequest,\n transformResponse,\n transformStreamEvent,\n createStreamState,\n buildResponseFromState,\n} from './transform.ts';\n\n/** Base URL for Moonshot's Chat Completions API endpoint (global) */\nconst MOONSHOT_API_URL = 'https://api.moonshot.ai/v1/chat/completions';\n\n/**\n * Capability declaration for the Moonshot 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: Native vision via MoonViT encoder\n * - Video Input: Experimental video support\n */\nconst MOONSHOT_CAPABILITIES: LLMCapabilities = {\n streaming: true,\n tools: true,\n structuredOutput: true,\n imageInput: true,\n documentInput: false,\n videoInput: true,\n audioInput: false,\n};\n\n/**\n * Resolves the Moonshot API key from config or environment variables.\n *\n * Checks in order:\n * 1. config.apiKey (if provided)\n * 2. MOONSHOT_API_KEY environment variable\n * 3. KIMI_API_KEY environment variable (fallback)\n *\n * @param config - Provider configuration\n * @returns The API key\n * @throws UPPError if no API key is found\n */\nasync function resolveMoonshotApiKey(config: ProviderConfig): Promise<string> {\n // First try the standard resolution with MOONSHOT_API_KEY\n try {\n return await resolveApiKey(config, 'MOONSHOT_API_KEY', 'moonshot', 'llm');\n } catch {\n // Fall back to KIMI_API_KEY\n const kimiKey = process.env.KIMI_API_KEY;\n if (kimiKey) {\n return kimiKey;\n }\n\n throw new UPPError(\n 'API key not found. Set MOONSHOT_API_KEY or KIMI_API_KEY environment variable, or pass apiKey in config.',\n ErrorCode.AuthenticationFailed,\n 'moonshot',\n ModalityType.LLM\n );\n }\n}\n\n/**\n * Creates an LLM handler for Moonshot's Chat Completions API.\n *\n * This factory function creates a handler that communicates with the\n * `/v1/chat/completions` endpoint. The handler supports both synchronous\n * completion requests and streaming responses.\n *\n * @returns An LLM handler configured for the Moonshot API\n *\n * @example\n * ```typescript\n * const handler = createLLMHandler();\n * const model = handler.bind('kimi-k2.5');\n *\n * // Synchronous completion\n * const response = await model.complete({\n * messages: [{ role: 'user', content: 'Hello!' }],\n * config: { apiKey: 'sk-...' }\n * });\n *\n * // Streaming completion\n * const stream = model.stream({\n * messages: [{ role: 'user', content: 'Tell me a story' }],\n * config: { apiKey: 'sk-...' }\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<MoonshotLLMParams> {\n let providerRef: LLMProvider<MoonshotLLMParams> | null = null;\n\n return {\n _setProvider(provider: LLMProvider<MoonshotLLMParams>) {\n providerRef = provider;\n },\n\n bind(modelId: string): BoundLLMModel<MoonshotLLMParams> {\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 'moonshot',\n ModalityType.LLM\n );\n }\n\n const model: BoundLLMModel<MoonshotLLMParams> = {\n modelId,\n capabilities: MOONSHOT_CAPABILITIES,\n\n get provider(): LLMProvider<MoonshotLLMParams> {\n return providerRef!;\n },\n\n async complete(request: LLMRequest<MoonshotLLMParams>): Promise<LLMResponse> {\n const apiKey = await resolveMoonshotApiKey(request.config);\n\n const baseUrl = request.config.baseUrl ?? MOONSHOT_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 'moonshot',\n 'llm'\n );\n\n const data = await parseJsonResponse<MoonshotResponse>(response, 'moonshot', 'llm');\n return transformResponse(data);\n },\n\n stream(request: LLMRequest<MoonshotLLMParams>): 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 resolveMoonshotApiKey(request.config);\n\n const baseUrl = request.config.baseUrl ?? MOONSHOT_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 'moonshot',\n 'llm'\n );\n\n if (!response.ok) {\n const error = await normalizeHttpError(response, 'moonshot', '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 'moonshot',\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 Moonshot error event\n if (typeof data === 'object' && data !== null) {\n const chunk = data as MoonshotStreamChunk;\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 'moonshot',\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 Moonshot AI Provider Type Definitions\n *\n * This module contains all TypeScript type definitions for the Moonshot provider,\n * including types for the Chat Completions API (OpenAI-compatible).\n *\n * @module providers/moonshot/types\n */\n\n/**\n * Thinking mode configuration for Moonshot models.\n *\n * By default, kimi-k2.5 has thinking mode enabled and returns reasoning traces.\n * Use `{ type: 'disabled' }` to switch to instant mode for faster responses.\n */\nexport interface MoonshotThinkingConfig {\n /** Thinking mode type: 'enabled' (default) or 'disabled' for instant mode */\n type: 'enabled' | 'disabled';\n}\n\n/**\n * Parameters for the Moonshot Chat Completions API.\n *\n * These parameters are passed directly to the `/v1/chat/completions` endpoint.\n * Moonshot's API is OpenAI-compatible with additional thinking mode support.\n *\n * @example\n * ```typescript\n * const params: MoonshotLLMParams = {\n * temperature: 1.0,\n * max_tokens: 1000,\n * thinking: { type: 'enabled' } // Default for kimi-k2.5\n * };\n * ```\n */\nexport interface MoonshotLLMParams {\n /** Maximum number of tokens to generate */\n max_tokens?: number;\n\n /** Maximum completion tokens (alias for max_tokens) */\n max_completion_tokens?: number;\n\n /** Temperature for randomness (0.0 to 2.0). Default: 1.0 (thinking) or 0.6 (instant) */\n temperature?: number;\n\n /** Top-p (nucleus) sampling (0.0 - 1.0), default 0.95 */\n top_p?: number;\n\n /** Custom stop sequences */\n stop?: string | string[];\n\n /** Frequency penalty (-2.0 - 2.0) */\n frequency_penalty?: number;\n\n /** Presence penalty (-2.0 - 2.0) */\n presence_penalty?: number;\n\n /** Seed for deterministic sampling */\n seed?: number;\n\n /** User identifier for rate limit tracking */\n user?: string;\n\n /** Response format for structured output */\n response_format?: MoonshotResponseFormat;\n\n /** Thinking mode configuration (kimi-k2.5 specific) */\n thinking?: MoonshotThinkingConfig;\n\n /**\n * Builtin tools to enable for this request.\n * Use the `tools` helper object to create these.\n *\n * @example\n * ```typescript\n * import { moonshot, tools } from '@providerprotocol/ai/moonshot';\n *\n * const model = llm({\n * model: moonshot('kimi-k2.5'),\n * params: {\n * tools: [tools.webSearch(), tools.codeRunner()],\n * },\n * });\n * ```\n */\n tools?: MoonshotTool[];\n}\n\n/**\n * Response format options for structured output.\n */\nexport type MoonshotResponseFormat =\n | { type: 'text' }\n | { type: 'json_object' }\n | {\n type: 'json_schema';\n json_schema: {\n name: string;\n description?: string;\n schema: Record<string, unknown>;\n strict?: boolean;\n };\n };\n\n/**\n * Request body for the Moonshot Chat Completions API.\n */\nexport interface MoonshotRequest {\n model: string;\n messages: MoonshotMessage[];\n temperature?: number;\n top_p?: number;\n stream?: boolean;\n stream_options?: { include_usage?: boolean };\n stop?: string | string[];\n max_tokens?: number;\n max_completion_tokens?: number;\n presence_penalty?: number;\n frequency_penalty?: number;\n user?: string;\n seed?: number;\n tools?: MoonshotTool[];\n tool_choice?: MoonshotToolChoice;\n response_format?: MoonshotResponseFormat;\n thinking?: MoonshotThinkingConfig;\n}\n\n/**\n * Union type for all message types in the Moonshot API.\n */\nexport type MoonshotMessage =\n | MoonshotSystemMessage\n | MoonshotUserMessage\n | MoonshotAssistantMessage\n | MoonshotToolMessage;\n\n/** System message for setting context and instructions */\nexport interface MoonshotSystemMessage {\n role: 'system';\n content: string;\n}\n\n/** User message with text or multimodal content */\nexport interface MoonshotUserMessage {\n role: 'user';\n content: string | MoonshotUserContent[];\n}\n\n/** Assistant message containing the model's response */\nexport interface MoonshotAssistantMessage {\n role: 'assistant';\n content?: string | null;\n /** Reasoning traces from thinking mode */\n reasoning_content?: string | null;\n tool_calls?: MoonshotToolCall[];\n}\n\n/** Tool result message providing output from a function call */\nexport interface MoonshotToolMessage {\n role: 'tool';\n content: string;\n tool_call_id: string;\n}\n\n/**\n * Union type for user content parts (text, image, or video).\n */\nexport type MoonshotUserContent = MoonshotTextContent | MoonshotImageContent | MoonshotVideoContent;\n\n/** Text content part */\nexport interface MoonshotTextContent {\n type: 'text';\n text: string;\n}\n\n/** Image content part with URL reference (for vision models) */\nexport interface MoonshotImageContent {\n type: 'image_url';\n image_url: {\n url: string;\n };\n}\n\n/** Video content part with URL reference (experimental) */\nexport interface MoonshotVideoContent {\n type: 'video_url';\n video_url: {\n url: string;\n };\n}\n\n/**\n * Tool call structure in assistant messages.\n */\nexport interface MoonshotToolCall {\n id: string;\n type: 'function';\n function: {\n name: string;\n arguments: string;\n };\n}\n\n/**\n * Tool definition for the Moonshot API.\n * Used for both custom function tools and server-side builtin tools.\n */\nexport interface MoonshotTool {\n type: 'function';\n function: {\n name: string;\n description: string;\n parameters: {\n type?: 'object';\n description?: string;\n properties: Record<string, unknown>;\n required?: string[];\n additionalProperties?: boolean;\n };\n strict?: boolean;\n };\n}\n\n/**\n * Tool choice options for controlling function calling behavior.\n * Moonshot models support full tool_choice including 'required'.\n */\nexport type MoonshotToolChoice =\n | 'none'\n | 'auto'\n | 'required'\n | { type: 'function'; function: { name: string } };\n\n// ============================================\n// Server-Side Tool Factory Functions\n// ============================================\n// These tools are executed by Moonshot's servers, not by the client.\n// The model decides when to call them and the API handles execution.\n//\n// TODO: Implement `excel` plugin - uses `_plugin` format with multiple\n// sub-functions (read_file, list_sheets, describe, inspect, pipe, groupby,\n// orderby, filter, head, value_counts, correlation, sample, select, count,\n// sum, distinct, add_column). Requires file IDs from Moonshot's /v1/files API.\n\n/**\n * Options for web search tool.\n */\nexport interface MoonshotWebSearchOptions {\n /** Search domains to focus on */\n classes?: Array<'all' | 'academic' | 'social' | 'library' | 'finance' | 'code' | 'ecommerce' | 'medical'>;\n}\n\n/**\n * Creates a web search tool (server-side execution).\n * Enables real-time internet search capabilities.\n *\n * Note: Web search is charged separately from regular API usage.\n *\n * @example\n * ```typescript\n * import { moonshot, tools } from '@providerprotocol/ai/moonshot';\n *\n * const model = llm({\n * model: moonshot('kimi-k2.5'),\n * params: {\n * tools: [tools.webSearch()],\n * },\n * });\n * ```\n */\nexport function webSearch(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'web_search',\n description: 'Search the web for information',\n parameters: {\n type: 'object',\n properties: {\n query: {\n description: 'What to search for',\n type: 'string',\n },\n classes: {\n description: 'Search domains to focus on. Defaults to \"all\" if not specified.',\n type: 'array',\n items: {\n type: 'string',\n enum: ['all', 'academic', 'social', 'library', 'finance', 'code', 'ecommerce', 'medical'],\n },\n },\n },\n required: ['query'],\n },\n },\n };\n}\n\n/**\n * Creates a Python code runner tool (server-side execution).\n * Allows execution of Python code for calculations and data processing.\n * Supports print output, matplotlib plots, pandas, and file reading via ctx.read_object().\n */\nexport function codeRunner(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'code_runner',\n description: 'Safely executes Python code and returns the result, with print output, last-line evaluation, error handling, and timeout protection.',\n parameters: {\n type: 'object',\n properties: {\n code: {\n description: 'The Python code to execute. Supports print(), matplotlib, pandas, and ctx.read_object() for file reading.',\n type: 'string',\n },\n },\n required: ['code'],\n },\n },\n };\n}\n\n/**\n * Creates a QuickJS JavaScript execution tool (server-side execution).\n * Enables secure JavaScript code execution via the QuickJS engine.\n */\nexport function quickjs(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'quickjs',\n description: 'Safely executes JavaScript code using QuickJS engine',\n parameters: {\n type: 'object',\n properties: {\n code: {\n description: 'The JavaScript code to execute. Supports console.log(), ES6+ features, and ctx.log() for logging.',\n type: 'string',\n },\n },\n required: ['code'],\n },\n },\n };\n}\n\n/**\n * Creates a URL fetch tool (server-side execution).\n * Extracts content from URLs and formats it as Markdown.\n */\nexport function fetch(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'fetch',\n description: 'Fetches a URL from the internet and optionally extracts its contents as markdown.',\n parameters: {\n type: 'object',\n properties: {\n url: {\n description: 'URL to fetch',\n type: 'string',\n format: 'uri',\n },\n max_length: {\n description: 'Maximum number of characters to return (default: 5000)',\n type: 'integer',\n default: 5000,\n },\n start_index: {\n description: 'Start at this character index, useful for pagination',\n type: 'integer',\n default: 0,\n },\n raw: {\n description: 'Get raw HTML without simplification',\n type: 'boolean',\n default: false,\n },\n },\n required: ['url'],\n },\n },\n };\n}\n\n/**\n * Creates a unit conversion tool (server-side execution).\n * Supports length, mass, volume, temperature, area, time, energy,\n * pressure, speed, and currency conversions.\n */\nexport function convert(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'convert',\n description: 'Convert between supported units of length, mass, volume, temperature, area, time, energy, pressure, speed, and currency.',\n parameters: {\n type: 'object',\n properties: {\n value: {\n description: 'Value to convert',\n type: 'number',\n },\n from_unit: {\n description: 'Source unit (e.g., m, km, ft, kg, lb, °C, °F, USD, EUR)',\n type: 'string',\n },\n to_unit: {\n description: 'Target unit',\n type: 'string',\n },\n },\n required: ['value', 'from_unit', 'to_unit'],\n },\n },\n };\n}\n\n/**\n * Creates a date/time processing tool (server-side execution).\n * Handles date and time calculations, timezone conversion, and formatting.\n */\nexport function date(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'date',\n description: 'Date and time processing tool, supports displaying current time, timezone conversion, date calculation, and more.',\n parameters: {\n type: 'object',\n properties: {\n operation: {\n description: 'Operation type',\n type: 'string',\n enum: ['time', 'convert', 'between', 'add', 'subtract'],\n },\n date: {\n description: 'Date string (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS)',\n type: 'string',\n },\n date1: {\n description: 'First date (for difference calculation)',\n type: 'string',\n },\n date2: {\n description: 'Second date (for difference calculation)',\n type: 'string',\n },\n days: {\n description: 'Number of days (for add/subtract)',\n type: 'integer',\n },\n zone: {\n description: 'Timezone name (e.g., Asia/Shanghai, America/New_York, UTC)',\n type: 'string',\n },\n from_zone: {\n description: 'Source timezone (for conversion)',\n type: 'string',\n },\n to_zone: {\n description: 'Target timezone (for conversion)',\n type: 'string',\n },\n format: {\n description: 'Output format (Python strftime)',\n type: 'string',\n default: '%Y-%m-%d %H:%M:%S',\n },\n },\n required: ['operation'],\n },\n },\n };\n}\n\n/**\n * Creates a Base64 encoding tool (server-side execution).\n */\nexport function base64Encode(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'base64_encode',\n description: 'Encode text to base64 format',\n parameters: {\n type: 'object',\n properties: {\n data: {\n description: 'Text data to encode to base64',\n type: 'string',\n },\n encoding: {\n description: 'Character encoding to use (default: utf-8)',\n type: 'string',\n default: 'utf-8',\n },\n },\n required: ['data'],\n },\n },\n };\n}\n\n/**\n * Creates a Base64 decoding tool (server-side execution).\n */\nexport function base64Decode(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'base64_decode',\n description: 'Decode base64 text to original format',\n parameters: {\n type: 'object',\n properties: {\n data: {\n description: 'Base64 encoded data to decode',\n type: 'string',\n },\n encoding: {\n description: 'Character encoding to use (default: utf-8)',\n type: 'string',\n default: 'utf-8',\n },\n },\n required: ['data'],\n },\n },\n };\n}\n\n/**\n * Creates a memory storage tool (server-side execution).\n * Supports persistent storage of conversation history and user preferences.\n */\nexport function memory(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'memory',\n description: 'Memory storage and retrieval system, supporting persistence of conversation history, user preferences, and other data.',\n parameters: {\n type: 'object',\n properties: {\n action: {\n description: 'Operation type',\n type: 'string',\n enum: ['store', 'retrieve', 'delete', 'list'],\n },\n key: {\n description: 'Storage key name',\n type: 'string',\n },\n data: {\n description: 'Data content to store',\n type: 'object',\n },\n prefix: {\n description: 'Key prefix for list operation',\n type: 'string',\n },\n ttl: {\n description: 'Data expiration time in seconds (default: 86400 = 24 hours)',\n type: 'integer',\n default: 86400,\n },\n },\n required: ['action'],\n },\n },\n };\n}\n\n/**\n * Creates an intelligent reasoning tool (server-side execution).\n * Allows the model to organize thoughts and plan before responding.\n */\nexport function rethink(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'rethink',\n description: 'Tool for organizing thoughts, making plans, and thinking step by step. Does not return information, just for reflection.',\n parameters: {\n type: 'object',\n properties: {\n thought: {\n description: 'The thought to consider for better solving the current task',\n type: 'string',\n },\n },\n required: ['thought'],\n },\n },\n };\n}\n\n/**\n * Creates a random choice tool (server-side execution).\n * Enables random selection from options with optional weights.\n */\nexport function randomChoice(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'random_choice',\n description: 'Random selection tool that supports choosing items from candidates with optional weights.',\n parameters: {\n type: 'object',\n properties: {\n candidates: {\n description: 'List of candidates to choose from',\n type: 'array',\n items: { type: 'string' },\n },\n count: {\n description: 'Number of items to select (default: 1)',\n type: 'integer',\n default: 1,\n },\n replace: {\n description: 'Allow duplicates (default: false)',\n type: 'boolean',\n default: false,\n },\n weights: {\n description: 'Optional weights for weighted selection',\n type: 'array',\n items: { type: 'number' },\n },\n seed: {\n description: 'Random seed for reproducibility',\n type: 'integer',\n },\n format: {\n description: 'Output format',\n type: 'string',\n enum: ['simple', 'detailed', 'json'],\n default: 'simple',\n },\n },\n required: ['candidates'],\n },\n },\n };\n}\n\n/**\n * Creates a cat meowing/blessing tool (server-side execution).\n * Returns random cat meowing sounds and blessings based on mood.\n */\nexport function mew(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'mew_generator',\n description: \"Randomly generates a cat's meow, accompanied by a blessing.\",\n parameters: {\n type: 'object',\n properties: {\n mood: {\n description: \"The cat's mood\",\n type: 'string',\n enum: ['happy', 'sleepy', 'hungry', 'playful', 'grumpy'],\n },\n },\n required: [],\n },\n },\n };\n}\n\n\n/**\n * Moonshot builtin tools factory object.\n * Provides convenient access to all builtin tool creators.\n *\n * Note: The `excel` plugin tool uses a different format and is not included here.\n * It requires file IDs from the Moonshot file upload API.\n *\n * @example\n * ```typescript\n * import { moonshot, tools } from '@providerprotocol/ai/moonshot';\n *\n * const model = llm({\n * model: moonshot('kimi-k2.5'),\n * params: {\n * tools: [\n * tools.webSearch(),\n * tools.codeRunner(),\n * tools.fetch(),\n * ],\n * },\n * });\n * ```\n */\nexport const tools = {\n /** Web search for real-time internet information */\n webSearch,\n /** Python code execution with matplotlib, pandas support */\n codeRunner,\n /** JavaScript execution via QuickJS engine */\n quickjs,\n /** URL content fetching with markdown extraction */\n fetch,\n /** Unit conversion (length, mass, temperature, currency, etc.) */\n convert,\n /** Date/time processing and timezone conversion */\n date,\n /** Base64 encoding */\n base64Encode,\n /** Base64 decoding */\n base64Decode,\n /** Alias for base64Encode */\n base64: base64Encode,\n /** Memory storage and retrieval system */\n memory,\n /** Intelligent reasoning/reflection tool */\n rethink,\n /** Random selection with optional weights */\n randomChoice,\n /** Cat meowing and blessings generator */\n mew,\n};\n\n/**\n * Response structure from the Moonshot Chat Completions API.\n */\nexport interface MoonshotResponse {\n id: string;\n object: 'chat.completion';\n created: number;\n model: string;\n choices: MoonshotChoice[];\n usage: MoonshotUsage;\n system_fingerprint?: string;\n}\n\n/** A single choice from a completion response */\nexport interface MoonshotChoice {\n index: number;\n message: MoonshotAssistantMessage;\n finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;\n}\n\n/** Token usage statistics from the API response */\nexport interface MoonshotUsage {\n prompt_tokens: number;\n completion_tokens: number;\n total_tokens: number;\n prompt_tokens_details?: {\n cached_tokens?: number;\n };\n}\n\n/**\n * Streaming chunk structure from the Moonshot API.\n */\nexport interface MoonshotStreamChunk {\n id: string;\n object: 'chat.completion.chunk';\n created: number;\n model: string;\n choices: MoonshotStreamChoice[];\n usage?: MoonshotUsage | null;\n system_fingerprint?: string;\n}\n\n/** A streaming choice containing incremental content */\nexport interface MoonshotStreamChoice {\n index: number;\n delta: MoonshotStreamDelta;\n finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;\n}\n\n/** Incremental content delta in a streaming chunk */\nexport interface MoonshotStreamDelta {\n role?: 'assistant';\n content?: string | null;\n reasoning_content?: string | null;\n tool_calls?: MoonshotStreamToolCall[];\n}\n\n/** Incremental tool call data in a streaming chunk */\nexport interface MoonshotStreamToolCall {\n index: number;\n id?: string;\n type?: 'function';\n function?: {\n name?: string;\n arguments?: string;\n };\n}\n\n/**\n * Moonshot-specific HTTP headers for API requests.\n *\n * @example\n * ```typescript\n * const headers: MoonshotHeaders = {\n * 'X-Request-Id': 'my-request-id',\n * };\n * ```\n */\nexport interface MoonshotHeaders {\n /** Client-generated request ID for tracing */\n 'X-Request-Id'?: string;\n [key: string]: string | undefined;\n}\n","/**\n * @fileoverview Moonshot Provider Factory\n *\n * This module provides the main Moonshot provider implementation for the\n * OpenAI-compatible Chat Completions API.\n *\n * @module providers/moonshot\n */\n\nimport { createProvider } from '../../core/provider.ts';\nimport { createLLMHandler } from './llm.ts';\n\n/**\n * Configuration options for the Moonshot provider.\n *\n * Currently Moonshot only supports one API endpoint (Chat Completions),\n * so no additional options are needed.\n */\nexport interface MoonshotProviderOptions {\n // Reserved for future use\n}\n\n/**\n * The Moonshot provider instance.\n *\n * Use this provider to create model references for Moonshot models like\n * Kimi K2.5 and other models available on the Moonshot AI platform.\n *\n * @example Basic usage\n * ```typescript\n * import { moonshot } from './providers/moonshot';\n * import { llm } from './core/llm';\n *\n * const model = llm({\n * model: moonshot('kimi-k2.5'),\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 thinking mode (default for K2.5)\n * ```typescript\n * const model = llm({\n * model: moonshot('kimi-k2.5'),\n * params: {\n * max_tokens: 2000,\n * temperature: 1.0, // Recommended for thinking mode\n * thinking: { type: 'enabled' } // Default\n * }\n * });\n *\n * // Response includes reasoning_content in metadata\n * const turn = await model.generate('Solve this step by step: 2x + 5 = 13');\n * ```\n *\n * @example With instant mode (disabled thinking)\n * ```typescript\n * const model = llm({\n * model: moonshot('kimi-k2.5'),\n * params: {\n * max_tokens: 1000,\n * temperature: 0.6, // Recommended for instant mode\n * thinking: { type: 'disabled' }\n * }\n * });\n * ```\n *\n * @example With vision (image input)\n * ```typescript\n * import { Image } from './core/media/Image';\n *\n * const image = await Image.fromPath('./photo.png');\n * const turn = await model.generate([\n * image.toBlock(),\n * { type: 'text', text: 'Describe this image' }\n * ]);\n * ```\n *\n * @example Available models\n * Production models:\n * - `kimi-k2.5` - Latest K2.5 with 256K context, vision, thinking mode\n *\n * Environment variables:\n * - `MOONSHOT_API_KEY` - Primary API key\n * - `KIMI_API_KEY` - Fallback API key\n */\nexport const moonshot = createProvider<MoonshotProviderOptions>({\n name: 'moonshot',\n version: '1.0.0',\n handlers: {\n llm: createLLMHandler(),\n },\n});\n\nexport { tools } from './types.ts';\nexport type {\n MoonshotLLMParams,\n MoonshotHeaders,\n MoonshotResponseFormat,\n MoonshotMessage,\n MoonshotRequest,\n MoonshotResponse,\n MoonshotStreamChunk,\n MoonshotTool,\n MoonshotToolCall,\n MoonshotToolChoice,\n MoonshotUsage,\n MoonshotThinkingConfig,\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,M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AAAA,YACN,MAAM,CAAC,SAAS,UAAU,UAAU,WAAW,QAAQ;AAAA,UACzD;AAAA,QACF;AAAA,QACA,UAAU,CAAC;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;AA0BO,IAAM,QAAQ;AAAA;AAAA,EAEnB;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA,QAAQ;AAAA;AAAA,EAER;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AACF;;;AChnBO,IAAM,WAAW,eAAwC;AAAA,EAC9D,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU;AAAA,IACR,KAAK,iBAAiB;AAAA,EACxB;AACF,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/providers/moonshot/transform.ts","../../src/providers/moonshot/llm.ts","../../src/providers/moonshot/types.ts","../../src/providers/moonshot/index.ts"],"sourcesContent":["/**\n * @fileoverview Moonshot API Message Transformers\n *\n * This module provides transformation functions for converting between the\n * Universal Provider Protocol (UPP) message format and Moonshot's Chat Completions\n * API format (OpenAI-compatible). It handles both request transformation (UPP -> Moonshot)\n * and response transformation (Moonshot -> UPP), including streaming event transformation.\n *\n * @module providers/moonshot/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, VideoBlock, ReasoningBlock } 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 MoonshotLLMParams,\n MoonshotRequest,\n MoonshotMessage,\n MoonshotUserContent,\n MoonshotTool,\n MoonshotResponse,\n MoonshotStreamChunk,\n MoonshotToolCall,\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 'moonshot',\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 'moonshot',\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 'moonshot',\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 Moonshot user content format.\n */\nfunction transformContentBlock(block: ContentBlock): MoonshotUserContent {\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 'moonshot',\n ModalityType.LLM\n );\n }\n\n return {\n type: 'image_url',\n image_url: { url },\n };\n }\n\n case 'video': {\n const videoBlock = block as VideoBlock;\n const base64 = Buffer.from(videoBlock.data).toString('base64');\n const url = `data:${videoBlock.mimeType};base64,${base64}`;\n\n return {\n type: 'video_url',\n video_url: { url },\n };\n }\n\n case 'document':\n throw new UPPError(\n 'Moonshot does not support inline document blocks. Use the /v1/files API to upload documents first.',\n ErrorCode.InvalidRequest,\n 'moonshot',\n ModalityType.LLM\n );\n\n case 'audio':\n throw new UPPError(\n 'Moonshot does not support audio input',\n ErrorCode.InvalidRequest,\n 'moonshot',\n ModalityType.LLM\n );\n\n default:\n throw new UPPError(\n `Unsupported content type: ${block.type}`,\n ErrorCode.InvalidRequest,\n 'moonshot',\n ModalityType.LLM\n );\n }\n}\n\n/**\n * Transforms a single UPP message to Moonshot format.\n */\nfunction transformMessage(message: Message): MoonshotMessage | 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 // Extract reasoning content from metadata or content blocks\n const moonshotMeta = message.metadata?.moonshot as { reasoning_content?: string } | undefined;\n let reasoningContent = moonshotMeta?.reasoning_content;\n\n // Also check for ReasoningBlock in content if not in metadata\n if (!reasoningContent) {\n const reasoningBlocks = validContent.filter(\n (c): c is ReasoningBlock => c.type === 'reasoning'\n );\n if (reasoningBlocks.length > 0) {\n reasoningContent = reasoningBlocks.map((b) => b.text).join('\\n');\n }\n }\n\n const assistantMessage: MoonshotMessage = {\n role: 'assistant',\n content: textContent || null,\n };\n\n // Include reasoning_content if present (required for tool call messages)\n if (reasoningContent) {\n (assistantMessage as { reasoning_content?: string }).reasoning_content = reasoningContent;\n }\n\n if (message.toolCalls && message.toolCalls.length > 0) {\n (assistantMessage as { tool_calls?: MoonshotToolCall[] }).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 Moonshot tool messages.\n */\nexport function transformToolResults(message: Message): MoonshotMessage[] {\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 Moonshot message format.\n *\n * @param messages - Array of UPP messages to transform\n * @param system - Optional system prompt\n * @returns Array of Moonshot-formatted messages\n */\nfunction transformMessages(\n messages: Message[],\n system?: string | unknown[]\n): MoonshotMessage[] {\n const result: MoonshotMessage[] = [];\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 Moonshot-specific options from tool metadata.\n */\nfunction extractToolOptions(tool: Tool): { strict?: boolean } {\n const moonshotMeta = tool.metadata?.moonshot as { strict?: boolean } | undefined;\n return { strict: moonshotMeta?.strict };\n}\n\n/**\n * Transforms a UPP tool definition to Moonshot function tool format.\n */\nfunction transformTool(tool: Tool): MoonshotTool {\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 Moonshot Chat Completions API format.\n *\n * @param request - The UPP LLM request containing messages, tools, and configuration\n * @param modelId - The Moonshot model identifier (e.g., 'kimi-k2.5')\n * @returns A Moonshot Chat Completions API request body\n */\nexport function transformRequest(\n request: LLMRequest<MoonshotLLMParams>,\n modelId: string\n): MoonshotRequest {\n const params = request.params ?? ({} as MoonshotLLMParams);\n\n // Extract builtin tools from params before spreading\n const { tools: paramsTools, ...restParams } = params;\n\n const moonshotRequest: MoonshotRequest = {\n ...restParams,\n model: modelId,\n messages: transformMessages(request.messages, request.system),\n };\n\n // Combine builtin tools from params with transformed UPP tools\n const allTools: MoonshotTool[] = [];\n\n // Add builtin tools from params (already in Moonshot format)\n if (paramsTools && paramsTools.length > 0) {\n allTools.push(...paramsTools);\n }\n\n // Transform and add UPP tools from request.tools\n if (request.tools && request.tools.length > 0) {\n allTools.push(...request.tools.map(transformTool));\n }\n\n if (allTools.length > 0) {\n moonshotRequest.tools = allTools;\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 moonshotRequest.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 moonshotRequest;\n}\n\n/**\n * Transforms a Moonshot response to UPP LLMResponse format.\n */\nexport function transformResponse(data: MoonshotResponse): LLMResponse {\n const choice = data.choices[0];\n if (!choice) {\n throw new UPPError(\n 'No choices in Moonshot response',\n ErrorCode.InvalidResponse,\n 'moonshot',\n ModalityType.LLM\n );\n }\n\n const contentBlocks: (TextBlock | ReasoningBlock)[] = [];\n let structuredData: unknown;\n\n if (choice.message.reasoning_content) {\n contentBlocks.push({ type: 'reasoning', text: choice.message.reasoning_content });\n }\n\n if (choice.message.content) {\n contentBlocks.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 contentBlocks,\n toolCalls.length > 0 ? toolCalls : undefined,\n {\n id: data.id || generateId(),\n metadata: {\n moonshot: {\n model: data.model,\n finish_reason: choice.finish_reason,\n system_fingerprint: data.system_fingerprint,\n reasoning_content: choice.message.reasoning_content ?? undefined,\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 MoonshotStreamState {\n /** Response ID from the first chunk */\n id: string;\n /** Model identifier */\n model: string;\n /** Accumulated text content */\n text: string;\n /** Accumulated reasoning content (thinking traces) */\n reasoningText: 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(): MoonshotStreamState {\n return {\n id: '',\n model: '',\n text: '',\n reasoningText: '',\n toolCalls: new Map(),\n finishReason: null,\n inputTokens: 0,\n outputTokens: 0,\n cacheReadTokens: 0,\n };\n}\n\n/**\n * Transforms a Moonshot streaming chunk into UPP stream events.\n */\nexport function transformStreamEvent(\n chunk: MoonshotStreamChunk,\n state: MoonshotStreamState\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.reasoning_content) {\n state.reasoningText += choice.delta.reasoning_content;\n events.push({\n type: StreamEventType.ReasoningDelta,\n index: 0,\n delta: { text: choice.delta.reasoning_content },\n });\n }\n\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 if (chunk.usage) {\n state.inputTokens = chunk.usage.prompt_tokens;\n state.outputTokens = chunk.usage.completion_tokens;\n state.cacheReadTokens = chunk.usage.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: MoonshotStreamState): LLMResponse {\n const contentBlocks: (TextBlock | ReasoningBlock)[] = [];\n let structuredData: unknown;\n\n if (state.reasoningText) {\n contentBlocks.push({ type: 'reasoning', text: state.reasoningText });\n }\n\n if (state.text) {\n contentBlocks.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 contentBlocks,\n toolCalls.length > 0 ? toolCalls : undefined,\n {\n id: messageId,\n metadata: {\n moonshot: {\n model: state.model,\n finish_reason: state.finishReason,\n reasoning_content: state.reasoningText || undefined,\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 Moonshot Chat Completions API Handler\n *\n * This module implements the LLM handler for Moonshot's Chat Completions API\n * (OpenAI-compatible at `https://api.moonshot.ai/v1/chat/completions`).\n *\n * @see {@link https://platform.moonshot.ai/docs/api/chat Moonshot API Reference}\n * @module providers/moonshot/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, ProviderConfig } 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 { MoonshotLLMParams, MoonshotResponse, MoonshotStreamChunk } from './types.ts';\nimport {\n transformRequest,\n transformResponse,\n transformStreamEvent,\n createStreamState,\n buildResponseFromState,\n} from './transform.ts';\n\n/** Base URL for Moonshot's Chat Completions API endpoint (global) */\nconst MOONSHOT_API_URL = 'https://api.moonshot.ai/v1/chat/completions';\n\n/**\n * Capability declaration for the Moonshot 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: Native vision via MoonViT encoder\n * - Video Input: Experimental video support\n */\nconst MOONSHOT_CAPABILITIES: LLMCapabilities = {\n streaming: true,\n tools: true,\n structuredOutput: true,\n imageInput: true,\n documentInput: false,\n videoInput: true,\n audioInput: false,\n};\n\n/**\n * Resolves the Moonshot API key from config or environment variables.\n *\n * Checks in order:\n * 1. config.apiKey (if provided)\n * 2. MOONSHOT_API_KEY environment variable\n * 3. KIMI_API_KEY environment variable (fallback)\n *\n * @param config - Provider configuration\n * @returns The API key\n * @throws UPPError if no API key is found\n */\nasync function resolveMoonshotApiKey(config: ProviderConfig): Promise<string> {\n // First try the standard resolution with MOONSHOT_API_KEY\n try {\n return await resolveApiKey(config, 'MOONSHOT_API_KEY', 'moonshot', 'llm');\n } catch {\n // Fall back to KIMI_API_KEY\n const kimiKey = process.env.KIMI_API_KEY;\n if (kimiKey) {\n return kimiKey;\n }\n\n throw new UPPError(\n 'API key not found. Set MOONSHOT_API_KEY or KIMI_API_KEY environment variable, or pass apiKey in config.',\n ErrorCode.AuthenticationFailed,\n 'moonshot',\n ModalityType.LLM\n );\n }\n}\n\n/**\n * Creates an LLM handler for Moonshot's Chat Completions API.\n *\n * This factory function creates a handler that communicates with the\n * `/v1/chat/completions` endpoint. The handler supports both synchronous\n * completion requests and streaming responses.\n *\n * @returns An LLM handler configured for the Moonshot API\n *\n * @example\n * ```typescript\n * const handler = createLLMHandler();\n * const model = handler.bind('kimi-k2.5');\n *\n * // Synchronous completion\n * const response = await model.complete({\n * messages: [{ role: 'user', content: 'Hello!' }],\n * config: { apiKey: 'sk-...' }\n * });\n *\n * // Streaming completion\n * const stream = model.stream({\n * messages: [{ role: 'user', content: 'Tell me a story' }],\n * config: { apiKey: 'sk-...' }\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<MoonshotLLMParams> {\n let providerRef: LLMProvider<MoonshotLLMParams> | null = null;\n\n return {\n _setProvider(provider: LLMProvider<MoonshotLLMParams>) {\n providerRef = provider;\n },\n\n bind(modelId: string): BoundLLMModel<MoonshotLLMParams> {\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 'moonshot',\n ModalityType.LLM\n );\n }\n\n const model: BoundLLMModel<MoonshotLLMParams> = {\n modelId,\n capabilities: MOONSHOT_CAPABILITIES,\n\n get provider(): LLMProvider<MoonshotLLMParams> {\n return providerRef!;\n },\n\n async complete(request: LLMRequest<MoonshotLLMParams>): Promise<LLMResponse> {\n const apiKey = await resolveMoonshotApiKey(request.config);\n\n const baseUrl = request.config.baseUrl ?? MOONSHOT_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 'moonshot',\n 'llm'\n );\n\n const data = await parseJsonResponse<MoonshotResponse>(response, 'moonshot', 'llm');\n return transformResponse(data);\n },\n\n stream(request: LLMRequest<MoonshotLLMParams>): 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 resolveMoonshotApiKey(request.config);\n\n const baseUrl = request.config.baseUrl ?? MOONSHOT_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 'moonshot',\n 'llm'\n );\n\n if (!response.ok) {\n const error = await normalizeHttpError(response, 'moonshot', '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 'moonshot',\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 Moonshot error event\n if (typeof data === 'object' && data !== null) {\n const chunk = data as MoonshotStreamChunk;\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 'moonshot',\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 Moonshot AI Provider Type Definitions\n *\n * This module contains all TypeScript type definitions for the Moonshot provider,\n * including types for the Chat Completions API (OpenAI-compatible).\n *\n * @module providers/moonshot/types\n */\n\n/**\n * Thinking mode configuration for Moonshot models.\n *\n * By default, kimi-k2.5 has thinking mode enabled and returns reasoning traces.\n * Use `{ type: 'disabled' }` to switch to instant mode for faster responses.\n */\nexport interface MoonshotThinkingConfig {\n /** Thinking mode type: 'enabled' (default) or 'disabled' for instant mode */\n type: 'enabled' | 'disabled';\n}\n\n/**\n * Parameters for the Moonshot Chat Completions API.\n *\n * These parameters are passed directly to the `/v1/chat/completions` endpoint.\n * Moonshot's API is OpenAI-compatible with additional thinking mode support.\n *\n * @example\n * ```typescript\n * const params: MoonshotLLMParams = {\n * temperature: 1.0,\n * max_tokens: 1000,\n * thinking: { type: 'enabled' } // Default for kimi-k2.5\n * };\n * ```\n */\nexport interface MoonshotLLMParams {\n /** Maximum number of tokens to generate */\n max_tokens?: number;\n\n /** Maximum completion tokens (alias for max_tokens) */\n max_completion_tokens?: number;\n\n /** Temperature for randomness (0.0 to 2.0). Default: 1.0 (thinking) or 0.6 (instant) */\n temperature?: number;\n\n /** Top-p (nucleus) sampling (0.0 - 1.0), default 0.95 */\n top_p?: number;\n\n /** Custom stop sequences */\n stop?: string | string[];\n\n /** Frequency penalty (-2.0 - 2.0) */\n frequency_penalty?: number;\n\n /** Presence penalty (-2.0 - 2.0) */\n presence_penalty?: number;\n\n /** Seed for deterministic sampling */\n seed?: number;\n\n /** User identifier for rate limit tracking */\n user?: string;\n\n /** Response format for structured output */\n response_format?: MoonshotResponseFormat;\n\n /** Thinking mode configuration (kimi-k2.5 specific) */\n thinking?: MoonshotThinkingConfig;\n\n /**\n * Builtin tools to enable for this request.\n * Use the `tools` helper object to create these.\n *\n * @example\n * ```typescript\n * import { moonshot, tools } from '@providerprotocol/ai/moonshot';\n *\n * const model = llm({\n * model: moonshot('kimi-k2.5'),\n * params: {\n * tools: [tools.webSearch(), tools.codeRunner()],\n * },\n * });\n * ```\n */\n tools?: MoonshotTool[];\n}\n\n/**\n * Response format options for structured output.\n */\nexport type MoonshotResponseFormat =\n | { type: 'text' }\n | { type: 'json_object' }\n | {\n type: 'json_schema';\n json_schema: {\n name: string;\n description?: string;\n schema: Record<string, unknown>;\n strict?: boolean;\n };\n };\n\n/**\n * Request body for the Moonshot Chat Completions API.\n */\nexport interface MoonshotRequest {\n model: string;\n messages: MoonshotMessage[];\n temperature?: number;\n top_p?: number;\n stream?: boolean;\n stream_options?: { include_usage?: boolean };\n stop?: string | string[];\n max_tokens?: number;\n max_completion_tokens?: number;\n presence_penalty?: number;\n frequency_penalty?: number;\n user?: string;\n seed?: number;\n tools?: MoonshotTool[];\n tool_choice?: MoonshotToolChoice;\n response_format?: MoonshotResponseFormat;\n thinking?: MoonshotThinkingConfig;\n}\n\n/**\n * Union type for all message types in the Moonshot API.\n */\nexport type MoonshotMessage =\n | MoonshotSystemMessage\n | MoonshotUserMessage\n | MoonshotAssistantMessage\n | MoonshotToolMessage;\n\n/** System message for setting context and instructions */\nexport interface MoonshotSystemMessage {\n role: 'system';\n content: string;\n}\n\n/** User message with text or multimodal content */\nexport interface MoonshotUserMessage {\n role: 'user';\n content: string | MoonshotUserContent[];\n}\n\n/** Assistant message containing the model's response */\nexport interface MoonshotAssistantMessage {\n role: 'assistant';\n content?: string | null;\n /** Reasoning traces from thinking mode */\n reasoning_content?: string | null;\n tool_calls?: MoonshotToolCall[];\n}\n\n/** Tool result message providing output from a function call */\nexport interface MoonshotToolMessage {\n role: 'tool';\n content: string;\n tool_call_id: string;\n}\n\n/**\n * Union type for user content parts (text, image, or video).\n */\nexport type MoonshotUserContent = MoonshotTextContent | MoonshotImageContent | MoonshotVideoContent;\n\n/** Text content part */\nexport interface MoonshotTextContent {\n type: 'text';\n text: string;\n}\n\n/** Image content part with URL reference (for vision models) */\nexport interface MoonshotImageContent {\n type: 'image_url';\n image_url: {\n url: string;\n };\n}\n\n/** Video content part with URL reference (experimental) */\nexport interface MoonshotVideoContent {\n type: 'video_url';\n video_url: {\n url: string;\n };\n}\n\n/**\n * Tool call structure in assistant messages.\n */\nexport interface MoonshotToolCall {\n id: string;\n type: 'function';\n function: {\n name: string;\n arguments: string;\n };\n}\n\n/**\n * Tool definition for the Moonshot API.\n * Used for both custom function tools and server-side builtin tools.\n */\nexport interface MoonshotTool {\n type: 'function';\n function: {\n name: string;\n description: string;\n parameters: {\n type?: 'object';\n description?: string;\n properties: Record<string, unknown>;\n required?: string[];\n additionalProperties?: boolean;\n };\n strict?: boolean;\n };\n}\n\n/**\n * Tool choice options for controlling function calling behavior.\n * Moonshot models support full tool_choice including 'required'.\n */\nexport type MoonshotToolChoice =\n | 'none'\n | 'auto'\n | 'required'\n | { type: 'function'; function: { name: string } };\n\n// ============================================\n// Server-Side Tool Factory Functions\n// ============================================\n// These tools are executed by Moonshot's servers, not by the client.\n// The model decides when to call them and the API handles execution.\n//\n// TODO: Implement `excel` plugin - uses `_plugin` format with multiple\n// sub-functions (read_file, list_sheets, describe, inspect, pipe, groupby,\n// orderby, filter, head, value_counts, correlation, sample, select, count,\n// sum, distinct, add_column). Requires file IDs from Moonshot's /v1/files API.\n\n/**\n * Options for web search tool.\n */\nexport interface MoonshotWebSearchOptions {\n /** Search domains to focus on */\n classes?: Array<'all' | 'academic' | 'social' | 'library' | 'finance' | 'code' | 'ecommerce' | 'medical'>;\n}\n\n/**\n * Creates a web search tool (server-side execution).\n * Enables real-time internet search capabilities.\n *\n * Note: Web search is charged separately from regular API usage.\n *\n * @example\n * ```typescript\n * import { moonshot, tools } from '@providerprotocol/ai/moonshot';\n *\n * const model = llm({\n * model: moonshot('kimi-k2.5'),\n * params: {\n * tools: [tools.webSearch()],\n * },\n * });\n * ```\n */\nexport function webSearch(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'web_search',\n description: 'Search the web for information',\n parameters: {\n type: 'object',\n properties: {\n query: {\n description: 'What to search for',\n type: 'string',\n },\n classes: {\n description: 'Search domains to focus on. Defaults to \"all\" if not specified.',\n type: 'array',\n items: {\n type: 'string',\n enum: ['all', 'academic', 'social', 'library', 'finance', 'code', 'ecommerce', 'medical'],\n },\n },\n },\n required: ['query'],\n },\n },\n };\n}\n\n/**\n * Creates a Python code runner tool (server-side execution).\n * Allows execution of Python code for calculations and data processing.\n * Supports print output, matplotlib plots, pandas, and file reading via ctx.read_object().\n */\nexport function codeRunner(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'code_runner',\n description: 'Safely executes Python code and returns the result, with print output, last-line evaluation, error handling, and timeout protection.',\n parameters: {\n type: 'object',\n properties: {\n code: {\n description: 'The Python code to execute. Supports print(), matplotlib, pandas, and ctx.read_object() for file reading.',\n type: 'string',\n },\n },\n required: ['code'],\n },\n },\n };\n}\n\n/**\n * Creates a QuickJS JavaScript execution tool (server-side execution).\n * Enables secure JavaScript code execution via the QuickJS engine.\n */\nexport function quickjs(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'quickjs',\n description: 'Safely executes JavaScript code using QuickJS engine',\n parameters: {\n type: 'object',\n properties: {\n code: {\n description: 'The JavaScript code to execute. Supports console.log(), ES6+ features, and ctx.log() for logging.',\n type: 'string',\n },\n },\n required: ['code'],\n },\n },\n };\n}\n\n/**\n * Creates a URL fetch tool (server-side execution).\n * Extracts content from URLs and formats it as Markdown.\n */\nexport function fetch(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'fetch',\n description: 'Fetches a URL from the internet and optionally extracts its contents as markdown.',\n parameters: {\n type: 'object',\n properties: {\n url: {\n description: 'URL to fetch',\n type: 'string',\n format: 'uri',\n },\n max_length: {\n description: 'Maximum number of characters to return (default: 5000)',\n type: 'integer',\n default: 5000,\n },\n start_index: {\n description: 'Start at this character index, useful for pagination',\n type: 'integer',\n default: 0,\n },\n raw: {\n description: 'Get raw HTML without simplification',\n type: 'boolean',\n default: false,\n },\n },\n required: ['url'],\n },\n },\n };\n}\n\n/**\n * Creates a unit conversion tool (server-side execution).\n * Supports length, mass, volume, temperature, area, time, energy,\n * pressure, speed, and currency conversions.\n */\nexport function convert(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'convert',\n description: 'Convert between supported units of length, mass, volume, temperature, area, time, energy, pressure, speed, and currency.',\n parameters: {\n type: 'object',\n properties: {\n value: {\n description: 'Value to convert',\n type: 'number',\n },\n from_unit: {\n description: 'Source unit (e.g., m, km, ft, kg, lb, °C, °F, USD, EUR)',\n type: 'string',\n },\n to_unit: {\n description: 'Target unit',\n type: 'string',\n },\n },\n required: ['value', 'from_unit', 'to_unit'],\n },\n },\n };\n}\n\n/**\n * Creates a date/time processing tool (server-side execution).\n * Handles date and time calculations, timezone conversion, and formatting.\n */\nexport function date(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'date',\n description: 'Date and time processing tool, supports displaying current time, timezone conversion, date calculation, and more.',\n parameters: {\n type: 'object',\n properties: {\n operation: {\n description: 'Operation type',\n type: 'string',\n enum: ['time', 'convert', 'between', 'add', 'subtract'],\n },\n date: {\n description: 'Date string (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS)',\n type: 'string',\n },\n date1: {\n description: 'First date (for difference calculation)',\n type: 'string',\n },\n date2: {\n description: 'Second date (for difference calculation)',\n type: 'string',\n },\n days: {\n description: 'Number of days (for add/subtract)',\n type: 'integer',\n },\n zone: {\n description: 'Timezone name (e.g., Asia/Shanghai, America/New_York, UTC)',\n type: 'string',\n },\n from_zone: {\n description: 'Source timezone (for conversion)',\n type: 'string',\n },\n to_zone: {\n description: 'Target timezone (for conversion)',\n type: 'string',\n },\n format: {\n description: 'Output format (Python strftime)',\n type: 'string',\n default: '%Y-%m-%d %H:%M:%S',\n },\n },\n required: ['operation'],\n },\n },\n };\n}\n\n/**\n * Creates a Base64 encoding tool (server-side execution).\n */\nexport function base64Encode(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'base64_encode',\n description: 'Encode text to base64 format',\n parameters: {\n type: 'object',\n properties: {\n data: {\n description: 'Text data to encode to base64',\n type: 'string',\n },\n encoding: {\n description: 'Character encoding to use (default: utf-8)',\n type: 'string',\n default: 'utf-8',\n },\n },\n required: ['data'],\n },\n },\n };\n}\n\n/**\n * Creates a Base64 decoding tool (server-side execution).\n */\nexport function base64Decode(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'base64_decode',\n description: 'Decode base64 text to original format',\n parameters: {\n type: 'object',\n properties: {\n data: {\n description: 'Base64 encoded data to decode',\n type: 'string',\n },\n encoding: {\n description: 'Character encoding to use (default: utf-8)',\n type: 'string',\n default: 'utf-8',\n },\n },\n required: ['data'],\n },\n },\n };\n}\n\n/**\n * Creates a memory storage tool (server-side execution).\n * Supports persistent storage of conversation history and user preferences.\n */\nexport function memory(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'memory',\n description: 'Memory storage and retrieval system, supporting persistence of conversation history, user preferences, and other data.',\n parameters: {\n type: 'object',\n properties: {\n action: {\n description: 'Operation type',\n type: 'string',\n enum: ['store', 'retrieve', 'delete', 'list'],\n },\n key: {\n description: 'Storage key name',\n type: 'string',\n },\n data: {\n description: 'Data content to store',\n type: 'object',\n },\n prefix: {\n description: 'Key prefix for list operation',\n type: 'string',\n },\n ttl: {\n description: 'Data expiration time in seconds (default: 86400 = 24 hours)',\n type: 'integer',\n default: 86400,\n },\n },\n required: ['action'],\n },\n },\n };\n}\n\n/**\n * Creates an intelligent reasoning tool (server-side execution).\n * Allows the model to organize thoughts and plan before responding.\n */\nexport function rethink(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'rethink',\n description: 'Tool for organizing thoughts, making plans, and thinking step by step. Does not return information, just for reflection.',\n parameters: {\n type: 'object',\n properties: {\n thought: {\n description: 'The thought to consider for better solving the current task',\n type: 'string',\n },\n },\n required: ['thought'],\n },\n },\n };\n}\n\n/**\n * Creates a random choice tool (server-side execution).\n * Enables random selection from options with optional weights.\n */\nexport function randomChoice(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'random_choice',\n description: 'Random selection tool that supports choosing items from candidates with optional weights.',\n parameters: {\n type: 'object',\n properties: {\n candidates: {\n description: 'List of candidates to choose from',\n type: 'array',\n items: { type: 'string' },\n },\n count: {\n description: 'Number of items to select (default: 1)',\n type: 'integer',\n default: 1,\n },\n replace: {\n description: 'Allow duplicates (default: false)',\n type: 'boolean',\n default: false,\n },\n weights: {\n description: 'Optional weights for weighted selection',\n type: 'array',\n items: { type: 'number' },\n },\n seed: {\n description: 'Random seed for reproducibility',\n type: 'integer',\n },\n format: {\n description: 'Output format',\n type: 'string',\n enum: ['simple', 'detailed', 'json'],\n default: 'simple',\n },\n },\n required: ['candidates'],\n },\n },\n };\n}\n\n/**\n * Creates a cat meowing/blessing tool (server-side execution).\n * Returns random cat meowing sounds and blessings based on mood.\n */\nexport function mew(): MoonshotTool {\n return {\n type: 'function',\n function: {\n name: 'mew_generator',\n description: \"Randomly generates a cat's meow, accompanied by a blessing.\",\n parameters: {\n type: 'object',\n properties: {\n mood: {\n description: \"The cat's mood\",\n type: 'string',\n enum: ['happy', 'sleepy', 'hungry', 'playful', 'grumpy'],\n },\n },\n required: [],\n },\n },\n };\n}\n\n\n/**\n * Moonshot builtin tools factory object.\n * Provides convenient access to all builtin tool creators.\n *\n * Note: The `excel` plugin tool uses a different format and is not included here.\n * It requires file IDs from the Moonshot file upload API.\n *\n * @example\n * ```typescript\n * import { moonshot, tools } from '@providerprotocol/ai/moonshot';\n *\n * const model = llm({\n * model: moonshot('kimi-k2.5'),\n * params: {\n * tools: [\n * tools.webSearch(),\n * tools.codeRunner(),\n * tools.fetch(),\n * ],\n * },\n * });\n * ```\n */\nexport const tools = {\n /** Web search for real-time internet information */\n webSearch,\n /** Python code execution with matplotlib, pandas support */\n codeRunner,\n /** JavaScript execution via QuickJS engine */\n quickjs,\n /** URL content fetching with markdown extraction */\n fetch,\n /** Unit conversion (length, mass, temperature, currency, etc.) */\n convert,\n /** Date/time processing and timezone conversion */\n date,\n /** Base64 encoding */\n base64Encode,\n /** Base64 decoding */\n base64Decode,\n /** Alias for base64Encode */\n base64: base64Encode,\n /** Memory storage and retrieval system */\n memory,\n /** Intelligent reasoning/reflection tool */\n rethink,\n /** Random selection with optional weights */\n randomChoice,\n /** Cat meowing and blessings generator */\n mew,\n};\n\n/**\n * Response structure from the Moonshot Chat Completions API.\n */\nexport interface MoonshotResponse {\n id: string;\n object: 'chat.completion';\n created: number;\n model: string;\n choices: MoonshotChoice[];\n usage: MoonshotUsage;\n system_fingerprint?: string;\n}\n\n/** A single choice from a completion response */\nexport interface MoonshotChoice {\n index: number;\n message: MoonshotAssistantMessage;\n finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;\n}\n\n/** Token usage statistics from the API response */\nexport interface MoonshotUsage {\n prompt_tokens: number;\n completion_tokens: number;\n total_tokens: number;\n prompt_tokens_details?: {\n cached_tokens?: number;\n };\n}\n\n/**\n * Streaming chunk structure from the Moonshot API.\n */\nexport interface MoonshotStreamChunk {\n id: string;\n object: 'chat.completion.chunk';\n created: number;\n model: string;\n choices: MoonshotStreamChoice[];\n usage?: MoonshotUsage | null;\n system_fingerprint?: string;\n}\n\n/** A streaming choice containing incremental content */\nexport interface MoonshotStreamChoice {\n index: number;\n delta: MoonshotStreamDelta;\n finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;\n}\n\n/** Incremental content delta in a streaming chunk */\nexport interface MoonshotStreamDelta {\n role?: 'assistant';\n content?: string | null;\n reasoning_content?: string | null;\n tool_calls?: MoonshotStreamToolCall[];\n}\n\n/** Incremental tool call data in a streaming chunk */\nexport interface MoonshotStreamToolCall {\n index: number;\n id?: string;\n type?: 'function';\n function?: {\n name?: string;\n arguments?: string;\n };\n}\n\n/**\n * Moonshot-specific HTTP headers for API requests.\n *\n * @example\n * ```typescript\n * const headers: MoonshotHeaders = {\n * 'X-Request-Id': 'my-request-id',\n * };\n * ```\n */\nexport interface MoonshotHeaders {\n /** Client-generated request ID for tracing */\n 'X-Request-Id'?: string;\n [key: string]: string | undefined;\n}\n","/**\n * @fileoverview Moonshot Provider Factory\n *\n * This module provides the main Moonshot provider implementation for the\n * OpenAI-compatible Chat Completions API.\n *\n * @module providers/moonshot\n */\n\nimport { createProvider } from '../../core/provider.ts';\nimport { createLLMHandler } from './llm.ts';\n\n/**\n * Configuration options for the Moonshot provider.\n *\n * Currently Moonshot only supports one API endpoint (Chat Completions),\n * so no additional options are needed.\n */\nexport interface MoonshotProviderOptions {\n // Reserved for future use\n}\n\n/**\n * The Moonshot provider instance.\n *\n * Use this provider to create model references for Moonshot models like\n * Kimi K2.5 and other models available on the Moonshot AI platform.\n *\n * @example Basic usage\n * ```typescript\n * import { moonshot } from './providers/moonshot';\n * import { llm } from './core/llm';\n *\n * const model = llm({\n * model: moonshot('kimi-k2.5'),\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 thinking mode (default for K2.5)\n * ```typescript\n * const model = llm({\n * model: moonshot('kimi-k2.5'),\n * params: {\n * max_tokens: 2000,\n * temperature: 1.0, // Recommended for thinking mode\n * thinking: { type: 'enabled' } // Default\n * }\n * });\n *\n * // Response includes reasoning_content in metadata\n * const turn = await model.generate('Solve this step by step: 2x + 5 = 13');\n * ```\n *\n * @example With instant mode (disabled thinking)\n * ```typescript\n * const model = llm({\n * model: moonshot('kimi-k2.5'),\n * params: {\n * max_tokens: 1000,\n * temperature: 0.6, // Recommended for instant mode\n * thinking: { type: 'disabled' }\n * }\n * });\n * ```\n *\n * @example With vision (image input)\n * ```typescript\n * import { Image } from './core/media/Image';\n *\n * const image = await Image.fromPath('./photo.png');\n * const turn = await model.generate([\n * image.toBlock(),\n * { type: 'text', text: 'Describe this image' }\n * ]);\n * ```\n *\n * @example Available models\n * Production models:\n * - `kimi-k2.5` - Latest K2.5 with 256K context, vision, thinking mode\n *\n * Environment variables:\n * - `MOONSHOT_API_KEY` - Primary API key\n * - `KIMI_API_KEY` - Fallback API key\n */\nexport const moonshot = createProvider<MoonshotProviderOptions>({\n name: 'moonshot',\n version: '1.0.0',\n handlers: {\n llm: createLLMHandler(),\n },\n});\n\nexport { tools } from './types.ts';\nexport type {\n MoonshotLLMParams,\n MoonshotHeaders,\n MoonshotResponseFormat,\n MoonshotMessage,\n MoonshotRequest,\n MoonshotResponse,\n MoonshotStreamChunk,\n MoonshotTool,\n MoonshotToolCall,\n MoonshotToolChoice,\n MoonshotUsage,\n MoonshotThinkingConfig,\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,IACF;AACA,UAAM,YAAa,MAA6B;AAChD,QAAI,OAAO,cAAc,UAAU;AACjC,YAAM,IAAI;AAAA,QACR;AAAA,QACA,UAAU;AAAA,QACV;AAAA,QACA,aAAa;AAAA,MACf;AAAA,IACF;AACA,QAAI,UAAU,SAAS,GAAG;AACxB,YAAM,KAAK,SAAS;AAAA,IACtB;AAAA,EACF;AAEA,SAAO,MAAM,SAAS,IAAI,MAAM,KAAK,MAAM,IAAI;AACjD;AAKA,SAAS,mBAAgD,SAAmB;AAC1E,SAAO,QAAQ,OAAO,CAAC,MAAM,KAAK,OAAO,EAAE,SAAS,QAAQ;AAC9D;AAKA,SAAS,sBAAsB,OAA0C;AACvE,UAAQ,MAA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AM;AAAA,EACN,SAAS;AAAA,EACT,UAAU;AAAA,IACR,KAAK,iBAAiB;AAAA,EACxB;AACF,CAAC;","names":[]}
|
package/dist/ollama/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { e as Provider } from '../llm-
|
|
2
|
-
import '../stream-
|
|
3
|
-
import '../tool-
|
|
1
|
+
import { e as Provider } from '../llm-BWLaTzzY.js';
|
|
2
|
+
import '../stream-bBd_4Ipu.js';
|
|
3
|
+
import '../tool-BmAfKNBq.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @fileoverview Type definitions for the Ollama provider.
|
|
@@ -100,6 +100,26 @@ interface OllamaLLMParams {
|
|
|
100
100
|
/** Number of top log probabilities to return */
|
|
101
101
|
top_logprobs?: number;
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Ollama-specific HTTP headers for API requests.
|
|
105
|
+
*
|
|
106
|
+
* Supports arbitrary headers for proxy authentication.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const headers: OllamaHeaders = {
|
|
111
|
+
* 'CF-Access-Client-Id': 'client-id.access',
|
|
112
|
+
* 'CF-Access-Client-Secret': 'secret-token',
|
|
113
|
+
* };
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
interface OllamaHeaders {
|
|
117
|
+
/** Cloudflare Access client ID for protected tunnels. */
|
|
118
|
+
'CF-Access-Client-Id'?: string;
|
|
119
|
+
/** Cloudflare Access client secret for protected tunnels. */
|
|
120
|
+
'CF-Access-Client-Secret'?: string;
|
|
121
|
+
[key: string]: string | undefined;
|
|
122
|
+
}
|
|
103
123
|
|
|
104
124
|
/**
|
|
105
125
|
* @fileoverview Ollama Embeddings API Handler
|
|
@@ -204,4 +224,4 @@ interface OllamaEmbedParams {
|
|
|
204
224
|
*/
|
|
205
225
|
declare const ollama: Provider<unknown>;
|
|
206
226
|
|
|
207
|
-
export { type OllamaEmbedParams, type OllamaLLMParams, ollama };
|
|
227
|
+
export { type OllamaEmbedParams, type OllamaHeaders, type OllamaLLMParams, ollama };
|
package/dist/ollama/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "../chunk-TUTYMOBL.js";
|
|
4
4
|
import {
|
|
5
5
|
resolveApiKey
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-EY2LLDGY.js";
|
|
7
7
|
import {
|
|
8
8
|
createProvider
|
|
9
9
|
} from "../chunk-JA3UZALR.js";
|
|
@@ -11,17 +11,18 @@ import {
|
|
|
11
11
|
doFetch,
|
|
12
12
|
doStreamFetch,
|
|
13
13
|
normalizeHttpError
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-VQZPADW6.js";
|
|
15
15
|
import {
|
|
16
16
|
StreamEventType,
|
|
17
17
|
objectDelta
|
|
18
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-F5ENANMJ.js";
|
|
19
19
|
import {
|
|
20
20
|
AssistantMessage,
|
|
21
21
|
isAssistantMessage,
|
|
22
22
|
isToolResultMessage,
|
|
23
23
|
isUserMessage
|
|
24
|
-
} from "../chunk-
|
|
24
|
+
} from "../chunk-6QCV4WXF.js";
|
|
25
|
+
import "../chunk-U2G5PHHL.js";
|
|
25
26
|
import {
|
|
26
27
|
toError
|
|
27
28
|
} from "../chunk-GIDT7C6I.js";
|