@amux.ai/adapter-deepseek 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +634 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +220 -0
- package/dist/index.d.ts +220 -0
- package/dist/index.js +632 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/inbound/request-parser.ts","../src/inbound/response-parser.ts","../src/inbound/stream-parser.ts","../src/inbound/error-parser.ts","../src/outbound/request-builder.ts","../src/outbound/response-builder.ts","../src/outbound/stream-builder.ts","../src/adapter.ts"],"names":["mapFinishReason","parseOpenAICompatibleError","contentToString"],"mappings":";;;;;AAeO,SAAS,aAAa,OAAA,EAAgC;AAC3D,EAAA,MAAM,GAAA,GAAM,OAAA;AAGZ,EAAA,IAAI,MAAA;AACJ,EAAA,MAAM,WAAsB,EAAC;AAE7B,EAAA,KAAA,MAAW,GAAA,IAAO,IAAI,QAAA,EAAU;AAC9B,IAAA,IAAI,GAAA,CAAI,SAAS,QAAA,EAAU;AACzB,MAAA,IAAI,OAAO,GAAA,CAAI,OAAA,KAAY,QAAA,EAAU;AACnC,QAAA,MAAA,GAAS,MAAA,GAAS,GAAG,MAAM;AAAA,EAAK,GAAA,CAAI,OAAO,CAAA,CAAA,GAAK,GAAA,CAAI,OAAA;AAAA,MACtD;AAAA,IACF,CAAA,MAAO;AACL,MAAA,QAAA,CAAS,IAAA,CAAK,YAAA,CAAa,GAAG,CAAC,CAAA;AAAA,IACjC;AAAA,EACF;AAGA,EAAA,MAAM,KAAA,GAA4B,IAAI,KAAA,EAAO,GAAA,CAAI,CAAC,IAAA,KAAS,SAAA,CAAU,IAAI,CAAC,CAAA;AAG1E,EAAA,MAAM,aAAqC,GAAA,CAAI,WAAA,GAC3C,eAAA,CAAgB,GAAA,CAAI,WAAW,CAAA,GAC/B,MAAA;AAEJ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A,QAAA,EAAU;AAAA,IACR,YAAA,EAAc,CAAC,EAAA,KAA8B;AAC3C,MAAA,OAAO,aAAa,EAAE,CAAA;AAAA,IACxB,CAAA;AAAA,IAEA,aAAA,EAAe,CAAC,EAAA,KAA+B;AAC7C,MAAA,OAAO,cAAc,EAAE,CAAA;AAAA,IACzB,CAAA;AAAA,IAEA;AAAA,GACF;AAAA,EAEA,OAAA,GAAuB;AACrB,IAAA,OAAO;AAAA,MACL,MAAM,IAAA,CAAK,IAAA;AAAA,MACX,SAAS,IAAA,CAAK,OAAA;AAAA,MACd,cAAc,IAAA,CAAK,YAAA;AAAA,MACnB,QAAA,EAAU;AAAA,QACR,OAAA,EAAS,0BAAA;AAAA,QACT,QAAA,EAAU,sBAAA;AAAA,QACV,UAAA,EAAY;AAAA;AACd,KACF;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import type {\n LLMRequestIR,\n Message,\n Tool,\n ToolChoice,\n ContentPart,\n TextContent,\n ImageContent,\n} from '@amux.ai/llm-bridge'\n\nimport type { DeepSeekRequest, DeepSeekMessage, DeepSeekTool, DeepSeekContentPart } from '../types'\n\n/**\n * Parse DeepSeek request to IR\n */\nexport function parseRequest(request: unknown): LLMRequestIR {\n const req = request as DeepSeekRequest\n\n // Extract system message if present\n let system: string | undefined\n const messages: Message[] = []\n\n for (const msg of req.messages) {\n if (msg.role === 'system') {\n if (typeof msg.content === 'string') {\n system = system ? `${system}\\n${msg.content}` : msg.content\n }\n } else {\n messages.push(parseMessage(msg))\n }\n }\n\n // Parse tools\n const tools: Tool[] | undefined = req.tools?.map((tool) => parseTool(tool))\n\n // Parse tool choice\n const toolChoice: ToolChoice | undefined = req.tool_choice\n ? parseToolChoice(req.tool_choice)\n : undefined\n\n return {\n messages,\n model: req.model,\n tools,\n toolChoice,\n stream: req.stream,\n system,\n generation: {\n temperature: req.temperature,\n topP: req.top_p,\n maxTokens: req.max_tokens,\n stopSequences: req.stop\n ? Array.isArray(req.stop)\n ? req.stop\n : [req.stop]\n : undefined,\n presencePenalty: req.presence_penalty,\n frequencyPenalty: req.frequency_penalty,\n responseFormat: req.response_format\n ? { type: req.response_format.type }\n : undefined,\n logprobs: req.logprobs,\n topLogprobs: req.top_logprobs,\n // DeepSeek-specific: thinking mode\n thinking: req.thinking\n ? { enabled: req.thinking.type === 'enabled' }\n : undefined,\n },\n raw: request,\n }\n}\n\nfunction parseMessage(msg: DeepSeekMessage): Message {\n return {\n role: msg.role,\n content: parseContent(msg.content),\n name: msg.name,\n toolCalls: msg.tool_calls,\n toolCallId: msg.tool_call_id,\n // DeepSeek-specific: reasoning content\n reasoningContent: msg.reasoning_content,\n }\n}\n\nfunction parseContent(\n content: string | DeepSeekContentPart[] | null | undefined\n): string | ContentPart[] {\n if (content === null || content === undefined) {\n return ''\n }\n\n if (typeof content === 'string') {\n return content\n }\n\n return content.map((part): ContentPart => {\n if (part.type === 'text') {\n return {\n type: 'text',\n text: part.text,\n } as TextContent\n }\n\n if (part.type === 'image_url') {\n const url = part.image_url.url\n\n if (url.startsWith('data:')) {\n const match = url.match(/^data:([^;]+);base64,(.+)$/)\n if (match) {\n return {\n type: 'image',\n source: {\n type: 'base64',\n mediaType: match[1],\n data: match[2],\n },\n } as ImageContent\n }\n }\n\n return {\n type: 'image',\n source: {\n type: 'url',\n url: url,\n },\n } as ImageContent\n }\n\n return {\n type: 'text',\n text: JSON.stringify(part),\n } as TextContent\n })\n}\n\nfunction parseTool(tool: DeepSeekTool): Tool {\n return {\n type: 'function',\n function: {\n name: tool.function.name,\n description: tool.function.description,\n parameters: tool.function.parameters,\n strict: tool.function.strict,\n },\n }\n}\n\nfunction parseToolChoice(\n choice: 'auto' | 'none' | 'required' | { type: 'function'; function: { name: string } }\n): ToolChoice {\n if (typeof choice === 'string') {\n return choice as ToolChoice\n }\n return {\n type: 'function',\n function: {\n name: choice.function.name,\n },\n }\n}\n","import type { LLMResponseIR, Choice, Role } from '@amux.ai/llm-bridge'\nimport { mapFinishReason } from '@amux.ai/llm-bridge'\n\nimport type { DeepSeekResponse } from '../types'\n\n/**\n * Parse DeepSeek response to IR\n */\nexport function parseResponse(response: unknown): LLMResponseIR {\n const res = response as DeepSeekResponse\n\n const choices: Choice[] = res.choices.map((choice) => ({\n index: choice.index,\n message: {\n role: choice.message.role as Role,\n content: choice.message.content ?? '',\n toolCalls: choice.message.tool_calls,\n // DeepSeek-specific: reasoning content\n reasoningContent: choice.message.reasoning_content,\n },\n finishReason: mapFinishReason(choice.finish_reason),\n logprobs: choice.logprobs,\n }))\n\n return {\n id: res.id,\n model: res.model,\n choices,\n created: res.created,\n systemFingerprint: res.system_fingerprint,\n usage: res.usage\n ? {\n promptTokens: res.usage.prompt_tokens,\n completionTokens: res.usage.completion_tokens,\n totalTokens: res.usage.total_tokens,\n details: {\n reasoningTokens: res.usage.completion_tokens_details?.reasoning_tokens,\n // DeepSeek-specific: cache tokens\n cachedTokens: res.usage.prompt_cache_hit_tokens,\n },\n }\n : undefined,\n // Store DeepSeek-specific cache info in extensions\n extensions: res.usage?.prompt_cache_hit_tokens !== undefined\n ? {\n deepseek: {\n promptCacheHitTokens: res.usage.prompt_cache_hit_tokens,\n promptCacheMissTokens: res.usage.prompt_cache_miss_tokens,\n },\n }\n : undefined,\n raw: response,\n }\n}\n","import type { LLMStreamEvent, FinishReason } from '@amux.ai/llm-bridge'\n\nimport type { DeepSeekStreamChunk } from '../types'\n\n/**\n * Map DeepSeek finish reason to IR finish reason\n */\nfunction mapFinishReason(reason: string): FinishReason {\n const reasonMap: Record<string, FinishReason> = {\n stop: 'stop',\n length: 'length',\n tool_calls: 'tool_calls',\n content_filter: 'content_filter',\n insufficient_system_resource: 'error',\n }\n return reasonMap[reason] ?? 'stop'\n}\n\n/**\n * Parse DeepSeek stream chunk to IR stream event\n */\nexport function parseStream(\n chunk: unknown\n): LLMStreamEvent | LLMStreamEvent[] | null {\n const data = chunk as DeepSeekStreamChunk\n\n if (!data.choices || data.choices.length === 0) {\n // Check for usage-only chunk\n if (data.usage) {\n return {\n type: 'end',\n id: data.id,\n model: data.model,\n usage: {\n promptTokens: data.usage.prompt_tokens,\n completionTokens: data.usage.completion_tokens,\n totalTokens: data.usage.total_tokens,\n details: {\n reasoningTokens: data.usage.completion_tokens_details?.reasoning_tokens,\n cachedTokens: data.usage.prompt_cache_hit_tokens,\n },\n },\n raw: chunk,\n }\n }\n return null\n }\n\n const choice = data.choices[0]\n if (!choice) return null\n\n const delta = choice.delta\n const events: LLMStreamEvent[] = []\n\n // Start event (first chunk with role)\n if (delta.role && !delta.content && !delta.tool_calls && !delta.reasoning_content) {\n return {\n type: 'start',\n id: data.id,\n model: data.model,\n raw: chunk,\n }\n }\n\n // DeepSeek-specific: Reasoning content delta\n if (delta.reasoning_content) {\n events.push({\n type: 'reasoning',\n id: data.id,\n model: data.model,\n reasoning: {\n type: 'reasoning',\n delta: delta.reasoning_content,\n index: choice.index,\n },\n raw: chunk,\n })\n }\n\n // Content delta\n if (delta.content) {\n events.push({\n type: 'content',\n id: data.id,\n model: data.model,\n content: {\n type: 'content',\n delta: delta.content,\n index: choice.index,\n },\n raw: chunk,\n })\n }\n\n // Tool call delta\n if (delta.tool_calls && delta.tool_calls.length > 0) {\n const toolCall = delta.tool_calls[0]\n if (toolCall) {\n events.push({\n type: 'tool_call',\n id: data.id,\n model: data.model,\n toolCall: {\n type: 'tool_call',\n id: toolCall.id,\n name: toolCall.function?.name,\n arguments: toolCall.function?.arguments,\n index: toolCall.index,\n },\n raw: chunk,\n })\n }\n }\n\n // End event\n if (choice.finish_reason) {\n events.push({\n type: 'end',\n id: data.id,\n model: data.model,\n finishReason: mapFinishReason(choice.finish_reason),\n usage: data.usage\n ? {\n promptTokens: data.usage.prompt_tokens,\n completionTokens: data.usage.completion_tokens,\n totalTokens: data.usage.total_tokens,\n details: {\n reasoningTokens: data.usage.completion_tokens_details?.reasoning_tokens,\n cachedTokens: data.usage.prompt_cache_hit_tokens,\n },\n }\n : undefined,\n raw: chunk,\n })\n }\n\n if (events.length === 0) {\n return null\n }\n\n const firstEvent = events[0]\n return events.length === 1 && firstEvent ? firstEvent : events\n}\n","import { parseOpenAICompatibleError } from '@amux.ai/llm-bridge'\nimport type { LLMErrorIR } from '@amux.ai/llm-bridge'\n\n/**\n * Parse DeepSeek error to IR\n */\nexport function parseError(error: unknown): LLMErrorIR {\n return parseOpenAICompatibleError(error)\n}\n","import type { LLMRequestIR, ContentPart, ImageContent } from '@amux.ai/llm-bridge'\n\nimport type { DeepSeekRequest, DeepSeekMessage, DeepSeekContentPart } from '../types'\n\n/**\n * Build DeepSeek request from IR\n */\nexport function buildRequest(ir: LLMRequestIR): DeepSeekRequest {\n const messages: DeepSeekMessage[] = []\n const isReasonerModel = ir.model?.includes('reasoner')\n\n // Add system message if present (from ir.system field)\n // Note: DeepSeek Reasoner does NOT support system messages\n if (ir.system && !isReasonerModel) {\n messages.push({\n role: 'system',\n content: ir.system,\n })\n }\n\n // Add conversation messages\n for (const msg of ir.messages) {\n // DeepSeek Reasoner: Skip system messages entirely\n // The API will return error if system messages are included\n if (isReasonerModel && msg.role === 'system') {\n continue\n }\n\n const message: DeepSeekMessage = {\n role: msg.role,\n content: buildContent(msg.content),\n name: msg.name,\n tool_calls: msg.toolCalls,\n tool_call_id: msg.toolCallId,\n }\n\n // DeepSeek Reasoner: Do NOT include reasoning_content in input messages\n // The API will return 400 error if reasoning_content is included\n if (!isReasonerModel && msg.reasoningContent !== undefined) {\n message.reasoning_content = msg.reasoningContent\n }\n\n messages.push(message)\n }\n\n const request: DeepSeekRequest = {\n model: ir.model ?? 'deepseek-chat',\n messages,\n stream: ir.stream,\n }\n\n // Add tools if present\n if (ir.tools && ir.tools.length > 0) {\n request.tools = ir.tools.map((tool) => ({\n type: 'function',\n function: {\n name: tool.function.name,\n description: tool.function.description,\n parameters: tool.function.parameters,\n strict: tool.function.strict,\n },\n }))\n }\n\n // Add tool choice if present\n if (ir.toolChoice) {\n request.tool_choice = ir.toolChoice\n }\n\n // Add generation parameters\n if (ir.generation) {\n if (ir.generation.temperature !== undefined) {\n request.temperature = ir.generation.temperature\n }\n if (ir.generation.topP !== undefined) {\n request.top_p = ir.generation.topP\n }\n if (ir.generation.maxTokens !== undefined) {\n // DeepSeek max_tokens limit: 1-8192\n request.max_tokens = Math.min(Math.max(ir.generation.maxTokens, 1), 8192)\n }\n if (ir.generation.stopSequences && ir.generation.stopSequences.length > 0) {\n request.stop = ir.generation.stopSequences\n }\n if (ir.generation.presencePenalty !== undefined) {\n request.presence_penalty = ir.generation.presencePenalty\n }\n if (ir.generation.frequencyPenalty !== undefined) {\n request.frequency_penalty = ir.generation.frequencyPenalty\n }\n if (ir.generation.responseFormat) {\n // DeepSeek only supports text and json_object\n if (ir.generation.responseFormat.type === 'json_object') {\n request.response_format = { type: 'json_object' }\n }\n }\n if (ir.generation.logprobs !== undefined) {\n request.logprobs = ir.generation.logprobs\n }\n if (ir.generation.topLogprobs !== undefined) {\n request.top_logprobs = ir.generation.topLogprobs\n }\n // DeepSeek-specific: thinking mode\n if (ir.generation.thinking) {\n request.thinking = {\n type: ir.generation.thinking.enabled ? 'enabled' : 'disabled',\n }\n }\n }\n\n // Add stream options for usage in streaming\n if (ir.stream) {\n request.stream_options = { include_usage: true }\n }\n\n return request\n}\n\nfunction buildContent(\n content: string | ContentPart[]\n): string | DeepSeekContentPart[] | null {\n if (typeof content === 'string') {\n return content || null\n }\n\n if (!content || content.length === 0) {\n return null\n }\n\n // Check if all parts are text - if so, concatenate them\n const allText = content.every((part) => part.type === 'text')\n if (allText) {\n return content\n .map((part) => (part.type === 'text' ? part.text : ''))\n .join('')\n }\n\n // Build multimodal content\n return content.map((part): DeepSeekContentPart => {\n if (part.type === 'text') {\n return { type: 'text', text: part.text }\n }\n\n if (part.type === 'image') {\n const imgPart = part as ImageContent\n if (imgPart.source.type === 'url') {\n return {\n type: 'image_url',\n image_url: { url: imgPart.source.url },\n }\n }\n return {\n type: 'image_url',\n image_url: {\n url: `data:${imgPart.source.mediaType};base64,${imgPart.source.data}`,\n },\n }\n }\n\n return { type: 'text', text: JSON.stringify(part) }\n })\n}\n","import type { LLMResponseIR } from '@amux.ai/llm-bridge'\nimport { contentToString } from '@amux.ai/llm-bridge'\n\nimport type { DeepSeekResponse } from '../types'\n\n/**\n * Build DeepSeek response from IR\n */\nexport function buildResponse(ir: LLMResponseIR): DeepSeekResponse {\n return {\n id: ir.id,\n object: 'chat.completion',\n created: ir.created ?? Math.floor(Date.now() / 1000),\n model: ir.model,\n system_fingerprint: ir.systemFingerprint,\n choices: ir.choices.map((choice) => ({\n index: choice.index,\n message: {\n role: choice.message.role,\n content: contentToString(choice.message.content),\n tool_calls: choice.message.toolCalls,\n // DeepSeek-specific: reasoning content\n reasoning_content: choice.message.reasoningContent,\n },\n finish_reason: choice.finishReason ?? 'stop',\n logprobs: choice.logprobs,\n })),\n usage: ir.usage\n ? {\n prompt_tokens: ir.usage.promptTokens,\n completion_tokens: ir.usage.completionTokens,\n total_tokens: ir.usage.totalTokens,\n // DeepSeek-specific: cache tokens\n prompt_cache_hit_tokens: ir.usage.details?.cachedTokens,\n prompt_cache_miss_tokens: (ir.extensions?.deepseek as { promptCacheMissTokens?: number } | undefined)?.promptCacheMissTokens,\n completion_tokens_details: ir.usage.details?.reasoningTokens\n ? {\n reasoning_tokens: ir.usage.details.reasoningTokens,\n }\n : undefined,\n }\n : undefined,\n }\n}\n","import type { LLMStreamEvent, SSEEvent, StreamEventBuilder } from '@amux.ai/llm-bridge'\n\n/**\n * OpenAI stream event builder\n * Converts IR stream events to OpenAI SSE format\n *\n * OpenAI uses a simpler SSE format compared to Anthropic:\n * - All events use \"data:\" prefix (no event type)\n * - Each chunk contains the full delta structure\n * - Stream ends with \"data: [DONE]\"\n */\nexport function createStreamBuilder(): StreamEventBuilder {\n let chunkId = `chatcmpl-${Date.now()}`\n let model = ''\n let created = Math.floor(Date.now() / 1000)\n const toolCallsState: Map<number, { id: string; name: string }> = new Map()\n\n return {\n process(event: LLMStreamEvent): SSEEvent[] {\n const events: SSEEvent[] = []\n\n // Update metadata from event\n if (event.id) chunkId = event.id\n if (event.model) model = event.model\n\n // Handle start event\n if (event.type === 'start') {\n // OpenAI doesn't have a separate start event\n // The first content chunk serves as the start\n events.push({\n event: 'data',\n data: {\n id: chunkId,\n object: 'chat.completion.chunk',\n created,\n model,\n choices: [{\n index: 0,\n delta: { role: 'assistant', content: '' },\n finish_reason: null,\n }],\n },\n })\n }\n\n // Handle content delta\n if (event.type === 'content' && event.content?.delta) {\n events.push({\n event: 'data',\n data: {\n id: chunkId,\n object: 'chat.completion.chunk',\n created,\n model,\n choices: [{\n index: 0,\n delta: { content: event.content.delta },\n finish_reason: null,\n }],\n },\n })\n }\n\n // Handle reasoning delta (for DeepSeek reasoner model)\n if (event.type === 'reasoning' && event.reasoning?.delta) {\n // DeepSeek uses reasoning_content field for thinking process\n events.push({\n event: 'data',\n data: {\n id: chunkId,\n object: 'chat.completion.chunk',\n created,\n model,\n choices: [{\n index: 0,\n delta: { reasoning_content: event.reasoning.delta },\n finish_reason: null,\n }],\n },\n })\n }\n\n // Handle tool call\n if (event.type === 'tool_call' && event.toolCall) {\n const toolIndex = event.toolCall.index ?? 0\n const toolCallDelta: {\n index: number\n id?: string\n type?: string\n function?: { name?: string; arguments?: string }\n } = { index: toolIndex }\n\n // If this is a new tool call (has name)\n if (event.toolCall.name) {\n toolCallDelta.id = event.toolCall.id || `call_${Date.now()}_${toolIndex}`\n toolCallDelta.type = 'function'\n toolCallDelta.function = { name: event.toolCall.name }\n toolCallsState.set(toolIndex, {\n id: toolCallDelta.id,\n name: event.toolCall.name,\n })\n }\n\n // If this has arguments\n if (event.toolCall.arguments) {\n toolCallDelta.function = {\n ...toolCallDelta.function,\n arguments: event.toolCall.arguments,\n }\n }\n\n events.push({\n event: 'data',\n data: {\n id: chunkId,\n object: 'chat.completion.chunk',\n created,\n model,\n choices: [{\n index: 0,\n delta: { tool_calls: [toolCallDelta] },\n finish_reason: null,\n }],\n },\n })\n }\n\n // Handle end event\n if (event.type === 'end') {\n const finishReason = mapFinishReason(event.finishReason)\n\n // Emit final chunk with finish_reason\n const finalChunk: {\n id: string\n object: string\n created: number\n model: string\n choices: Array<{\n index: number\n delta: Record<string, never>\n finish_reason: string\n }>\n usage?: {\n prompt_tokens: number\n completion_tokens: number\n total_tokens: number\n }\n } = {\n id: chunkId,\n object: 'chat.completion.chunk',\n created,\n model,\n choices: [{\n index: 0,\n delta: {},\n finish_reason: finishReason,\n }],\n }\n\n // Include usage if available\n if (event.usage) {\n finalChunk.usage = {\n prompt_tokens: event.usage.promptTokens ?? 0,\n completion_tokens: event.usage.completionTokens ?? 0,\n total_tokens: event.usage.totalTokens ?? 0,\n }\n }\n\n events.push({ event: 'data', data: finalChunk })\n }\n\n // Handle error event\n if (event.type === 'error' && event.error) {\n events.push({\n event: 'data',\n data: {\n error: {\n message: event.error.message,\n type: 'server_error',\n code: event.error.code,\n },\n },\n })\n }\n\n return events\n },\n\n finalize(): SSEEvent[] {\n // OpenAI streams end with [DONE]\n return [{ event: 'data', data: '[DONE]' }]\n },\n }\n}\n\n/**\n * Map IR finish reason to OpenAI finish reason\n */\nfunction mapFinishReason(reason?: string): string {\n if (!reason) return 'stop'\n\n const reasonMap: Record<string, string> = {\n stop: 'stop',\n length: 'length',\n tool_calls: 'tool_calls',\n content_filter: 'content_filter',\n end_turn: 'stop',\n max_tokens: 'length',\n }\n\n return reasonMap[reason] ?? 'stop'\n}\n","import type {\n LLMAdapter,\n LLMRequestIR,\n LLMResponseIR,\n LLMStreamEvent,\n LLMErrorIR,\n AdapterInfo,\n} from '@amux.ai/llm-bridge'\n\nimport { parseRequest } from './inbound/request-parser'\nimport { parseResponse } from './inbound/response-parser'\nimport { parseStream } from './inbound/stream-parser'\nimport { parseError } from './inbound/error-parser'\nimport { buildRequest } from './outbound/request-builder'\nimport { buildResponse } from './outbound/response-builder'\nimport { createStreamBuilder } from './outbound/stream-builder'\n\n/**\n * DeepSeek adapter implementation\n * Handles DeepSeek-specific features like reasoning_content and cache tokens\n */\nexport const deepseekAdapter: LLMAdapter = {\n name: 'deepseek',\n version: '1.0.0',\n capabilities: {\n streaming: true,\n tools: true,\n vision: false,\n multimodal: false,\n systemPrompt: true,\n toolChoice: true,\n reasoning: true, // DeepSeek-reasoner supports reasoning\n webSearch: false,\n jsonMode: true,\n logprobs: true,\n seed: false,\n },\n\n inbound: {\n parseRequest: (request: unknown): LLMRequestIR => {\n return parseRequest(request)\n },\n\n parseResponse: (response: unknown): LLMResponseIR => {\n return parseResponse(response)\n },\n\n parseStream: (chunk: unknown): LLMStreamEvent | LLMStreamEvent[] | null => {\n return parseStream(chunk)\n },\n\n parseError: (error: unknown): LLMErrorIR => {\n return parseError(error)\n },\n },\n\n outbound: {\n buildRequest: (ir: LLMRequestIR): unknown => {\n return buildRequest(ir)\n },\n\n buildResponse: (ir: LLMResponseIR): unknown => {\n return buildResponse(ir)\n },\n\n createStreamBuilder,\n },\n\n getInfo(): AdapterInfo {\n return {\n name: this.name,\n version: this.version,\n capabilities: this.capabilities,\n endpoint: {\n baseUrl: 'https://api.deepseek.com',\n chatPath: '/v1/chat/completions',\n modelsPath: '/v1/models',\n },\n }\n },\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { LLMAdapter, ToolCall, JSONSchema } from '@amux.ai/llm-bridge';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DeepSeek adapter implementation
|
|
5
|
+
* Handles DeepSeek-specific features like reasoning_content and cache tokens
|
|
6
|
+
*/
|
|
7
|
+
declare const deepseekAdapter: LLMAdapter;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* DeepSeek message content part types (same as OpenAI)
|
|
11
|
+
*/
|
|
12
|
+
type DeepSeekContentPart = {
|
|
13
|
+
type: 'text';
|
|
14
|
+
text: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: 'image_url';
|
|
17
|
+
image_url: {
|
|
18
|
+
url: string;
|
|
19
|
+
detail?: 'auto' | 'low' | 'high';
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* DeepSeek message format
|
|
24
|
+
* Extended from OpenAI with reasoning_content support
|
|
25
|
+
*/
|
|
26
|
+
interface DeepSeekMessage {
|
|
27
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
28
|
+
content?: string | DeepSeekContentPart[] | null;
|
|
29
|
+
name?: string;
|
|
30
|
+
tool_calls?: ToolCall[];
|
|
31
|
+
tool_call_id?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Reasoning content (for deepseek-reasoner model)
|
|
34
|
+
* Contains the model's chain-of-thought reasoning process
|
|
35
|
+
*/
|
|
36
|
+
reasoning_content?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Beta: Prefix mode - force model to start with specific content
|
|
39
|
+
*/
|
|
40
|
+
prefix?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* DeepSeek tool format (same as OpenAI)
|
|
44
|
+
*/
|
|
45
|
+
interface DeepSeekTool {
|
|
46
|
+
type: 'function';
|
|
47
|
+
function: {
|
|
48
|
+
name: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
parameters?: JSONSchema;
|
|
51
|
+
strict?: boolean;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* DeepSeek response format configuration
|
|
56
|
+
*/
|
|
57
|
+
interface DeepSeekResponseFormat {
|
|
58
|
+
type: 'text' | 'json_object';
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* DeepSeek thinking configuration
|
|
62
|
+
*/
|
|
63
|
+
interface DeepSeekThinking {
|
|
64
|
+
type: 'enabled' | 'disabled';
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* DeepSeek stream options
|
|
68
|
+
*/
|
|
69
|
+
interface DeepSeekStreamOptions {
|
|
70
|
+
include_usage?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* DeepSeek request format
|
|
74
|
+
* Based on OpenAI with DeepSeek-specific extensions
|
|
75
|
+
*/
|
|
76
|
+
interface DeepSeekRequest {
|
|
77
|
+
model: string;
|
|
78
|
+
messages: DeepSeekMessage[];
|
|
79
|
+
tools?: DeepSeekTool[];
|
|
80
|
+
tool_choice?: 'auto' | 'none' | 'required' | {
|
|
81
|
+
type: 'function';
|
|
82
|
+
function: {
|
|
83
|
+
name: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
stream?: boolean;
|
|
87
|
+
stream_options?: DeepSeekStreamOptions;
|
|
88
|
+
temperature?: number;
|
|
89
|
+
top_p?: number;
|
|
90
|
+
max_tokens?: number;
|
|
91
|
+
stop?: string | string[];
|
|
92
|
+
presence_penalty?: number;
|
|
93
|
+
frequency_penalty?: number;
|
|
94
|
+
response_format?: DeepSeekResponseFormat;
|
|
95
|
+
logprobs?: boolean;
|
|
96
|
+
top_logprobs?: number;
|
|
97
|
+
/**
|
|
98
|
+
* DeepSeek-specific: Enable thinking/reasoning mode
|
|
99
|
+
*/
|
|
100
|
+
thinking?: DeepSeekThinking;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* DeepSeek response usage with cache and reasoning details
|
|
104
|
+
*/
|
|
105
|
+
interface DeepSeekUsage {
|
|
106
|
+
prompt_tokens: number;
|
|
107
|
+
completion_tokens: number;
|
|
108
|
+
total_tokens: number;
|
|
109
|
+
/**
|
|
110
|
+
* DeepSeek-specific: Cached prompt tokens
|
|
111
|
+
*/
|
|
112
|
+
prompt_cache_hit_tokens?: number;
|
|
113
|
+
prompt_cache_miss_tokens?: number;
|
|
114
|
+
/**
|
|
115
|
+
* DeepSeek-specific: Reasoning tokens breakdown
|
|
116
|
+
*/
|
|
117
|
+
completion_tokens_details?: {
|
|
118
|
+
reasoning_tokens?: number;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* DeepSeek response format
|
|
123
|
+
*/
|
|
124
|
+
interface DeepSeekResponse {
|
|
125
|
+
id: string;
|
|
126
|
+
object: string;
|
|
127
|
+
created: number;
|
|
128
|
+
model: string;
|
|
129
|
+
system_fingerprint?: string;
|
|
130
|
+
choices: Array<{
|
|
131
|
+
index: number;
|
|
132
|
+
message: {
|
|
133
|
+
role: string;
|
|
134
|
+
content: string | null;
|
|
135
|
+
tool_calls?: ToolCall[];
|
|
136
|
+
/**
|
|
137
|
+
* DeepSeek-specific: Reasoning content
|
|
138
|
+
*/
|
|
139
|
+
reasoning_content?: string;
|
|
140
|
+
};
|
|
141
|
+
finish_reason: string;
|
|
142
|
+
logprobs?: {
|
|
143
|
+
content?: Array<{
|
|
144
|
+
token: string;
|
|
145
|
+
logprob: number;
|
|
146
|
+
top_logprobs?: Array<{
|
|
147
|
+
token: string;
|
|
148
|
+
logprob: number;
|
|
149
|
+
}>;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* DeepSeek-specific: Reasoning content logprobs
|
|
153
|
+
*/
|
|
154
|
+
reasoning_content?: Array<{
|
|
155
|
+
token: string;
|
|
156
|
+
logprob: number;
|
|
157
|
+
top_logprobs?: Array<{
|
|
158
|
+
token: string;
|
|
159
|
+
logprob: number;
|
|
160
|
+
}>;
|
|
161
|
+
}>;
|
|
162
|
+
};
|
|
163
|
+
}>;
|
|
164
|
+
usage?: DeepSeekUsage;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* DeepSeek stream chunk format
|
|
168
|
+
*/
|
|
169
|
+
interface DeepSeekStreamChunk {
|
|
170
|
+
id: string;
|
|
171
|
+
object: string;
|
|
172
|
+
created: number;
|
|
173
|
+
model: string;
|
|
174
|
+
system_fingerprint?: string;
|
|
175
|
+
choices: Array<{
|
|
176
|
+
index: number;
|
|
177
|
+
delta: {
|
|
178
|
+
role?: string;
|
|
179
|
+
content?: string;
|
|
180
|
+
tool_calls?: Array<{
|
|
181
|
+
index: number;
|
|
182
|
+
id?: string;
|
|
183
|
+
type?: string;
|
|
184
|
+
function?: {
|
|
185
|
+
name?: string;
|
|
186
|
+
arguments?: string;
|
|
187
|
+
};
|
|
188
|
+
}>;
|
|
189
|
+
/**
|
|
190
|
+
* DeepSeek-specific: Reasoning content delta
|
|
191
|
+
*/
|
|
192
|
+
reasoning_content?: string;
|
|
193
|
+
};
|
|
194
|
+
finish_reason?: string | null;
|
|
195
|
+
logprobs?: {
|
|
196
|
+
content?: Array<{
|
|
197
|
+
token: string;
|
|
198
|
+
logprob: number;
|
|
199
|
+
top_logprobs?: Array<{
|
|
200
|
+
token: string;
|
|
201
|
+
logprob: number;
|
|
202
|
+
}>;
|
|
203
|
+
}>;
|
|
204
|
+
};
|
|
205
|
+
}>;
|
|
206
|
+
usage?: DeepSeekUsage;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* DeepSeek error format
|
|
210
|
+
*/
|
|
211
|
+
interface DeepSeekError {
|
|
212
|
+
error: {
|
|
213
|
+
message: string;
|
|
214
|
+
type: string;
|
|
215
|
+
param?: string;
|
|
216
|
+
code?: string;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export { type DeepSeekContentPart, type DeepSeekError, type DeepSeekMessage, type DeepSeekRequest, type DeepSeekResponse, type DeepSeekResponseFormat, type DeepSeekStreamChunk, type DeepSeekStreamOptions, type DeepSeekThinking, type DeepSeekTool, type DeepSeekUsage, deepseekAdapter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { LLMAdapter, ToolCall, JSONSchema } from '@amux.ai/llm-bridge';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DeepSeek adapter implementation
|
|
5
|
+
* Handles DeepSeek-specific features like reasoning_content and cache tokens
|
|
6
|
+
*/
|
|
7
|
+
declare const deepseekAdapter: LLMAdapter;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* DeepSeek message content part types (same as OpenAI)
|
|
11
|
+
*/
|
|
12
|
+
type DeepSeekContentPart = {
|
|
13
|
+
type: 'text';
|
|
14
|
+
text: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: 'image_url';
|
|
17
|
+
image_url: {
|
|
18
|
+
url: string;
|
|
19
|
+
detail?: 'auto' | 'low' | 'high';
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* DeepSeek message format
|
|
24
|
+
* Extended from OpenAI with reasoning_content support
|
|
25
|
+
*/
|
|
26
|
+
interface DeepSeekMessage {
|
|
27
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
28
|
+
content?: string | DeepSeekContentPart[] | null;
|
|
29
|
+
name?: string;
|
|
30
|
+
tool_calls?: ToolCall[];
|
|
31
|
+
tool_call_id?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Reasoning content (for deepseek-reasoner model)
|
|
34
|
+
* Contains the model's chain-of-thought reasoning process
|
|
35
|
+
*/
|
|
36
|
+
reasoning_content?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Beta: Prefix mode - force model to start with specific content
|
|
39
|
+
*/
|
|
40
|
+
prefix?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* DeepSeek tool format (same as OpenAI)
|
|
44
|
+
*/
|
|
45
|
+
interface DeepSeekTool {
|
|
46
|
+
type: 'function';
|
|
47
|
+
function: {
|
|
48
|
+
name: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
parameters?: JSONSchema;
|
|
51
|
+
strict?: boolean;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* DeepSeek response format configuration
|
|
56
|
+
*/
|
|
57
|
+
interface DeepSeekResponseFormat {
|
|
58
|
+
type: 'text' | 'json_object';
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* DeepSeek thinking configuration
|
|
62
|
+
*/
|
|
63
|
+
interface DeepSeekThinking {
|
|
64
|
+
type: 'enabled' | 'disabled';
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* DeepSeek stream options
|
|
68
|
+
*/
|
|
69
|
+
interface DeepSeekStreamOptions {
|
|
70
|
+
include_usage?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* DeepSeek request format
|
|
74
|
+
* Based on OpenAI with DeepSeek-specific extensions
|
|
75
|
+
*/
|
|
76
|
+
interface DeepSeekRequest {
|
|
77
|
+
model: string;
|
|
78
|
+
messages: DeepSeekMessage[];
|
|
79
|
+
tools?: DeepSeekTool[];
|
|
80
|
+
tool_choice?: 'auto' | 'none' | 'required' | {
|
|
81
|
+
type: 'function';
|
|
82
|
+
function: {
|
|
83
|
+
name: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
stream?: boolean;
|
|
87
|
+
stream_options?: DeepSeekStreamOptions;
|
|
88
|
+
temperature?: number;
|
|
89
|
+
top_p?: number;
|
|
90
|
+
max_tokens?: number;
|
|
91
|
+
stop?: string | string[];
|
|
92
|
+
presence_penalty?: number;
|
|
93
|
+
frequency_penalty?: number;
|
|
94
|
+
response_format?: DeepSeekResponseFormat;
|
|
95
|
+
logprobs?: boolean;
|
|
96
|
+
top_logprobs?: number;
|
|
97
|
+
/**
|
|
98
|
+
* DeepSeek-specific: Enable thinking/reasoning mode
|
|
99
|
+
*/
|
|
100
|
+
thinking?: DeepSeekThinking;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* DeepSeek response usage with cache and reasoning details
|
|
104
|
+
*/
|
|
105
|
+
interface DeepSeekUsage {
|
|
106
|
+
prompt_tokens: number;
|
|
107
|
+
completion_tokens: number;
|
|
108
|
+
total_tokens: number;
|
|
109
|
+
/**
|
|
110
|
+
* DeepSeek-specific: Cached prompt tokens
|
|
111
|
+
*/
|
|
112
|
+
prompt_cache_hit_tokens?: number;
|
|
113
|
+
prompt_cache_miss_tokens?: number;
|
|
114
|
+
/**
|
|
115
|
+
* DeepSeek-specific: Reasoning tokens breakdown
|
|
116
|
+
*/
|
|
117
|
+
completion_tokens_details?: {
|
|
118
|
+
reasoning_tokens?: number;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* DeepSeek response format
|
|
123
|
+
*/
|
|
124
|
+
interface DeepSeekResponse {
|
|
125
|
+
id: string;
|
|
126
|
+
object: string;
|
|
127
|
+
created: number;
|
|
128
|
+
model: string;
|
|
129
|
+
system_fingerprint?: string;
|
|
130
|
+
choices: Array<{
|
|
131
|
+
index: number;
|
|
132
|
+
message: {
|
|
133
|
+
role: string;
|
|
134
|
+
content: string | null;
|
|
135
|
+
tool_calls?: ToolCall[];
|
|
136
|
+
/**
|
|
137
|
+
* DeepSeek-specific: Reasoning content
|
|
138
|
+
*/
|
|
139
|
+
reasoning_content?: string;
|
|
140
|
+
};
|
|
141
|
+
finish_reason: string;
|
|
142
|
+
logprobs?: {
|
|
143
|
+
content?: Array<{
|
|
144
|
+
token: string;
|
|
145
|
+
logprob: number;
|
|
146
|
+
top_logprobs?: Array<{
|
|
147
|
+
token: string;
|
|
148
|
+
logprob: number;
|
|
149
|
+
}>;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* DeepSeek-specific: Reasoning content logprobs
|
|
153
|
+
*/
|
|
154
|
+
reasoning_content?: Array<{
|
|
155
|
+
token: string;
|
|
156
|
+
logprob: number;
|
|
157
|
+
top_logprobs?: Array<{
|
|
158
|
+
token: string;
|
|
159
|
+
logprob: number;
|
|
160
|
+
}>;
|
|
161
|
+
}>;
|
|
162
|
+
};
|
|
163
|
+
}>;
|
|
164
|
+
usage?: DeepSeekUsage;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* DeepSeek stream chunk format
|
|
168
|
+
*/
|
|
169
|
+
interface DeepSeekStreamChunk {
|
|
170
|
+
id: string;
|
|
171
|
+
object: string;
|
|
172
|
+
created: number;
|
|
173
|
+
model: string;
|
|
174
|
+
system_fingerprint?: string;
|
|
175
|
+
choices: Array<{
|
|
176
|
+
index: number;
|
|
177
|
+
delta: {
|
|
178
|
+
role?: string;
|
|
179
|
+
content?: string;
|
|
180
|
+
tool_calls?: Array<{
|
|
181
|
+
index: number;
|
|
182
|
+
id?: string;
|
|
183
|
+
type?: string;
|
|
184
|
+
function?: {
|
|
185
|
+
name?: string;
|
|
186
|
+
arguments?: string;
|
|
187
|
+
};
|
|
188
|
+
}>;
|
|
189
|
+
/**
|
|
190
|
+
* DeepSeek-specific: Reasoning content delta
|
|
191
|
+
*/
|
|
192
|
+
reasoning_content?: string;
|
|
193
|
+
};
|
|
194
|
+
finish_reason?: string | null;
|
|
195
|
+
logprobs?: {
|
|
196
|
+
content?: Array<{
|
|
197
|
+
token: string;
|
|
198
|
+
logprob: number;
|
|
199
|
+
top_logprobs?: Array<{
|
|
200
|
+
token: string;
|
|
201
|
+
logprob: number;
|
|
202
|
+
}>;
|
|
203
|
+
}>;
|
|
204
|
+
};
|
|
205
|
+
}>;
|
|
206
|
+
usage?: DeepSeekUsage;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* DeepSeek error format
|
|
210
|
+
*/
|
|
211
|
+
interface DeepSeekError {
|
|
212
|
+
error: {
|
|
213
|
+
message: string;
|
|
214
|
+
type: string;
|
|
215
|
+
param?: string;
|
|
216
|
+
code?: string;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export { type DeepSeekContentPart, type DeepSeekError, type DeepSeekMessage, type DeepSeekRequest, type DeepSeekResponse, type DeepSeekResponseFormat, type DeepSeekStreamChunk, type DeepSeekStreamOptions, type DeepSeekThinking, type DeepSeekTool, type DeepSeekUsage, deepseekAdapter };
|