MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / addKimiToolCompatibilityFields

Function addKimiToolCompatibilityFields

web/src/llm-api/kimi-tool-compat.ts:31–67  ·  view source on GitHub ↗
(
  body: ChatCompletionRequestBody,
)

Source from the content-addressed store, hash-verified

29 * names on tool-result messages.
30 */
31export function addKimiToolCompatibilityFields(
32 body: ChatCompletionRequestBody,
33): ChatCompletionRequestBody {
34 const namesByToolCallId = getToolCallNamesById(body.messages)
35
36 return {
37 ...body,
38 tools: body.tools?.map((tool, index) => {
39 if (tool.type !== 'function' || tool.id) {
40 return tool
41 }
42 return {
43 ...tool,
44 id: `tool_${index + 1}`,
45 }
46 }),
47 messages: body.messages.map((message) => {
48 if (
49 message.role !== 'tool' ||
50 message.name ||
51 typeof message.tool_call_id !== 'string'
52 ) {
53 return message
54 }
55
56 const name = namesByToolCallId.get(message.tool_call_id)
57 if (!name) {
58 return message
59 }
60
61 return {
62 ...message,
63 name,
64 }
65 }),
66 }
67}

Callers 4

createOpenRouterRequestFunction · 0.90
createCanopyWaveRequestFunction · 0.90
buildMoonshotRequestBodyFunction · 0.90

Calls 2

getToolCallNamesByIdFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected