MCPcopy Create free account
hub / github.com/Noumena-Network/code / convertTools

Function convertTools

src/services/api/openAICompatInferenceClient.ts:684–713  ·  view source on GitHub ↗
(tools: unknown)

Source from the content-addressed store, hash-verified

682}
683
684function convertTools(tools: unknown): Array<Record<string, unknown>> | undefined {
685 if (!Array.isArray(tools) || tools.length === 0) {
686 return undefined
687 }
688
689 return tools.map(tool => {
690 if (
691 !tool ||
692 typeof tool !== 'object' ||
693 !('name' in tool) ||
694 typeof tool.name !== 'string'
695 ) {
696 throw new Error('Unsupported tool shape for OpenAI compat client')
697 }
698
699 return {
700 type: 'function',
701 function: {
702 name: tool.name,
703 ...(typeof tool.description === 'string'
704 ? { description: tool.description }
705 : {}),
706 parameters:
707 'input_schema' in tool && tool.input_schema
708 ? tool.input_schema
709 : { type: 'object', properties: {} },
710 },
711 }
712 })
713}
714
715function convertToolChoice(
716 toolChoice: unknown,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected