toTools builds the OpenAI tool list. OpenAI expects the *full* JSON Schema envelope (`{"type":"object","properties":..., "required":...}`); our ToolDef.InputSchema only holds the inner properties map, so we wrap.
(tools []api.ToolDef)
| 193 | // envelope (`{"type":"object","properties":..., "required":...}`); our |
| 194 | // ToolDef.InputSchema only holds the inner properties map, so we wrap. |
| 195 | func (p *OpenAIProvider) toTools(tools []api.ToolDef) []openai.ChatCompletionToolParam { |
| 196 | if len(tools) == 0 { |
| 197 | return nil |
| 198 | } |
| 199 | out := make([]openai.ChatCompletionToolParam, 0, len(tools)) |
| 200 | for _, t := range tools { |
| 201 | parameters := map[string]any{ |
| 202 | "type": "object", |
| 203 | "properties": t.InputSchema, |
| 204 | } |
| 205 | if len(t.Required) > 0 { |
| 206 | parameters["required"] = t.Required |
| 207 | } |
| 208 | out = append(out, openai.ChatCompletionToolParam{ |
| 209 | Function: shared.FunctionDefinitionParam{ |
| 210 | Name: t.Name, |
| 211 | Description: param.NewOpt(t.Description), |
| 212 | Parameters: shared.FunctionParameters(parameters), |
| 213 | }, |
| 214 | }) |
| 215 | } |
| 216 | return out |
| 217 | } |
| 218 | |
| 219 | func fromFinishReason(r string) api.StopReason { |
| 220 | switch r { |