Repository: vercel-labs/ai
File: packages/anthropic/src/convert-to-anthropic-messages-prompt.ts (TypeScript)

Code before:
                                url: contentPart.url,
                              },
                            };
                          }
                          case 'file-data': {
                            if (contentPart.mediaType === 'application/pdf') {
                              betas.add('pdfs-2024-09-25');
                              return {
                                type: 'document' as const,
                                source: {
                                  type: 'base64' as const,
                                  media_type: contentPart.mediaType,
                                  data: contentPart.data,
                                },
                              };
                            }

                            warnings.push({
                              type: 'other',
                              message: `unsupported tool content part type: ${contentPart.type} with media type: ${contentPart.mediaType}`,
                            });

                            return undefined;
                          }
                          default: {
                            warnings.push({
                              type: 'other',
                              message: `unsupported tool content part type: ${contentPart.type}`,
                            });

                            return undefined;
                          }
                        }
                      })
                      .filter(isNonNullable);
                    break;
                  case 'text':
                  case 'error-text':
                    contentValue = output.value;
                    break;
                  case 'execution-denied':
                    contentValue = output.reason ?? 'Tool execution denied.';
                    break;
                  case 'json':
                  case 'error-json':
                  default:
                    contentValue = JSON.stringify(output.value);
                    break;
                }

                anthropicContent.push({

Review comment (suggestion):
Could this also be done in a part that's not `custom`? Asking since parts of other types also support `providerOptions`. We could check presence of provider-specific `tool-reference` data regardless of type.

Maybe `custom` is the way to go, but wanted to double check.

Code after:
                                url: contentPart.url,
                              },
                            };
                          }
                          case 'file-data': {
                            if (contentPart.mediaType === 'application/pdf') {
                              betas.add('pdfs-2024-09-25');
                              return {
                                type: 'document' as const,
                                source: {
                                  type: 'base64' as const,
                                  media_type: contentPart.mediaType,
                                  data: contentPart.data,
                                },
                              };
                            }

                            warnings.push({
                              type: 'other',
                              message: `unsupported tool content part type: ${contentPart.type} with media type: ${contentPart.mediaType}`,
                            });

                            return undefined;
                          }
                          case 'custom': {
                            const anthropicOptions = contentPart.providerOptions
                              ?.anthropic as
                              | { type: string; toolName?: string }
                              | undefined;
                            if (anthropicOptions?.type === 'tool-reference') {
                              return {
                                type: 'tool_reference' as const,
                                tool_name: anthropicOptions.toolName!,
                              };
                            }
                            warnings.push({
                              type: 'other',
                              message: `unsupported custom tool content part`,
                            });
                            return undefined;
                          }
                          default: {
                            warnings.push({
                              type: 'other',
                              message: `unsupported tool content part type: ${contentPart.type}`,
                            });

                            return undefined;
                          }
                        }
                      })